# HG changeset patch # User Sebastien Jodogne # Date 1493815521 -7200 # Node ID d20e25cfcf3acb30b2b82c95695cb7af34b2a67f # Parent 9e3c2e75b87055a915458526a85d361eaac17758 IWebService diff -r 9e3c2e75b870 -r d20e25cfcf3a Applications/BasicApplicationContext.cpp --- 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 volume(new VolumeImage(new OrthancSeriesLoader(orthanc_, series))); + std::auto_ptr volume + (new VolumeImage(new OrthancSeriesLoader(GetWebService().GetConnection(), series))); if (isProgressiveDownload) { @@ -104,7 +105,8 @@ DicomStructureSet& BasicApplicationContext::AddStructureSet(const std::string& instance) { - std::auto_ptr structureSet(new DicomStructureSet(orthanc_, instance)); + std::auto_ptr structureSet + (new DicomStructureSet(GetWebService().GetConnection(), instance)); DicomStructureSet& result = *structureSet; structureSets_.push_back(structureSet.release()); diff -r 9e3c2e75b870 -r d20e25cfcf3a Applications/BasicApplicationContext.h --- 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 #include @@ -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); diff -r 9e3c2e75b870 -r d20e25cfcf3a Applications/IBasicApplication.cpp --- 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); diff -r 9e3c2e75b870 -r d20e25cfcf3a Applications/Samples/SingleFrameApplication.h --- 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(); std::auto_ptr renderer; - renderer.reset(new SingleFrameRendererFactory(context.GetOrthancConnection(), instance, frame)); + renderer.reset + (new SingleFrameRendererFactory(context.GetWebService().GetConnection(), instance, frame)); std::auto_ptr widget(new LayeredSceneWidget); widget->SetSlice(renderer->GetSliceGeometry()); diff -r 9e3c2e75b870 -r d20e25cfcf3a Applications/Samples/SynchronizedSeriesApplication.h --- 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 loader(new OrthancSeriesLoader(context.GetOrthancConnection(), series)); + std::auto_ptr loader + (new OrthancSeriesLoader(context.GetWebService().GetConnection(), series)); std::auto_ptr interactor(new SampleInteractor(*loader, false)); diff -r 9e3c2e75b870 -r d20e25cfcf3a Framework/Toolbox/IWebService.h --- /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 . + **/ + + +#pragma once + +#include "../../Resources/Orthanc/Core/IDynamicObject.h" + +#include + +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; + }; +} diff -r 9e3c2e75b870 -r d20e25cfcf3a Framework/Toolbox/MessagingToolbox.h --- 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__) diff -r 9e3c2e75b870 -r d20e25cfcf3a Framework/Toolbox/OrthancWebService.cpp --- /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 . + **/ + + +#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 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 tmp(payload); + + try + { + std::string answer; + orthanc_->RestApiPost(answer, uri, body); + observer.NotifyAnswer(answer, tmp.release()); + } + catch (Orthanc::OrthancException&) + { + observer.NotifyError(tmp.release()); + } + } +} diff -r 9e3c2e75b870 -r d20e25cfcf3a Framework/Toolbox/OrthancWebService.h --- /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 . + **/ + + +#pragma once + +#include "IWebService.h" +#include "../../Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.h" +#include "../../Resources/Orthanc/Core/WebServiceParameters.h" + +#include + +namespace OrthancStone +{ + class OrthancWebService : public IWebService + { + private: + std::auto_ptr 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); + }; +} diff -r 9e3c2e75b870 -r d20e25cfcf3a Resources/CMake/OrthancStone.cmake --- 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 diff -r 9e3c2e75b870 -r d20e25cfcf3a Resources/Orthanc/Core/IDynamicObject.h --- /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 . + **/ + + +#pragma once + +#include + +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() + { + } + }; +} diff -r 9e3c2e75b870 -r d20e25cfcf3a Resources/SyncOrthancFolder.py --- 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',