[libgda] gda-connection-event: ported to G_DECLARE/G_DEFINE



commit 64527012023b3e490c5467fa637b49ef362db17c
Author: Daniel Espinosa <esodan gmail com>
Date:   Tue Sep 11 08:46:47 2018 -0500

    gda-connection-event: ported to G_DECLARE/G_DEFINE

 libgda/gda-connection-event.c | 58 +++++++++++--------------------------------
 libgda/gda-connection-event.h | 18 ++------------
 2 files changed, 17 insertions(+), 59 deletions(-)
---
diff --git a/libgda/gda-connection-event.c b/libgda/gda-connection-event.c
index f37b68c87..0590f754a 100644
--- a/libgda/gda-connection-event.c
+++ b/libgda/gda-connection-event.c
@@ -30,7 +30,6 @@ typedef struct {
        gchar                  *sqlstate;
        GdaConnectionEventType  type; /* default is GDA_CONNECTION_EVENT_ERROR */
 } GdaConnectionEventPrivate;
-#define gda_connection_event_get_instance_private(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, 
GDA_TYPE_CONNECTION_EVENT, GdaConnectionEventPrivate)
 
 enum {
        PROP_0,
@@ -38,56 +37,23 @@ enum {
        PROP_TYPE
 };
 
-static void gda_connection_event_class_init   (GdaConnectionEventClass *klass);
-static void gda_connection_event_init         (GdaConnectionEvent *event, GdaConnectionEventClass *klass);
-static void gda_connection_event_finalize     (GObject *object);
+static void gda_connection_event_dispose      (GObject *object);
 static void gda_connection_event_set_property (GObject *object, guint prop_id, const GValue *value, 
GParamSpec *pspec);
 static void gda_connection_event_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec 
*pspec);
 
-static GObjectClass *parent_class = NULL;
-
 /*
  * GdaConnectionEvent class implementation
  */
 
-GType
-gda_connection_event_get_type (void)
-{
-       static GType type = 0;
-
-       if (G_UNLIKELY (type == 0)) {
-               static GMutex registering;
-               static const GTypeInfo info = {
-                       sizeof (GdaConnectionEventClass),
-                       (GBaseInitFunc) NULL,
-                       (GBaseFinalizeFunc) NULL,
-                       (GClassInitFunc) gda_connection_event_class_init,
-                       NULL,
-                       NULL,
-                       sizeof (GdaConnectionEvent),
-                       0,
-                       (GInstanceInitFunc) gda_connection_event_init,
-                       0
-               };
-               g_mutex_lock (&registering);
-               if (type == 0)
-                       type = g_type_register_static (G_TYPE_OBJECT, "GdaConnectionEvent", &info, 0);
-               g_mutex_unlock (&registering);
-       }
+G_DEFINE_TYPE_WITH_PRIVATE (GdaConnectionEvent, gda_connection_event, G_TYPE_OBJECT)
 
-       return type;
-}
 
 static void
 gda_connection_event_class_init (GdaConnectionEventClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-       parent_class = g_type_class_peek_parent (klass);
-
-       g_type_class_add_private (object_class, sizeof (GdaConnectionEventPrivate));
-
-       object_class->finalize = gda_connection_event_finalize;
+       object_class->dispose = gda_connection_event_dispose;
        object_class->set_property = gda_connection_event_set_property;
        object_class->get_property = gda_connection_event_get_property;
 
@@ -103,7 +69,7 @@ gda_connection_event_class_init (GdaConnectionEventClass *klass)
 }
 
 static void
-gda_connection_event_init (GdaConnectionEvent *event, G_GNUC_UNUSED GdaConnectionEventClass *klass)
+gda_connection_event_init (GdaConnectionEvent *event)
 {
        GdaConnectionEventPrivate *priv = gda_connection_event_get_instance_private (event);
        priv->type = GDA_CONNECTION_EVENT_ERROR;
@@ -111,7 +77,7 @@ gda_connection_event_init (GdaConnectionEvent *event, G_GNUC_UNUSED GdaConnectio
 }
 
 static void
-gda_connection_event_finalize (GObject *object)
+gda_connection_event_dispose (GObject *object)
 {
        GdaConnectionEvent *event = (GdaConnectionEvent *) object;
 
@@ -119,15 +85,21 @@ gda_connection_event_finalize (GObject *object)
        GdaConnectionEventPrivate *priv = gda_connection_event_get_instance_private (event);
 
        /* free memory */
-       if (priv->description)
+       if (priv->description) {
                g_free (priv->description);
-       if (priv->source)
+               priv->description = NULL;
+       }
+       if (priv->source) {
                g_free (priv->source);
-       if (priv->sqlstate)
+               priv->source = NULL;
+       }
+       if (priv->sqlstate) {
                g_free (priv->sqlstate);
+               priv->sqlstate = NULL;
+       }
 
        /* chain to parent class */
-       parent_class->finalize (object);
+       G_OBJECT_CLASS (gda_connection_event_parent_class)->dispose (object);
 }
 
 static void gda_connection_event_set_property (GObject *object, guint prop_id, const GValue *value, 
GParamSpec *pspec)
diff --git a/libgda/gda-connection-event.h b/libgda/gda-connection-event.h
index ce13d6507..c6632fdde 100644
--- a/libgda/gda-connection-event.h
+++ b/libgda/gda-connection-event.h
@@ -26,24 +26,12 @@
 G_BEGIN_DECLS
 
 #define GDA_TYPE_CONNECTION_EVENT            (gda_connection_event_get_type())
-#define GDA_CONNECTION_EVENT(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_CONNECTION_EVENT, 
GdaConnectionEvent))
-#define GDA_CONNECTION_EVENT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_CONNECTION_EVENT, 
GdaConnectionEventClass))
-#define GDA_IS_CONNECTION_EVENT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE(obj, GDA_TYPE_CONNECTION_EVENT))
-#define GDA_IS_CONNECTION_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GDA_TYPE_CONNECTION_EVENT))
-
-struct _GdaConnectionEvent {
-       GObject object;
-};
+G_DECLARE_DERIVABLE_TYPE (GdaConnectionEvent, gda_connection_event, GDA, CONNECTION_EVENT, GObject)
 
 struct _GdaConnectionEventClass {
        GObjectClass parent_class;
 
-       /*< private >*/
-       /* Padding for future expansion */
-       void (*_gda_reserved1) (void);
-       void (*_gda_reserved2) (void);
-       void (*_gda_reserved3) (void);
-       void (*_gda_reserved4) (void);
+       gpointer padding[12];
 };
 
 typedef enum {
@@ -92,8 +80,6 @@ typedef enum
  * gda_connection_get_events() function.
  */
 
-GType                   gda_connection_event_get_type (void) G_GNUC_CONST;
-
 void                    gda_connection_event_set_event_type (GdaConnectionEvent *event, 
GdaConnectionEventType type);
 GdaConnectionEventType  gda_connection_event_get_event_type (GdaConnectionEvent *event);
 


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