DeviceFactory.h
Go to the documentation of this file.00001
00002
00003 #ifndef DEVICE_FACTORY_H_
00004 #define DEVICE_FACTORY_H_
00005
00006 #include <fesa-core/DataStore/AbstractDeviceFactory.h>
00007 #include <fesa-core/DataStore/HeapFactory.h>
00008 #include <fesa-core/DataStore/ShmFactory.h>
00009
00010 #include <string>
00011 #include <vector>
00012
00013 namespace fesa
00014 {
00015
00026 template<typename GlobalDeviceType, typename DomainStoreType, typename DevInstType>
00027 class DeviceFactory : public AbstractDeviceFactory
00028 {
00029 public:
00030
00036 DevInstType* getDevice(const std::string& deviceName);
00037
00043 GlobalDeviceType* getGlobalDevice();
00044
00049 const std::vector<DevInstType*>& getDeviceCollection();
00050
00054 ~DeviceFactory();
00055
00056 protected:
00057
00062 DeviceFactory(const std::string& className);
00063
00068 static DeviceFactory* instance_;
00069
00070 private:
00075 DeviceFactoryImp<GlobalDeviceType, DomainStoreType, DevInstType>* imp_;
00076 };
00077
00078
00079
00080 template<typename GlobalDeviceType, typename DomainStoreType, typename DevInstType>
00081 DeviceFactory<GlobalDeviceType, DomainStoreType, DevInstType>::DeviceFactory(const std::string& className) :
00082 AbstractDeviceFactory(className)
00083 {
00085 if (AbstractEquipment::getInstance()->getProcessType() == unsplit)
00086 {
00087 imp_ = new HeapFactory<GlobalDeviceType, DomainStoreType, DevInstType> (className);
00088 }
00089 else
00090 {
00091 imp_ = new ShmFactory<GlobalDeviceType, DomainStoreType, DevInstType> (className);
00092 }
00093 imp_->initialize();
00094
00095
00096 for (uint32_t i = 0; i < imp_->getDeviceCollection().size(); i++)
00097 {
00098 pAbstractDeviceCol_.push_back((imp_->getDeviceCollection())[i]);
00099 }
00100
00101 }
00102
00103 template<typename GlobalDeviceType, typename DomainStoreType, typename DevInstType>
00104 DeviceFactory<GlobalDeviceType, DomainStoreType, DevInstType>::~DeviceFactory<GlobalDeviceType, DomainStoreType,
00105 DevInstType>()
00106 {
00107
00108 delete imp_;
00109 }
00110
00111 template<typename GlobalDeviceType, typename DomainStoreType, typename DevInstType>
00112 inline DevInstType* DeviceFactory<GlobalDeviceType, DomainStoreType, DevInstType>::getDevice(
00113 const std::string& devName)
00114 {
00115 return imp_->getDevice(devName);
00116 }
00117
00118 template<typename GlobalDeviceType, typename DomainStoreType, typename DevInstType>
00119 inline GlobalDeviceType* DeviceFactory<GlobalDeviceType, DomainStoreType, DevInstType>::getGlobalDevice()
00120 {
00121 return imp_->getGlobalDevice();
00122 }
00123
00124 template<typename GlobalDeviceType, typename DomainStoreType, typename DevInstType>
00125 inline const std::vector<DevInstType*>& DeviceFactory<GlobalDeviceType, DomainStoreType, DevInstType>::getDeviceCollection()
00126 {
00127 return imp_->getDeviceCollection();
00128 }
00129
00130 }
00131
00132 #endif // DEVICE_FACTORY_H_