Mercurial > hg > orthanc-transfers
comparison Resources/Orthanc/Sdk-1.12.1/orthanc/OrthancCPlugin.h @ 64:5fb01c588287
updated to Orthanc Framework 1.12.1
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 11 Oct 2023 15:58:27 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
63:9789c6003e9d | 64:5fb01c588287 |
---|---|
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 ::OrthancPluginRegisterStorageArea2(). | |
20 * - Possibly register a custom database back-end area using OrthancPluginRegisterDatabaseBackendV4(). | |
21 * - Possibly register a handler for C-Find SCP using OrthancPluginRegisterFindCallback(). | |
22 * - Possibly register a handler for C-Find SCP against DICOM worklists using OrthancPluginRegisterWorklistCallback(). | |
23 * - Possibly register a handler for C-Move SCP using OrthancPluginRegisterMoveCallback(). | |
24 * - Possibly register a custom decoder for DICOM images using OrthancPluginRegisterDecodeImageCallback(). | |
25 * - Possibly register a callback to filter incoming HTTP requests using OrthancPluginRegisterIncomingHttpRequestFilter2(). | |
26 * - Possibly register a callback to unserialize jobs using OrthancPluginRegisterJobsUnserializer(). | |
27 * - Possibly register a callback to refresh its metrics using OrthancPluginRegisterRefreshMetricsCallback(). | |
28 * - Possibly register a callback to answer chunked HTTP transfers using ::OrthancPluginRegisterChunkedRestCallback(). | |
29 * - Possibly register a callback for Storage Commitment SCP using ::OrthancPluginRegisterStorageCommitmentScpCallback(). | |
30 * - Possibly register a callback to keep/discard/modify incoming DICOM instances using OrthancPluginRegisterReceivedInstanceCallback(). | |
31 * - Possibly register a custom transcoder for DICOM images using OrthancPluginRegisterTranscoderCallback(). | |
32 * - Possibly register a callback to discard instances received through DICOM C-STORE using OrthancPluginRegisterIncomingCStoreInstanceFilter(). | |
33 * - Possibly register a callback to branch a WebDAV virtual filesystem using OrthancPluginRegisterWebDavCollection(). | |
34 * -# <tt>void OrthancPluginFinalize()</tt>: | |
35 * This function is invoked by Orthanc during its shutdown. The plugin | |
36 * must free all its memory. | |
37 * -# <tt>const char* OrthancPluginGetName()</tt>: | |
38 * The plugin must return a short string to identify itself. | |
39 * -# <tt>const char* OrthancPluginGetVersion()</tt>: | |
40 * The plugin must return a string containing its version number. | |
41 * | |
42 * The name and the version of a plugin is only used to prevent it | |
43 * from being loaded twice. Note that, in C++, it is mandatory to | |
44 * declare these functions within an <tt>extern "C"</tt> section. | |
45 * | |
46 * To ensure multi-threading safety, the various REST callbacks are | |
47 * guaranteed to be executed in mutual exclusion since Orthanc | |
48 * 0.8.5. If this feature is undesired (notably when developing | |
49 * high-performance plugins handling simultaneous requests), use | |
50 * ::OrthancPluginRegisterRestCallbackNoLock(). | |
51 **/ | |
52 | |
53 | |
54 | |
55 /** | |
56 * @defgroup Images Images and compression | |
57 * @brief Functions to deal with images and compressed buffers. | |
58 * | |
59 * @defgroup REST REST | |
60 * @brief Functions to answer REST requests in a callback. | |
61 * | |
62 * @defgroup Callbacks Callbacks | |
63 * @brief Functions to register and manage callbacks by the plugins. | |
64 * | |
65 * @defgroup DicomCallbacks DicomCallbacks | |
66 * @brief Functions to register and manage DICOM callbacks (worklists, C-FIND, C-MOVE, storage commitment). | |
67 * | |
68 * @defgroup Orthanc Orthanc | |
69 * @brief Functions to access the content of the Orthanc server. | |
70 * | |
71 * @defgroup DicomInstance DicomInstance | |
72 * @brief Functions to access DICOM images that are managed by the Orthanc core. | |
73 **/ | |
74 | |
75 | |
76 | |
77 /** | |
78 * @defgroup Toolbox Toolbox | |
79 * @brief Generic functions to help with the creation of plugins. | |
80 **/ | |
81 | |
82 | |
83 | |
84 /** | |
85 * Orthanc - A Lightweight, RESTful DICOM Store | |
86 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
87 * Department, University Hospital of Liege, Belgium | |
88 * Copyright (C) 2017-2023 Osimis S.A., Belgium | |
89 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
90 * | |
91 * This program is free software: you can redistribute it and/or | |
92 * modify it under the terms of the GNU General Public License as | |
93 * published by the Free Software Foundation, either version 3 of the | |
94 * License, or (at your option) any later version. | |
95 * | |
96 * This program is distributed in the hope that it will be useful, but | |
97 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
98 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
99 * General Public License for more details. | |
100 * | |
101 * You should have received a copy of the GNU General Public License | |
102 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
103 **/ | |
104 | |
105 | |
106 | |
107 #pragma once | |
108 | |
109 | |
110 #include <stdio.h> | |
111 #include <string.h> | |
112 | |
113 #ifdef WIN32 | |
114 # define ORTHANC_PLUGINS_API __declspec(dllexport) | |
115 #elif __GNUC__ >= 4 | |
116 # define ORTHANC_PLUGINS_API __attribute__ ((visibility ("default"))) | |
117 #else | |
118 # define ORTHANC_PLUGINS_API | |
119 #endif | |
120 | |
121 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1 | |
122 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 12 | |
123 #define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 1 | |
124 | |
125 | |
126 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) | |
127 #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \ | |
128 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \ | |
129 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \ | |
130 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \ | |
131 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \ | |
132 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision)))) | |
133 #endif | |
134 | |
135 | |
136 | |
137 /******************************************************************** | |
138 ** Check that function inlining is properly supported. The use of | |
139 ** inlining is required, to avoid the duplication of object code | |
140 ** between two compilation modules that would use the Orthanc Plugin | |
141 ** API. | |
142 ********************************************************************/ | |
143 | |
144 /* If the auto-detection of the "inline" keyword below does not work | |
145 automatically and that your compiler is known to properly support | |
146 inlining, uncomment the following #define and adapt the definition | |
147 of "static inline". */ | |
148 | |
149 /* #define ORTHANC_PLUGIN_INLINE static inline */ | |
150 | |
151 #ifndef ORTHANC_PLUGIN_INLINE | |
152 # if __STDC_VERSION__ >= 199901L | |
153 /* This is C99 or above: http://predef.sourceforge.net/prestd.html */ | |
154 # define ORTHANC_PLUGIN_INLINE static inline | |
155 # elif defined(__cplusplus) | |
156 /* This is C++ */ | |
157 # define ORTHANC_PLUGIN_INLINE static inline | |
158 # elif defined(__GNUC__) | |
159 /* This is GCC running in C89 mode */ | |
160 # define ORTHANC_PLUGIN_INLINE static __inline | |
161 # elif defined(_MSC_VER) | |
162 /* This is Visual Studio running in C89 mode */ | |
163 # define ORTHANC_PLUGIN_INLINE static __inline | |
164 # else | |
165 # error Your compiler is not known to support the "inline" keyword | |
166 # endif | |
167 #endif | |
168 | |
169 | |
170 | |
171 /******************************************************************** | |
172 ** Inclusion of standard libraries. | |
173 ********************************************************************/ | |
174 | |
175 /** | |
176 * For Microsoft Visual Studio, a compatibility "stdint.h" can be | |
177 * downloaded at the following URL: | |
178 * https://hg.orthanc-server.com/orthanc/raw-file/tip/Resources/ThirdParty/VisualStudio/stdint.h | |
179 **/ | |
180 #include <stdint.h> | |
181 | |
182 #include <stdlib.h> | |
183 | |
184 | |
185 | |
186 /******************************************************************** | |
187 ** Definition of the Orthanc Plugin API. | |
188 ********************************************************************/ | |
189 | |
190 /** @{ */ | |
191 | |
192 #ifdef __cplusplus | |
193 extern "C" | |
194 { | |
195 #endif | |
196 | |
197 /** | |
198 * The various error codes that can be returned by the Orthanc core. | |
199 **/ | |
200 typedef enum | |
201 { | |
202 OrthancPluginErrorCode_InternalError = -1 /*!< Internal error */, | |
203 OrthancPluginErrorCode_Success = 0 /*!< Success */, | |
204 OrthancPluginErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */, | |
205 OrthancPluginErrorCode_NotImplemented = 2 /*!< Not implemented yet */, | |
206 OrthancPluginErrorCode_ParameterOutOfRange = 3 /*!< Parameter out of range */, | |
207 OrthancPluginErrorCode_NotEnoughMemory = 4 /*!< The server hosting Orthanc is running out of memory */, | |
208 OrthancPluginErrorCode_BadParameterType = 5 /*!< Bad type for a parameter */, | |
209 OrthancPluginErrorCode_BadSequenceOfCalls = 6 /*!< Bad sequence of calls */, | |
210 OrthancPluginErrorCode_InexistentItem = 7 /*!< Accessing an inexistent item */, | |
211 OrthancPluginErrorCode_BadRequest = 8 /*!< Bad request */, | |
212 OrthancPluginErrorCode_NetworkProtocol = 9 /*!< Error in the network protocol */, | |
213 OrthancPluginErrorCode_SystemCommand = 10 /*!< Error while calling a system command */, | |
214 OrthancPluginErrorCode_Database = 11 /*!< Error with the database engine */, | |
215 OrthancPluginErrorCode_UriSyntax = 12 /*!< Badly formatted URI */, | |
216 OrthancPluginErrorCode_InexistentFile = 13 /*!< Inexistent file */, | |
217 OrthancPluginErrorCode_CannotWriteFile = 14 /*!< Cannot write to file */, | |
218 OrthancPluginErrorCode_BadFileFormat = 15 /*!< Bad file format */, | |
219 OrthancPluginErrorCode_Timeout = 16 /*!< Timeout */, | |
220 OrthancPluginErrorCode_UnknownResource = 17 /*!< Unknown resource */, | |
221 OrthancPluginErrorCode_IncompatibleDatabaseVersion = 18 /*!< Incompatible version of the database */, | |
222 OrthancPluginErrorCode_FullStorage = 19 /*!< The file storage is full */, | |
223 OrthancPluginErrorCode_CorruptedFile = 20 /*!< Corrupted file (e.g. inconsistent MD5 hash) */, | |
224 OrthancPluginErrorCode_InexistentTag = 21 /*!< Inexistent tag */, | |
225 OrthancPluginErrorCode_ReadOnly = 22 /*!< Cannot modify a read-only data structure */, | |
226 OrthancPluginErrorCode_IncompatibleImageFormat = 23 /*!< Incompatible format of the images */, | |
227 OrthancPluginErrorCode_IncompatibleImageSize = 24 /*!< Incompatible size of the images */, | |
228 OrthancPluginErrorCode_SharedLibrary = 25 /*!< Error while using a shared library (plugin) */, | |
229 OrthancPluginErrorCode_UnknownPluginService = 26 /*!< Plugin invoking an unknown service */, | |
230 OrthancPluginErrorCode_UnknownDicomTag = 27 /*!< Unknown DICOM tag */, | |
231 OrthancPluginErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */, | |
232 OrthancPluginErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */, | |
233 OrthancPluginErrorCode_BadFont = 30 /*!< Badly formatted font file */, | |
234 OrthancPluginErrorCode_DatabasePlugin = 31 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */, | |
235 OrthancPluginErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */, | |
236 OrthancPluginErrorCode_EmptyRequest = 33 /*!< The request is empty */, | |
237 OrthancPluginErrorCode_NotAcceptable = 34 /*!< Cannot send a response which is acceptable according to the Accept HTTP header */, | |
238 OrthancPluginErrorCode_NullPointer = 35 /*!< Cannot handle a NULL pointer */, | |
239 OrthancPluginErrorCode_DatabaseUnavailable = 36 /*!< The database is currently not available (probably a transient situation) */, | |
240 OrthancPluginErrorCode_CanceledJob = 37 /*!< This job was canceled */, | |
241 OrthancPluginErrorCode_BadGeometry = 38 /*!< Geometry error encountered in Stone */, | |
242 OrthancPluginErrorCode_SslInitialization = 39 /*!< Cannot initialize SSL encryption, check out your certificates */, | |
243 OrthancPluginErrorCode_DiscontinuedAbi = 40 /*!< Calling a function that has been removed from the Orthanc Framework */, | |
244 OrthancPluginErrorCode_BadRange = 41 /*!< Incorrect range request */, | |
245 OrthancPluginErrorCode_DatabaseCannotSerialize = 42 /*!< Database could not serialize access due to concurrent update, the transaction should be retried */, | |
246 OrthancPluginErrorCode_Revision = 43 /*!< A bad revision number was provided, which might indicate conflict between multiple writers */, | |
247 OrthancPluginErrorCode_MainDicomTagsMultiplyDefined = 44 /*!< A main DICOM Tag has been defined multiple times for the same resource level */, | |
248 OrthancPluginErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */, | |
249 OrthancPluginErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */, | |
250 OrthancPluginErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */, | |
251 OrthancPluginErrorCode_SQLiteStatementAlreadyUsed = 1003 /*!< SQLite: This cached statement is already being referred to */, | |
252 OrthancPluginErrorCode_SQLiteExecute = 1004 /*!< SQLite: Cannot execute a command */, | |
253 OrthancPluginErrorCode_SQLiteRollbackWithoutTransaction = 1005 /*!< SQLite: Rolling back a nonexistent transaction (have you called Begin()?) */, | |
254 OrthancPluginErrorCode_SQLiteCommitWithoutTransaction = 1006 /*!< SQLite: Committing a nonexistent transaction */, | |
255 OrthancPluginErrorCode_SQLiteRegisterFunction = 1007 /*!< SQLite: Unable to register a function */, | |
256 OrthancPluginErrorCode_SQLiteFlush = 1008 /*!< SQLite: Unable to flush the database */, | |
257 OrthancPluginErrorCode_SQLiteCannotRun = 1009 /*!< SQLite: Cannot run a cached statement */, | |
258 OrthancPluginErrorCode_SQLiteCannotStep = 1010 /*!< SQLite: Cannot step over a cached statement */, | |
259 OrthancPluginErrorCode_SQLiteBindOutOfRange = 1011 /*!< SQLite: Bing a value while out of range (serious error) */, | |
260 OrthancPluginErrorCode_SQLitePrepareStatement = 1012 /*!< SQLite: Cannot prepare a cached statement */, | |
261 OrthancPluginErrorCode_SQLiteTransactionAlreadyStarted = 1013 /*!< SQLite: Beginning the same transaction twice */, | |
262 OrthancPluginErrorCode_SQLiteTransactionCommit = 1014 /*!< SQLite: Failure when committing the transaction */, | |
263 OrthancPluginErrorCode_SQLiteTransactionBegin = 1015 /*!< SQLite: Cannot start a transaction */, | |
264 OrthancPluginErrorCode_DirectoryOverFile = 2000 /*!< The directory to be created is already occupied by a regular file */, | |
265 OrthancPluginErrorCode_FileStorageCannotWrite = 2001 /*!< Unable to create a subdirectory or a file in the file storage */, | |
266 OrthancPluginErrorCode_DirectoryExpected = 2002 /*!< The specified path does not point to a directory */, | |
267 OrthancPluginErrorCode_HttpPortInUse = 2003 /*!< The TCP port of the HTTP server is privileged or already in use */, | |
268 OrthancPluginErrorCode_DicomPortInUse = 2004 /*!< The TCP port of the DICOM server is privileged or already in use */, | |
269 OrthancPluginErrorCode_BadHttpStatusInRest = 2005 /*!< This HTTP status is not allowed in a REST API */, | |
270 OrthancPluginErrorCode_RegularFileExpected = 2006 /*!< The specified path does not point to a regular file */, | |
271 OrthancPluginErrorCode_PathToExecutable = 2007 /*!< Unable to get the path to the executable */, | |
272 OrthancPluginErrorCode_MakeDirectory = 2008 /*!< Cannot create a directory */, | |
273 OrthancPluginErrorCode_BadApplicationEntityTitle = 2009 /*!< An application entity title (AET) cannot be empty or be longer than 16 characters */, | |
274 OrthancPluginErrorCode_NoCFindHandler = 2010 /*!< No request handler factory for DICOM C-FIND SCP */, | |
275 OrthancPluginErrorCode_NoCMoveHandler = 2011 /*!< No request handler factory for DICOM C-MOVE SCP */, | |
276 OrthancPluginErrorCode_NoCStoreHandler = 2012 /*!< No request handler factory for DICOM C-STORE SCP */, | |
277 OrthancPluginErrorCode_NoApplicationEntityFilter = 2013 /*!< No application entity filter */, | |
278 OrthancPluginErrorCode_NoSopClassOrInstance = 2014 /*!< DicomUserConnection: Unable to find the SOP class and instance */, | |
279 OrthancPluginErrorCode_NoPresentationContext = 2015 /*!< DicomUserConnection: No acceptable presentation context for modality */, | |
280 OrthancPluginErrorCode_DicomFindUnavailable = 2016 /*!< DicomUserConnection: The C-FIND command is not supported by the remote SCP */, | |
281 OrthancPluginErrorCode_DicomMoveUnavailable = 2017 /*!< DicomUserConnection: The C-MOVE command is not supported by the remote SCP */, | |
282 OrthancPluginErrorCode_CannotStoreInstance = 2018 /*!< Cannot store an instance */, | |
283 OrthancPluginErrorCode_CreateDicomNotString = 2019 /*!< Only string values are supported when creating DICOM instances */, | |
284 OrthancPluginErrorCode_CreateDicomOverrideTag = 2020 /*!< Trying to override a value inherited from a parent module */, | |
285 OrthancPluginErrorCode_CreateDicomUseContent = 2021 /*!< Use \"Content\" to inject an image into a new DICOM instance */, | |
286 OrthancPluginErrorCode_CreateDicomNoPayload = 2022 /*!< No payload is present for one instance in the series */, | |
287 OrthancPluginErrorCode_CreateDicomUseDataUriScheme = 2023 /*!< The payload of the DICOM instance must be specified according to Data URI scheme */, | |
288 OrthancPluginErrorCode_CreateDicomBadParent = 2024 /*!< Trying to attach a new DICOM instance to an inexistent resource */, | |
289 OrthancPluginErrorCode_CreateDicomParentIsInstance = 2025 /*!< Trying to attach a new DICOM instance to an instance (must be a series, study or patient) */, | |
290 OrthancPluginErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */, | |
291 OrthancPluginErrorCode_UnknownModality = 2027 /*!< Unknown modality */, | |
292 OrthancPluginErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */, | |
293 OrthancPluginErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */, | |
294 OrthancPluginErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */, | |
295 OrthancPluginErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */, | |
296 OrthancPluginErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */, | |
297 OrthancPluginErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */, | |
298 OrthancPluginErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */, | |
299 OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */, | |
300 OrthancPluginErrorCode_StorageAreaAlreadyRegistered = 2036 /*!< Another plugin has already registered a custom storage area */, | |
301 OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered = 2037 /*!< Another plugin has already registered a custom database back-end */, | |
302 OrthancPluginErrorCode_DatabaseNotInitialized = 2038 /*!< Plugin trying to call the database during its initialization */, | |
303 OrthancPluginErrorCode_SslDisabled = 2039 /*!< Orthanc has been built without SSL support */, | |
304 OrthancPluginErrorCode_CannotOrderSlices = 2040 /*!< Unable to order the slices of the series */, | |
305 OrthancPluginErrorCode_NoWorklistHandler = 2041 /*!< No request handler factory for DICOM C-Find Modality SCP */, | |
306 OrthancPluginErrorCode_AlreadyExistingTag = 2042 /*!< Cannot override the value of a tag that already exists */, | |
307 OrthancPluginErrorCode_NoStorageCommitmentHandler = 2043 /*!< No request handler factory for DICOM N-ACTION SCP (storage commitment) */, | |
308 OrthancPluginErrorCode_NoCGetHandler = 2044 /*!< No request handler factory for DICOM C-GET SCP */, | |
309 OrthancPluginErrorCode_UnsupportedMediaType = 3000 /*!< Unsupported media type */, | |
310 | |
311 _OrthancPluginErrorCode_INTERNAL = 0x7fffffff | |
312 } OrthancPluginErrorCode; | |
313 | |
314 | |
315 /** | |
316 * Forward declaration of one of the mandatory functions for Orthanc | |
317 * plugins. | |
318 **/ | |
319 ORTHANC_PLUGINS_API const char* OrthancPluginGetName(); | |
320 | |
321 | |
322 /** | |
323 * The various HTTP methods for a REST call. | |
324 **/ | |
325 typedef enum | |
326 { | |
327 OrthancPluginHttpMethod_Get = 1, /*!< GET request */ | |
328 OrthancPluginHttpMethod_Post = 2, /*!< POST request */ | |
329 OrthancPluginHttpMethod_Put = 3, /*!< PUT request */ | |
330 OrthancPluginHttpMethod_Delete = 4, /*!< DELETE request */ | |
331 | |
332 _OrthancPluginHttpMethod_INTERNAL = 0x7fffffff | |
333 } OrthancPluginHttpMethod; | |
334 | |
335 | |
336 /** | |
337 * @brief The parameters of a REST request. | |
338 * @ingroup Callbacks | |
339 **/ | |
340 typedef struct | |
341 { | |
342 /** | |
343 * @brief The HTTP method. | |
344 **/ | |
345 OrthancPluginHttpMethod method; | |
346 | |
347 /** | |
348 * @brief The number of groups of the regular expression. | |
349 **/ | |
350 uint32_t groupsCount; | |
351 | |
352 /** | |
353 * @brief The matched values for the groups of the regular expression. | |
354 **/ | |
355 const char* const* groups; | |
356 | |
357 /** | |
358 * @brief For a GET request, the number of GET parameters. | |
359 **/ | |
360 uint32_t getCount; | |
361 | |
362 /** | |
363 * @brief For a GET request, the keys of the GET parameters. | |
364 **/ | |
365 const char* const* getKeys; | |
366 | |
367 /** | |
368 * @brief For a GET request, the values of the GET parameters. | |
369 **/ | |
370 const char* const* getValues; | |
371 | |
372 /** | |
373 * @brief For a PUT or POST request, the content of the body. | |
374 **/ | |
375 const void* body; | |
376 | |
377 /** | |
378 * @brief For a PUT or POST request, the number of bytes of the body. | |
379 **/ | |
380 uint32_t bodySize; | |
381 | |
382 | |
383 /* -------------------------------------------------- | |
384 New in version 0.8.1 | |
385 -------------------------------------------------- */ | |
386 | |
387 /** | |
388 * @brief The number of HTTP headers. | |
389 **/ | |
390 uint32_t headersCount; | |
391 | |
392 /** | |
393 * @brief The keys of the HTTP headers (always converted to low-case). | |
394 **/ | |
395 const char* const* headersKeys; | |
396 | |
397 /** | |
398 * @brief The values of the HTTP headers. | |
399 **/ | |
400 const char* const* headersValues; | |
401 | |
402 } OrthancPluginHttpRequest; | |
403 | |
404 | |
405 typedef enum | |
406 { | |
407 /* Generic services */ | |
408 _OrthancPluginService_LogInfo = 1, | |
409 _OrthancPluginService_LogWarning = 2, | |
410 _OrthancPluginService_LogError = 3, | |
411 _OrthancPluginService_GetOrthancPath = 4, | |
412 _OrthancPluginService_GetOrthancDirectory = 5, | |
413 _OrthancPluginService_GetConfigurationPath = 6, | |
414 _OrthancPluginService_SetPluginProperty = 7, | |
415 _OrthancPluginService_GetGlobalProperty = 8, | |
416 _OrthancPluginService_SetGlobalProperty = 9, | |
417 _OrthancPluginService_GetCommandLineArgumentsCount = 10, | |
418 _OrthancPluginService_GetCommandLineArgument = 11, | |
419 _OrthancPluginService_GetExpectedDatabaseVersion = 12, | |
420 _OrthancPluginService_GetConfiguration = 13, | |
421 _OrthancPluginService_BufferCompression = 14, | |
422 _OrthancPluginService_ReadFile = 15, | |
423 _OrthancPluginService_WriteFile = 16, | |
424 _OrthancPluginService_GetErrorDescription = 17, | |
425 _OrthancPluginService_CallHttpClient = 18, | |
426 _OrthancPluginService_RegisterErrorCode = 19, | |
427 _OrthancPluginService_RegisterDictionaryTag = 20, | |
428 _OrthancPluginService_DicomBufferToJson = 21, | |
429 _OrthancPluginService_DicomInstanceToJson = 22, | |
430 _OrthancPluginService_CreateDicom = 23, | |
431 _OrthancPluginService_ComputeMd5 = 24, | |
432 _OrthancPluginService_ComputeSha1 = 25, | |
433 _OrthancPluginService_LookupDictionary = 26, | |
434 _OrthancPluginService_CallHttpClient2 = 27, | |
435 _OrthancPluginService_GenerateUuid = 28, | |
436 _OrthancPluginService_RegisterPrivateDictionaryTag = 29, | |
437 _OrthancPluginService_AutodetectMimeType = 30, | |
438 _OrthancPluginService_SetMetricsValue = 31, | |
439 _OrthancPluginService_EncodeDicomWebJson = 32, | |
440 _OrthancPluginService_EncodeDicomWebXml = 33, | |
441 _OrthancPluginService_ChunkedHttpClient = 34, /* New in Orthanc 1.5.7 */ | |
442 _OrthancPluginService_GetTagName = 35, /* New in Orthanc 1.5.7 */ | |
443 _OrthancPluginService_EncodeDicomWebJson2 = 36, /* New in Orthanc 1.7.0 */ | |
444 _OrthancPluginService_EncodeDicomWebXml2 = 37, /* New in Orthanc 1.7.0 */ | |
445 _OrthancPluginService_CreateMemoryBuffer = 38, /* New in Orthanc 1.7.0 */ | |
446 _OrthancPluginService_GenerateRestApiAuthorizationToken = 39, /* New in Orthanc 1.8.1 */ | |
447 _OrthancPluginService_CreateMemoryBuffer64 = 40, /* New in Orthanc 1.9.0 */ | |
448 _OrthancPluginService_CreateDicom2 = 41, /* New in Orthanc 1.9.0 */ | |
449 _OrthancPluginService_GetDatabaseServerIdentifier = 42, /* New in Orthanc 1.11.1 */ | |
450 _OrthancPluginService_SetMetricsIntegerValue = 43, /* New in Orthanc 1.12.1 */ | |
451 | |
452 /* Registration of callbacks */ | |
453 _OrthancPluginService_RegisterRestCallback = 1000, | |
454 _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001, | |
455 _OrthancPluginService_RegisterStorageArea = 1002, | |
456 _OrthancPluginService_RegisterOnChangeCallback = 1003, | |
457 _OrthancPluginService_RegisterRestCallbackNoLock = 1004, | |
458 _OrthancPluginService_RegisterWorklistCallback = 1005, | |
459 _OrthancPluginService_RegisterDecodeImageCallback = 1006, | |
460 _OrthancPluginService_RegisterIncomingHttpRequestFilter = 1007, | |
461 _OrthancPluginService_RegisterFindCallback = 1008, | |
462 _OrthancPluginService_RegisterMoveCallback = 1009, | |
463 _OrthancPluginService_RegisterIncomingHttpRequestFilter2 = 1010, | |
464 _OrthancPluginService_RegisterRefreshMetricsCallback = 1011, | |
465 _OrthancPluginService_RegisterChunkedRestCallback = 1012, /* New in Orthanc 1.5.7 */ | |
466 _OrthancPluginService_RegisterStorageCommitmentScpCallback = 1013, | |
467 _OrthancPluginService_RegisterIncomingDicomInstanceFilter = 1014, | |
468 _OrthancPluginService_RegisterTranscoderCallback = 1015, /* New in Orthanc 1.7.0 */ | |
469 _OrthancPluginService_RegisterStorageArea2 = 1016, /* New in Orthanc 1.9.0 */ | |
470 _OrthancPluginService_RegisterIncomingCStoreInstanceFilter = 1017, /* New in Orthanc 1.10.0 */ | |
471 _OrthancPluginService_RegisterReceivedInstanceCallback = 1018, /* New in Orthanc 1.10.0 */ | |
472 _OrthancPluginService_RegisterWebDavCollection = 1019, /* New in Orthanc 1.10.1 */ | |
473 | |
474 /* Sending answers to REST calls */ | |
475 _OrthancPluginService_AnswerBuffer = 2000, | |
476 _OrthancPluginService_CompressAndAnswerPngImage = 2001, /* Unused as of Orthanc 0.9.4 */ | |
477 _OrthancPluginService_Redirect = 2002, | |
478 _OrthancPluginService_SendHttpStatusCode = 2003, | |
479 _OrthancPluginService_SendUnauthorized = 2004, | |
480 _OrthancPluginService_SendMethodNotAllowed = 2005, | |
481 _OrthancPluginService_SetCookie = 2006, | |
482 _OrthancPluginService_SetHttpHeader = 2007, | |
483 _OrthancPluginService_StartMultipartAnswer = 2008, | |
484 _OrthancPluginService_SendMultipartItem = 2009, | |
485 _OrthancPluginService_SendHttpStatus = 2010, | |
486 _OrthancPluginService_CompressAndAnswerImage = 2011, | |
487 _OrthancPluginService_SendMultipartItem2 = 2012, | |
488 _OrthancPluginService_SetHttpErrorDetails = 2013, | |
489 | |
490 /* Access to the Orthanc database and API */ | |
491 _OrthancPluginService_GetDicomForInstance = 3000, | |
492 _OrthancPluginService_RestApiGet = 3001, | |
493 _OrthancPluginService_RestApiPost = 3002, | |
494 _OrthancPluginService_RestApiDelete = 3003, | |
495 _OrthancPluginService_RestApiPut = 3004, | |
496 _OrthancPluginService_LookupPatient = 3005, | |
497 _OrthancPluginService_LookupStudy = 3006, | |
498 _OrthancPluginService_LookupSeries = 3007, | |
499 _OrthancPluginService_LookupInstance = 3008, | |
500 _OrthancPluginService_LookupStudyWithAccessionNumber = 3009, | |
501 _OrthancPluginService_RestApiGetAfterPlugins = 3010, | |
502 _OrthancPluginService_RestApiPostAfterPlugins = 3011, | |
503 _OrthancPluginService_RestApiDeleteAfterPlugins = 3012, | |
504 _OrthancPluginService_RestApiPutAfterPlugins = 3013, | |
505 _OrthancPluginService_ReconstructMainDicomTags = 3014, | |
506 _OrthancPluginService_RestApiGet2 = 3015, | |
507 _OrthancPluginService_CallRestApi = 3016, /* New in Orthanc 1.9.2 */ | |
508 | |
509 /* Access to DICOM instances */ | |
510 _OrthancPluginService_GetInstanceRemoteAet = 4000, | |
511 _OrthancPluginService_GetInstanceSize = 4001, | |
512 _OrthancPluginService_GetInstanceData = 4002, | |
513 _OrthancPluginService_GetInstanceJson = 4003, | |
514 _OrthancPluginService_GetInstanceSimplifiedJson = 4004, | |
515 _OrthancPluginService_HasInstanceMetadata = 4005, | |
516 _OrthancPluginService_GetInstanceMetadata = 4006, | |
517 _OrthancPluginService_GetInstanceOrigin = 4007, | |
518 _OrthancPluginService_GetInstanceTransferSyntaxUid = 4008, | |
519 _OrthancPluginService_HasInstancePixelData = 4009, | |
520 _OrthancPluginService_CreateDicomInstance = 4010, /* New in Orthanc 1.7.0 */ | |
521 _OrthancPluginService_FreeDicomInstance = 4011, /* New in Orthanc 1.7.0 */ | |
522 _OrthancPluginService_GetInstanceFramesCount = 4012, /* New in Orthanc 1.7.0 */ | |
523 _OrthancPluginService_GetInstanceRawFrame = 4013, /* New in Orthanc 1.7.0 */ | |
524 _OrthancPluginService_GetInstanceDecodedFrame = 4014, /* New in Orthanc 1.7.0 */ | |
525 _OrthancPluginService_TranscodeDicomInstance = 4015, /* New in Orthanc 1.7.0 */ | |
526 _OrthancPluginService_SerializeDicomInstance = 4016, /* New in Orthanc 1.7.0 */ | |
527 _OrthancPluginService_GetInstanceAdvancedJson = 4017, /* New in Orthanc 1.7.0 */ | |
528 _OrthancPluginService_GetInstanceDicomWebJson = 4018, /* New in Orthanc 1.7.0 */ | |
529 _OrthancPluginService_GetInstanceDicomWebXml = 4019, /* New in Orthanc 1.7.0 */ | |
530 _OrthancPluginService_LoadDicomInstance = 4020, /* New in Orthanc 1.12.1 */ | |
531 | |
532 /* Services for plugins implementing a database back-end */ | |
533 _OrthancPluginService_RegisterDatabaseBackend = 5000, /* New in Orthanc 0.8.6 */ | |
534 _OrthancPluginService_DatabaseAnswer = 5001, | |
535 _OrthancPluginService_RegisterDatabaseBackendV2 = 5002, /* New in Orthanc 0.9.4 */ | |
536 _OrthancPluginService_StorageAreaCreate = 5003, | |
537 _OrthancPluginService_StorageAreaRead = 5004, | |
538 _OrthancPluginService_StorageAreaRemove = 5005, | |
539 _OrthancPluginService_RegisterDatabaseBackendV3 = 5006, /* New in Orthanc 1.9.2 */ | |
540 _OrthancPluginService_RegisterDatabaseBackendV4 = 5007, /* New in Orthanc 1.12.0 */ | |
541 | |
542 /* Primitives for handling images */ | |
543 _OrthancPluginService_GetImagePixelFormat = 6000, | |
544 _OrthancPluginService_GetImageWidth = 6001, | |
545 _OrthancPluginService_GetImageHeight = 6002, | |
546 _OrthancPluginService_GetImagePitch = 6003, | |
547 _OrthancPluginService_GetImageBuffer = 6004, | |
548 _OrthancPluginService_UncompressImage = 6005, | |
549 _OrthancPluginService_FreeImage = 6006, | |
550 _OrthancPluginService_CompressImage = 6007, | |
551 _OrthancPluginService_ConvertPixelFormat = 6008, | |
552 _OrthancPluginService_GetFontsCount = 6009, | |
553 _OrthancPluginService_GetFontInfo = 6010, | |
554 _OrthancPluginService_DrawText = 6011, | |
555 _OrthancPluginService_CreateImage = 6012, | |
556 _OrthancPluginService_CreateImageAccessor = 6013, | |
557 _OrthancPluginService_DecodeDicomImage = 6014, | |
558 | |
559 /* Primitives for handling C-Find, C-Move and worklists */ | |
560 _OrthancPluginService_WorklistAddAnswer = 7000, | |
561 _OrthancPluginService_WorklistMarkIncomplete = 7001, | |
562 _OrthancPluginService_WorklistIsMatch = 7002, | |
563 _OrthancPluginService_WorklistGetDicomQuery = 7003, | |
564 _OrthancPluginService_FindAddAnswer = 7004, | |
565 _OrthancPluginService_FindMarkIncomplete = 7005, | |
566 _OrthancPluginService_GetFindQuerySize = 7006, | |
567 _OrthancPluginService_GetFindQueryTag = 7007, | |
568 _OrthancPluginService_GetFindQueryTagName = 7008, | |
569 _OrthancPluginService_GetFindQueryValue = 7009, | |
570 _OrthancPluginService_CreateFindMatcher = 7010, | |
571 _OrthancPluginService_FreeFindMatcher = 7011, | |
572 _OrthancPluginService_FindMatcherIsMatch = 7012, | |
573 | |
574 /* Primitives for accessing Orthanc Peers (new in 1.4.2) */ | |
575 _OrthancPluginService_GetPeers = 8000, | |
576 _OrthancPluginService_FreePeers = 8001, | |
577 _OrthancPluginService_GetPeersCount = 8003, | |
578 _OrthancPluginService_GetPeerName = 8004, | |
579 _OrthancPluginService_GetPeerUrl = 8005, | |
580 _OrthancPluginService_CallPeerApi = 8006, | |
581 _OrthancPluginService_GetPeerUserProperty = 8007, | |
582 | |
583 /* Primitives for handling jobs (new in 1.4.2) */ | |
584 _OrthancPluginService_CreateJob = 9000, /* Deprecated since SDK 1.11.3 */ | |
585 _OrthancPluginService_FreeJob = 9001, | |
586 _OrthancPluginService_SubmitJob = 9002, | |
587 _OrthancPluginService_RegisterJobsUnserializer = 9003, | |
588 _OrthancPluginService_CreateJob2 = 9004, /* New in SDK 1.11.3 */ | |
589 | |
590 _OrthancPluginService_INTERNAL = 0x7fffffff | |
591 } _OrthancPluginService; | |
592 | |
593 | |
594 typedef enum | |
595 { | |
596 _OrthancPluginProperty_Description = 1, | |
597 _OrthancPluginProperty_RootUri = 2, | |
598 _OrthancPluginProperty_OrthancExplorer = 3, | |
599 | |
600 _OrthancPluginProperty_INTERNAL = 0x7fffffff | |
601 } _OrthancPluginProperty; | |
602 | |
603 | |
604 | |
605 /** | |
606 * The memory layout of the pixels of an image. | |
607 * @ingroup Images | |
608 **/ | |
609 typedef enum | |
610 { | |
611 /** | |
612 * @brief Graylevel 8bpp image. | |
613 * | |
614 * The image is graylevel. Each pixel is unsigned and stored in | |
615 * one byte. | |
616 **/ | |
617 OrthancPluginPixelFormat_Grayscale8 = 1, | |
618 | |
619 /** | |
620 * @brief Graylevel, unsigned 16bpp image. | |
621 * | |
622 * The image is graylevel. Each pixel is unsigned and stored in | |
623 * two bytes. | |
624 **/ | |
625 OrthancPluginPixelFormat_Grayscale16 = 2, | |
626 | |
627 /** | |
628 * @brief Graylevel, signed 16bpp image. | |
629 * | |
630 * The image is graylevel. Each pixel is signed and stored in two | |
631 * bytes. | |
632 **/ | |
633 OrthancPluginPixelFormat_SignedGrayscale16 = 3, | |
634 | |
635 /** | |
636 * @brief Color image in RGB24 format. | |
637 * | |
638 * This format describes a color image. The pixels are stored in 3 | |
639 * consecutive bytes. The memory layout is RGB. | |
640 **/ | |
641 OrthancPluginPixelFormat_RGB24 = 4, | |
642 | |
643 /** | |
644 * @brief Color image in RGBA32 format. | |
645 * | |
646 * This format describes a color image. The pixels are stored in 4 | |
647 * consecutive bytes. The memory layout is RGBA. | |
648 **/ | |
649 OrthancPluginPixelFormat_RGBA32 = 5, | |
650 | |
651 OrthancPluginPixelFormat_Unknown = 6, /*!< Unknown pixel format */ | |
652 | |
653 /** | |
654 * @brief Color image in RGB48 format. | |
655 * | |
656 * This format describes a color image. The pixels are stored in 6 | |
657 * consecutive bytes. The memory layout is RRGGBB. | |
658 **/ | |
659 OrthancPluginPixelFormat_RGB48 = 7, | |
660 | |
661 /** | |
662 * @brief Graylevel, unsigned 32bpp image. | |
663 * | |
664 * The image is graylevel. Each pixel is unsigned and stored in | |
665 * four bytes. | |
666 **/ | |
667 OrthancPluginPixelFormat_Grayscale32 = 8, | |
668 | |
669 /** | |
670 * @brief Graylevel, floating-point 32bpp image. | |
671 * | |
672 * The image is graylevel. Each pixel is floating-point and stored | |
673 * in four bytes. | |
674 **/ | |
675 OrthancPluginPixelFormat_Float32 = 9, | |
676 | |
677 /** | |
678 * @brief Color image in BGRA32 format. | |
679 * | |
680 * This format describes a color image. The pixels are stored in 4 | |
681 * consecutive bytes. The memory layout is BGRA. | |
682 **/ | |
683 OrthancPluginPixelFormat_BGRA32 = 10, | |
684 | |
685 /** | |
686 * @brief Graylevel, unsigned 64bpp image. | |
687 * | |
688 * The image is graylevel. Each pixel is unsigned and stored in | |
689 * eight bytes. | |
690 **/ | |
691 OrthancPluginPixelFormat_Grayscale64 = 11, | |
692 | |
693 _OrthancPluginPixelFormat_INTERNAL = 0x7fffffff | |
694 } OrthancPluginPixelFormat; | |
695 | |
696 | |
697 | |
698 /** | |
699 * The content types that are supported by Orthanc plugins. | |
700 **/ | |
701 typedef enum | |
702 { | |
703 OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */ | |
704 OrthancPluginContentType_Dicom = 1, /*!< DICOM */ | |
705 OrthancPluginContentType_DicomAsJson = 2, /*!< JSON summary of a DICOM file */ | |
706 OrthancPluginContentType_DicomUntilPixelData = 3, /*!< DICOM Header till pixel data */ | |
707 | |
708 _OrthancPluginContentType_INTERNAL = 0x7fffffff | |
709 } OrthancPluginContentType; | |
710 | |
711 | |
712 | |
713 /** | |
714 * The supported types of DICOM resources. | |
715 **/ | |
716 typedef enum | |
717 { | |
718 OrthancPluginResourceType_Patient = 0, /*!< Patient */ | |
719 OrthancPluginResourceType_Study = 1, /*!< Study */ | |
720 OrthancPluginResourceType_Series = 2, /*!< Series */ | |
721 OrthancPluginResourceType_Instance = 3, /*!< Instance */ | |
722 OrthancPluginResourceType_None = 4, /*!< Unavailable resource type */ | |
723 | |
724 _OrthancPluginResourceType_INTERNAL = 0x7fffffff | |
725 } OrthancPluginResourceType; | |
726 | |
727 | |
728 | |
729 /** | |
730 * The supported types of changes that can be signaled to the change callback. | |
731 * @ingroup Callbacks | |
732 **/ | |
733 typedef enum | |
734 { | |
735 OrthancPluginChangeType_CompletedSeries = 0, /*!< Series is now complete */ | |
736 OrthancPluginChangeType_Deleted = 1, /*!< Deleted resource */ | |
737 OrthancPluginChangeType_NewChildInstance = 2, /*!< A new instance was added to this resource */ | |
738 OrthancPluginChangeType_NewInstance = 3, /*!< New instance received */ | |
739 OrthancPluginChangeType_NewPatient = 4, /*!< New patient created */ | |
740 OrthancPluginChangeType_NewSeries = 5, /*!< New series created */ | |
741 OrthancPluginChangeType_NewStudy = 6, /*!< New study created */ | |
742 OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */ | |
743 OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */ | |
744 OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */ | |
745 OrthancPluginChangeType_OrthancStarted = 10, /*!< Orthanc has started */ | |
746 OrthancPluginChangeType_OrthancStopped = 11, /*!< Orthanc is stopping */ | |
747 OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */ | |
748 OrthancPluginChangeType_UpdatedMetadata = 13, /*!< Some user-defined metadata has changed for this resource */ | |
749 OrthancPluginChangeType_UpdatedPeers = 14, /*!< The list of Orthanc peers has changed */ | |
750 OrthancPluginChangeType_UpdatedModalities = 15, /*!< The list of DICOM modalities has changed */ | |
751 OrthancPluginChangeType_JobSubmitted = 16, /*!< New Job submitted */ | |
752 OrthancPluginChangeType_JobSuccess = 17, /*!< A Job has completed successfully */ | |
753 OrthancPluginChangeType_JobFailure = 18, /*!< A Job has failed */ | |
754 | |
755 _OrthancPluginChangeType_INTERNAL = 0x7fffffff | |
756 } OrthancPluginChangeType; | |
757 | |
758 | |
759 /** | |
760 * The compression algorithms that are supported by the Orthanc core. | |
761 * @ingroup Images | |
762 **/ | |
763 typedef enum | |
764 { | |
765 OrthancPluginCompressionType_Zlib = 0, /*!< Standard zlib compression */ | |
766 OrthancPluginCompressionType_ZlibWithSize = 1, /*!< zlib, prefixed with uncompressed size (uint64_t) */ | |
767 OrthancPluginCompressionType_Gzip = 2, /*!< Standard gzip compression */ | |
768 OrthancPluginCompressionType_GzipWithSize = 3, /*!< gzip, prefixed with uncompressed size (uint64_t) */ | |
769 | |
770 _OrthancPluginCompressionType_INTERNAL = 0x7fffffff | |
771 } OrthancPluginCompressionType; | |
772 | |
773 | |
774 /** | |
775 * The image formats that are supported by the Orthanc core. | |
776 * @ingroup Images | |
777 **/ | |
778 typedef enum | |
779 { | |
780 OrthancPluginImageFormat_Png = 0, /*!< Image compressed using PNG */ | |
781 OrthancPluginImageFormat_Jpeg = 1, /*!< Image compressed using JPEG */ | |
782 OrthancPluginImageFormat_Dicom = 2, /*!< Image compressed using DICOM */ | |
783 | |
784 _OrthancPluginImageFormat_INTERNAL = 0x7fffffff | |
785 } OrthancPluginImageFormat; | |
786 | |
787 | |
788 /** | |
789 * The value representations present in the DICOM standard (version 2013). | |
790 * @ingroup Toolbox | |
791 **/ | |
792 typedef enum | |
793 { | |
794 OrthancPluginValueRepresentation_AE = 1, /*!< Application Entity */ | |
795 OrthancPluginValueRepresentation_AS = 2, /*!< Age String */ | |
796 OrthancPluginValueRepresentation_AT = 3, /*!< Attribute Tag */ | |
797 OrthancPluginValueRepresentation_CS = 4, /*!< Code String */ | |
798 OrthancPluginValueRepresentation_DA = 5, /*!< Date */ | |
799 OrthancPluginValueRepresentation_DS = 6, /*!< Decimal String */ | |
800 OrthancPluginValueRepresentation_DT = 7, /*!< Date Time */ | |
801 OrthancPluginValueRepresentation_FD = 8, /*!< Floating Point Double */ | |
802 OrthancPluginValueRepresentation_FL = 9, /*!< Floating Point Single */ | |
803 OrthancPluginValueRepresentation_IS = 10, /*!< Integer String */ | |
804 OrthancPluginValueRepresentation_LO = 11, /*!< Long String */ | |
805 OrthancPluginValueRepresentation_LT = 12, /*!< Long Text */ | |
806 OrthancPluginValueRepresentation_OB = 13, /*!< Other Byte String */ | |
807 OrthancPluginValueRepresentation_OF = 14, /*!< Other Float String */ | |
808 OrthancPluginValueRepresentation_OW = 15, /*!< Other Word String */ | |
809 OrthancPluginValueRepresentation_PN = 16, /*!< Person Name */ | |
810 OrthancPluginValueRepresentation_SH = 17, /*!< Short String */ | |
811 OrthancPluginValueRepresentation_SL = 18, /*!< Signed Long */ | |
812 OrthancPluginValueRepresentation_SQ = 19, /*!< Sequence of Items */ | |
813 OrthancPluginValueRepresentation_SS = 20, /*!< Signed Short */ | |
814 OrthancPluginValueRepresentation_ST = 21, /*!< Short Text */ | |
815 OrthancPluginValueRepresentation_TM = 22, /*!< Time */ | |
816 OrthancPluginValueRepresentation_UI = 23, /*!< Unique Identifier (UID) */ | |
817 OrthancPluginValueRepresentation_UL = 24, /*!< Unsigned Long */ | |
818 OrthancPluginValueRepresentation_UN = 25, /*!< Unknown */ | |
819 OrthancPluginValueRepresentation_US = 26, /*!< Unsigned Short */ | |
820 OrthancPluginValueRepresentation_UT = 27, /*!< Unlimited Text */ | |
821 | |
822 _OrthancPluginValueRepresentation_INTERNAL = 0x7fffffff | |
823 } OrthancPluginValueRepresentation; | |
824 | |
825 | |
826 /** | |
827 * The possible output formats for a DICOM-to-JSON conversion. | |
828 * @ingroup Toolbox | |
829 * @see OrthancPluginDicomToJson() | |
830 **/ | |
831 typedef enum | |
832 { | |
833 OrthancPluginDicomToJsonFormat_Full = 1, /*!< Full output, with most details */ | |
834 OrthancPluginDicomToJsonFormat_Short = 2, /*!< Tags output as hexadecimal numbers */ | |
835 OrthancPluginDicomToJsonFormat_Human = 3, /*!< Human-readable JSON */ | |
836 | |
837 _OrthancPluginDicomToJsonFormat_INTERNAL = 0x7fffffff | |
838 } OrthancPluginDicomToJsonFormat; | |
839 | |
840 | |
841 /** | |
842 * Flags to customize a DICOM-to-JSON conversion. By default, binary | |
843 * tags are formatted using Data URI scheme. | |
844 * @ingroup Toolbox | |
845 **/ | |
846 typedef enum | |
847 { | |
848 OrthancPluginDicomToJsonFlags_None = 0, | |
849 OrthancPluginDicomToJsonFlags_IncludeBinary = (1 << 0), /*!< Include the binary tags */ | |
850 OrthancPluginDicomToJsonFlags_IncludePrivateTags = (1 << 1), /*!< Include the private tags */ | |
851 OrthancPluginDicomToJsonFlags_IncludeUnknownTags = (1 << 2), /*!< Include the tags unknown by the dictionary */ | |
852 OrthancPluginDicomToJsonFlags_IncludePixelData = (1 << 3), /*!< Include the pixel data */ | |
853 OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii = (1 << 4), /*!< Output binary tags as-is, dropping non-ASCII */ | |
854 OrthancPluginDicomToJsonFlags_ConvertBinaryToNull = (1 << 5), /*!< Signal binary tags as null values */ | |
855 OrthancPluginDicomToJsonFlags_StopAfterPixelData = (1 << 6), /*!< Stop processing after pixel data (new in 1.9.1) */ | |
856 OrthancPluginDicomToJsonFlags_SkipGroupLengths = (1 << 7), /*!< Skip tags whose element is zero (new in 1.9.1) */ | |
857 | |
858 _OrthancPluginDicomToJsonFlags_INTERNAL = 0x7fffffff | |
859 } OrthancPluginDicomToJsonFlags; | |
860 | |
861 | |
862 /** | |
863 * Flags to the creation of a DICOM file. | |
864 * @ingroup Toolbox | |
865 * @see OrthancPluginCreateDicom() | |
866 **/ | |
867 typedef enum | |
868 { | |
869 OrthancPluginCreateDicomFlags_None = 0, | |
870 OrthancPluginCreateDicomFlags_DecodeDataUriScheme = (1 << 0), /*!< Decode fields encoded using data URI scheme */ | |
871 OrthancPluginCreateDicomFlags_GenerateIdentifiers = (1 << 1), /*!< Automatically generate DICOM identifiers */ | |
872 | |
873 _OrthancPluginCreateDicomFlags_INTERNAL = 0x7fffffff | |
874 } OrthancPluginCreateDicomFlags; | |
875 | |
876 | |
877 /** | |
878 * The constraints on the DICOM identifiers that must be supported | |
879 * by the database plugins. | |
880 * @deprecated Plugins using OrthancPluginConstraintType will be faster | |
881 **/ | |
882 typedef enum | |
883 { | |
884 OrthancPluginIdentifierConstraint_Equal = 1, /*!< Equal */ | |
885 OrthancPluginIdentifierConstraint_SmallerOrEqual = 2, /*!< Less or equal */ | |
886 OrthancPluginIdentifierConstraint_GreaterOrEqual = 3, /*!< More or equal */ | |
887 OrthancPluginIdentifierConstraint_Wildcard = 4, /*!< Case-sensitive wildcard matching (with * and ?) */ | |
888 | |
889 _OrthancPluginIdentifierConstraint_INTERNAL = 0x7fffffff | |
890 } OrthancPluginIdentifierConstraint; | |
891 | |
892 | |
893 /** | |
894 * The constraints on the tags (main DICOM tags and identifier tags) | |
895 * that must be supported by the database plugins. | |
896 **/ | |
897 typedef enum | |
898 { | |
899 OrthancPluginConstraintType_Equal = 1, /*!< Equal */ | |
900 OrthancPluginConstraintType_SmallerOrEqual = 2, /*!< Less or equal */ | |
901 OrthancPluginConstraintType_GreaterOrEqual = 3, /*!< More or equal */ | |
902 OrthancPluginConstraintType_Wildcard = 4, /*!< Wildcard matching */ | |
903 OrthancPluginConstraintType_List = 5, /*!< List of values */ | |
904 | |
905 _OrthancPluginConstraintType_INTERNAL = 0x7fffffff | |
906 } OrthancPluginConstraintType; | |
907 | |
908 | |
909 /** | |
910 * The origin of a DICOM instance that has been received by Orthanc. | |
911 **/ | |
912 typedef enum | |
913 { | |
914 OrthancPluginInstanceOrigin_Unknown = 1, /*!< Unknown origin */ | |
915 OrthancPluginInstanceOrigin_DicomProtocol = 2, /*!< Instance received through DICOM protocol */ | |
916 OrthancPluginInstanceOrigin_RestApi = 3, /*!< Instance received through REST API of Orthanc */ | |
917 OrthancPluginInstanceOrigin_Plugin = 4, /*!< Instance added to Orthanc by a plugin */ | |
918 OrthancPluginInstanceOrigin_Lua = 5, /*!< Instance added to Orthanc by a Lua script */ | |
919 OrthancPluginInstanceOrigin_WebDav = 6, /*!< Instance received through WebDAV (new in 1.8.0) */ | |
920 | |
921 _OrthancPluginInstanceOrigin_INTERNAL = 0x7fffffff | |
922 } OrthancPluginInstanceOrigin; | |
923 | |
924 | |
925 /** | |
926 * The possible status for one single step of a job. | |
927 **/ | |
928 typedef enum | |
929 { | |
930 OrthancPluginJobStepStatus_Success = 1, /*!< The job has successfully executed all its steps */ | |
931 OrthancPluginJobStepStatus_Failure = 2, /*!< The job has failed while executing this step */ | |
932 OrthancPluginJobStepStatus_Continue = 3 /*!< The job has still data to process after this step */ | |
933 } OrthancPluginJobStepStatus; | |
934 | |
935 | |
936 /** | |
937 * Explains why the job should stop and release the resources it has | |
938 * allocated. This is especially important to disambiguate between | |
939 * the "paused" condition and the "final" conditions (success, | |
940 * failure, or canceled). | |
941 **/ | |
942 typedef enum | |
943 { | |
944 OrthancPluginJobStopReason_Success = 1, /*!< The job has succeeded */ | |
945 OrthancPluginJobStopReason_Paused = 2, /*!< The job was paused, and will be resumed later */ | |
946 OrthancPluginJobStopReason_Failure = 3, /*!< The job has failed, and might be resubmitted later */ | |
947 OrthancPluginJobStopReason_Canceled = 4 /*!< The job was canceled, and might be resubmitted later */ | |
948 } OrthancPluginJobStopReason; | |
949 | |
950 | |
951 /** | |
952 * The available types of metrics. | |
953 **/ | |
954 typedef enum | |
955 { | |
956 OrthancPluginMetricsType_Default = 0, /*!< Default metrics */ | |
957 | |
958 /** | |
959 * This metrics represents a time duration. Orthanc will keep the | |
960 * maximum value of the metrics over a sliding window of ten | |
961 * seconds, which is useful if the metrics is sampled frequently. | |
962 **/ | |
963 OrthancPluginMetricsType_Timer = 1 | |
964 } OrthancPluginMetricsType; | |
965 | |
966 | |
967 /** | |
968 * The available modes to export a binary DICOM tag into a DICOMweb | |
969 * JSON or XML document. | |
970 **/ | |
971 typedef enum | |
972 { | |
973 OrthancPluginDicomWebBinaryMode_Ignore = 0, /*!< Don't include binary tags */ | |
974 OrthancPluginDicomWebBinaryMode_InlineBinary = 1, /*!< Inline encoding using Base64 */ | |
975 OrthancPluginDicomWebBinaryMode_BulkDataUri = 2 /*!< Use a bulk data URI field */ | |
976 } OrthancPluginDicomWebBinaryMode; | |
977 | |
978 | |
979 /** | |
980 * The available values for the Failure Reason (0008,1197) during | |
981 * storage commitment. | |
982 * http://dicom.nema.org/medical/dicom/2019e/output/chtml/part03/sect_C.14.html#sect_C.14.1.1 | |
983 **/ | |
984 typedef enum | |
985 { | |
986 OrthancPluginStorageCommitmentFailureReason_Success = 0, | |
987 /*!< Success: The DICOM instance is properly stored in the SCP */ | |
988 | |
989 OrthancPluginStorageCommitmentFailureReason_ProcessingFailure = 1, | |
990 /*!< 0110H: A general failure in processing the operation was encountered */ | |
991 | |
992 OrthancPluginStorageCommitmentFailureReason_NoSuchObjectInstance = 2, | |
993 /*!< 0112H: One or more of the elements in the Referenced SOP | |
994 Instance Sequence was not available */ | |
995 | |
996 OrthancPluginStorageCommitmentFailureReason_ResourceLimitation = 3, | |
997 /*!< 0213H: The SCP does not currently have enough resources to | |
998 store the requested SOP Instance(s) */ | |
999 | |
1000 OrthancPluginStorageCommitmentFailureReason_ReferencedSOPClassNotSupported = 4, | |
1001 /*!< 0122H: Storage Commitment has been requested for a SOP | |
1002 Instance with a SOP Class that is not supported by the SCP */ | |
1003 | |
1004 OrthancPluginStorageCommitmentFailureReason_ClassInstanceConflict = 5, | |
1005 /*!< 0119H: The SOP Class of an element in the Referenced SOP | |
1006 Instance Sequence did not correspond to the SOP class registered | |
1007 for this SOP Instance at the SCP */ | |
1008 | |
1009 OrthancPluginStorageCommitmentFailureReason_DuplicateTransactionUID = 6 | |
1010 /*!< 0131H: The Transaction UID of the Storage Commitment Request | |
1011 is already in use */ | |
1012 } OrthancPluginStorageCommitmentFailureReason; | |
1013 | |
1014 | |
1015 /** | |
1016 * The action to be taken after ReceivedInstanceCallback is triggered | |
1017 **/ | |
1018 typedef enum | |
1019 { | |
1020 OrthancPluginReceivedInstanceAction_KeepAsIs = 1, /*!< Keep the instance as is */ | |
1021 OrthancPluginReceivedInstanceAction_Modify = 2, /*!< Modify the instance */ | |
1022 OrthancPluginReceivedInstanceAction_Discard = 3, /*!< Discard the instance */ | |
1023 | |
1024 _OrthancPluginReceivedInstanceAction_INTERNAL = 0x7fffffff | |
1025 } OrthancPluginReceivedInstanceAction; | |
1026 | |
1027 | |
1028 /** | |
1029 * Mode specifying how to load a DICOM instance. | |
1030 * @see OrthancPluginLoadDicomInstance() | |
1031 **/ | |
1032 typedef enum | |
1033 { | |
1034 OrthancPluginLoadDicomInstanceMode_WholeDicom = 1, | |
1035 /*!< Load the whole DICOM file, including pixel data */ | |
1036 | |
1037 OrthancPluginLoadDicomInstanceMode_UntilPixelData = 2, | |
1038 /*!< Load the whole DICOM file until pixel data, which will speed | |
1039 up the loading */ | |
1040 | |
1041 OrthancPluginLoadDicomInstanceMode_EmptyPixelData = 3, | |
1042 /*!< Load the whole DICOM file until pixel data, and replace pixel | |
1043 data by an empty tag whose VR (value representation) is the same | |
1044 as those of the original DICOM file */ | |
1045 | |
1046 _OrthancPluginLoadDicomInstanceMode_INTERNAL = 0x7fffffff | |
1047 } OrthancPluginLoadDicomInstanceMode; | |
1048 | |
1049 | |
1050 /** | |
1051 * @brief A 32-bit memory buffer allocated by the core system of Orthanc. | |
1052 * | |
1053 * A memory buffer allocated by the core system of Orthanc. When the | |
1054 * content of the buffer is not useful anymore, it must be free by a | |
1055 * call to ::OrthancPluginFreeMemoryBuffer(). | |
1056 **/ | |
1057 typedef struct | |
1058 { | |
1059 /** | |
1060 * @brief The content of the buffer. | |
1061 **/ | |
1062 void* data; | |
1063 | |
1064 /** | |
1065 * @brief The number of bytes in the buffer. | |
1066 **/ | |
1067 uint32_t size; | |
1068 } OrthancPluginMemoryBuffer; | |
1069 | |
1070 | |
1071 | |
1072 /** | |
1073 * @brief A 64-bit memory buffer allocated by the core system of Orthanc. | |
1074 * | |
1075 * A memory buffer allocated by the core system of Orthanc. When the | |
1076 * content of the buffer is not useful anymore, it must be free by a | |
1077 * call to ::OrthancPluginFreeMemoryBuffer64(). | |
1078 **/ | |
1079 typedef struct | |
1080 { | |
1081 /** | |
1082 * @brief The content of the buffer. | |
1083 **/ | |
1084 void* data; | |
1085 | |
1086 /** | |
1087 * @brief The number of bytes in the buffer. | |
1088 **/ | |
1089 uint64_t size; | |
1090 } OrthancPluginMemoryBuffer64; | |
1091 | |
1092 | |
1093 | |
1094 | |
1095 /** | |
1096 * @brief Opaque structure that represents the HTTP connection to the client application. | |
1097 * @ingroup Callbacks | |
1098 **/ | |
1099 typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput; | |
1100 | |
1101 | |
1102 | |
1103 /** | |
1104 * @brief Opaque structure that represents a DICOM instance that is managed by the Orthanc core. | |
1105 * @ingroup DicomInstance | |
1106 **/ | |
1107 typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance; | |
1108 | |
1109 | |
1110 | |
1111 /** | |
1112 * @brief Opaque structure that represents an image that is uncompressed in memory. | |
1113 * @ingroup Images | |
1114 **/ | |
1115 typedef struct _OrthancPluginImage_t OrthancPluginImage; | |
1116 | |
1117 | |
1118 | |
1119 /** | |
1120 * @brief Opaque structure that represents the storage area that is actually used by Orthanc. | |
1121 * @ingroup Images | |
1122 **/ | |
1123 typedef struct _OrthancPluginStorageArea_t OrthancPluginStorageArea; | |
1124 | |
1125 | |
1126 | |
1127 /** | |
1128 * @brief Opaque structure to an object that represents a C-Find query for worklists. | |
1129 * @ingroup DicomCallbacks | |
1130 **/ | |
1131 typedef struct _OrthancPluginWorklistQuery_t OrthancPluginWorklistQuery; | |
1132 | |
1133 | |
1134 | |
1135 /** | |
1136 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists. | |
1137 * @ingroup DicomCallbacks | |
1138 **/ | |
1139 typedef struct _OrthancPluginWorklistAnswers_t OrthancPluginWorklistAnswers; | |
1140 | |
1141 | |
1142 | |
1143 /** | |
1144 * @brief Opaque structure to an object that represents a C-Find query. | |
1145 * @ingroup DicomCallbacks | |
1146 **/ | |
1147 typedef struct _OrthancPluginFindQuery_t OrthancPluginFindQuery; | |
1148 | |
1149 | |
1150 | |
1151 /** | |
1152 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists. | |
1153 * @ingroup DicomCallbacks | |
1154 **/ | |
1155 typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindAnswers; | |
1156 | |
1157 | |
1158 | |
1159 /** | |
1160 * @brief Opaque structure to an object that can be used to check whether a DICOM instance matches a C-Find query. | |
1161 * @ingroup Toolbox | |
1162 **/ | |
1163 typedef struct _OrthancPluginFindMatcher_t OrthancPluginFindMatcher; | |
1164 | |
1165 | |
1166 | |
1167 /** | |
1168 * @brief Opaque structure to the set of remote Orthanc Peers that are known to the local Orthanc server. | |
1169 * @ingroup Toolbox | |
1170 **/ | |
1171 typedef struct _OrthancPluginPeers_t OrthancPluginPeers; | |
1172 | |
1173 | |
1174 | |
1175 /** | |
1176 * @brief Opaque structure to a job to be executed by Orthanc. | |
1177 * @ingroup Toolbox | |
1178 **/ | |
1179 typedef struct _OrthancPluginJob_t OrthancPluginJob; | |
1180 | |
1181 | |
1182 | |
1183 /** | |
1184 * @brief Opaque structure that represents a node in a JSON or XML | |
1185 * document used in DICOMweb. | |
1186 * @ingroup Toolbox | |
1187 **/ | |
1188 typedef struct _OrthancPluginDicomWebNode_t OrthancPluginDicomWebNode; | |
1189 | |
1190 | |
1191 | |
1192 /** | |
1193 * @brief Signature of a callback function that answers to a REST request. | |
1194 * @ingroup Callbacks | |
1195 **/ | |
1196 typedef OrthancPluginErrorCode (*OrthancPluginRestCallback) ( | |
1197 OrthancPluginRestOutput* output, | |
1198 const char* url, | |
1199 const OrthancPluginHttpRequest* request); | |
1200 | |
1201 | |
1202 | |
1203 /** | |
1204 * @brief Signature of a callback function that is triggered when Orthanc stores a new DICOM instance. | |
1205 * @ingroup Callbacks | |
1206 **/ | |
1207 typedef OrthancPluginErrorCode (*OrthancPluginOnStoredInstanceCallback) ( | |
1208 const OrthancPluginDicomInstance* instance, | |
1209 const char* instanceId); | |
1210 | |
1211 | |
1212 | |
1213 /** | |
1214 * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource. | |
1215 * @ingroup Callbacks | |
1216 **/ | |
1217 typedef OrthancPluginErrorCode (*OrthancPluginOnChangeCallback) ( | |
1218 OrthancPluginChangeType changeType, | |
1219 OrthancPluginResourceType resourceType, | |
1220 const char* resourceId); | |
1221 | |
1222 | |
1223 | |
1224 /** | |
1225 * @brief Signature of a callback function to decode a DICOM instance as an image. | |
1226 * @ingroup Callbacks | |
1227 **/ | |
1228 typedef OrthancPluginErrorCode (*OrthancPluginDecodeImageCallback) ( | |
1229 OrthancPluginImage** target, | |
1230 const void* dicom, | |
1231 const uint32_t size, | |
1232 uint32_t frameIndex); | |
1233 | |
1234 | |
1235 | |
1236 /** | |
1237 * @brief Signature of a function to free dynamic memory. | |
1238 * @ingroup Callbacks | |
1239 **/ | |
1240 typedef void (*OrthancPluginFree) (void* buffer); | |
1241 | |
1242 | |
1243 | |
1244 /** | |
1245 * @brief Signature of a function to set the content of a node | |
1246 * encoding a binary DICOM tag, into a JSON or XML document | |
1247 * generated for DICOMweb. | |
1248 * @ingroup Callbacks | |
1249 **/ | |
1250 typedef void (*OrthancPluginDicomWebSetBinaryNode) ( | |
1251 OrthancPluginDicomWebNode* node, | |
1252 OrthancPluginDicomWebBinaryMode mode, | |
1253 const char* bulkDataUri); | |
1254 | |
1255 | |
1256 | |
1257 /** | |
1258 * @brief Callback for writing to the storage area. | |
1259 * | |
1260 * Signature of a callback function that is triggered when Orthanc writes a file to the storage area. | |
1261 * | |
1262 * @param uuid The UUID of the file. | |
1263 * @param content The content of the file. | |
1264 * @param size The size of the file. | |
1265 * @param type The content type corresponding to this file. | |
1266 * @return 0 if success, other value if error. | |
1267 * @ingroup Callbacks | |
1268 **/ | |
1269 typedef OrthancPluginErrorCode (*OrthancPluginStorageCreate) ( | |
1270 const char* uuid, | |
1271 const void* content, | |
1272 int64_t size, | |
1273 OrthancPluginContentType type); | |
1274 | |
1275 | |
1276 | |
1277 /** | |
1278 * @brief Callback for reading from the storage area. | |
1279 * | |
1280 * Signature of a callback function that is triggered when Orthanc reads a file from the storage area. | |
1281 * | |
1282 * @param content The content of the file (output). | |
1283 * @param size The size of the file (output). | |
1284 * @param uuid The UUID of the file of interest. | |
1285 * @param type The content type corresponding to this file. | |
1286 * @return 0 if success, other value if error. | |
1287 * @ingroup Callbacks | |
1288 * @deprecated New plugins should use OrthancPluginStorageRead2 | |
1289 * | |
1290 * @warning The "content" buffer *must* have been allocated using | |
1291 * the "malloc()" function of your C standard library (i.e. nor | |
1292 * "new[]", neither a pointer to a buffer). The "free()" function of | |
1293 * your C standard library will automatically be invoked on the | |
1294 * "content" pointer. | |
1295 **/ | |
1296 typedef OrthancPluginErrorCode (*OrthancPluginStorageRead) ( | |
1297 void** content, | |
1298 int64_t* size, | |
1299 const char* uuid, | |
1300 OrthancPluginContentType type); | |
1301 | |
1302 | |
1303 | |
1304 /** | |
1305 * @brief Callback for reading a whole file from the storage area. | |
1306 * | |
1307 * Signature of a callback function that is triggered when Orthanc | |
1308 * reads a whole file from the storage area. | |
1309 * | |
1310 * @param target Memory buffer where to store the content of the file. It must be allocated by the | |
1311 * plugin using OrthancPluginCreateMemoryBuffer64(). The core of Orthanc will free it. | |
1312 * @param uuid The UUID of the file of interest. | |
1313 * @param type The content type corresponding to this file. | |
1314 * @ingroup Callbacks | |
1315 **/ | |
1316 typedef OrthancPluginErrorCode (*OrthancPluginStorageReadWhole) ( | |
1317 OrthancPluginMemoryBuffer64* target, | |
1318 const char* uuid, | |
1319 OrthancPluginContentType type); | |
1320 | |
1321 | |
1322 | |
1323 /** | |
1324 * @brief Callback for reading a range of a file from the storage area. | |
1325 * | |
1326 * Signature of a callback function that is triggered when Orthanc | |
1327 * reads a portion of a file from the storage area. Orthanc | |
1328 * indicates the start position and the length of the range. | |
1329 * | |
1330 * @param target Memory buffer where to store the content of the range. | |
1331 * The memory buffer is allocated and freed by Orthanc. The length of the range | |
1332 * of interest corresponds to the size of this buffer. | |
1333 * @param uuid The UUID of the file of interest. | |
1334 * @param type The content type corresponding to this file. | |
1335 * @param rangeStart Start position of the requested range in the file. | |
1336 * @return 0 if success, other value if error. | |
1337 * @ingroup Callbacks | |
1338 **/ | |
1339 typedef OrthancPluginErrorCode (*OrthancPluginStorageReadRange) ( | |
1340 OrthancPluginMemoryBuffer64* target, | |
1341 const char* uuid, | |
1342 OrthancPluginContentType type, | |
1343 uint64_t rangeStart); | |
1344 | |
1345 | |
1346 | |
1347 /** | |
1348 * @brief Callback for removing a file from the storage area. | |
1349 * | |
1350 * Signature of a callback function that is triggered when Orthanc deletes a file from the storage area. | |
1351 * | |
1352 * @param uuid The UUID of the file to be removed. | |
1353 * @param type The content type corresponding to this file. | |
1354 * @return 0 if success, other value if error. | |
1355 * @ingroup Callbacks | |
1356 **/ | |
1357 typedef OrthancPluginErrorCode (*OrthancPluginStorageRemove) ( | |
1358 const char* uuid, | |
1359 OrthancPluginContentType type); | |
1360 | |
1361 | |
1362 | |
1363 /** | |
1364 * @brief Callback to handle the C-Find SCP requests for worklists. | |
1365 * | |
1366 * Signature of a callback function that is triggered when Orthanc | |
1367 * receives a C-Find SCP request against modality worklists. | |
1368 * | |
1369 * @param answers The target structure where answers must be stored. | |
1370 * @param query The worklist query. | |
1371 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates. | |
1372 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request. | |
1373 * @return 0 if success, other value if error. | |
1374 * @ingroup DicomCallbacks | |
1375 **/ | |
1376 typedef OrthancPluginErrorCode (*OrthancPluginWorklistCallback) ( | |
1377 OrthancPluginWorklistAnswers* answers, | |
1378 const OrthancPluginWorklistQuery* query, | |
1379 const char* issuerAet, | |
1380 const char* calledAet); | |
1381 | |
1382 | |
1383 | |
1384 /** | |
1385 * @brief Callback to filter incoming HTTP requests received by Orthanc. | |
1386 * | |
1387 * Signature of a callback function that is triggered whenever | |
1388 * Orthanc receives an HTTP/REST request, and that answers whether | |
1389 * this request should be allowed. If the callback returns "0" | |
1390 * ("false"), the server answers with HTTP status code 403 | |
1391 * (Forbidden). | |
1392 * | |
1393 * Pay attention to the fact that this function may be invoked | |
1394 * concurrently by different threads of the Web server of | |
1395 * Orthanc. You must implement proper locking if applicable. | |
1396 * | |
1397 * @param method The HTTP method used by the request. | |
1398 * @param uri The URI of interest. | |
1399 * @param ip The IP address of the HTTP client. | |
1400 * @param headersCount The number of HTTP headers. | |
1401 * @param headersKeys The keys of the HTTP headers (always converted to low-case). | |
1402 * @param headersValues The values of the HTTP headers. | |
1403 * @return 0 if forbidden access, 1 if allowed access, -1 if error. | |
1404 * @ingroup Callbacks | |
1405 * @deprecated Please instead use OrthancPluginIncomingHttpRequestFilter2() | |
1406 **/ | |
1407 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter) ( | |
1408 OrthancPluginHttpMethod method, | |
1409 const char* uri, | |
1410 const char* ip, | |
1411 uint32_t headersCount, | |
1412 const char* const* headersKeys, | |
1413 const char* const* headersValues); | |
1414 | |
1415 | |
1416 | |
1417 /** | |
1418 * @brief Callback to filter incoming HTTP requests received by Orthanc. | |
1419 * | |
1420 * Signature of a callback function that is triggered whenever | |
1421 * Orthanc receives an HTTP/REST request, and that answers whether | |
1422 * this request should be allowed. If the callback returns "0" | |
1423 * ("false"), the server answers with HTTP status code 403 | |
1424 * (Forbidden). | |
1425 * | |
1426 * Pay attention to the fact that this function may be invoked | |
1427 * concurrently by different threads of the Web server of | |
1428 * Orthanc. You must implement proper locking if applicable. | |
1429 * | |
1430 * @param method The HTTP method used by the request. | |
1431 * @param uri The URI of interest. | |
1432 * @param ip The IP address of the HTTP client. | |
1433 * @param headersCount The number of HTTP headers. | |
1434 * @param headersKeys The keys of the HTTP headers (always converted to low-case). | |
1435 * @param headersValues The values of the HTTP headers. | |
1436 * @param getArgumentsCount The number of GET arguments (only for the GET HTTP method). | |
1437 * @param getArgumentsKeys The keys of the GET arguments (only for the GET HTTP method). | |
1438 * @param getArgumentsValues The values of the GET arguments (only for the GET HTTP method). | |
1439 * @return 0 if forbidden access, 1 if allowed access, -1 if error. | |
1440 * @ingroup Callbacks | |
1441 **/ | |
1442 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter2) ( | |
1443 OrthancPluginHttpMethod method, | |
1444 const char* uri, | |
1445 const char* ip, | |
1446 uint32_t headersCount, | |
1447 const char* const* headersKeys, | |
1448 const char* const* headersValues, | |
1449 uint32_t getArgumentsCount, | |
1450 const char* const* getArgumentsKeys, | |
1451 const char* const* getArgumentsValues); | |
1452 | |
1453 | |
1454 | |
1455 /** | |
1456 * @brief Callback to handle incoming C-Find SCP requests. | |
1457 * | |
1458 * Signature of a callback function that is triggered whenever | |
1459 * Orthanc receives a C-Find SCP request not concerning modality | |
1460 * worklists. | |
1461 * | |
1462 * @param answers The target structure where answers must be stored. | |
1463 * @param query The worklist query. | |
1464 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates. | |
1465 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request. | |
1466 * @return 0 if success, other value if error. | |
1467 * @ingroup DicomCallbacks | |
1468 **/ | |
1469 typedef OrthancPluginErrorCode (*OrthancPluginFindCallback) ( | |
1470 OrthancPluginFindAnswers* answers, | |
1471 const OrthancPluginFindQuery* query, | |
1472 const char* issuerAet, | |
1473 const char* calledAet); | |
1474 | |
1475 | |
1476 | |
1477 /** | |
1478 * @brief Callback to handle incoming C-Move SCP requests. | |
1479 * | |
1480 * Signature of a callback function that is triggered whenever | |
1481 * Orthanc receives a C-Move SCP request. The callback receives the | |
1482 * type of the resource of interest (study, series, instance...) | |
1483 * together with the DICOM tags containing its identifiers. In turn, | |
1484 * the plugin must create a driver object that will be responsible | |
1485 * for driving the successive move suboperations. | |
1486 * | |
1487 * @param resourceType The type of the resource of interest. Note | |
1488 * that this might be set to ResourceType_None if the | |
1489 * QueryRetrieveLevel (0008,0052) tag was not provided by the | |
1490 * issuer (i.e. the originator modality). | |
1491 * @param patientId Content of the PatientID (0x0010, 0x0020) tag of the resource of interest. Might be NULL. | |
1492 * @param accessionNumber Content of the AccessionNumber (0x0008, 0x0050) tag. Might be NULL. | |
1493 * @param studyInstanceUid Content of the StudyInstanceUID (0x0020, 0x000d) tag. Might be NULL. | |
1494 * @param seriesInstanceUid Content of the SeriesInstanceUID (0x0020, 0x000e) tag. Might be NULL. | |
1495 * @param sopInstanceUid Content of the SOPInstanceUID (0x0008, 0x0018) tag. Might be NULL. | |
1496 * @param originatorAet The Application Entity Title (AET) of the | |
1497 * modality from which the request originates. | |
1498 * @param sourceAet The Application Entity Title (AET) of the | |
1499 * modality that should send its DICOM files to another modality. | |
1500 * @param targetAet The Application Entity Title (AET) of the | |
1501 * modality that should receive the DICOM files. | |
1502 * @param originatorId The Message ID issued by the originator modality, | |
1503 * as found in tag (0000,0110) of the DICOM query emitted by the issuer. | |
1504 * | |
1505 * @return The NULL value if the plugin cannot deal with this query, | |
1506 * or a pointer to the driver object that is responsible for | |
1507 * handling the successive move suboperations. | |
1508 * | |
1509 * @note If targetAet equals sourceAet, this is actually a query/retrieve operation. | |
1510 * @ingroup DicomCallbacks | |
1511 **/ | |
1512 typedef void* (*OrthancPluginMoveCallback) ( | |
1513 OrthancPluginResourceType resourceType, | |
1514 const char* patientId, | |
1515 const char* accessionNumber, | |
1516 const char* studyInstanceUid, | |
1517 const char* seriesInstanceUid, | |
1518 const char* sopInstanceUid, | |
1519 const char* originatorAet, | |
1520 const char* sourceAet, | |
1521 const char* targetAet, | |
1522 uint16_t originatorId); | |
1523 | |
1524 | |
1525 /** | |
1526 * @brief Callback to read the size of a C-Move driver. | |
1527 * | |
1528 * Signature of a callback function that returns the number of | |
1529 * C-Move suboperations that are to be achieved by the given C-Move | |
1530 * driver. This driver is the return value of a previous call to the | |
1531 * OrthancPluginMoveCallback() callback. | |
1532 * | |
1533 * @param moveDriver The C-Move driver of interest. | |
1534 * @return The number of suboperations. | |
1535 * @ingroup DicomCallbacks | |
1536 **/ | |
1537 typedef uint32_t (*OrthancPluginGetMoveSize) (void* moveDriver); | |
1538 | |
1539 | |
1540 /** | |
1541 * @brief Callback to apply one C-Move suboperation. | |
1542 * | |
1543 * Signature of a callback function that applies the next C-Move | |
1544 * suboperation that os to be achieved by the given C-Move | |
1545 * driver. This driver is the return value of a previous call to the | |
1546 * OrthancPluginMoveCallback() callback. | |
1547 * | |
1548 * @param moveDriver The C-Move driver of interest. | |
1549 * @return 0 if success, or the error code if failure. | |
1550 * @ingroup DicomCallbacks | |
1551 **/ | |
1552 typedef OrthancPluginErrorCode (*OrthancPluginApplyMove) (void* moveDriver); | |
1553 | |
1554 | |
1555 /** | |
1556 * @brief Callback to free one C-Move driver. | |
1557 * | |
1558 * Signature of a callback function that releases the resources | |
1559 * allocated by the given C-Move driver. This driver is the return | |
1560 * value of a previous call to the OrthancPluginMoveCallback() | |
1561 * callback. | |
1562 * | |
1563 * @param moveDriver The C-Move driver of interest. | |
1564 * @ingroup DicomCallbacks | |
1565 **/ | |
1566 typedef void (*OrthancPluginFreeMove) (void* moveDriver); | |
1567 | |
1568 | |
1569 /** | |
1570 * @brief Callback to finalize one custom job. | |
1571 * | |
1572 * Signature of a callback function that releases all the resources | |
1573 * allocated by the given job. This job is the argument provided to | |
1574 * OrthancPluginCreateJob(). | |
1575 * | |
1576 * @param job The job of interest. | |
1577 * @ingroup Toolbox | |
1578 **/ | |
1579 typedef void (*OrthancPluginJobFinalize) (void* job); | |
1580 | |
1581 | |
1582 /** | |
1583 * @brief Callback to check the progress of one custom job. | |
1584 * | |
1585 * Signature of a callback function that returns the progress of the | |
1586 * job. | |
1587 * | |
1588 * @param job The job of interest. | |
1589 * @return The progress, as a floating-point number ranging from 0 to 1. | |
1590 * @ingroup Toolbox | |
1591 **/ | |
1592 typedef float (*OrthancPluginJobGetProgress) (void* job); | |
1593 | |
1594 | |
1595 /** | |
1596 * @brief Callback to retrieve the content of one custom job. | |
1597 * | |
1598 * Signature of a callback function that returns human-readable | |
1599 * statistics about the job. This statistics must be formatted as a | |
1600 * JSON object. This information is notably displayed in the "Jobs" | |
1601 * tab of "Orthanc Explorer". | |
1602 * | |
1603 * @param job The job of interest. | |
1604 * @return The statistics, as a JSON object encoded as a string. | |
1605 * @ingroup Toolbox | |
1606 * @deprecated This signature should not be used anymore since Orthanc SDK 1.11.3. | |
1607 **/ | |
1608 typedef const char* (*OrthancPluginJobGetContent) (void* job); | |
1609 | |
1610 | |
1611 /** | |
1612 * @brief Callback to retrieve the content of one custom job. | |
1613 * | |
1614 * Signature of a callback function that returns human-readable | |
1615 * statistics about the job. This statistics must be formatted as a | |
1616 * JSON object. This information is notably displayed in the "Jobs" | |
1617 * tab of "Orthanc Explorer". | |
1618 * | |
1619 * @param target The target memory buffer where to store the JSON string. | |
1620 * This buffer must be allocated using OrthancPluginCreateMemoryBuffer() | |
1621 * and will be freed by the Orthanc core. | |
1622 * @param job The job of interest. | |
1623 * @return 0 if success, other value if error. | |
1624 * @ingroup Toolbox | |
1625 **/ | |
1626 typedef OrthancPluginErrorCode (*OrthancPluginJobGetContent2) (OrthancPluginMemoryBuffer* target, | |
1627 void* job); | |
1628 | |
1629 | |
1630 /** | |
1631 * @brief Callback to serialize one custom job. | |
1632 * | |
1633 * Signature of a callback function that returns a serialized | |
1634 * version of the job, formatted as a JSON object. This | |
1635 * serialization is stored in the Orthanc database, and is used to | |
1636 * reload the job on the restart of Orthanc. The "unserialization" | |
1637 * callback (with OrthancPluginJobsUnserializer signature) will | |
1638 * receive this serialized object. | |
1639 * | |
1640 * @param job The job of interest. | |
1641 * @return The serialized job, as a JSON object encoded as a string. | |
1642 * @see OrthancPluginRegisterJobsUnserializer() | |
1643 * @ingroup Toolbox | |
1644 * @deprecated This signature should not be used anymore since Orthanc SDK 1.11.3. | |
1645 **/ | |
1646 typedef const char* (*OrthancPluginJobGetSerialized) (void* job); | |
1647 | |
1648 | |
1649 /** | |
1650 * @brief Callback to serialize one custom job. | |
1651 * | |
1652 * Signature of a callback function that returns a serialized | |
1653 * version of the job, formatted as a JSON object. This | |
1654 * serialization is stored in the Orthanc database, and is used to | |
1655 * reload the job on the restart of Orthanc. The "unserialization" | |
1656 * callback (with OrthancPluginJobsUnserializer signature) will | |
1657 * receive this serialized object. | |
1658 * | |
1659 * @param target The target memory buffer where to store the JSON string. | |
1660 * This buffer must be allocated using OrthancPluginCreateMemoryBuffer() | |
1661 * and will be freed by the Orthanc core. | |
1662 * @param job The job of interest. | |
1663 * @return 1 if the serialization has succeeded, 0 if serialization is | |
1664 * not implemented for this type of job, or -1 in case of error. | |
1665 **/ | |
1666 typedef int32_t (*OrthancPluginJobGetSerialized2) (OrthancPluginMemoryBuffer* target, | |
1667 void* job); | |
1668 | |
1669 | |
1670 /** | |
1671 * @brief Callback to execute one step of a custom job. | |
1672 * | |
1673 * Signature of a callback function that executes one step in the | |
1674 * job. The jobs engine of Orthanc will make successive calls to | |
1675 * this method, as long as it returns | |
1676 * OrthancPluginJobStepStatus_Continue. | |
1677 * | |
1678 * @param job The job of interest. | |
1679 * @return The status of execution. | |
1680 * @ingroup Toolbox | |
1681 **/ | |
1682 typedef OrthancPluginJobStepStatus (*OrthancPluginJobStep) (void* job); | |
1683 | |
1684 | |
1685 /** | |
1686 * @brief Callback executed once one custom job leaves the "running" state. | |
1687 * | |
1688 * Signature of a callback function that is invoked once a job | |
1689 * leaves the "running" state. This can happen if the previous call | |
1690 * to OrthancPluginJobStep has failed/succeeded, if the host Orthanc | |
1691 * server is being stopped, or if the user manually tags the job as | |
1692 * paused/canceled. This callback allows the plugin to free | |
1693 * resources allocated for running this custom job (e.g. to stop | |
1694 * threads, or to remove temporary files). | |
1695 * | |
1696 * Note that handling pauses might involves a specific treatment | |
1697 * (such a stopping threads, but keeping temporary files on the | |
1698 * disk). This "paused" situation can be checked by looking at the | |
1699 * "reason" parameter. | |
1700 * | |
1701 * @param job The job of interest. | |
1702 * @param reason The reason for leaving the "running" state. | |
1703 * @return 0 if success, or the error code if failure. | |
1704 * @ingroup Toolbox | |
1705 **/ | |
1706 typedef OrthancPluginErrorCode (*OrthancPluginJobStop) (void* job, | |
1707 OrthancPluginJobStopReason reason); | |
1708 | |
1709 | |
1710 /** | |
1711 * @brief Callback executed once one stopped custom job is started again. | |
1712 * | |
1713 * Signature of a callback function that is invoked once a job | |
1714 * leaves the "failure/canceled" state, to be started again. This | |
1715 * function will typically reset the progress to zero. Note that | |
1716 * before being actually executed, the job would first be tagged as | |
1717 * "pending" in the Orthanc jobs engine. | |
1718 * | |
1719 * @param job The job of interest. | |
1720 * @return 0 if success, or the error code if failure. | |
1721 * @ingroup Toolbox | |
1722 **/ | |
1723 typedef OrthancPluginErrorCode (*OrthancPluginJobReset) (void* job); | |
1724 | |
1725 | |
1726 /** | |
1727 * @brief Callback executed to unserialize a custom job. | |
1728 * | |
1729 * Signature of a callback function that unserializes a job that was | |
1730 * saved in the Orthanc database. | |
1731 * | |
1732 * @param jobType The type of the job, as provided to OrthancPluginCreateJob(). | |
1733 * @param serialized The serialization of the job, as provided by OrthancPluginJobGetSerialized. | |
1734 * @return The unserialized job (as created by OrthancPluginCreateJob()), or NULL | |
1735 * if this unserializer cannot handle this job type. | |
1736 * @see OrthancPluginRegisterJobsUnserializer() | |
1737 * @ingroup Callbacks | |
1738 **/ | |
1739 typedef OrthancPluginJob* (*OrthancPluginJobsUnserializer) (const char* jobType, | |
1740 const char* serialized); | |
1741 | |
1742 | |
1743 | |
1744 /** | |
1745 * @brief Callback executed to update the metrics of the plugin. | |
1746 * | |
1747 * Signature of a callback function that is called by Orthanc | |
1748 * whenever a monitoring tool (such as Prometheus) asks the current | |
1749 * values of the metrics. This callback gives the plugin a chance to | |
1750 * update its metrics, by calling OrthancPluginSetMetricsValue() or | |
1751 * OrthancPluginSetMetricsIntegerValue(). | |
1752 * This is typically useful for metrics that are expensive to | |
1753 * acquire. | |
1754 * | |
1755 * @see OrthancPluginRegisterRefreshMetrics() | |
1756 * @ingroup Callbacks | |
1757 **/ | |
1758 typedef void (*OrthancPluginRefreshMetricsCallback) (); | |
1759 | |
1760 | |
1761 | |
1762 /** | |
1763 * @brief Callback executed to encode a binary tag in DICOMweb. | |
1764 * | |
1765 * Signature of a callback function that is called by Orthanc | |
1766 * whenever a DICOM tag that contains a binary value must be written | |
1767 * to a JSON or XML node, while a DICOMweb document is being | |
1768 * generated. The value representation (VR) of the DICOM tag can be | |
1769 * OB, OD, OF, OL, OW, or UN. | |
1770 * | |
1771 * @see OrthancPluginEncodeDicomWebJson() and OrthancPluginEncodeDicomWebXml() | |
1772 * @param node The node being generated, as provided by Orthanc. | |
1773 * @param setter The setter to be used to encode the content of the node. If | |
1774 * the setter is not called, the binary tag is not written to the output document. | |
1775 * @param levelDepth The depth of the node in the DICOM hierarchy of sequences. | |
1776 * This parameter gives the number of elements in the "levelTagGroup", | |
1777 * "levelTagElement", and "levelIndex" arrays. | |
1778 * @param levelTagGroup The group of the parent DICOM tags in the hierarchy. | |
1779 * @param levelTagElement The element of the parent DICOM tags in the hierarchy. | |
1780 * @param levelIndex The index of the node in the parent sequences of the hierarchy. | |
1781 * @param tagGroup The group of the DICOM tag of interest. | |
1782 * @param tagElement The element of the DICOM tag of interest. | |
1783 * @param vr The value representation of the binary DICOM node. | |
1784 * @ingroup Callbacks | |
1785 **/ | |
1786 typedef void (*OrthancPluginDicomWebBinaryCallback) ( | |
1787 OrthancPluginDicomWebNode* node, | |
1788 OrthancPluginDicomWebSetBinaryNode setter, | |
1789 uint32_t levelDepth, | |
1790 const uint16_t* levelTagGroup, | |
1791 const uint16_t* levelTagElement, | |
1792 const uint32_t* levelIndex, | |
1793 uint16_t tagGroup, | |
1794 uint16_t tagElement, | |
1795 OrthancPluginValueRepresentation vr); | |
1796 | |
1797 | |
1798 | |
1799 /** | |
1800 * @brief Callback executed to encode a binary tag in DICOMweb. | |
1801 * | |
1802 * Signature of a callback function that is called by Orthanc | |
1803 * whenever a DICOM tag that contains a binary value must be written | |
1804 * to a JSON or XML node, while a DICOMweb document is being | |
1805 * generated. The value representation (VR) of the DICOM tag can be | |
1806 * OB, OD, OF, OL, OW, or UN. | |
1807 * | |
1808 * @see OrthancPluginEncodeDicomWebJson() and OrthancPluginEncodeDicomWebXml() | |
1809 * @param node The node being generated, as provided by Orthanc. | |
1810 * @param setter The setter to be used to encode the content of the node. If | |
1811 * the setter is not called, the binary tag is not written to the output document. | |
1812 * @param levelDepth The depth of the node in the DICOM hierarchy of sequences. | |
1813 * This parameter gives the number of elements in the "levelTagGroup", | |
1814 * "levelTagElement", and "levelIndex" arrays. | |
1815 * @param levelTagGroup The group of the parent DICOM tags in the hierarchy. | |
1816 * @param levelTagElement The element of the parent DICOM tags in the hierarchy. | |
1817 * @param levelIndex The index of the node in the parent sequences of the hierarchy. | |
1818 * @param tagGroup The group of the DICOM tag of interest. | |
1819 * @param tagElement The element of the DICOM tag of interest. | |
1820 * @param vr The value representation of the binary DICOM node. | |
1821 * @param payload The user payload. | |
1822 * @ingroup Callbacks | |
1823 **/ | |
1824 typedef void (*OrthancPluginDicomWebBinaryCallback2) ( | |
1825 OrthancPluginDicomWebNode* node, | |
1826 OrthancPluginDicomWebSetBinaryNode setter, | |
1827 uint32_t levelDepth, | |
1828 const uint16_t* levelTagGroup, | |
1829 const uint16_t* levelTagElement, | |
1830 const uint32_t* levelIndex, | |
1831 uint16_t tagGroup, | |
1832 uint16_t tagElement, | |
1833 OrthancPluginValueRepresentation vr, | |
1834 void* payload); | |
1835 | |
1836 | |
1837 | |
1838 /** | |
1839 * @brief Data structure that contains information about the Orthanc core. | |
1840 **/ | |
1841 typedef struct _OrthancPluginContext_t | |
1842 { | |
1843 void* pluginsManager; | |
1844 const char* orthancVersion; | |
1845 OrthancPluginFree Free; | |
1846 OrthancPluginErrorCode (*InvokeService) (struct _OrthancPluginContext_t* context, | |
1847 _OrthancPluginService service, | |
1848 const void* params); | |
1849 } OrthancPluginContext; | |
1850 | |
1851 | |
1852 | |
1853 /** | |
1854 * @brief An entry in the dictionary of DICOM tags. | |
1855 **/ | |
1856 typedef struct | |
1857 { | |
1858 uint16_t group; /*!< The group of the tag */ | |
1859 uint16_t element; /*!< The element of the tag */ | |
1860 OrthancPluginValueRepresentation vr; /*!< The value representation of the tag */ | |
1861 uint32_t minMultiplicity; /*!< The minimum multiplicity of the tag */ | |
1862 uint32_t maxMultiplicity; /*!< The maximum multiplicity of the tag (0 means arbitrary) */ | |
1863 } OrthancPluginDictionaryEntry; | |
1864 | |
1865 | |
1866 | |
1867 /** | |
1868 * @brief Free a string. | |
1869 * | |
1870 * Free a string that was allocated by the core system of Orthanc. | |
1871 * | |
1872 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1873 * @param str The string to be freed. | |
1874 **/ | |
1875 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString( | |
1876 OrthancPluginContext* context, | |
1877 char* str) | |
1878 { | |
1879 if (str != NULL) | |
1880 { | |
1881 context->Free(str); | |
1882 } | |
1883 } | |
1884 | |
1885 | |
1886 /** | |
1887 * @brief Check that the version of the hosting Orthanc is above a given version. | |
1888 * | |
1889 * This function checks whether the version of the Orthanc server | |
1890 * running this plugin, is above the given version. Contrarily to | |
1891 * OrthancPluginCheckVersion(), it is up to the developer of the | |
1892 * plugin to make sure that all the Orthanc SDK services called by | |
1893 * the plugin are actually implemented in the given version of | |
1894 * Orthanc. | |
1895 * | |
1896 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
1897 * @param expectedMajor Expected major version. | |
1898 * @param expectedMinor Expected minor version. | |
1899 * @param expectedRevision Expected revision. | |
1900 * @return 1 if and only if the versions are compatible. If the | |
1901 * result is 0, the initialization of the plugin should fail. | |
1902 * @see OrthancPluginCheckVersion() | |
1903 * @ingroup Callbacks | |
1904 **/ | |
1905 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersionAdvanced( | |
1906 OrthancPluginContext* context, | |
1907 int expectedMajor, | |
1908 int expectedMinor, | |
1909 int expectedRevision) | |
1910 { | |
1911 int major, minor, revision; | |
1912 | |
1913 if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) || | |
1914 sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) || | |
1915 sizeof(int32_t) != sizeof(_OrthancPluginService) || | |
1916 sizeof(int32_t) != sizeof(_OrthancPluginProperty) || | |
1917 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) || | |
1918 sizeof(int32_t) != sizeof(OrthancPluginContentType) || | |
1919 sizeof(int32_t) != sizeof(OrthancPluginResourceType) || | |
1920 sizeof(int32_t) != sizeof(OrthancPluginChangeType) || | |
1921 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || | |
1922 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) || | |
1923 sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) || | |
1924 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) || | |
1925 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) || | |
1926 sizeof(int32_t) != sizeof(OrthancPluginCreateDicomFlags) || | |
1927 sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) || | |
1928 sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) || | |
1929 sizeof(int32_t) != sizeof(OrthancPluginJobStepStatus) || | |
1930 sizeof(int32_t) != sizeof(OrthancPluginConstraintType) || | |
1931 sizeof(int32_t) != sizeof(OrthancPluginMetricsType) || | |
1932 sizeof(int32_t) != sizeof(OrthancPluginDicomWebBinaryMode) || | |
1933 sizeof(int32_t) != sizeof(OrthancPluginStorageCommitmentFailureReason) || | |
1934 sizeof(int32_t) != sizeof(OrthancPluginLoadDicomInstanceMode)) | |
1935 { | |
1936 /* Mismatch in the size of the enumerations */ | |
1937 return 0; | |
1938 } | |
1939 | |
1940 /* Assume compatibility with the mainline */ | |
1941 if (!strcmp(context->orthancVersion, "mainline")) | |
1942 { | |
1943 return 1; | |
1944 } | |
1945 | |
1946 /* Parse the version of the Orthanc core */ | |
1947 if ( | |
1948 #ifdef _MSC_VER | |
1949 sscanf_s | |
1950 #else | |
1951 sscanf | |
1952 #endif | |
1953 (context->orthancVersion, "%4d.%4d.%4d", &major, &minor, &revision) != 3) | |
1954 { | |
1955 return 0; | |
1956 } | |
1957 | |
1958 /* Check the major number of the version */ | |
1959 | |
1960 if (major > expectedMajor) | |
1961 { | |
1962 return 1; | |
1963 } | |
1964 | |
1965 if (major < expectedMajor) | |
1966 { | |
1967 return 0; | |
1968 } | |
1969 | |
1970 /* Check the minor number of the version */ | |
1971 | |
1972 if (minor > expectedMinor) | |
1973 { | |
1974 return 1; | |
1975 } | |
1976 | |
1977 if (minor < expectedMinor) | |
1978 { | |
1979 return 0; | |
1980 } | |
1981 | |
1982 /* Check the revision number of the version */ | |
1983 | |
1984 if (revision >= expectedRevision) | |
1985 { | |
1986 return 1; | |
1987 } | |
1988 else | |
1989 { | |
1990 return 0; | |
1991 } | |
1992 } | |
1993 | |
1994 | |
1995 /** | |
1996 * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc. | |
1997 * | |
1998 * This function checks whether the version of the Orthanc server | |
1999 * running this plugin, is above the version of the current Orthanc | |
2000 * SDK header. This guarantees that the plugin is compatible with | |
2001 * the hosting Orthanc (i.e. it will not call unavailable services). | |
2002 * The result of this function should always be checked in the | |
2003 * OrthancPluginInitialize() entry point of the plugin. | |
2004 * | |
2005 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2006 * @return 1 if and only if the versions are compatible. If the | |
2007 * result is 0, the initialization of the plugin should fail. | |
2008 * @see OrthancPluginCheckVersionAdvanced() | |
2009 * @ingroup Callbacks | |
2010 **/ | |
2011 ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion( | |
2012 OrthancPluginContext* context) | |
2013 { | |
2014 return OrthancPluginCheckVersionAdvanced( | |
2015 context, | |
2016 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | |
2017 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
2018 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
2019 } | |
2020 | |
2021 | |
2022 /** | |
2023 * @brief Free a memory buffer. | |
2024 * | |
2025 * Free a memory buffer that was allocated by the core system of Orthanc. | |
2026 * | |
2027 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2028 * @param buffer The memory buffer to release. | |
2029 **/ | |
2030 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer( | |
2031 OrthancPluginContext* context, | |
2032 OrthancPluginMemoryBuffer* buffer) | |
2033 { | |
2034 context->Free(buffer->data); | |
2035 } | |
2036 | |
2037 | |
2038 /** | |
2039 * @brief Free a memory buffer. | |
2040 * | |
2041 * Free a memory buffer that was allocated by the core system of Orthanc. | |
2042 * | |
2043 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2044 * @param buffer The memory buffer to release. | |
2045 **/ | |
2046 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer64( | |
2047 OrthancPluginContext* context, | |
2048 OrthancPluginMemoryBuffer64* buffer) | |
2049 { | |
2050 context->Free(buffer->data); | |
2051 } | |
2052 | |
2053 | |
2054 /** | |
2055 * @brief Log an error. | |
2056 * | |
2057 * Log an error message using the Orthanc logging system. | |
2058 * | |
2059 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2060 * @param message The message to be logged. | |
2061 **/ | |
2062 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError( | |
2063 OrthancPluginContext* context, | |
2064 const char* message) | |
2065 { | |
2066 context->InvokeService(context, _OrthancPluginService_LogError, message); | |
2067 } | |
2068 | |
2069 | |
2070 /** | |
2071 * @brief Log a warning. | |
2072 * | |
2073 * Log a warning message using the Orthanc logging system. | |
2074 * | |
2075 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2076 * @param message The message to be logged. | |
2077 **/ | |
2078 ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning( | |
2079 OrthancPluginContext* context, | |
2080 const char* message) | |
2081 { | |
2082 context->InvokeService(context, _OrthancPluginService_LogWarning, message); | |
2083 } | |
2084 | |
2085 | |
2086 /** | |
2087 * @brief Log an information. | |
2088 * | |
2089 * Log an information message using the Orthanc logging system. | |
2090 * | |
2091 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2092 * @param message The message to be logged. | |
2093 **/ | |
2094 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo( | |
2095 OrthancPluginContext* context, | |
2096 const char* message) | |
2097 { | |
2098 context->InvokeService(context, _OrthancPluginService_LogInfo, message); | |
2099 } | |
2100 | |
2101 | |
2102 | |
2103 typedef struct | |
2104 { | |
2105 const char* pathRegularExpression; | |
2106 OrthancPluginRestCallback callback; | |
2107 } _OrthancPluginRestCallback; | |
2108 | |
2109 /** | |
2110 * @brief Register a REST callback. | |
2111 * | |
2112 * This function registers a REST callback against a regular | |
2113 * expression for a URI. This function must be called during the | |
2114 * initialization of the plugin, i.e. inside the | |
2115 * OrthancPluginInitialize() public function. | |
2116 * | |
2117 * Each REST callback is guaranteed to run in mutual exclusion. | |
2118 * | |
2119 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2120 * @param pathRegularExpression Regular expression for the URI. May contain groups. | |
2121 * @param callback The callback function to handle the REST call. | |
2122 * @see OrthancPluginRegisterRestCallbackNoLock() | |
2123 * | |
2124 * @note | |
2125 * The regular expression is case sensitive and must follow the | |
2126 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html). | |
2127 * | |
2128 * @ingroup Callbacks | |
2129 **/ | |
2130 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback( | |
2131 OrthancPluginContext* context, | |
2132 const char* pathRegularExpression, | |
2133 OrthancPluginRestCallback callback) | |
2134 { | |
2135 _OrthancPluginRestCallback params; | |
2136 params.pathRegularExpression = pathRegularExpression; | |
2137 params.callback = callback; | |
2138 context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, ¶ms); | |
2139 } | |
2140 | |
2141 | |
2142 | |
2143 /** | |
2144 * @brief Register a REST callback, without locking. | |
2145 * | |
2146 * This function registers a REST callback against a regular | |
2147 * expression for a URI. This function must be called during the | |
2148 * initialization of the plugin, i.e. inside the | |
2149 * OrthancPluginInitialize() public function. | |
2150 * | |
2151 * Contrarily to OrthancPluginRegisterRestCallback(), the callback | |
2152 * will NOT be invoked in mutual exclusion. This can be useful for | |
2153 * high-performance plugins that must handle concurrent requests | |
2154 * (Orthanc uses a pool of threads, one thread being assigned to | |
2155 * each incoming HTTP request). Of course, if using this function, | |
2156 * it is up to the plugin to implement the required locking | |
2157 * mechanisms. | |
2158 * | |
2159 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2160 * @param pathRegularExpression Regular expression for the URI. May contain groups. | |
2161 * @param callback The callback function to handle the REST call. | |
2162 * @see OrthancPluginRegisterRestCallback() | |
2163 * | |
2164 * @note | |
2165 * The regular expression is case sensitive and must follow the | |
2166 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html). | |
2167 * | |
2168 * @ingroup Callbacks | |
2169 **/ | |
2170 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallbackNoLock( | |
2171 OrthancPluginContext* context, | |
2172 const char* pathRegularExpression, | |
2173 OrthancPluginRestCallback callback) | |
2174 { | |
2175 _OrthancPluginRestCallback params; | |
2176 params.pathRegularExpression = pathRegularExpression; | |
2177 params.callback = callback; | |
2178 context->InvokeService(context, _OrthancPluginService_RegisterRestCallbackNoLock, ¶ms); | |
2179 } | |
2180 | |
2181 | |
2182 | |
2183 typedef struct | |
2184 { | |
2185 OrthancPluginOnStoredInstanceCallback callback; | |
2186 } _OrthancPluginOnStoredInstanceCallback; | |
2187 | |
2188 /** | |
2189 * @brief Register a callback for received instances. | |
2190 * | |
2191 * This function registers a callback function that is called | |
2192 * whenever a new DICOM instance is stored into the Orthanc core. | |
2193 * | |
2194 * @warning Your callback function will be called synchronously with | |
2195 * the core of Orthanc. This implies that deadlocks might emerge if | |
2196 * you call other core primitives of Orthanc in your callback (such | |
2197 * deadlocks are particularly visible in the presence of other plugins | |
2198 * or Lua scripts). It is thus strongly advised to avoid any call to | |
2199 * the REST API of Orthanc in the callback. If you have to call | |
2200 * other primitives of Orthanc, you should make these calls in a | |
2201 * separate thread, passing the pending events to be processed | |
2202 * through a message queue. | |
2203 * | |
2204 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2205 * @param callback The callback function. | |
2206 * @ingroup Callbacks | |
2207 **/ | |
2208 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback( | |
2209 OrthancPluginContext* context, | |
2210 OrthancPluginOnStoredInstanceCallback callback) | |
2211 { | |
2212 _OrthancPluginOnStoredInstanceCallback params; | |
2213 params.callback = callback; | |
2214 | |
2215 context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, ¶ms); | |
2216 } | |
2217 | |
2218 | |
2219 | |
2220 typedef struct | |
2221 { | |
2222 OrthancPluginRestOutput* output; | |
2223 const void* answer; | |
2224 uint32_t answerSize; | |
2225 const char* mimeType; | |
2226 } _OrthancPluginAnswerBuffer; | |
2227 | |
2228 /** | |
2229 * @brief Answer to a REST request. | |
2230 * | |
2231 * This function answers to a REST request with the content of a memory buffer. | |
2232 * | |
2233 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2234 * @param output The HTTP connection to the client application. | |
2235 * @param answer Pointer to the memory buffer containing the answer. | |
2236 * @param answerSize Number of bytes of the answer. | |
2237 * @param mimeType The MIME type of the answer. | |
2238 * @ingroup REST | |
2239 **/ | |
2240 ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer( | |
2241 OrthancPluginContext* context, | |
2242 OrthancPluginRestOutput* output, | |
2243 const void* answer, | |
2244 uint32_t answerSize, | |
2245 const char* mimeType) | |
2246 { | |
2247 _OrthancPluginAnswerBuffer params; | |
2248 params.output = output; | |
2249 params.answer = answer; | |
2250 params.answerSize = answerSize; | |
2251 params.mimeType = mimeType; | |
2252 context->InvokeService(context, _OrthancPluginService_AnswerBuffer, ¶ms); | |
2253 } | |
2254 | |
2255 | |
2256 typedef struct | |
2257 { | |
2258 OrthancPluginRestOutput* output; | |
2259 OrthancPluginPixelFormat format; | |
2260 uint32_t width; | |
2261 uint32_t height; | |
2262 uint32_t pitch; | |
2263 const void* buffer; | |
2264 } _OrthancPluginCompressAndAnswerPngImage; | |
2265 | |
2266 typedef struct | |
2267 { | |
2268 OrthancPluginRestOutput* output; | |
2269 OrthancPluginImageFormat imageFormat; | |
2270 OrthancPluginPixelFormat pixelFormat; | |
2271 uint32_t width; | |
2272 uint32_t height; | |
2273 uint32_t pitch; | |
2274 const void* buffer; | |
2275 uint8_t quality; | |
2276 } _OrthancPluginCompressAndAnswerImage; | |
2277 | |
2278 | |
2279 /** | |
2280 * @brief Answer to a REST request with a PNG image. | |
2281 * | |
2282 * This function answers to a REST request with a PNG image. The | |
2283 * parameters of this function describe a memory buffer that | |
2284 * contains an uncompressed image. The image will be automatically compressed | |
2285 * as a PNG image by the core system of Orthanc. | |
2286 * | |
2287 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2288 * @param output The HTTP connection to the client application. | |
2289 * @param format The memory layout of the uncompressed image. | |
2290 * @param width The width of the image. | |
2291 * @param height The height of the image. | |
2292 * @param pitch The pitch of the image (i.e. the number of bytes | |
2293 * between 2 successive lines of the image in the memory buffer). | |
2294 * @param buffer The memory buffer containing the uncompressed image. | |
2295 * @ingroup REST | |
2296 **/ | |
2297 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage( | |
2298 OrthancPluginContext* context, | |
2299 OrthancPluginRestOutput* output, | |
2300 OrthancPluginPixelFormat format, | |
2301 uint32_t width, | |
2302 uint32_t height, | |
2303 uint32_t pitch, | |
2304 const void* buffer) | |
2305 { | |
2306 _OrthancPluginCompressAndAnswerImage params; | |
2307 params.output = output; | |
2308 params.imageFormat = OrthancPluginImageFormat_Png; | |
2309 params.pixelFormat = format; | |
2310 params.width = width; | |
2311 params.height = height; | |
2312 params.pitch = pitch; | |
2313 params.buffer = buffer; | |
2314 params.quality = 0; /* No quality for PNG */ | |
2315 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, ¶ms); | |
2316 } | |
2317 | |
2318 | |
2319 | |
2320 typedef struct | |
2321 { | |
2322 OrthancPluginMemoryBuffer* target; | |
2323 const char* instanceId; | |
2324 } _OrthancPluginGetDicomForInstance; | |
2325 | |
2326 /** | |
2327 * @brief Retrieve a DICOM instance using its Orthanc identifier. | |
2328 * | |
2329 * Retrieve a DICOM instance using its Orthanc identifier. The DICOM | |
2330 * file is stored into a newly allocated memory buffer. | |
2331 * | |
2332 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2333 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
2334 * @param instanceId The Orthanc identifier of the DICOM instance of interest. | |
2335 * @return 0 if success, or the error code if failure. | |
2336 * @ingroup Orthanc | |
2337 **/ | |
2338 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetDicomForInstance( | |
2339 OrthancPluginContext* context, | |
2340 OrthancPluginMemoryBuffer* target, | |
2341 const char* instanceId) | |
2342 { | |
2343 _OrthancPluginGetDicomForInstance params; | |
2344 params.target = target; | |
2345 params.instanceId = instanceId; | |
2346 return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, ¶ms); | |
2347 } | |
2348 | |
2349 | |
2350 | |
2351 typedef struct | |
2352 { | |
2353 OrthancPluginMemoryBuffer* target; | |
2354 const char* uri; | |
2355 } _OrthancPluginRestApiGet; | |
2356 | |
2357 /** | |
2358 * @brief Make a GET call to the built-in Orthanc REST API. | |
2359 * | |
2360 * Make a GET call to the built-in Orthanc REST API. The result to | |
2361 * the query is stored into a newly allocated memory buffer. | |
2362 * | |
2363 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2364 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
2365 * @param uri The URI in the built-in Orthanc API. | |
2366 * @return 0 if success, or the error code if failure. | |
2367 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2368 * @see OrthancPluginRestApiGetAfterPlugins() | |
2369 * @ingroup Orthanc | |
2370 **/ | |
2371 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet( | |
2372 OrthancPluginContext* context, | |
2373 OrthancPluginMemoryBuffer* target, | |
2374 const char* uri) | |
2375 { | |
2376 _OrthancPluginRestApiGet params; | |
2377 params.target = target; | |
2378 params.uri = uri; | |
2379 return context->InvokeService(context, _OrthancPluginService_RestApiGet, ¶ms); | |
2380 } | |
2381 | |
2382 | |
2383 | |
2384 /** | |
2385 * @brief Make a GET call to the REST API, as tainted by the plugins. | |
2386 * | |
2387 * Make a GET call to the Orthanc REST API, after all the plugins | |
2388 * are applied. In other words, if some plugin overrides or adds the | |
2389 * called URI to the built-in Orthanc REST API, this call will | |
2390 * return the result provided by this plugin. The result to the | |
2391 * query is stored into a newly allocated memory buffer. | |
2392 * | |
2393 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2394 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
2395 * @param uri The URI in the built-in Orthanc API. | |
2396 * @return 0 if success, or the error code if failure. | |
2397 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2398 * @see OrthancPluginRestApiGet() | |
2399 * @ingroup Orthanc | |
2400 **/ | |
2401 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGetAfterPlugins( | |
2402 OrthancPluginContext* context, | |
2403 OrthancPluginMemoryBuffer* target, | |
2404 const char* uri) | |
2405 { | |
2406 _OrthancPluginRestApiGet params; | |
2407 params.target = target; | |
2408 params.uri = uri; | |
2409 return context->InvokeService(context, _OrthancPluginService_RestApiGetAfterPlugins, ¶ms); | |
2410 } | |
2411 | |
2412 | |
2413 | |
2414 typedef struct | |
2415 { | |
2416 OrthancPluginMemoryBuffer* target; | |
2417 const char* uri; | |
2418 const void* body; | |
2419 uint32_t bodySize; | |
2420 } _OrthancPluginRestApiPostPut; | |
2421 | |
2422 /** | |
2423 * @brief Make a POST call to the built-in Orthanc REST API. | |
2424 * | |
2425 * Make a POST call to the built-in Orthanc REST API. The result to | |
2426 * the query is stored into a newly allocated memory buffer. | |
2427 * | |
2428 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2429 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
2430 * @param uri The URI in the built-in Orthanc API. | |
2431 * @param body The body of the POST request. | |
2432 * @param bodySize The size of the body. | |
2433 * @return 0 if success, or the error code if failure. | |
2434 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2435 * @see OrthancPluginRestApiPostAfterPlugins() | |
2436 * @ingroup Orthanc | |
2437 **/ | |
2438 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPost( | |
2439 OrthancPluginContext* context, | |
2440 OrthancPluginMemoryBuffer* target, | |
2441 const char* uri, | |
2442 const void* body, | |
2443 uint32_t bodySize) | |
2444 { | |
2445 _OrthancPluginRestApiPostPut params; | |
2446 params.target = target; | |
2447 params.uri = uri; | |
2448 params.body = body; | |
2449 params.bodySize = bodySize; | |
2450 return context->InvokeService(context, _OrthancPluginService_RestApiPost, ¶ms); | |
2451 } | |
2452 | |
2453 | |
2454 /** | |
2455 * @brief Make a POST call to the REST API, as tainted by the plugins. | |
2456 * | |
2457 * Make a POST call to the Orthanc REST API, after all the plugins | |
2458 * are applied. In other words, if some plugin overrides or adds the | |
2459 * called URI to the built-in Orthanc REST API, this call will | |
2460 * return the result provided by this plugin. The result to the | |
2461 * query is stored into a newly allocated memory buffer. | |
2462 * | |
2463 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2464 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
2465 * @param uri The URI in the built-in Orthanc API. | |
2466 * @param body The body of the POST request. | |
2467 * @param bodySize The size of the body. | |
2468 * @return 0 if success, or the error code if failure. | |
2469 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2470 * @see OrthancPluginRestApiPost() | |
2471 * @ingroup Orthanc | |
2472 **/ | |
2473 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPostAfterPlugins( | |
2474 OrthancPluginContext* context, | |
2475 OrthancPluginMemoryBuffer* target, | |
2476 const char* uri, | |
2477 const void* body, | |
2478 uint32_t bodySize) | |
2479 { | |
2480 _OrthancPluginRestApiPostPut params; | |
2481 params.target = target; | |
2482 params.uri = uri; | |
2483 params.body = body; | |
2484 params.bodySize = bodySize; | |
2485 return context->InvokeService(context, _OrthancPluginService_RestApiPostAfterPlugins, ¶ms); | |
2486 } | |
2487 | |
2488 | |
2489 | |
2490 /** | |
2491 * @brief Make a DELETE call to the built-in Orthanc REST API. | |
2492 * | |
2493 * Make a DELETE call to the built-in Orthanc REST API. | |
2494 * | |
2495 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2496 * @param uri The URI to delete in the built-in Orthanc API. | |
2497 * @return 0 if success, or the error code if failure. | |
2498 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2499 * @see OrthancPluginRestApiDeleteAfterPlugins() | |
2500 * @ingroup Orthanc | |
2501 **/ | |
2502 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDelete( | |
2503 OrthancPluginContext* context, | |
2504 const char* uri) | |
2505 { | |
2506 return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri); | |
2507 } | |
2508 | |
2509 | |
2510 /** | |
2511 * @brief Make a DELETE call to the REST API, as tainted by the plugins. | |
2512 * | |
2513 * Make a DELETE call to the Orthanc REST API, after all the plugins | |
2514 * are applied. In other words, if some plugin overrides or adds the | |
2515 * called URI to the built-in Orthanc REST API, this call will | |
2516 * return the result provided by this plugin. | |
2517 * | |
2518 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2519 * @param uri The URI to delete in the built-in Orthanc API. | |
2520 * @return 0 if success, or the error code if failure. | |
2521 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2522 * @see OrthancPluginRestApiDelete() | |
2523 * @ingroup Orthanc | |
2524 **/ | |
2525 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDeleteAfterPlugins( | |
2526 OrthancPluginContext* context, | |
2527 const char* uri) | |
2528 { | |
2529 return context->InvokeService(context, _OrthancPluginService_RestApiDeleteAfterPlugins, uri); | |
2530 } | |
2531 | |
2532 | |
2533 | |
2534 /** | |
2535 * @brief Make a PUT call to the built-in Orthanc REST API. | |
2536 * | |
2537 * Make a PUT call to the built-in Orthanc REST API. The result to | |
2538 * the query is stored into a newly allocated memory buffer. | |
2539 * | |
2540 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2541 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
2542 * @param uri The URI in the built-in Orthanc API. | |
2543 * @param body The body of the PUT request. | |
2544 * @param bodySize The size of the body. | |
2545 * @return 0 if success, or the error code if failure. | |
2546 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2547 * @see OrthancPluginRestApiPutAfterPlugins() | |
2548 * @ingroup Orthanc | |
2549 **/ | |
2550 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPut( | |
2551 OrthancPluginContext* context, | |
2552 OrthancPluginMemoryBuffer* target, | |
2553 const char* uri, | |
2554 const void* body, | |
2555 uint32_t bodySize) | |
2556 { | |
2557 _OrthancPluginRestApiPostPut params; | |
2558 params.target = target; | |
2559 params.uri = uri; | |
2560 params.body = body; | |
2561 params.bodySize = bodySize; | |
2562 return context->InvokeService(context, _OrthancPluginService_RestApiPut, ¶ms); | |
2563 } | |
2564 | |
2565 | |
2566 | |
2567 /** | |
2568 * @brief Make a PUT call to the REST API, as tainted by the plugins. | |
2569 * | |
2570 * Make a PUT call to the Orthanc REST API, after all the plugins | |
2571 * are applied. In other words, if some plugin overrides or adds the | |
2572 * called URI to the built-in Orthanc REST API, this call will | |
2573 * return the result provided by this plugin. The result to the | |
2574 * query is stored into a newly allocated memory buffer. | |
2575 * | |
2576 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2577 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
2578 * @param uri The URI in the built-in Orthanc API. | |
2579 * @param body The body of the PUT request. | |
2580 * @param bodySize The size of the body. | |
2581 * @return 0 if success, or the error code if failure. | |
2582 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. | |
2583 * @see OrthancPluginRestApiPut() | |
2584 * @ingroup Orthanc | |
2585 **/ | |
2586 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPutAfterPlugins( | |
2587 OrthancPluginContext* context, | |
2588 OrthancPluginMemoryBuffer* target, | |
2589 const char* uri, | |
2590 const void* body, | |
2591 uint32_t bodySize) | |
2592 { | |
2593 _OrthancPluginRestApiPostPut params; | |
2594 params.target = target; | |
2595 params.uri = uri; | |
2596 params.body = body; | |
2597 params.bodySize = bodySize; | |
2598 return context->InvokeService(context, _OrthancPluginService_RestApiPutAfterPlugins, ¶ms); | |
2599 } | |
2600 | |
2601 | |
2602 | |
2603 typedef struct | |
2604 { | |
2605 OrthancPluginRestOutput* output; | |
2606 const char* argument; | |
2607 } _OrthancPluginOutputPlusArgument; | |
2608 | |
2609 /** | |
2610 * @brief Redirect a REST request. | |
2611 * | |
2612 * This function answers to a REST request by redirecting the user | |
2613 * to another URI using HTTP status 301. | |
2614 * | |
2615 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2616 * @param output The HTTP connection to the client application. | |
2617 * @param redirection Where to redirect. | |
2618 * @ingroup REST | |
2619 **/ | |
2620 ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect( | |
2621 OrthancPluginContext* context, | |
2622 OrthancPluginRestOutput* output, | |
2623 const char* redirection) | |
2624 { | |
2625 _OrthancPluginOutputPlusArgument params; | |
2626 params.output = output; | |
2627 params.argument = redirection; | |
2628 context->InvokeService(context, _OrthancPluginService_Redirect, ¶ms); | |
2629 } | |
2630 | |
2631 | |
2632 | |
2633 typedef struct | |
2634 { | |
2635 char** result; | |
2636 const char* argument; | |
2637 } _OrthancPluginRetrieveDynamicString; | |
2638 | |
2639 /** | |
2640 * @brief Look for a patient. | |
2641 * | |
2642 * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020). | |
2643 * This function uses the database index to run as fast as possible (it does not loop | |
2644 * over all the stored patients). | |
2645 * | |
2646 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2647 * @param patientID The Patient ID of interest. | |
2648 * @return The NULL value if the patient is non-existent, or a string containing the | |
2649 * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString(). | |
2650 * @ingroup Orthanc | |
2651 **/ | |
2652 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient( | |
2653 OrthancPluginContext* context, | |
2654 const char* patientID) | |
2655 { | |
2656 char* result; | |
2657 | |
2658 _OrthancPluginRetrieveDynamicString params; | |
2659 params.result = &result; | |
2660 params.argument = patientID; | |
2661 | |
2662 if (context->InvokeService(context, _OrthancPluginService_LookupPatient, ¶ms) != OrthancPluginErrorCode_Success) | |
2663 { | |
2664 /* Error */ | |
2665 return NULL; | |
2666 } | |
2667 else | |
2668 { | |
2669 return result; | |
2670 } | |
2671 } | |
2672 | |
2673 | |
2674 /** | |
2675 * @brief Look for a study. | |
2676 * | |
2677 * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d). | |
2678 * This function uses the database index to run as fast as possible (it does not loop | |
2679 * over all the stored studies). | |
2680 * | |
2681 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2682 * @param studyUID The Study Instance UID of interest. | |
2683 * @return The NULL value if the study is non-existent, or a string containing the | |
2684 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString(). | |
2685 * @ingroup Orthanc | |
2686 **/ | |
2687 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy( | |
2688 OrthancPluginContext* context, | |
2689 const char* studyUID) | |
2690 { | |
2691 char* result; | |
2692 | |
2693 _OrthancPluginRetrieveDynamicString params; | |
2694 params.result = &result; | |
2695 params.argument = studyUID; | |
2696 | |
2697 if (context->InvokeService(context, _OrthancPluginService_LookupStudy, ¶ms) != OrthancPluginErrorCode_Success) | |
2698 { | |
2699 /* Error */ | |
2700 return NULL; | |
2701 } | |
2702 else | |
2703 { | |
2704 return result; | |
2705 } | |
2706 } | |
2707 | |
2708 | |
2709 /** | |
2710 * @brief Look for a study, using the accession number. | |
2711 * | |
2712 * Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050). | |
2713 * This function uses the database index to run as fast as possible (it does not loop | |
2714 * over all the stored studies). | |
2715 * | |
2716 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2717 * @param accessionNumber The Accession Number of interest. | |
2718 * @return The NULL value if the study is non-existent, or a string containing the | |
2719 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString(). | |
2720 * @ingroup Orthanc | |
2721 **/ | |
2722 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber( | |
2723 OrthancPluginContext* context, | |
2724 const char* accessionNumber) | |
2725 { | |
2726 char* result; | |
2727 | |
2728 _OrthancPluginRetrieveDynamicString params; | |
2729 params.result = &result; | |
2730 params.argument = accessionNumber; | |
2731 | |
2732 if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, ¶ms) != OrthancPluginErrorCode_Success) | |
2733 { | |
2734 /* Error */ | |
2735 return NULL; | |
2736 } | |
2737 else | |
2738 { | |
2739 return result; | |
2740 } | |
2741 } | |
2742 | |
2743 | |
2744 /** | |
2745 * @brief Look for a series. | |
2746 * | |
2747 * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e). | |
2748 * This function uses the database index to run as fast as possible (it does not loop | |
2749 * over all the stored series). | |
2750 * | |
2751 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2752 * @param seriesUID The Series Instance UID of interest. | |
2753 * @return The NULL value if the series is non-existent, or a string containing the | |
2754 * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString(). | |
2755 * @ingroup Orthanc | |
2756 **/ | |
2757 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries( | |
2758 OrthancPluginContext* context, | |
2759 const char* seriesUID) | |
2760 { | |
2761 char* result; | |
2762 | |
2763 _OrthancPluginRetrieveDynamicString params; | |
2764 params.result = &result; | |
2765 params.argument = seriesUID; | |
2766 | |
2767 if (context->InvokeService(context, _OrthancPluginService_LookupSeries, ¶ms) != OrthancPluginErrorCode_Success) | |
2768 { | |
2769 /* Error */ | |
2770 return NULL; | |
2771 } | |
2772 else | |
2773 { | |
2774 return result; | |
2775 } | |
2776 } | |
2777 | |
2778 | |
2779 /** | |
2780 * @brief Look for an instance. | |
2781 * | |
2782 * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018). | |
2783 * This function uses the database index to run as fast as possible (it does not loop | |
2784 * over all the stored instances). | |
2785 * | |
2786 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2787 * @param sopInstanceUID The SOP Instance UID of interest. | |
2788 * @return The NULL value if the instance is non-existent, or a string containing the | |
2789 * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString(). | |
2790 * @ingroup Orthanc | |
2791 **/ | |
2792 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance( | |
2793 OrthancPluginContext* context, | |
2794 const char* sopInstanceUID) | |
2795 { | |
2796 char* result; | |
2797 | |
2798 _OrthancPluginRetrieveDynamicString params; | |
2799 params.result = &result; | |
2800 params.argument = sopInstanceUID; | |
2801 | |
2802 if (context->InvokeService(context, _OrthancPluginService_LookupInstance, ¶ms) != OrthancPluginErrorCode_Success) | |
2803 { | |
2804 /* Error */ | |
2805 return NULL; | |
2806 } | |
2807 else | |
2808 { | |
2809 return result; | |
2810 } | |
2811 } | |
2812 | |
2813 | |
2814 | |
2815 typedef struct | |
2816 { | |
2817 OrthancPluginRestOutput* output; | |
2818 uint16_t status; | |
2819 } _OrthancPluginSendHttpStatusCode; | |
2820 | |
2821 /** | |
2822 * @brief Send a HTTP status code. | |
2823 * | |
2824 * This function answers to a REST request by sending a HTTP status | |
2825 * code (such as "400 - Bad Request"). Note that: | |
2826 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). | |
2827 * - Redirections (status 301) must use ::OrthancPluginRedirect(). | |
2828 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). | |
2829 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed(). | |
2830 * | |
2831 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2832 * @param output The HTTP connection to the client application. | |
2833 * @param status The HTTP status code to be sent. | |
2834 * @ingroup REST | |
2835 * @see OrthancPluginSendHttpStatus() | |
2836 **/ | |
2837 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode( | |
2838 OrthancPluginContext* context, | |
2839 OrthancPluginRestOutput* output, | |
2840 uint16_t status) | |
2841 { | |
2842 _OrthancPluginSendHttpStatusCode params; | |
2843 params.output = output; | |
2844 params.status = status; | |
2845 context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, ¶ms); | |
2846 } | |
2847 | |
2848 | |
2849 /** | |
2850 * @brief Signal that a REST request is not authorized. | |
2851 * | |
2852 * This function answers to a REST request by signaling that it is | |
2853 * not authorized. | |
2854 * | |
2855 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2856 * @param output The HTTP connection to the client application. | |
2857 * @param realm The realm for the authorization process. | |
2858 * @ingroup REST | |
2859 **/ | |
2860 ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized( | |
2861 OrthancPluginContext* context, | |
2862 OrthancPluginRestOutput* output, | |
2863 const char* realm) | |
2864 { | |
2865 _OrthancPluginOutputPlusArgument params; | |
2866 params.output = output; | |
2867 params.argument = realm; | |
2868 context->InvokeService(context, _OrthancPluginService_SendUnauthorized, ¶ms); | |
2869 } | |
2870 | |
2871 | |
2872 /** | |
2873 * @brief Signal that this URI does not support this HTTP method. | |
2874 * | |
2875 * This function answers to a REST request by signaling that the | |
2876 * queried URI does not support this method. | |
2877 * | |
2878 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2879 * @param output The HTTP connection to the client application. | |
2880 * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request). | |
2881 * @ingroup REST | |
2882 **/ | |
2883 ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed( | |
2884 OrthancPluginContext* context, | |
2885 OrthancPluginRestOutput* output, | |
2886 const char* allowedMethods) | |
2887 { | |
2888 _OrthancPluginOutputPlusArgument params; | |
2889 params.output = output; | |
2890 params.argument = allowedMethods; | |
2891 context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, ¶ms); | |
2892 } | |
2893 | |
2894 | |
2895 typedef struct | |
2896 { | |
2897 OrthancPluginRestOutput* output; | |
2898 const char* key; | |
2899 const char* value; | |
2900 } _OrthancPluginSetHttpHeader; | |
2901 | |
2902 /** | |
2903 * @brief Set a cookie. | |
2904 * | |
2905 * This function sets a cookie in the HTTP client. | |
2906 * | |
2907 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2908 * @param output The HTTP connection to the client application. | |
2909 * @param cookie The cookie to be set. | |
2910 * @param value The value of the cookie. | |
2911 * @ingroup REST | |
2912 **/ | |
2913 ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie( | |
2914 OrthancPluginContext* context, | |
2915 OrthancPluginRestOutput* output, | |
2916 const char* cookie, | |
2917 const char* value) | |
2918 { | |
2919 _OrthancPluginSetHttpHeader params; | |
2920 params.output = output; | |
2921 params.key = cookie; | |
2922 params.value = value; | |
2923 context->InvokeService(context, _OrthancPluginService_SetCookie, ¶ms); | |
2924 } | |
2925 | |
2926 | |
2927 /** | |
2928 * @brief Set some HTTP header. | |
2929 * | |
2930 * This function sets a HTTP header in the HTTP answer. | |
2931 * | |
2932 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2933 * @param output The HTTP connection to the client application. | |
2934 * @param key The HTTP header to be set. | |
2935 * @param value The value of the HTTP header. | |
2936 * @ingroup REST | |
2937 **/ | |
2938 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader( | |
2939 OrthancPluginContext* context, | |
2940 OrthancPluginRestOutput* output, | |
2941 const char* key, | |
2942 const char* value) | |
2943 { | |
2944 _OrthancPluginSetHttpHeader params; | |
2945 params.output = output; | |
2946 params.key = key; | |
2947 params.value = value; | |
2948 context->InvokeService(context, _OrthancPluginService_SetHttpHeader, ¶ms); | |
2949 } | |
2950 | |
2951 | |
2952 typedef struct | |
2953 { | |
2954 char** resultStringToFree; | |
2955 const char** resultString; | |
2956 int64_t* resultInt64; | |
2957 const char* key; | |
2958 const OrthancPluginDicomInstance* instance; | |
2959 OrthancPluginInstanceOrigin* resultOrigin; /* New in Orthanc 0.9.5 SDK */ | |
2960 } _OrthancPluginAccessDicomInstance; | |
2961 | |
2962 | |
2963 /** | |
2964 * @brief Get the AET of a DICOM instance. | |
2965 * | |
2966 * This function returns the Application Entity Title (AET) of the | |
2967 * DICOM modality from which a DICOM instance originates. | |
2968 * | |
2969 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
2970 * @param instance The instance of interest. | |
2971 * @return The AET if success, NULL if error. | |
2972 * @ingroup DicomInstance | |
2973 **/ | |
2974 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet( | |
2975 OrthancPluginContext* context, | |
2976 const OrthancPluginDicomInstance* instance) | |
2977 { | |
2978 const char* result; | |
2979 | |
2980 _OrthancPluginAccessDicomInstance params; | |
2981 memset(¶ms, 0, sizeof(params)); | |
2982 params.resultString = &result; | |
2983 params.instance = instance; | |
2984 | |
2985 if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, ¶ms) != OrthancPluginErrorCode_Success) | |
2986 { | |
2987 /* Error */ | |
2988 return NULL; | |
2989 } | |
2990 else | |
2991 { | |
2992 return result; | |
2993 } | |
2994 } | |
2995 | |
2996 | |
2997 /** | |
2998 * @brief Get the size of a DICOM file. | |
2999 * | |
3000 * This function returns the number of bytes of the given DICOM instance. | |
3001 * | |
3002 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3003 * @param instance The instance of interest. | |
3004 * @return The size of the file, -1 in case of error. | |
3005 * @ingroup DicomInstance | |
3006 **/ | |
3007 ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize( | |
3008 OrthancPluginContext* context, | |
3009 const OrthancPluginDicomInstance* instance) | |
3010 { | |
3011 int64_t size; | |
3012 | |
3013 _OrthancPluginAccessDicomInstance params; | |
3014 memset(¶ms, 0, sizeof(params)); | |
3015 params.resultInt64 = &size; | |
3016 params.instance = instance; | |
3017 | |
3018 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, ¶ms) != OrthancPluginErrorCode_Success) | |
3019 { | |
3020 /* Error */ | |
3021 return -1; | |
3022 } | |
3023 else | |
3024 { | |
3025 return size; | |
3026 } | |
3027 } | |
3028 | |
3029 | |
3030 /** | |
3031 * @brief Get the data of a DICOM file. | |
3032 * | |
3033 * This function returns a pointer to the content of the given DICOM instance. | |
3034 * | |
3035 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3036 * @param instance The instance of interest. | |
3037 * @return The pointer to the DICOM data, NULL in case of error. | |
3038 * @ingroup DicomInstance | |
3039 **/ | |
3040 ORTHANC_PLUGIN_INLINE const void* OrthancPluginGetInstanceData( | |
3041 OrthancPluginContext* context, | |
3042 const OrthancPluginDicomInstance* instance) | |
3043 { | |
3044 const char* result; | |
3045 | |
3046 _OrthancPluginAccessDicomInstance params; | |
3047 memset(¶ms, 0, sizeof(params)); | |
3048 params.resultString = &result; | |
3049 params.instance = instance; | |
3050 | |
3051 if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, ¶ms) != OrthancPluginErrorCode_Success) | |
3052 { | |
3053 /* Error */ | |
3054 return NULL; | |
3055 } | |
3056 else | |
3057 { | |
3058 return result; | |
3059 } | |
3060 } | |
3061 | |
3062 | |
3063 /** | |
3064 * @brief Get the DICOM tag hierarchy as a JSON file. | |
3065 * | |
3066 * This function returns a pointer to a newly created string | |
3067 * containing a JSON file. This JSON file encodes the tag hierarchy | |
3068 * of the given DICOM instance. | |
3069 * | |
3070 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3071 * @param instance The instance of interest. | |
3072 * @return The NULL value in case of error, or a string containing the JSON file. | |
3073 * This string must be freed by OrthancPluginFreeString(). | |
3074 * @ingroup DicomInstance | |
3075 **/ | |
3076 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson( | |
3077 OrthancPluginContext* context, | |
3078 const OrthancPluginDicomInstance* instance) | |
3079 { | |
3080 char* result; | |
3081 | |
3082 _OrthancPluginAccessDicomInstance params; | |
3083 memset(¶ms, 0, sizeof(params)); | |
3084 params.resultStringToFree = &result; | |
3085 params.instance = instance; | |
3086 | |
3087 if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, ¶ms) != OrthancPluginErrorCode_Success) | |
3088 { | |
3089 /* Error */ | |
3090 return NULL; | |
3091 } | |
3092 else | |
3093 { | |
3094 return result; | |
3095 } | |
3096 } | |
3097 | |
3098 | |
3099 /** | |
3100 * @brief Get the DICOM tag hierarchy as a JSON file (with simplification). | |
3101 * | |
3102 * This function returns a pointer to a newly created string | |
3103 * containing a JSON file. This JSON file encodes the tag hierarchy | |
3104 * of the given DICOM instance. In contrast with | |
3105 * ::OrthancPluginGetInstanceJson(), the returned JSON file is in | |
3106 * its simplified version. | |
3107 * | |
3108 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3109 * @param instance The instance of interest. | |
3110 * @return The NULL value in case of error, or a string containing the JSON file. | |
3111 * This string must be freed by OrthancPluginFreeString(). | |
3112 * @ingroup DicomInstance | |
3113 **/ | |
3114 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson( | |
3115 OrthancPluginContext* context, | |
3116 const OrthancPluginDicomInstance* instance) | |
3117 { | |
3118 char* result; | |
3119 | |
3120 _OrthancPluginAccessDicomInstance params; | |
3121 memset(¶ms, 0, sizeof(params)); | |
3122 params.resultStringToFree = &result; | |
3123 params.instance = instance; | |
3124 | |
3125 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, ¶ms) != OrthancPluginErrorCode_Success) | |
3126 { | |
3127 /* Error */ | |
3128 return NULL; | |
3129 } | |
3130 else | |
3131 { | |
3132 return result; | |
3133 } | |
3134 } | |
3135 | |
3136 | |
3137 /** | |
3138 * @brief Check whether a DICOM instance is associated with some metadata. | |
3139 * | |
3140 * This function checks whether the DICOM instance of interest is | |
3141 * associated with some metadata. As of Orthanc 0.8.1, in the | |
3142 * callbacks registered by | |
3143 * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only | |
3144 * possibly available metadata are "ReceptionDate", "RemoteAET" and | |
3145 * "IndexInSeries". | |
3146 * | |
3147 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3148 * @param instance The instance of interest. | |
3149 * @param metadata The metadata of interest. | |
3150 * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error. | |
3151 * @ingroup DicomInstance | |
3152 **/ | |
3153 ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata( | |
3154 OrthancPluginContext* context, | |
3155 const OrthancPluginDicomInstance* instance, | |
3156 const char* metadata) | |
3157 { | |
3158 int64_t result; | |
3159 | |
3160 _OrthancPluginAccessDicomInstance params; | |
3161 memset(¶ms, 0, sizeof(params)); | |
3162 params.resultInt64 = &result; | |
3163 params.instance = instance; | |
3164 params.key = metadata; | |
3165 | |
3166 if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, ¶ms) != OrthancPluginErrorCode_Success) | |
3167 { | |
3168 /* Error */ | |
3169 return -1; | |
3170 } | |
3171 else | |
3172 { | |
3173 return (result != 0); | |
3174 } | |
3175 } | |
3176 | |
3177 | |
3178 /** | |
3179 * @brief Get the value of some metadata associated with a given DICOM instance. | |
3180 * | |
3181 * This functions returns the value of some metadata that is associated with the DICOM instance of interest. | |
3182 * Before calling this function, the existence of the metadata must have been checked with | |
3183 * ::OrthancPluginHasInstanceMetadata(). | |
3184 * | |
3185 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3186 * @param instance The instance of interest. | |
3187 * @param metadata The metadata of interest. | |
3188 * @return The metadata value if success, NULL if error. Please note that the | |
3189 * returned string belongs to the instance object and must NOT be | |
3190 * deallocated. Please make a copy of the string if you wish to access | |
3191 * it later. | |
3192 * @ingroup DicomInstance | |
3193 **/ | |
3194 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata( | |
3195 OrthancPluginContext* context, | |
3196 const OrthancPluginDicomInstance* instance, | |
3197 const char* metadata) | |
3198 { | |
3199 const char* result; | |
3200 | |
3201 _OrthancPluginAccessDicomInstance params; | |
3202 memset(¶ms, 0, sizeof(params)); | |
3203 params.resultString = &result; | |
3204 params.instance = instance; | |
3205 params.key = metadata; | |
3206 | |
3207 if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, ¶ms) != OrthancPluginErrorCode_Success) | |
3208 { | |
3209 /* Error */ | |
3210 return NULL; | |
3211 } | |
3212 else | |
3213 { | |
3214 return result; | |
3215 } | |
3216 } | |
3217 | |
3218 | |
3219 | |
3220 typedef struct | |
3221 { | |
3222 OrthancPluginStorageCreate create; | |
3223 OrthancPluginStorageRead read; | |
3224 OrthancPluginStorageRemove remove; | |
3225 OrthancPluginFree free; | |
3226 } _OrthancPluginRegisterStorageArea; | |
3227 | |
3228 /** | |
3229 * @brief Register a custom storage area. | |
3230 * | |
3231 * This function registers a custom storage area, to replace the | |
3232 * built-in way Orthanc stores its files on the filesystem. This | |
3233 * function must be called during the initialization of the plugin, | |
3234 * i.e. inside the OrthancPluginInitialize() public function. | |
3235 * | |
3236 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3237 * @param create The callback function to store a file on the custom storage area. | |
3238 * @param read The callback function to read a file from the custom storage area. | |
3239 * @param remove The callback function to remove a file from the custom storage area. | |
3240 * @ingroup Callbacks | |
3241 * @deprecated Please use OrthancPluginRegisterStorageArea2() | |
3242 **/ | |
3243 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea( | |
3244 OrthancPluginContext* context, | |
3245 OrthancPluginStorageCreate create, | |
3246 OrthancPluginStorageRead read, | |
3247 OrthancPluginStorageRemove remove) | |
3248 { | |
3249 _OrthancPluginRegisterStorageArea params; | |
3250 params.create = create; | |
3251 params.read = read; | |
3252 params.remove = remove; | |
3253 | |
3254 #ifdef __cplusplus | |
3255 params.free = ::free; | |
3256 #else | |
3257 params.free = free; | |
3258 #endif | |
3259 | |
3260 context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, ¶ms); | |
3261 } | |
3262 | |
3263 | |
3264 | |
3265 /** | |
3266 * @brief Return the path to the Orthanc executable. | |
3267 * | |
3268 * This function returns the path to the Orthanc executable. | |
3269 * | |
3270 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3271 * @return NULL in the case of an error, or a newly allocated string | |
3272 * containing the path. This string must be freed by | |
3273 * OrthancPluginFreeString(). | |
3274 **/ | |
3275 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context) | |
3276 { | |
3277 char* result; | |
3278 | |
3279 _OrthancPluginRetrieveDynamicString params; | |
3280 params.result = &result; | |
3281 params.argument = NULL; | |
3282 | |
3283 if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, ¶ms) != OrthancPluginErrorCode_Success) | |
3284 { | |
3285 /* Error */ | |
3286 return NULL; | |
3287 } | |
3288 else | |
3289 { | |
3290 return result; | |
3291 } | |
3292 } | |
3293 | |
3294 | |
3295 /** | |
3296 * @brief Return the directory containing the Orthanc. | |
3297 * | |
3298 * This function returns the path to the directory containing the Orthanc executable. | |
3299 * | |
3300 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3301 * @return NULL in the case of an error, or a newly allocated string | |
3302 * containing the path. This string must be freed by | |
3303 * OrthancPluginFreeString(). | |
3304 **/ | |
3305 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context) | |
3306 { | |
3307 char* result; | |
3308 | |
3309 _OrthancPluginRetrieveDynamicString params; | |
3310 params.result = &result; | |
3311 params.argument = NULL; | |
3312 | |
3313 if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, ¶ms) != OrthancPluginErrorCode_Success) | |
3314 { | |
3315 /* Error */ | |
3316 return NULL; | |
3317 } | |
3318 else | |
3319 { | |
3320 return result; | |
3321 } | |
3322 } | |
3323 | |
3324 | |
3325 /** | |
3326 * @brief Return the path to the configuration file(s). | |
3327 * | |
3328 * This function returns the path to the configuration file(s) that | |
3329 * was specified when starting Orthanc. Since version 0.9.1, this | |
3330 * path can refer to a folder that stores a set of configuration | |
3331 * files. This function is deprecated in favor of | |
3332 * OrthancPluginGetConfiguration(). | |
3333 * | |
3334 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3335 * @return NULL in the case of an error, or a newly allocated string | |
3336 * containing the path. This string must be freed by | |
3337 * OrthancPluginFreeString(). | |
3338 * @see OrthancPluginGetConfiguration() | |
3339 **/ | |
3340 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context) | |
3341 { | |
3342 char* result; | |
3343 | |
3344 _OrthancPluginRetrieveDynamicString params; | |
3345 params.result = &result; | |
3346 params.argument = NULL; | |
3347 | |
3348 if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, ¶ms) != OrthancPluginErrorCode_Success) | |
3349 { | |
3350 /* Error */ | |
3351 return NULL; | |
3352 } | |
3353 else | |
3354 { | |
3355 return result; | |
3356 } | |
3357 } | |
3358 | |
3359 | |
3360 | |
3361 typedef struct | |
3362 { | |
3363 OrthancPluginOnChangeCallback callback; | |
3364 } _OrthancPluginOnChangeCallback; | |
3365 | |
3366 /** | |
3367 * @brief Register a callback to monitor changes. | |
3368 * | |
3369 * This function registers a callback function that is called | |
3370 * whenever a change happens to some DICOM resource. | |
3371 * | |
3372 * @warning Your callback function will be called synchronously with | |
3373 * the core of Orthanc. This implies that deadlocks might emerge if | |
3374 * you call other core primitives of Orthanc in your callback (such | |
3375 * deadlocks are particularly visible in the presence of other plugins | |
3376 * or Lua scripts). It is thus strongly advised to avoid any call to | |
3377 * the REST API of Orthanc in the callback. If you have to call | |
3378 * other primitives of Orthanc, you should make these calls in a | |
3379 * separate thread, passing the pending events to be processed | |
3380 * through a message queue. | |
3381 * | |
3382 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3383 * @param callback The callback function. | |
3384 * @ingroup Callbacks | |
3385 **/ | |
3386 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnChangeCallback( | |
3387 OrthancPluginContext* context, | |
3388 OrthancPluginOnChangeCallback callback) | |
3389 { | |
3390 _OrthancPluginOnChangeCallback params; | |
3391 params.callback = callback; | |
3392 | |
3393 context->InvokeService(context, _OrthancPluginService_RegisterOnChangeCallback, ¶ms); | |
3394 } | |
3395 | |
3396 | |
3397 | |
3398 typedef struct | |
3399 { | |
3400 const char* plugin; | |
3401 _OrthancPluginProperty property; | |
3402 const char* value; | |
3403 } _OrthancPluginSetPluginProperty; | |
3404 | |
3405 | |
3406 /** | |
3407 * @brief Set the URI where the plugin provides its Web interface. | |
3408 * | |
3409 * For plugins that come with a Web interface, this function | |
3410 * declares the entry path where to find this interface. This | |
3411 * information is notably used in the "Plugins" page of Orthanc | |
3412 * Explorer. | |
3413 * | |
3414 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3415 * @param uri The root URI for this plugin. | |
3416 **/ | |
3417 ORTHANC_PLUGIN_INLINE void OrthancPluginSetRootUri( | |
3418 OrthancPluginContext* context, | |
3419 const char* uri) | |
3420 { | |
3421 _OrthancPluginSetPluginProperty params; | |
3422 params.plugin = OrthancPluginGetName(); | |
3423 params.property = _OrthancPluginProperty_RootUri; | |
3424 params.value = uri; | |
3425 | |
3426 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); | |
3427 } | |
3428 | |
3429 | |
3430 /** | |
3431 * @brief Set a description for this plugin. | |
3432 * | |
3433 * Set a description for this plugin. It is displayed in the | |
3434 * "Plugins" page of Orthanc Explorer. | |
3435 * | |
3436 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3437 * @param description The description. | |
3438 **/ | |
3439 ORTHANC_PLUGIN_INLINE void OrthancPluginSetDescription( | |
3440 OrthancPluginContext* context, | |
3441 const char* description) | |
3442 { | |
3443 _OrthancPluginSetPluginProperty params; | |
3444 params.plugin = OrthancPluginGetName(); | |
3445 params.property = _OrthancPluginProperty_Description; | |
3446 params.value = description; | |
3447 | |
3448 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); | |
3449 } | |
3450 | |
3451 | |
3452 /** | |
3453 * @brief Extend the JavaScript code of Orthanc Explorer. | |
3454 * | |
3455 * Add JavaScript code to customize the default behavior of Orthanc | |
3456 * Explorer. This can for instance be used to add new buttons. | |
3457 * | |
3458 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3459 * @param javascript The custom JavaScript code. | |
3460 **/ | |
3461 ORTHANC_PLUGIN_INLINE void OrthancPluginExtendOrthancExplorer( | |
3462 OrthancPluginContext* context, | |
3463 const char* javascript) | |
3464 { | |
3465 _OrthancPluginSetPluginProperty params; | |
3466 params.plugin = OrthancPluginGetName(); | |
3467 params.property = _OrthancPluginProperty_OrthancExplorer; | |
3468 params.value = javascript; | |
3469 | |
3470 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); | |
3471 } | |
3472 | |
3473 | |
3474 typedef struct | |
3475 { | |
3476 char** result; | |
3477 int32_t property; | |
3478 const char* value; | |
3479 } _OrthancPluginGlobalProperty; | |
3480 | |
3481 | |
3482 /** | |
3483 * @brief Get the value of a global property. | |
3484 * | |
3485 * Get the value of a global property that is stored in the Orthanc database. Global | |
3486 * properties whose index is below 1024 are reserved by Orthanc. | |
3487 * | |
3488 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3489 * @param property The global property of interest. | |
3490 * @param defaultValue The value to return, if the global property is unset. | |
3491 * @return The value of the global property, or NULL in the case of an error. This | |
3492 * string must be freed by OrthancPluginFreeString(). | |
3493 * @ingroup Orthanc | |
3494 **/ | |
3495 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetGlobalProperty( | |
3496 OrthancPluginContext* context, | |
3497 int32_t property, | |
3498 const char* defaultValue) | |
3499 { | |
3500 char* result; | |
3501 | |
3502 _OrthancPluginGlobalProperty params; | |
3503 params.result = &result; | |
3504 params.property = property; | |
3505 params.value = defaultValue; | |
3506 | |
3507 if (context->InvokeService(context, _OrthancPluginService_GetGlobalProperty, ¶ms) != OrthancPluginErrorCode_Success) | |
3508 { | |
3509 /* Error */ | |
3510 return NULL; | |
3511 } | |
3512 else | |
3513 { | |
3514 return result; | |
3515 } | |
3516 } | |
3517 | |
3518 | |
3519 /** | |
3520 * @brief Set the value of a global property. | |
3521 * | |
3522 * Set the value of a global property into the Orthanc | |
3523 * database. Setting a global property can be used by plugins to | |
3524 * save their internal parameters. Plugins are only allowed to set | |
3525 * properties whose index are above or equal to 1024 (properties | |
3526 * below 1024 are read-only and reserved by Orthanc). | |
3527 * | |
3528 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3529 * @param property The global property of interest. | |
3530 * @param value The value to be set in the global property. | |
3531 * @return 0 if success, or the error code if failure. | |
3532 * @ingroup Orthanc | |
3533 **/ | |
3534 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetGlobalProperty( | |
3535 OrthancPluginContext* context, | |
3536 int32_t property, | |
3537 const char* value) | |
3538 { | |
3539 _OrthancPluginGlobalProperty params; | |
3540 params.result = NULL; | |
3541 params.property = property; | |
3542 params.value = value; | |
3543 | |
3544 return context->InvokeService(context, _OrthancPluginService_SetGlobalProperty, ¶ms); | |
3545 } | |
3546 | |
3547 | |
3548 | |
3549 typedef struct | |
3550 { | |
3551 int32_t *resultInt32; | |
3552 uint32_t *resultUint32; | |
3553 int64_t *resultInt64; | |
3554 uint64_t *resultUint64; | |
3555 } _OrthancPluginReturnSingleValue; | |
3556 | |
3557 /** | |
3558 * @brief Get the number of command-line arguments. | |
3559 * | |
3560 * Retrieve the number of command-line arguments that were used to launch Orthanc. | |
3561 * | |
3562 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3563 * @return The number of arguments. | |
3564 **/ | |
3565 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetCommandLineArgumentsCount( | |
3566 OrthancPluginContext* context) | |
3567 { | |
3568 uint32_t count = 0; | |
3569 | |
3570 _OrthancPluginReturnSingleValue params; | |
3571 memset(¶ms, 0, sizeof(params)); | |
3572 params.resultUint32 = &count; | |
3573 | |
3574 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgumentsCount, ¶ms) != OrthancPluginErrorCode_Success) | |
3575 { | |
3576 /* Error */ | |
3577 return 0; | |
3578 } | |
3579 else | |
3580 { | |
3581 return count; | |
3582 } | |
3583 } | |
3584 | |
3585 | |
3586 | |
3587 /** | |
3588 * @brief Get the value of a command-line argument. | |
3589 * | |
3590 * Get the value of one of the command-line arguments that were used | |
3591 * to launch Orthanc. The number of available arguments can be | |
3592 * retrieved by OrthancPluginGetCommandLineArgumentsCount(). | |
3593 * | |
3594 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3595 * @param argument The index of the argument. | |
3596 * @return The value of the argument, or NULL in the case of an error. This | |
3597 * string must be freed by OrthancPluginFreeString(). | |
3598 **/ | |
3599 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetCommandLineArgument( | |
3600 OrthancPluginContext* context, | |
3601 uint32_t argument) | |
3602 { | |
3603 char* result; | |
3604 | |
3605 _OrthancPluginGlobalProperty params; | |
3606 params.result = &result; | |
3607 params.property = (int32_t) argument; | |
3608 params.value = NULL; | |
3609 | |
3610 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgument, ¶ms) != OrthancPluginErrorCode_Success) | |
3611 { | |
3612 /* Error */ | |
3613 return NULL; | |
3614 } | |
3615 else | |
3616 { | |
3617 return result; | |
3618 } | |
3619 } | |
3620 | |
3621 | |
3622 /** | |
3623 * @brief Get the expected version of the database schema. | |
3624 * | |
3625 * Retrieve the expected version of the database schema. | |
3626 * | |
3627 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3628 * @return The version. | |
3629 * @ingroup Callbacks | |
3630 **/ | |
3631 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion( | |
3632 OrthancPluginContext* context) | |
3633 { | |
3634 uint32_t count = 0; | |
3635 | |
3636 _OrthancPluginReturnSingleValue params; | |
3637 memset(¶ms, 0, sizeof(params)); | |
3638 params.resultUint32 = &count; | |
3639 | |
3640 if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, ¶ms) != OrthancPluginErrorCode_Success) | |
3641 { | |
3642 /* Error */ | |
3643 return 0; | |
3644 } | |
3645 else | |
3646 { | |
3647 return count; | |
3648 } | |
3649 } | |
3650 | |
3651 | |
3652 | |
3653 /** | |
3654 * @brief Return the content of the configuration file(s). | |
3655 * | |
3656 * This function returns the content of the configuration that is | |
3657 * used by Orthanc, formatted as a JSON string. | |
3658 * | |
3659 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3660 * @return NULL in the case of an error, or a newly allocated string | |
3661 * containing the configuration. This string must be freed by | |
3662 * OrthancPluginFreeString(). | |
3663 **/ | |
3664 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfiguration(OrthancPluginContext* context) | |
3665 { | |
3666 char* result; | |
3667 | |
3668 _OrthancPluginRetrieveDynamicString params; | |
3669 params.result = &result; | |
3670 params.argument = NULL; | |
3671 | |
3672 if (context->InvokeService(context, _OrthancPluginService_GetConfiguration, ¶ms) != OrthancPluginErrorCode_Success) | |
3673 { | |
3674 /* Error */ | |
3675 return NULL; | |
3676 } | |
3677 else | |
3678 { | |
3679 return result; | |
3680 } | |
3681 } | |
3682 | |
3683 | |
3684 | |
3685 typedef struct | |
3686 { | |
3687 OrthancPluginRestOutput* output; | |
3688 const char* subType; | |
3689 const char* contentType; | |
3690 } _OrthancPluginStartMultipartAnswer; | |
3691 | |
3692 /** | |
3693 * @brief Start an HTTP multipart answer. | |
3694 * | |
3695 * Initiates a HTTP multipart answer, as the result of a REST request. | |
3696 * | |
3697 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3698 * @param output The HTTP connection to the client application. | |
3699 * @param subType The sub-type of the multipart answer ("mixed" or "related"). | |
3700 * @param contentType The MIME type of the items in the multipart answer. | |
3701 * @return 0 if success, or the error code if failure. | |
3702 * @see OrthancPluginSendMultipartItem(), OrthancPluginSendMultipartItem2() | |
3703 * @ingroup REST | |
3704 **/ | |
3705 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStartMultipartAnswer( | |
3706 OrthancPluginContext* context, | |
3707 OrthancPluginRestOutput* output, | |
3708 const char* subType, | |
3709 const char* contentType) | |
3710 { | |
3711 _OrthancPluginStartMultipartAnswer params; | |
3712 params.output = output; | |
3713 params.subType = subType; | |
3714 params.contentType = contentType; | |
3715 return context->InvokeService(context, _OrthancPluginService_StartMultipartAnswer, ¶ms); | |
3716 } | |
3717 | |
3718 | |
3719 /** | |
3720 * @brief Send an item as a part of some HTTP multipart answer. | |
3721 * | |
3722 * This function sends an item as a part of some HTTP multipart | |
3723 * answer that was initiated by OrthancPluginStartMultipartAnswer(). | |
3724 * | |
3725 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3726 * @param output The HTTP connection to the client application. | |
3727 * @param answer Pointer to the memory buffer containing the item. | |
3728 * @param answerSize Number of bytes of the item. | |
3729 * @return 0 if success, or the error code if failure (this notably happens | |
3730 * if the connection is closed by the client). | |
3731 * @see OrthancPluginSendMultipartItem2() | |
3732 * @ingroup REST | |
3733 **/ | |
3734 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem( | |
3735 OrthancPluginContext* context, | |
3736 OrthancPluginRestOutput* output, | |
3737 const void* answer, | |
3738 uint32_t answerSize) | |
3739 { | |
3740 _OrthancPluginAnswerBuffer params; | |
3741 params.output = output; | |
3742 params.answer = answer; | |
3743 params.answerSize = answerSize; | |
3744 params.mimeType = NULL; | |
3745 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem, ¶ms); | |
3746 } | |
3747 | |
3748 | |
3749 | |
3750 typedef struct | |
3751 { | |
3752 OrthancPluginMemoryBuffer* target; | |
3753 const void* source; | |
3754 uint32_t size; | |
3755 OrthancPluginCompressionType compression; | |
3756 uint8_t uncompress; | |
3757 } _OrthancPluginBufferCompression; | |
3758 | |
3759 | |
3760 /** | |
3761 * @brief Compress or decompress a buffer. | |
3762 * | |
3763 * This function compresses or decompresses a buffer, using the | |
3764 * version of the zlib library that is used by the Orthanc core. | |
3765 * | |
3766 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3767 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3768 * @param source The source buffer. | |
3769 * @param size The size in bytes of the source buffer. | |
3770 * @param compression The compression algorithm. | |
3771 * @param uncompress If set to "0", the buffer must be compressed. | |
3772 * If set to "1", the buffer must be uncompressed. | |
3773 * @return 0 if success, or the error code if failure. | |
3774 * @ingroup Images | |
3775 **/ | |
3776 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginBufferCompression( | |
3777 OrthancPluginContext* context, | |
3778 OrthancPluginMemoryBuffer* target, | |
3779 const void* source, | |
3780 uint32_t size, | |
3781 OrthancPluginCompressionType compression, | |
3782 uint8_t uncompress) | |
3783 { | |
3784 _OrthancPluginBufferCompression params; | |
3785 params.target = target; | |
3786 params.source = source; | |
3787 params.size = size; | |
3788 params.compression = compression; | |
3789 params.uncompress = uncompress; | |
3790 | |
3791 return context->InvokeService(context, _OrthancPluginService_BufferCompression, ¶ms); | |
3792 } | |
3793 | |
3794 | |
3795 | |
3796 typedef struct | |
3797 { | |
3798 OrthancPluginMemoryBuffer* target; | |
3799 const char* path; | |
3800 } _OrthancPluginReadFile; | |
3801 | |
3802 /** | |
3803 * @brief Read a file. | |
3804 * | |
3805 * Read the content of a file on the filesystem, and returns it into | |
3806 * a newly allocated memory buffer. | |
3807 * | |
3808 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3809 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
3810 * @param path The path of the file to be read. | |
3811 * @return 0 if success, or the error code if failure. | |
3812 **/ | |
3813 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReadFile( | |
3814 OrthancPluginContext* context, | |
3815 OrthancPluginMemoryBuffer* target, | |
3816 const char* path) | |
3817 { | |
3818 _OrthancPluginReadFile params; | |
3819 params.target = target; | |
3820 params.path = path; | |
3821 return context->InvokeService(context, _OrthancPluginService_ReadFile, ¶ms); | |
3822 } | |
3823 | |
3824 | |
3825 | |
3826 typedef struct | |
3827 { | |
3828 const char* path; | |
3829 const void* data; | |
3830 uint32_t size; | |
3831 } _OrthancPluginWriteFile; | |
3832 | |
3833 /** | |
3834 * @brief Write a file. | |
3835 * | |
3836 * Write the content of a memory buffer to the filesystem. | |
3837 * | |
3838 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3839 * @param path The path of the file to be written. | |
3840 * @param data The content of the memory buffer. | |
3841 * @param size The size of the memory buffer. | |
3842 * @return 0 if success, or the error code if failure. | |
3843 **/ | |
3844 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWriteFile( | |
3845 OrthancPluginContext* context, | |
3846 const char* path, | |
3847 const void* data, | |
3848 uint32_t size) | |
3849 { | |
3850 _OrthancPluginWriteFile params; | |
3851 params.path = path; | |
3852 params.data = data; | |
3853 params.size = size; | |
3854 return context->InvokeService(context, _OrthancPluginService_WriteFile, ¶ms); | |
3855 } | |
3856 | |
3857 | |
3858 | |
3859 typedef struct | |
3860 { | |
3861 const char** target; | |
3862 OrthancPluginErrorCode error; | |
3863 } _OrthancPluginGetErrorDescription; | |
3864 | |
3865 /** | |
3866 * @brief Get the description of a given error code. | |
3867 * | |
3868 * This function returns the description of a given error code. | |
3869 * | |
3870 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3871 * @param error The error code of interest. | |
3872 * @return The error description. This is a statically-allocated | |
3873 * string, do not free it. | |
3874 **/ | |
3875 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetErrorDescription( | |
3876 OrthancPluginContext* context, | |
3877 OrthancPluginErrorCode error) | |
3878 { | |
3879 const char* result = NULL; | |
3880 | |
3881 _OrthancPluginGetErrorDescription params; | |
3882 params.target = &result; | |
3883 params.error = error; | |
3884 | |
3885 if (context->InvokeService(context, _OrthancPluginService_GetErrorDescription, ¶ms) != OrthancPluginErrorCode_Success || | |
3886 result == NULL) | |
3887 { | |
3888 return "Unknown error code"; | |
3889 } | |
3890 else | |
3891 { | |
3892 return result; | |
3893 } | |
3894 } | |
3895 | |
3896 | |
3897 | |
3898 typedef struct | |
3899 { | |
3900 OrthancPluginRestOutput* output; | |
3901 uint16_t status; | |
3902 const void* body; | |
3903 uint32_t bodySize; | |
3904 } _OrthancPluginSendHttpStatus; | |
3905 | |
3906 /** | |
3907 * @brief Send a HTTP status, with a custom body. | |
3908 * | |
3909 * This function answers to a HTTP request by sending a HTTP status | |
3910 * code (such as "400 - Bad Request"), together with a body | |
3911 * describing the error. The body will only be returned if the | |
3912 * configuration option "HttpDescribeErrors" of Orthanc is set to "true". | |
3913 * | |
3914 * Note that: | |
3915 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). | |
3916 * - Redirections (status 301) must use ::OrthancPluginRedirect(). | |
3917 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). | |
3918 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed(). | |
3919 * | |
3920 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3921 * @param output The HTTP connection to the client application. | |
3922 * @param status The HTTP status code to be sent. | |
3923 * @param body The body of the answer. | |
3924 * @param bodySize The size of the body. | |
3925 * @see OrthancPluginSendHttpStatusCode() | |
3926 * @ingroup REST | |
3927 **/ | |
3928 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatus( | |
3929 OrthancPluginContext* context, | |
3930 OrthancPluginRestOutput* output, | |
3931 uint16_t status, | |
3932 const void* body, | |
3933 uint32_t bodySize) | |
3934 { | |
3935 _OrthancPluginSendHttpStatus params; | |
3936 params.output = output; | |
3937 params.status = status; | |
3938 params.body = body; | |
3939 params.bodySize = bodySize; | |
3940 context->InvokeService(context, _OrthancPluginService_SendHttpStatus, ¶ms); | |
3941 } | |
3942 | |
3943 | |
3944 | |
3945 typedef struct | |
3946 { | |
3947 const OrthancPluginImage* image; | |
3948 uint32_t* resultUint32; | |
3949 OrthancPluginPixelFormat* resultPixelFormat; | |
3950 void** resultBuffer; | |
3951 } _OrthancPluginGetImageInfo; | |
3952 | |
3953 | |
3954 /** | |
3955 * @brief Return the pixel format of an image. | |
3956 * | |
3957 * This function returns the type of memory layout for the pixels of the given image. | |
3958 * | |
3959 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3960 * @param image The image of interest. | |
3961 * @return The pixel format. | |
3962 * @ingroup Images | |
3963 **/ | |
3964 ORTHANC_PLUGIN_INLINE OrthancPluginPixelFormat OrthancPluginGetImagePixelFormat( | |
3965 OrthancPluginContext* context, | |
3966 const OrthancPluginImage* image) | |
3967 { | |
3968 OrthancPluginPixelFormat target; | |
3969 | |
3970 _OrthancPluginGetImageInfo params; | |
3971 memset(¶ms, 0, sizeof(params)); | |
3972 params.image = image; | |
3973 params.resultPixelFormat = ⌖ | |
3974 | |
3975 if (context->InvokeService(context, _OrthancPluginService_GetImagePixelFormat, ¶ms) != OrthancPluginErrorCode_Success) | |
3976 { | |
3977 return OrthancPluginPixelFormat_Unknown; | |
3978 } | |
3979 else | |
3980 { | |
3981 return (OrthancPluginPixelFormat) target; | |
3982 } | |
3983 } | |
3984 | |
3985 | |
3986 | |
3987 /** | |
3988 * @brief Return the width of an image. | |
3989 * | |
3990 * This function returns the width of the given image. | |
3991 * | |
3992 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
3993 * @param image The image of interest. | |
3994 * @return The width. | |
3995 * @ingroup Images | |
3996 **/ | |
3997 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageWidth( | |
3998 OrthancPluginContext* context, | |
3999 const OrthancPluginImage* image) | |
4000 { | |
4001 uint32_t width; | |
4002 | |
4003 _OrthancPluginGetImageInfo params; | |
4004 memset(¶ms, 0, sizeof(params)); | |
4005 params.image = image; | |
4006 params.resultUint32 = &width; | |
4007 | |
4008 if (context->InvokeService(context, _OrthancPluginService_GetImageWidth, ¶ms) != OrthancPluginErrorCode_Success) | |
4009 { | |
4010 return 0; | |
4011 } | |
4012 else | |
4013 { | |
4014 return width; | |
4015 } | |
4016 } | |
4017 | |
4018 | |
4019 | |
4020 /** | |
4021 * @brief Return the height of an image. | |
4022 * | |
4023 * This function returns the height of the given image. | |
4024 * | |
4025 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4026 * @param image The image of interest. | |
4027 * @return The height. | |
4028 * @ingroup Images | |
4029 **/ | |
4030 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageHeight( | |
4031 OrthancPluginContext* context, | |
4032 const OrthancPluginImage* image) | |
4033 { | |
4034 uint32_t height; | |
4035 | |
4036 _OrthancPluginGetImageInfo params; | |
4037 memset(¶ms, 0, sizeof(params)); | |
4038 params.image = image; | |
4039 params.resultUint32 = &height; | |
4040 | |
4041 if (context->InvokeService(context, _OrthancPluginService_GetImageHeight, ¶ms) != OrthancPluginErrorCode_Success) | |
4042 { | |
4043 return 0; | |
4044 } | |
4045 else | |
4046 { | |
4047 return height; | |
4048 } | |
4049 } | |
4050 | |
4051 | |
4052 | |
4053 /** | |
4054 * @brief Return the pitch of an image. | |
4055 * | |
4056 * This function returns the pitch of the given image. The pitch is | |
4057 * defined as the number of bytes between 2 successive lines of the | |
4058 * image in the memory buffer. | |
4059 * | |
4060 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4061 * @param image The image of interest. | |
4062 * @return The pitch. | |
4063 * @ingroup Images | |
4064 **/ | |
4065 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImagePitch( | |
4066 OrthancPluginContext* context, | |
4067 const OrthancPluginImage* image) | |
4068 { | |
4069 uint32_t pitch; | |
4070 | |
4071 _OrthancPluginGetImageInfo params; | |
4072 memset(¶ms, 0, sizeof(params)); | |
4073 params.image = image; | |
4074 params.resultUint32 = &pitch; | |
4075 | |
4076 if (context->InvokeService(context, _OrthancPluginService_GetImagePitch, ¶ms) != OrthancPluginErrorCode_Success) | |
4077 { | |
4078 return 0; | |
4079 } | |
4080 else | |
4081 { | |
4082 return pitch; | |
4083 } | |
4084 } | |
4085 | |
4086 | |
4087 | |
4088 /** | |
4089 * @brief Return a pointer to the content of an image. | |
4090 * | |
4091 * This function returns a pointer to the memory buffer that | |
4092 * contains the pixels of the image. | |
4093 * | |
4094 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4095 * @param image The image of interest. | |
4096 * @return The pointer. | |
4097 * @ingroup Images | |
4098 **/ | |
4099 ORTHANC_PLUGIN_INLINE void* OrthancPluginGetImageBuffer( | |
4100 OrthancPluginContext* context, | |
4101 const OrthancPluginImage* image) | |
4102 { | |
4103 void* target = NULL; | |
4104 | |
4105 _OrthancPluginGetImageInfo params; | |
4106 memset(¶ms, 0, sizeof(params)); | |
4107 params.resultBuffer = ⌖ | |
4108 params.image = image; | |
4109 | |
4110 if (context->InvokeService(context, _OrthancPluginService_GetImageBuffer, ¶ms) != OrthancPluginErrorCode_Success) | |
4111 { | |
4112 return NULL; | |
4113 } | |
4114 else | |
4115 { | |
4116 return target; | |
4117 } | |
4118 } | |
4119 | |
4120 | |
4121 typedef struct | |
4122 { | |
4123 OrthancPluginImage** target; | |
4124 const void* data; | |
4125 uint32_t size; | |
4126 OrthancPluginImageFormat format; | |
4127 } _OrthancPluginUncompressImage; | |
4128 | |
4129 | |
4130 /** | |
4131 * @brief Decode a compressed image. | |
4132 * | |
4133 * This function decodes a compressed image from a memory buffer. | |
4134 * | |
4135 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4136 * @param data Pointer to a memory buffer containing the compressed image. | |
4137 * @param size Size of the memory buffer containing the compressed image. | |
4138 * @param format The file format of the compressed image. | |
4139 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage(). | |
4140 * @ingroup Images | |
4141 **/ | |
4142 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginUncompressImage( | |
4143 OrthancPluginContext* context, | |
4144 const void* data, | |
4145 uint32_t size, | |
4146 OrthancPluginImageFormat format) | |
4147 { | |
4148 OrthancPluginImage* target = NULL; | |
4149 | |
4150 _OrthancPluginUncompressImage params; | |
4151 memset(¶ms, 0, sizeof(params)); | |
4152 params.target = ⌖ | |
4153 params.data = data; | |
4154 params.size = size; | |
4155 params.format = format; | |
4156 | |
4157 if (context->InvokeService(context, _OrthancPluginService_UncompressImage, ¶ms) != OrthancPluginErrorCode_Success) | |
4158 { | |
4159 return NULL; | |
4160 } | |
4161 else | |
4162 { | |
4163 return target; | |
4164 } | |
4165 } | |
4166 | |
4167 | |
4168 | |
4169 | |
4170 typedef struct | |
4171 { | |
4172 OrthancPluginImage* image; | |
4173 } _OrthancPluginFreeImage; | |
4174 | |
4175 /** | |
4176 * @brief Free an image. | |
4177 * | |
4178 * This function frees an image that was decoded with OrthancPluginUncompressImage(). | |
4179 * | |
4180 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4181 * @param image The image. | |
4182 * @ingroup Images | |
4183 **/ | |
4184 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeImage( | |
4185 OrthancPluginContext* context, | |
4186 OrthancPluginImage* image) | |
4187 { | |
4188 _OrthancPluginFreeImage params; | |
4189 params.image = image; | |
4190 | |
4191 context->InvokeService(context, _OrthancPluginService_FreeImage, ¶ms); | |
4192 } | |
4193 | |
4194 | |
4195 | |
4196 | |
4197 typedef struct | |
4198 { | |
4199 OrthancPluginMemoryBuffer* target; | |
4200 OrthancPluginImageFormat imageFormat; | |
4201 OrthancPluginPixelFormat pixelFormat; | |
4202 uint32_t width; | |
4203 uint32_t height; | |
4204 uint32_t pitch; | |
4205 const void* buffer; | |
4206 uint8_t quality; | |
4207 } _OrthancPluginCompressImage; | |
4208 | |
4209 | |
4210 /** | |
4211 * @brief Encode a PNG image. | |
4212 * | |
4213 * This function compresses the given memory buffer containing an | |
4214 * image using the PNG specification, and stores the result of the | |
4215 * compression into a newly allocated memory buffer. | |
4216 * | |
4217 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4218 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4219 * @param format The memory layout of the uncompressed image. | |
4220 * @param width The width of the image. | |
4221 * @param height The height of the image. | |
4222 * @param pitch The pitch of the image (i.e. the number of bytes | |
4223 * between 2 successive lines of the image in the memory buffer). | |
4224 * @param buffer The memory buffer containing the uncompressed image. | |
4225 * @return 0 if success, or the error code if failure. | |
4226 * @see OrthancPluginCompressAndAnswerPngImage() | |
4227 * @ingroup Images | |
4228 **/ | |
4229 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressPngImage( | |
4230 OrthancPluginContext* context, | |
4231 OrthancPluginMemoryBuffer* target, | |
4232 OrthancPluginPixelFormat format, | |
4233 uint32_t width, | |
4234 uint32_t height, | |
4235 uint32_t pitch, | |
4236 const void* buffer) | |
4237 { | |
4238 _OrthancPluginCompressImage params; | |
4239 memset(¶ms, 0, sizeof(params)); | |
4240 params.target = target; | |
4241 params.imageFormat = OrthancPluginImageFormat_Png; | |
4242 params.pixelFormat = format; | |
4243 params.width = width; | |
4244 params.height = height; | |
4245 params.pitch = pitch; | |
4246 params.buffer = buffer; | |
4247 params.quality = 0; /* Unused for PNG */ | |
4248 | |
4249 return context->InvokeService(context, _OrthancPluginService_CompressImage, ¶ms); | |
4250 } | |
4251 | |
4252 | |
4253 /** | |
4254 * @brief Encode a JPEG image. | |
4255 * | |
4256 * This function compresses the given memory buffer containing an | |
4257 * image using the JPEG specification, and stores the result of the | |
4258 * compression into a newly allocated memory buffer. | |
4259 * | |
4260 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4261 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4262 * @param format The memory layout of the uncompressed image. | |
4263 * @param width The width of the image. | |
4264 * @param height The height of the image. | |
4265 * @param pitch The pitch of the image (i.e. the number of bytes | |
4266 * between 2 successive lines of the image in the memory buffer). | |
4267 * @param buffer The memory buffer containing the uncompressed image. | |
4268 * @param quality The quality of the JPEG encoding, between 1 (worst | |
4269 * quality, best compression) and 100 (best quality, worst | |
4270 * compression). | |
4271 * @return 0 if success, or the error code if failure. | |
4272 * @ingroup Images | |
4273 **/ | |
4274 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressJpegImage( | |
4275 OrthancPluginContext* context, | |
4276 OrthancPluginMemoryBuffer* target, | |
4277 OrthancPluginPixelFormat format, | |
4278 uint32_t width, | |
4279 uint32_t height, | |
4280 uint32_t pitch, | |
4281 const void* buffer, | |
4282 uint8_t quality) | |
4283 { | |
4284 _OrthancPluginCompressImage params; | |
4285 memset(¶ms, 0, sizeof(params)); | |
4286 params.target = target; | |
4287 params.imageFormat = OrthancPluginImageFormat_Jpeg; | |
4288 params.pixelFormat = format; | |
4289 params.width = width; | |
4290 params.height = height; | |
4291 params.pitch = pitch; | |
4292 params.buffer = buffer; | |
4293 params.quality = quality; | |
4294 | |
4295 return context->InvokeService(context, _OrthancPluginService_CompressImage, ¶ms); | |
4296 } | |
4297 | |
4298 | |
4299 | |
4300 /** | |
4301 * @brief Answer to a REST request with a JPEG image. | |
4302 * | |
4303 * This function answers to a REST request with a JPEG image. The | |
4304 * parameters of this function describe a memory buffer that | |
4305 * contains an uncompressed image. The image will be automatically compressed | |
4306 * as a JPEG image by the core system of Orthanc. | |
4307 * | |
4308 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4309 * @param output The HTTP connection to the client application. | |
4310 * @param format The memory layout of the uncompressed image. | |
4311 * @param width The width of the image. | |
4312 * @param height The height of the image. | |
4313 * @param pitch The pitch of the image (i.e. the number of bytes | |
4314 * between 2 successive lines of the image in the memory buffer). | |
4315 * @param buffer The memory buffer containing the uncompressed image. | |
4316 * @param quality The quality of the JPEG encoding, between 1 (worst | |
4317 * quality, best compression) and 100 (best quality, worst | |
4318 * compression). | |
4319 * @ingroup REST | |
4320 **/ | |
4321 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerJpegImage( | |
4322 OrthancPluginContext* context, | |
4323 OrthancPluginRestOutput* output, | |
4324 OrthancPluginPixelFormat format, | |
4325 uint32_t width, | |
4326 uint32_t height, | |
4327 uint32_t pitch, | |
4328 const void* buffer, | |
4329 uint8_t quality) | |
4330 { | |
4331 _OrthancPluginCompressAndAnswerImage params; | |
4332 params.output = output; | |
4333 params.imageFormat = OrthancPluginImageFormat_Jpeg; | |
4334 params.pixelFormat = format; | |
4335 params.width = width; | |
4336 params.height = height; | |
4337 params.pitch = pitch; | |
4338 params.buffer = buffer; | |
4339 params.quality = quality; | |
4340 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, ¶ms); | |
4341 } | |
4342 | |
4343 | |
4344 | |
4345 | |
4346 typedef struct | |
4347 { | |
4348 OrthancPluginMemoryBuffer* target; | |
4349 OrthancPluginHttpMethod method; | |
4350 const char* url; | |
4351 const char* username; | |
4352 const char* password; | |
4353 const void* body; | |
4354 uint32_t bodySize; | |
4355 } _OrthancPluginCallHttpClient; | |
4356 | |
4357 | |
4358 /** | |
4359 * @brief Issue a HTTP GET call. | |
4360 * | |
4361 * Make a HTTP GET call to the given URL. The result to the query is | |
4362 * stored into a newly allocated memory buffer. Favor | |
4363 * OrthancPluginRestApiGet() if calling the built-in REST API of the | |
4364 * Orthanc instance that hosts this plugin. | |
4365 * | |
4366 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4367 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4368 * @param url The URL of interest. | |
4369 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
4370 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
4371 * @return 0 if success, or the error code if failure. | |
4372 * @ingroup Toolbox | |
4373 **/ | |
4374 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpGet( | |
4375 OrthancPluginContext* context, | |
4376 OrthancPluginMemoryBuffer* target, | |
4377 const char* url, | |
4378 const char* username, | |
4379 const char* password) | |
4380 { | |
4381 _OrthancPluginCallHttpClient params; | |
4382 memset(¶ms, 0, sizeof(params)); | |
4383 | |
4384 params.target = target; | |
4385 params.method = OrthancPluginHttpMethod_Get; | |
4386 params.url = url; | |
4387 params.username = username; | |
4388 params.password = password; | |
4389 | |
4390 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
4391 } | |
4392 | |
4393 | |
4394 /** | |
4395 * @brief Issue a HTTP POST call. | |
4396 * | |
4397 * Make a HTTP POST call to the given URL. The result to the query | |
4398 * is stored into a newly allocated memory buffer. Favor | |
4399 * OrthancPluginRestApiPost() if calling the built-in REST API of | |
4400 * the Orthanc instance that hosts this plugin. | |
4401 * | |
4402 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4403 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4404 * @param url The URL of interest. | |
4405 * @param body The content of the body of the request. | |
4406 * @param bodySize The size of the body of the request. | |
4407 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
4408 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
4409 * @return 0 if success, or the error code if failure. | |
4410 * @ingroup Toolbox | |
4411 **/ | |
4412 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPost( | |
4413 OrthancPluginContext* context, | |
4414 OrthancPluginMemoryBuffer* target, | |
4415 const char* url, | |
4416 const void* body, | |
4417 uint32_t bodySize, | |
4418 const char* username, | |
4419 const char* password) | |
4420 { | |
4421 _OrthancPluginCallHttpClient params; | |
4422 memset(¶ms, 0, sizeof(params)); | |
4423 | |
4424 params.target = target; | |
4425 params.method = OrthancPluginHttpMethod_Post; | |
4426 params.url = url; | |
4427 params.body = body; | |
4428 params.bodySize = bodySize; | |
4429 params.username = username; | |
4430 params.password = password; | |
4431 | |
4432 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
4433 } | |
4434 | |
4435 | |
4436 /** | |
4437 * @brief Issue a HTTP PUT call. | |
4438 * | |
4439 * Make a HTTP PUT call to the given URL. The result to the query is | |
4440 * stored into a newly allocated memory buffer. Favor | |
4441 * OrthancPluginRestApiPut() if calling the built-in REST API of the | |
4442 * Orthanc instance that hosts this plugin. | |
4443 * | |
4444 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4445 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4446 * @param url The URL of interest. | |
4447 * @param body The content of the body of the request. | |
4448 * @param bodySize The size of the body of the request. | |
4449 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
4450 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
4451 * @return 0 if success, or the error code if failure. | |
4452 * @ingroup Toolbox | |
4453 **/ | |
4454 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPut( | |
4455 OrthancPluginContext* context, | |
4456 OrthancPluginMemoryBuffer* target, | |
4457 const char* url, | |
4458 const void* body, | |
4459 uint32_t bodySize, | |
4460 const char* username, | |
4461 const char* password) | |
4462 { | |
4463 _OrthancPluginCallHttpClient params; | |
4464 memset(¶ms, 0, sizeof(params)); | |
4465 | |
4466 params.target = target; | |
4467 params.method = OrthancPluginHttpMethod_Put; | |
4468 params.url = url; | |
4469 params.body = body; | |
4470 params.bodySize = bodySize; | |
4471 params.username = username; | |
4472 params.password = password; | |
4473 | |
4474 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
4475 } | |
4476 | |
4477 | |
4478 /** | |
4479 * @brief Issue a HTTP DELETE call. | |
4480 * | |
4481 * Make a HTTP DELETE call to the given URL. Favor | |
4482 * OrthancPluginRestApiDelete() if calling the built-in REST API of | |
4483 * the Orthanc instance that hosts this plugin. | |
4484 * | |
4485 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4486 * @param url The URL of interest. | |
4487 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
4488 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
4489 * @return 0 if success, or the error code if failure. | |
4490 * @ingroup Toolbox | |
4491 **/ | |
4492 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpDelete( | |
4493 OrthancPluginContext* context, | |
4494 const char* url, | |
4495 const char* username, | |
4496 const char* password) | |
4497 { | |
4498 _OrthancPluginCallHttpClient params; | |
4499 memset(¶ms, 0, sizeof(params)); | |
4500 | |
4501 params.method = OrthancPluginHttpMethod_Delete; | |
4502 params.url = url; | |
4503 params.username = username; | |
4504 params.password = password; | |
4505 | |
4506 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); | |
4507 } | |
4508 | |
4509 | |
4510 | |
4511 typedef struct | |
4512 { | |
4513 OrthancPluginImage** target; | |
4514 const OrthancPluginImage* source; | |
4515 OrthancPluginPixelFormat targetFormat; | |
4516 } _OrthancPluginConvertPixelFormat; | |
4517 | |
4518 | |
4519 /** | |
4520 * @brief Change the pixel format of an image. | |
4521 * | |
4522 * This function creates a new image, changing the memory layout of the pixels. | |
4523 * | |
4524 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4525 * @param source The source image. | |
4526 * @param targetFormat The target pixel format. | |
4527 * @return The resulting image. It must be freed with OrthancPluginFreeImage(). | |
4528 * @ingroup Images | |
4529 **/ | |
4530 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginConvertPixelFormat( | |
4531 OrthancPluginContext* context, | |
4532 const OrthancPluginImage* source, | |
4533 OrthancPluginPixelFormat targetFormat) | |
4534 { | |
4535 OrthancPluginImage* target = NULL; | |
4536 | |
4537 _OrthancPluginConvertPixelFormat params; | |
4538 params.target = ⌖ | |
4539 params.source = source; | |
4540 params.targetFormat = targetFormat; | |
4541 | |
4542 if (context->InvokeService(context, _OrthancPluginService_ConvertPixelFormat, ¶ms) != OrthancPluginErrorCode_Success) | |
4543 { | |
4544 return NULL; | |
4545 } | |
4546 else | |
4547 { | |
4548 return target; | |
4549 } | |
4550 } | |
4551 | |
4552 | |
4553 | |
4554 /** | |
4555 * @brief Return the number of available fonts. | |
4556 * | |
4557 * This function returns the number of fonts that are built in the | |
4558 * Orthanc core. These fonts can be used to draw texts on images | |
4559 * through OrthancPluginDrawText(). | |
4560 * | |
4561 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4562 * @return The number of fonts. | |
4563 * @ingroup Images | |
4564 **/ | |
4565 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontsCount( | |
4566 OrthancPluginContext* context) | |
4567 { | |
4568 uint32_t count = 0; | |
4569 | |
4570 _OrthancPluginReturnSingleValue params; | |
4571 memset(¶ms, 0, sizeof(params)); | |
4572 params.resultUint32 = &count; | |
4573 | |
4574 if (context->InvokeService(context, _OrthancPluginService_GetFontsCount, ¶ms) != OrthancPluginErrorCode_Success) | |
4575 { | |
4576 /* Error */ | |
4577 return 0; | |
4578 } | |
4579 else | |
4580 { | |
4581 return count; | |
4582 } | |
4583 } | |
4584 | |
4585 | |
4586 | |
4587 | |
4588 typedef struct | |
4589 { | |
4590 uint32_t fontIndex; /* in */ | |
4591 const char** name; /* out */ | |
4592 uint32_t* size; /* out */ | |
4593 } _OrthancPluginGetFontInfo; | |
4594 | |
4595 /** | |
4596 * @brief Return the name of a font. | |
4597 * | |
4598 * This function returns the name of a font that is built in the Orthanc core. | |
4599 * | |
4600 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4601 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). | |
4602 * @return The font name. This is a statically-allocated string, do not free it. | |
4603 * @ingroup Images | |
4604 **/ | |
4605 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetFontName( | |
4606 OrthancPluginContext* context, | |
4607 uint32_t fontIndex) | |
4608 { | |
4609 const char* result = NULL; | |
4610 | |
4611 _OrthancPluginGetFontInfo params; | |
4612 memset(¶ms, 0, sizeof(params)); | |
4613 params.name = &result; | |
4614 params.fontIndex = fontIndex; | |
4615 | |
4616 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, ¶ms) != OrthancPluginErrorCode_Success) | |
4617 { | |
4618 return NULL; | |
4619 } | |
4620 else | |
4621 { | |
4622 return result; | |
4623 } | |
4624 } | |
4625 | |
4626 | |
4627 /** | |
4628 * @brief Return the size of a font. | |
4629 * | |
4630 * This function returns the size of a font that is built in the Orthanc core. | |
4631 * | |
4632 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4633 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). | |
4634 * @return The font size. | |
4635 * @ingroup Images | |
4636 **/ | |
4637 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontSize( | |
4638 OrthancPluginContext* context, | |
4639 uint32_t fontIndex) | |
4640 { | |
4641 uint32_t result; | |
4642 | |
4643 _OrthancPluginGetFontInfo params; | |
4644 memset(¶ms, 0, sizeof(params)); | |
4645 params.size = &result; | |
4646 params.fontIndex = fontIndex; | |
4647 | |
4648 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, ¶ms) != OrthancPluginErrorCode_Success) | |
4649 { | |
4650 return 0; | |
4651 } | |
4652 else | |
4653 { | |
4654 return result; | |
4655 } | |
4656 } | |
4657 | |
4658 | |
4659 | |
4660 typedef struct | |
4661 { | |
4662 OrthancPluginImage* image; | |
4663 uint32_t fontIndex; | |
4664 const char* utf8Text; | |
4665 int32_t x; | |
4666 int32_t y; | |
4667 uint8_t r; | |
4668 uint8_t g; | |
4669 uint8_t b; | |
4670 } _OrthancPluginDrawText; | |
4671 | |
4672 | |
4673 /** | |
4674 * @brief Draw text on an image. | |
4675 * | |
4676 * This function draws some text on some image. | |
4677 * | |
4678 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4679 * @param image The image upon which to draw the text. | |
4680 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). | |
4681 * @param utf8Text The text to be drawn, encoded as an UTF-8 zero-terminated string. | |
4682 * @param x The X position of the text over the image. | |
4683 * @param y The Y position of the text over the image. | |
4684 * @param r The value of the red color channel of the text. | |
4685 * @param g The value of the green color channel of the text. | |
4686 * @param b The value of the blue color channel of the text. | |
4687 * @return 0 if success, other value if error. | |
4688 * @ingroup Images | |
4689 **/ | |
4690 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginDrawText( | |
4691 OrthancPluginContext* context, | |
4692 OrthancPluginImage* image, | |
4693 uint32_t fontIndex, | |
4694 const char* utf8Text, | |
4695 int32_t x, | |
4696 int32_t y, | |
4697 uint8_t r, | |
4698 uint8_t g, | |
4699 uint8_t b) | |
4700 { | |
4701 _OrthancPluginDrawText params; | |
4702 memset(¶ms, 0, sizeof(params)); | |
4703 params.image = image; | |
4704 params.fontIndex = fontIndex; | |
4705 params.utf8Text = utf8Text; | |
4706 params.x = x; | |
4707 params.y = y; | |
4708 params.r = r; | |
4709 params.g = g; | |
4710 params.b = b; | |
4711 | |
4712 return context->InvokeService(context, _OrthancPluginService_DrawText, ¶ms); | |
4713 } | |
4714 | |
4715 | |
4716 | |
4717 typedef struct | |
4718 { | |
4719 OrthancPluginStorageArea* storageArea; | |
4720 const char* uuid; | |
4721 const void* content; | |
4722 uint64_t size; | |
4723 OrthancPluginContentType type; | |
4724 } _OrthancPluginStorageAreaCreate; | |
4725 | |
4726 | |
4727 /** | |
4728 * @brief Create a file inside the storage area. | |
4729 * | |
4730 * This function creates a new file inside the storage area that is | |
4731 * currently used by Orthanc. | |
4732 * | |
4733 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4734 * @param storageArea The storage area. | |
4735 * @param uuid The identifier of the file to be created. | |
4736 * @param content The content to store in the newly created file. | |
4737 * @param size The size of the content. | |
4738 * @param type The type of the file content. | |
4739 * @return 0 if success, other value if error. | |
4740 * @ingroup Callbacks | |
4741 * @deprecated This function should not be used anymore. Use "OrthancPluginRestApiPut()" on | |
4742 * "/{patients|studies|series|instances}/{id}/attachments/{name}" instead. | |
4743 **/ | |
4744 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaCreate( | |
4745 OrthancPluginContext* context, | |
4746 OrthancPluginStorageArea* storageArea, | |
4747 const char* uuid, | |
4748 const void* content, | |
4749 uint64_t size, | |
4750 OrthancPluginContentType type) | |
4751 { | |
4752 _OrthancPluginStorageAreaCreate params; | |
4753 params.storageArea = storageArea; | |
4754 params.uuid = uuid; | |
4755 params.content = content; | |
4756 params.size = size; | |
4757 params.type = type; | |
4758 | |
4759 return context->InvokeService(context, _OrthancPluginService_StorageAreaCreate, ¶ms); | |
4760 } | |
4761 | |
4762 | |
4763 typedef struct | |
4764 { | |
4765 OrthancPluginMemoryBuffer* target; | |
4766 OrthancPluginStorageArea* storageArea; | |
4767 const char* uuid; | |
4768 OrthancPluginContentType type; | |
4769 } _OrthancPluginStorageAreaRead; | |
4770 | |
4771 | |
4772 /** | |
4773 * @brief Read a file from the storage area. | |
4774 * | |
4775 * This function reads the content of a given file from the storage | |
4776 * area that is currently used by Orthanc. | |
4777 * | |
4778 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4779 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
4780 * @param storageArea The storage area. | |
4781 * @param uuid The identifier of the file to be read. | |
4782 * @param type The type of the file content. | |
4783 * @return 0 if success, other value if error. | |
4784 * @ingroup Callbacks | |
4785 * @deprecated This function should not be used anymore. Use "OrthancPluginRestApiGet()" on | |
4786 * "/{patients|studies|series|instances}/{id}/attachments/{name}" instead. | |
4787 **/ | |
4788 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRead( | |
4789 OrthancPluginContext* context, | |
4790 OrthancPluginMemoryBuffer* target, | |
4791 OrthancPluginStorageArea* storageArea, | |
4792 const char* uuid, | |
4793 OrthancPluginContentType type) | |
4794 { | |
4795 _OrthancPluginStorageAreaRead params; | |
4796 params.target = target; | |
4797 params.storageArea = storageArea; | |
4798 params.uuid = uuid; | |
4799 params.type = type; | |
4800 | |
4801 return context->InvokeService(context, _OrthancPluginService_StorageAreaRead, ¶ms); | |
4802 } | |
4803 | |
4804 | |
4805 typedef struct | |
4806 { | |
4807 OrthancPluginStorageArea* storageArea; | |
4808 const char* uuid; | |
4809 OrthancPluginContentType type; | |
4810 } _OrthancPluginStorageAreaRemove; | |
4811 | |
4812 /** | |
4813 * @brief Remove a file from the storage area. | |
4814 * | |
4815 * This function removes a given file from the storage area that is | |
4816 * currently used by Orthanc. | |
4817 * | |
4818 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4819 * @param storageArea The storage area. | |
4820 * @param uuid The identifier of the file to be removed. | |
4821 * @param type The type of the file content. | |
4822 * @return 0 if success, other value if error. | |
4823 * @ingroup Callbacks | |
4824 * @deprecated This function should not be used anymore. Use "OrthancPluginRestApiDelete()" on | |
4825 * "/{patients|studies|series|instances}/{id}/attachments/{name}" instead. | |
4826 **/ | |
4827 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRemove( | |
4828 OrthancPluginContext* context, | |
4829 OrthancPluginStorageArea* storageArea, | |
4830 const char* uuid, | |
4831 OrthancPluginContentType type) | |
4832 { | |
4833 _OrthancPluginStorageAreaRemove params; | |
4834 params.storageArea = storageArea; | |
4835 params.uuid = uuid; | |
4836 params.type = type; | |
4837 | |
4838 return context->InvokeService(context, _OrthancPluginService_StorageAreaRemove, ¶ms); | |
4839 } | |
4840 | |
4841 | |
4842 | |
4843 typedef struct | |
4844 { | |
4845 OrthancPluginErrorCode* target; | |
4846 int32_t code; | |
4847 uint16_t httpStatus; | |
4848 const char* message; | |
4849 } _OrthancPluginRegisterErrorCode; | |
4850 | |
4851 /** | |
4852 * @brief Declare a custom error code for this plugin. | |
4853 * | |
4854 * This function declares a custom error code that can be generated | |
4855 * by this plugin. This declaration is used to enrich the body of | |
4856 * the HTTP answer in the case of an error, and to set the proper | |
4857 * HTTP status code. | |
4858 * | |
4859 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4860 * @param code The error code that is internal to this plugin. | |
4861 * @param httpStatus The HTTP status corresponding to this error. | |
4862 * @param message The description of the error. | |
4863 * @return The error code that has been assigned inside the Orthanc core. | |
4864 * @ingroup Toolbox | |
4865 **/ | |
4866 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterErrorCode( | |
4867 OrthancPluginContext* context, | |
4868 int32_t code, | |
4869 uint16_t httpStatus, | |
4870 const char* message) | |
4871 { | |
4872 OrthancPluginErrorCode target; | |
4873 | |
4874 _OrthancPluginRegisterErrorCode params; | |
4875 params.target = ⌖ | |
4876 params.code = code; | |
4877 params.httpStatus = httpStatus; | |
4878 params.message = message; | |
4879 | |
4880 if (context->InvokeService(context, _OrthancPluginService_RegisterErrorCode, ¶ms) == OrthancPluginErrorCode_Success) | |
4881 { | |
4882 return target; | |
4883 } | |
4884 else | |
4885 { | |
4886 /* There was an error while assigned the error. Use a generic code. */ | |
4887 return OrthancPluginErrorCode_Plugin; | |
4888 } | |
4889 } | |
4890 | |
4891 | |
4892 | |
4893 typedef struct | |
4894 { | |
4895 uint16_t group; | |
4896 uint16_t element; | |
4897 OrthancPluginValueRepresentation vr; | |
4898 const char* name; | |
4899 uint32_t minMultiplicity; | |
4900 uint32_t maxMultiplicity; | |
4901 } _OrthancPluginRegisterDictionaryTag; | |
4902 | |
4903 /** | |
4904 * @brief Register a new tag into the DICOM dictionary. | |
4905 * | |
4906 * This function declares a new public tag in the dictionary of | |
4907 * DICOM tags that are known to Orthanc. This function should be | |
4908 * used in the OrthancPluginInitialize() callback. | |
4909 * | |
4910 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4911 * @param group The group of the tag. | |
4912 * @param element The element of the tag. | |
4913 * @param vr The value representation of the tag. | |
4914 * @param name The nickname of the tag. | |
4915 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0). | |
4916 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means | |
4917 * an arbitrary multiplicity ("<tt>n</tt>"). | |
4918 * @return 0 if success, other value if error. | |
4919 * @see OrthancPluginRegisterPrivateDictionaryTag() | |
4920 * @ingroup Toolbox | |
4921 **/ | |
4922 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDictionaryTag( | |
4923 OrthancPluginContext* context, | |
4924 uint16_t group, | |
4925 uint16_t element, | |
4926 OrthancPluginValueRepresentation vr, | |
4927 const char* name, | |
4928 uint32_t minMultiplicity, | |
4929 uint32_t maxMultiplicity) | |
4930 { | |
4931 _OrthancPluginRegisterDictionaryTag params; | |
4932 params.group = group; | |
4933 params.element = element; | |
4934 params.vr = vr; | |
4935 params.name = name; | |
4936 params.minMultiplicity = minMultiplicity; | |
4937 params.maxMultiplicity = maxMultiplicity; | |
4938 | |
4939 return context->InvokeService(context, _OrthancPluginService_RegisterDictionaryTag, ¶ms); | |
4940 } | |
4941 | |
4942 | |
4943 | |
4944 typedef struct | |
4945 { | |
4946 uint16_t group; | |
4947 uint16_t element; | |
4948 OrthancPluginValueRepresentation vr; | |
4949 const char* name; | |
4950 uint32_t minMultiplicity; | |
4951 uint32_t maxMultiplicity; | |
4952 const char* privateCreator; | |
4953 } _OrthancPluginRegisterPrivateDictionaryTag; | |
4954 | |
4955 /** | |
4956 * @brief Register a new private tag into the DICOM dictionary. | |
4957 * | |
4958 * This function declares a new private tag in the dictionary of | |
4959 * DICOM tags that are known to Orthanc. This function should be | |
4960 * used in the OrthancPluginInitialize() callback. | |
4961 * | |
4962 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
4963 * @param group The group of the tag. | |
4964 * @param element The element of the tag. | |
4965 * @param vr The value representation of the tag. | |
4966 * @param name The nickname of the tag. | |
4967 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0). | |
4968 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means | |
4969 * an arbitrary multiplicity ("<tt>n</tt>"). | |
4970 * @param privateCreator The private creator of this private tag. | |
4971 * @return 0 if success, other value if error. | |
4972 * @see OrthancPluginRegisterDictionaryTag() | |
4973 * @ingroup Toolbox | |
4974 **/ | |
4975 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterPrivateDictionaryTag( | |
4976 OrthancPluginContext* context, | |
4977 uint16_t group, | |
4978 uint16_t element, | |
4979 OrthancPluginValueRepresentation vr, | |
4980 const char* name, | |
4981 uint32_t minMultiplicity, | |
4982 uint32_t maxMultiplicity, | |
4983 const char* privateCreator) | |
4984 { | |
4985 _OrthancPluginRegisterPrivateDictionaryTag params; | |
4986 params.group = group; | |
4987 params.element = element; | |
4988 params.vr = vr; | |
4989 params.name = name; | |
4990 params.minMultiplicity = minMultiplicity; | |
4991 params.maxMultiplicity = maxMultiplicity; | |
4992 params.privateCreator = privateCreator; | |
4993 | |
4994 return context->InvokeService(context, _OrthancPluginService_RegisterPrivateDictionaryTag, ¶ms); | |
4995 } | |
4996 | |
4997 | |
4998 | |
4999 typedef struct | |
5000 { | |
5001 OrthancPluginStorageArea* storageArea; | |
5002 OrthancPluginResourceType level; | |
5003 } _OrthancPluginReconstructMainDicomTags; | |
5004 | |
5005 /** | |
5006 * @brief Reconstruct the main DICOM tags. | |
5007 * | |
5008 * This function requests the Orthanc core to reconstruct the main | |
5009 * DICOM tags of all the resources of the given type. This function | |
5010 * can only be used as a part of the upgrade of a custom database | |
5011 * back-end. A database transaction will be automatically setup. | |
5012 * | |
5013 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5014 * @param storageArea The storage area. | |
5015 * @param level The type of the resources of interest. | |
5016 * @return 0 if success, other value if error. | |
5017 * @ingroup Callbacks | |
5018 **/ | |
5019 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReconstructMainDicomTags( | |
5020 OrthancPluginContext* context, | |
5021 OrthancPluginStorageArea* storageArea, | |
5022 OrthancPluginResourceType level) | |
5023 { | |
5024 _OrthancPluginReconstructMainDicomTags params; | |
5025 params.level = level; | |
5026 params.storageArea = storageArea; | |
5027 | |
5028 return context->InvokeService(context, _OrthancPluginService_ReconstructMainDicomTags, ¶ms); | |
5029 } | |
5030 | |
5031 | |
5032 typedef struct | |
5033 { | |
5034 char** result; | |
5035 const char* instanceId; | |
5036 const void* buffer; | |
5037 uint32_t size; | |
5038 OrthancPluginDicomToJsonFormat format; | |
5039 OrthancPluginDicomToJsonFlags flags; | |
5040 uint32_t maxStringLength; | |
5041 } _OrthancPluginDicomToJson; | |
5042 | |
5043 | |
5044 /** | |
5045 * @brief Format a DICOM memory buffer as a JSON string. | |
5046 * | |
5047 * This function takes as input a memory buffer containing a DICOM | |
5048 * file, and outputs a JSON string representing the tags of this | |
5049 * DICOM file. | |
5050 * | |
5051 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5052 * @param buffer The memory buffer containing the DICOM file. | |
5053 * @param size The size of the memory buffer. | |
5054 * @param format The output format. | |
5055 * @param flags Flags governing the output. | |
5056 * @param maxStringLength The maximum length of a field. Too long fields will | |
5057 * be output as "null". The 0 value means no maximum length. | |
5058 * @return The NULL value if the case of an error, or the JSON | |
5059 * string. This string must be freed by OrthancPluginFreeString(). | |
5060 * @ingroup Toolbox | |
5061 * @see OrthancPluginDicomInstanceToJson() | |
5062 **/ | |
5063 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomBufferToJson( | |
5064 OrthancPluginContext* context, | |
5065 const void* buffer, | |
5066 uint32_t size, | |
5067 OrthancPluginDicomToJsonFormat format, | |
5068 OrthancPluginDicomToJsonFlags flags, | |
5069 uint32_t maxStringLength) | |
5070 { | |
5071 char* result; | |
5072 | |
5073 _OrthancPluginDicomToJson params; | |
5074 memset(¶ms, 0, sizeof(params)); | |
5075 params.result = &result; | |
5076 params.buffer = buffer; | |
5077 params.size = size; | |
5078 params.format = format; | |
5079 params.flags = flags; | |
5080 params.maxStringLength = maxStringLength; | |
5081 | |
5082 if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, ¶ms) != OrthancPluginErrorCode_Success) | |
5083 { | |
5084 /* Error */ | |
5085 return NULL; | |
5086 } | |
5087 else | |
5088 { | |
5089 return result; | |
5090 } | |
5091 } | |
5092 | |
5093 | |
5094 /** | |
5095 * @brief Format a DICOM instance as a JSON string. | |
5096 * | |
5097 * This function formats a DICOM instance that is stored in Orthanc, | |
5098 * and outputs a JSON string representing the tags of this DICOM | |
5099 * instance. | |
5100 * | |
5101 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5102 * @param instanceId The Orthanc identifier of the instance. | |
5103 * @param format The output format. | |
5104 * @param flags Flags governing the output. | |
5105 * @param maxStringLength The maximum length of a field. Too long fields will | |
5106 * be output as "null". The 0 value means no maximum length. | |
5107 * @return The NULL value if the case of an error, or the JSON | |
5108 * string. This string must be freed by OrthancPluginFreeString(). | |
5109 * @ingroup Toolbox | |
5110 * @see OrthancPluginDicomInstanceToJson() | |
5111 **/ | |
5112 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomInstanceToJson( | |
5113 OrthancPluginContext* context, | |
5114 const char* instanceId, | |
5115 OrthancPluginDicomToJsonFormat format, | |
5116 OrthancPluginDicomToJsonFlags flags, | |
5117 uint32_t maxStringLength) | |
5118 { | |
5119 char* result; | |
5120 | |
5121 _OrthancPluginDicomToJson params; | |
5122 memset(¶ms, 0, sizeof(params)); | |
5123 params.result = &result; | |
5124 params.instanceId = instanceId; | |
5125 params.format = format; | |
5126 params.flags = flags; | |
5127 params.maxStringLength = maxStringLength; | |
5128 | |
5129 if (context->InvokeService(context, _OrthancPluginService_DicomInstanceToJson, ¶ms) != OrthancPluginErrorCode_Success) | |
5130 { | |
5131 /* Error */ | |
5132 return NULL; | |
5133 } | |
5134 else | |
5135 { | |
5136 return result; | |
5137 } | |
5138 } | |
5139 | |
5140 | |
5141 typedef struct | |
5142 { | |
5143 OrthancPluginMemoryBuffer* target; | |
5144 const char* uri; | |
5145 uint32_t headersCount; | |
5146 const char* const* headersKeys; | |
5147 const char* const* headersValues; | |
5148 int32_t afterPlugins; | |
5149 } _OrthancPluginRestApiGet2; | |
5150 | |
5151 /** | |
5152 * @brief Make a GET call to the Orthanc REST API, with custom HTTP headers. | |
5153 * | |
5154 * Make a GET call to the Orthanc REST API with extended | |
5155 * parameters. The result to the query is stored into a newly | |
5156 * allocated memory buffer. | |
5157 * | |
5158 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5159 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
5160 * @param uri The URI in the built-in Orthanc API. | |
5161 * @param headersCount The number of HTTP headers. | |
5162 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header). | |
5163 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header). | |
5164 * @param afterPlugins If 0, the built-in API of Orthanc is used. | |
5165 * If 1, the API is tainted by the plugins. | |
5166 * @return 0 if success, or the error code if failure. | |
5167 * @see OrthancPluginRestApiGet(), OrthancPluginRestApiGetAfterPlugins() | |
5168 * @ingroup Orthanc | |
5169 **/ | |
5170 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet2( | |
5171 OrthancPluginContext* context, | |
5172 OrthancPluginMemoryBuffer* target, | |
5173 const char* uri, | |
5174 uint32_t headersCount, | |
5175 const char* const* headersKeys, | |
5176 const char* const* headersValues, | |
5177 int32_t afterPlugins) | |
5178 { | |
5179 _OrthancPluginRestApiGet2 params; | |
5180 params.target = target; | |
5181 params.uri = uri; | |
5182 params.headersCount = headersCount; | |
5183 params.headersKeys = headersKeys; | |
5184 params.headersValues = headersValues; | |
5185 params.afterPlugins = afterPlugins; | |
5186 | |
5187 return context->InvokeService(context, _OrthancPluginService_RestApiGet2, ¶ms); | |
5188 } | |
5189 | |
5190 | |
5191 | |
5192 typedef struct | |
5193 { | |
5194 OrthancPluginWorklistCallback callback; | |
5195 } _OrthancPluginWorklistCallback; | |
5196 | |
5197 /** | |
5198 * @brief Register a callback to handle modality worklists requests. | |
5199 * | |
5200 * This function registers a callback to handle C-Find SCP requests | |
5201 * on modality worklists. | |
5202 * | |
5203 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5204 * @param callback The callback. | |
5205 * @return 0 if success, other value if error. | |
5206 * @ingroup DicomCallbacks | |
5207 **/ | |
5208 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterWorklistCallback( | |
5209 OrthancPluginContext* context, | |
5210 OrthancPluginWorklistCallback callback) | |
5211 { | |
5212 _OrthancPluginWorklistCallback params; | |
5213 params.callback = callback; | |
5214 | |
5215 return context->InvokeService(context, _OrthancPluginService_RegisterWorklistCallback, ¶ms); | |
5216 } | |
5217 | |
5218 | |
5219 | |
5220 typedef struct | |
5221 { | |
5222 OrthancPluginWorklistAnswers* answers; | |
5223 const OrthancPluginWorklistQuery* query; | |
5224 const void* dicom; | |
5225 uint32_t size; | |
5226 } _OrthancPluginWorklistAnswersOperation; | |
5227 | |
5228 /** | |
5229 * @brief Add one answer to some modality worklist request. | |
5230 * | |
5231 * This function adds one worklist (encoded as a DICOM file) to the | |
5232 * set of answers corresponding to some C-Find SCP request against | |
5233 * modality worklists. | |
5234 * | |
5235 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5236 * @param answers The set of answers. | |
5237 * @param query The worklist query, as received by the callback. | |
5238 * @param dicom The worklist to answer, encoded as a DICOM file. | |
5239 * @param size The size of the DICOM file. | |
5240 * @return 0 if success, other value if error. | |
5241 * @ingroup DicomCallbacks | |
5242 * @see OrthancPluginCreateDicom() | |
5243 **/ | |
5244 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistAddAnswer( | |
5245 OrthancPluginContext* context, | |
5246 OrthancPluginWorklistAnswers* answers, | |
5247 const OrthancPluginWorklistQuery* query, | |
5248 const void* dicom, | |
5249 uint32_t size) | |
5250 { | |
5251 _OrthancPluginWorklistAnswersOperation params; | |
5252 params.answers = answers; | |
5253 params.query = query; | |
5254 params.dicom = dicom; | |
5255 params.size = size; | |
5256 | |
5257 return context->InvokeService(context, _OrthancPluginService_WorklistAddAnswer, ¶ms); | |
5258 } | |
5259 | |
5260 | |
5261 /** | |
5262 * @brief Mark the set of worklist answers as incomplete. | |
5263 * | |
5264 * This function marks as incomplete the set of answers | |
5265 * corresponding to some C-Find SCP request against modality | |
5266 * worklists. This must be used if canceling the handling of a | |
5267 * request when too many answers are to be returned. | |
5268 * | |
5269 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5270 * @param answers The set of answers. | |
5271 * @return 0 if success, other value if error. | |
5272 * @ingroup DicomCallbacks | |
5273 **/ | |
5274 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistMarkIncomplete( | |
5275 OrthancPluginContext* context, | |
5276 OrthancPluginWorklistAnswers* answers) | |
5277 { | |
5278 _OrthancPluginWorklistAnswersOperation params; | |
5279 params.answers = answers; | |
5280 params.query = NULL; | |
5281 params.dicom = NULL; | |
5282 params.size = 0; | |
5283 | |
5284 return context->InvokeService(context, _OrthancPluginService_WorklistMarkIncomplete, ¶ms); | |
5285 } | |
5286 | |
5287 | |
5288 typedef struct | |
5289 { | |
5290 const OrthancPluginWorklistQuery* query; | |
5291 const void* dicom; | |
5292 uint32_t size; | |
5293 int32_t* isMatch; | |
5294 OrthancPluginMemoryBuffer* target; | |
5295 } _OrthancPluginWorklistQueryOperation; | |
5296 | |
5297 /** | |
5298 * @brief Test whether a worklist matches the query. | |
5299 * | |
5300 * This function checks whether one worklist (encoded as a DICOM | |
5301 * file) matches the C-Find SCP query against modality | |
5302 * worklists. This function must be called before adding the | |
5303 * worklist as an answer through OrthancPluginWorklistAddAnswer(). | |
5304 * | |
5305 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5306 * @param query The worklist query, as received by the callback. | |
5307 * @param dicom The worklist to answer, encoded as a DICOM file. | |
5308 * @param size The size of the DICOM file. | |
5309 * @return 1 if the worklist matches the query, 0 otherwise. | |
5310 * @ingroup DicomCallbacks | |
5311 **/ | |
5312 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginWorklistIsMatch( | |
5313 OrthancPluginContext* context, | |
5314 const OrthancPluginWorklistQuery* query, | |
5315 const void* dicom, | |
5316 uint32_t size) | |
5317 { | |
5318 int32_t isMatch = 0; | |
5319 | |
5320 _OrthancPluginWorklistQueryOperation params; | |
5321 params.query = query; | |
5322 params.dicom = dicom; | |
5323 params.size = size; | |
5324 params.isMatch = &isMatch; | |
5325 params.target = NULL; | |
5326 | |
5327 if (context->InvokeService(context, _OrthancPluginService_WorklistIsMatch, ¶ms) == OrthancPluginErrorCode_Success) | |
5328 { | |
5329 return isMatch; | |
5330 } | |
5331 else | |
5332 { | |
5333 /* Error: Assume non-match */ | |
5334 return 0; | |
5335 } | |
5336 } | |
5337 | |
5338 | |
5339 /** | |
5340 * @brief Retrieve the worklist query as a DICOM file. | |
5341 * | |
5342 * This function retrieves the DICOM file that underlies a C-Find | |
5343 * SCP query against modality worklists. | |
5344 * | |
5345 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5346 * @param target Memory buffer where to store the DICOM file. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
5347 * @param query The worklist query, as received by the callback. | |
5348 * @return 0 if success, other value if error. | |
5349 * @ingroup DicomCallbacks | |
5350 **/ | |
5351 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistGetDicomQuery( | |
5352 OrthancPluginContext* context, | |
5353 OrthancPluginMemoryBuffer* target, | |
5354 const OrthancPluginWorklistQuery* query) | |
5355 { | |
5356 _OrthancPluginWorklistQueryOperation params; | |
5357 params.query = query; | |
5358 params.dicom = NULL; | |
5359 params.size = 0; | |
5360 params.isMatch = NULL; | |
5361 params.target = target; | |
5362 | |
5363 return context->InvokeService(context, _OrthancPluginService_WorklistGetDicomQuery, ¶ms); | |
5364 } | |
5365 | |
5366 | |
5367 /** | |
5368 * @brief Get the origin of a DICOM file. | |
5369 * | |
5370 * This function returns the origin of a DICOM instance that has been received by Orthanc. | |
5371 * | |
5372 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5373 * @param instance The instance of interest. | |
5374 * @return The origin of the instance. | |
5375 * @ingroup DicomInstance | |
5376 **/ | |
5377 ORTHANC_PLUGIN_INLINE OrthancPluginInstanceOrigin OrthancPluginGetInstanceOrigin( | |
5378 OrthancPluginContext* context, | |
5379 const OrthancPluginDicomInstance* instance) | |
5380 { | |
5381 OrthancPluginInstanceOrigin origin; | |
5382 | |
5383 _OrthancPluginAccessDicomInstance params; | |
5384 memset(¶ms, 0, sizeof(params)); | |
5385 params.resultOrigin = &origin; | |
5386 params.instance = instance; | |
5387 | |
5388 if (context->InvokeService(context, _OrthancPluginService_GetInstanceOrigin, ¶ms) != OrthancPluginErrorCode_Success) | |
5389 { | |
5390 /* Error */ | |
5391 return OrthancPluginInstanceOrigin_Unknown; | |
5392 } | |
5393 else | |
5394 { | |
5395 return origin; | |
5396 } | |
5397 } | |
5398 | |
5399 | |
5400 typedef struct | |
5401 { | |
5402 OrthancPluginMemoryBuffer* target; | |
5403 const char* json; | |
5404 const OrthancPluginImage* pixelData; | |
5405 OrthancPluginCreateDicomFlags flags; | |
5406 } _OrthancPluginCreateDicom; | |
5407 | |
5408 /** | |
5409 * @brief Create a DICOM instance from a JSON string and an image. | |
5410 * | |
5411 * This function takes as input a string containing a JSON file | |
5412 * describing the content of a DICOM instance. As an output, it | |
5413 * writes the corresponding DICOM instance to a newly allocated | |
5414 * memory buffer. Additionally, an image to be encoded within the | |
5415 * DICOM instance can also be provided. | |
5416 * | |
5417 * Private tags will be associated with the private creator whose | |
5418 * value is specified in the "DefaultPrivateCreator" configuration | |
5419 * option of Orthanc. The function OrthancPluginCreateDicom2() can | |
5420 * be used if another private creator must be used to create this | |
5421 * instance. | |
5422 * | |
5423 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5424 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
5425 * @param json The input JSON file. | |
5426 * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme. | |
5427 * @param flags Flags governing the output. | |
5428 * @return 0 if success, other value if error. | |
5429 * @ingroup Toolbox | |
5430 * @see OrthancPluginCreateDicom2() | |
5431 * @see OrthancPluginDicomBufferToJson() | |
5432 **/ | |
5433 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom( | |
5434 OrthancPluginContext* context, | |
5435 OrthancPluginMemoryBuffer* target, | |
5436 const char* json, | |
5437 const OrthancPluginImage* pixelData, | |
5438 OrthancPluginCreateDicomFlags flags) | |
5439 { | |
5440 _OrthancPluginCreateDicom params; | |
5441 params.target = target; | |
5442 params.json = json; | |
5443 params.pixelData = pixelData; | |
5444 params.flags = flags; | |
5445 | |
5446 return context->InvokeService(context, _OrthancPluginService_CreateDicom, ¶ms); | |
5447 } | |
5448 | |
5449 | |
5450 typedef struct | |
5451 { | |
5452 OrthancPluginDecodeImageCallback callback; | |
5453 } _OrthancPluginDecodeImageCallback; | |
5454 | |
5455 /** | |
5456 * @brief Register a callback to handle the decoding of DICOM images. | |
5457 * | |
5458 * This function registers a custom callback to decode DICOM images, | |
5459 * extending the built-in decoder of Orthanc that uses | |
5460 * DCMTK. Starting with Orthanc 1.7.0, the exact behavior is | |
5461 * affected by the configuration option | |
5462 * "BuiltinDecoderTranscoderOrder" of Orthanc. | |
5463 * | |
5464 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5465 * @param callback The callback. | |
5466 * @return 0 if success, other value if error. | |
5467 * @ingroup Callbacks | |
5468 **/ | |
5469 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDecodeImageCallback( | |
5470 OrthancPluginContext* context, | |
5471 OrthancPluginDecodeImageCallback callback) | |
5472 { | |
5473 _OrthancPluginDecodeImageCallback params; | |
5474 params.callback = callback; | |
5475 | |
5476 return context->InvokeService(context, _OrthancPluginService_RegisterDecodeImageCallback, ¶ms); | |
5477 } | |
5478 | |
5479 | |
5480 | |
5481 typedef struct | |
5482 { | |
5483 OrthancPluginImage** target; | |
5484 OrthancPluginPixelFormat format; | |
5485 uint32_t width; | |
5486 uint32_t height; | |
5487 uint32_t pitch; | |
5488 void* buffer; | |
5489 const void* constBuffer; | |
5490 uint32_t bufferSize; | |
5491 uint32_t frameIndex; | |
5492 } _OrthancPluginCreateImage; | |
5493 | |
5494 | |
5495 /** | |
5496 * @brief Create an image. | |
5497 * | |
5498 * This function creates an image of given size and format. | |
5499 * | |
5500 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5501 * @param format The format of the pixels. | |
5502 * @param width The width of the image. | |
5503 * @param height The height of the image. | |
5504 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage(). | |
5505 * @ingroup Images | |
5506 **/ | |
5507 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImage( | |
5508 OrthancPluginContext* context, | |
5509 OrthancPluginPixelFormat format, | |
5510 uint32_t width, | |
5511 uint32_t height) | |
5512 { | |
5513 OrthancPluginImage* target = NULL; | |
5514 | |
5515 _OrthancPluginCreateImage params; | |
5516 memset(¶ms, 0, sizeof(params)); | |
5517 params.target = ⌖ | |
5518 params.format = format; | |
5519 params.width = width; | |
5520 params.height = height; | |
5521 | |
5522 if (context->InvokeService(context, _OrthancPluginService_CreateImage, ¶ms) != OrthancPluginErrorCode_Success) | |
5523 { | |
5524 return NULL; | |
5525 } | |
5526 else | |
5527 { | |
5528 return target; | |
5529 } | |
5530 } | |
5531 | |
5532 | |
5533 /** | |
5534 * @brief Create an image pointing to a memory buffer. | |
5535 * | |
5536 * This function creates an image whose content points to a memory | |
5537 * buffer managed by the plugin. Note that the buffer is directly | |
5538 * accessed, no memory is allocated and no data is copied. | |
5539 * | |
5540 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5541 * @param format The format of the pixels. | |
5542 * @param width The width of the image. | |
5543 * @param height The height of the image. | |
5544 * @param pitch The pitch of the image (i.e. the number of bytes | |
5545 * between 2 successive lines of the image in the memory buffer). | |
5546 * @param buffer The memory buffer. | |
5547 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage(). | |
5548 * @ingroup Images | |
5549 **/ | |
5550 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImageAccessor( | |
5551 OrthancPluginContext* context, | |
5552 OrthancPluginPixelFormat format, | |
5553 uint32_t width, | |
5554 uint32_t height, | |
5555 uint32_t pitch, | |
5556 void* buffer) | |
5557 { | |
5558 OrthancPluginImage* target = NULL; | |
5559 | |
5560 _OrthancPluginCreateImage params; | |
5561 memset(¶ms, 0, sizeof(params)); | |
5562 params.target = ⌖ | |
5563 params.format = format; | |
5564 params.width = width; | |
5565 params.height = height; | |
5566 params.pitch = pitch; | |
5567 params.buffer = buffer; | |
5568 | |
5569 if (context->InvokeService(context, _OrthancPluginService_CreateImageAccessor, ¶ms) != OrthancPluginErrorCode_Success) | |
5570 { | |
5571 return NULL; | |
5572 } | |
5573 else | |
5574 { | |
5575 return target; | |
5576 } | |
5577 } | |
5578 | |
5579 | |
5580 | |
5581 /** | |
5582 * @brief Decode one frame from a DICOM instance. | |
5583 * | |
5584 * This function decodes one frame of a DICOM image that is stored | |
5585 * in a memory buffer. This function will give the same result as | |
5586 * OrthancPluginUncompressImage() for single-frame DICOM images. | |
5587 * | |
5588 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5589 * @param buffer Pointer to a memory buffer containing the DICOM image. | |
5590 * @param bufferSize Size of the memory buffer containing the DICOM image. | |
5591 * @param frameIndex The index of the frame of interest in a multi-frame image. | |
5592 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage(). | |
5593 * @ingroup Images | |
5594 * @see OrthancPluginGetInstanceDecodedFrame() | |
5595 **/ | |
5596 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginDecodeDicomImage( | |
5597 OrthancPluginContext* context, | |
5598 const void* buffer, | |
5599 uint32_t bufferSize, | |
5600 uint32_t frameIndex) | |
5601 { | |
5602 OrthancPluginImage* target = NULL; | |
5603 | |
5604 _OrthancPluginCreateImage params; | |
5605 memset(¶ms, 0, sizeof(params)); | |
5606 params.target = ⌖ | |
5607 params.constBuffer = buffer; | |
5608 params.bufferSize = bufferSize; | |
5609 params.frameIndex = frameIndex; | |
5610 | |
5611 if (context->InvokeService(context, _OrthancPluginService_DecodeDicomImage, ¶ms) != OrthancPluginErrorCode_Success) | |
5612 { | |
5613 return NULL; | |
5614 } | |
5615 else | |
5616 { | |
5617 return target; | |
5618 } | |
5619 } | |
5620 | |
5621 | |
5622 | |
5623 typedef struct | |
5624 { | |
5625 char** result; | |
5626 const void* buffer; | |
5627 uint32_t size; | |
5628 } _OrthancPluginComputeHash; | |
5629 | |
5630 /** | |
5631 * @brief Compute an MD5 hash. | |
5632 * | |
5633 * This functions computes the MD5 cryptographic hash of the given memory buffer. | |
5634 * | |
5635 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5636 * @param buffer The source memory buffer. | |
5637 * @param size The size in bytes of the source buffer. | |
5638 * @return The NULL value in case of error, or a string containing the cryptographic hash. | |
5639 * This string must be freed by OrthancPluginFreeString(). | |
5640 * @ingroup Toolbox | |
5641 **/ | |
5642 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeMd5( | |
5643 OrthancPluginContext* context, | |
5644 const void* buffer, | |
5645 uint32_t size) | |
5646 { | |
5647 char* result; | |
5648 | |
5649 _OrthancPluginComputeHash params; | |
5650 params.result = &result; | |
5651 params.buffer = buffer; | |
5652 params.size = size; | |
5653 | |
5654 if (context->InvokeService(context, _OrthancPluginService_ComputeMd5, ¶ms) != OrthancPluginErrorCode_Success) | |
5655 { | |
5656 /* Error */ | |
5657 return NULL; | |
5658 } | |
5659 else | |
5660 { | |
5661 return result; | |
5662 } | |
5663 } | |
5664 | |
5665 | |
5666 /** | |
5667 * @brief Compute a SHA-1 hash. | |
5668 * | |
5669 * This functions computes the SHA-1 cryptographic hash of the given memory buffer. | |
5670 * | |
5671 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5672 * @param buffer The source memory buffer. | |
5673 * @param size The size in bytes of the source buffer. | |
5674 * @return The NULL value in case of error, or a string containing the cryptographic hash. | |
5675 * This string must be freed by OrthancPluginFreeString(). | |
5676 * @ingroup Toolbox | |
5677 **/ | |
5678 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeSha1( | |
5679 OrthancPluginContext* context, | |
5680 const void* buffer, | |
5681 uint32_t size) | |
5682 { | |
5683 char* result; | |
5684 | |
5685 _OrthancPluginComputeHash params; | |
5686 params.result = &result; | |
5687 params.buffer = buffer; | |
5688 params.size = size; | |
5689 | |
5690 if (context->InvokeService(context, _OrthancPluginService_ComputeSha1, ¶ms) != OrthancPluginErrorCode_Success) | |
5691 { | |
5692 /* Error */ | |
5693 return NULL; | |
5694 } | |
5695 else | |
5696 { | |
5697 return result; | |
5698 } | |
5699 } | |
5700 | |
5701 | |
5702 | |
5703 typedef struct | |
5704 { | |
5705 OrthancPluginDictionaryEntry* target; | |
5706 const char* name; | |
5707 } _OrthancPluginLookupDictionary; | |
5708 | |
5709 /** | |
5710 * @brief Get information about the given DICOM tag. | |
5711 * | |
5712 * This functions makes a lookup in the dictionary of DICOM tags | |
5713 * that are known to Orthanc, and returns information about this | |
5714 * tag. The tag can be specified using its human-readable name | |
5715 * (e.g. "PatientName") or a set of two hexadecimal numbers | |
5716 * (e.g. "0010-0020"). | |
5717 * | |
5718 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5719 * @param target Where to store the information about the tag. | |
5720 * @param name The name of the DICOM tag. | |
5721 * @return 0 if success, other value if error. | |
5722 * @ingroup Toolbox | |
5723 **/ | |
5724 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginLookupDictionary( | |
5725 OrthancPluginContext* context, | |
5726 OrthancPluginDictionaryEntry* target, | |
5727 const char* name) | |
5728 { | |
5729 _OrthancPluginLookupDictionary params; | |
5730 params.target = target; | |
5731 params.name = name; | |
5732 return context->InvokeService(context, _OrthancPluginService_LookupDictionary, ¶ms); | |
5733 } | |
5734 | |
5735 | |
5736 | |
5737 typedef struct | |
5738 { | |
5739 OrthancPluginRestOutput* output; | |
5740 const void* answer; | |
5741 uint32_t answerSize; | |
5742 uint32_t headersCount; | |
5743 const char* const* headersKeys; | |
5744 const char* const* headersValues; | |
5745 } _OrthancPluginSendMultipartItem2; | |
5746 | |
5747 /** | |
5748 * @brief Send an item as a part of some HTTP multipart answer, with custom headers. | |
5749 * | |
5750 * This function sends an item as a part of some HTTP multipart | |
5751 * answer that was initiated by OrthancPluginStartMultipartAnswer(). In addition to | |
5752 * OrthancPluginSendMultipartItem(), this function will set HTTP header associated | |
5753 * with the item. | |
5754 * | |
5755 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5756 * @param output The HTTP connection to the client application. | |
5757 * @param answer Pointer to the memory buffer containing the item. | |
5758 * @param answerSize Number of bytes of the item. | |
5759 * @param headersCount The number of HTTP headers. | |
5760 * @param headersKeys Array containing the keys of the HTTP headers. | |
5761 * @param headersValues Array containing the values of the HTTP headers. | |
5762 * @return 0 if success, or the error code if failure (this notably happens | |
5763 * if the connection is closed by the client). | |
5764 * @see OrthancPluginSendMultipartItem() | |
5765 * @ingroup REST | |
5766 **/ | |
5767 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem2( | |
5768 OrthancPluginContext* context, | |
5769 OrthancPluginRestOutput* output, | |
5770 const void* answer, | |
5771 uint32_t answerSize, | |
5772 uint32_t headersCount, | |
5773 const char* const* headersKeys, | |
5774 const char* const* headersValues) | |
5775 { | |
5776 _OrthancPluginSendMultipartItem2 params; | |
5777 params.output = output; | |
5778 params.answer = answer; | |
5779 params.answerSize = answerSize; | |
5780 params.headersCount = headersCount; | |
5781 params.headersKeys = headersKeys; | |
5782 params.headersValues = headersValues; | |
5783 | |
5784 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem2, ¶ms); | |
5785 } | |
5786 | |
5787 | |
5788 typedef struct | |
5789 { | |
5790 OrthancPluginIncomingHttpRequestFilter callback; | |
5791 } _OrthancPluginIncomingHttpRequestFilter; | |
5792 | |
5793 /** | |
5794 * @brief Register a callback to filter incoming HTTP requests. | |
5795 * | |
5796 * This function registers a custom callback to filter incoming HTTP/REST | |
5797 * requests received by the HTTP server of Orthanc. | |
5798 * | |
5799 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5800 * @param callback The callback. | |
5801 * @return 0 if success, other value if error. | |
5802 * @ingroup Callbacks | |
5803 * @deprecated Please instead use OrthancPluginRegisterIncomingHttpRequestFilter2() | |
5804 **/ | |
5805 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter( | |
5806 OrthancPluginContext* context, | |
5807 OrthancPluginIncomingHttpRequestFilter callback) | |
5808 { | |
5809 _OrthancPluginIncomingHttpRequestFilter params; | |
5810 params.callback = callback; | |
5811 | |
5812 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter, ¶ms); | |
5813 } | |
5814 | |
5815 | |
5816 | |
5817 typedef struct | |
5818 { | |
5819 OrthancPluginMemoryBuffer* answerBody; | |
5820 OrthancPluginMemoryBuffer* answerHeaders; | |
5821 uint16_t* httpStatus; | |
5822 OrthancPluginHttpMethod method; | |
5823 const char* url; | |
5824 uint32_t headersCount; | |
5825 const char* const* headersKeys; | |
5826 const char* const* headersValues; | |
5827 const void* body; | |
5828 uint32_t bodySize; | |
5829 const char* username; | |
5830 const char* password; | |
5831 uint32_t timeout; | |
5832 const char* certificateFile; | |
5833 const char* certificateKeyFile; | |
5834 const char* certificateKeyPassword; | |
5835 uint8_t pkcs11; | |
5836 } _OrthancPluginCallHttpClient2; | |
5837 | |
5838 | |
5839 | |
5840 /** | |
5841 * @brief Issue a HTTP call with full flexibility. | |
5842 * | |
5843 * Make a HTTP call to the given URL. The result to the query is | |
5844 * stored into a newly allocated memory buffer. The HTTP request | |
5845 * will be done accordingly to the global configuration of Orthanc | |
5846 * (in particular, the options "HttpProxy", "HttpTimeout", | |
5847 * "HttpsVerifyPeers", "HttpsCACertificates", and "Pkcs11" will be | |
5848 * taken into account). | |
5849 * | |
5850 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5851 * @param answerBody The target memory buffer (out argument). | |
5852 * It must be freed with OrthancPluginFreeMemoryBuffer(). | |
5853 * The value of this argument is ignored if the HTTP method is DELETE. | |
5854 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument). | |
5855 * The answer headers are formatted as a JSON object (associative array). | |
5856 * The buffer must be freed with OrthancPluginFreeMemoryBuffer(). | |
5857 * This argument can be set to NULL if the plugin has no interest in the HTTP headers. | |
5858 * @param httpStatus The HTTP status after the execution of the request (out argument). | |
5859 * @param method HTTP method to be used. | |
5860 * @param url The URL of interest. | |
5861 * @param headersCount The number of HTTP headers. | |
5862 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header). | |
5863 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header). | |
5864 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
5865 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
5866 * @param body The HTTP body for a POST or PUT request. | |
5867 * @param bodySize The size of the body. | |
5868 * @param timeout Timeout in seconds (0 for default timeout). | |
5869 * @param certificateFile Path to the client certificate for HTTPS, in PEM format | |
5870 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
5871 * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format | |
5872 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
5873 * @param certificateKeyPassword Password to unlock the key of the client certificate | |
5874 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
5875 * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards. | |
5876 * @return 0 if success, or the error code if failure. | |
5877 * @see OrthancPluginCallPeerApi() | |
5878 * @ingroup Toolbox | |
5879 **/ | |
5880 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpClient( | |
5881 OrthancPluginContext* context, | |
5882 OrthancPluginMemoryBuffer* answerBody, | |
5883 OrthancPluginMemoryBuffer* answerHeaders, | |
5884 uint16_t* httpStatus, | |
5885 OrthancPluginHttpMethod method, | |
5886 const char* url, | |
5887 uint32_t headersCount, | |
5888 const char* const* headersKeys, | |
5889 const char* const* headersValues, | |
5890 const void* body, | |
5891 uint32_t bodySize, | |
5892 const char* username, | |
5893 const char* password, | |
5894 uint32_t timeout, | |
5895 const char* certificateFile, | |
5896 const char* certificateKeyFile, | |
5897 const char* certificateKeyPassword, | |
5898 uint8_t pkcs11) | |
5899 { | |
5900 _OrthancPluginCallHttpClient2 params; | |
5901 memset(¶ms, 0, sizeof(params)); | |
5902 | |
5903 params.answerBody = answerBody; | |
5904 params.answerHeaders = answerHeaders; | |
5905 params.httpStatus = httpStatus; | |
5906 params.method = method; | |
5907 params.url = url; | |
5908 params.headersCount = headersCount; | |
5909 params.headersKeys = headersKeys; | |
5910 params.headersValues = headersValues; | |
5911 params.body = body; | |
5912 params.bodySize = bodySize; | |
5913 params.username = username; | |
5914 params.password = password; | |
5915 params.timeout = timeout; | |
5916 params.certificateFile = certificateFile; | |
5917 params.certificateKeyFile = certificateKeyFile; | |
5918 params.certificateKeyPassword = certificateKeyPassword; | |
5919 params.pkcs11 = pkcs11; | |
5920 | |
5921 return context->InvokeService(context, _OrthancPluginService_CallHttpClient2, ¶ms); | |
5922 } | |
5923 | |
5924 | |
5925 /** | |
5926 * @brief Generate an UUID. | |
5927 * | |
5928 * Generate a random GUID/UUID (globally unique identifier). | |
5929 * | |
5930 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5931 * @return NULL in the case of an error, or a newly allocated string | |
5932 * containing the UUID. This string must be freed by OrthancPluginFreeString(). | |
5933 * @ingroup Toolbox | |
5934 **/ | |
5935 ORTHANC_PLUGIN_INLINE char* OrthancPluginGenerateUuid( | |
5936 OrthancPluginContext* context) | |
5937 { | |
5938 char* result; | |
5939 | |
5940 _OrthancPluginRetrieveDynamicString params; | |
5941 params.result = &result; | |
5942 params.argument = NULL; | |
5943 | |
5944 if (context->InvokeService(context, _OrthancPluginService_GenerateUuid, ¶ms) != OrthancPluginErrorCode_Success) | |
5945 { | |
5946 /* Error */ | |
5947 return NULL; | |
5948 } | |
5949 else | |
5950 { | |
5951 return result; | |
5952 } | |
5953 } | |
5954 | |
5955 | |
5956 | |
5957 | |
5958 typedef struct | |
5959 { | |
5960 OrthancPluginFindCallback callback; | |
5961 } _OrthancPluginFindCallback; | |
5962 | |
5963 /** | |
5964 * @brief Register a callback to handle C-Find requests. | |
5965 * | |
5966 * This function registers a callback to handle C-Find SCP requests | |
5967 * that are not related to modality worklists. | |
5968 * | |
5969 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
5970 * @param callback The callback. | |
5971 * @return 0 if success, other value if error. | |
5972 * @ingroup DicomCallbacks | |
5973 **/ | |
5974 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterFindCallback( | |
5975 OrthancPluginContext* context, | |
5976 OrthancPluginFindCallback callback) | |
5977 { | |
5978 _OrthancPluginFindCallback params; | |
5979 params.callback = callback; | |
5980 | |
5981 return context->InvokeService(context, _OrthancPluginService_RegisterFindCallback, ¶ms); | |
5982 } | |
5983 | |
5984 | |
5985 typedef struct | |
5986 { | |
5987 OrthancPluginFindAnswers *answers; | |
5988 const OrthancPluginFindQuery *query; | |
5989 const void *dicom; | |
5990 uint32_t size; | |
5991 uint32_t index; | |
5992 uint32_t *resultUint32; | |
5993 uint16_t *resultGroup; | |
5994 uint16_t *resultElement; | |
5995 char **resultString; | |
5996 } _OrthancPluginFindOperation; | |
5997 | |
5998 /** | |
5999 * @brief Add one answer to some C-Find request. | |
6000 * | |
6001 * This function adds one answer (encoded as a DICOM file) to the | |
6002 * set of answers corresponding to some C-Find SCP request that is | |
6003 * not related to modality worklists. | |
6004 * | |
6005 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6006 * @param answers The set of answers. | |
6007 * @param dicom The answer to be added, encoded as a DICOM file. | |
6008 * @param size The size of the DICOM file. | |
6009 * @return 0 if success, other value if error. | |
6010 * @ingroup DicomCallbacks | |
6011 * @see OrthancPluginCreateDicom() | |
6012 **/ | |
6013 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindAddAnswer( | |
6014 OrthancPluginContext* context, | |
6015 OrthancPluginFindAnswers* answers, | |
6016 const void* dicom, | |
6017 uint32_t size) | |
6018 { | |
6019 _OrthancPluginFindOperation params; | |
6020 memset(¶ms, 0, sizeof(params)); | |
6021 params.answers = answers; | |
6022 params.dicom = dicom; | |
6023 params.size = size; | |
6024 | |
6025 return context->InvokeService(context, _OrthancPluginService_FindAddAnswer, ¶ms); | |
6026 } | |
6027 | |
6028 | |
6029 /** | |
6030 * @brief Mark the set of C-Find answers as incomplete. | |
6031 * | |
6032 * This function marks as incomplete the set of answers | |
6033 * corresponding to some C-Find SCP request that is not related to | |
6034 * modality worklists. This must be used if canceling the handling | |
6035 * of a request when too many answers are to be returned. | |
6036 * | |
6037 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6038 * @param answers The set of answers. | |
6039 * @return 0 if success, other value if error. | |
6040 * @ingroup DicomCallbacks | |
6041 **/ | |
6042 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindMarkIncomplete( | |
6043 OrthancPluginContext* context, | |
6044 OrthancPluginFindAnswers* answers) | |
6045 { | |
6046 _OrthancPluginFindOperation params; | |
6047 memset(¶ms, 0, sizeof(params)); | |
6048 params.answers = answers; | |
6049 | |
6050 return context->InvokeService(context, _OrthancPluginService_FindMarkIncomplete, ¶ms); | |
6051 } | |
6052 | |
6053 | |
6054 | |
6055 /** | |
6056 * @brief Get the number of tags in a C-Find query. | |
6057 * | |
6058 * This function returns the number of tags that are contained in | |
6059 * the given C-Find query. | |
6060 * | |
6061 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6062 * @param query The C-Find query. | |
6063 * @return The number of tags. | |
6064 * @ingroup DicomCallbacks | |
6065 **/ | |
6066 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFindQuerySize( | |
6067 OrthancPluginContext* context, | |
6068 const OrthancPluginFindQuery* query) | |
6069 { | |
6070 uint32_t count = 0; | |
6071 | |
6072 _OrthancPluginFindOperation params; | |
6073 memset(¶ms, 0, sizeof(params)); | |
6074 params.query = query; | |
6075 params.resultUint32 = &count; | |
6076 | |
6077 if (context->InvokeService(context, _OrthancPluginService_GetFindQuerySize, ¶ms) != OrthancPluginErrorCode_Success) | |
6078 { | |
6079 /* Error */ | |
6080 return 0; | |
6081 } | |
6082 else | |
6083 { | |
6084 return count; | |
6085 } | |
6086 } | |
6087 | |
6088 | |
6089 /** | |
6090 * @brief Get one tag in a C-Find query. | |
6091 * | |
6092 * This function returns the group and the element of one DICOM tag | |
6093 * in the given C-Find query. | |
6094 * | |
6095 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6096 * @param group The group of the tag (output). | |
6097 * @param element The element of the tag (output). | |
6098 * @param query The C-Find query. | |
6099 * @param index The index of the tag of interest. | |
6100 * @return 0 if success, other value if error. | |
6101 * @ingroup DicomCallbacks | |
6102 **/ | |
6103 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetFindQueryTag( | |
6104 OrthancPluginContext* context, | |
6105 uint16_t* group, | |
6106 uint16_t* element, | |
6107 const OrthancPluginFindQuery* query, | |
6108 uint32_t index) | |
6109 { | |
6110 _OrthancPluginFindOperation params; | |
6111 memset(¶ms, 0, sizeof(params)); | |
6112 params.query = query; | |
6113 params.index = index; | |
6114 params.resultGroup = group; | |
6115 params.resultElement = element; | |
6116 | |
6117 return context->InvokeService(context, _OrthancPluginService_GetFindQueryTag, ¶ms); | |
6118 } | |
6119 | |
6120 | |
6121 /** | |
6122 * @brief Get the symbolic name of one tag in a C-Find query. | |
6123 * | |
6124 * This function returns the symbolic name of one DICOM tag in the | |
6125 * given C-Find query. | |
6126 * | |
6127 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6128 * @param query The C-Find query. | |
6129 * @param index The index of the tag of interest. | |
6130 * @return The NULL value in case of error, or a string containing the name of the tag. | |
6131 * @return 0 if success, other value if error. | |
6132 * @ingroup DicomCallbacks | |
6133 **/ | |
6134 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryTagName( | |
6135 OrthancPluginContext* context, | |
6136 const OrthancPluginFindQuery* query, | |
6137 uint32_t index) | |
6138 { | |
6139 char* result; | |
6140 | |
6141 _OrthancPluginFindOperation params; | |
6142 memset(¶ms, 0, sizeof(params)); | |
6143 params.query = query; | |
6144 params.index = index; | |
6145 params.resultString = &result; | |
6146 | |
6147 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryTagName, ¶ms) != OrthancPluginErrorCode_Success) | |
6148 { | |
6149 /* Error */ | |
6150 return NULL; | |
6151 } | |
6152 else | |
6153 { | |
6154 return result; | |
6155 } | |
6156 } | |
6157 | |
6158 | |
6159 /** | |
6160 * @brief Get the value associated with one tag in a C-Find query. | |
6161 * | |
6162 * This function returns the value associated with one tag in the | |
6163 * given C-Find query. | |
6164 * | |
6165 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6166 * @param query The C-Find query. | |
6167 * @param index The index of the tag of interest. | |
6168 * @return The NULL value in case of error, or a string containing the value of the tag. | |
6169 * @return 0 if success, other value if error. | |
6170 * @ingroup DicomCallbacks | |
6171 **/ | |
6172 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryValue( | |
6173 OrthancPluginContext* context, | |
6174 const OrthancPluginFindQuery* query, | |
6175 uint32_t index) | |
6176 { | |
6177 char* result; | |
6178 | |
6179 _OrthancPluginFindOperation params; | |
6180 memset(¶ms, 0, sizeof(params)); | |
6181 params.query = query; | |
6182 params.index = index; | |
6183 params.resultString = &result; | |
6184 | |
6185 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryValue, ¶ms) != OrthancPluginErrorCode_Success) | |
6186 { | |
6187 /* Error */ | |
6188 return NULL; | |
6189 } | |
6190 else | |
6191 { | |
6192 return result; | |
6193 } | |
6194 } | |
6195 | |
6196 | |
6197 | |
6198 | |
6199 typedef struct | |
6200 { | |
6201 OrthancPluginMoveCallback callback; | |
6202 OrthancPluginGetMoveSize getMoveSize; | |
6203 OrthancPluginApplyMove applyMove; | |
6204 OrthancPluginFreeMove freeMove; | |
6205 } _OrthancPluginMoveCallback; | |
6206 | |
6207 /** | |
6208 * @brief Register a callback to handle C-Move requests. | |
6209 * | |
6210 * This function registers a callback to handle C-Move SCP requests. | |
6211 * | |
6212 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6213 * @param callback The main callback. | |
6214 * @param getMoveSize Callback to read the number of C-Move suboperations. | |
6215 * @param applyMove Callback to apply one C-Move suboperation. | |
6216 * @param freeMove Callback to free the C-Move driver. | |
6217 * @return 0 if success, other value if error. | |
6218 * @ingroup DicomCallbacks | |
6219 **/ | |
6220 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterMoveCallback( | |
6221 OrthancPluginContext* context, | |
6222 OrthancPluginMoveCallback callback, | |
6223 OrthancPluginGetMoveSize getMoveSize, | |
6224 OrthancPluginApplyMove applyMove, | |
6225 OrthancPluginFreeMove freeMove) | |
6226 { | |
6227 _OrthancPluginMoveCallback params; | |
6228 params.callback = callback; | |
6229 params.getMoveSize = getMoveSize; | |
6230 params.applyMove = applyMove; | |
6231 params.freeMove = freeMove; | |
6232 | |
6233 return context->InvokeService(context, _OrthancPluginService_RegisterMoveCallback, ¶ms); | |
6234 } | |
6235 | |
6236 | |
6237 | |
6238 typedef struct | |
6239 { | |
6240 OrthancPluginFindMatcher** target; | |
6241 const void* query; | |
6242 uint32_t size; | |
6243 } _OrthancPluginCreateFindMatcher; | |
6244 | |
6245 | |
6246 /** | |
6247 * @brief Create a C-Find matcher. | |
6248 * | |
6249 * This function creates a "matcher" object that can be used to | |
6250 * check whether a DICOM instance matches a C-Find query. The C-Find | |
6251 * query must be expressed as a DICOM buffer. | |
6252 * | |
6253 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6254 * @param query The C-Find DICOM query. | |
6255 * @param size The size of the DICOM query. | |
6256 * @return The newly allocated matcher. It must be freed with OrthancPluginFreeFindMatcher(). | |
6257 * @ingroup Toolbox | |
6258 **/ | |
6259 ORTHANC_PLUGIN_INLINE OrthancPluginFindMatcher* OrthancPluginCreateFindMatcher( | |
6260 OrthancPluginContext* context, | |
6261 const void* query, | |
6262 uint32_t size) | |
6263 { | |
6264 OrthancPluginFindMatcher* target = NULL; | |
6265 | |
6266 _OrthancPluginCreateFindMatcher params; | |
6267 memset(¶ms, 0, sizeof(params)); | |
6268 params.target = ⌖ | |
6269 params.query = query; | |
6270 params.size = size; | |
6271 | |
6272 if (context->InvokeService(context, _OrthancPluginService_CreateFindMatcher, ¶ms) != OrthancPluginErrorCode_Success) | |
6273 { | |
6274 return NULL; | |
6275 } | |
6276 else | |
6277 { | |
6278 return target; | |
6279 } | |
6280 } | |
6281 | |
6282 | |
6283 typedef struct | |
6284 { | |
6285 OrthancPluginFindMatcher* matcher; | |
6286 } _OrthancPluginFreeFindMatcher; | |
6287 | |
6288 /** | |
6289 * @brief Free a C-Find matcher. | |
6290 * | |
6291 * This function frees a matcher that was created using OrthancPluginCreateFindMatcher(). | |
6292 * | |
6293 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6294 * @param matcher The matcher of interest. | |
6295 * @ingroup Toolbox | |
6296 **/ | |
6297 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeFindMatcher( | |
6298 OrthancPluginContext* context, | |
6299 OrthancPluginFindMatcher* matcher) | |
6300 { | |
6301 _OrthancPluginFreeFindMatcher params; | |
6302 params.matcher = matcher; | |
6303 | |
6304 context->InvokeService(context, _OrthancPluginService_FreeFindMatcher, ¶ms); | |
6305 } | |
6306 | |
6307 | |
6308 typedef struct | |
6309 { | |
6310 const OrthancPluginFindMatcher* matcher; | |
6311 const void* dicom; | |
6312 uint32_t size; | |
6313 int32_t* isMatch; | |
6314 } _OrthancPluginFindMatcherIsMatch; | |
6315 | |
6316 /** | |
6317 * @brief Test whether a DICOM instance matches a C-Find query. | |
6318 * | |
6319 * This function checks whether one DICOM instance matches C-Find | |
6320 * matcher that was previously allocated using | |
6321 * OrthancPluginCreateFindMatcher(). | |
6322 * | |
6323 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6324 * @param matcher The matcher of interest. | |
6325 * @param dicom The DICOM instance to be matched. | |
6326 * @param size The size of the DICOM instance. | |
6327 * @return 1 if the DICOM instance matches the query, 0 otherwise. | |
6328 * @ingroup Toolbox | |
6329 **/ | |
6330 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginFindMatcherIsMatch( | |
6331 OrthancPluginContext* context, | |
6332 const OrthancPluginFindMatcher* matcher, | |
6333 const void* dicom, | |
6334 uint32_t size) | |
6335 { | |
6336 int32_t isMatch = 0; | |
6337 | |
6338 _OrthancPluginFindMatcherIsMatch params; | |
6339 params.matcher = matcher; | |
6340 params.dicom = dicom; | |
6341 params.size = size; | |
6342 params.isMatch = &isMatch; | |
6343 | |
6344 if (context->InvokeService(context, _OrthancPluginService_FindMatcherIsMatch, ¶ms) == OrthancPluginErrorCode_Success) | |
6345 { | |
6346 return isMatch; | |
6347 } | |
6348 else | |
6349 { | |
6350 /* Error: Assume non-match */ | |
6351 return 0; | |
6352 } | |
6353 } | |
6354 | |
6355 | |
6356 typedef struct | |
6357 { | |
6358 OrthancPluginIncomingHttpRequestFilter2 callback; | |
6359 } _OrthancPluginIncomingHttpRequestFilter2; | |
6360 | |
6361 /** | |
6362 * @brief Register a callback to filter incoming HTTP requests. | |
6363 * | |
6364 * This function registers a custom callback to filter incoming HTTP/REST | |
6365 * requests received by the HTTP server of Orthanc. | |
6366 * | |
6367 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6368 * @param callback The callback. | |
6369 * @return 0 if success, other value if error. | |
6370 * @ingroup Callbacks | |
6371 **/ | |
6372 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter2( | |
6373 OrthancPluginContext* context, | |
6374 OrthancPluginIncomingHttpRequestFilter2 callback) | |
6375 { | |
6376 _OrthancPluginIncomingHttpRequestFilter2 params; | |
6377 params.callback = callback; | |
6378 | |
6379 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter2, ¶ms); | |
6380 } | |
6381 | |
6382 | |
6383 | |
6384 typedef struct | |
6385 { | |
6386 OrthancPluginPeers** peers; | |
6387 } _OrthancPluginGetPeers; | |
6388 | |
6389 /** | |
6390 * @brief Return the list of available Orthanc peers. | |
6391 * | |
6392 * This function returns the parameters of the Orthanc peers that are known to | |
6393 * the Orthanc server hosting the plugin. | |
6394 * | |
6395 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6396 * @return NULL if error, or a newly allocated opaque data structure containing the peers. | |
6397 * This structure must be freed with OrthancPluginFreePeers(). | |
6398 * @ingroup Toolbox | |
6399 **/ | |
6400 ORTHANC_PLUGIN_INLINE OrthancPluginPeers* OrthancPluginGetPeers( | |
6401 OrthancPluginContext* context) | |
6402 { | |
6403 OrthancPluginPeers* peers = NULL; | |
6404 | |
6405 _OrthancPluginGetPeers params; | |
6406 memset(¶ms, 0, sizeof(params)); | |
6407 params.peers = &peers; | |
6408 | |
6409 if (context->InvokeService(context, _OrthancPluginService_GetPeers, ¶ms) != OrthancPluginErrorCode_Success) | |
6410 { | |
6411 return NULL; | |
6412 } | |
6413 else | |
6414 { | |
6415 return peers; | |
6416 } | |
6417 } | |
6418 | |
6419 | |
6420 typedef struct | |
6421 { | |
6422 OrthancPluginPeers* peers; | |
6423 } _OrthancPluginFreePeers; | |
6424 | |
6425 /** | |
6426 * @brief Free the list of available Orthanc peers. | |
6427 * | |
6428 * This function frees the data structure returned by OrthancPluginGetPeers(). | |
6429 * | |
6430 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6431 * @param peers The data structure describing the Orthanc peers. | |
6432 * @ingroup Toolbox | |
6433 **/ | |
6434 ORTHANC_PLUGIN_INLINE void OrthancPluginFreePeers( | |
6435 OrthancPluginContext* context, | |
6436 OrthancPluginPeers* peers) | |
6437 { | |
6438 _OrthancPluginFreePeers params; | |
6439 params.peers = peers; | |
6440 | |
6441 context->InvokeService(context, _OrthancPluginService_FreePeers, ¶ms); | |
6442 } | |
6443 | |
6444 | |
6445 typedef struct | |
6446 { | |
6447 uint32_t* target; | |
6448 const OrthancPluginPeers* peers; | |
6449 } _OrthancPluginGetPeersCount; | |
6450 | |
6451 /** | |
6452 * @brief Get the number of Orthanc peers. | |
6453 * | |
6454 * This function returns the number of Orthanc peers. | |
6455 * | |
6456 * This function is thread-safe: Several threads sharing the same | |
6457 * OrthancPluginPeers object can simultaneously call this function. | |
6458 * | |
6459 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6460 * @param peers The data structure describing the Orthanc peers. | |
6461 * @result The number of peers. | |
6462 * @ingroup Toolbox | |
6463 **/ | |
6464 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetPeersCount( | |
6465 OrthancPluginContext* context, | |
6466 const OrthancPluginPeers* peers) | |
6467 { | |
6468 uint32_t target = 0; | |
6469 | |
6470 _OrthancPluginGetPeersCount params; | |
6471 memset(¶ms, 0, sizeof(params)); | |
6472 params.target = ⌖ | |
6473 params.peers = peers; | |
6474 | |
6475 if (context->InvokeService(context, _OrthancPluginService_GetPeersCount, ¶ms) != OrthancPluginErrorCode_Success) | |
6476 { | |
6477 /* Error */ | |
6478 return 0; | |
6479 } | |
6480 else | |
6481 { | |
6482 return target; | |
6483 } | |
6484 } | |
6485 | |
6486 | |
6487 typedef struct | |
6488 { | |
6489 const char** target; | |
6490 const OrthancPluginPeers* peers; | |
6491 uint32_t peerIndex; | |
6492 const char* userProperty; | |
6493 } _OrthancPluginGetPeerProperty; | |
6494 | |
6495 /** | |
6496 * @brief Get the symbolic name of an Orthanc peer. | |
6497 * | |
6498 * This function returns the symbolic name of the Orthanc peer, | |
6499 * which corresponds to the key of the "OrthancPeers" configuration | |
6500 * option of Orthanc. | |
6501 * | |
6502 * This function is thread-safe: Several threads sharing the same | |
6503 * OrthancPluginPeers object can simultaneously call this function. | |
6504 * | |
6505 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6506 * @param peers The data structure describing the Orthanc peers. | |
6507 * @param peerIndex The index of the peer of interest. | |
6508 * This value must be lower than OrthancPluginGetPeersCount(). | |
6509 * @result The symbolic name, or NULL in the case of an error. | |
6510 * @ingroup Toolbox | |
6511 **/ | |
6512 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerName( | |
6513 OrthancPluginContext* context, | |
6514 const OrthancPluginPeers* peers, | |
6515 uint32_t peerIndex) | |
6516 { | |
6517 const char* target = NULL; | |
6518 | |
6519 _OrthancPluginGetPeerProperty params; | |
6520 memset(¶ms, 0, sizeof(params)); | |
6521 params.target = ⌖ | |
6522 params.peers = peers; | |
6523 params.peerIndex = peerIndex; | |
6524 params.userProperty = NULL; | |
6525 | |
6526 if (context->InvokeService(context, _OrthancPluginService_GetPeerName, ¶ms) != OrthancPluginErrorCode_Success) | |
6527 { | |
6528 /* Error */ | |
6529 return NULL; | |
6530 } | |
6531 else | |
6532 { | |
6533 return target; | |
6534 } | |
6535 } | |
6536 | |
6537 | |
6538 /** | |
6539 * @brief Get the base URL of an Orthanc peer. | |
6540 * | |
6541 * This function returns the base URL to the REST API of some Orthanc peer. | |
6542 * | |
6543 * This function is thread-safe: Several threads sharing the same | |
6544 * OrthancPluginPeers object can simultaneously call this function. | |
6545 * | |
6546 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6547 * @param peers The data structure describing the Orthanc peers. | |
6548 * @param peerIndex The index of the peer of interest. | |
6549 * This value must be lower than OrthancPluginGetPeersCount(). | |
6550 * @result The URL, or NULL in the case of an error. | |
6551 * @ingroup Toolbox | |
6552 **/ | |
6553 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUrl( | |
6554 OrthancPluginContext* context, | |
6555 const OrthancPluginPeers* peers, | |
6556 uint32_t peerIndex) | |
6557 { | |
6558 const char* target = NULL; | |
6559 | |
6560 _OrthancPluginGetPeerProperty params; | |
6561 memset(¶ms, 0, sizeof(params)); | |
6562 params.target = ⌖ | |
6563 params.peers = peers; | |
6564 params.peerIndex = peerIndex; | |
6565 params.userProperty = NULL; | |
6566 | |
6567 if (context->InvokeService(context, _OrthancPluginService_GetPeerUrl, ¶ms) != OrthancPluginErrorCode_Success) | |
6568 { | |
6569 /* Error */ | |
6570 return NULL; | |
6571 } | |
6572 else | |
6573 { | |
6574 return target; | |
6575 } | |
6576 } | |
6577 | |
6578 | |
6579 | |
6580 /** | |
6581 * @brief Get some user-defined property of an Orthanc peer. | |
6582 * | |
6583 * This function returns some user-defined property of some Orthanc | |
6584 * peer. An user-defined property is a property that is associated | |
6585 * with the peer in the Orthanc configuration file, but that is not | |
6586 * recognized by the Orthanc core. | |
6587 * | |
6588 * This function is thread-safe: Several threads sharing the same | |
6589 * OrthancPluginPeers object can simultaneously call this function. | |
6590 * | |
6591 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6592 * @param peers The data structure describing the Orthanc peers. | |
6593 * @param peerIndex The index of the peer of interest. | |
6594 * This value must be lower than OrthancPluginGetPeersCount(). | |
6595 * @param userProperty The user property of interest. | |
6596 * @result The value of the user property, or NULL if it is not defined. | |
6597 * @ingroup Toolbox | |
6598 **/ | |
6599 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUserProperty( | |
6600 OrthancPluginContext* context, | |
6601 const OrthancPluginPeers* peers, | |
6602 uint32_t peerIndex, | |
6603 const char* userProperty) | |
6604 { | |
6605 const char* target = NULL; | |
6606 | |
6607 _OrthancPluginGetPeerProperty params; | |
6608 memset(¶ms, 0, sizeof(params)); | |
6609 params.target = ⌖ | |
6610 params.peers = peers; | |
6611 params.peerIndex = peerIndex; | |
6612 params.userProperty = userProperty; | |
6613 | |
6614 if (context->InvokeService(context, _OrthancPluginService_GetPeerUserProperty, ¶ms) != OrthancPluginErrorCode_Success) | |
6615 { | |
6616 /* No such user property */ | |
6617 return NULL; | |
6618 } | |
6619 else | |
6620 { | |
6621 return target; | |
6622 } | |
6623 } | |
6624 | |
6625 | |
6626 | |
6627 typedef struct | |
6628 { | |
6629 OrthancPluginMemoryBuffer* answerBody; | |
6630 OrthancPluginMemoryBuffer* answerHeaders; | |
6631 uint16_t* httpStatus; | |
6632 const OrthancPluginPeers* peers; | |
6633 uint32_t peerIndex; | |
6634 OrthancPluginHttpMethod method; | |
6635 const char* uri; | |
6636 uint32_t additionalHeadersCount; | |
6637 const char* const* additionalHeadersKeys; | |
6638 const char* const* additionalHeadersValues; | |
6639 const void* body; | |
6640 uint32_t bodySize; | |
6641 uint32_t timeout; | |
6642 } _OrthancPluginCallPeerApi; | |
6643 | |
6644 /** | |
6645 * @brief Call the REST API of an Orthanc peer. | |
6646 * | |
6647 * Make a REST call to the given URI in the REST API of a remote | |
6648 * Orthanc peer. The result to the query is stored into a newly | |
6649 * allocated memory buffer. The HTTP request will be done according | |
6650 * to the "OrthancPeers" configuration option of Orthanc. | |
6651 * | |
6652 * This function is thread-safe: Several threads sharing the same | |
6653 * OrthancPluginPeers object can simultaneously call this function. | |
6654 * | |
6655 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6656 * @param answerBody The target memory buffer (out argument). | |
6657 * It must be freed with OrthancPluginFreeMemoryBuffer(). | |
6658 * The value of this argument is ignored if the HTTP method is DELETE. | |
6659 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument). | |
6660 * The answer headers are formatted as a JSON object (associative array). | |
6661 * The buffer must be freed with OrthancPluginFreeMemoryBuffer(). | |
6662 * This argument can be set to NULL if the plugin has no interest in the HTTP headers. | |
6663 * @param httpStatus The HTTP status after the execution of the request (out argument). | |
6664 * @param peers The data structure describing the Orthanc peers. | |
6665 * @param peerIndex The index of the peer of interest. | |
6666 * This value must be lower than OrthancPluginGetPeersCount(). | |
6667 * @param method HTTP method to be used. | |
6668 * @param uri The URI of interest in the REST API. | |
6669 * @param additionalHeadersCount The number of HTTP headers to be added to the | |
6670 * HTTP headers provided in the global configuration of Orthanc. | |
6671 * @param additionalHeadersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header). | |
6672 * @param additionalHeadersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header). | |
6673 * @param body The HTTP body for a POST or PUT request. | |
6674 * @param bodySize The size of the body. | |
6675 * @param timeout Timeout in seconds (0 for default timeout). | |
6676 * @return 0 if success, or the error code if failure. | |
6677 * @see OrthancPluginHttpClient() | |
6678 * @ingroup Toolbox | |
6679 **/ | |
6680 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCallPeerApi( | |
6681 OrthancPluginContext* context, | |
6682 OrthancPluginMemoryBuffer* answerBody, | |
6683 OrthancPluginMemoryBuffer* answerHeaders, | |
6684 uint16_t* httpStatus, | |
6685 const OrthancPluginPeers* peers, | |
6686 uint32_t peerIndex, | |
6687 OrthancPluginHttpMethod method, | |
6688 const char* uri, | |
6689 uint32_t additionalHeadersCount, | |
6690 const char* const* additionalHeadersKeys, | |
6691 const char* const* additionalHeadersValues, | |
6692 const void* body, | |
6693 uint32_t bodySize, | |
6694 uint32_t timeout) | |
6695 { | |
6696 _OrthancPluginCallPeerApi params; | |
6697 memset(¶ms, 0, sizeof(params)); | |
6698 | |
6699 params.answerBody = answerBody; | |
6700 params.answerHeaders = answerHeaders; | |
6701 params.httpStatus = httpStatus; | |
6702 params.peers = peers; | |
6703 params.peerIndex = peerIndex; | |
6704 params.method = method; | |
6705 params.uri = uri; | |
6706 params.additionalHeadersCount = additionalHeadersCount; | |
6707 params.additionalHeadersKeys = additionalHeadersKeys; | |
6708 params.additionalHeadersValues = additionalHeadersValues; | |
6709 params.body = body; | |
6710 params.bodySize = bodySize; | |
6711 params.timeout = timeout; | |
6712 | |
6713 return context->InvokeService(context, _OrthancPluginService_CallPeerApi, ¶ms); | |
6714 } | |
6715 | |
6716 | |
6717 | |
6718 | |
6719 | |
6720 typedef struct | |
6721 { | |
6722 OrthancPluginJob** target; | |
6723 void *job; | |
6724 OrthancPluginJobFinalize finalize; | |
6725 const char *type; | |
6726 OrthancPluginJobGetProgress getProgress; | |
6727 OrthancPluginJobGetContent getContent; | |
6728 OrthancPluginJobGetSerialized getSerialized; | |
6729 OrthancPluginJobStep step; | |
6730 OrthancPluginJobStop stop; | |
6731 OrthancPluginJobReset reset; | |
6732 } _OrthancPluginCreateJob; | |
6733 | |
6734 /** | |
6735 * @brief Create a custom job. | |
6736 * | |
6737 * This function creates a custom job to be run by the jobs engine | |
6738 * of Orthanc. | |
6739 * | |
6740 * Orthanc starts one dedicated thread per custom job that is | |
6741 * running. It is guaranteed that all the callbacks will only be | |
6742 * called from this single dedicated thread, in mutual exclusion: As | |
6743 * a consequence, it is *not* mandatory to protect the various | |
6744 * callbacks by mutexes. | |
6745 * | |
6746 * The custom job can nonetheless launch its own processing threads | |
6747 * on the first call to the "step()" callback, and stop them once | |
6748 * the "stop()" callback is called. | |
6749 * | |
6750 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6751 * @param job The job to be executed. | |
6752 * @param finalize The finalization callback. | |
6753 * @param type The type of the job, provided to the job unserializer. | |
6754 * See OrthancPluginRegisterJobsUnserializer(). | |
6755 * @param getProgress The progress callback. | |
6756 * @param getContent The content callback. | |
6757 * @param getSerialized The serialization callback. | |
6758 * @param step The callback to execute the individual steps of the job. | |
6759 * @param stop The callback that is invoked once the job leaves the "running" state. | |
6760 * @param reset The callback that is invoked if a stopped job is started again. | |
6761 * @return The newly allocated job. It must be freed with OrthancPluginFreeJob(), | |
6762 * as long as it is not submitted with OrthancPluginSubmitJob(). | |
6763 * @ingroup Toolbox | |
6764 * @deprecated This signature should not be used anymore since Orthanc SDK 1.11.3. | |
6765 **/ | |
6766 ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob( | |
6767 OrthancPluginContext *context, | |
6768 void *job, | |
6769 OrthancPluginJobFinalize finalize, | |
6770 const char *type, | |
6771 OrthancPluginJobGetProgress getProgress, | |
6772 OrthancPluginJobGetContent getContent, | |
6773 OrthancPluginJobGetSerialized getSerialized, | |
6774 OrthancPluginJobStep step, | |
6775 OrthancPluginJobStop stop, | |
6776 OrthancPluginJobReset reset) | |
6777 { | |
6778 OrthancPluginJob* target = NULL; | |
6779 | |
6780 _OrthancPluginCreateJob params; | |
6781 memset(¶ms, 0, sizeof(params)); | |
6782 | |
6783 params.target = ⌖ | |
6784 params.job = job; | |
6785 params.finalize = finalize; | |
6786 params.type = type; | |
6787 params.getProgress = getProgress; | |
6788 params.getContent = getContent; | |
6789 params.getSerialized = getSerialized; | |
6790 params.step = step; | |
6791 params.stop = stop; | |
6792 params.reset = reset; | |
6793 | |
6794 if (context->InvokeService(context, _OrthancPluginService_CreateJob, ¶ms) != OrthancPluginErrorCode_Success || | |
6795 target == NULL) | |
6796 { | |
6797 /* Error */ | |
6798 return NULL; | |
6799 } | |
6800 else | |
6801 { | |
6802 return target; | |
6803 } | |
6804 } | |
6805 | |
6806 | |
6807 typedef struct | |
6808 { | |
6809 OrthancPluginJob** target; | |
6810 void *job; | |
6811 OrthancPluginJobFinalize finalize; | |
6812 const char *type; | |
6813 OrthancPluginJobGetProgress getProgress; | |
6814 OrthancPluginJobGetContent2 getContent; | |
6815 OrthancPluginJobGetSerialized2 getSerialized; | |
6816 OrthancPluginJobStep step; | |
6817 OrthancPluginJobStop stop; | |
6818 OrthancPluginJobReset reset; | |
6819 } _OrthancPluginCreateJob2; | |
6820 | |
6821 /** | |
6822 * @brief Create a custom job. | |
6823 * | |
6824 * This function creates a custom job to be run by the jobs engine | |
6825 * of Orthanc. | |
6826 * | |
6827 * Orthanc starts one dedicated thread per custom job that is | |
6828 * running. It is guaranteed that all the callbacks will only be | |
6829 * called from this single dedicated thread, in mutual exclusion: As | |
6830 * a consequence, it is *not* mandatory to protect the various | |
6831 * callbacks by mutexes. | |
6832 * | |
6833 * The custom job can nonetheless launch its own processing threads | |
6834 * on the first call to the "step()" callback, and stop them once | |
6835 * the "stop()" callback is called. | |
6836 * | |
6837 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6838 * @param job The job to be executed. | |
6839 * @param finalize The finalization callback. | |
6840 * @param type The type of the job, provided to the job unserializer. | |
6841 * See OrthancPluginRegisterJobsUnserializer(). | |
6842 * @param getProgress The progress callback. | |
6843 * @param getContent The content callback. | |
6844 * @param getSerialized The serialization callback. | |
6845 * @param step The callback to execute the individual steps of the job. | |
6846 * @param stop The callback that is invoked once the job leaves the "running" state. | |
6847 * @param reset The callback that is invoked if a stopped job is started again. | |
6848 * @return The newly allocated job. It must be freed with OrthancPluginFreeJob(), | |
6849 * as long as it is not submitted with OrthancPluginSubmitJob(). | |
6850 * @ingroup Toolbox | |
6851 **/ | |
6852 ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob2( | |
6853 OrthancPluginContext *context, | |
6854 void *job, | |
6855 OrthancPluginJobFinalize finalize, | |
6856 const char *type, | |
6857 OrthancPluginJobGetProgress getProgress, | |
6858 OrthancPluginJobGetContent2 getContent, | |
6859 OrthancPluginJobGetSerialized2 getSerialized, | |
6860 OrthancPluginJobStep step, | |
6861 OrthancPluginJobStop stop, | |
6862 OrthancPluginJobReset reset) | |
6863 { | |
6864 OrthancPluginJob* target = NULL; | |
6865 | |
6866 _OrthancPluginCreateJob2 params; | |
6867 memset(¶ms, 0, sizeof(params)); | |
6868 | |
6869 params.target = ⌖ | |
6870 params.job = job; | |
6871 params.finalize = finalize; | |
6872 params.type = type; | |
6873 params.getProgress = getProgress; | |
6874 params.getContent = getContent; | |
6875 params.getSerialized = getSerialized; | |
6876 params.step = step; | |
6877 params.stop = stop; | |
6878 params.reset = reset; | |
6879 | |
6880 if (context->InvokeService(context, _OrthancPluginService_CreateJob2, ¶ms) != OrthancPluginErrorCode_Success || | |
6881 target == NULL) | |
6882 { | |
6883 /* Error */ | |
6884 return NULL; | |
6885 } | |
6886 else | |
6887 { | |
6888 return target; | |
6889 } | |
6890 } | |
6891 | |
6892 | |
6893 typedef struct | |
6894 { | |
6895 OrthancPluginJob* job; | |
6896 } _OrthancPluginFreeJob; | |
6897 | |
6898 /** | |
6899 * @brief Free a custom job. | |
6900 * | |
6901 * This function frees an image that was created with OrthancPluginCreateJob(). | |
6902 * | |
6903 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6904 * @param job The job. | |
6905 * @ingroup Toolbox | |
6906 **/ | |
6907 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeJob( | |
6908 OrthancPluginContext* context, | |
6909 OrthancPluginJob* job) | |
6910 { | |
6911 _OrthancPluginFreeJob params; | |
6912 params.job = job; | |
6913 | |
6914 context->InvokeService(context, _OrthancPluginService_FreeJob, ¶ms); | |
6915 } | |
6916 | |
6917 | |
6918 | |
6919 typedef struct | |
6920 { | |
6921 char** resultId; | |
6922 OrthancPluginJob *job; | |
6923 int priority; | |
6924 } _OrthancPluginSubmitJob; | |
6925 | |
6926 /** | |
6927 * @brief Submit a new job to the jobs engine of Orthanc. | |
6928 * | |
6929 * This function adds the given job to the pending jobs of | |
6930 * Orthanc. Orthanc will take take of freeing it by invoking the | |
6931 * finalization callback provided to OrthancPluginCreateJob(). | |
6932 * | |
6933 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6934 * @param job The job, as received by OrthancPluginCreateJob(). | |
6935 * @param priority The priority of the job. | |
6936 * @return ID of the newly-submitted job. This string must be freed by OrthancPluginFreeString(). | |
6937 * @ingroup Toolbox | |
6938 **/ | |
6939 ORTHANC_PLUGIN_INLINE char *OrthancPluginSubmitJob( | |
6940 OrthancPluginContext *context, | |
6941 OrthancPluginJob *job, | |
6942 int priority) | |
6943 { | |
6944 char* resultId = NULL; | |
6945 | |
6946 _OrthancPluginSubmitJob params; | |
6947 memset(¶ms, 0, sizeof(params)); | |
6948 | |
6949 params.resultId = &resultId; | |
6950 params.job = job; | |
6951 params.priority = priority; | |
6952 | |
6953 if (context->InvokeService(context, _OrthancPluginService_SubmitJob, ¶ms) != OrthancPluginErrorCode_Success || | |
6954 resultId == NULL) | |
6955 { | |
6956 /* Error */ | |
6957 return NULL; | |
6958 } | |
6959 else | |
6960 { | |
6961 return resultId; | |
6962 } | |
6963 } | |
6964 | |
6965 | |
6966 | |
6967 typedef struct | |
6968 { | |
6969 OrthancPluginJobsUnserializer unserializer; | |
6970 } _OrthancPluginJobsUnserializer; | |
6971 | |
6972 /** | |
6973 * @brief Register an unserializer for custom jobs. | |
6974 * | |
6975 * This function registers an unserializer that decodes custom jobs | |
6976 * from a JSON string. This callback is invoked when the jobs engine | |
6977 * of Orthanc is started (on Orthanc initialization), for each job | |
6978 * that is stored in the Orthanc database. | |
6979 * | |
6980 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
6981 * @param unserializer The job unserializer. | |
6982 * @ingroup Callbacks | |
6983 **/ | |
6984 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterJobsUnserializer( | |
6985 OrthancPluginContext* context, | |
6986 OrthancPluginJobsUnserializer unserializer) | |
6987 { | |
6988 _OrthancPluginJobsUnserializer params; | |
6989 params.unserializer = unserializer; | |
6990 | |
6991 context->InvokeService(context, _OrthancPluginService_RegisterJobsUnserializer, ¶ms); | |
6992 } | |
6993 | |
6994 | |
6995 | |
6996 typedef struct | |
6997 { | |
6998 OrthancPluginRestOutput* output; | |
6999 const char* details; | |
7000 uint8_t log; | |
7001 } _OrthancPluginSetHttpErrorDetails; | |
7002 | |
7003 /** | |
7004 * @brief Provide a detailed description for an HTTP error. | |
7005 * | |
7006 * This function sets the detailed description associated with an | |
7007 * HTTP error. This description will be displayed in the "Details" | |
7008 * field of the JSON body of the HTTP answer. It is only taken into | |
7009 * consideration if the REST callback returns an error code that is | |
7010 * different from "OrthancPluginErrorCode_Success", and if the | |
7011 * "HttpDescribeErrors" configuration option of Orthanc is set to | |
7012 * "true". | |
7013 * | |
7014 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7015 * @param output The HTTP connection to the client application. | |
7016 * @param details The details of the error message. | |
7017 * @param log Whether to also write the detailed error to the Orthanc logs. | |
7018 * @ingroup REST | |
7019 **/ | |
7020 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpErrorDetails( | |
7021 OrthancPluginContext* context, | |
7022 OrthancPluginRestOutput* output, | |
7023 const char* details, | |
7024 uint8_t log) | |
7025 { | |
7026 _OrthancPluginSetHttpErrorDetails params; | |
7027 params.output = output; | |
7028 params.details = details; | |
7029 params.log = log; | |
7030 context->InvokeService(context, _OrthancPluginService_SetHttpErrorDetails, ¶ms); | |
7031 } | |
7032 | |
7033 | |
7034 | |
7035 typedef struct | |
7036 { | |
7037 const char** result; | |
7038 const char* argument; | |
7039 } _OrthancPluginRetrieveStaticString; | |
7040 | |
7041 /** | |
7042 * @brief Detect the MIME type of a file. | |
7043 * | |
7044 * This function returns the MIME type of a file by inspecting its extension. | |
7045 * | |
7046 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7047 * @param path Path to the file. | |
7048 * @return The MIME type. This is a statically-allocated | |
7049 * string, do not free it. | |
7050 * @ingroup Toolbox | |
7051 **/ | |
7052 ORTHANC_PLUGIN_INLINE const char* OrthancPluginAutodetectMimeType( | |
7053 OrthancPluginContext* context, | |
7054 const char* path) | |
7055 { | |
7056 const char* result = NULL; | |
7057 | |
7058 _OrthancPluginRetrieveStaticString params; | |
7059 params.result = &result; | |
7060 params.argument = path; | |
7061 | |
7062 if (context->InvokeService(context, _OrthancPluginService_AutodetectMimeType, ¶ms) != OrthancPluginErrorCode_Success) | |
7063 { | |
7064 /* Error */ | |
7065 return NULL; | |
7066 } | |
7067 else | |
7068 { | |
7069 return result; | |
7070 } | |
7071 } | |
7072 | |
7073 | |
7074 | |
7075 typedef struct | |
7076 { | |
7077 const char* name; | |
7078 float value; | |
7079 OrthancPluginMetricsType type; | |
7080 } _OrthancPluginSetMetricsValue; | |
7081 | |
7082 /** | |
7083 * @brief Set the value of a floating-point metrics. | |
7084 * | |
7085 * This function sets the value of a floating-point metrics to | |
7086 * monitor the behavior of the plugin through tools such as | |
7087 * Prometheus. The values of all the metrics are stored within the | |
7088 * Orthanc context. | |
7089 * | |
7090 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7091 * @param name The name of the metrics to be set. | |
7092 * @param value The value of the metrics. | |
7093 * @param type The type of the metrics. This parameter is only taken into consideration | |
7094 * the first time this metrics is set. | |
7095 * @ingroup Toolbox | |
7096 * @see OrthancPluginSetMetricsIntegerValue() | |
7097 **/ | |
7098 ORTHANC_PLUGIN_INLINE void OrthancPluginSetMetricsValue( | |
7099 OrthancPluginContext* context, | |
7100 const char* name, | |
7101 float value, | |
7102 OrthancPluginMetricsType type) | |
7103 { | |
7104 _OrthancPluginSetMetricsValue params; | |
7105 params.name = name; | |
7106 params.value = value; | |
7107 params.type = type; | |
7108 context->InvokeService(context, _OrthancPluginService_SetMetricsValue, ¶ms); | |
7109 } | |
7110 | |
7111 | |
7112 | |
7113 typedef struct | |
7114 { | |
7115 OrthancPluginRefreshMetricsCallback callback; | |
7116 } _OrthancPluginRegisterRefreshMetricsCallback; | |
7117 | |
7118 /** | |
7119 * @brief Register a callback to refresh the metrics. | |
7120 * | |
7121 * This function registers a callback to refresh the metrics. The | |
7122 * callback must make calls to OrthancPluginSetMetricsValue() or | |
7123 * OrthancPluginSetMetricsIntegerValue(). | |
7124 * | |
7125 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7126 * @param callback The callback function to handle the refresh. | |
7127 * @ingroup Callbacks | |
7128 **/ | |
7129 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRefreshMetricsCallback( | |
7130 OrthancPluginContext* context, | |
7131 OrthancPluginRefreshMetricsCallback callback) | |
7132 { | |
7133 _OrthancPluginRegisterRefreshMetricsCallback params; | |
7134 params.callback = callback; | |
7135 context->InvokeService(context, _OrthancPluginService_RegisterRefreshMetricsCallback, ¶ms); | |
7136 } | |
7137 | |
7138 | |
7139 | |
7140 | |
7141 typedef struct | |
7142 { | |
7143 char** target; | |
7144 const void* dicom; | |
7145 uint32_t dicomSize; | |
7146 OrthancPluginDicomWebBinaryCallback callback; | |
7147 } _OrthancPluginEncodeDicomWeb; | |
7148 | |
7149 /** | |
7150 * @brief Convert a DICOM instance to DICOMweb JSON. | |
7151 * | |
7152 * This function converts a memory buffer containing a DICOM instance, | |
7153 * into its DICOMweb JSON representation. | |
7154 * | |
7155 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7156 * @param dicom Pointer to the DICOM instance. | |
7157 * @param dicomSize Size of the DICOM instance. | |
7158 * @param callback Callback to set the value of the binary tags. | |
7159 * @see OrthancPluginCreateDicom() | |
7160 * @return The NULL value in case of error, or the JSON document. This string must | |
7161 * be freed by OrthancPluginFreeString(). | |
7162 * @deprecated OrthancPluginEncodeDicomWebJson2() | |
7163 * @ingroup Toolbox | |
7164 **/ | |
7165 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson( | |
7166 OrthancPluginContext* context, | |
7167 const void* dicom, | |
7168 uint32_t dicomSize, | |
7169 OrthancPluginDicomWebBinaryCallback callback) | |
7170 { | |
7171 char* target = NULL; | |
7172 | |
7173 _OrthancPluginEncodeDicomWeb params; | |
7174 params.target = ⌖ | |
7175 params.dicom = dicom; | |
7176 params.dicomSize = dicomSize; | |
7177 params.callback = callback; | |
7178 | |
7179 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebJson, ¶ms) != OrthancPluginErrorCode_Success) | |
7180 { | |
7181 /* Error */ | |
7182 return NULL; | |
7183 } | |
7184 else | |
7185 { | |
7186 return target; | |
7187 } | |
7188 } | |
7189 | |
7190 | |
7191 /** | |
7192 * @brief Convert a DICOM instance to DICOMweb XML. | |
7193 * | |
7194 * This function converts a memory buffer containing a DICOM instance, | |
7195 * into its DICOMweb XML representation. | |
7196 * | |
7197 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7198 * @param dicom Pointer to the DICOM instance. | |
7199 * @param dicomSize Size of the DICOM instance. | |
7200 * @param callback Callback to set the value of the binary tags. | |
7201 * @return The NULL value in case of error, or the XML document. This string must | |
7202 * be freed by OrthancPluginFreeString(). | |
7203 * @see OrthancPluginCreateDicom() | |
7204 * @deprecated OrthancPluginEncodeDicomWebXml2() | |
7205 * @ingroup Toolbox | |
7206 **/ | |
7207 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebXml( | |
7208 OrthancPluginContext* context, | |
7209 const void* dicom, | |
7210 uint32_t dicomSize, | |
7211 OrthancPluginDicomWebBinaryCallback callback) | |
7212 { | |
7213 char* target = NULL; | |
7214 | |
7215 _OrthancPluginEncodeDicomWeb params; | |
7216 params.target = ⌖ | |
7217 params.dicom = dicom; | |
7218 params.dicomSize = dicomSize; | |
7219 params.callback = callback; | |
7220 | |
7221 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebXml, ¶ms) != OrthancPluginErrorCode_Success) | |
7222 { | |
7223 /* Error */ | |
7224 return NULL; | |
7225 } | |
7226 else | |
7227 { | |
7228 return target; | |
7229 } | |
7230 } | |
7231 | |
7232 | |
7233 | |
7234 typedef struct | |
7235 { | |
7236 char** target; | |
7237 const void* dicom; | |
7238 uint32_t dicomSize; | |
7239 OrthancPluginDicomWebBinaryCallback2 callback; | |
7240 void* payload; | |
7241 } _OrthancPluginEncodeDicomWeb2; | |
7242 | |
7243 /** | |
7244 * @brief Convert a DICOM instance to DICOMweb JSON. | |
7245 * | |
7246 * This function converts a memory buffer containing a DICOM instance, | |
7247 * into its DICOMweb JSON representation. | |
7248 * | |
7249 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7250 * @param dicom Pointer to the DICOM instance. | |
7251 * @param dicomSize Size of the DICOM instance. | |
7252 * @param callback Callback to set the value of the binary tags. | |
7253 * @param payload User payload. | |
7254 * @return The NULL value in case of error, or the JSON document. This string must | |
7255 * be freed by OrthancPluginFreeString(). | |
7256 * @see OrthancPluginCreateDicom() | |
7257 * @ingroup Toolbox | |
7258 **/ | |
7259 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson2( | |
7260 OrthancPluginContext* context, | |
7261 const void* dicom, | |
7262 uint32_t dicomSize, | |
7263 OrthancPluginDicomWebBinaryCallback2 callback, | |
7264 void* payload) | |
7265 { | |
7266 char* target = NULL; | |
7267 | |
7268 _OrthancPluginEncodeDicomWeb2 params; | |
7269 params.target = ⌖ | |
7270 params.dicom = dicom; | |
7271 params.dicomSize = dicomSize; | |
7272 params.callback = callback; | |
7273 params.payload = payload; | |
7274 | |
7275 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebJson2, ¶ms) != OrthancPluginErrorCode_Success) | |
7276 { | |
7277 /* Error */ | |
7278 return NULL; | |
7279 } | |
7280 else | |
7281 { | |
7282 return target; | |
7283 } | |
7284 } | |
7285 | |
7286 | |
7287 /** | |
7288 * @brief Convert a DICOM instance to DICOMweb XML. | |
7289 * | |
7290 * This function converts a memory buffer containing a DICOM instance, | |
7291 * into its DICOMweb XML representation. | |
7292 * | |
7293 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7294 * @param dicom Pointer to the DICOM instance. | |
7295 * @param dicomSize Size of the DICOM instance. | |
7296 * @param callback Callback to set the value of the binary tags. | |
7297 * @param payload User payload. | |
7298 * @return The NULL value in case of error, or the XML document. This string must | |
7299 * be freed by OrthancPluginFreeString(). | |
7300 * @see OrthancPluginCreateDicom() | |
7301 * @ingroup Toolbox | |
7302 **/ | |
7303 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebXml2( | |
7304 OrthancPluginContext* context, | |
7305 const void* dicom, | |
7306 uint32_t dicomSize, | |
7307 OrthancPluginDicomWebBinaryCallback2 callback, | |
7308 void* payload) | |
7309 { | |
7310 char* target = NULL; | |
7311 | |
7312 _OrthancPluginEncodeDicomWeb2 params; | |
7313 params.target = ⌖ | |
7314 params.dicom = dicom; | |
7315 params.dicomSize = dicomSize; | |
7316 params.callback = callback; | |
7317 params.payload = payload; | |
7318 | |
7319 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebXml2, ¶ms) != OrthancPluginErrorCode_Success) | |
7320 { | |
7321 /* Error */ | |
7322 return NULL; | |
7323 } | |
7324 else | |
7325 { | |
7326 return target; | |
7327 } | |
7328 } | |
7329 | |
7330 | |
7331 | |
7332 /** | |
7333 * @brief Callback executed when a HTTP header is received during a chunked transfer. | |
7334 * | |
7335 * Signature of a callback function that is called by Orthanc acting | |
7336 * as a HTTP client during a chunked HTTP transfer, as soon as it | |
7337 * receives one HTTP header from the answer of the remote HTTP | |
7338 * server. | |
7339 * | |
7340 * @see OrthancPluginChunkedHttpClient() | |
7341 * @param answer The user payload, as provided by the calling plugin. | |
7342 * @param key The key of the HTTP header. | |
7343 * @param value The value of the HTTP header. | |
7344 * @return 0 if success, or the error code if failure. | |
7345 * @ingroup Toolbox | |
7346 **/ | |
7347 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientAnswerAddHeader) ( | |
7348 void* answer, | |
7349 const char* key, | |
7350 const char* value); | |
7351 | |
7352 | |
7353 /** | |
7354 * @brief Callback executed when an answer chunk is received during a chunked transfer. | |
7355 * | |
7356 * Signature of a callback function that is called by Orthanc acting | |
7357 * as a HTTP client during a chunked HTTP transfer, as soon as it | |
7358 * receives one data chunk from the answer of the remote HTTP | |
7359 * server. | |
7360 * | |
7361 * @see OrthancPluginChunkedHttpClient() | |
7362 * @param answer The user payload, as provided by the calling plugin. | |
7363 * @param data The content of the data chunk. | |
7364 * @param size The size of the data chunk. | |
7365 * @return 0 if success, or the error code if failure. | |
7366 * @ingroup Toolbox | |
7367 **/ | |
7368 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientAnswerAddChunk) ( | |
7369 void* answer, | |
7370 const void* data, | |
7371 uint32_t size); | |
7372 | |
7373 | |
7374 /** | |
7375 * @brief Callback to know whether the request body is entirely read during a chunked transfer | |
7376 * | |
7377 * Signature of a callback function that is called by Orthanc acting | |
7378 * as a HTTP client during a chunked HTTP transfer, while reading | |
7379 * the body of a POST or PUT request. The plugin must answer "1" as | |
7380 * soon as the body is entirely read: The "request" data structure | |
7381 * must act as an iterator. | |
7382 * | |
7383 * @see OrthancPluginChunkedHttpClient() | |
7384 * @param request The user payload, as provided by the calling plugin. | |
7385 * @return "1" if the body is over, or "0" if there is still data to be read. | |
7386 * @ingroup Toolbox | |
7387 **/ | |
7388 typedef uint8_t (*OrthancPluginChunkedClientRequestIsDone) (void* request); | |
7389 | |
7390 | |
7391 /** | |
7392 * @brief Callback to advance in the request body during a chunked transfer | |
7393 * | |
7394 * Signature of a callback function that is called by Orthanc acting | |
7395 * as a HTTP client during a chunked HTTP transfer, while reading | |
7396 * the body of a POST or PUT request. This function asks the plugin | |
7397 * to advance to the next chunk of data of the request body: The | |
7398 * "request" data structure must act as an iterator. | |
7399 * | |
7400 * @see OrthancPluginChunkedHttpClient() | |
7401 * @param request The user payload, as provided by the calling plugin. | |
7402 * @return 0 if success, or the error code if failure. | |
7403 * @ingroup Toolbox | |
7404 **/ | |
7405 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientRequestNext) (void* request); | |
7406 | |
7407 | |
7408 /** | |
7409 * @brief Callback to read the current chunk of the request body during a chunked transfer | |
7410 * | |
7411 * Signature of a callback function that is called by Orthanc acting | |
7412 * as a HTTP client during a chunked HTTP transfer, while reading | |
7413 * the body of a POST or PUT request. The plugin must provide the | |
7414 * content of the current chunk of data of the request body. | |
7415 * | |
7416 * @see OrthancPluginChunkedHttpClient() | |
7417 * @param request The user payload, as provided by the calling plugin. | |
7418 * @return The content of the current request chunk. | |
7419 * @ingroup Toolbox | |
7420 **/ | |
7421 typedef const void* (*OrthancPluginChunkedClientRequestGetChunkData) (void* request); | |
7422 | |
7423 | |
7424 /** | |
7425 * @brief Callback to read the size of the current request chunk during a chunked transfer | |
7426 * | |
7427 * Signature of a callback function that is called by Orthanc acting | |
7428 * as a HTTP client during a chunked HTTP transfer, while reading | |
7429 * the body of a POST or PUT request. The plugin must provide the | |
7430 * size of the current chunk of data of the request body. | |
7431 * | |
7432 * @see OrthancPluginChunkedHttpClient() | |
7433 * @param request The user payload, as provided by the calling plugin. | |
7434 * @return The size of the current request chunk. | |
7435 * @ingroup Toolbox | |
7436 **/ | |
7437 typedef uint32_t (*OrthancPluginChunkedClientRequestGetChunkSize) (void* request); | |
7438 | |
7439 | |
7440 typedef struct | |
7441 { | |
7442 void* answer; | |
7443 OrthancPluginChunkedClientAnswerAddChunk answerAddChunk; | |
7444 OrthancPluginChunkedClientAnswerAddHeader answerAddHeader; | |
7445 uint16_t* httpStatus; | |
7446 OrthancPluginHttpMethod method; | |
7447 const char* url; | |
7448 uint32_t headersCount; | |
7449 const char* const* headersKeys; | |
7450 const char* const* headersValues; | |
7451 void* request; | |
7452 OrthancPluginChunkedClientRequestIsDone requestIsDone; | |
7453 OrthancPluginChunkedClientRequestGetChunkData requestChunkData; | |
7454 OrthancPluginChunkedClientRequestGetChunkSize requestChunkSize; | |
7455 OrthancPluginChunkedClientRequestNext requestNext; | |
7456 const char* username; | |
7457 const char* password; | |
7458 uint32_t timeout; | |
7459 const char* certificateFile; | |
7460 const char* certificateKeyFile; | |
7461 const char* certificateKeyPassword; | |
7462 uint8_t pkcs11; | |
7463 } _OrthancPluginChunkedHttpClient; | |
7464 | |
7465 | |
7466 /** | |
7467 * @brief Issue a HTTP call, using chunked HTTP transfers. | |
7468 * | |
7469 * Make a HTTP call to the given URL using chunked HTTP | |
7470 * transfers. The request body is provided as an iterator over data | |
7471 * chunks. The answer is provided as a sequence of function calls | |
7472 * with the individual HTTP headers and answer chunks. | |
7473 * | |
7474 * Contrarily to OrthancPluginHttpClient() that entirely stores the | |
7475 * request body and the answer body in memory buffers, this function | |
7476 * uses chunked HTTP transfers. This results in a lower memory | |
7477 * consumption. Pay attention to the fact that Orthanc servers with | |
7478 * version <= 1.5.6 do not support chunked transfers: You must use | |
7479 * OrthancPluginHttpClient() if contacting such older servers. | |
7480 * | |
7481 * The HTTP request will be done accordingly to the global | |
7482 * configuration of Orthanc (in particular, the options "HttpProxy", | |
7483 * "HttpTimeout", "HttpsVerifyPeers", "HttpsCACertificates", and | |
7484 * "Pkcs11" will be taken into account). | |
7485 * | |
7486 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7487 * @param answer The user payload for the answer body. It will be provided to the callbacks for the answer. | |
7488 * @param answerAddChunk Callback function to report a data chunk from the answer body. | |
7489 * @param answerAddHeader Callback function to report an HTTP header sent by the remote server. | |
7490 * @param httpStatus The HTTP status after the execution of the request (out argument). | |
7491 * @param method HTTP method to be used. | |
7492 * @param url The URL of interest. | |
7493 * @param headersCount The number of HTTP headers. | |
7494 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header). | |
7495 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header). | |
7496 * @param request The user payload containing the request body, and acting as an iterator. | |
7497 * It will be provided to the callbacks for the request. | |
7498 * @param requestIsDone Callback function to tell whether the request body is entirely read. | |
7499 * @param requestChunkData Callback function to get the content of the current data chunk of the request body. | |
7500 * @param requestChunkSize Callback function to get the size of the current data chunk of the request body. | |
7501 * @param requestNext Callback function to advance to the next data chunk of the request body. | |
7502 * @param username The username (can be <tt>NULL</tt> if no password protection). | |
7503 * @param password The password (can be <tt>NULL</tt> if no password protection). | |
7504 * @param timeout Timeout in seconds (0 for default timeout). | |
7505 * @param certificateFile Path to the client certificate for HTTPS, in PEM format | |
7506 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
7507 * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format | |
7508 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
7509 * @param certificateKeyPassword Password to unlock the key of the client certificate | |
7510 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS). | |
7511 * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards. | |
7512 * @return 0 if success, or the error code if failure. | |
7513 * @see OrthancPluginHttpClient() | |
7514 * @ingroup Toolbox | |
7515 **/ | |
7516 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginChunkedHttpClient( | |
7517 OrthancPluginContext* context, | |
7518 void* answer, | |
7519 OrthancPluginChunkedClientAnswerAddChunk answerAddChunk, | |
7520 OrthancPluginChunkedClientAnswerAddHeader answerAddHeader, | |
7521 uint16_t* httpStatus, | |
7522 OrthancPluginHttpMethod method, | |
7523 const char* url, | |
7524 uint32_t headersCount, | |
7525 const char* const* headersKeys, | |
7526 const char* const* headersValues, | |
7527 void* request, | |
7528 OrthancPluginChunkedClientRequestIsDone requestIsDone, | |
7529 OrthancPluginChunkedClientRequestGetChunkData requestChunkData, | |
7530 OrthancPluginChunkedClientRequestGetChunkSize requestChunkSize, | |
7531 OrthancPluginChunkedClientRequestNext requestNext, | |
7532 const char* username, | |
7533 const char* password, | |
7534 uint32_t timeout, | |
7535 const char* certificateFile, | |
7536 const char* certificateKeyFile, | |
7537 const char* certificateKeyPassword, | |
7538 uint8_t pkcs11) | |
7539 { | |
7540 _OrthancPluginChunkedHttpClient params; | |
7541 memset(¶ms, 0, sizeof(params)); | |
7542 | |
7543 /* In common with OrthancPluginHttpClient() */ | |
7544 params.httpStatus = httpStatus; | |
7545 params.method = method; | |
7546 params.url = url; | |
7547 params.headersCount = headersCount; | |
7548 params.headersKeys = headersKeys; | |
7549 params.headersValues = headersValues; | |
7550 params.username = username; | |
7551 params.password = password; | |
7552 params.timeout = timeout; | |
7553 params.certificateFile = certificateFile; | |
7554 params.certificateKeyFile = certificateKeyFile; | |
7555 params.certificateKeyPassword = certificateKeyPassword; | |
7556 params.pkcs11 = pkcs11; | |
7557 | |
7558 /* For chunked body/answer */ | |
7559 params.answer = answer; | |
7560 params.answerAddChunk = answerAddChunk; | |
7561 params.answerAddHeader = answerAddHeader; | |
7562 params.request = request; | |
7563 params.requestIsDone = requestIsDone; | |
7564 params.requestChunkData = requestChunkData; | |
7565 params.requestChunkSize = requestChunkSize; | |
7566 params.requestNext = requestNext; | |
7567 | |
7568 return context->InvokeService(context, _OrthancPluginService_ChunkedHttpClient, ¶ms); | |
7569 } | |
7570 | |
7571 | |
7572 | |
7573 /** | |
7574 * @brief Opaque structure that reads the content of a HTTP request body during a chunked HTTP transfer. | |
7575 * @ingroup Callbacks | |
7576 **/ | |
7577 typedef struct _OrthancPluginServerChunkedRequestReader_t OrthancPluginServerChunkedRequestReader; | |
7578 | |
7579 | |
7580 | |
7581 /** | |
7582 * @brief Callback to create a reader to handle incoming chunked HTTP transfers. | |
7583 * | |
7584 * Signature of a callback function that is called by Orthanc acting | |
7585 * as a HTTP server that supports chunked HTTP transfers. This | |
7586 * callback is only invoked if the HTTP method is POST or PUT. The | |
7587 * callback must create an user-specific "reader" object that will | |
7588 * be fed with the body of the incoming body. | |
7589 * | |
7590 * @see OrthancPluginRegisterChunkedRestCallback() | |
7591 * @param reader Memory location that must be filled with the newly-created reader. | |
7592 * @param url The URI that is accessed. | |
7593 * @param request The body of the HTTP request. Note that "body" and "bodySize" are not used. | |
7594 * @return 0 if success, or the error code if failure. | |
7595 **/ | |
7596 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderFactory) ( | |
7597 OrthancPluginServerChunkedRequestReader** reader, | |
7598 const char* url, | |
7599 const OrthancPluginHttpRequest* request); | |
7600 | |
7601 | |
7602 /** | |
7603 * @brief Callback invoked whenever a new data chunk is available during a chunked transfer. | |
7604 * | |
7605 * Signature of a callback function that is called by Orthanc acting | |
7606 * as a HTTP server that supports chunked HTTP transfers. This callback | |
7607 * is invoked as soon as a new data chunk is available for the request body. | |
7608 * | |
7609 * @see OrthancPluginRegisterChunkedRestCallback() | |
7610 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback. | |
7611 * @param data The content of the data chunk. | |
7612 * @param size The size of the data chunk. | |
7613 * @return 0 if success, or the error code if failure. | |
7614 **/ | |
7615 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderAddChunk) ( | |
7616 OrthancPluginServerChunkedRequestReader* reader, | |
7617 const void* data, | |
7618 uint32_t size); | |
7619 | |
7620 | |
7621 /** | |
7622 * @brief Callback invoked whenever the request body is entirely received. | |
7623 * | |
7624 * Signature of a callback function that is called by Orthanc acting | |
7625 * as a HTTP server that supports chunked HTTP transfers. This | |
7626 * callback is invoked as soon as the full body of the HTTP request | |
7627 * is available. The plugin can then send its answer thanks to the | |
7628 * provided "output" object. | |
7629 * | |
7630 * @see OrthancPluginRegisterChunkedRestCallback() | |
7631 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback. | |
7632 * @param output The HTTP connection to the client application. | |
7633 * @return 0 if success, or the error code if failure. | |
7634 **/ | |
7635 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderExecute) ( | |
7636 OrthancPluginServerChunkedRequestReader* reader, | |
7637 OrthancPluginRestOutput* output); | |
7638 | |
7639 | |
7640 /** | |
7641 * @brief Callback invoked to release the resources associated with an incoming HTTP chunked transfer. | |
7642 * | |
7643 * Signature of a callback function that is called by Orthanc acting | |
7644 * as a HTTP server that supports chunked HTTP transfers. This | |
7645 * callback is invoked to release all the resources allocated by the | |
7646 * given reader. Note that this function might be invoked even if | |
7647 * the entire body was not read, to deal with client error or | |
7648 * disconnection. | |
7649 * | |
7650 * @see OrthancPluginRegisterChunkedRestCallback() | |
7651 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback. | |
7652 **/ | |
7653 typedef void (*OrthancPluginServerChunkedRequestReaderFinalize) ( | |
7654 OrthancPluginServerChunkedRequestReader* reader); | |
7655 | |
7656 typedef struct | |
7657 { | |
7658 const char* pathRegularExpression; | |
7659 OrthancPluginRestCallback getHandler; | |
7660 OrthancPluginServerChunkedRequestReaderFactory postHandler; | |
7661 OrthancPluginRestCallback deleteHandler; | |
7662 OrthancPluginServerChunkedRequestReaderFactory putHandler; | |
7663 OrthancPluginServerChunkedRequestReaderAddChunk addChunk; | |
7664 OrthancPluginServerChunkedRequestReaderExecute execute; | |
7665 OrthancPluginServerChunkedRequestReaderFinalize finalize; | |
7666 } _OrthancPluginChunkedRestCallback; | |
7667 | |
7668 | |
7669 /** | |
7670 * @brief Register a REST callback to handle chunked HTTP transfers. | |
7671 * | |
7672 * This function registers a REST callback against a regular | |
7673 * expression for a URI. This function must be called during the | |
7674 * initialization of the plugin, i.e. inside the | |
7675 * OrthancPluginInitialize() public function. | |
7676 * | |
7677 * Contrarily to OrthancPluginRegisterRestCallback(), the callbacks | |
7678 * will NOT be invoked in mutual exclusion, so it is up to the | |
7679 * plugin to implement the required locking mechanisms. | |
7680 * | |
7681 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7682 * @param pathRegularExpression Regular expression for the URI. May contain groups. | |
7683 * @param getHandler The callback function to handle REST calls using the GET HTTP method. | |
7684 * @param postHandler The callback function to handle REST calls using the POST HTTP method. | |
7685 * @param deleteHandler The callback function to handle REST calls using the DELETE HTTP method. | |
7686 * @param putHandler The callback function to handle REST calls using the PUT HTTP method. | |
7687 * @param addChunk The callback invoked when a new chunk is available for the request body of a POST or PUT call. | |
7688 * @param execute The callback invoked once the entire body of a POST or PUT call is read. | |
7689 * @param finalize The callback invoked to release the resources associated with a POST or PUT call. | |
7690 * @see OrthancPluginRegisterRestCallbackNoLock() | |
7691 * | |
7692 * @note | |
7693 * The regular expression is case sensitive and must follow the | |
7694 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html). | |
7695 * | |
7696 * @ingroup Callbacks | |
7697 **/ | |
7698 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterChunkedRestCallback( | |
7699 OrthancPluginContext* context, | |
7700 const char* pathRegularExpression, | |
7701 OrthancPluginRestCallback getHandler, | |
7702 OrthancPluginServerChunkedRequestReaderFactory postHandler, | |
7703 OrthancPluginRestCallback deleteHandler, | |
7704 OrthancPluginServerChunkedRequestReaderFactory putHandler, | |
7705 OrthancPluginServerChunkedRequestReaderAddChunk addChunk, | |
7706 OrthancPluginServerChunkedRequestReaderExecute execute, | |
7707 OrthancPluginServerChunkedRequestReaderFinalize finalize) | |
7708 { | |
7709 _OrthancPluginChunkedRestCallback params; | |
7710 params.pathRegularExpression = pathRegularExpression; | |
7711 params.getHandler = getHandler; | |
7712 params.postHandler = postHandler; | |
7713 params.deleteHandler = deleteHandler; | |
7714 params.putHandler = putHandler; | |
7715 params.addChunk = addChunk; | |
7716 params.execute = execute; | |
7717 params.finalize = finalize; | |
7718 | |
7719 context->InvokeService(context, _OrthancPluginService_RegisterChunkedRestCallback, ¶ms); | |
7720 } | |
7721 | |
7722 | |
7723 | |
7724 | |
7725 | |
7726 typedef struct | |
7727 { | |
7728 char** result; | |
7729 uint16_t group; | |
7730 uint16_t element; | |
7731 const char* privateCreator; | |
7732 } _OrthancPluginGetTagName; | |
7733 | |
7734 /** | |
7735 * @brief Returns the symbolic name of a DICOM tag. | |
7736 * | |
7737 * This function makes a lookup to the dictionary of DICOM tags that | |
7738 * are known to Orthanc, and returns the symbolic name of a DICOM tag. | |
7739 * | |
7740 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7741 * @param group The group of the tag. | |
7742 * @param element The element of the tag. | |
7743 * @param privateCreator For private tags, the name of the private creator (can be NULL). | |
7744 * @return NULL in the case of an error, or a newly allocated string | |
7745 * containing the path. This string must be freed by | |
7746 * OrthancPluginFreeString(). | |
7747 * @ingroup Toolbox | |
7748 **/ | |
7749 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetTagName( | |
7750 OrthancPluginContext* context, | |
7751 uint16_t group, | |
7752 uint16_t element, | |
7753 const char* privateCreator) | |
7754 { | |
7755 char* result; | |
7756 | |
7757 _OrthancPluginGetTagName params; | |
7758 params.result = &result; | |
7759 params.group = group; | |
7760 params.element = element; | |
7761 params.privateCreator = privateCreator; | |
7762 | |
7763 if (context->InvokeService(context, _OrthancPluginService_GetTagName, ¶ms) != OrthancPluginErrorCode_Success) | |
7764 { | |
7765 /* Error */ | |
7766 return NULL; | |
7767 } | |
7768 else | |
7769 { | |
7770 return result; | |
7771 } | |
7772 } | |
7773 | |
7774 | |
7775 | |
7776 /** | |
7777 * @brief Callback executed by the storage commitment SCP. | |
7778 * | |
7779 * Signature of a factory function that creates an object to handle | |
7780 * one incoming storage commitment request. | |
7781 * | |
7782 * @remark The factory receives the list of the SOP class/instance | |
7783 * UIDs of interest to the remote storage commitment SCU. This gives | |
7784 * the factory the possibility to start some prefetch process | |
7785 * upfront in the background, before the handler object is actually | |
7786 * queried about the status of these DICOM instances. | |
7787 * | |
7788 * @param handler Output variable where the factory puts the handler object it created. | |
7789 * @param jobId ID of the Orthanc job that is responsible for handling | |
7790 * the storage commitment request. This job will successively look for the | |
7791 * status of all the individual queried DICOM instances. | |
7792 * @param transactionUid UID of the storage commitment transaction | |
7793 * provided by the storage commitment SCU. It contains the value of the | |
7794 * (0008,1195) DICOM tag. | |
7795 * @param sopClassUids Array of the SOP class UIDs (0008,0016) that are queried by the SCU. | |
7796 * @param sopInstanceUids Array of the SOP instance UIDs (0008,0018) that are queried by the SCU. | |
7797 * @param countInstances Number of DICOM instances that are queried. This is the size | |
7798 * of the `sopClassUids` and `sopInstanceUids` arrays. | |
7799 * @param remoteAet The AET of the storage commitment SCU. | |
7800 * @param calledAet The AET used by the SCU to contact the storage commitment SCP (i.e. Orthanc). | |
7801 * @return 0 if success, other value if error. | |
7802 * @ingroup DicomCallbacks | |
7803 **/ | |
7804 typedef OrthancPluginErrorCode (*OrthancPluginStorageCommitmentFactory) ( | |
7805 void** handler /* out */, | |
7806 const char* jobId, | |
7807 const char* transactionUid, | |
7808 const char* const* sopClassUids, | |
7809 const char* const* sopInstanceUids, | |
7810 uint32_t countInstances, | |
7811 const char* remoteAet, | |
7812 const char* calledAet); | |
7813 | |
7814 | |
7815 /** | |
7816 * @brief Callback to free one storage commitment SCP handler. | |
7817 * | |
7818 * Signature of a callback function that releases the resources | |
7819 * allocated by the factory of the storage commitment SCP. The | |
7820 * handler is the return value of a previous call to the | |
7821 * OrthancPluginStorageCommitmentFactory() callback. | |
7822 * | |
7823 * @param handler The handler object to be destructed. | |
7824 * @ingroup DicomCallbacks | |
7825 **/ | |
7826 typedef void (*OrthancPluginStorageCommitmentDestructor) (void* handler); | |
7827 | |
7828 | |
7829 /** | |
7830 * @brief Callback to get the status of one DICOM instance in the | |
7831 * storage commitment SCP. | |
7832 * | |
7833 * Signature of a callback function that is successively invoked for | |
7834 * each DICOM instance that is queried by the remote storage | |
7835 * commitment SCU. The function must be tought of as a method of | |
7836 * the handler object that was created by a previous call to the | |
7837 * OrthancPluginStorageCommitmentFactory() callback. After each call | |
7838 * to this method, the progress of the associated Orthanc job is | |
7839 * updated. | |
7840 * | |
7841 * @param target Output variable where to put the status for the queried instance. | |
7842 * @param handler The handler object associated with this storage commitment request. | |
7843 * @param sopClassUid The SOP class UID (0008,0016) of interest. | |
7844 * @param sopInstanceUid The SOP instance UID (0008,0018) of interest. | |
7845 * @ingroup DicomCallbacks | |
7846 **/ | |
7847 typedef OrthancPluginErrorCode (*OrthancPluginStorageCommitmentLookup) ( | |
7848 OrthancPluginStorageCommitmentFailureReason* target, | |
7849 void* handler, | |
7850 const char* sopClassUid, | |
7851 const char* sopInstanceUid); | |
7852 | |
7853 | |
7854 typedef struct | |
7855 { | |
7856 OrthancPluginStorageCommitmentFactory factory; | |
7857 OrthancPluginStorageCommitmentDestructor destructor; | |
7858 OrthancPluginStorageCommitmentLookup lookup; | |
7859 } _OrthancPluginRegisterStorageCommitmentScpCallback; | |
7860 | |
7861 /** | |
7862 * @brief Register a callback to handle incoming requests to the storage commitment SCP. | |
7863 * | |
7864 * This function registers a callback to handle storage commitment SCP requests. | |
7865 * | |
7866 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7867 * @param factory Factory function that creates the handler object | |
7868 * for incoming storage commitment requests. | |
7869 * @param destructor Destructor function to destroy the handler object. | |
7870 * @param lookup Callback function to get the status of one DICOM instance. | |
7871 * @return 0 if success, other value if error. | |
7872 * @ingroup DicomCallbacks | |
7873 **/ | |
7874 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterStorageCommitmentScpCallback( | |
7875 OrthancPluginContext* context, | |
7876 OrthancPluginStorageCommitmentFactory factory, | |
7877 OrthancPluginStorageCommitmentDestructor destructor, | |
7878 OrthancPluginStorageCommitmentLookup lookup) | |
7879 { | |
7880 _OrthancPluginRegisterStorageCommitmentScpCallback params; | |
7881 params.factory = factory; | |
7882 params.destructor = destructor; | |
7883 params.lookup = lookup; | |
7884 return context->InvokeService(context, _OrthancPluginService_RegisterStorageCommitmentScpCallback, ¶ms); | |
7885 } | |
7886 | |
7887 | |
7888 | |
7889 /** | |
7890 * @brief Callback to filter incoming DICOM instances received by Orthanc. | |
7891 * | |
7892 * Signature of a callback function that is triggered whenever | |
7893 * Orthanc receives a new DICOM instance (e.g. through REST API or | |
7894 * DICOM protocol), and that answers whether this DICOM instance | |
7895 * should be accepted or discarded by Orthanc. | |
7896 * | |
7897 * Note that the metadata information is not available | |
7898 * (i.e. GetInstanceMetadata() should not be used on "instance"). | |
7899 * | |
7900 * @warning Your callback function will be called synchronously with | |
7901 * the core of Orthanc. This implies that deadlocks might emerge if | |
7902 * you call other core primitives of Orthanc in your callback (such | |
7903 * deadlocks are particularly visible in the presence of other plugins | |
7904 * or Lua scripts). It is thus strongly advised to avoid any call to | |
7905 * the REST API of Orthanc in the callback. If you have to call | |
7906 * other primitives of Orthanc, you should make these calls in a | |
7907 * separate thread, passing the pending events to be processed | |
7908 * through a message queue. | |
7909 * | |
7910 * @param instance The received DICOM instance. | |
7911 * @return 0 to discard the instance, 1 to store the instance, -1 if error. | |
7912 * @ingroup Callbacks | |
7913 **/ | |
7914 typedef int32_t (*OrthancPluginIncomingDicomInstanceFilter) ( | |
7915 const OrthancPluginDicomInstance* instance); | |
7916 | |
7917 | |
7918 typedef struct | |
7919 { | |
7920 OrthancPluginIncomingDicomInstanceFilter callback; | |
7921 } _OrthancPluginIncomingDicomInstanceFilter; | |
7922 | |
7923 /** | |
7924 * @brief Register a callback to filter incoming DICOM instances. | |
7925 * | |
7926 * This function registers a custom callback to filter incoming | |
7927 * DICOM instances received by Orthanc (either through the REST API | |
7928 * or through the DICOM protocol). | |
7929 * | |
7930 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7931 * @param callback The callback. | |
7932 * @return 0 if success, other value if error. | |
7933 * @ingroup Callbacks | |
7934 **/ | |
7935 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingDicomInstanceFilter( | |
7936 OrthancPluginContext* context, | |
7937 OrthancPluginIncomingDicomInstanceFilter callback) | |
7938 { | |
7939 _OrthancPluginIncomingDicomInstanceFilter params; | |
7940 params.callback = callback; | |
7941 | |
7942 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingDicomInstanceFilter, ¶ms); | |
7943 } | |
7944 | |
7945 | |
7946 /** | |
7947 * @brief Callback to filter incoming DICOM instances received by | |
7948 * Orthanc through C-STORE. | |
7949 * | |
7950 * Signature of a callback function that is triggered whenever | |
7951 * Orthanc receives a new DICOM instance using DICOM C-STORE, and | |
7952 * that answers whether this DICOM instance should be accepted or | |
7953 * discarded by Orthanc. If the instance is discarded, the callback | |
7954 * can specify the DIMSE error code answered by the Orthanc C-STORE | |
7955 * SCP. | |
7956 * | |
7957 * Note that the metadata information is not available | |
7958 * (i.e. GetInstanceMetadata() should not be used on "instance"). | |
7959 * | |
7960 * @warning Your callback function will be called synchronously with | |
7961 * the core of Orthanc. This implies that deadlocks might emerge if | |
7962 * you call other core primitives of Orthanc in your callback (such | |
7963 * deadlocks are particularly visible in the presence of other plugins | |
7964 * or Lua scripts). It is thus strongly advised to avoid any call to | |
7965 * the REST API of Orthanc in the callback. If you have to call | |
7966 * other primitives of Orthanc, you should make these calls in a | |
7967 * separate thread, passing the pending events to be processed | |
7968 * through a message queue. | |
7969 * | |
7970 * @param dimseStatus If the DICOM instance is discarded, | |
7971 * DIMSE status to be sent by the C-STORE SCP of Orthanc | |
7972 * @param instance The received DICOM instance. | |
7973 * @return 0 to discard the instance, 1 to store the instance, -1 if error. | |
7974 * @ingroup Callbacks | |
7975 **/ | |
7976 typedef int32_t (*OrthancPluginIncomingCStoreInstanceFilter) ( | |
7977 uint16_t* dimseStatus /* out */, | |
7978 const OrthancPluginDicomInstance* instance); | |
7979 | |
7980 | |
7981 typedef struct | |
7982 { | |
7983 OrthancPluginIncomingCStoreInstanceFilter callback; | |
7984 } _OrthancPluginIncomingCStoreInstanceFilter; | |
7985 | |
7986 /** | |
7987 * @brief Register a callback to filter incoming DICOM instances | |
7988 * received by Orthanc through C-STORE. | |
7989 * | |
7990 * This function registers a custom callback to filter incoming | |
7991 * DICOM instances received by Orthanc through the DICOM protocol. | |
7992 * | |
7993 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
7994 * @param callback The callback. | |
7995 * @return 0 if success, other value if error. | |
7996 * @ingroup Callbacks | |
7997 **/ | |
7998 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingCStoreInstanceFilter( | |
7999 OrthancPluginContext* context, | |
8000 OrthancPluginIncomingCStoreInstanceFilter callback) | |
8001 { | |
8002 _OrthancPluginIncomingCStoreInstanceFilter params; | |
8003 params.callback = callback; | |
8004 | |
8005 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingCStoreInstanceFilter, ¶ms); | |
8006 } | |
8007 | |
8008 /** | |
8009 * @brief Callback to keep/discard/modify a DICOM instance received | |
8010 * by Orthanc from any source (C-STORE or REST API) | |
8011 * | |
8012 * Signature of a callback function that is triggered whenever | |
8013 * Orthanc receives a new DICOM instance (through DICOM protocol or | |
8014 * REST API), and that specifies an action to be applied to this | |
8015 * newly received instance. The instance can be kept as it is, can | |
8016 * be modified by the plugin, or can be discarded. | |
8017 * | |
8018 * This callback is invoked immediately after reception, i.e. before | |
8019 * transcoding and before filtering | |
8020 * (cf. OrthancPluginRegisterIncomingDicomInstanceFilter()). | |
8021 * | |
8022 * @warning Your callback function will be called synchronously with | |
8023 * the core of Orthanc. This implies that deadlocks might emerge if | |
8024 * you call other core primitives of Orthanc in your callback (such | |
8025 * deadlocks are particularly visible in the presence of other plugins | |
8026 * or Lua scripts). It is thus strongly advised to avoid any call to | |
8027 * the REST API of Orthanc in the callback. If you have to call | |
8028 * other primitives of Orthanc, you should make these calls in a | |
8029 * separate thread, passing the pending events to be processed | |
8030 * through a message queue. | |
8031 * | |
8032 * @param modifiedDicomBuffer A buffer containing the modified DICOM (output). | |
8033 * This buffer must be allocated using OrthancPluginCreateMemoryBuffer64() | |
8034 * and will be freed by the Orthanc core. | |
8035 * @param receivedDicomBuffer A buffer containing the received DICOM (input). | |
8036 * @param receivedDicomBufferSize The size of the received DICOM (input). | |
8037 * @param origin The origin of the DICOM instance (input). | |
8038 * @return `OrthancPluginReceivedInstanceAction_KeepAsIs` to accept the instance as is,<br/> | |
8039 * `OrthancPluginReceivedInstanceAction_Modify` to store the modified DICOM contained in `modifiedDicomBuffer`,<br/> | |
8040 * `OrthancPluginReceivedInstanceAction_Discard` to tell Orthanc to discard the instance. | |
8041 * @ingroup Callbacks | |
8042 **/ | |
8043 typedef OrthancPluginReceivedInstanceAction (*OrthancPluginReceivedInstanceCallback) ( | |
8044 OrthancPluginMemoryBuffer64* modifiedDicomBuffer, | |
8045 const void* receivedDicomBuffer, | |
8046 uint64_t receivedDicomBufferSize, | |
8047 OrthancPluginInstanceOrigin origin); | |
8048 | |
8049 | |
8050 typedef struct | |
8051 { | |
8052 OrthancPluginReceivedInstanceCallback callback; | |
8053 } _OrthancPluginReceivedInstanceCallback; | |
8054 | |
8055 /** | |
8056 * @brief Register a callback to keep/discard/modify a DICOM instance received | |
8057 * by Orthanc from any source (C-STORE or REST API) | |
8058 * | |
8059 * This function registers a custom callback to keep/discard/modify | |
8060 * incoming DICOM instances received by Orthanc from any source | |
8061 * (C-STORE or REST API). | |
8062 * | |
8063 * @warning Contrarily to | |
8064 * OrthancPluginRegisterIncomingCStoreInstanceFilter() and | |
8065 * OrthancPluginRegisterIncomingDicomInstanceFilter() that can be | |
8066 * called by multiple plugins, | |
8067 * OrthancPluginRegisterReceivedInstanceCallback() can only be used | |
8068 * by one single plugin. | |
8069 * | |
8070 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8071 * @param callback The callback. | |
8072 * @return 0 if success, other value if error. | |
8073 * @ingroup Callbacks | |
8074 **/ | |
8075 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterReceivedInstanceCallback( | |
8076 OrthancPluginContext* context, | |
8077 OrthancPluginReceivedInstanceCallback callback) | |
8078 { | |
8079 _OrthancPluginReceivedInstanceCallback params; | |
8080 params.callback = callback; | |
8081 | |
8082 return context->InvokeService(context, _OrthancPluginService_RegisterReceivedInstanceCallback, ¶ms); | |
8083 } | |
8084 | |
8085 /** | |
8086 * @brief Get the transfer syntax of a DICOM file. | |
8087 * | |
8088 * This function returns a pointer to a newly created string that | |
8089 * contains the transfer syntax UID of the DICOM instance. The empty | |
8090 * string might be returned if this information is unknown. | |
8091 * | |
8092 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8093 * @param instance The instance of interest. | |
8094 * @return The NULL value in case of error, or a string containing the | |
8095 * transfer syntax UID. This string must be freed by OrthancPluginFreeString(). | |
8096 * @ingroup DicomInstance | |
8097 **/ | |
8098 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceTransferSyntaxUid( | |
8099 OrthancPluginContext* context, | |
8100 const OrthancPluginDicomInstance* instance) | |
8101 { | |
8102 char* result; | |
8103 | |
8104 _OrthancPluginAccessDicomInstance params; | |
8105 memset(¶ms, 0, sizeof(params)); | |
8106 params.resultStringToFree = &result; | |
8107 params.instance = instance; | |
8108 | |
8109 if (context->InvokeService(context, _OrthancPluginService_GetInstanceTransferSyntaxUid, ¶ms) != OrthancPluginErrorCode_Success) | |
8110 { | |
8111 /* Error */ | |
8112 return NULL; | |
8113 } | |
8114 else | |
8115 { | |
8116 return result; | |
8117 } | |
8118 } | |
8119 | |
8120 | |
8121 /** | |
8122 * @brief Check whether the DICOM file has pixel data. | |
8123 * | |
8124 * This function returns a Boolean value indicating whether the | |
8125 * DICOM instance contains the pixel data (7FE0,0010) tag. | |
8126 * | |
8127 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8128 * @param instance The instance of interest. | |
8129 * @return "1" if the DICOM instance contains pixel data, or "0" if | |
8130 * the tag is missing, or "-1" in the case of an error. | |
8131 * @ingroup DicomInstance | |
8132 **/ | |
8133 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginHasInstancePixelData( | |
8134 OrthancPluginContext* context, | |
8135 const OrthancPluginDicomInstance* instance) | |
8136 { | |
8137 int64_t hasPixelData; | |
8138 | |
8139 _OrthancPluginAccessDicomInstance params; | |
8140 memset(¶ms, 0, sizeof(params)); | |
8141 params.resultInt64 = &hasPixelData; | |
8142 params.instance = instance; | |
8143 | |
8144 if (context->InvokeService(context, _OrthancPluginService_HasInstancePixelData, ¶ms) != OrthancPluginErrorCode_Success || | |
8145 hasPixelData < 0 || | |
8146 hasPixelData > 1) | |
8147 { | |
8148 /* Error */ | |
8149 return -1; | |
8150 } | |
8151 else | |
8152 { | |
8153 return (hasPixelData != 0); | |
8154 } | |
8155 } | |
8156 | |
8157 | |
8158 | |
8159 | |
8160 | |
8161 | |
8162 typedef struct | |
8163 { | |
8164 OrthancPluginDicomInstance** target; | |
8165 const void* buffer; | |
8166 uint32_t size; | |
8167 const char* transferSyntax; | |
8168 } _OrthancPluginCreateDicomInstance; | |
8169 | |
8170 /** | |
8171 * @brief Parse a DICOM instance. | |
8172 * | |
8173 * This function parses a memory buffer that contains a DICOM | |
8174 * file. The function returns a new pointer to a data structure that | |
8175 * is managed by the Orthanc core. | |
8176 * | |
8177 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8178 * @param buffer The memory buffer containing the DICOM instance. | |
8179 * @param size The size of the memory buffer. | |
8180 * @return The newly allocated DICOM instance. It must be freed with OrthancPluginFreeDicomInstance(). | |
8181 * @ingroup DicomInstance | |
8182 **/ | |
8183 ORTHANC_PLUGIN_INLINE OrthancPluginDicomInstance* OrthancPluginCreateDicomInstance( | |
8184 OrthancPluginContext* context, | |
8185 const void* buffer, | |
8186 uint32_t size) | |
8187 { | |
8188 OrthancPluginDicomInstance* target = NULL; | |
8189 | |
8190 _OrthancPluginCreateDicomInstance params; | |
8191 params.target = ⌖ | |
8192 params.buffer = buffer; | |
8193 params.size = size; | |
8194 | |
8195 if (context->InvokeService(context, _OrthancPluginService_CreateDicomInstance, ¶ms) != OrthancPluginErrorCode_Success) | |
8196 { | |
8197 /* Error */ | |
8198 return NULL; | |
8199 } | |
8200 else | |
8201 { | |
8202 return target; | |
8203 } | |
8204 } | |
8205 | |
8206 typedef struct | |
8207 { | |
8208 OrthancPluginDicomInstance* dicom; | |
8209 } _OrthancPluginFreeDicomInstance; | |
8210 | |
8211 /** | |
8212 * @brief Free a DICOM instance. | |
8213 * | |
8214 * This function frees a DICOM instance that was parsed using | |
8215 * OrthancPluginCreateDicomInstance(). | |
8216 * | |
8217 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8218 * @param dicom The DICOM instance. | |
8219 * @ingroup DicomInstance | |
8220 **/ | |
8221 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeDicomInstance( | |
8222 OrthancPluginContext* context, | |
8223 OrthancPluginDicomInstance* dicom) | |
8224 { | |
8225 _OrthancPluginFreeDicomInstance params; | |
8226 params.dicom = dicom; | |
8227 | |
8228 context->InvokeService(context, _OrthancPluginService_FreeDicomInstance, ¶ms); | |
8229 } | |
8230 | |
8231 | |
8232 typedef struct | |
8233 { | |
8234 uint32_t* targetUint32; | |
8235 OrthancPluginMemoryBuffer* targetBuffer; | |
8236 OrthancPluginImage** targetImage; | |
8237 char** targetStringToFree; | |
8238 const OrthancPluginDicomInstance* instance; | |
8239 uint32_t frameIndex; | |
8240 OrthancPluginDicomToJsonFormat format; | |
8241 OrthancPluginDicomToJsonFlags flags; | |
8242 uint32_t maxStringLength; | |
8243 OrthancPluginDicomWebBinaryCallback2 dicomWebCallback; | |
8244 void* dicomWebPayload; | |
8245 } _OrthancPluginAccessDicomInstance2; | |
8246 | |
8247 /** | |
8248 * @brief Get the number of frames in a DICOM instance. | |
8249 * | |
8250 * This function returns the number of frames that are part of a | |
8251 * DICOM image managed by the Orthanc core. | |
8252 * | |
8253 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8254 * @param instance The instance of interest. | |
8255 * @return The number of frames (will be zero in the case of an error). | |
8256 * @ingroup DicomInstance | |
8257 **/ | |
8258 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetInstanceFramesCount( | |
8259 OrthancPluginContext* context, | |
8260 const OrthancPluginDicomInstance* instance) | |
8261 { | |
8262 uint32_t count; | |
8263 | |
8264 _OrthancPluginAccessDicomInstance2 params; | |
8265 memset(¶ms, 0, sizeof(params)); | |
8266 params.targetUint32 = &count; | |
8267 params.instance = instance; | |
8268 | |
8269 if (context->InvokeService(context, _OrthancPluginService_GetInstanceFramesCount, ¶ms) != OrthancPluginErrorCode_Success) | |
8270 { | |
8271 /* Error */ | |
8272 return 0; | |
8273 } | |
8274 else | |
8275 { | |
8276 return count; | |
8277 } | |
8278 } | |
8279 | |
8280 | |
8281 /** | |
8282 * @brief Get the raw content of a frame in a DICOM instance. | |
8283 * | |
8284 * This function returns a memory buffer containing the raw content | |
8285 * of a frame in a DICOM instance that is managed by the Orthanc | |
8286 * core. This is notably useful for compressed transfer syntaxes, as | |
8287 * it gives access to the embedded files (such as JPEG, JPEG-LS or | |
8288 * JPEG2k). The Orthanc core transparently reassembles the fragments | |
8289 * to extract the raw frame. | |
8290 * | |
8291 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8292 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
8293 * @param instance The instance of interest. | |
8294 * @param frameIndex The index of the frame of interest. | |
8295 * @return 0 if success, or the error code if failure. | |
8296 * @ingroup DicomInstance | |
8297 **/ | |
8298 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetInstanceRawFrame( | |
8299 OrthancPluginContext* context, | |
8300 OrthancPluginMemoryBuffer* target, | |
8301 const OrthancPluginDicomInstance* instance, | |
8302 uint32_t frameIndex) | |
8303 { | |
8304 _OrthancPluginAccessDicomInstance2 params; | |
8305 memset(¶ms, 0, sizeof(params)); | |
8306 params.targetBuffer = target; | |
8307 params.instance = instance; | |
8308 params.frameIndex = frameIndex; | |
8309 | |
8310 return context->InvokeService(context, _OrthancPluginService_GetInstanceRawFrame, ¶ms); | |
8311 } | |
8312 | |
8313 | |
8314 /** | |
8315 * @brief Decode one frame from a DICOM instance. | |
8316 * | |
8317 * This function decodes one frame of a DICOM image that is managed | |
8318 * by the Orthanc core. | |
8319 * | |
8320 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8321 * @param instance The instance of interest. | |
8322 * @param frameIndex The index of the frame of interest. | |
8323 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage(). | |
8324 * @ingroup DicomInstance | |
8325 **/ | |
8326 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginGetInstanceDecodedFrame( | |
8327 OrthancPluginContext* context, | |
8328 const OrthancPluginDicomInstance* instance, | |
8329 uint32_t frameIndex) | |
8330 { | |
8331 OrthancPluginImage* target = NULL; | |
8332 | |
8333 _OrthancPluginAccessDicomInstance2 params; | |
8334 memset(¶ms, 0, sizeof(params)); | |
8335 params.targetImage = ⌖ | |
8336 params.instance = instance; | |
8337 params.frameIndex = frameIndex; | |
8338 | |
8339 if (context->InvokeService(context, _OrthancPluginService_GetInstanceDecodedFrame, ¶ms) != OrthancPluginErrorCode_Success) | |
8340 { | |
8341 return NULL; | |
8342 } | |
8343 else | |
8344 { | |
8345 return target; | |
8346 } | |
8347 } | |
8348 | |
8349 | |
8350 /** | |
8351 * @brief Parse and transcode a DICOM instance. | |
8352 * | |
8353 * This function parses a memory buffer that contains a DICOM file, | |
8354 * then transcodes it to the given transfer syntax. The function | |
8355 * returns a new pointer to a data structure that is managed by the | |
8356 * Orthanc core. | |
8357 * | |
8358 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8359 * @param buffer The memory buffer containing the DICOM instance. | |
8360 * @param size The size of the memory buffer. | |
8361 * @param transferSyntax The transfer syntax UID for the transcoding. | |
8362 * @return The newly allocated DICOM instance. It must be freed with OrthancPluginFreeDicomInstance(). | |
8363 * @ingroup DicomInstance | |
8364 **/ | |
8365 ORTHANC_PLUGIN_INLINE OrthancPluginDicomInstance* OrthancPluginTranscodeDicomInstance( | |
8366 OrthancPluginContext* context, | |
8367 const void* buffer, | |
8368 uint32_t size, | |
8369 const char* transferSyntax) | |
8370 { | |
8371 OrthancPluginDicomInstance* target = NULL; | |
8372 | |
8373 _OrthancPluginCreateDicomInstance params; | |
8374 params.target = ⌖ | |
8375 params.buffer = buffer; | |
8376 params.size = size; | |
8377 params.transferSyntax = transferSyntax; | |
8378 | |
8379 if (context->InvokeService(context, _OrthancPluginService_TranscodeDicomInstance, ¶ms) != OrthancPluginErrorCode_Success) | |
8380 { | |
8381 /* Error */ | |
8382 return NULL; | |
8383 } | |
8384 else | |
8385 { | |
8386 return target; | |
8387 } | |
8388 } | |
8389 | |
8390 /** | |
8391 * @brief Writes a DICOM instance to a memory buffer. | |
8392 * | |
8393 * This function returns a memory buffer containing the | |
8394 * serialization of a DICOM instance that is managed by the Orthanc | |
8395 * core. | |
8396 * | |
8397 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8398 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
8399 * @param instance The instance of interest. | |
8400 * @return 0 if success, or the error code if failure. | |
8401 * @ingroup DicomInstance | |
8402 **/ | |
8403 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSerializeDicomInstance( | |
8404 OrthancPluginContext* context, | |
8405 OrthancPluginMemoryBuffer* target, | |
8406 const OrthancPluginDicomInstance* instance) | |
8407 { | |
8408 _OrthancPluginAccessDicomInstance2 params; | |
8409 memset(¶ms, 0, sizeof(params)); | |
8410 params.targetBuffer = target; | |
8411 params.instance = instance; | |
8412 | |
8413 return context->InvokeService(context, _OrthancPluginService_SerializeDicomInstance, ¶ms); | |
8414 } | |
8415 | |
8416 | |
8417 /** | |
8418 * @brief Format a DICOM memory buffer as a JSON string. | |
8419 * | |
8420 * This function takes as DICOM instance managed by the Orthanc | |
8421 * core, and outputs a JSON string representing the tags of this | |
8422 * DICOM file. | |
8423 * | |
8424 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8425 * @param instance The DICOM instance of interest. | |
8426 * @param format The output format. | |
8427 * @param flags Flags governing the output. | |
8428 * @param maxStringLength The maximum length of a field. Too long fields will | |
8429 * be output as "null". The 0 value means no maximum length. | |
8430 * @return The NULL value if the case of an error, or the JSON | |
8431 * string. This string must be freed by OrthancPluginFreeString(). | |
8432 * @ingroup DicomInstance | |
8433 * @see OrthancPluginDicomBufferToJson() | |
8434 **/ | |
8435 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceAdvancedJson( | |
8436 OrthancPluginContext* context, | |
8437 const OrthancPluginDicomInstance* instance, | |
8438 OrthancPluginDicomToJsonFormat format, | |
8439 OrthancPluginDicomToJsonFlags flags, | |
8440 uint32_t maxStringLength) | |
8441 { | |
8442 char* result = NULL; | |
8443 | |
8444 _OrthancPluginAccessDicomInstance2 params; | |
8445 memset(¶ms, 0, sizeof(params)); | |
8446 params.targetStringToFree = &result; | |
8447 params.instance = instance; | |
8448 params.format = format; | |
8449 params.flags = flags; | |
8450 params.maxStringLength = maxStringLength; | |
8451 | |
8452 if (context->InvokeService(context, _OrthancPluginService_GetInstanceAdvancedJson, ¶ms) != OrthancPluginErrorCode_Success) | |
8453 { | |
8454 /* Error */ | |
8455 return NULL; | |
8456 } | |
8457 else | |
8458 { | |
8459 return result; | |
8460 } | |
8461 } | |
8462 | |
8463 | |
8464 /** | |
8465 * @brief Convert a DICOM instance to DICOMweb JSON. | |
8466 * | |
8467 * This function converts a DICOM instance that is managed by the | |
8468 * Orthanc core, into its DICOMweb JSON representation. | |
8469 * | |
8470 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8471 * @param instance The DICOM instance of interest. | |
8472 * @param callback Callback to set the value of the binary tags. | |
8473 * @param payload User payload. | |
8474 * @return The NULL value in case of error, or the JSON document. This string must | |
8475 * be freed by OrthancPluginFreeString(). | |
8476 * @ingroup DicomInstance | |
8477 **/ | |
8478 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceDicomWebJson( | |
8479 OrthancPluginContext* context, | |
8480 const OrthancPluginDicomInstance* instance, | |
8481 OrthancPluginDicomWebBinaryCallback2 callback, | |
8482 void* payload) | |
8483 { | |
8484 char* target = NULL; | |
8485 | |
8486 _OrthancPluginAccessDicomInstance2 params; | |
8487 params.targetStringToFree = ⌖ | |
8488 params.instance = instance; | |
8489 params.dicomWebCallback = callback; | |
8490 params.dicomWebPayload = payload; | |
8491 | |
8492 if (context->InvokeService(context, _OrthancPluginService_GetInstanceDicomWebJson, ¶ms) != OrthancPluginErrorCode_Success) | |
8493 { | |
8494 /* Error */ | |
8495 return NULL; | |
8496 } | |
8497 else | |
8498 { | |
8499 return target; | |
8500 } | |
8501 } | |
8502 | |
8503 | |
8504 /** | |
8505 * @brief Convert a DICOM instance to DICOMweb XML. | |
8506 * | |
8507 * This function converts a DICOM instance that is managed by the | |
8508 * Orthanc core, into its DICOMweb XML representation. | |
8509 * | |
8510 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8511 * @param instance The DICOM instance of interest. | |
8512 * @param callback Callback to set the value of the binary tags. | |
8513 * @param payload User payload. | |
8514 * @return The NULL value in case of error, or the XML document. This string must | |
8515 * be freed by OrthancPluginFreeString(). | |
8516 * @ingroup DicomInstance | |
8517 **/ | |
8518 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceDicomWebXml( | |
8519 OrthancPluginContext* context, | |
8520 const OrthancPluginDicomInstance* instance, | |
8521 OrthancPluginDicomWebBinaryCallback2 callback, | |
8522 void* payload) | |
8523 { | |
8524 char* target = NULL; | |
8525 | |
8526 _OrthancPluginAccessDicomInstance2 params; | |
8527 params.targetStringToFree = ⌖ | |
8528 params.instance = instance; | |
8529 params.dicomWebCallback = callback; | |
8530 params.dicomWebPayload = payload; | |
8531 | |
8532 if (context->InvokeService(context, _OrthancPluginService_GetInstanceDicomWebXml, ¶ms) != OrthancPluginErrorCode_Success) | |
8533 { | |
8534 /* Error */ | |
8535 return NULL; | |
8536 } | |
8537 else | |
8538 { | |
8539 return target; | |
8540 } | |
8541 } | |
8542 | |
8543 | |
8544 | |
8545 /** | |
8546 * @brief Signature of a callback function to transcode a DICOM instance. | |
8547 * @param transcoded Target memory buffer. It must be allocated by the | |
8548 * plugin using OrthancPluginCreateMemoryBuffer(). | |
8549 * @param buffer Memory buffer containing the source DICOM instance. | |
8550 * @param size Size of the source memory buffer. | |
8551 * @param allowedSyntaxes A C array of possible transfer syntaxes UIDs for the | |
8552 * result of the transcoding. The plugin must choose by itself the | |
8553 * transfer syntax that will be used for the resulting DICOM image. | |
8554 * @param countSyntaxes The number of transfer syntaxes that are contained | |
8555 * in the "allowedSyntaxes" array. | |
8556 * @param allowNewSopInstanceUid Whether the transcoding plugin can select | |
8557 * a transfer syntax that will change the SOP instance UID (or, in other | |
8558 * terms, whether the plugin can transcode using lossy compression). | |
8559 * @return 0 if success (i.e. image successfully transcoded and stored into | |
8560 * "transcoded"), or the error code if failure. | |
8561 * @ingroup Callbacks | |
8562 **/ | |
8563 typedef OrthancPluginErrorCode (*OrthancPluginTranscoderCallback) ( | |
8564 OrthancPluginMemoryBuffer* transcoded /* out */, | |
8565 const void* buffer, | |
8566 uint64_t size, | |
8567 const char* const* allowedSyntaxes, | |
8568 uint32_t countSyntaxes, | |
8569 uint8_t allowNewSopInstanceUid); | |
8570 | |
8571 | |
8572 typedef struct | |
8573 { | |
8574 OrthancPluginTranscoderCallback callback; | |
8575 } _OrthancPluginTranscoderCallback; | |
8576 | |
8577 /** | |
8578 * @brief Register a callback to handle the transcoding of DICOM images. | |
8579 * | |
8580 * This function registers a custom callback to transcode DICOM | |
8581 * images, extending the built-in transcoder of Orthanc that uses | |
8582 * DCMTK. The exact behavior is affected by the configuration option | |
8583 * "BuiltinDecoderTranscoderOrder" of Orthanc. | |
8584 * | |
8585 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8586 * @param callback The callback. | |
8587 * @return 0 if success, other value if error. | |
8588 * @ingroup Callbacks | |
8589 **/ | |
8590 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterTranscoderCallback( | |
8591 OrthancPluginContext* context, | |
8592 OrthancPluginTranscoderCallback callback) | |
8593 { | |
8594 _OrthancPluginTranscoderCallback params; | |
8595 params.callback = callback; | |
8596 | |
8597 return context->InvokeService(context, _OrthancPluginService_RegisterTranscoderCallback, ¶ms); | |
8598 } | |
8599 | |
8600 | |
8601 | |
8602 typedef struct | |
8603 { | |
8604 OrthancPluginMemoryBuffer* target; | |
8605 uint32_t size; | |
8606 } _OrthancPluginCreateMemoryBuffer; | |
8607 | |
8608 /** | |
8609 * @brief Create a 32-bit memory buffer. | |
8610 * | |
8611 * This function creates a memory buffer that is managed by the | |
8612 * Orthanc core. The main use case of this function is for plugins | |
8613 * that act as DICOM transcoders. | |
8614 * | |
8615 * Your plugin should never call "free()" on the resulting memory | |
8616 * buffer, as the C library that is used by the plugin is in general | |
8617 * not the same as the one used by the Orthanc core. | |
8618 * | |
8619 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8620 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
8621 * @param size Size of the memory buffer to be created. | |
8622 * @return 0 if success, or the error code if failure. | |
8623 * @ingroup Toolbox | |
8624 **/ | |
8625 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateMemoryBuffer( | |
8626 OrthancPluginContext* context, | |
8627 OrthancPluginMemoryBuffer* target, | |
8628 uint32_t size) | |
8629 { | |
8630 _OrthancPluginCreateMemoryBuffer params; | |
8631 params.target = target; | |
8632 params.size = size; | |
8633 | |
8634 return context->InvokeService(context, _OrthancPluginService_CreateMemoryBuffer, ¶ms); | |
8635 } | |
8636 | |
8637 | |
8638 /** | |
8639 * @brief Generate a token to grant full access to the REST API of Orthanc. | |
8640 * | |
8641 * This function generates a token that can be set in the HTTP | |
8642 * header "Authorization" so as to grant full access to the REST API | |
8643 * of Orthanc using an external HTTP client. Using this function | |
8644 * avoids the need of adding a separate user in the | |
8645 * "RegisteredUsers" configuration of Orthanc, which eases | |
8646 * deployments. | |
8647 * | |
8648 * This feature is notably useful in multiprocess scenarios, where a | |
8649 * subprocess created by a plugin has no access to the | |
8650 * "OrthancPluginContext", and thus cannot call | |
8651 * "OrthancPluginRestApi[Get|Post|Put|Delete]()". | |
8652 * | |
8653 * This situation is frequently encountered in Python plugins, where | |
8654 * the "multiprocessing" package can be used to bypass the Global | |
8655 * Interpreter Lock (GIL) and thus to improve performance and | |
8656 * concurrency. | |
8657 * | |
8658 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8659 * @return The authorization token, or NULL value in the case of an error. | |
8660 * This string must be freed by OrthancPluginFreeString(). | |
8661 * @ingroup Orthanc | |
8662 **/ | |
8663 ORTHANC_PLUGIN_INLINE char* OrthancPluginGenerateRestApiAuthorizationToken( | |
8664 OrthancPluginContext* context) | |
8665 { | |
8666 char* result; | |
8667 | |
8668 _OrthancPluginRetrieveDynamicString params; | |
8669 params.result = &result; | |
8670 params.argument = NULL; | |
8671 | |
8672 if (context->InvokeService(context, _OrthancPluginService_GenerateRestApiAuthorizationToken, | |
8673 ¶ms) != OrthancPluginErrorCode_Success) | |
8674 { | |
8675 /* Error */ | |
8676 return NULL; | |
8677 } | |
8678 else | |
8679 { | |
8680 return result; | |
8681 } | |
8682 } | |
8683 | |
8684 | |
8685 | |
8686 typedef struct | |
8687 { | |
8688 OrthancPluginMemoryBuffer64* target; | |
8689 uint64_t size; | |
8690 } _OrthancPluginCreateMemoryBuffer64; | |
8691 | |
8692 /** | |
8693 * @brief Create a 64-bit memory buffer. | |
8694 * | |
8695 * This function creates a 64-bit memory buffer that is managed by | |
8696 * the Orthanc core. The main use case of this function is for | |
8697 * plugins that read files from the storage area. | |
8698 * | |
8699 * Your plugin should never call "free()" on the resulting memory | |
8700 * buffer, as the C library that is used by the plugin is in general | |
8701 * not the same as the one used by the Orthanc core. | |
8702 * | |
8703 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8704 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
8705 * @param size Size of the memory buffer to be created. | |
8706 * @return 0 if success, or the error code if failure. | |
8707 * @ingroup Toolbox | |
8708 **/ | |
8709 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateMemoryBuffer64( | |
8710 OrthancPluginContext* context, | |
8711 OrthancPluginMemoryBuffer64* target, | |
8712 uint64_t size) | |
8713 { | |
8714 _OrthancPluginCreateMemoryBuffer64 params; | |
8715 params.target = target; | |
8716 params.size = size; | |
8717 | |
8718 return context->InvokeService(context, _OrthancPluginService_CreateMemoryBuffer64, ¶ms); | |
8719 } | |
8720 | |
8721 | |
8722 typedef struct | |
8723 { | |
8724 OrthancPluginStorageCreate create; | |
8725 OrthancPluginStorageReadWhole readWhole; | |
8726 OrthancPluginStorageReadRange readRange; | |
8727 OrthancPluginStorageRemove remove; | |
8728 } _OrthancPluginRegisterStorageArea2; | |
8729 | |
8730 /** | |
8731 * @brief Register a custom storage area, with support for range request. | |
8732 * | |
8733 * This function registers a custom storage area, to replace the | |
8734 * built-in way Orthanc stores its files on the filesystem. This | |
8735 * function must be called during the initialization of the plugin, | |
8736 * i.e. inside the OrthancPluginInitialize() public function. | |
8737 * | |
8738 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8739 * @param create The callback function to store a file on the custom storage area. | |
8740 * @param readWhole The callback function to read a whole file from the custom storage area. | |
8741 * @param readRange The callback function to read some range of a file from the custom storage area. | |
8742 * If this feature is not supported by the plugin, this value can be set to NULL. | |
8743 * @param remove The callback function to remove a file from the custom storage area. | |
8744 * @ingroup Callbacks | |
8745 **/ | |
8746 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea2( | |
8747 OrthancPluginContext* context, | |
8748 OrthancPluginStorageCreate create, | |
8749 OrthancPluginStorageReadWhole readWhole, | |
8750 OrthancPluginStorageReadRange readRange, | |
8751 OrthancPluginStorageRemove remove) | |
8752 { | |
8753 _OrthancPluginRegisterStorageArea2 params; | |
8754 params.create = create; | |
8755 params.readWhole = readWhole; | |
8756 params.readRange = readRange; | |
8757 params.remove = remove; | |
8758 context->InvokeService(context, _OrthancPluginService_RegisterStorageArea2, ¶ms); | |
8759 } | |
8760 | |
8761 | |
8762 | |
8763 typedef struct | |
8764 { | |
8765 _OrthancPluginCreateDicom createDicom; | |
8766 const char* privateCreator; | |
8767 } _OrthancPluginCreateDicom2; | |
8768 | |
8769 /** | |
8770 * @brief Create a DICOM instance from a JSON string and an image, with a private creator. | |
8771 * | |
8772 * This function takes as input a string containing a JSON file | |
8773 * describing the content of a DICOM instance. As an output, it | |
8774 * writes the corresponding DICOM instance to a newly allocated | |
8775 * memory buffer. Additionally, an image to be encoded within the | |
8776 * DICOM instance can also be provided. | |
8777 * | |
8778 * Contrarily to the function OrthancPluginCreateDicom(), this | |
8779 * function can be explicitly provided with a private creator. | |
8780 * | |
8781 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8782 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). | |
8783 * @param json The input JSON file. | |
8784 * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme. | |
8785 * @param flags Flags governing the output. | |
8786 * @param privateCreator The private creator to be used for the private DICOM tags. | |
8787 * Check out the global configuration option "Dictionary" of Orthanc. | |
8788 * @return 0 if success, other value if error. | |
8789 * @ingroup Toolbox | |
8790 * @see OrthancPluginCreateDicom() | |
8791 * @see OrthancPluginDicomBufferToJson() | |
8792 **/ | |
8793 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom2( | |
8794 OrthancPluginContext* context, | |
8795 OrthancPluginMemoryBuffer* target, | |
8796 const char* json, | |
8797 const OrthancPluginImage* pixelData, | |
8798 OrthancPluginCreateDicomFlags flags, | |
8799 const char* privateCreator) | |
8800 { | |
8801 _OrthancPluginCreateDicom2 params; | |
8802 params.createDicom.target = target; | |
8803 params.createDicom.json = json; | |
8804 params.createDicom.pixelData = pixelData; | |
8805 params.createDicom.flags = flags; | |
8806 params.privateCreator = privateCreator; | |
8807 | |
8808 return context->InvokeService(context, _OrthancPluginService_CreateDicom2, ¶ms); | |
8809 } | |
8810 | |
8811 | |
8812 | |
8813 | |
8814 | |
8815 | |
8816 typedef struct | |
8817 { | |
8818 OrthancPluginMemoryBuffer* answerBody; | |
8819 OrthancPluginMemoryBuffer* answerHeaders; | |
8820 uint16_t* httpStatus; | |
8821 OrthancPluginHttpMethod method; | |
8822 const char* uri; | |
8823 uint32_t headersCount; | |
8824 const char* const* headersKeys; | |
8825 const char* const* headersValues; | |
8826 const void* body; | |
8827 uint32_t bodySize; | |
8828 uint8_t afterPlugins; | |
8829 } _OrthancPluginCallRestApi; | |
8830 | |
8831 /** | |
8832 * @brief Call the REST API of Orthanc with full flexibility. | |
8833 * | |
8834 * Make a call to the given URI in the REST API of Orthanc. The | |
8835 * result to the query is stored into a newly allocated memory | |
8836 * buffer. This function is always granted full access to the REST | |
8837 * API (no credentials, nor security token is needed). | |
8838 * | |
8839 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
8840 * @param answerBody The target memory buffer (out argument). | |
8841 * It must be freed with OrthancPluginFreeMemoryBuffer(). | |
8842 * The value of this argument is ignored if the HTTP method is DELETE. | |
8843 * @param answerHeaders The target memory buffer for the HTTP headers in the answer (out argument). | |
8844 * The answer headers are formatted as a JSON object (associative array). | |
8845 * The buffer must be freed with OrthancPluginFreeMemoryBuffer(). | |
8846 * This argument can be set to NULL if the plugin has no interest in the answer HTTP headers. | |
8847 * @param httpStatus The HTTP status after the execution of the request (out argument). | |
8848 * @param method HTTP method to be used. | |
8849 * @param uri The URI of interest. | |
8850 * @param headersCount The number of HTTP headers. | |
8851 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header). | |
8852 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header). | |
8853 * @param body The HTTP body for a POST or PUT request. | |
8854 * @param bodySize The size of the body. | |
8855 * @param afterPlugins If 0, the built-in API of Orthanc is used. | |
8856 * If 1, the API is tainted by the plugins. | |
8857 * @return 0 if success, or the error code if failure. | |
8858 * @see OrthancPluginRestApiGet2(), OrthancPluginRestApiPost(), OrthancPluginRestApiPut(), OrthancPluginRestApiDelete() | |
8859 * @ingroup Orthanc | |
8860 **/ | |
8861 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCallRestApi( | |
8862 OrthancPluginContext* context, | |
8863 OrthancPluginMemoryBuffer* answerBody, | |
8864 OrthancPluginMemoryBuffer* answerHeaders, | |
8865 uint16_t* httpStatus, | |
8866 OrthancPluginHttpMethod method, | |
8867 const char* uri, | |
8868 uint32_t headersCount, | |
8869 const char* const* headersKeys, | |
8870 const char* const* headersValues, | |
8871 const void* body, | |
8872 uint32_t bodySize, | |
8873 uint8_t afterPlugins) | |
8874 { | |
8875 _OrthancPluginCallRestApi params; | |
8876 memset(¶ms, 0, sizeof(params)); | |
8877 | |
8878 params.answerBody = answerBody; | |
8879 params.answerHeaders = answerHeaders; | |
8880 params.httpStatus = httpStatus; | |
8881 params.method = method; | |
8882 params.uri = uri; | |
8883 params.headersCount = headersCount; | |
8884 params.headersKeys = headersKeys; | |
8885 params.headersValues = headersValues; | |
8886 params.body = body; | |
8887 params.bodySize = bodySize; | |
8888 params.afterPlugins = afterPlugins; | |
8889 | |
8890 return context->InvokeService(context, _OrthancPluginService_CallRestApi, ¶ms); | |
8891 } | |
8892 | |
8893 | |
8894 | |
8895 /** | |
8896 * @brief Opaque structure that represents a WebDAV collection. | |
8897 * @ingroup Callbacks | |
8898 **/ | |
8899 typedef struct _OrthancPluginWebDavCollection_t OrthancPluginWebDavCollection; | |
8900 | |
8901 | |
8902 /** | |
8903 * @brief Declare a file while returning the content of a folder. | |
8904 * | |
8905 * This function declares a file while returning the content of a | |
8906 * WebDAV folder. | |
8907 * | |
8908 * @param collection Context of the collection. | |
8909 * @param name Base name of the file. | |
8910 * @param dateTime The date and time of creation of the file. | |
8911 * Check out the documentation of OrthancPluginWebDavRetrieveFile() for more information. | |
8912 * @param size Size of the file. | |
8913 * @param mimeType The MIME type of the file. If empty or set to `NULL`, | |
8914 * Orthanc will do a best guess depending on the file extension. | |
8915 * @return 0 if success, other value if error. | |
8916 * @ingroup Callbacks | |
8917 **/ | |
8918 typedef OrthancPluginErrorCode (*OrthancPluginWebDavAddFile) ( | |
8919 OrthancPluginWebDavCollection* collection, | |
8920 const char* name, | |
8921 uint64_t size, | |
8922 const char* mimeType, | |
8923 const char* dateTime); | |
8924 | |
8925 | |
8926 /** | |
8927 * @brief Declare a subfolder while returning the content of a folder. | |
8928 * | |
8929 * This function declares a subfolder while returning the content of a | |
8930 * WebDAV folder. | |
8931 * | |
8932 * @param collection Context of the collection. | |
8933 * @param name Base name of the subfolder. | |
8934 * @param dateTime The date and time of creation of the subfolder. | |
8935 * Check out the documentation of OrthancPluginWebDavRetrieveFile() for more information. | |
8936 * @return 0 if success, other value if error. | |
8937 * @ingroup Callbacks | |
8938 **/ | |
8939 typedef OrthancPluginErrorCode (*OrthancPluginWebDavAddFolder) ( | |
8940 OrthancPluginWebDavCollection* collection, | |
8941 const char* name, | |
8942 const char* dateTime); | |
8943 | |
8944 | |
8945 /** | |
8946 * @brief Retrieve the content of a file. | |
8947 * | |
8948 * This function is used to forward the content of a file from a | |
8949 * WebDAV collection, to the core of Orthanc. | |
8950 * | |
8951 * @param collection Context of the collection. | |
8952 * @param data Content of the file. | |
8953 * @param size Size of the file. | |
8954 * @param mimeType The MIME type of the file. If empty or set to `NULL`, | |
8955 * Orthanc will do a best guess depending on the file extension. | |
8956 * @param dateTime The date and time of creation of the file. | |
8957 * It must be formatted as an ISO string of form | |
8958 * `YYYYMMDDTHHMMSS,fffffffff` where T is the date-time | |
8959 * separator. It must be expressed in UTC (it is the responsibility | |
8960 * of the plugin to do the possible timezone | |
8961 * conversions). Internally, this string will be parsed using | |
8962 * `boost::posix_time::from_iso_string()`. | |
8963 * @return 0 if success, other value if error. | |
8964 * @ingroup Callbacks | |
8965 **/ | |
8966 typedef OrthancPluginErrorCode (*OrthancPluginWebDavRetrieveFile) ( | |
8967 OrthancPluginWebDavCollection* collection, | |
8968 const void* data, | |
8969 uint64_t size, | |
8970 const char* mimeType, | |
8971 const char* dateTime); | |
8972 | |
8973 | |
8974 /** | |
8975 * @brief Callback for testing the existence of a folder. | |
8976 * | |
8977 * Signature of a callback function that tests whether the given | |
8978 * path in the WebDAV collection exists and corresponds to a folder. | |
8979 * | |
8980 * @param isExisting Pointer to a Boolean that must be set to `1` if the folder exists, or `0` otherwise. | |
8981 * @param pathSize Number of levels in the path. | |
8982 * @param pathItems Items making the path. | |
8983 * @param payload The user payload. | |
8984 * @return 0 if success, other value if error. | |
8985 * @ingroup Callbacks | |
8986 **/ | |
8987 typedef OrthancPluginErrorCode (*OrthancPluginWebDavIsExistingFolderCallback) ( | |
8988 uint8_t* isExisting, /* out */ | |
8989 uint32_t pathSize, | |
8990 const char* const* pathItems, | |
8991 void* payload); | |
8992 | |
8993 | |
8994 /** | |
8995 * @brief Callback for listing the content of a folder. | |
8996 * | |
8997 * Signature of a callback function that lists the content of a | |
8998 * folder in the WebDAV collection. The callback must call the | |
8999 * provided `addFile()` and `addFolder()` functions to emit the | |
9000 * content of the folder. | |
9001 * | |
9002 * @param isExisting Pointer to a Boolean that must be set to `1` if the folder exists, or `0` otherwise. | |
9003 * @param collection Context to be provided to `addFile()` and `addFolder()` functions. | |
9004 * @param addFile Function to add a file to the list. | |
9005 * @param addFolder Function to add a folder to the list. | |
9006 * @param pathSize Number of levels in the path. | |
9007 * @param pathItems Items making the path. | |
9008 * @param payload The user payload. | |
9009 * @return 0 if success, other value if error. | |
9010 * @ingroup Callbacks | |
9011 **/ | |
9012 typedef OrthancPluginErrorCode (*OrthancPluginWebDavListFolderCallback) ( | |
9013 uint8_t* isExisting, /* out */ | |
9014 OrthancPluginWebDavCollection* collection, | |
9015 OrthancPluginWebDavAddFile addFile, | |
9016 OrthancPluginWebDavAddFolder addFolder, | |
9017 uint32_t pathSize, | |
9018 const char* const* pathItems, | |
9019 void* payload); | |
9020 | |
9021 | |
9022 /** | |
9023 * @brief Callback for retrieving the content of a file. | |
9024 * | |
9025 * Signature of a callback function that retrieves the content of a | |
9026 * file in the WebDAV collection. The callback must call the | |
9027 * provided `retrieveFile()` function to emit the actual content of | |
9028 * the file. | |
9029 * | |
9030 * @param collection Context to be provided to `retrieveFile()` function. | |
9031 * @param retrieveFile Function to return the content of the file. | |
9032 * @param pathSize Number of levels in the path. | |
9033 * @param pathItems Items making the path. | |
9034 * @param payload The user payload. | |
9035 * @return 0 if success, other value if error. | |
9036 * @ingroup Callbacks | |
9037 **/ | |
9038 typedef OrthancPluginErrorCode (*OrthancPluginWebDavRetrieveFileCallback) ( | |
9039 OrthancPluginWebDavCollection* collection, | |
9040 OrthancPluginWebDavRetrieveFile retrieveFile, | |
9041 uint32_t pathSize, | |
9042 const char* const* pathItems, | |
9043 void* payload); | |
9044 | |
9045 | |
9046 /** | |
9047 * @brief Callback to store a file. | |
9048 * | |
9049 * Signature of a callback function that stores a file into the | |
9050 * WebDAV collection. | |
9051 * | |
9052 * @param isReadOnly Pointer to a Boolean that must be set to `1` if the collection is read-only, or `0` otherwise. | |
9053 * @param pathSize Number of levels in the path. | |
9054 * @param pathItems Items making the path. | |
9055 * @param data Content of the file to be stored. | |
9056 * @param size Size of the file to be stored. | |
9057 * @param payload The user payload. | |
9058 * @return 0 if success, other value if error. | |
9059 * @ingroup Callbacks | |
9060 **/ | |
9061 typedef OrthancPluginErrorCode (*OrthancPluginWebDavStoreFileCallback) ( | |
9062 uint8_t* isReadOnly, /* out */ | |
9063 uint32_t pathSize, | |
9064 const char* const* pathItems, | |
9065 const void* data, | |
9066 uint64_t size, | |
9067 void* payload); | |
9068 | |
9069 | |
9070 /** | |
9071 * @brief Callback to create a folder. | |
9072 * | |
9073 * Signature of a callback function that creates a folder in the | |
9074 * WebDAV collection. | |
9075 * | |
9076 * @param isReadOnly Pointer to a Boolean that must be set to `1` if the collection is read-only, or `0` otherwise. | |
9077 * @param pathSize Number of levels in the path. | |
9078 * @param pathItems Items making the path. | |
9079 * @param payload The user payload. | |
9080 * @return 0 if success, other value if error. | |
9081 * @ingroup Callbacks | |
9082 **/ | |
9083 typedef OrthancPluginErrorCode (*OrthancPluginWebDavCreateFolderCallback) ( | |
9084 uint8_t* isReadOnly, /* out */ | |
9085 uint32_t pathSize, | |
9086 const char* const* pathItems, | |
9087 void* payload); | |
9088 | |
9089 | |
9090 /** | |
9091 * @brief Callback to remove a file or a folder. | |
9092 * | |
9093 * Signature of a callback function that removes a file or a folder | |
9094 * from the WebDAV collection. | |
9095 * | |
9096 * @param isReadOnly Pointer to a Boolean that must be set to `1` if the collection is read-only, or `0` otherwise. | |
9097 * @param pathSize Number of levels in the path. | |
9098 * @param pathItems Items making the path. | |
9099 * @param payload The user payload. | |
9100 * @return 0 if success, other value if error. | |
9101 * @ingroup Callbacks | |
9102 **/ | |
9103 typedef OrthancPluginErrorCode (*OrthancPluginWebDavDeleteItemCallback) ( | |
9104 uint8_t* isReadOnly, /* out */ | |
9105 uint32_t pathSize, | |
9106 const char* const* pathItems, | |
9107 void* payload); | |
9108 | |
9109 | |
9110 typedef struct | |
9111 { | |
9112 const char* uri; | |
9113 OrthancPluginWebDavIsExistingFolderCallback isExistingFolder; | |
9114 OrthancPluginWebDavListFolderCallback listFolder; | |
9115 OrthancPluginWebDavRetrieveFileCallback retrieveFile; | |
9116 OrthancPluginWebDavStoreFileCallback storeFile; | |
9117 OrthancPluginWebDavCreateFolderCallback createFolder; | |
9118 OrthancPluginWebDavDeleteItemCallback deleteItem; | |
9119 void* payload; | |
9120 } _OrthancPluginRegisterWebDavCollection; | |
9121 | |
9122 /** | |
9123 * @brief Register a WebDAV virtual filesystem. | |
9124 * | |
9125 * This function maps a WebDAV collection onto the given URI in the | |
9126 * REST API of Orthanc. This function must be called during the | |
9127 * initialization of the plugin, i.e. inside the | |
9128 * OrthancPluginInitialize() public function. | |
9129 * | |
9130 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
9131 * @param uri URI where to map the WebDAV collection (must start with a `/` character). | |
9132 * @param isExistingFolder Callback method to test for the existence of a folder. | |
9133 * @param listFolder Callback method to list the content of a folder. | |
9134 * @param retrieveFile Callback method to retrieve the content of a file. | |
9135 * @param storeFile Callback method to store a file into the WebDAV collection. | |
9136 * @param createFolder Callback method to create a folder. | |
9137 * @param deleteItem Callback method to delete a file or a folder. | |
9138 * @param payload The user payload. | |
9139 * @return 0 if success, other value if error. | |
9140 * @ingroup Callbacks | |
9141 **/ | |
9142 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterWebDavCollection( | |
9143 OrthancPluginContext* context, | |
9144 const char* uri, | |
9145 OrthancPluginWebDavIsExistingFolderCallback isExistingFolder, | |
9146 OrthancPluginWebDavListFolderCallback listFolder, | |
9147 OrthancPluginWebDavRetrieveFileCallback retrieveFile, | |
9148 OrthancPluginWebDavStoreFileCallback storeFile, | |
9149 OrthancPluginWebDavCreateFolderCallback createFolder, | |
9150 OrthancPluginWebDavDeleteItemCallback deleteItem, | |
9151 void* payload) | |
9152 { | |
9153 _OrthancPluginRegisterWebDavCollection params; | |
9154 params.uri = uri; | |
9155 params.isExistingFolder = isExistingFolder; | |
9156 params.listFolder = listFolder; | |
9157 params.retrieveFile = retrieveFile; | |
9158 params.storeFile = storeFile; | |
9159 params.createFolder = createFolder; | |
9160 params.deleteItem = deleteItem; | |
9161 params.payload = payload; | |
9162 | |
9163 return context->InvokeService(context, _OrthancPluginService_RegisterWebDavCollection, ¶ms); | |
9164 } | |
9165 | |
9166 | |
9167 /** | |
9168 * @brief Gets the DatabaseServerIdentifier. | |
9169 * | |
9170 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
9171 * @return the database server identifier. This is a statically-allocated | |
9172 * string, do not free it. | |
9173 * @ingroup Toolbox | |
9174 **/ | |
9175 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetDatabaseServerIdentifier( | |
9176 OrthancPluginContext* context) | |
9177 { | |
9178 const char* result; | |
9179 | |
9180 _OrthancPluginRetrieveStaticString params; | |
9181 params.result = &result; | |
9182 params.argument = NULL; | |
9183 | |
9184 if (context->InvokeService(context, _OrthancPluginService_GetDatabaseServerIdentifier, ¶ms) != OrthancPluginErrorCode_Success) | |
9185 { | |
9186 /* Error */ | |
9187 return NULL; | |
9188 } | |
9189 else | |
9190 { | |
9191 return result; | |
9192 } | |
9193 } | |
9194 | |
9195 | |
9196 /** | |
9197 * @brief Signature of a callback function that is triggered when | |
9198 * the Orthanc core requests an operation from the database plugin. | |
9199 * Both request and response are encoded as protobuf buffers. | |
9200 * @ingroup Callbacks | |
9201 **/ | |
9202 typedef OrthancPluginErrorCode (*OrthancPluginCallDatabaseBackendV4) ( | |
9203 OrthancPluginMemoryBuffer64* response, | |
9204 void* backend, | |
9205 const void* request, | |
9206 uint64_t requestSize); | |
9207 | |
9208 /** | |
9209 * @brief Signature of a callback function that is triggered when | |
9210 * the database plugin must be finalized. | |
9211 * @ingroup Callbacks | |
9212 **/ | |
9213 typedef void (*OrthancPluginFinalizeDatabaseBackendV4) (void* backend); | |
9214 | |
9215 typedef struct | |
9216 { | |
9217 void* backend; | |
9218 uint32_t maxDatabaseRetries; | |
9219 OrthancPluginCallDatabaseBackendV4 operations; | |
9220 OrthancPluginFinalizeDatabaseBackendV4 finalize; | |
9221 } _OrthancPluginRegisterDatabaseBackendV4; | |
9222 | |
9223 /** | |
9224 * Register a custom database back-end. | |
9225 * | |
9226 * This function was added in Orthanc SDK 1.12.0. It uses Google | |
9227 * Protocol Buffers for the communications between the Orthanc core | |
9228 * and database plugins. Check out "OrthancDatabasePlugin.proto" for | |
9229 * the definition of the protobuf messages. | |
9230 * | |
9231 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
9232 * @param backend Pointer to the custom database backend. | |
9233 * @param maxDatabaseRetries Maximum number of retries if transaction doesn't succeed. | |
9234 * If no retry is successful, OrthancPluginErrorCode_DatabaseCannotSerialize is generated. | |
9235 * @param operations Access to the operations of the custom database backend. | |
9236 * @param finalize Callback to deallocate the custom database backend. | |
9237 * @return 0 if success, other value if error. | |
9238 * @ingroup Callbacks | |
9239 **/ | |
9240 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDatabaseBackendV4( | |
9241 OrthancPluginContext* context, | |
9242 void* backend, | |
9243 uint32_t maxDatabaseRetries, | |
9244 OrthancPluginCallDatabaseBackendV4 operations, | |
9245 OrthancPluginFinalizeDatabaseBackendV4 finalize) | |
9246 { | |
9247 _OrthancPluginRegisterDatabaseBackendV4 params; | |
9248 params.backend = backend; | |
9249 params.maxDatabaseRetries = maxDatabaseRetries; | |
9250 params.operations = operations; | |
9251 params.finalize = finalize; | |
9252 | |
9253 return context->InvokeService(context, _OrthancPluginService_RegisterDatabaseBackendV4, ¶ms); | |
9254 } | |
9255 | |
9256 | |
9257 typedef struct | |
9258 { | |
9259 OrthancPluginDicomInstance** target; | |
9260 const char* instanceId; | |
9261 OrthancPluginLoadDicomInstanceMode mode; | |
9262 } _OrthancPluginLoadDicomInstance; | |
9263 | |
9264 /** | |
9265 * @brief Load a DICOM instance from the Orthanc server. | |
9266 * | |
9267 * This function loads a DICOM instance from the content of the | |
9268 * Orthanc database. The function returns a new pointer to a data | |
9269 * structure that is managed by the Orthanc core. | |
9270 * | |
9271 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
9272 * @param instanceId The Orthanc identifier of the DICOM instance of interest. | |
9273 * @param mode Flag specifying how to deal with pixel data. | |
9274 * @return The newly allocated DICOM instance. It must be freed with OrthancPluginFreeDicomInstance(). | |
9275 * @ingroup DicomInstance | |
9276 **/ | |
9277 ORTHANC_PLUGIN_INLINE OrthancPluginDicomInstance* OrthancPluginLoadDicomInstance( | |
9278 OrthancPluginContext* context, | |
9279 const char* instanceId, | |
9280 OrthancPluginLoadDicomInstanceMode mode) | |
9281 { | |
9282 OrthancPluginDicomInstance* target = NULL; | |
9283 | |
9284 _OrthancPluginLoadDicomInstance params; | |
9285 params.target = ⌖ | |
9286 params.instanceId = instanceId; | |
9287 params.mode = mode; | |
9288 | |
9289 if (context->InvokeService(context, _OrthancPluginService_LoadDicomInstance, ¶ms) != OrthancPluginErrorCode_Success) | |
9290 { | |
9291 /* Error */ | |
9292 return NULL; | |
9293 } | |
9294 else | |
9295 { | |
9296 return target; | |
9297 } | |
9298 } | |
9299 | |
9300 | |
9301 typedef struct | |
9302 { | |
9303 const char* name; | |
9304 int64_t value; | |
9305 OrthancPluginMetricsType type; | |
9306 } _OrthancPluginSetMetricsIntegerValue; | |
9307 | |
9308 /** | |
9309 * @brief Set the value of an integer metrics. | |
9310 * | |
9311 * This function sets the value of an integer metrics to monitor the | |
9312 * behavior of the plugin through tools such as Prometheus. The | |
9313 * values of all the metrics are stored within the Orthanc context. | |
9314 * | |
9315 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). | |
9316 * @param name The name of the metrics to be set. | |
9317 * @param value The value of the metrics. | |
9318 * @param type The type of the metrics. This parameter is only taken into consideration | |
9319 * the first time this metrics is set. | |
9320 * @ingroup Toolbox | |
9321 * @see OrthancPluginSetMetricsValue() | |
9322 **/ | |
9323 ORTHANC_PLUGIN_INLINE void OrthancPluginSetMetricsIntegerValue( | |
9324 OrthancPluginContext* context, | |
9325 const char* name, | |
9326 int64_t value, | |
9327 OrthancPluginMetricsType type) | |
9328 { | |
9329 _OrthancPluginSetMetricsIntegerValue params; | |
9330 params.name = name; | |
9331 params.value = value; | |
9332 params.type = type; | |
9333 context->InvokeService(context, _OrthancPluginService_SetMetricsIntegerValue, ¶ms); | |
9334 } | |
9335 | |
9336 | |
9337 #ifdef __cplusplus | |
9338 } | |
9339 #endif | |
9340 | |
9341 | |
9342 /** @} */ | |
9343 |