Browse Source

cleanup internal structures as soon as the controller is disconnected

Sven Czarnian 3 years ago
parent
commit
ef91a3badd
2 changed files with 18 additions and 0 deletions
  1. 17 0
      src/PlugIn.cpp
  2. 1 0
      src/PlugIn.h

+ 17 - 0
src/PlugIn.cpp

@@ -56,6 +56,7 @@ PlugIn::PlugIn() :
         m_inbounds(),
         m_forcedToBackendCallsigns(),
         m_compatible(false),
+        m_connectedToNetwork(false),
         m_sweatboxValid(false),
         m_playbackValid(false) {
     GOOGLE_PROTOBUF_VERIFY_VERSION;
@@ -655,6 +656,22 @@ void PlugIn::updateSequence(std::shared_ptr<aman::AircraftSequence>& sequence) {
 }
 
 void PlugIn::OnTimer(int counter) {
+    /* cleanup the internal data */
+    if (EuroScopePlugIn::CONNECTION_TYPE_NO == this->GetConnectionType()) {
+        if (true == this->m_connectedToNetwork) {
+            std::lock_guard guardUpdate(this->m_updateQueueLock);
+            this->m_updateQueue.clear();
+
+            std::lock_guard guardInbound(this->m_inboundsQueueLock);
+            this->m_inbounds.clear();
+
+            this->m_connectedToNetwork = false;
+        }
+
+        return;
+    }
+
+    this->m_connectedToNetwork = true;
     if (false == this->m_compatible || false == Backend::instance().initialized() || 0 != (counter % 10))
         return;
 

+ 1 - 0
src/PlugIn.h

@@ -61,6 +61,7 @@ namespace aman {
         std::map<std::string, Inbound>                m_inbounds;
         std::list<std::string>                        m_forcedToBackendCallsigns;
         bool                                          m_compatible;
+        bool                                          m_connectedToNetwork;
         bool                                          m_sweatboxValid;
         bool                                          m_playbackValid;