ConnectionFactory.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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