comparison Orthanc/Sdk-0.9.4/orthanc/OrthancCPlugin.h @ 78:d6da56f86e5a

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 25 Sep 2015 11:29:17 +0200
parents
children 2932473a9b19
comparison
equal deleted inserted replaced
77:f44ebb25691c 78:d6da56f86e5a
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 * -# <tt>void OrthancPluginFinalize()</tt>:
22 * This function is invoked by Orthanc during its shutdown. The plugin
23 * must free all its memory.
24 * -# <tt>const char* OrthancPluginGetName()</tt>:
25 * The plugin must return a short string to identify itself.
26 * -# <tt>const char* OrthancPluginGetVersion()</tt>:
27 * The plugin must return a string containing its version number.
28 *
29 * The name and the version of a plugin is only used to prevent it
30 * from being loaded twice. Note that, in C++, it is mandatory to
31 * declare these functions within an <tt>extern "C"</tt> section.
32 *
33 * To ensure multi-threading safety, the various REST callbacks are
34 * guaranteed to be executed in mutual exclusion since Orthanc
35 * 0.8.5. If this feature is undesired (notably when developing
36 * high-performance plugins handling simultaneous requests), use
37 * ::OrthancPluginRegisterRestCallbackNoLock().
38 **/
39
40
41
42 /**
43 * @defgroup Images Images and compression
44 * @brief Functions to deal with images and compressed buffers.
45 *
46 * @defgroup REST REST
47 * @brief Functions to answer REST requests in a callback.
48 *
49 * @defgroup Callbacks Callbacks
50 * @brief Functions to register and manage callbacks by the plugins.
51 *
52 * @defgroup Orthanc Orthanc
53 * @brief Functions to access the content of the Orthanc server.
54 **/
55
56
57
58 /**
59 * @defgroup Toolbox Toolbox
60 * @brief Generic functions to help with the creation of plugins.
61 **/
62
63
64
65 /**
66 * Orthanc - A Lightweight, RESTful DICOM Store
67 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
68 * Department, University Hospital of Liege, Belgium
69 *
70 * This program is free software: you can redistribute it and/or
71 * modify it under the terms of the GNU General Public License as
72 * published by the Free Software Foundation, either version 3 of the
73 * License, or (at your option) any later version.
74 *
75 * In addition, as a special exception, the copyright holders of this
76 * program give permission to link the code of its release with the
77 * OpenSSL project's "OpenSSL" library (or with modified versions of it
78 * that use the same license as the "OpenSSL" library), and distribute
79 * the linked executables. You must obey the GNU General Public License
80 * in all respects for all of the code used other than "OpenSSL". If you
81 * modify file(s) with this exception, you may extend this exception to
82 * your version of the file(s), but you are not obligated to do so. If
83 * you do not wish to do so, delete this exception statement from your
84 * version. If you delete this exception statement from all source files
85 * in the program, then also delete it here.
86 *
87 * This program is distributed in the hope that it will be useful, but
88 * WITHOUT ANY WARRANTY; without even the implied warranty of
89 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
90 * General Public License for more details.
91 *
92 * You should have received a copy of the GNU General Public License
93 * along with this program. If not, see <http://www.gnu.org/licenses/>.
94 **/
95
96
97
98 #pragma once
99
100
101 #include <stdio.h>
102 #include <string.h>
103
104 #ifdef WIN32
105 #define ORTHANC_PLUGINS_API __declspec(dllexport)
106 #else
107 #define ORTHANC_PLUGINS_API
108 #endif
109
110 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 0
111 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 9
112 #define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 4
113
114
115
116 /********************************************************************
117 ** Check that function inlining is properly supported. The use of
118 ** inlining is required, to avoid the duplication of object code
119 ** between two compilation modules that would use the Orthanc Plugin
120 ** API.
121 ********************************************************************/
122
123 /* If the auto-detection of the "inline" keyword below does not work
124 automatically and that your compiler is known to properly support
125 inlining, uncomment the following #define and adapt the definition
126 of "static inline". */
127
128 /* #define ORTHANC_PLUGIN_INLINE static inline */
129
130 #ifndef ORTHANC_PLUGIN_INLINE
131 # if __STDC_VERSION__ >= 199901L
132 /* This is C99 or above: http://predef.sourceforge.net/prestd.html */
133 # define ORTHANC_PLUGIN_INLINE static inline
134 # elif defined(__cplusplus)
135 /* This is C++ */
136 # define ORTHANC_PLUGIN_INLINE static inline
137 # elif defined(__GNUC__)
138 /* This is GCC running in C89 mode */
139 # define ORTHANC_PLUGIN_INLINE static __inline
140 # elif defined(_MSC_VER)
141 /* This is Visual Studio running in C89 mode */
142 # define ORTHANC_PLUGIN_INLINE static __inline
143 # else
144 # error Your compiler is not known to support the "inline" keyword
145 # endif
146 #endif
147
148
149
150 /********************************************************************
151 ** Inclusion of standard libraries.
152 ********************************************************************/
153
154 /**
155 * For Microsoft Visual Studio, a compatibility "stdint.h" can be
156 * downloaded at the following URL:
157 * https://orthanc.googlecode.com/hg/Resources/ThirdParty/VisualStudio/stdint.h
158 **/
159 #include <stdint.h>
160
161 #include <stdlib.h>
162
163
164
165 /********************************************************************
166 ** Definition of the Orthanc Plugin API.
167 ********************************************************************/
168
169 /** @{ */
170
171 #ifdef __cplusplus
172 extern "C"
173 {
174 #endif
175
176 /**
177 * The various error codes that can be returned by the Orthanc core.
178 **/
179 typedef enum
180 {
181 OrthancPluginErrorCode_InternalError = -1 /*!< Internal error */,
182 OrthancPluginErrorCode_Success = 0 /*!< Success */,
183 OrthancPluginErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */,
184 OrthancPluginErrorCode_NotImplemented = 2 /*!< Not implemented yet */,
185 OrthancPluginErrorCode_ParameterOutOfRange = 3 /*!< Parameter out of range */,
186 OrthancPluginErrorCode_NotEnoughMemory = 4 /*!< Not enough memory */,
187 OrthancPluginErrorCode_BadParameterType = 5 /*!< Bad type for a parameter */,
188 OrthancPluginErrorCode_BadSequenceOfCalls = 6 /*!< Bad sequence of calls */,
189 OrthancPluginErrorCode_InexistentItem = 7 /*!< Accessing an inexistent item */,
190 OrthancPluginErrorCode_BadRequest = 8 /*!< Bad request */,
191 OrthancPluginErrorCode_NetworkProtocol = 9 /*!< Error in the network protocol */,
192 OrthancPluginErrorCode_SystemCommand = 10 /*!< Error while calling a system command */,
193 OrthancPluginErrorCode_Database = 11 /*!< Error with the database engine */,
194 OrthancPluginErrorCode_UriSyntax = 12 /*!< Badly formatted URI */,
195 OrthancPluginErrorCode_InexistentFile = 13 /*!< Inexistent file */,
196 OrthancPluginErrorCode_CannotWriteFile = 14 /*!< Cannot write to file */,
197 OrthancPluginErrorCode_BadFileFormat = 15 /*!< Bad file format */,
198 OrthancPluginErrorCode_Timeout = 16 /*!< Timeout */,
199 OrthancPluginErrorCode_UnknownResource = 17 /*!< Unknown resource */,
200 OrthancPluginErrorCode_IncompatibleDatabaseVersion = 18 /*!< Incompatible version of the database */,
201 OrthancPluginErrorCode_FullStorage = 19 /*!< The file storage is full */,
202 OrthancPluginErrorCode_CorruptedFile = 20 /*!< Corrupted file (e.g. inconsistent MD5 hash) */,
203 OrthancPluginErrorCode_InexistentTag = 21 /*!< Inexistent tag */,
204 OrthancPluginErrorCode_ReadOnly = 22 /*!< Cannot modify a read-only data structure */,
205 OrthancPluginErrorCode_IncompatibleImageFormat = 23 /*!< Incompatible format of the images */,
206 OrthancPluginErrorCode_IncompatibleImageSize = 24 /*!< Incompatible size of the images */,
207 OrthancPluginErrorCode_SharedLibrary = 25 /*!< Error while using a shared library (plugin) */,
208 OrthancPluginErrorCode_UnknownPluginService = 26 /*!< Plugin invoking an unknown service */,
209 OrthancPluginErrorCode_UnknownDicomTag = 27 /*!< Unknown DICOM tag */,
210 OrthancPluginErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */,
211 OrthancPluginErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */,
212 OrthancPluginErrorCode_BadFont = 30 /*!< Badly formatted font file */,
213 OrthancPluginErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */,
214 OrthancPluginErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */,
215 OrthancPluginErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */,
216 OrthancPluginErrorCode_SQLiteStatementAlreadyUsed = 1003 /*!< SQLite: This cached statement is already being referred to */,
217 OrthancPluginErrorCode_SQLiteExecute = 1004 /*!< SQLite: Cannot execute a command */,
218 OrthancPluginErrorCode_SQLiteRollbackWithoutTransaction = 1005 /*!< SQLite: Rolling back a nonexistent transaction (have you called Begin()?) */,
219 OrthancPluginErrorCode_SQLiteCommitWithoutTransaction = 1006 /*!< SQLite: Committing a nonexistent transaction */,
220 OrthancPluginErrorCode_SQLiteRegisterFunction = 1007 /*!< SQLite: Unable to register a function */,
221 OrthancPluginErrorCode_SQLiteFlush = 1008 /*!< SQLite: Unable to flush the database */,
222 OrthancPluginErrorCode_SQLiteCannotRun = 1009 /*!< SQLite: Cannot run a cached statement */,
223 OrthancPluginErrorCode_SQLiteCannotStep = 1010 /*!< SQLite: Cannot step over a cached statement */,
224 OrthancPluginErrorCode_SQLiteBindOutOfRange = 1011 /*!< SQLite: Bing a value while out of range (serious error) */,
225 OrthancPluginErrorCode_SQLitePrepareStatement = 1012 /*!< SQLite: Cannot prepare a cached statement */,
226 OrthancPluginErrorCode_SQLiteTransactionAlreadyStarted = 1013 /*!< SQLite: Beginning the same transaction twice */,
227 OrthancPluginErrorCode_SQLiteTransactionCommit = 1014 /*!< SQLite: Failure when committing the transaction */,
228 OrthancPluginErrorCode_SQLiteTransactionBegin = 1015 /*!< SQLite: Cannot start a transaction */,
229 OrthancPluginErrorCode_DirectoryOverFile = 2000 /*!< The directory to be created is already occupied by a regular file */,
230 OrthancPluginErrorCode_FileStorageCannotWrite = 2001 /*!< Unable to create a subdirectory or a file in the file storage */,
231 OrthancPluginErrorCode_DirectoryExpected = 2002 /*!< The specified path does not point to a directory */,
232 OrthancPluginErrorCode_HttpPortInUse = 2003 /*!< The TCP port of the HTTP server is already in use */,
233 OrthancPluginErrorCode_DicomPortInUse = 2004 /*!< The TCP port of the DICOM server is already in use */,
234 OrthancPluginErrorCode_BadHttpStatusInRest = 2005 /*!< This HTTP status is not allowed in a REST API */,
235 OrthancPluginErrorCode_RegularFileExpected = 2006 /*!< The specified path does not point to a regular file */,
236 OrthancPluginErrorCode_PathToExecutable = 2007 /*!< Unable to get the path to the executable */,
237 OrthancPluginErrorCode_MakeDirectory = 2008 /*!< Cannot create a directory */,
238 OrthancPluginErrorCode_BadApplicationEntityTitle = 2009 /*!< An application entity title (AET) cannot be empty or be longer than 16 characters */,
239 OrthancPluginErrorCode_NoCFindHandler = 2010 /*!< No request handler factory for DICOM C-FIND SCP */,
240 OrthancPluginErrorCode_NoCMoveHandler = 2011 /*!< No request handler factory for DICOM C-MOVE SCP */,
241 OrthancPluginErrorCode_NoCStoreHandler = 2012 /*!< No request handler factory for DICOM C-STORE SCP */,
242 OrthancPluginErrorCode_NoApplicationEntityFilter = 2013 /*!< No application entity filter */,
243 OrthancPluginErrorCode_NoSopClassOrInstance = 2014 /*!< DicomUserConnection: Unable to find the SOP class and instance */,
244 OrthancPluginErrorCode_NoPresentationContext = 2015 /*!< DicomUserConnection: No acceptable presentation context for modality */,
245 OrthancPluginErrorCode_DicomFindUnavailable = 2016 /*!< DicomUserConnection: The C-FIND command is not supported by the remote SCP */,
246 OrthancPluginErrorCode_DicomMoveUnavailable = 2017 /*!< DicomUserConnection: The C-MOVE command is not supported by the remote SCP */,
247 OrthancPluginErrorCode_CannotStoreInstance = 2018 /*!< Cannot store an instance */,
248 OrthancPluginErrorCode_CreateDicomNotString = 2019 /*!< Only string values are supported when creating DICOM instances */,
249 OrthancPluginErrorCode_CreateDicomOverrideTag = 2020 /*!< Trying to override a value inherited from a parent module */,
250 OrthancPluginErrorCode_CreateDicomUseContent = 2021 /*!< Use \"Content\" to inject an image into a new DICOM instance */,
251 OrthancPluginErrorCode_CreateDicomNoPayload = 2022 /*!< No payload is present for one instance in the series */,
252 OrthancPluginErrorCode_CreateDicomUseDataUriScheme = 2023 /*!< The payload of the DICOM instance must be specified according to Data URI scheme */,
253 OrthancPluginErrorCode_CreateDicomBadParent = 2024 /*!< Trying to attach a new DICOM instance to an inexistent resource */,
254 OrthancPluginErrorCode_CreateDicomParentIsInstance = 2025 /*!< Trying to attach a new DICOM instance to an instance (must be a series, study or patient) */,
255 OrthancPluginErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */,
256 OrthancPluginErrorCode_UnknownModality = 2027 /*!< Unknown modality */,
257 OrthancPluginErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */,
258 OrthancPluginErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */,
259 OrthancPluginErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */,
260 OrthancPluginErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */,
261 OrthancPluginErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */,
262 OrthancPluginErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */,
263 OrthancPluginErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */,
264 OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */,
265
266 _OrthancPluginErrorCode_INTERNAL = 0x7fffffff
267 } OrthancPluginErrorCode;
268
269
270 /**
271 * Forward declaration of one of the mandatory functions for Orthanc
272 * plugins.
273 **/
274 ORTHANC_PLUGINS_API const char* OrthancPluginGetName();
275
276
277 /**
278 * The various HTTP methods for a REST call.
279 **/
280 typedef enum
281 {
282 OrthancPluginHttpMethod_Get = 1, /*!< GET request */
283 OrthancPluginHttpMethod_Post = 2, /*!< POST request */
284 OrthancPluginHttpMethod_Put = 3, /*!< PUT request */
285 OrthancPluginHttpMethod_Delete = 4, /*!< DELETE request */
286
287 _OrthancPluginHttpMethod_INTERNAL = 0x7fffffff
288 } OrthancPluginHttpMethod;
289
290
291 /**
292 * @brief The parameters of a REST request.
293 * @ingroup Callbacks
294 **/
295 typedef struct
296 {
297 /**
298 * @brief The HTTP method.
299 **/
300 OrthancPluginHttpMethod method;
301
302 /**
303 * @brief The number of groups of the regular expression.
304 **/
305 uint32_t groupsCount;
306
307 /**
308 * @brief The matched values for the groups of the regular expression.
309 **/
310 const char* const* groups;
311
312 /**
313 * @brief For a GET request, the number of GET parameters.
314 **/
315 uint32_t getCount;
316
317 /**
318 * @brief For a GET request, the keys of the GET parameters.
319 **/
320 const char* const* getKeys;
321
322 /**
323 * @brief For a GET request, the values of the GET parameters.
324 **/
325 const char* const* getValues;
326
327 /**
328 * @brief For a PUT or POST request, the content of the body.
329 **/
330 const char* body;
331
332 /**
333 * @brief For a PUT or POST request, the number of bytes of the body.
334 **/
335 uint32_t bodySize;
336
337
338 /* --------------------------------------------------
339 New in version 0.8.1
340 -------------------------------------------------- */
341
342 /**
343 * @brief The number of HTTP headers.
344 **/
345 uint32_t headersCount;
346
347 /**
348 * @brief The keys of the HTTP headers (always converted to low-case).
349 **/
350 const char* const* headersKeys;
351
352 /**
353 * @brief The values of the HTTP headers.
354 **/
355 const char* const* headersValues;
356
357 } OrthancPluginHttpRequest;
358
359
360 typedef enum
361 {
362 /* Generic services */
363 _OrthancPluginService_LogInfo = 1,
364 _OrthancPluginService_LogWarning = 2,
365 _OrthancPluginService_LogError = 3,
366 _OrthancPluginService_GetOrthancPath = 4,
367 _OrthancPluginService_GetOrthancDirectory = 5,
368 _OrthancPluginService_GetConfigurationPath = 6,
369 _OrthancPluginService_SetPluginProperty = 7,
370 _OrthancPluginService_GetGlobalProperty = 8,
371 _OrthancPluginService_SetGlobalProperty = 9,
372 _OrthancPluginService_GetCommandLineArgumentsCount = 10,
373 _OrthancPluginService_GetCommandLineArgument = 11,
374 _OrthancPluginService_GetExpectedDatabaseVersion = 12,
375 _OrthancPluginService_GetConfiguration = 13,
376 _OrthancPluginService_BufferCompression = 14,
377 _OrthancPluginService_ReadFile = 15,
378 _OrthancPluginService_WriteFile = 16,
379 _OrthancPluginService_GetErrorDescription = 17,
380 _OrthancPluginService_CallHttpClient = 18,
381
382 /* Registration of callbacks */
383 _OrthancPluginService_RegisterRestCallback = 1000,
384 _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001,
385 _OrthancPluginService_RegisterStorageArea = 1002,
386 _OrthancPluginService_RegisterOnChangeCallback = 1003,
387 _OrthancPluginService_RegisterRestCallbackNoLock = 1004,
388
389 /* Sending answers to REST calls */
390 _OrthancPluginService_AnswerBuffer = 2000,
391 _OrthancPluginService_CompressAndAnswerPngImage = 2001, /* Unused as of Orthanc 0.9.4 */
392 _OrthancPluginService_Redirect = 2002,
393 _OrthancPluginService_SendHttpStatusCode = 2003,
394 _OrthancPluginService_SendUnauthorized = 2004,
395 _OrthancPluginService_SendMethodNotAllowed = 2005,
396 _OrthancPluginService_SetCookie = 2006,
397 _OrthancPluginService_SetHttpHeader = 2007,
398 _OrthancPluginService_StartMultipartAnswer = 2008,
399 _OrthancPluginService_SendMultipartItem = 2009,
400 _OrthancPluginService_SendHttpStatus = 2010,
401 _OrthancPluginService_CompressAndAnswerImage = 2011,
402
403 /* Access to the Orthanc database and API */
404 _OrthancPluginService_GetDicomForInstance = 3000,
405 _OrthancPluginService_RestApiGet = 3001,
406 _OrthancPluginService_RestApiPost = 3002,
407 _OrthancPluginService_RestApiDelete = 3003,
408 _OrthancPluginService_RestApiPut = 3004,
409 _OrthancPluginService_LookupPatient = 3005,
410 _OrthancPluginService_LookupStudy = 3006,
411 _OrthancPluginService_LookupSeries = 3007,
412 _OrthancPluginService_LookupInstance = 3008,
413 _OrthancPluginService_LookupStudyWithAccessionNumber = 3009,
414 _OrthancPluginService_RestApiGetAfterPlugins = 3010,
415 _OrthancPluginService_RestApiPostAfterPlugins = 3011,
416 _OrthancPluginService_RestApiDeleteAfterPlugins = 3012,
417 _OrthancPluginService_RestApiPutAfterPlugins = 3013,
418
419 /* Access to DICOM instances */
420 _OrthancPluginService_GetInstanceRemoteAet = 4000,
421 _OrthancPluginService_GetInstanceSize = 4001,
422 _OrthancPluginService_GetInstanceData = 4002,
423 _OrthancPluginService_GetInstanceJson = 4003,
424 _OrthancPluginService_GetInstanceSimplifiedJson = 4004,
425 _OrthancPluginService_HasInstanceMetadata = 4005,
426 _OrthancPluginService_GetInstanceMetadata = 4006,
427
428 /* Services for plugins implementing a database back-end */
429 _OrthancPluginService_RegisterDatabaseBackend = 5000,
430 _OrthancPluginService_DatabaseAnswer = 5001,
431 _OrthancPluginService_RegisterDatabaseBackendV2 = 5002,
432 _OrthancPluginService_StorageAreaCreate = 5003,
433 _OrthancPluginService_StorageAreaRead = 5004,
434 _OrthancPluginService_StorageAreaRemove = 5005,
435
436 /* Primitives for handling images */
437 _OrthancPluginService_GetImagePixelFormat = 6000,
438 _OrthancPluginService_GetImageWidth = 6001,
439 _OrthancPluginService_GetImageHeight = 6002,
440 _OrthancPluginService_GetImagePitch = 6003,
441 _OrthancPluginService_GetImageBuffer = 6004,
442 _OrthancPluginService_UncompressImage = 6005,
443 _OrthancPluginService_FreeImage = 6006,
444 _OrthancPluginService_CompressImage = 6007,
445 _OrthancPluginService_ConvertPixelFormat = 6008,
446 _OrthancPluginService_GetFontsCount = 6009,
447 _OrthancPluginService_GetFontInfo = 6010,
448 _OrthancPluginService_DrawText = 6011,
449
450 _OrthancPluginService_INTERNAL = 0x7fffffff
451 } _OrthancPluginService;
452
453
454 typedef enum
455 {
456 _OrthancPluginProperty_Description = 1,
457 _OrthancPluginProperty_RootUri = 2,
458 _OrthancPluginProperty_OrthancExplorer = 3,
459
460 _OrthancPluginProperty_INTERNAL = 0x7fffffff
461 } _OrthancPluginProperty;
462
463
464
465 /**
466 * The memory layout of the pixels of an image.
467 * @ingroup Images
468 **/
469 typedef enum
470 {
471 /**
472 * @brief Graylevel 8bpp image.
473 *
474 * The image is graylevel. Each pixel is unsigned and stored in
475 * one byte.
476 **/
477 OrthancPluginPixelFormat_Grayscale8 = 1,
478
479 /**
480 * @brief Graylevel, unsigned 16bpp image.
481 *
482 * The image is graylevel. Each pixel is unsigned and stored in
483 * two bytes.
484 **/
485 OrthancPluginPixelFormat_Grayscale16 = 2,
486
487 /**
488 * @brief Graylevel, signed 16bpp image.
489 *
490 * The image is graylevel. Each pixel is signed and stored in two
491 * bytes.
492 **/
493 OrthancPluginPixelFormat_SignedGrayscale16 = 3,
494
495 /**
496 * @brief Color image in RGB24 format.
497 *
498 * This format describes a color image. The pixels are stored in 3
499 * consecutive bytes. The memory layout is RGB.
500 **/
501 OrthancPluginPixelFormat_RGB24 = 4,
502
503 /**
504 * @brief Color image in RGBA32 format.
505 *
506 * This format describes a color image. The pixels are stored in 4
507 * consecutive bytes. The memory layout is RGBA.
508 **/
509 OrthancPluginPixelFormat_RGBA32 = 5,
510
511 OrthancPluginPixelFormat_Unknown = 6, /*!< Unknown pixel format */
512
513 _OrthancPluginPixelFormat_INTERNAL = 0x7fffffff
514 } OrthancPluginPixelFormat;
515
516
517
518 /**
519 * The content types that are supported by Orthanc plugins.
520 **/
521 typedef enum
522 {
523 OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */
524 OrthancPluginContentType_Dicom = 1, /*!< DICOM */
525 OrthancPluginContentType_DicomAsJson = 2, /*!< JSON summary of a DICOM file */
526
527 _OrthancPluginContentType_INTERNAL = 0x7fffffff
528 } OrthancPluginContentType;
529
530
531
532 /**
533 * The supported types of DICOM resources.
534 **/
535 typedef enum
536 {
537 OrthancPluginResourceType_Patient = 0, /*!< Patient */
538 OrthancPluginResourceType_Study = 1, /*!< Study */
539 OrthancPluginResourceType_Series = 2, /*!< Series */
540 OrthancPluginResourceType_Instance = 3, /*!< Instance */
541
542 _OrthancPluginResourceType_INTERNAL = 0x7fffffff
543 } OrthancPluginResourceType;
544
545
546
547 /**
548 * The supported types of changes that can happen to DICOM resources.
549 * @ingroup Callbacks
550 **/
551 typedef enum
552 {
553 OrthancPluginChangeType_CompletedSeries = 0, /*!< Series is now complete */
554 OrthancPluginChangeType_Deleted = 1, /*!< Deleted resource */
555 OrthancPluginChangeType_NewChildInstance = 2, /*!< A new instance was added to this resource */
556 OrthancPluginChangeType_NewInstance = 3, /*!< New instance received */
557 OrthancPluginChangeType_NewPatient = 4, /*!< New patient created */
558 OrthancPluginChangeType_NewSeries = 5, /*!< New series created */
559 OrthancPluginChangeType_NewStudy = 6, /*!< New study created */
560 OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */
561 OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */
562 OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */
563
564 _OrthancPluginChangeType_INTERNAL = 0x7fffffff
565 } OrthancPluginChangeType;
566
567
568 /**
569 * The compression algorithms that are supported by the Orthanc core.
570 * @ingroup Images
571 **/
572 typedef enum
573 {
574 OrthancPluginCompressionType_Zlib = 0, /*!< Standard zlib compression */
575 OrthancPluginCompressionType_ZlibWithSize = 1, /*!< zlib, prefixed with uncompressed size (uint64_t) */
576 OrthancPluginCompressionType_Gzip = 2, /*!< Standard gzip compression */
577 OrthancPluginCompressionType_GzipWithSize = 3, /*!< gzip, prefixed with uncompressed size (uint64_t) */
578
579 _OrthancPluginCompressionType_INTERNAL = 0x7fffffff
580 } OrthancPluginCompressionType;
581
582
583 /**
584 * The image formats that are supported by the Orthanc core.
585 * @ingroup Images
586 **/
587 typedef enum
588 {
589 OrthancPluginImageFormat_Png = 0, /*!< Image compressed using PNG */
590 OrthancPluginImageFormat_Jpeg = 1, /*!< Image compressed using JPEG */
591
592 _OrthancPluginImageFormat_INTERNAL = 0x7fffffff
593 } OrthancPluginImageFormat;
594
595
596
597 /**
598 * @brief A memory buffer allocated by the core system of Orthanc.
599 *
600 * A memory buffer allocated by the core system of Orthanc. When the
601 * content of the buffer is not useful anymore, it must be free by a
602 * call to ::OrthancPluginFreeMemoryBuffer().
603 **/
604 typedef struct
605 {
606 /**
607 * @brief The content of the buffer.
608 **/
609 void* data;
610
611 /**
612 * @brief The number of bytes in the buffer.
613 **/
614 uint32_t size;
615 } OrthancPluginMemoryBuffer;
616
617
618
619
620 /**
621 * @brief Opaque structure that represents the HTTP connection to the client application.
622 * @ingroup Callback
623 **/
624 typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput;
625
626
627
628 /**
629 * @brief Opaque structure that represents a DICOM instance received by Orthanc.
630 **/
631 typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance;
632
633
634
635 /**
636 * @brief Opaque structure that represents an image that is uncompressed in memory.
637 * @ingroup Images
638 **/
639 typedef struct _OrthancPluginImage_t OrthancPluginImage;
640
641
642
643 /**
644 * @brief Opaque structure that represents the storage area that is actually used by Orthanc.
645 * @ingroup Images
646 **/
647 typedef struct _OrthancPluginStorageArea_t OrthancPluginStorageArea;
648
649
650
651 /**
652 * @brief Signature of a callback function that answers to a REST request.
653 * @ingroup Callbacks
654 **/
655 typedef int32_t (*OrthancPluginRestCallback) (
656 OrthancPluginRestOutput* output,
657 const char* url,
658 const OrthancPluginHttpRequest* request);
659
660
661
662 /**
663 * @brief Signature of a callback function that is triggered when Orthanc receives a DICOM instance.
664 * @ingroup Callbacks
665 **/
666 typedef int32_t (*OrthancPluginOnStoredInstanceCallback) (
667 OrthancPluginDicomInstance* instance,
668 const char* instanceId);
669
670
671
672 /**
673 * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource.
674 * @ingroup Callbacks
675 **/
676 typedef int32_t (*OrthancPluginOnChangeCallback) (
677 OrthancPluginChangeType changeType,
678 OrthancPluginResourceType resourceType,
679 const char* resourceId);
680
681
682
683 /**
684 * @brief Signature of a function to free dynamic memory.
685 **/
686 typedef void (*OrthancPluginFree) (void* buffer);
687
688
689
690 /**
691 * @brief Callback for writing to the storage area.
692 *
693 * Signature of a callback function that is triggered when Orthanc writes a file to the storage area.
694 *
695 * @param uuid The UUID of the file.
696 * @param content The content of the file.
697 * @param size The size of the file.
698 * @param type The content type corresponding to this file.
699 * @return 0 if success, other value if error.
700 * @ingroup Callbacks
701 **/
702 typedef int32_t (*OrthancPluginStorageCreate) (
703 const char* uuid,
704 const void* content,
705 int64_t size,
706 OrthancPluginContentType type);
707
708
709
710 /**
711 * @brief Callback for reading from the storage area.
712 *
713 * Signature of a callback function that is triggered when Orthanc reads a file from the storage area.
714 *
715 * @param content The content of the file (output).
716 * @param size The size of the file (output).
717 * @param uuid The UUID of the file of interest.
718 * @param type The content type corresponding to this file.
719 * @return 0 if success, other value if error.
720 * @ingroup Callbacks
721 **/
722 typedef int32_t (*OrthancPluginStorageRead) (
723 void** content,
724 int64_t* size,
725 const char* uuid,
726 OrthancPluginContentType type);
727
728
729
730 /**
731 * @brief Callback for removing a file from the storage area.
732 *
733 * Signature of a callback function that is triggered when Orthanc deletes a file from the storage area.
734 *
735 * @param uuid The UUID of the file to be removed.
736 * @param type The content type corresponding to this file.
737 * @return 0 if success, other value if error.
738 * @ingroup Callbacks
739 **/
740 typedef int32_t (*OrthancPluginStorageRemove) (
741 const char* uuid,
742 OrthancPluginContentType type);
743
744
745
746 /**
747 * @brief Data structure that contains information about the Orthanc core.
748 **/
749 typedef struct _OrthancPluginContext_t
750 {
751 void* pluginsManager;
752 const char* orthancVersion;
753 OrthancPluginFree Free;
754 OrthancPluginErrorCode (*InvokeService) (struct _OrthancPluginContext_t* context,
755 _OrthancPluginService service,
756 const void* params);
757 } OrthancPluginContext;
758
759
760
761 /**
762 * @brief Free a string.
763 *
764 * Free a string that was allocated by the core system of Orthanc.
765 *
766 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
767 * @param str The string to be freed.
768 **/
769 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString(
770 OrthancPluginContext* context,
771 char* str)
772 {
773 if (str != NULL)
774 {
775 context->Free(str);
776 }
777 }
778
779
780 /**
781 * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc.
782 *
783 * This function checks whether the version of this C header is
784 * compatible with the current version of Orthanc. The result of
785 * this function should always be checked in the
786 * OrthancPluginInitialize() entry point of the plugin.
787 *
788 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
789 * @return 1 if and only if the versions are compatible. If the
790 * result is 0, the initialization of the plugin should fail.
791 * @ingroup Callbacks
792 **/
793 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion(
794 OrthancPluginContext* context)
795 {
796 int major, minor, revision;
797
798 if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) ||
799 sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) ||
800 sizeof(int32_t) != sizeof(_OrthancPluginService) ||
801 sizeof(int32_t) != sizeof(_OrthancPluginProperty) ||
802 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) ||
803 sizeof(int32_t) != sizeof(OrthancPluginContentType) ||
804 sizeof(int32_t) != sizeof(OrthancPluginResourceType) ||
805 sizeof(int32_t) != sizeof(OrthancPluginChangeType) ||
806 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) ||
807 sizeof(int32_t) != sizeof(OrthancPluginImageFormat))
808 {
809 /* Mismatch in the size of the enumerations */
810 return 0;
811 }
812
813 /* Assume compatibility with the mainline */
814 if (!strcmp(context->orthancVersion, "mainline"))
815 {
816 return 1;
817 }
818
819 /* Parse the version of the Orthanc core */
820 if (
821 #ifdef _MSC_VER
822 sscanf_s
823 #else
824 sscanf
825 #endif
826 (context->orthancVersion, "%4d.%4d.%4d", &major, &minor, &revision) != 3)
827 {
828 return 0;
829 }
830
831 /* Check the major number of the version */
832
833 if (major > ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER)
834 {
835 return 1;
836 }
837
838 if (major < ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER)
839 {
840 return 0;
841 }
842
843 /* Check the minor number of the version */
844
845 if (minor > ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER)
846 {
847 return 1;
848 }
849
850 if (minor < ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER)
851 {
852 return 0;
853 }
854
855 /* Check the revision number of the version */
856
857 if (revision >= ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER)
858 {
859 return 1;
860 }
861 else
862 {
863 return 0;
864 }
865 }
866
867
868 /**
869 * @brief Free a memory buffer.
870 *
871 * Free a memory buffer that was allocated by the core system of Orthanc.
872 *
873 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
874 * @param buffer The memory buffer to release.
875 **/
876 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer(
877 OrthancPluginContext* context,
878 OrthancPluginMemoryBuffer* buffer)
879 {
880 context->Free(buffer->data);
881 }
882
883
884 /**
885 * @brief Log an error.
886 *
887 * Log an error message using the Orthanc logging system.
888 *
889 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
890 * @param message The message to be logged.
891 **/
892 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError(
893 OrthancPluginContext* context,
894 const char* message)
895 {
896 context->InvokeService(context, _OrthancPluginService_LogError, message);
897 }
898
899
900 /**
901 * @brief Log a warning.
902 *
903 * Log a warning message using the Orthanc logging system.
904 *
905 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
906 * @param message The message to be logged.
907 **/
908 ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning(
909 OrthancPluginContext* context,
910 const char* message)
911 {
912 context->InvokeService(context, _OrthancPluginService_LogWarning, message);
913 }
914
915
916 /**
917 * @brief Log an information.
918 *
919 * Log an information message using the Orthanc logging system.
920 *
921 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
922 * @param message The message to be logged.
923 **/
924 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo(
925 OrthancPluginContext* context,
926 const char* message)
927 {
928 context->InvokeService(context, _OrthancPluginService_LogInfo, message);
929 }
930
931
932
933 typedef struct
934 {
935 const char* pathRegularExpression;
936 OrthancPluginRestCallback callback;
937 } _OrthancPluginRestCallback;
938
939 /**
940 * @brief Register a REST callback.
941 *
942 * This function registers a REST callback against a regular
943 * expression for a URI. This function must be called during the
944 * initialization of the plugin, i.e. inside the
945 * OrthancPluginInitialize() public function.
946 *
947 * Each REST callback is guaranteed to run in mutual exclusion.
948 *
949 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
950 * @param pathRegularExpression Regular expression for the URI. May contain groups.
951 * @param callback The callback function to handle the REST call.
952 * @see OrthancPluginRegisterRestCallbackNoLock()
953 * @ingroup Callbacks
954 **/
955 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback(
956 OrthancPluginContext* context,
957 const char* pathRegularExpression,
958 OrthancPluginRestCallback callback)
959 {
960 _OrthancPluginRestCallback params;
961 params.pathRegularExpression = pathRegularExpression;
962 params.callback = callback;
963 context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, &params);
964 }
965
966
967
968 /**
969 * @brief Register a REST callback, without locking.
970 *
971 * This function registers a REST callback against a regular
972 * expression for a URI. This function must be called during the
973 * initialization of the plugin, i.e. inside the
974 * OrthancPluginInitialize() public function.
975 *
976 * Contrarily to OrthancPluginRegisterRestCallback(), the callback
977 * will NOT be invoked in mutual exclusion. This can be useful for
978 * high-performance plugins that must handle concurrent requests
979 * (Orthanc uses a pool of threads, one thread being assigned to
980 * each incoming HTTP request). Of course, it is up to the plugin to
981 * implement the required locking mechanisms.
982 *
983 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
984 * @param pathRegularExpression Regular expression for the URI. May contain groups.
985 * @param callback The callback function to handle the REST call.
986 * @see OrthancPluginRegisterRestCallback()
987 * @ingroup Callbacks
988 **/
989 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallbackNoLock(
990 OrthancPluginContext* context,
991 const char* pathRegularExpression,
992 OrthancPluginRestCallback callback)
993 {
994 _OrthancPluginRestCallback params;
995 params.pathRegularExpression = pathRegularExpression;
996 params.callback = callback;
997 context->InvokeService(context, _OrthancPluginService_RegisterRestCallbackNoLock, &params);
998 }
999
1000
1001
1002 typedef struct
1003 {
1004 OrthancPluginOnStoredInstanceCallback callback;
1005 } _OrthancPluginOnStoredInstanceCallback;
1006
1007 /**
1008 * @brief Register a callback for received instances.
1009 *
1010 * This function registers a callback function that is called
1011 * whenever a new DICOM instance is stored into the Orthanc core.
1012 *
1013 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1014 * @param callback The callback function.
1015 * @ingroup Callbacks
1016 **/
1017 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback(
1018 OrthancPluginContext* context,
1019 OrthancPluginOnStoredInstanceCallback callback)
1020 {
1021 _OrthancPluginOnStoredInstanceCallback params;
1022 params.callback = callback;
1023
1024 context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, &params);
1025 }
1026
1027
1028
1029 typedef struct
1030 {
1031 OrthancPluginRestOutput* output;
1032 const char* answer;
1033 uint32_t answerSize;
1034 const char* mimeType;
1035 } _OrthancPluginAnswerBuffer;
1036
1037 /**
1038 * @brief Answer to a REST request.
1039 *
1040 * This function answers to a REST request with the content of a memory buffer.
1041 *
1042 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1043 * @param output The HTTP connection to the client application.
1044 * @param answer Pointer to the memory buffer containing the answer.
1045 * @param answerSize Number of bytes of the answer.
1046 * @param mimeType The MIME type of the answer.
1047 * @ingroup REST
1048 **/
1049 ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer(
1050 OrthancPluginContext* context,
1051 OrthancPluginRestOutput* output,
1052 const char* answer,
1053 uint32_t answerSize,
1054 const char* mimeType)
1055 {
1056 _OrthancPluginAnswerBuffer params;
1057 params.output = output;
1058 params.answer = answer;
1059 params.answerSize = answerSize;
1060 params.mimeType = mimeType;
1061 context->InvokeService(context, _OrthancPluginService_AnswerBuffer, &params);
1062 }
1063
1064
1065 typedef struct
1066 {
1067 OrthancPluginRestOutput* output;
1068 OrthancPluginPixelFormat format;
1069 uint32_t width;
1070 uint32_t height;
1071 uint32_t pitch;
1072 const void* buffer;
1073 } _OrthancPluginCompressAndAnswerPngImage;
1074
1075 typedef struct
1076 {
1077 OrthancPluginRestOutput* output;
1078 OrthancPluginImageFormat imageFormat;
1079 OrthancPluginPixelFormat pixelFormat;
1080 uint32_t width;
1081 uint32_t height;
1082 uint32_t pitch;
1083 const void* buffer;
1084 uint8_t quality;
1085 } _OrthancPluginCompressAndAnswerImage;
1086
1087
1088 /**
1089 * @brief Answer to a REST request with a PNG image.
1090 *
1091 * This function answers to a REST request with a PNG image. The
1092 * parameters of this function describe a memory buffer that
1093 * contains an uncompressed image. The image will be automatically compressed
1094 * as a PNG image by the core system of Orthanc.
1095 *
1096 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1097 * @param output The HTTP connection to the client application.
1098 * @param format The memory layout of the uncompressed image.
1099 * @param width The width of the image.
1100 * @param height The height of the image.
1101 * @param pitch The pitch of the image (i.e. the number of bytes
1102 * between 2 successive lines of the image in the memory buffer).
1103 * @param buffer The memory buffer containing the uncompressed image.
1104 * @ingroup REST
1105 **/
1106 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage(
1107 OrthancPluginContext* context,
1108 OrthancPluginRestOutput* output,
1109 OrthancPluginPixelFormat format,
1110 uint32_t width,
1111 uint32_t height,
1112 uint32_t pitch,
1113 const void* buffer)
1114 {
1115 _OrthancPluginCompressAndAnswerImage params;
1116 params.output = output;
1117 params.imageFormat = OrthancPluginImageFormat_Png;
1118 params.pixelFormat = format;
1119 params.width = width;
1120 params.height = height;
1121 params.pitch = pitch;
1122 params.buffer = buffer;
1123 params.quality = 0; /* No quality for PNG */
1124 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, &params);
1125 }
1126
1127
1128
1129 typedef struct
1130 {
1131 OrthancPluginMemoryBuffer* target;
1132 const char* instanceId;
1133 } _OrthancPluginGetDicomForInstance;
1134
1135 /**
1136 * @brief Retrieve a DICOM instance using its Orthanc identifier.
1137 *
1138 * Retrieve a DICOM instance using its Orthanc identifier. The DICOM
1139 * file is stored into a newly allocated memory buffer.
1140 *
1141 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1142 * @param target The target memory buffer.
1143 * @param instanceId The Orthanc identifier of the DICOM instance of interest.
1144 * @return 0 if success, or the error code if failure.
1145 * @ingroup Orthanc
1146 **/
1147 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetDicomForInstance(
1148 OrthancPluginContext* context,
1149 OrthancPluginMemoryBuffer* target,
1150 const char* instanceId)
1151 {
1152 _OrthancPluginGetDicomForInstance params;
1153 params.target = target;
1154 params.instanceId = instanceId;
1155 return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, &params);
1156 }
1157
1158
1159
1160 typedef struct
1161 {
1162 OrthancPluginMemoryBuffer* target;
1163 const char* uri;
1164 } _OrthancPluginRestApiGet;
1165
1166 /**
1167 * @brief Make a GET call to the built-in Orthanc REST API.
1168 *
1169 * Make a GET call to the built-in Orthanc REST API. The result to
1170 * the query is stored into a newly allocated memory buffer.
1171 *
1172 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1173 * @param target The target memory buffer.
1174 * @param uri The URI in the built-in Orthanc API.
1175 * @return 0 if success, or the error code if failure.
1176 * @see OrthancPluginRestApiGetAfterPlugins
1177 * @ingroup Orthanc
1178 **/
1179 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet(
1180 OrthancPluginContext* context,
1181 OrthancPluginMemoryBuffer* target,
1182 const char* uri)
1183 {
1184 _OrthancPluginRestApiGet params;
1185 params.target = target;
1186 params.uri = uri;
1187 return context->InvokeService(context, _OrthancPluginService_RestApiGet, &params);
1188 }
1189
1190
1191
1192 /**
1193 * @brief Make a GET call to the REST API, as tainted by the plugins.
1194 *
1195 * Make a GET call to the Orthanc REST API, after all the plugins
1196 * are applied. In other words, if some plugin overrides or adds the
1197 * called URI to the built-in Orthanc REST API, this call will
1198 * return the result provided by this plugin. The result to the
1199 * query is stored into a newly allocated memory buffer.
1200 *
1201 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1202 * @param target The target memory buffer.
1203 * @param uri The URI in the built-in Orthanc API.
1204 * @return 0 if success, or the error code if failure.
1205 * @see OrthancPluginRestApiGet
1206 * @ingroup Orthanc
1207 **/
1208 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGetAfterPlugins(
1209 OrthancPluginContext* context,
1210 OrthancPluginMemoryBuffer* target,
1211 const char* uri)
1212 {
1213 _OrthancPluginRestApiGet params;
1214 params.target = target;
1215 params.uri = uri;
1216 return context->InvokeService(context, _OrthancPluginService_RestApiGetAfterPlugins, &params);
1217 }
1218
1219
1220
1221 typedef struct
1222 {
1223 OrthancPluginMemoryBuffer* target;
1224 const char* uri;
1225 const char* body;
1226 uint32_t bodySize;
1227 } _OrthancPluginRestApiPostPut;
1228
1229 /**
1230 * @brief Make a POST call to the built-in Orthanc REST API.
1231 *
1232 * Make a POST call to the built-in Orthanc REST API. The result to
1233 * the query is stored into a newly allocated memory buffer.
1234 *
1235 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1236 * @param target The target memory buffer.
1237 * @param uri The URI in the built-in Orthanc API.
1238 * @param body The body of the POST request.
1239 * @param bodySize The size of the body.
1240 * @return 0 if success, or the error code if failure.
1241 * @see OrthancPluginRestApiPostAfterPlugins
1242 * @ingroup Orthanc
1243 **/
1244 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPost(
1245 OrthancPluginContext* context,
1246 OrthancPluginMemoryBuffer* target,
1247 const char* uri,
1248 const char* body,
1249 uint32_t bodySize)
1250 {
1251 _OrthancPluginRestApiPostPut params;
1252 params.target = target;
1253 params.uri = uri;
1254 params.body = body;
1255 params.bodySize = bodySize;
1256 return context->InvokeService(context, _OrthancPluginService_RestApiPost, &params);
1257 }
1258
1259
1260 /**
1261 * @brief Make a POST call to the REST API, as tainted by the plugins.
1262 *
1263 * Make a POST call to the Orthanc REST API, after all the plugins
1264 * are applied. In other words, if some plugin overrides or adds the
1265 * called URI to the built-in Orthanc REST API, this call will
1266 * return the result provided by this plugin. The result to the
1267 * query is stored into a newly allocated memory buffer.
1268 *
1269 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1270 * @param target The target memory buffer.
1271 * @param uri The URI in the built-in Orthanc API.
1272 * @param body The body of the POST request.
1273 * @param bodySize The size of the body.
1274 * @return 0 if success, or the error code if failure.
1275 * @see OrthancPluginRestApiPost
1276 * @ingroup Orthanc
1277 **/
1278 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPostAfterPlugins(
1279 OrthancPluginContext* context,
1280 OrthancPluginMemoryBuffer* target,
1281 const char* uri,
1282 const char* body,
1283 uint32_t bodySize)
1284 {
1285 _OrthancPluginRestApiPostPut params;
1286 params.target = target;
1287 params.uri = uri;
1288 params.body = body;
1289 params.bodySize = bodySize;
1290 return context->InvokeService(context, _OrthancPluginService_RestApiPostAfterPlugins, &params);
1291 }
1292
1293
1294
1295 /**
1296 * @brief Make a DELETE call to the built-in Orthanc REST API.
1297 *
1298 * Make a DELETE call to the built-in Orthanc REST API.
1299 *
1300 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1301 * @param uri The URI to delete in the built-in Orthanc API.
1302 * @return 0 if success, or the error code if failure.
1303 * @see OrthancPluginRestApiDeleteAfterPlugins
1304 * @ingroup Orthanc
1305 **/
1306 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDelete(
1307 OrthancPluginContext* context,
1308 const char* uri)
1309 {
1310 return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri);
1311 }
1312
1313
1314 /**
1315 * @brief Make a DELETE call to the REST API, as tainted by the plugins.
1316 *
1317 * Make a DELETE call to the Orthanc REST API, after all the plugins
1318 * are applied. In other words, if some plugin overrides or adds the
1319 * called URI to the built-in Orthanc REST API, this call will
1320 * return the result provided by this plugin.
1321 *
1322 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1323 * @param uri The URI to delete in the built-in Orthanc API.
1324 * @return 0 if success, or the error code if failure.
1325 * @see OrthancPluginRestApiDelete
1326 * @ingroup Orthanc
1327 **/
1328 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDeleteAfterPlugins(
1329 OrthancPluginContext* context,
1330 const char* uri)
1331 {
1332 return context->InvokeService(context, _OrthancPluginService_RestApiDeleteAfterPlugins, uri);
1333 }
1334
1335
1336
1337 /**
1338 * @brief Make a PUT call to the built-in Orthanc REST API.
1339 *
1340 * Make a PUT call to the built-in Orthanc REST API. The result to
1341 * the query is stored into a newly allocated memory buffer.
1342 *
1343 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1344 * @param target The target memory buffer.
1345 * @param uri The URI in the built-in Orthanc API.
1346 * @param body The body of the PUT request.
1347 * @param bodySize The size of the body.
1348 * @return 0 if success, or the error code if failure.
1349 * @see OrthancPluginRestApiPutAfterPlugins
1350 * @ingroup Orthanc
1351 **/
1352 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPut(
1353 OrthancPluginContext* context,
1354 OrthancPluginMemoryBuffer* target,
1355 const char* uri,
1356 const char* body,
1357 uint32_t bodySize)
1358 {
1359 _OrthancPluginRestApiPostPut params;
1360 params.target = target;
1361 params.uri = uri;
1362 params.body = body;
1363 params.bodySize = bodySize;
1364 return context->InvokeService(context, _OrthancPluginService_RestApiPut, &params);
1365 }
1366
1367
1368
1369 /**
1370 * @brief Make a PUT call to the REST API, as tainted by the plugins.
1371 *
1372 * Make a PUT call to the Orthanc REST API, after all the plugins
1373 * are applied. In other words, if some plugin overrides or adds the
1374 * called URI to the built-in Orthanc REST API, this call will
1375 * return the result provided by this plugin. The result to the
1376 * query is stored into a newly allocated memory buffer.
1377 *
1378 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1379 * @param target The target memory buffer.
1380 * @param uri The URI in the built-in Orthanc API.
1381 * @param body The body of the PUT request.
1382 * @param bodySize The size of the body.
1383 * @return 0 if success, or the error code if failure.
1384 * @see OrthancPluginRestApiPut
1385 * @ingroup Orthanc
1386 **/
1387 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPutAfterPlugins(
1388 OrthancPluginContext* context,
1389 OrthancPluginMemoryBuffer* target,
1390 const char* uri,
1391 const char* body,
1392 uint32_t bodySize)
1393 {
1394 _OrthancPluginRestApiPostPut params;
1395 params.target = target;
1396 params.uri = uri;
1397 params.body = body;
1398 params.bodySize = bodySize;
1399 return context->InvokeService(context, _OrthancPluginService_RestApiPutAfterPlugins, &params);
1400 }
1401
1402
1403
1404 typedef struct
1405 {
1406 OrthancPluginRestOutput* output;
1407 const char* argument;
1408 } _OrthancPluginOutputPlusArgument;
1409
1410 /**
1411 * @brief Redirect a REST request.
1412 *
1413 * This function answers to a REST request by redirecting the user
1414 * to another URI using HTTP status 301.
1415 *
1416 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1417 * @param output The HTTP connection to the client application.
1418 * @param redirection Where to redirect.
1419 * @ingroup REST
1420 **/
1421 ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect(
1422 OrthancPluginContext* context,
1423 OrthancPluginRestOutput* output,
1424 const char* redirection)
1425 {
1426 _OrthancPluginOutputPlusArgument params;
1427 params.output = output;
1428 params.argument = redirection;
1429 context->InvokeService(context, _OrthancPluginService_Redirect, &params);
1430 }
1431
1432
1433
1434 typedef struct
1435 {
1436 char** result;
1437 const char* argument;
1438 } _OrthancPluginRetrieveDynamicString;
1439
1440 /**
1441 * @brief Look for a patient.
1442 *
1443 * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020).
1444 * This function uses the database index to run as fast as possible (it does not loop
1445 * over all the stored patients).
1446 *
1447 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1448 * @param patientID The Patient ID of interest.
1449 * @return The NULL value if the patient is non-existent, or a string containing the
1450 * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString().
1451 * @ingroup Orthanc
1452 **/
1453 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient(
1454 OrthancPluginContext* context,
1455 const char* patientID)
1456 {
1457 char* result;
1458
1459 _OrthancPluginRetrieveDynamicString params;
1460 params.result = &result;
1461 params.argument = patientID;
1462
1463 if (context->InvokeService(context, _OrthancPluginService_LookupPatient, &params) != OrthancPluginErrorCode_Success)
1464 {
1465 /* Error */
1466 return NULL;
1467 }
1468 else
1469 {
1470 return result;
1471 }
1472 }
1473
1474
1475 /**
1476 * @brief Look for a study.
1477 *
1478 * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d).
1479 * This function uses the database index to run as fast as possible (it does not loop
1480 * over all the stored studies).
1481 *
1482 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1483 * @param studyUID The Study Instance UID of interest.
1484 * @return The NULL value if the study is non-existent, or a string containing the
1485 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
1486 * @ingroup Orthanc
1487 **/
1488 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy(
1489 OrthancPluginContext* context,
1490 const char* studyUID)
1491 {
1492 char* result;
1493
1494 _OrthancPluginRetrieveDynamicString params;
1495 params.result = &result;
1496 params.argument = studyUID;
1497
1498 if (context->InvokeService(context, _OrthancPluginService_LookupStudy, &params) != OrthancPluginErrorCode_Success)
1499 {
1500 /* Error */
1501 return NULL;
1502 }
1503 else
1504 {
1505 return result;
1506 }
1507 }
1508
1509
1510 /**
1511 * @brief Look for a study, using the accession number.
1512 *
1513 * Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050).
1514 * This function uses the database index to run as fast as possible (it does not loop
1515 * over all the stored studies).
1516 *
1517 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1518 * @param accessionNumber The Accession Number of interest.
1519 * @return The NULL value if the study is non-existent, or a string containing the
1520 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
1521 * @ingroup Orthanc
1522 **/
1523 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber(
1524 OrthancPluginContext* context,
1525 const char* accessionNumber)
1526 {
1527 char* result;
1528
1529 _OrthancPluginRetrieveDynamicString params;
1530 params.result = &result;
1531 params.argument = accessionNumber;
1532
1533 if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, &params) != OrthancPluginErrorCode_Success)
1534 {
1535 /* Error */
1536 return NULL;
1537 }
1538 else
1539 {
1540 return result;
1541 }
1542 }
1543
1544
1545 /**
1546 * @brief Look for a series.
1547 *
1548 * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e).
1549 * This function uses the database index to run as fast as possible (it does not loop
1550 * over all the stored series).
1551 *
1552 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1553 * @param seriesUID The Series Instance UID of interest.
1554 * @return The NULL value if the series is non-existent, or a string containing the
1555 * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString().
1556 * @ingroup Orthanc
1557 **/
1558 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries(
1559 OrthancPluginContext* context,
1560 const char* seriesUID)
1561 {
1562 char* result;
1563
1564 _OrthancPluginRetrieveDynamicString params;
1565 params.result = &result;
1566 params.argument = seriesUID;
1567
1568 if (context->InvokeService(context, _OrthancPluginService_LookupSeries, &params) != OrthancPluginErrorCode_Success)
1569 {
1570 /* Error */
1571 return NULL;
1572 }
1573 else
1574 {
1575 return result;
1576 }
1577 }
1578
1579
1580 /**
1581 * @brief Look for an instance.
1582 *
1583 * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018).
1584 * This function uses the database index to run as fast as possible (it does not loop
1585 * over all the stored instances).
1586 *
1587 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1588 * @param sopInstanceUID The SOP Instance UID of interest.
1589 * @return The NULL value if the instance is non-existent, or a string containing the
1590 * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString().
1591 * @ingroup Orthanc
1592 **/
1593 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance(
1594 OrthancPluginContext* context,
1595 const char* sopInstanceUID)
1596 {
1597 char* result;
1598
1599 _OrthancPluginRetrieveDynamicString params;
1600 params.result = &result;
1601 params.argument = sopInstanceUID;
1602
1603 if (context->InvokeService(context, _OrthancPluginService_LookupInstance, &params) != OrthancPluginErrorCode_Success)
1604 {
1605 /* Error */
1606 return NULL;
1607 }
1608 else
1609 {
1610 return result;
1611 }
1612 }
1613
1614
1615
1616 typedef struct
1617 {
1618 OrthancPluginRestOutput* output;
1619 uint16_t status;
1620 } _OrthancPluginSendHttpStatusCode;
1621
1622 /**
1623 * @brief Send a HTTP status code.
1624 *
1625 * This function answers to a REST request by sending a HTTP status
1626 * code (such as "400 - Bad Request"). Note that:
1627 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
1628 * - Redirections (status 301) must use ::OrthancPluginRedirect().
1629 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
1630 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
1631 *
1632 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1633 * @param output The HTTP connection to the client application.
1634 * @param status The HTTP status code to be sent.
1635 * @ingroup REST
1636 * @see OrthancPluginSendHttpStatus()
1637 **/
1638 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode(
1639 OrthancPluginContext* context,
1640 OrthancPluginRestOutput* output,
1641 uint16_t status)
1642 {
1643 _OrthancPluginSendHttpStatusCode params;
1644 params.output = output;
1645 params.status = status;
1646 context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, &params);
1647 }
1648
1649
1650 /**
1651 * @brief Signal that a REST request is not authorized.
1652 *
1653 * This function answers to a REST request by signaling that it is
1654 * not authorized.
1655 *
1656 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1657 * @param output The HTTP connection to the client application.
1658 * @param realm The realm for the authorization process.
1659 * @ingroup REST
1660 **/
1661 ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized(
1662 OrthancPluginContext* context,
1663 OrthancPluginRestOutput* output,
1664 const char* realm)
1665 {
1666 _OrthancPluginOutputPlusArgument params;
1667 params.output = output;
1668 params.argument = realm;
1669 context->InvokeService(context, _OrthancPluginService_SendUnauthorized, &params);
1670 }
1671
1672
1673 /**
1674 * @brief Signal that this URI does not support this HTTP method.
1675 *
1676 * This function answers to a REST request by signaling that the
1677 * queried URI does not support this method.
1678 *
1679 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1680 * @param output The HTTP connection to the client application.
1681 * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request).
1682 * @ingroup REST
1683 **/
1684 ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed(
1685 OrthancPluginContext* context,
1686 OrthancPluginRestOutput* output,
1687 const char* allowedMethods)
1688 {
1689 _OrthancPluginOutputPlusArgument params;
1690 params.output = output;
1691 params.argument = allowedMethods;
1692 context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, &params);
1693 }
1694
1695
1696 typedef struct
1697 {
1698 OrthancPluginRestOutput* output;
1699 const char* key;
1700 const char* value;
1701 } _OrthancPluginSetHttpHeader;
1702
1703 /**
1704 * @brief Set a cookie.
1705 *
1706 * This function sets a cookie in the HTTP client.
1707 *
1708 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1709 * @param output The HTTP connection to the client application.
1710 * @param cookie The cookie to be set.
1711 * @param value The value of the cookie.
1712 * @ingroup REST
1713 **/
1714 ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie(
1715 OrthancPluginContext* context,
1716 OrthancPluginRestOutput* output,
1717 const char* cookie,
1718 const char* value)
1719 {
1720 _OrthancPluginSetHttpHeader params;
1721 params.output = output;
1722 params.key = cookie;
1723 params.value = value;
1724 context->InvokeService(context, _OrthancPluginService_SetCookie, &params);
1725 }
1726
1727
1728 /**
1729 * @brief Set some HTTP header.
1730 *
1731 * This function sets a HTTP header in the HTTP answer.
1732 *
1733 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1734 * @param output The HTTP connection to the client application.
1735 * @param key The HTTP header to be set.
1736 * @param value The value of the HTTP header.
1737 * @ingroup REST
1738 **/
1739 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader(
1740 OrthancPluginContext* context,
1741 OrthancPluginRestOutput* output,
1742 const char* key,
1743 const char* value)
1744 {
1745 _OrthancPluginSetHttpHeader params;
1746 params.output = output;
1747 params.key = key;
1748 params.value = value;
1749 context->InvokeService(context, _OrthancPluginService_SetHttpHeader, &params);
1750 }
1751
1752
1753 typedef struct
1754 {
1755 char** resultStringToFree;
1756 const char** resultString;
1757 int64_t* resultInt64;
1758 const char* key;
1759 OrthancPluginDicomInstance* instance;
1760 } _OrthancPluginAccessDicomInstance;
1761
1762
1763 /**
1764 * @brief Get the AET of a DICOM instance.
1765 *
1766 * This function returns the Application Entity Title (AET) of the
1767 * DICOM modality from which a DICOM instance originates.
1768 *
1769 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1770 * @param instance The instance of interest.
1771 * @return The AET if success, NULL if error.
1772 * @ingroup Callbacks
1773 **/
1774 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet(
1775 OrthancPluginContext* context,
1776 OrthancPluginDicomInstance* instance)
1777 {
1778 const char* result;
1779
1780 _OrthancPluginAccessDicomInstance params;
1781 memset(&params, 0, sizeof(params));
1782 params.resultString = &result;
1783 params.instance = instance;
1784
1785 if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, &params) != OrthancPluginErrorCode_Success)
1786 {
1787 /* Error */
1788 return NULL;
1789 }
1790 else
1791 {
1792 return result;
1793 }
1794 }
1795
1796
1797 /**
1798 * @brief Get the size of a DICOM file.
1799 *
1800 * This function returns the number of bytes of the given DICOM instance.
1801 *
1802 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1803 * @param instance The instance of interest.
1804 * @return The size of the file, -1 in case of error.
1805 * @ingroup Callbacks
1806 **/
1807 ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize(
1808 OrthancPluginContext* context,
1809 OrthancPluginDicomInstance* instance)
1810 {
1811 int64_t size;
1812
1813 _OrthancPluginAccessDicomInstance params;
1814 memset(&params, 0, sizeof(params));
1815 params.resultInt64 = &size;
1816 params.instance = instance;
1817
1818 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, &params) != OrthancPluginErrorCode_Success)
1819 {
1820 /* Error */
1821 return -1;
1822 }
1823 else
1824 {
1825 return size;
1826 }
1827 }
1828
1829
1830 /**
1831 * @brief Get the data of a DICOM file.
1832 *
1833 * This function returns a pointer to the content of the given DICOM instance.
1834 *
1835 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1836 * @param instance The instance of interest.
1837 * @return The pointer to the DICOM data, NULL in case of error.
1838 * @ingroup Callbacks
1839 **/
1840 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceData(
1841 OrthancPluginContext* context,
1842 OrthancPluginDicomInstance* instance)
1843 {
1844 const char* result;
1845
1846 _OrthancPluginAccessDicomInstance params;
1847 memset(&params, 0, sizeof(params));
1848 params.resultString = &result;
1849 params.instance = instance;
1850
1851 if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, &params) != OrthancPluginErrorCode_Success)
1852 {
1853 /* Error */
1854 return NULL;
1855 }
1856 else
1857 {
1858 return result;
1859 }
1860 }
1861
1862
1863 /**
1864 * @brief Get the DICOM tag hierarchy as a JSON file.
1865 *
1866 * This function returns a pointer to a newly created string
1867 * containing a JSON file. This JSON file encodes the tag hierarchy
1868 * of the given DICOM instance.
1869 *
1870 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1871 * @param instance The instance of interest.
1872 * @return The NULL value in case of error, or a string containing the JSON file.
1873 * This string must be freed by OrthancPluginFreeString().
1874 * @ingroup Callbacks
1875 **/
1876 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson(
1877 OrthancPluginContext* context,
1878 OrthancPluginDicomInstance* instance)
1879 {
1880 char* result;
1881
1882 _OrthancPluginAccessDicomInstance params;
1883 memset(&params, 0, sizeof(params));
1884 params.resultStringToFree = &result;
1885 params.instance = instance;
1886
1887 if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, &params) != OrthancPluginErrorCode_Success)
1888 {
1889 /* Error */
1890 return NULL;
1891 }
1892 else
1893 {
1894 return result;
1895 }
1896 }
1897
1898
1899 /**
1900 * @brief Get the DICOM tag hierarchy as a JSON file (with simplification).
1901 *
1902 * This function returns a pointer to a newly created string
1903 * containing a JSON file. This JSON file encodes the tag hierarchy
1904 * of the given DICOM instance. In contrast with
1905 * ::OrthancPluginGetInstanceJson(), the returned JSON file is in
1906 * its simplified version.
1907 *
1908 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1909 * @param instance The instance of interest.
1910 * @return The NULL value in case of error, or a string containing the JSON file.
1911 * This string must be freed by OrthancPluginFreeString().
1912 * @ingroup Callbacks
1913 **/
1914 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson(
1915 OrthancPluginContext* context,
1916 OrthancPluginDicomInstance* instance)
1917 {
1918 char* result;
1919
1920 _OrthancPluginAccessDicomInstance params;
1921 memset(&params, 0, sizeof(params));
1922 params.resultStringToFree = &result;
1923 params.instance = instance;
1924
1925 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, &params) != OrthancPluginErrorCode_Success)
1926 {
1927 /* Error */
1928 return NULL;
1929 }
1930 else
1931 {
1932 return result;
1933 }
1934 }
1935
1936
1937 /**
1938 * @brief Check whether a DICOM instance is associated with some metadata.
1939 *
1940 * This function checks whether the DICOM instance of interest is
1941 * associated with some metadata. As of Orthanc 0.8.1, in the
1942 * callbacks registered by
1943 * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only
1944 * possibly available metadata are "ReceptionDate", "RemoteAET" and
1945 * "IndexInSeries".
1946 *
1947 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1948 * @param instance The instance of interest.
1949 * @param metadata The metadata of interest.
1950 * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error.
1951 * @ingroup Callbacks
1952 **/
1953 ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata(
1954 OrthancPluginContext* context,
1955 OrthancPluginDicomInstance* instance,
1956 const char* metadata)
1957 {
1958 int64_t result;
1959
1960 _OrthancPluginAccessDicomInstance params;
1961 memset(&params, 0, sizeof(params));
1962 params.resultInt64 = &result;
1963 params.instance = instance;
1964 params.key = metadata;
1965
1966 if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, &params) != OrthancPluginErrorCode_Success)
1967 {
1968 /* Error */
1969 return -1;
1970 }
1971 else
1972 {
1973 return (result != 0);
1974 }
1975 }
1976
1977
1978 /**
1979 * @brief Get the value of some metadata associated with a given DICOM instance.
1980 *
1981 * This functions returns the value of some metadata that is associated with the DICOM instance of interest.
1982 * Before calling this function, the existence of the metadata must have been checked with
1983 * ::OrthancPluginHasInstanceMetadata().
1984 *
1985 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1986 * @param instance The instance of interest.
1987 * @param metadata The metadata of interest.
1988 * @return The metadata value if success, NULL if error.
1989 * @ingroup Callbacks
1990 **/
1991 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata(
1992 OrthancPluginContext* context,
1993 OrthancPluginDicomInstance* instance,
1994 const char* metadata)
1995 {
1996 const char* result;
1997
1998 _OrthancPluginAccessDicomInstance params;
1999 memset(&params, 0, sizeof(params));
2000 params.resultString = &result;
2001 params.instance = instance;
2002 params.key = metadata;
2003
2004 if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, &params) != OrthancPluginErrorCode_Success)
2005 {
2006 /* Error */
2007 return NULL;
2008 }
2009 else
2010 {
2011 return result;
2012 }
2013 }
2014
2015
2016
2017 typedef struct
2018 {
2019 OrthancPluginStorageCreate create;
2020 OrthancPluginStorageRead read;
2021 OrthancPluginStorageRemove remove;
2022 OrthancPluginFree free;
2023 } _OrthancPluginRegisterStorageArea;
2024
2025 /**
2026 * @brief Register a custom storage area.
2027 *
2028 * This function registers a custom storage area, to replace the
2029 * built-in way Orthanc stores its files on the filesystem. This
2030 * function must be called during the initialization of the plugin,
2031 * i.e. inside the OrthancPluginInitialize() public function.
2032 *
2033 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2034 * @param create The callback function to store a file on the custom storage area.
2035 * @param read The callback function to read a file from the custom storage area.
2036 * @param remove The callback function to remove a file from the custom storage area.
2037 * @ingroup Callbacks
2038 **/
2039 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea(
2040 OrthancPluginContext* context,
2041 OrthancPluginStorageCreate create,
2042 OrthancPluginStorageRead read,
2043 OrthancPluginStorageRemove remove)
2044 {
2045 _OrthancPluginRegisterStorageArea params;
2046 params.create = create;
2047 params.read = read;
2048 params.remove = remove;
2049
2050 #ifdef __cplusplus
2051 params.free = ::free;
2052 #else
2053 params.free = free;
2054 #endif
2055
2056 context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, &params);
2057 }
2058
2059
2060
2061 /**
2062 * @brief Return the path to the Orthanc executable.
2063 *
2064 * This function returns the path to the Orthanc executable.
2065 *
2066 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2067 * @return NULL in the case of an error, or a newly allocated string
2068 * containing the path. This string must be freed by
2069 * OrthancPluginFreeString().
2070 **/
2071 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context)
2072 {
2073 char* result;
2074
2075 _OrthancPluginRetrieveDynamicString params;
2076 params.result = &result;
2077 params.argument = NULL;
2078
2079 if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, &params) != OrthancPluginErrorCode_Success)
2080 {
2081 /* Error */
2082 return NULL;
2083 }
2084 else
2085 {
2086 return result;
2087 }
2088 }
2089
2090
2091 /**
2092 * @brief Return the directory containing the Orthanc.
2093 *
2094 * This function returns the path to the directory containing the Orthanc executable.
2095 *
2096 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2097 * @return NULL in the case of an error, or a newly allocated string
2098 * containing the path. This string must be freed by
2099 * OrthancPluginFreeString().
2100 **/
2101 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context)
2102 {
2103 char* result;
2104
2105 _OrthancPluginRetrieveDynamicString params;
2106 params.result = &result;
2107 params.argument = NULL;
2108
2109 if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, &params) != OrthancPluginErrorCode_Success)
2110 {
2111 /* Error */
2112 return NULL;
2113 }
2114 else
2115 {
2116 return result;
2117 }
2118 }
2119
2120
2121 /**
2122 * @brief Return the path to the configuration file(s).
2123 *
2124 * This function returns the path to the configuration file(s) that
2125 * was specified when starting Orthanc. Since version 0.9.1, this
2126 * path can refer to a folder that stores a set of configuration
2127 * files. This function is deprecated in favor of
2128 * OrthancPluginGetConfiguration().
2129 *
2130 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2131 * @return NULL in the case of an error, or a newly allocated string
2132 * containing the path. This string must be freed by
2133 * OrthancPluginFreeString().
2134 * @see OrthancPluginGetConfiguration()
2135 **/
2136 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context)
2137 {
2138 char* result;
2139
2140 _OrthancPluginRetrieveDynamicString params;
2141 params.result = &result;
2142 params.argument = NULL;
2143
2144 if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, &params) != OrthancPluginErrorCode_Success)
2145 {
2146 /* Error */
2147 return NULL;
2148 }
2149 else
2150 {
2151 return result;
2152 }
2153 }
2154
2155
2156
2157 typedef struct
2158 {
2159 OrthancPluginOnChangeCallback callback;
2160 } _OrthancPluginOnChangeCallback;
2161
2162 /**
2163 * @brief Register a callback to monitor changes.
2164 *
2165 * This function registers a callback function that is called
2166 * whenever a change happens to some DICOM resource.
2167 *
2168 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2169 * @param callback The callback function.
2170 * @ingroup Callbacks
2171 **/
2172 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnChangeCallback(
2173 OrthancPluginContext* context,
2174 OrthancPluginOnChangeCallback callback)
2175 {
2176 _OrthancPluginOnChangeCallback params;
2177 params.callback = callback;
2178
2179 context->InvokeService(context, _OrthancPluginService_RegisterOnChangeCallback, &params);
2180 }
2181
2182
2183
2184 typedef struct
2185 {
2186 const char* plugin;
2187 _OrthancPluginProperty property;
2188 const char* value;
2189 } _OrthancPluginSetPluginProperty;
2190
2191
2192 /**
2193 * @brief Set the URI where the plugin provides its Web interface.
2194 *
2195 * For plugins that come with a Web interface, this function
2196 * declares the entry path where to find this interface. This
2197 * information is notably used in the "Plugins" page of Orthanc
2198 * Explorer.
2199 *
2200 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2201 * @param uri The root URI for this plugin.
2202 **/
2203 ORTHANC_PLUGIN_INLINE void OrthancPluginSetRootUri(
2204 OrthancPluginContext* context,
2205 const char* uri)
2206 {
2207 _OrthancPluginSetPluginProperty params;
2208 params.plugin = OrthancPluginGetName();
2209 params.property = _OrthancPluginProperty_RootUri;
2210 params.value = uri;
2211
2212 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
2213 }
2214
2215
2216 /**
2217 * @brief Set a description for this plugin.
2218 *
2219 * Set a description for this plugin. It is displayed in the
2220 * "Plugins" page of Orthanc Explorer.
2221 *
2222 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2223 * @param description The description.
2224 **/
2225 ORTHANC_PLUGIN_INLINE void OrthancPluginSetDescription(
2226 OrthancPluginContext* context,
2227 const char* description)
2228 {
2229 _OrthancPluginSetPluginProperty params;
2230 params.plugin = OrthancPluginGetName();
2231 params.property = _OrthancPluginProperty_Description;
2232 params.value = description;
2233
2234 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
2235 }
2236
2237
2238 /**
2239 * @brief Extend the JavaScript code of Orthanc Explorer.
2240 *
2241 * Add JavaScript code to customize the default behavior of Orthanc
2242 * Explorer. This can for instance be used to add new buttons.
2243 *
2244 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2245 * @param javascript The custom JavaScript code.
2246 **/
2247 ORTHANC_PLUGIN_INLINE void OrthancPluginExtendOrthancExplorer(
2248 OrthancPluginContext* context,
2249 const char* javascript)
2250 {
2251 _OrthancPluginSetPluginProperty params;
2252 params.plugin = OrthancPluginGetName();
2253 params.property = _OrthancPluginProperty_OrthancExplorer;
2254 params.value = javascript;
2255
2256 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
2257 }
2258
2259
2260 typedef struct
2261 {
2262 char** result;
2263 int32_t property;
2264 const char* value;
2265 } _OrthancPluginGlobalProperty;
2266
2267
2268 /**
2269 * @brief Get the value of a global property.
2270 *
2271 * Get the value of a global property that is stored in the Orthanc database. Global
2272 * properties whose index is below 1024 are reserved by Orthanc.
2273 *
2274 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2275 * @param property The global property of interest.
2276 * @param defaultValue The value to return, if the global property is unset.
2277 * @return The value of the global property, or NULL in the case of an error. This
2278 * string must be freed by OrthancPluginFreeString().
2279 * @ingroup Orthanc
2280 **/
2281 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetGlobalProperty(
2282 OrthancPluginContext* context,
2283 int32_t property,
2284 const char* defaultValue)
2285 {
2286 char* result;
2287
2288 _OrthancPluginGlobalProperty params;
2289 params.result = &result;
2290 params.property = property;
2291 params.value = defaultValue;
2292
2293 if (context->InvokeService(context, _OrthancPluginService_GetGlobalProperty, &params) != OrthancPluginErrorCode_Success)
2294 {
2295 /* Error */
2296 return NULL;
2297 }
2298 else
2299 {
2300 return result;
2301 }
2302 }
2303
2304
2305 /**
2306 * @brief Set the value of a global property.
2307 *
2308 * Set the value of a global property into the Orthanc
2309 * database. Setting a global property can be used by plugins to
2310 * save their internal parameters. Plugins are only allowed to set
2311 * properties whose index are above or equal to 1024 (properties
2312 * below 1024 are read-only and reserved by Orthanc).
2313 *
2314 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2315 * @param property The global property of interest.
2316 * @param value The value to be set in the global property.
2317 * @return 0 if success, or the error code if failure.
2318 * @ingroup Orthanc
2319 **/
2320 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetGlobalProperty(
2321 OrthancPluginContext* context,
2322 int32_t property,
2323 const char* value)
2324 {
2325 _OrthancPluginGlobalProperty params;
2326 params.result = NULL;
2327 params.property = property;
2328 params.value = value;
2329
2330 return context->InvokeService(context, _OrthancPluginService_SetGlobalProperty, &params);
2331 }
2332
2333
2334
2335 typedef struct
2336 {
2337 int32_t *resultInt32;
2338 uint32_t *resultUint32;
2339 int64_t *resultInt64;
2340 uint64_t *resultUint64;
2341 } _OrthancPluginReturnSingleValue;
2342
2343 /**
2344 * @brief Get the number of command-line arguments.
2345 *
2346 * Retrieve the number of command-line arguments that were used to launch Orthanc.
2347 *
2348 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2349 * @return The number of arguments.
2350 **/
2351 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetCommandLineArgumentsCount(
2352 OrthancPluginContext* context)
2353 {
2354 uint32_t count = 0;
2355
2356 _OrthancPluginReturnSingleValue params;
2357 memset(&params, 0, sizeof(params));
2358 params.resultUint32 = &count;
2359
2360 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgumentsCount, &params) != OrthancPluginErrorCode_Success)
2361 {
2362 /* Error */
2363 return 0;
2364 }
2365 else
2366 {
2367 return count;
2368 }
2369 }
2370
2371
2372
2373 /**
2374 * @brief Get the value of a command-line argument.
2375 *
2376 * Get the value of one of the command-line arguments that were used
2377 * to launch Orthanc. The number of available arguments can be
2378 * retrieved by OrthancPluginGetCommandLineArgumentsCount().
2379 *
2380 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2381 * @param argument The index of the argument.
2382 * @return The value of the argument, or NULL in the case of an error. This
2383 * string must be freed by OrthancPluginFreeString().
2384 **/
2385 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetCommandLineArgument(
2386 OrthancPluginContext* context,
2387 uint32_t argument)
2388 {
2389 char* result;
2390
2391 _OrthancPluginGlobalProperty params;
2392 params.result = &result;
2393 params.property = (int32_t) argument;
2394 params.value = NULL;
2395
2396 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgument, &params) != OrthancPluginErrorCode_Success)
2397 {
2398 /* Error */
2399 return NULL;
2400 }
2401 else
2402 {
2403 return result;
2404 }
2405 }
2406
2407
2408 /**
2409 * @brief Get the expected version of the database schema.
2410 *
2411 * Retrieve the expected version of the database schema.
2412 *
2413 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2414 * @return The version.
2415 * @ingroup Callbacks
2416 * @deprecated Please instead use IDatabaseBackend::UpgradeDatabase()
2417 **/
2418 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion(
2419 OrthancPluginContext* context)
2420 {
2421 uint32_t count = 0;
2422
2423 _OrthancPluginReturnSingleValue params;
2424 memset(&params, 0, sizeof(params));
2425 params.resultUint32 = &count;
2426
2427 if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, &params) != OrthancPluginErrorCode_Success)
2428 {
2429 /* Error */
2430 return 0;
2431 }
2432 else
2433 {
2434 return count;
2435 }
2436 }
2437
2438
2439
2440 /**
2441 * @brief Return the content of the configuration file(s).
2442 *
2443 * This function returns the content of the configuration that is
2444 * used by Orthanc, formatted as a JSON string.
2445 *
2446 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2447 * @return NULL in the case of an error, or a newly allocated string
2448 * containing the configuration. This string must be freed by
2449 * OrthancPluginFreeString().
2450 **/
2451 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfiguration(OrthancPluginContext* context)
2452 {
2453 char* result;
2454
2455 _OrthancPluginRetrieveDynamicString params;
2456 params.result = &result;
2457 params.argument = NULL;
2458
2459 if (context->InvokeService(context, _OrthancPluginService_GetConfiguration, &params) != OrthancPluginErrorCode_Success)
2460 {
2461 /* Error */
2462 return NULL;
2463 }
2464 else
2465 {
2466 return result;
2467 }
2468 }
2469
2470
2471
2472 typedef struct
2473 {
2474 OrthancPluginRestOutput* output;
2475 const char* subType;
2476 const char* contentType;
2477 } _OrthancPluginStartMultipartAnswer;
2478
2479 /**
2480 * @brief Start an HTTP multipart answer.
2481 *
2482 * Initiates a HTTP multipart answer, as the result of a REST request.
2483 *
2484 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2485 * @param output The HTTP connection to the client application.
2486 * @param subType The sub-type of the multipart answer ("mixed" or "related").
2487 * @param contentType The MIME type of the items in the multipart answer.
2488 * @return 0 if success, or the error code if failure.
2489 * @see OrthancPluginSendMultipartItem()
2490 * @ingroup REST
2491 **/
2492 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStartMultipartAnswer(
2493 OrthancPluginContext* context,
2494 OrthancPluginRestOutput* output,
2495 const char* subType,
2496 const char* contentType)
2497 {
2498 _OrthancPluginStartMultipartAnswer params;
2499 params.output = output;
2500 params.subType = subType;
2501 params.contentType = contentType;
2502 return context->InvokeService(context, _OrthancPluginService_StartMultipartAnswer, &params);
2503 }
2504
2505
2506 /**
2507 * @brief Send an item as a part of some HTTP multipart answer.
2508 *
2509 * This function sends an item as a part of some HTTP multipart
2510 * answer that was initiated by OrthancPluginStartMultipartAnswer().
2511 *
2512 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2513 * @param output The HTTP connection to the client application.
2514 * @param answer Pointer to the memory buffer containing the item.
2515 * @param answerSize Number of bytes of the item.
2516 * @return 0 if success, or the error code if failure (this notably happens
2517 * if the connection is closed by the client).
2518 * @ingroup REST
2519 **/
2520 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem(
2521 OrthancPluginContext* context,
2522 OrthancPluginRestOutput* output,
2523 const char* answer,
2524 uint32_t answerSize)
2525 {
2526 _OrthancPluginAnswerBuffer params;
2527 params.output = output;
2528 params.answer = answer;
2529 params.answerSize = answerSize;
2530 params.mimeType = NULL;
2531 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem, &params);
2532 }
2533
2534
2535
2536 typedef struct
2537 {
2538 OrthancPluginMemoryBuffer* target;
2539 const void* source;
2540 uint32_t size;
2541 OrthancPluginCompressionType compression;
2542 uint8_t uncompress;
2543 } _OrthancPluginBufferCompression;
2544
2545
2546 /**
2547 * @brief Compress or decompress a buffer.
2548 *
2549 * This function compresses or decompresses a buffer, using the
2550 * version of the zlib library that is used by the Orthanc core.
2551 *
2552 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2553 * @param target The target memory buffer.
2554 * @param source The source buffer.
2555 * @param size The size in bytes of the source buffer.
2556 * @param compression The compression algorithm.
2557 * @param uncompress If set to "0", the buffer must be compressed.
2558 * If set to "1", the buffer must be uncompressed.
2559 * @return 0 if success, or the error code if failure.
2560 * @ingroup Images
2561 **/
2562 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginBufferCompression(
2563 OrthancPluginContext* context,
2564 OrthancPluginMemoryBuffer* target,
2565 const void* source,
2566 uint32_t size,
2567 OrthancPluginCompressionType compression,
2568 uint8_t uncompress)
2569 {
2570 _OrthancPluginBufferCompression params;
2571 params.target = target;
2572 params.source = source;
2573 params.size = size;
2574 params.compression = compression;
2575 params.uncompress = uncompress;
2576
2577 return context->InvokeService(context, _OrthancPluginService_BufferCompression, &params);
2578 }
2579
2580
2581
2582 typedef struct
2583 {
2584 OrthancPluginMemoryBuffer* target;
2585 const char* path;
2586 } _OrthancPluginReadFile;
2587
2588 /**
2589 * @brief Read a file.
2590 *
2591 * Read the content of a file on the filesystem, and returns it into
2592 * a newly allocated memory buffer.
2593 *
2594 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2595 * @param target The target memory buffer.
2596 * @param path The path of the file to be read.
2597 * @return 0 if success, or the error code if failure.
2598 **/
2599 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReadFile(
2600 OrthancPluginContext* context,
2601 OrthancPluginMemoryBuffer* target,
2602 const char* path)
2603 {
2604 _OrthancPluginReadFile params;
2605 params.target = target;
2606 params.path = path;
2607 return context->InvokeService(context, _OrthancPluginService_ReadFile, &params);
2608 }
2609
2610
2611
2612 typedef struct
2613 {
2614 const char* path;
2615 const void* data;
2616 uint32_t size;
2617 } _OrthancPluginWriteFile;
2618
2619 /**
2620 * @brief Write a file.
2621 *
2622 * Write the content of a memory buffer to the filesystem.
2623 *
2624 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2625 * @param path The path of the file to be written.
2626 * @param data The content of the memory buffer.
2627 * @param size The size of the memory buffer.
2628 * @return 0 if success, or the error code if failure.
2629 **/
2630 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWriteFile(
2631 OrthancPluginContext* context,
2632 const char* path,
2633 const void* data,
2634 uint32_t size)
2635 {
2636 _OrthancPluginWriteFile params;
2637 params.path = path;
2638 params.data = data;
2639 params.size = size;
2640 return context->InvokeService(context, _OrthancPluginService_WriteFile, &params);
2641 }
2642
2643
2644
2645 typedef struct
2646 {
2647 const char** target;
2648 OrthancPluginErrorCode error;
2649 } _OrthancPluginGetErrorDescription;
2650
2651 /**
2652 * @brief Get the description of a given error code.
2653 *
2654 * This function returns the description of a given error code.
2655 *
2656 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2657 * @param error The error code of interest.
2658 * @return The error description. This is a statically-allocated
2659 * string, do not free it.
2660 **/
2661 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetErrorDescription(
2662 OrthancPluginContext* context,
2663 OrthancPluginErrorCode error)
2664 {
2665 const char* result = NULL;
2666
2667 _OrthancPluginGetErrorDescription params;
2668 params.target = &result;
2669 params.error = error;
2670
2671 if (context->InvokeService(context, _OrthancPluginService_GetErrorDescription, &params) != OrthancPluginErrorCode_Success ||
2672 result == NULL)
2673 {
2674 return "Unknown error code";
2675 }
2676 else
2677 {
2678 return result;
2679 }
2680 }
2681
2682
2683
2684 typedef struct
2685 {
2686 OrthancPluginRestOutput* output;
2687 uint16_t status;
2688 const char* body;
2689 uint32_t bodySize;
2690 } _OrthancPluginSendHttpStatus;
2691
2692 /**
2693 * @brief Send a HTTP status, with a custom body.
2694 *
2695 * This function answers to a HTTP request by sending a HTTP status
2696 * code (such as "400 - Bad Request"), together with a body
2697 * describing the error. The body will only be returned if the
2698 * configuration option "HttpDescribeErrors" of Orthanc is set to "true".
2699 *
2700 * Note that:
2701 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
2702 * - Redirections (status 301) must use ::OrthancPluginRedirect().
2703 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
2704 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
2705 *
2706 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2707 * @param output The HTTP connection to the client application.
2708 * @param status The HTTP status code to be sent.
2709 * @param body The body of the answer.
2710 * @param bodySize The size of the body.
2711 * @see OrthancPluginSendHttpStatusCode()
2712 * @ingroup REST
2713 **/
2714 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatus(
2715 OrthancPluginContext* context,
2716 OrthancPluginRestOutput* output,
2717 uint16_t status,
2718 const char* body,
2719 uint32_t bodySize)
2720 {
2721 _OrthancPluginSendHttpStatus params;
2722 params.output = output;
2723 params.status = status;
2724 params.body = body;
2725 params.bodySize = bodySize;
2726 context->InvokeService(context, _OrthancPluginService_SendHttpStatus, &params);
2727 }
2728
2729
2730
2731 typedef struct
2732 {
2733 const OrthancPluginImage* image;
2734 uint32_t* resultUint32;
2735 OrthancPluginPixelFormat* resultPixelFormat;
2736 const void** resultBuffer;
2737 } _OrthancPluginGetImageInfo;
2738
2739
2740 /**
2741 * @brief Return the pixel format of an image.
2742 *
2743 * This function returns the type of memory layout for the pixels of the given image.
2744 *
2745 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2746 * @param image The image of interest.
2747 * @return The pixel format.
2748 * @ingroup Images
2749 **/
2750 ORTHANC_PLUGIN_INLINE OrthancPluginPixelFormat OrthancPluginGetImagePixelFormat(
2751 OrthancPluginContext* context,
2752 const OrthancPluginImage* image)
2753 {
2754 OrthancPluginPixelFormat target;
2755
2756 _OrthancPluginGetImageInfo params;
2757 memset(&params, 0, sizeof(params));
2758 params.image = image;
2759 params.resultPixelFormat = &target;
2760
2761 if (context->InvokeService(context, _OrthancPluginService_GetImagePixelFormat, &params) != OrthancPluginErrorCode_Success)
2762 {
2763 return OrthancPluginPixelFormat_Unknown;
2764 }
2765 else
2766 {
2767 return (OrthancPluginPixelFormat) target;
2768 }
2769 }
2770
2771
2772
2773 /**
2774 * @brief Return the width of an image.
2775 *
2776 * This function returns the width of the given image.
2777 *
2778 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2779 * @param image The image of interest.
2780 * @return The width.
2781 * @ingroup Images
2782 **/
2783 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageWidth(
2784 OrthancPluginContext* context,
2785 const OrthancPluginImage* image)
2786 {
2787 uint32_t width;
2788
2789 _OrthancPluginGetImageInfo params;
2790 memset(&params, 0, sizeof(params));
2791 params.image = image;
2792 params.resultUint32 = &width;
2793
2794 if (context->InvokeService(context, _OrthancPluginService_GetImageWidth, &params) != OrthancPluginErrorCode_Success)
2795 {
2796 return 0;
2797 }
2798 else
2799 {
2800 return width;
2801 }
2802 }
2803
2804
2805
2806 /**
2807 * @brief Return the height of an image.
2808 *
2809 * This function returns the height of the given image.
2810 *
2811 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2812 * @param image The image of interest.
2813 * @return The height.
2814 * @ingroup Images
2815 **/
2816 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageHeight(
2817 OrthancPluginContext* context,
2818 const OrthancPluginImage* image)
2819 {
2820 uint32_t height;
2821
2822 _OrthancPluginGetImageInfo params;
2823 memset(&params, 0, sizeof(params));
2824 params.image = image;
2825 params.resultUint32 = &height;
2826
2827 if (context->InvokeService(context, _OrthancPluginService_GetImageHeight, &params) != OrthancPluginErrorCode_Success)
2828 {
2829 return 0;
2830 }
2831 else
2832 {
2833 return height;
2834 }
2835 }
2836
2837
2838
2839 /**
2840 * @brief Return the pitch of an image.
2841 *
2842 * This function returns the pitch of the given image. The pitch is
2843 * defined as the number of bytes between 2 successive lines of the
2844 * image in the memory buffer.
2845 *
2846 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2847 * @param image The image of interest.
2848 * @return The pitch.
2849 * @ingroup Images
2850 **/
2851 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImagePitch(
2852 OrthancPluginContext* context,
2853 const OrthancPluginImage* image)
2854 {
2855 uint32_t pitch;
2856
2857 _OrthancPluginGetImageInfo params;
2858 memset(&params, 0, sizeof(params));
2859 params.image = image;
2860 params.resultUint32 = &pitch;
2861
2862 if (context->InvokeService(context, _OrthancPluginService_GetImagePitch, &params) != OrthancPluginErrorCode_Success)
2863 {
2864 return 0;
2865 }
2866 else
2867 {
2868 return pitch;
2869 }
2870 }
2871
2872
2873
2874 /**
2875 * @brief Return a pointer to the content of an image.
2876 *
2877 * This function returns a pointer to the memory buffer that
2878 * contains the pixels of the image.
2879 *
2880 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2881 * @param image The image of interest.
2882 * @return The pointer.
2883 * @ingroup Images
2884 **/
2885 ORTHANC_PLUGIN_INLINE const void* OrthancPluginGetImageBuffer(
2886 OrthancPluginContext* context,
2887 const OrthancPluginImage* image)
2888 {
2889 const void* target = NULL;
2890
2891 _OrthancPluginGetImageInfo params;
2892 memset(&params, 0, sizeof(params));
2893 params.resultBuffer = &target;
2894 params.image = image;
2895
2896 if (context->InvokeService(context, _OrthancPluginService_GetImageBuffer, &params) != OrthancPluginErrorCode_Success)
2897 {
2898 return NULL;
2899 }
2900 else
2901 {
2902 return target;
2903 }
2904 }
2905
2906
2907 typedef struct
2908 {
2909 OrthancPluginImage** target;
2910 const void* data;
2911 uint32_t size;
2912 OrthancPluginImageFormat format;
2913 } _OrthancPluginUncompressImage;
2914
2915
2916 /**
2917 * @brief Decode a compressed image.
2918 *
2919 * This function decodes a compressed image from a memory buffer.
2920 *
2921 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2922 * @param data Pointer to a memory buffer containing the compressed image.
2923 * @param size Size of the memory buffer containing the compressed image.
2924 * @param format The file format of the compressed image.
2925 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage().
2926 * @ingroup Images
2927 **/
2928 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginUncompressImage(
2929 OrthancPluginContext* context,
2930 const void* data,
2931 uint32_t size,
2932 OrthancPluginImageFormat format)
2933 {
2934 OrthancPluginImage* target = NULL;
2935
2936 _OrthancPluginUncompressImage params;
2937 memset(&params, 0, sizeof(params));
2938 params.target = &target;
2939 params.data = data;
2940 params.size = size;
2941 params.format = format;
2942
2943 if (context->InvokeService(context, _OrthancPluginService_UncompressImage, &params) != OrthancPluginErrorCode_Success)
2944 {
2945 return NULL;
2946 }
2947 else
2948 {
2949 return target;
2950 }
2951 }
2952
2953
2954
2955
2956 typedef struct
2957 {
2958 OrthancPluginImage* image;
2959 } _OrthancPluginFreeImage;
2960
2961 /**
2962 * @brief Free an image.
2963 *
2964 * This function frees an image that was decoded with OrthancPluginUncompressImage().
2965 *
2966 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2967 * @param image The image.
2968 * @ingroup Images
2969 **/
2970 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeImage(
2971 OrthancPluginContext* context,
2972 OrthancPluginImage* image)
2973 {
2974 _OrthancPluginFreeImage params;
2975 params.image = image;
2976
2977 context->InvokeService(context, _OrthancPluginService_FreeImage, &params);
2978 }
2979
2980
2981
2982
2983 typedef struct
2984 {
2985 OrthancPluginMemoryBuffer* target;
2986 OrthancPluginImageFormat imageFormat;
2987 OrthancPluginPixelFormat pixelFormat;
2988 uint32_t width;
2989 uint32_t height;
2990 uint32_t pitch;
2991 const void* buffer;
2992 uint8_t quality;
2993 } _OrthancPluginCompressImage;
2994
2995
2996 /**
2997 * @brief Encode a PNG image.
2998 *
2999 * This function compresses the given memory buffer containing an
3000 * image using the PNG specification, and stores the result of the
3001 * compression into a newly allocated memory buffer.
3002 *
3003 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3004 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3005 * @param format The memory layout of the uncompressed image.
3006 * @param width The width of the image.
3007 * @param height The height of the image.
3008 * @param pitch The pitch of the image (i.e. the number of bytes
3009 * between 2 successive lines of the image in the memory buffer).
3010 * @param buffer The memory buffer containing the uncompressed image.
3011 * @return 0 if success, or the error code if failure.
3012 * @see OrthancPluginCompressAndAnswerPngImage()
3013 * @ingroup Images
3014 **/
3015 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressPngImage(
3016 OrthancPluginContext* context,
3017 OrthancPluginMemoryBuffer* target,
3018 OrthancPluginPixelFormat format,
3019 uint32_t width,
3020 uint32_t height,
3021 uint32_t pitch,
3022 const void* buffer)
3023 {
3024 _OrthancPluginCompressImage params;
3025 memset(&params, 0, sizeof(params));
3026 params.target = target;
3027 params.imageFormat = OrthancPluginImageFormat_Png;
3028 params.pixelFormat = format;
3029 params.width = width;
3030 params.height = height;
3031 params.pitch = pitch;
3032 params.buffer = buffer;
3033 params.quality = 0; /* Unused for PNG */
3034
3035 return context->InvokeService(context, _OrthancPluginService_CompressImage, &params);
3036 }
3037
3038
3039 /**
3040 * @brief Encode a JPEG image.
3041 *
3042 * This function compresses the given memory buffer containing an
3043 * image using the JPEG specification, and stores the result of the
3044 * compression into a newly allocated memory buffer.
3045 *
3046 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3047 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3048 * @param format The memory layout of the uncompressed image.
3049 * @param width The width of the image.
3050 * @param height The height of the image.
3051 * @param pitch The pitch of the image (i.e. the number of bytes
3052 * between 2 successive lines of the image in the memory buffer).
3053 * @param buffer The memory buffer containing the uncompressed image.
3054 * @param quality The quality of the JPEG encoding, between 1 (worst
3055 * quality, best compression) and 100 (best quality, worst
3056 * compression).
3057 * @return 0 if success, or the error code if failure.
3058 * @ingroup Images
3059 **/
3060 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressJpegImage(
3061 OrthancPluginContext* context,
3062 OrthancPluginMemoryBuffer* target,
3063 OrthancPluginPixelFormat format,
3064 uint32_t width,
3065 uint32_t height,
3066 uint32_t pitch,
3067 const void* buffer,
3068 uint8_t quality)
3069 {
3070 _OrthancPluginCompressImage params;
3071 memset(&params, 0, sizeof(params));
3072 params.target = target;
3073 params.imageFormat = OrthancPluginImageFormat_Jpeg;
3074 params.pixelFormat = format;
3075 params.width = width;
3076 params.height = height;
3077 params.pitch = pitch;
3078 params.buffer = buffer;
3079 params.quality = quality;
3080
3081 return context->InvokeService(context, _OrthancPluginService_CompressImage, &params);
3082 }
3083
3084
3085
3086 /**
3087 * @brief Answer to a REST request with a JPEG image.
3088 *
3089 * This function answers to a REST request with a JPEG image. The
3090 * parameters of this function describe a memory buffer that
3091 * contains an uncompressed image. The image will be automatically compressed
3092 * as a JPEG image by the core system of Orthanc.
3093 *
3094 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3095 * @param output The HTTP connection to the client application.
3096 * @param format The memory layout of the uncompressed image.
3097 * @param width The width of the image.
3098 * @param height The height of the image.
3099 * @param pitch The pitch of the image (i.e. the number of bytes
3100 * between 2 successive lines of the image in the memory buffer).
3101 * @param buffer The memory buffer containing the uncompressed image.
3102 * @param quality The quality of the JPEG encoding, between 1 (worst
3103 * quality, best compression) and 100 (best quality, worst
3104 * compression).
3105 * @ingroup REST
3106 **/
3107 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerJpegImage(
3108 OrthancPluginContext* context,
3109 OrthancPluginRestOutput* output,
3110 OrthancPluginPixelFormat format,
3111 uint32_t width,
3112 uint32_t height,
3113 uint32_t pitch,
3114 const void* buffer,
3115 uint8_t quality)
3116 {
3117 _OrthancPluginCompressAndAnswerImage params;
3118 params.output = output;
3119 params.imageFormat = OrthancPluginImageFormat_Jpeg;
3120 params.pixelFormat = format;
3121 params.width = width;
3122 params.height = height;
3123 params.pitch = pitch;
3124 params.buffer = buffer;
3125 params.quality = quality;
3126 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, &params);
3127 }
3128
3129
3130
3131
3132 typedef struct
3133 {
3134 OrthancPluginMemoryBuffer* target;
3135 OrthancPluginHttpMethod method;
3136 const char* url;
3137 const char* username;
3138 const char* password;
3139 const char* body;
3140 uint32_t bodySize;
3141 } _OrthancPluginCallHttpClient;
3142
3143
3144 /**
3145 * @brief Issue a HTTP GET call.
3146 *
3147 * Make a HTTP GET call to the given URL. The result to the query is
3148 * stored into a newly allocated memory buffer. Favor
3149 * OrthancPluginRestApiGet() if calling the built-in REST API of the
3150 * Orthanc instance that hosts this plugin.
3151 *
3152 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3153 * @param target The target memory buffer.
3154 * @param url The URL of interest.
3155 * @param username The username (can be <tt>NULL</tt> if no password protection).
3156 * @param password The password (can be <tt>NULL</tt> if no password protection).
3157 * @return 0 if success, or the error code if failure.
3158 **/
3159 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpGet(
3160 OrthancPluginContext* context,
3161 OrthancPluginMemoryBuffer* target,
3162 const char* url,
3163 const char* username,
3164 const char* password)
3165 {
3166 _OrthancPluginCallHttpClient params;
3167 memset(&params, 0, sizeof(params));
3168
3169 params.target = target;
3170 params.method = OrthancPluginHttpMethod_Get;
3171 params.url = url;
3172 params.username = username;
3173 params.password = password;
3174
3175 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
3176 }
3177
3178
3179 /**
3180 * @brief Issue a HTTP POST call.
3181 *
3182 * Make a HTTP POST call to the given URL. The result to the query
3183 * is stored into a newly allocated memory buffer. Favor
3184 * OrthancPluginRestApiPost() if calling the built-in REST API of
3185 * the Orthanc instance that hosts this plugin.
3186 *
3187 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3188 * @param target The target memory buffer.
3189 * @param url The URL of interest.
3190 * @param body The content of the body of the request.
3191 * @param bodySize The size of the body of the request.
3192 * @param username The username (can be <tt>NULL</tt> if no password protection).
3193 * @param password The password (can be <tt>NULL</tt> if no password protection).
3194 * @return 0 if success, or the error code if failure.
3195 **/
3196 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPost(
3197 OrthancPluginContext* context,
3198 OrthancPluginMemoryBuffer* target,
3199 const char* url,
3200 const char* body,
3201 uint32_t bodySize,
3202 const char* username,
3203 const char* password)
3204 {
3205 _OrthancPluginCallHttpClient params;
3206 memset(&params, 0, sizeof(params));
3207
3208 params.target = target;
3209 params.method = OrthancPluginHttpMethod_Post;
3210 params.url = url;
3211 params.body = body;
3212 params.bodySize = bodySize;
3213 params.username = username;
3214 params.password = password;
3215
3216 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
3217 }
3218
3219
3220 /**
3221 * @brief Issue a HTTP PUT call.
3222 *
3223 * Make a HTTP PUT call to the given URL. The result to the query is
3224 * stored into a newly allocated memory buffer. Favor
3225 * OrthancPluginRestApiPut() if calling the built-in REST API of the
3226 * Orthanc instance that hosts this plugin.
3227 *
3228 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3229 * @param target The target memory buffer.
3230 * @param url The URL of interest.
3231 * @param body The content of the body of the request.
3232 * @param bodySize The size of the body of the request.
3233 * @param username The username (can be <tt>NULL</tt> if no password protection).
3234 * @param password The password (can be <tt>NULL</tt> if no password protection).
3235 * @return 0 if success, or the error code if failure.
3236 **/
3237 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPut(
3238 OrthancPluginContext* context,
3239 OrthancPluginMemoryBuffer* target,
3240 const char* url,
3241 const char* body,
3242 uint32_t bodySize,
3243 const char* username,
3244 const char* password)
3245 {
3246 _OrthancPluginCallHttpClient params;
3247 memset(&params, 0, sizeof(params));
3248
3249 params.target = target;
3250 params.method = OrthancPluginHttpMethod_Put;
3251 params.url = url;
3252 params.body = body;
3253 params.bodySize = bodySize;
3254 params.username = username;
3255 params.password = password;
3256
3257 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
3258 }
3259
3260
3261 /**
3262 * @brief Issue a HTTP DELETE call.
3263 *
3264 * Make a HTTP DELETE call to the given URL. Favor
3265 * OrthancPluginRestApiDelete() if calling the built-in REST API of
3266 * the Orthanc instance that hosts this plugin.
3267 *
3268 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3269 * @param url The URL of interest.
3270 * @param username The username (can be <tt>NULL</tt> if no password protection).
3271 * @param password The password (can be <tt>NULL</tt> if no password protection).
3272 * @return 0 if success, or the error code if failure.
3273 **/
3274 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpDelete(
3275 OrthancPluginContext* context,
3276 const char* url,
3277 const char* username,
3278 const char* password)
3279 {
3280 _OrthancPluginCallHttpClient params;
3281 memset(&params, 0, sizeof(params));
3282
3283 params.method = OrthancPluginHttpMethod_Delete;
3284 params.url = url;
3285 params.username = username;
3286 params.password = password;
3287
3288 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
3289 }
3290
3291
3292
3293 typedef struct
3294 {
3295 OrthancPluginImage** target;
3296 const OrthancPluginImage* source;
3297 OrthancPluginPixelFormat targetFormat;
3298 } _OrthancPluginConvertPixelFormat;
3299
3300
3301 /**
3302 * @brief Change the pixel format of an image.
3303 *
3304 * This function creates a new image, changing the memory layout of the pixels.
3305 *
3306 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3307 * @param source The source image.
3308 * @param targetFormat The target pixel format.
3309 * @return The resulting image. It must be freed with OrthancPluginFreeImage().
3310 * @ingroup Images
3311 **/
3312 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginConvertPixelFormat(
3313 OrthancPluginContext* context,
3314 const OrthancPluginImage* source,
3315 OrthancPluginPixelFormat targetFormat)
3316 {
3317 OrthancPluginImage* target = NULL;
3318
3319 _OrthancPluginConvertPixelFormat params;
3320 params.target = &target;
3321 params.source = source;
3322 params.targetFormat = targetFormat;
3323
3324 if (context->InvokeService(context, _OrthancPluginService_ConvertPixelFormat, &params) != OrthancPluginErrorCode_Success)
3325 {
3326 return NULL;
3327 }
3328 else
3329 {
3330 return target;
3331 }
3332 }
3333
3334
3335
3336 /**
3337 * @brief Return the number of available fonts.
3338 *
3339 * This function returns the number of fonts that are built in the
3340 * Orthanc core. These fonts can be used to draw texts on images
3341 * through OrthancPluginDrawText().
3342 *
3343 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3344 * @return The number of fonts.
3345 * @ingroup Images
3346 **/
3347 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontsCount(
3348 OrthancPluginContext* context)
3349 {
3350 uint32_t count = 0;
3351
3352 _OrthancPluginReturnSingleValue params;
3353 memset(&params, 0, sizeof(params));
3354 params.resultUint32 = &count;
3355
3356 if (context->InvokeService(context, _OrthancPluginService_GetFontsCount, &params) != OrthancPluginErrorCode_Success)
3357 {
3358 /* Error */
3359 return 0;
3360 }
3361 else
3362 {
3363 return count;
3364 }
3365 }
3366
3367
3368
3369
3370 typedef struct
3371 {
3372 uint32_t fontIndex; /* in */
3373 const char** name; /* out */
3374 uint32_t* size; /* out */
3375 } _OrthancPluginGetFontInfo;
3376
3377 /**
3378 * @brief Return the name of a font.
3379 *
3380 * This function returns the name of a font that is built in the Orthanc core.
3381 *
3382 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3383 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
3384 * @return The font name. This is a statically-allocated string, do not free it.
3385 * @ingroup Images
3386 **/
3387 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetFontName(
3388 OrthancPluginContext* context,
3389 uint32_t fontIndex)
3390 {
3391 const char* result = NULL;
3392
3393 _OrthancPluginGetFontInfo params;
3394 memset(&params, 0, sizeof(params));
3395 params.name = &result;
3396 params.fontIndex = fontIndex;
3397
3398 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, &params) != OrthancPluginErrorCode_Success)
3399 {
3400 return NULL;
3401 }
3402 else
3403 {
3404 return result;
3405 }
3406 }
3407
3408
3409 /**
3410 * @brief Return the size of a font.
3411 *
3412 * This function returns the size of a font that is built in the Orthanc core.
3413 *
3414 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3415 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
3416 * @return The font size.
3417 * @ingroup Images
3418 **/
3419 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontSize(
3420 OrthancPluginContext* context,
3421 uint32_t fontIndex)
3422 {
3423 uint32_t result;
3424
3425 _OrthancPluginGetFontInfo params;
3426 memset(&params, 0, sizeof(params));
3427 params.size = &result;
3428 params.fontIndex = fontIndex;
3429
3430 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, &params) != OrthancPluginErrorCode_Success)
3431 {
3432 return 0;
3433 }
3434 else
3435 {
3436 return result;
3437 }
3438 }
3439
3440
3441
3442 typedef struct
3443 {
3444 OrthancPluginImage* image;
3445 uint32_t fontIndex;
3446 const char* utf8Text;
3447 int32_t x;
3448 int32_t y;
3449 uint8_t r;
3450 uint8_t g;
3451 uint8_t b;
3452 } _OrthancPluginDrawText;
3453
3454
3455 /**
3456 * @brief Draw text on an image.
3457 *
3458 * This function draws some text on some image.
3459 *
3460 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3461 * @param image The image upon which to draw the text.
3462 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
3463 * @param utf8Text The text to be drawn, encoded as an UTF-8 zero-terminated string.
3464 * @param x The X position of the text over the image.
3465 * @param y The Y position of the text over the image.
3466 * @param r The value of the red color channel of the text.
3467 * @param g The value of the green color channel of the text.
3468 * @param b The value of the blue color channel of the text.
3469 * @return 0 if success, other value if error.
3470 * @ingroup Images
3471 **/
3472 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginDrawText(
3473 OrthancPluginContext* context,
3474 OrthancPluginImage* image,
3475 uint32_t fontIndex,
3476 const char* utf8Text,
3477 int32_t x,
3478 int32_t y,
3479 uint8_t r,
3480 uint8_t g,
3481 uint8_t b)
3482 {
3483 _OrthancPluginDrawText params;
3484 memset(&params, 0, sizeof(params));
3485 params.image = image;
3486 params.fontIndex = fontIndex;
3487 params.utf8Text = utf8Text;
3488 params.x = x;
3489 params.y = y;
3490 params.r = r;
3491 params.g = g;
3492 params.b = b;
3493
3494 return context->InvokeService(context, _OrthancPluginService_DrawText, &params);
3495 }
3496
3497
3498
3499 typedef struct
3500 {
3501 OrthancPluginStorageArea* storageArea;
3502 const char* uuid;
3503 const void* content;
3504 uint64_t size;
3505 OrthancPluginContentType type;
3506 } _OrthancPluginStorageAreaCreate;
3507
3508
3509 /**
3510 * @brief Create a file inside the storage area.
3511 *
3512 * This function creates a new file inside the storage area that is
3513 * currently used by Orthanc.
3514 *
3515 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3516 * @param storageArea The storage area.
3517 * @param uuid The identifier of the file to be created.
3518 * @param content The content to store in the newly created file.
3519 * @param size The size of the content.
3520 * @param type The type of the file content.
3521 * @return 0 if success, other value if error.
3522 * @ingroup Callbacks
3523 **/
3524 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaCreate(
3525 OrthancPluginContext* context,
3526 OrthancPluginStorageArea* storageArea,
3527 const char* uuid,
3528 const void* content,
3529 uint64_t size,
3530 OrthancPluginContentType type)
3531 {
3532 _OrthancPluginStorageAreaCreate params;
3533 params.storageArea = storageArea;
3534 params.uuid = uuid;
3535 params.content = content;
3536 params.size = size;
3537 params.type = type;
3538
3539 return context->InvokeService(context, _OrthancPluginService_StorageAreaCreate, &params);
3540 }
3541
3542
3543 typedef struct
3544 {
3545 OrthancPluginMemoryBuffer* target;
3546 OrthancPluginStorageArea* storageArea;
3547 const char* uuid;
3548 OrthancPluginContentType type;
3549 } _OrthancPluginStorageAreaRead;
3550
3551
3552 /**
3553 * @brief Read a file from the storage area.
3554 *
3555 * This function reads the content of a given file from the storage
3556 * area that is currently used by Orthanc.
3557 *
3558 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3559 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3560 * @param storageArea The storage area.
3561 * @param uuid The identifier of the file to be read.
3562 * @param type The type of the file content.
3563 * @return 0 if success, other value if error.
3564 * @ingroup Callbacks
3565 **/
3566 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRead(
3567 OrthancPluginContext* context,
3568 OrthancPluginMemoryBuffer* target,
3569 OrthancPluginStorageArea* storageArea,
3570 const char* uuid,
3571 OrthancPluginContentType type)
3572 {
3573 _OrthancPluginStorageAreaRead params;
3574 params.target = target;
3575 params.storageArea = storageArea;
3576 params.uuid = uuid;
3577 params.type = type;
3578
3579 return context->InvokeService(context, _OrthancPluginService_StorageAreaRead, &params);
3580 }
3581
3582
3583 typedef struct
3584 {
3585 OrthancPluginStorageArea* storageArea;
3586 const char* uuid;
3587 OrthancPluginContentType type;
3588 } _OrthancPluginStorageAreaRemove;
3589
3590
3591 /**
3592 * @brief Remove a file from the storage area.
3593 *
3594 * This function removes a given file from the storage area that is
3595 * currently used by Orthanc.
3596 *
3597 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3598 * @param storageArea The storage area.
3599 * @param uuid The identifier of the file to be removed.
3600 * @param type The type of the file content.
3601 * @return 0 if success, other value if error.
3602 * @ingroup Callbacks
3603 **/
3604 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRemove(
3605 OrthancPluginContext* context,
3606 OrthancPluginStorageArea* storageArea,
3607 const char* uuid,
3608 OrthancPluginContentType type)
3609 {
3610 _OrthancPluginStorageAreaRemove params;
3611 params.storageArea = storageArea;
3612 params.uuid = uuid;
3613 params.type = type;
3614
3615 return context->InvokeService(context, _OrthancPluginService_StorageAreaRemove, &params);
3616 }
3617
3618
3619
3620 #ifdef __cplusplus
3621 }
3622 #endif
3623
3624
3625 /** @} */
3626