44 #include <boost/bind.hpp> 50 using namespace boost;
51 using namespace detail;
55 mrname(name), mrowner(tc)
67 log(
Error) <<
"OperationCaller with name '" + isb.
getName() +
"' already present." << endlog();
86 OperationCallers::iterator it =
mmethods.find(name);
94 for(OperationCallers::iterator it =
mmethods.begin(); it !=
mmethods.end(); ++it)
95 it->second->setCaller( new_owner ? new_owner->
engine() : 0);
100 it->second->setOwner( new_owner );
105 return shared_from_this();
106 }
catch( boost::bad_weak_ptr& ) {
107 log(
Error) <<
"When using boost < 1.40.0 : You are not allowed to call requires() on a ServiceRequester that does not yet belong to a TaskContext or another ServiceRequester." << endlog();
108 log(
Error) <<
"Try to avoid using requires() in this case: omit it or use the service requester directly." <<endlog();
109 log(
Error) <<
"OR: upgrade to boost 1.40.0, then this error will go away." <<endlog();
110 throw std::runtime_error(
"Illegal use of requires()");
115 if (service_name ==
"this")
117 Requests::iterator it =
mrequests.find(service_name);
128 log(
Error) <<
"Could not add ServiceRequester " << obj->getRequestName() <<
": name already in use." <<endlog();
141 if (!sp)
return false;
142 for (OperationCallers::iterator it =
mmethods.begin(); it !=
mmethods.end(); ++it) {
143 if ( !it->second->ready() ) {
144 if (sp->hasOperation( it->first )) {
145 it->second->setImplementation( sp->getLocalOperation( it->first ),
mrowner ?
mrowner->
engine() : 0 );
146 if ( it->second->ready() ) {
147 log(
Debug) <<
"Successfully set up OperationCaller " << it->first <<endlog();
149 log(
Debug) <<
"OperationCaller "<< it->first <<
" has no caller set: using GlobalEngine."<<endlog();
152 if (sp->hasMember( it->first )) {
153 it->second->setImplementationPart( sp->getOperation( it->first ),
mrowner ?
mrowner->
engine() : 0 );
154 if ( it->second->ready() ) {
155 log(
Debug) <<
"Successfully set up OperationCaller " << it->first <<endlog();
157 log(
Debug) <<
"OperationCaller "<< it->first <<
" has no caller set: using GlobalEngine."<<endlog();
165 log(
Info) <<
"Found complete interface of requested service '" <<
mrname <<
"'"<< endlog();
181 for (OperationCallers::const_iterator it =
mmethods.begin(); it !=
mmethods.end(); ++it)
182 if ( !it->second->ready() ) {
183 log(
Debug) <<
"ServiceRequester: "<< it->first <<
" not set up." <<endlog();
An invoker can be given an implementation and is identified by a name.
virtual const std::string & getName() const =0
Returns the name of this method instance.
RequesterNames getRequesterNames() const
OperationCallers mmethods
virtual bool ready() const
Returns true when all methods were resolved.
virtual void clear()
Remove all operation callers from this service requester.
void setOwner(TaskContext *new_owner)
Sets the owning TaskContext that is considered as the caller of requested operations.
boost::shared_ptr< ServiceRequester > shared_ptr
virtual void disconnect()
Disconnects all methods from their implementation.
Requests mrequests
the services we implement.
base::OperationCallerBaseInvoker * getOperationCaller(const std::string &name)
boost::shared_ptr< Service > shared_ptr
ServiceRequester(const std::string &name, TaskContext *owner=0)
Service::shared_ptr mprovider
OperationCallerNames getOperationCallerNames() const
ServiceRequester::shared_ptr requires()
std::vector< typename MapT::key_type > keys(const MapT &map)
virtual void disconnect()=0
Disconnects this caller from the operation it was connected to.
virtual bool connectTo(Service::shared_ptr sp)
Connects this service's methods to the operations provided by op.
bool addServiceRequester(shared_ptr obj)
Add a new ServiceRequester to this TaskContext.
The TaskContext is the C++ representation of an Orocos component.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
const ExecutionEngine * engine() const
Get a const pointer to the ExecutionEngine of this Task.
virtual ~ServiceRequester()
bool addOperationCaller(base::OperationCallerBaseInvoker &mbi)