Commit c2d370df authored by Claes Sjofors's avatar Claes Sjofors

Merge branch 'master'

parents 0c561193 a238e41c
......@@ -420,6 +420,69 @@ int sev_server::send_itemlist(qcom_sQid tgt)
return 1;
}
int sev_server::send_eventsitemlist(qcom_sQid tgt)
{
int item_cnt = 0;
qcom_sPut put;
pwr_tStatus sts, lsts;
int size;
for (unsigned int i = 0; i < m_db->m_items.size(); i++) {
if (!m_db->m_items[i].deleted &&
strcmp(m_db->m_items[i].attr[0].aname, "Events") == 0 &&
m_db->m_items[i].attr[0].size == 0)
item_cnt++;
}
if (!item_cnt)
return 1;
size = sizeof(sev_sMsgEventsItems) + (item_cnt - 1) * sizeof(sev_sEventsItem);
put.size = size;
put.data = qcom_Alloc(&lsts, put.size);
put.allocate = 0;
((sev_sMsgEventsItems*)put.data)->Type = sev_eMsgType_EventsItems;
((sev_sMsgEventsItems*)put.data)->Version = sev_cNetVersion;
((sev_sMsgEventsItems*)put.data)->NumItems = item_cnt;
sev_sEventsItem* itemPtr = ((sev_sMsgEventsItems*)put.data)->Items;
for (unsigned int i = 0; i < m_db->m_items.size(); i++) {
if (!(!m_db->m_items[i].deleted &&
strcmp(m_db->m_items[i].attr[0].aname, "Events") == 0 &&
m_db->m_items[i].attr[0].size == 0))
continue;
itemPtr->oid = m_db->m_items[i].oid;
strcpy(itemPtr->oname, m_db->m_items[i].oname);
itemPtr->storagetime
= net_DeltaTimeToNetTime(&m_db->m_items[i].storagetime);
itemPtr->creatime = net_TimeToNetTime(&m_db->m_items[i].creatime);
strcpy(itemPtr->description, m_db->m_items[i].description);
itemPtr->options = m_db->m_items[i].options;
itemPtr++;
}
if (!item_cnt)
((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_EventsItems;
put.msg_id = m_msg_id++;
if (!qcom_Put(&sts, &tgt, &put)) {
qcom_Free(&sts, put.data);
return 0;
}
return 1;
}
int sev_server::send_server_status(qcom_sQid tgt)
{
qcom_sPut put;
......@@ -625,6 +688,14 @@ int sev_server::mainloop()
receive_events((sev_sMsgEventsStore*)mp, get.size, get.sender.nid);
m_stat.eventstore_msg_cnt++;
break;
case sev_eMsgType_EventsGetRequest:
send_events(get.reply, (sev_sMsgEventsGetRequest*)mp, get.size);
// m_stat.dataget_msg_cnt++;
// Don't free the message now
continue;
case sev_eMsgType_EventsItemsRequest:
send_eventsitemlist(get.reply);
break;
default:;
}
break;
......@@ -845,6 +916,8 @@ int sev_server::check_histitems(sev_sMsgHistItems* msg, unsigned int size)
} else {
// SevHistEvents item
storagetime = net_NetTimeToDeltaTime(&msg->Items[i].storagetime);
if (!m_db->check_item(&m_sts, msg->Items[i].oid, msg->Items[i].oname,
(char*)"Events", storagetime, (pwr_eType)0, 0,
msg->Items[i].description, (char*)"", msg->Items[i].scantime, 0,
......@@ -1192,6 +1265,118 @@ void* sev_server::send_objecthistdata_thread(void* arg)
return (void*)1;
}
int sev_server::send_events(
qcom_sQid tgt, sev_sMsgEventsGetRequest* rmsg, unsigned int size)
{
pthread_t thread;
pthread_attr_t attr;
int sts;
sev_sEventsThread* arg = (sev_sEventsThread*)malloc(sizeof(*arg));
arg->sev = this;
arg->tgt = tgt;
arg->rmsg = rmsg;
arg->size = size;
if (m_read_threads) {
static int pcnt = 0;
printf("New read thread %d\n", pcnt++);
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
sts = pthread_create(&thread, &attr, send_events_thread, arg);
if (sts != 0)
printf("pthread_create error %d\n", sts);
} else {
send_events_thread(arg);
}
return 1;
}
void* sev_server::send_events_thread(void* arg)
{
sev_sMsgEventsGet* msg;
int msize;
qcom_sPut put;
pwr_tStatus sts, lsts;
pwr_tTime starttime, endtime;
unsigned int item_idx;
void* thread = 0;
std::vector<sev_event> list;
sev_server* sev = ((sev_sEventsThread*)arg)->sev;
qcom_sQid tgt = ((sev_sEventsThread*)arg)->tgt;
sev_sMsgEventsGetRequest* rmsg = ((sev_sEventsThread*)arg)->rmsg;
free(arg);
starttime = net_NetTimeToTime(&rmsg->StartTime);
endtime = net_NetTimeToTime(&rmsg->EndTime);
sev->m_db->get_item_idx(&sts, &item_idx, rmsg->Oid, (char *)"Events");
if (EVEN(sts)) {
qcom_Free(&lsts, rmsg);
return (void*)1;
}
if (sev->m_read_threads)
thread = sev->m_db->new_thread();
sev->m_db->get_events(&sts, thread, rmsg->Oid,
sev->m_db->m_items[item_idx].options, rmsg->EventTypeMask,
rmsg->EventPrioMask, rmsg->EventText, rmsg->EventName,
&starttime, &endtime, rmsg->MaxEvents, list);
if (ODD(sts) && list.size() != 0)
msize = sizeof(*msg) + (list.size() - 1) * sizeof(sev_sEvents);
else
msize = sizeof(*msg);
put.reply.nid = sev->m_nodes[0].nid;
put.reply.qix = sev_eProcSevServer;
put.type.b = (qcom_eBtype)sev_cMsgClass;
put.type.s = (qcom_eStype)sev_eMsgType_EventsGet;
put.msg_id = sev->m_msg_id++;
put.size = msize;
msg = (sev_sMsgEventsGet*)qcom_Alloc(&lsts, put.size);
put.data = msg;
put.allocate = 0;
msg->Type = sev_eMsgType_EventsGet;
msg->Version = sev_cNetVersion;
msg->Oid = rmsg->Oid;
if (ODD(sts)) {
msg->NumEvents = list.size();
}
qcom_Free(&lsts, rmsg);
msg->Status = sts;
if (ODD(sts) && list.size()) {
sev_sEvents *mp = msg->Events;
for (int i = 0; i < list.size(); i++) {
mp->Time = net_TimeToNetTime(&list[i].time);
mp->EventType = list[i].type;
mp->EventPrio = list[i].eventprio;
mp->SupObjectOid = list[i].supobject.Objid;
mp->SupObjectOffset = list[i].supobject.Offset;
mp->SupObjectSize = list[i].supobject.Size;
strncpy(mp->EventText, list[i].eventtext, sizeof(mp->EventText));
strncpy(mp->EventName, list[i].eventname, sizeof(mp->EventName));
mp->EventId = list[i].eventid;
mp++;
}
}
if (!qcom_Put(&sts, &tgt, &put)) {
qcom_Free(&sts, put.data);
}
if (sev->m_read_threads)
sev->m_db->delete_thread(thread);
pthread_exit( (void *) 1);
return (void*)1;
}
int sev_server::receive_events(
sev_sMsgEventsStore* msg, unsigned int size, pwr_tNodeId nid)
{
......
......@@ -65,6 +65,14 @@ typedef struct {
unsigned int item_idx;
} sev_sHistDataThread;
typedef struct {
sev_server* sev;
qcom_sQid tgt;
sev_sMsgEventsGetRequest* rmsg;
unsigned int size;
unsigned int item_idx;
} sev_sEventsThread;
typedef struct {
int key;
pthread_t thread;
......@@ -148,7 +156,10 @@ public:
int send_objecthistdata(
qcom_sQid tgt, sev_sMsgHistDataGetRequest* rmsg, unsigned int size);
static void* send_objecthistdata_thread(void* arg);
int send_events(qcom_sQid tgt, sev_sMsgEventsGetRequest* rmsg, unsigned int size);
static void* send_events_thread(void* arg);
int send_itemlist(qcom_sQid tgt);
int send_eventsitemlist(qcom_sQid tgt);
int send_server_status(qcom_sQid tgt);
int delete_item(qcom_sQid tgt, sev_sMsgHistItemDelete* rmsg);
int receive_events(
......
......@@ -224,6 +224,11 @@ public:
pwr_tTime** tbuf, void** vbuf, unsigned int* bsize);
virtual int handle_objectchange(
pwr_tStatus* sts, char* tablename, unsigned int item_idx, bool newObject);
virtual int get_events(pwr_tStatus *sts, void *thread, pwr_tOid,
pwr_tMask options, pwr_tMask eventtypemask,
pwr_tMask eventpriomask, char *eventtext, char *eventname,
pwr_tTime *starttime, pwr_tTime *endtime, unsigned int numpoints,
std::vector<sev_event> &list) {return 0;}
virtual int repair_table(pwr_tStatus* sts, char* tablename);
virtual int alter_engine(pwr_tStatus* sts, char* tablename);
virtual int optimize(pwr_tStatus* sts, char* tablename);
......
......@@ -4716,6 +4716,342 @@ int sev_dbms::handle_objectchange(
return 1;
}
int sev_dbms::get_events(pwr_tStatus *sts, void *thread, pwr_tOid oid,
pwr_tMask options, pwr_tMask eventtypemask,
pwr_tMask eventpriomask, char *eventtext, char *eventname,
pwr_tTime *starttime, pwr_tTime *endtime, unsigned int numevents,
std::vector<sev_event> &list)
{
sev_item item;
get_item(sts, thread, &item, oid, (char *)"Events");
if (EVEN(*sts)) {
return 0;
}
char query[700];
char starttimstr[40];
char endtimstr[40];
pwr_tTime stime, etime;
char column_part[200];
char orderby_part[80];
char limit_part[80];
char where_part[600];
int rows = 0;
MYSQL* con;
if (thread)
con = (MYSQL*)thread;
else
con = m_env->con();
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';", item.tablename);
int rc = mysql_query(con, query);
if (rc) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf("GetEvents Query Error\n");
*sts = SEV__DBERROR;
return 0;
}
MYSQL_ROW row;
MYSQL_RES* result = mysql_store_result(con);
if (!result) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf("GetValues Status Result Error\n");
*sts = SEV__DBERROR;
return 0;
}
row = mysql_fetch_row(result);
if (!row) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf("GetValues Status Result Error\n");
*sts = SEV__DBERROR;
return 0;
}
mysql_free_result(result);
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;
}
// Column part
if (options & pwr_mSevOptionsMask_HighTimeResolution)
strcpy(column_part, "time,ntime,eventtype,eventprio,eventid_nix,eventid_birthtime,"
"eventid_idx,supobject_vid,supobject_oix,supobject_offset,supobject_size,eventtext,"
"eventname");
else
strcpy(column_part, "time,eventtype,eventprio,eventid_nix,eventid_birthtime,"
"eventid_idx,supobject_vid,supobject_oix,supobject_offset,supobject_size,eventtext,"
"eventname");
// 'order by' part
if (options & pwr_mSevOptionsMask_HighTimeResolution)
strcpy(orderby_part, "time,ntime");
else
strcpy(orderby_part, "time");
// 'where' part
// Not read optimized
if (starttime && endtime) {
if (options & pwr_mSevOptionsMask_PosixTime)
sprintf(where_part, "where time >= %ld and time <= %ld",
(long int)starttime->tv_sec, (long int)endtime->tv_sec);
else
sprintf(where_part, "where time >= '%s' and time <= '%s'",
starttimstr, endtimstr);
} else if (starttime) {
if (options & pwr_mSevOptionsMask_PosixTime)
sprintf(where_part, "where time >= %ld", (long int)starttime->tv_sec);
else
sprintf(where_part, "where time >= '%s'", starttimstr);
} else if (endtime) {
if (options & pwr_mSevOptionsMask_PosixTime)
sprintf(where_part, "where time <= %ld", (long int)endtime->tv_sec);
else
sprintf(where_part, "where time <= '%s'", endtimstr);
} else
strcpy(where_part, "");
if (eventtypemask) {
bool first = true;
sprintf(&where_part[strlen(where_part)], " and (");
if (eventtypemask & sev_mEventType_Ack) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_Ack);
first = false;
}
if (eventtypemask & sev_mEventType_Block) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_Block);
first = false;
}
if (eventtypemask & sev_mEventType_Cancel) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_Cancel);
first = false;
}
if (eventtypemask & sev_mEventType_CancelBlock) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_CancelBlock);
first = false;
}
if (eventtypemask & sev_mEventType_Missing) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_Missing);
first = false;
}
if (eventtypemask & sev_mEventType_Reblock) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_Reblock);
first = false;
}
if (eventtypemask & sev_mEventType_Return) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_Return);
first = false;
}
if (eventtypemask & sev_mEventType_Unblock) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_Unblock);
first = false;
}
if (eventtypemask & sev_mEventType_InfoSuccess) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_InfoSuccess);
first = false;
}
if (eventtypemask & sev_mEventType_Alarm) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_Alarm);
first = false;
}
if (eventtypemask & sev_mEventType_MaintenanceAlarm) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_MaintenanceAlarm);
first = false;
}
if (eventtypemask & sev_mEventType_SystemAlarm) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_SystemAlarm);
first = false;
}
if (eventtypemask & sev_mEventType_UserAlarm1) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_UserAlarm1);
first = false;
}
if (eventtypemask & sev_mEventType_UserAlarm2) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_UserAlarm2);
first = false;
}
if (eventtypemask & sev_mEventType_UserAlarm3) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_UserAlarm3);
first = false;
}
if (eventtypemask & sev_mEventType_UserAlarm4) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_UserAlarm4);
first = false;
}
if (eventtypemask & sev_mEventType_Info) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventtype = %d", mh_eEvent_Info);
first = false;
}
sprintf(&where_part[strlen(where_part)], ")");
}
if (eventpriomask) {
bool first = true;
sprintf(&where_part[strlen(where_part)], " and (");
if (eventpriomask & sev_mEventPrio_A) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventprio = %d", mh_eEventPrio_A);
first = false;
}
if (eventpriomask & sev_mEventPrio_B) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventprio = %d", mh_eEventPrio_B);
first = false;
}
if (eventpriomask & sev_mEventPrio_C) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventprio = %d", mh_eEventPrio_C);
first = false;
}
if (eventpriomask & sev_mEventPrio_D) {
if (!first)
sprintf(&where_part[strlen(where_part)], " or ");
sprintf(&where_part[strlen(where_part)], "eventprio = %d", mh_eEventPrio_C);
first = false;
}
sprintf(&where_part[strlen(where_part)], ")");
}
if (!streq(eventtext, ""))
sprintf(&where_part[strlen(where_part)], " and eventtext regexp '%s'", eventtext);
if (!streq(eventname, ""))
sprintf(&where_part[strlen(where_part)], " and eventname regexp '%s'", eventname);
if (numevents)
sprintf(limit_part, "limit %d", numevents);
else
strcpy(limit_part, "");
sprintf(query, "select %s from %s %s order by %s %s", column_part,
item.tablename, where_part, orderby_part, limit_part);
printf("Query: %s\n", query);
rc = mysql_query(con, query);
if (rc) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf("Get Events: %s\n", mysql_error(con));
*sts = SEV__DBERROR;
return 0;
}
result = mysql_store_result(con);
if (!result) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf("GetEvents Result Error\n");
*sts = SEV__DBERROR;
return 0;
}
rows = mysql_num_rows(result);
for (int i = 0; i < rows; i++) {
sev_event e;
int j = 0;
row = mysql_fetch_row(result);
if (!row)
break;
if (options & pwr_mSevOptionsMask_PosixTime) {
if (options & pwr_mSevOptionsMask_HighTimeResolution) {
// Posix time, high resolution
e.time.tv_sec = strtoul(row[j++], 0, 10);
e.time.tv_nsec = strtoul(row[j++], 0, 10);
} else
// Posix time, low resolution
e.time.tv_sec = strtoul(row[j++], 0, 10);
} else {
if (options & pwr_mSevOptionsMask_HighTimeResolution) {
// Sql time, high resolution
timestr_to_time(row[j++], &e.time);
e.time.tv_nsec = strtoul(row[j++], 0, 10);
} else
// Sql time, low resolution
timestr_to_time(row[j++], &e.time);
}
e.type = strtoul(row[j++], 0, 10);
e.eventprio = strtoul(row[j++], 0, 10);
e.eventid.Nix = strtoul(row[j++], 0, 10);
e.eventid.BirthTime.tv_sec = strtoul(row[j++], 0, 10);
e.eventid.Idx = strtoul(row[j++], 0, 10);
e.supobject.Objid.vid = strtoul(row[j++], 0, 10);
e.supobject.Objid.oix = strtoul(row[j++], 0, 10);
e.supobject.Offset = strtoul(row[j++], 0, 10);
e.supobject.Size = strtoul(row[j++], 0, 10);
strncpy(e.eventtext, row[j++], sizeof(e.eventtext));
strncpy(e.eventname, row[j++], sizeof(e.eventname));
list.push_back(e);
}
printf("ecnt %d\n", list.size());
mysql_free_result(result);
*sts = SEV__SUCCESS;
return 1;
}
int sev_dbms::repair_table(pwr_tStatus* sts, char* tablename)
{
char query[200];
......
......@@ -205,6 +205,11 @@ public:
pwr_tStatus* sts, char* tablename, unsigned int item_idx);
int handle_objectchange(
pwr_tStatus* sts, char* tablename, unsigned int item_idx, bool newObject);
int get_events(pwr_tStatus *sts, void *thread, pwr_tOid,
pwr_tMask options, pwr_tMask eventtypemask,
pwr_tMask eventpriomask, char *eventtext, char *eventname,
pwr_tTime *starttime, pwr_tTime *endtime, unsigned int numpoints,
std::vector<sev_event> &list);
int repair_table(pwr_tStatus* sts, char* tablename);
int alter_engine(pwr_tStatus* sts, char* tablename);
int optimize(pwr_tStatus* sts, char* tablename);
......
......@@ -1215,8 +1215,7 @@ static void sendAlarmStatus(sOutunit* op)
if (ep && !(ep->msg.info.EventFlags & mh_mEventFlags_InfoWindow))
break;
if (ep && ep->msg.info.EventFlags & mh_mEventFlags_InfoWindow
&& (!(ep->msg.info.EventFlags & mh_mEventFlags_Ack)
|| !(ep->msg.info.EventFlags & mh_mEventFlags_Return)))
&& !(ep->msg.info.EventFlags & mh_mEventFlags_Ack))
break;
}
......@@ -1263,8 +1262,7 @@ static void sendAlarmStatus(sOutunit* op)
if (ep && !(ep->msg.info.EventFlags & mh_mEventFlags_InfoWindow))
break;
if (ep && ep->msg.info.EventFlags & mh_mEventFlags_InfoWindow
&& (!(ep->msg.info.EventFlags & mh_mEventFlags_Ack)
|| !(ep->msg.info.EventFlags & mh_mEventFlags_Return)))
&& !(ep->msg.info.EventFlags & mh_mEventFlags_Ack))
break;
}
......
......@@ -1480,7 +1480,7 @@ pwr_tStatus rt_sevhistmon::mh_ack_bc(mh_sAck* msg)
{
sev_sEvent ed;
ed.type = sev_eEventType_Ack;
ed.type = msg->Info.EventType;
ed.time = msg->Info.EventTime;
strcpy(ed.eventtext, "");
strncpy(ed.eventname, msg->EventName, sizeof(ed.eventname));
......@@ -1502,7 +1502,7 @@ pwr_tStatus rt_sevhistmon::mh_return_bc(mh_sReturn* msg)
{
sev_sEvent ed;
ed.type = sev_eEventType_Return;
ed.type = msg->Info.EventType;
ed.time = msg->Info.EventTime;
strncpy(ed.eventtext, msg->EventText, sizeof(ed.eventtext));
strncpy(ed.eventname, msg->EventName, sizeof(ed.eventname));
......@@ -1525,7 +1525,7 @@ pwr_tStatus rt_sevhistmon::mh_alarm_bc(mh_sMessage* msg)
{
sev_sEvent ed;
ed.type = sev_eEventType_Alarm;
ed.type = msg->Info.EventType;
ed.time = msg->Info.EventTime;
strncpy(ed.eventtext, msg->EventText, sizeof(ed.eventtext));
strncpy(ed.eventname, msg->EventName, sizeof(ed.eventname));
......@@ -1548,7 +1548,7 @@ pwr_tStatus rt_sevhistmon::mh_block_bc(mh_sBlock* msg)
{
sev_sEvent ed;
ed.type = sev_eEventType_Block;
ed.type = msg->Info.EventType;
ed.time = msg->Info.EventTime;
strcpy(ed.eventtext, "");
strncpy(ed.eventname, msg->EventName, sizeof(ed.eventname));
......@@ -1571,7 +1571,7 @@ pwr_tStatus rt_sevhistmon::mh_cancel_bc(mh_sReturn* msg)
{
sev_sEvent ed;
ed.type = sev_eEventType_Cancel;
ed.type = msg->Info.EventType;
ed.time = msg->Info.EventTime;
strcpy(ed.eventtext, "");
strncpy(ed.eventname, msg->EventName, sizeof(ed.eventname));
......@@ -1594,7 +1594,7 @@ pwr_tStatus rt_sevhistmon::mh_info_bc(mh_sMessage* msg)
{
sev_sEvent ed;
ed.type = sev_eEventType_Info;
ed.type = msg->Info.EventType;
ed.time = msg->Info.EventTime;
strncpy(ed.eventtext, msg->EventText, sizeof(ed.eventtext));
strncpy(ed.eventname, msg->EventName, sizeof(ed.eventname));
......
......@@ -36,7 +36,7 @@ $(pwrp_obj)/%.o : %.c
($(pwrp_obj)/%.o) : %.c
@ echo "cc ar $(notdir $(source))"
@ $(cc) $(cflags) $(csetos) $(cinc) -c -o $% $(source)
@ ar r $(target) $%
@ ar -Ur $(target) $%
$(pwrp_obj)/%.o : %.cpp
@ echo "cc $(notdir $(source))"
......@@ -45,7 +45,7 @@ $(pwrp_obj)/%.o : %.cpp
($(pwrp_obj)/%.o) : %.cpp
@ echo "cc ar $(notdir $(source))"
@ $(cxx) $(cxxflags) $(csetos) $(cinc) -c -o $% $(source)
@ ar r $(target) $%
@ ar -Ur $(target) $%
$(pwrp_obj)/%.o : %.for
@ echo "fortran77 $(notdir $(source))"
......@@ -54,7 +54,7 @@ $(pwrp_obj)/%.o : %.for
($(pwrp_obj)/%.o) : %.for
@ echo "fortran77 ar $(notdir $(source))"
@ $(f77) $(f77flags) $(f77inc) -c -o $% $(source)
@ ar r $(target) $%
@ ar -Ur $(target) $%
$(pwrp_inc)/%.h: %.msg
@ echo "Msg to h $(source)"
......
......@@ -3370,6 +3370,68 @@ static PyObject *pwrrt_getSevItemList(PyObject *self, PyObject *args)
return result;
}
static PyObject *pwrrt_getSevEventsItemList(PyObject *self, PyObject *args)
{
char *server;
char *filter = 0;
pwr_tStatus sts;
sevcli_sEventsItem *itemlist;
unsigned int itemcnt;
int cnt;
int i;
PyObject *ituple, *result;
if ( !pwrrt_scctx) {
sevcli_init( &sts, &pwrrt_scctx);
if ( EVEN(sts))
return set_error(sts);
}
if ( !PyArg_ParseTuple(args, "s|si", &server, &filter))
return NULL;
sevcli_set_servernode( &sts, pwrrt_scctx, server);
if ( EVEN(sts))
return set_error(sts);
sevcli_get_eventsitemlist( &sts, pwrrt_scctx, &itemlist, &itemcnt);
if (EVEN(sts))
return set_error(sts);
if ( filter && strcmp(filter,"") == 0)
filter = 0;
cnt = 0;
if ( filter) {
for ( i = 0; i < itemcnt; i++) {
if ( str_NoCaseStrncmp(filter, itemlist[i].oname, strlen(filter)) == 0)
cnt++;
}
}
else
cnt = itemcnt;
result = PyTuple_New(cnt);
cnt = 0;
for ( i = 0; i < itemcnt; i++) {
if ( !filter || str_NoCaseStrncmp(filter, itemlist[i].oname, strlen(filter)) == 0) {
ituple = PyTuple_New(4);
PyTuple_SetItem(ituple, 0, PyString_FromString(itemlist[i].oname));
PyTuple_SetItem(ituple, 1, PyString_FromString(cdh_ObjidToString(itemlist[i].oid, 1)));
PyTuple_SetItem(ituple, 2, PyString_FromString(itemlist[i].description));
PyTuple_SetItem(ituple, 3, PyLong_FromUnsignedLong(itemlist[i].options));
PyTuple_SetItem(result, cnt, ituple);
cnt++;
}
}
free(itemlist);
return result;
}
static PyObject *pwrrt_getSevItemData(PyObject *self, PyObject *args)
{
pwr_tStatus sts;
......@@ -3653,9 +3715,9 @@ static PyObject *pwrrt_getSevItemsDataFrame(PyObject *self, PyObject *args)
/* Find longest continuous interval where condition is high */
pwr_tBoolean last_value = 0;
pwr_tFloat32 max_time = 0.0f;
int last_idx;
int start_idx;
int end_idx;
int last_idx = 0;
int start_idx = 0;
int end_idx = 0;
for (i = 0; i < rows; i++) {
if (((pwr_tBoolean *)vbuf)[i] == 1 && last_value == 0) {
last_value = 1;
......@@ -3838,7 +3900,7 @@ static PyObject *pwrrt_getSevItemsDataFrameD(PyObject *self, PyObject *args)
pwr_tDeltaTime fromdelta;
float tdiff;
pwr_tOid oid;
pwr_tTime *ttbuf, *tt0buf;
pwr_tTime *ttbuf, *tt0buf = 0;
PyObject *oidobj, *anameobj, *isobjectobj;
pwr_tFloat32 *vbuf;
int maxrows = 0;
......@@ -3851,10 +3913,10 @@ static PyObject *pwrrt_getSevItemsDataFrameD(PyObject *self, PyObject *args)
time_t sec;
struct tm ts;
char *time_format = 0;
int valcnt;
int valcnt = 0;
pwr_tDeltaTime dt;
pwr_tFloat32 **vvect;
float *tbuf, *t0buf;
float *tbuf, *t0buf = 0;
if ( !pwrrt_scctx) {
sevcli_init( &sts, &pwrrt_scctx);
......@@ -4130,6 +4192,280 @@ static PyObject *pwrrt_getSevItemsDataFrameD(PyObject *self, PyObject *args)
return result;
}
static PyObject *pwrrt_getSevEvents(PyObject *self, PyObject *args)
{
pwr_tStatus sts;
char *server, *oidstr, *fromstr, *tostr, *eventtext, *eventname;
unsigned int eventtypemask, eventpriomask;
pwr_tTime from, to;
pwr_tDeltaTime fromdelta;
pwr_tOid oid;
int maxrows = 0;
sevcli_sEvents *list;
unsigned int listcnt;
PyObject *item_tuple, *eventid_tuple, *result;
char timstr[30];
int i;
PyObject *date;
time_t sec;
struct tm ts;
char *time_format = 0;
int time_string = 0;
char supobject[80];
if ( !pwrrt_scctx) {
sevcli_init( &sts, &pwrrt_scctx);
if ( EVEN(sts))
return set_error(sts);
}
if ( !PyArg_ParseTuple(args, "ssssIIss|Is", &server, &oidstr, &fromstr, &tostr, &eventtypemask,
&eventpriomask, &eventtext, &eventname, &maxrows,
&time_format))
return NULL;
if ( time_format) {
if ( strcmp(time_format, "string") == 0)
time_string = 1;
}
if ( maxrows == 0)
maxrows = 1000;
sevcli_set_servernode( &sts, pwrrt_scctx, server);
if ( EVEN(sts))
return set_error(sts);
if ( strncmp("_O", oidstr, 2) == 0)
sts = cdh_StringToObjid( oidstr, &oid);
else
sts = gdh_NameToObjid( oidstr, &oid);
if ( EVEN(sts))
return set_error(sts);
if ( strcmp(tostr, "now") == 0) {
/* fromstr is a deltatime */
sts = time_AsciiToD(fromstr, &fromdelta);
if ( EVEN(sts))
return set_error(sts);
time_GetTime(&to);
time_Asub(&from, &to, &fromdelta);
}
else {
sts = time_AsciiToA(fromstr, &from);
if ( EVEN(sts))
return set_error(sts);
sts = time_AsciiToA(tostr, &to);
if ( EVEN(sts))
return set_error(sts);
}
sevcli_get_events( &sts, pwrrt_scctx, oid, from, to, eventtypemask, eventpriomask,
eventtext, eventname, maxrows, &list, &listcnt);
if ( sts == SEV__NOPOINTS)
Py_RETURN_NONE;
else if (EVEN(sts))
return set_error(sts);
result = PyTuple_New(listcnt);
for ( i = 0; i < listcnt; i++) {
item_tuple = PyTuple_New(7);
eventid_tuple = PyTuple_New(2);
if ( time_string) {
/* Time string */
time_AtoAscii( &list[i].Time, time_eFormat_DateAndTime, timstr, sizeof(timstr));
PyTuple_SetItem(item_tuple, 0, PyString_FromString(timstr));
}
else {
/* Time datetime object */
sec = (time_t)list[i].Time.tv_sec;
localtime_r(&sec, &ts);
date = PyDateTime_FromDateAndTime(ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday,
ts.tm_hour, ts.tm_min, ts.tm_sec,
(int)list[i].Time.tv_nsec/1000);
PyTuple_SetItem(item_tuple, 0, date);
}
PyTuple_SetItem(item_tuple, 1, PyInt_FromLong((long)list[i].EventType));
PyTuple_SetItem(item_tuple, 2, PyInt_FromLong((long)list[i].EventPrio));
PyTuple_SetItem(item_tuple, 3, PyString_FromString(list[i].EventText));
PyTuple_SetItem(item_tuple, 4, PyString_FromString(list[i].EventName));
strcpy(supobject, cdh_ObjidToString(list[i].SupObjectOid, 1));
if (list[i].SupObjectOffset > 0)
sprintf(&supobject[strlen(supobject)], "#%d:%d", list[i].SupObjectOffset, list[i].SupObjectSize);
PyTuple_SetItem(item_tuple, 5, PyString_FromString(supobject));
PyTuple_SetItem(eventid_tuple, 0, PyInt_FromLong((long)list[i].EventId.Nix));
PyTuple_SetItem(eventid_tuple, 1, PyInt_FromLong((long)list[i].EventId.Idx));
PyTuple_SetItem(item_tuple, 6, eventid_tuple);
PyTuple_SetItem(result, i, item_tuple);
}
free(list);
return result;
}
static PyObject *pwrrt_getSevEventsDataFrame(PyObject *self, PyObject *args)
{
pwr_tStatus sts;
char *server, *oidstr, *fromstr, *tostr, *eventtext, *eventname;
unsigned int eventtypemask, eventpriomask;
pwr_tTime from, to;
pwr_tDeltaTime fromdelta;
pwr_tOid oid;
int maxrows = 0;
sevcli_sEvents *list;
unsigned int listcnt;
PyObject *item_tuple, *eventid_tuple, *result;
char timstr[30];
int i;
PyObject *date;
time_t sec;
struct tm ts;
char *time_format = 0;
int time_string = 0;
char supobject[80];
if ( !pwrrt_scctx) {
sevcli_init( &sts, &pwrrt_scctx);
if ( EVEN(sts))
return set_error(sts);
}
if ( !PyArg_ParseTuple(args, "ssssIIss|Is", &server, &oidstr, &fromstr, &tostr, &eventtypemask,
&eventpriomask, &eventtext, &eventname, &maxrows,
&time_format))
return NULL;
if ( time_format) {
if ( strcmp(time_format, "string") == 0)
time_string = 1;
}
if ( maxrows == 0)
maxrows = 1000;
sevcli_set_servernode( &sts, pwrrt_scctx, server);
if ( EVEN(sts))
return set_error(sts);
if ( strncmp("_O", oidstr, 2) == 0)
sts = cdh_StringToObjid( oidstr, &oid);
else
sts = gdh_NameToObjid( oidstr, &oid);
if ( EVEN(sts))
return set_error(sts);
if ( strcmp(tostr, "now") == 0) {
/* fromstr is a deltatime */
sts = time_AsciiToD(fromstr, &fromdelta);
if ( EVEN(sts))
return set_error(sts);
time_GetTime(&to);
time_Asub(&from, &to, &fromdelta);
}
else {
sts = time_AsciiToA(fromstr, &from);
if ( EVEN(sts))
return set_error(sts);
sts = time_AsciiToA(tostr, &to);
if ( EVEN(sts))
return set_error(sts);
}
sevcli_get_events( &sts, pwrrt_scctx, oid, from, to, eventtypemask, eventpriomask,
eventtext, eventname, maxrows, &list, &listcnt);
if ( sts == SEV__NOPOINTS)
Py_RETURN_NONE;
else if (EVEN(sts))
return set_error(sts);
result = PyList_New(listcnt);
for ( i = 0; i < listcnt; i++) {
item_tuple = PyTuple_New(7);
eventid_tuple = PyTuple_New(2);
if ( time_string) {
/* Time string */
time_AtoAscii( &list[i].Time, time_eFormat_DateAndTime, timstr, sizeof(timstr));
PyTuple_SetItem(item_tuple, 0, PyString_FromString(timstr));
}
else {
/* Time datetime object */
sec = (time_t)list[i].Time.tv_sec;
localtime_r(&sec, &ts);
date = PyDateTime_FromDateAndTime(ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday,
ts.tm_hour, ts.tm_min, ts.tm_sec,
(int)list[i].Time.tv_nsec/1000);
PyTuple_SetItem(item_tuple, 0, date);
}
PyTuple_SetItem(item_tuple, 1, PyInt_FromLong((long)list[i].EventType));
PyTuple_SetItem(item_tuple, 2, PyInt_FromLong((long)list[i].EventPrio));
PyTuple_SetItem(item_tuple, 3, PyString_FromString(list[i].EventText));
PyTuple_SetItem(item_tuple, 4, PyString_FromString(list[i].EventName));
strcpy(supobject, cdh_ObjidToString(list[i].SupObjectOid, 1));
if (list[i].SupObjectOffset > 0)
sprintf(&supobject[strlen(supobject)], "#%d:%d", list[i].SupObjectOffset, list[i].SupObjectSize);
PyTuple_SetItem(item_tuple, 5, PyString_FromString(supobject));
PyTuple_SetItem(eventid_tuple, 0, PyInt_FromLong((long)list[i].EventId.Nix));
PyTuple_SetItem(eventid_tuple, 1, PyInt_FromLong((long)list[i].EventId.Idx));
PyTuple_SetItem(item_tuple, 6, eventid_tuple);
PyList_SetItem(result, i, item_tuple);
}
#if 0
result = PyList_New(7);
time_tuple = PyTuple_New(listcnt);
eventtype_tuple = PyTuple_New(listcnt);
eventprio_tuple = PyTuple_New(listcnt);
eventtext_tuple = PyTuple_New(listcnt);
eventname_tuple = PyTuple_New(listcnt);
supobject_tuple = PyTuple_New(listcnt);
eventid_tuple = PyTuple_New(listcnt);
for ( i = 0; i < listcnt; i++) {
if ( time_string) {
/* Time string */
time_AtoAscii( &list[i].Time, time_eFormat_DateAndTime, timstr, sizeof(timstr));
PyTuple_SetItem(time_tuple, i, PyString_FromString(timstr));
}
else {
/* Time datetime object */
sec = (time_t)list[i].Time.tv_sec;
localtime_r(&sec, &ts);
date = PyDateTime_FromDateAndTime(ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday,
ts.tm_hour, ts.tm_min, ts.tm_sec,
(int)list[i].Time.tv_nsec/1000);
PyTuple_SetItem(time_tuple, i, date);
}
PyTuple_SetItem(eventtype_tuple, i, PyInt_FromLong((long)list[i].EventType));
PyTuple_SetItem(eventprio_tuple, i, PyInt_FromLong((long)list[i].EventPrio));
PyTuple_SetItem(eventtext_tuple, i, PyString_FromString(list[i].EventText));
PyTuple_SetItem(eventname_tuple, i, PyString_FromString(list[i].EventName));
strcpy(supobject, cdh_ObjidToString(list[i].SupObjectOid, 1));
if (list[i].SupObjectOffset > 0)
sprintf(&supobject[strlen(supobject)], "#%d:%d", list[i].SupObjectOffset, list[i].SupObjectSize);
PyTuple_SetItem(supobject_tuple, i, PyString_FromString(supobject));
PyTuple_SetItem(eventid_tuple, i, PyInt_FromLong((long)list[i].EventId.Idx));
}
PyList_SetItem(result, 0, time_tuple);
PyList_SetItem(result, 1, eventtype_tuple);
PyList_SetItem(result, 2, eventprio_tuple);
PyList_SetItem(result, 3, eventtext_tuple);
PyList_SetItem(result, 4, eventname_tuple);
PyList_SetItem(result, 5, supobject_tuple);
PyList_SetItem(result, 6, eventid_tuple);
#endif
free(list);
return result;
}
static PyMethodDef PwrrtMethods[] = {
{"volume", pwrrt_volume, METH_VARARGS, pwrrt_volume_doc},
......@@ -4143,9 +4479,12 @@ static PyMethodDef PwrrtMethods[] = {
{"getPriv", pwrrt_getPriv, METH_NOARGS, pwrrt_getPriv_doc},
{"getUser", pwrrt_getUser, METH_NOARGS, pwrrt_getUser_doc},
{"getSevItemList", pwrrt_getSevItemList, METH_VARARGS, "Get history item list"},
{"getSevEventsItemList", pwrrt_getSevEventsItemList, METH_VARARGS, "Get events history item list"},
{"getSevItemData", pwrrt_getSevItemData, METH_VARARGS, "Get history data"},
{"getSevItemsDataFrame", pwrrt_getSevItemsDataFrame, METH_VARARGS, "Get history data frame"},
{"getSevItemsDataFrameD", pwrrt_getSevItemsDataFrameD, METH_VARARGS, "Get history data frame discrete"},
{"getSevEvents", pwrrt_getSevEvents, METH_VARARGS, "Get history events"},
{"getSevEventsDataFrame", pwrrt_getSevEventsDataFrame, METH_VARARGS, "Get history events data frame"},
{NULL, NULL, 0, NULL}};
PyMODINIT_FUNC initpwrrt(void)
......
......@@ -191,7 +191,13 @@ int rtt_alarm_send(char* alarm_text, int alarm_prio)
break;
case 'I':
mh_msg.EventType = mh_eEvent_Info;
mh_msg.EventFlags = mh_mEventFlags_InfoWindow;
mh_msg.EventFlags |= mh_mEventFlags_InfoWindow;
mh_msg.EventFlags |= mh_mEventFlags_Ack;
break;
case 'S':
mh_msg.EventType = mh_eEvent_InfoSuccess;
mh_msg.EventFlags |= mh_mEventFlags_InfoWindow;
mh_msg.EventFlags |= mh_mEventFlags_Ack;
break;
default:
mh_msg.EventPrio = mh_eEventPrio_A;
......
......@@ -67,7 +67,11 @@ typedef enum {
sev_eMsgType_ExportNodeUp,
sev_eMsgType_ExportItemsRequest,
sev_eMsgType_ExportItems,
sev_eMsgType_ExportData
sev_eMsgType_ExportData,
sev_eMsgType_EventsItemsRequest,
sev_eMsgType_EventsItems,
sev_eMsgType_EventsGetRequest,
sev_eMsgType_EventsGet
} sev_eMsgType;
typedef enum {
......@@ -79,8 +83,35 @@ typedef enum {
sev_eEventType_Cancel
} sev_eEventType;
typedef enum {
sev_mEventType_Ack = 1,
sev_mEventType_Block = 2,
sev_mEventType_Cancel = 4,
sev_mEventType_CancelBlock = 8,
sev_mEventType_Missing = 16,
sev_mEventType_Reblock = 32,
sev_mEventType_Return = 64,
sev_mEventType_Unblock = 128,
sev_mEventType_InfoSuccess = 256,
sev_mEventType_Alarm = 512,
sev_mEventType_MaintenanceAlarm = 1024,
sev_mEventType_SystemAlarm = 2048,
sev_mEventType_UserAlarm1 = 4096,
sev_mEventType_UserAlarm2 = 8192,
sev_mEventType_UserAlarm3 = 16384,
sev_mEventType_UserAlarm4 = 32768,
sev_mEventType_Info = 65536
} sev_mEventType;
typedef enum {
sev_mEventPrio_A = 1,
sev_mEventPrio_B = 2,
sev_mEventPrio_C = 4,
sev_mEventPrio_D = 8
} sev_mEventPrio;
typedef struct {
sev_eEventType type;
unsigned int type;
unsigned int eventprio;
unsigned int eventid_nix;
unsigned int eventid_birthtime;
......@@ -273,6 +304,57 @@ typedef struct {
sev_sExportItem Items[1];
} sev_sMsgExportItems;
typedef struct {
pwr_tOid oid;
pwr_tOName oname;
net_sTime storagetime;
net_sTime creatime;
pwr_tString80 description;
pwr_tMask options;
} sev_sEventsItem;
typedef struct {
pwr_tUInt16 Type;
pwr_tUInt16 Version;
pwr_tStatus Status;
unsigned int NumItems;
sev_sEventsItem Items[1];
} sev_sMsgEventsItems;
typedef struct {
pwr_tUInt16 Type;
pwr_tUInt16 Version;
pwr_tOid Oid;
net_sTime StartTime;
net_sTime EndTime;
pwr_tUInt32 EventTypeMask;
pwr_tUInt32 EventPrioMask;
pwr_tString80 EventText;
pwr_tOName EventName;
pwr_tUInt32 MaxEvents;
} sev_sMsgEventsGetRequest;
typedef struct {
net_sTime Time;
pwr_tUInt32 EventType;
pwr_tUInt32 EventPrio;
pwr_tOid SupObjectOid;
pwr_tUInt32 SupObjectOffset;
pwr_tUInt32 SupObjectSize;
pwr_tString80 EventText;
pwr_tOName EventName;
mh_sEventId EventId;
} sev_sEvents;
typedef struct {
pwr_tUInt16 Type;
pwr_tUInt16 Version;
pwr_tOid Oid;
pwr_tStatus Status;
int NumEvents;
sev_sEvents Events[1];
} sev_sMsgEventsGet;
#ifdef __cplusplus
}
......
......@@ -639,3 +639,225 @@ int sevcli_delete_item(
qcom_Free(sts, rmsg);
return 1;
}
/**
* @brief Fetches a list with the stored eventlists of the server.
* @return pwr_tStatus
*/
int sevcli_get_eventsitemlist(pwr_tStatus* sts, sevcli_tCtx ctx,
sevcli_sEventsItem** list, unsigned int* cnt)
{
sev_sMsgAny* msg;
qcom_sQid tgt;
qcom_sPut put;
pwr_tStatus lsts;
int tmo = 10000;
qcom_sGet get;
sevcli_sEventsItem* 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.type.b = (qcom_eBtype)sev_cMsgClass;
put.type.s = (qcom_eStype)sev_eMsgType_EventsItemsRequest;
put.msg_id = ctx->msg_id++;
put.size = sizeof(*msg);
put.allocate = 0;
msg = (sev_sMsgAny*)qcom_Alloc(sts, put.size);
put.data = msg;
msg->Type = sev_eMsgType_EventsItemsRequest;
msg->Version = sev_cNetVersion;
if (!qcom_Put(sts, &tgt, &put)) {
qcom_Free(&lsts, put.data);
return 0;
}
sev_sMsgEventsItems* rmsg;
memset(&get, 0, sizeof(get));
for (;;) {
rmsg = (sev_sMsgEventsItems*)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_EventsItems)
break;
qcom_Free(sts, rmsg);
}
*sts = rmsg->Status;
if (EVEN(*sts))
return 0;
int item_cnt = rmsg->NumItems;
unsigned int data_size = (item_cnt * sizeof(sevcli_sEventsItem));
lp = (sevcli_sEventsItem*)malloc(data_size);
sevcli_sEventsItem* lp2 = lp;
sev_sEventsItem* itemPtr = ((sev_sMsgEventsItems*)rmsg)->Items;
for (i = 0; i < item_cnt; i++) {
lp->oid = itemPtr->oid;
strncpy(lp->oname, itemPtr->oname, sizeof(lp->oname));
strncpy(lp->description, itemPtr->description, sizeof(lp->description));
lp->storagetime = net_NetTimeToDeltaTime(&itemPtr->storagetime);
lp->options = itemPtr->options;
lp->creatime = net_NetTimeToTime(&itemPtr->creatime);
itemPtr++;
lp++;
}
qcom_Free(sts, rmsg);
*cnt = item_cnt;
*list = lp2;
*sts = SEV__SUCCESS;
return 1;
}
/**
* @brief Fetch stored historical events for an events item.
*
* @return pwr_tStatus
*/
int sevcli_get_events(pwr_tStatus* sts, sevcli_tCtx ctx, pwr_tOid oid,
pwr_tTime starttime, pwr_tTime endtime, pwr_tUInt32 eventtypemask,
pwr_tUInt32 eventpriomask, pwr_tString80 eventtext, pwr_tOName eventname,
unsigned int maxevents, sevcli_sEvents **list, unsigned int* cnt)
{
sev_sMsgEventsGetRequest* msg;
qcom_sQid tgt;
qcom_sPut put;
static int tmo = 0;
qcom_sGet get;
pwr_tStatus lsts;
sevcli_sEvents *lp;
sev_sEvents *ip;
int i;
if (tmo == 0) {
int value;
char value_str[20];
int nr;
if (cnf_get_value("sevTimeout", value_str, sizeof(value_str))) {
nr = sscanf(value_str, "%d", &value);
if (nr != 1)
tmo = 30000;
else
tmo = 1000 * value;
} else
tmo = 30000;
}
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_EventsGetRequest;
put.msg_id = ctx->msg_id++;
put.size = sizeof(*msg);
put.allocate = 0;
msg = (sev_sMsgEventsGetRequest*)qcom_Alloc(sts, put.size);
put.data = msg;
msg->Type = sev_eMsgType_EventsGetRequest;
msg->Version = sev_cNetVersion;
msg->Oid = oid;
msg->StartTime = net_TimeToNetTime(&starttime);
msg->EndTime = net_TimeToNetTime(&endtime);
msg->EventTypeMask = eventtypemask;
msg->EventPrioMask = eventpriomask;
strncpy(msg->EventText, eventtext, sizeof(msg->EventText));
strncpy(msg->EventName, eventname, sizeof(msg->EventName));
msg->MaxEvents = maxevents;
// Empty queue
sev_sMsgEventsGet* rmsg;
memset(&get, 0, sizeof(get));
for (;;) {
rmsg = (sev_sMsgEventsGet*)qcom_Get(sts, &ctx->qid, &get, 0);
if (!rmsg)
break;
qcom_Free(sts, rmsg);
}
if (!qcom_Put(sts, &tgt, &put)) {
qcom_Free(&lsts, put.data);
return 0;
}
memset(&get, 0, sizeof(get));
for (;;) {
rmsg = (sev_sMsgEventsGet*)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_EventsGet
&& cdh_ObjidIsEqual(oid, rmsg->Oid))
break;
qcom_Free(sts, rmsg);
}
*sts = rmsg->Status;
if (EVEN(*sts)) {
qcom_Free(&lsts, rmsg);
return 0;
}
if (rmsg->NumEvents == 0) {
qcom_Free(sts, rmsg);
*sts = SEV__NOPOINTS;
return 0;
}
int item_cnt = rmsg->NumEvents;
*list = calloc(item_cnt, sizeof(sevcli_sEventsItem));
lp = *list;
ip = rmsg->Events;
for (i = 0; i < item_cnt; i++) {
lp->Time = net_NetTimeToTime(&ip->Time);
lp->EventType = ip->EventType;
lp->EventPrio = ip->EventPrio;
lp->SupObjectOid = ip->SupObjectOid;
lp->SupObjectSize = ip->SupObjectSize;
strncpy(lp->EventText, ip->EventText, sizeof(lp->EventText));
strncpy(lp->EventName, ip->EventName, sizeof(lp->EventName));
lp->EventId = ip->EventId;
lp++;
ip++;
}
*cnt = item_cnt;
qcom_Free(&lsts, rmsg);
*sts = SEV__SUCCESS;
return 1;
}
......@@ -43,6 +43,7 @@
/*@{*/
#include "rt_qcom.h"
#include "rt_mh_net.h"
#ifdef __cplusplus
extern "C" {
......@@ -85,6 +86,27 @@ typedef struct {
sevcli_sHistAttr attr[1]; /**< Array of attribute data */
} sevcli_sHistItem;
typedef struct {
pwr_tOid oid; /**< Object identity */
pwr_tAName oname; /**< Object name */
pwr_tDeltaTime storagetime; /**< Storage time from SevHist object */
pwr_tTime creatime; /**< Creation time */
pwr_tString80 description; /**< Description */
pwr_tMask options; /**< Options from SevHist object */
} sevcli_sEventsItem;
typedef struct {
pwr_tTime Time;
pwr_tUInt32 EventType;
pwr_tUInt32 EventPrio;
pwr_tOid SupObjectOid;
pwr_tUInt32 SupObjectOffset;
pwr_tUInt32 SupObjectSize;
pwr_tString80 EventText;
pwr_tOName EventName;
mh_sEventId EventId;
} sevcli_sEvents;
int sevcli_init(pwr_tStatus* sts, sevcli_tCtx* ctx);
int sevcli_close(pwr_tStatus* sts, sevcli_tCtx ctx);
void sevcli_set_servernid(sevcli_tCtx ctx, pwr_tNid nid);
......@@ -101,6 +123,12 @@ 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);
int sevcli_get_eventsitemlist(pwr_tStatus* sts, sevcli_tCtx ctx,
sevcli_sEventsItem** list, unsigned int* cnt);
int sevcli_get_events(pwr_tStatus* sts, sevcli_tCtx ctx, pwr_tOid oid,
pwr_tTime starttime, pwr_tTime endtime, pwr_tUInt32 eventtypemask,
pwr_tUInt32 eventpriomask, pwr_tString80 eventtext, pwr_tOName eventname,
unsigned int maxevents, sevcli_sEvents **list, unsigned int* cnt);
/** @} */
......
......@@ -176,6 +176,11 @@ XttMultiViewQt::XttMultiViewQt(void* mv_parent_ctx, const char* mv_name,
comp_widget = std::vector<QWidget*>(rows * cols);
exchange_widget = std::vector<QWidget*>(rows * cols);
exchange_widget_layout = std::vector<QHBoxLayout*>(rows * cols);
for (int i = 0; i < rows * cols; i++) {
exchange_widget_layout[i] = new QHBoxLayout(toplevel);
exchange_widget[i]
= layout_to_widget(exchange_widget_layout[i]);
}
QHBoxLayout* col_widget_box = new QHBoxLayout();
QSplitter* col_widget_pane = new QSplitter();
......@@ -680,8 +685,6 @@ XttMultiViewQt::XttMultiViewQt(void* mv_parent_ctx, const char* mv_name,
if (mv.Action[idx].Options
& pwr_mMultiViewElemOptionsMask_Exchangeable) {
exchange_widget[idx]
= layout_to_widget(exchange_widget_layout[idx]);
if (comp_widget[idx]) {
add_expanding(exchange_widget_layout[idx],
comp_widget[idx]);
......
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