comparison Orthanc/Sdk-0.9.1/orthanc/OrthancCPlugin.h @ 51:7b4b8b82112e

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 Jul 2015 15:56:27 +0200
parents
children
comparison
equal deleted inserted replaced
50:2578545f8d87 51:7b4b8b82112e
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 * - Register all its callbacks for received instances using ::OrthancPluginRegisterOnStoredInstanceCallback().
18 * - Possibly register a custom storage area using ::OrthancPluginRegisterStorageArea().
19 * - Possibly register a custom database back-end area using ::OrthancPluginRegisterDatabaseBackend().
20 * -# <tt>void OrthancPluginFinalize()</tt>:
21 * This function is invoked by Orthanc during its shutdown. The plugin
22 * must free all its memory.
23 * -# <tt>const char* OrthancPluginGetName()</tt>:
24 * The plugin must return a short string to identify itself.
25 * -# <tt>const char* OrthancPluginGetVersion()</tt>:
26 * The plugin must return a string containing its version number.
27 *
28 * The name and the version of a plugin is only used to prevent it
29 * from being loaded twice.
30 *
31 * The various callbacks are guaranteed to be executed in mutual
32 * exclusion since Orthanc 0.8.5.
33 **/
34
35
36
37 /**
38 * @defgroup CInterface C Interface
39 * @brief The C interface to create Orthanc plugins.
40 *
41 * These functions must be used to create C plugins for Orthanc.
42 **/
43
44
45
46 /**
47 * Orthanc - A Lightweight, RESTful DICOM Store
48 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
49 * Department, University Hospital of Liege, Belgium
50 *
51 * This program is free software: you can redistribute it and/or
52 * modify it under the terms of the GNU General Public License as
53 * published by the Free Software Foundation, either version 3 of the
54 * License, or (at your option) any later version.
55 *
56 * In addition, as a special exception, the copyright holders of this
57 * program give permission to link the code of its release with the
58 * OpenSSL project's "OpenSSL" library (or with modified versions of it
59 * that use the same license as the "OpenSSL" library), and distribute
60 * the linked executables. You must obey the GNU General Public License
61 * in all respects for all of the code used other than "OpenSSL". If you
62 * modify file(s) with this exception, you may extend this exception to
63 * your version of the file(s), but you are not obligated to do so. If
64 * you do not wish to do so, delete this exception statement from your
65 * version. If you delete this exception statement from all source files
66 * in the program, then also delete it here.
67 *
68 * This program is distributed in the hope that it will be useful, but
69 * WITHOUT ANY WARRANTY; without even the implied warranty of
70 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
71 * General Public License for more details.
72 *
73 * You should have received a copy of the GNU General Public License
74 * along with this program. If not, see <http://www.gnu.org/licenses/>.
75 **/
76
77
78
79 #pragma once
80
81
82 #include <stdio.h>
83 #include <string.h>
84
85 #ifdef WIN32
86 #define ORTHANC_PLUGINS_API __declspec(dllexport)
87 #else
88 #define ORTHANC_PLUGINS_API
89 #endif
90
91 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 0
92 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 9
93 #define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 1
94
95
96
97 /********************************************************************
98 ** Check that function inlining is properly supported. The use of
99 ** inlining is required, to avoid the duplication of object code
100 ** between two compilation modules that would use the Orthanc Plugin
101 ** API.
102 ********************************************************************/
103
104 /* If the auto-detection of the "inline" keyword below does not work
105 automatically and that your compiler is known to properly support
106 inlining, uncomment the following #define and adapt the definition
107 of "static inline". */
108
109 /* #define ORTHANC_PLUGIN_INLINE static inline */
110
111 #ifndef ORTHANC_PLUGIN_INLINE
112 # if __STDC_VERSION__ >= 199901L
113 /* This is C99 or above: http://predef.sourceforge.net/prestd.html */
114 # define ORTHANC_PLUGIN_INLINE static inline
115 # elif defined(__cplusplus)
116 /* This is C++ */
117 # define ORTHANC_PLUGIN_INLINE static inline
118 # elif defined(__GNUC__)
119 /* This is GCC running in C89 mode */
120 # define ORTHANC_PLUGIN_INLINE static __inline
121 # elif defined(_MSC_VER)
122 /* This is Visual Studio running in C89 mode */
123 # define ORTHANC_PLUGIN_INLINE static __inline
124 # else
125 # error Your compiler is not known to support the "inline" keyword
126 # endif
127 #endif
128
129
130
131 /********************************************************************
132 ** Inclusion of standard libraries.
133 ********************************************************************/
134
135 /**
136 * For Microsoft Visual Studio, a compatibility "stdint.h" can be
137 * downloaded at the following URL:
138 * https://orthanc.googlecode.com/hg/Resources/ThirdParty/VisualStudio/stdint.h
139 **/
140 #include <stdint.h>
141
142 #include <stdlib.h>
143
144
145
146 /********************************************************************
147 ** Definition of the Orthanc Plugin API.
148 ********************************************************************/
149
150 /** @{ */
151
152 #ifdef __cplusplus
153 extern "C"
154 {
155 #endif
156
157 /**
158 * Forward declaration of one of the mandatory functions for Orthanc
159 * plugins.
160 **/
161 ORTHANC_PLUGINS_API const char* OrthancPluginGetName();
162
163
164 /**
165 * The various HTTP methods for a REST call.
166 **/
167 typedef enum
168 {
169 OrthancPluginHttpMethod_Get = 1, /*!< GET request */
170 OrthancPluginHttpMethod_Post = 2, /*!< POST request */
171 OrthancPluginHttpMethod_Put = 3, /*!< PUT request */
172 OrthancPluginHttpMethod_Delete = 4 /*!< DELETE request */
173 } OrthancPluginHttpMethod;
174
175
176 /**
177 * @brief The parameters of a REST request.
178 **/
179 typedef struct
180 {
181 /**
182 * @brief The HTTP method.
183 **/
184 OrthancPluginHttpMethod method;
185
186 /**
187 * @brief The number of groups of the regular expression.
188 **/
189 uint32_t groupsCount;
190
191 /**
192 * @brief The matched values for the groups of the regular expression.
193 **/
194 const char* const* groups;
195
196 /**
197 * @brief For a GET request, the number of GET parameters.
198 **/
199 uint32_t getCount;
200
201 /**
202 * @brief For a GET request, the keys of the GET parameters.
203 **/
204 const char* const* getKeys;
205
206 /**
207 * @brief For a GET request, the values of the GET parameters.
208 **/
209 const char* const* getValues;
210
211 /**
212 * @brief For a PUT or POST request, the content of the body.
213 **/
214 const char* body;
215
216 /**
217 * @brief For a PUT or POST request, the number of bytes of the body.
218 **/
219 uint32_t bodySize;
220
221
222 /* --------------------------------------------------
223 New in version 0.8.1
224 -------------------------------------------------- */
225
226 /**
227 * @brief The number of HTTP headers.
228 **/
229 uint32_t headersCount;
230
231 /**
232 * @brief The keys of the HTTP headers (always converted to low-case).
233 **/
234 const char* const* headersKeys;
235
236 /**
237 * @brief The values of the HTTP headers.
238 **/
239 const char* const* headersValues;
240
241 } OrthancPluginHttpRequest;
242
243
244 typedef enum
245 {
246 /* Generic services */
247 _OrthancPluginService_LogInfo = 1,
248 _OrthancPluginService_LogWarning = 2,
249 _OrthancPluginService_LogError = 3,
250 _OrthancPluginService_GetOrthancPath = 4,
251 _OrthancPluginService_GetOrthancDirectory = 5,
252 _OrthancPluginService_GetConfigurationPath = 6,
253 _OrthancPluginService_SetPluginProperty = 7,
254 _OrthancPluginService_GetGlobalProperty = 8,
255 _OrthancPluginService_SetGlobalProperty = 9,
256 _OrthancPluginService_GetCommandLineArgumentsCount = 10,
257 _OrthancPluginService_GetCommandLineArgument = 11,
258 _OrthancPluginService_GetExpectedDatabaseVersion = 12,
259 _OrthancPluginService_GetConfiguration = 13,
260
261 /* Registration of callbacks */
262 _OrthancPluginService_RegisterRestCallback = 1000,
263 _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001,
264 _OrthancPluginService_RegisterStorageArea = 1002,
265 _OrthancPluginService_RegisterOnChangeCallback = 1003,
266
267 /* Sending answers to REST calls */
268 _OrthancPluginService_AnswerBuffer = 2000,
269 _OrthancPluginService_CompressAndAnswerPngImage = 2001,
270 _OrthancPluginService_Redirect = 2002,
271 _OrthancPluginService_SendHttpStatusCode = 2003,
272 _OrthancPluginService_SendUnauthorized = 2004,
273 _OrthancPluginService_SendMethodNotAllowed = 2005,
274 _OrthancPluginService_SetCookie = 2006,
275 _OrthancPluginService_SetHttpHeader = 2007,
276 _OrthancPluginService_StartMultipartAnswer = 2008,
277 _OrthancPluginService_SendMultipartItem = 2009,
278
279 /* Access to the Orthanc database and API */
280 _OrthancPluginService_GetDicomForInstance = 3000,
281 _OrthancPluginService_RestApiGet = 3001,
282 _OrthancPluginService_RestApiPost = 3002,
283 _OrthancPluginService_RestApiDelete = 3003,
284 _OrthancPluginService_RestApiPut = 3004,
285 _OrthancPluginService_LookupPatient = 3005,
286 _OrthancPluginService_LookupStudy = 3006,
287 _OrthancPluginService_LookupSeries = 3007,
288 _OrthancPluginService_LookupInstance = 3008,
289 _OrthancPluginService_LookupStudyWithAccessionNumber = 3009,
290 _OrthancPluginService_RestApiGetAfterPlugins = 3010,
291 _OrthancPluginService_RestApiPostAfterPlugins = 3011,
292 _OrthancPluginService_RestApiDeleteAfterPlugins = 3012,
293 _OrthancPluginService_RestApiPutAfterPlugins = 3013,
294
295 /* Access to DICOM instances */
296 _OrthancPluginService_GetInstanceRemoteAet = 4000,
297 _OrthancPluginService_GetInstanceSize = 4001,
298 _OrthancPluginService_GetInstanceData = 4002,
299 _OrthancPluginService_GetInstanceJson = 4003,
300 _OrthancPluginService_GetInstanceSimplifiedJson = 4004,
301 _OrthancPluginService_HasInstanceMetadata = 4005,
302 _OrthancPluginService_GetInstanceMetadata = 4006,
303
304 /* Services for plugins implementing a database back-end */
305 _OrthancPluginService_RegisterDatabaseBackend = 5000,
306 _OrthancPluginService_DatabaseAnswer = 5001
307
308 } _OrthancPluginService;
309
310
311 typedef enum
312 {
313 _OrthancPluginProperty_Description = 1,
314 _OrthancPluginProperty_RootUri = 2,
315 _OrthancPluginProperty_OrthancExplorer = 3
316 } _OrthancPluginProperty;
317
318
319
320 /**
321 * The memory layout of the pixels of an image.
322 **/
323 typedef enum
324 {
325 /**
326 * @brief Graylevel 8bpp image.
327 *
328 * The image is graylevel. Each pixel is unsigned and stored in
329 * one byte.
330 **/
331 OrthancPluginPixelFormat_Grayscale8 = 1,
332
333 /**
334 * @brief Graylevel, unsigned 16bpp image.
335 *
336 * The image is graylevel. Each pixel is unsigned and stored in
337 * two bytes.
338 **/
339 OrthancPluginPixelFormat_Grayscale16 = 2,
340
341 /**
342 * @brief Graylevel, signed 16bpp image.
343 *
344 * The image is graylevel. Each pixel is signed and stored in two
345 * bytes.
346 **/
347 OrthancPluginPixelFormat_SignedGrayscale16 = 3,
348
349 /**
350 * @brief Color image in RGB24 format.
351 *
352 * This format describes a color image. The pixels are stored in 3
353 * consecutive bytes. The memory layout is RGB.
354 **/
355 OrthancPluginPixelFormat_RGB24 = 4,
356
357 /**
358 * @brief Color image in RGBA32 format.
359 *
360 * This format describes a color image. The pixels are stored in 4
361 * consecutive bytes. The memory layout is RGBA.
362 **/
363 OrthancPluginPixelFormat_RGBA32 = 5
364 } OrthancPluginPixelFormat;
365
366
367
368 /**
369 * The content types that are supported by Orthanc plugins.
370 **/
371 typedef enum
372 {
373 OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */
374 OrthancPluginContentType_Dicom = 1, /*!< DICOM */
375 OrthancPluginContentType_DicomAsJson = 2 /*!< JSON summary of a DICOM file */
376 } OrthancPluginContentType;
377
378
379
380 /**
381 * The supported type of DICOM resources.
382 **/
383 typedef enum
384 {
385 OrthancPluginResourceType_Patient = 0, /*!< Patient */
386 OrthancPluginResourceType_Study = 1, /*!< Study */
387 OrthancPluginResourceType_Series = 2, /*!< Series */
388 OrthancPluginResourceType_Instance = 3 /*!< Instance */
389 } OrthancPluginResourceType;
390
391
392
393 /**
394 * The supported type of changes that can happen to DICOM resources.
395 **/
396 typedef enum
397 {
398 OrthancPluginChangeType_CompletedSeries = 0, /*!< Series is now complete */
399 OrthancPluginChangeType_Deleted = 1, /*!< Deleted resource */
400 OrthancPluginChangeType_NewChildInstance = 2, /*!< A new instance was added to this resource */
401 OrthancPluginChangeType_NewInstance = 3, /*!< New instance received */
402 OrthancPluginChangeType_NewPatient = 4, /*!< New patient created */
403 OrthancPluginChangeType_NewSeries = 5, /*!< New series created */
404 OrthancPluginChangeType_NewStudy = 6, /*!< New study created */
405 OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */
406 OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */
407 OrthancPluginChangeType_StableStudy = 9 /*!< Timeout: No new instance in this study */
408 } OrthancPluginChangeType;
409
410
411
412 /**
413 * @brief A memory buffer allocated by the core system of Orthanc.
414 *
415 * A memory buffer allocated by the core system of Orthanc. When the
416 * content of the buffer is not useful anymore, it must be free by a
417 * call to ::OrthancPluginFreeMemoryBuffer().
418 **/
419 typedef struct
420 {
421 /**
422 * @brief The content of the buffer.
423 **/
424 void* data;
425
426 /**
427 * @brief The number of bytes in the buffer.
428 **/
429 uint32_t size;
430 } OrthancPluginMemoryBuffer;
431
432
433
434
435 /**
436 * @brief Opaque structure that represents the HTTP connection to the client application.
437 **/
438 typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput;
439
440
441
442 /**
443 * @brief Opaque structure that represents a DICOM instance received by Orthanc.
444 **/
445 typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance;
446
447
448
449 /**
450 * @brief Signature of a callback function that answers to a REST request.
451 **/
452 typedef int32_t (*OrthancPluginRestCallback) (
453 OrthancPluginRestOutput* output,
454 const char* url,
455 const OrthancPluginHttpRequest* request);
456
457
458
459 /**
460 * @brief Signature of a callback function that is triggered when Orthanc receives a DICOM instance.
461 **/
462 typedef int32_t (*OrthancPluginOnStoredInstanceCallback) (
463 OrthancPluginDicomInstance* instance,
464 const char* instanceId);
465
466
467
468 /**
469 * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource.
470 **/
471 typedef int32_t (*OrthancPluginOnChangeCallback) (
472 OrthancPluginChangeType changeType,
473 OrthancPluginResourceType resourceType,
474 const char* resourceId);
475
476
477
478 /**
479 * @brief Signature of a function to free dynamic memory.
480 **/
481 typedef void (*OrthancPluginFree) (void* buffer);
482
483
484
485 /**
486 * @brief Callback for writing to the storage area.
487 *
488 * Signature of a callback function that is triggered when Orthanc writes a file to the storage area.
489 *
490 * @param uuid The UUID of the file.
491 * @param content The content of the file.
492 * @param size The size of the file.
493 * @param type The content type corresponding to this file.
494 * @return 0 if success, other value if error.
495 **/
496 typedef int32_t (*OrthancPluginStorageCreate) (
497 const char* uuid,
498 const void* content,
499 int64_t size,
500 OrthancPluginContentType type);
501
502
503
504 /**
505 * @brief Callback for reading from the storage area.
506 *
507 * Signature of a callback function that is triggered when Orthanc reads a file from the storage area.
508 *
509 * @param content The content of the file (output).
510 * @param size The size of the file (output).
511 * @param uuid The UUID of the file of interest.
512 * @param type The content type corresponding to this file.
513 * @return 0 if success, other value if error.
514 **/
515 typedef int32_t (*OrthancPluginStorageRead) (
516 void** content,
517 int64_t* size,
518 const char* uuid,
519 OrthancPluginContentType type);
520
521
522
523 /**
524 * @brief Callback for removing a file from the storage area.
525 *
526 * Signature of a callback function that is triggered when Orthanc deletes a file from the storage area.
527 *
528 * @param uuid The UUID of the file to be removed.
529 * @param type The content type corresponding to this file.
530 * @return 0 if success, other value if error.
531 **/
532 typedef int32_t (*OrthancPluginStorageRemove) (
533 const char* uuid,
534 OrthancPluginContentType type);
535
536
537
538 /**
539 * @brief Data structure that contains information about the Orthanc core.
540 **/
541 typedef struct _OrthancPluginContext_t
542 {
543 void* pluginsManager;
544 const char* orthancVersion;
545 OrthancPluginFree Free;
546 int32_t (*InvokeService) (struct _OrthancPluginContext_t* context,
547 _OrthancPluginService service,
548 const void* params);
549 } OrthancPluginContext;
550
551
552
553 /**
554 * @brief Free a string.
555 *
556 * Free a string that was allocated by the core system of Orthanc.
557 *
558 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
559 * @param str The string to be freed.
560 **/
561 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString(
562 OrthancPluginContext* context,
563 char* str)
564 {
565 if (str != NULL)
566 {
567 context->Free(str);
568 }
569 }
570
571
572 /**
573 * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc.
574 *
575 * This function checks whether the version of this C header is
576 * compatible with the current version of Orthanc. The result of
577 * this function should always be checked in the
578 * OrthancPluginInitialize() entry point of the plugin.
579 *
580 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
581 * @return 1 if and only if the versions are compatible. If the
582 * result is 0, the initialization of the plugin should fail.
583 **/
584 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion(
585 OrthancPluginContext* context)
586 {
587 int major, minor, revision;
588
589 /* Assume compatibility with the mainline */
590 if (!strcmp(context->orthancVersion, "mainline"))
591 {
592 return 1;
593 }
594
595 /* Parse the version of the Orthanc core */
596 if (
597 #ifdef _MSC_VER
598 sscanf_s
599 #else
600 sscanf
601 #endif
602 (context->orthancVersion, "%4d.%4d.%4d", &major, &minor, &revision) != 3)
603 {
604 return 0;
605 }
606
607 /* Check the major number of the version */
608
609 if (major > ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER)
610 {
611 return 1;
612 }
613
614 if (major < ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER)
615 {
616 return 0;
617 }
618
619 /* Check the minor number of the version */
620
621 if (minor > ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER)
622 {
623 return 1;
624 }
625
626 if (minor < ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER)
627 {
628 return 0;
629 }
630
631 /* Check the revision number of the version */
632
633 if (revision >= ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER)
634 {
635 return 1;
636 }
637 else
638 {
639 return 0;
640 }
641 }
642
643
644 /**
645 * @brief Free a memory buffer.
646 *
647 * Free a memory buffer that was allocated by the core system of Orthanc.
648 *
649 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
650 * @param buffer The memory buffer to release.
651 **/
652 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer(
653 OrthancPluginContext* context,
654 OrthancPluginMemoryBuffer* buffer)
655 {
656 context->Free(buffer->data);
657 }
658
659
660 /**
661 * @brief Log an error.
662 *
663 * Log an error message using the Orthanc logging system.
664 *
665 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
666 * @param message The message to be logged.
667 **/
668 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError(
669 OrthancPluginContext* context,
670 const char* message)
671 {
672 context->InvokeService(context, _OrthancPluginService_LogError, message);
673 }
674
675
676 /**
677 * @brief Log a warning.
678 *
679 * Log a warning message using the Orthanc logging system.
680 *
681 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
682 * @param message The message to be logged.
683 **/
684 ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning(
685 OrthancPluginContext* context,
686 const char* message)
687 {
688 context->InvokeService(context, _OrthancPluginService_LogWarning, message);
689 }
690
691
692 /**
693 * @brief Log an information.
694 *
695 * Log an information message using the Orthanc logging system.
696 *
697 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
698 * @param message The message to be logged.
699 **/
700 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo(
701 OrthancPluginContext* context,
702 const char* message)
703 {
704 context->InvokeService(context, _OrthancPluginService_LogInfo, message);
705 }
706
707
708
709 typedef struct
710 {
711 const char* pathRegularExpression;
712 OrthancPluginRestCallback callback;
713 } _OrthancPluginRestCallback;
714
715 /**
716 * @brief Register a REST callback.
717 *
718 * This function registers a REST callback against a regular
719 * expression for a URI. This function must be called during the
720 * initialization of the plugin, i.e. inside the
721 * OrthancPluginInitialize() public function.
722 *
723 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
724 * @param pathRegularExpression Regular expression for the URI. May contain groups.
725 * @param callback The callback function to handle the REST call.
726 **/
727 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback(
728 OrthancPluginContext* context,
729 const char* pathRegularExpression,
730 OrthancPluginRestCallback callback)
731 {
732 _OrthancPluginRestCallback params;
733 params.pathRegularExpression = pathRegularExpression;
734 params.callback = callback;
735 context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, &params);
736 }
737
738
739
740 typedef struct
741 {
742 OrthancPluginOnStoredInstanceCallback callback;
743 } _OrthancPluginOnStoredInstanceCallback;
744
745 /**
746 * @brief Register a callback for received instances.
747 *
748 * This function registers a callback function that is called
749 * whenever a new DICOM instance is stored into the Orthanc core.
750 *
751 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
752 * @param callback The callback function.
753 **/
754 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback(
755 OrthancPluginContext* context,
756 OrthancPluginOnStoredInstanceCallback callback)
757 {
758 _OrthancPluginOnStoredInstanceCallback params;
759 params.callback = callback;
760
761 context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, &params);
762 }
763
764
765
766 typedef struct
767 {
768 OrthancPluginRestOutput* output;
769 const char* answer;
770 uint32_t answerSize;
771 const char* mimeType;
772 } _OrthancPluginAnswerBuffer;
773
774 /**
775 * @brief Answer to a REST request.
776 *
777 * This function answers to a REST request with the content of a memory buffer.
778 *
779 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
780 * @param output The HTTP connection to the client application.
781 * @param answer Pointer to the memory buffer containing the answer.
782 * @param answerSize Number of bytes of the answer.
783 * @param mimeType The MIME type of the answer.
784 **/
785 ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer(
786 OrthancPluginContext* context,
787 OrthancPluginRestOutput* output,
788 const char* answer,
789 uint32_t answerSize,
790 const char* mimeType)
791 {
792 _OrthancPluginAnswerBuffer params;
793 params.output = output;
794 params.answer = answer;
795 params.answerSize = answerSize;
796 params.mimeType = mimeType;
797 context->InvokeService(context, _OrthancPluginService_AnswerBuffer, &params);
798 }
799
800
801 typedef struct
802 {
803 OrthancPluginRestOutput* output;
804 OrthancPluginPixelFormat format;
805 uint32_t width;
806 uint32_t height;
807 uint32_t pitch;
808 const void* buffer;
809 } _OrthancPluginCompressAndAnswerPngImage;
810
811 /**
812 * @brief Answer to a REST request with a PNG image.
813 *
814 * This function answers to a REST request with a PNG image. The
815 * parameters of this function describe a memory buffer that
816 * contains an uncompressed image. The image will be automatically compressed
817 * as a PNG image by the core system of Orthanc.
818 *
819 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
820 * @param output The HTTP connection to the client application.
821 * @param format The memory layout of the uncompressed image.
822 * @param width The width of the image.
823 * @param height The height of the image.
824 * @param pitch The pitch of the image (i.e. the number of bytes
825 * between 2 successive lines of the image in the memory buffer.
826 * @param buffer The memory buffer containing the uncompressed image.
827 **/
828 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage(
829 OrthancPluginContext* context,
830 OrthancPluginRestOutput* output,
831 OrthancPluginPixelFormat format,
832 uint32_t width,
833 uint32_t height,
834 uint32_t pitch,
835 const void* buffer)
836 {
837 _OrthancPluginCompressAndAnswerPngImage params;
838 params.output = output;
839 params.format = format;
840 params.width = width;
841 params.height = height;
842 params.pitch = pitch;
843 params.buffer = buffer;
844 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerPngImage, &params);
845 }
846
847
848
849 typedef struct
850 {
851 OrthancPluginMemoryBuffer* target;
852 const char* instanceId;
853 } _OrthancPluginGetDicomForInstance;
854
855 /**
856 * @brief Retrieve a DICOM instance using its Orthanc identifier.
857 *
858 * Retrieve a DICOM instance using its Orthanc identifier. The DICOM
859 * file is stored into a newly allocated memory buffer.
860 *
861 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
862 * @param target The target memory buffer.
863 * @param instanceId The Orthanc identifier of the DICOM instance of interest.
864 * @return 0 if success, other value if error.
865 **/
866 ORTHANC_PLUGIN_INLINE int OrthancPluginGetDicomForInstance(
867 OrthancPluginContext* context,
868 OrthancPluginMemoryBuffer* target,
869 const char* instanceId)
870 {
871 _OrthancPluginGetDicomForInstance params;
872 params.target = target;
873 params.instanceId = instanceId;
874 return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, &params);
875 }
876
877
878
879 typedef struct
880 {
881 OrthancPluginMemoryBuffer* target;
882 const char* uri;
883 } _OrthancPluginRestApiGet;
884
885 /**
886 * @brief Make a GET call to the built-in Orthanc REST API.
887 *
888 * Make a GET call to the built-in Orthanc REST API. The result to
889 * the query is stored into a newly allocated memory buffer.
890 *
891 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
892 * @param target The target memory buffer.
893 * @param uri The URI in the built-in Orthanc API.
894 * @return 0 if success, other value if error.
895 **/
896 ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiGet(
897 OrthancPluginContext* context,
898 OrthancPluginMemoryBuffer* target,
899 const char* uri)
900 {
901 _OrthancPluginRestApiGet params;
902 params.target = target;
903 params.uri = uri;
904 return context->InvokeService(context, _OrthancPluginService_RestApiGet, &params);
905 }
906
907
908
909 /**
910 * @brief Make a GET call to the REST API, as tainted by the plugins.
911 *
912 * Make a GET call to the Orthanc REST API, after all the plugins
913 * are applied. In other words, if some plugin overrides or adds the
914 * called URI to the built-in Orthanc REST API, this call will
915 * return the result provided by this plugin. The result to the
916 * query is stored into a newly allocated memory buffer.
917 *
918 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
919 * @param target The target memory buffer.
920 * @param uri The URI in the built-in Orthanc API.
921 * @return 0 if success, other value if error.
922 **/
923 ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiGetAfterPlugins(
924 OrthancPluginContext* context,
925 OrthancPluginMemoryBuffer* target,
926 const char* uri)
927 {
928 _OrthancPluginRestApiGet params;
929 params.target = target;
930 params.uri = uri;
931 return context->InvokeService(context, _OrthancPluginService_RestApiGetAfterPlugins, &params);
932 }
933
934
935
936 typedef struct
937 {
938 OrthancPluginMemoryBuffer* target;
939 const char* uri;
940 const char* body;
941 uint32_t bodySize;
942 } _OrthancPluginRestApiPostPut;
943
944 /**
945 * @brief Make a POST call to the built-in Orthanc REST API.
946 *
947 * Make a POST call to the built-in Orthanc REST API. The result to
948 * the query is stored into a newly allocated memory buffer.
949 *
950 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
951 * @param target The target memory buffer.
952 * @param uri The URI in the built-in Orthanc API.
953 * @param body The body of the POST request.
954 * @param bodySize The size of the body.
955 * @return 0 if success, other value if error.
956 **/
957 ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiPost(
958 OrthancPluginContext* context,
959 OrthancPluginMemoryBuffer* target,
960 const char* uri,
961 const char* body,
962 uint32_t bodySize)
963 {
964 _OrthancPluginRestApiPostPut params;
965 params.target = target;
966 params.uri = uri;
967 params.body = body;
968 params.bodySize = bodySize;
969 return context->InvokeService(context, _OrthancPluginService_RestApiPost, &params);
970 }
971
972
973 /**
974 * @brief Make a POST call to the REST API, as tainted by the plugins.
975 *
976 * Make a POST call to the Orthanc REST API, after all the plugins
977 * are applied. In other words, if some plugin overrides or adds the
978 * called URI to the built-in Orthanc REST API, this call will
979 * return the result provided by this plugin. The result to the
980 * query is stored into a newly allocated memory buffer.
981 *
982 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
983 * @param target The target memory buffer.
984 * @param uri The URI in the built-in Orthanc API.
985 * @param body The body of the POST request.
986 * @param bodySize The size of the body.
987 * @return 0 if success, other value if error.
988 **/
989 ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiPostAfterPlugins(
990 OrthancPluginContext* context,
991 OrthancPluginMemoryBuffer* target,
992 const char* uri,
993 const char* body,
994 uint32_t bodySize)
995 {
996 _OrthancPluginRestApiPostPut params;
997 params.target = target;
998 params.uri = uri;
999 params.body = body;
1000 params.bodySize = bodySize;
1001 return context->InvokeService(context, _OrthancPluginService_RestApiPostAfterPlugins, &params);
1002 }
1003
1004
1005
1006 /**
1007 * @brief Make a DELETE call to the built-in Orthanc REST API.
1008 *
1009 * Make a DELETE call to the built-in Orthanc REST API.
1010 *
1011 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1012 * @param uri The URI to delete in the built-in Orthanc API.
1013 * @return 0 if success, other value if error.
1014 **/
1015 ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiDelete(
1016 OrthancPluginContext* context,
1017 const char* uri)
1018 {
1019 return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri);
1020 }
1021
1022
1023 /**
1024 * @brief Make a DELETE call to the REST API, as tainted by the plugins.
1025 *
1026 * Make a DELETE call to the Orthanc REST API, after all the plugins
1027 * are applied. In other words, if some plugin overrides or adds the
1028 * called URI to the built-in Orthanc REST API, this call will
1029 * return the result provided by this plugin.
1030 *
1031 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1032 * @param uri The URI to delete in the built-in Orthanc API.
1033 * @return 0 if success, other value if error.
1034 **/
1035 ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiDeleteAfterPlugins(
1036 OrthancPluginContext* context,
1037 const char* uri)
1038 {
1039 return context->InvokeService(context, _OrthancPluginService_RestApiDeleteAfterPlugins, uri);
1040 }
1041
1042
1043
1044 /**
1045 * @brief Make a PUT call to the built-in Orthanc REST API.
1046 *
1047 * Make a PUT call to the built-in Orthanc REST API. The result to
1048 * the query is stored into a newly allocated memory buffer.
1049 *
1050 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1051 * @param target The target memory buffer.
1052 * @param uri The URI in the built-in Orthanc API.
1053 * @param body The body of the PUT request.
1054 * @param bodySize The size of the body.
1055 * @return 0 if success, other value if error.
1056 **/
1057 ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiPut(
1058 OrthancPluginContext* context,
1059 OrthancPluginMemoryBuffer* target,
1060 const char* uri,
1061 const char* body,
1062 uint32_t bodySize)
1063 {
1064 _OrthancPluginRestApiPostPut params;
1065 params.target = target;
1066 params.uri = uri;
1067 params.body = body;
1068 params.bodySize = bodySize;
1069 return context->InvokeService(context, _OrthancPluginService_RestApiPut, &params);
1070 }
1071
1072
1073
1074 /**
1075 * @brief Make a PUT call to the REST API, as tainted by the plugins.
1076 *
1077 * Make a PUT call to the Orthanc REST API, after all the plugins
1078 * are applied. In other words, if some plugin overrides or adds the
1079 * called URI to the built-in Orthanc REST API, this call will
1080 * return the result provided by this plugin. The result to the
1081 * query is stored into a newly allocated memory buffer.
1082 *
1083 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1084 * @param target The target memory buffer.
1085 * @param uri The URI in the built-in Orthanc API.
1086 * @param body The body of the PUT request.
1087 * @param bodySize The size of the body.
1088 * @return 0 if success, other value if error.
1089 **/
1090 ORTHANC_PLUGIN_INLINE int OrthancPluginRestApiPutAfterPlugins(
1091 OrthancPluginContext* context,
1092 OrthancPluginMemoryBuffer* target,
1093 const char* uri,
1094 const char* body,
1095 uint32_t bodySize)
1096 {
1097 _OrthancPluginRestApiPostPut params;
1098 params.target = target;
1099 params.uri = uri;
1100 params.body = body;
1101 params.bodySize = bodySize;
1102 return context->InvokeService(context, _OrthancPluginService_RestApiPutAfterPlugins, &params);
1103 }
1104
1105
1106
1107 typedef struct
1108 {
1109 OrthancPluginRestOutput* output;
1110 const char* argument;
1111 } _OrthancPluginOutputPlusArgument;
1112
1113 /**
1114 * @brief Redirect a REST request.
1115 *
1116 * This function answers to a REST request by redirecting the user
1117 * to another URI using HTTP status 301.
1118 *
1119 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1120 * @param output The HTTP connection to the client application.
1121 * @param redirection Where to redirect.
1122 **/
1123 ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect(
1124 OrthancPluginContext* context,
1125 OrthancPluginRestOutput* output,
1126 const char* redirection)
1127 {
1128 _OrthancPluginOutputPlusArgument params;
1129 params.output = output;
1130 params.argument = redirection;
1131 context->InvokeService(context, _OrthancPluginService_Redirect, &params);
1132 }
1133
1134
1135
1136 typedef struct
1137 {
1138 char** result;
1139 const char* argument;
1140 } _OrthancPluginRetrieveDynamicString;
1141
1142 /**
1143 * @brief Look for a patient.
1144 *
1145 * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020).
1146 * This function uses the database index to run as fast as possible (it does not loop
1147 * over all the stored patients).
1148 *
1149 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1150 * @param patientID The Patient ID of interest.
1151 * @return The NULL value if the patient is non-existent, or a string containing the
1152 * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString().
1153 **/
1154 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient(
1155 OrthancPluginContext* context,
1156 const char* patientID)
1157 {
1158 char* result;
1159
1160 _OrthancPluginRetrieveDynamicString params;
1161 params.result = &result;
1162 params.argument = patientID;
1163
1164 if (context->InvokeService(context, _OrthancPluginService_LookupPatient, &params))
1165 {
1166 /* Error */
1167 return NULL;
1168 }
1169 else
1170 {
1171 return result;
1172 }
1173 }
1174
1175
1176 /**
1177 * @brief Look for a study.
1178 *
1179 * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d).
1180 * This function uses the database index to run as fast as possible (it does not loop
1181 * over all the stored studies).
1182 *
1183 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1184 * @param studyUID The Study Instance UID of interest.
1185 * @return The NULL value if the study is non-existent, or a string containing the
1186 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
1187 **/
1188 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy(
1189 OrthancPluginContext* context,
1190 const char* studyUID)
1191 {
1192 char* result;
1193
1194 _OrthancPluginRetrieveDynamicString params;
1195 params.result = &result;
1196 params.argument = studyUID;
1197
1198 if (context->InvokeService(context, _OrthancPluginService_LookupStudy, &params))
1199 {
1200 /* Error */
1201 return NULL;
1202 }
1203 else
1204 {
1205 return result;
1206 }
1207 }
1208
1209
1210 /**
1211 * @brief Look for a study, using the accession number.
1212 *
1213 * Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050).
1214 * This function uses the database index to run as fast as possible (it does not loop
1215 * over all the stored studies).
1216 *
1217 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1218 * @param accessionNumber The Accession Number of interest.
1219 * @return The NULL value if the study is non-existent, or a string containing the
1220 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
1221 **/
1222 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber(
1223 OrthancPluginContext* context,
1224 const char* accessionNumber)
1225 {
1226 char* result;
1227
1228 _OrthancPluginRetrieveDynamicString params;
1229 params.result = &result;
1230 params.argument = accessionNumber;
1231
1232 if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, &params))
1233 {
1234 /* Error */
1235 return NULL;
1236 }
1237 else
1238 {
1239 return result;
1240 }
1241 }
1242
1243
1244 /**
1245 * @brief Look for a series.
1246 *
1247 * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e).
1248 * This function uses the database index to run as fast as possible (it does not loop
1249 * over all the stored series).
1250 *
1251 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1252 * @param seriesUID The Series Instance UID of interest.
1253 * @return The NULL value if the series is non-existent, or a string containing the
1254 * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString().
1255 **/
1256 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries(
1257 OrthancPluginContext* context,
1258 const char* seriesUID)
1259 {
1260 char* result;
1261
1262 _OrthancPluginRetrieveDynamicString params;
1263 params.result = &result;
1264 params.argument = seriesUID;
1265
1266 if (context->InvokeService(context, _OrthancPluginService_LookupSeries, &params))
1267 {
1268 /* Error */
1269 return NULL;
1270 }
1271 else
1272 {
1273 return result;
1274 }
1275 }
1276
1277
1278 /**
1279 * @brief Look for an instance.
1280 *
1281 * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018).
1282 * This function uses the database index to run as fast as possible (it does not loop
1283 * over all the stored instances).
1284 *
1285 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1286 * @param sopInstanceUID The SOP Instance UID of interest.
1287 * @return The NULL value if the instance is non-existent, or a string containing the
1288 * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString().
1289 **/
1290 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance(
1291 OrthancPluginContext* context,
1292 const char* sopInstanceUID)
1293 {
1294 char* result;
1295
1296 _OrthancPluginRetrieveDynamicString params;
1297 params.result = &result;
1298 params.argument = sopInstanceUID;
1299
1300 if (context->InvokeService(context, _OrthancPluginService_LookupInstance, &params))
1301 {
1302 /* Error */
1303 return NULL;
1304 }
1305 else
1306 {
1307 return result;
1308 }
1309 }
1310
1311
1312
1313 typedef struct
1314 {
1315 OrthancPluginRestOutput* output;
1316 uint16_t status;
1317 } _OrthancPluginSendHttpStatusCode;
1318
1319 /**
1320 * @brief Send a HTTP status code.
1321 *
1322 * This function answers to a REST request by sending a HTTP status
1323 * code (such as "400 - Bad Request"). Note that:
1324 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
1325 * - Redirections (status 301) must use ::OrthancPluginRedirect().
1326 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
1327 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
1328 *
1329 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1330 * @param output The HTTP connection to the client application.
1331 * @param status The HTTP status code to be sent.
1332 **/
1333 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode(
1334 OrthancPluginContext* context,
1335 OrthancPluginRestOutput* output,
1336 uint16_t status)
1337 {
1338 _OrthancPluginSendHttpStatusCode params;
1339 params.output = output;
1340 params.status = status;
1341 context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, &params);
1342 }
1343
1344
1345 /**
1346 * @brief Signal that a REST request is not authorized.
1347 *
1348 * This function answers to a REST request by signaling that it is
1349 * not authorized.
1350 *
1351 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1352 * @param output The HTTP connection to the client application.
1353 * @param realm The realm for the authorization process.
1354 **/
1355 ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized(
1356 OrthancPluginContext* context,
1357 OrthancPluginRestOutput* output,
1358 const char* realm)
1359 {
1360 _OrthancPluginOutputPlusArgument params;
1361 params.output = output;
1362 params.argument = realm;
1363 context->InvokeService(context, _OrthancPluginService_SendUnauthorized, &params);
1364 }
1365
1366
1367 /**
1368 * @brief Signal that this URI does not support this HTTP method.
1369 *
1370 * This function answers to a REST request by signaling that the
1371 * queried URI does not support this method.
1372 *
1373 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1374 * @param output The HTTP connection to the client application.
1375 * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request).
1376 **/
1377 ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed(
1378 OrthancPluginContext* context,
1379 OrthancPluginRestOutput* output,
1380 const char* allowedMethods)
1381 {
1382 _OrthancPluginOutputPlusArgument params;
1383 params.output = output;
1384 params.argument = allowedMethods;
1385 context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, &params);
1386 }
1387
1388
1389 typedef struct
1390 {
1391 OrthancPluginRestOutput* output;
1392 const char* key;
1393 const char* value;
1394 } _OrthancPluginSetHttpHeader;
1395
1396 /**
1397 * @brief Set a cookie.
1398 *
1399 * This function sets a cookie in the HTTP client.
1400 *
1401 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1402 * @param output The HTTP connection to the client application.
1403 * @param cookie The cookie to be set.
1404 * @param value The value of the cookie.
1405 **/
1406 ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie(
1407 OrthancPluginContext* context,
1408 OrthancPluginRestOutput* output,
1409 const char* cookie,
1410 const char* value)
1411 {
1412 _OrthancPluginSetHttpHeader params;
1413 params.output = output;
1414 params.key = cookie;
1415 params.value = value;
1416 context->InvokeService(context, _OrthancPluginService_SetCookie, &params);
1417 }
1418
1419
1420 /**
1421 * @brief Set some HTTP header.
1422 *
1423 * This function sets a HTTP header in the HTTP answer.
1424 *
1425 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1426 * @param output The HTTP connection to the client application.
1427 * @param key The HTTP header to be set.
1428 * @param value The value of the HTTP header.
1429 **/
1430 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader(
1431 OrthancPluginContext* context,
1432 OrthancPluginRestOutput* output,
1433 const char* key,
1434 const char* value)
1435 {
1436 _OrthancPluginSetHttpHeader params;
1437 params.output = output;
1438 params.key = key;
1439 params.value = value;
1440 context->InvokeService(context, _OrthancPluginService_SetHttpHeader, &params);
1441 }
1442
1443
1444 typedef struct
1445 {
1446 char** resultStringToFree;
1447 const char** resultString;
1448 int64_t* resultInt64;
1449 const char* key;
1450 OrthancPluginDicomInstance* instance;
1451 } _OrthancPluginAccessDicomInstance;
1452
1453
1454 /**
1455 * @brief Get the AET of a DICOM instance.
1456 *
1457 * This function returns the Application Entity Title (AET) of the
1458 * DICOM modality from which a DICOM instance originates.
1459 *
1460 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1461 * @param instance The instance of interest.
1462 * @return The AET if success, NULL if error.
1463 **/
1464 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet(
1465 OrthancPluginContext* context,
1466 OrthancPluginDicomInstance* instance)
1467 {
1468 const char* result;
1469
1470 _OrthancPluginAccessDicomInstance params;
1471 memset(&params, 0, sizeof(params));
1472 params.resultString = &result;
1473 params.instance = instance;
1474
1475 if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, &params))
1476 {
1477 /* Error */
1478 return NULL;
1479 }
1480 else
1481 {
1482 return result;
1483 }
1484 }
1485
1486
1487 /**
1488 * @brief Get the size of a DICOM file.
1489 *
1490 * This function returns the number of bytes of the given DICOM instance.
1491 *
1492 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1493 * @param instance The instance of interest.
1494 * @return The size of the file, -1 in case of error.
1495 **/
1496 ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize(
1497 OrthancPluginContext* context,
1498 OrthancPluginDicomInstance* instance)
1499 {
1500 int64_t size;
1501
1502 _OrthancPluginAccessDicomInstance params;
1503 memset(&params, 0, sizeof(params));
1504 params.resultInt64 = &size;
1505 params.instance = instance;
1506
1507 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, &params))
1508 {
1509 /* Error */
1510 return -1;
1511 }
1512 else
1513 {
1514 return size;
1515 }
1516 }
1517
1518
1519 /**
1520 * @brief Get the data of a DICOM file.
1521 *
1522 * This function returns a pointer to the content of the given DICOM instance.
1523 *
1524 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1525 * @param instance The instance of interest.
1526 * @return The pointer to the DICOM data, NULL in case of error.
1527 **/
1528 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceData(
1529 OrthancPluginContext* context,
1530 OrthancPluginDicomInstance* instance)
1531 {
1532 const char* result;
1533
1534 _OrthancPluginAccessDicomInstance params;
1535 memset(&params, 0, sizeof(params));
1536 params.resultString = &result;
1537 params.instance = instance;
1538
1539 if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, &params))
1540 {
1541 /* Error */
1542 return NULL;
1543 }
1544 else
1545 {
1546 return result;
1547 }
1548 }
1549
1550
1551 /**
1552 * @brief Get the DICOM tag hierarchy as a JSON file.
1553 *
1554 * This function returns a pointer to a newly created string
1555 * containing a JSON file. This JSON file encodes the tag hierarchy
1556 * of the given DICOM instance.
1557 *
1558 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1559 * @param instance The instance of interest.
1560 * @return The NULL value in case of error, or a string containing the JSON file.
1561 * This string must be freed by OrthancPluginFreeString().
1562 **/
1563 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson(
1564 OrthancPluginContext* context,
1565 OrthancPluginDicomInstance* instance)
1566 {
1567 char* result;
1568
1569 _OrthancPluginAccessDicomInstance params;
1570 memset(&params, 0, sizeof(params));
1571 params.resultStringToFree = &result;
1572 params.instance = instance;
1573
1574 if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, &params))
1575 {
1576 /* Error */
1577 return NULL;
1578 }
1579 else
1580 {
1581 return result;
1582 }
1583 }
1584
1585
1586 /**
1587 * @brief Get the DICOM tag hierarchy as a JSON file (with simplification).
1588 *
1589 * This function returns a pointer to a newly created string
1590 * containing a JSON file. This JSON file encodes the tag hierarchy
1591 * of the given DICOM instance. In contrast with
1592 * ::OrthancPluginGetInstanceJson(), the returned JSON file is in
1593 * its simplified version.
1594 *
1595 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1596 * @param instance The instance of interest.
1597 * @return The NULL value in case of error, or a string containing the JSON file.
1598 * This string must be freed by OrthancPluginFreeString().
1599 **/
1600 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson(
1601 OrthancPluginContext* context,
1602 OrthancPluginDicomInstance* instance)
1603 {
1604 char* result;
1605
1606 _OrthancPluginAccessDicomInstance params;
1607 memset(&params, 0, sizeof(params));
1608 params.resultStringToFree = &result;
1609 params.instance = instance;
1610
1611 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, &params))
1612 {
1613 /* Error */
1614 return NULL;
1615 }
1616 else
1617 {
1618 return result;
1619 }
1620 }
1621
1622
1623 /**
1624 * @brief Check whether a DICOM instance is associated with some metadata.
1625 *
1626 * This function checks whether the DICOM instance of interest is
1627 * associated with some metadata. As of Orthanc 0.8.1, in the
1628 * callbacks registered by
1629 * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only
1630 * possibly available metadata are "ReceptionDate", "RemoteAET" and
1631 * "IndexInSeries".
1632 *
1633 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1634 * @param instance The instance of interest.
1635 * @param metadata The metadata of interest.
1636 * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error.
1637 **/
1638 ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata(
1639 OrthancPluginContext* context,
1640 OrthancPluginDicomInstance* instance,
1641 const char* metadata)
1642 {
1643 int64_t result;
1644
1645 _OrthancPluginAccessDicomInstance params;
1646 memset(&params, 0, sizeof(params));
1647 params.resultInt64 = &result;
1648 params.instance = instance;
1649 params.key = metadata;
1650
1651 if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, &params))
1652 {
1653 /* Error */
1654 return -1;
1655 }
1656 else
1657 {
1658 return (result != 0);
1659 }
1660 }
1661
1662
1663 /**
1664 * @brief Get the value of some metadata associated with a given DICOM instance.
1665 *
1666 * This functions returns the value of some metadata that is associated with the DICOM instance of interest.
1667 * Before calling this function, the existence of the metadata must have been checked with
1668 * ::OrthancPluginHasInstanceMetadata().
1669 *
1670 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1671 * @param instance The instance of interest.
1672 * @param metadata The metadata of interest.
1673 * @return The metadata value if success, NULL if error.
1674 **/
1675 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata(
1676 OrthancPluginContext* context,
1677 OrthancPluginDicomInstance* instance,
1678 const char* metadata)
1679 {
1680 const char* result;
1681
1682 _OrthancPluginAccessDicomInstance params;
1683 memset(&params, 0, sizeof(params));
1684 params.resultString = &result;
1685 params.instance = instance;
1686 params.key = metadata;
1687
1688 if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, &params))
1689 {
1690 /* Error */
1691 return NULL;
1692 }
1693 else
1694 {
1695 return result;
1696 }
1697 }
1698
1699
1700
1701 typedef struct
1702 {
1703 OrthancPluginStorageCreate create;
1704 OrthancPluginStorageRead read;
1705 OrthancPluginStorageRemove remove;
1706 OrthancPluginFree free;
1707 } _OrthancPluginRegisterStorageArea;
1708
1709 /**
1710 * @brief Register a custom storage area.
1711 *
1712 * This function registers a custom storage area, to replace the
1713 * built-in way Orthanc stores its files on the filesystem. This
1714 * function must be called during the initialization of the plugin,
1715 * i.e. inside the OrthancPluginInitialize() public function.
1716 *
1717 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1718 * @param create The callback function to store a file on the custom storage area.
1719 * @param read The callback function to read a file from the custom storage area.
1720 * @param remove The callback function to remove a file from the custom storage area.
1721 **/
1722 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea(
1723 OrthancPluginContext* context,
1724 OrthancPluginStorageCreate create,
1725 OrthancPluginStorageRead read,
1726 OrthancPluginStorageRemove remove)
1727 {
1728 _OrthancPluginRegisterStorageArea params;
1729 params.create = create;
1730 params.read = read;
1731 params.remove = remove;
1732
1733 #ifdef __cplusplus
1734 params.free = ::free;
1735 #else
1736 params.free = free;
1737 #endif
1738
1739 context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, &params);
1740 }
1741
1742
1743
1744 /**
1745 * @brief Return the path to the Orthanc executable.
1746 *
1747 * This function returns the path to the Orthanc executable.
1748 *
1749 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1750 * @return NULL in the case of an error, or a newly allocated string
1751 * containing the path. This string must be freed by
1752 * OrthancPluginFreeString().
1753 **/
1754 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context)
1755 {
1756 char* result;
1757
1758 _OrthancPluginRetrieveDynamicString params;
1759 params.result = &result;
1760 params.argument = NULL;
1761
1762 if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, &params))
1763 {
1764 /* Error */
1765 return NULL;
1766 }
1767 else
1768 {
1769 return result;
1770 }
1771 }
1772
1773
1774 /**
1775 * @brief Return the directory containing the Orthanc.
1776 *
1777 * This function returns the path to the directory containing the Orthanc executable.
1778 *
1779 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1780 * @return NULL in the case of an error, or a newly allocated string
1781 * containing the path. This string must be freed by
1782 * OrthancPluginFreeString().
1783 **/
1784 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context)
1785 {
1786 char* result;
1787
1788 _OrthancPluginRetrieveDynamicString params;
1789 params.result = &result;
1790 params.argument = NULL;
1791
1792 if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, &params))
1793 {
1794 /* Error */
1795 return NULL;
1796 }
1797 else
1798 {
1799 return result;
1800 }
1801 }
1802
1803
1804 /**
1805 * @brief Return the path to the configuration file(s).
1806 *
1807 * This function returns the path to the configuration file(s) that
1808 * was specified when starting Orthanc. Since version 0.9.1, this
1809 * path can refer to a folder that stores a set of configuration
1810 * files. This function is deprecated in favor of
1811 * OrthancPluginGetConfiguration().
1812 *
1813 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1814 * @return NULL in the case of an error, or a newly allocated string
1815 * containing the path. This string must be freed by
1816 * OrthancPluginFreeString().
1817 * @see OrthancPluginGetConfiguration()
1818 **/
1819 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context)
1820 {
1821 char* result;
1822
1823 _OrthancPluginRetrieveDynamicString params;
1824 params.result = &result;
1825 params.argument = NULL;
1826
1827 if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, &params))
1828 {
1829 /* Error */
1830 return NULL;
1831 }
1832 else
1833 {
1834 return result;
1835 }
1836 }
1837
1838
1839
1840 typedef struct
1841 {
1842 OrthancPluginOnChangeCallback callback;
1843 } _OrthancPluginOnChangeCallback;
1844
1845 /**
1846 * @brief Register a callback to monitor changes.
1847 *
1848 * This function registers a callback function that is called
1849 * whenever a change happens to some DICOM resource.
1850 *
1851 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1852 * @param callback The callback function.
1853 **/
1854 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnChangeCallback(
1855 OrthancPluginContext* context,
1856 OrthancPluginOnChangeCallback callback)
1857 {
1858 _OrthancPluginOnChangeCallback params;
1859 params.callback = callback;
1860
1861 context->InvokeService(context, _OrthancPluginService_RegisterOnChangeCallback, &params);
1862 }
1863
1864
1865
1866 typedef struct
1867 {
1868 const char* plugin;
1869 _OrthancPluginProperty property;
1870 const char* value;
1871 } _OrthancPluginSetPluginProperty;
1872
1873
1874 /**
1875 * @brief Set the URI where the plugin provides its Web interface.
1876 *
1877 * For plugins that come with a Web interface, this function
1878 * declares the entry path where to find this interface. This
1879 * information is notably used in the "Plugins" page of Orthanc
1880 * Explorer.
1881 *
1882 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1883 * @param uri The root URI for this plugin.
1884 **/
1885 ORTHANC_PLUGIN_INLINE void OrthancPluginSetRootUri(
1886 OrthancPluginContext* context,
1887 const char* uri)
1888 {
1889 _OrthancPluginSetPluginProperty params;
1890 params.plugin = OrthancPluginGetName();
1891 params.property = _OrthancPluginProperty_RootUri;
1892 params.value = uri;
1893
1894 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
1895 }
1896
1897
1898 /**
1899 * @brief Set a description for this plugin.
1900 *
1901 * Set a description for this plugin. It is displayed in the
1902 * "Plugins" page of Orthanc Explorer.
1903 *
1904 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1905 * @param description The description.
1906 **/
1907 ORTHANC_PLUGIN_INLINE void OrthancPluginSetDescription(
1908 OrthancPluginContext* context,
1909 const char* description)
1910 {
1911 _OrthancPluginSetPluginProperty params;
1912 params.plugin = OrthancPluginGetName();
1913 params.property = _OrthancPluginProperty_Description;
1914 params.value = description;
1915
1916 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
1917 }
1918
1919
1920 /**
1921 * @brief Extend the JavaScript code of Orthanc Explorer.
1922 *
1923 * Add JavaScript code to customize the default behavior of Orthanc
1924 * Explorer. This can for instance be used to add new buttons.
1925 *
1926 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1927 * @param javascript The custom JavaScript code.
1928 **/
1929 ORTHANC_PLUGIN_INLINE void OrthancPluginExtendOrthancExplorer(
1930 OrthancPluginContext* context,
1931 const char* javascript)
1932 {
1933 _OrthancPluginSetPluginProperty params;
1934 params.plugin = OrthancPluginGetName();
1935 params.property = _OrthancPluginProperty_OrthancExplorer;
1936 params.value = javascript;
1937
1938 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
1939 }
1940
1941
1942 typedef struct
1943 {
1944 char** result;
1945 int32_t property;
1946 const char* value;
1947 } _OrthancPluginGlobalProperty;
1948
1949
1950 /**
1951 * @brief Get the value of a global property.
1952 *
1953 * Get the value of a global property that is stored in the Orthanc database. Global
1954 * properties whose index is below 1024 are reserved by Orthanc.
1955 *
1956 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1957 * @param property The global property of interest.
1958 * @param defaultValue The value to return, if the global property is unset.
1959 * @return The value of the global property, or NULL in the case of an error. This
1960 * string must be freed by OrthancPluginFreeString().
1961 **/
1962 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetGlobalProperty(
1963 OrthancPluginContext* context,
1964 int32_t property,
1965 const char* defaultValue)
1966 {
1967 char* result;
1968
1969 _OrthancPluginGlobalProperty params;
1970 params.result = &result;
1971 params.property = property;
1972 params.value = defaultValue;
1973
1974 if (context->InvokeService(context, _OrthancPluginService_GetGlobalProperty, &params))
1975 {
1976 /* Error */
1977 return NULL;
1978 }
1979 else
1980 {
1981 return result;
1982 }
1983 }
1984
1985
1986 /**
1987 * @brief Set the value of a global property.
1988 *
1989 * Set the value of a global property into the Orthanc
1990 * database. Setting a global property can be used by plugins to
1991 * save their internal parameters. Plugins are only allowed to set
1992 * properties whose index are above or equal to 1024 (properties
1993 * below 1024 are read-only and reserved by Orthanc).
1994 *
1995 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1996 * @param property The global property of interest.
1997 * @param value The value to be set in the global property.
1998 * @return 0 if success, -1 in case of error.
1999 **/
2000 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginSetGlobalProperty(
2001 OrthancPluginContext* context,
2002 int32_t property,
2003 const char* value)
2004 {
2005 _OrthancPluginGlobalProperty params;
2006 params.result = NULL;
2007 params.property = property;
2008 params.value = value;
2009
2010 if (context->InvokeService(context, _OrthancPluginService_SetGlobalProperty, &params))
2011 {
2012 /* Error */
2013 return -1;
2014 }
2015 else
2016 {
2017 return 0;
2018 }
2019 }
2020
2021
2022
2023 typedef struct
2024 {
2025 int32_t *resultInt32;
2026 uint32_t *resultUint32;
2027 int64_t *resultInt64;
2028 uint64_t *resultUint64;
2029 } _OrthancPluginReturnSingleValue;
2030
2031 /**
2032 * @brief Get the number of command-line arguments.
2033 *
2034 * Retrieve the number of command-line arguments that were used to launch Orthanc.
2035 *
2036 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2037 * @return The number of arguments.
2038 **/
2039 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetCommandLineArgumentsCount(
2040 OrthancPluginContext* context)
2041 {
2042 uint32_t count = 0;
2043
2044 _OrthancPluginReturnSingleValue params;
2045 memset(&params, 0, sizeof(params));
2046 params.resultUint32 = &count;
2047
2048 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgumentsCount, &params))
2049 {
2050 /* Error */
2051 return 0;
2052 }
2053 else
2054 {
2055 return count;
2056 }
2057 }
2058
2059
2060
2061 /**
2062 * @brief Get the value of a command-line argument.
2063 *
2064 * Get the value of one of the command-line arguments that were used
2065 * to launch Orthanc. The number of available arguments can be
2066 * retrieved by OrthancPluginGetCommandLineArgumentsCount().
2067 *
2068 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2069 * @param argument The index of the argument.
2070 * @return The value of the argument, or NULL in the case of an error. This
2071 * string must be freed by OrthancPluginFreeString().
2072 **/
2073 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetCommandLineArgument(
2074 OrthancPluginContext* context,
2075 uint32_t argument)
2076 {
2077 char* result;
2078
2079 _OrthancPluginGlobalProperty params;
2080 params.result = &result;
2081 params.property = (int32_t) argument;
2082 params.value = NULL;
2083
2084 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgument, &params))
2085 {
2086 /* Error */
2087 return NULL;
2088 }
2089 else
2090 {
2091 return result;
2092 }
2093 }
2094
2095
2096 /**
2097 * @brief Get the expected version of the database schema.
2098 *
2099 * Retrieve the expected version of the database schema.
2100 *
2101 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2102 * @return The version.
2103 **/
2104 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion(
2105 OrthancPluginContext* context)
2106 {
2107 uint32_t count = 0;
2108
2109 _OrthancPluginReturnSingleValue params;
2110 memset(&params, 0, sizeof(params));
2111 params.resultUint32 = &count;
2112
2113 if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, &params))
2114 {
2115 /* Error */
2116 return 0;
2117 }
2118 else
2119 {
2120 return count;
2121 }
2122 }
2123
2124
2125
2126 /**
2127 * @brief Return the content of the configuration file(s).
2128 *
2129 * This function returns the content of the configuration that is
2130 * used by Orthanc, formatted as a JSON string.
2131 *
2132 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2133 * @return NULL in the case of an error, or a newly allocated string
2134 * containing the configuration. This string must be freed by
2135 * OrthancPluginFreeString().
2136 **/
2137 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfiguration(OrthancPluginContext* context)
2138 {
2139 char* result;
2140
2141 _OrthancPluginRetrieveDynamicString params;
2142 params.result = &result;
2143 params.argument = NULL;
2144
2145 if (context->InvokeService(context, _OrthancPluginService_GetConfiguration, &params))
2146 {
2147 /* Error */
2148 return NULL;
2149 }
2150 else
2151 {
2152 return result;
2153 }
2154 }
2155
2156
2157
2158 typedef struct
2159 {
2160 OrthancPluginRestOutput* output;
2161 const char* subType;
2162 const char* contentType;
2163 } _OrthancPluginStartMultipartAnswer;
2164
2165 /**
2166 * @brief Start an HTTP multipart answer.
2167 *
2168 * Initiates a HTTP multipart answer, as the result of a REST request.
2169 *
2170 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2171 * @param output The HTTP connection to the client application.
2172 * @param subType The sub-type of the multipart answer ("mixed" or "related").
2173 * @param contentType The MIME type of the items in the multipart answer.
2174 * @return 0 if success, other value if error.
2175 * @see OrthancPluginSendMultipartItem()
2176 **/
2177 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginStartMultipartAnswer(
2178 OrthancPluginContext* context,
2179 OrthancPluginRestOutput* output,
2180 const char* subType,
2181 const char* contentType)
2182 {
2183 _OrthancPluginStartMultipartAnswer params;
2184 params.output = output;
2185 params.subType = subType;
2186 params.contentType = contentType;
2187 return context->InvokeService(context, _OrthancPluginService_StartMultipartAnswer, &params);
2188 }
2189
2190
2191 /**
2192 * @brief Send an item as a part of some HTTP multipart answer.
2193 *
2194 * This function sends an item as a part of some HTTP multipart
2195 * answer that was initiated by OrthancPluginStartMultipartAnswer().
2196 *
2197 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2198 * @param output The HTTP connection to the client application.
2199 * @param answer Pointer to the memory buffer containing the item.
2200 * @param answerSize Number of bytes of the item.
2201 * @return 0 if success, other value if error (this notably happens
2202 * if the connection is closed by the client).
2203 **/
2204 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginSendMultipartItem(
2205 OrthancPluginContext* context,
2206 OrthancPluginRestOutput* output,
2207 const char* answer,
2208 uint32_t answerSize)
2209 {
2210 _OrthancPluginAnswerBuffer params;
2211 params.output = output;
2212 params.answer = answer;
2213 params.answerSize = answerSize;
2214 params.mimeType = NULL;
2215 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem, &params);
2216 }
2217
2218 #ifdef __cplusplus
2219 }
2220 #endif
2221
2222
2223 /** @} */
2224