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;