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