1 #include "TangoHKLAdapterFactory.h"
2 #include "TangoHKLAdapter.h"
3 #include "Diffractometer.h"
5 namespace Diffractometer_ns
9 * Static instance of the factory
12 TangoHKLAdapterFactory
* TangoHKLAdapterFactory::_instance
= NULL
;
16 * Return the instance of the factory
19 TangoHKLAdapterFactory
* TangoHKLAdapterFactory::instance(void)
22 _instance
= new TangoHKLAdapterFactory();
27 * method: DiffractometerFactory::createDiffractometer
29 * description: create a hkl library associated with device name
31 * @return an instance of hkl adapter which contains an instance of the library
34 TangoHKLAdapter
* TangoHKLAdapterFactory::attach_diffractometer_device(
35 Diffractometer
*device
,
38 omni_mutex_lock
lock(_lock
);
40 TangoHKLAdapter
* adapter
= NULL
;
42 // Check if it already build
43 adapterMap_t::const_iterator iter
;
44 iter
= _adapterMap
.find( device
);
46 if (iter
== _adapterMap
.end()) {
47 adapter
= new TangoHKLAdapter(device
, type
);
48 _adapterMap
[device
] = adapter
;
49 std::cout
<< "TangoHKLAdapterFactory::attach_device new Diffractometer device " << device
->get_name() << " created." << std::endl
;
51 adapter
= iter
->second
;
56 void TangoHKLAdapterFactory::detach_diffractometer_device(Diffractometer
*device
)
58 omni_mutex_lock
lock(_lock
);
60 // Find the name in map
61 adapterMap_t::iterator iter
;
62 iter
= _adapterMap
.find( device
);
64 if (iter
!= _adapterMap
.end()) {
65 // Do Delete it as it is used by the PseudoAxes.
66 //delete iter->second;
67 //_adapterMap.erase(iter);
68 std::cout
<< "TangoHKLAdapterFactory::removeDiffractometer Diffractometer device " << device
->get_name() << " removed." << std::endl
;
73 * @brief Get the TangoHKLAdapter associated to a device named:
74 * @param devicename The name of the device.
75 * @return The TangoHKLAdapter pointer of the Device or NULL if the device is not present.
77 TangoHKLAdapter
* TangoHKLAdapterFactory::get_diffractometer_adapter(std::string
const & diffractometerProxyName
)
79 omni_mutex_lock
lock(_lock
);
81 TangoHKLAdapter
* adapter
= NULL
;
83 adapterMap_t::iterator iter
= _adapterMap
.begin();
84 adapterMap_t::iterator end
= _adapterMap
.end();
86 if (iter
->first
->get_name() == diffractometerProxyName
) {
87 adapter
= iter
->second
;
96 TangoHKLAdapterFactory::~TangoHKLAdapterFactory(void)
99 // remove all undeleted devices.
100 adapterMap_t::iterator iter
= _adapterMap
.begin();
101 adapterMap_t::iterator end
= _adapterMap
.end();