- Added DBus handler interface
- Added more complex flow to both samples
- Added custom class to be transfered
This commit is contained in:
Roland Winklmeier
2013-08-07 01:32:13 +02:00
parent 40abcf4c19
commit efacac77eb
47 changed files with 1036 additions and 434 deletions

View File

@@ -0,0 +1,8 @@
<!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.AircraftManager">
<property name="aircraftList" type="a(ii)" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="CRemoteAircraftList"/>
</property>
</interface>
</node>

View File

@@ -1,20 +1,22 @@
#include <QDebug> #include <QDebug>
#include <QStringList> #include <QStringList>
#include "remote_aircraft.h"
#include "dbusclient.h" #include "dbusclient.h"
DBusClient::DBusClient(QObject *parent) : DBusClient::DBusClient(QObject *parent) :
QObject(parent), m_connection("daemon") QObject(parent), m_connection("daemon")
{ {
m_connection = QDBusConnection::connectToPeer("tcp:host=127.0.0.1,port=6668", "daemon"); m_connection = QDBusConnection::connectToPeer("tcp:host=127.0.0.1,port=45000", "daemon");
if(!m_connection.isConnected()) if(!m_connection.isConnected())
{ {
qWarning() << m_connection.lastError().message(); qWarning() << m_connection.lastError().message();
} }
pilotManagerIface = new org::vatsim::pilotClient::PlaneManager("org.vatsim.PilotClient", "/PlaneManager", m_connection, this); aircraftManagerIface = new org::vatsim::pilotClient::AircraftManager("org.vatsim.PilotClient", "/AircraftManager", m_connection, this);
atcManagerIface = new org::vatsim::pilotClient::AtcManager("org.vatsim.PilotClien", "/AtcManager", 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); fsdClientIface = new org::vatsim::pilotClient::FsdClient("org.vatsim.PilotClient", "/FsdClient", m_connection, this);
connect(fsdClientIface, &org::vatsim::pilotClient::FsdClient::connectedTo, this, &DBusClient::slot_connected); connect(fsdClientIface, &org::vatsim::pilotClient::FsdClient::connectedTo, this, &DBusClient::slot_connected);
@@ -32,19 +34,16 @@ void DBusClient::connectTo(const QString &host)
void DBusClient::disconnectFrom() void DBusClient::disconnectFrom()
{ {
//iface->disconnectFrom();
} }
void DBusClient::slot_connected( const QString & host) void DBusClient::slot_connected( const QString & host)
{ {
qDebug() << "Conntected to " << host; qDebug() << "Conntected to " << host;
qDebug() << "So lets collect some information... "; qDebug() << "Retrieve all visible aircrafts and controllers...";
printPilotList(); printPilotList();
printAtcList(); printAtcList();
//qDebug() << iface->getMetar("EDDM");
} }
void DBusClient::slot_disconnected() void DBusClient::slot_disconnected()
@@ -54,20 +53,19 @@ void DBusClient::slot_disconnected()
void DBusClient::printPilotList() void DBusClient::printPilotList()
{ {
Q_ASSERT(pilotManagerIface); Q_ASSERT(aircraftManagerIface);
qDebug() << "Online pilots: "; qDebug() << "Online aircrafts: ";
QStringList planes = pilotManagerIface->pilotList(); CRemoteAircraftList aircrafts = aircraftManagerIface->aircraftList();
if (planes.isEmpty()) if (aircrafts.isEmpty())
{ {
qWarning() << "Got no pilots. Something went wrong!"; qWarning() << "Got no aircrafts. Something went wrong!";
return; return;
} }
foreach(CRemoteAircraft aircraft, aircrafts)
foreach(QString plane, planes)
{ {
qDebug() << plane; qDebug() << aircraft.getCallsign();
} }
} }
@@ -78,6 +76,7 @@ void DBusClient::printAtcList()
qDebug() << "Online controllers: "; qDebug() << "Online controllers: ";
QStringList controllers = atcManagerIface->atcList(); QStringList controllers = atcManagerIface->atcList();
if (controllers.isEmpty()) if (controllers.isEmpty())
{ {
qWarning() << "Got no controllers. Something went wrong!"; qWarning() << "Got no controllers. Something went wrong!";

View File

@@ -5,7 +5,7 @@
#include <QDBusConnection> #include <QDBusConnection>
#include <QtDBus/QDBusError> #include <QtDBus/QDBusError>
#include "planemanager_interface.h" #include "aircraftmanager_interface.h"
#include "atcmanager_interface.h" #include "atcmanager_interface.h"
#include "fsdclient_interface.h" #include "fsdclient_interface.h"
@@ -15,7 +15,7 @@ class DBusClient : public QObject
private: private:
QDBusConnection m_connection; QDBusConnection m_connection;
org::vatsim::pilotClient::PlaneManager *pilotManagerIface; org::vatsim::pilotClient::AircraftManager *aircraftManagerIface;
org::vatsim::pilotClient::AtcManager *atcManagerIface; org::vatsim::pilotClient::AtcManager *atcManagerIface;
org::vatsim::pilotClient::FsdClient *fsdClientIface; org::vatsim::pilotClient::FsdClient *fsdClientIface;

View File

@@ -1,11 +1,31 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug>
#include "dbusclient.h" #include "dbusclient.h"
#include "remote_aircraft.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
qDebug() << "***********************************************";
qDebug() << "******* Welcome to DBus Client sample *********";
qDebug() << "* This samples demonstrates the communication *";
qDebug() << "* between two different processes, simulating *";
qDebug() << "* a client connection to DBusSever by P2P and *";
qDebug() << "* and asking for online aircrafts and ATC *";
qDebug() << "* controllers. Use DBusServer sample to get *";
qDebug() << "* aircraft and contoller objects from the *";
qDebug() << "* FSD network They can be accessed by the *";
qDebug() << "* client after they have been transfered. Be *";
qDebug() << "* aware: All objects are simulated and not *";
qDebug() << "* VATSIM realtime traffic. *";
qDebug() << "***********************************************";
qDebug();
DBusClient client; DBusClient client;
CRemoteAircraft::registerMetaType();
client.connectTo("dev.vatsim-germany.org"); client.connectTo("dev.vatsim-germany.org");
return a.exec(); return a.exec();

View File

@@ -1,6 +0,0 @@
<!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>

View File

@@ -0,0 +1,58 @@
#include "remote_aircraft.h"
CRemoteAircraft::CRemoteAircraft() :
m_callsign(), m_heading(0), m_groundSpeed(0), m_wakeTurbulence()
{
}
CRemoteAircraft::CRemoteAircraft(const CRemoteAircraft &other) :
m_callsign(other.m_callsign),
m_heading(other.m_heading),
m_groundSpeed(other.m_groundSpeed),
m_wakeTurbulence(other.m_wakeTurbulence)
{
}
CRemoteAircraft &CRemoteAircraft::operator =(const CRemoteAircraft &other)
{
if (this != &other)
{
m_callsign = other.m_callsign;
m_heading = other.m_heading;
m_groundSpeed = other.m_groundSpeed;
m_wakeTurbulence = other.m_wakeTurbulence;
}
return *this;
}
void CRemoteAircraft::registerMetaType()
{
qRegisterMetaType<CRemoteAircraft>("CRemoteAircraft");
qDBusRegisterMetaType<CRemoteAircraft>();
qDBusRegisterMetaType<CRemoteAircraftList>();
}
QDBusArgument &operator<<(QDBusArgument &argument, const CRemoteAircraft& remoteAircraft)
{
argument.beginStructure();
argument << remoteAircraft.m_callsign;
argument << remoteAircraft.m_heading;
argument << remoteAircraft.m_groundSpeed;
argument << remoteAircraft.m_wakeTurbulence;
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, CRemoteAircraft &remoteAircraft)
{
argument.beginStructure();
argument >> remoteAircraft.m_callsign;
argument >> remoteAircraft.m_heading;
argument >> remoteAircraft.m_groundSpeed;
argument >> remoteAircraft.m_wakeTurbulence;
argument.endStructure();
return argument;
}

View File

@@ -0,0 +1,85 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 REMOTE_AIRCRAFT_H
#define REMOTE_AIRCRAFT_H
#include <QtDBus>
/*!
* \brief Remove Aircraft
* \details This class represents a aircraft from another user in the network
* \author Roland Winklmeier
* \version 0.1
* \date July 2013
*/
class CRemoteAircraft
{
QString m_callsign; //!< Aircrafts callsign
double m_heading; //!< Aircrafts heading.
double m_groundSpeed; //!< Aircrafts groundspeed in knots
QString m_wakeTurbulence; //!< wake turbulence classification
public:
/*!
* \brief Constructor
*/
CRemoteAircraft();
/*!
* \brief Copy constructor
* \param other
*/
CRemoteAircraft(const CRemoteAircraft &other);
/*!
* \brief Assignment operator
* \param other
*/
CRemoteAircraft &operator=(const CRemoteAircraft &other);
/*!
* \brief Destructor
*/
~CRemoteAircraft() {}
friend QDBusArgument &operator<<(QDBusArgument &argument, const CRemoteAircraft &remoteAircraft);
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CRemoteAircraft &remoteAircraft);
/*!
* \brief Aircrafts Callsign
*/
QString getCallsign() const { return m_callsign; }
/*!
* \brief Aircrafts heading
*/
double getHeading() const { return m_heading; }
/*!
* \brief Aircrafts ground speed
*/
double getGroundSpeed() const { return m_groundSpeed; }
/*!
* \brief Aircrafts wake turbulence classification
*/
QString getWakeTurbulence() const { return m_wakeTurbulence; }
static void registerMetaType();
};
typedef QList<CRemoteAircraft> CRemoteAircraftList;
Q_DECLARE_METATYPE(CRemoteAircraft)
Q_DECLARE_METATYPE(CRemoteAircraftList)
#endif // REMOTE_AIRCRAFT_H

View File

@@ -14,11 +14,16 @@ CONFIG -= app_bundle
TEMPLATE = app TEMPLATE = app
DBUS_INTERFACES += planemanager.xml atcmanager.xml fsdclient.xml DBUS_INTERFACES += dbus/aircraftmanager.xml dbus/atcmanager.xml dbus/fsdclient.xml
QDBUSXML2CPP_INTERFACE_HEADER_FLAGS = -i remote_aircraft.h
QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS = -i remote_aircraft.h
SOURCES += main.cpp \ SOURCES += main.cpp \
dbusclient.cpp dbusclient.cpp \
remote_aircraft.cpp
HEADERS += \ HEADERS += \
dbusclient.h dbusclient.h \
remote_aircraft.h

View File

@@ -0,0 +1,30 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 <QDebug>
#include "aircraft_manager.h"
CAircraftManager::CAircraftManager(QObject *parent) :
QObject(parent)
{
}
CAircraftManager::~CAircraftManager()
{
}
QList<CRemoteAircraft> CAircraftManager::aircraftList() const
{
return m_aircraftList;
}
void CAircraftManager::addAircraft(const CRemoteAircraft &aircraft)
{
if (m_aircraftList.indexOf(aircraft) == -1)
{
qDebug() << "Got new aircraft from FSD with callsign: " << aircraft.getCallsign();
m_aircraftList << aircraft;
}
}

View File

@@ -0,0 +1,64 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 AIRCRAFTMANAGER_H
#define AIRCRAFTMANAGER_H
#include <QObject>
#include <QStringList>
#include <QList>
#include "remote_aircraft.h"
/*!
* \brief Plane Manager
* \details This class manages all plane objects visible to the user
* \author Roland Winklmeier
* \version 0.1
* \date July 2013
*/
class CAircraftManager : public QObject
{
Q_OBJECT
QList<CRemoteAircraft> m_aircraftList; //!< List of all aircrafts with their callsigns
public:
/*!
* \brief Constructor
* \param parent
*/
CAircraftManager(QObject *parent = 0);
/*!
* \brief Destructor
*/
~CAircraftManager();
/*!
* \brief Returns a list of all pilots with their callsigns
* \return pilotList
*/
QStringList pilotList() const;
/*!
* \brief Returns a list of all pilots with their callsigns
* \return pilotList
*/
QList<CRemoteAircraft> aircraftList() const;
/*!
* \brief Adds new aircraft
* \return aircraft
*/
void addAircraft( const CRemoteAircraft &aircraft );
signals:
public slots:
};
#endif // AIRCRAFTMANAGER_H

View File

@@ -0,0 +1,29 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 <QDebug>
#include "aircraft_manager_handler.h"
#include "aircraft_manager.h"
/**
* It is really IMPORTANT to include the following header.
* Otherwise it won't be generated by qmake and the
* project can't be build
*/
#include "aircraftmanager_adaptor.h"
CAircraftManagerHandler::CAircraftManagerHandler(QObject *parent) :
IDBusHandler(parent)
{
setDBusObjectPath("/AircraftManager");
new AircraftManagerAdaptor(this);
}
QList<CRemoteAircraft> CAircraftManagerHandler::aircraftList() const
{
qDebug() << "Client requested the list of aircrafts. Sending to him...";
return qobject_cast<CAircraftManager*>(m_parent)->aircraftList();
}

View File

@@ -0,0 +1,53 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 PLANEMANAGERHANDLER_H
#define PLANEMANAGERHANDLER_H
#include <QObject>
#include <QStringList>
#include "blackmisc/dbus_handler.h"
#include "remote_aircraft.h"
class CAircraftManager;
/*!
* \brief Plane Manager wrapper for DBus
* \details This class handles the DBus communication for the PlaneManager
* \author Roland Winklmeier
* \version 0.1
* \date July 2013
*/
class CAircraftManagerHandler : public BlackMisc::IDBusHandler
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.vatsim.pilotClient.PlaneManager")
Q_PROPERTY( QList<CRemoteAircraft> aircraftList READ aircraftList)
QList<CRemoteAircraft> aircraftList() const;
public:
/*!
* \brief Default constructor
* \param parent
*/
CAircraftManagerHandler(QObject *parent);
/*!
* \brief Destructor
*/
~CAircraftManagerHandler() {}
signals:
public slots:
private:
};
#endif // PLANEMANAGERHANDLER_H

View File

@@ -0,0 +1,28 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 "atc_manager.h"
/**
* Constructor
*/
CAtcManager::CAtcManager(QObject *parent) :
QObject(parent)
{
}
/**
* Return QStringList of controller callsigns
*/
QStringList CAtcManager::atcList() const
{
return m_atcList;
}
void CAtcManager::addATC(const QString &controller)
{
if (m_atcList.indexOf(controller) == -1)
m_atcList << controller;
}

View File

@@ -0,0 +1,57 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 ATCMANAGER_H
#define ATCMANAGER_H
#include <QObject>
#include <QStringList>
/*!
* \brief ATC Controller Managing class
* \details This class is used hold a map of all controllers in the network and visible to the user
* \author Roland Winklmeier
* \version 0.1
* \date July 2013
*/
class CAtcManager : public QObject
{
Q_OBJECT
QStringList m_atcList; //!< List of all controllers with their callsigns
public:
/*!
* \brief Default constructor
* \param parent
*/
CAtcManager(QObject *parent = 0);
/*!
* \brief Destructor
*/
~CAtcManager() {}
/*!
* \brief Returns a list of all controllers with their callsigns
* \return atcList
*/
QStringList atcList() const;
/*!
* \brief Add new ATC controller
* \return controller
*/
void addATC( const QString &controller );
signals:
public slots:
};
#endif // ATCMANAGER_H

View File

@@ -0,0 +1,33 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 "atc_manager.h"
#include "blackcore/dbus_server.h"
#include "atc_manager_handler.h"
/**
* It is really IMPORTANT to include the following header.
* Otherwise it won't be generated by qmake and the
* project can't be build
*/
#include "atcmanager_adaptor.h"
CAtcManagerHandler::CAtcManagerHandler(QObject *parent) :
IDBusHandler(parent)
{
setDBusObjectPath("/AtcManager");
new AtcManagerAdaptor(this);
}
CAtcManagerHandler::~CAtcManagerHandler()
{
}
QStringList CAtcManagerHandler::atcList() const
{
qDebug() << "Client requested the list of controllers. Sending to him...";
return qobject_cast<CAtcManager*>(m_parent)->atcList();
}

View File

@@ -0,0 +1,49 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 ATCMANAGERHANDLER_H
#define ATCMANAGERHANDLER_H
#include <QObject>
#include <QStringList>
#include "blackmisc/dbus_handler.h"
class CAtcManager;
/*!
* \brief ATC Manager Wrapper for DBus
* \details This class handles the DBus communication for the ATC manager
* \author Roland Winklmeier
* \version 0.1
* \date July 2013
*/
class CAtcManagerHandler : public BlackMisc::IDBusHandler
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.vatsim.pilotClient.AtcManager")
Q_PROPERTY( QStringList atcList READ atcList)
/**
* Return QStringList of controller callsigns
* This needs to be private, since you should not call this
* directly in your application. Use the parents method instead.
*/
QStringList atcList() const;
public:
/*!
* \brief Default constructor
* \param parent
*/
CAtcManagerHandler(QObject *parent);
/*!
* \brief Destructor
*/
~CAtcManagerHandler();
};
#endif // ATCMANAGERHANDLER_H

View File

@@ -1,12 +0,0 @@
#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;
}

View File

@@ -1,30 +0,0 @@
#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

View File

@@ -1,37 +0,0 @@
#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();
}

View File

@@ -1,36 +0,0 @@
#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

View File

@@ -0,0 +1,8 @@
<!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.AircraftManager">
<property name="aircraftList" type="a(ii)" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="CRemoteAircraftList"/>
</property>
</interface>
</node>

View File

@@ -0,0 +1,18 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 <QDebug>
#include "fsd_client.h"
CFsdClient::CFsdClient(QObject *parent) :
QObject(parent)
{
}
void CFsdClient::connectTo(const QString &host)
{
qDebug() << "Client requests to connect to " << host;
}

View File

@@ -0,0 +1,42 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 FSDCLIENT_H
#define FSDCLIENT_H
#include <QObject>
/*!
* \brief FSD client
* \details This class implements methods to connect to a FSD server
* \author Roland Winklmeier
* \version 0.1
* \date July 2013
*/
class CFsdClient : public QObject
{
Q_OBJECT
public:
/*!
* \brief Constructor
* \param parent
*/
CFsdClient(QObject *parent = 0);
/*!
* \brief Starts connection to FSD server
* \param host
*/
void connectTo(const QString &host);
signals:
public slots:
};
#endif // FSDCLIENT_H

View File

@@ -0,0 +1,29 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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/dbus_server.h"
#include "fsd_client_handler.h"
#include "fsd_client.h"
/**
* It is really IMPORTANT to include the following header.
* Otherwise it won't be generated by qmake and the
* project can't be build
*/
#include "fsdclient_adaptor.h"
CFsdClientHandler::CFsdClientHandler(QObject *parent) :
IDBusHandler(parent)
{
setDBusObjectPath("/FsdClient");
new FsdClientAdaptor(this);
}
void CFsdClientHandler::connectTo(const QString &host)
{
CFsdClient *fsdClient = qobject_cast<CFsdClient*>(m_parent);
fsdClient->connectTo(host);
emit connectedTo(host);
}

View File

@@ -0,0 +1,52 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 FSDCLIENTHANDLER_H
#define FSDCLIENTHANDLER_H
#include <QObject>
#include <BlackMisc/dbus_handler.h>
class CFsdClient;
/*!
* \brief FSD client wrapper for DBus
* \details This class handles the DBus communication for the FSD client
* \author Roland Winklmeier
* \version 0.1
* \date July 2013
*/
class CFsdClientHandler : public BlackMisc::IDBusHandler
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.vatsim.pilotClient.FsdClient")
public:
/*!
* \brief Default constructor
* \param parent
*/
CFsdClientHandler(QObject *parent);
/*!
* \brief Destructor
*/
~CFsdClientHandler() {}
/*!
* \brief Starts connection to FSD server
* \param host
*/
Q_INVOKABLE void connectTo(const QString &host);
signals:
void connectedTo( const QString &host);
public slots:
};
#endif // FSDCLIENTHANDLER_H

View File

@@ -1,13 +0,0 @@
#include <QDebug>
#include "fsdclient.h"
CFsdClient::CFsdClient(QObject *parent) :
QObject(parent)
{
}
void CFsdClient::connectTo(const QString &host)
{
qDebug() << "Client requests to connect to " << host;
}

View File

@@ -1,20 +0,0 @@
#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

View File

@@ -1,32 +0,0 @@
#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);
}

View File

@@ -1,39 +0,0 @@
#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

View File

@@ -1,33 +1,46 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
#include "blackcore/dbusserver.h" #include "blackcore/dbus_server.h"
#include "planemanagerhandler.h" #include "aircraft_manager_handler.h"
#include "atcmanagerhandler.h" #include "aircraft_manager.h"
#include "atcmanager.h" #include "atc_manager_handler.h"
#include "fsdclient.h" #include "atc_manager.h"
#include "fsdclienthandler.h" #include "fsd_client.h"
#include "fsd_client_handler.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
BlackCore::CDBusServer server; CRemoteAircraft::registerMetaType();
BlackCore::CDBusServer server("tcp:host=127.0.0.1,port=45000");
// Setting up our objects // Setting up our objects
CPlaneManager planeManager; CAircraftManager aircraftManager;
aircraftManager.addAircraft(CRemoteAircraft("DLH456"));
aircraftManager.addAircraft(CRemoteAircraft("DLH555"));
aircraftManager.addAircraft(CRemoteAircraft("DLH666"));
CAtcManager atcManager; CAtcManager atcManager;
atcManager.addATC("EDDM_N_TWR");
atcManager.addATC("KJFK_GND");
atcManager.addATC("LOWW_CTR");
CFsdClient fsdclient; CFsdClient fsdclient;
// Setting up the handler to expose the objects via DBus // Setting up the handler to expose the objects via DBus
CPlaneManagerHandler planeManagerHandler(&planeManager); CAircraftManagerHandler aircraftManagerHandler(&aircraftManager);
CAtcManagerHandler atcManagerHandler(&atcManager); CAtcManagerHandler atcManagerHandler(&atcManager);
CFsdClientHandler fsdClientHandler (&fsdclient); CFsdClientHandler fsdClientHandler (&fsdclient);
// Pass the DBus server to the handlers. This registers also // Pass the DBus server to the handlers. This registers also
// the handler in the DBus server and makes it available // the handler in the DBus server and makes it available
// via the interface. // via the interface.
planeManagerHandler.setDBusServer(&server); aircraftManagerHandler.setDBusServer(&server);
atcManagerHandler.setDBusServer(&server); atcManagerHandler.setDBusServer(&server);
fsdClientHandler.setDBusServer(&server); fsdClientHandler.setDBusServer(&server);

View File

@@ -1,16 +0,0 @@
#include "planemanager.h"
CPlaneManager::CPlaneManager(QObject *parent) :
QObject(parent)
{
m_pilotsList << "DLH123" << "BER456" << "SWS789";
}
CPlaneManager::~CPlaneManager()
{
}
QStringList CPlaneManager::pilotList() const
{
return m_pilotsList;
}

View File

@@ -1,28 +0,0 @@
#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

View File

@@ -1,6 +0,0 @@
<!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>

View File

@@ -1,33 +0,0 @@
#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();
}

View File

@@ -1,34 +0,0 @@
#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

View File

@@ -0,0 +1,68 @@
#include "remote_aircraft.h"
CRemoteAircraft::CRemoteAircraft() :
m_callsign(), m_heading(0), m_groundSpeed(0), m_wakeTurbulence()
{
}
CRemoteAircraft::CRemoteAircraft(const QString &callsign) :
m_callsign(callsign), m_heading(0), m_groundSpeed(0), m_wakeTurbulence("M")
{
}
CRemoteAircraft::CRemoteAircraft(const CRemoteAircraft &other) :
m_callsign(other.m_callsign),
m_heading(other.m_heading),
m_groundSpeed(other.m_groundSpeed),
m_wakeTurbulence(other.m_wakeTurbulence)
{
}
CRemoteAircraft &CRemoteAircraft::operator =(const CRemoteAircraft &other)
{
if (this != &other)
{
m_callsign = other.m_callsign;
m_heading = other.m_heading;
m_groundSpeed = other.m_groundSpeed;
m_wakeTurbulence = other.m_wakeTurbulence;
}
return *this;
}
bool CRemoteAircraft::operator ==(const CRemoteAircraft &other)
{
return (m_callsign == other.m_callsign);
}
void CRemoteAircraft::registerMetaType()
{
qRegisterMetaType<CRemoteAircraft>("CRemoteAircraft");
qDBusRegisterMetaType<CRemoteAircraft>();
qDBusRegisterMetaType<CRemoteAircraftList>();
}
QDBusArgument &operator<<(QDBusArgument &argument, const CRemoteAircraft& remoteAircraft)
{
argument.beginStructure();
argument << remoteAircraft.m_callsign;
argument << remoteAircraft.m_heading;
argument << remoteAircraft.m_groundSpeed;
argument << remoteAircraft.m_wakeTurbulence;
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, CRemoteAircraft &remoteAircraft)
{
argument.beginStructure();
argument >> remoteAircraft.m_callsign;
argument >> remoteAircraft.m_heading;
argument >> remoteAircraft.m_groundSpeed;
argument >> remoteAircraft.m_wakeTurbulence;
argument.endStructure();
return argument;
}

View File

@@ -0,0 +1,92 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 REMOTE_AIRCRAFT_H
#define REMOTE_AIRCRAFT_H
#include <QtDBus>
/*!
* \brief Remove Aircraft
* \details This class represents a aircraft from another user in the network
* \author Roland Winklmeier
* \version 0.1
* \date July 2013
*/
class CRemoteAircraft
{
QString m_callsign; //!< Aircrafts callsign
double m_heading; //!< Aircrafts heading.
double m_groundSpeed; //!< Aircrafts groundspeed in knots
QString m_wakeTurbulence; //!< wake turbulence classification
public:
/*!
* \brief Constructor
*/
CRemoteAircraft();
CRemoteAircraft(const QString &callsign);
/*!
* \brief Copy constructor
* \param other
*/
CRemoteAircraft(const CRemoteAircraft &other);
/*!
* \brief Assignment operator
* \param other
*/
CRemoteAircraft &operator=(const CRemoteAircraft &other);
/*!
* \brief Compare operator
* \param other
*/
bool operator==(const CRemoteAircraft &other);
/*!
* \brief Destructor
*/
~CRemoteAircraft() {}
friend QDBusArgument &operator<<(QDBusArgument &argument, const CRemoteAircraft &remoteAircraft);
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CRemoteAircraft &remoteAircraft);
/*!
* \brief Aircrafts Callsign
*/
QString getCallsign() const { return m_callsign; }
/*!
* \brief Aircrafts heading
*/
double getHeading() const { return m_heading; }
/*!
* \brief Aircrafts ground speed
*/
double getGroundSpeed() const { return m_groundSpeed; }
/*!
* \brief Aircrafts wake turbulence classification
*/
QString getWakeTurbulence() const { return m_wakeTurbulence; }
static void registerMetaType();
};
typedef QList<CRemoteAircraft> CRemoteAircraftList;
Q_DECLARE_METATYPE(CRemoteAircraft)
Q_DECLARE_METATYPE(CRemoteAircraftList)
#endif // REMOTE_AIRCRAFT_H

View File

@@ -14,7 +14,7 @@ CONFIG -= app_bundle
TEMPLATE = app TEMPLATE = app
DBUS_ADAPTORS += planemanager.xml atcmanager.xml fsdclient.xml DBUS_ADAPTORS += dbus/aircraftmanager.xml dbus/atcmanager.xml dbus/fsdclient.xml
DEPENDPATH += . ../../src DEPENDPATH += . ../../src
INCLUDEPATH += . ../../src INCLUDEPATH += . ../../src
@@ -22,6 +22,9 @@ INCLUDEPATH += . ../../src
HEADERS += *.h HEADERS += *.h
SOURCES += *.cpp SOURCES += *.cpp
QDBUSXML2CPP_INTERFACE_HEADER_FLAGS = -i remote_aircraft.h
QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS = -i remote_aircraft.h
LIBS += -L../../lib -lblackcore -lblackmisc LIBS += -L../../lib -lblackcore -lblackmisc
win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \

View File

@@ -1,16 +1,16 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 <QDebug> #include <QDebug>
#include "dbusserver.h" #include "dbus_server.h"
namespace BlackCore namespace BlackCore {
{
// TODO: CDBusServer::CDBusServer(const QString &address, QObject *parent) :
// - Change constructor to use address from the config file QObject(parent), m_busServer(address, parent)
// - 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()) if (!m_busServer.isConnected())
{ {
@@ -18,7 +18,7 @@ namespace BlackCore
} }
else else
{ {
qDebug() << "Server is running on" << m_busServer.address(); qDebug() << "Server listening on address: " << m_busServer.address();
} }
connect(&m_busServer, &QDBusServer::newConnection, this, &CDBusServer::newConnection); connect(&m_busServer, &QDBusServer::newConnection, this, &CDBusServer::newConnection);
@@ -53,4 +53,3 @@ namespace BlackCore
} // namespace BlackCore } // namespace BlackCore

View File

@@ -0,0 +1,64 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 DBUSSERVER_H
#define DBUSSERVER_H
#include <QObject>
#include <QtDBus/QDBusServer>
#include <QtDBus/QDBusError>
#include <QtDBus/QDBusConnection>
#include <QStringList>
#include <QMap>
namespace BlackCore {
/*!
* \brief Custom DBusServer
* \details This class implements a custom DBusServer for DBus peer connections
*/
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(const QString &address, 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:
/*!
* \brief Called when a new DBus client has connected
* \param connection
*/
void newConnection(const QDBusConnection & connection);
signals:
};
}
#endif // DBUSSERVER_H

View File

@@ -1,51 +0,0 @@
#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

View File

@@ -0,0 +1,30 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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/dbus_server.h"
#include "blackmisc/dbus_handler.h"
namespace BlackMisc
{
IDBusHandler::IDBusHandler(QObject *parent) :
QObject(parent), m_dbusserver(0), m_parent(parent)
{
}
void IDBusHandler::setDBusServer(BlackCore::CDBusServer *dbusServer)
{
m_dbusserver = dbusServer;
if (m_dbusserver)
m_dbusserver->addObject(m_dbusPath, this);
}
void IDBusHandler::setDBusObjectPath(const QString &dbusPath)
{
m_dbusPath = dbusPath;
}
} // namespace BlackMisc

View File

@@ -0,0 +1,59 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* 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 DBUS_HANDLER_BASE_H
#define DBUS_HANDLER_BASE_H
#include <QObject>
namespace BlackCore {
class CDBusServer;
}
namespace BlackMisc
{
/*!
* \brief DBus Handler Base class
* \details This class implements the basic methods any DBus handler class needs to use. If you want
* to implement your own DBus handler derive it from this one.
*/
class IDBusHandler : public QObject
{
Q_OBJECT
protected:
BlackCore::CDBusServer *m_dbusserver; //!< Our DBusServer
QString m_dbusPath; //!< DBus object path
QObject *m_parent; //!< Pointer to the parent plane manager object
public:
/*!
* \brief Default constructor
* \param parent
*/
IDBusHandler(QObject *parent = 0);
/*!
* \brief Sets the DBusServer
* \param dbusServer
*/
void setDBusServer(BlackCore::CDBusServer *dbusServer);
void setDBusObjectPath( const QString &dbusPath);
signals:
public slots:
};
} // namespace BlackMisc
#endif // DBUS_HANDLER_BASE_H