Skip to content

Commit

Permalink
Split up renderd.conf processing by section type (openstreetmap#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
hummeltech authored Mar 2, 2024
1 parent 04a0bf0 commit 2de946d
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 222 deletions.
4 changes: 2 additions & 2 deletions includes/parameterize_style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

#include <mapnik/map.hpp>

typedef void (*parameterize_function_ptr)(mapnik::Map &m, char * parameter);
typedef void (*parameterize_function_ptr)(mapnik::Map &m, char *parameter);

parameterize_function_ptr init_parameterization_function(char * function_name);
parameterize_function_ptr init_parameterization_function(const char *function_name);

#endif
41 changes: 22 additions & 19 deletions includes/renderd.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,34 @@ int daemon(int nochdir, int noclose);
#define MAX_SLAVES 5

typedef struct {
char *iphostname;
char *mapnik_font_dir;
char *mapnik_plugins_dir;
char *pid_filename;
char *socketname;
char *stats_filename;
char *tile_dir;
const char *iphostname;
const char *mapnik_font_dir;
const char *mapnik_plugins_dir;
const char *name;
const char *pid_filename;
const char *socketname;
const char *stats_filename;
const char *tile_dir;
int ipport;
int mapnik_font_dir_recurse;
int num_threads;
} renderd_config;

typedef struct {
char *attribution;
char *cors;
char *description;
char *host;
char *htcpip;
char *output_format;
char *parameterization;
char *server_alias;
char *tile_dir;
char *xmlfile;
char *xmlname;
char *xmluri;
const char *attribution;
const char *cors;
const char *description;
const char *file_extension;
const char *host;
const char *htcpip;
const char *mime_type;
const char *output_format;
const char *parameterization;
const char *server_alias;
const char *tile_dir;
const char *xmlfile;
const char *xmlname;
const char *xmluri;
double scale_factor;
int aspect_x;
int aspect_y;
Expand Down
15 changes: 11 additions & 4 deletions includes/renderd_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@
extern "C" {
#endif

extern int num_slave_threads;
extern renderd_config config;
extern renderd_config config_slaves[MAX_SLAVES];
extern xmlconfigitem maps[XMLCONFIGS_MAX];
int num_slave_threads;
renderd_config config;
renderd_config config_slaves[MAX_SLAVES];
xmlconfigitem maps[XMLCONFIGS_MAX];

int min_max_int_opt(const char *opt_arg, const char *opt_type_name, int minimum, int maximum);
void free_map_section(xmlconfigitem map_section);
void free_map_sections(xmlconfigitem *map_sections);
void free_renderd_section(renderd_config renderd_section);
void free_renderd_sections(renderd_config *renderd_sections);
void process_config_file(const char *config_file_name, int active_renderd_section_num, int log_level);
void process_map_sections(const char *config_file_name, xmlconfigitem *maps_dest, const char *default_tile_dir, int num_threads);
void process_mapnik_section(const char *config_file_name, renderd_config *config_dest);
void process_renderd_sections(const char *config_file_name, renderd_config *configs_dest);

#ifdef __cplusplus
}
Expand Down
29 changes: 12 additions & 17 deletions src/parameterize_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@
* along with this program; If not, see http://www.gnu.org/licenses/.
*/

#include <mapnik/version.hpp>
#include <mapnik/map.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/params.hpp>
#include <boost/optional.hpp>
#include <mapnik/datasource.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/map.hpp>
#include <mapnik/params.hpp>
#include <mapnik/version.hpp>

#include <boost/optional.hpp>

#include "parameterize_style.hpp"
#include "g_logger.h"
#include "parameterize_style.hpp"


static void parameterize_map_language(mapnik::Map &m, char * parameter)
static void parameterize_map_language(mapnik::Map &m, char *parameter)
{
unsigned int i;
char * data = strdup(parameter);
char * tok;
char *data = strdup(parameter);
char *tok;
char name_replace[256];

name_replace[0] = 0;
Expand All @@ -41,7 +39,7 @@ static void parameterize_map_language(mapnik::Map &m, char * parameter)

if (!tok) {
free(data);
return; //No parameterization given
return; // No parameterization given
}

strncat(name_replace, ", coalesce(", 255);
Expand All @@ -56,15 +54,14 @@ static void parameterize_map_language(mapnik::Map &m, char * parameter)
}

tok = strtok(NULL, ",");

}

free(data);
name_replace[strlen(name_replace) - 1] = 0;
strncat(name_replace, ") as name", 255);

for (i = 0; i < m.layer_count(); i++) {
mapnik::layer& l = m.get_layer(i);
mapnik::layer &l = m.get_layer(i);
mapnik::parameters params = l.datasource()->params();

if (params.find("table") != params.end()) {
Expand All @@ -78,12 +75,10 @@ static void parameterize_map_language(mapnik::Map &m, char * parameter)
l.set_datasource(mapnik::datasource_cache::instance().create(params));
}
}

}
}


parameterize_function_ptr init_parameterization_function(char * function_name)
parameterize_function_ptr init_parameterization_function(const char *function_name)
{
if (strcmp(function_name, "") == 0) {
g_logger(G_LOG_LEVEL_DEBUG, "Parameterize_style not specified (or empty string specified)");
Expand Down
20 changes: 15 additions & 5 deletions src/renderd.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ int main(int argc, char **argv)

switch (c) {
case 'c': /* -c, --config */
config_file_name = strdup(optarg);
config_file_name = strndup(optarg, PATH_MAX);
config_file_name_passed = 1;

struct stat buffer;
Expand Down Expand Up @@ -777,7 +777,7 @@ int main(int argc, char **argv)
fprintf(stderr, " -V, --version display the version number and exit\n");
return 0;

case 'V':
case 'V': /* -V, --version */
fprintf(stdout, "%s\n", VERSION);
return 0;

Expand All @@ -799,6 +799,10 @@ int main(int argc, char **argv)

process_config_file(config_file_name, active_renderd_section_num, G_LOG_LEVEL_INFO);

if (config_file_name_passed) {
free((void *)config_file_name);
}

fd = server_socket_init(&config);

#if 0
Expand Down Expand Up @@ -867,10 +871,9 @@ int main(int argc, char **argv)
}

if (active_renderd_section_num == 0) {
//Only the master renderd opens connections to its slaves
// Only the master renderd opens connections to its slaves
k = 0;
slave_threads
= (pthread_t *) malloc(sizeof(pthread_t) * num_slave_threads);
slave_threads = (pthread_t *) malloc(sizeof(pthread_t) * num_slave_threads);

for (i = 1; i < MAX_SLAVES; i++) {
for (j = 0; j < config_slaves[i].num_threads; j++) {
Expand All @@ -881,6 +884,13 @@ int main(int argc, char **argv)
}
}
}
} else {
for (i = 0; i < MAX_SLAVES; i++) {
if (active_renderd_section_num != i && config_slaves[i].num_threads != 0) {
g_logger(G_LOG_LEVEL_DEBUG, "Freeing unused renderd config section %i: %s", i, config_slaves[i].name);
free_renderd_section(config_slaves[i]);
}
}
}

process_loop(fd);
Expand Down
Loading

0 comments on commit 2de946d

Please sign in to comment.