Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/OrthancApiClient.h @ 434:3a8bcc45c221 am-vsol-upgrade
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
author | am@osimis.io |
---|---|
date | Mon, 03 Dec 2018 18:03:30 +0100 |
parents | bb573a52fc63 |
children | a750f11892ec |
comparison
equal
deleted
inserted
replaced
433:8999823db8b8 | 434:3a8bcc45c221 |
---|---|
147 | 147 |
148 | 148 |
149 | 149 |
150 private: | 150 private: |
151 class WebServicePayload; | 151 class WebServicePayload; |
152 class CachedHttpRequestSuccessMessage; | |
153 | 152 |
154 protected: | 153 protected: |
155 IWebService& web_; | 154 IWebService& web_; |
156 std::string baseUrl_; | 155 std::string baseUrl_; |
157 | 156 |
158 std::map<std::string, boost::shared_ptr<CachedHttpRequestSuccessMessage>> cache_; // TODO: this is currently an infinite cache ! | |
159 bool cacheEnabled_; | |
160 public: | 157 public: |
161 OrthancApiClient(MessageBroker& broker, | 158 OrthancApiClient(MessageBroker& broker, |
162 IWebService& web, | 159 IWebService& web, |
163 const std::string& baseUrl); | 160 const std::string& baseUrl); |
164 | 161 |
165 virtual ~OrthancApiClient() | 162 virtual ~OrthancApiClient() |
166 { | 163 { |
167 } | 164 } |
168 | 165 |
169 void EnableCache(bool enable) | |
170 { | |
171 cacheEnabled_ = enable; | |
172 } | |
173 | |
174 // schedule a GET request expecting a JSON response. | 166 // schedule a GET request expecting a JSON response. |
175 void GetJsonAsync(const std::string& uri, | 167 void GetJsonAsync(const std::string& uri, |
176 MessageHandler<JsonResponseReadyMessage>* successCallback, | 168 MessageHandler<JsonResponseReadyMessage>* successCallback, |
177 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, | 169 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
178 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); | 170 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
221 | 213 |
222 void NotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message); | 214 void NotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message); |
223 | 215 |
224 void NotifyHttpError(const IWebService::HttpRequestErrorMessage& message); | 216 void NotifyHttpError(const IWebService::HttpRequestErrorMessage& message); |
225 | 217 |
226 void CacheAndNotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message); | |
227 | |
228 private: | 218 private: |
229 void HandleFromCache(const std::string& uri, | 219 void HandleFromCache(const std::string& uri, |
230 const IWebService::HttpHeaders& headers, | 220 const IWebService::HttpHeaders& headers, |
231 Orthanc::IDynamicObject* payload /* takes ownership */); | 221 Orthanc::IDynamicObject* payload /* takes ownership */); |
232 }; | 222 }; |