botsense/libbotsense/bsLibServer.c
int bsServerReqOpenDev(BsClient_P               pClient,
                       const char              *sDevName,
                       const char              *sModName,
                       byte_t                   argbuf[],
                       size_t                   arglen,
                       const BsClientAppInfo_T *pAppInfo,
                       bool_t                   bInitTrace)
{
  static BsProxyMsgId_T msgIdReq = BsProxyMsgIdReqDevOpen;
  static BsProxyMsgId_T msgIdRsp = BsProxyMsgIdRspDevOpen;

  BsProxyReqDevOpen_T   msgReq;                   // request message 
  BsProxyRspDevOpen_T   msgRsp;                   // response message
  byte_t                buf[BSPROXY_MSG_MAX_LEN]; // req/rsp buffer
  bool_t                bTrace;                   // do [not] trace messages
  int                   index;                    // internal vconn index
  int                   n;                        // number of bytes/return code
  int                   rc;                       // return code

  //
  // Parameter checks.
  //
  BSCLIENT_TRY_EXPR(pClient, (strlen(sDevName)<=BSPROXY_REQDEVOPEN_DEVNAME_LEN),
      BS_ECODE_BAD_VAL,
      "%zu > %u", strlen(sDevName), BSPROXY_REQDEVOPEN_DEVNAME_LEN);

  BSCLIENT_TRY_EXPR(pClient, (strlen(sModName)<=BSPROXY_REQDEVOPEN_MODNAME_LEN),
      BS_ECODE_BAD_VAL,
      "%zu > %u", strlen(sModName), BSPROXY_REQDEVOPEN_MODNAME_LEN);

  BSCLIENT_TRY_EXPR(pClient, (arglen<=BSPROXY_REQDEVOPEN_ARGBUF_LEN),
      BS_ECODE_BAD_VAL,
      "%zu > %u", arglen, BSPROXY_REQDEVOPEN_ARGBUF_LEN);

  //
  // Create and reserve new client vConnection.
  //
  if((index=bsVConnNew(pClient, sDevName, sModName, pAppInfo, bInitTrace)) < 0)
  {
    return index;
  }

  // server-ended trace state
  bTrace = bsClientAttrGetTraceState(pClient, BSPROXY_VCONN_SERVER);

  //
  // Set request message values.
  //
  msgReq.m_trace = bInitTrace;
  strcpy(msgReq.m_devname, sDevName);
  strcpy(msgReq.m_modname, sModName);
  memcpy(msgReq.m_argbuf.u.m_buf, argbuf, arglen);
  msgReq.m_argbuf.m_count = arglen;

  //
  // Pack request.
  //
  if( (n = BsProxyPackReqDevOpen(&msgReq, BSPROXY_BUF_BODY(buf), bTrace)) < 0 )
  {
    BSCLIENT_LOG_NM_ERROR(pClient, n, "MsgId=%u", msgIdReq);
    rc = -BS_ECODE_BAD_MSG;
  }

  //
  // Execute request-response transaction.
  //
  else if( (n = bsClientTrans(pClient,  BSPROXY_VCONN_SERVER,
                              msgIdReq, buf, (size_t)n,
                              msgIdRsp, buf, sizeof(buf))) < 0 )
  {
    BSCLIENT_LOG_ERROR(pClient, n, "MsgId=%u: Transaction failed.", msgIdReq);
    rc = n;
  }

  //
  // Unpack response.
  //
  else if( (n = BsProxyUnpackRspDevOpen(buf, (size_t)n, &msgRsp, bTrace)) < 0 )
  {
    BSCLIENT_LOG_NM_ERROR(pClient, n, "MsgId=%u", msgIdRsp);
    rc = -BS_ECODE_BAD_MSG;
  }

  //
  // Success
  //
  else
  {
    bsVConnAdd(pClient, msgRsp.m_vconn, index);
    _BS_LOG_VCONN_OPEN(pClient, index);
    rc = (int)msgRsp.m_vconn;
  }

  //
  // Error clean up
  //
  if( rc < 0 )
  {
    bsVConnDelete(pClient, index);
  }

  return rc;
}
/*!
 * \brief Request server to establish a virtual connection to the device end
 * point.
 *
 * The device is open if not already opened by another virtual connection.
 * Otherwise it is attached to this vconn.
 *
 * The interface module is dynamically loaded into the server and provides
 * the set of services for the client application communicating with the device.
 * 
 * \param pClient     \h_botsense client.
 * \param sDevName    Device path name.
 * \param sModName    Interface module path name.
 * \param argbuf      Packed buffer of module-specific open parameters.
 * \param arglen      Number of packed bytes in argument buffer.
 * \param pAppInfo    Application-specific information and callbacks (optional).
 *                    Set to NULL if no info. Set any member to NULL to ignore
 *                    that value.
 * \param bInitTrace  Initial message tracing enable(true)/disable(false) state.
 * 
 * \return
 * On success, the virtual connection handle is returned.\n
 * \copydoc doc_return_ecode
 */
\brief Request server to establish a virtual connection to the device end
point.

The device is open if not already opened by another virtual connection.
Otherwise it is attached to this vconn.

The interface module is dynamically loaded into the server and provides
the set of services for the client application communicating with the device.

\param pClient     \h_botsense client.
\param sDevName    Device path name.
\param sModName    Interface module path name.
\param argbuf      Packed buffer of module-specific open parameters.
\param arglen      Number of packed bytes in argument buffer.
\param pAppInfo    Application-specific information and callbacks (optional).
Set to NULL if no info. Set any member to NULL to ignore
that value.

\return
On success, the virtual connection handle is returned.\n
\copydoc doc_return_ecode
\ brief Request server to establish a virtual connection to the device end point . The device is open if not already opened by another virtual connection . Otherwise it is attached to this vconn . The interface module is dynamically loaded into the server and provides the set of services for the client application communicating with the device . \ param pClient \ h_botsense client . \ param sDevName Device path name . \ param sModName Interface module path name . \ param argbuf Packed buffer of module - specific open parameters . \ param arglen Number of packed bytes in argument buffer . \ param pAppInfo Application - specific information and callbacks ( optional ) . Set to NULL if no info . Set any member to NULL to ignore that value . \ return On success the virtual connection handle is returned . \ n \ copydoc doc_return_ecode
int bsServerReqOpenDev(BsClient_P               pClient,
                       const char              *sDevName,
                       const char              *sModName,
                       byte_t                   argbuf[],
                       size_t                   arglen,
                       const BsClientAppInfo_T *pAppInfo,
                       bool_t                   bInitTrace)
{
  static BsProxyMsgId_T msgIdReq = BsProxyMsgIdReqDevOpen;
  static BsProxyMsgId_T msgIdRsp = BsProxyMsgIdRspDevOpen;
  BsProxyReqDevOpen_T   msgReq;                   
  BsProxyRspDevOpen_T   msgRsp;                   
  byte_t                buf[BSPROXY_MSG_MAX_LEN]; 
  bool_t                bTrace;                   
  int                   index;                    
  int                   n;                        
  int                   rc;                       
   Parameter checks.
  BSCLIENT_TRY_EXPR(pClient, (strlen(sDevName)<=BSPROXY_REQDEVOPEN_DEVNAME_LEN),
      BS_ECODE_BAD_VAL,
      "%zu > %u", strlen(sDevName), BSPROXY_REQDEVOPEN_DEVNAME_LEN);
  BSCLIENT_TRY_EXPR(pClient, (strlen(sModName)<=BSPROXY_REQDEVOPEN_MODNAME_LEN),
      BS_ECODE_BAD_VAL,
      "%zu > %u", strlen(sModName), BSPROXY_REQDEVOPEN_MODNAME_LEN);
  BSCLIENT_TRY_EXPR(pClient, (arglen<=BSPROXY_REQDEVOPEN_ARGBUF_LEN),
      BS_ECODE_BAD_VAL,
      "%zu > %u", arglen, BSPROXY_REQDEVOPEN_ARGBUF_LEN);
   Create and reserve new client vConnection.
  if((index=bsVConnNew(pClient, sDevName, sModName, pAppInfo, bInitTrace)) < 0)
  {
    return index;
  }
   server-ended trace state
  bTrace = bsClientAttrGetTraceState(pClient, BSPROXY_VCONN_SERVER);
   Set request message values.
  msgReq.m_trace = bInitTrace;
  strcpy(msgReq.m_devname, sDevName);
  strcpy(msgReq.m_modname, sModName);
  memcpy(msgReq.m_argbuf.u.m_buf, argbuf, arglen);
  msgReq.m_argbuf.m_count = arglen;
   Pack request.
  if( (n = BsProxyPackReqDevOpen(&msgReq, BSPROXY_BUF_BODY(buf), bTrace)) < 0 )
  {
    BSCLIENT_LOG_NM_ERROR(pClient, n, "MsgId=%u", msgIdReq);
    rc = -BS_ECODE_BAD_MSG;
  }
   Execute request-response transaction.
  else if( (n = bsClientTrans(pClient,  BSPROXY_VCONN_SERVER,
                              msgIdReq, buf, (size_t)n,
                              msgIdRsp, buf, sizeof(buf))) < 0 )
  {
    BSCLIENT_LOG_ERROR(pClient, n, "MsgId=%u: Transaction failed.", msgIdReq);
    rc = n;
  }
   Unpack response.
  else if( (n = BsProxyUnpackRspDevOpen(buf, (size_t)n, &msgRsp, bTrace)) < 0 )
  {
    BSCLIENT_LOG_NM_ERROR(pClient, n, "MsgId=%u", msgIdRsp);
    rc = -BS_ECODE_BAD_MSG;
  }
   Success
  else
  {
    bsVConnAdd(pClient, msgRsp.m_vconn, index);
    _BS_LOG_VCONN_OPEN(pClient, index);
    rc = (int)msgRsp.m_vconn;
  }
   Error clean up
  if( rc < 0 )
  {
    bsVConnDelete(pClient, index);
  }
  return rc;
}
int bsServerReqOpenDev ( BsClient_P pClient , const char * sDevName , const char * sModName , byte_t argbuf [ ] , size_t arglen , const BsClientAppInfo_T * pAppInfo , bool_t bInitTrace ) { static BsProxyMsgId_T msgIdReq = BsProxyMsgIdReqDevOpen ; static BsProxyMsgId_T msgIdRsp = BsProxyMsgIdRspDevOpen ; BsProxyReqDevOpen_T msgReq ; BsProxyRspDevOpen_T msgRsp ; byte_t buf [ BSPROXY_MSG_MAX_LEN ] ; bool_t bTrace ; int index ; int n ; int rc ; BSCLIENT_TRY_EXPR ( pClient , ( strlen ( sDevName ) <= BSPROXY_REQDEVOPEN_DEVNAME_LEN ) , BS_ECODE_BAD_VAL , " " , strlen ( sDevName ) , BSPROXY_REQDEVOPEN_DEVNAME_LEN ) ; BSCLIENT_TRY_EXPR ( pClient , ( strlen ( sModName ) <= BSPROXY_REQDEVOPEN_MODNAME_LEN ) , BS_ECODE_BAD_VAL , " " , strlen ( sModName ) , BSPROXY_REQDEVOPEN_MODNAME_LEN ) ; BSCLIENT_TRY_EXPR ( pClient , ( arglen <= BSPROXY_REQDEVOPEN_ARGBUF_LEN ) , BS_ECODE_BAD_VAL , " " , arglen , BSPROXY_REQDEVOPEN_ARGBUF_LEN ) ; if ( ( index = bsVConnNew ( pClient , sDevName , sModName , pAppInfo , bInitTrace ) ) < 0 ) { return index ; } bTrace = bsClientAttrGetTraceState ( pClient , BSPROXY_VCONN_SERVER ) ; msgReq . m_trace = bInitTrace ; strcpy ( msgReq . m_devname , sDevName ) ; strcpy ( msgReq . m_modname , sModName ) ; memcpy ( msgReq . m_argbuf . u . m_buf , argbuf , arglen ) ; msgReq . m_argbuf . m_count = arglen ; if ( ( n = BsProxyPackReqDevOpen ( & msgReq , BSPROXY_BUF_BODY ( buf ) , bTrace ) ) < 0 ) { BSCLIENT_LOG_NM_ERROR ( pClient , n , " " , msgIdReq ) ; rc = - BS_ECODE_BAD_MSG ; } else if ( ( n = bsClientTrans ( pClient , BSPROXY_VCONN_SERVER , msgIdReq , buf , ( size_t ) n , msgIdRsp , buf , sizeof ( buf ) ) ) < 0 ) { BSCLIENT_LOG_ERROR ( pClient , n , " " , msgIdReq ) ; rc = n ; } else if ( ( n = BsProxyUnpackRspDevOpen ( buf , ( size_t ) n , & msgRsp , bTrace ) ) < 0 ) { BSCLIENT_LOG_NM_ERROR ( pClient , n , " " , msgIdRsp ) ; rc = - BS_ECODE_BAD_MSG ; } else { bsVConnAdd ( pClient , msgRsp . m_vconn , index ) ; _BS_LOG_VCONN_OPEN ( pClient , index ) ; rc = ( int ) msgRsp . m_vconn ; } if ( rc < 0 ) { bsVConnDelete ( pClient , index ) ; } return rc ; }
\brief Request server to establish a virtual connection to the device end
 point.
\ brief Request server to establish a virtual connection to the device end point .
// request message  // response message // req/rsp buffer // do [not] trace messages // internal vconn index // number of bytes/return code // return code // // Parameter checks. // // // Create and reserve new client vConnection. // // server-ended trace state // // Set request message values. // // // Pack request. // // // Execute request-response transaction. // // // Unpack response. // // // Success // // // Error clean up //