[gdm/rhel-7.9: 31/51] libgdm: get connection explicitly
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdm/rhel-7.9: 31/51] libgdm: get connection explicitly
- Date: Mon, 12 Apr 2021 20:58:09 +0000 (UTC)
commit 7c1bc78c1506175636bb49e3ef455cfa10798f94
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Mon May 14 16:32:25 2018 -0400
libgdm: get connection explicitly
At the moment we call gdm_client_open_connection and when it finishes,
assume client->priv->connection is implicitly initialized.
This commit makes the operation more explicit by changing
gdm_client_open_connection to gdm_client_get_connection and returning
the GDBusConnection object directly, instead of returning a boolean.
https://bugzilla.gnome.org/show_bug.cgi?id=795940
libgdm/gdm-client.c | 136 +++++++++++++++++++++++++++++++---------------------
1 file changed, 82 insertions(+), 54 deletions(-)
---
diff --git a/libgdm/gdm-client.c b/libgdm/gdm-client.c
index e02e3ea57..e7b93e382 100644
--- a/libgdm/gdm-client.c
+++ b/libgdm/gdm-client.c
@@ -393,10 +393,10 @@ on_got_manager_for_reauthentication (GdmClient *client,
}
-static gboolean
-gdm_client_open_connection_sync (GdmClient *client,
- GCancellable *cancellable,
- GError **error)
+static GDBusConnection *
+gdm_client_get_connection_sync (GdmClient *client,
+ GCancellable *cancellable,
+ GError **error)
{
g_autoptr(GdmManager) manager = NULL;
gboolean ret;
@@ -404,8 +404,7 @@ gdm_client_open_connection_sync (GdmClient *client,
g_return_val_if_fail (GDM_IS_CLIENT (client), FALSE);
if (client->priv->connection != NULL) {
- g_object_ref (client->priv->connection);
- return TRUE;
+ return g_object_ref (client->priv->connection);
}
manager = gdm_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
@@ -446,7 +445,7 @@ gdm_client_open_connection_sync (GdmClient *client,
&client->priv->connection);
out:
- return client->priv->connection != NULL;
+ return client->priv->connection;
}
static void
@@ -530,33 +529,31 @@ on_got_manager_for_opening_connection (GdmClient *client,
task);
}
-static gboolean
-gdm_client_open_connection_finish (GdmClient *client,
- GAsyncResult *result,
- GError **error)
+static GDBusConnection *
+gdm_client_get_connection_finish (GdmClient *client,
+ GAsyncResult *result,
+ GError **error)
{
- g_autoptr(GDBusConnection) connection = NULL;
+ GDBusConnection *connection = NULL;
g_return_val_if_fail (GDM_IS_CLIENT (client), FALSE);
connection = g_task_propagate_pointer (G_TASK (result), error);
if (connection == NULL) {
- return FALSE;
+ return NULL;
}
if (client->priv->connection == NULL) {
- client->priv->connection = g_steal_pointer (&connection);
+ client->priv->connection = connection;
g_object_add_weak_pointer (G_OBJECT (client->priv->connection),
(gpointer *) &client->priv->connection);
- } else if (client->priv->connection == connection) {
- connection = NULL;
}
- return TRUE;
+ return g_object_ref (connection);
}
static void
-gdm_client_open_connection (GdmClient *client,
+gdm_client_get_connection (GdmClient *client,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -743,15 +740,19 @@ gdm_client_get_user_verifier_sync (GdmClient *client,
GCancellable *cancellable,
GError **error)
{
+ g_autoptr(GDBusConnection) connection = NULL;
+
if (client->priv->user_verifier != NULL) {
return g_object_ref (client->priv->user_verifier);
}
- if (!gdm_client_open_connection_sync (client, cancellable, error)) {
+ connection = gdm_client_get_connection_sync (client, cancellable, error);
+
+ if (connection == NULL) {
return NULL;
}
- client->priv->user_verifier = gdm_user_verifier_proxy_new_sync (client->priv->connection,
+ client->priv->user_verifier = gdm_user_verifier_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
@@ -762,6 +763,7 @@ gdm_client_get_user_verifier_sync (GdmClient *client,
g_object_add_weak_pointer (G_OBJECT (client->priv->user_verifier),
(gpointer *)
&client->priv->user_verifier);
+ g_object_ref (connection);
g_object_weak_ref (G_OBJECT (client->priv->user_verifier),
(GWeakNotify)
g_object_unref,
@@ -805,22 +807,25 @@ gdm_client_get_user_verifier_sync (GdmClient *client,
}
static void
-on_connection_opened_for_user_verifier (GdmClient *client,
- GAsyncResult *result,
- GTask *task)
+on_connection_for_user_verifier (GdmClient *client,
+ GAsyncResult *result,
+ GTask *task)
{
+ g_autoptr(GDBusConnection) connection = NULL;
GCancellable *cancellable;
GError *error;
error = NULL;
- if (!gdm_client_open_connection_finish (client, result, &error)) {
+ connection = gdm_client_get_connection_finish (client, result, &error);
+
+ if (connection == NULL) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
cancellable = g_task_get_cancellable (task);
- gdm_user_verifier_proxy_new (client->priv->connection,
+ gdm_user_verifier_proxy_new (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
@@ -863,10 +868,10 @@ gdm_client_get_user_verifier (GdmClient *client,
return;
}
- gdm_client_open_connection (client,
+ gdm_client_get_connection (client,
cancellable,
(GAsyncReadyCallback)
- on_connection_opened_for_user_verifier,
+ on_connection_for_user_verifier,
task);
}
@@ -975,22 +980,25 @@ on_greeter_proxy_created (GObject *source,
}
static void
-on_connection_opened_for_greeter (GdmClient *client,
- GAsyncResult *result,
- GTask *task)
+on_connection_for_greeter (GdmClient *client,
+ GAsyncResult *result,
+ GTask *task)
{
+ g_autoptr(GDBusConnection) connection = NULL;
GCancellable *cancellable;
GError *error;
error = NULL;
- if (!gdm_client_open_connection_finish (client, result, &error)) {
+ connection = gdm_client_get_connection_finish (client, result, &error);
+
+ if (connection == NULL) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
cancellable = g_task_get_cancellable (task);
- gdm_greeter_proxy_new (client->priv->connection,
+ gdm_greeter_proxy_new (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
@@ -1033,10 +1041,10 @@ gdm_client_get_greeter (GdmClient *client,
return;
}
- gdm_client_open_connection (client,
+ gdm_client_get_connection (client,
cancellable,
(GAsyncReadyCallback)
- on_connection_opened_for_greeter,
+ on_connection_for_greeter,
task);
}
@@ -1098,15 +1106,19 @@ gdm_client_get_greeter_sync (GdmClient *client,
GCancellable *cancellable,
GError **error)
{
+ g_autoptr(GDBusConnection) connection = NULL;
+
if (client->priv->greeter != NULL) {
return g_object_ref (client->priv->greeter);
}
- if (!gdm_client_open_connection_sync (client, cancellable, error)) {
+ connection = gdm_client_get_connection_sync (client, cancellable, error);
+
+ if (connection == NULL) {
return NULL;
}
- client->priv->greeter = gdm_greeter_proxy_new_sync (client->priv->connection,
+ client->priv->greeter = gdm_greeter_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
@@ -1150,22 +1162,25 @@ on_remote_greeter_proxy_created (GObject *object,
}
static void
-on_connection_opened_for_remote_greeter (GdmClient *client,
- GAsyncResult *result,
- GTask *task)
+on_connection_for_remote_greeter (GdmClient *client,
+ GAsyncResult *result,
+ GTask *task)
{
+ g_autoptr(GDBusConnection) connection = NULL;
GCancellable *cancellable;
GError *error;
error = NULL;
- if (!gdm_client_open_connection_finish (client, result, &error)) {
+ connection = gdm_client_get_connection_finish (client, result, &error);
+
+ if (connection == NULL) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
cancellable = g_task_get_cancellable (task);
- gdm_remote_greeter_proxy_new (client->priv->connection,
+ gdm_remote_greeter_proxy_new (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
@@ -1208,10 +1223,10 @@ gdm_client_get_remote_greeter (GdmClient *client,
return;
}
- gdm_client_open_connection (client,
+ gdm_client_get_connection (client,
cancellable,
(GAsyncReadyCallback)
- on_connection_opened_for_remote_greeter,
+ on_connection_for_remote_greeter,
task);
}
@@ -1273,15 +1288,19 @@ gdm_client_get_remote_greeter_sync (GdmClient *client,
GCancellable *cancellable,
GError **error)
{
+ g_autoptr(GDBusConnection) connection = NULL;
+
if (client->priv->remote_greeter != NULL) {
return g_object_ref (client->priv->remote_greeter);
}
- if (!gdm_client_open_connection_sync (client, cancellable, error)) {
+ connection = gdm_client_get_connection_sync (client, cancellable, error);
+
+ if (connection == NULL) {
return NULL;
}
- client->priv->remote_greeter = gdm_remote_greeter_proxy_new_sync (client->priv->connection,
+ client->priv->remote_greeter = gdm_remote_greeter_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
@@ -1292,6 +1311,7 @@ gdm_client_get_remote_greeter_sync (GdmClient *client,
g_object_add_weak_pointer (G_OBJECT (client->priv->remote_greeter),
(gpointer *)
&client->priv->remote_greeter);
+ g_object_ref (connection);
g_object_weak_ref (G_OBJECT (client->priv->remote_greeter),
(GWeakNotify)
g_object_unref,
@@ -1323,22 +1343,25 @@ on_chooser_proxy_created (GObject *source,
}
static void
-on_connection_opened_for_chooser (GdmClient *client,
- GAsyncResult *result,
- GTask *task)
+on_connection_for_chooser (GdmClient *client,
+ GAsyncResult *result,
+ GTask *task)
{
+ g_autoptr(GDBusConnection) connection = NULL;
GCancellable *cancellable;
GError *error;
error = NULL;
- if (!gdm_client_open_connection_finish (client, result, &error)) {
+ connection = gdm_client_get_connection_finish (client, result, &error);
+
+ if (connection == NULL) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
cancellable = g_task_get_cancellable (task);
- gdm_chooser_proxy_new (client->priv->connection,
+ gdm_chooser_proxy_new (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
@@ -1381,10 +1404,10 @@ gdm_client_get_chooser (GdmClient *client,
return;
}
- gdm_client_open_connection (client,
+ gdm_client_get_connection (client,
cancellable,
(GAsyncReadyCallback)
- on_connection_opened_for_chooser,
+ on_connection_for_chooser,
task);
}
@@ -1421,6 +1444,7 @@ gdm_client_get_chooser_finish (GdmClient *client,
(gpointer *)
&client->priv->chooser);
+ g_object_ref (connection);
g_object_weak_ref (G_OBJECT (client->priv->chooser),
(GWeakNotify)
g_object_unref,
@@ -1446,16 +1470,19 @@ gdm_client_get_chooser_sync (GdmClient *client,
GCancellable *cancellable,
GError **error)
{
+ g_autoptr(GDBusConnection) connection = NULL;
if (client->priv->chooser != NULL) {
return g_object_ref (client->priv->chooser);
}
- if (!gdm_client_open_connection_sync (client, cancellable, error)) {
+ connection = gdm_client_get_connection_sync (client, cancellable, error);
+
+ if (connection == NULL) {
return NULL;
}
- client->priv->chooser = gdm_chooser_proxy_new_sync (client->priv->connection,
+ client->priv->chooser = gdm_chooser_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
SESSION_DBUS_PATH,
@@ -1466,6 +1493,7 @@ gdm_client_get_chooser_sync (GdmClient *client,
g_object_add_weak_pointer (G_OBJECT (client->priv->chooser),
(gpointer *)
&client->priv->chooser);
+ g_object_ref (connection);
g_object_weak_ref (G_OBJECT (client->priv->chooser),
(GWeakNotify)
g_object_unref,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]