Mercurial > hg > orthanc-stone
diff Framework/Toolbox/IWebService.h @ 301:547e1cf7aa7b am-callable-and-promise
cleanup
author | am@osimis.io |
---|---|
date | Tue, 18 Sep 2018 15:34:28 +0200 |
parents | b4abaeb783b1 |
children | 14ef1227120f |
line wrap: on
line diff
--- a/Framework/Toolbox/IWebService.h Tue Sep 18 15:23:21 2018 +0200 +++ b/Framework/Toolbox/IWebService.h Tue Sep 18 15:34:28 2018 +0200 @@ -42,110 +42,37 @@ public: typedef std::map<std::string, std::string> Headers; - struct NewHttpRequestSuccessMessage: public BaseMessage<MessageType_HttpRequestSuccess> + struct HttpRequestSuccessMessage: public BaseMessage<MessageType_HttpRequestSuccess> { - const std::string& Uri; - const void* Answer; - size_t AnswerSize; - Orthanc::IDynamicObject* Payload; - NewHttpRequestSuccessMessage(const std::string& uri, + const std::string& uri_; + const void* answer_; + size_t answerSize_; + Orthanc::IDynamicObject* payload_; + HttpRequestSuccessMessage(const std::string& uri, const void* answer, size_t answerSize, Orthanc::IDynamicObject* payload) : BaseMessage(), - Uri(uri), - Answer(answer), - AnswerSize(answerSize), - Payload(payload) + uri_(uri), + answer_(answer), + answerSize_(answerSize), + payload_(payload) {} }; - struct NewHttpRequestErrorMessage: public BaseMessage<MessageType_HttpRequestError> + struct HttpRequestErrorMessage: public BaseMessage<MessageType_HttpRequestError> { - const std::string& Uri; - Orthanc::IDynamicObject* Payload; - NewHttpRequestErrorMessage(const std::string& uri, + const std::string& uri_; + Orthanc::IDynamicObject* payload_; + HttpRequestErrorMessage(const std::string& uri, Orthanc::IDynamicObject* payload) : BaseMessage(), - Uri(uri), - Payload(payload) + uri_(uri), + payload_(payload) {} }; - class ICallback : public IObserver - { - public: - struct HttpRequestSuccessMessage: public IMessage - { - const std::string& Uri; - const void* Answer; - size_t AnswerSize; - Orthanc::IDynamicObject* Payload; - HttpRequestSuccessMessage(const std::string& uri, - const void* answer, - size_t answerSize, - Orthanc::IDynamicObject* payload) - : IMessage(MessageType_HttpRequestSuccess), - Uri(uri), - Answer(answer), - AnswerSize(answerSize), - Payload(payload) - {} - }; - - struct HttpRequestErrorMessage: public IMessage - { - const std::string& Uri; - Orthanc::IDynamicObject* Payload; - HttpRequestErrorMessage(const std::string& uri, - Orthanc::IDynamicObject* payload) - : IMessage(MessageType_HttpRequestError), - Uri(uri), - Payload(payload) - {} - }; - - ICallback(MessageBroker& broker) - : IObserver(broker) - { - } - virtual ~ICallback() - { - } - - virtual void HandleMessage(IObservable& from, const IMessage& message) - { - switch(message.GetType()) - { - case MessageType_HttpRequestError: - { - const HttpRequestErrorMessage& msg = dynamic_cast<const HttpRequestErrorMessage&>(message); - OnHttpRequestError(msg.Uri, - msg.Payload); - }; break; - - case MessageType_HttpRequestSuccess: - { - const HttpRequestSuccessMessage& msg = dynamic_cast<const HttpRequestSuccessMessage&>(message); - OnHttpRequestSuccess(msg.Uri, - msg.Answer, - msg.AnswerSize, - msg.Payload); - }; break; - default: - VLOG("unhandled message type" << message.GetType()); - } - } - - virtual void OnHttpRequestError(const std::string& uri, - Orthanc::IDynamicObject* payload) = 0; - - virtual void OnHttpRequestSuccess(const std::string& uri, - const void* answer, - size_t answerSize, - Orthanc::IDynamicObject* payload) = 0; - }; IWebService(MessageBroker& broker) : broker_(broker) @@ -158,15 +85,15 @@ virtual void GetAsync(const std::string& uri, const Headers& headers, Orthanc::IDynamicObject* payload, - MessageHandler<IWebService::NewHttpRequestSuccessMessage>* successCallback, - MessageHandler<IWebService::NewHttpRequestErrorMessage>* failureCallback) = 0; + MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback) = 0; virtual void PostAsync(const std::string& uri, const Headers& headers, const std::string& body, Orthanc::IDynamicObject* payload, - MessageHandler<IWebService::NewHttpRequestSuccessMessage>* successCallback, - MessageHandler<IWebService::NewHttpRequestErrorMessage>* failureCallback) = 0; + MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback) = 0; }; }