ConnectionFactory.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Mar 2 08:30:17 CET 2006  ConnectionFactory.hpp
00003 
00004                         ConnectionFactory.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_CONNECTION_FACTORY_HPP
00040 #define ORO_EXECUTION_CONNECTION_FACTORY_HPP
00041 
00042 #include "ConnectionTypes.hpp"
00043 #include "rtt-config.h"
00044 
00045 namespace RTT
00046 {
00047     class PortInterface;
00048     template<class T>
00049     class BufferConnection;
00050     template<class T>
00051     class DataConnection;
00057     template<class T>
00058     class ConnectionFactory
00059     {
00060     public:
00076         BufferConnection<T>* createBuffer(int size, const T& initial_value = T(), ConnectionTypes::ConnectionType type = ConnectionTypes::lockfree);
00077 
00092         DataConnection<T>* createDataObject(const T& initial_value = T(), ConnectionTypes::ConnectionType type = ConnectionTypes::lockfree);
00093 
00094     };
00095 }
00096 #endif
00097 
00098 #ifndef ORO_CONNECTIONFACTORY_INLINE
00099 #define ORO_CONNECTIONFACTORY_INLINE
00100 #include "BufferConnection.hpp"
00101 #include "DataConnection.hpp"
00102 #include "BufferLocked.hpp"
00103 #include "BufferLockFree.hpp"
00104 #include "DataObjectInterfaces.hpp"
00105 
00106 namespace RTT
00107 {
00108 
00109         template<class T>
00110         BufferConnection<T>* ConnectionFactory<T>::createBuffer(int size, const T& initial_value, ConnectionTypes::ConnectionType type )
00111         {
00112             if (type == ConnectionTypes::lockfree)
00113                 return new BufferConnection<T>( typename BufferInterface<T>::shared_ptr(new BufferLockFree<T>(size, initial_value)) );
00114             if (type == ConnectionTypes::locked)
00115                 return new BufferConnection<T>( typename BufferInterface<T>::shared_ptr(new BufferLocked<T>(size, initial_value)) );
00116             return 0;
00117         }
00118 
00119         template<class T>
00120         DataConnection<T>* ConnectionFactory<T>::createDataObject(const T& initial_value, ConnectionTypes::ConnectionType type)
00121         {
00122             if (type == ConnectionTypes::lockfree)
00123                 return new DataConnection<T>( new DataObjectLockFree<T>("DataObject", initial_value) );
00124             if (type == ConnectionTypes::locked)
00125                 return new DataConnection<T>( new DataObjectLocked<T>("DataObject", initial_value) );
00126             return 0;
00127         }
00128 }
00129 #endif

Generated on Tue Aug 25 14:17:21 2009 for Orocos Real-Time Toolkit by  doxygen 1.5.8