Orocos Real-Time Toolkit  2.8.3
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, bool) 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  }
124 
126  ConnPolicy const& policy) const {
127  Logger::In in("CorbaFallBackProtocol");
128  log(Error) << "Could create outputHalf for port "<<port.getName()<<": data type not known to CORBA Transport." <<Logger::endl;
129  return 0;
130  }
131 
133  ConnPolicy const& policy) const {
134  Logger::In in("CorbaFallBackProtocol");
135  log(Error) << "Could create outputHalf for port "<<port.getName()<<": data type not known to CORBA Transport." <<Logger::endl;
136  return 0;
137  }
138  virtual base::DataSourceBase::shared_ptr createPropertyDataSource(CService_ptr serv, const std::string& vname) {
139  CORBA::String_var tname = serv->getPropertyTypeName( CORBA::string_dup(vname.c_str()));
140  log(Warning) << "Corba: Remote property '"<< vname << "' has unknown type " << tname.in() << endlog();
142  }
143 
144  virtual base::DataSourceBase::shared_ptr createAttributeDataSource(CService_ptr serv, const std::string& vname) {
145  CORBA::String_var tname = serv->getAttributeTypeName( CORBA::string_dup( vname.c_str()));
146  log(Warning) << "Corba: Remote attribute '"<< vname << "' has unknown type " << tname.in() << endlog();
148  }
149  };
150 
151  bool CorbaLibPlugin::registerTransport(std::string name, TypeInfo* ti)
152  {
153  if ( name == "unknown_t") // register fallback also.
155  if ( name == "int" )
157  if ( name == "double" )
159  if ( name == "float" )
161  if ( name == "uint" )
163  if ( name == "char" )
165  //if ( name == "long" )
166  // return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<long>() );
167 // if ( name == "PropertyBag" )
168 // return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol<PropertyBag>() );
169  if ( name == "bool" )
171 #ifndef RTT_NO_STD_TYPES
172  if ( name == "string" )
174  if ( name == "array" )
175  return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaTemplateProtocol< std::vector<double> >() );
176 #endif
177 #ifdef OS_RT_MALLOC
178  if ( name == "rt_string")
180 #endif
181  if ( name == "void" )
182  return ti->addProtocol(ORO_CORBA_PROTOCOL_ID, new CorbaFallBackProtocol(false)); // warn=false
183  if ( name == "ConnPolicy")
185  if ( name == "TaskContext")
187 
188  return false;
189  }
190 
191  std::string CorbaLibPlugin::getTransportName() const {
192  return "CORBA";
193  }
194 
195  std::string CorbaLibPlugin::getTypekitName() const {
196  return "rtt-types";
197  }
198 
199  std::string CorbaLibPlugin::getName() const {
200  return "rtt-corba-types";
201  }
202  }
203 }
204 
#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
virtual base::DataSourceBase::shared_ptr createAttributeDataSource(CService_ptr serv, const std::string &vname)
Definition: CorbaLib.cpp:144
Base class for CORBA channel servers.
Definition: DataFlowI.h:69
A connection policy object describes how a given connection should behave.
Definition: ConnPolicy.hpp:92
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
virtual CRemoteChannelElement_i * createChannelElement_i(DataFlowInterface *,::PortableServer::POA *poa, bool) const
Builds a channel element for remote transport in both directions.
Definition: CorbaLib.cpp:118
A class for representing a user type, and which can build instances of that type. ...
Definition: TypeInfo.hpp:66
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:138
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:125
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:51
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:132
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