From: Enar Väikene Date: Wed, 20 Apr 2011 11:50:31 +0000 (+0300) Subject: Added more files to the project. X-Git-Url: https://vaikene.ee/gitweb/overview.html?a=commitdiff_plain;h=441d1b38e0900f56891f495a94a08dc8d48e0a32;p=evaf Added more files to the project. --- diff --git a/CMakeLinux.txt b/CMakeLinux.txt new file mode 100644 index 0000000..f45ee04 --- /dev/null +++ b/CMakeLinux.txt @@ -0,0 +1,12 @@ +# Extra rules for Linux builds + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fvisibility=hidden") + +# gcc options for release and debug builds +IF(CMAKE_BUILD_TYPE STREQUAL Release) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2") +ELSE(CMAKE_BUILD_TYPE STREQUAL Release) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") +ENDIF(CMAKE_BUILD_TYPE STREQUAL Release) + +set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined") diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f7baf28 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,48 @@ +project(eVaf) + +cmake_minimum_required(VERSION 2.6.0) + +if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +# Include our own cmake modules +set(CMAKE_MODULE_PATH ${eVaf_SOURCE_DIR}/mk/cmake) + +# Find Qt4 +find_package(Qt4 REQUIRED) + +# Default to the Debug build type if none is specified +IF(NOT CMAKE_BUILD_TYPE) + SET(CMAKE_BUILD_TYPE Debug) +ENDIF(NOT CMAKE_BUILD_TYPE) + +# Add QT_NO_DEBUG for Release builds +IF(CMAKE_BUILD_TYPE STREQUAL Release) + message(STATUS "Release build") + ADD_DEFINITIONS(-DQT_NO_DEBUG) +ELSE(CMAKE_BUILD_TYPE STREQUAL Release) + message(STATUS "Debug build") +ENDIF(CMAKE_BUILD_TYPE STREQUAL Release) + +# Where common eVaf header files are located +set(eVaf_INCLUDE ${CMAKE_SOURCE_DIR}/src/libs ${CMAKE_SOURCE_DIR}/src/plugins) + +# Include platform-specific rules +if(WIN32) + include(CMakeWin.txt) +else(WIN32) + if(UNIX) + include(CMakeLinux.txt) + endif(UNIX) +endif(WIN32) + +# Output all the executables and libraries to the bin directory +set(EXECUTABLE_OUTPUT_PATH ${eVaf_BINARY_DIR}/bin) +set(LIBRARY_OUTPUT_PATH ${eVaf_BINARY_DIR}/bin) + +# Uncomment if you want to see the commands that make runs +#set(CMAKE_VERBOSE_MAKEFILE ON) + +# Include subdirectories +add_subdirectory(src) diff --git a/CMakeWin.txt b/CMakeWin.txt new file mode 100644 index 0000000..6e43b9a --- /dev/null +++ b/CMakeWin.txt @@ -0,0 +1,3 @@ +# Extra rules for Windows builds + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:wchar_t-") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..79123e7 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(libs) +add_subdirectory(main) +add_subdirectory(plugins) diff --git a/src/libs/CMakeLists.txt b/src/libs/CMakeLists.txt new file mode 100644 index 0000000..918e3ce --- /dev/null +++ b/src/libs/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(Plugins) +add_subdirectory(Common) diff --git a/src/libs/Common/Globals b/src/libs/Common/Globals new file mode 100644 index 0000000..117c1b0 --- /dev/null +++ b/src/libs/Common/Globals @@ -0,0 +1 @@ +#include "globals.h" diff --git a/src/libs/Common/globals.h b/src/libs/Common/globals.h new file mode 100644 index 0000000..e21aa86 --- /dev/null +++ b/src/libs/Common/globals.h @@ -0,0 +1,54 @@ +/** + * @file Common/globals.h + * @brief Global constants and macros for eVaf + * @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_GLOBALS_H +# define __COMMON_GLOBALS_H + +#include "libcommon.h" + +/** + * Common namespace for eVaf. + */ +namespace eVaf { + +/** + * Common eVaf library. + * + * This library contains interfaces, classes and functions shared by all the eVaf applications + * and modules. This library is the required dependency for all the other libraries, modules and + * applications. + * + * The common eVaf library shall be initialized with the eVaf::Common::init() function. + */ +namespace Common { + +/** + * eVaf common library initialized + * @param args List of arguments + * @return True if ok; false if the initialization failed + * + * Call this function to initialize the common eVaf library after creating the Qt application + * object and before loading any of the modules. + */ +extern bool COMMON_EXPORT init(QStringList const & args); + +} // namespace eVaf::Common +} // namespace eVaf + +#endif // globals.h diff --git a/src/libs/Common/iEnv b/src/libs/Common/iEnv new file mode 100644 index 0000000..9c2cb25 --- /dev/null +++ b/src/libs/Common/iEnv @@ -0,0 +1 @@ +#include "ienv.h" diff --git a/src/libs/Common/iLogger b/src/libs/Common/iLogger new file mode 100644 index 0000000..da42c92 --- /dev/null +++ b/src/libs/Common/iLogger @@ -0,0 +1 @@ +#include "ilogger.h" diff --git a/src/libs/Common/iapp.h b/src/libs/Common/iapp.h new file mode 100644 index 0000000..55269e1 --- /dev/null +++ b/src/libs/Common/iapp.h @@ -0,0 +1,127 @@ +/** + * @file Common/iapp.h + * @brief eVaf application interface + * @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_IAPP_H +#define __COMMON_IAPP_H + +#include "libcommon.h" + +#include +#include + +namespace eVaf { +namespace Common { + +/** + * eVaf application interface + * @code#include @endcode + * + * The iApp interface provides information about current eVaf application. + * + * All the resources returned by this interface have default values, that should work in most of the cases. + * + * Default values can be overwritten with environment variables and command line arguments. If both are used, + * then command line arguments have higher priorities. + */ +class COMMON_EXPORT iApp : public QObject +{ + Q_OBJECT + +public: + + /// Interface constructor + iApp() : QObject() {} + + /// Empty virtual destructor + virtual ~iApp() {} + + /** + * Returns the iApp interface instance + * @return The iApp interface + * + * This function returns the global iApp interface instance. As all the eVaf modules and applications + * are expected to be linked against the common library, then this is the preferred method of obtaining + * the iApp interface. The other method is by using the iRegistry interface. + */ + static iApp * instance(); + + /** + * Returns the name of the eVaf application + * + * This function returns the name of the eVaf application, which is a string that identifies the application. + * The default name of the application is "eVaf". + * + * This name of the application can be changed with the EVAF_APP_NAME environment variable or with the + * -app[lication]=<name> command line argument. + */ + virtual QString const name() const = 0; + + /** + * Returns the current language and country used by the application. + * + * This function returns the current lowercase two-letter ISO 639 language code and uppercase + * two-letter ISO 3166 country code if set. + * + * The default language is queried from the operating system. + * + * The language can be changed with the EVAF_LANGUAGE environment variabel or with the + * -lang[uage]=<language> command line argument. + */ + virtual QString const language() const = 0; + + /** + * Returns the name of the application's XML file. + * + * This function returns the name of the application's XML file. + * It tries to find the most specific file name for the given language. If not found, then + * defaults to the generic name. + * + * For example, if the language is set to "et_EE" and the application's name is "eVaf", then + * it tries to find XML files with the following names "eVaf_et_EE.xml" and "eVaf_et.xml". If + * neither is found, defaults to the name "eVaf.xml". + * + * The path is not included in the returned file name. Use the eVaf::Common::iEnv::etcDir() function + * for the location of the file. + */ + virtual QString const xmlFileName() const = 0; + + +signals: + + /** + * Ready signal. + * + * This signal is emitted when the eVaf application is ready, ie the application initialized and all the + * modules loaded. + */ + void ready(); + + /** + * Terminating signal. + * + * This signal is emitted when the eVaf application is about to terminate. + */ + void terminating(); + +}; + +} // namespace eVaf::Common +} // namespace eVaf + +#endif diff --git a/src/libs/Common/ienv.h b/src/libs/Common/ienv.h new file mode 100644 index 0000000..0eba5ea --- /dev/null +++ b/src/libs/Common/ienv.h @@ -0,0 +1,158 @@ +/** + * @file Common/ienv.h + * @brief Environment interface + * @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_IENV_H +#define __COMMON_IENV_H + +#include "libcommon.h" + +#include +#include + +namespace eVaf { +namespace Common { + +/** + * Environment interface for eVaf applications + * @code#include @endcode + * + * The iEnv interface provides information about the environment where the application is running. + * Functions in this interface return names of directories where different resources are located. + * Modules should always use the iEnv interface for directory names and locations. + * + * Directory names returned by functions in this interface are UNIX path names and they are quaranteed + * to end with the '/' character. + * + * All the directories have reasonable default values, that should work in most of the cases. For example, + * the binary directory is set to the same directory where the application's main executable is located. + * The root directory is the parent of the binary directory etc. + * + * Default values can be overwritten with environment variables and command line arguments. If both are used, + * then command line arguments have higher priorities. + */ +class COMMON_EXPORT iEnv : public QObject +{ + Q_OBJECT + +public: + + /// Interface constructor + iEnv() : QObject() {} + + /// Empty virtual destructor + virtual ~iEnv() {} + + /** + * Returns the iEnv interface instance + * @return The iEnv interface + * + * This function returns the global iEnv interface instance. As all the eVaf modules and applications + * are expected to be linked against the common library, then this is the preferred method of obtaining + * the iEnv interface. The other method is by using the iRegistry interface. + */ + static iEnv * instance(); + + /** + * Returns the name of the eVaf root directory + * + * The root directory is the base directory where the eVaf application is installed. The default root + * directory is the parent of the binary directory. + * + * Write access to the root directory is not required to run the application. + * + * This directory can be changed with the EVAF_ROOT_DIR environment variable or with the -root[dir]=<directory> + * command line argument. + */ + virtual QString const rootDir() const = 0; + + /** + * Returns the name of the eVaf data directory. + * + * The data root directory is the base directory for all the directories that require write access. + * + * The default data directory on Windows is \%APPDATA\%/\%EVAF_APP_NAME\%. The default data directory + * 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. + */ + virtual QString const dataRootDir() const = 0; + + /** + * Returns the name of the binary files directory. + * + * The binary directory is the directory where all the application's binary files (main executable and + * modules) are located. The default binary directory is where the main executable is located. + * + * NB! Changing the application's root directory does not change the location of the binary directory. + */ + virtual QString const binDir() const = 0; + + /** + * Returns the configuration files directory. + * + * This is the directory where all the application's configuration files are located. The default + * configuration files directory is 'etc' in the data root directory. + * + * This directory can be changed with the EVAF_ETC_DIR environment variable or with the -etc[dir]=<directory> + * command line argument. + */ + virtual QString const etcDir() const = 0; + + /** + * Returns the log files directory. + * + * This is the directory where the application outputs all the log files. The default log files + * directory is 'log' in the data root directory. + * + * This directory can be changed with the EVAF_LOG_DIR environment variable or with the + * -log[dir]=<directory> command line argument. + */ + virtual QString const logDir() const = 0; + + /** + * Returns the documentation directory. + * + * This is the directory where all the documentation and help files are located. The default + * documentation directory is 'doc' in the root directory. + * + * This directory can be changed with the EVAF_DOC_DIR environment variable or with the + * -doc[dir]=<directory> command line argument. + */ + virtual QString const docDir() const = 0; + + /** + * Returns the Qt plugins directory. + * + * The Qt plugins directory is where additional Qt plugins are located. These Qt plugins + * are loaded manually by the application and specified in the application's XML file. + * + * 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. + */ + virtual QString const qtPluginsDir() const = 0; + +}; + +} // namespace eVaf::Common +} // namespace eVaf + +#endif diff --git a/src/libs/Common/ilogger.h b/src/libs/Common/ilogger.h new file mode 100644 index 0000000..ecc4858 --- /dev/null +++ b/src/libs/Common/ilogger.h @@ -0,0 +1,247 @@ +/** + * @file Common/ilogger.h + * @brief Logger interface for eVaf + * @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_ILOGGER_H +# define __COMMON_ILOGGER_H + +#include "libcommon.h" + +#include +#include +#include + + +namespace eVaf { +namespace Common { + +/** + * Prototype for custom fatal message handler. + * + * This is a typedef for a pointer to a function with the following signature: + * @code + * void myFatalMessageHandler(QString const & msg, QString const & source, QString const & where); + * @endcode + * + * @sa iLogger::installFatalMsgHandler() + */ +typedef void (*FatalMsgHandler)(QString const & msg, QString const & source, QString const & where); + +/** + * Logger interface for eVaf modules and applications. + * @code#include @endcode + * + */ +class COMMON_EXPORT iLogger : public QObject +{ + Q_OBJECT + +public: + + /** + * Severity levels for messages indicating the meaning and seriousness of the message. + */ + enum Severity { + None = 0, ///< For disabling logging completely (to be not used with messages). + Fatal, ///< Fatal error that causes the application to stop functioning. + Error, ///< Unexpected issues in the software that could be solved automatically. + Warning, ///< Expected issues in the software that will be solved automatically. + Info, ///< General information output by the application or modules. + Debug ///< Information for debugging purposes. + }; + + /// Interface constructor + iLogger() : QObject() {} + + /// Empty virtual destructor + virtual ~iLogger() {} + + /** + * Returns the iLogger interface instance. + * @return The iLogger interface + * + * The instance() function returns the global iLogger interface instance. As all the modules and applications + * 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(); + + /** + * Returns the current default source name. + */ + virtual QString defaultSource() const = 0; + + /** + * Sets the default source. + * @param source The new default source name. + * + * Use the setDefaultSource() function to change the default source name. If not set, then + * uses the default source name "common". + */ + virtual void setDefaultSource(QString const & source) = 0; + + /** + * Returns the current severity level + * @param source Name of the source or default if omitted. + */ + virtual Severity severity(QString const & source = 0) const = 0; + + /** + * Changes the current severity level. + * @param severity The new severity level + * @param source Name of the source or default if omitted. + * + * This function changes the severity level of the given logger source. By default, only fatal errors + * are output. With this function the severity level can be changed so that also less important + * messages are output. + */ + virtual void setSeverity(Severity severity, QString const & source) = 0; + + /** + * Returns the current maximum size of log files in KiB. + * @param source Name of the source or default if omitted. + */ + virtual uint maxSize(QString const & source = 0) const = 0; + + /** + * Changes the maximum size of log files for the given source + * @param maxSize The new maximum size in KiB + * @param source Name of the source of default if omitted. + * + * This function changes the maximum size of log files. Log files larger than this value + * will be renamed to backup files. + * + * The default value for all the sources is usually 100 KiB. + * + * Set the maximum size to 0 for no limits (dangerous!). + */ + virtual void setMaxSize(uint maxSize, QString const & source = 0) = 0; + + /** + * Returns the maximum number of log files. + * @param source Name of the source or default if omitted. + */ + virtual uint maxCount(QString const & source = 0) const = 0; + + /** + * Changes the maximum number of log files + * @param maxCount The new maximum number + * @param source Name of the source or default if omitted + * + * This function sets the maximum number of log files including the current log file + * and any backup files. Older backup files are deleted to keep the number of log + * files at the maximum. + * + * The default value for all the sources is usually 3 (the current log file plus 2 + * backup files). + * + * Set the maximum number of log files to 0 for no limits (dangerous!). + */ + virtual void setMaxCount(uint maxCount, QString const & source = 0) = 0; + + /** + * Returns the current console severity level. + */ + virtual Severity consoleSeverity() const = 0; + + /** + * Changes the console severity level. + * @param severity The new console severity level + * + * This function changes the console severity level. By default, only fatal errors are output to + * the console. + */ + virtual void setConsoleSeverity(Severity severity) = 0; + + /** + * Outputs a message. + * @param severity Severity of the message, ie how important it is. + * @param msg The message to be output + * @param source Source of the message or default if omitted. + * @param where Location in the source file where the message was output. + * + * This function writes a message to the log file if the severity is high enough. If the + * severity is lower than the current severity level, then does nothing. + * + * If the source parameter is given, then uses the specified source. Otherwise writes + * to the default log file. + * + * The where parameter can be used to indicate the location in the source file where + * the message was generated. + * + * Messages for the default source are also output to the console if the console severity + * level is high enough. + */ + virtual void write(Severity severity, QString const & msg, QString const & source = 0, QString const & where = 0) = 0; + + /** + * Helper function for formatting messages using the standard printf() function. + * @param fmt The format string + * @param ... Variable number of arguments + * @return The formatted string + */ + virtual QString printf(char const * const fmt, ...) const +#ifdef Q_OS_LINUX + __attribute__((format(printf, 2, 3))) +#endif + = 0; + + /** + * Replaces non-printable characters in the input string with human-readable strings. + * @param msg The input string + * @return Human-readable string + * + * This function replaces all the non-printable characters with human-readable strings, like + * ASCII symbol names or HEX codes. + * + * For example, the Line Feed character will be replaced with "[LF]". + */ + virtual QString printable(QByteArray const & msg) const = 0; + + /** + * Installs a fatal error message handler. + * @param newHandler The new fatal error message handler + * @return The old fatal error message handler + * + * This function installs a custom fatal error message handler. The custom fatal error message + * handler is responsible for giving feedback to the user and terminating the application. + * + * The default fatal error message handler outputs the message to stderr and terminates the + * application. + */ + virtual FatalMsgHandler installFatalMsgHandler(FatalMsgHandler newHandler) = 0; + +}; + +} // namespace eVaf::Common +} // namespace eVaf + +/** + * Outputs info messages + * @param msg The format string + * @param ... Variable list of arguments + * + * The qInfo() function adds info messages to the Qt family of functions qDebug(), qWarning(), qError() and qFatal(). + */ +void COMMON_EXPORT qInfo(char const * const msg, ...) +#ifdef Q_OS_LINUX + __attribute__((format(printf, 1, 2))) +#endif +; + +#endif // ilogger.h diff --git a/src/libs/Common/libcommon.h b/src/libs/Common/libcommon.h new file mode 100644 index 0000000..e1c58a9 --- /dev/null +++ b/src/libs/Common/libcommon.h @@ -0,0 +1,30 @@ +/** + * @file Common/libcommon.h + * @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_LIBCOMMON_H +# define __COMMON_LIBCOMMON_H + +#include + +#if defined(COMMON_LIBRARY) +# define COMMON_EXPORT Q_DECL_EXPORT +#else +# define COMMON_EXPORT Q_DECL_IMPORT +#endif + +#endif // libcommon.h diff --git a/src/libs/Plugins/CMakeLists.txt b/src/libs/Plugins/CMakeLists.txt new file mode 100644 index 0000000..f0b59ad --- /dev/null +++ b/src/libs/Plugins/CMakeLists.txt @@ -0,0 +1,42 @@ +# Name of the target +set(TARGET PluginsLib) + +# Qt modules +set(QT_DONT_USE_QTGUI TRUE) +set(QT_USE_QTXML TRUE) +include(${QT_USE_FILE}) + +# Needed for exporting/importing symbols +add_definitions(-DPLUGINS_LIBRARY) + +# Include files +include_directories(${eVaf_INCLUDE}) + +# Required eVaf libraries +set(eVaf_LIBRARIES) + +# Source files +set(SRCS + pluginmanager.cpp +) + +# Header files for the meta-object compiler +set(MOC_HDRS + iplugin.h + ipluginfactory.h + pluginmanager.h + pluginmanager_p.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) diff --git a/src/libs/Plugins/PluginManager b/src/libs/Plugins/PluginManager new file mode 100644 index 0000000..7f19fcd --- /dev/null +++ b/src/libs/Plugins/PluginManager @@ -0,0 +1 @@ +#include "pluginmanager.h" diff --git a/src/libs/Plugins/iPlugin b/src/libs/Plugins/iPlugin new file mode 100644 index 0000000..c359428 --- /dev/null +++ b/src/libs/Plugins/iPlugin @@ -0,0 +1 @@ +#include "iplugin.h" diff --git a/src/libs/Plugins/iplugin.h b/src/libs/Plugins/iplugin.h new file mode 100644 index 0000000..1cc2b8e --- /dev/null +++ b/src/libs/Plugins/iplugin.h @@ -0,0 +1,94 @@ +/** + * @file plugins/iplugin.h + * @brief Common interface for all the eVaf modules + * @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 __PLUGINS_IPLUGIN_H +#define __PLUGINS_IPLUGIN_H + +#include "libplugins.h" + +#include +#include + +namespace eVaf { +namespace Plugins { + +/** + * Common interface for all the eVaf modules. + * + * @code#include @endcode + * + * The iPlugin interface is the common interface implemented by all the eVaf modules. + */ +class PLUGINS_EXPORT iPlugin : public QObject +{ + Q_OBJECT + +public: + + /// Empty constructor + iPlugin() : QObject() {} + + /// Empty virtual destructor + virtual ~iPlugin() {} + + /** + * Initializes the module that implements the iPlugin interface + * @param args Arguments for the initialization + * @return True if ok; false if initialization failed + * + * The plugin manager calls the init() function for every eVaf module during the initialization + * of the application. Modules implementing the iPlugin interface shall allocate and initialize + * all the required resources in the init() function. + * + * Modules can assume that the init() function is always called once after loading the module + * and creating the interface object. Every init() function call is followed by a done() + * function call during the finalization of the application. Modules can be initialized + * multiple times without destroying the interface object, but init() function calls are + * always followed by a done() function call. + * + * When the init() function returns true, then the initialization of the module shall be completed + * and all the interfaces and other resources published by the module safe to use. + * + */ + virtual bool init(const QString & args) = 0; + + /** + * Finalizes the module. + * + * The plugin manager calls the done() function for every eVaf module during the finalization + * of the application. Modules implementing the iPlugin interface shall finalize and release + * all the resources in the done() function. + */ + virtual void done() = 0; + + /** + * Ready flag. + * @return True if the module is ready. + * + * The ready flag indicates that the module is initialized and all the published interfaces + * and resources safe to use. + */ + virtual bool isReady() const = 0; + +}; + +} // namespace eVaf::Plugins +} // namespace eVaf + +#endif // iplugin.h diff --git a/src/libs/Plugins/libplugins.h b/src/libs/Plugins/libplugins.h new file mode 100644 index 0000000..dbca84c --- /dev/null +++ b/src/libs/Plugins/libplugins.h @@ -0,0 +1,30 @@ +/** + * @file Plugins/libplugins.h + * @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 __PLUGINS_LIBPLUGINS_H +#define __PLUGINS_LIBPLUGINS_H + +#include + +#if defined(PLUGINS_LIBRARY) +# define PLUGINS_EXPORT Q_DECL_EXPORT +#else +# define PLUGINS_EXPORT Q_DECL_IMPORT +#endif + +#endif // libplugins.h diff --git a/src/libs/Plugins/pluginmanager.h b/src/libs/Plugins/pluginmanager.h new file mode 100644 index 0000000..2f320f9 --- /dev/null +++ b/src/libs/Plugins/pluginmanager.h @@ -0,0 +1,111 @@ +/** + * @file plugins/pluginmanager.h + * @brief Manager for loadable modules (plugins) + * + * 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 __PLUGINS_PLUGINMANAGER_H +#define __PLUGINS_PLUGINMANAGER_H + +#include "libplugins.h" + +#include + +#include + +/** + * Library for managing loadable modules (plugins). + * + * The Plugins library adds loadable modules (plugins) support to the eVaf application. A module is one + * external library (.so or .dll file) that implements one or more plugins. A plugin is an individual object + * that is created and initialized as one entirety. + * + * Modules are loaded and plugins created by the plugin manager. Plugin manager uses the application's + * XML file to define which modules should be loaded and which plugins to be created. + */ +namespace Plugins { + +/** + * Internal implementation of the plugin manager library. + */ +namespace Internal { + class PluginManagerPrivate; +} + +/** + * Plugin manager for eVaf applications. + */ +class PLUGINS_EXPORT PluginManager : public QObject +{ + Q_OBJECT + +public: + + /// Ctr. + PluginManager(); + + /// Dtr. + virtual ~PluginManager(); + + /** + * Returns the plugin manager's instance + */ + static PluginManager * instance(); + + /** + * Initializes the plugin manager. + * @return True if ok; false if initialization failed. + * + * This function initializes the plugin manager. External modules are loaded and plugin objects + * created in this function. + */ + bool init(); + + /** + * Finalizes the plugin manager. + * + * This function finalizes the plugin manager. Plugin objects are destroyed and external modules + * unloaded in this function. + */ + void done(); + + +signals: + + /** + * Plugins loaded signal. + * + * This signal is emitted when all the modules are loaded and plugin objects created. + */ + void pluginsLoaded(); + + /** + * Plugins unloaded signal. + * + * This signal is emitted when all the plugin objects are destroyed and modules unloaded. + */ + void pluginsUnloaded(); + + +private: + + Internal::PluginManagerPrivate * dl; + +}; + +} // namespace Plugins + + +#endif // pluginmanager.h diff --git a/src/libs/version_rc.h b/src/libs/version_rc.h new file mode 100644 index 0000000..d174e8d --- /dev/null +++ b/src/libs/version_rc.h @@ -0,0 +1,217 @@ +/** + * @file version_rc.h + * @brief Global version information for eVaf applications and modules + * @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 __VERSION_RC_H +#define __VERSION_RC_H + +/** + * Product's version number in the format major,minor,release + */ +#ifndef VER_PRODUCT_VERSION +# define VER_PRODUCT_VERSION 0,1,1 +#endif + +/** + * Product's version number in the human-readable format (shall end with \0) + */ +#ifndef VER_PRODUCT_VERSION_STR +# define VER_PRODUCT_VERSION_STR "0.1.1\0" +#endif + +/** + * Product's name (shall end with \0) + */ +#ifndef VER_PRODUCT_NAME_STR +# define VER_PRODUCT_NAME_STR "eVaf\0" +#endif + +/** + * Product's release date (shall end with \0) + */ +#ifndef VER_PRODUCT_DATE_STR +# define VER_PRODUCT_DATE_STR "N/A\0" +#endif + +/** + * Legal copyright (shall end with \0) + */ +#ifndef VER_LEGAL_COPYRIGHT_STR +# define VER_LEGAL_COPYRIGHT_STR "(C) 2011 Enar Vaikene\0" +#endif + +/** + * Name of the company (shall end with \0) + */ +#ifndef VER_COMPANY_NAME_STR +# define VER_COMPANY_NAME_STR "N/A\0" +#endif + +/** + * Generic type for modules. + * The string version shall end with \0. + */ +#define MT_GENERIC 0 +#define MT_GENERIC_STR "generic\0" + +/** + * Version info structure for modules. + * + * All the eVaf modules include this version info structure so that their version numbers, + * purposes etc can be retrieved before loading the module. + */ +struct ModuleVersionInfo +{ + /** + * Type of the module. + * + * This value can be used to group modules by their purpose. For example, if all the communication + * modules had the same module type value, then this value can be used to determine, which modules + * should be shown in a list of available communication modules. + * + * The exact meaning of the type is up to the application. Generic modules should use the type + * MT_GENERIC. + */ + uint const type; + + /** + * Name of the module. + * + * A short name of the module. + */ + char const * const name; + + /** + * 4-digit version number of the module in the format major,minor,release,build + */ + uint const version[4]; + + /** + * Human-readable version number of the module. + */ + char const * const versionStr; + + /** + * Description of the module. + * + * A longer description explaining the purpose of the module. + */ + char const * const description; + + /** + * Name of the product. + * + * If the module is part of a product, then this field holds the name of the product. + */ + char const * const prodName; + + /** + * 3-digit product version number in the format major,minor,release + * + * If the module is part of a product, then this field holds the version number + * of the product. + */ + uint const prodVersion[3]; + + /** + * Human-readable product version number of the product. + */ + char const * const prodVersionStr; + + /** + * Human-readable release date of the product. + * + * If the module is part of a product, then this field holds the release date + * of the product. + */ + char const * const prodDateStr; + + /** + * Legal copyright. + */ + char const * const copyright; + + /** + * Name of the company. + */ + char const * const company; + +}; + +#ifndef C_EXTERN_C +# ifdef __cplusplus +# define C_EXTERN_C extern "C" +# else +# define C_EXTERN_C +# endif +#endif + +/** + * Function prototype that returns version information from a module. + * + * This is a typedef for a pointer to a function with the following signature: + * @code + * void queryVersionInfo(ModuleVersionInfo **); + * @endcode + * + * Every eVaf module is expected to export this function and the version info shall + * be available without any extra initialization. + * + * The function copies the address of the ModuleVersionInfo structure to the variable at ptr. + */ +typedef void (* ModuleQueryVersionInfoFunction)(ModuleVersionInfo ** ptr); + +/** + * Macro that exports version information from modules. + * + * At least the following macros describing the module shall be defined for this macro to work properly: + * @li VER_MODULE_TYPE + * @li VER_MODULE_NAME_STR + * @li VER_FILE_VERSION + * @li VER_FILE_VERSION_STR + * @li VER_FILE_DESCRIPTION_STR + * + * Additional macros describing the product are: + * @li VER_PRODUCT_NAME_STR + * @li VER_PRODUCT_VERSION + * @li VER_PRODUCT_VERSION_STR + * @li VER_PRODUCT_DATE_STR + * + * And some legal stuff: + * @li VER_LEGAL_COPYRIGHT_STR + * @li VER_COMPANY_NAME_STR + */ +#define VER_EXPORT_VERSION_INFO() \ + C_EXTERN_C Q_DECL_EXPORT void moduleQueryVersionInfo(ModuleVersionInfo ** ptr) \ + { \ + static ModuleVersionInfo ver = { VER_MODULE_TYPE, \ + VER_MODULE_NAME_STR, \ + { VER_FILE_VERSION }, \ + VER_FILE_VERSION_STR, \ + VER_FILE_DESCRIPTION_STR, \ + VER_PRODUCT_NAME_STR, \ + { VER_PRODUCT_VERSION }, \ + VER_PRODUCT_VERSION_STR, \ + VER_PRODUCT_DATE_STR, \ + VER_LEGAL_COPYRIGHT_STR, \ + VER_COMPANY_NAME_STR \ + }; \ + *ptr = &ver; \ + } + +#endif // version_rc.h diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt new file mode 100644 index 0000000..b686c31 --- /dev/null +++ b/src/main/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(gui) +add_subdirectory(cli) diff --git a/src/main/cli/CMakeLists.txt b/src/main/cli/CMakeLists.txt new file mode 100644 index 0000000..f27ec1f --- /dev/null +++ b/src/main/cli/CMakeLists.txt @@ -0,0 +1,38 @@ +# Name of the target +set(TARGET eVafCLI) + +# Qt modules +set(QT_DONT_USE_QTGUI TRUE) +include(${QT_USE_FILE}) + +# Include files +include_directories(${eVaf_INCLUDE}) + +# Required eVaf libraries +set(eVaf_LIBRARIES) + +# Source files +set(SRCS + main.cpp + exithandler.cpp + version.cpp +) + +# Header files for the meta-object compiler +set(MOC_HDRS + main.h + version_p.h +) + +# Version info resource file for Windows builds +if(WIN32) + set(SRCS ${SRCS} version.rc cli.rc) +endif(WIN32) + +qt4_wrap_cpp(MOC_SRCS ${MOC_HDRS}) + +add_executable(${TARGET} ${SRCS} ${MOC_SRCS}) + +target_link_libraries(${TARGET} ${QT_LIBRARIES} ${eVaf_LIBRARIES}) + +install(TARGETS ${TARGET} DESTINATION bin) diff --git a/src/main/cli/main.cpp b/src/main/cli/main.cpp new file mode 100644 index 0000000..4c57084 --- /dev/null +++ b/src/main/cli/main.cpp @@ -0,0 +1,56 @@ +/** + * @file main/gui/main.cpp + * @brief The main eVaf GUI application class + * + * 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 "main.h" +#include "exithandler.h" +#include "fatalerr.h" +#include "version_p.h" +#include "version.h" + +#ifdef Q_OS_WIN32 +#include "winconsole.h" +#endif + +#include + + +//------------------------------------------------------------------- + +using namespace eVafGUI; + +Application::Application(int & argc, char ** argv) + : QApplication(argc, argv) +{ + setObjectName(QString("%1-%2").arg(VER_MODULENAME_STR).arg(__FUNCTION__)); + + setWindowIcon(QIcon(":/eVafGUI/Icon")); +} + +Application::~Application() +{ +} + + +//------------------------------------------------------------------- + +int main(int argc, char ** argv) +{ + Application app(argc, argv); + + return rval; +} diff --git a/src/main/cli/main.h b/src/main/cli/main.h new file mode 100644 index 0000000..41ec6b5 --- /dev/null +++ b/src/main/cli/main.h @@ -0,0 +1,35 @@ +/** + * @file main/cli/main.h + * @brief The main eVaf CLI application class + * + * 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 __CLI_MAIN_H +#define __CLI_MAIN_H + +#include + + +/** + * The main eVaf CLI application. + * + * eVafGUI is the main CLI executable. It provides an empty CLI application + * that is used to load other eVaf modules. + */ +namespace eVafCLI { + +} // namespace eVafCLI + +#endif // main.h diff --git a/src/main/gui/CMakeLists.txt b/src/main/gui/CMakeLists.txt new file mode 100644 index 0000000..5339fea --- /dev/null +++ b/src/main/gui/CMakeLists.txt @@ -0,0 +1,53 @@ +# Name of the target +set(TARGET eVafGUI) + +# Qt modules +set(QT_USE_QTMAIN TRUE) +include(${QT_USE_FILE}) + +# Include files +include_directories(${eVaf_INCLUDE}) + +# Required eVaf libraries +set(eVaf_LIBRARIES) + +# Source files +set(SRCS + main.cpp + exithandler.cpp + fatalerr.cpp + version.cpp +) +if(WIN32) + set(SRCS + ${SRCS} + winconsole.cpp + ) +) + +# Header files for the meta-object compiler +set(MOC_HDRS + main.h + fatalerr.h + version_p.h +) + +# Resources +set(RCCS + gui.qrc +) + +# Version info resource file for Windows builds +if(WIN32) + set(SRCS ${SRCS} version.rc gui.rc) +endif(WIN32) + +qt4_add_resources(RCC_SRCS ${RCCS}) + +qt4_wrap_cpp(MOC_SRCS ${MOC_HDRS}) + +add_executable(${TARGET} WIN32 ${SRCS} ${MOC_SRCS} ${RCC_SRCS}) + +target_link_libraries(${TARGET} ${QT_LIBRARIES} ${eVaf_LIBRARIES}) + +install(TARGETS ${TARGET} DESTINATION bin) diff --git a/src/main/gui/main.h b/src/main/gui/main.h new file mode 100644 index 0000000..46daca7 --- /dev/null +++ b/src/main/gui/main.h @@ -0,0 +1,50 @@ +/** + * @file main/gui/main.h + * @brief The main eVaf GUI application class + * + * 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 __GUI_MAIN_H +#define __GUI_MAIN_H + +#include + + +/** + * The main eVaf GUI application. + * + * eVafGUI is the main GUI executable. It provides an empty GUI application + * that is used to load other eVaf modules. + */ +namespace eVafGUI { + +/** + * The main eVaf GUI application class. + */ +class Application : public QApplication +{ + Q_OBJECT + +public: + + Application(int & argc, char ** argv); + + virtual ~Application(); + +}; + +} // namespace eVafGUI + +#endif // main.h