CorbaLib.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: FMTC  Tue Mar 11 21:49:22 CET 2008  CorbaLib.cpp
00003 
00004                         CorbaLib.cpp -  description
00005                            -------------------
00006     begin                : Tue March 11 2008
00007     copyright            : (C) 2008 FMTC
00008     email                : peter.soetens@fmtc.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
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") // register fallback also.
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             //if ( name == "long" )
00166             //    return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<long>() );
00167 //                if ( name == "PropertyBag" )
00168 //                    return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<PropertyBag>() );
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)); // warn=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 )


rtt
Author(s): RTT Developers
autogenerated on Wed Aug 26 2015 16:15:47