13 #include <QDBusConnection>
14 #include <QDBusConnectionInterface>
16 #include <QDBusMessage>
17 #include <QDBusObjectPath>
18 #include <QDBusPendingReply>
20 #include <QDBusVariant>
23 #include <QElapsedTimer>
25 #include <QLatin1Char>
30 #include <QTextStream>
43 using namespace swift::misc::simulation;
44 using namespace swift::misc::physical_quantities;
45 using namespace swift::misc::aviation;
46 using namespace swift::misc::math;
47 using namespace swift::misc::geo;
48 using namespace swift::misc::network;
49 using namespace swift::misc::simulation::fscommon;
53 namespace swift::sample
55 void ServiceTool::dataTransferTestServer(
CDBusServer *dBusServer,
bool verbose)
57 QDBusConnection sessionBusConnection = QDBusConnection::sessionBus();
58 if (sessionBusConnection.interface()->isServiceRegistered(CTestService::InterfaceName()))
60 qFatal(
"Testservice already registed on session bus");
65 CTestService::registerTestService(sessionBusConnection, verbose, QCoreApplication::instance());
66 dBusServer->
addObject(CTestService::ObjectPath(), testService);
69 void ServiceTool::dataTransferTestClient(
const QString &address)
72 const bool sb = address.startsWith(
"session", Qt::CaseInsensitive);
73 QDBusConnection connection =
74 sb ? QDBusConnection::sessionBus() : QDBusConnection::connectToPeer(address,
"p2pConnection");
79 ServiceTool::sendDataToTestservice(connection);
82 void ServiceTool::sendDataToTestservice(
const QDBusConnection &connection)
87 QTextStream qtin(stdin);
88 QTextStream qtout(stdout);
90 const QList<double> list { 1.0, 2.0, 3.0 };
94 QDBusMessage m = QDBusMessage::createSignal(CTestService::ObjectPath(), CTestService::InterfaceName(),
98 const QDateTime dtnow = QDateTime::currentDateTimeUtc();
99 const QString msg = QStringLiteral(
"Con.: %1, message at %2")
100 .arg(connection.name(), dtnow.toString(
"MM/dd/yyyy @ hh:mm:ss"));
105 qtout <<
"----------------- receiver tests ----------------" << Qt::endl;
108 if (connection.send(m)) { qtout <<
"Send via low level method " << Qt::endl; }
113 qtout <<
"Send string via interface " << msg << Qt::endl;
117 qtout <<
"Send list via interface " << list.size() << Qt::endl;
120 CSpeed speed(200, CSpeedUnit::km_h());
121 const CSpeed speedNull(0,
nullptr);
124 qtout <<
"Send speed via interface " << speed << Qt::endl;
126 qtout <<
"Send null speed via interface " << speedNull << Qt::endl;
129 qtout <<
"Send speed via interface " << speed << Qt::endl;
134 const CServer trafficServer = CTestData::getTrafficServer();
135 QVariant tsqv = QVariant::fromValue(trafficServer);
136 QDBusVariant tsv(tsqv);
138 qtout <<
"Send server via interface and variant '" << trafficServer << QLatin1String(
"' ")
139 << tsqv.userType() << Qt::endl;
142 const CComSystem comSystem =
CComSystem(
"DBUS COM1", CPhysicalQuantitiesConstants::FrequencyUnicom(),
143 CPhysicalQuantitiesConstants::FrequencyUnicom());
145 qtout <<
"Send COM via interface " << comSystem << Qt::endl;
147 CAltitude altitude(1000, CAltitude::MeanSeaLevel, CLengthUnit::ft());
148 QVariant qvAl = QVariant::fromValue(altitude);
149 QDBusVariant qv(qvAl);
152 qtout <<
"Send altitude via interface and variant " << altitude << qvAl.userType() << Qt::endl;
155 const CTransponder transponder(7000, CTransponder::ModeC);
157 qtout <<
"Send transponder via interface " << transponder << Qt::endl;
159 const CTrack track(123.45, CTrack::Magnetic, CAngleUnit::deg());
161 qtout <<
"Send track via interface " << track << Qt::endl;
163 const CLength len(33, CLengthUnit::m());
165 qtout <<
"Send length via interface " << len << Qt::endl;
167 const CAltitude alt(44, CAltitude::MeanSeaLevel, CLengthUnit::m());
169 qtout <<
"Send altitude via interface " << alt << Qt::endl;
171 const CCallsign callsign = CTestData::getRandomPilotCallsign();
173 qtout <<
"Send callsign via interface " << callsign << Qt::endl;
175 const CAtcStation station = CTestData::getMunichTower();
177 qtout <<
"Send ATC " << station << Qt::endl;
182 qtout <<
"Send geo position " << geoPos << Qt::endl;
183 CApplication::processEventsFor(1000);
185 qtout <<
"----------------- variant tests ----------------" << Qt::endl;
186 const CVariantList cvList = CTestData::getCVariantList();
188 qtout <<
"Send " << cvList.
size() <<
" variants via interface as CVariantList" << Qt::endl;
192 qtout <<
"Send " << valueMap.
size() <<
" index variant map entries" << Qt::endl;
193 CApplication::processEventsFor(1000);
195 qtout <<
"----------------- pings ----------------" << Qt::endl;
196 const int errors = ITestServiceInterface::pingTests(testServiceInterface,
false);
197 qtout <<
"Ping errors " << errors << Qt::endl;
198 CApplication::processEventsFor(1000);
201 qtout <<
"----------------- performance ----------------" << Qt::endl;
205 for (
int i = 0; i < 10; i++)
208 Q_UNUSED(speedDummy);
210 qint64 t10 = timer.elapsed();
213 for (
int i = 0; i < 100; i++)
216 Q_UNUSED(speedDummy);
218 qint64 t100 = timer.elapsed();
221 for (
int i = 0; i < 1000; i++)
224 Q_UNUSED(speedDummy);
226 qint64 t1000 = timer.elapsed();
228 qtout <<
"Reading speed objects 10/100/1000 in ms: " << t10 <<
" " << t100 <<
" " << t1000 << Qt::endl;
231 for (
int i = 0; i < 10; i++)
234 Q_UNUSED(stationDummy);
236 t10 = timer.elapsed();
238 for (
int i = 0; i < 100; i++)
241 Q_UNUSED(stationDummy);
243 t100 = timer.elapsed();
245 for (
int i = 0; i < 1000; i++)
248 Q_UNUSED(stationDummy);
250 t1000 = timer.elapsed();
251 qtout <<
"Reading station objects 10/100/1000 in ms: " << t10 <<
" " << t100 <<
" " << t1000 << Qt::endl;
255 if (atcStationList.
size() != 10) qtout <<
"wrong list size" << atcStationList.
size() << Qt::endl;
256 t10 = timer.elapsed();
259 if (atcStationList.
size() != 100) qtout <<
"wrong list size" << atcStationList.
size() << Qt::endl;
260 t100 = timer.elapsed();
263 if (atcStationList.
size() != 1000) qtout <<
"wrong list size" << atcStationList.
size() << Qt::endl;
264 t1000 = timer.elapsed();
265 qtout <<
"Reading station list 10/100/1000 in ms: " << t10 <<
" " << t100 <<
" " << t1000 << Qt::endl;
270 if (entriesList.
size() != 5000) qtout <<
"wrong list size" << entriesList.
size() << Qt::endl;
271 qint64 t5000 = timer.elapsed();
272 qtout <<
"Reading aircraft cfg entries in ms: " << t5000 << Qt::endl;
276 QList<QDBusObjectPath> objectPaths = testServiceInterface.
getObjectPaths(10);
277 if (objectPaths.size() != 10) qtout <<
"wrong list size" << objectPaths.size() << Qt::endl;
278 t10 = timer.elapsed();
281 if (objectPaths.size() != 100) qtout <<
"wrong list size" << objectPaths.size() << Qt::endl;
282 t100 = timer.elapsed();
285 if (objectPaths.size() != 1000) qtout <<
"wrong list size" << objectPaths.size() << Qt::endl;
286 t1000 = timer.elapsed();
287 qtout <<
"Reading paths list 10/100/1000 in ms: " << t10 <<
" " << t100 <<
" " << t1000 << Qt::endl;
291 qtout <<
"---------------------------------------" << Qt::endl;
292 qtout <<
"Key ....... x to exit" << Qt::endl;
293 QString line = qtin.readLine().toLower().trimmed();
294 if (line.startsWith(
'x'))
296 qtout <<
"Ending!" << Qt::endl;
void addObject(const QString &name, QObject *object)
Add a QObject to be exposed via DBus.
Specialized value object compliant map for variants, based on indexes.
int size() const
Number of elements.
size_type size() const
Returns number of elements in the sequence.
Value object encapsulating a list of variants.
Altitude as used in aviation, can be AGL or MSL altitude.
Value object encapsulating information about an ATC station.
Value object for a list of ATC stations.
Value object encapsulating information of a callsign.
Track as used in aviation, can be true or magnetic Track.
Value object encapsulating information of a server.
Physical unit length (length)
PQ & switchUnit(const MU &newUnit)
Change unit, and convert value to maintain the same quantity.
void addValueSameUnit(double value)
Add to the value in the current unit.
Utility, providing FS aircraft.cfg entries.
Testservice for PQ / CValueObject DBus tests. This part is the callee.
Proxy class for swift::misc::Test::CTestService. This part is the caller.
QDBusPendingReply receiveAtcStation(const swift::misc::aviation::CAtcStation &station)
DBus calls.
QDBusPendingReply receiveStringMessage(const QString &message)
DBus calls.
QDBusPendingReply< swift::misc::simulation::fscommon::CAircraftCfgEntriesList > getAircraftCfgEntriesList(int number)
DBus calls.
QDBusPendingReply receiveSpeed(const swift::misc::physical_quantities::CSpeed &speed)
DBus calls.
QDBusPendingReply receiveVariantList(const swift::misc::CVariantList &list)
DBus calls.
QDBusPendingReply< swift::misc::aviation::CAtcStation > getAtcStation()
DBus calls.
QDBusPendingReply receiveCallsign(const swift::misc::aviation::CCallsign &callsign)
DBus calls.
QDBusPendingReply receiveLength(const swift::misc::physical_quantities::CLength &length)
DBus calls.
QDBusPendingReply receiveList(const QList< double > &list)
DBus calls.
QDBusPendingReply receiveComUnit(const swift::misc::aviation::CComSystem &comUnit)
DBus calls.
QDBusPendingReply receiveGeoPosition(const swift::misc::geo::CCoordinateGeodetic &geo)
DBus calls.
QDBusPendingReply receiveTransponder(const swift::misc::aviation::CTransponder &transponder)
DBus calls.
QDBusPendingReply< swift::misc::aviation::CAltitude > receiveAltitude(const swift::misc::aviation::CAltitude &altitude)
DBus calls.
QDBusPendingReply< QList< QDBusObjectPath > > getObjectPaths(int number)
DBus calls.
QDBusPendingReply< swift::misc::physical_quantities::CSpeed > getSpeed()
DBus calls.
QDBusPendingReply receiveTrack(const swift::misc::aviation::CTrack &track)
DBus calls.
QDBusPendingReply receiveVariant(const QDBusVariant &variant, int localMetyType)
DBus calls.
QDBusPendingReply receiveValueMap(const swift::misc::CPropertyIndexVariantMap &valueMap)
DBus calls.
QDBusPendingReply< swift::misc::aviation::CAtcStationList > getAtcStationList(int number)
DBus calls.
Backend services of the swift project, like dealing with the network or the simulators.
Generate data for testing purposes.
Free functions in swift::misc.