[couchdb-glib: 4/21] WARNING: Highly work-in-progress - DOESN'T COMPILE (not even close). This is just an intermediate co
- From: Mikkel Kamstrup Erlandsen <kamstrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [couchdb-glib: 4/21] WARNING: Highly work-in-progress - DOESN'T COMPILE (not even close). This is just an intermediate co
- Date: Wed, 7 Oct 2009 18:55:58 +0000 (UTC)
commit e9652061c35cd2a25d15df17013228a2d943a2bd
Author: Mikkel Kamstrup Erlandsen <mikkel kamstrup gmail com>
Date: Sat Oct 3 16:16:17 2009 +0200
WARNING: Highly work-in-progress - DOESN'T COMPILE (not even close). This is just an intermediate commit in order to back my work up on LP
couchdb-glib/Makefile.am | 1 +
couchdb-glib/couchdb-database-info.c | 126 ++++++
couchdb-glib/couchdb-database-info.h | 51 +++
couchdb-glib/couchdb-document-info.c | 82 ++++
couchdb-glib/couchdb-document-info.h | 19 +
couchdb-glib/couchdb-document.c | 8 +
couchdb-glib/couchdb-document.h | 133 ++++++
couchdb-glib/couchdb-glib.h | 111 +-----
couchdb-glib/couchdb-struct-field.c | 258 +++++++++++
.../{couchdb-types.h => couchdb-struct-field.h} | 47 +--
couchdb-glib/couchdb-types.c | 466 --------------------
couchdb-glib/couchdb.c | 20 +
couchdb-glib/couchdb.h | 78 ++++
couchdb-glib/utils.h | 74 +---
14 files changed, 795 insertions(+), 679 deletions(-)
---
diff --git a/couchdb-glib/Makefile.am b/couchdb-glib/Makefile.am
index c017653..0105777 100644
--- a/couchdb-glib/Makefile.am
+++ b/couchdb-glib/Makefile.am
@@ -26,6 +26,7 @@ libcouchdb_glib_1_0_la_SOURCES = \
$(MARSHAL_GENERATED) \
couchdb.c \
couchdb-document.c \
+ couchdb-document.h \
couchdb-document-contact.c \
couchdb-types.c \
dbwatch.c \
diff --git a/couchdb-glib/couchdb-database-info.c b/couchdb-glib/couchdb-database-info.c
new file mode 100644
index 0000000..f9c4be0
--- /dev/null
+++ b/couchdb-glib/couchdb-database-info.c
@@ -0,0 +1,126 @@
+struct _CouchDBDatabaseInfo {
+ gint ref_count;
+
+ char *dbname;
+ gint doc_count;
+ gint doc_del_count;
+ gint update_seq;
+ gboolean compact_running;
+ gint disk_size;
+};
+
+/*
+ * CouchDBDatabaseInfo object
+ */
+
+GType
+couchdb_database_info_get_type (void)
+{
+ static GType object_type = 0;
+
+ if (G_UNLIKELY (!object_type))
+ object_type = g_boxed_type_register_static (g_intern_static_string ("CouchDBDatabaseInfo"),
+ (GBoxedCopyFunc) couchdb_database_info_ref,
+ (GBoxedFreeFunc) couchdb_database_info_unref);
+
+ return object_type;
+}
+
+CouchDBDatabaseInfo *
+couchdb_database_info_new (const char *dbname,
+ gint doc_count,
+ gint doc_del_count,
+ gint update_seq,
+ gboolean compact_running,
+ gint disk_size)
+{
+ CouchDBDatabaseInfo *dbinfo;
+
+ dbinfo = g_slice_new (CouchDBDatabaseInfo);
+ dbinfo->ref_count = 1;
+ dbinfo->dbname = g_strdup (dbname);
+ dbinfo->doc_count = doc_count;
+ dbinfo->doc_del_count = doc_del_count;
+ dbinfo->update_seq = update_seq;
+ dbinfo->compact_running = compact_running;
+ dbinfo->disk_size = disk_size;
+
+ return dbinfo;
+}
+
+CouchDBDatabaseInfo *
+couchdb_database_info_ref (CouchDBDatabaseInfo *dbinfo)
+{
+ g_return_val_if_fail (dbinfo != NULL, NULL);
+ g_return_val_if_fail (dbinfo->ref_count > 0, NULL);
+
+ g_atomic_int_exchange_and_add (&dbinfo->ref_count, 1);
+
+ return dbinfo;
+}
+
+void
+couchdb_database_info_unref (CouchDBDatabaseInfo *dbinfo)
+{
+ gint old_ref;
+
+ g_return_if_fail (dbinfo != NULL);
+ g_return_if_fail (dbinfo->ref_count > 0);
+
+ old_ref = g_atomic_int_get (&dbinfo->ref_count);
+ if (old_ref > 1)
+ g_atomic_int_compare_and_exchange (&dbinfo->ref_count, old_ref, old_ref - 1);
+ else {
+ g_free (dbinfo->dbname);
+ g_slice_free (CouchDBDatabaseInfo, dbinfo);
+ }
+}
+
+const char *
+couchdb_database_info_get_dbname (CouchDBDatabaseInfo *dbinfo)
+{
+ g_return_val_if_fail (dbinfo != NULL, NULL);
+
+ return (const char *) dbinfo->dbname;
+}
+
+gint
+couchdb_database_info_get_documents_count (CouchDBDatabaseInfo *dbinfo)
+{
+ g_return_val_if_fail (dbinfo != NULL, 0);
+
+ return dbinfo->doc_count;
+}
+
+gint
+couchdb_database_info_get_deleted_documents_count (CouchDBDatabaseInfo *dbinfo)
+{
+ g_return_val_if_fail (dbinfo != NULL, 0);
+
+ return dbinfo->doc_del_count;
+}
+
+gint
+couchdb_database_info_get_update_sequence (CouchDBDatabaseInfo *dbinfo)
+{
+ g_return_val_if_fail (dbinfo != NULL, 0);
+
+ return dbinfo->update_seq;
+}
+
+gboolean
+couchdb_database_info_is_compact_running (CouchDBDatabaseInfo *dbinfo)
+{
+ g_return_val_if_fail (dbinfo != NULL, FALSE);
+
+ return dbinfo->compact_running;
+}
+
+gint
+couchdb_database_info_get_disk_size (CouchDBDatabaseInfo *dbinfo)
+{
+ g_return_val_if_fail (dbinfo != NULL, 0);
+
+ return dbinfo->disk_size;
+}
+
diff --git a/couchdb-glib/couchdb-database-info.h b/couchdb-glib/couchdb-database-info.h
new file mode 100644
index 0000000..6f6797c
--- /dev/null
+++ b/couchdb-glib/couchdb-database-info.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com)
+ * 2009 Mikkel Kamstrup Erlandsen
+ *
+ * Authors: Rodrigo Moya <rodrigo moya canonical com>
+ * Mikkel Kamstrup Erlandsen <mikkel kamstrup gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program 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
+ * 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 Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <glib-object.h>
+
+#define COUCHDB_TYPE_DATABASE_INFO (couchdb_database_info_get_type ())
+
+
+/*
+ * CouchDBDatabaseInfo
+ */
+typedef struct _CouchDBDatabaseInfo CouchDBDatabaseInfo;
+
+GType couchdb_database_info_get_type (void);
+CouchDBDatabaseInfo *couchdb_database_info_ref (CouchDBDatabaseInfo *dbinfo);
+void couchdb_database_info_unref (CouchDBDatabaseInfo *dbinfo);
+
+const char *couchdb_database_info_get_dbname (CouchDBDatabaseInfo *dbinfo);
+gint couchdb_database_info_get_documents_count (CouchDBDatabaseInfo *dbinfo);
+gint couchdb_database_info_get_deleted_documents_count (CouchDBDatabaseInfo *dbinfo);
+gint couchdb_database_info_get_update_sequence (CouchDBDatabaseInfo *dbinfo);
+gboolean couchdb_database_info_is_compact_running (CouchDBDatabaseInfo *dbinfo);
+gint couchdb_database_info_get_disk_size (CouchDBDatabaseInfo *dbinfo);
+
+CouchDBDatabaseInfo* couchdb_database_info_new (const char *dbname,
+ gint doc_count,
+ gint doc_del_count,
+ gint update_seq,
+ gboolean compact_running,
+ gint disk_size);
+
diff --git a/couchdb-glib/couchdb-document-info.c b/couchdb-glib/couchdb-document-info.c
new file mode 100644
index 0000000..121c72c
--- /dev/null
+++ b/couchdb-glib/couchdb-document-info.c
@@ -0,0 +1,82 @@
+struct _CouchDBDocumentInfo {
+ gint ref_count;
+
+ char *docid;
+ char *revision;
+};
+
+/*
+ * CouchDBDocumentInfo object
+ */
+
+GType
+couchdb_document_info_get_type (void)
+{
+ static GType object_type = 0;
+
+ if (G_UNLIKELY (!object_type))
+ object_type = g_boxed_type_register_static (g_intern_static_string ("CouchDBDocumentInfo"),
+ (GBoxedCopyFunc) couchdb_document_info_ref,
+ (GBoxedFreeFunc) couchdb_document_info_unref);
+
+ return object_type;
+}
+
+CouchDBDocumentInfo *
+couchdb_document_info_new (const char *docid, const char *revision)
+{
+ CouchDBDocumentInfo *doc_info;
+
+ doc_info = g_slice_new (CouchDBDocumentInfo);
+ doc_info->ref_count = 1;
+ doc_info->docid = g_strdup (docid);
+ doc_info->revision = g_strdup (revision);
+
+ return doc_info;
+}
+
+CouchDBDocumentInfo *
+couchdb_document_info_ref (CouchDBDocumentInfo *doc_info)
+{
+ g_return_val_if_fail (doc_info != NULL, NULL);
+ g_return_val_if_fail (doc_info->ref_count > 0, NULL);
+
+ g_atomic_int_exchange_and_add (&doc_info->ref_count, 1);
+
+ return doc_info;
+}
+
+void
+couchdb_document_info_unref (CouchDBDocumentInfo *doc_info)
+{
+ gint old_ref;
+
+ g_return_if_fail (doc_info != NULL);
+ g_return_if_fail (doc_info->ref_count > 0);
+
+ old_ref = g_atomic_int_get (&doc_info->ref_count);
+ if (old_ref > 1)
+ g_atomic_int_compare_and_exchange (&doc_info->ref_count, old_ref, old_ref - 1);
+ else {
+ g_free (doc_info->docid);
+ g_free (doc_info->revision);
+ g_slice_free (CouchDBDocumentInfo, doc_info);
+ }
+}
+
+const char *
+couchdb_document_info_get_docid (CouchDBDocumentInfo *doc_info)
+{
+ g_return_val_if_fail (doc_info != NULL, NULL);
+
+ return (const char *) doc_info->docid;
+}
+
+const char *
+couchdb_document_info_get_revision (CouchDBDocumentInfo *doc_info)
+{
+ g_return_val_if_fail (doc_info != NULL, NULL);
+
+ return (const char *) doc_info->revision;
+}
+
diff --git a/couchdb-glib/couchdb-document-info.h b/couchdb-glib/couchdb-document-info.h
new file mode 100644
index 0000000..42e48a3
--- /dev/null
+++ b/couchdb-glib/couchdb-document-info.h
@@ -0,0 +1,19 @@
+#define COUCHDB_TYPE_DOCUMENT_INFO (couchdb_document_info_get_type ())
+
+
+typedef struct _CouchDBDatabaseInfo CouchDBDatabaseInfo;
+
+GType couchdb_database_info_get_type (void);
+CouchDBDocumentInfo *couchdb_document_info_new (const char *docid, const char *revision);
+CouchDBDatabaseInfo *couchdb_database_info_ref (CouchDBDatabaseInfo *dbinfo);
+void couchdb_database_info_unref (CouchDBDatabaseInfo *dbinfo);
+
+const char *couchdb_database_info_get_dbname (CouchDBDatabaseInfo *dbinfo);
+const char *couchdb_document_info_get_docid (CouchDBDocumentInfo *doc_info);
+const char *couchdb_document_info_get_revision (CouchDBDocumentInfo *doc_info);
+gint couchdb_database_info_get_documents_count (CouchDBDatabaseInfo *dbinfo);
+gint couchdb_database_info_get_deleted_documents_count (CouchDBDatabaseInfo *dbinfo);
+gint couchdb_database_info_get_update_sequence (CouchDBDatabaseInfo *dbinfo);
+gboolean couchdb_database_info_is_compact_running (CouchDBDatabaseInfo *dbinfo);
+gint couchdb_database_info_get_disk_size (CouchDBDatabaseInfo *dbinfo);
+
diff --git a/couchdb-glib/couchdb-document.c b/couchdb-glib/couchdb-document.c
index 064e1a5..cbaee93 100644
--- a/couchdb-glib/couchdb-document.c
+++ b/couchdb-glib/couchdb-document.c
@@ -28,6 +28,14 @@
G_DEFINE_TYPE(CouchDBDocument, couchdb_document, G_TYPE_OBJECT);
+struct _CouchDBDocument {
+ GObject parent;
+
+ CouchDB *couchdb;
+ char *dbname;
+ JsonNode *root_node;
+};
+
static void
couchdb_document_finalize (GObject *object)
{
diff --git a/couchdb-glib/couchdb-document.h b/couchdb-glib/couchdb-document.h
new file mode 100644
index 0000000..7a15064
--- /dev/null
+++ b/couchdb-glib/couchdb-document.h
@@ -0,0 +1,133 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com)
+ * 2009 Mikkel Kamstrup Erlandsen
+ *
+ * Authors: Rodrigo Moya <rodrigo moya canonical com>
+ * Mikkel Kamstrup Erlandsen <mikkel kamstrup gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program 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
+ * 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 Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __COUCHDB_GLIB_DOCUMENT_H__
+#define __COUCHDB_GLIB_DOCUMENT_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include "couchdb.h"
+#include "couchdb-types.h"
+
+G_BEGIN_DECLS
+
+
+#define COUCHDB_TYPE_DOCUMENT (couchdb_document_get_type ())
+#define COUCHDB_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COUCHDB_TYPE_DOCUMENT, CouchDBDocument))
+#define COUCHDB_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COUCHDB_TYPE_DOCUMENT))
+#define COUCHDB_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COUCHDB_TYPE_DOCUMENT, CouchDBDocumentClass))
+#define COUCHDB_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COUCHDB_TYPE_DOCUMENT))
+#define COUCHDB_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COUCHDB_TYPE_DOCUMENT, CouchDBDocumentClass))
+
+typedef struct _CouchDBDocument CouchDBDocument
+typedef struct _CouchDBDocumentClass CouchDBDocumentClass
+
+typedef struct {
+ GObjectClass parent_class;
+} CouchDBDocumentClass;
+
+
+GType couchdb_document_get_type (void);
+
+CouchDBDocument *couchdb_document_new (CouchDB *couchdb);
+
+CouchDBDocument *couchdb_document_get (CouchDB *couchdb,
+ const char *dbname,
+ const char *docid,
+ GError **error);
+
+gboolean couchdb_document_put (CouchDBDocument *document,
+ const char *dbname,
+ GError **error);
+
+gboolean couchdb_document_delete (CouchDBDocument *document,
+ GError **error);
+
+const char *couchdb_document_get_id (CouchDBDocument *document);
+
+void couchdb_document_set_id (CouchDBDocument *document,
+ const char *id);
+
+const char *couchdb_document_get_revision (CouchDBDocument *document);
+void couchdb_document_set_revision (CouchDBDocument *document,
+ const char *revision);
+
+const char *couchdb_document_get_record_type (CouchDBDocument *document);
+
+void couchdb_document_set_record_type (CouchDBDocument *document,
+
+ const char *record_type);
+
+gboolean couchdb_document_has_field (CouchDBDocument *document,
+ const char *field);
+
+void couchdb_document_remove_field (CouchDBDocument *document,
+ const char *field);
+
+gboolean couchdb_document_get_boolean_field (CouchDBDocument *document,
+ const char *field);
+
+void couchdb_document_set_boolean_field (CouchDBDocument *document,
+ const char *field,
+ gboolean value);
+
+gint couchdb_document_get_int_field (CouchDBDocument *document,
+ const char *field);
+
+void couchdb_document_set_int_field (CouchDBDocument *document,
+ const char *field,
+ gint value);
+
+gdouble couchdb_document_get_double_field (CouchDBDocument *document,
+ const char *field);
+
+void couchdb_document_set_double_field (CouchDBDocument *document,
+ const char *field,
+ gdouble value);
+
+const char *couchdb_document_get_string_field (CouchDBDocument *document,
+ const char *field);
+
+void couchdb_document_set_string_field (CouchDBDocument *document,
+ const char *field,
+ const char *value);
+
+CouchDBStructField*
+ couchdb_document_get_struct_field (CouchDBDocument *document,
+ const char *field);
+
+void couchdb_document_set_struct_field (CouchDBDocument *document,
+ const char *field,
+ CouchDBStructField *value);
+
+CouchDBStructField*
+ couchdb_document_get_application_annotations
+ (CouchDBDocument *document);
+
+void couchdb_document_set_application_annotations
+ (CouchDBDocument *document,
+ CouchDBStructField *annotations);
+
+char* couchdb_document_to_string (CouchDBDocument *document);
+
+#endif /* __COUCHDB_GLIB_DOCUMENT_H__ */
diff --git a/couchdb-glib/couchdb-glib.h b/couchdb-glib/couchdb-glib.h
index 5d1ad06..016ebf4 100644
--- a/couchdb-glib/couchdb-glib.h
+++ b/couchdb-glib/couchdb-glib.h
@@ -1,8 +1,10 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2009 Canonical Services Ltd (www.canonical.com)
+ * 2009 Mikkel Kamstrup Erlandsen
*
* Authors: Rodrigo Moya <rodrigo moya canonical com>
+ * Mikkel Kamstrup Erlandsen <mikkel kamstrup gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU Lesser General Public
@@ -18,115 +20,10 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-
+
#ifndef __COUCHDB_GLIB_H__
#define __COUCHDB_GLIB_H__
-#include <couchdb-types.h>
-
-#define COUCHDB_TYPE (couchdb_get_type ())
-#define COUCHDB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COUCHDB_TYPE, CouchDB))
-#define COUCHDB_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COUCHDB_TYPE))
-#define COUCHDB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COUCHDB_TYPE, CouchDBClass))
-#define COUCHDB_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COUCHDB_TYPE))
-#define COUCHDB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COUCHDB_TYPE, CouchDBClass))
-
-typedef struct _CouchDBDocument CouchDBDocument;
-
-typedef struct _CouchDB CouchDB;
-typedef struct {
- GObjectClass parent_class;
-
- void (* database_created) (CouchDB *couchdb, const char *dbname);
- void (* database_deleted) (CouchDB *couchdb, const char *dbname);
-
- void (* document_created) (CouchDB *couchdb, const char *dbname, CouchDBDocument *document);
- void (* document_updated) (CouchDB *couchdb, const char *dbname, CouchDBDocument *document);
- void (* document_deleted) (CouchDB *couchdb, const char *dbname, const char *docid);
-} CouchDBClass;
-
-GType couchdb_get_type (void);
-CouchDB *couchdb_new (const char *hostname);
-
-const char *couchdb_get_hostname (CouchDB *couchdb);
-
-/*
- * Databases API
- */
-
-GSList *couchdb_list_databases (CouchDB *couchdb, GError **error);
-void couchdb_free_database_list (GSList *dblist);
-
-CouchDBDatabaseInfo *couchdb_get_database_info (CouchDB *couchdb, const char *dbname, GError **error);
-
-gboolean couchdb_create_database (CouchDB *couchdb, const char *dbname, GError **error);
-gboolean couchdb_delete_database (CouchDB *couchdb, const char *dbname, GError **error);
-
-void couchdb_listen_for_changes (CouchDB *couchdb, const char *dbname);
-
-gboolean couchdb_enable_oauth (CouchDB *couchdb,
- const char *consumer_key,
- const char *consumer_secret,
- const char *token_key,
- const char *token_secret);
-void couchdb_disable_oauth (CouchDB *couchdb);
-
-/*
- * Documents API
- */
-
-#define COUCHDB_TYPE_DOCUMENT (couchdb_document_get_type ())
-#define COUCHDB_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COUCHDB_TYPE_DOCUMENT, CouchDBDocument))
-#define COUCHDB_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COUCHDB_TYPE_DOCUMENT))
-#define COUCHDB_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COUCHDB_TYPE_DOCUMENT, CouchDBDocumentClass))
-#define COUCHDB_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COUCHDB_TYPE_DOCUMENT))
-#define COUCHDB_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COUCHDB_TYPE_DOCUMENT, CouchDBDocumentClass))
-
-typedef struct {
- GObjectClass parent_class;
-} CouchDBDocumentClass;
-
-GSList *couchdb_list_documents (CouchDB *couchdb, const char *dbname, GError **error);
-void couchdb_free_document_list (GSList *doclist);
-
-GType couchdb_document_get_type (void);
-CouchDBDocument *couchdb_document_new (CouchDB *couchdb);
-CouchDBDocument *couchdb_document_get (CouchDB *couchdb,
- const char *dbname,
- const char *docid,
- GError **error);
-gboolean couchdb_document_put (CouchDBDocument *document,
- const char *dbname,
- GError **error);
-gboolean couchdb_document_delete (CouchDBDocument *document, GError **error);
-
-const char *couchdb_document_get_id (CouchDBDocument *document);
-void couchdb_document_set_id (CouchDBDocument *document, const char *id);
-const char *couchdb_document_get_revision (CouchDBDocument *document);
-void couchdb_document_set_revision (CouchDBDocument *document, const char *revision);
-const char *couchdb_document_get_record_type (CouchDBDocument *document);
-void couchdb_document_set_record_type (CouchDBDocument *document, const char *record_type);
-
-gboolean couchdb_document_has_field (CouchDBDocument *document, const char *field);
-void couchdb_document_remove_field (CouchDBDocument *document, const char *field);
-
-gboolean couchdb_document_get_boolean_field (CouchDBDocument *document, const char *field);
-void couchdb_document_set_boolean_field (CouchDBDocument *document, const char *field, gboolean value);
-gint couchdb_document_get_int_field (CouchDBDocument *document, const char *field);
-void couchdb_document_set_int_field (CouchDBDocument *document, const char *field, gint value);
-gdouble couchdb_document_get_double_field (CouchDBDocument *document, const char *field);
-void couchdb_document_set_double_field (CouchDBDocument *document, const char *field, gdouble value);
-const char *couchdb_document_get_string_field (CouchDBDocument *document, const char *field);
-void couchdb_document_set_string_field (CouchDBDocument *document, const char *field, const char *value);
-CouchDBStructField *couchdb_document_get_struct_field (CouchDBDocument *document, const char *field);
-void couchdb_document_set_struct_field (CouchDBDocument *document,
- const char *field,
- CouchDBStructField *value);
-
-CouchDBStructField *couchdb_document_get_application_annotations (CouchDBDocument *document);
-void couchdb_document_set_application_annotations (CouchDBDocument *document, CouchDBStructField *annotations);
-
-char *couchdb_document_to_string (CouchDBDocument *document);
+#endif /* __COUCHDB_GLIB_H__ */
-#endif
diff --git a/couchdb-glib/couchdb-struct-field.c b/couchdb-glib/couchdb-struct-field.c
new file mode 100644
index 0000000..2418129
--- /dev/null
+++ b/couchdb-glib/couchdb-struct-field.c
@@ -0,0 +1,258 @@
+struct _CouchDBStructField {
+ gint ref_count;
+ JsonObject *json_object;
+
+ /* Extra data needed for some specific StructField's */
+ char *uuid; /* the UUID of this item */
+};
+
+GType
+couchdb_struct_field_get_type (void)
+{
+ static GType object_type = 0;
+
+ if (G_UNLIKELY (!object_type))
+ object_type = g_boxed_type_register_static (g_intern_static_string ("CouchDBStructField"),
+ (GBoxedCopyFunc) couchdb_struct_field_ref,
+ (GBoxedFreeFunc) couchdb_struct_field_unref);
+
+ return object_type;
+}
+
+CouchDBStructField *
+couchdb_struct_field_new (void)
+{
+ CouchDBStructField *sf;
+
+ sf = g_slice_new (CouchDBStructField);
+ sf->ref_count = 1;
+ sf->json_object = json_object_new ();
+ sf->uuid = NULL;
+
+ return sf;
+}
+
+CouchDBStructField *
+couchdb_struct_field_new_from_string (const char *str)
+{
+ JsonParser *parser;
+ GError *error = NULL;
+ CouchDBStructField *sf = NULL;
+
+ g_return_val_if_fail (str != NULL, NULL);
+
+ parser = json_parser_new ();
+ if (json_parser_load_from_data (parser, str, strlen (str), &error)) {
+ JsonNode *node = json_parser_get_root (parser);
+
+ if (json_node_get_node_type (node) == JSON_NODE_OBJECT)
+ sf = couchdb_struct_field_new_from_json_object (json_node_get_object (node));
+ } else {
+ g_warning ("Could not parse string: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (G_OBJECT (parser));
+
+ return sf;
+}
+
+CouchDBStructField *
+couchdb_struct_field_new_from_json_object (JsonObject *json_object)
+{
+ CouchDBStructField *sf;
+
+ sf = g_slice_new (CouchDBStructField);
+ sf->ref_count = 1;
+ sf->json_object = json_object_ref (json_object);
+ sf->uuid = NULL;
+
+ return sf;
+}
+
+CouchDBStructField *
+couchdb_struct_field_ref (CouchDBStructField *sf)
+{
+ g_return_val_if_fail (sf != NULL, NULL);
+ g_return_val_if_fail (sf->ref_count > 0, NULL);
+
+ g_atomic_int_exchange_and_add (&sf->ref_count, 1);
+
+ return sf;
+}
+
+void
+couchdb_struct_field_unref (CouchDBStructField *sf)
+{
+ gint old_ref;
+
+ g_return_if_fail (sf != NULL);
+ g_return_if_fail (sf->ref_count > 0);
+
+ old_ref = g_atomic_int_get (&sf->ref_count);
+ if (old_ref > 1)
+ g_atomic_int_compare_and_exchange (&sf->ref_count, old_ref, old_ref - 1);
+ else {
+ json_object_unref (sf->json_object);
+ g_slice_free (CouchDBStructField, sf);
+ }
+}
+
+gboolean
+couchdb_struct_field_has_field (CouchDBStructField *sf, const char *field)
+{
+ g_return_val_if_fail (sf != NULL, FALSE);
+ g_return_val_if_fail (field != NULL, FALSE);
+
+ return json_object_has_member (sf->json_object, field);
+}
+
+void
+couchdb_struct_field_remove_field (CouchDBStructField *sf, const char *field)
+{
+ g_return_if_fail (sf != NULL);
+ g_return_if_fail (field != NULL);
+
+ json_object_remove_member (sf->json_object, field);
+}
+
+gboolean
+couchdb_struct_field_get_boolean_field (CouchDBStructField *sf, const char *field)
+{
+ g_return_val_if_fail (sf != NULL, 0);
+ g_return_val_if_fail (field != NULL, 0);
+
+ return json_object_get_boolean_member (sf->json_object, field);
+}
+
+void
+couchdb_struct_field_set_boolean_field (CouchDBStructField *sf, const char *field, gboolean value)
+{
+ g_return_if_fail (sf != NULL);
+ g_return_if_fail (field != NULL);
+
+ json_object_set_boolean_member (sf->json_object, field, value);
+}
+
+gdouble
+couchdb_struct_field_get_double_field (CouchDBStructField *sf, const char *field)
+{
+ g_return_val_if_fail (sf != NULL, 0);
+ g_return_val_if_fail (field != NULL, 0);
+
+ return json_object_get_double_member (sf->json_object, field);
+}
+
+void
+couchdb_struct_field_set_double_field (CouchDBStructField *sf, const char *field, gdouble value)
+{
+ g_return_if_fail (sf != NULL);
+ g_return_if_fail (field != NULL);
+
+ json_object_set_double_member (sf->json_object, field, value);
+}
+
+gint
+couchdb_struct_field_get_int_field (CouchDBStructField *sf, const char *field)
+{
+ g_return_val_if_fail (sf != NULL, 0);
+ g_return_val_if_fail (field != NULL, 0);
+
+ return json_object_get_int_member (sf->json_object, field);
+}
+
+void
+couchdb_struct_field_set_int_field (CouchDBStructField *sf, const char *field, gint value)
+{
+ g_return_if_fail (sf != NULL);
+ g_return_if_fail (field != NULL);
+
+ json_object_set_int_member (sf->json_object, field, value);
+}
+
+const char *
+couchdb_struct_field_get_string_field (CouchDBStructField *sf, const char *field)
+{
+ g_return_val_if_fail (sf != NULL, NULL);
+ g_return_val_if_fail (field != NULL, NULL);
+
+ return json_object_get_string_member (sf->json_object, field);
+}
+
+void
+couchdb_struct_field_set_string_field (CouchDBStructField *sf, const char *field, const char *value)
+{
+ g_return_if_fail (sf != NULL);
+ g_return_if_fail (field != NULL);
+
+ if (value)
+ json_object_set_string_member (sf->json_object, field, value);
+ else {
+ /* Remove the field if the value is NULL */
+ couchdb_struct_field_remove_field (sf, field);
+ }
+}
+
+CouchDBStructField *
+couchdb_struct_field_get_struct_field (CouchDBStructField *sf, const char *field)
+{
+ g_return_val_if_fail (sf != NULL, NULL);
+ g_return_val_if_fail (field != NULL, NULL);
+
+ return couchdb_struct_field_new_from_json_object (
+ json_object_get_object_member (sf->json_object, field));
+}
+
+void
+couchdb_struct_field_set_struct_field (CouchDBStructField *sf, const char *field, CouchDBStructField *value)
+{
+ g_return_if_fail (sf != NULL);
+ g_return_if_fail (field != NULL);
+ g_return_if_fail (value != NULL);
+
+ json_object_set_object_member (sf->json_object, field, json_object_ref (value->json_object));
+}
+
+const char *
+couchdb_struct_field_get_uuid (CouchDBStructField *sf)
+{
+ g_return_val_if_fail (sf != NULL, NULL);
+
+ return (const char *) sf->uuid;
+}
+
+void
+couchdb_struct_field_set_uuid (CouchDBStructField *sf, const char *uuid)
+{
+ g_return_if_fail (sf != NULL);
+
+ if (sf->uuid)
+ g_free (sf->uuid);
+
+ sf->uuid = g_strdup (uuid);
+}
+
+char *
+couchdb_struct_field_to_string (CouchDBStructField *sf)
+{
+ JsonNode *node;
+ JsonGenerator *generator;
+ gsize size;
+ char *str = NULL;
+
+ g_return_val_if_fail (sf != NULL, NULL);
+
+ node = json_node_new (JSON_NODE_OBJECT);
+ json_node_set_object (node, sf->json_object);
+
+ generator = json_generator_new ();
+ json_generator_set_root (generator, node);
+
+ str = json_generator_to_data (generator, &size);
+ g_object_unref (G_OBJECT (generator));
+
+ json_node_free (node);
+
+ return str;
+}
+
diff --git a/couchdb-glib/couchdb-types.h b/couchdb-glib/couchdb-struct-field.h
similarity index 64%
rename from couchdb-glib/couchdb-types.h
rename to couchdb-glib/couchdb-struct-field.h
index fafb9e0..70caea7 100644
--- a/couchdb-glib/couchdb-types.h
+++ b/couchdb-glib/couchdb-struct-field.h
@@ -1,8 +1,10 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2009 Canonical Services Ltd (www.canonical.com)
+ * 2009 Mikkel Kamstrup Erlandsen
*
* Authors: Rodrigo Moya <rodrigo moya canonical com>
+ * Mikkel Kamstrup Erlandsen <mikkel kamstrup gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU Lesser General Public
@@ -19,46 +21,18 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __COUCHDB_TYPES_H__
-#define __COUCHDB_TYPES_H__
+#ifndef __COUCHDB_GLIB_DOCUMENT_H__
+#define __COUCHDB_GLIB_DOCUMENT_H__
+#include <glib.h>
#include <glib-object.h>
+#include "couchdb.h"
+#include "couchdb-types.h"
-#define COUCHDB_TYPE_DATABASE_INFO (couchdb_database_info_get_type ())
-#define COUCHDB_TYPE_DOCUMENT_INFO (couchdb_document_info_get_type ())
-#define COUCHDB_TYPE_STRUCT_FIELD (couchdb_struct_field_get_type ())
-
-/*
- * CouchDBDatabaseInfo
- */
-typedef struct _CouchDBDatabaseInfo CouchDBDatabaseInfo;
-
-GType couchdb_database_info_get_type (void);
-CouchDBDatabaseInfo *couchdb_database_info_ref (CouchDBDatabaseInfo *dbinfo);
-void couchdb_database_info_unref (CouchDBDatabaseInfo *dbinfo);
-
-const char *couchdb_database_info_get_dbname (CouchDBDatabaseInfo *dbinfo);
-gint couchdb_database_info_get_documents_count (CouchDBDatabaseInfo *dbinfo);
-gint couchdb_database_info_get_deleted_documents_count (CouchDBDatabaseInfo *dbinfo);
-gint couchdb_database_info_get_update_sequence (CouchDBDatabaseInfo *dbinfo);
-gboolean couchdb_database_info_is_compact_running (CouchDBDatabaseInfo *dbinfo);
-gint couchdb_database_info_get_disk_size (CouchDBDatabaseInfo *dbinfo);
-
-/*
- * CouchDBDocumentInfo
- */
-typedef struct _CouchDBDocumentInfo CouchDBDocumentInfo;
+G_BEGIN_DECLS
-GType couchdb_document_info_get_type (void);
-CouchDBDocumentInfo *couchdb_document_info_ref (CouchDBDocumentInfo *doc_info);
-void couchdb_document_info_unref (CouchDBDocumentInfo *doc_info);
-
-const char *couchdb_document_info_get_docid (CouchDBDocumentInfo *doc_info);
-const char *couchdb_document_info_get_revision (CouchDBDocumentInfo *doc_info);
+#define COUCHDB_TYPE_STRUCT_FIELD (couchdb_struct_field_get_type ())
-/*
- * CouchDBStructField
- */
typedef struct _CouchDBStructField CouchDBStructField;
GType couchdb_struct_field_get_type (void);
@@ -86,4 +60,5 @@ void couchdb_struct_field_set_uuid (CouchDBStructField *sf, const
char *couchdb_struct_field_to_string (CouchDBStructField *sf);
-#endif
+CouchDBStructField *couchdb_struct_field_new_from_json_object (JsonObject *json_object);
+
diff --git a/couchdb-glib/couchdb.c b/couchdb-glib/couchdb.c
index 84aec50..cc59c4d 100644
--- a/couchdb-glib/couchdb.c
+++ b/couchdb-glib/couchdb.c
@@ -29,6 +29,26 @@
G_DEFINE_TYPE(CouchDB, couchdb, G_TYPE_OBJECT)
+struct _CouchDB {
+ GObject parent;
+
+ char *hostname;
+ SoupSession *http_session;
+
+ GHashTable *db_watchlist;
+
+ /* COMMENT:
+ * Our ABI now depends on OAUTH config - here be dragons! //kamstrup
+ */
+ #ifdef HAVE_OAUTH
+ gboolean oauth_enabled;
+ char *oauth_consumer_key;
+ char *oauth_consumer_secret;
+ char *oauth_token_key;
+ char *oauth_token_secret;
+ #endif
+};
+
enum {
DATABASE_CREATED,
DATABASE_DELETED,
diff --git a/couchdb-glib/couchdb.h b/couchdb-glib/couchdb.h
new file mode 100644
index 0000000..ebc3f0b
--- /dev/null
+++ b/couchdb-glib/couchdb.h
@@ -0,0 +1,78 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com)
+ * 2009 Mikkel Kamstrup Erlandsen
+ *
+ * Authors: Rodrigo Moya <rodrigo moya canonical com>
+ * Mikkel Kamstrup Erlandsen <mikkel kamstrup gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program 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
+ * 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 Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __COUCHDB_H__
+#define __COUCHDB_H__
+
+#include <couchdb-types.h>
+#include <couchdb-document.h>
+
+G_BEGIN_DECLS
+
+#define COUCHDB_TYPE (couchdb_get_type ())
+#define COUCHDB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COUCHDB_TYPE, CouchDB))
+#define COUCHDB_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COUCHDB_TYPE))
+#define COUCHDB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COUCHDB_TYPE, CouchDBClass))
+#define COUCHDB_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COUCHDB_TYPE))
+#define COUCHDB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COUCHDB_TYPE, CouchDBClass))
+
+typedef struct _CouchDB CouchDB;
+typedef struct {
+ GObjectClass parent_class;
+
+ void (* database_created) (CouchDB *couchdb, const char *dbname);
+ void (* database_deleted) (CouchDB *couchdb, const char *dbname);
+
+ void (* document_created) (CouchDB *couchdb, const char *dbname, CouchDBDocument *document);
+ void (* document_updated) (CouchDB *couchdb, const char *dbname, CouchDBDocument *document);
+ void (* document_deleted) (CouchDB *couchdb, const char *dbname, const char *docid);
+} CouchDBClass;
+
+GType couchdb_get_type (void);
+CouchDB *couchdb_new (const char *hostname);
+
+const char *couchdb_get_hostname (CouchDB *couchdb);
+
+GSList *couchdb_list_databases (CouchDB *couchdb, GError **error);
+void couchdb_free_database_list (GSList *dblist);
+
+CouchDBDatabaseInfo *couchdb_get_database_info (CouchDB *couchdb, const char *dbname, GError **error);
+
+gboolean couchdb_create_database (CouchDB *couchdb, const char *dbname, GError **error);
+gboolean couchdb_delete_database (CouchDB *couchdb, const char *dbname, GError **error);
+
+void couchdb_listen_for_changes (CouchDB *couchdb, const char *dbname);
+
+gboolean couchdb_enable_oauth (CouchDB *couchdb,
+ const char *consumer_key,
+ const char *consumer_secret,
+ const char *token_key,
+ const char *token_secret);
+void couchdb_disable_oauth (CouchDB *couchdb);
+
+GSList *couchdb_list_documents (CouchDB *couchdb, const char *dbname, GError **error);
+void couchdb_free_document_list (GSList *doclist);
+
+G_END_DECLS
+
+#endif /* __COUCHDB_H__ */
diff --git a/couchdb-glib/utils.h b/couchdb-glib/utils.h
index d3f124a..82d7d27 100644
--- a/couchdb-glib/utils.h
+++ b/couchdb-glib/utils.h
@@ -22,85 +22,19 @@
#ifndef __UTILS_H__
#define __UTILS_H__
+#include <glib.h>
#include "config.h"
-#include <libsoup/soup-session-async.h>
-#include <json-glib/json-glib.h>
-
-struct _CouchDB {
- GObject parent;
-
- char *hostname;
- SoupSession *http_session;
-
- GHashTable *db_watchlist;
-
-#ifdef HAVE_OAUTH
- gboolean oauth_enabled;
- char *oauth_consumer_key;
- char *oauth_consumer_secret;
- char *oauth_token_key;
- char *oauth_token_secret;
-#endif
-};
-
-struct _CouchDBDocument {
- GObject parent;
-
- CouchDB *couchdb;
- char *dbname;
- JsonNode *root_node;
-};
-
-struct _CouchDBDatabaseInfo {
- gint ref_count;
-
- char *dbname;
- gint doc_count;
- gint doc_del_count;
- gint update_seq;
- gboolean compact_running;
- gint disk_size;
-};
-
-CouchDBDatabaseInfo *couchdb_database_info_new (const char *dbname,
- gint doc_count,
- gint doc_del_count,
- gint update_seq,
- gboolean compact_running,
- gint disk_size);
-
-struct _CouchDBDocumentInfo {
- gint ref_count;
-
- char *docid;
- char *revision;
-};
-
-CouchDBDocumentInfo *couchdb_document_info_new (const char *docid, const char *revision);
-
-struct _CouchDBStructField {
- gint ref_count;
- JsonObject *json_object;
-
- /* Extra data needed for some specific StructField's */
- char *uuid; /* the UUID of this item */
-};
-
-CouchDBStructField *couchdb_struct_field_new_from_json_object (JsonObject *json_object);
-
-/*
- * Utility functions
- */
+#include "couchdb.h"
#define COUCHDB_ERROR couchdb_error_quark()
GQuark couchdb_error_quark (void);
-JsonParser *send_message_and_parse (CouchDB *couchdb,
+JsonParser* send_message_and_parse (CouchDB *couchdb,
const char *method,
const char *url,
const char *body,
GError **error);
-char *generate_uuid (void);
+char* generate_uuid (void);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]