From 160aad047d6823541f1988ce7608b993cf533963 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Thu, 28 Feb 2002 00:06:02 +0000 Subject: [PATCH] new sorce file --- src/db/Makefile | 1 + src/db/dbServiceIOReadNotifyCache.cpp | 78 +++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/db/dbServiceIOReadNotifyCache.cpp diff --git a/src/db/Makefile b/src/db/Makefile index 195956cc9..d9edbb4a7 100644 --- a/src/db/Makefile +++ b/src/db/Makefile @@ -62,6 +62,7 @@ LIBSRCS += dbServiceIO.cpp LIBSRCS += dbChannelIO.cpp LIBSRCS += dbSubscriptionIO.cpp LIBSRCS += dbPutNotifyBlocker.cpp +LIBSRCS += dbServiceIOReadNotifyCache.cpp LIBRARY_IOC = dbIoc DLL_LIBS = dbStaticIoc ca Com diff --git a/src/db/dbServiceIOReadNotifyCache.cpp b/src/db/dbServiceIOReadNotifyCache.cpp new file mode 100644 index 000000000..61d016556 --- /dev/null +++ b/src/db/dbServiceIOReadNotifyCache.cpp @@ -0,0 +1,78 @@ + +#include "epicsMutex.h" +#include "tsFreeList.h" + +#include "cacIO.h" +#include "cadef.h" // this can be eliminated when the callbacks use the new interface +#include "db_access.h" // should be eliminated here in the future + +#define epicsExportSharedSymbols + +#include "db_access_routines.h" +#include "dbCAC.h" + +dbServiceIOReadNotifyCache::dbServiceIOReadNotifyCache () : + readNotifyCacheSize ( 0 ), pReadNotifyCache ( 0 ) +{ +} + +dbServiceIOReadNotifyCache::~dbServiceIOReadNotifyCache () +{ + delete this->pReadNotifyCache; +} + +void dbServiceIOReadNotifyCache::show ( unsigned level ) const +{ + if ( level > 0 ) { + printf ( "\tget call back cache location %p, and its size %lu\n", + static_cast ( this->pReadNotifyCache ), + this->readNotifyCacheSize ); + } +} + +// extra effort taken here to not hold the lock when caslling the callback +void dbServiceIOReadNotifyCache::callReadNotify ( struct dbAddr &addr, + unsigned type, unsigned long count, cacReadNotify ¬ify ) +{ + epicsAutoMutex locker ( this->mutex ); + + unsigned long size = dbr_size_n ( type, count ); + + if ( type > INT_MAX ) { + notify.exception ( ECA_BADTYPE, + "type code out of range (high side)", + type, count ); + return; + } + + if ( count > static_cast(INT_MAX) || + count > static_cast(addr.no_elements) ) { + notify.exception ( ECA_BADCOUNT, + "element count out of range (high side)", + type, count); + return; + } + + if ( this->readNotifyCacheSize < size) { + char * pTmp = new char [size]; + if ( ! pTmp ) { + notify.exception ( ECA_ALLOCMEM, + "unable to allocate callback cache", + type, count ); + return; + } + delete [] this->pReadNotifyCache; + this->pReadNotifyCache = pTmp; + this->readNotifyCacheSize = size; + } + int status = db_get_field ( &addr, static_cast ( type ), + this->pReadNotifyCache, static_cast ( count ), 0 ); + if ( status ) { + notify.exception ( ECA_GETFAIL, + "db_get_field() completed unsuccessfuly", + type, count); + } + else { + notify.completion ( type, count, this->pReadNotifyCache ); + } +}