Service.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:55:18 CEST 2010  Service.hpp
00003 
00004                         Service.hpp -  description
00005                            -------------------
00006     begin                : Tue September 07 2010
00007     copyright            : (C) 2010 The SourceWorks
00008     email                : peter@thesourceworks.com
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 
00039 #ifndef ORO_SERVICE_PROVIDER_HPP
00040 #define ORO_SERVICE_PROVIDER_HPP
00041 
00042 #include "rtt-config.h"
00043 #include "OperationInterface.hpp"
00044 #include "DataFlowInterface.hpp"
00045 #include "internal/OperationInterfacePartFused.hpp"
00046 #include "internal/LocalOperationCaller.hpp"
00047 #include "internal/OperationCallerC.hpp"
00048 #include "internal/UnMember.hpp"
00049 #include "internal/GetSignature.hpp"
00050 
00051 #include "ConfigurationInterface.hpp"
00052 #include "Operation.hpp"
00053 #ifdef ORO_REMOTING
00054 #include "internal/RemoteOperationCaller.hpp"
00055 #endif
00056 #include <boost/shared_ptr.hpp>
00057 #include <boost/static_assert.hpp>
00058 #include <boost/type_traits/function_traits.hpp>
00059 #include <boost/function_types/components.hpp>
00060 #include <boost/enable_shared_from_this.hpp>
00061 #if BOOST_VERSION >= 104000 && BOOST_VERSION <= 105030
00062 #include <boost/smart_ptr/enable_shared_from_this2.hpp>
00063 #endif
00064 
00065 namespace RTT
00066 {
00081     class RTT_API Service
00082         : public OperationInterface,
00083           public ConfigurationInterface,
00084           public DataFlowInterface,
00085 #if BOOST_VERSION >= 104000 && BOOST_VERSION <= 105030
00086           public boost::enable_shared_from_this2<Service>
00087 #else
00088           public boost::enable_shared_from_this<Service>
00089 #endif
00090     {
00091     public:
00092         typedef OperationInterface Factory;
00093         typedef boost::shared_ptr<Service> shared_ptr;
00094         typedef std::vector<std::string> ProviderNames;
00095 
00106         static Service::shared_ptr Create(const std::string& name, TaskContext* owner = 0);
00107 
00118         Service(const std::string& name, TaskContext* owner = 0);
00119 
00120         virtual ~Service();
00121 
00125         const std::string& getName() const { return mname; }
00126 
00130         const std::string& doc() const { return mdescription; }
00131 
00135         void doc(const std::string& description) { mdescription = description; }
00136 
00140         void setName(const std::string& name) { mname = name;}
00141 
00146         void setOwner(TaskContext* new_owner);
00147 
00152         void setParent(shared_ptr new_parent);
00153 
00157         shared_ptr getParent() const { return parent; }
00158 
00163         virtual ProviderNames getProviderNames() const;
00164 
00171         TaskContext* getOwner() const { return mowner; }
00172 
00177         ExecutionEngine* getOwnerExecutionEngine() const;
00178 
00187         virtual bool addService( shared_ptr obj );
00188 
00193         virtual void removeService( std::string const& service_name );
00194 
00199         Service::shared_ptr provides();
00200 
00206         Service::shared_ptr provides(const std::string& service_name);
00212         shared_ptr getService(const std::string& service_name);
00213 
00217         bool hasService(const std::string& service_name);
00218 
00223         void clear();
00224 
00229         std::vector<std::string> getOperationNames() const;
00230 
00235         bool hasOperation(const std::string& name) const;
00236 
00249         bool addLocalOperation( base::OperationBase& op );
00250 
00257         boost::shared_ptr<base::DisposableInterface> getLocalOperation( std::string name );
00258 
00269         OperationInterfacePart* getOperation( std::string name );
00270 
00274         void removeOperation( const std::string& name );
00275 
00292         bool setOperationThread(std::string const& name, ExecutionThread et);
00293 
00303         template<class Signature>
00304         Operation<Signature>& addOperation( Operation<Signature>& op )
00305         {
00306             if ( this->addLocalOperation( op ) == false )
00307                 return op;
00308             this->add( op.getName(), new internal::OperationInterfacePartFused<Signature>( &op ) );
00309             return op;
00310         }
00311 
00320         template<class Signature>
00321         Operation<Signature>& addSynchronousOperation( Operation<Signature>& op )
00322         {
00323             if ( this->addLocalOperation( op ) == false )
00324                 return op;
00325             this->add( op.getName(), new internal::SynchronousOperationInterfacePartFused<Signature>( &op ) );
00326             return op;
00327         }
00328 
00342         template<class Func, class Service>
00343         Operation< typename internal::GetSignature<Func>::Signature >&
00344         addOperation( const std::string name, Func func, Service* serv, ExecutionThread et = ClientThread )
00345         {
00346             typedef typename internal::GetSignature<Func>::Signature Signature;
00347             Operation<Signature>* op = new Operation<Signature>(name, func, serv, et, this->getOwnerExecutionEngine() );
00348             ownedoperations.push_back(op);
00349             return addOperation( *op );
00350         }
00351 
00363         template<class Func>
00364         Operation< Func >&
00365         addOperation( const std::string name, Func* func, ExecutionThread et = ClientThread )
00366         {
00367             typedef Func Signature;
00368             boost::function<Signature> bfunc = func;
00369             Operation<Signature>* op = new Operation<Signature>(name, bfunc, et, this->getOwnerExecutionEngine() );
00370             ownedoperations.push_back(op);
00371             return addOperation( *op );
00372         }
00373 
00386         template<class Func, class Service>
00387         Operation< typename internal::GetSignature<Func>::Signature >&
00388         addSynchronousOperation( const std::string name, Func func, Service* serv, ExecutionThread et = ClientThread )
00389         {
00390             typedef typename internal::GetSignature<Func>::Signature Signature;
00391             Operation<Signature>* op = new Operation<Signature>(name, func, serv, et, this->getOwnerExecutionEngine() );
00392             ownedoperations.push_back(op);
00393             return addSynchronousOperation( *op );
00394         }
00395 
00401         template<class Func,class ObjT>
00402         Operation< typename internal::GetSignatureDS<Func>::Signature>& addOperationDS( const std::string& name, Func func, internal::DataSource< boost::shared_ptr<ObjT> >* sp,
00403                 ExecutionThread et = ClientThread)
00404         {
00405             typedef typename internal::GetSignatureDS<Func>::Signature SignatureDS;    // function signature with normal object pointer
00406             Operation<SignatureDS>* op = new Operation<SignatureDS>(name, boost::function<SignatureDS>(func), et, this->getOwnerExecutionEngine() );
00407             ownedoperations.push_back(op);
00408             return addOperationDS( sp, *op );
00409         }
00410 
00416         template<class Signature,class ObjT>
00417         Operation<Signature>& addOperationDS( internal::DataSource< boost::shared_ptr<ObjT> >* sp, Operation<Signature>& op)
00418         {
00419             if ( this->addLocalOperation( op ) == false ) {
00420                 assert(false);
00421                 return op; // should never be reached.
00422             }
00423             this->add( op.getName(), new internal::OperationInterfacePartFusedDS<Signature,ObjT>( sp, &op) );
00424             return op;
00425         }
00426 
00436         base::DataSourceBase::shared_ptr getOperation( std::string name,
00437                                    const std::vector<base::DataSourceBase::shared_ptr>& args, ExecutionEngine* caller) const
00438         {
00439             return this->produce(name, args, caller);
00440         }
00441 
00450         internal::OperationCallerC create(std::string name, ExecutionEngine* caller);
00451 
00455         bool resetOperation(std::string name, base::OperationBase* impl);
00456     protected:
00457         typedef std::map< std::string, shared_ptr > Services;
00459         Services services;
00460 
00461         bool testOperation(base::OperationBase& op);
00462         typedef std::map<std::string,base::OperationBase* > SimpleOperations;
00463         typedef std::vector<base::OperationBase*> OperationList;
00464         SimpleOperations simpleoperations;
00465         OperationList ownedoperations;
00466         std::string mname;
00467         std::string mdescription;
00468         TaskContext* mowner;
00469         shared_ptr parent;
00470     };
00471 }
00472 
00473 
00474 #endif


rtt
Author(s): RTT Developers
autogenerated on Thu Jan 2 2014 11:35:25