diff --git a/samples/cli_client/client.cpp b/samples/cli_client/client.cpp index 9e06e66d8..7caff6c5d 100644 --- a/samples/cli_client/client.cpp +++ b/samples/cli_client/client.cpp @@ -8,8 +8,8 @@ #include #include -Client::Client() - : m_net(BlackMisc::IContext::getInstance().singleton()) +Client::Client(BlackMisc::IContext &ctx) + : m_net(&ctx.getObject()) { using namespace BlackCore; connect(m_net, &INetwork::atcPositionUpdate, this, &Client::atcPositionUpdate); diff --git a/samples/cli_client/client.h b/samples/cli_client/client.h index 65f6eaf8a..6c149ebbd 100644 --- a/samples/cli_client/client.h +++ b/samples/cli_client/client.h @@ -6,18 +6,19 @@ #ifndef __BLACKSAMPLE_CLI_CLIENT_H__ #define __BLACKSAMPLE_CLI_CLIENT_H__ +#include "blackcore/network.h" +#include "blackmisc/context.h" #include #include #include #include -#include "blackcore/network.h" class Client : public QObject { Q_OBJECT public: - Client(); + Client(BlackMisc::IContext &); signals: void quit(); diff --git a/samples/cli_client/main.cpp b/samples/cli_client/main.cpp index 1c7ed9f11..44cf0126a 100644 --- a/samples/cli_client/main.cpp +++ b/samples/cli_client/main.cpp @@ -4,6 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "blackcore/network_vatlib.h" +#include "blackmisc/context.h" #include "client.h" #include "reader.h" #include @@ -12,11 +13,15 @@ int main(int argc, char *argv[]) { QCoreApplication app (argc, argv); - BlackMisc::CApplicationContext myApplicationContext; - BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); - BlackMisc::IContext::getInstance().setSingleton(new BlackCore::NetworkVatlib()); - Client client; + BlackMisc::CApplicationContext ctx; + BlackMisc::IContext::setInstance(ctx); + BlackMisc::CDebug debug; + ctx.setObject(debug); + BlackCore::NetworkVatlib net; + ctx.setObject(net); + + Client client(ctx); LineReader reader; QObject::connect(&reader, SIGNAL(command(const QString&)), &client, SLOT(command(const QString&))); QObject::connect(&client, SIGNAL(quit()), &reader, SLOT(terminate())); diff --git a/samples/com_client/main.cpp b/samples/com_client/main.cpp index 081b6ec48..4f1a2f4a5 100644 --- a/samples/com_client/main.cpp +++ b/samples/com_client/main.cpp @@ -7,10 +7,12 @@ using namespace BlackMisc; int main(int argc, char *argv[]) { - BlackMisc::CApplicationContext myApplicationContext; QCoreApplication a(argc, argv); - BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + BlackMisc::CApplicationContext ctx; + BlackMisc::IContext::setInstance(ctx); + BlackMisc::CDebug debug; + ctx.setObject(debug); Client client; diff --git a/samples/com_server/main.cpp b/samples/com_server/main.cpp index c98e592f8..bb937fb3f 100644 --- a/samples/com_server/main.cpp +++ b/samples/com_server/main.cpp @@ -7,10 +7,12 @@ using namespace BlackMisc; int main(int argc, char *argv[]) { - BlackMisc::CApplicationContext myApplicationContext; QCoreApplication a(argc, argv); - BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + BlackMisc::CApplicationContext ctx; + BlackMisc::IContext::setInstance(ctx); + BlackMisc::CDebug debug; + ctx.setObject(debug); Server server; diff --git a/samples/config/main.cpp b/samples/config/main.cpp index ae7b719d8..7874fbcb2 100644 --- a/samples/config/main.cpp +++ b/samples/config/main.cpp @@ -10,9 +10,11 @@ using namespace BlackMisc; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); - BlackMisc::CApplicationContext myApplicationContext; - BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + BlackMisc::CApplicationContext ctx; + BlackMisc::IContext::setInstance(ctx); + BlackMisc::CDebug debug; + ctx.setObject(debug); CConfigManager::getInstance().setConfigPath(QString("config")); if (!CConfigManager::getInstance().readConfig()) diff --git a/samples/interpolator/main.cpp b/samples/interpolator/main.cpp index 92c4b3bfa..0aef41e10 100644 --- a/samples/interpolator/main.cpp +++ b/samples/interpolator/main.cpp @@ -22,7 +22,11 @@ using namespace BlackMisc::Aviation; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); - BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + + BlackMisc::CApplicationContext ctx; + BlackMisc::IContext::setInstance(ctx); + BlackMisc::CDebug debug; + ctx.setObject(debug); QElapsedTimer timer; diff --git a/samples/logging/main.cpp b/samples/logging/main.cpp index 1ad1a607a..05aa9089d 100644 --- a/samples/logging/main.cpp +++ b/samples/logging/main.cpp @@ -7,9 +7,11 @@ int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); - BlackMisc::CApplicationContext myApplicationContext; - BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + BlackMisc::CApplicationContext ctx; + BlackMisc::IContext::setInstance(ctx); + BlackMisc::CDebug debug; + ctx.setObject(debug); bAppInfo << "This is a Info log message"; bAppWarning << "This is a bWarning log message"; diff --git a/samples/pluginmgr/main.cpp b/samples/pluginmgr/main.cpp index dcb64e883..47d174c2e 100644 --- a/samples/pluginmgr/main.cpp +++ b/samples/pluginmgr/main.cpp @@ -9,9 +9,11 @@ int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); - BlackMisc::CApplicationContext myApplicationContext; - BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + BlackMisc::CApplicationContext ctx; + BlackMisc::IContext::setInstance(ctx); + BlackMisc::CDebug debug; + ctx.setObject(debug); { const QString pluginPath = "../../build/bin"; diff --git a/src/blackbox/dialog_connect.cpp b/src/blackbox/dialog_connect.cpp index 802430a48..73aad4914 100644 --- a/src/blackbox/dialog_connect.cpp +++ b/src/blackbox/dialog_connect.cpp @@ -9,6 +9,7 @@ #include "blackmisc/debug.h" #include "blackmisc/message.h" #include "blackmisc/gui_messages.h" +#include "blackmisc/context.h" using namespace BlackMisc; diff --git a/src/blackbox/main.cpp b/src/blackbox/main.cpp index 1bf40f033..0336b7977 100644 --- a/src/blackbox/main.cpp +++ b/src/blackbox/main.cpp @@ -11,7 +11,11 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + + BlackMisc::CApplicationContext ctx; + BlackMisc::IContext::setInstance(ctx); + BlackMisc::CDebug debug; + ctx.setObject(debug); BlackBox w; w.show(); diff --git a/src/blackcore/atclistmgr.cpp b/src/blackcore/atclistmgr.cpp index 622b0444b..4b3ff7437 100644 --- a/src/blackcore/atclistmgr.cpp +++ b/src/blackcore/atclistmgr.cpp @@ -6,9 +6,9 @@ #include "atclistmgr.h" #include "network.h" -BlackCore::CAtcListManager::CAtcListManager() +BlackCore::CAtcListManager::CAtcListManager(BlackMisc::IContext &ctx) { - INetwork *net = BlackMisc::IContext::getInstance().singleton(); + INetwork *net = &ctx.getObject(); connect(net, &INetwork::atcPositionUpdate, this, &CAtcListManager::update, Qt::QueuedConnection); connect(net, &INetwork::atcDisconnected, this, &CAtcListManager::remove, Qt::QueuedConnection); diff --git a/src/blackcore/atclistmgr.h b/src/blackcore/atclistmgr.h index bbd4af67f..0942b31a4 100644 --- a/src/blackcore/atclistmgr.h +++ b/src/blackcore/atclistmgr.h @@ -25,8 +25,6 @@ namespace BlackCore Q_PROPERTY(BlackMisc::CAtcList list READ getList NOTIFY listChanged) public: - BLACK_INTERFACE(BlackCore::IAtcListManager) - /*! * Virtual destructor. */ @@ -49,7 +47,7 @@ namespace BlackCore /*! * Concrete ATC list manager. Implementation of IAtcListManager. * - * Has a dependency on INetwork. An INetwork must be available through the IContext singleton. + * Has a dependency on INetwork. An INetwork must be available through the IContext. */ class CAtcListManager : public IAtcListManager { @@ -58,8 +56,9 @@ namespace BlackCore public: /*! * Constructor. + * \param context */ - CAtcListManager(); + CAtcListManager(BlackMisc::IContext &context); virtual const BlackMisc::CAtcList& getList() const { return m_list; } diff --git a/src/blackcore/network.h b/src/blackcore/network.h index 2264ae6c7..3b66196ba 100644 --- a/src/blackcore/network.h +++ b/src/blackcore/network.h @@ -34,8 +34,6 @@ namespace BlackCore Q_OBJECT public: - BLACK_INTERFACE(BlackCore::INetwork) - virtual ~INetwork() {} enum diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index 495118829..3056c8fb2 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -14,7 +14,7 @@ #include "blackcore/simulator.h" #include "blackmisc/debug.h" - +#include "blackmisc/context.h" #include #include diff --git a/src/blackd/blackd.cpp b/src/blackd/blackd.cpp index 02e539e42..fd18bd94d 100644 --- a/src/blackd/blackd.cpp +++ b/src/blackd/blackd.cpp @@ -118,14 +118,14 @@ void BlackD::createTrayIcon() void BlackD::createLogging() { - BlackMisc::IContext::getInstance().getDebug()->create(); + BlackMisc::IContext::getInstance().getDebug().create(); m_displayer = new CQtDisplayer(ui->logginView); - 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()->getErrorLog()->attachDisplay(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().getErrorLog()->attachDisplay(m_displayer); } void BlackD::createComServer() diff --git a/src/blackd/main.cpp b/src/blackd/main.cpp index ac7f6ade7..226003f1e 100644 --- a/src/blackd/main.cpp +++ b/src/blackd/main.cpp @@ -18,7 +18,10 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); BlackMisc::CApplicationContext myBlackApp; - BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + BlackMisc::CApplicationContext ctx; + BlackMisc::IContext::setInstance(ctx); + BlackMisc::CDebug debug; + ctx.setObject(debug); if (!QSystemTrayIcon::isSystemTrayAvailable()) { QMessageBox::critical(0, QObject::tr("Systray"), diff --git a/src/blackmisc/com_handler.cpp b/src/blackmisc/com_handler.cpp index 0a95e7e43..582e81ab0 100644 --- a/src/blackmisc/com_handler.cpp +++ b/src/blackmisc/com_handler.cpp @@ -5,6 +5,7 @@ #include "blackmisc/com_handler.h" #include "blackmisc/debug.h" +#include "blackmisc/context.h" #include #include diff --git a/src/blackmisc/config.cpp b/src/blackmisc/config.cpp index f6dd5edb2..da9afb02d 100644 --- a/src/blackmisc/config.cpp +++ b/src/blackmisc/config.cpp @@ -5,6 +5,7 @@ #include "blackmisc/config.h" #include "blackmisc/debug.h" +#include "blackmisc/context.h" #include #include diff --git a/src/blackmisc/context.cpp b/src/blackmisc/context.cpp index 6cf9a80d4..76c56fc06 100644 --- a/src/blackmisc/context.cpp +++ b/src/blackmisc/context.cpp @@ -6,7 +6,6 @@ #include "blackmisc/debug.h" #include "blackmisc/context.h" #include -#include #ifdef Q_OS_WIN #include @@ -15,10 +14,21 @@ namespace BlackMisc { - IContext &IContext::getInstance() + IContext *&instancePointer() { static CApplicationContext context; - return context; + static IContext *ptr = &context; + return ptr; + } + + void IContext::setInstance(IContext &context) + { + instancePointer() = &context; + } + + IContext &IContext::getInstance() + { + return *instancePointer(); } IContext::~IContext() @@ -29,44 +39,20 @@ namespace BlackMisc { } - QObject *CApplicationContext::singleton(const QString &singletonName) + const QObject *CApplicationContext::getQObjectNothrow(const QString &name) const { - TSingletonMap::const_iterator it = m_singletons.find(singletonName); - if (it != m_singletons.end()) - { - return it.value(); - } - throw std::logic_error("Requested singleton not present"); + auto it = m_map.find(name); + return it == m_map.end() ? nullptr : it.value(); } - bool CApplicationContext::hasSingleton(const QString &singletonName) const + void CApplicationContext::setQObject(QString name, QObject &object) { - TSingletonMap::const_iterator it = m_singletons.find(singletonName); - if (it != m_singletons.end()) - { - return true; - } - return false; + m_map.insert(name, &object); } - void CApplicationContext::setSingleton(const QString &singletonName, QObject *object) + void CApplicationContext::removeQObject(const QString &name) { - m_singletons.insert(singletonName, object); - } - - void CApplicationContext::releaseSingleton(const QString &singletonName) - { - m_singletons.remove(singletonName); - } - - CDebug *CApplicationContext::getDebug() - { - return IContext::singleton(); - } - - void CApplicationContext::setDebug(CDebug *debug) - { - IContext::setSingleton(debug); + m_map.remove(name); } void CApplicationContext::setDefaultApplicationName() diff --git a/src/blackmisc/context.h b/src/blackmisc/context.h index de2c3ab9c..ac1505fb2 100644 --- a/src/blackmisc/context.h +++ b/src/blackmisc/context.h @@ -6,178 +6,202 @@ #ifndef BLACKMISC_CONTEXT_H #define BLACKMISC_CONTEXT_H +#include "blackmisc/debug.h" +#include #include #include +#include namespace BlackMisc { - class CDebug; - /*! - Keeps track of all singleton and pseudo-singleton objects. - */ + * Provides centralized modular access to long-lived interface objects. + */ class IContext { public: /*! - Returns a reference to the static global context singleton. - \return - \warning Do not use this from within a plugin. - */ + * Returns a reference to a static global context singleton. + * \return + * \warning Do not use this in code which could be called from within a plugin. + * \deprecated Provided as a crutch to ease transition from singleton-based design. + */ static IContext &getInstance(); /*! - Destructor. - */ + * Allows for apps to set the static global context singleton. + * \deprecated Provided as a crutch to ease transition from singleton-based design. + */ + static void setInstance(IContext &); + + /*! + * Destructor. + */ virtual ~IContext(); /*! - 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 QObject *singleton(const QString &singletonName) = 0; - - /*! - 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 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() + * Returns true if an object with the given name is present. + * You usually use the type-safe hasObject method instead. + * \param name + * \return + */ + bool hasQObject(const QString &name) { - QObject *qobj = singleton(T::blackInterfaceId()); - T *t = qobject_cast(qobj); - Q_ASSERT_X(t, "IContext", "qobject_cast failed"); - return t; + return getQObjectNothrow(name); } /*! - 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 + * Set the object pointer with the type T. + * \tparam T A class derived from QObject using the Q_OBJECT macro. + * \param object + * \param name The name of the object; default is the name of its class, T. + */ + template void setObject(T &object, QString name = T::staticMetaObject.className()) { - return hasSingleton(T::blackInterfaceId()); + setQObject(name, object); } /*! - 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) + * Remove the object pointer with the type T. + * \tparam T A class derived from QObject using the Q_OBJECT macro. + * \param name The name of the object; default is the name of its class T. + */ + template void removeObject(const QString &name = T::staticMetaObject.className()) { - setSingleton(T::blackInterfaceId(), object); + removeQObject(name); } /*! - Remove the singleton pointer with the type T. - \tparam T An interface defined with the BLACK_INTERFACE macro. - */ - template - void releaseSingleton() + * Return an object pointer of the class T. + * \tparam T A class derived from QObject using the Q_OBJECT macro. + * \param name The name of the object; default is the name of its class, T. + * \return + * \throw std::logic_error The requested object is not present. + */ + template T &getObject(const QString &name = T::staticMetaObject.className()) { - releaseSingleton(T::blackInterfaceId()); + T *obj = qobject_cast(getQObjectNothrow(name)); + if (!obj) { throw std::logic_error("IContext: qobject_cast failed"); } + return *obj; } /*! - Set the global name of the application. - \param appName - */ - virtual void setApplicationName(const QString &appName) = 0; + * Return true if the requested object in present in the context. + * \tparam T A class derived from QObject using the Q_OBJECT macro. + * \param name The name of the object; default is the name of its class, T. + * \return + */ + template bool hasObject(const QString &name = T::staticMetaObject.className()) const + { + QObject *qobj = getQObjectNothrow(name); + return qobj && qobject_cast(qobj); + } /*! - Set the application name to the default. - */ + * Sets an object pointer, given by its name. + * You usually use the type-safe setObject method instead. + * \param object + * \param name + */ + virtual void setQObject(QString name, QObject &object) = 0; + + /*! + * Removes an object pointer, given by its name. + * You usually use the type-safe removeObject method instead. + * \param name + * \param object + */ + virtual void removeQObject(const QString &name) = 0; + + /*! + * Like getQObject but returns nullptr instead of throwing an exception. + * \param name + * \return + */ + virtual const QObject *getQObjectNothrow(const QString &name) const = 0; + + /*! + * Like getQObject but returns nullptr instead of throwing an exception. + * \param name + * \return + */ + QObject *getQObjectNothrow(const QString &name) + { + return const_cast(static_cast(this)->getQObjectNothrow(name)); + } + + /*! + * Returns the pointer to an object by its name. + * You usually use the type-safe getObject method instead. + * \param name + * \return + * \throw std::logic_error The requested object is not present. + */ + QObject &getQObject(const QString &name) + { + QObject *qobj = getQObjectNothrow(name); + if (!qobj) { throw std::logic_error("IContext: named object not found"); } + return *qobj; + } + + /*! + * Set the global name of the application. + * \param appName + */ + virtual void setApplicationName(QString appName) = 0; + + /*! + * Set the application name to the default. + */ virtual void setDefaultApplicationName() = 0; /*! - Return the global name of the application. - \return - */ + * 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; + * Return the CDebug object. + * \return + * \throw std::logic_error The requested object is not present. + */ + CDebug &getDebug() + { + return getObject(); + } /*! - Set the CDebug singleton. - \param debug - \deprecated Use setSingletonPointer() instead. - */ - virtual void setDebug(CDebug *debug) = 0; + * Set the CDebug object. + * \param debug + */ + void setDebug(CDebug &debug) + { + setObject(debug); + } }; /*! - 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. - */ + * Default implementation of the IContext interface. + */ class CApplicationContext : public IContext { public: /*! - Constructor - */ + * 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 const QObject *getQObjectNothrow(const QString &) const; + virtual void setQObject(QString, QObject &); + virtual void removeQObject(const QString &); + virtual void setApplicationName(QString appName) { m_appName = appName; } virtual void setDefaultApplicationName(); virtual const QString &getApplicationName() const { return m_appName; } private: - typedef QMap TSingletonMap; - - TSingletonMap m_singletons; - + QMap m_map; QString m_appName; }; @@ -186,7 +210,7 @@ namespace BlackMisc 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, + construct would-be singletons and register them manually, and when you want to access them, do it through the IContext. */ #define SINGLETON_CLASS_DECLARATION(className) \ @@ -202,15 +226,15 @@ public:\ if (m_instance == NULL) \ { \ /* Get the singleton object from the context, if there is one */ \ - if (BlackMisc::IContext::getInstance().hasSingleton(#className)) \ + if (BlackMisc::IContext::getInstance().hasQObject(#className)) \ { \ - m_instance = reinterpret_cast(BlackMisc::IContext::getInstance().singleton(#className)); \ + m_instance = static_cast(&BlackMisc::IContext::getInstance().getQObject(#className)); \ } \ else \ { \ /* We have no allocated object yet, so do it now. */ \ m_instance = new className; \ - BlackMisc::IContext::getInstance().setSingleton(#className, m_instance); \ + BlackMisc::IContext::getInstance().setQObject(#className, *m_instance); \ } \ } \ return *m_instance; \ diff --git a/src/blackmisc/debug.cpp b/src/blackmisc/debug.cpp index a07368c82..79a90889f 100644 --- a/src/blackmisc/debug.cpp +++ b/src/blackmisc/debug.cpp @@ -1,6 +1,7 @@ #include "blackmisc/debug.h" #include "blackmisc/log.h" #include "blackmisc/display.h" +#include "blackmisc/context.h" #include #include diff --git a/src/blackmisc/debug.h b/src/blackmisc/debug.h index 05beb241f..2b5d62ae9 100644 --- a/src/blackmisc/debug.h +++ b/src/blackmisc/debug.h @@ -6,7 +6,6 @@ #ifndef BLACKMISC_DEBUG_H #define BLACKMISC_DEBUG_H -#include "blackmisc/context.h" #include "blackmisc/log.h" #include "blackmisc/display.h" #include "blackmisc/logmessage.h" @@ -26,8 +25,6 @@ namespace BlackMisc Q_OBJECT public: - BLACK_INTERFACE(BlackMisc::CDebug) - CDebug(); // internal use only @@ -110,10 +107,10 @@ namespace BlackMisc 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 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()) diff --git a/src/blackmisc/logmessage.h b/src/blackmisc/logmessage.h index f06d184cf..74e3c04db 100644 --- a/src/blackmisc/logmessage.h +++ b/src/blackmisc/logmessage.h @@ -7,7 +7,6 @@ #define LOGMESSAGE_H #include "blackmisc/log.h" -#include "blackmisc/context.h" #include namespace BlackMisc diff --git a/tests/blackcore/testnetmediators.cpp b/tests/blackcore/testnetmediators.cpp index e551b0816..db26daf63 100644 --- a/tests/blackcore/testnetmediators.cpp +++ b/tests/blackcore/testnetmediators.cpp @@ -17,17 +17,17 @@ namespace BlackCoreTest void CTestNetMediators::initTestCase() { - BlackMisc::IContext::getInstance().setSingleton(&m_networkDummy); + m_context.setObject(m_networkDummy); } void CTestNetMediators::cleanupTestCase() { - BlackMisc::IContext::getInstance().releaseSingleton(); + m_context.removeObject(); } void CTestNetMediators::atcListManagerTest() { - CAtcListManager mgr; + CAtcListManager mgr(m_context); AtcListConsumer cons; QObject::connect(&mgr, &IAtcListManager::listChanged, &cons, &AtcListConsumer::listChanged); diff --git a/tests/blackcore/testnetmediators.h b/tests/blackcore/testnetmediators.h index 7cfac4993..6dada2a07 100644 --- a/tests/blackcore/testnetmediators.h +++ b/tests/blackcore/testnetmediators.h @@ -45,6 +45,7 @@ namespace BlackCoreTest void cleanupTestCase(); private: + BlackMisc::CApplicationContext m_context; BlackCore::NetworkDummy m_networkDummy; };