Commit 06a43bd8 authored by claes's avatar claes

Soft restart for xtt

parent cd4057f1
......@@ -11,6 +11,10 @@
#include <string.h>
#include <stdlib.h>
#if defined OS_LINUX
#include <sys/stat.h>
#endif
#include "pwr.h"
#include "pwr_baseclasses.h"
#include "pwr_privilege.h"
......@@ -1134,6 +1138,65 @@ void trace_pop( tra_tCtx tractx)
*/
}
void trace_swap( tra_tCtx tractx, int mode)
{
pwr_tStatus sts;
if ( mode == 0) {
if ( tractx->trace_started) {
flow_TraceClose( tractx->flow_ctx);
XtRemoveTimeOut( tractx->trace_timerid);
}
}
else {
if ( tractx->trace_started) {
int version = 0;
#if defined OS_LINUX
{
struct stat info;
if ( stat( tractx->filename, &info) != -1)
version = info.st_ctime;
}
#endif
if ( tractx->version != version) {
flow_sAttributes attr;
char tfile[200];
char *s;
// Temporary file to store trace objects
strcpy( tfile, "/tmp/");
if ( (s = strrchr( tractx->filename, '/')))
strcat( tfile, s+1);
else
strcat( tfile, tractx->filename);
flow_GetAttributes( tractx->flow_ctx, &attr);
flow_SaveTrace( tractx->flow_ctx, tfile);
tractx->version = version;
tractx->trace_started = 0;
flow_SetNodraw( tractx->flow_ctx);
flow_DeleteAll( tractx->flow_ctx);
flow_Open( tractx->flow_ctx, tractx->filename);
flow_SetAttributes( tractx->flow_ctx, &attr, ~0);
flow_Zoom( tractx->flow_ctx, 1);
flow_ResetNodraw( tractx->flow_ctx);
flow_Redraw( tractx->flow_ctx);
trace_start( tractx);
flow_OpenTrace( tractx->flow_ctx, tfile);
}
else {
sts = flow_TraceInit( tractx->flow_ctx, trace_connect_bc,
trace_disconnect_bc, NULL);
if ( EVEN(sts))
return;
trace_scan( tractx);
}
}
}
}
tra_tCtx trace_new( void *parent_ctx,
Widget parent_wid,
pwr_tObjid objid,
......@@ -1323,6 +1386,16 @@ tra_tCtx trace_new( void *parent_ctx,
trace_trasetup( tractx);
trace_start( tractx);
strcpy( tractx->filename, filename);
#if defined OS_LINUX
{
struct stat info;
if ( stat( tractx->filename, &info) != -1)
tractx->version = info.st_ctime;
}
#endif
return tractx;
}
......
......@@ -63,6 +63,8 @@ struct tra_sCtx{
unsigned long utility,
char *arg);
trace_t_node *trace_list;
char filename[200];
int version;
};
......@@ -82,5 +84,12 @@ int trace_search_object( tra_tCtx tractx,
char *object_str);
void trace_pop( tra_tCtx tractx);
void trace_swap( tra_tCtx tractx, int mode);
#endif
......@@ -13,6 +13,8 @@
extern "C" {
#include "rt_gdh.h"
#include "rt_gdh_msg.h"
#include "rt_ini_event.h"
#include "rt_qcom_msg.h"
#include "co_cdh.h"
#include "co_time.h"
#include "pwr_baseclasses.h"
......@@ -229,14 +231,44 @@ static void xtt_hotkey_ResetDig( Widget w, XKeyEvent* ev, String* av, Cardinal*
printf("rt_xtt hotkey: SetDig. Can't get %s\n", name);
}
static void xtt_mainloop (XtAppContext AppCtx)
static void xtt_qcom_events( Xtt *xtt)
{
char mp[2000];
qcom_sQid qid = qcom_cNQid;
qcom_sGet get;
int swap = 0;
pwr_tStatus sts = 1;
while ( ODD(sts)) {
get.maxSize = sizeof(mp);
get.data = mp;
qcom_Get( &sts, &xtt->queid, &get, 0);
if ( !(sts == QCOM__TMO || sts == QCOM__QEMPTY)) {
ini_mEvent new_event;
qcom_sEvent *ep = (qcom_sEvent*) get.data;
new_event.m = ep->mask;
if (new_event.b.oldPlcStop && !swap) {
swap = 1;
xtt->xnav->swap(0);
} else if (new_event.b.swapDone && swap) {
swap = 0;
xtt->xnav->swap(1);
}
}
}
xtt->timerid = XtAppAddTimeOut(
XtWidgetToApplicationContext(xtt->toplevel), 1000,
(XtTimerCallbackProc)xtt_qcom_events, xtt);
}
static void xtt_mainloop (XtAppContext AppCtx, Xtt *xtt)
{
XEvent Event;
for (;;)
{
XtAppNextEvent (AppCtx, &Event);
if (Event.type != KeyPress ||
TkSUCCESS != hotkey_Process(HotkeyHandle, &Event))
XtDispatchEvent (&Event);
......@@ -855,6 +887,8 @@ Xtt::Xtt( int argc, char *argv[], int *return_sts) :
char opplace_str[80] = "";
int opplace_found = 0;
pwr_tObjid op_objid;
qcom_sQattr qAttr;
qcom_sQid qini;
hot_xtt = this;
......@@ -864,6 +898,24 @@ Xtt::Xtt( int argc, char *argv[], int *return_sts) :
return;
}
if (!qcom_Init(&sts, 0, "rt_xtt")) {
*return_sts = sts;
return;
}
qAttr.type = qcom_eQtype_private;
qAttr.quota = 100;
if (!qcom_CreateQ(&sts, &queid, &qAttr, "events")) {
*return_sts = sts;
return;
}
qini = qcom_cQini;
if (!qcom_Bind(&sts, &queid, &qini)) {
*return_sts = sts;
return;
}
// Set language
for ( i = 1; i < argc; i++) {
if ( strcmp( argv[i], "-l") == 0 && i + 1 < argc)
......@@ -993,6 +1045,11 @@ Xtt::Xtt( int argc, char *argv[], int *return_sts) :
if ( xnav->op)
xtt_close( this);
xtt_mainloop( app_ctx);
// Start timer to check for qcom events
timerid = XtAppAddTimeOut(
XtWidgetToApplicationContext(toplevel), 1000,
(XtTimerCallbackProc)xtt_qcom_events, this);
xtt_mainloop( app_ctx, this);
}
......@@ -28,6 +28,12 @@ extern "C" {
}
#endif
#ifndef rt_qcom_h
extern "C" {
#include "rt_qcom.h"
}
#endif
#ifndef xtt_xnav_h
#include "xtt_xnav.h"
#endif
......@@ -57,6 +63,8 @@ class Xtt {
Widget india_label;
Widget india_text;
void (*india_ok_cb)( Xtt *, char *);
qcom_sQid queid;
XtIntervalId timerid;
};
#endif
......
......@@ -43,6 +43,11 @@ int flow_OpenTrace( flow_tCtx ctx, char *filename)
return ctx->open( filename, flow_eSaveMode_Trace);
}
void flow_DeleteAll( flow_tCtx ctx)
{
ctx->delete_all();
}
void flow_DeleteNode( flow_tNode node)
{
((FlowNode *)node)->ctx->delete_object((FlowArrayElem *)node);
......@@ -519,6 +524,29 @@ void flow_SetAttributes( flow_tCtx ctx, flow_sAttributes *attr,
ctx->select_policy = attr->select_policy;
if ( mask & flow_eAttr_display_level)
ctx->display_level = attr->display_level;
if ( mask & flow_eAttr_zoom_factor)
ctx->zoom_factor = attr->zoom_factor;
}
void flow_GetAttributes( flow_tCtx ctx, flow_sAttributes *attr)
{
attr->base_zoom_factor = ctx->base_zoom_factor;
attr->offset_x = ctx->offset_x;
attr->offset_y = ctx->offset_y;
attr->grid_size_x = ctx->grid_size_x;
attr->grid_size_y = ctx->grid_size_y;
attr->grid_on = ctx->grid_on;
attr->user_highlight = ctx->user_highlight;
attr->draw_delta = ctx->draw_delta;
attr->grafcet_con_delta = ctx->grafcet_con_delta;
attr->refcon_width = ctx->refcon_width;
attr->refcon_height = ctx->refcon_height;
attr->refcon_linewidth = ctx->refcon_linewidth;
attr->refcon_textsize = ctx->refcon_textsize;
attr->application_paste = ctx->application_paste;
attr->select_policy = ctx->select_policy;
attr->display_level = ctx->display_level;
attr->zoom_factor = ctx->zoom_factor;
}
void flow_PositionToPixel( flow_tCtx ctx, double x, double y,
......
......@@ -30,6 +30,7 @@ typedef struct {
int application_paste;
flow_eSelectPolicy select_policy;
int display_level;
double zoom_factor;
} flow_sAttributes;
typedef enum {
......@@ -48,7 +49,8 @@ typedef enum {
flow_eAttr_refcon_textsize = 1 << 12,
flow_eAttr_application_paste = 1 << 13,
flow_eAttr_select_policy = 1 << 14,
flow_eAttr_display_level = 1 << 15
flow_eAttr_display_level = 1 << 15,
flow_eAttr_zoom_factor = 1 << 16
} flow_eAttribute;
......@@ -63,6 +65,7 @@ int flow_Save( flow_tCtx ctx, char *filename);
int flow_Open( flow_tCtx ctx, char *filename);
int flow_SaveTrace( flow_tCtx ctx, char *filename);
int flow_OpenTrace( flow_tCtx ctx, char *filename);
void flow_DeleteAll( flow_tCtx ctx);
void flow_DeleteNode( flow_tNode node);
void flow_DeleteConnection( flow_tCon con);
int flow_FindSelectedObject( flow_tCtx ctx, flow_tObject object);
......@@ -180,6 +183,7 @@ void flow_Zoom( flow_tCtx ctx, double zoom_factor);
void flow_ZoomAbsolute( flow_tCtx ctx, double zoom_factor);
void flow_SetAttributes( flow_tCtx ctx, flow_sAttributes *attr,
unsigned long mask);
void flow_GetAttributes( flow_tCtx ctx, flow_sAttributes *attr);
void flow_PositionToPixel( flow_tCtx ctx, double x, double y,
int *pix_x, int *pix_y);
void flow_UnZoom( flow_tCtx ctx);
......
......@@ -606,7 +606,7 @@ int draw_event_handler( FlowCtx *ctx, XEvent event)
case ButtonPress :
// printf( "-- Button event: (%d,%d) button: %d time:%d\n", event.xbutton.x,
// event.xbutton.y, event.xbutton.button, event.xbutton.time);
// event.xbutton.y, event.xbutton.button, event.xbutton.time);
// XSetInputFocus( draw_ctx->display, draw_ctx->window,
// RevertToNone, CurrentTime);
......
......@@ -3641,6 +3641,28 @@ void Graph::create_axis( grow_tObject *object, double x, double y)
grow_Redraw( grow->ctx);
}
void Graph::swap( int mode)
{
if ( mode == 0) {
// Swap starting
if ( trace_started) {
XtRemoveTimeOut( trace_timerid);
grow_TraceClose( grow->ctx);
trace_started = 0;
}
}
else if ( mode == 1) {
// Swap done
if ( !trace_started) {
grow_TraceInit( grow->ctx, graph_trace_connect_bc,
graph_trace_disconnect_bc, graph_trace_scan_bc);
trace_started = 1;
graph_trace_scan( this);
}
}
}
void GraphApplList::insert( void *ctx)
{
......
......@@ -1221,6 +1221,10 @@ class Graph {
//! Conversion of an object between different versions.
/*! \param object Object to convert. */
int convert_object( grow_tObject object);
//! Soft restart
/*! \param mode 0: swap starting, 1: swap done. */
void swap( int mode);
//! Destructor
/*! Stop trace (if started), delete open attribute editors, free local database, delete grow and
......
......@@ -1813,6 +1813,15 @@ static int graph_object_collect_build( Graph *graph, pwr_tObjid objid)
// Register scan function
graph->graph_object_scan = graph_object_collect_scan;
// Set graph attributes
grow_sAttributes grow_attr;
unsigned long mask = 0;
mask |= grow_eAttr_double_buffer_on;
grow_attr.double_buffer_on = 1;
grow_SetAttributes( graph->grow->ctx, &grow_attr, mask);
return 1;
}
......
......@@ -369,6 +369,11 @@ void ge_pop( ge_tCtx gectx)
flow_MapWidget( gectx->toplevel);
}
void ge_swap( ge_tCtx gectx, int mode)
{
((Graph *)gectx->graph)->swap( mode);
}
extern "C" ge_tCtx ge_new( Widget parent_wid,
void *parent_ctx,
char *name,
......
......@@ -58,6 +58,7 @@ typedef struct ge_sCtx {
void ge_pop( ge_tCtx gectx);
int ge_set_object_focus( ge_tCtx gectx, char *name, int empty);
void ge_swap( ge_tCtx gectx, int mode);
extern "C" ge_tCtx ge_new( Widget parent_wid,
void *parent_ctx,
......@@ -90,3 +91,5 @@ extern "C" void ge_delete( ge_tCtx gectx);
......@@ -409,15 +409,17 @@ static void hist_display_in_xnav_cb( void *ctx, pwr_tObjid objid)
static void hist_action_inputfocus( Widget w, XmAnyCallbackStruct *data)
{
Arg args[1];
Hist *histOP;
Hist *hist;
XtSetArg (args[0], XmNuserData, &histOP);
XtSetArg (args[0], XmNuserData, &hist);
XtGetValues (w, args, 1);
//printf("focus\n");
//histOP->hist->set_input_focus();
//?????????????????????
//if ( ev && ev->hist_displayed)
// ev->hist->set_input_focus();
// ev->hist->set_input_focus();
hist->hist->set_input_focus();
}
......
......@@ -479,6 +479,11 @@ void XAtt::pop()
flow_MapWidget( parent_wid);
}
void XAtt::swap( int mode)
{
((XAttNav *)xattnav)->swap( mode);
}
XAtt::~XAtt()
{
if ( set_focus_disabled)
......
......@@ -67,6 +67,7 @@ class XAtt {
int open_changevalue( char *name);
void change_value_close();
void pop();
void swap( int mode);
};
......
......@@ -995,6 +995,23 @@ void XAttNav::start_trace()
}
}
void XAttNav::swap( int mode)
{
if ( mode == 0) {
if ( trace_started) {
brow_TraceClose( brow->ctx);
XtRemoveTimeOut( trace_timerid);
}
}
else if ( mode == 1) {
if ( trace_started) {
brow_TraceInit( brow->ctx, xattnav_trace_connect_bc,
xattnav_trace_disconnect_bc, xattnav_trace_scan_bc);
xattnav_trace_scan( this);
}
}
}
......
......@@ -86,6 +86,7 @@ class XAttNav {
void enable_events();
int select_by_name( char *name);
void start_trace();
void swap( int mode);
};
......
......@@ -50,6 +50,7 @@ extern "C" {
#include "xtt_menu.h"
#include "xtt_xatt.h"
#include "xtt_xcrr.h"
#include "xtt_ge.h"
#define max(Dragon,Eagle) ((Dragon) > (Eagle) ? (Dragon) : (Eagle))
#define min(Dragon,Eagle) ((Dragon) < (Eagle) ? (Dragon) : (Eagle))
......@@ -3423,6 +3424,26 @@ int ApplList::find( applist_eType type, char *name, char *instance, void **ctx)
return 0;
}
void ApplList::swap( int mode)
{
ApplListElem *elem;
for ( elem = root; elem; elem = elem->next) {
switch( elem->type) {
case applist_eType_Graph:
ge_swap( (ge_tCtx)elem->ctx, mode);
break;
case applist_eType_Trace:
trace_swap( (tra_tCtx)elem->ctx, mode);
break;
case applist_eType_Attr:
((XAtt *)elem->ctx)->swap( mode);
break;
default: ;
}
}
}
char *XNav::get_message( int sts)
{
static char msg[256];
......@@ -3505,10 +3526,28 @@ int XNav::show_object_as_struct(
return XNAV__SUCCESS;
}
void XNav::swap( int mode)
{
if ( !mode)
printf( "XNav swap start\n");
else
printf( "XNav swap done\n");
appl.swap( mode);
if ( mode == 0) {
if ( trace_started) {
brow_TraceClose( brow->ctx);
XtRemoveTimeOut( trace_timerid);
}
}
else if ( mode == 1) {
if ( trace_started) {
brow_TraceInit( brow->ctx, xnav_trace_connect_bc,
xnav_trace_disconnect_bc, xnav_trace_scan_bc);
xnav_trace_scan( this);
}
}
}
......@@ -170,6 +170,7 @@ class ApplList {
void remove( void *ctx);
int find( applist_eType type, char *name, char *instance, void **ctx);
int find( applist_eType type, pwr_tObjid objid, void **ctx);
void swap( int mode);
};
class XNavGbl {
......@@ -333,6 +334,7 @@ class XNav {
int open_object( pwr_tObjid objid);
int open_crossref( pwr_tObjid objid);
int open_help();
void swap( int mode);
// Command module member functions
......
......@@ -824,19 +824,23 @@ int XNav::show_device()
strcat( attr_name, ".ErrorCount");
sts = gdh_GetAttributeCharacteristics ( attr_name,
&attrtype, &attrsize, &attroffs, &attrelem);
if ( EVEN(sts)) return sts;
sts = gdh_NameToAttrref( pwr_cNObjid, attr_name, &attrref);
if ( EVEN(sts)) return sts;
sts = gdh_DLRefObjectInfoAttrref ( &attrref, &attr_ptr, &subid);
if ( EVEN(sts)) return sts;
t.elem[t.elem_cnt].value_p = attr_ptr;
t.elem[t.elem_cnt].type_id = attrtype;
t.elem[t.elem_cnt].size = attrsize;
strcpy( t.elem[t.elem_cnt++].format, "%8d");
ts.subid[ts.subid_cnt++] = subid;
if ( EVEN(sts)) {
strcpy( t.elem[t.elem_cnt].fix_str, " -");
t.elem[t.elem_cnt++].type_id = xnav_eType_FixStr;
}
else {
sts = gdh_NameToAttrref( pwr_cNObjid, attr_name, &attrref);
if ( EVEN(sts)) return sts;
sts = gdh_DLRefObjectInfoAttrref ( &attrref, &attr_ptr, &subid);
if ( EVEN(sts)) return sts;
t.elem[t.elem_cnt].value_p = attr_ptr;
t.elem[t.elem_cnt].type_id = attrtype;
t.elem[t.elem_cnt].size = attrsize;
strcpy( t.elem[t.elem_cnt++].format, "%8d");
ts.subid[ts.subid_cnt++] = subid;
}
// Process
strcpy( attr_name, object_name);
......
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