* pogo add the AutoUpdateFromProxies attribut
[diffractometer.git] / src / PseudoAxes / PseudoAxesClass.cpp
blobc975e6e6aa6d638c2d6ced025dd53c5745438c72
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 : AxisInitClass::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 *AxisInitClass::execute(Tango::DeviceImpl *device,const CORBA::Any &in_any)
76 cout2 << "AxisInitClass::execute(): arrived" << endl;
78 ((static_cast<PseudoAxes *>(device))->axis_init());
79 return new CORBA::Any();
85 //----------------------------------------------------------------
86 // Initialize pointer for singleton pattern
87 //----------------------------------------------------------------
89 PseudoAxesClass *PseudoAxesClass::_instance = NULL;
91 //+----------------------------------------------------------------------------
93 // method : PseudoAxesClass::PseudoAxesClass(string &s)
94 //
95 // description : constructor for the PseudoAxesClass
97 // in : - s : The class name
99 //-----------------------------------------------------------------------------
100 PseudoAxesClass::PseudoAxesClass(string &s):DeviceClass(s)
103 cout2 << "Entering PseudoAxesClass constructor" << endl;
104 set_default_property();
105 get_class_property();
106 write_class_property();
108 cout2 << "Leaving PseudoAxesClass constructor" << endl;
111 //+----------------------------------------------------------------------------
113 // method : PseudoAxesClass::~PseudoAxesClass()
115 // description : destructor for the PseudoAxesClass
117 //-----------------------------------------------------------------------------
118 PseudoAxesClass::~PseudoAxesClass()
120 _instance = NULL;
123 //+----------------------------------------------------------------------------
125 // method : PseudoAxesClass::instance
127 // description : Create the object if not already done. Otherwise, just
128 // return a pointer to the object
130 // in : - name : The class name
132 //-----------------------------------------------------------------------------
133 PseudoAxesClass *PseudoAxesClass::init(const char *name)
135 if (_instance == NULL)
139 string s(name);
140 _instance = new PseudoAxesClass(s);
142 catch (bad_alloc)
144 throw;
147 return _instance;
150 PseudoAxesClass *PseudoAxesClass::instance()
152 if (_instance == NULL)
154 cerr << "Class is not initialised !!" << endl;
155 exit(-1);
157 return _instance;
160 //+----------------------------------------------------------------------------
162 // method : PseudoAxesClass::command_factory
164 // description : Create the command object(s) and store them in the
165 // command list
167 //-----------------------------------------------------------------------------
168 void PseudoAxesClass::command_factory()
170 command_list.push_back(new AxisInitClass("AxisInit",
171 Tango::DEV_VOID, Tango::DEV_VOID,
174 Tango::OPERATOR));
176 // add polling if any
177 for (unsigned int i=0 ; i<command_list.size(); i++)
182 //+----------------------------------------------------------------------------
184 // method : PseudoAxesClass::get_class_property
186 // description : Get the class property for specified name.
188 // in : string name : The property name
190 //+----------------------------------------------------------------------------
191 Tango::DbDatum PseudoAxesClass::get_class_property(string &prop_name)
193 for (unsigned int i=0 ; i<cl_prop.size() ; i++)
194 if (cl_prop[i].name == prop_name)
195 return cl_prop[i];
196 // if not found, return an empty DbDatum
197 return Tango::DbDatum(prop_name);
199 //+----------------------------------------------------------------------------
201 // method : PseudoAxesClass::get_default_device_property()
203 // description : Return the default value for device property.
205 //-----------------------------------------------------------------------------
206 Tango::DbDatum PseudoAxesClass::get_default_device_property(string &prop_name)
208 for (unsigned int i=0 ; i<dev_def_prop.size() ; i++)
209 if (dev_def_prop[i].name == prop_name)
210 return dev_def_prop[i];
211 // if not found, return an empty DbDatum
212 return Tango::DbDatum(prop_name);
215 //+----------------------------------------------------------------------------
217 // method : PseudoAxesClass::get_default_class_property()
219 // description : Return the default value for class property.
221 //-----------------------------------------------------------------------------
222 Tango::DbDatum PseudoAxesClass::get_default_class_property(string &prop_name)
224 for (unsigned int i=0 ; i<cl_def_prop.size() ; i++)
225 if (cl_def_prop[i].name == prop_name)
226 return cl_def_prop[i];
227 // if not found, return an empty DbDatum
228 return Tango::DbDatum(prop_name);
230 //+----------------------------------------------------------------------------
232 // method : PseudoAxesClass::device_factory
234 // description : Create the device object(s) and store them in the
235 // device list
237 // in : Tango::DevVarStringArray *devlist_ptr : The device name list
239 //-----------------------------------------------------------------------------
240 void PseudoAxesClass::device_factory(const Tango::DevVarStringArray *devlist_ptr)
243 // Create all devices.(Automatic code generation)
244 //-------------------------------------------------------------
245 for (unsigned long i=0 ; i < devlist_ptr->length() ; i++)
247 cout4 << "Device name : " << (*devlist_ptr)[i].in() << endl;
249 // Create devices and add it into the device list
250 //----------------------------------------------------
251 device_list.push_back(new PseudoAxes(this, (*devlist_ptr)[i]));
253 // Export device to the outside world
254 // Check before if database used.
255 //---------------------------------------------
256 if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false))
257 export_device(device_list.back());
258 else
259 export_device(device_list.back(), (*devlist_ptr)[i]);
261 // End of Automatic code generation
262 //-------------------------------------------------------------
265 //+----------------------------------------------------------------------------
266 // Method: PseudoAxesClass::attribute_factory(vector<Tango::Attr *> &att_list)
267 //-----------------------------------------------------------------------------
268 void PseudoAxesClass::attribute_factory(vector<Tango::Attr *> &att_list)
270 // Attribute : mode
271 modeAttrib *mode = new modeAttrib();
272 att_list.push_back(mode);
274 // Attribute : modeNames
275 modeNamesAttrib *mode_names = new modeNamesAttrib();
276 att_list.push_back(mode_names);
278 // Attribute : parametersNames
279 parametersNamesAttrib *parameters_names = new parametersNamesAttrib();
280 att_list.push_back(parameters_names);
282 // Attribute : parameters
283 parametersAttrib *parameters = new parametersAttrib();
284 att_list.push_back(parameters);
286 // Attribute : pseudoAxisNames
287 pseudoAxisNamesAttrib *pseudo_axis_names = new pseudoAxisNamesAttrib();
288 att_list.push_back(pseudo_axis_names);
290 // End of Automatic code generation
291 //-------------------------------------------------------------
294 //+----------------------------------------------------------------------------
296 // method : PseudoAxesClass::get_class_property()
298 // description : Read the class properties from database.
300 //-----------------------------------------------------------------------------
301 void PseudoAxesClass::get_class_property()
303 // Initialize your default values here (if not done with POGO).
304 //------------------------------------------------------------------
306 // Read class properties from database.(Automatic code generation)
307 //------------------------------------------------------------------
309 // Call database and extract values
310 //--------------------------------------------
311 if (Tango::Util::instance()->_UseDb==true)
312 get_db_class()->get_property(cl_prop);
313 Tango::DbDatum def_prop;
314 int i = -1;
317 // End of Automatic code generation
318 //------------------------------------------------------------------
322 //+----------------------------------------------------------------------------
324 // method : PseudoAxesClass::set_default_property
326 // description: Set default property (class and device) for wizard.
327 // For each property, add to wizard property name and description
328 // If default value has been set, add it to wizard property and
329 // store it in a DbDatum.
331 //-----------------------------------------------------------------------------
332 void PseudoAxesClass::set_default_property()
334 string prop_name;
335 string prop_desc;
336 string prop_def;
338 vector<string> vect_data;
339 // Set Default Class Properties
340 // Set Default Device Properties
341 prop_name = "DiffractometerProxy";
342 prop_desc = "the diffractometer Proxy";
343 prop_def = "";
344 if (prop_def.length()>0)
346 Tango::DbDatum data(prop_name);
347 data << vect_data ;
348 dev_def_prop.push_back(data);
349 add_wiz_dev_prop(prop_name, prop_desc, prop_def);
351 else
352 add_wiz_dev_prop(prop_name, prop_desc);
354 prop_name = "EngineName";
355 prop_desc = "name of the HklPseudoAxisEngine used by this device.";
356 prop_def = "";
357 if (prop_def.length()>0)
359 Tango::DbDatum data(prop_name);
360 data << vect_data ;
361 dev_def_prop.push_back(data);
362 add_wiz_dev_prop(prop_name, prop_desc, prop_def);
364 else
365 add_wiz_dev_prop(prop_name, prop_desc);
368 //+----------------------------------------------------------------------------
370 // method : PseudoAxesClass::write_class_property
372 // description : Set class description as property in database
374 //-----------------------------------------------------------------------------
375 void PseudoAxesClass::write_class_property()
377 // First time, check if database used
378 //--------------------------------------------
379 if (Tango::Util::_UseDb == false)
380 return;
382 Tango::DbData data;
383 string classname = get_name();
384 string header;
385 string::size_type start, end;
387 // Put title
388 Tango::DbDatum title("ProjectTitle");
389 string str_title("");
390 title << str_title;
391 data.push_back(title);
393 // Put Description
394 Tango::DbDatum description("Description");
395 vector<string> str_desc;
396 str_desc.push_back(" ");
397 description << str_desc;
398 data.push_back(description);
400 // put cvs location
401 string rcsId(RcsId);
402 string filename(classname);
403 start = rcsId.find("/");
404 if (start!=string::npos)
406 filename += "Class.cpp";
407 end = rcsId.find(filename);
408 if (end>start)
410 string strloc = rcsId.substr(start, end-start);
411 // Check if specific repository
412 start = strloc.find("/cvsroot/");
413 if (start!=string::npos && start>0)
415 string repository = strloc.substr(0, start);
416 if (repository.find("/segfs/")!=string::npos)
417 strloc = "ESRF:" + strloc.substr(start, strloc.length()-start);
419 Tango::DbDatum cvs_loc("cvs_location");
420 cvs_loc << strloc;
421 data.push_back(cvs_loc);
425 // Get CVS tag revision
426 string tagname(TagName);
427 header = "$Name: ";
428 start = header.length();
429 string endstr(" $");
430 end = tagname.find(endstr);
431 if (end!=string::npos && end>start)
433 string strtag = tagname.substr(start, end-start);
434 Tango::DbDatum cvs_tag("cvs_tag");
435 cvs_tag << strtag;
436 data.push_back(cvs_tag);
439 // Get URL location
440 string httpServ(HttpServer);
441 if (httpServ.length()>0)
443 Tango::DbDatum db_doc_url("doc_url");
444 db_doc_url << httpServ;
445 data.push_back(db_doc_url);
448 // Put inheritance
449 Tango::DbDatum inher_datum("InheritedFrom");
450 vector<string> inheritance;
451 inheritance.push_back("Device_3Impl");
452 inher_datum << inheritance;
453 data.push_back(inher_datum);
455 // Call database and and values
456 //--------------------------------------------
457 get_db_class()->put_property(data);
460 } // namespace