From 2ebc19fe192fe5f1a7cac66b178f91758f0316d5 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 13 Jan 2014 18:35:16 +0100 Subject: [PATCH 09/12] log-store: add 'writable' property This makes the API more symetric as we already had a 'readable' property and will allow us to easily instantiate read-only stores. --- telepathy-logger/log-store-pidgin.c | 5 +++++ telepathy-logger/log-store-sqlite.c | 6 ++++++ telepathy-logger/log-store-xml.c | 5 +++++ telepathy-logger/log-store.c | 32 ++++++++++++++++++++++++++++++-- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/telepathy-logger/log-store-pidgin.c b/telepathy-logger/log-store-pidgin.c index 036b6b7..cdbd043 100644 --- a/telepathy-logger/log-store-pidgin.c +++ b/telepathy-logger/log-store-pidgin.c @@ -56,6 +56,7 @@ enum { PROP_0, PROP_NAME, PROP_READABLE, + PROP_WRITABLE, }; @@ -90,6 +91,9 @@ tpl_log_store_pidgin_get_property (GObject *object, case PROP_READABLE: g_value_set_boolean (value, TRUE); break; + case PROP_WRITABLE: + g_value_set_boolean (value, FALSE); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -150,6 +154,7 @@ tpl_log_store_pidgin_class_init (TplLogStorePidginClass *klass) g_object_class_override_property (object_class, PROP_NAME, "name"); g_object_class_override_property (object_class, PROP_READABLE, "readable"); + g_object_class_override_property (object_class, PROP_WRITABLE, "writable"); g_type_class_add_private (object_class, sizeof (TplLogStorePidginPriv)); } diff --git a/telepathy-logger/log-store-sqlite.c b/telepathy-logger/log-store-sqlite.c index ace554f..26d1ac2 100644 --- a/telepathy-logger/log-store-sqlite.c +++ b/telepathy-logger/log-store-sqlite.c @@ -52,6 +52,7 @@ enum /* properties */ PROP_0, PROP_NAME, PROP_READABLE, + PROP_WRITABLE, }; struct _TplLogStoreSqlitePrivate @@ -116,6 +117,10 @@ tpl_log_store_sqlite_get_property (GObject *self, g_value_set_boolean (value, FALSE); break; + case PROP_WRITABLE: + g_value_set_boolean (value, TRUE); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec); break; @@ -324,6 +329,7 @@ _tpl_log_store_sqlite_class_init (TplLogStoreSqliteClass *klass) g_object_class_override_property (gobject_class, PROP_NAME, "name"); g_object_class_override_property (gobject_class, PROP_READABLE, "readable"); + g_object_class_override_property (gobject_class, PROP_WRITABLE, "writable"); g_type_class_add_private (gobject_class, sizeof (TplLogStoreSqlitePrivate)); } diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c index 3a05dad..11edc03 100644 --- a/telepathy-logger/log-store-xml.c +++ b/telepathy-logger/log-store-xml.c @@ -88,6 +88,7 @@ enum { PROP_0, PROP_NAME, PROP_READABLE, + PROP_WRITABLE, }; static void log_store_iface_init (gpointer g_iface, gpointer iface_data); @@ -159,6 +160,9 @@ tpl_log_store_xml_get_property (GObject *object, case PROP_READABLE: g_value_set_boolean (value, TRUE); break; + case PROP_WRITABLE: + g_value_set_boolean (value, TRUE); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -198,6 +202,7 @@ _tpl_log_store_xml_class_init (TplLogStoreXmlClass *klass) g_object_class_override_property (object_class, PROP_NAME, "name"); g_object_class_override_property (object_class, PROP_READABLE, "readable"); + g_object_class_override_property (object_class, PROP_WRITABLE, "writable"); g_type_class_add_private (object_class, sizeof (TplLogStoreXmlPriv)); } diff --git a/telepathy-logger/log-store.c b/telepathy-logger/log-store.c index 48952ec..fbf0255 100644 --- a/telepathy-logger/log-store.c +++ b/telepathy-logger/log-store.c @@ -95,6 +95,22 @@ _tpl_log_store_init (gpointer g_iface) "Whether this log store is readable", TRUE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + /** + * TplLogStore:writable: + * + * Defines whether the object is writable for a #TplLogManager. + * + * If an TplLogStore implementation is writable, the #TplLogManager will + * use the _tpl_log_store_add_event method against the instance + * every time a event needs to be logged. + */ + g_object_interface_install_property (g_iface, + g_param_spec_boolean ("writable", + "Writable", + "Whether this log store is writable", + FALSE, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); } gchar * @@ -371,11 +387,23 @@ _tpl_log_store_create_iter (TplLogStore *self, gboolean _tpl_log_store_is_writable (TplLogStore *self) { + gboolean writable; + g_return_val_if_fail (TPL_IS_LOG_STORE (self), FALSE); - return (TPL_LOG_STORE_GET_INTERFACE (self)->add_event != NULL); -} + g_object_get (self, + "writable", &writable, + NULL); + if (!writable) + return FALSE; + + /* If the store claims to be writable it MUST implement add_event */ + g_return_val_if_fail (TPL_LOG_STORE_GET_INTERFACE (self)->add_event != NULL, + FALSE); + + return TRUE; +} gboolean _tpl_log_store_is_readable (TplLogStore *self) -- 1.8.4.2