df_BlockProxy Class Reference
[IVD Data format.]

#include <df.h>

Inheritance diagram for df_BlockProxy:

Inheritance graph
[legend]

List of all members.


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 1275 of file df.h.


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)

Constructor & Destructor Documentation

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

Definition at line 44 of file df_blockproxy.cpp.

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

Referenced by ~df_BlockProxy().

00047     :
00048     m_curBlock_p(NULL),
00049     m_curBlockUsed(0),
00050     m_blkType(a_blkType),
00051     m_blkSize(a_blkSize),
00052     m_blkNum(0),
00053     m_curBlockID(0),
00054     m_lastKnownGoodBlockID(0),
00055     m_findMode(false) {
00056     
00057     log_FUNC_m(df_BlockProxy);
00058     log_DBG_m(dbg_DETAIL, 
00059              "m_blkType = " << m_blkType
00060          <<  " a_bufType = " << a_bufType
00061          <<  " m_blkSize = " << m_blkSize);
00062 }
//============================================================================//

Here is the caller graph for this function:

df_BlockProxy::~df_BlockProxy (  )  [virtual]

Definition at line 65 of file df_blockproxy.cpp.

References df_BlockProxy(), and log_FUNC_m.

00065                               {
00066     log_FUNC_m(~df_BlockProxy());
00067 }

Here is the call graph for this function:


Member Function Documentation

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 268 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().

00271                                 {
00272     
00273     m_curBlock_p = a_dataBlock_p;
00274     m_curBlockID = a_curBlockID;
00275 
00276     if (m_findMode) {
00277         if (IsBlockHeaderPresent()) {
00278             log_FUNC_m(SetPtrToDataBlock);
00279             log_DBG_m(dbg_NORM, "Found block header on position: " << m_curBlockID);
00280             m_findMode = false;
00281         }
00282         else {
00283             m_curBlockUsed = 0;
00284             return;
00285         }
00286     }
00287     
00288     if (!a_rawBlock) {
00289         ParseBlockHeader();
00290     }
00291     else {
00292         m_curBlockUsed = m_blkSize;
00293     }
00294 }

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 70 of file df_blockproxy.cpp.

References log_FUNC_m, m_blkNum, and m_curBlockUsed.

00070                           {
00071     log_FUNC_m(Reset);
00072     
00073     m_curBlockUsed = 0;
00074     m_blkNum = 0;
00075 }

bool df_BlockProxy::IsBlockHeaderPresent (  )  const

Definition at line 195 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().

00195                                                {
00196     
00197     const df_BlockHeader_t *blkHdr_p = 
00198         reinterpret_cast<const df_BlockHeader_t*>(m_curBlock_p);
00199  
00200     // Check all static data
00201     if (   IsBlockCookie(blkHdr_p->blkCookie)
00202         && m_blkType == blkHdr_p->type
00203         && ntoh(blkHdr_p->used) <= m_blkSize
00204         && blkHdr_p->reserved1[0] == 0
00205         && blkHdr_p->reserved1[1] == 0 ) {
00206         
00207         return true;
00208     }
00209     else {
00210         return false;
00211     }
00212 }

Here is the call graph for this function:

Here is the caller graph for this function:

void df_BlockProxy::ParseBlockHeader (  ) 

Reads block header, verifies it and sets internal set.

Definition at line 217 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().

00217                                      {
00218     try{
00219         const df_BlockHeader_t *blkHdr_p = VerifiedBlock(
00220             m_curBlock_p,
00221             m_blkSize,
00222             m_blkNum,
00223             m_blkType,
00224             m_lastKnownGoodBlockID);
00225 
00226         m_curBlockUsed = ntoh(blkHdr_p->used);
00227         
00228         // reset block ID. good block. Used only with blocks
00229         // that have block header.
00230         m_lastKnownGoodBlockID = m_curBlockID;
00231     }
00232     catch (const ivd_DFError& de) {
00233         log_FUNC_m(ParseBlockHeader);
00234         // log_WRN_m(
00235         ostringstream sstr;
00236         sstr << "Data format in FRI header record: " << de.GetFriendly()
00237              << "Check the block size values please.";
00238         log_WriteEvent(evt_ERROR, sstr.str());
00239         throw de;
00240     }
00241 }

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 94 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().

00099                               {
00100 
00101     log_FUNC_m(VerifiedBlock);
00102     log_DBG_m(dbg_DETAIL, 
00103              "a_blockSize = " << a_blockSize
00104          <<  " a_blockType = " << a_blockType
00105          <<  " a_lastGood = " << a_lastGood);
00106 
00107     const df_BlockHeader_t *blkHdr_p = 
00108         reinterpret_cast<const df_BlockHeader_t*>(a_block_p);
00109  
00110     if (!IsBlockCookie(blkHdr_p->blkCookie)) {
00111         throw ivd_DFError(
00112             ie_DF_INVBLKCOOKIE, 
00113             a_lastGood,
00114             "Got: " +
00115             string(
00116                 (const char*)blkHdr_p->blkCookie, 
00117                 sizeof(blkHdr_p->blkCookie)) );
00118     }
00119 
00120     if ( /*  m_blkType != blk_AnyBlk_c 
00121         && */ a_blockType != blkHdr_p->type ) {
00122         throw ivd_DFError(
00123             ie_DF_INV_BLK,
00124             a_lastGood,
00125             "Invalid block type \"" + 
00126             string(
00127                 reinterpret_cast<const char*>(&blkHdr_p->type),
00128                 sizeof(blkHdr_p->type)) +
00129             "\" - expected \"" + 
00130             string(
00131                 reinterpret_cast<const char*>(&a_blockType),
00132                 sizeof(a_blockType)) + "\"");
00133     }
00134 
00135     // Check that current block number matches
00136     UInt32_t curBlkNum      = ntoh(blkHdr_p->seqNum); 
00137     UInt32_t curBlkFlags    = ntoh(blkHdr_p->flags); 
00138 
00139     // if this is first block we got - set blkNum appropriately
00140     if (a_blockNum == 0) {
00141         a_blockNum = curBlkNum;
00142     }     // if this is first block from new stream - restart counting
00143     else if (curBlkNum == 1) { // reset counter
00144         a_blockNum = 1;
00145     }
00146     else if ( (curBlkFlags & df_BF_CONTINUED) != 0) {
00147         // split found in the middle of the volume.
00148         // Reset block number to that number.
00149         a_blockNum = curBlkNum;
00150     }
00151     else {
00152         a_blockNum++;
00153         if (curBlkNum != a_blockNum) {
00154             throw ivd_DFError(
00155                 ie_DF_INVBLKSEQNUM, 
00156                 a_lastGood,
00157                 "Got=" + cmn_Num2Str(curBlkNum) + 
00158                 ", expected=" + cmn_Num2Str(a_blockNum));
00159         }
00160     }
00161 
00162     UInt32_t curBlockUsed = ntoh(blkHdr_p->used);
00163     
00164     // if first record position is above block used size -> very strange! 
00165     if (curBlockUsed > a_blockSize) {
00166         throw ivd_DFError(
00167             ie_DF_INV_BLK,
00168             a_lastGood,
00169             "Block Used=" + cmn_Num2Str(curBlockUsed) +
00170             " larger than specified Block Size=" + 
00171             cmn_Num2Str(a_blockSize));
00172     } 
00173     
00174     // if first record position is above block used size -> very strange!
00175     if (sizeof(df_BlockHeader_t) > curBlockUsed) {
00176         throw ivd_DFError(
00177             ie_DF_INV_BLK, 
00178             a_lastGood,
00179             "Block Used=" + cmn_Num2Str(curBlockUsed) +
00180             ", First Rec=" + 
00181             cmn_Num2Str(sizeof(df_BlockHeader_t)));
00182     }
00183 
00184     log_DBG_m(dbg_DETAIL, 
00185         "HSM block: blkNum=" << a_blockNum <<
00186         " flags=" << cmn_Num2Str(ntoh(blkHdr_p->flags), true));
00187 
00188 
00189     return blkHdr_p;
00190 }

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 245 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().

00250                                 {
00251 
00252     log_FUNC_m(VerifyBlockHeader);
00253 
00254     const df_BlockHeader_t *blkHdr_p = 
00255         reinterpret_cast<const df_BlockHeader_t*>(a_block_p);
00256 
00257     return  (    IsBlockCookie(blkHdr_p->blkCookie)
00258             &&  (blkHdr_p->type         == a_blockType)
00259             &&  (ntoh(blkHdr_p->used)   <= a_blockSize)
00260             &&  (ntoh(blkHdr_p->seqNum) == a_blockNum)
00261             &&  (ntoh(blkHdr_p->flags)  == a_blockFlags)
00262             &&  (blkHdr_p->reserved1[0] == 0)
00263             &&  (blkHdr_p->reserved1[1] == 0)
00264             );
00265 }

Here is the call graph for this function:

Here is the caller graph for this function:

void df_BlockProxy::GetNextBlock (  )  [virtual]

get next block and check its header

Reimplemented in df_BlockReader, and df_FileBlockReader.

Definition at line 297 of file df_blockproxy.cpp.

References log_FUNC_m, m_curBlock_p, and NULL.

00297                                  {
00298     log_FUNC_m(GetNextBlock);
00299 
00300     // set as no more blocks
00301     m_curBlock_p = NULL;
00302 }

void df_BlockProxy::GetRawNextBlock (  )  [virtual]

just get next block

Reimplemented in df_BlockReader, and df_FileBlockReader.

Definition at line 305 of file df_blockproxy.cpp.

References log_FUNC_m, m_blkNum, m_curBlock_p, and NULL.

00305                                     {
00306     log_FUNC_m(GetRawNextBlock);
00307     
00308     m_blkNum++;
00309     
00310     // set as no more blocks
00311     m_curBlock_p = NULL;
00312 }

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

Definition at line 1345 of file df.h.

01345 { return a_blockPos >= m_curBlockUsed; };

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

Definition at line 1346 of file df.h.

01346 { return a_blkType == m_blkType; };

UInt32_t df_BlockProxy::GetCurBlockUsed (  )  const [inline]

Definition at line 1348 of file df.h.

01348 { return m_curBlockUsed; };

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

Definition at line 1349 of file df.h.

01349 { return m_curBlock_p; };

UInt32_t df_BlockProxy::GetBlkType (  )  const [inline]

Definition at line 1350 of file df.h.

01350 { return m_blkType;    };

UInt32_t df_BlockProxy::GetBlkSize (  )  const [inline]

Definition at line 1351 of file df.h.

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

01351 { return m_blkSize;    };

Here is the caller graph for this function:

UInt32_t df_BlockProxy::GetBlockID (  )  const [inline]

Definition at line 1352 of file df.h.

01352 { return m_curBlockID; };

UInt32_t df_BlockProxy::GetBlockNum (  )  const [inline]

Definition at line 1353 of file df.h.

01353 { return m_blkNum; };

void df_BlockProxy::SetFindMode ( bool  a_mode  ) 

Definition at line 80 of file df_blockproxy.cpp.

References log_FUNC_m, and m_findMode.

00080                                            {
00081     log_FUNC_m(SetFindMode);
00082     //
00083     // When in find mode, block proxy attempts to position to the next
00084     // block with magic cookie (IsBlockHeaderPresent()).
00085     // It does not throw data format exceptions.
00086     //
00087     // When such a block is found, the find mode is automatically reset.
00088     //
00089     m_findMode = a_mode;
00090 }

bool df_BlockProxy::GetFindMode (  )  const [inline]

Definition at line 1356 of file df.h.

01356 { return m_findMode; };

UInt32_t df_BlockProxy::GetLastKnownGoodBlockID (  )  const [inline]

get the number of raw blocks after

Definition at line 1359 of file df.h.

01359 { return m_lastKnownGoodBlockID;};


Friends And Related Function Documentation

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

Definition at line 315 of file df_blockproxy.cpp.

00315                                                             {
00316     a_os << "==== Dump of df_BlockProxy object =====" << endl
00317         << "m_curBlock_p : 0x" << hex << (const void*)(o.m_curBlock_p) << dec << endl
00318         << "m_curBlockUsed : " << o.m_curBlockUsed << endl
00319         << "m_blkType : " << o.m_blkType << endl
00320         << "m_blkSize : " << o.m_blkSize << endl
00321         << "m_blkNum : " << o.m_blkNum << endl
00322         << "m_curBlockID : " << o.m_curBlockID << endl
00323         << "m_lastKnownGoodBlockID : " << o.m_lastKnownGoodBlockID << endl
00324         << "m_findMode : " << boolalpha << o.m_findMode << endl;
00325     return a_os;
00326 }


Member Data Documentation

Definition at line 1287 of file df.h.

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

Definition at line 1288 of file df.h.

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

Current block number (ID inside the data format).

It's reset to 1 for every migration.

Definition at line 1294 of file df.h.

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

Macro to add class name member s_className.

Reimplemented in df_BlockReader, and df_FileBlockReader.

Definition at line 1298 of file df.h.

Definition at line 1300 of file df.h.

Referenced by operator<<(), ParseBlockHeader(), 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 1305 of file df.h.

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

bool df_BlockProxy::m_findMode [private]

Definition at line 1306 of file df.h.

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


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

Generated on Mon Feb 27 19:11:32 2012 for OPENARCHIVE by  doxygen 1.5.6