Mercurial > hg > orthanc
annotate OrthancFramework/Sources/RestApi/RestApiHierarchy.h @ 5485:48b8dae6dc77
upgrade to year 2024
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Jan 2024 15:10:42 +0100 |
parents | 0ea402b4d901 |
children | f7adfb22e20e |
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 |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
969 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * the License, or (at your option) any later version. |
969 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
16 * Lesser General Public License for more details. |
969 | 17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
969 | 21 **/ |
22 | |
23 | |
24 #pragma once | |
25 | |
975 | 26 #include "RestApiGetCall.h" |
27 #include "RestApiPostCall.h" | |
28 #include "RestApiPutCall.h" | |
29 #include "RestApiDeleteCall.h" | |
969 | 30 |
978 | 31 #include <set> |
32 | |
969 | 33 namespace Orthanc |
34 { | |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
35 class ORTHANC_PUBLIC RestApiHierarchy : public boost::noncopyable |
969 | 36 { |
978 | 37 public: |
4026
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3992
diff
changeset
|
38 class ORTHANC_PUBLIC Resource : public boost::noncopyable |
969 | 39 { |
972 | 40 private: |
975 | 41 RestApiGetCall::Handler getHandler_; |
42 RestApiPostCall::Handler postHandler_; | |
43 RestApiPutCall::Handler putHandler_; | |
974 | 44 RestApiDeleteCall::Handler deleteHandler_; |
969 | 45 |
972 | 46 public: |
978 | 47 Resource(); |
972 | 48 |
4400 | 49 bool HasHandler(HttpMethod method) const; |
969 | 50 |
4300 | 51 void Register(RestApiGetCall::Handler handler); |
969 | 52 |
4300 | 53 void Register(RestApiPutCall::Handler handler); |
969 | 54 |
4300 | 55 void Register(RestApiPostCall::Handler handler); |
969 | 56 |
4300 | 57 void Register(RestApiDeleteCall::Handler handler); |
969 | 58 |
59 bool IsEmpty() const; | |
978 | 60 |
61 bool Handle(RestApiGetCall& call) const; | |
62 | |
63 bool Handle(RestApiPutCall& call) const; | |
64 | |
65 bool Handle(RestApiPostCall& call) const; | |
66 | |
67 bool Handle(RestApiDeleteCall& call) const; | |
969 | 68 }; |
69 | |
70 | |
978 | 71 class IVisitor : public boost::noncopyable |
72 { | |
73 public: | |
4303
44b53a2c0a13
improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
74 virtual ~IVisitor() |
44b53a2c0a13
improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
75 { |
44b53a2c0a13
improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
76 } |
978 | 77 |
78 virtual bool Visit(const Resource& resource, | |
79 const UriComponents& uri, | |
4399
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
80 bool hasTrailing, |
4401
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
81 // "uriArguments" only contains their name if using "ExploreAllResources()" |
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
82 const HttpToolbox::Arguments& uriArguments, |
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
83 // "trailing" is empty if using "ExploreAllResources()" |
978 | 84 const UriComponents& trailing) = 0; |
85 }; | |
86 | |
87 | |
88 private: | |
969 | 89 typedef std::map<std::string, RestApiHierarchy*> Children; |
90 | |
978 | 91 Resource handlers_; |
969 | 92 Children children_; |
93 Children wildcardChildren_; | |
4399
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
94 Resource handlersWithTrailing_; |
969 | 95 |
96 static RestApiHierarchy& AddChild(Children& children, | |
97 const std::string& name); | |
98 | |
99 static void DeleteChildren(Children& children); | |
100 | |
101 template <typename Handler> | |
102 void RegisterInternal(const RestApiPath& path, | |
103 Handler handler, | |
104 size_t level); | |
105 | |
978 | 106 bool CanGenerateDirectory() const; |
107 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4303
diff
changeset
|
108 bool LookupResource(HttpToolbox::Arguments& components, |
978 | 109 const UriComponents& uri, |
110 IVisitor& visitor, | |
111 size_t level); | |
969 | 112 |
113 bool GetDirectory(Json::Value& result, | |
114 const UriComponents& uri, | |
115 size_t level); | |
116 | |
117 public: | |
118 ~RestApiHierarchy(); | |
119 | |
970 | 120 void Register(const std::string& uri, |
974 | 121 RestApiGetCall::Handler handler); |
969 | 122 |
970 | 123 void Register(const std::string& uri, |
974 | 124 RestApiPutCall::Handler handler); |
969 | 125 |
970 | 126 void Register(const std::string& uri, |
974 | 127 RestApiPostCall::Handler handler); |
969 | 128 |
970 | 129 void Register(const std::string& uri, |
974 | 130 RestApiDeleteCall::Handler handler); |
969 | 131 |
132 void CreateSiteMap(Json::Value& target) const; | |
133 | |
134 bool GetDirectory(Json::Value& result, | |
4300 | 135 const UriComponents& uri); |
969 | 136 |
978 | 137 bool LookupResource(const UriComponents& uri, |
138 IVisitor& visitor); | |
969 | 139 |
978 | 140 void GetAcceptedMethods(std::set<HttpMethod>& methods, |
141 const UriComponents& uri); | |
4399
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
142 |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
143 void ExploreAllResources(IVisitor& visitor, |
4401
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
144 const UriComponents& path, |
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
145 const std::set<std::string>& uriArguments) const; |
969 | 146 }; |
147 } |