mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 06:35:52 +08:00
@@ -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 <QObject>
|
||||
|
||||
#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<CCoreRuntime *>(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;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
73
src/blackcore/context_application_impl.h
Normal file
73
src/blackcore/context_application_impl.h
Normal 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
|
||||
@@ -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
|
||||
@@ -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 <QObject>
|
||||
#include <QMetaEnum>
|
||||
@@ -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<qint64>(QLatin1Literal("ping"), token);
|
||||
return t;
|
||||
62
src/blackcore/context_application_proxy.h
Normal file
62
src/blackcore/context_application_proxy.h
Normal 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
|
||||
Reference in New Issue
Block a user