CorbaMethodFactory.hpp
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 #ifndef ORO_CORBAMETHODFACTORY_HPP
00041 #define ORO_CORBAMETHODFACTORY_HPP
00042
00043 #include "../OperationInterface.hpp"
00044 #include "../FactoryExceptions.hpp"
00045 #include "ExpressionProxy.hpp"
00046 #include "OperationInterfaceC.h"
00047
00048 namespace RTT
00049 {namespace Corba
00050 {
00051
00057 class RTT_CORBA_API CorbaMethodFactory
00058 : public RTT::detail::OperationFactoryPart<DataSourceBase*>
00059 {
00060 Corba::MethodInterface_var mfact;
00061 PortableServer::POA_var mpoa;
00062 std::string method;
00063 public:
00064 typedef std::vector<DataSourceBase::shared_ptr> Arguments;
00065 typedef std::vector<std::string> Members;
00066 typedef std::vector< RTT::ArgumentDescription > Descriptions;
00067
00068 CorbaMethodFactory( const std::string& method_name, Corba::MethodInterface_ptr fact, PortableServer::POA_ptr the_poa )
00069 : RTT::detail::OperationFactoryPart<DataSourceBase*>("Corba Method"),
00070 mfact(Corba::MethodInterface::_duplicate(fact) ),
00071 mpoa(PortableServer::POA::_duplicate(the_poa)),
00072 method(method_name)
00073 {}
00074
00075 virtual ~CorbaMethodFactory() {}
00076
00077 virtual int arity() const {
00078 return this->getArgumentList().size();
00079 }
00080
00081 virtual std::string resultType() const {
00082 try {
00083 CORBA::String_var result = mfact->getResultType( method.c_str() );
00084 return std::string( result.in() );
00085 } catch ( Corba::NoSuchNameException& nsn ) {
00086 throw name_not_found_exception( nsn.name.in() );
00087 }
00088 return std::string();
00089 }
00090
00091 virtual std::string description() const {
00092 try {
00093 CORBA::String_var result = mfact->getDescription( method.c_str() );
00094 return std::string( result.in() );
00095 } catch ( Corba::NoSuchNameException& nsn ) {
00096 throw name_not_found_exception( nsn.name.in() );
00097 }
00098 return std::string();
00099 }
00100
00101 virtual std::vector< RTT::ArgumentDescription > getArgumentList() const {
00102 Descriptions ret;
00103 try {
00104 Corba::Descriptions_var result = mfact->getArguments( method.c_str() );
00105 ret.reserve( result->length() );
00106 for (size_t i=0; i!= result->length(); ++i)
00107 ret.push_back( RTT::ArgumentDescription(std::string( result[i].name.in() ),
00108 std::string( result[i].description.in() ),
00109 std::string( result[i].type.in() ) ));
00110 } catch ( Corba::NoSuchNameException& nsn ) {
00111 throw name_not_found_exception( nsn.name.in() );
00112 }
00113 return ret;
00114 }
00115
00116 virtual DataSourceBase* produce( const Arguments& args ) const {
00117 Corba::Arguments_var nargs = new Corba::Arguments();
00118 nargs->length( args.size() );
00119 for (size_t i=0; i < args.size(); ++i )
00120 nargs[i] = (Corba::Expression_ptr)args[i]->server(ORO_CORBA_PROTOCOL_ID, mpoa.in() );
00121 try {
00122 Corba::Expression_var result = mfact->createMethod( method.c_str(), nargs.in() );
00123 return ExpressionProxy::CreateDataSource( result._retn() ).get();
00124 } catch ( Corba::NoSuchNameException& nsn ) {
00125 throw name_not_found_exception( nsn.name.in() );
00126 } catch ( Corba::WrongNumbArgException& wa ) {
00127 throw wrong_number_of_args_exception( wa.wanted, wa.received );
00128 } catch ( Corba::WrongTypeArgException& wta ) {
00129 throw wrong_types_of_args_exception( wta.whicharg, wta.expected.in(), wta.received.in() );
00130 }
00131 return 0;
00132 }
00133 };
00134
00135 }}
00136
00137 #endif