diff options
Diffstat (limited to 'protocols/Slack/src/slack_requests.cpp')
-rw-r--r-- | protocols/Slack/src/slack_requests.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/protocols/Slack/src/slack_requests.cpp b/protocols/Slack/src/slack_requests.cpp new file mode 100644 index 0000000000..7fd0ef4805 --- /dev/null +++ b/protocols/Slack/src/slack_requests.cpp @@ -0,0 +1,95 @@ +#include "stdafx.h" + +void CSlackProto::SendRequest(HttpRequest *request) +{ + NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, (NETLIBHTTPREQUEST*)request); + HttpResponse response(request, pResp); + delete request; +} + +void CSlackProto::SendRequest(HttpRequest *request, HttpCallback callback) +{ + NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, (NETLIBHTTPREQUEST*)request); + HttpResponse response(request, pResp); + if (callback) + (this->*callback)(response); + delete request; +} + +void CSlackProto::SendRequest(HttpRequest *request, JsonCallback callback) +{ + NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, (NETLIBHTTPREQUEST*)request); + HttpResponse response(request, pResp); + if (callback) + { + JSONNode root = JSONNode::parse(response.Content); + (this->*callback)(root); + } + delete request; +} + +void CSlackProto::PushRequest(HttpRequest *request) +{ + RequestQueueItem *item = new RequestQueueItem(); + item->request = request; + { + mir_cslock lock(requestQueueLock); + requestQueue.insert(item); + } + SetEvent(hRequestsQueueEvent); +} + +void CSlackProto::PushRequest(HttpRequest *request, HttpCallback callback) +{ + RequestQueueItem *item = new RequestQueueItem(); + item->request = request; + item->httpCallback = callback; + { + mir_cslock lock(requestQueueLock); + requestQueue.insert(item); + } + SetEvent(hRequestsQueueEvent); +} + +void CSlackProto::PushRequest(HttpRequest *request, JsonCallback callback) +{ + RequestQueueItem *item = new RequestQueueItem(); + item->request = request; + item->jsonCallback = callback; + { + mir_cslock lock(requestQueueLock); + requestQueue.insert(item); + } + SetEvent(hRequestsQueueEvent); +} + +void CSlackProto::RequestQueueThread(void*) +{ + Login(); + + do + { + RequestQueueItem *item; + while (true) + { + { + mir_cslock lock(requestQueueLock); + if (!requestQueue.getCount()) + break; + + item = requestQueue[0]; + requestQueue.remove(0); + } + if (item->httpCallback) + SendRequest(item->request, item->httpCallback); + else if (item->jsonCallback) + SendRequest(item->request, item->jsonCallback); + else + SendRequest(item->request); + delete item; + } + WaitForSingleObject(hRequestsQueueEvent, 1000); + } while (!isTerminated); + + hRequestQueueThread = NULL; +}
\ No newline at end of file |