diff --git a/src/blackcore/blackcore.contextapplication.xml b/src/blackcore/blackcore.contextapplication.xml new file mode 100644 index 000000000..c2bb9e5f0 --- /dev/null +++ b/src/blackcore/blackcore.contextapplication.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/src/blackcore/blackcore.pro b/src/blackcore/blackcore.pro index 3d93d31ee..ca2a62be2 100644 --- a/src/blackcore/blackcore.pro +++ b/src/blackcore/blackcore.pro @@ -24,6 +24,7 @@ precompile_header:!isEmpty(PRECOMPILED_HEADER) { QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h DBUS_ADAPTORS += blackcore.contextnetwork.xml DBUS_ADAPTORS += blackcore.contextsettings.xml +DBUS_ADAPTORS += blackcore.contextapplication.xml # QDBUSXML2CPP_INTERFACE_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h # DBUS_INTERFACES += blackcore.contextnetwork.xml diff --git a/src/blackcore/context_application.cpp b/src/blackcore/context_application.cpp new file mode 100644 index 000000000..665bc7f43 --- /dev/null +++ b/src/blackcore/context_application.cpp @@ -0,0 +1,32 @@ +/* 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/. */ + +#include "context_application.h" +#include "coreruntime.h" +#include "blackmisc/settingutilities.h" + +using namespace BlackMisc::Settings; +using namespace BlackMisc::Network; +using namespace BlackMisc; + +namespace BlackCore +{ + + /* + * Init this context + */ + CContextApplication::CContextApplication(CCoreRuntime *parent) : IContextApplication(parent) + { + // void + } + + /* + * Ping, is DBus alive? + */ + qint64 CContextApplication::ping(qint64 token) const + { + return token; + } +} // namespace diff --git a/src/blackcore/context_application.h b/src/blackcore/context_application.h new file mode 100644 index 000000000..cae0acf0c --- /dev/null +++ b/src/blackcore/context_application.h @@ -0,0 +1,75 @@ +/* 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_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" + +namespace BlackCore +{ + class CCoreRuntime; + + /*! + * \brief Application context + */ + class CContextApplication : public IContextApplication + { + // 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 + + public: + + /*! + * Context + * \param parent + */ + CContextApplication(CCoreRuntime *parent); + + /*! + * Destructor + */ + virtual ~CContextApplication() {} + + /*! + * \brief Register myself in DBus + * \param server + */ + void registerWithDBus(CDBusServer *server) + { + server->addObject(IContextApplication::ServicePath(), this); + } + + /*! + * \brief Runtime + * \return + */ + const CCoreRuntime *getRuntime() const + { + return static_cast(this->parent()); + } + + public slots: + + /*! + * \brief Ping + * \param token + * \return + */ + qint64 ping(qint64 token) const; + + }; +} + +#endif // guard diff --git a/src/blackcore/context_application_interface.cpp b/src/blackcore/context_application_interface.cpp new file mode 100644 index 000000000..7093ec302 --- /dev/null +++ b/src/blackcore/context_application_interface.cpp @@ -0,0 +1,46 @@ +/* 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/. */ + +#include "blackcore/context_application_interface.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include +#include +#include + +namespace BlackCore +{ + + /* + * Constructor for DBus + */ + IContextApplication::IContextApplication(const QString &serviceName, QDBusConnection &connection, QObject *parent) : QObject(parent), m_dBusInterface(0) + { + this->m_dBusInterface = new BlackMisc::CGenericDBusInterface(serviceName , IContextApplication::ServicePath(), IContextApplication::InterfaceName(), connection, this); + this->relaySignals(serviceName, connection); + } + + /* + * Workaround for signals + */ + void IContextApplication::relaySignals(const QString &serviceName, QDBusConnection &connection) + { + connection.connect(serviceName, IContextApplication::ServicePath(), IContextApplication::InterfaceName(), + "statusMessage", this, SIGNAL(statusMessage(BlackMisc::CStatusMessage))); + connection.connect(serviceName, IContextApplication::ServicePath(), IContextApplication::InterfaceName(), + "widgetGuiStarting", this, SIGNAL(widgetGuiStarting())); + connection.connect(serviceName, IContextApplication::ServicePath(), IContextApplication::InterfaceName(), + "widgetGuiTerminating", this, SIGNAL(widgetGuiTerminating())); + } + + /* + * Ping, is DBus alive? + */ + qint64 IContextApplication::ping(qint64 token) const + { + qint64 t = this->m_dBusInterface->callDBusRet(QLatin1Literal("ping"), token); + return t; + } + +} // namespace diff --git a/src/blackcore/context_application_interface.h b/src/blackcore/context_application_interface.h new file mode 100644 index 000000000..0ab9fdaf3 --- /dev/null +++ b/src/blackcore/context_application_interface.h @@ -0,0 +1,109 @@ +/* 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 + * \param message + */ + void statusMessage(const BlackMisc::CStatusMessage &message); + + + void widgetGuiStarting() const; + void widgetGuiTerminating() const; + + public slots: + + /*! + * \brief Ping + * \param token + * \return + */ + virtual qint64 ping(qint64 token) const; + + }; +} + +#endif // guard diff --git a/src/blackcore/coreruntime.cpp b/src/blackcore/coreruntime.cpp index de25d5760..446e67007 100644 --- a/src/blackcore/coreruntime.cpp +++ b/src/blackcore/coreruntime.cpp @@ -12,7 +12,9 @@ namespace BlackCore * Constructor */ CCoreRuntime::CCoreRuntime(bool withDbus, QObject *parent) : - QObject(parent), m_init(false), m_dbusServer(nullptr), m_contextNetwork(nullptr), m_settings(nullptr) + QObject(parent), m_init(false), m_dbusServer(nullptr), + m_contextNetwork(nullptr), m_contextVoice(nullptr), + m_contextSettings(nullptr), m_contextApplication(nullptr) { this->init(withDbus); } @@ -34,11 +36,17 @@ namespace BlackCore } // contexts - this->m_settings = new CContextSettings(this); - if (withDbus) this->m_settings->registerWithDBus(this->m_dbusServer); + this->m_contextSettings = new CContextSettings(this); + if (withDbus) this->m_contextSettings->registerWithDBus(this->m_dbusServer); this->m_contextNetwork = new CContextNetwork(this); - if (withDbus) this->m_contextNetwork->registerWithDBus(this->m_dbusServer); // complete object after init + if (withDbus) this->m_contextNetwork->registerWithDBus(this->m_dbusServer); + + this->m_contextApplication = new CContextApplication(this); + if (withDbus) this->m_contextApplication->registerWithDBus(this->m_dbusServer); + + this->m_contextVoice = new CContextVoice(this); + if (withDbus) this->m_contextVoice->registerWithDBus(this->m_dbusServer); // flag m_init = true;