60 #include "rnr/rnrconfig.h" 64 #include "rnr/dliststr.h" 79 # define DLL_EXT ".so" 81 # define DLL_EXT ".DLL" 85 #define BS_AUX_LIBDIR "/prj/lib" 89 #define BS_PLUGIN_DIR "." 92 #define BSPROXY_MOD_HASH_MIN 32 93 #define BSPROXY_MOD_HASH_MAX 256
107 #define BSPROXY_MOD_LOG_ERROR(moduri, ecode, efmt, ...) \ 108 LOGERROR("%s: \"%s\": %s(ecode=%d): " efmt, \ 109 ServerHasName(), moduri, \ 110 bsStrError(ecode), (ecode>=0? ecode: -ecode), \ 125 if( (rc = pthread_mutex_lock(&
BsModMutex)) != 0 )
128 LOGSYSERROR(
"pthread_mutex_lock()");
139 if( (rc = pthread_mutex_unlock(&
BsModMutex)) != 0 )
142 LOGSYSERROR(
"pthread_mutex_unlock()");
155 return pthread_mutex_trylock(&
BsModMutex) == 0?
true:
false;
184 for(sLibPath=DListStrIterDataFirst(pDListLibPath, &iter);
186 sLibPath=DListStrIterDataNext(&iter))
189 if( (sPath = NewSearchPathCanonicalized(sLibPath)) == NULL )
191 LOGDIAG2(
"Warning: \"%s\": Ignoring bad library path.", sLibPath);
229 if( (s = NewSearchPathCanonicalized(sModName)) == NULL )
231 LOGERROR(
"NewSearchPathCanonicalized(\"%s\") failed.", sModName);
239 if( (
DLL_EXT != NULL) && ((m <= n) || strncasecmp(s+m-n,
DLL_EXT, n)) )
242 sprintf(t,
"%s%s", s,
DLL_EXT);
275 void *dllHandle = NULL;
277 if( sModUri == NULL )
289 if( PathIsAbsolute(sModUri) )
291 if( (sFqPath = NewRealPath(sModUri)) != NULL )
293 LOGDIAG3(
"%s: trying dlopen(\"%s\").",
ServerHasName(), sFqPath);
294 dllHandle = dlopen(sFqPath, RTLD_LAZY | RTLD_GLOBAL);
304 for(sPath=DListStrIterDataFirst(
BsModDllPaths, &iter), dllHandle=NULL;
305 sPath!=NULL && dllHandle==NULL;
306 sPath=DListStrIterDataNext(&iter))
308 if( (sFqPath = NewJoinedPath(sPath, sModUri)) != NULL )
310 LOGDIAG3(
"%s: trying dlopen(\"%s\").",
ServerHasName(), sFqPath);
311 dllHandle = dlopen(sFqPath, RTLD_LAZY | RTLD_GLOBAL);
319 if( dllHandle == NULL )
321 LOGDIAG3(
"%s: trying dlopen(\"%s\").",
ServerHasName(), sModUri);
322 dllHandle = dlopen(sModUri, RTLD_LAZY | RTLD_GLOBAL);
326 if( dllHandle == NULL )
349 if( dlclose(dllHandle) != 0 )
382 sEMsg =
"Not defined";
385 "%s: %s.", sSym, sEMsg);
540 char *sKey = new_strdup(sModUri);
545 LOGERROR(
"hash_insert(%s,...) failed", sKey);
587 if( (pNode = hash_lookup(
BsModHashTbl, sModUri)) == NULL )
622 if( (pVConn =
VConnGet(hndVConn)) != NULL )
628 LOGERROR(
"%s: %s(ecode=%d): VConn=%d.",
647 if( (pVConn =
VConnGet(hndVConn)) != NULL )
653 LOGERROR(
"%s: %s(ecode=%d): VConn=%d.",
680 if( (pVConn =
VConnGet(hndVConn)) != NULL )
682 va_start(ap, sErrFmt);
688 LOGERROR(
"%s: %s(ecode=%d): VConn=%d.",
707 pRsrcTbl->
m_vecRsrc =
new(
sizeof(
void *) * (
size_t)nMaxResources);
728 if( pRsrcTbl != NULL )
772 LOGERROR(
"Internal module data corruption.");
778 pRsrcTbl->
m_vecIndex[hndVConn] = (byte_t)index;
881 bool_t bHasMatch =
false;
1027 hash_set_self_verify(
false);
1092 void *dllHandle = NULL;
1105 LOGDIAG1(
"Interface Module \"%s\" attached (refcnt=%u).",
1112 else if( (dllHandle =
ModDllOpen(sModUri)) == NULL )
1122 else if( (pModIF =
ModDllNewIF(sModUri, dllHandle)) == NULL )
1132 else if( (rc = pModIF->
m_fnModInit(sModUri, &BsModProxyCallbacks)) < 0 )
1141 else if( (rc =
ModHashAdd(sModUri, pModIF)) < 0 )
1153 LOGDIAG1(
"Interface Module \"%s\" loaded (refcnt=%u).",
1164 if( dllHandle != NULL )
1170 if( pModIF != NULL )
1211 LOGDIAG1(
"Interface Module \"%s\" unloaded (refcnt=%u).",
1219 LOGDIAG1(
"Interface Module \"%s\" detached (refcnt=%u).",
uint_t BsMsgId_T
client message id type [0-64k].
void ModCbSendRsp(BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufRsp[], size_t uRspLen)
Send module-specific repsonse callback function.
iterator over virtual connections (no pattern)
#define BSMOD_SYM_OPEN_S
open function string
BsModTraceFunc_T * BsModTraceFunc_P
pointer to msg trace func.
BsModExitFunc_P m_fnModExit
module exit
<b><i>BotSense</i></b> bsProxy IP server declarations.
Useful indirect indexing of handle to resource instance structure.
int m_rd
module resource descriptor
BotSense client application - bsProxy server-terminated core messages.
char * ModNewModUri(const char *sModName)
Convert the module name to a quasi Uniform Resource Id.
#define BSPROXY_MOD_HASH_MAX
maximum hash table size
void ModCbSendErrorRsp(BsVConnHnd_T hndVConn, BsTid_T uTid, int nECode, const char *sErrFmt,...)
Send generic error repsonse callback function.
void VConnRelease(BsVConnHnd_T hndVConn)
Release the locked virtual client.
const char * ModCbGetDevUri(BsVConnHnd_T hndVConn, char dest[], size_t n)
Copy the device URI associated with the virtual connection.
BsModRequestFunc_T * BsModRequestFunc_P
pointer to request func.
BsModCloseFunc_T * BsModCloseFunc_P
pointer to close function
static char * ModDllNewCanonicalName(const char *sModName)
Make DLL canonical file name.
#define BS_PLUGIN_DIR
bsProxy module plugin subdirectory
uint_t BsTid_T
client transaction id type [0-255].
#define BSPROXY_VCONN_NUMOF
total number of module handles
#define BSPROXY_MOD_HASH_MIN
minimum hash table size
uint_t m_uInUseCount
resources in-use count
static bool_t ModTryLock()
Try to lock module's global mutual exclusion.
BsModInfoFunc_T * BsModInfoFunc_P
pointer to mod info function
BsProxyThCtl_T * m_pThCtl
service thread
BsProxyModIF_T * ModLoad(const char *sModUri)
Load the interface module.
BsModIter_T * ModCbIterNext(BsModIter_T *pIter)
Get the next set of information given the iterator state.
static void * ModDllSym(BsProxyModIF_T *pModIF, const char *sSym)
Get the address of where the module symbol is loaded into memory.
static void ModUnlock()
Unlock module's global mutual exclusion.
static hash_t * BsModHashTbl
i/f module hash table
byte_t m_vecIndex[BSPROXY_VCONN_MOD_NUMOF]
vecIndex[handle] -> index
#define BSMOD_IS_VCONN_HANDLE(hndVConn)
Test if the handle is in the valid module virtual connection range.
void ModUnload(BsProxyModIF_T *pModIF)
Unload the interface module.
static void ModDllInit(DListStr_T *pDListLibPath)
BsModExitFunc_T * BsModExitFunc_P
pointer to exit function
#define BSMOD_SYM_TRACE_S
tracing func string
#define BS_AUX_LIBDIR
additional bsProxy library directory
static void ModDllClose(const char *sModUri, void *dllHandle)
Unload the dynamic library from the application.
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server's official name.
#define BS_OK
not an error, success
static void ModHashDeleteData(void *sModUri, void *pModIF)
Delete hash node data callback.
#define BS_ECODE_BAD_VCONN_HND
bad virtual connection handle
void ModCbRsrcTblDelete(BsModRsrcTbl_T *pRsrcTbl)
Delete an allocated resource table.
BsModCloseFunc_P m_fnModClose
device close
void * ModCbRsrcRemove(BsModRsrcTbl_T *pRsrcTbl, BsVConnHnd_T hndVConn)
Remove a resource from the resource table.
#define BSPROXY_VCONN_UNDEF
undefined virtual connection handle
static BsProxyModIF_T * ModDllNewIF(const char *sModUri, void *dllHandle)
Allocate an attached exported module interface block.
static pthread_mutex_t BsModMutex
bsProxy module operations mutex
#define BS_ECODE_NO_EXEC
cannot execute
BsModInfoFunc_P m_fnModInfo
static info
int ClientSendOkRsp(BsProxyClientHnd_T hndClient, BsTid_T uTid)
Send an ok response to the client.
Interface Module callbacks to bsProxy services type.
BsModOpenFunc_T * BsModOpenFunc_P
pointer to open function
int ModCbRsrcAdd(BsModRsrcTbl_T *pRsrcTbl, BsVConnHnd_T hndVConn, void *pRsrc)
Add a new resource to the resource table.
char * m_sDevUri
device URI
BsProxyVConn_T * VConnAcquire(BsVConnHnd_T hndVConn)
Acquire virtual connection, locking it from other threads.
#define BS_ECODE_BAD_MOD
bad interface module
static BsModProxyCb_T BsModProxyCallbacks
Interface module callbacks to bsProxy server services.
BsProxyClientHnd_T m_hndClient
proxied client handle
static int ModHashAdd(const char *sModUri, BsProxyModIF_T *pModIF)
Add the module data to the i/f module hash table.
BsModTraceFunc_P m_fnModTrace
tracing
#define BSMOD_SYM_EXIT_S
exit function string
uint_t m_uMaxResources
maximum resource count
#define BS_ECODE_NO_RSRC
no resource available
int m_rd
module's resource descriptor
static DListStr_T * BsModDllPaths
module search paths
BsProxyVConn_T * VConnGet(BsVConnHnd_T hndVConn)
Get the virtual connection entry associated with the handle.
#define BSMOD_SYM_CLOSE_S
close function string
static void ModHashDelete(BsProxyModIF_T *pModIF)
Remove and delete the module data from the i/f module hash table.
uint_t m_uRefCnt
vconn reference count for this module
#define BS_ECODE_NO_MOD
no interface module
const char * m_sModUri
module Uniform Resource Id
<b><i>BotSense</i></b> bsProxy Dynamically Linked Library module interface.
BsModRsrcTbl_T * ModCbRsrcTblNew(int nMaxResources)
Allocatae a new module resource table of fixed size.
BsModInitFunc_P m_fnModInit
module init
void ModCbSendOkRsp(BsVConnHnd_T hndVConn, BsTid_T uTid)
Send generic ok repsonse callback function.
static BsProxyModIF_T * ModHashGetIF(const char *sModUri)
Get the interface module's i/f from the module hash table.
#define BSMOD_SYM_REQUEST_S
request func string
BsVConnHnd_T m_hndVConn
virtual connection handle
#define BSMOD_SYM_INFO_S
info function string
#define BS_ECODE_INTERNAL
internal error (bug)
int ClientSendVErrorRsp(BsProxyClientHnd_T hndClient, BsTid_T uTid, int nECode, const char *sErrFmt, va_list ap)
Send va_list error response to the client.
static void * ModDllOpen(const char *sModUri)
Dynamically load bsProxy server compatible interface module library.
#define BS_ECODE_NO_VCONN
virtual connection not found
BsProxyModIF_T * ModGetLoadedIF(const char *sModUri)
Get the defined interface from a previously loaded i/f module.
#define BSMOD_SYM_INIT_S
Required Module Symbols Strings.
BsModIter_T * ModCbIterFirst(BsModIterOver_T eOver, const char *sPattern)
Start an iterator over the virtual connections matching the given pattern.
static void ModDllDeleteIF(BsProxyModIF_T *pModIF)
Delete module interface block.
int ClientSendRsp(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufRsp[], size_t uRspSize)
Send module-specific response to the client.
char * m_sModUri
module URI
#define BSMOD_RSRC_INDEX(pRsrcTbl, hndVConn)
Get the resource index given the handle.
#define BSPROXY_MOD_LOG_ERROR(moduri, ecode, efmt,...)
Log Proxy Server Module Error.
void ModCbIterDelete(BsModIter_T *pIter)
Delete the module iterator.
void ** m_vecRsrc
vecRsrc[index] -> rsrc
BsModOpenFunc_P m_fnModOpen
device open
#define DLL_EXT
standard dll library file name extension
BsModInitFunc_T * BsModInitFunc_P
pointer to init function
const char * m_sDevUri
proxied device URI or server
BsModIterOver_T
What to iterate over.
BsModIterOver_T m_eOver
iterator over enum
BsProxyModIF_T * m_pModIF
interface module I/F
void * m_dllHandle
dynamic library loader handle
<b><i>BotSense</i></b> package top-level, unifying header declarations.
void ModOneTimeInit(DListStr_T *pDListLibPath)
The bsProxy interface module handling one-time initialization.
int BsVConnHnd_T
virtual connection handle type
static void ModLock()
Lock module's global mutual exclusion.
BsModRequestFunc_P m_fnModRequest
module request