OSDN Git Service

[dennco] re-working the doTick process flow. The work is still in progress.
authortkawata <tkawata@users.sourceforge.jp>
Tue, 20 Nov 2012 15:11:06 +0000 (00:11 +0900)
committertkawata <tkawata@users.sourceforge.jp>
Tue, 20 Nov 2012 15:11:06 +0000 (00:11 +0900)
24 files changed:
Source/Source.pro
Source/layer1/TKCell.cpp
Source/layer1/TKCell.h
Source/layer1/TKContainer.cpp
Source/layer1/TKContainer.h
Source/layer1/TKReceptor.cpp
Source/layer1/TKReceptor.h
Source/layer1/platform/qt/QtTKConsole.cpp
Source/layer3/DNCellInterfaceable.cpp [moved from Source/layer3/TKUICell.cpp with 58% similarity]
Source/layer3/DNCellInterfaceable.h [moved from Source/layer3/TKUICell.h with 52% similarity]
Source/layer3/DNEngine.cpp
Source/layer3/DNEngine.h
Source/layer3/QtScript/dnqsbasiccell.cpp
Source/layer3/QtScript/dnqsbasiccell.h
Source/layer3/QtScript/dnqsbasicstoragecell.cpp
Source/layer3/QtScript/dnqsbasicstoragecell.h
Source/layer3/QtScript/dnqscellbase.cpp
Source/layer3/QtScript/dnqscellbase.h
Source/layer3/QtScript/dnqscontainer.cpp
Source/layer3/QtScript/dnqscontainer.h
Source/layer3/QtScript/dnqsinputcell.cpp
Source/layer3/QtScript/dnqsinputcell.h
Source/layer3/QtScript/dnqsoutputcell.cpp
Source/layer3/QtScript/dnqsoutputcell.h

index 81d7391..86eebf4 100644 (file)
@@ -38,7 +38,6 @@ SOURCES += \
     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 \
@@ -62,7 +61,8 @@ SOURCES += \
     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 \
@@ -93,7 +93,6 @@ HEADERS  += \
     layer2/platform/qt/qtdnxmlimpl.h \
     layer3/DNAlertImpl.h \
     layer3/DNAlert.h \
-    layer3/TKUICell.h \
     layer3/DNTimeKeeperImpl.h \
     layer3/DNTimeKeeper.h \
     layer3/DNThreadImpl.h \
@@ -123,7 +122,8 @@ HEADERS  += \
     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
index 7f5a31b..0b9963d 100644 (file)
@@ -26,8 +26,9 @@
 #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)
 {
 }
 
@@ -116,3 +117,24 @@ TKReceptor* TKCell::createReceptor(std::string name)
     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;
+        }
+    }
+}
index 62e8eb9..3d5e5e7 100644 (file)
@@ -34,7 +34,7 @@ typedef std::map<std::string, TKReceptor*> TKReceptorMap;
 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();
@@ -49,11 +49,14 @@ public:
 
     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);
@@ -64,7 +67,9 @@ protected:
     TKAxon                  *mAxon;
     TKReceptorMap           mReceptors;
     TKCellCodeInstance      *mCellCodeInstance;
-    bool                    mCanInterface;
+    bool                    mCanInterfaceIn;
+    bool                    mCanInterfaceOut;
+    bool                    mReceptorValueUpdated;
 
 };
 
index d4bbe89..f45621d 100644 (file)
@@ -48,27 +48,81 @@ TKContainer::~TKContainer()
 
 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();
@@ -77,9 +131,9 @@ bool TKContainer::doDestroy()
         delete it->second;
     }
     mCells.clear();
-    mInterfaceCells.clear();
+    mInpInterfaceCells.clear();
+    mOutInterfaceCells.clear();
 
-    mLock.unlock();
     return true;
 }
 
@@ -90,21 +144,21 @@ TKCell* TKContainer::addCell(std::string theLocation, std::string theName, std::
 
     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
     {
@@ -117,9 +171,20 @@ TKCell* TKContainer::addCell(std::string theLocation, std::string theName, std::
     {
         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)
         {
@@ -156,11 +221,11 @@ TKCell* TKContainer::addCell(std::string theLocation, std::string theName, TKCel
 
     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)
     {
@@ -188,9 +253,20 @@ TKCell* TKContainer::addCell(std::string theLocation, std::string theName, TKCel
         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
@@ -248,22 +324,29 @@ TKCell* TKContainer::getCell(std::string theFQNName)
     }
 }
 
-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;
     }
 }
 
index af46ce5..da4ee78 100644 (file)
@@ -59,12 +59,16 @@ public:
     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);
@@ -73,7 +77,7 @@ public:
     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;
@@ -85,7 +89,9 @@ public:
 protected:
     TKContainer();
     TKCellMap       mCells;
-    TKCellMap       mInterfaceCells;
+    TKCellMap       mInpInterfaceCells;
+    TKCellMap       mOutInterfaceCells;
+    TKCellMap       mNonInterfaceCells;
     TKCellCodeMap   mCellCodes;
     std::string     mContainerRootPath;
     DNStorage       *mStorage;
index 45e4a3a..76b8184 100644 (file)
 #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)
index 58ad661..5efb02c 100644 (file)
 #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
index 364af26..60afa78 100644 (file)
@@ -23,7 +23,7 @@
 
 void TKConsole::vprintf(TKLog::MessageType type, const char *fmt, va_list ap)
 {
-    (type);
+    (void)type;
     QString msg = QString().vsprintf(fmt,ap);
     qDebug() << msg << endl;
 }
similarity index 58%
rename from Source/layer3/TKUICell.cpp
rename to Source/layer3/DNCellInterfaceable.cpp
index 24b0c3e..edd2d3c 100644 (file)
 // 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();
 }
-
similarity index 52%
rename from Source/layer3/TKUICell.h
rename to Source/layer3/DNCellInterfaceable.h
index 07356af..7a64a0f 100644 (file)
 // 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
index d00828e..b1ef7de 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "TKLock.h"
 #include "TKContainer.h"
-#include "TKUICell.h"
+#include "DNCellInterfaceable.h"
 #include "DNTimeKeeper.h"
 #include "DNServerHTTP.h"
 #include "DNServerSerialPort.h"
@@ -40,7 +40,7 @@
 #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();
@@ -155,7 +155,7 @@ bool DNEngine::parseSettingFile(const char *contentRoot)
                     is >> t;
                     if (t>0)
                     {
-                        setTickIntervalSec(t);
+                        setTickIntervalSec(t/(mNumUpdateScan+1));
                     }
                     else
                     {
@@ -306,9 +306,31 @@ void DNEngine::doTickThread(void *self)
 
     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();
     }
 
@@ -321,7 +343,7 @@ float DNEngine::doClientGetRequest(const char* path)
         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)
     {
@@ -348,7 +370,7 @@ bool DNEngine::doClientSetRequest(const char* path, float value)
         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)
     {
index afe809f..24cbfef 100644 (file)
@@ -73,6 +73,7 @@ private:
     std::string     mUIPath;
 
     DNThread        *mDoTickThread;
+    int             mNumUpdateScan;
     
 };
 
index bcb3c7d..33118fe 100644 (file)
 #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()
@@ -46,41 +36,6 @@ 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;
index f1cf350..4761e55 100644 (file)
 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
index 7f325aa..1de636c 100644 (file)
@@ -33,8 +33,8 @@ QScriptString DNQSBasicStorageCell::mZQSString;
 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();
index 3e1e477..6bdde5a 100644 (file)
@@ -32,7 +32,7 @@ class DNStorageXYZVRecords;
 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:
index 0afa1a5..98815cc 100644 (file)
 //
 #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);
+}
index 0340b44..cf463f8 100644 (file)
@@ -30,14 +30,20 @@ class DNQSContainer;
 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;
 
 };
 
index 2b143fe..e667333 100644 (file)
@@ -31,7 +31,6 @@
 #include "dnqsinputcell.h"
 #include "dnqsoutputcell.h"
 #include "dnqsbasicstoragecell.h"
-#include "TKUICell.h"
 #include "dnqscellcode.h"
 #include "DNGlobal.h"
 
@@ -109,28 +108,28 @@ float DNQSContainer::getValue(std::string key) const
     }
 }
 
-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();
     }
 
index c411557..d055db8 100644 (file)
@@ -37,7 +37,7 @@ public:
     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);
index 9a34371..e33a175 100644 (file)
@@ -21,8 +21,8 @@
 #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)
 {
 }
 
@@ -32,6 +32,7 @@ DNQSInputCell::~DNQSInputCell()
 
 bool DNQSInputCell::doTick(float time)
 {
+    (void)time;
     return true;
 }
 
@@ -44,3 +45,14 @@ bool DNQSInputCell::doDestroy()
 {
     return true;
 }
+
+void DNQSInputCell::updateReceptorValue()
+{
+    mAxon->setValue(mInputValue);
+}
+
+void DNQSInputCell::setValue(float value)
+{
+    mInputValue = value;
+    mReceptorValueUpdated = true;
+}
index b7bc3ef..7491628 100644 (file)
 #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
index c7f0d35..b5cb790 100644 (file)
@@ -22,8 +22,8 @@
 #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)
 {
 }
 
@@ -33,6 +33,8 @@ DNQSOutputCell::~DNQSOutputCell()
 
 bool DNQSOutputCell::doTick(float time)
 {
+    (void)time;
+
     float value = 0.0;
 
     for ( TKReceptorMap::iterator it = mReceptors.begin(); it != mReceptors.end(); ++it ) {
@@ -53,3 +55,8 @@ bool DNQSOutputCell::doDestroy()
 {
     return true;
 }
+
+void DNQSOutputCell::setValue(float value)
+{
+    (void)value;
+}
index a61d358..d453a63 100644 (file)
 #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