Merge branch 'master' into fsd

This commit is contained in:
Mathew Sutcliffe
2013-07-20 16:00:53 +01:00
15 changed files with 98 additions and 89 deletions

View File

@@ -6,8 +6,10 @@ using namespace BlackMisc;
Client::Client(QObject *parent) : QObject(parent), comclient(IContext::getInstance()) Client::Client(QObject *parent) : QObject(parent), comclient(IContext::getInstance())
{ {
connect(&comclient, SIGNAL(doError(QAbstractSocket::SocketError,QString)), this, SLOT(onError(QAbstractSocket::SocketError,QString))); connect(&comclient, &BlackMisc::CComClient::doError,
connect(&comclient, SIGNAL(doConnected()), this, SLOT(onClientConnected())); this, &Client::onError);
connect(&comclient, &BlackMisc::CComClient::doConnected,
this, &Client::onClientConnected);
QString address = "127.0.0.1"; QString address = "127.0.0.1";
comclient.connectTo(address, 6809); comclient.connectTo(address, 6809);

View File

@@ -9,7 +9,8 @@ Server::Server(QObject *parent) : QObject(parent), server(IContext::getInstance(
server.Host(local, 6809); server.Host(local, 6809);
connect(&server, SIGNAL(doMessageReceived(QString &, QByteArray&)), this, SLOT(onData(QString &, QByteArray&))); connect(&server, static_cast<void (BlackMisc::CComServer::*)(QString &, QByteArray &)>(&BlackMisc::CComServer::doMessageReceived),
this, &Server::onData);
CMessageSystem myMessageSystem; CMessageSystem myMessageSystem;

View File

@@ -1,6 +1,9 @@
FILE(GLOB SRC *.cpp) 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}) TARGET_LINK_LIBRARIES(sample_plugin blackmisc ${QT_LIBRARIES})
SET_TARGET_PROPERTIES(sample_plugin PROPERTIES PROJECT_LABEL "Samples - Plugin") SET_TARGET_PROPERTIES(sample_plugin PROPERTIES PROJECT_LABEL "Samples - Plugin")

View File

@@ -3,28 +3,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "blackmisc/plugins.h" #include "plugin.h"
#include <iostream> #include <iostream>
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) CPlugin::CPlugin(BlackMisc::IPluginFactory &factory, BlackMisc::IContext &context)
: m_ctorOK(false), : m_ctorOK(false),
m_factory(factory), m_factory(factory),

37
samples/plugin/plugin.h Normal file
View File

@@ -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

View File

@@ -9,6 +9,7 @@ DEPENDPATH += . ../../src
INCLUDEPATH += . ../../src INCLUDEPATH += . ../../src
SOURCES += *.cpp SOURCES += *.cpp
HEADERS += *.h
LIBS += -L../../lib -lblackmisc LIBS += -L../../lib -lblackmisc

View File

@@ -21,8 +21,10 @@ BlackBox::BlackBox(QWidget *parent) :
m_dlg_chat = new CDialogChat(); m_dlg_chat = new CDialogChat();
m_dlg_chat->hide(); m_dlg_chat->hide();
connect(ui->bt_Connect, SIGNAL(clicked()), this, SLOT(onConnect())); connect(ui->bt_Connect, &QPushButton::clicked,
connect(ui->bt_Chat, SIGNAL(clicked()), this, SLOT(onButtonChat())); this, &BlackBox::onConnect);
connect(ui->bt_Chat, &QPushButton::clicked,
this, &BlackBox::onButtonChat);
} }
BlackBox::~BlackBox() BlackBox::~BlackBox()

View File

@@ -18,9 +18,12 @@ CDialogConnect::CDialogConnect(QWidget *parent) :
{ {
ui->setupUi(this); ui->setupUi(this);
connect(&comclient, SIGNAL(doError(QAbstractSocket::SocketError,QString)), this, SLOT(onError(QAbstractSocket::SocketError,QString))); connect(&comclient, &BlackMisc::CComClient::doError,
connect(&comclient, SIGNAL(doConnected()), this, SLOT(onClientConnected())); this, &CDialogConnect::onError);
connect(ui->bt_FSDConnect, SIGNAL(clicked()), this, SLOT(onFSDConnect())); connect(&comclient, &BlackMisc::CComClient::doConnected,
this, &CDialogConnect::onClientConnected);
connect(ui->bt_FSDConnect, &QPushButton::clicked,
this, &CDialogConnect::onFSDConnect);
QString address = "127.0.0.1"; QString address = "127.0.0.1";
comclient.connectTo(address, 42000); comclient.connectTo(address, 42000);

View File

@@ -129,7 +129,7 @@ namespace FSD
qint64 message_size = message.size(); 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) if (bytes < 0 || bytes != message_size)
{ {
bWarning(m_context) << "Error writing to socket!"; bWarning(m_context) << "Error writing to socket!";

View File

@@ -8,6 +8,7 @@
#include "blackmisc/context.h" #include "blackmisc/context.h"
#include <QDirIterator> #include <QDirIterator>
#include <iostream> #include <iostream>
#include <stdexcept>
namespace BlackCore namespace BlackCore
{ {
@@ -41,7 +42,7 @@ namespace BlackCore
{ {
if (! loader->load()) if (! loader->load())
{ {
throw; throw std::runtime_error(QString("Failed loading plugin from %1").arg(filename).toStdString());
} }
PluginEntry entry; PluginEntry entry;
@@ -50,14 +51,14 @@ namespace BlackCore
if (! entry.factory) if (! entry.factory)
{ {
throw; throw std::runtime_error(QString("Plugin loaded from %1 is not compatible").arg(filename).toStdString());
} }
m_plugins.push_back(entry); m_plugins.push_back(entry);
} }
catch (...) catch (...)
{ {
//TODO warning //TODO warning?
} }
} }
} }

View File

@@ -4,6 +4,8 @@
//! file, You can obtain one at http://mozilla.org/MPL/2.0/ //! file, You can obtain one at http://mozilla.org/MPL/2.0/
#include <QtGui> #include <QtGui>
#include <QMessageBox>
#include <QMenu>
#include "blackmisc/context.h" #include "blackmisc/context.h"
#include "blackmisc/debug.h" #include "blackmisc/debug.h"
@@ -15,7 +17,6 @@
#include "blackd.h" #include "blackd.h"
#include "ui_blackd.h" #include "ui_blackd.h"
using namespace BlackMisc;
using namespace FSD; using namespace FSD;
@@ -28,8 +29,8 @@ BlackD::BlackD(QWidget *parent) :
createActions(); createActions();
createTrayIcon(); createTrayIcon();
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), connect(trayIcon, &QSystemTrayIcon::activated,
this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); this, &BlackD::iconActivated);
setWindowTitle(tr("BlackD")); setWindowTitle(tr("BlackD"));
@@ -43,7 +44,7 @@ BlackD::BlackD(QWidget *parent) :
createComServer(); createComServer();
m_fsd_client = new CFSDClient(IContext::getInstance()); m_fsd_client = new CFSDClient(BlackMisc::IContext::getInstance());
bAppDebug << "BlackDaemon running..."; bAppDebug << "BlackDaemon running...";
} }
@@ -129,8 +130,8 @@ void BlackD::createLogging()
void BlackD::createComServer() void BlackD::createComServer()
{ {
CMessageFactory::getInstance().registerMessages(); BlackMisc::CMessageFactory::getInstance().registerMessages();
m_comserver = new CComServer(IContext::getInstance(), this); m_comserver = new BlackMisc::CComServer(BlackMisc::IContext::getInstance(), this);
registerMessageFunction(this, &BlackD::onMSG_CONNECT_TO_VATSIM); registerMessageFunction(this, &BlackD::onMSG_CONNECT_TO_VATSIM);
@@ -149,8 +150,8 @@ void BlackD::onData(QString &messageID, QByteArray &message)
Q_ASSERT(test); Q_ASSERT(test);
*test << stream; *test << stream;
CMessageDispatcher::getInstance().append(test); BlackMisc::CMessageDispatcher::getInstance().append(test);
CMessageDispatcher::getInstance().dispatch(); BlackMisc::CMessageDispatcher::getInstance().dispatch();
} }
void BlackD::onMSG_CONNECT_TO_VATSIM(const BlackMisc::MSG_CONNECT_TO_VATSIM *connect) void BlackD::onMSG_CONNECT_TO_VATSIM(const BlackMisc::MSG_CONNECT_TO_VATSIM *connect)

View File

@@ -4,9 +4,11 @@
//! file, You can obtain one at http://mozilla.org/MPL/2.0/ //! file, You can obtain one at http://mozilla.org/MPL/2.0/
#include "blackmisc/context.h" #include "blackmisc/context.h"
#include "blackmisc/debug.h"
#include "blackd.h" #include "blackd.h"
#include <QApplication> #include <QApplication>
#include <QMessageBox>
#include <QtGui> #include <QtGui>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@@ -16,6 +18,8 @@ int main(int argc, char *argv[])
QApplication app(argc, argv); QApplication app(argc, argv);
BlackMisc::CApplicationContext myBlackApp; BlackMisc::CApplicationContext myBlackApp;
BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug());
if (!QSystemTrayIcon::isSystemTrayAvailable()) { if (!QSystemTrayIcon::isSystemTrayAvailable()) {
QMessageBox::critical(0, QObject::tr("Systray"), QMessageBox::critical(0, QObject::tr("Systray"),
QObject::tr("I couldn't detect any system tray " QObject::tr("I couldn't detect any system tray "

View File

@@ -4,6 +4,7 @@
#include "blackmisc/debug.h" #include "blackmisc/debug.h"
#include <QString> #include <QString>
#include <QtGlobal> #include <QtGlobal>
#include <QDataStream>
#include <QDebug> #include <QDebug>
#include <iostream> #include <iostream>

View File

@@ -46,7 +46,6 @@ namespace BlackMisc
inline CLogMessage &maybeSpace() { if (logStream->needSpace) logStream->output << ' '; return *this; } inline CLogMessage &maybeSpace() { if (logStream->needSpace) logStream->output << ' '; return *this; }
inline CLogMessage &operator<<(QChar t) { logStream->output << '\'' << t << '\''; return maybeSpace(); } 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<<(bool t) { logStream->output << (t ? "true" : "false"); return maybeSpace(); }
inline CLogMessage &operator<<(char t) { logStream->output << t; return maybeSpace(); } inline CLogMessage &operator<<(char t) { logStream->output << t; return maybeSpace(); }
inline CLogMessage &operator<<(signed short 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(); } { logStream->output << QString::number(t); return maybeSpace(); }
inline CLogMessage &operator<<(float t) { logStream->output << 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<<(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 QString &t) { logStream->output << '\"' << t << '\"'; return maybeSpace(); }
inline CLogMessage &operator<<(const QByteArray &t) { logStream->output << '\"' << t << '\"'; return maybeSpace(); } inline CLogMessage &operator<<(const QByteArray &t) { logStream->output << '\"' << t << '\"'; return maybeSpace(); }

View File

@@ -87,51 +87,6 @@ namespace BlackMisc
virtual const char *getDescription() const = 0; 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 P>
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<FQCLASS> \
{ \
const char *getName() const { return #NAME ; } \
const char *getDescription() const { return DESCR; } \
}; \
Q_EXPORT_PLUGIN2(NAME, CPluginFactory_##NAME )
/*! /*!
Custom deleter for QScopedPointer. Custom deleter for QScopedPointer.
*/ */
@@ -147,4 +102,22 @@ namespace BlackMisc
} //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 #endif //BLACKMISC_PLUGINS_H