From 91263fc873c103ed8c9e2de6c62c80621b0e1b10 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Mon, 11 May 2020 09:37:26 +0200 Subject: [PATCH] [swift] Initialize/cleanup traffic module correctly --- src/Network/Swift/SwiftAircraftManager.cpp | 14 ++++++++++++-- src/Network/Swift/SwiftAircraftManager.h | 3 +++ src/Network/Swift/traffic.cpp | 9 +++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Network/Swift/SwiftAircraftManager.cpp b/src/Network/Swift/SwiftAircraftManager.cpp index a2b65bd41..fc76dca61 100644 --- a/src/Network/Swift/SwiftAircraftManager.cpp +++ b/src/Network/Swift/SwiftAircraftManager.cpp @@ -22,10 +22,20 @@ #include FGSwiftAircraftManager::FGSwiftAircraftManager() -= default; +{ + m_initialized = true; +} FGSwiftAircraftManager::~FGSwiftAircraftManager() -= default; +{ + this->removeAllPlanes(); + m_initialized = false; +} + +bool FGSwiftAircraftManager::isInitialized() const +{ + return m_initialized; +} bool FGSwiftAircraftManager::addPlane(const std::string& callsign, const std::string& modelString) { diff --git a/src/Network/Swift/SwiftAircraftManager.h b/src/Network/Swift/SwiftAircraftManager.h index 6c4826a13..b11e63fb6 100644 --- a/src/Network/Swift/SwiftAircraftManager.h +++ b/src/Network/Swift/SwiftAircraftManager.h @@ -39,8 +39,11 @@ public: void removePlane(const std::string& callsign); void removeAllPlanes(); double getElevationAtPosition(const std::string &callsign, const SGGeod& pos) const; + bool isInitialized() const; private: std::unordered_map aircraftByCallsign; + bool m_initialized = false; + }; #endif \ No newline at end of file diff --git a/src/Network/Swift/traffic.cpp b/src/Network/Swift/traffic.cpp index 32c6ba6ab..8a86a549a 100644 --- a/src/Network/Swift/traffic.cpp +++ b/src/Network/Swift/traffic.cpp @@ -34,7 +34,6 @@ namespace FGSwiftBus { CTraffic::CTraffic() { - acm.reset(new FGSwiftAircraftManager()); SG_LOG(SG_NETWORK, SG_INFO, "FGSwiftBus Traffic started"); } @@ -58,7 +57,8 @@ const std::string& CTraffic::ObjectPath() bool CTraffic::initialize() { - return true; + acm.reset(new FGSwiftAircraftManager()); + return acm->isInitialized(); } void CTraffic::emitSimFrame() @@ -77,12 +77,13 @@ void CTraffic::emitPlaneAdded(const std::string& callsign) void CTraffic::cleanup() { - acm->removeAllPlanes(); + acm.reset(); } void CTraffic::dbusDisconnectedHandler() { - acm->removeAllPlanes(); + if(acm) + acm->removeAllPlanes(); } const char* introspection_traffic = DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE;