[libgda] GdaVproviderHub: ported to G_DECLARE/G_DEFINE
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaVproviderHub: ported to G_DECLARE/G_DEFINE
- Date: Mon, 25 Feb 2019 23:13:28 +0000 (UTC)
commit 59a44c66c1769e019554b5f2bb037501c7ac6a99
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date: Mon Feb 25 12:51:16 2019 -0600
GdaVproviderHub: ported to G_DECLARE/G_DEFINE
libgda/sqlite/gda-sqlite-provider.c | 25 +++---
libgda/sqlite/virtual/gda-vprovider-hub.c | 128 +++---------------------------
libgda/sqlite/virtual/gda-vprovider-hub.h | 15 +---
3 files changed, 24 insertions(+), 144 deletions(-)
---
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 2963d9688..e6169edce 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -269,19 +269,7 @@ typedef struct {
G_DEFINE_TYPE_WITH_CODE (GdaSqliteProvider, gda_sqlite_provider, GDA_TYPE_SERVER_PROVIDER,
G_ADD_PRIVATE (GdaSqliteProvider)
G_IMPLEMENT_INTERFACE (GDA_TYPE_PROVIDER_META, gda_sqlite_provider_meta_iface_init)
- G_IMPLEMENT_INTERFACE (GDA_TYPE_PROVIDER, gda_sqlite_provider_iface_init)
-
- #ifdef HAVE_SQLITE
- GModule *module2;
-
- module2 = find_sqlite_library ("libsqlite3");
- if (module2)
- load_symbols (module2);
- if (s3r == NULL) {
- g_warning (_("Can't find libsqlite3." G_MODULE_SUFFIX " file."));
- }
- #endif
- )
+ G_IMPLEMENT_INTERFACE (GDA_TYPE_PROVIDER, gda_sqlite_provider_iface_init))
/*
@@ -941,6 +929,17 @@ gda_sqlite_provider_class_init (GdaSqliteProviderClass *klass)
GDA_SERVER_PROVIDER_FUNCTIONS_XA,
NULL);
g_object_class_override_property (G_OBJECT_CLASS (klass), PROP_CONNECTION, "connection");
+
+#ifdef HAVE_SQLITE
+ GModule *module2;
+
+ module2 = find_sqlite_library ("libsqlite3");
+ if (module2)
+ load_symbols (module2);
+ if (s3r == NULL) {
+ g_warning (_("Can't find libsqlite3." G_MODULE_SUFFIX " file."));
+ }
+#endif
}
static void
diff --git a/libgda/sqlite/virtual/gda-vprovider-hub.c b/libgda/sqlite/virtual/gda-vprovider-hub.c
index 447517dc8..353d496f5 100644
--- a/libgda/sqlite/virtual/gda-vprovider-hub.c
+++ b/libgda/sqlite/virtual/gda-vprovider-hub.c
@@ -25,28 +25,20 @@
#include <libgda/gda-debug-macros.h>
#include <libgda/gda-server-provider-impl.h>
-struct _GdaVproviderHubPrivate {
+typedef struct {
int foo;
-};
+} GdaVproviderHubPrivate;
/* properties */
enum
{
- PROP_0,
+ PROP_0,
};
static void gda_vprovider_hub_class_init (GdaVproviderHubClass *klass);
-static void gda_vprovider_hub_init (GdaVproviderHub *prov, GdaVproviderHubClass *klass);
-static void gda_vprovider_hub_finalize (GObject *object);
-static void gda_vprovider_hub_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gda_vprovider_hub_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static GObjectClass *parent_class = NULL;
+static void gda_vprovider_hub_init (GdaVproviderHub *prov);
+
+G_DEFINE_TYPE_WITH_PRIVATE (GdaVproviderHub, gda_vprovider_hub, GDA_TYPE_VPROVIDER_DATA_MODEL)
static GdaConnection *gda_vprovider_hub_create_connection (GdaServerProvider *provider);
static gboolean gda_vprovider_hub_close_connection (GdaServerProvider *provider, GdaConnection *cnc);
@@ -95,109 +87,18 @@ gda_vprovider_hub_class_init (GdaVproviderHubClass *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) &hub_base_functions);
-
- object_class->finalize = gda_vprovider_hub_finalize;
-
- /* Properties */
- object_class->set_property = gda_vprovider_hub_set_property;
- object_class->get_property = gda_vprovider_hub_get_property;
}
static void
-gda_vprovider_hub_init (GdaVproviderHub *prov, G_GNUC_UNUSED GdaVproviderHubClass *klass)
-{
- prov->priv = g_new (GdaVproviderHubPrivate, 1);
-}
-
-static void
-gda_vprovider_hub_finalize (GObject *object)
+gda_vprovider_hub_init (GdaVproviderHub *prov)
{
- GdaVproviderHub *prov = (GdaVproviderHub *) object;
-
- g_return_if_fail (GDA_IS_VPROVIDER_HUB (prov));
-
- /* free memory */
- g_free (prov->priv);
- prov->priv = NULL;
-
- /* chain to parent class */
- parent_class->finalize (object);
}
-GType
-gda_vprovider_hub_get_type (void)
-{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0)) {
- static GMutex registering;
- if (type == 0) {
- static GTypeInfo info = {
- sizeof (GdaVproviderHubClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gda_vprovider_hub_class_init,
- NULL, NULL,
- sizeof (GdaVproviderHub),
- 0,
- (GInstanceInitFunc) gda_vprovider_hub_init,
- 0
- };
-
- g_mutex_lock (®istering);
- if (type == 0)
- type = g_type_register_static (GDA_TYPE_VPROVIDER_DATA_MODEL, "GdaVproviderHub",
&info, 0);
- g_mutex_unlock (®istering);
- }
- }
-
- return type;
-}
-
-static void
-gda_vprovider_hub_set_property (GObject *object,
- guint param_id,
- G_GNUC_UNUSED const GValue *value,
- GParamSpec *pspec)
-{
- GdaVproviderHub *prov;
-
- prov = GDA_VPROVIDER_HUB (object);
- if (prov->priv) {
- switch (param_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
- }
-}
-
-static void
-gda_vprovider_hub_get_property (GObject *object,
- guint param_id,
- G_GNUC_UNUSED GValue *value,
- GParamSpec *pspec)
-{
- GdaVproviderHub *prov;
-
- prov = GDA_VPROVIDER_HUB (object);
- if (prov->priv) {
- switch (param_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
- }
-}
-
-
/**
* gda_vprovider_hub_new
*
@@ -226,25 +127,18 @@ gda_vprovider_hub_create_connection (GdaServerProvider *provider)
return cnc;
}
-static void
-cnc_close_foreach_func (GdaConnection *cnc, G_GNUC_UNUSED const gchar *ns, GdaVconnectionHub *hub)
-{
- /*g_print ("---- FOREACH: Removing connection %p ('%s') from HUB\n", cnc, ns);*/
- if (! gda_vconnection_hub_remove (hub, cnc, NULL))
- g_warning ("Internal GdaVproviderHub error");
-}
-
static gboolean
gda_vprovider_hub_close_connection (GdaServerProvider *provider, GdaConnection *cnc)
{
g_return_val_if_fail (GDA_IS_VPROVIDER_HUB (provider), FALSE);
g_return_val_if_fail (GDA_IS_VCONNECTION_HUB (cnc), FALSE);
- gda_vconnection_hub_foreach (GDA_VCONNECTION_HUB (cnc),
- (GdaVConnectionHubFunc) cnc_close_foreach_func, cnc);
+ if (! gda_vconnection_hub_remove (GDA_VCONNECTION_HUB (provider), cnc, NULL)) {
+ g_warning (_("Internal GdaVproviderHub error"));
+ }
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_hub_parent_class,
GDA_SERVER_PROVIDER_FUNCTIONS_BASE);
return parent_functions->close_connection (provider, cnc);
}
diff --git a/libgda/sqlite/virtual/gda-vprovider-hub.h b/libgda/sqlite/virtual/gda-vprovider-hub.h
index ec4202d1e..e0d90027a 100644
--- a/libgda/sqlite/virtual/gda-vprovider-hub.h
+++ b/libgda/sqlite/virtual/gda-vprovider-hub.h
@@ -23,21 +23,10 @@
#include <virtual/gda-vprovider-data-model.h>
#define GDA_TYPE_VPROVIDER_HUB (gda_vprovider_hub_get_type())
-#define GDA_VPROVIDER_HUB(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_VPROVIDER_HUB,
GdaVproviderHub))
-#define GDA_VPROVIDER_HUB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_VPROVIDER_HUB,
GdaVproviderHubClass))
-#define GDA_IS_VPROVIDER_HUB(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GDA_TYPE_VPROVIDER_HUB))
-#define GDA_IS_VPROVIDER_HUB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDA_TYPE_VPROVIDER_HUB))
G_BEGIN_DECLS
-typedef struct _GdaVproviderHub GdaVproviderHub;
-typedef struct _GdaVproviderHubClass GdaVproviderHubClass;
-typedef struct _GdaVproviderHubPrivate GdaVproviderHubPrivate;
-
-struct _GdaVproviderHub {
- GdaVproviderDataModel parent;
- GdaVproviderHubPrivate *priv;
-};
+G_DECLARE_DERIVABLE_TYPE (GdaVproviderHub, gda_vprovider_hub, GDA, VPROVIDER_HUB, GdaVproviderDataModel)
struct _GdaVproviderHubClass {
GdaVproviderDataModelClass parent_class;
@@ -65,8 +54,6 @@ struct _GdaVproviderHubClass {
* will generate a #GdaVconnectionHub connection object, from which connections can be added.
*/
-
-GType gda_vprovider_hub_get_type (void) G_GNUC_CONST;
GdaVirtualProvider *gda_vprovider_hub_new (void);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]