set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
-set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
+if(NOT APPLE)
+ set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
+endif()
project(eVaf)
-cmake_minimum_required(VERSION 2.8.9)
+cmake_minimum_required(VERSION 3.1)
+set (CMAKE_CXX_STANDARD 11)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
Module::Module()
: Plugins::iPlugin()
, mReady(false)
- , mGenerator(0)
- , mStorage(0)
+ , mGenerator(NULL)
+ , mStorage(NULL)
{
setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__));
* @brief Application interface implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
using namespace eVaf::Common;
+namespace
+{
+ static Internal::App * singleton = nullptr;
+}
+
iApp * iApp::instance()
{
- static Internal::App singleton;
- return &singleton;
+ if (nullptr == singleton)
+ {
+ singleton = new Internal::App;
+ }
+ return singleton;
}
char const * const iApp::EV_QUIT = "iApp::quit";
using namespace eVaf::Common::Internal;
+void App::destroyInstance()
+{
+ if (nullptr != singleton)
+ {
+ delete singleton;
+ singleton = nullptr;
+ }
+}
+
App::App()
: iApp()
, mReady(false)
, mEvTerminating(0)
{
setObjectName(QString("%1.iApp").arg(VER_MODULE_NAME_STR));
-
+ EVAF_INFO("%s-App created", VER_MODULE_NAME_STR);
}
App::~App()
{
+ EVAF_INFO("%s-App destroyed", VER_MODULE_NAME_STR);
}
bool App::init()
QString const App::dataRootDir() const
{
if (mDataRootDir.isEmpty()) {
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
QString dataLoc = QDir::homePath();
if (!dataLoc.endsWith('/'))
dataLoc.append('/');
* @brief Application interface implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
public:
+ /**
+ * Destroys the iApp interface instance
+ */
+ static void destroyInstance();
+
App();
virtual ~App();
* @brief eVaf configuration interface implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
using namespace eVaf::Common;
+namespace
+{
+ static Internal::Config * singleton = nullptr;
+}
+
iConfig * iConfig::instance()
{
- static Internal::Config singleton;
- return singleton._interface();
+ if (nullptr == singleton)
+ {
+ singleton = new Internal::Config;
+ }
+ return singleton->_interface();
}
using namespace eVaf::Common::Internal;
+void Config::destroyInstance()
+{
+ if (nullptr != singleton)
+ {
+ delete singleton;
+ singleton = nullptr;
+ }
+}
+
Config::Config()
: iConfig()
{
// Register the iConfig interface
iRegistry::instance()->registerInterface("iConfig", this);
+
+ EVAF_INFO("%s-Config created", VER_MODULE_NAME_STR);
}
Config::~Config()
{
done();
+ EVAF_INFO("%s-Config destroyed", VER_MODULE_NAME_STR);
}
iConfig * Config::_interface() const
if (file.isEmpty() || file == "*")
file = iApp::instance()->name();
- IniFile * ini = 0;
+ IniFile * ini = nullptr;
// Is this INI file already opened?
QHash<QString, IniFile *>::const_iterator it = mIniFiles.constFind(file);
if (file.isEmpty() || file == "*")
file = iApp::instance()->name();
- IniFile * ini = 0;
+ IniFile * ini = nullptr;
// Is this INI file already opened?
QHash<QString, IniFile *>::const_iterator it = mIniFiles.constFind(file);
* @brief eVaf configuration interface implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
public:
+ /**
+ * Destroys the iConfig interface instance.
+ */
+ static void destroyInstance();
+
Config();
virtual ~Config();
* @brief Base class for all the events
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
* is decreased by 1 when the event object is destroyed. If nobody else claimed the ownership, then
* the shared data object is destroyed too.
*/
- Event(uint eventId, quint32 intValue = 0, QSharedData * dataObj = 0)
+ Event(uint eventId, quint32 intValue = 0, QSharedData * dataObj = nullptr)
: QEvent(eVafEvent)
, mId(eventId)
, mValue(intValue)
* is finished, the event and shared data attached to it are destroyed. To keep the shared
* data object, use QExplicitlySharedDataPointer<> to claim ownership.
*/
- inline QSharedData * data() const { return mData ? mData.data() : 0; }
+ inline QSharedData * data() const { return mData != nullptr ? mData.data() : nullptr; }
private:
* @brief Event queue interface implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
Event * event = static_cast<Event *>(e);
- uint id = event->id();
+ uint const id = event->id();
// Verify that this event is registered
Events::const_iterator eventsIt = mEvents.constFind(id);
* @brief Event queue interface implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
/// One of the subscribers is destroyed
/// We need to remove it from the list of subscribers.
- void subscriberDestroyed(QObject * obj = 0);
+ void subscriberDestroyed(QObject * obj = nullptr);
};
* @brief Global constants and macros for eVaf
* @author Enar Vaikene
*
- * Copyright (c) 2011-2012 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
#include "logger.h"
#include "version.h"
#include "ilogger.h"
+#include "iregistry.h"
#include <QCoreApplication>
bool eVaf::Common::init()
{
- if (QCoreApplication::instance() == 0) {
+ if (QCoreApplication::instance() == nullptr) {
EVAF_FATAL_ERROR("QApplication is not instantiated");
return false;
}
return true;
}
+
+void eVaf::Common::done()
+{
+ EVAF_INFO("Finalizing %s-Globals", VER_MODULE_NAME_STR);
+
+ //eVaf::Common::Internal::Logger::destroyInstance();
+ eVaf::Common::Internal::Prop::destroyInstance();
+ eVaf::Common::Internal::Config::destroyInstance();
+ eVaf::Common::Internal::App::destroyInstance();
+
+ EVAF_INFO("%s-Globals finalized", VER_MODULE_NAME_STR);
+}
* @brief Global constants and macros for eVaf
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
namespace Common {
/**
- * eVaf common library initialized
+ * eVaf common library initializer
* @return True if ok; false if the initialization failed
*
* Call this function to initialize the common eVaf library after creating the Qt application
*/
extern bool COMMON_EXPORT init();
+/**
+ * eVaf common library finalizer
+ *
+ * Call this function to finalize the common eVaf library after destroying the Qt application
+ * object and unloading all the modules.
+ */
+extern void COMMON_EXPORT done();
+
/**
* Internal implementation of the common eVaf library.
*/
* @brief eVaf application interface
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
* @brief eVaf configuration interface
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
* @brief Event queue interface
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
* @brief Logger interface for eVaf
* @author Enar Vaikene
*
- * Copyright (c) 2011-2012 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
* Returns the current severity level
* @param source Name of the source or default if omitted.
*/
- virtual Severity severity(QString const & source = 0) = 0;
+ virtual Severity severity(QString const & source = QString()) = 0;
/**
* Changes the current severity level.
* 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) = 0;
+ virtual void setSeverity(Severity severity, QString const & source = QString()) = 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) = 0;
+ virtual uint maxSize(QString const & source = QString()) = 0;
/**
* Changes the maximum size of log files for the given source
*
* Set the maximum size to 0 for no limits (dangerous!).
*/
- virtual void setMaxSize(uint maxSize, QString const & source = 0) = 0;
+ virtual void setMaxSize(uint maxSize, QString const & source = QString()) = 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) = 0;
+ virtual uint maxCount(QString const & source = QString()) = 0;
/**
* Changes the maximum number of log files
*
* Set the maximum number of log files to 0 for no limits (dangerous!).
*/
- virtual void setMaxCount(uint maxCount, QString const & source = 0) = 0;
+ virtual void setMaxCount(uint maxCount, QString const & source = QString()) = 0;
/**
* Returns the current console severity level.
* 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;
+ virtual void write(Severity severity, QString const & msg, QString const & source = QString(), QString const & where = QString()) = 0;
/**
* Helper function for formatting messages using the standard printf() function.
* @return The formatted string
*/
virtual QString printf(char const * const fmt, ...) const
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
__attribute__((format(printf, 2, 3)))
#endif
= 0;
eVaf::Common::iLogger::instance()->write( \
eVaf::Common::iLogger::Fatal, \
eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
- 0, \
+ QString(), \
eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
); \
} while (0)
eVaf::Common::iLogger::instance()->write( \
eVaf::Common::iLogger::Error, \
eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
- 0, \
+ QString(), \
eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
); \
} while (0)
eVaf::Common::iLogger::instance()->write( \
eVaf::Common::iLogger::Warning, \
eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
- 0, \
+ QString(), \
eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
); \
} while (0)
eVaf::Common::iLogger::instance()->write( \
eVaf::Common::iLogger::Info, \
eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
- 0, \
+ QString(), \
eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
); \
} while (0)
eVaf::Common::iLogger::instance()->write( \
eVaf::Common::iLogger::Debug, \
eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
- 0, \
+ QString(), \
eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
); \
} while (0)
//-------------------------------------------------------------------
IniFile::IniFile(QString const & fileName, QIODevice::OpenMode mode)
+ : d(new Internal::IniFileImpl(fileName, mode))
{
- d = new Internal::IniFileImpl(fileName, mode);
}
IniFile::~IniFile()
{
- delete d;
+ d.reset();
}
bool IniFile::isValid() const
// Check for the 'windows:' or 'linux:' prefix in the parameter name
bool thisOsOnly = false;
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
if (name.startsWith("windows:"))
continue;
if (name.startsWith("linux:")) {
* @brief Class for reading and writing parameter values in INI files.
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
#include <QString>
#include <QVariant>
#include <QIODevice>
+#include <QScopedPointer>
namespace eVaf {
namespace Common {
private:
/// Pointer to the internal implementation of the class
- Internal::IniFileImpl * d;
+ QScopedPointer<Internal::IniFileImpl> d;
};
* @brief Internal implementation of the class for reading and writing parameter values in INI files.
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
//-------------------------------------------------------------------
-void eVaf::Common::Internal::defFatalMsgHandler(QString const & msg, QString const & source, QString const & where)
+[[noreturn]] void eVaf::Common::Internal::defFatalMsgHandler(QString const & msg, QString const & source, QString const & where)
{
Q_UNUSED(source);
using namespace eVaf::Common;
+namespace
+{
+ static Internal::Logger * singleton = nullptr;
+}
+
iLogger * iLogger::instance()
{
- static Internal::Logger singleton;
- return &singleton;
+ if (nullptr == singleton)
+ {
+ singleton = new Internal::Logger;
+ }
+ return singleton;
}
IniFile ini(confFileName, QIODevice::ReadOnly);
// Default values for all sources
- maxSize = 1024 * ini.getValue(".default/log_size", maxSize / 1024).toInt();
- maxCount = ini.getValue(".default/log_count", maxCount).toInt();
+ maxSize = 1024 * ini.getValue(".default/log_size", maxSize / 1024).toUInt();
+ maxCount = ini.getValue(".default/log_count", maxCount).toUInt();
// Default values for this source
- maxSize = 1024 * ini.getValue(source.toLatin1() + "/log_size", maxSize / 1024).toInt();
- maxCount = ini.getValue(source.toLatin1() + "/log_count", maxCount).toInt();
+ maxSize = 1024 * ini.getValue(source.toLatin1() + "/log_size", maxSize / 1024).toUInt();
+ maxCount = ini.getValue(source.toLatin1() + "/log_count", maxCount).toUInt();
}
}
//-------------------------------------------------------------------
-/// Recursively renames backup files
-void renameBackupFile(QDir & dir, QString const & baseName, int idx)
+namespace
{
- QString f1 = QString("%1.%2").arg(baseName).arg(idx);
- QString f2 = QString("%1.%2").arg(baseName).arg(idx + 1);
+ /// Recursively renames backup files
+ void renameBackupFile(QDir & dir, QString const & baseName, int idx)
+ {
+ QString f1 = QString("%1.%2").arg(baseName).arg(idx);
+ QString f2 = QString("%1.%2").arg(baseName).arg(idx + 1);
- if (dir.exists(f2))
- renameBackupFile(dir, baseName, idx + 1);
+ if (dir.exists(f2))
+ renameBackupFile(dir, baseName, idx + 1);
- dir.rename(f1, f2);
+ dir.rename(f1, f2);
+ }
}
void LoggerWorker::writeToLogFile(LoggerSource const & src, QString const & msg)
//-------------------------------------------------------------------
+void Logger::destroyInstance()
+{
+ if (singleton != nullptr)
+ {
+ delete singleton;
+ singleton = nullptr;
+ }
+}
+
Logger::Logger()
: iLogger()
, mReady(false)
, mFatalMsgHandler(defFatalMsgHandler)
, mConsoleSeverity(iLogger::Fatal)
- , mThread(0)
- , mWorker(0)
{
setObjectName(QString("%1-iLogger").arg(VER_MODULE_NAME_STR));
mDefaultSource = new LoggerSource;
mDefaultSource->name = "common";
- write(Info, QString("%1 created").arg(objectName()), 0, printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__));
+ write(Info, QString("%1 created").arg(objectName()), QString(), printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__));
}
Logger::~Logger()
{
// Disconnect any potential receivers from this object
- disconnect(this, SIGNAL(loggerEvent(Common::iLogger::Severity,QString,QString,QString)), 0, 0);
+ disconnect(this, SIGNAL(loggerEvent(Common::iLogger::Severity,QString,QString,QString)), nullptr, nullptr);
// Destroy the worker thread
if (mWorker) {
- delete mWorker;
+ mWorker.reset();
if (mThread) {
mThread->quit();
mThread->wait();
- delete mThread;
+ mThread.reset();
}
}
- write(Info, QString("%1 destroyed").arg(objectName()), 0, printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__));
+ write(Info, QString("%1 destroyed").arg(objectName()), QString(), printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__));
}
bool Logger::init()
setMaxCount(v.toUInt());
// Destroy the previous worker thread
- if (mWorker) {
- delete mWorker;
- if (mThread) {
- mThread->quit();
- mThread->wait();
- delete mThread;
- }
+ if (mThread) {
+ mThread->quit();
+ mThread->wait();
}
// Create the worker thread
- mWorker = new LoggerWorker;
- mThread = new QThread;
- mWorker->moveToThread(mThread);
+ mWorker.reset(new LoggerWorker);
+ mThread.reset(new QThread);
+ mWorker->moveToThread(mThread.data());
mThread->start(QThread::IdlePriority);
- connect(this, SIGNAL(writeToLogFile(LoggerSource,QString)), mWorker, SLOT(writeToLogFile(LoggerSource,QString)), Qt::QueuedConnection);
+ connect(this, SIGNAL(writeToLogFile(LoggerSource,QString)), mWorker.data(), SLOT(writeToLogFile(LoggerSource,QString)), Qt::QueuedConnection);
mReady = true;
- write(Info, QString("%1 initialized").arg(objectName()), 0, printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__));
+ write(Info, QString("%1 initialized").arg(objectName()), QString(), printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__));
return true;
}
FILE * f = (severity < iLogger::Info) ? stderr : stdout;
// Set text colors
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
switch (severity) {
case iLogger::Info:
- fprintf(f, "\e[32m"); // Green
+ fprintf(f, "\033[32m"); // Green
break;
case iLogger::Warning:
- fprintf(f, "\e[1m"); // Bold
+ fprintf(f, "\033[1m"); // Bold
break;
case iLogger::Error:
- fprintf(f, "\e[31m"); // Red
+ fprintf(f, "\033[31m"); // Red
break;
case iLogger::Fatal:
- fprintf(f, "\e[31m\e[1m"); // Bold Red
+ fprintf(f, "\033[31m\033[1m"); // Bold Red
break;
default:
- fprintf(f, "\e[34m"); // Blue
+ fprintf(f, "\033[34m"); // Blue
break;
}
-#elif defined Q_OS_WIN32
+#elif defined(Q_OS_WIN32)
switch (severity) {
case iLogger::Info:
setColor(FOREGROUND_GREEN);
fprintf(f, "\t(occurred in %s)\n\n", qPrintable(where));
// Reset text colors
-#ifdef Q_OS_LINUX
- fputs("\e[0m", f);
-#elif defined Q_OS_WIN32
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
+ fputs("\033[0m", f);
+#elif defined(Q_OS_WIN32)
setColor(7);
#endif
#ifdef Q_OS_WIN32
char str[4096];
#else
- char * str = 0;
+ char * str = nullptr;
#endif
va_list ap;
* @brief iLogger interface implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011-2012 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
#include <QHash>
#include <QExplicitlySharedDataPointer>
#include <QSharedData>
+#include <QScopedPointer>
class QThread;
namespace Internal {
/// Default fatal error message handler
-void defFatalMsgHandler(QString const & msg, QString const & source, QString const & where);
+[[noreturn]] void defFatalMsgHandler(QString const & msg, QString const & source, QString const & where);
/**
* Logger source.
public:
+ /**
+ * Destroys the iLogger interface instance
+ */
+ static void destroyInstance();
+
Logger();
virtual ~Logger();
virtual void setDefaultSource(QString const & source);
- virtual iLogger::Severity severity(QString const & source = 0);
+ virtual iLogger::Severity severity(QString const & source = QString());
- virtual void setSeverity(iLogger::Severity severity, QString const & source = 0);
+ virtual void setSeverity(iLogger::Severity severity, QString const & source = QString());
- virtual uint maxSize(QString const & source = 0);
+ virtual uint maxSize(QString const & source = QString());
- virtual void setMaxSize(uint maxSize, QString const & source = 0);
+ virtual void setMaxSize(uint maxSize, QString const & source = QString());
- virtual uint maxCount(QString const & source = 0);
+ virtual uint maxCount(QString const & source = QString());
- virtual void setMaxCount(uint maxCount, QString const & source = 0);
+ virtual void setMaxCount(uint maxCount, QString const & source = QString());
virtual iLogger::Severity consoleSeverity() const { return mConsoleSeverity; }
virtual void setConsoleSeverity(iLogger::Severity severity);
- virtual void write(Severity severity, QString const & msg, QString const & source = 0, QString const & where = 0);
+ virtual void write(Severity severity, QString const & msg, QString const & source = QString(), QString const & where = QString());
virtual QString printf(char const * const fmt, ...) const;
QHash<QString, QExplicitlySharedDataPointer<LoggerSource> > mSources;
/// Worker thread
- QThread * mThread;
+ QScopedPointer<QThread> mThread;
/// Worker object
- LoggerWorker * mWorker;
+ QScopedPointer<LoggerWorker> mWorker;
private: // Methods
* @brief Implementation of the iProp interface
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
using namespace eVaf::Common;
+namespace
+{
+ static Internal::Prop * singleton = nullptr;
+}
+
iProp * iProp::instance()
{
- static Internal::Prop singleton;
- return singleton._interface();
+ if (nullptr == singleton)
+ {
+ singleton = new Internal::Prop;
+ }
+ return singleton->_interface();
}
using namespace eVaf::Common::Internal;
+void Prop::destroyInstance()
+{
+ if (nullptr != singleton)
+ {
+ delete singleton;
+ singleton = nullptr;
+ }
+}
+
Prop::Prop()
: iProp()
- , mPersistentProps(0)
{
setObjectName(QString("%1.iProp").arg(VER_MODULE_NAME_STR));
// Register the iProp interface
iRegistry::instance()->registerInterface("iProp", this);
+
+ EVAF_INFO("%s-Prop created", VER_MODULE_NAME_STR);
}
Prop::~Prop()
{
done();
+ EVAF_INFO("%s-Prop destroyed", VER_MODULE_NAME_STR);
}
iProp * Prop::_interface() const
isProp = true;
}
else if (isProp && xml.name() == "property") {
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
if (isTrue(xml.attributes().value("windowsonly").toString()))
continue;
#endif
}
// Initialize persistent properties
- if (mPersistentProps)
- delete mPersistentProps;
- mPersistentProps = new QSettings(QString("%1/.%2.dat").arg(iApp::instance()->dataRootDir()).arg(iApp::instance()->name()), QSettings::IniFormat);
+ mPersistentProps.reset(new QSettings(QString("%1/.%2.dat")
+ .arg(iApp::instance()->dataRootDir())
+ .arg(iApp::instance()->name()),
+ QSettings::IniFormat));
QStringList keys = mPersistentProps->allKeys();
for (int i = 0; i < keys.size(); ++i) {
QString key = keys.at(i);
void Prop::done()
{
- if (mPersistentProps) {
- delete mPersistentProps;
- mPersistentProps = 0;
- }
+ mPersistentProps.reset();
}
QVariant Prop::getValue(QString const & name, QVariant const & defaultValue) const
* @brief Implementation of the iProp interface
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
#include "iprop.h"
#include <QHash>
+#include <QScopedPointer>
class QSettings;
public:
+ /**
+ * Destroys the iProp interface instance
+ */
+ static void destroyInstance();
+
Prop();
virtual ~Prop();
QHash<QString, QVariant> mProps;
/// Persistent property values
- QSettings * mPersistentProps;
+ QScopedPointer<QSettings> mPersistentProps;
};
public:
- Panel(QWidget * parent = 0, Qt::WindowFlags f = 0);
+ Panel(QWidget * parent = nullptr, Qt::WindowFlags f = 0);
virtual ~Panel();
namespace Internal {
// Plugin manager interface implementation
- static eVaf::Plugins::PluginManager * mPluginManager = 0;
+ static eVaf::Plugins::PluginManager * mPluginManager = nullptr;
} // namespace eVaf::Plugins::Internal
} // namespace eVaf::Plugins
PluginManager::PluginManager()
: QObject()
+ , d(new Internal::PluginManagerPrivate)
{
setObjectName(QString("%1-PluginManager").arg(VER_MODULE_NAME_STR));
Internal::mPluginManager = this;
- d = new Internal::PluginManagerPrivate;
-
EVAF_INFO("%s created", qPrintable(objectName()));
}
PluginManager::~PluginManager()
{
- delete d;
+ d.reset();
- Internal::mPluginManager = 0;
+ Internal::mPluginManager = nullptr;
EVAF_INFO("%s destroyed", qPrintable(objectName()));
}
if (!isPlugins && !isQtPlugins) {
if (xml.name() == "plugins") {
// Check for windows and linux only sections
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
if (Common::isTrue(xml.attributes().value("windowsonly").toString()))
continue;
#endif
else if (xml.name() == "qtplugins") {
// Check for windows and linux only sections
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
if (Common::isTrue(xml.attributes().value("windowsonly").toString()))
continue;
#endif
// An individual plugin?
else if (isPlugins && xml.name() == "plugin") {
// Check for windows and linux only plugins
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
if (Common::isTrue(xml.attributes().value("windowsonly").toString())) {
EVAF_INFO("Plugin '%s' is for Windows only", qPrintable(xml.attributes().value("name").toString()));
continue;
// An individual Qt plugin?
else if (isQtPlugins && xml.name() == "plugin") {
// Check for windows and linux only plugins
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
if (Common::isTrue(xml.attributes().value("windowsonly").toString())) {
EVAF_INFO("Qt plugin '%s' is for Windows only", qPrintable(xml.attributes().value("name").toString()));
continue;
if (mModules.at(i)->name() == name)
return mModules.at(i).data();
}
- return 0;
+ return nullptr;
}
Module::Module(QString const & name)
: QSharedData()
, mName(name)
- , mLoader(0)
- , mRoot(0)
- , mPlugin(0)
- , mPluginFactory(0)
+ , mRoot(nullptr)
+ , mPlugin(nullptr)
+ , mPluginFactory(nullptr)
{}
Module::~Module()
{
if (mLoader) {
mLoader->unload();
- delete mLoader;
+ mLoader.reset();
}
}
QObject * root = p->instance();
// Does the module implement the iPluginFactory interface?
- if ((mPluginFactory = qobject_cast<iPluginFactory *>(root)) == 0) {
+ if ((mPluginFactory = qobject_cast<iPluginFactory *>(root)) == nullptr) {
// If not, then it has to implement the iPlugin interface
- if (qobject_cast<iPlugin *>(root) == 0) {
+ if (qobject_cast<iPlugin *>(root) == nullptr) {
EVAF_FATAL_ERROR("Module '%s' is not a valid eVaf module", qPrintable(mName));
return false;
}
}
mRoot = root;
- mLoader = p.take();
+ mLoader.reset(p.take());
return true;
}
void Module::unload()
{
- mRoot = 0;
- mPluginFactory = 0;
- mPlugin = 0;
+ mRoot = nullptr;
+ mPluginFactory = nullptr;
+ mPlugin = nullptr;
if (mLoader) {
mLoader->unload();
- delete mLoader;
- mLoader = 0;
+ mLoader.reset();
}
}
// If the module is not loaded, load it now
if (!mLoader) {
if (!load())
- return 0;
+ return nullptr;
}
- iPlugin * i = 0;
+ iPlugin * i = nullptr;
// Does the module implement the iPluginFactory interface?
if (mPluginFactory) {
// Use the iPluginFactory interface to create the requested interface
i = qobject_cast<iPlugin *>(mPluginFactory->create(name));
- if (i == 0) {
+ if (i == nullptr) {
EVAF_FATAL_ERROR("Module '%s' failed to create the iPlugin interface with name '%s'", qPrintable(mName), qPrintable(name));
- return 0;
+ return nullptr;
}
}
if (mPlugin) {
EVAF_FATAL_ERROR("Module '%s' can implement only one iPlugin interface and one with the name '%s' is already created",
qPrintable(mName), qPrintable(mPlugin->objectName()));
- return 0;
+ return nullptr;
}
i = qobject_cast<iPlugin *>(mRoot);
- if (i == 0) {
+ if (i == nullptr) {
EVAF_FATAL_ERROR("Module '%s' does not implement the iPlugin interface", qPrintable(mName));
- return 0;
+ return nullptr;
}
mPlugin = i;
, mModule(module)
, mName(name)
, mArgs(args)
- , mPlugin(0)
+ , mPlugin(nullptr)
{}
Plugin::~Plugin()
mPlugin = mModule->create(mName);
if (mPlugin && !mPlugin->objectName().isEmpty())
mName = mPlugin->objectName();
- return mPlugin != 0;
+ return mPlugin != nullptr;
}
void Plugin::unload()
{
- mPlugin = 0;
+ mPlugin = nullptr;
}
bool Plugin::init()
* @file Plugins/pluginmanager.h
* @brief Manager for loadable modules (plugins)
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
#include <QObject>
#include <QString>
+#include <QScopedPointer>
namespace eVaf {
return "lib" + name + ".so";
#elif defined Q_OS_CYGWIN
return "cyg" + name + ".dll";
+#elif defined Q_OS_MACOS
+ return "lib" + name + ".dylib";
#else
return name;
#endif
private:
- Internal::PluginManagerPrivate * d;
+ QScopedPointer<Internal::PluginManagerPrivate> d;
};
* @file Plugins/pluginmanager_p.h
* @brief Private implementation of the plugin manager
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
#include <QObject>
#include <QSharedData>
#include <QExplicitlySharedDataPointer>
+#include <QScopedPointer>
#include <QPluginLoader>
namespace eVaf {
QString mName;
/// Plugin loader
- QPluginLoader * mLoader;
+ QScopedPointer<QPluginLoader> mLoader;
/// Plugin's root component
QObject * mRoot;
#include <QtCore>
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
# include <signal.h>
#endif
namespace CLI {
namespace Internal {
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
/**
* Signal handler on Linux
bool eVaf::CLI::Internal::installExitHandler()
{
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = signalHandler;
* If the critical error message is shown, then the user has an option to ignore the error. In this
* case the application is not terminated.
*/
-static void fatalMsgHandler(QString const & msg, QString const & source, QString const & where)
+[[noreturn]] static void fatalMsgHandler(QString const & msg, QString const & source, QString const & where)
{
-#ifdef Q_OS_LINUX
- abort();
-#else
+ Q_UNUSED(msg);
+ Q_UNUSED(source);
+ Q_UNUSED(where);
exit(1);
-#endif
}
} // namespace eVaf::CLI::Internal
#include <QtCore>
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
# include <signal.h>
#endif
namespace GUI {
namespace Internal {
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
/**
* Signal handler on Linux
bool eVaf::GUI::Internal::installExitHandler()
{
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = signalHandler;
*/
static void fatalMsgHandler(QString const & msg, QString const & source, QString const & where)
{
+ Q_UNUSED(source);
+
// Show the message on the screen
if (BeVerbose) {
if (FatalErr::message(QObject::tr("Fatal Error"),
QObject::tr("%1\n\nOccurred in '%2'")
.arg(msg)
.arg(where),
- 0) == FatalErr::Ignore)
+ nullptr) == FatalErr::Ignore)
return;
}
-#ifdef Q_OS_LINUX
- abort();
-#else
exit(1);
-#endif
}
} // namespace eVaf::GUI::Internal
if (!Internal::installExitHandler())
return 1;
- // Plugin manager
- Plugins::PluginManager pluginManager;
+ int rval = 0;
+ {
+ // Plugin manager
+ Plugins::PluginManager pluginManager;
- // The main run loop
- bool quit = false;
- int rval;
- while (!quit) {
+ // The main run loop
+ bool quit = false;
+ while (!quit) {
- EVAF_INFO("%s is starting up", VER_MODULE_NAME_STR);
+ EVAF_INFO("%s is starting up", VER_MODULE_NAME_STR);
- // Initialize the common library
- if (!Common::init())
- return 1;
+ // Initialize the common library
+ if (!Common::init())
+ return 1;
- // Initialize the plugin manager and load plugins
- if (!pluginManager.init())
- return 1;
+ // Initialize the plugin manager and load plugins
+ if (!pluginManager.init())
+ return 1;
- // Run the application
- EVAF_INFO("Running %s", VER_MODULE_NAME_STR);
- rval = Common::iApp::instance()->exec();
+ // Run the application
+ EVAF_INFO("Running %s", VER_MODULE_NAME_STR);
+ rval = Common::iApp::instance()->exec();
- quit = rval != Common::iApp::RC_Restart;
+ quit = rval != Common::iApp::RC_Restart;
- EVAF_INFO("%s is %s", VER_MODULE_NAME_STR, quit ? "exiting" : "restarting");
+ EVAF_INFO("%s is %s", VER_MODULE_NAME_STR, quit ? "exiting" : "restarting");
- // Unload plugins and finalize the plugin manager
- pluginManager.done();
+ // Unload plugins and finalize the plugin manager
+ pluginManager.done();
+
+ // Finalize the common library
+ Common::done();
+ }
}
EVAF_INFO("%s exit with code %d", VER_MODULE_NAME_STR, rval);
* @brief SDI module's factory class
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
Factory::Factory()
: Plugins::iPluginFactory()
- , mPlugin(0)
{
setObjectName(QString("%1-Factory").arg(VER_MODULE_NAME_STR));
Factory::~Factory()
{
- if (mPlugin)
- delete mPlugin;
+ mPlugin.reset();
EVAF_INFO("%s destroyed", qPrintable(objectName()));
}
{
Q_UNUSED(name);
- if (mPlugin == 0)
- mPlugin = new Internal::SdiWindowPlugin;
- return mPlugin;
+ if (!mPlugin)
+ mPlugin.reset(new Internal::SdiWindowPlugin);
+ return mPlugin.data();
}
* @brief SDI module's factory class
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
#include "version.h"
#include <Plugins/iPluginFactory>
+#include <QScopedPointer>
namespace eVaf {
private: // Members
- Internal::SdiWindowPlugin * mPlugin;
+ QScopedPointer<Internal::SdiWindowPlugin> mPlugin;
};
* @brief SdiWindow module's implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
namespace SdiWindow {
namespace Internal {
/// iSdiWindow interface instance singleton
- static iSdiWindow * mSdiWindow = 0;
+ static iSdiWindow * mSdiWindow = nullptr;
} // namespace eVaf::SdiWindow::Internal
} // namespace eVaf::SdiWindow
} // namespace eVaf
SdiWindow::Internal::MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags flags)
: QWidget(parent, flags)
, mReady(false)
- , mMainPanel(0)
+ , mMainPanel(nullptr)
{
setObjectName(QString("%1-%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__));
SdiWindow::Internal::MainWindow::~MainWindow()
{
- mSdiWindow = 0;
+ mSdiWindow = nullptr;
// Save geometry
saveSettings();
mPanels.clear();
mMinimizedPanels.clear();
mPanelNames.clear();
- mMainPanel = 0;
+ mMainPanel = nullptr;
mMainPanelName.clear();
EVAF_INFO("%s finalized", qPrintable(objectName()));
QHash<QString, Gui::Panel *>::const_iterator it = mPanelNames.constFind(name);
if (it != mPanelNames.constEnd())
return it.value();
- return 0;
+ return nullptr;
}
bool SdiWindow::Internal::MainWindow::showPanel(QString const & name)
// If it was the main panel, set the main panel to NULL
if (mMainPanel == obj) {
- mMainPanel = 0;
+ mMainPanel = nullptr;
}
}
SdiWindow::Internal::SdiWindowPlugin::SdiWindowPlugin()
: Plugins::iPlugin()
+ , mWindow(new MainWindow)
{
setObjectName(VER_MODULE_NAME_STR);
- mWindow = new MainWindow;
-
EVAF_INFO("%s created", qPrintable(objectName()));
}
SdiWindow::Internal::SdiWindowPlugin::~SdiWindowPlugin()
{
- delete mWindow;
+ mWindow.reset();
EVAF_INFO("%s destroyed", qPrintable(objectName()));
}
* @brief SdiWindow module's implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
#include <QList>
#include <QVector>
#include <QHash>
+#include <QScopedPointer>
class QVBoxLayout;
public:
- MainWindow(QWidget * parent = 0, Qt::WindowFlags flags = 0);
+ MainWindow(QWidget * parent = nullptr, Qt::WindowFlags flags = 0);
virtual ~MainWindow();
/// Panel destroyed signal. We need to remove the panel from all the
/// lists.
- void panelDestroyed(QObject * obj = 0);
+ void panelDestroyed(QObject * obj = nullptr);
};
virtual void done();
- virtual bool isReady() const { return mWindow != 0 && mWindow->isReady(); }
+ virtual bool isReady() const { return mWindow != nullptr && mWindow->isReady(); }
private:
/// iSdiWindow interface implementation
- MainWindow * mWindow;
+ QScopedPointer<MainWindow> mWindow;
};
} // namespace eVaf::SdiWindow::Internal