TaskContext.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef ORO_TASK_CONTEXT_HPP
00040 #define ORO_TASK_CONTEXT_HPP
00041
00042 #include "AttributeRepository.hpp"
00043
00044 #include "rtt-config.h"
00045 #ifdef OROPKG_EXECUTION_ENGINE_EVENTS
00046 #include "EventService.hpp"
00047 #endif
00048
00049 #include "DataFlowInterface.hpp"
00050 #include "ExecutionEngine.hpp"
00051 #include "ScriptingAccess.hpp"
00052 #include "ExecutionAccess.hpp"
00053 #include "MarshallingAccess.hpp"
00054 #include "TaskCore.hpp"
00055 #include "PropertyBag.hpp"
00056
00057 #include <string>
00058 #include <map>
00059
00060 namespace RTT
00061 {
00098 class RTT_API TaskContext
00099 : public OperationInterface,
00100 public TaskCore
00101 {
00102 public:
00106 typedef std::vector< std::string > PeerList;
00119 TaskContext( const std::string& name, TaskState initial_state = Stopped );
00120
00130 TaskContext(const std::string& name, ExecutionEngine* parent, TaskState initial_state = Stopped );
00131
00132 virtual ~TaskContext();
00133
00134 virtual const std::string& getName() const;
00135
00136 virtual const std::string& getDescription() const;
00137
00138 virtual void setDescription(const std::string& descr);
00139
00140 virtual OperationInterface* getParent() { return this; }
00141
00145 virtual void setParent(OperationInterface*) { }
00146
00152 virtual void setEngine(ExecutionEngine*) { }
00153
00160 void exportPorts();
00161
00168 virtual bool addPeer( TaskContext* peer, std::string alias = "" );
00169
00173 virtual void removePeer( const std::string& name );
00174
00178 virtual void removePeer( TaskContext* peer );
00179
00183 virtual bool connectPeers( TaskContext* peer );
00184
00188 virtual bool connectPorts( TaskContext* peer );
00189
00196 virtual void disconnect();
00197
00203 virtual void reconnect();
00204
00208 virtual void disconnectPeers( const std::string& name );
00209
00214 virtual PeerList getPeerList() const;
00215
00219 virtual bool hasPeer( const std::string& peer_name ) const;
00220
00225 virtual TaskContext* getPeer(const std::string& peer_name ) const;
00226
00235 virtual bool addObject( OperationInterface *obj );
00236
00245 void setActivity( ActivityInterface* new_act );
00246
00252 ActivityInterface* getActivity();
00253
00259 virtual void clear();
00260
00269 virtual bool ready();
00270
00271 bool start();
00272
00278 void updateHook();
00279
00286 virtual void updateHook(std::vector<PortInterface*> const& updated_ports);
00287
00293 ScriptingAccess* scripting()
00294 {
00295 return mscriptAcc;
00296 }
00297
00303 const ScriptingAccess* scripting() const
00304 {
00305 return mscriptAcc;
00306 }
00307
00314 ExecutionAccess* execution()
00315 {
00316 return mengAcc;
00317 }
00318
00325 const ExecutionAccess* execution() const
00326 {
00327 return mengAcc;
00328 }
00329
00334 MarshallingAccess* marshalling()
00335 {
00336 return marshAcc;
00337 }
00338
00343 const MarshallingAccess* marshalling() const
00344 {
00345 return marshAcc;
00346 }
00347
00351 PropertyBag* properties() {
00352 return mattributes.properties();
00353 }
00354
00358 const PropertyBag* properties() const {
00359 return mattributes.properties();
00360 }
00361
00365 DataFlowInterface* ports() {
00366 return &dataPorts;
00367 }
00368
00372 const DataFlowInterface* ports() const {
00373 return &dataPorts;
00374 }
00375
00376 private:
00377
00378 TaskContext( TaskContext& );
00379 protected:
00380 std::string mdescription;
00381
00382 typedef std::map< std::string, TaskContext* > PeerMap;
00383 typedef std::vector< TaskContext* > Users;
00384 typedef std::vector< OperationInterface* > Objects;
00386 PeerMap _task_map;
00388 Users musers;
00390 Objects mobjects;
00391
00392 ScriptingAccess* mscriptAcc;
00393
00394 ExecutionAccess* mengAcc;
00395
00396 MarshallingAccess* marshAcc;
00397
00402 void addUser(TaskContext* user);
00403
00408 void removeUser(TaskContext* user);
00409
00410 void setup();
00411
00412 protected:
00413 std::vector< PortInterface* > updated_ports;
00418 void dataOnPort(PortInterface*);
00419 private:
00423 DataFlowInterface dataPorts;
00424
00429 ActivityInterface::shared_ptr our_act;
00430 };
00431
00437 RTT_API bool connectPorts(TaskContext* A, TaskContext* B);
00438
00445 RTT_API bool connectPeers(TaskContext* A, TaskContext* B);
00446 }
00447
00448 #endif