-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalCaCommon.c
306 lines (267 loc) · 8.42 KB
/
alCaCommon.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
/*************************************************************************\
* 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.
\*************************************************************************/
/* alCaCommon.c */
/************************DESCRIPTION***********************************
This file contains ca routines common to cdev and epics ca.
This file also contains misc group and channel routines.
**********************************************************************/
/******************************************************************
Some misc. routines
******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "alarm.h"
#include "fdmgr.h"
#include "cadef.h"
#include "sllLib.h"
#include "alLib.h"
#include "alh.h"
#include "ax.h"
extern SLIST *areaList;
extern int toBeConnectedCount;
extern int _transients_flag;
extern int _global_flag;
extern int _passive_flag;
extern int _description_field_flag;
/* Struct for file descriptor linked list */
struct FDLIST {
struct FDLIST *prev;
XtInputId inpid;
int fd;
};
struct FDLIST *lastFdInList=(struct FDLIST *)0;
#define AUTOMATIC 0
#define UNKNOWN 0
/***************************************************************
get first group or channel
***************************************************************/
static GCLINK *firstGroupChannel(SLIST *proot,int *plinkType)
{
*plinkType = UNKNOWN;
if (proot == NULL ) return NULL;
if ((GCLINK *)sllFirst(proot)) *plinkType = GROUP;
return (GCLINK *)sllFirst(proot);
}
/***************************************************************
get next group or channel
***************************************************************/
static GCLINK *nextGroupChannel(GCLINK *gclink,int *plinkType)
{
SNODE *pt;
GCLINK *next=0;
GLINK *glink;
if (gclink == NULL ) return NULL;
if (*plinkType == GROUP) {
glink=(GLINK *)gclink;
/* get first child group*/
next = (GCLINK *)sllFirst(&(glink->subGroupList));
if (next) return next;
/* get first channel */
next = (GCLINK *)sllFirst(&(glink->chanList));
if (next) {
*plinkType = CHANNEL;
return next;
}
}
/* get next group or channel at same level*/
next= 0;
pt = (SNODE *)gclink;
while (pt) {
next = (GCLINK *)sllNext(pt);
if (next) return next;
pt =(SNODE *)((GCLINK *)pt)->parent;
if (pt && *plinkType == GROUP ) {
glink=(GLINK *)pt;
next = (GCLINK *)sllFirst(&(glink->chanList));
*plinkType = CHANNEL;
if (next) return next;
}
*plinkType = GROUP;
}
if (!next) *plinkType = UNKNOWN;
return next;
}
/*****************************************************************
alSetNotConnected
*****************************************************************/
void alSetNotConnected(struct mainGroup *pmainGroup)
{
GCLINK *gclink;
struct gcData *gcdata;
struct chanData *cdata;
int type;
if (!toBeConnectedCount) return;
if (pmainGroup->heartbeatPV.chid && !alCaIsConnected(pmainGroup->heartbeatPV.chid) ) {
errMsg("Heartbeat PV %s Not Connected\n",pmainGroup->heartbeatPV.name);
}
if (!pmainGroup) return;
gclink = firstGroupChannel((SLIST *)pmainGroup,&type);
while (gclink) {
gcdata = gclink->pgcData;
alForcePVSetNotConnected(gcdata->pforcePV,gcdata->name);
if (gcdata->sevrchid && !alCaIsConnected(gcdata->sevrchid) ) {
errMsg("Severity PV %s for %s Not Connected\n",
gcdata->sevrPVName, gcdata->name);
}
if (type == CHANNEL ) {
cdata = ((struct chanData *)gcdata);
if (cdata && cdata->ackPVId && !alCaIsConnected(cdata->ackPVId) ) {
errMsg("Acknowledge PV %s for %s Not Connected\n",
cdata->ackPVName, cdata->name);
}
if (cdata && cdata->chid && !alCaIsConnected(cdata->chid)) {
alNewEvent(NOT_CONNECTED,ERROR_STATE,0,-1,"",(CLINK *)gclink);
}
}
gclink = nextGroupChannel(gclink,&type);
}
}
/*****************************************************************
alPutGblAckT
*****************************************************************/
void alPutGblAckT(struct mainGroup *pmainGroup)
{
GCLINK *gclink;
struct chanData *cdata;
int type;
if (!pmainGroup) return;
if ( !_transients_flag || !_global_flag ||_passive_flag) return;
gclink = firstGroupChannel((SLIST*)pmainGroup,&type);
while (gclink) {
if (type == CHANNEL) {
cdata = ((CLINK *)gclink)->pchanData;
if ( alCaIsConnected(cdata->chid)) {
/*NOTE: ackt and defaultMask.AckT have opposite meaning */
short ackt = (cdata->defaultMask.AckT+1)%2;
alCaPutGblAckT(cdata->chid,&ackt);
}
}
gclink = nextGroupChannel(gclink,&type);
}
}
/********************************************************
Callback when there is activity on a CA file descriptor
********************************************************/
static void alProcessCA(XtPointer cd, int *source, XtInputId *id)
{
alCaPoll();
}
/********************************************************
Callback to register file descriptors
********************************************************/
void registerCA(void *dummy, int fd, int opened)
{
struct FDLIST *cur,*next;
int found;
#ifdef WIN32
#define alhInputMask XtInputReadWinsock
#else
#define alhInputMask XtInputReadMask
#endif
/* Branch depending on whether the fd is opened or closed */
if(opened) {
/* Look for a linked list structure for this fd */
cur=lastFdInList;
while(cur) {
if(cur->fd == fd) {
errMsg("Tried to add a second callback for file descriptor %d\n",fd);
return;
}
cur=cur->prev;
}
/* Allocate and fill a linked list structure for this fd */
cur=(struct FDLIST *)calloc(1,sizeof(struct FDLIST));
if(cur == NULL) {
errMsg("Could not allocate space to keep track of file descriptor %d\n",fd);
return;
}
cur->prev=lastFdInList;
cur->inpid=XtAppAddInput(appContext,fd,(XtPointer)alhInputMask,
alProcessCA,NULL);
cur->fd=fd;
lastFdInList=cur;
} else {
/* Find the linked list structure for this fd */
found=0;
cur=next=lastFdInList;
while(cur) {
if(cur->fd == fd) {
found=1;
break;
}
next=cur;
cur=cur->prev;
}
/* Remove the callback */
if(found) {
XtRemoveInput(cur->inpid);
if(cur == lastFdInList) lastFdInList=cur->prev;
else next->prev=cur->prev;
free(cur);
} else {
errMsg("Error removing callback for file descriptor %d\n",fd);
}
}
}
/********************************************************
Update all areas
********************************************************/
void alUpdateAreas()
{
ALINK *area;
area = 0;
if (areaList) area = (ALINK *)sllFirst(areaList);
while (area) {
if (area->pmainGroup && area->pmainGroup->p1stgroup){
alHighestSystemSeverity(area->pmainGroup->p1stgroup);
if ( area->pmainGroup->modified ){
if ( area->mapped && area->managed){
/*invokeDialogUpdate(area);*/
invokeSubWindowUpdate(area->treeWindow);
invokeSubWindowUpdate(area->groupWindow);
}
if (area->managed) updateCurrentAlarmWindow(area);
area->pmainGroup->modified = 0;
}
}
area = (ALINK *)sllNext(area);
}
}
/*****************************************************************
close all the channel links, groups & subwindows
*****************************************************************/
void alCaCancel(struct mainGroup *pmainGroup)
{
GCLINK *gclink;
struct gcData *gcdata;
int type;
if (!pmainGroup) return;
if (pmainGroup->heartbeatPV.chid) alCaClearChannel(&(pmainGroup->heartbeatPV.chid));
gclink = firstGroupChannel((SLIST *)pmainGroup,&type);
while (gclink) {
gcdata = gclink->pgcData;
alForcePVClearCA(gcdata->pforcePV);
alCaClearChannel(&gcdata->sevrchid);
if (type == CHANNEL) {
alCaClearEvent(&((struct chanData *)gcdata)->evid);
alCaClearChannel(&((struct chanData *)gcdata)->chid);
alCaClearChannel(&((struct chanData *)gcdata)->ackPVId);
if(_description_field_flag)
alCaClearChannel(&((struct chanData *)gcdata)->descriptionId);
}
gclink = nextGroupChannel(gclink,&type);
}
alCaPoll();
}