Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10538


Ignore:
Timestamp:
Jun 7, 2015, 11:57:31 AM (9 years ago)
Author:
landauf
Message:

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

Location:
code/branches/core7/src/libraries/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/CoreStaticInitializationHandler.cc

    r10535 r10538  
    3131#include "module/ModuleInstance.h"
    3232#include "class/IdentifierManager.h"
    33 #include "singleton/ScopeManager.h"
    3433
    3534namespace orxonox
     
    6564    {
    6665        IdentifierManager::getInstance().createClassHierarchy();
    67         ScopeManager::getInstance().updateListeners();
    6866    }
    6967
  • code/branches/core7/src/libraries/core/singleton/ScopeManager.cc

    r10517 r10538  
    6464    {
    6565        this->listeners_[scope].insert(listener);
     66        if (this->isActive(scope))
     67            this->activateListener(listener);
    6668    }
    6769
    6870    void ScopeManager::removeListener(ScopeListener* listener, ScopeID::Value scope)
    6971    {
     72        if (this->isActive(scope))
     73            this->deactivateListener(listener);
    7074        this->listeners_[scope].erase(listener);
    7175    }
     
    8084    {
    8185        for (std::set<ScopeListener*>::iterator it = this->listeners_[scope].begin(); it != this->listeners_[scope].end(); ++it)
    82             if ((*it)->bActivated_)
    83                 this->deactivateListener(*it);
     86            this->deactivateListener(*it);
    8487    }
    8588
     
    9295    void ScopeManager::deactivateListener(ScopeListener* listener)
    9396    {
    94         try
    95             { listener->deactivated(); }
    96         catch (...)
    97             { orxout(internal_warning) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << endl; }
    98         listener->bActivated_ = false;
    99     }
    100 
    101     void ScopeManager::updateListeners()
    102     {
    103         std::map<ScopeID::Value, std::set<ScopeListener*> >::iterator it1;
    104         for (it1 = this->listeners_.begin(); it1 != this->listeners_.end(); ++it1)
     97        if (listener->bActivated_)
    10598        {
    106             const ScopeID::Value& scope = it1->first;
    107             const std::set<ScopeListener*>& listeners = it1->second;
    108 
    109             bool scopeIsActive = this->isActive(scope);
    110             for (std::set<ScopeListener*>::const_iterator it2 = listeners.begin(); it2 != listeners.end(); ++it2)
    111             {
    112                 ScopeListener* listener = (*it2);
    113 
    114                 if (scopeIsActive && !listener->bActivated_)
    115                     this->activateListener(listener);
    116                 else if (!scopeIsActive && listener->bActivated_)
    117                     this->deactivateListener(listener);
    118             }
     99            try
     100                { listener->deactivated(); }
     101            catch (...)
     102                { orxout(internal_warning) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << endl; }
     103            listener->bActivated_ = false;
    119104        }
    120105    }
  • code/branches/core7/src/libraries/core/singleton/ScopeManager.h

    r10517 r10538  
    6464            bool isActive(ScopeID::Value scope);
    6565
    66             /** Registers a listener for the given scope. */
     66            /** Registers a listener for the given scope. If the scope is already active, the listener is activate immediately. */
    6767            void addListener(ScopeListener* listener, ScopeID::Value scope);
    68             /** Unregisters a listener for the given scope. */
     68            /** Unregisters a listener for the given scope. If the scope is still active, the listener is deactivated before removal. */
    6969            void removeListener(ScopeListener* listener, ScopeID::Value scope);
    70 
    71             /**
    72              * Checks for all listeners if their activity matches the activity of the scope.
    73              * If not, listeners are activated or deactivated depending on their state.
    74              */
    75             void updateListeners();
    7670
    7771        private:
Note: See TracChangeset for help on using the changeset viewer.