diff options
Diffstat (limited to 'protocols/Steam/src/steam_request.cpp')
-rw-r--r-- | protocols/Steam/src/steam_request.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/protocols/Steam/src/steam_request.cpp b/protocols/Steam/src/steam_request.cpp new file mode 100644 index 0000000000..05a7b235b1 --- /dev/null +++ b/protocols/Steam/src/steam_request.cpp @@ -0,0 +1,73 @@ +#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(NULL), arg(NULL), httpFinallyCallback(NULL), hasArg(false) {}
+
+ SteamResponseDelegate(CSteamProto *proto, SteamResponseWithArgCallback responseCallback, void *arg, HttpFinallyCallback httpFinallyCallback)
+ : proto(proto), responseCallback(NULL), responseWithArgCallback(responseCallback), arg(arg), httpFinallyCallback(httpFinallyCallback), hasArg(true) { }
+
+ void Invoke(const NETLIBHTTPREQUEST *response)
+ {
+ if (hasArg)
+ {
+ (proto->*(responseWithArgCallback))(response, arg);
+ if (httpFinallyCallback != NULL)
+ httpFinallyCallback(arg);
+ }
+ else
+ (proto->*(responseCallback))(response);
+ }
+};
+
+static void SteamHttpResponse(const NETLIBHTTPREQUEST *response, void *arg)
+{
+ SteamResponseDelegate *delegate = (SteamResponseDelegate*)arg;
+ delegate->Invoke(response);
+ 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);
+}
+
+void CSteamProto::PushRequest(HttpRequest *request, SteamResponseWithArgCallback response, void *arg, HttpFinallyCallback last)
+{
+ SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response, arg, last);
+ requestQueue->Push(request, SteamHttpResponse, delegate);
+}
+
+void CSteamProto::SendRequest(HttpRequest *request)
+{
+ requestQueue->Send(request, NULL, NULL);
+}
+
+void CSteamProto::SendRequest(HttpRequest *request, SteamResponseCallback response)
+{
+ SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response);
+ requestQueue->Send(request, SteamHttpResponse, delegate);
+}
+
+void CSteamProto::SendRequest(HttpRequest *request, SteamResponseWithArgCallback response, void *arg, HttpFinallyCallback last)
+{
+ SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response, arg, last);
+ requestQueue->Send(request, SteamHttpResponse, delegate);
+}
|