1
0
Fork 0

[swift] Initialize/cleanup traffic module correctly

This commit is contained in:
Lars Toenning 2020-05-11 09:37:26 +02:00 committed by James Turner
parent 7b9940f1b1
commit 91263fc873
3 changed files with 20 additions and 6 deletions

View file

@ -22,10 +22,20 @@
#include <utility>
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)
{

View file

@ -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<std::string, FGAISwiftAircraft*> aircraftByCallsign;
bool m_initialized = false;
};
#endif

View file

@ -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;