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 <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/subsystem_mgr.hxx>
class FGAIBase;
class FGAIThermal;

View file

@ -33,7 +33,7 @@ FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::str
_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;
_setLatitude(position.getLatitudeDeg());

View file

@ -25,8 +25,6 @@
#include "AIBaseAircraft.hxx"
using charPtr = const char*;
struct AircraftTransponder
{
AircraftTransponder(std::string callsign, int code, bool modeC, bool ident)
@ -76,7 +74,7 @@ public:
string_view getTypeString() const override { return "swift"; }
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;
void initProps();
void setPlaneSurface(const AircraftSurfaces& surfaces);

View file

@ -49,14 +49,11 @@ bool FGSwiftAircraftManager::addPlane(const std::string& callsign, const std::st
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)
{
for (long unsigned int i = 0; i < callsigns.size(); i++)
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++) {
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);
}
}
@ -99,8 +96,7 @@ void FGSwiftAircraftManager::getRemoteAircraftData(std::vector<std::string>& cal
void FGSwiftAircraftManager::removePlane(const std::string& callsign)
{
auto it = aircraftByCallsign.find(callsign);
if(it != aircraftByCallsign.end())
{
if (it != aircraftByCallsign.end()) {
it->second->setDie(true);
aircraftByCallsign.erase(it);
}
@ -108,8 +104,7 @@ void FGSwiftAircraftManager::removePlane(const std::string& callsign)
void FGSwiftAircraftManager::removeAllPlanes()
{
for(auto it = aircraftByCallsign.begin(); it!= aircraftByCallsign.end();)
{
for (auto it = aircraftByCallsign.begin(); it != aircraftByCallsign.end();) {
it->second->setDie(true);
it = aircraftByCallsign.erase(it);
}
@ -118,8 +113,7 @@ void FGSwiftAircraftManager::removeAllPlanes()
double FGSwiftAircraftManager::getElevationAtPosition(const std::string& callsign, const SGGeod& pos) const
{
auto it = aircraftByCallsign.find(callsign);
if(it != aircraftByCallsign.end())
{
if (it != aircraftByCallsign.end()) {
return it->second->getGroundElevation(pos);
}
// Aircraft not found in list
@ -128,11 +122,9 @@ double FGSwiftAircraftManager::getElevationAtPosition(const std::string &callsig
void FGSwiftAircraftManager::setPlanesTransponders(const std::vector<AircraftTransponder>& transponders)
{
for (const auto & transponder : transponders)
{
for (const auto& transponder : transponders) {
auto it = aircraftByCallsign.find(transponder.callsign);
if(it != aircraftByCallsign.end())
{
if (it != aircraftByCallsign.end()) {
it->second->setPlaneTransponder(transponder);
}
}
@ -140,11 +132,9 @@ void FGSwiftAircraftManager::setPlanesTransponders(const std::vector<AircraftTra
void FGSwiftAircraftManager::setPlanesSurfaces(const std::vector<AircraftSurfaces>& surfaces)
{
for (const auto & surface : surfaces)
{
for (const auto& surface : surfaces) {
auto it = aircraftByCallsign.find(surface.callsign);
if(it != aircraftByCallsign.end())
{
if (it != aircraftByCallsign.end()) {
it->second->setPlaneSurface(surface);
}
}

View file

@ -17,12 +17,12 @@
// along with this program; if not, write to the Free Software
// 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/AISwiftAircraft.h>
#include <Scenery/scenery.hxx>
#include <vector>
#include <unordered_map>
#include <vector>
#ifndef FGSWIFTAIRCRAFTMANAGER_H
#define FGSWIFTAIRCRAFTMANAGER_H
@ -35,7 +35,7 @@ public:
FGSwiftAircraftManager();
~FGSwiftAircraftManager();
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,
std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const;
void removePlane(const std::string& callsign);
@ -48,6 +48,5 @@ public:
private:
std::unordered_map<std::string, FGAISwiftAircraftPtr> aircraftByCallsign;
bool m_initialized = false;
};
#endif

View file

@ -23,8 +23,7 @@
#include <dbus/dbus.h>
#include <functional>
namespace FGSwiftBus
{
namespace FGSwiftBus {
//! \cond PRIVATE
template <typename T>
class DBusAsyncCallbacks
@ -35,7 +34,8 @@ namespace FGSwiftBus
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)
{
@ -59,6 +59,6 @@ namespace FGSwiftBus
};
//! \endcond
}
} // namespace FGSwiftBus
#endif // guard

View file

@ -1,5 +1,3 @@
#include <utility>
// dbusconnection.cpp
//
// Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/)
@ -26,8 +24,7 @@
#include <cassert>
#include <memory>
namespace FGSwiftBus
{
namespace FGSwiftBus {
CDBusConnection::CDBusConnection()
{
@ -57,14 +54,12 @@ namespace FGSwiftBus
dbus_error_init(&error);
DBusBusType dbusBusType;
switch (type)
{
switch (type) {
case SessionBus: dbusBusType = DBUS_BUS_SESSION; break;
}
m_connection.reset(dbus_bus_get_private(dbusBusType, &error));
if (dbus_error_is_set(&error))
{
if (dbus_error_is_set(&error)) {
m_lastError = CDBusError(&error);
return false;
}
@ -144,9 +139,9 @@ namespace FGSwiftBus
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);
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());
}
@ -155,8 +150,7 @@ namespace FGSwiftBus
{
if (dbus_connection_get_is_connected(connection) == FALSE) { return; }
switch (status)
{
switch (status) {
case DBUS_DISPATCH_DATA_REMAINS:
//m_dispatcher->add(this);
break;
@ -181,10 +175,8 @@ namespace FGSwiftBus
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)
{
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;
@ -192,4 +184,4 @@ namespace FGSwiftBus
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
}
} // namespace FGSwiftBus

View file

@ -20,19 +20,18 @@
#ifndef BLACKSIM_FGSWIFTBUS_DBUSCONNECTION_H
#define BLACKSIM_FGSWIFTBUS_DBUSCONNECTION_H
#include "dbusmessage.h"
#include "dbuserror.h"
#include "dbuscallbacks.h"
#include "dbusdispatcher.h"
#include "dbuserror.h"
#include "dbusmessage.h"
#include <event2/event.h>
#include <dbus/dbus.h>
#include <event2/event.h>
#include <memory>
#include <string>
#include <unordered_map>
#include <memory>
namespace FGSwiftBus
{
namespace FGSwiftBus {
class CDBusObject;
@ -103,8 +102,7 @@ namespace FGSwiftBus
static void setDispatchStatus(DBusConnection* connection, DBusDispatchStatus status, void* data);
static DBusHandlerResult filterDisconnectedFunction(DBusConnection* connection, DBusMessage* message, void* data);
struct DBusConnectionDeleter
{
struct DBusConnectionDeleter {
void operator()(DBusConnection* obj) const { dbus_connection_unref(obj); }
};
@ -114,6 +112,6 @@ namespace FGSwiftBus
std::unordered_map<CDBusObject*, DisconnectedCallback> m_disconnectedCallbacks;
};
}
} // namespace FGSwiftBus
#endif // guard

View file

@ -24,18 +24,17 @@
namespace { // anonymosu namespace
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)...));
}
} // end of anonymous namespace
namespace FGSwiftBus
{
namespace FGSwiftBus {
//! Functor struct deleteing an event
struct EventDeleter
{
struct EventDeleter {
//! Delete functor
void operator()(event* obj) const
{
@ -151,8 +150,7 @@ namespace FGSwiftBus
std::function<void()> m_func;
};
CDBusDispatcher::CDBusDispatcher() :
m_eventBase(event_base_new())
CDBusDispatcher::CDBusDispatcher() : m_eventBase(event_base_new())
{
using namespace std::placeholders;
m_watchCallbacks = WatchCallbacks(std::bind(&CDBusDispatcher::dbusAddWatch, this, _1),
@ -196,8 +194,7 @@ namespace FGSwiftBus
{
if (m_dispatchList.empty()) { return; }
for (IDispatchable *dispatchable : m_dispatchList)
{
for (IDispatchable* dispatchable : m_dispatchList) {
dispatchable->dispatch();
}
}
@ -213,17 +210,22 @@ namespace FGSwiftBus
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; }
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); }
if (dbus_watch_get_enabled(watch) == TRUE) {
dbusAddWatch(watch);
} else {
dbusRemoveWatch(watch);
}
}
dbus_bool_t CDBusDispatcher::dbusAddTimeout(DBusTimeout* timeout)
@ -235,8 +237,7 @@ namespace FGSwiftBus
void CDBusDispatcher::dbusRemoveTimeout(DBusTimeout* timeout)
{
auto predicate = [timeout](const std::unique_ptr<TimeoutHandler> &ptr)
{
auto predicate = [timeout](const std::unique_ptr<TimeoutHandler>& ptr) {
return ptr->getTimeout() == timeout;
};
@ -251,4 +252,4 @@ namespace FGSwiftBus
dbusRemoveTimeout(timeout);
}
}
} // namespace FGSwiftBus

View file

@ -22,15 +22,14 @@
#include "dbuscallbacks.h"
#include <event2/event.h>
#include <dbus/dbus.h>
#include <event2/event.h>
#include <memory>
#include <unordered_map>
#include <vector>
#include <memory>
namespace FGSwiftBus
{
namespace FGSwiftBus {
class WatchHandler;
class TimeoutHandler;
@ -83,8 +82,7 @@ namespace FGSwiftBus
friend class CDBusConnection;
friend class CDBusServer;
struct EventBaseDeleter
{
struct EventBaseDeleter {
void operator()(event_base* obj) const { event_base_free(obj); }
};
@ -109,6 +107,6 @@ namespace FGSwiftBus
std::vector<IDispatchable*> m_dispatchList;
};
}
} // namespace FGSwiftBus
#endif

View file

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

View file

@ -23,16 +23,14 @@
#include <dbus/dbus.h>
#include <string>
namespace FGSwiftBus
{
namespace FGSwiftBus {
//! DBus error
class CDBusError
{
public:
//! Error type
enum ErrorType
{
enum ErrorType {
NoError,
Other
};
@ -52,6 +50,6 @@ namespace FGSwiftBus
std::string m_message;
};
}
} // namespace FGSwiftBus
#endif // guard

View file

@ -19,8 +19,7 @@
#include "dbusmessage.h"
namespace FGSwiftBus
{
namespace FGSwiftBus {
CDBusMessage::CDBusMessage(DBusMessage* message)
{
@ -133,8 +132,7 @@ namespace FGSwiftBus
{
DBusMessageIter arrayIterator;
dbus_message_iter_open_container(&m_messageIterator, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &arrayIterator);
for (const auto &i : array)
{
for (const auto& i : array) {
const char* ptr = i.c_str();
dbus_message_iter_append_basic(&arrayIterator, DBUS_TYPE_STRING, &ptr);
}
@ -160,8 +158,11 @@ namespace FGSwiftBus
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; }
if (v == TRUE) {
value = true;
} else {
value = false;
}
dbus_message_iter_next(&m_messageIterator);
}
@ -185,14 +186,12 @@ namespace FGSwiftBus
{
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do
{
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));
} while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
@ -201,15 +200,16 @@ namespace FGSwiftBus
if (dbus_message_iter_get_arg_type(&m_messageIterator) != DBUS_TYPE_ARRAY) { return; }
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do
{
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); }
if (b == TRUE) {
value.push_back(true);
} else {
value.push_back(false);
}
while (dbus_message_iter_next(&arrayIterator));
} while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
@ -217,14 +217,12 @@ namespace FGSwiftBus
{
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do
{
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));
} while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
@ -232,14 +230,12 @@ namespace FGSwiftBus
{
DBusMessageIter arrayIterator;
dbus_message_iter_recurse(&m_messageIterator, &arrayIterator);
do
{
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));
} while (dbus_message_iter_next(&arrayIterator));
dbus_message_iter_next(&m_messageIterator);
}
@ -260,4 +256,4 @@ namespace FGSwiftBus
return msg;
}
}
} // namespace FGSwiftBus

View file

@ -24,8 +24,7 @@
#include <string>
#include <vector>
namespace FGSwiftBus
{
namespace FGSwiftBus {
//! DBus Message
class CDBusMessage
@ -108,6 +107,6 @@ namespace FGSwiftBus
dbus_uint32_t m_serial = 0;
};
}
} // namespace FGSwiftBus
#endif // guard

View file

@ -20,10 +20,10 @@
#include "dbusobject.h"
#include <cassert>
namespace FGSwiftBus
{
namespace FGSwiftBus {
CDBusObject::CDBusObject()
{ }
{
}
CDBusObject::~CDBusObject()
{
@ -61,8 +61,7 @@ namespace FGSwiftBus
void CDBusObject::maybeSendEmptyDBusReply(bool wantsReply, const std::string& destination, dbus_uint32_t serial)
{
if (wantsReply)
{
if (wantsReply) {
CDBusMessage reply = CDBusMessage::createReply(destination, serial);
m_dbusConnection->sendMessage(reply);
}
@ -77,8 +76,7 @@ namespace FGSwiftBus
void CDBusObject::invokeQueuedDBusCalls()
{
std::lock_guard<std::mutex> lock(m_mutex);
while (m_qeuedDBusCalls.size() > 0)
{
while (m_qeuedDBusCalls.size() > 0) {
m_qeuedDBusCalls.front()();
m_qeuedDBusCalls.pop_front();
}
@ -103,4 +101,4 @@ namespace FGSwiftBus
return obj->dbusMessageHandler(dbusMessage);
}
}
} // namespace FGSwiftBus

View file

@ -21,11 +21,10 @@
#define BLACKSIM_FGSWIFTBUS_DBUSOBJECT_H
#include "dbusconnection.h"
#include <mutex>
#include <deque>
#include <mutex>
namespace FGSwiftBus
{
namespace FGSwiftBus {
//! DBus base object
class CDBusObject
{
@ -103,6 +102,6 @@ namespace FGSwiftBus
const DBusObjectPathVTable m_dbusObjectPathVTable = {dbusObjectPathUnregisterFunction, dbusObjectPathMessageFunction, nullptr, nullptr, nullptr, nullptr};
};
}
} // namespace FGSwiftBus
#endif // guard

View file

@ -19,15 +19,14 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "dbusserver.h"
#include "dbusobject.h"
#include "dbusserver.h"
#include <algorithm>
#include <cassert>
#include <memory>
namespace FGSwiftBus
{
namespace FGSwiftBus {
CDBusServer::CDBusServer()
{
@ -45,8 +44,7 @@ namespace FGSwiftBus
dbus_error_init(&error);
m_server.reset(dbus_server_listen(address.c_str(), &error));
if (! m_server)
{
if (!m_server) {
return false;
}
@ -98,4 +96,4 @@ namespace FGSwiftBus
obj->onNewConnection(server, conn);
}
}
} // namespace FGSwiftBus

View file

@ -20,21 +20,20 @@
#ifndef BLACKSIM_FGSWIFTBUS_DBUSSERVER_H
#define BLACKSIM_FGSWIFTBUS_DBUSSERVER_H
#include "dbusmessage.h"
#include "dbuserror.h"
#include "dbuscallbacks.h"
#include "dbusdispatcher.h"
#include "dbuserror.h"
#include "dbusmessage.h"
#include <event2/event.h>
#include <dbus/dbus.h>
#include <event2/event.h>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include <memory>
#include <functional>
namespace FGSwiftBus
{
namespace FGSwiftBus {
class CDBusObject;
@ -78,8 +77,7 @@ namespace FGSwiftBus
void onNewConnection(DBusServer* server, DBusConnection* conn);
static void onNewConnection(DBusServer* server, DBusConnection* conn, void* data);
struct DBusServerDeleter
{
struct DBusServerDeleter {
void operator()(DBusServer* obj) const { dbus_server_unref(obj); }
};
@ -89,6 +87,6 @@ namespace FGSwiftBus
NewConnectionFunc m_newConnectionFunc;
};
}
} // namespace FGSwiftBus
#endif // guard

View file

@ -23,17 +23,15 @@
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <cmath>
#include <functional>
#include <iostream>
#include <simgear/structure/commands.hxx>
#include <simgear/structure/event_mgr.hxx>
#include <thread>
namespace {
inline std::string fgswiftbusServiceName()
{
return std::string("org.swift-project.fgswiftbus");
return "org.swift-project.fgswiftbus";
}
} // namespace
@ -79,17 +77,6 @@ void CPlugin::startServer()
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()
{
this->m_dbusDispatcher.runOnce();

View file

@ -31,18 +31,16 @@
#define NOMINMAX
#endif
#include "config.h"
#include "dbusconnection.h"
#include "dbusdispatcher.h"
#include "dbusserver.h"
#include "config.h"
#include <memory>
#include <thread>
namespace FGSwiftBus
{
namespace FGSwiftBus {
class CService;
class CTraffic;
class CWeather;
/*!
* Main plugin class
@ -55,7 +53,6 @@ namespace FGSwiftBus
void startServer();
//! Destructor
~CPlugin();
static float startServerDeferred(float, float, int, void* refcon);
void fastLoop();
private:
@ -69,6 +66,6 @@ namespace FGSwiftBus
bool m_isRunning = false;
bool m_shouldStop = false;
};
}
} // namespace FGSwiftBus
#endif // guard
#endif // BLACKSIM_FGSWIFTBUS_PLUGIN_H

View file

@ -20,9 +20,9 @@
#include "service.h"
#include <Main/fg_props.hxx>
#include <iostream>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/commands.hxx>
#include <simgear/constants.h>
#define FGSWIFTBUS_API_VERSION 3;
@ -75,7 +75,8 @@ CService::CService()
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);
return s;
}

View file

@ -28,9 +28,8 @@
#include "dbusobject.h"
#include <chrono>
#include <string>
#include <Main/fg_props.hxx>
#include <chrono>
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/io/raw_socket.hxx>
@ -40,6 +39,7 @@
#include <simgear/structure/event_mgr.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/timing/timestamp.hxx>
#include <string>
//! \cond PRIVATE
@ -268,8 +268,6 @@ private:
SGPropertyNode_ptr m_yawRateNode;
SGPropertyNode_ptr m_com1VolumeNode;
SGPropertyNode_ptr m_com2VolumeNode;
};
} // namespace FGSwiftBus

View file

@ -24,15 +24,10 @@
#include "plugin.h"
#include "swift_connection.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/structure/commands.hxx>
#include <simgear/structure/event_mgr.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/timing/timestamp.hxx>
namespace {
inline std::string fgswiftbusServiceName()

View file

@ -22,8 +22,10 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include "traffic.h"
#include "SwiftAircraftManager.h"
#include <algorithm>
#include <iostream>
@ -205,8 +207,7 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
reply.appendArgument(verticalOffsets);
sendDBusMessage(reply);
});
} else if (message.getMethodName() == "getElevationAtPosition")
{
} else if (message.getMethodName() == "getElevationAtPosition") {
std::string callsign;
double latitudeDeg;
double longitudeDeg;
@ -216,8 +217,7 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
message.getArgument(latitudeDeg);
message.getArgument(longitudeDeg);
message.getArgument(altitudeMeters);
queueDBusCall([ = ]()
{
queueDBusCall([=]() {
SGGeod pos;
pos.setLatitudeDeg(latitudeDeg);
pos.setLongitudeDeg(longitudeDeg);
@ -229,8 +229,7 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
reply.appendArgument(elevation);
sendDBusMessage(reply);
});
} else if (message.getMethodName() == "setPlanesTransponders")
{
} else if (message.getMethodName() == "setPlanesTransponders") {
maybeSendEmptyDBusReply(wantsReply, sender, serial);
std::vector<std::string> callsigns;
std::vector<int> codes;
@ -243,16 +242,13 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
message.getArgument(idents);
std::vector<AircraftTransponder> transponders;
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));
}
queueDBusCall([ = ]()
{
queueDBusCall([=]() {
acm->setPlanesTransponders(transponders);
});
} else if (message.getMethodName() == "setPlanesSurfaces")
{
} else if (message.getMethodName() == "setPlanesSurfaces") {
maybeSendEmptyDBusReply(wantsReply, sender, serial);
std::vector<std::string> callsigns;
std::vector<double> gears;
@ -291,14 +287,12 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
message.getArgument(lightPatterns);
std::vector<AircraftSurfaces> surfaces;
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),
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));
}
queueDBusCall([ = ]()
{
queueDBusCall([=]() {
acm->setPlanesSurfaces(surfaces);
});
} else {

View file

@ -24,6 +24,7 @@
#include "SwiftAircraftManager.h"
#include "dbusobject.h"
#include <functional>
#include <utility>