Orocos Real-Time Toolkit  2.9.0
ProgramService.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Wed Jan 18 14:11:40 CET 2006 ProgramService.cpp
3 
4  ProgramService.cpp - description
5  -------------------
6  begin : Wed January 18 2006
7  copyright : (C) 2006 Peter Soetens
8  email : peter.soetens@mech.kuleuven.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 
40 #include "ProgramService.hpp"
41 
42 #include "../OperationCaller.hpp"
43 #include "../FactoryExceptions.hpp"
44 #include "../ExecutionEngine.hpp"
45 #include "../internal/DataSources.hpp"
46 
47 namespace RTT
48 {
49 
50  using namespace detail;
51 
53  : Service( prog->getName(), tc),
54  program( new ValueDataSource<ProgramInterfacePtr>(prog) ),
55  function(prog)
56  {
57  this->doc("Orocos Program Script");
58 
59  // We need a weak pointer here in order to be able to unload programs that
60  // reference self. The only way we can use weak_ptr with OperationCaller/Operation is by putting it in the data source
61  // of the first argument. We can not 'boost::bind' to a weak pointer, only to a shared_ptr.
62  DataSource<ProgramInterfacePtr>* ptr = program.get();
63  // OperationCallers :
64  addOperationDS("start", &ProgramInterface::start,ptr).doc("Start or continue this program.");
65  addOperationDS("pause", &ProgramInterface::pause,ptr).doc("Pause this program.");
66  addOperationDS("step", &ProgramInterface::step,ptr).doc("Step a paused program.");
67  addOperationDS("stop", &ProgramInterface::stop,ptr).doc("Stop and reset this program.");
68 
69  // DataSources:
70 
71  addOperationDS("isRunning", &ProgramInterface::isRunning,ptr).doc("Is this program being executed and not paused ?");
72  addOperationDS("inError", &ProgramInterface::inError,ptr).doc("Has this program executed an erroneous method ?");
73  addOperationDS("isPaused", &ProgramInterface::isPaused,ptr).doc("Is this program running but paused ?");
74  }
75 
77  // When the this Service is deleted, make sure the program does not reference us.
78  FunctionGraphPtr prog = function;
79  if ( prog ) {
80  prog->setProgramService( ProgramServicePtr() );
81  }
82  }
83 }
boost::shared_ptr< FunctionGraph > FunctionGraphPtr
virtual bool pause()=0
Pause or start-and-pause the execution of this program.
boost::shared_ptr< ProgramInterface > ProgramInterfacePtr
This class allows storage and retrieval of operations, ports, attributes and properties provided by a...
Definition: Service.hpp:93
ProgramService(FunctionGraphPtr prog, TaskContext *tc=0)
By constructing this object, a program is added to a taskcontext as a TaskContext, with its commands and methods.
virtual bool start()=0
Start the execution of this program.
virtual bool step()=0
Execute a single action when paused.
virtual bool stop()=0
Stop the execution of this program.
const std::string & doc() const
Returns a descriptive text for this service.
Definition: Service.hpp:144
bool isRunning() const
Returns true if the program is running.
DataSource< T >::result_t get() const
Return the data as type T.
Definition: DataSources.hpp:78
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93
Operation< typename internal::GetSignatureDS< Func >::Signature > & addOperationDS(const std::string &name, Func func, internal::DataSource< boost::shared_ptr< ObjT > > *sp, ExecutionThread et=ClientThread)
For internal use only.
Definition: Service.hpp:506
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
A simple, yet very useful DataSource, which keeps a value, and returns it in its get() method...
Definition: DataSources.hpp:60
boost::shared_ptr< ProgramService > ProgramServicePtr
bool inError() const
Returns true if the program is in error.
bool isPaused() const
Returns true if the program is paused.