Mercurial > hg > orthanc-stone
changeset 57:d20e25cfcf3a wasm
IWebService
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 May 2017 14:45:21 +0200 |
parents | 9e3c2e75b870 |
children | 468c48eaa01c |
files | Applications/BasicApplicationContext.cpp Applications/BasicApplicationContext.h Applications/IBasicApplication.cpp Applications/Samples/SingleFrameApplication.h Applications/Samples/SynchronizedSeriesApplication.h Framework/Toolbox/IWebService.h Framework/Toolbox/MessagingToolbox.h Framework/Toolbox/OrthancWebService.cpp Framework/Toolbox/OrthancWebService.h Resources/CMake/OrthancStone.cmake Resources/Orthanc/Core/IDynamicObject.h Resources/SyncOrthancFolder.py |
diffstat | 12 files changed, 274 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/BasicApplicationContext.cpp Fri Apr 28 21:46:41 2017 +0200 +++ b/Applications/BasicApplicationContext.cpp Wed May 03 14:45:21 2017 +0200 @@ -41,7 +41,7 @@ } - BasicApplicationContext::BasicApplicationContext(OrthancPlugins::IOrthancConnection& orthanc) : + BasicApplicationContext::BasicApplicationContext(OrthancWebService& orthanc) : orthanc_(orthanc), stopped_(true), updateDelay_(100) // By default, 100ms between each refresh of the content @@ -82,7 +82,8 @@ bool isProgressiveDownload, size_t downloadThreadCount) { - std::auto_ptr<VolumeImage> volume(new VolumeImage(new OrthancSeriesLoader(orthanc_, series))); + std::auto_ptr<VolumeImage> volume + (new VolumeImage(new OrthancSeriesLoader(GetWebService().GetConnection(), series))); if (isProgressiveDownload) { @@ -104,7 +105,8 @@ DicomStructureSet& BasicApplicationContext::AddStructureSet(const std::string& instance) { - std::auto_ptr<DicomStructureSet> structureSet(new DicomStructureSet(orthanc_, instance)); + std::auto_ptr<DicomStructureSet> structureSet + (new DicomStructureSet(GetWebService().GetConnection(), instance)); DicomStructureSet& result = *structureSet; structureSets_.push_back(structureSet.release());
--- a/Applications/BasicApplicationContext.h Fri Apr 28 21:46:41 2017 +0200 +++ b/Applications/BasicApplicationContext.h Wed May 03 14:45:21 2017 +0200 @@ -25,6 +25,7 @@ #include "../../Framework/Viewport/WidgetViewport.h" #include "../../Framework/Widgets/IWorldSceneInteractor.h" #include "../../Framework/Toolbox/DicomStructureSet.h" +#include "../../Framework/Toolbox/OrthancWebService.h" #include <list> #include <boost/thread.hpp> @@ -40,16 +41,15 @@ static void UpdateThread(BasicApplicationContext* that); - OrthancPlugins::IOrthancConnection& orthanc_; - - boost::mutex viewportMutex_; - WidgetViewport viewport_; - Volumes volumes_; - Interactors interactors_; - StructureSets structureSets_; - boost::thread updateThread_; - bool stopped_; - unsigned int updateDelay_; + OrthancWebService& orthanc_; + boost::mutex viewportMutex_; + WidgetViewport viewport_; + Volumes volumes_; + Interactors interactors_; + StructureSets structureSets_; + boost::thread updateThread_; + bool stopped_; + unsigned int updateDelay_; public: class ViewportLocker : public boost::noncopyable @@ -72,17 +72,17 @@ }; - BasicApplicationContext(OrthancPlugins::IOrthancConnection& orthanc); + BasicApplicationContext(OrthancWebService& orthanc); ~BasicApplicationContext(); IWidget& SetCentralWidget(IWidget* widget); // Takes ownership - OrthancPlugins::IOrthancConnection& GetOrthancConnection() + OrthancWebService& GetWebService() { return orthanc_; } - + VolumeImage& AddSeriesVolume(const std::string& series, bool isProgressiveDownload, size_t downloadThreadCount);
--- a/Applications/IBasicApplication.cpp Fri Apr 28 21:46:41 2017 +0200 +++ b/Applications/IBasicApplication.cpp Wed May 03 14:45:21 2017 +0200 @@ -197,9 +197,9 @@ } LOG(WARNING) << "URL to the Orthanc REST API: " << webService.GetUrl(); - OrthancPlugins::OrthancHttpConnection orthanc(webService); + OrthancWebService orthanc(webService); - if (!MessagingToolbox::CheckOrthancVersion(orthanc)) + if (!MessagingToolbox::CheckOrthancVersion(orthanc.GetConnection())) { LOG(ERROR) << "Your version of Orthanc is incompatible with Orthanc Stone, please upgrade"; throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
--- a/Applications/Samples/SingleFrameApplication.h Fri Apr 28 21:46:41 2017 +0200 +++ b/Applications/Samples/SingleFrameApplication.h Wed May 03 14:45:21 2017 +0200 @@ -65,7 +65,8 @@ int frame = parameters["frame"].as<unsigned int>(); std::auto_ptr<SingleFrameRendererFactory> renderer; - renderer.reset(new SingleFrameRendererFactory(context.GetOrthancConnection(), instance, frame)); + renderer.reset + (new SingleFrameRendererFactory(context.GetWebService().GetConnection(), instance, frame)); std::auto_ptr<LayeredSceneWidget> widget(new LayeredSceneWidget); widget->SetSlice(renderer->GetSliceGeometry());
--- a/Applications/Samples/SynchronizedSeriesApplication.h Fri Apr 28 21:46:41 2017 +0200 +++ b/Applications/Samples/SynchronizedSeriesApplication.h Wed May 03 14:45:21 2017 +0200 @@ -39,7 +39,8 @@ LayeredSceneWidget* CreateSeriesWidget(BasicApplicationContext& context, const std::string& series) { - std::auto_ptr<ISeriesLoader> loader(new OrthancSeriesLoader(context.GetOrthancConnection(), series)); + std::auto_ptr<ISeriesLoader> loader + (new OrthancSeriesLoader(context.GetWebService().GetConnection(), series)); std::auto_ptr<SampleInteractor> interactor(new SampleInteractor(*loader, false));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Toolbox/IWebService.h Wed May 03 14:45:21 2017 +0200 @@ -0,0 +1,59 @@ +/** + * 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 "../../Resources/Orthanc/Core/IDynamicObject.h" + +#include <string> + +namespace OrthancStone +{ + class IWebService : public boost::noncopyable + { + public: + class IRequestObserver : public boost::noncopyable + { + public: + virtual ~IRequestObserver() + { + } + + virtual void NotifyError(Orthanc::IDynamicObject* payload) = 0; + + virtual void NotifyAnswer(const std::string& answer, + Orthanc::IDynamicObject* payload) = 0; + }; + + virtual ~IWebService() + { + } + + virtual void ScheduleGetRequest(IRequestObserver& observer, + const std::string& uri, + Orthanc::IDynamicObject* payload) = 0; + + virtual void SchedulePostRequest(IRequestObserver& observer, + const std::string& uri, + const std::string& body, + Orthanc::IDynamicObject* payload) = 0; + }; +}
--- a/Framework/Toolbox/MessagingToolbox.h Fri Apr 28 21:46:41 2017 +0200 +++ b/Framework/Toolbox/MessagingToolbox.h Wed May 03 14:45:21 2017 +0200 @@ -38,7 +38,7 @@ { namespace MessagingToolbox { - class Timestamp + class Timestamp // TODO REMOVE THIS { private: #if defined(__native_client__)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Toolbox/OrthancWebService.cpp Wed May 03 14:45:21 2017 +0200 @@ -0,0 +1,79 @@ +/** + * 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 "OrthancWebService.h" + +#include "../../Resources/Orthanc/Core/OrthancException.h" +#include "../../Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.h" + +namespace OrthancStone +{ + OrthancWebService::OrthancWebService(OrthancPlugins::IOrthancConnection* orthanc) : + orthanc_(orthanc) + { + if (orthanc == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); + } + } + + OrthancWebService::OrthancWebService(const Orthanc::WebServiceParameters& parameters) + { + orthanc_.reset(new OrthancPlugins::OrthancHttpConnection(parameters)); + } + + void OrthancWebService::ScheduleGetRequest(IRequestObserver& observer, + const std::string& uri, + Orthanc::IDynamicObject* payload) + { + std::auto_ptr<Orthanc::IDynamicObject> tmp(payload); + + try + { + std::string answer; + orthanc_->RestApiGet(answer, uri); + observer.NotifyAnswer(answer, tmp.release()); + } + catch (Orthanc::OrthancException&) + { + observer.NotifyError(tmp.release()); + } + } + + void OrthancWebService::SchedulePostRequest(IRequestObserver& observer, + 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); + observer.NotifyAnswer(answer, tmp.release()); + } + catch (Orthanc::OrthancException&) + { + observer.NotifyError(tmp.release()); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Toolbox/OrthancWebService.h Wed May 03 14:45:21 2017 +0200 @@ -0,0 +1,56 @@ +/** + * 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> + +namespace OrthancStone +{ + class OrthancWebService : public IWebService + { + private: + std::auto_ptr<OrthancPlugins::IOrthancConnection> orthanc_; + + public: + OrthancWebService(OrthancPlugins::IOrthancConnection* orthanc); // Takes ownership + + OrthancWebService(const Orthanc::WebServiceParameters& parameters); + + OrthancPlugins::IOrthancConnection& GetConnection() + { + return *orthanc_; + } + + virtual void ScheduleGetRequest(IRequestObserver& observer, + const std::string& uri, + Orthanc::IDynamicObject* payload); + + virtual void SchedulePostRequest(IRequestObserver& observer, + const std::string& uri, + const std::string& body, + Orthanc::IDynamicObject* payload); + }; +}
--- a/Resources/CMake/OrthancStone.cmake Fri Apr 28 21:46:41 2017 +0200 +++ b/Resources/CMake/OrthancStone.cmake Wed May 03 14:45:21 2017 +0200 @@ -197,6 +197,7 @@ ${ORTHANC_STONE_DIR}/Framework/Toolbox/DicomStructureSet.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/DownloadStack.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/GeometryToolbox.cpp + ${ORTHANC_STONE_DIR}/Framework/Toolbox/OrthancWebService.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/MessagingToolbox.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/OrthancSeriesLoader.cpp ${ORTHANC_STONE_DIR}/Framework/Toolbox/ParallelSlices.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Core/IDynamicObject.h Wed May 03 14:45:21 2017 +0200 @@ -0,0 +1,53 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * 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 General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include <boost/noncopyable.hpp> + +namespace Orthanc +{ + /** + * This class should be the ancestor to any class whose type is + * determined at the runtime, and that can be dynamically allocated. + * Being a child of IDynamicObject only implies the existence of a + * virtual destructor. + **/ + class IDynamicObject : public boost::noncopyable + { + public: + virtual ~IDynamicObject() + { + } + }; +}
--- a/Resources/SyncOrthancFolder.py Fri Apr 28 21:46:41 2017 +0200 +++ b/Resources/SyncOrthancFolder.py Wed May 03 14:45:21 2017 +0200 @@ -26,6 +26,7 @@ 'Core/Enumerations.h', 'Core/HttpClient.cpp', 'Core/HttpClient.h', + 'Core/IDynamicObject.h', 'Core/Images/Image.cpp', 'Core/Images/Image.h', 'Core/Images/ImageAccessor.cpp',