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