ScriptConnector.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_SCRIPT_CONNECTOR_H_
00015 #define _NR_SCRIPT_CONNECTOR_H_
00016 
00017 //----------------------------------------------------------------------------------
00018 // Includes
00019 //----------------------------------------------------------------------------------
00020 #include "Prerequisities.h"
00021 #include "EventActor.h"
00022 #include "ScriptEngine.h"
00023 
00024 namespace nrEngine{
00025 
00026 
00027         //! Script connectors are listening on script engine events and react on them
00028         /**
00029          * In our engine we do provide some default behaviour of how to access
00030          * registered engine's functions in your scripts. However if you implement
00031          * a new embedded scripting language you have somehow to bind the calling
00032          * of engine's provided function within your script. Only the functions which
00033          * are registered in ScriptEngine are for the public use within the engine.
00034          *
00035          * To connect your scripts with the functions you can ask scripting engine
00036          * for registered functions and somehow connect them. The other more elegant
00037          * way is to derive a class from this one. If any instance of this class
00038          * is created (done automaticaly by the constructors), so the class will act
00039          * as a event listener and wait for certain scripting engine events. If they
00040          * occurs it will call virtual functions overwriten by your class which handle
00041          * this events. In this way you just derive any new class from this one and
00042          * write a glue code to connect new functions (coming by events) within your
00043          * scripting language.
00044          * 
00045          * \ingroup script
00046         **/
00047         class _NRExport ScriptConnector : public EventActor{
00048                 public:
00049 
00050                         /**
00051                          * Remove the listener and release used memory
00052                          **/
00053                         virtual ~ScriptConnector();
00054 
00055                 protected:
00056 
00057                         /**
00058                          * Call this function to get noticed about all currently
00059                          * registered functions
00060                          * This function should be called from the constructor of derived class.
00061                          **/
00062                         void initialize();
00063 
00064                         /**
00065                          * Protected constructor, so you can only create instancies
00066                          * of this class in derived classes.
00067                          * The constructor will add itself as a listener on scripting evnets.
00068                          **/
00069                         ScriptConnector(const std::string& name);
00070 
00071                         /**
00072                          * React on events coming from the scripting engine
00073                          **/
00074                         void OnEvent(const EventChannel& channel, SharedPtr<Event> event);
00075 
00076                         /**
00077                          * New function was registered, so handle it
00078                          **/
00079                         virtual void OnRegisterFunction(const std::string& name, const ScriptFunctor& func) = 0;
00080                         
00081                         /**
00082                          * A function was removed from the database
00083                          **/
00084                         virtual void OnRemoveFunction(const std::string& name) = 0;
00085 
00086                         
00087         };
00088 
00089 
00090 };
00091 
00092 #endif

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