#include "stdafx.h" #include "ProcessRemodule.h" #include #include #include #include "log_process_module.h" #include "./system_basic_info/SystemAnalysis.h" using namespace std; //#include //#include //#include #define BUF_SIZE 5001 #define REAL_BUF BUF_SIZE-1 ParseData* gBuf = NULL; unsigned int gBufFlag[BUF_SIZE] = {0}; HANDLE gBufMutex; HANDLE hThread[MSG_PROCESS_THREAD_NUM]; unsigned nThreadID[MSG_PROCESS_THREAD_NUM]; HANDLE hSqlThread[SQL_PROCESS_THREAD_NUM]; unsigned nSqlThreadID[SQL_PROCESS_THREAD_NUM]; HANDLE hErrLogThread[ERR_LOG_PROCESS_THREAD_NUM]; unsigned nErrLogThreadID[ERR_LOG_PROCESS_THREAD_NUM]; HANDLE hSysLogThread[SYS_LOG_PROCESS_THREAD_NUM]; unsigned nSysLogThreadID[SYS_LOG_PROCESS_THREAD_NUM]; BufferUtility* BufferUtility::instance = NULL; BufferUtility* BufferUtility::getInstance() { if (instance == NULL) { if (instance == NULL) { instance = new BufferUtility; } } return instance; } int BufferUtility::init() { gBuf = (ParseData *)malloc(sizeof(ParseData) * BUF_SIZE); memset(gBuf, 0, sizeof(ParseData) * BUF_SIZE); memset(gBufFlag, 0, sizeof(gBufFlag)); gBufMutex =CreateMutex(NULL, FALSE, NULL); return 0; } ParseData* BufferUtility::getItem() { int i = 0; WaitForSingleObject(gBufMutex,INFINITE); for(i=0; iinit(); //初始化消息处理线程 int i = 0; for(i=0; i(data->handle); //#ifdef TRACE_MEMORY_PARSE_PACKAGE try { dlg->parse_package_data(data->buf, data->len, data->dwConnID); } catch(exception e) { } //#endif // TRACE_MEMORY_PARSE_PACKAGE BufferUtility::getInstance()->releaseItem(data); break; #else //printf("current thread id: %d, receive tcp msg:%d\n", GetCurrentThreadId(), data->a); BufferUtility::getInstance()->releaseItem(data); #endif } } } return 0; } int send_tcp_thread_message(ParseData* data) { //send thread message LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_91); unsigned thread_id = rand() % MSG_PROCESS_THREAD_NUM; if(!PostThreadMessage(nThreadID[thread_id], TCP_MSG, (WPARAM)data, 0))//post thread msg { LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_31); debug_print_syslog(0, "post tcp message failed,errno:%d\n",::GetLastError()); BufferUtility::getInstance()->releaseItem(data); return 1; } return 0; } int sql_process_thread_init() { int i = 0; for(i=0; iinit(); message_process_thread_init(); sql_process_thread_init(); err_log_process_thread_init(); sys_log_process_thread_init(); ::Sleep(1000); return 0; } int send_sys_log_message(char* pchr) { //send thread message if(!m_log_sys_status) { return 0; } unsigned thread_id = rand() % SYS_LOG_PROCESS_THREAD_NUM; if(!PostThreadMessage(nSysLogThreadID[thread_id], SYS_LOG_MSG, (WPARAM)pchr, 0))//post thread msg { LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_34); delete[] pchr; return 1; } return 0; } int debug_print_syslog(UINT debugLevel, const char* format, ...) { char *buffer = new char[LOG_BUF_SIZE]; memset(buffer, 0, LOG_BUF_SIZE); va_list args; va_start (args, format); vsnprintf_s(buffer, LOG_BUF_SIZE, LOG_BUF_SIZE-1, format, args); va_end (args); send_sys_log_message(buffer); return 0; }