From 29afb880062973b095cb282fa9f645577e7e0250 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 24 Mar 2016 10:30:36 -0400 Subject: [PATCH] add broken lset --- src/ioc/db/dbCa.h | 4 +++- src/ioc/db/dbLink.c | 55 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/ioc/db/dbCa.h b/src/ioc/db/dbCa.h index 4ddab6436..c70a94f9a 100644 --- a/src/ioc/db/dbCa.h +++ b/src/ioc/db/dbCa.h @@ -49,7 +49,9 @@ extern struct ca_client_context * dbCaClientContext; #ifdef EPICS_DBCA_PRIVATE_API epicsShareFunc void dbCaSync(void); -void dbCaReportLink(const struct link *plink, dbLinkReportInfo *pinfo); +epicsShareFunc void dbCaReportLink(const struct link *plink, dbLinkReportInfo *pinfo); +epicsShareExtern void (*dbAddLinkHook)(struct link *link, short dbfType); +epicsShareFunc void dbSetBrokenLink(struct link *link, short dbfType); #endif /* These macros are for backwards compatibility */ diff --git a/src/ioc/db/dbLink.c b/src/ioc/db/dbLink.c index 85e4b910c..c47adb307 100644 --- a/src/ioc/db/dbLink.c +++ b/src/ioc/db/dbLink.c @@ -449,9 +449,54 @@ static lset dbDb_lset = { dbDbScanFwdLink }; +static void dbBrokenReportLink(const struct link *plink, dbLinkReportInfo *pinfo) +{ + const char * fname = dbGetFieldName(pinfo->pentry), + * rname = dbGetRecordName(pinfo->pentry); + + if (pinfo->filter==dbLinkReportAll || pinfo->filter==dbLinkReportDisconnected) { + printf("%28s.%-4s --> %-28s \n", + rname, + fname, + plink->value.pv_link.pvname); + } +} + +static void dbBrokenRemoveLink(dbLocker *locker, struct link *plink) +{ + assert(!plink->value.pv_link.pvt); + plink->value.pv_link.pvt = 0; + plink->value.pv_link.backend = NULL; + plink->value.pv_link.getCvt = 0; + plink->value.pv_link.pvlMask = 0; + plink->value.pv_link.lastGetdbrType = 0; + plink->type = PV_LINK; + plink->lset = NULL; +} + +static lset broken_lset = { + LSET_API_VERSION, + dbBrokenReportLink, + dbBrokenRemoveLink +}; + /***************************** Generic Link API *****************************/ -void (*dbAddLinkHook)(struct link *link, short dbfType); +void dbSetBrokenLink(struct link *plink, short dbfType) +{ + plink->lset = &broken_lset; + plink->type = CA_LINK; + plink->value.pv_link.pvt = NULL; + plink->value.pv_link.backend = "invalid"; +} + +static +void dbCaAddLinkHook(struct link *plink, short dbfType) +{ + dbCaAddLink(NULL, plink, dbfType); +} + +void (*dbAddLinkHook)(struct link *link, short dbfType) = &dbCaAddLinkHook; /* initialize CA_LINK with possibly custom lset */ static @@ -475,12 +520,14 @@ void customlset(struct link *plink, short dbfType) { plink->lset = NULL; plink->type = PV_LINK; - plink->value.pv_link.pvt = NULL; // leaking - /* TODO, turn into CONSTANT? */ + plink->value.pv_link.pvt = NULL; /* leaking */ } if(!plink->lset) - dbCaAddLink(NULL, plink, dbfType); + dbSetBrokenLink(plink, dbfType); /* install "invalid" lset as fallback */ + assert(plink->lset); + assert(plink->type==CA_LINK); + assert(plink->lset->version==LSET_API_VERSION); } void dbInitLink(struct link *plink, short dbfType)