diff --git a/samples/blackgui/mainwindow.cpp b/samples/blackgui/mainwindow.cpp index 0a7df0cef..6a0ee461a 100644 --- a/samples/blackgui/mainwindow.cpp +++ b/samples/blackgui/mainwindow.cpp @@ -3,7 +3,10 @@ #include "blackgui/atcstationlistmodel.h" #include "blackcore/dbus_server.h" #include "blackcore/context_network.h" +#include "blackcore/context_application.h" + #include "blackmisc/avaircraft.h" + #include using namespace BlackCore; diff --git a/samples/blackgui/mainwindow.h b/samples/blackgui/mainwindow.h index ddc3e00bc..917187d4b 100644 --- a/samples/blackgui/mainwindow.h +++ b/samples/blackgui/mainwindow.h @@ -13,9 +13,9 @@ #include "infowindow.h" #include "guimodeenums.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_application_interface.h" +#include "blackcore/context_application.h" #include "blackcore/context_simulator.h" #include "blackcore/coreruntime.h" #include "blackgui/atcstationlistmodel.h" diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index ee1d24071..23949a5d6 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -4,6 +4,8 @@ #include "blackcore/context_network.h" #include "blackcore/context_simulator_impl.h" #include "blackcore/context_simulator_proxy.h" +#include "blackcore/context_application_impl.h" +#include "blackcore/context_application_proxy.h" #include "blackcore/coreruntime.h" #include "blackgui/atcstationlistmodel.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_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_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); } else diff --git a/src/blackcore/context_application.h b/src/blackcore/context_application.h index cae0acf0c..da1e72351 100644 --- a/src/blackcore/context_application.h +++ b/src/blackcore/context_application.h @@ -6,59 +6,65 @@ #ifndef BLACKCORE_CONTEXTAPPLICATION_H #define BLACKCORE_CONTEXTAPPLICATION_H -#include "blackcore/dbus_server.h" -#include "blackcore/context_application_interface.h" #include "blackmisc/statusmessage.h" -#include "blackmisc/statusmessagelist.h" -#include "blackcore/coreruntime.h" #include -#define BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME "blackcore.contextapplication" +#define BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME "net.vatsim.PilotClient.BlackCore.ContextApplication" +#define BLACKCORE_CONTEXTAPPLICATION_OBJECTPATH "/Application" 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_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME) public: /*! - * Context - * \param parent + * \brief Service name + * \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 */ - virtual ~CContextApplication() {} + virtual ~IContextApplication() {} - /*! - * \brief Register myself in DBus - * \param server - */ - void registerWithDBus(CDBusServer *server) - { - server->addObject(IContextApplication::ServicePath(), this); - } + signals: + //! \brief Status message + void statusMessage(const BlackMisc::CStatusMessage &message); - /*! - * \brief Runtime - * \return - */ - const CCoreRuntime *getRuntime() const - { - return static_cast(this->parent()); - } + //! Widget GUI is about to start + void widgetGuiStarting() const; + + //! Widget GUI is about to terminate + void widgetGuiTerminating() const; public slots: @@ -67,7 +73,7 @@ namespace BlackCore * \param token * \return */ - qint64 ping(qint64 token) const; + virtual qint64 ping(qint64 token) const = 0; }; } diff --git a/src/blackcore/context_application.cpp b/src/blackcore/context_application_impl.cpp similarity index 74% rename from src/blackcore/context_application.cpp rename to src/blackcore/context_application_impl.cpp index 665bc7f43..7f01c5f6f 100644 --- a/src/blackcore/context_application.cpp +++ b/src/blackcore/context_application_impl.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 "context_application.h" +#include "context_application_impl.h" #include "coreruntime.h" #include "blackmisc/settingutilities.h" -using namespace BlackMisc::Settings; -using namespace BlackMisc::Network; using namespace BlackMisc; namespace BlackCore @@ -17,7 +15,7 @@ namespace BlackCore /* * Init this context */ - CContextApplication::CContextApplication(CCoreRuntime *parent) : IContextApplication(parent) + CContextApplication::CContextApplication(QObject *parent) : IContextApplication(parent) { // void } diff --git a/src/blackcore/context_application_impl.h b/src/blackcore/context_application_impl.h new file mode 100644 index 000000000..edc2a54d2 --- /dev/null +++ b/src/blackcore/context_application_impl.h @@ -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(this->parent()); + } + + /*! + * \brief Const runtime + * \return + */ + const CCoreRuntime *getRuntime() const + { + return static_cast(this->parent()); + } + + public slots: + + //! \copydoc IContextApplication::ping() + virtual qint64 ping(qint64 token) const override; + + }; +} + +#endif // guard diff --git a/src/blackcore/context_application_interface.h b/src/blackcore/context_application_interface.h deleted file mode 100644 index 2b2ea25ee..000000000 --- a/src/blackcore/context_application_interface.h +++ /dev/null @@ -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 -#include -#include - -#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 diff --git a/src/blackcore/context_application_interface.cpp b/src/blackcore/context_application_proxy.cpp similarity index 55% rename from src/blackcore/context_application_interface.cpp rename to src/blackcore/context_application_proxy.cpp index 7093ec302..34b8c6f81 100644 --- a/src/blackcore/context_application_interface.cpp +++ b/src/blackcore/context_application_proxy.cpp @@ -3,7 +3,7 @@ * 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/context_application_interface.h" +#include "blackcore/context_application_proxy.h" #include "blackmisc/blackmiscfreefunctions.h" #include #include @@ -15,29 +15,29 @@ namespace BlackCore /* * 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); } /* * 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))); - connection.connect(serviceName, IContextApplication::ServicePath(), IContextApplication::InterfaceName(), + connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), "widgetGuiStarting", this, SIGNAL(widgetGuiStarting())); - connection.connect(serviceName, IContextApplication::ServicePath(), IContextApplication::InterfaceName(), + connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), "widgetGuiTerminating", this, SIGNAL(widgetGuiTerminating())); } /* * Ping, is DBus alive? */ - qint64 IContextApplication::ping(qint64 token) const + qint64 CContextApplicationProxy::ping(qint64 token) const { qint64 t = this->m_dBusInterface->callDBusRet(QLatin1Literal("ping"), token); return t; diff --git a/src/blackcore/context_application_proxy.h b/src/blackcore/context_application_proxy.h new file mode 100644 index 000000000..a65dce60c --- /dev/null +++ b/src/blackcore/context_application_proxy.h @@ -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