ScriptingService.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jun 26 13:25:57 CEST 2006 ScriptingService.hpp
3 
4  ScriptingService.hpp - description
5  -------------------
6  begin : Mon June 26 2006
7  copyright : (C) 2006 Peter Soetens
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_EXECUTION_SCRIPTING_ACCESS
40 #define ORO_EXECUTION_SCRIPTING_ACCESS
41 
42 #include <vector>
43 #include <map>
44 #include <string>
45 #include "rtt-scripting-config.h"
46 #include "ProgramInterface.hpp"
47 #include "StateMachine.hpp"
48 #include "../Service.hpp"
49 #include "ProgramExceptions.hpp"
50 
51 namespace RTT
52 { namespace scripting {
53 
60  class RTT_SCRIPTING_API ScriptingService
61  : public Service
62  {
63  public:
64  typedef boost::shared_ptr<ScriptingService> shared_ptr;
69  static shared_ptr Create(TaskContext* parent);
70 
76  ScriptingService( TaskContext* parent );
77 
78  virtual ~ScriptingService();
79 
82 
88  bool loadProgram( ProgramInterfacePtr pi );
89 
96  bool deleteProgram(const std::string& name);
97 
103  bool unloadProgram(const std::string& name);
104 
108  void clear();
109 
113  ProgramStatus::ProgramStatus getProgramStatus(const std::string& name) const;
114 
118  std::string getProgramStatusStr(const std::string& name) const;
119 
120 
124  std::vector<std::string> getProgramList() const;
125 
129  const ProgramInterfacePtr getProgram(const std::string& name) const;
130 
131  ProgramInterfacePtr getProgram(const std::string& name);
132 
137  bool loadStateMachine( StateMachinePtr sc );
138 
144  bool unloadStateMachine( const std::string& name );
145 
152  bool deleteStateMachine( const std::string& name );
153 
157  StateMachineStatus::StateMachineStatus getStateMachineStatus(const std::string& name) const;
158 
162  std::string getStateMachineStatusStr(const std::string& name) const;
163 
167  std::vector<std::string> getStateMachineList() const;
168 
172  const StateMachinePtr getStateMachine(const std::string& name) const;
173 
177  StateMachinePtr getStateMachine(const std::string& name);
178 
189  int execute(const std::string& code );
190 
207  bool eval(const std::string& code );
208 
219  bool runScript( const std::string& filename);
220 
224  typedef std::vector< ProgramInterfacePtr > Functions;
225 
236  virtual Functions loadFunctions(const std::string& filename, bool do_throw );
237 
249  virtual Functions loadFunctions(const std::string& code, const std::string& filename, bool do_throw );
250 
262  virtual bool loadPrograms( const std::string& filename, bool do_throw );
263 
276  virtual bool loadPrograms( const std::string& code, const std::string& filename, bool do_throw );
277 
287  virtual bool unloadProgram( const std::string& name, bool do_throw );
288 
299  virtual int getProgramLine(const std::string& name) const;
300 
308  virtual std::string getProgramText(const std::string& name ) const;
309 
321  virtual bool loadStateMachines( const std::string& filename, bool do_throw );
322 
335  virtual bool loadStateMachines( const std::string& code, const std::string& filename, bool do_throw );
336 
346  virtual bool unloadStateMachine( const std::string& name, bool do_throw );
347 
355  virtual std::string getStateMachineText(const std::string& name ) const;
356 
367  virtual int getStateMachineLine(const std::string& name ) const;
368 
377  bool startProgram(const std::string& name);
378 
383  bool stopProgram(const std::string& name);
384 
389  bool pauseProgram(const std::string& name);
390 
395  bool stepProgram(const std::string& name);
411  virtual bool hasProgram(const std::string& name) const;
412 
420  bool isProgramRunning(const std::string& name) const;
421 
429  bool isProgramPaused(const std::string& name) const;
430 
438  bool inProgramError(const std::string& name) const;
451  bool activateStateMachine(const std::string& name);
452 
457  bool deactivateStateMachine(const std::string& name);
458 
463  bool startStateMachine(const std::string& name);
464 
469  bool pauseStateMachine(const std::string& name);
470 
475  bool stopStateMachine(const std::string& name);
476 
481  bool resetStateMachine(const std::string& name);
482 
489  bool requestStateMachineState(const std::string& name, const std::string& state);
505  virtual bool hasStateMachine(const std::string& name) const;
506 
511  bool isStateMachineActive(const std::string& name) const;
512 
517  bool isStateMachineRunning(const std::string& name) const;
518 
523  bool inStateMachineError(const std::string& name) const;
524 
529  bool isStateMachinePaused(const std::string& name) const;
530 
535  std::string getStateMachineState(const std::string& name) const;
536 
543  bool inStateMachineState(const std::string& name, const std::string& state) const;
547  protected:
549  bool doExecute(const std::string& code);
550 
551  bool evalInternal(const std::string& filename, const std::string& code);
552  bool doLoadPrograms( const std::string& filename );
553  bool doLoadProgramText( const std::string& code );
554  bool doUnloadProgram( const std::string& name );
555 
556  bool doLoadStateMachines( const std::string& filename );
557  bool doLoadStateMachineText( const std::string& code );
558  bool doUnloadStateMachine( const std::string& name );
559 
560  void createInterface(void);
561 
562  void recursiveLoadStateMachine( StateMachinePtr sc );
563  bool recursiveCheckLoadStateMachine( StateMachinePtr sc );
564  void recursiveUnloadStateMachine( StateMachinePtr sc );
565  bool recursiveCheckUnloadStateMachine( StateMachinePtr si );
566 
567  typedef std::map<std::string,StateMachinePtr> StateMap;
568  StateMap states;
569  typedef StateMap::const_iterator StateMapIt;
570 
571  typedef std::map<std::string,ProgramInterfacePtr> ProgMap;
572  ProgMap programs;
573  typedef ProgMap::const_iterator ProgMapIt;
574 
584 
585  };
586 }}
587 
588 #endif
boost::shared_ptr< ScriptingService > shared_ptr
StateMap::const_iterator StateMapIt
std::map< std::string, ProgramInterfacePtr > ProgMap
ProgMap::const_iterator ProgMapIt
boost::shared_ptr< ProgramInterface > ProgramInterfacePtr
ProgramInterface::Status ProgramStatus
boost::shared_ptr< StateMachine > StateMachinePtr
std::vector< ProgramInterfacePtr > Functions
scripting::StateMachine::Status StateMachineStatus
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
std::map< std::string, StateMachinePtr > StateMap


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:35