-
Notifications
You must be signed in to change notification settings - Fork 1
/
alView.c
422 lines (370 loc) · 10.2 KB
/
alView.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
/*************************************************************************\
* 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.
\*************************************************************************/
/* alView.c */
/************************DESCRIPTIO************************************
Routines for adjusting the tree view
**********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sllLib.h"
#include "alLib.h"
#include "ax.h"
/* forward declarations */
static void treeView( GLINK *glink, int command, char *treeSym, int (*viewFilter)());
/***************************************************
Returns groupWindow viewCount for new glink
****************************************************/
int alViewAdjustGroupW(GLINK *glink,int (*viewFilter)())
{
SNODE *pt;
int count=0;
if (!glink) return(0);
pt = sllFirst(&glink->subGroupList);
while ( pt){
if (glink->viewCount <= 1)
((GCLINK *)pt)->viewCount = viewFilter((GCLINK *)pt);
if( ((GCLINK *)pt)->viewCount ) count++;
pt = sllNext(pt);
}
pt = sllFirst(&(glink->chanList));
while (pt){
((GCLINK *)pt)->viewCount = viewFilter((GCLINK *)pt);
if( ((GCLINK *)pt)->viewCount ) count++;
pt = sllNext(pt);
}
return(count);
}
/***************************************************
Uses command to adjust treeW view at glink and return new viewCount
****************************************************/
int alViewAdjustTreeW(GLINK *glink,int command,int (*viewFilter)())
{
GLINK *glinkTemp;
int holdViewCount, diffCount, count;
char treeSym[MAX_TREE_DEPTH+1];
memset(treeSym,'\0',MAX_TREE_DEPTH);
if (glink->pgroupData->treeSym)
strcpy(treeSym,glink->pgroupData->treeSym);
holdViewCount = glink->viewCount;
treeView(glink, command, treeSym, viewFilter);
diffCount = glink->viewCount - holdViewCount;
glinkTemp=glink;
count = glinkTemp->viewCount;
while (glink){
glinkTemp = glinkTemp->parent;
if (glinkTemp == NULL ) break;
glinkTemp->viewCount += diffCount;
count = glinkTemp->viewCount;
}
return(count);
}
/***************************************************
treeView
****************************************************/
static void treeView(GLINK *glink,int command,char *treeSym,int (*viewFilter)())
{
SNODE *pt;
int subcommand;
int oldViewCount=0;
size_t length;
static char symMiddle={
0x15 };
static char symContinue={
0x19 };
static char symEnd={
0x0E };
static char symBlank={
0x20 };
static char symNull={
0x00 };
if (glink == NULL) return;
if (command != NOCHANGE){
oldViewCount = glink->viewCount;
glink->viewCount = viewFilter((GCLINK *)glink);
}
length = strlen(treeSym);
if (length >= MAX_TREE_DEPTH) return;
if (glink->pgroupData->treeSym &&
(length+1) > (int)strlen(glink->pgroupData->treeSym) ) {
free(glink->pgroupData->treeSym);
glink->pgroupData->treeSym = 0 ;
}
if (!glink->pgroupData->treeSym)
glink->pgroupData->treeSym = (char *)calloc(1,length+1);
/* find next view sibling */
pt = sllNext(glink);
while (pt){
if (command == NOCHANGE){
if (((GLINK *)pt)->viewCount>0) break;
} else {
if (viewFilter((GCLINK *)pt)) break;
}
pt = sllNext(pt);
}
if (length){
if (pt) treeSym[length-1] = symMiddle;
else treeSym[length-1] = symEnd;
treeSym[length] = symNull;
strcpy(glink->pgroupData->treeSym,treeSym);
}
if ( command == COLLAPSE) return;
if ( command == NOCHANGE && glink->viewCount == 1) return;
subcommand = command;
if ( command == EXPANDCOLLAPSE1){
if ( oldViewCount > 1) return;
subcommand=COLLAPSE;
}
if (length){
if (pt) treeSym[length-1] = symContinue;
else treeSym[length-1]=symBlank;
}
pt = sllFirst(&(glink->subGroupList));
if (!pt) return;
if (glink->viewCount) treeSym[length]=symBlank;
while (pt){
treeView((GLINK *)pt, subcommand, treeSym, viewFilter);
if ( command != NOCHANGE) glink->viewCount += ((GLINK *)pt)->viewCount;
pt = sllNext(pt);
}
treeSym[length]=symNull;
return;
}
/***************************************************
Return next treeWindow item open for view
****************************************************/
GCLINK *alViewNextTreeW(GLINK *glink,int *plinkType)
{
GLINK *glinkTemp;
SNODE *pt;
*plinkType = GROUP;
/* try child */
if (glink->viewCount >1){
pt = sllFirst(&glink->subGroupList);
while (pt){
if (((GLINK *)pt)->viewCount) break;
pt = sllNext(pt);
}
return((GCLINK *)pt);
}
/* try following siblings */
pt = sllNext(glink);
while (pt){
if (((GLINK *)pt)->viewCount) break;
pt = sllNext(pt);
}
if (pt) return((GCLINK *)pt);
/* try parent siblings */
glinkTemp = glink->parent;
while (glinkTemp){
pt = sllNext(glinkTemp);
while (pt){
if (((GLINK *)pt)->viewCount) break;
pt = sllNext(pt);
}
if (pt) return((GCLINK *)pt);
glinkTemp = glinkTemp->parent;
}
return(NULL);
}
/***************************************************
Return next groupWindow item open for view
****************************************************/
GCLINK *alViewNextGroupW(GCLINK *link,int *plinkType)
{
SNODE *pt;
GLINK *parent;
pt = sllNext((SNODE *)link);
while(pt){
if (((GCLINK *)pt)->viewCount) break;
pt = sllNext(pt);
}
if (!pt && *plinkType == GROUP){
parent = link->parent;
pt = sllFirst(&(parent->chanList));
*plinkType = CHANNEL;
while(pt){
if (((GCLINK *)pt)->viewCount) break;
pt = sllNext(pt);
}
}
return((GCLINK *)pt);
}
/***************************************************
Return nth treeWindow item open for view
****************************************************/
GCLINK *alViewNthTreeW(GLINK *glinkStart,int *plinkType,int n)
{
GLINK *glink;
int count;
SNODE *pt;
*plinkType = GROUP;
if (!glinkStart) return(NULL);
glink = glinkStart;
if (!glink->viewCount) return(0);
if (n > glink->viewCount) return(0);
count = 0;
while (count<n){
if (count + glink->viewCount > n ){
if (glink->viewCount) count++;
glink = (GLINK *)sllFirst(&glink->subGroupList);
}
else {
count += glink->viewCount;
pt = sllNext(glink);
while (!pt){
glink = glink->parent;
if (!glink) break;
pt = sllNext(glink);
}
glink = (GLINK *)pt;
if (!glink) return(NULL);
}
}
if (count != n) return(NULL);
return((GCLINK *)glink);
}
/***************************************************
Return nth groupWindow item open for view
****************************************************/
GCLINK *alViewNthGroupW(GLINK *link,int *plinkType,int n)
{
SNODE *pt;
int count= 0;
*plinkType = 0;
if (!link) return(0);
pt = sllFirst(&link->subGroupList);
while ( pt){
if (count == n && ((GCLINK *)pt)->viewCount) break;
if (((GCLINK *)pt)->viewCount) count++;
pt = sllNext(pt);
}
if (pt) {
*plinkType = GROUP;
return((GCLINK *)pt);
}
pt = sllFirst(&(link->chanList));
while (pt){
if (count == n && ((GCLINK *)pt)->viewCount) break;
if (((GCLINK *)pt)->viewCount) count++;
pt = sllNext(pt);
}
if (pt) {
*plinkType = CHANNEL;
}
return((GCLINK *)pt);
}
/***************************************************
Get groupWindow max sevr in range from glinkstart
to Nth item following linkstart
****************************************************/
int alViewMaxSevrNGroupW(GCLINK *linkStart,int n)
{
GLINK *glink;
GLINK *parent;
CLINK *clink=0;
int count= 0;
int sevr = 0;
int linkType;
if (n <= 0 || !linkStart) return(0);
/* determine linkType of linkStart */
parent = linkStart->parent;
glink = (GLINK *)sllFirst(&parent->subGroupList);
while ( glink){
if ((GCLINK *)glink == linkStart ) break;
glink = (GLINK *)sllNext(glink);
}
if (glink) {
linkType = GROUP;
} else {
linkType = CHANNEL;
clink = (CLINK *)sllFirst(&(parent->chanList));
while (clink){
if ((GCLINK *)clink == linkStart) break;
clink = (CLINK *)sllNext(clink);
}
}
/* determine maximum severity below linkStart */
if (linkType == GROUP ){
while ( glink){
if (count == n) break;
if (glink->viewCount) {
sevr = Mmax(sevr,glink->pgroupData->curSevr);
if (sevr >= ALH_ALARM_NSEV-1) break;
count++;
}
glink = (GLINK *)sllNext(glink);
}
if (sevr >= ALH_ALARM_NSEV-1) return(sevr);
if (glink) {
return(sevr);
}
clink = (CLINK *)sllFirst(&(parent->chanList));
}
while (clink){
if (count == n) break;
if (clink->viewCount) {
sevr = Mmax(sevr,clink->pchanData->curSevr);
count++;
}
if (sevr >= ALH_ALARM_NSEV-1) break;
clink = (CLINK *)sllNext(clink);
}
return(sevr);
}
/***************************************************
Get treeWindow max sevr in range from glinkstart
to nth item following glinkstart
****************************************************/
int alViewMaxSevrNTreeW(GLINK *glinkStart,int n)
{
GLINK *glink;
CLINK *clink=0;
SNODE *pt;
int sevr=0;
int count=0;
if (n <= 0 ) return(0);
if (!glinkStart) return(-1);
glink = glinkStart;
if (!glink->viewCount) return(-1);
while (count<n){
if (count + glink->viewCount > n ){
/* max severity of channels within group */
clink = (CLINK *)sllFirst(&(glink->chanList));
while (clink){
sevr = Mmax(sevr,clink->pchanData->curSevr);
if (sevr >= ALH_ALARM_NSEV-1) break;
clink = (CLINK *)sllNext(clink);
}
if (sevr >= ALH_ALARM_NSEV-1) break;
count++;
glink = (GLINK *)sllFirst(&glink->subGroupList);
}
else {
if (glink->viewCount)
sevr = Mmax(sevr,glink->pgroupData->curSevr);
if (sevr >= ALH_ALARM_NSEV-1) break;
count += glink->viewCount;
pt = sllNext(glink);
while (!pt){
glink = glink->parent;
if (!glink) return(sevr);
pt = sllNext(glink);
}
glink = (GLINK *)pt;
}
}
return(sevr);
}