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.


Detailed Description

Definition at line 31 of file log_File.h.


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

Constructor & Destructor Documentation

log_File::log_File ( bool  a_closeAfterWrite = true  ) 

Definition at line 40 of file log_File.cpp.

00041     : 
00042     m_closeAfterWrite(a_closeAfterWrite),
00043     m_fileHandle(invalidHandle_c),
00044     m_inErrorHandling(false)
00045 {
00046     // empty
00047 }

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

Definition at line 49 of file log_File.cpp.

00050     : 
00051     m_fileName(a_fileName),
00052     m_closeAfterWrite(a_closeAfterWrite),
00053     m_fileHandle(invalidHandle_c),
00054     m_inErrorHandling(false)
00055 {
00056     // empty
00057 }

log_File::~log_File (  )  [virtual]

Definition at line 59 of file log_File.cpp.

References CloseF().

00059                     {
00060     CloseF();
00061 }

Here is the call graph for this function:


Member Function Documentation

bool log_File::OpenF (  ) 

Definition at line 151 of file log_File.cpp.

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

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

00151                      {
00152     //cout << "OpenF:" << m_fileName << endl;
00153 
00154     if (m_fileName.empty()) {
00155         //cout << "m_fileName.empty() == true" << endl;
00156         // Redirect debugging stream to //cout.
00157 #if IVD_POSIX_OS
00158         m_fileHandle = fileno(stdout);
00159         //cout << "m_fileHandle:" << m_fileHandle << endl;
00160         return true;
00161 #elif TGT_OS_windows
00162         // WARNING: Output to screen is not supported on Windows.
00163         m_fileHandle = ivd_FileHandle_t(fileno(stdout));
00164         return false;
00165 #endif
00166     }
00167 
00168 #if IVD_POSIX_OS
00169     int openFlags(O_APPEND| O_CREAT | O_WRONLY);
00170     int oldMask = umask(0x0);
00171     m_fileHandle = open(m_fileName.c_str(), openFlags, fileMode_c);
00172     umask(oldMask);
00173 #elif TGT_OS_windows
00174     DWORD accessMode(GENERIC_WRITE | WRITE_OWNER | WRITE_DAC);
00175     DWORD createMode(OPEN_ALWAYS);
00176     DWORD attrAndFlags(FILE_ATTRIBUTE_NORMAL);
00177 
00178     m_fileHandle = CreateFile(
00179         cmn_MultiByteToWString(m_fileName.c_str()).c_str(),
00180         accessMode,
00181         (FILE_SHARE_READ | FILE_SHARE_WRITE),
00182         NULL,
00183         createMode,
00184         attrAndFlags,
00185         NULL);
00186 #endif
00187     return m_fileHandle != invalidHandle_c;
00188 }

Here is the call graph for this function:

Here is the caller graph for this function:

void log_File::CloseF (  )  [virtual]

Reimplemented in log_Debugger.

Definition at line 192 of file log_File.cpp.

References invalidHandle_c(), and m_fileHandle.

Referenced by log_Debugger::Off(), WriteF(), and ~log_File().

00192                       {
00193     if (m_fileHandle != invalidHandle_c) {
00194 #if TGT_OS_windows
00195         CloseHandle(m_fileHandle);
00196 #elif IVD_POSIX_OS
00197         close(m_fileHandle);
00198 #endif
00199     }
00200     m_fileHandle = invalidHandle_c;
00201 }

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 41 of file log_File.h.

Referenced by log_ivdfs::Init().

00041                                                  {
00042         m_fileName = a_fileName;
00043     };

Here is the caller graph for this function:

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

Definition at line 45 of file log_File.h.

Referenced by log_Debugger::On().

00045 { return m_fileName; };

Here is the caller graph for this function:

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

Definition at line 64 of file log_File.cpp.

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

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

00064                                                                  {
00065     //cout << "WriteF:" << m_fileName << endl;
00066     //cout << "m_fileHandle:" << m_fileHandle << endl;
00067     //cout << "m_closeAfterWrite:" << boolalpha << m_closeAfterWrite << endl;
00068     //cout << "invalidHandle_c:" << invalidHandle_c << endl;
00069     
00070     
00071     if (m_closeAfterWrite && m_fileHandle == invalidHandle_c) {
00072         if (!OpenF()) {
00073 //cout << "OpenF() == false";
00074             
00075             return;
00076         }
00077         //cout << "OpenF() == true" << endl;
00078     }
00079     //cout << "Positioning:" << endl;
00080 
00081     ivd_FilePosition_t pos(-1LL);
00082     ivd_FileRetSize_t ret;
00083 
00084 #if TGT_OS_windows
00085 
00086     LARGE_INTEGER winPos, zero = {0, 0};
00087     if ( !SetFilePointerEx(m_fileHandle, zero, &winPos, FILE_END) ) {
00088         HandleError(GetLastError());
00089         return;
00090     }
00091     pos = winPos.QuadPart;
00092             
00093 #elif IVD_POSIX_OS
00094     if (m_fileHandle == 1) {
00095         //if stdout position at 0
00096         pos = 0LL;
00097     } else {
00098         pos = lseek(m_fileHandle, 0, SEEK_END);
00099     }
00100     //cout << "95: ret seek:" << pos << endl;
00101     if (pos == -1) {
00102         HandleError(errno);
00103         return;
00104     }
00105     if (pos == 0LL ) {
00106         (void)chmod(m_fileName.c_str(), fileMode_c);
00107     }
00108 #endif
00109 
00110     if (pos == 0LL ) {
00111 //    cout << "pos == 0LL" << endl;
00112         // If file is positioned to 0 after opening, write header and
00113         // change mode. Files was most probably deleted since last write.
00114         string head = GetHeader();
00115 
00116 #if TGT_OS_windows
00117         if (!WriteFile(m_fileHandle, head.data(), head.length(), &ret, NULL)) {
00118             HandleError(GetLastError());
00119             return;
00120         }
00121 #elif IVD_POSIX_OS
00122         ret = write(m_fileHandle, head.data(), head.length());
00123   //      cout << "117: ret head:" << ret << endl;
00124         if (ret < 0 ) {
00125             HandleError(errno);
00126             return;
00127         }
00128 #endif
00129     };
00130         
00131 #if TGT_OS_windows
00132     if ( !WriteFile(m_fileHandle, a_buf, a_size, &ret, NULL) ) {
00133         HandleError(GetLastError());
00134     };
00135 #elif IVD_POSIX_OS
00136 
00137     //cout << "ret" << endl;
00138     ret = write(m_fileHandle, a_buf, a_size);
00139     //cout << "ret:" << ret << endl;
00140     if (ret < 0) {
00141         HandleError(errno);
00142     };
00143 #endif
00144 
00145     if (m_closeAfterWrite) {
00146         CloseF();
00147     }
00148 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 50 of file log_File.h.

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

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

Reimplemented in log_ErrorStream, and log_EventLogger.

Definition at line 54 of file log_File.h.

Referenced by WriteF().

00054 { return string(""); };

Here is the caller graph for this function:

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

Definition at line 55 of file log_File.h.

Referenced by HandleError().

00055 { CloseF(); };

Here is the caller graph for this function:

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

Definition at line 205 of file log_File.cpp.

References Error(), and m_inErrorHandling.

Referenced by WriteF().

00205                                       {
00206     if (m_inErrorHandling) {
00207         // Prevent cycle
00208         return;
00209     }
00210     m_inErrorHandling = true;
00211     Error(a_error);
00212     m_inErrorHandling = false;
00213 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 61 of file log_File.h.

Referenced by WriteF().

Definition at line 62 of file log_File.h.

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

Definition at line 63 of file log_File.h.

Referenced by HandleError().


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

Generated on Mon Feb 27 19:42:53 2012 for OPENARCHIVE by  doxygen 1.5.6