From 0437bf33818cb279cb5bcfa7a2df314d786ac0e0 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 10 Mar 2014 15:07:43 +0100 Subject: [PATCH] refs #140 , adjust sample for DBus marshalling / unmarshalling in order to test "tupel-ized" classes * Added further DBus tests * Crossover from refs #85 , removed dependency from generator adaptor and XML files, as this will not work anymore in the future * Removed from .pro DBUS_ADAPTORS , DBUS_INTERFACES, QDBUSXML2CPP_INTERFACE_HEADER_FLAGS , QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS * Added interface, as this will be no longer generated * Removed samples no longer required, the sample no represents a framework to test DBus marshalling / unmarshalling --- .../BlackMiscTest.Datacontext.xml | 34 --- .../BlackMiscTest.Testservice.xml | 114 ------- samples/blackmiscdbus/datacontext.cpp | 39 --- samples/blackmiscdbus/datacontext.h | 193 ------------ samples/blackmiscdbus/dummysignalslot.cpp | 20 -- samples/blackmiscdbus/dummysignalslot.h | 43 --- samples/blackmiscdbus/main.cpp | 19 +- samples/blackmiscdbus/readme.txt | 11 + .../blackmiscdbus/sample_blackmisc_dbus.pro | 9 +- samples/blackmiscdbus/servicetool.cpp | 286 +----------------- samples/blackmiscdbus/servicetool.h | 35 +-- samples/blackmiscdbus/testservice.cpp | 7 + samples/blackmiscdbus/testservice.h | 9 +- .../blackmiscdbus/testservice_interface.cpp | 11 + samples/blackmiscdbus/testservice_interface.h | 227 ++++++++++++++ src/blackcore/blackcore.pro | 10 +- src/blackcore/dbus_server.cpp | 7 - 17 files changed, 286 insertions(+), 788 deletions(-) delete mode 100644 samples/blackmiscdbus/BlackMiscTest.Datacontext.xml delete mode 100644 samples/blackmiscdbus/BlackMiscTest.Testservice.xml delete mode 100644 samples/blackmiscdbus/datacontext.cpp delete mode 100644 samples/blackmiscdbus/datacontext.h delete mode 100644 samples/blackmiscdbus/dummysignalslot.cpp delete mode 100644 samples/blackmiscdbus/dummysignalslot.h create mode 100644 samples/blackmiscdbus/testservice_interface.cpp create mode 100644 samples/blackmiscdbus/testservice_interface.h diff --git a/samples/blackmiscdbus/BlackMiscTest.Datacontext.xml b/samples/blackmiscdbus/BlackMiscTest.Datacontext.xml deleted file mode 100644 index 1e8476a45..000000000 --- a/samples/blackmiscdbus/BlackMiscTest.Datacontext.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/blackmiscdbus/BlackMiscTest.Testservice.xml b/samples/blackmiscdbus/BlackMiscTest.Testservice.xml deleted file mode 100644 index 4ba47fb73..000000000 --- a/samples/blackmiscdbus/BlackMiscTest.Testservice.xml +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/blackmiscdbus/datacontext.cpp b/samples/blackmiscdbus/datacontext.cpp deleted file mode 100644 index 255eaa527..000000000 --- a/samples/blackmiscdbus/datacontext.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "datacontext.h" - -namespace BlackMiscTest -{ - - const QString CDataContext::ServiceName = QString(BLACKMISCKTEST_DATACONTEXT_INTERFACENAME); - const QString CDataContext::ServicePath = QString(BLACKMISCKTEST_DATACONTEXT_SERVICEPATH); - - /* - * Init this context - */ - CDataContext::CDataContext(BlackCore::CDBusServer *server) - { - // 1. Register with the server - server->addObject(CDataContext::ServicePath, this); - - // 2. Next I would wire all signals and slots of this context - // belonging together - } - - /* - * FooSlot - */ - void CDataContext::fooSlot(const QString &baz) - { - qDebug() << "foo slot" << baz; - } - - - /* - * FooSlot - * \return - */ - QString CDataContext::fooSlotRet(const QString &baz) - { - qDebug() << "foo slot" << baz; - return baz; - } -} diff --git a/samples/blackmiscdbus/datacontext.h b/samples/blackmiscdbus/datacontext.h deleted file mode 100644 index 8ab546e6e..000000000 --- a/samples/blackmiscdbus/datacontext.h +++ /dev/null @@ -1,193 +0,0 @@ -#ifndef BLACKMISCTEST_DATACONTEXTCORE_H -#define BLACKMISCTEST_DATACONTEXTCORE_H - -#include "blackcore/dbus_server.h" -#include "blackmisc/avallclasses.h" -#include - -#define BLACKMISCKTEST_DATACONTEXT_INTERFACENAME "blackmisctest.datacontext" -#define BLACKMISCKTEST_DATACONTEXT_SERVICEPATH "/datacontext" - -namespace BlackMiscTest -{ - - /*! - * \brief A poor man's Data context running in the core - */ - class CDataContext : public QObject - { - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", BLACKMISCKTEST_DATACONTEXT_INTERFACENAME) - Q_PROPERTY(BlackMisc::Aviation::CAtcStationList qpAtcOnlineList READ onlineControllers WRITE setOnlineControllers) - Q_PROPERTY(BlackMisc::Aviation::CAtcStationList qpAtcBookedList READ bookedControllers WRITE setBookedControllers) - Q_PROPERTY(QStringList qpFooStrings READ fooStrings) - - // no property for Foo, which is just meant to be local only - - Q_SIGNALS: - void fooSignal(const QString &message); - - public: - static const QString ServiceName; - static const QString ServicePath; - - private: - BlackMisc::Aviation::CAtcStationList m_atcOnline; - BlackMisc::Aviation::CAtcStationList m_atcBooked; - QString m_foo; - QStringList m_fooStrings; - - public slots: - - /*! - * \brief FooSlot - * \param baz - */ - void fooSlot(const QString &baz); // generated interface methods are "const &QString", so this must match - - /*! - * \brief FooSlotRet, with return value - * \param baz - * \return - */ - QString fooSlotRet(const QString &baz); - - /*! - * \brief Update booked controllers - * \param condition - * \param values - */ - void updateBookedControllers(const BlackMisc::CValueMap &condition, const BlackMisc::CValueMap &values) - { - qDebug() << Q_FUNC_INFO; - qDebug() << " condition" << condition; - qDebug() << " values" << values; - m_atcBooked.applyIf(condition, values); - } - - /*! - * \brief Update online controllers - * \param condition - * \param values - */ - void updateOnlineControllers(const BlackMisc::CValueMap &condition, const BlackMisc::CValueMap &values) - { - qDebug() << Q_FUNC_INFO; - qDebug() << " condition" << condition; - qDebug() << " values" << values; - m_atcOnline.applyIf(condition, values); - } - - public: - /*! - * \brief Default constructor - */ - CDataContext(QObject *parent = nullptr) : QObject(parent) {} - - /*! - * \brief ctor for Qt meta system - * \param other - */ - CDataContext(const CDataContext &other) : - QObject(), m_atcOnline(other.m_atcOnline), m_atcBooked(other.m_atcBooked), m_foo(other.m_foo), m_fooStrings(other.fooStrings()) - { - // void - } - - /*! - * \brief With link to server - * \param server - */ - CDataContext(BlackCore::CDBusServer *server); - - /*! - * \brief The "central" ATC list with online ATC controllers - * \return - */ - BlackMisc::Aviation::CAtcStationList &onlineControllers() - { - qDebug() << Q_FUNC_INFO; - return m_atcOnline; - } - - /*! - * \brief The "central" ATC list with online ATC controllers - * \return - */ - const BlackMisc::Aviation::CAtcStationList &onlineControllers() const - { - return m_atcOnline; - } - - /*! - * \brief Another ATC list, maybe all booked controllers - * \return - */ - const BlackMisc::Aviation::CAtcStationList &bookedControllers() const - { - qDebug() << Q_FUNC_INFO; - return m_atcBooked; - } - - /*! - * \brief Replace value by new values, but keep object itself intact - * \param newValues - */ - void setBookedControllers(const BlackMisc::Aviation::CAtcStationList &newValues) - { - // problem concurrent updates - qDebug() << Q_FUNC_INFO; - this->m_atcBooked = newValues; - } - - /*! - * \brief Replace value by new values, but keep object itself intact - * \param newValues - */ - void setOnlineControllers(const BlackMisc::Aviation::CAtcStationList &newValues) - { - // problem concurrent updates - qDebug() << Q_FUNC_INFO; - this->m_atcOnline = newValues; - } - - /*! - * \brief Some property which would be local only - * \return - */ - const QString &foo() const - { - qDebug() << Q_FUNC_INFO; - return m_foo; - } - - /*! - * \brief Some foo strings - * \return - */ - const QStringList &fooStrings() const - { - qDebug() << Q_FUNC_INFO; - return m_fooStrings; - } - - /*! - * \brief Set n foo strings - * \param number - */ - void setFooStrings(int number) - { - this->m_fooStrings.clear(); - for (int i = 0; i < number; i++) - { - QString foo("I am foo "); - foo.append(QString::number(i)); - this->m_fooStrings.append(foo); - } - } - - }; -} -Q_DECLARE_METATYPE(BlackMiscTest::CDataContext) - -#endif // guard diff --git a/samples/blackmiscdbus/dummysignalslot.cpp b/samples/blackmiscdbus/dummysignalslot.cpp deleted file mode 100644 index f7a39c630..000000000 --- a/samples/blackmiscdbus/dummysignalslot.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "dummysignalslot.h" - -namespace BlackMiscTest -{ - - /* - * Constructor - */ - CDummySignalSlot::CDummySignalSlot(const QString &name, QObject *parent) : QObject(parent), m_name(name) - {} - - /* - * Dummy slot - */ - void CDummySignalSlot::slotCDummy(const QString &saySomething) - { - qDebug() << Q_FUNC_INFO << "name:" << this->m_name << "received:" << saySomething; - } - -} diff --git a/samples/blackmiscdbus/dummysignalslot.h b/samples/blackmiscdbus/dummysignalslot.h deleted file mode 100644 index 8ce74ee59..000000000 --- a/samples/blackmiscdbus/dummysignalslot.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef BLACKMISCTEST_DUMMYSIGNALSLOT_H -#define BLACKMISCTEST_DUMMYSIGNALSLOT_H - -#include -#include -#include - -namespace BlackMiscTest -{ - - /*! - * \brief Dummy class to hook a signal or slot - */ - class CDummySignalSlot : public QObject - { - Q_OBJECT - - public: - /*! - * \brief CDummySignalSlot - * \param parent - */ - CDummySignalSlot(const QString &name, QObject *parent = 0); - - signals: - /*! - * \brief Test signal - * \param saySomething - */ - void signalCDummy(const QString &saySomething); - public slots: - /*! - * \brief Test slot - * \param saySomething - */ - void slotCDummy(const QString &saySomething); - - private: - QString m_name; - - }; -} -#endif // BLACKMISCTEST_DUMMYSIGNALSLOT_H diff --git a/samples/blackmiscdbus/main.cpp b/samples/blackmiscdbus/main.cpp index d2c519c61..311a97d4c 100644 --- a/samples/blackmiscdbus/main.cpp +++ b/samples/blackmiscdbus/main.cpp @@ -65,10 +65,6 @@ int main(int argc, char *argv[]) qDebug() << "1 .. Run testservice to test data transfer" << addressTcp; qDebug() << "1sb. Run testservice via session bus"; - qDebug() << "2 .. Data context example (via TCP)" << addressTcp; - qDebug() << "2sb. Data context example (via session bus)"; - qDebug() << "3 .. Data context example, only server (via TCP)" << addressTcp; - qDebug() << "3sb. Data context example, only server (via session bus)"; qDebug() << "----- Change address / port (no validation, do before starting server)"; qDebug() << "loop Address to loopback, 127.0.0.1"; qDebug() << "ip some IP address, e.g 192.168.100.100"; @@ -107,16 +103,11 @@ int main(int argc, char *argv[]) // start DBus address = QString(useSessionBusForServer ? "session" : addressTcp); // testing with real transfer - bool startClient = !mode.startsWith('3'); if (mode.contains("sb", Qt::CaseInsensitive)) address = "session"; if (mode.startsWith("1")) { mode = "testservice"; } - else if (mode.startsWith('2') || mode.startsWith('3')) - { - mode = "context"; - } else { return 0; @@ -142,17 +133,13 @@ int main(int argc, char *argv[]) args << ip; args << port; } - if (startClient) BlackMiscTest::ServiceTool::startNewProcess(executable, args, &a); + BlackMiscTest::ServiceTool::startNewProcess(executable, args, &a); // run tests if (mode == "testservice") { BlackMiscTest::ServiceTool::dataTransferTestServer(dBusServer); } - else if (mode == "context") - { - BlackMiscTest::ServiceTool::contextTestServer(dBusServer); - } // loop return a.exec(); @@ -167,10 +154,6 @@ int main(int argc, char *argv[]) { BlackMiscTest::ServiceTool::dataTransferTestClient(address); } - else if (cmdlineArgs.contains("context", Qt::CaseInsensitive)) - { - BlackMiscTest::ServiceTool::contextTestClient(address); - } // loop return a.exec(); diff --git a/samples/blackmiscdbus/readme.txt b/samples/blackmiscdbus/readme.txt index c2254ea4e..d89049c08 100644 --- a/samples/blackmiscdbus/readme.txt +++ b/samples/blackmiscdbus/readme.txt @@ -11,3 +11,14 @@ Set search path for plugins: env.var. QT_PLUGIN_PATH Done automatically (qmake), but if required manually Interface: qdbusxml2cpp blackbus.testservice.xml -p itestservice Adaptor: qdbusxml2cpp blackbus.testservice.xml -a atestservice + +-- Removed after changing to "handwritten" interface + +# Causes nmake to run qdbusxml2cpp to automatically generate the dbus adaptor and interface classes, +# then automatically adds them to the sources to compile +# DBUS_ADAPTORS += BlackMiscTest.Testservice.xml BlackMiscTest.Datacontext.xml +# DBUS_INTERFACES += BlackMiscTest.Testservice.xml BlackMiscTest.Datacontext.xml +# DBUS_INTERFACES += BlackMiscTest.Datacontext.xml +# QDBUSXML2CPP_INTERFACE_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h +# QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h + diff --git a/samples/blackmiscdbus/sample_blackmisc_dbus.pro b/samples/blackmiscdbus/sample_blackmisc_dbus.pro index 29b8b1a41..0bd54e1b7 100644 --- a/samples/blackmiscdbus/sample_blackmisc_dbus.pro +++ b/samples/blackmiscdbus/sample_blackmisc_dbus.pro @@ -6,13 +6,6 @@ TEMPLATE = app CONFIG += console c++11 CONFIG -= app_bundle -# Causes nmake to run qdbusxml2cpp to automatically generate the dbus adaptor and interface classes, -# then automatically adds them to the sources to compile -DBUS_ADAPTORS += BlackMiscTest.Testservice.xml BlackMiscTest.Datacontext.xml -DBUS_INTERFACES += BlackMiscTest.Testservice.xml BlackMiscTest.Datacontext.xml -QDBUSXML2CPP_INTERFACE_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h -QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h - DEPENDPATH += . ../../src/blackmisc ../../src/blackcore INCLUDEPATH += . ../../src @@ -27,4 +20,4 @@ DESTDIR = ../../bin HEADERS += *.h SOURCES += *.cpp -OTHER_FILES += readme.txt BlackMiscTest.Testservice.xml BlackMiscTest.Datacontext.xml +OTHER_FILES += *.txt *.xml diff --git a/samples/blackmiscdbus/servicetool.cpp b/samples/blackmiscdbus/servicetool.cpp index 28934868f..e861ce74a 100644 --- a/samples/blackmiscdbus/servicetool.cpp +++ b/samples/blackmiscdbus/servicetool.cpp @@ -1,10 +1,6 @@ #include "servicetool.h" #include "testservice.h" -#include "testservice_adaptor.h" #include "testservice_interface.h" -#include "datacontext.h" -#include "datacontext_interface.h" -#include "datacontext_adaptor.h" #include "blackcore/dbus_server.h" #include "blackmisc/valuemap.h" #include "blackmisc/nwserver.h" @@ -97,45 +93,6 @@ namespace BlackMiscTest ServiceTool::sendDataToTestservice(p2pConnection); } - /* - * Context data transfer test server - */ - void ServiceTool::contextTestServer(BlackCore::CDBusServer *dBusServer) - { - // init data context - CDataContext *dataContext = new CDataContext(dBusServer); - - // create a object which can be connected to signals / slots - CDummySignalSlot *serverSignalSlot = new CDummySignalSlot("server", QCoreApplication::instance()); - - // Adaptor based on context objext - DatacontextAdaptor *dataContextAdaptor = new DatacontextAdaptor(dataContext); // needs to be created in same thread - - // Run server loop: - // This happens in a different thread, because server needs event loop for - // its signal and slots - QtConcurrent::run(ServiceTool::serverLoop, dBusServer, dataContext, dataContextAdaptor, serverSignalSlot); // QFuture future - qDebug() << "Server event loop, pid:" << ServiceTool::getPid(); - } - - /* - * Context data transfer test client - */ - void ServiceTool::contextTestClient(const QString &address) - { - // create a object which can be connected to signals / slots - CDummySignalSlot *clientSignalSlot = new CDummySignalSlot("client", QCoreApplication::instance()); - - // connection - QDBusConnection p2pConnection = address == "session" ? - QDBusConnection::sessionBus() : - QDBusConnection::connectToPeer(address, "p2pConnection"); - - // run client loop - QtConcurrent::run(ServiceTool::clientLoop, p2pConnection, clientSignalSlot); // QFuture future - qDebug() << "Client event loop, pid:" << ServiceTool::getPid(); - } - /* * Get callsign */ @@ -182,8 +139,6 @@ namespace BlackMiscTest Testservice *ServiceTool::registerTestservice(QDBusConnection &connection, QObject *parent) { Testservice *pTestservice = new Testservice(parent); // just a QObject with signals / slots and Q_CLASSINFO("D-Bus Interface", some service name) - TestserviceAdaptor *pTestserviceAdaptor = new TestserviceAdaptor(pTestservice); - if (!connection.registerService(Testservice::ServiceName)) { QDBusError err = connection.lastError(); @@ -194,14 +149,13 @@ namespace BlackMiscTest qFatal("Could not register service!"); } - if (!connection.registerObject(Testservice::ServicePath, pTestservice)) + if (!connection.registerObject(Testservice::ServicePath, pTestservice, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals | QDBusConnection::ExportAdaptors)) { qFatal("Could not register service object!"); } qDebug() << "Registration running as pid:" << ServiceTool::getPid(); if (pTestservice) qDebug() << "Service registered"; - if (pTestserviceAdaptor) qDebug() << "Adaptor object registered"; QString service; // service not needed if (connection.connect( @@ -223,7 +177,7 @@ namespace BlackMiscTest void ServiceTool::sendDataToTestservice(const QDBusConnection &connection) { // on the client's side - BlackmisctestTestserviceInterface testserviceInterface(Testservice::ServiceName, Testservice::ServicePath, connection); + TestServiceInterface testserviceInterface(Testservice::ServiceName, Testservice::ServicePath, connection); CSpeed speed(200, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h()); CAltitude al(1000, CAltitude::MeanSeaLevel, CLengthUnit::ft()); @@ -308,16 +262,23 @@ namespace BlackMiscTest CCallsign callsign("d-ambz"); testserviceInterface.receiveCallsign(callsign); qDebug() << "Send callsign via interface" << callsign; + CCoordinateGeodetic geoPos = CCoordinateGeodetic::fromWgs84("48° 21′ 13″ N", "11° 47′ 09″ E", CLength(1487, CLengthUnit::ft())); // Munich - CAtcStation station(CCallsign("eddm_twr"), CUser("123456", "Joe Doe"), + CAtcStation station(CCallsign("eddm_twr"), CUser("123456", "Joe Controller"), CFrequency(118.7, CFrequencyUnit::MHz()), geoPos, CLength(50, CLengthUnit::km())); testserviceInterface.receiveAtcStation(station); - qDebug() << "Send ATC station via interface" << station; - station = testserviceInterface.pingAtcStation(station); - qDebug() << "Pinged ATC station via interface" << station; + CAtcStation stationReceived = testserviceInterface.pingAtcStation(station); + qDebug() << "Pinged ATC station via interface" + << ((station == stationReceived) ? "OK" : "ERROR!") << stationReceived; + + CAircraftSituation situation; + CAircraft aircraft(callsign, CUser("123456", "Joe Pilot"), situation); + CAircraft aircraftReceived = testserviceInterface.pingAircraft(aircraft); + qDebug() << "Pinged aircraft via interface" + << ((aircraft == aircraftReceived) ? "OK" : "ERROR!") << aircraftReceived; CAtcStationList AtcStationList; AtcStationList.push_back(station); @@ -464,225 +425,4 @@ namespace BlackMiscTest if (ch == 'x') loop = false; } } - - /* - * Send data to testservice, this sends data to the slots on the server - */ - void ServiceTool::serverLoop(BlackCore::CDBusServer *server, CDataContext *dataContext, DatacontextAdaptor *dataContextAdaptor, CDummySignalSlot *dummySignalSlot) - { - QThread::msleep(3 * 1000); // let the client conncect - qDebug() << "Running on server here" << ServiceTool::getPid(); - CCoordinateGeodetic geoPos = CCoordinateGeodetic::fromWgs84("48° 21′ 13″ N", "11° 47′ 09″ E", CLength(1487, CLengthUnit::ft())); // Munich - CAtcStation station(CCallsign("eddm_twr"), CUser("123456", "Server"), - CFrequency(118.7, CFrequencyUnit::MHz()), - geoPos, CLength(50, CLengthUnit::km())); - CAtcStationList stationList; - QTextStream qtin(stdin); - QString line; - - // we can hook up signal slot - if (QObject::connect(dataContext, SIGNAL(fooSignal(QString)), - dummySignalSlot, SLOT(slotCDummy(QString)))) - { - qDebug() << "Hooked up foo signal"; - } - else - { - qDebug() << "Hook up of foo signal failed!!!"; - } - - // - // Server loop - // - while (line != "x") - { - // set a random callsign - station.setCallsign(ServiceTool::getRandomCallsign()); - - // do what we got to do - if (line == "1") - { - stationList.push_back(station); - dataContextAdaptor->setQpAtcOnlineList(stationList); - dataContextAdaptor->setQpAtcBookedList(stationList); - } - else if (line == "2") - { - stationList.push_back(station); - dataContext->setBookedControllers(stationList); - dataContext->setOnlineControllers(stationList); - } - else if (line.startsWith("3")) - { - int end = (line == "3l") ? 1000 : 1; - for (int i = 0; i < end; i++) - { - station.setCallsign(ServiceTool::getRandomCallsign()); - dataContext->onlineControllers().push_back(station); // non const version - } - } - else if (line == "4") - { - // Signal sending is not transparent - qDebug() << "emit foo signal as Qt signal"; - emit dataContext->fooSignal(QDateTime::currentDateTime().toString()); - // emit dataContextAdaptor->fooSignal(QDateTime::currentDateTime().toString()); - } - else if (line == "5") - { - QDBusMessage signal = QDBusMessage::createSignal( - CDataContext::ServicePath, - CDataContext::ServiceName, - "fooSignal"); - signal << QDateTime::currentDateTime().toString(); // parameter - - // With server use the server's connection which is only available once a connection has been established - // otherwise use the given connection which allows to use this method with session/system bus - QDBusConnection serverConnection = server->getDbusConnections().first(); - if (serverConnection.send(signal)) - { - qDebug() << "emit foo signal as DBus signal on server connection " << serverConnection.name(); - } - else - { - qDebug() << "some issue with DBus signal on server connection" << serverConnection.name(); - } - } - else if (line == "6") - { - dataContext->setFooStrings(1000); - } - - // display current status - qDebug() << "-------------"; - qDebug() << "ATC booked"; - qDebug() << dataContext->bookedControllers().toQString(); - qDebug() << "-------------"; - qDebug() << "ATC online"; - qDebug() << dataContext->onlineControllers().toQString(); - qDebug() << "-------------"; - qDebug() << "Foos"; - qDebug() << dataContext->fooStrings(); - qDebug() << "-------------"; - - // next round? Server - qDebug() << "Key x to exit"; - qDebug() << "1 .. new list via property on adaptor"; - qDebug() << "2 .. new list via context"; - qDebug() << "3 .. append 1 to online controllers in context"; // add to reference - qDebug() << "3l . append 1000 to context"; - qDebug() << "4 .. send Foo signal as Qt signal"; - qDebug() << "5 .. send Foo signal as DBus signal"; - qDebug() << "6 .. set 1000 Foo objects"; - - line = qtin.readLine(); - } - } - - /* - * Send data to testservice, this sends data to the slots on the server - */ - void ServiceTool::clientLoop(QDBusConnection &connection, CDummySignalSlot *dummyObjectSignalSlot) - { - // Service name does not matter when using P2P, it is only required using session/system bus - // Using a literal here ("foo"), crashes the app - BlackmisctestDatacontextInterface dataContextInterface(BlackCore::CDBusServer::ServiceName, CDataContext::ServicePath, connection); - if (dummyObjectSignalSlot) - { - const QString signalName("fooSignal"); - if (connection.connect(BlackCore::CDBusServer::ServiceName, CDataContext::ServicePath, CDataContext::ServiceName, signalName, dummyObjectSignalSlot, SLOT(slotCDummy(QString)))) - { - qDebug() << "Hooked up foo signal on connection"; - } - else - { - qDebug() << "Hook up of foo signal failed on connection!!!"; - } - - - // we can hook up signal slot - if (dataContextInterface.connect(&dataContextInterface, SIGNAL(fooSignal(QString)), - dummyObjectSignalSlot, SLOT(slotCDummy(QString)))) - { - qDebug() << "Hooked up foo signal on interface"; - } - else - { - qDebug() << "Hook up of foo signal failed on interface!!!"; - } - } - - qDebug() << "Running on client here, pid:" << ServiceTool::getPid(); - CCoordinateGeodetic geoPos = CCoordinateGeodetic::fromWgs84("48° 21′ 13″ N", "11° 47′ 09″ E", CLength(1487, CLengthUnit::ft())); // Munich - CAtcStation station(CCallsign("eddm_twr"), CUser("654321", "client"), - CFrequency(118.7, CFrequencyUnit::MHz()), - geoPos, CLength(50, CLengthUnit::km())); - QTextStream qtin(stdin); - QString line; - - // - // Server loop - // - while (line != "x") - { - // set a random callsign - station.setCallsign(ServiceTool::getRandomCallsign()); - - // do what we got to do - if (line == "1") - { - // retrieves all stations, add one, and sends them back - CAtcStationList stations = dataContextInterface.qpAtcBookedList(); - stations.push_back(station); - dataContextInterface.setQpAtcBookedList(stations); - - stations = dataContextInterface.qpAtcOnlineList(); - stations.push_back(station); - dataContextInterface.setQpAtcOnlineList(stations); - } - else if (line == "3") - { - // this will not change anything - dataContextInterface.qpAtcBookedList().push_back(station); - dataContextInterface.qpAtcOnlineList().push_back(station); - } - else if (line == "5") - { - emit dataContextInterface.fooSignal("Directly called on interface on client"); - } - else if (line.startsWith("7") && line.length() > 1) - { - CCallsign callsign(line.mid(1)); - CValueMap condition; - condition.addValue(CAtcStation::IndexCallsign, callsign); - CValueMap value; - value.addValue(CAtcStation::IndexBookedFrom, QDateTime::currentDateTimeUtc().addDays(1)); - value.addValue(CAtcStation::IndexBookedUntil, QDateTime::currentDateTimeUtc().addDays(2)); - qDebug() << " condition" << condition; - qDebug() << " values" << value; - dataContextInterface.updateOnlineControllers(condition, value); - } - - // display current status - qDebug() << "-------------"; - qDebug() << "ATC booked"; - qDebug() << dataContextInterface.qpAtcBookedList().toQString(); // as property - qDebug() << "-------------"; - qDebug() << "ATC online"; - qDebug() << dataContextInterface.qpAtcOnlineList().toQString(); // as property - qDebug() << "-------------"; - qDebug() << "Foos"; - qDebug() << dataContextInterface.qpFooStrings(); - qDebug() << "-------------"; - - // next round? Client - qDebug() << "Key x to exit"; - qDebug() << "1 .. add new list via property on interface"; - qDebug() << "3 .. append 1 to controllers in context (not expected to change anything)"; // add to reference - qDebug() << "5 .. foo signal directly on interface"; - qDebug() << "7x . 7, update if, e.g. 7EDDM_TWR"; - - line = qtin.readLine(); - } - } } // namespace diff --git a/samples/blackmiscdbus/servicetool.h b/samples/blackmiscdbus/servicetool.h index 4f80ce8a0..0c5d4e051 100644 --- a/samples/blackmiscdbus/servicetool.h +++ b/samples/blackmiscdbus/servicetool.h @@ -2,21 +2,17 @@ #define BLACKMISCTEST_SERVICETOOL_H #include "blackcore/dbus_server.h" -#include "datacontext.h" -#include "dummysignalslot.h" +#include "blackmisc/avatcstationlist.h" #include #include #include -class DatacontextAdaptor; - namespace BlackMiscTest { - class Testservice; // forward declaration /*! - * \brief Supporting functions for running the tests + * \brief Supporting / helper functions for running the tests */ class ServiceTool { @@ -44,18 +40,6 @@ namespace BlackMiscTest */ static void dataTransferTestServer(BlackCore::CDBusServer *dBusServer); - /*! - * \brief Context test, server side - * \param dBusServer - */ - static void contextTestServer(BlackCore::CDBusServer *dBusServer); - - /*! - * \brief Context test, client side - * \param address - */ - static void contextTestClient(const QString &address); - /*! * \brief Start a new process * \param executable @@ -85,21 +69,6 @@ namespace BlackMiscTest */ static Testservice *registerTestservice(QDBusConnection &connection, QObject *parent = 0); - /*! - * \brief Server loop - * \param server - * \param dataContext - * \param dataContextAdaptor - * \param dummySignalSlot - */ - static void serverLoop(BlackCore::CDBusServer *server, CDataContext *dataContext, DatacontextAdaptor *dataContextAdaptor, CDummySignalSlot *dummySignalSlot); - - /*! - * \brief Client loop - * \param connection - */ - static void clientLoop(QDBusConnection &connection, CDummySignalSlot *dummyObjectSignalSlot); - /*! * \brief Get a random callsign * \return diff --git a/samples/blackmiscdbus/testservice.cpp b/samples/blackmiscdbus/testservice.cpp index 6348f730d..6a59af3bb 100644 --- a/samples/blackmiscdbus/testservice.cpp +++ b/samples/blackmiscdbus/testservice.cpp @@ -250,4 +250,11 @@ namespace BlackMiscTest return station; } + /* + * Ping aircraft + */ + BlackMisc::Aviation::CAircraft Testservice::pingAircraft(const BlackMisc::Aviation::CAircraft &aircraft) + { + return aircraft; + } } // namespace diff --git a/samples/blackmiscdbus/testservice.h b/samples/blackmiscdbus/testservice.h index cab3472be..1797fee89 100644 --- a/samples/blackmiscdbus/testservice.h +++ b/samples/blackmiscdbus/testservice.h @@ -157,6 +157,13 @@ namespace BlackMiscTest */ BlackMisc::Aviation::CAtcStation pingAtcStation(const BlackMisc::Aviation::CAtcStation &station); + /*! + * \brief Ping aircraft + * \param aircraft + * \return + */ + BlackMisc::Aviation::CAircraft pingAircraft(const BlackMisc::Aviation::CAircraft &aircraft); + /*! * \brief Receive callsign * \param callsign @@ -216,7 +223,7 @@ namespace BlackMiscTest * \brief Constructor * \param parent */ - explicit Testservice(QObject *parent = 0); + explicit Testservice(QObject *parent = nullptr); private: BlackMisc::Aviation::CAtcStationList m_someAtcStations; diff --git a/samples/blackmiscdbus/testservice_interface.cpp b/samples/blackmiscdbus/testservice_interface.cpp new file mode 100644 index 000000000..92ac45724 --- /dev/null +++ b/samples/blackmiscdbus/testservice_interface.cpp @@ -0,0 +1,11 @@ +#include "testservice_interface.h" + +namespace BlackMiscTest +{ + TestServiceInterface::TestServiceInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) + {} + + TestServiceInterface::~TestServiceInterface() + {} +} diff --git a/samples/blackmiscdbus/testservice_interface.h b/samples/blackmiscdbus/testservice_interface.h new file mode 100644 index 000000000..a42ba7f57 --- /dev/null +++ b/samples/blackmiscdbus/testservice_interface.h @@ -0,0 +1,227 @@ +#ifndef BLACKMISCTEST_TESTSERVICE_INTERFACE_H +#define BLACKMISCTEST_TESTSERVICE_INTERFACE_H + +#include "blackmisc/blackmiscfreefunctions.h" +#include "blackmisc/blackmiscallvalueclasses.h" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace BlackMiscTest +{ + + /*! + * \brief Proxy class for interface blackmisctest.testservice + */ + class TestServiceInterface: public QDBusAbstractInterface + { + Q_OBJECT + + public: + static inline const char *staticInterfaceName() { return "blackmisctest.testservice"; } + + public: + //! \brief Constructor + TestServiceInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + //! \brief Destructor + ~TestServiceInterface(); + + public Q_SLOTS: + + //! \brief DBus calls + //! @{ + inline QDBusPendingReply getAtcStation() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("getAtcStation"), argumentList); + } + + inline QDBusPendingReply getAtcStationList(int number) + { + QList argumentList; + argumentList << QVariant::fromValue(number); + return asyncCallWithArgumentList(QLatin1String("getAtcStationList"), argumentList); + } + + inline QDBusPendingReply > getObjectPaths(int number) + { + QList argumentList; + argumentList << QVariant::fromValue(number); + return asyncCallWithArgumentList(QLatin1String("getObjectPaths"), argumentList); + } + + inline QDBusPendingReply getSpeed() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("getSpeed"), argumentList); + } + + inline QDBusPendingReply pingAltitude(BlackMisc::Aviation::CAltitude altitude) + { + QList argumentList; + argumentList << QVariant::fromValue(altitude); + return asyncCallWithArgumentList(QLatin1String("pingAltitude"), argumentList); + } + + inline QDBusPendingReply pingAtcStation(BlackMisc::Aviation::CAtcStation station) + { + QList argumentList; + argumentList << QVariant::fromValue(station); + return asyncCallWithArgumentList(QLatin1String("pingAtcStation"), argumentList); + } + + inline QDBusPendingReply pingAircraft(BlackMisc::Aviation::CAircraft aircraft) + { + QList argumentList; + argumentList << QVariant::fromValue(aircraft); + return asyncCallWithArgumentList(QLatin1String("pingAircraft"), argumentList); + } + + inline QDBusPendingReply pingAtcStationList(BlackMisc::Aviation::CAtcStationList AtcStationList) + { + QList argumentList; + argumentList << QVariant::fromValue(AtcStationList); + return asyncCallWithArgumentList(QLatin1String("pingAtcStationList"), argumentList); + } + + inline QDBusPendingReply pingSpeed(BlackMisc::PhysicalQuantities::CSpeed speed) + { + QList argumentList; + argumentList << QVariant::fromValue(speed); + return asyncCallWithArgumentList(QLatin1String("pingSpeed"), argumentList); + } + + inline QDBusPendingReply<> receiveAltitude(BlackMisc::Aviation::CAltitude altitude) + { + QList argumentList; + argumentList << QVariant::fromValue(altitude); + return asyncCallWithArgumentList(QLatin1String("receiveAltitude"), argumentList); + } + + inline QDBusPendingReply<> receiveAtcStation(BlackMisc::Aviation::CAtcStation station) + { + QList argumentList; + argumentList << QVariant::fromValue(station); + return asyncCallWithArgumentList(QLatin1String("receiveAtcStation"), argumentList); + } + + inline QDBusPendingReply<> receiveAtcStationList(BlackMisc::Aviation::CAtcStationList AtcStationList) + { + QList argumentList; + argumentList << QVariant::fromValue(AtcStationList); + return asyncCallWithArgumentList(QLatin1String("receiveAtcStationList"), argumentList); + } + + inline QDBusPendingReply<> receiveCallsign(BlackMisc::Aviation::CCallsign callsign) + { + QList argumentList; + argumentList << QVariant::fromValue(callsign); + return asyncCallWithArgumentList(QLatin1String("receiveCallsign"), argumentList); + } + + inline QDBusPendingReply<> receiveComUnit(BlackMisc::Aviation::CComSystem comUnit) + { + QList argumentList; + argumentList << QVariant::fromValue(comUnit); + return asyncCallWithArgumentList(QLatin1String("receiveComUnit"), argumentList); + } + + inline QDBusPendingReply<> receiveGeoPosition(BlackMisc::Geo::CCoordinateGeodetic geo) + { + QList argumentList; + argumentList << QVariant::fromValue(geo); + return asyncCallWithArgumentList(QLatin1String("receiveGeoPosition"), argumentList); + } + + inline QDBusPendingReply<> receiveLength(BlackMisc::PhysicalQuantities::CLength length) + { + QList argumentList; + argumentList << QVariant::fromValue(length); + return asyncCallWithArgumentList(QLatin1String("receiveLength"), argumentList); + } + + inline QDBusPendingReply<> receiveLengthsQl(const QVariantList &lengthsList) + { + QList argumentList; + argumentList << QVariant::fromValue(lengthsList); + return asyncCallWithArgumentList(QLatin1String("receiveLengthsQl"), argumentList); + } + + inline QDBusPendingReply<> receiveLengthsQvl(const QVariantList &lengthsVariantList) + { + QList argumentList; + argumentList << QVariant::fromValue(lengthsVariantList); + return asyncCallWithArgumentList(QLatin1String("receiveLengthsQvl"), argumentList); + } + + inline QDBusPendingReply<> receiveList(const QList &list) + { + QList argumentList; + argumentList << QVariant::fromValue(list); + return asyncCallWithArgumentList(QLatin1String("receiveList"), argumentList); + } + + inline QDBusPendingReply<> receiveMatrix(BlackMisc::Math::CMatrix3x3 matrix) + { + QList argumentList; + argumentList << QVariant::fromValue(matrix); + return asyncCallWithArgumentList(QLatin1String("receiveMatrix"), argumentList); + } + + inline QDBusPendingReply<> receiveSpeed(BlackMisc::PhysicalQuantities::CSpeed speed) + { + QList argumentList; + argumentList << QVariant::fromValue(speed); + return asyncCallWithArgumentList(QLatin1String("receiveSpeed"), argumentList); + } + + inline QDBusPendingReply<> receiveStringMessage(const QString &message) + { + QList argumentList; + argumentList << QVariant::fromValue(message); + return asyncCallWithArgumentList(QLatin1String("receiveStringMessage"), argumentList); + } + + inline QDBusPendingReply<> receiveTrack(BlackMisc::Aviation::CTrack track) + { + QList argumentList; + argumentList << QVariant::fromValue(track); + return asyncCallWithArgumentList(QLatin1String("receiveTrack"), argumentList); + } + + inline QDBusPendingReply<> receiveTransponder(BlackMisc::Aviation::CTransponder transponder) + { + QList argumentList; + argumentList << QVariant::fromValue(transponder); + return asyncCallWithArgumentList(QLatin1String("receiveTransponder"), argumentList); + } + + inline QDBusPendingReply<> receiveValueMap(BlackMisc::CValueMap valueMap) + { + QList argumentList; + argumentList << QVariant::fromValue(valueMap); + return asyncCallWithArgumentList(QLatin1String("receiveValueMap"), argumentList); + } + + inline QDBusPendingReply<> receiveVariant(const QDBusVariant &variant, int localMetyType) + { + QList argumentList; + argumentList << QVariant::fromValue(variant) << QVariant::fromValue(localMetyType); + return asyncCallWithArgumentList(QLatin1String("receiveVariant"), argumentList); + } + //! @} + + + Q_SIGNALS: + //! \brief send message + void sendStringMessage(const QString &message); + }; +} // namespace + +#endif diff --git a/src/blackcore/blackcore.pro b/src/blackcore/blackcore.pro index f58f4e443..9ec5f444f 100644 --- a/src/blackcore/blackcore.pro +++ b/src/blackcore/blackcore.pro @@ -23,11 +23,11 @@ precompile_header:!isEmpty(PRECOMPILED_HEADER) { # Causes nmake to run qdbusxml2cpp to automatically generate the dbus adaptor and interface classes, # then automatically adds them to the sources to compile # !! Make sure the plugin is available as release build and known QT_PLUGIN_PATH -QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h -DBUS_ADAPTORS += blackcore.contextnetwork.xml -DBUS_ADAPTORS += blackcore.contextvoice.xml -DBUS_ADAPTORS += blackcore.contextsettings.xml -DBUS_ADAPTORS += blackcore.contextapplication.xml +# QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h +# DBUS_ADAPTORS += blackcore.contextnetwork.xml +# DBUS_ADAPTORS += blackcore.contextvoice.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/dbus_server.cpp b/src/blackcore/dbus_server.cpp index ac3096ab6..2d354d295 100644 --- a/src/blackcore/dbus_server.cpp +++ b/src/blackcore/dbus_server.cpp @@ -8,13 +8,6 @@ #include "dbus_server.h" -// TODO: move from dbus_dummy.cpp -// These two header files are not really needed here. But if they are not -// included "somewhere", they are not generated -> compiler error! -// Possible solution: Generate them once and put them in git. -#include "contextnetwork_adaptor.h" -#include "contextsettings_adaptor.h" - namespace BlackCore {