From 2ac2290fd3023d707b520c3e8d2d7bfa69cd0d53 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 21 Dec 2011 14:03:47 +0000 Subject: [PATCH] Put PostgreSQL module related code in a new postgis_module.c file Beside the existing MODULE_MAGIC macro we now also have _PG_init and _PG_fini which are called at module load and unload. Such functions may be used to deal with GUC (and sample code for that is stubbed already). See #1393. git-svn-id: http://svn.osgeo.org/postgis/trunk@8486 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/Makefile.in | 1 + postgis/lwgeom_functions_basic.c | 5 -- postgis/postgis_module.c | 84 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 postgis/postgis_module.c diff --git a/postgis/Makefile.in b/postgis/Makefile.in index 951e5f655..f70fa49ca 100644 --- a/postgis/Makefile.in +++ b/postgis/Makefile.in @@ -22,6 +22,7 @@ SQL_OBJS=postgis.sql.in uninstall_postgis.sql.in legacy.sql.in uninstall_legacy. # PostgreSQL objects PG_OBJS=lwgeom_debug.o \ + postgis_module.o \ lwgeom_accum.o \ lwgeom_spheroid.o \ lwgeom_ogc.o \ diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 30e7c6804..68ae03e7c 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -26,11 +26,6 @@ #include #include -/* - * This is required for builds against pgsql - */ -PG_MODULE_MAGIC; - Datum LWGEOM_mem_size(PG_FUNCTION_ARGS); Datum LWGEOM_summary(PG_FUNCTION_ARGS); Datum LWGEOM_npoints(PG_FUNCTION_ARGS); diff --git a/postgis/postgis_module.c b/postgis/postgis_module.c new file mode 100644 index 000000000..654b84b36 --- /dev/null +++ b/postgis/postgis_module.c @@ -0,0 +1,84 @@ +/********************************************************************** + * + * PostGIS - Spatial Types for PostgreSQL + * http://postgis.refractions.net + * + * Copyright (C) 2011 OpenGeo.org + * + * This is free software; you can redistribute and/or modify it under + * the terms of the GNU General Public Licence. See the COPYING file. + * + **********************************************************************/ + +#include "postgres.h" +#include "fmgr.h" +#include "utils/elog.h" +#include "utils/guc.h" + +#include "lwgeom_log.h" +#include "lwgeom_pg.h" +#include "../postgis_config.h" + +/* + * This is required for builds against pgsql + */ +PG_MODULE_MAGIC; + +/* + * Module load callback + */ +void _PG_init(void); +void +_PG_init(void) +{ +#if 0 + /* Define custom GUC variables. */ + DefineCustomIntVariable( + "postgis.debug.level", /* name */ + "Sets the debugging level of PostGIS.", /* short_desc */ + "This is an experimental configuration.", /* long_desc */ + &postgis_debug_level, /* valueAddr */ + 0, 8, /* min-max */ + 0, /* bootValue */ + PGC_SUSET, /* GucContext context */ + GUC_UNIT_MS, /* int flags */ +#if POSTGIS_PGSQL_VERSION >= 91 + NULL, /* GucStringCheckHook check_hook */ +#endif + NULL, /* GucStringAssignHook assign_hook */ + NULL /* GucShowHook show_hook */ + ); +#endif + +#if 0 + /* Define custom GUC variables. */ + DefineCustomStringVariable( + "postgis.greeting.string", /* name */ + "Sets the greeting string used on postgis module load.", /* short_desc */ + "This is an experimental configuration.", /* long_desc */ + &greeting, /* valueAddr */ + "Welcome to PostGIS " POSTGIS_VERSION, /* bootValue */ + PGC_SUSET, /* GucContext context */ + GUC_UNIT_MS, /* int flags */ +#if POSTGIS_PGSQL_VERSION >= 91 + NULL, /* GucStringCheckHook check_hook */ +#endif + NULL, /* GucStringAssignHook assign_hook */ + NULL /* GucShowHook show_hook */ + ); +#endif + +} + +/* + * Module unload callback + */ +void _PG_fini(void); +void +_PG_fini(void) +{ + elog(NOTICE, "Goodbye from PostGIS %s", POSTGIS_VERSION); +} + + + -- 2.40.0