Salome HOME
updated copyright message
[modules/shaper.git] / src / Events / Events_Listener.h
index 5bac8dc8a8bf444330d716c3bd5f93f1fb5c36a2..907f1b0dcdeb44a0f65c266fa40c5ed6a6e6a075 100644 (file)
@@ -1,12 +1,31 @@
-// File:       Events_Listener.hxx
-// Created:    Thu Mar 13 2014
-// Author:     Mikhail PONIKAROV
+// Copyright (C) 2014-2023  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #ifndef Events_Listener_H_
 #define Events_Listener_H_
 
 #include <Events.h>
+#include <memory>
+#include <map>
+
 class Events_Message;
+class Events_ID;
 
 /**\class Events_Listener
  * \ingroup EventsLoop
@@ -15,11 +34,28 @@ 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:
+  virtual ~Events_Listener() {}
+
   //! This method is called by loop when the event is started to process.
-  virtual void processEvent(const 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