From 37245fe3095f722b695d08ad5cbf307245814ad5 Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Wed, 22 Mar 2000 17:13:37 +0000 Subject: [PATCH] added pvAdapter --- src/db/dbAddr.h | 4 +- src/db/dbEvent.c | 2 +- src/db/dbEvent.h | 2 +- src/db/dbNotify.c | 11 +-- src/db/dbNotify.h | 6 +- src/db/db_access.c | 131 ++++++++++++++++++++++++++++++++++++ src/db/db_access_routines.h | 2 + src/db/iocInit.c | 5 +- 8 files changed, 152 insertions(+), 11 deletions(-) diff --git a/src/db/dbAddr.h b/src/db/dbAddr.h index a47a5bdde..ed4dbf737 100644 --- a/src/db/dbAddr.h +++ b/src/db/dbAddr.h @@ -20,6 +20,8 @@ typedef struct dbAddr{ short special; /* special processing */ short dbr_field_type; /* field type as seen by database request*/ /*DBR_STRING,...,DBR_ENUM,DBR_NOACCESS*/ -}DBADDR; +}dbAddr; + +typedef dbAddr DBADDR; #endif /* dbAddrh */ diff --git a/src/db/dbEvent.c b/src/db/dbEvent.c index 0daa61189..d2ef0b020 100644 --- a/src/db/dbEvent.c +++ b/src/db/dbEvent.c @@ -944,7 +944,7 @@ LOCAL void event_task (void *pParm) * DB_START_EVENTS() */ int epicsShareAPI db_start_events ( - dbEventCtx ctx, char *taskname, void (*init_func)(threadId), + dbEventCtx ctx,const char *taskname, void (*init_func)(threadId), void *init_func_arg, int priority_offset) { struct event_user *evUser = (struct event_user *) ctx; diff --git a/src/db/dbEvent.h b/src/db/dbEvent.h index 0acfacd41..f592fe52d 100644 --- a/src/db/dbEvent.h +++ b/src/db/dbEvent.h @@ -46,7 +46,7 @@ typedef void OVRFFUNC (void *overflow_arg, unsigned count); typedef void EXTRALABORFUNC (void *extralabor_arg); epicsShareFunc dbEventCtx epicsShareAPI db_init_events (void); epicsShareFunc int epicsShareAPI db_start_events ( - dbEventCtx ctx, char *taskname, void (*init_func)(void *), + dbEventCtx ctx, const char *taskname, void (*init_func)(void *), void *init_func_arg, int priority_offset); epicsShareFunc void epicsShareAPI db_close_events (dbEventCtx ctx); epicsShareFunc void epicsShareAPI db_event_flow_ctrl_mode_on (dbEventCtx ctx); diff --git a/src/db/dbNotify.c b/src/db/dbNotify.c index a1c4e0c73..1720b5d56 100644 --- a/src/db/dbNotify.c +++ b/src/db/dbNotify.c @@ -68,7 +68,7 @@ typedef struct pnWaitNode { /*Local routines*/ static void restartAdd(PUTNOTIFY *ppnto, PUTNOTIFY *ppnfrom); static void waitAdd(struct dbCommon *precord,PUTNOTIFY *ppn); -static long putNotify(PUTNOTIFY *ppn); +static long doPutNotify(PUTNOTIFY *ppn); static void notifyCallback(CALLBACK *pcallback); static void notifyCancel(PUTNOTIFY *ppn); static void issueCallback(PUTNOTIFY *ppn); @@ -153,12 +153,12 @@ long epicsShareAPI dbPutNotify(PUTNOTIFY *ppn) dbScanLock(precord); ellInit(&ppn->restartList); memset(&ppn->restartNode,'\0',sizeof(PNRESTARTNODE)); - status = putNotify(ppn); + status = doPutNotify(ppn); dbScanUnlock(precord); return(status); } -static long putNotify(PUTNOTIFY *ppn) +static long doPutNotify(PUTNOTIFY *ppn) { struct dbAddr *paddr = ppn->paddr; short dbrType = ppn->dbrType; @@ -237,7 +237,7 @@ static void notifyCallback(CALLBACK *pcallback) } if(ppn->callbackState==callbackActive) { if(ppn->restart) { - putNotify(ppn); + doPutNotify(ppn); dbScanUnlock(precord); } else { dbScanUnlock(precord); @@ -459,4 +459,5 @@ epicsShareFunc void epicsShareAPI dbPutNotifyDestroy (dbPutNotifyID idIn) } } -#endif \ No newline at end of file +#endif + diff --git a/src/db/dbNotify.h b/src/db/dbNotify.h index 6a8a21fea..b5bff3a29 100644 --- a/src/db/dbNotify.h +++ b/src/db/dbNotify.h @@ -28,7 +28,8 @@ typedef struct pnRestartNode { ELLNODE node; struct putNotify *ppn; struct putNotify *ppnrestartList; /*ppn with restartList*/ -}PNRESTARTNODE; +}pnRestartNode; +typedef pnRestartNode PNRESTARTNODE; typedef struct putNotify{ @@ -49,7 +50,8 @@ typedef struct putNotify{ short restart; short callbackState; void *waitForCallback; -}PUTNOTIFY; +}putNotify; +typedef putNotify PUTNOTIFY; epicsShareFunc int epicsShareAPI dbPutNotifyMapType (PUTNOTIFY *ppn, short oldtype); diff --git a/src/db/db_access.c b/src/db/db_access.c index e0e22cb84..5f7d3847d 100644 --- a/src/db/db_access.c +++ b/src/db/db_access.c @@ -54,6 +54,7 @@ #include "errlog.h" #include "ellLib.h" #include "tsStamp.h" +#include "pvAdapter.h" #include "dbStaticLib.h" #include "dbBase.h" #include "dbCommon.h" @@ -63,6 +64,7 @@ #define epicsExportSharedSymbols #include "dbNotify.h" #include "dbAccessDefs.h" +#include "dbEvent.h" #include "db_access_routines.h" #ifndef NULL @@ -1608,6 +1610,135 @@ int no_elements return(0); } +pvId pvNameToId(const char *pname) +{ + int status; + dbAddr addr; + dbAddr *paddr; + status = db_name_to_addr(pname, &addr); + if(status) return(0); + paddr = dbCalloc(1,sizeof(dbAddr)); + *paddr = addr; + return(paddr); +} + +int pvPutField(pvId id, int src_type, + const void *psrc, int no_elements) +{ + dbAddr *pdbAddr = (dbAddr *)id; + return(db_put_field(pdbAddr,src_type,psrc,no_elements)); +} + +int pvGetField(pvId id, int dest_type, + void *pdest, int no_elements, void *pfl) +{ + dbAddr *pdbAddr = (dbAddr *)id; + return(db_get_field(pdbAddr,dest_type,pdest,no_elements,pfl)); +} + +long pvPutNotifyInitiate(pvId id, unsigned type, unsigned long count, + const void *pValue, putNotifyCallback func, void *usrPvt, putNotifyId * pID) +{ + return( dbPutNotifyInitiate( + (dbAddr *)id,type,count,pValue,func,usrPvt,(dbPutNotifyID *)pID)); +} + +void pvPutNotifyDestroy(putNotifyId id) +{ + dbPutNotifyDestroy((dbPutNotifyID)id); +} + +const char * pvName(pvId id) +{ + dbAddr *pdbAddr = (dbAddr *)id; + return(pdbAddr->precord->name); +} + +unsigned long pvNoElements(pvId id) +{ + dbAddr *pdbAddr = (dbAddr *)id; + return(pdbAddr->no_elements); +} + +short pvType(pvId id) +{ + dbAddr *pdbAddr = (dbAddr *)id; + return(pdbAddr->dbr_field_type); +} + +void * pvEventQueueInit(void) +{ + return((void *)db_init_events()); +} + +int pvEventQueueStart(void *id, const char *taskname, + eventQueueInit initFunc, void *init_func_arg, int priority_offset) +{ + return(db_start_events( + (dbEventCtx)id,taskname,initFunc,init_func_arg,priority_offset)); +} + +void pvEventQueueClose(void * id) +{ + db_close_events((dbEventCtx)id); +} + +int pvEventQueuePostSingleEvent(void *es) +{ + db_post_single_event((dbEventSubscription)es); +printf("pvEventQueuePostSingleEvent why does this return int\n"); + return(0); +} + +void * pvEventQueueAddEvent(void *ctx, pvId id, + eventQueueEventUser func, void *user_arg, unsigned select) +{ + return((void *)db_add_event( + (dbEventCtx)ctx,(dbAddr *)id,(EVENTFUNC*)func,user_arg,select)); +} + +void pvEventQueueCancelEvent(void *es) +{ + db_cancel_event((dbEventSubscription)es); +} + +int pvEventQueueAddExtraLaborEvent(void *ctx, + eventQueueExtraLaborUser func, void *arg) +{ + return(db_add_extra_labor_event((dbEventCtx)ctx,func,arg)); +} + +int pvEventQueuePostExtraLabor(void *ctx) +{ + return(db_post_extra_labor((dbEventCtx)ctx)); +} + + +static pvAdapter adapter = { + pvNameToId, + pvPutField, + pvGetField, + pvPutNotifyInitiate, + pvPutNotifyDestroy, + pvName, + pvNoElements, + pvType, + pvEventQueueInit, + pvEventQueueStart, + pvEventQueueClose, + pvEventQueuePostSingleEvent, + pvEventQueueAddEvent, + pvEventQueueCancelEvent, + pvEventQueueAddExtraLaborEvent, + pvEventQueuePostExtraLabor +}; + + +epicsShareFunc void epicsShareAPI db_attach_pvAdapter(void) +{ +printf("db_attach_pvAdapter I dont know what to call\n"); +} + epicsShareFunc int epicsShareAPI dbPutNotifyMapType (PUTNOTIFY *ppn, short oldtype) { switch(oldtype) { diff --git a/src/db/db_access_routines.h b/src/db/db_access_routines.h index 4b12727ca..869d830e6 100644 --- a/src/db/db_access_routines.h +++ b/src/db/db_access_routines.h @@ -43,6 +43,8 @@ epicsShareFunc int epicsShareAPI db_put_field( epicsShareFunc int epicsShareAPI db_get_field( DBADDR *paddr, int dest_type,void *pdest, int no_elements, void *pfl); +epicsShareFunc void epicsShareAPI db_attach_pvAdapter(void); + #ifdef __cplusplus } diff --git a/src/db/iocInit.c b/src/db/iocInit.c index 2e4212306..dfad14ce5 100644 --- a/src/db/iocInit.c +++ b/src/db/iocInit.c @@ -79,8 +79,10 @@ of this distribution. #include "errMdef.h" #include "recSup.h" #include "envDefs.h" -#include "rsrv.h" +epicsShareFunc int epicsShareAPI rsrv_init (void); +epicsShareFunc int epicsShareAPI asInit (void); #include "dbStaticLib.h" +#include "db_access_routines.h" #include "initHooks.h" LOCAL int initialized=FALSE; @@ -145,6 +147,7 @@ int iocInit() /* Start up CA server */ rsrv_init(); + db_attach_pvAdapter(); errlogPrintf("iocInit: All initialization complete\n"); initHooks(initHookAtEnd);