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

hsm_RecallInfoGrp Class Reference
[G_new_group]

#include <hsm_RecallInfoGrp.h>

Collaboration diagram for hsm_RecallInfoGrp:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 hsm_RecallInfoGrp (const ivd_FS_File &a_file, ivd_FileSize_t a_fileSize)
 ~hsm_RecallInfoGrp (void)
void OpenF (cmn_Path &a_filePath)
void SeekF (UInt64_t a_pmJobId, ivd_FilePosition_t a_offset)
ivd_FileRetSize_t WriteF (const void *a_buf, ivd_FileBufSize_t a_size)
ivd_FileRetSize_t WriteBufferedF (const void *a_buf, ivd_FileBufSize_t a_size)
void Close ()
bool IsFileRecalled ()
void SetJobIndices (Int32_t a_jobIdx, Int32_t a_jobElemIdx)
void SetRecallFailed ()
bool IsRecallFailed ()
ivd_FileSize_t GetStreamSize ()
void DumpChunks (ostream &a_os)

Public Attributes

Int32_t m_jobIdx
Int32_t m_jobElemIdx
ivd_FS_File m_fsFile

Private Member Functions

void RememberChunkOffset (UInt64_t a_pmJobId, ivd_FilePosition_t a_offset)

Private Attributes

 log_CLASSID_m
ivd_FilePosition_t m_streamOffset
ivd_FileSize_t m_streamSize
char * m_streamBuffer_p
size_t m_streamBLevel
hsm_Chunk_t_v m_chunks
hsm_Chunk_tm_currentChunk_p
bool m_recallFailed

Detailed Description

Definition at line 68 of file hsm_RecallInfoGrp.h.


Constructor & Destructor Documentation

hsm_RecallInfoGrp::hsm_RecallInfoGrp ( const ivd_FS_File a_file,
ivd_FileSize_t  a_fileSize 
)

Definition at line 49 of file hsm_RecallInfoGrp.cpp.

References m_chunks, and m_streamBuffer_p.

    : 
    m_jobIdx(0),
    m_jobElemIdx(0),
    m_fsFile(a_file),
    m_streamOffset(0),
    m_streamSize(0),
    m_streamBuffer_p(NULL),
    m_streamBLevel(0),
    m_currentChunk_p(NULL),
    m_recallFailed(false)
{
    m_streamBuffer_p = new char[RecallBufferSize_d];

    // reserve vector space. One for file size as whole offset
    // and one for one chunk file.
    m_chunks.reserve(2); 
    // last chunk is a sentinel that hold filesize as offset
    m_chunks.push_back(hsm_Chunk_t(0, a_fileSize, 0)); // reserve some place
}

hsm_RecallInfoGrp::~hsm_RecallInfoGrp ( void   ) 

Definition at line 72 of file hsm_RecallInfoGrp.cpp.

References log_FUNC_m, and m_streamBuffer_p.


Member Function Documentation

void hsm_RecallInfoGrp::Close ( void   ) 

Definition at line 191 of file hsm_RecallInfoGrp.cpp.

References dbg_DETAIL, dbg_NORM, log_DBG_m, log_FUNC_m, m_currentChunk_p, m_recallFailed, m_streamBLevel, m_streamBuffer_p, m_streamSize, hsm_Chunk_t::offset, hsm_Chunk_t::size, and WriteF().

Referenced by hsm_Recall::ProcRecBSEnd(), and hsm_Recall::ProcRecFileEnd().

                              {
    log_FUNC_m(Close);
    // Largest data written to some offset count.
    // It could happened that DF strem has no data because it is split 
    // soon after BSS.
    if (!m_recallFailed && (m_streamBLevel > 0)){
        ivd_FileRetSize_t
            ret = WriteF(m_streamBuffer_p, m_streamBLevel);
        log_DBG_m(dbg_NORM, "Written on close " << ret << " m_streamBLevel: " << m_streamBLevel 
                    << " data was written for chunk at offset: " << m_currentChunk_p->offset);
        if(ret != m_streamBLevel){
            m_recallFailed = true;
        }
    }
    m_streamBLevel = 0;

    if (m_currentChunk_p->size < m_streamSize) {
        m_currentChunk_p->size = m_streamSize;
    }
    log_DBG_m(dbg_DETAIL, "m_streamSize: " << m_streamSize 
                    << " data was written for chunk at offset: " << m_currentChunk_p->offset);
// Close a file when object is destructed
// because of virus checkers 
//    m_fsFile.Close();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_RecallInfoGrp::DumpChunks ( ostream &  a_os  ) 

Definition at line 259 of file hsm_RecallInfoGrp.cpp.

References log_FUNC_m, m_chunks, hsm_Chunk_t::offset, hsm_Chunk_t::pmJobId, and hsm_Chunk_t::size.

Referenced by IsFileRecalled(), and hsm_FileHeader::Recalled().

                                                {
    log_FUNC_m(DumpChunks);
    
    if (m_chunks.size() < 2) {
        a_os << "Non chunk is written.";
        return;
    }
    hsm_Chunk_t *pi = &m_chunks[0];
    hsm_Chunk_t *pe = &m_chunks[m_chunks.size() - 2]; // the last present file size
    for (; pi < pe; ++pi) {
        a_os << "( " << pi->pmJobId 
             << ", " << pi->offset
             << ", " << pi->size
             << " ), ";
    }
    a_os << "( " << pe->pmJobId 
         << ", " << pe->offset
         << ", " << pe->size
         << " ).";
}

Here is the caller graph for this function:

ivd_FileSize_t hsm_RecallInfoGrp::GetStreamSize (  )  [inline]

Definition at line 89 of file hsm_RecallInfoGrp.h.

References m_streamSize.

Referenced by hsm_Recall::ProcRecEmbData(), and hsm_Recall::ProcRecRawData().

{ return m_streamSize; };

Here is the caller graph for this function:

bool hsm_RecallInfoGrp::IsFileRecalled (  ) 

Definition at line 218 of file hsm_RecallInfoGrp.cpp.

References dbg_DETAIL, DumpChunks(), log_DBG_m, log_FUNC_m, log_NOTE_m, m_chunks, hsm_Chunk_t::offset, and hsm_Chunk_t::size.

Referenced by hsm_Recall::FileRecalledCheck().

                                       {
    log_FUNC_m(IsFileRecalled);
    hsm_Chunk_t *pi = &m_chunks[0];
    hsm_Chunk_t *pe = &m_chunks[m_chunks.size()];
    // offsets of all chunks are checked
    // first offset must be 0
    // last offset is set to file size by constructor
    ivd_FilePosition_t recalledUpTo = 0;
    for (; pi != pe; ++pi) {
        log_DBG_m(dbg_DETAIL, "Recalled up to: " << recalledUpTo
                           << ", chunk offset: " << pi->offset
                           << ", size: " << pi->size
                           );
        if (pi->offset > recalledUpTo) { // exist a gap in file
            return false;
        }
        ivd_FilePosition_t newPos = pi->offset + pi->size;
        if (recalledUpTo < newPos) {
            recalledUpTo = newPos;
        }
    }
    --pi; // element that store file size
    if (recalledUpTo > pi->offset) {
        ostringstream sstr;
        sstr << "Recalled more than file size. recalled up to: " << recalledUpTo
             << ", ";
        DumpChunks(sstr);
        log_NOTE_m(sstr.str());
        log_DBG_m(dbg_DETAIL,sstr.str());
    }
    log_DBG_m(dbg_DETAIL, "File is completely recalled.");
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool hsm_RecallInfoGrp::IsRecallFailed (  )  [inline]

Definition at line 87 of file hsm_RecallInfoGrp.h.

References m_recallFailed.

Referenced by hsm_Recall::FileRecalledCheck(), hsm_Recall::ProcRecEmbData(), and hsm_Recall::ProcRecRawData().

{ return m_recallFailed; };

Here is the caller graph for this function:

void hsm_RecallInfoGrp::OpenF ( cmn_Path a_filePath  ) 

Definition at line 78 of file hsm_RecallInfoGrp.cpp.

References ivd_FS_File::e_Recall, ivd_FS_File::IsOpen(), log_FUNC_m, m_fsFile, and ivd_FS_File::Open().

Referenced by hsm_Recall::ProcRecBSStart().

                                                  {
    log_FUNC_m(OpenF);
    // open when at first chunk and close it when object is destructed.
    if (!m_fsFile.IsOpen()) {
        m_fsFile.Open(ivd_FS_File::e_Recall, a_filePath);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_RecallInfoGrp::RememberChunkOffset ( UInt64_t  a_pmJobId,
ivd_FilePosition_t  a_offset 
) [private]

Definition at line 281 of file hsm_RecallInfoGrp.cpp.

References dbg_DETAIL, ie_FATAL_ERROR, log_DBG_m, log_FUNC_m, m_chunks, m_currentChunk_p, hsm_Chunk_t::offset, and hsm_Chunk_t::size.

Referenced by SeekF().

                                                                                          {
    log_FUNC_m(RememberChunkOffset);
    log_DBG_m(dbg_DETAIL, "Insert new chunk offset: " << a_offset);
    hsm_Chunk_t_v_i iter = m_chunks.begin();
    for (; iter != m_chunks.end(); ++iter) {
        log_DBG_m(dbg_DETAIL, "offset: " << (*iter).offset
                           << ", size: " << (*iter).size
                           << ", PM jobID: " << (*iter).pmJobId);
        if ((*iter).offset > a_offset) { // insert 
            // Size will be set by Close method that use m_streamSize member            
            // address of current added vector element
            m_currentChunk_p = &(*m_chunks.insert(iter, hsm_Chunk_t(a_pmJobId, a_offset, 0)));
            return;
        }
        else if ((*iter).offset < a_offset) {
            continue;
        }
        else {
            log_DBG_m(dbg_DETAIL, "Chunk alredy exist.");
            m_currentChunk_p = &(*iter); // already exist ??! 
            return;
        }
    }
    ostringstream sstr;
    sstr << "Seek offset cannot be greater that file size!."
         << " a_offset: " << a_offset
         << endl
         << "Chunks:" << endl
         << "      offset        size" << endl
         << "========================" << endl;

    hsm_Chunk_t *pi = &m_chunks[0];
    hsm_Chunk_t *pe = &m_chunks[m_chunks.size()];
    for (; pi != pe; ++pi) {
        sstr << setw(12) << pi->offset << setw(12) << pi->size << endl;    
    }
    throw ivd_InternalError(ie_FATAL_ERROR, sstr.str(), true);            
}

Here is the caller graph for this function:

void hsm_RecallInfoGrp::SeekF ( UInt64_t  a_pmJobId,
ivd_FilePosition_t  a_offset 
)

Definition at line 87 of file hsm_RecallInfoGrp.cpp.

References log_FUNC_m, m_fsFile, m_streamSize, RememberChunkOffset(), and ivd_FS_File::SeekF().

Referenced by hsm_Recall::ProcRecBSStart().

                                                                            {
    log_FUNC_m(SeekF);
    m_fsFile.SeekF(a_offset);
    m_streamSize = 0; // start writing new stream
    RememberChunkOffset(a_pmJobId, a_offset);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_RecallInfoGrp::SetJobIndices ( Int32_t  a_jobIdx,
Int32_t  a_jobElemIdx 
)

Definition at line 253 of file hsm_RecallInfoGrp.cpp.

References log_FUNC_m.

void hsm_RecallInfoGrp::SetRecallFailed (  )  [inline]

Definition at line 86 of file hsm_RecallInfoGrp.h.

References m_recallFailed.

Referenced by hsm_Recall::RecallOfFileCanceled().

{ m_recallFailed = true; };

Here is the caller graph for this function:

ivd_FileRetSize_t hsm_RecallInfoGrp::WriteBufferedF ( const void *  a_buf,
ivd_FileBufSize_t  a_size 
)

Definition at line 147 of file hsm_RecallInfoGrp.cpp.

References dbg_NORM, log_DBG_m, log_FUNC_m, m_currentChunk_p, m_recallFailed, m_streamBLevel, m_streamBuffer_p, hsm_Chunk_t::offset, RecallBufferSize_d, and WriteF().

Referenced by hsm_Recall::ProcRecEmbData(), and hsm_Recall::ProcRecRawData().

                                                                                {
    
    log_FUNC_m(WriteBufferedF);
    if (a_size == 0) {
        return a_size;
    }
    ivd_FileRetSize_t ret(0);
    size_t remaining = RecallBufferSize_d - m_streamBLevel;
    char *Target_p = &(m_streamBuffer_p[m_streamBLevel]);
    if(a_size < remaining){
            log_DBG_m(dbg_NORM, "m_streamBLevel " << m_streamBLevel << " a_size " << a_size);
            memcpy(Target_p, a_buf, a_size);
            m_streamBLevel += a_size;
            ret = a_size;
    }
    else {
        // copy x to fill remaining buffer  (HRRRx yRRR) or (yRRRx yRRR)
        log_DBG_m(dbg_NORM, "m_streamBLevel " << m_streamBLevel << " remaining " << remaining);
        memcpy(Target_p, a_buf, remaining);
        ret = WriteF(m_streamBuffer_p, RecallBufferSize_d);
        log_DBG_m(dbg_NORM, "Written " << ret << " RecallBufferSize_d: " << RecallBufferSize_d 
                    << " data was written for chunk at offset: " << m_currentChunk_p->offset);
        if(ret != RecallBufferSize_d){
            m_recallFailed = true;
        }
        else {
            // copy y, the remaining data to the beginning of the buffer
            m_streamBLevel = 0;
            size_t ySize = a_size - remaining;
            if(ySize != 0){
                log_DBG_m(dbg_NORM, "m_streamBLevel=" << m_streamBLevel << " ySize=" << ySize);
                memcpy(m_streamBuffer_p, (char*)a_buf + remaining, ySize);
                m_streamBLevel += ySize;
            }
            ret = a_size;
            //log_DBG_m(dbg_DETAIL, "m_streamBLevel=" << m_streamBLevel << " a_size=" << a_size << " ret=" << ret);
        }
    }            
    return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ivd_FileRetSize_t hsm_RecallInfoGrp::WriteF ( const void *  a_buf,
ivd_FileBufSize_t  a_size 
)

Definition at line 95 of file hsm_RecallInfoGrp.cpp.

References dbg_DETAIL, ivd_BaseException::GetFriendly(), log_DBG_m, log_FUNC_m, m_fsFile, m_recallFailed, m_streamSize, and ivd_FS_File::WriteF().

Referenced by Close(), and WriteBufferedF().

                                                                                         {
    log_FUNC_m(WriteF);
    // do not write 
    ivd_FileRetSize_t ret;
    if (m_recallFailed) {
        // recall is already failed, simulate a proper write.
        ret = a_size;
    }
    else {
        try {
            ret = m_fsFile.WriteF(a_buf, a_size);
        }
        catch (ivd_SysError se) {
            m_streamSize += a_size;
            m_recallFailed = true;
            log_DBG_m(dbg_DETAIL, "m_streamSize: " << m_streamSize 
                        << "Recall failed cannot write to file. " << se.GetFriendly()); 
            return 0;
        }
        if (ret < a_size) {
            log_DBG_m(dbg_DETAIL, "Recall failed write less than ask. ret: " << ret
                                << ", size to write: " << a_size);
            m_recallFailed = true;
        }
    }
    // WriteF increase m_streamSize member
    // count the actual stream size, ret value may be smaller.
    m_streamSize += a_size;
    return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 96 of file hsm_RecallInfoGrp.h.

Definition at line 122 of file hsm_RecallInfoGrp.h.

Referenced by Close(), RememberChunkOffset(), and WriteBufferedF().

Definition at line 130 of file hsm_RecallInfoGrp.h.

Referenced by Close(), IsRecallFailed(), SetRecallFailed(), WriteBufferedF(), and WriteF().

Definition at line 116 of file hsm_RecallInfoGrp.h.

Referenced by Close(), and WriteBufferedF().

Definition at line 115 of file hsm_RecallInfoGrp.h.

Referenced by Close(), hsm_RecallInfoGrp(), WriteBufferedF(), and ~hsm_RecallInfoGrp().

Definition at line 107 of file hsm_RecallInfoGrp.h.

Definition at line 112 of file hsm_RecallInfoGrp.h.

Referenced by Close(), GetStreamSize(), SeekF(), and WriteF().


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