Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / Events / Events_Message.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef Events_Message_H_
22 #define Events_Message_H_
23
24 #include <Events.h>
25
26 /**\class Events_ID
27  * \ingroup EventsLoop
28  * \brief Identifier of the event kind.
29  *
30  * Each event ID is created in main Envent_Loop class
31  * that stores correspondence between the string-name of the
32  * identifier and the pointer to the static string that is really
33  * used as an identifier (this is useful for debugging of the events
34  * with log files and in debugger).
35  */
36 class EVENTS_EXPORT Events_ID
37 {
38   /// pointer to the text-identifier of the event, unique pointer for all events of such type
39   char* myID;
40
41   Events_ID(char* theID)
42   {
43     myID = theID;
44   }
45
46   friend class Events_Loop;
47  public:
48   /// Returns the text-identifier of the event (for debugging reasons)
49   char* eventText() const
50   {
51     return myID;
52   }
53   /// Allows to compare identifiers
54   bool operator==(const Events_ID& theID) const
55   {
56     return myID == theID.myID;
57   }
58 };
59
60 /**\class Events_Message
61  * \ingroup EventsLoop
62  * \brief Message for communication between sender and listener of event.
63  * Normally it is inherited by the higher-level 
64  */
65 class EVENTS_EXPORT Events_Message
66 {
67   Events_ID myEventsId;  ///< identifier of the event
68   void* mySender;  ///< the sender object
69
70  public:
71
72   //! Creates the message
73   Events_Message(const Events_ID theID, const void* theSender = 0)
74       : myEventsId(theID),
75         mySender((void*) theSender)
76   {
77   }
78   //! do nothing in the destructor yet
79   virtual ~Events_Message()
80   {
81   }
82
83   //! Returns identifier of the message
84   const Events_ID& eventID() const
85   {
86     return myEventsId;
87   }
88
89   //! Returns sender of the message or NULL if it is anonymous message
90   void* sender() const
91   {
92     return mySender;
93   }
94 };
95
96 #endif