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 #include "corba.h"
00040 #ifdef CORBA_IS_TAO
00041 #include "corba.h"
00042 #include <tao/PortableServer/PortableServer.h>
00043 #else
00044 #include <omniORB4/CORBA.h>
00045 #include <omniORB4/poa.h>
00046 #endif
00047
00048 #include "TransportPlugin.hpp"
00049 #include "CorbaTemplateProtocol.hpp"
00050 #include "RTTCorbaConversion.hpp"
00051 #include "../../types/TransportPlugin.hpp"
00052 #include "../../types/TypekitPlugin.hpp"
00053
00054 using namespace std;
00055 using namespace RTT::detail;
00056
00057 namespace RTT {
00058 namespace corba {
00059
00064 class CorbaFallBackProtocol
00065 : public CorbaTypeTransporter
00066 {
00067 bool warn;
00068 public:
00069 CorbaFallBackProtocol(bool do_warn = true) : warn(do_warn) {}
00070 virtual CORBA::Any* createAny(DataSourceBase::shared_ptr source) const
00071 {
00072 if (warn) {
00073 Logger::In in("CorbaFallBackProtocol");
00074 log(Error) << "Could not send data of type '"<< source->getTypeName()<<"' : data type not known to CORBA Transport." <<Logger::endl;
00075 }
00076 source->evaluate();
00077 return new CORBA::Any();
00078 }
00079
00080 virtual bool updateAny( base::DataSourceBase::shared_ptr source, CORBA::Any& any) const
00081 {
00082 if (warn) {
00083 Logger::In in("CorbaFallBackProtocol");
00084 log(Error) << "Could not send data of type '"<< source->getTypeName()<<"' : data type not known to CORBA Transport." <<Logger::endl;
00085 }
00086 source->evaluate();
00087 return false;
00088 }
00089
00090 virtual base::DataSourceBase::shared_ptr createDataSource(const CORBA::Any* any) const
00091 {
00092 return base::DataSourceBase::shared_ptr();
00093 }
00094
00098 virtual bool updateFromAny(const CORBA::Any* blob, DataSourceBase::shared_ptr target) const
00099 {
00100 if (warn) {
00101 Logger::In in("CorbaFallBackProtocol");
00102 log(Error) << "Could not update type '"<<target->getTypeName()<<"' with received data : data type not known to CORBA Transport." <<Logger::endl;
00103 }
00104 return false;
00105 }
00106
00107 virtual ChannelElementBase::shared_ptr createStream(base::PortInterface* port, const ConnPolicy& policy, bool is_sender) const {
00108 Logger::In in("CorbaFallBackProtocol");
00109 log(Error) << "Could create Stream for port '"<<port->getName()<<"' : data type not known to CORBA Transport." <<Logger::endl;
00110 return ChannelElementBase::shared_ptr();
00111 }
00112
00113 virtual base::ChannelElementBase* buildDataStorage(ConnPolicy const& policy) const { return 0; }
00114
00115 virtual CRemoteChannelElement_i* createChannelElement_i(DataFlowInterface*, ::PortableServer::POA* poa, bool) const {
00116 Logger::In in("CorbaFallBackProtocol");
00117 log(Error) << "Could create Channel : data type not known to CORBA Transport." <<Logger::endl;
00118 return 0;
00119
00120 }
00121
00122 virtual base::ChannelElementBase* buildChannelOutput(base::InputPortInterface& port,
00123 ConnPolicy const& policy) const {
00124 Logger::In in("CorbaFallBackProtocol");
00125 log(Error) << "Could create outputHalf for port "<<port.getName()<<": data type not known to CORBA Transport." <<Logger::endl;
00126 return 0;
00127 }
00128
00129 virtual base::ChannelElementBase* buildChannelInput(base::OutputPortInterface& port,
00130 ConnPolicy const& policy) const {
00131 Logger::In in("CorbaFallBackProtocol");
00132 log(Error) << "Could create outputHalf for port "<<port.getName()<<": data type not known to CORBA Transport." <<Logger::endl;
00133 return 0;
00134 }
00135 virtual base::DataSourceBase::shared_ptr createPropertyDataSource(CService_ptr serv, const std::string& vname) {
00136 CORBA::String_var tname = serv->getPropertyTypeName( CORBA::string_dup(vname.c_str()));
00137 log(Warning) << "Corba: Remote property '"<< vname << "' has unknown type " << tname.in() << endlog();
00138 return base::DataSourceBase::shared_ptr( );
00139 }
00140
00141 virtual base::DataSourceBase::shared_ptr createAttributeDataSource(CService_ptr serv, const std::string& vname) {
00142 CORBA::String_var tname = serv->getAttributeTypeName( CORBA::string_dup( vname.c_str()));
00143 log(Warning) << "Corba: Remote attribute '"<< vname << "' has unknown type " << tname.in() << endlog();
00144 return base::DataSourceBase::shared_ptr( );
00145 }
00146 };
00147
00148 bool CorbaLibPlugin::registerTransport(std::string name, TypeInfo* ti)
00149 {
00150 if ( name == "unknown_t")
00151 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaFallBackProtocol());
00152 if ( name == "int" )
00153 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<int>() );
00154 if ( name == "double" )
00155 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<double>() );
00156 if ( name == "float" )
00157 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<float>() );
00158 if ( name == "uint" )
00159 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<unsigned int>() );
00160 if ( name == "char" )
00161 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<char>() );
00162
00163
00164
00165
00166 if ( name == "bool" )
00167 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<bool>() );
00168 #ifndef RTT_NO_STD_TYPES
00169 if ( name == "string" )
00170 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<std::string>() );
00171 if ( name == "array" )
00172 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol< std::vector<double> >() );
00173 #endif
00174 if ( name == "void" )
00175 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaFallBackProtocol(false));
00176 if ( name == "ConnPolicy")
00177 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<ConnPolicy>() );
00178 if ( name == "TaskContext")
00179 return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<TaskContext*>() );
00180
00181 return false;
00182 }
00183
00184 std::string CorbaLibPlugin::getTransportName() const {
00185 return "CORBA";
00186 }
00187
00188 std::string CorbaLibPlugin::getTypekitName() const {
00189 return "rtt-types";
00190 }
00191
00192 std::string CorbaLibPlugin::getName() const {
00193 return "rtt-corba-types";
00194 }
00195 }
00196 }
00197
00198 ORO_TYPEKIT_PLUGIN( RTT::corba::CorbaLibPlugin )