comparison Platforms/Wasm/WasmWebService.cpp @ 236:f73d722d98c8 am

renamed folder
author am@osimis.io
date Tue, 19 Jun 2018 16:06:32 +0200
parents Platforms/WebAssembly/WasmWebService.cpp@d7b2590744f8
children ddbb339ed4cf
comparison
equal deleted inserted replaced
235:ce4405d98b92 236:f73d722d98c8
1 #include "WasmWebService.h"
2
3 #include <emscripten/emscripten.h>
4
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8
9 extern void WasmWebService_ScheduleGetRequest(void* callback,
10 const char* uri,
11 void* payload);
12
13 extern void WasmWebService_SchedulePostRequest(void* callback,
14 const char* uri,
15 const void* body,
16 size_t bodySize,
17 void* payload);
18
19 void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifyError(void* callback,
20 const char* uri,
21 void* payload)
22 {
23 if (callback == NULL)
24 {
25 throw;
26 }
27 else
28 {
29 reinterpret_cast<OrthancStone::IWebService::ICallback*>(callback)->
30 NotifyError(uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload));
31 }
32 }
33
34 void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifySuccess(void* callback,
35 const char* uri,
36 const void* body,
37 size_t bodySize,
38 void* payload)
39 {
40 if (callback == NULL)
41 {
42 throw;
43 }
44 else
45 {
46 reinterpret_cast<OrthancStone::IWebService::ICallback*>(callback)->
47 NotifySuccess(uri, body, bodySize, reinterpret_cast<Orthanc::IDynamicObject*>(payload));
48 }
49 }
50
51 #ifdef __cplusplus
52 }
53 #endif
54
55
56
57 namespace OrthancStone
58 {
59 void WasmWebService::SetBaseUrl(const std::string base)
60 {
61 // Make sure the base url ends with "/"
62 if (base.empty() ||
63 base[base.size() - 1] != '/')
64 {
65 base_ = base + "/";
66 }
67 else
68 {
69 base_ = base;
70 }
71 }
72
73 void WasmWebService::ScheduleGetRequest(ICallback& callback,
74 const std::string& uri,
75 Orthanc::IDynamicObject* payload)
76 {
77 std::string url = base_ + uri;
78 WasmWebService_ScheduleGetRequest(&callback, url.c_str(), payload);
79 }
80
81 void WasmWebService::SchedulePostRequest(ICallback& callback,
82 const std::string& uri,
83 const std::string& body,
84 Orthanc::IDynamicObject* payload)
85 {
86 std::string url = base_ + uri;
87 WasmWebService_SchedulePostRequest(&callback, url.c_str(),
88 body.c_str(), body.size(), payload);
89 }
90 }