Service.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 Service.hpp
3 
4  Service.hpp - 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 #ifndef ORO_SERVICE_PROVIDER_HPP
40 #define ORO_SERVICE_PROVIDER_HPP
41 
42 #include "rtt-config.h"
43 #include "OperationInterface.hpp"
44 #include "DataFlowInterface.hpp"
48 #include "internal/UnMember.hpp"
50 
52 #include "Operation.hpp"
53 #include <boost/shared_ptr.hpp>
54 #include <boost/static_assert.hpp>
55 #include <boost/type_traits/function_traits.hpp>
56 #include <boost/function_types/components.hpp>
57 #include <boost/enable_shared_from_this.hpp>
58 #if BOOST_VERSION >= 104000 && BOOST_VERSION < 105300
59 #include <boost/smart_ptr/enable_shared_from_this2.hpp>
60 #endif
61 #if BOOST_VERSION >= 105300
62 #include <boost/smart_ptr/enable_shared_from_raw.hpp>
63 #endif
64 
65 namespace RTT
66 {
67  namespace internal {
68 #if BOOST_VERSION >= 104000
69 #if BOOST_VERSION < 105300
70  typedef boost::enable_shared_from_this2<Service> shared_from_raw;
71 #else
72  typedef boost::enable_shared_from_raw shared_from_raw;
73 #endif
74 #else
75  typedef boost::enable_shared_from_this<Service> shared_from_raw;
76 #endif
77  }
93  class RTT_API Service
94  : public OperationInterface,
96  public DataFlowInterface,
98  {
99  public:
101  typedef boost::shared_ptr<Service> shared_ptr;
102  typedef boost::shared_ptr<const Service> shared_constptr;
103  typedef std::vector<std::string> ProviderNames;
104 
105 #if BOOST_VERSION >= 105300
106  Service::shared_ptr shared_from_this() { return boost::shared_from_raw(this); }
107  Service::shared_constptr shared_from_this() const { return boost::shared_from_raw(this); }
108 #endif
109 
120  static Service::shared_ptr Create(const std::string& name, TaskContext* owner = 0);
121 
132  Service(const std::string& name, TaskContext* owner = 0);
133 
134  virtual ~Service();
135 
139  const std::string& getName() const { return mname; }
140 
144  const std::string& doc() const { return mdescription; }
145 
149  void doc(const std::string& description) { mdescription = description; }
150 
154  void setName(const std::string& name) { mname = name;}
155 
160  void setOwner(TaskContext* new_owner);
161 
166  void setParent(shared_ptr new_parent);
167 
171  shared_ptr getParent() const { return parent; }
172 
177  virtual ProviderNames getProviderNames() const;
178 
185  TaskContext* getOwner() const { return mowner; }
186 
191  ExecutionEngine* getOwnerExecutionEngine() const;
192 
204  virtual bool addService( shared_ptr obj );
205 
215  virtual void removeService( std::string const& service_name );
216 
223  Service::shared_ptr provides();
224 
234  Service::shared_ptr provides(const std::string& service_name);
235 
245  shared_ptr getService(const std::string& service_name);
246 
252  bool hasService(const std::string& service_name);
253 
260  void clear();
261 
266  std::vector<std::string> getOperationNames() const;
267 
272  bool hasOperation(const std::string& name) const;
273 
286  bool addLocalOperation( base::OperationBase& op );
287 
294  boost::shared_ptr<base::DisposableInterface> getLocalOperation( std::string name );
295 
306  OperationInterfacePart* getOperation( std::string name );
307 
311  void removeOperation( const std::string& name );
312 
329  bool setOperationThread(std::string const& name, ExecutionThread et);
330 
340  template<class Signature>
342  {
343  if ( this->addLocalOperation( op ) == false )
344  return op;
345  this->add( op.getName(), new internal::OperationInterfacePartFused<Signature>( &op ) );
346  return op;
347  }
348 
349 #ifdef ORO_SIGNALLING_OPERATIONS
350 
359  template<class Signature>
360  Operation<Signature>& addEventOperation( Operation<Signature>& op )
361  {
362  op.signals();
363  if ( this->addLocalOperation( op ) == false )
364  return op;
365  this->add( op.getName(), new internal::EventOperationInterfacePartFused<Signature>( &op ) );
366  return op;
367  }
368 #endif
369 
378  template<class Signature>
380  {
381  if ( this->addLocalOperation( op ) == false )
382  return op;
384  return op;
385  }
386 
400  template<class Func, class Class>
402  addOperation( const std::string name, Func func, Class* obj, ExecutionThread et = ClientThread )
403  {
404  typedef typename internal::GetSignature<Func>::Signature Signature;
405  Operation<Signature>* op = new Operation<Signature>(name, func, obj, et, this->getOwnerExecutionEngine() );
406  ownedoperations.push_back(op);
407  return addOperation( *op );
408  }
409 
421  template<class Func>
423  addOperation( const std::string name, Func* func, ExecutionThread et = ClientThread )
424  {
425  typedef Func Signature;
426  boost::function<Signature> bfunc = func;
427  Operation<Signature>* op = new Operation<Signature>(name, bfunc, et, this->getOwnerExecutionEngine() );
428  ownedoperations.push_back(op);
429  return addOperation( *op );
430  }
431 
432 #ifdef ORO_SIGNALLING_OPERATIONS
433 
444  template<class Func>
446  addEventOperation( const std::string name, Func* func, ExecutionThread et = ClientThread )
447  {
448  typedef Func Signature;
449  boost::function<Signature> bfunc = func;
450  Operation<Signature>* op = new Operation<Signature>(name, bfunc, et, this->getOwnerExecutionEngine() );
451  ownedoperations.push_back(op);
452  return addEventOperation( *op );
453  }
454 
467  template<class Func, class Class>
469  addEventOperation( const std::string name, Func func, Class* obj, ExecutionThread et = ClientThread )
470  {
471  typedef typename internal::GetSignature<Func>::Signature Signature;
472  Operation<Signature>* op = new Operation<Signature>(name, func, obj, et, this->getOwnerExecutionEngine() );
473  ownedoperations.push_back(op);
474  return addEventOperation( *op );
475  }
476 #endif
477 
490  template<class Func, class Class>
492  addSynchronousOperation( const std::string name, Func func, Class* obj, ExecutionThread et = ClientThread )
493  {
494  typedef typename internal::GetSignature<Func>::Signature Signature;
495  Operation<Signature>* op = new Operation<Signature>(name, func, obj, et, this->getOwnerExecutionEngine() );
496  ownedoperations.push_back(op);
497  return addSynchronousOperation( *op );
498  }
499 
505  template<class Func,class ObjT>
506  Operation< typename internal::GetSignatureDS<Func>::Signature>& addOperationDS( const std::string& name, Func func, internal::DataSource< boost::shared_ptr<ObjT> >* sp,
508  {
509  typedef typename internal::GetSignatureDS<Func>::Signature SignatureDS; // function signature with normal object pointer
510  Operation<SignatureDS>* op = new Operation<SignatureDS>(name, boost::function<SignatureDS>(func), et, this->getOwnerExecutionEngine() );
511  ownedoperations.push_back(op);
512  return addOperationDS( sp, *op );
513  }
514 
520  template<class Signature,class ObjT>
522  {
523  if ( this->addLocalOperation( op ) == false ) {
524  assert(false);
525  return op; // should never be reached.
526  }
527  this->add( op.getName(), new internal::OperationInterfacePartFusedDS<Signature,ObjT>( sp, &op) );
528  return op;
529  }
530 
541  const std::vector<base::DataSourceBase::shared_ptr>& args, ExecutionEngine* caller) const
542  {
543  return this->produce(name, args, caller);
544  }
545 
554  internal::OperationCallerC create(std::string name, ExecutionEngine* caller);
555 
559  bool resetOperation(std::string name, base::OperationBase* impl);
560  protected:
561  typedef std::map< std::string, shared_ptr > Services;
563  Services services;
564 
565  bool testOperation(base::OperationBase& op);
566  typedef std::map<std::string,base::OperationBase* > SimpleOperations;
567  typedef std::vector<base::OperationBase*> OperationList;
568  SimpleOperations simpleoperations;
569  OperationList ownedoperations;
570  std::string mname;
571  std::string mdescription;
573  shared_ptr parent;
574  };
575 }
576 
577 
578 #endif
const std::string & getName() const
Definition: Service.hpp:139
TaskContext * getOwner() const
Definition: Service.hpp:185
internal::ArgMember< typename boost::remove_pointer< FunctionT >::type >::type Signature
Operation< Signature > & addOperationDS(internal::DataSource< boost::shared_ptr< ObjT > > *sp, Operation< Signature > &op)
Definition: Service.hpp:521
boost::shared_ptr< const Service > shared_constptr
Definition: Service.hpp:102
Operation< Signature > & addOperation(Operation< Signature > &op)
Definition: Service.hpp:341
void setName(const std::string &name)
Definition: Service.hpp:154
shared_ptr getParent() const
Definition: Service.hpp:171
std::vector< std::string > ProviderNames
Definition: Service.hpp:103
Services services
the services we implement.
Definition: Service.hpp:563
Operation< typename internal::GetSignature< Func >::Signature > & addSynchronousOperation(const std::string name, Func func, Class *obj, ExecutionThread et=ClientThread)
Definition: Service.hpp:492
base::DataSourceBase::shared_ptr getOperation(std::string name, const std::vector< base::DataSourceBase::shared_ptr > &args, ExecutionEngine *caller) const
Definition: Service.hpp:540
std::string mdescription
Definition: Service.hpp:571
boost::shared_ptr< Service > shared_ptr
Definition: Service.hpp:101
Operation< Signature > & addSynchronousOperation(Operation< Signature > &op)
Definition: Service.hpp:379
void doc(const std::string &description)
Definition: Service.hpp:149
const std::string & doc() const
Definition: Service.hpp:144
std::map< std::string, base::OperationBase * > SimpleOperations
Definition: Service.hpp:566
SimpleOperations simpleoperations
Definition: Service.hpp:568
internal::UnMember< typename boost::remove_pointer< FunctionT >::type >::type Signature
std::vector< base::OperationBase * > OperationList
Definition: Service.hpp:567
A class for keeping track of Attribute, Constant and Property objects of a TaskContext. It allows plugins and remote components to browse the attributes and properties of a TaskContext.
TaskContext * mowner
Definition: Service.hpp:572
OperationList ownedoperations
Definition: Service.hpp:569
std::map< std::string, shared_ptr > Services
Definition: Service.hpp:561
Operation< typename internal::GetSignatureDS< Func >::Signature > & addOperationDS(const std::string &name, Func func, internal::DataSource< boost::shared_ptr< ObjT > > *sp, ExecutionThread et=ClientThread)
Definition: Service.hpp:506
boost::intrusive_ptr< DataSourceBase > shared_ptr
Operation< Func > & addOperation(const std::string name, Func *func, ExecutionThread et=ClientThread)
Definition: Service.hpp:423
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
const std::string & getName()
std::string mname
Definition: Service.hpp:570
OperationInterface Factory
Definition: Service.hpp:100
Holds all exported operations of a component and is able to produce callers for these operations...
Operation< typename internal::GetSignature< Func >::Signature > & addOperation(const std::string name, Func func, Class *obj, ExecutionThread et=ClientThread)
Definition: Service.hpp:402
boost::enable_shared_from_this< Service > shared_from_raw
Definition: Service.hpp:75
ExecutionThread
shared_ptr parent
Definition: Service.hpp:573


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