Mercurial > hg > orthanc
comparison Plugins/Samples/Basic/Plugin.c @ 902:5c255e465b33 plugins
move
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 18 Jun 2014 15:23:32 +0200 |
parents | Resources/Samples/Plugins/Basic/Plugin.c@7d88f3f4a3b3 |
children | 06b9a30f1e6d |
comparison
equal
deleted
inserted
replaced
901:7d88f3f4a3b3 | 902:5c255e465b33 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, | |
4 * Belgium | |
5 * | |
6 * Permission is hereby granted, free of charge, to any person | |
7 * obtaining a copy of this software and associated documentation | |
8 * files (the "Software"), to deal in the Software without | |
9 * restriction, including without limitation the rights to use, copy, | |
10 * modify, merge, publish, distribute, sublicense, and/or sell copies | |
11 * of the Software, and to permit persons to whom the Software is | |
12 * furnished to do so, subject to the following conditions: | |
13 * | |
14 * The above copyright notice and this permission notice shall be | |
15 * included in all copies or substantial portions of the Software. | |
16 * | |
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
24 * SOFTWARE. | |
25 **/ | |
26 | |
27 | |
28 #include <OrthancCPlugin.h> | |
29 | |
30 #include <string.h> | |
31 #include <stdio.h> | |
32 | |
33 static OrthancPluginContext* context = NULL; | |
34 | |
35 | |
36 ORTHANC_PLUGINS_API int32_t Callback1(OrthancPluginRestOutput* output, | |
37 const char* url, | |
38 const OrthancPluginHttpRequest* request) | |
39 { | |
40 char buffer[1024]; | |
41 uint32_t i; | |
42 | |
43 sprintf(buffer, "Callback on URL [%s] with body [%s]", url, request->body); | |
44 OrthancPluginLogInfo(context, buffer); | |
45 | |
46 OrthancPluginAnswerBuffer(context, output, buffer, strlen(buffer), "text/plain"); | |
47 | |
48 for (i = 0; i < request->getCount; i++) | |
49 { | |
50 sprintf(buffer, " [%s] = [%s]", request->getKeys[i], request->getValues[i]); | |
51 OrthancPluginLogInfo(context, buffer); | |
52 } | |
53 | |
54 printf("** %d\n", request->groupCount); | |
55 for (i = 0; i < request->groupCount; i++) | |
56 { | |
57 printf("** [%s]\n", request->groupValues[i]); | |
58 } | |
59 | |
60 return 1; | |
61 } | |
62 | |
63 | |
64 ORTHANC_PLUGINS_API int32_t Callback2(OrthancPluginRestOutput* output, | |
65 const char* url, | |
66 const OrthancPluginHttpRequest* request) | |
67 { | |
68 /** | |
69 * Answer with a sample 16bpp image. | |
70 **/ | |
71 | |
72 uint16_t buffer[256 * 256]; | |
73 uint32_t x, y, value; | |
74 | |
75 value = 0; | |
76 for (y = 0; y < 256; y++) | |
77 { | |
78 for (x = 0; x < 256; x++, value++) | |
79 { | |
80 buffer[value] = value; | |
81 } | |
82 } | |
83 | |
84 OrthancPluginCompressAndAnswerPngImage(context, output, OrthancPluginPixelFormat_Grayscale16, | |
85 256, 256, sizeof(uint16_t) * 256, buffer); | |
86 return 0; | |
87 } | |
88 | |
89 | |
90 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) | |
91 { | |
92 char info[1024]; | |
93 | |
94 context = c; | |
95 OrthancPluginLogWarning(context, "Plugin is initializing"); | |
96 | |
97 sprintf(info, "The version of Orthanc is '%s'", context->orthancVersion); | |
98 OrthancPluginLogInfo(context, info); | |
99 | |
100 OrthancPluginRegisterRestCallback(context, "/(plu.*)/hello", Callback1); | |
101 OrthancPluginRegisterRestCallback(context, "/plu.*/image", Callback2); | |
102 | |
103 return 0; | |
104 } | |
105 | |
106 | |
107 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
108 { | |
109 OrthancPluginLogWarning(context, "Plugin is finalizing"); | |
110 } | |
111 | |
112 | |
113 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
114 { | |
115 return "sample"; | |
116 } | |
117 | |
118 | |
119 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
120 { | |
121 return "1.0"; | |
122 } | |
123 |