-
Notifications
You must be signed in to change notification settings - Fork 12
/
DownloadScheduler.h
108 lines (91 loc) · 3.45 KB
/
DownloadScheduler.h
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
#if !defined(AFX_DOWNLOADSCHUDLER_H__DEA6AD06_1FFE_4CD2_B6B5_13183FB73E97__INCLUDED_)
#define AFX_DOWNLOADSCHUDLER_H__DEA6AD06_1FFE_4CD2_B6B5_13183FB73E97__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DownloadSchudler.h : header file
//
#include <Winsock2.h>
class CMainFrame;
class CDownloadItemManager;
class CDownloadJet;
class CTreeItem;
class CListItem;
/////////////////////////////////////////////////////////////////////////////
// CDownloadScheduler window
#define WM_USER_ASYNC_SOCKET_MSG WM_USER + 301
class CDownloadScheduler : public CWnd
{
// Construction
public:
CDownloadScheduler();
DECLARE_DYNCREATE(CDownloadScheduler)
~CDownloadScheduler();
// Attributes
public:
protected:
//管理ListItem和DownloadManager的关系
CMap <CListItem *, CListItem *, CDownloadItemManager *, CDownloadItemManager *> m_mapDownloadItemMNGs;
//管理DownloadItemManager和DownloadJet(实际上是socket)的关系,
CMap <CDownloadJet *, CDownloadJet *, CDownloadItemManager *, CDownloadItemManager *> m_mapDownloadJets;
//管理DownloadJet及其注册时间
CMap <CDownloadJet *, CDownloadJet *, DWORD, DWORD> m_mapJetRegestedTimeout;
CTreeItem *m_pTreeItem;
HWND m_hMainWnd;
private:
int m_iCountOfLastDownloadData;
//For Get last download data count;
CCriticalSection m_crtsectCanGetDataCount;
CSingleLock m_slockCanGetDataCount;
enum TimerID {ID_SchedulerTimer, ID_1sTimer};
enum {SchedulerTimerSlot = 100};
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDownloadScheduler)
//afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_VIRTUAL
// Implementation
public:
void SetNotifyWnd(HWND hNotifyWnd);
//virtual LRESULT WindowProc( UINT message, WPARAM wParam, LPARAM lParam );
void RemoveDownloadEntry(CDownloadJet *pJet, CDownloadItemManager *pMNG);
void UnregisterTimeout(CDownloadJet *pJet);
void RegisterTimeout(CDownloadJet *pJet, DWORD dwTimeout);
BOOL AddDownloadEntry(CDownloadItemManager *pMNG, CDownloadJet *pJet, SOCKET socket);
void StopDownload();
void StartDownload();
void RefreshMainframe(CListItem *pListItem, UINT uiState = 0);
void SetDownloadTreeItem(CTreeItem *pTreeItem);
void Quit();
void MoveCompletedItem(CListItem *pListItem);
void IncLastDownloadDataCounter(int iInc);
// Generated message map functions
protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//{{AFX_MSG(CDownloadScheduler)
// NOTE - the ClassWizard will add and remove member functions here.
afx_msg void OnTimer(UINT nIDEvent);
afx_msg LRESULT OnAsyncSocketMsg(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnDownloadItemMsg(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
void prv_CheckTimeout();
int prv_GetLastDownloadDataCount();
void prv_ClearLastDownloadDataCounter();
void prv_NeedPauseDownloadingItems();
void prv_CheckScheduledItem();
void prv_StartDownloadReadyItems();
BOOL prv_IsItemInDownloadList(CListItem *pListItem);
void prv_StartDownload(CListItem *pListItem);
void prv_DoSchedule();
void prv_StopDownload(CListItem *pListItem);
BOOL prv_IsValidateDownloadEntry(CDownloadItemManager *pMNG);
void prv_RemoveDownloadEntry(CDownloadItemManager *pMNG);
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DOWNLOADSCHUDLER_H__DEA6AD06_1FFE_4CD2_B6B5_13183FB73E97__INCLUDED_)