mrDarker
2025-07-16 1dbe46cd9d0f181d08d5a69f72d8548628a13b9d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// ProcPADThread.cpp : implementation file
//
 
#include "StdAfx.h"
#include "Thread_Send.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 
/////////////////////////////////////////////////////////////////////////////
// CThread_SendMSG
CThread_SendMSG::CThread_SendMSG(DWORD dwPeriod) : CTimerThreadPool(dwPeriod,1)
{
    m_pS2M = NULL;
}
 
CThread_SendMSG::~CThread_SendMSG()
{
    ClearMSG();
}
 
BOOL CThread_SendMSG::CreateThread()
{
    BOOL bReturn = TRUE;
 
    // Thread 积己 饶 Thread 荐青
    bReturn = CreateTimerThread(this);
 
    return bReturn;
}
 
void CThread_SendMSG::TimerThreadProcess(PVOID pParameter)
{
    CThread_SendMSG* pSendThread = static_cast<CThread_SendMSG*>(pParameter);
    if(pSendThread == NULL)
        return;
 
    if(pSendThread->m_pS2M == NULL)
    {
        return;
    }
 
    std::vector<CPostSendMessage>    *pVecNetMSG;
    std::vector<CPostSendMessage>    vecMSG;
    std::vector<CPostSendMessage>::iterator    it;
 
    std::vector<CDisableSendMessage>    *pVecDisableMSG;
    std::vector<CDisableSendMessage>    vecDisableMSG;    
    std::vector<CDisableSendMessage>::iterator    itDis;
 
    CPostSendMessage        SendNetMSG;
    CDisableSendMessage        DisableMSG;
 
    CSingleLock MyLock(&pSendThread->m_csNetMSG);
    MyLock.Lock();
 
    pVecNetMSG = pSendThread->GetVecSendMSG();
    if(pVecNetMSG->empty() == FALSE)
    {    
        vecMSG.resize(pVecNetMSG->size());
        std::copy(pVecNetMSG->begin(),pVecNetMSG->end(),vecMSG.begin());
        pVecNetMSG->clear();            
    }
    
    MyLock.Unlock();
    Sleep(0);
        
    CSingleLock MyUnLock(&pSendThread->m_csDisableMSG);
    MyUnLock.Lock();
    pVecDisableMSG = pSendThread->GetVecDisableMSG();
    if(pVecDisableMSG->empty() == FALSE)
    {    
        vecDisableMSG.resize(pVecDisableMSG->size());
        std::copy(pVecDisableMSG->begin(),pVecDisableMSG->end(),vecDisableMSG.begin());
        pVecDisableMSG->clear();                    
    }
    MyUnLock.Unlock();
    Sleep(0);
 
    for(it=vecMSG.begin();it!=vecMSG.end();it++)
    {
        SendNetMSG = *it;
 
        pSendThread->m_pS2M->SendMSG_Received(&SendNetMSG);
    }
    vecMSG.clear();
 
    Sleep(0);
 
    DWORD        dwTick;
    for(itDis=vecDisableMSG.begin();itDis!=vecDisableMSG.end();itDis++)
    {
        DisableMSG = *itDis;
        if(DisableMSG.dwStart <= 0 || DisableMSG.dwOntime <= 0)
            continue;
 
        dwTick = GetTickCount()-DisableMSG.dwStart;
 
        if(dwTick >= DisableMSG.dwOntime)
        {
            DisableMSG.nValue = 0;
            pSendThread->m_pS2M->SendMSG_Received(&DisableMSG);
        }
        else
        {
            CSingleLock MyUnLock(&pSendThread->m_csDisableMSG);
            MyUnLock.Lock();
            pSendThread->m_VecDisableMSG.push_back(DisableMSG);
            MyUnLock.Unlock();
        }
    }
    vecDisableMSG.clear();    
}
 
int    CThread_SendMSG::AddDisableMSG(SEND_MESSAGE_SECTION emSection,int nSignal, int nValue, DWORD dwOntime)
{
    CDisableSendMessage        DisableMsg;    
 
    DisableMsg.emSection = emSection;    
    DisableMsg.nSignal = nSignal;
    DisableMsg.nValue = nValue;    
    DisableMsg.dwOntime = dwOntime;
    DisableMsg.dwStart = GetTickCount();
 
    CSingleLock MyLock(&m_csDisableMSG);
    MyLock.Lock();
 
    m_VecDisableMSG.push_back(DisableMsg);
    int nCount = (int)m_VecDisableMSG.size();
 
    MyLock.Unlock();
 
    return nCount;
}
 
int    CThread_SendMSG::AddSendMSG(SEND_MESSAGE_SECTION emSection,int nSignal, int nValue)
{
    CPostSendMessage netMessage;    
 
    netMessage.emSection = emSection;    
    netMessage.nSignal = nSignal;
    netMessage.nValue = nValue;    
 
    CSingleLock MyLock(&m_csNetMSG);
    MyLock.Lock();
 
    m_VecSendMSG.push_back(netMessage);
    int nCount = (int)m_VecSendMSG.size();
 
    MyLock.Unlock();
 
    return nCount;
}
 
BOOL CThread_SendMSG::ClearMSG()
{
    CSingleLock MyLock(&m_csNetMSG);
    MyLock.Lock();
 
    m_VecSendMSG.clear();
 
    MyLock.Unlock();
 
    CSingleLock MyUnLock(&m_csDisableMSG);
    MyUnLock.Lock();
 
    m_VecDisableMSG.clear();
 
    MyUnLock.Unlock();
 
    return TRUE;
}