From 9cf8a800fdca65977c426968ce9be1c319940bdb Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 26 Mar 2013 00:19:12 +0000 Subject: [PATCH 01/12] initial doxygen comments and minor cleanup --- src/blackcore/simulator.cpp | 2 +- src/blackcore/simulator.h | 171 +++++++++++++++++++++++------------- 2 files changed, 113 insertions(+), 60 deletions(-) diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index 20f76662c..b4e68ebd5 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -43,7 +43,7 @@ namespace BlackCore { ISimulator *result = NULL; getDriverVersionMajor driverVersionMajor; - getDriverVersionMinor driverVersionMinor; + //getDriverVersionMinor driverVersionMinor; createISimulatorInstance createDriver; switch (sim) diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index f74b4791d..b1db49fff 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -6,17 +6,21 @@ #ifndef SIMULATOR_H #define SIMULATOR_H -#include -#include - #include "blackcore/sim_callbacks.h" #include "blackcore/vector_geo.h" #include "blackcore/vector_3d.h" +#include +#include + #define SHARED_LIBRARY_NAME_FS9 "bb_driver_fs9" #define SHARED_LIBRARY_NAME_FSX "bb_driver_fsx" #define SHARED_LIBRARY_NAME_XPLANE "bb_driver_xplane" +/*! + * \file Simulator driver interface. + */ + namespace BlackMisc { class IContext; @@ -25,144 +29,193 @@ namespace BlackMisc { namespace BlackCore { + /*! + * A struct to hold data about an aircraft model and repaint. + */ class CPlaneModel { public: - QString name; - QString typeCode; - QString airlineCode; + QString name; //!< full name of the aircraft model, arbitrary string (hopefully unique) + QString typeCode; //!< ICAO aircraft type code + QString airlineCode; //!< ICAO air operator code }; + /*! + * A struct for passing around the physical state of an aircraft. + */ class CPhysicalState { public: + //! Constructor, initialize to zero. CPhysicalState() : headingDegrees(0), pitchDegrees(0), bankDegrees(0), groundSpeedKnots(0) {} - CVectorGeo position; - float headingDegrees; - float pitchDegrees; - float bankDegrees; - float groundSpeedKnots; - CVector3D trueSpeedMetersPerSec; + CVectorGeo position; //!< geographical position + float headingDegrees; //!< heading in degrees + float pitchDegrees; //!< pitch in degrees + float bankDegrees; //!< bank in degrees + float groundSpeedKnots; //!< ground speed in knots + CVector3D trueSpeedMetersPerSec; //!< needed by FSX }; + /*! + * A struct for passing around the avionics state of an aircraft. + */ class CAvionicsState { + //! Constructor, initialize to zero. CAvionicsState() : squawkCode(0), squawkModeC(false), squawkIdent(false), com1FreqHz(0), com2FreqHz(0) {} - qint16 squawkCode; - bool squawkModeC; - bool squawkIdent; - qint32 com1FreqHz; - qint32 com2FreqHz; + qint16 squawkCode; //!< decimal squawk code + bool squawkModeC; //!< true if squawking mode C + bool squawkIdent; //!< true if squawking ident + qint32 com1FreqHz; //!< COM1 radio frequency in Hz + qint32 com2FreqHz; //!< COM2 radio frequency in Hz }; + /*! + * A struct for passing around the animation state of an aircraft. + */ class CAnimationState { public: + //! Constructor, initialize to zero. CAnimationState() : gearPercent(0), flapsPercent(0), landingLights(false), taxiLights(false), navLights(false), strobeLights(false), beaconLights(false) {} - qint8 gearPercent; - qint8 flapsPercent; - bool landingLights; - bool taxiLights; - bool navLights; - bool strobeLights; - bool beaconLights; + qint8 gearPercent; //!< 0 = retracted, 100 = extended + qint8 flapsPercent; //!< 0 = ratracted, 100 = extended + bool landingLights; //!< true if landing lights on + bool taxiLights; //!< true if taxi lights on + bool navLights; //!< true if nav lights on + bool strobeLights; //!< true if strobe lights on + bool beaconLights; //!< true if beacon lights on }; + //! A callback that is called when the simulator is started. typedef std::tr1::function cbSimStarted; - typedef std::tr1::function cbChangedAvionicsState; - typedef std::tr1::function cbChangedAnimationState; - typedef std::tr1::function cbChangedModel; - typedef std::tr1::function cbSendTextMessage; + //! A callback that is called when the user's plane changes its avionics state. + typedef std::tr1::function cbChangedAvionicsState; + + //! A callback that is called when the user's plane changes its animation state. + typedef std::tr1::function cbChangedAnimationState; + + //! A callback that is called when the user's plane changes its model. + typedef std::tr1::function cbChangedModel; + + /*! + * The interface that is implemented by each simulator driver. + * + * Simulator drivers are responsible for communicating with the simulator on the user's + * computer and keeping it in sync with the client. + */ class ISimulator { public: - - /// Version of the driver interface. To increment when the interface change. + // Version of the driver interface. To increment when the interface change. static const quint32 InterfaceVersionMajor; static const quint32 InterfaceVersionMinor; + //! Enumeration to describe which simulator is desired. enum ESimulator { - FS9 = 0, - FSX, - XPLANE, + FS9 = 0, //!< Microsoft Flight Simulator 9 + FSX, //!< Microsoft Flight Simulator 10 + XPLANE, //!< X-Plane }; + //! Constructor. ISimulator() {} + + //! Destructor. virtual ~ISimulator() {} + //! Provide the driver with a pointer to the global context. virtual void setLibraryContext(BlackMisc::IContext *context); + //! Factory method. static ISimulator *createDriver(ESimulator sim); - //////////////////////////////// - // Global section - //////////////////////////////// - + //! Initialize the driver. virtual int init() = 0; + //! Connect to the simulator. virtual int connect() = 0; - // Callback when the Simulation starts + //! Provide a callback to be called when the simulation starts. virtual void setcbSimStarted(const cbSimStarted &func); + //! Query whether the driver is connected to the simulator. virtual bool isConnected() = 0; + //! If there has been an error, return the associated message. virtual QString getLastErrorMessage() = 0; - //////////////////////////////// - // User plane section - //////////////////////////////// - - // Callback avionics state + //! Provide a callback to be called when the user plane changes avionics state. virtual void setcbChangedAvionicsState(const cbChangedAvionicsState &func); - // Callback animation state + //! Provide a callback to be called when the user plane changes animation state. virtual void setcbChangedAnimationState(const cbChangedAnimationState &func); - // Callback, when the Aircraft is set or gets changed + //! Provide a callback to be called when the user plane changes model. virtual void setcbChangedModel(const cbChangedModel &func); - // Not const because it may need to mutate state in order to communicate with the sim + //! Returns true if the user plane is in contact with the ground. virtual bool isOnGround() = 0; - // This might block - use QtConcurrent::run if that is a problem + /*! + * Returns the physical state of the user plane. + * \warning This might block - use QtConcurrent::run if that is a problem. + */ virtual CPhysicalState getPhysicalState() = 0; - //////////////////////////////// - // Remote plane section - //////////////////////////////// - - // This might block - use QtConcurrent::run if that is a problem + /*! + * Adds a plane to the simulator traffic and returns its handle. + * \warning This might block - use QtConcurrent::run if that is a problem + */ virtual qint32 addPlane(const QString &callsign) = 0; + /*! + * Remove a plane from the simulator traffic. + * \param planeID a handle that was returned by addPlane(). + */ virtual bool removePlane(const qint32 planeID) = 0; + /*! + * Set the model of an aircraft in the simulator traffic. + * \param planeID a handle that was returned by addPlane(). + */ virtual void setModel(const qint32 planeID, const CPlaneModel &model) = 0; + /*! + * Set the physical state of an aircraft in the simulator traffic. + * \param planeID a handle that was returned by addPlane(). + */ virtual bool setPhysicalState(const qint32 planeID, const CPhysicalState &state) = 0; + /*! + * Set the animation state of an aircraft in the simulator traffic. + * \param planeID a handle that was returned by addPlane(). + */ virtual bool setAnimationState(const qint32 planeID, const CAnimationState &state) = 0; - // Calls the supplied visitor function once for every model available in the simulator. + //! Calls the supplied visitor function once for every model available in the simulator. virtual void visitAllModels(const std::tr1::function &visitor) = 0; - // Fills container with all models. Works for any container that supports push_back. + /*! + * Fills container with all models. + * Class T must be a container of CPlaneModel objects and must support push_back. + */ template void getAllModels(T &container) { visitAllModels(std::tr1::bind(T::push_back, container)); } protected: - BlackMisc::IContext *m_libraryContext; + BlackMisc::IContext *m_libraryContext; //!< The global context. - cbSimStarted m_cbSimStarted; - cbChangedAvionicsState m_cbChangedAvionicsState; - cbChangedAnimationState m_cbChangedAnimationState; - cbChangedModel m_cbChangedModel; + cbSimStarted m_cbSimStarted; //!< Callback to call when the sim starts. + cbChangedAvionicsState m_cbChangedAvionicsState; //!< Callback to call when the user plane changes avionics state. + cbChangedAnimationState m_cbChangedAnimationState; //!< Callback to call when the user plane changes animation state. + cbChangedModel m_cbChangedModel; //!< Callback to call when the user plane changes model. }; } //! namespace BlackCore From 585c4db5784776ef99100e15affefe8ee06e5cd2 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sat, 30 Mar 2013 17:41:04 +0100 Subject: [PATCH 02/12] #12 Fixing linux build --- .../CMakeLists.txt | 0 .../{Geodetic2Ecef => geodetic2ecef}/main.cpp | 2 -- .../sample_geodetic2ecef.pro | 0 samples/interpolator/main.cpp | 2 -- samples/{Logging => logging}/CMakeLists.txt | 0 samples/{Logging => logging}/main.cpp | 0 .../{Logging => logging}/sample_logging.pro | 0 src/blackcore/blackcore.pro | 4 +++ src/blackcore/constants.h | 2 ++ src/blackcore/fsd_messages.h | 4 +-- src/blackcore/mathematics.cpp | 2 +- src/blackcore/mathematics.h | 2 ++ src/blackcore/simulator.h | 27 +++++++++++++++++++ src/blackd/blackd.pro | 4 --- src/blackmisc/com_handler.cpp | 6 ++--- src/blackmisc/config_manager.cpp | 4 +-- src/blackmisc/config_manager.h | 4 +-- src/blackmisc/context.h | 10 +++---- src/blackmisc/debug.cpp | 8 +++--- src/blackmisc/debug.h | 2 +- src/blackmisc/display.cpp | 6 ++++- src/blackmisc/display.h | 2 +- src/blackmisc/log.cpp | 2 +- src/blackmisc/message.cpp | 2 +- src/blackmisc/message.h | 4 +-- src/blackmisc/type_info.cpp | 2 +- src/blackmisc/type_info.h | 4 +-- 27 files changed, 68 insertions(+), 37 deletions(-) rename samples/{Geodetic2Ecef => geodetic2ecef}/CMakeLists.txt (100%) rename samples/{Geodetic2Ecef => geodetic2ecef}/main.cpp (96%) rename samples/{Geodetic2Ecef => geodetic2ecef}/sample_geodetic2ecef.pro (100%) rename samples/{Logging => logging}/CMakeLists.txt (100%) rename samples/{Logging => logging}/main.cpp (100%) rename samples/{Logging => logging}/sample_logging.pro (100%) diff --git a/samples/Geodetic2Ecef/CMakeLists.txt b/samples/geodetic2ecef/CMakeLists.txt similarity index 100% rename from samples/Geodetic2Ecef/CMakeLists.txt rename to samples/geodetic2ecef/CMakeLists.txt diff --git a/samples/Geodetic2Ecef/main.cpp b/samples/geodetic2ecef/main.cpp similarity index 96% rename from samples/Geodetic2Ecef/main.cpp rename to samples/geodetic2ecef/main.cpp index 21fec1a5e..a9e3e7ef3 100644 --- a/samples/Geodetic2Ecef/main.cpp +++ b/samples/geodetic2ecef/main.cpp @@ -2,8 +2,6 @@ #include #include "blackmisc/debug.h" #include -#include -#include #include "blackcore/ecef.h" #include "blackcore/vector_geo.h" diff --git a/samples/Geodetic2Ecef/sample_geodetic2ecef.pro b/samples/geodetic2ecef/sample_geodetic2ecef.pro similarity index 100% rename from samples/Geodetic2Ecef/sample_geodetic2ecef.pro rename to samples/geodetic2ecef/sample_geodetic2ecef.pro diff --git a/samples/interpolator/main.cpp b/samples/interpolator/main.cpp index c6cc7724a..5631edae9 100644 --- a/samples/interpolator/main.cpp +++ b/samples/interpolator/main.cpp @@ -1,8 +1,6 @@ #include #include -#include - #include #include "blackcore/matrix_3d.h" diff --git a/samples/Logging/CMakeLists.txt b/samples/logging/CMakeLists.txt similarity index 100% rename from samples/Logging/CMakeLists.txt rename to samples/logging/CMakeLists.txt diff --git a/samples/Logging/main.cpp b/samples/logging/main.cpp similarity index 100% rename from samples/Logging/main.cpp rename to samples/logging/main.cpp diff --git a/samples/Logging/sample_logging.pro b/samples/logging/sample_logging.pro similarity index 100% rename from samples/Logging/sample_logging.pro rename to samples/logging/sample_logging.pro diff --git a/src/blackcore/blackcore.pro b/src/blackcore/blackcore.pro index 22f89c23a..3986d725c 100644 --- a/src/blackcore/blackcore.pro +++ b/src/blackcore/blackcore.pro @@ -8,6 +8,10 @@ INCLUDEPATH += .. DEPENDPATH += . .. +linux-g++* { + QMAKE_CXXFLAGS += -std=c++0x +} + #PRECOMPILED_HEADER = stdpch.h precompile_header:!isEmpty(PRECOMPILED_HEADER) { diff --git a/src/blackcore/constants.h b/src/blackcore/constants.h index b307e57f1..fc1ef6636 100644 --- a/src/blackcore/constants.h +++ b/src/blackcore/constants.h @@ -8,6 +8,8 @@ #include "mathematics.h" +#include + namespace BlackCore { namespace Constants diff --git a/src/blackcore/fsd_messages.h b/src/blackcore/fsd_messages.h index 8711b98fd..d60ad3f6a 100644 --- a/src/blackcore/fsd_messages.h +++ b/src/blackcore/fsd_messages.h @@ -21,7 +21,7 @@ namespace FSD class FSD_MSG : public BlackMisc::IMessage { public: - FSD_MSG(QString& id) : IMessage(id) + FSD_MSG(QString id) : IMessage(id) { } @@ -40,7 +40,7 @@ namespace FSD class FSD_MSG_AddPilot : public FSD_MSG { public: - FSD_MSG_AddPilot() : FSD_MSG(QString("#AP")), m_revision(VATSIM_PROTOCOL_REV), + FSD_MSG_AddPilot() : FSD_MSG("#AP"), m_revision(VATSIM_PROTOCOL_REV), m_rating(1) { } diff --git a/src/blackcore/mathematics.cpp b/src/blackcore/mathematics.cpp index 7005e3a85..49f790400 100644 --- a/src/blackcore/mathematics.cpp +++ b/src/blackcore/mathematics.cpp @@ -25,7 +25,7 @@ double CMath::hypot(double x, double y) double CMath::cubicRootReal(const double x) { double result; - result = std::pow(std::abs(x), (double)1/3); + result = pow(abs(x), (double)1/3); return x < 0 ? -result : result; } diff --git a/src/blackcore/mathematics.h b/src/blackcore/mathematics.h index e24db691d..db0ec5a3d 100644 --- a/src/blackcore/mathematics.h +++ b/src/blackcore/mathematics.h @@ -6,6 +6,8 @@ #ifndef MATH_H #define MATH_H +#include + namespace BlackCore { diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index b1db49fff..8215e0f92 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -92,6 +92,8 @@ namespace BlackCore { bool beaconLights; //!< true if beacon lights on }; +#ifdef Q_OS_WIN + //! A callback that is called when the simulator is started. typedef std::tr1::function cbSimStarted; @@ -104,6 +106,20 @@ namespace BlackCore { //! A callback that is called when the user's plane changes its model. typedef std::tr1::function cbChangedModel; +#else + //! A callback that is called when the simulator is started. + typedef std::function cbSimStarted; + + //! A callback that is called when the user's plane changes its avionics state. + typedef std::function cbChangedAvionicsState; + + //! A callback that is called when the user's plane changes its animation state. + typedef std::function cbChangedAnimationState; + + //! A callback that is called when the user's plane changes its model. + typedef std::function cbChangedModel; +#endif + /*! * The interface that is implemented by each simulator driver. * @@ -200,14 +216,25 @@ namespace BlackCore { virtual bool setAnimationState(const qint32 planeID, const CAnimationState &state) = 0; //! Calls the supplied visitor function once for every model available in the simulator. + +#ifdef Q_OS_WIN virtual void visitAllModels(const std::tr1::function &visitor) = 0; +#else + virtual void visitAllModels(const std::function &visitor) = 0; +#endif /*! * Fills container with all models. * Class T must be a container of CPlaneModel objects and must support push_back. */ +#ifdef Q_OS_WIN template void getAllModels(T &container) { visitAllModels(std::tr1::bind(T::push_back, container)); } +#else + template + void getAllModels(T &container) { visitAllModels(std::bind(T::push_back, container)); } +#endif + protected: BlackMisc::IContext *m_libraryContext; //!< The global context. diff --git a/src/blackd/blackd.pro b/src/blackd/blackd.pro index be3079e58..f49b78453 100644 --- a/src/blackd/blackd.pro +++ b/src/blackd/blackd.pro @@ -2,10 +2,6 @@ QT += core gui xml svg network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib - TARGET = blackd TEMPLATE = app diff --git a/src/blackmisc/com_handler.cpp b/src/blackmisc/com_handler.cpp index f6d31e6b1..2f582ae13 100644 --- a/src/blackmisc/com_handler.cpp +++ b/src/blackmisc/com_handler.cpp @@ -58,7 +58,7 @@ namespace BlackMisc do { qint32 sync = 0; - stream >> (qint32)sync; + stream >> sync; if (sync == Sync_Marker) found_sync = true; } @@ -78,7 +78,7 @@ namespace BlackMisc ///////////////////////////////////////////////// qint32 message_length = 0; - stream >> (qint32)message_length; + stream >> message_length; total_length += (int)sizeof(qint32); // Length total_length += message_length; // Data @@ -108,7 +108,7 @@ namespace BlackMisc quint16 crc_calc = qChecksum (data.constData(), data.size()); quint16 crc_recv = 0; - stream >> (quint16)crc_recv; + stream >> crc_recv; total_length += (int)sizeof(quint16); diff --git a/src/blackmisc/config_manager.cpp b/src/blackmisc/config_manager.cpp index 52eff6f37..57cc5da53 100644 --- a/src/blackmisc/config_manager.cpp +++ b/src/blackmisc/config_manager.cpp @@ -14,7 +14,7 @@ namespace BlackMisc { } - void CConfigManager::setConfigPath(QString &path) + void CConfigManager::setConfigPath(QString path) { m_config_path = QDir(path).absolutePath(); @@ -91,4 +91,4 @@ namespace BlackMisc } } -} // namespace BlackMisc \ No newline at end of file +} // namespace BlackMisc diff --git a/src/blackmisc/config_manager.h b/src/blackmisc/config_manager.h index 737cca67a..6bac64ae2 100644 --- a/src/blackmisc/config_manager.h +++ b/src/blackmisc/config_manager.h @@ -36,7 +36,7 @@ namespace BlackMisc /*! \param path absolute pathname */ - void setConfigPath(QString &path); + void setConfigPath(QString path); int readConfig(bool forceReload = false); @@ -56,4 +56,4 @@ namespace BlackMisc }; } // namespace BlackLib -#endif // CONFIGMANAGER_H \ No newline at end of file +#endif // CONFIGMANAGER_H diff --git a/src/blackmisc/context.h b/src/blackmisc/context.h index 8a3ffe2f9..a8ddc73ff 100644 --- a/src/blackmisc/context.h +++ b/src/blackmisc/context.h @@ -49,33 +49,33 @@ namespace BlackMisc \param singletonName a reference to the singletones name. \return Returns a pointer to the singleton object. */ - virtual void *singletonPointer(const QString &singletonName) = NULL; + virtual void *singletonPointer(const QString &singletonName) = 0; //! Pure virtual method sets the singletone pointer, given by its name. /*! \param singletonName a reference to the singletones name. \param object a pointer to the singletone object. */ - virtual void setSingletonPointer(const QString &singletonName, void *object) = NULL; + virtual void setSingletonPointer(const QString &singletonName, void *object) = 0; //! Deallocates the object and removes the singletone pointer from the context map. /*! \param singletonName a reference to the singletones name. \param object a pointer to the singletone object. */ - virtual void releaseSingletonPointer(const QString &singletonName, void *object) = NULL; + virtual void releaseSingletonPointer(const QString &singletonName, void *object) = 0; //! Pure virtual method returns the pointer to debug object /*! \return Pointer to CDebug object */ - virtual CDebug *getDebug() = NULL; + virtual CDebug *getDebug() = 0; //! Pure virtual function to set the global error log object /*! \param Pointer to CDebug object */ - virtual void setDebug(CDebug *debug) = NULL; + virtual void setDebug(CDebug *debug) = 0; protected: //! Method to register the context. diff --git a/src/blackmisc/debug.cpp b/src/blackmisc/debug.cpp index c07b4f66a..a58108b02 100644 --- a/src/blackmisc/debug.cpp +++ b/src/blackmisc/debug.cpp @@ -14,7 +14,7 @@ namespace BlackMisc } - void CDebug::create (QString &logPath, bool logInFile, bool eraseLastLog) + void CDebug::create (const char *logPath, bool logInFile, bool eraseLastLog) { if (!m_isInitialized) { @@ -28,7 +28,7 @@ namespace BlackMisc if (logInFile) { - QDir fileinfo(m_logPath); + QDir fileinfo(m_logPath); QString fn; if ( !m_logPath.isEmpty() ) { @@ -76,8 +76,8 @@ namespace BlackMisc m_assertLog->setLogInformation (line, file, function); BlackMisc::CLogMessage::getAssertMsgObj() << "ASSERT FAILED! STOP!"; - #ifdef BB_GUI - QMessageBox::critical(0, "ASSERT FAILED", + #ifdef BB_GUI + QMessageBox::critical(0, "ASSERT FAILED", QString("%1 %2 %3 () - failed assert: %4"). arg(QString(file)).arg(line).arg(QString(function)).arg(QString(exp))); #endif diff --git a/src/blackmisc/debug.h b/src/blackmisc/debug.h index 78e7041c7..8bb2cc6d1 100644 --- a/src/blackmisc/debug.h +++ b/src/blackmisc/debug.h @@ -29,7 +29,7 @@ namespace BlackMisc // internal use only - void create (QString &logPath = QString(""), bool logInFile = true, bool eraseLastLog = false); + void create (const char *logPath = "", bool logInFile = true, bool eraseLastLog = false); // init Debug void init(bool logInFile); diff --git a/src/blackmisc/display.cpp b/src/blackmisc/display.cpp index 1156578f3..ab1612b52 100644 --- a/src/blackmisc/display.cpp +++ b/src/blackmisc/display.cpp @@ -9,6 +9,10 @@ #include "blackmisc/context.h" #include "blackmisc/display.h" +#ifdef Q_OS_LINUX + #include +#endif + namespace BlackMisc { @@ -243,7 +247,7 @@ namespace BlackMisc if (m_file->handle() == -1) { if ( !m_file->open(QIODevice::WriteOnly) ) - printf ("Can't open log file '%s': %s\n", m_fileName.toLatin1(), strerror (errno)); + printf ("Can't open log file '%s': %s\n", m_fileName.toLatin1().constData(), strerror (errno)); } if (m_file->handle() != -1) diff --git a/src/blackmisc/display.h b/src/blackmisc/display.h index 1a98eb617..1fb3c2bbf 100644 --- a/src/blackmisc/display.h +++ b/src/blackmisc/display.h @@ -30,7 +30,7 @@ namespace BlackMisc protected: /// Method to implement in the derived class - virtual void doPrint(const CLog::SLogInformation &logInformation, const QString &message) = NULL; + virtual void doPrint(const CLog::SLogInformation &logInformation, const QString &message) = 0; // Return the header string with date (for the first line of the log) static QString headLine (); diff --git a/src/blackmisc/log.cpp b/src/blackmisc/log.cpp index 4d94cce2f..771a2ea08 100644 --- a/src/blackmisc/log.cpp +++ b/src/blackmisc/log.cpp @@ -60,7 +60,7 @@ namespace BlackMisc #else //! Todo: Check if there a corresponding API in Linux and Mac //! For the time being, set it to unknown. - if ((*m_applicationName).empty()) + if ((*m_applicationName).isEmpty()) { *m_applicationName = ""; } diff --git a/src/blackmisc/message.cpp b/src/blackmisc/message.cpp index a81a8769b..c5d85de9c 100644 --- a/src/blackmisc/message.cpp +++ b/src/blackmisc/message.cpp @@ -2,7 +2,7 @@ namespace BlackMisc { - IMessage::IMessage(QString& id) + IMessage::IMessage(QString id) { m_message_id = id; } diff --git a/src/blackmisc/message.h b/src/blackmisc/message.h index 58c9a2061..94b533acd 100644 --- a/src/blackmisc/message.h +++ b/src/blackmisc/message.h @@ -17,7 +17,7 @@ namespace BlackMisc class IMessage : public ISerialize { public: - IMessage(QString& id); + IMessage(QString id); QString getID() const; @@ -36,7 +36,7 @@ namespace BlackMisc class TestMessage : public IMessage { public: - TestMessage() : IMessage(QString("MSG_ID_TestMessage")) + TestMessage() : IMessage("MSG_ID_TestMessage") { testString = "This is a test message!"; } diff --git a/src/blackmisc/type_info.cpp b/src/blackmisc/type_info.cpp index d9fb8dcc8..d689816a3 100644 --- a/src/blackmisc/type_info.cpp +++ b/src/blackmisc/type_info.cpp @@ -8,7 +8,7 @@ namespace BlackMisc { - CTypeInfo::CTypeInfo(const type_info& info) + CTypeInfo::CTypeInfo(const std::type_info& info) : m_typeinfo(info) { } diff --git a/src/blackmisc/type_info.h b/src/blackmisc/type_info.h index 7061bd9c7..6ed97623f 100644 --- a/src/blackmisc/type_info.h +++ b/src/blackmisc/type_info.h @@ -14,12 +14,12 @@ namespace BlackMisc class CTypeInfo { public: - explicit CTypeInfo(const type_info& info); + explicit CTypeInfo(const std::type_info& info); bool operator < (const CTypeInfo& rhs) const; private: - const type_info& m_typeinfo; + const std::type_info& m_typeinfo; }; } // namespace BlackMisc From ce55772f7a015f1a40cd65dc0a41c962043f2d6c Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sat, 30 Mar 2013 16:53:35 +0000 Subject: [PATCH 03/12] fixed dependencies between generated MSVC project files --- .../Geodetic2Ecef/sample_geodetic2ecef.pro | 21 ++++---------- samples/Logging/sample_logging.pro | 15 +++------- samples/com_client/sample_com_client.pro | 17 ++++------- samples/com_server/sample_com_server.pro | 19 ++++-------- samples/config/sample_config.pro | 13 ++------- samples/interpolator/sample_interpolator.pro | 21 ++++---------- src/blackbox/blackbox.pro | 19 +++++------- src/blackd/blackd.pro | 29 +++++-------------- 8 files changed, 45 insertions(+), 109 deletions(-) diff --git a/samples/Geodetic2Ecef/sample_geodetic2ecef.pro b/samples/Geodetic2Ecef/sample_geodetic2ecef.pro index c3dccb6aa..14e317f79 100644 --- a/samples/Geodetic2Ecef/sample_geodetic2ecef.pro +++ b/samples/Geodetic2Ecef/sample_geodetic2ecef.pro @@ -11,23 +11,14 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -SOURCES += main.cpp\ +SOURCES += main.cpp -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib +LIBS += -L../../lib -lblackmisc -lblackcore - LIBS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib -} - -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a - - LIBS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a -} +win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ + ../../lib/blackcore.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ + ../../lib/libblackcore.a DESTDIR = ../../bin diff --git a/samples/Logging/sample_logging.pro b/samples/Logging/sample_logging.pro index 795f495c4..8a9aae37b 100644 --- a/samples/Logging/sample_logging.pro +++ b/samples/Logging/sample_logging.pro @@ -11,19 +11,12 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -SOURCES += main.cpp\ +SOURCES += main.cpp -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib \ +LIBS += -L../../lib -lblackmisc - LIBS += ../../lib/blackmisc.lib \ -} - -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - - LIBS += ../../lib/libblackmisc.a \ -} +win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin diff --git a/samples/com_client/sample_com_client.pro b/samples/com_client/sample_com_client.pro index e4e5fe1f4..dbd3fcae9 100644 --- a/samples/com_client/sample_com_client.pro +++ b/samples/com_client/sample_com_client.pro @@ -13,21 +13,14 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src SOURCES += main.cpp\ - client.cpp + client.cpp -HEADERS += client.h +HEADERS += client.h -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib \ +LIBS += -L../../lib -lblackmisc - LIBS += ../../lib/blackmisc.lib \ -} - -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - - LIBS += ../../lib/libblackmisc.a \ -} +win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin diff --git a/samples/com_server/sample_com_server.pro b/samples/com_server/sample_com_server.pro index c5d8117ff..ca86554fd 100644 --- a/samples/com_server/sample_com_server.pro +++ b/samples/com_server/sample_com_server.pro @@ -11,22 +11,15 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -SOURCES += main.cpp \ - server.cpp +SOURCES += main.cpp \ + server.cpp -HEADERS += server.h +HEADERS += server.h -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib \ +LIBS += -L../../lib -lblackmisc - LIBS += ../../lib/blackmisc.lib \ -} - -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - - LIBS += ../../lib/libblackmisc.a \ -} +win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin diff --git a/samples/config/sample_config.pro b/samples/config/sample_config.pro index b3be69e9b..ac9d8c880 100644 --- a/samples/config/sample_config.pro +++ b/samples/config/sample_config.pro @@ -10,17 +10,10 @@ INCLUDEPATH += . ../../src SOURCES += main.cpp\ -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib \ +LIBS += -L../../lib -lblackmisc - LIBS += ../../lib/blackmisc.lib \ -} - -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - - LIBS += ../../lib/libblackmisc.a \ -} +win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin diff --git a/samples/interpolator/sample_interpolator.pro b/samples/interpolator/sample_interpolator.pro index 371bdfd05..270978ab1 100644 --- a/samples/interpolator/sample_interpolator.pro +++ b/samples/interpolator/sample_interpolator.pro @@ -11,23 +11,14 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -SOURCES += main.cpp\ +SOURCES += main.cpp -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib +LIBS += -L../../lib -lblackmisc -lblackcore - LIBS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib -} - -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a - - LIBS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a -} +win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ + ../../lib/blackcore.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ + ../../lib/libblackcore.a DESTDIR = ../../bin diff --git a/src/blackbox/blackbox.pro b/src/blackbox/blackbox.pro index f3ec3e901..b26749626 100644 --- a/src/blackbox/blackbox.pro +++ b/src/blackbox/blackbox.pro @@ -1,4 +1,4 @@ -QT += core gui xml svg network +QT += core gui xml svg network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -7,25 +7,20 @@ INCLUDEPATH += . .. TARGET = BlackBox TEMPLATE = app -SOURCES += main.cpp\ +SOURCES += main.cpp \ blackbox.cpp \ dialog_chat.cpp \ dialog_connect.cpp -HEADERS += blackbox.h \ +HEADERS += blackbox.h \ dialog_chat.h \ dialog_connect.h -FORMS += blackbox.ui dialog_connect.ui dialog_chat.ui +FORMS += blackbox.ui dialog_connect.ui dialog_chat.ui -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackmisc.lib -} +LIBS += -L../../lib -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackmisc.a -} +win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin diff --git a/src/blackd/blackd.pro b/src/blackd/blackd.pro index be3079e58..74ccf1a20 100644 --- a/src/blackd/blackd.pro +++ b/src/blackd/blackd.pro @@ -3,9 +3,6 @@ QT += core gui xml svg network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib - TARGET = blackd TEMPLATE = app @@ -13,8 +10,8 @@ DEPENDPATH += . .. INCLUDEPATH += .. -SOURCES += main.cpp\ - blackd.cpp \ +SOURCES += main.cpp \ + blackd.cpp \ qt_displayer.cpp \ HEADERS += blackd.h \ @@ -22,24 +19,14 @@ HEADERS += blackd.h \ FORMS += blackd.ui -RESOURCES += \ - blackd.qrc +RESOURCES += blackd.qrc -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib +LIBS += -L../../lib -lblackmisc -lblackcore - LIBS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib -} - -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a - - LIBS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a -} +win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ + ../../lib/blackcore.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ + ../../lib/libblackcore.a DESTDIR = ../../bin From 876912e5a0621a9e27391475025691cfeae64468 Mon Sep 17 00:00:00 2001 From: gmt2001 Date: Sat, 30 Mar 2013 13:43:21 -0700 Subject: [PATCH 04/12] Added missing define to blackmisc.pro --- src/blackmisc/blackmisc.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index 5fa9106eb..263247b94 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -15,6 +15,7 @@ precompile_header:!isEmpty(PRECOMPILED_HEADER) { } DEFINES += LOG_IN_FILE +DEFINES += Q_OS_LINUX HEADERS += \ logmessage.h \ From d61f8845da5c6131925d48d68643e748ef34eb16 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sun, 31 Mar 2013 14:46:08 +0200 Subject: [PATCH 05/12] #12 Fixed linker error and Mac build --- samples/interpolator/sample_interpolator.pro | 5 +++-- src/blackmisc/blackmisc.pro | 1 - src/blackmisc/display.cpp | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/samples/interpolator/sample_interpolator.pro b/samples/interpolator/sample_interpolator.pro index 371bdfd05..b669712e9 100644 --- a/samples/interpolator/sample_interpolator.pro +++ b/samples/interpolator/sample_interpolator.pro @@ -25,8 +25,9 @@ win32-msvc* { PRE_TARGETDEPS += ../../lib/libblackmisc.a \ ../../lib/libblackcore.a - LIBS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a + LIBS += ../../lib/libblackcore.a \ + ../../lib/libblackmisc.a + } DESTDIR = ../../bin diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index 263247b94..5fa9106eb 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -15,7 +15,6 @@ precompile_header:!isEmpty(PRECOMPILED_HEADER) { } DEFINES += LOG_IN_FILE -DEFINES += Q_OS_LINUX HEADERS += \ logmessage.h \ diff --git a/src/blackmisc/display.cpp b/src/blackmisc/display.cpp index ab1612b52..5dbc285e3 100644 --- a/src/blackmisc/display.cpp +++ b/src/blackmisc/display.cpp @@ -9,9 +9,7 @@ #include "blackmisc/context.h" #include "blackmisc/display.h" -#ifdef Q_OS_LINUX - #include -#endif +#include namespace BlackMisc { From e24d563729261c6f608bcecdb89843c1516b7309 Mon Sep 17 00:00:00 2001 From: gmt2001 Date: Sun, 31 Mar 2013 11:23:16 -0400 Subject: [PATCH 06/12] Fixed CXX flags to use C++11 standard WITH_STATIC is always defaulted to ON for the time being --- CMakeLists.txt | 6 +----- src/blackcore/CMakeLists.txt | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d483f9227..6ceae58d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,11 +25,7 @@ OPTION(WITH_BLACK_LIB "Build BlackBox libraries" IF(WITH_BLACK_LIB) OPTION(WITH_BLACK_CORE "Build Core library" ON ) OPTION(WITH_BLACK_MISC "Build Misc library" ON ) - IF(WIN32) - OPTION(WITH_STATIC "With static libraries." ON ) - ELSE(WIN32) - OPTION(WITH_STATIC "With static libraries." OFF) - ENDIF() + OPTION(WITH_STATIC "With static libraries." ON ) OPTION(WITH_BLACK_SAMPLES "With BlackLib Samples." ON) ENDIF(WITH_BLACK_LIB) diff --git a/src/blackcore/CMakeLists.txt b/src/blackcore/CMakeLists.txt index 13c37653c..2a5762087 100644 --- a/src/blackcore/CMakeLists.txt +++ b/src/blackcore/CMakeLists.txt @@ -2,6 +2,8 @@ FILE(GLOB blackcore_SOURCES *.cpp) FILE(GLOB blackcore_HEADERS *.h) SET(blackcore_HEADERS_QOBJECT fsd_client.h) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") QT4_WRAP_CPP(blackcore_HEADERS_MOC ${blackcore_HEADERS_QOBJECT}) From be743ba75e0f43302f8c5df3b8a3d911cc261335 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Thu, 4 Apr 2013 20:50:53 +0200 Subject: [PATCH 07/12] #12 fix capitalization errors on linux --- CMakeLists.txt | 4 ++++ samples/CMakeLists.txt | 4 ++-- samples/geodetic2ecef/CMakeLists.txt | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ceae58d4..83375e97c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,6 +165,10 @@ IF(MSVC) ENDIF(MSVC11) ADD_COMPILER_FLAGS("/D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS /DWIN32 /D_WINDOWS /Zm1000 /wd4250") + + ADD_DEFINITIONS( + /Zc:wchar_t- # Treat wchar_t as built-in type + ) ENDIF() ############### Configure checks ############### diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 4ec2bec48..2e087986a 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,6 +1,6 @@ -ADD_SUBDIRECTORY(Logging) +ADD_SUBDIRECTORY(logging) ADD_SUBDIRECTORY(com_server) ADD_SUBDIRECTORY(com_client) -ADD_SUBDIRECTORY(Geodetic2Ecef) +ADD_SUBDIRECTORY(geodetic2ecef) ADD_SUBDIRECTORY(interpolator) ADD_SUBDIRECTORY(config) \ No newline at end of file diff --git a/samples/geodetic2ecef/CMakeLists.txt b/samples/geodetic2ecef/CMakeLists.txt index b3afc69b1..0b3848fa2 100644 --- a/samples/geodetic2ecef/CMakeLists.txt +++ b/samples/geodetic2ecef/CMakeLists.txt @@ -1,6 +1,6 @@ FILE(GLOB SRC *.cpp) -ADD_EXECUTABLE(sample_Geodetic2Ecef ${SRC}) +ADD_EXECUTABLE(sample_geodetic2ecef ${SRC}) -TARGET_LINK_LIBRARIES(sample_Geodetic2Ecef blackmisc blackcore ${QT_LIBRARIES}) -SET_TARGET_PROPERTIES(sample_Geodetic2Ecef PROPERTIES PROJECT_LABEL "Samples - Geodetic to Ecef") \ No newline at end of file +TARGET_LINK_LIBRARIES(sample_geodetic2ecef blackmisc blackcore ${QT_LIBRARIES}) +SET_TARGET_PROPERTIES(sample_geodetic2ecef PROPERTIES PROJECT_LABEL "Samples - Geodetic to Ecef") \ No newline at end of file From e3a8ad29872e7b87c9508dade76da940248bcadc Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 9 Apr 2013 18:05:52 +0100 Subject: [PATCH 08/12] wildcards for qmake variables SOURCES and HEADERS --- samples/com_client/sample_com_client.pro | 5 +-- samples/com_server/sample_com_server.pro | 5 +-- samples/config/sample_config.pro | 2 +- .../geodetic2ecef/sample_geodetic2ecef.pro | 2 +- samples/interpolator/sample_interpolator.pro | 2 +- samples/logging/sample_logging.pro | 2 +- src/blackbox/blackbox.pro | 9 +--- src/blackcore/blackcore.pro | 31 +------------- src/blackd/blackd.pro | 7 +--- src/blackmisc/blackmisc.pro | 41 +------------------ src/driver/fs9/driver_fs9.pro | 6 +-- src/driver/fsx/driver_fsx.pro | 6 +-- src/driver/xplane/driver_xplane.pro | 6 +-- 13 files changed, 22 insertions(+), 102 deletions(-) diff --git a/samples/com_client/sample_com_client.pro b/samples/com_client/sample_com_client.pro index dbd3fcae9..7ae763799 100644 --- a/samples/com_client/sample_com_client.pro +++ b/samples/com_client/sample_com_client.pro @@ -12,10 +12,9 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -SOURCES += main.cpp\ - client.cpp +SOURCES += *.cpp -HEADERS += client.h +HEADERS += *.h LIBS += -L../../lib -lblackmisc diff --git a/samples/com_server/sample_com_server.pro b/samples/com_server/sample_com_server.pro index ca86554fd..968f4e4a3 100644 --- a/samples/com_server/sample_com_server.pro +++ b/samples/com_server/sample_com_server.pro @@ -11,10 +11,9 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -SOURCES += main.cpp \ - server.cpp +SOURCES += *.cpp -HEADERS += server.h +HEADERS += *.h LIBS += -L../../lib -lblackmisc diff --git a/samples/config/sample_config.pro b/samples/config/sample_config.pro index ac9d8c880..ed1122f63 100644 --- a/samples/config/sample_config.pro +++ b/samples/config/sample_config.pro @@ -8,7 +8,7 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -SOURCES += main.cpp\ +SOURCES += *.cpp LIBS += -L../../lib -lblackmisc diff --git a/samples/geodetic2ecef/sample_geodetic2ecef.pro b/samples/geodetic2ecef/sample_geodetic2ecef.pro index 14e317f79..90598595a 100644 --- a/samples/geodetic2ecef/sample_geodetic2ecef.pro +++ b/samples/geodetic2ecef/sample_geodetic2ecef.pro @@ -11,7 +11,7 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -SOURCES += main.cpp +SOURCES += *.cpp LIBS += -L../../lib -lblackmisc -lblackcore diff --git a/samples/interpolator/sample_interpolator.pro b/samples/interpolator/sample_interpolator.pro index 270978ab1..339ed12f4 100644 --- a/samples/interpolator/sample_interpolator.pro +++ b/samples/interpolator/sample_interpolator.pro @@ -11,7 +11,7 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -SOURCES += main.cpp +SOURCES += *.cpp LIBS += -L../../lib -lblackmisc -lblackcore diff --git a/samples/logging/sample_logging.pro b/samples/logging/sample_logging.pro index 8a9aae37b..3afe1dfe7 100644 --- a/samples/logging/sample_logging.pro +++ b/samples/logging/sample_logging.pro @@ -11,7 +11,7 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -SOURCES += main.cpp +SOURCES += *.cpp LIBS += -L../../lib -lblackmisc diff --git a/src/blackbox/blackbox.pro b/src/blackbox/blackbox.pro index b26749626..5f1a9f31e 100644 --- a/src/blackbox/blackbox.pro +++ b/src/blackbox/blackbox.pro @@ -7,14 +7,9 @@ INCLUDEPATH += . .. TARGET = BlackBox TEMPLATE = app -SOURCES += main.cpp \ - blackbox.cpp \ - dialog_chat.cpp \ - dialog_connect.cpp +SOURCES += *.cpp -HEADERS += blackbox.h \ - dialog_chat.h \ - dialog_connect.h +HEADERS += *.h FORMS += blackbox.ui dialog_connect.ui dialog_chat.ui diff --git a/src/blackcore/blackcore.pro b/src/blackcore/blackcore.pro index 3986d725c..dc0e02753 100644 --- a/src/blackcore/blackcore.pro +++ b/src/blackcore/blackcore.pro @@ -20,36 +20,9 @@ precompile_header:!isEmpty(PRECOMPILED_HEADER) { DEFINES += LOG_IN_FILE -HEADERS += \ - sim_callbacks.h \ - constants.h \ - fsd_protocol.h \ - ecef.h \ - fsd_client.h \ - fsd_messages.h \ - interpolator.h \ - mathematics.h \ - matrix_3d.h \ - multiplayer.h \ - ned.h \ - plane.h \ - simulator.h \ - vector_3d.h \ - vector_geo.h +HEADERS += *.h -SOURCES += \ - ecef.cpp \ - fsd_client.cpp \ - fsd_messages.cpp \ - interpolator.cpp \ - mathematics.cpp \ - matrix_3d.cpp \ - multiplayer.cpp \ - ned.cpp \ - plane.cpp \ - simulator.cpp \ - vector_3d.cpp \ - vector_geo.cpp +SOURCES += *.cpp DESTDIR = ../../lib diff --git a/src/blackd/blackd.pro b/src/blackd/blackd.pro index 74ccf1a20..8e786f59f 100644 --- a/src/blackd/blackd.pro +++ b/src/blackd/blackd.pro @@ -10,12 +10,9 @@ DEPENDPATH += . .. INCLUDEPATH += .. -SOURCES += main.cpp \ - blackd.cpp \ - qt_displayer.cpp \ +SOURCES += *.cpp -HEADERS += blackd.h \ - qt_displayer.h \ +HEADERS += *.h FORMS += blackd.ui diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index 5fa9106eb..32495884d 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -16,46 +16,9 @@ precompile_header:!isEmpty(PRECOMPILED_HEADER) { DEFINES += LOG_IN_FILE -HEADERS += \ - logmessage.h \ - log.h \ - display.h \ - debug.h \ - context.h \ - config.h \ - config_manager.h \ - serialize.h \ - com_client.h \ - com_server.h \ - com_client_buffer.h \ - message.h \ - com_handler.h \ - message_factory.h \ - message_handler.h \ - type_info.h \ - message_dispatcher.h \ - message_system.h \ - gui_messages.h +HEADERS += *.h -SOURCES += \ - logmessage.cpp \ - log.cpp \ - display.cpp \ - debug.cpp \ - context.cpp \ - config.cpp \ - config_manager.cpp \ - serialize.cpp \ - com_client.cpp \ - com_server.cpp \ - com_client_buffer.cpp \ - message.cpp \ - com_handler.cpp \ - message_factory.cpp \ - message_handler.cpp \ - type_info.cpp \ - message_dispatcher.cpp \ - message_system.cpp +SOURCES += *.cpp DESTDIR = ../../lib diff --git a/src/driver/fs9/driver_fs9.pro b/src/driver/fs9/driver_fs9.pro index 8397ff782..236b65797 100644 --- a/src/driver/fs9/driver_fs9.pro +++ b/src/driver/fs9/driver_fs9.pro @@ -8,11 +8,9 @@ DESTDIR = ../../../bin DEPENDPATH += . -HEADERS += \ - driver_fs9.h +HEADERS += *.h -SOURCES += \ - driver_fs9.cpp +SOURCES += *.cpp diff --git a/src/driver/fsx/driver_fsx.pro b/src/driver/fsx/driver_fsx.pro index 2bcd027fb..81ecfc425 100644 --- a/src/driver/fsx/driver_fsx.pro +++ b/src/driver/fsx/driver_fsx.pro @@ -8,11 +8,9 @@ DESTDIR = ../../../bin DEPENDPATH += . -HEADERS += \ - driver_fsx.h +HEADERS += *.h -SOURCES += \ - driver_fsx.cpp +SOURCES += *.cpp diff --git a/src/driver/xplane/driver_xplane.pro b/src/driver/xplane/driver_xplane.pro index 3e59e5d0f..7116b9cf8 100644 --- a/src/driver/xplane/driver_xplane.pro +++ b/src/driver/xplane/driver_xplane.pro @@ -8,11 +8,9 @@ DESTDIR = ../../../bin DEPENDPATH += . -HEADERS += \ - driver_xplane.h +HEADERS += *.h -SOURCES += \ - driver_xplane.cpp +SOURCES += *.cpp From 83b380d03570fce29acc310551993077d026a328 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Fri, 12 Apr 2013 22:30:06 +0100 Subject: [PATCH 09/12] #12 fixed link order when linking with blackcore and blackmisc --- samples/geodetic2ecef/sample_geodetic2ecef.pro | 2 +- samples/interpolator/sample_interpolator.pro | 2 +- src/blackd/blackd.pro | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/geodetic2ecef/sample_geodetic2ecef.pro b/samples/geodetic2ecef/sample_geodetic2ecef.pro index 90598595a..33ac98235 100644 --- a/samples/geodetic2ecef/sample_geodetic2ecef.pro +++ b/samples/geodetic2ecef/sample_geodetic2ecef.pro @@ -13,7 +13,7 @@ INCLUDEPATH += . ../../src SOURCES += *.cpp -LIBS += -L../../lib -lblackmisc -lblackcore +LIBS += -L../../lib -lblackcore -lblackmisc win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ ../../lib/blackcore.lib diff --git a/samples/interpolator/sample_interpolator.pro b/samples/interpolator/sample_interpolator.pro index 339ed12f4..697863670 100644 --- a/samples/interpolator/sample_interpolator.pro +++ b/samples/interpolator/sample_interpolator.pro @@ -13,7 +13,7 @@ INCLUDEPATH += . ../../src SOURCES += *.cpp -LIBS += -L../../lib -lblackmisc -lblackcore +LIBS += -L../../lib -lblackcore -lblackmisc win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ ../../lib/blackcore.lib diff --git a/src/blackd/blackd.pro b/src/blackd/blackd.pro index 8e786f59f..77231cdf9 100644 --- a/src/blackd/blackd.pro +++ b/src/blackd/blackd.pro @@ -18,7 +18,7 @@ FORMS += blackd.ui RESOURCES += blackd.qrc -LIBS += -L../../lib -lblackmisc -lblackcore +LIBS += -L../../lib -lblackcore -lblackmisc win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ ../../lib/blackcore.lib From 4e812975b4c0dbc6e9a88eacc114cc5e550bd87a Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Fri, 12 Apr 2013 23:57:44 +0100 Subject: [PATCH 10/12] provisionally added doxygen target in qmake build system --- client.pro | 7 +++++-- docs/doxygen.pro | 49 ++++++++++++++++++++++++++++++++++++++++++++++ docs/qconfigure.pl | 43 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 docs/doxygen.pro create mode 100644 docs/qconfigure.pl diff --git a/client.pro b/client.pro index fb6ec2edd..eee2b9360 100644 --- a/client.pro +++ b/client.pro @@ -20,6 +20,8 @@ WITH_SAMPLES = ON #WITH_UNITTESTS = ON +#WITH_DOXYGEN = ON + equals(WITH_BLACKMISC, ON) { SUBDIRS += src/blackmisc @@ -62,5 +64,6 @@ equals(WITH_UNITTESTS, ON) { SUBDIRS += } - - +equals(WITH_DOXYGEN, ON) { + SUBDIRS += docs/doxygen.pro +} diff --git a/docs/doxygen.pro b/docs/doxygen.pro new file mode 100644 index 000000000..48b0e7e03 --- /dev/null +++ b/docs/doxygen.pro @@ -0,0 +1,49 @@ +# Copyright (C) 2013 VATSIM community / contributors +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/ +# +# Black magic to get qmake to generate a build target to process the file +# Doxyfile.cmake.in and then invoke doxygen. + +TEMPLATE = lib +CONFIG += staticlib +CONFIG -= qt + +COPY_FILES += qconfigure.pl +CONFIGURE_IN += Doxyfile.cmake.in +DOXYFILE = Doxyfile + +defineReplace(qconfigureReplace) { + file = $$1 + file = $$basename(file) + file = $$replace(file, .cmake.in, ) + return($$file) +} + +win32: copy.commands = copy ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} +else: copy.commands = cp ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} +copy.CONFIG = no_link +copy.input = COPY_FILES +copy.output = ${QMAKE_FILE_IN_BASE}${QMAKE_FILE_EXT} +copy.name = COPY +QMAKE_EXTRA_COMPILERS += copy + +qconfigure.commands = perl qconfigure.pl ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} \ + CMAKE_CURRENT_BINARY_DIR=$$OUT_PWD \ + CMAKE_CURRENT_SOURCE_DIR=$$PWD +qconfigure.CONFIG = no_link +qconfigure.depends = qconfigure.pl +qconfigure.input = CONFIGURE_IN +qconfigure.name = QCONFIGURE +qconfigure.output_function = qconfigureReplace +QMAKE_EXTRA_COMPILERS += qconfigure + +DOXY_INPUT = . +doxy.commands = doxygen $$DOXYFILE +doxy.CONFIG = no_link +doxy.depends = $$DOXYFILE +doxy.input = DOXY_INPUT +doxy.name = DOXY +doxy.output = .nothing +QMAKE_EXTRA_COMPILERS += doxy \ No newline at end of file diff --git a/docs/qconfigure.pl b/docs/qconfigure.pl new file mode 100644 index 000000000..95c2b8373 --- /dev/null +++ b/docs/qconfigure.pl @@ -0,0 +1,43 @@ +#!/usr/bin/perl +# +# Copyright (C) 2013 VATSIM community / contributors +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/ +# +# Script used by the qmake project file doxygen.pro to process the file +# Doxyfile.cmake.in + +use strict; +use warnings; + +die "not enough arguments\n" if @ARGV < 2; + +my ($infile, $outfile, @vars) = @ARGV; + +my %vars; +for my $line (@vars) +{ + my ($var, $val) = split '=', $line; + $vars{$var} = $val; + + die "missing '=' in parameter\n" unless defined $val; +} + +$infile =~ s.\\./.g; +$outfile =~ s.\\./.g; + +open my $in, '<', $infile or die "couldn't read from $infile\n"; +open my $out, '>', $outfile or die "couldn't write to $outfile\n"; + +while (defined(my $line = <$in>)) +{ + for my $var (keys %vars) + { + $line =~ s.\@$var\@.$vars{$var}.g; + } + print $out $line; +} + +close $in; +close $out; \ No newline at end of file From 9916419678175b0470b7cb28380be77c5a7c74c6 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Wed, 17 Apr 2013 01:26:54 +0100 Subject: [PATCH 11/12] #31 Squashed merge of commits relating to the plugin system and IContext redesign, from the 'interconnect' branch. --- client.pro | 2 + samples/CMakeLists.txt | 4 +- samples/com_client/client.cpp | 4 +- samples/com_client/main.cpp | 4 +- samples/com_server/main.cpp | 4 +- samples/com_server/server.cpp | 8 +- samples/config/main.cpp | 10 +- samples/geodetic2ecef/main.cpp | 4 +- samples/interpolator/main.cpp | 5 + samples/logging/main.cpp | 11 +- samples/plugin/CMakeLists.txt | 6 + samples/plugin/plugin.cpp | 40 +++ samples/plugin/sample_plugin.pro | 22 ++ samples/pluginmgr/CMakeLists.txt | 6 + samples/pluginmgr/main.cpp | 53 ++++ samples/pluginmgr/sample_pluginmgr.pro | 26 ++ src/blackbox/dialog_connect.cpp | 2 +- src/blackbox/main.cpp | 4 +- src/blackcore/fsd_client.cpp | 42 ++- src/blackcore/fsd_client.h | 11 +- src/blackcore/fsd_messages.cpp | 7 +- src/blackcore/fsd_messages.h | 2 +- src/blackcore/matrix_3d.cpp | 10 +- src/blackcore/plane.cpp | 8 +- src/blackcore/plane.h | 1 + src/blackcore/pluginmgr.cpp | 104 +++++++ src/blackcore/pluginmgr.h | 136 ++++++++ src/blackcore/simulator.cpp | 46 ++- src/blackcore/vector_3d.cpp | 16 +- src/blackd/blackd.cpp | 17 +- src/blackd/qt_displayer.cpp | 4 +- src/blackmisc/com_client.cpp | 38 +-- src/blackmisc/com_client.h | 10 +- src/blackmisc/com_client_buffer.cpp | 15 +- src/blackmisc/com_client_buffer.h | 8 +- src/blackmisc/com_handler.cpp | 23 +- src/blackmisc/com_handler.h | 7 +- src/blackmisc/com_server.cpp | 32 +- src/blackmisc/com_server.h | 10 +- src/blackmisc/config.cpp | 19 +- src/blackmisc/config.h | 7 +- src/blackmisc/config_manager.cpp | 22 +- src/blackmisc/config_manager.h | 25 +- src/blackmisc/context.cpp | 116 +++---- src/blackmisc/context.h | 415 ++++++++++++------------- src/blackmisc/debug.cpp | 186 ++++------- src/blackmisc/debug.h | 194 +++++------- src/blackmisc/display.cpp | 27 +- src/blackmisc/display.h | 3 +- src/blackmisc/log.cpp | 226 ++++++-------- src/blackmisc/log.h | 281 ++++++++--------- src/blackmisc/logmessage.cpp | 77 +++-- src/blackmisc/logmessage.h | 59 ++-- src/blackmisc/message_dispatcher.h | 26 +- src/blackmisc/message_factory.h | 10 +- src/blackmisc/message_handler.h | 4 +- src/blackmisc/plugins.h | 150 +++++++++ 57 files changed, 1517 insertions(+), 1092 deletions(-) create mode 100644 samples/plugin/CMakeLists.txt create mode 100644 samples/plugin/plugin.cpp create mode 100644 samples/plugin/sample_plugin.pro create mode 100644 samples/pluginmgr/CMakeLists.txt create mode 100644 samples/pluginmgr/main.cpp create mode 100644 samples/pluginmgr/sample_pluginmgr.pro create mode 100644 src/blackcore/pluginmgr.cpp create mode 100644 src/blackcore/pluginmgr.h create mode 100644 src/blackmisc/plugins.h diff --git a/client.pro b/client.pro index eee2b9360..38facf902 100644 --- a/client.pro +++ b/client.pro @@ -58,6 +58,8 @@ equals(WITH_SAMPLES, ON) { SUBDIRS += samples/geodetic2ecef/sample_geodetic2ecef.pro SUBDIRS += samples/interpolator/sample_interpolator.pro SUBDIRS += samples/logging/sample_logging.pro + SUBDIRS += samples/plugin/sample_plugin.pro + SUBDIRS += samples/pluginmgr/sample_pluginmgr.pro } equals(WITH_UNITTESTS, ON) { diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 2e087986a..44a4acf0e 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -3,4 +3,6 @@ ADD_SUBDIRECTORY(com_server) ADD_SUBDIRECTORY(com_client) ADD_SUBDIRECTORY(geodetic2ecef) ADD_SUBDIRECTORY(interpolator) -ADD_SUBDIRECTORY(config) \ No newline at end of file +ADD_SUBDIRECTORY(config) +ADD_SUBDIRECTORY(plugin) +ADD_SUBDIRECTORY(pluginmgr) \ No newline at end of file diff --git a/samples/com_client/client.cpp b/samples/com_client/client.cpp index 6858316f1..ce56654b0 100644 --- a/samples/com_client/client.cpp +++ b/samples/com_client/client.cpp @@ -4,7 +4,7 @@ using namespace BlackMisc; -Client::Client(QObject *parent) : QObject(parent) +Client::Client(QObject *parent) : QObject(parent), comclient(IContext::getInstance()) { connect(&comclient, SIGNAL(doError(QAbstractSocket::SocketError,QString)), this, SLOT(onError(QAbstractSocket::SocketError,QString))); connect(&comclient, SIGNAL(doConnected()), this, SLOT(onClientConnected())); @@ -19,7 +19,7 @@ Client::~Client() void Client::onError(QAbstractSocket::SocketError error, QString message) { - bWarning << "Socket error!"; + bAppWarning << "Socket error!"; } void Client::onClientConnected() diff --git a/samples/com_client/main.cpp b/samples/com_client/main.cpp index dbfac244e..081b6ec48 100644 --- a/samples/com_client/main.cpp +++ b/samples/com_client/main.cpp @@ -10,7 +10,9 @@ int main(int argc, char *argv[]) BlackMisc::CApplicationContext myApplicationContext; QCoreApplication a(argc, argv); - Client client; + BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + + Client client; return a.exec(); } diff --git a/samples/com_server/main.cpp b/samples/com_server/main.cpp index dc024e6c1..c98e592f8 100644 --- a/samples/com_server/main.cpp +++ b/samples/com_server/main.cpp @@ -10,7 +10,9 @@ int main(int argc, char *argv[]) BlackMisc::CApplicationContext myApplicationContext; QCoreApplication a(argc, argv); - Server server; + BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + + Server server; return a.exec(); } diff --git a/samples/com_server/server.cpp b/samples/com_server/server.cpp index f0170cdf6..31141e034 100644 --- a/samples/com_server/server.cpp +++ b/samples/com_server/server.cpp @@ -3,7 +3,7 @@ using namespace BlackMisc; -Server::Server(QObject *parent) : QObject(parent) +Server::Server(QObject *parent) : QObject(parent), server(IContext::getInstance()) { QHostAddress local = QHostAddress(QHostAddress::LocalHost); @@ -13,7 +13,7 @@ Server::Server(QObject *parent) : QObject(parent) CMessageSystem myMessageSystem; - bInfo << "Com Server running. \n"; + bAppInfo << "Com Server running. \n"; } Server::~Server() @@ -25,7 +25,7 @@ void Server::onData(QString &messageID, QByteArray &message) BlackMisc::IMessage* test = BlackMisc::CMessageFactory::getInstance().create(messageID); QDataStream stream(&message, QIODevice::ReadOnly); - bAssert (test); + Q_ASSERT(test); *test << stream; CMessageDispatcher::getInstance().append(test); @@ -35,5 +35,5 @@ void Server::onData(QString &messageID, QByteArray &message) void TestMessageHandler::onTestMessage(const TestMessage *testmessage) { - bDebug << "Message ID: " << testmessage->getID() << " with text: " << testmessage->getTestString(); + bAppDebug << "Message ID: " << testmessage->getID() << " with text: " << testmessage->getTestString(); } diff --git a/samples/config/main.cpp b/samples/config/main.cpp index e1215c467..ae7b719d8 100644 --- a/samples/config/main.cpp +++ b/samples/config/main.cpp @@ -12,15 +12,17 @@ int main(int argc, char *argv[]) QCoreApplication a(argc, argv); BlackMisc::CApplicationContext myApplicationContext; - CConfigManager::getInstance().setConfigPath(QString("config")); + BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + + CConfigManager::getInstance().setConfigPath(QString("config")); if (!CConfigManager::getInstance().readConfig()) { - bWarning << "To run this sample, there must be a config folder"; - bWarning << "in the same directory, containing *.cfg files."; + bAppWarning << "To run this sample, there must be a config folder"; + bAppWarning << "in the same directory, containing *.cfg files."; } CConfig *myConfig = CConfigManager::getInstance().getConfig("position"); - bAssert(myConfig); + Q_ASSERT(myConfig); myConfig->display(); return a.exec(); diff --git a/samples/geodetic2ecef/main.cpp b/samples/geodetic2ecef/main.cpp index a9e3e7ef3..384f4e288 100644 --- a/samples/geodetic2ecef/main.cpp +++ b/samples/geodetic2ecef/main.cpp @@ -13,7 +13,9 @@ int main(int argc, char *argv[]) QCoreApplication a(argc, argv); BlackMisc::CApplicationContext myApplicationContext; - QElapsedTimer timer; + BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + + QElapsedTimer timer; qint64 duration; double lat = 27.999999, lon = 86.999999, h = 8820.999999; // Mt Everest diff --git a/samples/interpolator/main.cpp b/samples/interpolator/main.cpp index 5631edae9..cd92bde68 100644 --- a/samples/interpolator/main.cpp +++ b/samples/interpolator/main.cpp @@ -7,6 +7,8 @@ #include "blackcore/vector_geo.h" #include "blackcore/vector_3d.h" #include "blackcore/interpolator.h" +#include "blackmisc/context.h" +#include "blackmisc/debug.h" using namespace std; using namespace BlackCore; @@ -14,6 +16,9 @@ using namespace BlackCore; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); + + BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + QElapsedTimer timer; CVectorGeo myGeo(48.123, 11.75, 400); diff --git a/samples/logging/main.cpp b/samples/logging/main.cpp index b3f428e77..43ce024a6 100644 --- a/samples/logging/main.cpp +++ b/samples/logging/main.cpp @@ -1,5 +1,6 @@ #include #include "blackmisc/debug.h" +#include "blackmisc/context.h" #include "blackcore/constants.h" #include #include @@ -9,10 +10,12 @@ int main(int argc, char *argv[]) QCoreApplication a(argc, argv); BlackMisc::CApplicationContext myApplicationContext; - bInfo << "This is a Info log message"; - bWarning << "This is a bWarning log message"; - bError << "This is a bError log message"; - bDebug << "This is a bDebug log message"; + BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + + bAppInfo << "This is a Info log message"; + bAppWarning << "This is a bWarning log message"; + bAppError << "This is a bError log message"; + bAppDebug << "This is a bDebug log message"; return a.exec(); } diff --git a/samples/plugin/CMakeLists.txt b/samples/plugin/CMakeLists.txt new file mode 100644 index 000000000..63d30b352 --- /dev/null +++ b/samples/plugin/CMakeLists.txt @@ -0,0 +1,6 @@ +FILE(GLOB SRC *.cpp) + +ADD_LIBRARY(sample_plugin MODULE ${SRC}) + +TARGET_LINK_LIBRARIES(sample_plugin blackmisc ${QT_LIBRARIES}) +SET_TARGET_PROPERTIES(sample_plugin PROPERTIES PROJECT_LABEL "Samples - Plugin") \ No newline at end of file diff --git a/samples/plugin/plugin.cpp b/samples/plugin/plugin.cpp new file mode 100644 index 000000000..0b183c767 --- /dev/null +++ b/samples/plugin/plugin.cpp @@ -0,0 +1,40 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackmisc/plugins.h" +#include + +class CPlugin : public BlackMisc::IPlugin +{ +public: + CPlugin(BlackMisc::IPluginFactory &factory, BlackMisc::IContext &context); + + virtual ~CPlugin(); + + virtual bool isValid() const { return m_ctorOK; } + + virtual BlackMisc::IPluginFactory &getFactory() { return m_factory; } + +private: + bool m_ctorOK; + BlackMisc::IPluginFactory &m_factory; + BlackMisc::IContext &m_context; +}; + +MAKE_BLACK_PLUGIN(sample_plugin, CPlugin, "An example minimal plugin") + +CPlugin::CPlugin(BlackMisc::IPluginFactory &factory, BlackMisc::IContext &context) +: m_ctorOK(false), + m_factory(factory), + m_context(context) +{ + std::cout << "Sample plugin constructor" << std::endl; + m_ctorOK = true; +} + +CPlugin::~CPlugin() +{ + std::cout << "Sample plugin destructor" << std::endl; +} \ No newline at end of file diff --git a/samples/plugin/sample_plugin.pro b/samples/plugin/sample_plugin.pro new file mode 100644 index 000000000..2604ada6b --- /dev/null +++ b/samples/plugin/sample_plugin.pro @@ -0,0 +1,22 @@ +QT += core +QT -= gui + +TARGET = sample_plugin +TEMPLATE = lib +CONFIG += plugin + +DEPENDPATH += . ../../src + +INCLUDEPATH += . ../../src + +SOURCES += *.cpp + +LIBS += -L../../lib -lblackmisc + +win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a + +DESTDIR = ../../bin + + + diff --git a/samples/pluginmgr/CMakeLists.txt b/samples/pluginmgr/CMakeLists.txt new file mode 100644 index 000000000..7c07f94e2 --- /dev/null +++ b/samples/pluginmgr/CMakeLists.txt @@ -0,0 +1,6 @@ +FILE(GLOB SRC *.cpp) + +ADD_EXECUTABLE(sample_pluginmgr ${SRC}) + +TARGET_LINK_LIBRARIES(sample_pluginmgr blackmisc ${QT_LIBRARIES}) +SET_TARGET_PROPERTIES(sample_pluginmgr PROPERTIES PROJECT_LABEL "Samples - Plugin Manager") \ No newline at end of file diff --git a/samples/pluginmgr/main.cpp b/samples/pluginmgr/main.cpp new file mode 100644 index 000000000..dcb64e883 --- /dev/null +++ b/samples/pluginmgr/main.cpp @@ -0,0 +1,53 @@ +#include "blackcore/pluginmgr.h" +#include "blackmisc/plugins.h" +#include "blackmisc/context.h" +#include "blackmisc/debug.h" +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + BlackMisc::CApplicationContext myApplicationContext; + + BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + + { + const QString pluginPath = "../../build/bin"; + + std::cout << "Loading plugins from " << pluginPath.toStdString() << std::endl; + + BlackCore::CPluginManager pluginmgr; + pluginmgr.loadAllPlugins(pluginPath); + size_t count = pluginmgr.getPluginCount(); + + std::cout << count << " plugins loaded" << std::endl << std::endl; + + for (size_t i = 0; i < count; ++i) + { + std::cout << "Plugin " << i << ": " << pluginmgr.getName(i).toStdString() + << ": " << pluginmgr.getDescription(i).toStdString() << std::endl; + } + std::cout << std::endl; + + std::vector plugins; + + for (size_t i = 0; i < count; ++i) + { + std::cout << "Constructing plugin " << i << std::endl; + + plugins.push_back(pluginmgr.constructPlugin(i)); + } + + size_t i = 0; + for (std::vector::iterator it = plugins.begin(); it != plugins.end(); ++it, ++i) + { + std::cout << "Destroying plugin " << i << std::endl; + + (*it)->getFactory().destroy(*it); + } + } + + //return a.exec(); +} diff --git a/samples/pluginmgr/sample_pluginmgr.pro b/samples/pluginmgr/sample_pluginmgr.pro new file mode 100644 index 000000000..30f50f0fa --- /dev/null +++ b/samples/pluginmgr/sample_pluginmgr.pro @@ -0,0 +1,26 @@ +QT += core +QT -= gui + +TARGET = sample_pluginmgr +TEMPLATE = app + +CONFIG += console +CONFIG -= app_bundle + +DEPENDPATH += . ../../src + +INCLUDEPATH += . ../../src + +SOURCES += *.cpp + +LIBS += -L../../lib -lblackcore -lblackmisc + +win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ + ../../lib/blackcore.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ + ../../lib/libblackcore.a + +DESTDIR = ../../bin + + + diff --git a/src/blackbox/dialog_connect.cpp b/src/blackbox/dialog_connect.cpp index f10035e5d..49357850a 100644 --- a/src/blackbox/dialog_connect.cpp +++ b/src/blackbox/dialog_connect.cpp @@ -14,7 +14,7 @@ using namespace BlackMisc; CDialogConnect::CDialogConnect(QWidget *parent) : QDialog(parent), m_hasComConnection(false), - ui(new Ui::CDialogConnect) + ui(new Ui::CDialogConnect), comclient(IContext::getInstance()) { ui->setupUi(this); diff --git a/src/blackbox/main.cpp b/src/blackbox/main.cpp index e4bca8d7f..1bf40f033 100644 --- a/src/blackbox/main.cpp +++ b/src/blackbox/main.cpp @@ -11,10 +11,8 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - BlackMisc::CApplicationContext myBlackApp; - BlackMisc::IContext::getInstance().getDebug()->create(); + BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); - BlackBox w; w.show(); diff --git a/src/blackcore/fsd_client.cpp b/src/blackcore/fsd_client.cpp index 2d1153216..2f5445895 100644 --- a/src/blackcore/fsd_client.cpp +++ b/src/blackcore/fsd_client.cpp @@ -1,11 +1,9 @@ -#include -#include - -#include -#include - #include "blackcore/fsd_client.h" #include "blackcore/fsd_messages.h" +#include +#include +#include +#include namespace FSD { @@ -13,8 +11,8 @@ namespace FSD using namespace BlackMisc; - CFSDClient::CFSDClient() - : m_tcp_socket(NULL), m_port(0), m_simType(FSD::SIM_UNKNOWN) + CFSDClient::CFSDClient(IContext &context) + : m_context(context), m_tcp_socket(NULL), m_port(0), m_simType(FSD::SIM_UNKNOWN) { init(); } @@ -27,14 +25,14 @@ namespace FSD if ( isConnected() ) return; - bDebug << "Connecting to FSD server: " << m_host << ":" << m_port; + bDebug(m_context) << "Connecting to FSD server: " << m_host << ":" << m_port; m_tcp_socket->connectToHost(m_host, m_port); } void CFSDClient::disconnectFrom() { - bDebug << "Disconnecting from host."; + bDebug(m_context) << "Disconnecting from host."; m_tcp_socket->disconnectFromHost(); m_port = 0; @@ -69,8 +67,8 @@ namespace FSD void CFSDClient::onConnected() { - bDebug << "Connected successfully to remote host."; - bDebug << "Sending #AP now..."; + bDebug(m_context) << "Connected successfully to remote host."; + bDebug(m_context) << "Sending #AP now..."; QString line; @@ -92,7 +90,7 @@ namespace FSD void CFSDClient::onDisconnected() { - bDebug << "Disconnected successfully from remote host."; + bDebug(m_context) << "Disconnected successfully from remote host."; emit doDisconnected(); } @@ -101,7 +99,7 @@ namespace FSD if ( error != 0 ) { - bError << "Received socket error: " << error << " - Disconnecting..."; + bError(m_context) << "Received socket error: " << error << " - Disconnecting..."; } disconnectFrom(); @@ -125,7 +123,7 @@ namespace FSD { if (!isConnected()) { - bError << "Cannot send data in disconnected state!"; + bError(m_context) << "Cannot send data in disconnected state!"; return false; } @@ -134,7 +132,7 @@ namespace FSD qint64 bytes = m_tcp_socket->write(message.toAscii()); if (bytes < 0 || bytes != message_size) { - bWarning << "Error writing to socket!"; + bWarning(m_context) << "Error writing to socket!"; return false; } @@ -144,13 +142,13 @@ namespace FSD void CFSDClient::init() { m_tcp_socket = new QTcpSocket(this); - bAssert(m_tcp_socket); + Q_ASSERT(m_tcp_socket); - bAssert ( QObject::connect( m_tcp_socket, SIGNAL( connected() ), this, SLOT( onConnected() ) ) ); - bAssert ( QObject::connect( m_tcp_socket, SIGNAL( disconnected() ), this, SLOT( onDisconnected() ) ) ); - bAssert ( QObject::connect( m_tcp_socket, SIGNAL( error(QAbstractSocket::SocketError) ), this, SLOT( onError(QAbstractSocket::SocketError) ) ) ); + Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( connected() ), this, SLOT( onConnected() ) ) ); + Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( disconnected() ), this, SLOT( onDisconnected() ) ) ); + Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( error(QAbstractSocket::SocketError) ), this, SLOT( onError(QAbstractSocket::SocketError) ) ) ); - bAssert ( QObject::connect( m_tcp_socket, SIGNAL( readyRead() ), this, SLOT( onReceivingData() ) ) ); + Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( readyRead() ), this, SLOT( onReceivingData() ) ) ); registerMessages(); } @@ -178,7 +176,7 @@ namespace FSD QTextStream stream(&line); IMessage* fsd_message = CMessageFactory::getInstance().create(header); - bAssert(fsd_message); + Q_ASSERT(fsd_message); *fsd_message << stream; CMessageDispatcher::getInstance().append(fsd_message); diff --git a/src/blackcore/fsd_client.h b/src/blackcore/fsd_client.h index 5cf8746a2..40aa11650 100644 --- a/src/blackcore/fsd_client.h +++ b/src/blackcore/fsd_client.h @@ -6,13 +6,16 @@ #ifndef FSD_CLIENT_H #define FSD_CLIENT_H +#include #include #include #include #include -#include - +namespace BlackMisc +{ + class IContext; +} namespace FSD { @@ -32,7 +35,7 @@ class CFSDClient : public QObject Q_OBJECT public: - CFSDClient(); + CFSDClient(BlackMisc::IContext &context); void connectTo(const QString &host, quint16 port); void disconnectFrom(); @@ -107,6 +110,8 @@ private: void processLine(QString &line); + BlackMisc::IContext& m_context; + QTcpSocket* m_tcp_socket; QString m_host; diff --git a/src/blackcore/fsd_messages.cpp b/src/blackcore/fsd_messages.cpp index 6b4b59973..e8209d92a 100644 --- a/src/blackcore/fsd_messages.cpp +++ b/src/blackcore/fsd_messages.cpp @@ -1,6 +1,5 @@ -#include "blackmisc/debug.h" - #include "blackcore/fsd_messages.h" +#include "blackmisc/debug.h" using namespace BlackMisc; @@ -27,7 +26,7 @@ namespace FSD } else { - bError << "Cannot split message. Vector is to small"; + bAppError << "Cannot split message. Vector is to small"; return -1; } } @@ -84,7 +83,7 @@ namespace FSD { QString message = in.readAll(); qint32 size = unpack(message, m_message_tokens); - bAssert ( size == 10 ); + Q_ASSERT ( size == 10 ); return in; } diff --git a/src/blackcore/fsd_messages.h b/src/blackcore/fsd_messages.h index d60ad3f6a..d52d0fcdb 100644 --- a/src/blackcore/fsd_messages.h +++ b/src/blackcore/fsd_messages.h @@ -98,7 +98,7 @@ namespace FSD QString m_textmessage; for ( int ii = 2; ii < tokens.size(); ++ii) m_textmessage += tokens.at(ii); - bInfo << m_textmessage; + bAppInfo << m_textmessage; return in; } diff --git a/src/blackcore/matrix_3d.cpp b/src/blackcore/matrix_3d.cpp index 7494e0a6c..635e3c001 100644 --- a/src/blackcore/matrix_3d.cpp +++ b/src/blackcore/matrix_3d.cpp @@ -1,7 +1,7 @@ -#include -#include "blackmisc/debug.h" -#include "blackcore/vector_3d.h" #include "blackcore/matrix_3d.h" +#include "blackcore/vector_3d.h" +#include "blackmisc/debug.h" +#include /* TODO * @@ -112,14 +112,14 @@ void CMatrix3D::print() double CMatrix3D::getElement(qint8 row, qint8 column) const { - bAssert (row < 3 || column < 3); + Q_ASSERT (row < 3 || column < 3); return m[row][column]; } void CMatrix3D::setElement(qint8 row, qint8 column, double value) { - bAssert (row < 3 || column < 3); + Q_ASSERT (row < 3 || column < 3); m[row][column] = value; } diff --git a/src/blackcore/plane.cpp b/src/blackcore/plane.cpp index a082e2b90..6fc60d40c 100644 --- a/src/blackcore/plane.cpp +++ b/src/blackcore/plane.cpp @@ -1,7 +1,7 @@ +#include "blackcore/plane.h" #include "blackcore/interpolator.h" #include "blackcore/simulator.h" #include "blackmisc/debug.h" -#include "blackcore/plane.h" namespace BlackCore { @@ -15,13 +15,13 @@ namespace BlackCore { { m_interpolator = new CInterpolator(); - bAssert(m_interpolator); - bAssert(driver); + Q_ASSERT(m_interpolator); + Q_ASSERT(driver); } void CPlane::addPosition(const CVectorGeo &position, double groundVelocity, double heading, double pitch, double bank) { - bAssert(m_interpolator); + Q_ASSERT(m_interpolator); m_interpolator->pushUpdate(position, groundVelocity, heading, pitch, bank); } diff --git a/src/blackcore/plane.h b/src/blackcore/plane.h index 998aa9e75..90ec02502 100644 --- a/src/blackcore/plane.h +++ b/src/blackcore/plane.h @@ -12,6 +12,7 @@ namespace BlackCore { class ISimulator; class CInterpolator; + class CVectorGeo; class CPlane { diff --git a/src/blackcore/pluginmgr.cpp b/src/blackcore/pluginmgr.cpp new file mode 100644 index 000000000..ee86d592a --- /dev/null +++ b/src/blackcore/pluginmgr.cpp @@ -0,0 +1,104 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackcore/pluginmgr.h" +#include "blackmisc/plugins.h" +#include "blackmisc/context.h" +#include +#include + +namespace BlackCore +{ + + CPluginManager::~CPluginManager() + { + for (QVector::iterator it = m_plugins.begin(); it != m_plugins.end(); ++it) + { + Q_ASSERT_X(it->loader, "Plugin manager", "Previously loaded plugin's loader ptr is null"); + + it->loader->unload(); + } + } + + void CPluginManager::loadAllPlugins(const QString &pluginsPath) + { + //TODO should we use a custom extension, so we don't attempt to load non-plugin .dll/.so files? + #ifdef Q_OS_WIN + static const QStringList pluginsFilter("*.dll"); + #else + static const QStringList pluginsFilter("*.so"); + #endif + + QDirIterator iter (pluginsPath, pluginsFilter, QDir::Files); + while (iter.hasNext()) + { + QString filename = iter.next(); + + QSharedPointer loader (new QPluginLoader (filename)); + try + { + if (! loader->load()) + { + throw; + } + + PluginEntry entry; + entry.loader = loader; + entry.factory = qobject_cast(loader->instance()); + + if (! entry.factory) + { + throw; + } + + m_plugins.push_back(entry); + } + catch (...) + { + //TODO warning + } + } + } + + const CPluginManager::PluginEntry &CPluginManager::getEntry(size_t index) const + { + Q_ASSERT_X(index < getPluginCount(), "Plugin manager", "Plugin index out of bounds"); + + const PluginEntry &entry = m_plugins[index]; + + Q_ASSERT_X(entry.factory, "Plugin manager", "Previously loaded plugin's factory ptr is null"); + Q_ASSERT_X(entry.loader, "Plugin manager", "Previously loaded plugin's loader ptr is null"); + + if (! entry.loader->isLoaded()) + { + //TODO throw plugin loader unexpectedly unloaded + } + + return entry; + } + + const QString CPluginManager::getName(size_t index) const + { + return getFactory(index)->getName(); + } + + const QString CPluginManager::getDescription(size_t index) const + { + return getFactory(index)->getDescription(); + } + + BlackMisc::IPlugin *CPluginManager::constructPlugin(size_t index) + { + BlackMisc::IPlugin *plugin = getFactory(index)->create(BlackMisc::IContext::getInstance()); + if (! plugin->isValid()) + { + delete plugin; + plugin = 0; + //TODO throw plugin construction failed + } + return plugin; + } + +} // namespace BlackCore \ No newline at end of file diff --git a/src/blackcore/pluginmgr.h b/src/blackcore/pluginmgr.h new file mode 100644 index 000000000..e791d8ab8 --- /dev/null +++ b/src/blackcore/pluginmgr.h @@ -0,0 +1,136 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/*! + \file +*/ + +#ifndef BLACKCORE_PLUGINMGR_H +#define BLACKCORE_PLUGINMGR_H + +#include +#include +#include + +namespace BlackMisc +{ + class IPlugin; + class IPluginFactory; +} + +namespace BlackCore +{ + + /*! + Plugin manager. + Loads plugins and allows them to be queried and instantiated. + */ + class CPluginManager + { + public: + /*! + Destructor. + */ + virtual ~CPluginManager(); + + /*! + Attempt to load all plugins found at the given path. + \param pluginsPath + */ + void loadAllPlugins(const QString &pluginsPath); + + /*! + Return the total number of plugins loaded so far. + \return + */ + size_t getPluginCount() const + { + return m_plugins.size(); + } + + /*! + Return the name of a plugin. + \param index the plugin's index in the vector of plugins. + \return + */ + const QString getName(size_t index) const; + + /*! + Return the description of a plugin. + \param index the plugin's index in the vector of plugins. + \return + */ + const QString getDescription(size_t index) const; + + /*! + Construct a plugin. + \param index the plugin's index in the vector of plugins. + \return a pointer to the newly created plugin. + \warning You must release this pointer with IPluginFactory::destroy(). + */ + BlackMisc::IPlugin *constructPlugin(size_t index); + + /*! + Direct access to the factory. You don't usually need this. + \param index + \return + */ + BlackMisc::IPluginFactory *getFactory(size_t index) + { + return const_cast(static_cast(this)->getFactory(index)); + } + + /*! + Direct access to the factory. You don't usually need this. + \param index + \return + */ + const BlackMisc::IPluginFactory *getFactory(size_t index) const + { + return getEntry(index).factory; + } + + /*! + Direct access to the QPluginLoader. You don't usually need this. + \param index + \return + */ + QPluginLoader *getLoader(size_t index) + { + return const_cast(static_cast(this)->getLoader(index)); + } + + /*! + Direct access to the QPluginLoader. You don't usually need this. + \param index + \return + */ + const QPluginLoader *getLoader(size_t index) const + { + return getEntry(index).loader.data(); + } + + private: + class PluginEntry + { + public: + PluginEntry() : factory(0) {} + BlackMisc::IPluginFactory *factory; + QSharedPointer loader; + }; + + QVector m_plugins; + + PluginEntry &getEntry(size_t index) + { + return const_cast(static_cast(this)->getEntry(index)); + } + + const PluginEntry &getEntry(size_t index) const; + }; + +} // namespace BlackCore + +#endif //BLACKCORE_PLUGINMGR_H \ No newline at end of file diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index b4e68ebd5..495118829 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -52,18 +52,24 @@ namespace BlackCore { case FS9: { myLib.setFileName(SHARED_LIBRARY_NAME_FS9); - bAssertstr(myLib.load(), myLib.errorString()); - driverVersionMajor = (getDriverVersionMajor) myLib.resolve(DRIVER_VERSION_MAJOR); + if (! myLib.load()) + { + //TODO throw + } - if (driverVersionMajor != NULL) + driverVersionMajor = (getDriverVersionMajor) myLib.resolve(DRIVER_VERSION_MAJOR); + if (driverVersionMajor) { - bAssertstr(driverVersionMajor() == ISimulator::InterfaceVersionMajor, QString("Wrong version of the driver. Try to reinstall!")); + if (driverVersionMajor() != ISimulator::InterfaceVersionMajor) + { + //TODO throw + } } createDriver = (createISimulatorInstance) myLib.resolve(IDRV_CREATE_SIM_INTERFACE); if (createDriver) { - bInfo << "Loaded successfully shared library 'bb_driver_fs9'"; + bAppInfo << "Loaded successfully shared library 'bb_driver_fs9'"; result = createDriver(); } } @@ -71,38 +77,48 @@ namespace BlackCore { case FSX: myLib.setFileName(SHARED_LIBRARY_NAME_FSX); - bAssertstr(myLib.load(), myLib.errorString()); + if (! myLib.load()) + { + //TODO throw + } driverVersionMajor = (getDriverVersionMajor) myLib.resolve(DRIVER_VERSION_MAJOR); - - if (driverVersionMajor != NULL) + if (driverVersionMajor) { - bAssertstr(driverVersionMajor() == ISimulator::InterfaceVersionMajor, QString("Wrong version of the driver. Try to reinstall!")); + if (driverVersionMajor() != ISimulator::InterfaceVersionMajor) + { + //TODO throw + } } createDriver = (createISimulatorInstance) myLib.resolve(IDRV_CREATE_SIM_INTERFACE); if (createDriver) { - bInfo << "Loaded successfully shared library 'bb_driver_fsx'"; + bAppInfo << "Loaded successfully shared library 'bb_driver_fsx'"; result = createDriver(); } break; #endif case XPLANE: myLib.setFileName(SHARED_LIBRARY_NAME_XPLANE); - bAssertstr(myLib.load(), myLib.errorString()); + if (! myLib.load()) + { + //TODO throw + } driverVersionMajor = (getDriverVersionMajor) myLib.resolve(DRIVER_VERSION_MAJOR); - - if (driverVersionMajor != NULL) + if (driverVersionMajor) { - bAssertstr(driverVersionMajor() == ISimulator::InterfaceVersionMajor, QString("Wrong version of the driver. Try to reinstall!")); + if (driverVersionMajor() != ISimulator::InterfaceVersionMajor) + { + //TODO throw + } } createDriver = (createISimulatorInstance) myLib.resolve(IDRV_CREATE_SIM_INTERFACE); if (createDriver) { - bInfo << "Loaded successfully shared library 'bb_driver_xplane'"; + bAppInfo << "Loaded successfully shared library 'bb_driver_xplane'"; result = createDriver(); } break; diff --git a/src/blackcore/vector_3d.cpp b/src/blackcore/vector_3d.cpp index c25f0d8de..fd9b06f00 100644 --- a/src/blackcore/vector_3d.cpp +++ b/src/blackcore/vector_3d.cpp @@ -1,14 +1,12 @@ + +#include "blackcore/vector_3d.h" +#include "blackcore/matrix_3d.h" +#include "blackcore/vector_geo.h" +#include "blackcore/constants.h" +#include "blackmisc/debug.h" #include #include -#include "blackmisc/debug.h" - -#include "blackcore/matrix_3d.h" -#include "blackcore/vector_3d.h" -#include "blackcore/vector_geo.h" - -#include "blackcore/constants.h" - namespace BlackCore { @@ -59,7 +57,7 @@ double CVector3D::magnitude() double CVector3D::getElement(qint8 row) const { - bAssert(row < 3); + Q_ASSERT(row < 3); return v[row]; } diff --git a/src/blackd/blackd.cpp b/src/blackd/blackd.cpp index 603c679bb..0bf4ee96c 100644 --- a/src/blackd/blackd.cpp +++ b/src/blackd/blackd.cpp @@ -43,9 +43,9 @@ BlackD::BlackD(QWidget *parent) : createComServer(); - m_fsd_client = new CFSDClient(); + m_fsd_client = new CFSDClient(IContext::getInstance()); - bDebug << "BlackDaemon running..."; + bAppDebug << "BlackDaemon running..."; } BlackD::~BlackD() @@ -115,18 +115,17 @@ void BlackD::createLogging() BlackMisc::IContext::getInstance().getDebug()->create(); m_displayer = new CQtDisplayer(ui->logginView); - bAssert(m_displayer); + BlackMisc::IContext::getInstance().getDebug()->getDebugLog()->attachDisplay (m_displayer); BlackMisc::IContext::getInstance().getDebug()->getInfoLog()->attachDisplay (m_displayer); BlackMisc::IContext::getInstance().getDebug()->getWarningLog()->attachDisplay (m_displayer); - BlackMisc::IContext::getInstance().getDebug()->getAssertLog()->attachDisplay (m_displayer); BlackMisc::IContext::getInstance().getDebug()->getErrorLog()->attachDisplay (m_displayer); } void BlackD::createComServer() { CMessageFactory::getInstance().registerMessages(); - m_comserver = new CComServer(this); + m_comserver = new CComServer(IContext::getInstance(), this); registerMessageFunction(this, &BlackD::onMSG_CONNECT_TO_VATSIM); @@ -138,11 +137,11 @@ void BlackD::createComServer() void BlackD::onData(QString &messageID, QByteArray &message) { - bDebug << messageID; + bAppDebug << messageID; BlackMisc::IMessage* test = BlackMisc::CMessageFactory::getInstance().create(messageID); QDataStream stream(&message, QIODevice::ReadOnly); - bAssert (test); + Q_ASSERT(test); *test << stream; CMessageDispatcher::getInstance().append(test); @@ -151,8 +150,8 @@ void BlackD::onData(QString &messageID, QByteArray &message) void BlackD::onMSG_CONNECT_TO_VATSIM(const BlackMisc::MSG_CONNECT_TO_VATSIM *connect) { - bDebug << "Connecting to FSD server:"; - bDebug << connect->getHost() << ":" << connect->getPort(); + bAppDebug << "Connecting to FSD server:"; + bAppDebug << connect->getHost() << ":" << connect->getPort(); FSD::TClientInfo clientinfo; clientinfo.m_callsign = connect->getCallsign(); diff --git a/src/blackd/qt_displayer.cpp b/src/blackd/qt_displayer.cpp index fb0e02890..551461011 100644 --- a/src/blackd/qt_displayer.cpp +++ b/src/blackd/qt_displayer.cpp @@ -46,11 +46,11 @@ void CQtDisplayer::doPrint ( const BlackMisc::CLog::SLogInformation &logInformat needSpace = true; } - if (logInformation.m_logType != CLog::OFF) + if (logInformation.m_logType != CLog::eOff) { if (needSpace) { line += " "; needSpace = false; } line += logTypeToString(logInformation.m_logType); - if (logInformation.m_logType == BlackMisc::CLog::WARNING) + if (logInformation.m_logType == BlackMisc::CLog::eWarning) format.setForeground(QBrush(QColor("red"))); else format.setForeground(QBrush(QColor("black"))); diff --git a/src/blackmisc/com_client.cpp b/src/blackmisc/com_client.cpp index 1ed90c6a9..4efedff50 100644 --- a/src/blackmisc/com_client.cpp +++ b/src/blackmisc/com_client.cpp @@ -3,17 +3,17 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ +#include "blackmisc/com_client.h" +#include "blackmisc/context.h" +#include "blackmisc/debug.h" #include #include -#include "blackmisc/debug.h" -#include "blackmisc/com_client.h" - namespace BlackMisc { - CComClient::CComClient(QObject *parent) - : IComHandler(parent), m_tcp_socket(NULL), m_port(0) + CComClient::CComClient(IContext &context, QObject *parent) + : m_context(context), IComHandler(context, parent), m_tcp_socket(NULL), m_port(0) { init(); } @@ -32,21 +32,21 @@ namespace BlackMisc bool CComClient::init() { m_tcp_socket = new QTcpSocket(this); - bAssert(m_tcp_socket); + Q_ASSERT(m_tcp_socket); - bAssert ( QObject::connect( m_tcp_socket, SIGNAL( connected() ), this, SLOT( onConnected() ) ) ); - bAssert ( QObject::connect( m_tcp_socket, SIGNAL( disconnected() ), this, SLOT( onDisconnected() ) ) ); - bAssert ( QObject::connect( m_tcp_socket, SIGNAL( error(QAbstractSocket::SocketError) ), this, SLOT( onError(QAbstractSocket::SocketError) ) ) ); + Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( connected() ), this, SLOT( onConnected() ) ) ); + Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( disconnected() ), this, SLOT( onDisconnected() ) ) ); + Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( error(QAbstractSocket::SocketError) ), this, SLOT( onError(QAbstractSocket::SocketError) ) ) ); - bAssert ( QObject::connect( m_tcp_socket, SIGNAL( readyRead() ), this, SLOT( onReceivingData() ) ) ); + Q_ASSERT ( QObject::connect( m_tcp_socket, SIGNAL( readyRead() ), this, SLOT( onReceivingData() ) ) ); return true; } void CComClient::connectTo( const QString& hostName, quint16 port) { - bAssert ( ! hostName.isEmpty() ); - bAssert ( port > 0 ); + Q_ASSERT ( ! hostName.isEmpty() ); + Q_ASSERT ( port > 0 ); m_hostName = hostName; m_port = port; @@ -54,7 +54,7 @@ namespace BlackMisc if ( isConnected() ) return; - bDebug << "Connecting to host: " << hostName << ":" << port; + bDebug(m_context) << "Connecting to host: " << hostName << ":" << port; m_receive_buffer.clear(); @@ -69,7 +69,7 @@ namespace BlackMisc void CComClient::disconnectFrom() { - bDebug << "Disconnecting from host."; + bDebug(m_context) << "Disconnecting from host."; m_tcp_socket->disconnectFromHost(); m_port = 0; @@ -80,7 +80,7 @@ namespace BlackMisc { if (!isConnected()) { - bError << "Cannot send data in disconnected state!"; + bError(m_context) << "Cannot send data in disconnected state!"; return false; } @@ -91,7 +91,7 @@ namespace BlackMisc qint64 bytes = m_tcp_socket->write(m_sender_buffer); if (bytes < 0 || bytes != sender_buffer_size) { - bWarning << "Error writing to socket!"; + bWarning(m_context) << "Error writing to socket!"; return false; } @@ -149,13 +149,13 @@ namespace BlackMisc void CComClient::onConnected() { - bDebug << "Connected successfully to remote host."; + bDebug(m_context) << "Connected successfully to remote host."; emit doConnected(); } void CComClient::onDisconnected() { - bDebug << "Disconnected successfully from remote host."; + bDebug(m_context) << "Disconnected successfully from remote host."; emit doDisconnected(); } @@ -163,7 +163,7 @@ namespace BlackMisc { if ( error != 0 ) { - bError << "Received socket error: " << error << " - Disconnecting..."; + bError(m_context) << "Received socket error: " << error << " - Disconnecting..."; } disconnect(); diff --git a/src/blackmisc/com_client.h b/src/blackmisc/com_client.h index f8fa60a6b..0ba9b02df 100644 --- a/src/blackmisc/com_client.h +++ b/src/blackmisc/com_client.h @@ -6,16 +6,17 @@ #ifndef COM_CLIENT_H #define COM_CLIENT_H +#include "blackmisc/com_handler.h" #include #include -#include "blackmisc/com_handler.h" - class QTcpSocket; namespace BlackMisc { + class IContext; + class CComClient : public IComHandler { Q_OBJECT @@ -26,7 +27,7 @@ public: /*! \param parent Pointer to the parent QObject */ - CComClient(QObject *parent = 0); + CComClient(IContext &context, QObject *parent = 0); //! Destructor ~CComClient(); @@ -89,6 +90,9 @@ protected slots: //! Call this slot, when data has been received void onReceivingData(); +private: + IContext& m_context; + protected: //! TCP Socket diff --git a/src/blackmisc/com_client_buffer.cpp b/src/blackmisc/com_client_buffer.cpp index 412fa06d7..ef2b26b8a 100644 --- a/src/blackmisc/com_client_buffer.cpp +++ b/src/blackmisc/com_client_buffer.cpp @@ -3,17 +3,16 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ -#include - -#include "blackmisc/debug.h" - #include "blackmisc/com_client_buffer.h" +#include "blackmisc/debug.h" +#include "blackmisc/context.h" +#include namespace BlackMisc { - CComClientBuffer::CComClientBuffer(uint clientID, QTcpSocket *socket, QObject *parent) - : m_client_id(clientID), m_tcp_socket(socket), IComHandler(parent) + CComClientBuffer::CComClientBuffer(IContext &context, uint clientID, QTcpSocket *socket, QObject *parent) + : m_context(context), m_client_id(clientID), m_tcp_socket(socket), IComHandler(context, parent) { connect(m_tcp_socket, SIGNAL(readyRead()), this, SLOT(onReceivingData())); connect(m_tcp_socket, SIGNAL(disconnected()), this, SLOT(onClientDisconnected())); @@ -32,7 +31,7 @@ namespace BlackMisc qint64 bytes = m_tcp_socket->write(m_sender_buffer); if (bytes < 0 || bytes != sender_buffer_size) { - bWarning << "Error writing to socket!"; + bWarning(m_context) << "Error writing to socket!"; return false; } @@ -53,7 +52,7 @@ namespace BlackMisc void CComClientBuffer::onClientDisconnected() { - bInfo << "Client disconnected!"; + bInfo(m_context) << "Client disconnected!"; emit doDisconnected(m_client_id); } diff --git a/src/blackmisc/com_client_buffer.h b/src/blackmisc/com_client_buffer.h index e83772835..63c78b79d 100644 --- a/src/blackmisc/com_client_buffer.h +++ b/src/blackmisc/com_client_buffer.h @@ -6,21 +6,22 @@ #ifndef COM_CLIENT_BUFFER_H #define COM_CLIENT_BUFFER_H -#include - #include "blackmisc/com_handler.h" +#include class QTcpSocket; namespace BlackMisc { + class IContext; + class CComClientBuffer : public IComHandler { Q_OBJECT public: - CComClientBuffer(uint clientID, QTcpSocket *socket, QObject *parent = 0); + CComClientBuffer(IContext &context, uint clientID, QTcpSocket *socket, QObject *parent = 0); virtual ~CComClientBuffer(); @@ -43,6 +44,7 @@ namespace BlackMisc protected: + IContext& m_context; QTcpSocket* m_tcp_socket; uint m_client_id; diff --git a/src/blackmisc/com_handler.cpp b/src/blackmisc/com_handler.cpp index 2f582ae13..ec87385d7 100644 --- a/src/blackmisc/com_handler.cpp +++ b/src/blackmisc/com_handler.cpp @@ -3,18 +3,17 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ +#include "blackmisc/com_handler.h" +#include "blackmisc/debug.h" #include #include -#include "blackmisc/debug.h" - -#include "blackmisc/com_handler.h" - namespace BlackMisc { - IComHandler::IComHandler(QObject *parent) : - QObject(parent) + IComHandler::IComHandler(IContext &context, QObject *parent) : + QObject(parent), + m_context(context) { } @@ -44,7 +43,7 @@ namespace BlackMisc if (m_receive_buffer.size() < min_size) { - bDebug << "Received data is to small to read SYNC and frame length!"; + bDebug(m_context) << "Received data is to small to read SYNC and frame length!"; return false; } @@ -66,7 +65,7 @@ namespace BlackMisc if (!found_sync) { - bWarning << "Could not find sync pattern in the stream. Discarding all data!"; + bWarning(m_context) << "Could not find sync pattern in the stream. Discarding all data!"; m_receive_buffer.clear(); return false; } @@ -92,7 +91,7 @@ namespace BlackMisc if (m_receive_buffer.size() < (total_length + (int)sizeof (quint16))) { - bDebug << "Received data is to small to read data block!"; + bDebug(m_context) << "Received data is to small to read data block!"; return false; } @@ -103,8 +102,8 @@ namespace BlackMisc data.resize(message_length); qint32 bytes = stream.readRawData(data.data(), message_length); - bAssert (bytes == message_length); - bAssert (data.size() == message_length); + Q_ASSERT (bytes == message_length); + Q_ASSERT (data.size() == message_length); quint16 crc_calc = qChecksum (data.constData(), data.size()); quint16 crc_recv = 0; @@ -116,7 +115,7 @@ namespace BlackMisc if (crc_calc != crc_recv) { - bWarning << "Message CRC error!"; + bWarning(m_context) << "Message CRC error!"; data.clear(); return false; } diff --git a/src/blackmisc/com_handler.h b/src/blackmisc/com_handler.h index 913e50635..ec7d28e2d 100644 --- a/src/blackmisc/com_handler.h +++ b/src/blackmisc/com_handler.h @@ -14,6 +14,8 @@ const qint32 Sync_Marker = 0x1ACFFC1D; namespace BlackMisc { + class IContext; + //! IComHandler Interface. /*! This interface implements the basic class for every InterCommunikation @@ -30,7 +32,7 @@ namespace BlackMisc /*! \param parent Pointer to the parent QObject */ - explicit IComHandler(QObject *parent = 0); + IComHandler(IContext &context, QObject *parent = 0); //! Virtual destructor virtual ~IComHandler() {} @@ -53,6 +55,9 @@ namespace BlackMisc */ bool parseFrame(QString &messageID, QByteArray &data); + //! Context. + IContext &m_context; + //! Receive Buffer /*! Data received from the TCP socket, will stored in here. diff --git a/src/blackmisc/com_server.cpp b/src/blackmisc/com_server.cpp index 85a7aee1c..b8a9d1347 100644 --- a/src/blackmisc/com_server.cpp +++ b/src/blackmisc/com_server.cpp @@ -3,18 +3,18 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ +#include "blackmisc/com_server.h" +#include "blackmisc/com_client_buffer.h" +#include "blackmisc/debug.h" +#include "blackmisc/context.h" #include #include -#include "blackmisc/debug.h" -#include "blackmisc/com_client_buffer.h" -#include "blackmisc/com_server.h" - namespace BlackMisc { -CComServer::CComServer(QObject *parent) - : QObject(parent), m_tcp_server(NULL), m_port(0) +CComServer::CComServer(IContext &context, QObject *parent) + : m_context(context), QObject(parent), m_tcp_server(NULL), m_port(0) { init(); } @@ -37,8 +37,8 @@ CComServer::~CComServer() bool CComServer::init() { m_tcp_server = new QTcpServer(this); - bAssert (m_tcp_server); - bAssert ( QObject::connect(m_tcp_server, SIGNAL(newConnection()), this, SLOT(onIncomingConnection()) ) ); + Q_ASSERT (m_tcp_server); + Q_ASSERT ( QObject::connect(m_tcp_server, SIGNAL(newConnection()), this, SLOT(onIncomingConnection()) ) ); return true; } @@ -47,17 +47,17 @@ void CComServer::Host(const QHostAddress &address, const quint16 port) { if (isHosting()) return; - bAssert ( ! address.isNull() ); - bAssert ( port > 0 ); + Q_ASSERT ( ! address.isNull() ); + Q_ASSERT ( port > 0 ); if ( !m_tcp_server->listen(address, port) ) { - bError << "Hosting failed"; + bError(m_context) << "Hosting failed"; emit doHostClosed(); } else { - bDebug << "Hosting successfull"; + bDebug(m_context) << "Hosting successfull"; emit doHosting(); } } @@ -76,7 +76,7 @@ void CComServer::sendToClient( const uint clientID, const QString &messageID, co { if (!m_client_buffers.contains(clientID)) { - bWarning << "Cannot send data to client - unknown client!"; + bWarning(m_context) << "Cannot send data to client - unknown client!"; return; } m_client_buffers.value(clientID)->sendMessage(messageID, data); @@ -105,8 +105,8 @@ void CComServer::onIncomingConnection() uint clientID = qHash(socket); // Create new ClientBuffer object. This new object gets the owner of the socket - CComClientBuffer* clientbuf = new CComClientBuffer (clientID, socket,this); - bAssert(clientbuf); + CComClientBuffer* clientbuf = new CComClientBuffer (m_context, clientID, socket,this); + Q_ASSERT(clientbuf); connect(clientbuf, SIGNAL(doDisconnected(uint)), this, SLOT(onClientDisconnected(uint))); connect(clientbuf, SIGNAL(doReceivedMessage(uint, QString&, QByteArray&)), this, SLOT(onClientMessageReceived(uint, QString&, QByteArray&))); @@ -121,7 +121,7 @@ void CComServer::onClientDisconnected(uint clientID) { if ( !m_client_buffers.contains(clientID)) { - bWarning << "Disconnected unknown client!"; + bWarning(m_context) << "Disconnected unknown client!"; return; } diff --git a/src/blackmisc/com_server.h b/src/blackmisc/com_server.h index 4ca0cd3b4..81b1cb7ee 100644 --- a/src/blackmisc/com_server.h +++ b/src/blackmisc/com_server.h @@ -12,11 +12,12 @@ class QTcpServer; -class CComClientBuffer; - namespace BlackMisc { + class CComClientBuffer; + class IContext; + class CComServer : public QObject { Q_OBJECT @@ -25,9 +26,10 @@ namespace BlackMisc //! Constructor /*! + \param context \param parent Pointer to the parent QObject */ - CComServer(QObject *parent = 0); + CComServer(IContext &context, QObject *parent = 0); //! Destructor ~CComServer(); @@ -90,6 +92,8 @@ namespace BlackMisc protected: + IContext& m_context; + QTcpServer* m_tcp_server; QHostAddress m_address; diff --git a/src/blackmisc/config.cpp b/src/blackmisc/config.cpp index 5c23f94dd..408746336 100644 --- a/src/blackmisc/config.cpp +++ b/src/blackmisc/config.cpp @@ -3,12 +3,11 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ +#include "blackmisc/config.h" +#include "blackmisc/debug.h" #include #include -#include "blackmisc/debug.h" -#include "blackmisc/config.h" - namespace BlackMisc { CValue::CValue() : _type(CONFIG_UNKOWN), _value(""), _int_value(0), @@ -112,11 +111,9 @@ namespace BlackMisc return _bool_value; } - CConfig::CConfig(const QString& filename, const QString& separator, bool isRelative) + CConfig::CConfig(IContext &context, const QString& filename, const QString& separator, bool /*isRelative*/) + : m_context(context), m_configfile(filename), m_separator(separator) { - m_configfile = filename; - m_separator = separator; - Q_UNUSED(isRelative); } bool CConfig::load() @@ -132,13 +129,13 @@ namespace BlackMisc if (m_configfile.isEmpty()) { - bError << "Can't open emtpy config file!"; + bError(m_context) << "Can't open emtpy config file!"; return false; } QFile input (m_configfile); if ( !input.open(QIODevice::ReadOnly)) { - bError << "Failed to open config file !" << m_configfile; + bError(m_context) << "Failed to open config file !" << m_configfile; input.close(); return false; } @@ -170,7 +167,7 @@ namespace BlackMisc QStringList tags = line.split(m_separator); if ( tags.count() != 2) { - bWarning << "Could not parse line " << no_line << " in file " << m_configfile << "!"; + bWarning(m_context) << "Could not parse line " << no_line << " in file " << m_configfile << "!"; error = true; continue; } @@ -234,7 +231,7 @@ namespace BlackMisc for (it = m_value_map.begin(); it != m_value_map.end(); ++it) { CValue value = it.value(); - bDebug << "Key: " << it.key() << " - Value: " << value.asString(); + bDebug(m_context) << "Key: " << it.key() << " - Value: " << value.asString(); } } diff --git a/src/blackmisc/config.h b/src/blackmisc/config.h index 4661ef6c0..9dc0bdb1d 100644 --- a/src/blackmisc/config.h +++ b/src/blackmisc/config.h @@ -8,10 +8,13 @@ #include #include +#include namespace BlackMisc { + class IContext; + class CValue { public: @@ -59,12 +62,13 @@ namespace BlackMisc //! Configuration class. /*! This class implements the configuration part of the library. + \warning it is not safe to use this from within */ class CConfig { public: - CConfig(const QString& filename, const QString& separator = "=", bool isRelative = false); + CConfig(IContext &context, const QString& filename, const QString& separator = "=", bool isRelative = false); //! Sets the value of the specified key. /*! @@ -151,6 +155,7 @@ namespace BlackMisc protected: + IContext &m_context; QString m_configfile; QString m_separator; typedef QMap TValueMap; diff --git a/src/blackmisc/config_manager.cpp b/src/blackmisc/config_manager.cpp index 57cc5da53..b8748e13e 100644 --- a/src/blackmisc/config_manager.cpp +++ b/src/blackmisc/config_manager.cpp @@ -1,23 +1,26 @@ -#include -#include - - +#include "blackmisc/config_manager.h" #include "blackmisc/config.h" #include "blackmisc/debug.h" -#include "blackmisc/config_manager.h" +#include +#include namespace BlackMisc { SINGLETON_CLASS_IMPLEMENTATION(CConfigManager) + + CConfigManager::CConfigManager() + : m_context(IContext::getInstance()) + { + } - CConfigManager::CConfigManager() + CConfigManager::CConfigManager(IContext &context) + : m_context(context) { } void CConfigManager::setConfigPath(QString path) { m_config_path = QDir(path).absolutePath(); - } int CConfigManager::readConfig(bool forceReload) @@ -48,7 +51,7 @@ namespace BlackMisc if (!m_config_map.contains(section)) { QString filePath = m_config_path + QDir::separator() + (*constIterator); - CConfig *config = new CConfig(filePath); + CConfig *config = new CConfig(m_context, filePath); config->load(); m_config_map.insert(section, config); @@ -86,7 +89,8 @@ namespace BlackMisc return m_config_map.value(section); else { - bError << "Could not find config section: " << section; + //@@@ should we throw an exception here? + bAppError << "Could not find config section: " << section; return NULL; } } diff --git a/src/blackmisc/config_manager.h b/src/blackmisc/config_manager.h index 6bac64ae2..43cfaba8b 100644 --- a/src/blackmisc/config_manager.h +++ b/src/blackmisc/config_manager.h @@ -3,8 +3,8 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ -#ifndef CONFIGMANAGER_H -#define CONFIGMANAGER_H +#ifndef BLACKMISC_CONFIGMANAGER_H +#define BLACKMISC_CONFIGMANAGER_H #include #include @@ -16,13 +16,26 @@ namespace BlackMisc class CConfig; - class CConfigManager + class CConfigManager : public QObject { + Q_OBJECT + // safe singleton declaration SINGLETON_CLASS_DECLARATION(CConfigManager) - CConfigManager(); public: + /*! + Default constructor. + \deprecated Do not use. + \todo Remove this when removing SINGLETON_CLASS_DECLARATION. + */ + CConfigManager(); + + /*! + Constructor. + \param context + */ + CConfigManager(IContext &context); //! Configuration Manager error codes. /*! This enum lists all errors, which can appear. If you need @@ -47,6 +60,8 @@ namespace BlackMisc CConfig *getConfig(const QString §ion); private: + + IContext &m_context; typedef QMap TConfigMap; TConfigMap m_config_map; @@ -56,4 +71,4 @@ namespace BlackMisc }; } // namespace BlackLib -#endif // CONFIGMANAGER_H +#endif // BLACKMISC_CONFIGMANAGER_H diff --git a/src/blackmisc/context.cpp b/src/blackmisc/context.cpp index 5f107831f..7ab4e673b 100644 --- a/src/blackmisc/context.cpp +++ b/src/blackmisc/context.cpp @@ -5,109 +5,89 @@ #include "blackmisc/debug.h" #include "blackmisc/context.h" +#include +#include + +#ifdef Q_OS_WIN +#include +#endif namespace BlackMisc { - IContext *IContext::m_context = NULL; - IContext &IContext::getInstance() { - if (m_context == NULL) - { - m_context = new CApplicationContext; - } - return *m_context; + static CApplicationContext context; + return context; } - bool IContext::isInitialised() - { - return m_context != NULL; - } - - IContext::~IContext() { - m_context = NULL; - } - - void IContext::registerContext() - { - #ifdef Q_OS_WIN - bAssert(m_context == NULL); - #endif // Q_OS_WIN - m_context = this; - - m_debug = new CDebug; } CApplicationContext::CApplicationContext() { - registerContext(); } - void *CApplicationContext::singletonPointer(const QString &singletonName) + QObject *CApplicationContext::singleton(const QString &singletonName) { - TSingletonMap::const_iterator it = m_singletonObjects.find(singletonName); - if (it != m_singletonObjects.end()) + TSingletonMap::const_iterator it = m_singletons.find(singletonName); + if (it != m_singletons.end()) + { return it.value(); - - return NULL; + } + throw std::logic_error("Requested singleton not present"); } - void CApplicationContext::setSingletonPointer(const QString &singletonName, void *object) + bool CApplicationContext::hasSingleton(const QString &singletonName) const { - m_singletonObjects.insert(singletonName, object); + TSingletonMap::const_iterator it = m_singletons.find(singletonName); + if (it != m_singletons.end()) + { + return true; + } + return false; } - void CApplicationContext::releaseSingletonPointer(const QString &singletonName, void *object) + void CApplicationContext::setSingleton(const QString &singletonName, QObject *object) { - bAssert (m_singletonObjects.find(singletonName).value() == object); - m_singletonObjects.remove(singletonName); + m_singletons.insert(singletonName, object); + } + + void CApplicationContext::releaseSingleton(const QString &singletonName) + { + m_singletons.remove(singletonName); } CDebug *CApplicationContext::getDebug() { - return m_debug; + return qobject_cast(singleton("CDebug")); } void CApplicationContext::setDebug(CDebug *debug) { - m_debug = debug; + setSingleton("CDebug", debug); } - CLibraryContext::CLibraryContext(IContext &applicationContext) - : m_applicationContext(&applicationContext) + void CApplicationContext::setDefaultApplicationName() { - registerContext(); - } - - void *CLibraryContext::singletonPointer(const QString &singletonName) - { - bAssert(m_applicationContext != NULL); - return m_applicationContext->singletonPointer(singletonName); - } - - void CLibraryContext::setSingletonPointer(const QString &singletonName, void *object) - { - bAssert(m_applicationContext != NULL); - m_applicationContext->setSingletonPointer(singletonName, object); - } - - void CLibraryContext::releaseSingletonPointer(const QString &singletonName, void *object) - { - bAssert(m_applicationContext != NULL); - m_applicationContext->releaseSingletonPointer(singletonName, object); - } - - CDebug *CLibraryContext::getDebug() - { - return m_applicationContext->getDebug(); - } - - void CLibraryContext::setDebug(CDebug *debug) - { - m_debug = debug; +#ifdef Q_OS_WIN + //! By default, we use the executables name. + if (getApplicationName().isEmpty()) + { + WCHAR name[1024]; + int size = GetModuleFileName(NULL, name, 1023); + QString applicationPath = QString::fromWCharArray(name, size); + setApplicationName(QFileInfo(applicationPath).fileName()); + } +#else + //! Todo: Check if there a corresponding API in Linux and Mac + //! For the time being, set it to unknown. + if (m_context.getApplicationName().isEmpty()) + { + m_context.setApplicationName(""); + } +#endif } } // namespace BlackMisc diff --git a/src/blackmisc/context.h b/src/blackmisc/context.h index a8ddc73ff..de2c3ab9c 100644 --- a/src/blackmisc/context.h +++ b/src/blackmisc/context.h @@ -3,247 +3,224 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ -#ifndef CONTEXT_H -#define CONTEXT_H +#ifndef BLACKMISC_CONTEXT_H +#define BLACKMISC_CONTEXT_H +#include #include namespace BlackMisc { - class CLog; + class CDebug; - //! IContext Interface. - /*! - This interface abstracts any application and library context. Use it to - add singleton classes and for application and library wide logging. - */ - class IContext - { - public: - - //! Reference to IConext. - /*! - This static function returns a reference to the singleton object. - Use always this method to retrieve the context, since you cannot - instantiate your own one. Before it can be used you have to create - either a CApplicationContext or a CLibraryContext in the very - beginning of the executable/libary. - */ - static IContext &getInstance(); - - //! Returns true if the context is initialized and ready. - /*! - \return Returns true if context is initialized, otherwise false. - */ - static bool isInitialised(); - - //! Destructor. - /*! - Destroys the context. - */ - virtual ~IContext(); - - //! Pure virtual method returns the pointer to singletone object by its name. - /*! - \param singletonName a reference to the singletones name. - \return Returns a pointer to the singleton object. - */ - virtual void *singletonPointer(const QString &singletonName) = 0; - - //! Pure virtual method sets the singletone pointer, given by its name. - /*! - \param singletonName a reference to the singletones name. - \param object a pointer to the singletone object. - */ - virtual void setSingletonPointer(const QString &singletonName, void *object) = 0; - - //! Deallocates the object and removes the singletone pointer from the context map. - /*! - \param singletonName a reference to the singletones name. - \param object a pointer to the singletone object. - */ - virtual void releaseSingletonPointer(const QString &singletonName, void *object) = 0; - - //! Pure virtual method returns the pointer to debug object - /*! - \return Pointer to CDebug object - */ - virtual CDebug *getDebug() = 0; - - //! Pure virtual function to set the global error log object - /*! - \param Pointer to CDebug object - */ - virtual void setDebug(CDebug *debug) = 0; - - protected: - //! Method to register the context. - /*! This method should be called by the derived class. It sets the - context variable to the calling object.*/ - /*! - \param Pointer to CLog object - */ - void registerContext(); - - //! Pointer to the global context. - /*! - This variable holds a pointer to the application context. - */ - static IContext *m_context; - - //! Pointer to the global Debug object. - /*! - This member variable contains all logging types, not only debug. - */ - CDebug *m_debug; - - }; - - //! CApplicationContext. - /*! - This class implements the IContext interface for applications. - */ - class CApplicationContext : public IContext - { - public: - CApplicationContext(); - - //! This method returns the pointer to singletone object by its name. - /*! - \param singletonName a reference to the singletones name. - \return Returns a pointer to the singleton object. - */ - virtual void *singletonPointer(const QString &singletonName); - - //! Sets the singletone pointer, given by its name. - /*! - \param singletonName a reference to the singletones name. - \param object a pointer to the singletone object. - */ - virtual void setSingletonPointer(const QString &singletonName, void *object); - - //! Deallocates the object and removes the singletone pointer from the context map. - /*! - \param singletonName a reference to the singletones name. - \param object a pointer to the singletone object. - */ - virtual void releaseSingletonPointer(const QString &singletonName, void *ptr); - - //! Pure virtual method returns the pointer to debug object + /*! + Keeps track of all singleton and pseudo-singleton objects. + */ + class IContext + { + public: /*! - \return Pointer to CDebug object + Returns a reference to the static global context singleton. + \return + \warning Do not use this from within a plugin. */ - virtual CDebug *getDebug(); + static IContext &getInstance(); - //! Pure virtual function to set the global error log object /*! - \param Pointer to CDebug object + Destructor. */ - virtual void setDebug(CDebug *debug); + virtual ~IContext(); - private: - //! Typedef for the singleton map - typedef QMap TSingletonMap; - - //! Map of all registered objects inside the application. - /*! - This map holds associates all registered singleton objects to their names. - */ - TSingletonMap m_singletonObjects; - }; - - //! CApplicationContext. - /*! - This class implements the IContext interface for libraries. - */ - class CLibraryContext : public IContext - { - public: - CLibraryContext (IContext &application); - - //! This method returns the pointer to singletone object by its name. - /*! - \param singletonName a reference to the singletones name. - \return Returns a pointer to the singleton object. - */ - virtual void *singletonPointer(const QString &singletonName); - - //! Sets the singletone pointer, given by its name. - /*! - \param singletonName a reference to the singletones name. - \param object a pointer to the singletone object. - */ - virtual void setSingletonPointer(const QString &singletonName, void *ptr); - - //! Deallocates the object and removes the singletone pointer from the context map. - /*! - \param singletonName a reference to the singletones name. - \param object a pointer to the singletone object. - */ - virtual void releaseSingletonPointer(const QString &singletonName, void *ptr); - - //! Pure virtual method returns the pointer to debug object /*! - \return Pointer to CDebug object + Returns the pointer to a singleton object by its name. + You usually use the template overload of this method instead. + \param singletonName + \return + \throw std::logic_error The requested singleton is not present. */ - virtual CDebug *getDebug(); + virtual QObject *singleton(const QString &singletonName) = 0; - //! Pure virtual function to set the global error log object /*! - \param Pointer to CDebug object + Returns true if a singleton object with the give name is present. + You usually use the template overload of this method instead. + \param singletonName + \return */ - virtual void setDebug(CDebug *debug); - - private: - //! Pointer the application context. - /*! - Libraries do not have their own context, because they are using - the one from the linked application. - */ - IContext *m_applicationContext; - }; + virtual bool hasSingleton(const QString &singletonName) const = 0; + + /*! + Sets a singleton pointer, given by its name. + You usually use the template overload of this method instead. + \param singletonName + \param object + */ + virtual void setSingleton(const QString &singletonName, QObject *object) = 0; + + /*! + Removes the singleton pointer, given by its name. + You usually use the template overload of this method instead. + \param singletonName + \param object + */ + virtual void releaseSingleton(const QString &singletonName) = 0; + + /*! + Return the singleton pointer with the type T. + \tparam T An interface defined with the BLACK_INTERFACE macro. + \return + \throw std::logic_error The requested singleton is not present. + */ + template + T *singleton() + { + QObject *qobj = singleton(T::blackInterfaceId()); + T *t = qobject_cast(qobj); + Q_ASSERT_X(t, "IContext", "qobject_cast failed"); + return t; + } + + /*! + Return true if the requested singleton in present in the context. + \tparam T An interface defined with the BLACK_INTERFACE macro. + \return + */ + template + bool hasSingleton() const + { + return hasSingleton(T::blackInterfaceId()); + } + + /*! + Set the singleton pointer with the type T. + \tparam T An interface defined with the BLACK_INTERFACE macro. + \param object + */ + template + void setSingleton(T *object) + { + setSingleton(T::blackInterfaceId(), object); + } + + /*! + Remove the singleton pointer with the type T. + \tparam T An interface defined with the BLACK_INTERFACE macro. + */ + template + void releaseSingleton() + { + releaseSingleton(T::blackInterfaceId()); + } + + /*! + Set the global name of the application. + \param appName + */ + virtual void setApplicationName(const QString &appName) = 0; + + /*! + Set the application name to the default. + */ + virtual void setDefaultApplicationName() = 0; + + /*! + Return the global name of the application. + \return + */ + virtual const QString &getApplicationName() const = 0; + + /*! + Return the CDebug singleton. + \return + \deprecated Use getSingletonPointer() instead. + \throw std::logic_error The requested singleton is not present. + */ + virtual CDebug *getDebug() = 0; + + /*! + Set the CDebug singleton. + \param debug + \deprecated Use setSingletonPointer() instead. + */ + virtual void setDebug(CDebug *debug) = 0; + }; /*! - This macros helps to create the body of a singletone class, - which registers itself with the application context. - */ - #define SINGLETON_CLASS_DECLARATION(className) \ - private:\ - /* Singletone class constructor */ \ - className (const className &) {}\ - /* the local static pointer to the singleton instance */ \ - static className *m_instance; \ - public:\ - static className &getInstance() \ + Enable an interface to be manipulated with the template methods of IContext. + Put this macro in the public section of the interface definition. + \param FQNAME The fully qualified name of the interface (e.g. BlackMisc::IWhatever). + */ +#define BLACK_INTERFACE(FQNAME) static const char *blackInterfaceId() { return #FQNAME ; } + + /*! + Default implementation of the IContext interface. + */ + class CApplicationContext : public IContext + { + public: + /*! + Constructor + */ + CApplicationContext(); + + virtual QObject *singleton(const QString &singletonName); + virtual bool hasSingleton(const QString &singletonName) const; + virtual void setSingleton(const QString &singletonName, QObject *object); + virtual void releaseSingleton(const QString &singletonName); + virtual CDebug *getDebug(); + virtual void setDebug(CDebug *debug); + virtual void setApplicationName(const QString &applicationName) { m_appName = applicationName; } + virtual void setDefaultApplicationName(); + virtual const QString &getApplicationName() const { return m_appName; } + + private: + typedef QMap TSingletonMap; + + TSingletonMap m_singletons; + + QString m_appName; + }; + + /*! + This macros helps to create the body of a singletone class, + which registers itself with the application context. + \warning Singletons defined with this macro will not be accessible in plugins. + \deprecated Preferred way is, during application initialization, + construct singletons and register them manually, + and when you want to access them, do it through the IContext. + */ +#define SINGLETON_CLASS_DECLARATION(className) \ +private:\ + /* Forbid copying */ \ + className (const className &); \ + className &operator= (const className &); \ + /* the local static pointer to the singleton instance */ \ + static className *m_instance; \ +public:\ + static className &getInstance() \ + { \ + if (m_instance == NULL) \ + { \ + /* Get the singleton object from the context, if there is one */ \ + if (BlackMisc::IContext::getInstance().hasSingleton(#className)) \ { \ - if (m_instance == NULL) \ - { \ - /* We need a valid context.*/ \ - bAssertstr(BlackMisc::IContext::isInitialised(), QString("You are trying to access a singleton without having initialized a context. The simplest correction is to add 'BlackMisc::CApplicationContext myApplicationContext;' at the very beginning of your application.")); \ - \ - /* Get the singleton object from the context, if there is one */ \ - void *object = BlackMisc::IContext::getInstance().singletonPointer(#className); \ - if (object == NULL) \ - { \ - /* We have no allocated object yet, so do it now. */ \ - m_instance = new className; \ - BlackMisc::IContext::getInstance().setSingletonPointer(#className, m_instance); \ - } \ - else \ - { \ - /* Always use the c++ methods instead of casting the C way. */ \ - m_instance = reinterpret_cast(object); \ - } \ - } \ - return *m_instance; \ + m_instance = reinterpret_cast(BlackMisc::IContext::getInstance().singleton(#className)); \ } \ - private: - /* Put your class constructor directly after this makro and make sure it is private! */ - - - #define SINGLETON_CLASS_IMPLEMENTATION(className) className *className::m_instance = NULL; + else \ + { \ + /* We have no allocated object yet, so do it now. */ \ + m_instance = new className; \ + BlackMisc::IContext::getInstance().setSingleton(#className, m_instance); \ + } \ + } \ + return *m_instance; \ + } \ +private: + /* Put your class constructor directly after this makro and make sure it is private! */ + + +#define SINGLETON_CLASS_IMPLEMENTATION(className) className *className::m_instance = NULL; } // namespace BlackMisc -#endif CONTEXT_H +#endif //BLACKMISC_CONTEXT_H diff --git a/src/blackmisc/debug.cpp b/src/blackmisc/debug.cpp index a58108b02..f260e46a0 100644 --- a/src/blackmisc/debug.cpp +++ b/src/blackmisc/debug.cpp @@ -1,91 +1,72 @@ +#include "blackmisc/debug.h" +#include "blackmisc/log.h" +#include "blackmisc/display.h" #include #include -#include "blackmisc/log.h" -#include "blackmisc/debug.h" -#include "blackmisc/display.h" namespace BlackMisc { CDebug::CDebug() : m_isInitialized(false), m_errorLog(NULL), m_warningLog(NULL), - m_infoLog(NULL), m_debugLog(NULL), m_assertLog(NULL) + m_infoLog(NULL), m_debugLog(NULL) { } - void CDebug::create (const char *logPath, bool logInFile, bool eraseLastLog) - { - if (!m_isInitialized) - { - setErrorLog(new CLog (CLog::ERROR)); - setWarningLog(new CLog (CLog::WARNING)); - setInfoLog(new CLog (CLog::INFO)); - setDebugLog(new CLog (CLog::DEBUG)); - setAssertLog(new CLog (CLog::ASSERT)); + void CDebug::create(const char *logPath, bool logInFile, bool eraseLastLog) + { + if (!m_isInitialized) + { + setErrorLog(new CLog(IContext::getInstance(), CLog::eError)); + setWarningLog(new CLog(IContext::getInstance(), CLog::eWarning)); + setInfoLog(new CLog(IContext::getInstance(), CLog::eInfo)); + setDebugLog(new CLog(IContext::getInstance(), CLog::eDebug)); - stdDisplayer = new CStdDisplay ("DEFAULT_SD"); + stdDisplayer = new CStdDisplay("DEFAULT_SD"); - if (logInFile) - { + if (logInFile) + { QDir fileinfo(m_logPath); - QString fn; - if ( !m_logPath.isEmpty() ) - { - m_logPath = fileinfo.absolutePath(); - fn += m_logPath; - } - else - { - } + QString fn; + if (!m_logPath.isEmpty()) + { + m_logPath = fileinfo.absolutePath(); + fn += m_logPath; + } + else + { + } - fileDisplayer = new CFileDisplay ("", true, "DEFAULT_FD"); - fileDisplayer = new CFileDisplay ("", eraseLastLog, "DEFAULT_FD"); - } + fileDisplayer = new CFileDisplay("", true, "DEFAULT_FD"); + fileDisplayer = new CFileDisplay("", eraseLastLog, "DEFAULT_FD"); + } - init(true); - m_isInitialized = true; - } - } + init(true); + m_isInitialized = true; + } + } - void CDebug::init (bool logInFile) - { - m_debugLog->attachDisplay(stdDisplayer); - m_infoLog->attachDisplay (stdDisplayer); - m_warningLog->attachDisplay (stdDisplayer); - m_assertLog->attachDisplay (stdDisplayer); - m_errorLog->attachDisplay (stdDisplayer); + void CDebug::init(bool logInFile) + { + m_debugLog->attachDisplay(stdDisplayer); + m_infoLog->attachDisplay(stdDisplayer); + m_warningLog->attachDisplay(stdDisplayer); + m_errorLog->attachDisplay(stdDisplayer); - if (logInFile) - { - m_debugLog->attachDisplay (fileDisplayer); - m_infoLog->attachDisplay (fileDisplayer); - m_warningLog->attachDisplay (fileDisplayer); - m_assertLog->attachDisplay (fileDisplayer); - m_errorLog->attachDisplay (fileDisplayer); - } - } + if (logInFile) + { + m_debugLog->attachDisplay(fileDisplayer); + m_infoLog->attachDisplay(fileDisplayer); + m_warningLog->attachDisplay(fileDisplayer); + m_errorLog->attachDisplay(fileDisplayer); + } + } - QString CDebug::getLogDirectory() - { - return m_logPath; - } - - void CDebug::assertFailed(int line, const char *file, const char* function, const char *exp) - { - m_assertLog->setLogInformation (line, file, function); - BlackMisc::CLogMessage::getAssertMsgObj() << "ASSERT FAILED! STOP!"; - - #ifdef BB_GUI - QMessageBox::critical(0, "ASSERT FAILED", - QString("%1 %2 %3 () - failed assert: %4"). - arg(QString(file)).arg(line).arg(QString(function)).arg(QString(exp))); - #endif - - qApp->quit(); - exit(1); - - } + QString CDebug::getLogDirectory() + { + return m_logPath; + } CLog *CDebug::getErrorLog() { @@ -127,65 +108,32 @@ namespace BlackMisc m_debugLog = debugLog; } - CLog *CDebug::getAssertLog() + CLogMessage CDebug::blackInfo(int line, const char *fileName, const char *methodName) { - return m_assertLog; + create(); + m_infoLog->setLogInformation(line, fileName, methodName); + return CLogMessage(*this, CLog::eInfo); } - void CDebug::setAssertLog(CLog *assertLog) + CLogMessage CDebug::blackWarning(int line, const char *fileName, const char *methodName) { - m_assertLog = assertLog; + create(); + m_warningLog->setLogInformation(line, fileName, methodName); + return CLogMessage(*this, CLog::eWarning); } - void CDebug::assertFailedString(int line, const char *fileName, const char *methodName, const char* exp, const char* string) + CLogMessage CDebug::blackDebug(int line, const char *fileName, const char *methodName) { - m_assertLog->setLogInformation (line, fileName, methodName); - BlackMisc::CLogMessage::getAssertMsgObj() << "ASSERT FAILED: " << string; - #ifdef BB_GUI - QMessageBox::critical(0, "ASSERT FAILED", string); - #endif + create(); + m_debugLog->setLogInformation(line, fileName, methodName); + return CLogMessage(*this, CLog::eDebug); } - CLogMessage CDebug::blackInfo(int line, const char *fileName, const char *methodName) - { - create(); - m_infoLog->setLogInformation( line, fileName, methodName); - return BlackMisc::CLogMessage::getInfoMsgObj(); - } - - CLogMessage CDebug::blackWarning(int line, const char *fileName, const char *methodName) - { - create(); - m_warningLog->setLogInformation( line, fileName, methodName); - return BlackMisc::CLogMessage::getWarningMsgObj(); - } - - CLogMessage CDebug::blackDebug(int line, const char *fileName, const char *methodName) - { - create(); - m_debugLog->setLogInformation( line, fileName, methodName); - return BlackMisc::CLogMessage::getDebugMsgObj(); - } - - CLogMessage CDebug::blackError(int line, const char *fileName, const char *methodName) - { - create(); - m_errorLog->setLogInformation( line, fileName, methodName); - return BlackMisc::CLogMessage::getErrorMsgObj(); - } - - CLogMessage CDebug::blackAssert(int line, const char *fileName, const char *methodName) - { - create(); - m_assertLog->setLogInformation( line, fileName, methodName); - return BlackMisc::CLogMessage::getAssertMsgObj(); - } - - CLogMessage CDebug::blackAssertqstr(int line, const char *fileName, const char *methodName) - { - create(); - m_assertLog->setLogInformation( line, fileName, methodName); - return BlackMisc::CLogMessage::getAssertMsgObj(); - } + CLogMessage CDebug::blackError(int line, const char *fileName, const char *methodName) + { + create(); + m_errorLog->setLogInformation(line, fileName, methodName); + return CLogMessage(*this, CLog::eError); + } } // namespace BlackMisc diff --git a/src/blackmisc/debug.h b/src/blackmisc/debug.h index 8bb2cc6d1..05beb241f 100644 --- a/src/blackmisc/debug.h +++ b/src/blackmisc/debug.h @@ -3,8 +3,8 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ -#ifndef DEBUG_H -#define DEBUG_H +#ifndef BLACKMISC_DEBUG_H +#define BLACKMISC_DEBUG_H #include "blackmisc/context.h" #include "blackmisc/log.h" @@ -15,133 +15,111 @@ namespace BlackMisc { - //! class CDebug - /*! This class implements the logging of the library. It holds a list of displays - takes care of any additional information needed, e.g. timestamps, filename etc. - To use the logging use the default displayer or implement your own one and - register it with this class. - */ - class CDebug - { - public: + //! class CDebug + /*! This class implements the logging of the library. It holds a list of displays + takes care of any additional information needed, e.g. timestamps, filename etc. + To use the logging use the default displayer or implement your own one and + register it with this class. + */ + class CDebug : public QObject + { + Q_OBJECT + + public: + BLACK_INTERFACE(BlackMisc::CDebug) CDebug(); + // internal use only + void create(const char *logPath = "", bool logInFile = true, bool eraseLastLog = false); - // internal use only - void create (const char *logPath = "", bool logInFile = true, bool eraseLastLog = false); + // init Debug + void init(bool logInFile); - // init Debug - void init(bool logInFile); - - /// Do not call this, unless you know what you're trying to do (it kills debug)! - void destroy() {} + /// Do not call this, unless you know what you're trying to do (it kills debug)! + void destroy() {} void changeLogDirectory(const QString &dir) { Q_UNUSED(dir); } - QString getLogDirectory(); + QString getLogDirectory(); - // Assert function - - //! Method returns the pointer to the global assert log object - /*! - \return Pointer to CLog object - */ - CLog *getAssertLog(); - - //! Pure virtual function to set the global assert log object - /*! - \param Pointer to CLog object - */ - void setAssertLog(CLog *assertLog); - - //! Pure virtual method returns the pointer to the global error log object - /*! - \return Pointer to CLog object - */ + //! Pure virtual method returns the pointer to the global error log object + /*! + \return Pointer to CLog object + */ CLog *getErrorLog(); - - //! Pure virtual function to set the global error log object - /*! - \param Pointer to CLog object - */ + + //! Pure virtual function to set the global error log object + /*! + \param Pointer to CLog object + */ void setErrorLog(CLog *errorLog); - - //! Pure virtual method returns the pointer to the global warning log object - /*! - \return Pointer to CLog object - */ + + //! Pure virtual method returns the pointer to the global warning log object + /*! + \return Pointer to CLog object + */ CLog *getWarningLog(); - - //! Pure virtual function to set the global warning log object - /*! - \param Pointer to CLog object - */ + + //! Pure virtual function to set the global warning log object + /*! + \param Pointer to CLog object + */ void setWarningLog(CLog *warningLog); - - //! Pure virtual method returns the pointer to the global info log object - /*! - \return Pointer to CLog object - */ + + //! Pure virtual method returns the pointer to the global info log object + /*! + \return Pointer to CLog object + */ CLog *getInfoLog(); - - //! Pure virtual function to set the global info log object - /*! - \param Pointer to CLog object - */ + + //! Pure virtual function to set the global info log object + /*! + \param Pointer to CLog object + */ void setInfoLog(CLog *infoLog); - - //! Pure virtual method returns the pointer to the global debug log object - /*! - \return Pointer to CLog object - */ + + //! Pure virtual method returns the pointer to the global debug log object + /*! + \return Pointer to CLog object + */ CLog *getDebugLog(); - - //! Pure virtual function to set the global debug log object - /*! - \param Pointer to CLog object - */ + + //! Pure virtual function to set the global debug log object + /*! + \param Pointer to CLog object + */ void setDebugLog(CLog *debugLog); - void assertFailed(int line, const char *file, const char* function, const char *exp); - void assertFailedString(int line, const char *fileName, const char *methodName, const char* exp, const char* string); - - CLogMessage blackInfo(int line, const char *fileName, const char *methodName); - CLogMessage blackWarning(int line, const char *fileName, const char *methodName); - CLogMessage blackDebug(int line, const char *fileName, const char *methodName); - CLogMessage blackError(int line, const char *fileName, const char *methodName); - CLogMessage blackAssert(int line, const char *fileName, const char *methodName); - CLogMessage blackAssertqstr(int line, const char *fileName, const char *methodName); - - private: - bool m_isInitialized; - + CLogMessage blackInfo(int line, const char *fileName, const char *methodName); + CLogMessage blackWarning(int line, const char *fileName, const char *methodName); + CLogMessage blackDebug(int line, const char *fileName, const char *methodName); + CLogMessage blackError(int line, const char *fileName, const char *methodName); + + private: + bool m_isInitialized; + CStdDisplay *stdDisplayer; CFileDisplay *fileDisplayer; - - QString m_logPath; - - CLog *m_errorLog; - CLog *m_warningLog; - CLog *m_infoLog; - CLog *m_debugLog; - CLog *m_assertLog; - }; - /*! - Macro is not defined in VC6 - */ - #if _MSC_VER <= 1200 - # define __FUNCTION__ NULL - #endif - - #define bInfo ( BlackMisc::IContext::getInstance().getDebug()->blackInfo(__LINE__, __FILE__, __FUNCTION__ ) ) - #define bWarning ( BlackMisc::IContext::getInstance().getDebug()->blackWarning(__LINE__, __FILE__, __FUNCTION__ ) ) - #define bDebug ( BlackMisc::IContext::getInstance().getDebug()->blackDebug(__LINE__, __FILE__, __FUNCTION__ ) ) - #define bError ( BlackMisc::IContext::getInstance().getDebug()->blackError(__LINE__, __FILE__, __FUNCTION__ ) ) - #define bAssert(exp) if (!(exp)) BlackMisc::IContext::getInstance().getDebug()->assertFailed(__LINE__, __FILE__, __FUNCTION__, #exp) - #define bAssertstr(exp, str) if (!(exp)) BlackMisc::IContext::getInstance().getDebug()->assertFailedString(__LINE__, __FILE__, __FUNCTION__, #exp, #str) + QString m_logPath; + + CLog *m_errorLog; + CLog *m_warningLog; + CLog *m_infoLog; + CLog *m_debugLog; + }; + +#define bInfo(CONTEXT) ( (CONTEXT).getDebug()->blackInfo(__LINE__, __FILE__, __FUNCTION__ ) ) +#define bWarning(CONTEXT) ( (CONTEXT).getDebug()->blackWarning(__LINE__, __FILE__, __FUNCTION__ ) ) +#define bDebug(CONTEXT) ( (CONTEXT).getDebug()->blackDebug(__LINE__, __FILE__, __FUNCTION__ ) ) +#define bError(CONTEXT) ( (CONTEXT).getDebug()->blackError(__LINE__, __FILE__, __FUNCTION__ ) ) + +#define bAppInfo bInfo(BlackMisc::IContext::getInstance()) +#define bAppWarning bWarning(BlackMisc::IContext::getInstance()) +#define bAppDebug bDebug(BlackMisc::IContext::getInstance()) +#define bAppError bError(BlackMisc::IContext::getInstance()) } // namespace BlackMisc -#endif DEBUG_H // DEBUG_H +#endif //BLACKMISC_DEBUG_H diff --git a/src/blackmisc/display.cpp b/src/blackmisc/display.cpp index 5dbc285e3..003ddbdf7 100644 --- a/src/blackmisc/display.cpp +++ b/src/blackmisc/display.cpp @@ -3,12 +3,10 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ +#include "blackmisc/display.h" +#include "blackmisc/context.h" #include #include - -#include "blackmisc/context.h" -#include "blackmisc/display.h" - #include namespace BlackMisc @@ -30,7 +28,7 @@ namespace BlackMisc const char *ILogDisplay::logTypeToString (CLog::TLogType logType) { - if (logType < CLog::OFF || logType > CLog::UNKNOWN) + if (logType < CLog::eOff || logType >= CLog::eLast) return "Not defined"; return LogTypeToString[logType]; @@ -70,7 +68,7 @@ namespace BlackMisc bool needSpace = false; QString line; - if (logInformation.m_logType != CLog::OFF) + if (logInformation.m_logType != CLog::eOff) { line += logTypeToString(logInformation.m_logType); needSpace = true; @@ -148,21 +146,6 @@ namespace BlackMisc { m_fileName = filename; - if (filename.isEmpty()) - { - // Call this first, otherwise the Singleton pointer is NULL - CLog::setDefaultApplicationName(); - - // Read the process name and name the log accordingly - QString *processName = (QString *)IContext::getInstance().singletonPointer("BlackMisc::CLog::m_applicationName"); - - // Just in case - if ( processName != NULL ) - m_fileName = QFileInfo(*processName).baseName() + ".log"; - else - printf("Cannot create log file without a filename!"); - } - m_file = new QFile(m_fileName); if (eraseLastLog) @@ -202,7 +185,7 @@ namespace BlackMisc needSpace = true; } - if (logInformation.m_logType != CLog::OFF) + if (logInformation.m_logType != CLog::eOff) { if (needSpace) { line += " "; needSpace = false; } line += logTypeToString(logInformation.m_logType); diff --git a/src/blackmisc/display.h b/src/blackmisc/display.h index 1fb3c2bbf..3c5b1786c 100644 --- a/src/blackmisc/display.h +++ b/src/blackmisc/display.h @@ -6,11 +6,10 @@ #ifndef DISPLAY_H #define DISPLAY_H +#include "blackmisc/log.h" #include #include -#include "blackmisc/log.h" - namespace BlackMisc { class ILogDisplay diff --git a/src/blackmisc/log.cpp b/src/blackmisc/log.cpp index 771a2ea08..967bd86f9 100644 --- a/src/blackmisc/log.cpp +++ b/src/blackmisc/log.cpp @@ -7,209 +7,177 @@ #define UNICODE #endif +#include "blackmisc/log.h" +#include "blackmisc/display.h" +#include "blackmisc/debug.h" +#include "blackmisc/context.h" + #include #include #include -#include "blackmisc/log.h" -#include "blackmisc/display.h" -#include "blackmisc/debug.h" - +//TODO do we still need these platform includes here? #ifdef Q_OS_WIN -# define NOMINMAX -# include -# include +# define NOMINMAX +# include +# include #else -# include +# include #endif namespace BlackMisc { - QString *CLog::m_applicationName = NULL; - - CLog::CLog(TLogType logType) : m_logType (logType) - { - } - - CLog::~CLog(void) - { - } - - void CLog::setDefaultApplicationName() + CLog::CLog(IContext &context, TLogType logType) : m_context(context), m_logType(logType) { - //! Get the object from the singleton context and create a new one if not already done - if (m_applicationName == NULL) - { - m_applicationName = static_cast(IContext::getInstance().singletonPointer("BlackMisc::CLog::m_applicationName")); - if (m_applicationName == NULL) - { - m_applicationName = new QString; - IContext::getInstance().setSingletonPointer("BlackMisc::CLog::m_applicationName", m_applicationName); - } - } - -#ifdef Q_OS_WIN - //! By default, we use the executables name. - if ((*m_applicationName).isEmpty()) - { - WCHAR name[1024]; - int size = GetModuleFileName (NULL, name, 1023); - QString applicationPath = QString::fromWCharArray(name,size); - (*m_applicationName) = QFileInfo ( applicationPath ).fileName(); - } -#else - //! Todo: Check if there a corresponding API in Linux and Mac - //! For the time being, set it to unknown. - if ((*m_applicationName).isEmpty()) - { - *m_applicationName = ""; - } -#endif } - void CLog::printWithNewLine( QString &message ) + CLog::~CLog(void) { - //! If we have no displays, we have nothing to do. - if ( hasNoDisplays() ) + } + + void CLog::printWithNewLine(QString &message) + { + //! If we have no displays, we have nothing to do. + if (hasNoDisplays()) { return; } - + QChar newLine = '\n'; - - //! We should print the message with a new line. So check - //! if one is already there. If not append it. + + //! We should print the message with a new line. So check + //! if one is already there. If not append it. if (!message.endsWith(newLine, Qt::CaseInsensitive)) message.append(newLine); - printString (message); + printString(message); } - void CLog::print( QString &message ) + void CLog::print(QString &message) { - //! If we have no displays, we have nothing to do. - if ( hasNoDisplays() ) + //! If we have no displays, we have nothing to do. + if (hasNoDisplays()) { return; } - printString (message); + printString(message); } - void CLog::printString( QString &message ) + void CLog::printString(QString &message) { QString logDisplay; - //! Just in case, lets set the default name - setDefaultApplicationName (); + //! Just in case, lets set the default name + m_context.setDefaultApplicationName(); - //! If the current line is empty, then put some information as - //! the prefix. - //! Be aware: This information must be set by the \sa setLogInformation() - //! before. - if ( m_logLine.isEmpty() ) - { - m_logInformation.m_dateTime = QDateTime::currentDateTime(); - m_logInformation.m_logType = m_logType; - m_logInformation.m_applicationName = *m_applicationName; - m_logInformation.m_threadId = 0; //getThreadId(); - m_logInformation.m_sourceFile = m_sourceFile; - m_logInformation.m_line = m_line; - m_logInformation.m_methodName = m_methodName; + //! If the current line is empty, then put some information as + //! the prefix. + //! Be aware: This information must be set by the \sa setLogInformation() + //! before. + if (m_logLine.isEmpty()) + { + m_logInformation.m_dateTime = QDateTime::currentDateTime(); + m_logInformation.m_logType = m_logType; + m_logInformation.m_applicationName = m_context.getApplicationName(); + m_logInformation.m_threadId = 0; //getThreadId(); + m_logInformation.m_sourceFile = m_sourceFile; + m_logInformation.m_line = m_line; + m_logInformation.m_methodName = m_methodName; - m_logLine = message; - } - else - { - m_logLine += message; - } - - //! If this is not the end of the line, we are done for now. - if ( ! message.contains('\n') ) - { - return; - } + m_logLine = message; + } + else + { + m_logLine += message; + } - for ( TLogDisplayList::iterator it = m_logDisplays.begin(); it != m_logDisplays.end(); ++it) + //! If this is not the end of the line, we are done for now. + if (! message.contains('\n')) + { + return; + } + + for (TLogDisplayList::iterator it = m_logDisplays.begin(); it != m_logDisplays.end(); ++it) { (*it)->print(m_logInformation, m_logLine); } - - //! Reset everything for the next line + + //! Reset everything for the next line m_logLine.clear(); resetLogInformation(); } void CLog::attachDisplay(ILogDisplay *display) - { - //! Display must be a valid pointer + { + //! Display must be a valid pointer if (display == NULL) - { - printf ("Trying to add a NULL pointer\n"); - return; - } - - //! Check if it is already attached - if ( !m_logDisplays.contains(display) ) { - m_logDisplays.push_back (display); + printf("Trying to add a NULL pointer\n"); + return; + } + + //! Check if it is already attached + if (!m_logDisplays.contains(display)) + { + m_logDisplays.push_back(display); } else { - bWarning << "Couldn't attach the display - already in the list!"; + bWarning(m_context) << "Couldn't attach the display - already in the list!"; } - } + } - ILogDisplay* CLog::getDisplay(const QString &displayName) - { - //! Must be a valid name + ILogDisplay *CLog::getDisplay(const QString &displayName) + { + //! Must be a valid name if (displayName.isEmpty()) { - bWarning << "Cannot return a display with empty name!"; + bWarning(m_context) << "Cannot return a display with empty name!"; return NULL; } TLogDisplayList::const_iterator it; - //! Loop through the list and find the candidate - for ( it = m_logDisplays.constBegin(); it != m_logDisplays.constEnd(); ++it) + //! Loop through the list and find the candidate + for (it = m_logDisplays.constBegin(); it != m_logDisplays.constEnd(); ++it) { - //! Does it have the desired name? - if ( (*it)->DisplayName == displayName ) + //! Does it have the desired name? + if ((*it)->DisplayName == displayName) { return *it; } } - } + } - void CLog::dettachDisplay (ILogDisplay *logDisplay) + void CLog::dettachDisplay(ILogDisplay *logDisplay) { - //! Must be a valid pointer + //! Must be a valid pointer if (logDisplay == NULL) { - bWarning << "Cannot remove a NULL displayer!"; + bWarning(m_context) << "Cannot remove a NULL displayer!"; return; } - - //! We should have only one, but just in case. + + //! We should have only one, but just in case. m_logDisplays.removeAll(logDisplay); } - void CLog::dettachDisplay (const QString &displayName) + void CLog::dettachDisplay(const QString &displayName) { - //! Must be a valid name + //! Must be a valid name if (displayName.isEmpty()) { - bWarning << "Cannot remove displayer with empty name!"; + bWarning(m_context) << "Cannot remove displayer with empty name!"; return; } TLogDisplayList::iterator it; - for ( it = m_logDisplays.begin(); it != m_logDisplays.end(); ) + for (it = m_logDisplays.begin(); it != m_logDisplays.end();) { - if ( (*it)->DisplayName == displayName ) + if ((*it)->DisplayName == displayName) { it = m_logDisplays.erase(it); } @@ -220,15 +188,15 @@ namespace BlackMisc } } - bool CLog::isAttached (ILogDisplay *logDisplay) const + bool CLog::isAttached(ILogDisplay *logDisplay) const { return m_logDisplays.contains(logDisplay); } - void CLog::setLogInformation (int line, const char *sourceFile, const char *methodName) + void CLog::setLogInformation(int line, const char *sourceFile, const char *methodName) { - //! We have to make sure, we at least one display. - if ( !hasNoDisplays() ) + //! We have to make sure, we at least one display. + if (!hasNoDisplays()) { m_mutex.lock(); m_posSet++; @@ -240,11 +208,11 @@ namespace BlackMisc void CLog::resetLogInformation() { - //! It should be impossible that this gets called, withoud - //! having a attached display. - bAssert( !hasNoDisplays() ); + //! It should be impossible that this gets called, withoud + //! having a attached display. + Q_ASSERT(!hasNoDisplays()); - if ( m_posSet > 0 ) + if (m_posSet > 0) { m_sourceFile = NULL; m_line = -1; diff --git a/src/blackmisc/log.h b/src/blackmisc/log.h index b184f96fd..a06e9232e 100644 --- a/src/blackmisc/log.h +++ b/src/blackmisc/log.h @@ -3,36 +3,40 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ -#ifndef LOG_H -#define LOG_H +#ifndef BLACKMISC_LOG_H +#define BLACKMISC_LOG_H #include #include #include #include -namespace BlackMisc { +namespace BlackMisc +{ class ILogDisplay; + class IContext; - //! Logging class - /*! This class implements the logging of the library. It holds a list of displays - takes care of any additional information needed, e.g. timestamps, filename etc. - To use the logging use the default displayer or implement your own one and - register it with this class. - */ - class CLog - { - public: + //! Logging class + /*! This class implements the logging of the library. It holds a list of displays + takes care of any additional information needed, e.g. timestamps, filename etc. + To use the logging use the default displayer or implement your own one and + register it with this class. + */ + class CLog + { + public: //! Logging type. /*! This enum holds all different available log types. */ - typedef enum { OFF = 0, - ERROR, - WARNING, - INFO, - DEBUG, - ASSERT, - UNKNOWN } TLogType; + enum TLogType + { + eOff = 0, + eError, + eWarning, + eInfo, + eDebug, + eLast + }; //! SLogParameter /*! @@ -40,165 +44,152 @@ namespace BlackMisc { */ struct SLogInformation { - SLogInformation() : m_logType(CLog::OFF), m_threadId(0), m_line(-1), m_sourceFile(NULL), m_methodName(NULL) {} + SLogInformation() : m_logType(CLog::eOff), m_threadId(0), m_line(-1), m_sourceFile(NULL), m_methodName(NULL) {} - QDateTime m_dateTime; - TLogType m_logType; - QString m_applicationName; - quint32 m_threadId; - const char *m_sourceFile; - qint32 m_line; + QDateTime m_dateTime; + TLogType m_logType; + QString m_applicationName; + quint32 m_threadId; + const char *m_sourceFile; + qint32 m_line; const char *m_methodName; }; - CLog (TLogType logType = OFF); + CLog(IContext &context, TLogType logType = eOff); //! CLog destructor. - virtual ~CLog(void); + virtual ~CLog(void); /*! * Display */ - //! This method adds a Displayer to the Log object - /*! CLog does not own the pointer. It is the callers responsibility - to allocate the displayer and remove it after using. */ - /*! - \param display A pointer to a display. - \sa ILogDisplay - */ - void attachDisplay (BlackMisc::ILogDisplay *display); + //! This method adds a Displayer to the Log object + /*! CLog does not own the pointer. It is the callers responsibility + to allocate the displayer and remove it after using. */ + /*! + \param display A pointer to a display. + \sa ILogDisplay + */ + void attachDisplay(BlackMisc::ILogDisplay *display); - //! This method returns the pointer to a registered display. - /*! - \return display A pointer to a display. - */ - ILogDisplay *getDisplay (const QString &displayName); + //! This method returns the pointer to a registered display. + /*! + \return display A pointer to a display. + */ + ILogDisplay *getDisplay(const QString &displayName); - //! Removes a display - /*! - \param logDisplay Pointer to the display. - */ - void dettachDisplay (ILogDisplay *logDisplay); + //! Removes a display + /*! + \param logDisplay Pointer to the display. + */ + void dettachDisplay(ILogDisplay *logDisplay); - //! Removes a display by its name. - /*! - \param displayName Name of the display. - */ - void dettachDisplay (const QString& displayName); + //! Removes a display by its name. + /*! + \param displayName Name of the display. + */ + void dettachDisplay(const QString &displayName); - //! Checks if the displayer is added - /*! - \param logDisplay Pointer to a display. - \return Returns true if display is attached, otherwise false. - */ - bool isAttached (ILogDisplay *logDisplay) const; + //! Checks if the displayer is added + /*! + \param logDisplay Pointer to a display. + \return Returns true if display is attached, otherwise false. + */ + bool isAttached(ILogDisplay *logDisplay) const; - //! Checks if the object has any attached displays - /*! - \return Returns true if no display is attached, otherwise false. - */ - bool hasNoDisplays () const { return m_logDisplays.empty(); } - - //! Sets the name of the application process - /*! - \param displayName Name of the application. - */ - static void setApplicationName (const QString &displayName); - - //! Sets the default application name. This is the name - //! of the executable. - static void setDefaultApplicationName (); + //! Checks if the object has any attached displays + /*! + \return Returns true if no display is attached, otherwise false. + */ + bool hasNoDisplays() const { return m_logDisplays.empty(); } //! Sets any additional information as prefix to the log message - /*! - \param fileName This is the name of the corresponding source file. - \param methodName This is the name of calling method. - */ - void setLogInformation (int line, const char *fileName, const char *methodName = NULL); + /*! + \param fileName This is the name of the corresponding source file. + \param methodName This is the name of calling method. + */ + void setLogInformation(int line, const char *fileName, const char *methodName = NULL); - //! Prints the message and adds an new line character at the end - /*! - \param message Message string, which has to be logged - */ - void printWithNewLine( QString &message ); + //! Prints the message and adds an new line character at the end + /*! + \param message Message string, which has to be logged + */ + void printWithNewLine(QString &message); - //! Prints the message as is and appends no additional characters - /*! - \param message Message string, which has to be logged - */ - void print( QString &message ); + //! Prints the message as is and appends no additional characters + /*! + \param message Message string, which has to be logged + */ + void print(QString &message); - void printString ( QString &message ); + void printString(QString &message); - protected: - - /// Display a string in decorated form to all attached displayers. - void displayString (const char *str); + protected: + + /// Display a string in decorated form to all attached displayers. + void displayString(const char *str); /// Symetric to setPosition(). Automatically called by display...(). Do not call if noDisplayer(). void resetLogInformation(); - //! Logging Type. - /*! - Specifies which logging type should be used. - Possible are: Error, Warning, Info, Debug and Assert. - */ - TLogType m_logType; - - //! Application name. - /*! - Specifies the name of the application to put it into the log line - */ - static QString *m_applicationName; + //! Context + IContext &m_context; - //! Source file name. - /*! - Specifies the name of the source file, log message was called from. - */ - const char *m_sourceFile; - - //! Code line. - /*! - Specifies the line in the source file, log message was called from. - */ + //! Logging Type. + /*! + Specifies which logging type should be used. + Possible are: Error, Warning, Info, Debug and Assert. + */ + TLogType m_logType; + + //! Source file name. + /*! + Specifies the name of the source file, log message was called from. + */ + const char *m_sourceFile; + + //! Code line. + /*! + Specifies the line in the source file, log message was called from. + */ qint32 m_line; - - //! Method name. - /*! - Specifies the method in the source file, log message was called from. - */ - const char *m_methodName; - - /*! - \typedef TLogDisplayerMap - QList container holding pointers to ILogDisplay objects - \sa ArrayList::GetEnumerator, \sa List::GetEnumerator - */ - typedef QList TLogDisplayList; - - //! List of all attached displays. + + //! Method name. + /*! + Specifies the method in the source file, log message was called from. + */ + const char *m_methodName; + + /*! + \typedef TLogDisplayerMap + QList container holding pointers to ILogDisplay objects + \sa ArrayList::GetEnumerator, \sa List::GetEnumerator + */ + typedef QList TLogDisplayList; + + //! List of all attached displays. TLogDisplayList m_logDisplays; - - //! Mutex object - /*! - This makes our class thread safe. - */ + + //! Mutex object + /*! + This makes our class thread safe. + */ QMutex m_mutex; - //! Position - quint32 m_posSet; + //! Position + quint32 m_posSet; - //! Log message string - /*! - This variable is used, if a log line consists of two or more - calls. The first ones are then stored temporary in this variable - until one message ends with a line feed. - */ + //! Log message string + /*! + This variable is used, if a log line consists of two or more + calls. The first ones are then stored temporary in this variable + until one message ends with a line feed. + */ QString m_logLine; - SLogInformation m_logInformation; - }; + SLogInformation m_logInformation; + }; } // namespace BlackMisc -#endif LOG_H +#endif //BLACKMISC_LOG_H diff --git a/src/blackmisc/logmessage.cpp b/src/blackmisc/logmessage.cpp index 07a42ba71..200979a5a 100644 --- a/src/blackmisc/logmessage.cpp +++ b/src/blackmisc/logmessage.cpp @@ -4,51 +4,50 @@ namespace BlackMisc { - CLogMessage::LogStream::LogStream(CLog::TLogType type) - : output(&buffer, QIODevice::WriteOnly), reference(1), - type(type), needSpace(true), enableOutput(true) - {} + CLogMessage::LogStream::LogStream(CLog::TLogType type) + : output(&buffer, QIODevice::WriteOnly), reference(1), + type(type), needSpace(true), enableOutput(true) + {} - CLogMessage::CLogMessage(CLog::TLogType type) - : logStream(new LogStream(type)) - { - } + CLogMessage::CLogMessage(CDebug &debug_, CLog::TLogType type) + : debug(debug_), logStream(new LogStream(type)) + { + } - CLogMessage::CLogMessage(const CLogMessage &other) - : logStream(other.logStream) - { - ++logStream->reference; - } + CLogMessage::CLogMessage(const CLogMessage &other) + : debug(other.debug), logStream(other.logStream) + { + ++logStream->reference; + } - CLogMessage::~CLogMessage() { - if (!--logStream->reference) { - if(logStream->enableOutput) { - switch (logStream->type) - { - case CLog::WARNING: - BlackMisc::IContext::getInstance().getDebug()->getWarningLog()->printWithNewLine(logStream->buffer); - break; + CLogMessage::~CLogMessage() + { + if (!--logStream->reference) + { + if (logStream->enableOutput) + { + switch (logStream->type) + { + case CLog::eWarning: + debug.getWarningLog()->printWithNewLine(logStream->buffer); + break; - case CLog::INFO: - BlackMisc::IContext::getInstance().getDebug()->getInfoLog()->printWithNewLine(logStream->buffer); - break; + case CLog::eInfo: + debug.getInfoLog()->printWithNewLine(logStream->buffer); + break; - case CLog::DEBUG: - BlackMisc::IContext::getInstance().getDebug()->getDebugLog()->printWithNewLine(logStream->buffer); - break; + case CLog::eDebug: + debug.getDebugLog()->printWithNewLine(logStream->buffer); + break; - case CLog::ERROR: - BlackMisc::IContext::getInstance().getDebug()->getErrorLog()->printWithNewLine(logStream->buffer); - break; - - case CLog::ASSERT: - BlackMisc::IContext::getInstance().getDebug()->getAssertLog()->printWithNewLine(logStream->buffer); - break; - } - - } - delete logStream; - } + case CLog::eError: + default: + debug.getErrorLog()->printWithNewLine(logStream->buffer); + break; + } + } + delete logStream; + } } } // namespace Blackib diff --git a/src/blackmisc/logmessage.h b/src/blackmisc/logmessage.h index 26945b753..1e0cdae1d 100644 --- a/src/blackmisc/logmessage.h +++ b/src/blackmisc/logmessage.h @@ -6,41 +6,40 @@ #ifndef LOGMESSAGE_H #define LOGMESSAGE_H -// Qt includes - -#include - -#include "blackmisc/context.h" #include "blackmisc/log.h" +#include "blackmisc/context.h" +#include namespace BlackMisc { + class CDebug; + class CLogMessage { - struct LogStream { - - //! Constructor + struct LogStream + { + //! Constructor LogStream(CLog::TLogType type); - - + QTextStream output; - - //! Message Buffer + + //! Message Buffer QString buffer; - - //! Logging type + + //! Logging type CLog::TLogType type; bool needSpace; bool enableOutput; - //! Reference count - quint32 reference; + //! Reference count + quint32 reference; + } *logStream; + + CDebug &debug; - } *logStream; - public: - CLogMessage( CLog::TLogType type ); - CLogMessage(const CLogMessage &other); + CLogMessage(CDebug &debug_, CLog::TLogType type); + CLogMessage(const CLogMessage &other); ~CLogMessage(); @@ -57,25 +56,19 @@ namespace BlackMisc inline CLogMessage &operator<<(signed long t) { logStream->output << t; return maybeSpace(); } inline CLogMessage &operator<<(unsigned long t) { logStream->output << t; return maybeSpace(); } inline CLogMessage &operator<<(qint64 t) - { logStream->output << QString::number(t); return maybeSpace(); } + { logStream->output << QString::number(t); return maybeSpace(); } inline CLogMessage &operator<<(quint64 t) - { logStream->output << QString::number(t); return maybeSpace(); } + { logStream->output << QString::number(t); return maybeSpace(); } inline CLogMessage &operator<<(float t) { logStream->output << t; return maybeSpace(); } inline CLogMessage &operator<<(double t) { logStream->output << t; return maybeSpace(); } - inline CLogMessage &operator<<(const char* t) { logStream->output << QString::fromAscii(t); return maybeSpace(); } - inline CLogMessage &operator<<(const QString & t) { logStream->output << '\"' << t << '\"'; return maybeSpace(); } - inline CLogMessage &operator<<(const QByteArray & t) { logStream->output << '\"' << t << '\"'; return maybeSpace(); } - - static CLogMessage getWarningMsgObj() { return CLogMessage(CLog::WARNING); } - static CLogMessage getInfoMsgObj() { return CLogMessage(CLog::INFO); } - static CLogMessage getDebugMsgObj() { return CLogMessage(CLog::DEBUG); } - static CLogMessage getErrorMsgObj() { return CLogMessage(CLog::ERROR); } - static CLogMessage getAssertMsgObj() { return CLogMessage(CLog::ASSERT); } + inline CLogMessage &operator<<(const char *t) { logStream->output << QString::fromAscii(t); return maybeSpace(); } + inline CLogMessage &operator<<(const QString &t) { logStream->output << '\"' << t << '\"'; return maybeSpace(); } + inline CLogMessage &operator<<(const QByteArray &t) { logStream->output << '\"' << t << '\"'; return maybeSpace(); } inline CLogMessage &operator<<(QTextStreamManipulator m) { logStream->output << m; return *this; } - - + + }; } // BlackMisc diff --git a/src/blackmisc/message_dispatcher.h b/src/blackmisc/message_dispatcher.h index 820b16eae..5e4491748 100644 --- a/src/blackmisc/message_dispatcher.h +++ b/src/blackmisc/message_dispatcher.h @@ -3,23 +3,22 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ -#ifndef MESSAGE_DISPATCHER_H -#define MESSAGE_DISPATCHER_H - -#include -#include +#ifndef BLACKMISC_MESSAGE_DISPATCHER_H +#define BLACKMISC_MESSAGE_DISPATCHER_H #include "blackmisc/message.h" - #include "blackmisc/context.h" #include "blackmisc/type_info.h" +#include +#include namespace BlackMisc { class CMessageHandler; - class CMessageDispatcher + class CMessageDispatcher : public QObject { + Q_OBJECT // safe singleton declaration SINGLETON_CLASS_DECLARATION(CMessageDispatcher) @@ -38,7 +37,10 @@ namespace BlackMisc } template - void registerClass(T*, CTypeInfo); + void registerClass(T* object, CTypeInfo typeinfo) + { + m_messageHander.insert(typeinfo, object); + } private: typedef QQueue TMessageQueue; @@ -48,12 +50,6 @@ namespace BlackMisc TMessageHandlerMap m_messageHander; }; - template - void CMessageDispatcher::registerClass( T* object, CTypeInfo typeinfo) - { - m_messageHander.insert(typeinfo, object); - } - } // namespace BlackMisc -#endif // MESSAGE_DISPATCHER_H +#endif // BLACKMISC_MESSAGE_DISPATCHER_H diff --git a/src/blackmisc/message_factory.h b/src/blackmisc/message_factory.h index e76b1d321..b9dc1ca05 100644 --- a/src/blackmisc/message_factory.h +++ b/src/blackmisc/message_factory.h @@ -3,8 +3,8 @@ //! License, v. 2.0. If a copy of the MPL was not distributed with this //! file, You can obtain one at http://mozilla.org/MPL/2.0/ -#ifndef MESSAGE_FACTORY_H -#define MESSAGE_FACTORY_H +#ifndef BLACKMISC_MESSAGE_FACTORY_H +#define BLACKMISC_MESSAGE_FACTORY_H #include #include "blackmisc/message.h" @@ -33,8 +33,10 @@ namespace BlackMisc virtual IMessage* create() { return new T; } }; - class CMessageFactory + class CMessageFactory : public QObject { + Q_OBJECT + // safe singleton declaration SINGLETON_CLASS_DECLARATION(CMessageFactory) @@ -56,4 +58,4 @@ namespace BlackMisc } // namespace BlackMisc -#endif // MESSAGE_FACTORY_H +#endif // BLACKMISC_MESSAGE_FACTORY_H diff --git a/src/blackmisc/message_handler.h b/src/blackmisc/message_handler.h index 07c785ee8..ba4f45df0 100644 --- a/src/blackmisc/message_handler.h +++ b/src/blackmisc/message_handler.h @@ -6,11 +6,11 @@ #ifndef MESSAGE_HANDLER_H #define MESSAGE_HANDLER_H -#include +#include "blackmisc/message_dispatcher.h" #include "blackmisc/message.h" #include "blackmisc/debug.h" #include "blackmisc/type_info.h" -#include "blackmisc/message_dispatcher.h" +#include namespace BlackMisc { diff --git a/src/blackmisc/plugins.h b/src/blackmisc/plugins.h new file mode 100644 index 000000000..4178933bb --- /dev/null +++ b/src/blackmisc/plugins.h @@ -0,0 +1,150 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/*! + \file +*/ + +#ifndef BLACKMISC_PLUGINS_H +#define BLACKMISC_PLUGINS_H + +#include +#include + +namespace BlackMisc +{ + + class IContext; + class IPluginFactory; + + /*! + The interface implemented by the main worker class in a plugin. + Constructed by a factory implementing IPluginFactory and + accessible to the application through the CPluginManager. + */ + class IPlugin + { + public: + /*! + Destructor. + */ + virtual ~IPlugin() {} + + /*! + Exceptions are not allowed to leave plugins, so we use this function + to test whether the plugin was constructed successfully. + \return False if an error occurred during plugin construction. + */ + virtual bool isValid() const = 0; + + /*! + Return the factory used to construct this object. + This is usually passed to the plugin's constructor by the factory itself. + \return + */ + virtual IPluginFactory &getFactory() = 0; + }; + + /*! + The root interface for classes exported from plugins. + This is a factory pattern for creating and destroying instances of IPlugin. + You usually don't need to worry about this, if you use the + MAKE_BLACK_PLUGIN macro to define your factory. + */ + class IPluginFactory + { + public: + /*! + Destructor. + */ + virtual ~IPluginFactory() {} + + /*! + Construct an instance of the plugin. + \param context The application context. + \return a pointer to the newly created plugin. + \warning You must release this pointer with IPluginFactory::destroy(). + */ + virtual IPlugin *create(IContext &context) = 0; + + /*! + Destroy a plugin which was created by this factory. + */ + virtual void destroy(IPlugin *plugin) = 0; + + /*! + Return the plugin's short name. + \return + */ + virtual const char *getName() const = 0; + + /*! + Return the plugin's description. + \return + */ + virtual const char *getDescription() const = 0; + }; + +} //namespace BlackMisc + +// must be placed outside namespace and before CPluginFactoryBase +Q_DECLARE_INTERFACE(BlackMisc::IPluginFactory, "net.vatsim.client.BlackMisc.IPluginFactory") + +namespace BlackMisc +{ + + /*! + Base class for CPluginFactory template used by MAKE_BLACK_PLUGIN. + */ + class CPluginFactoryBase : public QObject, public IPluginFactory + { + Q_OBJECT + Q_INTERFACES(BlackMisc::IPluginFactory) + }; + + /*! + Template used by MAKE_BLACK_PLUGIN. + */ + template + class CPluginFactory : public CPluginFactoryBase + { + public: + IPlugin *create(IContext &context) { return new P(*this, context); } + + void destroy(IPlugin *plugin) { if (plugin) delete plugin; } + }; + + /*! + Simplifies the process of building a plugin. + Put this macro somewhere in one of your plugin's .cpp files (but not in a namespace) + to export the necessary factory class for your plugin. + FQCLASS must have a constructor with the signature (IPluginFactory&, IContext&). + \param NAME A short name for your plugin with no spaces (a bareword, not a string). + \param FQCLASS The fully qualified name of the IPlugin subclass that the factory will construct. + */ + #define MAKE_BLACK_PLUGIN(NAME, FQCLASS, DESCR) \ + class CPluginFactory_##NAME : public BlackMisc::CPluginFactory \ + { \ + const char *getName() const { return #NAME ; } \ + const char *getDescription() const { return DESCR; } \ + }; \ + Q_EXPORT_PLUGIN2(NAME, CPluginFactory_##NAME ) + + /*! + Custom deleter for QScopedPointer. + */ + struct TPluginDeleter + { + static void cleanup(IPlugin *plugin) + { + if (plugin) { + plugin->getFactory().destroy(plugin); + } + } + }; + +} //namespace BlackMisc + +#endif //BLACKMISC_PLUGINS_H \ No newline at end of file From de1d46aa731a59d9cc602c09837439bb409dd445 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 18 Apr 2013 23:05:28 +0100 Subject: [PATCH 12/12] #31 CApplicationContext: fixed setDebug and getDebug (thanks Roland) --- src/blackmisc/context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/blackmisc/context.cpp b/src/blackmisc/context.cpp index 7ab4e673b..6cf9a80d4 100644 --- a/src/blackmisc/context.cpp +++ b/src/blackmisc/context.cpp @@ -61,12 +61,12 @@ namespace BlackMisc CDebug *CApplicationContext::getDebug() { - return qobject_cast(singleton("CDebug")); + return IContext::singleton(); } void CApplicationContext::setDebug(CDebug *debug) { - setSingleton("CDebug", debug); + IContext::setSingleton(debug); } void CApplicationContext::setDefaultApplicationName()