mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Shifted DBus operators to CBaseStreamStringifier, much easier to provide streaming - especially for derived classes.
Still required but unwanted overloaded DBus operator in aviomodulator.h - no compilation without them. Need to be removed. Enabled more classes for DBus.
This commit is contained in:
@@ -15,8 +15,12 @@
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="BlackMisc::PhysicalQuantities::CSpeed"/>
|
||||
</method>
|
||||
<method name="receiveComUnit">
|
||||
<arg name="comUnit" type="((didb(s)(s))(didb(s)(s))i)" direction="in"/>
|
||||
<arg name="comUnit" type="(s(didb(s)(s))(didb(s)(s))i)" direction="in"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="BlackMisc::Aviation::CComSystem"/>
|
||||
</method>
|
||||
<method name="receiveAltitude">
|
||||
<arg name="altitude" type="(didb(s)(s)b)" direction="in"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="BlackMisc::Aviation::CAltitude"/>
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
||||
|
||||
@@ -60,8 +60,7 @@ int main(int argc, char *argv[])
|
||||
QString service; // service not needed
|
||||
if (QDBusConnection::sessionBus().connect(
|
||||
service, Testservice::ServicePath, Testservice::ServiceName,
|
||||
"sendStringMessage", pTestservice,
|
||||
SLOT(receiveStringMessage(const QString &)))) {
|
||||
"sendStringMessage", pTestservice, SLOT(receiveStringMessage(const QString &)))) {
|
||||
qDebug() << "Connected object with bus sendStringMessage";
|
||||
} else {
|
||||
qFatal("Cannot connect service with DBus");
|
||||
@@ -100,12 +99,23 @@ int main(int argc, char *argv[])
|
||||
CSpeed speed(speedValue++, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h());
|
||||
testserviceInterface.receiveSpeed(speed);
|
||||
qDebug() << "Send speed via interface" << speed;
|
||||
|
||||
speed.switchUnit(CSpeedUnit::kts());
|
||||
testserviceInterface.receiveSpeed(speed);
|
||||
qDebug() << "Send speed via interface" << speed;
|
||||
TestserviceTool::sleep(2500);
|
||||
|
||||
// Aviation
|
||||
CComSystem comSystem = CComSystem("DBUS COM1", CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress(), CPhysicalQuantitiesConstants::FrequencyUnicom());
|
||||
testserviceInterface.receiveComUnit(comSystem);
|
||||
qDebug() << "Send COM via interface" << comSystem;
|
||||
|
||||
CAltitude al(1000, true, CLengthUnit::ft());
|
||||
QDBusVariant qv(QVariant::fromValue(al));
|
||||
testserviceInterface.receiveVariant(qv);
|
||||
testserviceInterface.receiveAltitude(al);
|
||||
qDebug() << "Send altitude via interface" << al;
|
||||
|
||||
TestserviceTool::sleep(2500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ Starting: dbus-daemon.exe --session
|
||||
- blocks CMD (sometimes daemon continues to run when pressing CTRL/C)
|
||||
- does not start without directory session.d, i.e. ..\Qt\Qt5.1.0DBus\qtbase\etc\dbus-1\session.d
|
||||
|
||||
qdbuscpp2xml testservice.h -x H:\Projects\QtBuilds\build-client-Qt_5_1_0_VATSIM_qmake_Microsoft_Visual_C_Compiler_10_0_x86_2-Release\bin\blackmisc_cpp2xml.dll -o BlackMiscTest.Testservice.xml
|
||||
qdbuscpp2xml testservice.h -x blackmisc_cpp2xml.dll -o BlackMiscTest.Testservice.xml
|
||||
Set search path for plugins: env.var. QT_PLUGIN_PATH
|
||||
|
||||
Done automatically, but if required manually
|
||||
Interface: qdbusxml2cpp blackbus.testservice.xml -p itestservice
|
||||
|
||||
@@ -33,7 +33,8 @@ void Testservice::receiveStringMessage(const QString &message)
|
||||
void Testservice::receiveVariant(const QDBusVariant &variant)
|
||||
{
|
||||
QVariant qv = variant.variant();
|
||||
qDebug() << "Pid:" << TestserviceTool::getPid() << "Received variant:" << qv;
|
||||
BlackMisc::Aviation::CAltitude altitude = qv.value<BlackMisc::Aviation::CAltitude>();
|
||||
qDebug() << "Pid:" << TestserviceTool::getPid() << "Received variant:" << altitude;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -52,5 +53,13 @@ void Testservice::receiveComUnit(const BlackMisc::Aviation::CComSystem &comUnit)
|
||||
qDebug() << "Pid:" << TestserviceTool::getPid() << "Received COM:" << comUnit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Receivealtitude
|
||||
*/
|
||||
void Testservice::receiveAltitude(const BlackMisc::Aviation::CAltitude &altitude)
|
||||
{
|
||||
qDebug() << "Pid:" << TestserviceTool::getPid() << "Received altitude:" << altitude;
|
||||
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -65,11 +65,18 @@ public slots:
|
||||
void receiveSpeed(const BlackMisc::PhysicalQuantities::CSpeed &speed);
|
||||
|
||||
/*!
|
||||
* \brief receiveComUnit
|
||||
* \brief Receive com unit
|
||||
* \param comUnit
|
||||
*/
|
||||
void receiveComUnit(const BlackMisc::Aviation::CComSystem &comUnit);
|
||||
|
||||
/*!
|
||||
* \brief Receive altitude
|
||||
* \param comUnit
|
||||
*/
|
||||
void receiveAltitude(const BlackMisc::Aviation::CAltitude &altitude);
|
||||
|
||||
|
||||
public:
|
||||
static const QString ServiceName;
|
||||
static const QString ServicePath;
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
QT += core dbus
|
||||
|
||||
TARGET = sample_quantities_avionics_xmlplugin
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG += plugin
|
||||
|
||||
DEPENDPATH += . ../../src/blackmisc
|
||||
INCLUDEPATH += . ../../src
|
||||
|
||||
LIBS += -L../../lib -lblackmisc \
|
||||
../blackmiscquantities_dbus/release/dummy.obj \
|
||||
../blackmiscquantities_dbus/release/moc_dummy.obj \
|
||||
../blackmiscquantities_dbus/release/dummynoq.obj
|
||||
|
||||
win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \
|
||||
../../samples/blackmiscquantities_dbus/release/dummy.obj
|
||||
else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \
|
||||
../../samples/blackmiscquantities_dbus/release/dummy.obj
|
||||
|
||||
DESTDIR = ../../bin
|
||||
|
||||
HEADERS += *.h
|
||||
SOURCES += *.cpp
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#include "sampleplugin.h"
|
||||
|
||||
|
||||
void CXmlSamplePlugin::registerMetaTypes()
|
||||
{
|
||||
qRegisterMetaType<BlackMiscTest::Dummy>("BlackMiscTest::Dummy");
|
||||
qDBusRegisterMetaType<BlackMiscTest::Dummy>();
|
||||
|
||||
qRegisterMetaType<BlackMiscTest::DummyNoQ>("BlackMiscTest::DummyNoQ");
|
||||
qDBusRegisterMetaType<BlackMiscTest::DummyNoQ>();
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#ifndef SAMPLEPLUGIN_H
|
||||
#define SAMPLEPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QDBusMetaType>
|
||||
#include <QMetaType>
|
||||
#include "../blackmiscquantities_dbus/dummy.h"
|
||||
#include "../blackmiscquantities_dbus/dummynoq.h"
|
||||
|
||||
class CXmlSamplePlugin : public QObject, public QDBusCpp2XmlPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDBusCpp2XmlPlugin)
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.DBus.Cpp2XmlPlugin")
|
||||
|
||||
public:
|
||||
virtual void registerMetaTypes();
|
||||
};
|
||||
|
||||
#endif // SAMPLEPLUGIN_H
|
||||
@@ -50,5 +50,14 @@ bool CAltitude::operator !=(const CAltitude &otherAltitude)
|
||||
return !((*this) == otherAltitude);
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
void CAltitude::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<CAltitude>(typeid(CAltitude).name());
|
||||
qDBusRegisterMetaType<CAltitude>();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -28,6 +28,24 @@ protected:
|
||||
*/
|
||||
virtual QString stringForConverter() const;
|
||||
|
||||
/*!
|
||||
* \brief Stream to DBus <<
|
||||
* \param argument
|
||||
*/
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const {
|
||||
CLength::marshallToDbus(argument);
|
||||
argument << this->m_msl;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream from DBus >>
|
||||
* \param argument
|
||||
*/
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
CLength::unmarshallFromDbus(argument);
|
||||
argument >> this->m_msl;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
@@ -105,9 +123,16 @@ public:
|
||||
{
|
||||
return this->m_msl;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Register metadata
|
||||
*/
|
||||
static void registerMetadata();
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CAltitude)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -19,17 +19,16 @@ namespace Aviation
|
||||
/*!
|
||||
* \brief Base class for avionics
|
||||
*/
|
||||
class CAvionicsBase : public CBaseStreamStringifier
|
||||
class CAvionicsBase : public BlackMisc::CBaseStreamStringifier
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
QString m_name; //!< name of the unit
|
||||
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
* \brief Constructor
|
||||
*/
|
||||
CAvionicsBase(const QString &name) : m_name(name) {}
|
||||
CAvionicsBase(const QString &name) : CBaseStreamStringifier(), m_name(name) {}
|
||||
|
||||
/*!
|
||||
* \brief Are the set values valid / in range
|
||||
@@ -60,6 +59,22 @@ protected:
|
||||
return this->m_name == otherSystem.m_name;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream to DBus <<
|
||||
* \param argument
|
||||
*/
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const {
|
||||
argument << this->m_name;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream from DBus >>
|
||||
* \param argument
|
||||
*/
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
argument >> this->m_name;
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* 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 BLACKMISC_AVIOCOMUNIT_H
|
||||
#define BLACKMISC_AVIOCOMUNIT_H
|
||||
#ifndef BLACKMISC_AVIOCOMSYSTEM_H
|
||||
#define BLACKMISC_AVIOCOMSYSTEM_H
|
||||
#include "blackmisc/aviomodulator.h"
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -315,8 +315,10 @@ public:
|
||||
static bool tryGetCom3System(CComSystem &comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) {
|
||||
return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom3(), activeFrequency, standbyFrequency);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "blackmisc/aviomodulator.h"
|
||||
#include "blackmisc/aviocomsystem.h"
|
||||
#include "blackmisc/avionavsystem.h"
|
||||
#include "blackmisc/avioadfsystem.h"
|
||||
|
||||
using BlackMisc::PhysicalQuantities::CFrequency;
|
||||
using BlackMisc::PhysicalQuantities::CFrequencyUnit;
|
||||
@@ -25,12 +26,20 @@ template <class AVIO> void CModulator<AVIO>::toggleActiveStandby()
|
||||
this->m_frequencyStandby = a;
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
template <class AVIO> void CModulator<AVIO>::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<AVIO>(typeid(AVIO).name());
|
||||
qDBusRegisterMetaType<AVIO>();
|
||||
}
|
||||
|
||||
/*
|
||||
* Assigment operator =
|
||||
*/
|
||||
template <class AVIO> CModulator<AVIO>& CModulator<AVIO>::operator=(const CModulator<AVIO> &otherModulator)
|
||||
{
|
||||
|
||||
if (this == &otherModulator) return *this; // Same object?
|
||||
this->m_frequencyActive = otherModulator.m_frequencyActive;
|
||||
this->m_frequencyStandby = otherModulator.m_frequencyStandby;
|
||||
@@ -63,6 +72,8 @@ template <class AVIO> bool CModulator<AVIO>::operator !=(const CModulator<AVIO>
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
template class CModulator<CComSystem>;
|
||||
template class CModulator<CNavSystem>;
|
||||
template class CModulator<CAdfSystem>;
|
||||
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#ifndef BLACKMISC_AVIOMODULATORUNIT_H
|
||||
#define BLACKMISC_AVIOMODULATORUNIT_H
|
||||
|
||||
#include <QDBusArgument>
|
||||
#include <QDBusMetaType>
|
||||
#include "blackmisc/aviobase.h"
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -19,6 +19,33 @@ namespace Aviation
|
||||
*/
|
||||
template <class AVIO> class CModulator : public CAvionicsBase
|
||||
{
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, DBus to object
|
||||
* \param argument
|
||||
* \param uc
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, AVIO &uc) {
|
||||
// If I do not have the method here, DBus metasystem tries to stream against
|
||||
// a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<T> &list)
|
||||
// Once someone solves this, this methods should go and the CBaseStreamStringifier signature
|
||||
// should be used
|
||||
CBaseStreamStringifier &sf = uc;
|
||||
return argument >> sf;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Marshalling operator <<, object to DBus
|
||||
* \param argument
|
||||
* \param pq
|
||||
* \return
|
||||
*/
|
||||
friend QDBusArgument &operator<<(QDBusArgument &argument, const AVIO &uc)
|
||||
{
|
||||
const CBaseStreamStringifier &sf = uc;
|
||||
return argument << sf;
|
||||
}
|
||||
|
||||
private:
|
||||
BlackMisc::PhysicalQuantities::CFrequency m_frequencyActive; //!< active frequency
|
||||
BlackMisc::PhysicalQuantities::CFrequency m_frequencyStandby; //!< standby frequency
|
||||
@@ -207,6 +234,28 @@ protected:
|
||||
return f;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream to DBus <<
|
||||
* \param argument
|
||||
*/
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const {
|
||||
CAvionicsBase::marshallToDbus(argument);
|
||||
argument << this->m_frequencyActive;
|
||||
argument << this->m_frequencyStandby;
|
||||
argument << this->m_digits;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream from DBus >>
|
||||
* \param argument
|
||||
*/
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
CAvionicsBase::unmarshallFromDbus(argument);
|
||||
argument >> this->m_frequencyActive;
|
||||
argument >> this->m_frequencyStandby;
|
||||
argument >> this->m_digits;
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
@@ -262,47 +311,10 @@ public:
|
||||
this->m_frequencyStandby = frequency;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, DBus to object
|
||||
* \param argument
|
||||
* \param aviationUnit
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, AVIO &aviationUnit) {
|
||||
argument.beginStructure();
|
||||
argument >> aviationUnit.m_frequencyActive;
|
||||
argument >> aviationUnit.m_frequencyStandby;
|
||||
argument >> aviationUnit.m_digits;
|
||||
argument >> aviationUnit.m_name;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Marshalling operator <<, object to DBus
|
||||
* \param argument
|
||||
* \param aviationUnit
|
||||
* \return
|
||||
*/
|
||||
friend QDBusArgument &operator<<(QDBusArgument &argument, const AVIO& aviationUnit)
|
||||
{
|
||||
argument.beginStructure();
|
||||
argument << aviationUnit.m_frequencyActive;
|
||||
argument << aviationUnit.m_frequencyStandby;
|
||||
argument << aviationUnit.m_digits;
|
||||
argument << aviationUnit.m_name;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Register metadata
|
||||
*/
|
||||
static void registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<AVIO>(typeid(AVIO).name());
|
||||
qDBusRegisterMetaType<AVIO>();
|
||||
}
|
||||
static void registerMetadata();
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define BLACKMISC_BASESTREAMSTRINGIFIER_H
|
||||
|
||||
#include "blackmisc/debug.h"
|
||||
#include <QDBusMetaType>
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
#include <QDataStream>
|
||||
@@ -23,10 +24,10 @@ class CBaseStreamStringifier
|
||||
*/
|
||||
friend QDebug operator<<(QDebug debug, const CBaseStreamStringifier &uc)
|
||||
{
|
||||
const CBaseStreamStringifier &sf = uc; // allows to access protected method
|
||||
debug << sf.stringForStreaming();
|
||||
debug << uc.stringForStreaming();
|
||||
return debug;
|
||||
}
|
||||
|
||||
// msvc2010: friend QDebug &operator<<(QDebug &debug, const CBaseStreamStringifier &uc)
|
||||
// MinGW: No reference
|
||||
|
||||
@@ -38,8 +39,7 @@ class CBaseStreamStringifier
|
||||
*/
|
||||
friend QTextStream &operator<<(QTextStream &textStream, const CBaseStreamStringifier &uc)
|
||||
{
|
||||
const CBaseStreamStringifier &sf = uc; // allows to acces protected method
|
||||
textStream << sf.stringForStreaming();
|
||||
textStream << uc.stringForStreaming();
|
||||
return textStream;
|
||||
}
|
||||
|
||||
@@ -62,8 +62,7 @@ class CBaseStreamStringifier
|
||||
*/
|
||||
friend QDataStream &operator<<(QDataStream &stream, const CBaseStreamStringifier &uc)
|
||||
{
|
||||
const CBaseStreamStringifier &sf = uc; // allows to acces protected method
|
||||
stream << sf.stringForStreaming();
|
||||
stream << uc.stringForStreaming();
|
||||
return stream;
|
||||
}
|
||||
|
||||
@@ -75,8 +74,7 @@ class CBaseStreamStringifier
|
||||
*/
|
||||
friend CLogMessage operator<<(CLogMessage log, const CBaseStreamStringifier &uc)
|
||||
{
|
||||
const CBaseStreamStringifier &sf = uc; // allows to acces protected method
|
||||
log << sf.stringForStreaming();
|
||||
log << uc.stringForStreaming();
|
||||
return log;
|
||||
}
|
||||
|
||||
@@ -88,12 +86,39 @@ class CBaseStreamStringifier
|
||||
*/
|
||||
friend std::ostream &operator<<(std::ostream &ostr, const CBaseStreamStringifier &uc)
|
||||
{
|
||||
const CBaseStreamStringifier &sf = uc; // allows to acces protected method
|
||||
ostr << sf.stringForStreaming().toStdString();
|
||||
ostr << uc.stringForStreaming().toStdString();
|
||||
return ostr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, DBus to object
|
||||
* \param argument
|
||||
* \param uc
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CBaseStreamStringifier &uc) {
|
||||
argument.beginStructure();
|
||||
uc.unmarshallFromDbus(argument);
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Marshalling operator <<, object to DBus
|
||||
* \param argument
|
||||
* \param pq
|
||||
* \return
|
||||
*/
|
||||
friend QDBusArgument &operator<<(QDBusArgument &argument, const CBaseStreamStringifier &uc)
|
||||
{
|
||||
argument.beginStructure();
|
||||
uc.marshallToDbus(argument);
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
@@ -109,6 +134,10 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CBaseStreamStringifier() {}
|
||||
|
||||
/*!
|
||||
* \brief String for streaming operators
|
||||
@@ -126,6 +155,18 @@ protected:
|
||||
*/
|
||||
virtual QString stringForConverter() const = 0;
|
||||
|
||||
/*!
|
||||
* \brief Stream to DBus
|
||||
* \param argument
|
||||
*/
|
||||
virtual void marshallToDbus(QDBusArgument &) const { }
|
||||
|
||||
/*!
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
*/
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &) {}
|
||||
|
||||
/*!
|
||||
* \brief Copy assignment operator.
|
||||
* This is protected in order to forbid slicing an instance of one derived
|
||||
|
||||
@@ -29,8 +29,9 @@ void BlackMisc::PhysicalQuantities::registerMetadata()
|
||||
void BlackMisc::Aviation::registerMetadata()
|
||||
{
|
||||
CComSystem::registerMetadata();
|
||||
CAdfSystem::registerMetadata();
|
||||
CNavSystem::registerMetadata();
|
||||
CAdfSystem::registerMetadata();
|
||||
CAltitude::registerMetadata();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -50,6 +50,24 @@ protected:
|
||||
return this->m_name;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream to DBus
|
||||
* \param argument
|
||||
*/
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const {
|
||||
argument << this->m_name;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
*/
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
QString name;
|
||||
argument >> name;
|
||||
(*this) = CMeasurementPrefix::fromPrefixName(name);
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
@@ -224,6 +242,40 @@ public:
|
||||
return milli;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief All prefixes
|
||||
* \return
|
||||
*/
|
||||
static const QList<CMeasurementPrefix> &prefixes()
|
||||
{
|
||||
static QList<CMeasurementPrefix> prefixes;
|
||||
prefixes.append(CMeasurementPrefix::c());
|
||||
prefixes.append(CMeasurementPrefix::G());
|
||||
prefixes.append(CMeasurementPrefix::h());
|
||||
prefixes.append(CMeasurementPrefix::k());
|
||||
prefixes.append(CMeasurementPrefix::M());
|
||||
prefixes.append(CMeasurementPrefix::m());
|
||||
prefixes.append(CMeasurementPrefix::None());
|
||||
prefixes.append(CMeasurementPrefix::One());
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Prefix from name
|
||||
* \param prefixName must be valid!
|
||||
* \return
|
||||
*/
|
||||
static const CMeasurementPrefix &fromPrefixName(const QString &prefixName) {
|
||||
QList<CMeasurementPrefix> prefixes = CMeasurementPrefix::prefixes();
|
||||
// read only, avoid deep copy
|
||||
for (int i = 0; i < prefixes.size(); ++i) {
|
||||
if (prefixes.at(i).getName() == prefixName) return (prefixes.at(i));
|
||||
}
|
||||
qFatal("Illegal unit name");
|
||||
return CMeasurementPrefix::None(); // just suppress "not all control paths return a value"
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
@@ -243,16 +295,11 @@ protected:
|
||||
typedef double(*UnitConverter)(const CMeasurementUnit &, double);
|
||||
|
||||
/*!
|
||||
* \brief Get unit from DBus argument
|
||||
* \brief Stream to DBus
|
||||
* \param argument
|
||||
* \return
|
||||
*/
|
||||
static QString unitNameUnmarshalling(const QDBusArgument &argument) {
|
||||
QString type;
|
||||
argument.beginStructure();
|
||||
argument >> type;
|
||||
argument.endStructure();
|
||||
return type;
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const {
|
||||
argument << this->m_unitName;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -520,21 +567,6 @@ public:
|
||||
return abs(checkValue) <= this->m_epsilon;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Marshalling (to DBus) operator, unmarshalling to be found in specialized classes and
|
||||
* mapping back to static object
|
||||
* \brief Marshalling (to DBus) operator <<
|
||||
* \param argument
|
||||
* \param unit
|
||||
* \return
|
||||
*/
|
||||
friend QDBusArgument &operator<<(QDBusArgument &argument, const CMeasurementUnit& unit) {
|
||||
argument.beginStructure();
|
||||
argument << unit.m_unitName;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// -- static
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
@@ -422,40 +422,29 @@ public:
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, DBus to object
|
||||
* \brief Stream to DBus <<
|
||||
* \param argument
|
||||
* \param pq
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, PQ &pq) {
|
||||
argument.beginStructure();
|
||||
argument >> pq.m_unitValueD;
|
||||
argument >> pq.m_unitValueI;
|
||||
argument >> pq.m_convertedSiUnitValueD;
|
||||
argument >> pq.m_isIntegerBaseValue;
|
||||
argument >> pq.m_unit;
|
||||
argument >> pq.m_conversionSiUnit;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const {
|
||||
argument << this->m_unitValueD;
|
||||
argument << this->m_unitValueI;
|
||||
argument << this->m_convertedSiUnitValueD;
|
||||
argument << this->m_isIntegerBaseValue;
|
||||
argument << this->m_unit;
|
||||
argument << this->m_conversionSiUnit;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Marshalling operator <<, object to DBus
|
||||
* \brief Stream from DBus >>
|
||||
* \param argument
|
||||
* \param pq
|
||||
* \return
|
||||
*/
|
||||
friend QDBusArgument &operator<<(QDBusArgument &argument, const PQ& pq)
|
||||
{
|
||||
argument.beginStructure();
|
||||
argument << pq.m_unitValueD;
|
||||
argument << pq.m_unitValueI;
|
||||
argument << pq.m_convertedSiUnitValueD;
|
||||
argument << pq.m_isIntegerBaseValue;
|
||||
argument << pq.m_unit;
|
||||
argument << pq.m_conversionSiUnit;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
argument >> this->m_unitValueD;
|
||||
argument >> this->m_unitValueI;
|
||||
argument >> this->m_convertedSiUnitValueD;
|
||||
argument >> this->m_isIntegerBaseValue;
|
||||
argument >> this->m_unit;
|
||||
argument >> this->m_conversionSiUnit;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -160,16 +160,15 @@ public:
|
||||
return CLengthUnit::m(); // just suppress "not all control paths return a value"
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, map back to concrete static object
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
* \param dummy
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CLengthUnit &unit) {
|
||||
QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument);
|
||||
unit = CLengthUnit::fromUnitName(unitName);
|
||||
return argument;
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
(*this) = CLengthUnit::fromUnitName(unitName);
|
||||
}
|
||||
};
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CLengthUnit)
|
||||
@@ -289,16 +288,15 @@ public:
|
||||
return CAngleUnit::rad(); // just suppress "not all control paths return a value"
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, map back to concrete static object
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
* \param dummy
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CAngleUnit &unit) {
|
||||
QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument);
|
||||
unit = CAngleUnit::fromUnitName(unitName);
|
||||
return argument;
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
(*this) = CAngleUnit::fromUnitName(unitName);
|
||||
}
|
||||
};
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAngleUnit)
|
||||
@@ -406,16 +404,15 @@ public:
|
||||
return CFrequencyUnit::Hz(); // just suppress "not all control paths return a value"
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, map back to concrete static object
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
* \param dummy
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CFrequencyUnit &unit) {
|
||||
QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument);
|
||||
unit = CFrequencyUnit::fromUnitName(unitName);
|
||||
return argument;
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
(*this) = CFrequencyUnit::fromUnitName(unitName);
|
||||
}
|
||||
};
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CFrequencyUnit)
|
||||
@@ -523,16 +520,15 @@ public:
|
||||
return CMassUnit::kg(); // just suppress "not all control paths return a value"
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, map back to concrete static object
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
* \param dummy
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CMassUnit &unit) {
|
||||
QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument);
|
||||
unit = CMassUnit::fromUnitName(unitName);
|
||||
return argument;
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
(*this) = CMassUnit::fromUnitName(unitName);
|
||||
}
|
||||
|
||||
};
|
||||
@@ -673,16 +669,15 @@ public:
|
||||
return CPressureUnit::Pa(); // just suppress "not all control paths return a value"
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, map back to concrete static object
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
* \param dummy
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CPressureUnit &unit) {
|
||||
QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument);
|
||||
unit = CPressureUnit::fromUnitName(unitName);
|
||||
return argument;
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
(*this) = CPressureUnit::fromUnitName(unitName);
|
||||
}
|
||||
};
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPressureUnit)
|
||||
@@ -805,16 +800,15 @@ public:
|
||||
return CTemperatureUnit::K(); // just suppress "not all control paths return a value"
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, map back to concrete static object
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
* \param dummy
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CTemperatureUnit &unit) {
|
||||
QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument);
|
||||
unit = CTemperatureUnit::fromUnitName(unitName);
|
||||
return argument;
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
(*this) = CTemperatureUnit::fromUnitName(unitName);
|
||||
}
|
||||
};
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTemperatureUnit)
|
||||
@@ -942,16 +936,15 @@ public:
|
||||
return CSpeedUnit::m_s(); // just suppress "not all control paths return a value"
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, map back to concrete static object
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
* \param dummy
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CSpeedUnit &unit) {
|
||||
QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument);
|
||||
unit = CSpeedUnit::fromUnitName(unitName);
|
||||
return argument;
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
(*this) = CSpeedUnit::fromUnitName(unitName);
|
||||
}
|
||||
};
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CSpeedUnit)
|
||||
@@ -1068,16 +1061,15 @@ public:
|
||||
return CTimeUnit::s(); // just suppress "not all control paths return a value"
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, map back to concrete static object
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
* \param dummy
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CTimeUnit &unit) {
|
||||
QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument);
|
||||
unit = CTimeUnit::fromUnitName(unitName);
|
||||
return argument;
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
(*this) = CTimeUnit::fromUnitName(unitName);
|
||||
}
|
||||
};
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTimeUnit)
|
||||
@@ -1161,16 +1153,15 @@ public:
|
||||
return CAccelerationUnit::m_s2(); // just suppress "not all control paths return a value"
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Unmarshalling operator >>, map back to concrete static object
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
* \param dummy
|
||||
* \return
|
||||
*/
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CAccelerationUnit &unit) {
|
||||
QString unitName = CMeasurementUnit::unitNameUnmarshalling(argument);
|
||||
unit = CAccelerationUnit::fromUnitName(unitName);
|
||||
return argument;
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
(*this) = CAccelerationUnit::fromUnitName(unitName);
|
||||
}
|
||||
};
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAccelerationUnit)
|
||||
|
||||
Reference in New Issue
Block a user