diff options
author | George Hazan <ghazan@miranda.im> | 2019-03-02 12:32:44 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-03-02 12:32:55 +0300 |
commit | 931a7dc1ac0dbc7e6c1083583ced915e572f5b47 (patch) | |
tree | 9fe9a6448d44030e26aa7107ce16044ed413e0d0 /protocols/YAMN/src/debug.cpp | |
parent | dd7d9954042254e66e3bbbec7195c6be8b1a0663 (diff) |
all protocols (even virtual ones) moved to the Protocols folder
Diffstat (limited to 'protocols/YAMN/src/debug.cpp')
-rw-r--r-- | protocols/YAMN/src/debug.cpp | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/protocols/YAMN/src/debug.cpp b/protocols/YAMN/src/debug.cpp new file mode 100644 index 0000000000..971b3dcbce --- /dev/null +++ b/protocols/YAMN/src/debug.cpp @@ -0,0 +1,127 @@ +/* + * YAMN plugin main file + * Miranda homepage: http://miranda-icq.sourceforge.net/ + * + * Debug functions used in DEBUG release (you need to global #define DEBUG to get debug version) + * + * (c) majvan 2002-2004 + */ + +#include "stdafx.h" + +#ifdef _DEBUG + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +wchar_t DebugUserDirectory[MAX_PATH] = L"."; +CRITICAL_SECTION FileAccessCS; + +#ifdef DEBUG_SYNCHRO +wchar_t DebugSynchroFileName2[]=L"%s\\yamn-debug.synchro.log"; +HANDLE SynchroFile; +#endif + +#ifdef DEBUG_COMM +wchar_t DebugCommFileName2[]=L"%s\\yamn-debug.comm.log"; +HANDLE CommFile; +#endif + +#ifdef DEBUG_DECODE +wchar_t DebugDecodeFileName2[]=L"%s\\yamn-debug.decode.log"; +HANDLE DecodeFile; +#endif + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +void InitDebug() +{ +#if defined (DEBUG_SYNCHRO) || defined (DEBUG_COMM) || defined (DEBUG_DECODE) + wchar_t DebugFileName[MAX_PATH]; +#endif + InitializeCriticalSection(&FileAccessCS); + +#ifdef DEBUG_SYNCHRO + mir_snwprintf(DebugFileName, DebugSynchroFileName2, DebugUserDirectory); + + SynchroFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); + DebugLog(SynchroFile,"Synchro debug file created by %s\n",YAMN_VER); +#endif + +#ifdef DEBUG_COMM + mir_snwprintf(DebugFileName, DebugCommFileName2, DebugUserDirectory); + + CommFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); + DebugLog(CommFile,"Communication debug file created by %s\n",YAMN_VER); +#endif + +#ifdef DEBUG_DECODE + mir_snwprintf(DebugFileName, DebugDecodeFileName2, DebugUserDirectory); + + DecodeFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); + DebugLog(DecodeFile,"Decoding kernel debug file created by %s\n",YAMN_VER); +#endif +} + +void UnInitDebug() +{ + DeleteCriticalSection(&FileAccessCS); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"File is being closed normally."); + CloseHandle(SynchroFile); +#endif +#ifdef DEBUG_COMM + DebugLog(CommFile,"File is being closed normally."); + CloseHandle(CommFile); +#endif +#ifdef DEBUG_DECODE + DebugLog(DecodeFile,"File is being closed normally."); + CloseHandle(DecodeFile); +#endif +} + + +void DebugLog(HANDLE File,const char *fmt,...) +{ + char *str; + char tids[32]; + va_list vararg; + int strsize; + DWORD Written; + + va_start(vararg,fmt); + str=(char *)malloc(strsize=65536); + mir_snprintf(tids, "[%x]",GetCurrentThreadId()); + while(mir_vsnprintf(str, strsize, fmt, vararg)==-1) + str=(char *)realloc(str,strsize+=65536); + va_end(vararg); + EnterCriticalSection(&FileAccessCS); + WriteFile(File,tids,(DWORD)mir_strlen(tids),&Written,nullptr); + WriteFile(File,str,(DWORD)mir_strlen(str),&Written,nullptr); + LeaveCriticalSection(&FileAccessCS); + free(str); +} + +void DebugLogW(HANDLE File,const WCHAR *fmt,...) +{ + WCHAR *str; + char tids[32]; + va_list vararg; + int strsize; + DWORD Written; + + va_start(vararg,fmt); + str=(WCHAR *)malloc((strsize=65536)*sizeof(WCHAR)); + mir_snprintf(tids, "[%x]",GetCurrentThreadId()); + while(mir_vsnwprintf(str, strsize, fmt, vararg)==-1) + str=(WCHAR *)realloc(str,(strsize+=65536)*sizeof(WCHAR)); + va_end(vararg); + EnterCriticalSection(&FileAccessCS); + WriteFile(File,tids,(DWORD)mir_strlen(tids),&Written,nullptr); + WriteFile(File,str,(DWORD)mir_wstrlen(str)*sizeof(WCHAR),&Written,nullptr); + LeaveCriticalSection(&FileAccessCS); + free(str); +} + +#endif //ifdef DEBUG
\ No newline at end of file |