annotate OrthancServer/Plugins/Samples/ConnectivityChecks/Plugin.cpp @ 5859:3ddd1b0231e9 default tip

Housekeeper doc and config default value
author Alain Mazy <am@orthanc.team>
date Tue, 05 Nov 2024 13:21:23 +0100
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3622
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5538
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5538
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5257
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
3622
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU General Public License as
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * published by the Free Software Foundation, either version 3 of the
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * License, or (at your option) any later version.
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * General Public License for more details.
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
5257
0b183bb77c83 Avoid the use of "externalproject_add()" to build the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
24 #include <ConnectivityChecksResources.h>
3622
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <orthanc/OrthancCPlugin.h>
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
27 #include "../../../../OrthancFramework/Sources/OrthancException.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
28 #include "../../../../OrthancFramework/Sources/SystemToolbox.h"
3622
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #define ROOT_URI "/connectivity-checks"
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 static OrthancPluginContext* context_ = NULL;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 template <Orthanc::EmbeddedResources::DirectoryResourceId DIRECTORY>
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 static OrthancPluginErrorCode ServeStaticResource(OrthancPluginRestOutput* output,
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 const char* url,
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 const OrthancPluginHttpRequest* request)
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 if (request->method != OrthancPluginHttpMethod_Get)
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 OrthancPluginSendMethodNotAllowed(context_, output, "GET");
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 return OrthancPluginErrorCode_Success;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 std::string path = "/" + std::string(request->groups[0]);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 std::string mime = Orthanc::EnumerationToString(Orthanc::SystemToolbox::AutodetectMimeType(path));
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 try
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 std::string s;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 Orthanc::EmbeddedResources::GetDirectoryResource(s, DIRECTORY, path.c_str());
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 const char* resource = s.size() ? s.c_str() : NULL;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime.c_str());
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 catch (Orthanc::OrthancException&)
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 OrthancPluginLogError(context_, s.c_str());
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 OrthancPluginSendHttpStatusCode(context_, output, 404);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 return OrthancPluginErrorCode_Success;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 extern "C"
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 context_ = c;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 /* Check the version of the Orthanc core */
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 if (OrthancPluginCheckVersion(c) == 0)
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 char info[256];
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin",
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 c->orthancVersion,
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 OrthancPluginLogError(context_, info);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 return -1;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 /* Register the callbacks */
5538
6ce05f8b5b13 deprecating OrthancPluginSetDescription2(), OrthancPluginExtendOrthancExplorer2() and OrthancPluginSetRootUri2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
90 OrthancPluginSetDescription2(context_, ORTHANC_PLUGIN_NAME, "Utilities to check connectivity to DICOM modalities, DICOMweb servers and Orthanc peers.");
6ce05f8b5b13 deprecating OrthancPluginSetDescription2(), OrthancPluginExtendOrthancExplorer2() and OrthancPluginSetRootUri2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
91 OrthancPluginSetRootUri2(context_, ORTHANC_PLUGIN_NAME, ROOT_URI "/app/index.html");
3622
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 OrthancPluginRegisterRestCallback(context_, ROOT_URI "/libs/(.*)", ServeStaticResource<Orthanc::EmbeddedResources::LIBRARIES>);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 OrthancPluginRegisterRestCallback(context_, ROOT_URI "/app/(.*)", ServeStaticResource<Orthanc::EmbeddedResources::WEB_RESOURCES>);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 return 0;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 return ORTHANC_PLUGIN_NAME;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 return ORTHANC_PLUGIN_VERSION;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }