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_ENGINE_EVENT__H_ 00015 #define _NR_ENGINE_EVENT__H_ 00016 00017 //---------------------------------------------------------------------------------- 00018 // Includes 00019 //---------------------------------------------------------------------------------- 00020 #include "../Prerequisities.h" 00021 #include "../Event.h" 00022 #include "ScriptEngine.h" 00023 00024 /*! 00025 * \defgroup sysevent System events 00026 * 00027 * This group represents all system events used in the engine. 00028 * The events are send trough the default engine's communication 00029 * channel. Very important events will be send on every channel, so 00030 * user application get noticed about them. 00031 * 00032 * The event interface is usefull for appropriate work of the engine. 00033 * All events are handled in the background fully transparent to the user, 00034 * so you do not have to care about them. 00035 * 00036 * Some of the events could only be created by the system, so normal 00037 * application is not allowed to send messages of this type. This is done 00038 * by declaring the event constructor as protected/private, so only friend 00039 * classes can create such events. You as normal user either don't need them or 00040 * uncontrolled sending of them could cause system damage. However you are able 00041 * to recieve the messages sended by the engine, if you need them this is another 00042 * question ;-) 00043 * 00044 **/ 00045 00046 namespace nrEngine{ 00047 00048 //! Base event class for scripting engine events 00049 /** 00050 * This is a base class for all type of events sended by the script 00051 * engine. 00052 * \ingroup sysevent 00053 **/ 00054 class _NRExport ScriptEvent : public Event { 00055 00056 META_Event(ScriptEvent) 00057 00058 protected: 00059 00060 /** 00061 * Protect the constructor, so only friend can emit this events. 00062 **/ 00063 ScriptEvent(Priority prior = Priority::IMMEDIATE) : Event(prior) {} 00064 00065 private: 00066 friend class ScriptEngine; 00067 00068 }; 00069 00070 00071 //! Send this event by registering of a new function in the script engine 00072 /** 00073 * Listen on this event if you want to be informed when some engine's component 00074 * or your application does register a new function in the ScriptEngine. This is 00075 * important if you implement your own glue code for any scripting language. 00076 * If you get this event you know that you know have to provide the function 00077 * with the given name in your scripting language. This can be done by 00078 * calling ScriptEngine::call() method with the given function name and function 00079 * arguments. 00080 * 00081 * \ingroup sysevent 00082 **/ 00083 class _NRExport ScriptRegisterFunctionEvent : public ScriptEvent { 00084 00085 META_Event(ScriptRegisterFunctionEvent) 00086 00087 public: 00088 //! Get the function name which has been registered 00089 const std::string& getName() const { return mName; } 00090 00091 //! Get the functor for this event 00092 ScriptFunctor getFunctor() { return mFunctor; } 00093 00094 private: 00095 friend class ScriptEngine; 00096 00097 ScriptRegisterFunctionEvent(const std::string& name, const ScriptFunctor& func) : ScriptEvent() 00098 { 00099 this->mName = name; 00100 this->mFunctor = func; 00101 } 00102 00103 //! Functor on the function 00104 ScriptFunctor mFunctor; 00105 00106 //! Function name 00107 std::string mName; 00108 }; 00109 00110 00111 //! Send this event by removing of a function from the script engine 00112 /** 00113 * Listen on this event if you want to know when a certain function is 00114 * removed from the ScriptEngie subsystem. 00115 * 00116 * \ingroup sysevent 00117 **/ 00118 class _NRExport ScriptRemoveFunctionEvent : public ScriptEvent { 00119 00120 META_Event (ScriptRemoveFunctionEvent) 00121 00122 public: 00123 //! Get the function name which has been registered 00124 const std::string& getName() const { return mName; } 00125 00126 private: 00127 friend class ScriptEngine; 00128 00129 ScriptRemoveFunctionEvent(const std::string& name) : ScriptEvent() 00130 { 00131 this->mName = name; 00132 } 00133 00134 //! Function name 00135 std::string mName; 00136 }; 00137 00138 }; 00139 00140 #endif