Salome HOME
Meet the coding style (line length <= 100)
[modules/shaper.git] / src / Events / Events_Listener.h
index f59bbd2f9d36de78f3cbb9839b06a3d20c889eaf..74aac548334feda5a60f33c7e95b84c2f9dd626d 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:       Events_Listener.hxx
 // Created:    Thu Mar 13 2014
 // Author:     Mikhail PONIKAROV
@@ -6,9 +8,11 @@
 #define Events_Listener_H_
 
 #include <Events.h>
-#include <boost/shared_ptr.hpp>
+#include <memory>
+#include <map>
 
 class Events_Message;
+class Events_ID;
 
 /**\class Events_Listener
  * \ingroup EventsLoop
@@ -17,12 +21,26 @@ class Events_Message;
  * If some object wants to listen some events it must inherit
  * this class and register in the Loop.
  */
-class EVENTS_EXPORT Events_Listener
-{
+class Events_Listener {
+  /// map from event ID to groupped messages (for flush for groupMessages=true listeners)
+  std::map<char*, std::shared_ptr<Events_Message> > myGroups;
 
  public:
   //! This method is called by loop when the event is started to process.
-  virtual void processEvent(const boost::shared_ptr<Events_Message>& theMessage) = 0;
+  EVENTS_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage) = 0;
+
+  //! Listener that needs mostly grouped messages received returns true in this method.
+  //! In this case during the message is flushed, all the new messages are grouped, not sended
+  //! immideately and then sent in the end of flush.
+  EVENTS_EXPORT virtual bool groupMessages() {return false;}
+
+protected:
+  //! Allows to group messages while they are flushed (for flush for groupMessages=true listeners)
+  void groupWhileFlush(const std::shared_ptr<Events_Message>& theMessage);
+  //! Sends myGroups on flush finish
+  EVENTS_EXPORT void flushGrouped(const Events_ID& theID);
+
+  friend class Events_Loop;
 };
 
 #endif