while(!mPendingCellDefinitions.empty())
{
PendingCellDefinition *cellInfo = mPendingCellDefinitions.front();
- TKCellCode *cellCode = mContainer->getCellCode(cellInfo->cellCodeName);
TKCell *newCell = NULL;
- if (cellCode)
+ if (cellInfo->useCellCodeClass)
{
- newCell = mContainer->createCell(cellInfo->location, cellInfo->cellName, cellCode, cellInfo->customScript);
+ TKCellCode *cellCode = mContainer->getCellCode(cellInfo->cellCodeClassOrType);
+ if (cellCode)
+ {
+ newCell = mContainer->createCellWithCellCodeClass(cellInfo->location, cellInfo->cellName, cellCode, cellInfo->customScript);
+ }
+ else
+ {
+ std::string message = std::string("Failed to construct cell: ").append(cellInfo->location).append("#").append(cellInfo->cellName);
+ message.append("\nCellCode '").append(cellInfo->cellCodeClassOrType).append("' couldn't be found.");
+ TKLog::printf("%s", message.c_str());
+ if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
+ {
+ dnGlobal()->setMessage1("Initialization failed");
+ dnGlobal()->setMessage2(message);
+ }
+ }
}
else
{
- std::string message = std::string("Failed to construct cell: ").append(cellInfo->location).append("#").append(cellInfo->cellName);
- message.append("\nCellCode '").append(cellInfo->cellCodeName).append("' couldn't be found.");
- TKLog::printf("%s", message.c_str());
- if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
- {
- dnGlobal()->setMessage1("Initialization failed");
- dnGlobal()->setMessage2(message);
- }
+ newCell = mContainer->createCellWithoutCellCodeClass(cellInfo->location, cellInfo->cellName, cellInfo->cellCodeClassOrType, cellInfo->customScript);
}
+
if (newCell == NULL)
{
std::string message = std::string("Failed to construct cell: ").append(cellInfo->location).append("#").append(cellInfo->cellName);
return true;
}
-void DNContainerBuilder::addCell(const char *path, std::string name, std::string cellcode, std::string customScript)
+void DNContainerBuilder::defineCellWithoutCellCodeClass(const char *path, std::string name, std::string type, std::string customScript)
+{
+ DEBUG_TRACE("\n===== Define cell (no CellCode class) ================ \nName:%s/%s\nType:%s\nCustom script:\n%s\n", path,name.c_str(), type.c_str(),customScript.c_str());
+
+ PendingCellDefinition *newCellDefine = new PendingCellDefinition();
+ newCellDefine->useCellCodeClass = false;
+ newCellDefine->location = path;
+ newCellDefine->cellName = name;
+ newCellDefine->cellCodeClassOrType = type;
+ newCellDefine->customScript = customScript;
+
+ mPendingCellDefinitions.push(newCellDefine);
+}
+
+void DNContainerBuilder::defineCellWithCellCodeClass(const char *path, std::string name, std::string cellcode, std::string customScript)
{
- DEBUG_TRACE("\n===== Define cell ================ \nName:%s/%s\nClass:%s\nCustom script:\n%s\n", path,name.c_str(), cellcode.c_str(),customScript.c_str());
+ DEBUG_TRACE("\n===== Define cell (CellCode class attached)=========== \nName:%s/%s\nClass:%s\nCustom script:\n%s\n", path,name.c_str(), cellcode.c_str(),customScript.c_str());
PendingCellDefinition *newCellDefine = new PendingCellDefinition();
+ newCellDefine->useCellCodeClass = true;
newCellDefine->location = path;
newCellDefine->cellName = name;
- newCellDefine->cellCodeName = getFQNString(path, cellcode.c_str());
+ newCellDefine->cellCodeClassOrType = getFQNString(path, cellcode.c_str());
newCellDefine->customScript = customScript;
mPendingCellDefinitions.push(newCellDefine);
}
-void DNContainerBuilder::addCellCode(const char *path, std::string name, std::string type, std::string cellScript)
+void DNContainerBuilder::defineCellCodeClass(const char *path, std::string name, std::string type, std::string cellScript)
{
std::string fqnName = getFQNString(path, name.c_str());
mContainer->createCellCode(fqnName, type, cellScript);
}
-void DNContainerBuilder::addConnection(const char *path, std::string origine, std::string destination, std::string name)
+void DNContainerBuilder::defineConnection(const char *path, std::string origine, std::string destination, std::string name)
{
PendingCellConnection *newConnection = new PendingCellConnection();
newConnection->connectionName = name;
DNXMLElement *element = xml->getRoot();
std::string cellName;
- std::string cellCodeName;
+ std::string cellCodeClassName;
std::string cellAPIType;
std::string script;
}
else if (define == "cellcode")
{
- cellCodeName = element->getAttributeValue("name");
+ cellCodeClassName = element->getAttributeValue("name");
cellAPIType = element->getAttributeValue("type");
defineDepth = element->depth;
}
else
{
std::string message = std::string("Syntax error while parsing ").append(path).append(". defnie='").append("' isn't correct.");
- TKLog::printf("%s", message.c_str());
+ TKLog::printf("%s\n", message.c_str());
if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
{
dnGlobal()->setMessage1("Initialization failed");
}
else if (parameter == "cellcode")
{
- cellCodeName = element->getAttributeValue("href");
+ cellCodeClassName = element->getAttributeValue("href");
+ cellAPIType = element->getAttributeValue("type");
+ if (cellCodeClassName.length() > 0 && cellAPIType.length() > 0)
+ {
+ std::string message = std::string("Syntax error while parsing ").append(path).append(". CellCode:").append(cellName);
+ message.append("\n'type' can't be defined here if you use CellCode class.");
+ TKLog::printf("%s\n", message.c_str());
+ if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
+ {
+ dnGlobal()->setMessage1("Initialization failed");
+ dnGlobal()->setMessage2(message);
+ }
+ }
}
else if (parameter== "connection")
{
{
rname = cellName;
}
- addConnection(path, cellName, target, rname);
+ defineConnection(path, cellName, target, rname);
}
else
{
defineDepth = -1;
if (cellName.length()>0)
{
- addCell(path, cellName, cellCodeName, script);
+ if (cellCodeClassName.length()>0)
+ {
+ defineCellWithCellCodeClass(path, cellName, cellCodeClassName, script);
+ }
+ else
+ {
+ defineCellWithoutCellCodeClass(path, cellName, cellAPIType, script);
+ }
+
cellName = "";
- cellCodeName = "";
+ cellCodeClassName = "";
+ cellAPIType = "";
script = "";
}
else
{
- addCellCode(path, cellCodeName, cellAPIType, script);
- cellCodeName = "";
+ defineCellCodeClass(path, cellCodeClassName, cellAPIType, script);
+ cellCodeClassName = "";
cellAPIType = "";
script = "";
}
TKLock mLock;
TKContainer *mContainer;
- void addCell(const char *path, std::string name, std::string cellcode, std::string customScript);
- void addCellCode(const char *path, std::string name, std::string type, std::string cellScript);
- void addConnection(const char *path, std::string origine, std::string destination, std::string name);
+ void defineCellWithoutCellCodeClass(const char *path, std::string name, std::string type, std::string customScript);
+ void defineCellWithCellCodeClass(const char *path, std::string name, std::string cellcode, std::string customScript);
+ void defineCellCodeClass(const char *path, std::string name, std::string type, std::string cellScript);
+ void defineConnection(const char *path, std::string origine, std::string destination, std::string name);
class PendingCellDefinition
{
public:
+ bool useCellCodeClass;
std::string location;
std::string cellName;
- std::string cellCodeName;
+ std::string cellCodeClassOrType;
std::string customScript;
};
#include "DNEngine.h"
#include "DNAlert.h"
#include "DNXML.h"
+#include "DNXMLElement.h"
#include "DNGlobal.h"
#include "DNUtils.h"
+#include "TKLog.h"
#include <stdlib.h>
+#include <sstream>
+#include <iostream>
DNEngine::DNEngine(const char *contentPath) :
mContainer(NULL),mPortNumber(9080),mHTTPServer(NULL),mValid(false), mDoTickThread(NULL)
{
mTimeKeeper = new DNTimeKeeper();
mContainer = TKContainer::createContainer();
-
+ mUIPath = "/ui/index.html";
+
dnGlobal()->updateRunningStatus(DNGlobal::STOPPED);
std::string basePath(contentPath);
bool DNEngine::parseSettingFile(const char *contentRoot)
{
+ bool valid = false;
+
DNXML *xml = DNXML::createXMLFromFile(contentRoot, "property.xml");
if (xml)
{
- //TODO
+ valid = true;
+ DNXMLElement *element = xml->getRoot();
+ if (element->name != "dennco")
+ {
+ valid = false;
+ std::string message = "First element of property.xml should be <dennco>";
+ TKLog::printf("ERROR wile parsing property.xml file.\n%s\n",message.c_str());
+ if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
+ {
+ dnGlobal()->setMessage1("Initialization failed");
+ dnGlobal()->setMessage2(message);
+ }
+ else
+ {
+ dnGlobal()->setMessage1("Initialization failed");
+ }
+ }
+
+ if (valid)
+ {
+ DNXMLElement *e = element->inner;
+ while(e)
+ {
+ if (e->name == "TickIntervalSec")
+ {
+ std::istringstream is(e->text);
+ float t = 0.0;
+ is >> t;
+ if (t>0)
+ {
+ setTickIntervalSec(t);
+ }
+ else
+ {
+ valid = false;
+ std::string message = "Error in property.xml. TickIntervalSec is not configured properly.";
+ TKLog::printf("ERROR wile parsing property.xml file.\n%s\n",message.c_str());
+ if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
+ {
+ dnGlobal()->setMessage1("Initialization failed");
+ dnGlobal()->setMessage2(message);
+ }
+ else
+ {
+ dnGlobal()->setMessage1("Initialization failed");
+ }
+ }
+ }
+ else if (e->name == "UIPath")
+ {
+ mUIPath = e->text;
+ }
+ else if (e->name == "EnableHTTPServer")
+ {
+
+ }
+ else if (e->name == "EnableSerialServer")
+ {
+
+ }
+ e = e->next;
+ }
+ }
+
delete xml;
}
- return true;
+ return valid;
}
bool DNEngine::parseContainerFile(const char *containerRoot)
std::string DNEngine::getUIPath()
{
- //TODO
- return "/ui/index.html";
+ return mUIPath;
}
DNHTTPServer *mHTTPServer;
DNTimeKeeper *mTimeKeeper;
bool mValid;
+ std::string mUIPath;
DNThread *mDoTickThread;
#include "DNFileList.h"
-DNFileList::DNFileList(std::string f) : prev(NULL),next(NULL)
+DNFileList::DNFileList(std::string f) : next(NULL),prev(NULL)
{
filePath = f;
}
#include "DNXMLElement.h"
DNXMLElement::DNXMLElement(std::string _name):
-name(_name),outer(NULL),inner(NULL),next(NULL),depth(0),text("")
+outer(NULL),inner(NULL),next(NULL),depth(0),name(_name),text("")
{
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
- mEngine(NULL), mWebInterface(NULL)
+ mEngine(NULL), mWebInterface(NULL),
+ mHasPendingConsoleMessage(false)
{
ui->setupUi(this);
QVariant defaultPath(QDir::homePath());
QString contentPath = settings.value("content_path", defaultPath).toString();
- mConsole = new TKConsole();
- TKLog::setDestination(mConsole);
ui->filePath->setText(contentPath);
+
+ ui->console->document()->setMaximumBlockCount(2000);
+ TKLog::setDestination(this);
}
MainWindow::~MainWindow()
}
}
+void MainWindow::paintEvent( QPaintEvent * event )
+{
+ mConsoleLock.lock();
+ if (mHasPendingConsoleMessage)
+ {
+ ui->console->append(mPendingConsoleMessage);
+ mPendingConsoleMessage.clear();
+ mHasPendingConsoleMessage = false;
+ }
+ mConsoleLock.unlock();
+
+ QMainWindow::paintEvent(event);
+}
+
+void MainWindow::vprintf(const char *fmt, va_list ap)
+{
+ QString msg = QString().vsprintf(fmt,ap);
+ qDebug() << msg << endl;
+ mConsoleLock.lock();
+ if (mHasPendingConsoleMessage)
+ mPendingConsoleMessage.append("\n");
+ mPendingConsoleMessage.append(msg);
+ mHasPendingConsoleMessage = true;
+ mConsoleLock.unlock();
+ update();
+}
+
+void MainWindow::vDebugPrintf(const char *fmt, va_list ap)
+{
+#ifdef DEBUG
+ QString msg = QString().vsprintf(fmt,ap);
+ qDebug() << "DEBUG:" << msg << endl;
+#endif
+}
+
+
#include <QMainWindow>
+#include "TKConsole.h"
+#include "TKLock.h"
+
class DNEngine;
class TKConsole;
class DNWebInterface;
class MainWindow;
}
-class MainWindow : public QMainWindow
+class MainWindow : public QMainWindow, TKConsole
{
Q_OBJECT
protected:
virtual void closeEvent(QCloseEvent *event);
+ virtual void paintEvent(QPaintEvent *event );
private slots:
void on_chooseDirButton_clicked();
DNEngine *mEngine;
TKConsole *mConsole;
DNWebInterface *mWebInterface;
+
+ virtual void vprintf(const char *fmt, va_list arg);
+ virtual void vDebugPrintf(const char *fmt, va_list arg);
+ TKLock mConsoleLock;
+ QString mPendingConsoleMessage;
+ bool mHasPendingConsoleMessage;
+
};
#endif // MAINWINDOW_H
<widget class="QWidget" name="dockWidgetContents_3">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
- <widget class="QTextBrowser" name="textBrowser_2"/>
+ <widget class="QTextEdit" name="console"/>
</item>
</layout>
</widget>
{
}
-
TKCellCodeInstance* DNQSCellCode::createCellCodeInstance(TKCell *owner, const void *data)
{
if (!mCellContainer)
QScriptContext *context = scriptEngine->pushContext();
context->setThisObject(instance);
context->setActivationObject(instance);
- QScriptProgram initCode(QString((const char*)data));
- scriptEngine->evaluate(initCode);
+ QString customScriptStr((const char*)data);
+ QScriptProgram customScript(customScriptStr);
+ scriptEngine->evaluate(customScript);
scriptEngine->popContext();
mQSCellContainer = mQSEngine->newObject();
mQSGlobalObject.setProperty("__private_DNCellContainer__",mQSCellContainer);
+
+ std::string pname = "_";
+ pname.append(CELLTYPE_JSBASIC);
+ mEmptyCellClassForB = createCellCode(pname,CELLTYPE_JSBASIC,"");
+ pname = "_";
+ pname.append(CELLTYPE_UIBASIC);
+ mEmptyCellClassForUB = createCellCode(pname,CELLTYPE_UIBASIC,"");
}
DNQSContainer::~DNQSContainer()
if (mQSEngine)
delete mQSEngine;
}
+TKCell* DNQSContainer::createCellWithoutCellCodeClass(std::string theLocation, std::string theName, std::string type, std::string customScript)
+{
+ TKCell *cell = NULL;
+ TKCellCode *cellCode = NULL;
+ if (type == CELLTYPE_JSBASIC || type.length() == 0)
+ {
+ cell = new DNQSBasicCell(this, theLocation, theName, false);
+ cellCode = mEmptyCellClassForB;
+ }
+ else if (type == CELLTYPE_UIBASIC)
+ {
+ cell = new DNQSBasicCell(this, theLocation, theName, true);
+ cellCode = mEmptyCellClassForUB;
+ }
+ else
+ {
+ std::string message = std::string("Failed to construct cell '").append(theLocation).append("#").append(theName);
+ message.append("'\nThe cellcode requires type '").append(type).append("' but it's not a supported type.");
+ TKLog::printf("%s", message.c_str());
+ if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
+ {
+ dnGlobal()->setMessage1("Initialization failed");
+ dnGlobal()->setMessage2(message);
+ }
+ }
+
+
+ if (cell)
+ {
+ std::string fqnName = getFQNString(theLocation.c_str(), theName.c_str());
+ mCells.insert(TKCellMap::value_type(fqnName, cell));
+ cell->setCellCode(cellCode,(const void*)customScript.c_str());
+
+ if (cell->isInterface())
+ {
+ mInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ }
+ }
+ 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* DNQSContainer::createCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string startupScript)
+TKCell* DNQSContainer::createCellWithCellCodeClass(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript)
{
TKCell *cell = NULL;
{
std::string fqnName = getFQNString(theLocation.c_str(), theName.c_str());
mCells.insert(TKCellMap::value_type(fqnName, cell));
- cell->setCellCode(cellCode,(const void*)startupScript.c_str());
+ cell->setCellCode(cellCode,(const void*)customScript.c_str());
if (cell->isInterface())
{
DNQSContainer();
virtual ~DNQSContainer();
- virtual TKCell* createCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string startupScript);
+ virtual TKCell* createCellWithoutCellCodeClass(std::string theLocation, std::string theName, std::string type, std::string customScript);
+ virtual TKCell* createCellWithCellCodeClass(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript);
virtual TKCellCode* createCellCode(std::string theName, std::string theAPIType, std::string code);
- virtual bool doTick(float time);
+ virtual bool doTick(float time);
- virtual void setValue(std::string key, float value);
- virtual float getValue(std::string key);
+ virtual void setValue(std::string key, float value);
+ virtual float getValue(std::string key);
inline QScriptEngine* getScriptEngine() { return mQSEngine; }
inline QScriptValue getScriptGlobalObject() { return mQSGlobalObject; }
QScriptEngine *mQSEngine;
QScriptValue mQSGlobalObject;
QScriptValue mQSCellContainer;
+ TKCellCode *mEmptyCellClassForB;
+ TKCellCode *mEmptyCellClassForUB;
};
#endif // DNQSCONTAINER_H
#include <string>
TKCell::TKCell(TKContainer *container, std::string location, std::string name, bool canIntarface)
-: mContainer(container), mAxon(NULL), mCellCodeInstance(NULL), mLocation(location), mName(name), mCanInterface(canIntarface)
+: mName(name), mLocation(location), mContainer(container), mAxon(NULL), mCellCodeInstance(NULL), mCanInterface(canIntarface)
{
mAxon = new TKAxon(this);
}
public:
static TKContainer* createContainer();
- virtual ~TKContainer();
+ virtual ~TKContainer();
const TKCellMap* getCells() { return &mCells; }
const TKCellCodeMap* getCellCodes() { return &mCellCodes; }
void setContentPath(std::string contentPath) { mContentPath = contentPath; }
std::string getContentPath() { return mContentPath; }
- TKCell* getCell(std::string theFQNName);
- TKCell* getInterfaceCell(std::string theFQNName);
- TKCellCode* getCellCode(std::string theCellCodeName);
-
- 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;
+ TKCell* getCell(std::string theFQNName);
+ TKCell* getInterfaceCell(std::string theFQNName);
+ TKCellCode* getCellCode(std::string theCellCodeName);
+
+ virtual TKCell* createCellWithoutCellCodeClass(std::string theLocation, std::string theName, std::string type, std::string customScript) = 0;
+ virtual TKCell* createCellWithCellCodeClass(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript) = 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;
+ virtual bool doTick(float time) = 0;
+
+ virtual void setValue(std::string key, float value) = 0;
+ inline virtual float getValue(std::string key) = 0;
protected:
TKContainer() {}
- TKCellMap mCells;
+ TKCellMap mCells;
TKCellMap mInterfaceCells;
TKCellCodeMap mCellCodes;
std::string mContentPath;
-
+
};
#endif