Mercurial > hg > orthanc
annotate Core/RestApi/RestApiHierarchy.h @ 2148:e18023c2fdfb
fix visual studio 2015 build
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 10 Nov 2016 08:47:31 +0100 |
parents | b1291df2f780 |
children | a3a65de1840f |
rev | line source |
---|---|
969 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
978
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
969 | 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 #pragma once | |
34 | |
975 | 35 #include "RestApiGetCall.h" |
36 #include "RestApiPostCall.h" | |
37 #include "RestApiPutCall.h" | |
38 #include "RestApiDeleteCall.h" | |
969 | 39 |
978 | 40 #include <set> |
41 | |
969 | 42 namespace Orthanc |
43 { | |
978 | 44 class RestApiHierarchy : public boost::noncopyable |
969 | 45 { |
978 | 46 public: |
47 class Resource : public boost::noncopyable | |
969 | 48 { |
972 | 49 private: |
975 | 50 RestApiGetCall::Handler getHandler_; |
51 RestApiPostCall::Handler postHandler_; | |
52 RestApiPutCall::Handler putHandler_; | |
974 | 53 RestApiDeleteCall::Handler deleteHandler_; |
969 | 54 |
972 | 55 public: |
978 | 56 Resource(); |
972 | 57 |
58 bool HasHandler(HttpMethod method) const; | |
969 | 59 |
974 | 60 void Register(RestApiGetCall::Handler handler) |
969 | 61 { |
972 | 62 getHandler_ = handler; |
969 | 63 } |
64 | |
974 | 65 void Register(RestApiPutCall::Handler handler) |
969 | 66 { |
972 | 67 putHandler_ = handler; |
969 | 68 } |
69 | |
974 | 70 void Register(RestApiPostCall::Handler handler) |
969 | 71 { |
972 | 72 postHandler_ = handler; |
969 | 73 } |
74 | |
974 | 75 void Register(RestApiDeleteCall::Handler handler) |
969 | 76 { |
972 | 77 deleteHandler_ = handler; |
969 | 78 } |
79 | |
80 bool IsEmpty() const; | |
978 | 81 |
82 bool Handle(RestApiGetCall& call) const; | |
83 | |
84 bool Handle(RestApiPutCall& call) const; | |
85 | |
86 bool Handle(RestApiPostCall& call) const; | |
87 | |
88 bool Handle(RestApiDeleteCall& call) const; | |
969 | 89 }; |
90 | |
91 | |
978 | 92 class IVisitor : public boost::noncopyable |
93 { | |
94 public: | |
95 virtual ~IVisitor() | |
96 { | |
97 } | |
98 | |
99 virtual bool Visit(const Resource& resource, | |
100 const UriComponents& uri, | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
101 const IHttpHandler::Arguments& components, |
978 | 102 const UriComponents& trailing) = 0; |
103 }; | |
104 | |
105 | |
106 private: | |
969 | 107 typedef std::map<std::string, RestApiHierarchy*> Children; |
108 | |
978 | 109 Resource handlers_; |
969 | 110 Children children_; |
111 Children wildcardChildren_; | |
978 | 112 Resource universalHandlers_; |
969 | 113 |
114 static RestApiHierarchy& AddChild(Children& children, | |
115 const std::string& name); | |
116 | |
117 static void DeleteChildren(Children& children); | |
118 | |
119 template <typename Handler> | |
120 void RegisterInternal(const RestApiPath& path, | |
121 Handler handler, | |
122 size_t level); | |
123 | |
978 | 124 bool CanGenerateDirectory() const; |
125 | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
126 bool LookupResource(IHttpHandler::Arguments& components, |
978 | 127 const UriComponents& uri, |
128 IVisitor& visitor, | |
129 size_t level); | |
969 | 130 |
131 bool GetDirectory(Json::Value& result, | |
132 const UriComponents& uri, | |
133 size_t level); | |
134 | |
135 public: | |
136 ~RestApiHierarchy(); | |
137 | |
970 | 138 void Register(const std::string& uri, |
974 | 139 RestApiGetCall::Handler handler); |
969 | 140 |
970 | 141 void Register(const std::string& uri, |
974 | 142 RestApiPutCall::Handler handler); |
969 | 143 |
970 | 144 void Register(const std::string& uri, |
974 | 145 RestApiPostCall::Handler handler); |
969 | 146 |
970 | 147 void Register(const std::string& uri, |
974 | 148 RestApiDeleteCall::Handler handler); |
969 | 149 |
150 void CreateSiteMap(Json::Value& target) const; | |
151 | |
152 bool GetDirectory(Json::Value& result, | |
153 const UriComponents& uri) | |
154 { | |
155 return GetDirectory(result, uri, 0); | |
156 } | |
157 | |
978 | 158 bool LookupResource(const UriComponents& uri, |
159 IVisitor& visitor); | |
969 | 160 |
978 | 161 void GetAcceptedMethods(std::set<HttpMethod>& methods, |
162 const UriComponents& uri); | |
969 | 163 }; |
164 } |