Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 6, 2009, 5:29:39 AM (15 years ago)
Author:
landauf
Message:

Using target= instead of name= to define the target-object in EventTarget. This avoids possible loops if more than one EventTarget point to the same object, because the other EventTarget becomes a target itself, passing the event back and forth.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/modules/objects/eventsystem/EventTarget.cc

    r5887 r5890  
    3838    {
    3939        RegisterObject(EventTarget);
     40
     41        this->bActive_ = false;
    4042    }
    4143
     
    4850        SUPER(EventTarget, XMLPort, xmlelement, mode);
    4951
     52        XMLPortParam(EventTarget, "target", setTargetName, getTargetName, xmlelement, mode);
     53
    5054        // since we need event sources mapped to any state, we have to parse XML by ourselves
    5155        this->loadAllEventStates(xmlelement, mode, this, Class(EventTarget));
     
    5458    void EventTarget::processEvent(Event& event)
    5559    {
     60        if (this->bActive_)
     61        {
     62            COUT(2) << "Warning: Detected Event loop in EventTarget \"" << this->getName() << "\"" << std::endl;
     63            return;
     64        }
     65
     66        this->bActive_ = true;
    5667        this->fireEvent(event);
     68        this->bActive_ = false;
    5769    }
    5870
    59     void EventTarget::changedName()
     71    void EventTarget::setTargetName(const std::string& name)
    6072    {
    61         SUPER(EventTarget, changedName);
    62 
     73        this->target_ = name;
     74       
    6375        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
    64             if (it->getName() == this->getName())
     76            if (it->getName() == this->target_)
    6577                this->addEventTarget(*it);
    6678    }
     
    6880    void EventTarget::loadedNewXMLName(BaseObject* object)
    6981    {
    70         if (this->getName() == "")
     82        if (this->target_ == "")
    7183            return;
    7284
    73         if (object->getName() == this->getName())
     85        if (object->getName() == this->target_)
    7486            this->addEventTarget(object);
    7587    }
Note: See TracChangeset for help on using the changeset viewer.