-
Notifications
You must be signed in to change notification settings - Fork 2
/
noAck.c
454 lines (384 loc) · 13.9 KB
/
noAck.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 Deutches Elektronen-Synchrotron in der Helmholtz-
* Gemelnschaft (DESY).
* Copyright (c) 2002 Berliner Speicherring-Gesellschaft fuer Synchrotron-
* Strahlung mbH (BESSY).
* Copyright (c) 2002 Southeastern Universities Research Association, as
* Operator of Thomas Jefferson National Accelerator Facility.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
/* noAck.c */
/************************DESCRIPTION***********************************
Routines for modifying noAck mask for 1 hour.
**********************************************************************/
#include <stdlib.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/LabelG.h>
#include <Xm/PushB.h>
#include <Xm/ToggleB.h>
#include <Xm/PanedW.h>
#include <Xm/Protocols.h>
#include <Xm/RowColumn.h>
#include <Xm/ToggleBG.h>
#include "axArea.h"
#include "alLib.h"
#include "alh.h"
#include "ax.h"
extern int _DB_call_flag;
typedef struct {
char *label;
int index;
} noAckChoiceItem;
struct noAckWindow {
void *area;
Widget menuButton;
Widget noAckDialog;
Widget nameLabelW;
Widget nameTextW;
Widget noAckOneHourToggleButton;
};
/* forward declarations */
static void noAckDismissCallback(Widget widget,XtPointer calldata,XtPointer cbs);
static void noAckHelpCallback(Widget widget,XtPointer calldata,XtPointer cbs);
static void noAckActivateCallback( Widget widget,XtPointer calldata,XtPointer cbs);
static void noAckCreateDialog(ALINK*area);
static void noAckUpdateDialogWidgets(struct noAckWindow *noAckWindow);
static void noAckOneHourTimerGroupCallback(XtPointer data, XtIntervalId *id);
static void noAckOneHourTimerChanCallback(XtPointer data, XtIntervalId *id);
static void alResetNoAckChan(CLINK *clink);
static void alResetNoAckGroup(GLINK *glink);
/******************************************************
noAckUpdateDialog
******************************************************/
void noAckUpdateDialog(ALINK *area)
{
struct noAckWindow *noAckWindow;
noAckWindow = (struct noAckWindow *)area->noAckWindow;
if (!noAckWindow) return;
if (!noAckWindow->noAckDialog ||
!XtIsManaged(noAckWindow->noAckDialog)) return;
noAckUpdateDialogWidgets(noAckWindow);
}
/******************************************************
noAckShowDialog
******************************************************/
void noAckShowDialog(ALINK *area,Widget menuButton)
{
struct noAckWindow *noAckWindow;
noAckWindow = (struct noAckWindow *)area->noAckWindow;
/* dismiss Dialog */
if (noAckWindow && noAckWindow->noAckDialog &&
XtIsManaged(noAckWindow->noAckDialog)) {
noAckDismissCallback(NULL, (XtPointer)noAckWindow, NULL);
return;
}
/* create noAckWindow and Dialog Widgets if necessary */
if (!noAckWindow) noAckCreateDialog(area);
/* update noAckWindow */
noAckWindow = (struct noAckWindow *)area->noAckWindow;
noAckWindow->menuButton = menuButton;
/* update Dialog Widgets */
noAckUpdateDialogWidgets(noAckWindow);
/* show Dialog */
if (!noAckWindow->noAckDialog) return;
if (!XtIsManaged(noAckWindow->noAckDialog)) {
XtManageChild(noAckWindow->noAckDialog);
}
XMapWindow(XtDisplay(noAckWindow->noAckDialog),
XtWindow(XtParent(noAckWindow->noAckDialog)));
if (menuButton) XtVaSetValues(menuButton, XmNset, TRUE, NULL);
}
/******************************************************
noAckUpdateDialogWidgets
******************************************************/
static void noAckUpdateDialogWidgets(struct noAckWindow *noAckWindow)
{
struct gcData *pgcData;
GCLINK *link;
int linkType;
XmString string;
if (! noAckWindow || !noAckWindow->noAckDialog ) return;
link =getSelectionLinkArea(noAckWindow->area);
/* ---------------------------------
Group/Channel name
--------------------------------- */
if (!link) {
string = XmStringCreateSimple("");
if (noAckWindow->nameTextW )
XtVaSetValues(noAckWindow->nameTextW,XmNlabelString, string, NULL);
XmStringFree(string);
return;
}
pgcData = link->pgcData;
linkType =getSelectionLinkTypeArea(noAckWindow->area);
/* ---------------------------------
Group/Channel label
--------------------------------- */
if (linkType == GROUP) string = XmStringCreateSimple("Group: ");
else string = XmStringCreateSimple("Channel: ");
XtVaSetValues(noAckWindow->nameLabelW, XmNlabelString, string, NULL);
XmStringFree(string);
if (pgcData->alias){
string = XmStringCreateSimple(pgcData->alias);
} else {
string = XmStringCreateSimple(pgcData->name);
}
XtVaSetValues(noAckWindow->nameTextW, XmNlabelString, string, NULL);
XmStringFree(string);
/* ---------------------------------
noAck for one hour toggle button
--------------------------------- */
if (pgcData->noAckTimerId)
XmToggleButtonGadgetSetState(noAckWindow->noAckOneHourToggleButton,TRUE,FALSE);
else XmToggleButtonGadgetSetState(noAckWindow->noAckOneHourToggleButton,FALSE,FALSE);
}
/******************************************************
noAckCreateDialog
******************************************************/
static void noAckCreateDialog(ALINK *area)
{
struct noAckWindow *noAckWindow;
Widget noAckDialogShell, noAckDialog;
Widget form;
Widget nameLabelW, nameTextW;
Widget noAckOneHourToggleButton;
static ActionAreaItem buttonItems[] = {
{ "Dismiss", noAckDismissCallback, NULL },
{ "Help", noAckHelpCallback, NULL },
};
if (!area) return;
noAckWindow = (struct noAckWindow *)area->noAckWindow;
if (noAckWindow && noAckWindow->noAckDialog){
if (XtIsManaged(noAckWindow->noAckDialog)) return;
else XtManageChild(noAckWindow->noAckDialog);
}
noAckWindow = (struct noAckWindow *)calloc(1,sizeof(struct noAckWindow));
area->noAckWindow = (void *)noAckWindow;
noAckWindow->area = (void *)area;
noAckDialogShell = XtVaCreatePopupShell("Modify NoAck Mask",
transientShellWidgetClass, area->toplevel,
XmNallowShellResize, TRUE,
NULL);
/* Modify the window manager menu "close" callback */
{
Atom WM_DELETE_WINDOW;
XtVaSetValues(noAckDialogShell,
XmNdeleteResponse, XmDO_NOTHING, NULL);
WM_DELETE_WINDOW = XmInternAtom(XtDisplay(noAckDialogShell),
"WM_DELETE_WINDOW", False);
XmAddWMProtocolCallback(noAckDialogShell,WM_DELETE_WINDOW,
(XtCallbackProc)noAckDismissCallback, (XtPointer)noAckWindow);
}
noAckDialog = XtVaCreateWidget("noAckDialog",
xmPanedWindowWidgetClass, noAckDialogShell,
XmNallowResize, TRUE,
XmNsashWidth, 1,
XmNsashHeight, 1,
XmNuserData, area,
(XtPointer)NULL);
form = XtVaCreateWidget("control_area",
xmFormWidgetClass, noAckDialog,
XmNallowResize, TRUE,
NULL);
/* ---------------------------------
Group/Channel Name
--------------------------------- */
nameLabelW = XtVaCreateManagedWidget("nameLabelW",
xmLabelGadgetClass, form,
XmNalignment, XmALIGNMENT_END,
XmNtopAttachment, XmATTACH_FORM,
XmNrecomputeSize, True,
NULL);
nameTextW = XtVaCreateManagedWidget("nameTextW",
xmLabelGadgetClass, form,
XmNalignment, XmALIGNMENT_BEGINNING,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, nameLabelW,
XmNrightAttachment, XmATTACH_NONE,
XmNrecomputeSize, True,
NULL);
/* ---------------------------------
NoAck One Hour toggle button
--------------------------------- */
noAckOneHourToggleButton = XtVaCreateManagedWidget("NoAck For One Hour",
xmToggleButtonGadgetClass, form,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, nameLabelW,
XmNtopOffset, 10,
XmNuserData, (XtPointer)area,
NULL);
XtAddCallback(noAckOneHourToggleButton, XmNvalueChangedCallback,
(XtCallbackProc)noAckActivateCallback,area);
XtManageChild(form);
/* Set the client data "Dismiss" and "Help" button's callbacks. */
buttonItems[0].data = (XtPointer)noAckWindow;
buttonItems[1].data = (XtPointer)noAckWindow;
(void)createActionButtons(noAckDialog, buttonItems, XtNumber(buttonItems));
noAckWindow->noAckDialog = noAckDialog;
noAckWindow->nameLabelW = nameLabelW;
noAckWindow->nameTextW = nameTextW;
noAckWindow->noAckOneHourToggleButton = noAckOneHourToggleButton;
XtManageChild(noAckDialog);
XtRealizeWidget(noAckDialogShell);
}
/******************************************************
noAckHelpCallback
******************************************************/
static void noAckHelpCallback(Widget widget,XtPointer calldata,XtPointer cbs)
{
char *message1 =
"Set group or channel ack/noAck mask to noAck for one hour and then\n"
"reset it to initial (config file) value after the hour is over.\n\n"
"Setting the 'noAck for One Hour' button to ON means setting the ack/noAck\n"
"mask to noAck for the selected channel or for all channels in the\n"
"selected group and creating a one hour timer. When the timer expires\n"
"the ack/noAck masks will be set to the initial value from the config file.\n\n"
;
char * message2 =
"Setting the 'noAck for One Hour' button to OFF means setting the ack/noAck\n"
"mask to the initial value from the config file for the celected channel or\n"
"for all channels in the selected group and removing the one hour timer.\n\n"
"Press the Dismiss button to close the dialog window.\n"
"Press the Help button to get this help description window.\n"
;
createDialog(widget,XmDIALOG_INFORMATION, message1,message2);
}
/******************************************************
noAckDismissCallback
******************************************************/
static void noAckDismissCallback(Widget widget,XtPointer calldata,
XtPointer cbs)
{
struct noAckWindow *noAckWindow=(struct noAckWindow *)calldata;
Widget noAckDialog;
noAckDialog = noAckWindow->noAckDialog;
XtUnmanageChild(noAckDialog);
XUnmapWindow(XtDisplay(noAckDialog), XtWindow(XtParent(noAckDialog)));
if (noAckWindow->menuButton)
XtVaSetValues(noAckWindow->menuButton, XmNset, FALSE, NULL);
}
/***************************************************
noAckOneHourTimerChanCallback
****************************************************/
static void noAckOneHourTimerChanCallback(XtPointer data, XtIntervalId *id)
{
CLINK * clink = (CLINK *)data;
clink->pchanData->noAckTimerId=0;;
alResetNoAckChan(clink);
alLogOpModMessage(0,(GCLINK*)clink,
"Set Ack after expiration of NoAck one hour timer");
clink->pmainGroup->modified = TRUE;
axUpdateDialogs(clink->pmainGroup->area);
}
/***************************************************
noAckOneHourTimerGroupCallback
****************************************************/
static void noAckOneHourTimerGroupCallback(XtPointer data, XtIntervalId *id)
{
GLINK * glink = (GLINK *)data;
glink->pgroupData->noAckTimerId=0;;
alResetNoAckGroup(glink);
alLogOpModMessage(0,(GCLINK*)glink,
"Set Ack after expiration of NoAck one hour timer");
glink->pmainGroup->modified = TRUE;
axUpdateDialogs(glink->pmainGroup->area);
}
/***************************************************
noAckActivateCallback
****************************************************/
static void noAckActivateCallback(Widget widget,XtPointer link,
XtPointer call_data)
{
int seconds = 3600; /* 1 hour */
#if 0
int seconds = 60; /* 1 minute */
#endif
ALINK *area;
GCLINK *gclink;
struct gcData *gcdata;
int linkType;
XtTimerCallbackProc proc;
XtVaGetValues(widget, XmNuserData, &area, NULL);
gclink =(GCLINK *)getSelectionLinkArea(area);
gcdata = gclink->pgcData;
linkType =getSelectionLinkTypeArea(area);
if (linkType == GROUP) proc = noAckOneHourTimerGroupCallback;
else proc = noAckOneHourTimerChanCallback;
if (gcdata->noAckTimerId) {
XtRemoveTimeOut(gcdata->noAckTimerId);
gcdata->noAckTimerId = 0;
}
if (XmToggleButtonGadgetGetState(widget)) {
if (linkType==GROUP) {
alRemoveNoAck1HrTimerGroup((GLINK*)gclink);
alForceGroupMask((GLINK*)gclink,ALARMACK,1);
} else {
alRemoveNoAck1HrTimerChan((CLINK*)gclink);
alForceChanMask((CLINK*)gclink,ALARMACK,1);
}
gcdata->noAckTimerId = XtAppAddTimeOut(appContext,
(unsigned long)(1000*seconds),
(XtTimerCallbackProc)proc,
(XtPointer)gclink);
alLogOpModMessage(0,gclink,
"Set NoAck and start NoAck one hour timer");
} else {
if (linkType==GROUP) {
alResetNoAckGroup((GLINK *)gclink);
} else {
alResetNoAckChan((CLINK *)gclink);
}
alLogOpModMessage(0,gclink,
"Reset Ack mask and cancel NoAck one hour timer");
}
gclink->modified = 1;
gclink->pmainGroup->modified = 1;
axUpdateDialogs(area);
}
/*************************************************************************
alResetNoAckChan
**********************************************************************/
static void alResetNoAckChan(CLINK *clink)
{
MASK mask;
if (clink->pchanData->noAckTimerId) return;
mask = clink->pchanData->curMask;
mask.Ack = clink->pchanData->defaultMask.Ack;
alChangeChanMask(clink,mask);
if(_DB_call_flag) alLog2DBMask(clink->pchanData->name);
}
/*************************************************************************
alResetNoAckGroup
**********************************************************************/
static void alResetNoAckGroup(GLINK *glink)
{
GLINK *group;
CLINK *clink;
SNODE *pt;
if (glink->pgroupData->noAckTimerId) return;
/*
* for all channels in this group
*/
pt = sllFirst(&(glink->chanList));
while (pt) {
clink = (CLINK *)pt;
alResetNoAckChan(clink);
pt = sllNext(pt);
}
/*
* for all subgroups
*/
pt = sllFirst(&(glink->subGroupList));
while (pt) {
group = (GLINK *)pt;
alResetNoAckGroup(group);
pt = sllNext(pt);
}
}