1 //=============================================================================
3 // file : Deviceclass.h
5 // description : Include file for the DeviceClass root class.
9 // author(s) : E.Taurel
11 // Copyright (C) : 2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015
12 // European Synchrotron Radiation Facility
13 // BP 220, Grenoble 38043
16 // This file is part of Tango.
18 // Tango is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU Lesser General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
23 // Tango is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU Lesser General Public License for more details.
28 // You should have received a copy of the GNU Lesser General Public License
29 // along with Tango. If not, see <http://www.gnu.org/licenses/>.
34 //=============================================================================
36 #ifndef _DEVICECLASS_H
37 #define _DEVICECLASS_H
45 class AutoTangoMonitor
;
46 class NoSyncModelTangoMonitor
;
52 //=============================================================================
54 // The DeviceClass class
57 // description : This class will act as root class for all other
58 // DeviceClass classes. Its job is to define all Device
59 // class related properties and methods which exist only
60 // once e.g. the command list.
62 //=============================================================================
65 * Base class for all TANGO device-class class. A TANGO device-class class is
66 * a class where is stored all data/method common to all devices of a TANGO
84 friend class Tango::AutoTangoMonitor
;
88 * Only one desctructor is defined for this class */
91 * The device destructor.
93 virtual ~DeviceClass();
96 /**@name Miscellaneous methods */
101 * It looks for the correct command object in the command object vector.
102 * If the command is found, it invoke the <i>always_executed_hook</i> method.
103 * Check if the command is allowed by invoking the <i>is_allowed</i> method
104 * If the command is allowed, invokes the <i>execute</i> method.
106 * @param device The device on which the command must be executed
107 * @param command The command name
108 * @param in_any The command input data still packed in a CORBA Any object
109 * @return A CORBA Any object with the output data packed in
110 * @exception DevFailed If the command is not found, if the command is not allowed
111 * in the actual device state and re-throws of all the exception thrown by the
112 * <i>always_executed_hook</i>, <i>is_alloed</i> and <i>execute</i> methods.
113 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
114 * <b>DevFailed</b> exception specification
117 CORBA::Any
*command_handler(DeviceImpl
*device
,
118 string
&command
,const CORBA::Any
&in_any
);
120 * Create command objects for all command supported by this class of device.
122 * In the DeviceClass class, this method is pure abstract and must be defined
123 * in sub-class. Its rule is to create the command object and to store them
124 * in a vector of command objects
127 virtual void command_factory() = 0;
129 * Create all the attributes name supported by this class of device.
131 * In the DeviceClass class, this method does nothing and must be re-defined
132 * in sub-class if the sub-class supports attributes. Its rule is to
133 * create and store the supported attributes in a vector.
136 virtual void attribute_factory(vector
<Attr
*> &) {};
138 * Create all the pipes supported by this class of device.
140 * In the DeviceClass class, this method does nothing and must be re-defined
141 * in sub-class if the sub-class supports pipes. Its rule is to
142 * create and store the supported pipes in a vector.
145 virtual void pipe_factory() {};
150 * In the DeviceClass class, this method is pure abstract and must be defined
151 * in sub-class. Its rule is to create all the class devices and to store them
152 * in a vector of device
154 * @param dev_list The device name list
155 * @exception DevFailed This method does not throw exception but a
156 * redefined method can.
157 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
158 * <b>DevFailed</b> exception specification
160 virtual void device_factory(const Tango::DevVarStringArray
*dev_list
) = 0;
163 * Create device(s) name list (for no database device server).
165 * This method can be re-defined in DeviceClass sub-class for device server
166 * started without database. Its rule is to initialise class device name.
167 * The default method does nothing.
169 * @param list Reference to the device name list
172 virtual void device_name_factory(vector
<string
> &list
) {(void)list
;};
177 * The rule of this method is to delete a device from the running
178 * server belonging to the Tango class. It does change anything in the
181 * @param dev_name Reference to the device name
184 void device_destroyer(const string
&dev_name
);
189 * The rule of this method is to delete a device from the running
190 * device belonging to the Tango class. It does change anything in the
193 * @param dev_name Reference to the device name
196 void device_destroyer(const char *dev_name
);
200 /**@name Get/Set object members.
201 * These methods allows the external world to get/set DeviceImpl instance
206 * Get the TANGO device class name.
208 * @return The TANGO device class name
210 string
&get_name() {return name
;}
212 * Get the TANGO device class documentation URL.
214 * @return The TANGO device class documentation
216 string
&get_doc_url() {return doc_url
;}
218 * Get the TANGO device type name.
220 * @return The TANGO device type name
222 string
&get_type() {return type
;}
224 * Get the device object vector.
226 * @return A reference to the device vector
228 vector
<DeviceImpl
*> &get_device_list() {return device_list
;}
230 * Get the command object vector.
232 * @return A reference to the command vector
234 vector
<Command
*> &get_command_list() {return command_list
;}
236 * Get the pipe object vector.
238 * @param dev_name The device name
240 * @return A reference to the pipe vector containing all device pipes
242 vector
<Pipe
*> &get_pipe_list(const string
&dev_name
);
244 * Get a reference to a command object.
246 * @return A reference to the command object
248 Command
&get_cmd_by_name(const string
&);
250 * Get a reference to a pipe object.
252 * @param pipe_name The pipe name
253 * @param dev_name The device name
255 * @return A reference to the pipe object
257 Pipe
&get_pipe_by_name(const string
&pipe_name
,const string
&dev_name
);
259 * Get a pointer to the associated DbClass object.
261 * @return Pointer to the DbClas object
264 DbClass
*get_db_class() {return db_class
;}
266 * Get a pointer to the class attributes object
268 * @return A pointer to the instance of the MultiClassAttribute
270 MultiClassAttribute
*get_class_attr() {return class_attr
;}
272 * Get a pointer to the class pipes object
274 * @return A pointer to the instance of the MultiClassPipe
276 MultiClassPipe
*get_class_pipe() {return class_pipe
;}
278 * Set the TANGO device type name.
280 * @param dev_type The new TANGO device type name
282 void set_type(string
&dev_type
) {type
= dev_type
;}
284 * Set the TANGO device type name.
286 * @param dev_type The new TANGO device type name
288 void set_type(const char *dev_type
) {type
= dev_type
;}
292 /**@name Signal related methods
293 * These methods allow a signal management at device level */
295 #if defined _TG_WINDOWS_
299 * Register this class as class to be informed when signal signo is sent to
300 * to the device server process
302 * @param signo The signal number
303 * @exception DevFailed Thrown if the signal number is out of range or if the
304 * operating system failed to register a signal for the process.
305 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
306 * <b>DevFailed</b> exception specification
308 void register_signal(long signo
);
313 * Register this class as class to be informed when signal signo is sent to
314 * to the device server process. This method is available only under Linux.
316 * @param signo The signal number
317 * @param own_handler A boolean set to true if you want the device signal handler
318 * to be executed in its own handler instead of being executed by the signal
319 * thread. If this parameter is set to true, care should be taken on how the
320 * handler is written. A default false value is provided * @exception DevFailed Thrown if the signal number is out of range or if the
321 * operating system failed to register a signal for the process.
322 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
323 * <b>DevFailed</b> exception specification
325 void register_signal(long signo
,bool own_handler
= false);
329 * Unregister a signal.
331 * Unregister this class as class to be informed when signal signo is sent to
332 * to the device server process
334 * @param signo The signal number
335 * @exception DevFailed Thrown if the signal number is out of range or if the
336 * operating system failed to unregister a signal for the process. Unregister
337 * a device for a signal number for a device not previously registered is not
338 * an error. This simply will do nothing.
339 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
340 * <b>DevFailed</b> exception specification
342 void unregister_signal(long signo
);
347 * The method executed when the signal arrived in the device server process.
348 * This method is defined as virtual and then, can be redefined following
349 * device class needs.
351 * @param signo The signal number
353 virtual void signal_handler(long signo
);
359 Only one constructot for this class which is a singleton */
362 * Construct a newly allocated DeviceClass object.
364 * @param s The Tango device class name
367 DeviceClass(string
&s
);
370 /**@name Miscellaneous protected methods */
375 * Associate the servant to a CORBA object and send device network parameter
376 * to TANGO database. The main parameter sent to database is the CORBA
377 * object stringified device IOR.
379 * @param dev The device to be exported (CORBA servant)
380 * @param corba_dev_name The name to be used in the CORBA object key. This
381 * parameter does not need to be set in most of cases and has a default value.
382 * It is used for special device server like the database device server.
383 * @exception DevFailed If the command sent to the database failed.
384 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
385 * <b>DevFailed</b> exception specification
387 void export_device(DeviceImpl
*dev
,const char* corba_dev_name
= "Unused");
390 * Set a Tango classs default command
392 * Define one command to be the Tango class default command
393 * The default command is the command which will be exceuted when
394 * an unknown command is sent to one of the Tango class device
395 * By default, there is no default class
397 * @param cmd The command object
400 void set_default_command(Command
*cmd
) {default_cmd
= cmd
;}
403 /**@name Class data members */
406 * The TANGO device class name
410 * The TANGO device class documentation URL
414 * The TANGO device type name
418 * The command(s) list
420 vector
<Command
*> command_list
;
424 vector
<DeviceImpl
*> device_list
;
426 * The associated DbClass object
430 * Pointer to the class multi attribute object
432 MultiClassAttribute
*class_attr
;
434 * Pointer to the class multi pipe object
436 MultiClassPipe
*class_pipe
;
440 vector
<Pipe
*> pipe_list
;
445 vector
<string
> &get_nodb_name_list() {return nodb_name_list
;}
446 void set_memorized_values(bool flag
, long idx
= 0,bool from_init
= false);
448 void add_wiz_dev_prop(string
&name
,string
&desc
,string
&def
);
449 void add_wiz_dev_prop(string
&name
,string
&desc
);
451 void add_wiz_class_prop(string
&name
,string
&desc
,string
&def
);
452 void add_wiz_class_prop(string
&name
,string
&desc
);
454 vector
<string
> &get_wiz_class_prop() {return wiz_class_prop
;}
455 vector
<string
> &get_wiz_dev_prop() {return wiz_dev_prop
;}
457 string
&get_cvs_tag() {return cvs_tag
;}
458 string
&get_cvs_location() {return cvs_location
;}
460 string
&get_svn_tag() {return svn_tag
;}
461 string
&get_svn_location() {return svn_location
;}
463 void set_cvs_tag(string
&str
) {cvs_tag
=str
;}
464 void set_cvs_location(string
&str
) {cvs_location
=str
;}
466 void add_device(DeviceImpl
*dev
) {device_list
.push_back(dev
);}
467 void delete_dev(long idx
,Tango::Util
*tg
,PortableServer::POA_ptr r_poa
);
469 bool is_py_class() {return py_class
;}
470 void set_py_class(bool py
) {py_class
=py
;}
471 virtual void delete_class() {}
472 void get_mcast_event(DServer
*);
474 bool is_command_allowed(const char *);
476 bool get_device_factory_done() {return device_factory_done
;}
477 void set_device_factory_done(bool val
) {device_factory_done
= val
;}
479 void check_att_conf();
480 void release_devices_mon();
482 void remove_command(const string
&);
484 void create_device_pipe(DeviceClass
*,DeviceImpl
*);
485 vector
<Pipe
*> &get_pipe_list() {return pipe_list
;}
489 Command
*get_default_command() {return default_cmd
;}
497 map
<string
,vector
<Pipe
*> > dev_pipe_list
;
500 void get_class_system_resource();
501 void throw_mem_value(DeviceImpl
*,Attribute
&);
503 vector
<string
> wiz_class_prop
;
504 vector
<string
> wiz_dev_prop
;
506 vector
<string
> allowed_cmds
;
508 #ifdef HAS_UNIQUE_PTR
509 unique_ptr
<DeviceClassExt
> ext
; // Class extension
515 // Ported from the extension class
518 vector
<string
> nodb_name_list
;
519 TangoMonitor only_one
;
522 Command
* default_cmd
;
526 bool device_factory_done
;
530 } // End of Tango namespace
532 #endif // _DEVICECLASS_H