Salome HOME
Auto-formatting according to the defined code standard.
[modules/shaper.git] / src / Event / Event_Loop.hxx
1 // File:        Event_Loop.hxx
2 // Created:     Thu Mar 13 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef Event_Loop_HeaderFile
6 #define Event_Loop_HeaderFile
7
8 #include <Event_Message.hxx>
9 #include <Event_Listener.hxx>
10
11 #include <map>
12 #include <list>
13
14 /**\class Event_Lopp
15  * \ingroup EventLoop
16  * \brief Base class that manages the receiving and sending of all
17  * not Qt-events in the application.
18  *
19  * One per application, initialized on start. Listeners must register in this loop
20  * to get events, called by senders. Sending of events is very fast (just adding to container).
21  * Performing of events is processed in separated thread, so, sender takes 
22  * control back immideately.
23  */
24 class Event_Loop
25 {
26   std::map<char*, std::map<void*, std::list<Event_Listener*> > > myListeners; ///< map from event ID to sender pointer to listeners that must be called for this
27
28   //! The empty constructor, will be called at startup of the application, only once
29   Event_Loop()
30   {
31   }
32   ;
33 public:
34   ///! Returns the main object of the loop, one per application.
35   EVENT_EXPORT static Event_Loop* Loop();
36   //! Returns the unique event by the given name. Call this method only on initialization of object
37   //! to speedup the events processing without parsing of the string.
38   EVENT_EXPORT static Event_ID EventByName(const char* theName);
39
40   //! Allows to send an event
41   EVENT_EXPORT void Send(Event_Message& theMessage);
42
43   //! Registers (or adds if such listener is already registered) a listener 
44   //! that will be called on the event and from the defined sender
45   EVENT_EXPORT void RegisterListener(Event_Listener* theListener, const Event_ID theID,
46                                      void* theSender = 0);
47 };
48
49 #endif