* move the initialized attribut in the PseudoAxesConfig
[diffractometer.git] / src / PseudoAxes / PseudoAxes.cpp
blobadb7833decbe52420f8e292605704a5e1c11638b
1 static const char *RcsId = "$Header: $";
2 //+=============================================================================
3 //
4 // file : PseudoAxes.cpp
5 //
6 // description : C++ source for the PseudoAxes and its commands.
7 // The class is derived from Device. It represents the
8 // CORBA servant object which will be accessed from the
9 // network. All commands which can be executed on the
10 // PseudoAxes are implemented in this file.
12 // project : TANGO Device Server
14 // $Author: $
16 // $Revision: $
18 // $Log: $
20 // copyleft : European Synchrotron Radiation Facility
21 // BP 220, Grenoble 38043
22 // FRANCE
24 //-=============================================================================
26 // This file is generated by POGO
27 // (Program Obviously used to Generate tango Object)
29 // (c) - Software Engineering Group - ESRF
30 //=============================================================================
34 //===================================================================
36 // The following table gives the correspondence
37 // between commands and method name.
39 // Command name| Method name
40 // ----------------------------------------
41 // State | dev_state()
42 // Status | dev_status()
43 // AxisInit | axis_init()
45 //===================================================================
48 #include <tango.h>
49 #include <PseudoAxes.h>
50 #include <PseudoAxesClass.h>
52 #include "TangoHKLAdapterFactory.h"
54 namespace PseudoAxes_ns
57 //+----------------------------------------------------------------------------
59 // method : PseudoAxes::PseudoAxes(string &s)
60 //
61 // description : constructor for simulated PseudoAxes
63 // in : - cl : Pointer to the DeviceClass object
64 // - s : Device name
66 //-----------------------------------------------------------------------------
67 PseudoAxes::PseudoAxes(Tango::DeviceClass *cl,string &s)
68 :Tango::Device_3Impl(cl,s.c_str())
70 init_device();
73 PseudoAxes::PseudoAxes(Tango::DeviceClass *cl,const char *s)
74 :Tango::Device_3Impl(cl,s)
76 init_device();
79 PseudoAxes::PseudoAxes(Tango::DeviceClass *cl,const char *s,const char *d)
80 :Tango::Device_3Impl(cl,s,d)
82 init_device();
84 //+----------------------------------------------------------------------------
86 // method : PseudoAxes::delete_device()
87 //
88 // description : will be called at device destruction or at init command.
90 //-----------------------------------------------------------------------------
91 void PseudoAxes::delete_device()
93 // Delete device's allocated object
95 if(_adapter){
96 _adapter->save();
97 _adapter->remove_dynamic_attributes();
98 _adapter = NULL;
100 _hklAdapter = NULL;
103 //+----------------------------------------------------------------------------
105 // method : PseudoAxes::init_device()
107 // description : will be called at device initialization.
109 //-----------------------------------------------------------------------------
110 void PseudoAxes::init_device()
112 INFO_STREAM << "PseudoAxes::PseudoAxes() create device " << device_name << endl;
114 // Initialise variables to default values
115 //--------------------------------------------
116 get_device_property();
118 _adapter = NULL;
119 _hklAdapter = NULL;
121 _config.state = Tango::FAULT;
122 _config.status = "Not yet initialized";
123 _config.initialized = false;
125 // we can get the Diffractometer device adapter in the init as this one start all PseudoAxes
126 if(!_hklAdapter)
127 _hklAdapter = Diffractometer_ns::TangoHKLAdapterFactory::instance()->get_diffractometer_adapter(diffractometerProxy);
129 if(_hklAdapter && !_adapter){
130 _adapter = _hklAdapter->pseudo_axes_adapter_get_by_name(engineName);
131 if(_adapter){
132 _adapter->set_device(this);
133 _adapter->add_dynamic_attributes();
134 _adapter->load();
140 //+----------------------------------------------------------------------------
142 // method : PseudoAxes::get_device_property()
144 // description : Read the device properties from database.
146 //-----------------------------------------------------------------------------
147 void PseudoAxes::get_device_property()
149 // Initialize your default values here (if not done with POGO).
150 //------------------------------------------------------------------
152 // Read device properties from database.(Automatic code generation)
153 //------------------------------------------------------------------
154 Tango::DbData dev_prop;
155 dev_prop.push_back(Tango::DbDatum("DiffractometerProxy"));
156 dev_prop.push_back(Tango::DbDatum("EngineName"));
158 // Call database and extract values
159 //--------------------------------------------
160 if (Tango::Util::instance()->_UseDb==true)
161 get_db_device()->get_property(dev_prop);
162 Tango::DbDatum def_prop, cl_prop;
163 PseudoAxesClass *ds_class =
164 (static_cast<PseudoAxesClass *>(get_device_class()));
165 int i = -1;
167 // Try to initialize DiffractometerProxy from class property
168 cl_prop = ds_class->get_class_property(dev_prop[++i].name);
169 if (cl_prop.is_empty()==false) cl_prop >> diffractometerProxy;
170 else {
171 // Try to initialize DiffractometerProxy from default device value
172 def_prop = ds_class->get_default_device_property(dev_prop[i].name);
173 if (def_prop.is_empty()==false) def_prop >> diffractometerProxy;
175 // And try to extract DiffractometerProxy value from database
176 if (dev_prop[i].is_empty()==false) dev_prop[i] >> diffractometerProxy;
178 // Try to initialize EngineName from class property
179 cl_prop = ds_class->get_class_property(dev_prop[++i].name);
180 if (cl_prop.is_empty()==false) cl_prop >> engineName;
181 else {
182 // Try to initialize EngineName from default device value
183 def_prop = ds_class->get_default_device_property(dev_prop[i].name);
184 if (def_prop.is_empty()==false) def_prop >> engineName;
186 // And try to extract EngineName value from database
187 if (dev_prop[i].is_empty()==false) dev_prop[i] >> engineName;
191 // End of Automatic code generation
192 //------------------------------------------------------------------
195 //+----------------------------------------------------------------------------
197 // method : PseudoAxes::always_executed_hook()
199 // description : method always executed before any command is executed
201 //-----------------------------------------------------------------------------
202 void PseudoAxes::always_executed_hook()
204 if(!_hklAdapter)
205 _hklAdapter = Diffractometer_ns::TangoHKLAdapterFactory::instance()->get_diffractometer_adapter(diffractometerProxy);
207 if(_hklAdapter && !_adapter)
208 _adapter = _hklAdapter->pseudo_axes_adapter_get_by_name(engineName);
211 //+----------------------------------------------------------------------------
213 // method : PseudoAxes::read_attr_hardware
215 // description : Hardware acquisition for attributes.
217 //-----------------------------------------------------------------------------
218 void PseudoAxes::read_attr_hardware(vector<long> &attr_list)
220 DEBUG_STREAM << "PseudoAxes::read_attr_hardware(vector<long> &attr_list) entering... "<< endl;
221 // Add your own code here
222 if(_adapter)
223 _config = _adapter->get_config();
225 //+----------------------------------------------------------------------------
227 // method : PseudoAxes::read_initialized
229 // description : Extract real attribute values for initialized acquisition result.
231 //-----------------------------------------------------------------------------
232 void PseudoAxes::read_initialized(Tango::Attribute &attr)
234 DEBUG_STREAM << "PseudoAxes::read_initialized(Tango::Attribute &attr) entering... "<< endl;
235 if(_adapter)
236 attr.set_value(&_config.initialized);
239 //+----------------------------------------------------------------------------
241 // method : PseudoAxes::write_initialized
243 // description : Write initialized attribute values to hardware.
245 //-----------------------------------------------------------------------------
246 void PseudoAxes::write_initialized(Tango::WAttribute &attr)
248 DEBUG_STREAM << "PseudoAxes::write_initialized(Tango::WAttribute &attr) entering... "<< endl;
250 if(_adapter){
251 Tango::DevBoolean initialized;
252 attr.get_write_value(initialized);
253 _adapter->set_initialized(initialized);
257 //+----------------------------------------------------------------------------
259 // method : PseudoAxes::read_parameters
261 // description : Extract real attribute values for parameters acquisition result.
263 //-----------------------------------------------------------------------------
264 void PseudoAxes::read_parameters(Tango::Attribute &attr)
266 DEBUG_STREAM << "PseudoAxes::read_parameters(Tango::Attribute &attr) entering... "<< endl;
268 if(_adapter){
269 Matrix<double> const & img = _adapter->get_mode_parameters();
270 attr.set_value(img.data, img.xdim);
274 //+----------------------------------------------------------------------------
276 // method : PseudoAxes::write_parameters
278 // description : Write parameters attribute values to hardware.
280 //-----------------------------------------------------------------------------
281 void PseudoAxes::write_parameters(Tango::WAttribute &attr)
283 DEBUG_STREAM << "PseudoAxes::write_parameters(Tango::WAttribute &attr) entering... "<< endl;
285 if(_adapter){
286 const Tango::DevDouble *values;
287 attr.get_write_value(values);
288 Matrix<double> img;
289 img.attach_to_const_buffer(values,
290 attr.get_w_dim_x(), attr.get_w_dim_y());
292 _adapter->set_mode_parameters(img);
296 //+----------------------------------------------------------------------------
298 // method : PseudoAxes::read_pseudoAxisNames
300 // description : Extract real attribute values for pseudoAxisNames acquisition result.
302 //-----------------------------------------------------------------------------
303 void PseudoAxes::read_pseudoAxisNames(Tango::Attribute &attr)
305 DEBUG_STREAM << "PseudoAxes::read_pseudoAxisNames(Tango::Attribute &attr) entering... "<< endl;
306 if(_adapter){
307 Matrix<char *> const & img = _adapter->get_pseudo_axis_names();
308 attr.set_value(img.data, img.xdim);
313 //+----------------------------------------------------------------------------
315 // method : PseudoAxes::read_mode
317 // description : Extract real attribute values for mode acquisition result.
319 //-----------------------------------------------------------------------------
320 void PseudoAxes::read_mode(Tango::Attribute &attr)
322 DEBUG_STREAM << "PseudoAxes::read_mode(Tango::Attribute &attr) entering... "<< endl;
323 if(_adapter)
324 attr.set_value(_adapter->get_mode());
327 //+----------------------------------------------------------------------------
329 // method : PseudoAxes::write_mode
331 // description : Write mode attribute values to hardware.
333 //-----------------------------------------------------------------------------
334 void PseudoAxes::write_mode(Tango::WAttribute &attr)
336 DEBUG_STREAM << "PseudoAxes::write_mode(Tango::WAttribute &attr) entering... "<< endl;
337 attr.get_write_value(attr_mode_write);
338 if(_adapter)
339 _adapter->set_mode(attr_mode_write);
342 //+----------------------------------------------------------------------------
344 // method : PseudoAxes::read_modeNames
346 // description : Extract real attribute values for modeNames acquisition result.
348 //-----------------------------------------------------------------------------
349 void PseudoAxes::read_modeNames(Tango::Attribute &attr)
351 DEBUG_STREAM << "PseudoAxes::read_modeNames(Tango::Attribute &attr) entering... "<< endl;
352 if(_adapter){
353 Matrix<char *> const & img = _adapter->get_mode_names();
354 attr.set_value(img.data, img.xdim);
358 //+----------------------------------------------------------------------------
360 // method : PseudoAxes::read_parametersNames
362 // description : Extract real attribute values for parametersNames acquisition result.
364 //-----------------------------------------------------------------------------
365 void PseudoAxes::read_parametersNames(Tango::Attribute &attr)
367 DEBUG_STREAM << "PseudoAxes::read_parametersNames(Tango::Attribute &attr) entering... "<< endl;
368 if(_adapter){
369 Matrix<char *> const & img = _adapter->get_mode_parameters_names();
370 attr.set_value(img.data, img.xdim);
374 //+------------------------------------------------------------------
376 * method: PseudoAxes::axis_init
378 * description: method to execute "AxisInit"
379 * Initialize the pseudoAxes (exemple the psi pseudo axis)
383 //+------------------------------------------------------------------
384 void PseudoAxes::axis_init()
386 DEBUG_STREAM << "PseudoAxes::axis_init(): entering... !" << endl;
388 // Add your own code to control device here
389 if(_adapter)
390 _adapter->init();
394 //+------------------------------------------------------------------
396 * method: PseudoAxes::dev_state
398 * description: method to execute "State"
399 * This command gets the device state (stored in its <i>device_state</i> data member) and returns it to the caller.
401 * @return State Code
404 //+------------------------------------------------------------------
405 Tango::DevState PseudoAxes::dev_state()
407 Tango::DevState argout = DeviceImpl::dev_state();
408 DEBUG_STREAM << "PseudoAxes::dev_state(): entering... !" << endl;
410 // Add your own code to control device here
412 if(_adapter)
413 this->set_state(_config.state);
415 return this->device_state;
418 //+------------------------------------------------------------------
420 * method: PseudoAxes::dev_status
422 * description: method to execute "Status"
423 * This command gets the device status (stored in its <i>device_status</i> data member) and returns it to the caller.
425 * @return Status description
428 //+------------------------------------------------------------------
429 Tango::ConstDevString PseudoAxes::dev_status()
431 Tango::ConstDevString argout = DeviceImpl::dev_status();
432 DEBUG_STREAM << "PseudoAxes::dev_status(): entering... !" << endl;
434 // Add your own code to control device here
436 if(_adapter)
437 this->set_status(_config.status);
439 return this->device_status.c_str();
443 } // namespace