if (classElement && (element == NULL || element->depth <= classElement->depth))
{
std::string _cellCodeName = getFQNString(path,className.c_str());
- std::string _cellCodeAPIType = classAPIElement->text;
- std::string _cellCodeScript = classScriptElement->text;
+ std::string _cellCodeAPIType = classAPIElement ? classAPIElement->text : "";
+ std::string _cellCodeScript = classScriptElement ? 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());
}
}
-}
\ No newline at end of file
+}
impl = DNDirectoryImpl::create(dir);
}
+DNDirectory::~DNDirectory()
+{
+ if (impl)
+ delete impl;
+}
+
const DNFileList* DNDirectory::getFileList(const char *filter)
{
return impl->getFileList(filter);
{
public:
DNDirectory(const char *dir);
-
+ ~DNDirectory();
+
const DNFileList* getFileList(const char *filter);
private:
static DNDirectoryImpl* create(const char *dir);
virtual const DNFileList* getFileList(const char *filter) = 0;
+
+ virtual ~DNDirectoryImpl() {}
};
#endif
#include "DNEngine.h"
#include "DNAlert.h"
#include "DNXML.h"
+#include "DNGlobal.h"
#include <stdlib.h>
DNEngine::DNEngine(const char *contentPath) :
-mContainer(NULL),mIsRunning(false),mPortNumber(9080),mHTTPServer(NULL),mValid(false)
+mContainer(NULL),mPortNumber(9080),mHTTPServer(NULL),mValid(false)
{
mTimeKeeper = new DNTimeKeeper();
mContainer = TKContainer::createContainer();
+ dnGlobal()->updateRunningStatus(DNGlobal::STOPPED);
+
std::string basePath(contentPath);
std::string containerRoot = basePath.append("/Container");
bool succeeded = false;
succeeded = parseSettingFile(contentPath);
- if (!succeeded)
+ if (!succeeded || !dnGlobal()->isErrorStatusNormal())
{
- DNAlert::show("Initialization failed", "failed to parse setting file /property.xml");
+ if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
+ {
+ dnGlobal()->setMessage1("property.xml parse error");
+ dnGlobal()->setMessage2("failed to parse setting file /property.xml");
+ }
+ else
+ {
+ dnGlobal()->setMessage1("property.xml parse error");
+ }
return;
}
succeeded = parseContainerFile(containerRoot.c_str());
if (!succeeded)
{
- DNAlert::show("Initialization failed", "failed to parse container file");
- return;
+ if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
+ {
+ dnGlobal()->setMessage1("Initialization failed");
+ dnGlobal()->setMessage2("Failed to parse container file");
+ }
+ else
+ {
+ dnGlobal()->setMessage1("Initialization failed");
+ }
}
-
+
mValid = true;
}
DNXML *xml = DNXML::createXMLFromFile(contentRoot, "property.xml");
if (xml)
{
-
+ //TODO
+ delete xml;
}
- return false;
+ return true;
}
bool DNEngine::parseContainerFile(const char *containerRoot)
mTimeKeeper->setIntevalSec(interval);
}
-void DNEngine::doTickThread()
+bool DNEngine::startEngine()
+{
+ mDoTickThread = DNThread::createThread(DNEngine::doTickThread, this);
+ mDoTickThread->start();
+}
+
+bool DNEngine::stopEngine()
{
- mTickThreadLock.lock();
- if (mIsRunning)
+ dnGlobal()->updateRunningStatus(DNGlobal::STOPPING);
+ return mDoTickThread->waitForExit(5000);
+}
+
+void DNEngine::doTickThread(void *self)
+{
+ if (!dnGlobal()->updateRunningStatus(DNGlobal::RUNNIING))
{
- //doTickThread is already running.
- mTickThreadLock.unlock();
return;
}
- mIsRunning = true;
- mTickThreadLock.unlock();
-
-
- DNTimeKeeper *timeKeeper = new DNTimeKeeper();
+
+ DNEngine *engine = (DNEngine*)self;
- while(mIsRunning)
+ while(dnGlobal()->getRunningStatus() == DNGlobal::RUNNIING)
{
- mContainer->doTick(timeKeeper->getTickTime());
- timeKeeper->sleepUntilNextInterval();
+ engine->mContainer->doTick(engine->mTimeKeeper->getTickTime());
+ engine->mTimeKeeper->sleepUntilNextInterval();
}
-
- delete timeKeeper;
+
+ dnGlobal()->updateRunningStatus(DNGlobal::STOPPED);
}
float DNEngine::doClientGetRequest(const char* path)
class DNHTTPServer;
#include "TKLock.h"
+#include "DNThread.h"
#include <string>
public:
DNEngine(const char *contentPath);
virtual ~DNEngine();
+
+ bool startEngine();
+ bool stopEngine();
bool startHTTPServer(int portNumber);
void stopServer();
void setTickIntervalSec(float interval);
- void doTickThread();
+ static void doTickThread(void *self);
float doClientGetRequest(const char* path);
bool doClientSetRequest(const char* path, const char* value);
TKContainer *mContainer;
int mPortNumber;
- TKLock mTickThreadLock;
DNHTTPServer *mHTTPServer;
- bool mIsRunning;
DNTimeKeeper *mTimeKeeper;
bool mValid;
-
+
+ DNThread *mDoTickThread;
};
{
if (prev)
{
- prev->next = this->next;
+ prev->next = next;
}
- this->next->prev = prev;
+ if (next)
+ next->prev = prev;
}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// Created by tkawata on Mar-1/2012.
+//
+#include "DNGlobal.h"
+
+DNGlobal* dnGlobal()
+{
+ return DNGlobal::instance();
+}
+
+//static
+DNGlobal *DNGlobal::instance()
+{
+ static DNGlobal *_instance = 0;
+ if (!_instance)
+ {
+ _instance = new DNGlobal();
+ }
+
+ return _instance;
+}
+
+DNGlobal::DNGlobal() : mEStatus(NORMAL), mRStatus(STOPPED)
+{
+}
+
+DNGlobal::~DNGlobal()
+{
+}
+
+bool DNGlobal::updateErrorStatus(E_Status status)
+{
+ bool isStatusUpdated = false;
+ mLock.lock();
+ if (mEStatus < status)
+ {
+ mEStatus = status;
+ isStatusUpdated = true;
+ }
+ mLock.unlock();
+ return isStatusUpdated;
+}
+
+void DNGlobal::setMessage1(std::string message1)
+{
+ mLock.lock();
+ mMessage1 = message1;
+ mLock.unlock();
+}
+
+void DNGlobal::setMessage2(std::string message2)
+{
+ mLock.lock();
+ mMessage2 = message2;
+ mLock.unlock();
+}
+
+DNGlobal::E_Status DNGlobal::getErrorStatus()
+{
+ return mEStatus;
+}
+
+bool DNGlobal::isErrorStatusNormal()
+{
+ return mEStatus == NORMAL;
+}
+
+std::string DNGlobal::getMessage1()
+{
+ if (mEStatus > NORMAL)
+ {
+ return mMessage1;
+ }
+ else
+ {
+ return "";
+ }
+}
+
+std::string DNGlobal::getMessage2()
+{
+ if (mEStatus > NORMAL)
+ {
+ return mMessage2;
+ }
+ else
+ {
+ return "";
+ }
+}
+
+void DNGlobal::resetErrorStatus()
+{
+ mEStatus = NORMAL;
+ mMessage1 = "";
+ mMessage2 = "";
+}
+
+DNGlobal::R_Status DNGlobal::getRunningStatus()
+{
+ return mRStatus;
+}
+
+bool DNGlobal::updateRunningStatus(R_Status status)
+{
+ bool updated = false;
+ mLock.lock();
+ if (mRStatus != status)
+ {
+ updated = true;
+ mRStatus = status;
+ }
+ mLock.unlock();
+
+ return updated;
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// Created by tkawata on Mar-1/2012.
+//
+#ifndef DNGLOBAL_H
+#define DNGLOBAL_H
+
+#include <string>
+#include "TKLock.h"
+
+class DNGlobal
+{
+public:
+ static DNGlobal* instance();
+ ~DNGlobal();
+
+ enum E_Status {NORMAL,WARNING,ERROR,FATAL_ERROR};
+ enum R_Status {STOPPED,RUNNIING,STOPPING};
+
+ bool updateErrorStatus(E_Status status);
+ E_Status getErrorStatus();
+
+ bool isErrorStatusNormal();
+ void setMessage1(std::string message);
+ void setMessage2(std::string message);
+ std::string getMessage1();
+ std::string getMessage2();
+ void resetErrorStatus();
+
+ bool updateRunningStatus(R_Status running);
+ R_Status getRunningStatus();
+
+
+private:
+ DNGlobal();
+ TKLock mLock;
+ std::string mMessage1;
+ std::string mMessage2;
+ E_Status mEStatus;
+ R_Status mRStatus;
+};
+
+DNGlobal* dnGlobal();
+
+#endif // DNGLOBAL_H
impl = DNHTTPServerImpl::create(this, DNHTTPServer::clientRequestHandler);
}
+DNHTTPServer::~DNHTTPServer()
+{
+ if (impl)
+ delete impl;
+}
+
bool DNHTTPServer::isRunning()
{
return impl->isRunning();
{
public:
DNHTTPServer(DNEngine *engine);
+ ~DNHTTPServer();
virtual bool isRunning();
virtual void start();
virtual void replyWithStatusCode(int code, const char* message) = 0;
virtual void replyWithFile(const char* filePath) = 0;
+ virtual ~DNHTTPServerImpl() {};
};
#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// Created by tkawata on Mar-1/2012.
+//
+#include "DNThread.h"
+#include "DNThreadImpl.h"
+
+DNThread::DNThread(DNThreadImpl *_impl) : impl(_impl)
+{
+}
+
+DNThread::~DNThread()
+{
+ if (impl)
+ delete impl;
+}
+
+
+//static
+DNThread* DNThread::createThread(DNThreadFunc threadFunc, void *data)
+{
+ return DNThreadImpl::createThread(threadFunc, data);
+}
+
+bool DNThread::start()
+{
+ return impl->start();
+}
+
+bool DNThread::waitForExit(int timeout)
+{
+ return impl->waitForExit(timeout);
+}
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// Created by tkawata on Mar-1/2012.
+//
+#ifndef DNTHREAD_H
+#define DNTHREAD_H
+
+typedef void (*DNThreadFunc)(void* data);
+
+class DNThreadImpl;
+
+class DNThread
+{
+public:
+ DNThread(DNThreadImpl *impl);
+ ~DNThread();
+
+ bool waitForExit(int timeout);
+ bool start();
+
+ static DNThread* createThread(DNThreadFunc threadFunc, void *data);
+
+private:
+
+ DNThreadImpl *impl;
+};
+
+#endif // DNTHREAD_H
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// Created by tkawata on Mar-1/2012.
+//
+#ifndef DNTHREADIMPL_H
+#define DNTHREADIMPL_H
+
+#include "DNThread.h"
+
+class DNThreadImpl
+{
+public:
+ static DNThread* createThread(DNThreadFunc threadFunc, void *data);
+
+ virtual bool start() = 0;
+ virtual bool waitForExit(int timeout) = 0;
+
+ DNThreadImpl() {}
+ virtual ~DNThreadImpl() {}
+
+};
+
+#endif // DNTHREADIMPL_H
static DNXMLImpl* createXMLFromFileImpl(const char *docRoot, const char *path);
virtual DNXMLElement* getRoot() = 0;
+ virtual ~DNXMLImpl() {}
};
#endif
#include <QDir>
#include <QDebug>
#include "TKLog.h"
+#include "DNGlobal.h"
+#include "DNAlert.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
{
delete mEngine;
}
- QString path = ui->filePath->text();
- mEngine = new DNEngine(ui->filePath->text().toLocal8Bit().data());
- if (mEngine->isValid())
+
+ if (startEngine())
{
ui->startButton->setText("Stop");
}
-
}
else
{
ui->startButton->setText("Start");
}
}
+
+bool MainWindow::startEngine()
+{
+ bool initializationFailed = false;
+
+ mEngine = new DNEngine(ui->filePath->text().toLocal8Bit().data());
+ if (!dnGlobal()->isErrorStatusNormal())
+ {
+ DNAlert::show(dnGlobal()->getMessage1(), dnGlobal()->getMessage2());
+ dnGlobal()->resetErrorStatus();
+ initializationFailed = true;
+ }
+ else if (!mEngine->isValid())
+ {
+ DNAlert::show("DNEngine initialize error", "ERROR. DNEngine not configured properly");
+ initializationFailed = true;
+ }
+
+ if (!initializationFailed)
+ {
+ mEngine->startEngine();
+ }
+ return !initializationFailed;
+}
+
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
+
private slots:
void on_chooseDirButton_clicked();
void on_startButton_clicked();
private:
+ bool startEngine();
+
Ui::MainWindow *ui;
DNEngine *mEngine;
TKConsole *mConsole;
bool DNQSBasicCell::doTick(float time)
{
- if (mCellCodeInstance) return false;
+ if (!mCellCodeInstance) return false;
//update receptor values
for ( TKReceptorMap::iterator it = mReceptors.begin(); it != mReceptors.end(); ++it ) {
{
QScriptValueList args;
args << time;
- mQSDoInit.call(mQSCellCodeInstance, args);
+ mQSDoTick.call(mQSCellCodeInstance, args);
return true;
}
else
if (context->argumentCount() >= 1)
{
QString value = context->argument(0).toString();
- const char *str = value.toUtf8().constData();
- TKLog::printf("%s", str);
+ TKLog::printf("%s", value.toLocal8Bit().data());
}
return engine->nullValue();
}
bool TKCell::setCellCode(TKCellCode *code, const void *data)
{
mCellCodeInstance = code->createCellCodeInstance(this, data);
- mCellCodeInstance->doInit();
-
- return true;
+ if (mCellCodeInstance)
+ return mCellCodeInstance->doInit();
+ else
+ return false;
}
bool TKCell::connectTo(std::string connectionName, TKCell *targetCell)
inline virtual float getValue(std::string key) = 0;
protected:
- TKContainer() {};
+ TKContainer() {}
TKCellMap mCells;
TKCellMap mInterfaceCells;
TKCellCodeMap mCellCodes;
#endif
#ifdef DEBUG
-#define TKASSERT(b) { if (!b) {TKLog::debugPrintf("ASSERT ERROR! %s(%d)",__PRETTY_FUNCTION__, __LINE__);exit(-1);}}
+ #define TKASSERT(b) { if (!b) {TKLog::debugPrintf("ASSERT ERROR! %s(%d)",__PRETTY_FUNCTION__, __LINE__);/*TODO*/}}
#else
-#define TKASSERT(b)
+ #define TKASSERT(b)
#endif
-#endif
\ No newline at end of file
+#endif
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// Created by tkawata on 2/27/2012.
+//
+
+#include "TKConsole.h"
+
+#include <QDebug>
+
+void TKConsole::vprintf(const char *fmt, va_list ap)
+{
+ QString msg = QString().vsprintf(fmt,ap);
+ qDebug() << msg << endl;
+}
+
+void TKConsole::vDebugPrintf(const char *fmt, va_list ap)
+{
+#ifdef DEBUG
+ QString msg = QString().vsprintf(fmt,ap);
+ qDebug() << "DEBUG:" << msg << endl;
+#endif
+}
{
cleanFileList();
- QDir dir(mRootDir,QString::fromLocal8Bit(filter));
+ QDir dir(mRootDir);
+ QStringList filters;
+ QString filterString = QString::fromLocal8Bit(filter);
+ if (filterString.length()>0)
+ {
+ int idx = 0;
+ while( (idx = filterString.indexOf("|")) != -1 )
+ {
+ QString pre("*.");
+ filters << pre.append(filterString.left(idx));
+ filterString = filterString.right(filterString.length()-idx-1);
+ }
+ QString pre("*.");
+ filters << pre.append(filterString);
+ dir.setNameFilters (filters);
+ }
QStringList list = dir.entryList(QDir::Files);
mFileList = 0;
DNFileList *prev = 0;
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// Created by tkawata on Mar-1/2012.
+//
+#include "qtdnthreadimpl.h"
+
+#include "TKLog.h"
+
+//static
+DNThread* DNThreadImpl::createThread(DNThreadFunc threadFunc, void *data)
+{
+ return new DNThread(new QtDNThreadImpl(threadFunc,data));
+}
+
+QtDNThreadImpl::QtDNThreadImpl(DNThreadFunc threadFunc, void *data): mThreadFunc(threadFunc), mData(data)
+{
+ mThread = new QThread;
+}
+
+QtDNThreadImpl::~QtDNThreadImpl()
+{
+ mLock.lock();
+ if (mThread)
+ {
+ QThread *t = mThread;
+ mThread = NULL;
+ mLock.unlock();
+ if (!t->wait(5000))
+ {
+ TKLog::printf("!WARNING! DNThread %p hasn't finished in 5sec. execute terminate to quit forcedly ", this);
+ t->terminate();
+ }
+ delete t;
+ }
+ else
+ {
+ mLock.unlock();
+ }
+}
+
+bool QtDNThreadImpl::start()
+{
+ bool started = false;
+ mLock.lock();
+ if (!mThread->isRunning())
+ {
+ moveToThread(mThread);
+ mThread->start();
+ QMetaObject::invokeMethod(this, "doWork", Qt::QueuedConnection);
+ started = true;
+ }
+ mLock.unlock();
+ return started;
+}
+
+bool QtDNThreadImpl::waitForExit(int timeout)
+{
+ return mThread->wait(timeout);
+}
+
+void QtDNThreadImpl::doWork()
+{
+ mThreadFunc(mData);
+}
+
+
--- /dev/null
+// Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// Created by tkawata on Mar-1/2012.
+//
+#ifndef QTDNTHREADIMPL_H
+#define QTDNTHREADIMPL_H
+
+#include "DNThreadImpl.h"
+
+#include "TKLock.h"
+#include "DNThread.h"
+
+#include <QObject>
+#include <QThread>
+
+class QtDNThreadImpl : public QObject, public DNThreadImpl
+{
+ Q_OBJECT
+
+public:
+ QtDNThreadImpl(DNThreadFunc threadFunc, void *data);
+ virtual ~QtDNThreadImpl();
+
+ virtual bool start();
+ virtual bool waitForExit(int timeout);
+
+
+public slots:
+ void doWork();
+
+private:
+ DNThreadFunc mThreadFunc;
+ void *mData;
+ TKLock mLock;
+ QThread *mThread;
+};
+
+#endif // QTDNTHREADIMPL_H
#include "DNXMLElement.h"
#include "TKLog.h"
+#include "DNGlobal.h"
DNXMLImpl *DNXMLImpl::createXMLFromFileImpl(const char *docRoot, const char *docPath)
{
QString filePath = qDocRoot;
filePath.append(qDocPath);
+ return new QtDNXMLImpl(filePath);
+}
+
+QtDNXMLImpl::QtDNXMLImpl(QString filePath) : mValid(false), mFilePath(filePath)
+{
QFile file(filePath);
if (file.open(QFile::ReadOnly | QFile::Text)) {
QXmlInputSource xmlInputSource(&file);
- return new QtDNXMLImpl(&xmlInputSource);
+ mHandler = new QtXMLHandler(filePath);
+ QXmlSimpleReader reader;
+ reader.setContentHandler(mHandler);
+ reader.setErrorHandler(mHandler);
+
+ mValid = reader.parse(xmlInputSource);
}
- else
+
+ if (!mValid)
{
- TKLog::printf("ERROR failed to load file.%s/%s", docRoot,docPath);
- return NULL;
+ TKLog::printf("ERROR failed to load file.%s", filePath.toLocal8Bit().data());
+ std::string message = "failed to load file:";
+ message.append(filePath.toStdString());
+ if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
+ {
+ dnGlobal()->setMessage1("Error at loading XML file");
+ dnGlobal()->setMessage2(message);
+ }
}
}
-QtDNXMLImpl::QtDNXMLImpl(QXmlInputSource *input)
-{
- mHandler = new QtXMLHandler();
- QXmlSimpleReader reader;
- reader.setContentHandler(mHandler);
- reader.setErrorHandler(mHandler);
-
- reader.parse(input,true);
-}
-
QtDNXMLImpl::~QtDNXMLImpl()
{
if (mHandler)
DNXMLElement* QtDNXMLImpl::getRoot()
{
- if (mHandler)
+ if (mHandler && mValid)
{
return mHandler->getRoot();
}
}
}
-QtXMLHandler::QtXMLHandler() : mRootElement(NULL), mCurrentElement(NULL)
+QtXMLHandler::QtXMLHandler(QString filePath) : mRootElement(NULL), mCurrentElement(NULL), mFilePath(filePath)
{
}
{
if (!mCurrentElement->inner)
{
- mCurrentElement->inner = new DNXMLElement(qName.toStdString());
DNXMLElement *outer = mCurrentElement;
+ mCurrentElement->inner = new DNXMLElement(qName.toStdString());
mCurrentElement = mCurrentElement->inner;
mCurrentElement->outer = outer;
- mCurrentElement->depth = outer->depth++;
+ mCurrentElement->depth = outer->depth + 1;
}
else
{
DNXMLElement *prev = mCurrentElement->inner;
+ while(prev->next) prev = prev->next;
prev->next = new DNXMLElement(qName.toStdString());
mCurrentElement = prev->next;
mCurrentElement->outer = prev->outer;
bool QtXMLHandler::characters (const QString & ch )
{
- mCurrentElement->text = ch.toStdString();
+ mCurrentElement->text.append(ch.toStdString());
return true;
}
return true;
}
+bool QtXMLHandler::fatalError(const QXmlParseException & exception )
+{
+ QString message = QString().sprintf("ERROR while reading XML file!! file.%s (line:%d) \nReason:%s",
+ mFilePath.toLocal8Bit().data(), exception.lineNumber(), exception.message().toLocal8Bit().data());
+ TKLog::printf("%s", message.toLocal8Bit().data());
+ if (dnGlobal()->updateErrorStatus(DNGlobal::ERROR))
+ {
+ dnGlobal()->setMessage1("Error at loading XML file");
+ dnGlobal()->setMessage2(message.toStdString());
+ }
+ return true;
+}
+
+
class QtXMLHandler : public QXmlDefaultHandler
{
public:
- QtXMLHandler();
+ QtXMLHandler(QString filePath);
virtual ~QtXMLHandler();
DNXMLElement *getRoot() { return mRootElement; }
virtual bool endElement (const QString & namespaceURI, const QString & localName, const QString & qName );
virtual bool characters (const QString & ch );
virtual bool error (const QXmlParseException & exception );
+ virtual bool fatalError(const QXmlParseException & exception );
private:
- DNXMLElement *mRootElement;
- DNXMLElement *mCurrentElement;
+ DNXMLElement *mRootElement;
+ DNXMLElement *mCurrentElement;
+ QString mFilePath;
};
class QtDNXMLImpl : public DNXMLImpl
{
public:
- QtDNXMLImpl(QXmlInputSource *input);
+ QtDNXMLImpl(QString filePath);
virtual ~QtDNXMLImpl();
virtual DNXMLElement *getRoot();
private:
- QtXMLHandler *mHandler;
+ QtXMLHandler *mHandler;
+ bool mValid;
+ QString mFilePath;
};
Source/platform/qt/qtsimplehttpserverimpl.cpp \
Source/platform/qt/qtdntimekeeperimpl.cpp \
Source/platform/qt/qtdnxmlimpl.cpp \
- Source/platform/qt/QtTKConsole.cpp
+ Source/platform/qt/QtTKConsole.cpp \
+ Source/DNGlobal.cpp \
+ Source/DNThread.cpp \
+ Source/platform/qt/qtdnthreadimpl.cpp
HEADERS += Source/QtDennco/mainwindow.h \
Source/TKUICell.h \
Source/platform/qt/qtdnalertimpl.h \
Source/platform/qt/qtsimplehttpserverimpl.h \
Source/platform/qt/qtdntimekeeperimpl.h \
- Source/platform/qt/qtdnxmlimpl.h
+ Source/platform/qt/qtdnxmlimpl.h \
+ Source/DNGlobal.h \
+ Source/DNThread.h \
+ Source/DNThreadImpl.h \
+ Source/platform/qt/qtdnthreadimpl.h
FORMS += Source/QtDennco/mainwindow.ui
+Debug:DEFINES+=DEBUG