# HG changeset patch # User Alain Mazy # Date 1562141482 -7200 # Node ID debb70fa10b5e88b93a6794ff0689f343c5a59a1 # Parent 78f4317eb94bd5385555c8ed2d59725bfa1857a5 correct handling of deleted observers in OrthancApiClient diff -r 78f4317eb94b -r debb70fa10b5 Framework/Deprecated/Toolbox/OrthancApiClient.cpp --- a/Framework/Deprecated/Toolbox/OrthancApiClient.cpp Mon Jul 01 18:18:58 2019 +0200 +++ b/Framework/Deprecated/Toolbox/OrthancApiClient.cpp Wed Jul 03 10:11:22 2019 +0200 @@ -73,7 +73,7 @@ std::auto_ptr< OrthancStone::MessageHandler > binaryHandler_; std::auto_ptr< OrthancStone::MessageHandler > failureHandler_; std::auto_ptr< Orthanc::IDynamicObject > userPayload_; - + OrthancStone::MessageBroker& broker_; void NotifyConversionError(const IWebService::HttpRequestSuccessMessage& message) const { if (failureHandler_.get() != NULL) @@ -84,12 +84,15 @@ } public: - WebServicePayload(OrthancStone::MessageHandler* handler, + WebServicePayload(OrthancStone::MessageBroker& broker, + OrthancStone::MessageHandler* handler, OrthancStone::MessageHandler* failureHandler, Orthanc::IDynamicObject* userPayload) : emptyHandler_(handler), failureHandler_(failureHandler), - userPayload_(userPayload) + userPayload_(userPayload), + broker_(broker) + { if (handler == NULL) { @@ -97,12 +100,14 @@ } } - WebServicePayload(OrthancStone::MessageHandler* handler, + WebServicePayload(OrthancStone::MessageBroker& broker, + OrthancStone::MessageHandler* handler, OrthancStone::MessageHandler* failureHandler, Orthanc::IDynamicObject* userPayload) : binaryHandler_(handler), failureHandler_(failureHandler), - userPayload_(userPayload) + userPayload_(userPayload), + broker_(broker) { if (handler == NULL) { @@ -110,12 +115,14 @@ } } - WebServicePayload(OrthancStone::MessageHandler* handler, + WebServicePayload(OrthancStone::MessageBroker& broker, + OrthancStone::MessageHandler* handler, OrthancStone::MessageHandler* failureHandler, Orthanc::IDynamicObject* userPayload) : jsonHandler_(handler), failureHandler_(failureHandler), - userPayload_(userPayload) + userPayload_(userPayload), + broker_(broker) { if (handler == NULL) { @@ -127,26 +134,35 @@ { if (emptyHandler_.get() != NULL) { - emptyHandler_->Apply(OrthancApiClient::EmptyResponseReadyMessage - (message.GetUri(), userPayload_.get())); + if (broker_.IsActive(*(emptyHandler_->GetObserver()))) + { + emptyHandler_->Apply(OrthancApiClient::EmptyResponseReadyMessage + (message.GetUri(), userPayload_.get())); + } } else if (binaryHandler_.get() != NULL) { - binaryHandler_->Apply(OrthancApiClient::BinaryResponseReadyMessage - (message.GetUri(), message.GetAnswer(), - message.GetAnswerSize(), userPayload_.get())); + if (broker_.IsActive(*(binaryHandler_->GetObserver()))) + { + binaryHandler_->Apply(OrthancApiClient::BinaryResponseReadyMessage + (message.GetUri(), message.GetAnswer(), + message.GetAnswerSize(), userPayload_.get())); + } } else if (jsonHandler_.get() != NULL) { - Json::Value response; - if (MessagingToolbox::ParseJson(response, message.GetAnswer(), message.GetAnswerSize())) + if (broker_.IsActive(*(jsonHandler_->GetObserver()))) { - jsonHandler_->Apply(OrthancApiClient::JsonResponseReadyMessage - (message.GetUri(), response, userPayload_.get())); - } - else - { - NotifyConversionError(message); + Json::Value response; + if (MessagingToolbox::ParseJson(response, message.GetAnswer(), message.GetAnswerSize())) + { + jsonHandler_->Apply(OrthancApiClient::JsonResponseReadyMessage + (message.GetUri(), response, userPayload_.get())); + } + else + { + NotifyConversionError(message); + } } } else @@ -186,7 +202,7 @@ IWebService::HttpHeaders emptyHeaders; web_.GetAsync(baseUrl_ + uri, emptyHeaders, - new WebServicePayload(successCallback, failureCallback, payload), + new WebServicePayload(IObservable::GetBroker(), successCallback, failureCallback, payload), new OrthancStone::Callable (*this, &OrthancApiClient::NotifyHttpSuccess), new OrthancStone::Callable @@ -216,7 +232,7 @@ // printf("GET [%s] [%s]\n", baseUrl_.c_str(), uri.c_str()); web_.GetAsync(baseUrl_ + uri, headers, - new WebServicePayload(successCallback, failureCallback, payload), + new WebServicePayload(IObservable::GetBroker(), successCallback, failureCallback, payload), new OrthancStone::Callable (*this, &OrthancApiClient::NotifyHttpSuccess), new OrthancStone::Callable @@ -232,7 +248,7 @@ Orthanc::IDynamicObject* payload) { web_.PostAsync(baseUrl_ + uri, IWebService::HttpHeaders(), body, - new WebServicePayload(successCallback, failureCallback, payload), + new WebServicePayload(IObservable::GetBroker(), successCallback, failureCallback, payload), new OrthancStone::Callable (*this, &OrthancApiClient::NotifyHttpSuccess), new OrthancStone::Callable @@ -255,7 +271,7 @@ Orthanc::IDynamicObject* payload /* takes ownership */) { web_.PostAsync(baseUrl_ + uri, IWebService::HttpHeaders(), body, - new WebServicePayload(successCallback, failureCallback, payload), + new WebServicePayload(IObservable::GetBroker(), successCallback, failureCallback, payload), new OrthancStone::Callable (*this, &OrthancApiClient::NotifyHttpSuccess), new OrthancStone::Callable @@ -302,7 +318,7 @@ Orthanc::IDynamicObject* payload) { web_.DeleteAsync(baseUrl_ + uri, IWebService::HttpHeaders(), - new WebServicePayload(successCallback, failureCallback, payload), + new WebServicePayload(IObservable::GetBroker(), successCallback, failureCallback, payload), new OrthancStone::Callable (*this, &OrthancApiClient::NotifyHttpSuccess), new OrthancStone::Callable