new contexts

refs #81
This commit is contained in:
Klaus Basan
2014-01-07 23:57:53 +00:00
committed by Mathew Sutcliffe
parent 0bad7bb2e8
commit ee43f5598d
7 changed files with 292 additions and 4 deletions

View File

@@ -0,0 +1,17 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="blackcore.contextapplication">
<signal name="statusMessage">
<arg name="message" type="(sii((iii)(iiii)i))" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="BlackMisc::CStatusMessage"/>
</signal>
<signal name="widgetGuiStarting">
</signal>
<signal name="widgetGuiTerminating">
</signal>
<method name="ping">
<arg type="x" direction="out"/>
<arg name="token" type="x" direction="in"/>
</method>
</interface>
</node>

View File

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

View File

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

View File

@@ -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 <QObject>
#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<CCoreRuntime *>(this->parent());
}
public slots:
/*!
* \brief Ping
* \param token
* \return
*/
qint64 ping(qint64 token) const;
};
}
#endif // guard

View File

@@ -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 <QObject>
#include <QMetaEnum>
#include <QDBusConnection>
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<qint64>(QLatin1Literal("ping"), token);
return t;
}
} // namespace

View File

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

View File

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