1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2007 - 2008 Novell, Inc.
19 * Copyright 2007 - 2011 Red Hat, Inc.
22 #include "nm-default.h"
26 #include "NetworkManager.h"
28 #include "nm-setting-connection.h"
29 #include "nm-remote-connection.h"
30 #include "nm-remote-connection-private.h"
31 #include "nm-object-private.h"
32 #include "nm-dbus-glib-types.h"
33 #include "nm-dbus-helpers-private.h"
34 #include "nm-setting-private.h"
36 #define NM_REMOTE_CONNECTION_BUS "bus"
37 #define NM_REMOTE_CONNECTION_DBUS_CONNECTION "dbus-connection"
38 #define NM_REMOTE_CONNECTION_DBUS_PATH "dbus-path"
40 static void nm_remote_connection_initable_iface_init (GInitableIface *iface);
41 static void nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface);
43 G_DEFINE_TYPE_WITH_CODE (NMRemoteConnection, nm_remote_connection, NM_TYPE_CONNECTION,
44 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_remote_connection_initable_iface_init);
45 G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_remote_connection_async_initable_iface_init);
65 static guint signals[LAST_SIGNAL] = { 0 };
67 typedef struct RemoteCall RemoteCall;
68 typedef void (*RemoteCallFetchResultCb) (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error);
72 NMRemoteConnection *self;
74 RemoteCallFetchResultCb fetch_result_cb;
82 DBusGProxy *props_proxy;
83 gboolean proxy_is_destroyed;
90 } NMRemoteConnectionPrivate;
92 #define NM_REMOTE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_REMOTE_CONNECTION, NMRemoteConnectionPrivate))
95 * nm_remote_connection_error_quark:
97 * Registers an error quark for #NMRemoteConnection if necessary.
99 * Returns: the error quark used for #NMRemoteConnection errors.
102 nm_remote_connection_error_quark (void)
104 static GQuark quark = 0;
106 if (G_UNLIKELY (quark == 0))
107 quark = g_quark_from_static_string ("nm-remote-connection-error-quark");
111 /****************************************************************/
114 _nm_remote_connection_ensure_inited (NMRemoteConnection *self)
116 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
117 GError *error = NULL;
120 if (!g_initable_init (G_INITABLE (self), NULL, &error)) {
121 /* Don't warn when the call times out because the settings service can't
122 * be activated or whatever.
124 if (!g_error_matches (error, DBUS_GERROR, DBUS_GERROR_NO_REPLY)) {
125 g_warning ("%s: (NMRemoteConnection) error initializing: %s\n",
126 __func__, error->message);
128 g_error_free (error);
134 /****************************************************************/
137 remote_call_dbus_cb (DBusGProxy *proxy, DBusGProxyCall *proxy_call, gpointer user_data)
139 RemoteCall *call = user_data;
140 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self);
141 GError *error = NULL;
143 g_assert ( (!proxy && !proxy_call && priv->proxy_is_destroyed) ||
144 ( proxy && proxy_call && !priv->proxy_is_destroyed && proxy == priv->proxy) );
146 if (priv->proxy_is_destroyed) {
147 error = g_error_new_literal (NM_REMOTE_CONNECTION_ERROR,
148 NM_REMOTE_CONNECTION_ERROR_DISCONNECTED,
149 _("Disconnected by D-Bus"));
151 call->fetch_result_cb (call, proxy_call, error);
152 g_clear_error (&error);
154 priv->calls = g_slist_remove (priv->calls, call);
155 g_object_unref (call->self);
160 remote_call_cleanup_cb (void *user_data)
162 remote_call_dbus_cb (NULL, NULL, user_data);
163 return G_SOURCE_REMOVE;
167 remote_call_new (NMRemoteConnection *self,
168 RemoteCallFetchResultCb fetch_result_cb,
173 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
175 g_assert (fetch_result_cb);
177 if (priv->proxy_is_destroyed && !callback)
180 call = g_malloc0 (sizeof (RemoteCall));
181 call->self = g_object_ref (self);
182 call->fetch_result_cb = fetch_result_cb;
183 call->user_data = user_data;
184 call->callback = callback;
186 if (priv->proxy_is_destroyed) {
187 g_idle_add (remote_call_cleanup_cb, call);
190 priv->calls = g_slist_prepend (priv->calls, call);
195 proxy_set_destroyed (NMRemoteConnection *self)
197 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
199 if (priv->proxy_is_destroyed) {
200 g_assert (!priv->calls);
204 priv->proxy_is_destroyed = TRUE;
206 priv->calls = g_slist_reverse (priv->calls);
208 remote_call_dbus_cb (NULL, NULL, priv->calls->data);
212 proxy_destroy_cb (DBusGProxy* proxy, gpointer user_data) {
213 proxy_set_destroyed (user_data);
216 /****************************************************************/
219 result_cb (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error)
221 NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback;
222 GError *local_error = NULL;
225 dbus_g_proxy_end_call (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy,
226 proxy_call, &local_error, G_TYPE_INVALID);
230 (*func) (call->self, error, call->user_data);
231 g_clear_error (&local_error);
235 * nm_remote_connection_commit_changes:
236 * @connection: the #NMRemoteConnection
237 * @callback: (scope async) (allow-none): a function to be called when the
239 * @user_data: (closure): caller-specific data to be passed to @callback
241 * Send any local changes to the settings and properties of this connection to
242 * NetworkManager, which will immediately save them to disk.
245 nm_remote_connection_commit_changes (NMRemoteConnection *self,
246 NMRemoteConnectionResultFunc callback,
249 NMRemoteConnectionPrivate *priv;
251 GHashTable *settings;
253 g_return_if_fail (NM_IS_REMOTE_CONNECTION (self));
255 priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
257 call = remote_call_new (self, result_cb, (GFunc) callback, user_data);
261 settings = nm_connection_to_hash (NM_CONNECTION (self), NM_SETTING_HASH_FLAG_ALL);
262 call->call = dbus_g_proxy_begin_call (priv->proxy, "Update",
263 remote_call_dbus_cb, call, NULL,
264 DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings,
266 g_assert (call->call);
267 g_hash_table_destroy (settings);
271 * nm_remote_connection_commit_changes_unsaved:
272 * @connection: the #NMRemoteConnection
273 * @callback: (scope async) (allow-none): a function to be called when the
275 * @user_data: (closure): caller-specific data to be passed to @callback
277 * Send any local changes to the settings and properties of this connection to
278 * NetworkManager. The changes are not saved to disk until either
279 * nm_remote_connection_save() or nm_remote_connection_commit_changes() is
285 nm_remote_connection_commit_changes_unsaved (NMRemoteConnection *connection,
286 NMRemoteConnectionResultFunc callback,
289 NMRemoteConnectionPrivate *priv;
290 GHashTable *settings = NULL;
293 g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
295 priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
297 call = remote_call_new (connection, result_cb, (GFunc) callback, user_data);
301 settings = nm_connection_to_hash (NM_CONNECTION (connection), NM_SETTING_HASH_FLAG_ALL);
302 call->call = dbus_g_proxy_begin_call (priv->proxy, "UpdateUnsaved",
303 remote_call_dbus_cb, call, NULL,
304 DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings,
306 g_assert (call->call);
307 g_hash_table_destroy (settings);
311 * nm_remote_connection_save:
312 * @connection: the #NMRemoteConnection
313 * @callback: (scope async) (allow-none): a function to be called when the
315 * @user_data: (closure): caller-specific data to be passed to @callback
317 * Saves the connection to disk if the connection has changes that have not yet
318 * been written to disk, or if the connection has never been saved.
323 nm_remote_connection_save (NMRemoteConnection *connection,
324 NMRemoteConnectionResultFunc callback,
327 NMRemoteConnectionPrivate *priv;
330 g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
332 priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
334 call = remote_call_new (connection, result_cb, (GFunc) callback, user_data);
338 call->call = dbus_g_proxy_begin_call (priv->proxy, "Save", remote_call_dbus_cb, call, NULL, G_TYPE_INVALID);
339 g_assert (call->call);
343 * nm_remote_connection_delete:
344 * @connection: the #NMRemoteConnection
345 * @callback: (scope async) (allow-none): a function to be called when the delete completes
346 * @user_data: (closure): caller-specific data to be passed to @callback
348 * Delete the connection.
351 nm_remote_connection_delete (NMRemoteConnection *self,
352 NMRemoteConnectionResultFunc callback,
355 NMRemoteConnectionPrivate *priv;
358 g_return_if_fail (NM_IS_REMOTE_CONNECTION (self));
360 priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
362 call = remote_call_new (self, result_cb, (GFunc) callback, user_data);
366 call->call = dbus_g_proxy_begin_call (priv->proxy, "Delete",
367 remote_call_dbus_cb, call, NULL,
369 g_assert (call->call);
373 get_secrets_cb (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error)
375 NMRemoteConnectionGetSecretsFunc func = (NMRemoteConnectionGetSecretsFunc) call->callback;
376 GHashTable *secrets = NULL;
377 GError *local_error = NULL;
380 dbus_g_proxy_end_call (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy,
381 proxy_call, &local_error,
382 DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &secrets,
387 (*func) (call->self, error ? NULL : secrets, error, call->user_data);
388 g_clear_error (&local_error);
390 g_hash_table_destroy (secrets);
395 * nm_remote_connection_get_secrets:
396 * @connection: the #NMRemoteConnection
397 * @setting_name: the #NMSetting object name to get secrets for
398 * @callback: (scope async): a function to be called when the update completes;
400 * @user_data: (closure): caller-specific data to be passed to @callback
402 * Request the connection's secrets.
405 nm_remote_connection_get_secrets (NMRemoteConnection *self,
406 const char *setting_name,
407 NMRemoteConnectionGetSecretsFunc callback,
410 NMRemoteConnectionPrivate *priv;
413 g_return_if_fail (NM_IS_REMOTE_CONNECTION (self));
414 g_return_if_fail (callback != NULL);
416 priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
418 call = remote_call_new (self, get_secrets_cb, (GFunc) callback, user_data);
422 call->call = dbus_g_proxy_begin_call (priv->proxy, "GetSecrets",
423 remote_call_dbus_cb, call, NULL,
424 G_TYPE_STRING, setting_name,
426 g_assert (call->call);
430 * nm_remote_connection_get_unsaved:
431 * @connection: the #NMRemoteConnection
433 * Returns: %TRUE if the remote connection contains changes that have not
434 * been saved to disk, %FALSE if the connection is the same as its on-disk
440 nm_remote_connection_get_unsaved (NMRemoteConnection *connection)
442 g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
444 _nm_remote_connection_ensure_inited (connection);
445 return NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->unsaved;
448 /****************************************************************/
451 updated_get_settings_cb (DBusGProxy *proxy,
452 DBusGProxyCall *call,
455 NMRemoteConnection *self = user_data;
456 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
457 GHashTable *new_settings;
458 GError *error = NULL;
460 dbus_g_proxy_end_call (proxy, call, &error,
461 DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &new_settings,
466 g_error_free (error);
468 /* Connection is no longer visible to this user. Let the settings
469 * service handle this via 'visible'. The settings service will emit
470 * the "removed" signal for us since it handles the lifetime of this
473 hash = g_hash_table_new (g_str_hash, g_str_equal);
474 _nm_connection_replace_settings (NM_CONNECTION (self), hash);
475 g_hash_table_destroy (hash);
477 priv->visible = FALSE;
478 g_signal_emit (self, signals[VISIBLE], 0, FALSE);
480 gs_unref_object NMConnection *self_alive = NULL;
482 self_alive = g_object_ref (self);
483 _nm_connection_replace_settings (NM_CONNECTION (self), new_settings);
484 g_signal_emit (self, signals[UPDATED], 0, new_settings);
485 g_hash_table_destroy (new_settings);
487 /* Settings service will handle announcing the connection to clients */
488 if (priv->visible == FALSE) {
489 priv->visible = TRUE;
490 g_signal_emit (self, signals[VISIBLE], 0, TRUE);
496 updated_cb (DBusGProxy *proxy, gpointer user_data)
498 NMRemoteConnection *self = NM_REMOTE_CONNECTION (user_data);
499 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
501 /* The connection got updated; request the replacement settings */
502 if (!priv->proxy_is_destroyed) {
503 dbus_g_proxy_begin_call (priv->proxy, "GetSettings",
504 updated_get_settings_cb, self, NULL,
510 removed_cb (DBusGProxy *proxy, gpointer user_data)
512 g_signal_emit (G_OBJECT (user_data), signals[REMOVED], 0);
516 properties_changed_cb (DBusGProxy *proxy,
517 GHashTable *properties,
520 NMRemoteConnection *self = NM_REMOTE_CONNECTION (user_data);
525 g_hash_table_iter_init (&iter, properties);
526 while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
527 if (!strcmp (key, "Unsaved")) {
528 NM_REMOTE_CONNECTION_GET_PRIVATE (self)->unsaved = g_value_get_boolean (value);
529 g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_UNSAVED);
534 /****************************************************************/
537 * nm_remote_connection_new:
538 * @bus: a valid and connected D-Bus connection
539 * @path: the D-Bus path of the connection as exported by the settings service
541 * Creates a new object representing the remote connection.
543 * Returns: the new remote connection object on success, or %NULL on failure
546 nm_remote_connection_new (DBusGConnection *bus,
549 g_return_val_if_fail (bus != NULL, NULL);
550 g_return_val_if_fail (path != NULL, NULL);
552 return (NMRemoteConnection *) g_object_new (NM_TYPE_REMOTE_CONNECTION,
553 NM_REMOTE_CONNECTION_BUS, bus,
554 NM_CONNECTION_PATH, path,
559 constructed (GObject *object)
561 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (object);
563 G_OBJECT_CLASS (nm_remote_connection_parent_class)->constructed (object);
565 g_assert (priv->bus);
566 g_assert (nm_connection_get_path (NM_CONNECTION (object)));
568 priv->proxy = _nm_dbus_new_proxy_for_connection (priv->bus,
569 nm_connection_get_path (NM_CONNECTION (object)),
570 NM_DBUS_IFACE_SETTINGS_CONNECTION);
571 g_assert (priv->proxy);
572 dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT);
574 dbus_g_proxy_add_signal (priv->proxy, "Updated", G_TYPE_INVALID);
575 dbus_g_proxy_connect_signal (priv->proxy, "Updated", G_CALLBACK (updated_cb), object, NULL);
577 dbus_g_proxy_add_signal (priv->proxy, "Removed", G_TYPE_INVALID);
578 dbus_g_proxy_connect_signal (priv->proxy, "Removed", G_CALLBACK (removed_cb), object, NULL);
580 g_signal_connect (priv->proxy, "destroy", G_CALLBACK (proxy_destroy_cb), object);
582 /* Monitor properties */
583 dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED,
585 DBUS_TYPE_G_MAP_OF_VARIANT,
587 dbus_g_proxy_add_signal (priv->proxy, "PropertiesChanged",
588 DBUS_TYPE_G_MAP_OF_VARIANT,
590 dbus_g_proxy_connect_signal (priv->proxy, "PropertiesChanged",
591 G_CALLBACK (properties_changed_cb),
595 priv->props_proxy = _nm_dbus_new_proxy_for_connection (priv->bus,
596 nm_connection_get_path (NM_CONNECTION (object)),
597 DBUS_INTERFACE_PROPERTIES);
598 g_assert (priv->props_proxy);
602 init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
604 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable);
606 gs_unref_object NMConnection *self_alive = NULL;
608 if (!dbus_g_proxy_call (priv->proxy, "GetSettings", error,
610 DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &hash,
613 priv->visible = TRUE;
614 self_alive = g_object_ref (initable);
615 _nm_connection_replace_settings (NM_CONNECTION (initable), hash);
616 g_signal_emit (initable, signals[UPDATED], 0, hash);
617 g_hash_table_destroy (hash);
621 if (!dbus_g_proxy_call (priv->props_proxy, "GetAll", error,
622 G_TYPE_STRING, NM_DBUS_IFACE_SETTINGS_CONNECTION,
624 DBUS_TYPE_G_MAP_OF_VARIANT, &hash,
627 properties_changed_cb (priv->props_proxy, hash, NM_REMOTE_CONNECTION (initable));
628 g_hash_table_destroy (hash);
634 NMRemoteConnection *connection;
635 GSimpleAsyncResult *result;
636 } NMRemoteConnectionInitData;
639 init_async_complete (NMRemoteConnectionInitData *init_data, GError *error)
642 g_simple_async_result_take_error (init_data->result, error);
644 g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE);
645 NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection)->inited = TRUE;
648 g_simple_async_result_complete (init_data->result);
649 g_object_unref (init_data->result);
650 g_slice_free (NMRemoteConnectionInitData, init_data);
654 init_async_got_properties (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
656 NMRemoteConnectionInitData *init_data = user_data;
657 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection);
659 GError *error = NULL;
661 if (dbus_g_proxy_end_call (proxy, call, &error,
662 DBUS_TYPE_G_MAP_OF_VARIANT, &props,
664 properties_changed_cb (priv->props_proxy, props, init_data->connection);
665 g_hash_table_destroy (props);
667 init_async_complete (init_data, error);
671 init_get_settings_cb (DBusGProxy *proxy,
672 DBusGProxyCall *call,
675 NMRemoteConnectionInitData *init_data = user_data;
676 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection);
677 GHashTable *settings;
678 GError *error = NULL;
679 gs_unref_object NMConnection *self_alive = NULL;
681 dbus_g_proxy_end_call (proxy, call, &error,
682 DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings,
685 init_async_complete (init_data, error);
689 priv->visible = TRUE;
690 self_alive = g_object_ref (init_data->connection);
691 _nm_connection_replace_settings (NM_CONNECTION (init_data->connection), settings);
692 g_signal_emit (init_data->connection, signals[UPDATED], 0, settings);
693 g_hash_table_destroy (settings);
695 /* Grab properties */
696 dbus_g_proxy_begin_call (priv->props_proxy, "GetAll",
697 init_async_got_properties, init_data, NULL,
698 G_TYPE_STRING, NM_DBUS_IFACE_SETTINGS_CONNECTION,
703 init_async (GAsyncInitable *initable, int io_priority,
704 GCancellable *cancellable, GAsyncReadyCallback callback,
707 NMRemoteConnectionInitData *init_data;
708 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable);
711 init_data = g_slice_new0 (NMRemoteConnectionInitData);
712 init_data->connection = NM_REMOTE_CONNECTION (initable);
713 init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback,
714 user_data, init_async);
716 dbus_g_proxy_begin_call (priv->proxy, "GetSettings",
717 init_get_settings_cb, init_data, NULL,
722 init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error)
724 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
726 if (g_simple_async_result_propagate_error (simple, error))
733 nm_remote_connection_init (NMRemoteConnection *self)
738 constructor (GType type, guint n_construct_properties,
739 GObjectConstructParam *construct_properties)
741 static GParamSpec *nm_connection_path = NULL;
742 static GParamSpec *nm_remote_connection_dbus_path = NULL;
743 int i, path_index = -1, dbus_path_index = -1;
745 if (!nm_connection_path) {
747 g_object_class_find_property (g_type_class_peek (NM_TYPE_CONNECTION),
749 nm_remote_connection_dbus_path =
750 g_object_class_find_property (g_type_class_peek (NM_TYPE_REMOTE_CONNECTION),
751 NM_REMOTE_CONNECTION_DBUS_PATH);
754 /* Find the two properties */
755 for (i = 0; i < n_construct_properties; i++) {
756 if (construct_properties[i].pspec == nm_connection_path)
758 else if (construct_properties[i].pspec == nm_remote_connection_dbus_path)
761 g_assert (path_index != -1 && dbus_path_index != -1);
763 /* If NMRemoteConnection:dbus-path is set, and NMConnection:path
764 * is not, then copy the value of the former to the latter.
766 if (g_value_get_string (construct_properties[dbus_path_index].value) &&
767 !g_value_get_string (construct_properties[path_index].value))
768 construct_properties[path_index].value = construct_properties[dbus_path_index].value;
770 return G_OBJECT_CLASS (nm_remote_connection_parent_class)->
771 constructor (type, n_construct_properties, construct_properties);
775 get_property (GObject *object, guint prop_id,
776 GValue *value, GParamSpec *pspec)
778 _nm_remote_connection_ensure_inited (NM_REMOTE_CONNECTION (object));
782 g_value_set_boolean (value, NM_REMOTE_CONNECTION_GET_PRIVATE (object)->unsaved);
785 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
791 set_property (GObject *object, guint prop_id,
792 const GValue *value, GParamSpec *pspec)
794 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (object);
798 case PROP_DBUS_CONNECTION:
800 /* priv->bus is set from either of two properties so that it (a) remains
801 * backwards compatible with the previous "bus" property, and that (b)
802 * it can be created just like an NMObject using the "dbus-connection",
803 * even though it's not a subclass of NMObject. So don't overwrite the
804 * a valid value that the other property set with NULL, if one of the
805 * properties isn't specified at construction time.
808 priv->bus = g_value_dup_boxed (value);
811 /* Don't need to do anything; see constructor(). */
814 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
820 dispose (GObject *object)
822 NMRemoteConnection *self = NM_REMOTE_CONNECTION (object);
823 NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
825 proxy_set_destroyed (self);
828 g_signal_handlers_disconnect_by_func (priv->proxy, proxy_destroy_cb, object);
829 g_clear_object (&priv->proxy);
831 g_clear_object (&priv->props_proxy);
834 dbus_g_connection_unref (priv->bus);
838 G_OBJECT_CLASS (nm_remote_connection_parent_class)->dispose (object);
842 nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class)
844 GObjectClass *object_class = G_OBJECT_CLASS (remote_class);
846 g_type_class_add_private (object_class, sizeof (NMRemoteConnectionPrivate));
848 /* virtual methods */
849 object_class->constructor = constructor;
850 object_class->get_property = get_property;
851 object_class->set_property = set_property;
852 object_class->dispose = dispose;
853 object_class->constructed = constructed;
857 * NMRemoteConnection:bus:
859 * The #DBusGConnection that the #NMRemoteConnection is connected to.
861 g_object_class_install_property
862 (object_class, PROP_BUS,
863 g_param_spec_boxed (NM_REMOTE_CONNECTION_BUS, "", "",
864 DBUS_TYPE_G_CONNECTION,
866 G_PARAM_CONSTRUCT_ONLY |
867 G_PARAM_STATIC_STRINGS));
869 /* These are needed so _nm_object_create() can create NMRemoteConnections */
870 g_object_class_install_property
871 (object_class, PROP_DBUS_CONNECTION,
872 g_param_spec_boxed (NM_REMOTE_CONNECTION_DBUS_CONNECTION, "", "",
873 DBUS_TYPE_G_CONNECTION,
875 G_PARAM_CONSTRUCT_ONLY |
876 G_PARAM_STATIC_STRINGS));
877 g_object_class_install_property
878 (object_class, PROP_DBUS_PATH,
879 g_param_spec_string (NM_REMOTE_CONNECTION_DBUS_PATH, "", "",
882 G_PARAM_CONSTRUCT_ONLY |
883 G_PARAM_STATIC_STRINGS));
886 * NMRemoteConnection:unsaved:
888 * %TRUE if the remote connection contains changes that have not been saved
889 * to disk, %FALSE if the connection is the same as its on-disk representation.
893 g_object_class_install_property
894 (object_class, PROP_UNSAVED,
895 g_param_spec_boolean (NM_REMOTE_CONNECTION_UNSAVED, "", "",
898 G_PARAM_STATIC_STRINGS));
902 * NMRemoteConnection::updated:
903 * @connection: a #NMConnection
905 * This signal is emitted when a connection changes, and it is
906 * still visible to the user.
909 g_signal_new (NM_REMOTE_CONNECTION_UPDATED,
910 G_TYPE_FROM_CLASS (remote_class),
912 G_STRUCT_OFFSET (NMRemoteConnectionClass, updated),
914 g_cclosure_marshal_VOID__VOID,
918 * NMRemoteConnection::removed:
919 * @connection: a #NMConnection
921 * This signal is emitted when a connection is either deleted or becomes
922 * invisible to the current user.
925 g_signal_new (NM_REMOTE_CONNECTION_REMOVED,
926 G_TYPE_FROM_CLASS (remote_class),
928 G_STRUCT_OFFSET (NMRemoteConnectionClass, removed),
930 g_cclosure_marshal_VOID__VOID,
935 g_signal_new ("visible",
936 G_TYPE_FROM_CLASS (remote_class),
939 g_cclosure_marshal_VOID__BOOLEAN,
940 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
944 nm_remote_connection_initable_iface_init (GInitableIface *iface)
946 iface->init = init_sync;
950 nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface)
952 iface->init_async = init_async;
953 iface->init_finish = init_finish;