[libgda] Skeleton providers adaptations to make provider work correctly in case some files are missing



commit 512f449fe7381db1b60adf9489fafff1991f50e7
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Feb 4 15:20:13 2015 +0100

    Skeleton providers adaptations to make provider work correctly in case some files are missing

 providers/skel-implementation/capi/Makefile.am     |   13 ++++-
 .../skel-implementation/capi/capi.gresource.xml    |    7 +++
 .../skel-implementation/capi/gda-capi-provider.c   |   58 ++++++++++++--------
 providers/skel-implementation/capi/libmain.c       |    5 ++-
 providers/skel-implementation/models/Makefile.am   |   13 +++++
 providers/skel-implementation/models/libmain.c     |    5 ++-
 .../models/models.gresource.xml                    |    6 ++
 7 files changed, 81 insertions(+), 26 deletions(-)
---
diff --git a/providers/skel-implementation/capi/Makefile.am b/providers/skel-implementation/capi/Makefile.am
index f94d09b..522a0e5 100644
--- a/providers/skel-implementation/capi/Makefile.am
+++ b/providers/skel-implementation/capi/Makefile.am
@@ -49,6 +49,7 @@ libgda_capi_la_SOURCES = \
        gda-capi-recordset.c \
        gda-capi-recordset.h \
        gda-capi.h \
+       capi.gresources.c \
        libmain.c \
        parser.h \
         parser.c \
@@ -69,6 +70,15 @@ xml_in_files = \
 #xml_DATA = $(xml_in_files:.xml.in=.xml) 
 noinst_DATA = $(xml_in_files:.xml.in=.xml)
 
+# resources
+RESOURCES=$(xml_in_files:.xml.in=.raw.xml)
+capi.gresources.c: capi.gresource.xml $(RESOURCES)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(srcdir)/capi.gresource.xml
+
+%.raw.xml:%.xml.in
+       @echo "  GEN      $@"
+       @cat $< | sed -e 's/_\([a-zA-Z0-9]*\)=/\1=/g' -e 's/<_\([a-ZA-Z0-9_]*\)>/<\1>/g' -e 
's/<\/_\([a-ZA-Z0-9_]*\)>/<\/\1>/g' -e 's/<!-- .* -->//'> $@
+
 pkgconfigdir = $(libdir)/pkgconfig
 #pkgconfig_DATA = libgda-capi-6.0.pc
 noinst_DATA += libgda-capi-6.0.pc
@@ -77,4 +87,5 @@ EXTRA_DIST = $(xml_in_files) libgda-capi-6.0.pc.in parser.y gen_def.c $(keyword_
 DISTCLEANFILES = $(noinst_DATA)
 
 CLEANFILES = parser.h parser.c parser.out capi_token_types.h gen_def$(EXEEXT_FOR_BUILD) \
-       mkkeywordhash$(EXEEXT_FOR_BUILD) keywords_hash.c
+       mkkeywordhash$(EXEEXT_FOR_BUILD) keywords_hash.c \
+       capi.gresources.c
diff --git a/providers/skel-implementation/capi/capi.gresource.xml 
b/providers/skel-implementation/capi/capi.gresource.xml
new file mode 100644
index 0000000..818b0bf
--- /dev/null
+++ b/providers/skel-implementation/capi/capi.gresource.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/spec/capi">
+    <file compressed="true">capi_specs_create_table.raw.xml</file>
+    <file compressed="true">capi_specs_dsn.raw.xml</file>
+  </gresource>
+</gresources>
diff --git a/providers/skel-implementation/capi/gda-capi-provider.c 
b/providers/skel-implementation/capi/gda-capi-provider.c
index 8ab12c4..38702db 100644
--- a/providers/skel-implementation/capi/gda-capi-provider.c
+++ b/providers/skel-implementation/capi/gda-capi-provider.c
@@ -548,23 +548,28 @@ gda_capi_provider_create_operation (GdaServerProvider *provider, GdaConnection *
        }
 
         file = g_utf8_strdown (gda_server_operation_op_type_to_string (type), -1);
-        str = g_strdup_printf ("capi_specs_%s.xml", file);
+        str = g_strdup_printf ("capi_specs_%s", file);
         g_free (file);
 
+       gchar *tmp;
+       tmp = g_strdup_printf ("%s.xml", str);
        dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
-        file = gda_server_provider_find_file (provider, dir, str);
+        file = gda_server_provider_find_file (provider, dir, tmp);
        g_free (dir);
+       g_free (tmp);
 
-        if (! file) {
-                g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_FILE_NOT_FOUND_ERROR,
-                            _("Missing spec. file '%s'"), str);
+       if (file) {
                g_free (str);
-                return NULL;
+               op = gda_server_operation_new (type, file);
+               g_free (file);
+       }
+       else {
+               file = g_strdup_printf ("/spec/capi/%s.raw.xml", str);
+               g_free (str);
+               op = GDA_SERVER_OPERATION (g_object_new (GDA_TYPE_SERVER_OPERATION, "op-type", type,
+                                                        "spec-resource", file, NULL));
+               g_free (file);
         }
-        g_free (str);
-
-        op = gda_server_operation_new (type, file);
-        g_free (file);
 
         return op;
 }
@@ -588,25 +593,32 @@ gda_capi_provider_render_operation (GdaServerProvider *provider, GdaConnection *
 
        /* test @op's validity */
         file = g_utf8_strdown (gda_server_operation_op_type_to_string (gda_server_operation_get_op_type 
(op)), -1);
-        str = g_strdup_printf ("capi_specs_%s.xml", file);
+        str = g_strdup_printf ("capi_specs_%s", file);
         g_free (file);
-
+       
+       gchar *tmp;
+       tmp = g_strdup_printf ("%s.xml", str);
        dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
-        file = gda_server_provider_find_file (provider, dir, str);
+        file = gda_server_provider_find_file (provider, dir, tmp);
        g_free (dir);
+       g_free (tmp);
 
-        if (! file) {
-                g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_FILE_NOT_FOUND_ERROR,
-                            _("Missing spec. file '%s'"), str);
+       if (file) {
                g_free (str);
-                return NULL;
-        }
-        g_free (str);
-        if (!gda_server_operation_is_valid (op, file, error)) {
-                g_free (file);
-                return NULL;
+               if (!gda_server_operation_is_valid (op, file, error)) {
+                       g_free (file);
+                       return NULL;
+               }
+       }
+       else {
+               file = g_strdup_printf ("/spec/mysql/%s.raw.xml", str);
+               g_free (str);
+               if (!gda_server_operation_is_valid_from_resource (op, file, error)) {
+                       g_free (file);
+                       return NULL;
+               }
         }
-        g_free (file);
+       g_free (file);
 
        /* actual rendering */
         switch (gda_server_operation_get_op_type (op)) {
diff --git a/providers/skel-implementation/capi/libmain.c b/providers/skel-implementation/capi/libmain.c
index 142cfeb..3678695 100644
--- a/providers/skel-implementation/capi/libmain.c
+++ b/providers/skel-implementation/capi/libmain.c
@@ -80,7 +80,10 @@ plugin_get_dsn_spec (void)
        dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
        ret = gda_server_provider_load_file_contents (module_path, dir, "capi_specs_dsn.xml");
        g_free (dir);
-       return ret;
+       if (ret)
+               return ret;
+       else
+               return gda_server_provider_load_resource_contents ("capi", "capi_specs_dsn.raw.xml");
 }
 
 GdaServerProvider *
diff --git a/providers/skel-implementation/models/Makefile.am 
b/providers/skel-implementation/models/Makefile.am
index 0930d99..4a869b1 100644
--- a/providers/skel-implementation/models/Makefile.am
+++ b/providers/skel-implementation/models/Makefile.am
@@ -14,6 +14,7 @@ libgda_models_la_SOURCES = \
        gda-models-provider.c \
        gda-models-provider.h \
        gda-models.h \
+       models.gresources.c \
        libmain.c
 
 libgda_models_la_LDFLAGS = -export-dynamic -module -avoid-version $(NO_UNDEFINED) 
$(LIBTOOL_PROV_EXPORT_OPTIONS)
@@ -29,6 +30,15 @@ xml_in_files = models_specs_dsn.xml.in
 #xml_DATA = $(xml_in_files:.xml.in=.xml)
 noinst_DATA = $(xml_in_files:.xml.in=.xml)
 
+# resources
+RESOURCES=$(xml_in_files:.xml.in=.raw.xml)
+models.gresources.c: models.gresource.xml $(RESOURCES)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(srcdir)/models.gresource.xml
+
+%.raw.xml:%.xml.in
+       @echo "  GEN      $@"
+       @cat $< | sed -e 's/_\([a-zA-Z0-9]*\)=/\1=/g' -e 's/<_\([a-ZA-Z0-9_]*\)>/<\1>/g' -e 
's/<\/_\([a-ZA-Z0-9_]*\)>/<\/\1>/g' -e 's/<!-- .* -->//'> $@
+
 pkgconfigdir = $(libdir)/pkgconfig
 #pkgconfig_DATA = libgda-models-6.0.pc
 noinst_DATA += libgda-models-6.0.pc
@@ -36,3 +46,6 @@ noinst_DATA += libgda-models-6.0.pc
 EXTRA_DIST = $(xml_in_files) libgda-models-6.0.pc.in
 DISTCLEANFILES = $(noinst_DATA)
 
+CLEANFILES = \
+        models.gresources.c \
+        $(RESOURCES)
diff --git a/providers/skel-implementation/models/libmain.c b/providers/skel-implementation/models/libmain.c
index 9267e4d..eacd888 100644
--- a/providers/skel-implementation/models/libmain.c
+++ b/providers/skel-implementation/models/libmain.c
@@ -81,7 +81,10 @@ plugin_get_dsn_spec (void)
        dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
        ret = gda_server_provider_load_file_contents (module_path, dir, "models_specs_dsn.xml");
        g_free (dir);
-       return ret;
+       if (ret)
+               return ret;
+       else
+               return gda_server_provider_load_resource_contents ("models", "models_specs_dsn.raw.xml");
 }
 
 gchar *
diff --git a/providers/skel-implementation/models/models.gresource.xml 
b/providers/skel-implementation/models/models.gresource.xml
new file mode 100644
index 0000000..572cda3
--- /dev/null
+++ b/providers/skel-implementation/models/models.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/spec/models">
+    <file compressed="true">models_specs_dsn.raw.xml</file>
+  </gresource>
+</gresources>


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