botsense/bsModules/bsNull/bsNullServer.c
int bsModOpen(BsVConnHnd_T  hndVConn,
              bool_t        bTrace,
              const char   *sDevUri,
              byte_t        argbuf[],
              size_t        uArgSize)
{
  BsModCtlBlk_T    *pCtlBlk;
  int               fd;

  // Check if handle is in valid range.
  BSMOD_TRY_VCONN_HND_RANGE(hndVConn);

  // Check if resources are available.
  if( BSMOD_RSRC_INUSE_COUNT(BsModRsrcTbl) >= BSMOD_MAX_HANDLES )
  {
    BSMOD_LOG_ERROR(hndVConn, BS_ECODE_NO_RSRC,
        "InUseCount=%u: No more resources available.",
        BSMOD_RSRC_INUSE_COUNT(BsModRsrcTbl));
    return -BS_ECODE_NO_RSRC;
  }
  
  // Check if the handle in this module's resource table is not already in-use.
  else if( BSMOD_RSRC_IS_INUSE(BsModRsrcTbl, hndVConn) )
  {
    BSMOD_LOG_ERROR(hndVConn, BS_ECODE_BUSY, 
        "Module virtual connection handle already in use");
    return -BS_ECODE_BUSY;
  }

  // open device
  fd = open(sDevUri, O_WRONLY);

  if( fd < 0 )
  {
    BSMOD_LOG_SYSERROR(hndVConn, "open(%s,...).", sDevUri);
    return -BS_ECODE_SYS;
  }

  // allocate a new control block and initialize
  pCtlBlk = bsModCtlBlkNew(fd, bTrace);

  // add to module resource table
  BsModCallbacks->m_cbModRsrcAdd(BsModRsrcTbl, hndVConn, pCtlBlk);

  LOGDIAG2("VConn=%d: %d=open(dev=%s, ...).", hndVConn, fd, sDevUri);

  return fd;
}
/*!
 * \brief Open an /dev/null device and associate with the given handle.
 *
 * Subsequent calls to the module use the given handle to associate the 
 * specific module-device instance.
 *
 * The argument buffer contains packed message arguements specific to the 
 * device and module. For this /dev/null module, there are now additional
 * arguments.
 *
 * \note
 * It is the responsibile of the client to ensure consistency if more than
 * one virtual connection is established.
 *
 * \param hndVConn      Virtual connection handle.
 * \param bTrace        Do [not] enable message tracing on this handle.
 * \param sDevUri       Device URI.
 * \param argbuf        Packed specific open configuration arguments submessage.
 * \param uArgSize      Size of packed argumets in buffer (number of bytes).
 *
 * \return
 * On success, returns a unique resource descriptor \h_ge 0 which is typically
 * an opened file descriptor or socket descriptor, but can be module defined.\n
 * \copydoc doc_return_ecode
 */
\brief Open an /dev/null device and associate with the given handle.
Subsequent calls to the module use the given handle to associate the
specific module-device instance.

The argument buffer contains packed message arguements specific to the
device and module. For this /dev/null module, there are now additional
arguments.

\note
It is the responsibile of the client to ensure consistency if more than
one virtual connection is established.

\param hndVConn      Virtual connection handle.
\param bTrace        Do [not] enable message tracing on this handle.
\param sDevUri       Device URI.
\param argbuf        Packed specific open configuration arguments submessage.
\param uArgSize      Size of packed argumets in buffer (number of bytes).

\return
On success, returns a unique resource descriptor \h_ge 0 which is typically
an opened file descriptor or socket descriptor, but can be module defined.\n
\copydoc doc_return_ecode
\ brief Open an / dev / null device and associate with the given handle . Subsequent calls to the module use the given handle to associate the specific module - device instance . The argument buffer contains packed message arguements specific to the device and module . For this / dev / null module there are now additional arguments . \ note It is the responsibile of the client to ensure consistency if more than one virtual connection is established . \ param hndVConn Virtual connection handle . \ param bTrace Do [ not ] enable message tracing on this handle . \ param sDevUri Device URI . \ param argbuf Packed specific open configuration arguments submessage . \ param uArgSize Size of packed argumets in buffer ( number of bytes ) . \ return On success returns a unique resource descriptor \ h_ge 0 which is typically an opened file descriptor or socket descriptor but can be module defined . \ n \ copydoc doc_return_ecode
int bsModOpen(BsVConnHnd_T  hndVConn,
              bool_t        bTrace,
              const char   *sDevUri,
              byte_t        argbuf[],
              size_t        uArgSize)
{
  BsModCtlBlk_T    *pCtlBlk;
  int               fd;
  BSMOD_TRY_VCONN_HND_RANGE(hndVConn);
  if( BSMOD_RSRC_INUSE_COUNT(BsModRsrcTbl) >= BSMOD_MAX_HANDLES )
  {
    BSMOD_LOG_ERROR(hndVConn, BS_ECODE_NO_RSRC,
        "InUseCount=%u: No more resources available.",
        BSMOD_RSRC_INUSE_COUNT(BsModRsrcTbl));
    return -BS_ECODE_NO_RSRC;
  }
  else if( BSMOD_RSRC_IS_INUSE(BsModRsrcTbl, hndVConn) )
  {
    BSMOD_LOG_ERROR(hndVConn, BS_ECODE_BUSY, 
        "Module virtual connection handle already in use");
    return -BS_ECODE_BUSY;
  }
  fd = open(sDevUri, O_WRONLY);
  if( fd < 0 )
  {
    BSMOD_LOG_SYSERROR(hndVConn, "open(%s,...).", sDevUri);
    return -BS_ECODE_SYS;
  }
  pCtlBlk = bsModCtlBlkNew(fd, bTrace);
  BsModCallbacks->m_cbModRsrcAdd(BsModRsrcTbl, hndVConn, pCtlBlk);
  LOGDIAG2("VConn=%d: %d=open(dev=%s, ...).", hndVConn, fd, sDevUri);
  return fd;
}
int bsModOpen ( BsVConnHnd_T hndVConn , bool_t bTrace , const char * sDevUri , byte_t argbuf [ ] , size_t uArgSize ) { BsModCtlBlk_T * pCtlBlk ; int fd ; BSMOD_TRY_VCONN_HND_RANGE ( hndVConn ) ; if ( BSMOD_RSRC_INUSE_COUNT ( BsModRsrcTbl ) >= BSMOD_MAX_HANDLES ) { BSMOD_LOG_ERROR ( hndVConn , BS_ECODE_NO_RSRC , " " , BSMOD_RSRC_INUSE_COUNT ( BsModRsrcTbl ) ) ; return - BS_ECODE_NO_RSRC ; } else if ( BSMOD_RSRC_IS_INUSE ( BsModRsrcTbl , hndVConn ) ) { BSMOD_LOG_ERROR ( hndVConn , BS_ECODE_BUSY , " " ) ; return - BS_ECODE_BUSY ; } fd = open ( sDevUri , O_WRONLY ) ; if ( fd < 0 ) { BSMOD_LOG_SYSERROR ( hndVConn , " " , sDevUri ) ; return - BS_ECODE_SYS ; } pCtlBlk = bsModCtlBlkNew ( fd , bTrace ) ; BsModCallbacks -> m_cbModRsrcAdd ( BsModRsrcTbl , hndVConn , pCtlBlk ) ; LOGDIAG2 ( " " , hndVConn , fd , sDevUri ) ; return fd ; }
\brief Open an /dev/null device and associate with the given handle.
\ brief Open an / dev / null device and associate with the given handle .
// Check if handle is in valid range. // Check if resources are available. // Check if the handle in this module's resource table is not already in-use. // open device // allocate a new control block and initialize // add to module resource table