[grilo-plugins/wip/carlosg/tracker3: 8/39] tracker3: Make sources manage notifications
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins/wip/carlosg/tracker3: 8/39] tracker3: Make sources manage notifications
- Date: Sun, 14 Jun 2020 18:37:12 +0000 (UTC)
commit 8e0424f207c4cf65a0c97ac473ea850661791b89
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed May 20 03:03:50 2020 +0200
tracker3: Make sources manage notifications
Instead of being a singleton, the GrlSource sets up its own
notification.
src/tracker3/grl-tracker-source-api.c | 5 ++--
src/tracker3/grl-tracker-source-notif.c | 50 ++++++++++++++++-----------------
src/tracker3/grl-tracker-source-notif.h | 7 +++--
src/tracker3/grl-tracker-source-priv.h | 2 ++
src/tracker3/grl-tracker-source.c | 20 +++++++++++--
src/tracker3/grl-tracker.c | 5 +---
6 files changed, 52 insertions(+), 37 deletions(-)
---
diff --git a/src/tracker3/grl-tracker-source-api.c b/src/tracker3/grl-tracker-source-api.c
index e627c237..59dc1cf2 100644
--- a/src/tracker3/grl-tracker-source-api.c
+++ b/src/tracker3/grl-tracker-source-api.c
@@ -1217,7 +1217,8 @@ grl_tracker_source_change_start (GrlSource *source, GError **error)
{
GrlTrackerSourcePriv *priv = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
- priv->notify_changes = TRUE;
+ priv->notifier =
+ grl_tracker_source_notify_new (source, priv->tracker_connection);
return TRUE;
}
@@ -1227,7 +1228,7 @@ grl_tracker_source_change_stop (GrlSource *source, GError **error)
{
GrlTrackerSourcePriv *priv = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
- priv->notify_changes = FALSE;
+ g_clear_object (&priv->notifier);
return TRUE;
}
diff --git a/src/tracker3/grl-tracker-source-notif.c b/src/tracker3/grl-tracker-source-notif.c
index ffdc62b0..ff4a4c61 100644
--- a/src/tracker3/grl-tracker-source-notif.c
+++ b/src/tracker3/grl-tracker-source-notif.c
@@ -36,19 +36,18 @@
#define GRL_LOG_DOMAIN_DEFAULT tracker_notif_log_domain
GRL_LOG_DOMAIN_STATIC(tracker_notif_log_domain);
-#define GRL_TRACKER_TYPE_SOURCE_NOTIFY grl_tracker_source_notify_get_type ()
-G_DECLARE_FINAL_TYPE (GrlTrackerSourceNotify, grl_tracker_source_notify, GRL_TRACKER, SOURCE_NOTIFY, GObject)
-
struct _GrlTrackerSourceNotify {
GObject parent;
TrackerSparqlConnection *connection;
TrackerNotifier *notifier;
+ GrlSource *source;
guint events_signal_id;
};
enum {
PROP_0,
PROP_CONNECTION,
+ PROP_SOURCE,
N_PROPS
};
@@ -56,8 +55,6 @@ static GParamSpec *props[N_PROPS] = { 0, };
G_DEFINE_TYPE (GrlTrackerSourceNotify, grl_tracker_source_notify, G_TYPE_OBJECT)
-static GrlTrackerSourceNotify *singleton = NULL;
-
static GrlMedia *
media_for_event (GrlTrackerSourceNotify *self,
TrackerNotifierEvent *event)
@@ -83,17 +80,11 @@ handle_changes (GrlTrackerSourceNotify *self,
TrackerNotifierEventType tracker_type,
GrlSourceChangeType change_type)
{
- GrlTrackerSource *source = NULL;
TrackerNotifierEvent *event;
GPtrArray *change_list;
GrlMedia *media;
gint i;
- source = grl_tracker_source_find ("");
-
- if (!source || !grl_tracker_source_can_notify (source))
- return;
-
change_list = g_ptr_array_new ();
for (i = 0; i < events->len; i++) {
@@ -105,7 +96,7 @@ handle_changes (GrlTrackerSourceNotify *self,
g_ptr_array_add (change_list, media);
}
- grl_source_notify_change_list (GRL_SOURCE (source), change_list,
+ grl_source_notify_change_list (self->source, change_list,
change_type, FALSE);
}
@@ -139,6 +130,9 @@ grl_tracker_source_notify_get_property (GObject *object,
case PROP_CONNECTION:
g_value_set_object (value, self->connection);
break;
+ case PROP_SOURCE:
+ g_value_set_object (value, self->source);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -157,6 +151,9 @@ grl_tracker_source_notify_set_property (GObject *object,
case PROP_CONNECTION:
self->connection = g_value_get_object (value);
break;
+ case PROP_SOURCE:
+ self->source = g_value_get_object (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -208,6 +205,14 @@ grl_tracker_source_notify_class_init (GrlTrackerSourceNotifyClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
+ props[PROP_SOURCE] =
+ g_param_spec_object ("source",
+ "Source",
+ "Source being notified",
+ GRL_TYPE_SOURCE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, props);
}
@@ -217,19 +222,12 @@ grl_tracker_source_notify_init (GrlTrackerSourceNotify *self)
{
}
-void
-grl_tracker_notify_init (TrackerSparqlConnection *sparql_conn)
-{
- if (singleton != NULL)
- return;
-
- singleton = g_object_new (GRL_TRACKER_TYPE_SOURCE_NOTIFY,
- "connection", sparql_conn,
- NULL);
-}
-
-void
-grl_tracker_notify_shutdown (void)
+GrlTrackerSourceNotify *
+grl_tracker_source_notify_new (GrlSource *source,
+ TrackerSparqlConnection *sparql_conn)
{
- g_clear_object (&singleton);
+ return g_object_new (GRL_TRACKER_TYPE_SOURCE_NOTIFY,
+ "source", source,
+ "connection", sparql_conn,
+ NULL);
}
diff --git a/src/tracker3/grl-tracker-source-notif.h b/src/tracker3/grl-tracker-source-notif.h
index dd787221..6b6e5678 100644
--- a/src/tracker3/grl-tracker-source-notif.h
+++ b/src/tracker3/grl-tracker-source-notif.h
@@ -31,6 +31,9 @@
/* ------- Definitions ------- */
+#define GRL_TRACKER_TYPE_SOURCE_NOTIFY grl_tracker_source_notify_get_type ()
+G_DECLARE_FINAL_TYPE (GrlTrackerSourceNotify, grl_tracker_source_notify, GRL_TRACKER, SOURCE_NOTIFY, GObject)
+
#define TRACKER_DATASOURCES_REQUEST \
"SELECT " \
"(SELECT GROUP_CONCAT(rdf:type(?source), \":\") " \
@@ -49,7 +52,7 @@
/**/
-void grl_tracker_notify_init (TrackerSparqlConnection *sparql_conn);
-void grl_tracker_notify_shutdown (void);
+GrlTrackerSourceNotify * grl_tracker_source_notify_new (GrlSource *source,
+ TrackerSparqlConnection *sparql_conn);
#endif /* _GRL_TRACKER_SOURCE_NOTIF_H_ */
diff --git a/src/tracker3/grl-tracker-source-priv.h b/src/tracker3/grl-tracker-source-priv.h
index 227e19db..7016b6e6 100644
--- a/src/tracker3/grl-tracker-source-priv.h
+++ b/src/tracker3/grl-tracker-source-priv.h
@@ -29,6 +29,7 @@
#include "grl-tracker-source.h"
#include "grl-tracker-source-cache.h"
+#include "grl-tracker-source-notif.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -65,6 +66,7 @@ struct _GrlTrackerSourcePriv {
TrackerSparqlConnection *tracker_connection;
GHashTable *operations;
+ GrlTrackerSourceNotify *notifier;
gchar *tracker_datasource;
gboolean notify_changes;
diff --git a/src/tracker3/grl-tracker-source.c b/src/tracker3/grl-tracker-source.c
index 78c39980..c0b245f2 100644
--- a/src/tracker3/grl-tracker-source.c
+++ b/src/tracker3/grl-tracker-source.c
@@ -65,6 +65,8 @@ static void grl_tracker_source_set_property (GObject *object,
static void grl_tracker_source_finalize (GObject *object);
+static void grl_tracker_source_constructed (GObject *object);
+
/* ===================== Globals ================= */
/* shared data across */
@@ -97,6 +99,7 @@ grl_tracker_source_class_init (GrlTrackerSourceClass * klass)
g_class->finalize = grl_tracker_source_finalize;
g_class->set_property = grl_tracker_source_set_property;
+ g_class->constructed = grl_tracker_source_constructed;
source_class->cancel = grl_tracker_source_cancel;
source_class->supported_keys = grl_tracker_supported_keys;
@@ -147,6 +150,18 @@ grl_tracker_source_init (GrlTrackerSource *source)
priv->operations = g_hash_table_new (g_direct_hash, g_direct_equal);
}
+static void
+grl_tracker_source_constructed (GObject *object)
+{
+ GrlTrackerSource *self;
+
+ self = GRL_TRACKER_SOURCE (object);
+
+ g_clear_object (&self->priv->tracker_connection);
+
+ G_OBJECT_CLASS (grl_tracker_source_parent_class)->constructed (object);
+}
+
static void
grl_tracker_source_finalize (GObject *object)
{
@@ -154,6 +169,7 @@ grl_tracker_source_finalize (GObject *object)
self = GRL_TRACKER_SOURCE (object);
+ g_clear_object (&self->priv->notifier);
g_clear_object (&self->priv->tracker_connection);
G_OBJECT_CLASS (grl_tracker_source_parent_class)->finalize (object);
@@ -251,7 +267,7 @@ grl_tracker_source_can_notify (GrlTrackerSource *source)
GrlTrackerSourcePriv *priv = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
if (priv->state == GRL_TRACKER_SOURCE_STATE_RUNNING)
- return priv->notify_changes;
+ return priv->notifier != NULL;
return FALSE;
}
@@ -306,8 +322,6 @@ grl_tracker_source_sources_init (void)
if (grl_tracker_connection != NULL) {
GrlTrackerSource *source;
- grl_tracker_notify_init (grl_tracker_connection);
-
/* One source to rule them all. */
source = grl_tracker_source_new (grl_tracker_connection);
grl_tracker_add_source (source);
diff --git a/src/tracker3/grl-tracker.c b/src/tracker3/grl-tracker.c
index 3505db59..380f816b 100644
--- a/src/tracker3/grl-tracker.c
+++ b/src/tracker3/grl-tracker.c
@@ -68,11 +68,8 @@ init_sources (void)
grl_tracker_queue = grl_tracker_queue_new ();
- if (grl_tracker_connection != NULL) {
- grl_tracker_notify_init (grl_tracker_connection);
-
+ if (grl_tracker_connection != NULL)
grl_tracker_source_sources_init ();
- }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]