comparison Plugins/OrthancCPlugin/OrthancCPlugin.h @ 898:7000fc86fe62 plugins

improved plugin api
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Jun 2014 09:18:28 +0200
parents bafc9d592632
children bb0a51561016
comparison
equal deleted inserted replaced
897:bafc9d592632 898:7000fc86fe62
31 31
32 32
33 #pragma once 33 #pragma once
34 34
35 35
36 #ifdef _MSC_VER
37 #include "../../Resources/VisualStudio/stdint.h"
38 #else
39 #include <stdint.h>
40 #endif
41
42
43 #ifdef WIN32 36 #ifdef WIN32
44 #define ORTHANC_PLUGINS_API __declspec(dllexport) 37 #define ORTHANC_PLUGINS_API __declspec(dllexport)
45 #else 38 #else
46 #define ORTHANC_PLUGINS_API 39 #define ORTHANC_PLUGINS_API
47 #endif 40 #endif
48 41
49 42
43
44 /********************************************************************
45 ** Check that function inlining is properly supported. The use of
46 ** inlining is required, to avoid the duplication of object code
47 ** between two compilation modules that would use the Orthanc Plugin
48 ** API.
49 ********************************************************************/
50
51 /* If the auto-detection of the "inline" keyword below does not work
52 automatically and that your compiler is known to properly support
53 inlining, uncomment the following #define and adapt the definition
54 of "static inline". */
55
56 /* #define ORTHANC_PLUGIN_INLINE static inline */
57
58 #ifndef ORTHANC_PLUGIN_INLINE
59 # if __STDC_VERSION__ >= 199901L
60 /* This is C99 or above: http://predef.sourceforge.net/prestd.html */
61 # define ORTHANC_PLUGIN_INLINE static inline
62 # elif defined(__cplusplus)
63 /* This is C++ */
64 # define ORTHANC_PLUGIN_INLINE static inline
65 # elif defined(__GNUC__)
66 /* This is GCC running in C89 mode */
67 # define ORTHANC_PLUGIN_INLINE static __inline
68 # elif defined(_MSC_VER)
69 /* This is Visual Studio running in C89 mode */
70 # define ORTHANC_PLUGIN_INLINE static __inline
71 # else
72 # error Your compiler is not known to support the "inline" keyword
73 # endif
74 #endif
75
76
77
78 /********************************************************************
79 ** Inclusion of standard libaries.
80 ********************************************************************/
81
82 #ifdef _MSC_VER
83 #include "../../Resources/VisualStudio/stdint.h"
84 #else
85 #include <stdint.h>
86 #endif
87
50 #include <stdlib.h> 88 #include <stdlib.h>
51 89
90
91
92 /********************************************************************
93 ** Definition of the Orthanc Plugin API.
94 ********************************************************************/
52 95
53 #ifdef __cplusplus 96 #ifdef __cplusplus
54 extern "C" 97 extern "C"
55 { 98 {
56 #endif 99 #endif
63 OrthancPluginHttpMethod_Post = 2, 106 OrthancPluginHttpMethod_Post = 2,
64 OrthancPluginHttpMethod_Put = 3, 107 OrthancPluginHttpMethod_Put = 3,
65 OrthancPluginHttpMethod_Delete = 4 108 OrthancPluginHttpMethod_Delete = 4
66 } OrthancPluginHttpMethod; 109 } OrthancPluginHttpMethod;
67 110
68 typedef int32_t (*OrthancPluginService) (const char* serviceName, 111 typedef enum
69 const void* serviceParameters); 112 {
113 OrthancPluginService_LogInfo = 1,
114 OrthancPluginService_LogWarning = 2,
115 OrthancPluginService_LogError = 3
116 } OrthancPluginService;
70 117
71 typedef int32_t (*OrthancPluginRestCallback) (OrthancPluginRestOutput* output, 118 typedef int32_t (*OrthancPluginRestCallback) (OrthancPluginRestOutput* output,
72 OrthancPluginHttpMethod method, 119 OrthancPluginHttpMethod method,
73 const char* url, 120 const char* url,
74 const char* const* getKeys, 121 const char* const* getKeys,
76 uint32_t getSize, 123 uint32_t getSize,
77 const char* body, uint32_t bodySize); 124 const char* body, uint32_t bodySize);
78 125
79 typedef struct OrthancPluginContext_t 126 typedef struct OrthancPluginContext_t
80 { 127 {
81 void* pimpl; 128 void* pluginsManager;
82 129
83 const char* orthancVersion; 130 const char* orthancVersion;
84 void (*FreeBuffer) (void* buffer); 131 void (*FreeBuffer) (void* buffer);
85 132 int32_t (*InvokeService) (struct OrthancPluginContext_t* context,
86 /* Logging functions */ 133 OrthancPluginService service,
87 void (*LogError) (const char* str); 134 const void* parameters);
88 void (*LogWarning) (const char* str);
89 void (*LogInfo) (const char* str);
90 135
91 /* REST API */ 136 /* REST API */
92 void (*RegisterRestCallback) (const struct OrthancPluginContext_t* context, 137 void (*RegisterRestCallback) (const struct OrthancPluginContext_t* context,
93 const char* pathRegularExpression, 138 const char* pathRegularExpression,
94 OrthancPluginRestCallback callback); 139 OrthancPluginRestCallback callback);
96 void (*AnswerBuffer) (OrthancPluginRestOutput* output, 141 void (*AnswerBuffer) (OrthancPluginRestOutput* output,
97 const char* answer, 142 const char* answer,
98 uint32_t answerSize, 143 uint32_t answerSize,
99 const char* mimeType); 144 const char* mimeType);
100 } OrthancPluginContext; 145 } OrthancPluginContext;
146
147
148 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError(OrthancPluginContext* context,
149 const char* str)
150 {
151 context->InvokeService(context, OrthancPluginService_LogError, str);
152 }
153
154
155 ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning(OrthancPluginContext* context,
156 const char* str)
157 {
158 context->InvokeService(context, OrthancPluginService_LogWarning, str);
159 }
160
161
162 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo(OrthancPluginContext* context,
163 const char* str)
164 {
165 context->InvokeService(context, OrthancPluginService_LogInfo, str);
166 }
167
101 168
102 169
103 /** 170 /**
104 Each plugin must define 4 functions, whose signature are: 171 Each plugin must define 4 functions, whose signature are:
105 - int32_t OrthancPluginInitialize(const OrthancPluginContext*); 172 - int32_t OrthancPluginInitialize(const OrthancPluginContext*);