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

BotSense bsProxy client library /dev/null interface. More...

#include "rnr/rnrconfig.h"
#include "botsense/BotSense.h"
#include "botsense/libBotSense.h"

Go to the source code of this file.

Macros

#define BS_NULL_DEV_NAME   "/dev/null"
 DevNull device.
 
#define BS_NULL_SERVER_MOD   "libbsserver_null"
 server plugin dll module
 
#define BS_NULL_CLIENT_LIB   "libbsclient_null"
 client app library
 

Functions

const char * bsNullGetMsgName (BsClient_P pClient, BsVConnHnd_T hndVConn, uint_t uMsgId)
 Get the DevNull message name. More...
 
int bsNullReqOpen (BsClient_P pClient, bool_t bInitTrace)
 Request proxy server to establish a virtual connection to the /dev/null device. More...
 
int bsNullReqClose (BsClient_P pClient, BsVConnHnd_T hndVConn)
 Request proxy server to close client's proxied DevNull device vitual connection. More...
 
int bsNullReqWrite (BsClient_P pClient, BsVConnHnd_T hndVConn, byte_t wbuf[], size_t uWriteLen)
 Proxied request to write to /dev/null. More...
 

Detailed Description

BotSense bsProxy client library /dev/null interface.

LastChangedDate
2010-08-20 11:36:38 -0600 (Fri, 20 Aug 2010)
Rev
568
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 bsNull.h.

Function Documentation

const char* bsNullGetMsgName ( BsClient_P  pClient,
BsVConnHnd_T  hndVConn,
uint_t  uMsgId 
)

Get the DevNull message name.

For each (virtual connection, message id) 2-tuple, there can be a known name string (provided the id is valid and an application provides the information).

Parameters
pClient

Definition at line 100 of file bsNullClient.c.

References BsNullLookupMsgDef().

103 {
104  const NMMsgDef_T *pMsgDef;
105 
106  pMsgDef = BsNullLookupMsgDef((BsNullMsgId_T)uMsgId);
107 
108  return pMsgDef!=NULL? pMsgDef->m_sMsgName: "unknown";
109 }
const NMMsgDef_T * BsNullLookupMsgDef(BsNullMsgId_T eMsgId)
Look up the message definition associated with the message id.
Definition: bsNullMsgs.c:186
BsNullMsgId_T
Definition: bsNullMsgs.h:35
int bsNullReqClose ( BsClient_P  pClient,
BsVConnHnd_T  hndVConn 
)

Request proxy server to close client's proxied DevNull device vitual connection.

Parameters
pClient

Definition at line 149 of file bsNullClient.c.

150 {
151  return bsServerReqCloseDev(pClient, hndVConn);
152 }
int bsNullReqOpen ( BsClient_P  pClient,
bool_t  bInitTrace 
)

Request proxy server to establish a virtual connection to the /dev/null device.

Parameters
pClient

Definition at line 122 of file bsNullClient.c.

References BS_NULL_DEV_NAME, BS_NULL_SERVER_MOD, and BSCLIENT_TRY_ECODE.

123 {
124  int hnd; // vconn handle / return code
125 
126  //
127  // Execute server transaction (returns handle \h_ge 0 on success).
128  //
129  hnd = bsServerReqOpenDev(pClient, BS_NULL_DEV_NAME, BS_NULL_SERVER_MOD,
130  NULL, (size_t)0, &bsNullAppInfo, bInitTrace);
131 
132  // check transaction return code
133  BSCLIENT_TRY_ECODE(pClient, hnd, "bsServerReqOpenDev(dev='%s') failed.",
135 
136  // return handle
137  return hnd;
138 }
#define BS_NULL_DEV_NAME
DevNull device.
Definition: bsNull.h:55
#define BSCLIENT_TRY_ECODE(pClient, ecode, efmt,...)
Check if <b><i>BotSense</i></b> return value is not an error ( &lt; 0).
Definition: libBotSense.h:214
#define BS_NULL_SERVER_MOD
server plugin dll module
Definition: bsNull.h:57
static BsClientAppInfo_T bsNullAppInfo
<b><i>BotSense</i></b> client application information.
Definition: bsNullClient.c:70
int bsNullReqWrite ( BsClient_P  pClient,
BsVConnHnd_T  hndVConn,
byte_t  wbuf[],
size_t  uWriteLen 
)

Proxied request to write to /dev/null.

Parameters
pClient

Definition at line 166 of file bsNullClient.c.

References BS_ECODE_BAD_VAL, BSCLIENT_HAS_VCONN, BSCLIENT_TRY_ECODE, BSCLIENT_TRY_EXPR, BSCLIENT_TRY_NM_ECODE, BSNULL_REQWRITE_WRITEBUF_LEN, BsNullMsgIdReqWrite, BsNullMsgIdRspWrite, BsNullPackReqWrite(), BsNullUnpackRspWrite(), BSPROXY_BUF_BODY, BSPROXY_MSG_MAX_LEN, BsNullRspWrite_T::m_byteswritten, BsNullReqWrite_T::m_count, BsNullReqWrite_T::m_writebuf, and BsNullReqWrite_T::u.

170 {
171  static BsNullMsgId_T msgIdReq = BsNullMsgIdReqWrite;
172  static BsNullMsgId_T msgIdRsp = BsNullMsgIdRspWrite;
173 
174  BsNullReqWrite_T msgReq; // request message
175  BsNullRspWrite_T msgRsp; // response message
176  byte_t buf[BSPROXY_MSG_MAX_LEN]; // req/rsp buffer
177  bool_t bTrace; // do [not] trace messages
178  int n; // number of bytes/return code
179 
180  //
181  // Parameter checks.
182  //
183  BSCLIENT_TRY_EXPR(pClient, BSCLIENT_HAS_VCONN(pClient, hndVConn),
184  BS_ECODE_BAD_VAL, "VConn=%d", hndVConn);
185 
186  BSCLIENT_TRY_EXPR(pClient,
187  (uWriteLen <= (size_t)BSNULL_REQWRITE_WRITEBUF_LEN), BS_ECODE_BAD_VAL,
188  "write_len=%zu > max_len=%zu",
189  uWriteLen, (size_t)BSNULL_REQWRITE_WRITEBUF_LEN);
190 
191  // trace state
192  bTrace = bsClientAttrGetTraceState(pClient, hndVConn);
193 
194  //
195  // Set request message values.
196  //
197  memcpy(msgReq.m_writebuf.u.m_buf, wbuf, uWriteLen);
198  msgReq.m_writebuf.m_count = uWriteLen;
199 
200  //
201  // Pack request.
202  //
203  n = BsNullPackReqWrite(&msgReq, BSPROXY_BUF_BODY(buf), bTrace);
204 
205  // check packing return code
206  BSCLIENT_TRY_NM_ECODE(pClient, n, "MsgId=%u", msgIdReq);
207 
208  //
209  // Execute request-response transaction.
210  //
211  n = bsClientTrans(pClient, hndVConn,
212  msgIdReq, buf, (size_t)n,
213  msgIdRsp, buf, sizeof(buf));
214 
215  // check transaction return code
216  BSCLIENT_TRY_ECODE(pClient, n, "MsgId=%u: Transaction failed.", msgIdReq);
217 
218  //
219  // Unpack response.
220  //
221  n = BsNullUnpackRspWrite(buf, (size_t)n, &msgRsp, bTrace);
222 
223  // check unpack return code
224  BSCLIENT_TRY_NM_ECODE(pClient, n, "MsgId=%u", msgIdRsp);
225 
226  //
227  // Set return values from response.
228  //
229  return (int)msgRsp.m_byteswritten;
230 }
#define BSCLIENT_TRY_ECODE(pClient, ecode, efmt,...)
Check if <b><i>BotSense</i></b> return value is not an error ( &lt; 0).
Definition: libBotSense.h:214
#define BS_ECODE_BAD_VAL
bad value
Definition: BotSense.h:77
union BsNullReqWrite_T::@8::@9 u
aligned vector items
INLINE_IN_H int BsNullUnpackRspWrite(byte_t buf[], size_t uMsgLen, BsNullRspWrite_T *pStruct, bool_t bTrace)
Unpack a BsNullRspWrite ITV message in big-endian byte order from the input buffer.
Definition: bsNullMsgs.h:202
#define BSCLIENT_TRY_EXPR(pClient, expr, ecode, efmt,...)
Check if expression evaluates to true.
Definition: libBotSense.h:259
#define BSNULL_REQWRITE_WRITEBUF_LEN
Definition: bsNullMsgs.h:54
struct BsNullReqWrite_T::@8 m_writebuf
vector
byte_t m_byteswritten
byteswritten
Definition: bsNullMsgs.h:83
#define BSPROXY_BUF_BODY(buf)
Convenience macro to produce a buffer (offset, size) 2-tuple.
Definition: BotSense.h:272
BsNullMsgId_T
Definition: bsNullMsgs.h:35
#define BSCLIENT_HAS_VCONN(pClient, hnd)
Tests if the handle is valid and there is an established virtual connection.
Definition: libBotSense.h:285
#define BSCLIENT_TRY_NM_ECODE(pClient, nmecode, efmt,...)
Check if NetMsgs (un)packing return value is not an error ( &lt; 0).
Definition: libBotSense.h:236
#define BSPROXY_MSG_MAX_LEN
total message maximum length
Definition: BotSense.h:259
INLINE_IN_H int BsNullPackReqWrite(BsNullReqWrite_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsNullReqWrite ITV message in big-endian byte order into the output buffer.
Definition: bsNullMsgs.h:138
size_t m_count
vector item count
Definition: bsNullMsgs.h:63