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 "TaskContextI.h"
00070 #include "TaskContextServer.hpp"
00071 #include "TaskContextProxy.hpp"
00072 #include "ServiceI.h"
00073 #include "ServiceRequesterI.h"
00074 #include "DataFlowI.h"
00075 #include "../../OperationCaller.hpp"
00076 #include "../../rtt-detail-fwd.hpp"
00077
00078
00079 using namespace RTT;
00080 using namespace RTT::detail;
00081 using namespace RTT::corba;
00082
00083
00084 RTT_corba_CTaskContext_i::RTT_corba_CTaskContext_i (RTT::TaskContext* orig, PortableServer::POA_ptr the_poa)
00085 : mpoa( PortableServer::POA::_duplicate(the_poa) )
00086 , mtask( orig ), mRequest_i(0), mService_i(0)
00087 {
00088
00089 mtask->addOperation("shutdown", &RTT_corba_CTaskContext_i::shutdownCORBA, this).doc("Shutdown CORBA ORB. This function makes RunOrb() return.");
00090 }
00091
00092
00093 RTT_corba_CTaskContext_i::~RTT_corba_CTaskContext_i (void)
00094 {
00095
00096 }
00097
00098 void RTT_corba_CTaskContext_i::shutdownCORBA() {
00099 TaskContextServer::ShutdownOrb(false);
00100 }
00101
00102 char * RTT_corba_CTaskContext_i::getName (
00103 void)
00104 {
00105 return CORBA::string_dup( mtask->getName().c_str() );
00106 }
00107
00108 char * RTT_corba_CTaskContext_i::getDescription (
00109 void)
00110 {
00111 return CORBA::string_dup( mtask->provides()->doc().c_str() );
00112 }
00113
00114 ::RTT::corba::CTaskState RTT_corba_CTaskContext_i::getTaskState (
00115 void)
00116 {
00117 return ::RTT::corba::CTaskState(mtask->getTaskState());
00118 }
00119
00120 ::CORBA::Boolean RTT_corba_CTaskContext_i::configure (
00121 void)
00122 {
00123 return mtask->configure();
00124 }
00125
00126 ::CORBA::Boolean RTT_corba_CTaskContext_i::start (
00127 void)
00128 {
00129 return mtask->start();
00130 }
00131
00132 ::CORBA::Boolean RTT_corba_CTaskContext_i::activate (
00133 void)
00134 {
00135 return mtask->activate();
00136 }
00137
00138 ::CORBA::Boolean RTT_corba_CTaskContext_i::stop (
00139 void)
00140 {
00141 return mtask->stop();
00142 }
00143
00144 ::CORBA::Boolean RTT_corba_CTaskContext_i::cleanup (
00145 void)
00146 {
00147 return mtask->cleanup();
00148 }
00149
00150 ::CORBA::Boolean RTT_corba_CTaskContext_i::resetException (
00151 void)
00152 {
00153 if (mtask->getTaskState() == RTT::TaskContext::Exception)
00154 return mtask->recover();
00155 return false;
00156 }
00157
00158 ::CORBA::Boolean RTT_corba_CTaskContext_i::isActive (
00159 void)
00160 {
00161 return mtask->isActive();
00162 }
00163
00164 ::CORBA::Boolean RTT_corba_CTaskContext_i::isRunning (
00165 void)
00166 {
00167 return mtask->isRunning();
00168 }
00169
00170 ::CORBA::Boolean RTT_corba_CTaskContext_i::isConfigured (
00171 void)
00172 {
00173 return mtask->isConfigured();
00174 }
00175
00176 ::CORBA::Boolean RTT_corba_CTaskContext_i::inFatalError (
00177 void)
00178 {
00179 return mtask->inFatalError();
00180 }
00181
00182 ::CORBA::Boolean RTT_corba_CTaskContext_i::inRunTimeError (
00183 void)
00184 {
00185 return mtask->inRunTimeError();
00186 }
00187
00188 ::RTT::corba::CDataFlowInterface_ptr RTT_corba_CTaskContext_i::ports (
00189 void)
00190 {
00191 return getProvider("this");
00192 }
00193
00194 ::RTT::corba::CService_ptr RTT_corba_CTaskContext_i::getProvider (
00195 const char * service_name)
00196 {
00197 if ( mtask->provides()->hasService(service_name) == false)
00198 return CService::_nil();
00199
00200 if ( CORBA::is_nil( mService ) ) {
00201 log(Debug) << "Creating CService for "<< mtask->getName()<<endlog();
00202 RTT_corba_CService_i* mserv;
00203 mService_i = mserv = new RTT_corba_CService_i( mtask->provides(), mpoa );
00204 mService = mserv->activate_this();
00205 CDataFlowInterface_i::registerServant(CDataFlowInterface::_narrow(mService), mtask->provides().get());
00206 }
00207
00208 std::string svc(service_name);
00209 if ( svc == "this" )
00210 return ::RTT::corba::CService::_duplicate( mService.in() );
00211 return mService->getService( service_name );
00212 }
00213
00214 ::RTT::corba::CServiceRequester_ptr RTT_corba_CTaskContext_i::getRequester (
00215 const char * service_name)
00216 {
00217 std::string svc(service_name);
00218 if ( mtask->requires()->requiresService(service_name) == false && svc != "this")
00219 return CServiceRequester::_nil();
00220
00221 if ( CORBA::is_nil( mRequest ) ) {
00222 log(Debug) << "Creating CServiceRequester for "<< mtask->getName()<<endlog();
00223 RTT_corba_CServiceRequester_i* mserv;
00224 mRequest_i = mserv = new RTT_corba_CServiceRequester_i( mtask->requires(), mpoa );
00225 mRequest = mserv->activate_this();
00226
00227 }
00228
00229 if ( svc == "this" )
00230 return ::RTT::corba::CServiceRequester::_duplicate( mRequest.in() );
00231 return mRequest->getRequest( service_name );
00232 }
00233
00234 ::RTT::corba::CTaskContext::CPeerNames * RTT_corba_CTaskContext_i::getPeerList (
00235 void)
00236 {
00237 TaskContext::PeerList peers = mtask->getPeerList();
00238 ::RTT::corba::CTaskContext::CPeerNames_var result = new ::RTT::corba::CTaskContext::CPeerNames();
00239 result->length( peers.size() );
00240 for (unsigned int i=0; i != peers.size(); ++i )
00241 result[i] = CORBA::string_dup( peers[i].c_str() );
00242
00243 return result._retn();
00244 }
00245
00246 ::RTT::corba::CTaskContext_ptr RTT_corba_CTaskContext_i::getPeer (
00247 const char * name)
00248 {
00249 std::string pname(name);
00250 TaskContext* task = mtask->getPeer( pname );
00251 if ( task ) {
00252
00253
00254 return TaskContextServer::CreateServer( task, false );
00255 }
00256 return RTT::corba::CTaskContext::_nil();
00257 }
00258
00259 ::CORBA::Boolean RTT_corba_CTaskContext_i::hasPeer (
00260 const char * name)
00261 {
00262 std::string mname(name);
00263 return mtask->hasPeer(mname);
00264 }
00265
00266 ::CORBA::Boolean RTT_corba_CTaskContext_i::addPeer (
00267 ::RTT::corba::CTaskContext_ptr p,
00268 const char * alias)
00269 {
00270 std::string malias(alias);
00271 if (mtask->hasPeer(alias) == false )
00272 return mtask->addPeer( TaskContextProxy::Create(p), alias );
00273 return false;
00274 }
00275
00276 ::CORBA::Boolean RTT_corba_CTaskContext_i::removePeer (
00277 const char * name)
00278 {
00279 std::string mname(name);
00280 mtask->removePeer( mname );
00281 return true;
00282 }
00283
00284 ::CORBA::Boolean RTT_corba_CTaskContext_i::connectPeers (
00285 ::RTT::corba::CTaskContext_ptr p)
00286 {
00287 TaskContext* t = TaskContextProxy::Create( p );
00288 return mtask->connectPeers( t );
00289 }
00290
00291 ::CORBA::Boolean RTT_corba_CTaskContext_i::disconnectPeers (
00292 const char * name)
00293 {
00294 std::string pname(name);
00295 mtask->disconnectPeers( pname );
00296 return true;
00297 }
00298
00299 ::CORBA::Boolean RTT_corba_CTaskContext_i::connectPorts (
00300 ::RTT::corba::CTaskContext_ptr p)
00301 {
00302 TaskContext* t = TaskContextProxy::Create( p );
00303 return mtask->connectPorts( t );
00304 }
00305
00306 ::CORBA::Boolean RTT_corba_CTaskContext_i::connectServices (
00307 ::RTT::corba::CTaskContext_ptr p)
00308 {
00309 TaskContext* t = TaskContextProxy::Create( p );
00310 return mtask->connectServices( t );
00311 }
00312
00313