[Orxonox-commit 5878] r10538 - in code/branches/core7/src/libraries/core: . singleton

landauf at orxonox.net landauf at orxonox.net
Sun Jun 7 11:57:31 CEST 2015


Author: landauf
Date: 2015-06-07 11:57:31 +0200 (Sun, 07 Jun 2015)
New Revision: 10538

Modified:
   code/branches/core7/src/libraries/core/CoreStaticInitializationHandler.cc
   code/branches/core7/src/libraries/core/singleton/ScopeManager.cc
   code/branches/core7/src/libraries/core/singleton/ScopeManager.h
Log:
now that the order of initialization is well defined (first identifiers, then singletons) we can safely create singletons right after they are registered (and unload them again when they are unregistered). this reverts changes from r10517

Modified: code/branches/core7/src/libraries/core/CoreStaticInitializationHandler.cc
===================================================================
--- code/branches/core7/src/libraries/core/CoreStaticInitializationHandler.cc	2015-06-07 08:56:59 UTC (rev 10537)
+++ code/branches/core7/src/libraries/core/CoreStaticInitializationHandler.cc	2015-06-07 09:57:31 UTC (rev 10538)
@@ -30,7 +30,6 @@
 
 #include "module/ModuleInstance.h"
 #include "class/IdentifierManager.h"
-#include "singleton/ScopeManager.h"
 
 namespace orxonox
 {
@@ -64,7 +63,6 @@
     void CoreStaticInitializationHandler::initInstances(ModuleInstance* module)
     {
         IdentifierManager::getInstance().createClassHierarchy();
-        ScopeManager::getInstance().updateListeners();
     }
 
     void CoreStaticInitializationHandler::unloadModule(ModuleInstance* module)

Modified: code/branches/core7/src/libraries/core/singleton/ScopeManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopeManager.cc	2015-06-07 08:56:59 UTC (rev 10537)
+++ code/branches/core7/src/libraries/core/singleton/ScopeManager.cc	2015-06-07 09:57:31 UTC (rev 10538)
@@ -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 (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,31 +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;
-    }
-
-    void ScopeManager::updateListeners()
-    {
-        std::map<ScopeID::Value, std::set<ScopeListener*> >::iterator it1;
-        for (it1 = this->listeners_.begin(); it1 != this->listeners_.end(); ++it1)
+        if (listener->bActivated_)
         {
-            const ScopeID::Value& scope = it1->first;
-            const std::set<ScopeListener*>& listeners = it1->second;
-
-            bool scopeIsActive = this->isActive(scope);
-            for (std::set<ScopeListener*>::const_iterator it2 = listeners.begin(); it2 != listeners.end(); ++it2)
-            {
-                ScopeListener* listener = (*it2);
-
-                if (scopeIsActive && !listener->bActivated_)
-                    this->activateListener(listener);
-                else if (!scopeIsActive && listener->bActivated_)
-                    this->deactivateListener(listener);
-            }
+            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-06-07 08:56:59 UTC (rev 10537)
+++ code/branches/core7/src/libraries/core/singleton/ScopeManager.h	2015-06-07 09:57:31 UTC (rev 10538)
@@ -63,17 +63,11 @@
             /** 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);
 
-            /**
-             * Checks for all listeners if their activity matches the activity of the scope.
-             * If not, listeners are activated or deactivated depending on their state.
-             */
-            void updateListeners();
-
         private:
             void activateListenersForScope(ScopeID::Value scope);
             void deactivateListenersForScope(ScopeID::Value scope);




More information about the Orxonox-commit mailing list