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

log_File Class Reference
[G_new_group]

#include <log_File.h>

Inheritance diagram for log_File:
Inheritance graph
[legend]
Collaboration diagram for log_File:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 log_File (bool a_closeAfterWrite=true)
 log_File (const cmn_Path &a_fileName, bool a_closeAfterWrite=true)
virtual ~log_File ()
bool OpenF ()
virtual void CloseF ()
void SetFileName (const cmn_Path &a_fileName)
const cmn_PathGetFileName () const
void WriteF (const void *a_buf, ivd_FileBufSize_t a_size)
void WriteF (const string &a_os)
virtual string GetHeader () const
virtual void Error (int a_errorCode)

Protected Attributes

cmn_Path m_fileName

Private Member Functions

void HandleError (int a_error)

Private Attributes

bool m_closeAfterWrite
ivd_FileHandle_t m_fileHandle
bool m_inErrorHandling

Detailed Description

Definition at line 45 of file log_File.h.


Constructor & Destructor Documentation

log_File::log_File ( bool  a_closeAfterWrite = true  ) 

Definition at line 54 of file log_File.cpp.

    : 
    m_closeAfterWrite(a_closeAfterWrite),
    m_fileHandle(invalidHandle_c),
    m_inErrorHandling(false)
{
    // empty
}

log_File::log_File ( const cmn_Path a_fileName,
bool  a_closeAfterWrite = true 
)

Definition at line 63 of file log_File.cpp.

    : 
    m_fileName(a_fileName),
    m_closeAfterWrite(a_closeAfterWrite),
    m_fileHandle(invalidHandle_c),
    m_inErrorHandling(false)
{
    // empty
}

log_File::~log_File (  )  [virtual]

Definition at line 73 of file log_File.cpp.

References CloseF().

                    {
    CloseF();
}

Here is the call graph for this function:


Member Function Documentation

void log_File::CloseF (  )  [virtual]

Reimplemented in log_Debugger.

Definition at line 206 of file log_File.cpp.

References invalidHandle_c(), and m_fileHandle.

Referenced by WriteF(), and ~log_File().

                      {
    if (m_fileHandle != invalidHandle_c) {
#if TGT_OS_windows
        CloseHandle(m_fileHandle);
#elif IVD_POSIX_OS
        close(m_fileHandle);
#endif
    }
    m_fileHandle = invalidHandle_c;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void log_File::Error ( int  a_errorCode  )  [inline, virtual]

Definition at line 69 of file log_File.h.

Referenced by HandleError().

{ CloseF(); };

Here is the caller graph for this function:

const cmn_Path& log_File::GetFileName (  )  const [inline]

Definition at line 59 of file log_File.h.

Referenced by log_Debugger::On().

{ return m_fileName; };

Here is the caller graph for this function:

virtual string log_File::GetHeader (  )  const [inline, virtual]

Reimplemented in log_ErrorStream, and log_EventLogger.

Definition at line 68 of file log_File.h.

Referenced by WriteF().

{ return string(""); };

Here is the caller graph for this function:

void log_File::HandleError ( int  a_error  )  [private]

Definition at line 219 of file log_File.cpp.

References Error(), and m_inErrorHandling.

Referenced by WriteF().

                                      {
    if (m_inErrorHandling) {
        // Prevent cycle
        return;
    }
    m_inErrorHandling = true;
    Error(a_error);
    m_inErrorHandling = false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool log_File::OpenF (  ) 

Definition at line 165 of file log_File.cpp.

References cmn_MultiByteToWString(), m_fileHandle, m_fileName, and NULL.

Referenced by log_Debugger::On(), and WriteF().

                     {
    //cout << "OpenF:" << m_fileName << endl;

    if (m_fileName.empty()) {
        //cout << "m_fileName.empty() == true" << endl;
        // Redirect debugging stream to //cout.
#if IVD_POSIX_OS
        m_fileHandle = fileno(stdout);
        //cout << "m_fileHandle:" << m_fileHandle << endl;
        return true;
#elif TGT_OS_windows
        // WARNING: Output to screen is not supported on Windows.
        m_fileHandle = ivd_FileHandle_t(fileno(stdout));
        return false;
#endif
    }

#if IVD_POSIX_OS
    int openFlags(O_APPEND| O_CREAT | O_WRONLY);
    int oldMask = umask(0x0);
    m_fileHandle = open(m_fileName.c_str(), openFlags, fileMode_c);
    umask(oldMask);
#elif TGT_OS_windows
    DWORD accessMode(GENERIC_WRITE | WRITE_OWNER | WRITE_DAC);
    DWORD createMode(OPEN_ALWAYS);
    DWORD attrAndFlags(FILE_ATTRIBUTE_NORMAL);

    m_fileHandle = CreateFile(
        cmn_MultiByteToWString(m_fileName.c_str()).c_str(),
        accessMode,
        (FILE_SHARE_READ | FILE_SHARE_WRITE),
        NULL,
        createMode,
        attrAndFlags,
        NULL);
#endif
    return m_fileHandle != invalidHandle_c;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void log_File::SetFileName ( const cmn_Path a_fileName  )  [inline]

Reimplemented in log_Debugger.

Definition at line 55 of file log_File.h.

Referenced by log_ivdfs::Init().

                                                 {
        m_fileName = a_fileName;
    };

Here is the caller graph for this function:

void log_File::WriteF ( const string &  a_os  )  [inline]

Definition at line 64 of file log_File.h.

                                    {
        WriteF(a_os.data(), ivd_FileBufSize_t(a_os.length()) );
    };

void log_File::WriteF ( const void *  a_buf,
ivd_FileBufSize_t  a_size 
)

Definition at line 78 of file log_File.cpp.

References CloseF(), errno, GetHeader(), HandleError(), invalidHandle_c(), m_closeAfterWrite, m_fileHandle, m_fileName, NULL, OpenF(), and zero.

Referenced by log_Output(), log_ivdfs::Write(), log_EventLogger::Write(), log_Debugger::Write(), and log_ivdfs::WriteHL7MsgNotification().

                                                                 {
    //cout << "WriteF:" << m_fileName << endl;
    //cout << "m_fileHandle:" << m_fileHandle << endl;
    //cout << "m_closeAfterWrite:" << boolalpha << m_closeAfterWrite << endl;
    //cout << "invalidHandle_c:" << invalidHandle_c << endl;
    
    
    if (m_closeAfterWrite && m_fileHandle == invalidHandle_c) {
        if (!OpenF()) {
//cout << "OpenF() == false";
            
            return;
        }
        //cout << "OpenF() == true" << endl;
    }
    //cout << "Positioning:" << endl;

    ivd_FilePosition_t pos(-1LL);
    ivd_FileRetSize_t ret;

#if TGT_OS_windows

    LARGE_INTEGER winPos, zero = {0, 0};
    if ( !SetFilePointerEx(m_fileHandle, zero, &winPos, FILE_END) ) {
        HandleError(GetLastError());
        return;
    }
    pos = winPos.QuadPart;
            
#elif IVD_POSIX_OS
    if (m_fileHandle == 1) {
        //if stdout position at 0
        pos = 0LL;
    } else {
        pos = lseek(m_fileHandle, 0, SEEK_END);
    }
    //cout << "95: ret seek:" << pos << endl;
    if (pos == -1) {
        HandleError(errno);
        return;
    }
    if (pos == 0LL ) {
        (void)chmod(m_fileName.c_str(), fileMode_c);
    }
#endif

    if (pos == 0LL ) {
//    cout << "pos == 0LL" << endl;
        // If file is positioned to 0 after opening, write header and
        // change mode. Files was most probably deleted since last write.
        string head = GetHeader();

#if TGT_OS_windows
        if (!WriteFile(m_fileHandle, head.data(), head.length(), &ret, NULL)) {
            HandleError(GetLastError());
            return;
        }
#elif IVD_POSIX_OS
        ret = write(m_fileHandle, head.data(), head.length());
  //      cout << "117: ret head:" << ret << endl;
        if (ret < 0 ) {
            HandleError(errno);
            return;
        }
#endif
    };
        
#if TGT_OS_windows
    if ( !WriteFile(m_fileHandle, a_buf, a_size, &ret, NULL) ) {
        HandleError(GetLastError());
    };
#elif IVD_POSIX_OS

    //cout << "ret" << endl;
    ret = write(m_fileHandle, a_buf, a_size);
    //cout << "ret:" << ret << endl;
    if (ret < 0) {
        HandleError(errno);
    };
#endif

    if (m_closeAfterWrite) {
        CloseF();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 75 of file log_File.h.

Referenced by WriteF().

Definition at line 76 of file log_File.h.

Referenced by CloseF(), OpenF(), and WriteF().

Definition at line 77 of file log_File.h.

Referenced by HandleError().


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