-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathdbcb.c
164 lines (131 loc) · 3.6 KB
/
dbcb.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
#include <epicsVersion.h>
#include <epicsString.h>
#include <envDefs.h>
#include <dbStaticLib.h>
#include <dbAccess.h>
#define epicsExportSharedSymbols
#include "caster.h"
const char* default_envs[] =
{
/* automatic (if unset) */
"HOSTNAME",
/* from envPaths */
"EPICS_BASE",
"TOP",
"ARCH",
"IOC",
/* CA related */
"EPICS_CA_ADDR_LIST",
"EPICS_CA_AUTO_ADDR_LIST",
"EPICS_CA_MAX_ARRAY_BYTES",
"RSRV_SERVER_PORT",
/* PVA related */
"PVAS_SERVER_PORT",
/* Common */
"PWD",
"EPICS_HOST_ARCH",
"IOCNAME",
"HOSTNAME",
/* iocStats */
"ENGINEER",
"LOCATION",
NULL
};
static int pushEnv(caster_t *caster)
{
size_t i;
int ret = 0;
if(!getenv("HOSTNAME")) {
const size_t blen = 256;
char *buf = calloc(1,blen);
if(buf && gethostname(buf, blen)==0) {
buf[blen-1] = '\0'; /* paranoia */
epicsEnvSet("HOSTNAME", buf);
}
free(buf);
}
ret = casterSendInfo(caster, 0, "EPICS_VERSION", EPICS_VERSION_STRING);
if(ret)
ERRRET(ret, caster, "Failed to send epics version");
for(i=0; !ret && default_envs[i]; i++) {
const char *val = getenv(default_envs[i]);
if(val && val[0]!='\0')
ret = casterSendInfo(caster, 0, default_envs[i], val);
if(ret)
casterMsg(caster, "Error sending env %s", default_envs[i]);
}
epicsMutexMustLock(caster->lock);
for (i = 0; !ret && i < caster->num_extra_envs; i++) {
const char *val = getenv(caster->extra_envs[i]);
if (val && val[0] != '\0')
ret = casterSendInfo(caster, 0, caster->extra_envs[i], val);
if (ret)
casterMsg(caster, "Error sending env %s", caster->extra_envs[i]);
}
epicsMutexUnlock(caster->lock);
return ret;
}
static int pushRecord(caster_t *caster, DBENTRY *pent)
{
dbCommon *prec = pent->precnode->precord;
ssize_t rid;
int ret = 0;
long status;
if(dbIsAlias(pent))
return 0;
rid = casterSendRecord(caster, prec->rdes->name, prec->name);
if(rid<=0)
return rid;
if(pent->precnode->flags & DBRN_FLAGS_HASALIAS) {
DBENTRY subent;
dbCopyEntryContents(pent, &subent);
for(status = dbFirstRecord(&subent); !ret && !status;
status = dbNextRecord(&subent))
{
if(dbIsAlias(&subent) &&
subent.precnode->precord == prec)
{
ret = casterSendAlias(caster, rid, subent.precnode->recordname);
}
}
dbFinishEntry(&subent);
}
for(status=dbFirstInfo(pent); !ret && !status;
status=dbNextInfo(pent))
{
const char *name = dbGetInfoName(pent),
*val = dbGetInfoString(pent);
if(val && val[0]!='\0')
ret = casterSendInfo(caster, rid, name, val);
}
/* send desc as INFO tag */
const char *name = "recordDesc";
const char *val= prec->desc;
if(val && val[0]!='\0')
ret = casterSendInfo(caster, rid, name, val);
return ret;
}
int casterPushPDB(void *junk, caster_t *caster)
{
DBENTRY ent;
int ret;
long rtstat, rstat;
ret = pushEnv(caster);
if(ret)
return ret;
dbInitEntry(pdbbase, &ent);
for(rtstat=dbFirstRecordType(&ent); !rtstat;
rtstat=dbNextRecordType(&ent))
{
for(rstat=dbFirstRecord(&ent); !rstat;
rstat=dbNextRecord(&ent))
{
ret = pushRecord(caster, &ent);
if(ret)
goto done;
}
}
done:
dbFinishEntry(&ent);
return ret;
}