Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes

df_Unpacker Class Reference
[IVD Data format.]

#include <df.h>

Collaboration diagram for df_Unpacker:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 df_Unpacker (UInt32_t a_blkType, bbt_BufType_t a_bufType, UInt32_t a_blkSize)
virtual ~df_Unpacker ()
void NewFRIBuffer (const string &a_id)
void NewDiskBuffer (const string &a_id, const string &a_diskBufferFS)
void NewNetBuffer (i_DownloadAgent_ptr a_downloadAgt)
void NewStdIOBuffer (const string &a_fName)
UInt32_t GetNextRecord ()
 Get next record in the block stream.
void ReadRecFile (UInt64_t &a_idFile, UInt64_t &a_idMig, UInt64_t &a_idParent, UInt64_t &a_idParentOld, string &a_name, string &a_nameOld, ivd_FileInfo_t &a_info, UInt32_t &a_changeFlags, UInt32_t &a_flags, UInt64_t &a_chunkSize)
void ReadRecFileEnd (UInt64_t &a_idFile, UInt64_t &a_idMig, UInt32_t &a_status, UInt32_t &a_recFlags)
void ReadRecBSStart (UInt32_t &a_type, string &a_name, UInt64_t &a_streamSize, UInt64_t &a_streamOffset)
void ReadRecBSEnd (UInt32_t &a_status)
void GetBSData (UInt8_t *&a_block, UInt32_t &a_size)

Protected Member Functions

void GetNextBlock ()

Protected Attributes

auto_ptr< df_BlockManagerm_manager
auto_ptr< df_MgrReaderm_mgrReader
df_BlockScanner m_scanner
df_DataBlockm_curBlock_p
df_RecCmn_tm_curRec_p
bool m_hasBlkHdr
UInt64_t m_idFile
string m_fileName
UInt64_t m_chunkSize
UInt64_t m_fileOffset

Private Attributes

 log_CLASSID_m

Detailed Description

Definition at line 1177 of file df.h.


Constructor & Destructor Documentation

df_Unpacker::df_Unpacker ( UInt32_t  a_blkType,
bbt_BufType_t  a_bufType,
UInt32_t  a_blkSize 
)
df_Unpacker::~df_Unpacker (  )  [virtual]

Definition at line 73 of file df_unpacker.cpp.

References dbg_LOW, log_DBG_m, log_FUNC_m, m_manager, and m_mgrReader.

                          {
    log_FUNC_m(~df_Unpacker);

/* TODO try to improve this. m_curRec_p may not point to proper location.
    // Was stream properly terminated?
    bool termError = false;
    UInt32_t type = rec_NoRec_c;
    if (   m_curRec_p == NULL
        || !df_IsValidTerminator(m_curRec_p->type) ) {

        termError = true;
        if (m_curRec_p != NULL) {
            type = m_curRec_p->type;
        }
    };
*/
    try {

        // End Of Data - we are done reading
        if (m_mgrReader.get() != NULL) {
            m_mgrReader.reset();
        };
        // Will wait for the writer to finish.
        if (m_manager.get() != NULL) {
            m_manager.reset();
        };
    }
    catch (ivd_Exception &ie) {
        log_DBG_m(dbg_LOW,
            "Ignoring exception in DTOR." << endl <<
            "Error: " << ie);
    }
/*
    if (termError) {
        log_DBG_m(dbg_NORM,
            "Data stream might not be properly terminated. " <<
            "Last record: " << string( (char*)(&type), sizeof(type) ) );
    };
*/
}


Member Function Documentation

void df_Unpacker::GetBSData ( UInt8_t *&  a_block,
UInt32_t a_size 
)

Definition at line 181 of file df_unpacker.cpp.

References df_RecEmbeddedData_t::data, df_DataBlock::GetBlockSize(), df_DataBlock::GetData(), ie_IMPOSSIBLE, log_FUNC_m, m_curBlock_p, m_curRec_p, ntoh(), NULL, ivd_VarData_t::offset, rec_EmbData_c, ivd_VarData_t::size, and df_RecCmn_t::type.

Referenced by UnpackFile(), and i_HSM_i::UnPackFile().

                                                               {
    log_FUNC_m(GetBSData);

    // check for RAW block first
    if (m_curRec_p == NULL) {
        a_block = m_curBlock_p->GetData();
        a_size  = m_curBlock_p->GetBlockSize();
    } else {
        if (m_curRec_p->type != rec_EmbData_c) {
            throw ivd_InternalError(
                ie_IMPOSSIBLE,
                "Cannot get BS data: current record type=" +
                string((char*)(&m_curRec_p->type), sizeof(m_curRec_p->type)));
        }
        const df_RecEmbeddedData_t *eData_p = df_GetSpecificRec<df_RecEmbeddedData_t>(m_curRec_p);

        a_block = (UInt8_t *)m_curRec_p + ntoh(eData_p->data.offset);
        a_size  = ntoh(eData_p->data.size);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void df_Unpacker::GetNextBlock (  )  [protected]

Definition at line 117 of file df_unpacker.cpp.

References df_DataBlock::GetData(), df_DataBlock::IsEmpty(), log_FUNC_m, log_WRN_m, m_curBlock_p, m_curRec_p, m_hasBlkHdr, m_mgrReader, m_scanner, NULL, and df_BlockScanner::SetBlock().

Referenced by GetNextRecord(), NewDiskBuffer(), NewFRIBuffer(), NewNetBuffer(), and NewStdIOBuffer().

                               {
    log_FUNC_m(GetNextBlock);

    if (m_curBlock_p != NULL) {
        m_mgrReader.get()->Release();
    }

    m_curRec_p = NULL;
    m_hasBlkHdr = false;

    m_curBlock_p = m_mgrReader.get()->GetFull();
    if (m_curBlock_p == NULL) {
        return;
    }

    if (m_curBlock_p->IsEmpty()) {
        log_WRN_m("Strange: Empty block in the middle of the input stream.");
    }
    m_hasBlkHdr = (m_scanner.SetBlock(m_curBlock_p->GetData()) != NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

UInt32_t df_Unpacker::GetNextRecord (  ) 

Get next record in the block stream.

Move to the next record in the input stream and return its type.

Returns type of the record or NULL if no more records.

Definition at line 139 of file df_unpacker.cpp.

References dbg_DETAIL, GetNextBlock(), df_BlockScanner::GetNextRecord(), log_DBG_m, log_FUNC_m, m_curBlock_p, m_curRec_p, m_hasBlkHdr, m_scanner, NULL, rec_Data_c, rec_EmbData_c, rec_NoRec_c, and df_RecCmn_t::type.

Referenced by UnpackFile(), and i_HSM_i::UnPackFile().

                                    {
    log_FUNC_m(GetNextRecord);

retry:
    // nothing more to read
    if (m_curBlock_p == NULL) {
        log_DBG_m(dbg_DETAIL, "No block - end of stream");
        return rec_NoRec_c;
    }

    if (!m_hasBlkHdr) {
        m_hasBlkHdr = true; // done with this one - expect blk hdr in next one
        m_curRec_p = NULL;
        log_DBG_m(dbg_DETAIL, "No block header - raw block");
        return rec_Data_c;
    }

    m_curRec_p = m_scanner.GetNextRecord();

    // nothing more in current block -> get next block
    if (m_curRec_p == NULL) {
        GetNextBlock();
        if (m_curBlock_p == NULL) {
            return rec_NoRec_c;
        }
        goto retry;
    }

    log_DBG_m(dbg_DETAIL,
              "Record=" <<
              string((char*)&m_curRec_p->type, sizeof(m_curRec_p->type)) );

    if (m_curRec_p->type == rec_EmbData_c) {
        return rec_Data_c;
    }

    return m_curRec_p->type;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void df_Unpacker::NewDiskBuffer ( const string &  a_id,
const string &  a_diskBufferFS 
)

Definition at line 394 of file df_unpacker.cpp.

References GetNextBlock(), log_FUNC_A_m, m_manager, and cmn_Thread::Start().

Referenced by i_HSM_i::Recall().

                                                                                {
    log_FUNC_A_m(NewDiskBuffer, "file: " << a_diskBufferFS << a_id );

    blk_DiskBufferReader *db_p =
        new blk_DiskBufferReader(*m_manager.get(), a_diskBufferFS, a_id);
    db_p->Start();

    GetNextBlock();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void df_Unpacker::NewFRIBuffer ( const string &  a_id  ) 

Definition at line 384 of file df_unpacker.cpp.

References GetNextBlock(), log_FUNC_A_m, m_manager, and cmn_Thread::Start().

                                                 {
    log_FUNC_A_m(NewFRIBuffer, "id: " << a_id);

    blk_DiskFRIReader *fri_p =
        new blk_DiskFRIReader(*m_manager.get(), a_id);
    fri_p->Start();

    GetNextBlock();
}

Here is the call graph for this function:

void df_Unpacker::NewNetBuffer ( i_DownloadAgent_ptr  a_downloadAgt  ) 

Definition at line 404 of file df_unpacker.cpp.

References GetNextBlock(), log_FUNC_A_m, m_manager, and cmn_Thread::Start().

Referenced by i_HSM_i::Recall().

                                                                {
    log_FUNC_A_m(NewNetBuffer, "dloadAgt: " << a_downloadAgt);

    blk_NetReader *nr_p =
        new blk_NetReader(*m_manager.get(), a_downloadAgt);
    nr_p->Start();

    GetNextBlock();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void df_Unpacker::NewStdIOBuffer ( const string &  a_fName  ) 

Definition at line 414 of file df_unpacker.cpp.

References GetNextBlock(), log_FUNC_m, m_manager, and cmn_Thread::Start().

Referenced by Restore().

                                                      {
    log_FUNC_m(NewStdIOBuffer);

    blk_StdIOReader *db_p =
        new blk_StdIOReader(*m_manager.get(), a_fName);
    db_p->Start();

    GetNextBlock();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void df_Unpacker::ReadRecBSEnd ( UInt32_t a_status  ) 

Definition at line 357 of file df_unpacker.cpp.

References ie_IMPOSSIBLE, log_FUNC_m, m_curRec_p, ntoh(), rec_BSEnd_c, df_RecByteStreamEnd_t::status, and df_RecCmn_t::type.

Referenced by UnpackFile(), and i_HSM_i::UnPackFile().

                                   {

    log_FUNC_m(ReadRecBSEnd);

    if (!m_curRec_p) {
        throw ivd_InternalError(
            ie_IMPOSSIBLE,
            "Cannot read BSEnd record: current record is NULL");
    }

    if (m_curRec_p->type != rec_BSEnd_c) {
        throw ivd_InternalError(
            ie_IMPOSSIBLE,
            "Cannot read BSEnd record: current record of type=" +
            string((char*)(&m_curRec_p->type), sizeof(m_curRec_p->type)));
    }

    df_RecByteStreamEnd_t *bse_p
        = df_GetSpecificRec<df_RecByteStreamEnd_t>(m_curRec_p);

    a_status        = ntoh(bse_p->status);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void df_Unpacker::ReadRecBSStart ( UInt32_t a_type,
string &  a_name,
UInt64_t a_streamSize,
UInt64_t a_streamOffset 
)

Definition at line 316 of file df_unpacker.cpp.

References df_RecCmn_t::GetVarDataNet(), ie_IMPOSSIBLE, log_FUNC_m, m_curRec_p, ntoh(), ivd_VarData_t::offset, rec_BSStart_c, df_RecByteStreamStart_t::streamName, df_RecByteStreamStart_t::streamOffset, df_RecByteStreamStart_t::streamSize, df_RecByteStreamStart_t::streamType, and df_RecCmn_t::type.

Referenced by UnpackFile(), and i_HSM_i::UnPackFile().

                                         {

    log_FUNC_m(ReadRecBSStart);

    if (!m_curRec_p) {
        throw ivd_InternalError(
            ie_IMPOSSIBLE,
            "Cannot read BSStart record: current record is NULL");
    }

    if (m_curRec_p->type != rec_BSStart_c) {
        throw ivd_InternalError(
            ie_IMPOSSIBLE,
            "Cannot read BSStart record: current record of type=" +
            string((char*)(&m_curRec_p->type), sizeof(m_curRec_p->type)));
    }

    df_RecByteStreamStart_t *bss_p
        = df_GetSpecificRec<df_RecByteStreamStart_t>(m_curRec_p);

    a_type          = ntoh(bss_p->streamType);
    a_streamSize    = ntoh(bss_p->streamSize);
//    a_fileOffset    = ntoh(bss_p->chunkOffset);
    a_streamOffset    = ntoh(bss_p->streamOffset);

    if (ntoh(bss_p->streamName.offset) > 0) {
        string name(m_curRec_p->GetVarDataNet(bss_p->streamName));
        a_name.swap(name);
    }
    else {
        a_name = string("");
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void df_Unpacker::ReadRecFile ( UInt64_t a_idFile,
UInt64_t a_idMig,
UInt64_t a_idParent,
UInt64_t a_idParentOld,
string &  a_name,
string &  a_nameOld,
ivd_FileInfo_t &  a_info,
UInt32_t a_changeFlags,
UInt32_t a_flags,
UInt64_t a_chunkSize 
)

Definition at line 205 of file df_unpacker.cpp.

References df_StandardAttr_t::attr, df_StandardAttr_t::changeFlags, df_RecFile_t::chunkSize, cmn_SlashToBackSlash(), dbg_DETAIL, df_StandardAttr_t::flags, df_RecCmn_t::GetVarDataNet(), df_StandardAttr_t::group, df_RecFile_t::idFile, df_RecFile_t::idMig, df_StandardAttr_t::idOnFS, df_RecFile_t::idParent, df_RecFile_t::idParentOld, ie_IMPOSSIBLE, log_DBG_m, log_FUNC_m, m_curRec_p, df_RecFile_t::name, df_RecFile_t::nameOld, ntoh(), df_StandardAttr_t::numLinks, ivd_VarData_t::offset, df_StandardAttr_t::owner, PATH_SEPARATOR, rec_FileHdr_c, df_StandardAttr_t::size, df_RecFile_t::stdAttr, df_StandardAttr_t::timeAccess, df_StandardAttr_t::timeChange, df_StandardAttr_t::timeCreate, df_StandardAttr_t::timeModify, df_StandardAttr_t::type, and df_RecCmn_t::type.

Referenced by UnpackFile(), and i_HSM_i::UnPackFile().

                                      {

    log_FUNC_m(ReadRecFile);

    if (!m_curRec_p) {
        throw ivd_InternalError(
            ie_IMPOSSIBLE,
            "Cannot read File record: current record is NULL");
    }

    if (m_curRec_p->type != rec_FileHdr_c) {
        throw ivd_InternalError(
            ie_IMPOSSIBLE,
            "Cannot read File record: current record of type=" +
            string((char*)(&m_curRec_p->type), sizeof(m_curRec_p->type)));
    }

    df_RecFile_t *file_p = df_GetSpecificRec<df_RecFile_t>(m_curRec_p);

    a_idFile        = ntoh(file_p->idFile);
    a_idParent      = ntoh(file_p->idParent);
    a_idParentOld   = ntoh(file_p->idParentOld);

    a_idMig         = ntoh(file_p->idMig);

    a_flags         = ntoh(file_p->stdAttr.flags);
    a_changeFlags   = ntoh(file_p->stdAttr.changeFlags);
    a_chunkSize     = ntoh(file_p->chunkSize);

    a_info.numLinks    = ntoh(file_p->stdAttr.numLinks);
    a_info.idOnFS      = ntoh(file_p->stdAttr.idOnFS);
    a_info.type        = static_cast<ivd_FileType_e> (ntoh(file_p->stdAttr.type));
    a_info.size        = static_cast<ivd_FileSize_t> (ntoh(file_p->stdAttr.size));
    a_info.attr        = ntoh(file_p->stdAttr.attr);

    a_info.owner       = ntoh(file_p->stdAttr.owner);
    a_info.group       = ntoh(file_p->stdAttr.group);

    a_info.timeCreate  = ntoh(file_p->stdAttr.timeCreate);
    a_info.timeAccess  = ntoh(file_p->stdAttr.timeAccess);
    a_info.timeModify  = ntoh(file_p->stdAttr.timeModify);
    a_info.timeChange  = ntoh(file_p->stdAttr.timeChange);

    string name(m_curRec_p->GetVarDataNet(file_p->name));
    if (PATH_SEPARATOR == '\\') { // this OS use separator for DF
        cmn_SlashToBackSlash(name);
    }
    a_name.swap(name);

    if (ntoh(file_p->nameOld.offset) > 0) {
        string nameOld(m_curRec_p->GetVarDataNet(file_p->nameOld));
        if (PATH_SEPARATOR == '\\') { // this OS use separator for DF
            cmn_SlashToBackSlash(nameOld);
        }
        a_nameOld.swap(nameOld);
    }
    else {
        a_nameOld.clear();
    }

    log_DBG_m(dbg_DETAIL, "ID: " << a_idFile << " name: " << a_name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void df_Unpacker::ReadRecFileEnd ( UInt64_t a_idFile,
UInt64_t a_idMig,
UInt32_t a_status,
UInt32_t a_recFlags 
)

Definition at line 284 of file df_unpacker.cpp.

References df_RecCmn_t::flags, df_RecFileEnd_t::idFile, df_RecFileEnd_t::idMig, ie_IMPOSSIBLE, log_FUNC_m, m_curRec_p, ntoh(), rec_FileEnd_c, df_RecFileEnd_t::status, and df_RecCmn_t::type.

Referenced by UnpackFile(), and i_HSM_i::UnPackFile().

                                     {

    log_FUNC_m(ReadRecFileEnd);

    if (!m_curRec_p) {
        throw ivd_InternalError(
            ie_IMPOSSIBLE,
            "Cannot read FileEnd record: current record is NULL");
    }

    if (m_curRec_p->type != rec_FileEnd_c) {
        throw ivd_InternalError(
            ie_IMPOSSIBLE,
            "Cannot read FileEnd record: current record of type=" +
            string((char*)(&m_curRec_p->type), sizeof(m_curRec_p->type)));
    }
    a_recFlags      = ntoh(m_curRec_p->flags);

    df_RecFileEnd_t *fEnd_p =  df_GetSpecificRec<df_RecFileEnd_t>(m_curRec_p);

    a_idFile        = ntoh(fEnd_p->idFile);
    a_idMig         = ntoh(fEnd_p->idMig);

    a_status        = ntoh(fEnd_p->status);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1268 of file df.h.

Definition at line 1262 of file df.h.

Definition at line 1254 of file df.h.

Referenced by GetBSData(), GetNextBlock(), and GetNextRecord().

string df_Unpacker::m_fileName [protected]

Definition at line 1261 of file df.h.

Definition at line 1263 of file df.h.

bool df_Unpacker::m_hasBlkHdr [protected]

Definition at line 1258 of file df.h.

Referenced by GetNextBlock(), and GetNextRecord().

Definition at line 1260 of file df.h.

auto_ptr<df_BlockManager> df_Unpacker::m_manager [protected]
auto_ptr<df_MgrReader> df_Unpacker::m_mgrReader [protected]

Definition at line 1250 of file df.h.

Referenced by df_Unpacker(), GetNextBlock(), and ~df_Unpacker().

Definition at line 1252 of file df.h.

Referenced by GetNextBlock(), and GetNextRecord().


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