Use a two stage pass, since several initialization functions now read preferences as part of their process.
This is due to the first time a_preferences_get() is called it loads any preferences values from disk,
but of course for preferences not registered yet it can't actually understand them.
Thus subsequent initial attempts to get unregistered preferences would not return the expected values.
/**
* a_babel_init:
*
- * Initialises babel module.
- * Mainly check existence of gpsbabel progam
- * and load all features available in that version.
+ * Just setup preferences first
*/
void a_babel_init ()
{
vlpd.s = "gpsbabel";
#endif
a_preferences_register(&prefs[0], vlpd, VIKING_PREFERENCES_IO_GROUP_KEY);
+}
+/**
+ * a_babel_post_init:
+ *
+ * Initialises babel module.
+ * Mainly check existence of gpsbabel progam
+ * and load all features available in that version.
+ */
+void a_babel_post_init ()
+{
// Read the current preference
const gchar *gpsbabel = a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "gpsbabel")->s;
// If setting is still the UNIX default then lookup in the path - otherwise attempt to use the specified value directly.
gboolean a_babel_convert_to( VikTrwLayer *vt, VikTrack *track, const char *babelargs, const char *file, BabelStatusFunc cb, gpointer user_data );
void a_babel_init ();
+void a_babel_post_init ();
void a_babel_uninit ();
gboolean a_babel_available ();
/**
* a_background_init:
*
+ * Just setup any preferences.
+ */
+void a_background_init ()
+{
+#ifdef HAVE_LIBMAPNIK
+ VikLayerParamData tmp;
+ // implicit use of 'MAPNIK_PREFS_NAMESPACE' to avoid dependency issues
+ tmp.u = 1; // Default to 1 thread due to potential crashing issues
+ a_preferences_register(&prefs_mapnik[0], tmp, "mapnik");
+#endif
+}
+
+/**
+ * a_background_post_init:
+ *
* Initialize background feature.
*/
-void a_background_init()
+void a_background_post_init()
{
// initialize thread pools
gint max_threads = 10; /* limit maximum number of threads running at one time */
thread_pool_local = g_thread_pool_new ( (GFunc) thread_helper, NULL, max_threads, FALSE, NULL );
#ifdef HAVE_LIBMAPNIK
- VikLayerParamData tmp;
// implicit use of 'MAPNIK_PREFS_NAMESPACE' to avoid dependency issues
- tmp.u = 1; // Default to 1 thread due to potential crashing issues
- a_preferences_register(&prefs_mapnik[0], tmp, "mapnik");
guint mapnik_threads = a_preferences_get("mapnik.background_max_threads_local_mapnik")->u;
thread_pool_local_mapnik = g_thread_pool_new ( (GFunc) thread_helper, NULL, mapnik_threads, FALSE, NULL );
#endif
int a_background_testcancel ( gpointer callbackdata );
void a_background_show_window ();
void a_background_init ();
+void a_background_post_init ();
void a_background_uninit ();
void a_background_add_window (VikWindow *vw);
void a_background_remove_window (VikWindow *vw);
a_settings_init ();
a_preferences_init ();
+ /*
+ * First stage initialization
+ *
+ * Should not use a_preferences_get() yet
+ *
+ * Since the first time a_preferences_get() is called it loads any preferences values from disk,
+ * but of course for preferences not registered yet it can't actually understand them
+ * so subsequent initial attempts to get those preferences return the default value, until the values have changed
+ */
a_vik_preferences_init ();
a_layer_defaults_init ();
a_toolbar_init();
vik_routing_prefs_init();
+ /*
+ * Second stage initialization
+ *
+ * Can now use a_preferences_get()
+ */
+ a_background_post_init ();
+ a_babel_post_init ();
+ modules_post_init ();
+
+ // May need to initialize the Positonal TimeZone lookup
if ( a_vik_get_time_ref_frame() == VIK_TIME_REF_WORLD )
vu_setup_lat_lon_tz_lookup();
g_debug("%d types loaded", (int)sizeof(types)/(int)sizeof(GType));
}
+/**
+ * First stage initialization
+ * Can not use a_get_preferences() yet...
+ * See comment in main.c
+ */
void modules_init()
{
#ifdef VIK_CONFIG_BING
modules_load_config ();
}
+/**
+ * modules_post_init:
+ *
+ * Secondary stage initialization
+ * Can now use a_get_preferences()
+ */
+void modules_post_init ()
+{
+#ifdef HAVE_LIBMAPNIK
+ vik_mapnik_layer_post_init();
+#endif
+}
+
/**
*
*/
#define __VIKING_MODULES_H
void modules_init();
-
+void modules_post_init ();
void modules_uninit();
#endif
void a_preferences_register(VikLayerParam *pref, VikLayerParamData defaultval, const gchar *group_key )
{
+ // All preferences should be registered before loading
+ if ( loaded )
+ g_critical ( "REGISTERING preference %s after LOADING from " VIKING_PREFS_FILE, pref->name );
/* copy value */
VikLayerParam *newpref = g_new(VikLayerParam,1);
*newpref = *pref;
VikLayerParamData *a_preferences_get(const gchar *key)
{
if ( ! loaded ) {
+ g_debug ( "%s: First time: %s\n", __FUNCTION__, key );
/* since we can't load the file in a_preferences_init (no params registered yet),
* do it once before we get the first key. */
preferences_load_from_file();
/**
* vik_mapnik_layer_init:
*
- * Mostly to initialize preferences
+ * Just initialize preferences
*/
void vik_mapnik_layer_init (void)
{
tmp.s = "carto";
a_preferences_register(&prefs[i++], tmp, MAPNIK_PREFS_GROUP_KEY);
+}
+/**
+ * vik_mapnik_layer_post_init:
+ *
+ * Initialize data structures - now that reading preferences is OK to perform
+ */
+void vik_mapnik_layer_post_init (void)
+{
tp_mutex = vik_mutex_new();
// Just storing keys only
typedef struct _VikMapnikLayer VikMapnikLayer;
void vik_mapnik_layer_init (void);
+void vik_mapnik_layer_post_init (void);
void vik_mapnik_layer_uninit (void);
G_END_DECLS