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>
#include "DNXMLElement.h"
#include "TKLog.h"
#include "DNUtils.h"
+#include "TKCell.h"
#include "TKDebug.h"
#include "DNContainerBuilder.h"
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;
}
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;
}
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;
}
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);
}
}
}
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")
}
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")
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")
}
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;
}
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);
}
}
// 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;
// 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 = "";
#ifndef dennco_TKContainerBuilder_h
#define dennco_TKContainerBuilder_h
-#include <map>
+#include <queue>
#include "TKLock.h"
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;
+
+
};
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;
+}
void trimString(std::string& str);
+std::string getFQNString(const char *location, const char *name);
#endif
#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()
class DNXML
{
public:
- static DNXML* createXMLFromFile(const char *fpath);
+ static DNXML* createXMLFromFile(const char *docRoot, const char *path);
DNXMLElement* getRoot();
class DNXMLImpl
{
public:
- static DNXMLImpl* createXMLFromFileImpl(const char *fpath);
+ static DNXMLImpl* createXMLFromFileImpl(const char *docRoot, const char *path);
virtual DNXMLElement* getRoot() = 0;
};
#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);
}
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();
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; }
virtual TKReceptor* createReceptor(std::string name);
std::string mName;
+ std::string mLocation;
TKContainer *mContainer;
TKAxon *mAxon;
TKReceptorMap mReceptors;
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
}
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;
+ }
+}
class TKCellCode;
typedef std::map<std::string, TKCell*> TKCellMap;
+typedef std::map<std::string, TKCellCode*> TKCellCodeMap;
class TKContainer
{
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
//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();
JSValueProtect(ctx, mJName);
JSStringRelease(jstrName);
+ JSStringRef jstrLocation = JSStringCreateWithUTF8CString(location.c_str());
+ mJLocation = JSValueMakeString(ctx, jstrLocation);
+ JSValueProtect(ctx, mJLocation);
+ JSStringRelease(jstrLocation);
+
}
TKJSBasicCell::~TKJSBasicCell()
{
JSValueUnprotect(ctx, mJName);
}
+ if (mJLocation)
+ {
+ JSValueUnprotect(ctx, mJLocation);
+ }
}
}
}
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)
{
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);
JSObjectRef mJsReceptorValues;
JSValueRef mJName;
+ JSValueRef mJLocation;
public:
static JSValueRef jsAPICB_getAxonValue(
JSStringRef propertyName,
JSValueRef *exception);
+ static JSValueRef jsAPICB_getLocation(
+ JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef *exception);
+
static void jsFinalize(JSObjectRef object);
};
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; }
#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)
{
}
-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)
{
{
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;
};
#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,
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);
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);
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.
}
else if (type == CELLTYPE_UIBASE)
{
- cell = new TKUICell(this, theName);
+ cell = new TKUICell(this, theLocation, theName);
}
else
{
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());
return true;
}
-static JSValueRef jsGlobalPrint(
+JSValueRef jsGlobalPrint(
JSContextRef ctx,
JSObjectRef jobj,
JSObjectRef jobjThis,
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;
+}
+
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);
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;}
};
#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
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;
}
#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);
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();
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"));
+