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 CTaskContextDescription_var tcd =
mtask->getCTaskContextDescription();
204 CService_var serv = tcd->mainprovider;
207 CServiceRequester_var srq = tcd->mainrequester;
210 log(
Debug) <<
"All Done."<<endlog();
223 for(
size_t i =0; i != cdescription.
children.length(); ++i) {
224 CServiceRequester_ptr cobj = cdescription.
children[i];
234 log(
Debug) <<
"Synchronizing "<<parent->getName()<<
" Service:"<<endlog();
241 log(
Debug) <<
"Synchronizing Operations."<<endlog();
242 for (
size_t i=0; i < cdescription.
operations.length(); ++i) {
243 if ( parent->hasMember(
string(cdescription.
operations[i].name.in() )))
245 log(
Debug) <<
"Providing operation: "<< cdescription.
operations[i].name.in() <<endlog();
250 log(
Debug) <<
"Synchronizing Properties."<<endlog();
251 for (
size_t i=0; i != cdescription.
properties.length(); ++i) {
262 string pname = string( cdescription.
properties[i].name.in() );
263 pname = pname.substr( pname.rfind(
".") + 1 );
264 string prefix = string( cdescription.
properties[i].name.in() );
265 if ( prefix.rfind(
".") == string::npos ) {
269 prefix = prefix.substr( 0, prefix.rfind(
".") );
278 log(
Debug) <<
"Looked up Property " << cdescription.
properties[i].type_name.in() <<
" "<< pname <<
": created."<<endlog();
281 if (
string(
"PropertyBag") == cdescription.
properties[i].type_name.in() ) {
283 log(
Debug) <<
"Looked up PropertyBag " << cdescription.
properties[i].type_name.in() <<
" "<< pname <<
": created."<<endlog();
285 log(
Error) <<
"Looked up Property " << cdescription.
properties[i].type_name.in() <<
" "<< pname <<
": type not known. Check your RTT_COMPONENT_PATH ( \""<<getenv(
"RTT_COMPONENT_PATH")<<
" \")."<<endlog();
289 log(
Debug) <<
"Synchronizing Attributes."<<endlog();
290 for (
size_t i=0; i != cdescription.
attributes.length(); ++i) {
291 if ( parent->hasAttribute(
string(cdescription.
attributes[i].name.in()) ) )
294 if ( !serv->hasAttribute( cdescription.
attributes[i].name.in() ) ) {
295 log(
Error) <<
"Attribute '"<< string(cdescription.
attributes[i].name.in()) <<
"' present in getAttributeList() but not accessible."<<endlog();
302 log(
Debug) <<
"Looking up Attribute " << cdescription.
attributes[i].type_name.in() <<
": found!"<<endlog();
312 log(
Error) <<
"Looking up Attribute '" << cdescription.
attributes[i].name.in() <<
"' of type " << cdescription.
attributes[i].type_name.in() <<
": ";
314 log() <<
": type not known. Check your RTT_COMPONENT_PATH ( \""<<getenv(
"RTT_COMPONENT_PATH")<<
" \")." << endlog();
316 log() <<
": type does not support CORBA (no transport plugin loaded)" << endlog();
322 for(
size_t i =0; i != cdescription.
children.length(); ++i) {
323 CService_ptr cobj = cdescription.
children[i];
334 log(
Debug) <<
"Synchronizing Ports for service "<<parent->getName()<<
"."<<endlog();
337 for (
size_t i=0; i < cdescription.
ports.length(); ++i) {
338 if (parent->getPort( cdescription.
ports[i].name.in() ))
341 TypeInfo const* type_info = type_repo->type(cdescription.
ports[i].type_name.in());
344 log(
Warning) <<
"remote port '" << cdescription.
ports[i].name <<
"' " 345 <<
" has unknown type " << cdescription.
ports[i].type_name <<
" and cannot be marshalled over CORBA. " 346 <<
"It is ignored by TaskContextProxy" << endlog();
350 log(
Warning) <<
"remote port '" << cdescription.
ports[i].name <<
"' " 351 <<
" has type " << cdescription.
ports[i].type_name <<
" which cannot be marshalled over CORBA. " 352 <<
"It is ignored by TaskContextProxy" << endlog();
362 new_port->
doc(cdescription.
ports[i].description.in());
363 parent->addLocalPort(*new_port);
524 catch (CORBA::Exception &e) {
531 if ( CORBA::is_nil(
orb) ) {
532 log(
Error) <<
"Won't create a proxy for '"<<name<<
"' : orb is nill. Call TaskContextProxy::InitOrb(argc, argv); before TaskContextProxy::Create()." <<endlog();
535 if ( name.empty() ) {
536 log(
Error) <<
"Can't create a proxy with an empty name." <<endlog();
547 catch (CORBA::Exception &e) {
554 if ( CORBA::is_nil(
orb) ) {
555 log(
Error) <<
"Won't create a proxy for '"<<name<<
"' : orb is nill. Call TaskContextProxy::InitOrb(argc, argv); before TaskContextProxy::Create()." <<endlog();
558 if ( name.empty() ) {
559 log(
Error) <<
"Can't create a proxy with an empty file name." <<endlog();
564 ifstream namestream( name.c_str() );
567 return Create( ior,
true);
572 if ( CORBA::is_nil(
orb) ) {
573 log(
Error) <<
"Can not create proxy when ORB is nill !"<<endlog();
576 if ( CORBA::is_nil(t) ) {
577 log(
Error) <<
"Can not create proxy for nill peer !" <<endlog();
583 for (PMap::iterator it =
proxies.begin(); it !=
proxies.end(); ++it)
584 if ( (it->second)->_is_equivalent( t ) ) {
585 log(
Debug) <<
"Existing proxy found !" <<endlog();
593 if ( it->second->server()->_is_equivalent( t ) ) {
594 log(
Debug) <<
"Local server found !" <<endlog();
599 log(
Debug) <<
"No local taskcontext found..." <<endlog();
608 catch (CORBA::Exception &e) {
617 if (! CORBA::is_nil(
mtask) )
618 return mtask->start();
620 mtask = CTaskContext::_nil();
629 if (! CORBA::is_nil(
mtask) )
630 return mtask->stop();
632 mtask = CTaskContext::_nil();
642 if (! CORBA::is_nil(
mtask) )
643 return mtask->recover();
645 mtask = CTaskContext::_nil();
655 if (! CORBA::is_nil(
mtask) )
656 return mtask->activate();
658 mtask = CTaskContext::_nil();
667 if (! CORBA::is_nil(
mtask) )
668 return mtask->isActive();
670 mtask = CTaskContext::_nil();
677 if (! CORBA::is_nil(
mtask) )
678 return mtask->isRunning();
680 mtask = CTaskContext::_nil();
687 if (! CORBA::is_nil(
mtask) )
688 return mtask->configure();
690 mtask = CTaskContext::_nil();
699 if (! CORBA::is_nil(
mtask) )
700 return mtask->cleanup();
702 mtask = CTaskContext::_nil();
711 if (! CORBA::is_nil(
mtask) )
712 return mtask->isConfigured();
714 mtask = CTaskContext::_nil();
721 if (! CORBA::is_nil(
mtask) )
722 return mtask->inFatalError();
724 mtask = CTaskContext::_nil();
731 if (! CORBA::is_nil(
mtask) )
732 return mtask->inRunTimeError();
734 mtask = CTaskContext::_nil();
742 if (! CORBA::is_nil(
mtask) )
743 return mtask->inException();
745 mtask = CTaskContext::_nil();
753 if (! CORBA::is_nil(
mtask) )
756 mtask = CTaskContext::_nil();
769 if (CORBA::is_nil(
mtask))
775 if (
mtask->addPeer( ctp->
server(), alias.c_str() ) ) {
783 if (
mtask->addPeer( newpeer->
server(), alias.c_str() ) ) {
788 mtask = CTaskContext::_nil();
798 if (CORBA::is_nil(
mtask))
800 mtask->removePeer( name.c_str() );
802 mtask = CTaskContext::_nil();
811 if (CORBA::is_nil(
mtask))
815 mtask = CTaskContext::_nil();
824 if (CORBA::is_nil(
mtask))
829 mtask = CTaskContext::_nil();
839 if (! CORBA::is_nil(
mtask) )
840 mtask->disconnectPeers( name.c_str() );
842 mtask = CTaskContext::_nil();
853 if (! CORBA::is_nil(
mtask) ) {
854 corba::CTaskContext::CPeerNames_var plist =
mtask->getPeerList();
855 for(
size_t i =0; i != plist->length(); ++i)
856 vlist.push_back( std::string( plist[i] ) );
859 mtask = CTaskContext::_nil();
867 if (! CORBA::is_nil(
mtask))
868 return mtask->hasPeer( peer_name.c_str() );
870 mtask = CTaskContext::_nil();
878 if (CORBA::is_nil(
mtask))
880 corba::CTaskContext_ptr ct =
mtask->getPeer( peer_name.c_str() );
881 if ( CORBA::is_nil(ct) )
885 mtask = CTaskContext::_nil();
893 if (CORBA::is_nil(
mtask))
898 mtask = CTaskContext::_nil();
908 if (CORBA::is_nil(
mtask))
911 return mtask->connectServices( newpeer->
server() );
913 mtask = CTaskContext::_nil();
922 if (CORBA::is_nil(
mtask)) {
932 mtask = CTaskContext::_nil();
938 if ( CORBA::is_nil(
mtask) )
939 return CTaskContext::_nil();
944 if ( CORBA::is_nil(
orb) )
945 return PortableServer::POA::_nil();
947 CORBA::Object_var poa_object =
948 orb->resolve_initial_references (
"RootPOA");
956 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.
virtual void disconnectPeers(const std::string &name)
Remove a two-way connection from this task to a peer task.
Complete description of a Service.
virtual bool isRunning() const
Inspect if the component is in the Running or RunTimeError state.
CConfigurationInterface::CAttributeNames attributes
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.
Service::shared_ptr provides()
Returns this Service.
corba::CTaskContext_ptr server() const
Get the Corba Object of the CTaskContext.
void synchronizePorts(Service::shared_ptr parent, CDataFlowInterface_ptr dfact, const CServiceDescription &cdescription)
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.
CDataFlowInterface::CPortDescriptions ports
virtual bool stop()
This method stops the execution of updateHook() of this component.
A local factory for creating remote Corba methods.
COperationCallerNames operationcallernames
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.
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.
COperationInterface::COperationDescriptions operations
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.
CServiceRequesterDescriptions children_descriptions
Complete description of a ServiceRequester.
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.
CConfigurationInterface::CPropertyNames properties
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.
CServiceDescriptions children_descriptions
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...
PortInterface & doc(const std::string &desc)
Set the documentation of this port.
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.
void synchronizeRequesters(ServiceRequester::shared_ptr parent, CServiceRequester_ptr csrq, const CServiceRequesterDescription &cdescription)
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 base::DataSourceBase::shared_ptr createAttributeDataSource(CService_ptr serv, const std::string &vname, bool is_assignable)=0
void synchronizeServices(Service::shared_ptr parent, CService_ptr serv, const CServiceDescription &cdescription)
virtual void clear()
Clear the complete interface of this Component.
CServiceRequesters children
A CTaskContext is the main entry point of a distributed component and maps to a RTT::TaskContext.