# HG changeset patch # User Sebastien Jodogne # Date 1404475793 -7200 # Node ID db18c071fbd7dcc32d0e57c70f1c834f1a52a836 # Parent 4136fab6a63992e2b8ecc81d238dfbee2d786562 store-scu filter diff -r 4136fab6a639 -r db18c071fbd7 CMakeLists.txt --- a/CMakeLists.txt Thu Jul 03 18:30:23 2014 +0200 +++ b/CMakeLists.txt Fri Jul 04 14:09:53 2014 +0200 @@ -157,6 +157,7 @@ OrthancServer/Scheduler/ServerFilterInstance.cpp OrthancServer/Scheduler/ServerJob.cpp OrthancServer/Scheduler/ServerScheduler.cpp + OrthancServer/Scheduler/StoreScuFilter.cpp ) diff -r 4136fab6a639 -r db18c071fbd7 OrthancServer/OrthancRestApi/OrthancRestModalities.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Thu Jul 03 18:30:23 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Fri Jul 04 14:09:53 2014 +0200 @@ -36,6 +36,8 @@ #include "../OrthancInitialization.h" #include "../../Core/HttpClient.h" #include "../FromDcmtkBridge.h" +#include "../Scheduler/ServerJob.h" +#include "../Scheduler/StoreScuFilter.h" #include @@ -321,17 +323,16 @@ } RemoteModalityParameters p = Configuration::GetModalityUsingSymbolicName(remote); - ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), p); + ServerJob job; for (std::list::const_iterator it = instances.begin(); it != instances.end(); ++it) { - LOG(INFO) << "Sending resource " << *it << " to modality \"" << remote << "\""; + job.AddFilter(new StoreScuFilter(context, p)).AddInput(*it); + } - std::string dicom; - context.ReadFile(dicom, *it, FileContentType_Dicom); - locker.GetConnection().Store(dicom); - } + job.SetDescription("Store-SCU from HTTP to modality \"" + remote + "\""); + context.GetScheduler().SubmitAndWait(job); call.GetOutput().AnswerBuffer("{}", "application/json"); } diff -r 4136fab6a639 -r db18c071fbd7 OrthancServer/Scheduler/IServerFilter.h --- a/OrthancServer/Scheduler/IServerFilter.h Thu Jul 03 18:30:23 2014 +0200 +++ b/OrthancServer/Scheduler/IServerFilter.h Fri Jul 04 14:09:53 2014 +0200 @@ -34,10 +34,11 @@ #include #include +#include namespace Orthanc { - class IServerFilter + class IServerFilter : public boost::noncopyable { public: typedef std::list ListOfStrings; diff -r 4136fab6a639 -r db18c071fbd7 OrthancServer/Scheduler/ServerJob.h --- a/OrthancServer/Scheduler/ServerJob.h Thu Jul 03 18:30:23 2014 +0200 +++ b/OrthancServer/Scheduler/ServerJob.h Fri Jul 04 14:09:53 2014 +0200 @@ -62,7 +62,7 @@ return jobId_; } - void SetDescription(const char* description) + void SetDescription(const std::string& description) { description_ = description; } diff -r 4136fab6a639 -r db18c071fbd7 OrthancServer/Scheduler/ServerScheduler.cpp --- a/OrthancServer/Scheduler/ServerScheduler.cpp Thu Jul 03 18:30:23 2014 +0200 +++ b/OrthancServer/Scheduler/ServerScheduler.cpp Fri Jul 04 14:09:53 2014 +0200 @@ -271,6 +271,13 @@ } + bool ServerScheduler::SubmitAndWait(ServerJob& job) + { + ListOfStrings ignoredSink; + return SubmitAndWait(ignoredSink, job); + } + + bool ServerScheduler::IsRunning(const std::string& jobId) { boost::mutex::scoped_lock lock(mutex_); diff -r 4136fab6a639 -r db18c071fbd7 OrthancServer/Scheduler/ServerScheduler.h --- a/OrthancServer/Scheduler/ServerScheduler.h Thu Jul 03 18:30:23 2014 +0200 +++ b/OrthancServer/Scheduler/ServerScheduler.h Fri Jul 04 14:09:53 2014 +0200 @@ -91,6 +91,8 @@ bool SubmitAndWait(ListOfStrings& outputs, ServerJob& job); + bool SubmitAndWait(ServerJob& job); + bool IsRunning(const std::string& jobId); void Cancel(const std::string& jobId); diff -r 4136fab6a639 -r db18c071fbd7 OrthancServer/Scheduler/StoreScuFilter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/Scheduler/StoreScuFilter.cpp Fri Jul 04 14:09:53 2014 +0200 @@ -0,0 +1,65 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * 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 . + **/ + + +#include "StoreScuFilter.h" + +#include + +namespace Orthanc +{ + StoreScuFilter::StoreScuFilter(ServerContext& context, + const RemoteModalityParameters& modality) : + context_(context), + modality_(modality) + { + } + + bool StoreScuFilter::Apply(ListOfStrings& outputs, + const ListOfStrings& inputs) + { + + ReusableDicomUserConnection::Locker locker(context_.GetReusableDicomUserConnection(), modality_); + + for (ListOfStrings::const_iterator + it = inputs.begin(); it != inputs.end(); ++it) + { + LOG(INFO) << "Sending resource " << *it << " to modality \"" + << modality_.GetApplicationEntityTitle() << "\""; + + std::string dicom; + context_.ReadFile(dicom, *it, FileContentType_Dicom); + locker.GetConnection().Store(dicom); + } + + return true; + } +} diff -r 4136fab6a639 -r db18c071fbd7 OrthancServer/Scheduler/StoreScuFilter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/Scheduler/StoreScuFilter.h Fri Jul 04 14:09:53 2014 +0200 @@ -0,0 +1,58 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * 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 "IServerFilter.h" +#include "../ServerContext.h" + +namespace Orthanc +{ + class StoreScuFilter : public IServerFilter + { + private: + ServerContext& context_; + RemoteModalityParameters modality_; + + public: + StoreScuFilter(ServerContext& context, + const RemoteModalityParameters& modality); + + bool Apply(ListOfStrings& outputs, + const ListOfStrings& inputs); + + bool SendOutputsToSink() const + { + return false; + } + }; +}