[gnome-session] client: Modernise GObject private data handling
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] client: Modernise GObject private data handling
- Date: Fri, 10 Dec 2021 14:53:56 +0000 (UTC)
commit 6b6871a7cd6e89136ddc54cfae9841474ce985e9
Author: Philip Withnall <pwithnall endlessos org>
Date: Mon Nov 15 11:42:02 2021 +0000
client: Modernise GObject private data handling
Use `G_DECLARE_DERIVABLE_TYPE` and
`G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE`.
This introduces no functional changes, but removes a few GLib
deprecation warnings.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
gnome-session/gsm-client.c | 115 +++++++++++++++++++++++++++------------------
gnome-session/gsm-client.h | 16 +------
2 files changed, 69 insertions(+), 62 deletions(-)
---
diff --git a/gnome-session/gsm-client.c b/gnome-session/gsm-client.c
index f50a86a3..ca1f6ca3 100644
--- a/gnome-session/gsm-client.c
+++ b/gnome-session/gsm-client.c
@@ -24,9 +24,7 @@
static guint32 client_serial = 1;
-#define GSM_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSM_TYPE_CLIENT, GsmClientPrivate))
-
-struct GsmClientPrivate
+typedef struct
{
char *id;
char *startup_id;
@@ -34,7 +32,7 @@ struct GsmClientPrivate
guint status;
GsmExportedClient *skeleton;
GDBusConnection *connection;
-};
+} GsmClientPrivate;
enum {
PROP_0,
@@ -51,7 +49,7 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_ABSTRACT_TYPE (GsmClient, gsm_client, G_TYPE_OBJECT)
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GsmClient, gsm_client, G_TYPE_OBJECT)
#define GSM_CLIENT_DBUS_IFACE "org.gnome.SessionManager.Client"
@@ -91,7 +89,9 @@ gsm_client_get_startup_id (GsmExportedClient *skeleton,
GDBusMethodInvocation *invocation,
GsmClient *client)
{
- gsm_exported_client_complete_get_startup_id (skeleton, invocation, client->priv->startup_id);
+ GsmClientPrivate *priv = gsm_client_get_instance_private (client);
+
+ gsm_exported_client_complete_get_startup_id (skeleton, invocation, priv->startup_id);
return TRUE;
}
@@ -100,7 +100,9 @@ gsm_client_get_app_id (GsmExportedClient *skeleton,
GDBusMethodInvocation *invocation,
GsmClient *client)
{
- gsm_exported_client_complete_get_app_id (skeleton, invocation, client->priv->app_id);
+ GsmClientPrivate *priv = gsm_client_get_instance_private (client);
+
+ gsm_exported_client_complete_get_app_id (skeleton, invocation, priv->app_id);
return TRUE;
}
@@ -121,7 +123,9 @@ gsm_client_get_status (GsmExportedClient *skeleton,
GDBusMethodInvocation *invocation,
GsmClient *client)
{
- gsm_exported_client_complete_get_status (skeleton, invocation, client->priv->status);
+ GsmClientPrivate *priv = gsm_client_get_instance_private (client);
+
+ gsm_exported_client_complete_get_status (skeleton, invocation, priv->status);
return TRUE;
}
@@ -157,22 +161,23 @@ gsm_client_stop_dbus (GsmExportedClient *skeleton,
static gboolean
register_client (GsmClient *client)
{
+ GsmClientPrivate *priv = gsm_client_get_instance_private (client);
GError *error = NULL;
GsmExportedClient *skeleton;
- client->priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
- if (client->priv->connection == NULL) {
+ priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (priv->connection == NULL) {
g_critical ("error getting session bus: %s", error->message);
g_error_free (error);
return FALSE;
}
skeleton = gsm_exported_client_skeleton_new ();
- client->priv->skeleton = skeleton;
- g_debug ("exporting client to object path: %s", client->priv->id);
+ priv->skeleton = skeleton;
+ g_debug ("exporting client to object path: %s", priv->id);
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton),
- client->priv->connection,
- client->priv->id, &error);
+ priv->connection,
+ priv->id, &error);
if (error != NULL) {
g_critical ("error exporting client on session bus: %s", error->message);
@@ -201,15 +206,17 @@ gsm_client_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
+ GsmClientPrivate *priv;
GsmClient *client;
gboolean res;
client = GSM_CLIENT (G_OBJECT_CLASS (gsm_client_parent_class)->constructor (type,
n_construct_properties,
construct_properties));
+ priv = gsm_client_get_instance_private (client);
- g_free (client->priv->id);
- client->priv->id = g_strdup_printf ("/org/gnome/SessionManager/Client%u", get_next_client_serial ());
+ g_free (priv->id);
+ priv->id = g_strdup_printf ("/org/gnome/SessionManager/Client%u", get_next_client_serial ());
res = register_client (client);
if (! res) {
@@ -222,32 +229,33 @@ gsm_client_constructor (GType type,
static void
gsm_client_init (GsmClient *client)
{
- client->priv = GSM_CLIENT_GET_PRIVATE (client);
}
static void
gsm_client_finalize (GObject *object)
{
GsmClient *client;
+ GsmClientPrivate *priv;
g_return_if_fail (object != NULL);
g_return_if_fail (GSM_IS_CLIENT (object));
client = GSM_CLIENT (object);
+ priv = gsm_client_get_instance_private (client);
- g_return_if_fail (client->priv != NULL);
+ g_return_if_fail (priv != NULL);
- g_free (client->priv->id);
- g_free (client->priv->startup_id);
- g_free (client->priv->app_id);
+ g_free (priv->id);
+ g_free (priv->startup_id);
+ g_free (priv->app_id);
- if (client->priv->skeleton != NULL) {
- g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON
(client->priv->skeleton),
- client->priv->connection);
- g_clear_object (&client->priv->skeleton);
+ if (priv->skeleton != NULL) {
+ g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON
(priv->skeleton),
+ priv->connection);
+ g_clear_object (&priv->skeleton);
}
- g_clear_object (&client->priv->connection);
+ g_clear_object (&priv->connection);
G_OBJECT_CLASS (gsm_client_parent_class)->finalize (object);
}
@@ -256,9 +264,11 @@ void
gsm_client_set_status (GsmClient *client,
guint status)
{
+ GsmClientPrivate *priv = gsm_client_get_instance_private (client);
+
g_return_if_fail (GSM_IS_CLIENT (client));
- if (client->priv->status != status) {
- client->priv->status = status;
+ if (priv->status != status) {
+ priv->status = status;
g_object_notify (G_OBJECT (client), "status");
}
}
@@ -267,14 +277,16 @@ static void
gsm_client_set_startup_id (GsmClient *client,
const char *startup_id)
{
+ GsmClientPrivate *priv = gsm_client_get_instance_private (client);
+
g_return_if_fail (GSM_IS_CLIENT (client));
- g_free (client->priv->startup_id);
+ g_free (priv->startup_id);
if (startup_id != NULL) {
- client->priv->startup_id = g_strdup (startup_id);
+ priv->startup_id = g_strdup (startup_id);
} else {
- client->priv->startup_id = g_strdup ("");
+ priv->startup_id = g_strdup ("");
}
g_object_notify (G_OBJECT (client), "startup-id");
}
@@ -283,14 +295,16 @@ void
gsm_client_set_app_id (GsmClient *client,
const char *app_id)
{
+ GsmClientPrivate *priv = gsm_client_get_instance_private (client);
+
g_return_if_fail (GSM_IS_CLIENT (client));
- g_free (client->priv->app_id);
+ g_free (priv->app_id);
if (app_id != NULL) {
- client->priv->app_id = g_strdup (app_id);
+ priv->app_id = g_strdup (app_id);
} else {
- client->priv->app_id = g_strdup ("");
+ priv->app_id = g_strdup ("");
}
g_object_notify (G_OBJECT (client), "app-id");
}
@@ -327,19 +341,18 @@ gsm_client_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GsmClient *self;
-
- self = GSM_CLIENT (object);
+ GsmClient *self = GSM_CLIENT (object);
+ GsmClientPrivate *priv = gsm_client_get_instance_private (self);
switch (prop_id) {
case PROP_STARTUP_ID:
- g_value_set_string (value, self->priv->startup_id);
+ g_value_set_string (value, priv->startup_id);
break;
case PROP_APP_ID:
- g_value_set_string (value, self->priv->app_id);
+ g_value_set_string (value, priv->app_id);
break;
case PROP_STATUS:
- g_value_set_uint (value, self->priv->status);
+ g_value_set_uint (value, priv->status);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -362,13 +375,15 @@ static void
gsm_client_dispose (GObject *object)
{
GsmClient *client;
+ GsmClientPrivate *priv;
g_return_if_fail (object != NULL);
g_return_if_fail (GSM_IS_CLIENT (object));
client = GSM_CLIENT (object);
+ priv = gsm_client_get_instance_private (client);
- g_debug ("GsmClient: disposing %s", client->priv->id);
+ g_debug ("GsmClient: disposing %s", priv->id);
G_OBJECT_CLASS (gsm_client_parent_class)->dispose (object);
}
@@ -426,16 +441,16 @@ gsm_client_class_init (GsmClientClass *klass)
G_MAXINT,
GSM_CLIENT_UNREGISTERED,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
- g_type_class_add_private (klass, sizeof (GsmClientPrivate));
}
const char *
gsm_client_peek_id (GsmClient *client)
{
+ GsmClientPrivate *priv = gsm_client_get_instance_private (client);
+
g_return_val_if_fail (GSM_IS_CLIENT (client), NULL);
- return client->priv->id;
+ return priv->id;
}
/**
@@ -451,25 +466,31 @@ gsm_client_peek_id (GsmClient *client)
const char *
gsm_client_peek_app_id (GsmClient *client)
{
+ GsmClientPrivate *priv = gsm_client_get_instance_private (client);
+
g_return_val_if_fail (GSM_IS_CLIENT (client), NULL);
- return client->priv->app_id;
+ return priv->app_id;
}
const char *
gsm_client_peek_startup_id (GsmClient *client)
{
+ GsmClientPrivate *priv = gsm_client_get_instance_private (client);
+
g_return_val_if_fail (GSM_IS_CLIENT (client), NULL);
- return client->priv->startup_id;
+ return priv->startup_id;
}
guint
gsm_client_peek_status (GsmClient *client)
{
+ GsmClientPrivate *priv = gsm_client_get_instance_private (client);
+
g_return_val_if_fail (GSM_IS_CLIENT (client), GSM_CLIENT_UNREGISTERED);
- return client->priv->status;
+ return priv->status;
}
guint
diff --git a/gnome-session/gsm-client.h b/gnome-session/gsm-client.h
index 78cb15d8..d3feba90 100644
--- a/gnome-session/gsm-client.h
+++ b/gnome-session/gsm-client.h
@@ -27,18 +27,12 @@
G_BEGIN_DECLS
#define GSM_TYPE_CLIENT (gsm_client_get_type ())
-#define GSM_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSM_TYPE_CLIENT, GsmClient))
-#define GSM_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSM_TYPE_CLIENT, GsmClientClass))
-#define GSM_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSM_TYPE_CLIENT))
-#define GSM_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSM_TYPE_CLIENT))
-#define GSM_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSM_TYPE_CLIENT, GsmClientClass))
+G_DECLARE_DERIVABLE_TYPE (GsmClient, gsm_client, GSM, CLIENT, GObject)
typedef struct _GsmApp GsmApp;
typedef struct _GsmClient GsmClient;
typedef struct _GsmClientClass GsmClientClass;
-typedef struct GsmClientPrivate GsmClientPrivate;
-
typedef enum {
GSM_CLIENT_UNREGISTERED = 0,
GSM_CLIENT_REGISTERED,
@@ -59,12 +53,6 @@ typedef enum {
GSM_CLIENT_END_SESSION_FLAG_LAST = 1 << 2
} GsmClientEndSessionFlag;
-struct _GsmClient
-{
- GObject parent;
- GsmClientPrivate *priv;
-};
-
struct _GsmClientClass
{
GObjectClass parent_class;
@@ -106,8 +94,6 @@ typedef enum
#define GSM_CLIENT_ERROR gsm_client_error_quark ()
GQuark gsm_client_error_quark (void);
-GType gsm_client_get_type (void) G_GNUC_CONST;
-
const char *gsm_client_peek_id (GsmClient *client);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]