OSDN Git Service

Container builder and some refactoring. still working on.
authortkawata <takuji.kawata@gmail.com>
Sun, 22 Jan 2012 05:36:22 +0000 (14:36 +0900)
committertkawata <takuji.kawata@gmail.com>
Sun, 22 Jan 2012 05:36:22 +0000 (14:36 +0900)
24 files changed:
Samples/HTML/Sample1.html
Source/DNContainerBuilder.cpp
Source/DNContainerBuilder.h
Source/DNUtils.cpp
Source/DNUtils.h
Source/DNXML.cpp
Source/DNXML.h
Source/DNXMLImpl.h
Source/TKCell.cpp
Source/TKCell.h
Source/TKCellCode.h
Source/TKContainer.cpp
Source/TKContainer.h
Source/TKJSBasicCell.cpp
Source/TKJSBasicCell.h
Source/TKJSCellBase.h
Source/TKJSCellCode.cpp
Source/TKJSCellCode.h
Source/TKJSContainer.cpp
Source/TKJSContainer.h
Source/TKUICell.h
Source/platform/osx/OSXDNXMLImpl.mm
dennco-jstestapp1/Controller.mm
dennco-jstestapp1/startup11_1.js

index 9ceb55b..d822e67 100644 (file)
             Code class : <a href="#SampleScript2" class="dennco-script">SampleScript2</a>
             <pre class="dennco-script">
                 
-    positiveInputs = {"cell1-1", "cell1-2"};
-    negativeInputs = {"cell1-3"}    
+                positiveInputs = {FQN("/sample.html#cell1-1"), FQN("sample2.html#cell1-2")};
+                negativeInputs = {FQN("../sample3.html#cell1-3")}    
             </pre>
         Connections:
         <ul>
             Code class : <a href="#SampleScript2" class="dennco-script">SampleScript2</a>
             <pre class="dennco-script">
                 
-    positiveInputs = {"cell1-3"};
-    negativeInputs = {"cell1-1", "cell1-2"}    
+    positiveInputs = {FQN("cell1-3")};
+    negativeInputs = {FQN("../cell1-1"), FQN("cell1-2")}    
             </pre>
         Connections:
         <ul>
             Code class : <a href="#SampleScript1" class="dennco-script">SampleScript2</a>
             <pre class='dennco-script'>
         
-    positiveInputs = {"cell2-1"};
-    negativeInputs = {"cell2-2"}    
+    positiveInputs = {FQN("cell2-1")};
+    negativeInputs = {FQN("cell2-2")}    
             </pre>
         </div>
     </a>
index 94cfd8e..904f282 100644 (file)
@@ -26,6 +26,7 @@
 #include "DNXMLElement.h"
 #include "TKLog.h"
 #include "DNUtils.h"
+#include "TKCell.h"
 #include "TKDebug.h"
 
 #include "DNContainerBuilder.h"
@@ -47,25 +48,59 @@ TKContainer* DNContainerBuilder::buildContainerFromXHTML(const char* docRoot)
     
     DNDirectory directory(docRoot);
     const DNFileList *flist = directory.getFileList("html|htm|xml");
+    
+    //parse XHTML files
     while(flist)
     {
-        std::string pathString = docRoot;
-        trimString(pathString);
-        pathString.append("/");
-        pathString.append(flist->filePath);
-        parseXHTML(pathString.c_str());
+        parseXHTML(docRoot, flist->filePath.c_str());
 
         flist = flist->next;
     }
     
+    //build cells
+    while(!mPendingCellDefinitions.empty())
+    {
+        PendingCellDefinition *cellInfo = mPendingCellDefinitions.front();
+        TKCellCode *cellCode = mContainer->getCellCode(cellInfo->cellCodeName);
+        TKCell *newCell = NULL;
+        if (cellCode)
+        {
+            newCell = mContainer->createCell(cellInfo->location, cellInfo->cellName, cellCode, cellInfo->startupScript);
+        }
+        if (newCell == NULL)
+        {
+            TKLog::printf("Failed to construct cell:%s.",cellInfo->cellName.c_str());
+        }
+        mPendingCellDefinitions.pop();
+    }
+    
+    //build connections
+    while(!mPendingConnections.empty())
+    {
+        PendingCellConnection *connInfo = mPendingConnections.front();
+        TKCell *orgCell = mContainer->getCell(connInfo->originCellName);
+        TKCell *tgtCell = mContainer->getCell(connInfo->targetCellName);
+        
+        if (orgCell && tgtCell)
+        {
+            orgCell->connectTo(connInfo->connectionName, tgtCell);
+        }
+        else
+        {
+            TKLog::printf("Failed to make connection (%s) cell:%s -> cell:%s", connInfo->connectionName.c_str(),connInfo->originCellName.c_str(), connInfo->targetCellName.c_str());            
+        }
+        mPendingConnections.pop();
+    }
+    
     mLock.unlock();
     
     return mContainer;
 }
 
-void DNContainerBuilder::parseXHTML(const char *fpath)
+void DNContainerBuilder::parseXHTML(const char *docRoot, const char *path)
 {
-    DNXML *xml = DNXML::createXMLFromFile(fpath);
+    
+    DNXML *xml = DNXML::createXMLFromFile(docRoot, path);
     DNXMLElement *element = xml->getRoot();
     
     DNXMLElement *classElement = NULL;
@@ -95,7 +130,7 @@ void DNContainerBuilder::parseXHTML(const char *fpath)
                     }
                     else
                     {                    
-                        TKLog::printf("A syntax error is found in %s. dennco-script isn't properly defined.",fpath);
+                        TKLog::printf("A syntax error is found in %s. dennco-script isn't properly defined.",path);
                     }
                     
                     break;
@@ -116,7 +151,7 @@ void DNContainerBuilder::parseXHTML(const char *fpath)
                     }
                     else
                     {
-                        TKLog::printf("A syntax error is found in %s. dennco-script isn't properly defined.",fpath);
+                        TKLog::printf("A syntax error is found in %s. dennco-script isn't properly defined.",path);
                     }
                     
                     break;
@@ -125,7 +160,7 @@ void DNContainerBuilder::parseXHTML(const char *fpath)
             }
             if (!te)
             {
-                TKLog::printf("A syntax error is found in %s. dennco-script doesn't belong to any of dennco-classdef or dennco-cell.", fpath);
+                TKLog::printf("A syntax error is found in %s. dennco-script doesn't belong to any of dennco-classdef or dennco-cell.", path);
             }
             
         }
@@ -140,12 +175,12 @@ void DNContainerBuilder::parseXHTML(const char *fpath)
                 }
                 else
                 {
-                    TKLog::printf("A syntax error is found in %s. Nested dennco-classdef?", fpath);
+                    TKLog::printf("A syntax error is found in %s. Nested dennco-classdef?", path);
                 }
             }
             else
             {
-                TKLog::printf("A syntax error is found in %s. dennco-classdef doesn't have name attribute", fpath);                
+                TKLog::printf("A syntax error is found in %s. dennco-classdef doesn't have name attribute", path);                
             }
         }
         else if (eclass == "dennco-cell")
@@ -160,12 +195,12 @@ void DNContainerBuilder::parseXHTML(const char *fpath)
                 }
                 else
                 {
-                    TKLog::printf("A syntax error is found in %s. Nested dennco-cell?", fpath);
+                    TKLog::printf("A syntax error is found in %s. Nested dennco-cell?", path);
                 }
             }
             else
             {
-                TKLog::printf("A syntax error is found in %s. dennco-cell doesn't have name attribute", fpath);
+                TKLog::printf("A syntax error is found in %s. dennco-cell doesn't have name attribute", path);
             }
         }
         else if (eclass == "dennco-connect")
@@ -177,16 +212,20 @@ void DNContainerBuilder::parseXHTML(const char *fpath)
                 trimString(target);
                 if (target.length() > 0)
                 {
-                    mPendingConnection.insert( std::map<std::string, std::string>::value_type( cellName, target));
+                    PendingCellConnection *newConnection = new PendingCellConnection();
+                    newConnection->connectionName = getFQNString(path, cellName.c_str());
+                    newConnection->originCellName = getFQNString(path, cellName.c_str());
+                    newConnection->targetCellName = getFQNString(path, target.c_str());
+                    mPendingConnections.push(newConnection);
                 }
                 else
                 {
-                    TKLog::printf("A syntax error is found in %s. dennco-connect doesn't have link target (href) attribute.", fpath);                    
+                    TKLog::printf("A syntax error is found in %s. dennco-connect doesn't have link target (href) attribute.", path);                    
                 }
             }
             else
             {
-                TKLog::printf("A syntax error is found in %s. dennco-connect doesn't belong to any of dennco-cell.", fpath);
+                TKLog::printf("A syntax error is found in %s. dennco-connect doesn't belong to any of dennco-cell.", path);
             }
         }
         else if (eclass == "dennco-api")
@@ -203,7 +242,7 @@ void DNContainerBuilder::parseXHTML(const char *fpath)
                     }
                     else
                     {
-                        TKLog::printf("A syntax error is found in %s. dennco-api isn't properly defined.",fpath);
+                        TKLog::printf("A syntax error is found in %s. dennco-api isn't properly defined.",path);
                     }
                     
                     break;
@@ -212,7 +251,7 @@ void DNContainerBuilder::parseXHTML(const char *fpath)
             }
             if (!te)
             {
-                TKLog::printf("A syntax error is found in %s. dennco-api doesn't belong to any of dennco-cell.", fpath);
+                TKLog::printf("A syntax error is found in %s. dennco-api doesn't belong to any of dennco-cell.", path);
             }
         }
         
@@ -236,8 +275,15 @@ void DNContainerBuilder::parseXHTML(const char *fpath)
                 // define it now.
                 if (classElement && (element == NULL || element->depth <= classElement->depth))
                 {
-                    DEBUG_TRACE("\n===== Define cell code class ===== \nClass:%s\nAPI:%s\n%s\n==================================\n\n", className.c_str(), classAPIElement->text.c_str(), classScriptElement->text.c_str());
-                    //scriptless classdef
+                    std::string _cellCodeName = getFQNString(path,className.c_str());
+                    std::string _cellCodeAPIType = classAPIElement->text;
+                    std::string _cellCodeScript = classScriptElement->text;
+                    
+                    DEBUG_TRACE("\n===== Define cell code class ===== \nClass:%s\nAPI:%s\n%s\n", _cellCodeName.c_str(), _cellCodeAPIType.c_str(), _cellCodeScript.c_str());
+                    
+                    mContainer->createCellCode(_cellCodeName, _cellCodeAPIType, _cellCodeScript);
+                    
+                    
                     classElement = NULL;
                     classScriptElement = NULL;
                     classAPIElement = NULL;
@@ -248,8 +294,23 @@ void DNContainerBuilder::parseXHTML(const char *fpath)
                 // define it now.
                 if (cellElement && (element == NULL || element->depth <= cellElement->depth))
                 {
-                    DEBUG_TRACE("\n===== Define cell ===== \nName:%s\nClass:%s\nStartup script:\n%s\n=======================\n\n", cellName.c_str(), cellCodeClassName.c_str(),cellScriptElement->text.c_str());
-                    //scriptless celldef
+                    //scriptless celldef                    
+                    std::string _cellName = cellName;
+                    std::string _cellNameFQN = getFQNString(path, cellName.c_str());
+                    std::string _cellCodeName = getFQNString(path, cellCodeClassName.c_str());
+                    std::string _cellScript = cellScriptElement->text;
+                    
+                    DEBUG_TRACE("\n===== Define cell ================ \nName:%s\nClass:%s\nStartup script:\n%s\n", _cellNameFQN.c_str(), _cellCodeName.c_str(),_cellScript.c_str());
+                    
+                    
+                    PendingCellDefinition *newCellDefine = new PendingCellDefinition();
+                    newCellDefine->location = path;
+                    newCellDefine->cellName = _cellName;
+                    newCellDefine->cellCodeName = _cellCodeName;
+                    newCellDefine->startupScript = _cellScript;
+                    
+                    mPendingCellDefinitions.push(newCellDefine);
+                    
                     cellElement = NULL;
                     cellScriptElement = NULL;
                     cellName = "";
index e54052f..d4f419c 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef dennco_TKContainerBuilder_h
 #define dennco_TKContainerBuilder_h
 
-#include <map>
+#include <queue>
 
 #include "TKLock.h"
 
@@ -35,10 +35,31 @@ public:
     TKContainer *buildContainerFromXHTML(const char* docRoot);
 
 private:
-    void        parseXHTML(const char *fpath);
-    std::map<std::string, std::string>  mPendingConnection;
+    void        parseXHTML(const char* docRoot, const char *fpath);
     TKLock                              mLock;
     TKContainer                         *mContainer;
+
+    class PendingCellDefinition
+    {
+    public:
+        std::string location;
+        std::string cellName;
+        std::string cellCodeName;
+        std::string startupScript;
+    };
+    
+    class PendingCellConnection
+    {
+    public:
+        std::string connectionName;
+        std::string originCellName;
+        std::string targetCellName;
+    };
+    
+    std::queue<PendingCellConnection*> mPendingConnections;
+    std::queue<PendingCellDefinition*> mPendingCellDefinitions;
+    
+
 };
 
 
index 66496bb..9e30041 100644 (file)
@@ -32,3 +32,188 @@ void trimString(std::string& str)
     str = str.substr(pos1 == std::string::npos ? 0 : pos1, 
                      pos2 == std::string::npos ? str.length() - 1 : pos2 - pos1 + 1);
 }
+
+std::string getFQNString(const char *location, const char *name)
+{
+    std::string path;
+    std::string node;
+    int l = (int)strlen(location) - 1;
+    bool f = false;
+    while (l >= 0)
+    {
+        if (location[l] == '/')
+        {
+            f = true;
+            break;
+        }
+        l--;
+    }
+    if( f )
+    {
+        if (l == 0)
+        {
+            path = "/";
+            node = location;
+        }
+        else
+        {
+            node = location;
+            path = node.substr(0,l);
+            node = node.substr(l);
+        }
+    }
+    else
+    {
+        path = "";
+        node = location;
+    }
+    
+    const char *c = name;
+    int i = 0;
+    const char *p = c;
+    while(*c)
+    {
+        if (*c == '/')
+        {
+            if (i >= 2 && *(c - 2) == '.' && *(c - 1) == '.')
+            {
+                unsigned long l = path.find_last_of("/");
+                if( l != std::string::npos )
+                {
+                    if (l == 0)
+                    {
+                        path = "/";
+                    }
+                    else if (l > 0)
+                    {
+                        path = path.substr(0, l);
+                    }
+                }
+                else
+                {
+                    path = "";
+                }
+                p = c;
+            }
+            else if (i >= 1 && *(c - 1) == '.')
+            {
+                p = c;
+            }
+            else if (i >= 1 && *(c - 1) == '/')
+            {
+                p = c; 
+            }
+            else if (i == 0)
+            {
+                if (path.length() > 0 && path.at(0) == '/')
+                {
+                    path = "/";
+                }
+                else
+                {
+                    path = "";
+                }
+            }
+            else
+            {
+                size_t pl = path.length();
+                if (pl == 0)
+                {
+                    if (*p == '/')
+                    {
+                        p++;
+                    }                    
+                }
+                else if (pl == 1)
+                {
+                    char p1 = path.at(0);
+                    if (p1 == '/' || p1 == '.')
+                    {
+                        if (*p == '/')
+                        {
+                            p++;
+                        }
+                    }
+                }
+                else
+                {
+                    if (*p != '/')
+                    {
+                        path.append("/");
+                    }
+                }
+                std::string s(p, c-p); 
+                path.append(s);
+                p = c;
+            }
+        }
+        c++;
+        i++;
+        if (i > 1024) break;
+    }
+    
+    if (*p == '/')
+    {
+        node = p;
+    }
+    else if(*p == '#')
+    {
+        node.append(p);
+    }
+    else
+    {
+        const char *p2 = p;
+        bool hasAnchor = false;
+        while(*p2)
+        {
+            if (*p2 == '#')
+            {
+                hasAnchor = true;
+                break;
+            }
+            p2++;
+        }
+        if (hasAnchor)
+        {
+            node = "/";
+            node.append(p);        
+        }
+        else
+        {
+            node.append("#");
+            node.append(p);
+        }
+    }
+    
+    int pl = (int)path.length();
+    std::string fqn;
+    if (pl == 0)
+    {
+        if (node.at(0) == '/' && node.length() > 1)
+        {
+            fqn = node.substr(1);
+        }
+        else
+        {
+            fqn = node;
+        }
+        
+    }
+    else if (pl == 1)
+    {
+        if (path.at(0) == '/' && node.length() > 0 && node.at(0) == '/')
+        {
+            fqn = node;
+        }
+        else
+        {
+            fqn = path.append(node);
+        }
+    }
+    else
+    {
+        fqn = path.append(node);
+    }
+    
+    return fqn;
+}
index 8295708..cd4361a 100644 (file)
@@ -24,5 +24,6 @@
 
 void trimString(std::string& str);
 
+std::string getFQNString(const char *location, const char *name);
 
 #endif
index 101b618..ec36a98 100644 (file)
@@ -21,9 +21,9 @@
 #include "DNXML.h"
 
 //static 
-DNXML* DNXML::createXMLFromFile(const char *fpath)
+DNXML* DNXML::createXMLFromFile(const char *docRoot, const char *path)
 {
-    return new DNXML(DNXMLImpl::createXMLFromFileImpl(fpath));
+    return new DNXML(DNXMLImpl::createXMLFromFileImpl(docRoot, path));
 }
 
 DNXMLElement* DNXML::getRoot()
index e31e82c..6a92d13 100644 (file)
@@ -26,7 +26,7 @@ class DNXMLElement;
 class DNXML
 {
 public:
-    static DNXML*   createXMLFromFile(const char *fpath);
+    static DNXML*   createXMLFromFile(const char *docRoot, const char *path);
     
     DNXMLElement*   getRoot();
     
index 49f2766..7c390cb 100644 (file)
@@ -26,7 +26,7 @@ class DNXMLElement;
 class DNXMLImpl
 {
 public:
-    static DNXMLImpl*       createXMLFromFileImpl(const char *fpath);
+    static DNXMLImpl*       createXMLFromFileImpl(const char *docRoot, const char *path);
     
     virtual DNXMLElement*   getRoot() = 0;
 };
index 8882aee..72dc2e1 100644 (file)
@@ -26,7 +26,8 @@
 #include "TKLog.h"
 #include <string>
 
-TKCell::TKCell(TKContainer *container, std::string name): mContainer(container), mAxon(NULL), mCellCode(NULL), mName(name)
+TKCell::TKCell(TKContainer *container, std::string location, std::string name)
+: mContainer(container), mAxon(NULL), mCellCode(NULL), mLocation(location), mName(name)
 {
     mAxon = new TKAxon(this);
 }
@@ -54,7 +55,7 @@ void  TKCell::setAxonValue(float value)
     mAxon->value = value;
 }
 
-bool TKCell::setCellCode(TKCellCode *code, void *data)
+bool TKCell::setCellCode(TKCellCode *code, const void *data)
 {
     mCellCode = code->createCellCodeInstance(this, data);
     mCellCode->doInit();
index c765b49..cc965ff 100644 (file)
@@ -34,17 +34,16 @@ typedef std::map<std::string, TKReceptor*> TKReceptorMap;
 class TKCell
 {
 public:
-       TKCell(TKContainer *container, std::string name);
+       TKCell(TKContainer *container, std::string location, std::string name);
        virtual ~TKCell();
     
     std::string             getName() { return mName; }
-    
     float                   getAxonValue();
     void                    setAxonValue(float value);
     
     const TKReceptorMap*    getReceptors() { return &mReceptors; }
     
-    virtual bool            setCellCode(TKCellCode *code, void *data);
+    virtual bool            setCellCode(TKCellCode *code, const void *data);
     
        bool                    connectTo(std::string connectionName, TKCell *targetReceptor);
        inline TKContainer*     getContainer() { return mContainer; }
@@ -55,6 +54,7 @@ protected:
     virtual TKReceptor*     createReceptor(std::string name);
     
     std::string             mName;
+    std::string             mLocation;
        TKContainer             *mContainer;
        TKAxon                  *mAxon;
        TKReceptorMap           mReceptors;
index 4e8dfd9..46a588d 100644 (file)
@@ -31,12 +31,17 @@ class TKCellCodeInstance;
 class TKCellCode
 {
 public:
-       TKCellCode() {};
+       TKCellCode(std::string theName, std::string theCellAPIName) : mName(theName), mCellAPIName(theCellAPIName) {};
        virtual ~TKCellCode() {};
-
-       virtual TKCellCodeInstance* createCellCodeInstance(TKCell *owner, void *data) = 0;
-    
     
+    std::string getName() { return mName; }
+    std::string getCellAPIName() { return mCellAPIName; }
+
+       virtual TKCellCodeInstance* createCellCodeInstance(TKCell *owner, const void *data) = 0;
+
+private:
+    std::string mName;
+    std::string mCellAPIName;
 };
 
 #endif 
\ No newline at end of file
index 5c68519..2451c13 100644 (file)
@@ -28,3 +28,29 @@ TKContainer::~TKContainer()
     }
     mCells.clear();
 }
+
+TKCell* TKContainer::getCell(std::string theFQNName)
+{
+    TKCellMap::iterator it = mCells.find(theFQNName);
+    if (it == mCells.end())
+    {
+        return NULL;
+    }
+    else
+    {
+        return it->second;
+    }
+}
+
+TKCellCode* TKContainer::getCellCode(std::string theCellCodeName)
+{
+    TKCellCodeMap::iterator it = mCellCodes.find(theCellCodeName);
+    if (it == mCellCodes.end())
+    {
+        return NULL;
+    }
+    else
+    {
+        return it->second;
+    }
+}
index 305b0d2..e37897e 100644 (file)
@@ -27,6 +27,7 @@ class TKCell;
 class TKCellCode;
 
 typedef std::map<std::string, TKCell*> TKCellMap;
+typedef std::map<std::string, TKCellCode*> TKCellCodeMap;
 
 class TKContainer
 {
@@ -34,18 +35,23 @@ public:
        
        TKContainer() {};
        virtual ~TKContainer();
-    
+
     const TKCellMap* getCells() { return &mCells; } 
+    const TKCellCodeMap* getCellCodes() { return &mCellCodes; }
+       TKCell* getCell(std::string theFQNName);
+       TKCellCode* getCellCode(std::string theCellCodeName);
        
-       virtual TKCell* getCell(std::string theName) = 0;
-       
+       virtual TKCell* createCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string startupString) = 0;
+       virtual TKCellCode* createCellCode(std::string theName, std::string theAPIType, std::string code) = 0;
+       
        virtual bool doTick(float time) = 0;
        
        virtual void setValue(std::string key, float value) = 0;
        inline virtual float getValue(std::string key) = 0;
 
 protected:
-       TKCellMap mCells;
+       TKCellMap       mCells;
+    TKCellCodeMap   mCellCodes;
        
 };
 #endif
\ No newline at end of file
index 369c115..1b508e9 100644 (file)
@@ -36,24 +36,25 @@ JSClassDefinition TKJSBasicCell::mJsClassDef;
 
 
 //JavaScript API functions
-/*
-JSStaticFunction jsfuncGetReceptorValues = {"getReceptorValues",(JSObjectCallAsFunctionCallback)TKJSBasicCell::jsAPICB_getReceptorValues,kJSPropertyAttributeNone};
+
+/*JSStaticFunction jsfuncFQN = {"FQN",(JSObjectCallAsFunctionCallback)TKJSBasicCell::jsAPICB_FQN,kJSPropertyAttributeNone};
 JSStaticFunction jsfuncSetAxonValue = {"setAxonValue",(JSObjectCallAsFunctionCallback)TKJSBasicCell::jsAPICB_setAxonValue,kJSPropertyAttributeNone};
 JSStaticFunction jsfuncGetAxonValue = {"getAxonValue",(JSObjectCallAsFunctionCallback)TKJSBasicCell::jsAPICB_getAxonValue,kJSPropertyAttributeNone};
-JSStaticFunction jsfuncEOF = {0,0,0};
-JSStaticFunction classFunctions[] = {jsfuncGetReceptorValues, jsfuncSetAxonValue, jsfuncGetAxonValue, jsfuncEOF};
-*/
+ */
+//JSStaticFunction classFunctions[] = {jsfuncFQN, {0,0,0}};
+
 
 JSStaticValue jsStaticValueArray[] = { 
     { "axonValue", (JSObjectGetPropertyCallback)TKJSBasicCell::jsAPICB_getAxonValue, (JSObjectSetPropertyCallback)TKJSBasicCell::jsAPICB_setAxonValue, kJSPropertyAttributeNone }, 
     { "name", (JSObjectGetPropertyCallback)TKJSBasicCell::jsAPICB_getName, NULL, kJSPropertyAttributeNone },     
+    { "location", (JSObjectGetPropertyCallback)TKJSBasicCell::jsAPICB_getLocation, NULL, kJSPropertyAttributeNone },     
     { 0, 0, 0, 0 } };
 
 
 const char* JSCLASSNAME = "__TKCLASSDEF_TKJSBasicCell";
 
-TKJSBasicCell::TKJSBasicCell(TKJSContainer *container, std::string name)
-:TKJSCellBase(container, name)
+TKJSBasicCell::TKJSBasicCell(TKJSContainer *container, std::string location, std::string name)
+:TKJSCellBase(container, location, name)
 {
     JSContextRef ctx = ((TKJSContainer*)getContainer())->getJSContext();
     
@@ -72,6 +73,11 @@ TKJSBasicCell::TKJSBasicCell(TKJSContainer *container, std::string name)
     JSValueProtect(ctx, mJName);
     JSStringRelease(jstrName);
 
+    JSStringRef jstrLocation = JSStringCreateWithUTF8CString(location.c_str());
+    mJLocation = JSValueMakeString(ctx, jstrLocation);
+    JSValueProtect(ctx, mJLocation);
+    JSStringRelease(jstrLocation);
+
 }
 
 TKJSBasicCell::~TKJSBasicCell()
@@ -90,6 +96,10 @@ TKJSBasicCell::~TKJSBasicCell()
             {
                 JSValueUnprotect(ctx, mJName);
             }
+            if (mJLocation)
+            {
+                JSValueUnprotect(ctx, mJLocation);
+            }
         }
     }
 }
@@ -188,7 +198,16 @@ JSValueRef TKJSBasicCell::jsAPICB_getName(
     return self->mJName;
 }
 
-
+JSValueRef TKJSBasicCell::jsAPICB_getLocation(
+                                          JSContextRef ctx,
+                                          JSObjectRef object,
+                                          JSStringRef propertyName,
+                                          JSValueRef *exception)
+{
+    TKJSBasicCell *self = (TKJSBasicCell*)JSObjectGetPrivate(object);
+    TKASSERT(self);
+    return self->mJLocation;
+}
 
 void TKJSBasicCell::jsFinalize(JSObjectRef object)
 {
index 34587f9..7fe0998 100644 (file)
@@ -35,7 +35,7 @@ class TKReceptor;
 class TKJSBasicCell : public TKJSCellBase
 {
 public:
-       TKJSBasicCell(TKJSContainer *container, std::string name);
+       TKJSBasicCell(TKJSContainer *container, std::string location, std::string name);
     virtual ~TKJSBasicCell();
        
        virtual bool                doTick(float time);
@@ -50,6 +50,7 @@ private:
     
     JSObjectRef                 mJsReceptorValues;
     JSValueRef                  mJName;
+    JSValueRef                  mJLocation;
 
 public:
     static JSValueRef           jsAPICB_getAxonValue(
@@ -71,6 +72,12 @@ public:
                                                      JSStringRef propertyName,
                                                      JSValueRef *exception);
 
+    static JSValueRef           jsAPICB_getLocation(
+                                                JSContextRef ctx,
+                                                JSObjectRef object,
+                                                JSStringRef propertyName,
+                                                JSValueRef *exception);
+
     static void                 jsFinalize(JSObjectRef object);
 
 };
index a99af7f..147adb5 100644 (file)
@@ -32,7 +32,8 @@ class TKJSCellCode;
 class TKJSCellBase : public TKCell
 {
 public:
-       TKJSCellBase(TKJSContainer *container, std::string name) : TKCell((TKContainer*)container, name), mJSAPIInstance(0) {}
+       TKJSCellBase(TKJSContainer *container, std::string location, std::string name) 
+    : TKCell((TKContainer*)container, location, name), mJSAPIInstance(0) {}
     
     JSObjectRef                 getCellAPI() { return mJSAPIInstance; }
     
index 998513e..aa0bfcc 100644 (file)
@@ -27,7 +27,7 @@
 #include "DNUtils.h"
 #include <string>
 
-TKCellCodeInstance* TKJSCellCode::createCellCodeInstance(TKCell *owner, void *data)
+TKCellCodeInstance* TKJSCellCode::createCellCodeInstance(TKCell *owner, const void *data)
 {
      TKCellCodeInstance *result = NULL;
     if (mJsConstructorRef)
@@ -54,8 +54,8 @@ TKJSCellCode::~TKJSCellCode()
 {    
 }
 
-TKJSCellCode::TKJSCellCode(TKJSContainer *container, std::string name, std::string code):
-    mName(name),
+TKJSCellCode::TKJSCellCode(std::string name, std::string cellapi, TKJSContainer *container, std::string code):
+    TKCellCode(name, cellapi),
     mJsConstructorRef(NULL),
     mJSContainer(container)
 {
index 44f173d..b44e9a9 100644 (file)
@@ -32,15 +32,13 @@ class TKJSCellCode : public TKCellCode
 {
        
 public:
-       TKJSCellCode(TKJSContainer *container, std::string name, std::string code);
+       TKJSCellCode(std::string name, std::string cellapi, TKJSContainer *container, std::string code);
        virtual ~TKJSCellCode();
     
-       virtual TKCellCodeInstance* createCellCodeInstance(TKCell *owner, void *data);
+       virtual TKCellCodeInstance* createCellCodeInstance(TKCell *owner, const void *data);
 
-    std::string     getName() { return mName; }
 private:
     JSObjectRef     mJsConstructorRef;
-    std::string     mName;
     TKJSContainer   *mJSContainer;
        
 };
index 99befb3..7d5e3a6 100644 (file)
 #include "TKJSBasicCell.h"
 #include "TKUICell.h"
 #include "TKLog.h"
+#include "DNUtils.h"
 
 #include <string>
 
-const std::string TKJSContainer::CELLTYPE_JSBASIC = "BasicJSCell";
-const std::string TKJSContainer::CELLTYPE_UIBASE = "UIBaseCell";
+const std::string TKJSContainer::CELLTYPE_JSBASIC = "TKJSBasicCell";
+const std::string TKJSContainer::CELLTYPE_UIBASE = "TKUIBaseCell";
 
 static JSValueRef jsGlobalPrint(
                                                                JSContextRef        ctx,
@@ -37,6 +38,14 @@ static JSValueRef jsGlobalPrint(
                                                                const JSObjectRef   args[],
                                                                JSValueRef*         jobjExp);
 
+static JSValueRef jsGlobalFQN(
+                                                               JSContextRef        ctx,
+                                                               JSObjectRef         jobj,
+                                                               JSObjectRef         jobjThis,
+                                                               size_t              argLen,
+                                                               const JSObjectRef   args[],
+                                                               JSValueRef*         jobjExp);
+
 TKJSContainer::TKJSContainer()
 {
     mContext = JSGlobalContextCreate(NULL);
@@ -47,6 +56,11 @@ TKJSContainer::TKJSContainer()
     JSObjectSetProperty(mContext, mGlobalObject, jstrPrint, jfuncPrint, kJSPropertyAttributeNone, NULL);
     JSStringRelease(jstrPrint);
 
+    JSStringRef jstrFQN = JSStringCreateWithUTF8CString("FQN");
+    JSObjectRef jfuncFQN = JSObjectMakeFunctionWithCallback(mContext, jstrFQN, (JSObjectCallAsFunctionCallback)jsGlobalFQN);
+    JSObjectSetProperty(mContext, mGlobalObject, jstrFQN, jfuncFQN, kJSPropertyAttributeNone, NULL);
+    JSStringRelease(jstrFQN);
+
     JSStringRef jstrDGlobal = JSStringCreateWithUTF8CString("global");
     mJGlobalObject = JSObjectMake(mContext, NULL, NULL);
     JSObjectSetProperty(mContext, mGlobalObject, jstrDGlobal, mJGlobalObject, kJSPropertyAttributeNone, NULL);
@@ -67,13 +81,15 @@ TKJSContainer::~TKJSContainer()
     mContext = 0;
 }
 
-TKCell* TKJSContainer::createCell(std::string theName, std::string type)
+TKCell* TKJSContainer::createCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string startupScript)
 {
        TKCell *cell = NULL;
        
+    std::string type = cellCode->getCellAPIName();
+    
        if (type == CELLTYPE_JSBASIC)
        {
-               TKJSBasicCell *basicCell = new TKJSBasicCell(this, theName);
+               TKJSBasicCell *basicCell = new TKJSBasicCell(this, theLocation, theName);
                if (basicCell)
                {
             //do some init here if needed.
@@ -83,7 +99,7 @@ TKCell* TKJSContainer::createCell(std::string theName, std::string type)
        }
        else if (type == CELLTYPE_UIBASE)
     {
-        cell = new TKUICell(this, theName);
+        cell = new TKUICell(this, theLocation, theName);
     }
     else
        {
@@ -93,18 +109,32 @@ TKCell* TKJSContainer::createCell(std::string theName, std::string type)
        
        if (cell)
        {
-               mCells.insert( std::map<std::string, TKCell*>::value_type( theName, cell ) );
+        std::string fqnName = getFQNString(theLocation.c_str(), theName.c_str());
+               mCells.insert( std::map<std::string, TKCell*>::value_type(fqnName, cell));
+        cell->setCellCode(cellCode,(const void*)startupScript.c_str());
        }
+    else
+    {
+        std::string fqnName = getFQNString(theLocation.c_str(),theName.c_str());
+        TKLog::printf("Failed to create a cell. %s", fqnName.c_str());
+    }
+    
        return cell;
 
 }
 
-
-TKCell* TKJSContainer::getCell(std::string theName)
+TKCellCode* TKJSContainer::createCellCode(std::string theName, std::string theAPIType, std::string code)
 {
-       return mCells[theName];
+    TKJSCellCode *cellCode = new TKJSCellCode(theName, theAPIType, this, code);
+    
+    if (cellCode)
+    {
+        mCellCodes.insert( std::map<std::string, TKCellCode*>::value_type(theName, cellCode));
+    }
+    return cellCode;
 }
 
+
 void TKJSContainer::setValue(std::string key, float value)
 {    
     JSStringRef jstr = JSStringCreateWithUTF8CString(key.c_str());
@@ -135,7 +165,7 @@ bool TKJSContainer::doTick(float time)
        return true;
 }
 
-static JSValueRef jsGlobalPrint(
+JSValueRef jsGlobalPrint(
                                                                JSContextRef        ctx,
                                                                JSObjectRef         jobj,
                                                                JSObjectRef         jobjThis,
@@ -156,4 +186,39 @@ static JSValueRef jsGlobalPrint(
     return JSValueMakeUndefined(ctx);
 }
 
+JSValueRef jsGlobalFQN(
+                                                               JSContextRef        ctx,
+                                                               JSObjectRef         jobj,
+                                                               JSObjectRef         jobjThis,
+                                                               size_t              argLen,
+                                                               const JSObjectRef   args[],
+                                                               JSValueRef*         jobjExp) {
+       
+    JSValueRef jsResult = NULL;;
+    
+    if (argLen >= 2) {
+        JSStringRef     jstrLocation    = JSValueToStringCopy(ctx, args[0], jobjExp);
+        JSStringRef     jstrName        = JSValueToStringCopy(ctx, args[1], jobjExp);
+        
+        size_t          locationLen = JSStringGetMaximumUTF8CStringSize(jstrLocation);
+        size_t          nameLen     = JSStringGetMaximumUTF8CStringSize(jstrName);
+        char*           cLocation   =  (char*)malloc(locationLen);
+        char*           cName       =  (char*)malloc(nameLen);
+        JSStringGetUTF8CString(jstrLocation, cLocation, locationLen);
+        JSStringGetUTF8CString(jstrName, cName, nameLen);
+        std::string fqnString = getFQNString(cLocation, cName);
+        
+        jsResult = JSValueMakeString(ctx,JSStringCreateWithUTF8CString(fqnString.c_str()));
+        
+        free(cLocation);
+        free(cName);
+    }
+    else
+    {
+        jsResult = JSValueMakeUndefined(ctx);        
+    }
+       
+    return jsResult;
+}
+
 
index d0497de..71a36fd 100644 (file)
@@ -35,9 +35,9 @@ class TKJSContainer : public TKContainer
 public:
        TKJSContainer();
        virtual ~TKJSContainer();
-       
-       virtual TKCell* createCell(std::string theName, std::string type);              
-       virtual TKCell* getCell(std::string theName);
+
+       virtual TKCell* createCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string startupScript);
+       virtual TKCellCode* createCellCode(std::string theName, std::string theAPIType, std::string code);
        
        virtual bool doTick(float time);
                
index b896605..4d700fe 100644 (file)
@@ -25,7 +25,7 @@
 class TKUICell : public TKCell
 {
 public:
-       TKUICell(TKContainer *container, std::string name) : TKCell(container, name) {}
+       TKUICell(TKContainer *container, std::string location, std::string name) : TKCell(container, location, name) {}
     virtual ~TKUICell() {}
        virtual bool    doTick(float time) { return true;}
 };
index 38e84c3..5f0ada6 100644 (file)
 #include <map>
 
 //static 
-DNXMLImpl* DNXMLImpl::createXMLFromFileImpl(const char *fpath)
+DNXMLImpl* DNXMLImpl::createXMLFromFileImpl(const char *docRoot, const char *path)
 {
-    NSString *file = [[NSString alloc]initWithUTF8String:fpath];
+    NSString *file = [[NSString alloc]initWithFormat:@"%s/%s", docRoot,path];
     
     NSXMLDocument *xmlDoc;
     NSError *err=nil;
     NSURL *furl = [NSURL fileURLWithPath:file];
     if (!furl) {
-        TKLog::printf("Can't create an URL from file %s.", fpath);
+        TKLog::printf("Can't create an URL from file %s.", path);
         return 0;
     }
     xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl
@@ -47,7 +47,7 @@ DNXMLImpl* DNXMLImpl::createXMLFromFileImpl(const char *fpath)
                                                         error:&err];
     }
     if (xmlDoc == nil)  {
-        TKLog::printf("Can't parse xml file %s.", fpath);
+        TKLog::printf("Can't parse xml file %s.", path);
         return 0;
     }
 
index 609142a..8141f6d 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "ConsoleUIOut.h"
 #include "DNTimeKeeper.h"
+#include "DNUtils.h"
 
 @implementation Controller
 
     const char *cstrStartupScript22 = [startupScript22 UTF8String];
     const char *cstrStartupScript31 = [startupScript31 UTF8String];
     
-    
-    TKJSCellCode *layer1Code = new TKJSCellCode(ctn,"layer1code", jslayer1code);
-    TKJSCellCode *layer2Code = new TKJSCellCode(ctn,"layer2code", jslayer2code);
-    TKJSCellCode *layer3Code = new TKJSCellCode(ctn,"layer3code", jslayer3code);
-
-       signal1 = ctn->createCell("signal1", TKJSContainer::CELLTYPE_UIBASE);
-       signal2 = ctn->createCell("signal2", TKJSContainer::CELLTYPE_UIBASE);
-       signal3 = ctn->createCell("signal3", TKJSContainer::CELLTYPE_UIBASE);
-    
-       TKCell *cell11 = ctn->createCell("cell1-1", TKJSContainer::CELLTYPE_JSBASIC);
-       TKCell *cell12 = ctn->createCell("cell1-2", TKJSContainer::CELLTYPE_JSBASIC);
-       TKCell *cell13 = ctn->createCell("cell1-3", TKJSContainer::CELLTYPE_JSBASIC);
 
-       TKCell *cell21 = ctn->createCell("cell2-1", TKJSContainer::CELLTYPE_JSBASIC);
-       TKCell *cell22 = ctn->createCell("cell2-2", TKJSContainer::CELLTYPE_JSBASIC);
+    TKCellCode *uiCode = ctn->createCellCode("layer1code", TKJSContainer::CELLTYPE_UIBASE, "");
+    TKCellCode *layer1Code = ctn->createCellCode("layer1code", TKJSContainer::CELLTYPE_JSBASIC, jslayer1code);
+    TKCellCode *layer2Code = ctn->createCellCode("layer2code", TKJSContainer::CELLTYPE_JSBASIC, jslayer2code);
+    TKCellCode *layer3Code = ctn->createCellCode("layer3code", TKJSContainer::CELLTYPE_JSBASIC, jslayer3code);
 
-       TKCell *cell31 = ctn->createCell("cell3-1", TKJSContainer::CELLTYPE_JSBASIC);
+       signal1 = ctn->createCell("","signal1", uiCode,"");
+       signal2 = ctn->createCell("","signal2", uiCode,"");
+       signal3 = ctn->createCell("","signal3", uiCode,"");
+    
+       TKCell *cell11 = ctn->createCell("","cell1-1", layer1Code, cstrStartupScript11);
+       TKCell *cell12 = ctn->createCell("","cell1-2", layer1Code, cstrStartupScript12);
+       TKCell *cell13 = ctn->createCell("","cell1-3", layer1Code, cstrStartupScript13);
 
-    cell11->setCellCode(layer1Code,(void*)cstrStartupScript11);
-    cell12->setCellCode(layer1Code,(void*)cstrStartupScript12);
-    cell13->setCellCode(layer1Code,(void*)cstrStartupScript13);
+       TKCell *cell21 = ctn->createCell("","cell2-1", layer2Code, cstrStartupScript21);
+       TKCell *cell22 = ctn->createCell("","cell2-2", layer2Code, cstrStartupScript22);
 
-    cell21->setCellCode(layer2Code,(void*)cstrStartupScript21);
-    cell22->setCellCode(layer2Code,(void*)cstrStartupScript22);
+       TKCell *cell31 = ctn->createCell("","cell3-1", layer3Code, cstrStartupScript31);
 
-    cell31->setCellCode(layer3Code,(void*)cstrStartupScript31);
 
        ((TKCell*)signal1)->connectTo("signal1", cell11);
        ((TKCell*)signal1)->connectTo("signal1", cell12);
@@ -371,12 +365,12 @@ float cv31;
     
     const TKCellMap *cells = ctn->getCells();
 
-    TKCellMap::const_iterator it11 = cells->find("cell1-1");
-    TKCellMap::const_iterator it12 = cells->find("cell1-2");
-    TKCellMap::const_iterator it13 = cells->find("cell1-3");
-    TKCellMap::const_iterator it21 = cells->find("cell2-1");
-    TKCellMap::const_iterator it22 = cells->find("cell2-2");
-    TKCellMap::const_iterator it31 = cells->find("cell3-1");
+    TKCellMap::const_iterator it11 = cells->find(getFQNString("","cell1-1"));
+    TKCellMap::const_iterator it12 = cells->find(getFQNString("","cell1-2"));
+    TKCellMap::const_iterator it13 = cells->find(getFQNString("","cell1-3"));
+    TKCellMap::const_iterator it21 = cells->find(getFQNString("","cell2-1"));
+    TKCellMap::const_iterator it22 = cells->find(getFQNString("","cell2-2"));
+    TKCellMap::const_iterator it31 = cells->find(getFQNString("","cell3-1"));
 
     timeKeeper->start();
     
index 7405537..0b32d96 100644 (file)
@@ -1,2 +1,19 @@
 
 this.priorityReceptor = "signal1";
+
+print("FQN function test /a/b/c.html , cell1                    = " + FQN("/a/b/c.html", "cell1"));
+print("FQN function test /a/b/c.hml  , ../d.html#cell1          = " + FQN("/a/b/c.html", "../d.html#cell1"));
+print("FQN function test /a/b/c.html , ../../../../e.html#cell1 = " + FQN("/a/b/c.html", "../../../../e.html#cell1"));
+print("FQN function test a/b/c.html  , ../../../../e.html#cell1 = " + FQN("a/b/c.html", "../../../../e.html#cell1"));
+print("FQN function test /a/b/c.html , /f.html#cell1            = " + FQN("/a/b/c.html", "/f.html#cell1"));
+print("FQN function test a/b/c.html  , /f.html#cell1            = " + FQN("a/b/c.html", "/f.html#cell1"));
+print("FQN function test /a/b/c.html , g.html#cell1             = " + FQN("/a/b/c.html", "g.html#cell1"));
+print("FQN function test /a/b/c.html , d/e/f/g.html#cell1       = " + FQN("/a/b/c.html", "d/e/f/g.html#cell1"));
+print("FQN function test /a/b/c.html , /d/e/f/g.html#cell1      = " + FQN("/a/b/c.html", "/d/e/f/g.html#cell1"));
+print("FQN function test /           , /d/e/f/g.html#cell1      = " + FQN("/", "/d/e/f/g.html#cell1"));
+print("FQN function test .           , /d/e/f/g.html#cell1      = " + FQN(".", "/d/e/f/g.html#cell1"));
+print("FQN function test             , /d/e/f/g.html#cell1      = " + FQN("", "/d/e/f/g.html#cell1"));
+print("FQN function test /           , d/e/f/g.html#cell1      = " + FQN("/", "d/e/f/g.html#cell1"));
+print("FQN function test .           , d/e/f/g.html#cell1      = " + FQN(".", "d/e/f/g.html#cell1"));
+print("FQN function test             , d/e/f/g.html#cell1      = " + FQN("", "d/e/f/g.html#cell1"));
+