#include <log_File.h>


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_Path & | GetFileName () 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 |
| 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 }

| 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 }


| 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 }


| 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 };

| 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; };

| 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 }


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

| virtual void log_File::Error | ( | int | a_errorCode | ) | [inline, virtual] |
Definition at line 55 of file log_File.h.
Referenced by HandleError().
00055 { CloseF(); };

| 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 }


cmn_Path log_File::m_fileName [protected] |
Definition at line 55 of file log_File.h.
Referenced by log_Debugger::On(), OpenF(), log_Debugger::SetFileName(), log_EventLogger::SetNewPath(), log_ErrorStream::SetNewPath(), and WriteF().
bool log_File::m_closeAfterWrite [private] |
ivd_FileHandle_t log_File::m_fileHandle [mutable, private] |
bool log_File::m_inErrorHandling [private] |
1.5.6