annotate Plugins/Samples/Basic/Plugin.c @ 1211:88511c737760

integration db-changes->mainline
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Nov 2014 13:57:11 +0100
parents 1e1390665639
children f1c01451a8ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
886
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * Permission is hereby granted, free of charge, to any person
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * obtaining a copy of this software and associated documentation
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * files (the "Software"), to deal in the Software without
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * restriction, including without limitation the rights to use, copy,
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * of the Software, and to permit persons to whom the Software is
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * included in all copies or substantial portions of the Software.
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * SOFTWARE.
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 **/
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
896
c4053ac5db04 better plugni api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 894
diff changeset
28 #include <OrthancCPlugin.h>
886
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <string.h>
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <stdio.h>
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
33 static OrthancPluginContext* context = NULL;
886
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
901
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
36 ORTHANC_PLUGINS_API int32_t Callback1(OrthancPluginRestOutput* output,
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
37 const char* url,
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
38 const OrthancPluginHttpRequest* request)
894
690aeb4cb899 REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
39 {
690aeb4cb899 REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
40 char buffer[1024];
897
bafc9d592632 REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 896
diff changeset
41 uint32_t i;
bafc9d592632 REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 896
diff changeset
42
1041
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
43 sprintf(buffer, "Callback on URL [%s] with body [%s]\n", url, request->body);
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
44 OrthancPluginLogWarning(context, buffer);
897
bafc9d592632 REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 896
diff changeset
45
1042
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1041
diff changeset
46 OrthancPluginSetCookie(context, output, "hello", "world");
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
47 OrthancPluginAnswerBuffer(context, output, buffer, strlen(buffer), "text/plain");
897
bafc9d592632 REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 896
diff changeset
48
1041
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
49 OrthancPluginLogWarning(context, "");
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
50
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
51 for (i = 0; i < request->groupsCount; i++)
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
52 {
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
53 sprintf(buffer, " REGEX GROUP %d = [%s]", i, request->groups[i]);
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
54 OrthancPluginLogWarning(context, buffer);
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
55 }
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
56
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
57 OrthancPluginLogWarning(context, "");
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
58
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
59 for (i = 0; i < request->getCount; i++)
897
bafc9d592632 REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 896
diff changeset
60 {
1041
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
61 sprintf(buffer, " GET [%s] = [%s]", request->getKeys[i], request->getValues[i]);
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
62 OrthancPluginLogWarning(context, buffer);
897
bafc9d592632 REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 896
diff changeset
63 }
bafc9d592632 REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 896
diff changeset
64
1041
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
65 OrthancPluginLogWarning(context, "");
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
66
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
67 for (i = 0; i < request->headersCount; i++)
901
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
68 {
1041
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
69 sprintf(buffer, " HEADERS [%s] = [%s]", request->headersKeys[i], request->headersValues[i]);
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
70 OrthancPluginLogWarning(context, buffer);
901
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
71 }
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
72
1042
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1041
diff changeset
73 OrthancPluginLogWarning(context, "");
1041
2c49b7dffcec plugins have access to the HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1040
diff changeset
74
894
690aeb4cb899 REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
75 return 1;
690aeb4cb899 REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
76 }
690aeb4cb899 REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
77
690aeb4cb899 REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
78
901
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
79 ORTHANC_PLUGINS_API int32_t Callback2(OrthancPluginRestOutput* output,
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
80 const char* url,
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
81 const OrthancPluginHttpRequest* request)
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
82 {
904
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
83 /* Answer with a sample 16bpp image. */
901
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
84
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
85 uint16_t buffer[256 * 256];
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
86 uint32_t x, y, value;
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
87
1042
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1041
diff changeset
88 if (request->method != OrthancPluginHttpMethod_Get)
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1041
diff changeset
89 {
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1041
diff changeset
90 OrthancPluginSendMethodNotAllowed(context, output, "GET");
1043
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
91 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
92 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
93 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
94 value = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
95 for (y = 0; y < 256; y++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
96 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
97 for (x = 0; x < 256; x++, value++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
98 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
99 buffer[value] = value;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
100 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
101 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
102
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
103 OrthancPluginCompressAndAnswerPngImage(context, output, OrthancPluginPixelFormat_Grayscale16,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
104 256, 256, sizeof(uint16_t) * 256, buffer);
1042
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1041
diff changeset
105 }
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1041
diff changeset
106
901
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
107 return 0;
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
108 }
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
109
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
110
904
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
111 ORTHANC_PLUGINS_API int32_t Callback3(OrthancPluginRestOutput* output,
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
112 const char* url,
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
113 const OrthancPluginHttpRequest* request)
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
114 {
1044
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
115 if (request->method != OrthancPluginHttpMethod_Get)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
116 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
117 OrthancPluginSendMethodNotAllowed(context, output, "GET");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
118 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
119 else
904
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
120 {
1044
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
121 OrthancPluginMemoryBuffer dicom;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
122 if (!OrthancPluginGetDicomForInstance(context, &dicom, request->groups[0]))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
123 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
124 /* No error, forward the DICOM file */
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
125 OrthancPluginAnswerBuffer(context, output, dicom.data, dicom.size, "application/dicom");
904
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
126
1044
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
127 /* Free memory */
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
128 OrthancPluginFreeMemoryBuffer(context, &dicom);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
129 }
904
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
130 }
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
131
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
132 return 0;
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
133 }
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
134
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
135
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
136 ORTHANC_PLUGINS_API int32_t Callback4(OrthancPluginRestOutput* output,
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
137 const char* url,
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
138 const OrthancPluginHttpRequest* request)
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
139 {
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
140 /* Answer with a sample 8bpp image. */
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
141
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
142 uint8_t buffer[256 * 256];
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
143 uint32_t x, y, value;
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
144
1044
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
145 if (request->method != OrthancPluginHttpMethod_Get)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
146 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
147 OrthancPluginSendMethodNotAllowed(context, output, "GET");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
148 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
149 else
904
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
150 {
1044
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
151 value = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
152 for (y = 0; y < 256; y++)
904
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
153 {
1044
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
154 for (x = 0; x < 256; x++, value++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
155 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
156 buffer[value] = x;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
157 }
904
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
158 }
1044
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
159
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
160 OrthancPluginCompressAndAnswerPngImage(context, output, OrthancPluginPixelFormat_Grayscale8,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1043
diff changeset
161 256, 256, 256, buffer);
904
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
162 }
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
163
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
164 return 0;
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
165 }
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
166
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
167
1137
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
168 ORTHANC_PLUGINS_API int32_t CallbackCreateDicom(OrthancPluginRestOutput* output,
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
169 const char* url,
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
170 const OrthancPluginHttpRequest* request)
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
171 {
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
172 const char* pathLocator = "\"Path\" : \"";
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
173 char info[1024];
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
174 char *id, *eos;
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
175 OrthancPluginMemoryBuffer tmp;
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
176
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
177 if (request->method != OrthancPluginHttpMethod_Post)
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
178 {
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
179 OrthancPluginSendMethodNotAllowed(context, output, "POST");
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
180 }
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
181 else
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
182 {
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
183 /* Make POST request to create a new DICOM instance */
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
184 sprintf(info, "{\"PatientName\":\"Test\"}");
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
185 OrthancPluginRestApiPost(context, &tmp, "/tools/create-dicom", info, strlen(info));
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
186
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
187 /**
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
188 * Recover the ID of the created instance is constructed by a
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
189 * quick-and-dirty parsing of a JSON string.
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
190 **/
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
191 id = strstr((char*) tmp.data, pathLocator) + strlen(pathLocator);
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
192 eos = strchr(id, '\"');
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
193 eos[0] = '\0';
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
194
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
195 /* Delete the newly created DICOM instance. */
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
196 OrthancPluginRestApiDelete(context, id);
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
197 OrthancPluginFreeMemoryBuffer(context, &tmp);
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
198
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
199 /* Set some cookie */
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
200 OrthancPluginSetCookie(context, output, "hello", "world");
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
201
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
202 /* Set some HTTP header */
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
203 OrthancPluginSetHttpHeader(context, output, "Cache-Control", "max-age=0, no-cache");
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
204
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
205 OrthancPluginAnswerBuffer(context, output, "OK\n", 3, "text/plain");
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
206 }
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
207
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
208 return 0;
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
209 }
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
210
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
211
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
212 ORTHANC_PLUGINS_API int32_t OnStoredCallback(OrthancPluginDicomInstance* instance,
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
213 const char* instanceId)
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
214 {
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
215 char buffer[256];
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
216 FILE* fp;
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
217 char* json;
1191
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
218 static int first = 1;
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
219
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
220 sprintf(buffer, "Just received a DICOM instance of size %d and ID %s from AET %s",
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
221 (int) OrthancPluginGetInstanceSize(context, instance), instanceId,
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
222 OrthancPluginGetInstanceRemoteAet(context, instance));
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
223
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
224 OrthancPluginLogWarning(context, buffer);
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
225
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
226 fp = fopen("PluginReceivedInstance.dcm", "wb");
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
227 fwrite(OrthancPluginGetInstanceData(context, instance),
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
228 OrthancPluginGetInstanceSize(context, instance), 1, fp);
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
229 fclose(fp);
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
230
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
231 json = OrthancPluginGetInstanceSimplifiedJson(context, instance);
1191
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
232 if (first)
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
233 {
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
234 /* Only print the first DICOM instance */
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
235 printf("[%s]\n", json);
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
236 first = 0;
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
237 }
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
238 OrthancPluginFreeString(context, json);
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
239
1067
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
240 if (OrthancPluginHasInstanceMetadata(context, instance, "ReceptionDate"))
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
241 {
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
242 printf("Received on [%s]\n", OrthancPluginGetInstanceMetadata(context, instance, "ReceptionDate"));
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
243 }
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
244 else
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
245 {
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
246 OrthancPluginLogError(context, "Instance has no reception date, should never happen!");
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
247 }
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
248
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
249 return 0;
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
250 }
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
251
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
252
1191
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
253 ORTHANC_PLUGINS_API int32_t OnChangeCallback(OrthancPluginChangeType changeType,
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
254 OrthancPluginResourceType resourceType,
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
255 const char* resourceId)
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
256 {
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
257 char info[1024];
1199
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
258 OrthancPluginMemoryBuffer tmp;
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
259
1191
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
260 sprintf(info, "Change %d on resource %s of type %d", changeType, resourceId, resourceType);
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
261 OrthancPluginLogWarning(context, info);
1199
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
262
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
263 if (changeType == OrthancPluginChangeType_NewInstance)
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
264 {
1200
1e1390665639 fix sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1199
diff changeset
265 sprintf(info, "/instances/%s/metadata/AnonymizedFrom", resourceId);
1199
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
266 if (OrthancPluginRestApiGet(context, &tmp, info) == 0)
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
267 {
1200
1e1390665639 fix sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1199
diff changeset
268 sprintf(info, " Instance %s comes from the anonymization of instance", resourceId);
1e1390665639 fix sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1199
diff changeset
269 strncat(info, (const char*) tmp.data, tmp.size);
1199
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
270 OrthancPluginLogWarning(context, info);
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
271 OrthancPluginFreeMemoryBuffer(context, &tmp);
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
272 }
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
273 }
a843ee8bb903 separated thread for change callbacks in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1191
diff changeset
274
1191
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
275 return 0;
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
276 }
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
277
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
278
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
279 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
886
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 {
912
dcb2469f00f4 PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 904
diff changeset
281 OrthancPluginMemoryBuffer tmp;
1145
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
282 char info[1024], *s;
894
690aeb4cb899 REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
283
1040
d06186cdc502 check plugin version in samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1039
diff changeset
284 context = c;
d06186cdc502 check plugin version in samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1039
diff changeset
285 OrthancPluginLogWarning(context, "Sample plugin is initializing");
d06186cdc502 check plugin version in samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1039
diff changeset
286
d06186cdc502 check plugin version in samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1039
diff changeset
287 /* Check the version of the Orthanc core */
1039
5a5a4890ffca check version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 913
diff changeset
288 if (OrthancPluginCheckVersion(c) == 0)
5a5a4890ffca check version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 913
diff changeset
289 {
1040
d06186cdc502 check plugin version in samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1039
diff changeset
290 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin",
1039
5a5a4890ffca check version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 913
diff changeset
291 c->orthancVersion,
5a5a4890ffca check version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 913
diff changeset
292 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
5a5a4890ffca check version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 913
diff changeset
293 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
5a5a4890ffca check version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 913
diff changeset
294 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
1040
d06186cdc502 check plugin version in samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1039
diff changeset
295 OrthancPluginLogError(context, info);
1039
5a5a4890ffca check version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 913
diff changeset
296 return -1;
5a5a4890ffca check version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 913
diff changeset
297 }
5a5a4890ffca check version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 913
diff changeset
298
1145
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
299 /* Print some information about Orthanc */
886
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 sprintf(info, "The version of Orthanc is '%s'", context->orthancVersion);
1145
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
301 OrthancPluginLogWarning(context, info);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
302
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
303 s = OrthancPluginGetOrthancPath(context);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
304 sprintf(info, " Path to Orthanc: %s", s);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
305 OrthancPluginLogWarning(context, info);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
306 OrthancPluginFreeString(context, s);
886
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
1145
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
308 s = OrthancPluginGetOrthancDirectory(context);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
309 sprintf(info, " Directory of Orthanc: %s", s);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
310 OrthancPluginLogWarning(context, info);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
311 OrthancPluginFreeString(context, s);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
312
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
313 s = OrthancPluginGetConfigurationPath(context);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
314 sprintf(info, " Path to configuration file: %s", s);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
315 OrthancPluginLogWarning(context, info);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
316 OrthancPluginFreeString(context, s);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
317
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
318 /* Register the callbacks */
901
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
319 OrthancPluginRegisterRestCallback(context, "/(plu.*)/hello", Callback1);
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 899
diff changeset
320 OrthancPluginRegisterRestCallback(context, "/plu.*/image", Callback2);
904
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
321 OrthancPluginRegisterRestCallback(context, "/plugin/instances/([^/]+)/info", Callback3);
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
322 OrthancPluginRegisterRestCallback(context, "/instances/([^/]+)/preview", Callback4);
1137
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
323 OrthancPluginRegisterRestCallback(context, "/plugin/create", CallbackCreateDicom);
904
2732b5f57d9c sample to forward dicom data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 903
diff changeset
324
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1044
diff changeset
325 OrthancPluginRegisterOnStoredInstanceCallback(context, OnStoredCallback);
886
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
1191
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
327 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);
d49505e377e3 demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
328
913
3e43de893d88 POST, DELETE, PUT from Orthanc plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
329 /* Make REST requests to the built-in Orthanc API */
3e43de893d88 POST, DELETE, PUT from Orthanc plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
330 OrthancPluginRestApiGet(context, &tmp, "/changes");
3e43de893d88 POST, DELETE, PUT from Orthanc plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
331 OrthancPluginFreeMemoryBuffer(context, &tmp);
3e43de893d88 POST, DELETE, PUT from Orthanc plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
332 OrthancPluginRestApiGet(context, &tmp, "/changes?limit=1");
912
dcb2469f00f4 PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 904
diff changeset
333 OrthancPluginFreeMemoryBuffer(context, &tmp);
1137
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
334
913
3e43de893d88 POST, DELETE, PUT from Orthanc plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
335 /* Play with PUT by defining a new target modality. */
3e43de893d88 POST, DELETE, PUT from Orthanc plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
336 sprintf(info, "[ \"STORESCP\", \"localhost\", 2000 ]");
3e43de893d88 POST, DELETE, PUT from Orthanc plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 912
diff changeset
337 OrthancPluginRestApiPut(context, &tmp, "/modalities/demo", info, strlen(info));
1137
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1067
diff changeset
338
886
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 return 0;
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 }
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 {
903
06b9a30f1e6d fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 902
diff changeset
345 OrthancPluginLogWarning(context, "Sample plugin is finalizing");
886
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 }
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347
29087d728e0a plugin sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 886
diff changeset
349 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 886
diff changeset
350 {
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 886
diff changeset
351 return "sample";
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 886
diff changeset
352 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 886
diff changeset
353
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 886
diff changeset
354
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 886
diff changeset
355 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 886
diff changeset
356 {
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 886
diff changeset
357 return "1.0";
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 886
diff changeset
358 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 886
diff changeset
359