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 - 2012 Red Hat, Inc.
22 #include "nm-default.h"
24 #include "nm-object.h"
31 #include "nm-dbus-interface.h"
32 #include "nm-object-cache.h"
33 #include "nm-object-private.h"
34 #include "nm-dbus-helpers.h"
35 #include "nm-client.h"
36 #include "nm-core-internal.h"
38 static gboolean debug = FALSE;
39 #define dbgmsg(f,...) if (G_UNLIKELY (debug)) { g_message (f, ## __VA_ARGS__ ); }
41 static void nm_object_initable_iface_init (GInitableIface *iface);
42 static void nm_object_async_initable_iface_init (GAsyncInitableIface *iface);
45 NMObjectDecideTypeFunc type_func;
48 } NMObjectTypeFuncData;
50 static GHashTable *type_funcs;
54 } NMObjectClassPrivate;
56 #define NM_OBJECT_CLASS_GET_PRIVATE(k) (G_TYPE_CLASS_GET_PRIVATE ((k), NM_TYPE_OBJECT, NMObjectClassPrivate))
58 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMObject, nm_object, G_TYPE_OBJECT,
59 type_funcs = g_hash_table_new (NULL, NULL);
60 g_type_add_class_private (g_define_type_id, sizeof (NMObjectClassPrivate));
61 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_object_initable_iface_init);
62 G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_object_async_initable_iface_init);
65 #define NM_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_OBJECT, NMObjectPrivate))
68 PropertyMarshalFunc func;
71 const char *signal_prefix;
74 static void reload_complete (NMObject *object, gboolean emit_now);
75 static gboolean demarshal_generic (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field);
78 GDBusConnection *connection;
83 GDBusProxy *properties_proxy;
84 GSList *property_tables;
86 gboolean suppress_property_updates;
88 gboolean inited; /* async init finished? */
89 GSList *waiters; /* if async init did not finish, users of this object need
90 * to defer their notifications by adding themselves here. */
95 GSList *reload_results;
96 guint reload_remaining;
103 PROP_DBUS_CONNECTION,
110 * _nm_object_class_add_interface:
111 * @object_class: an #NMObjectClass
112 * @interface: a D-Bus interface name
114 * Registers that @object_class implements @interface. A proxy for that
115 * interface will automatically be created at construction time, and can
116 * be retrieved with _nm_object_get_proxy().
119 _nm_object_class_add_interface (NMObjectClass *object_class,
120 const char *interface)
122 NMObjectClassPrivate *cpriv;
124 g_return_if_fail (NM_IS_OBJECT_CLASS (object_class));
125 g_return_if_fail (interface);
127 cpriv = NM_OBJECT_CLASS_GET_PRIVATE (object_class);
129 g_return_if_fail (g_slist_find_custom (cpriv->interfaces, interface, (GCompareFunc) g_strcmp0) == NULL);
131 cpriv->interfaces = g_slist_prepend (cpriv->interfaces, g_strdup (interface));
135 * nm_object_get_path:
136 * @object: a #NMObject
138 * Gets the DBus path of the #NMObject.
140 * Returns: the object's path. This is the internal string used by the
141 * device, and must not be modified.
144 nm_object_get_path (NMObject *object)
146 g_return_val_if_fail (NM_IS_OBJECT (object), NULL);
148 return NM_OBJECT_GET_PRIVATE (object)->path;
152 * _nm_object_get_proxy:
153 * @object: an #NMObject
154 * @interface: a D-Bus interface implemented by @object
156 * Gets the D-Bus proxy for @interface on @object.
158 * Returns: (transfer none): a D-Bus proxy
161 _nm_object_get_proxy (NMObject *object,
162 const char *interface)
166 g_return_val_if_fail (NM_IS_OBJECT (object), NULL);
168 proxy = g_hash_table_lookup (NM_OBJECT_GET_PRIVATE (object)->proxies, interface);
169 g_return_val_if_fail (proxy != NULL, NULL);
174 NOTIFY_SIGNAL_PENDING_NONE,
175 NOTIFY_SIGNAL_PENDING_ADDED,
176 NOTIFY_SIGNAL_PENDING_REMOVED,
177 NOTIFY_SIGNAL_PENDING_ADDED_REMOVED,
178 } NotifySignalPending;
181 const char *property;
182 const char *signal_prefix;
183 NotifySignalPending pending;
188 notify_item_free (NotifyItem *item)
190 g_clear_object (&item->changed);
191 g_slice_free (NotifyItem, item);
195 deferred_notify_cb (gpointer data)
197 NMObject *object = NM_OBJECT (data);
198 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
199 NMObjectClass *object_class = NM_OBJECT_GET_CLASS (object);
200 GSList *props, *iter;
204 /* Wait until all reloads are done before notifying */
205 if (priv->reload_remaining)
206 return G_SOURCE_REMOVE;
208 /* Clear priv->notify_items early so that an NMObject subclass that
209 * listens to property changes can queue up other property changes
210 * during the g_object_notify() call separately from the property
211 * list we're iterating.
213 props = g_slist_reverse (priv->notify_items);
214 priv->notify_items = NULL;
216 g_object_ref (object);
218 /* Emit added/removed signals first since some of our internal objects
219 * use the added/removed signals for new object processing.
221 for (iter = props; iter; iter = g_slist_next (iter)) {
222 NotifyItem *item = iter->data;
226 switch (item->pending) {
227 case NOTIFY_SIGNAL_PENDING_ADDED:
228 ret = g_snprintf (buf, sizeof (buf), "%s-added", item->signal_prefix);
230 case NOTIFY_SIGNAL_PENDING_REMOVED:
231 ret = g_snprintf (buf, sizeof (buf), "%s-removed", item->signal_prefix);
233 case NOTIFY_SIGNAL_PENDING_ADDED_REMOVED:
234 if (object_class->object_creation_failed)
235 object_class->object_creation_failed (object, nm_object_get_path (item->changed));
237 case NOTIFY_SIGNAL_PENDING_NONE:
242 g_assert (ret < sizeof (buf));
243 g_signal_emit_by_name (object, buf, item->changed);
247 /* Emit property change notifications second */
248 for (iter = props; iter; iter = g_slist_next (iter)) {
249 NotifyItem *item = iter->data;
252 g_object_notify (G_OBJECT (object), item->property);
255 g_object_unref (object);
257 g_slist_free_full (props, (GDestroyNotify) notify_item_free);
258 return G_SOURCE_REMOVE;
262 _nm_object_defer_notify (NMObject *object)
264 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
266 if (!priv->notify_id)
267 priv->notify_id = g_idle_add_full (G_PRIORITY_LOW, deferred_notify_cb, object, NULL);
271 _nm_object_queue_notify_full (NMObject *object,
272 const char *property,
273 const char *signal_prefix,
277 NMObjectPrivate *priv;
281 g_return_if_fail (NM_IS_OBJECT (object));
282 g_return_if_fail (!signal_prefix != !property);
283 g_return_if_fail (!signal_prefix == !changed);
285 priv = NM_OBJECT_GET_PRIVATE (object);
286 _nm_object_defer_notify (object);
288 property = g_intern_string (property);
289 signal_prefix = g_intern_string (signal_prefix);
290 for (iter = priv->notify_items; iter; iter = g_slist_next (iter)) {
293 if (property && (property == item->property))
296 /* Collapse signals for the same object (such as "added->removed") to
297 * ensure we don't emit signals when their sum should have no effect.
298 * The "added->removed->removed" sequence requires special handling,
299 * hence the addition of the ADDED_REMOVED state to ensure that no
300 * signal is emitted in this case:
302 * Without the ADDED_REMOVED state:
303 * NONE + added -> ADDED
304 * ADDED + removed -> NONE
305 * NONE + removed -> REMOVED (would emit 'removed' signal)
307 * With the ADDED_REMOVED state:
308 * NONE | ADDED_REMOVED + added -> ADDED
309 * ADDED + removed -> ADDED_REMOVED
310 * ADDED_REMOVED + removed -> ADDED_REMOVED (emits no signal)
312 if (signal_prefix && (changed == item->changed) && (item->signal_prefix == signal_prefix)) {
313 switch (item->pending) {
314 case NOTIFY_SIGNAL_PENDING_ADDED:
316 item->pending = NOTIFY_SIGNAL_PENDING_ADDED_REMOVED;
318 case NOTIFY_SIGNAL_PENDING_REMOVED:
320 item->pending = NOTIFY_SIGNAL_PENDING_NONE;
322 case NOTIFY_SIGNAL_PENDING_ADDED_REMOVED:
324 item->pending = NOTIFY_SIGNAL_PENDING_ADDED;
326 case NOTIFY_SIGNAL_PENDING_NONE:
327 item->pending = added ? NOTIFY_SIGNAL_PENDING_ADDED : NOTIFY_SIGNAL_PENDING_REMOVED;
330 g_assert_not_reached ();
336 item = g_slice_new0 (NotifyItem);
337 item->property = property;
339 item->signal_prefix = signal_prefix;
340 item->pending = added ? NOTIFY_SIGNAL_PENDING_ADDED : NOTIFY_SIGNAL_PENDING_REMOVED;
341 item->changed = changed ? g_object_ref (changed) : NULL;
343 priv->notify_items = g_slist_prepend (priv->notify_items, item);
347 _nm_object_queue_notify (NMObject *object, const char *property)
349 _nm_object_queue_notify_full (object, property, NULL, FALSE, NULL);
353 _nm_object_register_type_func (GType base_type,
354 NMObjectDecideTypeFunc type_func,
355 const char *interface,
356 const char *property)
358 NMObjectTypeFuncData *type_data;
360 g_return_if_fail (type_func != NULL);
361 g_return_if_fail (interface != NULL);
362 g_return_if_fail (property != NULL);
364 type_data = g_slice_new (NMObjectTypeFuncData);
365 type_data->type_func = type_func;
366 type_data->interface = g_strdup (interface);
367 type_data->property = g_strdup (property);
369 g_hash_table_insert (type_funcs,
370 GSIZE_TO_POINTER (base_type),
375 _nm_object_create (GType type, GDBusConnection *connection, const char *path)
377 NMObjectTypeFuncData *type_data;
379 GError *error = NULL;
381 type_data = g_hash_table_lookup (type_funcs, GSIZE_TO_POINTER (type));
384 GVariant *ret, *value;
386 proxy = _nm_dbus_new_proxy_for_connection (connection, path,
387 DBUS_INTERFACE_PROPERTIES,
390 g_warning ("Could not create proxy for %s: %s.", path, error->message);
391 g_error_free (error);
395 ret = g_dbus_proxy_call_sync (proxy,
397 g_variant_new ("(ss)",
398 type_data->interface,
399 type_data->property),
400 G_DBUS_CALL_FLAGS_NONE, -1,
402 g_object_unref (proxy);
404 dbgmsg ("Could not fetch property '%s' of interface '%s' on %s: %s\n",
405 type_data->property, type_data->interface, path, error->message);
406 g_error_free (error);
410 g_variant_get (ret, "(v)", &value);
411 type = type_data->type_func (value);
412 g_variant_unref (value);
413 g_variant_unref (ret);
416 if (type == G_TYPE_INVALID) {
417 dbgmsg ("Could not create object for %s: unknown object type", path);
421 object = g_object_new (type,
422 NM_OBJECT_PATH, path,
423 NM_OBJECT_DBUS_CONNECTION, connection,
425 /* Cache the object before initializing it (and in particular, loading its
426 * property values); this is necessary to make circular references work (eg,
427 * when creating an NMActiveConnection, it will create an NMDevice which
428 * will in turn try to create the parent NMActiveConnection). Since we don't
429 * support multi-threaded use, we know that we will have inited the object
430 * before any external code sees it.
432 _nm_object_cache_add (NM_OBJECT (object));
433 NM_OBJECT_GET_PRIVATE (object)->inited = TRUE;
434 if (!g_initable_init (G_INITABLE (object), NULL, &error)) {
435 dbgmsg ("Could not create object for %s: %s", path, error->message);
436 g_error_free (error);
437 g_clear_object (&object);
448 int length, remaining;
451 const char *property_name;
455 odata_free (gpointer data)
457 ObjectCreatedData *odata = data;
459 g_object_unref (odata->self);
460 g_free (odata->objects);
462 g_ptr_array_unref (odata->array);
463 g_slice_free (ObjectCreatedData, odata);
466 static void object_property_maybe_complete (ObjectCreatedData *odata);
469 typedef void (*NMObjectCreateCallbackFunc) (GObject *, const char *, gpointer);
472 NMObjectCreateCallbackFunc callback;
474 NMObjectTypeFuncData *type_data;
475 GDBusConnection *connection;
476 } NMObjectTypeAsyncData;
479 create_async_complete (GObject *object, NMObjectTypeAsyncData *async_data)
481 async_data->callback (object, async_data->path, async_data->user_data);
483 g_free (async_data->path);
484 g_object_unref (async_data->connection);
485 g_slice_free (NMObjectTypeAsyncData, async_data);
489 create_async_inited (GObject *object, GAsyncResult *result, gpointer user_data)
491 NMObjectTypeAsyncData *async_data = user_data;
492 GError *error = NULL;
494 NM_OBJECT_GET_PRIVATE (object)->inited = TRUE;
495 if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error)) {
496 dbgmsg ("Could not create object for %s: %s",
497 nm_object_get_path (NM_OBJECT (object)),
499 g_error_free (error);
500 g_clear_object (&object);
503 create_async_complete (object, async_data);
506 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
508 /* There are some object properties whose creation couldn't proceed
509 * because it depended on this object. */
510 while (priv->waiters) {
511 ObjectCreatedData *odata = priv->waiters->data;
513 priv->waiters = g_slist_remove (priv->waiters, odata);
514 object_property_maybe_complete (odata);
520 create_async_got_type (NMObjectTypeAsyncData *async_data, GType type)
524 /* Ensure we don't have the object already; we may get multiple type
525 * requests for the same object if there are multiple properties on
526 * other objects that refer to the object at this path. One of those
527 * other requests may have already completed.
529 object = (GObject *) _nm_object_cache_get (async_data->path);
531 create_async_complete (object, async_data);
535 if (type == G_TYPE_INVALID) {
536 /* Don't know how to create this object */
537 create_async_complete (NULL, async_data);
541 object = g_object_new (type,
542 NM_OBJECT_PATH, async_data->path,
543 NM_OBJECT_DBUS_CONNECTION, async_data->connection,
545 _nm_object_cache_add (NM_OBJECT (object));
546 g_async_initable_init_async (G_ASYNC_INITABLE (object), G_PRIORITY_DEFAULT,
547 NULL, create_async_inited, async_data);
551 create_async_got_property (GObject *proxy, GAsyncResult *result, gpointer user_data)
553 NMObjectTypeAsyncData *async_data = user_data;
554 NMObjectTypeFuncData *type_data = async_data->type_data;
555 GVariant *ret, *value;
556 GError *error = NULL;
559 ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result,
560 G_VARIANT_TYPE ("(v)"), &error);
562 g_variant_get (ret, "(v)", &value);
563 type = type_data->type_func (value);
564 g_variant_unref (value);
565 g_variant_unref (ret);
567 dbgmsg ("Could not fetch property '%s' of interface '%s' on %s: %s\n",
568 type_data->property, type_data->interface, async_data->path,
570 g_clear_error (&error);
571 type = G_TYPE_INVALID;
574 create_async_got_type (async_data, type);
578 create_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
580 NMObjectTypeAsyncData *async_data = user_data;
582 GError *error = NULL;
584 proxy = _nm_dbus_new_proxy_for_connection_finish (result, &error);
586 g_warning ("Could not create proxy for %s: %s.", async_data->path, error->message);
587 g_error_free (error);
588 create_async_complete (NULL, async_data);
592 g_dbus_proxy_call (proxy,
594 g_variant_new ("(ss)",
595 async_data->type_data->interface,
596 async_data->type_data->property),
597 G_DBUS_CALL_FLAGS_NONE, -1,
599 create_async_got_property, async_data);
603 _nm_object_create_async (GType type, GDBusConnection *connection, const char *path,
604 NMObjectCreateCallbackFunc callback, gpointer user_data)
606 NMObjectTypeAsyncData *async_data;
608 async_data = g_slice_new (NMObjectTypeAsyncData);
609 async_data->path = g_strdup (path);
610 async_data->callback = callback;
611 async_data->user_data = user_data;
612 async_data->connection = g_object_ref (connection);
614 async_data->type_data = g_hash_table_lookup (type_funcs, GSIZE_TO_POINTER (type));
615 if (async_data->type_data) {
616 _nm_dbus_new_proxy_for_connection_async (connection, path,
617 DBUS_INTERFACE_PROPERTIES,
619 create_async_got_proxy, async_data);
623 create_async_got_type (async_data, type);
626 /* Stolen from dbus-glib */
628 wincaps_to_dash (const char *caps)
633 str = g_string_new (NULL);
636 if (g_ascii_isupper (*p)) {
637 if (str->len > 0 && (str->len < 2 || str->str[str->len-2] != '-'))
638 g_string_append_c (str, '-');
639 g_string_append_c (str, g_ascii_tolower (*p));
641 g_string_append_c (str, *p);
645 return g_string_free (str, FALSE);
648 /* Adds object to array if it's not already there */
650 add_to_object_array_unique (GPtrArray *array, GObject *obj)
654 g_return_if_fail (array != NULL);
657 for (i = 0; i < array->len; i++) {
658 if (g_ptr_array_index (array, i) == obj) {
659 g_object_unref (obj);
663 g_ptr_array_add (array, obj);
667 /* Places items from 'needles' that are not in 'haystack' into 'diff' */
669 array_diff (GPtrArray *needles, GPtrArray *haystack, GPtrArray *diff)
678 for (i = 0; i < needles->len; i++) {
679 obj = g_ptr_array_index (needles, i);
681 for (j = 0; j < haystack->len; j++) {
682 if (g_ptr_array_index (haystack, j) == obj)
686 if (j == haystack->len)
687 g_ptr_array_add (diff, obj);
692 queue_added_removed_signal (NMObject *self,
693 const char *signal_prefix,
697 _nm_object_queue_notify_full (self, NULL, signal_prefix, added, changed);
701 already_awaits (ObjectCreatedData *odata, GObject *object)
703 NMObject *self = odata->self;
704 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
707 if ((GObject *)odata->self == object)
710 for (iter = priv->waiters; iter; iter = g_slist_next (iter)) {
711 if (already_awaits (iter->data, object))
719 object_property_maybe_complete (ObjectCreatedData *odata)
721 NMObject *self = odata->self;
722 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
723 PropertyInfo *pi = odata->pi;
724 gboolean different = TRUE;
727 /* Only complete the array property load when all the objects are initialized. */
728 for (i = 0; i < odata->length; i++) {
729 GObject *obj = odata->objects[i];
730 NMObjectPrivate *obj_priv;
732 /* Could not load the object. Perhaps it was removed. */
736 obj_priv = NM_OBJECT_GET_PRIVATE (obj);
737 if (!obj_priv->inited) {
739 /* The object is not finished because we block its creation. */
740 if (already_awaits (odata, obj))
743 if (!g_slist_find (obj_priv->waiters, odata))
744 obj_priv->waiters = g_slist_prepend (obj_priv->waiters, odata);
750 GPtrArray *pi_old = *((GPtrArray **) pi->field);
751 GPtrArray *old = odata->array;
754 /* Build up new array */
755 new = g_ptr_array_new_full (odata->length, g_object_unref);
756 for (i = 0; i < odata->length; i++)
757 add_to_object_array_unique (new, odata->objects[i]);
759 *((GPtrArray **) pi->field) = new;
761 if (pi->signal_prefix) {
762 GPtrArray *added = g_ptr_array_sized_new (3);
763 GPtrArray *removed = g_ptr_array_sized_new (3);
765 /* Find objects in 'old' that do not exist in 'new' */
766 array_diff (old, new, removed);
768 /* Find objects in 'new' that do not exist in old */
769 array_diff (new, old, added);
771 /* Emit added & removed */
772 for (i = 0; i < removed->len; i++) {
773 queue_added_removed_signal (self,
775 g_ptr_array_index (removed, i),
779 for (i = 0; i < added->len; i++) {
780 queue_added_removed_signal (self,
782 g_ptr_array_index (added, i),
786 different = removed->len || added->len;
787 g_ptr_array_unref (added);
788 g_ptr_array_unref (removed);
790 /* No added/removed signals to send, just replace the property with
796 /* Free old array last since it will release references, thus freeing
797 * any objects in the 'removed' array.
800 g_ptr_array_unref (pi_old);
802 GObject **obj_p = pi->field;
804 different = (*obj_p != odata->objects[0]);
806 g_object_unref (*obj_p);
807 *obj_p = odata->objects[0];
810 if (different && odata->property_name)
811 _nm_object_queue_notify (self, odata->property_name);
813 if (--priv->reload_remaining == 0)
814 reload_complete (self, FALSE);
820 object_created (GObject *obj, const char *path, gpointer user_data)
822 ObjectCreatedData *odata = user_data;
824 /* We assume that on error, the creator_func printed something */
826 if (obj == NULL && g_strcmp0 (path, "/") != 0 ) {
827 NMObjectClass *object_class = NM_OBJECT_GET_CLASS (odata->self);
829 if (object_class->object_creation_failed)
830 object_class->object_creation_failed (odata->self, path);
833 odata->objects[--odata->remaining] = obj;
834 if (!odata->remaining)
835 object_property_maybe_complete (odata);
839 handle_object_property (NMObject *self, const char *property_name, GVariant *value,
840 PropertyInfo *pi, gboolean synchronously)
842 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
845 ObjectCreatedData *odata;
847 odata = g_slice_new (ObjectCreatedData);
848 odata->self = g_object_ref (self);
850 odata->objects = g_new (GObject *, 1);
851 odata->length = odata->remaining = 1;
853 odata->property_name = property_name;
855 priv->reload_remaining++;
857 path = g_variant_get_string (value, NULL);
859 if (!strcmp (path, "/")) {
860 object_created (NULL, path, odata);
864 obj = G_OBJECT (_nm_object_cache_get (path));
866 object_created (obj, path, odata);
868 } else if (synchronously) {
869 obj = _nm_object_create (pi->object_type, priv->connection, path);
870 object_created (obj, path, odata);
873 _nm_object_create_async (pi->object_type, priv->connection, path,
874 object_created, odata);
881 handle_object_array_property (NMObject *self, const char *property_name, GVariant *value,
882 PropertyInfo *pi, gboolean synchronously)
884 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
888 GPtrArray **array = pi->field;
890 ObjectCreatedData *odata;
891 guint i, len = *array ? (*array)->len : 0;
893 npaths = g_variant_n_children (value);
895 odata = g_slice_new (ObjectCreatedData);
896 odata->self = g_object_ref (self);
898 odata->objects = g_new0 (GObject *, npaths);
899 odata->length = odata->remaining = npaths;
900 odata->property_name = property_name;
902 /* Objects known at this point. */
903 odata->array = g_ptr_array_new_full (len, g_object_unref);
904 for (i = 0; i < len; i++)
905 g_ptr_array_add (odata->array, g_object_ref (g_ptr_array_index (*array, i)));
907 priv->reload_remaining++;
910 object_property_maybe_complete (odata);
914 g_variant_iter_init (&iter, value);
915 while (g_variant_iter_next (&iter, "&o", &path)) {
916 if (!strcmp (path, "/")) {
917 /* FIXME: can't happen? */
921 obj = G_OBJECT (_nm_object_cache_get (path));
923 object_created (obj, path, odata);
924 } else if (synchronously) {
925 obj = _nm_object_create (pi->object_type, priv->connection, path);
926 object_created (obj, path, odata);
928 _nm_object_create_async (pi->object_type, priv->connection, path,
929 object_created, odata);
933 if (!synchronously) {
938 return *array && ((*array)->len == npaths);
942 handle_property_changed (NMObject *self, const char *dbus_name,
943 GVariant *value, gboolean synchronously)
945 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
949 gboolean success = FALSE, found = FALSE;
952 prop_name = wincaps_to_dash (dbus_name);
954 /* Iterate through the object and its parents to find the property */
955 for (iter = priv->property_tables; iter; iter = g_slist_next (iter)) {
956 pi = g_hash_table_lookup ((GHashTable *) iter->data, prop_name);
959 /* We know about this property but aren't tracking changes on it. */
969 dbgmsg ("Property '%s' unhandled.", prop_name);
973 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (self)), prop_name);
974 if (!pspec && pi->func == demarshal_generic) {
975 dbgmsg ("%s: property '%s' changed but wasn't defined by object type %s.",
978 G_OBJECT_TYPE_NAME (self));
982 if (G_UNLIKELY (debug)) {
984 s = g_variant_print (value, FALSE);
985 dbgmsg ("PC: (%p) %s:%s => '%s' (%s%s%s)",
986 self, G_OBJECT_TYPE_NAME (self),
989 g_variant_get_type_string (value),
990 pi->object_type ? " / " : "",
991 pi->object_type ? g_type_name (pi->object_type) : "");
995 if (pspec && pi->object_type) {
996 if (g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH))
997 success = handle_object_property (self, pspec->name, value, pi, synchronously);
998 else if (g_variant_is_of_type (value, G_VARIANT_TYPE ("ao")))
999 success = handle_object_array_property (self, pspec->name, value, pi, synchronously);
1001 g_warn_if_reached ();
1005 success = (*(pi->func)) (self, pspec, value, pi->field);
1008 dbgmsg ("%s: failed to update property '%s' of object type %s.",
1011 G_OBJECT_TYPE_NAME (self));
1019 process_properties_changed (NMObject *self, GVariant *properties, gboolean synchronously)
1021 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
1026 if (priv->suppress_property_updates)
1029 g_variant_iter_init (&iter, properties);
1030 while (g_variant_iter_next (&iter, "{&sv}", &name, &value)) {
1031 handle_property_changed (self, name, value, synchronously);
1032 g_variant_unref (value);
1037 properties_changed (GDBusProxy *proxy,
1038 GVariant *properties,
1041 process_properties_changed (NM_OBJECT (user_data), properties, FALSE);
1044 #define HANDLE_TYPE(vtype, ctype, getter) \
1046 if (g_variant_is_of_type (value, vtype)) { \
1047 ctype *param = (ctype *) field; \
1048 ctype newval = getter (value); \
1049 different = *param != newval; \
1058 demarshal_generic (NMObject *object,
1063 gboolean success = TRUE;
1064 gboolean different = FALSE;
1066 if (pspec->value_type == G_TYPE_STRING) {
1067 if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) {
1068 char **param = (char **) field;
1069 const char *newval = g_variant_get_string (value, NULL);
1071 different = !!g_strcmp0 (*param, newval);
1074 *param = g_strdup (newval);
1076 } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH)) {
1077 char **param = (char **) field;
1078 const char *newval = g_variant_get_string (value, NULL);
1080 /* Handle "NULL" object paths */
1081 if (g_strcmp0 (newval, "/") == 0)
1083 different = !!g_strcmp0 (*param, newval);
1086 *param = g_strdup (newval);
1092 } else if (pspec->value_type == G_TYPE_STRV) {
1093 char ***param = (char ***)field;
1094 const char **newval;
1097 newval = g_variant_get_strv (value, NULL);
1101 if (!_nm_utils_strv_equal ((char **) newval, *param)) {
1103 g_strfreev (*param);
1107 for (i = 0; newval[i]; i++)
1108 newval[i] = g_strdup (newval[i]);
1109 *param = (char **) newval;
1112 } else if (pspec->value_type == G_TYPE_BYTES) {
1113 GBytes **param = (GBytes **)field;
1114 gconstpointer val, old_val = NULL;
1115 gsize length, old_length = 0;
1117 val = g_variant_get_fixed_array (value, &length, 1);
1120 old_val = g_bytes_get_data (*param, &old_length);
1121 different = old_length != length
1123 && memcmp (old_val, val, length) != 0);
1126 g_bytes_unref (*param);
1127 *param = length > 0 ? g_bytes_new (val, length) : NULL;
1129 } else if (G_IS_PARAM_SPEC_ENUM (pspec)) {
1130 int *param = (int *) field;
1133 if (g_variant_is_of_type (value, G_VARIANT_TYPE_INT32))
1134 newval = g_variant_get_int32 (value);
1135 else if (g_variant_is_of_type (value, G_VARIANT_TYPE_UINT32))
1136 newval = g_variant_get_uint32 (value);
1141 different = *param != newval;
1143 } else if (G_IS_PARAM_SPEC_FLAGS (pspec)) {
1144 guint *param = (guint *) field;
1147 if (g_variant_is_of_type (value, G_VARIANT_TYPE_INT32))
1148 newval = g_variant_get_int32 (value);
1149 else if (g_variant_is_of_type (value, G_VARIANT_TYPE_UINT32))
1150 newval = g_variant_get_uint32 (value);
1155 different = *param != newval;
1157 } else if (pspec->value_type == G_TYPE_BOOLEAN)
1158 HANDLE_TYPE (G_VARIANT_TYPE_BOOLEAN, gboolean, g_variant_get_boolean);
1159 else if (pspec->value_type == G_TYPE_UCHAR)
1160 HANDLE_TYPE (G_VARIANT_TYPE_BYTE, guchar, g_variant_get_byte);
1161 else if (pspec->value_type == G_TYPE_DOUBLE) {
1162 NM_PRAGMA_WARNING_DISABLE("-Wfloat-equal")
1163 HANDLE_TYPE (G_VARIANT_TYPE_DOUBLE, gdouble, g_variant_get_double);
1164 NM_PRAGMA_WARNING_REENABLE
1165 } else if (pspec->value_type == G_TYPE_INT)
1166 HANDLE_TYPE (G_VARIANT_TYPE_INT32, gint, g_variant_get_int32);
1167 else if (pspec->value_type == G_TYPE_UINT)
1168 HANDLE_TYPE (G_VARIANT_TYPE_UINT32, guint, g_variant_get_uint32);
1169 else if (pspec->value_type == G_TYPE_INT64)
1170 HANDLE_TYPE (G_VARIANT_TYPE_INT64, gint, g_variant_get_int64);
1171 else if (pspec->value_type == G_TYPE_UINT64)
1172 HANDLE_TYPE (G_VARIANT_TYPE_UINT64, guint, g_variant_get_uint64);
1173 else if (pspec->value_type == G_TYPE_LONG)
1174 HANDLE_TYPE (G_VARIANT_TYPE_INT64, glong, g_variant_get_int64);
1175 else if (pspec->value_type == G_TYPE_ULONG)
1176 HANDLE_TYPE (G_VARIANT_TYPE_UINT64, gulong, g_variant_get_uint64);
1178 g_warning ("%s: %s:%s unhandled type %s.",
1180 G_OBJECT_TYPE_NAME (object),
1182 g_type_name (pspec->value_type));
1189 _nm_object_queue_notify (object, pspec->name);
1191 dbgmsg ("%s: %s:%s (type %s) couldn't be set from D-Bus type %s.",
1192 __func__, G_OBJECT_TYPE_NAME (object), pspec->name,
1193 g_type_name (pspec->value_type), g_variant_get_type_string (value));
1199 _nm_object_register_properties (NMObject *object,
1200 const char *interface,
1201 const NMPropertiesInfo *info)
1203 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1205 static gsize dval = 0;
1206 const char *debugstr;
1207 NMPropertiesInfo *tmp;
1208 GHashTable *instance;
1210 g_return_if_fail (NM_IS_OBJECT (object));
1211 g_return_if_fail (interface != NULL);
1212 g_return_if_fail (info != NULL);
1214 if (g_once_init_enter (&dval)) {
1215 debugstr = getenv ("LIBNM_GLIB_DEBUG");
1216 if (debugstr && strstr (debugstr, "properties-changed"))
1218 g_once_init_leave (&dval, 1);
1221 proxy = _nm_object_get_proxy (object, interface);
1222 g_return_if_fail (proxy != NULL);
1224 _nm_dbus_signal_connect (proxy, "PropertiesChanged", G_VARIANT_TYPE ("(a{sv})"),
1225 G_CALLBACK (properties_changed), object);
1227 instance = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1228 priv->property_tables = g_slist_prepend (priv->property_tables, instance);
1230 for (tmp = (NMPropertiesInfo *) info; tmp->name; tmp++) {
1233 if (!tmp->name || (tmp->func && !tmp->field)) {
1234 g_warning ("%s: missing field in NMPropertiesInfo", __func__);
1238 pi = g_malloc0 (sizeof (PropertyInfo));
1239 pi->func = tmp->func ? tmp->func : demarshal_generic;
1240 pi->object_type = tmp->object_type;
1241 pi->field = tmp->field;
1242 pi->signal_prefix = tmp->signal_prefix;
1243 g_hash_table_insert (instance, g_strdup (tmp->name), pi);
1248 _nm_object_reload_properties (NMObject *object, GError **error)
1250 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1251 GVariant *ret, *props;
1252 GHashTableIter iter;
1253 const char *interface;
1256 if (!g_hash_table_size (priv->proxies) || !priv->nm_running)
1259 priv->reload_remaining++;
1261 g_hash_table_iter_init (&iter, priv->proxies);
1262 while (g_hash_table_iter_next (&iter, (gpointer *) &interface, (gpointer *) &proxy)) {
1263 ret = _nm_dbus_proxy_call_sync (priv->properties_proxy,
1265 g_variant_new ("(s)", interface),
1266 G_VARIANT_TYPE ("(a{sv})"),
1267 G_DBUS_CALL_FLAGS_NONE, -1,
1270 if (error && *error)
1271 g_dbus_error_strip_remote_error (*error);
1275 g_variant_get (ret, "(@a{sv})", &props);
1276 process_properties_changed (object, props, TRUE);
1277 g_variant_unref (props);
1278 g_variant_unref (ret);
1281 if (--priv->reload_remaining == 0)
1282 reload_complete (object, TRUE);
1288 _nm_object_suppress_property_updates (NMObject *object, gboolean suppress)
1290 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1292 priv->suppress_property_updates = suppress;
1297 _nm_object_reload_property (NMObject *object,
1298 const char *interface,
1299 const char *prop_name)
1301 GVariant *ret, *value;
1304 g_return_if_fail (NM_IS_OBJECT (object));
1305 g_return_if_fail (interface != NULL);
1306 g_return_if_fail (prop_name != NULL);
1308 if (!NM_OBJECT_GET_PRIVATE (object)->nm_running)
1311 ret = _nm_dbus_proxy_call_sync (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
1313 g_variant_new ("(ss)", interface, prop_name),
1314 G_VARIANT_TYPE ("(v)"),
1315 G_DBUS_CALL_FLAGS_NONE, 15000,
1318 dbgmsg ("%s: Error getting '%s' for %s: %s\n",
1321 nm_object_get_path (object),
1323 g_clear_error (&err);
1327 g_variant_get (ret, "(v)", &value);
1328 handle_property_changed (object, prop_name, value, TRUE);
1329 g_variant_unref (value);
1330 g_variant_unref (ret);
1334 _nm_object_set_property (NMObject *object,
1335 const char *interface,
1336 const char *prop_name,
1337 const char *format_string,
1340 GVariant *val, *ret;
1343 g_return_if_fail (NM_IS_OBJECT (object));
1344 g_return_if_fail (interface != NULL);
1345 g_return_if_fail (prop_name != NULL);
1346 g_return_if_fail (format_string != NULL);
1348 if (!NM_OBJECT_GET_PRIVATE (object)->nm_running)
1351 va_start (ap, format_string);
1352 val = g_variant_new_va (format_string, NULL, &ap);
1354 g_return_if_fail (val != NULL);
1356 ret = g_dbus_proxy_call_sync (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
1358 g_variant_new ("(ssv)", interface, prop_name, val),
1359 G_DBUS_CALL_FLAGS_NONE, 2000,
1361 /* Ignore errors. */
1363 g_variant_unref (ret);
1367 reload_complete (NMObject *object, gboolean emit_now)
1369 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1370 GSimpleAsyncResult *simple;
1371 GSList *results, *iter;
1375 nm_clear_g_source (&priv->notify_id);
1376 deferred_notify_cb (object);
1378 _nm_object_defer_notify (object);
1380 results = priv->reload_results;
1381 priv->reload_results = NULL;
1382 error = priv->reload_error;
1383 priv->reload_error = NULL;
1385 for (iter = results; iter; iter = iter->next) {
1386 simple = iter->data;
1389 g_simple_async_result_set_from_error (simple, error);
1391 g_simple_async_result_set_op_res_gboolean (simple, TRUE);
1393 g_simple_async_result_complete (simple);
1394 g_object_unref (simple);
1396 g_slist_free (results);
1397 g_clear_error (&error);
1401 reload_got_properties (GObject *proxy,
1402 GAsyncResult *result,
1405 NMObject *object = user_data;
1406 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1407 GVariant *ret, *props;
1408 GError *error = NULL;
1410 ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result,
1411 G_VARIANT_TYPE ("(a{sv})"),
1414 g_variant_get (ret, "(@a{sv})", &props);
1415 process_properties_changed (object, props, FALSE);
1416 g_variant_unref (props);
1417 g_variant_unref (ret);
1419 g_dbus_error_strip_remote_error (error);
1420 if (priv->reload_error)
1421 g_error_free (error);
1423 priv->reload_error = error;
1426 if (--priv->reload_remaining == 0)
1427 reload_complete (object, FALSE);
1431 _nm_object_reload_properties_async (NMObject *object,
1432 GCancellable *cancellable,
1433 GAsyncReadyCallback callback,
1436 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1437 GSimpleAsyncResult *simple;
1438 GHashTableIter iter;
1439 const char *interface;
1442 simple = g_simple_async_result_new (G_OBJECT (object), callback,
1443 user_data, _nm_object_reload_properties_async);
1445 if (!g_hash_table_size (priv->proxies) || !priv->nm_running) {
1446 g_simple_async_result_complete_in_idle (simple);
1447 g_object_unref (simple);
1451 priv->reload_results = g_slist_prepend (priv->reload_results, simple);
1453 /* If there was already a reload happening, we don't need to
1454 * re-read the properties again, we just need to wait for the
1455 * existing reload to finish.
1457 if (priv->reload_results->next)
1460 g_hash_table_iter_init (&iter, priv->proxies);
1461 while (g_hash_table_iter_next (&iter, (gpointer *) &interface, (gpointer *) &proxy)) {
1462 priv->reload_remaining++;
1463 g_dbus_proxy_call (priv->properties_proxy,
1465 g_variant_new ("(s)", interface),
1466 G_DBUS_CALL_FLAGS_NONE, -1,
1468 reload_got_properties, object);
1473 _nm_object_reload_properties_finish (NMObject *object, GAsyncResult *result, GError **error)
1475 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1476 GSimpleAsyncResult *simple;
1478 g_return_val_if_fail (NM_IS_OBJECT (object), FALSE);
1479 g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (object), _nm_object_reload_properties_async), FALSE);
1481 /* NM might have disappeared meanwhile. That would cause a NoReply error to be emitted,
1482 * but we don't care if property updates were disabled. */
1483 if (priv->suppress_property_updates)
1486 simple = G_SIMPLE_ASYNC_RESULT (result);
1487 if (g_simple_async_result_propagate_error (simple, error))
1490 return g_simple_async_result_get_op_res_gboolean (simple);
1494 _nm_object_get_nm_running (NMObject *self)
1496 return NM_OBJECT_GET_PRIVATE (self)->nm_running;
1499 /**************************************************************/
1502 on_name_owner_changed (GObject *proxy,
1506 NMObject *self = NM_OBJECT (user_data);
1507 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
1508 gboolean now_running;
1511 now_running = ((owner = g_dbus_proxy_get_name_owner (priv->properties_proxy)) != NULL);
1513 if (now_running != priv->nm_running) {
1514 priv->nm_running = now_running;
1515 g_object_notify (G_OBJECT (self), NM_OBJECT_NM_RUNNING);
1520 init_dbus (NMObject *object)
1522 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1525 if (_nm_dbus_is_connection_private (priv->connection))
1526 priv->nm_running = TRUE;
1528 priv->nm_running = ((owner = g_dbus_proxy_get_name_owner (priv->properties_proxy)) != NULL);
1530 g_signal_connect (priv->properties_proxy, "notify::g-name-owner",
1531 G_CALLBACK (on_name_owner_changed), object);
1536 init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
1538 NMObject *self = NM_OBJECT (initable);
1539 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
1540 NMObjectClassPrivate *cpriv = NM_OBJECT_CLASS_GET_PRIVATE (NM_OBJECT_GET_CLASS (self));
1544 g_set_error_literal (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
1545 _("Caller did not specify D-Bus path for object"));
1549 if (!priv->connection)
1550 priv->connection = _nm_dbus_new_connection (cancellable, error);
1551 if (!priv->connection)
1554 /* Create proxies */
1555 for (iter = cpriv->interfaces; iter; iter = iter->next) {
1556 const char *interface = iter->data;
1559 proxy = _nm_dbus_new_proxy_for_connection (priv->connection, priv->path, interface,
1560 cancellable, error);
1563 g_hash_table_insert (priv->proxies, (char *) interface, proxy);
1566 priv->properties_proxy = _nm_dbus_new_proxy_for_connection (priv->connection,
1568 DBUS_INTERFACE_PROPERTIES,
1569 cancellable, error);
1570 if (!priv->properties_proxy)
1573 NM_OBJECT_GET_CLASS (self)->init_dbus (self);
1575 return _nm_object_reload_properties (self, error);
1578 /**************************************************************/
1582 GSimpleAsyncResult *simple;
1583 GCancellable *cancellable;
1584 int proxies_pending;
1589 init_async_complete (NMObjectInitData *init_data)
1591 if (init_data->error)
1592 g_simple_async_result_take_error (init_data->simple, init_data->error);
1594 g_simple_async_result_set_op_res_gboolean (init_data->simple, TRUE);
1595 g_simple_async_result_complete (init_data->simple);
1596 g_object_unref (init_data->simple);
1597 g_clear_object (&init_data->cancellable);
1598 g_slice_free (NMObjectInitData, init_data);
1602 init_async_got_properties (GObject *object, GAsyncResult *result, gpointer user_data)
1604 NMObjectInitData *init_data = user_data;
1606 _nm_object_reload_properties_finish (NM_OBJECT (object), result, &init_data->error);
1607 init_async_complete (init_data);
1611 init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
1613 NMObjectInitData *init_data = user_data;
1614 NMObject *self = init_data->object;
1615 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
1618 if (!init_data->error) {
1619 proxy = _nm_dbus_new_proxy_for_connection_finish (result, &init_data->error);
1621 const char *interface = g_dbus_proxy_get_interface_name (proxy);
1623 if (!strcmp (interface, DBUS_INTERFACE_PROPERTIES))
1624 priv->properties_proxy = proxy;
1626 g_hash_table_insert (priv->proxies, (char *) interface, proxy);
1630 init_data->proxies_pending--;
1631 if (init_data->proxies_pending)
1634 if (init_data->error) {
1635 init_async_complete (init_data);
1639 NM_OBJECT_GET_CLASS (self)->init_dbus (self);
1641 _nm_object_reload_properties_async (init_data->object, init_data->cancellable, init_async_got_properties, init_data);
1645 init_async_got_bus (GObject *object, GAsyncResult *result, gpointer user_data)
1647 NMObjectInitData *init_data = user_data;
1648 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (init_data->object);
1649 NMObjectClassPrivate *cpriv = NM_OBJECT_CLASS_GET_PRIVATE (NM_OBJECT_GET_CLASS (init_data->object));
1652 priv->connection = _nm_dbus_new_connection_finish (result, &init_data->error);
1653 if (!priv->connection) {
1654 init_async_complete (init_data);
1658 for (iter = cpriv->interfaces; iter; iter = iter->next) {
1659 const char *interface = iter->data;
1661 _nm_dbus_new_proxy_for_connection_async (priv->connection,
1662 priv->path, interface,
1663 init_data->cancellable,
1664 init_async_got_proxy, init_data);
1665 init_data->proxies_pending++;
1668 _nm_dbus_new_proxy_for_connection_async (priv->connection,
1670 DBUS_INTERFACE_PROPERTIES,
1671 init_data->cancellable,
1672 init_async_got_proxy, init_data);
1673 init_data->proxies_pending++;
1677 init_async (GAsyncInitable *initable, int io_priority,
1678 GCancellable *cancellable, GAsyncReadyCallback callback,
1681 NMObject *self = NM_OBJECT (initable);
1682 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
1683 NMObjectInitData *init_data;
1686 g_simple_async_report_error_in_idle (G_OBJECT (initable),
1687 callback, user_data,
1689 NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
1691 _("Caller did not specify D-Bus path for object"));
1695 init_data = g_slice_new0 (NMObjectInitData);
1696 init_data->object = self;
1697 init_data->simple = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async);
1698 init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
1700 _nm_dbus_new_connection_async (cancellable, init_async_got_bus, init_data);
1704 init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error)
1706 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
1708 if (g_simple_async_result_propagate_error (simple, error))
1714 /**************************************************************/
1717 nm_object_initable_iface_init (GInitableIface *iface)
1719 iface->init = init_sync;
1723 nm_object_async_initable_iface_init (GAsyncInitableIface *iface)
1725 iface->init_async = init_async;
1726 iface->init_finish = init_finish;
1730 nm_object_init (NMObject *object)
1732 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1734 priv->proxies = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
1738 set_property (GObject *object, guint prop_id,
1739 const GValue *value, GParamSpec *pspec)
1741 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1745 /* Construct only */
1746 priv->path = g_value_dup_string (value);
1748 case PROP_DBUS_CONNECTION:
1749 /* Construct only */
1750 priv->connection = g_value_dup_object (value);
1753 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1759 get_property (GObject *object, guint prop_id,
1760 GValue *value, GParamSpec *pspec)
1762 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1766 g_value_set_string (value, priv->path);
1768 case PROP_DBUS_CONNECTION:
1769 g_value_set_object (value, priv->connection);
1771 case PROP_NM_RUNNING:
1772 g_value_set_boolean (value, priv->nm_running);
1775 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1781 dispose (GObject *object)
1783 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1785 nm_clear_g_source (&priv->notify_id);
1787 g_slist_free_full (priv->notify_items, (GDestroyNotify) notify_item_free);
1788 priv->notify_items = NULL;
1790 g_slist_free_full (priv->waiters, odata_free);
1791 g_clear_pointer (&priv->proxies, g_hash_table_unref);
1792 g_clear_object (&priv->properties_proxy);
1794 g_clear_object (&priv->connection);
1796 G_OBJECT_CLASS (nm_object_parent_class)->dispose (object);
1800 finalize (GObject *object)
1802 NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
1804 g_slist_free_full (priv->property_tables, (GDestroyNotify) g_hash_table_destroy);
1805 g_free (priv->path);
1807 G_OBJECT_CLASS (nm_object_parent_class)->finalize (object);
1811 nm_object_class_init (NMObjectClass *nm_object_class)
1813 GObjectClass *object_class = G_OBJECT_CLASS (nm_object_class);
1815 g_type_class_add_private (nm_object_class, sizeof (NMObjectPrivate));
1817 /* virtual methods */
1818 object_class->set_property = set_property;
1819 object_class->get_property = get_property;
1820 object_class->dispose = dispose;
1821 object_class->finalize = finalize;
1823 nm_object_class->init_dbus = init_dbus;
1830 * The D-Bus object path.
1832 g_object_class_install_property
1833 (object_class, PROP_PATH,
1834 g_param_spec_string (NM_OBJECT_PATH, "", "",
1837 G_PARAM_CONSTRUCT_ONLY |
1838 G_PARAM_STATIC_STRINGS));
1841 * NMObject:dbus-connection: (skip)
1843 * The #GDBusConnection of the object.
1845 g_object_class_install_property
1846 (object_class, PROP_DBUS_CONNECTION,
1847 g_param_spec_object (NM_OBJECT_DBUS_CONNECTION, "", "",
1848 G_TYPE_DBUS_CONNECTION,
1850 G_PARAM_CONSTRUCT_ONLY |
1851 G_PARAM_STATIC_STRINGS));
1854 * NMObject:manager-running: (skip)
1856 * Internal use only.
1858 g_object_class_install_property
1859 (object_class, PROP_NM_RUNNING,
1860 g_param_spec_boolean (NM_OBJECT_NM_RUNNING, "", "",
1863 G_PARAM_STATIC_STRINGS));