debug.cpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: debug.cpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #include "debug.hpp" 00045 00046 #ifdef WIN32 00047 00048 #include <stdarg.h> 00049 00050 #ifdef WINCE 00051 #include <winbase.h> 00052 #include <afxwin.h> 00053 #endif 00054 00055 static char buf[2048]; 00056 00057 00058 #ifdef WINCE 00059 static void * logfile = NULL; 00060 static CFile *myfile = NULL; 00061 static bool createLogfile = true; 00062 static int errno = 0; 00063 #endif 00064 00065 00066 void logFile() 00067 { 00068 #ifdef WINCE 00069 if (createLogfile) { 00070 logfile = CreateFile(_T("vitookilog.txt"),GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 00071 myfile = new CFile((int)logfile); 00072 createLogfile = false; 00073 } else { 00074 /*logfile = CreateFile(_T("\\vitookilog.txt"),GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 00075 myfile = new CFile((int)logfile); 00076 myfile->SeekToEnd();*/ 00077 } 00078 00079 if (logfile != NULL) { 00080 char threadId[50]; 00081 DWORD curId = GetCurrentThreadId(); 00082 sprintf(threadId, "[%d] ", curId); 00083 myfile->Write(threadId, strlen(threadId)); 00084 myfile->Write(buf, strlen(buf)); 00085 myfile->Write("\r\n", 2); 00086 //myfile->Close(); 00087 } 00088 00089 #endif 00090 } 00091 00092 00093 00094 void dprintf(const char *format, ...) 00095 { 00096 #ifdef VITOOKI_DEBUG 00097 va_list args; 00098 00099 va_start(args, format); 00100 vsprintf(buf, format, args); 00101 #ifndef WINCE 00102 printf("[%d] %s",(int)pthread_self(), buf); 00103 #else 00104 logFile(); 00105 #endif 00106 00107 va_end(args); 00108 #endif 00109 } 00110 00111 void dfprintf(FILE * F, const char *format, ...) 00112 { 00113 #ifdef VITOOKI_DEBUG 00114 va_list args; 00115 00116 va_start(args, format); 00117 vsprintf(buf, format, args); 00118 #ifndef WINCE 00119 printf("[%d] %s",(int)pthread_self(), buf); 00120 #else 00121 logFile(); 00122 #endif 00123 00124 va_end(args); 00125 #endif 00126 } 00127 00128 void dprintf_err(const char *format, ...) 00129 { 00130 #if VITOOKI_DEBUG_LEVEL >= VITOOKI_DEBUG_ERR 00131 va_list args; 00132 00133 va_start(args, format); 00134 vsprintf(buf, format, args); 00135 #ifndef WINCE 00136 printf("Log_E: [%d] %s",(int)pthread_self(), buf); 00137 #else 00138 logFile(); 00139 #endif 00140 00141 va_end(args); 00142 #endif 00143 } 00144 00145 void dprintf_err_fatal(const char *format, ...) 00146 { 00147 #if VITOOKI_DEBUG_LEVEL >= VITOOKI_DEBUG_ERR 00148 va_list args; 00149 00150 va_start(args, format); 00151 vsprintf(buf, format, args); 00152 #ifndef WINCE 00153 printf("Log_E: [%d] %s",(int)pthread_self(), buf); 00154 #else 00155 logFile(); 00156 CString serr (buf); 00157 MessageBox(NULL, serr, _T("Error"), MB_ICONERROR); 00158 #endif 00159 00160 va_end(args); 00161 #endif 00162 } 00163 00164 void dfprintf_err(FILE * F, const char *format, ...) 00165 { 00166 #if VITOOKI_DEBUG_LEVEL >= VITOOKI_DEBUG_ERR 00167 va_list args; 00168 00169 va_start(args, format); 00170 vsprintf(buf, format, args); 00171 #ifndef WINCE 00172 fprintf(F, "Log_E: [%d] %s",(int)pthread_self(), buf); 00173 #else 00174 logFile(); 00175 #endif 00176 00177 va_end(args); 00178 #endif 00179 } 00180 00181 void dprintf_small(const char *format, ...) 00182 { 00183 #if VITOOKI_DEBUG_LEVEL >= VITOOKI_DEBUG_SMALL 00184 va_list args; 00185 00186 va_start(args, format); 00187 vsprintf(buf, format, args); 00188 #ifndef WINCE 00189 printf("Log_S: [%d] %s",(int)pthread_self(), buf); 00190 #else 00191 logFile(); 00192 #endif 00193 00194 va_end(args); 00195 #endif 00196 } 00197 00198 void dfprintf_small(FILE * F, const char *format, ...) 00199 { 00200 #if VITOOKI_DEBUG_LEVEL >= VITOOKI_DEBUG_SMALL 00201 va_list args; 00202 00203 va_start(args, format); 00204 vsprintf(buf, format, args); 00205 #ifndef WINCE 00206 fprintf(F, "Log_S: [%d] %s",(int)pthread_self(), buf); 00207 #else 00208 logFile(); 00209 #endif 00210 00211 va_end(args); 00212 #endif 00213 } 00214 00215 void dprintf_full(const char *format, ...) 00216 { 00217 #if VITOOKI_DEBUG_LEVEL >= VITOOKI_DEBUG_FULL 00218 va_list args; 00219 00220 va_start(args, format); 00221 vsprintf(buf, format, args); 00222 #ifndef WINCE 00223 printf("Log_F: [%d] %s",(int)pthread_self(), buf); 00224 #else 00225 logFile(); 00226 #endif 00227 00228 va_end(args); 00229 #endif 00230 } 00231 00232 void dfprintf_full(FILE * F, const char *format, ...) 00233 { 00234 #if VITOOKI_DEBUG_LEVEL >= VITOOKI_DEBUG_FULL 00235 va_list args; 00236 00237 va_start(args, format); 00238 vsprintf(buf, format, args); 00239 #ifndef WINCE 00240 fprintf(F, "[%d] %s",(int)pthread_self(), buf); 00241 #else 00242 logFile(); 00243 #endif 00244 00245 va_end(args); 00246 #endif 00247 } 00248 00249 #endif