ScriptingService.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jun 26 13:25:57 CEST 2006  ScriptingService.hpp
00003 
00004                         ScriptingService.hpp -  description
00005                            -------------------
00006     begin                : Mon June 26 2006
00007     copyright            : (C) 2006 Peter Soetens
00008     email                : peter.soetens@fmtc.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 
00039 #ifndef ORO_EXECUTION_SCRIPTING_ACCESS
00040 #define ORO_EXECUTION_SCRIPTING_ACCESS
00041 
00042 #include <vector>
00043 #include <map>
00044 #include <string>
00045 #include "rtt-scripting-config.h"
00046 #include "ProgramInterface.hpp"
00047 #include "StateMachine.hpp"
00048 #include "../Service.hpp"
00049 #include "ProgramExceptions.hpp"
00050 
00051 namespace RTT
00052 { namespace scripting {
00053 
00060     class RTT_SCRIPTING_API ScriptingService
00061         : public Service
00062     {
00063     public:
00064         typedef boost::shared_ptr<ScriptingService> shared_ptr;
00069         static shared_ptr Create(TaskContext* parent);
00070 
00076         ScriptingService( TaskContext* parent );
00077 
00078         virtual ~ScriptingService();
00079 
00080         typedef ProgramInterface::Status ProgramStatus;
00081         typedef scripting::StateMachine::Status StateMachineStatus;
00082 
00088         bool loadProgram( ProgramInterfacePtr pi );
00089 
00096         bool deleteProgram(const std::string& name);
00097 
00103         bool unloadProgram(const std::string& name);
00104 
00108         void clear();
00109 
00113         ProgramStatus::ProgramStatus getProgramStatus(const std::string& name) const;
00114 
00118         std::string getProgramStatusStr(const std::string& name) const;
00119 
00120 
00124         std::vector<std::string> getProgramList() const;
00125 
00129         const ProgramInterfacePtr getProgram(const std::string& name) const;
00130 
00131         ProgramInterfacePtr getProgram(const std::string& name);
00132 
00137         bool loadStateMachine( StateMachinePtr sc );
00138 
00144         bool unloadStateMachine( const std::string& name );
00145 
00152         bool deleteStateMachine( const std::string& name );
00153 
00157         StateMachineStatus::StateMachineStatus getStateMachineStatus(const std::string& name) const;
00158 
00162         std::string getStateMachineStatusStr(const std::string& name) const;
00163 
00167         std::vector<std::string> getStateMachineList() const;
00168 
00172         const StateMachinePtr getStateMachine(const std::string& name) const;
00173 
00177         StateMachinePtr getStateMachine(const std::string& name);
00178 
00189         int execute(const std::string& code );
00190 
00207         bool eval(const std::string& code );
00208 
00219         bool runScript( const std::string& filename);
00220 
00224         typedef std::vector< ProgramInterfacePtr > Functions;
00225 
00236         virtual Functions loadFunctions(const std::string& filename, bool do_throw );
00237 
00249         virtual Functions loadFunctions(const std::string& code, const std::string& filename, bool do_throw );
00250 
00262         virtual bool loadPrograms( const std::string& filename, bool do_throw );
00263 
00276         virtual bool loadPrograms( const std::string& code, const std::string& filename, bool do_throw  );
00277 
00287         virtual bool unloadProgram( const std::string& name, bool do_throw );
00288 
00299         virtual int getProgramLine(const std::string& name) const;
00300 
00308         virtual std::string getProgramText(const std::string& name ) const;
00309 
00321         virtual bool loadStateMachines( const std::string& filename, bool do_throw );
00322 
00335         virtual bool loadStateMachines( const std::string& code, const std::string& filename, bool do_throw );
00336 
00346         virtual bool unloadStateMachine( const std::string& name, bool do_throw );
00347 
00355         virtual std::string getStateMachineText(const std::string& name ) const;
00356 
00367         virtual int getStateMachineLine(const std::string& name ) const;
00368 
00377         bool startProgram(const std::string& name);
00378 
00383         bool stopProgram(const std::string& name);
00384 
00389         bool pauseProgram(const std::string& name);
00390 
00395         bool stepProgram(const std::string& name);
00411         virtual bool hasProgram(const std::string& name) const;
00412 
00420         bool isProgramRunning(const std::string& name) const;
00421 
00429         bool isProgramPaused(const std::string& name) const;
00430 
00438         bool inProgramError(const std::string& name) const;
00451         bool activateStateMachine(const std::string& name);
00452 
00457         bool deactivateStateMachine(const std::string& name);
00458 
00463         bool startStateMachine(const std::string& name);
00464 
00469         bool pauseStateMachine(const std::string& name);
00470 
00475         bool stopStateMachine(const std::string& name);
00476 
00481         bool resetStateMachine(const std::string& name);
00482 
00489         bool requestStateMachineState(const std::string& name, const std::string& state);
00505         virtual bool hasStateMachine(const std::string& name) const;
00506 
00511         bool isStateMachineActive(const std::string& name) const;
00512 
00517         bool isStateMachineRunning(const std::string& name) const;
00518 
00523         bool inStateMachineError(const std::string& name) const;
00524 
00529         bool isStateMachinePaused(const std::string& name) const;
00530 
00535         std::string getStateMachineState(const std::string& name) const;
00536 
00543         bool inStateMachineState(const std::string& name, const std::string& state) const;
00547     protected:
00548         StatementProcessor* sproc;
00549         bool doExecute(const std::string& code);
00550 
00551         bool evalInternal(const std::string& filename, const std::string& code);
00552         bool doLoadPrograms( const std::string& filename );
00553         bool doLoadProgramText( const std::string& code );
00554         bool doUnloadProgram( const std::string& name );
00555 
00556         bool doLoadStateMachines( const std::string& filename );
00557         bool doLoadStateMachineText( const std::string& code );
00558         bool doUnloadStateMachine( const std::string& name );
00559 
00560         void createInterface(void);
00561 
00562         void recursiveLoadStateMachine( StateMachinePtr sc );
00563         bool recursiveCheckLoadStateMachine( StateMachinePtr sc );
00564         void recursiveUnloadStateMachine( StateMachinePtr sc );
00565         bool recursiveCheckUnloadStateMachine( StateMachinePtr si );
00566 
00567         typedef std::map<std::string,StateMachinePtr> StateMap;
00568         StateMap   states;
00569         typedef StateMap::const_iterator StateMapIt;
00570 
00571         typedef std::map<std::string,ProgramInterfacePtr> ProgMap;
00572         ProgMap programs;
00573         typedef ProgMap::const_iterator ProgMapIt;
00574 
00583         bool ZeroPeriodWarning;
00584 
00585     };
00586 }}
00587 
00588 #endif


rtt
Author(s): RTT Developers
autogenerated on Fri Sep 9 2016 04:01:58