18 #include "dbAccessDefs.h" 19 #include "dbConvertFast.h" 42 static lset lnkConst_lset;
56 clink = calloc(1,
sizeof(*clink));
69 static void lnkConst_free(
jlink *pjlink)
73 switch (clink->
type) {
76 for (i=0; i<clink->
nElems; i++)
93 static jlif_result lnkConst_integer(
jlink *pjlink,
long long num)
96 int newElems = clink->
nElems + 1;
98 switch (clink->
type) {
105 printf(
" si64 := %lld\n", num);
119 printf(
" ai64 += %lld\n", num);
130 printf(
" af64 += %lld\n", num);
141 return jlif_continue;
144 static jlif_result lnkConst_boolean(
jlink *pjlink,
int val)
146 return lnkConst_integer(pjlink, val);
149 static jlif_result lnkConst_double(
jlink *pjlink,
double num)
152 int newElems = clink->
nElems + 1;
154 switch (clink->
type) {
171 f64buf[clink->
nElems] = num;
180 for (i = 0; i < clink->
nElems; i++) {
184 f64buf[clink->
nElems] = num;
197 return jlif_continue;
200 static jlif_result lnkConst_string(
jlink *pjlink,
const char *val,
size_t len)
203 int newElems = clink->
nElems + 1;
205 switch (clink->
type) {
213 strncpy(str, val, len);
223 vec = realloc(clink->
value.
pmem, newElems *
sizeof(
char *));
230 strncpy(str, val, len);
245 return jlif_continue;
248 static jlif_result lnkConst_start_array(
jlink *pjlink)
258 return jlif_continue;
261 static jlif_result lnkConst_end_array(
jlink *pjlink)
263 return jlif_continue;
266 static struct lset* lnkConst_get_lset(
const jlink *pjlink)
268 return &lnkConst_lset;
287 static void lnkConst_report(
const jlink *pjlink,
int level,
int indent)
290 const char *
const type_names[4] = {
291 "bug",
"integer",
"double",
"string" 293 const char *
const dtype = type_names[clink->
type & 3];
296 const char *
const plural = clink->
nElems > 1 ?
"s" :
"";
298 printf(
"%*s'const': array of %d %s%s", indent,
"",
299 clink->
nElems, dtype, plural);
307 switch (clink->
type) {
310 for (i = 1; i < clink->
nElems; i++) {
316 for (i = 1; i < clink->
nElems; i++) {
322 for (i = 1; i < clink->
nElems; i++) {
334 printf(
"%*s'const': %s", indent,
"", dtype);
336 switch (clink->
type) {
354 static void lnkConst_remove(
struct dbLocker *locker,
struct link *plink)
359 static long lnkConst_loadScalar(
struct link *plink,
short dbrType,
void *
pbuffer)
365 return S_db_badDbrtype;
367 switch (clink->
type) {
369 if (clink->
jlink.debug)
371 status = dbFastPutConvertRoutine[
DBF_INT64][dbrType]
376 if (clink->
jlink.debug)
378 status = dbFastPutConvertRoutine[
DBF_DOUBLE][dbrType]
383 if (clink->
jlink.debug)
385 status = dbFastPutConvertRoutine[
DBF_STRING][dbrType]
390 if (clink->
jlink.debug)
392 status = dbFastPutConvertRoutine[
DBF_INT64][dbrType]
397 if (clink->
jlink.debug)
399 status = dbFastPutConvertRoutine[
DBF_DOUBLE][dbrType]
404 if (clink->
jlink.debug)
406 status = dbFastPutConvertRoutine[
DBF_STRING][dbrType]
411 if (clink->
jlink.debug)
413 status = S_db_badField;
428 switch (clink->
type) {
430 if (clink->
jlink.debug)
436 if (clink->
jlink.debug)
442 if (clink->
jlink.debug)
444 return S_db_badField;
447 strncpy(
pbuffer, pstr, --size);
453 static long lnkConst_loadArray(
struct link *plink,
short dbrType,
void *
pbuffer,
464 return S_db_badDbrtype;
466 dbrSize = dbValueSize(dbrType);
471 switch (clink->
type) {
475 if (clink->
jlink.debug)
477 status = dbFastPutConvertRoutine[
DBF_INT64][dbrType]
482 if (clink->
jlink.debug)
484 status = dbFastPutConvertRoutine[
DBF_DOUBLE][dbrType]
489 if (clink->
jlink.debug)
491 status = dbFastPutConvertRoutine[
DBF_STRING][dbrType]
496 if (clink->
jlink.debug)
498 conv = dbFastPutConvertRoutine[
DBF_INT64][dbrType];
499 for (i = 0; i <
nElems; i++) {
507 if (clink->
jlink.debug)
509 conv = dbFastPutConvertRoutine[
DBF_DOUBLE][dbrType];
510 for (i = 0; i <
nElems; i++) {
518 if (clink->
jlink.debug)
520 conv = dbFastPutConvertRoutine[
DBF_STRING][dbrType];
521 for (i = 0; i <
nElems; i++) {
529 if (clink->
jlink.debug)
531 status = S_db_badField;
537 static long lnkConst_getNelements(
const struct link *plink,
long *nelements)
543 static long lnkConst_getValue(
struct link *plink,
short dbrType,
void *
pbuffer,
551 static long lnkConst_putValue(
struct link *plink,
short dbrType,
552 const void *
pbuffer,
long nRequest)
560 static lset lnkConst_lset = {
562 NULL, lnkConst_remove,
563 lnkConst_loadScalar, lnkConst_loadLS, lnkConst_loadArray,
NULL,
564 NULL, lnkConst_getNelements, lnkConst_getValue,
568 lnkConst_putValue,
NULL,
572 static jlif lnkConstIf = {
573 "const", lnkConst_alloc, lnkConst_free,
574 NULL, lnkConst_boolean, lnkConst_integer, lnkConst_double, lnkConst_string,
576 lnkConst_start_array, lnkConst_end_array,
577 NULL, lnkConst_get_lset,
578 lnkConst_report,
NULL, NULL
struct const_link const_link
enum const_link::@10 type
An EPICS-specific replacement for ANSI C's assert.
#define CONTAINER(ptr, structure, member)
Find parent object from a member pointer.
#define INVALID_DB_REQ(x)
epicsInt64 scalar_integer
Miscellaneous macro definitions.
union const_link::@11 value
epicsExportAddress(jlif, lnkConstIf)
int errlogPrintf(const char *pFormat,...)
epicsFloat64 scalar_double