source: nrEngine/include/EventActor.h @ 19

Revision 19, 4.2 KB checked in by art, 13 years ago (diff)
Line 
1/***************************************************************************
2 *                                                                         *
3 *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
4 *       mailto: <tevs@mpi-sb.mpg.de>                                      *
5 *                                                                         *
6 *   This program is free software; you can redistribute it and/or modify  *
7 *   it under the terms of the GNU General Public License as published by  *
8 *   the Free Software Foundation; either version 2 of the License, or     *
9 *   (at your option) any later version.                                   *
10 *                                                                         *
11 ***************************************************************************/
12
13
14#ifndef _NR_EVENT_ACTOR_H_
15#define _NR_EVENT_ACTOR_H_
16
17//----------------------------------------------------------------------------------
18// Includes
19//----------------------------------------------------------------------------------
20#include "Prerequisities.h"
21#include "Event.h"
22
23namespace nrEngine{
24
25
26        //! Event actors could acts as a server and client on event communication channels
27        /**
28         * \par
29         * EventActor is a class representing an actor working on the event messaging
30         * communication channel. An actor could recieve and send new events. It will
31         * be informed by the channel if there is new events available, so it can react
32         * on them. EventActor could also send new events to a connected channel, so
33         * it acts as a server on the communication.
34         *
35         * \par
36         * We do not want to separate event servers and clients like it does in a lot
37         * of event based messaging systems.
38         *
39         * \ingroup event
40        **/
41        class _NRExport EventActor{
42                public:
43
44                        //! Create new actor without any name (@see setName() )
45                        EventActor();
46                       
47                        //! Create a new actor within unique name
48                        EventActor(const std::string& name);
49
50                        //! Release used memory and disconnect the actor from the channel
51                        virtual ~EventActor();
52
53                        /**
54                         * Get the name of an actor. The name should be unique
55                         * to a certain channel. The communication channel will use the
56                         * names to access its database for actors.
57                         **/
58                        const std::string& getName() const;
59
60                        /**
61                         * Set name for this actor. You have to setup a name before you can
62                         * connect the actor to any communication channel.
63                         **/
64                        void setName(const std::string& name);
65                       
66                        /**
67                         * This is a function which will be called from the channel
68                         * if any new event arise. You have to check for the event types
69                         * derived by this function to do the job for the certain
70                         * type of events.
71                         *
72                         * @param channel Channel from where does this event occurs
73                         * @param event Smart pointer to an event object representing the message
74                         *
75                         **/
76                        virtual void OnEvent(const EventChannel& channel, SharedPtr<Event> event) = 0;
77
78                        /**
79                         * Send a message through all connected channels.
80                         *
81                         * @param event Message to be send
82                         **/
83                        Result emit(SharedPtr<Event> event);
84                       
85                        /**
86                         * Connect an actor to a certain channel.
87                         *
88                         * @param name Unique name of the channel to connect to.
89                         * @return either OK or an error from EVENT_ERROR-group
90                         **/
91                        Result connect (const std::string& name);
92
93                        /**
94                         * Disconnect this actor from a certain channel
95                         * @param name Unique name of the channel to disconnect
96                         **/
97                        Result disconnect(const std::string& name);
98
99                protected:
100
101                        //! Unique name of an actor in the channel
102                        std::string mName;
103
104                        //! The EventChannel is a friend so he is able to change default values
105                        friend class EventChannel;
106
107                        //! Here we store the all the channels we are connected to
108                        std::list<std::string> mChannel;
109
110                        //! EventManager which this actor belongs to
111                        //EventManager* mParentManager;
112
113                        //! Check whenever we are already connected to a channel
114                        bool isConnected (const std::string& name);
115
116                        /**
117                         * This function will be called from the channel, to notice the actor,
118                         * that he is got now a new connection.
119                         **/
120                        void _noticeConnected(EventChannel* channel);
121
122                        /**
123                         * Notice an actor that he is disconnected now.
124                         **/
125                        void _noticeDisconnected(EventChannel* channel);
126
127        };
128
129}; // end namespace
130
131#endif
Note: See TracBrowser for help on using the repository browser.