Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes | Friends

df_BlockProxy Class Reference
[IVD Data format.]

new unpacker class structure More...

#include <df.h>

Inheritance diagram for df_BlockProxy:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 df_BlockProxy (UInt32_t a_blkType, bbt_BufType_t a_bufType, UInt32_t a_blkSize)
virtual ~df_BlockProxy ()
void SetPtrToDataBlock (const UInt8_t *a_dataBlock_p, UInt32_t a_curBlockID, bool a_rawBlock=false)
 Sets the pointer to data block which will be parsed.
virtual void Reset ()
 Reset internal state to be able to skip blocks (reorg recall).
bool IsBlockHeaderPresent () const
void ParseBlockHeader ()
 Reads block header, verifies it and sets internal set.
virtual void GetNextBlock ()
 get next block and check its header
virtual void GetRawNextBlock ()
 just get next block
bool IsEndOfBlock (UInt32_t a_blockPos)
bool IsBlkType (UInt32_t a_blkType)
UInt32_t GetCurBlockUsed () const
const UInt8_tGetData () const
UInt32_t GetBlkType () const
UInt32_t GetBlkSize () const
UInt32_t GetBlockID () const
UInt32_t GetBlockNum () const
void SetFindMode (bool a_mode)
bool GetFindMode () const
UInt32_t GetLastKnownGoodBlockID () const
 get the number of raw blocks after

Static Public Member Functions

static const df_BlockHeader_tVerifiedBlock (const UInt8_t *a_block_p, UInt32_t a_blockSize, UInt32_t &a_blockNum, UInt32_t a_blockType, UInt32_t a_lastGoodBlock)
 Static helper function to verify block header.
static bool VerifyBlockHeader (const UInt8_t *a_block_p, UInt32_t a_blockSize, UInt32_t a_blockNum, UInt32_t a_blockType, UInt32_t a_blockFlags)

Protected Attributes

const UInt8_tm_curBlock_p
 pointer to current block
UInt32_t m_curBlockUsed
const UInt32_t m_blkType
const UInt32_t m_blkSize
UInt32_t m_blkNum
 Current block number (ID inside the data format).

Private Attributes

 log_CLASSID_m
 Macro to add class name member s_className.
UInt32_t m_curBlockID
UInt32_t m_lastKnownGoodBlockID
 The ID (medium position) of the last known good block.
bool m_findMode

Friends

ostream & operator<< (ostream &a_os, const df_BlockProxy &o)

Detailed Description

new unpacker class structure

dataFormatClassStructure.png

Class takes care about one block set by usee class. It is base class for any block reader class

See also:
df_BlockReader
Author:
Dejan Volk Lupo, HERMES SoftLab
See also:
<reference>

Definition at line 1289 of file df.h.


Constructor & Destructor Documentation

df_BlockProxy::df_BlockProxy ( UInt32_t  a_blkType,
bbt_BufType_t  a_bufType,
UInt32_t  a_blkSize 
)

Definition at line 58 of file df_blockproxy.cpp.

References dbg_DETAIL, log_DBG_m, log_FUNC_m, m_blkSize, and m_blkType.

Referenced by ~df_BlockProxy().

    :
    m_curBlock_p(NULL),
    m_curBlockUsed(0),
    m_blkType(a_blkType),
    m_blkSize(a_blkSize),
    m_blkNum(0),
    m_curBlockID(0),
    m_lastKnownGoodBlockID(0),
    m_findMode(false) {
    
    log_FUNC_m(df_BlockProxy);
    log_DBG_m(dbg_DETAIL, 
             "m_blkType = " << m_blkType
         <<  " a_bufType = " << a_bufType
         <<  " m_blkSize = " << m_blkSize);
}

Here is the caller graph for this function:

df_BlockProxy::~df_BlockProxy (  )  [virtual]

Definition at line 79 of file df_blockproxy.cpp.

References df_BlockProxy(), and log_FUNC_m.

Here is the call graph for this function:


Member Function Documentation

UInt32_t df_BlockProxy::GetBlkSize (  )  const [inline]

Definition at line 1365 of file df.h.

Referenced by df_FileBlockReader::GetNextBlock(), and df_FileBlockReader::GetRawNextBlock().

{ return m_blkSize;    };

Here is the caller graph for this function:

UInt32_t df_BlockProxy::GetBlkType (  )  const [inline]

Definition at line 1364 of file df.h.

{ return m_blkType;    };

UInt32_t df_BlockProxy::GetBlockID (  )  const [inline]

Definition at line 1366 of file df.h.

{ return m_curBlockID; };

UInt32_t df_BlockProxy::GetBlockNum (  )  const [inline]

Definition at line 1367 of file df.h.

{ return m_blkNum; };

UInt32_t df_BlockProxy::GetCurBlockUsed (  )  const [inline]

Definition at line 1362 of file df.h.

{ return m_curBlockUsed; };

const UInt8_t* df_BlockProxy::GetData (  )  const [inline]

Definition at line 1363 of file df.h.

{ return m_curBlock_p; };

bool df_BlockProxy::GetFindMode (  )  const [inline]

Definition at line 1370 of file df.h.

{ return m_findMode; };

UInt32_t df_BlockProxy::GetLastKnownGoodBlockID (  )  const [inline]

get the number of raw blocks after

Definition at line 1373 of file df.h.

void df_BlockProxy::GetNextBlock (  )  [virtual]

get next block and check its header

Reimplemented in df_BlockReader, and df_FileBlockReader.

Definition at line 311 of file df_blockproxy.cpp.

References log_FUNC_m, and m_curBlock_p.

                                 {
    log_FUNC_m(GetNextBlock);

    // set as no more blocks
    m_curBlock_p = NULL;
}

void df_BlockProxy::GetRawNextBlock (  )  [virtual]

just get next block

Reimplemented in df_BlockReader, and df_FileBlockReader.

Definition at line 319 of file df_blockproxy.cpp.

References log_FUNC_m, m_blkNum, and m_curBlock_p.

                                    {
    log_FUNC_m(GetRawNextBlock);
    
    m_blkNum++;
    
    // set as no more blocks
    m_curBlock_p = NULL;
}

bool df_BlockProxy::IsBlkType ( UInt32_t  a_blkType  )  [inline]

Definition at line 1360 of file df.h.

{ return a_blkType == m_blkType; };

bool df_BlockProxy::IsBlockHeaderPresent (  )  const

Definition at line 209 of file df_blockproxy.cpp.

References df_BlockHeader_t::blkCookie, IsBlockCookie(), m_blkSize, m_blkType, m_curBlock_p, ntoh(), df_BlockHeader_t::reserved1, df_BlockHeader_t::type, and df_BlockHeader_t::used.

Referenced by SetPtrToDataBlock().

                                               {
    
    const df_BlockHeader_t *blkHdr_p = 
        reinterpret_cast<const df_BlockHeader_t*>(m_curBlock_p);
 
    // Check all static data
    if (   IsBlockCookie(blkHdr_p->blkCookie)
        && m_blkType == blkHdr_p->type
        && ntoh(blkHdr_p->used) <= m_blkSize
        && blkHdr_p->reserved1[0] == 0
        && blkHdr_p->reserved1[1] == 0 ) {
        
        return true;
    }
    else {
        return false;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool df_BlockProxy::IsEndOfBlock ( UInt32_t  a_blockPos  )  [inline]

Definition at line 1359 of file df.h.

{ return a_blockPos >= m_curBlockUsed; };

void df_BlockProxy::ParseBlockHeader (  ) 

Reads block header, verifies it and sets internal set.

Definition at line 231 of file df_blockproxy.cpp.

References evt_ERROR, ivd_BaseException::GetFriendly(), log_FUNC_m, log_WriteEvent(), m_blkNum, m_blkSize, m_blkType, m_curBlock_p, m_curBlockID, m_curBlockUsed, m_lastKnownGoodBlockID, ntoh(), df_BlockHeader_t::used, and VerifiedBlock().

Referenced by SetPtrToDataBlock().

                                     {
    try{
        const df_BlockHeader_t *blkHdr_p = VerifiedBlock(
            m_curBlock_p,
            m_blkSize,
            m_blkNum,
            m_blkType,
            m_lastKnownGoodBlockID);

        m_curBlockUsed = ntoh(blkHdr_p->used);
        
        // reset block ID. good block. Used only with blocks
        // that have block header.
        m_lastKnownGoodBlockID = m_curBlockID;
    }
    catch (const ivd_DFError& de) {
        log_FUNC_m(ParseBlockHeader);
        // log_WRN_m(
        ostringstream sstr;
        sstr << "Data format in FRI header record: " << de.GetFriendly()
             << "Check the block size values please.";
        log_WriteEvent(evt_ERROR, sstr.str());
        throw de;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void df_BlockProxy::Reset (  )  [virtual]

Reset internal state to be able to skip blocks (reorg recall).

Definition at line 84 of file df_blockproxy.cpp.

References log_FUNC_m, m_blkNum, and m_curBlockUsed.

void df_BlockProxy::SetFindMode ( bool  a_mode  ) 

Definition at line 94 of file df_blockproxy.cpp.

References log_FUNC_m, and m_findMode.

                                           {
    log_FUNC_m(SetFindMode);
    //
    // When in find mode, block proxy attempts to position to the next
    // block with magic cookie (IsBlockHeaderPresent()).
    // It does not throw data format exceptions.
    //
    // When such a block is found, the find mode is automatically reset.
    //
    m_findMode = a_mode;
}

void df_BlockProxy::SetPtrToDataBlock ( const UInt8_t a_dataBlock_p,
UInt32_t  a_curBlockID,
bool  a_rawBlock = false 
)

Sets the pointer to data block which will be parsed.

Definition at line 282 of file df_blockproxy.cpp.

References dbg_NORM, IsBlockHeaderPresent(), log_DBG_m, log_FUNC_m, m_blkSize, m_curBlock_p, m_curBlockID, m_curBlockUsed, m_findMode, and ParseBlockHeader().

Referenced by df_FileBlockReader::GetNextBlock(), df_BlockReader::GetNextBlock(), and df_BlockReader::GetRawNextBlock().

                                {
    
    m_curBlock_p = a_dataBlock_p;
    m_curBlockID = a_curBlockID;

    if (m_findMode) {
        if (IsBlockHeaderPresent()) {
            log_FUNC_m(SetPtrToDataBlock);
            log_DBG_m(dbg_NORM, "Found block header on position: " << m_curBlockID);
            m_findMode = false;
        }
        else {
            m_curBlockUsed = 0;
            return;
        }
    }
    
    if (!a_rawBlock) {
        ParseBlockHeader();
    }
    else {
        m_curBlockUsed = m_blkSize;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

const df_BlockHeader_t * df_BlockProxy::VerifiedBlock ( const UInt8_t a_block_p,
UInt32_t  a_blockSize,
UInt32_t a_blockNum,
UInt32_t  a_blockType,
UInt32_t  a_lastGoodBlock 
) [static]

Static helper function to verify block header.

Definition at line 108 of file df_blockproxy.cpp.

References df_BlockHeader_t::blkCookie, cmn_Num2Str(), dbg_DETAIL, df_BF_CONTINUED, df_BlockHeader_t::flags, ie_DF_INV_BLK, ie_DF_INVBLKCOOKIE, ie_DF_INVBLKSEQNUM, IsBlockCookie(), log_DBG_m, log_FUNC_m, ntoh(), df_BlockHeader_t::seqNum, df_BlockHeader_t::type, and df_BlockHeader_t::used.

Referenced by ParseBlockHeader(), and bea_FRI::ReadFRIStart().

                              {

    log_FUNC_m(VerifiedBlock);
    log_DBG_m(dbg_DETAIL, 
             "a_blockSize = " << a_blockSize
         <<  " a_blockType = " << a_blockType
         <<  " a_lastGood = " << a_lastGood);

    const df_BlockHeader_t *blkHdr_p = 
        reinterpret_cast<const df_BlockHeader_t*>(a_block_p);
 
    if (!IsBlockCookie(blkHdr_p->blkCookie)) {
        throw ivd_DFError(
            ie_DF_INVBLKCOOKIE, 
            a_lastGood,
            "Got: " +
            string(
                (const char*)blkHdr_p->blkCookie, 
                sizeof(blkHdr_p->blkCookie)) );
    }

    if ( /*  m_blkType != blk_AnyBlk_c 
        && */ a_blockType != blkHdr_p->type ) {
        throw ivd_DFError(
            ie_DF_INV_BLK,
            a_lastGood,
            "Invalid block type \"" + 
            string(
                reinterpret_cast<const char*>(&blkHdr_p->type),
                sizeof(blkHdr_p->type)) +
            "\" - expected \"" + 
            string(
                reinterpret_cast<const char*>(&a_blockType),
                sizeof(a_blockType)) + "\"");
    }

    // Check that current block number matches
    UInt32_t curBlkNum      = ntoh(blkHdr_p->seqNum); 
    UInt32_t curBlkFlags    = ntoh(blkHdr_p->flags); 

    // if this is first block we got - set blkNum appropriately
    if (a_blockNum == 0) {
        a_blockNum = curBlkNum;
    }     // if this is first block from new stream - restart counting
    else if (curBlkNum == 1) { // reset counter
        a_blockNum = 1;
    }
    else if ( (curBlkFlags & df_BF_CONTINUED) != 0) {
        // split found in the middle of the volume.
        // Reset block number to that number.
        a_blockNum = curBlkNum;
    }
    else {
        a_blockNum++;
        if (curBlkNum != a_blockNum) {
            throw ivd_DFError(
                ie_DF_INVBLKSEQNUM, 
                a_lastGood,
                "Got=" + cmn_Num2Str(curBlkNum) + 
                ", expected=" + cmn_Num2Str(a_blockNum));
        }
    }

    UInt32_t curBlockUsed = ntoh(blkHdr_p->used);
    
    // if first record position is above block used size -> very strange! 
    if (curBlockUsed > a_blockSize) {
        throw ivd_DFError(
            ie_DF_INV_BLK,
            a_lastGood,
            "Block Used=" + cmn_Num2Str(curBlockUsed) +
            " larger than specified Block Size=" + 
            cmn_Num2Str(a_blockSize));
    } 
    
    // if first record position is above block used size -> very strange!
    if (sizeof(df_BlockHeader_t) > curBlockUsed) {
        throw ivd_DFError(
            ie_DF_INV_BLK, 
            a_lastGood,
            "Block Used=" + cmn_Num2Str(curBlockUsed) +
            ", First Rec=" + 
            cmn_Num2Str(sizeof(df_BlockHeader_t)));
    }

    log_DBG_m(dbg_DETAIL, 
        "HSM block: blkNum=" << a_blockNum <<
        " flags=" << cmn_Num2Str(ntoh(blkHdr_p->flags), true));


    return blkHdr_p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool df_BlockProxy::VerifyBlockHeader ( const UInt8_t a_block_p,
UInt32_t  a_blockSize,
UInt32_t  a_blockNum,
UInt32_t  a_blockType,
UInt32_t  a_blockFlags 
) [static]

Definition at line 259 of file df_blockproxy.cpp.

References df_BlockHeader_t::blkCookie, df_BlockHeader_t::flags, IsBlockCookie(), log_FUNC_m, ntoh(), df_BlockHeader_t::reserved1, df_BlockHeader_t::seqNum, df_BlockHeader_t::type, and df_BlockHeader_t::used.

Referenced by ParseBlock().

                                {

    log_FUNC_m(VerifyBlockHeader);

    const df_BlockHeader_t *blkHdr_p = 
        reinterpret_cast<const df_BlockHeader_t*>(a_block_p);

    return  (    IsBlockCookie(blkHdr_p->blkCookie)
            &&  (blkHdr_p->type         == a_blockType)
            &&  (ntoh(blkHdr_p->used)   <= a_blockSize)
            &&  (ntoh(blkHdr_p->seqNum) == a_blockNum)
            &&  (ntoh(blkHdr_p->flags)  == a_blockFlags)
            &&  (blkHdr_p->reserved1[0] == 0)
            &&  (blkHdr_p->reserved1[1] == 0)
            );
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

ostream& operator<< ( ostream &  a_os,
const df_BlockProxy o 
) [friend]

Definition at line 329 of file df_blockproxy.cpp.

                                                            {
    a_os << "==== Dump of df_BlockProxy object =====" << endl
        << "m_curBlock_p : 0x" << hex << (const void*)(o.m_curBlock_p) << dec << endl
        << "m_curBlockUsed : " << o.m_curBlockUsed << endl
        << "m_blkType : " << o.m_blkType << endl
        << "m_blkSize : " << o.m_blkSize << endl
        << "m_blkNum : " << o.m_blkNum << endl
        << "m_curBlockID : " << o.m_curBlockID << endl
        << "m_lastKnownGoodBlockID : " << o.m_lastKnownGoodBlockID << endl
        << "m_findMode : " << boolalpha << o.m_findMode << endl;
    return a_os;
}


Member Data Documentation

Macro to add class name member s_className.

Reimplemented in df_BlockReader, and df_FileBlockReader.

Definition at line 1312 of file df.h.

Current block number (ID inside the data format).

It's reset to 1 for every migration.

Definition at line 1308 of file df.h.

Referenced by df_BlockReader::GetRawNextBlock(), GetRawNextBlock(), operator<<(), ParseBlockHeader(), and Reset().

Definition at line 1302 of file df.h.

Referenced by df_BlockProxy(), IsBlockHeaderPresent(), operator<<(), and ParseBlockHeader().

Definition at line 1314 of file df.h.

Referenced by operator<<(), ParseBlockHeader(), and SetPtrToDataBlock().

Definition at line 1301 of file df.h.

Referenced by operator<<(), ParseBlockHeader(), Reset(), and SetPtrToDataBlock().

bool df_BlockProxy::m_findMode [private]

Definition at line 1320 of file df.h.

Referenced by operator<<(), SetFindMode(), and SetPtrToDataBlock().

The ID (medium position) of the last known good block.

Used to be able to re-position if data format parsing fails.

Definition at line 1319 of file df.h.

Referenced by operator<<(), and ParseBlockHeader().


The documentation for this class was generated from the following files: