-
Notifications
You must be signed in to change notification settings - Fork 1
/
PieceQueue.h
106 lines (81 loc) · 1.89 KB
/
PieceQueue.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
#ifndef __PIECEQUEUE_H
#define __PIECEQUEUE_H
#include <wx/wx.h>
#include <wx/datetime.h>
#include "_wxconfig.h"
#include <vector>
#include "Message.h"
namespace RAIN
{
class ManifestEntry;
enum QueuedPieceDirection
{
QUEUE_DIR_REQUESTING,
QUEUE_DIR_DISTRIBUTING
};
enum QueueState
{
QUEUE_RUNNING,
QUEUE_STOPPED,
QUEUE_PAUSED,
};
class QueuedPiece
{
public:
wxString hash;
size_t pieceSize;
QueuedPieceDirection direction;
wxString target, status;
bool heldBack;
};
enum WaitingFor
{
WAITFOR_PEERCONNECT,
WAITFOR_PIECESEARCH
};
class QueueWait
{
public:
QueueWait(WaitingFor w, const wxString& phash, const wxString& hash);
WaitingFor wait;
wxDateTime start;
wxString pieceHash, hash;
bool satisfied;
};
class SandboxApp;
namespace GUI
{
class QueueWidget;
};
class PieceQueue : public RAIN::MessageHandler
{
public:
PieceQueue(RAIN::SandboxApp *app);
~PieceQueue();
void HandleMessage(RAIN::Message *msg);
void Tick();
int GetMessageHandlerID();
int QueueMissingPieces(ManifestEntry *entry);
void EmptyQueue();
void LoadQueue();
void SaveQueue();
void SentPiece(const wxString& hash);
bool RemoveQueues(const wxString& hash, QueuedPieceDirection d);
void ResetQueues(const wxString& hash, QueuedPieceDirection d);
void AddWaits(QueuedPiece *p);
void CheckWaits();
bool HasWaits(const wxString& hash);
bool SetWaitsSatisfied(WaitingFor w, const wxString& hash);
bool InCurrentQueue(QueuedPiece *p);
void InitiateTransfer(QueuedPiece *q);
private:
RAIN::SandboxApp *app;
std::vector<QueuedPiece*> queue;
std::vector<QueuedPiece*> current;
std::vector<QueueWait*> waits;
QueueState state;
friend class RAIN::GUI::QueueWidget;
static const int concurrency = 3;
};
}
#endif //__PIECEQUEUE_H