CogniBoost/sw/libCogniBoost/cbLibDev.c
static int cbCacheLoad(cbHnd_T      hnd,
                       cbTid_T      uTid,
                       cbPktHdr_T  *pPktHdr,
                       byte_t       bufRspMsg[],
                       size_t       sizeRsp)
{
  cbTransInfo_T  *pInfo;            // cached information
  size_t          uRspMsgLen;       // response message len
  int             rc = 0;           // return code

  cbLock(hnd);

  pInfo = hnd->m_tblTransCache[uTid & CB_HDR_TID_MASK];

  if( (pInfo == NULL) || !pInfo->m_bCached )
  {
    rc = 0;
  }

  else
  {
    uRspMsgLen = (size_t)(pPktHdr->m_hdrMsgLen);
    if( uRspMsgLen > sizeRsp )
    {
      CB_LOG_ERROR(hnd, CB_LIB_ECODE_TOO_BIG,
        "Message length=%zu > buffer size=%zu.", uRspMsgLen, sizeRsp);
      rc = -CB_LIB_ECODE_TOO_BIG;
    }

    // load from cache
    else
    {
      *pPktHdr = *(pInfo->m_pPktHdr);
      memcpy(bufRspMsg, pInfo->m_pBuf, uRspMsgLen);

      LOGDIAG3("Device %d: Loaded response from cache: "
               "tid=%u, msg=%s(msgid=%u).",
        hnd->m_fd, uTid, CB_MSG_NAME_ID(cbGetMsgId(bufRspMsg, uRspMsgLen)));

      rc = 1;
    }
  }

  cbUnlock(hnd);

  return rc;
}
/*!
 * \brief Load cached response from transaction cache.
 *
 * Caching a response occurs when this client thread receives a response
 * for another client thread.
 *
 * \param hnd           CogniBoost device handle.
 * \param uTid          Transaction id.
 * \param [out] pPktHdr Response packet header.
 * \param [out] bufRspMsg  Packed response message buffer.
 * \param sizeRsp       Size of response buffer.
 * 
 * \return
 * Returns \h_lt 0 error code if a response was cached but an error occurred.\n
 * Returns = 0 if no response found in cache.\n
 * Returns \h_gt 0 if a good cached response was loaded.
 */
\brief Load cached response from transaction cache.
Caching a response occurs when this client thread receives a response
for another client thread.

\param hnd           CogniBoost device handle.
\param uTid          Transaction id.
\param [out] pPktHdr Response packet header.
\param [out] bufRspMsg  Packed response message buffer.
\param sizeRsp       Size of response buffer.


\ brief Load cached response from transaction cache . Caching a response occurs when this client thread receives a response for another client thread . \ param hnd CogniBoost device handle . \ param uTid Transaction id . \ param [ out ] pPktHdr Response packet header . \ param [ out ] bufRspMsg Packed response message buffer . \ param sizeRsp Size of response buffer .
static int cbCacheLoad(cbHnd_T      hnd,
                       cbTid_T      uTid,
                       cbPktHdr_T  *pPktHdr,
                       byte_t       bufRspMsg[],
                       size_t       sizeRsp)
{
  cbTransInfo_T  *pInfo;            
  size_t          uRspMsgLen;       
  int             rc = 0;           
  cbLock(hnd);
  pInfo = hnd->m_tblTransCache[uTid & CB_HDR_TID_MASK];
  if( (pInfo == NULL) || !pInfo->m_bCached )
  {
    rc = 0;
  }
  else
  {
    uRspMsgLen = (size_t)(pPktHdr->m_hdrMsgLen);
    if( uRspMsgLen > sizeRsp )
    {
      CB_LOG_ERROR(hnd, CB_LIB_ECODE_TOO_BIG,
        "Message length=%zu > buffer size=%zu.", uRspMsgLen, sizeRsp);
      rc = -CB_LIB_ECODE_TOO_BIG;
    }
    else
    {
      *pPktHdr = *(pInfo->m_pPktHdr);
      memcpy(bufRspMsg, pInfo->m_pBuf, uRspMsgLen);
      LOGDIAG3("Device %d: Loaded response from cache: "
               "tid=%u, msg=%s(msgid=%u).",
        hnd->m_fd, uTid, CB_MSG_NAME_ID(cbGetMsgId(bufRspMsg, uRspMsgLen)));
      rc = 1;
    }
  }
  cbUnlock(hnd);
  return rc;
}
static int cbCacheLoad ( cbHnd_T hnd , cbTid_T uTid , cbPktHdr_T * pPktHdr , byte_t bufRspMsg [ ] , size_t sizeRsp ) { cbTransInfo_T * pInfo ; size_t uRspMsgLen ; int rc = 0 ; cbLock ( hnd ) ; pInfo = hnd -> m_tblTransCache [ uTid & CB_HDR_TID_MASK ] ; if ( ( pInfo == NULL ) || ! pInfo -> m_bCached ) { rc = 0 ; } else { uRspMsgLen = ( size_t ) ( pPktHdr -> m_hdrMsgLen ) ; if ( uRspMsgLen > sizeRsp ) { CB_LOG_ERROR ( hnd , CB_LIB_ECODE_TOO_BIG , " " , uRspMsgLen , sizeRsp ) ; rc = - CB_LIB_ECODE_TOO_BIG ; } else { * pPktHdr = * ( pInfo -> m_pPktHdr ) ; memcpy ( bufRspMsg , pInfo -> m_pBuf , uRspMsgLen ) ; LOGDIAG3 ( " " " " , hnd -> m_fd , uTid , CB_MSG_NAME_ID ( cbGetMsgId ( bufRspMsg , uRspMsgLen ) ) ) ; rc = 1 ; } } cbUnlock ( hnd ) ; return rc ; }
\brief Load cached response from transaction cache.
\ brief Load cached response from transaction cache .
// cached information // response message len // return code // load from cache