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