botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
bsProxy.h File Reference

BotSense bsProxy IP server declarations. More...

#include <sys/time.h>
#include <sys/select.h>
#include <stdarg.h>
#include <pthread.h>
#include <errno.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/dlistvoid.h"
#include "rnr/dliststr.h"
#include "rnr/sock.h"
#include "rnr/sockset.h"
#include "rnr/netmsgs.h"
#include "botsense/BotSense.h"
#include "botsense/libBotSense.h"
#include "botsense/bsProxyModIF.h"
#include "botsense/bsProxyMsgs.h"

Go to the source code of this file.

Classes

struct  BsProxyModIF_T
 
struct  _bsproxy_th_ctl
 
struct  BsProxyClientCtl_T
 
struct  BsProxyServerCtl_T
 
struct  BsProxyVConn_T
 
struct  _bsproxy_th_req
 
struct  BsProxyListenIF_T
 

Macros

#define BSPROXY_TUNE_T_RECV   1000000
 1.0s receive time out
 
#define BSPROXY_TUNE_T_SEND   500000
 0.5s send time out
 
#define BSPROXY_TUNE_T_SELECT   5000000
 5.0s send select time out
 
#define BSPROXY_FD_SETSIZE   256
 server socket set size
 
#define BSPROXY_LOG_WARN(hndClient, ecode, wfmt, ...)
 Log Proxy Server Warning. More...
 
#define BSPROXY_LOG_ERROR(hndClient, ecode, efmt, ...)
 Log Proxy Server Error. More...
 
#define BSPROXY_LOG_NMERROR(hndClient, nmecode, efmt, ...)
 Log Proxy Server NetMsgs (Un)Packing Error. More...
 
#define BSPROXY_LOG_SYSERROR(hndClient, efmt, ...)
 Log Proxy Server System Error. More...
 
#define BSPROXY_SEND_ERROR_RSP(hndClient, hndVConn, uTid, ecode, efmt, ...)
 Log BotSense Error and Send Error Response. More...
 
#define BSPROXY_SEND_NMERROR_RSP(hndClient, hndVConn, uTid, nmecode, efmt, ...)
 Log NetMsgs (Un)Packing Error and Send Error Response. More...
 
#define BSPROXY_SEND_SYSERROR_RSP(hndClient, hndVConn, uTid, efmt, ...)
 Log System Error and Send Error Response. More...
 
#define BSPROXY_LOG_REQ(hndClient, pMsgHdr)
 Log client request. More...
 
#define BSPROXY_LOG_RSP(hndClient, pMsgHdr)
 Log client request. More...
 
#define BSPROXY_CHK_VCONN_HND(hndVConn)
 
#define BSPROXY_CHK_MOD_VCONN_HND(hndVConn)
 

Typedefs

typedef struct _bsproxy_th_ctlBsProxyThCtl_P
 service thread control
 
typedef struct _bsproxy_th_reqBsProxyThReq_P
 service thread request
 
typedef int BsProxyClientHnd_T
 bsProxy server client handle
 
typedef struct _bsproxy_th_ctl BsProxyThCtl_T
 
typedef struct _bsproxy_th_req BsProxyThReq_T
 

Enumerations

enum  BsProxyThState_T {
  BsProxyThStateUninit,
  BsProxyThStateInit,
  BsProxyThStateRunning,
  BsProxyThStateExit
}
 Service thread states. More...
 
enum  BsProxyClientState_T {
  BsProxyClientStateInit,
  BsProxyClientStateNominal,
  BsProxyClientStateReSync,
  BsProxyClientStateZombie
}
 

Functions

static void timer_mark (struct timeval *pTvMark)
 Mark the current time. Resolution is microseconds. More...
 
uint_t timer_elapsed (struct timeval *pTvMark)
 Calculate the elapsed time between the given time mark and this call. More...
 
INLINE_IN_H BsProxyServerCtl_TServerGet ()
 Get the BotSense server. More...
 
INLINE_IN_H const char * ServerHasName ()
 Get the BotSense server's official name. More...
 
INLINE_IN_H const char * ServerHasAddr ()
 Get the BotSense server's listening address. More...
 
INLINE_IN_H int ServerHasPort ()
 Get the BotSense server's listening port. More...
 
INLINE_IN_H int ServerClientHnd2Sd (BsProxyClientHnd_T hndClient)
 Convert the BotSense server client handle to client socket descriptor. More...
 
INLINE_IN_H BsProxyClientHnd_T ServerClientSd2Hnd (int sd)
 Convert the BotSense server client socket descriptor to client handle. More...
 
INLINE_IN_H BsProxyClientCtl_TServerGetClient (BsProxyClientHnd_T hndClient)
 Get the BotSense server client. More...
 
INLINE_IN_H const char * ClientThisHasName (BsProxyClientCtl_T *pClient)
 Get this BotSense client official name. More...
 
INLINE_IN_H const char * ClientHasName (BsProxyClientHnd_T hndClient)
 Get the BotSense client official name. More...
 
INLINE_IN_H bool_t ClientGetTraceState (BsProxyClientHnd_T hndClient)
 Get the BotSense client's server-terminated message trace state. More...
 
INLINE_IN_H void ClientSetTraceState (BsProxyClientHnd_T hndClient, bool_t bTrace)
 Set the BotSense client's server-terminated message trace state. More...
 
void BsProxyLogMsgHdr (const char *sPreface, BsProxyMsgHdr_T *pMsgHdr)
 Log message header. More...
 
void ClientOneTimeInit ()
 The BotSense bsProxy server one-time client control initialization.
 
BsProxyClientCtl_TClientAcquire (BsProxyClientHnd_T hndClient)
 Acquire client, locking it from other threads. More...
 
void ClientRelease (BsProxyClientHnd_T hndClient)
 Release the locked client. More...
 
BsProxyClientCtl_TClientNew (Socket_T *pSockClient)
 Create new client control structure. More...
 
void ClientDelete (BsProxyClientCtl_T *pClient)
 Delete a client with the server. More...
 
void ClientSetState (BsProxyClientCtl_T *pClient, BsProxyClientState_T eNewState)
 Set client's state. More...
 
int ClientRecvReq (BsProxyClientHnd_T hndClient, BsProxyMsgHdr_T *pMsgHdr, byte_t **addrBuf)
 Receive a request message from client. More...
 
int ClientSendOkRsp (BsProxyClientHnd_T hndClient, BsTid_T uTid)
 Send an ok response to the client. More...
 
int ClientSendErrorRsp (BsProxyClientHnd_T hndClient, BsTid_T uTid, int nECode, const char *sErrFmt,...)
 Send an error response to the client. More...
 
int ClientSendVErrorRsp (BsProxyClientHnd_T hndClient, BsTid_T uTid, int nECode, const char *sErrFmt, va_list ap)
 Send va_list error response to the client. More...
 
int ClientSendServerRsp (BsProxyClientHnd_T hndClient, BsTid_T uTid, BsProxyMsgId_T uMsgId, void *pMsgRsp)
 Send a server-terminated response message to client. More...
 
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. More...
 
void VConnOneTimeInit ()
 The bsProxy virtual connections one-time initialization.
 
BsProxyVConn_TVConnNew ()
 Create a new, allocated virtual connection entry. More...
 
void VConnDelete (BsProxyVConn_T *pVConn)
 Delete allocated virtual connection entry. More...
 
BsProxyVConn_TVConnGet (BsVConnHnd_T hndVConn)
 Get the virtual connection entry associated with the handle. More...
 
int VConnOpenServer ()
 Open special server virtual connection. More...
 
int VConnOpenDev (BsProxyClientHnd_T hndClient, const char *sDevName, const char *sModName, byte_t argbuf[], size_t uArgLen, bool_t bTrace)
 Open a virtual device connection. More...
 
int VConnClose (BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn)
 Close the virtual connection. More...
 
BsProxyVConn_TVConnAcquire (BsVConnHnd_T hndVConn)
 Acquire virtual connection, locking it from other threads. More...
 
void VConnRelease (BsVConnHnd_T hndVConn)
 Release the locked virtual client. 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_TModGetLoadedIF (const char *sModUri)
 Get the defined interface from a previously loaded i/f module. More...
 
BsProxyModIF_TModLoad (const char *sModUri)
 Load the interface module. More...
 
void ModUnload (BsProxyModIF_T *pModIF)
 Unload the interface module. More...
 
BsProxyThReq_TThReqNew (BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
 Allocate and initalized a new service thread request. More...
 
void ThReqDelete (BsProxyThReq_T *pThReq)
 Delete service thread request. More...
 
int ThQueue (BsProxyThCtl_T *pThCtl, BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
 Queue a request for the given service thread. More...
 
BsProxyThReq_TThDequeue (BsProxyThCtl_T *pThCtl)
 Dequeue a request for the given service thread. More...
 
void ThOneTimeInit ()
 The service thread one-time global initialization.
 
char * ThNewDevUri (const char *sDevName)
 Convert the device name to a quasi Uniform Resource Id. More...
 
BsProxyThCtl_TThCreateDevThread (const char *sDevUri)
 Create a device service thread. More...
 
BsProxyThCtl_TThCreateServerThread ()
 Create the special server service thread. More...
 
void ThDestroyThread (BsProxyThCtl_T *pThCtl)
 Destroy service thread. More...
 
int ServerRequest (BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
 Server service thread request handler. More...
 

Variables

BsProxyServerCtl_TBsServerCtl
 The server control block. More...
 

Detailed Description

BotSense bsProxy IP server declarations.

LastChangedDate
2010-08-23 09:53:11 -0600 (Mon, 23 Aug 2010)
Rev
570
Todo:

Add support for botsense configuration XML files.

Add fork-exec'ing to support multiple interfaces.

Author
Robin Knight (robin.nosp@m..kni.nosp@m.ght@r.nosp@m.oadn.nosp@m.arrow.nosp@m.s.co.nosp@m.m)

Definition in file bsProxy.h.

Macro Definition Documentation

#define BSPROXY_CHK_MOD_VCONN_HND (   hndVConn)
Value:
(((int)(hndVConn) >= BSPROXY_VCONN_MOD_MIN) && \
((int)(hndVConn) <= BSPROXY_VCONN_MOD_MAX))
#define BSPROXY_VCONN_MOD_MIN
minimum module-specific handle value
Definition: BotSense.h:141
#define BSPROXY_VCONN_MOD_MAX
maximum module-specific handle value
Definition: BotSense.h:142

Check if handle is in virtual connection device module range.

See also
bsProxyMsg.h
Parameters
hndVConnVirtual connection handle.
Returns
true or false

Definition at line 441 of file bsProxy.h.

Referenced by VConnClose().

#define BSPROXY_CHK_VCONN_HND (   hndVConn)
Value:
(((int)(hndVConn) >= BSPROXY_VCONN_MIN) && \
((int)(hndVConn) <= BSPROXY_VCONN_MAX))
#define BSPROXY_VCONN_MIN
minimum handle value
Definition: BotSense.h:146
#define BSPROXY_VCONN_MAX
maximum handle value
Definition: BotSense.h:148

Check if handle is in virtual connection range.

The special server handle is included.

See also
bsProxyMsg.h
Parameters
hndVConnVirtual connection handle.
Returns
true or false

Definition at line 428 of file bsProxy.h.

Referenced by BsProxyDispatch(), VConnAcquire(), VConnDelete(), VConnGet(), and VConnRelease().

#define BSPROXY_LOG_ERROR (   hndClient,
  ecode,
  efmt,
  ... 
)
Value:
LOGERROR("%s: %s: %s(ecode=%d): " efmt, \
ServerHasName(), ClientHasName(hndClient), \
bsStrError(ecode), (ecode>=0? ecode: -ecode), \
##__VA_ARGS__)
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
INLINE_IN_H const char * ClientHasName(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:588

Log Proxy Server Error.

Parameters
hndClientClient handle.
ecode

Definition at line 288 of file bsProxy.h.

Referenced by ClientRecvBody(), ClientRecvHdr(), ClientSendRsp(), ClientSendServerRsp(), ThDevRequest(), VConnClose(), and VConnOpenDev().

#define BSPROXY_LOG_NMERROR (   hndClient,
  nmecode,
  efmt,
  ... 
)
Value:
BSPROXY_LOG_ERROR(hndClient, BS_ECODE_BAD_MSG, "%s(nmecode=%d): " efmt, \
nmStrError(nmecode), (nmecode>=0? nmecode: -nmecode), \
##__VA_ARGS__)
#define BS_ECODE_BAD_MSG
bad message
Definition: BotSense.h:76
#define BSPROXY_LOG_ERROR(hndClient, ecode, efmt,...)
Log Proxy Server Error.
Definition: bsProxy.h:288

Log Proxy Server NetMsgs (Un)Packing Error.

Parameters
hndClientClient handle.
nmecodeNetMsgs error code.
efmtError output format string literal.
...Error variable arguments.

Definition at line 302 of file bsProxy.h.

Referenced by ClientSendServerRsp().

#define BSPROXY_LOG_REQ (   hndClient,
  pMsgHdr 
)
Value:
do \
{ \
if( LOGABLE(LOG_LEVEL_DIAG2) ) \
{ \
LOGDIAG2("%s: %s:", ServerHasName(), ClientHasName(hndClient)); \
BsProxyLogMsgHdr("Rx Req", pMsgHdr); \
} \
} while(0)
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
void BsProxyLogMsgHdr(const char *sPreface, BsProxyMsgHdr_T *pMsgHdr)
Log message header.
Definition: bsProxyUtils.c:108
INLINE_IN_H const char * ClientHasName(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:588

Log client request.

Parameters
hndClientClient handle.
pMsgHdrRequest message header.

Definition at line 384 of file bsProxy.h.

Referenced by ClientRecvReq().

#define BSPROXY_LOG_RSP (   hndClient,
  pMsgHdr 
)
Value:
do \
{ \
if( LOGABLE(LOG_LEVEL_DIAG2) ) \
{ \
LOGDIAG2("%s: %s:", ServerHasName(), ClientHasName(hndClient)); \
BsProxyLogMsgHdr("Tx Rsp", pMsgHdr); \
} \
} while(0)
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
void BsProxyLogMsgHdr(const char *sPreface, BsProxyMsgHdr_T *pMsgHdr)
Log message header.
Definition: bsProxyUtils.c:108
INLINE_IN_H const char * ClientHasName(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:588

Log client request.

Parameters
hndClientClient handle.
pMsgHdrRequest message header.

Definition at line 404 of file bsProxy.h.

Referenced by ClientSendRsp().

#define BSPROXY_LOG_SYSERROR (   hndClient,
  efmt,
  ... 
)
Value:
LOGERROR("%s: %s: %s(ecode=%d): %s(errno=%d)" efmt, \
ServerHasName(), ClientHasName(hndClient), \
bsStrError(BS_ECODE_SYS), BS_ECODE_SYS, \
strerror(errno), errno, ##__VA_ARGS__)
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
#define BS_ECODE_SYS
system (errno) error
Definition: BotSense.h:92
INLINE_IN_H const char * ClientHasName(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:588

Log Proxy Server System Error.

Parameters
hndClientClient handle.
efmtError output format string litteral.
...Error variable arguments.

Definition at line 314 of file bsProxy.h.

Referenced by ClientRead(), ClientSendRsp(), and ClientWrite().

#define BSPROXY_LOG_WARN (   hndClient,
  ecode,
  wfmt,
  ... 
)
Value:
LOGDIAG2("Warning: %s: %s: %s(ecode=%d): " wfmt, \
ServerHasName(), ClientHasName(hndClient), \
bsStrError(ecode), ((ecode)>=0? (ecode): -(ecode)), \
##__VA_ARGS__)
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
INLINE_IN_H const char * ClientHasName(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:588

Log Proxy Server Warning.

Parameters
hndClientClient handle.
ecode

Definition at line 274 of file bsProxy.h.

#define BSPROXY_SEND_ERROR_RSP (   hndClient,
  hndVConn,
  uTid,
  ecode,
  efmt,
  ... 
)
Value:
do \
{ \
BSPROXY_LOG_ERROR(hndClient, ecode, "req_vconn=%u: " efmt, \
hndVConn, ##__VA_ARGS__); \
ClientSendErrorRsp(hndClient, uTid, ecode, efmt, ##__VA_ARGS__); \
} while(0)
int ClientSendErrorRsp(BsProxyClientHnd_T hndClient, BsTid_T uTid, int nECode, const char *sErrFmt,...)
Send an error response to the client.
#define BSPROXY_LOG_ERROR(hndClient, ecode, efmt,...)
Log Proxy Server Error.
Definition: bsProxy.h:288

Log BotSense Error and Send Error Response.

Parameters
hndClientClient handle.
hndVConnRequestor's virtual connection handle.
uTidRequest-Response transaction id.
ecode

Definition at line 330 of file bsProxy.h.

Referenced by BsProxyDispatch(), ReqDevClose(), ReqDevOpen(), ReqMsgTrace(), ServerRequest(), and ThDevRequest().

#define BSPROXY_SEND_NMERROR_RSP (   hndClient,
  hndVConn,
  uTid,
  nmecode,
  efmt,
  ... 
)
Value:
do \
{ \
BSPROXY_LOG_NMERROR(hndClient, nmecode, "req_vconn=%u: " efmt, \
hndVConn, ##__VA_ARGS__); \
ClientSendErrorRsp(hndClient, uTid, BS_ECODE_BAD_MSG, efmt, \
##__VA_ARGS__); \
} while(0)
int ClientSendErrorRsp(BsProxyClientHnd_T hndClient, BsTid_T uTid, int nECode, const char *sErrFmt,...)
Send an error response to the client.
#define BS_ECODE_BAD_MSG
bad message
Definition: BotSense.h:76
#define BSPROXY_LOG_NMERROR(hndClient, nmecode, efmt,...)
Log Proxy Server NetMsgs (Un)Packing Error.
Definition: bsProxy.h:302

Log NetMsgs (Un)Packing Error and Send Error Response.

Parameters
hndClientClient handle.
hndVConnRequestor's virtual connection handle.
uTidRequest-Response transaction id.
nmecodeNetMsgs error code.
efmtError output format string literal.
...Error variable arguments.

Definition at line 348 of file bsProxy.h.

Referenced by ReqDevClose(), ReqDevOpen(), ReqGetVConnInfo(), ReqLoopback(), ReqMsgTrace(), and ReqSetLogging().

#define BSPROXY_SEND_SYSERROR_RSP (   hndClient,
  hndVConn,
  uTid,
  efmt,
  ... 
)
Value:
do \
{ \
BSPROXY_LOG_SYSERROR(hndClient, "req_vconn=%u: " efmt, \
hndVConn, ##__VA_ARGS__); \
ClientSendErrorRsp(hndClient, uTid, BS_ECODE_SYS, \
"%s(errno=%d): vconn=%u:" efmt, \
strerror(errno), errno, hndVConn, ##__VA_ARGS__); \
} while(0)
int ClientSendErrorRsp(BsProxyClientHnd_T hndClient, BsTid_T uTid, int nECode, const char *sErrFmt,...)
Send an error response to the client.
#define BSPROXY_LOG_SYSERROR(hndClient, efmt,...)
Log Proxy Server System Error.
Definition: bsProxy.h:314
#define BS_ECODE_SYS
system (errno) error
Definition: BotSense.h:92

Log System Error and Send Error Response.

Parameters
hndClientClient handle.
hndVConnRequestor's virtual connection handle.
uTidRequest-Response transaction id.
efmtError output format string literal.
...Error variable arguments.

Definition at line 366 of file bsProxy.h.

Typedef Documentation

BotSense Service Thread Control Block Structure Type

BotSense Service Thread Request Structure Type

Enumeration Type Documentation

BotSense Proxy Client States

Enumerator
BsProxyClientStateInit 

initialization state

BsProxyClientStateNominal 

normal operation

BsProxyClientStateReSync 

resyncing server with client

BsProxyClientStateZombie 

disconnected or fatal, not deleted

Definition at line 181 of file bsProxy.h.

182 {
183  BsProxyClientStateInit, ///< initialization state
184  BsProxyClientStateNominal, ///< normal operation
185  BsProxyClientStateReSync, ///< resyncing server with client
186  BsProxyClientStateZombie, ///< disconnected or fatal, not deleted
disconnected or fatal, not deleted
Definition: bsProxy.h:186
initialization state
Definition: bsProxy.h:183
normal operation
Definition: bsProxy.h:184
BsProxyClientState_T
Definition: bsProxy.h:181
resyncing server with client
Definition: bsProxy.h:185

Service thread states.

Enumerator
BsProxyThStateUninit 

thread is not fully initialized

BsProxyThStateInit 

thread is initialized

BsProxyThStateRunning 

thread is running (nominal state)

BsProxyThStateExit 

thread is exiting

Definition at line 137 of file bsProxy.h.

138 {
139  BsProxyThStateUninit, ///< thread is not fully initialized
140  BsProxyThStateInit, ///< thread is initialized
141  BsProxyThStateRunning, ///< thread is running (nominal state)
142  BsProxyThStateExit ///< thread is exiting
thread is exiting
Definition: bsProxy.h:142
BsProxyThState_T
Service thread states.
Definition: bsProxy.h:137
thread is not fully initialized
Definition: bsProxy.h:139
thread is running (nominal state)
Definition: bsProxy.h:141
thread is initialized
Definition: bsProxy.h:140

Function Documentation

void BsProxyLogMsgHdr ( const char *  sPreface,
BsProxyMsgHdr_T pMsgHdr 
)

Log message header.

Parameters
sPrefacePreface string.
pMsgHdrPointer to message header structure.

Definition at line 108 of file bsProxyUtils.c.

References BSPROXY_VCONN_SERVER, BsProxyLookupMsgDef(), BsProxyMsgHdr_T::m_hdrBodyLen, BsProxyMsgHdr_T::m_hdrMagic, BsProxyMsgHdr_T::m_hdrMsgId, BsProxyMsgHdr_T::m_hdrTid, and BsProxyMsgHdr_T::m_hdrVConn.

Referenced by ClientSetTraceState().

109 {
110  FILE *fp;
111  const NMMsgDef_T *pMsgDef;
112  const char *sMsgName;
113 
114  fp = LOG_GET_LOGFP();
115 
116  if( pMsgHdr != NULL )
117  {
118  if( pMsgHdr->m_hdrVConn == BSPROXY_VCONN_SERVER )
119  {
120  pMsgDef = BsProxyLookupMsgDef((BsProxyMsgId_T)pMsgHdr->m_hdrMsgId);
121  sMsgName = pMsgDef!=NULL? pMsgDef->m_sMsgName: "";
122  }
123  else
124  {
125  sMsgName = "";
126  }
127  fprintf(fp, "%s MsgHdr = {\n", sPreface);
128  fprintf(fp, " Magic: 0x%04x\n", pMsgHdr->m_hdrMagic);
129  fprintf(fp, " Tid: %u\n", (uint_t)(pMsgHdr->m_hdrTid));
130  fprintf(fp, " VConn: %u\n", (uint_t)(pMsgHdr->m_hdrVConn));
131  fprintf(fp, " MsgId: %u %s\n", pMsgHdr->m_hdrMsgId, sMsgName);
132  fprintf(fp, " BodyLen: %u\n", pMsgHdr->m_hdrBodyLen);
133  fprintf(fp, "}\n");
134  }
135  else
136  {
137  fprintf(fp, "%s MsgHdr: (null)\n", sPreface);
138  }
139 }
const NMMsgDef_T * BsProxyLookupMsgDef(BsProxyMsgId_T eMsgId)
Look up the message definition associated with the message id.
Definition: bsProxyMsgs.c:874
#define BSPROXY_VCONN_SERVER
handle for server-terminated msgs
Definition: BotSense.h:140
ushort_t m_hdrBodyLen
message body length
Definition: BotSense.h:284
ushort_t m_hdrMsgId
message id (vConnection unique)
Definition: BotSense.h:283
ushort_t m_hdrMagic
"unique" magic pattern
Definition: BotSense.h:280
BsProxyMsgId_T
Definition: bsProxyMsgs.h:35
byte_t m_hdrTid
transaction id
Definition: BotSense.h:281
byte_t m_hdrVConn
virtual connection handle (server unique)
Definition: BotSense.h:282
BsProxyClientCtl_T* ClientAcquire ( BsProxyClientHnd_T  hndClient)

Acquire client, locking it from other threads.

The calling thread is blocked until the client is availble or has been deleted.

Parameters
hndClientClient handle.
Returns
On success, returns pointer to locked client control block. On failure, NULL is returned.

Definition at line 546 of file bsProxyClient.c.

References ClientLockBusy(), ClientUnlockBusy(), ClientWaitNotBusy(), BsProxyClientCtl_T::m_bBusy, and ServerGetClient().

Referenced by BsProxyClientUnregister(), ClientRecvReq(), ClientSendRsp(), ClientSetTraceState(), ReqDevClose(), and ReqDevOpen().

547 {
548  BsProxyClientCtl_T *pClient;
549 
550  ClientLockBusy();
551 
552  while( ((pClient = ServerGetClient(hndClient)) != NULL) && pClient->m_bBusy )
553  {
555  }
556 
557  if( pClient )
558  {
559  pClient->m_bBusy = true;
560  }
561 
563 
564  return pClient;
565 }
static void ClientUnlockBusy()
Unlock client&#39;s global busy mutual exclusion.
bool_t m_bBusy
client is [not] busy
Definition: bsProxy.h:194
INLINE_IN_H BsProxyClientCtl_T * ServerGetClient(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> server client.
Definition: bsProxy.h:551
static void ClientLockBusy()
Lock client&#39;s global busy mutual exclusion.
Definition: bsProxyClient.c:91
static void ClientWaitNotBusy()
Wait on a client to become free.
void ClientDelete ( BsProxyClientCtl_T pClient)

Delete a client with the server.

Parameters
pClient

Definition at line 621 of file bsProxyClient.c.

References BsProxyClientCtl_T::m_pClientSock, and BsProxyClientCtl_T::m_sClientName.

Referenced by BsProxyClientUnregister(), and ClientSetTraceState().

622 {
623  if( pClient != NULL )
624  {
625  SocketClose(pClient->m_pClientSock);
626  SocketDelete(pClient->m_pClientSock);
627  delete((char *)pClient->m_sClientName);
628  delete(pClient);
629  }
630 }
Socket_T * m_pClientSock
client opened TCP socket
Definition: bsProxy.h:196
const char * m_sClientName
client&#39;s (remote) name
Definition: bsProxy.h:195
INLINE_IN_H bool_t ClientGetTraceState ( BsProxyClientHnd_T  hndClient)

Get the BotSense client's server-terminated message trace state.

Warning
The client is not locked. Use in a safe context.
Parameters
hndClient

Definition at line 602 of file bsProxy.h.

References BsProxyClientCtl_T::m_bServerTrace, and ServerGetClient().

Referenced by ClientSendServerRsp(), and ServerRequest().

603 {
604  BsProxyClientCtl_T *pClient = ServerGetClient(hndClient);
605 
606  return pClient != NULL? pClient->m_bServerTrace: false;
607 }
bool_t m_bServerTrace
do [not] trace server messages
Definition: bsProxy.h:199
INLINE_IN_H BsProxyClientCtl_T * ServerGetClient(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> server client.
Definition: bsProxy.h:551
INLINE_IN_H const char* ClientHasName ( BsProxyClientHnd_T  hndClient)

Get the BotSense client official name.

Warning
The client is not locked. Use in a safe context.
Parameters
hndClient

Definition at line 588 of file bsProxy.h.

References ClientThisHasName(), and ServerGetClient().

Referenced by BsProxyServer(), ReqGetVConnInfo(), ReqLoopback(), VConnClose(), and VConnOpenDev().

589 {
590  return ClientThisHasName(ServerGetClient(hndClient));
591 }
INLINE_IN_H BsProxyClientCtl_T * ServerGetClient(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> server client.
Definition: bsProxy.h:551
INLINE_IN_H const char * ClientThisHasName(BsProxyClientCtl_T *pClient)
Get this <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:574
BsProxyClientCtl_T* ClientNew ( Socket_T *  pSockClient)

Create new client control structure.

Parameters
pSockClientAccecpted client socket.
Returns
Returns a newly allocated and intialized client control block.

Definition at line 602 of file bsProxyClient.c.

References BsProxyClientStateNominal, BsProxyClientCtl_T::m_bServerTrace, BsProxyClientCtl_T::m_eClientState, BsProxyClientCtl_T::m_pClientSock, BsProxyClientCtl_T::m_sClientName, and BsProxyClientCtl_T::m_uRefCnt.

Referenced by BsProxyClientRegister(), and ClientSetTraceState().

603 {
604  BsProxyClientCtl_T *pClient;
605 
606  pClient = NEW(BsProxyClientCtl_T);
607  pClient->m_sClientName = new_strdup(SocketAttrGetRemoteName(pSockClient));
608  pClient->m_pClientSock = pSockClient;
610  pClient->m_uRefCnt = 0;
611  pClient->m_bServerTrace = false;
612 
613  return pClient;
614 }
BsProxyClientState_T m_eClientState
client state
Definition: bsProxy.h:197
Socket_T * m_pClientSock
client opened TCP socket
Definition: bsProxy.h:196
bool_t m_bServerTrace
do [not] trace server messages
Definition: bsProxy.h:199
uint_t m_uRefCnt
vconn ref count for this client
Definition: bsProxy.h:198
normal operation
Definition: bsProxy.h:184
const char * m_sClientName
client&#39;s (remote) name
Definition: bsProxy.h:195
int ClientRecvReq ( BsProxyClientHnd_T  hndClient,
BsProxyMsgHdr_T pMsgHdr,
byte_t **  addrBuf 
)

Receive a request message from client.

Parameters
hndClient

Definition at line 836 of file bsProxyClient.c.

References BS_ECODE_SERVER_BAD_CLIENT, BSPROXY_LOG_REQ, BsProxyClientStateNominal, ClientAcquire(), ClientRecvBody(), ClientRecvHdr(), ClientRelease(), ClientSetState(), ClientThisHasName(), BsProxyClientCtl_T::m_eClientState, BsProxyMsgHdr_T::m_hdrBodyLen, and ServerHasName().

Referenced by BsProxyServer(), and ClientSetTraceState().

839 {
840  BsProxyClientCtl_T *pClient; // BotSense client
841  size_t uBodyLen; // expected message body length
842  byte_t *pBuf = NULL; // allocated request packed message body
843  int nBytesHdr; // read message header bytes/return code
844  int nBytesBody; // read message body bytes/return code
845  int nMsgLen; // total message length/return code
846 
847  *addrBuf = NULL;
848 
849  // lock client
850  if( (pClient = ClientAcquire(hndClient)) == NULL )
851  {
853  }
854 
855  // receive message header
856  if( (nBytesHdr = ClientRecvHdr(pClient, pMsgHdr)) <= 0 )
857  {
858  nMsgLen = nBytesHdr; // return code
859  }
860 
861  // received a good header, now receive any message body
862  else
863  {
864  // (reenter) nominal state
865  if( pClient->m_eClientState != BsProxyClientStateNominal )
866  {
868  }
869 
870  BSPROXY_LOG_REQ(hndClient, pMsgHdr);
871 
872  // specified message body length
873  uBodyLen = (size_t)pMsgHdr->m_hdrBodyLen;
874 
875  //
876  // Get the message body.
877  //
878  if( uBodyLen > 0 )
879  {
880  // allocate buffer
881  pBuf = (byte_t *)new(uBodyLen);
882 
883  // receive
884  if( (nBytesBody = ClientRecvBody(pClient, pBuf, uBodyLen)) <= 0 )
885  {
886  delete(pBuf);
887  pBuf = NULL;
888  nMsgLen = nBytesBody; // return code
889  }
890 
891  // success
892  else
893  {
894  nMsgLen = nBytesHdr + nBytesBody;
895  }
896  }
897 
898  //
899  // No message body
900  //
901  else
902  {
903  pBuf = NULL;
904  nMsgLen = nBytesHdr;
905  }
906  }
907 
908  // set allocated buffer
909  *addrBuf = pBuf;
910 
911  if( nMsgLen > 0 )
912  {
913  LOGDIAG3("%s: %s: received message length=%d",
914  ServerHasName(), ClientThisHasName(pClient), nMsgLen);
915  }
916 
917  // unlock client
918  ClientRelease(hndClient);
919 
920  return nMsgLen;
921 }
BsProxyClientState_T m_eClientState
client state
Definition: bsProxy.h:197
static int ClientRecvHdr(BsProxyClientCtl_T *pClient, BsProxyMsgHdr_T *pMsgHdr)
Receive client request header.
#define BSPROXY_LOG_REQ(hndClient, pMsgHdr)
Log client request.
Definition: bsProxy.h:384
BsProxyClientCtl_T * ClientAcquire(BsProxyClientHnd_T hndClient)
Acquire client, locking it from other threads.
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
void ClientSetState(BsProxyClientCtl_T *pClient, BsProxyClientState_T eNewState)
Set client&#39;s state.
void ClientRelease(BsProxyClientHnd_T hndClient)
Release the locked client.
ushort_t m_hdrBodyLen
message body length
Definition: BotSense.h:284
normal operation
Definition: bsProxy.h:184
#define BS_ECODE_SERVER_BAD_CLIENT
server detected bad client
Definition: BotSense.h:91
static int ClientRecvBody(BsProxyClientCtl_T *pClient, byte_t buf[], size_t uBodyLen)
Receive client request message body.
INLINE_IN_H const char * ClientThisHasName(BsProxyClientCtl_T *pClient)
Get this <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:574
void ClientRelease ( BsProxyClientHnd_T  hndClient)

Release the locked client.

A broadcast is sent to all blocking threads on the freed event.

Parameters
hndClientClient handle.

Definition at line 574 of file bsProxyClient.c.

References ClientBroadcastNotBusy(), ClientLockBusy(), ClientUnlockBusy(), BsProxyClientCtl_T::m_bBusy, and ServerGetClient().

Referenced by ClientRecvReq(), ClientSendRsp(), ClientSetTraceState(), ReqDevClose(), and ReqDevOpen().

575 {
576  BsProxyClientCtl_T *pClient;
577 
578  ClientLockBusy();
579 
580  if( (pClient = ServerGetClient(hndClient)) != NULL )
581  {
582  pClient->m_bBusy = false;
583  }
584 
586 
588 }
static void ClientUnlockBusy()
Unlock client&#39;s global busy mutual exclusion.
bool_t m_bBusy
client is [not] busy
Definition: bsProxy.h:194
INLINE_IN_H BsProxyClientCtl_T * ServerGetClient(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> server client.
Definition: bsProxy.h:551
static void ClientLockBusy()
Lock client&#39;s global busy mutual exclusion.
Definition: bsProxyClient.c:91
static void ClientBroadcastNotBusy()
Broadcast that a client has been freed or deleted.
int ClientSendErrorRsp ( BsProxyClientHnd_T  hndClient,
BsTid_T  uTid,
int  nECode,
const char *  sErrFmt,
  ... 
)

Send an error response to the client.

Parameters
hndClient

Definition at line 960 of file bsProxyClient.c.

References ClientSendVErrorRsp().

Referenced by ClientSetTraceState().

965 {
966  va_list ap;
967  int rc;
968 
969  va_start(ap, sErrFmt);
970  rc = ClientSendVErrorRsp(hndClient, uTid, nECode, sErrFmt,ap);
971  va_end(ap);
972  return rc;
973 }
int ClientSendVErrorRsp(BsProxyClientHnd_T hndClient, BsTid_T uTid, int nECode, const char *sErrFmt, va_list ap)
Send va_list error response to the client.
int ClientSendOkRsp ( BsProxyClientHnd_T  hndClient,
BsTid_T  uTid 
)

Send an ok response to the client.

Parameters
hndClient

Definition at line 936 of file bsProxyClient.c.

References BSPROXY_MSG_HDR_LEN, BSPROXY_VCONN_SERVER, BsProxyMsgIdRspOk, and ClientSendRsp().

Referenced by ClientSetTraceState(), ModCbSendOkRsp(), ReqDevClose(), ReqMsgTrace(), and ReqSetLogging().

937 {
938  byte_t bufRsp[BSPROXY_MSG_HDR_LEN];
939 
940  //
941  // Send the ok message.
942  // Note: Even though this is a server defined message, there is no message
943  // body, so use the lower level send function directly.
944  //
945  return ClientSendRsp(hndClient, BSPROXY_VCONN_SERVER, uTid,
946  BsProxyMsgIdRspOk, bufRsp, (size_t)0);
947 }
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.
#define BSPROXY_VCONN_SERVER
handle for server-terminated msgs
Definition: BotSense.h:140
#define BSPROXY_MSG_HDR_LEN
message header length (bytes)
Definition: BotSense.h:258
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.

Parameters
hndClient

Definition at line 1084 of file bsProxyClient.c.

References BS_ECODE_BAD_SEND, BS_ECODE_INTERNAL, BS_ECODE_SERVER_BAD_CLIENT, BSPROXY_LOG_ERROR, BSPROXY_LOG_RSP, BSPROXY_LOG_SYSERROR, BSPROXY_MSG_HDR_LEN, BSPROXY_MSG_MAGIC, ClientAcquire(), ClientRelease(), ClientWrite(), BsProxyMsgHdr_T::m_hdrBodyLen, BsProxyMsgHdr_T::m_hdrMagic, BsProxyMsgHdr_T::m_hdrMsgId, BsProxyMsgHdr_T::m_hdrTid, and BsProxyMsgHdr_T::m_hdrVConn.

Referenced by ClientSendOkRsp(), ClientSendServerRsp(), ClientSetTraceState(), and ModCbSendRsp().

1090 {
1091  BsProxyClientCtl_T *pClient;
1092  BsProxyMsgHdr_T msgHdr;
1093  size_t nBytes;
1094  int n;
1095 
1096  // message header
1097  msgHdr.m_hdrMagic = (ushort_t)BSPROXY_MSG_MAGIC;
1098  msgHdr.m_hdrTid = (byte_t)uTid;
1099  msgHdr.m_hdrVConn = (byte_t)hndVConn;
1100  msgHdr.m_hdrMsgId = (ushort_t)uMsgId;
1101  msgHdr.m_hdrBodyLen = (ushort_t)uRspSize;
1102 
1103  n = bsPackMsgHdr(&msgHdr, bufRsp, BSPROXY_MSG_HDR_LEN);
1104 
1105  if( n < 0 )
1106  {
1107  BSPROXY_LOG_ERROR(hndClient, n,
1108  "Failed to pack message header for MsgId=%u.", uMsgId);
1109  return -BS_ECODE_INTERNAL;
1110  }
1111 
1112  nBytes = (size_t)n + uRspSize;
1113 
1114  if( (pClient = ClientAcquire(hndClient)) == NULL )
1115  {
1117  "Failed to acquire Client=%d.", hndClient);
1119  }
1120 
1121  // send message to client
1122  n = (int)ClientWrite(pClient, bufRsp, nBytes);
1123 
1124  ClientRelease(hndClient);
1125 
1126  if( n < 0 )
1127  {
1128  BSPROXY_LOG_SYSERROR(hndClient,
1129  "Failed to send message, MsgId=%u", uMsgId);
1130  return -BS_ECODE_BAD_SEND;
1131  }
1132 
1133  // success
1134  else
1135  {
1136  BSPROXY_LOG_RSP(hndClient, &msgHdr);
1137  return n;
1138  }
1139 }
static ssize_t ClientWrite(BsProxyClientCtl_T *pClient, byte_t buf[], size_t uCount)
Write count bytes to socket.
#define BSPROXY_LOG_SYSERROR(hndClient, efmt,...)
Log Proxy Server System Error.
Definition: bsProxy.h:314
#define BS_ECODE_BAD_SEND
bad send
Definition: BotSense.h:70
BsProxyClientCtl_T * ClientAcquire(BsProxyClientHnd_T hndClient)
Acquire client, locking it from other threads.
#define BSPROXY_LOG_RSP(hndClient, pMsgHdr)
Log client request.
Definition: bsProxy.h:404
void ClientRelease(BsProxyClientHnd_T hndClient)
Release the locked client.
ushort_t m_hdrBodyLen
message body length
Definition: BotSense.h:284
ushort_t m_hdrMsgId
message id (vConnection unique)
Definition: BotSense.h:283
#define BSPROXY_MSG_MAGIC
message magic pattern
Definition: BotSense.h:261
#define BSPROXY_MSG_HDR_LEN
message header length (bytes)
Definition: BotSense.h:258
ushort_t m_hdrMagic
"unique" magic pattern
Definition: BotSense.h:280
#define BSPROXY_LOG_ERROR(hndClient, ecode, efmt,...)
Log Proxy Server Error.
Definition: bsProxy.h:288
BotSense Proxy Message Header Structure.
Definition: BotSense.h:278
#define BS_ECODE_SERVER_BAD_CLIENT
server detected bad client
Definition: BotSense.h:91
#define BS_ECODE_INTERNAL
internal error (bug)
Definition: BotSense.h:93
byte_t m_hdrTid
transaction id
Definition: BotSense.h:281
byte_t m_hdrVConn
virtual connection handle (server unique)
Definition: BotSense.h:282
int ClientSendServerRsp ( BsProxyClientHnd_T  hndClient,
BsTid_T  uTid,
BsProxyMsgId_T  uMsgId,
void *  pMsgRsp 
)

Send a server-terminated response message to client.

The response message header must contain the information except for the body length which will be automatically calculated.

Parameters
hndClient

Definition at line 1025 of file bsProxyClient.c.

References BS_ECODE_INTERNAL, BSPROXY_BUF_BODY, BSPROXY_LOG_ERROR, BSPROXY_LOG_NMERROR, BSPROXY_MSG_MAX_LEN, BSPROXY_VCONN_SERVER, BsProxyLookupMsgDef(), BsProxyPackMsg(), ClientGetTraceState(), and ClientSendRsp().

Referenced by ClientSendVErrorRsp(), ClientSetTraceState(), ReqDevOpen(), ReqGetVConnInfo(), ReqGetVConnList(), ReqGetVersion(), and ReqLoopback().

1029 {
1030  const NMMsgDef_T *pMsgDef;
1031  byte_t bufRsp[BSPROXY_MSG_MAX_LEN];
1032  int n;
1033 
1034  // find the bsProxy server message definition
1035  pMsgDef = BsProxyLookupMsgDef(uMsgId);
1036 
1037  if( pMsgDef == NULL )
1038  {
1040  "Cannot find message definition for MsgId=%u.", uMsgId);
1041  return -BS_ECODE_INTERNAL;
1042  }
1043 
1044  //
1045  // Pack response message body
1046  //
1047  if( pMsgRsp != NULL )
1048  {
1049  n = BsProxyPackMsg(uMsgId, pMsgRsp, BSPROXY_BUF_BODY(bufRsp),
1050  ClientGetTraceState(hndClient));
1051 
1052  if( n < 0 )
1053  {
1054  BSPROXY_LOG_NMERROR(hndClient, n,
1055  "Failed to pack message body for MsgId=%u.", uMsgId);
1056  return -BS_ECODE_INTERNAL;
1057  }
1058  }
1059 
1060  //
1061  // No response message body
1062  //
1063  else
1064  {
1065  n = 0;
1066  }
1067 
1068  return ClientSendRsp(hndClient, BSPROXY_VCONN_SERVER, uTid, uMsgId,
1069  bufRsp, (size_t)n);
1070 }
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.
const NMMsgDef_T * BsProxyLookupMsgDef(BsProxyMsgId_T eMsgId)
Look up the message definition associated with the message id.
Definition: bsProxyMsgs.c:874
#define BSPROXY_VCONN_SERVER
handle for server-terminated msgs
Definition: BotSense.h:140
INLINE_IN_H bool_t ClientGetTraceState(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> client&#39;s server-terminated message trace state.
Definition: bsProxy.h:602
#define BSPROXY_LOG_ERROR(hndClient, ecode, efmt,...)
Log Proxy Server Error.
Definition: bsProxy.h:288
#define BSPROXY_LOG_NMERROR(hndClient, nmecode, efmt,...)
Log Proxy Server NetMsgs (Un)Packing Error.
Definition: bsProxy.h:302
#define BS_ECODE_INTERNAL
internal error (bug)
Definition: BotSense.h:93
#define BSPROXY_BUF_BODY(buf)
Convenience macro to produce a buffer (offset, size) 2-tuple.
Definition: BotSense.h:272
#define BSPROXY_MSG_MAX_LEN
total message maximum length
Definition: BotSense.h:259
int BsProxyPackMsg(BsProxyMsgId_T eMsgId, void *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a ITV message in big-endian byte order.
Definition: bsProxyMsgs.c:924
int ClientSendVErrorRsp ( BsProxyClientHnd_T  hndClient,
BsTid_T  uTid,
int  nECode,
const char *  sErrFmt,
va_list  ap 
)

Send va_list error response to the client.

Parameters
hndClient

Definition at line 986 of file bsProxyClient.c.

References BSPROXY_RSPERR_EMSG_LEN, BsProxyMsgIdRspErr, ClientSendServerRsp(), BsProxyRspErr_T::m_ecode, and BsProxyRspErr_T::m_emsg.

Referenced by ClientSendErrorRsp(), ClientSetTraceState(), and ModCbSendErrorRsp().

991 {
992  BsProxyRspErr_T msgRsp;
993 
994  // Fill in formatted error string as the response message body.
995  vsnprintf(msgRsp.m_emsg, BSPROXY_RSPERR_EMSG_LEN+1, sErrFmt, ap);
996  msgRsp.m_emsg[BSPROXY_RSPERR_EMSG_LEN] = 0;
997 
998  // set error code
999  if( nECode < 0 )
1000  {
1001  nECode = -nECode;
1002  }
1003  msgRsp.m_ecode = (byte_t)nECode;
1004 
1005  // send error message
1006  ClientSendServerRsp(hndClient, uTid, BsProxyMsgIdRspErr, &msgRsp);
1007 
1008  return -nECode;
1009 }
char m_emsg[(NMFVAL_LEN_MAX_STRING)+1]
emsg
Definition: bsProxyMsgs.h:75
int ClientSendServerRsp(BsProxyClientHnd_T hndClient, BsTid_T uTid, BsProxyMsgId_T uMsgId, void *pMsgRsp)
Send a server-terminated response message to client.
byte_t m_ecode
ecode
Definition: bsProxyMsgs.h:74
#define BSPROXY_RSPERR_EMSG_LEN
Definition: bsProxyMsgs.h:67
void ClientSetState ( BsProxyClientCtl_T pClient,
BsProxyClientState_T  eNewState 
)

Set client's state.

Parameters
pClient

< disconnected but not deleted

< normal operation

< resyncing server with client

Definition at line 643 of file bsProxyClient.c.

References BsProxyClientStateNominal, BsProxyClientStateReSync, BsProxyClientStateZombie, ClientThisHasName(), BsProxyClientCtl_T::m_eClientState, BsProxyClientCtl_T::m_sClientName, and ServerHasName().

Referenced by BsProxyClientUnregister(), ClientRecvBody(), ClientRecvHdr(), ClientRecvReq(), and ClientSetTraceState().

644 {
645  static const char *sZombie = "(zombie)";
646 
647  const char *sState;
648  char *sName;
649  size_t n;
650 
651  if( pClient == NULL )
652  {
653  return;
654  }
655 
656  else if( pClient->m_eClientState == eNewState )
657  {
658  return;
659  }
660 
661  switch( eNewState )
662  {
663  case BsProxyClientStateZombie: ///< disconnected but not deleted
664  sState = "disconnected";
665  n = strlen(pClient->m_sClientName) + strlen(sZombie) + 2;
666  sName = NEWSTR(n);
667  sprintf(sName, "%s %s", pClient->m_sClientName, sZombie);
668  delete((char *)pClient->m_sClientName);
669  pClient->m_sClientName = sName;
670  break;
671  case BsProxyClientStateNominal: ///< normal operation
672  sState = "nominal";
673  break;
674  case BsProxyClientStateReSync: ///< resyncing server with client
675  sState = "resyncing";
676  break;
677  default:
678  return;
679  }
680 
681  pClient->m_eClientState = eNewState;
682 
683  LOGDIAG2("%s: %s: %s.", ServerHasName(), ClientThisHasName(pClient), sState);
684 }
BsProxyClientState_T m_eClientState
client state
Definition: bsProxy.h:197
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
disconnected or fatal, not deleted
Definition: bsProxy.h:186
normal operation
Definition: bsProxy.h:184
const char * m_sClientName
client&#39;s (remote) name
Definition: bsProxy.h:195
resyncing server with client
Definition: bsProxy.h:185
INLINE_IN_H const char * ClientThisHasName(BsProxyClientCtl_T *pClient)
Get this <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:574
INLINE_IN_H void ClientSetTraceState ( BsProxyClientHnd_T  hndClient,
bool_t  bTrace 
)

Set the BotSense client's server-terminated message trace state.

Warning
The client is not locked. Use in a safe context.
Parameters
hndClient

Definition at line 617 of file bsProxy.h.

References BsProxyLogMsgHdr(), ClientAcquire(), ClientDelete(), ClientNew(), ClientOneTimeInit(), ClientRecvReq(), ClientRelease(), ClientSendErrorRsp(), ClientSendOkRsp(), ClientSendRsp(), ClientSendServerRsp(), ClientSendVErrorRsp(), ClientSetState(), BsProxyClientCtl_T::m_bServerTrace, ModGetLoadedIF(), ModLoad(), ModNewModUri(), ModOneTimeInit(), ModUnload(), ServerGetClient(), ServerRequest(), ThCreateDevThread(), ThCreateServerThread(), ThDequeue(), ThDestroyThread(), ThNewDevUri(), ThOneTimeInit(), ThQueue(), ThReqDelete(), ThReqNew(), VConnAcquire(), VConnClose(), VConnDelete(), VConnGet(), VConnNew(), VConnOneTimeInit(), VConnOpenDev(), VConnOpenServer(), and VConnRelease().

Referenced by ReqMsgTrace().

619 {
620  BsProxyClientCtl_T *pClient = ServerGetClient(hndClient);
621 
622  if( pClient != NULL )
623  {
624  pClient->m_bServerTrace = bTrace;
625  }
626 }
bool_t m_bServerTrace
do [not] trace server messages
Definition: bsProxy.h:199
INLINE_IN_H BsProxyClientCtl_T * ServerGetClient(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> server client.
Definition: bsProxy.h:551
INLINE_IN_H const char* ClientThisHasName ( BsProxyClientCtl_T pClient)

Get this BotSense client official name.

Warning
The client is not locked. Use in a safe context.
Parameters
pClient

Definition at line 574 of file bsProxy.h.

References BsProxyClientCtl_T::m_sClientName.

Referenced by ClientHasName(), ClientRead(), ClientRecvReq(), ClientSetState(), and ClientWrite().

575 {
576  return pClient != NULL? pClient->m_sClientName: "(none)";
577 }
const char * m_sClientName
client&#39;s (remote) name
Definition: bsProxy.h:195
BsProxyModIF_T* ModGetLoadedIF ( const char *  sModUri)

Get the defined interface from a previously loaded i/f module.

Multi-Thread safe.

Parameters
sModUriInterface module expanded, canonical name.
Returns
On success, returns a pointer to the module's exported interface.
Returns NULL if no interface is found.

Definition at line 1058 of file bsProxyMod.c.

References ModHashGetIF(), ModLock(), and ModUnlock().

Referenced by ClientSetTraceState().

1059 {
1060  BsProxyModIF_T *pModIF;
1061 
1062  ModLock();
1063 
1064  pModIF = ModHashGetIF(sModUri);
1065 
1066  ModUnlock();
1067 
1068  return pModIF;
1069 }
static void ModUnlock()
Unlock module&#39;s global mutual exclusion.
Definition: bsProxyMod.c:135
static BsProxyModIF_T * ModHashGetIF(const char *sModUri)
Get the interface module&#39;s i/f from the module hash table.
Definition: bsProxyMod.c:583
static void ModLock()
Lock module&#39;s global mutual exclusion.
Definition: bsProxyMod.c:121
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.

Parameters
sModUriInterface module expanded, canonical name.
Returns
On success, returns a pointer to the module's exported interface.
On failure, returns NULL.

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().

1090 {
1091  BsProxyModIF_T *pModIF = NULL;
1092  void *dllHandle = NULL;
1093  int rc;
1094 
1095  // lock global mutex
1096  ModLock();
1097 
1098  //
1099  // Check if module is already loaded.
1100  //
1101  if( (pModIF = ModHashGetIF(sModUri)) != NULL )
1102  {
1103  rc = BS_OK;
1104  pModIF->m_uRefCnt++;
1105  LOGDIAG1("Interface Module \"%s\" attached (refcnt=%u).",
1106  pModIF->m_sModUri, pModIF->m_uRefCnt);
1107  }
1108 
1109  //
1110  // Load the dynamic library.
1111  //
1112  else if( (dllHandle = ModDllOpen(sModUri)) == NULL )
1113  {
1114  rc = -BS_ECODE_NO_MOD;
1115  BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to open.");
1116  }
1117 
1118  //
1119  // Allocate new interface control blcok and attach module's exported
1120  // interface.
1121  //
1122  else if( (pModIF = ModDllNewIF(sModUri, dllHandle)) == NULL )
1123  {
1124  rc = -BS_ECODE_BAD_MOD;
1125  BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to get interface.");
1126  }
1127 
1128  //
1129  // Call the newly loaded module's exported initialization function to
1130  // initialize any module specific data and resources.
1131  //
1132  else if( (rc = pModIF->m_fnModInit(sModUri, &BsModProxyCallbacks)) < 0 )
1133  {
1134  rc = -BS_ECODE_BAD_MOD;
1135  BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to initialize.");
1136  }
1137 
1138  //
1139  // Add the module to the hash table (failure auto-deletes node data).
1140  //
1141  else if( (rc = ModHashAdd(sModUri, pModIF)) < 0 )
1142  {
1143  rc = -BS_ECODE_NO_RSRC;
1144  BSPROXY_MOD_LOG_ERROR(sModUri, rc, "Failed to add module to hash table.");
1145  }
1146 
1147  //
1148  // Successfully loaded new module.
1149  //
1150  else
1151  {
1152  rc = BS_OK;
1153  LOGDIAG1("Interface Module \"%s\" loaded (refcnt=%u).",
1154  pModIF->m_sModUri, pModIF->m_uRefCnt);
1155  }
1156 
1157  ModUnlock();
1158 
1159  //
1160  // Error clean up.
1161  //
1162  if( rc < 0 )
1163  {
1164  if( dllHandle != NULL )
1165  {
1166  dlclose(dllHandle);
1167  dllHandle = NULL;
1168  }
1169 
1170  if( pModIF != NULL )
1171  {
1172  ModDllDeleteIF(pModIF);
1173  pModIF = NULL;
1174  }
1175  }
1176 
1177  return pModIF;
1178 }
static void ModUnlock()
Unlock module&#39;s global mutual exclusion.
Definition: bsProxyMod.c:135
#define BS_OK
not an error, success
Definition: BotSense.h:66
static BsProxyModIF_T * ModDllNewIF(const char *sModUri, void *dllHandle)
Allocate an attached exported module interface block.
Definition: bsProxyMod.c:420
#define BS_ECODE_BAD_MOD
bad interface module
Definition: BotSense.h:84
static BsModProxyCb_T BsModProxyCallbacks
Interface module callbacks to bsProxy server services.
Definition: bsProxyMod.c:988
static int ModHashAdd(const char *sModUri, BsProxyModIF_T *pModIF)
Add the module data to the i/f module hash table.
Definition: bsProxyMod.c:538
#define BS_ECODE_NO_RSRC
no resource available
Definition: BotSense.h:85
uint_t m_uRefCnt
vconn reference count for this module
Definition: bsProxy.h:124
#define BS_ECODE_NO_MOD
no interface module
Definition: BotSense.h:83
const char * m_sModUri
module Uniform Resource Id
Definition: bsProxy.h:122
BsModInitFunc_P m_fnModInit
module init
Definition: bsProxy.h:125
static BsProxyModIF_T * ModHashGetIF(const char *sModUri)
Get the interface module&#39;s i/f from the module hash table.
Definition: bsProxyMod.c:583
static void * ModDllOpen(const char *sModUri)
Dynamically load bsProxy server compatible interface module library.
Definition: bsProxyMod.c:270
static void ModDllDeleteIF(BsProxyModIF_T *pModIF)
Delete module interface block.
Definition: bsProxyMod.c:396
#define BSPROXY_MOD_LOG_ERROR(moduri, ecode, efmt,...)
Log Proxy Server Module Error.
Definition: bsProxyMod.c:107
static void ModLock()
Lock module&#39;s global mutual exclusion.
Definition: bsProxyMod.c:121
char* ModNewModUri ( const char *  sModName)

Convert the module name to a quasi Uniform Resource Id.

Parameters
sModNameModule path name.
Returns
On success, an allocated, canonical library path name is returned.
On failure, NULL is returned.

Definition at line 1042 of file bsProxyMod.c.

References ModDllNewCanonicalName().

Referenced by ClientSetTraceState(), and VConnOpenDev().

1043 {
1044  return ModDllNewCanonicalName(sModName);
1045 }
static char * ModDllNewCanonicalName(const char *sModName)
Make DLL canonical file name.
Definition: bsProxyMod.c:222
void ModOneTimeInit ( DListStr_T *  pDListLibPath)

The bsProxy interface module handling one-time initialization.

Parameters
pDListLibPathList 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().

1014 {
1015  // create mutex
1016  pthread_mutex_init(&BsModMutex, NULL);
1017 
1018  BsModHashTbl = hash_table_create(
1019  true, // dynamic table sizing
1020  (hashcount_t)BSPROXY_MOD_HASH_MIN, // minimum size
1021  (hashcount_t)BSPROXY_MOD_HASH_MAX, // maximum size
1022  NULL, // use default comparator function
1023  NULL, // use default hashing function
1024  ModHashDeleteData); // hash node data deletion function
1025 
1026  // turn off most asserts()
1027  hash_set_self_verify(false);
1028 
1029  // initialize DLL environment
1030  ModDllInit(pDListLibPath);
1031 }
#define BSPROXY_MOD_HASH_MAX
maximum hash table size
Definition: bsProxyMod.c:93
#define BSPROXY_MOD_HASH_MIN
minimum hash table size
Definition: bsProxyMod.c:92
static hash_t * BsModHashTbl
i/f module hash table
Definition: bsProxyMod.c:96
static void ModDllInit(DListStr_T *pDListLibPath)
Definition: bsProxyMod.c:175
static void ModHashDeleteData(void *sModUri, void *pModIF)
Delete hash node data callback.
Definition: bsProxyMod.c:524
static pthread_mutex_t BsModMutex
bsProxy module operations mutex
Definition: bsProxyMod.c:95
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.

Parameters
pModIFExported 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().

1192 {
1193 
1194  ModLock();
1195 
1196  if( (pModIF = ModHashGetIF(pModIF->m_sModUri)) != NULL )
1197  {
1198  if( pModIF->m_uRefCnt > 0 )
1199  {
1200  pModIF->m_uRefCnt--;
1201  }
1202 
1203  if( pModIF->m_uRefCnt == 0 )
1204  {
1205  // call module specific exported exit function
1206  pModIF->m_fnModExit();
1207 
1208  // unload the dll
1209  ModDllClose(pModIF->m_sModUri, pModIF->m_dllHandle);
1210 
1211  LOGDIAG1("Interface Module \"%s\" unloaded (refcnt=%u).",
1212  pModIF->m_sModUri, pModIF->m_uRefCnt);
1213 
1214  // delete data
1215  ModHashDelete(pModIF);
1216  }
1217  else
1218  {
1219  LOGDIAG1("Interface Module \"%s\" detached (refcnt=%u).",
1220  pModIF->m_sModUri, pModIF->m_uRefCnt);
1221  }
1222  }
1223 
1224  ModUnlock();
1225 }
BsModExitFunc_P m_fnModExit
module exit
Definition: bsProxy.h:126
static void ModUnlock()
Unlock module&#39;s global mutual exclusion.
Definition: bsProxyMod.c:135
static void ModDllClose(const char *sModUri, void *dllHandle)
Unload the dynamic library from the application.
Definition: bsProxyMod.c:344
static void ModHashDelete(BsProxyModIF_T *pModIF)
Remove and delete the module data from the i/f module hash table.
Definition: bsProxyMod.c:560
uint_t m_uRefCnt
vconn reference count for this module
Definition: bsProxy.h:124
const char * m_sModUri
module Uniform Resource Id
Definition: bsProxy.h:122
static BsProxyModIF_T * ModHashGetIF(const char *sModUri)
Get the interface module&#39;s i/f from the module hash table.
Definition: bsProxyMod.c:583
void * m_dllHandle
dynamic library loader handle
Definition: bsProxy.h:123
static void ModLock()
Lock module&#39;s global mutual exclusion.
Definition: bsProxyMod.c:121
INLINE_IN_H int ServerClientHnd2Sd ( BsProxyClientHnd_T  hndClient)

Convert the BotSense server client handle to client socket descriptor.

Note
Currently, the handle and socket descriptor are one and the same. But this mapping could change in the future.
Parameters
hndClient

Definition at line 521 of file bsProxy.h.

Referenced by BsProxyClientUnregister(), BsProxyServerDelete(), and ServerGetClient().

522 {
523  return (int)hndClient;
524 }
INLINE_IN_H BsProxyClientHnd_T ServerClientSd2Hnd ( int  sd)

Convert the BotSense server client socket descriptor to client handle.

Note
Currently, the handle and socket descriptor are one and the same. But this mapping could change in the future.
Parameters
sd

Definition at line 537 of file bsProxy.h.

Referenced by BsProxyClientRegister(), BsProxyServer(), ClientRead(), and ClientWrite().

538 {
539  return (BsProxyClientHnd_T)sd;
540 }
int BsProxyClientHnd_T
bsProxy server client handle
Definition: bsProxy.h:114
INLINE_IN_H BsProxyServerCtl_T* ServerGet ( )

Get the BotSense server.

Note
In the future, if bsProxy is expanded to be multi-threaded multi-server then this call will return the correct server given the caller's context.
Returns
Pointer to the server's control block.

Definition at line 475 of file bsProxy.h.

References BsServerCtl.

Referenced by BsProxyClientRegister(), BsProxyClientUnregister(), ServerGetClient(), ServerHasAddr(), ServerHasName(), and ServerHasPort().

476 {
477  return BsServerCtl;
478 }
BsProxyServerCtl_T * BsServerCtl
The server control block.
Definition: bsProxy.c:831
INLINE_IN_H BsProxyClientCtl_T* ServerGetClient ( BsProxyClientHnd_T  hndClient)

Get the BotSense server client.

Note
The client is not locked.
Parameters
hndClient

Definition at line 551 of file bsProxy.h.

References BSPROXY_FD_SETSIZE, BsProxyServerCtl_T::m_pServerRegClient, ServerClientHnd2Sd(), and ServerGet().

Referenced by BsProxyServer(), ClientAcquire(), ClientGetTraceState(), ClientHasName(), ClientRelease(), and ClientSetTraceState().

552 {
553  int sd = ServerClientHnd2Sd(hndClient);
554 
555  if( (sd >= 0) && (sd < BSPROXY_FD_SETSIZE) )
556  {
557  return ServerGet()->m_pServerRegClient[sd];
558  }
559  else
560  {
561  return NULL;
562  }
563 }
BsProxyClientCtl_T * m_pServerRegClient[256]
registered clients
Definition: bsProxy.h:212
#define BSPROXY_FD_SETSIZE
server socket set size
Definition: bsProxy.h:103
INLINE_IN_H BsProxyServerCtl_T * ServerGet()
Get the <b><i>BotSense</i></b> server.
Definition: bsProxy.h:475
INLINE_IN_H int ServerClientHnd2Sd(BsProxyClientHnd_T hndClient)
Convert the <b><i>BotSense</i></b> server client handle to client socket descriptor.
Definition: bsProxy.h:521
INLINE_IN_H const char* ServerHasAddr ( )

Get the BotSense server's listening address.

Returns
Null-terminated server address string.

Definition at line 495 of file bsProxy.h.

References ServerGet().

496 {
497  return SocketAttrGetLocalName(ServerGet()->m_pServerSockListener);
498 }
INLINE_IN_H BsProxyServerCtl_T * ServerGet()
Get the <b><i>BotSense</i></b> server.
Definition: bsProxy.h:475
INLINE_IN_H const char* ServerHasName ( )

Get the BotSense server's official name.

Returns
Null-terminated server name string.

Definition at line 485 of file bsProxy.h.

References BsProxyServerCtl_T::m_sServerName, and ServerGet().

Referenced by BsProxyServer(), ClientRecvReq(), ClientSetState(), main(), ModCbSendErrorRsp(), ModCbSendOkRsp(), ModCbSendRsp(), ModDllOpen(), ThQueue(), VConnClose(), VConnOpenDev(), and VConnOpenServer().

486 {
487  return ServerGet()->m_sServerName;
488 }
INLINE_IN_H BsProxyServerCtl_T * ServerGet()
Get the <b><i>BotSense</i></b> server.
Definition: bsProxy.h:475
const char * m_sServerName
server&#39;s name
Definition: bsProxy.h:207
INLINE_IN_H int ServerHasPort ( )

Get the BotSense server's listening port.

Returns
Port.

Definition at line 505 of file bsProxy.h.

References BsProxyServerCtl_T::m_nServerPort, and ServerGet().

Referenced by BsProxyServer().

506 {
507  return ServerGet()->m_nServerPort;
508 }
INLINE_IN_H BsProxyServerCtl_T * ServerGet()
Get the <b><i>BotSense</i></b> server.
Definition: bsProxy.h:475
int m_nServerPort
server&#39;s listener port
Definition: bsProxy.h:208
int ServerRequest ( BsProxyClientHnd_T  hndClient,
BsVConnHnd_T  hndVConn,
BsTid_T  uTid,
BsMsgId_T  uMsgId,
byte_t  bufReq[],
size_t  uReqLen 
)

Server service thread request handler.

Execution Context:
Server service thread.
Parameters
hndClient

Definition at line 610 of file bsProxyRequest.c.

References BS_ECODE_UNKNOWN_REQ, BSPROXY_SEND_ERROR_RSP, BsProxyMsgIdReqDevClose, BsProxyMsgIdReqDevOpen, BsProxyMsgIdReqGetVConnInfo, BsProxyMsgIdReqGetVConnList, BsProxyMsgIdReqGetVersion, BsProxyMsgIdReqLoopback, BsProxyMsgIdReqMsgTrace, BsProxyMsgIdReqSetLogging, ClientGetTraceState(), ReqDevClose(), ReqDevOpen(), ReqGetVConnInfo(), ReqGetVConnList(), ReqGetVersion(), ReqLoopback(), ReqMsgTrace(), and ReqSetLogging().

Referenced by ClientSetTraceState(), and ThCreateServerThread().

617 {
618  bool_t bServerTrace = ClientGetTraceState(hndClient);
619 
620  switch( uMsgId )
621  {
623  return ReqLoopback(hndClient, hndVConn, uTid, uMsgId, bufReq, uReqLen,
624  bServerTrace);
625 
627  return ReqSetLogging(hndClient, hndVConn, uTid, uMsgId, bufReq, uReqLen,
628  bServerTrace);
629 
631  return ReqMsgTrace(hndClient, hndVConn, uTid, uMsgId, bufReq, uReqLen,
632  bServerTrace);
633 
635  return ReqGetVersion(hndClient, hndVConn, uTid, uMsgId, bufReq, uReqLen,
636  bServerTrace);
637 
639  return ReqDevOpen(hndClient, hndVConn, uTid, uMsgId, bufReq, uReqLen,
640  bServerTrace);
641 
643  return ReqDevClose(hndClient, hndVConn, uTid, uMsgId, bufReq, uReqLen,
644  bServerTrace);
645 
647  return ReqGetVConnList(hndClient, hndVConn, uTid, uMsgId, bufReq, uReqLen,
648  bServerTrace);
649 
651  return ReqGetVConnInfo(hndClient, hndVConn, uTid, uMsgId, bufReq, uReqLen,
652  bServerTrace);
653 
654  default:
655  BSPROXY_SEND_ERROR_RSP(hndClient, hndVConn, uTid, BS_ECODE_UNKNOWN_REQ,
656  "MsgId=%u", uMsgId);
657  return -BS_ECODE_UNKNOWN_REQ;
658  }
659 }
#define BS_ECODE_UNKNOWN_REQ
unknown request
Definition: BotSense.h:81
static int ReqMsgTrace(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen, bool_t bTrace)
Service client&#39;s request to set server or client terminated message tracing.
static int ReqGetVersion(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen, bool_t bTrace)
Service client&#39;s request to get the server&#39;s version.
static int ReqGetVConnInfo(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen, bool_t bTrace)
Service client&#39;s request to get a virtual connection&#39;s information.
static int ReqGetVConnList(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen, bool_t bTrace)
Service client&#39;s request to get the list of all of the client&#39;s opened virtual connection handles...
ReqGetVConnInfo.
Definition: bsProxyMsgs.h:51
static int ReqSetLogging(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen, bool_t bTrace)
Service client&#39;s request to set the server&#39;s logging level.
static int ReqDevClose(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen, bool_t bTrace)
Service client&#39;s request to close a device virtual connection.
static int ReqDevOpen(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen, bool_t bTrace)
Service client&#39;s request to open a proxied device virtual connection.
static int ReqLoopback(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen, bool_t bTrace)
Service client&#39;s request to perform a loopback.
INLINE_IN_H bool_t ClientGetTraceState(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> client&#39;s server-terminated message trace state.
Definition: bsProxy.h:602
#define BSPROXY_SEND_ERROR_RSP(hndClient, hndVConn, uTid, ecode, efmt,...)
Log <b><i>BotSense</i></b> Error and Send Error Response.
Definition: bsProxy.h:330
ReqGetVConnList.
Definition: bsProxyMsgs.h:49
BsProxyThCtl_T* ThCreateDevThread ( const char *  sDevUri)

Create a device service thread.

The actual thread is only created if it does not already exists. The internal reference count is incremented to keep track of the users of this thread.

Execution Context:
Calling thread.
Parameters
sDevUriDevice URI.
Returns
On success, returns the service thread control block. On failure, NULL is returned.

Definition at line 756 of file bsProxyThread.c.

References BsProxyThStateInit, _bsproxy_th_ctl::m_eState, _bsproxy_th_ctl::m_fnRequest, _bsproxy_th_ctl::m_sDevUri, _bsproxy_th_ctl::m_thread, _bsproxy_th_ctl::m_uRefCnt, ThCtlBlkDelete(), ThCtlBlkNew(), ThDevRequest(), ThGlobalLock(), ThGlobalUnlock(), ThHashAdd(), ThHashDelete(), ThHashGetCtl(), ThServiceThread(), and ThSyncRun().

Referenced by ClientSetTraceState(), and VConnOpenDev().

757 {
758  BsProxyThCtl_T *pThCtl;
759  int rc;
760 
761  // lock global mutex
762  ThGlobalLock();
763 
764  //
765  // Device thread already exists.
766  //
767  if( (pThCtl = ThHashGetCtl(sDevUri)) != NULL )
768  {
769  pThCtl->m_uRefCnt++;
770  LOGDIAG1("Service Thread \"%s\" attached (refcnt=%u).",
771  pThCtl->m_sDevUri, pThCtl->m_uRefCnt);
772  }
773 
774  //
775  // Create new device thread.
776  //
777  else
778  {
779  //
780  // Create a new thread control block.
781  //
782  pThCtl = ThCtlBlkNew(sDevUri);
783 
784  pThCtl->m_fnRequest = ThDevRequest; // device request handler
785  pThCtl->m_uRefCnt = 1; // thread reference count
786  pThCtl->m_eState = BsProxyThStateInit; // control is (mostly) initialized
787 
788  //
789  // Add thread control to thread hash table
790  //
791  if( (rc = ThHashAdd(sDevUri, pThCtl)) < 0 )
792  {
793  LOGERROR("\"%s\": Failed to add thread control to hash table.", sDevUri);
794  ThCtlBlkDelete(pThCtl);
795  pThCtl = NULL;
796  }
797 
798  //
799  // Start the device service thread. The thread will block until the run
800  // state is set this context.
801  //
802  else if( pthread_create(&pThCtl->m_thread, NULL, ThServiceThread,
803  (void *)pThCtl) )
804  {
805  LOGSYSERROR("pthread_create(\"%s\")", sDevUri);
806  ThHashDelete(pThCtl);
807  pThCtl = NULL;
808  }
809 
810  //
811  // Signal the thread to run.
812  //
813  else
814  {
815  ThSyncRun(pThCtl);
816  }
817  }
818 
819  // unlock thread mutex
820  ThGlobalUnlock();
821 
822  return pThCtl;
823 }
static void ThGlobalLock()
Lock global mutual exclusion.
static BsProxyThCtl_T * ThCtlBlkNew(const char *sDevUri)
Allocate new service thread control block.
uint_t m_uRefCnt
vconn reference count for this thread
Definition: bsProxy.h:151
static void ThCtlBlkDelete(BsProxyThCtl_T *pThCtl)
Delete service thread control block.
static void ThSyncRun(BsProxyThCtl_T *pThCtl)
Command service thread to run.
pthread_t m_thread
the service thread
Definition: bsProxy.h:156
static int ThDevRequest(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
Device service thread request handler.
static int ThHashAdd(const char *sDevUri, BsProxyThCtl_T *pThCtl)
Add the module data to the i/f module hash table.
thread is initialized
Definition: bsProxy.h:140
static void * ThServiceThread(void *pThArg)
The service thread.
int(* m_fnRequest)(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
Service thread request handler.
Definition: bsProxy.h:170
static void ThHashDelete(BsProxyThCtl_T *pThCtl)
Remove and delete the module data from the i/f module hash table.
static void ThGlobalUnlock()
Unlock global mutual exclusion.
static BsProxyThCtl_T * ThHashGetCtl(const char *sDevUri)
Get the interface module&#39;s i/f from the module hash table.
BsProxyThState_T m_eState
thread state
Definition: bsProxy.h:152
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
BsProxyThCtl_T* ThCreateServerThread ( )

Create the special server service thread.

There is only one server service thread per server. The server thread processes all server terminated requests.

Execution Context:
Calling thread.
Returns
On success, returns the service thread control block. On failure, NULL is returned.

Definition at line 837 of file bsProxyThread.c.

References BS_ECODE_INTERNAL, BSPROXY_TH_LOG_ERROR, BSPROXY_TH_SERVER_URI, BsProxyThStateInit, _bsproxy_th_ctl::m_eState, _bsproxy_th_ctl::m_fnRequest, _bsproxy_th_ctl::m_thread, _bsproxy_th_ctl::m_uRefCnt, ServerRequest(), ThCtlBlkDelete(), ThCtlBlkNew(), ThGlobalLock(), ThGlobalUnlock(), ThHashAdd(), ThHashDelete(), ThHashGetCtl(), ThServiceThread(), and ThSyncRun().

Referenced by ClientSetTraceState(), and VConnOpenServer().

838 {
839  char *sDevUri;
840  BsProxyThCtl_T *pThCtl;
841  int rc;
842 
843  // Server URI
844  sDevUri = new_strdup(BSPROXY_TH_SERVER_URI);
845 
846  // lock global mutex
847  ThGlobalLock();
848 
849  //
850  // There should only be one server thread.
851  //
852  if( (pThCtl = ThHashGetCtl(sDevUri)) != NULL )
853  {
855  "Server service thread already exists.");
856  }
857 
858  //
859  // Create new device thread.
860  //
861  else
862  {
863  //
864  // Create a new thread control block.
865  //
866  pThCtl = ThCtlBlkNew(sDevUri);
867 
868  pThCtl->m_fnRequest = ServerRequest; // server request handler
869  pThCtl->m_uRefCnt = 1; // thread reference count
870  pThCtl->m_eState = BsProxyThStateInit; // control is (mostly) initialized
871 
872  //
873  // Add thread control to thread hash table
874  //
875  if( (rc = ThHashAdd(sDevUri, pThCtl)) < 0 )
876  {
877  LOGERROR("\"%s\": Failed to add thread control to hash table.", sDevUri);
878  ThCtlBlkDelete(pThCtl);
879  pThCtl = NULL;
880  }
881 
882  //
883  // Start the device service thread. The thread will block until the run
884  // state is set this context.
885  //
886  else if( pthread_create(&pThCtl->m_thread, NULL, ThServiceThread,
887  (void *)pThCtl) )
888  {
889  LOGSYSERROR("pthread_create(\"%s\")", sDevUri);
890  ThHashDelete(pThCtl);
891  pThCtl = NULL;
892  }
893 
894  //
895  // Signal the thread to run.
896  //
897  else
898  {
899  ThSyncRun(pThCtl);
900  }
901  }
902 
903  // unlock global mutex
904  ThGlobalUnlock();
905 
906  return pThCtl;
907 }
static void ThGlobalLock()
Lock global mutual exclusion.
static BsProxyThCtl_T * ThCtlBlkNew(const char *sDevUri)
Allocate new service thread control block.
uint_t m_uRefCnt
vconn reference count for this thread
Definition: bsProxy.h:151
static void ThCtlBlkDelete(BsProxyThCtl_T *pThCtl)
Delete service thread control block.
static void ThSyncRun(BsProxyThCtl_T *pThCtl)
Command service thread to run.
#define BSPROXY_TH_LOG_ERROR(devuri, ecode, efmt,...)
Log Proxy Server Thread Error.
pthread_t m_thread
the service thread
Definition: bsProxy.h:156
static int ThHashAdd(const char *sDevUri, BsProxyThCtl_T *pThCtl)
Add the module data to the i/f module hash table.
thread is initialized
Definition: bsProxy.h:140
static void * ThServiceThread(void *pThArg)
The service thread.
int(* m_fnRequest)(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
Service thread request handler.
Definition: bsProxy.h:170
static void ThHashDelete(BsProxyThCtl_T *pThCtl)
Remove and delete the module data from the i/f module hash table.
static void ThGlobalUnlock()
Unlock global mutual exclusion.
#define BS_ECODE_INTERNAL
internal error (bug)
Definition: BotSense.h:93
static BsProxyThCtl_T * ThHashGetCtl(const char *sDevUri)
Get the interface module&#39;s i/f from the module hash table.
BsProxyThState_T m_eState
thread state
Definition: bsProxy.h:152
#define BSPROXY_TH_SERVER_URI
server "URI"
Definition: bsProxyThread.c:87
int ServerRequest(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
Server service thread request handler.
BsProxyThReq_T* ThDequeue ( BsProxyThCtl_T pThCtl)

Dequeue a request for the given service thread.

The service thread will block if no queued request is present.

Execution Context:
Service thread.
Returns
On success, returns removed request at the front of the queue.
On failure, NULL is returned.

Definition at line 675 of file bsProxyThread.c.

References BsProxyThStateRunning, _bsproxy_th_ctl::m_eState, _bsproxy_th_ctl::m_queue, ThSyncLock(), ThSyncUnlock(), and ThSyncWait().

Referenced by ClientSetTraceState(), and ThServiceThread().

676 {
677  BsProxyThReq_T *pThReq;
678 
679  // lock thread and queue
680  ThSyncLock(pThCtl);
681 
682  //
683  // Block waiting for queued request or state change event.
684  //
685  while( (pThCtl->m_eState == BsProxyThStateRunning) &&
686  (DListVoidCount(pThCtl->m_queue) == 0) )
687  {
688  // Release mutex, block on conditional variable, auto-lock mutex on return.
689  ThSyncWait(pThCtl);
690  }
691 
692  if( pThCtl->m_eState == BsProxyThStateRunning )
693  {
694  pThReq = (BsProxyThReq_T *)DListVoidDequeue(pThCtl->m_queue);
695  }
696  else
697  {
698  pThReq = NULL;
699  }
700 
701  // unlock thread and queue
702  ThSyncUnlock(pThCtl);
703 
704  return pThReq;
705 }
static void ThSyncUnlock(BsProxyThCtl_T *pThCtl)
Unlock service thread&#39;s mutual exclusion.
static void ThSyncWait(BsProxyThCtl_T *pThCtl)
Wait on service thread&#39;s condition.
static void ThSyncLock(BsProxyThCtl_T *pThCtl)
Lock service thread&#39;s mutual exclusion.
DListVoid_T * m_queue
thread request queue
Definition: bsProxy.h:155
thread is running (nominal state)
Definition: bsProxy.h:141
BsProxyThState_T m_eState
thread state
Definition: bsProxy.h:152
void ThDestroyThread ( BsProxyThCtl_T pThCtl)

Destroy service thread.

The thread's reference count is decremented. If the count is zero, then the thread is actually destroyed with all queued requests deleted. The calling thread is suspended until the target service thread terminates.

Execution Context:
Calling thread.
Parameters
pThCtlService thread control block.

Definition at line 921 of file bsProxyThread.c.

References _bsproxy_th_ctl::m_sDevUri, _bsproxy_th_ctl::m_thread, _bsproxy_th_ctl::m_uRefCnt, ThGlobalLock(), ThGlobalUnlock(), ThHashDelete(), and ThSyncExit().

Referenced by ClientSetTraceState(), VConnClose(), and VConnOpenDev().

922 {
923  if( pThCtl == NULL )
924  {
925  return;
926  }
927 
928  // lock global mutex
929  ThGlobalLock();
930 
931  // do not destroy the thread since there exists users of this thread
932  if( pThCtl->m_uRefCnt > 0 )
933  {
934  pThCtl->m_uRefCnt--;
935  }
936 
937  // thread is not being used anymore - destroy
938  if( pThCtl->m_uRefCnt == 0 )
939  {
940  // signal thread of exit state change
941  ThSyncExit(pThCtl);
942 
943  // wait for thread to terminate
944  pthread_join(pThCtl->m_thread, NULL);
945 
946  // delete the thread hash entry's control block (including its queue)
947  ThHashDelete(pThCtl);
948  }
949 
950  else
951  {
952  LOGDIAG1("Service Thread \"%s\" detached (refcnt=%u).",
953  pThCtl->m_sDevUri, pThCtl->m_uRefCnt);
954  }
955 
956  // unlock global mutex
957  ThGlobalUnlock();
958 }
static void ThSyncExit(BsProxyThCtl_T *pThCtl)
Command service thread to exit.
static void ThGlobalLock()
Lock global mutual exclusion.
uint_t m_uRefCnt
vconn reference count for this thread
Definition: bsProxy.h:151
pthread_t m_thread
the service thread
Definition: bsProxy.h:156
static void ThHashDelete(BsProxyThCtl_T *pThCtl)
Remove and delete the module data from the i/f module hash table.
static void ThGlobalUnlock()
Unlock global mutual exclusion.
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
char* ThNewDevUri ( const char *  sDevName)

Convert the device name to a quasi Uniform Resource Id.

Parameters
sDevNameDevice path name.
Returns
On success, an allocated, canonical device path name is returned.
On failure, NULL is returned.

Definition at line 737 of file bsProxyThread.c.

Referenced by ClientSetTraceState(), and VConnOpenDev().

738 {
739  return NewSearchPathCanonicalized(sDevName);
740 }
int ThQueue ( BsProxyThCtl_T pThCtl,
BsProxyClientHnd_T  hndClient,
BsVConnHnd_T  hndVConn,
BsTid_T  uTid,
BsMsgId_T  uMsgId,
byte_t  bufReq[],
size_t  uReqLen 
)

Queue a request for the given service thread.

Execution Context:
Calling thread.
Parameters
pThCtlService thread control block.
hndClientClient handle.
hndVConnVirtual connection handle.
uTidRequest-Response transaction id.
uMsgIdRequest message id.
bufReqAllocated packed request message body.
uReqLenLength of request in buffer (number of bytes).
Returns
On success, BS_OK is returned.
On error, the appropriate < 0 negated BotSense Error Code is returned.

Definition at line 626 of file bsProxyThread.c.

References BS_ECODE_NO_RSRC, BS_OK, BSPROXY_TH_LOG_ERROR, BSPROXY_TH_MAX_QUEUE_SIZE, _bsproxy_th_ctl::m_queue, _bsproxy_th_ctl::m_sDevUri, ServerHasName(), ThReqNew(), ThSyncLock(), ThSyncSignal(), and ThSyncUnlock().

Referenced by BsProxyDispatch(), and ClientSetTraceState().

633 {
634  BsProxyThReq_T *pThReq;
635  int rc;
636 
637  // lock thread and queue
638  ThSyncLock(pThCtl);
639 
640  //
641  // Queue request on thread's message queue.
642  //
643  if( DListVoidCount(pThCtl->m_queue) < BSPROXY_TH_MAX_QUEUE_SIZE )
644  {
645  pThReq = ThReqNew(hndClient, hndVConn, uTid, uMsgId, bufReq, uReqLen);
646  DListVoidQueue(pThCtl->m_queue, pThReq);
647  ThSyncSignal(pThCtl);
648  LOGDIAG3("%s: Service Thread \"%s\": queue depth=%u.",
649  ServerHasName(), pThCtl->m_sDevUri, DListVoidCount(pThCtl->m_queue));
650  rc = BS_OK;
651  }
652  else
653  {
654  rc = -BS_ECODE_NO_RSRC;
655  BSPROXY_TH_LOG_ERROR(pThCtl->m_sDevUri, rc, "Queue overflow.");
656  }
657 
658  // unlock thread and queue
659  ThSyncUnlock(pThCtl);
660 
661  return rc;
662 }
static void ThSyncUnlock(BsProxyThCtl_T *pThCtl)
Unlock service thread&#39;s mutual exclusion.
#define BSPROXY_TH_MAX_QUEUE_SIZE
request queue maximum depth
Definition: bsProxyThread.c:86
#define BSPROXY_TH_LOG_ERROR(devuri, ecode, efmt,...)
Log Proxy Server Thread Error.
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
#define BS_OK
not an error, success
Definition: BotSense.h:66
static void ThSyncLock(BsProxyThCtl_T *pThCtl)
Lock service thread&#39;s mutual exclusion.
DListVoid_T * m_queue
thread request queue
Definition: bsProxy.h:155
BsProxyThReq_T * ThReqNew(BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen)
Allocate and initalized a new service thread request.
#define BS_ECODE_NO_RSRC
no resource available
Definition: BotSense.h:85
static void ThSyncSignal(BsProxyThCtl_T *pThCtl)
Signal service thread&#39;s condition.
const char * m_sDevUri
proxied device URI or server
Definition: bsProxy.h:150
void ThReqDelete ( BsProxyThReq_T pThReq)

Delete service thread request.

Parameters
pThReqService thread request.

Definition at line 601 of file bsProxyThread.c.

References _bsproxy_th_req::m_bufReq.

Referenced by ClientSetTraceState(), ThQReqDelete(), and ThServiceThread().

602 {
603  if( pThReq != NULL )
604  {
605  delete(pThReq->m_bufReq);
606  delete(pThReq);
607  }
608 }
byte_t * m_bufReq
packed request message buffer
Definition: bsProxy.h:239
BsProxyThReq_T* ThReqNew ( BsProxyClientHnd_T  hndClient,
BsVConnHnd_T  hndVConn,
BsTid_T  uTid,
BsMsgId_T  uMsgId,
byte_t  bufReq[],
size_t  uReqLen 
)

Allocate and initalized a new service thread request.

Parameters
hndClientClient handle.
hndVConnVirtual connection handle.
uTidRequest-Response transaction id.
uMsgIdRequest message id.
bufReqAllocated packed request message body.
uReqLenLength of request in buffer (number of bytes).
Returns
Pointer to allocated request.

Definition at line 577 of file bsProxyThread.c.

References _bsproxy_th_req::m_bufReq, _bsproxy_th_req::m_hndClient, _bsproxy_th_req::m_hndVConn, _bsproxy_th_req::m_uMsgId, _bsproxy_th_req::m_uReqLen, and _bsproxy_th_req::m_uTid.

Referenced by ClientSetTraceState(), and ThQueue().

583 {
584  BsProxyThReq_T *pThReq = NEW(BsProxyThReq_T);
585 
586  pThReq->m_hndClient = hndClient;
587  pThReq->m_hndVConn = hndVConn;
588  pThReq->m_uTid = uTid;
589  pThReq->m_uMsgId = uMsgId;
590  pThReq->m_bufReq = bufReq;
591  pThReq->m_uReqLen = uReqLen;
592 
593  return pThReq;
594 }
byte_t * m_bufReq
packed request message buffer
Definition: bsProxy.h:239
size_t m_uReqLen
request buffer length
Definition: bsProxy.h:240
BsProxyClientHnd_T m_hndClient
proxied client handle
Definition: bsProxy.h:235
BsVConnHnd_T m_hndVConn
virtual connection handle
Definition: bsProxy.h:236
BsMsgId_T m_uMsgId
message id
Definition: bsProxy.h:238
BsTid_T m_uTid
request-response transaction id
Definition: bsProxy.h:237
uint_t timer_elapsed ( struct timeval *  pTvMark)

Calculate the elapsed time between the given time mark and this call.

Parameters
pTvMarkPointer to timeval holding time mark.
Returns
Number of microseconds elasped. If the marked time is invalid or the current time cannot be ascertained, UINT_MAX is returned.

Definition at line 79 of file bsProxyUtils.c.

References timer_mark().

Referenced by timer_mark().

80 {
81  struct timeval tvEnd, tvDelta;
82 
83  timer_mark(&tvEnd);
84 
85  if( !timerisset(pTvMark) || !timerisset(&tvEnd) )
86  {
87  return UINT_MAX;
88  }
89 
90  tvDelta.tv_sec = tvEnd.tv_sec - pTvMark->tv_sec;
91  if( tvEnd.tv_usec < pTvMark->tv_usec )
92  {
93  tvDelta.tv_sec--;
94  tvEnd.tv_usec += 1000000;
95  }
96  tvDelta.tv_usec = tvEnd.tv_usec - pTvMark->tv_usec;
97 
98  return (uint_t)(tvDelta.tv_sec * 1000000 + tvDelta.tv_usec);
99 }
static void timer_mark(struct timeval *pTvMark)
Mark the current time. Resolution is microseconds.
Definition: bsLibClient.c:340
static void timer_mark ( struct timeval *  pTvMark)
inlinestatic

Mark the current time. Resolution is microseconds.

Parameters
pTvMarkPointer to timeval structure to be populated with the current system seconds and useconds.

Definition at line 456 of file bsProxy.h.

References timer_elapsed().

457 {
458  if( gettimeofday(pTvMark, NULL) != OK )
459  {
460  LOGSYSERROR("gettimeofday()");
461  timerclear(pTvMark);
462  }
463 }
BsProxyVConn_T* VConnAcquire ( BsVConnHnd_T  hndVConn)

Acquire virtual connection, locking it from other threads.

The calling thread is blocked until the virtual connection is availble or has been deleted.

Parameters
hndVConn

Definition at line 552 of file bsProxyVConn.c.

References BSPROXY_CHK_VCONN_HND, BsProxyVConn_T::m_bBusy, VConnLockBusy(), VConnUnlockBusy(), and VConnWaitNotBusy().

Referenced by BsProxyDispatch(), ClientSetTraceState(), ModCbGetDevUri(), ModCbIterNext(), ReqGetVConnInfo(), ReqGetVConnList(), ReqMsgTrace(), ThDevRequest(), and VConnClose().

553 {
554  BsProxyVConn_T *pVConn;
555 
556  if( !BSPROXY_CHK_VCONN_HND(hndVConn) )
557  {
558  return NULL;
559  }
560 
561  VConnLockBusy();
562 
563  while( (BsVConnTbl[hndVConn] != NULL) && BsVConnTbl[hndVConn]->m_bBusy )
564  {
566  }
567 
568  if( (pVConn = BsVConnTbl[hndVConn]) != NULL )
569  {
570  pVConn->m_bBusy = true;
571  }
572 
573  VConnUnlockBusy();
574 
575  return pVConn;
576 }
static void VConnUnlockBusy()
Unlock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:101
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
static void VConnWaitNotBusy()
Wait on a virtual connection to become&#39;s free.
Definition: bsProxyVConn.c:146
static void VConnLockBusy()
Lock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:87
#define BSPROXY_CHK_VCONN_HND(hndVConn)
Definition: bsProxy.h:428
bool_t m_bBusy
virtual connection is [not] busy
Definition: bsProxy.h:222
int VConnClose ( BsProxyClientHnd_T  hndClient,
BsVConnHnd_T  hndVConn 
)

Close the virtual connection.

Closing a virtual connections may close the resource (file) descriptor associated with the device, unload the interface module associated with the device, and terminate the device thread. These actions occur only when the reference counts are zero.

Parameters
hndClient

Definition at line 478 of file bsProxyVConn.c.

References BS_ECODE_BAD_VCONN_HND, BS_ECODE_NO_VCONN, BS_OK, BSPROXY_CHK_MOD_VCONN_HND, BSPROXY_LOG_ERROR, BsVConnActiveCnt, ClientHasName(), BsProxyModIF_T::m_fnModClose, BsProxyVConn_T::m_hndVConn, BsProxyVConn_T::m_pModIF, BsProxyVConn_T::m_pThCtl, ModUnload(), ServerHasName(), ThDestroyThread(), VConnAcquire(), and VConnDelete().

Referenced by BsProxyClientUnregister(), ClientSetTraceState(), and ReqDevClose().

479 {
480  BsProxyVConn_T *pVConn;
481  int rc;
482 
483  // Only virtual connections associated with devices can be closed.
484  if( !BSPROXY_CHK_MOD_VCONN_HND(hndVConn) )
485  {
487  }
488 
489  //
490  // Acquire virtual connection associated with handle. Aquiring a virtual
491  // connections locks out other thread access to the vConnection until it
492  // is released.
493  //
494  else if( (pVConn = VConnAcquire(hndVConn)) == NULL )
495  {
496  rc = -BS_ECODE_NO_VCONN;
497  BSPROXY_LOG_ERROR(hndClient, rc, "VConn=%d", hndVConn);
498  }
499 
500  else
501  {
502  //
503  // Destroy the device thread. The thread reference count is decremented and
504  // only when it drops to zero is the thread actually terminated.
505  //
506  ThDestroyThread(pVConn->m_pThCtl);
507 
508  //
509  // Close the device associated with virtual connection. The actual device
510  // may or may not be closed, depending on the device and module
511  // implementation. For example, for an \h_i2c Bus device, the device is
512  // only closed when the last reference to that device is closed.
513  //
514  pVConn->m_pModIF->m_fnModClose(pVConn->m_hndVConn);
515 
516  //
517  // Dynamically unload the interface module from the bsProxy application. The
518  // module's reference count is decremented and only when it drops to zero is
519  // the module actually unloaded.
520  //
521  ModUnload(pVConn->m_pModIF);
522 
523  LOGDIAG1("%s: %s: Virtual connection %d closed.",
524  ServerHasName(), ClientHasName(hndClient), pVConn->m_hndVConn);
525 
526  //
527  // Delete the virtual connection. The slot is now available for a new
528  // virtual connection.
529  //
530  VConnDelete(pVConn);
531 
532  LOGDIAG2("%s: %u active module virtual connections.",
534 
535  rc = BS_OK;
536  }
537 
538  return rc;
539 }
static uint_t BsVConnActiveCnt
Number of active v. connections.
Definition: bsProxyVConn.c:77
BsProxyThCtl_T * m_pThCtl
service thread
Definition: bsProxy.h:225
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
#define BS_OK
not an error, success
Definition: BotSense.h:66
#define BS_ECODE_BAD_VCONN_HND
bad virtual connection handle
Definition: BotSense.h:79
BsModCloseFunc_P m_fnModClose
device close
Definition: bsProxy.h:128
void ThDestroyThread(BsProxyThCtl_T *pThCtl)
Destroy service thread.
#define BSPROXY_LOG_ERROR(hndClient, ecode, efmt,...)
Log Proxy Server Error.
Definition: bsProxy.h:288
BsProxyVConn_T * VConnAcquire(BsVConnHnd_T hndVConn)
Acquire virtual connection, locking it from other threads.
Definition: bsProxyVConn.c:552
BsVConnHnd_T m_hndVConn
self reference
Definition: bsProxy.h:223
void VConnDelete(BsProxyVConn_T *pVConn)
Delete allocated virtual connection entry.
Definition: bsProxyVConn.c:220
#define BSPROXY_CHK_MOD_VCONN_HND(hndVConn)
Definition: bsProxy.h:441
#define BS_ECODE_NO_VCONN
virtual connection not found
Definition: BotSense.h:80
INLINE_IN_H const char * ClientHasName(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:588
BsProxyModIF_T * m_pModIF
interface module I/F
Definition: bsProxy.h:226
void ModUnload(BsProxyModIF_T *pModIF)
Unload the interface module.
Definition: bsProxyMod.c:1191
void VConnDelete ( BsProxyVConn_T pVConn)

Delete allocated virtual connection entry.

The deletion event is broadcasted to all blocked threads waiting on this connection.

Definition at line 220 of file bsProxyVConn.c.

References BSPROXY_CHK_VCONN_HND, BsVConnActiveCnt, BsProxyVConn_T::m_hndVConn, VConnBroadcastNotBusy(), VConnLockBusy(), and VConnUnlockBusy().

Referenced by ClientSetTraceState(), VConnClose(), and VConnOpenDev().

221 {
222  VConnLockBusy();
223 
224  if( pVConn != NULL )
225  {
226  if( BSPROXY_CHK_VCONN_HND(pVConn->m_hndVConn) )
227  {
228  BsVConnTbl[pVConn->m_hndVConn] = NULL;
230  }
231  delete(pVConn);
232  }
233 
235 
236  VConnUnlockBusy();
237 }
static uint_t BsVConnActiveCnt
Number of active v. connections.
Definition: bsProxyVConn.c:77
static void VConnUnlockBusy()
Unlock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:101
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
static void VConnBroadcastNotBusy()
Broadcast that a virtual connection has been freed or deleted.
Definition: bsProxyVConn.c:132
static void VConnLockBusy()
Lock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:87
#define BSPROXY_CHK_VCONN_HND(hndVConn)
Definition: bsProxy.h:428
BsVConnHnd_T m_hndVConn
self reference
Definition: bsProxy.h:223
BsProxyVConn_T* VConnGet ( BsVConnHnd_T  hndVConn)

Get the virtual connection entry associated with the handle.

Warning
The virtual connection is not locked.
Parameters
hndVConn

Definition at line 248 of file bsProxyVConn.c.

References BSPROXY_CHK_VCONN_HND.

Referenced by BsProxyClientUnregister(), ClientSetTraceState(), ModCbSendErrorRsp(), ModCbSendOkRsp(), and ModCbSendRsp().

249 {
250  if( !BSPROXY_CHK_VCONN_HND(hndVConn) )
251  {
252  return NULL;
253  }
254  else
255  {
256  return BsVConnTbl[hndVConn];
257  }
258 }
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
#define BSPROXY_CHK_VCONN_HND(hndVConn)
Definition: bsProxy.h:428
BsProxyVConn_T* VConnNew ( )

Create a new, allocated virtual connection entry.

The new virtual connection is added to the virtual connection table. It is marked busy (i.e. locked). The caller must call VConnRelease() or VConnDelete() to free the entry.

Returns
Allocated virtual connection on success, NULL on failure.

Definition at line 183 of file bsProxyVConn.c.

References BSPROXY_VCONN_MOD_NUMOF, BSPROXY_VCONN_NUMOF, BsVConnActiveCnt, BsProxyVConn_T::m_bBusy, BsProxyVConn_T::m_hndVConn, VConnLockBusy(), and VConnUnlockBusy().

Referenced by ClientSetTraceState(), and VConnOpenDev().

184 {
185  BsProxyVConn_T *pVConn = NULL;
186  BsVConnHnd_T hndVConn;
187 
188  // lock virtual connection table
189  VConnLockBusy();
190 
191  // find an empty virtual connection table slot
193  {
194  for(hndVConn=0; hndVConn<BSPROXY_VCONN_MOD_NUMOF; ++hndVConn)
195  {
196  if( BsVConnTbl[hndVConn] == NULL )
197  {
198  pVConn = NEW(BsProxyVConn_T);
199  pVConn->m_bBusy = true;
200  pVConn->m_hndVConn = hndVConn;
201  BsVConnTbl[hndVConn] = pVConn;
203  break;
204  }
205  }
206  }
207 
208  // unlock virtual connection table
209  VConnUnlockBusy();
210 
211  return pVConn;
212 }
static uint_t BsVConnActiveCnt
Number of active v. connections.
Definition: bsProxyVConn.c:77
static void VConnUnlockBusy()
Unlock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:101
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
#define BSPROXY_VCONN_NUMOF
total number of module handles
Definition: BotSense.h:144
static void VConnLockBusy()
Lock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:87
BsVConnHnd_T m_hndVConn
self reference
Definition: bsProxy.h:223
bool_t m_bBusy
virtual connection is [not] busy
Definition: bsProxy.h:222
#define BSPROXY_VCONN_MOD_NUMOF
number of module-specific handles
Definition: BotSense.h:143
int BsVConnHnd_T
virtual connection handle type
Definition: BotSense.h:151
int VConnOpenDev ( BsProxyClientHnd_T  hndClient,
const char *  sDevName,
const char *  sModName,
byte_t  argbuf[],
size_t  uArgLen,
bool_t  bTrace 
)

Open a virtual device connection.

To open a virtual connection:

  • A new entry is created.
  • The associated device thread is located or created.
  • The associated interface module is located or loaded.
  • The module's exported ModOpen() routine is called.
Parameters
hndClient

Definition at line 325 of file bsProxyVConn.c.

References BS_ECODE_BAD_VAL, BS_ECODE_NO_EXEC, BS_ECODE_NO_MOD, BS_ECODE_NO_RSRC, BSPROXY_LOG_ERROR, BsVConnActiveCnt, ClientHasName(), BsProxyModIF_T::m_fnModOpen, BsProxyVConn_T::m_hndClient, BsProxyVConn_T::m_hndVConn, BsProxyVConn_T::m_pModIF, BsProxyVConn_T::m_pThCtl, BsProxyVConn_T::m_rd, BsProxyModIF_T::m_sModUri, ModLoad(), ModNewModUri(), ModUnload(), ServerHasName(), ThCreateDevThread(), ThDestroyThread(), ThNewDevUri(), VConnDelete(), VConnNew(), and VConnRelease().

Referenced by ClientSetTraceState(), and ReqDevOpen().

331 {
332  BsProxyVConn_T *pVConn = NULL; // new virtual connection entry
333  char *sModUri = NULL; // module URI
334  char *sDevUri = NULL; // device URI
335  BsProxyModIF_T *pModIF = NULL; // interface module interface
336  BsProxyThCtl_T *pThCtl = NULL; // device thread control block
337  int rc; // return code
338  int rd; // resource descriptor
339 
340  //
341  // Allocate a new virtual connection. If no more virtual connections are
342  // available, NULL is returned. The return virtual connection is left in
343  // the acquired state which requires releasing prior to becoming available
344  // for normal operations.
345  //
346  if( (pVConn = VConnNew()) == NULL )
347  {
348  rc = -BS_ECODE_NO_RSRC;
349  BSPROXY_LOG_ERROR(hndClient, rc,
350  "No more virtual connections are available.");
351  }
352 
353  //
354  // Convert module path name to canonical uniform resource identifier.
355  //
356  else if( (sModUri = ModNewModUri(sModName)) == NULL )
357  {
358  rc = -BS_ECODE_BAD_VAL;
359  BSPROXY_LOG_ERROR(hndClient, rc, "\"%s\": Bad module name.", sModName);
360  }
361 
362  //
363  // Convert device path name to canonical uniform resource identifier.
364  //
365  else if( (sDevUri = ThNewDevUri(sDevName)) == NULL )
366  {
367  rc = -BS_ECODE_BAD_VAL;
368  BSPROXY_LOG_ERROR(hndClient, rc, "\"%s\": Bad device name.", sDevName);
369  }
370 
371  //
372  // Dynamically load and initialize library interface module and return the
373  // module's interface. If the module already exists, then the same interface
374  // is returned. The module interface maintains a reference count which is
375  // incremented.
376  //
377  else if( (pModIF = ModLoad(sModUri)) == NULL )
378  {
379  rc = -BS_ECODE_NO_MOD;
380  BSPROXY_LOG_ERROR(hndClient, rc,
381  "Could not load or attach to \"%s\" interface module.", sModUri);
382  }
383 
384  //
385  // Call the interface module's open() function to open the device and allocate
386  // any internal resources. The return resource descriptor is typically a
387  // file or socket descript, but may be any unique non-negative integer
388  // defined by the module.
389  //
390  else if( (rd = pModIF->m_fnModOpen(pVConn->m_hndVConn, bTrace,
391  sDevUri, argbuf, uArgLen)) < 0 )
392  {
393  rc = -BS_ECODE_NO_EXEC;
394  BSPROXY_LOG_ERROR(hndClient, rd,
395  "Could not open \"%s\" interface module.", pModIF->m_sModUri);
396  }
397 
398  //
399  // Create a device thread returning the thread's control. If the thread
400  // already exists, then the same thread control is returned. The thread
401  // control maintains a reference count which is incremented.
402  //
403  else if( (pThCtl = ThCreateDevThread(sDevUri)) == NULL )
404  {
405  rc = -BS_ECODE_NO_EXEC;
406  BSPROXY_LOG_ERROR(hndClient, rc,
407  "Could not create or attach to \"%s\" device service thread.",
408  sDevUri);
409  }
410 
411  //
412  // Success.
413  //
414  // Populate the virtual connection's data. All allocated data are not owned by
415  // the virtual connection. That is, any allocated data will not be deleted
416  // when the virtual connection is deleted.
417  //
418  else
419  {
420  pVConn->m_hndClient = hndClient;
421  pVConn->m_pThCtl = pThCtl;
422  pVConn->m_pModIF = pModIF;
423  pVConn->m_rd = rd;
424 
425  VConnRelease(pVConn->m_hndVConn);
426 
427  rc = (int)pVConn->m_hndVConn;
428 
429  LOGDIAG1("%s: %s: Virtual connection %d opened: %s('%s',rd=%d).",
430  ServerHasName(), ClientHasName(hndClient), pVConn->m_hndVConn,
431  sModUri, sDevUri, rd);
432 
433  LOGDIAG2("%s: %u active module virtual connections.",
435  }
436 
437  //
438  // Error occurred, so clean up before returning.
439  //
440  if( rc < 0 )
441  {
442  if( pThCtl != NULL )
443  {
444  ThDestroyThread(pThCtl);
445  }
446  if( pModIF != NULL )
447  {
448  ModUnload(pModIF);
449  }
450  if( pVConn != NULL )
451  {
452  VConnDelete(pVConn);
453  }
454  }
455 
456  //
457  // Fixed clean up.
458  //
459  delete(sModUri);
460  delete(sDevUri);
461 
462  return rc;
463 }
static uint_t BsVConnActiveCnt
Number of active v. connections.
Definition: bsProxyVConn.c:77
BsProxyVConn_T * VConnNew()
Create a new, allocated virtual connection entry.
Definition: bsProxyVConn.c:183
#define BS_ECODE_BAD_VAL
bad value
Definition: BotSense.h:77
int m_rd
module resource descriptor
Definition: bsProxy.h:227
char * ThNewDevUri(const char *sDevName)
Convert the device name to a quasi Uniform Resource Id.
BsProxyThCtl_T * ThCreateDevThread(const char *sDevUri)
Create a device service thread.
BsProxyThCtl_T * m_pThCtl
service thread
Definition: bsProxy.h:225
void VConnRelease(BsVConnHnd_T hndVConn)
Release the locked virtual client.
Definition: bsProxyVConn.c:585
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
char * ModNewModUri(const char *sModName)
Convert the module name to a quasi Uniform Resource Id.
Definition: bsProxyMod.c:1042
#define BS_ECODE_NO_EXEC
cannot execute
Definition: BotSense.h:88
void ThDestroyThread(BsProxyThCtl_T *pThCtl)
Destroy service thread.
BsProxyClientHnd_T m_hndClient
proxied client handle
Definition: bsProxy.h:224
BsProxyModIF_T * ModLoad(const char *sModUri)
Load the interface module.
Definition: bsProxyMod.c:1089
#define BS_ECODE_NO_RSRC
no resource available
Definition: BotSense.h:85
#define BSPROXY_LOG_ERROR(hndClient, ecode, efmt,...)
Log Proxy Server Error.
Definition: bsProxy.h:288
#define BS_ECODE_NO_MOD
no interface module
Definition: BotSense.h:83
const char * m_sModUri
module Uniform Resource Id
Definition: bsProxy.h:122
BsVConnHnd_T m_hndVConn
self reference
Definition: bsProxy.h:223
void VConnDelete(BsProxyVConn_T *pVConn)
Delete allocated virtual connection entry.
Definition: bsProxyVConn.c:220
BsModOpenFunc_P m_fnModOpen
device open
Definition: bsProxy.h:127
INLINE_IN_H const char * ClientHasName(BsProxyClientHnd_T hndClient)
Get the <b><i>BotSense</i></b> client official name.
Definition: bsProxy.h:588
BsProxyModIF_T * m_pModIF
interface module I/F
Definition: bsProxy.h:226
void ModUnload(BsProxyModIF_T *pModIF)
Unload the interface module.
Definition: bsProxyMod.c:1191
int VConnOpenServer ( )

Open special server virtual connection.

Returns
On success, BS_OK is returned.
On error, the appropriate < 0 negated BotSense Error Code is returned.

Definition at line 265 of file bsProxyVConn.c.

References BS_ECODE_NO_EXEC, BS_OK, BSPROXY_VCONN_SERVER, BsVConnActiveCnt, BsProxyVConn_T::m_bBusy, BsProxyVConn_T::m_hndClient, BsProxyVConn_T::m_hndVConn, BsProxyVConn_T::m_pModIF, BsProxyVConn_T::m_pThCtl, BsProxyVConn_T::m_rd, ServerHasName(), and ThCreateServerThread().

Referenced by ClientSetTraceState(), and main().

266 {
267  BsProxyThCtl_T *pThCtl; // server service thread control
268  BsProxyVConn_T *pVConn; // new virtual connection entry
269  BsVConnHnd_T hndVConn = BSPROXY_VCONN_SERVER; // reserved server handle
270  int rc; // return code
271 
272  //
273  // Create the one server thread.
274  //
275  if( (pThCtl = ThCreateServerThread()) == NULL )
276  {
277  rc = -BS_ECODE_NO_EXEC;
278  LOGERROR("%s: Could not create server service thread.", ServerHasName());
279  }
280 
281  //
282  // Add this special virtual connection to the table. No mutual exclusion is
283  // done since the server should be started prior to servicing an client
284  // requests.
285  //
286  else
287  {
288  pVConn = NEW(BsProxyVConn_T);
289  pVConn->m_bBusy = false;
290  pVConn->m_hndClient = -1;
291  pVConn->m_hndVConn = hndVConn;
292  pVConn->m_pThCtl = pThCtl;
293  pVConn->m_pModIF = NULL;
294  pVConn->m_rd = -1;
295 
296  BsVConnTbl[hndVConn] = pVConn;
298 
299  rc = BS_OK;
300  }
301 
302  return rc;
303 }
static uint_t BsVConnActiveCnt
Number of active v. connections.
Definition: bsProxyVConn.c:77
int m_rd
module resource descriptor
Definition: bsProxy.h:227
BsProxyThCtl_T * ThCreateServerThread()
Create the special server service thread.
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
#define BSPROXY_VCONN_SERVER
handle for server-terminated msgs
Definition: BotSense.h:140
BsProxyThCtl_T * m_pThCtl
service thread
Definition: bsProxy.h:225
INLINE_IN_H const char * ServerHasName()
Get the <b><i>BotSense</i></b> server&#39;s official name.
Definition: bsProxy.h:485
#define BS_OK
not an error, success
Definition: BotSense.h:66
#define BS_ECODE_NO_EXEC
cannot execute
Definition: BotSense.h:88
BsProxyClientHnd_T m_hndClient
proxied client handle
Definition: bsProxy.h:224
BsVConnHnd_T m_hndVConn
self reference
Definition: bsProxy.h:223
bool_t m_bBusy
virtual connection is [not] busy
Definition: bsProxy.h:222
BsProxyModIF_T * m_pModIF
interface module I/F
Definition: bsProxy.h:226
int BsVConnHnd_T
virtual connection handle type
Definition: BotSense.h:151
void VConnRelease ( BsVConnHnd_T  hndVConn)

Release the locked virtual client.

A broadcast is sent to all blocking threads on the freed event.

Parameters
hndVConn

Definition at line 585 of file bsProxyVConn.c.

References BSPROXY_CHK_VCONN_HND, BsProxyVConn_T::m_bBusy, VConnBroadcastNotBusy(), VConnLockBusy(), and VConnUnlockBusy().

Referenced by BsProxyDispatch(), ClientSetTraceState(), ModCbGetDevUri(), ModCbIterNext(), ReqGetVConnInfo(), ReqGetVConnList(), ReqMsgTrace(), ThDevRequest(), and VConnOpenDev().

586 {
587  if( !BSPROXY_CHK_VCONN_HND(hndVConn) )
588  {
589  return;
590  }
591 
592  VConnLockBusy();
593 
594  if( BsVConnTbl[hndVConn] != NULL )
595  {
596  BsVConnTbl[hndVConn]->m_bBusy = false;
597  }
598 
600 
601  VConnUnlockBusy();
602 }
static void VConnUnlockBusy()
Unlock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:101
static BsProxyVConn_T * BsVConnTbl[BSPROXY_VCONN_NUMOF]
table of virtual connections
Definition: bsProxyVConn.c:75
static void VConnBroadcastNotBusy()
Broadcast that a virtual connection has been freed or deleted.
Definition: bsProxyVConn.c:132
static void VConnLockBusy()
Lock virtual connection&#39;s global busy mutual exclusion.
Definition: bsProxyVConn.c:87
#define BSPROXY_CHK_VCONN_HND(hndVConn)
Definition: bsProxy.h:428
bool_t m_bBusy
virtual connection is [not] busy
Definition: bsProxy.h:222

Variable Documentation

BsProxyServerCtl_T* BsServerCtl

The server control block.

Note
In a future bsProxy implementation, multiple server instance threads could be running in the same application. But currently there is only one server per application instance.

Definition at line 831 of file bsProxy.c.

Referenced by ServerGet(), ServerLock(), ServerTryLock(), and ServerUnlock().