OperationInterfaceI.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 OperationInterfaceI.cpp
3 
4  OperationInterfaceI.cpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
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 // -*- C++ -*-
40 //
41 // $Id$
42 
43 // **** Code generated by the The ACE ORB (TAO) IDL Compiler ****
44 // TAO and the TAO IDL Compiler have been developed by:
45 // Center for Distributed Object Computing
46 // Washington University
47 // St. Louis, MO
48 // USA
49 // http://www.cs.wustl.edu/~schmidt/doc-center.html
50 // and
51 // Distributed Object Computing Laboratory
52 // University of California at Irvine
53 // Irvine, CA
54 // USA
55 // http://doc.ece.uci.edu/
56 // and
57 // Institute for Software Integrated Systems
58 // Vanderbilt University
59 // Nashville, TN
60 // USA
61 // http://www.isis.vanderbilt.edu/
62 //
63 // Information about TAO is available at:
64 // http://www.cs.wustl.edu/~schmidt/TAO.html
65 
66 // TAO_IDL - Generated from
67 // ../../../ACE_wrappers/TAO/TAO_IDL/be/be_codegen.cpp:1196
68 
69 #include "CorbaLib.hpp"
70 #include "CorbaTypeTransporter.hpp"
71 #include "OperationInterfaceI.h"
72 #include "AnyDataSource.hpp"
73 #include "../../rtt-detail-fwd.hpp"
74 #include "../../internal/OperationCallerC.hpp"
75 #include "../../internal/SendHandleC.hpp"
76 #include "../../Logger.hpp"
77 #include "../../internal/GlobalEngine.hpp"
78 #include "../../plugin/PluginLoader.hpp"
79 
80 using namespace RTT;
81 using namespace RTT::detail;
82 using namespace std;
83 
85 : mhandle(sh), morig(sh), mofp(ofp)
86 {
87  // this will always be correct:
88  for (unsigned int i = 1; i <= mofp->collectArity(); ++i) {
89  const TypeInfo* ti = mofp->getCollectType(i); // retrieve 1..collectArity()
90  assert(ti);
91  cargs.push_back( ti->buildValue() );
92  mhandle.arg( cargs.back() );
93  }
94  assert( mhandle.ready() );
95 }
96 
98 {
99 }
100 
107 bool anysequence_to_sourcevector( CAnyArguments const& anys, vector<DataSourceBase::shared_ptr>& sources) {
108  return false;
109 }
110 
117 bool sourcevector_to_anysequence( vector<DataSourceBase::shared_ptr> const& sources, CAnyArguments & anys ) {
118  bool valid = true;
119  anys.length( sources.size() );
120  for(unsigned int i = 0; i != sources.size(); ++i) {
121  const TypeInfo* ti = sources[i]->getTypeInfo();
123  ctt->updateAny(sources[i], anys[i]);
124  }
125  return valid;
126 }
127 
128 ::RTT::corba::CSendStatus RTT_corba_CSendHandle_i::collect (
129  ::RTT::corba::CAnyArguments_out args)
130 {
131  try {
132  SendStatus ss = mhandle.collect();
133  args = new CAnyArguments();
134  if (ss == SendSuccess) {
135  sourcevector_to_anysequence( cargs, *args.ptr() );
136  }
137  return CSendStatus(static_cast<int>(ss) + 2);
138  } catch(std::runtime_error& e) {
139  throw ::RTT::corba::CCallError(e.what());
140  }
141 }
142 
143 ::RTT::corba::CSendStatus RTT_corba_CSendHandle_i::collectIfDone (
144  ::RTT::corba::CAnyArguments_out args)
145 {
146  try {
148  args = new CAnyArguments();
149  if (ss == SendSuccess) {
150  sourcevector_to_anysequence( cargs, *args.ptr() );
151  }
152  return CSendStatus(static_cast<int>(ss) + 2);
153  } catch(std::runtime_error& e) {
154  throw ::RTT::corba::CCallError(e.what());
155  }
156 }
157 
158 ::RTT::corba::CSendStatus RTT_corba_CSendHandle_i::checkStatus (
159  void)
160 {
161  return CSendStatus( static_cast<int>(mhandle.collectIfDone()) + 2 );
162 }
163 
165  void)
166 {
167  try {
169  // We just copy over the first collectable argument. In
170  // case of a void operation, we will thus return the first
171  // reference argument.
172  if (ss == SendSuccess) {
173  if ( cargs.size() > 0) {
174  CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*> (cargs[0]->getTypeInfo()->getProtocol(ORO_CORBA_PROTOCOL_ID));
175  return ctt->createAny( cargs[0] );
176  }
177  }
178  return new CORBA::Any();
179  } catch(std::runtime_error& e) {
180  throw ::RTT::corba::CCallError(e.what());
181  }
182 }
183 
185  const ::RTT::corba::CAnyArguments & args)
186 {
187  try {
188  SendHandleC shc(morig);
189  for (unsigned int i = 0; i != mofp->collectArity(); ++i) {
190  const TypeInfo* ti = mofp->getCollectType(i + 1);
191  assert(ti);
193  shc.arg(ctt->createDataSource(&args[i]));
194  }
195  // otherwise, we would block !!!
196  shc.setAutoCollect(false);
197  shc.check();
198  } catch (name_not_found_exception& nnf) {
199  throw ::RTT::corba::CNoSuchNameException(nnf.name.c_str());
200  } catch (wrong_number_of_args_exception& wna) {
201  throw ::RTT::corba::CWrongNumbArgException(wna.wanted, wna.received);
202  } catch (wrong_types_of_args_exception& wta) {
203  throw ::RTT::corba::CWrongTypeArgException(wta.whicharg, wta.expected_.c_str(), wta.received_.c_str());
204  }
205 }
206 
208  void)
209 {
210  PortableServer::POA_var mPOA = _default_POA();
211  PortableServer::ObjectId_var oid = mPOA->servant_to_id(this);
212  mPOA->deactivate_object( oid.in() );
213  return;
214 }
215 
216 // Implementation skeleton constructor
218  : mfact(gmf), mpoa( PortableServer::POA::_duplicate(the_poa)),
219  loadPluginOperation("loadPlugin", &RTT_corba_COperationInterface_i::loadPlugin, this),
220  loadPluginOperationPart(&loadPluginOperation)
221 {
222  loadPluginOperation.doc("Loads a RTT plugin.").arg("plugin_path", "The path to the shared library containing the plugin.");
223 }
224 
226 {
227  return PortableServer::POA::_duplicate(mpoa);
228 }
229 
230 
231 // Implementation skeleton destructor
233 {
234 }
235 
236 ::RTT::corba::COperationInterface::COperationDescriptions * RTT_corba_COperationInterface_i::getOperations (
237  void)
238 {
239  RTT::corba::COperationInterface::COperationDescriptions_var rlist = new RTT::corba::COperationInterface::COperationDescriptions();
240 
241  vector<string> flist = mfact->getNames();
242  flist.push_back(loadPluginOperationPart.getName());
243  rlist->length( flist.size() );
244  size_t drops=0;
245  for (size_t i=0; i != flist.size(); ++i)
246  if ( !mfact->isSynchronous(flist[i]) ) {
247  RTT::OperationInterfacePart *op = findOperation( flist[i].c_str() );
248  rlist[i - drops].name = CORBA::string_dup( flist[i].c_str() );
249  rlist[i - drops].description = CORBA::string_dup( op->description().c_str() );
250  ::RTT::corba::CArgumentDescriptions_var arguments = getArguments( flist[i].c_str() );
251  rlist[i - drops].arguments = arguments;
252  ::RTT::corba::CTypeList_var collect_types = getCollectTypes( flist[i].c_str() );
253  rlist[i - drops].collect_types = collect_types;
254  rlist[i - drops].result_type = CORBA::string_dup( op->resultType().c_str() );
255  rlist[i - drops].send_oneway = (op->collectArity() == 0);
256 
257  } else {
258  ++drops;
259  }
260  rlist->length( flist.size() - drops); // we don't show the synchronous operations.
261  return rlist._retn();
262 }
263 
264 ::RTT::corba::CArgumentDescriptions * RTT_corba_COperationInterface_i::getArguments (
265  const char * operation)
266 {
267  CArgumentDescriptions_var ret = new CArgumentDescriptions();
268  OperationInterfacePart* mofp = findOperation(operation);
269  // operation found, convert args:
271  ret->length( args.size() );
272  for (size_t i =0; i != args.size(); ++i) {
273  ret[i].name = CORBA::string_dup( args[i].name.c_str() );
274  ret[i].description = CORBA::string_dup( args[i].description.c_str() );
275  ret[i].type = CORBA::string_dup( args[i].type.c_str() );
276  }
277  return ret._retn();
278 }
279 
281  const char * operation)
282 {
283  ::RTT::corba::CTypeList_var ret = new ::RTT::corba::CTypeList();
284  OperationInterfacePart* mofp = findOperation(operation);
285 
286  // operation found, convert args:
287  ret->length( mofp->collectArity() );
288  for (size_t i = 0; i != mofp->collectArity(); ++i) {
289  ret[i] = CORBA::string_dup( mofp->getCollectType(i+1)->getTypeName().c_str() );
290  }
291  return ret._retn();
292 }
293 
295  const char * operation)
296 {
297  OperationInterfacePart* mofp = findOperation(operation);
298  return CORBA::string_dup( mofp->resultType().c_str() );
299 }
300 
302  const char* operation,
303  CORBA::UShort nbr)
304 {
305  OperationInterfacePart* mofp = findOperation(operation);
306  if ( nbr > mofp->arity() )
307  throw ::RTT::corba::CWrongArgumentException( nbr, mofp->arity() );
308  return CORBA::string_dup( mofp->getArgumentType(nbr)->getTypeName().c_str() );
309 }
310 
312  const char* operation,
313  CORBA::UShort nbr)
314 {
315  OperationInterfacePart* mofp = findOperation(operation);
316  if ( nbr > mofp->collectArity() )
317  throw ::RTT::corba::CWrongArgumentException( nbr, mofp->collectArity() );
318  return CORBA::string_dup( mofp->getCollectType(nbr)->getTypeName().c_str() );
319 
320 }
321 
323  const char * operation)
324 {
325  OperationInterfacePart* mofp = findOperation(operation);
326  return mofp->arity();
327 }
328 
330  const char * operation)
331 {
332  OperationInterfacePart* mofp = findOperation(operation);
333  return mofp->collectArity();
334 }
335 
337  const char * operation)
338 {
339  OperationInterfacePart* mofp = findOperation(operation);
340  return CORBA::string_dup( mofp->description().c_str() );
341 }
342 
344  const char * operation,
345  const ::RTT::corba::CAnyArguments & args)
346 {
347  OperationInterfacePart* mofp = findOperation(operation);
348 
349  try {
350  OperationCallerC mc(mofp, operation, internal::GlobalEngine::Instance());
351  for (unsigned int i = 0; i < mofp->arity() && i < args.length(); ++i) {
352  const TypeInfo* ti = mofp->getArgumentType(i+1);
353  assert(ti);
355  if (ctt) {
356  DataSourceBase::shared_ptr ds = ctt->createDataSource(&args[i]);
357  if (ds)
358  mc.arg(ds);
359  else {
360  log(Error) << "Registered transport for type "<< ti->getTypeName()
361  << " could not create data source from Any (argument "<< i+1
362  <<"): calling operation '"<< operation <<"' will fail." <<endlog();
363  }
364  } else {
365  throw wrong_types_of_args_exception(i+1,"type known to CORBA", ti->getTypeName());
366  }
367  }
368  mc.check();
370  throw ::RTT::corba::CNoSuchNameException(operation);
371  } catch (name_not_found_exception& nnf) {
372  throw ::RTT::corba::CNoSuchNameException(nnf.name.c_str());
373  } catch (wrong_number_of_args_exception& wna) {
374  throw ::RTT::corba::CWrongNumbArgException(wna.wanted, wna.received);
375  } catch (wrong_types_of_args_exception& wta) {
376  throw ::RTT::corba::CWrongTypeArgException(wta.whicharg, wta.expected_.c_str(), wta.received_.c_str());
377  }
378 }
379 
381  const char * operation,
382  ::RTT::corba::CAnyArguments & args)
383 {
384  OperationInterfacePart* mofp = findOperation(operation);
385 
386  // convert Corba args to C++ args.
387  try {
388  OperationCallerC orig(mofp, operation, internal::GlobalEngine::Instance());
389  vector<DataSourceBase::shared_ptr> results;
390  for (size_t i =0; i != args.length(); ++i) {
391  const TypeInfo* ti = mofp->getArgumentType( i + 1);
393  // we need to store the results for returning them to caller (args is inout!) after the call()
394  results.push_back( ctt->createDataSource( &args[i] ) );
395  orig.arg( results[i] );
396  }
397  if ( orig.ready() ) {
399  CORBA::Any* retany;
400 
401  // Try to get the return result :
402  const TypeInfo* ti = ds->getTypeInfo();
404  if ( !ctt ) {
405  log(Warning) << "Could not return results of call to " << operation << ": unknown return type by CORBA transport."<<endlog();
406  ds->evaluate(); // equivalent to orig.call()
407  retany = new CORBA::Any();
408  } else {
409  retany = ctt->createAny( ds ); // call evaluate internally
410  }
411 
412  // Return results into args:
413  for (size_t i =0; i != args.length(); ++i) {
414  const TypeInfo* ti = mofp->getArgumentType( i + 1);
416  ctta->updateAny(results[i], args[i]);
417  }
418  return retany;
419  } else {
420  orig.check(); // will throw
421  }
423  throw ::RTT::corba::CNoSuchNameException( operation );
424  } catch ( name_not_found_exception& ) {
425  throw ::RTT::corba::CNoSuchNameException( operation );
426  } catch ( wrong_number_of_args_exception& wna ) {
427  throw ::RTT::corba::CWrongNumbArgException( wna.wanted, wna.received );
428  } catch (wrong_types_of_args_exception& wta ) {
429  throw ::RTT::corba::CWrongTypeArgException( wta.whicharg, wta.expected_.c_str(), wta.received_.c_str() );
430  } catch (std::runtime_error& e){
431  throw ::RTT::corba::CCallError(e.what());
432  }
433  return new ::CORBA::Any();
434 }
435 
437  const char * operation,
438  const ::RTT::corba::CAnyArguments & args)
439 {
440  // This implementation is 90% identical to callOperation above, only deviating in the orig.ready() part.
441  OperationInterfacePart* mofp = findOperation(operation);
442 
443  // convert Corba args to C++ args.
444  try {
445  OperationCallerC orig(mofp, operation, internal::GlobalEngine::Instance());
446  for (size_t i =0; i != args.length(); ++i) {
447  const TypeInfo* ti = mofp->getArgumentType( i + 1);
449  orig.arg( ctt->createDataSource( &args[i] ));
450  }
451  if ( orig.ready() ) {
452  SendHandleC resulthandle = orig.send();
453  // we may not destroy the SendHandle, before the operation completes:
454  resulthandle.setAutoCollect(true);
455  RTT_corba_CSendHandle_i* ret_i = new RTT_corba_CSendHandle_i( resulthandle, mofp );
456  return ret_i;
457  } else {
458  orig.check(); // will throw
459  }
461  throw ::RTT::corba::CNoSuchNameException( operation );
462  } catch ( name_not_found_exception& ) {
463  throw ::RTT::corba::CNoSuchNameException( operation );
464  } catch ( wrong_number_of_args_exception& wna ) {
465  throw ::RTT::corba::CWrongNumbArgException( wna.wanted, wna.received );
466  } catch (wrong_types_of_args_exception& wta ) {
467  throw ::RTT::corba::CWrongTypeArgException( wta.whicharg, wta.expected_.c_str(), wta.received_.c_str() );
468  }
469  return 0;
470 }
471 
472 ::RTT::corba::CSendHandle_ptr RTT_corba_COperationInterface_i::sendOperation (
473  const char * operation,
474  const ::RTT::corba::CAnyArguments & args)
475 {
476  RTT_corba_CSendHandle_i* ret_i = sendOperationInternal(operation, args);
477  if (ret_i) {
478  // our resulthandle copy makes sure that the resulthandle can return.
479  CSendHandle_var ret = ret_i->_this();
480  ret_i->_remove_ref(); // if POA drops this, it gets cleaned up.
481  return ret._retn();
482  } else {
483  return CSendHandle::_nil();
484  }
485 }
486 
488  const char * operation,
489  const ::RTT::corba::CAnyArguments & args)
490 {
491  RTT_corba_CSendHandle_i* ret_i = 0;
492 
493  try {
494  ret_i = sendOperationInternal(operation, args);
495 
496  if (!ret_i || ret_i->checkStatus() == CSendFailure) {
497  log(Error) << "Sending the '" << operation << "'' operation failed (SendFailure)." << endlog();
498  }
499  } catch(std::exception &e) {
500  log(Error) << "Sending the '" << operation << "'' operation failed:" << e.what() << endlog();
501  }
502 
503  if (ret_i) ret_i->_remove_ref(); // Drop the CSendHandle
504 }
505 
507 {
508  string operation_str(operation);
509  OperationInterfacePart* mofp = mfact->getPart(operation_str);
510  if ( !mofp && (operation_str == "loadPlugin") )
511  mofp = &loadPluginOperationPart;
512  if ( !mofp || mfact->isSynchronous(operation_str) )
513  throw ::RTT::corba::CNoSuchNameException( operation );
514  return mofp;
515 }
516 
517 bool RTT_corba_COperationInterface_i::loadPlugin(const string &pluginPath) {
518  return RTT::plugin::PluginLoader::Instance()->loadPlugin(pluginPath, "");
519 }
virtual ::RTT::corba::CSendStatus collect(::RTT::corba::CAnyArguments_out args)
RTT::internal::SendHandleC mhandle
OperationCallerC & arg(base::DataSourceBase::shared_ptr a)
base::DataSourceBase::shared_ptr getCallDataSource()
virtual ::RTT::corba::CSendStatus collectIfDone(::RTT::corba::CAnyArguments_out args)
Operation< Signature > & doc(const std::string &description)
Definition: Operation.hpp:128
RTT_corba_CSendHandle_i * sendOperationInternal(const char *operation, const ::RTT::corba::CAnyArguments &args)
virtual char * getDescription(const char *operation)
virtual char * getResultType(const char *operation)
virtual const types::TypeInfo * getArgumentType(unsigned int arg) const =0
const std::string & getTypeName() const
Definition: TypeInfo.hpp:83
virtual char * getArgumentType(const char *, CORBA::UShort)
RTT::Operation< bool(std::string)> loadPluginOperation
virtual ~RTT_corba_CSendHandle_i(void)
virtual ::RTT::corba::CSendStatus checkStatus(void)
std::vector< RTT::base::DataSourceBase::shared_ptr > cargs
bool loadPlugin(const std::string &pluginPath)
virtual CORBA::Any_ptr createAny(base::DataSourceBase::shared_ptr source) const =0
Definition: mystd.hpp:163
virtual const types::TypeInfo * getCollectType(unsigned int arg) const =0
void setAutoCollect(bool on_off)
virtual ::CORBA::Any * callOperation(const char *operation,::RTT::corba::CAnyArguments &args)
virtual std::string description() const =0
bool isSynchronous(const std::string &name) const
virtual char * getCollectType(const char *, CORBA::UShort)
RTT::OperationInterface * mfact
virtual ::CORBA::Any * ret(void)
SendStatus
Definition: SendStatus.hpp:53
virtual ::CORBA::UShort getCollectArity(const char *operation)
virtual ::CORBA::UShort getArity(const char *operation)
virtual unsigned int arity() const =0
virtual RTT::corba::COperationInterface::COperationDescriptions * getOperations(void)
OperationInterfacePart * getPart(const std::string &name)
RTT::OperationInterfacePart * findOperation(const char *operation)
SendHandleC & arg(base::DataSourceBase::shared_ptr a)
std::vector< ArgumentDescription > Descriptions
virtual void sendOperationOneway(const char *operation, const ::RTT::corba::CAnyArguments &args)
bool anysequence_to_sourcevector(CAnyArguments const &anys, vector< DataSourceBase::shared_ptr > &sources)
virtual void checkOperation(const char *operation, const ::RTT::corba::CAnyArguments &args)
Operation< Signature > & arg(const std::string &name, const std::string &description)
Definition: Operation.hpp:137
virtual std::string resultType() const =0
PortableServer::POA_ptr _default_POA()
virtual std::vector< ArgumentDescription > getArgumentList() const =0
TypeTransporter * getProtocol(int protocol_id) const
Definition: TypeInfo.cpp:150
RTT::internal::OperationInterfacePartFused< bool(std::string)> loadPluginOperationPart
std::vector< std::string > getNames() const
RTT_corba_COperationInterface_i(RTT::OperationInterface *mfact, PortableServer::POA_ptr the_poa)
virtual unsigned int collectArity() const =0
#define ORO_CORBA_PROTOCOL_ID
Definition: CorbaLib.hpp:45
virtual base::DataSourceBase::shared_ptr createDataSource(const CORBA::Any *any) const =0
base::DataSourceBase::shared_ptr buildValue() const
Definition: TypeInfo.hpp:230
virtual ::RTT::corba::CTypeList * getCollectTypes(const char *operation)
bool sourcevector_to_anysequence(vector< DataSourceBase::shared_ptr > const &sources, CAnyArguments &anys)
static boost::shared_ptr< PluginLoader > Instance()
boost::intrusive_ptr< DataSourceBase > shared_ptr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
virtual ::RTT::corba::CArgumentDescriptions * getArguments(const char *operation)
virtual void checkArguments(const ::RTT::corba::CAnyArguments &args)
RTT_corba_CSendHandle_i(RTT::internal::SendHandleC const &sh, RTT::OperationInterfacePart *ofp)
static Logger & log()
Definition: Logger.hpp:350
RTT::OperationInterfacePart * mofp
Holds all exported operations of a component and is able to produce callers for these operations...
virtual ::RTT::corba::CSendHandle_ptr sendOperation(const char *operation, const ::RTT::corba::CAnyArguments &args)
virtual bool updateAny(base::DataSourceBase::shared_ptr source, CORBA::Any &any) const =0
static Logger::LogFunction endlog()
Definition: Logger.hpp:362
RTT::internal::SendHandleC morig


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:34