From 8a5d1a08adde5bdaa6140baba7e81f12d3903c9b Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 3 Apr 2016 01:29:28 -0500 Subject: [PATCH] Restore loadLink to lset, move CONSTANT link code into its own source file --- src/ioc/db/Makefile | 2 + src/ioc/db/dbCa.c | 1 + src/ioc/db/dbConstLink.c | 112 +++++++++++++++++++++++++++++++++++++++ src/ioc/db/dbConstLink.h | 34 ++++++++++++ src/ioc/db/dbDbLink.c | 1 + src/ioc/db/dbLink.c | 75 ++------------------------ src/ioc/db/dbLink.h | 1 + 7 files changed, 156 insertions(+), 70 deletions(-) create mode 100644 src/ioc/db/dbConstLink.c create mode 100644 src/ioc/db/dbConstLink.h diff --git a/src/ioc/db/Makefile b/src/ioc/db/Makefile index 1b83eeaf9..3f08bbe83 100644 --- a/src/ioc/db/Makefile +++ b/src/ioc/db/Makefile @@ -18,6 +18,7 @@ INC += dbAddr.h INC += dbBkpt.h INC += dbCa.h INC += dbChannel.h +INC += dbConstLink.h INC += dbConvert.h INC += dbConvertFast.h INC += dbDbLink.h @@ -65,6 +66,7 @@ dbCore_SRCS += dbLock.c dbCore_SRCS += dbAccess.c dbCore_SRCS += dbBkpt.c dbCore_SRCS += dbChannel.c +dbCore_SRCS += dbConstLink.c dbCore_SRCS += dbConvert.c dbCore_SRCS += dbDbLink.c dbCore_SRCS += dbFastLinkConv.c diff --git a/src/ioc/db/dbCa.c b/src/ioc/db/dbCa.c index d05b8c7e5..de37682b6 100644 --- a/src/ioc/db/dbCa.c +++ b/src/ioc/db/dbCa.c @@ -709,6 +709,7 @@ static void scanLinkOnce(dbCommon *prec, caLink *pca) { } static lset dbCa_lset = { + NULL, dbCaRemoveLink, isConnected, getDBFtype, getElements, diff --git a/src/ioc/db/dbConstLink.c b/src/ioc/db/dbConstLink.c new file mode 100644 index 000000000..4666d6138 --- /dev/null +++ b/src/ioc/db/dbConstLink.c @@ -0,0 +1,112 @@ +/*************************************************************************\ +* Copyright (c) 2010 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* Copyright (c) 2002 The Regents of the University of California, as +* Operator of Los Alamos National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* dbConstLink.c + * + * Original Authors: Bob Dalesio, Marty Kraimer + * Current Author: Andrew Johnson + */ + +#include +#include +#include +#include +#include + +#include "alarm.h" +#include "cvtFast.h" +#include "dbDefs.h" +#include "ellLib.h" +#include "epicsTime.h" +#include "errlog.h" + +#define epicsExportSharedSymbols +#include "callback.h" +#include "dbAccessDefs.h" +#include "dbAddr.h" +#include "dbBase.h" +#include "dbBkpt.h" +#include "dbCa.h" +#include "dbCommon.h" +#include "dbConvertFast.h" +#include "dbConvert.h" +#include "dbDbLink.h" +#include "dbEvent.h" +#include "db_field_log.h" +#include "dbFldTypes.h" +#include "dbFldTypes.h" +#include "dbLink.h" +#include "dbLockPvt.h" +#include "dbNotify.h" +#include "dbScan.h" +#include "dbStaticLib.h" +#include "devSup.h" +#include "epicsEvent.h" +#include "errMdef.h" +#include "link.h" +#include "recGbl.h" +#include "recSup.h" +#include "special.h" + +/***************************** Constant Links *****************************/ + +/* Forward definition */ +static lset dbConst_lset; + +void dbConstInitLink(struct link *plink) +{ + plink->lset = &dbConst_lset; +} + +void dbConstAddLink(struct link *plink) +{ + plink->lset = &dbConst_lset; +} + +static long dbConstLoadLink(struct link *plink, short dbrType, void *pbuffer) +{ + if (!plink->value.constantStr) + return S_db_badField; + + plink->lset = &dbConst_lset; + + /* Constant strings are always numeric */ + if (dbrType == DBF_MENU || dbrType == DBF_ENUM || dbrType == DBF_DEVICE) + dbrType = DBF_USHORT; + + return dbFastPutConvertRoutine[DBR_STRING][dbrType] + (plink->value.constantStr, pbuffer, NULL); +} + +static long dbConstGetNelements(const struct link *plink, long *nelements) +{ + *nelements = 0; + return 0; +} + +static long dbConstGetValue(struct link *plink, short dbrType, void *pbuffer, + epicsEnum16 *pstat, epicsEnum16 *psevr, long *pnRequest) +{ + if (pnRequest) + *pnRequest = 0; + return 0; +} + +static lset dbConst_lset = { + dbConstLoadLink, + NULL, + NULL, + NULL, dbConstGetNelements, + dbConstGetValue, + NULL, NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, + NULL +}; + diff --git a/src/ioc/db/dbConstLink.h b/src/ioc/db/dbConstLink.h new file mode 100644 index 000000000..fb598ab9f --- /dev/null +++ b/src/ioc/db/dbConstLink.h @@ -0,0 +1,34 @@ +/*************************************************************************\ +* Copyright (c) 2016 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* Copyright (c) 2002 The Regents of the University of California, as +* Operator of Los Alamos National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* dbConstLink.h + * + * Created on: April 3rd, 2016 + * Author: Andrew Johnson + */ + +#ifndef INC_dbConstLink_H +#define INC_dbConstLink_H + +#include "shareLib.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct link; + +epicsShareFunc long dbConstInitLink(struct link *plink); +epicsShareFunc void dbConstAddLink(struct link *plink); + +#ifdef __cplusplus +} +#endif + +#endif /* INC_dbConstLink_H */ + diff --git a/src/ioc/db/dbDbLink.c b/src/ioc/db/dbDbLink.c index ab106f77d..f35791f7d 100644 --- a/src/ioc/db/dbDbLink.c +++ b/src/ioc/db/dbDbLink.c @@ -331,6 +331,7 @@ static void dbDbScanFwdLink(struct link *plink) } static lset dbDb_lset = { + NULL, dbDbRemoveLink, dbDbIsConnected, dbDbGetDBFtype, dbDbGetElements, diff --git a/src/ioc/db/dbLink.c b/src/ioc/db/dbLink.c index 5faa437bb..c14fecc73 100644 --- a/src/ioc/db/dbLink.c +++ b/src/ioc/db/dbLink.c @@ -19,39 +19,29 @@ #include #include "alarm.h" -#include "cantProceed.h" #include "cvtFast.h" #include "dbDefs.h" #include "ellLib.h" -#include "epicsThread.h" #include "epicsTime.h" #include "errlog.h" #include "caeventmask.h" #define epicsExportSharedSymbols -#include "callback.h" #include "dbAccessDefs.h" #include "dbAddr.h" #include "dbBase.h" -#include "dbBkpt.h" #include "dbCa.h" #include "dbCommon.h" -#include "dbConvertFast.h" -#include "dbConvert.h" +#include "dbConstLink.h" #include "dbDbLink.h" -#include "dbEvent.h" #include "db_field_log.h" #include "dbFldTypes.h" -#include "dbFldTypes.h" #include "dbLink.h" #include "dbLockPvt.h" -#include "dbNotify.h" #include "dbScan.h" #include "dbStaticLib.h" #include "devSup.h" -#include "epicsEvent.h" -#include "errMdef.h" #include "link.h" #include "recGbl.h" #include "recSup.h" @@ -76,62 +66,6 @@ static const char * link_field_name(const struct link *plink) } -/***************************** Constant Links *****************************/ - -/* Forward definition */ -static lset dbConst_lset; - -static void dbConstInitLink(struct link *plink) -{ - plink->lset = &dbConst_lset; -} - -static void dbConstAddLink(struct link *plink) -{ - plink->lset = &dbConst_lset; -} - -static long dbConstLoadLink(struct link *plink, short dbrType, void *pbuffer) -{ - if (!plink->value.constantStr) - return S_db_badField; - - plink->lset = &dbConst_lset; - - /* Constant strings are always numeric */ - if (dbrType == DBF_MENU || dbrType == DBF_ENUM || dbrType == DBF_DEVICE) - dbrType = DBF_USHORT; - - return dbFastPutConvertRoutine[DBR_STRING][dbrType] - (plink->value.constantStr, pbuffer, NULL); -} - -static long dbConstGetNelements(const struct link *plink, long *nelements) -{ - *nelements = 0; - return 0; -} - -static long dbConstGetValue(struct link *plink, short dbrType, void *pbuffer, - epicsEnum16 *pstat, epicsEnum16 *psevr, long *pnRequest) -{ - if (pnRequest) - *pnRequest = 0; - return 0; -} - -static lset dbConst_lset = { - NULL, - NULL, - NULL, dbConstGetNelements, - dbConstGetValue, - NULL, NULL, NULL, - NULL, NULL, - NULL, NULL, - NULL, - NULL -}; - /***************************** Generic Link API *****************************/ void dbInitLink(struct link *plink, short dbfType) @@ -209,10 +143,11 @@ void dbAddLink(dbLocker *locker, struct link *plink, short dbfType, DBADDR *ptar long dbLoadLink(struct link *plink, short dbrType, void *pbuffer) { - if (plink->type == CONSTANT) - return dbConstLoadLink(plink, dbrType, pbuffer); + lset *plset = plink->lset; + + if (plset->loadLink) + return plset->loadLink(plink, dbrType, pbuffer); - /* Could pass a type hint to the other link types here */ return S_db_notFound; } diff --git a/src/ioc/db/dbLink.h b/src/ioc/db/dbLink.h index a2e9175df..f33f6aee3 100644 --- a/src/ioc/db/dbLink.h +++ b/src/ioc/db/dbLink.h @@ -28,6 +28,7 @@ extern "C" { struct dbLocker; typedef struct lset { + long (*loadLink)(struct link *plink, short dbrType, void *pbuffer); void (*removeLink)(struct dbLocker *locker, struct link *plink); int (*isConnected)(const struct link *plink); int (*getDBFtype)(const struct link *plink);