comparison Plugins/Samples/Basic/Plugin.c @ 904:2732b5f57d9c plugins

sample to forward dicom data
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Jun 2014 16:07:47 +0200
parents 06b9a30f1e6d
children dcb2469f00f4
comparison
equal deleted inserted replaced
903:06b9a30f1e6d 904:2732b5f57d9c
49 { 49 {
50 sprintf(buffer, " [%s] = [%s]", request->getKeys[i], request->getValues[i]); 50 sprintf(buffer, " [%s] = [%s]", request->getKeys[i], request->getValues[i]);
51 OrthancPluginLogInfo(context, buffer); 51 OrthancPluginLogInfo(context, buffer);
52 } 52 }
53 53
54 printf("** %d\n", request->groupCount); 54 printf("** %d\n", request->groupsCount);
55 for (i = 0; i < request->groupCount; i++) 55 for (i = 0; i < request->groupsCount; i++)
56 { 56 {
57 printf("** [%s]\n", request->groupValues[i]); 57 printf("** [%s]\n", request->groups[i]);
58 } 58 }
59 59
60 return 1; 60 return 1;
61 } 61 }
62 62
63 63
64 ORTHANC_PLUGINS_API int32_t Callback2(OrthancPluginRestOutput* output, 64 ORTHANC_PLUGINS_API int32_t Callback2(OrthancPluginRestOutput* output,
65 const char* url, 65 const char* url,
66 const OrthancPluginHttpRequest* request) 66 const OrthancPluginHttpRequest* request)
67 { 67 {
68 /** 68 /* Answer with a sample 16bpp image. */
69 * Answer with a sample 16bpp image.
70 **/
71 69
72 uint16_t buffer[256 * 256]; 70 uint16_t buffer[256 * 256];
73 uint32_t x, y, value; 71 uint32_t x, y, value;
74 72
75 value = 0; 73 value = 0;
85 256, 256, sizeof(uint16_t) * 256, buffer); 83 256, 256, sizeof(uint16_t) * 256, buffer);
86 return 0; 84 return 0;
87 } 85 }
88 86
89 87
88 ORTHANC_PLUGINS_API int32_t Callback3(OrthancPluginRestOutput* output,
89 const char* url,
90 const OrthancPluginHttpRequest* request)
91 {
92 OrthancPluginMemoryBuffer dicom;
93 if (!OrthancPluginGetDicomForInstance(context, &dicom, request->groups[0]))
94 {
95 /* No error, forward the DICOM file */
96 OrthancPluginAnswerBuffer(context, output, dicom.data, dicom.size, "application/dicom");
97
98 /* Free memory */
99 OrthancPluginFreeMemoryBuffer(context, &dicom);
100 }
101
102 return 0;
103 }
104
105
106 ORTHANC_PLUGINS_API int32_t Callback4(OrthancPluginRestOutput* output,
107 const char* url,
108 const OrthancPluginHttpRequest* request)
109 {
110 /* Answer with a sample 8bpp image. */
111
112 uint8_t buffer[256 * 256];
113 uint32_t x, y, value;
114
115 value = 0;
116 for (y = 0; y < 256; y++)
117 {
118 for (x = 0; x < 256; x++, value++)
119 {
120 buffer[value] = x;
121 }
122 }
123
124 OrthancPluginCompressAndAnswerPngImage(context, output, OrthancPluginPixelFormat_Grayscale8,
125 256, 256, 256, buffer);
126 return 0;
127 }
128
129
90 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) 130 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
91 { 131 {
92 char info[1024]; 132 char info[1024];
93 133
94 context = c; 134 context = c;
97 sprintf(info, "The version of Orthanc is '%s'", context->orthancVersion); 137 sprintf(info, "The version of Orthanc is '%s'", context->orthancVersion);
98 OrthancPluginLogInfo(context, info); 138 OrthancPluginLogInfo(context, info);
99 139
100 OrthancPluginRegisterRestCallback(context, "/(plu.*)/hello", Callback1); 140 OrthancPluginRegisterRestCallback(context, "/(plu.*)/hello", Callback1);
101 OrthancPluginRegisterRestCallback(context, "/plu.*/image", Callback2); 141 OrthancPluginRegisterRestCallback(context, "/plu.*/image", Callback2);
142 OrthancPluginRegisterRestCallback(context, "/plugin/instances/([^/]+)/info", Callback3);
143
144 OrthancPluginRegisterRestCallback(context, "/instances/([^/]+)/preview", Callback4);
102 145
103 return 0; 146 return 0;
104 } 147 }
105 148
106 149