47 #include <boost/bind.hpp> 48 #include <boost/mem_fn.hpp> 55 #include "rtt-config.h" 57 #if defined(ORO_ACT_DEFAULT_SEQUENTIAL) 59 #elif defined(ORO_ACT_DEFAULT_ACTIVITY) 66 using namespace boost;
68 using namespace detail;
73 #if defined(ORO_ACT_DEFAULT_SEQUENTIAL)
75 #elif defined(ORO_ACT_DEFAULT_ACTIVITY)
76 ,our_act( new
Activity( this->engine(), name ) )
86 provides()->doc(
"The interface of this TaskContext.");
106 this->
addOperation(
"trigger", &
TaskContext::trigger,
this,
ClientThread).doc(
"Trigger the update method for execution in the thread of this task.\n Only succeeds if the task isRunning() and allowed by the Activity executing this task.");
138 while( !
musers.empty() ) {
139 musers.front()->removePeer(
this);
144 _task_map.begin()->second->removeUser(
this);
153 bool failure =
false;
154 const std::string& location = this->
getName();
158 for (DataFlowInterface::Ports::iterator it = myports.begin();
170 if((dynamic_cast<OutputPortInterface*>(*it) && dynamic_cast<OutputPortInterface*>(peerport)) ||
171 (dynamic_cast<InputPortInterface*>(*it) && dynamic_cast<InputPortInterface*>(peerport)))
173 log(
Debug)<< (*it)->getName() <<
" and " << peerport->
getName() <<
" have the same type" <<
endlog();
178 if ( !(*it)->connectTo( peerport ) ) {
179 log(
Debug)<<
"Data flow incompatible between ports " 180 <<
getName() <<
"." << (*it)->getName() <<
" and " 191 const std::string& location = this->
getName();
194 vector<string> myreqs = this->
requires()->getRequesterNames();
195 vector<string> peerreqs = peer->
requires()->getRequesterNames();
198 for (vector<string>::iterator it = myreqs.begin();
202 if ( !sr->ready() ) {
203 if (peer->
provides()->hasService( *it ))
204 success = sr->connectTo( peer->
provides(*it) ) && success;
212 for (vector<string>::iterator it = peerreqs.begin();
213 it != peerreqs.end();
216 if ( !sr->ready() ) {
217 if (this->
provides()->hasService(*it))
218 success = sr->connectTo( this->provides(*it) ) && success;
220 log(
Debug)<<
"This Task provides no Service " << *it <<
" for peer Task "<<peer->
getName() <<
"."<<
endlog();
231 if (
provides()->hasService(service_name))
244 Users::iterator it = find(
musers.begin(),
musers.end(), peer);
253 if ( !peer ||
_task_map.count( alias ) != 0 )
262 PeerMap::iterator it =
_task_map.find( name );
264 it->second->removeUser(
this );
272 if ( it->second == peer ) {
282 || peer->
hasPeer( this->getName() ) )
293 for (DataFlowInterface::Ports::iterator it = myports.begin();
300 while( !
musers.empty() ) {
301 musers.front()->removePeer(
this);
305 _task_map.begin()->second->removeUser(
this);
321 std::vector<std::string> res;
323 std::back_inserter( res ),
330 return _task_map.count( peer_name ) == 1;
335 if (this->
hasPeer( peer_name ) )
336 return _task_map.find(peer_name)->second;
348 log(
Error) <<
"Cannot set the activity of TaskContext " 355 #if defined(ORO_ACT_DEFAULT_SEQUENTIAL) 357 #elif defined(ORO_ACT_DEFAULT_ACTIVITY) 420 #ifdef ORO_SIGNALLING_PORTS 421 ports()->setupHandles();
431 #ifdef ORO_SIGNALLING_PORTS 432 ports()->cleanupHandles();
TaskContext(const std::string &name, TaskState initial_state=Stopped)
PeerMap _task_map
map of the tasks we are using
UserCallbacks user_callbacks
Service::shared_ptr provides()
ActivityInterface * getActivity() const
Query for the task this interface is run in.
Users musers
map of the tasks that are using us.
bool loadService(const std::string &service_name)
void addUser(TaskContext *user)
void forceActivity(base::ActivityInterface *new_act)
boost::shared_ptr< ServiceRequester > shared_ptr
const std::string & getName() const
virtual bool connectPeers(TaskContext *peer)
virtual void removePeer(const std::string &name)
virtual bool isConfigured() const
virtual bool setCpuAffinity(unsigned cpu)
virtual bool isRunning() const
bool setActivity(base::ActivityInterface *new_act)
void dataOnPort(base::PortInterface *port)
void setDataOnPortCallback(base::InputPortInterface *port, SlotFunction callback)
unsigned int mCycleCounter
virtual TaskContext * getPeer(const std::string &peer_name) const
virtual Seconds getPeriod() const
virtual bool run(RunnableInterface *r)
virtual bool inException() const
virtual bool hasPeer(const std::string &peer_name) const
ServiceRequester::shared_ptr requires()
unsigned int mTimeOutCounter
boost::function< void(base::PortInterface *)> SlotFunction
virtual void disconnect()
DataFlowInterface * ports()
virtual bool inFatalError() const
base::PortInterface * getPort(const std::string &name) const
virtual PeerList getPeerList() const
boost::shared_ptr< ActivityInterface > shared_ptr
bool prepareProvide(const std::string &name)
Interface to start/stop and query a Activity.
Service::shared_ptr tcservice
ServiceRequester::shared_ptr tcrequests
virtual void disconnectPeers(const std::string &name)
bool addAttribute(const std::string &name, T &attr)
std::vector< base::PortInterface * > Ports
void removeUser(TaskContext *user)
An Activity executes a RunnableInterface object in a (periodic) thread.
virtual bool isActive() const
virtual bool inRunTimeError() const
virtual unsigned getCpuAffinity() const
base::ActivityInterface::shared_ptr our_act
virtual bool connectPorts(TaskContext *peer)
static boost::shared_ptr< PluginLoader > Instance()
void removeDataOnPortCallback(base::PortInterface *port)
virtual bool connectServices(TaskContext *peer)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
virtual void dataOnPortCallback(base::PortInterface *port)
virtual bool process(base::DisposableInterface *c)
Operation< Signature > & addOperation(Operation< Signature > &op)
virtual bool setPeriod(Seconds s)
unsigned int mTriggerCounter
const ExecutionEngine * engine() const
static Logger::LogFunction endlog()
virtual bool addPeer(TaskContext *peer, std::string alias="")
base::ActivityInterface * getActivity()
virtual const std::string & getName() const
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...
virtual bool dataOnPortHook(base::PortInterface *port)