1
0
Fork 0

swift cleanup

This commit is contained in:
Lars Toenning 2022-03-26 11:29:25 +01:00 committed by James Turner
parent 7a0be3f000
commit 9ec7d6b855
25 changed files with 1496 additions and 1558 deletions

View file

@ -25,8 +25,11 @@
#include <list> #include <list>
#include <map> #include <map>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/math/SGVec3.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/props/props.hxx>
#include <simgear/structure/SGSharedPtr.hxx> #include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
class FGAIBase; class FGAIBase;
class FGAIThermal; class FGAIThermal;

View file

@ -33,7 +33,7 @@ FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::str
_searchOrder = ModelSearchOrder::PREFER_AI; _searchOrder = ModelSearchOrder::PREFER_AI;
} }
void FGAISwiftAircraft::updatePosition(SGGeod& position, SGVec3<double>& orientation, double groundspeed, bool initPos) void FGAISwiftAircraft::updatePosition(const SGGeod &position, const SGVec3<double> &orientation, double groundspeed, bool initPos)
{ {
m_initPos = initPos; m_initPos = initPos;
_setLatitude(position.getLatitudeDeg()); _setLatitude(position.getLatitudeDeg());

View file

@ -25,8 +25,6 @@
#include "AIBaseAircraft.hxx" #include "AIBaseAircraft.hxx"
using charPtr = const char*;
struct AircraftTransponder struct AircraftTransponder
{ {
AircraftTransponder(std::string callsign, int code, bool modeC, bool ident) AircraftTransponder(std::string callsign, int code, bool modeC, bool ident)
@ -76,7 +74,7 @@ public:
string_view getTypeString() const override { return "swift"; } string_view getTypeString() const override { return "swift"; }
void update(double dt) override; void update(double dt) override;
void updatePosition(SGGeod& position, SGVec3<double>& orientation, double groundspeed, bool initPos); void updatePosition(const SGGeod &position, const SGVec3<double> &orientation, double groundspeed, bool initPos);
double getGroundElevation(const SGGeod& pos) const; double getGroundElevation(const SGGeod& pos) const;
void initProps(); void initProps();
void setPlaneSurface(const AircraftSurfaces& surfaces); void setPlaneSurface(const AircraftSurfaces& surfaces);

View file

@ -49,15 +49,12 @@ bool FGSwiftAircraftManager::addPlane(const std::string& callsign, const std::st
return true; return true;
} }
void FGSwiftAircraftManager::updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<double> groundspeeds, std::vector<bool> onGrounds) void FGSwiftAircraftManager::updatePlanes(const std::vector<std::string>& callsigns, const std::vector<SGGeod>& positions, const std::vector<SGVec3d>& orientations, const std::vector<double>& groundspeeds, const std::vector<bool>& onGrounds)
{ {
for (long unsigned int i = 0; i < callsigns.size(); i++) {
for (long unsigned int i = 0; i < callsigns.size(); i++)
{
auto it = aircraftByCallsign.find(callsigns.at(i)); auto it = aircraftByCallsign.find(callsigns.at(i));
if(it != aircraftByCallsign.end()) if (it != aircraftByCallsign.end()) {
{ it->second->updatePosition(positions.at(i), orientations.at(i), groundspeeds.at(i), true);
it->second->updatePosition(positions.at(i), orientations.at(i), groundspeeds.at(i),true);
} }
} }
} }
@ -73,9 +70,9 @@ void FGSwiftAircraftManager::getRemoteAircraftData(std::vector<std::string>& cal
elevationsM.clear(); elevationsM.clear();
verticalOffsets.clear(); verticalOffsets.clear();
for (const auto & requestedCallsign : requestedCallsigns) { for (const auto& requestedCallsign : requestedCallsigns) {
const auto it = aircraftByCallsign.find(requestedCallsign); const auto it = aircraftByCallsign.find(requestedCallsign);
if(it == aircraftByCallsign.end()) { continue; } if (it == aircraftByCallsign.end()) { continue; }
const FGAISwiftAircraft* aircraft = it->second; const FGAISwiftAircraft* aircraft = it->second;
assert(aircraft); assert(aircraft);
@ -93,14 +90,13 @@ void FGSwiftAircraftManager::getRemoteAircraftData(std::vector<std::string>& cal
longitudesDeg.push_back(lonDeg); longitudesDeg.push_back(lonDeg);
elevationsM.push_back(groundElevation); elevationsM.push_back(groundElevation);
verticalOffsets.push_back(0); verticalOffsets.push_back(0);
} }
} }
void FGSwiftAircraftManager::removePlane(const std::string& callsign) void FGSwiftAircraftManager::removePlane(const std::string& callsign)
{ {
auto it = aircraftByCallsign.find(callsign); auto it = aircraftByCallsign.find(callsign);
if(it != aircraftByCallsign.end()) if (it != aircraftByCallsign.end()) {
{
it->second->setDie(true); it->second->setDie(true);
aircraftByCallsign.erase(it); aircraftByCallsign.erase(it);
} }
@ -108,18 +104,16 @@ void FGSwiftAircraftManager::removePlane(const std::string& callsign)
void FGSwiftAircraftManager::removeAllPlanes() void FGSwiftAircraftManager::removeAllPlanes()
{ {
for(auto it = aircraftByCallsign.begin(); it!= aircraftByCallsign.end();) for (auto it = aircraftByCallsign.begin(); it != aircraftByCallsign.end();) {
{
it->second->setDie(true); it->second->setDie(true);
it = aircraftByCallsign.erase(it); it = aircraftByCallsign.erase(it);
} }
} }
double FGSwiftAircraftManager::getElevationAtPosition(const std::string &callsign, const SGGeod& pos) const double FGSwiftAircraftManager::getElevationAtPosition(const std::string& callsign, const SGGeod& pos) const
{ {
auto it = aircraftByCallsign.find(callsign); auto it = aircraftByCallsign.find(callsign);
if(it != aircraftByCallsign.end()) if (it != aircraftByCallsign.end()) {
{
return it->second->getGroundElevation(pos); return it->second->getGroundElevation(pos);
} }
// Aircraft not found in list // Aircraft not found in list
@ -128,11 +122,9 @@ double FGSwiftAircraftManager::getElevationAtPosition(const std::string &callsig
void FGSwiftAircraftManager::setPlanesTransponders(const std::vector<AircraftTransponder>& transponders) void FGSwiftAircraftManager::setPlanesTransponders(const std::vector<AircraftTransponder>& transponders)
{ {
for (const auto & transponder : transponders) for (const auto& transponder : transponders) {
{
auto it = aircraftByCallsign.find(transponder.callsign); auto it = aircraftByCallsign.find(transponder.callsign);
if(it != aircraftByCallsign.end()) if (it != aircraftByCallsign.end()) {
{
it->second->setPlaneTransponder(transponder); it->second->setPlaneTransponder(transponder);
} }
} }
@ -140,11 +132,9 @@ void FGSwiftAircraftManager::setPlanesTransponders(const std::vector<AircraftTra
void FGSwiftAircraftManager::setPlanesSurfaces(const std::vector<AircraftSurfaces>& surfaces) void FGSwiftAircraftManager::setPlanesSurfaces(const std::vector<AircraftSurfaces>& surfaces)
{ {
for (const auto & surface : surfaces) for (const auto& surface : surfaces) {
{
auto it = aircraftByCallsign.find(surface.callsign); auto it = aircraftByCallsign.find(surface.callsign);
if(it != aircraftByCallsign.end()) if (it != aircraftByCallsign.end()) {
{
it->second->setPlaneSurface(surface); it->second->setPlaneSurface(surface);
} }
} }

View file

@ -17,12 +17,12 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <Scenery/scenery.hxx>
#include <AIModel/AISwiftAircraft.h>
#include <AIModel/AIManager.hxx> #include <AIModel/AIManager.hxx>
#include <AIModel/AISwiftAircraft.h>
#include <Scenery/scenery.hxx>
#include <vector>
#include <unordered_map> #include <unordered_map>
#include <vector>
#ifndef FGSWIFTAIRCRAFTMANAGER_H #ifndef FGSWIFTAIRCRAFTMANAGER_H
#define FGSWIFTAIRCRAFTMANAGER_H #define FGSWIFTAIRCRAFTMANAGER_H
@ -34,20 +34,19 @@ class FGSwiftAircraftManager
public: public:
FGSwiftAircraftManager(); FGSwiftAircraftManager();
~FGSwiftAircraftManager(); ~FGSwiftAircraftManager();
bool addPlane(const std::string& callsign, const std::string& modelString); bool addPlane(const std::string& callsign, const std::string& modelString);
void updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<double> groundspeeds, std::vector<bool> onGrounds); void updatePlanes(const std::vector<std::string>& callsigns, const std::vector<SGGeod>& positions, const std::vector<SGVec3d>& orientations, const std::vector<double>& groundspeeds, const std::vector<bool>& onGrounds);
void getRemoteAircraftData(std::vector<std::string>& callsigns, std::vector<double>& latitudesDeg, std::vector<double>& longitudesDeg, void getRemoteAircraftData(std::vector<std::string>& callsigns, std::vector<double>& latitudesDeg, std::vector<double>& longitudesDeg,
std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const; std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const;
void removePlane(const std::string& callsign); void removePlane(const std::string& callsign);
void removeAllPlanes(); void removeAllPlanes();
void setPlanesTransponders(const std::vector<AircraftTransponder>& transponders); void setPlanesTransponders(const std::vector<AircraftTransponder>& transponders);
double getElevationAtPosition(const std::string &callsign, const SGGeod& pos) const; double getElevationAtPosition(const std::string& callsign, const SGGeod& pos) const;
bool isInitialized() const; bool isInitialized() const;
void setPlanesSurfaces(const std::vector<AircraftSurfaces>& surfaces); void setPlanesSurfaces(const std::vector<AircraftSurfaces>& surfaces);
private: private:
std::unordered_map<std::string, FGAISwiftAircraftPtr> aircraftByCallsign; std::unordered_map<std::string, FGAISwiftAircraftPtr> aircraftByCallsign;
bool m_initialized = false; bool m_initialized = false;
}; };
#endif #endif

View file

@ -23,42 +23,42 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <functional> #include <functional>
namespace FGSwiftBus namespace FGSwiftBus {
//! \cond PRIVATE
template <typename T>
class DBusAsyncCallbacks
{ {
//! \cond PRIVATE public:
template <typename T> DBusAsyncCallbacks() = default;
class DBusAsyncCallbacks DBusAsyncCallbacks(const std::function<dbus_bool_t(T*)>& add,
const std::function<void(T*)>& remove,
const std::function<void(T*)>& toggled)
: m_addHandler(add), m_removeHandler(remove), m_toggledHandler(toggled)
{ {
public: }
DBusAsyncCallbacks() = default;
DBusAsyncCallbacks(const std::function<dbus_bool_t(T *)> &add,
const std::function<void(T *)> &remove,
const std::function<void(T *)> &toggled)
: m_addHandler(add), m_removeHandler(remove), m_toggledHandler(toggled)
{ }
static dbus_bool_t add(T *watch, void *refcon) static dbus_bool_t add(T* watch, void* refcon)
{ {
return static_cast<DBusAsyncCallbacks *>(refcon)->m_addHandler(watch); return static_cast<DBusAsyncCallbacks*>(refcon)->m_addHandler(watch);
} }
static void remove(T *watch, void *refcon) static void remove(T* watch, void* refcon)
{ {
return static_cast<DBusAsyncCallbacks *>(refcon)->m_removeHandler(watch); return static_cast<DBusAsyncCallbacks*>(refcon)->m_removeHandler(watch);
} }
static void toggled(T *watch, void *refcon) static void toggled(T* watch, void* refcon)
{ {
return static_cast<DBusAsyncCallbacks *>(refcon)->m_toggledHandler(watch); return static_cast<DBusAsyncCallbacks*>(refcon)->m_toggledHandler(watch);
} }
private: private:
std::function<dbus_bool_t(T *)> m_addHandler; std::function<dbus_bool_t(T*)> m_addHandler;
std::function<void(T *)> m_removeHandler; std::function<void(T*)> m_removeHandler;
std::function<void(T *)> m_toggledHandler; std::function<void(T*)> m_toggledHandler;
}; };
//! \endcond //! \endcond
} } // namespace FGSwiftBus
#endif // guard #endif // guard

View file

@ -1,5 +1,3 @@
#include <utility>
// dbusconnection.cpp // dbusconnection.cpp
// //
// Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/) // Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/)
@ -26,170 +24,164 @@
#include <cassert> #include <cassert>
#include <memory> #include <memory>
namespace FGSwiftBus namespace FGSwiftBus {
CDBusConnection::CDBusConnection()
{ {
dbus_threads_init_default();
CDBusConnection::CDBusConnection()
{
dbus_threads_init_default();
}
CDBusConnection::CDBusConnection(DBusConnection *connection)
{
m_connection.reset(connection);
dbus_connection_ref(connection);
// Don't exit application, if the connection is disconnected
dbus_connection_set_exit_on_disconnect(connection, false);
dbus_connection_add_filter(connection, filterDisconnectedFunction, this, nullptr);
}
CDBusConnection::~CDBusConnection()
{
close();
if (m_connection) { dispatch(); } // dispatch is virtual, but safe to call in dtor, as it's declared final
if (m_dispatcher) { m_dispatcher->remove(this); }
}
bool CDBusConnection::connect(BusType type)
{
assert(type == SessionBus);
DBusError error;
dbus_error_init(&error);
DBusBusType dbusBusType;
switch (type)
{
case SessionBus: dbusBusType = DBUS_BUS_SESSION; break;
}
m_connection.reset(dbus_bus_get_private(dbusBusType, &error));
if (dbus_error_is_set(&error))
{
m_lastError = CDBusError(&error);
return false;
}
// Don't exit application, if the connection is disconnected
dbus_connection_set_exit_on_disconnect(m_connection.get(), false);
return true;
}
void CDBusConnection::setDispatcher(CDBusDispatcher *dispatcher)
{
assert(dispatcher);
m_dispatcher = dispatcher;
m_dispatcher->add(this);
dbus_connection_set_watch_functions(
m_connection.get(),
dispatcher->m_watchCallbacks.add,
dispatcher->m_watchCallbacks.remove,
dispatcher->m_watchCallbacks.toggled,
&dispatcher->m_watchCallbacks, nullptr);
dbus_connection_set_timeout_functions(
m_connection.get(),
dispatcher->m_timeoutCallbacks.add,
dispatcher->m_timeoutCallbacks.remove,
dispatcher->m_timeoutCallbacks.toggled,
&dispatcher->m_timeoutCallbacks, nullptr);
}
void CDBusConnection::requestName(const std::string &name)
{
DBusError error;
dbus_error_init(&error);
dbus_bus_request_name(m_connection.get(), name.c_str(), 0, &error);
}
bool CDBusConnection::isConnected() const
{
return m_connection && dbus_connection_get_is_connected(m_connection.get());
}
void CDBusConnection::registerDisconnectedCallback(CDBusObject *obj, DisconnectedCallback func)
{
m_disconnectedCallbacks[obj] = func;
}
void CDBusConnection::unregisterDisconnectedCallback(CDBusObject *obj)
{
auto it = m_disconnectedCallbacks.find(obj);
if (it == m_disconnectedCallbacks.end()) { return; }
m_disconnectedCallbacks.erase(it);
}
void CDBusConnection::registerObjectPath(CDBusObject *object, const std::string &interfaceName, const std::string &objectPath, const DBusObjectPathVTable &dbusObjectPathVTable)
{
(void) interfaceName;
if (!m_connection) { return; }
dbus_connection_try_register_object_path(m_connection.get(), objectPath.c_str(), &dbusObjectPathVTable, object, nullptr);
}
void CDBusConnection::sendMessage(const CDBusMessage &message)
{
if (!isConnected()) { return; }
dbus_uint32_t serial = message.getSerial();
dbus_connection_send(m_connection.get(), message.m_message, &serial);
}
void CDBusConnection::close()
{
if (m_connection) { dbus_connection_close(m_connection.get()); }
}
void CDBusConnection::dispatch()
{
dbus_connection_ref(m_connection.get());
if (dbus_connection_get_dispatch_status(m_connection.get()) == DBUS_DISPATCH_DATA_REMAINS)
{
while (dbus_connection_dispatch(m_connection.get()) == DBUS_DISPATCH_DATA_REMAINS);
}
dbus_connection_unref(m_connection.get());
}
void CDBusConnection::setDispatchStatus(DBusConnection *connection, DBusDispatchStatus status)
{
if (dbus_connection_get_is_connected(connection) == FALSE) { return; }
switch (status)
{
case DBUS_DISPATCH_DATA_REMAINS:
//m_dispatcher->add(this);
break;
case DBUS_DISPATCH_COMPLETE:
case DBUS_DISPATCH_NEED_MEMORY:
break;
}
}
void CDBusConnection::setDispatchStatus(DBusConnection *connection, DBusDispatchStatus status, void *data)
{
auto *obj = static_cast<CDBusConnection *>(data);
obj->setDispatchStatus(connection, status);
}
DBusHandlerResult CDBusConnection::filterDisconnectedFunction(DBusConnection *connection, DBusMessage *message, void *data)
{
(void)connection; // unused
auto *obj = static_cast<CDBusConnection *>(data);
DBusError err;
dbus_error_init(&err);
if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected"))
{
for (auto it = obj->m_disconnectedCallbacks.begin(); it != obj->m_disconnectedCallbacks.end(); ++it)
{
it->second();
}
return DBUS_HANDLER_RESULT_HANDLED;
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
} }
CDBusConnection::CDBusConnection(DBusConnection* connection)
{
m_connection.reset(connection);
dbus_connection_ref(connection);
// Don't exit application, if the connection is disconnected
dbus_connection_set_exit_on_disconnect(connection, false);
dbus_connection_add_filter(connection, filterDisconnectedFunction, this, nullptr);
}
CDBusConnection::~CDBusConnection()
{
close();
if (m_connection) { dispatch(); } // dispatch is virtual, but safe to call in dtor, as it's declared final
if (m_dispatcher) { m_dispatcher->remove(this); }
}
bool CDBusConnection::connect(BusType type)
{
assert(type == SessionBus);
DBusError error;
dbus_error_init(&error);
DBusBusType dbusBusType;
switch (type) {
case SessionBus: dbusBusType = DBUS_BUS_SESSION; break;
}
m_connection.reset(dbus_bus_get_private(dbusBusType, &error));
if (dbus_error_is_set(&error)) {
m_lastError = CDBusError(&error);
return false;
}
// Don't exit application, if the connection is disconnected
dbus_connection_set_exit_on_disconnect(m_connection.get(), false);
return true;
}
void CDBusConnection::setDispatcher(CDBusDispatcher* dispatcher)
{
assert(dispatcher);
m_dispatcher = dispatcher;
m_dispatcher->add(this);
dbus_connection_set_watch_functions(
m_connection.get(),
dispatcher->m_watchCallbacks.add,
dispatcher->m_watchCallbacks.remove,
dispatcher->m_watchCallbacks.toggled,
&dispatcher->m_watchCallbacks, nullptr);
dbus_connection_set_timeout_functions(
m_connection.get(),
dispatcher->m_timeoutCallbacks.add,
dispatcher->m_timeoutCallbacks.remove,
dispatcher->m_timeoutCallbacks.toggled,
&dispatcher->m_timeoutCallbacks, nullptr);
}
void CDBusConnection::requestName(const std::string& name)
{
DBusError error;
dbus_error_init(&error);
dbus_bus_request_name(m_connection.get(), name.c_str(), 0, &error);
}
bool CDBusConnection::isConnected() const
{
return m_connection && dbus_connection_get_is_connected(m_connection.get());
}
void CDBusConnection::registerDisconnectedCallback(CDBusObject* obj, DisconnectedCallback func)
{
m_disconnectedCallbacks[obj] = func;
}
void CDBusConnection::unregisterDisconnectedCallback(CDBusObject* obj)
{
auto it = m_disconnectedCallbacks.find(obj);
if (it == m_disconnectedCallbacks.end()) { return; }
m_disconnectedCallbacks.erase(it);
}
void CDBusConnection::registerObjectPath(CDBusObject* object, const std::string& interfaceName, const std::string& objectPath, const DBusObjectPathVTable& dbusObjectPathVTable)
{
(void)interfaceName;
if (!m_connection) { return; }
dbus_connection_try_register_object_path(m_connection.get(), objectPath.c_str(), &dbusObjectPathVTable, object, nullptr);
}
void CDBusConnection::sendMessage(const CDBusMessage& message)
{
if (!isConnected()) { return; }
dbus_uint32_t serial = message.getSerial();
dbus_connection_send(m_connection.get(), message.m_message, &serial);
}
void CDBusConnection::close()
{
if (m_connection) { dbus_connection_close(m_connection.get()); }
}
void CDBusConnection::dispatch()
{
dbus_connection_ref(m_connection.get());
if (dbus_connection_get_dispatch_status(m_connection.get()) == DBUS_DISPATCH_DATA_REMAINS) {
while (dbus_connection_dispatch(m_connection.get()) == DBUS_DISPATCH_DATA_REMAINS)
;
}
dbus_connection_unref(m_connection.get());
}
void CDBusConnection::setDispatchStatus(DBusConnection* connection, DBusDispatchStatus status)
{
if (dbus_connection_get_is_connected(connection) == FALSE) { return; }
switch (status) {
case DBUS_DISPATCH_DATA_REMAINS:
//m_dispatcher->add(this);
break;
case DBUS_DISPATCH_COMPLETE:
case DBUS_DISPATCH_NEED_MEMORY:
break;
}
}
void CDBusConnection::setDispatchStatus(DBusConnection* connection, DBusDispatchStatus status, void* data)
{
auto* obj = static_cast<CDBusConnection*>(data);
obj->setDispatchStatus(connection, status);
}
DBusHandlerResult CDBusConnection::filterDisconnectedFunction(DBusConnection* connection, DBusMessage* message, void* data)
{
(void)connection; // unused
auto* obj = static_cast<CDBusConnection*>(data);
DBusError err;
dbus_error_init(&err);
if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
for (auto it = obj->m_disconnectedCallbacks.begin(); it != obj->m_disconnectedCallbacks.end(); ++it) {
it->second();
}
return DBUS_HANDLER_RESULT_HANDLED;
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
} // namespace FGSwiftBus

View file

@ -20,100 +20,98 @@
#ifndef BLACKSIM_FGSWIFTBUS_DBUSCONNECTION_H #ifndef BLACKSIM_FGSWIFTBUS_DBUSCONNECTION_H
#define BLACKSIM_FGSWIFTBUS_DBUSCONNECTION_H #define BLACKSIM_FGSWIFTBUS_DBUSCONNECTION_H
#include "dbusmessage.h"
#include "dbuserror.h"
#include "dbuscallbacks.h" #include "dbuscallbacks.h"
#include "dbusdispatcher.h" #include "dbusdispatcher.h"
#include "dbuserror.h"
#include "dbusmessage.h"
#include <event2/event.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <event2/event.h>
#include <memory>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <memory>
namespace FGSwiftBus namespace FGSwiftBus {
class CDBusObject;
//! DBus connection
class CDBusConnection : public IDispatchable
{ {
public:
//! Bus type
enum BusType { SessionBus };
class CDBusObject; //! Disconnect Callback
using DisconnectedCallback = std::function<void()>;
//! DBus connection //! Default constructor
class CDBusConnection : public IDispatchable CDBusConnection();
{
public:
//! Bus type
enum BusType { SessionBus };
//! Disconnect Callback //! Constructor
using DisconnectedCallback = std::function<void()>; CDBusConnection(DBusConnection* connection);
//! Default constructor //! Destructor
CDBusConnection(); ~CDBusConnection() override;
//! Constructor // The ones below are not implemented yet.
CDBusConnection(DBusConnection *connection); // If you need them, make sure that connection reference count is correct
CDBusConnection(const CDBusConnection&) = delete;
CDBusConnection& operator=(const CDBusConnection&) = delete;
//! Destructor //! Connect to bus
~CDBusConnection() override; bool connect(BusType type);
// The ones below are not implemented yet. //! Set dispatcher
// If you need them, make sure that connection reference count is correct void setDispatcher(CDBusDispatcher* dispatcher);
CDBusConnection(const CDBusConnection &) = delete;
CDBusConnection &operator=(const CDBusConnection &) = delete;
//! Connect to bus //! Request name to the bus
bool connect(BusType type); void requestName(const std::string& name);
//! Set dispatcher //! Is connected?
void setDispatcher(CDBusDispatcher *dispatcher); bool isConnected() const;
//! Request name to the bus //! Register a disconnected callback
void requestName(const std::string &name); void registerDisconnectedCallback(CDBusObject* obj, DisconnectedCallback func);
//! Is connected? //! Register a disconnected callback
bool isConnected() const; void unregisterDisconnectedCallback(CDBusObject* obj);
//! Register a disconnected callback //! Register DBus object with interfaceName and objectPath.
void registerDisconnectedCallback(CDBusObject *obj, DisconnectedCallback func); //! \param object
//! \param interfaceName
//! \param objectPath
//! \param dbusObjectPathVTable Virtual table handling DBus messages
void registerObjectPath(CDBusObject* object, const std::string& interfaceName, const std::string& objectPath, const DBusObjectPathVTable& dbusObjectPathVTable);
//! Register a disconnected callback //! Send message to bus
void unregisterDisconnectedCallback(CDBusObject *obj); void sendMessage(const CDBusMessage& message);
//! Register DBus object with interfaceName and objectPath. //! Close connection
//! \param object void close();
//! \param interfaceName
//! \param objectPath
//! \param dbusObjectPathVTable Virtual table handling DBus messages
void registerObjectPath(CDBusObject *object, const std::string &interfaceName, const std::string &objectPath, const DBusObjectPathVTable &dbusObjectPathVTable);
//! Send message to bus //! Get the last error
void sendMessage(const CDBusMessage &message); CDBusError lastError() const { return m_lastError; }
//! Close connection protected:
void close(); // cppcheck-suppress virtualCallInConstructor
virtual void dispatch() override final;
//! Get the last error private:
CDBusError lastError() const { return m_lastError; } void setDispatchStatus(DBusConnection* connection, DBusDispatchStatus status);
static void setDispatchStatus(DBusConnection* connection, DBusDispatchStatus status, void* data);
static DBusHandlerResult filterDisconnectedFunction(DBusConnection* connection, DBusMessage* message, void* data);
protected: struct DBusConnectionDeleter {
// cppcheck-suppress virtualCallInConstructor void operator()(DBusConnection* obj) const { dbus_connection_unref(obj); }
virtual void dispatch() override final;
private:
void setDispatchStatus(DBusConnection *connection, DBusDispatchStatus status);
static void setDispatchStatus(DBusConnection *connection, DBusDispatchStatus status, void *data);
static DBusHandlerResult filterDisconnectedFunction(DBusConnection *connection, DBusMessage *message, void *data);
struct DBusConnectionDeleter
{
void operator()(DBusConnection *obj) const { dbus_connection_unref(obj); }
};
CDBusDispatcher *m_dispatcher = nullptr;
std::unique_ptr<DBusConnection, DBusConnectionDeleter> m_connection;
CDBusError m_lastError;
std::unordered_map<CDBusObject *, DisconnectedCallback> m_disconnectedCallbacks;
}; };
} CDBusDispatcher* m_dispatcher = nullptr;
std::unique_ptr<DBusConnection, DBusConnectionDeleter> m_connection;
CDBusError m_lastError;
std::unordered_map<CDBusObject*, DisconnectedCallback> m_disconnectedCallbacks;
};
} // namespace FGSwiftBus
#endif // guard #endif // guard

View file

@ -24,231 +24,232 @@
namespace { // anonymosu namespace namespace { // anonymosu namespace
template <typename T, typename... Args> template <typename T, typename... Args>
std::unique_ptr<T> our_make_unique(Args&&... args) { std::unique_ptr<T> our_make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
} }
} // end of anonymous namespace } // end of anonymous namespace
namespace FGSwiftBus namespace FGSwiftBus {
//! Functor struct deleteing an event
struct EventDeleter {
//! Delete functor
void operator()(event* obj) const
{
event_del(obj);
event_free(obj);
}
};
//! DBus watch handler
class WatchHandler
{ {
public:
//! Functor struct deleteing an event //! Constructor
struct EventDeleter WatchHandler(event_base* base, DBusWatch* watch)
: m_base(base), m_watch(watch)
{ {
//! Delete functor const unsigned int flags = dbus_watch_get_flags(watch);
void operator()(event *obj) const short monitoredEvents = EV_PERSIST;
{
event_del(obj);
event_free(obj);
}
};
//! DBus watch handler if (flags & DBUS_WATCH_READABLE) { monitoredEvents |= EV_READ; }
class WatchHandler if (flags & DBUS_WATCH_WRITABLE) { monitoredEvents |= EV_WRITE; }
{
public:
//! Constructor
WatchHandler(event_base *base, DBusWatch *watch)
: m_base(base), m_watch(watch)
{
const unsigned int flags = dbus_watch_get_flags(watch);
short monitoredEvents = EV_PERSIST;
if (flags & DBUS_WATCH_READABLE) { monitoredEvents |= EV_READ; } const int fd = dbus_watch_get_unix_fd(watch);
if (flags & DBUS_WATCH_WRITABLE) { monitoredEvents |= EV_WRITE; } m_event.reset(event_new(m_base, fd, monitoredEvents, callback, this));
event_add(m_event.get(), nullptr);
const int fd = dbus_watch_get_unix_fd(watch);
m_event.reset(event_new(m_base, fd, monitoredEvents, callback, this));
event_add(m_event.get(), nullptr);
}
//! Get DBus watch
DBusWatch *getWatch() { return m_watch; }
//! Get DBus watch
const DBusWatch *getWatch() const { return m_watch; }
private:
//! Event callback
static void callback(evutil_socket_t fd, short event, void *data)
{
(void) fd; // Not really unused, but GCC/Clang still complain about it.
auto *watchHandler = static_cast<WatchHandler *>(data);
unsigned int flags = 0;
if (event & EV_READ) { flags |= DBUS_WATCH_READABLE; }
if (event & EV_WRITE) { flags |= DBUS_WATCH_WRITABLE; }
dbus_watch_handle(watchHandler->m_watch, flags);
}
event_base *m_base = nullptr;
std::unique_ptr<event, EventDeleter> m_event;
DBusWatch *m_watch = nullptr;
};
//! DBus timeout handler
class TimeoutHandler
{
public:
//! Constructor
TimeoutHandler(event_base *base, DBusTimeout *timeout)
: m_base(base), m_timeout(timeout)
{
timeval timer;
const int interval = dbus_timeout_get_interval(timeout);
timer.tv_sec = interval / 1000;
timer.tv_usec = (interval % 1000) * 1000;
m_event.reset(evtimer_new(m_base, callback, this));
evtimer_add(m_event.get(), &timer);
}
//! Get DBus timeout
const DBusTimeout *getTimeout() const { return m_timeout; }
private:
//! Event callback
static void callback(evutil_socket_t fd, short event, void *data)
{
(void) fd; // unused
(void) event; // unused
auto *timeoutHandler = static_cast<TimeoutHandler *>(data);
dbus_timeout_handle(timeoutHandler->m_timeout);
}
event_base *m_base = nullptr;
std::unique_ptr<event, EventDeleter> m_event;
DBusTimeout *m_timeout = nullptr;
};
//! Generic Timer
class Timer
{
public:
Timer() = default;
//! Constructor
Timer(event_base *base, const timeval &timeout, const std::function<void()> &func)
: m_base(base), m_func(func)
{
m_event.reset(evtimer_new(m_base, callback, this));
evtimer_add(m_event.get(), &timeout);
}
private:
//! Event callback
static void callback(evutil_socket_t fd, short event, void *data)
{
(void) fd; // unused
(void) event; // unused
auto *timer = static_cast<Timer *>(data);
timer->m_func();
delete timer;
}
event_base *m_base = nullptr;
std::unique_ptr<event, EventDeleter> m_event;
std::function<void()> m_func;
};
CDBusDispatcher::CDBusDispatcher() :
m_eventBase(event_base_new())
{
using namespace std::placeholders;
m_watchCallbacks = WatchCallbacks(std::bind(&CDBusDispatcher::dbusAddWatch, this, _1),
std::bind(&CDBusDispatcher::dbusRemoveWatch, this, _1),
std::bind(&CDBusDispatcher::dbusWatchToggled, this, _1));
m_timeoutCallbacks = TimeoutCallbacks(std::bind(&CDBusDispatcher::dbusAddTimeout, this, _1),
std::bind(&CDBusDispatcher::dbusRemoveTimeout, this, _1),
std::bind(&CDBusDispatcher::dbusTimeoutToggled, this, _1));
} }
CDBusDispatcher::~CDBusDispatcher() //! Get DBus watch
DBusWatch* getWatch() { return m_watch; }
//! Get DBus watch
const DBusWatch* getWatch() const { return m_watch; }
private:
//! Event callback
static void callback(evutil_socket_t fd, short event, void* data)
{ {
(void)fd; // Not really unused, but GCC/Clang still complain about it.
auto* watchHandler = static_cast<WatchHandler*>(data);
unsigned int flags = 0;
if (event & EV_READ) { flags |= DBUS_WATCH_READABLE; }
if (event & EV_WRITE) { flags |= DBUS_WATCH_WRITABLE; }
dbus_watch_handle(watchHandler->m_watch, flags);
} }
void CDBusDispatcher::add(IDispatchable *dispatchable) event_base* m_base = nullptr;
std::unique_ptr<event, EventDeleter> m_event;
DBusWatch* m_watch = nullptr;
};
//! DBus timeout handler
class TimeoutHandler
{
public:
//! Constructor
TimeoutHandler(event_base* base, DBusTimeout* timeout)
: m_base(base), m_timeout(timeout)
{ {
m_dispatchList.push_back(dispatchable); timeval timer;
const int interval = dbus_timeout_get_interval(timeout);
timer.tv_sec = interval / 1000;
timer.tv_usec = (interval % 1000) * 1000;
m_event.reset(evtimer_new(m_base, callback, this));
evtimer_add(m_event.get(), &timer);
} }
void CDBusDispatcher::remove(IDispatchable *dispatchable) //! Get DBus timeout
const DBusTimeout* getTimeout() const { return m_timeout; }
private:
//! Event callback
static void callback(evutil_socket_t fd, short event, void* data)
{ {
auto it = std::find(m_dispatchList.begin(), m_dispatchList.end(), dispatchable); (void)fd; // unused
if (it != m_dispatchList.end()) { m_dispatchList.erase(it); } (void)event; // unused
auto* timeoutHandler = static_cast<TimeoutHandler*>(data);
dbus_timeout_handle(timeoutHandler->m_timeout);
} }
void CDBusDispatcher::waitAndRun() event_base* m_base = nullptr;
std::unique_ptr<event, EventDeleter> m_event;
DBusTimeout* m_timeout = nullptr;
};
//! Generic Timer
class Timer
{
public:
Timer() = default;
//! Constructor
Timer(event_base* base, const timeval& timeout, const std::function<void()>& func)
: m_base(base), m_func(func)
{ {
if (!m_eventBase) { return; } m_event.reset(evtimer_new(m_base, callback, this));
event_base_dispatch(m_eventBase.get()); evtimer_add(m_event.get(), &timeout);
} }
void CDBusDispatcher::runOnce() private:
//! Event callback
static void callback(evutil_socket_t fd, short event, void* data)
{ {
if (!m_eventBase) { return; } (void)fd; // unused
event_base_loop(m_eventBase.get(), EVLOOP_NONBLOCK); (void)event; // unused
dispatch(); auto* timer = static_cast<Timer*>(data);
timer->m_func();
delete timer;
} }
void CDBusDispatcher::dispatch() event_base* m_base = nullptr;
{ std::unique_ptr<event, EventDeleter> m_event;
if (m_dispatchList.empty()) { return; } std::function<void()> m_func;
};
for (IDispatchable *dispatchable : m_dispatchList) CDBusDispatcher::CDBusDispatcher() : m_eventBase(event_base_new())
{ {
dispatchable->dispatch(); using namespace std::placeholders;
} m_watchCallbacks = WatchCallbacks(std::bind(&CDBusDispatcher::dbusAddWatch, this, _1),
} std::bind(&CDBusDispatcher::dbusRemoveWatch, this, _1),
std::bind(&CDBusDispatcher::dbusWatchToggled, this, _1));
dbus_bool_t CDBusDispatcher::dbusAddWatch(DBusWatch *watch)
{
if (dbus_watch_get_enabled(watch) == FALSE) { return true; }
int fd = dbus_watch_get_unix_fd(watch);
m_watchers.emplace(fd, our_make_unique<WatchHandler>(m_eventBase.get(), watch));
return true;
}
void CDBusDispatcher::dbusRemoveWatch(DBusWatch *watch)
{
for (auto it = m_watchers.begin(); it != m_watchers.end();)
{
if (it->second->getWatch() == watch) { it = m_watchers.erase(it); }
else { ++it; }
}
}
void CDBusDispatcher::dbusWatchToggled(DBusWatch *watch)
{
if (dbus_watch_get_enabled(watch) == TRUE) { dbusAddWatch(watch); }
else { dbusRemoveWatch(watch); }
}
dbus_bool_t CDBusDispatcher::dbusAddTimeout(DBusTimeout *timeout)
{
if (dbus_timeout_get_enabled(timeout) == FALSE) { return TRUE; }
m_timeouts.emplace_back(new TimeoutHandler(m_eventBase.get(), timeout));
return true;
}
void CDBusDispatcher::dbusRemoveTimeout(DBusTimeout *timeout)
{
auto predicate = [timeout](const std::unique_ptr<TimeoutHandler> &ptr)
{
return ptr->getTimeout() == timeout;
};
m_timeouts.erase(std::remove_if(m_timeouts.begin(), m_timeouts.end(), predicate), m_timeouts.end());
}
void CDBusDispatcher::dbusTimeoutToggled(DBusTimeout *timeout)
{
if (dbus_timeout_get_enabled(timeout) == TRUE)
dbusAddTimeout(timeout);
else
dbusRemoveTimeout(timeout);
}
m_timeoutCallbacks = TimeoutCallbacks(std::bind(&CDBusDispatcher::dbusAddTimeout, this, _1),
std::bind(&CDBusDispatcher::dbusRemoveTimeout, this, _1),
std::bind(&CDBusDispatcher::dbusTimeoutToggled, this, _1));
} }
CDBusDispatcher::~CDBusDispatcher()
{
}
void CDBusDispatcher::add(IDispatchable* dispatchable)
{
m_dispatchList.push_back(dispatchable);
}
void CDBusDispatcher::remove(IDispatchable* dispatchable)
{
auto it = std::find(m_dispatchList.begin(), m_dispatchList.end(), dispatchable);
if (it != m_dispatchList.end()) { m_dispatchList.erase(it); }
}
void CDBusDispatcher::waitAndRun()
{
if (!m_eventBase) { return; }
event_base_dispatch(m_eventBase.get());
}
void CDBusDispatcher::runOnce()
{
if (!m_eventBase) { return; }
event_base_loop(m_eventBase.get(), EVLOOP_NONBLOCK);
dispatch();
}
void CDBusDispatcher::dispatch()
{
if (m_dispatchList.empty()) { return; }
for (IDispatchable* dispatchable : m_dispatchList) {
dispatchable->dispatch();
}
}
dbus_bool_t CDBusDispatcher::dbusAddWatch(DBusWatch* watch)
{
if (dbus_watch_get_enabled(watch) == FALSE) { return true; }
int fd = dbus_watch_get_unix_fd(watch);
m_watchers.emplace(fd, our_make_unique<WatchHandler>(m_eventBase.get(), watch));
return true;
}
void CDBusDispatcher::dbusRemoveWatch(DBusWatch* watch)
{
for (auto it = m_watchers.begin(); it != m_watchers.end();) {
if (it->second->getWatch() == watch) {
it = m_watchers.erase(it);
} else {
++it;
}
}
}
void CDBusDispatcher::dbusWatchToggled(DBusWatch* watch)
{
if (dbus_watch_get_enabled(watch) == TRUE) {
dbusAddWatch(watch);
} else {
dbusRemoveWatch(watch);
}
}
dbus_bool_t CDBusDispatcher::dbusAddTimeout(DBusTimeout* timeout)
{
if (dbus_timeout_get_enabled(timeout) == FALSE) { return TRUE; }
m_timeouts.emplace_back(new TimeoutHandler(m_eventBase.get(), timeout));
return true;
}
void CDBusDispatcher::dbusRemoveTimeout(DBusTimeout* timeout)
{
auto predicate = [timeout](const std::unique_ptr<TimeoutHandler>& ptr) {
return ptr->getTimeout() == timeout;
};
m_timeouts.erase(std::remove_if(m_timeouts.begin(), m_timeouts.end(), predicate), m_timeouts.end());
}
void CDBusDispatcher::dbusTimeoutToggled(DBusTimeout* timeout)
{
if (dbus_timeout_get_enabled(timeout) == TRUE)
dbusAddTimeout(timeout);
else
dbusRemoveTimeout(timeout);
}
} // namespace FGSwiftBus

View file

@ -22,93 +22,91 @@
#include "dbuscallbacks.h" #include "dbuscallbacks.h"
#include <event2/event.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <event2/event.h>
#include <memory>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <memory>
namespace FGSwiftBus namespace FGSwiftBus {
class WatchHandler;
class TimeoutHandler;
class CDBusConnection;
class CDBusDispatcher;
//! Dispatchable Interface
class IDispatchable
{ {
public:
//! Default constructor
IDispatchable() = default;
class WatchHandler; //! Default destructor
class TimeoutHandler; virtual ~IDispatchable() = default;
class CDBusConnection;
class CDBusDispatcher;
//! Dispatchable Interface //! Dispatch execution method
class IDispatchable virtual void dispatch() = 0;
{
public:
//! Default constructor
IDispatchable() = default;
//! Default destructor private:
virtual ~IDispatchable() = default; friend CDBusDispatcher;
};
//! Dispatch execution method //! DBus Dispatcher
virtual void dispatch() = 0; class CDBusDispatcher
{
public:
//! Constructor
CDBusDispatcher();
private: //! Destructor
friend CDBusDispatcher; virtual ~CDBusDispatcher();
//! Add dispatchable object
void add(IDispatchable* dispatchable);
//! Remove dispatchable object
void remove(IDispatchable* dispatchable);
//! Waits for events to be dispatched and handles them
void waitAndRun();
//! Dispatches ready handlers and returns without waiting
void runOnce();
private:
friend class WatchHandler;
friend class TimeoutHandler;
friend class Timer;
friend class CDBusConnection;
friend class CDBusServer;
struct EventBaseDeleter {
void operator()(event_base* obj) const { event_base_free(obj); }
}; };
//! DBus Dispatcher using WatchCallbacks = DBusAsyncCallbacks<DBusWatch>;
class CDBusDispatcher using TimeoutCallbacks = DBusAsyncCallbacks<DBusTimeout>;
{
public:
//! Constructor
CDBusDispatcher();
//! Destructor void dispatch();
virtual ~CDBusDispatcher();
//! Add dispatchable object dbus_bool_t dbusAddWatch(DBusWatch* watch);
void add(IDispatchable *dispatchable); void dbusRemoveWatch(DBusWatch* watch);
void dbusWatchToggled(DBusWatch* watch);
//! Remove dispatchable object dbus_bool_t dbusAddTimeout(DBusTimeout* timeout);
void remove(IDispatchable *dispatchable); void dbusRemoveTimeout(DBusTimeout* timeout);
void dbusTimeoutToggled(DBusTimeout* timeout);
//! Waits for events to be dispatched and handles them WatchCallbacks m_watchCallbacks;
void waitAndRun(); TimeoutCallbacks m_timeoutCallbacks;
std::unordered_multimap<evutil_socket_t, std::unique_ptr<WatchHandler>> m_watchers;
std::vector<std::unique_ptr<TimeoutHandler>> m_timeouts;
std::unique_ptr<event_base, EventBaseDeleter> m_eventBase;
//! Dispatches ready handlers and returns without waiting std::vector<IDispatchable*> m_dispatchList;
void runOnce(); };
} // namespace FGSwiftBus
private:
friend class WatchHandler;
friend class TimeoutHandler;
friend class Timer;
friend class CDBusConnection;
friend class CDBusServer;
struct EventBaseDeleter
{
void operator()(event_base *obj) const { event_base_free(obj); }
};
using WatchCallbacks = DBusAsyncCallbacks<DBusWatch>;
using TimeoutCallbacks = DBusAsyncCallbacks<DBusTimeout>;
void dispatch();
dbus_bool_t dbusAddWatch(DBusWatch *watch);
void dbusRemoveWatch(DBusWatch *watch);
void dbusWatchToggled(DBusWatch *watch);
dbus_bool_t dbusAddTimeout(DBusTimeout *timeout);
void dbusRemoveTimeout(DBusTimeout *timeout);
void dbusTimeoutToggled(DBusTimeout *timeout);
WatchCallbacks m_watchCallbacks;
TimeoutCallbacks m_timeoutCallbacks;
std::unordered_multimap<evutil_socket_t, std::unique_ptr<WatchHandler>> m_watchers;
std::vector<std::unique_ptr<TimeoutHandler>> m_timeouts;
std::unique_ptr<event_base, EventBaseDeleter> m_eventBase;
std::vector<IDispatchable*> m_dispatchList;
};
}
#endif #endif

View file

@ -19,11 +19,11 @@
#include "dbuserror.h" #include "dbuserror.h"
namespace FGSwiftBus namespace FGSwiftBus {
CDBusError::CDBusError(const DBusError* error)
: m_name(error->name), m_message(error->message)
{ {
CDBusError::CDBusError(const DBusError *error)
: m_name(error->name), m_message(error->message)
{ }
} }
} // namespace FGSwiftBus

View file

@ -23,35 +23,33 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <string> #include <string>
namespace FGSwiftBus namespace FGSwiftBus {
//! DBus error
class CDBusError
{ {
public:
//! DBus error //! Error type
class CDBusError enum ErrorType {
{ NoError,
public: Other
//! Error type
enum ErrorType
{
NoError,
Other
};
//! Default constructur
CDBusError() = default;
//! Constructor
explicit CDBusError(const DBusError *error);
//! Get error type
ErrorType getType() const { return m_errorType; }
private:
ErrorType m_errorType = NoError;
std::string m_name;
std::string m_message;
}; };
} //! Default constructur
CDBusError() = default;
//! Constructor
explicit CDBusError(const DBusError* error);
//! Get error type
ErrorType getType() const { return m_errorType; }
private:
ErrorType m_errorType = NoError;
std::string m_name;
std::string m_message;
};
} // namespace FGSwiftBus
#endif // guard #endif // guard

View file

@ -19,245 +19,241 @@
#include "dbusmessage.h" #include "dbusmessage.h"
namespace FGSwiftBus namespace FGSwiftBus {
CDBusMessage::CDBusMessage(DBusMessage* message)
{ {
m_message = dbus_message_ref(message);
CDBusMessage::CDBusMessage(DBusMessage *message)
{
m_message = dbus_message_ref(message);
}
CDBusMessage::CDBusMessage(const CDBusMessage &other)
{
m_message = dbus_message_ref(other.m_message);
m_serial = other.m_serial;
}
CDBusMessage::CDBusMessage(DBusMessage *message, dbus_uint32_t serial)
{
m_message = dbus_message_ref(message);
m_serial = serial;
}
CDBusMessage::~CDBusMessage()
{
dbus_message_unref(m_message);
}
CDBusMessage &CDBusMessage::operator =(CDBusMessage other)
{
std::swap(m_serial, other.m_serial);
m_message = dbus_message_ref(other.m_message);
return *this;
}
bool CDBusMessage::isMethodCall() const
{
return dbus_message_get_type(m_message) == DBUS_MESSAGE_TYPE_METHOD_CALL;
}
bool CDBusMessage::wantsReply() const
{
return !dbus_message_get_no_reply(m_message);
}
std::string CDBusMessage::getSender() const
{
const char *sender = dbus_message_get_sender(m_message);
return sender ? std::string(sender) : std::string();
}
dbus_uint32_t CDBusMessage::getSerial() const
{
return dbus_message_get_serial(m_message);
}
std::string CDBusMessage::getInterfaceName() const
{
return dbus_message_get_interface(m_message);
}
std::string CDBusMessage::getObjectPath() const
{
return dbus_message_get_path(m_message);
}
std::string CDBusMessage::getMethodName() const
{
return dbus_message_get_member(m_message);
}
void CDBusMessage::beginArgumentWrite()
{
dbus_message_iter_init_append(m_message, &m_messageIterator);
}
void CDBusMessage::appendArgument(bool value)
{
dbus_bool_t boolean = value ? 1 : 0;
dbus_message_iter_append_basic(&m_messageIterator, DBUS_TYPE_BOOLEAN, &boolean);
}
void CDBusMessage::appendArgument(const char *value)
{
dbus_message_iter_append_basic(&m_messageIterator, DBUS_TYPE_STRING, &value);
}
void CDBusMessage::appendArgument(const std::string &value)
{
const char *ptr = value.c_str();
dbus_message_iter_append_basic(&m_messageIterator, DBUS_TYPE_STRING, &ptr);
}
void CDBusMessage::appendArgument(int value)
{
dbus_int32_t i = value;
dbus_message_iter_append_basic(&m_messageIterator, DBUS_TYPE_INT32, &i);
}
void CDBusMessage::appendArgument(double value)
{
dbus_message_iter_append_basic(&m_messageIterator, DBUS_TYPE_DOUBLE, &value);
}
void CDBusMessage::appendArgument(const std::vector<double> &array)
{
DBusMessageIter arrayIterator;
dbus_message_iter_open_container(&m_messageIterator, DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE_AS_STRING, &arrayIterator);
const double *ptr = array.data();
dbus_message_iter_append_fixed_array(&arrayIterator, DBUS_TYPE_DOUBLE, &ptr, static_cast<int>(array.size()));
dbus_message_iter_close_container(&m_messageIterator, &arrayIterator);
}
void CDBusMessage::appendArgument(const std::vector<std::string> &array)
{
DBusMessageIter arrayIterator;
dbus_message_iter_open_container(&m_messageIterator, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &arrayIterator);
for (const auto &i : array)
{
const char *ptr = i.c_str();
dbus_message_iter_append_basic(&arrayIterator, DBUS_TYPE_STRING, &ptr);
}
dbus_message_iter_close_container(&m_messageIterator, &arrayIterator);
}
void CDBusMessage::beginArgumentRead()
{
dbus_message_iter_init(m_message, &m_messageIterator);
}
void CDBusMessage::getArgument(int &value)
{
if (dbus_message_iter_get_arg_type(&m_messageIterator) != DBUS_TYPE_INT32) { return; }
dbus_int32_t i;
dbus_message_iter_get_basic(&m_messageIterator, &i);
value = i;
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(bool &value)
{
if (dbus_message_iter_get_arg_type(&m_messageIterator) != DBUS_TYPE_BOOLEAN) { return; }
dbus_bool_t v;
dbus_message_iter_get_basic(&m_messageIterator, &v);
if (v == TRUE) { value = true; }
else { value = false; }
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(double &value)
{
if (dbus_message_iter_get_arg_type(&m_messageIterator) != DBUS_TYPE_DOUBLE) { return; }
dbus_message_iter_get_basic(&m_messageIterator, &value);
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(std::string &value)
{
const char *str = nullptr;
if (dbus_message_iter_get_arg_type(&m_messageIterator) != DBUS_TYPE_STRING) { return; }
dbus_message_iter_get_basic(&m_messageIterator, &str);
dbus_message_iter_next(&m_messageIterator);
value = std::string(str);
}
void CDBusMessage::getArgument(std::vector<int> &value)
{
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do
{
if (dbus_message_iter_get_arg_type(&arrayIterator) != DBUS_TYPE_INT32) { return; }
dbus_int32_t i;
dbus_message_iter_get_basic(&arrayIterator, &i);
value.push_back(i);
}
while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(std::vector<bool> &value)
{
if (dbus_message_iter_get_arg_type(&m_messageIterator) != DBUS_TYPE_ARRAY) { return; }
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do
{
if (dbus_message_iter_get_arg_type(&arrayIterator) != DBUS_TYPE_BOOLEAN) { return; }
dbus_bool_t b;
dbus_message_iter_get_basic(&arrayIterator, &b);
if (b == TRUE) { value.push_back(true); }
else { value.push_back(false); }
}
while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(std::vector<double> &value)
{
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do
{
if (dbus_message_iter_get_arg_type(&arrayIterator) != DBUS_TYPE_DOUBLE) { return; }
double d;
dbus_message_iter_get_basic(&arrayIterator, &d);
value.push_back(d);
}
while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(std::vector<std::string> &value)
{
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do
{
if (dbus_message_iter_get_arg_type(&arrayIterator) != DBUS_TYPE_STRING) { return; }
const char *str = nullptr;
dbus_message_iter_get_basic(&arrayIterator, &str);
value.push_back(std::string(str));
}
while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
CDBusMessage CDBusMessage::createSignal(const std::string &path, const std::string &interfaceName, const std::string &signalName)
{
DBusMessage *signal = dbus_message_new_signal(path.c_str(), interfaceName.c_str(), signalName.c_str());
return CDBusMessage(signal);
}
CDBusMessage CDBusMessage::createReply(const std::string &destination, dbus_uint32_t serial)
{
DBusMessage *reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
dbus_message_set_no_reply(reply, TRUE);
if (! destination.empty()) { dbus_message_set_destination(reply, destination.c_str()); }
dbus_message_set_reply_serial(reply, serial);
CDBusMessage msg(reply);
dbus_message_unref(reply);
return msg;
}
} }
CDBusMessage::CDBusMessage(const CDBusMessage& other)
{
m_message = dbus_message_ref(other.m_message);
m_serial = other.m_serial;
}
CDBusMessage::CDBusMessage(DBusMessage* message, dbus_uint32_t serial)
{
m_message = dbus_message_ref(message);
m_serial = serial;
}
CDBusMessage::~CDBusMessage()
{
dbus_message_unref(m_message);
}
CDBusMessage& CDBusMessage::operator=(CDBusMessage other)
{
std::swap(m_serial, other.m_serial);
m_message = dbus_message_ref(other.m_message);
return *this;
}
bool CDBusMessage::isMethodCall() const
{
return dbus_message_get_type(m_message) == DBUS_MESSAGE_TYPE_METHOD_CALL;
}
bool CDBusMessage::wantsReply() const
{
return !dbus_message_get_no_reply(m_message);
}
std::string CDBusMessage::getSender() const
{
const char* sender = dbus_message_get_sender(m_message);
return sender ? std::string(sender) : std::string();
}
dbus_uint32_t CDBusMessage::getSerial() const
{
return dbus_message_get_serial(m_message);
}
std::string CDBusMessage::getInterfaceName() const
{
return dbus_message_get_interface(m_message);
}
std::string CDBusMessage::getObjectPath() const
{
return dbus_message_get_path(m_message);
}
std::string CDBusMessage::getMethodName() const
{
return dbus_message_get_member(m_message);
}
void CDBusMessage::beginArgumentWrite()
{
dbus_message_iter_init_append(m_message, &m_messageIterator);
}
void CDBusMessage::appendArgument(bool value)
{
dbus_bool_t boolean = value ? 1 : 0;
dbus_message_iter_append_basic(&m_messageIterator, DBUS_TYPE_BOOLEAN, &boolean);
}
void CDBusMessage::appendArgument(const char* value)
{
dbus_message_iter_append_basic(&m_messageIterator, DBUS_TYPE_STRING, &value);
}
void CDBusMessage::appendArgument(const std::string& value)
{
const char* ptr = value.c_str();
dbus_message_iter_append_basic(&m_messageIterator, DBUS_TYPE_STRING, &ptr);
}
void CDBusMessage::appendArgument(int value)
{
dbus_int32_t i = value;
dbus_message_iter_append_basic(&m_messageIterator, DBUS_TYPE_INT32, &i);
}
void CDBusMessage::appendArgument(double value)
{
dbus_message_iter_append_basic(&m_messageIterator, DBUS_TYPE_DOUBLE, &value);
}
void CDBusMessage::appendArgument(const std::vector<double>& array)
{
DBusMessageIter arrayIterator;
dbus_message_iter_open_container(&m_messageIterator, DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE_AS_STRING, &arrayIterator);
const double* ptr = array.data();
dbus_message_iter_append_fixed_array(&arrayIterator, DBUS_TYPE_DOUBLE, &ptr, static_cast<int>(array.size()));
dbus_message_iter_close_container(&m_messageIterator, &arrayIterator);
}
void CDBusMessage::appendArgument(const std::vector<std::string>& array)
{
DBusMessageIter arrayIterator;
dbus_message_iter_open_container(&m_messageIterator, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &arrayIterator);
for (const auto& i : array) {
const char* ptr = i.c_str();
dbus_message_iter_append_basic(&arrayIterator, DBUS_TYPE_STRING, &ptr);
}
dbus_message_iter_close_container(&m_messageIterator, &arrayIterator);
}
void CDBusMessage::beginArgumentRead()
{
dbus_message_iter_init(m_message, &m_messageIterator);
}
void CDBusMessage::getArgument(int& value)
{
if (dbus_message_iter_get_arg_type(&m_messageIterator) != DBUS_TYPE_INT32) { return; }
dbus_int32_t i;
dbus_message_iter_get_basic(&m_messageIterator, &i);
value = i;
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(bool& value)
{
if (dbus_message_iter_get_arg_type(&m_messageIterator) != DBUS_TYPE_BOOLEAN) { return; }
dbus_bool_t v;
dbus_message_iter_get_basic(&m_messageIterator, &v);
if (v == TRUE) {
value = true;
} else {
value = false;
}
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(double& value)
{
if (dbus_message_iter_get_arg_type(&m_messageIterator) != DBUS_TYPE_DOUBLE) { return; }
dbus_message_iter_get_basic(&m_messageIterator, &value);
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(std::string& value)
{
const char* str = nullptr;
if (dbus_message_iter_get_arg_type(&m_messageIterator) != DBUS_TYPE_STRING) { return; }
dbus_message_iter_get_basic(&m_messageIterator, &str);
dbus_message_iter_next(&m_messageIterator);
value = std::string(str);
}
void CDBusMessage::getArgument(std::vector<int>& value)
{
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do {
if (dbus_message_iter_get_arg_type(&arrayIterator) != DBUS_TYPE_INT32) { return; }
dbus_int32_t i;
dbus_message_iter_get_basic(&arrayIterator, &i);
value.push_back(i);
} while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(std::vector<bool>& value)
{
if (dbus_message_iter_get_arg_type(&m_messageIterator) != DBUS_TYPE_ARRAY) { return; }
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do {
if (dbus_message_iter_get_arg_type(&arrayIterator) != DBUS_TYPE_BOOLEAN) { return; }
dbus_bool_t b;
dbus_message_iter_get_basic(&arrayIterator, &b);
if (b == TRUE) {
value.push_back(true);
} else {
value.push_back(false);
}
} while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(std::vector<double>& value)
{
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do {
if (dbus_message_iter_get_arg_type(&arrayIterator) != DBUS_TYPE_DOUBLE) { return; }
double d;
dbus_message_iter_get_basic(&arrayIterator, &d);
value.push_back(d);
} while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
void CDBusMessage::getArgument(std::vector<std::string>& value)
{
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do {
if (dbus_message_iter_get_arg_type(&arrayIterator) != DBUS_TYPE_STRING) { return; }
const char* str = nullptr;
dbus_message_iter_get_basic(&arrayIterator, &str);
value.push_back(std::string(str));
} while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
CDBusMessage CDBusMessage::createSignal(const std::string& path, const std::string& interfaceName, const std::string& signalName)
{
DBusMessage* signal = dbus_message_new_signal(path.c_str(), interfaceName.c_str(), signalName.c_str());
return CDBusMessage(signal);
}
CDBusMessage CDBusMessage::createReply(const std::string& destination, dbus_uint32_t serial)
{
DBusMessage* reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
dbus_message_set_no_reply(reply, TRUE);
if (!destination.empty()) { dbus_message_set_destination(reply, destination.c_str()); }
dbus_message_set_reply_serial(reply, serial);
CDBusMessage msg(reply);
dbus_message_unref(reply);
return msg;
}
} // namespace FGSwiftBus

View file

@ -24,90 +24,89 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace FGSwiftBus namespace FGSwiftBus {
//! DBus Message
class CDBusMessage
{ {
public:
//! Constructor
//! @{
CDBusMessage(DBusMessage* message);
CDBusMessage(const CDBusMessage& other);
//! @}
//! DBus Message //! Destructor
class CDBusMessage ~CDBusMessage();
{
public:
//! Constructor
//! @{
CDBusMessage(DBusMessage *message);
CDBusMessage(const CDBusMessage &other);
//! @}
//! Destructor //! Assignment operator
~CDBusMessage(); CDBusMessage& operator=(CDBusMessage other);
//! Assignment operator //! Is this message a method call?
CDBusMessage &operator=(CDBusMessage other); bool isMethodCall() const;
//! Is this message a method call? //! Does this message want a reply?
bool isMethodCall() const; bool wantsReply() const;
//! Does this message want a reply? //! Get the message sender
bool wantsReply() const; std::string getSender() const;
//! Get the message sender //! Get the message serial. This is usally required for reply message.
std::string getSender() const; dbus_uint32_t getSerial() const;
//! Get the message serial. This is usally required for reply message. //! Get the called interface name
dbus_uint32_t getSerial() const; std::string getInterfaceName() const;
//! Get the called interface name //! Get the called object path
std::string getInterfaceName() const; std::string getObjectPath() const;
//! Get the called object path //! Get the called method name
std::string getObjectPath() const; std::string getMethodName() const;
//! Get the called method name //! Begin writing argument
std::string getMethodName() const; void beginArgumentWrite();
//! Begin writing argument //! Append argument. Make sure to call \sa beginArgumentWrite() before.
void beginArgumentWrite(); //! @{
void appendArgument(bool value);
void appendArgument(const char* value);
void appendArgument(const std::string& value);
void appendArgument(int value);
void appendArgument(double value);
void appendArgument(const std::vector<double>& array);
void appendArgument(const std::vector<std::string>& array);
//! @}
//! Append argument. Make sure to call \sa beginArgumentWrite() before. //! Begin reading arguments
//! @{ void beginArgumentRead();
void appendArgument(bool value);
void appendArgument(const char *value);
void appendArgument(const std::string &value);
void appendArgument(int value);
void appendArgument(double value);
void appendArgument(const std::vector<double> &array);
void appendArgument(const std::vector<std::string> &array);
//! @}
//! Begin reading arguments //! Read single argument. Make sure to call \sa beginArgumentRead() before.
void beginArgumentRead(); //! @{
void getArgument(int& value);
void getArgument(bool& value);
void getArgument(double& value);
void getArgument(std::string& value);
void getArgument(std::vector<int>& value);
void getArgument(std::vector<bool>& value);
void getArgument(std::vector<double>& value);
void getArgument(std::vector<std::string>& value);
//! @}
//! Read single argument. Make sure to call \sa beginArgumentRead() before. //! Creates a DBus message containing a DBus signal
//! @{ static CDBusMessage createSignal(const std::string& path, const std::string& interfaceName, const std::string& signalName);
void getArgument(int &value);
void getArgument(bool &value);
void getArgument(double &value);
void getArgument(std::string &value);
void getArgument(std::vector<int> &value);
void getArgument(std::vector<bool> &value);
void getArgument(std::vector<double> &value);
void getArgument(std::vector<std::string> &value);
//! @}
//! Creates a DBus message containing a DBus signal //! Creates a DBus message containing a DBus reply
static CDBusMessage createSignal(const std::string &path, const std::string &interfaceName, const std::string &signalName); static CDBusMessage createReply(const std::string& destination, dbus_uint32_t serial);
//! Creates a DBus message containing a DBus reply private:
static CDBusMessage createReply(const std::string &destination, dbus_uint32_t serial); friend class CDBusConnection;
private: DBusMessage* m_message = nullptr;
friend class CDBusConnection; DBusMessageIter m_messageIterator;
CDBusMessage(DBusMessage* message, dbus_uint32_t serial);
dbus_uint32_t m_serial = 0;
};
DBusMessage *m_message = nullptr; } // namespace FGSwiftBus
DBusMessageIter m_messageIterator;
CDBusMessage(DBusMessage *message, dbus_uint32_t serial);
dbus_uint32_t m_serial = 0;
};
}
#endif // guard #endif // guard

View file

@ -20,87 +20,85 @@
#include "dbusobject.h" #include "dbusobject.h"
#include <cassert> #include <cassert>
namespace FGSwiftBus namespace FGSwiftBus {
CDBusObject::CDBusObject()
{ {
CDBusObject::CDBusObject()
{ }
CDBusObject::~CDBusObject()
{
if (m_dbusConnection) { m_dbusConnection->unregisterDisconnectedCallback(this); }
};
void CDBusObject::setDBusConnection(const std::shared_ptr<CDBusConnection> &dbusConnection)
{
m_dbusConnection = dbusConnection;
dbusConnectedHandler();
CDBusConnection::DisconnectedCallback disconnectedHandler = std::bind(&CDBusObject::dbusDisconnectedHandler, this);
m_dbusConnection->registerDisconnectedCallback(this, disconnectedHandler);
}
void CDBusObject::registerDBusObjectPath(const std::string &interfaceName, const std::string &objectPath)
{
assert(m_dbusConnection);
m_interfaceName = interfaceName;
m_objectPath = objectPath;
m_dbusConnection->registerObjectPath(this, interfaceName, objectPath, m_dbusObjectPathVTable);
}
void CDBusObject::sendDBusSignal(const std::string &name)
{
if (! m_dbusConnection) { return; }
CDBusMessage signal = CDBusMessage::createSignal(m_objectPath, m_interfaceName, name);
m_dbusConnection->sendMessage(signal);
}
void CDBusObject::sendDBusMessage(const CDBusMessage &message)
{
if (! m_dbusConnection) { return; }
m_dbusConnection->sendMessage(message);
}
void CDBusObject::maybeSendEmptyDBusReply(bool wantsReply, const std::string &destination, dbus_uint32_t serial)
{
if (wantsReply)
{
CDBusMessage reply = CDBusMessage::createReply(destination, serial);
m_dbusConnection->sendMessage(reply);
}
}
void CDBusObject::queueDBusCall(const std::function<void ()> &func)
{
std::lock_guard<std::mutex> lock(m_mutex);
m_qeuedDBusCalls.push_back(func);
}
void CDBusObject::invokeQueuedDBusCalls()
{
std::lock_guard<std::mutex> lock(m_mutex);
while (m_qeuedDBusCalls.size() > 0)
{
m_qeuedDBusCalls.front()();
m_qeuedDBusCalls.pop_front();
}
}
void CDBusObject::dbusObjectPathUnregisterFunction(DBusConnection *connection, void *data)
{
(void)connection; // unused
(void)data; // unused
}
DBusHandlerResult CDBusObject::dbusObjectPathMessageFunction(DBusConnection *connection, DBusMessage *message, void *data)
{
(void)connection; // unused
auto *obj = static_cast<CDBusObject *>(data);
DBusError err;
dbus_error_init(&err);
CDBusMessage dbusMessage(message);
return obj->dbusMessageHandler(dbusMessage);
}
} }
CDBusObject::~CDBusObject()
{
if (m_dbusConnection) { m_dbusConnection->unregisterDisconnectedCallback(this); }
};
void CDBusObject::setDBusConnection(const std::shared_ptr<CDBusConnection>& dbusConnection)
{
m_dbusConnection = dbusConnection;
dbusConnectedHandler();
CDBusConnection::DisconnectedCallback disconnectedHandler = std::bind(&CDBusObject::dbusDisconnectedHandler, this);
m_dbusConnection->registerDisconnectedCallback(this, disconnectedHandler);
}
void CDBusObject::registerDBusObjectPath(const std::string& interfaceName, const std::string& objectPath)
{
assert(m_dbusConnection);
m_interfaceName = interfaceName;
m_objectPath = objectPath;
m_dbusConnection->registerObjectPath(this, interfaceName, objectPath, m_dbusObjectPathVTable);
}
void CDBusObject::sendDBusSignal(const std::string& name)
{
if (!m_dbusConnection) { return; }
CDBusMessage signal = CDBusMessage::createSignal(m_objectPath, m_interfaceName, name);
m_dbusConnection->sendMessage(signal);
}
void CDBusObject::sendDBusMessage(const CDBusMessage& message)
{
if (!m_dbusConnection) { return; }
m_dbusConnection->sendMessage(message);
}
void CDBusObject::maybeSendEmptyDBusReply(bool wantsReply, const std::string& destination, dbus_uint32_t serial)
{
if (wantsReply) {
CDBusMessage reply = CDBusMessage::createReply(destination, serial);
m_dbusConnection->sendMessage(reply);
}
}
void CDBusObject::queueDBusCall(const std::function<void()>& func)
{
std::lock_guard<std::mutex> lock(m_mutex);
m_qeuedDBusCalls.push_back(func);
}
void CDBusObject::invokeQueuedDBusCalls()
{
std::lock_guard<std::mutex> lock(m_mutex);
while (m_qeuedDBusCalls.size() > 0) {
m_qeuedDBusCalls.front()();
m_qeuedDBusCalls.pop_front();
}
}
void CDBusObject::dbusObjectPathUnregisterFunction(DBusConnection* connection, void* data)
{
(void)connection; // unused
(void)data; // unused
}
DBusHandlerResult CDBusObject::dbusObjectPathMessageFunction(DBusConnection* connection, DBusMessage* message, void* data)
{
(void)connection; // unused
auto* obj = static_cast<CDBusObject*>(data);
DBusError err;
dbus_error_init(&err);
CDBusMessage dbusMessage(message);
return obj->dbusMessageHandler(dbusMessage);
}
} // namespace FGSwiftBus

View file

@ -21,88 +21,87 @@
#define BLACKSIM_FGSWIFTBUS_DBUSOBJECT_H #define BLACKSIM_FGSWIFTBUS_DBUSOBJECT_H
#include "dbusconnection.h" #include "dbusconnection.h"
#include <mutex>
#include <deque> #include <deque>
#include <mutex>
namespace FGSwiftBus namespace FGSwiftBus {
//! DBus base object
class CDBusObject
{ {
//! DBus base object public:
class CDBusObject //! Constructor
CDBusObject();
//! Destructor
virtual ~CDBusObject();
//! Set the assigned DBus connection.
//! \remark Currently one object can only manage one connection at a time
void setDBusConnection(const std::shared_ptr<CDBusConnection>& dbusConnection);
//! Register itself with interfaceName and objectPath
//! \warning Before calling this method, make sure that a valid DBus connection was set.
void registerDBusObjectPath(const std::string& interfaceName, const std::string& objectPath);
protected:
//! Handler which is called when DBusCconnection is established
virtual void dbusConnectedHandler() {}
//! DBus message handler
virtual DBusHandlerResult dbusMessageHandler(const CDBusMessage& message) = 0;
//! Handler which is called when DBusConnection disconnected
virtual void dbusDisconnectedHandler() {}
//! Send DBus signal
void sendDBusSignal(const std::string& name);
//! Send DBus message
void sendDBusMessage(const CDBusMessage& message);
//! Maybe sends an empty DBus reply (acknowledgement)
void maybeSendEmptyDBusReply(bool wantsReply, const std::string& destination, dbus_uint32_t serial);
//! Send DBus reply
template <typename T>
void sendDBusReply(const std::string& destination, dbus_uint32_t serial, const T& argument)
{ {
public: CDBusMessage reply = CDBusMessage::createReply(destination, serial);
//! Constructor reply.beginArgumentWrite();
CDBusObject(); reply.appendArgument(argument);
m_dbusConnection->sendMessage(reply);
}
//! Destructor //! Send DBus reply
virtual ~CDBusObject(); template <typename T>
void sendDBusReply(const std::string& destination, dbus_uint32_t serial, const std::vector<T>& array)
{
CDBusMessage reply = CDBusMessage::createReply(destination, serial);
reply.beginArgumentWrite();
reply.appendArgument(array);
m_dbusConnection->sendMessage(reply);
}
//! Set the assigned DBus connection. //! Queue a DBus call to be executed in a different thread
//! \remark Currently one object can only manage one connection at a time void queueDBusCall(const std::function<void()>& func);
void setDBusConnection(const std::shared_ptr<CDBusConnection> &dbusConnection);
//! Register itself with interfaceName and objectPath //! Invoke all pending DBus calls. They will be executed in the calling thread.
//! \warning Before calling this method, make sure that a valid DBus connection was set. void invokeQueuedDBusCalls();
void registerDBusObjectPath(const std::string &interfaceName, const std::string &objectPath);
protected: private:
//! Handler which is called when DBusCconnection is established static void dbusObjectPathUnregisterFunction(DBusConnection* connection, void* data);
virtual void dbusConnectedHandler() {} static DBusHandlerResult dbusObjectPathMessageFunction(DBusConnection* connection, DBusMessage* message, void* data);
//! DBus message handler std::shared_ptr<CDBusConnection> m_dbusConnection;
virtual DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) = 0; std::string m_interfaceName;
std::string m_objectPath;
//! Handler which is called when DBusConnection disconnected std::mutex m_mutex;
virtual void dbusDisconnectedHandler() {} std::deque<std::function<void()>> m_qeuedDBusCalls;
//! Send DBus signal const DBusObjectPathVTable m_dbusObjectPathVTable = {dbusObjectPathUnregisterFunction, dbusObjectPathMessageFunction, nullptr, nullptr, nullptr, nullptr};
void sendDBusSignal(const std::string &name); };
//! Send DBus message } // namespace FGSwiftBus
void sendDBusMessage(const CDBusMessage &message);
//! Maybe sends an empty DBus reply (acknowledgement)
void maybeSendEmptyDBusReply(bool wantsReply, const std::string &destination, dbus_uint32_t serial);
//! Send DBus reply
template <typename T>
void sendDBusReply(const std::string &destination, dbus_uint32_t serial, const T &argument)
{
CDBusMessage reply = CDBusMessage::createReply(destination, serial);
reply.beginArgumentWrite();
reply.appendArgument(argument);
m_dbusConnection->sendMessage(reply);
}
//! Send DBus reply
template <typename T>
void sendDBusReply(const std::string &destination, dbus_uint32_t serial, const std::vector<T> &array)
{
CDBusMessage reply = CDBusMessage::createReply(destination, serial);
reply.beginArgumentWrite();
reply.appendArgument(array);
m_dbusConnection->sendMessage(reply);
}
//! Queue a DBus call to be executed in a different thread
void queueDBusCall(const std::function<void()> &func);
//! Invoke all pending DBus calls. They will be executed in the calling thread.
void invokeQueuedDBusCalls();
private:
static void dbusObjectPathUnregisterFunction(DBusConnection *connection, void *data);
static DBusHandlerResult dbusObjectPathMessageFunction(DBusConnection *connection, DBusMessage *message, void *data);
std::shared_ptr<CDBusConnection> m_dbusConnection;
std::string m_interfaceName;
std::string m_objectPath;
std::mutex m_mutex;
std::deque<std::function<void()>> m_qeuedDBusCalls;
const DBusObjectPathVTable m_dbusObjectPathVTable = { dbusObjectPathUnregisterFunction, dbusObjectPathMessageFunction, nullptr, nullptr, nullptr, nullptr };
};
}
#endif // guard #endif // guard

View file

@ -19,83 +19,81 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "dbusserver.h"
#include "dbusobject.h" #include "dbusobject.h"
#include "dbusserver.h"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <memory> #include <memory>
namespace FGSwiftBus namespace FGSwiftBus {
CDBusServer::CDBusServer()
{ {
dbus_threads_init_default();
CDBusServer::CDBusServer()
{
dbus_threads_init_default();
}
CDBusServer::~CDBusServer()
{
close();
}
bool CDBusServer::listen(const std::string &address)
{
DBusError error;
dbus_error_init(&error);
m_server.reset(dbus_server_listen(address.c_str(), &error));
if (! m_server)
{
return false;
}
dbus_server_set_new_connection_function(m_server.get(), onNewConnection, this, nullptr);
return true;
}
bool CDBusServer::isConnected() const
{
return m_server ? dbus_server_get_is_connected(m_server.get()) : false;
}
void CDBusServer::close()
{
if (m_server) { dbus_server_disconnect(m_server.get()); }
}
void CDBusServer::setDispatcher(CDBusDispatcher *dispatcher)
{
assert(dispatcher);
assert(m_server);
m_dispatcher = dispatcher;
dbus_server_set_watch_functions(
m_server.get(),
dispatcher->m_watchCallbacks.add,
dispatcher->m_watchCallbacks.remove,
dispatcher->m_watchCallbacks.toggled,
&dispatcher->m_watchCallbacks, nullptr);
dbus_server_set_timeout_functions(
m_server.get(),
dispatcher->m_timeoutCallbacks.add,
dispatcher->m_timeoutCallbacks.remove,
dispatcher->m_timeoutCallbacks.toggled,
&dispatcher->m_timeoutCallbacks, nullptr);
}
void CDBusServer::onNewConnection(DBusServer *, DBusConnection *conn)
{
auto dbusConnection = std::make_shared<CDBusConnection>(conn);
m_newConnectionFunc(dbusConnection);
}
void CDBusServer::onNewConnection(DBusServer *server, DBusConnection *conn, void *data)
{
auto *obj = static_cast<CDBusServer *>(data);
obj->onNewConnection(server, conn);
}
} }
CDBusServer::~CDBusServer()
{
close();
}
bool CDBusServer::listen(const std::string& address)
{
DBusError error;
dbus_error_init(&error);
m_server.reset(dbus_server_listen(address.c_str(), &error));
if (!m_server) {
return false;
}
dbus_server_set_new_connection_function(m_server.get(), onNewConnection, this, nullptr);
return true;
}
bool CDBusServer::isConnected() const
{
return m_server ? dbus_server_get_is_connected(m_server.get()) : false;
}
void CDBusServer::close()
{
if (m_server) { dbus_server_disconnect(m_server.get()); }
}
void CDBusServer::setDispatcher(CDBusDispatcher* dispatcher)
{
assert(dispatcher);
assert(m_server);
m_dispatcher = dispatcher;
dbus_server_set_watch_functions(
m_server.get(),
dispatcher->m_watchCallbacks.add,
dispatcher->m_watchCallbacks.remove,
dispatcher->m_watchCallbacks.toggled,
&dispatcher->m_watchCallbacks, nullptr);
dbus_server_set_timeout_functions(
m_server.get(),
dispatcher->m_timeoutCallbacks.add,
dispatcher->m_timeoutCallbacks.remove,
dispatcher->m_timeoutCallbacks.toggled,
&dispatcher->m_timeoutCallbacks, nullptr);
}
void CDBusServer::onNewConnection(DBusServer*, DBusConnection* conn)
{
auto dbusConnection = std::make_shared<CDBusConnection>(conn);
m_newConnectionFunc(dbusConnection);
}
void CDBusServer::onNewConnection(DBusServer* server, DBusConnection* conn, void* data)
{
auto* obj = static_cast<CDBusServer*>(data);
obj->onNewConnection(server, conn);
}
} // namespace FGSwiftBus

View file

@ -20,75 +20,73 @@
#ifndef BLACKSIM_FGSWIFTBUS_DBUSSERVER_H #ifndef BLACKSIM_FGSWIFTBUS_DBUSSERVER_H
#define BLACKSIM_FGSWIFTBUS_DBUSSERVER_H #define BLACKSIM_FGSWIFTBUS_DBUSSERVER_H
#include "dbusmessage.h"
#include "dbuserror.h"
#include "dbuscallbacks.h" #include "dbuscallbacks.h"
#include "dbusdispatcher.h" #include "dbusdispatcher.h"
#include "dbuserror.h"
#include "dbusmessage.h"
#include <event2/event.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <event2/event.h>
#include <functional>
#include <memory>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <memory>
#include <functional>
namespace FGSwiftBus namespace FGSwiftBus {
class CDBusObject;
//! DBus connection
class CDBusServer : public IDispatchable
{ {
public:
//! New connection handler function
using NewConnectionFunc = std::function<void(std::shared_ptr<CDBusConnection>)>;
class CDBusObject; //! Constructor
CDBusServer();
//! DBus connection //! Destructor
class CDBusServer : public IDispatchable ~CDBusServer();
//! Set the dispatcher
void setDispatcher(CDBusDispatcher* dispatcher);
//! Connect to bus
bool listen(const std::string& address);
//! Is connected?
bool isConnected() const;
void dispatch() override {}
//! Close connection
void close();
//! Get the last error
CDBusError lastError() const { return m_lastError; }
//! Set the function to be used for handling new connections.
void setNewConnectionFunc(const NewConnectionFunc& func)
{ {
public: m_newConnectionFunc = func;
//! New connection handler function }
using NewConnectionFunc = std::function<void(std::shared_ptr<CDBusConnection>)>;
//! Constructor private:
CDBusServer(); void onNewConnection(DBusServer* server, DBusConnection* conn);
static void onNewConnection(DBusServer* server, DBusConnection* conn, void* data);
//! Destructor struct DBusServerDeleter {
~CDBusServer(); void operator()(DBusServer* obj) const { dbus_server_unref(obj); }
//! Set the dispatcher
void setDispatcher(CDBusDispatcher *dispatcher);
//! Connect to bus
bool listen(const std::string &address);
//! Is connected?
bool isConnected() const;
void dispatch() override {}
//! Close connection
void close();
//! Get the last error
CDBusError lastError() const { return m_lastError; }
//! Set the function to be used for handling new connections.
void setNewConnectionFunc(const NewConnectionFunc &func)
{
m_newConnectionFunc = func;
}
private:
void onNewConnection(DBusServer *server, DBusConnection *conn);
static void onNewConnection(DBusServer *server, DBusConnection *conn, void *data);
struct DBusServerDeleter
{
void operator()(DBusServer *obj) const { dbus_server_unref(obj); }
};
CDBusDispatcher *m_dispatcher = nullptr;
std::unique_ptr<DBusServer, DBusServerDeleter> m_server;
CDBusError m_lastError;
NewConnectionFunc m_newConnectionFunc;
}; };
} CDBusDispatcher* m_dispatcher = nullptr;
std::unique_ptr<DBusServer, DBusServerDeleter> m_server;
CDBusError m_lastError;
NewConnectionFunc m_newConnectionFunc;
};
} // namespace FGSwiftBus
#endif // guard #endif // guard

View file

@ -23,17 +23,15 @@
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <cmath>
#include <functional> #include <functional>
#include <iostream> #include <iostream>
#include <simgear/structure/commands.hxx> #include <simgear/structure/commands.hxx>
#include <simgear/structure/event_mgr.hxx>
#include <thread> #include <thread>
namespace { namespace {
inline std::string fgswiftbusServiceName() inline std::string fgswiftbusServiceName()
{ {
return std::string("org.swift-project.fgswiftbus"); return "org.swift-project.fgswiftbus";
} }
} // namespace } // namespace
@ -79,17 +77,6 @@ void CPlugin::startServer()
SG_LOG(SG_NETWORK, SG_INFO, "FGSwiftBus started"); SG_LOG(SG_NETWORK, SG_INFO, "FGSwiftBus started");
} }
float CPlugin::startServerDeferred(float, float, int, void* refcon)
{
auto plugin = static_cast<CPlugin*>(refcon);
if (!plugin->m_isRunning) {
plugin->startServer();
plugin->m_isRunning = true;
}
return 0;
}
void CPlugin::fastLoop() void CPlugin::fastLoop()
{ {
this->m_dbusDispatcher.runOnce(); this->m_dbusDispatcher.runOnce();

View file

@ -31,44 +31,41 @@
#define NOMINMAX #define NOMINMAX
#endif #endif
#include "config.h"
#include "dbusconnection.h" #include "dbusconnection.h"
#include "dbusdispatcher.h" #include "dbusdispatcher.h"
#include "dbusserver.h" #include "dbusserver.h"
#include "config.h"
#include <memory> #include <memory>
#include <thread> #include <thread>
namespace FGSwiftBus namespace FGSwiftBus {
{ class CService;
class CService; class CTraffic;
class CTraffic;
class CWeather;
/*! /*!
* Main plugin class * Main plugin class
*/ */
class CPlugin class CPlugin
{ {
public: public:
//! Constructor //! Constructor
CPlugin(); CPlugin();
void startServer(); void startServer();
//! Destructor //! Destructor
~CPlugin(); ~CPlugin();
static float startServerDeferred(float, float, int, void* refcon); void fastLoop();
void fastLoop();
private: private:
CDBusDispatcher m_dbusDispatcher; CDBusDispatcher m_dbusDispatcher;
std::unique_ptr<CDBusServer> m_dbusP2PServer; std::unique_ptr<CDBusServer> m_dbusP2PServer;
std::shared_ptr<CDBusConnection> m_dbusConnection; std::shared_ptr<CDBusConnection> m_dbusConnection;
std::unique_ptr<CService> m_service; std::unique_ptr<CService> m_service;
std::unique_ptr<CTraffic> m_traffic; std::unique_ptr<CTraffic> m_traffic;
std::thread m_dbusThread; std::thread m_dbusThread;
bool m_isRunning = false; bool m_isRunning = false;
bool m_shouldStop = false; bool m_shouldStop = false;
}; };
} } // namespace FGSwiftBus
#endif // guard #endif // BLACKSIM_FGSWIFTBUS_PLUGIN_H

View file

@ -20,9 +20,9 @@
#include "service.h" #include "service.h"
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <iostream> #include <iostream>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/structure/commands.hxx> #include <simgear/structure/commands.hxx>
#include <simgear/constants.h>
#define FGSWIFTBUS_API_VERSION 3; #define FGSWIFTBUS_API_VERSION 3;
@ -31,51 +31,52 @@ namespace FGSwiftBus {
CService::CService() CService::CService()
{ {
// Initialize node pointers // Initialize node pointers
m_textMessageNode = fgGetNode("/sim/messages/copilot", true); m_textMessageNode = fgGetNode("/sim/messages/copilot", true);
m_aircraftModelPathNode = fgGetNode("/sim/aircraft-dir", true); m_aircraftModelPathNode = fgGetNode("/sim/aircraft-dir", true);
m_aircraftDescriptionNode = fgGetNode("/sim/description", true); m_aircraftDescriptionNode = fgGetNode("/sim/description", true);
m_isPausedNode = fgGetNode("/sim/freeze/master", true); m_isPausedNode = fgGetNode("/sim/freeze/master", true);
m_latitudeNode = fgGetNode("/position/latitude-deg", true); m_latitudeNode = fgGetNode("/position/latitude-deg", true);
m_longitudeNode = fgGetNode("/position/longitude-deg", true); m_longitudeNode = fgGetNode("/position/longitude-deg", true);
m_altitudeMSLNode = fgGetNode("/position/altitude-ft", true); m_altitudeMSLNode = fgGetNode("/position/altitude-ft", true);
m_heightAGLNode = fgGetNode("/position/altitude-agl-ft", true); m_heightAGLNode = fgGetNode("/position/altitude-agl-ft", true);
m_groundSpeedNode = fgGetNode("/velocities/groundspeed-kt", true); m_groundSpeedNode = fgGetNode("/velocities/groundspeed-kt", true);
m_pitchNode = fgGetNode("/orientation/pitch-deg", true); m_pitchNode = fgGetNode("/orientation/pitch-deg", true);
m_rollNode = fgGetNode("/orientation/roll-deg", true); m_rollNode = fgGetNode("/orientation/roll-deg", true);
m_trueHeadingNode = fgGetNode("/orientation/heading-deg", true); m_trueHeadingNode = fgGetNode("/orientation/heading-deg", true);
m_wheelsOnGroundNode = fgGetNode("/gear/gear/wow", true); m_wheelsOnGroundNode = fgGetNode("/gear/gear/wow", true);
m_com1ActiveNode = fgGetNode("/instrumentation/comm/frequencies/selected-mhz", true); m_com1ActiveNode = fgGetNode("/instrumentation/comm/frequencies/selected-mhz", true);
m_com1StandbyNode = fgGetNode("/instrumentation/comm/frequencies/standby-mhz", true); m_com1StandbyNode = fgGetNode("/instrumentation/comm/frequencies/standby-mhz", true);
m_com2ActiveNode = fgGetNode("/instrumentation/comm[1]/frequencies/selected-mhz", true); m_com2ActiveNode = fgGetNode("/instrumentation/comm[1]/frequencies/selected-mhz", true);
m_com2StandbyNode = fgGetNode("/instrumentation/comm[1]/frequencies/standby-mhz", true); m_com2StandbyNode = fgGetNode("/instrumentation/comm[1]/frequencies/standby-mhz", true);
m_transponderCodeNode = fgGetNode("/instrumentation/transponder/id-code", true); m_transponderCodeNode = fgGetNode("/instrumentation/transponder/id-code", true);
m_transponderModeNode = fgGetNode("/instrumentation/transponder/inputs/knob-mode", true); m_transponderModeNode = fgGetNode("/instrumentation/transponder/inputs/knob-mode", true);
m_transponderIdentNode = fgGetNode("/instrumentation/transponder/ident", true); m_transponderIdentNode = fgGetNode("/instrumentation/transponder/ident", true);
m_beaconLightsNode = fgGetNode("/controls/lighting/beacon", true); m_beaconLightsNode = fgGetNode("/controls/lighting/beacon", true);
m_landingLightsNode = fgGetNode("/controls/lighting/landing-lights", true); m_landingLightsNode = fgGetNode("/controls/lighting/landing-lights", true);
m_navLightsNode = fgGetNode("/controls/lighting/nav-lights", true); m_navLightsNode = fgGetNode("/controls/lighting/nav-lights", true);
m_strobeLightsNode = fgGetNode("/controls/lighting/strobe", true); m_strobeLightsNode = fgGetNode("/controls/lighting/strobe", true);
m_taxiLightsNode = fgGetNode("/controls/lighting/taxi-light", true); m_taxiLightsNode = fgGetNode("/controls/lighting/taxi-light", true);
m_altimeterServiceableNode = fgGetNode("/instrumentation/altimeter/serviceable", true); m_altimeterServiceableNode = fgGetNode("/instrumentation/altimeter/serviceable", true);
m_pressAltitudeFtNode = fgGetNode("/instrumentation/altimeter/pressure-alt-ft", true); m_pressAltitudeFtNode = fgGetNode("/instrumentation/altimeter/pressure-alt-ft", true);
m_flapsDeployRatioNode = fgGetNode("/surface-positions/flap-pos-norm", true); m_flapsDeployRatioNode = fgGetNode("/surface-positions/flap-pos-norm", true);
m_gearDeployRatioNode = fgGetNode("/gear/gear/position-norm", true); m_gearDeployRatioNode = fgGetNode("/gear/gear/position-norm", true);
m_speedBrakeDeployRatioNode = fgGetNode("/surface-positions/speedbrake-pos-norm", true); m_speedBrakeDeployRatioNode = fgGetNode("/surface-positions/speedbrake-pos-norm", true);
m_aircraftNameNode = fgGetNode("/sim/aircraft", true); m_aircraftNameNode = fgGetNode("/sim/aircraft", true);
m_groundElevationNode = fgGetNode("/position/ground-elev-m", true); m_groundElevationNode = fgGetNode("/position/ground-elev-m", true);
m_velocityXNode = fgGetNode("/velocities/speed-east-fps", true); m_velocityXNode = fgGetNode("/velocities/speed-east-fps", true);
m_velocityYNode = fgGetNode("/velocities/speed-down-fps", true); m_velocityYNode = fgGetNode("/velocities/speed-down-fps", true);
m_velocityZNode = fgGetNode("/velocities/speed-north-fps", true); m_velocityZNode = fgGetNode("/velocities/speed-north-fps", true);
m_rollRateNode = fgGetNode("/orientation/roll-rate-degps", true); m_rollRateNode = fgGetNode("/orientation/roll-rate-degps", true);
m_pichRateNode = fgGetNode("/orientation/pitch-rate-degps", true); m_pichRateNode = fgGetNode("/orientation/pitch-rate-degps", true);
m_yawRateNode = fgGetNode("/orientation/yaw-rate-degps", true); m_yawRateNode = fgGetNode("/orientation/yaw-rate-degps", true);
m_com1VolumeNode = fgGetNode("/instrumentation/comm/volume", true); m_com1VolumeNode = fgGetNode("/instrumentation/comm/volume", true);
m_com2VolumeNode = fgGetNode("/instrumentation/comm[1]/volume", true); m_com2VolumeNode = fgGetNode("/instrumentation/comm[1]/volume", true);
SG_LOG(SG_NETWORK, SG_INFO, "FGSwiftBus Service initialized"); SG_LOG(SG_NETWORK, SG_INFO, "FGSwiftBus Service initialized");
} }
const std::string& CService::InterfaceName() { const std::string& CService::InterfaceName()
{
static const std::string s(FGSWIFTBUS_SERVICE_INTERFACENAME); static const std::string s(FGSWIFTBUS_SERVICE_INTERFACENAME);
return s; return s;
} }
@ -100,162 +101,162 @@ void CService::addTextMessage(const std::string& text)
std::string CService::getAircraftModelPath() const std::string CService::getAircraftModelPath() const
{ {
return m_aircraftModelPathNode->getStringValue(); return m_aircraftModelPathNode->getStringValue();
} }
std::string CService::getAircraftLivery() const std::string CService::getAircraftLivery() const
{ {
return ""; return "";
} }
std::string CService::getAircraftIcaoCode() const std::string CService::getAircraftIcaoCode() const
{ {
return ""; return "";
} }
std::string CService::getAircraftDescription() const std::string CService::getAircraftDescription() const
{ {
return m_aircraftDescriptionNode->getStringValue(); return m_aircraftDescriptionNode->getStringValue();
} }
bool CService::isPaused() const bool CService::isPaused() const
{ {
return m_isPausedNode->getBoolValue(); return m_isPausedNode->getBoolValue();
} }
double CService::getLatitude() const double CService::getLatitude() const
{ {
return m_latitudeNode->getDoubleValue(); return m_latitudeNode->getDoubleValue();
} }
double CService::getLongitude() const double CService::getLongitude() const
{ {
return m_longitudeNode->getDoubleValue(); return m_longitudeNode->getDoubleValue();
} }
double CService::getAltitudeMSL() const double CService::getAltitudeMSL() const
{ {
return m_altitudeMSLNode->getDoubleValue(); return m_altitudeMSLNode->getDoubleValue();
} }
double CService::getHeightAGL() const double CService::getHeightAGL() const
{ {
return m_heightAGLNode->getDoubleValue(); return m_heightAGLNode->getDoubleValue();
} }
double CService::getGroundSpeed() const double CService::getGroundSpeed() const
{ {
return m_groundSpeedNode->getDoubleValue(); return m_groundSpeedNode->getDoubleValue();
} }
double CService::getPitch() const double CService::getPitch() const
{ {
return m_pitchNode->getDoubleValue(); return m_pitchNode->getDoubleValue();
} }
double CService::getRoll() const double CService::getRoll() const
{ {
return m_rollNode->getDoubleValue(); return m_rollNode->getDoubleValue();
} }
double CService::getTrueHeading() const double CService::getTrueHeading() const
{ {
return m_trueHeadingNode->getDoubleValue(); return m_trueHeadingNode->getDoubleValue();
} }
bool CService::getAllWheelsOnGround() const bool CService::getAllWheelsOnGround() const
{ {
return m_wheelsOnGroundNode->getBoolValue(); return m_wheelsOnGroundNode->getBoolValue();
} }
int CService::getCom1Active() const int CService::getCom1Active() const
{ {
return (int)(m_com1ActiveNode->getDoubleValue() * 1000); return (int)(m_com1ActiveNode->getDoubleValue() * 1000);
} }
int CService::getCom1Standby() const int CService::getCom1Standby() const
{ {
return (int)(m_com1StandbyNode->getDoubleValue() * 1000); return (int)(m_com1StandbyNode->getDoubleValue() * 1000);
} }
int CService::getCom2Active() const int CService::getCom2Active() const
{ {
return (int)(m_com2ActiveNode->getDoubleValue() * 1000); return (int)(m_com2ActiveNode->getDoubleValue() * 1000);
} }
int CService::getCom2Standby() const int CService::getCom2Standby() const
{ {
return (int)(m_com2StandbyNode->getDoubleValue() * 1000); return (int)(m_com2StandbyNode->getDoubleValue() * 1000);
} }
int CService::getTransponderCode() const int CService::getTransponderCode() const
{ {
return m_transponderCodeNode->getIntValue(); return m_transponderCodeNode->getIntValue();
} }
int CService::getTransponderMode() const int CService::getTransponderMode() const
{ {
return m_transponderModeNode->getIntValue(); return m_transponderModeNode->getIntValue();
} }
bool CService::getTransponderIdent() const bool CService::getTransponderIdent() const
{ {
return m_transponderIdentNode->getBoolValue(); return m_transponderIdentNode->getBoolValue();
} }
bool CService::getBeaconLightsOn() const bool CService::getBeaconLightsOn() const
{ {
return m_beaconLightsNode->getBoolValue(); return m_beaconLightsNode->getBoolValue();
} }
bool CService::getLandingLightsOn() const bool CService::getLandingLightsOn() const
{ {
return m_landingLightsNode->getBoolValue(); return m_landingLightsNode->getBoolValue();
} }
bool CService::getNavLightsOn() const bool CService::getNavLightsOn() const
{ {
return m_navLightsNode->getBoolValue(); return m_navLightsNode->getBoolValue();
} }
bool CService::getStrobeLightsOn() const bool CService::getStrobeLightsOn() const
{ {
return m_strobeLightsNode->getBoolValue(); return m_strobeLightsNode->getBoolValue();
} }
bool CService::getTaxiLightsOn() const bool CService::getTaxiLightsOn() const
{ {
return m_taxiLightsNode->getBoolValue(); return m_taxiLightsNode->getBoolValue();
} }
double CService::getPressAlt() const double CService::getPressAlt() const
{ {
if (m_altimeterServiceableNode->getBoolValue()){ if (m_altimeterServiceableNode->getBoolValue()) {
return m_pressAltitudeFtNode->getDoubleValue(); return m_pressAltitudeFtNode->getDoubleValue();
} else { } else {
return m_altitudeMSLNode->getDoubleValue(); return m_altitudeMSLNode->getDoubleValue();
} }
} }
void CService::setCom1Active(int freq) void CService::setCom1Active(int freq)
{ {
m_com1ActiveNode->setDoubleValue(freq /(double)1000); m_com1ActiveNode->setDoubleValue(freq / (double)1000);
} }
void CService::setCom1Standby(int freq) void CService::setCom1Standby(int freq)
{ {
m_com1StandbyNode->setDoubleValue(freq /(double)1000); m_com1StandbyNode->setDoubleValue(freq / (double)1000);
} }
void CService::setCom2Active(int freq) void CService::setCom2Active(int freq)
{ {
m_com2ActiveNode->setDoubleValue(freq /(double)1000); m_com2ActiveNode->setDoubleValue(freq / (double)1000);
} }
void CService::setCom2Standby(int freq) void CService::setCom2Standby(int freq)
{ {
m_com2StandbyNode->setDoubleValue(freq /(double)1000); m_com2StandbyNode->setDoubleValue(freq / (double)1000);
} }
void CService::setTransponderCode(int code) void CService::setTransponderCode(int code)
@ -270,25 +271,25 @@ void CService::setTransponderMode(int mode)
double CService::getFlapsDeployRatio() const double CService::getFlapsDeployRatio() const
{ {
return m_flapsDeployRatioNode->getFloatValue(); return m_flapsDeployRatioNode->getFloatValue();
} }
double CService::getGearDeployRatio() const double CService::getGearDeployRatio() const
{ {
return m_gearDeployRatioNode->getFloatValue(); return m_gearDeployRatioNode->getFloatValue();
} }
int CService::getNumberOfEngines() const int CService::getNumberOfEngines() const
{ {
// TODO Use correct property // TODO Use correct property
return 2; return 2;
} }
std::vector<double> CService::getEngineN1Percentage() const std::vector<double> CService::getEngineN1Percentage() const
{ {
// TODO use correct engine numbers // TODO use correct engine numbers
std::vector<double> list; std::vector<double> list;
const auto number = static_cast<unsigned int>(getNumberOfEngines()); const auto number = static_cast<unsigned int>(getNumberOfEngines());
list.reserve(number); list.reserve(number);
for (unsigned int engineNumber = 0; engineNumber < number; ++engineNumber) { for (unsigned int engineNumber = 0; engineNumber < number; ++engineNumber) {
list.push_back(fgGetDouble("/engine/engine/n1")); list.push_back(fgGetDouble("/engine/engine/n1"));
@ -298,7 +299,7 @@ std::vector<double> CService::getEngineN1Percentage() const
double CService::getSpeedBrakeRatio() const double CService::getSpeedBrakeRatio() const
{ {
return m_speedBrakeDeployRatioNode->getFloatValue(); return m_speedBrakeDeployRatioNode->getFloatValue();
} }
double CService::getGroundElevation() const double CService::getGroundElevation() const
@ -315,7 +316,7 @@ std::string CService::getAircraftModelFilename() const
std::string CService::getAircraftModelString() const std::string CService::getAircraftModelString() const
{ {
std::string modelName = getAircraftName(); std::string modelName = getAircraftName();
std::string modelString = "FG " + modelName; std::string modelString = "FG " + modelName;
return modelString; return modelString;
} }
@ -369,10 +370,10 @@ static const char* introspection_service = DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_
DBusHandlerResult CService::dbusMessageHandler(const CDBusMessage& message_) DBusHandlerResult CService::dbusMessageHandler(const CDBusMessage& message_)
{ {
CDBusMessage message(message_); CDBusMessage message(message_);
const std::string sender = message.getSender(); const std::string sender = message.getSender();
const dbus_uint32_t serial = message.getSerial(); const dbus_uint32_t serial = message.getSerial();
const bool wantsReply = message.wantsReply(); const bool wantsReply = message.wantsReply();
if (message.getInterfaceName() == DBUS_INTERFACE_INTROSPECTABLE) { if (message.getInterfaceName() == DBUS_INTERFACE_INTROSPECTABLE) {
if (message.getMethodName() == "Introspect") { if (message.getMethodName() == "Introspect") {
@ -390,15 +391,15 @@ DBusHandlerResult CService::dbusMessageHandler(const CDBusMessage& message_)
}); });
} else if (message.getMethodName() == "getOwnAircraftSituationData") { } else if (message.getMethodName() == "getOwnAircraftSituationData") {
queueDBusCall([=]() { queueDBusCall([=]() {
double lat = getLatitude(); double lat = getLatitude();
double lon = getLongitude(); double lon = getLongitude();
double alt = getAltitudeMSL(); double alt = getAltitudeMSL();
double gs = getGroundSpeed(); double gs = getGroundSpeed();
double pitch = getPitch(); double pitch = getPitch();
double roll = getRoll(); double roll = getRoll();
double trueHeading = getTrueHeading(); double trueHeading = getTrueHeading();
double pressAlt = getPressAlt(); double pressAlt = getPressAlt();
CDBusMessage reply = CDBusMessage::createReply(sender, serial); CDBusMessage reply = CDBusMessage::createReply(sender, serial);
reply.beginArgumentWrite(); reply.beginArgumentWrite();
reply.appendArgument(lat); reply.appendArgument(lat);
reply.appendArgument(lon); reply.appendArgument(lon);
@ -412,13 +413,13 @@ DBusHandlerResult CService::dbusMessageHandler(const CDBusMessage& message_)
}); });
} else if (message.getMethodName() == "getOwnAircraftVelocityData") { } else if (message.getMethodName() == "getOwnAircraftVelocityData") {
queueDBusCall([=]() { queueDBusCall([=]() {
double velocityX = getVelocityX(); double velocityX = getVelocityX();
double velocityY = getVelocityY(); double velocityY = getVelocityY();
double velocityZ = getVelocityZ(); double velocityZ = getVelocityZ();
double pitchVelocity = getPitchRate(); double pitchVelocity = getPitchRate();
double rollVelocity = getRollRate(); double rollVelocity = getRollRate();
double yawVelocity = getYawRate(); double yawVelocity = getYawRate();
CDBusMessage reply = CDBusMessage::createReply(sender, serial); CDBusMessage reply = CDBusMessage::createReply(sender, serial);
reply.beginArgumentWrite(); reply.beginArgumentWrite();
reply.appendArgument(velocityX); reply.appendArgument(velocityX);
reply.appendArgument(velocityY); reply.appendArgument(velocityY);

View file

@ -28,9 +28,8 @@
#include "dbusobject.h" #include "dbusobject.h"
#include <chrono>
#include <string>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <chrono>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/io/raw_socket.hxx> #include <simgear/io/raw_socket.hxx>
@ -40,6 +39,7 @@
#include <simgear/structure/event_mgr.hxx> #include <simgear/structure/event_mgr.hxx>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/timing/timestamp.hxx> #include <simgear/timing/timestamp.hxx>
#include <string>
//! \cond PRIVATE //! \cond PRIVATE
@ -49,7 +49,7 @@
namespace FGSwiftBus { namespace FGSwiftBus {
/*! /*!
* FGSwiftBus service object which is accessible through DBus * FGSwiftBus service object which is accessible through DBus
*/ */
class CService : public CDBusObject class CService : public CDBusObject
@ -268,8 +268,6 @@ private:
SGPropertyNode_ptr m_yawRateNode; SGPropertyNode_ptr m_yawRateNode;
SGPropertyNode_ptr m_com1VolumeNode; SGPropertyNode_ptr m_com1VolumeNode;
SGPropertyNode_ptr m_com2VolumeNode; SGPropertyNode_ptr m_com2VolumeNode;
}; };
} // namespace FGSwiftBus } // namespace FGSwiftBus

View file

@ -24,15 +24,10 @@
#include "plugin.h" #include "plugin.h"
#include "swift_connection.hxx" #include "swift_connection.hxx"
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/io/raw_socket.hxx>
#include <simgear/misc/stdint.hxx>
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <simgear/structure/commands.hxx> #include <simgear/structure/commands.hxx>
#include <simgear/structure/event_mgr.hxx> #include <simgear/structure/event_mgr.hxx>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/timing/timestamp.hxx>
namespace { namespace {
inline std::string fgswiftbusServiceName() inline std::string fgswiftbusServiceName()

View file

@ -22,8 +22,10 @@
#ifndef NOMINMAX #ifndef NOMINMAX
#define NOMINMAX #define NOMINMAX
#endif #endif
#include "traffic.h" #include "traffic.h"
#include "SwiftAircraftManager.h" #include "SwiftAircraftManager.h"
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
@ -82,7 +84,7 @@ void CTraffic::cleanup()
void CTraffic::dbusDisconnectedHandler() void CTraffic::dbusDisconnectedHandler()
{ {
if(acm) if (acm)
acm->removeAllPlanes(); acm->removeAllPlanes();
} }
@ -90,10 +92,10 @@ const char* introspection_traffic = DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE;
DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_) DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
{ {
CDBusMessage message(message_); CDBusMessage message(message_);
const std::string sender = message.getSender(); const std::string sender = message.getSender();
const dbus_uint32_t serial = message.getSerial(); const dbus_uint32_t serial = message.getSerial();
const bool wantsReply = message.wantsReply(); const bool wantsReply = message.wantsReply();
if (message.getInterfaceName() == DBUS_INTERFACE_INTROSPECTABLE) { if (message.getInterfaceName() == DBUS_INTERFACE_INTROSPECTABLE) {
if (message.getMethodName() == "Introspect") { if (message.getMethodName() == "Introspect") {
@ -102,9 +104,9 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
} else if (message.getInterfaceName() == FGSWIFTBUS_TRAFFIC_INTERFACENAME) { } else if (message.getInterfaceName() == FGSWIFTBUS_TRAFFIC_INTERFACENAME) {
if (message.getMethodName() == "acquireMultiplayerPlanes") { if (message.getMethodName() == "acquireMultiplayerPlanes") {
queueDBusCall([=]() { queueDBusCall([=]() {
std::string owner; std::string owner;
bool acquired = true; bool acquired = true;
CDBusMessage reply = CDBusMessage::createReply(sender, serial); CDBusMessage reply = CDBusMessage::createReply(sender, serial);
reply.beginArgumentWrite(); reply.beginArgumentWrite();
reply.appendArgument(acquired); reply.appendArgument(acquired);
reply.appendArgument(owner); reply.appendArgument(owner);
@ -152,14 +154,14 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
} else if (message.getMethodName() == "setPlanesPositions") { } else if (message.getMethodName() == "setPlanesPositions") {
maybeSendEmptyDBusReply(wantsReply, sender, serial); maybeSendEmptyDBusReply(wantsReply, sender, serial);
std::vector<std::string> callsigns; std::vector<std::string> callsigns;
std::vector<double> latitudes; std::vector<double> latitudes;
std::vector<double> longitudes; std::vector<double> longitudes;
std::vector<double> altitudes; std::vector<double> altitudes;
std::vector<double> pitches; std::vector<double> pitches;
std::vector<double> rolls; std::vector<double> rolls;
std::vector<double> headings; std::vector<double> headings;
std::vector<double> groundspeeds; std::vector<double> groundspeeds;
std::vector<bool> onGrounds; std::vector<bool> onGrounds;
message.beginArgumentRead(); message.beginArgumentRead();
message.getArgument(callsigns); message.getArgument(callsigns);
message.getArgument(latitudes); message.getArgument(latitudes);
@ -191,10 +193,10 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
message.getArgument(requestedcallsigns); message.getArgument(requestedcallsigns);
queueDBusCall([=]() { queueDBusCall([=]() {
std::vector<std::string> callsigns = requestedcallsigns; std::vector<std::string> callsigns = requestedcallsigns;
std::vector<double> latitudesDeg; std::vector<double> latitudesDeg;
std::vector<double> longitudesDeg; std::vector<double> longitudesDeg;
std::vector<double> elevationsM; std::vector<double> elevationsM;
std::vector<double> verticalOffsets; std::vector<double> verticalOffsets;
acm->getRemoteAircraftData(callsigns, latitudesDeg, longitudesDeg, elevationsM, verticalOffsets); acm->getRemoteAircraftData(callsigns, latitudesDeg, longitudesDeg, elevationsM, verticalOffsets);
CDBusMessage reply = CDBusMessage::createReply(sender, serial); CDBusMessage reply = CDBusMessage::createReply(sender, serial);
reply.beginArgumentWrite(); reply.beginArgumentWrite();
@ -205,8 +207,7 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
reply.appendArgument(verticalOffsets); reply.appendArgument(verticalOffsets);
sendDBusMessage(reply); sendDBusMessage(reply);
}); });
} else if (message.getMethodName() == "getElevationAtPosition") } else if (message.getMethodName() == "getElevationAtPosition") {
{
std::string callsign; std::string callsign;
double latitudeDeg; double latitudeDeg;
double longitudeDeg; double longitudeDeg;
@ -216,21 +217,19 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
message.getArgument(latitudeDeg); message.getArgument(latitudeDeg);
message.getArgument(longitudeDeg); message.getArgument(longitudeDeg);
message.getArgument(altitudeMeters); message.getArgument(altitudeMeters);
queueDBusCall([ = ]() queueDBusCall([=]() {
{ SGGeod pos;
SGGeod pos; pos.setLatitudeDeg(latitudeDeg);
pos.setLatitudeDeg(latitudeDeg); pos.setLongitudeDeg(longitudeDeg);
pos.setLongitudeDeg(longitudeDeg); pos.setElevationM(altitudeMeters);
pos.setElevationM(altitudeMeters); double elevation = acm->getElevationAtPosition(callsign, pos);
double elevation = acm->getElevationAtPosition(callsign, pos); CDBusMessage reply = CDBusMessage::createReply(sender, serial);
CDBusMessage reply = CDBusMessage::createReply(sender, serial); reply.beginArgumentWrite();
reply.beginArgumentWrite(); reply.appendArgument(callsign);
reply.appendArgument(callsign); reply.appendArgument(elevation);
reply.appendArgument(elevation); sendDBusMessage(reply);
sendDBusMessage(reply); });
}); } else if (message.getMethodName() == "setPlanesTransponders") {
} else if (message.getMethodName() == "setPlanesTransponders")
{
maybeSendEmptyDBusReply(wantsReply, sender, serial); maybeSendEmptyDBusReply(wantsReply, sender, serial);
std::vector<std::string> callsigns; std::vector<std::string> callsigns;
std::vector<int> codes; std::vector<int> codes;
@ -243,16 +242,13 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
message.getArgument(idents); message.getArgument(idents);
std::vector<AircraftTransponder> transponders; std::vector<AircraftTransponder> transponders;
transponders.reserve(callsigns.size()); transponders.reserve(callsigns.size());
for(long unsigned int i = 0; i < callsigns.size(); i++) for (long unsigned int i = 0; i < callsigns.size(); i++) {
{
transponders.emplace_back(callsigns.at(i), codes.at(i), modeCs.at(i), idents.at(i)); transponders.emplace_back(callsigns.at(i), codes.at(i), modeCs.at(i), idents.at(i));
} }
queueDBusCall([ = ]() queueDBusCall([=]() {
{ acm->setPlanesTransponders(transponders);
acm->setPlanesTransponders(transponders); });
}); } else if (message.getMethodName() == "setPlanesSurfaces") {
} else if (message.getMethodName() == "setPlanesSurfaces")
{
maybeSendEmptyDBusReply(wantsReply, sender, serial); maybeSendEmptyDBusReply(wantsReply, sender, serial);
std::vector<std::string> callsigns; std::vector<std::string> callsigns;
std::vector<double> gears; std::vector<double> gears;
@ -291,16 +287,14 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
message.getArgument(lightPatterns); message.getArgument(lightPatterns);
std::vector<AircraftSurfaces> surfaces; std::vector<AircraftSurfaces> surfaces;
surfaces.reserve(callsigns.size()); surfaces.reserve(callsigns.size());
for(long unsigned int i = 0; i < callsigns.size(); i++) for (long unsigned int i = 0; i < callsigns.size(); i++) {
{
surfaces.emplace_back(callsigns.at(i), gears.at(i), flaps.at(i), spoilers.at(i), speedBrakes.at(i), slats.at(i), surfaces.emplace_back(callsigns.at(i), gears.at(i), flaps.at(i), spoilers.at(i), speedBrakes.at(i), slats.at(i),
wingSweeps.at(i), thrusts.at(i), elevators.at(i), rudders.at(i), ailerons.at(i), wingSweeps.at(i), thrusts.at(i), elevators.at(i), rudders.at(i), ailerons.at(i),
landLights.at(i), taxiLights.at(i), beaconLights.at(i), strobeLights.at(i), navLights.at(i), lightPatterns.at(i)); landLights.at(i), taxiLights.at(i), beaconLights.at(i), strobeLights.at(i), navLights.at(i), lightPatterns.at(i));
} }
queueDBusCall([ = ]() queueDBusCall([=]() {
{ acm->setPlanesSurfaces(surfaces);
acm->setPlanesSurfaces(surfaces); });
});
} else { } else {
// Unknown message. Tell DBus that we cannot handle it // Unknown message. Tell DBus that we cannot handle it
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@ -309,11 +303,11 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
return DBUS_HANDLER_RESULT_HANDLED; return DBUS_HANDLER_RESULT_HANDLED;
} }
int CTraffic::process() int CTraffic::process()
{ {
invokeQueuedDBusCalls(); invokeQueuedDBusCalls();
return 1; return 1;
} }
} // namespace FGSwiftBus } // namespace FGSwiftBus

View file

@ -24,6 +24,7 @@
#include "SwiftAircraftManager.h" #include "SwiftAircraftManager.h"
#include "dbusobject.h" #include "dbusobject.h"
#include <functional> #include <functional>
#include <utility> #include <utility>
@ -48,7 +49,7 @@ public:
//! DBus interface name //! DBus interface name
static const std::string& InterfaceName(); static const std::string& InterfaceName();
//! DBus object path //! DBus object path
static const std::string& ObjectPath(); static const std::string& ObjectPath();
//! Initialize the multiplayer planes rendering and return true if successful //! Initialize the multiplayer planes rendering and return true if successful
@ -69,9 +70,9 @@ private:
void cleanup(); void cleanup();
struct Plane { struct Plane {
void* id = nullptr; void* id = nullptr;
std::string callsign; std::string callsign;
char label[32]{}; char label[32]{};
}; };
bool m_emitSimFrame = true; bool m_emitSimFrame = true;