From bcc6cb96ae461623b16ae699b83704e5dc5349e2 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 3 Feb 2025 12:00:08 -0600 Subject: [PATCH] Added dbServerStats() API for iocStats and similar --- modules/database/src/ioc/db/dbServer.c | 20 ++++++++++++++++++++ modules/database/src/ioc/db/dbServer.h | 15 ++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/modules/database/src/ioc/db/dbServer.c b/modules/database/src/ioc/db/dbServer.c index d39b345e0..58a643573 100644 --- a/modules/database/src/ioc/db/dbServer.c +++ b/modules/database/src/ioc/db/dbServer.c @@ -127,6 +127,26 @@ int dbServerClient(char *pBuf, size_t bufSize) return -1; } +int dbServerStats(const char *name, unsigned *channels, unsigned *clients) +{ + dbServer *psrv = (dbServer *)ellFirst(&serverList); + + if (state != running || !psrv) + return -1; + + while (psrv) { + if (strcmp(name, psrv->name) == 0) { + if (!psrv->stats) + return -1; + + psrv->stats(channels, clients); + return 0; + } + psrv = (dbServer *)ellNext(&psrv->node); + } + return -1; +} + #define STARTSTOP(routine, method, newState) \ void routine(void) \ { \ diff --git a/modules/database/src/ioc/db/dbServer.h b/modules/database/src/ioc/db/dbServer.h index 326166060..d816311dd 100644 --- a/modules/database/src/ioc/db/dbServer.h +++ b/modules/database/src/ioc/db/dbServer.h @@ -17,9 +17,6 @@ * the dbServer interface provides allow the IOC to start, pause and stop * the servers together, and to provide status and debugging information * to the IOC user/developer through a common set of commands. - * - * @todo No API is provided yet for calling stats() methods. - * Nothing in the IOC calls dbStopServers(), not sure where it should go. */ #ifndef INC_dbServer_H @@ -145,6 +142,18 @@ DBCORE_API void dbsr(unsigned level); */ DBCORE_API int dbServerClient(char *pBuf, size_t bufSize); +/** @brief Fetch statistics from named server. + * + * This is an API for iocStats and similar to fetch the number of channels + * and clients connected to the named server layer. + * @param name Server name + * @param channels Where to return the channel count + * @param clients Where to return the client count + * @returns 0 on success; -1 if IOC isn't running, no such named server, + * or that server doesn't implement the stats method. + */ +DBCORE_API int dbServerStats(const char *name, unsigned *channels, unsigned *clients); + /** @brief Initialize all registered servers. * * Calls all dbServer::init() methods.