diff --git a/samples/com_client/client.cpp b/samples/com_client/client.cpp index ce56654b0..4fdb3e1aa 100644 --- a/samples/com_client/client.cpp +++ b/samples/com_client/client.cpp @@ -6,8 +6,10 @@ using namespace BlackMisc; 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())); + connect(&comclient, &BlackMisc::CComClient::doError, + this, &Client::onError); + connect(&comclient, &BlackMisc::CComClient::doConnected, + this, &Client::onClientConnected); QString address = "127.0.0.1"; comclient.connectTo(address, 6809); @@ -33,4 +35,4 @@ void Client::onClientConnected() comclient.sendMessage(testmsg->getID(), message_data); delete testmsg; -} \ No newline at end of file +} diff --git a/samples/com_server/server.cpp b/samples/com_server/server.cpp index 31141e034..e47a9aa87 100644 --- a/samples/com_server/server.cpp +++ b/samples/com_server/server.cpp @@ -9,7 +9,8 @@ Server::Server(QObject *parent) : QObject(parent), server(IContext::getInstance( server.Host(local, 6809); - connect(&server, SIGNAL(doMessageReceived(QString &, QByteArray&)), this, SLOT(onData(QString &, QByteArray&))); + connect(&server, static_cast(&BlackMisc::CComServer::doMessageReceived), + this, &Server::onData); CMessageSystem myMessageSystem; diff --git a/samples/plugin/CMakeLists.txt b/samples/plugin/CMakeLists.txt index 63d30b352..20f045f54 100644 --- a/samples/plugin/CMakeLists.txt +++ b/samples/plugin/CMakeLists.txt @@ -1,6 +1,9 @@ FILE(GLOB SRC *.cpp) +SET(HEADERS server.h) -ADD_LIBRARY(sample_plugin MODULE ${SRC}) +QT4_WRAP_CPP(HEADERS_MOC ${HEADERS}) + +ADD_LIBRARY(sample_plugin MODULE ${SRC} ${HEADERS_MOC}) 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 index 0b183c767..8fcadd0f2 100644 --- a/samples/plugin/plugin.cpp +++ b/samples/plugin/plugin.cpp @@ -3,28 +3,9 @@ * 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 "plugin.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), diff --git a/samples/plugin/plugin.h b/samples/plugin/plugin.h new file mode 100644 index 000000000..e902e1b80 --- /dev/null +++ b/samples/plugin/plugin.h @@ -0,0 +1,37 @@ +/* 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/. */ + +#ifndef SAMPLE_PLUGIN_H +#define SAMPLE_PLUGIN_H + +#include "blackmisc/plugins.h" + +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; +}; + +// This needs to be in the header so that Qt's "moc" processor can see it. +class CPluginFactory : public QObject, public BlackMisc::IPluginFactory +{ + Q_OBJECT + Q_INTERFACES(BlackMisc::IPluginFactory) + Q_PLUGIN_METADATA(IID BLACKMISC_IPLUGINFACTORY_IID) + BLACKMISC_IMPLEMENT_IPLUGINFACTORY(CPlugin, "sample_plugin", "An example minimal plugin") +}; + +#endif //SAMPLE_PLUGIN_H \ No newline at end of file diff --git a/samples/plugin/sample_plugin.pro b/samples/plugin/sample_plugin.pro index c01de703c..e0e3f7291 100644 --- a/samples/plugin/sample_plugin.pro +++ b/samples/plugin/sample_plugin.pro @@ -9,6 +9,7 @@ DEPENDPATH += . ../../src INCLUDEPATH += . ../../src SOURCES += *.cpp +HEADERS += *.h LIBS += -L../../lib -lblackmisc diff --git a/src/blackbox/blackbox.cpp b/src/blackbox/blackbox.cpp index 4cddd2798..89a748a6d 100644 --- a/src/blackbox/blackbox.cpp +++ b/src/blackbox/blackbox.cpp @@ -21,8 +21,10 @@ BlackBox::BlackBox(QWidget *parent) : m_dlg_chat = new CDialogChat(); m_dlg_chat->hide(); - connect(ui->bt_Connect, SIGNAL(clicked()), this, SLOT(onConnect())); - connect(ui->bt_Chat, SIGNAL(clicked()), this, SLOT(onButtonChat())); + connect(ui->bt_Connect, &QPushButton::clicked, + this, &BlackBox::onConnect); + connect(ui->bt_Chat, &QPushButton::clicked, + this, &BlackBox::onButtonChat); } BlackBox::~BlackBox() diff --git a/src/blackbox/dialog_connect.cpp b/src/blackbox/dialog_connect.cpp index 49357850a..956288dd4 100644 --- a/src/blackbox/dialog_connect.cpp +++ b/src/blackbox/dialog_connect.cpp @@ -18,9 +18,12 @@ CDialogConnect::CDialogConnect(QWidget *parent) : { ui->setupUi(this); - connect(&comclient, SIGNAL(doError(QAbstractSocket::SocketError,QString)), this, SLOT(onError(QAbstractSocket::SocketError,QString))); - connect(&comclient, SIGNAL(doConnected()), this, SLOT(onClientConnected())); - connect(ui->bt_FSDConnect, SIGNAL(clicked()), this, SLOT(onFSDConnect())); + connect(&comclient, &BlackMisc::CComClient::doError, + this, &CDialogConnect::onError); + connect(&comclient, &BlackMisc::CComClient::doConnected, + this, &CDialogConnect::onClientConnected); + connect(ui->bt_FSDConnect, &QPushButton::clicked, + this, &CDialogConnect::onFSDConnect); QString address = "127.0.0.1"; comclient.connectTo(address, 42000); diff --git a/src/blackcore/fsd_client.cpp b/src/blackcore/fsd_client.cpp index 2f5445895..6a4e754c5 100644 --- a/src/blackcore/fsd_client.cpp +++ b/src/blackcore/fsd_client.cpp @@ -129,7 +129,7 @@ namespace FSD qint64 message_size = message.size(); - qint64 bytes = m_tcp_socket->write(message.toAscii()); + qint64 bytes = m_tcp_socket->write(message.toLatin1()); if (bytes < 0 || bytes != message_size) { bWarning(m_context) << "Error writing to socket!"; diff --git a/src/blackcore/pluginmgr.cpp b/src/blackcore/pluginmgr.cpp index ee86d592a..928a4a216 100644 --- a/src/blackcore/pluginmgr.cpp +++ b/src/blackcore/pluginmgr.cpp @@ -8,6 +8,7 @@ #include "blackmisc/context.h" #include #include +#include namespace BlackCore { @@ -41,7 +42,7 @@ namespace BlackCore { if (! loader->load()) { - throw; + throw std::runtime_error(QString("Failed loading plugin from %1").arg(filename).toStdString()); } PluginEntry entry; @@ -50,14 +51,14 @@ namespace BlackCore if (! entry.factory) { - throw; + throw std::runtime_error(QString("Plugin loaded from %1 is not compatible").arg(filename).toStdString()); } m_plugins.push_back(entry); } catch (...) { - //TODO warning + //TODO warning? } } } diff --git a/src/blackd/blackd.cpp b/src/blackd/blackd.cpp index 7d3d02d33..02e539e42 100644 --- a/src/blackd/blackd.cpp +++ b/src/blackd/blackd.cpp @@ -4,6 +4,8 @@ //! file, You can obtain one at http://mozilla.org/MPL/2.0/ #include +#include +#include #include "blackmisc/context.h" #include "blackmisc/debug.h" @@ -15,7 +17,6 @@ #include "blackd.h" #include "ui_blackd.h" -using namespace BlackMisc; using namespace FSD; @@ -28,8 +29,8 @@ BlackD::BlackD(QWidget *parent) : createActions(); createTrayIcon(); - connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), - this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); + connect(trayIcon, &QSystemTrayIcon::activated, + this, &BlackD::iconActivated); setWindowTitle(tr("BlackD")); @@ -43,7 +44,7 @@ BlackD::BlackD(QWidget *parent) : createComServer(); - m_fsd_client = new CFSDClient(IContext::getInstance()); + m_fsd_client = new CFSDClient(BlackMisc::IContext::getInstance()); bAppDebug << "BlackDaemon running..."; } @@ -129,8 +130,8 @@ void BlackD::createLogging() void BlackD::createComServer() { - CMessageFactory::getInstance().registerMessages(); - m_comserver = new CComServer(IContext::getInstance(), this); + BlackMisc::CMessageFactory::getInstance().registerMessages(); + m_comserver = new BlackMisc::CComServer(BlackMisc::IContext::getInstance(), this); registerMessageFunction(this, &BlackD::onMSG_CONNECT_TO_VATSIM); @@ -149,8 +150,8 @@ void BlackD::onData(QString &messageID, QByteArray &message) Q_ASSERT(test); *test << stream; - CMessageDispatcher::getInstance().append(test); - CMessageDispatcher::getInstance().dispatch(); + BlackMisc::CMessageDispatcher::getInstance().append(test); + BlackMisc::CMessageDispatcher::getInstance().dispatch(); } void BlackD::onMSG_CONNECT_TO_VATSIM(const BlackMisc::MSG_CONNECT_TO_VATSIM *connect) diff --git a/src/blackd/main.cpp b/src/blackd/main.cpp index de013e050..ac7f6ade7 100644 --- a/src/blackd/main.cpp +++ b/src/blackd/main.cpp @@ -4,9 +4,11 @@ //! file, You can obtain one at http://mozilla.org/MPL/2.0/ #include "blackmisc/context.h" +#include "blackmisc/debug.h" #include "blackd.h" #include +#include #include int main(int argc, char *argv[]) @@ -16,6 +18,8 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); BlackMisc::CApplicationContext myBlackApp; + BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); + if (!QSystemTrayIcon::isSystemTrayAvailable()) { QMessageBox::critical(0, QObject::tr("Systray"), QObject::tr("I couldn't detect any system tray " diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h index f7e49782f..412ff78f6 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/basestreamstringifier.h @@ -4,6 +4,7 @@ #include "blackmisc/debug.h" #include #include +#include #include #include diff --git a/src/blackmisc/logmessage.h b/src/blackmisc/logmessage.h index 019170574..f06d184cf 100644 --- a/src/blackmisc/logmessage.h +++ b/src/blackmisc/logmessage.h @@ -46,7 +46,6 @@ namespace BlackMisc inline CLogMessage &maybeSpace() { if (logStream->needSpace) logStream->output << ' '; return *this; } inline CLogMessage &operator<<(QChar t) { logStream->output << '\'' << t << '\''; return maybeSpace(); } - inline CLogMessage &operator<<(QBool t) { logStream->output << (bool(t != 0) ? "true" : "false"); return maybeSpace(); } inline CLogMessage &operator<<(bool t) { logStream->output << (t ? "true" : "false"); return maybeSpace(); } inline CLogMessage &operator<<(char t) { logStream->output << t; return maybeSpace(); } inline CLogMessage &operator<<(signed short t) { logStream->output << t; return maybeSpace(); } @@ -61,7 +60,7 @@ namespace BlackMisc { 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 char *t) { logStream->output << QString::fromLatin1(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(); } diff --git a/src/blackmisc/plugins.h b/src/blackmisc/plugins.h index 4178933bb..6e4182cd4 100644 --- a/src/blackmisc/plugins.h +++ b/src/blackmisc/plugins.h @@ -87,51 +87,6 @@ namespace BlackMisc 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. */ @@ -147,4 +102,22 @@ namespace BlackMisc } //namespace BlackMisc +//! Qt interface ID for IPluginFactory. +#define BLACKMISC_IPLUGINFACTORY_IID "net.vatsim.client.BlackMisc.IPluginFactory" + +Q_DECLARE_INTERFACE(BlackMisc::IPluginFactory, BLACKMISC_IPLUGINFACTORY_IID) + +/*! + Macro to put inside an IPluginFactory subclass to help with implementation. + \param CLASS The plugin class which this factory constructs. + \param NAME A string literal, the plugin's short name. + \param DESCRIPTION A string literal, a brief description of the plugin. +*/ +#define BLACKMISC_IMPLEMENT_IPLUGINFACTORY(CLASS, NAME, DESCRIPTION) \ + public: \ + BlackMisc::IPlugin *create(BlackMisc::IContext &context) { return new CLASS(*this, context); } \ + void destroy(BlackMisc::IPlugin *plugin) { if (plugin) delete plugin; } \ + const char *getName() const { return NAME; } \ + const char *getDescription() const { return DESCRIPTION; } + #endif //BLACKMISC_PLUGINS_H \ No newline at end of file