[libgda] GdaMysqlBlobOp: ported to G_DECLARE/G_DEFINE
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaMysqlBlobOp: ported to G_DECLARE/G_DEFINE
- Date: Fri, 5 Apr 2019 22:59:56 +0000 (UTC)
commit 09ab17b838b4eed4894fff5d5008439578eb9252
Author: Daniel Espinosa <esodan gmail com>
Date: Fri Apr 5 10:59:43 2019 -0600
GdaMysqlBlobOp: ported to G_DECLARE/G_DEFINE
providers/mysql/gda-mysql-blob-op.c | 92 ++++++++++++-------------------------
providers/mysql/gda-mysql-blob-op.h | 16 +------
2 files changed, 31 insertions(+), 77 deletions(-)
---
diff --git a/providers/mysql/gda-mysql-blob-op.c b/providers/mysql/gda-mysql-blob-op.c
index a7720524e..d247c706e 100644
--- a/providers/mysql/gda-mysql-blob-op.c
+++ b/providers/mysql/gda-mysql-blob-op.c
@@ -26,59 +26,30 @@
#include <libgda/gda-blob-op-impl.h>
#include <libgda/gda-debug-macros.h>
-struct _GdaMysqlBlobOpPrivate {
- GdaConnection *cnc;
- /* TO_ADD: specific information describing a Blob in the C API */
-};
static void gda_mysql_blob_op_class_init (GdaMysqlBlobOpClass *klass);
-static void gda_mysql_blob_op_init (GdaMysqlBlobOp *blob,
- GdaMysqlBlobOpClass *klass);
-static void gda_mysql_blob_op_finalize (GObject *object);
+static void gda_mysql_blob_op_init (GdaMysqlBlobOp *blob);
+static void gda_mysql_blob_op_dispose (GObject *object);
static glong gda_mysql_blob_op_get_length (GdaBlobOp *op);
static glong gda_mysql_blob_op_read (GdaBlobOp *op, GdaBlob *blob, glong offset, glong size);
static glong gda_mysql_blob_op_write (GdaBlobOp *op, GdaBlob *blob, glong offset);
-static GObjectClass *parent_class = NULL;
-/*
- * Object init and finalize
- */
-GType
-gda_mysql_blob_op_get_type (void)
-{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0)) {
- static GMutex registering;
- static const GTypeInfo info = {
- sizeof (GdaMysqlBlobOpClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gda_mysql_blob_op_class_init,
- NULL,
- NULL,
- sizeof (GdaMysqlBlobOp),
- 0,
- (GInstanceInitFunc) gda_mysql_blob_op_init,
- NULL
- };
- g_mutex_lock (®istering);
- if (type == 0)
- type = g_type_register_static (GDA_TYPE_BLOB_OP, "GdaMysqlBlobOp", &info, 0);
- g_mutex_unlock (®istering);
- }
- return type;
-}
+typedef struct {
+ GdaConnection *cnc;
+ /* TO_ADD: specific information describing a Blob in the C API */
+} GdaMysqlBlobOpPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GdaMysqlBlobOp, gda_mysql_blob_op, GDA_TYPE_BLOB_OP)
+
static void
-gda_mysql_blob_op_init (GdaMysqlBlobOp *op,
- G_GNUC_UNUSED GdaMysqlBlobOpClass *klass)
+gda_mysql_blob_op_init (GdaMysqlBlobOp *op)
{
g_return_if_fail (GDA_IS_MYSQL_BLOB_OP (op));
-
- op->priv = g_new0 (GdaMysqlBlobOpPrivate, 1);
+ GdaMysqlBlobOpPrivate *priv = gda_mysql_blob_op_get_instance_private (op);
+ priv->cnc = NULL;
/* initialize specific structure */
TO_IMPLEMENT;
@@ -90,28 +61,22 @@ gda_mysql_blob_op_class_init (GdaMysqlBlobOpClass *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_mysql_blob_op_finalize;
+ object_class->dispose = gda_mysql_blob_op_dispose;
GDA_BLOB_OP_FUNCTIONS (blob_class->functions)->get_length = gda_mysql_blob_op_get_length;
GDA_BLOB_OP_FUNCTIONS (blob_class->functions)->read = gda_mysql_blob_op_read;
GDA_BLOB_OP_FUNCTIONS (blob_class->functions)->write = gda_mysql_blob_op_write;
}
static void
-gda_mysql_blob_op_finalize (GObject *object)
+gda_mysql_blob_op_dispose (GObject *object)
{
- GdaMysqlBlobOp *pgop = (GdaMysqlBlobOp *) object;
+ GdaMysqlBlobOpPrivate *priv = gda_mysql_blob_op_get_instance_private (GDA_MYSQL_BLOB_OP (object));
+ if (priv->cnc != NULL) {
+ g_object_unref (priv->cnc);
+ priv->cnc = NULL;
+ }
- g_return_if_fail (GDA_IS_MYSQL_BLOB_OP (pgop));
-
- /* free specific information */
- TO_IMPLEMENT;
-
- g_free (pgop->priv);
- pgop->priv = NULL;
-
- parent_class->finalize (object);
+ G_OBJECT_CLASS (gda_mysql_blob_op_parent_class)->finalize (object);
}
GdaBlobOp *
@@ -122,7 +87,10 @@ gda_mysql_blob_op_new (GdaConnection *cnc)
g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
pgop = g_object_new (GDA_TYPE_MYSQL_BLOB_OP, "connection", cnc, NULL);
- pgop->priv->cnc = cnc;
+
+ GdaMysqlBlobOpPrivate *priv = gda_mysql_blob_op_get_instance_private (pgop);
+
+ priv->cnc = g_object_ref (cnc);
return GDA_BLOB_OP (pgop);
}
@@ -137,8 +105,8 @@ gda_mysql_blob_op_get_length (GdaBlobOp *op)
g_return_val_if_fail (GDA_IS_MYSQL_BLOB_OP (op), -1);
pgop = GDA_MYSQL_BLOB_OP (op);
- g_return_val_if_fail (pgop->priv, -1);
- g_return_val_if_fail (GDA_IS_CONNECTION (pgop->priv->cnc), -1);
+ GdaMysqlBlobOpPrivate *priv = gda_mysql_blob_op_get_instance_private (pgop);
+ g_return_val_if_fail (GDA_IS_CONNECTION (priv->cnc), -1);
TO_IMPLEMENT;
return -1;
@@ -157,8 +125,8 @@ gda_mysql_blob_op_read (GdaBlobOp *op,
g_return_val_if_fail (GDA_IS_MYSQL_BLOB_OP (op), -1);
pgop = GDA_MYSQL_BLOB_OP (op);
- g_return_val_if_fail (pgop->priv, -1);
- g_return_val_if_fail (GDA_IS_CONNECTION (pgop->priv->cnc), -1);
+ GdaMysqlBlobOpPrivate *priv = gda_mysql_blob_op_get_instance_private (pgop);
+ g_return_val_if_fail (GDA_IS_CONNECTION (priv->cnc), -1);
if (offset >= G_MAXINT)
return -1;
g_return_val_if_fail (blob, -1);
@@ -182,8 +150,8 @@ gda_mysql_blob_op_write (GdaBlobOp *op,
g_return_val_if_fail (GDA_IS_MYSQL_BLOB_OP (op), -1);
pgop = GDA_MYSQL_BLOB_OP (op);
- g_return_val_if_fail (pgop->priv, -1);
- g_return_val_if_fail (GDA_IS_CONNECTION (pgop->priv->cnc), -1);
+ GdaMysqlBlobOpPrivate *priv = gda_mysql_blob_op_get_instance_private (pgop);
+ g_return_val_if_fail (GDA_IS_CONNECTION (priv->cnc), -1);
g_return_val_if_fail (blob, -1);
/* write blob using bin->data and bin->binary_length */
diff --git a/providers/mysql/gda-mysql-blob-op.h b/providers/mysql/gda-mysql-blob-op.h
index 5c4645ca8..7facce659 100644
--- a/providers/mysql/gda-mysql-blob-op.h
+++ b/providers/mysql/gda-mysql-blob-op.h
@@ -25,25 +25,11 @@
G_BEGIN_DECLS
#define GDA_TYPE_MYSQL_BLOB_OP (gda_mysql_blob_op_get_type())
-#define GDA_MYSQL_BLOB_OP(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_MYSQL_BLOB_OP,
GdaMysqlBlobOp))
-#define GDA_MYSQL_BLOB_OP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_MYSQL_BLOB_OP,
GdaMysqlBlobOpClass))
-#define GDA_IS_MYSQL_BLOB_OP(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GDA_TYPE_MYSQL_BLOB_OP))
-#define GDA_IS_MYSQL_BLOB_OP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDA_TYPE_MYSQL_BLOB_OP))
-
-typedef struct _GdaMysqlBlobOp GdaMysqlBlobOp;
-typedef struct _GdaMysqlBlobOpClass GdaMysqlBlobOpClass;
-typedef struct _GdaMysqlBlobOpPrivate GdaMysqlBlobOpPrivate;
-
-struct _GdaMysqlBlobOp {
- GdaBlobOp parent;
- GdaMysqlBlobOpPrivate *priv;
-};
-
+G_DECLARE_DERIVABLE_TYPE(GdaMysqlBlobOp, gda_mysql_blob_op, GDA, MYSQL_BLOB_OP, GdaBlobOp)
struct _GdaMysqlBlobOpClass {
GdaBlobOpClass parent_class;
};
-GType gda_mysql_blob_op_get_type (void) G_GNUC_CONST;
GdaBlobOp *gda_mysql_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]