40 #include "TaskContextC.h" 45 #include "../../types/Types.hpp" 46 #include "../../extras/SequentialActivity.hpp" 49 #include "tao/TimeBaseC.h" 50 #include "tao/Messaging/Messaging.h" 51 #include "tao/Messaging/Messaging_RT_PolicyC.h" 52 #include "orbsvcs/CosNamingC.h" 53 #include <ace/String_Base.h> 55 #include <omniORB4/Naming.hh> 69 IllegalServer::IllegalServer() : reason(
"This server does not exist or has the wrong type.") {}
84 log(
Info) <<
"Terminating TaskContextProxy for " << this->getName() <<endlog();
85 if ( this->properties() ) {
88 this->attributes()->clear();
89 for (list<PortInterface*>::iterator it = port_proxies.begin(); it != port_proxies.end(); ++it)
115 CORBA::Object_var task_object =
116 orb->string_to_object ( name.c_str() );
119 mtask = corba::CTaskContext::_narrow (task_object.in ());
122 CORBA::Object_var rootObj;
123 CosNaming::NamingContext_var rootContext;
125 rootObj =
orb->resolve_initial_references(
"NameService");
126 rootContext = CosNaming::NamingContext::_narrow(rootObj);
129 if (CORBA::is_nil(rootContext)) {
130 std::string err(
"TaskContextProxy could not acquire NameService.");
131 log(
Error) << err <<endlog();
135 CosNaming::Name serverName;
136 serverName.length(2);
137 serverName[0].id = CORBA::string_dup(
"TaskContexts");
138 serverName[1].id = CORBA::string_dup( name.c_str() );
141 CORBA::Object_var task_object = rootContext->resolve(serverName);
142 mtask = corba::CTaskContext::_narrow (task_object.in ());
144 if ( CORBA::is_nil(
mtask ) ) {
145 std::string err(
"Failed to acquire TaskContextServer '"+name+
"'.");
149 CORBA::String_var nm =
mtask->getName();
150 std::string newname( nm.in() );
151 this->
provides()->setName( newname );
155 catch (CORBA::Exception &e) {
156 log(
Error)<<
"CORBA exception raised when resolving Object !" << endlog();
165 log(
Error) <<
"Unknown Exception in TaskContextProxy construction!"<<endlog();
180 CORBA::String_var nm =
mtask->getName();
181 std::string name( nm.in() );
185 catch (CORBA::Exception &e) {
186 log(
Error) <<
"CORBA exception raised when creating TaskContextProxy!" <<
Logger::nl;
199 if (CORBA::is_nil(
mtask))
202 CService_var serv =
mtask->getProvider(
"this");
205 CServiceRequester_var srq =
mtask->getRequester(
"this");
207 log(
Debug) <<
"All Done."<<endlog();
212 COperationCallerNames_var opcnames = csrq->getOperationCallerNames();
214 log(
Debug) <<
"Fetching OperationCallers of " << parent->getRequestName()<<endlog();
215 for (
size_t i=0; i < opcnames->length(); ++i) {
216 if ( parent->getOperationCaller(
string(opcnames[i].in() )))
218 log(
Debug) <<
"Requiring operation: "<< opcnames[i].in() <<endlog();
219 parent->addOperationCaller( *
new OperationCallerProxy(
string(opcnames[i].in() ), CServiceRequester::_duplicate(csrq) ));
222 CRequestNames_var rqlist = csrq->getRequestNames();
224 for(
size_t i =0; i != rqlist->length(); ++i) {
225 if (
string( rqlist[i] ) ==
"this")
227 CServiceRequester_var cobj = csrq->getRequest(rqlist[i]);
239 log(
Debug) <<
"Fetching "<<parent->getName()<<
" Service:"<<endlog();
246 log(
Debug) <<
"Fetching Operations."<<endlog();
247 COperationInterface::COperationList_var objs;
248 objs = serv->getOperations();
249 for (
size_t i=0; i < objs->length(); ++i) {
250 if ( parent->hasMember(
string(objs[i].in() )))
252 log(
Debug) <<
"Providing operation: "<< objs[i].in() <<endlog();
257 log(
Debug) <<
"Fetching Properties."<<endlog();
259 CConfigurationInterface::CPropertyNames_var props = serv->getPropertyList();
261 for (
size_t i=0; i != props->length(); ++i) {
262 if (
findProperty( *parent->properties(), string(props[i].name.in()),
"." ) )
264 if ( !serv->hasProperty( props[i].name.in() ) ) {
265 log(
Error) <<
"Property "<< string(props[i].name.in()) <<
" present in getPropertyList() but not accessible."<<endlog();
269 CORBA::String_var tn = serv->getPropertyTypeName(props[i].name.in());
273 string pname = string( props[i].name.in() );
274 pname = pname.substr( pname.rfind(
".") + 1 );
275 string prefix = string( props[i].name.in() );
276 if ( prefix.rfind(
".") == string::npos ) {
280 prefix = prefix.substr( 0, prefix.rfind(
".") );
289 log(
Debug) <<
"Looked up Property " << tn.in() <<
" "<< pname <<
": created."<<endlog();
292 if (
string(
"PropertyBag") == tn.in() ) {
294 log(
Debug) <<
"Looked up PropertyBag " << tn.in() <<
" "<< pname <<
": created."<<endlog();
296 log(
Error) <<
"Looked up Property " << tn.in() <<
" "<< pname <<
": type not known. Check your RTT_COMPONENT_PATH ( \""<<getenv(
"RTT_COMPONENT_PATH")<<
" \")."<<endlog();
300 log(
Debug) <<
"Fetching Attributes."<<endlog();
301 CConfigurationInterface::CAttributeNames_var attrs = serv->getAttributeList();
302 for (
size_t i=0; i != attrs->length(); ++i) {
303 if ( parent->hasAttribute(
string(attrs[i].in()) ) )
305 if ( !serv->hasAttribute( attrs[i].in() ) ) {
306 log(
Error) <<
"Attribute '"<< string(attrs[i].in()) <<
"' present in getAttributeList() but not accessible."<<endlog();
310 CORBA::String_var tn = serv->getAttributeTypeName( attrs[i].in() );
313 log(
Debug) <<
"Looking up Attribute " << tn.in() <<
": found!"<<endlog();
318 if ( serv->isAttributeAssignable( attrs[i].in() ) )
323 log(
Error) <<
"Looking up Attribute " << tn.in();
324 Logger::log() <<
": type not known. Check your RTT_COMPONENT_PATH ( \""<<getenv(
"RTT_COMPONENT_PATH")<<
" \")."<<endlog();
328 CService::CProviderNames_var plist = serv->getProviderNames();
330 for(
size_t i =0; i != plist->length(); ++i) {
331 if (
string( plist[i] ) ==
"this")
333 CService_var cobj = serv->getService(plist[i]);
334 CORBA::String_var descr = cobj->getServiceDescription();
337 tobj->doc( descr.in() );
347 log(
Debug) <<
"Fetching Ports for service "<<parent->getName()<<
"."<<endlog();
350 CDataFlowInterface::CPortDescriptions_var objs = dfact->getPortDescriptions();
351 for (
size_t i=0; i < objs->length(); ++i) {
353 if (parent->getPort( port.
name.in() ))
360 <<
" has a type that cannot be marshalled over CORBA: " << port.
type_name <<
". " 361 <<
"It is ignored by TaskContextProxy" << endlog();
371 parent->addPort(*new_port);
390 catch (CORBA::Exception &e) {
397 if ( CORBA::is_nil(
orb) ) {
398 log(
Error) <<
"Won't create a proxy for '"<<name<<
"' : orb is nill. Call TaskContextProxy::InitOrb(argc, argv); before TaskContextProxy::Create()." <<endlog();
401 if ( name.empty() ) {
402 log(
Error) <<
"Can't create a proxy with an empty name." <<endlog();
417 if ( CORBA::is_nil(
orb) ) {
418 log(
Error) <<
"Won't create a proxy for '"<<name<<
"' : orb is nill. Call TaskContextProxy::InitOrb(argc, argv); before TaskContextProxy::Create()." <<endlog();
421 if ( name.empty() ) {
422 log(
Error) <<
"Can't create a proxy with an empty file name." <<endlog();
427 ifstream namestream( name.c_str() );
430 return Create( ior,
true);
435 if ( CORBA::is_nil(
orb) ) {
436 log(
Error) <<
"Can not create proxy when ORB is nill !"<<endlog();
439 if ( CORBA::is_nil(t) ) {
440 log(
Error) <<
"Can not create proxy for nill peer !" <<endlog();
446 for (PMap::iterator it =
proxies.begin(); it !=
proxies.end(); ++it)
447 if ( (it->second)->_is_equivalent( t ) ) {
448 log(
Debug) <<
"Existing proxy found !" <<endlog();
456 if ( it->second->server()->_is_equivalent( t ) ) {
457 log(
Debug) <<
"Local server found !" <<endlog();
462 log(
Debug) <<
"No local taskcontext found..." <<endlog();
476 if (! CORBA::is_nil(
mtask) )
477 return mtask->start();
479 mtask = CTaskContext::_nil();
488 if (! CORBA::is_nil(
mtask) )
489 return mtask->stop();
491 mtask = CTaskContext::_nil();
501 if (! CORBA::is_nil(
mtask) )
502 return mtask->recover();
504 mtask = CTaskContext::_nil();
514 if (! CORBA::is_nil(
mtask) )
515 return mtask->activate();
517 mtask = CTaskContext::_nil();
526 if (! CORBA::is_nil(
mtask) )
527 return mtask->isActive();
529 mtask = CTaskContext::_nil();
536 if (! CORBA::is_nil(
mtask) )
537 return mtask->isRunning();
539 mtask = CTaskContext::_nil();
546 if (! CORBA::is_nil(
mtask) )
547 return mtask->configure();
549 mtask = CTaskContext::_nil();
558 if (! CORBA::is_nil(
mtask) )
559 return mtask->cleanup();
561 mtask = CTaskContext::_nil();
570 if (! CORBA::is_nil(
mtask) )
571 return mtask->isConfigured();
573 mtask = CTaskContext::_nil();
580 if (! CORBA::is_nil(
mtask) )
581 return mtask->inFatalError();
583 mtask = CTaskContext::_nil();
590 if (! CORBA::is_nil(
mtask) )
591 return mtask->inRunTimeError();
593 mtask = CTaskContext::_nil();
601 if (! CORBA::is_nil(
mtask) )
602 return mtask->inException();
604 mtask = CTaskContext::_nil();
612 if (! CORBA::is_nil(
mtask) )
615 mtask = CTaskContext::_nil();
628 if (CORBA::is_nil(
mtask))
634 if (
mtask->addPeer( ctp->
server(), alias.c_str() ) ) {
642 if (
mtask->addPeer( newpeer->
server(), alias.c_str() ) ) {
647 mtask = CTaskContext::_nil();
657 if (CORBA::is_nil(
mtask))
659 mtask->removePeer( name.c_str() );
661 mtask = CTaskContext::_nil();
670 if (CORBA::is_nil(
mtask))
674 mtask = CTaskContext::_nil();
683 if (CORBA::is_nil(
mtask))
688 mtask = CTaskContext::_nil();
698 if (! CORBA::is_nil(
mtask) )
699 mtask->disconnectPeers( name.c_str() );
701 mtask = CTaskContext::_nil();
712 if (! CORBA::is_nil(
mtask) ) {
713 corba::CTaskContext::CPeerNames_var plist =
mtask->getPeerList();
714 for(
size_t i =0; i != plist->length(); ++i)
715 vlist.push_back( std::string( plist[i] ) );
718 mtask = CTaskContext::_nil();
726 if (! CORBA::is_nil(
mtask))
727 return mtask->hasPeer( peer_name.c_str() );
729 mtask = CTaskContext::_nil();
737 if (CORBA::is_nil(
mtask))
739 corba::CTaskContext_ptr ct =
mtask->getPeer( peer_name.c_str() );
740 if ( CORBA::is_nil(ct) )
744 mtask = CTaskContext::_nil();
752 if (CORBA::is_nil(
mtask))
757 mtask = CTaskContext::_nil();
767 if (CORBA::is_nil(
mtask))
770 return mtask->connectServices( newpeer->
server() );
772 mtask = CTaskContext::_nil();
781 if (CORBA::is_nil(
mtask)) {
791 mtask = CTaskContext::_nil();
797 if ( CORBA::is_nil(
mtask) )
798 return CTaskContext::_nil();
803 if ( CORBA::is_nil(
orb) )
804 return PortableServer::POA::_nil();
806 CORBA::Object_var poa_object =
807 orb->resolve_initial_references (
"RootPOA");
815 PortableServer::POA::_narrow (poa_object.in ());
This class manages the creation of TaskContext Corba Servers and a Corba Object Request Broker (Orb) ...
static PortableServer::POA_var proxy_poa
For now one POA handles all proxies.
void fetchRequesters(ServiceRequester::shared_ptr parent, CServiceRequester_ptr csrq)
virtual void disconnectPeers(const std::string &name)
Remove a two-way connection from this task to a peer task.
virtual bool isRunning() const
Inspect if the component is in the Running or RunTimeError state.
base::AttributeBase * buildAttribute(std::string name, base::DataSourceBase::shared_ptr source=0) const
Build an Attribute of this type.
bool storeProperty(PropertyBag &bag, const std::string &path, base::PropertyBase *item, const std::string &separator)
Stores a property in a bag given a certain path with transfer of ownership.
void fetchPorts(Service::shared_ptr parent, CDataFlowInterface_ptr serv)
Service::shared_ptr provides()
Returns this Service.
corba::CTaskContext_ptr server() const
Get the Corba Object of the CTaskContext.
virtual bool activate()
This method starts the ExecutionEngine of this component in case it was not running.
virtual bool start()
This method starts the execution of the updateHook() with each trigger or period. ...
static std::ostream & nl(std::ostream &__os)
Insert a newline ' ' in the ostream.
void forceActivity(base::ActivityInterface *new_act)
Forces the current activity to become new_act, even if this TaskContext is still running.
#define CORBA_EXCEPTION_INFO(x)
boost::shared_ptr< ServiceRequester > shared_ptr
virtual bool isActive() const
Inspect if the component's ExecutionEngine is processing requests.
virtual bool stop()
This method stops the execution of updateHook() of this component.
A local factory for creating remote Corba methods.
virtual void setName(const std::string &n)
virtual bool inException() const
Inspect if the component is in the Exception state.
bool setActivity(base::ActivityInterface *new_act)
Sets the activity of this TaskContext.
basic_ostreams & endl(basic_ostreams &s)
Flush and newline.
virtual base::DataSourceBase::shared_ptr createAttributeDataSource(CService_ptr serv, const std::string &vname)=0
boost::shared_ptr< Service > shared_ptr
virtual base::DataSourceBase::shared_ptr createPropertyDataSource(CService_ptr serv, const std::string &vname)=0
Create a data source for an attribute or property.
Proxy for a remote output port.
ServiceRequester::shared_ptr requires()
Returns the object that manages which methods this Task requires to be implemented by another task...
PropertyBase * findProperty(const PropertyBag &bag, const std::string &nameSequence, const std::string &separator)
This function locates a Property in nested PropertyBags.
corba::CTaskContext_var mtask
Thrown if a server does not exist or has the wrong type.
virtual bool connectServices(TaskContext *peer)
Connects all requires/provides services of this component to these of a peer.
Convenient short notation for every sub-namespace of RTT.
void deletePropertyBag(PropertyBag &target)
This function iterates over a PropertyBag and recursively deletes all Property objects.
const char * what() const
static PortableServer::POA_var rootPOA
The root POA of this process.
This class manages the access of remote TaskContext Corba Servers and a Corba Object Request Broker (...
static TaskContextServer * Create(TaskContext *tc, bool use_naming=true, bool require_name_service=false)
Factory method: create a CORBA server for an existing TaskContext.
void initFromURIOrTaskname(std::string location, bool is_ior)
initializes the class from a stringified ior or taskname in NameServer.
base::AttributeBase * buildConstant(std::string name, base::DataSourceBase::shared_ptr source, int sizehint) const
Build a non modifyable instance of this type.
static TaskContextProxy * CreateFromFile(std::string filename)
Factory method: create a CORBA Proxy for an existing TaskContextServer.
A property represents a named value of any type with a description.
bool hasProtocol(int protocol_id) const
Check if this type is transporable over a given protocol.
virtual void removePeer(const std::string &name)
Remove a one-way connection from this task to a peer task.
std::vector< std::string > PeerList
A list of Peer TaskContext names.
The state during component construction.
static PortableServer::POA_ptr ProxyPOA()
Returns the default POA for all proxies.
A class for representing a user type, and which can build instances of that type. ...
virtual bool hasPeer(const std::string &peer_name) const
Return true if it knows a peer by that name.
TaskState
Describes the different states a component can have.
base::PropertyBase * buildProperty(const std::string &name, const std::string &desc, base::DataSourceBase::shared_ptr source=0) const
Build a Property of this type.
std::list< base::PortInterface * > port_proxies
CDataFlowInterface does not delete ports automatically, because they can then be defined as members o...
virtual PeerList getPeerList() const
Return a standard container which contains all the Peer names of this TaskContext.
static void DestroyOrb()
Invoke this method once to cleanup the orb.
virtual TaskState getTaskState() const
Returns the current state of the TaskCore.
virtual bool inFatalError() const
Inspect if the component is in the FatalError state.
static shared_ptr Instance()
TypeTransporter * getProtocol(int protocol_id) const
Returns this type's transport for a given protocol.
virtual bool inRunTimeError() const
Inspect if the component is in the RunTimeError state.
Notify the Logger in which 'module' the message occured.
virtual bool ready()
Checks the validity of this TaskContext.
#define ORO_CORBA_PROTOCOL_ID
static Logger & log()
As Instance(), but more userfriendly.
virtual bool connectPeers(TaskContext *peer)
Add a two-way connection from this task to a peer task.
The TaskContext is the C++ representation of an Orocos component.
virtual TaskContext * getPeer(const std::string &peer_name) const
Get a pointer to a peer of this task.
virtual bool addPeer(TaskContext *peer, std::string alias="")
Add a one-way connection from this task to a peer task.
virtual bool cleanup()
This method instructs a stopped component to enter the pre-operational state again.
TaskContextProxy()
A Private constructor which does nothing.
Mirrors a remote operation caller in a ServiceRequestor.
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
virtual bool configure()
This method instructs the component to (re-)read configuration data and try to enter the Stopped stat...
void fetchServices(Service::shared_ptr parent, CService_ptr mtask)
The base class of every data flow port.
boost::shared_ptr< TypeInfoRepository > shared_ptr
virtual bool isConfigured() const
Inspect if the component is configured, i.e.
virtual bool connectPorts(TaskContext *peer)
Add a data flow connection from this task's ports to a peer's ports.
static TaskContextProxy * Create(std::string name, bool is_ior=false)
Factory method: create a CORBA Proxy for an existing TaskContextServer.
virtual bool recover()
Call this method in a RunTimeError or Exception state to indicate that the run-time error conditions ...
CTaskContext_ptr server() const
Get the Corba Object of this TaskContext.
static CORBA::ORB_var orb
The orb of this process.
virtual const std::string & getName() const
Returns the name of this TaskContext.
Extends the TypeTransporter in order to allow the creation of channel elements or output halves for a...
virtual void clear()
Clear the complete interface of this Component.
A CTaskContext is the main entry point of a distributed component and maps to a RTT::TaskContext.