QueueStrManager.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "stdafx.h"
  2. #include "QueueStrManager.h"
  3. #include <stdio.h>
  4. #include <windows.h>
  5. #include <cstdio>
  6. #include <process.h>
  7. #include "ProcessRemodule.h"
  8. #include "./system_basic_info/SystemAnalysis.h"
  9. #pragma warning(disable: 4996)
  10. QueueStrManager::QueueStrManager(void)
  11. {
  12. m_pfunc = NULL;
  13. InitializeCriticalSectionAndSpinCount(&m_csQueueList, MAXCRITICALSECTIONSPINCOUNT);
  14. }
  15. QueueStrManager::~QueueStrManager(void)
  16. {
  17. DeleteCriticalSection(&m_csQueueList);
  18. delete[] m_chr;
  19. m_chr = NULL;
  20. m_pfunc = NULL;
  21. }
  22. void QueueStrManager::AddString(const char * chr)
  23. {
  24. LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_100);
  25. EnterCriticalSection(&m_csQueueList);
  26. int vlen = strlen(chr);
  27. if(m_couter + 1 > m_max_couter || m_length + vlen + 1 > m_max_length){
  28. LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_105);
  29. if(m_pfunc == NULL){
  30. LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_106);
  31. LeaveCriticalSection(&m_csQueueList);
  32. return;
  33. }
  34. try
  35. {
  36. char* pchr = new char[m_max_length];
  37. strcpy(pchr, m_chr);
  38. //QueueUserWorkItem(m_pfunc, (LPVOID)pchr, WT_EXECUTEDEFAULT);
  39. LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_101);
  40. send_sql_message(pchr);
  41. memset(m_chr, 0, m_max_length);
  42. strcpy(m_chr, chr);
  43. m_couter = 1;
  44. m_length = strlen(chr);
  45. }
  46. catch(...){
  47. }
  48. }else {
  49. if(m_couter == 0){
  50. strcpy(m_chr, chr);
  51. }else {
  52. strcat(m_chr, chr);
  53. }
  54. m_couter++;
  55. m_length += strlen(chr);
  56. //TRACE(_T("sql counts: %d \r\n"),m_couter);
  57. }
  58. LeaveCriticalSection(&m_csQueueList);
  59. }
  60. void QueueStrManager::Execute()
  61. {
  62. LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_103);
  63. EnterCriticalSection(&m_csQueueList);
  64. if(m_length > 0){
  65. LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_107);
  66. if(m_pfunc == NULL){
  67. LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_108);
  68. LeaveCriticalSection(&m_csQueueList);
  69. return;
  70. }
  71. try
  72. {
  73. char* pchr = new char[m_length + 2]; // Ô¤Áô½áÊø·û
  74. strcpy(pchr, m_chr);
  75. //QueueUserWorkItem(m_pfunc, (LPVOID)pchr, WT_EXECUTEDEFAULT);
  76. LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_104);
  77. send_sql_message(pchr);
  78. }
  79. catch(...){
  80. }
  81. }
  82. LeaveCriticalSection(&m_csQueueList);
  83. }