CorbaLib.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: FMTC Tue Mar 11 21:49:22 CET 2008 CorbaLib.cpp
3 
4  CorbaLib.cpp - description
5  -------------------
6  begin : Tue March 11 2008
7  copyright : (C) 2008 FMTC
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #include "corba.h"
40 #ifdef CORBA_IS_TAO
41 #include "corba.h"
42 #include <tao/PortableServer/PortableServer.h>
43 #else
44 #include <omniORB4/CORBA.h>
45 #include <omniORB4/poa.h>
46 #endif
47 
48 #include "TransportPlugin.hpp"
50 #include "RTTCorbaConversion.hpp"
51 #include "../../types/TransportPlugin.hpp"
52 #include "../../types/TypekitPlugin.hpp"
53 #ifdef OS_RT_MALLOC
54 #include "../../rt_string.hpp"
55 #endif
56 
57 using namespace std;
58 using namespace RTT::detail;
59 
60 namespace RTT {
61  namespace corba {
62 
68  : public CorbaTypeTransporter
69  {
70  bool warn;
71  public:
72  CorbaFallBackProtocol(bool do_warn = true) : warn(do_warn) {}
73  virtual CORBA::Any* createAny(DataSourceBase::shared_ptr source) const
74  {
75  if (warn) {
76  Logger::In in("CorbaFallBackProtocol");
77  log(Error) << "Could not send data of type '"<< source->getTypeName()<<"' : data type not known to CORBA Transport." <<Logger::endl;
78  }
79  source->evaluate();
80  return new CORBA::Any();
81  }
82 
83  virtual bool updateAny( base::DataSourceBase::shared_ptr source, CORBA::Any& any) const
84  {
85  if (warn) {
86  Logger::In in("CorbaFallBackProtocol");
87  log(Error) << "Could not send data of type '"<< source->getTypeName()<<"' : data type not known to CORBA Transport." <<Logger::endl;
88  }
89  source->evaluate();
90  return false;
91  }
92 
93  virtual base::DataSourceBase::shared_ptr createDataSource(const CORBA::Any* any) const
94  {
96  }
97 
101  virtual bool updateFromAny(const CORBA::Any* blob, DataSourceBase::shared_ptr target) const
102  {
103  if (warn) {
104  Logger::In in("CorbaFallBackProtocol");
105  log(Error) << "Could not update type '"<<target->getTypeName()<<"' with received data : data type not known to CORBA Transport." <<Logger::endl;
106  }
107  return false;
108  }
109 
110  virtual ChannelElementBase::shared_ptr createStream(base::PortInterface* port, const ConnPolicy& policy, bool is_sender) const {
111  Logger::In in("CorbaFallBackProtocol");
112  log(Error) << "Could create Stream for port '"<<port->getName()<<"' : data type not known to CORBA Transport." <<Logger::endl;
114  }
115 
116  virtual base::ChannelElementBase* buildDataStorage(ConnPolicy const& policy) const { return 0; }
117 
118  virtual CRemoteChannelElement_i* createChannelElement_i(DataFlowInterface*, ::PortableServer::POA* poa, const ConnPolicy &) const {
119  Logger::In in("CorbaFallBackProtocol");
120  log(Error) << "Could create Channel : data type not known to CORBA Transport." <<Logger::endl;
121  return 0;
122  }
123 
125  ConnPolicy const& policy) const {
126  Logger::In in("CorbaFallBackProtocol");
127  log(Error) << "Could create outputHalf for port "<<port.getName()<<": data type not known to CORBA Transport." <<Logger::endl;
128  return 0;
129  }
130 
132  ConnPolicy const& policy) const {
133  Logger::In in("CorbaFallBackProtocol");
134  log(Error) << "Could create outputHalf for port "<<port.getName()<<": data type not known to CORBA Transport." <<Logger::endl;
135  return 0;
136  }
137  virtual base::DataSourceBase::shared_ptr createPropertyDataSource(CService_ptr serv, const std::string& vname) {
138  CORBA::String_var tname = serv->getPropertyTypeName( CORBA::string_dup(vname.c_str()));
139  log(Warning) << "Corba: Remote property '"<< vname << "' has unknown type " << tname.in() << endlog();
141  }
142 
143  virtual base::DataSourceBase::shared_ptr createAttributeDataSource(CService_ptr serv, const std::string& vname, bool) {
144  CORBA::String_var tname = serv->getAttributeTypeName( CORBA::string_dup( vname.c_str()));
145  log(Warning) << "Corba: Remote attribute '"<< vname << "' has unknown type " << tname.in() << endlog();
147  }
148  };
149 
150  bool CorbaLibPlugin::registerTransport(std::string name, TypeInfo* ti)
151  {
152  if ( name == "unknown_t") // register fallback also.
154  if ( name == "int" )
156  if ( name == "double" )
158  if ( name == "float" )
160  if ( name == "uint" )
162  if ( name == "llong" )
164  if ( name == "ullong" )
166  if ( name == "char" )
168  //if ( name == "long" )
169  // return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<long>() );
170 // if ( name == "PropertyBag" )
171 // return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<PropertyBag>() );
172  if ( name == "bool" )
174 #ifndef RTT_NO_STD_TYPES
175  if ( name == "string" )
177  if ( name == "array" )
178  return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol< std::vector<double> >() );
179 #endif
180 #ifdef OS_RT_MALLOC
181  if ( name == "rt_string")
183 #endif
184  if ( name == "void" )
185  return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaFallBackProtocol(false)); // warn=false
186  if ( name == "ConnPolicy")
188  if ( name == "TaskContext")
190 
191  return false;
192  }
193 
194  std::string CorbaLibPlugin::getTransportName() const {
195  return "CORBA";
196  }
197 
198  std::string CorbaLibPlugin::getTypekitName() const {
199  return "rtt-types";
200  }
201 
202  std::string CorbaLibPlugin::getName() const {
203  return "rtt-corba-types";
204  }
205  }
206 }
207 
#define ORO_TYPEKIT_PLUGIN(TYPEKIT)
Definition: mystd.hpp:163
const std::string & getName() const
virtual ChannelElementBase::shared_ptr createStream(base::PortInterface *port, const ConnPolicy &policy, bool is_sender) const
Definition: CorbaLib.cpp:110
virtual CRemoteChannelElement_i * createChannelElement_i(DataFlowInterface *,::PortableServer::POA *poa, const ConnPolicy &) const
Definition: CorbaLib.cpp:118
virtual base::DataSourceBase::shared_ptr createDataSource(const CORBA::Any *any) const
Definition: CorbaLib.cpp:93
virtual base::DataSourceBase::shared_ptr createPropertyDataSource(CService_ptr serv, const std::string &vname)
Definition: CorbaLib.cpp:137
bool addProtocol(int protocol_id, TypeTransporter *tt)
Definition: TypeInfo.cpp:137
basic_ostreams & endl(basic_ostreams &s)
Definition: rtstreams.cpp:110
boost::intrusive_ptr< ChannelElementBase > shared_ptr
virtual base::ChannelElementBase * buildChannelOutput(base::InputPortInterface &port, ConnPolicy const &policy) const
Definition: CorbaLib.cpp:124
virtual base::DataSourceBase::shared_ptr createAttributeDataSource(CService_ptr serv, const std::string &vname, bool)
Definition: CorbaLib.cpp:143
#define ORO_CORBA_PROTOCOL_ID
Definition: CorbaLib.hpp:45
virtual bool updateAny(base::DataSourceBase::shared_ptr source, CORBA::Any &any) const
Definition: CorbaLib.cpp:83
virtual CORBA::Any * createAny(DataSourceBase::shared_ptr source) const
Definition: CorbaLib.cpp:73
boost::intrusive_ptr< DataSourceBase > shared_ptr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
CorbaFallBackProtocol(bool do_warn=true)
Definition: CorbaLib.cpp:72
static Logger & log()
Definition: Logger.hpp:350
Logger & in(const std::string &modname)
Definition: Logger.cpp:414
static Logger::LogFunction endlog()
Definition: Logger.hpp:362
virtual base::ChannelElementBase * buildDataStorage(ConnPolicy const &policy) const
Definition: CorbaLib.cpp:116
virtual base::ChannelElementBase * buildChannelInput(base::OutputPortInterface &port, ConnPolicy const &policy) const
Definition: CorbaLib.cpp:131
virtual bool updateFromAny(const CORBA::Any *blob, DataSourceBase::shared_ptr target) const
Definition: CorbaLib.cpp:101


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:23