Tango Core Classes Reference
9.3.4
|
Fundamental type for sending an dreceiving data to and from device attributes. More...
#include "tango.h"
Public Member Functions | |
Exception and error related methods | |
void | exceptions (bitset< numFlags > fl) |
Set exception flag. More... | |
bitset< numFlags > | exceptions () |
Get exception flag. More... | |
void | reset_exceptions (except_flags fl) |
Reset one exception flag. More... | |
void | set_exceptions (except_flags fl) |
Set one exception flag. More... | |
bitset< numFlags > | state () |
Get instance extraction state. More... | |
bool | has_failed () |
Check if the call failed. More... | |
const DevErrorList & | get_err_stack () |
Get the error stack. More... | |
Constructors | |
DeviceAttribute () | |
Create a DeviceAttribute object. More... | |
DeviceAttribute (string &name, short val) | |
Create a DeviceAttribute object from attribute name and value for scalar attribute. More... | |
DeviceAttribute (string &name, vector< short > &val) | |
Create a DeviceAttribute object from attribute name and value for spectrum attribute. More... | |
DeviceAttribute (string &name, vector< short > &val, int dim_x, int dim_y) | |
Create a DeviceAttribute object from attribute name and value for image attribute. More... | |
Inserters and Extractors | |
void | operator<< (short val) |
Insert attribute data. More... | |
void | insert (const char *str, unsigned char *data, unsigned int length) |
Insert attribute data for DevEncoded attribute. More... | |
void | insert (vector< short > &datum, int dim_x, int dim_y) |
Insert attribute data for image attribute (from C++ vector) More... | |
void | insert (const DevVarShortArray &datum, int dim_x, int dim_y) |
Insert attribute data for image attribute (from CORBA sequence by reference) More... | |
void | insert (DevVarShortArray *datum, int dim_x, int dim_y) |
Insert attribute data for image attribute (from CORBA sequence by pointer) More... | |
bool | operator>> (short &data) |
Extract attribute data. More... | |
bool | extract (const char *&str, unsigned char *&data, unsigned int &length) |
Extract attribute data for DevEncoded attribute. More... | |
bool | extract_read (vector< string > &data) |
Extract only read part of attribute data. More... | |
bool | extract_set (vector< string > &data) |
Extract only written part of attribute data. More... | |
Miscellaneous methods | |
bool | is_empty () |
Check is the instance is empty. More... | |
string & | get_name () |
Returns the name of the attribute. More... | |
void | set_name (string &na) |
Set attribute name. More... | |
void | set_name (const char *na) |
Set attribute name. More... | |
int | get_dim_x () |
Get attribute X dimension. More... | |
int | get_dim_y () |
Get attribute Y dimension. More... | |
int | get_written_dim_x () |
Get the attribute write X dimension. More... | |
int | get_written_dim_y () |
Get the attribute write Y dimension. More... | |
AttributeDimension | get_r_dimension () |
Get the attribute read dimensions. More... | |
AttributeDimension | get_w_dimension () |
Get the attribute write dimensions. More... | |
long | get_nb_read () |
Get the number of read value. More... | |
long | get_nb_written () |
Get the number of written value. More... | |
AttrQuality & | get_quality () |
Get attribute quality factor. More... | |
int | get_type () |
Get attribute data type. More... | |
AttrDataFormat | get_data_format () |
Get attribute data format. More... | |
TimeVal & | get_date () |
Get attribute read date. More... | |
Fundamental type for sending an dreceiving data to and from device attributes.
This is the fundamental type for sending and receiving data to and from device attributes. The values can be inserted and extracted using the operators << and >> respectively and insert() for mixed data types. There are two ways to check if the extraction operator succeed :
For insertion into DeviceAttribute instance from TANGO CORBA sequence pointers, the DeviceAttribute object takes ownership of the pointed to memory. This means that the pointed to memory will be freed when the DeviceAttribute object is destroyed or when another data is inserted into it. The insertion into DeviceAttribute instance from TANGO CORBA sequence reference copy the data into the DeviceAttribute object.
For extraction into TANGO CORBA sequence types, the extraction method consumes the memory allocated to store the data and it is the caller responsibility to delete this memory.
DeviceAttribute::DeviceAttribute | ( | ) |
Create a DeviceAttribute object.
Default constructor. The instance is empty
DeviceAttribute::DeviceAttribute | ( | string & | name, |
short | val | ||
) |
Create a DeviceAttribute object from attribute name and value for scalar attribute.
Create a DeviceAttribute object from attribute name and value for scalar attribute. These constructors exists for the following data type:
[in] | name | The attribute name |
[in] | val | The attribute value |
DeviceAttribute::DeviceAttribute | ( | string & | name, |
vector< short > & | val | ||
) |
Create a DeviceAttribute object from attribute name and value for spectrum attribute.
Create a DeviceAttribute object from attribute name and value for spectrum attribute. These constructors exists for the following data type:
[in] | name | The attribute name |
[in] | val | The attribute value |
DeviceAttribute::DeviceAttribute | ( | string & | name, |
vector< short > & | val, | ||
int | dim_x, | ||
int | dim_y | ||
) |
Create a DeviceAttribute object from attribute name and value for image attribute.
Create a DeviceAttribute object from attribute name and value for image attribute. These constructors have two more parameters allowing the user to define the x and y image dimensions. These constructors exists for the following data type:
[in] | name | The attribute name |
[in] | val | The attribute value |
[in] | dim_x | The attribute X dimension |
[in] | dim_y | The attribute Y dimension |
|
inline |
Get exception flag.
Returns the whole exception flags. The following is an example of how to use these exceptions related methods
|
inline |
Set exception flag.
Is a method which allows the user to switch on/off exception throwing when trying to extract data from a DeviceAttribute object. The following flags are supported :
[in] | fl | The exception flag |
Referenced by Tango::GroupAttrReply::operator>>().
bool DeviceAttribute::extract | ( | const char *& | str, |
unsigned char *& | data, | ||
unsigned int & | length | ||
) |
Extract attribute data for DevEncoded attribute.
Extract attribute data when the attribute data type is DevEncoded It's the user responsability to release the memory pointed to by the two pointers method parameter.
Similar method with following signature also exist extract(string &,vector<unsigned char> &);
See DeviceAttribute::operator<< for example of inserting and extracting data to/from DeviceAttribute instance
[out] | str | The DevEncoded string |
[out] | data | The DevEncoded data pointer |
[out] | length | The DevEncoded data length |
WrongData | if requested, DevFailed from device |
bool DeviceAttribute::extract_read | ( | vector< string > & | data | ) |
Extract only read part of attribute data.
Extract methods to extract only the read value of an attribute into a C++ vector. The dimension of the read value can be read by using the methods get_dim_x() and get_dim_y() or get_r_dimension(). The methods use the same return values as the extraction operators with exceptions triggered by the exception flags. This method exist for the following data type:
See DeviceAttribute::operator<< for example of inserting and extracting data to/from DeviceAttribute instance
[out] | data | The attribute data |
WrongData | if requested, DevFailed from device |
bool DeviceAttribute::extract_set | ( | vector< string > & | data | ) |
Extract only written part of attribute data.
Extract methods to extract only the set value of an attribute into a C++ vector. The dimension of the set value can be read by using the methods get_written_dim_x() and get_written_dim_y() or get_w_dimension(). The methods use the same return values as the extraction operators with exceptions triggered by the exception flags. This method exist for the following data type:
See DeviceAttribute::operator<< for example of inserting and extracting data to/from DeviceAttribute instance
[out] | data | The attribute data |
WrongData | if requested, DevFailed from device |
AttrDataFormat DeviceAttribute::get_data_format | ( | ) |
Get attribute data format.
Returns the attribute data format. Note that this information is valid only after the call to the device has been executed. Otherwise the FMT_UNKNOWN value of the AttrDataFormat enumeration is returned or an exception is thrown according to the object exception flags.
|
inline |
Get attribute read date.
Returns a reference to the time when the attribute was read in server
|
inline |
Get attribute X dimension.
Returns the attribute read x dimension
|
inline |
Get attribute Y dimension.
Returns the attribute read y dimension
|
inline |
Get the error stack.
Returns the error stack reported by the server when the attribute was read. The following is an example of the three available ways to get data out of a DeviceAttribute object
The first way uses the default behaviour of the DeviceAttribute object which is to throw an exception when the user try to extract data when the server reports an error when the attribute was read. In the second way, the DeviceAttribute object now does not throw "DevFailed" exception any more and the return value of the extractor operator is checked. IN the last case, the attribute data validity is checked before trying to extract them.
|
inline |
Returns the name of the attribute.
Returns the name of the attribute
long DeviceAttribute::get_nb_read | ( | ) |
Get the number of read value.
Returns the number of read values
long DeviceAttribute::get_nb_written | ( | ) |
Get the number of written value.
Returns the number of written values. Here is an example of these last methods usage.
|
inline |
Get attribute quality factor.
Returns the quality of the attribute: an enumerate type which can be one of:
AttributeDimension DeviceAttribute::get_r_dimension | ( | ) |
Get the attribute read dimensions.
Returns the attribute read dimensions
int DeviceAttribute::get_type | ( | ) |
Get attribute data type.
Returns the type of the attribute data.
AttributeDimension DeviceAttribute::get_w_dimension | ( | ) |
Get the attribute write dimensions.
Returns the attribute write dimensions
|
inline |
Get the attribute write X dimension.
Returns the attribute write x dimension
|
inline |
Get the attribute write Y dimension.
Returns the attribute write y dimension
|
inline |
Check if the call failed.
Returns a boolean set to true if the server report an error when the attribute was read.
void DeviceAttribute::insert | ( | const char * | str, |
unsigned char * | data, | ||
unsigned int | length | ||
) |
Insert attribute data for DevEncoded attribute.
Insert attribute data when the attribute data type is DevEncoded
Similar methods with following signature also exist
These three methods do not take ownership of the memory used for the data buffer.
See DeviceAttribute::operator<< for example of inserting and extracting data to/from DeviceAttribute instance
[in] | str | The DevEncoded string |
[in] | data | The DevEncoded data pointer |
[in] | length | The DevEncoded data length |
WrongData | if requested |
void DeviceAttribute::insert | ( | const DevVarShortArray & | datum, |
int | dim_x, | ||
int | dim_y | ||
) |
Insert attribute data for image attribute (from CORBA sequence by reference)
Insert methods for image attribute and for the following types by reference. These method allow the programmer to define the x and y image dimensions. The following methods are defined :
See DeviceAttribute::operator<< for example of inserting and extracting data to/from DeviceAttribute instance
[in] | datum | The attribute data |
[in] | dim_x | The attribute X dimension |
[in] | dim_y | The attribute Y dimension |
WrongData | if requested |
void DeviceAttribute::insert | ( | DevVarShortArray * | datum, |
int | dim_x, | ||
int | dim_y | ||
) |
Insert attribute data for image attribute (from CORBA sequence by pointer)
Insert methods for image attribute and pointers. The DeviceAttribute object takes ownership of the given memory. These method allow the programmer to define the x and y image dimensions. The following methods are defined :
See DeviceAttribute::operator<< for example of inserting and extracting data to/from DeviceAttribute instance
[in] | datum | The attribute data |
[in] | dim_x | The attribute X dimension |
[in] | dim_y | The attribute Y dimension |
WrongData | if requested |
void DeviceAttribute::insert | ( | vector< short > & | datum, |
int | dim_x, | ||
int | dim_y | ||
) |
Insert attribute data for image attribute (from C++ vector)
Insert methods for the following C++ vector types for image attributes allowing the specification of the x and y image dimensions :
See DeviceAttribute::operator<< for example of inserting and extracting data to/from DeviceAttribute instance
[in] | datum | The attribute data |
[in] | dim_x | The attribute X dimension |
[in] | dim_y | The attribute Y dimension |
WrongData | if requested |
bool DeviceAttribute::is_empty | ( | ) |
Check is the instance is empty.
is_empty() is a boolean method which returns true or false depending on whether the DeviceAttribute object contains data or not. Note that by default, a DeviceAttribute object throws exception if it is empty (See DeviceAttribute::exceptions() method). If you want to use this method, you have to change this default behavior. It can be used to test whether the DeviceAttribute has been initialized or not e.g.
WrongData | if requested |
void DeviceAttribute::operator<< | ( | short | val | ) |
Insert attribute data.
Special care has been taken to avoid memory copy between the network layer and the user application. Nevertheless, C++ vector types are not the CORBA native type and one copy is unavoidable when using vectors. Using the native TANGO CORBA sequence types in most cases avoid any copy but needs some more care about memory usage.
Insert operators for the following scalar C++ types
Insert operators for the following C++ vector types for spectrum attributes :
Insert operators for spectrum attribute and for the following types by pointer (with memory ownership transfert) :
Insert operators for spectrum attribute and for the following types by reference :
Here is an example of creating, inserting and extracting some DeviceAttribute types :
[in] | val | The attribute value |
WrongData | if requested |
bool DeviceAttribute::operator>> | ( | short & | data | ) |
Extract attribute data.
Special care has been taken to avoid memory copy between the network layer and the user application. Nevertheless, C++ vector types are not the CORBA native type and one copy is unavoidable when using vectors. Using the native TANGO CORBA sequence types in most cases avoid any copy but needs some more care about memory usage.
Extract operators for the following scalar C++ types
Extract operators for the following C++ vector types for spectrum and image attributes :
Extract operators for the following CORBA sequence types with memory consumption :
See DeviceAttribute::operator<< for example of inserting and extracting data to/from DeviceAttribute instance
[out] | data | The attribute data |
WrongData | if requested, DevFailed from device |
|
inline |
Reset one exception flag.
Resets one exception flag
[in] | fl | The exception flag |
|
inline |
Set one exception flag.
Sets one exception flag. The following is an example of how to use this exceptions related methods
There is another usage example in the DeviceAttribute::exceptions() method documentation.
[in] | fl | The exception flag |
|
inline |
Set attribute name.
Set attribute name
na | The attribute name |
|
inline |
Set attribute name.
Set attribute name
na | The attribute name |
|
inline |
Get instance extraction state.
Allow the user to find out what was the reason of extraction from DeviceAttribute failure. This method has to be used when exceptions are disabled. Here is an example of how method state() could be used