[libgda: 1/15] GI: GdaConnection modernized
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda: 1/15] GI: GdaConnection modernized
- Date: Fri, 11 Jan 2019 19:48:31 +0000 (UTC)
commit ad3d3e5264dfdc5017d85461e69c6343b7c0976d
Author: Pavlo Solntsev <p sun fun gmail com>
Date: Wed Jan 2 12:12:53 2019 -0600
GI: GdaConnection modernized
G_DECLARE and G_DEFINE macroses used for GdaConnection
static code warning were removed by changing paths for included files.
libgda/gda-connection.c | 85 ++++++++++---------------------------------------
libgda/gda-connection.h | 11 ++-----
2 files changed, 19 insertions(+), 77 deletions(-)
---
diff --git a/libgda/gda-connection.c b/libgda/gda-connection.c
index 8d0ed1e65..bddd10cd5 100644
--- a/libgda/gda-connection.c
+++ b/libgda/gda-connection.c
@@ -60,17 +60,17 @@
#include <libgda/gda-enum-types.h>
#include <libgda/gda-holder.h>
#include <libgda/gda-set.h>
-#include <sql-parser/gda-sql-parser.h>
-#include <sql-parser/gda-statement-struct-trans.h>
+#include <libgda/sql-parser/gda-sql-parser.h>
+#include <libgda/sql-parser/gda-statement-struct-trans.h>
#include <libgda/gda-meta-store-extra.h>
#include <libgda/gda-util.h>
#include <libgda/gda-lockable.h>
#include <libgda/gda-repetitive-statement.h>
-#include <gda-statement-priv.h>
-#include <sqlite/virtual/gda-vconnection-data-model.h>
+#include "gda-statement-priv.h"
+#include <libgda/sqlite/virtual/gda-vconnection-data-model.h>
#include <libgda/gda-debug-macros.h>
#include <libgda/gda-data-handler.h>
-#include <thread-wrapper/itsignaler.h>
+#include <libgda/thread-wrapper/itsignaler.h>
#include <libgda/gda-marshal.h>
#include <glib/gstdio.h>
@@ -82,6 +82,12 @@ static GMutex global_mutex;
static GdaSqlParser *internal_parser = NULL;
static GHashTable *all_context_hash = NULL; /* key = a #GThread, value = a #GMainContext (ref held) */
+/* GdaLockable interface */
+static void gda_connection_lockable_init (GdaLockableInterface *iface);
+static void gda_connection_lock (GdaLockable *lockable);
+static gboolean gda_connection_trylock (GdaLockable *lockable);
+static void gda_connection_unlock (GdaLockable *lockable);
+
/* number of GdaConnectionEvent kept by each connection. Should be enough to avoid losing any
* event, considering that the events are reseted after each statement execution */
#define EVENTS_ARRAY_SIZE 5
@@ -123,7 +129,10 @@ typedef struct {
guint exec_slowdown;
} GdaConnectionPrivate;
-#define gda_connection_get_instance_private(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, GDA_TYPE_CONNECTION,
GdaConnectionPrivate)
+G_DEFINE_TYPE_WITH_CODE (GdaConnection, gda_connection, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (GDA_TYPE_LOCKABLE, gda_connection_lockable_init)
+ G_ADD_PRIVATE (GdaConnection))
+
static void add_exec_time_to_object (GObject *obj, GTimer *timer);
@@ -140,11 +149,6 @@ static void gda_connection_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
-/* GdaLockable interface */
-static void gda_connection_lockable_init (GdaLockableInterface *iface);
-static void gda_connection_lock (GdaLockable *lockable);
-static gboolean gda_connection_trylock (GdaLockable *lockable);
-static void gda_connection_unlock (GdaLockable *lockable);
static void update_meta_store_after_statement_exec (GdaConnection *cnc, GdaStatement *stmt, GdaSet *params);
static void change_events_array_max_size (GdaConnection *cnc, gint size);
@@ -176,7 +180,6 @@ enum
PROP_EXEC_SLOWDOWN
};
-static GObjectClass *parent_class = NULL;
extern GdaServerProvider *_gda_config_sqlite_provider; /* defined in gda-config.c */
static gint debug_level = -1;
@@ -219,9 +222,6 @@ gda_connection_class_init (GdaConnectionClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
- g_type_class_add_private (object_class, sizeof (GdaConnectionPrivate));
/**
* GdaConnection::error:
* @cnc: the #GdaConnection
@@ -537,7 +537,7 @@ gda_connection_dispose (GObject *object)
}
/* chain to parent class */
- parent_class->dispose (object);
+ G_OBJECT_CLASS (gda_connection_parent_class)->dispose (object);
}
static void
@@ -556,7 +556,7 @@ gda_connection_finalize (GObject *object)
g_rec_mutex_clear (&priv->rmutex);
/* chain to parent class */
- parent_class->finalize (object);
+ G_OBJECT_CLASS (gda_connection_parent_class)->finalize (object);
}
/* module error */
@@ -568,49 +568,6 @@ GQuark gda_connection_error_quark (void)
return quark;
}
-/**
- * gda_connection_get_type:
- *
- * Registers the #GdaConnection class on the GLib type system.
- *
- * Returns: the GType identifying the class.
- */
-GType
-gda_connection_get_type (void)
-{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0)) {
- static GMutex registering;
- static GTypeInfo info = {
- sizeof (GdaConnectionClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gda_connection_class_init,
- NULL, NULL,
- sizeof (GdaConnection),
- 0,
- (GInstanceInitFunc) gda_connection_init,
- 0
- };
-
- static GInterfaceInfo lockable_info = {
- (GInterfaceInitFunc) gda_connection_lockable_init,
- NULL,
- NULL
- };
-
- g_mutex_lock (®istering);
- if (type == 0) {
- type = g_type_register_static (G_TYPE_OBJECT, "GdaConnection", &info, 0);
- g_type_add_interface_static (type, GDA_TYPE_LOCKABLE, &lockable_info);
- }
- g_mutex_unlock (®istering);
- }
-
- return type;
-}
-
static void
gda_connection_set_property (GObject *object,
guint param_id,
@@ -5854,14 +5811,6 @@ prepared_stmts_stmt_reset_cb (GdaStatement *gda_stmt, GdaConnection *cnc)
gda_connection_unlock ((GdaLockable*) cnc);
}
-static void
-prepared_stms_foreach_func (GdaStatement *gda_stmt, G_GNUC_UNUSED GdaPStmt *prepared_stmt, GdaConnection
*cnc)
-{
- g_object_ref (gda_stmt);
- g_signal_handlers_disconnect_by_func (gda_stmt, G_CALLBACK (prepared_stmts_stmt_reset_cb), cnc);
- g_object_unref (gda_stmt);
-}
-
typedef struct {
GdaStatement *statement;
GdaPStmt *prepared_stmt;
diff --git a/libgda/gda-connection.h b/libgda/gda-connection.h
index fe0d0a7e1..66a4c6f3b 100644
--- a/libgda/gda-connection.h
+++ b/libgda/gda-connection.h
@@ -46,10 +46,8 @@
G_BEGIN_DECLS
#define GDA_TYPE_CONNECTION (gda_connection_get_type())
-#define GDA_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_CONNECTION, GdaConnection))
-#define GDA_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_CONNECTION,
GdaConnectionClass))
-#define GDA_IS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE(obj, GDA_TYPE_CONNECTION))
-#define GDA_IS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GDA_TYPE_CONNECTION))
+
+G_DECLARE_DERIVABLE_TYPE (GdaConnection, gda_connection, GDA,CONNECTION, GObject)
/* error reporting */
extern GQuark gda_connection_error_quark (void);
@@ -98,10 +96,6 @@ typedef enum {
* lock on the connection is being acquired.
*/
-struct _GdaConnection {
- GObject object;
-};
-
/**
* GdaConnectionStatus:
* @GDA_CONNECTION_STATUS_CLOSED: the connection is closed (default status upon creation)
@@ -264,7 +258,6 @@ typedef enum {
} GdaConnectionMetaType;
-GType gda_connection_get_type (void) G_GNUC_CONST;
GdaConnection *gda_connection_open_from_dsn (const gchar *dsn, const gchar *auth_string,
GdaConnectionOptions options, GError **error);
GdaConnection *gda_connection_open_from_string (const gchar *provider_name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]