botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
bsLibInternal.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: BotSense
4 //
5 // Library: libbsclient
6 //
7 // File: bsLibInternal.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2012-11-25 10:42:41 -0700 (Sun, 25 Nov 2012) $
12  * $Rev: 2544 $
13  *
14  * \brief The libBotSense internal declarations.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \copyright
19  * \h_copy 2009-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 // Permission is hereby granted, without written agreement and without
24 // license or royalty fees, to use, copy, modify, and distribute this
25 // software and its documentation for any purpose, provided that
26 // (1) The above copyright notice and the following two paragraphs
27 // appear in all copies of the source code and (2) redistributions
28 // including binaries reproduces these notices in the supporting
29 // documentation. Substantial modifications to this software may be
30 // copyrighted by their authors and need not follow the licensing terms
31 // described here, provided that the new terms are clearly indicated in
32 // all files where they apply.
33 //
34 // IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
35 // OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
36 // PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
37 // DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
38 // EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
39 // THE POSSIBILITY OF SUCH DAMAGE.
40 //
41 // THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
42 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
43 // FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
44 // "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
45 // PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
46 //
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #ifndef _BSLIBINTERNAL_H
50 #define _BSLIBINTERNAL_H
51 
52 #include <errno.h>
53 #include <pthread.h>
54 
55 #include "rnr/rnrconfig.h"
56 #include "rnr/sock.h"
57 
58 #include "botsense/BotSense.h"
59 #include "botsense/libBotSense.h"
60 
61 //
62 // Default Time values in microseconds.
63 // Note: Defaults can be overridden by client attribute functions or by
64 // configuration file(s) (future).
65 //
66 #define BSCLIENT_T_READ 10000000 ///< 10 second read timeout default
67 #define BSCLIENT_T_WRITE 5000000 ///< 5 second write timeout default
68 #define BSCLIENT_T_FLUSH 5000000 ///< 5 second flush timeout default
69 
70 
71 /*!
72  * \brief Cashed Transaction Information Structure
73  */
74 typedef struct
75 {
76  bool_t m_bCached; ///< this transaction is [not] cached
77  BsProxyMsgHdr_T *m_pMsgHdr; ///< cached message header
78  byte_t *m_pBuf; ///< cached packed message body buffer
80 
81 /*!
82  * \brief Client Virtual Connection Info Structure
83  */
84 typedef struct
85 {
86  BsVConnHnd_T m_hndVConn; ///< virtual connection handle
87  bool_t m_bTrace; ///< do [not] trace this vconn msgs
88  const char *m_sDevName; ///< device path name
89  const char *m_sModName; ///< interface module path name
90  const BsClientAppInfo_T *m_pAppInfo; ///< app-specific info (optional)
91 } BsVConn_T;
92 
93 /*!
94  * \brief The Client Structure Type
95  */
96 typedef struct _bsClientStruct
97 {
98  const char *m_sClientName; ///< client name
99  Socket_T *m_pSocket; ///< IP socket to server
100  pthread_mutex_t m_mutexTrans; ///< client transaction mutex
101  uint_t m_uReqTimeout; ///< client request timeout
102  uint_t m_uRspTimeout; ///< client response timeout
103  uint_t m_uTidCounter; ///< transaction id counter
104  bool_t m_bTraceServer; ///< do [not] trace server-ended msgs
106  ///< transaction cache
107  int m_nVConnCount; ///< number of active v. connections
109  ///< handle to vconn index table
111  ///< table of virtual connections
112 } BsClient_T;
113 
114 
115 // ---------------------------------------------------------------------------
116 // Internal Defines, Macros, Types and Structures
117 // ---------------------------------------------------------------------------
118 
119 /*!
120  * \brief Log [pre/un]packed message header.
121  *
122  * \param pClient \h_botsense client.
123  * \param sPreface Preface string.
124  * \param pMsgHdr Pointer to message header.
125  */
126 #ifdef LOG
127 #define _BS_LOG_MSGHDR(pClient, sPreface, pMsgHdr) \
128  do \
129  { \
130  if( LOGABLE(LOG_LEVEL_DIAG3) ) \
131  { \
132  bsClientLogMsgHdr(pClient, sPreface, pMsgHdr); \
133  } \
134  } while(0)
135 #else
136 #define _BS_LOG_MSGHDR(pClient, sPreface, pMsgHdr)
137 #endif // LOG
138 
139 /*!
140  * \brief Log successful request recieved event.
141  *
142  * \param pClient \h_botsense client.
143  * \param pMsgHdr Pointer to request header.
144  */
145 #define _BS_LOG_REQ(pClient, pMsgHdr) \
146  LOGDIAG3("%s: MsgId=%d sent.", \
147  bsClientAttrGetName(pClient), (pMsgHdr)->m_hdrMsgId)
148 
149 /*!
150  * \brief Log successful repsonse recieved event.
151  *
152  * \param pClient \h_botsense client.
153  * \param pMsgHdr Pointer to response header.
154  */
155 #define _BS_LOG_RSP(pClient, pMsgHdr) \
156  LOGDIAG3("%s: MsgId=%d received.", \
157  bsClientAttrGetName(pClient), (pMsgHdr)->m_hdrMsgId)
158 
159 
160 // ---------------------------------------------------------------------------
161 // Internal Prototypes
162 // ---------------------------------------------------------------------------
163 
164 /*!
165  * Get the client vConnection given the handle.
166  *
167  * \param pClient \h_botsense client.
168  * \param hndVConn New virtual connection proxied device handle.
169  *
170  * \return On success, returns vConnection, else returns NULL.
171  */
172 INLINE_IN_H BsVConn_T *bsGetVConn(BsClient_T *pClient, BsVConnHnd_T hndVConn)
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 }
184 
185 extern void bsVConnClearAll(BsClient_T *pClient);
186 
187 extern int bsVConnAdd(BsClient_T *pClient,
188  BsVConnHnd_T hndVConn,
189  int index);
190 
191 extern int bsVConnRemove(BsClient_T *pClient, BsVConnHnd_T hndVConn);
192 
193 extern int bsVConnNew(BsClient_T *pClient,
194  const char *sDevName,
195  const char *sModName,
196  const BsClientAppInfo_T *pAppInfo,
197  bool_t bTrace);
198 
199 extern int bsVConnDelete(BsClient_T *pClient, int index);
200 
201 
202 #endif // _BSLIBINTERNAL_H
BsVConnHnd_T m_hndVConn
virtual connection handle
Definition: bsLibInternal.h:86
const BsClientAppInfo_T * m_pAppInfo
app-specific info (optional)
Definition: bsLibInternal.h:90
BsVConn_T * m_tblVConn[BSPROXY_VCONN_CLIENT_MAX]
table of virtual connections
const char * m_sModName
interface module path name
Definition: bsLibInternal.h:89
#define BSCLIENT_IS_VCONN_HANDLE(hnd)
Test if the handle is in the valid client virtual connection range.
Definition: libBotSense.h:274
BsProxyMsgHdr_T * m_pMsgHdr
cached message header
Definition: bsLibInternal.h:77
uint_t m_uReqTimeout
client request timeout
Socket_T * m_pSocket
IP socket to server.
Definition: bsLibInternal.h:99
int bsVConnDelete(BsClient_T *pClient, int index)
Delete a vConnection (and proxied device) from the client&#39;s tblVConn table.
Definition: bsLibClient.c:1684
Client Virtual Connection Info Structure.
Definition: bsLibInternal.h:84
int bsVConnRemove(BsClient_T *pClient, BsVConnHnd_T hndVConn)
Remove a vConnection from the client&#39;s tblHndIndex table.
Definition: bsLibClient.c:1565
Cashed Transaction Information Structure.
Definition: bsLibInternal.h:74
pthread_mutex_t m_mutexTrans
client transaction mutex
The Client Structure Type.
Definition: bsLibInternal.h:96
uint_t m_uRspTimeout
client response timeout
#define BSPROXY_VCONN_UNDEF
undefined virtual connection handle
Definition: BotSense.h:139
INLINE_IN_H BsVConn_T * bsGetVConn(BsClient_T *pClient, BsVConnHnd_T hndVConn)
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&#39;s tblVConn table.
Definition: bsLibClient.c:1614
struct _bsClientStruct BsClient_T
The Client Structure Type.
<b><i>BotSense</i></b> client library declarations.
const char * m_sDevName
device path name
Definition: bsLibInternal.h:88
uint_t m_uTidCounter
transaction id counter
BsTransInfo_T * m_tblTransCache[BSPROXY_TID_NUMOF]
transaction cache
<b><i>BotSense</i></b> client library information and callbacks to application-specific data...
Definition: libBotSense.h:86
byte_t * m_pBuf
cached packed message body buffer
Definition: bsLibInternal.h:78
bool_t m_bTraceServer
do [not] trace server-ended msgs
const char * m_sClientName
client name
Definition: bsLibInternal.h:98
bool_t m_bCached
this transaction is [not] cached
Definition: bsLibInternal.h:76
#define BSPROXY_TID_NUMOF
number of unique tid&#39;s
Definition: BotSense.h:169
void bsVConnClearAll(BsClient_T *pClient)
Remove and delete all of a client&#39;s vConnections.
Definition: bsLibClient.c:1478
int bsVConnAdd(BsClient_T *pClient, BsVConnHnd_T hndVConn, int index)
Add a created vConnection to the client&#39;s tblHndIndex table.
Definition: bsLibClient.c:1506
BotSense Proxy Message Header Structure.
Definition: BotSense.h:278
#define BSPROXY_VCONN_CLIENT_MAX
max number of virtual conn/client
Definition: BotSense.h:122
#define BSPROXY_VCONN_MOD_NUMOF
number of module-specific handles
Definition: BotSense.h:143
byte_t m_tblHndIndex[BSPROXY_VCONN_MOD_NUMOF]
handle to vconn index table
int m_nVConnCount
number of active v. connections
bool_t m_bTrace
do [not] trace this vconn msgs
Definition: bsLibInternal.h:87
<b><i>BotSense</i></b> package top-level, unifying header declarations.
int BsVConnHnd_T
virtual connection handle type
Definition: BotSense.h:151