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 #ifndef OROBLD_OS_NO_ASM
00103 #include "BufferLockFree.hpp"
00104 #endif
00105 #include "BufferLocked.hpp"
00106 #include "DataObjectInterfaces.hpp"
00107 
00108 namespace RTT
00109 {
00110 
00111         template<class T>
00112         BufferConnection<T>* ConnectionFactory<T>::createBuffer(int size, const T& initial_value, ConnectionTypes::ConnectionType type )
00113         {
00114 #ifndef OROBLD_OS_NO_ASM
00115             if (type == ConnectionTypes::lockfree)
00116                 return new BufferConnection<T>( typename BufferInterface<T>::shared_ptr(new BufferLockFree<T>(size, initial_value)) );
00117             if (type == ConnectionTypes::locked)
00118                 return new BufferConnection<T>( typename BufferInterface<T>::shared_ptr(new BufferLocked<T>(size, initial_value)) );
00119             return 0;
00120 #else
00121             return new BufferConnection<T>( typename BufferInterface<T>::shared_ptr(new BufferLocked<T>(size, initial_value)) );
00122 #endif
00123         }
00124 
00125         template<class T>
00126         DataConnection<T>* ConnectionFactory<T>::createDataObject(const T& initial_value, ConnectionTypes::ConnectionType type)
00127         {
00128 #ifndef OROBLD_OS_NO_ASM
00129             if (type == ConnectionTypes::lockfree)
00130                 return new DataConnection<T>( new DataObjectLockFree<T>("DataObject", initial_value) );
00131             if (type == ConnectionTypes::locked)
00132                 return new DataConnection<T>( new DataObjectLocked<T>("DataObject", initial_value) );
00133             return 0;
00134 #else
00135             return new DataConnection<T>( new DataObjectLocked<T>("DataObject", initial_value) );
00136 #endif
00137         }
00138 }
00139 #endif
Generated on Thu Dec 23 13:22:36 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3