[libgda] GdaVproviderDataModel: ported to G_DEFINE/G_DECLARE



commit 4fa0bf3f9f22fd9a1369b0291cf5ce101f44dfb4
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Mon Feb 25 11:58:37 2019 -0600

    GdaVproviderDataModel: ported to G_DEFINE/G_DECLARE

 libgda/sqlite/virtual/gda-vprovider-data-model.c | 74 ++++--------------------
 libgda/sqlite/virtual/gda-vprovider-data-model.h | 15 +----
 tests/parser/meson.build                         |  2 +-
 3 files changed, 12 insertions(+), 79 deletions(-)
---
diff --git a/libgda/sqlite/virtual/gda-vprovider-data-model.c 
b/libgda/sqlite/virtual/gda-vprovider-data-model.c
index 5428b1fc6..fc3cd06a2 100644
--- a/libgda/sqlite/virtual/gda-vprovider-data-model.c
+++ b/libgda/sqlite/virtual/gda-vprovider-data-model.c
@@ -51,14 +51,12 @@ GQuark gda_vprovider_data_model_error_quark (void)
 #define GDA_DEBUG_VIRTUAL
 #undef GDA_DEBUG_VIRTUAL
 
-struct _GdaVproviderDataModelPrivate {
+typedef struct  {
        int foo;
-};
+} GdaVproviderDataModelPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GdaVproviderDataModel, gda_vprovider_data_model, GDA_TYPE_VIRTUAL_PROVIDER)
 
-static void gda_vprovider_data_model_class_init (GdaVproviderDataModelClass *klass);
-static void gda_vprovider_data_model_init       (GdaVproviderDataModel *prov, GdaVproviderDataModelClass 
*klass);
-static void gda_vprovider_data_model_finalize   (GObject *object);
-static GObjectClass  *parent_class = NULL;
 
 static GdaConnection *gda_vprovider_data_model_create_connection (GdaServerProvider *provider);
 static gboolean       gda_vprovider_data_model_open_connection (GdaServerProvider *provider, GdaConnection 
*cnc,
@@ -117,68 +115,16 @@ GdaServerProviderBase data_model_base_functions = {
 static void
 gda_vprovider_data_model_class_init (GdaVproviderDataModelClass *klass)
 {
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-       parent_class = g_type_class_peek_parent (klass);
-
        /* set virtual functions */
        gda_server_provider_set_impl_functions (GDA_SERVER_PROVIDER_CLASS (klass),
                                                GDA_SERVER_PROVIDER_FUNCTIONS_BASE,
                                                (gpointer) &data_model_base_functions);
-
-       object_class->finalize = gda_vprovider_data_model_finalize;
 }
 
 
 static void
-gda_vprovider_data_model_init (GdaVproviderDataModel *prov, G_GNUC_UNUSED GdaVproviderDataModelClass *klass)
+gda_vprovider_data_model_init (GdaVproviderDataModel *prov)
 {
-       prov->priv = g_new (GdaVproviderDataModelPrivate, 1);
-}
-
-static void
-gda_vprovider_data_model_finalize (GObject *object)
-{
-       GdaVproviderDataModel *prov = (GdaVproviderDataModel *) object;
-
-       g_return_if_fail (GDA_IS_VPROVIDER_DATA_MODEL (prov));
-
-       /* free memory */
-       g_free (prov->priv);
-       prov->priv = NULL;
-
-       /* chain to parent class */
-       parent_class->finalize (object);
-}
-
-GType
-gda_vprovider_data_model_get_type (void)
-{
-       static GType type = 0;
-
-       if (G_UNLIKELY (type == 0)) {
-               static GMutex registering;
-               if (type == 0) {
-                       static GTypeInfo info = {
-                               sizeof (GdaVproviderDataModelClass),
-                               (GBaseInitFunc) NULL,
-                               (GBaseFinalizeFunc) NULL,
-                               (GClassInitFunc) gda_vprovider_data_model_class_init,
-                               NULL, NULL,
-                               sizeof (GdaVproviderDataModel),
-                               0,
-                               (GInstanceInitFunc) gda_vprovider_data_model_init,
-                               0
-                       };
-                       
-               g_mutex_lock (&registering);
-               if (type == 0)
-                       type = g_type_register_static (GDA_TYPE_VIRTUAL_PROVIDER, "GdaVproviderDataModel", 
&info, 0);
-               g_mutex_unlock (&registering);
-               }
-       }
-
-       return type;
 }
 
 /**
@@ -422,7 +368,7 @@ gda_vprovider_data_model_open_connection (GdaServerProvider *provider, GdaConnec
                m_params = gda_quark_list_new_from_string ("_IS_VIRTUAL=TRUE;EXTRA_FUNCTIONS=TRUE");
 
        GdaServerProviderBase *parent_functions;
-       parent_functions = gda_server_provider_get_impl_functions_for_class (parent_class, 
GDA_SERVER_PROVIDER_FUNCTIONS_BASE);
+       parent_functions = gda_server_provider_get_impl_functions_for_class 
(gda_vprovider_data_model_parent_class, GDA_SERVER_PROVIDER_FUNCTIONS_BASE);
        //g_print ("Open connection for Provider Name %\n", parent_functions->get_name(provider));
   if (parent_functions->open_connection) {
          if (! parent_functions->open_connection (GDA_SERVER_PROVIDER (provider), cnc, m_params, auth)) {
@@ -459,7 +405,7 @@ gda_vprovider_data_model_prepare_connection (GdaServerProvider *provider, GdaCon
 
        /* calling the parent's function first */
        GdaServerProviderBase *parent_functions;
-        parent_functions = gda_server_provider_get_impl_functions_for_class (parent_class, 
GDA_SERVER_PROVIDER_FUNCTIONS_BASE);
+        parent_functions = gda_server_provider_get_impl_functions_for_class 
(gda_vprovider_data_model_parent_class, GDA_SERVER_PROVIDER_FUNCTIONS_BASE);
        //g_print ("Provider Class: %s\n", parent_functions->get_name (GDA_SERVER_PROVIDER (provider)));
   if (parent_functions->prepare_connection) {
                if (! parent_functions->prepare_connection (GDA_SERVER_PROVIDER (provider), cnc, params, 
auth))
@@ -492,7 +438,7 @@ gda_vprovider_data_model_close_connection (GdaServerProvider *provider, GdaConne
                                            (GdaVconnectionDataModelFunc) cnc_close_foreach_func, cnc);
 
        GdaServerProviderBase *parent_functions;
-       parent_functions = gda_server_provider_get_impl_functions_for_class (parent_class, 
GDA_SERVER_PROVIDER_FUNCTIONS_BASE);
+       parent_functions = gda_server_provider_get_impl_functions_for_class 
(gda_vprovider_data_model_parent_class, GDA_SERVER_PROVIDER_FUNCTIONS_BASE);
        if (parent_functions->close_connection)
     return parent_functions->close_connection (provider, cnc);
   else {
@@ -511,7 +457,7 @@ gda_vprovider_data_model_statement_execute (GdaServerProvider *provider, GdaConn
        _gda_vconnection_set_working_obj ((GdaVconnectionDataModel*) cnc, (GObject*) stmt);
 
        GdaServerProviderBase *parent_functions;
-       parent_functions = gda_server_provider_get_impl_functions_for_class (parent_class, 
GDA_SERVER_PROVIDER_FUNCTIONS_BASE);
+       parent_functions = gda_server_provider_get_impl_functions_for_class 
(gda_vprovider_data_model_parent_class, GDA_SERVER_PROVIDER_FUNCTIONS_BASE);
        retval = parent_functions->statement_execute (provider, cnc, stmt, params,
                                                      model_usage, col_types,
                                                      last_inserted_row, error);
@@ -573,7 +519,7 @@ static const gchar *
 gda_vprovider_data_model_get_name (G_GNUC_UNUSED GdaServerProvider *provider)
 {
   GdaServerProviderBase *parent_functions;
-       parent_functions = gda_server_provider_get_impl_functions_for_class (parent_class, 
GDA_SERVER_PROVIDER_FUNCTIONS_BASE);
+       parent_functions = gda_server_provider_get_impl_functions_for_class 
(gda_vprovider_data_model_parent_class, GDA_SERVER_PROVIDER_FUNCTIONS_BASE);
        if (parent_functions->get_name)
     return parent_functions->get_name (provider);
   else
diff --git a/libgda/sqlite/virtual/gda-vprovider-data-model.h 
b/libgda/sqlite/virtual/gda-vprovider-data-model.h
index b63e37816..b0146ff05 100644
--- a/libgda/sqlite/virtual/gda-vprovider-data-model.h
+++ b/libgda/sqlite/virtual/gda-vprovider-data-model.h
@@ -33,21 +33,10 @@ typedef enum {
 
 
 #define GDA_TYPE_VPROVIDER_DATA_MODEL            (gda_vprovider_data_model_get_type())
-#define GDA_VPROVIDER_DATA_MODEL(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, 
GDA_TYPE_VPROVIDER_DATA_MODEL, GdaVproviderDataModel))
-#define GDA_VPROVIDER_DATA_MODEL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST (klass, 
GDA_TYPE_VPROVIDER_DATA_MODEL, GdaVproviderDataModelClass))
-#define GDA_IS_VPROVIDER_DATA_MODEL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE (obj, 
GDA_TYPE_VPROVIDER_DATA_MODEL))
-#define GDA_IS_VPROVIDER_DATA_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GDA_TYPE_VPROVIDER_DATA_MODEL))
 
 G_BEGIN_DECLS
 
-typedef struct _GdaVproviderDataModel      GdaVproviderDataModel;
-typedef struct _GdaVproviderDataModelClass GdaVproviderDataModelClass;
-typedef struct _GdaVproviderDataModelPrivate GdaVproviderDataModelPrivate;
-
-struct _GdaVproviderDataModel {
-       GdaVirtualProvider            vprovider;
-       GdaVproviderDataModelPrivate *priv;
-};
+G_DECLARE_DERIVABLE_TYPE (GdaVproviderDataModel, gda_vprovider_data_model, GDA, VPROVIDER_DATA_MODEL, 
GdaVirtualProvider)
 
 struct _GdaVproviderDataModelClass {
        GdaVirtualProviderClass       parent_class;
@@ -71,8 +60,6 @@ struct _GdaVproviderDataModelClass {
  * will generate a #GdaVconnectionDataModel connection object, from which data models can be added.
  */
 
-
-GType               gda_vprovider_data_model_get_type (void) G_GNUC_CONST;
 GdaVirtualProvider *gda_vprovider_data_model_new      (void);
 
 G_END_DECLS
diff --git a/tests/parser/meson.build b/tests/parser/meson.build
index 19628c32e..6545899d2 100644
--- a/tests/parser/meson.build
+++ b/tests/parser/meson.build
@@ -1,5 +1,5 @@
 
-tchkpr = executable('check_parsercheck_parser',
+tchkpr = executable('check_parser',
        ['check_parser.c'],
        c_args: [
                '-include',


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