Mercurial > hg > orthanc-stone
changeset 82:cee8f308a4bc wasm
Getting rid of Orthanc*WebService
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 24 May 2017 23:05:10 +0200 |
parents | 8677d95753f8 |
children | c75377306598 |
files | Applications/BasicApplicationContext.h Applications/IBasicApplication.cpp Framework/Toolbox/OrthancAsynchronousWebService.cpp Framework/Toolbox/OrthancAsynchronousWebService.h Framework/Toolbox/OrthancSynchronousWebService.cpp Framework/Toolbox/OrthancSynchronousWebService.h Resources/CMake/OrthancStone.cmake Resources/OrthancStone.doxygen UnitTestsSources/UnitTestsMain.cpp |
diffstat | 9 files changed, 3 insertions(+), 471 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/BasicApplicationContext.h Wed May 24 22:54:09 2017 +0200 +++ b/Applications/BasicApplicationContext.h Wed May 24 23:05:10 2017 +0200 @@ -25,7 +25,6 @@ #include "../../Framework/Viewport/WidgetViewport.h" #include "../../Framework/Widgets/IWorldSceneInteractor.h" #include "../../Framework/Toolbox/DicomStructureSet.h" -#include "../../Framework/Toolbox/OrthancSynchronousWebService.h" #include "../../Platforms/Generic/OracleWebService.h" #include <list>
--- a/Applications/IBasicApplication.cpp Wed May 24 22:54:09 2017 +0200 +++ b/Applications/IBasicApplication.cpp Wed May 24 23:05:10 2017 +0200 @@ -199,9 +199,8 @@ LOG(WARNING) << "URL to the Orthanc REST API: " << webService.GetUrl(); { - OrthancSynchronousWebService orthanc(webService); - - if (!MessagingToolbox::CheckOrthancVersion(orthanc.GetConnection())) + OrthancPlugins::OrthancHttpConnection orthanc(webService); + if (!MessagingToolbox::CheckOrthancVersion(orthanc)) { LOG(ERROR) << "Your version of Orthanc is incompatible with Orthanc Stone, please upgrade"; throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
--- a/Framework/Toolbox/OrthancAsynchronousWebService.cpp Wed May 24 22:54:09 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,269 +0,0 @@ -/** - * Stone of Orthanc - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017 Osimis, Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - **/ - - -#include "OrthancAsynchronousWebService.h" - -#include "../../Resources/Orthanc/Core/Logging.h" -#include "../../Resources/Orthanc/Core/OrthancException.h" -#include "../../Resources/Orthanc/Core/MultiThreading/SharedMessageQueue.h" -#include "../../Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.h" - -namespace OrthancStone -{ - class OrthancAsynchronousWebService::PendingRequest : public Orthanc::IDynamicObject - { - private: - bool isPost_; - ICallback& callback_; - std::string uri_; - std::string body_; - std::auto_ptr<Orthanc::IDynamicObject> payload_; - - PendingRequest(bool isPost, - ICallback& callback, - const std::string& uri, - const std::string& body, - Orthanc::IDynamicObject* payload) : - isPost_(isPost), - callback_(callback), - uri_(uri), - body_(body), - payload_(payload) - { - } - - public: - static PendingRequest* CreateGetRequest(ICallback& callback, - const std::string& uri, - Orthanc::IDynamicObject* payload) - { - return new PendingRequest(false, callback, uri, "", payload); - } - - static PendingRequest* CreatePostRequest(ICallback& callback, - const std::string& uri, - const std::string& body, - Orthanc::IDynamicObject* payload) - { - return new PendingRequest(true, callback, uri, body, payload); - } - - void Execute(OrthancPlugins::OrthancHttpConnection& connection) - { - if (payload_.get() == NULL) - { - // Execute() has already been invoked - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); - } - - std::string answer; - - try - { - if (isPost_) - { - connection.RestApiPost(answer, uri_, body_); - } - else - { - connection.RestApiGet(answer, uri_); - } - } - catch (Orthanc::OrthancException&) - { - callback_.NotifyError(uri_, payload_.release()); - return; - } - - callback_.NotifySuccess(uri_, answer.c_str(), answer.size(), payload_.release()); - } - }; - - class OrthancAsynchronousWebService::PImpl : public boost::noncopyable - { - private: - enum State - { - State_Init, - State_Started, - State_Stopped - }; - - boost::mutex mutex_; - State state_; - Orthanc::WebServiceParameters orthanc_; - std::vector<boost::thread*> threads_; - Orthanc::SharedMessageQueue queue_; - - static void Worker(PImpl* that) - { - OrthancPlugins::OrthancHttpConnection connection(that->orthanc_); - - for (;;) - { - State state; - - { - boost::mutex::scoped_lock lock(that->mutex_); - state = that->state_; - } - - if (state == State_Stopped) - { - break; - } - - std::auto_ptr<Orthanc::IDynamicObject> request(that->queue_.Dequeue(100)); - if (request.get() != NULL) - { - dynamic_cast<PendingRequest&>(*request).Execute(connection); - } - } - } - - public: - PImpl(const Orthanc::WebServiceParameters& orthanc, - unsigned int threadCount) : - state_(State_Init), - orthanc_(orthanc), - threads_(threadCount) - { - } - - ~PImpl() - { - if (state_ == State_Started) - { - LOG(ERROR) << "You should have manually called OrthancAsynchronousWebService::Stop()"; - Stop(); - } - } - - void Schedule(PendingRequest* request) - { - std::auto_ptr<PendingRequest> protection(request); - - if (request == NULL) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); - } - - boost::mutex::scoped_lock lock(mutex_); - - switch (state_) - { - case State_Init: - LOG(ERROR) << "You must call OrthancAsynchronousWebService::Start()"; - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); - - case State_Started: - queue_.Enqueue(protection.release()); - break; - - case State_Stopped: - LOG(ERROR) << "Cannot schedule a Web request after having " - << "called OrthancAsynchronousWebService::Stop()"; - break; - - default: - throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); - } - - } - - void Start() - { - boost::mutex::scoped_lock lock(mutex_); - - if (state_ != State_Init) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); - } - - for (size_t i = 0; i < threads_.size(); i++) - { - threads_[i] = new boost::thread(Worker, this); - } - - state_ = State_Started; - } - - void Stop() - { - { - boost::mutex::scoped_lock lock(mutex_); - - if (state_ != State_Started) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); - } - - state_ = State_Stopped; - } - - for (size_t i = 0; i < threads_.size(); i++) - { - if (threads_[i] != NULL) - { - if (threads_[i]->joinable()) - { - threads_[i]->join(); - } - - delete threads_[i]; - } - } - } - }; - - OrthancAsynchronousWebService::OrthancAsynchronousWebService( - const Orthanc::WebServiceParameters& parameters, - unsigned int threadCount) : - pimpl_(new PImpl(parameters, threadCount)) - { - } - - void OrthancAsynchronousWebService::ScheduleGetRequest(ICallback& callback, - const std::string& uri, - Orthanc::IDynamicObject* payload) - { - pimpl_->Schedule(PendingRequest::CreateGetRequest(callback, uri, payload)); - } - - - void OrthancAsynchronousWebService::SchedulePostRequest(ICallback& callback, - const std::string& uri, - const std::string& body, - Orthanc::IDynamicObject* payload) - { - pimpl_->Schedule(PendingRequest::CreatePostRequest(callback, uri, body, payload)); - } - - void OrthancAsynchronousWebService::Start() - { - pimpl_->Start(); - } - - void OrthancAsynchronousWebService::Stop() - { - pimpl_->Stop(); - } -}
--- a/Framework/Toolbox/OrthancAsynchronousWebService.h Wed May 24 22:54:09 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/** - * Stone of Orthanc - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017 Osimis, Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - **/ - - -#pragma once - -#include "IWebService.h" -#include "../../Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.h" -#include "../../Resources/Orthanc/Core/WebServiceParameters.h" - -#include <boost/shared_ptr.hpp> - -namespace OrthancStone -{ - class OrthancAsynchronousWebService : public IWebService - { - private: - class PendingRequest; - class PImpl; - - boost::shared_ptr<PImpl> pimpl_; - - public: - OrthancAsynchronousWebService(const Orthanc::WebServiceParameters& parameters, - unsigned int threadCount); - - virtual void ScheduleGetRequest(ICallback& callback, - const std::string& uri, - Orthanc::IDynamicObject* payload); - - virtual void SchedulePostRequest(ICallback& callback, - const std::string& uri, - const std::string& body, - Orthanc::IDynamicObject* payload); - - void Start(); - - void Stop(); - }; -}
--- a/Framework/Toolbox/OrthancSynchronousWebService.cpp Wed May 24 22:54:09 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/** - * Stone of Orthanc - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017 Osimis, Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - **/ - - -#include "OrthancSynchronousWebService.h" - -#include "../../Resources/Orthanc/Core/OrthancException.h" -#include "../../Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.h" - -namespace OrthancStone -{ - OrthancSynchronousWebService::OrthancSynchronousWebService(OrthancPlugins::IOrthancConnection* orthanc) : - orthanc_(orthanc) - { - if (orthanc == NULL) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); - } - } - - OrthancSynchronousWebService::OrthancSynchronousWebService(const Orthanc::WebServiceParameters& parameters) - { - orthanc_.reset(new OrthancPlugins::OrthancHttpConnection(parameters)); - } - - void OrthancSynchronousWebService::ScheduleGetRequest(ICallback& callback, - const std::string& uri, - Orthanc::IDynamicObject* payload) - { - std::auto_ptr<Orthanc::IDynamicObject> tmp(payload); - - try - { - std::string answer; - orthanc_->RestApiGet(answer, uri); - callback.NotifySuccess(uri, answer.c_str(), answer.size(), tmp.release()); - } - catch (Orthanc::OrthancException&) - { - callback.NotifyError(uri, tmp.release()); - } - } - - void OrthancSynchronousWebService::SchedulePostRequest(ICallback& callback, - const std::string& uri, - const std::string& body, - Orthanc::IDynamicObject* payload) - { - std::auto_ptr<Orthanc::IDynamicObject> tmp(payload); - - try - { - std::string answer; - orthanc_->RestApiPost(answer, uri, body); - callback.NotifySuccess(uri, answer.c_str(), answer.size(), tmp.release()); - } - catch (Orthanc::OrthancException&) - { - callback.NotifyError(uri, tmp.release()); - } - } -}
--- a/Framework/Toolbox/OrthancSynchronousWebService.h Wed May 24 22:54:09 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/** - * Stone of Orthanc - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017 Osimis, Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - **/ - - -#pragma once - -#include "IWebService.h" -#include "../../Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.h" -#include "../../Resources/Orthanc/Core/WebServiceParameters.h" - -#include <memory> - -// TODO REMOVE THIS - -namespace OrthancStone -{ - class OrthancSynchronousWebService : public IWebService - { - private: - std::auto_ptr<OrthancPlugins::IOrthancConnection> orthanc_; - - public: - OrthancSynchronousWebService(OrthancPlugins::IOrthancConnection* orthanc); // Takes ownership - - OrthancSynchronousWebService(const Orthanc::WebServiceParameters& parameters); - - OrthancPlugins::IOrthancConnection& GetConnection() - { - return *orthanc_; - } - - virtual void ScheduleGetRequest(ICallback& callback, - const std::string& uri, - Orthanc::IDynamicObject* payload); - - virtual void SchedulePostRequest(ICallback& callback, - const std::string& uri, - const std::string& body, - Orthanc::IDynamicObject* payload); - }; -}
--- a/Resources/CMake/OrthancStone.cmake Wed May 24 22:54:09 2017 +0200 +++ b/Resources/CMake/OrthancStone.cmake Wed May 24 23:05:10 2017 +0200 @@ -206,10 +206,8 @@ ${ORTHANC_STONE_DIR}/Framework/Toolbox/DownloadStack.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/GeometryToolbox.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/MessagingToolbox.cpp - ${ORTHANC_STONE_DIR}/Framework/Toolbox/OrthancAsynchronousWebService.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/OrthancSeriesLoader.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/OrthancSlicesLoader.cpp - ${ORTHANC_STONE_DIR}/Framework/Toolbox/OrthancSynchronousWebService.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/ParallelSlices.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/ParallelSlicesCursor.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/Slice.cpp
--- a/Resources/OrthancStone.doxygen Wed May 24 22:54:09 2017 +0200 +++ b/Resources/OrthancStone.doxygen Wed May 24 23:05:10 2017 +0200 @@ -655,7 +655,7 @@ # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = @ORTHANC_STONE_DIR@/Framework +INPUT = @ORTHANC_STONE_DIR@/Framework @ORTHANC_STONE_DIR@/Platforms # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
--- a/UnitTestsSources/UnitTestsMain.cpp Wed May 24 22:54:09 2017 +0200 +++ b/UnitTestsSources/UnitTestsMain.cpp Wed May 24 23:05:10 2017 +0200 @@ -22,7 +22,6 @@ #include "gtest/gtest.h" #include "../Platforms/Generic/OracleWebService.h" -#include "../Framework/Toolbox/OrthancAsynchronousWebService.h" #include "../Framework/Toolbox/OrthancSlicesLoader.h" #include "../Resources/Orthanc/Core/HttpClient.h" #include "../Resources/Orthanc/Core/Logging.h"