diff Resources/Samples/Plugins/Basic/Plugin.c @ 901:7d88f3f4a3b3 plugins

refactoring IsServedUri, answer PNG images, regular expression groups
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Jun 2014 15:22:13 +0200
parents bb0a51561016
children
line wrap: on
line diff
--- a/Resources/Samples/Plugins/Basic/Plugin.c	Wed Jun 18 14:02:02 2014 +0200
+++ b/Resources/Samples/Plugins/Basic/Plugin.c	Wed Jun 18 15:22:13 2014 +0200
@@ -33,9 +33,9 @@
 static OrthancPluginContext* context = NULL;
 
 
-ORTHANC_PLUGINS_API int32_t Callback(OrthancPluginRestOutput* output,
-                                     const char* url,
-                                     const OrthancPluginHttpRequest* request)
+ORTHANC_PLUGINS_API int32_t Callback1(OrthancPluginRestOutput* output,
+                                      const char* url,
+                                      const OrthancPluginHttpRequest* request)
 {
   char buffer[1024];
   uint32_t i;
@@ -51,10 +51,42 @@
     OrthancPluginLogInfo(context, buffer);    
   }
 
+  printf("** %d\n", request->groupCount);
+  for (i = 0; i < request->groupCount; i++)
+  {
+    printf("** [%s]\n",  request->groupValues[i]);
+  }
+
   return 1;
 }
 
 
+ORTHANC_PLUGINS_API int32_t Callback2(OrthancPluginRestOutput* output,
+                                      const char* url,
+                                      const OrthancPluginHttpRequest* request)
+{
+  /**
+   * Answer with a sample 16bpp image.
+   **/
+
+  uint16_t buffer[256 * 256];
+  uint32_t x, y, value;
+
+  value = 0;
+  for (y = 0; y < 256; y++)
+  {
+    for (x = 0; x < 256; x++, value++)
+    {
+      buffer[value] = value;
+    }
+  }
+
+  OrthancPluginCompressAndAnswerPngImage(context, output, OrthancPluginPixelFormat_Grayscale16,
+                                         256, 256, sizeof(uint16_t) * 256, buffer);
+  return 0;
+}
+
+
 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
 {
   char info[1024];
@@ -65,7 +97,8 @@
   sprintf(info, "The version of Orthanc is '%s'", context->orthancVersion);
   OrthancPluginLogInfo(context, info);
 
-  OrthancPluginRegisterRestCallback(context, "/plu.*/hello", Callback);
+  OrthancPluginRegisterRestCallback(context, "/(plu.*)/hello", Callback1);
+  OrthancPluginRegisterRestCallback(context, "/plu.*/image", Callback2);
 
   return 0;
 }