[grits] Improve shutdown code



commit 032ddbf6f1d5abbfc96e236e3a9f22b867f009f1
Author: Andy Spencer <andy753421 gmail com>
Date:   Tue May 24 05:51:20 2011 +0000

    Improve shutdown code

 src/grits-plugin.c |    8 ++------
 src/grits-test.c   |    8 ++++----
 src/grits-viewer.c |    1 +
 src/plugins/elev.c |    8 ++++++--
 src/plugins/map.c  |    5 +++++
 src/plugins/sat.c  |    5 +++++
 src/plugins/test.c |    4 ++--
 7 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/src/grits-plugin.c b/src/grits-plugin.c
index 494b716..91514fc 100644
--- a/src/grits-plugin.c
+++ b/src/grits-plugin.c
@@ -155,11 +155,7 @@ GritsPlugins *grits_plugins_new(const gchar *dir, GritsPrefs *prefs)
 static void grits_plugins_free_store(GritsPluginStore *store)
 {
 	g_object_unref(store->plugin);
-	/* Flush any possible callbacks before
-	 * unloading the plugin code */
-	while (gtk_events_pending())
-		  gtk_main_iteration();
-	g_module_close(store->module);
+	//g_module_close(store->module);
 	g_free(store->name);
 	g_free(store);
 }
@@ -349,8 +345,8 @@ gboolean grits_plugins_unload(GritsPlugins *plugins, const char *name)
 	for (GList *cur = plugins->plugins; cur; cur = cur->next) {
 		GritsPluginStore *store = cur->data;
 		if (g_str_equal(store->name, name)) {
-			grits_plugins_free_store(store);
 			plugins->plugins = g_list_delete_link(plugins->plugins, cur);
+			grits_plugins_free_store(store);
 		}
 	}
 	return FALSE;
diff --git a/src/grits-test.c b/src/grits-test.c
index 8f46185..67e299d 100644
--- a/src/grits-test.c
+++ b/src/grits-test.c
@@ -31,13 +31,13 @@ GritsViewer  *viewer  = NULL;
  *************/
 static gboolean grits_shutdown(GtkWidget *window)
 {
+	static gboolean shutdown = FALSE;
+	if (shutdown) return TRUE;
+	shutdown = TRUE;
+
 	grits_plugins_free(plugins);
 	g_object_unref(prefs);
 	gtk_widget_destroy(window);
-
-	while (gtk_events_pending())
-		  gtk_main_iteration();
-
 	gtk_main_quit();
 	return TRUE;
 }
diff --git a/src/grits-viewer.c b/src/grits-viewer.c
index bb86d64..bfc704b 100644
--- a/src/grits-viewer.c
+++ b/src/grits-viewer.c
@@ -592,6 +592,7 @@ static void grits_viewer_finalize(GObject *gobject)
 {
 	g_debug("GritsViewer: finalize");
 	G_OBJECT_CLASS(grits_viewer_parent_class)->finalize(gobject);
+	g_debug("GritsViewer: finalize - done");
 }
 static void grits_viewer_class_init(GritsViewerClass *klass)
 {
diff --git a/src/plugins/elev.c b/src/plugins/elev.c
index 251ec74..e99b326 100644
--- a/src/plugins/elev.c
+++ b/src/plugins/elev.c
@@ -336,9 +336,11 @@ static void grits_plugin_elev_dispose(GObject *gobject)
 	g_debug("GritsPluginElev: dispose");
 	GritsPluginElev *elev = GRITS_PLUGIN_ELEV(gobject);
 	/* Drop references */
-	if (LOAD_BIL)
-		grits_viewer_clear_height_func(elev->viewer);
 	if (elev->viewer) {
+		if (LOAD_BIL)
+			grits_viewer_clear_height_func(elev->viewer);
+		if (LOAD_OPENGL)
+			grits_viewer_remove(elev->viewer, elev->tiles);
 		g_signal_handler_disconnect(elev->viewer, elev->sigid);
 		g_object_unref(elev->viewer);
 		elev->viewer = NULL;
@@ -352,6 +354,8 @@ static void grits_plugin_elev_finalize(GObject *gobject)
 	/* Free data */
 	grits_tile_free(elev->tiles, _free_tile, elev);
 	grits_wms_free(elev->wms);
+	g_mutex_lock(elev->mutex);
+	g_mutex_unlock(elev->mutex);
 	g_mutex_free(elev->mutex);
 	G_OBJECT_CLASS(grits_plugin_elev_parent_class)->finalize(gobject);
 
diff --git a/src/plugins/map.c b/src/plugins/map.c
index 6c73796..b1363e4 100644
--- a/src/plugins/map.c
+++ b/src/plugins/map.c
@@ -220,6 +220,7 @@ static void grits_plugin_map_init(GritsPluginMap *map)
 	map->wms   = grits_wms_new(
 		"http://labs.metacarta.com/wms/vmap0";, "basic", "image/png",
 		"osm/", "png", TILE_WIDTH, TILE_HEIGHT);
+	g_object_ref(map->tiles);
 }
 static void grits_plugin_map_dispose(GObject *gobject)
 {
@@ -228,6 +229,10 @@ static void grits_plugin_map_dispose(GObject *gobject)
 	/* Drop references */
 	if (map->viewer) {
 		g_signal_handler_disconnect(map->viewer, map->sigid);
+		grits_viewer_remove(map->viewer, map->tiles);
+		soup_session_abort(map->wms->http->soup);
+		while (gtk_events_pending())
+			gtk_main_iteration();
 		g_object_unref(map->viewer);
 		map->viewer = NULL;
 	}
diff --git a/src/plugins/sat.c b/src/plugins/sat.c
index 29a7d26..ebcc838 100644
--- a/src/plugins/sat.c
+++ b/src/plugins/sat.c
@@ -210,6 +210,7 @@ static void grits_plugin_sat_init(GritsPluginSat *sat)
 	sat->wms   = grits_wms_new(
 		"http://www.nasa.network.com/wms";, "bmng200406", "image/jpeg",
 		"bmng/", "jpg", TILE_WIDTH, TILE_HEIGHT);
+	g_object_ref(sat->tiles);
 }
 static void grits_plugin_sat_dispose(GObject *gobject)
 {
@@ -218,6 +219,10 @@ static void grits_plugin_sat_dispose(GObject *gobject)
 	/* Drop references */
 	if (sat->viewer) {
 		g_signal_handler_disconnect(sat->viewer, sat->sigid);
+		grits_viewer_remove(sat->viewer, sat->tiles);
+		soup_session_abort(sat->wms->http->soup);
+		while (gtk_events_pending())
+			gtk_main_iteration();
 		g_object_unref(sat->viewer);
 		sat->viewer = NULL;
 	}
diff --git a/src/plugins/test.c b/src/plugins/test.c
index 609297c..d917092 100644
--- a/src/plugins/test.c
+++ b/src/plugins/test.c
@@ -56,7 +56,7 @@ GritsPluginTest *grits_plugin_test_new(GritsViewer *viewer)
 	g_debug("GritsPluginTest: new");
 	GritsPluginTest *test = g_object_new(GRITS_TYPE_PLUGIN_TEST, NULL);
 	test->viewer = g_object_ref(viewer);
-	g_idle_add(_load_marker, test);
+	_load_marker(test);
 	return test;
 }
 
@@ -88,7 +88,7 @@ static void grits_plugin_test_dispose(GObject *_test)
 		g_object_unref(test->viewer);
 		test->viewer = NULL;
 	}
-	G_OBJECT_CLASS(grits_plugin_test_parent_class)->finalize(_test);
+	G_OBJECT_CLASS(grits_plugin_test_parent_class)->dispose(_test);
 }
 static void grits_plugin_test_class_init(GritsPluginTestClass *klass)
 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]