Example #1
0
/**********************************************************************************
Function Name   :   nAdvanceReadIndex(int& nIndex)
Output          :   CALL_SUCCESS for success. CALL_FAILURE for failure.
                    if allocated memory by the caller is not enough.
Functionality   :   Helper function. Advances the nIndex to the next entry
Member of       :   CMsgBufVVSE
Friend of       :   -
Authors         :   Pradeep Kadoor
Date Created    :   22/06/2009
Modifications   :   -
************************************************************************************/
int CMsgBufVVSE::nAdvanceReadIndex(int& nReadIndex)
{
    int nResult = CALL_SUCCESS;
    static BYTE abyHeader[HEADER_LEN] = {0};
    nGetCurrMsgHeader(nReadIndex, abyHeader); // Get current msg header TYPE, MSG LENGTH

    int nMsgLen = 0;
    memcpy(&nMsgLen, abyHeader + MSGLEN_OFFSET, DATA_LEN_SIZE);
    if ((nReadIndex + HEADER_LEN + nMsgLen) < m_nBufferSize)
    {
        nReadIndex += (HEADER_LEN + nMsgLen);
    }
    else
    {
        nReadIndex = (nReadIndex + HEADER_LEN + nMsgLen) - m_nBufferSize;
    }
    return nResult;
}
Example #2
0
/**********************************************************************************
Function Name   :   ReadBuffer()
Input(s)        :   TYPE, SIZE, pointer to the byte where header will be stored.
Output          :   CALL_SUCCESS for success. ERR_READ_MEMORY_SHORT
                    if allocated memory by the caller is not enough.
Functionality   :   Helper function. Current msg pointed by read index
                    is read.
Member of       :   CMsgBufVSE
Friend of       :   -
Authors         :   Pradeep Kadoor
Date Created    :   22/06/2009
Modifications   :   -
************************************************************************************/
HRESULT CMsgBufVSE::ReadBuffer(INT& nType, BYTE* pbyMsg, INT& nSize)
{
    HRESULT Return = CALL_SUCCESS;
    BYTE abyHeader[HEADER_LEN];
    Return = nGetCurrMsgHeader(abyHeader);
    // It is expected to return CALL_SUCCESS
    ASSERT(Return == CALL_SUCCESS);
    DATA_LEN MsgLen = 0;
    TYPE Type;
    memcpy(&Type, (abyHeader + TYPE_OFFSET), TYPE_SIZE);
    nType = (INT) Type;
    memcpy(&MsgLen, (abyHeader + MSGLEN_OFFSET), DATA_LEN_SIZE);

    if ((int) MsgLen > nSize)
    {
        Return = ERR_READ_MEMORY_SHORT;
        nSize   = MsgLen - nSize;
    }
    else
    {
        if ((m_nIndexRead + HEADER_LEN + MsgLen) <= m_nBufferSize)
        {
            memcpy(pbyMsg, (m_pbyMsgBuffer + m_nIndexRead + HEADER_LEN), MsgLen);
            m_nIndexRead += (HEADER_LEN + MsgLen);
        }
        else if ((m_nIndexRead + HEADER_LEN) <= m_nBufferSize)
        {
            memcpy(pbyMsg, (m_pbyMsgBuffer + m_nIndexRead + HEADER_LEN), (m_nBufferSize - m_nIndexRead - HEADER_LEN));
            memcpy((pbyMsg + (m_nBufferSize - m_nIndexRead - HEADER_LEN)), m_pbyMsgBuffer, (MsgLen - (m_nBufferSize - m_nIndexRead - HEADER_LEN)));
            m_nIndexRead = MsgLen - (m_nBufferSize - m_nIndexRead - HEADER_LEN);
        }
        else
        {
            memcpy(pbyMsg, (m_pbyMsgBuffer + (m_nIndexRead + HEADER_LEN - m_nBufferSize)), MsgLen);
            m_nIndexRead = (m_nIndexRead + HEADER_LEN - m_nBufferSize) +  MsgLen;
        }

        nSize = MsgLen;
    }

    return Return;
}
Example #3
0
/**********************************************************************************
Function Name   :   nAdvanceReadIndex()
Output          :   CALL_SUCCESS for success. CALL_FAILURE for failure.
                    if allocated memory by the caller is not enough.
Functionality   :   Helper function. Current msg is skipped.
Member of       :   CMsgBufVSE
Friend of       :   -
Authors         :   Pradeep Kadoor
Date Created    :   22/06/2009
Modifications   :   -
************************************************************************************/
int CMsgBufVSE::nAdvanceReadIndex(void)
{
    int nResult = CALL_SUCCESS;
    static BYTE abyHeader[HEADER_LEN] = {0};
    nGetCurrMsgHeader(abyHeader); // Get current msg header TYPE, MSG LENGTH

    int nMsgLen = 0;
    memcpy(&nMsgLen, abyHeader + MSGLEN_OFFSET, DATA_LEN_SIZE);
    if ((m_nIndexRead + HEADER_LEN + nMsgLen) < m_nBufferSize)
    {
        m_nIndexRead += (HEADER_LEN + nMsgLen);
    }
    else
    {
        m_nIndexRead = (m_nIndexRead + HEADER_LEN + nMsgLen) - m_nBufferSize;
    }    
    m_nMsgSkipped++;
    m_nMsgCount--;        
    return nResult;
}
Example #4
0
/**********************************************************************************
Function Name   :   ReadBuffer()
Input(s)        :   TYPE, SIZE, pointer to the byte where MSG will be stored.
Output          :   CALL_SUCCESS for success. ERR_READ_MEMORY_SHORT
                    if allocated memory by the caller is not enough.
Functionality   :   Helper function. Current msg pointed by nIndex
                    is read.
Member of       :   CMsgBufVVSE
Friend of       :   -
Authors         :   Pradeep Kadoor
Date Created    :   22/06/2009
Modifications   :   -
************************************************************************************/
HRESULT CMsgBufVVSE::ReadBuffer(INT& nType, BYTE* pbyMsg, INT& nSize, INT& nIndex)
{
    HRESULT Return = CALL_SUCCESS;
    BYTE abyHeader[HEADER_LEN];
    Return = nGetCurrMsgHeader(nIndex, abyHeader);
    // It is expected to return CALL_SUCCESS
    ASSERT(Return == CALL_SUCCESS);
    int nMsgLen = 0;
    memcpy(&nType, (abyHeader + TYPE_OFFSET), TYPE_SIZE);
    memcpy(&nMsgLen, (abyHeader + MSGLEN_OFFSET), DATA_LEN_SIZE);
    if (nMsgLen > nSize)
    {
        Return = ERR_READ_MEMORY_SHORT;
        nSize   = nMsgLen - nSize;
    }
    else
    {
        if ((nIndex + HEADER_LEN + nMsgLen) <= m_nBufferSize)
        {
            memcpy(pbyMsg, (m_pbyMsgBuffer + nIndex + HEADER_LEN), nMsgLen);
            nIndex += (HEADER_LEN + nMsgLen);
        }
        else if ((nIndex + HEADER_LEN) <= m_nBufferSize)
        {
            memcpy(pbyMsg, (m_pbyMsgBuffer + nIndex + HEADER_LEN), (m_nBufferSize - nIndex - HEADER_LEN));
            memcpy((pbyMsg + (m_nBufferSize - nIndex - HEADER_LEN)), m_pbyMsgBuffer, (nMsgLen - (m_nBufferSize - nIndex - HEADER_LEN)));
            nIndex = nMsgLen - (m_nBufferSize - nIndex - HEADER_LEN);
        }
        else
        {
            memcpy(pbyMsg, (m_pbyMsgBuffer + (nIndex + HEADER_LEN - m_nBufferSize)), nMsgLen);
            nIndex = (nIndex + HEADER_LEN - m_nBufferSize) +  nMsgLen;
        }
        nSize = nMsgLen;
    }
    return Return;
}