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 #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