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);
102 return shared_from_this();
103 }
catch( boost::bad_weak_ptr& ) {
104 log(
Error) <<
"When using boost < 1.40.0 : You are not allowed to call provides() on a ServiceRequester that does not yet belong to a TaskContext or another ServiceRequester." << endlog();
105 log(
Error) <<
"Try to avoid using requires() in this case: omit it or use the service requester directly." <<endlog();
106 log(
Error) <<
"OR: upgrade to boost 1.40.0, then this error will go away." <<endlog();
107 throw std::runtime_error(
"Illegal use of requires()");
112 if (service_name ==
"this")
117 sp = boost::make_shared<ServiceRequester>(service_name,
mrowner);
124 log(
Error) <<
"Could not add ServiceRequester " << obj->getRequestName() <<
": name already in use." <<endlog();
137 if (!sp)
return false;
138 for (OperationCallers::iterator it =
mmethods.begin(); it !=
mmethods.end(); ++it) {
139 if ( !it->second->ready() ) {
140 if (sp->hasOperation( it->first )) {
141 it->second->setImplementation( sp->getLocalOperation( it->first ),
mrowner ?
mrowner->
engine() : 0 );
142 if ( it->second->ready() ) {
143 log(
Debug) <<
"Successfully set up OperationCaller " << it->first <<endlog();
145 log(
Debug) <<
"OperationCaller "<< it->first <<
" has no caller set: using GlobalEngine."<<endlog();
148 if (sp->hasMember( it->first )) {
149 it->second->setImplementationPart( sp->getOperation( it->first ),
mrowner ?
mrowner->
engine() : 0 );
150 if ( it->second->ready() ) {
151 log(
Debug) <<
"Successfully set up OperationCaller " << it->first <<endlog();
153 log(
Debug) <<
"OperationCaller "<< it->first <<
" has no caller set: using GlobalEngine."<<endlog();
161 log(
Info) <<
"Found complete interface of requested service '" <<
mrname <<
"'"<< endlog();
177 for (OperationCallers::const_iterator it =
mmethods.begin(); it !=
mmethods.end(); ++it)
178 if ( !it->second->ready() ) {
179 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)