Removed other modules from the build system so that the common lib can be compiled.
add_subdirectory(libs)
-add_subdirectory(main)
-add_subdirectory(plugins)
+#add_subdirectory(main)
+#add_subdirectory(plugins)
-add_subdirectory(Plugins)
+#add_subdirectory(Plugins)
add_subdirectory(Common)
--- /dev/null
+# Name of the target
+set(TARGET CommonLib)
+
+# Qt modules
+include(${QT_USE_FILE})
+
+# Needed for exporting/importing symbols
+add_definitions(-DCOMMON_LIBRARY)
+
+# Include files
+include_directories(${eVaf_INCLUDE})
+
+# Required eVaf libraries
+set(eVaf_LIBRARIES)
+
+# Source files
+set(SRCS
+ app.cpp
+ env.cpp
+ event.cpp
+ eventqueue.cpp
+ registry.cpp
+)
+
+# Header files for the meta-object compiler
+set(MOC_HDRS
+ iapp.h
+ ienv.h
+ ieventqueue.h
+ ilogger.h
+ iregistry.h
+ app.h
+ env.h
+ eventqueue.h
+ registry.h
+)
+
+# Version info resource file for Windows builds
+if(WIN32)
+ set(SRCS ${SRCS} version.rc)
+endif(WIN32)
+
+qt4_wrap_cpp(MOC_SRCS ${MOC_HDRS})
+
+add_library(${TARGET} SHARED ${SRCS} ${MOC_SRCS})
+
+target_link_libraries(${TARGET} ${QT_LIBRARIES} ${eVaf_LIBRARIES})
+
+install(TARGETS ${TARGET} DESTINATION bin)
iApp * iApp::instance()
{
- Internal::App singleton;
+ static Internal::App singleton;
return &singleton;
}
else if (QRegExp("-[-]?lang(uage)?").exactMatch(arg.at(0)) && arg.size() > 1)
mLanguage = arg.at(1);
}
+
+ return true;
}
QString const App::xmlFileName() const
name = mName + "_" + mLanguage.left(2) + ".xml";
fi.setFile(iEnv::instance()->etcDir() + name);
if (fi.isReadable())
- mName = name;
+ mXmlFile = name;
else
// Fall-back to the generic name
mXmlFile = mName + ".xml";
virtual void restart();
- virtual void quit();
+ virtual void quit(bool err);
virtual bool isReady() const { return mReady; }
QString mLanguage;
/// Name of the application's XML file
- QString mXmlFile;
+ mutable QString mXmlFile;
};
--- /dev/null
+/**
+ * @file Common/env.cpp
+ * @brief iEnv interface implementation
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 Enar Vaikene
+ *
+ * This file is part of the eVaf C++ cross-platform application development framework.
+ *
+ * This file can be used under the terms of the GNU General Public License
+ * version 3.0 as published by the Free Software Foundation and appearing in
+ * the file LICENSE included in the packaging of this file. Please review the
+ * the following information to ensure the GNU General Public License version
+ * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+ *
+ * Alternatively, this file may be used in accordance with the Commercial License
+ * Agreement provided with the Software.
+ */
+
+#include "env.h"
+#include "iregistry.h"
+#include "globals.h"
+#include "version.h"
+#include "iapp.h"
+
+#include <QtCore>
+#include <QDesktopServices>
+
+
+//-------------------------------------------------------------------
+
+using namespace eVaf::Common;
+
+iEnv * iEnv::instance()
+{
+ static Internal::Env singleton;
+ return &singleton;
+}
+
+
+//-------------------------------------------------------------------
+
+using namespace eVaf::Common::Internal;
+
+Env::Env()
+ : iEnv()
+{
+ setObjectName(QString("%1-iEnv").arg(VER_MODULE_NAME_STR));
+
+ // Set initial bin and root directories
+ mRootDir = mBinDir = qApp->applicationDirPath();
+ int t = mBinDir.lastIndexOf(QChar('/'), -1);
+ if (t >= 0)
+ mRootDir = mBinDir.left(t);
+
+ if (!mBinDir.endsWith('/'))
+ mBinDir.append('/');
+ if (!mRootDir.endsWith('/'))
+ mRootDir.append('/');
+}
+
+Env::~Env()
+{
+}
+
+bool Env::init()
+{
+ // Register out interface
+ iRegistry::instance()->registerInterface("iEnv", this);
+
+ // Clear directories
+ mDataRootDir.clear();
+ mQtPluginsDir.clear();
+ mEtcDir.clear();
+ mLogDir.clear();
+ mDocDir.clear();
+
+ // Process the environment
+ QStringList env = QProcess::systemEnvironment();
+ int sz = env.size();
+ for (int i = 0; i < sz; ++i) {
+ // Get the name/value pair
+ QString name = env.at(i).section('=', 0, 0).trimmed();
+ QString value = env.at(i).section('=', 1).trimmed();
+
+ if (name == "EVAF_ROOT_DIR") {
+ mRootDir = value;
+ if (!mRootDir.endsWith('/'))
+ mRootDir.append('/');
+ }
+ else if (name == "EVAF_DATA_ROOT_DIR") {
+ mDataRootDir = value;
+ if (!mDataRootDir.endsWith('/'))
+ mDataRootDir.append('/');
+ }
+ else if (name == "EVAF_ETC_DIR") {
+ mEtcDir = value;
+ if (!mEtcDir.endsWith('/'))
+ mEtcDir.append('/');
+ }
+ else if (name == "EVAF_LOG_DIR") {
+ mLogDir = value;
+ if (!mLogDir.endsWith('/'))
+ mLogDir.append('/');
+ }
+ else if (name == "EVAF_DOC_DIR") {
+ mDocDir = value;
+ if (!mDocDir.endsWith('/'))
+ mDocDir.append('/');
+ }
+ else if (name == "EVAF_QT_PLUGINS_DIR") {
+ mQtPluginsDir = value;
+ if (!mQtPluginsDir.endsWith('/'))
+ mQtPluginsDir.append('/');
+ }
+ }
+
+ // Then process comman-line arguments
+ env = QCoreApplication::arguments();
+ sz = env.size();
+ for (int i = 0; i < sz; ++i) {
+ // Get the name and optional value
+ QStringList arg = env.at(i).simplified().split(QChar('='));
+
+ if (QRegExp("-[-]?root(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mRootDir = arg.at(1);
+ if (!mRootDir.endsWith('/'))
+ mRootDir.append('/');
+ }
+ else if (QRegExp("-[-]?dataroot(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mDataRootDir = arg.at(1);
+ if (!mDataRootDir.endsWith('/'))
+ mDataRootDir.append('/');
+ }
+ else if (QRegExp("-[-]?etc(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mEtcDir = arg.at(1);
+ if (!mEtcDir.endsWith('/'))
+ mEtcDir.append('/');
+ }
+ else if (QRegExp("-[-]?log(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mLogDir = arg.at(1);
+ if (!mLogDir.endsWith('/'))
+ mLogDir.append('/');
+ }
+ else if (QRegExp("-[-]?doc(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mDocDir = arg.at(1);
+ if (!mDocDir.endsWith('/'))
+ mDocDir.append('/');
+ }
+ else if (QRegExp("-[-]?qtplugins(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mQtPluginsDir = arg.at(1);
+ if (!mQtPluginsDir.endsWith('/'))
+ mQtPluginsDir.append('/');
+ }
+ }
+
+ return true;
+}
+
+QString const Env::dataRootDir() const
+{
+ if (mDataRootDir.isEmpty()) {
+ QString dataLoc = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
+ if (!dataLoc.endsWith('/'))
+ dataLoc.append('/');
+ mDataRootDir = dataLoc.append(iApp::instance()->name());
+ if (!mDataRootDir.endsWith('/'))
+ mDataRootDir.append('/');
+ }
+
+ return mDataRootDir;
+}
+
+QString const Env::etcDir() const
+{
+ if (mEtcDir.isEmpty())
+ mEtcDir = dataRootDir() + "etc/";
+ return mEtcDir;
+}
+
+QString const Env::logDir() const
+{
+ if (mLogDir.isEmpty())
+ mLogDir = dataRootDir() + "log/";
+ return mLogDir;
+}
+
+QString const Env::docDir() const
+{
+ if (mDocDir.isEmpty())
+ mDocDir = rootDir() + "doc/";
+ return mDocDir;
+}
+
+QString const Env::qtPluginsDir() const
+{
+ if (mQtPluginsDir.isEmpty())
+ mQtPluginsDir = binDir();
+ return mQtPluginsDir;
+}
--- /dev/null
+/**
+ * @file Common/env.h
+ * @brief iEnv interface implementation
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 Enar Vaikene
+ *
+ * This file is part of the eVaf C++ cross-platform application development framework.
+ *
+ * This file can be used under the terms of the GNU General Public License
+ * version 3.0 as published by the Free Software Foundation and appearing in
+ * the file LICENSE included in the packaging of this file. Please review the
+ * the following information to ensure the GNU General Public License version
+ * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+ *
+ * Alternatively, this file may be used in accordance with the Commercial License
+ * Agreement provided with the Software.
+ */
+
+#ifndef __COMMON_ENV_H
+#define __COMMON_ENV_H
+
+#include "ienv.h"
+
+#include <QObject>
+#include <QString>
+
+namespace eVaf {
+namespace Common {
+namespace Internal {
+
+/**
+ * iEnv interface implementation
+ */
+class Env : public iEnv
+{
+ Q_OBJECT
+
+public:
+
+ Env();
+
+ virtual ~Env();
+
+ /**
+ * Initializes the iEnv interface implementation
+ * @return True if ok; false if the initialization fails
+ */
+ bool init();
+
+ /*
+ iEnv interface
+ */
+
+ virtual QString const rootDir() const { return mRootDir; }
+
+ virtual QString const dataRootDir() const;
+
+ virtual QString const binDir() const { return mBinDir; }
+
+ virtual QString const etcDir() const;
+
+ virtual QString const logDir() const;
+
+ virtual QString const docDir() const;
+
+ virtual QString const qtPluginsDir() const;
+
+
+private: // Members
+
+ QString mRootDir;
+ mutable QString mDataRootDir;
+ QString mBinDir;
+ mutable QString mQtPluginsDir;
+ mutable QString mEtcDir;
+ mutable QString mLogDir;
+ mutable QString mDocDir;
+
+};
+
+} // namespace eVaf::Common::Internal
+} // namespace eVaf::Common
+} // namespace eVaf
+
+#endif // env.h
--- /dev/null
+/**
+ * @file Common/event.cpp
+ * @brief Event class implementation
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 Enar Vaikene
+ *
+ * This file is part of the eVaf C++ cross-platform application development framework.
+ *
+ * This file can be used under the terms of the GNU General Public License
+ * version 3.0 as published by the Free Software Foundation and appearing in
+ * the file LICENSE included in the packaging of this file. Please review the
+ * the following information to ensure the GNU General Public License version
+ * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+ *
+ * Alternatively, this file may be used in accordance with the Commercial License
+ * Agreement provided with the Software.
+ */
+
+#include "event.h"
+
+using namespace eVaf::Common;
+
+QEvent::Type const Event::eVafEvent = QEvent::Type(QEvent::registerEventType());
namespace Common {
/**
- * Base class for all the eVaf events
+ * Event class for all the eVaf events
* @code@include <Common/Event>@endcode
*
- * The Event class is an event container for reference counted data objects.
+ * The Event class is an event container for all the eVaf events.
*/
class COMMON_EXPORT Event : public QEvent
{
--- /dev/null
+/**
+ * @file Common/eventqueue.cpp
+ * @brief Event queue interface implementation
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 Enar Vaikene
+ *
+ * This file is part of the eVaf C++ cross-platform application development framework.
+ *
+ * This file can be used under the terms of the GNU General Public License
+ * version 3.0 as published by the Free Software Foundation and appearing in
+ * the file LICENSE included in the packaging of this file. Please review the
+ * the following information to ensure the GNU General Public License version
+ * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+ *
+ * Alternatively, this file may be used in accordance with the Commercial License
+ * Agreement provided with the Software.
+ */
+
+#include "eventqueue.h"
+#include "event.h"
+#include "globals.h"
+#include "iregistry.h"
+#include "version.h"
+
+#include <QtCore>
+
+
+//-------------------------------------------------------------------
+
+using namespace eVaf::Common;
+
+iEventQueue * iEventQueue::instance()
+{
+ static Internal::EventQueue singleton;
+ return &singleton;
+}
+
+
+//-------------------------------------------------------------------
+
+using namespace eVaf::Common::Internal;
+
+EventQueue::EventQueue()
+ : iEventQueue()
+ , mNextEventId(1)
+{
+}
+
+EventQueue::~EventQueue()
+{
+}
+
+bool EventQueue::event(QEvent * e)
+{
+ // Is it an eVaf event?
+ if (e->type() == Event::eVafEvent) {
+
+ Event * event = static_cast<Event *>(e);
+
+ uint id = event->id();
+
+ // Verify that this event is registered
+ QHash<uint, QString>::const_iterator eventsIt = mEvents.constFind(id);
+ if (eventsIt == mEvents.constEnd()) {
+ return true; // We don't know it, but it is an eVaf event and we should handle it
+ }
+
+ // Send the event to all the subscribers
+ QHash<uint, QList<QPointer<QObject> > >::const_iterator subscribersIt = mSubscribers.constFind(id);
+ if (subscribersIt != mSubscribers.constEnd()) {
+ QList<QPointer<QObject> > subscribers = *subscribersIt;
+ int sz = subscribers.size();
+ for (int i = 0; i < sz; ++i) {
+
+ // Get the subscriber object and make sure that it is still alive
+ QPointer<QObject> obj = subscribers.at(i);
+ if (obj.isNull()) {
+ continue;
+ }
+
+ // Notify the subscriber
+ bool rval = QCoreApplication::sendEvent(obj, e);
+
+ if (rval) {
+ // The event was consumed and should be sent to any other subscribers
+ break;
+ }
+ }
+ }
+
+ return true;
+ }
+ else
+ return iEventQueue::event(e);
+}
+
+uint EventQueue::registerEvent(QString const & name)
+{
+ uint id = queryEvent(name);
+
+ if (id == 0) {
+ mEvents.insert(mNextEventId, name);
+ id = mNextEventId++;
+ }
+
+ return id;
+}
+
+uint EventQueue::queryEvent(QString const & name) const
+{
+ return mEvents.key(name, 0);
+}
+
+void EventQueue::unregisterEvent(uint id)
+{
+ mEvents.remove(id);
+ mSubscribers.remove(id);
+}
+
+uint EventQueue::subscribeEvent(uint id, QObject * obj)
+{
+ if (id == 0)
+ return 0;
+
+ // Only registered events please
+ if (mEvents.constFind(id) == mEvents.constEnd()) {
+ return 0;
+ }
+
+ // Check for duplicates
+ if (mSubscribers[id].indexOf(obj) != -1)
+ return id;
+
+ mSubscribers[id].append(obj);
+
+ return id;
+}
+
+void EventQueue::unsubscribeEvent(uint id, QObject * obj)
+{
+ if (id == 0)
+ return;
+
+ // Is the event registered?
+ if (mEvents.constFind(id) == mEvents.constEnd())
+ return;
+
+ mSubscribers[id].removeAll(obj);
+}
+
+void EventQueue::broadcastEvent(Event * event)
+{
+ QCoreApplication::postEvent(this, event);
+}
--- /dev/null
+/**
+ * @file Common/eventqueue.h
+ * @brief Event queue interface implementation
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 Enar Vaikene
+ *
+ * This file is part of the eVaf C++ cross-platform application development framework.
+ *
+ * This file can be used under the terms of the GNU General Public License
+ * version 3.0 as published by the Free Software Foundation and appearing in
+ * the file LICENSE included in the packaging of this file. Please review the
+ * the following information to ensure the GNU General Public License version
+ * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+ *
+ * Alternatively, this file may be used in accordance with the Commercial License
+ * Agreement provided with the Software.
+ */
+
+#ifndef __COMMON_EVENTQUEUE_H
+#define __COMMON_EVENTQUEUE_H
+
+#include "ieventqueue.h"
+
+#include <QObject>
+#include <QString>
+#include <QHash>
+#include <QList>
+#include <QPointer>
+
+
+namespace eVaf {
+namespace Common {
+namespace Internal {
+
+/**
+ * iEventQueue interface implementation
+ */
+class EventQueue : public iEventQueue
+{
+ Q_OBJECT
+
+public:
+
+ EventQueue();
+
+ virtual ~EventQueue();
+
+ /// Qt event handler
+ virtual bool event(QEvent * e);
+
+ /*
+ iEventQueue interface
+ */
+
+ virtual uint registerEvent(QString const & name);
+
+ virtual uint queryEvent(QString const & name) const;
+
+ virtual void unregisterEvent(uint id);
+
+ virtual uint subscribeEvent(uint id, QObject * obj);
+
+ virtual void unsubscribeEvent(uint id, QObject * obj);
+
+ virtual void broadcastEvent(Event * event);
+
+
+private: // Members
+
+ /// ID of the next event
+ uint mNextEventId;
+
+ /// List of registered events
+ QHash<uint, QString> mEvents;
+
+ /// List of subscribers
+ QHash<uint, QList<QPointer<QObject> > > mSubscribers;
+
+};
+
+} // namespace evaf::Common::Internal
+} // namespace eVaf::Common
+} // namespace eVaf
+
+#endif // eventqueue.h
/**
* Requests the eVaf application to quit.
+ * @param err If true, then indicates that the application exits due to a fatal error
*
* This function requests the eVaf application to quit.
*/
- virtual void quit() = 0;
+ virtual void quit(bool err) = 0;
/**
* Returns true if the eVaf application is ready.
* on Linux is ${HOME}/.${EVAF_APP_NAME}.
*
* This directory can be changed with the EVAF_DATA_ROOT_DIR environment variable or with the
- * -data[root[dir]]=<directory> command line argument.
+ * -dataroot[dir]=<directory> command line argument.
*/
virtual QString const dataRootDir() const = 0;
* Changing this directory does not affect the way how Qt itself loads its plugins.
*
* This directory can be changed with the EVAF_QT_PLUGINS_DIR environment variable or with the
- * -qt[plugins[dir]]=<directory> command line argument.
+ * -qtplugins[dir]=<directory> command line argument.
*/
virtual QString const qtPluginsDir() const = 0;
/**
* @file Common/ieventqueue.h
- * @brief Event queue interfaces
+ * @brief Event queue interface
* @author Enar Vaikene
*
* Copyright (c) 2011 Enar Vaikene
namespace eVaf {
namespace Common {
+class Event;
+
/**
* The eVaf event queue interface
* @code#include <Common/iEventQueue>@endcode
/// Empty virtual destructor
virtual ~iEventQueue() {}
+ /**
+ * Returns the instance of the iEventQueue interface
+ * @return The iEventQueue interface
+ */
+ static iEventQueue * instance();
+
/**
* Registers an event
* @param name Name of the event
* are expected to be linked against the Common library, then this is the preferred method of obtaining
* the iLogger interface. The other method is by using the iRegistry interface.
*/
- static iLogger::instance();
+ static iLogger * instance();
/**
* Returns the current default source name.
Registry::Registry()
: iRegistry()
{
- setObjectName(QString("%1-iRegistry").arg(VER_MODULENAME_STR));
+ setObjectName(QString("%1-iRegistry").arg(VER_MODULE_NAME_STR));
// Register our own interface
registerInterface("iRegistry", this);
bool Registry::registerInterface(QString const & name, QObject * obj)
{
mInterfaces.insert(name, QPointer<QObject>(obj));
+
+ return true;
}
-QObject * Registry::queryInterface(QString const & name)
+QObject * Registry::queryInterface(QString const & name) const
{
QHash<QString, QPointer<QObject> >::const_iterator it = mInterfaces.constFind(name);
return it != mInterfaces.constEnd() ? *it : 0;