+ if (!myFlushActive)
+ return;
+ bool hasEventsToFlush = !myGroups.empty();
+ std::map<char*, std::shared_ptr<Events_Message> >::iterator aMyGroup;
+ for(aMyGroup = myGroups.find(theID.eventText());
+ aMyGroup != myGroups.end(); aMyGroup = myGroups.find(theID.eventText()))
+ { // really sends
+ bool aWasFlushed = myFlushed.find(theID.myID) != myFlushed.end();
+ if (!aWasFlushed)
+ myFlushed.insert(theID.myID);
+ std::shared_ptr<Events_Message> aGroup = aMyGroup->second;
+ myGroups.erase(aMyGroup);
+ send(aGroup, false);
+
+ if (!aWasFlushed) {
+ // TODO: Stabilization fix. Check later.
+ if(myFlushed.find(theID.myID) != myFlushed.end()) {
+ myFlushed.erase(myFlushed.find(theID.myID));
+ }
+#ifdef _DEBUG
+ else {
+ bool aProblem = true;
+ }
+#endif
+ }
+ // send accumulated messages to "groupListeners"
+ std::map<char*, std::map<void*, std::list<Events_Listener*> > >::iterator aFindID =
+ myListeners.find(theID.eventText());
+ if (aFindID != myListeners.end()) {
+ std::map<void*, std::list<Events_Listener*> >::iterator aFindSender =
+ aFindID->second.begin();
+ for(; aFindSender != aFindID->second.end(); aFindSender++) {
+ std::list<Events_Listener*>::iterator aListener = aFindSender->second.begin();
+ for(; aListener != aFindSender->second.end(); aListener++) {
+ if ((*aListener)->groupMessages()) {
+ (*aListener)->flushGrouped(theID);
+ }
+ }
+ }
+ }
+ }
+ if (hasEventsToFlush && myGroups.empty() && myFlushed.empty()) {
+ // no more messages left in the queue, so, finalize the sketch processing
+ static Events_ID anID = Events_Loop::eventByName("SketchPrepared");
+ std::shared_ptr<Events_Message> aMsg(new Events_Message(anID, this));
+ Events_Loop::loop()->send(aMsg, false);
+ }
+}
+
+void Events_Loop::eraseMessages(const Events_ID& theID)
+{
+ std::map<char*, std::shared_ptr<Events_Message> >::iterator aMyGroup =