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

The libBotSense internal declarations. More...

#include <errno.h>
#include <pthread.h>
#include "rnr/rnrconfig.h"
#include "rnr/sock.h"
#include "botsense/BotSense.h"
#include "botsense/libBotSense.h"

Go to the source code of this file.

Classes

struct  BsTransInfo_T
 Cashed Transaction Information Structure. More...
 
struct  BsVConn_T
 Client Virtual Connection Info Structure. More...
 
struct  _bsClientStruct
 The Client Structure Type. More...
 

Macros

#define BSCLIENT_T_READ   10000000
 10 second read timeout default
 
#define BSCLIENT_T_WRITE   5000000
 5 second write timeout default
 
#define BSCLIENT_T_FLUSH   5000000
 5 second flush timeout default
 
#define _BS_LOG_MSGHDR(pClient, sPreface, pMsgHdr)
 Log [pre/un]packed message header. More...
 
#define _BS_LOG_REQ(pClient, pMsgHdr)
 Log successful request recieved event. More...
 
#define _BS_LOG_RSP(pClient, pMsgHdr)
 Log successful repsonse recieved event. More...
 

Typedefs

typedef struct _bsClientStruct BsClient_T
 The Client Structure Type.
 

Functions

INLINE_IN_H BsVConn_TbsGetVConn (BsClient_T *pClient, BsVConnHnd_T hndVConn)
 
void bsVConnClearAll (BsClient_T *pClient)
 Remove and delete all of a client's vConnections. More...
 
int bsVConnAdd (BsClient_T *pClient, BsVConnHnd_T hndVConn, int index)
 Add a created vConnection to the client's tblHndIndex table. More...
 
int bsVConnRemove (BsClient_T *pClient, BsVConnHnd_T hndVConn)
 Remove a vConnection from the client's tblHndIndex table. More...
 
int bsVConnNew (BsClient_T *pClient, const char *sDevName, const char *sModName, const BsClientAppInfo_T *pAppInfo, bool_t bTrace)
 Reserve a new client vConnection (and proxied device) in the client's tblVConn table. More...
 
int bsVConnDelete (BsClient_T *pClient, int index)
 Delete a vConnection (and proxied device) from the client's tblVConn table. More...
 

Detailed Description

The libBotSense internal declarations.

LastChangedDate
2012-11-25 10:42:41 -0700 (Sun, 25 Nov 2012)
Rev
2544
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 bsLibInternal.h.

Macro Definition Documentation

#define _BS_LOG_MSGHDR (   pClient,
  sPreface,
  pMsgHdr 
)
Value:
do \
{ \
if( LOGABLE(LOG_LEVEL_DIAG3) ) \
{ \
bsClientLogMsgHdr(pClient, sPreface, pMsgHdr); \
} \
} while(0)
void bsClientLogMsgHdr(BsClient_P pClient, const char *sPreface, BsProxyMsgHdr_T *pMsgHdr)
Log [pre/un]packed message header.
Definition: bsLibClient.c:1219

Log [pre/un]packed message header.

Parameters
pClient

Definition at line 127 of file bsLibInternal.h.

Referenced by bsClientRecvRsp(), and bsClientSendReq().

#define _BS_LOG_REQ (   pClient,
  pMsgHdr 
)
Value:
LOGDIAG3("%s: MsgId=%d sent.", \
bsClientAttrGetName(pClient), (pMsgHdr)->m_hdrMsgId)

Log successful request recieved event.

Parameters
pClient

Definition at line 145 of file bsLibInternal.h.

Referenced by bsClientTrans().

#define _BS_LOG_RSP (   pClient,
  pMsgHdr 
)
Value:
LOGDIAG3("%s: MsgId=%d received.", \
bsClientAttrGetName(pClient), (pMsgHdr)->m_hdrMsgId)

Log successful repsonse recieved event.

Parameters
pClient

Definition at line 155 of file bsLibInternal.h.

Referenced by bsClientTrans().

Function Documentation

INLINE_IN_H BsVConn_T* bsGetVConn ( BsClient_T pClient,
BsVConnHnd_T  hndVConn 
)

Get the client vConnection given the handle.

Parameters
pClient

Definition at line 172 of file bsLibInternal.h.

References BSCLIENT_IS_VCONN_HANDLE, BSPROXY_VCONN_UNDEF, bsVConnAdd(), bsVConnClearAll(), bsVConnDelete(), bsVConnNew(), bsVConnRemove(), _bsClientStruct::m_tblHndIndex, and _bsClientStruct::m_tblVConn.

Referenced by bsClientAttrGetTraceState(), and bsClientGetMsgName().

173 {
174  if( BSCLIENT_IS_VCONN_HANDLE(hndVConn) &&
175  (pClient->m_tblHndIndex[hndVConn] != BSPROXY_VCONN_UNDEF) )
176  {
177  return pClient->m_tblVConn[pClient->m_tblHndIndex[hndVConn]];
178  }
179  else
180  {
181  return NULL;
182  }
183 }
BsVConn_T * m_tblVConn[BSPROXY_VCONN_CLIENT_MAX]
table of virtual connections
#define BSCLIENT_IS_VCONN_HANDLE(hnd)
Test if the handle is in the valid client virtual connection range.
Definition: libBotSense.h:274
#define BSPROXY_VCONN_UNDEF
undefined virtual connection handle
Definition: BotSense.h:139
byte_t m_tblHndIndex[BSPROXY_VCONN_MOD_NUMOF]
handle to vconn index table
int bsVConnAdd ( BsClient_T pClient,
BsVConnHnd_T  hndVConn,
int  index 
)

Add a created vConnection to the client's tblHndIndex table.

Note
The new vConnection should have been created and reserved prior to adding.
Parameters
pClient

Definition at line 1506 of file bsLibClient.c.

References BS_ECODE_INTERNAL, BS_OK, BSCLIENT_IS_VCONN_HANDLE, BSCLIENT_LOG_ERROR, BSCLIENT_TRY_EXPR, BSPROXY_VCONN_CLIENT_MAX, BSPROXY_VCONN_UNDEF, bsTransLock(), bsTransUnlock(), BsVConn_T::m_hndVConn, _bsClientStruct::m_nVConnCount, _bsClientStruct::m_tblHndIndex, and _bsClientStruct::m_tblVConn.

Referenced by bsGetVConn(), and bsServerReqOpenDev().

1509 {
1510  int i;
1511  int rc;
1512 
1513  BSCLIENT_TRY_EXPR(pClient, BSCLIENT_IS_VCONN_HANDLE(hndVConn),
1514  BS_ECODE_INTERNAL, "VConn=%d: out-of-range.", hndVConn);
1515 
1516  BSCLIENT_TRY_EXPR(pClient, (index < BSPROXY_VCONN_CLIENT_MAX),
1517  BS_ECODE_INTERNAL, "index=%d: out-of-range.", index);
1518 
1519  bsTransLock(pClient);
1520 
1521  i = (int)pClient->m_tblHndIndex[hndVConn];
1522 
1523  if( i != BSPROXY_VCONN_UNDEF )
1524  {
1526  "VConn=%d: index=%d: handle already assigned: "
1527  "Internal vconn tables corrupted.", hndVConn, i);
1528  rc = -BS_ECODE_INTERNAL;
1529  }
1530 
1531  else if( pClient->m_tblVConn[index] == NULL )
1532  {
1534  "VConn=%d: index=%d: No vConnection present: "
1535  "Internal vconn tables corrupted.", hndVConn, index);
1536  rc = -BS_ECODE_INTERNAL;
1537  }
1538 
1539  else
1540  {
1541  pClient->m_tblVConn[index]->m_hndVConn = hndVConn;
1542  pClient->m_tblHndIndex[hndVConn] = (byte_t)index;
1543  pClient->m_nVConnCount++;
1544  rc = BS_OK;
1545  }
1546 
1547  bsTransUnlock(pClient);
1548 
1549  return rc;
1550 }
BsVConnHnd_T m_hndVConn
virtual connection handle
Definition: bsLibInternal.h:86
BsVConn_T * m_tblVConn[BSPROXY_VCONN_CLIENT_MAX]
table of virtual connections
#define BSCLIENT_IS_VCONN_HANDLE(hnd)
Test if the handle is in the valid client virtual connection range.
Definition: libBotSense.h:274
#define BSCLIENT_LOG_ERROR(pClient, ecode, efmt,...)
Log Error.
Definition: libBotSense.h:170
static void bsTransLock(BsClient_T *pClient)
Lock client&#39;s transaction mutual exclusion.
Definition: bsLibClient.c:97
#define BS_OK
not an error, success
Definition: BotSense.h:66
#define BSPROXY_VCONN_UNDEF
undefined virtual connection handle
Definition: BotSense.h:139
static void bsTransUnlock(BsClient_T *pClient)
Unlock client&#39;s transaction mutual exclusion.
Definition: bsLibClient.c:113
#define BSCLIENT_TRY_EXPR(pClient, expr, ecode, efmt,...)
Check if expression evaluates to true.
Definition: libBotSense.h:259
#define BSPROXY_VCONN_CLIENT_MAX
max number of virtual conn/client
Definition: BotSense.h:122
#define BS_ECODE_INTERNAL
internal error (bug)
Definition: BotSense.h:93
byte_t m_tblHndIndex[BSPROXY_VCONN_MOD_NUMOF]
handle to vconn index table
int m_nVConnCount
number of active v. connections
void bsVConnClearAll ( BsClient_T pClient)

Remove and delete all of a client's vConnections.

Parameters
pClient

Definition at line 1478 of file bsLibClient.c.

References BSPROXY_VCONN_UNDEF, bsVConnDelete(), bsVConnRemove(), and _bsClientStruct::m_tblHndIndex.

Referenced by bsClientDelete(), bsGetVConn(), and bsServerDisconnect().

1479 {
1480  size_t nHnd;
1481  int index;
1482 
1483  for(nHnd=0; nHnd<arraysize(pClient->m_tblHndIndex); ++nHnd)
1484  {
1485  index = (int)pClient->m_tblHndIndex[nHnd];
1486  if( index != BSPROXY_VCONN_UNDEF )
1487  {
1488  bsVConnRemove(pClient, (BsVConnHnd_T)nHnd);
1489  bsVConnDelete(pClient, index);
1490  }
1491  }
1492 }
int bsVConnRemove(BsClient_T *pClient, BsVConnHnd_T hndVConn)
Remove a vConnection from the client&#39;s tblHndIndex table.
Definition: bsLibClient.c:1565
#define BSPROXY_VCONN_UNDEF
undefined virtual connection handle
Definition: BotSense.h:139
int bsVConnDelete(BsClient_T *pClient, int index)
Delete a vConnection (and proxied device) from the client&#39;s tblVConn table.
Definition: bsLibClient.c:1684
byte_t m_tblHndIndex[BSPROXY_VCONN_MOD_NUMOF]
handle to vconn index table
int BsVConnHnd_T
virtual connection handle type
Definition: BotSense.h:151
int bsVConnDelete ( BsClient_T pClient,
int  index 
)

Delete a vConnection (and proxied device) from the client's tblVConn table.

Note
The vConnection should be removed first prior to deletion.
Parameters
pClient

Definition at line 1684 of file bsLibClient.c.

References BS_ECODE_INTERNAL, BS_OK, BSCLIENT_LOG_ERROR, BSCLIENT_TRY_EXPR, BSPROXY_VCONN_CLIENT_MAX, bsTransLock(), bsTransUnlock(), BsVConn_T::m_sDevName, BsVConn_T::m_sModName, and _bsClientStruct::m_tblVConn.

Referenced by bsGetVConn(), bsServerReqCloseDev(), bsServerReqOpenDev(), and bsVConnClearAll().

1685 {
1686  BsVConn_T *pVConn;
1687  int rc;
1688 
1689  BSCLIENT_TRY_EXPR(pClient, (index < BSPROXY_VCONN_CLIENT_MAX),
1690  BS_ECODE_INTERNAL, "index=%d: out-of-range.", index);
1691 
1692  bsTransLock(pClient);
1693 
1694  pVConn = pClient->m_tblVConn[index];
1695 
1696  if( pVConn == NULL )
1697  {
1699  "index=%u: vConnection not present in table.", index);
1700  rc = -BS_ECODE_INTERNAL;
1701  }
1702 
1703  else
1704  {
1705  delete((char *)(pVConn->m_sDevName));
1706  delete((char *)(pVConn->m_sModName));
1707  delete(pVConn);
1708 
1709  // free slot
1710  pClient->m_tblVConn[index] = NULL;
1711 
1712  rc = BS_OK;
1713  }
1714 
1715  bsTransUnlock(pClient);
1716 
1717  return rc;
1718 }
BsVConn_T * m_tblVConn[BSPROXY_VCONN_CLIENT_MAX]
table of virtual connections
const char * m_sModName
interface module path name
Definition: bsLibInternal.h:89
Client Virtual Connection Info Structure.
Definition: bsLibInternal.h:84
#define BSCLIENT_LOG_ERROR(pClient, ecode, efmt,...)
Log Error.
Definition: libBotSense.h:170
static void bsTransLock(BsClient_T *pClient)
Lock client&#39;s transaction mutual exclusion.
Definition: bsLibClient.c:97
#define BS_OK
not an error, success
Definition: BotSense.h:66
const char * m_sDevName
device path name
Definition: bsLibInternal.h:88
static void bsTransUnlock(BsClient_T *pClient)
Unlock client&#39;s transaction mutual exclusion.
Definition: bsLibClient.c:113
#define BSCLIENT_TRY_EXPR(pClient, expr, ecode, efmt,...)
Check if expression evaluates to true.
Definition: libBotSense.h:259
#define BSPROXY_VCONN_CLIENT_MAX
max number of virtual conn/client
Definition: BotSense.h:122
#define BS_ECODE_INTERNAL
internal error (bug)
Definition: BotSense.h:93
int bsVConnNew ( BsClient_T pClient,
const char *  sDevName,
const char *  sModName,
const BsClientAppInfo_T pAppInfo,
bool_t  bTrace 
)

Reserve a new client vConnection (and proxied device) in the client's tblVConn table.

Note
The new vConnection still needs to be added.
Parameters
pClient

Definition at line 1614 of file bsLibClient.c.

References BS_ECODE_INTERNAL, BS_ECODE_NO_RSRC, BS_OK, BSCLIENT_LOG_ERROR, bsClientAttrGetVConnCount(), BSPROXY_VCONN_CLIENT_MAX, BSPROXY_VCONN_UNDEF, bsTransLock(), bsTransUnlock(), BsVConn_T::m_bTrace, BsVConn_T::m_hndVConn, BsVConn_T::m_pAppInfo, BsVConn_T::m_sDevName, BsVConn_T::m_sModName, and _bsClientStruct::m_tblVConn.

Referenced by bsGetVConn(), and bsServerReqOpenDev().

1619 {
1620  int index;
1621  BsVConn_T *pVConn;
1622  int rc = BS_OK;
1623 
1624  bsTransLock(pClient);
1625 
1627  {
1629  "Client has the maximum=%d virtual connections.",
1631  rc = -BS_ECODE_NO_RSRC;
1632  }
1633 
1634  else
1635  {
1636  for(index=0; index<BSPROXY_VCONN_CLIENT_MAX; ++index)
1637  {
1638  if( pClient->m_tblVConn[index] == NULL )
1639  {
1640  break;
1641  }
1642  }
1643 
1644  if( index >= BSPROXY_VCONN_CLIENT_MAX )
1645  {
1647  "Internal vconn tables corrupted.");
1648  rc = -BS_ECODE_INTERNAL;
1649  }
1650  }
1651 
1652  if( rc == BS_OK )
1653  {
1654  pVConn = NEW(BsVConn_T);
1655 
1656  pVConn->m_hndVConn = BSPROXY_VCONN_UNDEF;
1657  pVConn->m_bTrace = bTrace;
1658  pVConn->m_sDevName = new_strdup(sDevName);
1659  pVConn->m_sModName = new_strdup(sModName);
1660  pVConn->m_pAppInfo = pAppInfo;
1661 
1662  // reserve slot
1663  pClient->m_tblVConn[index] = pVConn;
1664 
1665  rc = index;
1666  }
1667 
1668  bsTransUnlock(pClient);
1669 
1670  return rc;
1671 }
BsVConnHnd_T m_hndVConn
virtual connection handle
Definition: bsLibInternal.h:86
const BsClientAppInfo_T * m_pAppInfo
app-specific info (optional)
Definition: bsLibInternal.h:90
int bsClientAttrGetVConnCount(BsClient_P pClient)
Get the number of active virtual connections for this client.
Definition: bsLibClient.c:998
BsVConn_T * m_tblVConn[BSPROXY_VCONN_CLIENT_MAX]
table of virtual connections
const char * m_sModName
interface module path name
Definition: bsLibInternal.h:89
Client Virtual Connection Info Structure.
Definition: bsLibInternal.h:84
#define BSCLIENT_LOG_ERROR(pClient, ecode, efmt,...)
Log Error.
Definition: libBotSense.h:170
static void bsTransLock(BsClient_T *pClient)
Lock client&#39;s transaction mutual exclusion.
Definition: bsLibClient.c:97
#define BS_OK
not an error, success
Definition: BotSense.h:66
#define BSPROXY_VCONN_UNDEF
undefined virtual connection handle
Definition: BotSense.h:139
const char * m_sDevName
device path name
Definition: bsLibInternal.h:88
#define BS_ECODE_NO_RSRC
no resource available
Definition: BotSense.h:85
static void bsTransUnlock(BsClient_T *pClient)
Unlock client&#39;s transaction mutual exclusion.
Definition: bsLibClient.c:113
#define BSPROXY_VCONN_CLIENT_MAX
max number of virtual conn/client
Definition: BotSense.h:122
#define BS_ECODE_INTERNAL
internal error (bug)
Definition: BotSense.h:93
bool_t m_bTrace
do [not] trace this vconn msgs
Definition: bsLibInternal.h:87
int bsVConnRemove ( BsClient_T pClient,
BsVConnHnd_T  hndVConn 
)

Remove a vConnection from the client's tblHndIndex table.

Note
The vConnection stills needs to be deleted.
Parameters
pClient

Definition at line 1565 of file bsLibClient.c.

References BS_ECODE_INTERNAL, BSCLIENT_IS_VCONN_HANDLE, BSCLIENT_LOG_ERROR, BSCLIENT_TRY_EXPR, BSPROXY_VCONN_UNDEF, bsTransLock(), bsTransUnlock(), BsVConn_T::m_hndVConn, _bsClientStruct::m_nVConnCount, _bsClientStruct::m_tblHndIndex, and _bsClientStruct::m_tblVConn.

Referenced by bsGetVConn(), bsServerReqCloseDev(), and bsVConnClearAll().

1566 {
1567  int index;
1568  int rc;
1569 
1570  BSCLIENT_TRY_EXPR(pClient, BSCLIENT_IS_VCONN_HANDLE(hndVConn),
1571  BS_ECODE_INTERNAL, "VConn=%d: out-of-range.", hndVConn);
1572 
1573  bsTransLock(pClient);
1574 
1575  index = pClient->m_tblHndIndex[hndVConn];
1576 
1577  if( index == BSPROXY_VCONN_UNDEF )
1578  {
1580  "VConn=%d: vConnection not present in table.", hndVConn);
1581  rc = -BS_ECODE_INTERNAL;
1582  }
1583 
1584  else
1585  {
1586  pClient->m_tblVConn[index]->m_hndVConn = BSPROXY_VCONN_UNDEF;
1587  pClient->m_tblHndIndex[hndVConn] = BSPROXY_VCONN_UNDEF;
1588  pClient->m_nVConnCount--;
1589 
1590  rc = index;
1591  }
1592 
1593  bsTransUnlock(pClient);
1594 
1595  return rc;
1596 }
BsVConnHnd_T m_hndVConn
virtual connection handle
Definition: bsLibInternal.h:86
BsVConn_T * m_tblVConn[BSPROXY_VCONN_CLIENT_MAX]
table of virtual connections
#define BSCLIENT_IS_VCONN_HANDLE(hnd)
Test if the handle is in the valid client virtual connection range.
Definition: libBotSense.h:274
#define BSCLIENT_LOG_ERROR(pClient, ecode, efmt,...)
Log Error.
Definition: libBotSense.h:170
static void bsTransLock(BsClient_T *pClient)
Lock client&#39;s transaction mutual exclusion.
Definition: bsLibClient.c:97
#define BSPROXY_VCONN_UNDEF
undefined virtual connection handle
Definition: BotSense.h:139
static void bsTransUnlock(BsClient_T *pClient)
Unlock client&#39;s transaction mutual exclusion.
Definition: bsLibClient.c:113
#define BSCLIENT_TRY_EXPR(pClient, expr, ecode, efmt,...)
Check if expression evaluates to true.
Definition: libBotSense.h:259
#define BS_ECODE_INTERNAL
internal error (bug)
Definition: BotSense.h:93
byte_t m_tblHndIndex[BSPROXY_VCONN_MOD_NUMOF]
handle to vconn index table
int m_nVConnCount
number of active v. connections