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