[libgda] Added gda_server_provider_load_resource_contents()



commit 2e0a52d68e6d210750613d8fdf996d04951bc7c8
Author: Vivien Malerba <malerba gnome-db org>
Date:   Mon Dec 22 20:42:55 2014 +0100

    Added gda_server_provider_load_resource_contents()

 libgda/gda-server-provider-extra.c |   35 ++++++++++++++++++++++++++++++++++-
 libgda/gda-server-provider-extra.h |    1 +
 libgda/libgda.symbols              |    1 +
 3 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/libgda/gda-server-provider-extra.c b/libgda/gda-server-provider-extra.c
index 837bf6b..c48cd0d 100644
--- a/libgda/gda-server-provider-extra.c
+++ b/libgda/gda-server-provider-extra.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2006 - 2008 Murray Cumming <murrayc murrayc com>
  * Copyright (C) 2006 Rodrigo Moya <rodrigo gnome-db org>
- * Copyright (C) 2006 - 2013 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2006 - 2014 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2007 Armin Burgmeier <armin openismus com>
  * Copyright (C) 2007 Daniel Espinosa <esodan gmail com>
  * Copyright (C) 2010 David King <davidk openismus com>
@@ -30,6 +30,7 @@
 #include <libgda/gda-data-handler.h>
 #include <libgda/gda-util.h>
 #include <glib/gi18n-lib.h>
+#include <gio/gio.h>
 #include <libgda/sql-parser/gda-sql-parser.h>
 
 #include <libgda/handlers/gda-handler-numerical.h>
@@ -440,3 +441,35 @@ gda_server_provider_load_file_contents (const gchar *inst_dir, const gchar *data
        g_free (file);
        return contents;
 }
+
+/**
+ * gda_server_provider_load_resource_contents:
+ * @prov_name: the provider's name
+ * @resource: the name of the resource to load
+ *
+ * Loads and returns the contents of the specified resource.
+ * This function should only be used by database provider's implementations
+ *
+ * Returns: (transfer full): a new string containing the resource's contents, or %NULL if not found or if an 
error occurred
+ */
+gchar *
+gda_server_provider_load_resource_contents (const gchar *prov_name, const gchar *resource)
+{
+       g_return_val_if_fail (prov_name, NULL);
+       g_return_val_if_fail (resource, NULL);
+
+       gchar *rname;
+       rname = g_strdup_printf ("/spec/%s/%s", prov_name, resource);
+       g_print ("Using resource %s\n", rname);
+
+       GBytes *bytes;
+       bytes = g_resources_lookup_data (rname, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+       g_free (rname);
+       if (!bytes)
+               return NULL;
+
+       gchar *retval;
+       retval = g_strdup ((const gchar*) g_bytes_get_data (bytes, NULL));
+       g_bytes_unref (bytes);
+       return retval;
+}
diff --git a/libgda/gda-server-provider-extra.h b/libgda/gda-server-provider-extra.h
index 3b5f73b..ff4a775 100644
--- a/libgda/gda-server-provider-extra.h
+++ b/libgda/gda-server-provider-extra.h
@@ -84,6 +84,7 @@ void            _gda_server_provider_handlers_clear_for_cnc (GdaServerProvider *
  */
 gchar         *gda_server_provider_find_file                (GdaServerProvider *prov, const gchar *inst_dir, 
const gchar *filename);
 gchar         *gda_server_provider_load_file_contents       (const gchar *inst_dir, const gchar *data_dir, 
const gchar *filename);
+gchar         *gda_server_provider_load_resource_contents   (const gchar *prov_name, const gchar *resource);
 
 G_END_DECLS
 
diff --git a/libgda/libgda.symbols b/libgda/libgda.symbols
index df35efd..03f6889 100644
--- a/libgda/libgda.symbols
+++ b/libgda/libgda.symbols
@@ -604,6 +604,7 @@
        gda_server_provider_handler_use_default
        gda_server_provider_internal_get_parser
        gda_server_provider_load_file_contents
+       gda_server_provider_load_resource_contents
        gda_server_provider_perform_operation
        gda_server_provider_perform_operation_default
        gda_server_provider_render_operation


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]