release
[tango-nonfree.git] / lib / cpp / server / multiattribute.h
blob4296d229cbf06663f4a3d00707ec53564c030a50
1 //=============================================================================
2 //
3 // file : MultiAttribute.h
4 //
5 // description : Include file for the MultiAttribute class.
6 // Each device has one object of this class. All device
7 // attribute objects are stored in this class
8 //
9 // project : TANGO
11 // author(s) : A.Gotz + E.Taurel
13 // Copyright (C) : 2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015
14 // European Synchrotron Radiation Facility
15 // BP 220, Grenoble 38043
16 // FRANCE
18 // This file is part of Tango.
20 // Tango is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU Lesser General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
25 // Tango is distributed in the hope that it will be useful,
26 // but WITHOUT ANY WARRANTY; without even the implied warranty of
27 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 // GNU Lesser General Public License for more details.
30 // You should have received a copy of the GNU Lesser General Public License
31 // along with Tango. If not, see <http://www.gnu.org/licenses/>.
33 // $Revision: 28373 $
36 //=============================================================================
38 #ifndef _MULTIATTRIBUTE_H
39 #define _MULTIATTRIBUTE_H
41 #include <tango.h>
43 namespace Tango
46 class AttrProperty;
47 class DeviceClass;
49 struct EventPar
51 long attr_id;
52 vector<int> change;
53 vector<int> archive;
54 bool quality;
55 vector<int> periodic;
56 vector<int> user;
57 vector<int> att_conf;
58 bool data_ready;
59 bool dev_intr_change;
60 bool notifd;
61 bool zmq;
64 //=============================================================================
66 // The MultiAttribute class
69 // description : There is one instance of this class for each device.
70 // This is mainly a helper class. It maintains a vector
71 // of all the attribute for the device
73 //=============================================================================
75 /**
76 * There is one instance of this class for each device. This class is mainly
77 * an aggregate of Attribute or WAttribute objects. It eases management of
78 * multiple attributes
80 * $Author: taurel $
81 * $Revision: 28373 $
83 * @headerfile tango.h
84 * @ingroup Server
87 class MultiAttribute
89 public:
90 /**@name Constructor
91 * Only one constructor is defined for this class */
92 //@{
93 /**
94 * Create a new MultiAttribute object.
96 * This constructor will in-turn call the constructor of the Attribute or
97 * WAttribute class of all the device class attributes.
99 * @param dev_name The device name
100 * @param dev_class Reference to the device DeviceClass object
101 * @param dev The device pointer
102 * @exception DevFailed If the command sent to the database failed.
103 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
104 * <b>DevFailed</b> exception specification
106 MultiAttribute(string &dev_name,DeviceClass *dev_class,DeviceImpl *dev);
107 //@}
109 /**@name Destructor
110 * Only one desctructor is defined for this class */
111 //@{
113 * The MultiAttribute desctructor.
115 ~MultiAttribute();
116 //@}
118 /**@name Miscellaneous methods */
119 //@{
121 * Get Attribute object from its name.
123 * This method returns a reference to the Attribute object with a name passed
124 * as parameter. The equality on attribute name is case independant.
126 * @param attr_name The attribute name
127 * @return A reference to the Attribute object
128 * @exception DevFailed If the attribute is not defined.
129 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
130 * <b>DevFailed</b> exception specification
132 Attribute &get_attr_by_name(const char *attr_name);
134 * Get Attribute object from its index.
136 * This method returns a reference to the Attribute object from the index in the
137 * main attribute vector
139 * @param ind The attribute index
140 * @return A reference to the Attribute object
142 Attribute &get_attr_by_ind(const long ind) {return *(attr_list[ind]);}
144 * Get Writable Attribute object from its name.
146 * This method returns a reference to the WAttribute object with a name passed
147 * as parameter. The equality on attribute name is case independant.
149 * @param attr_name The attribute name
150 * @return A reference to the writable attribute object
151 * @exception DevFailed If the attribute is not defined.
152 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
153 * <b>DevFailed</b> exception specification
155 WAttribute &get_w_attr_by_name(const char *attr_name);
157 * Get Writable Attribute object from its index.
159 * This method returns a reference to the Writable Attribute object from the
160 * index in the main attribute vector
162 * @param ind The attribute index
163 * @return A reference to the WAttribute object
165 WAttribute &get_w_attr_by_ind(const long ind) {return static_cast<WAttribute &>(*(attr_list[ind]));}
167 * Get Attribute index into the main attribute vector from its name.
169 * This method returns the index in the Attribute vector (stored in the
170 * MultiAttribute object) of an attribute with a given name. The name equality
171 * is case independant
173 * @param attr_name The attribute name
174 * @return The index in the main attributes vector
175 * @exception DevFailed If the attribute is not found in the vector.
176 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
177 * <b>DevFailed</b> exception specification
179 long get_attr_ind_by_name(const char *attr_name);
181 * Get list of attribute with an alarm level defined.
183 * @return A vector of long data. Each object is the index in the main
184 * attribute vector of attribute with alarm level defined
186 vector<long> &get_alarm_list() {return alarm_attr_list;}
188 * Get attribute number.
190 * @return The attribute number
192 unsigned long get_attr_nb() {return (unsigned long)attr_list.size();}
195 * Check alarm for one attribute with a given name.
197 * This method returns a boolean set to true if the attribute with the given
198 * name is in alarm condition
200 * @param attr_name The attribute name
201 * @return A boolean set to true if the attribute is in alarm
202 * @exception DevFailed If the attribute does not have any alarm level defined.
203 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
204 * <b>DevFailed</b> exception specification
207 bool check_alarm(const char *attr_name) {return get_attr_by_name(attr_name).check_alarm();}
209 * Check alarm for one attribute from its index in the main attributes vector.
211 * This method returns a boolean set to true if the attribute with the given
212 * index in the attrobite object vector is in alarm condition
214 * @param ind The attribute index
215 * @return A boolean set to true if the attribute is in alarm
216 * @exception DevFailed If the attribute does not have any alarm level defined.
217 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
218 * <b>DevFailed</b> exception specification
221 bool check_alarm(const long ind) {return get_attr_by_ind(ind).check_alarm();}
223 * Check alarm on all attribute(s) with an alarm defined.
225 * This method returns a boolean set to true if one of the attribute with an
226 * alarm level defined is in alarm condition.
228 * @return A boolean set to true if one attribute is in alarm
229 * @exception DevFailed If the alarm level are not defined for one of the
230 * attribute in the list of alarmable one
231 * Click <a href="../../../tango_idl/idl_html/_Tango.html#DevFailed">here</a> to read
232 * <b>DevFailed</b> exception specification
235 bool check_alarm();
237 * Add alarm message to device status.
239 * This method add alarm mesage to the string passed as parameter. A message
240 * is added for each attribute which is in alarm condition
242 * @param status The string (should be the device status)
244 void read_alarm(string &status);
246 * Get the vector of attribute objects.
248 * Returns the vector of attribute objects.
251 vector<Attribute *> &get_attribute_list(){return attr_list;}
252 //@}
254 protected:
255 /**@name Class data members */
256 //@{
258 * The Attribute objects vector.
260 * This vector is often referred as the main attributes vector
262 vector<Attribute *> attr_list;
264 * The list of writable attribute.
266 * It is a vector of index in the main attribute vector
268 vector<long> writable_attr_list;
270 * The list of attribute with an alarm level defined.
272 * It is a vector of index in the main attribute vector
274 vector<long> alarm_attr_list;
275 //@}
277 public:
278 /// @privatesection
280 void add_write_value(Attribute &);
281 void add_attribute(string &,DeviceClass *,long);
282 void add_fwd_attribute(string &,DeviceClass *,long,Attr *);
283 void remove_attribute(string &,bool);
284 vector<long> &get_w_attr_list() {return writable_attr_list;}
285 bool is_att_quality_alarmed();
286 void get_event_param(vector<EventPar> &);
287 void set_event_param(vector<EventPar> &);
288 void add_alarmed_quality_factor(string &);
289 void add_default(vector<AttrProperty> &,string &,string &,long);
290 void add_attr(Attribute *att) {attr_list.push_back(att);}
291 void update(Attribute &,string &);
292 void check_idl_release(DeviceImpl *);
293 bool is_opt_prop(const string &);
295 private:
296 class MultiAttributeExt
300 void concat(vector<AttrProperty> &,vector<AttrProperty> &,vector<AttrProperty> &);
301 void add_user_default(vector<AttrProperty> &,vector<AttrProperty> &);
302 void check_associated(long,string &);
304 #ifdef HAS_UNIQUE_PTR
305 unique_ptr<MultiAttributeExt> ext; // Class extension
306 #else
307 MultiAttributeExt *ext;
308 #endif
312 } // End of Tango namespace
314 #endif // _MULTIATTRIBUTE_H