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
|
#include "stdafx.h"
class SteamResponseDelegate
{
private:
CSteamProto *proto;
SteamResponseCallback responseCallback;
SteamResponseWithArgCallback responseWithArgCallback;
HttpFinallyCallback httpFinallyCallback;
void *arg;
bool hasArg;
public:
SteamResponseDelegate(CSteamProto *proto, SteamResponseCallback responseCallback)
: proto(proto), responseCallback(responseCallback), responseWithArgCallback(nullptr), arg(nullptr), httpFinallyCallback(nullptr), hasArg(false) {}
SteamResponseDelegate(CSteamProto *proto, SteamResponseWithArgCallback responseCallback, void *arg, HttpFinallyCallback httpFinallyCallback)
: proto(proto), responseCallback(nullptr), responseWithArgCallback(responseCallback), arg(arg), httpFinallyCallback(httpFinallyCallback), hasArg(true) { }
void Invoke(const HttpResponse *response)
{
if (hasArg)
{
(proto->*(responseWithArgCallback))(response, arg);
if (httpFinallyCallback != nullptr)
httpFinallyCallback(arg);
}
else
(proto->*(responseCallback))(response);
}
};
static void SteamHttpResponse(const HttpResponse *response, void *arg)
{
SteamResponseDelegate *delegate = (SteamResponseDelegate*)arg;
delegate->Invoke(response);
}
void SteamResponseDelegateFree(void *arg)
{
SteamResponseDelegate *delegate = (SteamResponseDelegate*)arg;
delete delegate;
}
void CSteamProto::PushRequest(HttpRequest *request)
{
requestQueue->Push(request);
}
void CSteamProto::PushRequest(HttpRequest *request, SteamResponseCallback response)
{
SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response);
requestQueue->Push(request, SteamHttpResponse, delegate, SteamResponseDelegateFree);
}
void CSteamProto::PushRequest(HttpRequest *request, SteamResponseWithArgCallback response, void *arg, HttpFinallyCallback last)
{
SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response, arg, last);
requestQueue->Push(request, SteamHttpResponse, delegate, SteamResponseDelegateFree);
}
void CSteamProto::SendRequest(HttpRequest *request)
{
requestQueue->Send(request);
}
void CSteamProto::SendRequest(HttpRequest *request, SteamResponseCallback response)
{
SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response);
requestQueue->Send(request, SteamHttpResponse, delegate, SteamResponseDelegateFree);
}
void CSteamProto::SendRequest(HttpRequest *request, SteamResponseWithArgCallback response, void *arg, HttpFinallyCallback last)
{
SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response, arg, last);
requestQueue->Send(request, SteamHttpResponse, delegate, SteamResponseDelegateFree);
}
|