layer2/platform/qt/qtdndirectoryimpl.cpp \
layer2/platform/qt/qtdnxmlimpl.cpp \
layer3/DNAlert.cpp \
- layer3/TKUICell.cpp \
layer3/DNTimeKeeper.cpp \
layer3/DNThread.cpp \
layer3/DNSerialPort.cpp \
layer3/platform/qt/qtdnalertimpl.cpp \
layer3/platform/qt/qtdntimekeeperimpl.cpp \
layer3/platform/qt/qtdnthreadimpl.cpp \
- layer3/platform/qt/qtdnserialportimpl.cpp
+ layer3/platform/qt/qtdnserialportimpl.cpp \
+ layer3/DNCellInterfaceable.cpp
HEADERS += \
layer1/TKLockImpl.h \
layer2/platform/qt/qtdnxmlimpl.h \
layer3/DNAlertImpl.h \
layer3/DNAlert.h \
- layer3/TKUICell.h \
layer3/DNTimeKeeperImpl.h \
layer3/DNTimeKeeper.h \
layer3/DNThreadImpl.h \
layer3/platform/qt/qtsimplehttpserverimpl.h \
layer3/platform/qt/qtdnserialportimpl.h \
layer3/platform/qt/qtdntimekeeperimpl.h \
- layer1/DNStorageImpl.h
+ layer1/DNStorageImpl.h \
+ layer3/DNCellInterfaceable.h
FORMS += layer3/QtDennco/mainwindow.ui
FORMS += layer3/QtDennco/portinfodialog.ui
#include "TKLog.h"
#include <string>
-TKCell::TKCell(TKContainer *container, std::string location, std::string name, bool canIntarface)
-: mName(name), mLocation(location), mContainer(container), mAxon(NULL), mCellCodeInstance(NULL), mCanInterface(canIntarface)
+TKCell::TKCell(TKContainer *container, std::string location, std::string name, bool canIntarfaceIn, bool canInterfaceOut)
+: mName(name), mLocation(location), mContainer(container), mAxon(NULL), mCellCodeInstance(NULL),
+ mCanInterfaceIn(canIntarfaceIn), mCanInterfaceOut(canInterfaceOut), mReceptorValueUpdated(false)
{
}
return receptor;
}
+bool TKCell::enterDoTick(float time, bool forceUpdate)
+{
+ if (!forceUpdate && !mReceptorValueUpdated)
+ return false;
+
+ bool r = doTick(time);
+ mReceptorValueUpdated = false;
+
+ return r;
+}
+
+void TKCell::updateReceptorValue()
+{
+ for ( TKReceptorMap::iterator it = mReceptors.begin(); it != mReceptors.end(); ++it )
+ {
+ if (it->second->update())
+ {
+ mReceptorValueUpdated = true;
+ }
+ }
+}
class TKCell
{
public:
- TKCell(TKContainer *container, std::string location, std::string name, bool canInterface);
+ TKCell(TKContainer *container, std::string location, std::string name, bool canInterfaceIn, bool canInterfaceOut);
virtual ~TKCell();
void init();
bool connectTo(std::string connectionName, TKCell *targetReceptor);
inline TKContainer* getContainer() const { return mContainer; }
- bool isInterface() { return mCanInterface; }
+ bool canInterfaceIn() { return mCanInterfaceIn; }
+ bool canInterfaceOut() { return mCanInterfaceOut; }
+ bool enterDoTick(float time, bool forceUpdate);
virtual bool doTick(float time) = 0;
virtual bool doInit() = 0;
virtual bool doDestroy() = 0;
+ virtual void updateReceptorValue();
protected:
virtual TKReceptor* createReceptor(std::string name);
TKAxon *mAxon;
TKReceptorMap mReceptors;
TKCellCodeInstance *mCellCodeInstance;
- bool mCanInterface;
+ bool mCanInterfaceIn;
+ bool mCanInterfaceOut;
+ bool mReceptorValueUpdated;
};
bool TKContainer::doInit()
{
- mLock.lock();
+ DNLocker locker(&mLock);
+
for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
it->second->doInit();
}
- mLock.unlock();
return true;
}
-bool TKContainer::doTick(float time)
+bool TKContainer::doTickInputInterfaces(float time)
{
- mLock.lock();
- for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
- it->second->doTick(time);
+ DNLocker locker(&mLock);
+
+ for ( TKCellMap::iterator it = mInpInterfaceCells.begin(); it != mInpInterfaceCells.end(); ++it )
+ {
+ it->second->updateReceptorValue();
+ }
+
+ for ( TKCellMap::iterator it = mInpInterfaceCells.begin(); it != mInpInterfaceCells.end(); ++it )
+ {
+ it->second->enterDoTick(time,true);
+ }
+ return true;
+}
+
+bool TKContainer::doTickOutputInterfaces(float time)
+{
+ DNLocker locker(&mLock);
+
+ for ( TKCellMap::iterator it = mOutInterfaceCells.begin(); it != mOutInterfaceCells.end(); ++it )
+ {
+ it->second->updateReceptorValue();
+ }
+
+ for ( TKCellMap::iterator it = mOutInterfaceCells.begin(); it != mOutInterfaceCells.end(); ++it )
+ {
+ it->second->enterDoTick(time,true);
+ }
+ return true;
+}
+
+bool TKContainer::doTickSignalScan(float time)
+{
+ DNLocker locker(&mLock);
+
+ for ( TKCellMap::iterator it = mNonInterfaceCells.begin(); it != mNonInterfaceCells.end(); ++it )
+ {
+ it->second->updateReceptorValue();
+ }
+
+ for ( TKCellMap::iterator it = mNonInterfaceCells.begin(); it != mNonInterfaceCells.end(); ++it )
+ {
+ it->second->enterDoTick(time,false);
+ }
+ return true;
+}
+
+bool TKContainer::doTickFullScan(float time)
+{
+ DNLocker locker(&mLock);
+
+ for ( TKCellMap::iterator it = mNonInterfaceCells.begin(); it != mNonInterfaceCells.end(); ++it )
+ {
+ it->second->updateReceptorValue();
+ }
+
+ for ( TKCellMap::iterator it = mNonInterfaceCells.begin(); it != mNonInterfaceCells.end(); ++it )
+ {
+ it->second->enterDoTick(time,true);
}
- mLock.unlock();
return true;
}
bool TKContainer::doDestroy()
{
- mLock.lock();
+ DNLocker locker(&mLock);
for ( TKCellMap::iterator it = mCells.begin(); it != mCells.end(); ++it ) {
(it->second)->doDestroy();
delete it->second;
}
mCells.clear();
- mInterfaceCells.clear();
+ mInpInterfaceCells.clear();
+ mOutInterfaceCells.clear();
- mLock.unlock();
return true;
}
if (type == CELLTYPE_JSBASIC || type.length() == 0)
{
- cell = cellFactory(theLocation, theName, type, false);
+ cell = cellFactory(theLocation, theName, type, false, false);
}
else if (type == CELLTYPE_IN)
{
- cell = cellFactory(theLocation, theName, type, true);
+ cell = cellFactory(theLocation, theName, type, true, false);
noScript = true;
}
else if (type == CELLTYPE_OUT)
{
- cell = cellFactory(theLocation, theName, type, true);
+ cell = cellFactory(theLocation, theName, type, false, true);
noScript = true;
}
else if (type == CELLTYPE_BASICSTORAGE)
{
- cell = cellFactory(theLocation, theName, type, false);
+ cell = cellFactory(theLocation, theName, type, false, false);
}
else
{
{
std::string fqnName = getFQNString(theLocation.c_str(), theName.c_str());
mCells.insert(TKCellMap::value_type(fqnName, cell));
- if (cell->isInterface())
+ bool interface = false;
+ if (cell->canInterfaceIn())
{
- mInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ mInpInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ interface = true;
+ }
+ if (cell->canInterfaceOut())
+ {
+ mOutInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ interface = true;
+ }
+ if (!interface)
+ {
+ mNonInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
}
if (!noScript)
{
if (type == CELLTYPE_JSBASIC)
{
- cell = cellFactory(theLocation, theName, type, false);
+ cell = cellFactory(theLocation, theName, type, false, false);
}
else if (type == CELLTYPE_BASICSTORAGE)
{
- cell = cellFactory(theLocation, theName, type, false);
+ cell = cellFactory(theLocation, theName, type, false, false);
}
else if (type == CELLTYPE_OUT)
{
mCells.insert(TKCellMap::value_type(fqnName, cell));
cell->setCellCode(cellCode,(const void*)customScript.c_str());
- if (cell->isInterface())
+ bool interface = false;
+ if (cell->canInterfaceIn())
+ {
+ mInpInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ interface = true;
+ }
+ if (cell->canInterfaceOut())
+ {
+ mOutInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ interface = true;
+ }
+ if (!interface)
{
- mInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ mNonInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
}
}
else
}
}
-TKCell* TKContainer::getInterfaceCell(std::string theFQNName)
+TKCell* TKContainer::getInputInterfaceCell(std::string theFQNName)
{
- DNLocker locker(&mLock);
-
- if (mInterfaceCells.empty())
+ TKCellMap::iterator iti = mInpInterfaceCells.find(theFQNName);
+ if (iti == mInpInterfaceCells.end())
{
return NULL;
}
- TKCellMap::iterator it = mInterfaceCells.find(theFQNName);
- if (it == mInterfaceCells.end())
+ else
+ {
+ return iti->second;
+ }
+}
+
+TKCell* TKContainer::getOutputInterfaceCell(std::string theFQNName)
+{
+ TKCellMap::iterator ito = mOutInterfaceCells.find(theFQNName);
+ if (ito == mInpInterfaceCells.end())
{
return NULL;
}
else
{
- return it->second;
+ return ito->second;
}
}
DNStorage* getDataStore() { return mStorage; }
bool releaseDataStore();
TKCell* getCell(std::string theFQNName);
- TKCell* getInterfaceCell(std::string theFQNName);
+ TKCell* getInputInterfaceCell(std::string theFQNName);
+ TKCell* getOutputInterfaceCell(std::string theFQNName);
TKCellCode* getCellCode(std::string theCellCodeName);
- bool doInit();
- bool doTick(float time);
- bool doDestroy();
+ virtual bool doInit();
+ virtual bool doTickInputInterfaces(float time);
+ virtual bool doTickOutputInterfaces(float time);
+ virtual bool doTickSignalScan(float time);
+ virtual bool doTickFullScan(float time);
+ virtual bool doDestroy();
virtual TKCell* addCell(std::string theLocation, std::string theName, std::string type, std::string customScript);
virtual TKCell* addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript);
virtual void setValue(std::string key, float value) = 0;
inline virtual float getValue(std::string key) const = 0;
- virtual TKCell* cellFactory(std::string location, std::string name, std::string type, bool canInterface = true) = 0;
+ virtual TKCell* cellFactory(std::string location, std::string name, std::string type, bool canInterfaceIn, bool canInterfaceOut) = 0;
virtual TKAxon* axonFactory(TKCell *theOwner) = 0;
virtual TKReceptor* receptorFactory(TKCell *theOwner) = 0;
virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner) = 0;
protected:
TKContainer();
TKCellMap mCells;
- TKCellMap mInterfaceCells;
+ TKCellMap mInpInterfaceCells;
+ TKCellMap mOutInterfaceCells;
+ TKCellMap mNonInterfaceCells;
TKCellCodeMap mCellCodes;
std::string mContainerRootPath;
DNStorage *mStorage;
#include "TKAxon.h"
#include "TKLog.h"
+bool TKReceptor::update()
+{
+ if (mTerminal)
+ {
+ float newValue = mTerminal->getValue();
+ if (newValue != mValue)
+ {
+ mValue = newValue;
+ return true;
+ }
+ }
+ return false;
+}
+
float TKReceptor::getValue()
{
#ifdef DEBUG_CONNECTION
TKLog::debugPrintf("TKReceptor::getValue called: owner:%s tarminal owner:%s value:%f\n",
mOwner->getName().c_str(),
mTerminal->getOwner()->getOwner()->getName().c_str(),
- mTerminal->getValue());
+ mValue;
#endif
- if (mTerminal)
- {
- return mTerminal->getValue();
- }
- return 0.0;
+ return mValue;
}
void TKReceptor::setTarget(TKAxonTerminal *theTerminal)
#ifndef __INCLUDE_TKRECEPTOR__
#define __INCLUDE_TKRECEPTOR__
+#include "math.h"
+
class TKCell;
class TKAxonTerminal;
class TKReceptor
{
public:
- TKReceptor(TKCell *theOwner) : mOwner(theOwner), mTerminal(0) {}
+ TKReceptor(TKCell *theOwner) : mOwner(theOwner), mTerminal(0), mValue(NAN) {}
virtual ~TKReceptor() {}
void setTarget(TKAxonTerminal *theTerminal);
+ bool update();
float getValue();
protected:
TKCell *mOwner;
TKAxonTerminal *mTerminal;
+ float mValue;
};
#endif
void TKConsole::vprintf(TKLog::MessageType type, const char *fmt, va_list ap)
{
- (type);
+ (void)type;
QString msg = QString().vsprintf(fmt,ap);
qDebug() << msg << endl;
}
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-// Created by tkawata on 12/30/2011.
+// Created by tkawata on Nov 21,2012.
//
-#include "TKReceptor.h"
-#include "TKAxon.h"
-#include "TKUICell.h"
-
-const std::string TKUICell::RECEPTORNAME = "input";
-
-bool TKUICell::doTick(float time)
-{
- TKReceptorMap::iterator it = mReceptors.find(RECEPTORNAME);
- if (it != mReceptors.end())
- {
- mIsInput = true;
- TKReceptor *receptor = it->second;
- float v = receptor->getValue();
- mAxon->setValue(v);
- }
+#include "DNCellInterfaceable.h"
- return true;
-}
+#include "TKAxon.h"
-void TKUICell::setValue(float value)
+DNCellInterfaceable::DNCellInterfaceable(TKContainer *container, std::string location, std::string name, bool canInterfaceIn, bool canInterfaceOut)
+ :TKCell(container, location, name, canInterfaceIn, canInterfaceOut)
{
- mAxon->setValue(value);
-
}
-float TKUICell::getValue()
+float DNCellInterfaceable::getValue() const
{
return mAxon->getValue();
}
-
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-// Created by tkawata on 12/30/2011.
+// Created by tkawata on Nov 21,2012.
//
-#ifndef dennco_TKUICell_h
-#define dennco_TKUICell_h
-
-#include <string>
+#ifndef DNCELLINTERFACEABLE_H
+#define DNCELLINTERFACEABLE_H
#include "TKCell.h"
-class TKUICell : public TKCell
+class DNCellInterfaceable : public TKCell
{
public:
- TKUICell(TKContainer *container, std::string location, std::string name) : TKCell(container, location, name, true) , mIsInput(false) {}
- virtual ~TKUICell() {}
- virtual bool doTick(float time);
- virtual bool doInit() { return false; }
- virtual bool doDestroy() { return false; }
+ DNCellInterfaceable(TKContainer *container, std::string location, std::string name, bool canInterfaceIn, bool canInterfaceOut);
+ virtual ~DNCellInterfaceable() {}
+
+ float getValue() const;
+ virtual void setValue(float value) = 0;
- void setValue(float value);
- float getValue();
- bool isUIInputCell() { return mIsInput; }
-
- const static std::string RECEPTORNAME;
-
-public:
- bool mIsInput;
};
-#endif
+#endif // DNCELLINTERFACEABLE_H
#include "TKLock.h"
#include "TKContainer.h"
-#include "TKUICell.h"
+#include "DNCellInterfaceable.h"
#include "DNTimeKeeper.h"
#include "DNServerHTTP.h"
#include "DNServerSerialPort.h"
#include <iostream>
DNEngine::DNEngine(const char *contentPath) :
- mContainer(NULL),mPortNumber(9080),mHTTPServer(NULL),mSerialServer(NULL),mSerialServerEnabled(false),mValid(false), mDoTickThread(NULL)
+ mContainer(NULL),mPortNumber(9080),mHTTPServer(NULL),mSerialServer(NULL),mSerialServerEnabled(false),mValid(false), mDoTickThread(NULL), mNumUpdateScan(5)
{
mTimeKeeper = new DNTimeKeeper();
mContainer = TKContainer::createContainer();
is >> t;
if (t>0)
{
- setTickIntervalSec(t);
+ setTickIntervalSec(t/(mNumUpdateScan+1));
}
else
{
DNEngine *engine = (DNEngine*)self;
+ int scanCount = 0;
while(dnGlobal()->getRunningStatus() == DNGlobal::RUNNIING && engine->isValid())
{
- engine->mContainer->doTick(engine->mTimeKeeper->getTickTime());
+ if (scanCount == 0)
+ {
+ //scan input and all non-interface cells
+ engine->mContainer->doTickInputInterfaces(engine->mTimeKeeper->getTickTime());
+ engine->mContainer->doTickFullScan(engine->mTimeKeeper->getTickTime());
+ }
+ else
+ {
+ //scan non-interface cells which has updated receptor value
+ engine->mContainer->doTickSignalScan(engine->mTimeKeeper->getTickTime());
+ }
+
+ if (scanCount == engine->mNumUpdateScan)
+ {
+ //scan output cells
+ engine->mContainer->doTickOutputInterfaces(engine->mTimeKeeper->getTickTime());
+ }
+ scanCount++;
+ if (scanCount > engine->mNumUpdateScan)
+ {
+ scanCount = 0;
+ }
engine->mTimeKeeper->sleepUntilNextInterval();
}
return 0;
std::string fqn = getFQNString("/",path);
- TKUICell *cell = (TKUICell*)mContainer->getInterfaceCell(fqn);
+ DNCellInterfaceable *cell = dynamic_cast<DNCellInterfaceable*>(mContainer->getOutputInterfaceCell(fqn));
float result = 0;
if (cell)
{
return false;
std::string fqn = getFQNString("/",path);
- TKUICell *cell = (TKUICell*)mContainer->getInterfaceCell(fqn);
+ DNCellInterfaceable *cell = dynamic_cast<DNCellInterfaceable*>(mContainer->getInputInterfaceCell(fqn));
bool result = false;
if (cell)
{
std::string mUIPath;
DNThread *mDoTickThread;
+ int mNumUpdateScan;
};
#include "TKCellCodeInstance.h"
#include "DNUtils.h"
-DNQSBasicCell::DNQSBasicCell(DNQSContainer *container, std::string location, std::string name, bool canInterface):
- DNQSCellBase(container,location,name,canInterface)
+DNQSBasicCell::DNQSBasicCell(DNQSContainer *container, std::string location, std::string name, bool canInterfaceIn, bool canInterfaceOut):
+ DNQSCellBase(container,location,name,canInterfaceIn, canInterfaceOut)
{
- mEngine = container->getScriptEngine();
-
- mQSAPIInstance = mEngine->newObject();
- mQSAPIInstance.setProperty("location", QScriptValue(QString::fromStdString(location)),QScriptValue::ReadOnly|QScriptValue::Undeletable);
- mQSAPIInstance.setProperty("name", QScriptValue(QString::fromStdString(name)),QScriptValue::ReadOnly|QScriptValue::Undeletable);
-
- mQSReceptors = mEngine->newObject();
- mQSAPIInstance.setProperty("receptors", mQSReceptors,QScriptValue::ReadOnly|QScriptValue::Undeletable);
-
- mAxonValueHandle = mEngine->toStringHandle("axonValue");
}
DNQSBasicCell::~DNQSBasicCell()
}
-//TODO: find better way
-void DNQSBasicCell::prepareValueForScript()
-{
- //update receptor values
- for ( TKReceptorMap::iterator it = mReceptors.begin(); it != mReceptors.end(); ++it ) {
- mQSReceptors.setProperty(QString::fromStdString(it->first), QScriptValue(it->second->getValue()),QScriptValue::ReadOnly);
- }
- //update axonValue
- mQSAPIInstance.setProperty(mAxonValueHandle,QScriptValue(mAxon->getValue()));
-}
-
-//TODO: find better way
-void DNQSBasicCell::reflectValueFromScript()
-{
- QScriptValue value = mQSAPIInstance.property(mAxonValueHandle);
- mAxon->setValue(value.toNumber());
-}
-
-void DNQSBasicCell::handleScriptException(const char *funcName)
-{
- std::string message = "Script Error! in ";
- message += mLocation;
- message += "#";
- message += funcName;
- if (mEngine->hasUncaughtException())
- {
- QScriptValue error = mEngine->uncaughtException();
- QString errorString = error.toString();
- message += "\n";
- message += errorString.toStdString();
- mEngine->clearExceptions();
- }
- dnNotifyWarning("Script error", message);
-}
-
bool DNQSBasicCell::doTick(float time)
{
if (!mCellCodeInstance) return false;
class DNQSBasicCell : public DNQSCellBase
{
public:
- DNQSBasicCell(DNQSContainer *container, std::string location, std::string name, bool canInterface = false);
+ DNQSBasicCell(DNQSContainer *container, std::string location, std::string name, bool canInterfaceIn, bool canInterfaceOut);
virtual ~DNQSBasicCell();
virtual bool doTick(float time);
virtual bool doInit();
virtual bool doDestroy();
-
-private:
- void prepareValueForScript();
- void reflectValueFromScript();
- void handleScriptException(const char *funcName);
-
-protected:
- QScriptEngine *mEngine;
- QScriptValue mQSReceptors;
- QScriptString mAxonValueHandle;
};
#endif // DNQSBASICCELL_H
QScriptString DNQSBasicStorageCell::mVQSString;
QScriptString DNQSBasicStorageCell::mPushQSString;
-DNQSBasicStorageCell::DNQSBasicStorageCell(DNQSContainer *container, std::string location, std::string name, bool canInterface) :
- DNQSBasicCell(container, location, name, canInterface)
+DNQSBasicStorageCell::DNQSBasicStorageCell(DNQSContainer *container, std::string location, std::string name, bool canInterfaceIn, bool canInterfaceOut) :
+ DNQSBasicCell(container, location, name, canInterfaceIn, canInterfaceOut)
{
mQSStorage = mEngine->newObject();
class DNQSBasicStorageCell : public QObject, public DNQSBasicCell
{
public:
- DNQSBasicStorageCell(DNQSContainer *container, std::string location, std::string name, bool canInterface = false);
+ DNQSBasicStorageCell(DNQSContainer *container, std::string location, std::string name, bool canInterfaceIn, bool canInterfaceOut);
virtual ~DNQSBasicStorageCell();
protected:
//
#include "dnqscellbase.h"
+#include "dnqscontainer.h"
+#include "TKAxon.h"
+#include "TKReceptor.h"
+#include "TKLog.h"
+#include "DNUtils.h"
+
+
+DNQSCellBase::DNQSCellBase(DNQSContainer *container, std::string location, std::string name, bool canInterfaceIn, bool canInterfaceOut)
+ : TKCell(container,location,name,canInterfaceIn, canInterfaceOut)
+{
+ mEngine = container->getScriptEngine();
+
+ mQSAPIInstance = mEngine->newObject();
+ mQSAPIInstance.setProperty("location", QScriptValue(QString::fromStdString(location)),QScriptValue::ReadOnly|QScriptValue::Undeletable);
+ mQSAPIInstance.setProperty("name", QScriptValue(QString::fromStdString(name)),QScriptValue::ReadOnly|QScriptValue::Undeletable);
+
+ mQSReceptors = mEngine->newObject();
+ mQSAPIInstance.setProperty("receptors", mQSReceptors,QScriptValue::ReadOnly|QScriptValue::Undeletable);
+
+ mAxonValueHandle = mEngine->toStringHandle("axonValue");
+}
+
+DNQSCellBase::~DNQSCellBase()
+{
+
+}
+
+void DNQSCellBase::prepareValueForScript()
+{
+ //update receptor values
+ for ( TKReceptorMap::iterator it = mReceptors.begin(); it != mReceptors.end(); ++it )
+ {
+ mQSReceptors.setProperty(QString::fromStdString(it->first), QScriptValue(it->second->getValue()),QScriptValue::ReadOnly);
+ }
+ //update axonValue
+ mQSAPIInstance.setProperty(mAxonValueHandle,QScriptValue(mAxon->getValue()));
+
+ mReceptorValueUpdated = false;
+
+ return;
+}
+
+void DNQSCellBase::reflectValueFromScript()
+{
+ QScriptValue value = mQSAPIInstance.property(mAxonValueHandle);
+ mAxon->setValue(value.toNumber());
+}
+
+void DNQSCellBase::handleScriptException(const char *funcName)
+{
+ std::string message = "Script Error! in ";
+ message += mLocation;
+ message += "#";
+ message += funcName;
+ if (mEngine->hasUncaughtException())
+ {
+ QScriptValue error = mEngine->uncaughtException();
+ QString errorString = error.toString();
+ message += "\n";
+ message += errorString.toStdString();
+ mEngine->clearExceptions();
+ }
+ dnNotifyWarning("Script error", message);
+}
class DNQSCellBase : public TKCell
{
public:
- DNQSCellBase(DNQSContainer *container, std::string location, std::string name, bool canInterface)
- : TKCell((TKContainer*)container, location, name, canInterface) {}
- virtual ~DNQSCellBase() {}
+ DNQSCellBase(DNQSContainer *container, std::string location, std::string name, bool canInterfaceIn, bool canInterfaceOut);
+ virtual ~DNQSCellBase();
QScriptValue getCellAPI() { return mQSAPIInstance; }
+ void prepareValueForScript();
+ void reflectValueFromScript();
+ void handleScriptException(const char *funcName);
+
protected:
- QScriptValue mQSAPIInstance;
+ QScriptValue mQSAPIInstance;
+ QScriptEngine *mEngine;
+ QScriptValue mQSReceptors;
+ QScriptString mAxonValueHandle;
};
#include "dnqsinputcell.h"
#include "dnqsoutputcell.h"
#include "dnqsbasicstoragecell.h"
-#include "TKUICell.h"
#include "dnqscellcode.h"
#include "DNGlobal.h"
}
}
-TKCell* DNQSContainer::cellFactory(std::string location, std::string name, std::string type, bool canInterface)
+TKCell* DNQSContainer::cellFactory(std::string location, std::string name, std::string type, bool canInterfaceIn, bool canInterfaceOut)
{
TKCell *cell = NULL;
if (type == CELLTYPE_JSBASIC || type.length() == 0)
{
- cell = new DNQSBasicCell(this, location, name, canInterface);
+ cell = new DNQSBasicCell(this, location, name, canInterfaceIn, canInterfaceOut);
cell->init();
}
else if (type == CELLTYPE_IN)
{
- cell = new DNQSInputCell(this, location, name, canInterface);
+ cell = new DNQSInputCell(this, location, name);
cell->init();
}
else if (type == CELLTYPE_OUT)
{
- cell = new DNQSOutputCell(this, location, name, canInterface);
+ cell = new DNQSOutputCell(this, location, name);
cell->init();
}
else if (type == CELLTYPE_BASICSTORAGE)
{
- cell = new DNQSBasicStorageCell(this, location, name, canInterface);
+ cell = new DNQSBasicStorageCell(this, location, name, canInterfaceIn, canInterfaceOut);
cell->init();
}
inline QScriptValue getScriptGlobalObject() { return mQSGlobalObject; }
inline QScriptValue getQSCellContainer() { return mQSCellContainer; }
- virtual TKCell* cellFactory(std::string location, std::string name, std::string type, bool canInterface = true);
+ virtual TKCell* cellFactory(std::string location, std::string name, std::string type, bool canInterfaceIn, bool canInterfaceOut);
virtual TKAxon* axonFactory(TKCell *theOwner);
virtual TKReceptor* receptorFactory(TKCell *theOwner);
virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner);
#include "TKContainer.h"
#include "TKAxon.h"
-DNQSInputCell::DNQSInputCell(TKContainer *container, std::string location, std::string name, bool canInterface):
- TKCell(container,location,name,canInterface)
+DNQSInputCell::DNQSInputCell(TKContainer *container, std::string location, std::string name):
+ DNCellInterfaceable(container,location,name, true, false), mInputValue(0)
{
}
bool DNQSInputCell::doTick(float time)
{
+ (void)time;
return true;
}
{
return true;
}
+
+void DNQSInputCell::updateReceptorValue()
+{
+ mAxon->setValue(mInputValue);
+}
+
+void DNQSInputCell::setValue(float value)
+{
+ mInputValue = value;
+ mReceptorValueUpdated = true;
+}
#ifndef DNQSINPUTCELL_H
#define DNQSINPUTCELL_H
-#include "TKCell.h"
+#include "DNCellInterfaceable.h"
class TKContainer;
-class DNQSInputCell : public TKCell
+class DNQSInputCell : public DNCellInterfaceable
{
public:
- DNQSInputCell(TKContainer *container, std::string location, std::string name, bool canIntarface = false);
+ DNQSInputCell(TKContainer *container, std::string location, std::string name);
virtual ~DNQSInputCell();
virtual bool doTick(float time);
virtual bool doInit();
virtual bool doDestroy();
+
+ virtual void updateReceptorValue();
+ virtual void setValue(float value);
+
+private:
+ float mInputValue;
};
#endif // DNQSINPUTCELL_H
#include "TKAxon.h"
#include "TKReceptor.h"
-DNQSOutputCell::DNQSOutputCell(TKContainer *container, std::string location, std::string name, bool canInterface):
- TKCell(container,location,name,canInterface)
+DNQSOutputCell::DNQSOutputCell(TKContainer *container, std::string location, std::string name):
+ DNCellInterfaceable(container,location,name,false,true)
{
}
bool DNQSOutputCell::doTick(float time)
{
+ (void)time;
+
float value = 0.0;
for ( TKReceptorMap::iterator it = mReceptors.begin(); it != mReceptors.end(); ++it ) {
{
return true;
}
+
+void DNQSOutputCell::setValue(float value)
+{
+ (void)value;
+}
#ifndef DNQSOUTPUTCELL_H
#define DNQSOUTPUTCELL_H
-#include "TKCell.h"
+#include "DNCellInterfaceable.h"
class TKContainer;
-class DNQSOutputCell : public TKCell
+class DNQSOutputCell : public DNCellInterfaceable
+
{
public:
- DNQSOutputCell(TKContainer *container, std::string location, std::string name, bool canIntarface = false);
+ DNQSOutputCell(TKContainer *container, std::string location, std::string name);
virtual ~DNQSOutputCell();
virtual bool doTick(float time);
virtual bool doInit();
virtual bool doDestroy();
+
+ virtual void setValue(float value);
};
#endif // DNQSOUTPUTCELL_H