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
|
#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, void *param)
{
NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, (NETLIBHTTPREQUEST*)request);
HttpResponse response(request, pResp);
if (callback)
(this->*callback)(response, param);
delete request;
}
void CSlackProto::SendRequest(HttpRequest *request, JsonCallback callback, void *param)
{
NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, (NETLIBHTTPREQUEST*)request);
HttpResponse response(request, pResp);
if (callback)
{
JSONNode root = JSONNode::parse(response.Content);
(this->*callback)(root, param);
}
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, void *param)
{
RequestQueueItem *item = new RequestQueueItem();
item->request = request;
item->httpCallback = callback;
item->param = param;
{
mir_cslock lock(requestQueueLock);
requestQueue.insert(item);
}
SetEvent(hRequestsQueueEvent);
}
void CSlackProto::PushRequest(HttpRequest *request, JsonCallback callback, void *param)
{
RequestQueueItem *item = new RequestQueueItem();
item->request = request;
item->jsonCallback = callback;
item->param = param;
{
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, item->param);
else if (item->jsonCallback)
SendRequest(item->request, item->jsonCallback, item->param);
else
SendRequest(item->request);
delete item;
}
WaitForSingleObject(hRequestsQueueEvent, 1000);
} while (!isTerminated);
hRequestQueueThread = NULL;
}
|