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.");
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();
173 :
TaskContext(
"CORBAProxy"),
mtask( corba::CTaskContext::_duplicate(taskc) )
180 CORBA::String_var nm =
mtask->getName();
181 std::string name( nm.in() );
185 catch (CORBA::Exception &e) {
199 if (CORBA::is_nil(
mtask))
202 CTaskContextDescription_var tcd =
mtask->getCTaskContextDescription();
204 CService_var serv = tcd->mainprovider;
207 CServiceRequester_var srq = tcd->mainrequester;
215 for (
size_t i=0; i < cdescription.operationcallernames.length(); ++i) {
216 if ( parent->getOperationCaller(
string(cdescription.operationcallernames[i].in() )))
218 log(
Debug) <<
"Requiring operation: "<< cdescription.operationcallernames[i].
in() <<
endlog();
219 parent->addOperationCaller( *
new OperationCallerProxy(
string(cdescription.operationcallernames[i].in() ), CServiceRequester::_duplicate(csrq) ));
222 assert(cdescription.children.length() == cdescription.children_descriptions.length());
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();
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();
251 for (
size_t i=0; i != cdescription.properties.length(); ++i) {
252 if (
findProperty( *parent->properties(), string(cdescription.properties[i].name.in()),
"." ) )
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();
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();
307 if ( cdescription.attributes[i].assignable )
308 parent->setValue( ti->
buildAttribute( cdescription.attributes[i].name.in(), ds));
310 parent->setValue( ti->
buildConstant( cdescription.attributes[i].name.in(), ds));
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();
321 assert(cdescription.children.length() == cdescription.children_descriptions.length());
322 for(
size_t i =0; i != cdescription.children.length(); ++i) {
323 CService_ptr cobj = cdescription.children[i];
324 Service::shared_ptr tobj = parent->provides(std::string(cdescription.children_descriptions[i].name));
325 tobj->doc( cdescription.children_descriptions[i].description.in() );
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();
357 if (cdescription.ports[i].type == RTT::corba::CInput)
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) ) {
583 for (PMap::iterator it =
proxies.begin(); it !=
proxies.end(); ++it)
584 if ( (it->second)->_is_equivalent( t ) ) {
593 if ( it->second->server()->_is_equivalent( t ) ) {
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 ());
static PortableServer::POA_var proxy_poa
virtual void disconnectPeers(const std::string &name)
virtual bool isRunning() const
base::AttributeBase * buildAttribute(std::string name, base::DataSourceBase::shared_ptr source=0) const
Service::shared_ptr provides()
corba::CTaskContext_ptr server() const
void synchronizePorts(Service::shared_ptr parent, CDataFlowInterface_ptr dfact, const CServiceDescription &cdescription)
static std::ostream & nl(std::ostream &__os)
void forceActivity(base::ActivityInterface *new_act)
#define CORBA_EXCEPTION_INFO(x)
boost::shared_ptr< ServiceRequester > shared_ptr
virtual bool isActive() const
virtual void setName(const std::string &n)
virtual bool inException() const
bool setActivity(base::ActivityInterface *new_act)
PropertyBase * findProperty(const PropertyBag &bag, const std::string &nameSequence, const std::string &separator)
boost::shared_ptr< Service > shared_ptr
virtual base::DataSourceBase::shared_ptr createPropertyDataSource(CService_ptr serv, const std::string &vname)=0
ServiceRequester::shared_ptr requires()
corba::CTaskContext_var mtask
virtual bool connectServices(TaskContext *peer)
void deletePropertyBag(PropertyBag &target)
const char * what() const
static PortableServer::POA_var rootPOA
static TaskContextServer * Create(TaskContext *tc, bool use_naming=true, bool require_name_service=false)
void initFromURIOrTaskname(std::string location, bool is_ior)
base::AttributeBase * buildConstant(std::string name, base::DataSourceBase::shared_ptr source, int sizehint) const
static TaskContextProxy * CreateFromFile(std::string filename)
bool hasProtocol(int protocol_id) const
virtual void removePeer(const std::string &name)
std::vector< std::string > PeerList
The state during component construction.
static PortableServer::POA_ptr ProxyPOA()
virtual bool hasPeer(const std::string &peer_name) const
base::PropertyBase * buildProperty(const std::string &name, const std::string &desc, base::DataSourceBase::shared_ptr source=0) const
basic_ostreams & endl(basic_ostreams &s)
std::list< base::PortInterface * > port_proxies
virtual PeerList getPeerList() const
virtual TaskState getTaskState() const
virtual bool inFatalError() const
bool storeProperty(PropertyBag &bag, const std::string &path, base::PropertyBase *item, const std::string &separator)
static shared_ptr Instance()
TypeTransporter * getProtocol(int protocol_id) const
virtual bool inRunTimeError() const
#define ORO_CORBA_PROTOCOL_ID
virtual bool connectPeers(TaskContext *peer)
virtual TaskContext * getPeer(const std::string &peer_name) const
virtual bool addPeer(TaskContext *peer, std::string alias="")
boost::intrusive_ptr< DataSourceBase > shared_ptr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
PortInterface & doc(const std::string &desc)
boost::shared_ptr< TypeInfoRepository > shared_ptr
virtual bool isConfigured() const
Logger & in(const std::string &modname)
virtual bool connectPorts(TaskContext *peer)
void synchronizeRequesters(ServiceRequester::shared_ptr parent, CServiceRequester_ptr csrq, const CServiceRequesterDescription &cdescription)
static TaskContextProxy * Create(std::string name, bool is_ior=false)
static Logger::LogFunction endlog()
CTaskContext_ptr server() const
static CORBA::ORB_var orb
virtual const std::string & getName() const
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)