Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 31, 2015, 10:26:39 AM (9 years ago)
Author:
landauf
Message:

if the scope is already active when a scopelistener is registered, activate it immediately. the same logic applies on removals.

Location:
code/branches/core7/src/libraries/core/singleton
Files:
2 edited

Legend:

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

    r10514 r10515  
    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 (typename 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;
     97        if (listener->bActivated_)
     98        {
     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;
     104        }
    99105    }
    100106}
  • code/branches/core7/src/libraries/core/singleton/ScopeManager.h

    r10514 r10515  
    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);
    7070
Note: See TracChangeset for help on using the changeset viewer.