[libgda] GdaVirtualConnection: ported to G_DECLARE/G_DEFINE
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaVirtualConnection: ported to G_DECLARE/G_DEFINE
- Date: Mon, 25 Feb 2019 23:13:38 +0000 (UTC)
commit 6d0613662122076bb7413618e269eaaf6de42a8e
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date: Mon Feb 25 14:31:11 2019 -0600
GdaVirtualConnection: ported to G_DECLARE/G_DEFINE
libgda/sqlite/virtual/gda-virtual-connection.c | 97 ++++++++++----------------
libgda/sqlite/virtual/gda-virtual-connection.h | 13 +---
libgda/sqlite/virtual/gda-vprovider-hub.c | 2 -
3 files changed, 36 insertions(+), 76 deletions(-)
---
diff --git a/libgda/sqlite/virtual/gda-virtual-connection.c b/libgda/sqlite/virtual/gda-virtual-connection.c
index 36c645187..e0c8f5bd5 100644
--- a/libgda/sqlite/virtual/gda-virtual-connection.c
+++ b/libgda/sqlite/virtual/gda-virtual-connection.c
@@ -27,20 +27,14 @@
#include <libgda/gda-connection-internal.h>
#include <libgda/gda-debug-macros.h>
-#define PARENT_TYPE GDA_TYPE_CONNECTION
-#define CLASS(obj) (GDA_VIRTUAL_CONNECTION_CLASS (G_OBJECT_GET_CLASS (obj)))
-#define PROV_CLASS(provider) (GDA_SERVER_PROVIDER_CLASS (G_OBJECT_GET_CLASS (provider)))
+static void gda_virtual_connection_finalize (GObject *object);
-struct _GdaVirtualConnectionPrivate {
+typedef struct {
gpointer v_provider_data;
- GDestroyNotify v_provider_data_destroy_func;
-};
-
+ GDestroyNotify v_provider_data_destroy_func;
+} GdaVirtualConnectionPrivate;
-static void gda_virtual_connection_class_init (GdaVirtualConnectionClass *klass);
-static void gda_virtual_connection_init (GdaVirtualConnection *vcnc, GdaVirtualConnectionClass *klass);
-static void gda_virtual_connection_finalize (GObject *object);
-static GObjectClass *parent_class = NULL;
+G_DEFINE_TYPE_WITH_PRIVATE (GdaVirtualConnection, gda_virtual_connection, GDA_TYPE_CONNECTION)
/*
* GdaVirtualConnection class implementation
@@ -48,12 +42,13 @@ static GObjectClass *parent_class = NULL;
static void
conn_closed_cb (GdaVirtualConnection *vcnc)
{
- if (vcnc->priv->v_provider_data) {
- if (vcnc->priv->v_provider_data_destroy_func)
- vcnc->priv->v_provider_data_destroy_func (vcnc->priv->v_provider_data);
+ GdaVirtualConnectionPrivate *priv = gda_virtual_connection_get_instance_private (vcnc);
+ if (priv->v_provider_data) {
+ if (priv->v_provider_data_destroy_func)
+ priv->v_provider_data_destroy_func (priv->v_provider_data);
else
g_warning ("Provider did not clean its connection data");
- vcnc->priv->v_provider_data = NULL;
+ priv->v_provider_data = NULL;
}
}
@@ -62,19 +57,17 @@ gda_virtual_connection_class_init (GdaVirtualConnectionClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
/* virtual methods */
object_class->finalize = gda_virtual_connection_finalize;
GDA_CONNECTION_CLASS (klass)->closed = (void (*) (GdaConnection*)) conn_closed_cb;
}
static void
-gda_virtual_connection_init (GdaVirtualConnection *vcnc, G_GNUC_UNUSED GdaVirtualConnectionClass *klass)
+gda_virtual_connection_init (GdaVirtualConnection *vcnc)
{
- vcnc->priv = g_new0 (GdaVirtualConnectionPrivate, 1);
- vcnc->priv->v_provider_data = NULL;
- vcnc->priv->v_provider_data_destroy_func = NULL;
+ GdaVirtualConnectionPrivate *priv = gda_virtual_connection_get_instance_private (vcnc);
+ priv->v_provider_data = NULL;
+ priv->v_provider_data_destroy_func = NULL;
}
static void
@@ -83,41 +76,19 @@ gda_virtual_connection_finalize (GObject *object)
GdaVirtualConnection *vcnc = (GdaVirtualConnection *) object;
g_return_if_fail (GDA_IS_VIRTUAL_CONNECTION (vcnc));
-
- /* free memory */
- g_free (vcnc->priv);
- vcnc->priv = NULL;
-
- /* chain to parent class */
- parent_class->finalize (object);
-}
-
-GType
-gda_virtual_connection_get_type (void)
-{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0)) {
- static GMutex registering;
- static GTypeInfo info = {
- sizeof (GdaVirtualConnectionClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gda_virtual_connection_class_init,
- NULL, NULL,
- sizeof (GdaVirtualConnection),
- 0,
- (GInstanceInitFunc) gda_virtual_connection_init,
- 0
- };
-
- g_mutex_lock (®istering);
- if (type == 0)
- type = g_type_register_static (PARENT_TYPE, "GdaVirtualConnection", &info,
G_TYPE_FLAG_ABSTRACT);
- g_mutex_unlock (®istering);
+ GdaVirtualConnectionPrivate *priv = gda_virtual_connection_get_instance_private (vcnc);
+
+ if (priv->v_provider_data) {
+ if (priv->v_provider_data_destroy_func)
+ priv->v_provider_data_destroy_func (priv->v_provider_data);
+ else
+ g_warning (_("Provider did not clean its connection data"));
+ priv->v_provider_data = NULL;
+ priv->v_provider_data_destroy_func = NULL;
}
- return type;
+ /* chain to parent class */
+ G_OBJECT_CLASS (gda_virtual_connection_parent_class)->finalize (object);
}
/**
@@ -138,9 +109,9 @@ gda_virtual_connection_open (GdaVirtualProvider *virtual_provider, GdaConnection
GdaConnection *cnc = NULL;
cnc = _gda_server_provider_create_connection (GDA_SERVER_PROVIDER (virtual_provider), NULL, NULL,
- NULL, options);
+ NULL, options);
if (!GDA_IS_CONNECTION (cnc)) {
- g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_PROVIDER_ERROR, "%s",
+ g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_PROVIDER_ERROR,
_("Internal error: virtual provider does not implement the create_operation()
virtual method"));
return NULL;
}
@@ -164,9 +135,10 @@ gda_virtual_connection_open (GdaVirtualProvider *virtual_provider, GdaConnection
void
gda_virtual_connection_internal_set_provider_data (GdaVirtualConnection *vcnc, gpointer data, GDestroyNotify
destroy_func)
{
- g_return_if_fail (GDA_IS_VIRTUAL_CONNECTION (vcnc));
- vcnc->priv->v_provider_data = data;
- vcnc->priv->v_provider_data_destroy_func = destroy_func;
+ g_return_if_fail (GDA_IS_VIRTUAL_CONNECTION (vcnc));
+ GdaVirtualConnectionPrivate *priv = gda_virtual_connection_get_instance_private (vcnc);
+ priv->v_provider_data = data;
+ priv->v_provider_data_destroy_func = destroy_func;
}
/**
@@ -182,7 +154,8 @@ gpointer
gda_virtual_connection_internal_get_provider_data (GdaVirtualConnection *vcnc)
{
g_return_val_if_fail (GDA_IS_VIRTUAL_CONNECTION (vcnc), NULL);
- if (! vcnc->priv->v_provider_data)
- gda_connection_add_event_string (GDA_CONNECTION (vcnc), _("Internal error: invalid provider
handle"));
- return vcnc->priv->v_provider_data;
+ GdaVirtualConnectionPrivate *priv = gda_virtual_connection_get_instance_private (vcnc);
+ if (! priv->v_provider_data)
+ gda_connection_add_event_string (GDA_CONNECTION (vcnc), _("Internal error: invalid provider
handle"));
+ return priv->v_provider_data;
}
diff --git a/libgda/sqlite/virtual/gda-virtual-connection.h b/libgda/sqlite/virtual/gda-virtual-connection.h
index 6b321e3a3..730a98df0 100644
--- a/libgda/sqlite/virtual/gda-virtual-connection.h
+++ b/libgda/sqlite/virtual/gda-virtual-connection.h
@@ -24,21 +24,10 @@
#include "gda-virtual-provider.h"
#define GDA_TYPE_VIRTUAL_CONNECTION (gda_virtual_connection_get_type())
-#define GDA_VIRTUAL_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj,
GDA_TYPE_VIRTUAL_CONNECTION, GdaVirtualConnection))
-#define GDA_VIRTUAL_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_VIRTUAL_CONNECTION,
GdaVirtualConnectionClass))
-#define GDA_IS_VIRTUAL_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj,
GDA_TYPE_VIRTUAL_CONNECTION))
-#define GDA_IS_VIRTUAL_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GDA_TYPE_VIRTUAL_CONNECTION))
G_BEGIN_DECLS
-typedef struct _GdaVirtualConnection GdaVirtualConnection;
-typedef struct _GdaVirtualConnectionClass GdaVirtualConnectionClass;
-typedef struct _GdaVirtualConnectionPrivate GdaVirtualConnectionPrivate;
-
-struct _GdaVirtualConnection {
- GdaConnection connection;
- GdaVirtualConnectionPrivate *priv;
-};
+G_DECLARE_DERIVABLE_TYPE (GdaVirtualConnection, gda_virtual_connection, GDA, VIRTUAL_CONNECTION,
GdaConnection)
struct _GdaVirtualConnectionClass {
GdaConnectionClass parent_class;
diff --git a/libgda/sqlite/virtual/gda-vprovider-hub.c b/libgda/sqlite/virtual/gda-vprovider-hub.c
index 353d496f5..ecf302651 100644
--- a/libgda/sqlite/virtual/gda-vprovider-hub.c
+++ b/libgda/sqlite/virtual/gda-vprovider-hub.c
@@ -85,8 +85,6 @@ static GdaServerProviderBase hub_base_functions = {
static void
gda_vprovider_hub_class_init (GdaVproviderHubClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
/* set virtual functions */
gda_server_provider_set_impl_functions (GDA_SERVER_PROVIDER_CLASS (klass),
GDA_SERVER_PROVIDER_FUNCTIONS_BASE,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]