Commit 318529d8 authored by captainwong's avatar captainwong

update

parent b4c5f6ca
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
//#define TRACE CLog::WriteLog //#define TRACE CLog::WriteLog
//#endif //#endif
namespace jlib
{
#define IMPLEMENT_CLASS_LOG_STATIC_MEMBER \ #define IMPLEMENT_CLASS_LOG_STATIC_MEMBER \
CRITICAL_SECTION CLog::m_cs;\ CRITICAL_SECTION CLog::m_cs;\
CLock CLog::m_lockForSingleton;\ CLock CLog::m_lockForSingleton;\
...@@ -39,21 +42,21 @@ ...@@ -39,21 +42,21 @@
CLog* CLog::m_pInstance = NULL;\ CLog* CLog::m_pInstance = NULL;\
TCHAR CLog::g_szFileName[1024] = { 0 }; TCHAR CLog::g_szFileName[1024] = { 0 };
/* /*
#define TRACEFUNCNAME \ #define TRACEFUNCNAME \
CString str = _T("");\ CString str = _T("");\
INIT_SYM(TRUE);\ INIT_SYM(TRUE);\
str.Format("File %s, line %d, funcname %s\n", __FILE__, __LINE__, __FUNCNAME__);\ str.Format("File %s, line %d, funcname %s\n", __FILE__, __LINE__, __FUNCNAME__);\
OutputDebugString(str);\ OutputDebugString(str);\
UNINIT_SYM();\ UNINIT_SYM();\
*/ */
#define MAX_OUTPUT_LEN (1024 * 64) #define MAX_OUTPUT_LEN (1024 * 64)
#define MAX_FILE_LEN (1024 * 1024 * 10) #define MAX_FILE_LEN (1024 * 1024 * 10)
//static TCHAR g_szFileName[1024] = {0}; //static TCHAR g_szFileName[1024] = {0};
class CLog class CLog
{ {
private: private:
double exe_time; double exe_time;
LARGE_INTEGER freq; LARGE_INTEGER freq;
LARGE_INTEGER start_t, stop_t; LARGE_INTEGER start_t, stop_t;
...@@ -72,18 +75,20 @@ private: ...@@ -72,18 +75,20 @@ private:
static char m_ansiBuf[MAX_OUTPUT_LEN]; static char m_ansiBuf[MAX_OUTPUT_LEN];
static wchar_t m_utf16Buf[MAX_OUTPUT_LEN]; static wchar_t m_utf16Buf[MAX_OUTPUT_LEN];
static CLog* m_pInstance; static CLog* m_pInstance;
public: public:
static const wchar_t* GetPrivateLogPath(){ static const wchar_t* GetPrivateLogPath()
{
static wchar_t strPrivateMapFolder[1024] = { 0 }; static wchar_t strPrivateMapFolder[1024] = { 0 };
static BOOL b = TRUE; static BOOL b = TRUE;
if(b){ if (b) {
wsprintf(strPrivateMapFolder, _T("%s\\Log"), GetModuleFilePath()); wsprintf(strPrivateMapFolder, _T("%s\\Log"), GetModuleFilePath());
b = FALSE; b = FALSE;
} }
return strPrivateMapFolder; return strPrivateMapFolder;
} }
static CLog* GetInstance(){ static CLog* GetInstance()
{
m_lockForSingleton.Lock(); m_lockForSingleton.Lock();
if (CLog::m_pInstance == NULL) { if (CLog::m_pInstance == NULL) {
static CLog log; static CLog log;
...@@ -93,14 +98,15 @@ public: ...@@ -93,14 +98,15 @@ public:
return CLog::m_pInstance; return CLog::m_pInstance;
} }
~CLog(){ ~CLog()
{
m_bRunning = FALSE; m_bRunning = FALSE;
//WaitTillThreadExited(m_handle); //WaitTillThreadExited(m_handle);
if(m_bConsoleOpened) if (m_bConsoleOpened)
OpenConsole(FALSE); OpenConsole(FALSE);
if(m_bDbgviewOpened) if (m_bDbgviewOpened)
OpenDbgview(FALSE); OpenDbgview(FALSE);
if(m_bLogFileOpened) if (m_bLogFileOpened)
CloseLogFile(); CloseLogFile();
DeleteCriticalSection(&m_cs); DeleteCriticalSection(&m_cs);
#ifdef _DEBUG #ifdef _DEBUG
...@@ -111,26 +117,30 @@ public: ...@@ -111,26 +117,30 @@ public:
#endif #endif
} }
static void SetOutputLogFileName(LPCTSTR szLastName){ static void SetOutputLogFileName(LPCTSTR szLastName)
{
lstrcpy(g_szFileName, szLastName); lstrcpy(g_szFileName, szLastName);
} }
static void SetOutputConsole(BOOL bFlag){ static void SetOutputConsole(BOOL bFlag)
{
CLog* plog = CLog::GetInstance(); CLog* plog = CLog::GetInstance();
plog->m_bOutputConsole = bFlag; plog->m_bOutputConsole = bFlag;
plog->OpenConsole(bFlag); plog->OpenConsole(bFlag);
} }
static void SetOutputDbgView(BOOL bFlag){ static void SetOutputDbgView(BOOL bFlag)
{
CLog* plog = CLog::GetInstance(); CLog* plog = CLog::GetInstance();
plog->m_bOutputDbgView = bFlag; plog->m_bOutputDbgView = bFlag;
//plog->OpenDbgview(bFlag); //plog->OpenDbgview(bFlag);
} }
static void SetOutputLogFile(BOOL bFlag){ static void SetOutputLogFile(BOOL bFlag)
{
CLog* plog = CLog::GetInstance(); CLog* plog = CLog::GetInstance();
plog->m_bOutputLogFile = bFlag; plog->m_bOutputLogFile = bFlag;
if(plog->m_bOutputLogFile && lstrlen(g_szFileName) == 0) if (plog->m_bOutputLogFile && lstrlen(g_szFileName) == 0)
plog->CreateFileName(); plog->CreateFileName();
} }
...@@ -194,20 +204,21 @@ public: ...@@ -194,20 +204,21 @@ public:
} }
} }
static void WriteLog(const TCHAR* format, ...) { static void WriteLog(const TCHAR* format, ...)
try{ {
try {
CLog* plog = CLog::GetInstance(); CLog* plog = CLog::GetInstance();
if(plog == NULL) if (plog == NULL)
return; return;
CLocalLock lock(&m_cs); CLocalLock lock(&m_cs);
if(plog->m_bOutputLogFile || plog->m_bOutputDbgView || plog->m_bOutputConsole) { if (plog->m_bOutputLogFile || plog->m_bOutputDbgView || plog->m_bOutputConsole) {
static TCHAR buf[MAX_OUTPUT_LEN], output[MAX_OUTPUT_LEN], *p; static TCHAR buf[MAX_OUTPUT_LEN], output[MAX_OUTPUT_LEN], *p;
p = buf; p = buf;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
p += _vsntprintf_s(p, sizeof (buf) - 1, sizeof (buf) - 1, format, args); p += _vsntprintf_s(p, sizeof(buf) - 1, sizeof(buf) - 1, format, args);
va_end(args); va_end(args);
while ( (p > buf) && _istspace(*(p-1)) ) while ((p > buf) && _istspace(*(p - 1)))
*--p = _T('\0'); *--p = _T('\0');
*p++ = _T('\r'); *p++ = _T('\r');
*p++ = _T('\n'); *p++ = _T('\n');
...@@ -215,26 +226,26 @@ public: ...@@ -215,26 +226,26 @@ public:
plog->FormatBuf(buf, output); plog->FormatBuf(buf, output);
plog->Output(output); plog->Output(output);
} }
} } catch (...) {
catch(...){
assert(0); assert(0);
} }
} }
static void WriteLogW(const wchar_t* format, ...) { static void WriteLogW(const wchar_t* format, ...)
try{ {
try {
CLog* plog = CLog::GetInstance(); CLog* plog = CLog::GetInstance();
if(plog == NULL) if (plog == NULL)
return; return;
CLocalLock lock(&m_cs); CLocalLock lock(&m_cs);
if(plog->m_bOutputLogFile || plog->m_bOutputDbgView || plog->m_bOutputConsole) { if (plog->m_bOutputLogFile || plog->m_bOutputDbgView || plog->m_bOutputConsole) {
static wchar_t buf[MAX_OUTPUT_LEN], *p; static wchar_t buf[MAX_OUTPUT_LEN], *p;
p = buf; p = buf;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
p += _vsnwprintf_s(p, sizeof (buf) - 1, sizeof (buf) - 1, format, args); p += _vsnwprintf_s(p, sizeof(buf) - 1, sizeof(buf) - 1, format, args);
va_end(args); va_end(args);
while ( (p > buf) && iswspace(*(p-1)) ) while ((p > buf) && iswspace(*(p - 1)))
*--p = '\0'; *--p = '\0';
*p++ = '\r'; *p++ = '\r';
*p++ = '\n'; *p++ = '\n';
...@@ -256,39 +267,36 @@ public: ...@@ -256,39 +267,36 @@ public:
} }
#endif #endif
} }
} } catch (...) {
catch(...){
assert(0); assert(0);
} }
} }
static void WriteLogA(const char* format, ...) { static void WriteLogA(const char* format, ...)
try{ {
try {
CLog* plog = CLog::GetInstance(); CLog* plog = CLog::GetInstance();
if(plog == NULL) if (plog == NULL)
return; return;
CLocalLock lock(&m_cs); CLocalLock lock(&m_cs);
if(plog->m_bOutputLogFile || plog->m_bOutputDbgView || plog->m_bOutputConsole) { if (plog->m_bOutputLogFile || plog->m_bOutputDbgView || plog->m_bOutputConsole) {
static char buf[MAX_OUTPUT_LEN], *p; static char buf[MAX_OUTPUT_LEN], *p;
p = buf; p = buf;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
p += _vsnprintf_s(p, sizeof (buf) - 1, sizeof (buf) - 1, format, args); p += _vsnprintf_s(p, sizeof(buf) - 1, sizeof(buf) - 1, format, args);
va_end(args); va_end(args);
while ( (p > buf) && isspace(*(p-1)) ) while ((p > buf) && _istspace(*(p - 1)))
*--p = '\0'; *--p = '\0';
*p++ = '\r'; *p++ = '\r';
*p++ = '\n'; *p++ = '\n';
*p = '\0'; *p = '\0';
#if defined(_UNICODE) || defined(UNICODE) #if defined(_UNICODE) || defined(UNICODE)
wchar_t output[MAX_OUTPUT_LEN]; wchar_t output[MAX_OUTPUT_LEN];
if(AnsiToUtf16Array(buf, m_utf16Buf, MAX_OUTPUT_LEN)) if (AnsiToUtf16Array(buf, m_utf16Buf, MAX_OUTPUT_LEN)) {
{
plog->FormatBuf(m_utf16Buf, output); plog->FormatBuf(m_utf16Buf, output);
plog->Output(output); plog->Output(output);
} } else {
else
{
wchar_t *wBuf = AnsiToUtf16(buf); wchar_t *wBuf = AnsiToUtf16(buf);
plog->FormatBuf(wBuf, output); plog->FormatBuf(wBuf, output);
plog->Output(output); plog->Output(output);
...@@ -300,33 +308,34 @@ public: ...@@ -300,33 +308,34 @@ public:
plog->Output(output); plog->Output(output);
#endif #endif
} }
} } catch (...) {
catch(...){
assert(0); assert(0);
} }
} }
protected: protected:
CLog(): m_pLogFile(NULL), m_bOutputLogFile(FALSE), m_bOutputDbgView(FALSE), CLog() : m_pLogFile(NULL), m_bOutputLogFile(FALSE), m_bOutputDbgView(FALSE),
m_bOutputConsole(FALSE), m_bConsoleOpened(FALSE), m_bDbgviewOpened(FALSE), m_bOutputConsole(FALSE), m_bConsoleOpened(FALSE), m_bDbgviewOpened(FALSE),
m_bLogFileOpened(FALSE), m_bRunning(TRUE){ m_bLogFileOpened(FALSE), m_bRunning(TRUE)
{
QueryPerformanceFrequency(&freq); QueryPerformanceFrequency(&freq);
//OutputDebugString(_T("The frequency of your pc is 0x%X.\n"), freq.QuadPart); //OutputDebugString(_T("The frequency of your pc is 0x%X.\n"), freq.QuadPart);
QueryPerformanceCounter(&start_t); QueryPerformanceCounter(&start_t);
memset(g_szFileName, 0, sizeof(g_szFileName)); memset(g_szFileName, 0, sizeof(g_szFileName));
TCHAR out[128] = {0}; TCHAR out[128] = { 0 };
wsprintf(out, _T("CLog construction addr: %p\n"), this); wsprintf(out, _T("CLog construction addr: %p\n"), this);
OutputDebugString(out); OutputDebugString(out);
memset(&pi, 0, sizeof(pi)); memset(&pi, 0, sizeof(pi));
InitializeCriticalSection(&m_cs); InitializeCriticalSection(&m_cs);
} }
LPCTSTR GetAppRunTime() { LPCTSTR GetAppRunTime()
{
static TCHAR szTime[128]; static TCHAR szTime[128];
memset(szTime, 0, sizeof szTime); memset(szTime, 0, sizeof szTime);
QueryPerformanceCounter(&stop_t); QueryPerformanceCounter(&stop_t);
exe_time = 1e3*(stop_t.QuadPart-start_t.QuadPart)/freq.QuadPart; exe_time = 1e3*(stop_t.QuadPart - start_t.QuadPart) / freq.QuadPart;
WORD day, hour, min, sec; WORD day, hour, min, sec;
sec = static_cast<unsigned short>(static_cast<unsigned long>(exe_time / 1000) % 60); sec = static_cast<unsigned short>(static_cast<unsigned long>(exe_time / 1000) % 60);
...@@ -334,13 +343,14 @@ protected: ...@@ -334,13 +343,14 @@ protected:
hour = static_cast<unsigned short>((exe_time / 1000 / 60) / 60); hour = static_cast<unsigned short>((exe_time / 1000 / 60) / 60);
day = static_cast<unsigned short>(exe_time / 1000.0 / 60.0 / 60.0 / 24); day = static_cast<unsigned short>(exe_time / 1000.0 / 60.0 / 60.0 / 24);
double ms = exe_time - (int)(exe_time) + ((int)(exe_time) % 1000); double ms = exe_time - (int)(exe_time)+((int)(exe_time) % 1000);
wsprintf(szTime, _T("%dday%02d:%02d:%02ds.%3.6fms"), day, hour, min, sec, ms); wsprintf(szTime, _T("%dday%02d:%02d:%02ds.%3.6fms"), day, hour, min, sec, ms);
return szTime; return szTime;
} }
void Output(const TCHAR *out) { void Output(const TCHAR *out)
if(m_bOutputLogFile){ {
if (m_bOutputLogFile) {
OutputFile(out); OutputFile(out);
} }
#ifdef _DEBUG #ifdef _DEBUG
...@@ -350,7 +360,7 @@ protected: ...@@ -350,7 +360,7 @@ protected:
OutputDebugString(out); OutputDebugString(out);
} }
#endif #endif
if(m_bOutputConsole){ if (m_bOutputConsole) {
_tprintf(out); _tprintf(out);
} }
} }
...@@ -365,30 +375,31 @@ protected: ...@@ -365,30 +375,31 @@ protected:
st.wYear, st.wMonth, st.wDay, (st.wDayOfWeek != 0) ? st.wDayOfWeek : 7, st.wYear, st.wMonth, st.wDay, (st.wDayOfWeek != 0) ? st.wDayOfWeek : 7,
st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
lstrcpy(newBuf, sztime); lstrcpy(newBuf, sztime);
if(static_cast<DWORD>(lstrlen(sztime) + lstrlen(oldBuf)) < max_new_buff_len){ if (static_cast<DWORD>(lstrlen(sztime) + lstrlen(oldBuf)) < max_new_buff_len) {
lstrcat(newBuf, oldBuf); lstrcat(newBuf, oldBuf);
} }
return static_cast<DWORD>(lstrlen(newBuf)); return static_cast<DWORD>(lstrlen(newBuf));
} }
void OutputFile(const TCHAR *buf){ void OutputFile(const TCHAR *buf)
if(m_pLogFile == NULL) {
if (m_pLogFile == NULL)
m_pLogFile = OpenLogFile(); m_pLogFile = OpenLogFile();
if(m_pLogFile != NULL){ if (m_pLogFile != NULL) {
fseek(m_pLogFile, 0, SEEK_END); fseek(m_pLogFile, 0, SEEK_END);
long filelen = ftell(m_pLogFile); long filelen = ftell(m_pLogFile);
if(filelen >= MAX_FILE_LEN){ if (filelen >= MAX_FILE_LEN) {
fclose(m_pLogFile); fclose(m_pLogFile);
CreateFileName(); CreateFileName();
m_pLogFile = OpenLogFile(); m_pLogFile = OpenLogFile();
} }
} }
if(m_pLogFile != NULL){ if (m_pLogFile != NULL) {
fseek(m_pLogFile, 0, SEEK_END); fseek(m_pLogFile, 0, SEEK_END);
#if defined(_UNICODE) || defined(UNICODE) #if defined(_UNICODE) || defined(UNICODE)
if(Utf16ToAnsiUseCharArray(buf, m_ansiBuf, MAX_OUTPUT_LEN)){ if (Utf16ToAnsiUseCharArray(buf, m_ansiBuf, MAX_OUTPUT_LEN)) {
fwrite(m_ansiBuf, 1, strlen(m_ansiBuf), m_pLogFile); fwrite(m_ansiBuf, 1, strlen(m_ansiBuf), m_pLogFile);
}else{ } else {
char *ansiOut = Utf16ToAnsi(buf); char *ansiOut = Utf16ToAnsi(buf);
fwrite(ansiOut, 1, strlen(ansiOut), m_pLogFile); fwrite(ansiOut, 1, strlen(ansiOut), m_pLogFile);
SAFEDELETEARR(ansiOut); SAFEDELETEARR(ansiOut);
...@@ -400,20 +411,21 @@ protected: ...@@ -400,20 +411,21 @@ protected:
} }
} }
BOOL OpenDbgview(BOOL bOpen){ BOOL OpenDbgview(BOOL bOpen)
{
static STARTUPINFO si; static STARTUPINFO si;
static LPCTSTR lpszAppName = _T("dbgview.exe"); static LPCTSTR lpszAppName = _T("dbgview.exe");
if(bOpen){ if (bOpen) {
if(!m_bDbgviewOpened){ if (!m_bDbgviewOpened) {
memset(&si,0,sizeof(STARTUPINFO)); memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO); si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW; si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW; si.wShowWindow = SW_SHOW;
if(CreateProcess(lpszAppName,NULL,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) { if (CreateProcess(lpszAppName, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
m_bDbgviewOpened = TRUE; m_bDbgviewOpened = TRUE;
} }
} }
}else if(m_bDbgviewOpened){ } else if (m_bDbgviewOpened) {
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
m_bDbgviewOpened = FALSE; m_bDbgviewOpened = FALSE;
...@@ -422,31 +434,33 @@ protected: ...@@ -422,31 +434,33 @@ protected:
return bOpen ? m_bDbgviewOpened : !m_bDbgviewOpened; return bOpen ? m_bDbgviewOpened : !m_bDbgviewOpened;
} }
FILE* OpenLogFile(){ FILE* OpenLogFile()
{
FILE *pfile = NULL; FILE *pfile = NULL;
_tfopen_s(&pfile, g_szFileName, _T("r")); _tfopen_s(&pfile, g_szFileName, _T("r"));
if(pfile == NULL){ if (pfile == NULL) {
_tfopen_s(&pfile, g_szFileName, _T("wb")); _tfopen_s(&pfile, g_szFileName, _T("wb"));
if(pfile == NULL){ if (pfile == NULL) {
MessageBox(NULL, _T("Create log file failed."), NULL, 0); MessageBox(NULL, _T("Create log file failed."), NULL, 0);
ASSERT(0); ASSERT(0);
return NULL; return NULL;
} }
}else{ } else {
fclose(pfile); fclose(pfile);
_tfopen_s(&pfile, g_szFileName, _T("ab")); _tfopen_s(&pfile, g_szFileName, _T("ab"));
if(pfile == NULL){ if (pfile == NULL) {
MessageBox(NULL, _T("Open log file failed."), NULL, 0); MessageBox(NULL, _T("Open log file failed."), NULL, 0);
ASSERT(0); ASSERT(0);
return NULL; return NULL;
} }
} }
if(pfile != NULL) if (pfile != NULL)
m_bLogFileOpened = TRUE; m_bLogFileOpened = TRUE;
return pfile; return pfile;
} }
void CreateFileName(){ void CreateFileName()
{
SYSTEMTIME st; SYSTEMTIME st;
GetLocalTime(&st); GetLocalTime(&st);
const wchar_t* path = GetPrivateLogPath(); const wchar_t* path = GetPrivateLogPath();
...@@ -461,19 +475,21 @@ protected: ...@@ -461,19 +475,21 @@ protected:
lstrcat(g_szFileName, _T(".log")); lstrcat(g_szFileName, _T(".log"));
} }
void CloseLogFile(){ void CloseLogFile()
if(m_pLogFile != NULL){ {
if (m_pLogFile != NULL) {
fflush(m_pLogFile); fflush(m_pLogFile);
fclose(m_pLogFile); fclose(m_pLogFile);
m_pLogFile = NULL; m_pLogFile = NULL;
} }
} }
BOOL OpenConsole(BOOL bOpen){ BOOL OpenConsole(BOOL bOpen)
{
static FILE *pConsole = NULL; static FILE *pConsole = NULL;
if(bOpen){ if (bOpen) {
if(!m_bConsoleOpened){ if (!m_bConsoleOpened) {
if(AllocConsole()){ if (AllocConsole()) {
SetConsoleTitle(_T("output")); SetConsoleTitle(_T("output"));
/*COORD coord; /*COORD coord;
coord.X = 120; coord.X = 120;
...@@ -494,10 +510,10 @@ protected: ...@@ -494,10 +510,10 @@ protected:
} }
} }
return m_bConsoleOpened; return m_bConsoleOpened;
}else{ } else {
if(m_bConsoleOpened){ if (m_bConsoleOpened) {
fclose(pConsole); fclose(pConsole);
if(FreeConsole()){ if (FreeConsole()) {
m_bConsoleOpened = FALSE; m_bConsoleOpened = FALSE;
} }
} }
...@@ -505,11 +521,13 @@ protected: ...@@ -505,11 +521,13 @@ protected:
} }
} }
LPCTSTR GetLastTimeLogFileName(){ LPCTSTR GetLastTimeLogFileName()
{
return g_szFileName; return g_szFileName;
} }
}; };
};
//CRITICAL_SECTION CLog::m_cs; //CRITICAL_SECTION CLog::m_cs;
//int CLog::m_nRef = 0; //int CLog::m_nRef = 0;
//char CLog::m_ansiBuf[MAX_OUTPUT_LEN] = {0}; //char CLog::m_ansiBuf[MAX_OUTPUT_LEN] = {0};
......
#pragma once #pragma once
namespace jlib
inline wchar_t* FormatWSAError(int errornumber)
{ {
inline wchar_t* FormatWSAError(int errornumber)
{
switch (errornumber) { switch (errornumber) {
case WSANOTINITIALISED: case WSANOTINITIALISED:
return L"A successful WSAStartup call must occur before using this function. "; return L"A successful WSAStartup call must occur before using this function. ";
...@@ -78,4 +79,6 @@ inline wchar_t* FormatWSAError(int errornumber) ...@@ -78,4 +79,6 @@ inline wchar_t* FormatWSAError(int errornumber)
return buf; return buf;
}break; }break;
} }
} }
\ No newline at end of file
};
...@@ -6,26 +6,27 @@ ...@@ -6,26 +6,27 @@
#include "mtverify.h" #include "mtverify.h"
#include "FileOper.h" #include "FileOper.h"
#include "Log.h" #include "Log.h"
#define LOG CLog::WriteLog #include "MyWSAError.h"
#define LOGA CLog::WriteLogA #include "observer_macro.h"
#define LOGW CLog::WriteLogW
#define LOGB(b, l) CLog::Dump(b, l) namespace jlib {
#define LOGASC(b, l) CLog::DumpAsc(b, l) #define JLOG CLog::WriteLog
#define JLOGA CLog::WriteLogA
#define JLOGW CLog::WriteLogW
#define JLOGB(b, l) CLog::Dump(b, l)
#define JLOGASC(b, l) CLog::DumpAsc(b, l)
class LogFunction { class LogFunction {
private: private:
const char* _func_name; const char* _func_name;
public: public:
LogFunction(const char* func_name) : _func_name(func_name) { LOGA("%s in\n", _func_name); } LogFunction(const char* func_name) : _func_name(func_name) { JLOGA("%s in\n", _func_name); }
~LogFunction() { LOGA("%s out\n", _func_name); } ~LogFunction() { JLOGA("%s out\n", _func_name); }
}; };
#define LOG_FUNCTION(func_name) LogFunction _log_function_object(func_name); #define LOG_FUNCTION(func_name) LogFunction _log_function_object(func_name);
#define AUTO_LOG_FUNCTION LOG_FUNCTION(__FUNCTION__) #define AUTO_LOG_FUNCTION LOG_FUNCTION(__FUNCTION__)
#include "MyWSAError.h"
#include "observer_macro.h"
#define NAMESPACE_END }; #define NAMESPACE_END };
#define DECLARE_UNCOPYABLE(classname) \ #define DECLARE_UNCOPYABLE(classname) \
...@@ -105,3 +106,5 @@ public: \ ...@@ -105,3 +106,5 @@ public: \
#define INITIALIZE_STRING(val) { val = new wchar_t[1]; val[0] = 0; } #define INITIALIZE_STRING(val) { val = new wchar_t[1]; val[0] = 0; }
};
#pragma once
namespace jlib {
// place this macro in your class's header file, in your class's definition // place this macro in your class's header file, in your class's definition
#define DECLARE_OBSERVER(callback, param_type) \ #define DECLARE_OBSERVER(callback, param_type) \
protected: \ protected: \
...@@ -70,7 +72,7 @@ void class_name::NotifyObservers(_param_type param) \ ...@@ -70,7 +72,7 @@ void class_name::NotifyObservers(_param_type param) \
_observerList.clear(); \ _observerList.clear(); \
} }
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment