1 // Copyright (c) 2012 Dennco Project
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // Created by tkawata on 1/28/2012.
22 #include "TKContainer.h"
24 #include "DNTimeKeeper.h"
25 #include "DNHTTPServer.h"
28 DNEngine::DNEngine(TKContainer *container) :
29 mContainer(container),mIsRunning(false),mPortNumber(9080),mHTTPServer(NULL)
31 mTimeKeeper = new DNTimeKeeper();
36 bool DNEngine::startHTTPServer(int portNumber)
38 if (mHTTPServer && mHTTPServer->isRunning())
44 mHTTPServer = new DNHTTPServer(this);
47 mHTTPServer->setPortNumber(portNumber);
53 void DNEngine::stopServer()
55 if (mHTTPServer && mHTTPServer->isRunning())
63 void DNEngine::setTickIntervalSec(float interval)
66 mTimeKeeper->setIntevalSec(interval);
69 void DNEngine::doTickThread()
71 mTickThreadLock.lock();
74 //doTickThread is already running.
75 mTickThreadLock.unlock();
79 mTickThreadLock.unlock();
82 DNTimeKeeper *timeKeeper = new DNTimeKeeper();
86 mContainer->doTick(timeKeeper->getTickTime());
87 timeKeeper->sleepUntilNextInterval();
93 float DNEngine::doClientGetRequest(const char* path)
95 TKUICell *cell = (TKUICell*)mContainer->getInterfaceCell(path);
99 result = cell->getValue();
104 bool DNEngine::doClientSetRequest(const char* path, const char* value)
106 TKUICell *cell = (TKUICell*)mContainer->getInterfaceCell(path);
110 cell->setValue(atof(value));