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 //+=============================================================================
6 // file : PseudoAxesClass.cpp
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
21 // copyleft : European Synchrotron Radiation Facility
22 // BP 220, Grenoble 38043
25 //-=============================================================================
27 // This file is generated by POGO
28 // (Program Obviously used to Generate tango Object)
30 // (c) - Software Engineering Group - ESRF
31 //=============================================================================
36 #include <PseudoAxes.h>
37 #include <PseudoAxesClass.h>
40 //+----------------------------------------------------------------------------
42 * Create PseudoAxesClass singleton and return it in a C function for Python usage
44 //+----------------------------------------------------------------------------
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()
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)
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()
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
)
140 _instance
= new PseudoAxesClass(s
);
150 PseudoAxesClass
*PseudoAxesClass::instance()
152 if (_instance
== NULL
)
154 cerr
<< "Class is not initialised !!" << endl
;
160 //+----------------------------------------------------------------------------
162 // method : PseudoAxesClass::command_factory
164 // description : Create the command object(s) and store them in the
167 //-----------------------------------------------------------------------------
168 void PseudoAxesClass::command_factory()
170 command_list
.push_back(new AxisInitClass("AxisInit",
171 Tango::DEV_VOID
, Tango::DEV_VOID
,
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
)
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
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());
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
)
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
;
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()
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";
344 if (prop_def
.length()>0)
346 Tango::DbDatum
data(prop_name
);
348 dev_def_prop
.push_back(data
);
349 add_wiz_dev_prop(prop_name
, prop_desc
, prop_def
);
352 add_wiz_dev_prop(prop_name
, prop_desc
);
354 prop_name
= "EngineName";
355 prop_desc
= "name of the HklPseudoAxisEngine used by this device.";
357 if (prop_def
.length()>0)
359 Tango::DbDatum
data(prop_name
);
361 dev_def_prop
.push_back(data
);
362 add_wiz_dev_prop(prop_name
, prop_desc
, prop_def
);
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)
383 string classname
= get_name();
385 string::size_type start
, end
;
388 Tango::DbDatum
title("ProjectTitle");
389 string
str_title("");
391 data
.push_back(title
);
394 Tango::DbDatum
description("Description");
395 vector
<string
> str_desc
;
396 str_desc
.push_back(" ");
397 description
<< str_desc
;
398 data
.push_back(description
);
402 string
filename(classname
);
403 start
= rcsId
.find("/");
404 if (start
!=string::npos
)
406 filename
+= "Class.cpp";
407 end
= rcsId
.find(filename
);
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");
421 data
.push_back(cvs_loc
);
425 // Get CVS tag revision
426 string
tagname(TagName
);
428 start
= header
.length();
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");
436 data
.push_back(cvs_tag
);
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
);
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
);