[Groonga-commit] groonga/groonga-gobject at 0382fc8 [master] Add ggrn_context_open_database()

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Dec 1 22:33:16 JST 2013


Kouhei Sutou	2013-12-01 22:33:16 +0900 (Sun, 01 Dec 2013)

  New Revision: 0382fc8fab793768bbcaf0eb33948c195bf2a301
  https://github.com/groonga/groonga-gobject/commit/0382fc8fab793768bbcaf0eb33948c195bf2a301

  Message:
    Add ggrn_context_open_database()

  Added files:
    groonga-gobject/ggrn-error.c
    groonga-gobject/ggrn-error.h
    groonga-gobject/ggrn-internal.c
    groonga-gobject/ggrn-internal.h
  Modified files:
    .gitignore
    groonga-gobject/Makefile.am
    groonga-gobject/ggrn-context.c
    groonga-gobject/ggrn-context.h

  Modified: .gitignore (+1 -0)
===================================================================
--- .gitignore    2013-12-01 18:56:00 +0900 (a0a57a0)
+++ .gitignore    2013-12-01 22:33:16 +0900 (ccd4f3a)
@@ -7,6 +7,7 @@ Makefile
 *.o
 *.lo
 *.la
+*.bak
 /aclocal.m4
 /autom4te.cache/
 /config.h.in

  Modified: groonga-gobject/Makefile.am (+5 -1)
===================================================================
--- groonga-gobject/Makefile.am    2013-12-01 18:56:00 +0900 (4a6ceb5)
+++ groonga-gobject/Makefile.am    2013-12-01 22:33:16 +0900 (3c75f68)
@@ -39,7 +39,11 @@ libgroonga_gobject_la_SOURCES =			\
 	ggrn.c					\
 	ggrn.h					\
 	ggrn-context.c				\
-	ggrn-context.h
+	ggrn-context.h				\
+	ggrn-error.c				\
+	ggrn-error.h				\
+	ggrn-internal.c				\
+	ggrn-internal.h
 
 -include $(INTROSPECTION_MAKEFILE)
 INTROSPECTION_GIRS =

  Modified: groonga-gobject/ggrn-context.c (+29 -0)
===================================================================
--- groonga-gobject/ggrn-context.c    2013-12-01 18:56:00 +0900 (cb9c1ee)
+++ groonga-gobject/ggrn-context.c    2013-12-01 22:33:16 +0900 (3241c81)
@@ -23,6 +23,7 @@
 #include <groonga.h>
 
 #include "ggrn-context.h"
+#include "ggrn-internal.h"
 
 /**
 * SECTION: ggrn-context
@@ -96,3 +97,31 @@ ggrn_context_new(void)
     context = g_object_new(GGRN_TYPE_CONTEXT, NULL);
     return context;
 }
+
+/**
+ * ggrn_context_open_database:
+ * @context: A #GGrnContext.
+ * @path: The path of the database to be opened.
+ * @error: return location for a GError, or %NULL.
+ *
+ * Opens a database.
+ *
+ * Returns: TRUE on success, FALSE if an error occurred.
+ */
+gboolean
+ggrn_context_open_database(GGrnContext *context,
+                           const gchar *path, GError **error)
+{
+    GGrnContextPrivate *priv = GGRN_CONTEXT_GET_PRIVATE(context);
+    grn_obj *opened_database, *database;
+    gboolean succeeded;
+
+    opened_database = grn_ctx_db(priv->ctx);
+
+    database = grn_db_open(priv->ctx, path);
+    succeeded = _ggrn_rc_check(priv->ctx->rc, error);
+    if (succeeded && opened_database) {
+        grn_db_close(priv->ctx, opened_database);
+    }
+    return succeeded;
+}

  Modified: groonga-gobject/ggrn-context.h (+3 -0)
===================================================================
--- groonga-gobject/ggrn-context.h    2013-12-01 18:56:00 +0900 (d0d585d)
+++ groonga-gobject/ggrn-context.h    2013-12-01 22:33:16 +0900 (f3b9c24)
@@ -57,6 +57,9 @@ struct _GGrnContextClass
 
 GType                ggrn_context_get_type          (void) G_GNUC_CONST;
 GGrnContext         *ggrn_context_new               (void);
+gboolean             ggrn_context_open_database     (GGrnContext  *context,
+                                                     const gchar  *path,
+                                                     GError      **error);
 
 G_END_DECLS
 

  Added: groonga-gobject/ggrn-error.c (+267 -0) 100644
===================================================================
--- /dev/null
+++ groonga-gobject/ggrn-error.c    2013-12-01 22:33:16 +0900 (e5abbed)
@@ -0,0 +1,267 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013  Kouhei Sutou <kou �� clear-code.com>
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <groonga.h>
+
+#include "ggrn-error.h"
+
+GQuark
+ggrn_error_quark(void)
+{
+    return g_quark_from_static_string("ggrn-error-quark");
+}
+
+const gchar *
+ggrn_error_to_string(GGrnError error)
+{
+    const gchar *message = "unknown";
+
+    switch (error) {
+    case 0:
+        message = "succeess";
+        break;
+    case GGRN_ERROR_END_OF_DATA:
+        message = "end of data";
+        break;
+    case GGRN_ERROR_UNKNOWN_ERROR:
+        message = "unknown error";
+        break;
+    case GGRN_ERROR_OPERATION_NOT_PERMITTED:
+        message = "operation not permitted";
+        break;
+    case GGRN_ERROR_NO_SUCH_FILE_OR_DIRECTORY:
+        message = "no such file or directory";
+        break;
+    case GGRN_ERROR_NO_SUCH_PROCESS:
+        message = "no such process";
+        break;
+    case GGRN_ERROR_INTERRUPTED_FUNCTION_CALL:
+        message = "interrupted function call";
+        break;
+    case GGRN_ERROR_INPUT_OUTPUT_ERROR:
+        message = "input output error";
+        break;
+    case GGRN_ERROR_NO_SUCH_DEVICE_OR_ADDRESS:
+        message = "no such device or address";
+        break;
+    case GGRN_ERROR_ARG_LIST_TOO_LONG:
+        message = "arg list too long";
+        break;
+    case GGRN_ERROR_EXEC_FORMAT_ERROR:
+        message = "exec format error";
+        break;
+    case GGRN_ERROR_BAD_FILE_DESCRIPTOR:
+        message = "bad file descriptor";
+        break;
+    case GGRN_ERROR_NO_CHILD_PROCESSES:
+        message = "no child processes";
+        break;
+    case GGRN_ERROR_RESOURCE_TEMPORARILY_UNAVAILABLE:
+        message = "resource temporarily unavailable";
+        break;
+    case GGRN_ERROR_NOT_ENOUGH_SPACE:
+        message = "not enough space";
+        break;
+    case GGRN_ERROR_PERMISSION_DENIED:
+        message = "permission denied";
+        break;
+    case GGRN_ERROR_BAD_ADDRESS:
+        message = "bad address";
+        break;
+    case GGRN_ERROR_RESOURCE_BUSY:
+        message = "resource busy";
+        break;
+    case GGRN_ERROR_FILE_EXISTS:
+        message = "file exists";
+        break;
+    case GGRN_ERROR_IMPROPER_LINK:
+        message = "improper link";
+        break;
+    case GGRN_ERROR_NO_SUCH_DEVICE:
+        message = "no such device";
+        break;
+    case GGRN_ERROR_NOT_A_DIRECTORY:
+        message = "not a directory";
+        break;
+    case GGRN_ERROR_IS_A_DIRECTORY:
+        message = "is a directory";
+        break;
+    case GGRN_ERROR_INVALID_ARGUMENT:
+        message = "invalid argument";
+        break;
+    case GGRN_ERROR_TOO_MANY_OPEN_FILES_IN_SYSTEM:
+        message = "too many open files in system";
+        break;
+    case GGRN_ERROR_TOO_MANY_OPEN_FILES:
+        message = "too many open files";
+        break;
+    case GGRN_ERROR_INAPPROPRIATE_I_O_CONTROL_OPERATION:
+        message = "inappropriate i o control operation";
+        break;
+    case GGRN_ERROR_FILE_TOO_LARGE:
+        message = "file too large";
+        break;
+    case GGRN_ERROR_NO_SPACE_LEFT_ON_DEVICE:
+        message = "no space left on device";
+        break;
+    case GGRN_ERROR_INVALID_SEEK:
+        message = "invalid seek";
+        break;
+    case GGRN_ERROR_READ_ONLY_FILE_SYSTEM:
+        message = "read only file system";
+        break;
+    case GGRN_ERROR_TOO_MANY_LINKS:
+        message = "too many links";
+        break;
+    case GGRN_ERROR_BROKEN_PIPE:
+        message = "broken pipe";
+        break;
+    case GGRN_ERROR_DOMAIN_ERROR:
+        message = "domain error";
+        break;
+    case GGRN_ERROR_RESULT_TOO_LARGE:
+        message = "result too large";
+        break;
+    case GGRN_ERROR_RESOURCE_DEADLOCK_AVOIDED:
+        message = "resource deadlock avoided";
+        break;
+    case GGRN_ERROR_NO_MEMORY_AVAILABLE:
+        message = "no memory available";
+        break;
+    case GGRN_ERROR_FILENAME_TOO_LONG:
+        message = "filename too long";
+        break;
+    case GGRN_ERROR_NO_LOCKS_AVAILABLE:
+        message = "no locks available";
+        break;
+    case GGRN_ERROR_FUNCTION_NOT_IMPLEMENTED:
+        message = "function not implemented";
+        break;
+    case GGRN_ERROR_DIRECTORY_NOT_EMPTY:
+        message = "directory not empty";
+        break;
+    case GGRN_ERROR_ILLEGAL_BYTE_SEQUENCE:
+        message = "illegal byte sequence";
+        break;
+    case GGRN_ERROR_SOCKET_NOT_INITIALIZED:
+        message = "socket not initialized";
+        break;
+    case GGRN_ERROR_OPERATION_WOULD_BLOCK:
+        message = "operation would block";
+        break;
+    case GGRN_ERROR_ADDRESS_IS_NOT_AVAILABLE:
+        message = "address is not available";
+        break;
+    case GGRN_ERROR_NETWORK_IS_DOWN:
+        message = "network is down";
+        break;
+    case GGRN_ERROR_NO_BUFFER:
+        message = "no buffer";
+        break;
+    case GGRN_ERROR_SOCKET_IS_ALREADY_CONNECTED:
+        message = "socket is already connected";
+        break;
+    case GGRN_ERROR_SOCKET_IS_NOT_CONNECTED:
+        message = "socket is not connected";
+        break;
+    case GGRN_ERROR_SOCKET_IS_ALREADY_SHUTDOWNED:
+        message = "socket is already shutdowned";
+        break;
+    case GGRN_ERROR_OPERATION_TIMEOUT:
+        message = "operation timeout";
+        break;
+    case GGRN_ERROR_CONNECTION_REFUSED:
+        message = "connection refused";
+        break;
+    case GGRN_ERROR_RANGE_ERROR:
+        message = "range error";
+        break;
+    case GGRN_ERROR_TOKENIZER_ERROR:
+        message = "tokenizer error";
+        break;
+    case GGRN_ERROR_FILE_CORRUPT:
+        message = "file corrupt";
+        break;
+    case GGRN_ERROR_INVALID_FORMAT:
+        message = "invalid format";
+        break;
+    case GGRN_ERROR_OBJECT_CORRUPT:
+        message = "object corrupt";
+        break;
+    case GGRN_ERROR_TOO_MANY_SYMBOLIC_LINKS:
+        message = "too many symbolic links";
+        break;
+    case GGRN_ERROR_NOT_SOCKET:
+        message = "not socket";
+        break;
+    case GGRN_ERROR_OPERATION_NOT_SUPPORTED:
+        message = "operation not supported";
+        break;
+    case GGRN_ERROR_ADDRESS_IS_IN_USE:
+        message = "address is in use";
+        break;
+    case GGRN_ERROR_ZLIB_ERROR:
+        message = "zlib error";
+        break;
+    case GGRN_ERROR_LZO_ERROR:
+        message = "lzo error";
+        break;
+    case GGRN_ERROR_STACK_OVER_FLOW:
+        message = "stack over flow";
+        break;
+    case GGRN_ERROR_SYNTAX_ERROR:
+        message = "syntax error";
+        break;
+    case GGRN_ERROR_RETRY_MAX:
+        message = "retry max";
+        break;
+    case GGRN_ERROR_INCOMPATIBLE_FILE_FORMAT:
+        message = "incompatible file format";
+        break;
+    case GGRN_ERROR_UPDATE_NOT_ALLOWED:
+        message = "update not allowed";
+        break;
+    case GGRN_ERROR_TOO_SMALL_OFFSET:
+        message = "too small offset";
+        break;
+    case GGRN_ERROR_TOO_LARGE_OFFSET:
+        message = "too large offset";
+        break;
+    case GGRN_ERROR_TOO_SMALL_LIMIT:
+        message = "too small limit";
+        break;
+    case GGRN_ERROR_CAS_ERROR:
+        message = "cas error";
+        break;
+    case GGRN_ERROR_UNSUPPORTED_COMMAND_VERSION:
+        message = "unsupported command version";
+        break;
+    case GGRN_ERROR_NORMALIZER_ERROR:
+        message = "normalizer error";
+        break;
+    default:
+        message = "unknown";
+        break;
+    }
+
+    return message;
+}

  Added: groonga-gobject/ggrn-error.h (+111 -0) 100644
===================================================================
--- /dev/null
+++ groonga-gobject/ggrn-error.h    2013-12-01 22:33:16 +0900 (6217285)
@@ -0,0 +1,111 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013  Kouhei Sutou <kou �� clear-code.com>
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GGRN_ERROR_H
+#define GGRN_ERROR_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GGRN_ERROR \
+  (ggrn_error_quark())
+
+typedef enum
+{
+  GGRN_ERROR_END_OF_DATA = 1,
+  GGRN_ERROR_UNKNOWN_ERROR = -1,
+  GGRN_ERROR_OPERATION_NOT_PERMITTED = -2,
+  GGRN_ERROR_NO_SUCH_FILE_OR_DIRECTORY = -3,
+  GGRN_ERROR_NO_SUCH_PROCESS = -4,
+  GGRN_ERROR_INTERRUPTED_FUNCTION_CALL = -5,
+  GGRN_ERROR_INPUT_OUTPUT_ERROR = -6,
+  GGRN_ERROR_NO_SUCH_DEVICE_OR_ADDRESS = -7,
+  GGRN_ERROR_ARG_LIST_TOO_LONG = -8,
+  GGRN_ERROR_EXEC_FORMAT_ERROR = -9,
+  GGRN_ERROR_BAD_FILE_DESCRIPTOR = -10,
+  GGRN_ERROR_NO_CHILD_PROCESSES = -11,
+  GGRN_ERROR_RESOURCE_TEMPORARILY_UNAVAILABLE = -12,
+  GGRN_ERROR_NOT_ENOUGH_SPACE = -13,
+  GGRN_ERROR_PERMISSION_DENIED = -14,
+  GGRN_ERROR_BAD_ADDRESS = -15,
+  GGRN_ERROR_RESOURCE_BUSY = -16,
+  GGRN_ERROR_FILE_EXISTS = -17,
+  GGRN_ERROR_IMPROPER_LINK = -18,
+  GGRN_ERROR_NO_SUCH_DEVICE = -19,
+  GGRN_ERROR_NOT_A_DIRECTORY = -20,
+  GGRN_ERROR_IS_A_DIRECTORY = -21,
+  GGRN_ERROR_INVALID_ARGUMENT = -22,
+  GGRN_ERROR_TOO_MANY_OPEN_FILES_IN_SYSTEM = -23,
+  GGRN_ERROR_TOO_MANY_OPEN_FILES = -24,
+  GGRN_ERROR_INAPPROPRIATE_I_O_CONTROL_OPERATION = -25,
+  GGRN_ERROR_FILE_TOO_LARGE = -26,
+  GGRN_ERROR_NO_SPACE_LEFT_ON_DEVICE = -27,
+  GGRN_ERROR_INVALID_SEEK = -28,
+  GGRN_ERROR_READ_ONLY_FILE_SYSTEM = -29,
+  GGRN_ERROR_TOO_MANY_LINKS = -30,
+  GGRN_ERROR_BROKEN_PIPE = -31,
+  GGRN_ERROR_DOMAIN_ERROR = -32,
+  GGRN_ERROR_RESULT_TOO_LARGE = -33,
+  GGRN_ERROR_RESOURCE_DEADLOCK_AVOIDED = -34,
+  GGRN_ERROR_NO_MEMORY_AVAILABLE = -35,
+  GGRN_ERROR_FILENAME_TOO_LONG = -36,
+  GGRN_ERROR_NO_LOCKS_AVAILABLE = -37,
+  GGRN_ERROR_FUNCTION_NOT_IMPLEMENTED = -38,
+  GGRN_ERROR_DIRECTORY_NOT_EMPTY = -39,
+  GGRN_ERROR_ILLEGAL_BYTE_SEQUENCE = -40,
+  GGRN_ERROR_SOCKET_NOT_INITIALIZED = -41,
+  GGRN_ERROR_OPERATION_WOULD_BLOCK = -42,
+  GGRN_ERROR_ADDRESS_IS_NOT_AVAILABLE = -43,
+  GGRN_ERROR_NETWORK_IS_DOWN = -44,
+  GGRN_ERROR_NO_BUFFER = -45,
+  GGRN_ERROR_SOCKET_IS_ALREADY_CONNECTED = -46,
+  GGRN_ERROR_SOCKET_IS_NOT_CONNECTED = -47,
+  GGRN_ERROR_SOCKET_IS_ALREADY_SHUTDOWNED = -48,
+  GGRN_ERROR_OPERATION_TIMEOUT = -49,
+  GGRN_ERROR_CONNECTION_REFUSED = -50,
+  GGRN_ERROR_RANGE_ERROR = -51,
+  GGRN_ERROR_TOKENIZER_ERROR = -52,
+  GGRN_ERROR_FILE_CORRUPT = -53,
+  GGRN_ERROR_INVALID_FORMAT = -54,
+  GGRN_ERROR_OBJECT_CORRUPT = -55,
+  GGRN_ERROR_TOO_MANY_SYMBOLIC_LINKS = -56,
+  GGRN_ERROR_NOT_SOCKET = -57,
+  GGRN_ERROR_OPERATION_NOT_SUPPORTED = -58,
+  GGRN_ERROR_ADDRESS_IS_IN_USE = -59,
+  GGRN_ERROR_ZLIB_ERROR = -60,
+  GGRN_ERROR_LZO_ERROR = -61,
+  GGRN_ERROR_STACK_OVER_FLOW = -62,
+  GGRN_ERROR_SYNTAX_ERROR = -63,
+  GGRN_ERROR_RETRY_MAX = -64,
+  GGRN_ERROR_INCOMPATIBLE_FILE_FORMAT = -65,
+  GGRN_ERROR_UPDATE_NOT_ALLOWED = -66,
+  GGRN_ERROR_TOO_SMALL_OFFSET = -67,
+  GGRN_ERROR_TOO_LARGE_OFFSET = -68,
+  GGRN_ERROR_TOO_SMALL_LIMIT = -69,
+  GGRN_ERROR_CAS_ERROR = -70,
+  GGRN_ERROR_UNSUPPORTED_COMMAND_VERSION = -71,
+  GGRN_ERROR_NORMALIZER_ERROR = -72,
+} GGrnError;
+
+GQuark       ggrn_error_quark     (void);
+const gchar *ggrn_error_to_string (GGrnError error);
+
+G_END_DECLS
+
+#endif

  Added: groonga-gobject/ggrn-internal.c (+41 -0) 100644
===================================================================
--- /dev/null
+++ groonga-gobject/ggrn-internal.c    2013-12-01 22:33:16 +0900 (dab15ff)
@@ -0,0 +1,41 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013  Kouhei Sutou <kou �� clear-code.com>
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "ggrn-internal.h"
+#include "ggrn-error.h"
+
+gboolean
+_ggrn_rc_check(grn_rc rc, GError **error)
+{
+    GGrnError ggrn_error = (GGrnError)rc;
+
+    if (rc == GRN_SUCCESS) {
+        return TRUE;
+    }
+
+    g_set_error(error, GGRN_ERROR,
+                ggrn_error,
+                "%s (%d)",
+                ggrn_error_to_string(ggrn_error),
+                rc);
+    return FALSE;
+}

  Added: groonga-gobject/ggrn-internal.h (+31 -0) 100644
===================================================================
--- /dev/null
+++ groonga-gobject/ggrn-internal.h    2013-12-01 22:33:16 +0900 (04cb3c3)
@@ -0,0 +1,31 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013  Kouhei Sutou <kou �� clear-code.com>
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GGRN_INTERNAL_H
+#define GGRN_INTERNAL_H
+
+#include <glib.h>
+#include <groonga.h>
+
+G_BEGIN_DECLS
+
+G_GNUC_INTERNAL gboolean _ggrn_rc_check (grn_rc, GError **error);
+
+G_END_DECLS
+
+#endif
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index