botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
bsLibServer.c
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: BotSense
4 //
5 // Library: libbsclient
6 //
7 // File: bsLibServer.c
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2010-08-20 11:36:38 -0600 (Fri, 20 Aug 2010) $
12  * $Rev: 568 $
13  *
14  * \brief Server-Client connection, control, and information functions.
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 #include <stdio.h>
50 #include <stdlib.h>
51 #include <libgen.h>
52 #include <string.h>
53 
54 #include "rnr/rnrconfig.h"
55 #include "rnr/sock.h"
56 #include "rnr/new.h"
57 #include "rnr/log.h"
58 
59 #include "botsense/BotSense.h"
60 #include "botsense/libBotSense.h"
61 #include "botsense/bsProxyMsgs.h"
62 
63 #include "bsLibInternal.h"
64 
65 
66 // ---------------------------------------------------------------------------
67 // Private Interface
68 // ---------------------------------------------------------------------------
69 
70 #ifdef LOG
71 /*!
72  * \brief Log virtual connection open event.
73  * \param pClient \h_botsense client.
74  * \param index Internal vConnection index.
75  */
76 #define _BS_LOG_VCONN_OPEN(pClient, index) \
77  do \
78  { \
79  if( LOGABLE(LOG_LEVEL_DIAG2) ) \
80  { \
81  bsLogVConnOpenEvent(pClient, index); \
82  } \
83  } while(0)
84 
85 /*!
86  * \brief Log virtual connection open event.
87  *
88  * \param pClient \h_botsense client.
89  * \param index Internal vConnection index.
90  */
91 static void bsLogVConnOpenEvent(BsClient_T *pClient, int index)
92 {
93  FILE *fp;
94  BsVConn_T *pVConn;
95  const BsClientAppInfo_T *pAppInfo;
96 
97  fp = LOG_GET_LOGFP();
98  pVConn = pClient->m_tblVConn[index];
99 
100  if( pVConn == NULL )
101  {
102  fprintf(fp, "%s: internal data corruption.\n", pClient->m_sClientName);
103  return;
104  }
105 
106  pAppInfo = pVConn->m_pAppInfo;
107 
108  fprintf(fp, "%s: Opened Virtual Connection\n", pClient->m_sClientName);
109  fprintf(fp, "{\n");
110  fprintf(fp, " VConn: %d\n", pVConn->m_hndVConn);
111  fprintf(fp, " Device: %s\n", pVConn->m_sDevName);
112  fprintf(fp, " I/F Module: %s\n", pVConn->m_sModName);
113  if( pAppInfo != NULL )
114  {
115  fprintf(fp, " Application = {\n");
116  if( pAppInfo->app_name != NULL )
117  {
118  fprintf(fp, " Name: %s\n", pAppInfo->app_name);
119  }
120  if( pAppInfo->brief != NULL )
121  {
122  fprintf(fp, " Brief: %s\n", pAppInfo->brief);
123  }
124  if( pAppInfo->version != NULL )
125  {
126  fprintf(fp, " Version: %s\n", pAppInfo->version);
127  }
128  if( pAppInfo->date != NULL )
129  {
130  fprintf(fp, " Date: %s\n", pAppInfo->date);
131  }
132  if( pAppInfo->maintainer != NULL )
133  {
134  fprintf(fp, " Maintainer: %s\n", pAppInfo->maintainer);
135  }
136  fprintf(fp, " }\n");
137  }
138  fprintf(fp, "}\n");
139 }
140 
141 #else
142 
143 /*!
144  * \brief Do not log virtual connection open event.
145  * \param pClient \h_botsense client.
146  * \param hndVConn Virtual connection handle.
147  */
148 #define _BS_LOG_VCONN_OPEN(pClient, hndVConn)
149 
150 #endif // LOG
151 
152 
153 // ---------------------------------------------------------------------------
154 // Public Interface
155 // ---------------------------------------------------------------------------
156 
157 /*!
158  * \brief Connect to the bsProxy server.
159  *
160  * \param pClient \h_botsense client.
161  * \param sServerHostName Server's hostname in either a network name or a
162  * dotted IP address.
163  * \param ipServerPort Server's listen port number.
164  *
165  * \copydoc doc_return_std
166  */
168  const char *sServerHostName,
169  int ipServerPort)
170 {
171  Socket_T *pSocket;
172 
173  // close socket if already opened
174  if( SocketStateIsOpen(pClient->m_pSocket) )
175  {
176  bsServerDisconnect(pClient);
177  }
178 
179  // make TCP connection
180  pSocket = SocketOpenTcpConnection(sServerHostName, ipServerPort);
181 
182  if( pSocket == NULL )
183  {
185  "%s:%d", sServerHostName, ipServerPort);
187  }
188 
189  // set socket for non-block I/O
190  SocketAttrSetNonBlocking(pSocket);
191 
192  LOGDIAG2("%s: Connected to server at %s.\n",
193  pClient->m_sClientName, SocketAttrGetRemoteName(pSocket));
194 
195  pClient->m_pSocket = pSocket;
196 
197  return BS_OK;
198 }
199 
200 /*!
201  * \brief Disconnect from the bsProxy server.
202  *
203  * \param pClient \h_botsense client.
204  *
205  * \copydoc doc_return_std
206  */
208 {
209  if( SocketStateIsOpen(pClient->m_pSocket) )
210  {
211  LOGDIAG2("%s: Disconnected from server at %s.\n",
212  pClient->m_sClientName, SocketAttrGetRemoteName(pClient->m_pSocket));
213  SocketClose(pClient->m_pSocket);
214  SocketDelete(pClient->m_pSocket);
215  pClient->m_pSocket = NULL;
216  bsVConnClearAll(pClient);
217  }
218 
219  return BS_OK;
220 }
221 
222 /*!
223  * \brief Request server to loopback the requested message data.
224  *
225  * \param pClient \h_botsense client.
226  * \param [in,out] sLoopbackMsg Null-terminated message string to loopback.
227  *
228  * \copydoc doc_return_std
229  */
230 int bsServerReqLoopback(BsClient_P pClient, char sLoopbackMsg[])
231 {
232  static BsProxyMsgId_T msgIdReq = BsProxyMsgIdReqLoopback;
233  static BsProxyMsgId_T msgIdRsp = BsProxyMsgIdRspLoopback;
234 
235  BsProxyReqLoopback_T msgReq; // request message
236  BsProxyRspLoopback_T msgRsp; // response message
237  byte_t buf[BSPROXY_MSG_MAX_LEN]; // req/rsp buffer
238  bool_t bTrace; // do [not] trace messages
239  int n; // number of bytes/return code
240  size_t m; // loopback cdata length
241 
242  // trace state
243  bTrace = bsClientAttrGetTraceState(pClient, BSPROXY_VCONN_SERVER);
244 
245  //
246  // Set request message values.
247  //
248  m = strlen(sLoopbackMsg) + 1;
249  if( sizeof(msgReq.m_cdata) < m )
250  {
251  m = sizeof(msgReq.m_cdata);
252  }
253 
254  strcpy_s(msgReq.m_cdata, m, sLoopbackMsg);
255 
256  //
257  // Pack request.
258  //
259  n = BsProxyPackReqLoopback(&msgReq, BSPROXY_BUF_BODY(buf), bTrace);
260 
261  // check packing return code
262  BSCLIENT_TRY_NM_ECODE(pClient, n, "MsgId=%u", msgIdReq);
263 
264  //
265  // Execute request-response transaction.
266  //
267  n = bsClientTrans(pClient, BSPROXY_VCONN_SERVER,
268  msgIdReq, buf, (size_t)n,
269  msgIdRsp, buf, sizeof(buf));
270 
271  // check transaction return code
272  BSCLIENT_TRY_ECODE(pClient, n, "MsgId=%u: Transaction failed.", msgIdReq);
273 
274  //
275  // Unpack response.
276  //
277  n = BsProxyUnpackRspLoopback(buf, (size_t)n, &msgRsp, bTrace);
278 
279  // check unpack return code
280  BSCLIENT_TRY_NM_ECODE(pClient, n, "MsgId=%u", msgIdRsp);
281 
282  //
283  // Set return values from response.
284  //
285  strcpy_s(sLoopbackMsg, m, msgRsp.m_cdata);
286 
287  return BS_OK;
288 }
289 
290 /*!
291  * \brief Request server to set the server's logging level.
292  *
293  * \param pClient \h_botsense client.
294  * \param nLogLevel Log level.
295  *
296  * \copydoc doc_return_std
297  */
298 int bsServerReqSetLogging(BsClient_P pClient, int nLogLevel)
299 {
300  static BsProxyMsgId_T msgIdReq = BsProxyMsgIdReqSetLogging;
301  static BsProxyMsgId_T msgIdRsp = BsProxyMsgIdRspOk;
302 
303  BsProxyReqSetLogging_T msgReq; // request message
304  byte_t buf[BSPROXY_MSG_MAX_LEN]; // req/rsp buffer
305  bool_t bTrace; // do [not] trace messages
306  int n; // num. of bytes/return code
307 
308  // trace state
309  bTrace = bsClientAttrGetTraceState(pClient, BSPROXY_VCONN_SERVER);
310 
311  //
312  // Set request message values.
313  //
314  msgReq.m_level = nLogLevel;
315 
316  //
317  // Pack request.
318  //
319  n = BsProxyPackReqSetLogging(&msgReq, BSPROXY_BUF_BODY(buf), bTrace);
320 
321  // check packing return code
322  BSCLIENT_TRY_NM_ECODE(pClient, n, "MsgId=%u", msgIdReq);
323 
324  //
325  // Execute request-response transaction.
326  //
327  n = bsClientTrans(pClient, BSPROXY_VCONN_SERVER,
328  msgIdReq, buf, (size_t)n,
329  msgIdRsp, buf, sizeof(buf));
330 
331  // check transaction return code
332  BSCLIENT_TRY_ECODE(pClient, n, "MsgId=%u: Transaction failed.", msgIdReq);
333 
334  //
335  // Unpack response. No response body.
336  //
337 
338  //
339  // Set return values from response. No response values.
340  //
341 
342  return BS_OK;
343 }
344 
345 /*!
346  * \brief Request server to return the server's version string.
347  *
348  * \param pClient \h_botsense client.
349  * \param [out] bufVer Output null-terminated string buffer.
350  * \param bufSize Size of output buffer (chars).
351  *
352  * \copydoc doc_return_std
353  */
354 int bsServerReqGetVersion(BsClient_P pClient, char bufVer[], size_t bufSize)
355 {
356  static BsProxyMsgId_T msgIdReq = BsProxyMsgIdReqGetVersion;
357  static BsProxyMsgId_T msgIdRsp = BsProxyMsgIdRspGetVersion;
358 
359  BsProxyRspGetVersion_T msgRsp; // response message
360  byte_t buf[BSPROXY_MSG_MAX_LEN]; // req/rsp buffer
361  bool_t bTrace; // do [not] trace messages
362  int n; // num. of bytes/return code
363 
364  // trace state
365  bTrace = bsClientAttrGetTraceState(pClient, BSPROXY_VCONN_SERVER);
366 
367  //
368  // Set request message values. No request values.
369  //
370 
371  //
372  // Pack request. No request body.
373  //
374 
375  //
376  // Execute request-response transaction.
377  //
378  n = bsClientTrans(pClient, BSPROXY_VCONN_SERVER,
379  msgIdReq, buf, (size_t)0,
380  msgIdRsp, buf, sizeof(buf));
381 
382  // check transaction return code
383  BSCLIENT_TRY_ECODE(pClient, n, "MsgId=%u: Transaction failed.", msgIdReq);
384 
385  //
386  // Unpack response.
387  //
388  n = BsProxyUnpackRspGetVersion(buf, (size_t)n, &msgRsp, bTrace);
389 
390  // check unpack return code
391  BSCLIENT_TRY_NM_ECODE(pClient, n, "MsgId=%u", msgIdRsp);
392 
393  //
394  // Set return values from response.
395  //
396  strcpy_s(bufVer, bufSize, msgRsp.m_version);
397 
398  return BS_OK;
399 }
400 
401 /*!
402  * \brief Request server to enable/disable message tracing on a virtual
403  * connection.
404  *
405  * \param pClient \h_botsense client.
406  * \param hndVConn Virtual connection handle to set tracing state.
407  * \param bNewTrace Message new tracing enable(true)/disable(false) state.
408  *
409  * \copydoc doc_return_std
410  */
412  BsVConnHnd_T hndVConn,
413  bool_t bNewTrace)
414 {
415  static BsProxyMsgId_T msgIdReq = BsProxyMsgIdReqMsgTrace;
416  static BsProxyMsgId_T msgIdRsp = BsProxyMsgIdRspOk;
417 
418  BsProxyReqMsgTrace_T msgReq; // request message
419  byte_t buf[BSPROXY_MSG_MAX_LEN]; // req/rsp buffer
420  bool_t bTrace; // do [not] trace messages
421  int n; // number of bytes/return code
422 
423  // trace state
424  bTrace = bsClientAttrGetTraceState(pClient, BSPROXY_VCONN_SERVER);
425 
426  //
427  // Set request message values.
428  //
429  msgReq.m_vconn = (byte_t)hndVConn;
430  msgReq.m_trace = bNewTrace;
431 
432  //
433  // Pack request.
434  //
435  n = BsProxyPackReqMsgTrace(&msgReq, BSPROXY_BUF_BODY(buf), bTrace);
436 
437  // check packing return code
438  BSCLIENT_TRY_NM_ECODE(pClient, n, "MsgId=%u", msgIdReq);
439 
440  //
441  // Execute request-response transaction.
442  //
443  n = bsClientTrans(pClient, BSPROXY_VCONN_SERVER,
444  msgIdReq, buf, (size_t)n,
445  msgIdRsp, buf, sizeof(buf));
446 
447  // check transaction return code
448  BSCLIENT_TRY_ECODE(pClient, n, "MsgId=%u: Transaction failed.", msgIdReq);
449 
450  //
451  // Unpack response. No response body.
452  //
453 
454  //
455  // Set return values from response. No response values.
456  //
457 
458  return BS_OK;
459 }
460 
461 /*!
462  * \brief Request server to establish a virtual connection to the device end
463  * point.
464  *
465  * The device is open if not already opened by another virtual connection.
466  * Otherwise it is attached to this vconn.
467  *
468  * The interface module is dynamically loaded into the server and provides
469  * the set of services for the client application communicating with the device.
470  *
471  * \param pClient \h_botsense client.
472  * \param sDevName Device path name.
473  * \param sModName Interface module path name.
474  * \param argbuf Packed buffer of module-specific open parameters.
475  * \param arglen Number of packed bytes in argument buffer.
476  * \param pAppInfo Application-specific information and callbacks (optional).
477  * Set to NULL if no info. Set any member to NULL to ignore
478  * that value.
479  * \param bInitTrace Initial message tracing enable(true)/disable(false) state.
480  *
481  * \return
482  * On success, the virtual connection handle is returned.\n
483  * \copydoc doc_return_ecode
484  */
486  const char *sDevName,
487  const char *sModName,
488  byte_t argbuf[],
489  size_t arglen,
490  const BsClientAppInfo_T *pAppInfo,
491  bool_t bInitTrace)
492 {
493  static BsProxyMsgId_T msgIdReq = BsProxyMsgIdReqDevOpen;
494  static BsProxyMsgId_T msgIdRsp = BsProxyMsgIdRspDevOpen;
495 
496  BsProxyReqDevOpen_T msgReq; // request message
497  BsProxyRspDevOpen_T msgRsp; // response message
498  byte_t buf[BSPROXY_MSG_MAX_LEN]; // req/rsp buffer
499  bool_t bTrace; // do [not] trace messages
500  int index; // internal vconn index
501  int n; // number of bytes/return code
502  int rc; // return code
503 
504  //
505  // Parameter checks.
506  //
507  BSCLIENT_TRY_EXPR(pClient, (strlen(sDevName)<=BSPROXY_REQDEVOPEN_DEVNAME_LEN),
509  "%zu > %u", strlen(sDevName), BSPROXY_REQDEVOPEN_DEVNAME_LEN);
510 
511  BSCLIENT_TRY_EXPR(pClient, (strlen(sModName)<=BSPROXY_REQDEVOPEN_MODNAME_LEN),
513  "%zu > %u", strlen(sModName), BSPROXY_REQDEVOPEN_MODNAME_LEN);
514 
517  "%zu > %u", arglen, BSPROXY_REQDEVOPEN_ARGBUF_LEN);
518 
519  //
520  // Create and reserve new client vConnection.
521  //
522  if((index=bsVConnNew(pClient, sDevName, sModName, pAppInfo, bInitTrace)) < 0)
523  {
524  return index;
525  }
526 
527  // server-ended trace state
528  bTrace = bsClientAttrGetTraceState(pClient, BSPROXY_VCONN_SERVER);
529 
530  //
531  // Set request message values.
532  //
533  msgReq.m_trace = bInitTrace;
534  strcpy(msgReq.m_devname, sDevName);
535  strcpy(msgReq.m_modname, sModName);
536  memcpy(msgReq.m_argbuf.u.m_buf, argbuf, arglen);
537  msgReq.m_argbuf.m_count = arglen;
538 
539  //
540  // Pack request.
541  //
542  if( (n = BsProxyPackReqDevOpen(&msgReq, BSPROXY_BUF_BODY(buf), bTrace)) < 0 )
543  {
544  BSCLIENT_LOG_NM_ERROR(pClient, n, "MsgId=%u", msgIdReq);
545  rc = -BS_ECODE_BAD_MSG;
546  }
547 
548  //
549  // Execute request-response transaction.
550  //
551  else if( (n = bsClientTrans(pClient, BSPROXY_VCONN_SERVER,
552  msgIdReq, buf, (size_t)n,
553  msgIdRsp, buf, sizeof(buf))) < 0 )
554  {
555  BSCLIENT_LOG_ERROR(pClient, n, "MsgId=%u: Transaction failed.", msgIdReq);
556  rc = n;
557  }
558 
559  //
560  // Unpack response.
561  //
562  else if( (n = BsProxyUnpackRspDevOpen(buf, (size_t)n, &msgRsp, bTrace)) < 0 )
563  {
564  BSCLIENT_LOG_NM_ERROR(pClient, n, "MsgId=%u", msgIdRsp);
565  rc = -BS_ECODE_BAD_MSG;
566  }
567 
568  //
569  // Success
570  //
571  else
572  {
573  bsVConnAdd(pClient, msgRsp.m_vconn, index);
574  _BS_LOG_VCONN_OPEN(pClient, index);
575  rc = (int)msgRsp.m_vconn;
576  }
577 
578  //
579  // Error clean up
580  //
581  if( rc < 0 )
582  {
583  bsVConnDelete(pClient, index);
584  }
585 
586  return rc;
587 }
588 
589 /*!
590  * \brief Request server to close a client's vitual connection.
591  *
592  * \param pClient \h_botsense client.
593  * \param hndVConn Handle to virtual connection to close.
594  *
595  * \copydoc doc_return_std
596  */
598 {
599  static BsProxyMsgId_T msgIdReq = BsProxyMsgIdReqDevClose;
600  static BsProxyMsgId_T msgIdRsp = BsProxyMsgIdRspOk;
601 
602  BsProxyReqDevClose_T msgReq; // request message
603  byte_t buf[BSPROXY_MSG_MAX_LEN]; // req/rsp buffer
604  bool_t bTrace; // do [not] trace messages
605  int n; // number of bytes/return code
606  int index; // internal vconn index
607 
608  //
609  // Parameter checks.
610  //
611  BSCLIENT_TRY_EXPR(pClient, BSCLIENT_HAS_VCONN(pClient, hndVConn),
612  BS_ECODE_BAD_VAL, "VConn=%d", hndVConn);
613 
614 
615  // trace state
616  bTrace = bsClientAttrGetTraceState(pClient, BSPROXY_VCONN_SERVER);
617 
618  //
619  // Set request message values.
620  //
621  msgReq.m_vconn = (byte_t)hndVConn;
622 
623  //
624  // Pack request.
625  //
626  n = BsProxyPackReqDevClose(&msgReq, BSPROXY_BUF_BODY(buf), bTrace);
627 
628  // check packing return code
629  BSCLIENT_TRY_NM_ECODE(pClient, n, "MsgId=%u", msgIdReq);
630 
631  //
632  // Execute request-response transaction.
633  //
634  n = bsClientTrans(pClient, BSPROXY_VCONN_SERVER,
635  msgIdReq, buf, (size_t)n,
636  msgIdRsp, buf, sizeof(buf));
637 
638  // check transaction return code
639  BSCLIENT_TRY_ECODE(pClient, n, "MsgId=%u: Transaction failed.", msgIdReq);
640 
641  //
642  // Unpack response. No response body.
643  //
644 
645  //
646  // Set return values from response. No response values.
647  //
648 
649  //
650  // Remove and delete client vConnection.
651  //
652  if( (index = bsVConnRemove(pClient, hndVConn)) >= 0 )
653  {
654  bsVConnDelete(pClient, index);
655  }
656 
657  LOGDIAG2("%s: Virtual connecton %u closed.",
658  pClient->m_sClientName, (uint_t)hndVConn);
659 
660  return BS_OK;
661 }
662 
663 /*!
664  * \brief Request server to retrieve the server's list of virtual connection
665  * handles for this client.
666  *
667  * \param pClient \h_botsense client.
668  * \param [out] pVecHandles Vector of handles.
669  *
670  * \copydoc doc_return_std
671  */
673  BsVecHandles_T *pVecHandles)
674 {
677 
678  BsProxyRspGetVConnList_T msgRsp; // response message
679  byte_t buf[BSPROXY_MSG_MAX_LEN]; // req/rsp buffer
680  bool_t bTrace; // do [not] trace messages
681  int n; // num bytes/return code
682  int i; // working index
683 
684  // trace state
685  bTrace = bsClientAttrGetTraceState(pClient, BSPROXY_VCONN_SERVER);
686 
687  //
688  // Set request message values. No request values.
689  //
690 
691  //
692  // Pack request. No request body.
693  //
694 
695  //
696  // Execute request-response transaction.
697  //
698  n = bsClientTrans(pClient, BSPROXY_VCONN_SERVER,
699  msgIdReq, buf, (size_t)0,
700  msgIdRsp, buf, sizeof(buf));
701 
702  // check transaction return code
703  BSCLIENT_TRY_ECODE(pClient, n, "MsgId=%u: Transaction failed.", msgIdReq);
704 
705  //
706  // Unpack response.
707  //
708  n = BsProxyUnpackRspGetVConnList(buf, (size_t)n, &msgRsp, bTrace);
709 
710  // check unpack return code
711  BSCLIENT_TRY_NM_ECODE(pClient, n, "MsgId=%u", msgIdRsp);
712 
713  //
714  // Set return values from response.
715  //
716  for(i=0; (i<msgRsp.m_vconn.m_count) && (i<BSPROXY_VCONN_CLIENT_MAX); ++i)
717  {
718  pVecHandles->m_vecHnd[i] = (BsVConnHnd_T)msgRsp.m_vconn.u.m_buf[i];
719  }
720  pVecHandles->m_uCount = msgRsp.m_vconn.m_count;
721 
722  return BS_OK;
723 }
724 
725 /*!
726  * \brief Request server to retrieve the server's information for a given
727  * virtual connection.
728  *
729  * \param pClient \h_botsense client.
730  * \param hndVConn Virtual connection handle.
731  * \param [out] pVConnInfo Proxied device info.
732  *
733  * \copydoc doc_return_std
734  */
736  BsVConnHnd_T hndVConn,
737  BsVConnInfo_T *pVConnInfo)
738 {
741 
742  BsProxyReqGetVConnInfo_T msgReq; // request message
743  BsProxyRspGetVConnInfo_T msgRsp; // response message
744  byte_t buf[BSPROXY_MSG_MAX_LEN]; // req/rsp buffer
745  bool_t bTrace; // do [not] trace messages
746  int n; // num bytes/return code
747 
748  //
749  // Parameter checks.
750  //
751  BSCLIENT_TRY_EXPR(pClient, BSCLIENT_HAS_VCONN(pClient, hndVConn),
752  BS_ECODE_BAD_VAL, "VConn=%d", hndVConn);
753 
754 
755  // trace state
756  bTrace = bsClientAttrGetTraceState(pClient, BSPROXY_VCONN_SERVER);
757 
758  //
759  // Set request message values.
760  //
761  msgReq.m_vconn = (byte_t)hndVConn;
762 
763  //
764  // Pack request.
765  //
766  n = BsProxyPackReqGetVConnInfo(&msgReq, BSPROXY_BUF_BODY(buf), bTrace);
767 
768  // check packing return code
769  BSCLIENT_TRY_NM_ECODE(pClient, n, "MsgId=%u", msgIdReq);
770 
771  //
772  // Execute request-response transaction.
773  //
774  n = bsClientTrans(pClient, BSPROXY_VCONN_SERVER,
775  msgIdReq, buf, (size_t)n,
776  msgIdRsp, buf, sizeof(buf));
777 
778  // check transaction return code
779  BSCLIENT_TRY_ECODE(pClient, n, "MsgId=%u: Transaction failed.", msgIdReq);
780 
781  //
782  // Unpack response.
783  //
784  n = BsProxyUnpackRspGetVConnInfo(buf, (size_t)n, &msgRsp, bTrace);
785 
786  // check unpack return code
787  BSCLIENT_TRY_NM_ECODE(pClient, n, "MsgId=%u", msgIdRsp);
788 
789  //
790  // Set return values from response.
791  //
792  pVConnInfo->m_vconn = msgRsp.m_vconn;
793  pVConnInfo->m_rd = msgRsp.m_rd;
794  strcpy_s(pVConnInfo->m_client, sizeof(pVConnInfo->m_client),
795  msgRsp.m_client);
796  strcpy_s(pVConnInfo->m_devuri, sizeof(pVConnInfo->m_devuri), msgRsp.m_devuri);
797  strcpy_s(pVConnInfo->m_moduri, sizeof(pVConnInfo->m_moduri), msgRsp.m_moduri);
798  strcpy_s(pVConnInfo->m_modver, sizeof(pVConnInfo->m_modver), msgRsp.m_modver);
799  strcpy_s(pVConnInfo->m_moddate, sizeof(pVConnInfo->m_moddate),
800  msgRsp.m_moddate);
801 
802  return BS_OK;
803 }
char m_cdata[(NMFVAL_LEN_MAX_STRING)+1]
cdata
Definition: bsProxyMsgs.h:109
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
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
const char * m_sModName
interface module path name
Definition: bsLibInternal.h:89
#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
BotSense client application - bsProxy server-terminated core messages.
#define BSPROXY_REQDEVOPEN_MODNAME_LEN
Definition: bsProxyMsgs.h:166
int bsServerReqGetVConnInfo(BsClient_P pClient, BsVConnHnd_T hndVConn, BsVConnInfo_T *pVConnInfo)
Request server to retrieve the server&#39;s information for a given virtual connection.
Definition: bsLibServer.c:735
The libBotSense internal declarations.
int bsServerReqLoopback(BsClient_P pClient, char sLoopbackMsg[])
Request server to loopback the requested message data.
Definition: bsLibServer.c:230
char m_modname[(NMFVAL_LEN_MAX_STRING)+1]
modname
Definition: bsProxyMsgs.h:179
Socket_T * m_pSocket
IP socket to server.
Definition: bsLibInternal.h:99
Client Virtual Connection Info Structure.
Definition: bsLibInternal.h:84
union BsProxyRspGetVConnList_T::@12::@13 u
aligned vector items
INLINE_IN_H int BsProxyPackReqLoopback(BsProxyReqLoopback_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsProxyReqLoopback ITV message in big-endian byte order into the output buffer.
Definition: bsProxyMsgs.h:388
int bsVConnRemove(BsClient_T *pClient, BsVConnHnd_T hndVConn)
Remove a vConnection from the client&#39;s tblHndIndex table.
Definition: bsLibClient.c:1565
INLINE_IN_H int BsProxyPackReqDevClose(BsProxyReqDevClose_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsProxyReqDevClose ITV message in big-endian byte order into the output buffer.
Definition: bsProxyMsgs.h:689
bool_t m_trace
trace
Definition: bsProxyMsgs.h:154
byte_t m_vconn
virtual connection handle
Definition: libBotSense.h:139
const char * brief
brief one-line description
Definition: libBotSense.h:89
#define BS_ECODE_SERVER_CONN_FAIL
cannot connect to server
Definition: BotSense.h:89
char m_cdata[(NMFVAL_LEN_MAX_STRING)+1]
cdata
Definition: bsProxyMsgs.h:92
#define BSPROXY_VCONN_SERVER
handle for server-terminated msgs
Definition: BotSense.h:140
const char * date
version date
Definition: libBotSense.h:91
#define BSCLIENT_LOG_SYSERROR(pClient, ecode, efmt,...)
Log System Error.
Definition: libBotSense.h:196
INLINE_IN_H int BsProxyPackReqGetVConnInfo(BsProxyReqGetVConnInfo_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsProxyReqGetVConnInfo ITV message in big-endian byte order into the output buffer...
Definition: bsProxyMsgs.h:775
const char * maintainer
maintainer/owner
Definition: libBotSense.h:92
int bsServerDisconnect(BsClient_P pClient)
Disconnect from the bsProxy server.
Definition: bsLibServer.c:207
#define BSCLIENT_LOG_ERROR(pClient, ecode, efmt,...)
Log Error.
Definition: libBotSense.h:170
The Client Structure Type.
Definition: bsLibInternal.h:96
ReqGetVConnInfo.
Definition: bsProxyMsgs.h:51
bool_t m_trace
trace
Definition: bsProxyMsgs.h:176
int bsServerReqGetVConnList(BsClient_P pClient, BsVecHandles_T *pVecHandles)
Request server to retrieve the server&#39;s list of virtual connection handles for this client...
Definition: bsLibServer.c:672
INLINE_IN_H int BsProxyUnpackRspGetVConnList(byte_t buf[], size_t uMsgLen, BsProxyRspGetVConnList_T *pStruct, bool_t bTrace)
Unpack a BsProxyRspGetVConnList ITV message in big-endian byte order from the input buffer...
Definition: bsProxyMsgs.h:753
#define BS_OK
not an error, success
Definition: BotSense.h:66
BsVConnHnd_T m_vecHnd[BSPROXY_VCONN_CLIENT_MAX]
vector of handles
Definition: libBotSense.h:125
struct BsProxyRspGetVConnList_T::@12 m_vconn
vector
INLINE_IN_H int BsProxyPackReqMsgTrace(BsProxyReqMsgTrace_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsProxyReqMsgTrace ITV message in big-endian byte order into the output buffer.
Definition: bsProxyMsgs.h:560
const char * version
dotted version x.y.z[-app]
Definition: libBotSense.h:90
INLINE_IN_H int BsProxyUnpackRspDevOpen(byte_t buf[], size_t uMsgLen, BsProxyRspDevOpen_T *pStruct, bool_t bTrace)
Unpack a BsProxyRspDevOpen ITV message in big-endian byte order from the input buffer.
Definition: bsProxyMsgs.h:667
RspGetVConnInfo.
Definition: bsProxyMsgs.h:52
#define BSCLIENT_LOG_NM_ERROR(pClient, nmecode, efmt,...)
Log NetMsgs Error.
Definition: libBotSense.h:184
size_t m_count
vector item count
Definition: bsProxyMsgs.h:183
int bsServerReqMsgTrace(BsClient_P pClient, BsVConnHnd_T hndVConn, bool_t bNewTrace)
Request server to enable/disable message tracing on a virtual connection.
Definition: bsLibServer.c:411
INLINE_IN_H int BsProxyPackReqSetLogging(BsProxyReqSetLogging_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsProxyReqSetLogging ITV message in big-endian byte order into the output buffer.
Definition: bsProxyMsgs.h:474
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
char m_moddate[256]
i/f module date
Definition: libBotSense.h:145
int bsServerReqGetVersion(BsClient_P pClient, char bufVer[], size_t bufSize)
Request server to return the server&#39;s version string.
Definition: bsLibServer.c:354
char m_modver[256]
i/f module version
Definition: libBotSense.h:144
<b><i>BotSense</i></b> client library declarations.
#define BS_ECODE_BAD_MSG
bad message
Definition: BotSense.h:76
#define BSPROXY_REQDEVOPEN_DEVNAME_LEN
Definition: bsProxyMsgs.h:163
const char * m_sDevName
device path name
Definition: bsLibInternal.h:88
char m_devuri[(NMFVAL_LEN_MAX_STRING)+1]
devuri
Definition: bsProxyMsgs.h:283
RspGetVConnList.
Definition: bsProxyMsgs.h:50
int bsServerReqCloseDev(BsClient_P pClient, BsVConnHnd_T hndVConn)
Request server to close a client&#39;s vitual connection.
Definition: bsLibServer.c:597
static void bsLogVConnOpenEvent(BsClient_T *pClient, int index)
Log virtual connection open event.
Definition: bsLibServer.c:91
<b><i>BotSense</i></b> client library information and callbacks to application-specific data...
Definition: libBotSense.h:86
#define _BS_LOG_VCONN_OPEN(pClient, index)
Log virtual connection open event.
Definition: bsLibServer.c:76
char m_version[(NMFVAL_LEN_MAX_STRING)+1]
version
Definition: bsProxyMsgs.h:139
int bsServerReqSetLogging(BsClient_P pClient, int nLogLevel)
Request server to set the server&#39;s logging level.
Definition: bsLibServer.c:298
char m_client[256]
client name
Definition: libBotSense.h:141
int bsVConnDelete(BsClient_T *pClient, int index)
Delete a vConnection (and proxied device) from the client&#39;s tblVConn table.
Definition: bsLibClient.c:1684
INLINE_IN_H int BsProxyUnpackRspGetVConnInfo(byte_t buf[], size_t uMsgLen, BsProxyRspGetVConnInfo_T *pStruct, bool_t bTrace)
Unpack a BsProxyRspGetVConnInfo ITV message in big-endian byte order from the input buffer...
Definition: bsProxyMsgs.h:839
void bsVConnClearAll(BsClient_T *pClient)
Remove and delete all of a client&#39;s vConnections.
Definition: bsLibClient.c:1478
size_t m_uCount
vector length
Definition: libBotSense.h:124
ReqGetVConnList.
Definition: bsProxyMsgs.h:49
byte_t m_vconn
vconn
Definition: bsProxyMsgs.h:203
union BsProxyReqDevOpen_T::@10::@11 u
aligned vector items
struct BsProxyReqDevOpen_T::@10 m_argbuf
vector
const char * m_sClientName
client name
Definition: bsLibInternal.h:98
char m_moduri[256]
i/f module URI
Definition: libBotSense.h:143
#define BSCLIENT_TRY_EXPR(pClient, expr, ecode, efmt,...)
Check if expression evaluates to true.
Definition: libBotSense.h:259
int bsServerConnect(BsClient_P pClient, const char *sServerHostName, int ipServerPort)
Connect to the bsProxy server.
Definition: bsLibServer.c:167
size_t m_count
vector item count
Definition: bsProxyMsgs.h:231
INLINE_IN_H int BsProxyUnpackRspGetVersion(byte_t buf[], size_t uMsgLen, BsProxyRspGetVersion_T *pStruct, bool_t bTrace)
Unpack a BsProxyRspGetVersion ITV message in big-endian byte order from the input buffer...
Definition: bsProxyMsgs.h:538
BsProxyMsgId_T
Definition: bsProxyMsgs.h:35
char m_client[(NMFVAL_LEN_MAX_STRING)+1]
client
Definition: bsProxyMsgs.h:281
#define BSPROXY_VCONN_CLIENT_MAX
max number of virtual conn/client
Definition: BotSense.h:122
INLINE_IN_H int BsProxyUnpackRspLoopback(byte_t buf[], size_t uMsgLen, BsProxyRspLoopback_T *pStruct, bool_t bTrace)
Unpack a BsProxyRspLoopback ITV message in big-endian byte order from the input buffer.
Definition: bsProxyMsgs.h:452
int bsServerReqOpenDev(BsClient_P pClient, const char *sDevName, const char *sModName, byte_t argbuf[], size_t arglen, const BsClientAppInfo_T *pAppInfo, bool_t bInitTrace)
Request server to establish a virtual connection to the device end point.
Definition: bsLibServer.c:485
#define BSPROXY_BUF_BODY(buf)
Convenience macro to produce a buffer (offset, size) 2-tuple.
Definition: BotSense.h:272
#define BSCLIENT_HAS_VCONN(pClient, hnd)
Tests if the handle is valid and there is an established virtual connection.
Definition: libBotSense.h:285
#define BSPROXY_REQDEVOPEN_ARGBUF_LEN
Definition: bsProxyMsgs.h:169
#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
int m_rd
resource descriptor
Definition: libBotSense.h:140
#define BSPROXY_MSG_MAX_LEN
total message maximum length
Definition: BotSense.h:259
char m_devname[(NMFVAL_LEN_MAX_STRING)+1]
devname
Definition: bsProxyMsgs.h:177
byte_t m_vconn
vconn
Definition: bsProxyMsgs.h:153
byte_t m_vconn
vconn
Definition: bsProxyMsgs.h:216
char m_modver[(NMFVAL_LEN_MAX_STRING)+1]
modver
Definition: bsProxyMsgs.h:287
INLINE_IN_H int BsProxyPackReqDevOpen(BsProxyReqDevOpen_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsProxyReqDevOpen ITV message in big-endian byte order into the output buffer.
Definition: bsProxyMsgs.h:603
const char * app_name
application name
Definition: libBotSense.h:88
<b><i>BotSense</i></b> package top-level, unifying header declarations.
char m_moduri[(NMFVAL_LEN_MAX_STRING)+1]
moduri
Definition: bsProxyMsgs.h:285
int BsVConnHnd_T
virtual connection handle type
Definition: BotSense.h:151
char m_devuri[256]
device URI
Definition: libBotSense.h:142
char m_moddate[(NMFVAL_LEN_MAX_STRING)+1]
moddate
Definition: bsProxyMsgs.h:289