Orocos Real-Time Toolkit  2.6.0
DataFlowInterface.hpp
00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Mar 2 08:30:18 CET 2006  DataFlowInterface.hpp
00003 
00004                         DataFlowInterface.hpp -  description
00005                            -------------------
00006     begin                : Thu March 02 2006
00007     copyright            : (C) 2006 Peter Soetens
00008     email                : peter.soetens@fmtc.be
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_EXECUTION_DATA_FLOW_INTERFACE_HPP
00040 #define ORO_EXECUTION_DATA_FLOW_INTERFACE_HPP
00041 
00042 #include <vector>
00043 #include <map>
00044 #include <string>
00045 #include "base/InputPortInterface.hpp"
00046 #include "base/OutputPortInterface.hpp"
00047 #include "rtt-fwd.hpp"
00048 #include <boost/function.hpp>
00049 
00050 namespace RTT
00051 {
00052 
00059     class RTT_API DataFlowInterface
00060     {
00061     public:
00065         typedef std::vector<base::PortInterface*> Ports;
00066 
00070         typedef std::vector<std::string> PortNames;
00071 
00072         typedef boost::function<void(base::PortInterface*)> SlotFunction;
00073 
00079         DataFlowInterface(Service* parent = 0 );
00080 
00081         ~DataFlowInterface();
00082 
00089         base::PortInterface& addPort(const std::string& name, base::PortInterface& port) {
00090             if ( !chkPtr("addPort", name, &port) ) return port;
00091             port.setName(name);
00092             return addPort(port);
00093         }
00094 
00103         base::PortInterface& addPort(base::PortInterface& port);
00104 
00114         base::InputPortInterface& addEventPort(const std::string& name, base::InputPortInterface& port, SlotFunction callback = SlotFunction() ) {
00115             if ( !chkPtr("addEventPort", name, &port) ) return port;
00116             port.setName(name);
00117             return addEventPort(port,callback);
00118         }
00119 
00132         base::InputPortInterface& addEventPort(base::InputPortInterface& port, SlotFunction callback = SlotFunction() );
00133 
00140         void removePort(const std::string& name);
00141 
00146         Ports getPorts() const;
00147 
00153         PortNames getPortNames() const;
00154 
00160         base::PortInterface* getPort(const std::string& name) const;
00161 
00169         std::string getPortDescription(const std::string& name) const;
00170 
00181         bool setPortDescription(const std::string& name, const std::string description);
00182 
00186         TaskContext* getOwner() const;
00187 
00193         Service* getService() const { return mservice; }
00194 
00201         base::PortInterface& addLocalPort(base::PortInterface& port);
00202 
00215         base::InputPortInterface& addLocalEventPort(base::InputPortInterface& port,
00216                 SlotFunction callback = SlotFunction() );
00217 
00221         template< class Type>
00222         Type* getPortType(const std::string& name) {
00223             return dynamic_cast<Type*>( this->getPort(name) );
00224         }
00225 
00230         void clear();
00231 
00232 #ifdef ORO_SIGNALLING_PORTS
00233 
00236         void setupHandles();
00240         void cleanupHandles();
00241 #else
00242 
00245         void dataOnPort(base::PortInterface* port);
00246 #endif
00247     protected:
00252         Service* createPortObject(const std::string& name);
00253 
00254         bool chkPtr(const std::string &where, const std::string& name, const void* ptr);
00258         Ports mports;
00262         Service* mservice;
00263 #ifdef ORO_SIGNALLING_PORTS
00264 
00268         typedef std::vector< Handle > Handles;
00269         Handles handles;
00270 #endif
00271 
00272     };
00273 
00274 }
00275 
00276 #endif