[libgda] GdaCapiBlobOp: ported to G_DEFINE/G_DECLARE



commit 7264a3e6f26e8c868e158ded1d0ea91c37c1eb37
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Apr 4 12:51:07 2019 -0600

    GdaCapiBlobOp: ported to G_DEFINE/G_DECLARE

 .../skel-implementation/capi/gda-capi-blob-op.c    | 82 ++++++----------------
 .../skel-implementation/capi/gda-capi-blob-op.h    | 16 +----
 2 files changed, 23 insertions(+), 75 deletions(-)
---
diff --git a/providers/skel-implementation/capi/gda-capi-blob-op.c 
b/providers/skel-implementation/capi/gda-capi-blob-op.c
index ef37acfe5..4809e7adb 100644
--- a/providers/skel-implementation/capi/gda-capi-blob-op.c
+++ b/providers/skel-implementation/capi/gda-capi-blob-op.c
@@ -29,60 +29,28 @@
 #include <libgda/gda-blob-op-impl.h>
 #include <libgda/gda-debug-macros.h>
 
-struct _GdaCapiBlobOpPrivate {
-       GdaConnection *cnc;
-       /* TO_ADD: specific information describing a Blob in the C API */
-};
 
 static void gda_capi_blob_op_class_init (GdaCapiBlobOpClass *klass);
-static void gda_capi_blob_op_init       (GdaCapiBlobOp *blob,
-                                        GdaCapiBlobOpClass *klass);
-static void gda_capi_blob_op_finalize   (GObject *object);
+static void gda_capi_blob_op_init       (GdaCapiBlobOp *blob);
+static void gda_capi_blob_op_dispose   (GObject *object);
 
 static glong gda_capi_blob_op_get_length (GdaBlobOp *op);
 static glong gda_capi_blob_op_read       (GdaBlobOp *op, GdaBlob *blob, glong offset, glong size);
 static glong gda_capi_blob_op_write      (GdaBlobOp *op, GdaBlob *blob, glong offset);
 
-static GObjectClass *parent_class = NULL;
 
-/*
- * Object init and finalize
- */
-GType
-gda_capi_blob_op_get_type (void)
-{
-       static GType type = 0;
-
-       if (G_UNLIKELY (type == 0)) {
-               static GMutex registering;
-               static const GTypeInfo info = {
-                       sizeof (GdaCapiBlobOpClass),
-                       (GBaseInitFunc) NULL,
-                       (GBaseFinalizeFunc) NULL,
-                       (GClassInitFunc) gda_capi_blob_op_class_init,
-                       NULL,
-                       NULL,
-                       sizeof (GdaCapiBlobOp),
-                       0,
-                       (GInstanceInitFunc) gda_capi_blob_op_init,
-                       0
-               };
-               g_mutex_lock (&registering);
-               if (type == 0)
-                       type = g_type_register_static (GDA_TYPE_BLOB_OP, "GdaCapiBlobOp", &info, 0);
-               g_mutex_unlock (&registering);
-       }
-       return type;
-}
+typedef struct {
+       GdaConnection *cnc;
+       /* TO_ADD: specific information describing a Blob in the C API */
+} GdaCapiBlobOpPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GdaCapiBlobOp, gda_capi_blob_op, GDA_TYPE_BLOB_OP)
 
 static void
-gda_capi_blob_op_init (GdaCapiBlobOp *op,
-                          G_GNUC_UNUSED GdaCapiBlobOpClass *klass)
+gda_capi_blob_op_init (GdaCapiBlobOp *op)
 {
        g_return_if_fail (GDA_IS_CAPI_BLOB_OP (op));
 
-       op->priv = g_new0 (GdaCapiBlobOpPrivate, 1);
-
        /* initialize specific structure */
        TO_IMPLEMENT;
 }
@@ -93,28 +61,19 @@ gda_capi_blob_op_class_init (GdaCapiBlobOpClass *klass)
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GdaBlobOpClass *blob_class = GDA_BLOB_OP_CLASS (klass);
 
-       parent_class = g_type_class_peek_parent (klass);
 
-       object_class->finalize = gda_capi_blob_op_finalize;
+       object_class->dispose = gda_capi_blob_op_dispose;
        GDA_BLOB_OP_FUNCTIONS (blob_class->functions)->get_length = gda_capi_blob_op_get_length;
        GDA_BLOB_OP_FUNCTIONS (blob_class->functions)->read = gda_capi_blob_op_read;
        GDA_BLOB_OP_FUNCTIONS (blob_class->functions)->write = gda_capi_blob_op_write;
 }
 
 static void
-gda_capi_blob_op_finalize (GObject * object)
+gda_capi_blob_op_dispose (GObject * object)
 {
-       GdaCapiBlobOp *bop = (GdaCapiBlobOp *) object;
-
-       g_return_if_fail (GDA_IS_CAPI_BLOB_OP (bop));
-
        /* free specific information */
        TO_IMPLEMENT;
-
-       g_free (bop->priv);
-       bop->priv = NULL;
-
-       parent_class->finalize (object);
+       G_OBJECT_CLASS (gda_capi_blob_op_parent_class)->dispose (object);
 }
 
 GdaBlobOp *
@@ -125,7 +84,10 @@ gda_capi_blob_op_new (GdaConnection *cnc)
        g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
 
        bop = g_object_new (GDA_TYPE_CAPI_BLOB_OP, "connection", cnc, NULL);
-       bop->priv->cnc = cnc;
+
+  GdaCapiBlobOpPrivate *priv = gda_capi_blob_op_get_instance_private (bop);
+
+       priv->cnc = cnc;
        
        return GDA_BLOB_OP (bop);
 }
@@ -140,8 +102,8 @@ gda_capi_blob_op_get_length (GdaBlobOp *op)
 
        g_return_val_if_fail (GDA_IS_CAPI_BLOB_OP (op), -1);
        bop = GDA_CAPI_BLOB_OP (op);
-       g_return_val_if_fail (bop->priv, -1);
-       g_return_val_if_fail (GDA_IS_CONNECTION (bop->priv->cnc), -1);
+  GdaCapiBlobOpPrivate *priv = gda_capi_blob_op_get_instance_private (bop);
+       g_return_val_if_fail (GDA_IS_CONNECTION (priv->cnc), -1);
 
        TO_IMPLEMENT;
        return -1;
@@ -158,8 +120,8 @@ gda_capi_blob_op_read (GdaBlobOp *op, GdaBlob *blob, glong offset, glong size)
 
        g_return_val_if_fail (GDA_IS_CAPI_BLOB_OP (op), -1);
        bop = GDA_CAPI_BLOB_OP (op);
-       g_return_val_if_fail (bop->priv, -1);
-       g_return_val_if_fail (GDA_IS_CONNECTION (bop->priv->cnc), -1);
+  GdaCapiBlobOpPrivate *priv = gda_capi_blob_op_get_instance_private (bop);
+       g_return_val_if_fail (GDA_IS_CONNECTION (priv->cnc), -1);
        if (offset >= G_MAXINT)
                return -1;
        g_return_val_if_fail (blob, -1);
@@ -190,8 +152,8 @@ gda_capi_blob_op_write (GdaBlobOp *op, GdaBlob *blob, G_GNUC_UNUSED glong offset
 
        g_return_val_if_fail (GDA_IS_CAPI_BLOB_OP (op), -1);
        bop = GDA_CAPI_BLOB_OP (op);
-       g_return_val_if_fail (bop->priv, -1);
-       g_return_val_if_fail (GDA_IS_CONNECTION (bop->priv->cnc), -1);
+  GdaCapiBlobOpPrivate *priv = gda_capi_blob_op_get_instance_private (bop);
+       g_return_val_if_fail (GDA_IS_CONNECTION (priv->cnc), -1);
        g_return_val_if_fail (blob, -1);
 
        if (gda_blob_get_op (blob) && (gda_blob_get_op (blob) != op)) {
diff --git a/providers/skel-implementation/capi/gda-capi-blob-op.h 
b/providers/skel-implementation/capi/gda-capi-blob-op.h
index 8e1ad9b18..dbd2d1fd6 100644
--- a/providers/skel-implementation/capi/gda-capi-blob-op.h
+++ b/providers/skel-implementation/capi/gda-capi-blob-op.h
@@ -29,25 +29,11 @@
 G_BEGIN_DECLS
 
 #define GDA_TYPE_CAPI_BLOB_OP            (gda_capi_blob_op_get_type())
-#define GDA_CAPI_BLOB_OP(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_CAPI_BLOB_OP, 
GdaCapiBlobOp))
-#define GDA_CAPI_BLOB_OP_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_CAPI_BLOB_OP, 
GdaCapiBlobOpClass))
-#define GDA_IS_CAPI_BLOB_OP(obj)         (G_TYPE_CHECK_INSTANCE_TYPE (obj, GDA_TYPE_CAPI_BLOB_OP))
-#define GDA_IS_CAPI_BLOB_OP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDA_TYPE_CAPI_BLOB_OP))
-
-typedef struct _GdaCapiBlobOp        GdaCapiBlobOp;
-typedef struct _GdaCapiBlobOpClass   GdaCapiBlobOpClass;
-typedef struct _GdaCapiBlobOpPrivate GdaCapiBlobOpPrivate;
-
-struct _GdaCapiBlobOp {
-       GdaBlobOp             parent;
-       GdaCapiBlobOpPrivate *priv;
-};
-
+G_DECLARE_DERIVABLE_TYPE(GdaCapiBlobOp, gda_capi_blob_op, GDA, CAPI_BLOB_OP, GdaBlobOp)
 struct _GdaCapiBlobOpClass {
        GdaBlobOpClass        parent_class;
 };
 
-GType         gda_capi_blob_op_get_type     (void) G_GNUC_CONST;
 GdaBlobOp    *gda_capi_blob_op_new          (GdaConnection *cnc);
 
 /* TO_ADD: more convenient API to create a GdaBlobOp with some specific information as argument */


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