-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHTTPGetFilesThread.h
104 lines (92 loc) · 2.79 KB
/
HTTPGetFilesThread.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
//---------------------------------------------------------------------------
#ifndef HTTPGetFilesThreadH
#define HTTPGetFilesThreadH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <System.SyncObjs.hpp>
#include <Wininet.h>
//---------------------------------------------------------------------------
#define FILE_DESCR_ID_SIZE 2
struct tagFileDescr {
DWORD dwFileId[FILE_DESCR_ID_SIZE];
AnsiString asFileName;
};
struct tagFileList {
DWORD dwTaskId;
AnsiString asHost;
TList *pFiles;
};
struct tagReadyFile {
DWORD dwTaskId;
tagFileDescr sFileDescr;
DWORD dwErrorCode;
TMemoryStream *pData;
};
typedef tagFileDescr* PFileDescr;
typedef tagFileList* PFileList;
typedef tagReadyFile* PReadyFile;
enum eTaskStatus {tsReady, tsReqSent, tsFileReading, tsFileReady, tsComplete, tsError};
#define BUFFER_SIZE 65536
class Task {
public:
__fastcall Task(PFileList pFileList, HINTERNET hInternet);
__fastcall ~Task();
void __fastcall Touch();
__property bool Connected = { read=GetConnected };
__property DWORD Id = { read=GetId };
__property TList* ReadyFiles = { read=GetReadyFiles };
__property PReadyFile ReadyFile = { read=GetReadyFile };
__property bool Complete = { read=GetComplete };
__property bool FileReady = { read=GetFileReady };
protected:
eTaskStatus m_eStatus;
byte* m_pBuffer;
TList* m_pReadyFiles;
PReadyFile m_pCurrentFile;
DWORD m_dwCurrentFileLength;
DWORD m_dwWaitFor;
DWORD m_dwTimeout;
TMemoryStream* m_pStream;
DWORD m_dwId;
AnsiString m_asHost;
TList* m_pFiles;
HINTERNET m_hConnect;
HINTERNET m_hRequest;
private:
bool __fastcall GetConnected();
DWORD __fastcall GetId();
TList* __fastcall GetReadyFiles();
PReadyFile __fastcall GetReadyFile();
bool __fastcall GetComplete();
bool __fastcall GetFileReady();
};
typedef Task* PTask;
class THTTPGetFilesThread : public TThread
{
private:
PReadyFile __fastcall GetReadyFile();
bool __fastcall GetFileReady();
bool __fastcall GetComplete();
protected:
HINTERNET m_hInternet;
DWORD m_dwNewTaskId;
DWORD m_dwCurrentTaskId;
DWORD m_dwTaskToDelete;
PFileList m_pNewTask;
TList* m_pTaskList;
TThreadList *m_pReadyTasks;
TSimpleEvent *m_pNewTaskEvent;
TSimpleEvent *m_pFileReadyEvent;
TSimpleEvent *m_pDeleteTaskEvent;
void __fastcall Execute();
public:
__fastcall THTTPGetFilesThread(bool CreateSuspended);
__fastcall ~THTTPGetFilesThread();
DWORD __fastcall AddTask(PFileList pFiles);
bool __fastcall DeleteTask(DWORD deTaskId);
__property PReadyFile ReadyFile = { read=GetReadyFile };
__property bool FileReady = { read=GetFileReady };
__property bool Complete = { read=GetComplete };
};
//---------------------------------------------------------------------------
#endif