Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi2.cpp @ 210:96b7918a6a18
start of the refactoring of the Orthanc REST API
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Nov 2012 18:03:44 +0100 |
parents | |
children | b7aea293b965 |
comparison
equal
deleted
inserted
replaced
209:9960642f0f45 | 210:96b7918a6a18 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, | |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "OrthancRestApi2.h" | |
34 | |
35 #include "OrthancInitialization.h" | |
36 #include "FromDcmtkBridge.h" | |
37 #include "../Core/Uuid.h" | |
38 #include "../Core/HttpServer/FilesystemHttpSender.h" | |
39 | |
40 #include <dcmtk/dcmdata/dcistrmb.h> | |
41 #include <dcmtk/dcmdata/dcfilefo.h> | |
42 #include <boost/lexical_cast.hpp> | |
43 | |
44 | |
45 #define RETRIEVE_CONTEXT(call) \ | |
46 OrthancRestApi2& context = dynamic_cast<OrthancRestApi2&>(call.GetContext()) | |
47 | |
48 | |
49 namespace Orthanc | |
50 { | |
51 // System information ------------------------------------------------------- | |
52 | |
53 static void GetSystemInformation(RestApi::GetCall& call) | |
54 { | |
55 RETRIEVE_CONTEXT(call); | |
56 | |
57 Json::Value result = Json::objectValue; | |
58 result["Version"] = ORTHANC_VERSION; | |
59 result["Name"] = GetGlobalStringParameter("Name", ""); | |
60 result["TotalCompressedSize"] = boost::lexical_cast<std::string>(context.GetIndex().GetTotalCompressedSize()); | |
61 result["TotalUncompressedSize"] = boost::lexical_cast<std::string>(context.GetIndex().GetTotalUncompressedSize()); | |
62 call.GetOutput().AnswerJson(result); | |
63 } | |
64 | |
65 | |
66 // Changes API -------------------------------------------------------------- | |
67 | |
68 static void GetChanges(RestApi::GetCall& call) | |
69 { | |
70 RETRIEVE_CONTEXT(call); | |
71 | |
72 static const unsigned int MAX_RESULTS = 100; | |
73 ServerIndex& index = context.GetIndex(); | |
74 | |
75 //std::string filter = GetArgument(getArguments, "filter", ""); | |
76 int64_t since; | |
77 unsigned int limit; | |
78 try | |
79 { | |
80 since = boost::lexical_cast<int64_t>(call.GetArgument("since", "0")); | |
81 limit = boost::lexical_cast<unsigned int>(call.GetArgument("limit", "0")); | |
82 } | |
83 catch (boost::bad_lexical_cast) | |
84 { | |
85 return; | |
86 } | |
87 | |
88 if (limit == 0 || limit > MAX_RESULTS) | |
89 { | |
90 limit = MAX_RESULTS; | |
91 } | |
92 | |
93 Json::Value result; | |
94 if (index.GetChanges(result, since, limit)) | |
95 { | |
96 call.GetOutput().AnswerJson(result); | |
97 } | |
98 } | |
99 | |
100 | |
101 | |
102 | |
103 // DICOM bridge ------------------------------------------------------------- | |
104 | |
105 static void ListModalities(RestApi::GetCall& call) | |
106 { | |
107 RETRIEVE_CONTEXT(call); | |
108 | |
109 Json::Value result = Json::arrayValue; | |
110 | |
111 for (OrthancRestApi2::Modalities::const_iterator | |
112 it = context.GetModalities().begin(); | |
113 it != context.GetModalities().end(); it++) | |
114 { | |
115 result.append(*it); | |
116 } | |
117 | |
118 call.GetOutput().AnswerJson(result); | |
119 } | |
120 | |
121 | |
122 OrthancRestApi2::OrthancRestApi2(ServerIndex& index, | |
123 const std::string& path) : | |
124 index_(index), | |
125 storage_(path) | |
126 { | |
127 GetListOfDicomModalities(modalities_); | |
128 | |
129 Register("/system", GetSystemInformation); | |
130 Register("/changes", GetChanges); | |
131 Register("/modalities", ListModalities); | |
132 } | |
133 } |