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