Commit 563fa014 authored by claes's avatar claes

Storage server fist version

parent 4fa16fab
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
ifndef link_rule_mk
link_rule_mk := 1
link = $(ldxx) $(elinkflags) $(domap) -o $(export_exe) \
$(export_obj) $(objects) $(wb_msg_eobjs) $(rt_msg_eobjs) \
$(pwr_eobj)/rt_io_user.o \
-lpwr_sev -lpwr_rt -lpwr_co $(linkmysql)\
-lpwr_msg_dummy \
-lrpcsvc -lpthread -lm -lrt -ldb_cxx -lz -lcrypt
#-lpwr_wb -lpwr_rt -lpwr_ge -lpwr_flow -lpwr_glow -lpwr_co \
# -L/usr/X11R6/lib -L/usr/local/BerkeleyDB.4.0/lib \
# -L/opt/gnome/lib \
# -lantlr -lImlib -lMrm -lXm -lXpm -lXt -lX11 -lXext -lXp\
# -lXmu -lSM -lICE\
endif
/*
* Proview $Id: sev_server.cpp,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include "pwr.h"
#include "co_dcli.h"
#include "co_time.h"
#include "co_error.h"
#include "rt_qcom.h"
#include "rt_qcom_msg.h"
#include "sev_server.h"
#include "rt_sev_net.h"
#include "sev_dbms.h"
#include "rt_sev_msg.h"
#define sev_cGarbageInterval 120
int sev_server::init()
{
qcom_sNode node;
pwr_tNid nid;
pwr_tStatus sts;
qcom_sAid aid;
m_db->get_items( &m_sts);
for ( unsigned int i = 0; i < m_db->m_items.size(); i++) {
sev_item_key items_key( m_db->m_items[i].oid, m_db->m_items[i].aname);
m_item_key[items_key] = i;
}
qcom_Init( &m_sts, &aid, "sev_server");
if ( EVEN(m_sts)) throw co_error(m_sts);
// Create a queue to server
qcom_sQattr attr;
qcom_sQid qid;
qid.qix = sev_eProcSevServer;
qid.nid = 0;
attr.type = qcom_eQtype_private;
attr.quota = 100;
if (!qcom_CreateQ(&sts, &qid, &attr, "SevServer")) {
if ( sts == QCOM__QALLREXIST) {
if ( !qcom_AttachQ(&sts, &qid)) {
if ( !qcom_DeleteQ(&sts, &qid))
co_error(sts);
if ( !qcom_CreateQ(&sts, &qid, &attr, "SevServer"))
co_error(sts);
}
}
else
throw co_error( sts);
}
// Get all qcom nodes
qcom_MyNode( &m_sts, &node);
if ( EVEN(m_sts)) throw co_error(m_sts);
sev_node myn;
myn.nid = node.nid;
strncpy( myn.name, node.name, sizeof(myn.name));
m_nodes.push_back( myn);
for (nid = qcom_cNNid; qcom_NextNode(&sts, &node, nid); nid = node.nid) {
sev_node n;
n.nid = node.nid;
strncpy( n.name, node.name, sizeof(n.name));
m_nodes.push_back( n);
}
return 1;
}
int sev_server::connect()
{
sev_sMsgAny *msg;
qcom_sQid tgt;
qcom_sPut put;
pwr_tStatus sts, lsts;
for ( unsigned int i = 0; i < m_nodes.size(); i++) {
tgt.nid = m_nodes[i].nid;
tgt.qix = sev_eProcSevClient;
put.reply.nid = m_nodes[0].nid;
put.reply.qix = sev_eProcSevServer;
put.type.b = (qcom_eBtype) sev_cMsgClass;
put.type.s = (qcom_eStype) sev_eMsgType_NodeUp;
put.msg_id = m_msg_id++;
put.size = sizeof(sev_sMsgAny);
msg = (sev_sMsgAny *) qcom_Alloc(&lsts, put.size);
msg->Type = sev_eMsgType_NodeUp;
put.data = msg;
if ( !qcom_Put( &sts, &tgt, &put)) {
qcom_Free( &sts, put.data);
}
}
return 1;
}
int sev_server::request_items( pwr_tNid nid)
{
sev_sMsgAny *msg;
qcom_sQid tgt;
qcom_sPut put;
pwr_tStatus sts, lsts;
tgt.nid = nid;
tgt.qix = sev_eProcSevClient;
put.reply.nid = m_nodes[0].nid;
put.reply.qix = sev_eProcSevServer;
put.type.b = (qcom_eBtype) sev_cMsgClass;
put.type.s = (qcom_eStype) sev_eMsgType_HistItemsRequest;
put.msg_id = m_msg_id++;
put.size = sizeof(*msg);
msg = (sev_sMsgAny *) qcom_Alloc(&lsts, put.size);
msg->Type = sev_eMsgType_HistItemsRequest;
put.data = msg;
if ( !qcom_Put( &sts, &tgt, &put)) {
qcom_Free( &sts, put.data);
}
return 1;
}
int sev_server::send_itemlist( qcom_sQid tgt)
{
int item_cnt = 0;
qcom_sPut put;
pwr_tStatus sts, lsts;
int size;
item_cnt = m_db->m_items.size();
if ( !item_cnt)
return 1;
size = sizeof(sev_sMsgHistItems) + (item_cnt - 1) * sizeof(sev_sHistItem);
put.size = size;
put.data = qcom_Alloc(&lsts, put.size);
((sev_sMsgHistItems *)put.data)->Type = sev_eMsgType_HistItems;
for ( unsigned int i = 0; i < m_db->m_items.size(); i++) {
((sev_sMsgHistItems *)put.data)->Items[i].oid = m_db->m_items[i].oid;
strcpy( ((sev_sMsgHistItems *)put.data)->Items[i].oname, m_db->m_items[i].oname);
strcpy( ((sev_sMsgHistItems *)put.data)->Items[i].aname, m_db->m_items[i].aname);
((sev_sMsgHistItems *)put.data)->Items[i].storagetime = m_db->m_items[i].storagetime;
((sev_sMsgHistItems *)put.data)->Items[i].type = m_db->m_items[i].vtype;
((sev_sMsgHistItems *)put.data)->Items[i].size = m_db->m_items[i].vsize;
strcpy( ((sev_sMsgHistItems *)put.data)->Items[i].description, m_db->m_items[i].description);
strcpy( ((sev_sMsgHistItems *)put.data)->Items[i].unit, m_db->m_items[i].unit);
((sev_sMsgHistItems *)put.data)->Items[i].scantime = m_db->m_items[i].scantime;
}
if ( m_db->m_items.size() == 0)
((sev_sMsgHistItems *)put.data)->Status = SEV__NOITEMS;
else
((sev_sMsgHistItems *)put.data)->Status = SEV__SUCCESS;
put.reply.nid = m_nodes[0].nid;
put.reply.qix = sev_eProcSevServer;
put.type.b = (qcom_eBtype) sev_cMsgClass;
put.type.s = (qcom_eStype) sev_eMsgType_HistItems;
put.msg_id = m_msg_id++;
if ( !qcom_Put( &sts, &tgt, &put)) {
qcom_Free( &sts, put.data);
return 0;
}
return 1;
}
int sev_server::mainloop()
{
qcom_sQid qid;
int tmo = 1000;
qcom_sGet get;
void *mp;
pwr_tStatus sts;
pwr_tTime next_garco, currenttime;
pwr_tDeltaTime garco_interval;
qid.nid = 0;
qid.qix = sev_eProcSevServer;
time_FloatToD( &garco_interval, sev_cGarbageInterval);
clock_gettime( CLOCK_REALTIME, &currenttime);
time_Aadd( &next_garco, &currenttime, &garco_interval);
for (;;) {
memset( &get, 0, sizeof(get));
mp = qcom_Get(&sts, &qid, &get, tmo);
clock_gettime( CLOCK_REALTIME, &currenttime);
if ( time_Acomp( &currenttime, &next_garco) == 1) {
printf( "Run garbage collector\n");
garbage_collector();
time_Aadd( &next_garco, &next_garco, &garco_interval);
}
if ( sts == QCOM__TMO || !mp)
continue;
switch (get.type.b) {
case sev_cMsgClass:
printf( "Message received\n");
switch ( get.type.s) {
case sev_eMsgType_NodeUp:
request_items( get.reply.nid);
break;
case sev_eMsgType_HistItems:
check_histitems( (sev_sMsgHistItems *) mp, get.size);
break;
case sev_eMsgType_HistDataStore:
receive_histdata( (sev_sMsgHistDataStore *) mp, get.size);
break;
case sev_eMsgType_HistDataGetRequest:
send_histdata( get.reply, (sev_sMsgHistDataGetRequest *) mp, get.size);
break;
case sev_eMsgType_HistItemsRequest:
send_itemlist( get.reply);
break;
default: ;
}
break;
default: ;
}
qcom_Free( &sts, mp);
}
}
int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size)
{
unsigned int idx;
int item_cnt = (size - sizeof(sev_sMsgHistItems)) / sizeof(sev_sHistItem) + 1;
if ( item_cnt <= 0)
return 0;
// Remove all refid's for this node
pwr_tNid nid = msg->Items[0].sevid.nid;
for ( iterator_refid it = m_refid.begin(); it != m_refid.end(); it++) {
if ( it->first.id.nid == nid)
m_refid.erase( it);
}
for ( int i = 0; i < item_cnt; i++) {
printf( "Received: %s.%s\n", msg->Items[i].oname, msg->Items[i].aname);
if ( !m_db->check_item( &m_sts, msg->Items[i].oid, msg->Items[i].oname, msg->Items[i].aname,
msg->Items[i].storagetime, msg->Items[i].type, msg->Items[i].size,
msg->Items[i].description, msg->Items[i].unit, msg->Items[i].scantime,
&idx)) {
m_db->add_item( &m_sts, msg->Items[i].oid, msg->Items[i].oname, msg->Items[i].aname,
msg->Items[i].storagetime, msg->Items[i].type, msg->Items[i].size,
msg->Items[i].description, msg->Items[i].unit, msg->Items[i].scantime, &idx);
sev_item_key item_key( msg->Items[i].oid, msg->Items[i].aname);
m_item_key[item_key] = idx;
}
m_db->m_items[idx].sevid = msg->Items[i].sevid;
sev_refid sevid(msg->Items[i].sevid);
m_refid[sevid] = idx;
}
printf( "---- Node up ----\n");
for ( iterator_refid it = m_refid.begin(); it != m_refid.end(); it++) {
printf( "Refid: %d,%d Name %s\n", it->first.id.nid, it->first.id.rix, m_db->m_items[it->second].oname);
}
return 1;
}
int sev_server::receive_histdata( sev_sMsgHistDataStore *msg, unsigned int size)
{
sev_sHistData *dp = (sev_sHistData *)&msg->Data;
while ( (char *)dp - (char *)msg < (int)size) {
sev_refid sevid(dp->sevid);
iterator_refid it = m_refid.find( sevid);
if ( it == m_refid.end()) {
dp = (sev_sHistData *)((char *)dp + sizeof( *dp) - sizeof(dp->data) + dp->size);
continue;
}
unsigned int idx = it->second;
m_db->store_value( &m_sts, m_db->m_items[idx].oid, m_db->m_items[idx].aname,
m_db->m_items[idx].vtype, msg->Time, &dp->data, dp->size);
dp = (sev_sHistData *)((char *)dp + sizeof( *dp) - sizeof(dp->data) + dp->size);
}
return 1;
}
int sev_server::send_histdata( qcom_sQid tgt, sev_sMsgHistDataGetRequest *rmsg, unsigned int size)
{
pwr_tTime *tbuf;
void *vbuf;
unsigned int rows;
sev_sMsgHistDataGet *msg;
int msize;
qcom_sPut put;
pwr_tStatus sts, lsts;
sev_item_key item_key( rmsg->Oid, rmsg->AName);
iterator_item_key it = m_item_key.find( item_key);
if ( it == m_item_key.end())
m_sts = SEV__NOSUCHITEM;
else
m_sts = SEV__SUCCESS;
int idx = 0;
if ( ODD(m_sts)) {
idx = it->second;
m_db->get_values( &m_sts, rmsg->Oid, rmsg->AName, m_db->m_items[idx].vtype,
m_db->m_items[idx].vsize, m_db->m_items[idx].scantime,
&rmsg->StartTime, &rmsg->EndTime, rmsg->NumPoints, &tbuf, &vbuf, &rows);
}
if ( ODD(m_sts))
msize = rows * ( sizeof(pwr_tTime) + m_db->m_items[idx].vsize) + sizeof(*msg) - sizeof(msg->Data);
else
msize = sizeof(*msg);
put.reply.nid = m_nodes[0].nid;
put.reply.qix = sev_eProcSevServer;
put.type.b = (qcom_eBtype) sev_cMsgClass;
put.type.s = (qcom_eStype) sev_eMsgType_HistDataGet;
put.msg_id = m_msg_id++;
put.size = msize;
msg = (sev_sMsgHistDataGet *) qcom_Alloc(&lsts, put.size);
put.data = msg;
msg->Type = sev_eMsgType_HistDataGet;
msg->Oid = rmsg->Oid;
strncpy( msg->AName, rmsg->AName, sizeof(msg->AName));
if ( ODD(m_sts)) {
msg->NumPoints = rows;
msg->VType = m_db->m_items[idx].vtype;
msg->VSize = m_db->m_items[idx].vsize;
}
msg->Status = m_sts;
if ( ODD(m_sts) && rows) {
memcpy( &msg->Data, tbuf, sizeof(pwr_tTime) * rows);
memcpy( (char *)&msg->Data + sizeof(pwr_tTime) * rows, vbuf, m_db->m_items[idx].vsize * rows);
}
if ( !qcom_Put( &sts, &tgt, &put)) {
qcom_Free( &sts, put.data);
}
return 1;
}
void sev_server::garbage_collector()
{
pwr_tTime currenttime, limit;
clock_gettime( CLOCK_REALTIME, &currenttime);
for ( unsigned int i = 0; i < m_db->m_items.size(); i++) {
if ( m_db->m_items[i].storagetime.tv_sec == 0)
continue;
time_Asub( &limit, &currenttime, &m_db->m_items[i].storagetime);
m_db->delete_old_data( &m_sts, m_db->m_items[i].oid, m_db->m_items[i].aname, limit);
}
}
int main()
{
sev_server srv;
sev_dbms_env *env;
pwr_tFileName envname;
sprintf( envname, "$pwrp_db/%s.db", sev_dbms_env::dbName());
dcli_translate_filename( envname, envname);
env = new sev_dbms_env( envname);
env->open( envname);
if ( !env->exists()) {
env->create( envname, "aristotle", "pwrp", "", sev_dbms_env::dbName(), 50,
"/var/run/mysqld/mysqld.sock");
env->open( envname);
env->createDb();
}
else
env->openDb();
srv.m_db = new sev_dbms( env);
srv.init();
srv.connect();
srv.mainloop();
}
/*
* Proview $Id: sev_server.h,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef sev_server_h
#define sev_server_h
#include <vector.h>
#include <map.h>
#include "pwr.h"
#include "pwr_class.h"
#include "rt_sev_net.h"
#include "sev_db.h"
class sev_node {
public:
pwr_tNodeId nid;
char name[80];
};
class sev_refid {
public:
sev_refid( pwr_tRefId rid) : id(rid) {}
bool operator<(const sev_refid& x) const {
if ( id.nid < x.id.nid)
return true;
if ( id.rix < x.id.rix)
return true;
return false;
}
pwr_tRefId id;
};
class sev_item_key {
public:
sev_item_key( pwr_tOid oid, char *aname) : m_oid(oid)
{
strncpy( m_aname, aname, sizeof(m_aname));
}
bool operator<(const sev_item_key& x) const {
if ( m_oid.vid < x.m_oid.vid)
return true;
if ( m_oid.oix < x.m_oid.oix)
return true;
return strcmp( m_aname, x.m_aname);
}
pwr_tOid m_oid;
pwr_tAName m_aname;
};
class sev_server {
public:
sev_server() : m_msg_id(0) {}
typedef map<sev_refid, unsigned int>::iterator iterator_refid;
typedef map<sev_item_key, unsigned int>::iterator iterator_item_key;
pwr_tStatus m_sts;
vector<sev_node> m_nodes;
map<sev_refid, unsigned int> m_refid;
map<sev_item_key, unsigned int> m_item_key;
unsigned int m_msg_id;
sev_db *m_db;
int init();
int connect();
int request_items( pwr_tNid nid);
int sev_server::mainloop();
int check_histitems( sev_sMsgHistItems *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_itemlist( qcom_sQid tgt);
void garbage_collector();
};
#endif
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
ifndef link_rule_mk
link_rule_mk := 1
link = $(ldxx) $(elinkflags) $(domap) -o $(pwr_exe)/sev_xtt_gtk \
$(bld_dir)/sev_xtt_gtk.o \
$(bld_dir)/xtt_tbl_gtk.o $(bld_dir)/xtt_tblnav_gtk.o $(bld_dir)/xtt_tbl.o \
$(bld_dir)/xtt_tblnav.o \
$(rt_msg_eobjs) \
$(pwr_eobj)/rt_io_user.o -L/usr/X11R6/lib\
-L/opt/gnome/lib \
-lpwr_xtt_gtk -lpwr_xtt -lpwr_xtt_gtk -lpwr_xtt -lpwr_ge_gtk -lpwr_ge -lpwr_rt_gtk -lpwr_rt \
-lpwr_co_gtk -lpwr_co -lpwr_flow_gtk -lpwr_flow -lpwr_glow_gtk -lpwr_glow \
`pkg-config --libs gtk+-2.0` \
-lpwr_msg_dummy \
-ldb -lrpcsvc -lpthread -lm -lrt -lcrypt -lasound
endif
/*
* Proview $Id: sev_xtt_gtk.cpp,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gtk/gtk.h>
#include "pwr.h"
#include "pwr_class.h"
#include "xtt_tbl_gtk.h"
#include "co_error.h"
#include "rt_qcom.h"
#include "rt_errh.h"
#include "rt_sevcli.h"
int main( int argc, char *argv[])
{
pwr_tStatus sts;
qcom_sAid aid;
sevcli_tCtx sevcli;
sevcli_sHistItem *items;
unsigned int itemcnt;
char servername[40] = "";
// Get options
for ( int i = 1; i < argc; i++) {
if ( strcmp( argv[i], "-s") == 0 && i + 1 < argc) {
strncpy( servername, argv[i+1], sizeof(servername));
i++;
}
}
sts = qcom_Init( &sts, &aid, "sev_xtt");
if ( EVEN(sts)) co_error(sts);
sevcli_init( &sts, &sevcli);
if ( EVEN(sts)) co_error(sts);
if ( strcmp(servername, "") != 0)
sevcli_set_servernode( &sts, sevcli, servername);
sevcli_get_itemlist( &sts, sevcli, &items, &itemcnt);
if ( EVEN(sts)) co_error(sts);
gtk_init( &argc, &argv);
new XttTblGtk( 0, 0, sevcli, items, itemcnt);
gtk_main();
return 1;
}
/*
* Proview $Id: xtt_tbl_gtk.cpp,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
/* xtt_tbl.cpp -- Sev Table Viewer */
#include "glow_std.h"
#include "co_cdh.h"
#include "co_time.h"
#include "co_wow_gtk.h"
#include "flow.h"
#include "flow_browctx.h"
#include "flow_browapi.h"
#include "flow_browwidget_gtk.h"
#include "glow.h"
#include "glow_curvectx.h"
#include "flow_msg.h"
#include "xtt_tbl_gtk.h"
#include "xtt_tblnav_gtk.h"
#include "xtt_dshist_gtk.h"
void XttTblGtk::message( char severity, char *message)
{
gtk_label_set_text( GTK_LABEL(msg_label), message);
}
static gint delete_event( GtkWidget *w, GdkEvent *event, gpointer data)
{
XttTblGtk *xtttbl = (XttTblGtk *)data;
delete xtttbl;
return FALSE;
}
static void destroy_event( GtkWidget *w, gpointer data)
{
// XttTblGtk *xtttbl = (XttTblGtk *)data;
// delete xtttbl;
}
static gboolean xtttbl_focus_in_event( GtkWidget *w, GdkEvent *event, gpointer data)
{
XttTblGtk *xtttbl = (XttTblGtk *)data;
if ( xtttbl->tblnav)
xtttbl->tblnav->set_inputfocus();
return FALSE;
}
static void xtttbl_activate_close( GtkWidget *w, gpointer data)
{
XttTbl *xtttbl = (XttTbl *)data;
delete xtttbl;
}
static void xtttbl_activate_help( GtkWidget *w, gpointer data)
{
}
static void xtttbl_activate_opendshist( GtkWidget *w, gpointer data)
{
((XttTbl *)data)->activate_opendshist();
}
XttDsHist *XttTblGtk::dshist_new( pwr_tOid oid, char *aname)
{
GtkWidget *w;
pwr_tStatus sts;
pwr_tOid oidv[2];
pwr_tOName anamev[2];
oidv[0] = oid;
oidv[1] = pwr_cNOid;
strncpy( anamev[0], aname, sizeof(anamev[0]));
return new XttDsHistGtk( (void *)this, toplevel, "DsHist", &w, oidv, anamev,
sevcli, &sts);
}
XttTblGtk::XttTblGtk( GtkWidget *a_parent_wid,
void *a_parent_ctx,
sevcli_tCtx a_sevcli,
sevcli_sHistItem *itemlist,
int item_cnt) :
XttTbl( a_parent_ctx, a_sevcli),
parent_wid(a_parent_wid)
{
int sts;
toplevel = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW,
"default-height", 700,
"default-width", 500,
"title", "Object Attributes",
NULL);
g_signal_connect( toplevel, "delete_event", G_CALLBACK(delete_event), this);
g_signal_connect( toplevel, "destroy", G_CALLBACK(destroy_event), this);
g_signal_connect( toplevel, "focus-in-event", G_CALLBACK(xtttbl_focus_in_event), this);
CoWowGtk::SetWindowIcon( toplevel);
GtkWidget *vbox = gtk_vbox_new( FALSE, 0);
// Menu
// Accelerators
GtkAccelGroup *accel_g = (GtkAccelGroup *) g_object_new(GTK_TYPE_ACCEL_GROUP, NULL);
gtk_window_add_accel_group(GTK_WINDOW(toplevel), accel_g);
GtkMenuBar *menu_bar = (GtkMenuBar *) g_object_new(GTK_TYPE_MENU_BAR, NULL);
// File entry
GtkWidget *file_close = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, accel_g);
g_signal_connect(file_close, "activate", G_CALLBACK(xtttbl_activate_close), this);
GtkMenu *file_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_close);
GtkWidget *file = gtk_menu_item_new_with_mnemonic("_File");
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), file);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), GTK_WIDGET(file_menu));
// Functions entry
GtkWidget *functions_opendshist = gtk_menu_item_new_with_mnemonic( "_Open DsHist");
g_signal_connect(functions_opendshist, "activate", G_CALLBACK(xtttbl_activate_opendshist), this);
GtkMenu *functions_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_opendshist);
GtkWidget *functions = gtk_menu_item_new_with_mnemonic("_Functions");
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), functions);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(functions), GTK_WIDGET(functions_menu));
// Help entry
GtkWidget *help_help = gtk_image_menu_item_new_from_stock(GTK_STOCK_HELP, accel_g);
g_signal_connect(help_help, "activate", G_CALLBACK(xtttbl_activate_help), this);
GtkMenu *help_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_help);
GtkWidget *help = gtk_menu_item_new_with_mnemonic("_Help");
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), help);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), GTK_WIDGET(help_menu));
pane = gtk_vpaned_new();
tblnav = new TblNavGtk( this, pane,
itemlist, item_cnt, &brow_widget, &sts);
tblnav->message_cb = &XttTbl::message;
GtkWidget *statusbar = gtk_hbox_new( FALSE, 0);
// msg_label = gtk_statusbar_new();
msg_label = gtk_label_new( "");
gtk_widget_set_size_request( msg_label, -1, 25);
gtk_box_pack_start( GTK_BOX(statusbar), msg_label, FALSE, FALSE, 0);
gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(menu_bar), FALSE, FALSE, 0);
gtk_box_pack_end( GTK_BOX(vbox), GTK_WIDGET(pane), TRUE, TRUE, 0);
gtk_paned_pack1( GTK_PANED(pane), GTK_WIDGET(brow_widget), TRUE, TRUE);
gtk_paned_pack2( GTK_PANED(pane), GTK_WIDGET(statusbar), FALSE, TRUE);
gtk_container_add( GTK_CONTAINER(toplevel), vbox);
gtk_widget_show_all( toplevel);
int w, h;
gdk_drawable_get_size( pane->window, &w, &h);
gtk_paned_set_position( GTK_PANED(pane), h - 50);
}
XttTblGtk::~XttTblGtk()
{
delete (TblNavGtk *)tblnav;
gtk_widget_destroy( toplevel);
}
/*
* Proview $Id: xtt_tbl_gtk.h,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef xtt_tbl_gtk_h
#define xtt_tbl_gtk_h
#include "../src/xtt_tbl.h"
#include "xtt_tblnav_gtk.h"
#include "co_wow_gtk.h"
/* ge_tbl.h -- Ge tblibute editor */
class XttTblGtk : public XttTbl {
public:
XttTblGtk(
GtkWidget *a_parent_wid,
void *a_parent_ctx,
sevcli_tCtx a_sevcli,
sevcli_sHistItem *itemlist,
int item_cnt);
GtkWidget *parent_wid;
GtkWidget *brow_widget;
GtkWidget *form_widget;
GtkWidget *toplevel;
GtkWidget *msg_label;
GtkWidget *pane;
void message( char severity, char *message);
XttDsHist *dshist_new( pwr_tOid oid, char *aname);
~XttTblGtk();
};
#endif
/*
* Proview $Id: xtt_tblnav_gtk.cpp,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
/* sev_tblnav.cpp -- Sev Table Viewer */
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector.h>
#include "co_cdh.h"
#include "co_time.h"
#include "flow.h"
#include "flow_browctx.h"
#include "flow_browapi.h"
#include "flow_browwidget_gtk.h"
#include "flow_msg.h"
#include "glow.h"
#include "glow_growctx.h"
#include "glow_growapi.h"
#include "glow_growwidget_gtk.h"
#include "xtt_tbl_gtk.h"
#include "xtt_tblnav_gtk.h"
//
// Create the navigator widget
//
TblNavGtk::TblNavGtk(
void *xn_parent_ctx,
GtkWidget *xn_parent_wid,
sevcli_sHistItem *xn_itemlist,
int xn_item_cnt,
GtkWidget **w,
pwr_tStatus *status) :
TblNav( xn_parent_ctx, xn_itemlist, xn_item_cnt, status),
parent_wid(xn_parent_wid)
{
form_widget = scrolledbrowwidgetgtk_new(
TblNav::init_brow_cb, this, &brow_widget);
gtk_widget_show_all( brow_widget);
// Create the root item
*w = form_widget;
*status = 1;
}
//
// Delete a nav context
//
TblNavGtk::~TblNavGtk()
{
delete brow;
gtk_widget_destroy( form_widget);
}
void TblNavGtk::set_inputfocus()
{
gtk_widget_grab_focus( brow_widget);
}
/*
* Proview $Id: xtt_tblnav_gtk.h,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef xtt_tblnav_gtk_h
#define xtt_tblnav_gtk_h
/* xtt_tblnav_gtk.h -- Simple navigator */
#include <gtk/gtk.h>
#ifndef xtt_tblnav_h
# include "../src/xtt_tblnav.h"
#endif
//! The navigation area of the attribute editor.
class TblNavGtk : public TblNav {
public:
TblNavGtk(
void *xn_parent_ctx,
GtkWidget *xn_parent_wid,
sevcli_sHistItem *xn_itemlist,
int xn_item_cnt,
GtkWidget **w,
pwr_tStatus *status);
~TblNavGtk();
GtkWidget *parent_wid;
GtkWidget *brow_widget;
GtkWidget *form_widget;
GtkWidget *toplevel;
void set_inputfocus();
};
#endif
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
ifndef link_rule_mk
link_rule_mk := 1
link = $(ldxx) $(elinkflags) $(domap) -o $(export_exe) \
$(export_obj) $(wb_msg_eobjs) $(rt_msg_eobjs) \
$(pwr_eobj)/rt_io_user.o \
-lpwr_sev -lpwr_rt -lpwr_co $(linkmysql)\
-lpwr_msg_dummy \
-lrpcsvc -lpthread -lm -lrt -ldb_cxx -lz -lcrypt
#-lpwr_wb -lpwr_rt -lpwr_ge -lpwr_flow -lpwr_glow -lpwr_co \
# -L/usr/X11R6/lib -L/usr/local/BerkeleyDB.4.0/lib \
# -L/opt/gnome/lib \
# -lantlr -lImlib -lMrm -lXm -lXpm -lXt -lX11 -lXext -lXp\
# -lXmu -lSM -lICE\
endif
/*
* Proview $Id: sev_xtt.cpp,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelösund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* wb.cpp -- graphical editor */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include "pwr.h"
#include "co_dcli.h"
int main( int argc, char *argv[])
{
int i;
int found = 0;
char wmg[80];
pwr_tFileName file;
if ( argc > 1) {
for ( i = 1; i < argc; i++) {
if ( strcmp( argv[i], "-f") == 0) {
if ( i+1 >= argc) {
printf( "sev_xtt: Syntax error\n");
exit(0);
}
found = 1;
strcpy( wmg, argv[i+1]);
i++;
}
}
}
if ( !found) {
struct stat st;
strcpy( file, "$pwr_exe/sev_xtt_gtk");
dcli_translate_filename( file, file);
if ( stat( file, &st) == 0)
strcpy( wmg, "gtk");
else
strcpy( wmg, "motif");
}
strcpy( file, argv[0]);
strcat( file, "_");
strcat( file, wmg);
execvp( file, argv);
}
/*
* Proview $Id: xtt_tbl.cpp,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
/* xtt_tbl.cpp -- Display object attributes */
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector.h>
#include "co_cdh.h"
#include "co_time.h"
#include "flow.h"
#include "flow_browctx.h"
#include "flow_browapi.h"
#include "glow.h"
#include "glow_growctx.h"
#include "glow_growapi.h"
#include "flow_msg.h"
#include "xtt_tbl.h"
#include "xtt_tblnav.h"
XttTbl::~XttTbl()
{
}
XttTbl::XttTbl( void *xn_parent_ctx, sevcli_tCtx xn_sevcli) :
parent_ctx(xn_parent_ctx), sevcli(xn_sevcli)
{
}
void XttTbl::message( void *xtttbl, char severity, char *message)
{
((XttTbl *)xtttbl)->message( severity, message);
}
void XttTbl::activate_opendshist()
{
sevcli_sHistItem *hi;
tblnav->get_select( &hi);
dshist_new( hi->oid, hi->aname);
}
/*
* Proview $Id: xtt_tbl.h,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef xtt_tbl_h
#define xtt_tbl_h
#include "glow.h"
#include "rt_sevcli.h"
/* xtt_tbl.h -- Sev Table Viewer */
class TblNav;
class XttDsHist;
class XttTbl {
public:
XttTbl( void *xn_parent_ctx, sevcli_tCtx xn_sevcli);
void *parent_ctx;
char name[80];
TblNav *tblnav;
sevcli_tCtx sevcli;
virtual void message( char severity, char *message) {}
virtual XttDsHist *dshist_new( pwr_tOid oid, char *aname) { return 0;}
void activate_opendshist();
static void message( void *attr, char severity, char *message);
virtual ~XttTbl();
};
#endif
/*
* Proview $Id: xtt_tblnav.cpp,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
/* ge_attrnav.cpp -- Display object info */
#include "glow_std.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector.h>
#include "co_cdh.h"
#include "co_time.h"
#include "flow.h"
#include "flow_browctx.h"
#include "flow_browapi.h"
#include "flow_msg.h"
#include "xtt_tblnav.h"
#include "xnav_bitmap_leaf12.h"
#include "xnav_bitmap_map12.h"
#include "xnav_bitmap_openmap12.h"
#include "xnav_bitmap_attr12.h"
#include "xnav_bitmap_attrarra12.h"
#define TBLNAV__INPUT_SYNTAX 2
#define TBLNAV__OBJNOTFOUND 4
#define TBLNAV__STRINGTOLONG 6
#define TBLNAV__ITEM_NOCREA 8
#define TBLNAV__SUCCESS 1
void TblNav::message( char sev, char *text)
{
(message_cb)( parent_ctx, sev, text);
}
//
// Free pixmaps
//
void TblNavBrow::free_pixmaps()
{
brow_FreeAnnotPixmap( ctx, pixmap_leaf);
brow_FreeAnnotPixmap( ctx, pixmap_map);
brow_FreeAnnotPixmap( ctx, pixmap_openmap);
brow_FreeAnnotPixmap( ctx, pixmap_attr);
}
//
// Create pixmaps for leaf, closed map and open map
//
void TblNavBrow::allocate_pixmaps()
{
flow_sPixmapData pixmap_data;
int i;
for ( i = 0; i < 9; i++) {
pixmap_data[i].width =xnav_bitmap_leaf12_width;
pixmap_data[i].height =xnav_bitmap_leaf12_height;
pixmap_data[i].bits = (char *)xnav_bitmap_leaf12_bits;
}
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_leaf);
for ( i = 0; i < 9; i++) {
pixmap_data[i].width =xnav_bitmap_map12_width;
pixmap_data[i].height =xnav_bitmap_map12_height;
pixmap_data[i].bits = (char *)xnav_bitmap_map12_bits;
}
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_map);
for ( i = 0; i < 9; i++) {
pixmap_data[i].width =xnav_bitmap_openmap12_width;
pixmap_data[i].height =xnav_bitmap_openmap12_height;
pixmap_data[i].bits = (char *)xnav_bitmap_openmap12_bits;
}
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_openmap);
for ( i = 0; i < 9; i++) {
pixmap_data[i].width =xnav_bitmap_attr12_width;
pixmap_data[i].height =xnav_bitmap_attr12_height;
pixmap_data[i].bits = (char *)xnav_bitmap_attr12_bits;
}
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_attr);
for ( i = 0; i < 9; i++) {
pixmap_data[i].width =xnav_bitmap_attrarra12_width;
pixmap_data[i].height =xnav_bitmap_attrarra12_height;
pixmap_data[i].bits = (char *)xnav_bitmap_attrarra12_bits;
}
brow_AllocAnnotPixmap( ctx, &pixmap_data, &pixmap_attrarray);
}
//
// Create the navigator widget
//
TblNav::TblNav(
void *xn_parent_ctx,
sevcli_sHistItem *xn_itemlist,
int xn_item_cnt,
pwr_tStatus *status) :
parent_ctx(xn_parent_ctx),
itemlist(xn_itemlist),item_cnt(xn_item_cnt),
message_cb(NULL)
{
*status = 1;
}
//
// Delete a nav context
//
TblNav::~TblNav()
{
}
TblNavBrow::~TblNavBrow()
{
free_pixmaps();
}
//
// Callbacks from brow
//
static int tblnav_brow_cb( FlowCtx *ctx, flow_tEvent event)
{
TblNav *tblnav;
ItemLocal *item;
if ( event->event == flow_eEvent_ObjectDeleted) {
brow_GetUserData( event->object.object, (void **)&item);
delete item;
return 1;
}
brow_GetCtxUserData( (BrowCtx *)ctx, (void **) &tblnav);
tblnav->message( ' ', "");
switch ( event->event) {
case flow_eEvent_Key_PageDown: {
brow_Page( tblnav->brow->ctx, 0.8);
break;
}
case flow_eEvent_Key_PageUp: {
brow_Page( tblnav->brow->ctx, -0.8);
break;
}
case flow_eEvent_ScrollDown: {
brow_Page( tblnav->brow->ctx, 0.1);
break;
}
case flow_eEvent_ScrollUp: {
brow_Page( tblnav->brow->ctx, -0.1);
break;
}
case flow_eEvent_Key_Up: {
brow_tNode *node_list;
int node_count;
brow_tObject object;
int sts;
brow_GetSelectedNodes( tblnav->brow->ctx, &node_list, &node_count);
if ( !node_count) {
sts = brow_GetLastVisible( tblnav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
if ( !brow_IsVisible( tblnav->brow->ctx, node_list[0], flow_eVisible_Partial)) {
sts = brow_GetLastVisible( tblnav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
sts = brow_GetPrevious( tblnav->brow->ctx, node_list[0], &object);
if ( EVEN(sts)) {
if ( node_count)
free( node_list);
return 1;
}
}
}
brow_SelectClear( tblnav->brow->ctx);
brow_SetInverse( object, 1);
brow_SelectInsert( tblnav->brow->ctx, object);
if ( !brow_IsVisible( tblnav->brow->ctx, object, flow_eVisible_Full))
brow_CenterObject( tblnav->brow->ctx, object, 0.25);
if ( node_count)
free( node_list);
break;
}
case flow_eEvent_Key_Down: {
brow_tNode *node_list;
int node_count;
brow_tObject object;
int sts;
brow_GetSelectedNodes( tblnav->brow->ctx, &node_list, &node_count);
if ( !node_count) {
sts = brow_GetFirstVisible( tblnav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
if ( !brow_IsVisible( tblnav->brow->ctx, node_list[0], flow_eVisible_Partial)) {
sts = brow_GetFirstVisible( tblnav->brow->ctx, &object);
if ( EVEN(sts)) return 1;
}
else {
sts = brow_GetNext( tblnav->brow->ctx, node_list[0], &object);
if ( EVEN(sts)) {
if ( node_count)
free( node_list);
return 1;
}
}
}
brow_SelectClear( tblnav->brow->ctx);
brow_SetInverse( object, 1);
brow_SelectInsert( tblnav->brow->ctx, object);
if ( !brow_IsVisible( tblnav->brow->ctx, object, flow_eVisible_Full))
brow_CenterObject( tblnav->brow->ctx, object, 0.75);
if ( node_count)
free( node_list);
break;
}
case flow_eEvent_SelectClear:
brow_ResetSelectInverse( tblnav->brow->ctx);
break;
case flow_eEvent_MB1Click:
// Select
switch ( event->object.object_type) {
case flow_eObjectType_Node:
if ( brow_FindSelectedObject( tblnav->brow->ctx, event->object.object)) {
brow_SelectClear( tblnav->brow->ctx);
}
else {
brow_SelectClear( tblnav->brow->ctx);
brow_SetInverse( event->object.object, 1);
brow_SelectInsert( tblnav->brow->ctx, event->object.object);
}
break;
default:
brow_SelectClear( tblnav->brow->ctx);
}
break;
case flow_eEvent_Key_Left: {
brow_tNode *node_list;
int node_count;
brow_tObject object;
int sts;
brow_GetSelectedNodes( tblnav->brow->ctx, &node_list, &node_count);
if ( !node_count)
return 1;
if ( brow_IsOpen( node_list[0]))
// Close this node
object = node_list[0];
else {
// Close parent
sts = brow_GetParent( tblnav->brow->ctx, node_list[0], &object);
if ( EVEN(sts)) {
free( node_list);
return 1;
}
}
brow_GetUserData( object, (void **)&item);
switch( item->type) {
case tblnav_eItemType_Local:
((ItemLocal *)item)->close( tblnav, 0, 0);
break;
default:
;
}
brow_SelectClear( tblnav->brow->ctx);
brow_SetInverse( object, 1);
brow_SelectInsert( tblnav->brow->ctx, object);
if ( !brow_IsVisible( tblnav->brow->ctx, object, flow_eVisible_Full))
brow_CenterObject( tblnav->brow->ctx, object, 0.25);
free( node_list);
break;
}
case flow_eEvent_Key_Right: {
brow_tNode *node_list;
int node_count;
brow_GetSelectedNodes( tblnav->brow->ctx, &node_list, &node_count);
if ( !node_count)
return 1;
brow_GetUserData( node_list[0], (void **)&item);
switch( item->type) {
case tblnav_eItemType_Local:
((ItemLocal *)item)->open_attributes( tblnav, 0, 0);
break;
default:
;
}
}
case flow_eEvent_MB1DoubleClick:
switch ( event->object.object_type) {
case flow_eObjectType_Node:
brow_GetUserData( event->object.object, (void **)&item);
switch( item->type) {
case tblnav_eItemType_Local:
((ItemLocal *)item)->open_attributes( tblnav,
event->object.x, event->object.y);
break;
default:
;
}
break;
default:
;
}
break;
default:
;
}
return 1;
}
//
// Create nodeclasses
//
void TblNavBrow::create_nodeclasses()
{
allocate_pixmaps();
// Create common-class
brow_CreateNodeClass( ctx, "NavigatorDefault",
flow_eNodeGroup_Common, &nc_object);
brow_AddFrame( nc_object, 0, 0, 20, 0.8, flow_eDrawType_Line, -1, 1);
brow_AddAnnotPixmap( nc_object, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
brow_AddAnnotPixmap( nc_object, 1, 1.1, 0.1, flow_eDrawType_Line, 2, 0);
brow_AddAnnot( nc_object, 2, 0.6, 0,
flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine,
0);
brow_AddAnnot( nc_object, 12, 0.6, 1,
flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine,
1);
brow_AddAnnot( nc_object, 15, 0.6, 2,
flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine,
1);
// Create attribute nodeclass
brow_CreateNodeClass( ctx, "NavigatorAttr",
flow_eNodeGroup_Common, &nc_attr);
brow_AddFrame( nc_attr, 0, 0, 20, 0.8, flow_eDrawType_Line, -1, 1);
brow_AddAnnotPixmap( nc_attr, 0, 0.2, 0.1, flow_eDrawType_Line, 2, 0);
brow_AddAnnot( nc_attr, 2, 0.6, 0,
flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine,
0);
brow_AddAnnot( nc_attr, 8, 0.6, 1,
flow_eDrawType_TextHelveticaBold, 2, flow_eAnnotType_OneLine,
1);
}
int TblNav::create_items()
{
int i;
brow_SetNodraw( brow->ctx);
for ( i = 0; i < item_cnt; i++) {
new ItemLocal( this, &itemlist[i], NULL, flow_eDest_IntoLast);
}
brow_ResetNodraw( brow->ctx);
brow_Redraw( brow->ctx, 0);
return TBLNAV__SUCCESS;
}
void TblNavBrow::brow_setup()
{
brow_sAttributes brow_attr;
unsigned long mask;
mask = 0;
mask |= brow_eAttr_indentation;
brow_attr.indentation = 0.5;
mask |= brow_eAttr_annotation_space;
brow_attr.annotation_space = 0.5;
brow_SetAttributes( ctx, &brow_attr, mask);
brow_SetCtxUserData( ctx, tblnav);
brow_EnableEvent( ctx, flow_eEvent_MB1Click, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_MB1DoubleClick, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_SelectClear, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_ObjectDeleted, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_Up, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_Down, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_Right, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_Left, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_PF3, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Radiobutton, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_PageUp, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_Key_PageDown, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_ScrollUp, flow_eEventType_CallBack,
tblnav_brow_cb);
brow_EnableEvent( ctx, flow_eEvent_ScrollDown, flow_eEventType_CallBack,
tblnav_brow_cb);
}
//
// Backcall routine called at creation of the brow widget
// Enable event, create nodeclasses and insert the root objects.
//
int TblNav::init_brow_cb( FlowCtx *fctx, void *client_data)
{
TblNav *tblnav = (TblNav *) client_data;
BrowCtx *ctx = (BrowCtx *)fctx;
tblnav->brow = new TblNavBrow( ctx, (void *)tblnav);
tblnav->brow->brow_setup();
tblnav->brow->create_nodeclasses();
// Create the root items
tblnav->create_items();
//sts = brow_TraceInit( ctx, tblnav_trace_connect_bc,
// tblnav_trace_disconnect_bc, tblnav_trace_scan_bc);
//tblnav->trace_started = 1;
//tblnav->trace_start();
return 1;
}
int TblNav::get_select( sevcli_sHistItem **hi)
{
brow_tNode *node_list;
int node_count;
ItemLocal *item;
brow_GetSelectedNodes( brow->ctx, &node_list, &node_count);
if ( !node_count)
return 0;
brow_GetUserData( node_list[0], (void **)&item);
switch ( item->type) {
case tblnav_eItemType_Local:
*hi = &item->item;
return 1;
default: ;
}
return 0;
}
ItemLocal::ItemLocal( TblNav *tblnav, sevcli_sHistItem *xitem,
brow_tNode dest, flow_eDest dest_code) : item(*xitem)
{
type = tblnav_eItemType_Local;
pwr_tAName aname;
brow_CreateNode( tblnav->brow->ctx, "LocalItem", tblnav->brow->nc_object,
dest, dest_code, (void *) this, 1, &node);
brow_SetAnnotPixmap( node, 0, tblnav->brow->pixmap_leaf);
strcpy( aname, item.oname);
strcat( aname, ".");
strcat( aname, item.aname);
brow_SetAnnotation( node, 0, aname, strlen(aname));
brow_SetAnnotation( node, 1, item.description, strlen(item.description));
}
int ItemLocal::open_attributes( TblNav *tblnav, double x, double y)
{
double node_x, node_y;
brow_GetNodePosition( node, &node_x, &node_y);
if ( brow_IsOpen( node)) {
// Close
brow_SetNodraw( tblnav->brow->ctx);
brow_CloseNode( tblnav->brow->ctx, node);
brow_SetAnnotPixmap( node, 0, tblnav->brow->pixmap_leaf);
brow_ResetOpen( node, tblnav_mOpen_All);
brow_ResetNodraw( tblnav->brow->ctx);
brow_Redraw( tblnav->brow->ctx, node_y);
}
else {
char value[256];
brow_SetNodraw( tblnav->brow->ctx);
new ItemLocalAttr( tblnav, "Description", item.description, node, flow_eDest_IntoLast);
strcpy( value, "");
cdh_ObjidToString( value, item.oid, 1);
new ItemLocalAttr( tblnav, "Oid", value, node, flow_eDest_IntoLast);
new ItemLocalAttr( tblnav, "Object", item.oname, node, flow_eDest_IntoLast);
new ItemLocalAttr( tblnav, "Attribute", item.aname, node, flow_eDest_IntoLast);
time_DtoAscii( &item.storagetime, 0, value, sizeof(value));
new ItemLocalAttr( tblnav, "StorageTime", value, node, flow_eDest_IntoLast);
switch ( item.type) {
case pwr_eType_Int64: strcpy( value, "Int64"); break;
case pwr_eType_Int32: strcpy( value, "Int32"); break;
case pwr_eType_Int16: strcpy( value, "Int16"); break;
case pwr_eType_Int8: strcpy( value, "Int8"); break;
case pwr_eType_UInt64: strcpy( value, "UInt64"); break;
case pwr_eType_UInt32: strcpy( value, "UInt32"); break;
case pwr_eType_UInt16: strcpy( value, "UInt16"); break;
case pwr_eType_UInt8: strcpy( value, "UInt8"); break;
case pwr_eType_Boolean: strcpy( value, "Boolean"); break;
case pwr_eType_Char: strcpy( value, "Char"); break;
case pwr_eType_Float32: strcpy( value, "Float32"); break;
case pwr_eType_Float64: strcpy( value, "Float64"); break;
case pwr_eType_String: strcpy( value, "String"); break;
case pwr_eType_Time: strcpy( value, "Time"); break;
case pwr_eType_DeltaTime: strcpy( value, "DeltaTime"); break;
default: strcpy( value, "Unknown");
}
new ItemLocalAttr( tblnav, "DataType", value, node, flow_eDest_IntoLast);
sprintf( value, "%d", item.size);
new ItemLocalAttr( tblnav, "DataSize", value, node, flow_eDest_IntoLast);
new ItemLocalAttr( tblnav, "Unit", item.unit, node, flow_eDest_IntoLast);
sprintf( value, "%f", item.scantime);
new ItemLocalAttr( tblnav, "ScanTime", value, node, flow_eDest_IntoLast);
brow_SetOpen( node, tblnav_mOpen_Attributes);
brow_ResetNodraw( tblnav->brow->ctx);
brow_Redraw( tblnav->brow->ctx, node_y);
}
return 1;
}
int ItemLocal::close( TblNav *tblnav, double x, double y)
{
double node_x, node_y;
brow_GetNodePosition( node, &node_x, &node_y);
if ( brow_IsOpen( node)) {
// Close
brow_SetNodraw( tblnav->brow->ctx);
brow_CloseNode( tblnav->brow->ctx, node);
brow_SetAnnotPixmap( node, 0, tblnav->brow->pixmap_leaf);
brow_ResetOpen( node, tblnav_mOpen_All);
brow_ResetNodraw( tblnav->brow->ctx);
brow_Redraw( tblnav->brow->ctx, node_y);
}
return 1;
}
ItemLocalAttr::ItemLocalAttr( TblNav *tblnav, char *name, char *value,
brow_tNode dest, flow_eDest dest_code)
{
type = tblnav_eItemType_LocalAttr;
brow_CreateNode( tblnav->brow->ctx, "LocalItemAttr", tblnav->brow->nc_attr,
dest, dest_code, (void *) this, 1, &node);
brow_SetAnnotPixmap( node, 0, tblnav->brow->pixmap_attr);
brow_SetAnnotation( node, 0, name, strlen(name));
brow_SetAnnotation( node, 1, value, strlen(value));
}
/*
* Proview $Id: xtt_tblnav.h,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef xtt_tblnav_h
#define xtt_tblnav_h
/* xtt_attrnav.h -- Sev Table Viewer */
#ifndef pwr_h
# include "pwr.h"
#endif
#ifndef flow_h
#include "flow.h"
#endif
#ifndef flow_browctx_h
#include "flow_browapi.h"
#endif
#ifndef rt_qcom_h
#include "rt_qcom.h"
#endif
#ifndef rt_sevcli_h
#include "rt_sevcli.h"
#endif
typedef enum {
tblnav_eItemType_Local,
tblnav_eItemType_LocalAttr
} tblnav_eItemType;
typedef enum {
tblnav_mOpen_All = ~0,
tblnav_mOpen_Attributes = 1 << 1
} tblnav_mOpen;
//! Class for handling of brow.
class TblNavBrow {
public:
TblNavBrow( BrowCtx *brow_ctx, void *xn) : ctx(brow_ctx), tblnav(xn) {};
~TblNavBrow();
BrowCtx *ctx;
void *tblnav;
brow_tNodeClass nc_object;
brow_tNodeClass nc_attr;
flow_sAnnotPixmap *pixmap_leaf;
flow_sAnnotPixmap *pixmap_map;
flow_sAnnotPixmap *pixmap_openmap;
flow_sAnnotPixmap *pixmap_attr;
flow_sAnnotPixmap *pixmap_attrarray;
void free_pixmaps();
void allocate_pixmaps();
void create_nodeclasses();
void brow_setup();
};
//! The navigation area of the attribute editor.
class TblNav {
public:
TblNav( void *xn_parent_ctx,
sevcli_sHistItem *xn_itemlist,
int xn_item_cnt,
pwr_tStatus *status);
virtual ~TblNav();
void *parent_ctx;
TblNavBrow *brow;
sevcli_sHistItem *itemlist;
int item_cnt;
void (*message_cb)( void *, char, char *);
int create_items();
int get_select( sevcli_sHistItem **hi);
virtual void message( char sev, char *text);
virtual void set_inputfocus() {}
static int init_brow_cb( FlowCtx *fctx, void *client_data);
};
//! Item for a normal attribute.
class ItemLocal {
public:
ItemLocal( TblNav *tblnav, sevcli_sHistItem *item, brow_tNode dest, flow_eDest dest_code);
sevcli_sHistItem item;
tblnav_eItemType type;
brow_tNode node;
int open_attributes( TblNav *tblnav, double x, double y);
int close( TblNav *tblnav, double x, double y);
};
class ItemLocalAttr {
public:
ItemLocalAttr( TblNav *tblnav, char *iname, char *ivalue, brow_tNode dest, flow_eDest dest_code);
sevcli_sHistItem item;
tblnav_eItemType type;
brow_tNode node;
};
#endif
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
-include ../../special.mk
-include ../special.mk
-include special.mk
/*
* Proview $Id: sev_db.h,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef sev_db_h
#define sev_db_h
#include <vector.h>
#include "pwr.h"
#include "pwr_class.h"
class sev_item {
public:
sev_item() {}
unsigned int id;
char tablename[256];
pwr_tOid oid;
pwr_tOName aname;
pwr_tOName oname;
pwr_tTime cretime;
pwr_tTime uptime;
pwr_tDeltaTime storagetime;
pwr_eType vtype;
unsigned int vsize;
pwr_tRefId sevid;
pwr_tString80 description;
pwr_tString16 unit;
pwr_tFloat32 scantime;
};
class sev_db {
public:
vector<sev_item> m_items;
sev_db() {}
virtual ~sev_db() {}
virtual int check_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storatetime, pwr_eType type, unsigned int size,
char *description, char *unit, pwr_tFloat32 scantime, unsigned int *idx)
{ return 0;}
virtual int add_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, pwr_eType type, unsigned int size,
char *description, char *unit, pwr_tFloat32 scantime, unsigned int *idx)
{ return 0;}
virtual int store_value( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eType type,
pwr_tTime time, void *buf, unsigned int size) { return 0;}
virtual int get_values( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eType type,
unsigned int size, pwr_tFloat32 scantime, pwr_tTime *starttime,
pwr_tTime *endtime, int maxsize, pwr_tTime **tbuf, void **vbuf,
unsigned int *bsize) { return 0;}
virtual int get_items( pwr_tStatus *sts) { return 0;}
virtual int delete_old_data( pwr_tStatus *sts, pwr_tOid oid, char *aname,
pwr_tTime limit) { return 0;}
};
#endif
/*
* Proview $Id: sev_dbms.cpp,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include "pwr.h"
#include "co_syi.h"
#include "co_cdh.h"
#include "co_dcli.h"
#include "co_time.h"
#include "rt_load.h"
#include "sev_dbms.h"
#include "rt_sev_msg.h"
char sev_dbms_env::m_systemName[40];
sev_dbms_env::sev_dbms_env(const char *v_fileName) :
m_con(0), m_fileName(0), m_host(0), m_user(0), m_passwd(0), m_dbName(0), m_port(0), m_socket(0), m_exists(false)
{
fileName(v_fileName);
strcpy( m_systemName, "");
get_systemname();
}
sev_dbms_env::sev_dbms_env(const char *v_host, const char *v_user, const char *v_passwd,
const char *v_dbName, unsigned int v_port, const char *v_socket) :
m_con(0), m_fileName(0), m_host(0), m_user(0), m_passwd(0), m_dbName(0), m_port(0),
m_socket(0), m_exists(false)
{
strcpy( m_systemName, "");
host(v_host);
user(v_user);
passwd(v_passwd);
dbName(v_dbName);
port(v_port);
socket(v_socket);
get_systemname();
}
void sev_dbms_env::host(const char *host)
{
if (!host)
return;
m_host = (char *)realloc(m_host, strlen(host));
strcpy(m_host, host);
}
void sev_dbms_env::user(const char *user)
{
if (!user)
return;
m_user = (char *)realloc(m_user, strlen(user));
strcpy(m_user, user);
}
void sev_dbms_env::passwd(const char *passwd)
{
if (!passwd)
return;
m_passwd = (char *)realloc(m_passwd, strlen(passwd));
strcpy(m_passwd, passwd);
}
void sev_dbms_env::dbName(const char *dbName)
{
if (!dbName)
return;
m_dbName = (char *)realloc(m_dbName, strlen(dbName));
strcpy(m_dbName, dbName);
}
void sev_dbms_env::fileName(const char *fileName)
{
if (!fileName)
return;
m_fileName = (char *)realloc(m_fileName, strlen(fileName));
strcpy(m_fileName, fileName);
}
char *sev_dbms_env::dbName(void)
{
static char dbname[80];
get_systemname();
strcpy( dbname, "pwrp__");
strcat( dbname, m_systemName);
cdh_ToLower( dbname, dbname);
return dbname;
}
char *sev_dbms_env::host(void)
{
char nodename[80];
pwr_tStatus sts;
static char host[80];
syi_NodeName( &sts, nodename, sizeof(nodename));
if ( ODD(sts) && cdh_NoCaseStrcmp( nodename, m_host) == 0)
strcpy( host, "localhost");
else
strcpy( host, m_host);
return host;
}
void sev_dbms_env::port(const unsigned int port)
{
m_port = port;
}
void sev_dbms_env::socket(const char *socket)
{
if (!socket)
return;
m_socket = (char *)realloc(m_socket, strlen(socket));
strcpy(m_socket, socket);
}
sev_dbms_env::sev_dbms_env() :
m_con(0), m_fileName(0), m_host(0), m_user(0), m_passwd(0), m_dbName(0), m_port(0), m_socket(0), m_exists(false)
{
};
int sev_dbms_env::close()
{
return 0;
}
int sev_dbms_env::open(const char *v_host, const char *v_user, const char *v_passwd,
const char *v_dbName, unsigned int v_port, const char *v_socket)
{
host(v_host);
user(v_user);
passwd(v_passwd);
dbName(v_dbName);
port(v_port);
socket(v_socket);
m_con = mysql_init(NULL);
MYSQL *con = mysql_real_connect(m_con, host(), user(), passwd(), dbName(), port(), socket(), 0);
if (con == 0) {
printf("Failed to connect to database: Error: %s\n", mysql_error(m_con));
return 1;
}
char sql[255];
sprintf(sql, "use %s", dbName());
int rc = mysql_query(m_con, sql);
if (rc) {
printf("%s\n", mysql_error(m_con));
printf("%s\n", sql);
return rc;
} else {
printf("database open %s\n", sql);
}
return 0;
}
int sev_dbms_env::create(const char *v_fileName, const char *v_host, const char *v_user,
const char *v_passwd, const char *v_dbName, unsigned int v_port,
const char *v_socket)
{
fileName(v_fileName);
host(v_host);
user(v_user);
passwd(v_passwd);
dbName(v_dbName);
port(v_port);
socket(v_socket);
create();
return 0;
}
MYSQL *sev_dbms_env::createDb(void)
{
m_con = mysql_init(NULL);
MYSQL *con = mysql_real_connect(m_con, host(), user(), passwd(), 0, port(), socket(), 0);
// printf("Tried to connect to database, con %x: Status: %s\n", (int)con, mysql_error(m_con));
if (con == 0) {
printf("Failed to connect to database: Error: %s\n", mysql_error(m_con));
return 0;
}
char query[400];
sprintf(query, "create database %s", dbName());
int rc = mysql_query(m_con, query);
if (rc) {
printf("%s\n", mysql_error(m_con));
printf("%s\n", query);
return 0;
}
sprintf(query, "use %s", dbName());
rc = mysql_query(m_con, query);
if (rc) {
printf("%s\n", mysql_error(m_con));
printf("%s\n", query);
return 0;
}
sprintf( query, "create table items ("
"id int unsigned not null primary key auto_increment,"
"tablename varchar(255),"
"vid int unsigned,"
"oix int unsigned,"
"oname varchar(255),"
"aname varchar(255),"
"uptime datetime,"
"cretime datetime,"
"storagetime int unsigned,"
"vtype int unsigned,"
"vsize int unsigned,"
"description varchar(80),"
"unit varchar(16),"
"scantime float);");
rc = mysql_query( m_con, query);
if (rc) printf( "Create items table: %s\n", mysql_error(m_con));
return con;
}
MYSQL *sev_dbms_env::openDb()
{
m_con = mysql_init(NULL);
MYSQL *con = mysql_real_connect(m_con, host(), user(), passwd(), dbName(), port(), socket(), 0);
// printf("Tried to connect to database, con %x: Status: %s\n", (int)con, mysql_error(m_con));
if (con == 0) {
printf("Failed to connect to database: Error: %s\n", mysql_error(m_con));
return 0;
}
return con;
}
int sev_dbms_env::create()
{
struct stat sb;
char name[512];
cdh_ToLower(m_fileName, m_fileName);
printf("sev_dbms_env::create: %s\n", m_fileName);
/* Create the directory, read/write/access owner and group. */
if (stat(m_fileName, &sb) != 0) {
if (mkdir(m_fileName, S_IRWXU | S_IRWXG) != 0) {
fprintf(stderr, "sev_dbms_env::create: mkdir: %s, %s\n", m_fileName, strerror(errno));
return errno;
}
}
sprintf(name, "%s/%s", m_fileName, "connection.dmsql");
if (stat(name, &sb) != 0) {
FILE *fp;
fp = fopen(name, "w+b");
if (fp == NULL) {
printf("** Cannot open file: %s, %s\n", name, strerror(errno));
return errno;
}
fprintf(fp, "HOST...: %s\n", m_host);
fprintf(fp, "USER...: %s\n", user());
if ( !passwd() || strcmp( passwd(), "") == 0)
fprintf(fp, "PASSWD.: (null)\n");
else
fprintf(fp, "PASSWD.: %s\n", passwd());
fprintf(fp, "DB_NAME: %s\n", m_dbName);
fprintf(fp, "PORT...: %d\n", port());
fprintf(fp, "SOCKET.: %s\n", socket());
fclose(fp);
}
return 0;
}
int sev_dbms_env::open(const char* v_fileName)
{
fileName(v_fileName);
return open();
}
int sev_dbms_env::open(void)
{
char var[32];
char value[32];
char buf[512];
char *s;
char *valp;
int rc;
cdh_ToLower(m_fileName, m_fileName);
sprintf(buf, "%s/%s", m_fileName, "connection.dmsql");
FILE *fp = fopen(buf, "r");
if (fp == NULL) {
printf("** Cannot open file: %s, %s\n", buf, strerror(errno));
return errno;
}
while ((s = fgets(buf, sizeof(buf) - 1, fp))) {
if (*s == '#')
continue;
rc = sscanf(s, " %[A-Z_] %*[^ ] %s", var, value);
if (rc < 1)
continue;
if (rc == 1)
valp = 0;
else
valp = value;
if (strcmp(valp, "(null)") == 0)
valp = 0;
if (strcmp(var, "HOST") == 0) {
host(valp);
}
else if (strcmp(var, "USER") == 0) {
user(valp);
}
else if (strcmp(var, "PASSWD") == 0) {
passwd(valp);
}
else if (strcmp(var, "DB_NAME") == 0) {
dbName(valp);
}
else if (strcmp(var, "PORT") == 0) {
if (valp == 0)
port(0);
else
port(atoi(valp));
}
else if (strcmp(var, "SOCKET") == 0) {
socket(valp);
}
else {
printf("Unknown connection parameter! : %s\n", var);
}
}
fclose(fp);
m_exists = true;
return 0;
}
int sev_dbms_env::get_systemname()
{
FILE *file;
char fname[120];
char nodename[40];
char *bus_str;
int bus;
char line[200];
pwr_tStatus sts;
if ( strcmp( m_systemName, "") != 0)
return 1;
syi_NodeName( &sts, nodename, sizeof(nodename));
if ( EVEN(sts)) return 0;
bus_str = getenv( "PWR_BUS_ID");
if ( !bus_str)
return 0;
if ( sscanf( bus_str, "%d", &bus) != 1)
return 0;
sprintf( fname, load_cNameBoot, load_cDirectory, nodename, bus);
dcli_translate_filename( fname, fname);
file = fopen( fname, "r");
if ( file == 0) {
printf("** Warning, systemname not found\n");
return 0;
}
if ( !dcli_read_line( line, sizeof(line), file))
return 0;
if ( !dcli_read_line( line, sizeof(line), file))
return 0;
strcpy( m_systemName, line);
return 1;
}
int sev_dbms::create_table( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eType type,
unsigned int size)
{
char query[200];
sprintf( query, "create table %s ( id int unsigned not null primary key auto_increment,"
"time datetime not null, value %s);",
oid_to_table(oid, aname), pwrtype_to_type( type, size));
int rc = mysql_query( m_env->con(), query);
if (rc) {
printf( "Create table: %s\n", mysql_error(m_env->con()));
*sts = SEV__DBERROR;
return 0;
}
return 1;
}
int sev_dbms::store_item( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *oname,
char *aname, pwr_tDeltaTime storagetime, pwr_eType vtype,
unsigned int vsize, char *description, char *unit, pwr_tFloat32 scantime)
{
char query[800];
char timestr[40];
pwr_tTime cretime;
clock_gettime( CLOCK_REALTIME, &cretime);
time_AtoAscii( &cretime, time_eFormat_NumDateAndTime, timestr, sizeof(timestr));
timestr[19] = 0;
sprintf( query, "insert into items (id,tablename,vid,oix,oname,aname,uptime,cretime,storagetime,vtype,vsize,description,unit,scantime) "
"values (0,'%s',%d,%d,'%s','%s','%s','%s',%d,%d,%d,'%s','%s',%f);",
tablename, oid.vid, oid.oix, oname, aname, timestr, timestr, storagetime.tv_sec, vtype,
vsize, description, unit, scantime);
int rc = mysql_query( m_env->con(), query);
if (rc) {
printf( "Store item: %s\n", mysql_error(m_env->con()));
*sts = SEV__DBERROR;
return 0;
}
*sts = SEV__SUCCESS;
return 1;
}
int sev_dbms::get_items( pwr_tStatus *sts)
{
m_items.clear();
char query[300];
sprintf( query, "select id,tablename,vid,oix,oname,aname,uptime,cretime,storagetime,vtype,vsize,description,unit,scantime "
"from items");
int rc = mysql_query( m_env->con(), query);
if (rc) {
printf( "Get Items: %s\n", mysql_error(m_env->con()));
*sts = SEV__DBERROR;
return 0;
}
MYSQL_ROW row;
MYSQL_RES *result = mysql_store_result( m_env->con());
if ( !result) {
printf( "GetValues Result Error\n");
*sts = SEV__DBERROR;
return 0;
}
int rows = mysql_num_rows( result);
for ( int i = 0; i < rows; i++) {
sev_item item;
row = mysql_fetch_row( result);
if (!row) break;
printf( "%d %s %s\n", i, row[0], row[1]);
item.id = atoi( row[0]);
strncpy( item.tablename, row[1], sizeof(item.tablename));
item.oid.vid = strtoul( row[2], 0, 10);
item.oid.oix = strtoul( row[3], 0, 10);
strncpy( item.oname, row[4], sizeof(item.oname));
strncpy( item.aname, row[5], sizeof(item.aname));
timestr_to_time( row[6], &item.uptime);
timestr_to_time( row[7], &item.cretime);
item.storagetime.tv_sec = strtoul( row[8], 0, 10);
item.storagetime.tv_nsec = 0;
item.vtype = (pwr_eType) strtoul( row[9], 0, 10);
item.vsize = strtoul( row[10], 0, 10);
strncpy( item.description, row[11], sizeof(item.description));
strncpy( item.unit, row[12], sizeof(item.unit));
item.scantime = atof(row[13]);
m_items.push_back( item);
}
mysql_free_result( result);
for ( int i = 0; i < (int)m_items.size(); i++)
printf( "Item: %d %s\n", m_items[i].id, m_items[i].tablename);
*sts = SEV__SUCCESS;
return 1;
}
int sev_dbms::store_value( pwr_tStatus *sts, pwr_tOid oid, char *aname,
pwr_eType type, pwr_tTime time, void *buf, unsigned int size)
{
char query[200];
char bufstr[512];
char timstr[40];
*sts = time_AtoAscii( &time, time_eFormat_NumDateAndTime, timstr, sizeof(timstr));
if ( EVEN(*sts)) return 0;
timstr[19] = 0;
*sts = cdh_AttrValueToString( type, buf, bufstr, sizeof(bufstr));
if ( EVEN(*sts)) return 0;
switch( type) {
case pwr_eType_String:
sprintf( query, "insert into %s (time, value) values ('%s','%s')",
oid_to_table(oid, aname), timstr, bufstr);
break;
default:
sprintf( query, "insert into %s (time, value) values ('%s',%s)",
oid_to_table(oid, aname), timstr, bufstr);
}
int rc = mysql_query( m_env->con(), query);
if (rc) {
printf( "Store value: %s\n", mysql_error(m_env->con()));
*sts = SEV__DBERROR;
return 0;
}
*sts = SEV__SUCCESS;
return 1;
}
int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eType type,
unsigned int size, pwr_tFloat32 scantime,
pwr_tTime *starttime, pwr_tTime *endtime,
int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize)
{
char query[200];
char starttimstr[40];
char endtimstr[40];
int total_rows;
int div;
pwr_tDeltaTime dt;
pwr_tTime stime, etime;
if ( starttime && starttime->tv_sec == 0 && starttime->tv_nsec == 0)
starttime = 0;
else
stime = *starttime;
if ( endtime && endtime->tv_sec == 0 && endtime->tv_nsec == 0)
endtime = 0;
else
etime = *endtime;
// Get number of rows
sprintf( query, "show table status where name = '%s';", oid_to_table(oid, aname));
int rc = mysql_query( m_env->con(), query);
if (rc) {
printf( "GetValues Query Error\n");
*sts = SEV__DBERROR;
return 0;
}
MYSQL_ROW row;
MYSQL_RES *result = mysql_store_result( m_env->con());
if ( !result) {
printf( "GetValues Status Result Error\n");
*sts = SEV__DBERROR;
return 0;
}
row = mysql_fetch_row( result);
if (!row) {
printf( "GetValues Status Result Error\n");
*sts = SEV__DBERROR;
return 0;
}
if ( starttime && endtime) {
pwr_tTime create_time;
pwr_tTime update_time;
timestr_to_time( row[11], &create_time);
timestr_to_time( row[12], &update_time);
if ( time_Acomp( &create_time, &stime) == 1)
stime = create_time;
if ( time_Acomp( &etime, &update_time) == 1)
etime = update_time;
time_Adiff( &dt, &etime, &stime);
total_rows = int (time_DToFloat( 0, &dt) / scantime);
div = total_rows / maxsize + 1;
}
else if ( starttime) {
pwr_tTime update_time;
timestr_to_time( row[12], &update_time);
if ( time_Acomp( &update_time, starttime) != 1) {
mysql_free_result( result);
*sts = SEV__NODATATIME;
return 0;
}
time_Adiff( &dt, &update_time, starttime);
total_rows = int (time_DToFloat( 0, &dt) / scantime);
}
else if ( endtime) {
pwr_tTime create_time;
timestr_to_time( row[11], &create_time);
if ( time_Acomp( endtime, &create_time) != 1) {
mysql_free_result( result);
*sts = SEV__NODATATIME;
return 0;
}
time_Adiff( &dt, endtime, &create_time);
total_rows = int (time_DToFloat( 0, &dt) / scantime);
}
else {
total_rows = atoi(row[4]);
}
mysql_free_result( result);
div = total_rows / maxsize + 1;
if ( starttime) {
*sts = time_AtoAscii( &stime, time_eFormat_NumDateAndTime, starttimstr,
sizeof(starttimstr));
if ( EVEN(*sts)) return 0;
starttimstr[19] = 0;
}
if ( endtime) {
*sts = time_AtoAscii( &etime, time_eFormat_NumDateAndTime, endtimstr,
sizeof(endtimstr));
if ( EVEN(*sts)) return 0;
endtimstr[19] = 0;
}
if ( starttime && endtime) {
if ( div == 1)
sprintf( query, "select time, value from %s where time >= '%s' and time <= '%s' order by time",
oid_to_table(oid, aname), starttimstr, endtimstr);
else
sprintf( query, "select time, value from %s where id %% %d = 0 and time >= '%s' and time <= '%s' order by time",
oid_to_table(oid, aname), div, starttimstr, endtimstr);
}
else if ( starttime) {
if ( div == 1)
sprintf( query, "select time, value from %s where time >= '%s' order by time",
oid_to_table(oid, aname), starttimstr);
else
sprintf( query, "select time, value from %s where id %% %d = 0 and time >= '%s' order by time",
oid_to_table(oid, aname), div, starttimstr);
}
else if ( endtime) {
if ( div == 1)
sprintf( query, "select time, value from %s where time <= '%s' order by time",
oid_to_table(oid, aname), endtimstr);
else
sprintf( query, "select time, value from %s where id %% %d = 0 and time <= '%s' order by time",
oid_to_table(oid, aname), div, endtimstr);
}
else {
if ( div == 1)
sprintf( query, "select time, value from %s order by time",
oid_to_table(oid, aname));
else
sprintf( query, "select time, value from %s where id %% %d = 0 order by time",
oid_to_table(oid, aname), div);
}
rc = mysql_query( m_env->con(), query);
if (rc) {
printf( "Get Values: %s\n", mysql_error(m_env->con()));
*sts = SEV__DBERROR;
return 0;
}
result = mysql_store_result( m_env->con());
if ( !result) {
printf( "GetValues Result Error\n");
*sts = SEV__DBERROR;
return 0;
}
int rows = mysql_num_rows( result);
int bufrows = rows;
*tbuf = (pwr_tTime *) calloc( bufrows, sizeof(pwr_tTime));
*vbuf = calloc( bufrows, size);
int bcnt = 0;
for ( int i = 0; i < rows; i ++) {
if ( div > 1)
mysql_data_seek( result, i);
row = mysql_fetch_row( result);
if (!row) break;
timestr_to_time( row[0], &(*tbuf)[bcnt]);
cdh_StringToAttrValue( type, row[1], ((char *)*vbuf)+ bcnt * size);
bcnt++;
printf( "%5d %5d %s %s\n", i, bcnt, row[0], row[1]);
}
printf( "bcnt %d bufrows %d\n", bcnt, bufrows);
*bsize = bcnt;
mysql_free_result( result);
*sts = SEV__SUCCESS;
return 1;
}
int sev_dbms::check_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, pwr_eType type, unsigned int size,
char *description, char *unit, pwr_tFloat32 scantime, unsigned int *idx)
{
char timestr[40];
pwr_tTime uptime;
clock_gettime( CLOCK_REALTIME, &uptime);
time_AtoAscii( &uptime, time_eFormat_NumDateAndTime, timestr, sizeof(timestr));
timestr[19] = 0;
for ( unsigned int i = 0; i < m_items.size(); i++) {
if ( cdh_ObjidIsEqual( oid, m_items[i].oid) &&
cdh_NoCaseStrcmp( aname, m_items[i].aname) == 0) {
char query[400];
sprintf( query, "update items set ");
if ( storagetime.tv_sec != m_items[i].storagetime.tv_sec)
sprintf( &query[strlen(query)], "storagetime=%d,", storagetime.tv_sec);
if ( strcmp( oname, m_items[i].oname) != 0)
sprintf( &query[strlen(query)], "oname=\'%s\',", oname);
if ( type != m_items[i].vtype)
sprintf( &query[strlen(query)], "type=%d,", type);
if ( size != m_items[i].vsize)
sprintf( &query[strlen(query)], "size=%d", size);
sprintf( &query[strlen(query)], "uptime=\'%s\' ", timestr);
sprintf( &query[strlen(query)], "where id=%d;", m_items[i].id);
int rc = mysql_query( m_env->con(), query);
if (rc) {
printf( "Store item: %s\n", mysql_error(m_env->con()));
*sts = SEV__DBERROR;
return 0;
}
*idx = i;
*sts = SEV__SUCCESS;
return 1;
}
}
*sts = SEV__NOSUCHITEM;
return 0;
}
int sev_dbms::add_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, pwr_eType type, unsigned int size,
char *description, char *unit, pwr_tFloat32 scantime, unsigned int *idx)
{
char tablename[256];
strcpy( tablename, oid_to_table( oid, aname));
store_item( sts, tablename, oid, oname, aname, storagetime, type, size, description, unit,
scantime);
if ( EVEN(*sts)) return 0;
create_table( sts, oid, aname, type, size);
if ( EVEN(*sts)) return 0;
sev_item item;
item.id = 0;
strncpy( item.tablename, tablename, sizeof(item.tablename));
item.oid = oid;
strncpy( item.oname, oname, sizeof(item.oname));
strncpy( item.aname, aname, sizeof(item.aname));
clock_gettime( CLOCK_REALTIME, &item.cretime);
item.uptime = item.cretime;
item.storagetime = storagetime;
item.vtype = type;
item.vsize = size;
strncpy( item.description, description, sizeof(item.description));
strncpy( item.unit, unit, sizeof(item.unit));
item.scantime = scantime;
m_items.push_back( item);
*idx = m_items.size() - 1;
*sts = SEV__SUCCESS;
return 1;
}
int sev_dbms::delete_old_data( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_tTime limit)
{
char query[300];
char timstr[40];
*sts = time_AtoAscii( &limit, time_eFormat_NumDateAndTime, timstr, sizeof(timstr));
if ( EVEN(*sts)) return 0;
timstr[19] = 0;
sprintf( query, "delete from %s where time < '%s';",
oid_to_table(oid, aname), timstr);
int rc = mysql_query( m_env->con(), query);
if (rc) {
printf( "Delete old data: %s\n", mysql_error(m_env->con()));
*sts = SEV__DBERROR;
return 0;
}
*sts = SEV__SUCCESS;
return 1;
}
int sev_dbms::timestr_to_time( char *tstr, pwr_tTime *ts)
{
struct tm tt;
int nr = sscanf(tstr, "%4d-%02d-%20d %02d:%02d:%02d", &tt.tm_year,
&tt.tm_mon, &tt.tm_mday, &tt.tm_hour, &tt.tm_min, &tt.tm_sec);
if ( nr != 6) return 0;
tt.tm_year -= 1900;
tt.tm_mon--;
tt.tm_wday = -1;
tt.tm_yday = -1;
tt.tm_isdst = -1;
ts->tv_sec = mktime(&tt);
ts->tv_nsec = 0;
return 1;
}
char *sev_dbms::oid_to_table( pwr_tOid oid, char *aname)
{
static char tbl[40];
unsigned char vid[4];
memcpy( &vid, &oid.vid, sizeof(vid));
sprintf( tbl, "O%3.3u_%3.3u_%3.3u_%3.3u_%8.8x_%s",
vid[3], vid[2], vid[1], vid[0], oid.oix, cdh_Low(aname));
return tbl;
}
char *sev_dbms::pwrtype_to_type( pwr_eType type, unsigned int size)
{
static char stype[40];
switch ( type) {
case pwr_eType_Boolean:
strcpy( stype, "int unsigned");
break;
case pwr_eType_Int64:
strcpy( stype, "bigint");
break;
case pwr_eType_UInt64:
strcpy( stype, "bigint unsigned");
break;
case pwr_eType_Int32:
strcpy( stype, "int");
break;
case pwr_eType_UInt32:
strcpy( stype, "int unsigned");
break;
case pwr_eType_Int16:
strcpy( stype, "smallint");
break;
case pwr_eType_UInt16:
strcpy( stype, "smallint unsigned");
break;
case pwr_eType_Int8:
strcpy( stype, "tinyint");
break;
case pwr_eType_UInt8:
strcpy( stype, "tinyint unsigned");
break;
case pwr_eType_Float64:
strcpy( stype, "double");
break;
case pwr_eType_Float32:
strcpy( stype, "float");
break;
case pwr_eType_Char:
strcpy( stype, "char(1)");
break;
case pwr_eType_String:
sprintf( stype, "varchar(%d)", size);
break;
case pwr_eType_Time:
strcpy( stype, "datetime");
break;
default:
strcpy( stype, "");
}
return stype;
}
/*
* Proview $Id: sev_dbms.h,v 1.1 2008-07-17 11:18:31 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef sev_dbms_h
#define sev_dbms_h
#include <vector.h>
#include "pwr.h"
#include "pwr_class.h"
#include "sev_db.h"
#include <mysql/mysql.h>
class sev_dbms_env;
class sev_dbms_env
{
public:
MYSQL *m_con;
char *m_fileName;
static char m_systemName[40];
char *m_host;
char *m_user;
char *m_passwd;
char *m_dbName;
unsigned int m_port;
char *m_socket;
bool m_exists;
sev_dbms_env();
sev_dbms_env(const char *fileName);
sev_dbms_env(const char *host, const char *user, const char *passwd,
const char *dbName, unsigned int port, const char *socket);
sev_dbms_env(const sev_dbms_env &);
void operator = (const sev_dbms_env &);
virtual ~ sev_dbms_env() { close();}
int create(const char *fileName, const char *host, const char *user, const char *passwd,
const char *dbName, unsigned int port, const char *socket);
int open(void);
int open(const char *fileName);
int open(const char *host, const char *user, const char *passwd,
const char *dbName, unsigned int port, const char *socket);
MYSQL *createDb(void);
MYSQL *openDb(void);
bool exists() { return m_exists;}
int close(void);
static int get_systemname();
void fileName(const char *fileName);
void host(const char *host);
void user(const char *user);
void passwd(const char *passwd);
void dbName(const char *dbName);
void port(unsigned int port);
void socket(const char *socket);
static char *dbName(void);
inline char *fileName(void) { return m_fileName;}
char *host(void);
inline char *user(void) { return m_user;}
inline char *passwd(void) { return m_passwd;}
inline unsigned int port(void) { return m_port;}
inline char *socket(void) { return m_socket;}
inline MYSQL *con(void) {
return m_con;
}
private:
int create();
};
class sev_dbms : public sev_db {
public:
sev_dbms_env *m_env;
sev_dbms( sev_dbms_env *env) : m_env(env) {}
~sev_dbms() {}
int check_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, pwr_eType type, unsigned int size,
char *description, char *unit, pwr_tFloat32 scantime, unsigned int *idx);
int add_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, pwr_eType type, unsigned int size,
char *description, char *unit, pwr_tFloat32 scantime, unsigned int *idx);
int store_value( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eType type, pwr_tTime time,
void *buf, unsigned int size);
int get_values( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eType type, unsigned int size,
pwr_tFloat32 scantime, pwr_tTime *starttime, pwr_tTime *endtime,
int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize);
int delete_old_data( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_tTime limit);
int get_items( pwr_tStatus *sts);
int create_table( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eType type, unsigned int size);
int store_item( pwr_tStatus *sts, char *tabelname, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, pwr_eType vtype, unsigned int vsize,
char *description, char *unit, pwr_tFloat32 scantime);
char *oid_to_table( pwr_tOid oid, char *aname);
char *pwrtype_to_type( pwr_eType type, unsigned int size);
static int timestr_to_time( char *tstr, pwr_tTime *ts);
};
#endif
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