Merge branch 'maint' into next
[diffractometer.git] / src / PseudoAxes / PseudoAxesClass.cpp
blob901b39e9382e2a60c2fbad666aa5ad29f84c082f
1 static const char *RcsId = "$Header: $";
2 static const char *TagName = "$Name: $";
3 static const char *HttpServer= "http://www.esrf.fr/computing/cs/tango/tango_doc/ds_doc/";
4 //+=============================================================================
5 //
6 // file : PseudoAxesClass.cpp
7 //
8 // description : C++ source for the PseudoAxesClass. A singleton
9 // class derived from DeviceClass. It implements the
10 // command list and all properties and methods required
11 // by the PseudoAxes once per process.
13 // project : TANGO Device Server
15 // $Author: $
17 // $Revision: $
19 // $Log: $
21 // copyleft : European Synchrotron Radiation Facility
22 // BP 220, Grenoble 38043
23 // FRANCE
25 //-=============================================================================
27 // This file is generated by POGO
28 // (Program Obviously used to Generate tango Object)
30 // (c) - Software Engineering Group - ESRF
31 //=============================================================================
34 #include <tango.h>
36 #include <PseudoAxes.h>
37 #include <PseudoAxesClass.h>
40 //+----------------------------------------------------------------------------
41 /**
42 * Create PseudoAxesClass singleton and return it in a C function for Python usage
44 //+----------------------------------------------------------------------------
45 extern "C" {
46 #ifdef WIN32
48 __declspec(dllexport)
50 #endif
52 Tango::DeviceClass *_create_PseudoAxes_class(const char *name) {
53 return PseudoAxes_ns::PseudoAxesClass::init(name);
58 namespace PseudoAxes_ns
60 //+----------------------------------------------------------------------------
62 // method : ApplyCmd::execute()
63 //
64 // description : method to trigger the execution of the command.
65 // PLEASE DO NOT MODIFY this method core without pogo
67 // in : - device : The device on which the command must be excuted
68 // - in_any : The command input data
70 // returns : The command output data (packed in the Any object)
72 //-----------------------------------------------------------------------------
73 CORBA::Any *ApplyCmd::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any)
76 cout2 << "ApplyCmd::execute(): arrived" << endl;
78 ((static_cast<PseudoAxes *>(device))->apply());
79 return new CORBA::Any();
82 //+----------------------------------------------------------------------------
84 // method : AxisInitClass::execute()
85 //
86 // description : method to trigger the execution of the command.
87 // PLEASE DO NOT MODIFY this method core without pogo
89 // in : - device : The device on which the command must be excuted
90 // - in_any : The command input data
92 // returns : The command output data (packed in the Any object)
94 //-----------------------------------------------------------------------------
95 CORBA::Any *AxisInitClass::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any)
98 cout2 << "AxisInitClass::execute(): arrived" << endl;
100 ((static_cast<PseudoAxes *>(device))->axis_init());
101 return new CORBA::Any();
107 //----------------------------------------------------------------
108 // Initialize pointer for singleton pattern
109 //----------------------------------------------------------------
111 PseudoAxesClass *PseudoAxesClass::_instance = NULL;
113 //+----------------------------------------------------------------------------
115 // method : PseudoAxesClass::PseudoAxesClass(string &s)
117 // description : constructor for the PseudoAxesClass
119 // in : - s : The class name
121 //-----------------------------------------------------------------------------
122 PseudoAxesClass::PseudoAxesClass(string &s):DeviceClass(s)
125 cout2 << "Entering PseudoAxesClass constructor" << endl;
126 set_default_property();
127 get_class_property();
128 write_class_property();
130 cout2 << "Leaving PseudoAxesClass constructor" << endl;
133 //+----------------------------------------------------------------------------
135 // method : PseudoAxesClass::~PseudoAxesClass()
137 // description : destructor for the PseudoAxesClass
139 //-----------------------------------------------------------------------------
140 PseudoAxesClass::~PseudoAxesClass()
142 _instance = NULL;
145 //+----------------------------------------------------------------------------
147 // method : PseudoAxesClass::instance
149 // description : Create the object if not already done. Otherwise, just
150 // return a pointer to the object
152 // in : - name : The class name
154 //-----------------------------------------------------------------------------
155 PseudoAxesClass *PseudoAxesClass::init(const char *name)
157 if (_instance == NULL)
161 string s(name);
162 _instance = new PseudoAxesClass(s);
164 catch (bad_alloc)
166 throw;
169 return _instance;
172 PseudoAxesClass *PseudoAxesClass::instance()
174 if (_instance == NULL)
176 cerr << "Class is not initialised !!" << endl;
177 exit(-1);
179 return _instance;
182 //+----------------------------------------------------------------------------
184 // method : PseudoAxesClass::command_factory
186 // description : Create the command object(s) and store them in the
187 // command list
189 //-----------------------------------------------------------------------------
190 void PseudoAxesClass::command_factory()
192 command_list.push_back(new AxisInitClass("AxisInit",
193 Tango::DEV_VOID, Tango::DEV_VOID,
196 Tango::OPERATOR));
197 command_list.push_back(new ApplyCmd("Apply",
198 Tango::DEV_VOID, Tango::DEV_VOID,
201 Tango::OPERATOR));
203 // add polling if any
204 for (unsigned int i=0 ; i<command_list.size(); i++)
209 //+----------------------------------------------------------------------------
211 // method : PseudoAxesClass::get_class_property
213 // description : Get the class property for specified name.
215 // in : string name : The property name
217 //+----------------------------------------------------------------------------
218 Tango::DbDatum PseudoAxesClass::get_class_property(string &prop_name)
220 for (unsigned int i=0 ; i<cl_prop.size() ; i++)
221 if (cl_prop[i].name == prop_name)
222 return cl_prop[i];
223 // if not found, return an empty DbDatum
224 return Tango::DbDatum(prop_name);
226 //+----------------------------------------------------------------------------
228 // method : PseudoAxesClass::get_default_device_property()
230 // description : Return the default value for device property.
232 //-----------------------------------------------------------------------------
233 Tango::DbDatum PseudoAxesClass::get_default_device_property(string &prop_name)
235 for (unsigned int i=0 ; i<dev_def_prop.size() ; i++)
236 if (dev_def_prop[i].name == prop_name)
237 return dev_def_prop[i];
238 // if not found, return an empty DbDatum
239 return Tango::DbDatum(prop_name);
242 //+----------------------------------------------------------------------------
244 // method : PseudoAxesClass::get_default_class_property()
246 // description : Return the default value for class property.
248 //-----------------------------------------------------------------------------
249 Tango::DbDatum PseudoAxesClass::get_default_class_property(string &prop_name)
251 for (unsigned int i=0 ; i<cl_def_prop.size() ; i++)
252 if (cl_def_prop[i].name == prop_name)
253 return cl_def_prop[i];
254 // if not found, return an empty DbDatum
255 return Tango::DbDatum(prop_name);
257 //+----------------------------------------------------------------------------
259 // method : PseudoAxesClass::device_factory
261 // description : Create the device object(s) and store them in the
262 // device list
264 // in : Tango::DevVarStringArray *devlist_ptr : The device name list
266 //-----------------------------------------------------------------------------
267 void PseudoAxesClass::device_factory(const Tango::DevVarStringArray *devlist_ptr)
270 // Create all devices.(Automatic code generation)
271 //-------------------------------------------------------------
272 for (unsigned long i=0 ; i < devlist_ptr->length() ; i++)
274 cout4 << "Device name : " << (*devlist_ptr)[i].in() << endl;
276 // Create devices and add it into the device list
277 //----------------------------------------------------
278 device_list.push_back(new PseudoAxes(this, (*devlist_ptr)[i]));
280 // Export device to the outside world
281 // Check before if database used.
282 //---------------------------------------------
283 if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false))
284 export_device(device_list.back());
285 else
286 export_device(device_list.back(), (*devlist_ptr)[i]);
288 // End of Automatic code generation
289 //-------------------------------------------------------------
292 //+----------------------------------------------------------------------------
293 // Method: PseudoAxesClass::attribute_factory(vector<Tango::Attr *> &att_list)
294 //-----------------------------------------------------------------------------
295 void PseudoAxesClass::attribute_factory(vector<Tango::Attr *> &att_list)
297 // Attribute : mode
298 modeAttrib *mode = new modeAttrib();
299 att_list.push_back(mode);
301 // Attribute : initialized
302 initializedAttrib *initialized = new initializedAttrib();
303 Tango::UserDefaultAttrProp initialized_prop;
304 initialized_prop.set_description("Initialize or not the pseudo axes");
305 initialized->set_default_properties(initialized_prop);
306 att_list.push_back(initialized);
308 // Attribute : modeNames
309 modeNamesAttrib *mode_names = new modeNamesAttrib();
310 att_list.push_back(mode_names);
312 // Attribute : parametersNames
313 parametersNamesAttrib *parameters_names = new parametersNamesAttrib();
314 att_list.push_back(parameters_names);
316 // Attribute : parameters
317 parametersAttrib *parameters = new parametersAttrib();
318 att_list.push_back(parameters);
320 // Attribute : pseudoAxisNames
321 pseudoAxisNamesAttrib *pseudo_axis_names = new pseudoAxisNamesAttrib();
322 att_list.push_back(pseudo_axis_names);
324 // End of Automatic code generation
325 //-------------------------------------------------------------
328 //+----------------------------------------------------------------------------
330 // method : PseudoAxesClass::get_class_property()
332 // description : Read the class properties from database.
334 //-----------------------------------------------------------------------------
335 void PseudoAxesClass::get_class_property()
337 // Initialize your default values here (if not done with POGO).
338 //------------------------------------------------------------------
340 // Read class properties from database.(Automatic code generation)
341 //------------------------------------------------------------------
343 // Call database and extract values
344 //--------------------------------------------
345 if (Tango::Util::instance()->_UseDb==true)
346 get_db_class()->get_property(cl_prop);
347 Tango::DbDatum def_prop;
348 int i = -1;
351 // End of Automatic code generation
352 //------------------------------------------------------------------
356 //+----------------------------------------------------------------------------
358 // method : PseudoAxesClass::set_default_property
360 // description: Set default property (class and device) for wizard.
361 // For each property, add to wizard property name and description
362 // If default value has been set, add it to wizard property and
363 // store it in a DbDatum.
365 //-----------------------------------------------------------------------------
366 void PseudoAxesClass::set_default_property()
368 string prop_name;
369 string prop_desc;
370 string prop_def;
372 vector<string> vect_data;
373 // Set Default Class Properties
374 // Set Default Device Properties
375 prop_name = "DiffractometerProxy";
376 prop_desc = "the diffractometer Proxy";
377 prop_def = "";
378 if (prop_def.length()>0)
380 Tango::DbDatum data(prop_name);
381 data << vect_data ;
382 dev_def_prop.push_back(data);
383 add_wiz_dev_prop(prop_name, prop_desc, prop_def);
385 else
386 add_wiz_dev_prop(prop_name, prop_desc);
388 prop_name = "EngineName";
389 prop_desc = "name of the HklPseudoAxisEngine used by this device.";
390 prop_def = "";
391 if (prop_def.length()>0)
393 Tango::DbDatum data(prop_name);
394 data << vect_data ;
395 dev_def_prop.push_back(data);
396 add_wiz_dev_prop(prop_name, prop_desc, prop_def);
398 else
399 add_wiz_dev_prop(prop_name, prop_desc);
402 //+----------------------------------------------------------------------------
404 // method : PseudoAxesClass::write_class_property
406 // description : Set class description as property in database
408 //-----------------------------------------------------------------------------
409 void PseudoAxesClass::write_class_property()
411 // First time, check if database used
412 //--------------------------------------------
413 if (Tango::Util::_UseDb == false)
414 return;
416 Tango::DbData data;
417 string classname = get_name();
418 string header;
419 string::size_type start, end;
421 // Put title
422 Tango::DbDatum title("ProjectTitle");
423 string str_title("");
424 title << str_title;
425 data.push_back(title);
427 // Put Description
428 Tango::DbDatum description("Description");
429 vector<string> str_desc;
430 str_desc.push_back(" ");
431 description << str_desc;
432 data.push_back(description);
434 // put cvs location
435 string rcsId(RcsId);
436 string filename(classname);
437 start = rcsId.find("/");
438 if (start!=string::npos)
440 filename += "Class.cpp";
441 end = rcsId.find(filename);
442 if (end>start)
444 string strloc = rcsId.substr(start, end-start);
445 // Check if specific repository
446 start = strloc.find("/cvsroot/");
447 if (start!=string::npos && start>0)
449 string repository = strloc.substr(0, start);
450 if (repository.find("/segfs/")!=string::npos)
451 strloc = "ESRF:" + strloc.substr(start, strloc.length()-start);
453 Tango::DbDatum cvs_loc("cvs_location");
454 cvs_loc << strloc;
455 data.push_back(cvs_loc);
459 // Get CVS tag revision
460 string tagname(TagName);
461 header = "$Name: ";
462 start = header.length();
463 string endstr(" $");
464 end = tagname.find(endstr);
465 if (end!=string::npos && end>start)
467 string strtag = tagname.substr(start, end-start);
468 Tango::DbDatum cvs_tag("cvs_tag");
469 cvs_tag << strtag;
470 data.push_back(cvs_tag);
473 // Get URL location
474 string httpServ(HttpServer);
475 if (httpServ.length()>0)
477 Tango::DbDatum db_doc_url("doc_url");
478 db_doc_url << httpServ;
479 data.push_back(db_doc_url);
482 // Put inheritance
483 Tango::DbDatum inher_datum("InheritedFrom");
484 vector<string> inheritance;
485 inheritance.push_back("Device_4Impl");
486 inher_datum << inheritance;
487 data.push_back(inher_datum);
489 // Call database and and values
490 //--------------------------------------------
491 get_db_class()->put_property(data);
494 } // namespace