13. Data in the OpenSCADA system and their storage in the DB (TConfig)
Storing data in the system based on the objects TConfig and TElem. These objects store the structure and fields' values of the database, allowing for direct loading and saving the configuration via the "DB" subsystem. For the specialized different types data storage the TVariant object is provided.
TElem object contains the structure of database record. Structure of the record contains extensive information about the elements, their types, sizes and other parameters. Information in this structure is enough to create, control and manage the real structure of the database. Elementary unit of the record is the cell Tfld.
TSonfig object is the heir of TElem and contains the actual values of elements. TConfig is used as the parameter in the functions of the manipulating with the table's records in the "DB" subsystem. Elementary unit of the record is the cell TCfg.
To provide an opportunity to inform the data storehouse about the changes in the structure it is provides an object TValElem, from which it is inherited the storehouse TConfig and the list of which is contained in the TElem structure.
13.1. Data object (TConfig)
| Inherits: | TValElem |
| Inherited: | TParamContr, TController, TMArchivator, TPrmTempl, TPrmTmplLib, TUser, TGroup, TTransportIn, TTransportOut, TBD, TVArchive, TVArchivator, а также модульные объекты хранящие свои данные в БД. |
Public methods:
- TConfig( TElem *Elements = NULL ); - Initializing constructor.
- TConfig &operator=( TConfig &cfg ); - Copying from <cfg>.
- void cfgList( vector<string> &list ); - Elements' list <list>.
- bool cfgPresent( const string &n_val ); - Check for the element's presence <n_val>.
- TCfg &cfg( const string &n_val ); - Getting of th element <n_val>.
- TCfg *at( const string &n_val, bool noExpt = false ); - Getting of the element's pointer <n_val>. If the element is absent an exception is generated or the null pointer is returned when setting <noExpt>.
- void cfgViewAll( bool val = true ); - Set/unset the sign of the visibility for all the elements.
- void cfgKeyUseAll( bool val ); - Set/unset the sign of the using the key for all the elements.
- TElem &elem( ); - The using structure.
- void setElem( TElem *Elements, bool first = false ); - Setting the structure in <Elements>.
- void cntrCmdMake( XMLNode *fld, const string &path, int pos, const string &user = "root", const string &grp = "root", int perm = 0664 ); - Formation of the information description of elements of the configuration for the management interface of OpenSCADA.
- void cntrCmdProc( XMLNode *fld, const string &elem, const string &user = "root", const string &grp = "root", int perm = 0664 ); - Requests' of the OpenSCADA management interface to the elements of the configuration processing.
- bool noTransl( ); - The sign: "Do not broadcast messages when working with the database".
- void setNoTransl( bool vl ); - Setting the sign of the broadcasting the messages.
Protected methods:
- virtual bool cfgChange( TCfg &cfg ); - Is called in the case of changing the contents of the configuration element.
13.2. Data cell (TCfg)
Data:
Additional flags to TFld (enum - TCfg::AttrFlg):
- TCfg::TransltText - Translate the text variables of the record.
- TCfg::NoVal - Do not reflect an element on the value of the TValue object.
- TCfg::Key - key field.
- TCfg::Hide - attribute is hidden.
Requests flags (enum - ReqFlg):
- TFld::ForceUse - Forcing the setting of the flag of the element's using during the setting of its value.
Public methods:
- TCfg( TFld &fld, TConfig &owner ); - Initializing constructor.
- const string &name( ); - Cell name.
- bool operator==( TCfg &cfg ); - Comparison of the cells.
- TCfg &operator=( TCfg &cfg ); - Copying of the cells.
- bool view( ); - The sign - "Cell is visible".
- bool keyUse( ); - The sign - "Use the key" for the dataSeek() and dataDel() requests.
- bool noTransl( ); - The sign "No translation" is provided to disable the translation of text variables for the record at the time of a request.
- void setView( bool vw ); - Setting of the sign "The cell is visible" в <vw>.
- void setKeyUse( bool vl ); - Setting of the sign "Use the key" in <vl>.
- void setNoTransl( bool vl ); - Setting of the sign "No translation".
- TFld &fld( ); - Configuration of the cell.
- string getSEL( char RqFlg = 0 ); - Get the value of the selective type with the request flags <RqFlg>.
- string getS( char RqFlg = 0 ); - Get the value of the string type with the request flags <RqFlg>.
- double getR( char RqFlg = 0 ); - Get the value of the real type with the request flags <RqFlg>.
- int getI( char RqFlg = 0 ); - Get the value of the integer type with the request flags <RqFlg>.
- bool getB( char RqFlg = 0 ); - Get the value of the boolean type with the request flags <RqFlg>.
- string &getSd( ); - Get the direct access to the string type value.
- double &getRd( ); - Get the direct access to the real type value.
- int &getId( ); - Get the direct access to the integer type value.
- bool &getBd( ); - Get the direct access to the boolean type value.
- void setSEL( const string &val, char RqFlg = 0 ); - Set the value of the selective type to the <val> with the request flags <RqFlg>.
- void setS( const string &val, char RqFlg = 0 ); - Set the value of the string type to the <val> with the request flags <RqFlg>.
- void setR( double val, char RqFlg = 0 ); - Set the value of the real type to the <val> with the request flags <RqFlg>.
- void setI( int val, char RqFlg = 0 ); - Set the value of the integer type to the <val> with the request flags <RqFlg>.
- void setB( bool val, char RqFlg = 0 ); - Set the value of the boolean type to the <val> with the request flags <RqFlg>.
13.3. Data structure object (TElem)
| Inherited: | By the TTipParam, TControllerS, TTipController, as well as by the modular objects, combining the functions of the structure storage . |
Public methods:
- TElem( const string &name = "" ); - Initialization of the structure with the specified name <name>.
- string &elName( ); - The name if the structure.
- void fldList( vector<string> &list ); - The cell's list in the structure <list>.
- unsigned fldSize( ); - The number of cells in the structure.
- unsigned fldId( const string &name); - Getting the index of the cell from its identifier <name>.
- bool fldPresent( const string &name ); - Check for the presence of the specified cell <name>.
- int fldAdd( TFld *fld, int id = -1 ); - Addition/insert of the cell <fld> to the position <id> (-1 - insert to the end).
- void fldDel( unsigned int id ); - Deleting of the cell <id>.
- TFld &fldAt( unsigned int id ); - Getting of the cell <id>.
- void valAtt( TValElem *cnt ); - Is called automatically when the structure is attached to the data storage <cnt>.
- void valDet( TValElem *cnt ); - Is called automatically when the structure is detached from the data storage <cnt>.
13.4. Data structure cell (TFld)
Data:
Cell's type (enum – TFld::Type):
- TFld::Boolean(0) - boolean type;
- TFld::Integer(1) - integer type;
- TFld::Real(4) - real type;
- TFld::String(5) - string type.
Cell's flags (enum - TFld::AttrFlg):
- TFld::NoFlag - No flags;
- TFld::Selected - selection mode from the available values, the selective type;
- TFld::SelfFld - To create the own copy of this cell;
- TFld::NoWrite - unwritable;
- TFld::HexDec - integer type: hexadecimal notation;
- TFld::OctDec - integer type: octal notation;
- TFld::DateTimeDec - integer type: содержит дату в UTC;
- TFld::FullText - Full-text, multi-string mode of the text type.
Public methods:
- TFld( ); - Initialization by default.
- TFld( TFld &ifld ); - Copying constructor.
- TFld( const char *name, const char *descr, Type type, unsigned char flg, const char *valLen = "", const char *valDef = "", const char *vals = "", const char *nSel = "", const char *res = "" ); - Initialization with the specified configuration.
- TFld &operator=( TFld &fld ); - Copy of the cell from <fld>.
- const string &name( ); - Cell's name.
- const string &descr( ); - Cell's description.
- int len( ); - The size of the cell's value (symbols in symbolic representation).
- int dec( ); - The size of the fractional part of a real (symbols in symbolic representation).
- Type type( ); - Cell's type.
- unsigned flg( ); - Cell's flag.
- const string &def( ); - Default value.
- string values( ); - Working range of the value or a list of possible values for the selective type (as - "vl1;vl2;vl3").
- string selNames( ); - List of names of values for the selective type (as - "Value 1;Value 2;Value 3").
- const string &reserve( ); - Reserve parameter.
- void setDescr( const string &dscr ); - Set the descrition to the <dscr>.
- void setLen( int vl ); - Set the cell's size to the <vl>.
- void setDec( int vl ); - Set the fraction part of the real to the <vl>.
- void setDef( const string &def ); - Set the default value to the <def>.
- void setFlg( unsigned flg ); - Set the flags to <flg>.
- void setValues( const string &vls ); - Set the working range of value or the list of possible values for the selective type (as - "vl1;vl2;vl3") to the <vls>.
- void setSelNames( const string &slnms ); - Set the list of values' names for the selective type (as - "Value 1;Value 2;Value 3") to the <slnms>.
- void setReserve( const string &ires ); - Set of the reserve parameter to <res>.
- const vector<string> &selValS(); - List of values' variants for the string type.
- const vector<int> &selValI(); - List of values' variants for the integer type.
- const vector<double> &selValR(); - List of values' variants for the real type
- const vector<bool> &selValB(); - List of values' variants for the boolean type
- const vector<string> &selNm(); - List of the names of values' variants.
- string selVl2Nm( const string &val ); - Get the selected name from the value <val> of the string type.
- string selVl2Nm( int val ); - Get the selected name from the value <val> of the integer type.
- string selVl2Nm( double val ); - Get the selected name from the value <val> of the real type.
- string selVl2Nm( bool val ); - Get the selected name from the value <val>of the boolean type.
- string selNm2VlS( const string &name ); - Get the value of string type from the selected name <name>.
- int selNm2VlI( const string &name ); - Get the value of integer type from the selected name <name>.
- double selNm2VlR( const string &name ); - Get the value of real type from the selected name <name>.
- bool selNm2VlB( const string &name ); - Get the value of boolean type from the selected name <name>.
- XMLNode *cntrCmdMake( XMLNode *opt, const string &path, int pos, const string &user = "root", const string &grp = "root", int perm = 0664 ); - Create a form element in accordance with the parameters of the cell.
13.5. The object which preacts about changing of the structure (TValElem)
| Inherited: | TValue, TConfig. |
Protected methods:
- virtual void detElem( TElem *el ); - Notification by the element <el> of the container about it's wish to detach.
- virtual void addFld( TElem *el, unsigned id ) = 0; - Notification about the addition of the cell <id> of the element <el>.
- virtual void delFld( TElem *el, unsigned id ) = 0; - Notification about the deleting of the cell <id> of the element <el>.
13.6. Data cell (TVariant)
Data:
Error values for the different data types (define):
- EVAL_BOOL - Error value of the boolean type (2);
- EVAL_INT - Error value of the integer type (-2147483647);
- EVAL_REAL - Error value of the real type (-3.3E308);
- EVAL_STR - Error value of the string type ("<EVAL>").
Типы данных (enum - TVariant::Type):
- TVariant::Null - data type and data is not set.
- TVariant::Boolean - boolean type (boolean, 8бит).
- TVariant::Integer - integer type (integer, 32бит).
- TVariant::Real - real type (double).
- TVariant::String - string.
- TVariant::Object - object.
Public methods:
- TVariant( ); - Default constructor.
- TVariant( char ivl ); - Boolean type constructor.
- TVariant( int ivl ); - Integer type constructor.
- TVariant( double ivl ); - Real type constructor.
- TVariant( string ivl ); - String type constructor.
- TVariant( TVarObj *ivl ); - Object constructor.
- TVariant( const TVariant &var ); - Copying constructor.
- bool operator==( TVariant &vr ); - Comparison of the object.
- TVariant &operator=( const TVariant &vr ); - Copy of the object.
- bool isNull( ) const; - Signs that the object is not initiated.
- Type type( ) const; - Value's type.
- void setType( Type tp ); - Type set.
- bool isModify( ); - Modification flag. It serves in the object functions to indicate the modification of variables.
- void setModify( bool vl = true ); - Set of the modification flag.
- char getB( ) const; - Getting the value as the boolean one.
- int getI( ) const; - Getting the value as the integer one.
- double getR( ) const; - Getting the value as the real one.
- string getS( ) const; - Getting the value as the string one.
- TVarObj *getO( ) const; - Getting the object.
- void setB( char val ); - Set to the value the boolean one.
- void setI( int val ); - Set to the value the integer one.
- void setR( double val ); - Set to the value the real one.
- void setS( const string &val ); - Set to the value the string one.
- void setO( TVarObj *val ); - Set the object.
13.7. User object (TVarObj)
Public methods:
- TVarObj( ); - Constructor.
- int connect( ); - Connection to the object.
- int disconnect( ); - Disconnection from the object.
- virtual TVariant propGet( const string &id ); - Request of the object property with an ID <id>.
- virtual void propSet( const string &id, TVariant val ); - Set the object property with an ID <id> to the value <val>.
- virtual string getStrXML( const string &oid = "" ); - Conversion of the contents of the object in the XML flow.
- virtual TVariant funcCall( const string &id, vector<TVariant> &prms ); - Call of the object function with the ID <id> and with the parameters <prms>.