diff --git a/src/ioc/db/Makefile b/src/ioc/db/Makefile index c957842cb..5d58542fe 100644 --- a/src/ioc/db/Makefile +++ b/src/ioc/db/Makefile @@ -26,6 +26,7 @@ INC += dbLink.h INC += dbLock.h INC += dbNotify.h INC += dbScan.h +INC += dbServer.h INC += dbTest.h INC += dbCaTest.h INC += db_test.h @@ -86,4 +87,5 @@ dbCore_SRCS += templateInstances.cpp dbCore_SRCS += dbIocRegister.c dbCore_SRCS += chfPlugin.c dbCore_SRCS += dbState.c +dbCore_SRCS += dbServer.c diff --git a/src/ioc/db/dbServer.c b/src/ioc/db/dbServer.c new file mode 100644 index 000000000..bc1094ce7 --- /dev/null +++ b/src/ioc/db/dbServer.c @@ -0,0 +1,58 @@ +/*************************************************************************\ +* Copyright (c) 2014 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +/* + * Author: Andrew Johnson + */ + +#include + +#include "ellLib.h" +#include "epicsStdio.h" + +#define epicsExportSharedSymbols +#include "dbServer.h" + +static ELLLIST serverList = ELLLIST_INIT; + + +void dbRegisterServer(dbServer *psrv) +{ + if (ellNext(&psrv->node)) { + fprintf(stderr, "dbRegisterServer: '%s' registered twice?\n", + psrv->name); + return; + } + + ellAdd(&serverList, &psrv->node); +} + +void dbsr(unsigned level) +{ + dbServer *psrv = (dbServer *)ellFirst(&serverList); + + while (psrv) { + printf("Server '%s':\n", psrv->name); + if (psrv->report) + psrv->report(level); + psrv = (dbServer *)ellNext(&psrv->node); + } +} + +int dbServerClient(char *pBuf, size_t bufSize) +{ + dbServer *psrv = (dbServer *)ellFirst(&serverList); + + while (psrv) { + if (psrv->client && + psrv->client(pBuf, bufSize) == 0) + return 0; + psrv = (dbServer *)ellNext(&psrv->node); + } + return -1; +} + diff --git a/src/ioc/db/dbServer.h b/src/ioc/db/dbServer.h new file mode 100644 index 000000000..345468676 --- /dev/null +++ b/src/ioc/db/dbServer.h @@ -0,0 +1,58 @@ +/*************************************************************************\ +* Copyright (c) 2014 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +/* + * Author: Andrew Johnson + */ + +#ifndef INC_dbServer_H +#define INC_dbServer_H + +#include + +#include "ellLib.h" +#include "shareLib.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Server information structure */ + +typedef struct dbServer { + ELLNODE node; + const char *name; + + /* Print level-dependent status report to stdout */ + void (* report) (unsigned level); + + /* Get number of channels and clients connected */ + void (* stats) (unsigned *channels, unsigned *clients); + + /* Get identity of client initiating the calling thread */ + /* Must return 0 (OK), or -1 (ERROR) from unknown threads */ + int (* client) (char *pBuf, size_t bufSize); +} dbServer; + + +epicsShareFunc void dbRegisterServer(dbServer *psrv); + +/* Extra routines could be added if/when needed: + * + * epicsShareFunc const dbServer* dbFindServer(const char *name); + * epicsShareFunc void dbIterateServers(srvIterFunc func, void *user); + */ + +epicsShareFunc void dbsr(unsigned level); + +epicsShareFunc int dbServerClient(char *pBuf, size_t bufSize); + +#ifdef __cplusplus +} +#endif + +#endif /* INC_dbServer_H */