botsense/bsModules/bsI2C/bsI2CServer.c
int bsModClose(BsVConnHnd_T hndVConn)
{
  BsModCtlBlk_T  *pCtlBlk;

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

  // check is resouce is in-use (i.e. opened)
  if( !BSMOD_RSRC_IS_INUSE(BsModRsrcTbl, hndVConn) )
  {
    BSMOD_LOG_ERROR(hndVConn, BS_ECODE_NO_VCONN,
        "Resources for virtual connection not found.");
    return -BS_ECODE_NO_VCONN;
  }

  // remove from module's resource table
  pCtlBlk = (BsModCtlBlk_T *)BsModCallbacks->m_cbModRsrcRemove(BsModRsrcTbl,
                                                               hndVConn);

  if( pCtlBlk == NULL )
  {
    BSMOD_LOG_ERROR(hndVConn, BS_ECODE_INTERNAL, "No module resource found.");
    return -BS_ECODE_INTERNAL;
  }

  //
  // Closing last reference to device. So really close and free resources.
  //
  if( pCtlBlk->m_uRefCnt <= 1 )
  {
    i2c_close(&pCtlBlk->m_hndI2C);

    LOGDIAG2("VConn=%d: i2c_close(fd=%d).", hndVConn, pCtlBlk->m_hndI2C.fd);

    bsModCtlBlkDelete(pCtlBlk);
  }

  // Simply decrement reference count.
  else
  {
    pCtlBlk->m_uRefCnt--;
  }

  return BS_OK;
}
/*!
 * \brief Close the \h_i2c device and disassociate virtual connection handle.
 *
 * The actual device and resources are only cleared if this is the last
 * virtual connection reference to this device.
 *
 * \param hndVConn  Virtual connection handle.
 *
 * \return
 * \copydoc doc_return_std
 */
\brief Close the \h_i2c device and disassociate virtual connection handle.
The actual device and resources are only cleared if this is the last
virtual connection reference to this device.

\param hndVConn  Virtual connection handle.


\ brief Close the \ h_i2c device and disassociate virtual connection handle . The actual device and resources are only cleared if this is the last virtual connection reference to this device . \ param hndVConn Virtual connection handle .
int bsModClose(BsVConnHnd_T hndVConn)
{
  BsModCtlBlk_T  *pCtlBlk;
  BSMOD_TRY_VCONN_HND_RANGE(hndVConn);
  if( !BSMOD_RSRC_IS_INUSE(BsModRsrcTbl, hndVConn) )
  {
    BSMOD_LOG_ERROR(hndVConn, BS_ECODE_NO_VCONN,
        "Resources for virtual connection not found.");
    return -BS_ECODE_NO_VCONN;
  }
  pCtlBlk = (BsModCtlBlk_T *)BsModCallbacks->m_cbModRsrcRemove(BsModRsrcTbl,
                                                               hndVConn);
  if( pCtlBlk == NULL )
  {
    BSMOD_LOG_ERROR(hndVConn, BS_ECODE_INTERNAL, "No module resource found.");
    return -BS_ECODE_INTERNAL;
  }
   Closing last reference to device. So really close and free resources.
  if( pCtlBlk->m_uRefCnt <= 1 )
  {
    i2c_close(&pCtlBlk->m_hndI2C);
    LOGDIAG2("VConn=%d: i2c_close(fd=%d).", hndVConn, pCtlBlk->m_hndI2C.fd);
    bsModCtlBlkDelete(pCtlBlk);
  }
   Simply decrement reference count.
  else
  {
    pCtlBlk->m_uRefCnt--;
  }
  return BS_OK;
}
int bsModClose ( BsVConnHnd_T hndVConn ) { BsModCtlBlk_T * pCtlBlk ; BSMOD_TRY_VCONN_HND_RANGE ( hndVConn ) ; if ( ! BSMOD_RSRC_IS_INUSE ( BsModRsrcTbl , hndVConn ) ) { BSMOD_LOG_ERROR ( hndVConn , BS_ECODE_NO_VCONN , " " ) ; return - BS_ECODE_NO_VCONN ; } pCtlBlk = ( BsModCtlBlk_T * ) BsModCallbacks -> m_cbModRsrcRemove ( BsModRsrcTbl , hndVConn ) ; if ( pCtlBlk == NULL ) { BSMOD_LOG_ERROR ( hndVConn , BS_ECODE_INTERNAL , " " ) ; return - BS_ECODE_INTERNAL ; } if ( pCtlBlk -> m_uRefCnt <= 1 ) { i2c_close ( & pCtlBlk -> m_hndI2C ) ; LOGDIAG2 ( " " , hndVConn , pCtlBlk -> m_hndI2C . fd ) ; bsModCtlBlkDelete ( pCtlBlk ) ; } else { pCtlBlk -> m_uRefCnt -- ; } return BS_OK ; }
\brief Close the \h_i2c device and disassociate virtual connection handle.
\ brief Close the \ h_i2c device and disassociate virtual connection handle .
// check if handle is in valid range // check is resouce is in-use (i.e. opened) // remove from module's resource table // // Closing last reference to device. So really close and free resources. // // Simply decrement reference count.