Refactored inheritance hierarchy of ContextApplication

refs #85
This commit is contained in:
Roland Winklmeier
2014-03-08 16:45:52 +01:00
parent eccfae1fd3
commit 1e8a2a5b01
9 changed files with 191 additions and 155 deletions

View File

@@ -3,7 +3,10 @@
#include "blackgui/atcstationlistmodel.h" #include "blackgui/atcstationlistmodel.h"
#include "blackcore/dbus_server.h" #include "blackcore/dbus_server.h"
#include "blackcore/context_network.h" #include "blackcore/context_network.h"
#include "blackcore/context_application.h"
#include "blackmisc/avaircraft.h" #include "blackmisc/avaircraft.h"
#include <QMouseEvent> #include <QMouseEvent>
using namespace BlackCore; using namespace BlackCore;

View File

@@ -13,9 +13,9 @@
#include "infowindow.h" #include "infowindow.h"
#include "guimodeenums.h" #include "guimodeenums.h"
#include "blackcore/context_voice.h" #include "blackcore/context_voice.h"
#include "blackcore/context_network_interface.h" #include "blackcore/context_network.h"
#include "blackcore/context_settings_interface.h" #include "blackcore/context_settings_interface.h"
#include "blackcore/context_application_interface.h" #include "blackcore/context_application.h"
#include "blackcore/context_simulator.h" #include "blackcore/context_simulator.h"
#include "blackcore/coreruntime.h" #include "blackcore/coreruntime.h"
#include "blackgui/atcstationlistmodel.h" #include "blackgui/atcstationlistmodel.h"

View File

@@ -4,6 +4,8 @@
#include "blackcore/context_network.h" #include "blackcore/context_network.h"
#include "blackcore/context_simulator_impl.h" #include "blackcore/context_simulator_impl.h"
#include "blackcore/context_simulator_proxy.h" #include "blackcore/context_simulator_proxy.h"
#include "blackcore/context_application_impl.h"
#include "blackcore/context_application_proxy.h"
#include "blackcore/coreruntime.h" #include "blackcore/coreruntime.h"
#include "blackgui/atcstationlistmodel.h" #include "blackgui/atcstationlistmodel.h"
#include "blackgui/keyboardkeylistmodel.h" #include "blackgui/keyboardkeylistmodel.h"
@@ -167,7 +169,7 @@ void MainWindow::init(GuiModes::CoreMode coreMode)
this->m_contextNetwork = new BlackCore::IContextNetwork(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); this->m_contextNetwork = new BlackCore::IContextNetwork(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this);
this->m_contextVoice = new BlackCore::IContextVoice(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); this->m_contextVoice = new BlackCore::IContextVoice(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this);
this->m_contextSettings = new BlackCore::IContextSettings(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); this->m_contextSettings = new BlackCore::IContextSettings(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this);
this->m_contextApplication = new BlackCore::IContextApplication(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); this->m_contextApplication = new BlackCore::CContextApplicationProxy(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this);
this->m_contextSimulator = new BlackCore::CContextSimulatorProxy(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); this->m_contextSimulator = new BlackCore::CContextSimulatorProxy(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this);
} }
else else

View File

@@ -6,59 +6,65 @@
#ifndef BLACKCORE_CONTEXTAPPLICATION_H #ifndef BLACKCORE_CONTEXTAPPLICATION_H
#define BLACKCORE_CONTEXTAPPLICATION_H #define BLACKCORE_CONTEXTAPPLICATION_H
#include "blackcore/dbus_server.h"
#include "blackcore/context_application_interface.h"
#include "blackmisc/statusmessage.h" #include "blackmisc/statusmessage.h"
#include "blackmisc/statusmessagelist.h"
#include "blackcore/coreruntime.h"
#include <QObject> #include <QObject>
#define BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME "blackcore.contextapplication" #define BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME "net.vatsim.PilotClient.BlackCore.ContextApplication"
#define BLACKCORE_CONTEXTAPPLICATION_OBJECTPATH "/Application"
namespace BlackCore namespace BlackCore
{ {
class CCoreRuntime;
/*! /*!
* \brief Application context * \brief Application context interface
*/ */
class CContextApplication : public IContextApplication class IContextApplication : public QObject
{ {
// Register by same name, make signals sender independent
// http://dbus.freedesktop.org/doc/dbus-faq.html#idp48032144
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME)
Q_OBJECT Q_OBJECT
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME)
public: public:
/*! /*!
* Context * \brief Service name
* \param parent * \return
*/ */
CContextApplication(CCoreRuntime *parent); static const QString &InterfaceName()
{
static QString s(BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME);
return s;
}
/*!
* \brief Service path
* \return
*/
static const QString &ObjectPath()
{
static QString s(BLACKCORE_CONTEXTAPPLICATION_OBJECTPATH);
return s;
}
/*!
* \brief DBus version constructor
* \param parent
*/
IContextApplication(QObject *parent = nullptr) : QObject(parent) {}
/*! /*!
* Destructor * Destructor
*/ */
virtual ~CContextApplication() {} virtual ~IContextApplication() {}
/*! signals:
* \brief Register myself in DBus //! \brief Status message
* \param server void statusMessage(const BlackMisc::CStatusMessage &message);
*/
void registerWithDBus(CDBusServer *server)
{
server->addObject(IContextApplication::ServicePath(), this);
}
/*! //! Widget GUI is about to start
* \brief Runtime void widgetGuiStarting() const;
* \return
*/ //! Widget GUI is about to terminate
const CCoreRuntime *getRuntime() const void widgetGuiTerminating() const;
{
return static_cast<CCoreRuntime *>(this->parent());
}
public slots: public slots:
@@ -67,7 +73,7 @@ namespace BlackCore
* \param token * \param token
* \return * \return
*/ */
qint64 ping(qint64 token) const; virtual qint64 ping(qint64 token) const = 0;
}; };
} }

View File

@@ -3,12 +3,10 @@
* 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 "context_application.h" #include "context_application_impl.h"
#include "coreruntime.h" #include "coreruntime.h"
#include "blackmisc/settingutilities.h" #include "blackmisc/settingutilities.h"
using namespace BlackMisc::Settings;
using namespace BlackMisc::Network;
using namespace BlackMisc; using namespace BlackMisc;
namespace BlackCore namespace BlackCore
@@ -17,7 +15,7 @@ namespace BlackCore
/* /*
* Init this context * Init this context
*/ */
CContextApplication::CContextApplication(CCoreRuntime *parent) : IContextApplication(parent) CContextApplication::CContextApplication(QObject *parent) : IContextApplication(parent)
{ {
// void // void
} }

View File

@@ -0,0 +1,73 @@
/* 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 BLACKCORE_CONTEXTAPPLICATION_IMPL_H
#define BLACKCORE_CONTEXTAPPLICATION_IMPL_H
#include "context_application.h"
#include "coreruntime.h"
#include "dbus_server.h"
namespace BlackCore
{
class CCoreRuntime;
/*!
* \brief Application context
*/
class CContextApplication : public IContextApplication
{
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME)
Q_OBJECT
public:
/*!
* Context
* \param parent
*/
CContextApplication(QObject *parent = nullptr);
/*!
* Destructor
*/
virtual ~CContextApplication() {}
/*!
* \brief Register myself in DBus
* \param server
*/
void registerWithDBus(CDBusServer *server)
{
server->addObject(IContextApplication::ObjectPath(), this);
}
/*!
* \brief Runtime
* \return
*/
CCoreRuntime *getRuntime()
{
return static_cast<CCoreRuntime *>(this->parent());
}
/*!
* \brief Const runtime
* \return
*/
const CCoreRuntime *getRuntime() const
{
return static_cast<CCoreRuntime *>(this->parent());
}
public slots:
//! \copydoc IContextApplication::ping()
virtual qint64 ping(qint64 token) const override;
};
}
#endif // guard

View File

@@ -1,108 +0,0 @@
/* 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 BLACKCORE_CONTEXTAPPLICATION_INTERFACE_H
#define BLACKCORE_CONTEXTAPPLICATION_INTERFACE_H
#include "blackmisc/genericdbusinterface.h"
#include "blackmisc/settingutilities.h"
#include "blackmisc/setnetwork.h"
#include "blackmisc/statusmessagelist.h"
#include <QObject>
#include <QVariant>
#include <QDBusAbstractInterface>
#define BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME "blackcore.contextapplication"
#define BLACKCORE_CONTEXTAPPLICATION_SERVICEPATH "/application"
// SERVICENAME must contain at least one ".", otherwise generation fails
// as this is interpreted in the way comain.somename
namespace BlackCore
{
/*!
* \brief The interface context settings
*/
class IContextApplication : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME)
public:
/*!
* \brief Service name
* \return
*/
static const QString &InterfaceName()
{
static QString s(BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME);
return s;
}
/*!
* \brief Service path
* \return
*/
static const QString &ServicePath()
{
static QString s(BLACKCORE_CONTEXTAPPLICATION_SERVICEPATH);
return s;
}
/*!
* \brief DBus version constructor
* \param serviceName
* \param connection
* \param parent
*/
IContextApplication(const QString &serviceName, QDBusConnection &connection, QObject *parent = 0);
/*!
* Destructor
*/
~IContextApplication() {}
private:
BlackMisc::CGenericDBusInterface *m_dBusInterface;
/*!
* Relay connection signals to local signals
* No idea why this has to be wired and is not done automatically
* \param connection
*/
void relaySignals(const QString &serviceName, QDBusConnection &connection);
protected:
/*!
* \brief IContextApplication
* \param parent
*/
IContextApplication(QObject *parent = nullptr) : QObject(parent), m_dBusInterface(nullptr) {}
signals:
//! \brief Status message
void statusMessage(const BlackMisc::CStatusMessage &message);
//! Widget GUI is about to start
void widgetGuiStarting() const;
//! Widget GUI is about to terminate
void widgetGuiTerminating() const;
public slots:
/*!
* \brief Ping
* \param token
* \return
*/
virtual qint64 ping(qint64 token) const;
};
}
#endif // guard

View File

@@ -3,7 +3,7 @@
* 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 "blackcore/context_application_interface.h" #include "blackcore/context_application_proxy.h"
#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h"
#include <QObject> #include <QObject>
#include <QMetaEnum> #include <QMetaEnum>
@@ -15,29 +15,29 @@ namespace BlackCore
/* /*
* Constructor for DBus * Constructor for DBus
*/ */
IContextApplication::IContextApplication(const QString &serviceName, QDBusConnection &connection, QObject *parent) : QObject(parent), m_dBusInterface(0) CContextApplicationProxy::CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, QObject *parent) : IContextApplication(parent), m_dBusInterface(nullptr)
{ {
this->m_dBusInterface = new BlackMisc::CGenericDBusInterface(serviceName , IContextApplication::ServicePath(), IContextApplication::InterfaceName(), connection, this); this->m_dBusInterface = new BlackMisc::CGenericDBusInterface(serviceName , IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), connection, this);
this->relaySignals(serviceName, connection); this->relaySignals(serviceName, connection);
} }
/* /*
* Workaround for signals * Workaround for signals
*/ */
void IContextApplication::relaySignals(const QString &serviceName, QDBusConnection &connection) void CContextApplicationProxy::relaySignals(const QString &serviceName, QDBusConnection &connection)
{ {
connection.connect(serviceName, IContextApplication::ServicePath(), IContextApplication::InterfaceName(), connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
"statusMessage", this, SIGNAL(statusMessage(BlackMisc::CStatusMessage))); "statusMessage", this, SIGNAL(statusMessage(BlackMisc::CStatusMessage)));
connection.connect(serviceName, IContextApplication::ServicePath(), IContextApplication::InterfaceName(), connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
"widgetGuiStarting", this, SIGNAL(widgetGuiStarting())); "widgetGuiStarting", this, SIGNAL(widgetGuiStarting()));
connection.connect(serviceName, IContextApplication::ServicePath(), IContextApplication::InterfaceName(), connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
"widgetGuiTerminating", this, SIGNAL(widgetGuiTerminating())); "widgetGuiTerminating", this, SIGNAL(widgetGuiTerminating()));
} }
/* /*
* Ping, is DBus alive? * Ping, is DBus alive?
*/ */
qint64 IContextApplication::ping(qint64 token) const qint64 CContextApplicationProxy::ping(qint64 token) const
{ {
qint64 t = this->m_dBusInterface->callDBusRet<qint64>(QLatin1Literal("ping"), token); qint64 t = this->m_dBusInterface->callDBusRet<qint64>(QLatin1Literal("ping"), token);
return t; return t;

View File

@@ -0,0 +1,62 @@
/* 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 BLACKCORE_CONTEXTAPPLICATION_PROXY_H
#define BLACKCORE_CONTEXTAPPLICATION_PROXY_H
#include "context_application.h"
#include "blackmisc/genericdbusinterface.h"
namespace BlackCore
{
/*!
* \brief Application context proxy
*/
class CContextApplicationProxy : public IContextApplication
{
Q_OBJECT
public:
/*!
* \brief DBus version constructor
* \param serviceName
* \param connection
* \param parent
*/
CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, QObject *parent = nullptr);
/*!
* Destructor
*/
virtual ~CContextApplicationProxy() {}
private:
BlackMisc::CGenericDBusInterface *m_dBusInterface;
/*!
* Relay connection signals to local signals
* No idea why this has to be wired and is not done automatically
* \param connection
*/
void relaySignals(const QString &serviceName, QDBusConnection &connection);
protected:
/*!
* \brief IContextApplication
* \param parent
*/
CContextApplicationProxy(QObject *parent = nullptr) : IContextApplication(parent), m_dBusInterface(nullptr) {}
public slots:
//! \copydoc IContextApplication::ping()
virtual qint64 ping(qint64 token) const override;
};
}
#endif // guard