Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #include "ServiceRequesterI.h"
00070 #include "CorbaOperationCallerFactory.hpp"
00071 #include "TaskContext.hpp"
00072
00073 using namespace RTT;
00074 using namespace RTT::detail;
00075
00076
00077 RTT_corba_CServiceRequester_i::RTT_corba_CServiceRequester_i ( RTT::ServiceRequester* service, PortableServer::POA_ptr poa )
00078 : mservice(service), mpoa( PortableServer::POA::_duplicate(poa) )
00079 {
00080 }
00081
00082
00083 RTT_corba_CServiceRequester_i::~RTT_corba_CServiceRequester_i (void)
00084 {
00085 }
00086
00087 char * RTT_corba_CServiceRequester_i::getRequestName (
00088 void)
00089 {
00090 return CORBA::string_dup( mservice->getRequestName().c_str() );
00091 }
00092
00093 ::RTT::corba::CRequestNames * RTT_corba_CServiceRequester_i::getRequestNames (
00094 void)
00095 {
00096 ServiceRequester::RequesterNames names = mservice->getRequesterNames();
00097 ::RTT::corba::CRequestNames_var result = new ::RTT::corba::CRequestNames();
00098 result->length( names.size() );
00099 for (unsigned int i=0; i != names.size(); ++i )
00100 result[i] = CORBA::string_dup( names[i].c_str() );
00101
00102 return result._retn();
00103 }
00104
00105 ::RTT::corba::COperationCallerNames * RTT_corba_CServiceRequester_i::getOperationCallerNames (
00106 void)
00107 {
00108 ServiceRequester::OperationCallerNames names = mservice->getOperationCallerNames();
00109 ::RTT::corba::COperationCallerNames_var result = new ::RTT::corba::COperationCallerNames();
00110 result->length( names.size() );
00111 for (unsigned int i=0; i != names.size(); ++i )
00112 result[i] = CORBA::string_dup( names[i].c_str() );
00113
00114 return result._retn();
00115 }
00116
00117 ::RTT::corba::CServiceRequester_ptr RTT_corba_CServiceRequester_i::getRequest (
00118 const char * service_name)
00119 {
00120 std::string svc(service_name);
00121 if ( svc == "this" )
00122 return _this();
00123
00124 if ( mservice->requiresService(service_name) == false )
00125 return RTT::corba::CServiceRequester::_nil();
00126
00127
00128 if ( mrequests.find(svc) == mrequests.end() ) {
00129 log(Debug) << "Creating CServiceRequester for "<< service_name <<endlog();
00130 RTT_corba_CServiceRequester_i* mserv;
00131 mserv = new RTT_corba_CServiceRequester_i( mservice->requires(service_name), mpoa );
00132 CServiceRequester_ptr request = mserv->activate_this();
00133 mrequests[svc] = std::pair<RTT::corba::CServiceRequester_var, PortableServer::ServantBase_var>(request,mserv);
00134 }
00135
00136 return RTT::corba::CServiceRequester::_duplicate( mrequests[svc].first.in() );
00137 }
00138
00139 ::CORBA::Boolean RTT_corba_CServiceRequester_i::hasRequest (
00140 const char * name)
00141 {
00142 return mservice->requiresService( name );
00143 }
00144
00145 ::CORBA::Boolean RTT_corba_CServiceRequester_i::connectTo (
00146 ::RTT::corba::CService_ptr svc)
00147 {
00148 ServiceRequester::OperationCallerNames names = mservice->getOperationCallerNames();
00149
00150 for (unsigned int i=0; i != names.size(); ++i )
00151 connectCallerTo( names[i].c_str(), svc);
00152
00153 return mservice->ready();;
00154 }
00155
00156 ::CORBA::Boolean RTT_corba_CServiceRequester_i::connectCallerTo (
00157 const char * name,
00158 ::RTT::corba::CService_ptr svc)
00159 {
00160 std::string oname(name);
00161 if ( mservice->getOperationCaller(oname) == 0) {
00162 log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
00163 return false;
00164 }
00165 if ( svc->getArity(oname.c_str()) == -1) {
00166 CORBA::String_var svcname = svc->getName();
00167 log(Error) << "No such Operation: " << oname << " in "<< svcname.in() << endlog();
00168 return false;
00169 }
00170
00171
00172 OperationInterfacePart* tmp = new CorbaOperationCallerFactory(oname,svc, mpoa.in() );
00173 return mservice->getOperationCaller(oname)->setImplementationPart( tmp, mservice->getServiceOwner()->engine() );
00174 }
00175
00176 ::CORBA::Boolean RTT_corba_CServiceRequester_i::disconnectCaller (
00177 const char * name )
00178 {
00179 std::string oname(name);
00180 if ( mservice->getOperationCaller(oname) == 0) {
00181 log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
00182 return false;
00183 }
00184
00185 mservice->getOperationCaller(oname)->disconnect();
00186 return true;
00187 }
00188
00189 ::CORBA::Boolean RTT_corba_CServiceRequester_i::callerReady (
00190 const char * name )
00191 {
00192 std::string oname(name);
00193 if ( mservice->getOperationCaller(oname) == 0) {
00194 log(Error) << "No such OperationCaller: " << oname << " in "<< mservice->getRequestName()<<endlog();
00195 return false;
00196 }
00197
00198 return mservice->getOperationCaller(oname)->ready();
00199 }
00200
00201 ::CORBA::Boolean RTT_corba_CServiceRequester_i::ready (
00202 void)
00203 {
00204 return mservice->ready();
00205 }
00206
00207 void RTT_corba_CServiceRequester_i::disconnect (
00208 void)
00209 {
00210 mservice->disconnect();
00211 }
00212
00213