summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/request_queue.h
blob: 44a2df3a8a5ef9ebb4e20dce8deb050dcac6fe82 (plain)
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
#ifndef _REQUEST_QUEUE_H_
#define _REQUEST_QUEUE_H_

typedef void(*HttpResponseCallback)(const HttpResponse *response, void *arg);
typedef void(*HttpFinallyCallback)(void *arg);

struct RequestQueueItem
{
	void *arg;
	HttpRequest *request;
	HttpResponseCallback responseCallback;
	HttpFinallyCallback finallyCallback;

	RequestQueueItem(HttpRequest *request, void *arg, HttpFinallyCallback finallyCallback) :
		request(request), responseCallback(NULL), arg(arg), finallyCallback(finallyCallback)
	{
	}

	RequestQueueItem(HttpRequest *request, HttpResponseCallback response, void *arg, HttpFinallyCallback finallyCallback) :
		request(request), responseCallback(response), arg(arg), finallyCallback(finallyCallback)
	{
	}

	~RequestQueueItem()
	{
		delete request;
		request = NULL;
		responseCallback = NULL;
		finallyCallback = NULL;
	}
};

class RequestQueue
{
	bool isTerminated;
	HNETLIBUSER hConnection;
	mir_cs requestQueueLock;
	LIST<RequestQueueItem> requests;
	HANDLE hRequestQueueEvent, hRequestQueueThread;

	void Execute(RequestQueueItem *item);

	static unsigned int __cdecl AsyncSendThread(void*, void*);
	static unsigned int __cdecl WorkerThread(void*);

public:
	RequestQueue(HNETLIBUSER hConnection);
	~RequestQueue();

	void Start();
	void Stop();

	void Push(HttpRequest *request, HttpResponseCallback response = NULL, void *arg = NULL, HttpFinallyCallback last = NULL);
	void Send(HttpRequest *request, HttpResponseCallback response = NULL, void *arg = NULL, HttpFinallyCallback last = NULL);

};

#endif //_REQUEST_QUEUE_H_