diff options
Diffstat (limited to 'libnm/nm-remote-connection.c')
-rw-r--r-- | libnm/nm-remote-connection.c | 348 |
1 files changed, 168 insertions, 180 deletions
diff --git a/libnm/nm-remote-connection.c b/libnm/nm-remote-connection.c index 1b124452b9..88c03a6969 100644 --- a/libnm/nm-remote-connection.c +++ b/libnm/nm-remote-connection.c @@ -29,7 +29,6 @@ #include "nm-remote-connection.h" #include "nm-remote-connection-private.h" #include "nm-object-private.h" -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #include "nm-dbus-helpers-private.h" @@ -63,21 +62,20 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; typedef struct RemoteCall RemoteCall; -typedef void (*RemoteCallFetchResultCb) (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error); +typedef void (*RemoteCallFetchResultCb) (RemoteCall *call, GAsyncResult *result, GError *error); typedef struct RemoteCall { NMRemoteConnection *self; - DBusGProxyCall *call; RemoteCallFetchResultCb fetch_result_cb; GFunc callback; gpointer user_data; } RemoteCall; typedef struct { - DBusGConnection *bus; - DBusGProxy *proxy; - DBusGProxy *props_proxy; + GDBusConnection *bus; + GDBusProxy *proxy; + GDBusProxy *props_proxy; gboolean proxy_is_destroyed; GSList *calls; @@ -108,21 +106,18 @@ nm_remote_connection_error_quark (void) /****************************************************************/ static void -remote_call_dbus_cb (DBusGProxy *proxy, DBusGProxyCall *proxy_call, gpointer user_data) +remote_call_dbus_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { RemoteCall *call = user_data; NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self); GError *error = NULL; - g_assert ( (!proxy && !proxy_call && priv->proxy_is_destroyed) || - ( proxy && proxy_call && !priv->proxy_is_destroyed && proxy == priv->proxy) ); - if (priv->proxy_is_destroyed) { error = g_error_new_literal (NM_REMOTE_CONNECTION_ERROR, NM_REMOTE_CONNECTION_ERROR_DISCONNECTED, _("Disconnected by D-Bus")); } - call->fetch_result_cb (call, proxy_call, error); + call->fetch_result_cb (call, result, error); g_clear_error (&error); priv->calls = g_slist_remove (priv->calls, call); @@ -165,39 +160,20 @@ remote_call_new (NMRemoteConnection *self, return call; } -static void -proxy_set_destroyed (NMRemoteConnection *self) -{ - NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); - - if (priv->proxy_is_destroyed) { - g_assert (!priv->calls); - return; - } - - priv->proxy_is_destroyed = TRUE; - - priv->calls = g_slist_reverse (priv->calls); - while (priv->calls) - remote_call_dbus_cb (NULL, NULL, priv->calls->data); -} - -static void -proxy_destroy_cb (DBusGProxy* proxy, gpointer user_data) { - proxy_set_destroyed (user_data); -} - /****************************************************************/ static void -result_cb (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error) +result_cb (RemoteCall *call, GAsyncResult *result, GError *error) { NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback; GError *local_error = NULL; + GVariant *ret; if (!error) { - dbus_g_proxy_end_call (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy, - proxy_call, &local_error, G_TYPE_INVALID); + ret = g_dbus_proxy_call_finish (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy, + result, &local_error); + if (ret) + g_variant_unref (ret); error = local_error; } if (func) @@ -222,7 +198,7 @@ nm_remote_connection_commit_changes (NMRemoteConnection *self, { NMRemoteConnectionPrivate *priv; RemoteCall *call; - GHashTable *settings; + GVariant *settings; g_return_if_fail (NM_IS_REMOTE_CONNECTION (self)); @@ -232,13 +208,14 @@ nm_remote_connection_commit_changes (NMRemoteConnection *self, if (!call) return; - settings = nm_connection_to_hash (NM_CONNECTION (self), NM_SETTING_HASH_FLAG_ALL); - call->call = dbus_g_proxy_begin_call (priv->proxy, "Update", - remote_call_dbus_cb, call, NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings, - G_TYPE_INVALID); - g_assert (call->call); - g_hash_table_destroy (settings); + settings = nm_connection_to_variant (NM_CONNECTION (self), NM_SETTING_HASH_FLAG_ALL); + g_dbus_proxy_call (priv->proxy, + "Update", + g_variant_new ("@a{sa{sv}}", settings), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + remote_call_dbus_cb, call); + g_variant_unref (settings); } /** @@ -259,7 +236,7 @@ nm_remote_connection_commit_changes_unsaved (NMRemoteConnection *connection, gpointer user_data) { NMRemoteConnectionPrivate *priv; - GHashTable *settings = NULL; + GVariant *settings; RemoteCall *call; g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); @@ -270,13 +247,14 @@ nm_remote_connection_commit_changes_unsaved (NMRemoteConnection *connection, if (!call) return; - settings = nm_connection_to_hash (NM_CONNECTION (connection), NM_SETTING_HASH_FLAG_ALL); - call->call = dbus_g_proxy_begin_call (priv->proxy, "UpdateUnsaved", - remote_call_dbus_cb, call, NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings, - G_TYPE_INVALID); - g_assert (call->call); - g_hash_table_destroy (settings); + settings = nm_connection_to_variant (NM_CONNECTION (connection), NM_SETTING_HASH_FLAG_ALL); + g_dbus_proxy_call (priv->proxy, + "UpdateUnsaved", + g_variant_new ("@a{sa{sv}}", settings), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + remote_call_dbus_cb, call); + g_variant_unref (settings); } /** @@ -305,8 +283,12 @@ nm_remote_connection_save (NMRemoteConnection *connection, if (!call) return; - call->call = dbus_g_proxy_begin_call (priv->proxy, "Save", remote_call_dbus_cb, call, NULL, G_TYPE_INVALID); - g_assert (call->call); + g_dbus_proxy_call (priv->proxy, + "Save", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + remote_call_dbus_cb, call); } /** @@ -333,31 +315,34 @@ nm_remote_connection_delete (NMRemoteConnection *self, if (!call) return; - call->call = dbus_g_proxy_begin_call (priv->proxy, "Delete", - remote_call_dbus_cb, call, NULL, - G_TYPE_INVALID); - g_assert (call->call); + g_dbus_proxy_call (priv->proxy, + "Delete", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + remote_call_dbus_cb, call); } static void -get_secrets_cb (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error) +get_secrets_cb (RemoteCall *call, GAsyncResult *result, GError *error) { NMRemoteConnectionGetSecretsFunc func = (NMRemoteConnectionGetSecretsFunc) call->callback; - GHashTable *secrets = NULL; + GVariant *ret, *secrets = NULL; GError *local_error = NULL; if (!error) { - dbus_g_proxy_end_call (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy, - proxy_call, &local_error, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &secrets, - G_TYPE_INVALID); - error = local_error; + ret = g_dbus_proxy_call_finish (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy, + result, &local_error); + if (ret) + g_variant_get (ret, "(@a{sa{sv}})", &secrets); + else + error = local_error; } if (func) (*func) (call->self, error ? NULL : secrets, error, call->user_data); g_clear_error (&local_error); if (secrets) - g_hash_table_destroy (secrets); + g_variant_unref (secrets); } @@ -389,11 +374,12 @@ nm_remote_connection_get_secrets (NMRemoteConnection *self, if (!call) return; - call->call = dbus_g_proxy_begin_call (priv->proxy, "GetSecrets", - remote_call_dbus_cb, call, NULL, - G_TYPE_STRING, setting_name, - G_TYPE_INVALID); - g_assert (call->call); + g_dbus_proxy_call (priv->proxy, + "GetSecrets", + g_variant_new ("(s)", setting_name), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + remote_call_dbus_cb, call); } /** @@ -439,7 +425,7 @@ nm_remote_connection_get_visible (NMRemoteConnection *connection) /****************************************************************/ static void -replace_settings (NMRemoteConnection *self, GHashTable *new_settings) +replace_settings (NMRemoteConnection *self, GVariant *new_settings) { GError *error = NULL; @@ -456,33 +442,28 @@ replace_settings (NMRemoteConnection *self, GHashTable *new_settings) } static void -updated_get_settings_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +updated_get_settings_cb (GObject *proxy, + GAsyncResult *result, gpointer user_data) { NMRemoteConnection *self = user_data; NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); - GHashTable *new_settings; - GError *error = NULL; + GVariant *ret, *new_settings; gboolean visible; - dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &new_settings, - G_TYPE_INVALID); - if (error) { - GHashTable *hash; - - g_error_free (error); - + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, NULL); + if (!ret) { /* Connection is no longer visible to this user. */ - hash = g_hash_table_new (g_str_hash, g_str_equal); - nm_connection_replace_settings (NM_CONNECTION (self), hash, NULL); - g_hash_table_destroy (hash); + new_settings = g_variant_new ("a{sa{sv}}", NULL); + nm_connection_replace_settings (NM_CONNECTION (self), new_settings, NULL); + g_variant_unref (new_settings); visible = FALSE; } else { + g_variant_get (ret, "(@a{sa{sv}})", &new_settings); replace_settings (self, new_settings); - g_hash_table_destroy (new_settings); + g_variant_unref (new_settings); + g_variant_unref (ret); visible = TRUE; } @@ -494,35 +475,49 @@ updated_get_settings_cb (DBusGProxy *proxy, } static void -updated_cb (DBusGProxy *proxy, gpointer user_data) +updated_cb (GDBusProxy *proxy, gpointer user_data) { NMRemoteConnection *self = NM_REMOTE_CONNECTION (user_data); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); /* The connection got updated; request the replacement settings */ if (!priv->proxy_is_destroyed) { - dbus_g_proxy_begin_call (priv->proxy, "GetSettings", - updated_get_settings_cb, self, NULL, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + "GetSettings", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + updated_get_settings_cb, self); } } static void -properties_changed_cb (DBusGProxy *proxy, - GHashTable *properties, +properties_changed_cb (GDBusProxy *proxy, + GVariant *properties, gpointer user_data) { NMRemoteConnection *self = NM_REMOTE_CONNECTION (user_data); - GHashTableIter iter; - const char *key; - GValue *value; - - g_hash_table_iter_init (&iter, properties); - while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) { - if (!strcmp (key, "Unsaved")) { - NM_REMOTE_CONNECTION_GET_PRIVATE (self)->unsaved = g_value_get_boolean (value); - g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_UNSAVED); - } + NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); + + if (g_variant_lookup (properties, "Unsaved", "b", &priv->unsaved)) + g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_UNSAVED); +} + +static void +dbus_proxy_signal (GDBusProxy *proxy, + const char *sender_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + if (!strcmp (signal_name, "Updated")) + updated_cb (proxy, user_data); + else if (!strcmp (signal_name, "PropertiesChanged")) { + GVariant *dict; + + g_variant_get (parameters, "(@a{sv})", &dict); + properties_changed_cb (proxy, dict, user_data); + g_variant_unref (dict); } } @@ -540,29 +535,13 @@ init_common (NMRemoteConnection *self) nm_connection_get_path (NM_CONNECTION (self)), NM_DBUS_INTERFACE_SETTINGS_CONNECTION); g_assert (priv->proxy); - dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT); - - dbus_g_proxy_add_signal (priv->proxy, "Updated", G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "Updated", G_CALLBACK (updated_cb), self, NULL); - - g_signal_connect (priv->proxy, "destroy", G_CALLBACK (proxy_destroy_cb), self); - - /* Monitor properties */ - dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, - DBUS_TYPE_G_MAP_OF_VARIANT, - G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->proxy, "PropertiesChanged", - DBUS_TYPE_G_MAP_OF_VARIANT, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "PropertiesChanged", - G_CALLBACK (properties_changed_cb), - self, - NULL); + + g_signal_connect (priv->proxy, "g-signal", + G_CALLBACK (dbus_proxy_signal), self); priv->props_proxy = _nm_dbus_new_proxy_for_connection (priv->bus, nm_connection_get_path (NM_CONNECTION (self)), - DBUS_INTERFACE_PROPERTIES); + "org.freedesktop.DBus.Properties"); g_assert (priv->props_proxy); } @@ -571,29 +550,37 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { NMRemoteConnection *self = NM_REMOTE_CONNECTION (initable); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable); - GHashTable *hash; + GVariant *ret, *dict; init_common (self); - if (!dbus_g_proxy_call (priv->proxy, "GetSettings", error, - G_TYPE_INVALID, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &hash, - G_TYPE_INVALID)) + ret = g_dbus_proxy_call_sync (priv->proxy, + "GetSettings", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + cancellable, error); + if (!ret) return FALSE; + priv->visible = TRUE; - replace_settings (self, hash); - g_hash_table_destroy (hash); + g_variant_get (ret, "(@a{sa{sv}})", &dict); + replace_settings (self, dict); + g_variant_unref (dict); + g_variant_unref (ret); /* Get properties */ - hash = NULL; - if (!dbus_g_proxy_call (priv->props_proxy, "GetAll", error, - G_TYPE_STRING, NM_DBUS_INTERFACE_SETTINGS_CONNECTION, - G_TYPE_INVALID, - DBUS_TYPE_G_MAP_OF_VARIANT, &hash, - G_TYPE_INVALID)) + ret = g_dbus_proxy_call_sync (priv->props_proxy, + "GetAll", + g_variant_new ("(s)", NM_DBUS_INTERFACE_SETTINGS_CONNECTION), + G_DBUS_CALL_FLAGS_NONE, -1, + cancellable, error); + if (!ret) return FALSE; - properties_changed_cb (priv->props_proxy, hash, self); - g_hash_table_destroy (hash); + + g_variant_get (ret, "(@a{sv})", &dict); + properties_changed_cb (priv->props_proxy, dict, self); + g_variant_unref (dict); + g_variant_unref (ret); return TRUE; } @@ -617,49 +604,54 @@ init_async_complete (NMRemoteConnectionInitData *init_data, GError *error) } static void -init_async_got_properties (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) +init_async_got_properties (GObject *proxy, + GAsyncResult *result, + gpointer user_data) { NMRemoteConnectionInitData *init_data = user_data; NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection); - GHashTable *props; + GVariant *ret, *props; GError *error = NULL; - if (dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_MAP_OF_VARIANT, &props, - G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (ret) { + g_variant_get (ret, "(@a{sv})", &props); properties_changed_cb (priv->props_proxy, props, init_data->connection); - g_hash_table_destroy (props); + g_variant_unref (props); + g_variant_unref (ret); } init_async_complete (init_data, error); } static void -init_get_settings_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +init_get_settings_cb (GObject *proxy, + GAsyncResult *result, gpointer user_data) { NMRemoteConnectionInitData *init_data = user_data; NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection); - GHashTable *settings; + GVariant *ret, *settings; GError *error = NULL; - dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings, - G_TYPE_INVALID); + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); if (error) { init_async_complete (init_data, error); return; } priv->visible = TRUE; + g_variant_get (ret, "(@a{sa{sv}})", &settings); replace_settings (init_data->connection, settings); - g_hash_table_destroy (settings); + g_variant_unref (settings); + g_variant_unref (ret); /* Grab properties */ - dbus_g_proxy_begin_call (priv->props_proxy, "GetAll", - init_async_got_properties, init_data, NULL, - G_TYPE_STRING, NM_DBUS_INTERFACE_SETTINGS_CONNECTION, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->props_proxy, + "GetAll", + g_variant_new ("(s)", NM_DBUS_INTERFACE_SETTINGS_CONNECTION), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + init_async_got_properties, init_data); } static void @@ -677,9 +669,12 @@ init_async (GAsyncInitable *initable, int io_priority, init_common (init_data->connection); - dbus_g_proxy_begin_call (priv->proxy, "GetSettings", - init_get_settings_cb, init_data, NULL, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + "GetSettings", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + init_get_settings_cb, init_data); } static gboolean @@ -770,7 +765,7 @@ set_property (GObject *object, guint prop_id, * properties isn't specified at construction time. */ if (!priv->bus) - priv->bus = g_value_dup_boxed (value); + priv->bus = g_value_dup_object (value); break; case PROP_DBUS_PATH: /* Don't need to do anything; see constructor(). */ @@ -787,18 +782,11 @@ dispose (GObject *object) NMRemoteConnection *self = NM_REMOTE_CONNECTION (object); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); - proxy_set_destroyed (self); + priv->proxy_is_destroyed = TRUE; - if (priv->proxy) { - g_signal_handlers_disconnect_by_func (priv->proxy, proxy_destroy_cb, object); - g_clear_object (&priv->proxy); - } + g_clear_object (&priv->proxy); g_clear_object (&priv->props_proxy); - - if (priv->bus) { - dbus_g_connection_unref (priv->bus); - priv->bus = NULL; - } + g_clear_object (&priv->bus); G_OBJECT_CLASS (nm_remote_connection_parent_class)->dispose (object); } @@ -819,20 +807,20 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class) /* Properties */ g_object_class_install_property (object_class, PROP_BUS, - g_param_spec_boxed (NM_REMOTE_CONNECTION_BUS, "", "", - DBUS_TYPE_G_CONNECTION, - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_param_spec_object (NM_REMOTE_CONNECTION_BUS, "", "", + G_TYPE_DBUS_CONNECTION, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); /* These are needed so _nm_object_create() can create NMRemoteConnections */ g_object_class_install_property (object_class, PROP_DBUS_CONNECTION, - g_param_spec_boxed (NM_REMOTE_CONNECTION_DBUS_CONNECTION, "", "", - DBUS_TYPE_G_CONNECTION, - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_param_spec_object (NM_REMOTE_CONNECTION_DBUS_CONNECTION, "", "", + G_TYPE_DBUS_CONNECTION, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DBUS_PATH, g_param_spec_string (NM_REMOTE_CONNECTION_DBUS_PATH, "", "", |