Mercurial > hg > orthanc
annotate Plugins/OrthancCPlugin/OrthancCPlugin.h @ 900:1b92ce45cc8d plugins
plugin doc
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 18 Jun 2014 14:02:02 +0200 |
parents | bb0a51561016 |
children | 7d88f3f4a3b3 |
rev | line source |
---|---|
900 | 1 /** |
2 * @defgroup CInterface C Interface | |
3 * @brief The C interface to create Orthanc plugins. | |
4 * | |
5 * These functions must be used to create C plugins for Orthanc. | |
6 **/ | |
7 | |
8 | |
886 | 9 /** |
10 * Orthanc - A Lightweight, RESTful DICOM Store | |
11 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, | |
12 * Belgium | |
13 * | |
14 * This program is free software: you can redistribute it and/or | |
15 * modify it under the terms of the GNU General Public License as | |
16 * published by the Free Software Foundation, either version 3 of the | |
17 * License, or (at your option) any later version. | |
18 * | |
19 * In addition, as a special exception, the copyright holders of this | |
20 * program give permission to link the code of its release with the | |
21 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
22 * that use the same license as the "OpenSSL" library), and distribute | |
23 * the linked executables. You must obey the GNU General Public License | |
24 * in all respects for all of the code used other than "OpenSSL". If you | |
25 * modify file(s) with this exception, you may extend this exception to | |
26 * your version of the file(s), but you are not obligated to do so. If | |
27 * you do not wish to do so, delete this exception statement from your | |
28 * version. If you delete this exception statement from all source files | |
29 * in the program, then also delete it here. | |
30 * | |
31 * This program is distributed in the hope that it will be useful, but | |
32 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
34 * General Public License for more details. | |
35 * | |
36 * You should have received a copy of the GNU General Public License | |
37 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
38 **/ | |
39 | |
40 | |
41 #pragma once | |
42 | |
43 | |
900 | 44 #include <stdio.h> |
45 #include <string.h> | |
46 | |
886 | 47 #ifdef WIN32 |
48 #define ORTHANC_PLUGINS_API __declspec(dllexport) | |
49 #else | |
50 #define ORTHANC_PLUGINS_API | |
51 #endif | |
52 | |
53 | |
898
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
54 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
55 /******************************************************************** |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
56 ** Check that function inlining is properly supported. The use of |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
57 ** inlining is required, to avoid the duplication of object code |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
58 ** between two compilation modules that would use the Orthanc Plugin |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
59 ** API. |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
60 ********************************************************************/ |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
61 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
62 /* If the auto-detection of the "inline" keyword below does not work |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
63 automatically and that your compiler is known to properly support |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
64 inlining, uncomment the following #define and adapt the definition |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
65 of "static inline". */ |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
66 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
67 /* #define ORTHANC_PLUGIN_INLINE static inline */ |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
68 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
69 #ifndef ORTHANC_PLUGIN_INLINE |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
70 # if __STDC_VERSION__ >= 199901L |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
71 /* This is C99 or above: http://predef.sourceforge.net/prestd.html */ |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
72 # define ORTHANC_PLUGIN_INLINE static inline |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
73 # elif defined(__cplusplus) |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
74 /* This is C++ */ |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
75 # define ORTHANC_PLUGIN_INLINE static inline |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
76 # elif defined(__GNUC__) |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
77 /* This is GCC running in C89 mode */ |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
78 # define ORTHANC_PLUGIN_INLINE static __inline |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
79 # elif defined(_MSC_VER) |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
80 /* This is Visual Studio running in C89 mode */ |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
81 # define ORTHANC_PLUGIN_INLINE static __inline |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
82 # else |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
83 # error Your compiler is not known to support the "inline" keyword |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
84 # endif |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
85 #endif |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
86 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
87 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
88 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
89 /******************************************************************** |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
90 ** Inclusion of standard libaries. |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
91 ********************************************************************/ |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
92 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
93 #ifdef _MSC_VER |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
94 #include "../../Resources/VisualStudio/stdint.h" |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
95 #else |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
96 #include <stdint.h> |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
97 #endif |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
98 |
886 | 99 #include <stdlib.h> |
100 | |
101 | |
898
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
102 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
103 /******************************************************************** |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
104 ** Definition of the Orthanc Plugin API. |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
105 ********************************************************************/ |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
106 |
900 | 107 /** @{ */ |
108 | |
886 | 109 #ifdef __cplusplus |
110 extern "C" | |
111 { | |
112 #endif | |
113 | |
894 | 114 typedef enum |
115 { | |
896 | 116 OrthancPluginHttpMethod_Get = 1, |
117 OrthancPluginHttpMethod_Post = 2, | |
118 OrthancPluginHttpMethod_Put = 3, | |
119 OrthancPluginHttpMethod_Delete = 4 | |
120 } OrthancPluginHttpMethod; | |
886 | 121 |
899 | 122 typedef struct |
123 { | |
124 OrthancPluginHttpMethod method; | |
125 | |
126 /* For GET requests */ | |
127 const char* const* getKeys; | |
128 const char* const* getValues; | |
129 uint32_t getCount; | |
130 | |
131 /* For POST and PUT requests */ | |
132 const char* body; | |
133 uint32_t bodySize; | |
134 } OrthancPluginHttpRequest; | |
135 | |
900 | 136 typedef enum |
886 | 137 { |
900 | 138 /* Generic services */ |
139 OrthancPluginService_LogInfo = 1, | |
140 OrthancPluginService_LogWarning = 2, | |
141 OrthancPluginService_LogError = 3, | |
142 | |
143 /* Registration of callbacks */ | |
144 OrthancPluginService_RegisterRestCallback = 1000, | |
145 | |
146 /* Sending answers to REST calls */ | |
147 OrthancPluginService_AnswerBuffer = 2000 | |
148 } OrthancPluginService; | |
149 | |
150 | |
151 | |
894 | 152 |
900 | 153 typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput; |
154 | |
155 typedef int32_t (*OrthancPluginRestCallback) ( | |
156 OrthancPluginRestOutput* output, | |
157 const char* url, | |
158 const OrthancPluginHttpRequest* request); | |
159 | |
160 typedef struct _OrthancPluginContext_t | |
161 { | |
162 void* pluginsManager; | |
163 const char* orthancVersion; | |
164 void (*FreeBuffer) (void* buffer); | |
165 int32_t (*InvokeService) (struct _OrthancPluginContext_t* context, | |
166 OrthancPluginService service, | |
167 const void* params); | |
899 | 168 } OrthancPluginContext; |
169 | |
886 | 170 |
899 | 171 typedef struct |
172 { | |
173 const char* pathRegularExpression; | |
174 OrthancPluginRestCallback callback; | |
900 | 175 } _OrthancPluginRestCallbackParams; |
899 | 176 |
886 | 177 |
899 | 178 typedef struct |
179 { | |
180 OrthancPluginRestOutput* output; | |
181 const char* answer; | |
182 uint32_t answerSize; | |
183 const char* mimeType; | |
900 | 184 } _OrthancPluginAnswerBufferParams; |
886 | 185 |
186 | |
900 | 187 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError( |
188 OrthancPluginContext* context, | |
189 const char* str) | |
898
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
190 { |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
191 context->InvokeService(context, OrthancPluginService_LogError, str); |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
192 } |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
193 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
194 |
900 | 195 ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning( |
196 OrthancPluginContext* context, | |
197 const char* str) | |
898
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
198 { |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
199 context->InvokeService(context, OrthancPluginService_LogWarning, str); |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
200 } |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
201 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
202 |
900 | 203 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo( |
204 OrthancPluginContext* context, | |
205 const char* str) | |
898
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
206 { |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
207 context->InvokeService(context, OrthancPluginService_LogInfo, str); |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
208 } |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
209 |
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
210 |
900 | 211 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback( |
212 OrthancPluginContext* context, | |
213 const char* pathRegularExpression, | |
214 OrthancPluginRestCallback callback) | |
899 | 215 { |
900 | 216 _OrthancPluginRestCallbackParams params; |
899 | 217 params.pathRegularExpression = pathRegularExpression; |
218 params.callback = callback; | |
219 context->InvokeService(context, OrthancPluginService_RegisterRestCallback, ¶ms); | |
220 } | |
221 | |
222 | |
900 | 223 ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer( |
224 OrthancPluginContext* context, | |
225 OrthancPluginRestOutput* output, | |
226 const char* answer, | |
227 uint32_t answerSize, | |
228 const char* mimeType) | |
899 | 229 { |
900 | 230 _OrthancPluginAnswerBufferParams params; |
899 | 231 params.output = output; |
232 params.answer = answer; | |
233 params.answerSize = answerSize; | |
234 params.mimeType = mimeType; | |
235 context->InvokeService(context, OrthancPluginService_AnswerBuffer, ¶ms); | |
236 } | |
237 | |
238 | |
898
7000fc86fe62
improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
897
diff
changeset
|
239 |
886 | 240 /** |
894 | 241 Each plugin must define 4 functions, whose signature are: |
886 | 242 - int32_t OrthancPluginInitialize(const OrthancPluginContext*); |
243 - void OrthancPluginFinalize(); | |
888
d44b845c1c89
recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
886
diff
changeset
|
244 - const char* OrthancPluginGetName(); |
d44b845c1c89
recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
886
diff
changeset
|
245 - const char* OrthancPluginGetVersion(); |
886 | 246 |
247 nm -C -D --defined-only libPluginTest.so | |
896 | 248 **/ |
886 | 249 |
250 #ifdef __cplusplus | |
251 } | |
252 #endif | |
900 | 253 |
254 | |
255 /** @} */ | |
256 |