From d27747a7f350d4057f23b99fe6ecdaaae07293f7 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 29 Nov 2012 13:21:11 -0600 Subject: [PATCH] Added helper functions dbGetLinkLS() and dbPutLinkLS() --- src/ioc/db/dbLink.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/ioc/db/dbLink.h | 4 ++++ 2 files changed, 49 insertions(+) diff --git a/src/ioc/db/dbLink.c b/src/ioc/db/dbLink.c index 8caae22e6..914252862 100644 --- a/src/ioc/db/dbLink.c +++ b/src/ioc/db/dbLink.c @@ -649,3 +649,48 @@ void dbScanFwdLink(struct link *plink) } } +/* Helper functions for long string support */ + +long dbGetLinkLS(struct link *plink, char *pbuffer, epicsUInt32 size, + epicsUInt32 *plen) +{ + int dtyp = dbGetLinkDBFtype(plink); + long len = size; + long status; + + if (dtyp < 0) /* Not connected */ + return 0; + + if (dtyp == DBR_CHAR || dtyp == DBF_UCHAR) { + status = dbGetLink(plink, dtyp, pbuffer, 0, &len); + } + else if (size >= MAX_STRING_SIZE) + status = dbGetLink(plink, DBR_STRING, pbuffer, 0, 0); + else { + /* pbuffer is too small to fetch using DBR_STRING */ + char tmp[MAX_STRING_SIZE]; + + status = dbGetLink(plink, DBR_STRING, tmp, 0, 0); + if (!status) + strncpy(pbuffer, tmp, len - 1); + } + if (!status) { + pbuffer[--len] = 0; + *plen = strlen(pbuffer) + 1; + } + return status; +} + +long dbPutLinkLS(struct link *plink, char *pbuffer, epicsUInt32 len) +{ + int dtyp = dbGetLinkDBFtype(plink); + + if (dtyp < 0) + return 0; /* Not connected */ + + if (dtyp == DBR_CHAR || dtyp == DBF_UCHAR) + return dbPutLink(plink, dtyp, pbuffer, len); + + return dbPutLink(plink, DBR_STRING, pbuffer, 1); +} + diff --git a/src/ioc/db/dbLink.h b/src/ioc/db/dbLink.h index 213327ee2..cb4b412ed 100644 --- a/src/ioc/db/dbLink.h +++ b/src/ioc/db/dbLink.h @@ -80,6 +80,10 @@ epicsShareFunc long dbGetTimeStamp(const struct link *plink, epicsShareFunc long dbPutLink(struct link *, short dbrType, const void *pbuffer, long nRequest); epicsShareFunc void dbScanFwdLink(struct link *plink); +epicsShareFunc long dbGetLinkLS(struct link *plink, char *pbuffer, + epicsUInt32 buffer_size, epicsUInt32 *plen); +epicsShareFunc long dbPutLinkLS(struct link *plink, char *pbuffer, + epicsUInt32 len); #ifdef __cplusplus }