Commit 7701b57a authored by Jonas Nylund's avatar Jonas Nylund

SevHistObject added and storage environment revisited

parent fa384bc6
This diff is collapsed.
...@@ -62,7 +62,10 @@ typedef struct { ...@@ -62,7 +62,10 @@ typedef struct {
class sev_server { class sev_server {
public: public:
sev_server() : m_server_status(0), m_item_key(0), m_msg_id(0) {} //TODO should this really be in this file?
static const unsigned int constSevVersion = 2;
sev_server() : m_server_status(0), m_msg_id(0) {}
typedef map<sev_refid, unsigned int>::iterator iterator_refid; typedef map<sev_refid, unsigned int>::iterator iterator_refid;
...@@ -70,7 +73,6 @@ class sev_server { ...@@ -70,7 +73,6 @@ class sev_server {
pwr_tStatus m_server_status; pwr_tStatus m_server_status;
vector<sev_node> m_nodes; vector<sev_node> m_nodes;
map<sev_refid, unsigned int> m_refid; map<sev_refid, unsigned int> m_refid;
tree_sTable *m_item_key;
unsigned int m_msg_id; unsigned int m_msg_id;
sev_db *m_db; sev_db *m_db;
int m_noneth; int m_noneth;
...@@ -82,9 +84,11 @@ class sev_server { ...@@ -82,9 +84,11 @@ class sev_server {
int check_histitems( sev_sMsgHistItems *msg, unsigned int size); int check_histitems( sev_sMsgHistItems *msg, unsigned int size);
int receive_histdata( sev_sMsgHistDataStore *msg, unsigned int size); int receive_histdata( sev_sMsgHistDataStore *msg, unsigned int size);
int send_histdata( qcom_sQid tgt, sev_sMsgHistDataGetRequest *msg, unsigned int size); int send_histdata( qcom_sQid tgt, sev_sMsgHistDataGetRequest *msg, unsigned int size);
int send_objecthistdata( qcom_sQid tgt, sev_sMsgHistDataGetRequest *rmsg, unsigned int size);
int send_itemlist( qcom_sQid tgt); int send_itemlist( qcom_sQid tgt);
int send_server_status( qcom_sQid tgt); int send_server_status( qcom_sQid tgt);
int delete_item( qcom_sQid tgt, sev_sMsgHistItemDelete *rmsg); int delete_item( qcom_sQid tgt, sev_sMsgHistItemDelete *rmsg);
void garbage_collector(); void garbage_collector();
void garbage_item( int idx);
}; };
#endif #endif
...@@ -202,7 +202,7 @@ void XttTblGtk::activate_list_layout( GtkWidget *w, gpointer data) ...@@ -202,7 +202,7 @@ void XttTblGtk::activate_list_layout( GtkWidget *w, gpointer data)
xtt->tblnav->show_list(); xtt->tblnav->show_list();
} }
XttSevHist *XttTblGtk::sevhist_new( pwr_tOid oid, char *aname) XttSevHist *XttTblGtk::sevhist_new( pwr_tOid oid, char *aname, bool sevhistobject)
{ {
GtkWidget *w; GtkWidget *w;
pwr_tStatus sts; pwr_tStatus sts;
...@@ -214,7 +214,7 @@ XttSevHist *XttTblGtk::sevhist_new( pwr_tOid oid, char *aname) ...@@ -214,7 +214,7 @@ XttSevHist *XttTblGtk::sevhist_new( pwr_tOid oid, char *aname)
strncpy( anamev[0], aname, sizeof(anamev[0])); strncpy( anamev[0], aname, sizeof(anamev[0]));
return new XttSevHistGtk( (void *)this, toplevel, "SevHist", &w, oidv, anamev, return new XttSevHistGtk( (void *)this, toplevel, "SevHist", &w, oidv, anamev,
sevcli, &sts); sevcli, &sts, sevhistobject);
} }
CoLogin *XttTblGtk::login_new( const char *name, CoLogin *XttTblGtk::login_new( const char *name,
......
...@@ -49,7 +49,7 @@ class XttTblGtk : public XttTbl { ...@@ -49,7 +49,7 @@ class XttTblGtk : public XttTbl {
CoWowEntryGtk *cmd_entry; CoWowEntryGtk *cmd_entry;
void message( char severity, char *message); void message( char severity, char *message);
XttSevHist *sevhist_new( pwr_tOid oid, char *aname); XttSevHist *sevhist_new( pwr_tOid oid, char *aname, bool sevhistobject);
CoLogin *login_new( const char *wl_name, CoLogin *login_new( const char *wl_name,
const char *wl_groupname, const char *wl_groupname,
void (* wl_bc_success)( void *), void (* wl_bc_success)( void *),
......
...@@ -120,24 +120,41 @@ void XttTbl::activate_print() ...@@ -120,24 +120,41 @@ void XttTbl::activate_print()
void XttTbl::activate_opensevhist() void XttTbl::activate_opensevhist()
{ {
sevcli_sHistItem *hi; // sevcli_sHistItem *hi;
TblNav_sevhistobject *hi;
if ( !tblnav->get_select( &hi)) { if ( !tblnav->get_select( &hi)) {
message( 'E', "Select an storage item"); message( 'E', "Select an storage item");
return; return;
} }
sevhist_new( hi->oid, hi->attr[0].aname); bool sevhistobject = hi->attrnum > 1;
if( !sevhistobject ) {
sevhist_new( hi->oid, hi->objectattrlist[0].aname, sevhistobject);
}
else {
char *s;
pwr_tAName aname;
s = strchr( hi->oname, '.');
if ( !s) {
//It is a complete object
aname[0] = '\0';
}
else {
strcpy( aname, s+1);
}
sevhist_new( hi->oid, aname, sevhistobject);
}
} }
void XttTbl::delete_item_yes( void *ctx, void *data) void XttTbl::delete_item_yes( void *ctx, void *data)
{ {
XttTbl *tbl = (XttTbl *)ctx; XttTbl *tbl = (XttTbl *)ctx;
sevcli_sHistItem *hi = (sevcli_sHistItem *)data; // sevcli_sHistItem *hi = (sevcli_sHistItem *)data;
TblNav_sevhistobject *hi = (TblNav_sevhistobject *)data;
pwr_tStatus sts; pwr_tStatus sts;
printf("Deleting %s\n", hi->oname); printf("Deleting %s\n", hi->oname);
sevcli_delete_item( &sts, tbl->sevcli, hi->oid, hi->attr[0].aname); sevcli_delete_item( &sts, tbl->sevcli, hi->oid, hi->objectattrlist[0].aname);
if ( EVEN(sts)) { if ( EVEN(sts)) {
tbl->message( 'E', "Delete error"); tbl->message( 'E', "Delete error");
return; return;
...@@ -149,7 +166,8 @@ void XttTbl::delete_item_yes( void *ctx, void *data) ...@@ -149,7 +166,8 @@ void XttTbl::delete_item_yes( void *ctx, void *data)
void XttTbl::activate_delete_item() void XttTbl::activate_delete_item()
{ {
sevcli_sHistItem *hi; //sevcli_sHistItem *hi;
TblNav_sevhistobject *hi;
char msg[300]; char msg[300];
if ( !tblnav->get_select( &hi)) { if ( !tblnav->get_select( &hi)) {
...@@ -157,7 +175,7 @@ void XttTbl::activate_delete_item() ...@@ -157,7 +175,7 @@ void XttTbl::activate_delete_item()
return; return;
} }
sprintf( msg, "Do you really wan't to delete all stored data for item\n\n%s.%s\n", hi->oname, hi->attr[0].aname); sprintf( msg, "Do you really wan't to delete all stored data for item\n\n%s.%s\n", hi->oname, hi->objectattrlist[0].aname);
wow->DisplayQuestion( this, "Confirm Delete Item", msg, delete_item_yes, 0, hi); wow->DisplayQuestion( this, "Confirm Delete Item", msg, delete_item_yes, 0, hi);
} }
......
...@@ -55,7 +55,7 @@ class XttTbl { ...@@ -55,7 +55,7 @@ class XttTbl {
int quiet; int quiet;
virtual void message( char severity, const char *message) {} virtual void message( char severity, const char *message) {}
virtual XttSevHist *sevhist_new( pwr_tOid oid, char *aname) { return 0;} virtual XttSevHist *sevhist_new( pwr_tOid oid, char *aname, bool sevhistobject) { return 0;}
virtual CoLogin *login_new( const char *wl_name, virtual CoLogin *login_new( const char *wl_name,
const char *wl_groupname, const char *wl_groupname,
void (* wl_bc_success)( void *), void (* wl_bc_success)( void *),
......
This diff is collapsed.
...@@ -63,6 +63,30 @@ typedef enum { ...@@ -63,6 +63,30 @@ typedef enum {
tblnav_mOpen_Attributes = 1 << 1 tblnav_mOpen_Attributes = 1 << 1
} tblnav_mOpen; } tblnav_mOpen;
class TblNav_sevhistobjectattr {
public:
pwr_tAName aname;
pwr_eType type;
unsigned int size;
unsigned int elem;
pwr_tString16 unit;
};
class TblNav_sevhistobject {
public:
pwr_tOid oid;
pwr_tAName oname;
pwr_tDeltaTime storagetime;
pwr_tTime creatime;
pwr_tTime modtime;
pwr_tString80 description;
pwr_tFloat32 scantime;
pwr_tFloat32 deadband;
pwr_tMask options;
unsigned int attrnum;
vector<TblNav_sevhistobjectattr> objectattrlist;
};
class TblTreeNode { class TblTreeNode {
public: public:
...@@ -73,7 +97,7 @@ public: ...@@ -73,7 +97,7 @@ public:
int fws; int fws;
int bws; int bws;
char sname[80]; char sname[80];
sevcli_sHistItem *item; TblNav_sevhistobject *item;
int deleted; int deleted;
}; };
...@@ -100,6 +124,7 @@ class TblNavBrow { ...@@ -100,6 +124,7 @@ class TblNavBrow {
}; };
//! The navigation area of the attribute editor. //! The navigation area of the attribute editor.
class TblNav { class TblNav {
public: public:
...@@ -112,6 +137,7 @@ class TblNav { ...@@ -112,6 +137,7 @@ class TblNav {
void *parent_ctx; void *parent_ctx;
TblNavBrow *brow; TblNavBrow *brow;
sevcli_sHistItem *itemlist; sevcli_sHistItem *itemlist;
vector<TblNav_sevhistobject> sevhistobjectlist;
int item_cnt; int item_cnt;
void (*message_cb)( void *, char, const char *); void (*message_cb)( void *, char, const char *);
int (*is_authorized_cb)( void *, unsigned int, int); int (*is_authorized_cb)( void *, unsigned int, int);
...@@ -122,14 +148,16 @@ class TblNav { ...@@ -122,14 +148,16 @@ class TblNav {
int is_authorized( unsigned int access = pwr_mAccess_AllSev, int msg = 1); int is_authorized( unsigned int access = pwr_mAccess_AllSev, int msg = 1);
int create_items(); int create_items();
void build_tree(); void build_tree();
int get_select( sevcli_sHistItem **hi); int get_select( TblNav_sevhistobject **hi);
void get_zoom( double *zoom_factor); void get_zoom( double *zoom_factor);
void zoom( double zoom_factor); void zoom( double zoom_factor);
void unzoom(); void unzoom();
void show_tree(); void show_tree();
void show_list(); void show_list();
void delete_item( sevcli_sHistItem *hi); void delete_item( TblNav_sevhistobject *hi);
void create_objectlist( sevcli_sHistItem *xn_itemlist,
int xn_item_cnt,
pwr_tStatus *status);
virtual void message( char sev, const char *text); virtual void message( char sev, const char *text);
virtual void set_inputfocus() {} virtual void set_inputfocus() {}
static int init_brow_cb( FlowCtx *fctx, void *client_data); static int init_brow_cb( FlowCtx *fctx, void *client_data);
...@@ -146,10 +174,13 @@ class ItemBase { ...@@ -146,10 +174,13 @@ class ItemBase {
//! Item for a normal attribute. //! Item for a normal attribute.
class ItemLocal : public ItemBase { class ItemLocal : public ItemBase {
public: public:
ItemLocal( TblNav *tblnav, sevcli_sHistItem *item, brow_tNode dest, flow_eDest dest_code); // ItemLocal( TblNav *tblnav, sevcli_sHistItem *item, brow_tNode dest, flow_eDest dest_code);
ItemLocal( TblNav *tblnav, TblNav_sevhistobject *item, brow_tNode dest, flow_eDest dest_code);
virtual ~ItemLocal() {} virtual ~ItemLocal() {}
sevcli_sHistItem item; // sevcli_sHistItem item;
TblNav_sevhistobject item;
brow_tNode node; brow_tNode node;
int open_attributes( TblNav *tblnav, double x, double y); int open_attributes( TblNav *tblnav, double x, double y);
...@@ -161,14 +192,15 @@ class ItemLocalAttr : public ItemBase { ...@@ -161,14 +192,15 @@ class ItemLocalAttr : public ItemBase {
ItemLocalAttr( TblNav *tblnav, const char *iname, char *ivalue, brow_tNode dest, flow_eDest dest_code); ItemLocalAttr( TblNav *tblnav, const char *iname, char *ivalue, brow_tNode dest, flow_eDest dest_code);
virtual ~ItemLocalAttr() {} virtual ~ItemLocalAttr() {}
sevcli_sHistItem item; TblNav_sevhistobject item;
//sevcli_sHistItem item;
brow_tNode node; brow_tNode node;
}; };
//! Item for a normal attribute. //! Item for a normal attribute.
class ItemTreeLocal : public ItemLocal { class ItemTreeLocal : public ItemLocal {
public: public:
ItemTreeLocal( TblNav *tblnav, sevcli_sHistItem *item, int index, brow_tNode dest, flow_eDest dest_code); ItemTreeLocal( TblNav *tblnav, TblNav_sevhistobject *item, int index, brow_tNode dest, flow_eDest dest_code);
virtual ~ItemTreeLocal() {} virtual ~ItemTreeLocal() {}
int idx; int idx;
......
...@@ -38,9 +38,9 @@ class sev_attr { ...@@ -38,9 +38,9 @@ class sev_attr {
class sev_item { class sev_item {
public: public:
sev_item() : deadband_active(0), last_id(0), first_storage(1), status(0), logged_status(0), sev_item() : deadband_active(0), last_id(0), value_size(0), old_value(0), first_storage(1), status(0), logged_status(0),
deleted(0) deleted(0)
{ memset( old_value, 0, sizeof(old_value));} { /*memset( old_value, 0, sizeof(old_value));*/}
unsigned int id; unsigned int id;
char tablename[256]; char tablename[256];
pwr_tOid oid; pwr_tOid oid;
...@@ -55,10 +55,12 @@ class sev_item { ...@@ -55,10 +55,12 @@ class sev_item {
pwr_tMask options; pwr_tMask options;
int deadband_active; int deadband_active;
unsigned int last_id; unsigned int last_id;
char old_value[8]; //char old_value[8];
unsigned int value_size;
void *old_value;
int first_storage; int first_storage;
unsigned int attrnum; unsigned int attrnum;
sev_attr attr[1]; vector<sev_attr> attr;
pwr_tStatus status; pwr_tStatus status;
pwr_tStatus logged_status; pwr_tStatus logged_status;
int deleted; int deleted;
...@@ -92,5 +94,31 @@ class sev_db { ...@@ -92,5 +94,31 @@ class sev_db {
virtual int get_items( pwr_tStatus *sts) { return 0;} virtual int get_items( pwr_tStatus *sts) { return 0;}
virtual int delete_old_data( pwr_tStatus *sts, pwr_tOid oid, char *aname, virtual int delete_old_data( pwr_tStatus *sts, pwr_tOid oid, char *aname,
pwr_tMask options, pwr_tTime limit) { return 0;} pwr_tMask options, pwr_tTime limit) { return 0;}
virtual char *oid_to_table( pwr_tOid oid, char *aname) { return 0;}
virtual int check_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime,
char *description, pwr_tFloat32 scantime,
pwr_tFloat32 deadband, pwr_tMask options, unsigned int *idx) { return 0;}
virtual int add_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime,
char *description, pwr_tFloat32 scantime,
pwr_tFloat32 deadband, pwr_tMask options, unsigned int *idx) { return 0;}
virtual int store_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, char *description, pwr_tFloat32 scantime, pwr_tFloat32 deadband, pwr_tMask options) { return 0;}
virtual int add_objectitemattr( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname,
pwr_eType type, unsigned int size, unsigned int *idx) { return 0;}
virtual int get_item( pwr_tStatus *sts, sev_item *item, char *tablename) { return 0;}
virtual int get_objectitem( pwr_tStatus *sts, sev_item *item, char *tablename) { return 0;}
virtual int get_objectitems( pwr_tStatus *sts) { return 0;}
virtual int check_objectitemattr( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname,
pwr_eType type, unsigned int size, unsigned int *idx) { return 0;}
virtual int delete_old_objectdata( pwr_tStatus *sts, char *tablename,
pwr_tMask options, pwr_tTime limit) { return 0;}
virtual int get_objectvalues( pwr_tStatus *sts, sev_item *item,
unsigned int size, pwr_tTime *starttime, pwr_tTime *endtime,
int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize) { return 0;}
}; };
#endif #endif
This diff is collapsed.
...@@ -67,6 +67,8 @@ class sev_dbms_env ...@@ -67,6 +67,8 @@ class sev_dbms_env
int open(const char *host, const char *user, const char *passwd, int open(const char *host, const char *user, const char *passwd,
const char *dbName, unsigned int port, const char *socket); const char *dbName, unsigned int port, const char *socket);
int checkAndUpdateVersion(unsigned int version);
int updateDB_to_SevVersion2(void);
MYSQL *createDb(void); MYSQL *createDb(void);
MYSQL *openDb(void); MYSQL *openDb(void);
bool exists() { return m_exists;} bool exists() { return m_exists;}
...@@ -104,7 +106,7 @@ class sev_dbms : public sev_db { ...@@ -104,7 +106,7 @@ class sev_dbms : public sev_db {
sev_dbms_env *m_env; sev_dbms_env *m_env;
sev_dbms( sev_dbms_env *env) : m_env(env) {} sev_dbms( sev_dbms_env *env) : m_env(env) {}
~sev_dbms() {} ~sev_dbms();
int check_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname, int check_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, pwr_eType type, unsigned int size, pwr_tDeltaTime storagetime, pwr_eType type, unsigned int size,
...@@ -136,7 +138,40 @@ class sev_dbms : public sev_db { ...@@ -136,7 +138,40 @@ class sev_dbms : public sev_db {
char *oid_to_table( pwr_tOid oid, char *aname); char *oid_to_table( pwr_tOid oid, char *aname);
char *pwrtype_to_type( pwr_eType type, unsigned int size); char *pwrtype_to_type( pwr_eType type, unsigned int size);
static int timestr_to_time( char *tstr, pwr_tTime *ts); static int timestr_to_time( char *tstr, pwr_tTime *ts);
int check_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime,
char *description, pwr_tFloat32 scantime,
pwr_tFloat32 deadband, pwr_tMask options, unsigned int *idx);
int add_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime,
char *description, pwr_tFloat32 scantime,
pwr_tFloat32 deadband, pwr_tMask options, unsigned int *idx);
int store_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, char *description, pwr_tFloat32 scantime,
pwr_tFloat32 deadband, pwr_tMask options);
int create_objecttable( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname,
pwr_tMask options, float deadband);
int add_objectitemattr( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname,
pwr_eType type, unsigned int size, unsigned int *idx);
int store_objectvalue( pwr_tStatus *sts, int item_idx, int attr_idx,
pwr_tTime time, void *buf, void *oldbuf, unsigned int size);
int get_item( pwr_tStatus *sts, sev_item *item, char *tablename);
int get_objectitem( pwr_tStatus *sts, sev_item *item, char *tablename);
int get_objectitems( pwr_tStatus *sts);
int get_objectitemattributes( pwr_tStatus *sts, sev_item *item, char *tablename);
int check_objectitemattr( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname,
pwr_eType type, unsigned int size, unsigned int *idx);
int get_nextattridx( pwr_tStatus *sts, char *tablename );
int delete_old_objectdata( pwr_tStatus *sts, char *tablename,
pwr_tMask options, pwr_tTime limit);
int alter_attrcolumn(pwr_tStatus *sts, char *tablename, char *aname, pwr_eType newtype, unsigned int newsize, pwr_eType oldtype, unsigned int oldsize);
int rename_attrcolumn(pwr_tStatus *sts, char *tablename, char *aname, pwr_eType type, unsigned int size);
int remove_objectitemattr( pwr_tStatus *sts, char *tablename, char *aname);
int update_objectitemattr( pwr_tStatus *sts, char *tablename, char *aname, pwr_eType type, unsigned int size);
int check_deadband(pwr_eType type, unsigned int size, pwr_tFloat32 deadband, void *value, void *oldvalue);
int get_objectvalues( pwr_tStatus *sts, sev_item *item, unsigned int size, pwr_tTime *starttime, pwr_tTime *endtime,
int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize);
pwr_tUInt64 get_minFromIntegerColumn( char *tablename, char *colname );
}; };
#endif #endif
#endif #endif
This diff is collapsed.
...@@ -42,6 +42,32 @@ class sev_sevhist { ...@@ -42,6 +42,32 @@ class sev_sevhist {
pwr_tFloat32 scantime; pwr_tFloat32 scantime;
}; };
class sev_sevhistobjectattr {
public:
pwr_tAttrRef aref;
pwr_tString80 description;
pwr_tString16 unit;
pwr_tAName aname;
pwr_tRefId refid;
void *datap;
pwr_eType type;
unsigned int size;
};
class sev_sevhistobject {
public:
pwr_tAttrRef aref;
pwr_tAName aname;
pwr_tDeltaTime storagetime;
pwr_tFloat32 deadband;
pwr_tMask options;
pwr_tRefId sevid;
pwr_tString80 description;
pwr_tFloat32 scantime;
unsigned int datasize;
vector<sev_sevhistobjectattr> sevhistobjectattrlist;
};
class sev_sevhistthread { class sev_sevhistthread {
public: public:
sev_sevhistthread() : configerror(0) {} sev_sevhistthread() : configerror(0) {}
...@@ -54,6 +80,7 @@ class sev_sevhistthread { ...@@ -54,6 +80,7 @@ class sev_sevhistthread {
pwr_tRefId refid; pwr_tRefId refid;
int configerror; int configerror;
vector<sev_sevhist> sevhistlist; vector<sev_sevhist> sevhistlist;
vector<sev_sevhistobject> sevhistobjectlist;
}; };
class sev_node { class sev_node {
...@@ -88,6 +115,16 @@ class rt_sevhistmon { ...@@ -88,6 +115,16 @@ class rt_sevhistmon {
int init(); int init();
int init_objects(); int init_objects();
int init_sevhistobjects();
void insert_sevhistobjectattr(pwr_sAttrRef *aref,
pwr_tAName objectname,
int hs_idx,
vector<sev_sevhistobjectattr> *listP);
int get_sevhistobjectattributes (pwr_tAName objectname,
vector<sev_sevhistobjectattr> *listP,
int hs_idx,
pwr_tBoolean first);
bool correct_histtype(const pwr_eType type);
int close(); int close();
int close_objects(); int close_objects();
int mainloop(); int mainloop();
......
...@@ -42,7 +42,9 @@ typedef enum { ...@@ -42,7 +42,9 @@ typedef enum {
sev_eMsgType_HistItemDelete, sev_eMsgType_HistItemDelete,
sev_eMsgType_HistItemStatus, sev_eMsgType_HistItemStatus,
sev_eMsgType_ServerStatusRequest, sev_eMsgType_ServerStatusRequest,
sev_eMsgType_ServerStatus sev_eMsgType_ServerStatus,
sev_eMsgType_HistObjectDataGetRequest,
sev_eMsgType_HistObjectDataGet
} sev_eMsgType; } sev_eMsgType;
typedef struct { typedef struct {
...@@ -83,7 +85,9 @@ typedef struct { ...@@ -83,7 +85,9 @@ typedef struct {
typedef struct { typedef struct {
sev_eMsgType Type; sev_eMsgType Type;
pwr_tStatus Status; pwr_tStatus Status;
unsigned int NumItems;
unsigned int NumAttributes;
sev_sHistItem Items[1]; sev_sHistItem Items[1];
} sev_sMsgHistItems; } sev_sMsgHistItems;
...@@ -113,6 +117,18 @@ typedef struct { ...@@ -113,6 +117,18 @@ typedef struct {
int Data[1]; int Data[1];
} sev_sMsgHistDataGet; } sev_sMsgHistDataGet;
typedef struct {
sev_eMsgType Type;
pwr_tOid Oid;
pwr_tOName AName;
pwr_tStatus Status;
int NumPoints;
int NumAttributes;
unsigned int TotalDataSize;
sev_sHistAttr Attr[1];
int Data[1];
} sev_sMsgHistObjectDataGet;
typedef struct { typedef struct {
sev_eMsgType Type; sev_eMsgType Type;
pwr_tOid Oid; pwr_tOid Oid;
......
...@@ -115,6 +115,104 @@ int sevcli_get_itemlist( pwr_tStatus *sts, sevcli_tCtx ctx, sevcli_sHistItem **l ...@@ -115,6 +115,104 @@ int sevcli_get_itemlist( pwr_tStatus *sts, sevcli_tCtx ctx, sevcli_sHistItem **l
tgt.qix = sev_eProcSevServer; tgt.qix = sev_eProcSevServer;
put.reply = ctx->qid;
put.type.b = (qcom_eBtype) sev_cMsgClass;
put.type.s = (qcom_eStype) sev_eMsgType_HistItemsRequest;
put.msg_id = ctx->msg_id++;
put.size = sizeof(*msg);
msg = (sev_sMsgAny *) qcom_Alloc( sts, put.size);
put.data = msg;
msg->Type = sev_eMsgType_HistItemsRequest;
if ( !qcom_Put( sts, &tgt, &put)) {
qcom_Free( &lsts, put.data);
return 0;
}
sev_sMsgHistItems *rmsg;
memset( &get, 0, sizeof(get));
for (;;) {
rmsg = (sev_sMsgHistItems *) qcom_Get( sts, &ctx->qid, &get, tmo);
if ( *sts == QCOM__TMO || !rmsg) {
return 0;
}
if ( get.type.b == sev_cMsgClass &&
get.type.s == (qcom_eStype) sev_eMsgType_HistItems)
break;
qcom_Free( sts, rmsg);
}
*sts = rmsg->Status;
if ( EVEN(*sts))
return 0;
//int item_cnt = (get.size - sizeof(sev_sMsgHistItems)) / sizeof(sev_sHistItem) + 1;
int item_cnt = rmsg->NumItems;
int attr_cnt = rmsg->NumAttributes;
unsigned int data_size = (item_cnt * sizeof(sevcli_sHistItem)) + ((attr_cnt - item_cnt) * sizeof(sevcli_sHistAttr));
printf("Get size: %d, data size: %d\n", get.size, data_size);
lp = (sevcli_sHistItem *) malloc( data_size );
sevcli_sHistItem *lp2 = lp;
sev_sHistItem *itemPtr = ((sev_sMsgHistItems *)rmsg)->Items;
for ( i = 0; i < item_cnt; i++) {
printf("i : %d\n", i);
lp->oid = itemPtr->oid;
strncpy( lp->oname, itemPtr->oname, sizeof(lp->oname));
lp->storagetime = net_NetTimeToDeltaTime( &itemPtr->storagetime);
lp->deadband = itemPtr->deadband;
lp->options = itemPtr->options;
lp->creatime = net_NetTimeToTime( &itemPtr->creatime);
lp->modtime = net_NetTimeToTime( &itemPtr->modtime);
strncpy( lp->description, itemPtr->description, sizeof(lp->description));
lp->scantime = itemPtr->scantime;
lp->attrnum = itemPtr->attrnum;
size_t j=0;
for( j=0; j < lp->attrnum; j++ ) {
lp->attr[j].type = itemPtr->attr[j].type;
lp->attr[j].size = itemPtr->attr[j].size;
strncpy( lp->attr[j].aname, itemPtr->attr[j].aname, sizeof(lp->attr[0].aname));
strncpy( lp->attr[j].unit, itemPtr->attr[j].unit, sizeof(lp->attr[0].unit));
}
itemPtr = (sev_sHistItem *)&itemPtr->attr[j];
lp = (sevcli_sHistItem *)&lp->attr[j];
}
qcom_Free( sts, rmsg);
*cnt = item_cnt;
*list = lp2;
*sts = SEV__SUCCESS;
return 1;
}
/*
int sevcli_get_itemlist( pwr_tStatus *sts, sevcli_tCtx ctx, sevcli_sHistItem **list,
unsigned int *cnt)
{
sev_sMsgAny *msg;
qcom_sQid tgt;
qcom_sPut put;
pwr_tStatus lsts;
int tmo = 1000;
qcom_sGet get;
sevcli_sHistItem *lp;
int i;
if ( ctx->server)
tgt.nid = ctx->server;
else
tgt.nid = ctx->qid.nid;
tgt.qix = sev_eProcSevServer;
put.reply = ctx->qid; put.reply = ctx->qid;
put.type.b = (qcom_eBtype) sev_cMsgClass; put.type.b = (qcom_eBtype) sev_cMsgClass;
put.type.s = (qcom_eStype) sev_eMsgType_HistItemsRequest; put.type.s = (qcom_eStype) sev_eMsgType_HistItemsRequest;
...@@ -180,6 +278,7 @@ int sevcli_get_itemlist( pwr_tStatus *sts, sevcli_tCtx ctx, sevcli_sHistItem **l ...@@ -180,6 +278,7 @@ int sevcli_get_itemlist( pwr_tStatus *sts, sevcli_tCtx ctx, sevcli_sHistItem **l
*sts = SEV__SUCCESS; *sts = SEV__SUCCESS;
return 1; return 1;
} }
*/
int sevcli_get_itemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid, int sevcli_get_itemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid,
char *aname, pwr_tTime starttime, pwr_tTime endtime, int numpoints, char *aname, pwr_tTime starttime, pwr_tTime endtime, int numpoints,
...@@ -220,6 +319,7 @@ int sevcli_get_itemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid, ...@@ -220,6 +319,7 @@ int sevcli_get_itemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid,
// Empty queue // Empty queue
sev_sMsgHistDataGet *rmsg; sev_sMsgHistDataGet *rmsg;
memset( &get, 0, sizeof(get));
for (;;) { for (;;) {
rmsg = (sev_sMsgHistDataGet *) qcom_Get(sts, &ctx->qid, &get, 0); rmsg = (sev_sMsgHistDataGet *) qcom_Get(sts, &ctx->qid, &get, 0);
if ( !rmsg) if ( !rmsg)
...@@ -268,6 +368,116 @@ int sevcli_get_itemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid, ...@@ -268,6 +368,116 @@ int sevcli_get_itemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid,
return 1; return 1;
} }
int sevcli_get_objectitemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid, char *aname,
pwr_tTime starttime, pwr_tTime endtime, int numpoints,
pwr_tTime **tbuf, void **vbuf, int *rows,
sevcli_sHistAttr **histattr, int *numattributes)
{
sev_sMsgHistDataGetRequest *msg;
qcom_sQid tgt;
qcom_sPut put;
int tmo = 30000;
qcom_sGet get;
pwr_tStatus lsts;
if ( ctx->server)
tgt.nid = ctx->server;
else
tgt.nid = ctx->qid.nid;
tgt.qix = sev_eProcSevServer;
put.reply = ctx->qid;
put.type.b = (qcom_eBtype) sev_cMsgClass;
put.type.s = (qcom_eStype) sev_eMsgType_HistObjectDataGetRequest;
put.msg_id = ctx->msg_id++;
put.size = sizeof(*msg);
msg = (sev_sMsgHistDataGetRequest *) qcom_Alloc( sts, put.size);
put.data = msg;
msg->Type = sev_eMsgType_HistObjectDataGetRequest;
msg->Oid = oid;
strncpy( msg->AName, aname, sizeof(msg->AName));
msg->StartTime = net_TimeToNetTime( &starttime);
msg->EndTime = net_TimeToNetTime( &endtime);
msg->NumPoints = numpoints;
// Empty queue
sev_sMsgHistObjectDataGet *rmsg;
memset(&get, 0, sizeof(get));
for (;;) {
rmsg = (sev_sMsgHistObjectDataGet *) qcom_Get(sts, &ctx->qid, &get, 0);
if ( !rmsg)
break;
}
if ( !qcom_Put( sts, &tgt, &put)) {
qcom_Free( &lsts, put.data);
*sts = 0;
return 0;
}
memset( &get, 0, sizeof(get));
for (;;) {
rmsg = (sev_sMsgHistObjectDataGet *) qcom_Get(sts, &ctx->qid, &get, tmo);
if ( *sts == QCOM__TMO || !rmsg) {
*sts = 0;
return 0;
}
if ( get.type.b == sev_cMsgClass &&
get.type.s == (qcom_eStype) sev_eMsgType_HistObjectDataGet &&
cdh_ObjidIsEqual( oid, rmsg->Oid) &&
cdh_NoCaseStrcmp( aname, rmsg->AName) == 0)
break;
qcom_Free( sts, rmsg);
}
*sts = rmsg->Status;
if ( EVEN(*sts))
return 0;
if( rmsg->NumPoints == 0 ) {
*sts = 0;
return 0;
}
*numattributes = rmsg->NumAttributes;
int item_cnt = rmsg->NumPoints;
unsigned int timebufsize = item_cnt * sizeof(pwr_tTime);
unsigned int databufsize = rmsg->TotalDataSize - timebufsize;
*tbuf = malloc( timebufsize);
*vbuf = malloc( databufsize );
sevcli_sHistAttr *attrptr;
attrptr = calloc( rmsg->NumAttributes, sizeof(sevcli_sHistAttr) );
int attrCount = rmsg->NumAttributes;
void *ptr = &rmsg->Attr[attrCount];
memcpy( *tbuf, ptr, item_cnt * sizeof(pwr_tTime));
memcpy( *vbuf, (char *)ptr + item_cnt * sizeof(pwr_tTime), databufsize );
*rows = item_cnt;
int i = 0;
for( i = 0; i < rmsg->NumAttributes; i++ ) {
strncpy(attrptr[i].aname, rmsg->Attr[i].aname, sizeof(attrptr[0].aname));
attrptr[i].type = rmsg->Attr[i].type;
attrptr[i].size = rmsg->Attr[i].size;
}
*histattr = attrptr;
qcom_Free( sts, rmsg);
*sts = SEV__SUCCESS;
return 1;
}
int sevcli_delete_item( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid, char *aname) int sevcli_delete_item( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid, char *aname)
{ {
sev_sMsgHistItemDelete *msg; sev_sMsgHistItemDelete *msg;
......
...@@ -76,7 +76,10 @@ int sevcli_get_itemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid, ...@@ -76,7 +76,10 @@ int sevcli_get_itemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid,
pwr_tTime **tbuf, void **vbuf, int *rows, pwr_tTime **tbuf, void **vbuf, int *rows,
pwr_eType *vtype, unsigned int *vsize); pwr_eType *vtype, unsigned int *vsize);
int sevcli_delete_item( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid, char *aname); int sevcli_delete_item( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid, char *aname);
int sevcli_get_objectitemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid, char *aname,
pwr_tTime starttime, pwr_tTime endtime, int numpoints,
pwr_tTime **tbuf, void **vbuf, int *rows,
sevcli_sHistAttr **histattr, int *numattributes);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -42,6 +42,7 @@ SObject pwrb:Class ...@@ -42,6 +42,7 @@ SObject pwrb:Class
! below the current signal object. ! below the current signal object.
! !
! @b See also ! @b See also
! @classlink SevHistObject pwrb_sevhistobject.html
! @classlink SevHistThread pwrb_sevhistthread.html ! @classlink SevHistThread pwrb_sevhistthread.html
! @classlink SevHistMonitor pwrb_sevhistmonitor.html ! @classlink SevHistMonitor pwrb_sevhistmonitor.html
! @classlink SevHistServer pwrb_sevhistserver.html ! @classlink SevHistServer pwrb_sevhistserver.html
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment