[mapserver-commits] r12943 - in trunk/mapserver/mapcache: include src

svn at osgeo.org svn at osgeo.org
Tue Jan 3 04:47:10 EST 2012


Author: tbonfort
Date: 2012-01-03 01:47:10 -0800 (Tue, 03 Jan 2012)
New Revision: 12943

Modified:
   trunk/mapserver/mapcache/include/mapcache.h
   trunk/mapserver/mapcache/src/configuration.c
   trunk/mapserver/mapcache/src/configuration_xml.c
   trunk/mapserver/mapcache/src/service_wms.c
   trunk/mapserver/mapcache/src/source_gdal.c
   trunk/mapserver/mapcache/src/source_mapserver.c
   trunk/mapserver/mapcache/src/source_wms.c
   trunk/mapserver/mapcache/src/tileset.c
Log:
add initial WMS mirror-mode implementation


Modified: trunk/mapserver/mapcache/include/mapcache.h
===================================================================
--- trunk/mapserver/mapcache/include/mapcache.h	2012-01-02 19:17:57 UTC (rev 12942)
+++ trunk/mapserver/mapcache/include/mapcache.h	2012-01-03 09:47:10 UTC (rev 12943)
@@ -36,7 +36,6 @@
 
 #include <apr_tables.h>
 #include <apr_hash.h>
-#include <apr_global_mutex.h>
 #include "util.h"
 #include "ezxml.h"
 
@@ -267,7 +266,7 @@
     void (*query_info)(mapcache_context *ctx, mapcache_feature_info *fi);
 
     void (*configuration_parse_xml)(mapcache_context *ctx, ezxml_t xml, mapcache_source * source);
-    void (*configuration_check)(mapcache_context *ctx, mapcache_source * source);
+    void (*configuration_check)(mapcache_context *ctx, mapcache_cfg *cfg, mapcache_source * source);
 };
 
 mapcache_http* mapcache_http_configuration_parse_xml(mapcache_context *ctx,ezxml_t node);
@@ -848,11 +847,17 @@
 /** @{ */
 
 struct mapcache_server_cfg {
-   apr_global_mutex_t *mutex;
-   char *mutex_name;
    apr_hash_t *aliases; /**< list of mapcache configurations aliased to a server uri */
 };
 
+
+
+typedef enum {
+   MAPCACHE_MODE_NORMAL,
+   MAPCACHE_MODE_MIRROR_COMBINED,
+   MAPCACHE_MODE_MIRROR_SPLIT
+} mapcache_mode;
+
 /**
  * a configuration that will be served
  */
@@ -936,6 +941,7 @@
     mapcache_log_level loglevel; /* logging verbosity. Ignored for the apache module
                                     as in that case the apache LogLevel directive is
                                     used. */
+    mapcache_mode mode;
 };
 
 /**
@@ -1143,15 +1149,12 @@
      */
     mapcache_cfg *config;
    
-    /**
-     * should we service wms requests not aligned to a grid
-     */
-    int full_wms;
-
     apr_table_t *metadata;
 };
 
 
+mapcache_tileset* mapcache_tileset_clone(mapcache_context *ctx, mapcache_tileset *tileset);
+
 void mapcache_tileset_get_map_tiles(mapcache_context *ctx, mapcache_tileset *tileset,
       mapcache_grid_link *grid_link,
       double *bbox, int width, int height,

Modified: trunk/mapserver/mapcache/src/configuration.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration.c	2012-01-02 19:17:57 UTC (rev 12942)
+++ trunk/mapserver/mapcache/src/configuration.c	2012-01-03 09:47:10 UTC (rev 12943)
@@ -275,7 +275,11 @@
 }
 
 mapcache_tileset *mapcache_configuration_get_tileset(mapcache_cfg *config, const char *key) {
-   return (mapcache_tileset*)apr_hash_get(config->tilesets, (void*)key, APR_HASH_KEY_STRING);
+   if(config->mode == MAPCACHE_MODE_NORMAL) {
+      return (mapcache_tileset*)apr_hash_get(config->tilesets, (void*)key, APR_HASH_KEY_STRING);
+   } else {
+      return (mapcache_tileset*)apr_hash_get(config->tilesets, (void*)"mirror", APR_HASH_KEY_STRING);
+   }
 }
 
 mapcache_image_format *mapcache_configuration_get_image_format(mapcache_cfg *config, const char *key) {

Modified: trunk/mapserver/mapcache/src/configuration_xml.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration_xml.c	2012-01-02 19:17:57 UTC (rev 12942)
+++ trunk/mapserver/mapcache/src/configuration_xml.c	2012-01-03 09:47:10 UTC (rev 12943)
@@ -296,7 +296,7 @@
    
    source->configuration_parse_xml(ctx,node,source);
    GC_CHECK_ERROR(ctx);
-   source->configuration_check(ctx,source);
+   source->configuration_check(ctx,config,source);
    GC_CHECK_ERROR(ctx);
    mapcache_configuration_add_source(config,source,name);
 }
@@ -375,7 +375,7 @@
       }
       format = mapcache_imageio_create_jpeg_format(ctx->pool,
             name,quality,photometric);
-   } else if(!strcmp(type,"MIXED")){
+   } else if(!strcasecmp(type,"MIXED")){
       mapcache_image_format *transparent=NULL, *opaque=NULL;
       if ((cur_node = ezxml_child(node,"transparent")) != NULL) {
          transparent = mapcache_configuration_get_image_format(config,cur_node->txt);
@@ -483,7 +483,11 @@
    ezxml_t cur_node;
    char* value;
    int havewgs84bbox=0;
-   name = (char*)ezxml_attr(node,"name");
+   if(config->mode == MAPCACHE_MODE_NORMAL) {
+      name = (char*)ezxml_attr(node,"name");
+   } else {
+      name = "mirror";
+   }
    if(!name || !strlen(name)) {
       ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <tileset>");
       return;
@@ -801,6 +805,21 @@
       ctx->set_error(ctx,400, "failed to parse file %s. first node is not <mapcache>", filename);
       goto cleanup;
    }
+   const char *mode = ezxml_attr(doc,"mode");
+   if(mode) {
+      if(!strcmp(mode,"combined_mirror")) {
+         config->mode = MAPCACHE_MODE_MIRROR_COMBINED;
+      } else if(!strcmp(mode,"split_mirror")) {
+         config->mode = MAPCACHE_MODE_MIRROR_SPLIT;
+      } else if(!strcmp(mode,"normal")) {
+         config->mode = MAPCACHE_MODE_NORMAL;
+      } else {
+         ctx->set_error(ctx,400,"unknown mode \"%s\" for <mapcache>",mode);
+         goto cleanup;
+      }
+   } else {
+         config->mode = MAPCACHE_MODE_NORMAL;
+   }
 
    for(node = ezxml_child(doc,"metadata"); node; node = node->next) {
       parseMetadata(ctx, node, config->metadata);

Modified: trunk/mapserver/mapcache/src/service_wms.c
===================================================================
--- trunk/mapserver/mapcache/src/service_wms.c	2012-01-02 19:17:57 UTC (rev 12942)
+++ trunk/mapserver/mapcache/src/service_wms.c	2012-01-03 09:47:10 UTC (rev 12943)
@@ -443,7 +443,7 @@
       }
    }
    if(iswms130) {
-      /*check if we should flib the axis order*/
+      /*check if we should flip the axis order*/
       if(mapcache_is_axis_inverted(srs)) {
          double swap;
          swap = bbox[0];
@@ -471,10 +471,14 @@
          mapcache_request_get_tile *tile_req = NULL;
          mapcache_grid_link *main_grid_link = NULL;
          mapcache_tileset *main_tileset = NULL;
-	 mapcache_request_type type;
+         mapcache_request_type type;
          
-         /* count the number of layers that are requested */
-         for(key=str;*key;key++) if(*key == ',') count++;
+         /* count the number of layers that are requested.
+          * if we are in combined-mirror mode, then there is
+          * always a single layer */
+         if(config->mode != MAPCACHE_MODE_MIRROR_COMBINED) {
+            for(key=str;*key;key++) if(*key == ',') count++;
+         }
 
          /* 
           * look to see if we have a getTile or a getMap request. We do this by looking at the first
@@ -483,7 +487,7 @@
           */
          type = MAPCACHE_REQUEST_GET_TILE;
          
-         if(count ==1) {
+         if(count ==1 || config->mode == MAPCACHE_MODE_MIRROR_COMBINED) {
             key = str;
          } else {
             layers = apr_pstrdup(ctx->pool,str);
@@ -495,6 +499,10 @@
             errmsg = apr_psprintf(ctx->pool,"received wms request with invalid layer %s", key);
             goto proxies;
          }
+         if(config->mode != MAPCACHE_MODE_NORMAL) {
+            main_tileset = mapcache_tileset_clone(ctx,main_tileset);
+            main_tileset->name = key;
+         }
 
          for(i=0;i<main_tileset->grid_links->nelts;i++){
             mapcache_grid_link *sgrid = APR_ARRAY_IDX(main_tileset->grid_links,i,mapcache_grid_link*);
@@ -552,7 +560,7 @@
 
          for (layeridx=0,key = ((count==1)?str:apr_strtok(layers, ",", &last)); key != NULL;
                key = ((count==1)?NULL:apr_strtok(NULL, ",", &last)),layeridx++) {
-	   int i;
+            int i;
             mapcache_tileset *tileset = main_tileset;
             mapcache_grid_link *grid_link = main_grid_link;
             apr_table_t *dimtable = NULL;
@@ -568,6 +576,10 @@
                   errmsg = apr_psprintf(ctx->pool,"received wms request with invalid layer %s", key);
                   goto proxies;
                }
+               if(config->mode != MAPCACHE_MODE_NORMAL) {
+                  tileset = mapcache_tileset_clone(ctx,tileset);
+                  tileset->name = key;
+               }
                grid_link = NULL;
                for(i=0;i<tileset->grid_links->nelts;i++){
                   grid_link = APR_ARRAY_IDX(tileset->grid_links,i,mapcache_grid_link*);

Modified: trunk/mapserver/mapcache/src/source_gdal.c
===================================================================
--- trunk/mapserver/mapcache/src/source_gdal.c	2012-01-02 19:17:57 UTC (rev 12942)
+++ trunk/mapserver/mapcache/src/source_gdal.c	2012-01-03 09:47:10 UTC (rev 12943)
@@ -241,7 +241,8 @@
  * \private \memberof mapcache_source_gdal
  * \sa mapcache_source::configuration_check()
  */
-void _mapcache_source_gdal_configuration_check(mapcache_context *ctx, mapcache_source *source) {
+void _mapcache_source_gdal_configuration_check(mapcache_context *ctx, mapcache_cfg *cfg,
+      mapcache_source *source) {
    mapcache_source_gdal *src = (mapcache_source_gdal*)source;
    /* check all required parameters are configured */
    if(!strlen(src->datastr)) {

Modified: trunk/mapserver/mapcache/src/source_mapserver.c
===================================================================
--- trunk/mapserver/mapcache/src/source_mapserver.c	2012-01-02 19:17:57 UTC (rev 12942)
+++ trunk/mapserver/mapcache/src/source_mapserver.c	2012-01-03 09:47:10 UTC (rev 12943)
@@ -180,7 +180,8 @@
  * \private \memberof mapcache_source_mapserver
  * \sa mapcache_source::configuration_check()
  */
-void _mapcache_source_mapserver_configuration_check(mapcache_context *ctx, mapcache_source *source) {
+void _mapcache_source_mapserver_configuration_check(mapcache_context *ctx, mapcache_cfg *cfg,
+      mapcache_source *source) {
    mapcache_source_mapserver *src = (mapcache_source_mapserver*)source;
    /* check all required parameters are configured */
    if(!src->mapfile) {

Modified: trunk/mapserver/mapcache/src/source_wms.c
===================================================================
--- trunk/mapserver/mapcache/src/source_wms.c	2012-01-02 19:17:57 UTC (rev 12942)
+++ trunk/mapserver/mapcache/src/source_wms.c	2012-01-03 09:47:10 UTC (rev 12943)
@@ -47,7 +47,7 @@
     apr_table_setn(params,"FORMAT","image/png");
     apr_table_setn(params,"SRS",map->grid_link->grid->srs);
  
-    apr_table_overlap(params,wms->getmap_params,0);
+    apr_table_overlap(params,wms->getmap_params,APR_OVERLAP_TABLES_SET);
     if(map->dimensions && !apr_is_empty_table(map->dimensions)) {
        const apr_array_header_t *elts = apr_table_elts(map->dimensions);
        int i;
@@ -56,7 +56,16 @@
           apr_table_setn(params,entry.key,entry.val);
        }
  
-    }      
+    }
+
+    /* if the source has no LAYERS parameter defined, then use the tileset name
+     * as the LAYERS to request. When using mirror-mode, the source has no layers
+     * defined, it is added based on the incoming request
+     */
+    if(!apr_table_get(params,"layers")) {
+       apr_table_set(params,"LAYERS",map->tileset->name);
+    }
+
     map->encoded_data = mapcache_buffer_create(30000,ctx->pool);
     mapcache_http_do_request_with_params(ctx,wms->http,params,map->encoded_data,NULL,NULL);
     GC_CHECK_ERROR(ctx);
@@ -158,14 +167,17 @@
  * \private \memberof mapcache_source_wms
  * \sa mapcache_source::configuration_check()
  */
-void _mapcache_source_wms_configuration_check(mapcache_context *ctx, mapcache_source *source) {
+void _mapcache_source_wms_configuration_check(mapcache_context *ctx, mapcache_cfg *cfg,
+      mapcache_source *source) {
    mapcache_source_wms *src = (mapcache_source_wms*)source;
    /* check all required parameters are configured */
    if(!src->http) {
       ctx->set_error(ctx, 400, "wms source %s has no <http> request configured",source->name);
    }
    if(!apr_table_get(src->getmap_params,"LAYERS")) {
-      ctx->set_error(ctx, 400, "wms source %s has no LAYERS", source->name);
+      if(cfg->mode == MAPCACHE_MODE_NORMAL) {
+         ctx->set_error(ctx, 400, "wms source %s has no LAYERS", source->name);
+      }
    }
    if(source->info_formats) {
       if(!apr_table_get(src->getfeatureinfo_params,"QUERY_LAYERS")) {

Modified: trunk/mapserver/mapcache/src/tileset.c
===================================================================
--- trunk/mapserver/mapcache/src/tileset.c	2012-01-02 19:17:57 UTC (rev 12942)
+++ trunk/mapserver/mapcache/src/tileset.c	2012-01-03 09:47:10 UTC (rev 12943)
@@ -412,6 +412,30 @@
    return tileset;
 }
 
+mapcache_tileset* mapcache_tileset_clone(mapcache_context *ctx, mapcache_tileset *src) {
+   mapcache_tileset* dst = (mapcache_tileset*)apr_pcalloc(ctx->pool, sizeof(mapcache_tileset));
+   dst->metasize_x = src->metasize_x;
+   dst->metasize_y = src->metasize_y;
+   dst->metabuffer = src->metabuffer;
+   dst->expires = src->expires;
+   dst->auto_expire = src->auto_expire;
+   dst->metadata = src->metadata;
+   dst->dimensions = src->dimensions;
+   dst->format = src->format;
+   dst->grid_links = src->grid_links;
+   dst->config = src->config;
+   dst->name = src->name;
+   dst->cache = src->cache;
+   dst->source = src->source;
+   dst->watermark = src->watermark;
+   dst->wgs84bbox[0] = src->wgs84bbox[0];
+   dst->wgs84bbox[1] = src->wgs84bbox[1];
+   dst->wgs84bbox[2] = src->wgs84bbox[2];
+   dst->wgs84bbox[3] = src->wgs84bbox[3];
+   dst->format = src->format;
+   return dst;
+}
+
 /*
  * allocate and initialize a tile for a given tileset
  */
@@ -588,5 +612,6 @@
    }
 }
 
+
 /* vim: ai ts=3 sts=3 et sw=3
 */



More information about the mapserver-commits mailing list