Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/WasmWebService.cpp @ 299:3897f9f28cfa am-callable-and-promise
backup work in progress: updated messaging framework with ICallable
author | am@osimis.io |
---|---|
date | Fri, 14 Sep 2018 16:44:01 +0200 |
parents | 9afafb192180 |
children | ed1a4302154f |
comparison
equal
deleted
inserted
replaced
298:f58bfb7bbcc9 | 299:3897f9f28cfa |
---|---|
9 | 9 |
10 extern void WasmWebService_ScheduleGetRequest(void* callback, | 10 extern void WasmWebService_ScheduleGetRequest(void* callback, |
11 const char* uri, | 11 const char* uri, |
12 const char* headersInJsonString, | 12 const char* headersInJsonString, |
13 void* payload); | 13 void* payload); |
14 | 14 |
15 extern void WasmWebService_NewScheduleGetRequest(void* callableSuccess, | |
16 void* callableFailure, | |
17 const char* uri, | |
18 const char* headersInJsonString, | |
19 void* payload); | |
20 | |
15 extern void WasmWebService_SchedulePostRequest(void* callback, | 21 extern void WasmWebService_SchedulePostRequest(void* callback, |
16 const char* uri, | 22 const char* uri, |
17 const char* headersInJsonString, | 23 const char* headersInJsonString, |
18 const void* body, | 24 const void* body, |
19 size_t bodySize, | 25 size_t bodySize, |
46 } | 52 } |
47 else | 53 else |
48 { | 54 { |
49 reinterpret_cast<OrthancStone::IWebService::ICallback*>(callback)-> | 55 reinterpret_cast<OrthancStone::IWebService::ICallback*>(callback)-> |
50 OnHttpRequestSuccess(uri, body, bodySize, reinterpret_cast<Orthanc::IDynamicObject*>(payload)); | 56 OnHttpRequestSuccess(uri, body, bodySize, reinterpret_cast<Orthanc::IDynamicObject*>(payload)); |
57 } | |
58 } | |
59 | |
60 void EMSCRIPTEN_KEEPALIVE WasmWebService_NewNotifyError(void* failureCallable, | |
61 const char* uri, | |
62 void* payload) | |
63 { | |
64 if (failureCallable == NULL) | |
65 { | |
66 throw; | |
67 } | |
68 else | |
69 { | |
70 reinterpret_cast<OrthancStone::MessageHandler<OrthancStone::IWebService::NewHttpRequestErrorMessage>*>(failureCallable)-> | |
71 Apply(OrthancStone::IWebService::NewHttpRequestErrorMessage(uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload))); | |
72 } | |
73 } | |
74 | |
75 void EMSCRIPTEN_KEEPALIVE WasmWebService_NewNotifySuccess(void* successCallable, | |
76 const char* uri, | |
77 const void* body, | |
78 size_t bodySize, | |
79 void* payload) | |
80 { | |
81 if (successCallable == NULL) | |
82 { | |
83 throw; | |
84 } | |
85 else | |
86 { | |
87 reinterpret_cast<OrthancStone::MessageHandler<OrthancStone::IWebService::NewHttpRequestSuccessMessage>*>(successCallable)-> | |
88 Apply(OrthancStone::IWebService::NewHttpRequestSuccessMessage(uri, body, bodySize, reinterpret_cast<Orthanc::IDynamicObject*>(payload))); | |
51 } | 89 } |
52 } | 90 } |
53 | 91 |
54 void EMSCRIPTEN_KEEPALIVE WasmWebService_SetBaseUri(const char* baseUri) | 92 void EMSCRIPTEN_KEEPALIVE WasmWebService_SetBaseUri(const char* baseUri) |
55 { | 93 { |
117 std::string headersInJsonString; | 155 std::string headersInJsonString; |
118 ToJsonString(headersInJsonString, headers); | 156 ToJsonString(headersInJsonString, headers); |
119 WasmWebService_SchedulePostRequest(&callback, uri.c_str(), headersInJsonString.c_str(), | 157 WasmWebService_SchedulePostRequest(&callback, uri.c_str(), headersInJsonString.c_str(), |
120 body.c_str(), body.size(), payload); | 158 body.c_str(), body.size(), payload); |
121 } | 159 } |
160 | |
161 void WasmWebService::GetAsync(const std::string& relativeUri, | |
162 const Headers& headers, | |
163 Orthanc::IDynamicObject* payload, | |
164 MessageHandler<IWebService::NewHttpRequestSuccessMessage>* successCallable, | |
165 MessageHandler<IWebService::NewHttpRequestErrorMessage>* failureCallable) | |
166 { | |
167 std::string uri = baseUri_ + relativeUri; | |
168 std::string headersInJsonString; | |
169 ToJsonString(headersInJsonString, headers); | |
170 WasmWebService_NewScheduleGetRequest(successCallable, failureCallable, uri.c_str(), headersInJsonString.c_str(), payload); | |
171 } | |
172 | |
122 } | 173 } |