12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include "stdafx.h"
- #include "QueueStrManager.h"
- #include <stdio.h>
- #include <windows.h>
- #include <cstdio>
- #include <process.h>
- #include "ProcessRemodule.h"
- #include "./system_basic_info/SystemAnalysis.h"
- #pragma warning(disable: 4996)
- QueueStrManager::QueueStrManager(void)
- {
- m_pfunc = NULL;
- InitializeCriticalSectionAndSpinCount(&m_csQueueList, MAXCRITICALSECTIONSPINCOUNT);
- }
- QueueStrManager::~QueueStrManager(void)
- {
- DeleteCriticalSection(&m_csQueueList);
- delete[] m_chr;
- m_chr = NULL;
- m_pfunc = NULL;
- }
- void QueueStrManager::AddString(const char * chr)
- {
- LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_100);
- EnterCriticalSection(&m_csQueueList);
- int vlen = strlen(chr);
- if(m_couter + 1 > m_max_couter || m_length + vlen + 1 > m_max_length){
- LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_105);
- if(m_pfunc == NULL){
- LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_106);
- LeaveCriticalSection(&m_csQueueList);
- return;
- }
- try
- {
- char* pchr = new char[m_max_length];
- strcpy(pchr, m_chr);
- //QueueUserWorkItem(m_pfunc, (LPVOID)pchr, WT_EXECUTEDEFAULT);
- LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_101);
- send_sql_message(pchr);
- memset(m_chr, 0, m_max_length);
-
- strcpy(m_chr, chr);
- m_couter = 1;
- m_length = strlen(chr);
- }
- catch(...){
- }
- }else {
- if(m_couter == 0){
- strcpy(m_chr, chr);
- }else {
- strcat(m_chr, chr);
- }
- m_couter++;
- m_length += strlen(chr);
- //TRACE(_T("sql counts: %d \r\n"),m_couter);
- }
- LeaveCriticalSection(&m_csQueueList);
- }
- void QueueStrManager::Execute()
- {
- LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_103);
- EnterCriticalSection(&m_csQueueList);
- if(m_length > 0){
- LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_107);
- if(m_pfunc == NULL){
- LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_108);
- LeaveCriticalSection(&m_csQueueList);
- return;
- }
- try
- {
- char* pchr = new char[m_length + 2]; // Ô¤Áô½áÊø·û
- strcpy(pchr, m_chr);
- //QueueUserWorkItem(m_pfunc, (LPVOID)pchr, WT_EXECUTEDEFAULT);
- LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_104);
- send_sql_message(pchr);
- }
- catch(...){
- }
- }
- LeaveCriticalSection(&m_csQueueList);
- }
|