[Orxonox-commit 5855] r10515 - code/branches/core7/src/libraries/core/singleton

landauf at orxonox.net landauf at orxonox.net
Sun May 31 10:26:39 CEST 2015


Author: landauf
Date: 2015-05-31 10:26:39 +0200 (Sun, 31 May 2015)
New Revision: 10515

Modified:
   code/branches/core7/src/libraries/core/singleton/ScopeManager.cc
   code/branches/core7/src/libraries/core/singleton/ScopeManager.h
Log:
if the scope is already active when a scopelistener is registered, activate it immediately. the same logic applies on removals.

Modified: code/branches/core7/src/libraries/core/singleton/ScopeManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopeManager.cc	2015-05-31 08:22:59 UTC (rev 10514)
+++ code/branches/core7/src/libraries/core/singleton/ScopeManager.cc	2015-05-31 08:26:39 UTC (rev 10515)
@@ -63,10 +63,14 @@
     void ScopeManager::addListener(ScopeListener* listener, ScopeID::Value scope)
     {
         this->listeners_[scope].insert(listener);
+        if (this->isActive(scope))
+            this->activateListener(listener);
     }
 
     void ScopeManager::removeListener(ScopeListener* listener, ScopeID::Value scope)
     {
+        if (this->isActive(scope))
+            this->deactivateListener(listener);
         this->listeners_[scope].erase(listener);
     }
 
@@ -79,8 +83,7 @@
     void ScopeManager::deactivateListenersForScope(ScopeID::Value scope)
     {
         for (typename std::set<ScopeListener*>::iterator it = this->listeners_[scope].begin(); it != this->listeners_[scope].end(); ++it)
-            if ((*it)->bActivated_)
-                this->deactivateListener(*it);
+            this->deactivateListener(*it);
     }
 
     void ScopeManager::activateListener(ScopeListener* listener)
@@ -91,10 +94,13 @@
 
     void ScopeManager::deactivateListener(ScopeListener* listener)
     {
-        try
-            { listener->deactivated(); }
-        catch (...)
-            { orxout(internal_warning) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << endl; }
-        listener->bActivated_ = false;
+        if (listener->bActivated_)
+        {
+            try
+                { listener->deactivated(); }
+            catch (...)
+                { orxout(internal_warning) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << endl; }
+            listener->bActivated_ = false;
+        }
     }
 }

Modified: code/branches/core7/src/libraries/core/singleton/ScopeManager.h
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopeManager.h	2015-05-31 08:22:59 UTC (rev 10514)
+++ code/branches/core7/src/libraries/core/singleton/ScopeManager.h	2015-05-31 08:26:39 UTC (rev 10515)
@@ -63,9 +63,9 @@
             /** Returns true if this scope is active */
             bool isActive(ScopeID::Value scope);
 
-            /** Registers a listener for the given scope. */
+            /** Registers a listener for the given scope. If the scope is already active, the listener is activate immediately. */
             void addListener(ScopeListener* listener, ScopeID::Value scope);
-            /** Unregisters a listener for the given scope. */
+            /** Unregisters a listener for the given scope. If the scope is still active, the listener is deactivated before removal. */
             void removeListener(ScopeListener* listener, ScopeID::Value scope);
 
         private:




More information about the Orxonox-commit mailing list