Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/WasmWebService.cpp @ 726:4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 May 2019 11:43:25 +0200 |
parents | a04f08baba27 |
children | 861c080ef47b |
comparison
equal
deleted
inserted
replaced
714:d2c0e347ddc2 | 726:4f2416d519b4 |
---|---|
4 #include <emscripten/emscripten.h> | 4 #include <emscripten/emscripten.h> |
5 #include <boost/shared_ptr.hpp> | 5 #include <boost/shared_ptr.hpp> |
6 | 6 |
7 struct CachedSuccessNotification | 7 struct CachedSuccessNotification |
8 { | 8 { |
9 boost::shared_ptr<OrthancStone::BaseWebService::CachedHttpRequestSuccessMessage> cachedMessage; | 9 boost::shared_ptr<Deprecated::BaseWebService::CachedHttpRequestSuccessMessage> cachedMessage; |
10 std::auto_ptr<Orthanc::IDynamicObject> payload; | 10 std::auto_ptr<Orthanc::IDynamicObject> payload; |
11 OrthancStone::MessageHandler<OrthancStone::IWebService::HttpRequestSuccessMessage>* successCallback; | 11 OrthancStone::MessageHandler<Deprecated::IWebService::HttpRequestSuccessMessage>* successCallback; |
12 }; | 12 }; |
13 | 13 |
14 | 14 |
15 #ifdef __cplusplus | 15 #ifdef __cplusplus |
16 extern "C" { | 16 extern "C" { |
45 const char* uri, | 45 const char* uri, |
46 void* payload) | 46 void* payload) |
47 { | 47 { |
48 if (failureCallable != NULL) | 48 if (failureCallable != NULL) |
49 { | 49 { |
50 reinterpret_cast<OrthancStone::MessageHandler<OrthancStone::IWebService::HttpRequestErrorMessage>*>(failureCallable)-> | 50 reinterpret_cast<OrthancStone::MessageHandler<Deprecated::IWebService::HttpRequestErrorMessage>*>(failureCallable)-> |
51 Apply(OrthancStone::IWebService::HttpRequestErrorMessage(uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload))); | 51 Apply(Deprecated::IWebService::HttpRequestErrorMessage(uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload))); |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifyCachedSuccess(void* notification_) | 55 void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifyCachedSuccess(void* notification_) |
56 { | 56 { |
57 // notification has been allocated in C++ and passed to JS. It must be deleted by this method | 57 // notification has been allocated in C++ and passed to JS. It must be deleted by this method |
58 std::auto_ptr<CachedSuccessNotification> notification(reinterpret_cast<CachedSuccessNotification*>(notification_)); | 58 std::auto_ptr<CachedSuccessNotification> notification(reinterpret_cast<CachedSuccessNotification*>(notification_)); |
59 | 59 |
60 notification->successCallback->Apply(OrthancStone::IWebService::HttpRequestSuccessMessage( | 60 notification->successCallback->Apply(Deprecated::IWebService::HttpRequestSuccessMessage( |
61 notification->cachedMessage->GetUri(), | 61 notification->cachedMessage->GetUri(), |
62 notification->cachedMessage->GetAnswer(), | 62 notification->cachedMessage->GetAnswer(), |
63 notification->cachedMessage->GetAnswerSize(), | 63 notification->cachedMessage->GetAnswerSize(), |
64 notification->cachedMessage->GetAnswerHttpHeaders(), | 64 notification->cachedMessage->GetAnswerHttpHeaders(), |
65 notification->payload.get() | 65 notification->payload.get() |
73 const char* answerHeaders, | 73 const char* answerHeaders, |
74 void* payload) | 74 void* payload) |
75 { | 75 { |
76 if (successCallable != NULL) | 76 if (successCallable != NULL) |
77 { | 77 { |
78 OrthancStone::IWebService::HttpHeaders headers; | 78 Deprecated::IWebService::HttpHeaders headers; |
79 | 79 |
80 // TODO - Parse "answerHeaders" | 80 // TODO - Parse "answerHeaders" |
81 //printf("TODO: parse headers [%s]\n", answerHeaders); | 81 //printf("TODO: parse headers [%s]\n", answerHeaders); |
82 | 82 |
83 reinterpret_cast<OrthancStone::MessageHandler<OrthancStone::IWebService::HttpRequestSuccessMessage>*>(successCallable)-> | 83 reinterpret_cast<OrthancStone::MessageHandler<Deprecated::IWebService::HttpRequestSuccessMessage>*>(successCallable)-> |
84 Apply(OrthancStone::IWebService::HttpRequestSuccessMessage(uri, body, bodySize, headers, | 84 Apply(Deprecated::IWebService::HttpRequestSuccessMessage(uri, body, bodySize, headers, |
85 reinterpret_cast<Orthanc::IDynamicObject*>(payload))); | 85 reinterpret_cast<Orthanc::IDynamicObject*>(payload))); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 #ifdef __cplusplus | 89 #ifdef __cplusplus |
90 } | 90 } |
91 #endif | 91 #endif |
92 | 92 |
93 | 93 |
94 | 94 |
95 namespace OrthancStone | 95 namespace Deprecated |
96 { | 96 { |
97 MessageBroker* WasmWebService::broker_ = NULL; | 97 OrthancStone::MessageBroker* WasmWebService::broker_ = NULL; |
98 | 98 |
99 void ToJsonString(std::string& output, const IWebService::HttpHeaders& headers) | 99 void ToJsonString(std::string& output, const IWebService::HttpHeaders& headers) |
100 { | 100 { |
101 Json::Value jsonHeaders; | 101 Json::Value jsonHeaders; |
102 for (IWebService::HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); it++ ) | 102 for (IWebService::HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); it++ ) |
114 | 114 |
115 void WasmWebService::PostAsync(const std::string& relativeUri, | 115 void WasmWebService::PostAsync(const std::string& relativeUri, |
116 const HttpHeaders& headers, | 116 const HttpHeaders& headers, |
117 const std::string& body, | 117 const std::string& body, |
118 Orthanc::IDynamicObject* payload, | 118 Orthanc::IDynamicObject* payload, |
119 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallable, | 119 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallable, |
120 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallable, | 120 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallable, |
121 unsigned int timeoutInSeconds) | 121 unsigned int timeoutInSeconds) |
122 { | 122 { |
123 std::string headersInJsonString; | 123 std::string headersInJsonString; |
124 ToJsonString(headersInJsonString, headers); | 124 ToJsonString(headersInJsonString, headers); |
125 WasmWebService_PostAsync(successCallable, failureCallable, relativeUri.c_str(), headersInJsonString.c_str(), | 125 WasmWebService_PostAsync(successCallable, failureCallable, relativeUri.c_str(), headersInJsonString.c_str(), |
127 } | 127 } |
128 | 128 |
129 void WasmWebService::DeleteAsync(const std::string& relativeUri, | 129 void WasmWebService::DeleteAsync(const std::string& relativeUri, |
130 const HttpHeaders& headers, | 130 const HttpHeaders& headers, |
131 Orthanc::IDynamicObject* payload, | 131 Orthanc::IDynamicObject* payload, |
132 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallable, | 132 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallable, |
133 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallable, | 133 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallable, |
134 unsigned int timeoutInSeconds) | 134 unsigned int timeoutInSeconds) |
135 { | 135 { |
136 std::string headersInJsonString; | 136 std::string headersInJsonString; |
137 ToJsonString(headersInJsonString, headers); | 137 ToJsonString(headersInJsonString, headers); |
138 WasmWebService_DeleteAsync(successCallable, failureCallable, relativeUri.c_str(), headersInJsonString.c_str(), | 138 WasmWebService_DeleteAsync(successCallable, failureCallable, relativeUri.c_str(), headersInJsonString.c_str(), |
140 } | 140 } |
141 | 141 |
142 void WasmWebService::GetAsyncInternal(const std::string &relativeUri, | 142 void WasmWebService::GetAsyncInternal(const std::string &relativeUri, |
143 const HttpHeaders &headers, | 143 const HttpHeaders &headers, |
144 Orthanc::IDynamicObject *payload, | 144 Orthanc::IDynamicObject *payload, |
145 MessageHandler<IWebService::HttpRequestSuccessMessage> *successCallable, | 145 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage> *successCallable, |
146 MessageHandler<IWebService::HttpRequestErrorMessage> *failureCallable, | 146 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage> *failureCallable, |
147 unsigned int timeoutInSeconds) | 147 unsigned int timeoutInSeconds) |
148 { | 148 { |
149 std::string headersInJsonString; | 149 std::string headersInJsonString; |
150 ToJsonString(headersInJsonString, headers); | 150 ToJsonString(headersInJsonString, headers); |
151 WasmWebService_GetAsync(successCallable, failureCallable, relativeUri.c_str(), | 151 WasmWebService_GetAsync(successCallable, failureCallable, relativeUri.c_str(), |
152 headersInJsonString.c_str(), payload, timeoutInSeconds); | 152 headersInJsonString.c_str(), payload, timeoutInSeconds); |
153 } | 153 } |
154 | 154 |
155 void WasmWebService::NotifyHttpSuccessLater(boost::shared_ptr<BaseWebService::CachedHttpRequestSuccessMessage> cachedMessage, | 155 void WasmWebService::NotifyHttpSuccessLater(boost::shared_ptr<BaseWebService::CachedHttpRequestSuccessMessage> cachedMessage, |
156 Orthanc::IDynamicObject* payload, // takes ownership | 156 Orthanc::IDynamicObject* payload, // takes ownership |
157 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback) | 157 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback) |
158 { | 158 { |
159 CachedSuccessNotification* notification = new CachedSuccessNotification(); // allocated on the heap, it will be passed to JS and deleted when coming back to C++ | 159 CachedSuccessNotification* notification = new CachedSuccessNotification(); // allocated on the heap, it will be passed to JS and deleted when coming back to C++ |
160 notification->cachedMessage = cachedMessage; | 160 notification->cachedMessage = cachedMessage; |
161 notification->payload.reset(payload); | 161 notification->payload.reset(payload); |
162 notification->successCallback = successCallback; | 162 notification->successCallback = successCallback; |