SHAPER  9.12.0
Events_Loop.h
1 // Copyright (C) 2014-2023 CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef Events_Loop_H_
21 #define Events_Loop_H_
22 
23 #include <Events_Message.h>
24 #include <Events_Listener.h>
25 
26 #include <map>
27 #include <set>
28 #include <list>
29 
31 
43 {
45  std::map<char*, std::map<void*, std::list<Events_Listener*> > > myListeners;
46 
48  std::map<char*, Events_Listener*> myImmediateListeners;
49 
51  std::map<char*, std::shared_ptr<Events_Message> > myGroups;
52 
54  std::set<char*> myFlushed;
55 
57  bool myFlushActive;
58 
60  Events_Loop() : myFlushActive(true) {}
61 
62  public:
64  EVENTS_EXPORT static Events_Loop* loop();
67  EVENTS_EXPORT static Events_ID eventByName(const char* theName);
68 
72  EVENTS_EXPORT void send(const std::shared_ptr<Events_Message>& theMessage, bool isGroup = true);
73 
80  EVENTS_EXPORT void registerListener(Events_Listener* theListener, const Events_ID theID,
81  void* theSender = 0, bool theImmediate = false);
82 
85  EVENTS_EXPORT void removeListener(Events_Listener* theListener);
86 
88  EVENTS_EXPORT void flush(const Events_ID& theID);
89 
91  EVENTS_EXPORT void eraseMessages(const Events_ID& theID);
92 
97  EVENTS_EXPORT bool activateFlushes(const bool theActivate);
98 
100  EVENTS_EXPORT void clear(const Events_ID& theID);
101 
103  EVENTS_EXPORT bool isFlushed(const Events_ID& theID);
105  EVENTS_EXPORT void setFlushed(const Events_ID& theID, const bool theValue);
106 
108  EVENTS_EXPORT bool hasGrouppedEvent(const Events_ID& theID);
109 
110 private:
113  void sendProcessEvent(const std::shared_ptr<Events_Message>& theMessage,
114  std::list<Events_Listener*>& theListeners, const bool theFlushedNow);
115 
116 };
117 
118 #endif
Identifier of the event kind.
Definition: Events_Message.h:36
Base interface for any event listener.
Definition: Events_Listener.h:37
Base class that manages the receiving and sending of all not Qt-events in the application.
Definition: Events_Loop.h:43
EVENTS_EXPORT bool activateFlushes(const bool theActivate)
Allows to disable flushes: needed in synchronization of document mechanism (to synchronize all and on...
Definition: Events_Loop.cpp:244
EVENTS_EXPORT bool hasGrouppedEvent(const Events_ID &theID)
Returns true if a loop accumulated events to be flashed.
Definition: Events_Loop.cpp:273
EVENTS_EXPORT void setFlushed(const Events_ID &theID, const bool theValue)
Sets the flag that the event is flished right now.
Definition: Events_Loop.cpp:265
EVENTS_EXPORT void flush(const Events_ID &theID)
Initializes sending of a group-message by the given ID.
Definition: Events_Loop.cpp:183
EVENTS_EXPORT void removeListener(Events_Listener *theListener)
Remove the listener from internal maps if it was registered there.
Definition: Events_Loop.cpp:136
static EVENTS_EXPORT Events_Loop * loop()
! Returns the main object of the loop, one per application.
Definition: Events_Loop.cpp:26
EVENTS_EXPORT void send(const std::shared_ptr< Events_Message > &theMessage, bool isGroup=true)
Allows to send an event.
Definition: Events_Loop.cpp:66
EVENTS_EXPORT void registerListener(Events_Listener *theListener, const Events_ID theID, void *theSender=0, bool theImmediate=false)
Registers (or adds if such listener is already registered) a listener that will be called on the even...
Definition: Events_Loop.cpp:107
EVENTS_EXPORT bool isFlushed(const Events_ID &theID)
Returns true if the evement is flushed right now.
Definition: Events_Loop.cpp:260
static EVENTS_EXPORT Events_ID eventByName(const char *theName)
Returns the unique event by the given name.
Definition: Events_Loop.cpp:33
EVENTS_EXPORT void eraseMessages(const Events_ID &theID)
Removes messages with the given ID: they are not needed anymore (UPDATE on close)
Definition: Events_Loop.cpp:234
EVENTS_EXPORT void clear(const Events_ID &theID)
Clears all collected messages.
Definition: Events_Loop.cpp:251
Message that allows to group messages and send them later as a group of messages.
Definition: Events_MessageGroup.h:34