使用soui开发的mbc,只支持windows版本
w1146869587
2022-01-24 4905e2e7537d507f218e8e9595485e09d9f3a2b4
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
176
177
178
179
180
#include "StdAfx.h"
#include "MBThreadDownloadDisk.h"
#include "MBTransExtendEvents.h"
 
CMBThreadDownloadDisk::CMBThreadDownloadDisk(void)
{
    m_bStop = false;
    m_pTaskLoopMgr = NULL;
    m_pTransMgr = NULL;
    m_pSvrMgr  = NULL;
    m_nDownloadQueueSize = 4;  
}
 
 
 
 
CMBThreadDownloadDisk::~CMBThreadDownloadDisk(void)
{
}
 
 
// ¿ªÊ¼Ïß³Ì
void CMBThreadDownloadDisk::StartThread()
{  
    if(IsRunning()) 
        return;
 
    BeginThread();    
}
 
// ½áÊøÏß³Ì
void CMBThreadDownloadDisk::OverThread()
{
    m_bStop = true;
 
    CMBDownloadQueue  *pDownloadQueue =  m_pTransMgr->GetDownloadQueue();             // ÏÂÔØ¶ÓÁÐ
    if( pDownloadQueue != NULL )
    { 
        pDownloadQueue->SetEventShutdownSet();
    }
 
    if(!IsRunning()) 
        return;
 
    EndThread();
}
 
void CMBThreadDownloadDisk::SetTransMgr(CMBTransMgr *pTransMgr)
{
    m_pTransMgr = pTransMgr;
}
 
void CMBThreadDownloadDisk::SetSvrMgr( CMBServerMgr *pSvrMgr)
{
    m_pSvrMgr = pSvrMgr;    
}
 
void CMBThreadDownloadDisk::SetTaskLoopMgr(CMBTaskLoopMgr *pTaskLoopMgr)
{
    m_pTaskLoopMgr = pTaskLoopMgr;
}
 
 
UINT CMBThreadDownloadDisk::Run()
    CMBDownloadQueue  *pDownloadQueue =  m_pTransMgr->GetDownloadQueue();             // ÏÂÔØ¶ÓÁÐ
    if( pDownloadQueue == NULL )
        return 0;
    
    HANDLE            handlesToWaitFor[2];
    DWORD            dwResult;
    handlesToWaitFor[0]        = pDownloadQueue->GetEventExeHandle(); 
    handlesToWaitFor[1]        = pDownloadQueue->GetEventShutdownHandle();
 
    pDownloadQueue->SetEventExeSet();
 
    while ( true )
    {
#ifdef _DEBUG
        dwResult    = ::WaitForMultipleObjects( 2, handlesToWaitFor, false, 6000 );    
#else
        dwResult    = ::WaitForMultipleObjects( 2, handlesToWaitFor, false, 300000 );
#endif                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
        if ( dwResult == WAIT_OBJECT_0 )
        {      
            if( m_bStop )
                break;
            // Î´³õʼ»¯²»ÈÃÆäÏÂÔØ
            if(m_pSvrMgr->GetFileSvrClientMgr()->IsInit())
            {
                // ÏÂÔØ     
                while(TRUE){
                    Sleep(1000);
                    TransTimerDownload(pDownloadQueue,m_bStop );
                    if(  pDownloadQueue->GetWaitingUserCount() == 0)
                        break;
                    if(m_bStop)
                        break;
                }   
                pDownloadQueue->SetEventExeReset();
            }  
        }
        else if ( dwResult == WAIT_OBJECT_0 + 1 )
        {
            // Time to shutdown
            break;
        } 
        else if ( dwResult == WAIT_TIMEOUT )
        {
             pDownloadQueue->SetEventExeSet();
        }    
    } // End of while ( true )  
 
    return 0;
}
 
 
// ´«Êä
bool CMBThreadDownloadDisk::TransTimerDownload(CMBDownloadQueue  *pDownloadQueue ,BOOL &bThreadStop)
{    
    CString strErrInfo; 
    if(!m_pTransMgr->ReDownloadToWaitingList(bThreadStop,strErrInfo ))
    {
        return false;
    } 
 
    if(!pDownloadQueue->RemoveUnUseFromDownloadQueue( bThreadStop ))
    {
        return false;
    }  
    if(!pDownloadQueue->RemoveFinishFromWaitingQueue( bThreadStop ))
    {
        return false;
    } 
    if(!pDownloadQueue->ReDownloadQueue( m_nDownloadQueueSize,bThreadStop ))
    {
        return false;
    } 
    //////////////////////ÏÂÔØ///////////////////////////////
    CDownClientAutoPtrList listDownloading;
    pDownloadQueue->CopyDownloadingQueue( listDownloading );
 
    CDownClientAutoPtrList::iterator it;
    CAutoRefPtr<CMBDownloadFileInfo>  curClient = NULL;
 
    for( it = listDownloading.begin();it != listDownloading.end();it++ )
    {
        if(bThreadStop)
            return false;
        curClient = *it;   
        if (curClient->GetStatus() == CMBDownloadFileInfo::Status_OnDownQueue)  
        {
            curClient->SetStatus(CMBDownloadFileInfo::Status_CalledDownServer); 
            
            if(curClient->m_strFrom.CompareNoCase(FCTN_AM) == 0)
            {
                EventAMDownloadFile *pEvt = new EventAMDownloadFile(NULL); 
                curClient.CopyTo(&pEvt->m_pDownloadFileInfo);
                SNotifyCenter::getSingleton().FireEventAsync(pEvt);
                pEvt->Release();
            }
            else
            {
                EventDownloadFile *pEvt = new EventDownloadFile(NULL); 
                curClient.CopyTo(&pEvt->m_pDownloadFileInfo);
                SNotifyCenter::getSingleton().FireEventAsync(pEvt);
                pEvt->Release();
            }
 
            break;
        }
    }   
     
    listDownloading.clear();
 
    return true;
}