Mercurial > hg > orthanc-transfers
comparison Resources/Orthanc/Sdk-1.4.2/orthanc/OrthancCPlugin.h @ 7:151e29acbb13
use orthanc sdk 1.4.2
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Sep 2018 12:52:23 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
6:6f504d862494 | 7:151e29acbb13 |
---|---|
1 /** | |
2 * \mainpage | |
3 * | |
4 * This C/C++ SDK allows external developers to create plugins that | |
5 * can be loaded into Orthanc to extend its functionality. Each | |
6 * Orthanc plugin must expose 4 public functions with the following | |
7 * signatures: | |
8 * | |
9 * -# <tt>int32_t OrthancPluginInitialize(const OrthancPluginContext* context)</tt>: | |
10 * This function is invoked by Orthanc when it loads the plugin on startup. | |
11 * The plugin must: | |
12 * - Check its compatibility with the Orthanc version using | |
13 * ::OrthancPluginCheckVersion(). | |
14 * - Store the context pointer so that it can use the plugin | |
15 * services of Orthanc. | |
16 * - Register all its REST callbacks using ::OrthancPluginRegisterRestCallback(). | |
17 * - Possibly register its callback for received DICOM instances using ::OrthancPluginRegisterOnStoredInstanceCallback(). | |
18 * - Possibly register its callback for changes to the DICOM store using ::OrthancPluginRegisterOnChangeCallback(). | |
19 * - Possibly register a custom storage area using ::OrthancPluginRegisterStorageArea(). | |
20 * - Possibly register a custom database back-end area using OrthancPluginRegisterDatabaseBackendV2(). | |
21 * - Possibly register a handler for C-Find SCP using OrthancPluginRegisterFindCallback(). | |
22 * - Possibly register a handler for C-Find SCP against DICOM worklists using OrthancPluginRegisterWorklistCallback(). | |
23 * - Possibly register a handler for C-Move SCP using OrthancPluginRegisterMoveCallback(). | |
24 * - Possibly register a custom decoder for DICOM images using OrthancPluginRegisterDecodeImageCallback(). | |
25 * - Possibly register a callback to filter incoming HTTP requests using OrthancPluginRegisterIncomingHttpRequestFilter2(). | |
26 * - Possibly register a callback to unserialize jobs using OrthancPluginRegisterJobsUnserializer(). | |
27 * -# <tt>void OrthancPluginFinalize()</tt>: | |
28 * This function is invoked by Orthanc during its shutdown. The plugin | |
29 * must free all its memory. | |
30 * -# <tt>const char* OrthancPluginGetName()</tt>: | |
31 * The plugin must return a short string to identify itself. | |
32 * -# <tt>const char* OrthancPluginGetVersion()</tt>: | |
33 * The plugin must return a string containing its version number. | |
34 * | |
35 * The name and the version of a plugin is only used to prevent it | |
36 * from being loaded twice. Note that, in C++, it is mandatory to | |
37 * declare these functions within an <tt>extern "C"</tt> section. | |
38 * | |
39 * To ensure multi-threading safety, the various REST callbacks are | |
40 * guaranteed to be executed in mutual exclusion since Orthanc | |
41 * 0.8.5. If this feature is undesired (notably when developing | |
42 * high-performance plugins handling simultaneous requests), use | |
43 * ::OrthancPluginRegisterRestCallbackNoLock(). | |
44 **/ | |
45 | |
46 | |
47 | |
48 /** | |
49 * @defgroup Images Images and compression | |
50 * @brief Functions to deal with images and compressed buffers. | |
51 * | |
52 * @defgroup REST REST | |
53 * @brief Functions to answer REST requests in a callback. | |
54 * | |
55 * @defgroup Callbacks Callbacks | |
56 * @brief Functions to register and manage callbacks by the plugins. | |
57 * | |
58 * @defgroup DicomCallbacks DicomCallbacks | |
59 * @brief Functions to register and manage DICOM callbacks (worklists, C-Find, C-MOVE). | |
60 * | |
61 * @defgroup Orthanc Orthanc | |
62 * @brief Functions to access the content of the Orthanc server. | |
63 **/ | |
64 | |
65 | |
66 | |
67 /** | |
68 * @defgroup Toolbox Toolbox | |
69 * @brief Generic functions to help with the creation of plugins. | |
70 **/ | |
71 | |
72 | |
73 | |
74 /** | |
75 * Orthanc - A Lightweight, RESTful DICOM Store | |
76 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
77 * Department, University Hospital of Liege, Belgium | |
78 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
79 * | |
80 * This program is free software: you can redistribute it and/or | |
81 * modify it under the terms of the GNU General Public License as | |
82 * published by the Free Software Foundation, either version 3 of the | |
83 * License, or (at your option) any later version. | |
84 * | |
85 * In addition, as a special exception, the copyright holders of this | |
86 * program give permission to link the code of its release with the | |
87 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
88 * that use the same license as the "OpenSSL" library), and distribute | |
89 * the linked executables. You must obey the GNU General Public License | |
90 * in all respects for all of the code used other than "OpenSSL". If you | |
91 * modify file(s) with this exception, you may extend this exception to | |
92 * your version of the file(s), but you are not obligated to do so. If | |
93 * you do not wish to do so, delete this exception statement from your | |
94 * version. If you delete this exception statement from all source files | |
95 * in the program, then also delete it here. | |
96 * | |
97 * This program is distributed in the hope that it will be useful, but | |
98 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
99 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
100 * General Public License for more details. | |
101 * | |
102 * You should have received a copy of the GNU General Public License | |
103 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
104 **/ | |
105 | |
106 | |
107 | |
108 #pragma once | |
109 | |
110 | |
111 #include <stdio.h> | |
112 #include <string.h> | |
113 | |
114 #ifdef WIN32 | |
115 #define ORTHANC_PLUGINS_API __declspec(dllexport) | |
116 #else | |
117 #define ORTHANC_PLUGINS_API | |
118 #endif | |
119 | |
120 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1 | |
121 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 4 | |
122 #define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 2 | |
123 | |
124 | |
125 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) | |
126 #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \ | |
127 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \ | |
128 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \ | |
129 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \ | |
130 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \ | |
131 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision)))) | |
132 #endif | |
133 | |
134 | |
135 | |
136 /******************************************************************** | |
137 ** Check that function inlining is properly supported. The use of | |
138 ** inlining is required, to avoid the duplication of object code | |
139 ** between two compilation modules that would use the Orthanc Plugin | |
140 ** API. | |
141 ********************************************************************/ | |
142 | |
143 /* If the auto-detection of the "inline" keyword below does not work | |
144 automatically and that your compiler is known to properly support | |
145 inlining, uncomment the following #define and adapt the definition | |
146 of "static inline". */ | |
147 | |
148 /* #define ORTHANC_PLUGIN_INLINE static inline */ | |
149 | |
150 #ifndef ORTHANC_PLUGIN_INLINE | |
151 # if __STDC_VERSION__ >= 199901L | |
152 /* This is C99 or above: http://predef.sourceforge.net/prestd.html */ | |
153 # define ORTHANC_PLUGIN_INLINE static inline | |
154 # elif defined(__cplusplus) | |
155 /* This is C++ */ | |
156 # define ORTHANC_PLUGIN_INLINE static inline | |
157 # elif defined(__GNUC__) | |
158 /* This is GCC running in C89 mode */ | |
159 # define ORTHANC_PLUGIN_INLINE static __inline | |
160 # elif defined(_MSC_VER) | |
161 /* This is Visual Studio running in C89 mode */ | |
162 # define ORTHANC_PLUGIN_INLINE static __inline | |
163 # else | |
164 # error Your compiler is not known to support the "inline" keyword | |
165 # endif | |
166 #endif | |
167 | |
168 | |
169 | |
170 /******************************************************************** | |
171 ** Inclusion of standard libraries. | |
172 ********************************************************************/ | |
173 | |
174 /** | |
175 * For Microsoft Visual Studio, a compatibility "stdint.h" can be | |
176 * downloaded at the following URL: | |
177 * https://orthanc.googlecode.com/hg/Resources/ThirdParty/VisualStudio/stdint.h | |
178 **/ | |
179 #include <stdint.h> | |
180 | |
181 #include <stdlib.h> | |
182 | |
183 | |
184 | |
185 /******************************************************************** | |
186 ** Definition of the Orthanc Plugin API. | |
187 ********************************************************************/ | |
188 | |
189 /** @{ */ | |
190 | |
191 #ifdef __cplusplus | |
192 extern "C" | |
193 { | |
194 #endif | |
195 | |
196 /** | |
197 * The various error codes that can be returned by the Orthanc core. | |
198 **/ | |
199 typedef enum | |
200 { | |
201 OrthancPluginErrorCode_InternalError = -1 /*!< Internal error */, | |
202 OrthancPluginErrorCode_Success = 0 /*!< Success */, | |
203 OrthancPluginErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */, | |
204 OrthancPluginErrorCode_NotImplemented = 2 /*!< Not implemented yet */, | |
205 OrthancPluginErrorCode_ParameterOutOfRange = 3 /*!< Parameter out of range */, | |
206 OrthancPluginErrorCode_NotEnoughMemory = 4 /*!< The server hosting Orthanc is running out of memory */, | |
207 OrthancPluginErrorCode_BadParameterType = 5 /*!< Bad type for a parameter */, | |
208 OrthancPluginErrorCode_BadSequenceOfCalls = 6 /*!< Bad sequence of calls */, | |
209 OrthancPluginErrorCode_InexistentItem = 7 /*!< Accessing an inexistent item */, | |
210 OrthancPluginErrorCode_BadRequest = 8 /*!< Bad request */, | |
211 OrthancPluginErrorCode_NetworkProtocol = 9 /*!< Error in the network protocol */, | |
212 OrthancPluginErrorCode_SystemCommand = 10 /*!< Error while calling a system command */, | |
213 OrthancPluginErrorCode_Database = 11 /*!< Error with the database engine */, | |
214 OrthancPluginErrorCode_UriSyntax = 12 /*!< Badly formatted URI */, | |
215 OrthancPluginErrorCode_InexistentFile = 13 /*!< Inexistent file */, | |
216 OrthancPluginErrorCode_CannotWriteFile = 14 /*!< Cannot write to file */, | |
217 OrthancPluginErrorCode_BadFileFormat = 15 /*!< Bad file format */, | |
218 OrthancPluginErrorCode_Timeout = 16 /*!< Timeout */, | |
219 OrthancPluginErrorCode_UnknownResource = 17 /*!< Unknown resource */, | |
220 OrthancPluginErrorCode_IncompatibleDatabaseVersion = 18 /*!< Incompatible version of the database */, | |
221 OrthancPluginErrorCode_FullStorage = 19 /*!< The file storage is full */, | |
222 OrthancPluginErrorCode_CorruptedFile = 20 /*!< Corrupted file (e.g. inconsistent MD5 hash) */, | |
223 OrthancPluginErrorCode_InexistentTag = 21 /*!< Inexistent tag */, | |
224 OrthancPluginErrorCode_ReadOnly = 22 /*!< Cannot modify a read-only data structure */, | |
225 OrthancPluginErrorCode_IncompatibleImageFormat = 23 /*!< Incompatible format of the images */, | |
226 OrthancPluginErrorCode_IncompatibleImageSize = 24 /*!< Incompatible size of the images */, | |
227 OrthancPluginErrorCode_SharedLibrary = 25 /*!< Error while using a shared library (plugin) */, | |
228 OrthancPluginErrorCode_UnknownPluginService = 26 /*!< Plugin invoking an unknown service */, | |
229 OrthancPluginErrorCode_UnknownDicomTag = 27 /*!< Unknown DICOM tag */, | |
230 OrthancPluginErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */, | |
231 OrthancPluginErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */, | |
232 OrthancPluginErrorCode_BadFont = 30 /*!< Badly formatted font file */, | |
233 OrthancPluginErrorCode_DatabasePlugin = 31 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */, | |
234 OrthancPluginErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */, | |
235 OrthancPluginErrorCode_EmptyRequest = 33 /*!< The request is empty */, | |
236 OrthancPluginErrorCode_NotAcceptable = 34 /*!< Cannot send a response which is acceptable according to the Accept HTTP header */, | |
237 OrthancPluginErrorCode_NullPointer = 35 /*!< Cannot handle a NULL pointer */, | |
238 OrthancPluginErrorCode_DatabaseUnavailable = 36 /*!< The database is currently not available (probably a transient situation) */, | |
239 OrthancPluginErrorCode_CanceledJob = 37 /*!< This job was canceled */, | |
240 OrthancPluginErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */, | |
241 OrthancPluginErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */, | |
242 OrthancPluginErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */, | |
243 OrthancPluginErrorCode_SQLiteStatementAlreadyUsed = 1003 /*!< SQLite: This cached statement is already being referred to */, | |
244 OrthancPluginErrorCode_SQLiteExecute = 1004 /*!< SQLite: Cannot execute a command */, | |
245 OrthancPluginErrorCode_SQLiteRollbackWithoutTransaction = 1005 /*!< SQLite: Rolling back a nonexistent transaction (have you called Begin()?) */, | |
246 OrthancPluginErrorCode_SQLiteCommitWithoutTransaction = 1006 /*!< SQLite: Committing a nonexistent transaction */, | |
247 OrthancPluginErrorCode_SQLiteRegisterFunction = 1007 /*!< SQLite: Unable to register a function */, | |
248 OrthancPluginErrorCode_SQLiteFlush = 1008 /*!< SQLite: Unable to flush the database */, | |
249 OrthancPluginErrorCode_SQLiteCannotRun = 1009 /*!< SQLite: Cannot run a cached statement */, | |
250 OrthancPluginErrorCode_SQLiteCannotStep = 1010 /*!< SQLite: Cannot step over a cached statement */, | |
251 OrthancPluginErrorCode_SQLiteBindOutOfRange = 1011 /*!< SQLite: Bing a value while out of range (serious error) */, | |
252 OrthancPluginErrorCode_SQLitePrepareStatement = 1012 /*!< SQLite: Cannot prepare a cached statement */, | |
253 OrthancPluginErrorCode_SQLiteTransactionAlreadyStarted = 1013 /*!< SQLite: Beginning the same transaction twice */, | |
254 OrthancPluginErrorCode_SQLiteTransactionCommit = 1014 /*!< SQLite: Failure when committing the transaction */, | |
255 OrthancPluginErrorCode_SQLiteTransactionBegin = 1015 /*!< SQLite: Cannot start a transaction */, | |
256 OrthancPluginErrorCode_DirectoryOverFile = 2000 /*!< The directory to be created is already occupied by a regular file */, | |
257 OrthancPluginErrorCode_FileStorageCannotWrite = 2001 /*!< Unable to create a subdirectory or a file in the file storage */, | |
258 OrthancPluginErrorCode_DirectoryExpected = 2002 /*!< The specified path does not point to a directory */, | |
259 OrthancPluginErrorCode_HttpPortInUse = 2003 /*!< The TCP port of the HTTP server is privileged or already in use */, | |
260 OrthancPluginErrorCode_DicomPortInUse = 2004 /*!< The TCP port of the DICOM server is privileged or already in use */, | |
261 OrthancPluginErrorCode_BadHttpStatusInRest = 2005 /*!< This HTTP status is not allowed in a REST API */, | |
262 OrthancPluginErrorCode_RegularFileExpected = 2006 /*!< The specified path does not point to a regular file */, | |
263 OrthancPluginErrorCode_PathToExecutable = 2007 /*!< Unable to get the path to the executable */, | |
264 OrthancPluginErrorCode_MakeDirectory = 2008 /*!< Cannot create a directory */, | |
265 OrthancPluginErrorCode_BadApplicationEntityTitle = 2009 /*!< An application entity title (AET) cannot be empty or be longer than 16 characters */, | |
266 OrthancPluginErrorCode_NoCFindHandler = 2010 /*!< No request handler factory for DICOM C-FIND SCP */, | |
267 OrthancPluginErrorCode_NoCMoveHandler = 2011 /*!< No request handler factory for DICOM C-MOVE SCP */, | |
268 OrthancPluginErrorCode_NoCStoreHandler = 2012 /*!< No request handler factory for DICOM C-STORE SCP */, | |
269 OrthancPluginErrorCode_NoApplicationEntityFilter = 2013 /*!< No application entity filter */, | |
270 OrthancPluginErrorCode_NoSopClassOrInstance = 2014 /*!< DicomUserConnection: Unable to find the SOP class and instance */, | |
271 OrthancPluginErrorCode_NoPresentationContext = 2015 /*!< DicomUserConnection: No acceptable presentation context for modality */, | |
272 OrthancPluginErrorCode_DicomFindUnavailable = 2016 /*!< DicomUserConnection: The C-FIND command is not supported by the remote SCP */, | |
273 OrthancPluginErrorCode_DicomMoveUnavailable = 2017 /*!< DicomUserConnection: The C-MOVE command is not supported by the remote SCP */, | |
274 OrthancPluginErrorCode_CannotStoreInstance = 2018 /*!< Cannot store an instance */, | |
275 OrthancPluginErrorCode_CreateDicomNotString = 2019 /*!< Only string values are supported when creating DICOM instances */, | |
276 OrthancPluginErrorCode_CreateDicomOverrideTag = 2020 /*!< Trying to override a value inherited from a parent module */, | |
277 OrthancPluginErrorCode_CreateDicomUseContent = 2021 /*!< Use \"Content\" to inject an image into a new DICOM instance */, | |
278 OrthancPluginErrorCode_CreateDicomNoPayload = 2022 /*!< No payload is present for one instance in the series */, | |
279 OrthancPluginErrorCode_CreateDicomUseDataUriScheme = 2023 /*!< The payload of the DICOM instance must be specified according to Data URI scheme */, | |
280 OrthancPluginErrorCode_CreateDicomBadParent = 2024 /*!< Trying to attach a new DICOM instance to an inexistent resource */, | |
281 OrthancPluginErrorCode_CreateDicomParentIsInstance = 2025 /*!< Trying to attach a new DICOM instance to an instance (must be a series, study or patient) */, | |
282 OrthancPluginErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */, | |
283 OrthancPluginErrorCode_UnknownModality = 2027 /*!< Unknown modality */, | |
284 OrthancPluginErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */, | |
285 OrthancPluginErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */, | |
286 OrthancPluginErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */, | |
287 OrthancPluginErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */, | |
288 OrthancPluginErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */, | |
289 OrthancPluginErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */, | |
290 OrthancPluginErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */, | |
291 OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */, | |
292 OrthancPluginErrorCode_StorageAreaAlreadyRegistered = 2036 /*!< Another plugin has already registered a custom storage area */, | |
293 OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered = 2037 /*!< Another plugin has already registered a custom database back-end */, | |
294 OrthancPluginErrorCode_DatabaseNotInitialized = 2038 /*!< Plugin trying to call the database during its initialization */, | |
295 OrthancPluginErrorCode_SslDisabled = 2039 /*!< Orthanc has been built without SSL support */, | |
296 OrthancPluginErrorCode_CannotOrderSlices = 2040 /*!< Unable to order the slices of the series */, | |
297 OrthancPluginErrorCode_NoWorklistHandler = 2041 /*!< No request handler factory for DICOM C-Find Modality SCP */, | |
298 OrthancPluginErrorCode_AlreadyExistingTag = 2042 /*!< Cannot override the value of a tag that already exists */, | |
299 | |
300 _OrthancPluginErrorCode_INTERNAL = 0x7fffffff | |
301 } OrthancPluginErrorCode; | |
302 | |
303 | |
304 /** | |
305 * Forward declaration of one of the mandatory functions for Orthanc | |
306 * plugins. | |
307 **/ | |
308 ORTHANC_PLUGINS_API const char* OrthancPluginGetName(); | |
309 | |
310 | |
311 /** | |
312 * The various HTTP methods for a REST call. | |
313 **/ | |
314 typedef enum | |
315 { | |
316 OrthancPluginHttpMethod_Get = 1, /*!< GET request */ | |
317 OrthancPluginHttpMethod_Post = 2, /*!< POST request */ | |
318 OrthancPluginHttpMethod_Put = 3, /*!< PUT request */ | |
319 OrthancPluginHttpMethod_Delete = 4, /*!< DELETE request */ | |
320 | |
321 _OrthancPluginHttpMethod_INTERNAL = 0x7fffffff | |
322 } OrthancPluginHttpMethod; | |
323 | |
324 | |
325 /** | |
326 * @brief The parameters of a REST request. | |
327 * @ingroup Callbacks | |
328 **/ | |
329 typedef struct | |
330 { | |
331 /** | |
332 * @brief The HTTP method. | |
333 **/ | |
334 OrthancPluginHttpMethod method; | |
335 | |
336 /** | |
337 * @brief The number of groups of the regular expression. | |
338 **/ | |
339 uint32_t groupsCount; | |
340 | |
341 /** | |
342 * @brief The matched values for the groups of the regular expression. | |
343 **/ | |
344 const char* const* groups; | |
345 | |
346 /** | |
347 * @brief For a GET request, the number of GET parameters. | |
348 **/ | |
349 uint32_t getCount; | |
350 | |
351 /** | |
352 * @brief For a GET request, the keys of the GET parameters. | |
353 **/ | |
354 const char* const* getKeys; | |
355 | |
356 /** | |
357 * @brief For a GET request, the values of the GET parameters. | |
358 **/ | |
359 const char* const* getValues; | |
360 | |
361 /** | |
362 * @brief For a PUT or POST request, the content of the body. | |
363 **/ | |
364 const char* body; | |
365 | |
366 /** | |
367 * @brief For a PUT or POST request, the number of bytes of the body. | |
368 **/ | |
369 uint32_t bodySize; | |
370 | |
371 | |
372 /* -------------------------------------------------- | |
373 New in version 0.8.1 | |
374 -------------------------------------------------- */ | |
375 | |
376 /** | |
377 * @brief The number of HTTP headers. | |
378 **/ | |
379 uint32_t headersCount; | |
380 | |
381 /** | |
382 * @brief The keys of the HTTP headers (always converted to low-case). | |
383 **/ | |
384 const char* const* headersKeys; | |
385 | |
386 /** | |
387 * @brief The values of the HTTP headers. | |
388 **/ | |
389 const char* const* headersValues; | |
390 | |
391 } OrthancPluginHttpRequest; | |
392 | |
393 | |
394 typedef enum | |
395 { | |
396 /* Generic services */ | |
397 _OrthancPluginService_LogInfo = 1, | |
398 _OrthancPluginService_LogWarning = 2, | |
399 _OrthancPluginService_LogError = 3, | |
400 _OrthancPluginService_GetOrthancPath = 4, | |
401 _OrthancPluginService_GetOrthancDirectory = 5, | |
402 _OrthancPluginService_GetConfigurationPath = 6, | |
403 _OrthancPluginService_SetPluginProperty = 7, | |
404 _OrthancPluginService_GetGlobalProperty = 8, | |
405 _OrthancPluginService_SetGlobalProperty = 9, | |
406 _OrthancPluginService_GetCommandLineArgumentsCount = 10, | |
407 _OrthancPluginService_GetCommandLineArgument = 11, | |
408 _OrthancPluginService_GetExpectedDatabaseVersion = 12, | |
409 _OrthancPluginService_GetConfiguration = 13, | |
410 _OrthancPluginService_BufferCompression = 14, | |
411 _OrthancPluginService_ReadFile = 15, | |
412 _OrthancPluginService_WriteFile = 16, | |
413 _OrthancPluginService_GetErrorDescription = 17, | |
414 _OrthancPluginService_CallHttpClient = 18, | |
415 _OrthancPluginService_RegisterErrorCode = 19, | |
416 _OrthancPluginService_RegisterDictionaryTag = 20, | |
417 _OrthancPluginService_DicomBufferToJson = 21, | |
418 _OrthancPluginService_DicomInstanceToJson = 22, | |
419 _OrthancPluginService_CreateDicom = 23, | |
420 _OrthancPluginService_ComputeMd5 = 24, | |
421 _OrthancPluginService_ComputeSha1 = 25, | |
422 _OrthancPluginService_LookupDictionary = 26, | |
423 _OrthancPluginService_CallHttpClient2 = 27, | |
424 _OrthancPluginService_GenerateUuid = 28, | |
425 _OrthancPluginService_RegisterPrivateDictionaryTag = 29, | |
426 | |
427 /* Registration of callbacks */ | |
428 _OrthancPluginService_RegisterRestCallback = 1000, | |
429 _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001, | |
430 _OrthancPluginService_RegisterStorageArea = 1002, | |
431 _OrthancPluginService_RegisterOnChangeCallback = 1003, | |
432 _OrthancPluginService_RegisterRestCallbackNoLock = 1004, | |
433 _OrthancPluginService_RegisterWorklistCallback = 1005, | |
434 _OrthancPluginService_RegisterDecodeImageCallback = 1006, | |
435 _OrthancPluginService_RegisterIncomingHttpRequestFilter = 1007, | |
436 _OrthancPluginService_RegisterFindCallback = 1008, | |
437 _OrthancPluginService_RegisterMoveCallback = 1009, | |
438 _OrthancPluginService_RegisterIncomingHttpRequestFilter2 = 1010, | |
439 | |
440 /* Sending answers to REST calls */ | |
441 _OrthancPluginService_AnswerBuffer = 2000, | |
442 _OrthancPluginService_CompressAndAnswerPngImage = 2001, /* Unused as of Orthanc 0.9.4 */ | |
443 _OrthancPluginService_Redirect = 2002, | |
444 _OrthancPluginService_SendHttpStatusCode = 2003, | |
445 _OrthancPluginService_SendUnauthorized = 2004, | |
446 _OrthancPluginService_SendMethodNotAllowed = 2005, | |
447 _OrthancPluginService_SetCookie = 2006, | |
448 _OrthancPluginService_SetHttpHeader = 2007, | |
449 _OrthancPluginService_StartMultipartAnswer = 2008, | |
450 _OrthancPluginService_SendMultipartItem = 2009, | |
451 _OrthancPluginService_SendHttpStatus = 2010, | |
452 _OrthancPluginService_CompressAndAnswerImage = 2011, | |
453 _OrthancPluginService_SendMultipartItem2 = 2012, | |
454 | |
455 /* Access to the Orthanc database and API */ | |
456 _OrthancPluginService_GetDicomForInstance = 3000, | |
457 _OrthancPluginService_RestApiGet = 3001, | |
458 _OrthancPluginService_RestApiPost = 3002, | |
459 _OrthancPluginService_RestApiDelete = 3003, | |
460 _OrthancPluginService_RestApiPut = 3004, | |
461 _OrthancPluginService_LookupPatient = 3005, | |
462 _OrthancPluginService_LookupStudy = 3006, | |
463 _OrthancPluginService_LookupSeries = 3007, | |
464 _OrthancPluginService_LookupInstance = 3008, | |
465 _OrthancPluginService_LookupStudyWithAccessionNumber = 3009, | |
466 _OrthancPluginService_RestApiGetAfterPlugins = 3010, | |
467 _OrthancPluginService_RestApiPostAfterPlugins = 3011, | |
468 _OrthancPluginService_RestApiDeleteAfterPlugins = 3012, | |
469 _OrthancPluginService_RestApiPutAfterPlugins = 3013, | |
470 _OrthancPluginService_ReconstructMainDicomTags = 3014, | |
471 _OrthancPluginService_RestApiGet2 = 3015, | |
472 | |
473 /* Access to DICOM instances */ | |
474 _OrthancPluginService_GetInstanceRemoteAet = 4000, | |
475 _OrthancPluginService_GetInstanceSize = 4001, | |
476 _OrthancPluginService_GetInstanceData = 4002, | |
477 _OrthancPluginService_GetInstanceJson = 4003, | |
478 _OrthancPluginService_GetInstanceSimplifiedJson = 4004, | |
479 _OrthancPluginService_HasInstanceMetadata = 4005, | |
480 _OrthancPluginService_GetInstanceMetadata = 4006, | |
481 _OrthancPluginService_GetInstanceOrigin = 4007, | |
482 | |
483 /* Services for plugins implementing a database back-end */ | |
484 _OrthancPluginService_RegisterDatabaseBackend = 5000, | |
485 _OrthancPluginService_DatabaseAnswer = 5001, | |
486 _OrthancPluginService_RegisterDatabaseBackendV2 = 5002, | |
487 _OrthancPluginService_StorageAreaCreate = 5003, | |
488 _OrthancPluginService_StorageAreaRead = 5004, | |
489 _OrthancPluginService_StorageAreaRemove = 5005, | |
490 | |
491 /* Primitives for handling images */ | |
492 _OrthancPluginService_GetImagePixelFormat = 6000, | |
493 _OrthancPluginService_GetImageWidth = 6001, | |
494 _OrthancPluginService_GetImageHeight = 6002, | |
495 _OrthancPluginService_GetImagePitch = 6003, | |
496 _OrthancPluginService_GetImageBuffer = 6004, | |
497 _OrthancPluginService_UncompressImage = 6005, | |
498 _OrthancPluginService_FreeImage = 6006, | |
499 _OrthancPluginService_CompressImage = 6007, | |
500 _OrthancPluginService_ConvertPixelFormat = 6008, | |
501 _OrthancPluginService_GetFontsCount = 6009, | |
502 _OrthancPluginService_GetFontInfo = 6010, | |
503 _OrthancPluginService_DrawText = 6011, | |
504 _OrthancPluginService_CreateImage = 6012, | |
505 _OrthancPluginService_CreateImageAccessor = 6013, | |
506 _OrthancPluginService_DecodeDicomImage = 6014, | |
507 | |
508 /* Primitives for handling C-Find, C-Move and worklists */ | |
509 _OrthancPluginService_WorklistAddAnswer = 7000, | |
510 _OrthancPluginService_WorklistMarkIncomplete = 7001, | |
511 _OrthancPluginService_WorklistIsMatch = 7002, | |
512 _OrthancPluginService_WorklistGetDicomQuery = 7003, | |
513 _OrthancPluginService_FindAddAnswer = 7004, | |
514 _OrthancPluginService_FindMarkIncomplete = 7005, | |
515 _OrthancPluginService_GetFindQuerySize = 7006, | |
516 _OrthancPluginService_GetFindQueryTag = 7007, | |
517 _OrthancPluginService_GetFindQueryTagName = 7008, | |
518 _OrthancPluginService_GetFindQueryValue = 7009, | |
519 _OrthancPluginService_CreateFindMatcher = 7010, | |
520 _OrthancPluginService_FreeFindMatcher = 7011, | |
521 _OrthancPluginService_FindMatcherIsMatch = 7012, | |
522 | |
523 /* Primitives for accessing Orthanc Peers (new in 1.4.2) */ | |
524 _OrthancPluginService_GetPeers = 8000, | |
525 _OrthancPluginService_FreePeers = 8001, | |
526 _OrthancPluginService_GetPeersCount = 8003, | |
527 _OrthancPluginService_GetPeerName = 8004, | |
528 _OrthancPluginService_GetPeerUrl = 8005, | |
529 _OrthancPluginService_CallPeerApi = 8006, | |
530 _OrthancPluginService_GetPeerUserProperty = 8007, | |
531 | |
532 /* Primitives for handling jobs (new in 1.4.2) */ | |
533 _OrthancPluginService_CreateJob = 9000, | |
534 _OrthancPluginService_FreeJob = 9001, | |
535 _OrthancPluginService_SubmitJob = 9002, | |
536 _OrthancPluginService_RegisterJobsUnserializer = 9003, | |
537 | |
538 _OrthancPluginService_INTERNAL = 0x7fffffff | |
539 } _OrthancPluginService; | |
540 | |
541 | |
542 typedef enum | |
543 { | |
544 _OrthancPluginProperty_Description = 1, | |
545 _OrthancPluginProperty_RootUri = 2, | |
546 _OrthancPluginProperty_OrthancExplorer = 3, | |
547 | |
548 _OrthancPluginProperty_INTERNAL = 0x7fffffff | |
549 } _OrthancPluginProperty; | |
550 | |
551 | |
552 | |
553 /** | |
554 * The memory layout of the pixels of an image. | |
555 * @ingroup Images | |
556 **/ | |
557 typedef enum | |
558 { | |
559 /** | |
560 * @brief Graylevel 8bpp image. | |
561 * | |
562 * The image is graylevel. Each pixel is unsigned and stored in | |
563 * one byte. | |
564 **/ | |
565 OrthancPluginPixelFormat_Grayscale8 = 1, | |
566 | |
567 /** | |
568 * @brief Graylevel, unsigned 16bpp image. | |
569 * | |
570 * The image is graylevel. Each pixel is unsigned and stored in | |
571 * two bytes. | |
572 **/ | |
573 OrthancPluginPixelFormat_Grayscale16 = 2, | |
574 | |
575 /** | |
576 * @brief Graylevel, signed 16bpp image. | |
577 * | |
578 * The image is graylevel. Each pixel is signed and stored in two | |
579 * bytes. | |
580 **/ | |
581 OrthancPluginPixelFormat_SignedGrayscale16 = 3, | |
582 | |
583 /** | |
584 * @brief Color image in RGB24 format. | |
585 * | |
586 * This format describes a color image. The pixels are stored in 3 | |
587 * consecutive bytes. The memory layout is RGB. | |
588 **/ | |
589 OrthancPluginPixelFormat_RGB24 = 4, | |
590 | |
591 /** | |
592 * @brief Color image in RGBA32 format. | |
593 * | |
594 * This format describes a color image. The pixels are stored in 4 | |
595 * consecutive bytes. The memory layout is RGBA. | |
596 **/ | |
597 OrthancPluginPixelFormat_RGBA32 = 5, | |
598 | |
599 OrthancPluginPixelFormat_Unknown = 6, /*!< Unknown pixel format */ | |
600 | |
601 /** | |
602 * @brief Color image in RGB48 format. | |
603 * | |
604 * This format describes a color image. The pixels are stored in 6 | |
605 * consecutive bytes. The memory layout is RRGGBB. | |
606 **/ | |
607 OrthancPluginPixelFormat_RGB48 = 7, | |
608 | |
609 /** | |
610 * @brief Graylevel, unsigned 32bpp image. | |
611 * | |
612 * The image is graylevel. Each pixel is unsigned and stored in | |
613 * four bytes. | |
614 **/ | |
615 OrthancPluginPixelFormat_Grayscale32 = 8, | |
616 | |
617 /** | |
618 * @brief Graylevel, floating-point 32bpp image. | |
619 * | |
620 * The image is graylevel. Each pixel is floating-point and stored | |
621 * in four bytes. | |
622 **/ | |
623 OrthancPluginPixelFormat_Float32 = 9, | |
624 | |
625 /** | |
626 * @brief Color image in BGRA32 format. | |
627 * | |
628 * This format describes a color image. The pixels are stored in 4 | |
629 * consecutive bytes. The memory layout is BGRA. | |
630 **/ | |
631 OrthancPluginPixelFormat_BGRA32 = 10, | |
632 | |
633 /** | |
634 * @brief Graylevel, unsigned 64bpp image. | |
635 * | |
636 * The image is graylevel. Each pixel is unsigned and stored in | |
637 * eight bytes. | |
638 **/ | |
639 OrthancPluginPixelFormat_Grayscale64 = 11, | |
640 | |
641 _OrthancPluginPixelFormat_INTERNAL = 0x7fffffff | |
642 } OrthancPluginPixelFormat; | |
643 | |
644 | |
645 | |
646 /** | |
647 * The content types that are supported by Orthanc plugins. | |
648 **/ | |
649 typedef enum | |
650 { | |
651 OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */ | |
652 OrthancPluginContentType_Dicom = 1, /*!< DICOM */ | |
653 OrthancPluginContentType_DicomAsJson = 2, /*!< JSON summary of a DICOM file */ | |
654 | |
655 _OrthancPluginContentType_INTERNAL = 0x7fffffff | |
656 } OrthancPluginContentType; | |
657 | |
658 | |
659 | |
660 /** | |
661 * The supported types of DICOM resources. | |
662 **/ | |
663 typedef enum | |
664 { | |
665 OrthancPluginResourceType_Patient = 0, /*!< Patient */ | |
666 OrthancPluginResourceType_Study = 1, /*!< Study */ | |
667 OrthancPluginResourceType_Series = 2, /*!< Series */ | |
668 OrthancPluginResourceType_Instance = 3, /*!< Instance */ | |
669 OrthancPluginResourceType_None = 4, /*!< Unavailable resource type */ | |
670 | |
671 _OrthancPluginResourceType_INTERNAL = 0x7fffffff | |
672 } OrthancPluginResourceType; | |
673 | |
674 | |
675 | |
676 /** | |
677 * The supported types of changes that can happen to DICOM resources. | |
678 * @ingroup Callbacks | |
679 **/ | |
680 typedef enum | |
681 { | |
682 OrthancPluginChangeType_CompletedSeries = 0, /*!< Series is now complete */ | |
683 OrthancPluginChangeType_Deleted = 1, /*!< Deleted resource */ | |
684 OrthancPluginChangeType_NewChildInstance = 2, /*!< A new instance was added to this resource */ | |
685 OrthancPluginChangeType_NewInstance = 3, /*!< New instance received */ | |
686 OrthancPluginChangeType_NewPatient = 4, /*!< New patient created */ | |
687 OrthancPluginChangeType_NewSeries = 5, /*!< New series created */ | |
688 OrthancPluginChangeType_NewStudy = 6, /*!< New study created */ | |
689 OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */ | |
690 OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */ | |
691 OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */ | |
692 OrthancPluginChangeType_OrthancStarted = 10, /*!< Orthanc has started */ | |
693 OrthancPluginChangeType_OrthancStopped = 11, /*!< Orthanc is stopping */ | |
694 OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */ | |
695 OrthancPluginChangeType_UpdatedMetadata = 13, /*!< Some user-defined metadata has changed for this resource */ | |
696 OrthancPluginChangeType_UpdatedPeers = 14, /*!< The list of Orthanc peers has changed */ | |
697 OrthancPluginChangeType_UpdatedModalities = 15, /*!< The list of DICOM modalities has changed */ | |
698 | |
699 _OrthancPluginChangeType_INTERNAL = 0x7fffffff | |
700 } OrthancPluginChangeType; | |
701 | |
702 | |
703 /** | |
704 * The compression algorithms that are supported by the Orthanc core. | |
705 * @ingroup Images | |
706 **/ | |
707 typedef enum | |
708 { | |
709 OrthancPluginCompressionType_Zlib = 0, /*!< Standard zlib compression */ | |
710 OrthancPluginCompressionType_ZlibWithSize = 1, /*!< zlib, prefixed with uncompressed size (uint64_t) */ | |
711 OrthancPluginCompressionType_Gzip = 2, /*!< Standard gzip compression */ | |
712 OrthancPluginCompressionType_GzipWithSize = 3, /*!< gzip, prefixed with uncompressed size (uint64_t) */ | |
713 | |
714 _OrthancPluginCompressionType_INTERNAL = 0x7fffffff | |
715 } OrthancPluginCompressionType; | |
716 | |
717 | |
718 /** | |
719 * The image formats that are supported by the Orthanc core. | |
720 * @ingroup Images | |
721 **/ | |
722 typedef enum | |
723 { | |
724 OrthancPluginImageFormat_Png = 0, /*!< Image compressed using PNG */ | |
725 OrthancPluginImageFormat_Jpeg = 1, /*!< Image compressed using JPEG */ | |
726 OrthancPluginImageFormat_Dicom = 2, /*!< Image compressed using DICOM */ | |
727 | |
728 _OrthancPluginImageFormat_INTERNAL = 0x7fffffff | |
729 } OrthancPluginImageFormat; | |
730 | |
731 | |
732 /** | |
733 * The value representations present in the DICOM standard (version 2013). | |
734 * @ingroup Toolbox | |
735 **/ | |
736 typedef enum | |
737 { | |
738 OrthancPluginValueRepresentation_AE = 1, /*!< Application Entity */ | |
739 OrthancPluginValueRepresentation_AS = 2, /*!< Age String */ | |
740 OrthancPluginValueRepresentation_AT = 3, /*!< Attribute Tag */ | |
741 OrthancPluginValueRepresentation_CS = 4, /*!< Code String */ | |
742 OrthancPluginValueRepresentation_DA = 5, /*!< Date */ | |
743 OrthancPluginValueRepresentation_DS = 6, /*!< Decimal String */ | |
744 OrthancPluginValueRepresentation_DT = 7, /*!< Date Time */ | |
745 OrthancPluginValueRepresentation_FD = 8, /*!< Floating Point Double */ | |
746 OrthancPluginValueRepresentation_FL = 9, /*!< Floating Point Single */ | |
747 OrthancPluginValueRepresentation_IS = 10, /*!< Integer String */ | |
748 OrthancPluginValueRepresentation_LO = 11, /*!< Long String */ | |
749 OrthancPluginValueRepresentation_LT = 12, /*!< Long Text */ | |
750 OrthancPluginValueRepresentation_OB = 13, /*!< Other Byte String */ | |
751 OrthancPluginValueRepresentation_OF = 14, /*!< Other Float String */ | |
752 OrthancPluginValueRepresentation_OW = 15, /*!< Other Word String */ | |
753 OrthancPluginValueRepresentation_PN = 16, /*!< Person Name */ | |
754 OrthancPluginValueRepresentation_SH = 17, /*!< Short String */ | |
755 OrthancPluginValueRepresentation_SL = 18, /*!< Signed Long */ | |
756 OrthancPluginValueRepresentation_SQ = 19, /*!< Sequence of Items */ | |
757 OrthancPluginValueRepresentation_SS = 20, /*!< Signed Short */ | |
758 OrthancPluginValueRepresentation_ST = 21, /*!< Short Text */ | |
759 OrthancPluginValueRepresentation_TM = 22, /*!< Time */ | |
760 OrthancPluginValueRepresentation_UI = 23, /*!< Unique Identifier (UID) */ | |
761 OrthancPluginValueRepresentation_UL = 24, /*!< Unsigned Long */ | |
762 OrthancPluginValueRepresentation_UN = 25, /*!< Unknown */ | |
763 OrthancPluginValueRepresentation_US = 26, /*!< Unsigned Short */ | |
764 OrthancPluginValueRepresentation_UT = 27, /*!< Unlimited Text */ | |
765 | |
766 _OrthancPluginValueRepresentation_INTERNAL = 0x7fffffff | |
767 } OrthancPluginValueRepresentation; | |
768 | |
769 | |
770 /** | |
771 * The possible output formats for a DICOM-to-JSON conversion. | |
772 * @ingroup Toolbox | |
773 * @see OrthancPluginDicomToJson() | |
774 **/ | |
775 typedef enum | |
776 { | |
777 OrthancPluginDicomToJsonFormat_Full = 1, /*!< Full output, with most details */ | |
778 OrthancPluginDicomToJsonFormat_Short = 2, /*!< Tags output as hexadecimal numbers */ | |
779 OrthancPluginDicomToJsonFormat_Human = 3, /*!< Human-readable JSON */ | |
780 | |
781 _OrthancPluginDicomToJsonFormat_INTERNAL = 0x7fffffff | |
782 } OrthancPluginDicomToJsonFormat; | |
783 | |
784 | |
785 /** | |
786 * Flags to customize a DICOM-to-JSON conversion. By default, binary | |
787 * tags are formatted using Data URI scheme. | |
788 * @ingroup Toolbox | |
789 **/ | |
790 typedef enum | |
791 { | |
792 OrthancPluginDicomToJsonFlags_None = 0, | |
793 OrthancPluginDicomToJsonFlags_IncludeBinary = (1 << 0), /*!< Include the binary tags */ | |
794 OrthancPluginDicomToJsonFlags_IncludePrivateTags = (1 << 1), /*!< Include the private tags */ | |
795 OrthancPluginDicomToJsonFlags_IncludeUnknownTags = (1 << 2), /*!< Include the tags unknown by the dictionary */ | |
796 OrthancPluginDicomToJsonFlags_IncludePixelData = (1 << 3), /*!< Include the pixel data */ | |
797 OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii = (1 << 4), /*!< Output binary tags as-is, dropping non-ASCII */ | |
798 OrthancPluginDicomToJsonFlags_ConvertBinaryToNull = (1 << 5), /*!< Signal binary tags as null values */ | |
799 | |
800 _OrthancPluginDicomToJsonFlags_INTERNAL = 0x7fffffff | |
801 } OrthancPluginDicomToJsonFlags; | |
802 | |
803 | |
804 /** | |
805 * Flags to the creation of a DICOM file. | |
806 * @ingroup Toolbox | |
807 * @see OrthancPluginCreateDicom() | |
808 **/ | |
809 typedef enum | |
810 { | |
811 OrthancPluginCreateDicomFlags_None = 0, | |
812 OrthancPluginCreateDicomFlags_DecodeDataUriScheme = (1 << 0), /*!< Decode fields encoded using data URI scheme */ | |
813 OrthancPluginCreateDicomFlags_GenerateIdentifiers = (1 << 1), /*!< Automatically generate DICOM identifiers */ | |
814 | |
815 _OrthancPluginCreateDicomFlags_INTERNAL = 0x7fffffff | |
816 } OrthancPluginCreateDicomFlags; | |
817 | |
818 | |
819 /** | |
820 * The constraints on the DICOM identifiers that must be supported | |
821 * by the database plugins. | |
822 **/ | |
823 typedef enum | |
824 { | |
825 OrthancPluginIdentifierConstraint_Equal = 1, /*!< Equal */ | |
826 OrthancPluginIdentifierConstraint_SmallerOrEqual = 2, /*!< Less or equal */ | |
827 OrthancPluginIdentifierConstraint_GreaterOrEqual = 3, /*!< More or equal */ | |
828 OrthancPluginIdentifierConstraint_Wildcard = 4, /*!< Case-sensitive wildcard matching (with * and ?) */ | |
829 | |
830 _OrthancPluginIdentifierConstraint_INTERNAL = 0x7fffffff | |
831 } OrthancPluginIdentifierConstraint; | |
832 | |
833 | |
834 /** | |
835 * The origin of a DICOM instance that has been received by Orthanc. | |
836 **/ | |
837 typedef enum | |
838 { | |
839 OrthancPluginInstanceOrigin_Unknown = 1, /*!< Unknown origin */ | |
840 OrthancPluginInstanceOrigin_DicomProtocol = 2, /*!< Instance received through DICOM protocol */ | |
841 OrthancPluginInstanceOrigin_RestApi = 3, /*!< Instance received through REST API of Orthanc */ | |
842 OrthancPluginInstanceOrigin_Plugin = 4, /*!< Instance added to Orthanc by a plugin */ | |
843 OrthancPluginInstanceOrigin_Lua = 5, /*!< Instance added to Orthanc by a Lua script */ | |
844 | |
845 _OrthancPluginInstanceOrigin_INTERNAL = 0x7fffffff | |
846 } OrthancPluginInstanceOrigin; | |
847 | |
848 | |
849 /** | |
850 * The possible status for one single step of a job. | |
851 **/ | |
852 typedef enum | |
853 { | |
854 OrthancPluginJobStepStatus_Success = 1, /*!< The job has successfully executed all its steps */ | |
855 OrthancPluginJobStepStatus_Failure = 2, /*!< The job has failed while executing this step */ | |
856 OrthancPluginJobStepStatus_Continue = 3 /*!< The job has still data to process after this step */ | |
857 } OrthancPluginJobStepStatus; | |
858 | |
859 | |
860 /** | |
861 * Explains why the job should stop and release the resources it has | |
862 * allocated. This is especially important to disambiguate between | |
863 * the "paused" condition and the "final" conditions (success, | |
864 * failure, or canceled). | |
865 **/ | |
866 typedef enum | |
867 { | |
868 OrthancPluginJobStopReason_Success = 1, /*!< The job has succeeded */ | |
869 OrthancPluginJobStopReason_Paused = 2, /*!< The job was paused, and will be resumed later */ | |
870 OrthancPluginJobStopReason_Failure = 3, /*!< The job has failed, and might be resubmitted later */ | |
871 OrthancPluginJobStopReason_Canceled = 4 /*!< The job was canceled, and might be resubmitted later */ | |
872 } OrthancPluginJobStopReason; | |
873 | |
874 | |
875 /** | |
876 * @brief A memory buffer allocated by the core system of Orthanc. | |
877 * | |
878 * A memory buffer allocated by the core system of Orthanc. When the | |
879 * content of the buffer is not useful anymore, it must be free by a | |
880 * call to ::OrthancPluginFreeMemoryBuffer(). | |
881 **/ | |
882 typedef struct | |
883 { | |
884 /** | |
885 * @brief The content of the buffer. | |
886 **/ | |
887 void* data; | |
888 | |
889 /** | |
890 * @brief The number of bytes in the buffer. | |
891 **/ | |
892 uint32_t size; | |
893 } OrthancPluginMemoryBuffer; | |
894 | |
895 | |
896 | |
897 | |
898 /** | |
899 * @brief Opaque structure that represents the HTTP connection to the client application. | |
900 * @ingroup Callback | |
901 **/ | |
902 typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput; | |
903 | |
904 | |
905 | |
906 /** | |
907 * @brief Opaque structure that represents a DICOM instance received by Orthanc. | |
908 **/ | |
909 typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance; | |
910 | |
911 | |
912 | |
913 /** | |
914 * @brief Opaque structure that represents an image that is uncompressed in memory. | |
915 * @ingroup Images | |
916 **/ | |
917 typedef struct _OrthancPluginImage_t OrthancPluginImage; | |
918 | |
919 | |
920 | |
921 /** | |
922 * @brief Opaque structure that represents the storage area that is actually used by Orthanc. | |
923 * @ingroup Images | |
924 **/ | |
925 typedef struct _OrthancPluginStorageArea_t OrthancPluginStorageArea; | |
926 | |
927 | |
928 | |
929 /** | |
930 * @brief Opaque structure to an object that represents a C-Find query for worklists. | |
931 * @ingroup DicomCallbacks | |
932 **/ | |
933 typedef struct _OrthancPluginWorklistQuery_t OrthancPluginWorklistQuery; | |
934 | |
935 | |
936 | |
937 /** | |
938 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists. | |
939 * @ingroup DicomCallbacks | |
940 **/ | |
941 typedef struct _OrthancPluginWorklistAnswers_t OrthancPluginWorklistAnswers; | |
942 | |
943 | |
944 | |
945 /** | |
946 * @brief Opaque structure to an object that represents a C-Find query. | |
947 * @ingroup DicomCallbacks | |
948 **/ | |
949 typedef struct _OrthancPluginFindQuery_t OrthancPluginFindQuery; | |
950 | |
951 | |
952 | |
953 /** | |
954 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists. | |
955 * @ingroup DicomCallbacks | |
956 **/ | |
957 typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindAnswers; | |
958 | |
959 | |
960 | |
961 /** | |
962 * @brief Opaque structure to an object that can be used to check whether a DICOM instance matches a C-Find query. | |
963 * @ingroup Toolbox | |
964 **/ | |
965 typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindMatcher; | |
966 | |
967 | |
968 | |
969 /** | |
970 * @brief Opaque structure to the set of remote Orthanc Peers that are known to the local Orthanc server. | |
971 * @ingroup Toolbox | |
972 **/ | |
973 typedef struct _OrthancPluginPeers_t OrthancPluginPeers; | |
974 | |
975 | |
976 | |
977 /** | |
978 * @brief Opaque structure to a job to be executed by Orthanc. | |
979 * @ingroup Toolbox | |
980 **/ | |
981 typedef struct _OrthancPluginJob_t OrthancPluginJob; | |
982 | |
983 | |
984 | |
985 /** | |
986 * @brief Signature of a callback function that answers to a REST request. | |
987 * @ingroup Callbacks | |
988 **/ | |
989 typedef OrthancPluginErrorCode (*OrthancPluginRestCallback) ( | |
990 OrthancPluginRestOutput* output, | |
991 const char* url, | |
992 const OrthancPluginHttpRequest* request); | |
993 | |
994 | |
995 | |
996 /** | |
997 * @brief Signature of a callback function that is triggered when Orthanc receives a DICOM instance. | |
998 * @ingroup Callbacks | |
999 **/ | |
1000 typedef OrthancPluginErrorCode (*OrthancPluginOnStoredInstanceCallback) ( | |
1001 OrthancPluginDicomInstance* instance, | |
1002 const char* instanceId); | |
1003 | |
1004 | |
1005 | |
1006 /** | |
1007 * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource. | |
1008 * @ingroup Callbacks | |
1009 **/ | |
1010 typedef OrthancPluginErrorCode (*OrthancPluginOnChangeCallback) ( | |
1011 OrthancPluginChangeType changeType, | |
1012 OrthancPluginResourceType resourceType, | |
1013 const char* resourceId); | |
1014 | |
1015 | |
1016 | |
1017 /** | |
1018 * @brief Signature of a callback function to decode a DICOM instance as an image. | |
1019 * @ingroup Callbacks | |
1020 **/ | |
1021 typedef OrthancPluginErrorCode (*OrthancPluginDecodeImageCallback) ( | |
1022 OrthancPluginImage** target, | |
1023 const void* dicom, | |
1024 const uint32_t size, | |
1025 uint32_t frameIndex); | |
1026 | |
1027 | |
1028 | |
1029 /** | |
1030 * @brief Signature of a function to free dynamic memory. | |
1031 **/ | |
1032 typedef void (*OrthancPluginFree) (void* buffer); | |
1033 | |
1034 | |
1035 | |
1036 /** | |
1037 * @brief Callback for writing to the storage area. | |
1038 * | |
1039 * Signature of a callback function that is triggered when Orthanc writes a file to the storage area. | |
1040 * | |
1041 * @param uuid The UUID of the file. | |
1042 * @param content The content of the file. | |
1043 * @param size The size of the file. | |
1044 * @param type The content type corresponding to this file. | |
1045 * @return 0 if success, other value if error. | |
1046 * @ingroup Callbacks | |
1047 **/ | |
1048 typedef OrthancPluginErrorCode (*OrthancPluginStorageCreate) ( | |
1049 const char* uuid, | |
1050 const void* content, | |
1051 int64_t size, | |
1052 OrthancPluginContentType type); | |
1053 | |
1054 | |
1055 | |
1056 /** | |
1057 * @brief Callback for reading from the storage area. | |
1058 * | |
1059 * Signature of a callback function that is triggered when Orthanc reads a file from the storage area. | |
1060 * | |
1061 * @param content The content of the file (output). | |
1062 * @param size The size of the file (output). | |
1063 * @param uuid The UUID of the file of interest. | |
1064 * @param type The content type corresponding to this file. | |
1065 * @return 0 if success, other value if error. | |
1066 * @ingroup Callbacks | |
1067 **/ | |
1068 typedef OrthancPluginErrorCode (*OrthancPluginStorageRead) ( | |
1069 void** content, | |
1070 int64_t* size, | |
1071 const char* uuid, | |
1072 OrthancPluginContentType type); | |
1073 | |
1074 | |
1075 | |
1076 /** | |
1077 * @brief Callback for removing a file from the storage area. | |
1078 * | |
1079 * Signature of a callback function that is triggered when Orthanc deletes a file from the storage area. | |
1080 * | |
1081 * @param uuid The UUID of the file to be removed. | |
1082 * @param type The content type corresponding to this file. | |
1083 * @return 0 if success, other value if error. | |
1084 * @ingroup Callbacks | |
1085 **/ | |
1086 typedef OrthancPluginErrorCode (*OrthancPluginStorageRemove) ( | |
1087 const char* uuid, | |
1088 OrthancPluginContentType type); | |
1089 | |
1090 | |
1091 | |
1092 /** | |
1093 * @brief Callback to handle the C-Find SCP requests for worklists. | |
1094 * | |
1095 * Signature of a callback function that is triggered when Orthanc | |
1096 * receives a C-Find SCP request against modality worklists. | |
1097 * | |
1098 * @param answers The target structure where answers must be stored. | |
1099 * @param query The worklist query. | |
1100 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates. | |
1101 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request. | |
1102 * @return 0 if success, other value if error. | |
1103 * @ingroup DicomCallbacks | |
1104 **/ | |
1105 typedef OrthancPluginErrorCode (*OrthancPluginWorklistCallback) ( | |
1106 OrthancPluginWorklistAnswers* answers, | |
1107 const OrthancPluginWorklistQuery* query, | |
1108 const char* issuerAet, | |
1109 const char* calledAet); | |
1110 | |
1111 | |
1112 | |
1113 /** | |
1114 * @brief Callback to filter incoming HTTP requests received by Orthanc. | |
1115 * | |
1116 * Signature of a callback function that is triggered whenever | |
1117 * Orthanc receives an HTTP/REST request, and that answers whether | |
1118 * this request should be allowed. If the callback returns "0" | |
1119 * ("false"), the server answers with HTTP status code 403 | |
1120 * (Forbidden). | |
1121 * | |
1122 * @param method The HTTP method used by the request. | |
1123 * @param uri The URI of interest. | |
1124 * @param ip The IP address of the HTTP client. | |
1125 * @param headersCount The number of HTTP headers. | |
1126 * @param headersKeys The keys of the HTTP headers (always converted to low-case). | |
1127 * @param headersValues The values of the HTTP headers. | |
1128 * @return 0 if forbidden access, 1 if allowed access, -1 if error. | |
1129 * @ingroup Callback | |
1130 * @deprecated Please instead use OrthancPluginIncomingHttpRequestFilter2() | |
1131 **/ | |
1132 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter) ( | |
1133 OrthancPluginHttpMethod method, | |
1134 const char* uri, | |
1135 const char* ip, | |
1136 uint32_t headersCount, | |
1137 const char* const* headersKeys, | |
1138 const char* const* headersValues); | |
1139 | |
1140 | |
1141 | |
1142 /** | |
1143 * @brief Callback to filter incoming HTTP requests received by Orthanc. | |
1144 * | |
1145 * Signature of a callback function that is triggered whenever | |
1146 * Orthanc receives an HTTP/REST request, and that answers whether | |
1147 * this request should be allowed. If the callback returns "0" | |
1148 * ("false"), the server answers with HTTP status code 403 | |
1149 * (Forbidden). | |
1150 * | |
1151 * @param method The HTTP method used by the request. | |
1152 * @param uri The URI of interest. | |
1153 * @param ip The IP address of the HTTP client. | |
1154 * @param headersCount The number of HTTP headers. | |
1155 * @param headersKeys The keys of the HTTP headers (always converted to low-case). | |
1156 * @param headersValues The values of the HTTP headers. | |
1157 * @param getArgumentsCount The number of GET arguments (only for the GET HTTP method). | |
1158 * @param getArgumentsKeys The keys of the GET arguments (only for the GET HTTP method). | |
1159 * @param getArgumentsValues The values of the GET arguments (only for the GET HTTP method). | |
1160 * @return 0 if forbidden access, 1 if allowed access, -1 if error. | |
1161 * @ingroup Callback | |
1162 **/ | |
1163 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter2) ( | |
1164 OrthancPluginHttpMethod method, | |
1165 const char* uri, | |
1166 const char* ip, | |
1167 uint32_t headersCount, | |
1168 const char* const* headersKeys, | |
1169 const char* const* headersValues, | |
1170 uint32_t getArgumentsCount, | |
1171 const char* const* getArgumentsKeys, | |
1172 const char* const* getArgumentsValues); | |
1173 | |
1174 | |
1175 | |
1176 /** | |
1177 * @brief Callback to handle incoming C-Find SCP requests. | |
1178 * | |
1179 * Signature of a callback function that is triggered whenever | |
1180 * Orthanc receives a C-Find SCP request not concerning modality | |
1181 * worklists. | |
1182 * | |
1183 * @param answers The target structure where answers must be stored. | |
1184 * @param query The worklist query. | |
1185 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates. | |
1186 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request. | |
1187 * @return 0 if success, other value if error. | |
1188 * @ingroup DicomCallbacks | |
1189 **/ | |
1190 typedef OrthancPluginErrorCode (*OrthancPluginFindCallback) ( | |
1191 OrthancPluginFindAnswers* answers, | |
1192 const OrthancPluginFindQuery* query, | |
1193 const char* issuerAet, | |
1194 const char* calledAet); | |
1195 | |
1196 | |
1197 | |
1198 /** | |
1199 * @brief Callback to handle incoming C-Move SCP requests. | |
1200 * | |
1201 * Signature of a callback function that is triggered whenever | |
1202 * Orthanc receives a C-Move SCP request. The callback receives the | |
1203 * type of the resource of interest (study, series, instance...) | |
1204 * together with the DICOM tags containing its identifiers. In turn, | |
1205 * the plugin must create a driver object that will be responsible | |
1206 * for driving the successive move suboperations. | |
1207 * | |
1208 * @param resourceType The type of the resource of interest. Note | |
1209 * that this might be set to ResourceType_None if the | |
1210 * QueryRetrieveLevel (0008,0052) tag was not provided by the | |
1211 * issuer (i.e. the originator modality). | |
1212 * @param patientId Content of the PatientID (0x0010, 0x0020) tag of the resource of interest. Might be NULL. | |
1213 * @param accessionNumber Content of the AccessionNumber (0x0008, 0x0050) tag. Might be NULL. | |
1214 * @param studyInstanceUid Content of the StudyInstanceUID (0x0020, 0x000d) tag. Might be NULL. | |
1215 * @param seriesInstanceUid Content of the SeriesInstanceUID (0x0020, 0x000e) tag. Might be NULL. | |
1216 * @param sopInstanceUid Content of the SOPInstanceUID (0x0008, 0x0018) tag. Might be NULL. | |
1217 * @param originatorAet The Application Entity Title (AET) of the | |
1218 * modality from which the request originates. | |
1219 * @param sourceAet The Application Entity Title (AET) of the | |
1220 * modality that should send its DICOM files to another modality. | |
1221 * @param targetAet The Application Entity Title (AET) of the | |
1222 * modality that should receive the DICOM files. | |
1223 * @param originatorId The Message ID issued by the originator modality, | |
1224 * as found in tag (0000,0110) of the DICOM query emitted by the issuer. | |
1225 * | |
1226 * @return The NULL value if the plugin cannot deal with this query, | |
1227 * or a pointer to the driver object that is responsible for | |
1228 * handling the successive move suboperations. | |
1229 * | |
1230 * @note If targetAet equals sourceAet, this is actually a query/retrieve operation. | |
1231 * @ingroup DicomCallbacks | |
1232 **/ | |
1233 typedef void* (*OrthancPluginMoveCallback) ( | |
1234 OrthancPluginResourceType resourceType, | |
1235 const char* patientId, | |
1236 const char* accessionNumber, | |
1237 const char* studyInstanceUid, | |
1238 const char* seriesInstanceUid, | |
1239 const char* sopInstanceUid, | |
1240 const char* originatorAet, | |
1241 const char* sourceAet, | |
1242 const char* targetAet, | |
1243 uint16_t originatorId); | |
1244 | |
1245 | |
1246 /** | |
1247 * @brief Callback to read the size of a C-Move driver. | |
1248 * | |
1249 * Signature of a callback function that returns the number of | |
1250 * C-Move suboperations that are to be achieved by the given C-Move | |
1251 * driver. This driver is the return value of a previous call to the | |
1252 * OrthancPluginMoveCallback() callback. | |
1253 * | |
1254 * @param moveDriver The C-Move driver of interest. | |
1255 * @return The number of suboperations. | |
1256 * @ingroup DicomCallbacks | |
1257 **/ | |
1258 typedef uint32_t (*OrthancPluginGetMoveSize) (void* moveDriver); | |
1259 | |
1260 | |
1261 /** | |
1262 * @brief Callback to apply one C-Move suboperation. | |
1263 * | |
1264 * Signature of a callback function that applies the next C-Move | |
1265 * suboperation that os to be achieved by the given C-Move | |
1266 * driver. This driver is the return value of a previous call to the | |
1267 * OrthancPluginMoveCallback() callback. | |
1268 * | |
1269 * @param moveDriver The C-Move driver of interest. | |
1270 * @return 0 if success, or the error code if failure. | |
1271 * @ingroup DicomCallbacks | |
1272 **/ | |
1273 typedef OrthancPluginErrorCode (*OrthancPluginApplyMove) (void* moveDriver); | |
1274 | |
1275 | |
1276 /** | |
1277 * @brief Callback to free one C-Move driver. | |
1278 * | |
1279 * Signature of a callback function that releases the resources | |
1280 * allocated by the given C-Move driver. This driver is the return | |
1281 * value of a previous call to the OrthancPluginMoveCallback() | |
1282 * callback. | |
1283 * | |
1284 * @param moveDriver The C-Move driver of interest. | |
1285 * @ingroup DicomCallbacks | |
1286 **/ | |
1287 typedef void (*OrthancPluginFreeMove) (void* moveDriver); | |
1288 | |
1289 | |
1290 /** | |
1291 * @brief Callback to finalize one custom job. | |
1292 * | |
1293 * Signature of a callback function that releases all the resources | |
1294 * allocated by the given job. This job is the argument provided to | |
1295 * OrthancPluginCreateJob(). | |
1296 * | |
1297 * @param job The job of interest. | |
1298 * @ingroup Toolbox | |
1299 **/ | |
1300 typedef void (*OrthancPluginJobFinalize) (void* job); | |
1301 | |
1302 | |
1303 /** | |
1304 * @brief Callback to check the progress of one custom job. | |
1305 * | |
1306 * Signature of a callback function that returns the progress of the | |
1307 * job. | |
1308 * | |
1309 * @param job The job of interest. | |
1310 * @return The progress, as a floating-point number ranging from 0 to 1. | |
1311 * @ingroup Toolbox | |
1312 **/ | |
1313 typedef float (*OrthancPluginJobGetProgress) (void* job); | |
1314 | |
1315 | |
1316 /** | |
1317 * @brief Callback to retrieve the content of one custom job. | |
1318 * | |
1319 * Signature of a callback function that returns human-readable | |
1320 * statistics about the job. This statistics must be formatted as a | |
1321 * JSON object. This information is notably displayed in the "Jobs" | |
1322 * tab of "Orthanc Explorer". | |
1323 * | |
1324 * @param job The job of interest. | |
1325 * @return The statistics, as a JSON object encoded as a string. | |
1326 * @ingroup Toolbox | |
1327 **/ | |
1328 typedef const char* (*OrthancPluginJobGetContent) (void* job); | |
1329 | |
1330 | |
1331 /** | |
1332 * @brief Callback to serialize one custom job. | |
1333 * | |
1334 * Signature of a callback function that returns a serialized | |
1335 * version of the job, formatted as a JSON object. This | |
1336 * serialization is stored in the Orthanc database, and is used to | |
1337 * reload the job on the restart of Orthanc. The "unserialization" | |
1338 * callback (with OrthancPluginJobsUnserializer signature) will | |
1339 * receive this serialized object. | |
1340 * | |
1341 * @param job The job of interest. | |
1342 * @return The serialized job, as a JSON object encoded as a string. | |
1343 * @see OrthancPluginRegisterJobsUnserializer() | |
1344 * @ingroup Toolbox | |
1345 **/ | |
1346 typedef const char* (*OrthancPluginJobGetSerialized) (void* job); | |
1347 | |
1348 | |
1349 /** | |
1350 * @brief Callback to execute one step of a custom job. | |
1351 * | |
1352 * Signature of a callback function that executes one step in the | |
1353 * job. The jobs engine of Orthanc will make successive calls to | |
1354 * this method, as long as it returns | |
1355 * OrthancPluginJobStepStatus_Continue. | |
1356 * | |
1357 * @param job The job of interest. | |
1358 * @return The status of execution. | |
1359 * @ingroup Toolbox | |
1360 **/ | |
1361 typedef OrthancPluginJobStepStatus (*OrthancPluginJobStep) (void* job); | |
1362 | |
1363 | |
1364 /** | |
1365 * @brief Callback executed once one custom job leaves the "running" state. | |
1366 * | |
1367 * Signature of a callback function that is invoked once a job | |
1368 * leaves the "running" state. This can happen if the previous call | |
1369 * to OrthancPluginJobStep has failed/succeeded, if the host Orthanc | |
1370 * server is being stopped, or if the user manually tags the job as | |
1371 * paused/canceled. This callback allows the plugin to free | |
1372 * resources allocated for running this custom job (e.g. to stop | |
1373 * threads, or to remove temporary files). | |
1374 * | |
1375 * Note that handling pauses might involves a specific treatment | |
1376 * (such a stopping threads, but keeping temporary files on the | |
1377 * disk). This "paused" situation can be checked by looking at the | |
1378 * "reason" parameter. | |
1379 * | |
1380 * @param job The job of interest. | |
1381 * @param reason The reason for leaving the "running" state. | |
1382 * @return 0 if success, or the error code if failure. | |
1383 * @ingroup Toolbox | |
1384 **/ | |
1385 typedef OrthancPluginErrorCode (*OrthancPluginJobStop) (void* job, | |
1386 OrthancPluginJobStopReason reason); | |
1387 | |
1388 | |
1389 /** | |
1390 * @brief Callback executed once one stopped custom job is started again. | |
1391 * | |
1392 * Signature of a callback function that is invoked once a job | |
1393 * leaves the "failure/canceled" state, to be started again. This | |
1394 * function will typically reset the progress to zero. Note that | |
1395 * before being actually executed, the job would first be tagged as | |
1396 * "pending" in the Orthanc jobs engine. | |
1397 * | |
1398 * @param job The job of interest. | |
1399 * @return 0 if success, or the error code if failure. | |
1400 * @ingroup Toolbox | |
1401 **/ | |
1402 typedef OrthancPluginErrorCode (*OrthancPluginJobReset) (void* job); | |
1403 | |
1404 | |
1405 /** | |
1406 * @brief Callback executed to unserialized a custom job. | |
1407 * | |
1408 * Signature of a callback function that unserializes a job that was | |
1409 * saved in the Orthanc database. | |
1410 * | |
1411 * @param jobType The type of the job, as provided to OrthancPluginCreateJob(). | |
1412 * @param serialized The serialization of the job, as provided by OrthancPluginJobGetSerialized. | |
1413 * @return The unserialized job (as created by OrthancPluginCreateJob()), or NULL | |
1414 * if this unserializer cannot handle this job type. | |
1415 * @see OrthancPluginRegisterJobsUnserializer() | |
1416 * @ingroup Callbacks | |
1417 **/ | |
1418 typedef OrthancPluginJob* (*OrthancPluginJobsUnserializer) (const char* jobType, | |
1419 const char* serialized); | |
1420 | |
1421 | |
1422 | |
1423 /** | |
1424 * @brief Data structure that contains information about the Orthanc core. | |
1425 **/ | |
1426 typedef struct _OrthancPluginContext_t | |
1427 { | |
1428 void* pluginsManager; | |
1429 const char* orthancVersion; | |
1430 OrthancPluginFree Free; | |
1431 OrthancPluginErrorCode (*InvokeService) (struct _OrthancPluginContext_t* context, | |
1432 _OrthancPluginService service, | |
1433 const void* params); | |
1434 } OrthancPluginContext; | |
1435 | |
1436 | |
1437 | |
1438 /** | |
1439 * @brief An entry in the dictionary of DICOM tags. | |
1440 **/ | |
1441 typedef struct | |
1442 { | |
1443 uint16_t group; /*!< The group of the tag */ | |
1444 uint16_t element; /*!< The element of the tag */ | |
1445 OrthancPluginValueRepresentation vr; /*!< The value representation of the tag */ | |
1446 uint32_t minMultiplicity; /*!< The minimum multiplicity of the tag */ | |
1447 uint32_t maxMultiplicity; /*!< The maximum multiplicity of the tag (0 means arbitrary) */ | |
1448 } OrthancPluginDictionaryEntry; | |
1449 | |
1450 | |
1451 | |
1452 /** | |
1453 * @brief Free a string. | |
1454 * | |
1455 * Free a string that was allocated by the core system of Orthanc. | |
1456 * | |
1457 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1458 * @param str The string to be freed. | |
1459 **/ | |
1460 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString( | |
1461 OrthancPluginContext* context, | |
1462 char* str) | |
1463 { | |
1464 if (str != NULL) | |
1465 { | |
1466 context->Free(str); | |
1467 } | |
1468 } | |
1469 | |
1470 | |
1471 /** | |
1472 * @brief Check that the version of the hosting Orthanc is above a given version. | |
1473 * | |
1474 * This function checks whether the version of the Orthanc server | |
1475 * running this plugin, is above the given version. Contrarily to | |
1476 * OrthancPluginCheckVersion(), it is up to the developer of the | |
1477 * plugin to make sure that all the Orthanc SDK services called by | |
1478 * the plugin are actually implemented in the given version of | |
1479 * Orthanc. | |
1480 * | |
1481 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1482 * @param expectedMajor Expected major version. | |
1483 * @param expectedMinor Expected minor version. | |
1484 * @param expectedRevision Expected revision. | |
1485 * @return 1 if and only if the versions are compatible. If the | |
1486 * result is 0, the initialization of the plugin should fail. | |
1487 * @see OrthancPluginCheckVersion | |
1488 * @ingroup Callbacks | |
1489 **/ | |
1490 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersionAdvanced( | |
1491 OrthancPluginContext* context, | |
1492 int expectedMajor, | |
1493 int expectedMinor, | |
1494 int expectedRevision) | |
1495 { | |
1496 int major, minor, revision; | |
1497 | |
1498 if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) || | |
1499 sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) || | |
1500 sizeof(int32_t) != sizeof(_OrthancPluginService) || | |
1501 sizeof(int32_t) != sizeof(_OrthancPluginProperty) || | |
1502 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) || | |
1503 sizeof(int32_t) != sizeof(OrthancPluginContentType) || | |
1504 sizeof(int32_t) != sizeof(OrthancPluginResourceType) || | |
1505 sizeof(int32_t) != sizeof(OrthancPluginChangeType) || | |
1506 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || | |
1507 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) || | |
1508 sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) || | |
1509 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) || | |
1510 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) || | |
1511 sizeof(int32_t) != sizeof(OrthancPluginCreateDicomFlags) || | |
1512 sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) || | |
1513 sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) || | |
1514 sizeof(int32_t) != sizeof(OrthancPluginJobStepStatus)) | |
1515 { | |
1516 /* Mismatch in the size of the enumerations */ | |
1517 return 0; | |
1518 } | |
1519 | |
1520 /* Assume compatibility with the mainline */ | |
1521 if (!strcmp(context->orthancVersion, "mainline")) | |
1522 { | |
1523 return 1; | |
1524 } | |
1525 | |
1526 /* Parse the version of the Orthanc core */ | |
1527 if ( | |
1528 #ifdef _MSC_VER | |
1529 sscanf_s | |
1530 #else | |
1531 sscanf | |
1532 #endif | |
1533 (context->orthancVersion, "%4d.%4d.%4d", &major, &minor, &revision) != 3) | |
1534 { | |
1535 return 0; | |
1536 } | |
1537 | |
1538 /* Check the major number of the version */ | |
1539 | |
1540 if (major > expectedMajor) | |
1541 { | |
1542 return 1; | |
1543 } | |
1544 | |
1545 if (major < expectedMajor) | |
1546 { | |
1547 return 0; | |
1548 } | |
1549 | |
1550 /* Check the minor number of the version */ | |
1551 | |
1552 if (minor > expectedMinor) | |
1553 { | |
1554 return 1; | |
1555 } | |
1556 | |
1557 if (minor < expectedMinor) | |
1558 { | |
1559 return 0; | |
1560 } | |
1561 | |
1562 /* Check the revision number of the version */ | |
1563 | |
1564 if (revision >= expectedRevision) | |
1565 { | |
1566 return 1; | |
1567 } | |
1568 else | |
1569 { | |
1570 return 0; | |
1571 } | |
1572 } | |
1573 | |
1574 | |
1575 /** | |
1576 * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc. | |
1577 * | |
1578 * This function checks whether the version of the Orthanc server | |
1579 * running this plugin, is above the version of the current Orthanc | |
1580 * SDK header. This guarantees that the plugin is compatible with | |
1581 * the hosting Orthanc (i.e. it will not call unavailable services). | |
1582 * The result of this function should always be checked in the | |
1583 * OrthancPluginInitialize() entry point of the plugin. | |
1584 * | |
1585 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1586 * @return 1 if and only if the versions are compatible. If the | |
1587 * result is 0, the initialization of the plugin should fail. | |
1588 * @see OrthancPluginCheckVersionAdvanced | |
1589 * @ingroup Callbacks | |
1590 **/ | |
1591 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion( | |
1592 OrthancPluginContext* context) | |
1593 { | |
1594 return OrthancPluginCheckVersionAdvanced( | |
1595 context, | |
1596 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | |
1597 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
1598 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
1599 } | |
1600 | |
1601 | |
1602 /** | |
1603 * @brief Free a memory buffer. | |
1604 * | |
1605 * Free a memory buffer that was allocated by the core system of Orthanc. | |
1606 * | |
1607 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1608 * @param buffer The memory buffer to release. | |
1609 **/ | |
1610 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer( | |
1611 OrthancPluginContext* context, | |
1612 OrthancPluginMemoryBuffer* buffer) | |
1613 { | |
1614 context->Free(buffer->data); | |
1615 } | |
1616 | |
1617 | |
1618 /** | |
1619 * @brief Log an error. | |
1620 * | |
1621 * Log an error message using the Orthanc logging system. | |
1622 * | |
1623 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1624 * @param message The message to be logged. | |
1625 **/ | |
1626 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError( | |
1627 OrthancPluginContext* context, | |
1628 const char* message) | |
1629 { | |
1630 context->InvokeService(context, _OrthancPluginService_LogError, message); | |
1631 } | |
1632 | |
1633 | |
1634 /** | |
1635 * @brief Log a warning. | |
1636 * | |
1637 * Log a warning message using the Orthanc logging system. | |
1638 * | |
1639 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1640 * @param message The message to be logged. | |
1641 **/ | |
1642 ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning( | |
1643 OrthancPluginContext* context, | |
1644 const char* message) | |
1645 { | |
1646 context->InvokeService(context, _OrthancPluginService_LogWarning, message); | |
1647 } | |
1648 | |
1649 | |
1650 /** | |
1651 * @brief Log an information. | |
1652 * | |
1653 * Log an information message using the Orthanc logging system. | |
1654 * | |
1655 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1656 * @param message The message to be logged. | |
1657 **/ | |
1658 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo( | |
1659 OrthancPluginContext* context, | |
1660 const char* message) | |
1661 { | |
1662 context->InvokeService(context, _OrthancPluginService_LogInfo, message); | |
1663 } | |
1664 | |
1665 | |
1666 | |
1667 typedef struct | |
1668 { | |
1669 const char* pathRegularExpression; | |
1670 OrthancPluginRestCallback callback; | |
1671 } _OrthancPluginRestCallback; | |
1672 | |
1673 /** | |
1674 * @brief Register a REST callback. | |
1675 * | |
1676 * This function registers a REST callback against a regular | |
1677 * expression for a URI. This function must be called during the | |
1678 * initialization of the plugin, i.e. inside the | |
1679 * OrthancPluginInitialize() public function. | |
1680 * | |
1681 * Each REST callback is guaranteed to run in mutual exclusion. | |
1682 * | |
1683 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1684 * @param pathRegularExpression Regular expression for the URI. May contain groups. | |
1685 * @param callback The callback function to handle the REST call. | |
1686 * @see OrthancPluginRegisterRestCallbackNoLock() | |
1687 * @ingroup Callbacks | |
1688 **/ | |
1689 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback( | |
1690 OrthancPluginContext* context, | |
1691 const char* pathRegularExpression, | |
1692 OrthancPluginRestCallback callback) | |
1693 { | |
1694 _OrthancPluginRestCallback params; | |
1695 params.pathRegularExpression = pathRegularExpression; | |
1696 params.callback = callback; | |
1697 context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, ¶ms); | |
1698 } | |
1699 | |
1700 | |
1701 | |
1702 /** | |
1703 * @brief Register a REST callback, without locking. | |
1704 * | |
1705 * This function registers a REST callback against a regular | |
1706 * expression for a URI. This function must be called during the | |
1707 * initialization of the plugin, i.e. inside the | |
1708 * OrthancPluginInitialize() public function. | |
1709 * | |
1710 * Contrarily to OrthancPluginRegisterRestCallback(), the callback | |
1711 * will NOT be invoked in mutual exclusion. This can be useful for | |
1712 * high-performance plugins that must handle concurrent requests | |
1713 * (Orthanc uses a pool of threads, one thread being assigned to | |
1714 * each incoming HTTP request). Of course, it is up to the plugin to | |
1715 * implement the required locking mechanisms. | |
1716 * | |
1717 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1718 * @param pathRegularExpression Regular expression for the URI. May contain groups. | |
1719 * @param callback The callback function to handle the REST call. | |
1720 * @see OrthancPluginRegisterRestCallback() | |
1721 * @ingroup Callbacks | |
1722 **/ | |
1723 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallbackNoLock( | |
1724 OrthancPluginContext* context, | |
1725 const char* pathRegularExpression, | |
1726 OrthancPluginRestCallback callback) | |
1727 { | |
1728 _OrthancPluginRestCallback params; | |
1729 params.pathRegularExpression = pathRegularExpression; | |
1730 params.callback = callback; | |
1731 context->InvokeService(context, _OrthancPluginService_RegisterRestCallbackNoLock, ¶ms); | |
1732 } | |
1733 | |
1734 | |
1735 | |
1736 typedef struct | |
1737 { | |
1738 OrthancPluginOnStoredInstanceCallback callback; | |
1739 } _OrthancPluginOnStoredInstanceCallback; | |
1740 | |
1741 /** | |
1742 * @brief Register a callback for received instances. | |
1743 * | |
1744 * This function registers a callback function that is called | |
1745 * whenever a new DICOM instance is stored into the Orthanc core. | |
1746 * | |
1747 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1748 * @param callback The callback function. | |
1749 * @ingroup Callbacks | |
1750 **/ | |
1751 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback( | |
1752 OrthancPluginContext* context, | |
1753 OrthancPluginOnStoredInstanceCallback callback) | |
1754 { | |
1755 _OrthancPluginOnStoredInstanceCallback params; | |
1756 params.callback = callback; | |
1757 | |
1758 context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, ¶ms); | |
1759 } | |
1760 | |
1761 | |
1762 | |
1763 typedef struct | |
1764 { | |
1765 OrthancPluginRestOutput* output; | |
1766 const char* answer; | |
1767 uint32_t answerSize; | |
1768 const char* mimeType; | |
1769 } _OrthancPluginAnswerBuffer; | |
1770 | |
1771 /** | |
1772 * @brief Answer to a REST request. | |
1773 * | |
1774 * This function answers to a REST request with the content of a memory buffer. | |
1775 * | |
1776 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1777 * @param output The HTTP connection to the client application. | |
1778 * @param answer Pointer to the memory buffer containing the answer. | |
1779 * @param answerSize Number of bytes of the answer. | |
1780 * @param mimeType The MIME type of the answer. | |
1781 * @ingroup REST | |
1782 **/ | |
1783 ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer( | |
1784 OrthancPluginContext* context, | |
1785 OrthancPluginRestOutput* output, | |
1786 const char* answer, | |
1787 uint32_t answerSize, | |
1788 const char* mimeType) | |
1789 { | |
1790 _OrthancPluginAnswerBuffer params; | |
1791 params.output = output; | |
1792 params.answer = answer; | |
1793 params.answerSize = answerSize; | |
1794 params.mimeType = mimeType; | |
1795 context->InvokeService(context, _OrthancPluginService_AnswerBuffer, ¶ms); | |
1796 } | |
1797 | |
1798 | |
1799 typedef struct | |
1800 { | |
1801 OrthancPluginRestOutput* output; | |
1802 OrthancPluginPixelFormat format; | |
1803 uint32_t width; | |
1804 uint32_t height; | |
1805 uint32_t pitch; | |
1806 const void* buffer; | |
1807 } _OrthancPluginCompressAndAnswerPngImage; | |
1808 | |
1809 typedef struct | |
1810 { | |
1811 OrthancPluginRestOutput* output; | |
1812 OrthancPluginImageFormat imageFormat; | |
1813 OrthancPluginPixelFormat pixelFormat; | |
1814 uint32_t width; | |
1815 uint32_t height; | |
1816 uint32_t pitch; | |
1817 const void* buffer; | |
1818 uint8_t quality; | |
1819 } _OrthancPluginCompressAndAnswerImage; | |
1820 | |
1821 | |
1822 /** | |
1823 * @brief Answer to a REST request with a PNG image. | |
1824 * | |
1825 * This function answers to a REST request with a PNG image. The | |
1826 * parameters of this function describe a memory buffer that | |
1827 * contains an uncompressed image. The image will be automatically compressed | |
1828 * as a PNG image by the core system of Orthanc. | |
1829 * | |
1830 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1831 * @param output The HTTP connection to the client application. | |
1832 * @param format The memory layout of the uncompressed image. | |
1833 * @param width The width of the image. | |
1834 * @param height The height of the image. | |
1835 * @param pitch The pitch of the image (i.e. the number of bytes | |
1836 * between 2 successive lines of the image in the memory buffer). | |
1837 * @param buffer The memory buffer containing the uncompressed image. | |
1838 * @ingroup REST | |
1839 **/ | |
1840 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage( | |
1841 OrthancPluginContext* context, | |
1842 OrthancPluginRestOutput* output, | |
1843 OrthancPluginPixelFormat format, | |
1844 uint32_t width, | |
1845 uint32_t height, | |
1846 uint32_t pitch, | |
1847 const void* buffer) | |
1848 { | |
1849 _OrthancPluginCompressAndAnswerImage params; | |
1850 params.output = output; | |
1851 params.imageFormat = OrthancPluginImageFormat_Png; | |
1852 params.pixelFormat = format; | |
1853 params.width = width; | |
1854 params.height = height; | |
1855 params.pitch = pitch; | |
1856 params.buffer = buffer; | |
1857 params.quality = 0; /* No quality for PNG */ | |
1858 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, ¶ms); | |
1859 } | |
1860 | |
1861 | |
1862 | |
1863 typedef struct | |
1864 { | |
1865 OrthancPluginMemoryBuffer* target; | |
1866 const char* instanceId; | |
1867 } _OrthancPluginGetDicomForInstance; | |
1868 | |
1869 /** | |
1870 * @brief Retrieve a DICOM instance using its Orthanc identifier. | |
1871 * | |
1872 * Retrieve a DICOM instance using its Orthanc identifier. The DICOM | |
1873 * file is stored into a newly allocated memory buffer. | |
1874 * | |
1875 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1876 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
1877 * @param instanceId The Orthanc identifier of the DICOM instance of interest. | |
1878 * @return 0 if success, or the error code if failure. | |
1879 * @ingroup Orthanc | |
1880 **/ | |
1881 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetDicomForInstance( | |
1882 OrthancPluginContext* context, | |
1883 OrthancPluginMemoryBuffer* target, | |
1884 const char* instanceId) | |
1885 { | |
1886 _OrthancPluginGetDicomForInstance params; | |
1887 params.target = target; | |
1888 params.instanceId = instanceId; | |
1889 return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, ¶ms); | |
1890 } | |
1891 | |
1892 | |
1893 | |
1894 typedef struct | |
1895 { | |
1896 OrthancPluginMemoryBuffer* target; | |
1897 const char* uri; | |
1898 } _OrthancPluginRestApiGet; | |
1899 | |
1900 /** | |
1901 * @brief Make a GET call to the built-in Orthanc REST API. | |
1902 * | |
1903 * Make a GET call to the built-in Orthanc REST API. The result to | |
1904 * the query is stored into a newly allocated memory buffer. | |
1905 * | |
1906 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1907 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
1908 * @param uri The URI in the built-in Orthanc API. | |
1909 * @return 0 if success, or the error code if failure. | |
1910 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
1911 * @see OrthancPluginRestApiGetAfterPlugins | |
1912 * @ingroup Orthanc | |
1913 **/ | |
1914 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet( | |
1915 OrthancPluginContext* context, | |
1916 OrthancPluginMemoryBuffer* target, | |
1917 const char* uri) | |
1918 { | |
1919 _OrthancPluginRestApiGet params; | |
1920 params.target = target; | |
1921 params.uri = uri; | |
1922 return context->InvokeService(context, _OrthancPluginService_RestApiGet, ¶ms); | |
1923 } | |
1924 | |
1925 | |
1926 | |
1927 /** | |
1928 * @brief Make a GET call to the REST API, as tainted by the plugins. | |
1929 * | |
1930 * Make a GET call to the Orthanc REST API, after all the plugins | |
1931 * are applied. In other words, if some plugin overrides or adds the | |
1932 * called URI to the built-in Orthanc REST API, this call will | |
1933 * return the result provided by this plugin. The result to the | |
1934 * query is stored into a newly allocated memory buffer. | |
1935 * | |
1936 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1937 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
1938 * @param uri The URI in the built-in Orthanc API. | |
1939 * @return 0 if success, or the error code if failure. | |
1940 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
1941 * @see OrthancPluginRestApiGet | |
1942 * @ingroup Orthanc | |
1943 **/ | |
1944 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGetAfterPlugins( | |
1945 OrthancPluginContext* context, | |
1946 OrthancPluginMemoryBuffer* target, | |
1947 const char* uri) | |
1948 { | |
1949 _OrthancPluginRestApiGet params; | |
1950 params.target = target; | |
1951 params.uri = uri; | |
1952 return context->InvokeService(context, _OrthancPluginService_RestApiGetAfterPlugins, ¶ms); | |
1953 } | |
1954 | |
1955 | |
1956 | |
1957 typedef struct | |
1958 { | |
1959 OrthancPluginMemoryBuffer* target; | |
1960 const char* uri; | |
1961 const char* body; | |
1962 uint32_t bodySize; | |
1963 } _OrthancPluginRestApiPostPut; | |
1964 | |
1965 /** | |
1966 * @brief Make a POST call to the built-in Orthanc REST API. | |
1967 * | |
1968 * Make a POST call to the built-in Orthanc REST API. The result to | |
1969 * the query is stored into a newly allocated memory buffer. | |
1970 * | |
1971 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1972 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
1973 * @param uri The URI in the built-in Orthanc API. | |
1974 * @param body The body of the POST request. | |
1975 * @param bodySize The size of the body. | |
1976 * @return 0 if success, or the error code if failure. | |
1977 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
1978 * @see OrthancPluginRestApiPostAfterPlugins | |
1979 * @ingroup Orthanc | |
1980 **/ | |
1981 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPost( | |
1982 OrthancPluginContext* context, | |
1983 OrthancPluginMemoryBuffer* target, | |
1984 const char* uri, | |
1985 const char* body, | |
1986 uint32_t bodySize) | |
1987 { | |
1988 _OrthancPluginRestApiPostPut params; | |
1989 params.target = target; | |
1990 params.uri = uri; | |
1991 params.body = body; | |
1992 params.bodySize = bodySize; | |
1993 return context->InvokeService(context, _OrthancPluginService_RestApiPost, ¶ms); | |
1994 } | |
1995 | |
1996 | |
1997 /** | |
1998 * @brief Make a POST call to the REST API, as tainted by the plugins. | |
1999 * | |
2000 * Make a POST call to the Orthanc REST API, after all the plugins | |
2001 * are applied. In other words, if some plugin overrides or adds the | |
2002 * called URI to the built-in Orthanc REST API, this call will | |
2003 * return the result provided by this plugin. The result to the | |
2004 * query is stored into a newly allocated memory buffer. | |
2005 * | |
2006 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2007 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
2008 * @param uri The URI in the built-in Orthanc API. | |
2009 * @param body The body of the POST request. | |
2010 * @param bodySize The size of the body. | |
2011 * @return 0 if success, or the error code if failure. | |
2012 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2013 * @see OrthancPluginRestApiPost | |
2014 * @ingroup Orthanc | |
2015 **/ | |
2016 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPostAfterPlugins( | |
2017 OrthancPluginContext* context, | |
2018 OrthancPluginMemoryBuffer* target, | |
2019 const char* uri, | |
2020 const char* body, | |
2021 uint32_t bodySize) | |
2022 { | |
2023 _OrthancPluginRestApiPostPut params; | |
2024 params.target = target; | |
2025 params.uri = uri; | |
2026 params.body = body; | |
2027 params.bodySize = bodySize; | |
2028 return context->InvokeService(context, _OrthancPluginService_RestApiPostAfterPlugins, ¶ms); | |
2029 } | |
2030 | |
2031 | |
2032 | |
2033 /** | |
2034 * @brief Make a DELETE call to the built-in Orthanc REST API. | |
2035 * | |
2036 * Make a DELETE call to the built-in Orthanc REST API. | |
2037 * | |
2038 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2039 * @param uri The URI to delete in the built-in Orthanc API. | |
2040 * @return 0 if success, or the error code if failure. | |
2041 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2042 * @see OrthancPluginRestApiDeleteAfterPlugins | |
2043 * @ingroup Orthanc | |
2044 **/ | |
2045 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDelete( | |
2046 OrthancPluginContext* context, | |
2047 const char* uri) | |
2048 { | |
2049 return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri); | |
2050 } | |
2051 | |
2052 | |
2053 /** | |
2054 * @brief Make a DELETE call to the REST API, as tainted by the plugins. | |
2055 * | |
2056 * Make a DELETE call to the Orthanc REST API, after all the plugins | |
2057 * are applied. In other words, if some plugin overrides or adds the | |
2058 * called URI to the built-in Orthanc REST API, this call will | |
2059 * return the result provided by this plugin. | |
2060 * | |
2061 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2062 * @param uri The URI to delete in the built-in Orthanc API. | |
2063 * @return 0 if success, or the error code if failure. | |
2064 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2065 * @see OrthancPluginRestApiDelete | |
2066 * @ingroup Orthanc | |
2067 **/ | |
2068 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDeleteAfterPlugins( | |
2069 OrthancPluginContext* context, | |
2070 const char* uri) | |
2071 { | |
2072 return context->InvokeService(context, _OrthancPluginService_RestApiDeleteAfterPlugins, uri); | |
2073 } | |
2074 | |
2075 | |
2076 | |
2077 /** | |
2078 * @brief Make a PUT call to the built-in Orthanc REST API. | |
2079 * | |
2080 * Make a PUT call to the built-in Orthanc REST API. The result to | |
2081 * the query is stored into a newly allocated memory buffer. | |
2082 * | |
2083 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2084 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
2085 * @param uri The URI in the built-in Orthanc API. | |
2086 * @param body The body of the PUT request. | |
2087 * @param bodySize The size of the body. | |
2088 * @return 0 if success, or the error code if failure. | |
2089 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2090 * @see OrthancPluginRestApiPutAfterPlugins | |
2091 * @ingroup Orthanc | |
2092 **/ | |
2093 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPut( | |
2094 OrthancPluginContext* context, | |
2095 OrthancPluginMemoryBuffer* target, | |
2096 const char* uri, | |
2097 const char* body, | |
2098 uint32_t bodySize) | |
2099 { | |
2100 _OrthancPluginRestApiPostPut params; | |
2101 params.target = target; | |
2102 params.uri = uri; | |
2103 params.body = body; | |
2104 params.bodySize = bodySize; | |
2105 return context->InvokeService(context, _OrthancPluginService_RestApiPut, ¶ms); | |
2106 } | |
2107 | |
2108 | |
2109 | |
2110 /** | |
2111 * @brief Make a PUT call to the REST API, as tainted by the plugins. | |
2112 * | |
2113 * Make a PUT call to the Orthanc REST API, after all the plugins | |
2114 * are applied. In other words, if some plugin overrides or adds the | |
2115 * called URI to the built-in Orthanc REST API, this call will | |
2116 * return the result provided by this plugin. The result to the | |
2117 * query is stored into a newly allocated memory buffer. | |
2118 * | |
2119 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2120 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
2121 * @param uri The URI in the built-in Orthanc API. | |
2122 * @param body The body of the PUT request. | |
2123 * @param bodySize The size of the body. | |
2124 * @return 0 if success, or the error code if failure. | |
2125 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2126 * @see OrthancPluginRestApiPut | |
2127 * @ingroup Orthanc | |
2128 **/ | |
2129 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPutAfterPlugins( | |
2130 OrthancPluginContext* context, | |
2131 OrthancPluginMemoryBuffer* target, | |
2132 const char* uri, | |
2133 const char* body, | |
2134 uint32_t bodySize) | |
2135 { | |
2136 _OrthancPluginRestApiPostPut params; | |
2137 params.target = target; | |
2138 params.uri = uri; | |
2139 params.body = body; | |
2140 params.bodySize = bodySize; | |
2141 return context->InvokeService(context, _OrthancPluginService_RestApiPutAfterPlugins, ¶ms); | |
2142 } | |
2143 | |
2144 | |
2145 | |
2146 typedef struct | |
2147 { | |
2148 OrthancPluginRestOutput* output; | |
2149 const char* argument; | |
2150 } _OrthancPluginOutputPlusArgument; | |
2151 | |
2152 /** | |
2153 * @brief Redirect a REST request. | |
2154 * | |
2155 * This function answers to a REST request by redirecting the user | |
2156 * to another URI using HTTP status 301. | |
2157 * | |
2158 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2159 * @param output The HTTP connection to the client application. | |
2160 * @param redirection Where to redirect. | |
2161 * @ingroup REST | |
2162 **/ | |
2163 ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect( | |
2164 OrthancPluginContext* context, | |
2165 OrthancPluginRestOutput* output, | |
2166 const char* redirection) | |
2167 { | |
2168 _OrthancPluginOutputPlusArgument params; | |
2169 params.output = output; | |
2170 params.argument = redirection; | |
2171 context->InvokeService(context, _OrthancPluginService_Redirect, ¶ms); | |
2172 } | |
2173 | |
2174 | |
2175 | |
2176 typedef struct | |
2177 { | |
2178 char** result; | |
2179 const char* argument; | |
2180 } _OrthancPluginRetrieveDynamicString; | |
2181 | |
2182 /** | |
2183 * @brief Look for a patient. | |
2184 * | |
2185 * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020). | |
2186 * This function uses the database index to run as fast as possible (it does not loop | |
2187 * over all the stored patients). | |
2188 * | |
2189 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2190 * @param patientID The Patient ID of interest. | |
2191 * @return The NULL value if the patient is non-existent, or a string containing the | |
2192 * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString(). | |
2193 * @ingroup Orthanc | |
2194 **/ | |
2195 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient( | |
2196 OrthancPluginContext* context, | |
2197 const char* patientID) | |
2198 { | |
2199 char* result; | |
2200 | |
2201 _OrthancPluginRetrieveDynamicString params; | |
2202 params.result = &result; | |
2203 params.argument = patientID; | |
2204 | |
2205 if (context->InvokeService(context, _OrthancPluginService_LookupPatient, ¶ms) != OrthancPluginErrorCode_Success) | |
2206 { | |
2207 /* Error */ | |
2208 return NULL; | |
2209 } | |
2210 else | |
2211 { | |
2212 return result; | |
2213 } | |
2214 } | |
2215 | |
2216 | |
2217 /** | |
2218 * @brief Look for a study. | |
2219 * | |
2220 * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d). | |
2221 * This function uses the database index to run as fast as possible (it does not loop | |
2222 * over all the stored studies). | |
2223 * | |
2224 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2225 * @param studyUID The Study Instance UID of interest. | |
2226 * @return The NULL value if the study is non-existent, or a string containing the | |
2227 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString(). | |
2228 * @ingroup Orthanc | |
2229 **/ | |
2230 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy( | |
2231 OrthancPluginContext* context, | |
2232 const char* studyUID) | |
2233 { | |
2234 char* result; | |
2235 | |
2236 _OrthancPluginRetrieveDynamicString params; | |
2237 params.result = &result; | |
2238 params.argument = studyUID; | |
2239 | |
2240 if (context->InvokeService(context, _OrthancPluginService_LookupStudy, ¶ms) != OrthancPluginErrorCode_Success) | |
2241 { | |
2242 /* Error */ | |
2243 return NULL; | |
2244 } | |
2245 else | |
2246 { | |
2247 return result; | |
2248 } | |
2249 } | |
2250 | |
2251 | |
2252 /** | |
2253 * @brief Look for a study, using the accession number. | |
2254 * | |
2255 * Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050). | |
2256 * This function uses the database index to run as fast as possible (it does not loop | |
2257 * over all the stored studies). | |
2258 * | |
2259 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2260 * @param accessionNumber The Accession Number of interest. | |
2261 * @return The NULL value if the study is non-existent, or a string containing the | |
2262 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString(). | |
2263 * @ingroup Orthanc | |
2264 **/ | |
2265 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber( | |
2266 OrthancPluginContext* context, | |
2267 const char* accessionNumber) | |
2268 { | |
2269 char* result; | |
2270 | |
2271 _OrthancPluginRetrieveDynamicString params; | |
2272 params.result = &result; | |
2273 params.argument = accessionNumber; | |
2274 | |
2275 if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, ¶ms) != OrthancPluginErrorCode_Success) | |
2276 { | |
2277 /* Error */ | |
2278 return NULL; | |
2279 } | |
2280 else | |
2281 { | |
2282 return result; | |
2283 } | |
2284 } | |
2285 | |
2286 | |
2287 /** | |
2288 * @brief Look for a series. | |
2289 * | |
2290 * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e). | |
2291 * This function uses the database index to run as fast as possible (it does not loop | |
2292 * over all the stored series). | |
2293 * | |
2294 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2295 * @param seriesUID The Series Instance UID of interest. | |
2296 * @return The NULL value if the series is non-existent, or a string containing the | |
2297 * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString(). | |
2298 * @ingroup Orthanc | |
2299 **/ | |
2300 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries( | |
2301 OrthancPluginContext* context, | |
2302 const char* seriesUID) | |
2303 { | |
2304 char* result; | |
2305 | |
2306 _OrthancPluginRetrieveDynamicString params; | |
2307 params.result = &result; | |
2308 params.argument = seriesUID; | |
2309 | |
2310 if (context->InvokeService(context, _OrthancPluginService_LookupSeries, ¶ms) != OrthancPluginErrorCode_Success) | |
2311 { | |
2312 /* Error */ | |
2313 return NULL; | |
2314 } | |
2315 else | |
2316 { | |
2317 return result; | |
2318 } | |
2319 } | |
2320 | |
2321 | |
2322 /** | |
2323 * @brief Look for an instance. | |
2324 * | |
2325 * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018). | |
2326 * This function uses the database index to run as fast as possible (it does not loop | |
2327 * over all the stored instances). | |
2328 * | |
2329 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2330 * @param sopInstanceUID The SOP Instance UID of interest. | |
2331 * @return The NULL value if the instance is non-existent, or a string containing the | |
2332 * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString(). | |
2333 * @ingroup Orthanc | |
2334 **/ | |
2335 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance( | |
2336 OrthancPluginContext* context, | |
2337 const char* sopInstanceUID) | |
2338 { | |
2339 char* result; | |
2340 | |
2341 _OrthancPluginRetrieveDynamicString params; | |
2342 params.result = &result; | |
2343 params.argument = sopInstanceUID; | |
2344 | |
2345 if (context->InvokeService(context, _OrthancPluginService_LookupInstance, ¶ms) != OrthancPluginErrorCode_Success) | |
2346 { | |
2347 /* Error */ | |
2348 return NULL; | |
2349 } | |
2350 else | |
2351 { | |
2352 return result; | |
2353 } | |
2354 } | |
2355 | |
2356 | |
2357 | |
2358 typedef struct | |
2359 { | |
2360 OrthancPluginRestOutput* output; | |
2361 uint16_t status; | |
2362 } _OrthancPluginSendHttpStatusCode; | |
2363 | |
2364 /** | |
2365 * @brief Send a HTTP status code. | |
2366 * | |
2367 * This function answers to a REST request by sending a HTTP status | |
2368 * code (such as "400 - Bad Request"). Note that: | |
2369 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). | |
2370 * - Redirections (status 301) must use ::OrthancPluginRedirect(). | |
2371 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). | |
2372 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed(). | |
2373 * | |
2374 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2375 * @param output The HTTP connection to the client application. | |
2376 * @param status The HTTP status code to be sent. | |
2377 * @ingroup REST | |
2378 * @see OrthancPluginSendHttpStatus() | |
2379 **/ | |
2380 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode( | |
2381 OrthancPluginContext* context, | |
2382 OrthancPluginRestOutput* output, | |
2383 uint16_t status) | |
2384 { | |
2385 _OrthancPluginSendHttpStatusCode params; | |
2386 params.output = output; | |
2387 params.status = status; | |
2388 context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, ¶ms); | |
2389 } | |
2390 | |
2391 | |
2392 /** | |
2393 * @brief Signal that a REST request is not authorized. | |
2394 * | |
2395 * This function answers to a REST request by signaling that it is | |
2396 * not authorized. | |
2397 * | |
2398 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2399 * @param output The HTTP connection to the client application. | |
2400 * @param realm The realm for the authorization process. | |
2401 * @ingroup REST | |
2402 **/ | |
2403 ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized( | |
2404 OrthancPluginContext* context, | |
2405 OrthancPluginRestOutput* output, | |
2406 const char* realm) | |
2407 { | |
2408 _OrthancPluginOutputPlusArgument params; | |
2409 params.output = output; | |
2410 params.argument = realm; | |
2411 context->InvokeService(context, _OrthancPluginService_SendUnauthorized, ¶ms); | |
2412 } | |
2413 | |
2414 | |
2415 /** | |
2416 * @brief Signal that this URI does not support this HTTP method. | |
2417 * | |
2418 * This function answers to a REST request by signaling that the | |
2419 * queried URI does not support this method. | |
2420 * | |
2421 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2422 * @param output The HTTP connection to the client application. | |
2423 * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request). | |
2424 * @ingroup REST | |
2425 **/ | |
2426 ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed( | |
2427 OrthancPluginContext* context, | |
2428 OrthancPluginRestOutput* output, | |
2429 const char* allowedMethods) | |
2430 { | |
2431 _OrthancPluginOutputPlusArgument params; | |
2432 params.output = output; | |
2433 params.argument = allowedMethods; | |
2434 context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, ¶ms); | |
2435 } | |
2436 | |
2437 | |
2438 typedef struct | |
2439 { | |
2440 OrthancPluginRestOutput* output; | |
2441 const char* key; | |
2442 const char* value; | |
2443 } _OrthancPluginSetHttpHeader; | |
2444 | |
2445 /** | |
2446 * @brief Set a cookie. | |
2447 * | |
2448 * This function sets a cookie in the HTTP client. | |
2449 * | |
2450 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2451 * @param output The HTTP connection to the client application. | |
2452 * @param cookie The cookie to be set. | |
2453 * @param value The value of the cookie. | |
2454 * @ingroup REST | |
2455 **/ | |
2456 ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie( | |
2457 OrthancPluginContext* context, | |
2458 OrthancPluginRestOutput* output, | |
2459 const char* cookie, | |
2460 const char* value) | |
2461 { | |
2462 _OrthancPluginSetHttpHeader params; | |
2463 params.output = output; | |
2464 params.key = cookie; | |
2465 params.value = value; | |
2466 context->InvokeService(context, _OrthancPluginService_SetCookie, ¶ms); | |
2467 } | |
2468 | |
2469 | |
2470 /** | |
2471 * @brief Set some HTTP header. | |
2472 * | |
2473 * This function sets a HTTP header in the HTTP answer. | |
2474 * | |
2475 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2476 * @param output The HTTP connection to the client application. | |
2477 * @param key The HTTP header to be set. | |
2478 * @param value The value of the HTTP header. | |
2479 * @ingroup REST | |
2480 **/ | |
2481 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader( | |
2482 OrthancPluginContext* context, | |
2483 OrthancPluginRestOutput* output, | |
2484 const char* key, | |
2485 const char* value) | |
2486 { | |
2487 _OrthancPluginSetHttpHeader params; | |
2488 params.output = output; | |
2489 params.key = key; | |
2490 params.value = value; | |
2491 context->InvokeService(context, _OrthancPluginService_SetHttpHeader, ¶ms); | |
2492 } | |
2493 | |
2494 | |
2495 typedef struct | |
2496 { | |
2497 char** resultStringToFree; | |
2498 const char** resultString; | |
2499 int64_t* resultInt64; | |
2500 const char* key; | |
2501 OrthancPluginDicomInstance* instance; | |
2502 OrthancPluginInstanceOrigin* resultOrigin; /* New in Orthanc 0.9.5 SDK */ | |
2503 } _OrthancPluginAccessDicomInstance; | |
2504 | |
2505 | |
2506 /** | |
2507 * @brief Get the AET of a DICOM instance. | |
2508 * | |
2509 * This function returns the Application Entity Title (AET) of the | |
2510 * DICOM modality from which a DICOM instance originates. | |
2511 * | |
2512 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2513 * @param instance The instance of interest. | |
2514 * @return The AET if success, NULL if error. | |
2515 * @ingroup Callbacks | |
2516 **/ | |
2517 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet( | |
2518 OrthancPluginContext* context, | |
2519 OrthancPluginDicomInstance* instance) | |
2520 { | |
2521 const char* result; | |
2522 | |
2523 _OrthancPluginAccessDicomInstance params; | |
2524 memset(¶ms, 0, sizeof(params)); | |
2525 params.resultString = &result; | |
2526 params.instance = instance; | |
2527 | |
2528 if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, ¶ms) != OrthancPluginErrorCode_Success) | |
2529 { | |
2530 /* Error */ | |
2531 return NULL; | |
2532 } | |
2533 else | |
2534 { | |
2535 return result; | |
2536 } | |
2537 } | |
2538 | |
2539 | |
2540 /** | |
2541 * @brief Get the size of a DICOM file. | |
2542 * | |
2543 * This function returns the number of bytes of the given DICOM instance. | |
2544 * | |
2545 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2546 * @param instance The instance of interest. | |
2547 * @return The size of the file, -1 in case of error. | |
2548 * @ingroup Callbacks | |
2549 **/ | |
2550 ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize( | |
2551 OrthancPluginContext* context, | |
2552 OrthancPluginDicomInstance* instance) | |
2553 { | |
2554 int64_t size; | |
2555 | |
2556 _OrthancPluginAccessDicomInstance params; | |
2557 memset(¶ms, 0, sizeof(params)); | |
2558 params.resultInt64 = &size; | |
2559 params.instance = instance; | |
2560 | |
2561 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, ¶ms) != OrthancPluginErrorCode_Success) | |
2562 { | |
2563 /* Error */ | |
2564 return -1; | |
2565 } | |
2566 else | |
2567 { | |
2568 return size; | |
2569 } | |
2570 } | |
2571 | |
2572 | |
2573 /** | |
2574 * @brief Get the data of a DICOM file. | |
2575 * | |
2576 * This function returns a pointer to the content of the given DICOM instance. | |
2577 * | |
2578 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2579 * @param instance The instance of interest. | |
2580 * @return The pointer to the DICOM data, NULL in case of error. | |
2581 * @ingroup Callbacks | |
2582 **/ | |
2583 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceData( | |
2584 OrthancPluginContext* context, | |
2585 OrthancPluginDicomInstance* instance) | |
2586 { | |
2587 const char* result; | |
2588 | |
2589 _OrthancPluginAccessDicomInstance params; | |
2590 memset(¶ms, 0, sizeof(params)); | |
2591 params.resultString = &result; | |
2592 params.instance = instance; | |
2593 | |
2594 if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, ¶ms) != OrthancPluginErrorCode_Success) | |
2595 { | |
2596 /* Error */ | |
2597 return NULL; | |
2598 } | |
2599 else | |
2600 { | |
2601 return result; | |
2602 } | |
2603 } | |
2604 | |
2605 | |
2606 /** | |
2607 * @brief Get the DICOM tag hierarchy as a JSON file. | |
2608 * | |
2609 * This function returns a pointer to a newly created string | |
2610 * containing a JSON file. This JSON file encodes the tag hierarchy | |
2611 * of the given DICOM instance. | |
2612 * | |
2613 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2614 * @param instance The instance of interest. | |
2615 * @return The NULL value in case of error, or a string containing the JSON file. | |
2616 * This string must be freed by OrthancPluginFreeString(). | |
2617 * @ingroup Callbacks | |
2618 **/ | |
2619 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson( | |
2620 OrthancPluginContext* context, | |
2621 OrthancPluginDicomInstance* instance) | |
2622 { | |
2623 char* result; | |
2624 | |
2625 _OrthancPluginAccessDicomInstance params; | |
2626 memset(¶ms, 0, sizeof(params)); | |
2627 params.resultStringToFree = &result; | |
2628 params.instance = instance; | |
2629 | |
2630 if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, ¶ms) != OrthancPluginErrorCode_Success) | |
2631 { | |
2632 /* Error */ | |
2633 return NULL; | |
2634 } | |
2635 else | |
2636 { | |
2637 return result; | |
2638 } | |
2639 } | |
2640 | |
2641 | |
2642 /** | |
2643 * @brief Get the DICOM tag hierarchy as a JSON file (with simplification). | |
2644 * | |
2645 * This function returns a pointer to a newly created string | |
2646 * containing a JSON file. This JSON file encodes the tag hierarchy | |
2647 * of the given DICOM instance. In contrast with | |
2648 * ::OrthancPluginGetInstanceJson(), the returned JSON file is in | |
2649 * its simplified version. | |
2650 * | |
2651 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2652 * @param instance The instance of interest. | |
2653 * @return The NULL value in case of error, or a string containing the JSON file. | |
2654 * This string must be freed by OrthancPluginFreeString(). | |
2655 * @ingroup Callbacks | |
2656 **/ | |
2657 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson( | |
2658 OrthancPluginContext* context, | |
2659 OrthancPluginDicomInstance* instance) | |
2660 { | |
2661 char* result; | |
2662 | |
2663 _OrthancPluginAccessDicomInstance params; | |
2664 memset(¶ms, 0, sizeof(params)); | |
2665 params.resultStringToFree = &result; | |
2666 params.instance = instance; | |
2667 | |
2668 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, ¶ms) != OrthancPluginErrorCode_Success) | |
2669 { | |
2670 /* Error */ | |
2671 return NULL; | |
2672 } | |
2673 else | |
2674 { | |
2675 return result; | |
2676 } | |
2677 } | |
2678 | |
2679 | |
2680 /** | |
2681 * @brief Check whether a DICOM instance is associated with some metadata. | |
2682 * | |
2683 * This function checks whether the DICOM instance of interest is | |
2684 * associated with some metadata. As of Orthanc 0.8.1, in the | |
2685 * callbacks registered by | |
2686 * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only | |
2687 * possibly available metadata are "ReceptionDate", "RemoteAET" and | |
2688 * "IndexInSeries". | |
2689 * | |
2690 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2691 * @param instance The instance of interest. | |
2692 * @param metadata The metadata of interest. | |
2693 * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error. | |
2694 * @ingroup Callbacks | |
2695 **/ | |
2696 ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata( | |
2697 OrthancPluginContext* context, | |
2698 OrthancPluginDicomInstance* instance, | |
2699 const char* metadata) | |
2700 { | |
2701 int64_t result; | |
2702 | |
2703 _OrthancPluginAccessDicomInstance params; | |
2704 memset(¶ms, 0, sizeof(params)); | |
2705 params.resultInt64 = &result; | |
2706 params.instance = instance; | |
2707 params.key = metadata; | |
2708 | |
2709 if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, ¶ms) != OrthancPluginErrorCode_Success) | |
2710 { | |
2711 /* Error */ | |
2712 return -1; | |
2713 } | |
2714 else | |
2715 { | |
2716 return (result != 0); | |
2717 } | |
2718 } | |
2719 | |
2720 | |
2721 /** | |
2722 * @brief Get the value of some metadata associated with a given DICOM instance. | |
2723 * | |
2724 * This functions returns the value of some metadata that is associated with the DICOM instance of interest. | |
2725 * Before calling this function, the existence of the metadata must have been checked with | |
2726 * ::OrthancPluginHasInstanceMetadata(). | |
2727 * | |
2728 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2729 * @param instance The instance of interest. | |
2730 * @param metadata The metadata of interest. | |
2731 * @return The metadata value if success, NULL if error. | |
2732 * @ingroup Callbacks | |
2733 **/ | |
2734 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata( | |
2735 OrthancPluginContext* context, | |
2736 OrthancPluginDicomInstance* instance, | |
2737 const char* metadata) | |
2738 { | |
2739 const char* result; | |
2740 | |
2741 _OrthancPluginAccessDicomInstance params; | |
2742 memset(¶ms, 0, sizeof(params)); | |
2743 params.resultString = &result; | |
2744 params.instance = instance; | |
2745 params.key = metadata; | |
2746 | |
2747 if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, ¶ms) != OrthancPluginErrorCode_Success) | |
2748 { | |
2749 /* Error */ | |
2750 return NULL; | |
2751 } | |
2752 else | |
2753 { | |
2754 return result; | |
2755 } | |
2756 } | |
2757 | |
2758 | |
2759 | |
2760 typedef struct | |
2761 { | |
2762 OrthancPluginStorageCreate create; | |
2763 OrthancPluginStorageRead read; | |
2764 OrthancPluginStorageRemove remove; | |
2765 OrthancPluginFree free; | |
2766 } _OrthancPluginRegisterStorageArea; | |
2767 | |
2768 /** | |
2769 * @brief Register a custom storage area. | |
2770 * | |
2771 * This function registers a custom storage area, to replace the | |
2772 * built-in way Orthanc stores its files on the filesystem. This | |
2773 * function must be called during the initialization of the plugin, | |
2774 * i.e. inside the OrthancPluginInitialize() public function. | |
2775 * | |
2776 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2777 * @param create The callback function to store a file on the custom storage area. | |
2778 * @param read The callback function to read a file from the custom storage area. | |
2779 * @param remove The callback function to remove a file from the custom storage area. | |
2780 * @ingroup Callbacks | |
2781 **/ | |
2782 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea( | |
2783 OrthancPluginContext* context, | |
2784 OrthancPluginStorageCreate create, | |
2785 OrthancPluginStorageRead read, | |
2786 OrthancPluginStorageRemove remove) | |
2787 { | |
2788 _OrthancPluginRegisterStorageArea params; | |
2789 params.create = create; | |
2790 params.read = read; | |
2791 params.remove = remove; | |
2792 | |
2793 #ifdef __cplusplus | |
2794 params.free = ::free; | |
2795 #else | |
2796 params.free = free; | |
2797 #endif | |
2798 | |
2799 context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, ¶ms); | |
2800 } | |
2801 | |
2802 | |
2803 | |
2804 /** | |
2805 * @brief Return the path to the Orthanc executable. | |
2806 * | |
2807 * This function returns the path to the Orthanc executable. | |
2808 * | |
2809 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2810 * @return NULL in the case of an error, or a newly allocated string | |
2811 * containing the path. This string must be freed by | |
2812 * OrthancPluginFreeString(). | |
2813 **/ | |
2814 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context) | |
2815 { | |
2816 char* result; | |
2817 | |
2818 _OrthancPluginRetrieveDynamicString params; | |
2819 params.result = &result; | |
2820 params.argument = NULL; | |
2821 | |
2822 if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, ¶ms) != OrthancPluginErrorCode_Success) | |
2823 { | |
2824 /* Error */ | |
2825 return NULL; | |
2826 } | |
2827 else | |
2828 { | |
2829 return result; | |
2830 } | |
2831 } | |
2832 | |
2833 | |
2834 /** | |
2835 * @brief Return the directory containing the Orthanc. | |
2836 * | |
2837 * This function returns the path to the directory containing the Orthanc executable. | |
2838 * | |
2839 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2840 * @return NULL in the case of an error, or a newly allocated string | |
2841 * containing the path. This string must be freed by | |
2842 * OrthancPluginFreeString(). | |
2843 **/ | |
2844 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context) | |
2845 { | |
2846 char* result; | |
2847 | |
2848 _OrthancPluginRetrieveDynamicString params; | |
2849 params.result = &result; | |
2850 params.argument = NULL; | |
2851 | |
2852 if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, ¶ms) != OrthancPluginErrorCode_Success) | |
2853 { | |
2854 /* Error */ | |
2855 return NULL; | |
2856 } | |
2857 else | |
2858 { | |
2859 return result; | |
2860 } | |
2861 } | |
2862 | |
2863 | |
2864 /** | |
2865 * @brief Return the path to the configuration file(s). | |
2866 * | |
2867 * This function returns the path to the configuration file(s) that | |
2868 * was specified when starting Orthanc. Since version 0.9.1, this | |
2869 * path can refer to a folder that stores a set of configuration | |
2870 * files. This function is deprecated in favor of | |
2871 * OrthancPluginGetConfiguration(). | |
2872 * | |
2873 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2874 * @return NULL in the case of an error, or a newly allocated string | |
2875 * containing the path. This string must be freed by | |
2876 * OrthancPluginFreeString(). | |
2877 * @see OrthancPluginGetConfiguration() | |
2878 **/ | |
2879 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context) | |
2880 { | |
2881 char* result; | |
2882 | |
2883 _OrthancPluginRetrieveDynamicString params; | |
2884 params.result = &result; | |
2885 params.argument = NULL; | |
2886 | |
2887 if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, ¶ms) != OrthancPluginErrorCode_Success) | |
2888 { | |
2889 /* Error */ | |
2890 return NULL; | |
2891 } | |
2892 else | |
2893 { | |
2894 return result; | |
2895 } | |
2896 } | |
2897 | |
2898 | |
2899 | |
2900 typedef struct | |
2901 { | |
2902 OrthancPluginOnChangeCallback callback; | |
2903 } _OrthancPluginOnChangeCallback; | |
2904 | |
2905 /** | |
2906 * @brief Register a callback to monitor changes. | |
2907 * | |
2908 * This function registers a callback function that is called | |
2909 * whenever a change happens to some DICOM resource. | |
2910 * | |
2911 * @warning If your change callback has to call the REST API of | |
2912 * Orthanc, you should make these calls in a separate thread (with | |
2913 * the events passing through a message queue). Otherwise, this | |
2914 * could result in deadlocks in the presence of other plugins or Lua | |
2915 * scripts. | |
2916 * | |
2917 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2918 * @param callback The callback function. | |
2919 * @ingroup Callbacks | |
2920 **/ | |
2921 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnChangeCallback( | |
2922 OrthancPluginContext* context, | |
2923 OrthancPluginOnChangeCallback callback) | |
2924 { | |
2925 _OrthancPluginOnChangeCallback params; | |
2926 params.callback = callback; | |
2927 | |
2928 context->InvokeService(context, _OrthancPluginService_RegisterOnChangeCallback, ¶ms); | |
2929 } | |
2930 | |
2931 | |
2932 | |
2933 typedef struct | |
2934 { | |
2935 const char* plugin; | |
2936 _OrthancPluginProperty property; | |
2937 const char* value; | |
2938 } _OrthancPluginSetPluginProperty; | |
2939 | |
2940 | |
2941 /** | |
2942 * @brief Set the URI where the plugin provides its Web interface. | |
2943 * | |
2944 * For plugins that come with a Web interface, this function | |
2945 * declares the entry path where to find this interface. This | |
2946 * information is notably used in the "Plugins" page of Orthanc | |
2947 * Explorer. | |
2948 * | |
2949 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2950 * @param uri The root URI for this plugin. | |
2951 **/ | |
2952 ORTHANC_PLUGIN_INLINE void OrthancPluginSetRootUri( | |
2953 OrthancPluginContext* context, | |
2954 const char* uri) | |
2955 { | |
2956 _OrthancPluginSetPluginProperty params; | |
2957 params.plugin = OrthancPluginGetName(); | |
2958 params.property = _OrthancPluginProperty_RootUri; | |
2959 params.value = uri; | |
2960 | |
2961 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); | |
2962 } | |
2963 | |
2964 | |
2965 /** | |
2966 * @brief Set a description for this plugin. | |
2967 * | |
2968 * Set a description for this plugin. It is displayed in the | |
2969 * "Plugins" page of Orthanc Explorer. | |
2970 * | |
2971 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2972 * @param description The description. | |
2973 **/ | |
2974 ORTHANC_PLUGIN_INLINE void OrthancPluginSetDescription( | |
2975 OrthancPluginContext* context, | |
2976 const char* description) | |
2977 { | |
2978 _OrthancPluginSetPluginProperty params; | |
2979 params.plugin = OrthancPluginGetName(); | |
2980 params.property = _OrthancPluginProperty_Description; | |
2981 params.value = description; | |
2982 | |
2983 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); | |
2984 } | |
2985 | |
2986 | |
2987 /** | |
2988 * @brief Extend the JavaScript code of Orthanc Explorer. | |
2989 * | |
2990 * Add JavaScript code to customize the default behavior of Orthanc | |
2991 * Explorer. This can for instance be used to add new buttons. | |
2992 * | |
2993 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2994 * @param javascript The custom JavaScript code. | |
2995 **/ | |
2996 ORTHANC_PLUGIN_INLINE void OrthancPluginExtendOrthancExplorer( | |
2997 OrthancPluginContext* context, | |
2998 const char* javascript) | |
2999 { | |
3000 _OrthancPluginSetPluginProperty params; | |
3001 params.plugin = OrthancPluginGetName(); | |
3002 params.property = _OrthancPluginProperty_OrthancExplorer; | |
3003 params.value = javascript; | |
3004 | |
3005 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); | |
3006 } | |
3007 | |
3008 | |
3009 typedef struct | |
3010 { | |
3011 char** result; | |
3012 int32_t property; | |
3013 const char* value; | |
3014 } _OrthancPluginGlobalProperty; | |
3015 | |
3016 | |
3017 /** | |
3018 * @brief Get the value of a global property. | |
3019 * | |
3020 * Get the value of a global property that is stored in the Orthanc database. Global | |
3021 * properties whose index is below 1024 are reserved by Orthanc. | |
3022 * | |
3023 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3024 * @param property The global property of interest. | |
3025 * @param defaultValue The value to return, if the global property is unset. | |
3026 * @return The value of the global property, or NULL in the case of an error. This | |
3027 * string must be freed by OrthancPluginFreeString(). | |
3028 * @ingroup Orthanc | |
3029 **/ | |
3030 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetGlobalProperty( | |
3031 OrthancPluginContext* context, | |
3032 int32_t property, | |
3033 const char* defaultValue) | |
3034 { | |
3035 char* result; | |
3036 | |
3037 _OrthancPluginGlobalProperty params; | |
3038 params.result = &result; | |
3039 params.property = property; | |
3040 params.value = defaultValue; | |
3041 | |
3042 if (context->InvokeService(context, _OrthancPluginService_GetGlobalProperty, ¶ms) != OrthancPluginErrorCode_Success) | |
3043 { | |
3044 /* Error */ | |
3045 return NULL; | |
3046 } | |
3047 else | |
3048 { | |
3049 return result; | |
3050 } | |
3051 } | |
3052 | |
3053 | |
3054 /** | |
3055 * @brief Set the value of a global property. | |
3056 * | |
3057 * Set the value of a global property into the Orthanc | |
3058 * database. Setting a global property can be used by plugins to | |
3059 * save their internal parameters. Plugins are only allowed to set | |
3060 * properties whose index are above or equal to 1024 (properties | |
3061 * below 1024 are read-only and reserved by Orthanc). | |
3062 * | |
3063 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3064 * @param property The global property of interest. | |
3065 * @param value The value to be set in the global property. | |
3066 * @return 0 if success, or the error code if failure. | |
3067 * @ingroup Orthanc | |
3068 **/ | |
3069 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetGlobalProperty( | |
3070 OrthancPluginContext* context, | |
3071 int32_t property, | |
3072 const char* value) | |
3073 { | |
3074 _OrthancPluginGlobalProperty params; | |
3075 params.result = NULL; | |
3076 params.property = property; | |
3077 params.value = value; | |
3078 | |
3079 return context->InvokeService(context, _OrthancPluginService_SetGlobalProperty, ¶ms); | |
3080 } | |
3081 | |
3082 | |
3083 | |
3084 typedef struct | |
3085 { | |
3086 int32_t *resultInt32; | |
3087 uint32_t *resultUint32; | |
3088 int64_t *resultInt64; | |
3089 uint64_t *resultUint64; | |
3090 } _OrthancPluginReturnSingleValue; | |
3091 | |
3092 /** | |
3093 * @brief Get the number of command-line arguments. | |
3094 * | |
3095 * Retrieve the number of command-line arguments that were used to launch Orthanc. | |
3096 * | |
3097 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3098 * @return The number of arguments. | |
3099 **/ | |
3100 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetCommandLineArgumentsCount( | |
3101 OrthancPluginContext* context) | |
3102 { | |
3103 uint32_t count = 0; | |
3104 | |
3105 _OrthancPluginReturnSingleValue params; | |
3106 memset(¶ms, 0, sizeof(params)); | |
3107 params.resultUint32 = &count; | |
3108 | |
3109 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgumentsCount, ¶ms) != OrthancPluginErrorCode_Success) | |
3110 { | |
3111 /* Error */ | |
3112 return 0; | |
3113 } | |
3114 else | |
3115 { | |
3116 return count; | |
3117 } | |
3118 } | |
3119 | |
3120 | |
3121 | |
3122 /** | |
3123 * @brief Get the value of a command-line argument. | |
3124 * | |
3125 * Get the value of one of the command-line arguments that were used | |
3126 * to launch Orthanc. The number of available arguments can be | |
3127 * retrieved by OrthancPluginGetCommandLineArgumentsCount(). | |
3128 * | |
3129 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3130 * @param argument The index of the argument. | |
3131 * @return The value of the argument, or NULL in the case of an error. This | |
3132 * string must be freed by OrthancPluginFreeString(). | |
3133 **/ | |
3134 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetCommandLineArgument( | |
3135 OrthancPluginContext* context, | |
3136 uint32_t argument) | |
3137 { | |
3138 char* result; | |
3139 | |
3140 _OrthancPluginGlobalProperty params; | |
3141 params.result = &result; | |
3142 params.property = (int32_t) argument; | |
3143 params.value = NULL; | |
3144 | |
3145 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgument, ¶ms) != OrthancPluginErrorCode_Success) | |
3146 { | |
3147 /* Error */ | |
3148 return NULL; | |
3149 } | |
3150 else | |
3151 { | |
3152 return result; | |
3153 } | |
3154 } | |
3155 | |
3156 | |
3157 /** | |
3158 * @brief Get the expected version of the database schema. | |
3159 * | |
3160 * Retrieve the expected version of the database schema. | |
3161 * | |
3162 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3163 * @return The version. | |
3164 * @ingroup Callbacks | |
3165 **/ | |
3166 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion( | |
3167 OrthancPluginContext* context) | |
3168 { | |
3169 uint32_t count = 0; | |
3170 | |
3171 _OrthancPluginReturnSingleValue params; | |
3172 memset(¶ms, 0, sizeof(params)); | |
3173 params.resultUint32 = &count; | |
3174 | |
3175 if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, ¶ms) != OrthancPluginErrorCode_Success) | |
3176 { | |
3177 /* Error */ | |
3178 return 0; | |
3179 } | |
3180 else | |
3181 { | |
3182 return count; | |
3183 } | |
3184 } | |
3185 | |
3186 | |
3187 | |
3188 /** | |
3189 * @brief Return the content of the configuration file(s). | |
3190 * | |
3191 * This function returns the content of the configuration that is | |
3192 * used by Orthanc, formatted as a JSON string. | |
3193 * | |
3194 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3195 * @return NULL in the case of an error, or a newly allocated string | |
3196 * containing the configuration. This string must be freed by | |
3197 * OrthancPluginFreeString(). | |
3198 **/ | |
3199 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfiguration(OrthancPluginContext* context) | |
3200 { | |
3201 char* result; | |
3202 | |
3203 _OrthancPluginRetrieveDynamicString params; | |
3204 params.result = &result; | |
3205 params.argument = NULL; | |
3206 | |
3207 if (context->InvokeService(context, _OrthancPluginService_GetConfiguration, ¶ms) != OrthancPluginErrorCode_Success) | |
3208 { | |
3209 /* Error */ | |
3210 return NULL; | |
3211 } | |
3212 else | |
3213 { | |
3214 return result; | |
3215 } | |
3216 } | |
3217 | |
3218 | |
3219 | |
3220 typedef struct | |
3221 { | |
3222 OrthancPluginRestOutput* output; | |
3223 const char* subType; | |
3224 const char* contentType; | |
3225 } _OrthancPluginStartMultipartAnswer; | |
3226 | |
3227 /** | |
3228 * @brief Start an HTTP multipart answer. | |
3229 * | |
3230 * Initiates a HTTP multipart answer, as the result of a REST request. | |
3231 * | |
3232 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3233 * @param output The HTTP connection to the client application. | |
3234 * @param subType The sub-type of the multipart answer ("mixed" or "related"). | |
3235 * @param contentType The MIME type of the items in the multipart answer. | |
3236 * @return 0 if success, or the error code if failure. | |
3237 * @see OrthancPluginSendMultipartItem(), OrthancPluginSendMultipartItem2() | |
3238 * @ingroup REST | |
3239 **/ | |
3240 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStartMultipartAnswer( | |
3241 OrthancPluginContext* context, | |
3242 OrthancPluginRestOutput* output, | |
3243 const char* subType, | |
3244 const char* contentType) | |
3245 { | |
3246 _OrthancPluginStartMultipartAnswer params; | |
3247 params.output = output; | |
3248 params.subType = subType; | |
3249 params.contentType = contentType; | |
3250 return context->InvokeService(context, _OrthancPluginService_StartMultipartAnswer, ¶ms); | |
3251 } | |
3252 | |
3253 | |
3254 /** | |
3255 * @brief Send an item as a part of some HTTP multipart answer. | |
3256 * | |
3257 * This function sends an item as a part of some HTTP multipart | |
3258 * answer that was initiated by OrthancPluginStartMultipartAnswer(). | |
3259 * | |
3260 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3261 * @param output The HTTP connection to the client application. | |
3262 * @param answer Pointer to the memory buffer containing the item. | |
3263 * @param answerSize Number of bytes of the item. | |
3264 * @return 0 if success, or the error code if failure (this notably happens | |
3265 * if the connection is closed by the client). | |
3266 * @see OrthancPluginSendMultipartItem2() | |
3267 * @ingroup REST | |
3268 **/ | |
3269 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem( | |
3270 OrthancPluginContext* context, | |
3271 OrthancPluginRestOutput* output, | |
3272 const char* answer, | |
3273 uint32_t answerSize) | |
3274 { | |
3275 _OrthancPluginAnswerBuffer params; | |
3276 params.output = output; | |
3277 params.answer = answer; | |
3278 params.answerSize = answerSize; | |
3279 params.mimeType = NULL; | |
3280 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem, ¶ms); | |
3281 } | |
3282 | |
3283 | |
3284 | |
3285 typedef struct | |
3286 { | |
3287 OrthancPluginMemoryBuffer* target; | |
3288 const void* source; | |
3289 uint32_t size; | |
3290 OrthancPluginCompressionType compression; | |
3291 uint8_t uncompress; | |
3292 } _OrthancPluginBufferCompression; | |
3293 | |
3294 | |
3295 /** | |
3296 * @brief Compress or decompress a buffer. | |
3297 * | |
3298 * This function compresses or decompresses a buffer, using the | |
3299 * version of the zlib library that is used by the Orthanc core. | |
3300 * | |
3301 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3302 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3303 * @param source The source buffer. | |
3304 * @param size The size in bytes of the source buffer. | |
3305 * @param compression The compression algorithm. | |
3306 * @param uncompress If set to "0", the buffer must be compressed. | |
3307 * If set to "1", the buffer must be uncompressed. | |
3308 * @return 0 if success, or the error code if failure. | |
3309 * @ingroup Images | |
3310 **/ | |
3311 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginBufferCompression( | |
3312 OrthancPluginContext* context, | |
3313 OrthancPluginMemoryBuffer* target, | |
3314 const void* source, | |
3315 uint32_t size, | |
3316 OrthancPluginCompressionType compression, | |
3317 uint8_t uncompress) | |
3318 { | |
3319 _OrthancPluginBufferCompression params; | |
3320 params.target = target; | |
3321 params.source = source; | |
3322 params.size = size; | |
3323 params.compression = compression; | |
3324 params.uncompress = uncompress; | |
3325 | |
3326 return context->InvokeService(context, _OrthancPluginService_BufferCompression, ¶ms); | |
3327 } | |
3328 | |
3329 | |
3330 | |
3331 typedef struct | |
3332 { | |
3333 OrthancPluginMemoryBuffer* target; | |
3334 const char* path; | |
3335 } _OrthancPluginReadFile; | |
3336 | |
3337 /** | |
3338 * @brief Read a file. | |
3339 * | |
3340 * Read the content of a file on the filesystem, and returns it into | |
3341 * a newly allocated memory buffer. | |
3342 * | |
3343 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3344 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3345 * @param path The path of the file to be read. | |
3346 * @return 0 if success, or the error code if failure. | |
3347 **/ | |
3348 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReadFile( | |
3349 OrthancPluginContext* context, | |
3350 OrthancPluginMemoryBuffer* target, | |
3351 const char* path) | |
3352 { | |
3353 _OrthancPluginReadFile params; | |
3354 params.target = target; | |
3355 params.path = path; | |
3356 return context->InvokeService(context, _OrthancPluginService_ReadFile, ¶ms); | |
3357 } | |
3358 | |
3359 | |
3360 | |
3361 typedef struct | |
3362 { | |
3363 const char* path; | |
3364 const void* data; | |
3365 uint32_t size; | |
3366 } _OrthancPluginWriteFile; | |
3367 | |
3368 /** | |
3369 * @brief Write a file. | |
3370 * | |
3371 * Write the content of a memory buffer to the filesystem. | |
3372 * | |
3373 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3374 * @param path The path of the file to be written. | |
3375 * @param data The content of the memory buffer. | |
3376 * @param size The size of the memory buffer. | |
3377 * @return 0 if success, or the error code if failure. | |
3378 **/ | |
3379 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWriteFile( | |
3380 OrthancPluginContext* context, | |
3381 const char* path, | |
3382 const void* data, | |
3383 uint32_t size) | |
3384 { | |
3385 _OrthancPluginWriteFile params; | |
3386 params.path = path; | |
3387 params.data = data; | |
3388 params.size = size; | |
3389 return context->InvokeService(context, _OrthancPluginService_WriteFile, ¶ms); | |
3390 } | |
3391 | |
3392 | |
3393 | |
3394 typedef struct | |
3395 { | |
3396 const char** target; | |
3397 OrthancPluginErrorCode error; | |
3398 } _OrthancPluginGetErrorDescription; | |
3399 | |
3400 /** | |
3401 * @brief Get the description of a given error code. | |
3402 * | |
3403 * This function returns the description of a given error code. | |
3404 * | |
3405 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3406 * @param error The error code of interest. | |
3407 * @return The error description. This is a statically-allocated | |
3408 * string, do not free it. | |
3409 **/ | |
3410 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetErrorDescription( | |
3411 OrthancPluginContext* context, | |
3412 OrthancPluginErrorCode error) | |
3413 { | |
3414 const char* result = NULL; | |
3415 | |
3416 _OrthancPluginGetErrorDescription params; | |
3417 params.target = &result; | |
3418 params.error = error; | |
3419 | |
3420 if (context->InvokeService(context, _OrthancPluginService_GetErrorDescription, ¶ms) != OrthancPluginErrorCode_Success || | |
3421 result == NULL) | |
3422 { | |
3423 return "Unknown error code"; | |
3424 } | |
3425 else | |
3426 { | |
3427 return result; | |
3428 } | |
3429 } | |
3430 | |
3431 | |
3432 | |
3433 typedef struct | |
3434 { | |
3435 OrthancPluginRestOutput* output; | |
3436 uint16_t status; | |
3437 const char* body; | |
3438 uint32_t bodySize; | |
3439 } _OrthancPluginSendHttpStatus; | |
3440 | |
3441 /** | |
3442 * @brief Send a HTTP status, with a custom body. | |
3443 * | |
3444 * This function answers to a HTTP request by sending a HTTP status | |
3445 * code (such as "400 - Bad Request"), together with a body | |
3446 * describing the error. The body will only be returned if the | |
3447 * configuration option "HttpDescribeErrors" of Orthanc is set to "true". | |
3448 * | |
3449 * Note that: | |
3450 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). | |
3451 * - Redirections (status 301) must use ::OrthancPluginRedirect(). | |
3452 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). | |
3453 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed(). | |
3454 * | |
3455 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3456 * @param output The HTTP connection to the client application. | |
3457 * @param status The HTTP status code to be sent. | |
3458 * @param body The body of the answer. | |
3459 * @param bodySize The size of the body. | |
3460 * @see OrthancPluginSendHttpStatusCode() | |
3461 * @ingroup REST | |
3462 **/ | |
3463 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatus( | |
3464 OrthancPluginContext* context, | |
3465 OrthancPluginRestOutput* output, | |
3466 uint16_t status, | |
3467 const char* body, | |
3468 uint32_t bodySize) | |
3469 { | |
3470 _OrthancPluginSendHttpStatus params; | |
3471 params.output = output; | |
3472 params.status = status; | |
3473 params.body = body; | |
3474 params.bodySize = bodySize; | |
3475 context->InvokeService(context, _OrthancPluginService_SendHttpStatus, ¶ms); | |
3476 } | |
3477 | |
3478 | |
3479 | |
3480 typedef struct | |
3481 { | |
3482 const OrthancPluginImage* image; | |
3483 uint32_t* resultUint32; | |
3484 OrthancPluginPixelFormat* resultPixelFormat; | |
3485 void** resultBuffer; | |
3486 } _OrthancPluginGetImageInfo; | |
3487 | |
3488 | |
3489 /** | |
3490 * @brief Return the pixel format of an image. | |
3491 * | |
3492 * This function returns the type of memory layout for the pixels of the given image. | |
3493 * | |
3494 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3495 * @param image The image of interest. | |
3496 * @return The pixel format. | |
3497 * @ingroup Images | |
3498 **/ | |
3499 ORTHANC_PLUGIN_INLINE OrthancPluginPixelFormat OrthancPluginGetImagePixelFormat( | |
3500 OrthancPluginContext* context, | |
3501 const OrthancPluginImage* image) | |
3502 { | |
3503 OrthancPluginPixelFormat target; | |
3504 | |
3505 _OrthancPluginGetImageInfo params; | |
3506 memset(¶ms, 0, sizeof(params)); | |
3507 params.image = image; | |
3508 params.resultPixelFormat = ⌖ | |
3509 | |
3510 if (context->InvokeService(context, _OrthancPluginService_GetImagePixelFormat, ¶ms) != OrthancPluginErrorCode_Success) | |
3511 { | |
3512 return OrthancPluginPixelFormat_Unknown; | |
3513 } | |
3514 else | |
3515 { | |
3516 return (OrthancPluginPixelFormat) target; | |
3517 } | |
3518 } | |
3519 | |
3520 | |
3521 | |
3522 /** | |
3523 * @brief Return the width of an image. | |
3524 * | |
3525 * This function returns the width of the given image. | |
3526 * | |
3527 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3528 * @param image The image of interest. | |
3529 * @return The width. | |
3530 * @ingroup Images | |
3531 **/ | |
3532 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageWidth( | |
3533 OrthancPluginContext* context, | |
3534 const OrthancPluginImage* image) | |
3535 { | |
3536 uint32_t width; | |
3537 | |
3538 _OrthancPluginGetImageInfo params; | |
3539 memset(¶ms, 0, sizeof(params)); | |
3540 params.image = image; | |
3541 params.resultUint32 = &width; | |
3542 | |
3543 if (context->InvokeService(context, _OrthancPluginService_GetImageWidth, ¶ms) != OrthancPluginErrorCode_Success) | |
3544 { | |
3545 return 0; | |
3546 } | |
3547 else | |
3548 { | |
3549 return width; | |
3550 } | |
3551 } | |
3552 | |
3553 | |
3554 | |
3555 /** | |
3556 * @brief Return the height of an image. | |
3557 * | |
3558 * This function returns the height of the given image. | |
3559 * | |
3560 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3561 * @param image The image of interest. | |
3562 * @return The height. | |
3563 * @ingroup Images | |
3564 **/ | |
3565 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageHeight( | |
3566 OrthancPluginContext* context, | |
3567 const OrthancPluginImage* image) | |
3568 { | |
3569 uint32_t height; | |
3570 | |
3571 _OrthancPluginGetImageInfo params; | |
3572 memset(¶ms, 0, sizeof(params)); | |
3573 params.image = image; | |
3574 params.resultUint32 = &height; | |
3575 | |
3576 if (context->InvokeService(context, _OrthancPluginService_GetImageHeight, ¶ms) != OrthancPluginErrorCode_Success) | |
3577 { | |
3578 return 0; | |
3579 } | |
3580 else | |
3581 { | |
3582 return height; | |
3583 } | |
3584 } | |
3585 | |
3586 | |
3587 | |
3588 /** | |
3589 * @brief Return the pitch of an image. | |
3590 * | |
3591 * This function returns the pitch of the given image. The pitch is | |
3592 * defined as the number of bytes between 2 successive lines of the | |
3593 * image in the memory buffer. | |
3594 * | |
3595 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3596 * @param image The image of interest. | |
3597 * @return The pitch. | |
3598 * @ingroup Images | |
3599 **/ | |
3600 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImagePitch( | |
3601 OrthancPluginContext* context, | |
3602 const OrthancPluginImage* image) | |
3603 { | |
3604 uint32_t pitch; | |
3605 | |
3606 _OrthancPluginGetImageInfo params; | |
3607 memset(¶ms, 0, sizeof(params)); | |
3608 params.image = image; | |
3609 params.resultUint32 = &pitch; | |
3610 | |
3611 if (context->InvokeService(context, _OrthancPluginService_GetImagePitch, ¶ms) != OrthancPluginErrorCode_Success) | |
3612 { | |
3613 return 0; | |
3614 } | |
3615 else | |
3616 { | |
3617 return pitch; | |
3618 } | |
3619 } | |
3620 | |
3621 | |
3622 | |
3623 /** | |
3624 * @brief Return a pointer to the content of an image. | |
3625 * | |
3626 * This function returns a pointer to the memory buffer that | |
3627 * contains the pixels of the image. | |
3628 * | |
3629 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3630 * @param image The image of interest. | |
3631 * @return The pointer. | |
3632 * @ingroup Images | |
3633 **/ | |
3634 ORTHANC_PLUGIN_INLINE void* OrthancPluginGetImageBuffer( | |
3635 OrthancPluginContext* context, | |
3636 const OrthancPluginImage* image) | |
3637 { | |
3638 void* target = NULL; | |
3639 | |
3640 _OrthancPluginGetImageInfo params; | |
3641 memset(¶ms, 0, sizeof(params)); | |
3642 params.resultBuffer = ⌖ | |
3643 params.image = image; | |
3644 | |
3645 if (context->InvokeService(context, _OrthancPluginService_GetImageBuffer, ¶ms) != OrthancPluginErrorCode_Success) | |
3646 { | |
3647 return NULL; | |
3648 } | |
3649 else | |
3650 { | |
3651 return target; | |
3652 } | |
3653 } | |
3654 | |
3655 | |
3656 typedef struct | |
3657 { | |
3658 OrthancPluginImage** target; | |
3659 const void* data; | |
3660 uint32_t size; | |
3661 OrthancPluginImageFormat format; | |
3662 } _OrthancPluginUncompressImage; | |
3663 | |
3664 | |
3665 /** | |
3666 * @brief Decode a compressed image. | |
3667 * | |
3668 * This function decodes a compressed image from a memory buffer. | |
3669 * | |
3670 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3671 * @param data Pointer to a memory buffer containing the compressed image. | |
3672 * @param size Size of the memory buffer containing the compressed image. | |
3673 * @param format The file format of the compressed image. | |
3674 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage(). | |
3675 * @ingroup Images | |
3676 **/ | |
3677 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginUncompressImage( | |
3678 OrthancPluginContext* context, | |
3679 const void* data, | |
3680 uint32_t size, | |
3681 OrthancPluginImageFormat format) | |
3682 { | |
3683 OrthancPluginImage* target = NULL; | |
3684 | |
3685 _OrthancPluginUncompressImage params; | |
3686 memset(¶ms, 0, sizeof(params)); | |
3687 params.target = ⌖ | |
3688 params.data = data; | |
3689 params.size = size; | |
3690 params.format = format; | |
3691 | |
3692 if (context->InvokeService(context, _OrthancPluginService_UncompressImage, ¶ms) != OrthancPluginErrorCode_Success) | |
3693 { | |
3694 return NULL; | |
3695 } | |
3696 else | |
3697 { | |
3698 return target; | |
3699 } | |
3700 } | |
3701 | |
3702 | |
3703 | |
3704 | |
3705 typedef struct | |
3706 { | |
3707 OrthancPluginImage* image; | |
3708 } _OrthancPluginFreeImage; | |
3709 | |
3710 /** | |
3711 * @brief Free an image. | |
3712 * | |
3713 * This function frees an image that was decoded with OrthancPluginUncompressImage(). | |
3714 * | |
3715 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3716 * @param image The image. | |
3717 * @ingroup Images | |
3718 **/ | |
3719 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeImage( | |
3720 OrthancPluginContext* context, | |
3721 OrthancPluginImage* image) | |
3722 { | |
3723 _OrthancPluginFreeImage params; | |
3724 params.image = image; | |
3725 | |
3726 context->InvokeService(context, _OrthancPluginService_FreeImage, ¶ms); | |
3727 } | |
3728 | |
3729 | |
3730 | |
3731 | |
3732 typedef struct | |
3733 { | |
3734 OrthancPluginMemoryBuffer* target; | |
3735 OrthancPluginImageFormat imageFormat; | |
3736 OrthancPluginPixelFormat pixelFormat; | |
3737 uint32_t width; | |
3738 uint32_t height; | |
3739 uint32_t pitch; | |
3740 const void* buffer; | |
3741 uint8_t quality; | |
3742 } _OrthancPluginCompressImage; | |
3743 | |
3744 | |
3745 /** | |
3746 * @brief Encode a PNG image. | |
3747 * | |
3748 * This function compresses the given memory buffer containing an | |
3749 * image using the PNG specification, and stores the result of the | |
3750 * compression into a newly allocated memory buffer. | |
3751 * | |
3752 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3753 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3754 * @param format The memory layout of the uncompressed image. | |
3755 * @param width The width of the image. | |
3756 * @param height The height of the image. | |
3757 * @param pitch The pitch of the image (i.e. the number of bytes | |
3758 * between 2 successive lines of the image in the memory buffer). | |
3759 * @param buffer The memory buffer containing the uncompressed image. | |
3760 * @return 0 if success, or the error code if failure. | |
3761 * @see OrthancPluginCompressAndAnswerPngImage() | |
3762 * @ingroup Images | |
3763 **/ | |
3764 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressPngImage( | |
3765 OrthancPluginContext* context, | |
3766 OrthancPluginMemoryBuffer* target, | |
3767 OrthancPluginPixelFormat format, | |
3768 uint32_t width, | |
3769 uint32_t height, | |
3770 uint32_t pitch, | |
3771 const void* buffer) | |
3772 { | |
3773 _OrthancPluginCompressImage params; | |
3774 memset(¶ms, 0, sizeof(params)); | |
3775 params.target = target; | |
3776 params.imageFormat = OrthancPluginImageFormat_Png; | |
3777 params.pixelFormat = format; | |
3778 params.width = width; | |
3779 params.height = height; | |
3780 params.pitch = pitch; | |
3781 params.buffer = buffer; | |
3782 params.quality = 0; /* Unused for PNG */ | |
3783 | |
3784 return context->InvokeService(context, _OrthancPluginService_CompressImage, ¶ms); | |
3785 } | |
3786 | |
3787 | |
3788 /** | |
3789 * @brief Encode a JPEG image. | |
3790 * | |
3791 * This function compresses the given memory buffer containing an | |
3792 * image using the JPEG specification, and stores the result of the | |
3793 * compression into a newly allocated memory buffer. | |
3794 * | |
3795 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3796 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3797 * @param format The memory layout of the uncompressed image. | |
3798 * @param width The width of the image. | |
3799 * @param height The height of the image. | |
3800 * @param pitch The pitch of the image (i.e. the number of bytes | |
3801 * between 2 successive lines of the image in the memory buffer). | |
3802 * @param buffer The memory buffer containing the uncompressed image. | |
3803 * @param quality The quality of the JPEG encoding, between 1 (worst | |
3804 * quality, best compression) and 100 (best quality, worst | |
3805 * compression). | |
3806 * @return 0 if success, or the error code if failure. | |
3807 * @ingroup Images | |
3808 **/ | |
3809 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressJpegImage( | |
3810 OrthancPluginContext* context, | |
3811 OrthancPluginMemoryBuffer* target, | |
3812 OrthancPluginPixelFormat format, | |
3813 uint32_t width, | |
3814 uint32_t height, | |
3815 uint32_t pitch, | |
3816 const void* buffer, | |
3817 uint8_t quality) | |
3818 { | |
3819 _OrthancPluginCompressImage params; | |
3820 memset(¶ms, 0, sizeof(params)); | |
3821 params.target = target; | |
3822 params.imageFormat = OrthancPluginImageFormat_Jpeg; | |
3823 params.pixelFormat = format; | |
3824 params.width = width; | |
3825 params.height = height; | |
3826 params.pitch = pitch; | |
3827 params.buffer = buffer; | |
3828 params.quality = quality; | |
3829 | |
3830 return context->InvokeService(context, _OrthancPluginService_CompressImage, ¶ms); | |
3831 } | |
3832 | |
3833 | |
3834 | |
3835 /** | |
3836 * @brief Answer to a REST request with a JPEG image. | |
3837 * | |
3838 * This function answers to a REST request with a JPEG image. The | |
3839 * parameters of this function describe a memory buffer that | |
3840 * contains an uncompressed image. The image will be automatically compressed | |
3841 * as a JPEG image by the core system of Orthanc. | |
3842 * | |
3843 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3844 * @param output The HTTP connection to the client application. | |
3845 * @param format The memory layout of the uncompressed image. | |
3846 * @param width The width of the image. | |
3847 * @param height The height of the image. | |
3848 * @param pitch The pitch of the image (i.e. the number of bytes | |
3849 * between 2 successive lines of the image in the memory buffer). | |
3850 * @param buffer The memory buffer containing the uncompressed image. | |
3851 * @param quality The quality of the JPEG encoding, between 1 (worst | |
3852 * quality, best compression) and 100 (best quality, worst | |
3853 * compression). | |
3854 * @ingroup REST | |
3855 **/ | |
3856 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerJpegImage( | |
3857 OrthancPluginContext* context, | |
3858 OrthancPluginRestOutput* output, | |
3859 OrthancPluginPixelFormat format, | |
3860 uint32_t width, | |
3861 uint32_t height, | |
3862 uint32_t pitch, | |
3863 const void* buffer, | |
3864 uint8_t quality) | |
3865 { | |
3866 _OrthancPluginCompressAndAnswerImage params; | |
3867 params.output = output; | |
3868 params.imageFormat = OrthancPluginImageFormat_Jpeg; | |
3869 params.pixelFormat = format; | |
3870 params.width = width; | |
3871 params.height = height; | |
3872 params.pitch = pitch; | |
3873 params.buffer = buffer; | |
3874 params.quality = quality; | |
3875 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, ¶ms); | |
3876 } | |
3877 | |
3878 | |
3879 | |
3880 | |
3881 typedef struct | |
3882 { | |
3883 OrthancPluginMemoryBuffer* target; | |
3884 OrthancPluginHttpMethod method; | |
3885 const char* url; | |
3886 const char* username; | |
3887 const char* password; | |
3888 const char* body; | |
3889 uint32_t bodySize; | |
3890 } _OrthancPluginCallHttpClient; | |
3891 | |
3892 | |
3893 /** | |
3894 * @brief Issue a HTTP GET call. | |
3895 * | |
3896 * Make a HTTP GET call to the given URL. The result to the query is | |
3897 * stored into a newly allocated memory buffer. Favor | |
3898 * OrthancPluginRestApiGet() if calling the built-in REST API of the | |
3899 * Orthanc instance that hosts this plugin. | |
3900 * | |
3901 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3902 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3903 * @param url The URL of interest. | |
3904 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
3905 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
3906 * @return 0 if success, or the error code if failure. | |
3907 **/ | |
3908 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpGet( | |
3909 OrthancPluginContext* context, | |
3910 OrthancPluginMemoryBuffer* target, | |
3911 const char* url, | |
3912 const char* username, | |
3913 const char* password) | |
3914 { | |
3915 _OrthancPluginCallHttpClient params; | |
3916 memset(¶ms, 0, sizeof(params)); | |
3917 | |
3918 params.target = target; | |
3919 params.method = OrthancPluginHttpMethod_Get; | |
3920 params.url = url; | |
3921 params.username = username; | |
3922 params.password = password; | |
3923 | |
3924 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
3925 } | |
3926 | |
3927 | |
3928 /** | |
3929 * @brief Issue a HTTP POST call. | |
3930 * | |
3931 * Make a HTTP POST call to the given URL. The result to the query | |
3932 * is stored into a newly allocated memory buffer. Favor | |
3933 * OrthancPluginRestApiPost() if calling the built-in REST API of | |
3934 * the Orthanc instance that hosts this plugin. | |
3935 * | |
3936 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3937 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3938 * @param url The URL of interest. | |
3939 * @param body The content of the body of the request. | |
3940 * @param bodySize The size of the body of the request. | |
3941 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
3942 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
3943 * @return 0 if success, or the error code if failure. | |
3944 **/ | |
3945 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPost( | |
3946 OrthancPluginContext* context, | |
3947 OrthancPluginMemoryBuffer* target, | |
3948 const char* url, | |
3949 const char* body, | |
3950 uint32_t bodySize, | |
3951 const char* username, | |
3952 const char* password) | |
3953 { | |
3954 _OrthancPluginCallHttpClient params; | |
3955 memset(¶ms, 0, sizeof(params)); | |
3956 | |
3957 params.target = target; | |
3958 params.method = OrthancPluginHttpMethod_Post; | |
3959 params.url = url; | |
3960 params.body = body; | |
3961 params.bodySize = bodySize; | |
3962 params.username = username; | |
3963 params.password = password; | |
3964 | |
3965 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
3966 } | |
3967 | |
3968 | |
3969 /** | |
3970 * @brief Issue a HTTP PUT call. | |
3971 * | |
3972 * Make a HTTP PUT call to the given URL. The result to the query is | |
3973 * stored into a newly allocated memory buffer. Favor | |
3974 * OrthancPluginRestApiPut() if calling the built-in REST API of the | |
3975 * Orthanc instance that hosts this plugin. | |
3976 * | |
3977 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3978 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3979 * @param url The URL of interest. | |
3980 * @param body The content of the body of the request. | |
3981 * @param bodySize The size of the body of the request. | |
3982 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
3983 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
3984 * @return 0 if success, or the error code if failure. | |
3985 **/ | |
3986 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPut( | |
3987 OrthancPluginContext* context, | |
3988 OrthancPluginMemoryBuffer* target, | |
3989 const char* url, | |
3990 const char* body, | |
3991 uint32_t bodySize, | |
3992 const char* username, | |
3993 const char* password) | |
3994 { | |
3995 _OrthancPluginCallHttpClient params; | |
3996 memset(¶ms, 0, sizeof(params)); | |
3997 | |
3998 params.target = target; | |
3999 params.method = OrthancPluginHttpMethod_Put; | |
4000 params.url = url; | |
4001 params.body = body; | |
4002 params.bodySize = bodySize; | |
4003 params.username = username; | |
4004 params.password = password; | |
4005 | |
4006 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
4007 } | |
4008 | |
4009 | |
4010 /** | |
4011 * @brief Issue a HTTP DELETE call. | |
4012 * | |
4013 * Make a HTTP DELETE call to the given URL. Favor | |
4014 * OrthancPluginRestApiDelete() if calling the built-in REST API of | |
4015 * the Orthanc instance that hosts this plugin. | |
4016 * | |
4017 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4018 * @param url The URL of interest. | |
4019 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
4020 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
4021 * @return 0 if success, or the error code if failure. | |
4022 **/ | |
4023 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpDelete( | |
4024 OrthancPluginContext* context, | |
4025 const char* url, | |
4026 const char* username, | |
4027 const char* password) | |
4028 { | |
4029 _OrthancPluginCallHttpClient params; | |
4030 memset(¶ms, 0, sizeof(params)); | |
4031 | |
4032 params.method = OrthancPluginHttpMethod_Delete; | |
4033 params.url = url; | |
4034 params.username = username; | |
4035 params.password = password; | |
4036 | |
4037 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
4038 } | |
4039 | |
4040 | |
4041 | |
4042 typedef struct | |
4043 { | |
4044 OrthancPluginImage** target; | |
4045 const OrthancPluginImage* source; | |
4046 OrthancPluginPixelFormat targetFormat; | |
4047 } _OrthancPluginConvertPixelFormat; | |
4048 | |
4049 | |
4050 /** | |
4051 * @brief Change the pixel format of an image. | |
4052 * | |
4053 * This function creates a new image, changing the memory layout of the pixels. | |
4054 * | |
4055 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4056 * @param source The source image. | |
4057 * @param targetFormat The target pixel format. | |
4058 * @return The resulting image. It must be freed with OrthancPluginFreeImage(). | |
4059 * @ingroup Images | |
4060 **/ | |
4061 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginConvertPixelFormat( | |
4062 OrthancPluginContext* context, | |
4063 const OrthancPluginImage* source, | |
4064 OrthancPluginPixelFormat targetFormat) | |
4065 { | |
4066 OrthancPluginImage* target = NULL; | |
4067 | |
4068 _OrthancPluginConvertPixelFormat params; | |
4069 params.target = ⌖ | |
4070 params.source = source; | |
4071 params.targetFormat = targetFormat; | |
4072 | |
4073 if (context->InvokeService(context, _OrthancPluginService_ConvertPixelFormat, ¶ms) != OrthancPluginErrorCode_Success) | |
4074 { | |
4075 return NULL; | |
4076 } | |
4077 else | |
4078 { | |
4079 return target; | |
4080 } | |
4081 } | |
4082 | |
4083 | |
4084 | |
4085 /** | |
4086 * @brief Return the number of available fonts. | |
4087 * | |
4088 * This function returns the number of fonts that are built in the | |
4089 * Orthanc core. These fonts can be used to draw texts on images | |
4090 * through OrthancPluginDrawText(). | |
4091 * | |
4092 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4093 * @return The number of fonts. | |
4094 * @ingroup Images | |
4095 **/ | |
4096 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontsCount( | |
4097 OrthancPluginContext* context) | |
4098 { | |
4099 uint32_t count = 0; | |
4100 | |
4101 _OrthancPluginReturnSingleValue params; | |
4102 memset(¶ms, 0, sizeof(params)); | |
4103 params.resultUint32 = &count; | |
4104 | |
4105 if (context->InvokeService(context, _OrthancPluginService_GetFontsCount, ¶ms) != OrthancPluginErrorCode_Success) | |
4106 { | |
4107 /* Error */ | |
4108 return 0; | |
4109 } | |
4110 else | |
4111 { | |
4112 return count; | |
4113 } | |
4114 } | |
4115 | |
4116 | |
4117 | |
4118 | |
4119 typedef struct | |
4120 { | |
4121 uint32_t fontIndex; /* in */ | |
4122 const char** name; /* out */ | |
4123 uint32_t* size; /* out */ | |
4124 } _OrthancPluginGetFontInfo; | |
4125 | |
4126 /** | |
4127 * @brief Return the name of a font. | |
4128 * | |
4129 * This function returns the name of a font that is built in the Orthanc core. | |
4130 * | |
4131 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4132 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). | |
4133 * @return The font name. This is a statically-allocated string, do not free it. | |
4134 * @ingroup Images | |
4135 **/ | |
4136 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetFontName( | |
4137 OrthancPluginContext* context, | |
4138 uint32_t fontIndex) | |
4139 { | |
4140 const char* result = NULL; | |
4141 | |
4142 _OrthancPluginGetFontInfo params; | |
4143 memset(¶ms, 0, sizeof(params)); | |
4144 params.name = &result; | |
4145 params.fontIndex = fontIndex; | |
4146 | |
4147 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, ¶ms) != OrthancPluginErrorCode_Success) | |
4148 { | |
4149 return NULL; | |
4150 } | |
4151 else | |
4152 { | |
4153 return result; | |
4154 } | |
4155 } | |
4156 | |
4157 | |
4158 /** | |
4159 * @brief Return the size of a font. | |
4160 * | |
4161 * This function returns the size of a font that is built in the Orthanc core. | |
4162 * | |
4163 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4164 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). | |
4165 * @return The font size. | |
4166 * @ingroup Images | |
4167 **/ | |
4168 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontSize( | |
4169 OrthancPluginContext* context, | |
4170 uint32_t fontIndex) | |
4171 { | |
4172 uint32_t result; | |
4173 | |
4174 _OrthancPluginGetFontInfo params; | |
4175 memset(¶ms, 0, sizeof(params)); | |
4176 params.size = &result; | |
4177 params.fontIndex = fontIndex; | |
4178 | |
4179 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, ¶ms) != OrthancPluginErrorCode_Success) | |
4180 { | |
4181 return 0; | |
4182 } | |
4183 else | |
4184 { | |
4185 return result; | |
4186 } | |
4187 } | |
4188 | |
4189 | |
4190 | |
4191 typedef struct | |
4192 { | |
4193 OrthancPluginImage* image; | |
4194 uint32_t fontIndex; | |
4195 const char* utf8Text; | |
4196 int32_t x; | |
4197 int32_t y; | |
4198 uint8_t r; | |
4199 uint8_t g; | |
4200 uint8_t b; | |
4201 } _OrthancPluginDrawText; | |
4202 | |
4203 | |
4204 /** | |
4205 * @brief Draw text on an image. | |
4206 * | |
4207 * This function draws some text on some image. | |
4208 * | |
4209 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4210 * @param image The image upon which to draw the text. | |
4211 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). | |
4212 * @param utf8Text The text to be drawn, encoded as an UTF-8 zero-terminated string. | |
4213 * @param x The X position of the text over the image. | |
4214 * @param y The Y position of the text over the image. | |
4215 * @param r The value of the red color channel of the text. | |
4216 * @param g The value of the green color channel of the text. | |
4217 * @param b The value of the blue color channel of the text. | |
4218 * @return 0 if success, other value if error. | |
4219 * @ingroup Images | |
4220 **/ | |
4221 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginDrawText( | |
4222 OrthancPluginContext* context, | |
4223 OrthancPluginImage* image, | |
4224 uint32_t fontIndex, | |
4225 const char* utf8Text, | |
4226 int32_t x, | |
4227 int32_t y, | |
4228 uint8_t r, | |
4229 uint8_t g, | |
4230 uint8_t b) | |
4231 { | |
4232 _OrthancPluginDrawText params; | |
4233 memset(¶ms, 0, sizeof(params)); | |
4234 params.image = image; | |
4235 params.fontIndex = fontIndex; | |
4236 params.utf8Text = utf8Text; | |
4237 params.x = x; | |
4238 params.y = y; | |
4239 params.r = r; | |
4240 params.g = g; | |
4241 params.b = b; | |
4242 | |
4243 return context->InvokeService(context, _OrthancPluginService_DrawText, ¶ms); | |
4244 } | |
4245 | |
4246 | |
4247 | |
4248 typedef struct | |
4249 { | |
4250 OrthancPluginStorageArea* storageArea; | |
4251 const char* uuid; | |
4252 const void* content; | |
4253 uint64_t size; | |
4254 OrthancPluginContentType type; | |
4255 } _OrthancPluginStorageAreaCreate; | |
4256 | |
4257 | |
4258 /** | |
4259 * @brief Create a file inside the storage area. | |
4260 * | |
4261 * This function creates a new file inside the storage area that is | |
4262 * currently used by Orthanc. | |
4263 * | |
4264 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4265 * @param storageArea The storage area. | |
4266 * @param uuid The identifier of the file to be created. | |
4267 * @param content The content to store in the newly created file. | |
4268 * @param size The size of the content. | |
4269 * @param type The type of the file content. | |
4270 * @return 0 if success, other value if error. | |
4271 * @ingroup Callbacks | |
4272 **/ | |
4273 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaCreate( | |
4274 OrthancPluginContext* context, | |
4275 OrthancPluginStorageArea* storageArea, | |
4276 const char* uuid, | |
4277 const void* content, | |
4278 uint64_t size, | |
4279 OrthancPluginContentType type) | |
4280 { | |
4281 _OrthancPluginStorageAreaCreate params; | |
4282 params.storageArea = storageArea; | |
4283 params.uuid = uuid; | |
4284 params.content = content; | |
4285 params.size = size; | |
4286 params.type = type; | |
4287 | |
4288 return context->InvokeService(context, _OrthancPluginService_StorageAreaCreate, ¶ms); | |
4289 } | |
4290 | |
4291 | |
4292 typedef struct | |
4293 { | |
4294 OrthancPluginMemoryBuffer* target; | |
4295 OrthancPluginStorageArea* storageArea; | |
4296 const char* uuid; | |
4297 OrthancPluginContentType type; | |
4298 } _OrthancPluginStorageAreaRead; | |
4299 | |
4300 | |
4301 /** | |
4302 * @brief Read a file from the storage area. | |
4303 * | |
4304 * This function reads the content of a given file from the storage | |
4305 * area that is currently used by Orthanc. | |
4306 * | |
4307 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4308 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4309 * @param storageArea The storage area. | |
4310 * @param uuid The identifier of the file to be read. | |
4311 * @param type The type of the file content. | |
4312 * @return 0 if success, other value if error. | |
4313 * @ingroup Callbacks | |
4314 **/ | |
4315 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRead( | |
4316 OrthancPluginContext* context, | |
4317 OrthancPluginMemoryBuffer* target, | |
4318 OrthancPluginStorageArea* storageArea, | |
4319 const char* uuid, | |
4320 OrthancPluginContentType type) | |
4321 { | |
4322 _OrthancPluginStorageAreaRead params; | |
4323 params.target = target; | |
4324 params.storageArea = storageArea; | |
4325 params.uuid = uuid; | |
4326 params.type = type; | |
4327 | |
4328 return context->InvokeService(context, _OrthancPluginService_StorageAreaRead, ¶ms); | |
4329 } | |
4330 | |
4331 | |
4332 typedef struct | |
4333 { | |
4334 OrthancPluginStorageArea* storageArea; | |
4335 const char* uuid; | |
4336 OrthancPluginContentType type; | |
4337 } _OrthancPluginStorageAreaRemove; | |
4338 | |
4339 /** | |
4340 * @brief Remove a file from the storage area. | |
4341 * | |
4342 * This function removes a given file from the storage area that is | |
4343 * currently used by Orthanc. | |
4344 * | |
4345 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4346 * @param storageArea The storage area. | |
4347 * @param uuid The identifier of the file to be removed. | |
4348 * @param type The type of the file content. | |
4349 * @return 0 if success, other value if error. | |
4350 * @ingroup Callbacks | |
4351 **/ | |
4352 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRemove( | |
4353 OrthancPluginContext* context, | |
4354 OrthancPluginStorageArea* storageArea, | |
4355 const char* uuid, | |
4356 OrthancPluginContentType type) | |
4357 { | |
4358 _OrthancPluginStorageAreaRemove params; | |
4359 params.storageArea = storageArea; | |
4360 params.uuid = uuid; | |
4361 params.type = type; | |
4362 | |
4363 return context->InvokeService(context, _OrthancPluginService_StorageAreaRemove, ¶ms); | |
4364 } | |
4365 | |
4366 | |
4367 | |
4368 typedef struct | |
4369 { | |
4370 OrthancPluginErrorCode* target; | |
4371 int32_t code; | |
4372 uint16_t httpStatus; | |
4373 const char* message; | |
4374 } _OrthancPluginRegisterErrorCode; | |
4375 | |
4376 /** | |
4377 * @brief Declare a custom error code for this plugin. | |
4378 * | |
4379 * This function declares a custom error code that can be generated | |
4380 * by this plugin. This declaration is used to enrich the body of | |
4381 * the HTTP answer in the case of an error, and to set the proper | |
4382 * HTTP status code. | |
4383 * | |
4384 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4385 * @param code The error code that is internal to this plugin. | |
4386 * @param httpStatus The HTTP status corresponding to this error. | |
4387 * @param message The description of the error. | |
4388 * @return The error code that has been assigned inside the Orthanc core. | |
4389 * @ingroup Toolbox | |
4390 **/ | |
4391 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterErrorCode( | |
4392 OrthancPluginContext* context, | |
4393 int32_t code, | |
4394 uint16_t httpStatus, | |
4395 const char* message) | |
4396 { | |
4397 OrthancPluginErrorCode target; | |
4398 | |
4399 _OrthancPluginRegisterErrorCode params; | |
4400 params.target = ⌖ | |
4401 params.code = code; | |
4402 params.httpStatus = httpStatus; | |
4403 params.message = message; | |
4404 | |
4405 if (context->InvokeService(context, _OrthancPluginService_RegisterErrorCode, ¶ms) == OrthancPluginErrorCode_Success) | |
4406 { | |
4407 return target; | |
4408 } | |
4409 else | |
4410 { | |
4411 /* There was an error while assigned the error. Use a generic code. */ | |
4412 return OrthancPluginErrorCode_Plugin; | |
4413 } | |
4414 } | |
4415 | |
4416 | |
4417 | |
4418 typedef struct | |
4419 { | |
4420 uint16_t group; | |
4421 uint16_t element; | |
4422 OrthancPluginValueRepresentation vr; | |
4423 const char* name; | |
4424 uint32_t minMultiplicity; | |
4425 uint32_t maxMultiplicity; | |
4426 } _OrthancPluginRegisterDictionaryTag; | |
4427 | |
4428 /** | |
4429 * @brief Register a new tag into the DICOM dictionary. | |
4430 * | |
4431 * This function declares a new public tag in the dictionary of | |
4432 * DICOM tags that are known to Orthanc. This function should be | |
4433 * used in the OrthancPluginInitialize() callback. | |
4434 * | |
4435 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4436 * @param group The group of the tag. | |
4437 * @param element The element of the tag. | |
4438 * @param vr The value representation of the tag. | |
4439 * @param name The nickname of the tag. | |
4440 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0). | |
4441 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means | |
4442 * an arbitrary multiplicity ("<tt>n</tt>"). | |
4443 * @return 0 if success, other value if error. | |
4444 * @see OrthancPluginRegisterPrivateDictionaryTag() | |
4445 * @ingroup Toolbox | |
4446 **/ | |
4447 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDictionaryTag( | |
4448 OrthancPluginContext* context, | |
4449 uint16_t group, | |
4450 uint16_t element, | |
4451 OrthancPluginValueRepresentation vr, | |
4452 const char* name, | |
4453 uint32_t minMultiplicity, | |
4454 uint32_t maxMultiplicity) | |
4455 { | |
4456 _OrthancPluginRegisterDictionaryTag params; | |
4457 params.group = group; | |
4458 params.element = element; | |
4459 params.vr = vr; | |
4460 params.name = name; | |
4461 params.minMultiplicity = minMultiplicity; | |
4462 params.maxMultiplicity = maxMultiplicity; | |
4463 | |
4464 return context->InvokeService(context, _OrthancPluginService_RegisterDictionaryTag, ¶ms); | |
4465 } | |
4466 | |
4467 | |
4468 | |
4469 typedef struct | |
4470 { | |
4471 uint16_t group; | |
4472 uint16_t element; | |
4473 OrthancPluginValueRepresentation vr; | |
4474 const char* name; | |
4475 uint32_t minMultiplicity; | |
4476 uint32_t maxMultiplicity; | |
4477 const char* privateCreator; | |
4478 } _OrthancPluginRegisterPrivateDictionaryTag; | |
4479 | |
4480 /** | |
4481 * @brief Register a new private tag into the DICOM dictionary. | |
4482 * | |
4483 * This function declares a new private tag in the dictionary of | |
4484 * DICOM tags that are known to Orthanc. This function should be | |
4485 * used in the OrthancPluginInitialize() callback. | |
4486 * | |
4487 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4488 * @param group The group of the tag. | |
4489 * @param element The element of the tag. | |
4490 * @param vr The value representation of the tag. | |
4491 * @param name The nickname of the tag. | |
4492 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0). | |
4493 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means | |
4494 * an arbitrary multiplicity ("<tt>n</tt>"). | |
4495 * @param privateCreator The private creator of this private tag. | |
4496 * @return 0 if success, other value if error. | |
4497 * @see OrthancPluginRegisterDictionaryTag() | |
4498 * @ingroup Toolbox | |
4499 **/ | |
4500 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterPrivateDictionaryTag( | |
4501 OrthancPluginContext* context, | |
4502 uint16_t group, | |
4503 uint16_t element, | |
4504 OrthancPluginValueRepresentation vr, | |
4505 const char* name, | |
4506 uint32_t minMultiplicity, | |
4507 uint32_t maxMultiplicity, | |
4508 const char* privateCreator) | |
4509 { | |
4510 _OrthancPluginRegisterPrivateDictionaryTag params; | |
4511 params.group = group; | |
4512 params.element = element; | |
4513 params.vr = vr; | |
4514 params.name = name; | |
4515 params.minMultiplicity = minMultiplicity; | |
4516 params.maxMultiplicity = maxMultiplicity; | |
4517 params.privateCreator = privateCreator; | |
4518 | |
4519 return context->InvokeService(context, _OrthancPluginService_RegisterPrivateDictionaryTag, ¶ms); | |
4520 } | |
4521 | |
4522 | |
4523 | |
4524 typedef struct | |
4525 { | |
4526 OrthancPluginStorageArea* storageArea; | |
4527 OrthancPluginResourceType level; | |
4528 } _OrthancPluginReconstructMainDicomTags; | |
4529 | |
4530 /** | |
4531 * @brief Reconstruct the main DICOM tags. | |
4532 * | |
4533 * This function requests the Orthanc core to reconstruct the main | |
4534 * DICOM tags of all the resources of the given type. This function | |
4535 * can only be used as a part of the upgrade of a custom database | |
4536 * back-end. A database transaction will be automatically setup. | |
4537 * | |
4538 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4539 * @param storageArea The storage area. | |
4540 * @param level The type of the resources of interest. | |
4541 * @return 0 if success, other value if error. | |
4542 * @ingroup Callbacks | |
4543 **/ | |
4544 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReconstructMainDicomTags( | |
4545 OrthancPluginContext* context, | |
4546 OrthancPluginStorageArea* storageArea, | |
4547 OrthancPluginResourceType level) | |
4548 { | |
4549 _OrthancPluginReconstructMainDicomTags params; | |
4550 params.level = level; | |
4551 params.storageArea = storageArea; | |
4552 | |
4553 return context->InvokeService(context, _OrthancPluginService_ReconstructMainDicomTags, ¶ms); | |
4554 } | |
4555 | |
4556 | |
4557 typedef struct | |
4558 { | |
4559 char** result; | |
4560 const char* instanceId; | |
4561 const void* buffer; | |
4562 uint32_t size; | |
4563 OrthancPluginDicomToJsonFormat format; | |
4564 OrthancPluginDicomToJsonFlags flags; | |
4565 uint32_t maxStringLength; | |
4566 } _OrthancPluginDicomToJson; | |
4567 | |
4568 | |
4569 /** | |
4570 * @brief Format a DICOM memory buffer as a JSON string. | |
4571 * | |
4572 * This function takes as input a memory buffer containing a DICOM | |
4573 * file, and outputs a JSON string representing the tags of this | |
4574 * DICOM file. | |
4575 * | |
4576 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4577 * @param buffer The memory buffer containing the DICOM file. | |
4578 * @param size The size of the memory buffer. | |
4579 * @param format The output format. | |
4580 * @param flags Flags governing the output. | |
4581 * @param maxStringLength The maximum length of a field. Too long fields will | |
4582 * be output as "null". The 0 value means no maximum length. | |
4583 * @return The NULL value if the case of an error, or the JSON | |
4584 * string. This string must be freed by OrthancPluginFreeString(). | |
4585 * @ingroup Toolbox | |
4586 * @see OrthancPluginDicomInstanceToJson | |
4587 **/ | |
4588 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomBufferToJson( | |
4589 OrthancPluginContext* context, | |
4590 const void* buffer, | |
4591 uint32_t size, | |
4592 OrthancPluginDicomToJsonFormat format, | |
4593 OrthancPluginDicomToJsonFlags flags, | |
4594 uint32_t maxStringLength) | |
4595 { | |
4596 char* result; | |
4597 | |
4598 _OrthancPluginDicomToJson params; | |
4599 memset(¶ms, 0, sizeof(params)); | |
4600 params.result = &result; | |
4601 params.buffer = buffer; | |
4602 params.size = size; | |
4603 params.format = format; | |
4604 params.flags = flags; | |
4605 params.maxStringLength = maxStringLength; | |
4606 | |
4607 if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, ¶ms) != OrthancPluginErrorCode_Success) | |
4608 { | |
4609 /* Error */ | |
4610 return NULL; | |
4611 } | |
4612 else | |
4613 { | |
4614 return result; | |
4615 } | |
4616 } | |
4617 | |
4618 | |
4619 /** | |
4620 * @brief Format a DICOM instance as a JSON string. | |
4621 * | |
4622 * This function formats a DICOM instance that is stored in Orthanc, | |
4623 * and outputs a JSON string representing the tags of this DICOM | |
4624 * instance. | |
4625 * | |
4626 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4627 * @param instanceId The Orthanc identifier of the instance. | |
4628 * @param format The output format. | |
4629 * @param flags Flags governing the output. | |
4630 * @param maxStringLength The maximum length of a field. Too long fields will | |
4631 * be output as "null". The 0 value means no maximum length. | |
4632 * @return The NULL value if the case of an error, or the JSON | |
4633 * string. This string must be freed by OrthancPluginFreeString(). | |
4634 * @ingroup Toolbox | |
4635 * @see OrthancPluginDicomInstanceToJson | |
4636 **/ | |
4637 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomInstanceToJson( | |
4638 OrthancPluginContext* context, | |
4639 const char* instanceId, | |
4640 OrthancPluginDicomToJsonFormat format, | |
4641 OrthancPluginDicomToJsonFlags flags, | |
4642 uint32_t maxStringLength) | |
4643 { | |
4644 char* result; | |
4645 | |
4646 _OrthancPluginDicomToJson params; | |
4647 memset(¶ms, 0, sizeof(params)); | |
4648 params.result = &result; | |
4649 params.instanceId = instanceId; | |
4650 params.format = format; | |
4651 params.flags = flags; | |
4652 params.maxStringLength = maxStringLength; | |
4653 | |
4654 if (context->InvokeService(context, _OrthancPluginService_DicomInstanceToJson, ¶ms) != OrthancPluginErrorCode_Success) | |
4655 { | |
4656 /* Error */ | |
4657 return NULL; | |
4658 } | |
4659 else | |
4660 { | |
4661 return result; | |
4662 } | |
4663 } | |
4664 | |
4665 | |
4666 typedef struct | |
4667 { | |
4668 OrthancPluginMemoryBuffer* target; | |
4669 const char* uri; | |
4670 uint32_t headersCount; | |
4671 const char* const* headersKeys; | |
4672 const char* const* headersValues; | |
4673 int32_t afterPlugins; | |
4674 } _OrthancPluginRestApiGet2; | |
4675 | |
4676 /** | |
4677 * @brief Make a GET call to the Orthanc REST API, with custom HTTP headers. | |
4678 * | |
4679 * Make a GET call to the Orthanc REST API with extended | |
4680 * parameters. The result to the query is stored into a newly | |
4681 * allocated memory buffer. | |
4682 * | |
4683 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4684 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4685 * @param uri The URI in the built-in Orthanc API. | |
4686 * @param headersCount The number of HTTP headers. | |
4687 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header). | |
4688 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header). | |
4689 * @param afterPlugins If 0, the built-in API of Orthanc is used. | |
4690 * If 1, the API is tainted by the plugins. | |
4691 * @return 0 if success, or the error code if failure. | |
4692 * @see OrthancPluginRestApiGet, OrthancPluginRestApiGetAfterPlugins | |
4693 * @ingroup Orthanc | |
4694 **/ | |
4695 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet2( | |
4696 OrthancPluginContext* context, | |
4697 OrthancPluginMemoryBuffer* target, | |
4698 const char* uri, | |
4699 uint32_t headersCount, | |
4700 const char* const* headersKeys, | |
4701 const char* const* headersValues, | |
4702 int32_t afterPlugins) | |
4703 { | |
4704 _OrthancPluginRestApiGet2 params; | |
4705 params.target = target; | |
4706 params.uri = uri; | |
4707 params.headersCount = headersCount; | |
4708 params.headersKeys = headersKeys; | |
4709 params.headersValues = headersValues; | |
4710 params.afterPlugins = afterPlugins; | |
4711 | |
4712 return context->InvokeService(context, _OrthancPluginService_RestApiGet2, ¶ms); | |
4713 } | |
4714 | |
4715 | |
4716 | |
4717 typedef struct | |
4718 { | |
4719 OrthancPluginWorklistCallback callback; | |
4720 } _OrthancPluginWorklistCallback; | |
4721 | |
4722 /** | |
4723 * @brief Register a callback to handle modality worklists requests. | |
4724 * | |
4725 * This function registers a callback to handle C-Find SCP requests | |
4726 * on modality worklists. | |
4727 * | |
4728 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4729 * @param callback The callback. | |
4730 * @return 0 if success, other value if error. | |
4731 * @ingroup DicomCallbacks | |
4732 **/ | |
4733 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterWorklistCallback( | |
4734 OrthancPluginContext* context, | |
4735 OrthancPluginWorklistCallback callback) | |
4736 { | |
4737 _OrthancPluginWorklistCallback params; | |
4738 params.callback = callback; | |
4739 | |
4740 return context->InvokeService(context, _OrthancPluginService_RegisterWorklistCallback, ¶ms); | |
4741 } | |
4742 | |
4743 | |
4744 | |
4745 typedef struct | |
4746 { | |
4747 OrthancPluginWorklistAnswers* answers; | |
4748 const OrthancPluginWorklistQuery* query; | |
4749 const void* dicom; | |
4750 uint32_t size; | |
4751 } _OrthancPluginWorklistAnswersOperation; | |
4752 | |
4753 /** | |
4754 * @brief Add one answer to some modality worklist request. | |
4755 * | |
4756 * This function adds one worklist (encoded as a DICOM file) to the | |
4757 * set of answers corresponding to some C-Find SCP request against | |
4758 * modality worklists. | |
4759 * | |
4760 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4761 * @param answers The set of answers. | |
4762 * @param query The worklist query, as received by the callback. | |
4763 * @param dicom The worklist to answer, encoded as a DICOM file. | |
4764 * @param size The size of the DICOM file. | |
4765 * @return 0 if success, other value if error. | |
4766 * @ingroup DicomCallbacks | |
4767 * @see OrthancPluginCreateDicom() | |
4768 **/ | |
4769 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistAddAnswer( | |
4770 OrthancPluginContext* context, | |
4771 OrthancPluginWorklistAnswers* answers, | |
4772 const OrthancPluginWorklistQuery* query, | |
4773 const void* dicom, | |
4774 uint32_t size) | |
4775 { | |
4776 _OrthancPluginWorklistAnswersOperation params; | |
4777 params.answers = answers; | |
4778 params.query = query; | |
4779 params.dicom = dicom; | |
4780 params.size = size; | |
4781 | |
4782 return context->InvokeService(context, _OrthancPluginService_WorklistAddAnswer, ¶ms); | |
4783 } | |
4784 | |
4785 | |
4786 /** | |
4787 * @brief Mark the set of worklist answers as incomplete. | |
4788 * | |
4789 * This function marks as incomplete the set of answers | |
4790 * corresponding to some C-Find SCP request against modality | |
4791 * worklists. This must be used if canceling the handling of a | |
4792 * request when too many answers are to be returned. | |
4793 * | |
4794 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4795 * @param answers The set of answers. | |
4796 * @return 0 if success, other value if error. | |
4797 * @ingroup DicomCallbacks | |
4798 **/ | |
4799 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistMarkIncomplete( | |
4800 OrthancPluginContext* context, | |
4801 OrthancPluginWorklistAnswers* answers) | |
4802 { | |
4803 _OrthancPluginWorklistAnswersOperation params; | |
4804 params.answers = answers; | |
4805 params.query = NULL; | |
4806 params.dicom = NULL; | |
4807 params.size = 0; | |
4808 | |
4809 return context->InvokeService(context, _OrthancPluginService_WorklistMarkIncomplete, ¶ms); | |
4810 } | |
4811 | |
4812 | |
4813 typedef struct | |
4814 { | |
4815 const OrthancPluginWorklistQuery* query; | |
4816 const void* dicom; | |
4817 uint32_t size; | |
4818 int32_t* isMatch; | |
4819 OrthancPluginMemoryBuffer* target; | |
4820 } _OrthancPluginWorklistQueryOperation; | |
4821 | |
4822 /** | |
4823 * @brief Test whether a worklist matches the query. | |
4824 * | |
4825 * This function checks whether one worklist (encoded as a DICOM | |
4826 * file) matches the C-Find SCP query against modality | |
4827 * worklists. This function must be called before adding the | |
4828 * worklist as an answer through OrthancPluginWorklistAddAnswer(). | |
4829 * | |
4830 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4831 * @param query The worklist query, as received by the callback. | |
4832 * @param dicom The worklist to answer, encoded as a DICOM file. | |
4833 * @param size The size of the DICOM file. | |
4834 * @return 1 if the worklist matches the query, 0 otherwise. | |
4835 * @ingroup DicomCallbacks | |
4836 **/ | |
4837 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginWorklistIsMatch( | |
4838 OrthancPluginContext* context, | |
4839 const OrthancPluginWorklistQuery* query, | |
4840 const void* dicom, | |
4841 uint32_t size) | |
4842 { | |
4843 int32_t isMatch = 0; | |
4844 | |
4845 _OrthancPluginWorklistQueryOperation params; | |
4846 params.query = query; | |
4847 params.dicom = dicom; | |
4848 params.size = size; | |
4849 params.isMatch = &isMatch; | |
4850 params.target = NULL; | |
4851 | |
4852 if (context->InvokeService(context, _OrthancPluginService_WorklistIsMatch, ¶ms) == OrthancPluginErrorCode_Success) | |
4853 { | |
4854 return isMatch; | |
4855 } | |
4856 else | |
4857 { | |
4858 /* Error: Assume non-match */ | |
4859 return 0; | |
4860 } | |
4861 } | |
4862 | |
4863 | |
4864 /** | |
4865 * @brief Retrieve the worklist query as a DICOM file. | |
4866 * | |
4867 * This function retrieves the DICOM file that underlies a C-Find | |
4868 * SCP query against modality worklists. | |
4869 * | |
4870 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4871 * @param target Memory buffer where to store the DICOM file. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4872 * @param query The worklist query, as received by the callback. | |
4873 * @return 0 if success, other value if error. | |
4874 * @ingroup DicomCallbacks | |
4875 **/ | |
4876 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistGetDicomQuery( | |
4877 OrthancPluginContext* context, | |
4878 OrthancPluginMemoryBuffer* target, | |
4879 const OrthancPluginWorklistQuery* query) | |
4880 { | |
4881 _OrthancPluginWorklistQueryOperation params; | |
4882 params.query = query; | |
4883 params.dicom = NULL; | |
4884 params.size = 0; | |
4885 params.isMatch = NULL; | |
4886 params.target = target; | |
4887 | |
4888 return context->InvokeService(context, _OrthancPluginService_WorklistGetDicomQuery, ¶ms); | |
4889 } | |
4890 | |
4891 | |
4892 /** | |
4893 * @brief Get the origin of a DICOM file. | |
4894 * | |
4895 * This function returns the origin of a DICOM instance that has been received by Orthanc. | |
4896 * | |
4897 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4898 * @param instance The instance of interest. | |
4899 * @return The origin of the instance. | |
4900 * @ingroup Callbacks | |
4901 **/ | |
4902 ORTHANC_PLUGIN_INLINE OrthancPluginInstanceOrigin OrthancPluginGetInstanceOrigin( | |
4903 OrthancPluginContext* context, | |
4904 OrthancPluginDicomInstance* instance) | |
4905 { | |
4906 OrthancPluginInstanceOrigin origin; | |
4907 | |
4908 _OrthancPluginAccessDicomInstance params; | |
4909 memset(¶ms, 0, sizeof(params)); | |
4910 params.resultOrigin = &origin; | |
4911 params.instance = instance; | |
4912 | |
4913 if (context->InvokeService(context, _OrthancPluginService_GetInstanceOrigin, ¶ms) != OrthancPluginErrorCode_Success) | |
4914 { | |
4915 /* Error */ | |
4916 return OrthancPluginInstanceOrigin_Unknown; | |
4917 } | |
4918 else | |
4919 { | |
4920 return origin; | |
4921 } | |
4922 } | |
4923 | |
4924 | |
4925 typedef struct | |
4926 { | |
4927 OrthancPluginMemoryBuffer* target; | |
4928 const char* json; | |
4929 const OrthancPluginImage* pixelData; | |
4930 OrthancPluginCreateDicomFlags flags; | |
4931 } _OrthancPluginCreateDicom; | |
4932 | |
4933 /** | |
4934 * @brief Create a DICOM instance from a JSON string and an image. | |
4935 * | |
4936 * This function takes as input a string containing a JSON file | |
4937 * describing the content of a DICOM instance. As an output, it | |
4938 * writes the corresponding DICOM instance to a newly allocated | |
4939 * memory buffer. Additionally, an image to be encoded within the | |
4940 * DICOM instance can also be provided. | |
4941 * | |
4942 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4943 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4944 * @param json The input JSON file. | |
4945 * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme. | |
4946 * @param flags Flags governing the output. | |
4947 * @return 0 if success, other value if error. | |
4948 * @ingroup Toolbox | |
4949 * @see OrthancPluginDicomBufferToJson | |
4950 **/ | |
4951 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom( | |
4952 OrthancPluginContext* context, | |
4953 OrthancPluginMemoryBuffer* target, | |
4954 const char* json, | |
4955 const OrthancPluginImage* pixelData, | |
4956 OrthancPluginCreateDicomFlags flags) | |
4957 { | |
4958 _OrthancPluginCreateDicom params; | |
4959 params.target = target; | |
4960 params.json = json; | |
4961 params.pixelData = pixelData; | |
4962 params.flags = flags; | |
4963 | |
4964 return context->InvokeService(context, _OrthancPluginService_CreateDicom, ¶ms); | |
4965 } | |
4966 | |
4967 | |
4968 typedef struct | |
4969 { | |
4970 OrthancPluginDecodeImageCallback callback; | |
4971 } _OrthancPluginDecodeImageCallback; | |
4972 | |
4973 /** | |
4974 * @brief Register a callback to handle the decoding of DICOM images. | |
4975 * | |
4976 * This function registers a custom callback to the decoding of | |
4977 * DICOM images, replacing the built-in decoder of Orthanc. | |
4978 * | |
4979 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4980 * @param callback The callback. | |
4981 * @return 0 if success, other value if error. | |
4982 * @ingroup Callbacks | |
4983 **/ | |
4984 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDecodeImageCallback( | |
4985 OrthancPluginContext* context, | |
4986 OrthancPluginDecodeImageCallback callback) | |
4987 { | |
4988 _OrthancPluginDecodeImageCallback params; | |
4989 params.callback = callback; | |
4990 | |
4991 return context->InvokeService(context, _OrthancPluginService_RegisterDecodeImageCallback, ¶ms); | |
4992 } | |
4993 | |
4994 | |
4995 | |
4996 typedef struct | |
4997 { | |
4998 OrthancPluginImage** target; | |
4999 OrthancPluginPixelFormat format; | |
5000 uint32_t width; | |
5001 uint32_t height; | |
5002 uint32_t pitch; | |
5003 void* buffer; | |
5004 const void* constBuffer; | |
5005 uint32_t bufferSize; | |
5006 uint32_t frameIndex; | |
5007 } _OrthancPluginCreateImage; | |
5008 | |
5009 | |
5010 /** | |
5011 * @brief Create an image. | |
5012 * | |
5013 * This function creates an image of given size and format. | |
5014 * | |
5015 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5016 * @param format The format of the pixels. | |
5017 * @param width The width of the image. | |
5018 * @param height The height of the image. | |
5019 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage(). | |
5020 * @ingroup Images | |
5021 **/ | |
5022 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImage( | |
5023 OrthancPluginContext* context, | |
5024 OrthancPluginPixelFormat format, | |
5025 uint32_t width, | |
5026 uint32_t height) | |
5027 { | |
5028 OrthancPluginImage* target = NULL; | |
5029 | |
5030 _OrthancPluginCreateImage params; | |
5031 memset(¶ms, 0, sizeof(params)); | |
5032 params.target = ⌖ | |
5033 params.format = format; | |
5034 params.width = width; | |
5035 params.height = height; | |
5036 | |
5037 if (context->InvokeService(context, _OrthancPluginService_CreateImage, ¶ms) != OrthancPluginErrorCode_Success) | |
5038 { | |
5039 return NULL; | |
5040 } | |
5041 else | |
5042 { | |
5043 return target; | |
5044 } | |
5045 } | |
5046 | |
5047 | |
5048 /** | |
5049 * @brief Create an image pointing to a memory buffer. | |
5050 * | |
5051 * This function creates an image whose content points to a memory | |
5052 * buffer managed by the plugin. Note that the buffer is directly | |
5053 * accessed, no memory is allocated and no data is copied. | |
5054 * | |
5055 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5056 * @param format The format of the pixels. | |
5057 * @param width The width of the image. | |
5058 * @param height The height of the image. | |
5059 * @param pitch The pitch of the image (i.e. the number of bytes | |
5060 * between 2 successive lines of the image in the memory buffer). | |
5061 * @param buffer The memory buffer. | |
5062 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage(). | |
5063 * @ingroup Images | |
5064 **/ | |
5065 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImageAccessor( | |
5066 OrthancPluginContext* context, | |
5067 OrthancPluginPixelFormat format, | |
5068 uint32_t width, | |
5069 uint32_t height, | |
5070 uint32_t pitch, | |
5071 void* buffer) | |
5072 { | |
5073 OrthancPluginImage* target = NULL; | |
5074 | |
5075 _OrthancPluginCreateImage params; | |
5076 memset(¶ms, 0, sizeof(params)); | |
5077 params.target = ⌖ | |
5078 params.format = format; | |
5079 params.width = width; | |
5080 params.height = height; | |
5081 params.pitch = pitch; | |
5082 params.buffer = buffer; | |
5083 | |
5084 if (context->InvokeService(context, _OrthancPluginService_CreateImageAccessor, ¶ms) != OrthancPluginErrorCode_Success) | |
5085 { | |
5086 return NULL; | |
5087 } | |
5088 else | |
5089 { | |
5090 return target; | |
5091 } | |
5092 } | |
5093 | |
5094 | |
5095 | |
5096 /** | |
5097 * @brief Decode one frame from a DICOM instance. | |
5098 * | |
5099 * This function decodes one frame of a DICOM image that is stored | |
5100 * in a memory buffer. This function will give the same result as | |
5101 * OrthancPluginUncompressImage() for single-frame DICOM images. | |
5102 * | |
5103 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5104 * @param buffer Pointer to a memory buffer containing the DICOM image. | |
5105 * @param bufferSize Size of the memory buffer containing the DICOM image. | |
5106 * @param frameIndex The index of the frame of interest in a multi-frame image. | |
5107 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage(). | |
5108 * @ingroup Images | |
5109 **/ | |
5110 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginDecodeDicomImage( | |
5111 OrthancPluginContext* context, | |
5112 const void* buffer, | |
5113 uint32_t bufferSize, | |
5114 uint32_t frameIndex) | |
5115 { | |
5116 OrthancPluginImage* target = NULL; | |
5117 | |
5118 _OrthancPluginCreateImage params; | |
5119 memset(¶ms, 0, sizeof(params)); | |
5120 params.target = ⌖ | |
5121 params.constBuffer = buffer; | |
5122 params.bufferSize = bufferSize; | |
5123 params.frameIndex = frameIndex; | |
5124 | |
5125 if (context->InvokeService(context, _OrthancPluginService_DecodeDicomImage, ¶ms) != OrthancPluginErrorCode_Success) | |
5126 { | |
5127 return NULL; | |
5128 } | |
5129 else | |
5130 { | |
5131 return target; | |
5132 } | |
5133 } | |
5134 | |
5135 | |
5136 | |
5137 typedef struct | |
5138 { | |
5139 char** result; | |
5140 const void* buffer; | |
5141 uint32_t size; | |
5142 } _OrthancPluginComputeHash; | |
5143 | |
5144 /** | |
5145 * @brief Compute an MD5 hash. | |
5146 * | |
5147 * This functions computes the MD5 cryptographic hash of the given memory buffer. | |
5148 * | |
5149 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5150 * @param buffer The source memory buffer. | |
5151 * @param size The size in bytes of the source buffer. | |
5152 * @return The NULL value in case of error, or a string containing the cryptographic hash. | |
5153 * This string must be freed by OrthancPluginFreeString(). | |
5154 * @ingroup Toolbox | |
5155 **/ | |
5156 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeMd5( | |
5157 OrthancPluginContext* context, | |
5158 const void* buffer, | |
5159 uint32_t size) | |
5160 { | |
5161 char* result; | |
5162 | |
5163 _OrthancPluginComputeHash params; | |
5164 params.result = &result; | |
5165 params.buffer = buffer; | |
5166 params.size = size; | |
5167 | |
5168 if (context->InvokeService(context, _OrthancPluginService_ComputeMd5, ¶ms) != OrthancPluginErrorCode_Success) | |
5169 { | |
5170 /* Error */ | |
5171 return NULL; | |
5172 } | |
5173 else | |
5174 { | |
5175 return result; | |
5176 } | |
5177 } | |
5178 | |
5179 | |
5180 /** | |
5181 * @brief Compute a SHA-1 hash. | |
5182 * | |
5183 * This functions computes the SHA-1 cryptographic hash of the given memory buffer. | |
5184 * | |
5185 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5186 * @param buffer The source memory buffer. | |
5187 * @param size The size in bytes of the source buffer. | |
5188 * @return The NULL value in case of error, or a string containing the cryptographic hash. | |
5189 * This string must be freed by OrthancPluginFreeString(). | |
5190 * @ingroup Toolbox | |
5191 **/ | |
5192 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeSha1( | |
5193 OrthancPluginContext* context, | |
5194 const void* buffer, | |
5195 uint32_t size) | |
5196 { | |
5197 char* result; | |
5198 | |
5199 _OrthancPluginComputeHash params; | |
5200 params.result = &result; | |
5201 params.buffer = buffer; | |
5202 params.size = size; | |
5203 | |
5204 if (context->InvokeService(context, _OrthancPluginService_ComputeSha1, ¶ms) != OrthancPluginErrorCode_Success) | |
5205 { | |
5206 /* Error */ | |
5207 return NULL; | |
5208 } | |
5209 else | |
5210 { | |
5211 return result; | |
5212 } | |
5213 } | |
5214 | |
5215 | |
5216 | |
5217 typedef struct | |
5218 { | |
5219 OrthancPluginDictionaryEntry* target; | |
5220 const char* name; | |
5221 } _OrthancPluginLookupDictionary; | |
5222 | |
5223 /** | |
5224 * @brief Get information about the given DICOM tag. | |
5225 * | |
5226 * This functions makes a lookup in the dictionary of DICOM tags | |
5227 * that are known to Orthanc, and returns information about this | |
5228 * tag. The tag can be specified using its human-readable name | |
5229 * (e.g. "PatientName") or a set of two hexadecimal numbers | |
5230 * (e.g. "0010-0020"). | |
5231 * | |
5232 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5233 * @param target Where to store the information about the tag. | |
5234 * @param name The name of the DICOM tag. | |
5235 * @return 0 if success, other value if error. | |
5236 * @ingroup Toolbox | |
5237 **/ | |
5238 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginLookupDictionary( | |
5239 OrthancPluginContext* context, | |
5240 OrthancPluginDictionaryEntry* target, | |
5241 const char* name) | |
5242 { | |
5243 _OrthancPluginLookupDictionary params; | |
5244 params.target = target; | |
5245 params.name = name; | |
5246 return context->InvokeService(context, _OrthancPluginService_LookupDictionary, ¶ms); | |
5247 } | |
5248 | |
5249 | |
5250 | |
5251 typedef struct | |
5252 { | |
5253 OrthancPluginRestOutput* output; | |
5254 const char* answer; | |
5255 uint32_t answerSize; | |
5256 uint32_t headersCount; | |
5257 const char* const* headersKeys; | |
5258 const char* const* headersValues; | |
5259 } _OrthancPluginSendMultipartItem2; | |
5260 | |
5261 /** | |
5262 * @brief Send an item as a part of some HTTP multipart answer, with custom headers. | |
5263 * | |
5264 * This function sends an item as a part of some HTTP multipart | |
5265 * answer that was initiated by OrthancPluginStartMultipartAnswer(). In addition to | |
5266 * OrthancPluginSendMultipartItem(), this function will set HTTP header associated | |
5267 * with the item. | |
5268 * | |
5269 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5270 * @param output The HTTP connection to the client application. | |
5271 * @param answer Pointer to the memory buffer containing the item. | |
5272 * @param answerSize Number of bytes of the item. | |
5273 * @param headersCount The number of HTTP headers. | |
5274 * @param headersKeys Array containing the keys of the HTTP headers. | |
5275 * @param headersValues Array containing the values of the HTTP headers. | |
5276 * @return 0 if success, or the error code if failure (this notably happens | |
5277 * if the connection is closed by the client). | |
5278 * @see OrthancPluginSendMultipartItem() | |
5279 * @ingroup REST | |
5280 **/ | |
5281 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem2( | |
5282 OrthancPluginContext* context, | |
5283 OrthancPluginRestOutput* output, | |
5284 const char* answer, | |
5285 uint32_t answerSize, | |
5286 uint32_t headersCount, | |
5287 const char* const* headersKeys, | |
5288 const char* const* headersValues) | |
5289 { | |
5290 _OrthancPluginSendMultipartItem2 params; | |
5291 params.output = output; | |
5292 params.answer = answer; | |
5293 params.answerSize = answerSize; | |
5294 params.headersCount = headersCount; | |
5295 params.headersKeys = headersKeys; | |
5296 params.headersValues = headersValues; | |
5297 | |
5298 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem2, ¶ms); | |
5299 } | |
5300 | |
5301 | |
5302 typedef struct | |
5303 { | |
5304 OrthancPluginIncomingHttpRequestFilter callback; | |
5305 } _OrthancPluginIncomingHttpRequestFilter; | |
5306 | |
5307 /** | |
5308 * @brief Register a callback to filter incoming HTTP requests. | |
5309 * | |
5310 * This function registers a custom callback to filter incoming HTTP/REST | |
5311 * requests received by the HTTP server of Orthanc. | |
5312 * | |
5313 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5314 * @param callback The callback. | |
5315 * @return 0 if success, other value if error. | |
5316 * @ingroup Callbacks | |
5317 * @deprecated Please instead use OrthancPluginRegisterIncomingHttpRequestFilter2() | |
5318 **/ | |
5319 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter( | |
5320 OrthancPluginContext* context, | |
5321 OrthancPluginIncomingHttpRequestFilter callback) | |
5322 { | |
5323 _OrthancPluginIncomingHttpRequestFilter params; | |
5324 params.callback = callback; | |
5325 | |
5326 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter, ¶ms); | |
5327 } | |
5328 | |
5329 | |
5330 | |
5331 typedef struct | |
5332 { | |
5333 OrthancPluginMemoryBuffer* answerBody; | |
5334 OrthancPluginMemoryBuffer* answerHeaders; | |
5335 uint16_t* httpStatus; | |
5336 OrthancPluginHttpMethod method; | |
5337 const char* url; | |
5338 uint32_t headersCount; | |
5339 const char* const* headersKeys; | |
5340 const char* const* headersValues; | |
5341 const char* body; | |
5342 uint32_t bodySize; | |
5343 const char* username; | |
5344 const char* password; | |
5345 uint32_t timeout; | |
5346 const char* certificateFile; | |
5347 const char* certificateKeyFile; | |
5348 const char* certificateKeyPassword; | |
5349 uint8_t pkcs11; | |
5350 } _OrthancPluginCallHttpClient2; | |
5351 | |
5352 | |
5353 | |
5354 /** | |
5355 * @brief Issue a HTTP call with full flexibility. | |
5356 * | |
5357 * Make a HTTP call to the given URL. The result to the query is | |
5358 * stored into a newly allocated memory buffer. The HTTP request | |
5359 * will be done accordingly to the global configuration of Orthanc | |
5360 * (in particular, the options "HttpProxy", "HttpTimeout", | |
5361 * "HttpsVerifyPeers", "HttpsCACertificates", and "Pkcs11" will be | |
5362 * taken into account). | |
5363 * | |
5364 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5365 * @param answerBody The target memory buffer (out argument). | |
5366 * It must be freed with OrthancPluginFreeMemoryBuffer(). | |
5367 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument). | |
5368 * The answer headers are formatted as a JSON object (associative array). | |
5369 * The buffer must be freed with OrthancPluginFreeMemoryBuffer(). | |
5370 * This argument can be set to NULL if the plugin has no interest in the HTTP headers. | |
5371 * @param httpStatus The HTTP status after the execution of the request (out argument). | |
5372 * @param method HTTP method to be used. | |
5373 * @param url The URL of interest. | |
5374 * @param headersCount The number of HTTP headers. | |
5375 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header). | |
5376 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header). | |
5377 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
5378 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
5379 * @param body The HTTP body for a POST or PUT request. | |
5380 * @param bodySize The size of the body. | |
5381 * @param timeout Timeout in seconds (0 for default timeout). | |
5382 * @param certificateFile Path to the client certificate for HTTPS, in PEM format | |
5383 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
5384 * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format | |
5385 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
5386 * @param certificateKeyPassword Password to unlock the key of the client certificate | |
5387 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
5388 * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards. | |
5389 * @return 0 if success, or the error code if failure. | |
5390 * @see OrthancPluginCallPeerApi() | |
5391 **/ | |
5392 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpClient( | |
5393 OrthancPluginContext* context, | |
5394 OrthancPluginMemoryBuffer* answerBody, | |
5395 OrthancPluginMemoryBuffer* answerHeaders, | |
5396 uint16_t* httpStatus, | |
5397 OrthancPluginHttpMethod method, | |
5398 const char* url, | |
5399 uint32_t headersCount, | |
5400 const char* const* headersKeys, | |
5401 const char* const* headersValues, | |
5402 const char* body, | |
5403 uint32_t bodySize, | |
5404 const char* username, | |
5405 const char* password, | |
5406 uint32_t timeout, | |
5407 const char* certificateFile, | |
5408 const char* certificateKeyFile, | |
5409 const char* certificateKeyPassword, | |
5410 uint8_t pkcs11) | |
5411 { | |
5412 _OrthancPluginCallHttpClient2 params; | |
5413 memset(¶ms, 0, sizeof(params)); | |
5414 | |
5415 params.answerBody = answerBody; | |
5416 params.answerHeaders = answerHeaders; | |
5417 params.httpStatus = httpStatus; | |
5418 params.method = method; | |
5419 params.url = url; | |
5420 params.headersCount = headersCount; | |
5421 params.headersKeys = headersKeys; | |
5422 params.headersValues = headersValues; | |
5423 params.body = body; | |
5424 params.bodySize = bodySize; | |
5425 params.username = username; | |
5426 params.password = password; | |
5427 params.timeout = timeout; | |
5428 params.certificateFile = certificateFile; | |
5429 params.certificateKeyFile = certificateKeyFile; | |
5430 params.certificateKeyPassword = certificateKeyPassword; | |
5431 params.pkcs11 = pkcs11; | |
5432 | |
5433 return context->InvokeService(context, _OrthancPluginService_CallHttpClient2, ¶ms); | |
5434 } | |
5435 | |
5436 | |
5437 /** | |
5438 * @brief Generate an UUID. | |
5439 * | |
5440 * Generate a random GUID/UUID (globally unique identifier). | |
5441 * | |
5442 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5443 * @return NULL in the case of an error, or a newly allocated string | |
5444 * containing the UUID. This string must be freed by OrthancPluginFreeString(). | |
5445 * @ingroup Toolbox | |
5446 **/ | |
5447 ORTHANC_PLUGIN_INLINE char* OrthancPluginGenerateUuid( | |
5448 OrthancPluginContext* context) | |
5449 { | |
5450 char* result; | |
5451 | |
5452 _OrthancPluginRetrieveDynamicString params; | |
5453 params.result = &result; | |
5454 params.argument = NULL; | |
5455 | |
5456 if (context->InvokeService(context, _OrthancPluginService_GenerateUuid, ¶ms) != OrthancPluginErrorCode_Success) | |
5457 { | |
5458 /* Error */ | |
5459 return NULL; | |
5460 } | |
5461 else | |
5462 { | |
5463 return result; | |
5464 } | |
5465 } | |
5466 | |
5467 | |
5468 | |
5469 | |
5470 typedef struct | |
5471 { | |
5472 OrthancPluginFindCallback callback; | |
5473 } _OrthancPluginFindCallback; | |
5474 | |
5475 /** | |
5476 * @brief Register a callback to handle C-Find requests. | |
5477 * | |
5478 * This function registers a callback to handle C-Find SCP requests | |
5479 * that are not related to modality worklists. | |
5480 * | |
5481 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5482 * @param callback The callback. | |
5483 * @return 0 if success, other value if error. | |
5484 * @ingroup DicomCallbacks | |
5485 **/ | |
5486 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterFindCallback( | |
5487 OrthancPluginContext* context, | |
5488 OrthancPluginFindCallback callback) | |
5489 { | |
5490 _OrthancPluginFindCallback params; | |
5491 params.callback = callback; | |
5492 | |
5493 return context->InvokeService(context, _OrthancPluginService_RegisterFindCallback, ¶ms); | |
5494 } | |
5495 | |
5496 | |
5497 typedef struct | |
5498 { | |
5499 OrthancPluginFindAnswers *answers; | |
5500 const OrthancPluginFindQuery *query; | |
5501 const void *dicom; | |
5502 uint32_t size; | |
5503 uint32_t index; | |
5504 uint32_t *resultUint32; | |
5505 uint16_t *resultGroup; | |
5506 uint16_t *resultElement; | |
5507 char **resultString; | |
5508 } _OrthancPluginFindOperation; | |
5509 | |
5510 /** | |
5511 * @brief Add one answer to some C-Find request. | |
5512 * | |
5513 * This function adds one answer (encoded as a DICOM file) to the | |
5514 * set of answers corresponding to some C-Find SCP request that is | |
5515 * not related to modality worklists. | |
5516 * | |
5517 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5518 * @param answers The set of answers. | |
5519 * @param dicom The answer to be added, encoded as a DICOM file. | |
5520 * @param size The size of the DICOM file. | |
5521 * @return 0 if success, other value if error. | |
5522 * @ingroup DicomCallbacks | |
5523 * @see OrthancPluginCreateDicom() | |
5524 **/ | |
5525 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindAddAnswer( | |
5526 OrthancPluginContext* context, | |
5527 OrthancPluginFindAnswers* answers, | |
5528 const void* dicom, | |
5529 uint32_t size) | |
5530 { | |
5531 _OrthancPluginFindOperation params; | |
5532 memset(¶ms, 0, sizeof(params)); | |
5533 params.answers = answers; | |
5534 params.dicom = dicom; | |
5535 params.size = size; | |
5536 | |
5537 return context->InvokeService(context, _OrthancPluginService_FindAddAnswer, ¶ms); | |
5538 } | |
5539 | |
5540 | |
5541 /** | |
5542 * @brief Mark the set of C-Find answers as incomplete. | |
5543 * | |
5544 * This function marks as incomplete the set of answers | |
5545 * corresponding to some C-Find SCP request that is not related to | |
5546 * modality worklists. This must be used if canceling the handling | |
5547 * of a request when too many answers are to be returned. | |
5548 * | |
5549 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5550 * @param answers The set of answers. | |
5551 * @return 0 if success, other value if error. | |
5552 * @ingroup DicomCallbacks | |
5553 **/ | |
5554 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindMarkIncomplete( | |
5555 OrthancPluginContext* context, | |
5556 OrthancPluginFindAnswers* answers) | |
5557 { | |
5558 _OrthancPluginFindOperation params; | |
5559 memset(¶ms, 0, sizeof(params)); | |
5560 params.answers = answers; | |
5561 | |
5562 return context->InvokeService(context, _OrthancPluginService_FindMarkIncomplete, ¶ms); | |
5563 } | |
5564 | |
5565 | |
5566 | |
5567 /** | |
5568 * @brief Get the number of tags in a C-Find query. | |
5569 * | |
5570 * This function returns the number of tags that are contained in | |
5571 * the given C-Find query. | |
5572 * | |
5573 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5574 * @param query The C-Find query. | |
5575 * @return The number of tags. | |
5576 * @ingroup DicomCallbacks | |
5577 **/ | |
5578 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFindQuerySize( | |
5579 OrthancPluginContext* context, | |
5580 const OrthancPluginFindQuery* query) | |
5581 { | |
5582 uint32_t count = 0; | |
5583 | |
5584 _OrthancPluginFindOperation params; | |
5585 memset(¶ms, 0, sizeof(params)); | |
5586 params.query = query; | |
5587 params.resultUint32 = &count; | |
5588 | |
5589 if (context->InvokeService(context, _OrthancPluginService_GetFindQuerySize, ¶ms) != OrthancPluginErrorCode_Success) | |
5590 { | |
5591 /* Error */ | |
5592 return 0; | |
5593 } | |
5594 else | |
5595 { | |
5596 return count; | |
5597 } | |
5598 } | |
5599 | |
5600 | |
5601 /** | |
5602 * @brief Get one tag in a C-Find query. | |
5603 * | |
5604 * This function returns the group and the element of one DICOM tag | |
5605 * in the given C-Find query. | |
5606 * | |
5607 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5608 * @param group The group of the tag (output). | |
5609 * @param element The element of the tag (output). | |
5610 * @param query The C-Find query. | |
5611 * @param index The index of the tag of interest. | |
5612 * @return 0 if success, other value if error. | |
5613 * @ingroup DicomCallbacks | |
5614 **/ | |
5615 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetFindQueryTag( | |
5616 OrthancPluginContext* context, | |
5617 uint16_t* group, | |
5618 uint16_t* element, | |
5619 const OrthancPluginFindQuery* query, | |
5620 uint32_t index) | |
5621 { | |
5622 _OrthancPluginFindOperation params; | |
5623 memset(¶ms, 0, sizeof(params)); | |
5624 params.query = query; | |
5625 params.index = index; | |
5626 params.resultGroup = group; | |
5627 params.resultElement = element; | |
5628 | |
5629 return context->InvokeService(context, _OrthancPluginService_GetFindQueryTag, ¶ms); | |
5630 } | |
5631 | |
5632 | |
5633 /** | |
5634 * @brief Get the symbolic name of one tag in a C-Find query. | |
5635 * | |
5636 * This function returns the symbolic name of one DICOM tag in the | |
5637 * given C-Find query. | |
5638 * | |
5639 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5640 * @param query The C-Find query. | |
5641 * @param index The index of the tag of interest. | |
5642 * @return The NULL value in case of error, or a string containing the name of the tag. | |
5643 * @return 0 if success, other value if error. | |
5644 * @ingroup DicomCallbacks | |
5645 **/ | |
5646 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryTagName( | |
5647 OrthancPluginContext* context, | |
5648 const OrthancPluginFindQuery* query, | |
5649 uint32_t index) | |
5650 { | |
5651 char* result; | |
5652 | |
5653 _OrthancPluginFindOperation params; | |
5654 memset(¶ms, 0, sizeof(params)); | |
5655 params.query = query; | |
5656 params.index = index; | |
5657 params.resultString = &result; | |
5658 | |
5659 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryTagName, ¶ms) != OrthancPluginErrorCode_Success) | |
5660 { | |
5661 /* Error */ | |
5662 return NULL; | |
5663 } | |
5664 else | |
5665 { | |
5666 return result; | |
5667 } | |
5668 } | |
5669 | |
5670 | |
5671 /** | |
5672 * @brief Get the value associated with one tag in a C-Find query. | |
5673 * | |
5674 * This function returns the value associated with one tag in the | |
5675 * given C-Find query. | |
5676 * | |
5677 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5678 * @param query The C-Find query. | |
5679 * @param index The index of the tag of interest. | |
5680 * @return The NULL value in case of error, or a string containing the value of the tag. | |
5681 * @return 0 if success, other value if error. | |
5682 * @ingroup DicomCallbacks | |
5683 **/ | |
5684 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryValue( | |
5685 OrthancPluginContext* context, | |
5686 const OrthancPluginFindQuery* query, | |
5687 uint32_t index) | |
5688 { | |
5689 char* result; | |
5690 | |
5691 _OrthancPluginFindOperation params; | |
5692 memset(¶ms, 0, sizeof(params)); | |
5693 params.query = query; | |
5694 params.index = index; | |
5695 params.resultString = &result; | |
5696 | |
5697 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryValue, ¶ms) != OrthancPluginErrorCode_Success) | |
5698 { | |
5699 /* Error */ | |
5700 return NULL; | |
5701 } | |
5702 else | |
5703 { | |
5704 return result; | |
5705 } | |
5706 } | |
5707 | |
5708 | |
5709 | |
5710 | |
5711 typedef struct | |
5712 { | |
5713 OrthancPluginMoveCallback callback; | |
5714 OrthancPluginGetMoveSize getMoveSize; | |
5715 OrthancPluginApplyMove applyMove; | |
5716 OrthancPluginFreeMove freeMove; | |
5717 } _OrthancPluginMoveCallback; | |
5718 | |
5719 /** | |
5720 * @brief Register a callback to handle C-Move requests. | |
5721 * | |
5722 * This function registers a callback to handle C-Move SCP requests. | |
5723 * | |
5724 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5725 * @param callback The main callback. | |
5726 * @param getMoveSize Callback to read the number of C-Move suboperations. | |
5727 * @param applyMove Callback to apply one C-Move suboperations. | |
5728 * @param freeMove Callback to free the C-Move driver. | |
5729 * @return 0 if success, other value if error. | |
5730 * @ingroup DicomCallbacks | |
5731 **/ | |
5732 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterMoveCallback( | |
5733 OrthancPluginContext* context, | |
5734 OrthancPluginMoveCallback callback, | |
5735 OrthancPluginGetMoveSize getMoveSize, | |
5736 OrthancPluginApplyMove applyMove, | |
5737 OrthancPluginFreeMove freeMove) | |
5738 { | |
5739 _OrthancPluginMoveCallback params; | |
5740 params.callback = callback; | |
5741 params.getMoveSize = getMoveSize; | |
5742 params.applyMove = applyMove; | |
5743 params.freeMove = freeMove; | |
5744 | |
5745 return context->InvokeService(context, _OrthancPluginService_RegisterMoveCallback, ¶ms); | |
5746 } | |
5747 | |
5748 | |
5749 | |
5750 typedef struct | |
5751 { | |
5752 OrthancPluginFindMatcher** target; | |
5753 const void* query; | |
5754 uint32_t size; | |
5755 } _OrthancPluginCreateFindMatcher; | |
5756 | |
5757 | |
5758 /** | |
5759 * @brief Create a C-Find matcher. | |
5760 * | |
5761 * This function creates a "matcher" object that can be used to | |
5762 * check whether a DICOM instance matches a C-Find query. The C-Find | |
5763 * query must be expressed as a DICOM buffer. | |
5764 * | |
5765 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5766 * @param query The C-Find DICOM query. | |
5767 * @param size The size of the DICOM query. | |
5768 * @return The newly allocated matcher. It must be freed with OrthancPluginFreeFindMatcher(). | |
5769 * @ingroup Toolbox | |
5770 **/ | |
5771 ORTHANC_PLUGIN_INLINE OrthancPluginFindMatcher* OrthancPluginCreateFindMatcher( | |
5772 OrthancPluginContext* context, | |
5773 const void* query, | |
5774 uint32_t size) | |
5775 { | |
5776 OrthancPluginFindMatcher* target = NULL; | |
5777 | |
5778 _OrthancPluginCreateFindMatcher params; | |
5779 memset(¶ms, 0, sizeof(params)); | |
5780 params.target = ⌖ | |
5781 params.query = query; | |
5782 params.size = size; | |
5783 | |
5784 if (context->InvokeService(context, _OrthancPluginService_CreateFindMatcher, ¶ms) != OrthancPluginErrorCode_Success) | |
5785 { | |
5786 return NULL; | |
5787 } | |
5788 else | |
5789 { | |
5790 return target; | |
5791 } | |
5792 } | |
5793 | |
5794 | |
5795 typedef struct | |
5796 { | |
5797 OrthancPluginFindMatcher* matcher; | |
5798 } _OrthancPluginFreeFindMatcher; | |
5799 | |
5800 /** | |
5801 * @brief Free a C-Find matcher. | |
5802 * | |
5803 * This function frees a matcher that was created using OrthancPluginCreateFindMatcher(). | |
5804 * | |
5805 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5806 * @param matcher The matcher of interest. | |
5807 * @ingroup Toolbox | |
5808 **/ | |
5809 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeFindMatcher( | |
5810 OrthancPluginContext* context, | |
5811 OrthancPluginFindMatcher* matcher) | |
5812 { | |
5813 _OrthancPluginFreeFindMatcher params; | |
5814 params.matcher = matcher; | |
5815 | |
5816 context->InvokeService(context, _OrthancPluginService_FreeFindMatcher, ¶ms); | |
5817 } | |
5818 | |
5819 | |
5820 typedef struct | |
5821 { | |
5822 const OrthancPluginFindMatcher* matcher; | |
5823 const void* dicom; | |
5824 uint32_t size; | |
5825 int32_t* isMatch; | |
5826 } _OrthancPluginFindMatcherIsMatch; | |
5827 | |
5828 /** | |
5829 * @brief Test whether a DICOM instance matches a C-Find query. | |
5830 * | |
5831 * This function checks whether one DICOM instance matches C-Find | |
5832 * matcher that was previously allocated using | |
5833 * OrthancPluginCreateFindMatcher(). | |
5834 * | |
5835 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5836 * @param matcher The matcher of interest. | |
5837 * @param dicom The DICOM instance to be matched. | |
5838 * @param size The size of the DICOM instance. | |
5839 * @return 1 if the DICOM instance matches the query, 0 otherwise. | |
5840 * @ingroup Toolbox | |
5841 **/ | |
5842 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginFindMatcherIsMatch( | |
5843 OrthancPluginContext* context, | |
5844 const OrthancPluginFindMatcher* matcher, | |
5845 const void* dicom, | |
5846 uint32_t size) | |
5847 { | |
5848 int32_t isMatch = 0; | |
5849 | |
5850 _OrthancPluginFindMatcherIsMatch params; | |
5851 params.matcher = matcher; | |
5852 params.dicom = dicom; | |
5853 params.size = size; | |
5854 params.isMatch = &isMatch; | |
5855 | |
5856 if (context->InvokeService(context, _OrthancPluginService_FindMatcherIsMatch, ¶ms) == OrthancPluginErrorCode_Success) | |
5857 { | |
5858 return isMatch; | |
5859 } | |
5860 else | |
5861 { | |
5862 /* Error: Assume non-match */ | |
5863 return 0; | |
5864 } | |
5865 } | |
5866 | |
5867 | |
5868 typedef struct | |
5869 { | |
5870 OrthancPluginIncomingHttpRequestFilter2 callback; | |
5871 } _OrthancPluginIncomingHttpRequestFilter2; | |
5872 | |
5873 /** | |
5874 * @brief Register a callback to filter incoming HTTP requests. | |
5875 * | |
5876 * This function registers a custom callback to filter incoming HTTP/REST | |
5877 * requests received by the HTTP server of Orthanc. | |
5878 * | |
5879 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5880 * @param callback The callback. | |
5881 * @return 0 if success, other value if error. | |
5882 * @ingroup Callbacks | |
5883 **/ | |
5884 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter2( | |
5885 OrthancPluginContext* context, | |
5886 OrthancPluginIncomingHttpRequestFilter2 callback) | |
5887 { | |
5888 _OrthancPluginIncomingHttpRequestFilter2 params; | |
5889 params.callback = callback; | |
5890 | |
5891 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter2, ¶ms); | |
5892 } | |
5893 | |
5894 | |
5895 | |
5896 typedef struct | |
5897 { | |
5898 OrthancPluginPeers** peers; | |
5899 } _OrthancPluginGetPeers; | |
5900 | |
5901 /** | |
5902 * @brief Return the list of available Orthanc peers. | |
5903 * | |
5904 * This function returns the parameters of the Orthanc peers that are known to | |
5905 * the Orthanc server hosting the plugin. | |
5906 * | |
5907 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5908 * @return NULL if error, or a newly allocated opaque data structure containing the peers. | |
5909 * This structure must be freed with OrthancPluginFreePeers(). | |
5910 * @ingroup Toolbox | |
5911 **/ | |
5912 ORTHANC_PLUGIN_INLINE OrthancPluginPeers* OrthancPluginGetPeers( | |
5913 OrthancPluginContext* context) | |
5914 { | |
5915 OrthancPluginPeers* peers = NULL; | |
5916 | |
5917 _OrthancPluginGetPeers params; | |
5918 memset(¶ms, 0, sizeof(params)); | |
5919 params.peers = &peers; | |
5920 | |
5921 if (context->InvokeService(context, _OrthancPluginService_GetPeers, ¶ms) != OrthancPluginErrorCode_Success) | |
5922 { | |
5923 return NULL; | |
5924 } | |
5925 else | |
5926 { | |
5927 return peers; | |
5928 } | |
5929 } | |
5930 | |
5931 | |
5932 typedef struct | |
5933 { | |
5934 OrthancPluginPeers* peers; | |
5935 } _OrthancPluginFreePeers; | |
5936 | |
5937 /** | |
5938 * @brief Free the list of available Orthanc peers. | |
5939 * | |
5940 * This function frees the data structure returned by OrthancPluginGetPeers(). | |
5941 * | |
5942 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5943 * @param peers The data structure describing the Orthanc peers. | |
5944 * @ingroup Toolbox | |
5945 **/ | |
5946 ORTHANC_PLUGIN_INLINE void OrthancPluginFreePeers( | |
5947 OrthancPluginContext* context, | |
5948 OrthancPluginPeers* peers) | |
5949 { | |
5950 _OrthancPluginFreePeers params; | |
5951 params.peers = peers; | |
5952 | |
5953 context->InvokeService(context, _OrthancPluginService_FreePeers, ¶ms); | |
5954 } | |
5955 | |
5956 | |
5957 typedef struct | |
5958 { | |
5959 uint32_t* target; | |
5960 const OrthancPluginPeers* peers; | |
5961 } _OrthancPluginGetPeersCount; | |
5962 | |
5963 /** | |
5964 * @brief Get the number of Orthanc peers. | |
5965 * | |
5966 * This function returns the number of Orthanc peers. | |
5967 * | |
5968 * This function is thread-safe: Several threads sharing the same | |
5969 * OrthancPluginPeers object can simultaneously call this function. | |
5970 * | |
5971 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5972 * @param peers The data structure describing the Orthanc peers. | |
5973 * @result The number of peers. | |
5974 * @ingroup Toolbox | |
5975 **/ | |
5976 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetPeersCount( | |
5977 OrthancPluginContext* context, | |
5978 const OrthancPluginPeers* peers) | |
5979 { | |
5980 uint32_t target = 0; | |
5981 | |
5982 _OrthancPluginGetPeersCount params; | |
5983 memset(¶ms, 0, sizeof(params)); | |
5984 params.target = ⌖ | |
5985 params.peers = peers; | |
5986 | |
5987 if (context->InvokeService(context, _OrthancPluginService_GetPeersCount, ¶ms) != OrthancPluginErrorCode_Success) | |
5988 { | |
5989 /* Error */ | |
5990 return 0; | |
5991 } | |
5992 else | |
5993 { | |
5994 return target; | |
5995 } | |
5996 } | |
5997 | |
5998 | |
5999 typedef struct | |
6000 { | |
6001 const char** target; | |
6002 const OrthancPluginPeers* peers; | |
6003 uint32_t peerIndex; | |
6004 const char* userProperty; | |
6005 } _OrthancPluginGetPeerProperty; | |
6006 | |
6007 /** | |
6008 * @brief Get the symbolic name of an Orthanc peer. | |
6009 * | |
6010 * This function returns the symbolic name of the Orthanc peer, | |
6011 * which corresponds to the key of the "OrthancPeers" configuration | |
6012 * option of Orthanc. | |
6013 * | |
6014 * This function is thread-safe: Several threads sharing the same | |
6015 * OrthancPluginPeers object can simultaneously call this function. | |
6016 * | |
6017 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6018 * @param peers The data structure describing the Orthanc peers. | |
6019 * @param peerIndex The index of the peer of interest. | |
6020 * This value must be lower than OrthancPluginGetPeersCount(). | |
6021 * @result The symbolic name, or NULL in the case of an error. | |
6022 * @ingroup Toolbox | |
6023 **/ | |
6024 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerName( | |
6025 OrthancPluginContext* context, | |
6026 const OrthancPluginPeers* peers, | |
6027 uint32_t peerIndex) | |
6028 { | |
6029 const char* target = NULL; | |
6030 | |
6031 _OrthancPluginGetPeerProperty params; | |
6032 memset(¶ms, 0, sizeof(params)); | |
6033 params.target = ⌖ | |
6034 params.peers = peers; | |
6035 params.peerIndex = peerIndex; | |
6036 params.userProperty = NULL; | |
6037 | |
6038 if (context->InvokeService(context, _OrthancPluginService_GetPeerName, ¶ms) != OrthancPluginErrorCode_Success) | |
6039 { | |
6040 /* Error */ | |
6041 return NULL; | |
6042 } | |
6043 else | |
6044 { | |
6045 return target; | |
6046 } | |
6047 } | |
6048 | |
6049 | |
6050 /** | |
6051 * @brief Get the base URL of an Orthanc peer. | |
6052 * | |
6053 * This function returns the base URL to the REST API of some Orthanc peer. | |
6054 * | |
6055 * This function is thread-safe: Several threads sharing the same | |
6056 * OrthancPluginPeers object can simultaneously call this function. | |
6057 * | |
6058 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6059 * @param peers The data structure describing the Orthanc peers. | |
6060 * @param peerIndex The index of the peer of interest. | |
6061 * This value must be lower than OrthancPluginGetPeersCount(). | |
6062 * @result The URL, or NULL in the case of an error. | |
6063 * @ingroup Toolbox | |
6064 **/ | |
6065 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUrl( | |
6066 OrthancPluginContext* context, | |
6067 const OrthancPluginPeers* peers, | |
6068 uint32_t peerIndex) | |
6069 { | |
6070 const char* target = NULL; | |
6071 | |
6072 _OrthancPluginGetPeerProperty params; | |
6073 memset(¶ms, 0, sizeof(params)); | |
6074 params.target = ⌖ | |
6075 params.peers = peers; | |
6076 params.peerIndex = peerIndex; | |
6077 params.userProperty = NULL; | |
6078 | |
6079 if (context->InvokeService(context, _OrthancPluginService_GetPeerUrl, ¶ms) != OrthancPluginErrorCode_Success) | |
6080 { | |
6081 /* Error */ | |
6082 return NULL; | |
6083 } | |
6084 else | |
6085 { | |
6086 return target; | |
6087 } | |
6088 } | |
6089 | |
6090 | |
6091 | |
6092 /** | |
6093 * @brief Get some user-defined property of an Orthanc peer. | |
6094 * | |
6095 * This function returns some user-defined property of some Orthanc | |
6096 * peer. An user-defined property is a property that is associated | |
6097 * with the peer in the Orthanc configuration file, but that is not | |
6098 * recognized by the Orthanc core. | |
6099 * | |
6100 * This function is thread-safe: Several threads sharing the same | |
6101 * OrthancPluginPeers object can simultaneously call this function. | |
6102 * | |
6103 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6104 * @param peers The data structure describing the Orthanc peers. | |
6105 * @param peerIndex The index of the peer of interest. | |
6106 * This value must be lower than OrthancPluginGetPeersCount(). | |
6107 * @param userProperty The user property of interest. | |
6108 * @result The value of the user property, or NULL if it is not defined. | |
6109 * @ingroup Toolbox | |
6110 **/ | |
6111 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUserProperty( | |
6112 OrthancPluginContext* context, | |
6113 const OrthancPluginPeers* peers, | |
6114 uint32_t peerIndex, | |
6115 const char* userProperty) | |
6116 { | |
6117 const char* target = NULL; | |
6118 | |
6119 _OrthancPluginGetPeerProperty params; | |
6120 memset(¶ms, 0, sizeof(params)); | |
6121 params.target = ⌖ | |
6122 params.peers = peers; | |
6123 params.peerIndex = peerIndex; | |
6124 params.userProperty = userProperty; | |
6125 | |
6126 if (context->InvokeService(context, _OrthancPluginService_GetPeerUserProperty, ¶ms) != OrthancPluginErrorCode_Success) | |
6127 { | |
6128 /* No such user property */ | |
6129 return NULL; | |
6130 } | |
6131 else | |
6132 { | |
6133 return target; | |
6134 } | |
6135 } | |
6136 | |
6137 | |
6138 | |
6139 typedef struct | |
6140 { | |
6141 OrthancPluginMemoryBuffer* answerBody; | |
6142 OrthancPluginMemoryBuffer* answerHeaders; | |
6143 uint16_t* httpStatus; | |
6144 const OrthancPluginPeers* peers; | |
6145 uint32_t peerIndex; | |
6146 OrthancPluginHttpMethod method; | |
6147 const char* uri; | |
6148 uint32_t additionalHeadersCount; | |
6149 const char* const* additionalHeadersKeys; | |
6150 const char* const* additionalHeadersValues; | |
6151 const char* body; | |
6152 uint32_t bodySize; | |
6153 uint32_t timeout; | |
6154 } _OrthancPluginCallPeerApi; | |
6155 | |
6156 /** | |
6157 * @brief Call the REST API of an Orthanc peer. | |
6158 * | |
6159 * Make a REST call to the given URI in the REST API of a remote | |
6160 * Orthanc peer. The result to the query is stored into a newly | |
6161 * allocated memory buffer. The HTTP request will be done according | |
6162 * to the "OrthancPeers" configuration option of Orthanc. | |
6163 * | |
6164 * This function is thread-safe: Several threads sharing the same | |
6165 * OrthancPluginPeers object can simultaneously call this function. | |
6166 * | |
6167 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6168 * @param answerBody The target memory buffer (out argument). | |
6169 * It must be freed with OrthancPluginFreeMemoryBuffer(). | |
6170 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument). | |
6171 * The answer headers are formatted as a JSON object (associative array). | |
6172 * The buffer must be freed with OrthancPluginFreeMemoryBuffer(). | |
6173 * This argument can be set to NULL if the plugin has no interest in the HTTP headers. | |
6174 * @param httpStatus The HTTP status after the execution of the request (out argument). | |
6175 * @param peers The data structure describing the Orthanc peers. | |
6176 * @param peerIndex The index of the peer of interest. | |
6177 * This value must be lower than OrthancPluginGetPeersCount(). | |
6178 * @param method HTTP method to be used. | |
6179 * @param uri The URI of interest in the REST API. | |
6180 * @param additionalHeadersCount The number of HTTP headers to be added to the | |
6181 * HTTP headers provided in the global configuration of Orthanc. | |
6182 * @param additionalHeadersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header). | |
6183 * @param additionalHeadersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header). | |
6184 * @param body The HTTP body for a POST or PUT request. | |
6185 * @param bodySize The size of the body. | |
6186 * @param timeout Timeout in seconds (0 for default timeout). | |
6187 * @return 0 if success, or the error code if failure. | |
6188 * @see OrthancPluginHttpClient() | |
6189 * @ingroup Toolbox | |
6190 **/ | |
6191 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCallPeerApi( | |
6192 OrthancPluginContext* context, | |
6193 OrthancPluginMemoryBuffer* answerBody, | |
6194 OrthancPluginMemoryBuffer* answerHeaders, | |
6195 uint16_t* httpStatus, | |
6196 const OrthancPluginPeers* peers, | |
6197 uint32_t peerIndex, | |
6198 OrthancPluginHttpMethod method, | |
6199 const char* uri, | |
6200 uint32_t additionalHeadersCount, | |
6201 const char* const* additionalHeadersKeys, | |
6202 const char* const* additionalHeadersValues, | |
6203 const char* body, | |
6204 uint32_t bodySize, | |
6205 uint32_t timeout) | |
6206 { | |
6207 _OrthancPluginCallPeerApi params; | |
6208 memset(¶ms, 0, sizeof(params)); | |
6209 | |
6210 params.answerBody = answerBody; | |
6211 params.answerHeaders = answerHeaders; | |
6212 params.httpStatus = httpStatus; | |
6213 params.peers = peers; | |
6214 params.peerIndex = peerIndex; | |
6215 params.method = method; | |
6216 params.uri = uri; | |
6217 params.additionalHeadersCount = additionalHeadersCount; | |
6218 params.additionalHeadersKeys = additionalHeadersKeys; | |
6219 params.additionalHeadersValues = additionalHeadersValues; | |
6220 params.body = body; | |
6221 params.bodySize = bodySize; | |
6222 params.timeout = timeout; | |
6223 | |
6224 return context->InvokeService(context, _OrthancPluginService_CallPeerApi, ¶ms); | |
6225 } | |
6226 | |
6227 | |
6228 | |
6229 | |
6230 | |
6231 typedef struct | |
6232 { | |
6233 OrthancPluginJob** target; | |
6234 void *job; | |
6235 OrthancPluginJobFinalize finalize; | |
6236 const char *type; | |
6237 OrthancPluginJobGetProgress getProgress; | |
6238 OrthancPluginJobGetContent getContent; | |
6239 OrthancPluginJobGetSerialized getSerialized; | |
6240 OrthancPluginJobStep step; | |
6241 OrthancPluginJobStop stop; | |
6242 OrthancPluginJobReset reset; | |
6243 } _OrthancPluginCreateJob; | |
6244 | |
6245 /** | |
6246 * @brief Create a custom job. | |
6247 * | |
6248 * This function creates a custom job to be run by the jobs engine | |
6249 * of Orthanc. | |
6250 * | |
6251 * Orthanc starts one dedicated thread per custom job that is | |
6252 * running. It is guaranteed that all the callbacks will only be | |
6253 * called from this single dedicated thread, in mutual exclusion: As | |
6254 * a consequence, it is *not* mandatory to protect the various | |
6255 * callbacks by mutexes. | |
6256 * | |
6257 * The custom job can nonetheless launch its own processing threads | |
6258 * on the first call to the "step()" callback, and stop them once | |
6259 * the "stop()" callback is called. | |
6260 * | |
6261 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6262 * @param job The job to be executed. | |
6263 * @param finalize The finalization callback. | |
6264 * @param type The type of the job, provided to the job unserializer. | |
6265 * See OrthancPluginRegisterJobsUnserializer(). | |
6266 * @param getProgress The progress callback. | |
6267 * @param getContent The content callback. | |
6268 * @param getSerialized The serialization callback. | |
6269 * @param step The callback to execute the individual steps of the job. | |
6270 * @param stop The callback that is invoked once the job leaves the "running" state. | |
6271 * @param reset The callback that is invoked if a stopped job is started again. | |
6272 * @return The newly allocated job. It must be freed with OrthancPluginFreeJob(), | |
6273 * as long as it is not submitted with OrthancPluginSubmitJob(). | |
6274 * @ingroup Toolbox | |
6275 **/ | |
6276 ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob( | |
6277 OrthancPluginContext *context, | |
6278 void *job, | |
6279 OrthancPluginJobFinalize finalize, | |
6280 const char *type, | |
6281 OrthancPluginJobGetProgress getProgress, | |
6282 OrthancPluginJobGetContent getContent, | |
6283 OrthancPluginJobGetSerialized getSerialized, | |
6284 OrthancPluginJobStep step, | |
6285 OrthancPluginJobStop stop, | |
6286 OrthancPluginJobReset reset) | |
6287 { | |
6288 OrthancPluginJob* target = NULL; | |
6289 | |
6290 _OrthancPluginCreateJob params; | |
6291 memset(¶ms, 0, sizeof(params)); | |
6292 | |
6293 params.target = ⌖ | |
6294 params.job = job; | |
6295 params.finalize = finalize; | |
6296 params.type = type; | |
6297 params.getProgress = getProgress; | |
6298 params.getContent = getContent; | |
6299 params.getSerialized = getSerialized; | |
6300 params.step = step; | |
6301 params.stop = stop; | |
6302 params.reset = reset; | |
6303 | |
6304 if (context->InvokeService(context, _OrthancPluginService_CreateJob, ¶ms) != OrthancPluginErrorCode_Success || | |
6305 target == NULL) | |
6306 { | |
6307 /* Error */ | |
6308 return NULL; | |
6309 } | |
6310 else | |
6311 { | |
6312 return target; | |
6313 } | |
6314 } | |
6315 | |
6316 | |
6317 typedef struct | |
6318 { | |
6319 OrthancPluginJob* job; | |
6320 } _OrthancPluginFreeJob; | |
6321 | |
6322 /** | |
6323 * @brief Free a custom job. | |
6324 * | |
6325 * This function frees an image that was created with OrthancPluginCreateJob(). | |
6326 * | |
6327 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6328 * @param job The job. | |
6329 * @ingroup Toolbox | |
6330 **/ | |
6331 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeJob( | |
6332 OrthancPluginContext* context, | |
6333 OrthancPluginJob* job) | |
6334 { | |
6335 _OrthancPluginFreeJob params; | |
6336 params.job = job; | |
6337 | |
6338 context->InvokeService(context, _OrthancPluginService_FreeJob, ¶ms); | |
6339 } | |
6340 | |
6341 | |
6342 | |
6343 typedef struct | |
6344 { | |
6345 char** resultId; | |
6346 OrthancPluginJob *job; | |
6347 int priority; | |
6348 } _OrthancPluginSubmitJob; | |
6349 | |
6350 /** | |
6351 * @brief Submit a new job to the jobs engine of Orthanc. | |
6352 * | |
6353 * This function adds the given job to the pending jobs of | |
6354 * Orthanc. Orthanc will take take of freeing it by invoking the | |
6355 * finalization callback provided to OrthancPluginCreateJob(). | |
6356 * | |
6357 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6358 * @param job The job, as received by OrthancPluginCreateJob(). | |
6359 * @param priority The priority of the job. | |
6360 * @return ID of the newly-submitted job. This string must be freed by OrthancPluginFreeString(). | |
6361 * @ingroup Toolbox | |
6362 **/ | |
6363 ORTHANC_PLUGIN_INLINE char *OrthancPluginSubmitJob( | |
6364 OrthancPluginContext *context, | |
6365 OrthancPluginJob *job, | |
6366 int priority) | |
6367 { | |
6368 char* resultId = NULL; | |
6369 | |
6370 _OrthancPluginSubmitJob params; | |
6371 memset(¶ms, 0, sizeof(params)); | |
6372 | |
6373 params.resultId = &resultId; | |
6374 params.job = job; | |
6375 params.priority = priority; | |
6376 | |
6377 if (context->InvokeService(context, _OrthancPluginService_SubmitJob, ¶ms) != OrthancPluginErrorCode_Success || | |
6378 resultId == NULL) | |
6379 { | |
6380 /* Error */ | |
6381 return NULL; | |
6382 } | |
6383 else | |
6384 { | |
6385 return resultId; | |
6386 } | |
6387 } | |
6388 | |
6389 | |
6390 | |
6391 typedef struct | |
6392 { | |
6393 OrthancPluginJobsUnserializer unserializer; | |
6394 } _OrthancPluginJobsUnserializer; | |
6395 | |
6396 /** | |
6397 * @brief Register an unserializer for custom jobs. | |
6398 * | |
6399 * This function registers an unserializer that decodes custom jobs | |
6400 * from a JSON string. This callback is invoked when the jobs engine | |
6401 * of Orthanc is started (on Orthanc initialization), for each job | |
6402 * that is stored in the Orthanc database. | |
6403 * | |
6404 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6405 * @param unserializer The job unserializer. | |
6406 * @ingroup Callbacks | |
6407 **/ | |
6408 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterJobsUnserializer( | |
6409 OrthancPluginContext* context, | |
6410 OrthancPluginJobsUnserializer unserializer) | |
6411 { | |
6412 _OrthancPluginJobsUnserializer params; | |
6413 params.unserializer = unserializer; | |
6414 | |
6415 context->InvokeService(context, _OrthancPluginService_RegisterJobsUnserializer, ¶ms); | |
6416 } | |
6417 | |
6418 | |
6419 #ifdef __cplusplus | |
6420 } | |
6421 #endif | |
6422 | |
6423 | |
6424 /** @} */ | |
6425 |