ScriptConnector.cpp

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 #include "ScriptConnector.h"
00014 #include "events/EngineEvent.h"
00015 #include "ScriptEngine.h"
00016 #include "Engine.h"
00017 
00018 namespace nrEngine{
00019 
00020         //----------------------------------------------------------------------
00021         ScriptConnector::ScriptConnector(const std::string& name) : EventActor(name + "_EventListener")
00022         {
00023                 connect(NR_DEFAULT_EVENT_CHANNEL);
00024         }
00025 
00026         //----------------------------------------------------------------------
00027         void ScriptConnector::initialize()
00028         {
00029                 uint32 count = Engine::sScriptEngine()->getFunctionCount();
00030                 for (uint32 i = 0; i < count; i++)
00031                 {
00032                         ScriptFunctor functor;
00033                         const std::string& name = Engine::sScriptEngine()->getFunction(i, functor);
00034                         OnRegisterFunction(name, functor);
00035                 }
00036         }
00037 
00038         //----------------------------------------------------------------------
00039         ScriptConnector::~ScriptConnector()
00040         {
00041                 disconnect(NR_DEFAULT_EVENT_CHANNEL);
00042         }
00043         
00044         //----------------------------------------------------------------------
00045         void ScriptConnector::OnEvent(const EventChannel& channel, SharedPtr<Event> event)
00046         {
00047                 // check if we got a new function event
00048                 if (event->same_as<ScriptRegisterFunctionEvent>())
00049                 {
00050                         SharedPtr<ScriptRegisterFunctionEvent> ev = event_shared_cast<ScriptRegisterFunctionEvent>(event);
00051                         OnRegisterFunction(ev->getName(), ev->getFunctor());
00052                 }
00053 
00054                 // we got a remove function event
00055                 if (event->same_as<ScriptRemoveFunctionEvent>())
00056                 {
00057                         SharedPtr<ScriptRemoveFunctionEvent> ev = event_shared_cast<ScriptRemoveFunctionEvent>(event);
00058                         OnRemoveFunction(ev->getName());
00059                 }               
00060         }
00061 
00062 };

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