Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/WasmWebService.cpp @ 253:8ff70c04c6df am-2
IObservable/IObserver now working in WASM too
author | am@osimis.io |
---|---|
date | Tue, 03 Jul 2018 10:48:47 +0200 |
parents | ddbb339ed4cf |
children | 9afafb192180 |
comparison
equal
deleted
inserted
replaced
252:40b21c1f8b8d | 253:8ff70c04c6df |
---|---|
25 throw; | 25 throw; |
26 } | 26 } |
27 else | 27 else |
28 { | 28 { |
29 reinterpret_cast<OrthancStone::IWebService::ICallback*>(callback)-> | 29 reinterpret_cast<OrthancStone::IWebService::ICallback*>(callback)-> |
30 NotifyError(uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload)); | 30 OnHttpRequestError(uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload)); |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifySuccess(void* callback, | 34 void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifySuccess(void* callback, |
35 const char* uri, | 35 const char* uri, |
42 throw; | 42 throw; |
43 } | 43 } |
44 else | 44 else |
45 { | 45 { |
46 reinterpret_cast<OrthancStone::IWebService::ICallback*>(callback)-> | 46 reinterpret_cast<OrthancStone::IWebService::ICallback*>(callback)-> |
47 NotifySuccess(uri, body, bodySize, reinterpret_cast<Orthanc::IDynamicObject*>(payload)); | 47 OnHttpRequestSuccess(uri, body, bodySize, reinterpret_cast<Orthanc::IDynamicObject*>(payload)); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 void EMSCRIPTEN_KEEPALIVE WasmWebService_SetBaseUrl(const char* baseUrl) | 51 void EMSCRIPTEN_KEEPALIVE WasmWebService_SetBaseUri(const char* baseUri) |
52 { | 52 { |
53 OrthancStone::WasmWebService::GetInstance().SetBaseUrl(baseUrl); | 53 OrthancStone::WasmWebService::GetInstance().SetBaseUri(baseUri); |
54 } | 54 } |
55 | 55 |
56 #ifdef __cplusplus | 56 #ifdef __cplusplus |
57 } | 57 } |
58 #endif | 58 #endif |
59 | 59 |
60 | 60 |
61 | 61 |
62 namespace OrthancStone | 62 namespace OrthancStone |
63 { | 63 { |
64 void WasmWebService::SetBaseUrl(const std::string base) | 64 MessageBroker* WasmWebService::broker_ = NULL; |
65 | |
66 void WasmWebService::SetBaseUri(const std::string baseUri) | |
65 { | 67 { |
66 // Make sure the base url ends with "/" | 68 // Make sure the base url ends with "/" |
67 if (base.empty() || | 69 if (baseUri.empty() || |
68 base[base.size() - 1] != '/') | 70 baseUri[baseUri.size() - 1] != '/') |
69 { | 71 { |
70 base_ = base + "/"; | 72 baseUri_ = baseUri + "/"; |
71 } | 73 } |
72 else | 74 else |
73 { | 75 { |
74 base_ = base; | 76 baseUri_ = baseUri; |
75 } | 77 } |
76 } | 78 } |
77 | 79 |
78 void WasmWebService::ScheduleGetRequest(ICallback& callback, | 80 void WasmWebService::ScheduleGetRequest(ICallback& callback, |
79 const std::string& uri, | 81 const std::string& relativeUri, |
80 Orthanc::IDynamicObject* payload) | 82 Orthanc::IDynamicObject* payload) |
81 { | 83 { |
82 std::string url = base_ + uri; | 84 std::string uri = baseUri_ + relativeUri; |
83 WasmWebService_ScheduleGetRequest(&callback, url.c_str(), payload); | 85 WasmWebService_ScheduleGetRequest(&callback, uri.c_str(), payload); |
84 } | 86 } |
85 | 87 |
86 void WasmWebService::SchedulePostRequest(ICallback& callback, | 88 void WasmWebService::SchedulePostRequest(ICallback& callback, |
87 const std::string& uri, | 89 const std::string& relativeUri, |
88 const std::string& body, | 90 const std::string& body, |
89 Orthanc::IDynamicObject* payload) | 91 Orthanc::IDynamicObject* payload) |
90 { | 92 { |
91 std::string url = base_ + uri; | 93 std::string uri = baseUri_ + relativeUri; |
92 WasmWebService_SchedulePostRequest(&callback, url.c_str(), | 94 WasmWebService_SchedulePostRequest(&callback, uri.c_str(), |
93 body.c_str(), body.size(), payload); | 95 body.c_str(), body.size(), payload); |
94 } | 96 } |
95 } | 97 } |