[tracker/tracker-0.6] Add mechanisms to TrackerDBInterface/TrackerDBManager to invalidate interfaces.
- From: Carlos Garnacho <carlosg src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker/tracker-0.6] Add mechanisms to TrackerDBInterface/TrackerDBManager to invalidate interfaces.
- Date: Wed, 3 Jun 2009 09:38:47 -0400 (EDT)
commit ad8769aca03fbf80800bd7216ebf8e009f0ba33b
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Jun 3 15:35:21 2009 +0200
Add mechanisms to TrackerDBInterface/TrackerDBManager to invalidate interfaces.
On shutdown, all interfaces created through the DB manager will emit a
"invalidated" signal, so callers have to do pending cleanups if necessary.
---
src/libtracker-db/tracker-db-interface.c | 9 ++++++
src/libtracker-db/tracker-db-manager.c | 40 ++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/src/libtracker-db/tracker-db-interface.c b/src/libtracker-db/tracker-db-interface.c
index 7cbfbc6..8ab7283 100644
--- a/src/libtracker-db/tracker-db-interface.c
+++ b/src/libtracker-db/tracker-db-interface.c
@@ -63,6 +63,15 @@ tracker_db_interface_error_quark (void)
static void
tracker_db_interface_class_init (gpointer iface)
{
+ GType iface_type = G_TYPE_FROM_INTERFACE (iface);
+
+ g_signal_new ("invalidated",
+ iface_type,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
g_object_interface_install_property (iface,
g_param_spec_boolean ("in-transaction",
"In transaction",
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index 1fe426c..d13d9f9 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -220,6 +220,7 @@ static gchar *sys_tmp_dir;
static gpointer db_type_enum_class_pointer;
static TrackerDBInterface *file_iface;
static TrackerDBInterface *email_iface;
+static GList *not_owned_ifaces = NULL;
static const gchar *
location_to_directory (TrackerDBLocation location)
@@ -2364,6 +2365,23 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
return TRUE;
}
+static void
+invalidate_ifaces (void)
+{
+ GList *l;
+ gint i;
+
+ for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
+ if (dbs[i].iface) {
+ g_signal_emit_by_name (dbs[i].iface, "invalidated");
+ }
+ }
+
+ for (l = not_owned_ifaces; l; l = l->next) {
+ g_signal_emit_by_name (l->data, "invalidated");
+ }
+}
+
void
tracker_db_manager_shutdown (void)
{
@@ -2373,6 +2391,8 @@ tracker_db_manager_shutdown (void)
return;
}
+ invalidate_ifaces ();
+
for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
if (dbs[i].abs_filename) {
g_free (dbs[i].abs_filename);
@@ -2429,6 +2449,9 @@ tracker_db_manager_shutdown (void)
tracker_ontology_shutdown ();
initialized = FALSE;
+
+ g_list_free (not_owned_ifaces);
+ not_owned_ifaces = NULL;
}
void
@@ -2484,6 +2507,13 @@ tracker_db_manager_get_file (TrackerDB db)
return dbs[db].abs_filename;
}
+static void
+remove_not_owned_iface (gpointer user_data,
+ GObject *iface)
+{
+ not_owned_ifaces = g_list_remove (not_owned_ifaces, iface);
+}
+
/**
* tracker_db_manager_get_db_interfaces:
* @num: amount of TrackerDB files wanted
@@ -2529,6 +2559,11 @@ tracker_db_manager_get_db_interfaces (gint num, ...)
}
va_end (args);
+ if (connection) {
+ not_owned_ifaces = g_list_prepend (not_owned_ifaces, connection);
+ g_object_weak_ref (G_OBJECT (connection), remove_not_owned_iface, NULL);
+ }
+
return connection;
}
@@ -2563,6 +2598,11 @@ tracker_db_manager_get_db_interfaces_ro (gint num, ...)
}
va_end (args);
+ if (connection) {
+ not_owned_ifaces = g_list_prepend (not_owned_ifaces, connection);
+ g_object_weak_ref (G_OBJECT (connection), remove_not_owned_iface, NULL);
+ }
+
return connection;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]