comparison Plugins/OrthancCPlugin/OrthancCPlugin.h @ 899:bb0a51561016 plugins

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Jun 2014 13:29:09 +0200
parents 7000fc86fe62
children 1b92ce45cc8d
comparison
equal deleted inserted replaced
898:7000fc86fe62 899:bb0a51561016
108 OrthancPluginHttpMethod_Delete = 4 108 OrthancPluginHttpMethod_Delete = 4
109 } OrthancPluginHttpMethod; 109 } OrthancPluginHttpMethod;
110 110
111 typedef enum 111 typedef enum
112 { 112 {
113 /* Generic services */
113 OrthancPluginService_LogInfo = 1, 114 OrthancPluginService_LogInfo = 1,
114 OrthancPluginService_LogWarning = 2, 115 OrthancPluginService_LogWarning = 2,
115 OrthancPluginService_LogError = 3 116 OrthancPluginService_LogError = 3,
117
118 /* Registration of callbacks */
119 OrthancPluginService_RegisterRestCallback = 1000,
120
121 /* Sending answers to REST calls */
122 OrthancPluginService_AnswerBuffer = 2000
116 } OrthancPluginService; 123 } OrthancPluginService;
117 124
125 typedef struct
126 {
127 OrthancPluginHttpMethod method;
128
129 /* For GET requests */
130 const char* const* getKeys;
131 const char* const* getValues;
132 uint32_t getCount;
133
134 /* For POST and PUT requests */
135 const char* body;
136 uint32_t bodySize;
137 } OrthancPluginHttpRequest;
138
118 typedef int32_t (*OrthancPluginRestCallback) (OrthancPluginRestOutput* output, 139 typedef int32_t (*OrthancPluginRestCallback) (OrthancPluginRestOutput* output,
119 OrthancPluginHttpMethod method,
120 const char* url, 140 const char* url,
121 const char* const* getKeys, 141 const OrthancPluginHttpRequest* request);
122 const char* const* getValues,
123 uint32_t getSize,
124 const char* body, uint32_t bodySize);
125 142
126 typedef struct OrthancPluginContext_t 143 typedef struct OrthancPluginContext_t
127 { 144 {
128 void* pluginsManager; 145 void* pluginsManager;
129 146
130 const char* orthancVersion; 147 const char* orthancVersion;
131 void (*FreeBuffer) (void* buffer); 148 void (*FreeBuffer) (void* buffer);
132 int32_t (*InvokeService) (struct OrthancPluginContext_t* context, 149 int32_t (*InvokeService) (struct OrthancPluginContext_t* context,
133 OrthancPluginService service, 150 OrthancPluginService service,
134 const void* parameters); 151 const void* params);
135
136 /* REST API */
137 void (*RegisterRestCallback) (const struct OrthancPluginContext_t* context,
138 const char* pathRegularExpression,
139 OrthancPluginRestCallback callback);
140
141 void (*AnswerBuffer) (OrthancPluginRestOutput* output,
142 const char* answer,
143 uint32_t answerSize,
144 const char* mimeType);
145 } OrthancPluginContext; 152 } OrthancPluginContext;
153
154
155 typedef struct
156 {
157 const char* pathRegularExpression;
158 OrthancPluginRestCallback callback;
159 } OrthancPluginRestCallbackParams;
160
161
162 typedef struct
163 {
164 OrthancPluginRestOutput* output;
165 const char* answer;
166 uint32_t answerSize;
167 const char* mimeType;
168 } OrthancPluginAnswerBufferParams;
146 169
147 170
148 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError(OrthancPluginContext* context, 171 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError(OrthancPluginContext* context,
149 const char* str) 172 const char* str)
150 { 173 {
161 184
162 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo(OrthancPluginContext* context, 185 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo(OrthancPluginContext* context,
163 const char* str) 186 const char* str)
164 { 187 {
165 context->InvokeService(context, OrthancPluginService_LogInfo, str); 188 context->InvokeService(context, OrthancPluginService_LogInfo, str);
189 }
190
191
192 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback(OrthancPluginContext* context,
193 const char* pathRegularExpression,
194 OrthancPluginRestCallback callback)
195 {
196 OrthancPluginRestCallbackParams params;
197 params.pathRegularExpression = pathRegularExpression;
198 params.callback = callback;
199 context->InvokeService(context, OrthancPluginService_RegisterRestCallback, &params);
200 }
201
202
203 ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer(OrthancPluginContext* context,
204 OrthancPluginRestOutput* output,
205 const char* answer,
206 uint32_t answerSize,
207 const char* mimeType)
208 {
209 OrthancPluginAnswerBufferParams params;
210 params.output = output;
211 params.answer = answer;
212 params.answerSize = answerSize;
213 params.mimeType = mimeType;
214 context->InvokeService(context, OrthancPluginService_AnswerBuffer, &params);
166 } 215 }
167 216
168 217
169 218
170 /** 219 /**