Mercurial > hg > orthanc
changeset 806:557575fd93e9
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 07 May 2014 15:22:28 +0200 |
parents | 56a813a4714d |
children | 566a2fb3c1fb |
files | CMakeLists.txt OrthancServer/DicomProtocol/RemoteModalityParameters.cpp OrthancServer/DicomProtocol/RemoteModalityParameters.h OrthancServer/OrthancFindRequestHandler.cpp OrthancServer/OrthancInitialization.cpp OrthancServer/OrthancInitialization.h OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Resources/Samples/WebApplications/DrawingDicomizer/orthanc.js |
diffstat | 8 files changed, 195 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Wed May 07 13:23:08 2014 +0200 +++ b/CMakeLists.txt Wed May 07 15:22:28 2014 +0200 @@ -205,6 +205,7 @@ OrthancServer/DicomProtocol/DicomFindAnswers.cpp OrthancServer/DicomProtocol/DicomServer.cpp OrthancServer/DicomProtocol/DicomUserConnection.cpp + OrthancServer/DicomProtocol/RemoteModalityParameters.cpp OrthancServer/DicomProtocol/ReusableDicomUserConnection.cpp OrthancServer/DicomModification.cpp OrthancServer/FromDcmtkBridge.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/DicomProtocol/RemoteModalityParameters.cpp Wed May 07 15:22:28 2014 +0200 @@ -0,0 +1,57 @@ +/** + * 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 <http://www.gnu.org/licenses/>. + **/ + + +#include "RemoteModalityParameters.h" + +#include "../../Core/OrthancException.h" + +namespace Orthanc +{ + RemoteModalityParameters::RemoteModalityParameters() + { + name_ = ""; + aet_ = "ORTHANC"; + host_ = "localhost"; + port_ = 104; + manufacturer_ = ModalityManufacturer_Generic; + } + + void RemoteModalityParameters::SetPort(int port) + { + if (port <= 0 || port >= 65535) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + port_ = port; + } +}
--- a/OrthancServer/DicomProtocol/RemoteModalityParameters.h Wed May 07 13:23:08 2014 +0200 +++ b/OrthancServer/DicomProtocol/RemoteModalityParameters.h Wed May 07 15:22:28 2014 +0200 @@ -43,50 +43,23 @@ // TODO Use the flyweight pattern for this class private: - std::string symbolicName_; - std::string aet_; - std::string host_; - int port_; - ModalityManufacturer manufacturer_; + std::string name_; + std::string aet_; + std::string host_; + int port_; + ModalityManufacturer manufacturer_; public: - RemoteModalityParameters() : - symbolicName_(""), - aet_(""), - host_(""), - port_(104), - manufacturer_(ModalityManufacturer_Generic) + RemoteModalityParameters(); + + const std::string& GetName() const { + return name_; } - RemoteModalityParameters(const std::string& symbolic, - const std::string& aet, - const std::string& host, - int port, - ModalityManufacturer manufacturer) : - symbolicName_(symbolic), - aet_(aet), - host_(host), - port_(port), - manufacturer_(manufacturer) + void SetName(const std::string& name) { - } - - RemoteModalityParameters(const std::string& aet, - const std::string& host, - int port, - ModalityManufacturer manufacturer) : - symbolicName_(""), - aet_(aet), - host_(host), - port_(port), - manufacturer_(manufacturer) - { - } - - const std::string& GetSymbolicName() const - { - return symbolicName_; + name_ = name; } const std::string& GetApplicationEntityTitle() const @@ -94,19 +67,41 @@ return aet_; } + void SetApplicationEntityTitle(const std::string& aet) + { + aet_ = aet; + } + const std::string& GetHost() const { return host_; } + void SetHost(const std::string& host) + { + host_ = host; + } + int GetPort() const { return port_; } + void SetPort(int port); + ModalityManufacturer GetManufacturer() const { return manufacturer_; } + + void SetManufacturer(ModalityManufacturer manufacturer) + { + manufacturer_ = manufacturer; + } + + void SetManufacturer(const std::string& manufacturer) + { + manufacturer_ = StringToModalityManufacturer(manufacturer); + } }; }
--- a/OrthancServer/OrthancFindRequestHandler.cpp Wed May 07 13:23:08 2014 +0200 +++ b/OrthancServer/OrthancFindRequestHandler.cpp Wed May 07 15:22:28 2014 +0200 @@ -451,13 +451,14 @@ ModalityManufacturer manufacturer; { - std::string symbolicName, address; - int port; + RemoteModalityParameters modality; - if (!LookupDicomModalityUsingAETitle(callingAETitle, symbolicName, address, port, manufacturer)) + if (!LookupDicomModalityUsingAETitle(modality, callingAETitle)) { throw OrthancException("Unknown modality"); } + + manufacturer = modality.GetManufacturer(); }
--- a/OrthancServer/OrthancInitialization.cpp Wed May 07 13:23:08 2014 +0200 +++ b/OrthancServer/OrthancInitialization.cpp Wed May 07 15:22:28 2014 +0200 @@ -50,6 +50,7 @@ static std::auto_ptr<Json::Value> configuration_; static boost::filesystem::path defaultDirectory_; + static void ReadGlobalConfiguration(const char* configurationFile) { configuration_.reset(new Json::Value); @@ -242,11 +243,8 @@ - void GetDicomModalityUsingSymbolicName(const std::string& name, - std::string& aet, - std::string& address, - int& port, - ModalityManufacturer& manufacturer) + void GetDicomModalityUsingSymbolicName(RemoteModalityParameters& modality, + const std::string& name) { boost::mutex::scoped_lock lock(globalMutex_); @@ -265,19 +263,19 @@ try { - aet = modalities[name].get(0u, "").asString(); - address = modalities[name].get(1u, "").asString(); + modality.SetApplicationEntityTitle(modalities[name].get(0u, "").asString()); + modality.SetHost(modalities[name].get(1u, "").asString()); const Json::Value& portValue = modalities[name].get(2u, ""); try { - port = portValue.asInt(); + modality.SetPort(portValue.asInt()); } catch (std::runtime_error /* error inside JsonCpp */) { try { - port = boost::lexical_cast<int>(portValue.asString()); + modality.SetPort(boost::lexical_cast<int>(portValue.asString())); } catch (boost::bad_lexical_cast) { @@ -287,11 +285,11 @@ if (modalities[name].size() == 4) { - manufacturer = StringToModalityManufacturer(modalities[name].get(3u, "").asString()); + modality.SetManufacturer(modalities[name].get(3u, "").asString()); } else { - manufacturer = ModalityManufacturer_Generic; + modality.SetManufacturer(ModalityManufacturer_Generic); } } catch (OrthancException& e) @@ -304,10 +302,8 @@ - void GetOrthancPeer(const std::string& name, - std::string& url, - std::string& username, - std::string& password) + void GetOrthancPeer(OrthancPeerParameters& peer, + const std::string& name) { boost::mutex::scoped_lock lock(globalMutex_); @@ -325,19 +321,21 @@ throw OrthancException(ErrorCode_BadFileFormat); } + std::string url; + try { url = modalities[name].get(0u, "").asString(); if (modalities[name].size() == 1) { - username = ""; - password = ""; + peer.SetUsername(""); + peer.SetPassword(""); } else if (modalities[name].size() == 3) { - username = modalities[name].get(1u, "").asString(); - password = modalities[name].get(2u, "").asString(); + peer.SetUsername(modalities[name].get(1u, "").asString()); + peer.SetPassword(modalities[name].get(2u, "").asString()); } else { @@ -353,6 +351,8 @@ { url += '/'; } + + peer.SetUrl(url); } catch (OrthancException& e) { @@ -527,11 +527,8 @@ } - bool LookupDicomModalityUsingAETitle(const std::string& aet, - std::string& symbolicName, - std::string& address, - int& port, - ModalityManufacturer& manufacturer) + bool LookupDicomModalityUsingAETitle(RemoteModalityParameters& modality, + const std::string& aet) { std::set<std::string> modalities; GetListOfDicomModalities(modalities); @@ -541,10 +538,9 @@ { try { - std::string thisAet; - GetDicomModalityUsingSymbolicName(*it, thisAet, address, port, manufacturer); + GetDicomModalityUsingSymbolicName(modality, *it); - if (IsSameAETitle(aet, thisAet)) + if (IsSameAETitle(aet, modality.GetApplicationEntityTitle())) { return true; } @@ -560,35 +556,27 @@ bool IsKnownAETitle(const std::string& aet) { - std::string symbolicName, address; - int port; - ModalityManufacturer manufacturer; - - return LookupDicomModalityUsingAETitle(aet, symbolicName, address, port, manufacturer); + RemoteModalityParameters modality; + return LookupDicomModalityUsingAETitle(modality, aet); } RemoteModalityParameters GetModalityUsingSymbolicName(const std::string& name) { - std::string aet, address; - int port; - ModalityManufacturer manufacturer; + RemoteModalityParameters modality; + GetDicomModalityUsingSymbolicName(modality, name); - GetDicomModalityUsingSymbolicName(name, aet, address, port, manufacturer); - - return RemoteModalityParameters(name, aet, address, port, manufacturer); + return modality; } RemoteModalityParameters GetModalityUsingAet(const std::string& aet) { - std::string name, address; - int port; - ModalityManufacturer manufacturer; + RemoteModalityParameters modality; - if (LookupDicomModalityUsingAETitle(aet, name, address, port, manufacturer)) + if (LookupDicomModalityUsingAETitle(modality, aet)) { - return RemoteModalityParameters(name, aet, address, port, manufacturer); + return modality; } else {
--- a/OrthancServer/OrthancInitialization.h Wed May 07 13:23:08 2014 +0200 +++ b/OrthancServer/OrthancInitialization.h Wed May 07 15:22:28 2014 +0200 @@ -42,6 +42,61 @@ namespace Orthanc { + class OrthancPeerParameters + { + private: + std::string name_; + std::string url_; + std::string username_; + std::string password_; + + public: + OrthancPeerParameters() : url_("http://localhost:8042/") + { + } + + const std::string& GetName() const + { + return name_; + } + + void SetName(const std::string& name) + { + name_ = name; + } + + const std::string& GetUrl() const + { + return url_; + } + + void SetUrl(const std::string& url) + { + url_ = url; + } + + const std::string& GetUsername() const + { + return username_; + } + + void SetUsername(const std::string& username) + { + username_ = username; + } + + const std::string& GetPassword() const + { + return password_; + } + + void SetPassword(const std::string& password) + { + password_ = password; + } + }; + + void OrthancInitialize(const char* configurationFile = NULL); void OrthancFinalize(); @@ -55,22 +110,14 @@ bool GetGlobalBoolParameter(const std::string& parameter, bool defaultValue); - void GetDicomModalityUsingSymbolicName(const std::string& name, - std::string& aet, - std::string& address, - int& port, - ModalityManufacturer& manufacturer); + void GetDicomModalityUsingSymbolicName(RemoteModalityParameters& modality, + const std::string& name); - bool LookupDicomModalityUsingAETitle(const std::string& aet, - std::string& symbolicName, - std::string& address, - int& port, - ModalityManufacturer& manufacturer); + bool LookupDicomModalityUsingAETitle(RemoteModalityParameters& modality, + const std::string& aet); - void GetOrthancPeer(const std::string& name, - std::string& url, - std::string& username, - std::string& password); + void GetOrthancPeer(OrthancPeerParameters& peer, + const std::string& name); void GetListOfDicomModalities(std::set<std::string>& target);
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Wed May 07 13:23:08 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Wed May 07 15:22:28 2014 +0200 @@ -385,17 +385,19 @@ return; } - std::string url, username, password; - GetOrthancPeer(remote, url, username, password); + OrthancPeerParameters peer; + GetOrthancPeer(peer, remote); // Configure the HTTP client HttpClient client; - if (username.size() != 0 && password.size() != 0) + if (peer.GetUsername().size() != 0 && + peer.GetPassword().size() != 0) { - client.SetCredentials(username.c_str(), password.c_str()); + client.SetCredentials(peer.GetUsername().c_str(), + peer.GetPassword().c_str()); } - client.SetUrl(url + "instances"); + client.SetUrl(peer.GetUrl() + "instances"); client.SetMethod(HttpMethod_Post); // Loop over the instances that are to be sent
--- a/Resources/Samples/WebApplications/DrawingDicomizer/orthanc.js Wed May 07 13:23:08 2014 +0200 +++ b/Resources/Samples/WebApplications/DrawingDicomizer/orthanc.js Wed May 07 15:22:28 2014 +0200 @@ -39,7 +39,7 @@ } }) .success(function( msg ) { - alert('The image has been dicomized! ' + msg); + alert('Your drawing has been dicomized!\n\n' + msg); }); return false;