EventActor.h

00001 /***************************************************************************
00002  *                                                                         *
00003  *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
00004  *       mailto: <tevs@mpi-sb.mpg.de>                                      *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  ***************************************************************************/
00012 
00013 
00014 #ifndef _NR_EVENT_ACTOR_H_
00015 #define _NR_EVENT_ACTOR_H_
00016 
00017 //----------------------------------------------------------------------------------
00018 // Includes
00019 //----------------------------------------------------------------------------------
00020 #include "Prerequisities.h"
00021 #include "Event.h"
00022 
00023 namespace nrEngine{
00024 
00025 
00026         //! Event actors could acts as a server and client on event communication channels
00027         /**
00028          * \par
00029          * EventActor is a class representing an actor working on the event messaging
00030          * communication channel. An actor could recieve and send new events. It will
00031          * be informed by the channel if there is new events available, so it can react
00032          * on them. EventActor could also send new events to a connected channel, so
00033          * it acts as a server on the communication.
00034          *
00035          * \par
00036          * We do not want to separate event servers and clients like it does in a lot
00037          * of event based messaging systems.
00038          *
00039          * \ingroup event
00040         **/
00041         class _NRExport EventActor{
00042                 public:
00043 
00044                         //! Create new actor without any name (@see setName() ) 
00045                         EventActor();
00046                         
00047                         //! Create a new actor within unique name
00048                         EventActor(const std::string& name);
00049 
00050                         //! Release used memory and disconnect the actor from the channel
00051                         virtual ~EventActor();
00052 
00053                         /**
00054                          * Get the name of an actor. The name should be unique
00055                          * to a certain channel. The communication channel will use the
00056                          * names to access its database for actors.
00057                          **/
00058                         const std::string& getName() const;
00059 
00060                         /**
00061                          * Set name for this actor. You have to setup a name before you can
00062                          * connect the actor to any communication channel.
00063                          **/
00064                         void setName(const std::string& name);
00065                         
00066                         /**
00067                          * This is a function which will be called from the channel
00068                          * if any new event arise. You have to check for the event types
00069                          * derived by this function to do the job for the certain
00070                          * type of events.
00071                          *
00072                          * @param channel Channel from where does this event occurs
00073                          * @param event Smart pointer to an event object representing the message
00074                          *
00075                          **/
00076                         virtual void OnEvent(const EventChannel& channel, SharedPtr<Event> event) = 0;
00077 
00078                         /**
00079                          * Send a message through all connected channels.
00080                          * 
00081                          * @param event Message to be send
00082                          **/
00083                         Result emit(SharedPtr<Event> event);
00084                         
00085                         /**
00086                          * Connect an actor to a certain channel.
00087                          *
00088                          * @param name Unique name of the channel to connect to.
00089                          * @return either OK or an error from EVENT_ERROR-group
00090                          **/
00091                         Result connect (const std::string& name);
00092 
00093                         /**
00094                          * Disconnect this actor from a certain channel
00095                          * @param name Unique name of the channel to disconnect
00096                          **/
00097                         Result disconnect(const std::string& name);
00098 
00099                 protected:
00100 
00101                         //! Unique name of an actor in the channel
00102                         std::string mName;
00103 
00104                         //! The EventChannel is a friend so he is able to change default values
00105                         friend class EventChannel;
00106 
00107                         //! Here we store the all the channels we are connected to
00108                         std::list<std::string> mChannel;
00109 
00110                         //! EventManager which this actor belongs to
00111                         //EventManager* mParentManager;
00112 
00113                         //! Check whenever we are already connected to a channel
00114                         bool isConnected (const std::string& name);
00115 
00116                         /**
00117                          * This function will be called from the channel, to notice the actor,
00118                          * that he is got now a new connection.
00119                          **/
00120                         void _noticeConnected(EventChannel* channel);
00121 
00122                         /**
00123                          * Notice an actor that he is disconnected now.
00124                          **/
00125                         void _noticeDisconnected(EventChannel* channel);
00126 
00127         };
00128 
00129 }; // end namespace
00130 
00131 #endif

Generated on Wed Sep 12 23:19:42 2007 for nrEngine by  doxygen 1.5.1