mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Enabled DBus with matrix classes, noticed issue with QList Signature (ad, addddd)
This commit is contained in:
@@ -22,5 +22,13 @@
|
||||
<arg name="altitude" type="(didb(s)(s)b)" direction="in"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="BlackMisc::Aviation::CAltitude"/>
|
||||
</method>
|
||||
<method name="receiveMatrix">
|
||||
<arg name="matrix" type="(ad)" direction="in"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="BlackMisc::Math::CMatrix3x3"/>
|
||||
</method>
|
||||
<method name="receiveList">
|
||||
<arg name="list" type="ad" direction="in"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QList<double>"/>
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <QtDBus/qdbusabstractinterface.h>
|
||||
#include <QtDBus/qdbusconnection.h>
|
||||
#include <QCoreApplication>
|
||||
#include <QList>
|
||||
|
||||
#include "testservice.h"
|
||||
#include "testservice_adaptor.h"
|
||||
@@ -15,6 +16,7 @@
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Math;
|
||||
using namespace BlackMiscTest;
|
||||
|
||||
/*!
|
||||
@@ -88,12 +90,19 @@ int main(int argc, char *argv[])
|
||||
if (connection.send(m)) {
|
||||
qDebug() << "Send via low level method" << m;
|
||||
}
|
||||
TestserviceTool::sleep(2500);
|
||||
|
||||
// same as interface message
|
||||
testserviceInterface.receiveStringMessage(msg);
|
||||
qDebug() << "Send string via interface" << msg;
|
||||
TestserviceTool::sleep(2500);
|
||||
|
||||
// a list
|
||||
QList<double> list;
|
||||
list << 1.0 << 2.0 << 3.0;
|
||||
testserviceInterface.receiveList(list);
|
||||
qDebug() << "Send list via interface" << list;
|
||||
qDebug() << "Key .......";
|
||||
getchar();
|
||||
|
||||
|
||||
// PQs
|
||||
CSpeed speed(speedValue++, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h());
|
||||
@@ -115,8 +124,17 @@ int main(int argc, char *argv[])
|
||||
testserviceInterface.receiveVariant(qv);
|
||||
testserviceInterface.receiveAltitude(al);
|
||||
qDebug() << "Send altitude via interface" << al;
|
||||
|
||||
TestserviceTool::sleep(2500);
|
||||
|
||||
// Math
|
||||
CMatrix3x3 m33;
|
||||
m33.setCellIndex();
|
||||
testserviceInterface.receiveMatrix(m33);
|
||||
qDebug() << "Send matrix" << m33;
|
||||
|
||||
// next round?
|
||||
qDebug() << "Key .......";
|
||||
getchar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
QT += core dbus
|
||||
QT -= gui
|
||||
|
||||
TARGET = sample_quantities_avionics_dbus
|
||||
TEMPLATE = app
|
||||
|
||||
@@ -54,12 +54,27 @@ void Testservice::receiveComUnit(const BlackMisc::Aviation::CComSystem &comUnit)
|
||||
}
|
||||
|
||||
/*
|
||||
* Receivealtitude
|
||||
* Receive altitude
|
||||
*/
|
||||
void Testservice::receiveAltitude(const BlackMisc::Aviation::CAltitude &altitude)
|
||||
{
|
||||
qDebug() << "Pid:" << TestserviceTool::getPid() << "Received altitude:" << altitude;
|
||||
}
|
||||
|
||||
/*
|
||||
* Receive matrix
|
||||
*/
|
||||
void Testservice::receiveMatrix(const BlackMisc::Math::CMatrix3x3 &matrix)
|
||||
{
|
||||
qDebug() << "Pid:" << TestserviceTool::getPid() << "Received matrix:" << matrix;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void Testservice::receiveList(const QList<double> &list)
|
||||
{
|
||||
qDebug() << "Pid:" << TestserviceTool::getPid() << "Received list:" << list;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -76,6 +76,17 @@ public slots:
|
||||
*/
|
||||
void receiveAltitude(const BlackMisc::Aviation::CAltitude &altitude);
|
||||
|
||||
/*!
|
||||
* \brief Receive matrix
|
||||
* \param matrix
|
||||
*/
|
||||
void receiveMatrix(const BlackMisc::Math::CMatrix3x3 &matrix);
|
||||
|
||||
/*!
|
||||
* \brief Receive list
|
||||
* \param list
|
||||
*/
|
||||
void receiveList(const QList<double> &list);
|
||||
|
||||
public:
|
||||
static const QString ServiceName;
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace Aviation
|
||||
*/
|
||||
class CAvionicsBase : public BlackMisc::CBaseStreamStringifier
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
QString m_name; //!< name of the unit
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
namespace Aviation
|
||||
{
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ protected:
|
||||
* \brief Stream to DBus
|
||||
* \param argument
|
||||
*/
|
||||
virtual void marshallToDbus(QDBusArgument &) const { }
|
||||
virtual void marshallToDbus(QDBusArgument &) const {}
|
||||
|
||||
/*!
|
||||
* \brief Stream from DBus
|
||||
|
||||
@@ -34,6 +34,18 @@ void BlackMisc::Aviation::registerMetadata()
|
||||
CAltitude::registerMetadata();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Metadata for math
|
||||
*/
|
||||
void BlackMisc::Math::registerMetadata()
|
||||
{
|
||||
CMatrix3x3::registerMetadata();
|
||||
CMatrix3x1::registerMetadata();
|
||||
CMatrix1x3::registerMetadata();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Metadata for Blackmisc
|
||||
*/
|
||||
@@ -41,4 +53,5 @@ void BlackMisc::registerMetadata()
|
||||
{
|
||||
PhysicalQuantities::registerMetadata();
|
||||
Aviation::registerMetadata();
|
||||
Math::registerMetadata();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#define BLACKMISC_FREEFUNCTIONS_H
|
||||
#include "avallclasses.h"
|
||||
#include "pqallquantities.h"
|
||||
#include "mathallclasses.h"
|
||||
|
||||
namespace BlackMisc {
|
||||
|
||||
@@ -34,6 +35,15 @@ void registerMetadata();
|
||||
|
||||
} // Aviation
|
||||
|
||||
namespace Math {
|
||||
|
||||
/*!
|
||||
* \brief Register metadata for math (matrices, vectors)
|
||||
*/
|
||||
void registerMetadata();
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Register all relevant metadata in BlackMisc
|
||||
*/
|
||||
|
||||
14
src/blackmisc/mathallclasses.h
Normal file
14
src/blackmisc/mathallclasses.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/* 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 BLACKMISC_MATHALLCLASSES_H
|
||||
#define BLACKMISC_MATHALLCLASSES_H
|
||||
|
||||
#include "blackmisc/mathmatrix1x3.h"
|
||||
#include "blackmisc/mathmatrix3x3.h"
|
||||
#include "blackmisc/mathmatrix3x1.h"
|
||||
#include "blackmisc/mathvector3d.h"
|
||||
|
||||
#endif // guard
|
||||
@@ -54,5 +54,6 @@ public:
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix1x3)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -76,5 +76,6 @@ public:
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix3x1)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -177,5 +177,6 @@ public:
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
||||
Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix3x3)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -69,6 +69,53 @@ template<class ImplMatrix, int Rows, int Columns> bool CMatrixBase<ImplMatrix, R
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Set cell index
|
||||
*/
|
||||
template<class ImplMatrix, int Rows, int Columns> void CMatrixBase<ImplMatrix, Rows, Columns>::setCellIndex()
|
||||
{
|
||||
for (int r = 0; r < Rows; r++)
|
||||
{
|
||||
for (int c = 0; c < Columns; c++)
|
||||
{
|
||||
this->m_matrix(r, c) = r + 0.1 * c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* To list
|
||||
*/
|
||||
template<class ImplMatrix, int Rows, int Columns> const QList<double> CMatrixBase<ImplMatrix, Rows, Columns>::toList() const
|
||||
{
|
||||
QList<double> list;
|
||||
for (int r = 0; r < Rows; r++)
|
||||
{
|
||||
for (int c = 0; c < Columns; c++)
|
||||
{
|
||||
list.append(this->m_matrix(r, c));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* From list
|
||||
*/
|
||||
template<class ImplMatrix, int Rows, int Columns> void CMatrixBase<ImplMatrix, Rows, Columns>::fromList(const QList<double> &list)
|
||||
{
|
||||
Q_ASSERT_X(Rows * Columns == list.count(), "fromList()", "Mismatch of elements in list");
|
||||
int ct = 0;
|
||||
for (int r = 0; r < Rows; r++)
|
||||
{
|
||||
for (int c = 0; c < Columns; c++)
|
||||
{
|
||||
this->m_matrix(r, c) = list.at(ct++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* All values equal?
|
||||
*/
|
||||
@@ -120,6 +167,16 @@ template <class ImplMatrix, int Rows, int Columns> QString CMatrixBase<ImplMatri
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
template <class ImplMatrix, int Rows, int Columns> void CMatrixBase<ImplMatrix, Rows, Columns>::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<ImplMatrix>(typeid(ImplMatrix).name());
|
||||
qDBusRegisterMetaType<ImplMatrix>();
|
||||
}
|
||||
|
||||
|
||||
// see here for the reason of thess forward instantiations
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
template class CMatrixBase<CMatrix3x3, 3, 3>;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "blackmisc/basestreamstringifier.h"
|
||||
#include "blackmisc/mathvector3dbase.h"
|
||||
#include <QGenericMatrix>
|
||||
#include <QDBusMetaType>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -49,6 +50,34 @@ protected:
|
||||
*/
|
||||
QString stringForConverter() const;
|
||||
|
||||
/*!
|
||||
* \brief Stream to DBus
|
||||
* \param argument
|
||||
*/
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const {
|
||||
const QList<double> l = this->toList();
|
||||
|
||||
// there is an issue with the signature of QList, so I use
|
||||
// individual values
|
||||
foreach(double v, l) {
|
||||
argument << v;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
*/
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) {
|
||||
QList<double> list;
|
||||
double v;
|
||||
while(!argument.atEnd()) {
|
||||
argument >> v;
|
||||
list.append(v);
|
||||
}
|
||||
this->fromList(list);
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
@@ -75,6 +104,18 @@ public:
|
||||
*/
|
||||
virtual ~CMatrixBase() {}
|
||||
|
||||
/*!
|
||||
* \brief List of values
|
||||
* \return
|
||||
*/
|
||||
const QList<double> toList() const;
|
||||
|
||||
/*!
|
||||
* \brief List of values
|
||||
* \return
|
||||
*/
|
||||
void fromList(const QList<double> &list);
|
||||
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
* \param otherMatrix
|
||||
@@ -264,6 +305,11 @@ public:
|
||||
*/
|
||||
bool isZero() const;
|
||||
|
||||
/*!
|
||||
* \brief Each cell gets a unique index (used primarily for testing)
|
||||
*/
|
||||
void setCellIndex();
|
||||
|
||||
/*!
|
||||
* \brief Is identity matrix? Epsilon considered.
|
||||
* \return
|
||||
@@ -342,6 +388,11 @@ public:
|
||||
return this->getElement(row, column);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Register metadata
|
||||
*/
|
||||
static void registerMetadata();
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief Check range of row / column
|
||||
|
||||
@@ -294,14 +294,6 @@ protected:
|
||||
*/
|
||||
typedef double(*UnitConverter)(const CMeasurementUnit &, double);
|
||||
|
||||
/*!
|
||||
* \brief Stream to DBus
|
||||
* \param argument
|
||||
*/
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const {
|
||||
argument << this->m_unitName;
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_name; //!< name, e.g. "meter"
|
||||
QString m_unitName; //!< unit name, e.g. "m"
|
||||
@@ -347,7 +339,6 @@ protected:
|
||||
*/
|
||||
CMeasurementUnit &operator =(const CMeasurementUnit &otherUnit);
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief String for streaming operators is full name
|
||||
* \return
|
||||
@@ -397,6 +388,24 @@ protected:
|
||||
return value / this->m_conversionFactorToSIConversionUnit;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream to DBus
|
||||
* \param argument
|
||||
*/
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const {
|
||||
argument << this->m_unitName;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream from DBus
|
||||
* \param argument
|
||||
*/
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &) {
|
||||
// the concrete implementations will override this default
|
||||
// this is required so I can also stream None
|
||||
(*this) = CMeasurementUnit::None();
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
|
||||
Reference in New Issue
Block a user