summaryrefslogtreecommitdiff
path: root/telepathy-logger
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2014-03-20 16:43:34 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2014-03-20 16:43:34 +0000
commitd371e2b9903981008e51f984f16ed18724ee8e9c (patch)
tree594f24d03bf7f229f8c7e65e08ba835f1822c6ad /telepathy-logger
parentb69970c32ebe25764ec9b21d45794c1f22f52010 (diff)
parent71eb66b32cabf75f1d831d2e720b0e11dfe40d7e (diff)
Merge remote-tracking branch 'cassidy/logger-1-70990' into next
Diffstat (limited to 'telepathy-logger')
-rw-r--r--telepathy-logger/Makefile.am2
-rw-r--r--telepathy-logger/log-manager.c51
-rw-r--r--telepathy-logger/log-store-empathy-internal.h54
-rw-r--r--telepathy-logger/log-store-empathy.c67
-rw-r--r--telepathy-logger/log-store-internal.h4
-rw-r--r--telepathy-logger/log-store-pidgin-internal.h2
-rw-r--r--telepathy-logger/log-store-pidgin.c99
-rw-r--r--telepathy-logger/log-store-sqlite.c60
-rw-r--r--telepathy-logger/log-store-xml-internal.h6
-rw-r--r--telepathy-logger/log-store-xml.c114
-rw-r--r--telepathy-logger/log-store.c58
11 files changed, 230 insertions, 287 deletions
diff --git a/telepathy-logger/Makefile.am b/telepathy-logger/Makefile.am
index ad4f88138..27187d0c7 100644
--- a/telepathy-logger/Makefile.am
+++ b/telepathy-logger/Makefile.am
@@ -99,8 +99,6 @@ libtelepathy_logger_1_la_SOURCES = \
log-store-internal.h \
log-store-xml.c \
log-store-xml-internal.h \
- log-store-empathy.c \
- log-store-empathy-internal.h \
log-store-sqlite.c \
log-store-sqlite-internal.h \
log-store-pidgin.c \
diff --git a/telepathy-logger/log-manager.c b/telepathy-logger/log-manager.c
index 95ebeb7a4..dfc761d37 100644
--- a/telepathy-logger/log-manager.c
+++ b/telepathy-logger/log-manager.c
@@ -39,7 +39,6 @@
#include <telepathy-logger/event.h>
#include <telepathy-logger/event-internal.h>
#include <telepathy-logger/log-store-internal.h>
-#include <telepathy-logger/log-store-empathy-internal.h>
#include <telepathy-logger/log-store-xml-internal.h>
#include <telepathy-logger/log-store-pidgin-internal.h>
#include <telepathy-logger/log-store-sqlite-internal.h>
@@ -192,18 +191,15 @@ static void
add_log_store (TplLogManager *self,
TplLogStore *store)
{
+ gchar *name;
+
g_return_if_fail (TPL_IS_LOG_STORE (store));
- /* set the log store in "testmode" if it supports it and the environment is
- * currently in test mode */
- if (g_object_class_find_property (G_OBJECT_GET_CLASS (store), "testmode"))
- g_object_set (store,
- "testmode", (g_getenv ("TPL_TEST_MODE") != NULL),
- NULL);
+ name = _tpl_log_store_dup_name (store);
if (!_tpl_log_manager_register_log_store (self, store))
- CRITICAL ("Failed to register store name=%s",
- _tpl_log_store_get_name (store));
+ CRITICAL ("Failed to register store name=%s", name);
+ g_free (name);
/* drop the initial ref */
g_object_unref (store);
@@ -276,23 +272,18 @@ tpl_log_manager_init (TplLogManager *self)
G_CALLBACK (_globally_enabled_changed), NULL);
/* The TPL's default read-write logstore */
- add_log_store (self,
- g_object_new (TPL_TYPE_LOG_STORE_XML,
- NULL));
+ add_log_store (self, _tpl_log_store_xml_new ());
+
+ /* Old (pre 1.0) TPL logs, read only */
+ add_log_store (self, _tpl_log_store_xml_legacy_new ());
/* Load by default the Empathy's legacy 'past coversations' LogStore */
- add_log_store (self,
- g_object_new (TPL_TYPE_LOG_STORE_EMPATHY,
- NULL));
+ add_log_store (self, _tpl_log_store_empathy_new ());
- add_log_store (self,
- g_object_new (TPL_TYPE_LOG_STORE_PIDGIN,
- NULL));
+ add_log_store (self, _tpl_log_store_pidgin_new ());
/* Load the event counting cache */
- add_log_store (self,
- g_object_new (TPL_TYPE_LOG_STORE_SQLITE,
- NULL));
+ add_log_store (self, _tpl_log_store_sqlite_dup ());
DEBUG ("Log Manager initialised");
}
@@ -366,10 +357,14 @@ _tpl_log_manager_add_event (TplLogManager *manager,
result = _tpl_log_store_add_event (store, event, &loc_error);
if (!result)
{
+ gchar *name = _tpl_log_store_dup_name (store);
+
CRITICAL ("logstore name=%s: %s. "
"Event may not be logged properly.",
- _tpl_log_store_get_name (store),
+ name,
loc_error != NULL ? loc_error->message : "no error message");
+
+ g_free (name);
g_clear_error (&loc_error);
}
/* TRUE if at least one LogStore succeeds */
@@ -403,7 +398,7 @@ _tpl_log_manager_register_log_store (TplLogManager *self,
TplLogStore *logstore)
{
TplLogManagerPriv *priv = self->priv;
- const gchar *name = _tpl_log_store_get_name (logstore);
+ gchar *name = _tpl_log_store_dup_name (logstore);
GList *l;
g_return_val_if_fail (TPL_IS_LOG_MANAGER (self), FALSE);
@@ -413,12 +408,17 @@ _tpl_log_manager_register_log_store (TplLogManager *self,
for (l = priv->stores; l != NULL; l = g_list_next (l))
{
TplLogStore *store = l->data;
+ gchar *n = _tpl_log_store_dup_name (store);
- if (!tp_strdiff (name, _tpl_log_store_get_name (store)))
+ if (!tp_strdiff (name, n))
{
DEBUG ("name=%s: already registered", name);
+ g_free (n);
+ g_free (name);
return FALSE;
}
+
+ g_free (n);
}
if (_tpl_log_store_is_readable (logstore))
@@ -430,8 +430,9 @@ _tpl_log_manager_register_log_store (TplLogManager *self,
/* reference just once, writable/readable lists are kept in sync with the
* general list and never written separately */
priv->stores = g_list_prepend (priv->stores, g_object_ref (logstore));
- DEBUG ("LogStore name=%s registered", _tpl_log_store_get_name (logstore));
+ DEBUG ("LogStore name=%s registered", name);
+ g_free (name);
return TRUE;
}
diff --git a/telepathy-logger/log-store-empathy-internal.h b/telepathy-logger/log-store-empathy-internal.h
deleted file mode 100644
index e4645bdd7..000000000
--- a/telepathy-logger/log-store-empathy-internal.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright © 2013 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef TPL_LOG_STORE_EMPATHY_H
-#define TPL_LOG_STORE_EMPATHY_H
-
-#include "log-store-xml-internal.h"
-
-typedef struct _TplLogStoreEmpathy TplLogStoreEmpathy;
-typedef struct _TplLogStoreEmpathyClass TplLogStoreEmpathyClass;
-
-struct _TplLogStoreEmpathyClass {
- /*< private >*/
- TplLogStoreXmlClass parent_class;
-};
-
-struct _TplLogStoreEmpathy {
- TplLogStoreXml parent;
-};
-
-GType _tpl_log_store_empathy_get_type (void);
-
-/* TYPE MACROS */
-#define TPL_TYPE_LOG_STORE_EMPATHY \
- (_tpl_log_store_empathy_get_type ())
-#define TPL_LOG_STORE_EMPATHY(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST((obj), TPL_TYPE_LOG_STORE_EMPATHY, TplLogStoreEmpathy))
-#define TPL_LOG_STORE_EMPATHY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST((klass), TPL_TYPE_LOG_STORE_EMPATHY,\
- TplLogStoreEmpathyClass))
-#define TPL_IS_LOG_STORE_EMPATHY(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE((obj), TPL_TYPE_LOG_STORE_EMPATHY))
-#define TPL_IS_LOG_STORE_EMPATHY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE((klass), TPL_TYPE_LOG_STORE_EMPATHY))
-#define TPL_LOG_STORE_EMPATHY_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_LOG_STORE_EMPATHY, \
- TplLogStoreEmpathyClass))
-
-#endif /* TPL_LOG_STORE_EMPATHY_H */
diff --git a/telepathy-logger/log-store-empathy.c b/telepathy-logger/log-store-empathy.c
deleted file mode 100644
index 651c72192..000000000
--- a/telepathy-logger/log-store-empathy.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright ©2013 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * This is a subclass of TplLogStoreXml to read logs from the directory Empathy
- * used to store them it. It disables writing to that legacy location.
- */
-
-#include "config.h"
-#include "log-store-empathy-internal.h"
-
-#include "telepathy-logger/log-store-internal.h"
-
-static void log_store_iface_init (gpointer g_iface, gpointer iface_data);
-
-G_DEFINE_TYPE_WITH_CODE (TplLogStoreEmpathy, _tpl_log_store_empathy,
- TPL_TYPE_LOG_STORE_XML,
- G_IMPLEMENT_INTERFACE (TPL_TYPE_LOG_STORE, log_store_iface_init))
-
-static void
-_tpl_log_store_empathy_init (TplLogStoreEmpathy *self)
-{
-}
-
-static void
-_tpl_log_store_empathy_class_init (TplLogStoreEmpathyClass *klass)
-{
-}
-
-
-static const gchar *
-log_store_empathy_get_name (TplLogStore *store)
-{
- TplLogStoreXml *self = (TplLogStoreXml *) store;
-
- g_return_val_if_fail (TPL_IS_LOG_STORE_EMPATHY (self), NULL);
-
- return "Empathy";
-}
-
-static void
-log_store_iface_init (gpointer g_iface,
- gpointer iface_data)
-{
- TplLogStoreInterface *iface = (TplLogStoreInterface *) g_iface;
-
- iface->get_name = log_store_empathy_get_name;
-
- /* We don't want to store new logs in Empathy's directory, just read the old
- * ones. */
- iface->add_event = NULL;
-}
diff --git a/telepathy-logger/log-store-internal.h b/telepathy-logger/log-store-internal.h
index 9b0a66695..158278b86 100644
--- a/telepathy-logger/log-store-internal.h
+++ b/telepathy-logger/log-store-internal.h
@@ -61,7 +61,6 @@ typedef struct
{
GTypeInterface parent;
- const gchar * (*get_name) (TplLogStore *self);
gboolean (*exists) (TplLogStore *self, TpAccount *account,
TplEntity *target, gint type_mask);
gboolean (*add_event) (TplLogStore *self, TplEvent *event,
@@ -87,7 +86,8 @@ typedef struct
GType _tpl_log_store_get_type (void);
-const gchar * _tpl_log_store_get_name (TplLogStore *self);
+gchar * _tpl_log_store_dup_name (TplLogStore *self)
+ G_GNUC_WARN_UNUSED_RESULT;
gboolean _tpl_log_store_exists (TplLogStore *self, TpAccount *account,
TplEntity *target, gint type_mask);
gboolean _tpl_log_store_add_event (TplLogStore *self, TplEvent *event,
diff --git a/telepathy-logger/log-store-pidgin-internal.h b/telepathy-logger/log-store-pidgin-internal.h
index abe214e50..1de987290 100644
--- a/telepathy-logger/log-store-pidgin-internal.h
+++ b/telepathy-logger/log-store-pidgin-internal.h
@@ -58,6 +58,8 @@ typedef struct
GType tpl_log_store_pidgin_get_type (void);
+TplLogStore * _tpl_log_store_pidgin_new (void);
+
G_END_DECLS
#endif /* __TPL_LOG_STORE_PIDGIN_H__ */
diff --git a/telepathy-logger/log-store-pidgin.c b/telepathy-logger/log-store-pidgin.c
index 95ab29a19..2aff34fe4 100644
--- a/telepathy-logger/log-store-pidgin.c
+++ b/telepathy-logger/log-store-pidgin.c
@@ -46,17 +46,18 @@
struct _TplLogStorePidginPriv
{
- gboolean test_mode;
- TpAccountManager *account_manager;
+ gchar *name;
+ gboolean writable;
+ TpAccountManager *account_manager;
gchar *basedir;
};
enum {
PROP_0,
+ PROP_NAME,
PROP_READABLE,
- PROP_BASEDIR,
- PROP_TESTMODE,
+ PROP_WRITABLE,
};
@@ -66,7 +67,6 @@ static void tpl_log_store_pidgin_get_property (GObject *object, guint param_id,
GParamSpec *pspec);
static void tpl_log_store_pidgin_set_property (GObject *object, guint param_id, const GValue *value,
GParamSpec *pspec);
-static const gchar *log_store_pidgin_get_name (TplLogStore *store);
static const gchar *log_store_pidgin_get_basedir (TplLogStorePidgin *self);
static void log_store_pidgin_set_basedir (TplLogStorePidgin *self,
const gchar *data);
@@ -82,18 +82,18 @@ tpl_log_store_pidgin_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- TplLogStorePidginPriv *priv = TPL_LOG_STORE_PIDGIN (object)->priv;
+ TplLogStorePidgin *self = TPL_LOG_STORE_PIDGIN (object);
switch (param_id)
{
+ case PROP_NAME:
+ g_value_set_string (value, self->priv->name);
+ break;
case PROP_READABLE:
g_value_set_boolean (value, TRUE);
break;
- case PROP_BASEDIR:
- g_value_set_string (value, priv->basedir);
- break;
- case PROP_TESTMODE:
- g_value_set_boolean (value, priv->test_mode);
+ case PROP_WRITABLE:
+ g_value_set_boolean (value, self->priv->writable);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -112,11 +112,12 @@ tpl_log_store_pidgin_set_property (GObject *object,
switch (param_id)
{
- case PROP_BASEDIR:
- log_store_pidgin_set_basedir (self, g_value_get_string (value));
+ case PROP_NAME:
+ self->priv->name = g_value_dup_string (value);
break;
- case PROP_TESTMODE:
- self->priv->test_mode = g_value_get_boolean (value);
+ case PROP_WRITABLE:
+ /* we don't support writing to Pidgin logs atm */
+ g_return_if_fail (!g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -131,44 +132,34 @@ tpl_log_store_pidgin_dispose (GObject *self)
TplLogStorePidginPriv *priv = TPL_LOG_STORE_PIDGIN (self)->priv;
g_clear_object (&priv->account_manager);
- g_free (priv->basedir);
- priv->basedir = NULL;
G_OBJECT_CLASS (tpl_log_store_pidgin_parent_class)->dispose (self);
}
+static void
+tpl_log_store_pidgin_finalize (GObject *self)
+{
+ TplLogStorePidginPriv *priv = TPL_LOG_STORE_PIDGIN (self)->priv;
+
+ g_free (priv->basedir);
+ g_free (priv->name);
+
+ G_OBJECT_CLASS (tpl_log_store_pidgin_parent_class)->finalize (self);
+}
static void
tpl_log_store_pidgin_class_init (TplLogStorePidginClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GParamSpec *param_spec;
object_class->get_property = tpl_log_store_pidgin_get_property;
object_class->set_property = tpl_log_store_pidgin_set_property;
object_class->dispose = tpl_log_store_pidgin_dispose;
+ object_class->finalize = tpl_log_store_pidgin_finalize;
+ g_object_class_override_property (object_class, PROP_NAME, "name");
g_object_class_override_property (object_class, PROP_READABLE, "readable");
-
- /**
- * TplLogStorePidgin:basedir:
- *
- * The log store's basedir.
- */
- param_spec = g_param_spec_string ("basedir",
- "Basedir",
- "The directory where the LogStore will look for data",
- NULL, G_PARAM_READABLE | G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class, PROP_BASEDIR, param_spec);
-
-
- param_spec = g_param_spec_boolean ("testmode",
- "TestMode",
- "Whether the logstore is in testmode, for testsuite use only",
- FALSE, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class, PROP_TESTMODE, param_spec);
-
+ g_object_class_override_property (object_class, PROP_WRITABLE, "writable");
g_type_class_add_private (object_class, sizeof (TplLogStorePidginPriv));
}
@@ -183,18 +174,6 @@ tpl_log_store_pidgin_init (TplLogStorePidgin *self)
self->priv->account_manager = tp_account_manager_dup ();
}
-
-static const gchar *
-log_store_pidgin_get_name (TplLogStore *store)
-{
- TplLogStorePidgin *self = (TplLogStorePidgin *) store;
-
- g_return_val_if_fail (TPL_IS_LOG_STORE_PIDGIN (self), NULL);
-
- return TPL_LOG_STORE_PIDGIN_NAME;
-}
-
-
/* returns an absolute path for the base directory of LogStore */
static const gchar *
log_store_pidgin_get_basedir (TplLogStorePidgin *self)
@@ -207,12 +186,11 @@ log_store_pidgin_get_basedir (TplLogStorePidgin *self)
{
gchar *dir;
- if (self->priv->test_mode && g_getenv ("TPL_TEST_LOG_DIR") != NULL)
- dir = g_build_path (G_DIR_SEPARATOR_S, g_getenv ("TPL_TEST_LOG_DIR"),
- "purple", NULL);
- else
- dir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".purple",
- "logs", NULL);
+ /* This is fine with tests as we depend on GLib 2.36 which is now using
+ * $HOME to find the home dir. */
+ dir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".purple",
+ "logs", NULL);
+
log_store_pidgin_set_basedir (self, dir);
g_free (dir);
@@ -1166,7 +1144,6 @@ log_store_iface_init (gpointer g_iface,
{
TplLogStoreInterface *iface = (TplLogStoreInterface *) g_iface;
- iface->get_name = log_store_pidgin_get_name;
iface->exists = log_store_pidgin_exists;
iface->add_event = NULL;
iface->get_dates = log_store_pidgin_get_dates;
@@ -1176,3 +1153,11 @@ log_store_iface_init (gpointer g_iface,
iface->get_filtered_events = log_store_pidgin_get_filtered_events;
iface->create_iter = log_store_pidgin_create_iter;
}
+
+TplLogStore *
+_tpl_log_store_pidgin_new (void)
+{
+ return g_object_new (TPL_TYPE_LOG_STORE_PIDGIN,
+ "name", TPL_LOG_STORE_PIDGIN_NAME,
+ NULL);
+}
diff --git a/telepathy-logger/log-store-sqlite.c b/telepathy-logger/log-store-sqlite.c
index 4486fe77d..53c1a760d 100644
--- a/telepathy-logger/log-store-sqlite.c
+++ b/telepathy-logger/log-store-sqlite.c
@@ -50,11 +50,16 @@ G_DEFINE_TYPE_WITH_CODE (TplLogStoreSqlite, _tpl_log_store_sqlite,
enum /* properties */
{
PROP_0,
+ PROP_NAME,
PROP_READABLE,
+ PROP_WRITABLE,
};
struct _TplLogStoreSqlitePrivate
{
+ gchar *name;
+ gchar writable;
+
sqlite3 *db;
};
@@ -101,19 +106,49 @@ tpl_log_store_sqlite_get_property (GObject *self,
GValue *value,
GParamSpec *pspec)
{
+ TplLogStoreSqlitePrivate *priv = TPL_LOG_STORE_SQLITE (self)->priv;
+
switch (id)
{
+ case PROP_NAME:
+ g_value_set_string (value, priv->name);
+ break;
case PROP_READABLE:
/* this store should never be queried by the LogManager */
g_value_set_boolean (value, FALSE);
break;
+ case PROP_WRITABLE:
+ g_value_set_boolean (value, priv->writable);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
break;
}
}
+static void
+tpl_log_store_sqlite_set_property (GObject *self,
+ guint id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TplLogStoreSqlitePrivate *priv = TPL_LOG_STORE_SQLITE (self)->priv;
+
+ switch (id)
+ {
+ case PROP_NAME:
+ priv->name = g_value_dup_string (value);
+ break;
+ case PROP_WRITABLE:
+ priv->writable = g_value_get_boolean (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
+ break;
+ }
+}
static void
purge_pending_messages (TplLogStoreSqlitePrivate *priv,
@@ -270,7 +305,7 @@ out:
static void
-tpl_log_store_sqlite_dispose (GObject *self)
+tpl_log_store_sqlite_finalize (GObject *self)
{
TplLogStoreSqlitePrivate *priv = TPL_LOG_STORE_SQLITE (self)->priv;
@@ -280,7 +315,9 @@ tpl_log_store_sqlite_dispose (GObject *self)
priv->db = NULL;
}
- G_OBJECT_CLASS (_tpl_log_store_sqlite_parent_class)->dispose (self);
+ g_free (priv->name);
+
+ G_OBJECT_CLASS (_tpl_log_store_sqlite_parent_class)->finalize (self);
}
@@ -291,9 +328,12 @@ _tpl_log_store_sqlite_class_init (TplLogStoreSqliteClass *klass)
gobject_class->constructor = tpl_log_store_sqlite_constructor;
gobject_class->get_property = tpl_log_store_sqlite_get_property;
- gobject_class->dispose = tpl_log_store_sqlite_dispose;
+ gobject_class->set_property = tpl_log_store_sqlite_set_property;
+ gobject_class->finalize = tpl_log_store_sqlite_finalize;
+ 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));
}
@@ -353,14 +393,6 @@ get_datetime (gint64 timestamp)
return date;
}
-
-static const char *
-tpl_log_store_sqlite_get_name (TplLogStore *self)
-{
- return TPL_LOG_STORE_SQLITE_NAME;
-}
-
-
static gboolean
tpl_log_store_sqlite_add_message_counter (TplLogStore *self,
TplEvent *message,
@@ -617,7 +649,6 @@ out:
static void
log_store_iface_init (TplLogStoreInterface *iface)
{
- iface->get_name = tpl_log_store_sqlite_get_name;
iface->add_event = tpl_log_store_sqlite_add_event;
iface->get_entities = tpl_log_store_sqlite_get_entities;
}
@@ -625,7 +656,10 @@ log_store_iface_init (TplLogStoreInterface *iface)
TplLogStore *
_tpl_log_store_sqlite_dup (void)
{
- return g_object_new (TPL_TYPE_LOG_STORE_SQLITE, NULL);
+ return g_object_new (TPL_TYPE_LOG_STORE_SQLITE,
+ "name", TPL_LOG_STORE_SQLITE_NAME,
+ "writable", TRUE,
+ NULL);
}
diff --git a/telepathy-logger/log-store-xml-internal.h b/telepathy-logger/log-store-xml-internal.h
index 4351936d0..04eb47d14 100644
--- a/telepathy-logger/log-store-xml-internal.h
+++ b/telepathy-logger/log-store-xml-internal.h
@@ -26,6 +26,8 @@
#include <glib.h>
#include <glib-object.h>
+#include "telepathy-logger/log-store-internal.h"
+
G_BEGIN_DECLS
#define TPL_TYPE_LOG_STORE_XML \
(_tpl_log_store_xml_get_type ())
@@ -58,5 +60,9 @@ typedef struct
GType _tpl_log_store_xml_get_type (void);
+TplLogStore * _tpl_log_store_xml_new (void);
+TplLogStore * _tpl_log_store_empathy_new (void);
+TplLogStore * _tpl_log_store_xml_legacy_new (void);
+
G_END_DECLS
#endif /* __TPL_LOG_STORE_XML_H__ */
diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c
index ee52cdc63..828e0d592 100644
--- a/telepathy-logger/log-store-xml.c
+++ b/telepathy-logger/log-store-xml.c
@@ -79,16 +79,17 @@
struct _TplLogStoreXmlPriv
{
+ gchar *name;
+ gboolean writable;
gchar *basedir;
- gboolean test_mode;
TpAccountManager *account_manager;
};
enum {
PROP_0,
+ PROP_NAME,
PROP_READABLE,
- PROP_BASEDIR,
- PROP_TESTMODE
+ PROP_WRITABLE,
};
static void log_store_iface_init (gpointer g_iface, gpointer iface_data);
@@ -134,6 +135,8 @@ log_store_xml_finalize (GObject *object)
TplLogStoreXml *self = TPL_LOG_STORE_XML (object);
TplLogStoreXmlPriv *priv = self->priv;
+ g_free (self->priv->name);
+
if (priv->basedir != NULL)
{
g_free (priv->basedir);
@@ -148,18 +151,18 @@ tpl_log_store_xml_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- TplLogStoreXmlPriv *priv = TPL_LOG_STORE_XML (object)->priv;
+ TplLogStoreXml *self = TPL_LOG_STORE_XML (object);
switch (param_id)
{
+ case PROP_NAME:
+ g_value_set_string (value, self->priv->name);
+ break;
case PROP_READABLE:
g_value_set_boolean (value, TRUE);
break;
- case PROP_BASEDIR:
- g_value_set_string (value, priv->basedir);
- break;
- case PROP_TESTMODE:
- g_value_set_boolean (value, priv->test_mode);
+ case PROP_WRITABLE:
+ g_value_set_boolean (value, self->priv->writable);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -178,11 +181,11 @@ tpl_log_store_xml_set_property (GObject *object,
switch (param_id)
{
- case PROP_BASEDIR:
- log_store_xml_set_basedir (self, g_value_get_string (value));
+ case PROP_NAME:
+ self->priv->name = g_value_dup_string (value);
break;
- case PROP_TESTMODE:
- self->priv->test_mode = g_value_get_boolean (value);
+ case PROP_WRITABLE:
+ self->priv->writable = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -195,32 +198,15 @@ static void
_tpl_log_store_xml_class_init (TplLogStoreXmlClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GParamSpec *param_spec;
object_class->finalize = log_store_xml_finalize;
object_class->dispose = log_store_xml_dispose;
object_class->get_property = tpl_log_store_xml_get_property;
object_class->set_property = tpl_log_store_xml_set_property;
+ g_object_class_override_property (object_class, PROP_NAME, "name");
g_object_class_override_property (object_class, PROP_READABLE, "readable");
-
- /**
- * TplLogStoreXml:basedir:
- *
- * The log store's basedir.
- */
- param_spec = g_param_spec_string ("basedir",
- "Basedir",
- "The TplLogStore implementation's name",
- NULL, G_PARAM_READABLE | G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class, PROP_BASEDIR, param_spec);
-
- param_spec = g_param_spec_boolean ("testmode",
- "TestMode",
- "Whether the logstore is in testmode, for testsuite use only",
- FALSE, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class, PROP_TESTMODE, param_spec);
+ g_object_class_override_property (object_class, PROP_WRITABLE, "writable");
g_type_class_add_private (object_class, sizeof (TplLogStoreXmlPriv));
}
@@ -673,6 +659,7 @@ log_store_xml_add_event (TplLogStore *store,
GError **error)
{
TplLogStoreXml *self = TPL_LOG_STORE_XML (store);
+ gchar *name;
g_return_val_if_fail (TPL_IS_EVENT (event), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -682,10 +669,13 @@ log_store_xml_add_event (TplLogStore *store,
else if (TPL_IS_CALL_EVENT (event))
return add_call_event (self, TPL_CALL_EVENT (event), error);
+ name = _tpl_log_store_dup_name (store);
+
DEBUG ("TplEntry not handled by this LogStore (%s). "
- "Ignoring Event", _tpl_log_store_get_name (store));
+ "Ignoring Event", name);
/* do not consider it an error, this LogStore simply do not want/need
* this Event */
+ g_free (name);
return TRUE;
}
@@ -1736,18 +1726,6 @@ log_store_xml_get_entities (TplLogStore *store,
return entities;
}
-
-static const gchar *
-log_store_xml_get_name (TplLogStore *store)
-{
- TplLogStoreXml *self = (TplLogStoreXml *) store;
-
- g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL);
-
- return "TpLogger";
-}
-
-
/* returns am absolute path for the base directory of LogStore */
static const gchar *
log_store_xml_get_basedir (TplLogStoreXml *self)
@@ -1759,22 +1737,13 @@ log_store_xml_get_basedir (TplLogStoreXml *self)
if (self->priv->basedir == NULL)
{
gchar *dir;
- const char *user_data_dir;
- const char *name;
+ char *name;
- if (self->priv->test_mode && g_getenv ("TPL_TEST_LOG_DIR") != NULL)
- {
- user_data_dir = g_getenv ("TPL_TEST_LOG_DIR");
- }
- else
- {
- user_data_dir = g_get_user_data_dir ();
- }
-
- name = _tpl_log_store_get_name ((TplLogStore *) self);
- dir = g_build_path (G_DIR_SEPARATOR_S, user_data_dir, name, "logs",
- NULL);
+ name = _tpl_log_store_dup_name ((TplLogStore *) self);
+ dir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), name,
+ "logs", NULL);
log_store_xml_set_basedir (self, dir);
+ g_free (name);
g_free (dir);
}
@@ -1931,7 +1900,6 @@ log_store_iface_init (gpointer g_iface,
{
TplLogStoreInterface *iface = (TplLogStoreInterface *) g_iface;
- iface->get_name = log_store_xml_get_name;
iface->exists = log_store_xml_exists;
iface->add_event = log_store_xml_add_event;
iface->get_dates = log_store_xml_get_dates;
@@ -1944,3 +1912,29 @@ log_store_iface_init (gpointer g_iface,
iface->clear_entity = log_store_xml_clear_entity;
iface->create_iter = log_store_xml_create_iter;
}
+
+TplLogStore *
+_tpl_log_store_xml_new (void)
+{
+ return g_object_new (TPL_TYPE_LOG_STORE_XML,
+ "name", "telepathy-1",
+ NULL);
+}
+
+TplLogStore *
+_tpl_log_store_empathy_new (void)
+{
+ return g_object_new (TPL_TYPE_LOG_STORE_XML,
+ "name", "Empathy",
+ "writable", FALSE,
+ NULL);
+}
+
+TplLogStore *
+_tpl_log_store_xml_legacy_new (void)
+{
+ return g_object_new (TPL_TYPE_LOG_STORE_XML,
+ "name", "TpLogger",
+ "writable", FALSE,
+ NULL);
+}
diff --git a/telepathy-logger/log-store.c b/telepathy-logger/log-store.c
index 6e1d10f19..9239bc4cc 100644
--- a/telepathy-logger/log-store.c
+++ b/telepathy-logger/log-store.c
@@ -37,6 +37,11 @@
* implement in order to be used into a #TplLogManager.
*/
+enum
+{
+ PROP_NAME = 1
+};
+
static void _tpl_log_store_init (gpointer g_iface);
GType
@@ -66,6 +71,14 @@ _tpl_log_store_get_type (void)
static void
_tpl_log_store_init (gpointer g_iface)
{
+ g_object_interface_install_property (g_iface,
+ g_param_spec_string ("name",
+ "Name",
+ "The name of the log store",
+ NULL,
+ G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
/**
* TplLogStore:readable:
*
@@ -82,16 +95,35 @@ _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_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
}
-const gchar *
-_tpl_log_store_get_name (TplLogStore *self)
+gchar *
+_tpl_log_store_dup_name (TplLogStore *self)
{
+ gchar *name;
+
g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL);
- if (!TPL_LOG_STORE_GET_INTERFACE (self)->get_name)
- return NULL;
- return TPL_LOG_STORE_GET_INTERFACE (self)->get_name (self);
+ g_object_get (self, "name", &name, NULL);
+
+ return name;
}
@@ -356,11 +388,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)