::CORBA::Any * RTT_corba_COperationInterface_i::callOperation ( const char * operation, ::RTT::corba::CAnyArguments & args) { if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) ) throw ::RTT::corba::CNoSuchNameException( operation ); // convert Corba args to C++ args. try { OperationCallerC orig(mfact->getPart(operation), operation, 0); vector<DataSourceBase::shared_ptr> results; for (size_t i =0; i != args.length(); ++i) { const TypeInfo* ti = mfact->getPart(operation)->getArgumentType( i + 1); CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*> ( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) ); // we need to store the results for returning them to caller (args is inout!) after the call() results.push_back( ctt->createDataSource( &args[i] ) ); orig.arg( results[i] ); } if ( orig.ready() ) { DataSourceBase::shared_ptr ds = orig.getCallDataSource(); CORBA::Any* retany; // Try to get the return result : const TypeInfo* ti = ds->getTypeInfo(); CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*> ( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) ); if ( !ctt ) { log(Warning) << "Could not return results of call to " << operation << ": unknown return type by CORBA transport."<<endlog(); ds->evaluate(); // equivalent to orig.call() retany = new CORBA::Any(); } else { retany = ctt->createAny( ds ); // call evaluate internally } // Return results into args: for (size_t i =0; i != args.length(); ++i) { const TypeInfo* ti = mfact->getPart(operation)->getArgumentType( i + 1); CorbaTypeTransporter* ctta = dynamic_cast<CorbaTypeTransporter*> ( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) ); ctta->updateAny(results[i], args[i]); } return retany; } else { orig.check(); // will throw } } catch (no_asynchronous_operation_exception& ) { throw ::RTT::corba::CNoSuchNameException( operation ); } catch ( name_not_found_exception& ) { throw ::RTT::corba::CNoSuchNameException( operation ); } catch ( wrong_number_of_args_exception& wna ) { throw ::RTT::corba::CWrongNumbArgException( wna.wanted, wna.received ); } catch (wrong_types_of_args_exception& wta ) { throw ::RTT::corba::CWrongTypeArgException( wta.whicharg, wta.expected_.c_str(), wta.received_.c_str() ); } return new ::CORBA::Any(); }
void RTT_corba_CSendHandle_i::checkArguments ( const ::RTT::corba::CAnyArguments & args) { try { SendHandleC shc(morig); for (unsigned int i = 0; i != mofp->collectArity(); ++i) { const TypeInfo* ti = mofp->getCollectType(i + 1); assert(ti); CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*> (ti->getProtocol(ORO_CORBA_PROTOCOL_ID)); shc.arg(ctt->createDataSource(&args[i])); } shc.check(); } catch (name_not_found_exception& nnf) { throw ::RTT::corba::CNoSuchNameException(nnf.name.c_str()); } catch (wrong_number_of_args_exception& wna) { throw ::RTT::corba::CWrongNumbArgException(wna.wanted, wna.received); } catch (wrong_types_of_args_exception& wta) { throw ::RTT::corba::CWrongTypeArgException(wta.whicharg, wta.expected_.c_str(), wta.received_.c_str()); } }
void RTT_corba_COperationInterface_i::checkOperation ( const char * operation, const ::RTT::corba::CAnyArguments & args) { if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) ) throw ::RTT::corba::CNoSuchNameException( operation ); try { OperationInterfacePart* mofp = mfact->getPart(operation); OperationCallerC mc(mofp, operation, 0); for (unsigned int i = 0; i < mofp->arity() && i < args.length(); ++i) { const TypeInfo* ti = mofp->getArgumentType(i+1); assert(ti); CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*> (ti->getProtocol(ORO_CORBA_PROTOCOL_ID)); if (ctt) { DataSourceBase::shared_ptr ds = ctt->createDataSource(&args[i]); if (ds) mc.arg(ds); else { log(Error) << "Registered transport for type "<< ti->getTypeName() << " could not create data source from Any (argument "<< i+1 <<"): calling operation '"<< operation <<"' will fail." <<endlog(); } } else { throw wrong_types_of_args_exception(i+1,"type known to CORBA", ti->getTypeName()); } } mc.check(); } catch (no_asynchronous_operation_exception& ) { throw ::RTT::corba::CNoSuchNameException(operation); } catch (name_not_found_exception& nnf) { throw ::RTT::corba::CNoSuchNameException(nnf.name.c_str()); } catch (wrong_number_of_args_exception& wna) { throw ::RTT::corba::CWrongNumbArgException(wna.wanted, wna.received); } catch (wrong_types_of_args_exception& wta) { throw ::RTT::corba::CWrongTypeArgException(wta.whicharg, wta.expected_.c_str(), wta.received_.c_str()); } }
::RTT::corba::CSendHandle_ptr RTT_corba_COperationInterface_i::sendOperation ( const char * operation, const ::RTT::corba::CAnyArguments & args) { // This implementation is 90% identical to callOperation above, only deviating in the orig.ready() part. if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) ) throw ::RTT::corba::CNoSuchNameException( operation ); // convert Corba args to C++ args. try { OperationCallerC orig(mfact->getPart(operation), operation, 0); for (size_t i =0; i != args.length(); ++i) { const TypeInfo* ti = mfact->getPart(operation)->getArgumentType( i + 1); CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*> ( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) ); orig.arg( ctt->createDataSource( &args[i] )); } if ( orig.ready() ) { SendHandleC resulthandle = orig.send(); // we may not destroy the SendHandle, before the operation completes: resulthandle.setAutoCollect(true); RTT_corba_CSendHandle_i* ret_i = new RTT_corba_CSendHandle_i( resulthandle, mfact->getPart(operation) ); CSendHandle_var ret = ret_i->_this(); return ret._retn(); } else { orig.check(); // will throw } } catch (no_asynchronous_operation_exception& ) { throw ::RTT::corba::CNoSuchNameException( operation ); } catch ( name_not_found_exception& ) { throw ::RTT::corba::CNoSuchNameException( operation ); } catch ( wrong_number_of_args_exception& wna ) { throw ::RTT::corba::CWrongNumbArgException( wna.wanted, wna.received ); } catch (wrong_types_of_args_exception& wta ) { throw ::RTT::corba::CWrongTypeArgException( wta.whicharg, wta.expected_.c_str(), wta.received_.c_str() ); } return CSendHandle::_nil(); }