Permalink
Browse files

Added the BSD 2-Clause licence

  • Loading branch information...
homme committed Oct 17, 2012
1 parent dd7f501 commit b4eae2b7ff90d5d9bd65ec1f5655d63b62552309
Showing with 294 additions and 9 deletions.
  1. +26 −0 LICENCE
  2. +97 −0 examples/cluster-server.js
  3. +27 −0 examples/display.js
  4. +27 −0 examples/server.js
  5. +28 −1 lib/mapcache.js
  6. +34 −7 src/mapcache.cpp
  7. +28 −1 src/mapcache.hpp
  8. +27 −0 src/node-mapcache.cpp
View
26 LICENCE
@@ -0,0 +1,26 @@
+/******************************************************************************
+ * Copyright (c) 2012, GeoData Institute (www.geodata.soton.ac.uk)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
View
@@ -0,0 +1,97 @@
+/******************************************************************************
+ * Copyright (c) 2012, GeoData Institute (www.geodata.soton.ac.uk)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+
+/**
+ * Set up MapCache as a Clustered Tile Caching HTTP server
+ *
+ * This provides an example of how to use the MapCache module in
+ * combination with the Node HTTP module to create a tile caching
+ * server that uses all the available processing cores.
+ */
+
+var cluster = require('cluster'); //for the multi-processing
+var path = require('path'); // for file path manipulations
+var http = require('http'); // for the http server
+var url = require('url'); // for url parsing
+
+var mapcache = require('mapcache'); // the MapCache module
+
+var port = 3000; // which port will the server run on?
+var baseUrl = "http://localhost:" + port; // what is the server url?
+var conffile = path.join(__dirname, 'mapcache.xml'); // the location of the config file
+var numCPUs = require('os').cpus().length;
+
+if (cluster.isMaster) {
+ // Fork workers.
+ for (var i = 0; i < numCPUs; i++) {
+ cluster.fork();
+ }
+
+ cluster.on('exit', function(worker, code, signal) {
+ console.log('worker ' + worker.process.pid + ' died');
+ });
+} else {
+ // Instantiate a MapCache cache object from the configuration file
+ mapcache.MapCache.FromConfigFile(conffile, function handleCache(err, cache) {
+ if (err) {
+ throw err; // error loading the configuration file
+ }
+
+ // fire up a http server, handling all requests
+ http.createServer(function handleCacheRequest(req, res) {
+ var urlParts = url.parse(decodeURIComponent(req.url)); // parse the request url
+ var pathInfo = urlParts.pathname || "/"; // generate the PATH_INFO
+ var params = urlParts.query || ''; // generate the QUERY_STRING
+
+ // delegate the request to the MapCache cache object, handling the response
+ cache.get(baseUrl, pathInfo, params, function handleCacheResponse(err, cacheResponse) {
+ console.log('Serving ' + req.url);
+
+ if (err) {
+ // the cache returned an error: handle it
+ res.writeHead(500);
+ res.end(err.stack);
+ console.error(err.stack);
+ return;
+ }
+
+ // send the cache response to the client
+ res.writeHead(cacheResponse.code, cacheResponse.headers);
+ if (req.method !== 'HEAD') {
+ res.end(cacheResponse.data);
+ } else {
+ res.end();
+ }
+ });
+ }).listen(port, "localhost");
+
+ console.log(
+ "Server running at " + baseUrl + " - try the following WMS request:\n" +
+ baseUrl + '?LAYERS=test&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&FORMAT=image%2Fjpeg&SRS=EPSG%3A4326&BBOX=-180,-90,180,90&WIDTH=800&HEIGHT=400'
+ );
+ });
+}
View
@@ -1,3 +1,30 @@
+/******************************************************************************
+ * Copyright (c) 2012, GeoData Institute (www.geodata.soton.ac.uk)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+
/**
* Display the results of a cache request
*
View
@@ -1,3 +1,30 @@
+/******************************************************************************
+ * Copyright (c) 2012, GeoData Institute (www.geodata.soton.ac.uk)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+
/**
* Set up MapCache as a Tile Caching HTTP server
*
View
@@ -1,3 +1,30 @@
+/******************************************************************************
+ * Copyright (c) 2012, GeoData Institute (www.geodata.soton.ac.uk)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+
/**
* Node.js MapCache Tile Caching Module
*
@@ -46,7 +73,7 @@ function httpCacheHandler(cache) {
var urlParts = url.parse(req.url);
var params = urlParts.query || '';
var pathInfo = urlParts.pathname || "/";
-
+
cache.get(baseUrl, pathInfo, params, getCacheResponseHandler(req, res));
}
View
@@ -1,3 +1,30 @@
+/******************************************************************************
+ * Copyright (c) 2012, GeoData Institute (www.geodata.soton.ac.uk)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+
/**
* @file mapcache.cpp
* @brief This defines the primary `MapCache` class.
@@ -43,7 +70,7 @@ Persistent<FunctionTemplate> MapCache::constructor_template;
*
* @param target The object representing the module.
*/
-void MapCache::Init(Handle<Object> target) {
+void MapCache::Init(Handle<Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(New);
@@ -412,7 +439,7 @@ void MapCache::FromConfigFileWork(uv_work_t *req) {
return;
}
-/**
+/**
* @details This is set by `FromConfigFileAsync` to run after
* `FromConfigFileWork` has finished, being passed the response
* generated by the latter and running in the same thread as the
@@ -484,7 +511,7 @@ MapCache::config_context* MapCache::CreateConfigContext() {
return ctx;
}
-/**
+/**
* @param pool The memory pool to be used for the context.
*/
MapCache::request_context* MapCache::CreateRequestContext(apr_pool_t *pool) {
@@ -512,13 +539,13 @@ MapCache::request_context* MapCache::CreateRequestContext(apr_pool_t *pool) {
return (request_context *)ctx;
}
-/**
+/**
* @details This is set as a function pointer to the context created
* by `CreateRequestContext`. It is called by the wrapped mapcache
* library when required.
*
* @param ctxt The mapcache context to clone.
- */
+ */
mapcache_context* MapCache::CloneRequestContext(mapcache_context *ctx) {
mapcache_context *newctx = (mapcache_context*)apr_pcalloc(ctx->pool,
sizeof(request_context));
@@ -529,10 +556,10 @@ mapcache_context* MapCache::CloneRequestContext(mapcache_context *ctx) {
return newctx;
}
-/**
+/**
* @details This currently outputs the log to STDERR. It might be nice
* to eventually expose it via a Node `EventEmitter`.
- */
+ */
void MapCache::LogRequestContext(mapcache_context *c, mapcache_log_level level, char *message, ...) {
va_list args;
va_start(args,message);
View
@@ -1,3 +1,30 @@
+/******************************************************************************
+ * Copyright (c) 2012, GeoData Institute (www.geodata.soton.ac.uk)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+
#ifndef __NODE_MAPCACHE_H__
#define __NODE_MAPCACHE_H__
@@ -212,7 +239,7 @@ class MapCache: ObjectWrap {
* extract in the `args` array.
* @param VAR The symbol name of the variable to be created.
- * @def REQ_FUN_ARG(I, VAR)
+ * @def REQ_FUN_ARG(I, VAR)
*
* This throws a `TypeError` if the argument is of the wrong type.
*
View
@@ -1,3 +1,30 @@
+/******************************************************************************
+ * Copyright (c) 2012, GeoData Institute (www.geodata.soton.ac.uk)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+
/**
* @file node-mapcache.cpp
* @brief This registers and initialises the module with Node.

0 comments on commit b4eae2b

Please sign in to comment.