[evolution-kolab/ek-wip-porting] CamelKolabIMAPXServer: add initialization for metadata (DB)
- From: Christian Hilberg <chilberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-kolab/ek-wip-porting] CamelKolabIMAPXServer: add initialization for metadata (DB)
- Date: Fri, 9 Mar 2012 17:16:42 +0000 (UTC)
commit a6ddb58d6666737b833e9b50d62aba71cf6493b5
Author: Christian Hilberg <hilberg kernelconcepts de>
Date: Fri Mar 9 18:07:08 2012 +0100
CamelKolabIMAPXServer: add initialization for metadata (DB)
* added initialization of the metadata subsystem
(data structures and SQLiteDB)
* in contrast to its parent class, this one's init
can now fail (I/O), thus we need to propagate
an error here
src/camel/camel-kolab-imapx-server.c | 102 +++++++++++++++++++++++++++++++++-
src/camel/camel-kolab-imapx-server.h | 3 +-
2 files changed, 103 insertions(+), 2 deletions(-)
---
diff --git a/src/camel/camel-kolab-imapx-server.c b/src/camel/camel-kolab-imapx-server.c
index fb75c41..b6c107e 100644
--- a/src/camel/camel-kolab-imapx-server.c
+++ b/src/camel/camel-kolab-imapx-server.c
@@ -31,6 +31,8 @@
#include <string.h>
+#include <libekolabutil/kolab-util-error.h>
+
#include "camel-kolab-imapx-store.h"
#include "camel-kolab-imapx-server.h"
@@ -47,6 +49,11 @@ struct _CamelKolabIMAPXServerPrivate {
G_DEFINE_TYPE (CamelKolabIMAPXServer, camel_kolab_imapx_server, CAMEL_TYPE_IMAPX_EXTD_SERVER)
/*----------------------------------------------------------------------------*/
+/* forward declarations */
+
+static gboolean imapx_server_shutdown (CamelKolabIMAPXServer *self, GError **err);
+
+/*----------------------------------------------------------------------------*/
/* object init */
static void
@@ -83,18 +90,100 @@ camel_kolab_imapx_server_finalize (GObject *object)
{
CamelKolabIMAPXServer *self = NULL;
CamelKolabIMAPXServerPrivate *priv = NULL;
+ GError *tmp_err = NULL;
+ gboolean ok = FALSE;
g_assert (CAMEL_IS_KOLAB_IMAPX_SERVER (object));
self = CAMEL_KOLAB_IMAPX_SERVER (object);
priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
+ ok = imapx_server_shutdown (self, &tmp_err);
+ if (! ok) {
+ /* TODO
+ * Uninitialization, which can fail,
+ * should be done in a place where we can
+ * propagate an error - just, GInitable does
+ * not provide for uninitialization either...
+ */
+ g_warning ("%s: %s",
+ __func__, tmp_err->message);
+ g_error_free (tmp_err);
+ }
camel_kolab_imapx_metadata_free (priv->kmd);
G_OBJECT_CLASS (camel_kolab_imapx_server_parent_class)->finalize (object);
}
/*----------------------------------------------------------------------------*/
+/* local statics */
+
+static gboolean
+imapx_server_bringup (CamelKolabIMAPXServer *self,
+ CamelService *service,
+ GError **err)
+{
+ CamelKolabIMAPXServerPrivate *priv = NULL;
+ const gchar *cachepath = NULL;
+ GError *tmp_err = NULL;
+ gboolean ok = FALSE;
+
+ g_assert (CAMEL_IS_KOLAB_IMAPX_SERVER (self));
+ g_assert (CAMEL_IS_SERVICE (service));
+ g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+ priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
+
+ cachepath = camel_service_get_user_cache_dir (service);
+ if (cachepath == NULL) {
+ /* FIXME mark this as a translatable string */
+ g_set_error (err,
+ KOLAB_CAMEL_ERROR,
+ KOLAB_CAMEL_ERROR_GENERIC,
+ "Could not get user cache directory from Camel service");
+ return FALSE;
+ }
+
+ ok = camel_kolab_imapx_metadata_init (priv->kmd,
+ cachepath,
+ &tmp_err);
+ if (! ok) {
+ g_warning ("%s: %s",
+ __func__, tmp_err->message);
+ g_propagate_error (err, tmp_err);
+ return FALSE;
+ }
+
+ g_debug ("%s: metadata database initialized", __func__);
+
+ return TRUE;
+}
+
+static gboolean
+imapx_server_shutdown (CamelKolabIMAPXServer *self,
+ GError **err)
+{
+ CamelKolabIMAPXServerPrivate *priv = NULL;
+ GError *tmp_err = NULL;
+ gboolean ok = FALSE;
+
+ g_assert (CAMEL_IS_KOLAB_IMAPX_SERVER (self));
+ g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+ priv = CAMEL_KOLAB_IMAPX_SERVER_PRIVATE (self);
+
+ ok = camel_kolab_imapx_metadata_shutdown (priv->kmd,
+ &tmp_err);
+ if (! ok) {
+ g_propagate_error (err, tmp_err);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/*----------------------------------------------------------------------------*/
/* class functions */
static KolabFolderTypeID
@@ -324,19 +413,30 @@ camel_kolab_imapx_server_class_init (CamelKolabIMAPXServerClass *klass)
/* API functions */
CamelKolabIMAPXServer*
-camel_kolab_imapx_server_new (CamelKolabIMAPXStore *store)
+camel_kolab_imapx_server_new (CamelKolabIMAPXStore *store,
+ GError **err)
{
CamelKolabIMAPXServer *self = NULL;
CamelIMAPXServer *is = NULL;
CamelService *service = NULL;
CamelSession *session = NULL;
+ GError *tmp_err = NULL;
+ gboolean ok = FALSE;
g_assert (CAMEL_IS_KOLAB_IMAPX_STORE (store));
+ g_return_val_if_fail (err == NULL || *err == NULL, NULL);
service = CAMEL_SERVICE (store);
session = camel_service_get_session (service);
self = g_object_new (CAMEL_TYPE_KOLAB_IMAPX_SERVER, NULL);
+ ok = imapx_server_bringup (self, service, &tmp_err);
+ if (! ok) {
+ g_object_unref (self);
+ g_propagate_error (err, tmp_err);
+ return NULL;
+ }
+
is = CAMEL_IMAPX_SERVER (self);
is->session = g_object_ref (session);
diff --git a/src/camel/camel-kolab-imapx-server.h b/src/camel/camel-kolab-imapx-server.h
index f69d77b..fc208bb 100644
--- a/src/camel/camel-kolab-imapx-server.h
+++ b/src/camel/camel-kolab-imapx-server.h
@@ -92,7 +92,8 @@ GType
camel_kolab_imapx_server_get_type (void);
CamelKolabIMAPXServer*
-camel_kolab_imapx_server_new (struct _CamelKolabIMAPXStore *store);
+camel_kolab_imapx_server_new (struct _CamelKolabIMAPXStore *store,
+ GError **err);
KolabFolderTypeID
camel_kolab_imapx_server_get_foldertype (CamelKolabIMAPXServer *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]