comparison Plugins/Samples/Basic/Plugin.c @ 2135:cadfe0a2a393

fix in the sample basic plugin
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 Nov 2016 13:42:33 +0100
parents 22ddb22fce83
children a3a65de1840f
comparison
equal deleted inserted replaced
2134:ddc75c6c712d 2135:cadfe0a2a393
26 static OrthancPluginContext* context = NULL; 26 static OrthancPluginContext* context = NULL;
27 27
28 static OrthancPluginErrorCode customError; 28 static OrthancPluginErrorCode customError;
29 29
30 30
31 ORTHANC_PLUGINS_API int32_t Callback1(OrthancPluginRestOutput* output, 31 ORTHANC_PLUGINS_API OrthancPluginErrorCode Callback1(OrthancPluginRestOutput* output,
32 const char* url, 32 const char* url,
33 const OrthancPluginHttpRequest* request) 33 const OrthancPluginHttpRequest* request)
34 { 34 {
35 char buffer[1024]; 35 char buffer[1024];
36 uint32_t i; 36 uint32_t i;
37 37
38 sprintf(buffer, "Callback on URL [%s] with body [%s]\n", url, request->body); 38 sprintf(buffer, "Callback on URL [%s] with body [%s]\n", url, request->body);
55 { 55 {
56 sprintf(buffer, " GET [%s] = [%s]", request->getKeys[i], request->getValues[i]); 56 sprintf(buffer, " GET [%s] = [%s]", request->getKeys[i], request->getValues[i]);
57 OrthancPluginLogWarning(context, buffer); 57 OrthancPluginLogWarning(context, buffer);
58 } 58 }
59 59
60 OrthancPluginLogWarning(context, ""); 60 OrthancPluginLogWarning(context, "");
61 61
62 for (i = 0; i < request->headersCount; i++) 62 for (i = 0; i < request->headersCount; i++)
63 { 63 {
64 sprintf(buffer, " HEADERS [%s] = [%s]", request->headersKeys[i], request->headersValues[i]); 64 sprintf(buffer, " HEADERS [%s] = [%s]", request->headersKeys[i], request->headersValues[i]);
65 OrthancPluginLogWarning(context, buffer); 65 OrthancPluginLogWarning(context, buffer);
66 } 66 }
67 67
68 OrthancPluginLogWarning(context, ""); 68 OrthancPluginLogWarning(context, "");
69 69
70 return 1; 70 return OrthancPluginErrorCode_Success;
71 } 71 }
72 72
73 73
74 ORTHANC_PLUGINS_API int32_t Callback2(OrthancPluginRestOutput* output, 74 ORTHANC_PLUGINS_API OrthancPluginErrorCode Callback2(OrthancPluginRestOutput* output,
75 const char* url, 75 const char* url,
76 const OrthancPluginHttpRequest* request) 76 const OrthancPluginHttpRequest* request)
77 { 77 {
78 /* Answer with a sample 16bpp image. */ 78 /* Answer with a sample 16bpp image. */
79 79
80 uint16_t buffer[256 * 256]; 80 uint16_t buffer[256 * 256];
81 uint32_t x, y, value; 81 uint32_t x, y, value;
97 97
98 OrthancPluginCompressAndAnswerPngImage(context, output, OrthancPluginPixelFormat_Grayscale16, 98 OrthancPluginCompressAndAnswerPngImage(context, output, OrthancPluginPixelFormat_Grayscale16,
99 256, 256, sizeof(uint16_t) * 256, buffer); 99 256, 256, sizeof(uint16_t) * 256, buffer);
100 } 100 }
101 101
102 return 0; 102 return OrthancPluginErrorCode_Success;
103 } 103 }
104 104
105 105
106 ORTHANC_PLUGINS_API int32_t Callback3(OrthancPluginRestOutput* output, 106 ORTHANC_PLUGINS_API OrthancPluginErrorCode Callback3(OrthancPluginRestOutput* output,
107 const char* url, 107 const char* url,
108 const OrthancPluginHttpRequest* request) 108 const OrthancPluginHttpRequest* request)
109 { 109 {
110 if (request->method != OrthancPluginHttpMethod_Get) 110 if (request->method != OrthancPluginHttpMethod_Get)
111 { 111 {
112 OrthancPluginSendMethodNotAllowed(context, output, "GET"); 112 OrthancPluginSendMethodNotAllowed(context, output, "GET");
113 } 113 }
122 /* Free memory */ 122 /* Free memory */
123 OrthancPluginFreeMemoryBuffer(context, &dicom); 123 OrthancPluginFreeMemoryBuffer(context, &dicom);
124 } 124 }
125 } 125 }
126 126
127 return 0; 127 return OrthancPluginErrorCode_Success;
128 } 128 }
129 129
130 130
131 ORTHANC_PLUGINS_API int32_t Callback4(OrthancPluginRestOutput* output, 131 ORTHANC_PLUGINS_API OrthancPluginErrorCode Callback4(OrthancPluginRestOutput* output,
132 const char* url, 132 const char* url,
133 const OrthancPluginHttpRequest* request) 133 const OrthancPluginHttpRequest* request)
134 { 134 {
135 /* Answer with a sample 8bpp image. */ 135 /* Answer with a sample 8bpp image. */
136 136
137 uint8_t buffer[256 * 256]; 137 uint8_t buffer[256 * 256];
138 uint32_t x, y, value; 138 uint32_t x, y, value;
154 154
155 OrthancPluginCompressAndAnswerPngImage(context, output, OrthancPluginPixelFormat_Grayscale8, 155 OrthancPluginCompressAndAnswerPngImage(context, output, OrthancPluginPixelFormat_Grayscale8,
156 256, 256, 256, buffer); 156 256, 256, 256, buffer);
157 } 157 }
158 158
159 return 0; 159 return OrthancPluginErrorCode_Success;
160 } 160 }
161 161
162 162
163 ORTHANC_PLUGINS_API int32_t Callback5(OrthancPluginRestOutput* output, 163 ORTHANC_PLUGINS_API OrthancPluginErrorCode Callback5(OrthancPluginRestOutput* output,
164 const char* url, 164 const char* url,
165 const OrthancPluginHttpRequest* request) 165 const OrthancPluginHttpRequest* request)
166 { 166 {
167 /** 167 /**
168 * Demonstration the difference between the 168 * Demonstration the difference between the
169 * "OrthancPluginRestApiXXX()" and the 169 * "OrthancPluginRestApiXXX()" and the
170 * "OrthancPluginRestApiXXXAfterPlugins()" mechanisms to forward 170 * "OrthancPluginRestApiXXXAfterPlugins()" mechanisms to forward
197 error = OrthancPluginRestApiGetAfterPlugins(context, &tmp, request->groups[1]); 197 error = OrthancPluginRestApiGetAfterPlugins(context, &tmp, request->groups[1]);
198 } 198 }
199 199
200 if (error) 200 if (error)
201 { 201 {
202 return -1; 202 return OrthancPluginErrorCode_InternalError;
203 } 203 }
204 else 204 else
205 { 205 {
206 OrthancPluginAnswerBuffer(context, output, tmp.data, tmp.size, "application/octet-stream"); 206 OrthancPluginAnswerBuffer(context, output, tmp.data, tmp.size, "application/octet-stream");
207 OrthancPluginFreeMemoryBuffer(context, &tmp); 207 OrthancPluginFreeMemoryBuffer(context, &tmp);
208 return 0; 208 return OrthancPluginErrorCode_Success;
209 } 209 }
210 } 210 }
211 211
212 212
213 ORTHANC_PLUGINS_API OrthancPluginErrorCode CallbackCreateDicom(OrthancPluginRestOutput* output, 213 ORTHANC_PLUGINS_API OrthancPluginErrorCode CallbackCreateDicom(OrthancPluginRestOutput* output,