Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenddlog.c
Go to the documentation of this file.
00001 /**************************************************************************** 00002 * 00003 * Mesa 3-D graphics library 00004 * Direct3D Driver Interface 00005 * 00006 * ======================================================================== 00007 * 00008 * Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved. 00009 * 00010 * Permission is hereby granted, free of charge, to any person obtaining a 00011 * copy of this software and associated documentation files (the "Software"), 00012 * to deal in the Software without restriction, including without limitation 00013 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00014 * and/or sell copies of the Software, and to permit persons to whom the 00015 * Software is furnished to do so, subject to the following conditions: 00016 * 00017 * The above copyright notice and this permission notice shall be included 00018 * in all copies or substantial portions of the Software. 00019 * 00020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00021 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00022 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00023 * SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00024 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 00025 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00026 * SOFTWARE. 00027 * 00028 * ====================================================================== 00029 * 00030 * Language: ANSI C 00031 * Environment: Windows 9x (Win32) 00032 * 00033 * Description: Logging functions. 00034 * 00035 ****************************************************************************/ 00036 00037 #define STRICT 00038 #include <windows.h> 00039 00040 #include "ddlog.h" 00041 #include "gld_driver.h" 00042 00043 // *********************************************************************** 00044 00045 static char ddlogbuf[256]; 00046 static FILE* fpDDLog = NULL; // Log file pointer 00047 static char szDDLogName[_MAX_PATH] = {"gldirect.log"}; // Filename of the log 00048 static DDLOG_loggingMethodType ddlogLoggingMethod = DDLOG_NONE; // Default to No Logging 00049 static DDLOG_severityType ddlogDebugLevel; 00050 static BOOL bUIWarning = FALSE; // MessageBox warning ? 00051 00052 // *********************************************************************** 00053 00054 void ddlogOpen( 00055 DDLOG_loggingMethodType LoggingMethod, 00056 DDLOG_severityType Severity) 00057 { 00058 if (fpDDLog != NULL) { 00059 // Tried to re-open the log 00060 ddlogMessage(DDLOG_WARN, "Tried to re-open the log file\n"); 00061 return; 00062 } 00063 00064 ddlogLoggingMethod = LoggingMethod; 00065 ddlogDebugLevel = Severity; 00066 00067 if (ddlogLoggingMethod == DDLOG_NORMAL) { 00068 fpDDLog = fopen(szDDLogName, "wt"); 00069 if (fpDDLog == NULL) 00070 return; 00071 } 00072 00073 ddlogMessage(DDLOG_SYSTEM, "\n"); 00074 ddlogMessage(DDLOG_SYSTEM, "-> Logging Started\n"); 00075 } 00076 00077 // *********************************************************************** 00078 00079 void ddlogClose() 00080 { 00081 // Determine whether the log is already closed 00082 if (fpDDLog == NULL && ddlogLoggingMethod == DDLOG_NORMAL) 00083 return; // Nothing to do. 00084 00085 ddlogMessage(DDLOG_SYSTEM, "<- Logging Ended\n"); 00086 00087 if (ddlogLoggingMethod == DDLOG_NORMAL) { 00088 fclose(fpDDLog); 00089 fpDDLog = NULL; 00090 } 00091 } 00092 00093 // *********************************************************************** 00094 00095 void ddlogMessage( 00096 DDLOG_severityType severity, 00097 LPSTR message) 00098 { 00099 char buf[256]; 00100 00101 // Bail if logging is disabled 00102 if (ddlogLoggingMethod == DDLOG_NONE) 00103 return; 00104 00105 if (ddlogLoggingMethod == DDLOG_CRASHPROOF) 00106 fpDDLog = fopen(szDDLogName, "at"); 00107 00108 if (fpDDLog == NULL) 00109 return; 00110 00111 if (severity >= ddlogDebugLevel) { 00112 sprintf(buf, "DDLog: (%s) %s", ddlogSeverityMessages[severity], message); 00113 fputs(buf, fpDDLog); // Write string to file 00114 OutputDebugString(buf); // Echo to debugger 00115 } 00116 00117 if (ddlogLoggingMethod == DDLOG_CRASHPROOF) { 00118 fflush(fpDDLog); // Write info to disk 00119 fclose(fpDDLog); 00120 fpDDLog = NULL; 00121 } 00122 00123 // Popup message box if critical error 00124 if (bUIWarning && severity == DDLOG_CRITICAL) { 00125 MessageBox(NULL, buf, "GLDirect", MB_OK | MB_ICONWARNING | MB_TASKMODAL); 00126 } 00127 } 00128 00129 // *********************************************************************** 00130 00131 // Write a string value to the log file 00132 void ddlogError( 00133 DDLOG_severityType severity, 00134 LPSTR message, 00135 HRESULT hResult) 00136 { 00137 #ifdef _USE_GLD3_WGL 00138 char dxErrStr[1024]; 00139 _gldDriver.GetDXErrorString(hResult, &dxErrStr[0], sizeof(dxErrStr)); 00140 if (FAILED(hResult)) { 00141 sprintf(ddlogbuf, "DDLog: %s %8x:[ %s ]\n", message, hResult, dxErrStr); 00142 } else 00143 sprintf(ddlogbuf, "DDLog: %s\n", message); 00144 #else 00145 if (FAILED(hResult)) { 00146 sprintf(ddlogbuf, "DDLog: %s %8x:[ %s ]\n", message, hResult, DDErrorToString(hResult)); 00147 } else 00148 sprintf(ddlogbuf, "DDLog: %s\n", message); 00149 #endif 00150 ddlogMessage(severity, ddlogbuf); 00151 } 00152 00153 // *********************************************************************** 00154 00155 void ddlogPrintf( 00156 DDLOG_severityType severity, 00157 LPSTR message, 00158 ...) 00159 { 00160 va_list args; 00161 00162 va_start(args, message); 00163 vsprintf(ddlogbuf, message, args); 00164 va_end(args); 00165 00166 lstrcat(ddlogbuf, "\n"); 00167 00168 ddlogMessage(severity, ddlogbuf); 00169 } 00170 00171 // *********************************************************************** 00172 00173 void ddlogWarnOption( 00174 BOOL bWarnOption) 00175 { 00176 bUIWarning = bWarnOption; 00177 } 00178 00179 // *********************************************************************** 00180 00181 void ddlogPathOption( 00182 LPSTR szPath) 00183 { 00184 char szPathName[_MAX_PATH]; 00185 00186 strcpy(szPathName, szPath); 00187 strcat(szPathName, "\\"); 00188 strcat(szPathName, szDDLogName); 00189 strcpy(szDDLogName, szPathName); 00190 } 00191 00192 // *********************************************************************** Generated on Sun May 27 2012 04:19:57 for ReactOS by
1.7.6.1
|