X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FEvents%2FEvents_Loop.cpp;h=013e0a02d6e9e0952e76a42db5da0c165b2046f9;hb=9c0937c3fce2633ae166b8a70fe43998f4babd1d;hp=b969741898d7840069eb08572de5ea7b4fd6e794;hpb=0edd45c3399c408340a033c8521ed2e3440e8375;p=modules%2Fshaper.git diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index b96974189..013e0a02d 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -10,8 +10,6 @@ #include #include -using namespace std; - Events_Loop* Events_Loop::loop() { // initialized on initialization of the application @@ -22,10 +20,10 @@ Events_Loop* Events_Loop::loop() Events_ID Events_Loop::eventByName(const char* theName) { ///! All events created in this session, uniquely identified by the text and char pointer - static map CREATED_EVENTS; + static std::map CREATED_EVENTS; char* aResult; - string aName(theName); - map::iterator aFound = CREATED_EVENTS.find(aName); + std::string aName(theName); + std::map::iterator aFound = CREATED_EVENTS.find(aName); if (aFound == CREATED_EVENTS.end()) { //not created yet #ifdef WIN32 aResult = _strdup(theName); // copy to make unique internal pointer @@ -39,14 +37,28 @@ Events_ID Events_Loop::eventByName(const char* theName) return Events_ID(aResult); } +void Events_Loop::sendProcessEvent(const std::shared_ptr& theMessage, + std::list& theListeners, const bool theFlushedNow) +{ + std::list::iterator aL = theListeners.begin(); + for (; aL != theListeners.end(); aL++) { + if (theFlushedNow && (*aL)->groupMessages()) { + (*aL)->groupWhileFlush(theMessage); + } else { + (*aL)->processEvent(theMessage); + } + } +} + void Events_Loop::send(const std::shared_ptr& theMessage, bool isGroup) { if (myImmediateListeners.find(theMessage->eventID().eventText()) != myImmediateListeners.end()) { myImmediateListeners[theMessage->eventID().eventText()]->processEvent(theMessage); } // if it is grouped message, just accumulate it - if (isGroup && myFlushed.find(theMessage->eventID().myID) == myFlushed.end()) { - std::shared_ptr aGroup = + bool isFlushedNow = myFlushed.find(theMessage->eventID().myID) != myFlushed.end(); + if (isGroup && !isFlushedNow) { + std::shared_ptr aGroup = std::dynamic_pointer_cast(theMessage); if (aGroup) { std::map >::iterator aMyGroup = myGroups.find( @@ -61,25 +73,19 @@ void Events_Loop::send(const std::shared_ptr& theMessage, bool i return; } } - - // TODO: make it in thread and with usage of semaphores - - map > >::iterator aFindID = myListeners.find( - theMessage->eventID().eventText()); + // send + std::map > >::iterator aFindID = + myListeners.find(theMessage->eventID().eventText()); if (aFindID != myListeners.end()) { - map >::iterator aFindSender = aFindID->second.find( + std::map >::iterator aFindSender = aFindID->second.find( theMessage->sender()); if (aFindSender != aFindID->second.end()) { - list& aListeners = aFindSender->second; - for (list::iterator aL = aListeners.begin(); aL != aListeners.end(); aL++) - (*aL)->processEvent(theMessage); + sendProcessEvent(theMessage, aFindSender->second, isFlushedNow && isGroup); } if (theMessage->sender()) { // also call for NULL senders registered aFindSender = aFindID->second.find(NULL); if (aFindSender != aFindID->second.end()) { - list& aListeners = aFindSender->second; - for (list::iterator aL = aListeners.begin(); aL != aListeners.end(); aL++) - (*aL)->processEvent(theMessage); + sendProcessEvent(theMessage, aFindSender->second, isFlushedNow && isGroup); } } } @@ -92,21 +98,22 @@ void Events_Loop::registerListener(Events_Listener* theListener, const Events_ID myImmediateListeners[theID.eventText()] = theListener; return; } - map > >::iterator aFindID = myListeners.find( - theID.eventText()); + std::map > >::iterator aFindID = + myListeners.find(theID.eventText()); if (aFindID == myListeners.end()) { // create container associated with ID - myListeners[theID.eventText()] = map >(); + myListeners[theID.eventText()] = std::map >(); aFindID = myListeners.find(theID.eventText()); } - map >::iterator aFindSender = aFindID->second.find(theSender); + std::map >::iterator aFindSender = + aFindID->second.find(theSender); if (aFindSender == aFindID->second.end()) { // create container associated with sender - aFindID->second[theSender] = list(); + aFindID->second[theSender] = std::list(); aFindSender = aFindID->second.find(theSender); } // check that listener was not registered wit hsuch parameters before - list& aListeners = aFindSender->second; - for (list::iterator aL = aListeners.begin(); aL != aListeners.end(); aL++) + std::list& aListeners = aFindSender->second; + for (std::list::iterator aL = aListeners.begin(); aL != aListeners.end(); aL++) if (*aL == theListener) return; // avoid duplicates @@ -175,11 +182,29 @@ void Events_Loop::flush(const Events_ID& theID) myGroups.erase(aMyGroup); send(aGroup, false); - if (!aWasFlushed) + if (!aWasFlushed) { // TODO: Stabilization fix. Check later. if(myFlushed.find(theID.myID) != myFlushed.end()) { myFlushed.erase(myFlushed.find(theID.myID)); + } else { + bool aProblem = true; + } + } + // send accumulated messages to "groupListeners" + std::map > >::iterator aFindID = + myListeners.find(theID.eventText()); + if (aFindID != myListeners.end()) { + std::map >::iterator aFindSender = + aFindID->second.begin(); + for(; aFindSender != aFindID->second.end(); aFindSender++) { + std::list::iterator aListener = aFindSender->second.begin(); + for(; aListener != aFindSender->second.end(); aListener++) { + if ((*aListener)->groupMessages()) { + (*aListener)->flushGrouped(theID); + } + } } + } } }