Orocos Real-Time Toolkit  2.9.0
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)
Once you defined your TypekitPlugin or TransportPlugin class, you can use this macro to make it avail...
The base class of the InputPort.
This protocol is used for all types which did not get a protocol.
Definition: CorbaLib.cpp:67
The Interface of a TaskContext which exposes its data-flow ports.
STL namespace.
const std::string & getName() const
Get the name of this Port.
For each transportable type T, specify the conversion functions.
virtual ChannelElementBase::shared_ptr createStream(base::PortInterface *port, const ConnPolicy &policy, bool is_sender) const
The CORBA transport does not support creating &#39;CORBA&#39; streams.
Definition: CorbaLib.cpp:110
Base class for CORBA channel servers.
Definition: DataFlowI.h:69
A connection policy object describes how a given connection should behave.
Definition: ConnPolicy.hpp:107
virtual CRemoteChannelElement_i * createChannelElement_i(DataFlowInterface *,::PortableServer::POA *poa, const ConnPolicy &) const
Builds a channel element for remote transport in both directions.
Definition: CorbaLib.cpp:118
The base class of each OutputPort.
basic_ostreams & endl(basic_ostreams &s)
Flush and newline.
Definition: rtstreams.cpp:110
Convenient short notation for every sub-namespace of RTT.
virtual base::DataSourceBase::shared_ptr createDataSource(const CORBA::Any *any) const
Create a Data Source from an any.
Definition: CorbaLib.cpp:93
A class for representing a user type, and which can build instances of that type. ...
Definition: TypeInfo.hpp:67
virtual base::DataSourceBase::shared_ptr createPropertyDataSource(CService_ptr serv, const std::string &vname)
Create a data source for an attribute or property.
Definition: CorbaLib.cpp:137
bool addProtocol(int protocol_id, TypeTransporter *tt)
Register a protocol for data transport over a network.
Definition: TypeInfo.cpp:137
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
Notify the Logger in which &#39;module&#39; the message occured.
Definition: Logger.hpp:159
#define ORO_CORBA_PROTOCOL_ID
Definition: CorbaLib.hpp:45
virtual bool updateAny(base::DataSourceBase::shared_ptr source, CORBA::Any &any) const
Evaluate source and update an any which contains the value of source.
Definition: CorbaLib.cpp:83
The CORBA transport plugin.
virtual CORBA::Any * createAny(DataSourceBase::shared_ptr source) const
Evaluate source and create an any which contains the value of source.
Definition: CorbaLib.cpp:73
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
In the data flow implementation, a channel is created by chaining ChannelElementBase objects...
The base class of every data flow port.
CorbaFallBackProtocol(bool do_warn=true)
Definition: CorbaLib.cpp:72
virtual base::ChannelElementBase * buildDataStorage(ConnPolicy const &policy) const
Definition: CorbaLib.cpp:116
Extends the TypeTransporter in order to allow the creation of channel elements or output halves for a...
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
Update target with the contents of blob which is an object of a protocol.
Definition: CorbaLib.cpp:101