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