Salome HOME
Send groupped events in finishOperation() until they exist
[modules/shaper.git] / src / Events / Events_Loop.h
index cd78497ed1c67b0c7b3482d5964df9b49674572b..94122adbe03100e2d8bb37bb30b1ba58260f6250 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:       Events_Loop.hxx
 // Created:    Thu Mar 13 2014
 // Author:     Mikhail PONIKAROV
 #include <Events_Listener.h>
 
 #include <map>
+#include <set>
 #include <list>
 
 class Events_MessageGroup;
 
-/**\class Events_Lopp
+/**\class Events_Loop
  * \ingroup EventsLoop
  * \brief Base class that manages the receiving and sending of all
  * not Qt-events in the application.
@@ -28,8 +31,14 @@ class Events_Loop
   /// map from event ID to sender pointer to listeners that must be called for this
   std::map<char*, std::map<void*, std::list<Events_Listener*> > > myListeners;
 
-  /// map from event ID to groupped messages (accumulated on flush)
-  std::map<char*, Events_MessageGroup*> myGroups;
+  /// map from event ID to listeners which must process message without waiting for flush
+  std::map<char*, Events_Listener*> myImmediateListeners;
+
+  /// map from event ID to groupped messages (accumulated for flush)
+  std::map<char*, std::shared_ptr<Events_Message> > myGroups;
+
+  ///< set of messages that are flushed right now, so they are not grouped
+  std::set<char*> myFlushed;
 
   /// to process flushes or not
   bool myFlushActive;
@@ -45,20 +54,52 @@ class Events_Loop
   EVENTS_EXPORT static Events_ID eventByName(const char* theName);
 
   //! Allows to send an event
+  //! \param theMessage the enevt message to send
   //! \param isGroup is true for grouping messages if possible
-  EVENTS_EXPORT void send(Events_Message& theMessage, bool isGroup = true);
+  EVENTS_EXPORT void send(const std::shared_ptr<Events_Message>& theMessage, bool isGroup = true);
 
-  //! Registers (or adds if such listener is already registered) a listener 
+  //! Registers (or adds if such listener is already registered) a listener
   //! that will be called on the event and from the defined sender
+  //! \param theListener the object that will listen (process) the event
+  //! \param theID listen for messages with this ID
+  //! \param theSender listen only for this sender (NULL - listen everybody)
+  //! \param theImmediate for listeners who can not wait (no groupping mechanism is used for it)
   EVENTS_EXPORT void registerListener(Events_Listener* theListener, const Events_ID theID,
-                                      void* theSender = 0);
+    void* theSender = 0, bool theImmediate = false);
+
+  //! Remove the listener from internal maps if it was registered there
+  //! \param theListener a listener
+  EVENTS_EXPORT void removeListener(Events_Listener* theListener);
 
   //! Initializes sending of a group-message by the given ID
   EVENTS_EXPORT void flush(const Events_ID& theID);
 
-  //! Allows to disable flushes: needed in synchronization of document mechanism 
+  //! Removes messages with the given ID: they are not needed anymore (UPDATE on close)
+  EVENTS_EXPORT void eraseMessages(const Events_ID& theID);
+
+  //! Allows to disable flushes: needed in synchronization of document mechanism
   //! (to synchronize all and only then flush create, update, etc in correct order)
-  EVENTS_EXPORT void activateFlushes(const bool theActivate);
+  //! \param theActivate a state about flushe is active. If false, the flush is disabled
+  //! \return the previous active flush state
+  EVENTS_EXPORT bool activateFlushes(const bool theActivate);
+
+  //! Clears all collected messages
+  EVENTS_EXPORT void clear(const Events_ID& theID);
+
+  //! Returns true if the evement is flushed right now
+  EVENTS_EXPORT bool isFlushed(const Events_ID& theID);
+  //! Sets the flag that the event is flished right now
+  EVENTS_EXPORT void setFlushed(const Events_ID& theID, const bool theValue);
+
+  //! Returns true if a loop accumulated events to be flashed
+  EVENTS_EXPORT bool hasGrouppedEvent(const Events_ID& theID);
+
+private:
+  //! Calls "processEvent" for the given listeners.
+  //! If theFlushedNow for grouped listeners is stores message in listeners.
+  void sendProcessEvent(const std::shared_ptr<Events_Message>& theMessage,
+    std::list<Events_Listener*>& theListeners, const bool theFlushedNow);
+
 };
 
 #endif