source: nrEngine/include/EventActor.h @ 15

Revision 15, 4.0 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 a new actor within unique name
45                        EventActor(const std::string& name);
46
47                        //! Release used memory and disconnect the actor from the channel
48                        virtual ~EventActor();
49
50                        /**
51                         * Get the name of an actor. The name should be unique
52                         * to a certain channel. The communication channel will use the
53                         * names to access its database for actors.
54                         **/
55                        const std::string& getName() const;
56
57                        /**
58                         * This is a function which will be called from the channel
59                         * if any new event arise. You have to check for the event types
60                         * derived by this function to do the job for the certain
61                         * type of events.
62                         *
63                         * @param channel Channel from where does this event occurs
64                         * @param event Smart pointer to an event object representing the message
65                         *
66                         **/
67                        virtual void OnEvent(const EventChannel& channel, SharedPtr<Event> event) = 0;
68
69                        /**
70                         * Send a message through all connected channels.
71                         *
72                         * @param event Message to be send
73                         **/
74                        Result emit(SharedPtr<Event> event);
75                       
76                        /**
77                         * Connect an actor to a certain channel.
78                         *
79                         * @param name Unique name of the channel to connect to.
80                         * @return either OK or an error from EVENT_ERROR-group
81                         **/
82                        Result connect (const std::string& name);
83
84                        /**
85                         * Disconnect this actor from a certain channel
86                         * @param name Unique name of the channel to disconnect
87                         **/
88                        Result disconnect(const std::string& name);
89
90                protected:
91
92                        //! Unique name of an actor in the channel
93                        std::string mName;
94
95                        //! The EventChannel is a friend so he is able to change default values
96                        friend class EventChannel;
97
98                        //! Here we store the all the channels we are connected to
99                        std::list<std::string> mChannel;
100
101                        //! EventManager which this actor belongs to
102                        //EventManager* mParentManager;
103
104                        //! Check whenever we are already connected to a channel
105                        bool isConnected (const std::string& name);
106
107                        /**
108                         * This function will be called from the channel, to notice the actor,
109                         * that he is got now a new connection.
110                         **/
111                        void _noticeConnected(EventChannel* channel);
112
113                        /**
114                         * Notice an actor that he is disconnected now.
115                         **/
116                        void _noticeDisconnected(EventChannel* channel);
117
118        };
119
120}; // end namespace
121
122#endif
Note: See TracBrowser for help on using the repository browser.