mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-19 20:25:29 +08:00
refs #42:
- Added CDBusServer into Blackcore library - Added DBus server and client sample
This commit is contained in:
@@ -52,6 +52,8 @@ equals(WITH_SAMPLES, ON) {
|
|||||||
SUBDIRS += samples/pluginmgr/sample_pluginmgr.pro
|
SUBDIRS += samples/pluginmgr/sample_pluginmgr.pro
|
||||||
SUBDIRS += samples/blackmiscquantities/sample_quantities_avionics.pro
|
SUBDIRS += samples/blackmiscquantities/sample_quantities_avionics.pro
|
||||||
SUBDIRS += samples/blackmiscvectorgeo/sample_vector_geo.pro
|
SUBDIRS += samples/blackmiscvectorgeo/sample_vector_geo.pro
|
||||||
|
SUBDIRS += samples/dbusserver/sample_dbusserver.pro
|
||||||
|
SUBDIRS += samples/dbusclient/sample_dbusclient.pro
|
||||||
}
|
}
|
||||||
|
|
||||||
equals(WITH_UNITTESTS, ON) {
|
equals(WITH_UNITTESTS, ON) {
|
||||||
|
|||||||
6
samples/dbusclient/atcmanager.xml
Normal file
6
samples/dbusclient/atcmanager.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<!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="org.vatsim.pilotClient.AtcManager">
|
||||||
|
<property name="atcList" type="as" access="read"/>
|
||||||
|
</interface>
|
||||||
|
</node>
|
||||||
96
samples/dbusclient/dbusclient.cpp
Normal file
96
samples/dbusclient/dbusclient.cpp
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
#include <QDebug>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include "dbusclient.h"
|
||||||
|
|
||||||
|
|
||||||
|
DBusClient::DBusClient(QObject *parent) :
|
||||||
|
QObject(parent), m_connection("daemon")
|
||||||
|
{
|
||||||
|
m_connection = QDBusConnection::connectToPeer("tcp:host=127.0.0.1,port=6668", "daemon");
|
||||||
|
|
||||||
|
if(!m_connection.isConnected())
|
||||||
|
{
|
||||||
|
qWarning() << m_connection.lastError().message();
|
||||||
|
}
|
||||||
|
|
||||||
|
pilotManagerIface = new org::vatsim::pilotClient::PlaneManager("org.vatsim.PilotClient", "/PlaneManager", m_connection, this);
|
||||||
|
atcManagerIface = new org::vatsim::pilotClient::AtcManager("org.vatsim.PilotClien", "/AtcManager", m_connection, this);
|
||||||
|
fsdClientIface = new org::vatsim::pilotClient::FsdClient("org.vatsim.PilotClient", "/FsdClient", m_connection, this);
|
||||||
|
connect(fsdClientIface, &org::vatsim::pilotClient::FsdClient::connectedTo, this, &DBusClient::slot_connected);
|
||||||
|
}
|
||||||
|
|
||||||
|
DBusClient::~DBusClient()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBusClient::connectTo(const QString &host)
|
||||||
|
{
|
||||||
|
fsdClientIface->connectTo(host);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBusClient::disconnectFrom()
|
||||||
|
{
|
||||||
|
//iface->disconnectFrom();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBusClient::slot_connected( const QString & host)
|
||||||
|
{
|
||||||
|
qDebug() << "Conntected to " << host;
|
||||||
|
qDebug() << "So lets collect some information... ";
|
||||||
|
|
||||||
|
|
||||||
|
printPilotList();
|
||||||
|
printAtcList();
|
||||||
|
|
||||||
|
//qDebug() << iface->getMetar("EDDM");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBusClient::slot_disconnected()
|
||||||
|
{
|
||||||
|
qDebug() << "Disconntected from Vatsim";
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBusClient::printPilotList()
|
||||||
|
{
|
||||||
|
Q_ASSERT(pilotManagerIface);
|
||||||
|
|
||||||
|
qDebug() << "Online pilots: ";
|
||||||
|
|
||||||
|
QStringList planes = pilotManagerIface->pilotList();
|
||||||
|
if (planes.isEmpty())
|
||||||
|
{
|
||||||
|
qWarning() << "Got no pilots. Something went wrong!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(QString plane, planes)
|
||||||
|
{
|
||||||
|
qDebug() << plane;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBusClient::printAtcList()
|
||||||
|
{
|
||||||
|
Q_ASSERT(atcManagerIface);
|
||||||
|
|
||||||
|
qDebug() << "Online controllers: ";
|
||||||
|
|
||||||
|
QStringList controllers = atcManagerIface->atcList();
|
||||||
|
if (controllers.isEmpty())
|
||||||
|
{
|
||||||
|
qWarning() << "Got no controllers. Something went wrong!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(QString controller, controllers)
|
||||||
|
{
|
||||||
|
qDebug() << controller;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBusClient::printError()
|
||||||
|
{
|
||||||
|
qWarning() << m_connection.lastError().message();
|
||||||
|
}
|
||||||
44
samples/dbusclient/dbusclient.h
Normal file
44
samples/dbusclient/dbusclient.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#ifndef DBUSCLIENT_H
|
||||||
|
#define DBUSCLIENT_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QDBusConnection>
|
||||||
|
#include <QtDBus/QDBusError>
|
||||||
|
|
||||||
|
#include "planemanager_interface.h"
|
||||||
|
#include "atcmanager_interface.h"
|
||||||
|
#include "fsdclient_interface.h"
|
||||||
|
|
||||||
|
class DBusClient : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
QDBusConnection m_connection;
|
||||||
|
org::vatsim::pilotClient::PlaneManager *pilotManagerIface;
|
||||||
|
org::vatsim::pilotClient::AtcManager *atcManagerIface;
|
||||||
|
org::vatsim::pilotClient::FsdClient *fsdClientIface;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DBusClient(QObject *parent = 0);
|
||||||
|
~DBusClient();
|
||||||
|
|
||||||
|
void connectTo(const QString &host);
|
||||||
|
void disconnectFrom();
|
||||||
|
|
||||||
|
void printPilotList();
|
||||||
|
void printAtcList();
|
||||||
|
|
||||||
|
void printError();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void slot_connected(const QString &host);
|
||||||
|
void slot_disconnected();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DBUSCLIENT_H
|
||||||
11
samples/dbusclient/fsdclient.xml
Normal file
11
samples/dbusclient/fsdclient.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<!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="org.vatsim.pilotClient.FsdClient">
|
||||||
|
<signal name="connectedTo">
|
||||||
|
<arg name="host" type="s" direction="out"/>
|
||||||
|
</signal>
|
||||||
|
<method name="connectTo">
|
||||||
|
<arg name="host" type="s" direction="in"/>
|
||||||
|
</method>
|
||||||
|
</interface>
|
||||||
|
</node>
|
||||||
12
samples/dbusclient/main.cpp
Normal file
12
samples/dbusclient/main.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include <QCoreApplication>
|
||||||
|
#include "dbusclient.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
DBusClient client;
|
||||||
|
|
||||||
|
client.connectTo("dev.vatsim-germany.org");
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
||||||
6
samples/dbusclient/planemanager.xml
Normal file
6
samples/dbusclient/planemanager.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<!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="org.vatsim.pilotClient.PlaneManager">
|
||||||
|
<property name="pilotList" type="as" access="read"/>
|
||||||
|
</interface>
|
||||||
|
</node>
|
||||||
24
samples/dbusclient/sample_dbusclient.pro
Normal file
24
samples/dbusclient/sample_dbusclient.pro
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#-------------------------------------------------
|
||||||
|
#
|
||||||
|
# Project created by QtCreator 2013-07-07T15:31:07
|
||||||
|
#
|
||||||
|
#-------------------------------------------------
|
||||||
|
|
||||||
|
QT += core dbus
|
||||||
|
|
||||||
|
QT -= gui
|
||||||
|
|
||||||
|
TARGET = DBusClient
|
||||||
|
CONFIG += console
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
DBUS_INTERFACES += planemanager.xml atcmanager.xml fsdclient.xml
|
||||||
|
|
||||||
|
|
||||||
|
SOURCES += main.cpp \
|
||||||
|
dbusclient.cpp
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
dbusclient.h
|
||||||
12
samples/dbusserver/atcmanager.cpp
Normal file
12
samples/dbusserver/atcmanager.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "atcmanager.h"
|
||||||
|
|
||||||
|
CAtcManager::CAtcManager(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
m_atcList << "EDDM_N_TWR" << "KJFK_GND" << "LOVV_CTR";
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CAtcManager::atcList() const
|
||||||
|
{
|
||||||
|
return m_atcList;
|
||||||
|
}
|
||||||
30
samples/dbusserver/atcmanager.h
Normal file
30
samples/dbusserver/atcmanager.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef ATCMANAGER_H
|
||||||
|
#define ATCMANAGER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
|
||||||
|
class CAtcManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QStringList m_atcList; //!< List of all controllers with their callsigns
|
||||||
|
|
||||||
|
public:
|
||||||
|
CAtcManager(QObject *parent = 0);
|
||||||
|
~CAtcManager() {}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Returns a list of all controllers with their callsigns
|
||||||
|
* \return atcList
|
||||||
|
*/
|
||||||
|
QStringList atcList() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ATCMANAGER_H
|
||||||
6
samples/dbusserver/atcmanager.xml
Normal file
6
samples/dbusserver/atcmanager.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<!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="org.vatsim.pilotClient.AtcManager">
|
||||||
|
<property name="atcList" type="as" access="read"/>
|
||||||
|
</interface>
|
||||||
|
</node>
|
||||||
37
samples/dbusserver/atcmanagerhandler.cpp
Normal file
37
samples/dbusserver/atcmanagerhandler.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include "atcmanager.h"
|
||||||
|
#include "blackcore/dbusserver.h"
|
||||||
|
|
||||||
|
#include "atcmanagerhandler.h"
|
||||||
|
|
||||||
|
// It is really IMPORTANT to include this header.
|
||||||
|
// Otherwise it won't be generated by qmake and the
|
||||||
|
// project can't be build
|
||||||
|
#include "atcmanager_adaptor.h"
|
||||||
|
|
||||||
|
CAtcManagerHandler::CAtcManagerHandler(QObject *parent) :
|
||||||
|
QObject(parent), m_dbusserver(0), m_parent(0)
|
||||||
|
{
|
||||||
|
m_dbusPath = "/AtcManager";
|
||||||
|
m_parent = qobject_cast<CAtcManager *>(parent);
|
||||||
|
|
||||||
|
new AtcManagerAdaptor(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
CAtcManagerHandler::~CAtcManagerHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAtcManagerHandler::setDBusServer(BlackCore::CDBusServer *dbusServer)
|
||||||
|
{
|
||||||
|
m_dbusserver = dbusServer;
|
||||||
|
|
||||||
|
if (m_dbusserver)
|
||||||
|
m_dbusserver->addObject(m_dbusPath, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CAtcManagerHandler::atcList() const
|
||||||
|
{
|
||||||
|
qDebug() << "Somebody requested the list of controllers. Here you go...";
|
||||||
|
return m_parent->atcList();
|
||||||
|
}
|
||||||
36
samples/dbusserver/atcmanagerhandler.h
Normal file
36
samples/dbusserver/atcmanagerhandler.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#ifndef ATCMANAGERHANDLER_H
|
||||||
|
#define ATCMANAGERHANDLER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
class CDBusServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CAtcManager;
|
||||||
|
|
||||||
|
class CAtcManagerHandler : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_CLASSINFO("D-Bus Interface", "org.vatsim.pilotClient.AtcManager")
|
||||||
|
Q_PROPERTY( QStringList atcList READ atcList)
|
||||||
|
|
||||||
|
QStringList atcList() const;
|
||||||
|
|
||||||
|
BlackCore::CDBusServer *m_dbusserver;
|
||||||
|
CAtcManager *m_parent;
|
||||||
|
|
||||||
|
QString m_dbusPath;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CAtcManagerHandler(QObject *parent = NULL);
|
||||||
|
~CAtcManagerHandler();
|
||||||
|
|
||||||
|
void setDBusServer(BlackCore::CDBusServer *dbusServer);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ATCMANAGERHANDLER_H
|
||||||
13
samples/dbusserver/fsdclient.cpp
Normal file
13
samples/dbusserver/fsdclient.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "fsdclient.h"
|
||||||
|
|
||||||
|
CFsdClient::CFsdClient(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFsdClient::connectTo(const QString &host)
|
||||||
|
{
|
||||||
|
qDebug() << "Client requests to connect to " << host;
|
||||||
|
}
|
||||||
20
samples/dbusserver/fsdclient.h
Normal file
20
samples/dbusserver/fsdclient.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef FSDCLIENT_H
|
||||||
|
#define FSDCLIENT_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class CFsdClient : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CFsdClient(QObject *parent = 0);
|
||||||
|
|
||||||
|
void connectTo(const QString &host);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FSDCLIENT_H
|
||||||
11
samples/dbusserver/fsdclient.xml
Normal file
11
samples/dbusserver/fsdclient.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<!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="org.vatsim.pilotClient.FsdClient">
|
||||||
|
<signal name="connectedTo">
|
||||||
|
<arg name="host" type="s" direction="out"/>
|
||||||
|
</signal>
|
||||||
|
<method name="connectTo">
|
||||||
|
<arg name="host" type="s" direction="in"/>
|
||||||
|
</method>
|
||||||
|
</interface>
|
||||||
|
</node>
|
||||||
32
samples/dbusserver/fsdclienthandler.cpp
Normal file
32
samples/dbusserver/fsdclienthandler.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
#include "blackcore/dbusserver.h"
|
||||||
|
#include "fsdclienthandler.h"
|
||||||
|
#include "fsdclient.h"
|
||||||
|
|
||||||
|
// It is really IMPORTANT to include this header.
|
||||||
|
// Otherwise it won't be generated by qmake and the
|
||||||
|
// project can't be build
|
||||||
|
#include "fsdclient_adaptor.h"
|
||||||
|
|
||||||
|
CFsdClientHandler::CFsdClientHandler(QObject *parent) :
|
||||||
|
QObject(parent), m_dbusserver(0), m_parent(0)
|
||||||
|
{
|
||||||
|
m_dbusPath = "/FsdClient";
|
||||||
|
m_parent = qobject_cast<CFsdClient *>(parent);
|
||||||
|
|
||||||
|
new FsdClientAdaptor(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFsdClientHandler::connectTo(const QString &host)
|
||||||
|
{
|
||||||
|
m_parent->connectTo(host);
|
||||||
|
emit connectedTo(host);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFsdClientHandler::setDBusServer(BlackCore::CDBusServer *dbusServer)
|
||||||
|
{
|
||||||
|
m_dbusserver = dbusServer;
|
||||||
|
|
||||||
|
if (m_dbusserver)
|
||||||
|
m_dbusserver->addObject(m_dbusPath, this);
|
||||||
|
}
|
||||||
39
samples/dbusserver/fsdclienthandler.h
Normal file
39
samples/dbusserver/fsdclienthandler.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#ifndef FSDCLIENTHANDLER_H
|
||||||
|
#define FSDCLIENTHANDLER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
class CDBusServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CFsdClient;
|
||||||
|
|
||||||
|
class CFsdClientHandler : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_CLASSINFO("D-Bus Interface", "org.vatsim.pilotClient.FsdClient")
|
||||||
|
|
||||||
|
BlackCore::CDBusServer *m_dbusserver;
|
||||||
|
CFsdClient *m_parent;
|
||||||
|
|
||||||
|
QString m_dbusPath;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CFsdClientHandler(QObject *parent = 0);
|
||||||
|
~CFsdClientHandler() {}
|
||||||
|
|
||||||
|
Q_INVOKABLE void connectTo(const QString &host);
|
||||||
|
|
||||||
|
void setDBusServer(BlackCore::CDBusServer *dbusServer);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void connectedTo( const QString &host);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FSDCLIENTHANDLER_H
|
||||||
35
samples/dbusserver/main.cpp
Normal file
35
samples/dbusserver/main.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
#include "blackcore/dbusserver.h"
|
||||||
|
#include "planemanagerhandler.h"
|
||||||
|
#include "atcmanagerhandler.h"
|
||||||
|
#include "atcmanager.h"
|
||||||
|
#include "fsdclient.h"
|
||||||
|
#include "fsdclienthandler.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
|
BlackCore::CDBusServer server;
|
||||||
|
|
||||||
|
// Setting up our objects
|
||||||
|
CPlaneManager planeManager;
|
||||||
|
CAtcManager atcManager;
|
||||||
|
CFsdClient fsdclient;
|
||||||
|
|
||||||
|
|
||||||
|
// Setting up the handler to expose the objects via DBus
|
||||||
|
CPlaneManagerHandler planeManagerHandler(&planeManager);
|
||||||
|
CAtcManagerHandler atcManagerHandler(&atcManager);
|
||||||
|
CFsdClientHandler fsdClientHandler (&fsdclient);
|
||||||
|
|
||||||
|
// Pass the DBus server to the handlers. This registers also
|
||||||
|
// the handler in the DBus server and makes it available
|
||||||
|
// via the interface.
|
||||||
|
planeManagerHandler.setDBusServer(&server);
|
||||||
|
atcManagerHandler.setDBusServer(&server);
|
||||||
|
fsdClientHandler.setDBusServer(&server);
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
||||||
16
samples/dbusserver/planemanager.cpp
Normal file
16
samples/dbusserver/planemanager.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include "planemanager.h"
|
||||||
|
|
||||||
|
CPlaneManager::CPlaneManager(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
m_pilotsList << "DLH123" << "BER456" << "SWS789";
|
||||||
|
}
|
||||||
|
|
||||||
|
CPlaneManager::~CPlaneManager()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CPlaneManager::pilotList() const
|
||||||
|
{
|
||||||
|
return m_pilotsList;
|
||||||
|
}
|
||||||
28
samples/dbusserver/planemanager.h
Normal file
28
samples/dbusserver/planemanager.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef PLANEMANAGER_H
|
||||||
|
#define PLANEMANAGER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
class CPlaneManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QStringList m_pilotsList; //!< List of all pilots with their callsigns
|
||||||
|
|
||||||
|
public:
|
||||||
|
CPlaneManager(QObject *parent = 0);
|
||||||
|
~CPlaneManager();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Returns a list of all pilots with their callsigns
|
||||||
|
* \return pilotList
|
||||||
|
*/
|
||||||
|
QStringList pilotList() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PLANEMANAGER_H
|
||||||
6
samples/dbusserver/planemanager.xml
Normal file
6
samples/dbusserver/planemanager.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<!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="org.vatsim.pilotClient.PlaneManager">
|
||||||
|
<property name="pilotList" type="as" access="read"/>
|
||||||
|
</interface>
|
||||||
|
</node>
|
||||||
33
samples/dbusserver/planemanagerhandler.cpp
Normal file
33
samples/dbusserver/planemanagerhandler.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include <QDebug>
|
||||||
|
#include "planemanagerhandler.h"
|
||||||
|
|
||||||
|
// It is really IMPORTANT to include this header.
|
||||||
|
// Otherwise it won't be generated by qmake and the
|
||||||
|
// project can't be build
|
||||||
|
#include "planemanager_adaptor.h"
|
||||||
|
|
||||||
|
CPlaneManagerHandler::CPlaneManagerHandler(QObject *parent) :
|
||||||
|
QObject(parent), m_dbusserver(0), m_parent(0)
|
||||||
|
{
|
||||||
|
m_dbusPath = "/PlaneManager";
|
||||||
|
m_parent = qobject_cast<CPlaneManager *>(parent);
|
||||||
|
|
||||||
|
new PlaneManagerAdaptor(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPlaneManagerHandler::setDBusServer(BlackCore::CDBusServer *dbusServer)
|
||||||
|
{
|
||||||
|
m_dbusserver = dbusServer;
|
||||||
|
|
||||||
|
// We add ourselves to the DBus server. This is needed, because
|
||||||
|
// DBus has to register all exposed objects for each new connection
|
||||||
|
if (m_dbusserver)
|
||||||
|
m_dbusserver->addObject(m_dbusPath, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CPlaneManagerHandler::pilotList() const
|
||||||
|
{
|
||||||
|
qDebug() << "Somebody requested the list of pilots. Here you go...";
|
||||||
|
return m_parent->pilotList();
|
||||||
|
}
|
||||||
34
samples/dbusserver/planemanagerhandler.h
Normal file
34
samples/dbusserver/planemanagerhandler.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef PLANEMANAGERHANDLER_H
|
||||||
|
#define PLANEMANAGERHANDLER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include "planemanager.h"
|
||||||
|
#include "blackcore/dbusserver.h"
|
||||||
|
|
||||||
|
class CPlaneManagerHandler : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_CLASSINFO("D-Bus Interface", "org.vatsim.pilotClient.PlaneManager")
|
||||||
|
Q_PROPERTY( QStringList pilotList READ pilotList)
|
||||||
|
|
||||||
|
public:
|
||||||
|
CPlaneManagerHandler(QObject *parent = NULL);
|
||||||
|
~CPlaneManagerHandler() {}
|
||||||
|
|
||||||
|
void setDBusServer(BlackCore::CDBusServer *dbusServer);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
QStringList pilotList() const;
|
||||||
|
|
||||||
|
BlackCore::CDBusServer *m_dbusserver;
|
||||||
|
CPlaneManager *m_parent;
|
||||||
|
|
||||||
|
QString m_dbusPath;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PLANEMANAGERHANDLER_H
|
||||||
32
samples/dbusserver/sample_dbusserver.pro
Normal file
32
samples/dbusserver/sample_dbusserver.pro
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#-------------------------------------------------
|
||||||
|
#
|
||||||
|
# Project created by QtCreator 2013-07-06T22:37:57
|
||||||
|
#
|
||||||
|
#-------------------------------------------------
|
||||||
|
|
||||||
|
QT += core dbus
|
||||||
|
|
||||||
|
QT -= gui
|
||||||
|
|
||||||
|
TARGET = DBusServer
|
||||||
|
CONFIG += console
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
DBUS_ADAPTORS += planemanager.xml atcmanager.xml fsdclient.xml
|
||||||
|
|
||||||
|
DEPENDPATH += . ../../src
|
||||||
|
INCLUDEPATH += . ../../src
|
||||||
|
|
||||||
|
HEADERS += *.h
|
||||||
|
SOURCES += *.cpp
|
||||||
|
|
||||||
|
LIBS += -L../../lib -lblackcore -lblackmisc
|
||||||
|
|
||||||
|
win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \
|
||||||
|
../../lib/blackcore.lib
|
||||||
|
else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \
|
||||||
|
../../lib/libblackcore.a
|
||||||
|
|
||||||
|
DESTDIR = ../../bin
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# GUI is required for the matrix classes
|
# GUI is required for the matrix classes
|
||||||
QT += network
|
QT += network dbus
|
||||||
|
|
||||||
TARGET = blackcore
|
TARGET = blackcore
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
|
|||||||
56
src/blackcore/dbusserver.cpp
Normal file
56
src/blackcore/dbusserver.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "dbusserver.h"
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// - Change constructor to use address from the config file
|
||||||
|
// - Ammend debug message according to the final result in the forum discussion
|
||||||
|
|
||||||
|
CDBusServer::CDBusServer(QObject *parent) :
|
||||||
|
QObject(parent), m_busServer("tcp:host=127.0.0.1,port=6668", parent)
|
||||||
|
{
|
||||||
|
if (!m_busServer.isConnected())
|
||||||
|
{
|
||||||
|
qWarning() << m_busServer.lastError().message();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << "Server is running on" << m_busServer.address();
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(&m_busServer, &QDBusServer::newConnection, this, &CDBusServer::newConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDBusServer::newConnection(const QDBusConnection & connection)
|
||||||
|
{
|
||||||
|
QMap<QString, QObject*>::ConstIterator i = m_objects.begin();
|
||||||
|
QDBusConnection newConnection(connection);
|
||||||
|
|
||||||
|
m_DBusConnections.insert(newConnection.name(), newConnection);
|
||||||
|
|
||||||
|
qDebug() << "New Connection from: " << newConnection.name();
|
||||||
|
|
||||||
|
while (i != m_objects.end())
|
||||||
|
{
|
||||||
|
qDebug() << "Adding " << i.key() << "to the new connection.";
|
||||||
|
newConnection.registerObject(i.key(), i.value());
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDBusServer::addObject(const QString &name, QObject *object)
|
||||||
|
{
|
||||||
|
m_objects.insert(name, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDBusServer::printError()
|
||||||
|
{
|
||||||
|
qWarning() << m_busServer.lastError().name();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace BlackCore
|
||||||
|
|
||||||
|
|
||||||
51
src/blackcore/dbusserver.h
Normal file
51
src/blackcore/dbusserver.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#ifndef BLACKCORE_DBUSSERVER_H
|
||||||
|
#define BLACKCORE_DBUSSERVER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QtDBus/QDBusServer>
|
||||||
|
#include <QtDBus/QDBusError>
|
||||||
|
#include <QtDBus/QDBusConnection>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
|
||||||
|
class CDBusServer : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_CLASSINFO("D-Bus Interface", "org.vatsim.pilotClient")
|
||||||
|
|
||||||
|
private:
|
||||||
|
QDBusServer m_busServer; //!< QDBusServer implementation
|
||||||
|
|
||||||
|
QMap<QString, QObject*> m_objects; //!< Mapping of all exposed objects
|
||||||
|
|
||||||
|
QMap<QString, QDBusConnection> m_DBusConnections; //!< Mapping of all DBusConnection objects
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Constructor
|
||||||
|
* \param parent
|
||||||
|
*/
|
||||||
|
CDBusServer(QObject *parent = 0);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Adds a QObject to be exposed to DBus
|
||||||
|
* \param name
|
||||||
|
* \param object
|
||||||
|
*/
|
||||||
|
void addObject(const QString &name, QObject *object);
|
||||||
|
|
||||||
|
|
||||||
|
void printError();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void newConnection(const QDBusConnection & connection);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace BlackCore
|
||||||
|
|
||||||
|
#endif // BLACKCORE_DBUSSERVER_H
|
||||||
Reference in New Issue
Block a user