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