df_Unpacker Class Reference
[IVD Data format.]

#include <df.h>

Collaboration diagram for df_Unpacker:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 1163 of file df.h.


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

Constructor & Destructor Documentation

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

Definition at line 34 of file df_unpacker.cpp.

References bbt_DISK_BUF, bbt_DISK_FRI, bbt_DISK_FRI_RECOVERY, bbt_REMOTE_BUF, bbt_SHMEM_BUF, bbt_TAPE_READ, df_BlockManager, df_DISKBUF_BLOCKS_c, df_DISKFRI_BLOCKS_c, df_MEMBUF_BLOCKS_c, df_REMOTEBUF_BLOCKS_c, df_TAPEBUF_c, log_FUNC_m, m_manager, and m_mgrReader.

00038     : m_scanner(a_blkType, a_blkSize),
00039       m_curBlock_p(NULL),
00040       m_curRec_p(NULL) {
00041 
00042     log_FUNC_m(df_Unpacker);
00043 
00044     UInt32_t count(4);
00045 
00046     switch (a_bufType) {
00047         case bbt_DISK_BUF:          count = df_DISKBUF_BLOCKS_c; break;
00048         case bbt_SHMEM_BUF:         count = df_MEMBUF_BLOCKS_c; break;
00049         case bbt_REMOTE_BUF:        count = df_REMOTEBUF_BLOCKS_c; break;
00050         case bbt_DISK_FRI:          count = df_DISKFRI_BLOCKS_c; break;
00051         case bbt_DISK_FRI_RECOVERY: count = df_DISKFRI_BLOCKS_c; break;
00052         case bbt_TAPE_READ:         count = df_TAPEBUF_c; break;
00053     };
00054 
00055     m_manager.reset( new df_BlockManager(a_blkSize, count) );
00056     m_mgrReader.reset( new df_MgrReader(*m_manager.get() ) );
00057 }

df_Unpacker::~df_Unpacker (  )  [virtual]

Definition at line 59 of file df_unpacker.cpp.

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

00059                           {
00060     log_FUNC_m(~df_Unpacker);
00061 
00062 /* TODO try to improve this. m_curRec_p may not point to proper location.
00063     // Was stream properly terminated?
00064     bool termError = false;
00065     UInt32_t type = rec_NoRec_c;
00066     if (   m_curRec_p == NULL
00067         || !df_IsValidTerminator(m_curRec_p->type) ) {
00068 
00069         termError = true;
00070         if (m_curRec_p != NULL) {
00071             type = m_curRec_p->type;
00072         }
00073     };
00074 */
00075     try {
00076 
00077         // End Of Data - we are done reading
00078         if (m_mgrReader.get() != NULL) {
00079             m_mgrReader.reset();
00080         };
00081         // Will wait for the writer to finish.
00082         if (m_manager.get() != NULL) {
00083             m_manager.reset();
00084         };
00085     }
00086     catch (ivd_Exception &ie) {
00087         log_DBG_m(dbg_LOW,
00088             "Ignoring exception in DTOR." << endl <<
00089             "Error: " << ie);
00090     }
00091 /*
00092     if (termError) {
00093         log_DBG_m(dbg_NORM,
00094             "Data stream might not be properly terminated. " <<
00095             "Last record: " << string( (char*)(&type), sizeof(type) ) );
00096     };
00097 */
00098 }


Member Function Documentation

void df_Unpacker::NewFRIBuffer ( const string &  a_id  ) 

Definition at line 370 of file df_unpacker.cpp.

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

00370                                                  {
00371     log_FUNC_A_m(NewFRIBuffer, "id: " << a_id);
00372 
00373     blk_DiskFRIReader *fri_p =
00374         new blk_DiskFRIReader(*m_manager.get(), a_id);
00375     fri_p->Start();
00376 
00377     GetNextBlock();
00378 }

Here is the call graph for this function:

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

Definition at line 380 of file df_unpacker.cpp.

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

Referenced by i_HSM_i::Recall().

00380                                                                                 {
00381     log_FUNC_A_m(NewDiskBuffer, "file: " << a_diskBufferFS << a_id );
00382 
00383     blk_DiskBufferReader *db_p =
00384         new blk_DiskBufferReader(*m_manager.get(), a_diskBufferFS, a_id);
00385     db_p->Start();
00386 
00387     GetNextBlock();
00388 }

Here is the call graph for this function:

Here is the caller graph for this function:

void df_Unpacker::NewNetBuffer ( i_DownloadAgent_ptr  a_downloadAgt  ) 

Definition at line 390 of file df_unpacker.cpp.

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

Referenced by i_HSM_i::Recall().

00390                                                                 {
00391     log_FUNC_A_m(NewNetBuffer, "dloadAgt: " << a_downloadAgt);
00392 
00393     blk_NetReader *nr_p =
00394         new blk_NetReader(*m_manager.get(), a_downloadAgt);
00395     nr_p->Start();
00396 
00397     GetNextBlock();
00398 }

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 400 of file df_unpacker.cpp.

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

Referenced by Restore().

00400                                                       {
00401     log_FUNC_m(NewStdIOBuffer);
00402 
00403     blk_StdIOReader *db_p =
00404         new blk_StdIOReader(*m_manager.get(), a_fName);
00405     db_p->Start();
00406 
00407     GetNextBlock();
00408 }

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

00125                                     {
00126     log_FUNC_m(GetNextRecord);
00127 
00128 retry:
00129     // nothing more to read
00130     if (m_curBlock_p == NULL) {
00131         log_DBG_m(dbg_DETAIL, "No block - end of stream");
00132         return rec_NoRec_c;
00133     }
00134 
00135     if (!m_hasBlkHdr) {
00136         m_hasBlkHdr = true; // done with this one - expect blk hdr in next one
00137         m_curRec_p = NULL;
00138         log_DBG_m(dbg_DETAIL, "No block header - raw block");
00139         return rec_Data_c;
00140     }
00141 
00142     m_curRec_p = m_scanner.GetNextRecord();
00143 
00144     // nothing more in current block -> get next block
00145     if (m_curRec_p == NULL) {
00146         GetNextBlock();
00147         if (m_curBlock_p == NULL) {
00148             return rec_NoRec_c;
00149         }
00150         goto retry;
00151     }
00152 
00153     log_DBG_m(dbg_DETAIL,
00154               "Record=" <<
00155               string((char*)&m_curRec_p->type, sizeof(m_curRec_p->type)) );
00156 
00157     if (m_curRec_p->type == rec_EmbData_c) {
00158         return rec_Data_c;
00159     }
00160 
00161     return m_curRec_p->type;
00162 }

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

00201                                       {
00202 
00203     log_FUNC_m(ReadRecFile);
00204 
00205     if (!m_curRec_p) {
00206         throw ivd_InternalError(
00207             ie_IMPOSSIBLE,
00208             "Cannot read File record: current record is NULL");
00209     }
00210 
00211     if (m_curRec_p->type != rec_FileHdr_c) {
00212         throw ivd_InternalError(
00213             ie_IMPOSSIBLE,
00214             "Cannot read File record: current record of type=" +
00215             string((char*)(&m_curRec_p->type), sizeof(m_curRec_p->type)));
00216     }
00217 
00218     df_RecFile_t *file_p = df_GetSpecificRec<df_RecFile_t>(m_curRec_p);
00219 
00220     a_idFile        = ntoh(file_p->idFile);
00221     a_idParent      = ntoh(file_p->idParent);
00222     a_idParentOld   = ntoh(file_p->idParentOld);
00223 
00224     a_idMig         = ntoh(file_p->idMig);
00225 
00226     a_flags         = ntoh(file_p->stdAttr.flags);
00227     a_changeFlags   = ntoh(file_p->stdAttr.changeFlags);
00228     a_chunkSize     = ntoh(file_p->chunkSize);
00229 
00234     a_info.numLinks    = ntoh(file_p->stdAttr.numLinks);
00235     a_info.idOnFS      = ntoh(file_p->stdAttr.idOnFS);
00236     a_info.type        = static_cast<ivd_FileType_e> (ntoh(file_p->stdAttr.type));
00237     a_info.size        = static_cast<ivd_FileSize_t> (ntoh(file_p->stdAttr.size));
00238     a_info.attr        = ntoh(file_p->stdAttr.attr);
00239 
00240     a_info.owner       = ntoh(file_p->stdAttr.owner);
00241     a_info.group       = ntoh(file_p->stdAttr.group);
00242 
00243     a_info.timeCreate  = ntoh(file_p->stdAttr.timeCreate);
00244     a_info.timeAccess  = ntoh(file_p->stdAttr.timeAccess);
00245     a_info.timeModify  = ntoh(file_p->stdAttr.timeModify);
00246     a_info.timeChange  = ntoh(file_p->stdAttr.timeChange);
00247 
00248     string name(m_curRec_p->GetVarDataNet(file_p->name));
00249     if (PATH_SEPARATOR == '\\') { // this OS use separator for DF
00250         cmn_SlashToBackSlash(name);
00251     }
00252     a_name.swap(name);
00253 
00254     if (ntoh(file_p->nameOld.offset) > 0) {
00255         string nameOld(m_curRec_p->GetVarDataNet(file_p->nameOld));
00256         if (PATH_SEPARATOR == '\\') { // this OS use separator for DF
00257             cmn_SlashToBackSlash(nameOld);
00258         }
00259         a_nameOld.swap(nameOld);
00260     }
00261     else {
00262         a_nameOld.clear();
00263     }
00264 
00265     log_DBG_m(dbg_DETAIL, "ID: " << a_idFile << " name: " << a_name);
00266 }

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

00274                                      {
00275 
00276     log_FUNC_m(ReadRecFileEnd);
00277 
00278     if (!m_curRec_p) {
00279         throw ivd_InternalError(
00280             ie_IMPOSSIBLE,
00281             "Cannot read FileEnd record: current record is NULL");
00282     }
00283 
00284     if (m_curRec_p->type != rec_FileEnd_c) {
00285         throw ivd_InternalError(
00286             ie_IMPOSSIBLE,
00287             "Cannot read FileEnd record: current record of type=" +
00288             string((char*)(&m_curRec_p->type), sizeof(m_curRec_p->type)));
00289     }
00290     a_recFlags      = ntoh(m_curRec_p->flags);
00291 
00292     df_RecFileEnd_t *fEnd_p =  df_GetSpecificRec<df_RecFileEnd_t>(m_curRec_p);
00293 
00294     a_idFile        = ntoh(fEnd_p->idFile);
00295     a_idMig         = ntoh(fEnd_p->idMig);
00296 
00297     a_status        = ntoh(fEnd_p->status);
00298 }

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

00306                                          {
00307 
00308     log_FUNC_m(ReadRecBSStart);
00309 
00310     if (!m_curRec_p) {
00311         throw ivd_InternalError(
00312             ie_IMPOSSIBLE,
00313             "Cannot read BSStart record: current record is NULL");
00314     }
00315 
00316     if (m_curRec_p->type != rec_BSStart_c) {
00317         throw ivd_InternalError(
00318             ie_IMPOSSIBLE,
00319             "Cannot read BSStart record: current record of type=" +
00320             string((char*)(&m_curRec_p->type), sizeof(m_curRec_p->type)));
00321     }
00322 
00323     df_RecByteStreamStart_t *bss_p
00324         = df_GetSpecificRec<df_RecByteStreamStart_t>(m_curRec_p);
00325 
00326     a_type          = ntoh(bss_p->streamType);
00327     a_streamSize    = ntoh(bss_p->streamSize);
00328 //    a_fileOffset    = ntoh(bss_p->chunkOffset);
00329     a_streamOffset    = ntoh(bss_p->streamOffset);
00330 
00331     if (ntoh(bss_p->streamName.offset) > 0) {
00332         string name(m_curRec_p->GetVarDataNet(bss_p->streamName));
00333         a_name.swap(name);
00334     }
00335     else {
00336         a_name = string("");
00337     }
00338 }

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

00344                                    {
00345 
00346     log_FUNC_m(ReadRecBSEnd);
00347 
00348     if (!m_curRec_p) {
00349         throw ivd_InternalError(
00350             ie_IMPOSSIBLE,
00351             "Cannot read BSEnd record: current record is NULL");
00352     }
00353 
00354     if (m_curRec_p->type != rec_BSEnd_c) {
00355         throw ivd_InternalError(
00356             ie_IMPOSSIBLE,
00357             "Cannot read BSEnd record: current record of type=" +
00358             string((char*)(&m_curRec_p->type), sizeof(m_curRec_p->type)));
00359     }
00360 
00361     df_RecByteStreamEnd_t *bse_p
00362         = df_GetSpecificRec<df_RecByteStreamEnd_t>(m_curRec_p);
00363 
00364     a_status        = ntoh(bse_p->status);
00365 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

00167                                                                {
00168     log_FUNC_m(GetBSData);
00169 
00170     // check for RAW block first
00171     if (m_curRec_p == NULL) {
00172         a_block = m_curBlock_p->GetData();
00173         a_size  = m_curBlock_p->GetBlockSize();
00174     } else {
00175         if (m_curRec_p->type != rec_EmbData_c) {
00176             throw ivd_InternalError(
00177                 ie_IMPOSSIBLE,
00178                 "Cannot get BS data: current record type=" +
00179                 string((char*)(&m_curRec_p->type), sizeof(m_curRec_p->type)));
00180         }
00181         const df_RecEmbeddedData_t *eData_p = df_GetSpecificRec<df_RecEmbeddedData_t>(m_curRec_p);
00182 
00183         a_block = (UInt8_t *)m_curRec_p + ntoh(eData_p->data.offset);
00184         a_size  = ntoh(eData_p->data.size);
00185     }
00186 }

Here is the call graph for this function:

Here is the caller graph for this function:

void df_Unpacker::GetNextBlock (  )  [protected]

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

00103                                {
00104     log_FUNC_m(GetNextBlock);
00105 
00106     if (m_curBlock_p != NULL) {
00107         m_mgrReader.get()->Release();
00108     }
00109 
00110     m_curRec_p = NULL;
00111     m_hasBlkHdr = false;
00112 
00113     m_curBlock_p = m_mgrReader.get()->GetFull();
00114     if (m_curBlock_p == NULL) {
00115         return;
00116     }
00117 
00118     if (m_curBlock_p->IsEmpty()) {
00119         log_WRN_m("Strange: Empty block in the middle of the input stream.");
00120     }
00121     m_hasBlkHdr = (m_scanner.SetBlock(m_curBlock_p->GetData()) != NULL);
00122 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

auto_ptr<df_BlockManager> df_Unpacker::m_manager [protected]

auto_ptr<df_MgrReader> df_Unpacker::m_mgrReader [protected]

Definition at line 1236 of file df.h.

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

Definition at line 1238 of file df.h.

Referenced by GetNextBlock(), and GetNextRecord().

Definition at line 1240 of file df.h.

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

bool df_Unpacker::m_hasBlkHdr [protected]

Definition at line 1244 of file df.h.

Referenced by GetNextBlock(), and GetNextRecord().

Definition at line 1246 of file df.h.

string df_Unpacker::m_fileName [protected]

Definition at line 1247 of file df.h.

Definition at line 1248 of file df.h.

Definition at line 1249 of file df.h.

Definition at line 1254 of file df.h.


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

Generated on Mon Feb 27 19:13:54 2012 for OPENARCHIVE by  doxygen 1.5.6