![]() |
botsense
3.2.0
RoadNarrows Client-Server Proxied Services Framework
|
Proxied interface module management operations. More...
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <dlfcn.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/new.h"
#include "rnr/hash.h"
#include "rnr/dliststr.h"
#include "rnr/path.h"
#include "botsense/BotSense.h"
#include "botsense/bsProxyModIF.h"
#include "botsense/bsProxyMsgs.h"
#include "bsProxy.h"
Go to the source code of this file.
Macros | |
#define | DLL_EXT ".so" |
standard dll library file name extension | |
#define | BS_AUX_LIBDIR "/prj/lib" |
additional bsProxy library directory | |
#define | BS_PLUGIN_DIR "." |
bsProxy module plugin subdirectory | |
#define | BSPROXY_MOD_HASH_MIN 32 |
minimum hash table size | |
#define | BSPROXY_MOD_HASH_MAX 256 |
maximum hash table size | |
#define | BSPROXY_MOD_LOG_ERROR(moduri, ecode, efmt, ...) |
Log Proxy Server Module Error. More... | |
Functions | |
static void | ModLock () |
Lock module's global mutual exclusion. | |
static void | ModUnlock () |
Unlock module's global mutual exclusion. | |
static bool_t | ModTryLock () |
Try to lock module's global mutual exclusion. More... | |
static void | ModDllInit (DListStr_T *pDListLibPath) |
static char * | ModDllNewCanonicalName (const char *sModName) |
Make DLL canonical file name. More... | |
static void * | ModDllOpen (const char *sModUri) |
Dynamically load bsProxy server compatible interface module library. More... | |
static void | ModDllClose (const char *sModUri, void *dllHandle) |
Unload the dynamic library from the application. More... | |
static void * | ModDllSym (BsProxyModIF_T *pModIF, const char *sSym) |
Get the address of where the module symbol is loaded into memory. More... | |
static void | ModDllDeleteIF (BsProxyModIF_T *pModIF) |
Delete module interface block. More... | |
static BsProxyModIF_T * | ModDllNewIF (const char *sModUri, void *dllHandle) |
Allocate an attached exported module interface block. More... | |
static void | ModHashDeleteData (void *sModUri, void *pModIF) |
Delete hash node data callback. More... | |
static int | ModHashAdd (const char *sModUri, BsProxyModIF_T *pModIF) |
Add the module data to the i/f module hash table. More... | |
static void | ModHashDelete (BsProxyModIF_T *pModIF) |
Remove and delete the module data from the i/f module hash table. More... | |
static BsProxyModIF_T * | ModHashGetIF (const char *sModUri) |
Get the interface module's i/f from the module hash table. More... | |
void | ModCbSendRsp (BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufRsp[], size_t uRspLen) |
Send module-specific repsonse callback function. More... | |
void | ModCbSendOkRsp (BsVConnHnd_T hndVConn, BsTid_T uTid) |
Send generic ok repsonse callback function. More... | |
void | ModCbSendErrorRsp (BsVConnHnd_T hndVConn, BsTid_T uTid, int nECode, const char *sErrFmt,...) |
Send generic error repsonse callback function. More... | |
BsModRsrcTbl_T * | ModCbRsrcTblNew (int nMaxResources) |
Allocatae a new module resource table of fixed size. More... | |
void | ModCbRsrcTblDelete (BsModRsrcTbl_T *pRsrcTbl) |
Delete an allocated resource table. More... | |
int | ModCbRsrcAdd (BsModRsrcTbl_T *pRsrcTbl, BsVConnHnd_T hndVConn, void *pRsrc) |
Add a new resource to the resource table. More... | |
void * | ModCbRsrcRemove (BsModRsrcTbl_T *pRsrcTbl, BsVConnHnd_T hndVConn) |
Remove a resource from the resource table. More... | |
const char * | ModCbGetDevUri (BsVConnHnd_T hndVConn, char dest[], size_t n) |
Copy the device URI associated with the virtual connection. More... | |
void | ModCbIterDelete (BsModIter_T *pIter) |
Delete the module iterator. More... | |
BsModIter_T * | ModCbIterNext (BsModIter_T *pIter) |
Get the next set of information given the iterator state. More... | |
BsModIter_T * | ModCbIterFirst (BsModIterOver_T eOver, const char *sPattern) |
Start an iterator over the virtual connections matching the given pattern. More... | |
void | ModOneTimeInit (DListStr_T *pDListLibPath) |
The bsProxy interface module handling one-time initialization. More... | |
char * | ModNewModUri (const char *sModName) |
Convert the module name to a quasi Uniform Resource Id. More... | |
BsProxyModIF_T * | ModGetLoadedIF (const char *sModUri) |
Get the defined interface from a previously loaded i/f module. More... | |
BsProxyModIF_T * | ModLoad (const char *sModUri) |
Load the interface module. More... | |
void | ModUnload (BsProxyModIF_T *pModIF) |
Unload the interface module. More... | |
Variables | |
static pthread_mutex_t | BsModMutex |
bsProxy module operations mutex | |
static hash_t * | BsModHashTbl |
i/f module hash table | |
static DListStr_T * | BsModDllPaths |
module search paths | |
static BsModProxyCb_T | BsModProxyCallbacks |
Interface module callbacks to bsProxy server services. More... | |
Proxied interface module management operations.
Definition in file bsProxyMod.c.
#define BSPROXY_MOD_LOG_ERROR | ( | moduri, | |
ecode, | |||
efmt, | |||
... | |||
) |
Log Proxy Server Module Error.
moduri | Module URI string. |
ecode |
Definition at line 107 of file bsProxyMod.c.
Referenced by ModDllClose(), ModDllOpen(), ModDllSym(), and ModLoad().
const char* ModCbGetDevUri | ( | BsVConnHnd_T | hndVConn, |
char | dest[], | ||
size_t | n | ||
) |
Copy the device URI associated with the virtual connection.
hndVConn | Virtual connection handle. | |
[out] | dest | Destination buffer. |
n | Size of buffer. |
Definition at line 832 of file bsProxyMod.c.
References BsProxyVConn_T::m_pThCtl, _bsproxy_th_ctl::m_sDevUri, VConnAcquire(), and VConnRelease().
void ModCbIterDelete | ( | BsModIter_T * | pIter | ) |
Delete the module iterator.
pIter | Module iterator. |
Definition at line 855 of file bsProxyMod.c.
References BsModIter_T::m_sDevUri, and BsModIter_T::m_sModUri.
Referenced by ModCbIterFirst(), and ModCbIterNext().
BsModIter_T* ModCbIterFirst | ( | BsModIterOver_T | eOver, |
const char * | sPattern | ||
) |
Start an iterator over the virtual connections matching the given pattern.
If a virtual connection match is found, an iterator is allocated and its data is filled with the first set of information.
The caller must delete the iterator by calling ModCbIterNext() until there are no more matches (auto-delete) or by calling ModCbIterDelete().
eOver | What pattern to iterator over (see BsModIterOver_T). |
sPattern | Device or module URI pattern string. |
Definition at line 959 of file bsProxyMod.c.
References BsModIterOverDevUri, BsModIterOverModUri, BsModIterOverVConn, BsModIter_T::m_eOver, BsModIter_T::m_hndVConn, BsModIter_T::m_rd, BsModIter_T::m_sDevUri, BsModIter_T::m_sModUri, ModCbIterDelete(), and ModCbIterNext().
BsModIter_T* ModCbIterNext | ( | BsModIter_T * | pIter | ) |
Get the next set of information given the iterator state.
If a virtual connection match is found, an iterator data is updated.
If no match is found, the iterator is auto-deleted.
pIter | Initialized, allocated iterator. |
Definition at line 877 of file bsProxyMod.c.
References BsModIterOverDevUri, BsModIterOverModUri, BsModIterOverVConn, BSPROXY_VCONN_NUMOF, BsModIter_T::m_eOver, BsModIter_T::m_hndVConn, BsProxyVConn_T::m_pModIF, BsProxyVConn_T::m_pThCtl, BsProxyVConn_T::m_rd, BsModIter_T::m_rd, _bsproxy_th_ctl::m_sDevUri, BsModIter_T::m_sDevUri, BsProxyModIF_T::m_sModUri, BsModIter_T::m_sModUri, ModCbIterDelete(), VConnAcquire(), and VConnRelease().
Referenced by ModCbIterFirst().
int ModCbRsrcAdd | ( | BsModRsrcTbl_T * | pRsrcTbl, |
BsVConnHnd_T | hndVConn, | ||
void * | pRsrc | ||
) |
Add a new resource to the resource table.
pRsrcTbl | Pointer to resource table. |
hndVConn | Virtual connection handle. |
pRsrc | Pointer to allocated resource associated with handle. |
Definition at line 744 of file bsProxyMod.c.
References BS_ECODE_BAD_VCONN_HND, BS_ECODE_INTERNAL, BS_ECODE_NO_RSRC, BSMOD_IS_VCONN_HANDLE, BsModRsrcTbl_T::m_uInUseCount, BsModRsrcTbl_T::m_uMaxResources, BsModRsrcTbl_T::m_vecIndex, and BsModRsrcTbl_T::m_vecRsrc.
void* ModCbRsrcRemove | ( | BsModRsrcTbl_T * | pRsrcTbl, |
BsVConnHnd_T | hndVConn | ||
) |
Remove a resource from the resource table.
The resource is not deleted.
pRsrcTbl | Pointer to resource table. |
hndVConn | Virtual connection handle. |
Definition at line 795 of file bsProxyMod.c.
References BSMOD_IS_VCONN_HANDLE, BSMOD_RSRC_INDEX, BSPROXY_VCONN_UNDEF, BsModRsrcTbl_T::m_uInUseCount, BsModRsrcTbl_T::m_vecIndex, and BsModRsrcTbl_T::m_vecRsrc.
void ModCbRsrcTblDelete | ( | BsModRsrcTbl_T * | pRsrcTbl | ) |
Delete an allocated resource table.
pRsrcTbl | Pointer to resource table. |
Definition at line 726 of file bsProxyMod.c.
References BsModRsrcTbl_T::m_vecRsrc.
BsModRsrcTbl_T* ModCbRsrcTblNew | ( | int | nMaxResources | ) |
Allocatae a new module resource table of fixed size.
The resource table is indexed by the virtual connection handle.
nMaxResources | Maximum number of simultaneous resources supported. |
Definition at line 703 of file bsProxyMod.c.
References BSPROXY_VCONN_UNDEF, BsModRsrcTbl_T::m_uInUseCount, BsModRsrcTbl_T::m_uMaxResources, BsModRsrcTbl_T::m_vecIndex, and BsModRsrcTbl_T::m_vecRsrc.
void ModCbSendErrorRsp | ( | BsVConnHnd_T | hndVConn, |
BsTid_T | uTid, | ||
int | nECode, | ||
const char * | sErrFmt, | ||
... | |||
) |
Send generic error repsonse callback function.
hndVConn | Virtual connection handle. |
uTid | Request-Response transaction id. |
nECode | One of BotSense Error Codes. |
sErrFmt | Error format string. |
... | Format string variable arguments. |
Definition at line 671 of file bsProxyMod.c.
References BS_ECODE_NO_VCONN, ClientSendVErrorRsp(), BsProxyVConn_T::m_hndClient, ServerHasName(), and VConnGet().
void ModCbSendOkRsp | ( | BsVConnHnd_T | hndVConn, |
BsTid_T | uTid | ||
) |
Send generic ok repsonse callback function.
hndVConn | Virtual connection handle. |
uTid | Request-Response transaction id. |
Definition at line 643 of file bsProxyMod.c.
References BS_ECODE_NO_VCONN, ClientSendOkRsp(), BsProxyVConn_T::m_hndClient, ServerHasName(), and VConnGet().
void ModCbSendRsp | ( | BsVConnHnd_T | hndVConn, |
BsTid_T | uTid, | ||
BsMsgId_T | uMsgId, | ||
byte_t | bufRsp[], | ||
size_t | uRspLen | ||
) |
Send module-specific repsonse callback function.
hndVConn | Virtual connection handle. |
uTid | Request-Response transaction id. |
uMsgId | Response message id. |
bufRsp | Packed repsonse message body. |
uRspLen | Length of response in buffer (number of bytes). |
Definition at line 614 of file bsProxyMod.c.
References BS_ECODE_NO_VCONN, ClientSendRsp(), BsProxyVConn_T::m_hndClient, ServerHasName(), and VConnGet().
|
static |
Unload the dynamic library from the application.
sModUri | Expanded, canonical name of the interface module. |
dllHandle | DLL handle. |
Definition at line 344 of file bsProxyMod.c.
References BS_ECODE_NO_EXEC, and BSPROXY_MOD_LOG_ERROR.
Referenced by ModUnload().
|
static |
Delete module interface block.
pModIF | Exported module interface. |
Definition at line 396 of file bsProxyMod.c.
References BsProxyModIF_T::m_sModUri.
Referenced by ModDllNewIF(), ModHashDeleteData(), and ModLoad().
|
static |
Initialize Dynamic Link Loader operating parameters.
pDListLibPath | List of optional library search paths. |
For i/f module search path order:
Definition at line 175 of file bsProxyMod.c.
References BS_AUX_LIBDIR, BS_PLUGIN_DIR, and BsModDllPaths.
Referenced by ModOneTimeInit().
|
static |
Make DLL canonical file name.
The library path is expanded, canonicalized and any necessary file extension is appended.
sModName | DLL library path name. |
Definition at line 222 of file bsProxyMod.c.
References DLL_EXT.
Referenced by ModNewModUri().
|
static |
Allocate an attached exported module interface block.
sModUri | Expanded, canonical name of the interface module. |
dllHandle | DLL handle. |
Definition at line 420 of file bsProxyMod.c.
References BS_ECODE_BAD_MOD, BS_OK, BSMOD_SYM_CLOSE_S, BSMOD_SYM_EXIT_S, BSMOD_SYM_INFO_S, BSMOD_SYM_INIT_S, BSMOD_SYM_OPEN_S, BSMOD_SYM_REQUEST_S, BSMOD_SYM_TRACE_S, BsProxyModIF_T::m_dllHandle, BsProxyModIF_T::m_fnModClose, BsProxyModIF_T::m_fnModExit, BsProxyModIF_T::m_fnModInfo, BsProxyModIF_T::m_fnModInit, BsProxyModIF_T::m_fnModOpen, BsProxyModIF_T::m_fnModRequest, BsProxyModIF_T::m_fnModTrace, BsProxyModIF_T::m_sModUri, BsProxyModIF_T::m_uRefCnt, ModDllDeleteIF(), and ModDllSym().
Referenced by ModLoad().
|
static |
Dynamically load bsProxy server compatible interface module library.
If the module path name is absolute, the only library at that location is attempted to be loaded. Otherwise, a series of path locations are searched for the library.
sModUri | Expanded, canonical name of the interface module. |
< paths dlist iterator
< a dll path
< fully qualified path name
< loaded dll handle
Definition at line 270 of file bsProxyMod.c.
References BS_ECODE_NO_MOD, BsModDllPaths, BSPROXY_MOD_LOG_ERROR, and ServerHasName().
Referenced by ModLoad().
|
static |
Get the address of where the module symbol is loaded into memory.
pModIF | Exported module interface. |
sSym | Symbol name. |
Definition at line 365 of file bsProxyMod.c.
References BS_ECODE_BAD_MOD, BSPROXY_MOD_LOG_ERROR, BsProxyModIF_T::m_dllHandle, and BsProxyModIF_T::m_sModUri.
Referenced by ModDllNewIF().
BsProxyModIF_T* ModGetLoadedIF | ( | const char * | sModUri | ) |
Get the defined interface from a previously loaded i/f module.
Multi-Thread safe.
sModUri | Interface module expanded, canonical name. |
Definition at line 1058 of file bsProxyMod.c.
References ModHashGetIF(), ModLock(), and ModUnlock().
Referenced by ClientSetTraceState().
|
static |
Add the module data to the i/f module hash table.
sModUri | Allocated interface module hash table key. |
pModIF | Allocated interface module hash table value. |
Definition at line 538 of file bsProxyMod.c.
References BS_ECODE_NO_RSRC, BS_OK, BsModHashTbl, and ModHashDeleteData().
Referenced by ModLoad().
|
static |
Remove and delete the module data from the i/f module hash table.
pModIF | Allocated interface module hash table value. |
Definition at line 560 of file bsProxyMod.c.
References BsModHashTbl, and BsProxyModIF_T::m_sModUri.
Referenced by ModUnload().
|
static |
Delete hash node data callback.
Both the key and value are dynamically allocated.
sModUri | Interface module hash table key. |
pModIF | Interface module hash table value. |
Definition at line 524 of file bsProxyMod.c.
References ModDllDeleteIF().
Referenced by ModHashAdd(), and ModOneTimeInit().
|
static |
Get the interface module's i/f from the module hash table.
sModUri | Interface module hash table key. |
Definition at line 583 of file bsProxyMod.c.
References BsModHashTbl.
Referenced by ModGetLoadedIF(), ModLoad(), and ModUnload().
BsProxyModIF_T* ModLoad | ( | const char * | sModUri | ) |
Load the interface module.
The module's expanded, canonical name is determined, the dynamic library is loaded, the module's exported interface is attached, and the module's initialization routine is called.
The the same module is loaded again, the reference count is bumped and the already attached interface is returned.
Multi-Thread safe.
sModUri | Interface module expanded, canonical name. |
Definition at line 1089 of file bsProxyMod.c.
References BS_ECODE_BAD_MOD, BS_ECODE_NO_MOD, BS_ECODE_NO_RSRC, BS_OK, BSPROXY_MOD_LOG_ERROR, BsProxyModIF_T::m_fnModInit, BsProxyModIF_T::m_sModUri, BsProxyModIF_T::m_uRefCnt, ModDllDeleteIF(), ModDllNewIF(), ModDllOpen(), ModHashAdd(), ModHashGetIF(), ModLock(), and ModUnlock().
Referenced by ClientSetTraceState(), and VConnOpenDev().
char* ModNewModUri | ( | const char * | sModName | ) |
Convert the module name to a quasi Uniform Resource Id.
sModName | Module path name. |
Definition at line 1042 of file bsProxyMod.c.
References ModDllNewCanonicalName().
Referenced by ClientSetTraceState(), and VConnOpenDev().
void ModOneTimeInit | ( | DListStr_T * | pDListLibPath | ) |
The bsProxy interface module handling one-time initialization.
pDListLibPath | List of optional library search paths. |
Definition at line 1013 of file bsProxyMod.c.
References BsModHashTbl, BsModMutex, BSPROXY_MOD_HASH_MAX, BSPROXY_MOD_HASH_MIN, ModDllInit(), and ModHashDeleteData().
Referenced by ClientSetTraceState(), and main().
|
inlinestatic |
Try to lock module's global mutual exclusion.
Definition at line 153 of file bsProxyMod.c.
References BsModMutex.
void ModUnload | ( | BsProxyModIF_T * | pModIF | ) |
Unload the interface module.
The module's reference count is decremented. If the count is zero, then the module's exit routine is called and the module dynamic library is unloaded from bsProxy server application.
Multi-Thread safe.
pModIF | Exported module interface. |
Definition at line 1191 of file bsProxyMod.c.
References BsProxyModIF_T::m_dllHandle, BsProxyModIF_T::m_fnModExit, BsProxyModIF_T::m_sModUri, BsProxyModIF_T::m_uRefCnt, ModDllClose(), ModHashDelete(), ModHashGetIF(), ModLock(), and ModUnlock().
Referenced by ClientSetTraceState(), VConnClose(), and VConnOpenDev().
|
static |
Interface module callbacks to bsProxy server services.
Definition at line 988 of file bsProxyMod.c.