Salome HOME
Set wait cursor on long operations
[modules/shaper.git] / src / Events / Events_Loop.cpp
index 6c8bb476070ed381339cef59b6a08774678a1f95..40917a64f710c5b7d7c815fb3e8f62313ed0bd0d 100644 (file)
@@ -3,6 +3,7 @@
 // Author:     Mikhail PONIKAROV
 
 #include <Events_Loop.h>
+#include <Events_MessageGroup.h>
 
 #include <string>
 #include <cstring>
@@ -32,9 +33,24 @@ Events_ID Events_Loop::eventByName(const char* theName)
   return Events_ID(aResult);
 }
 
-void Events_Loop::send(Events_Message& theMessage)
+void Events_Loop::send(Events_Message& theMessage, bool isGroup)
 {
-  // TO DO: make it in thread and wit husage of semaphores
+  // if it is grouped message, just accumulate it
+  if (isGroup) {
+    Events_MessageGroup* aGroup = dynamic_cast<Events_MessageGroup*>(&theMessage);
+    if (aGroup) {
+      std::map<char*, Events_MessageGroup*>::iterator aMyGroup = 
+        myGroups.find(aGroup->eventID().eventText());
+      if (aMyGroup == myGroups.end()) { // create a new group of messages for accumulation
+        myGroups[aGroup->eventID().eventText()] = aGroup->newEmpty();
+        aMyGroup = myGroups.find(aGroup->eventID().eventText());
+      }
+      aMyGroup->second->Join(*aGroup);
+      return;
+    }
+  }
+
+  // TO DO: make it in thread and with usage of semaphores
 
   map<char*, map<void*, list<Events_Listener*> > >::iterator aFindID = myListeners.find(
       theMessage.eventID().eventText());
@@ -80,3 +96,15 @@ void Events_Loop::registerListener(Events_Listener* theListener, const Events_ID
 
   aListeners.push_back(theListener);
 }
+
+void Events_Loop::flush(const Events_ID& theID)
+{
+  std::map<char*, Events_MessageGroup*>::iterator aMyGroup = 
+    myGroups.find(theID.eventText());
+  if (aMyGroup != myGroups.end()) { // really sends
+    Events_MessageGroup* aGroup = aMyGroup->second;
+    myGroups.erase(aMyGroup);
+    send(*aGroup, false);
+    delete aGroup;
+  }
+}