diff options
| author | Michael Biebl <biebl@debian.org> | 2019-12-18 18:29:24 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2019-12-18 18:29:24 +0100 |
| commit | 28028b26b3371756811e95d894f709f4b1207c00 (patch) | |
| tree | 6fe7316fd743b51042db47601a8ef8814b3134ac /libnm | |
| parent | e22609983008e1a669196ad64ba3a59ae8c76e0d (diff) | |
New upstream version 1.22.0 upstream/1.22.0
Diffstat (limited to 'libnm')
121 files changed, 12957 insertions, 14656 deletions
diff --git a/libnm/NetworkManager.h b/libnm/NetworkManager.h index 497dc753..6a0f1178 100644 --- a/libnm/NetworkManager.h +++ b/libnm/NetworkManager.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2014 - 2018 Red Hat, Inc. + * Copyright (C) 2014 - 2018 Red Hat, Inc. */ #ifndef __NETWORKMANAGER_H__ diff --git a/libnm/generate-plugin-docs.pl b/libnm/generate-plugin-docs.pl index a16374ad..540ecb6e 100755 --- a/libnm/generate-plugin-docs.pl +++ b/libnm/generate-plugin-docs.pl @@ -1,22 +1,7 @@ #!/usr/bin/env perl - -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# +# SPDX-License-Identifier: GPL-2.0+ # -# Copyright 2014 Red Hat, Inc. +# Copyright (C) 2014 Red Hat, Inc. # # diff --git a/libnm/generate-setting-docs.py b/libnm/generate-setting-docs.py index 7e890074..025689ea 100755 --- a/libnm/generate-setting-docs.py +++ b/libnm/generate-setting-docs.py @@ -1,20 +1,8 @@ #!/usr/bin/env python -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. +# SPDX-License-Identifier: LGPL-2.1+ # -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. +# Copyright (C) 2009 - 2017 Red Hat, Inc. # -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -# Boston, MA 02110-1301 USA. -# -# Copyright 2009 - 2017 Red Hat, Inc. from __future__ import print_function diff --git a/libnm/libnm.ver b/libnm/libnm.ver index be05d647..fb5a4f64 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1633,3 +1633,22 @@ libnm_1_20_6 { global: nm_setting_802_1x_get_optional; } libnm_1_20_0; + +libnm_1_22_0 { +global: + nm_client_get_context_busy_watcher; + nm_client_get_dbus_connection; + nm_client_get_dbus_name_owner; + nm_client_get_main_context; + nm_client_get_metered; + nm_client_reload; + nm_client_reload_finish; + nm_device_get_interface_flags; + nm_device_interface_flags_get_type; + nm_dhcp_hostname_flags_get_type; + nm_ip_address_cmp_flags_get_type; + nm_ip_address_cmp_full; + nm_manager_reload_flags_get_type; + nm_setting_gsm_get_auto_config; + nm_setting_ip_config_get_dhcp_hostname_flags; +} libnm_1_20_0; diff --git a/libnm/meson.build b/libnm/meson.build index 710ef181..51ca46d2 100644 --- a/libnm/meson.build +++ b/libnm/meson.build @@ -1,6 +1,12 @@ libnm_inc = include_directories('.') -cflags = [ +libnm_nm_default_dep = declare_dependency( + sources: libnm_core_enum_sources[1], + include_directories: libnm_inc, + dependencies: libnm_core_nm_default_dep, +) + +c_flags = [ '-DG_LOG_DOMAIN="@0@"'.format(libnm_name), '-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIBNM', ] @@ -55,16 +61,15 @@ libnm_headers = files( ) install_headers( - libnm_core_headers + libnm_headers + [version_header], + libnm_core_headers + libnm_headers + [nm_version_macro_header], subdir: libnm_name, ) -enum_headers = libnm_headers + [version_header] enum_types = 'nm-enum-types' -libnm_enum = gnome.mkenums( +libnm_enum_sources = gnome.mkenums( enum_types, - sources: enum_headers, + sources: libnm_headers + [nm_version_macro_header], identifier_prefix: nm_id_prefix, c_template: enum_types + '.c.template', h_template: enum_types + '.h.template', @@ -114,10 +119,8 @@ libnm_sources = files( 'nm-ip4-config.c', 'nm-ip6-config.c', 'nm-libnm-utils.c', - 'nm-manager.c', 'nm-object.c', 'nm-remote-connection.c', - 'nm-remote-settings.c', 'nm-secret-agent-old.c', 'nm-vpn-connection.c', 'nm-vpn-editor.c', @@ -127,65 +130,45 @@ libnm_sources = files( 'nm-wimax-nsp.c', ) -linker_script = join_paths(meson.current_source_dir(), 'libnm.ver') +deps = [ + libnmdbus_dep, + libnm_libnm_core_intern_dep, + libnm_nm_default_dep, + libnm_udev_aux_dep, + libudev_dep, +] liblibnm = static_library( 'libnm', - sources: libnm_sources + libnm_enum, - include_directories: libnm_core_inc, - dependencies: [ - libnmdbus_dep, - dl_dep, - libudev_dep, - shared_nm_glib_aux_dep, - libnm_core_dep, - uuid_dep, - libnm_systemd_shared_no_logging_dep, - ], - c_args: cflags, + sources: libnm_sources + libnm_enum_sources, + dependencies: deps, + c_args: c_flags, + link_with: libnm_systemd_logging_stub, ) -liblibnm_dep = declare_dependency( - sources: libnm_enum[1], - include_directories: [ - libnm_inc, - libnm_core_inc, - ], - dependencies: [ - libnm_core_dep, - libnm_systemd_shared_no_logging_dep, - libnmdbus_dep, - shared_nm_glib_aux_dep, - libudev_dep, - dl_dep, - uuid_dep, - ], -) +links = [ + liblibnm, + libnm_core, + libnmdbus, + libnm_systemd_logging_stub, + libnm_utils_base, +] + +linker_script = join_paths(meson.current_source_dir(), 'libnm.ver') libnm = shared_library( 'nm', version: libnm_version, - link_whole: [ - liblibnm, - libnm_core, - libnm_systemd_logging_stub, - libnmdbus, - shared_nm_glib_aux, - ], - dependencies: liblibnm_dep, - link_args: [ - '-Wl,--version-script,@0@'.format(linker_script), - ], + dependencies: libnm_nm_default_dep, + link_whole: links, + link_args: '-Wl,--version-script,@0@'.format(linker_script), link_depends: linker_script, install: true, ) libnm_dep = declare_dependency( - sources: libnm_enum[1], - include_directories: [ - libnm_inc, - libnm_core_inc, - ], + sources: libnm_enum_sources[1], + include_directories: libnm_inc, link_with: libnm, ) @@ -210,21 +193,19 @@ test( ) if enable_introspection - gir_sources = libnm_core_enum + libnm_core_headers + libnm_core_sources + libnm_enum + libnm_headers + libnm_sources + [version_header] libnm_gir = gnome.generate_gir( libnm, - sources: gir_sources, + sources: libnm_core_sources + libnm_core_headers + libnm_core_enum_sources + libnm_sources + libnm_headers + libnm_enum_sources + [nm_version_macro_header], + includes: 'Gio-2.0', nsversion: nm_gir_version, namespace: 'NM', identifier_prefix: nm_id_prefix, symbol_prefix: nm_id_prefix.to_lower(), - export_packages: libnm_name, - includes: 'Gio-2.0', - extra_args: cflags, header: 'NetworkManager.h', + export_packages: libnm_name, + extra_args: c_flags, install: true, - depends: libnm_dep, ) generate_plugin_docs = join_paths(meson.current_source_dir(), 'generate-plugin-docs.pl') @@ -287,9 +268,9 @@ if enable_introspection name = 'nm-settings-docs.xml' nm_settings_docs = custom_target( name, - input: libnm_gir[0], + input: [libnm_gir[0], nm_settings_docs_overrides], output: name, - command: [generate_setting_docs_env, python.path(), generate_setting_docs, '--lib-path', meson.current_build_dir(), '--gir', '@INPUT@', '--overrides', nm_settings_docs_overrides, '--output', '@OUTPUT@'], + command: [generate_setting_docs_env, python.path(), generate_setting_docs, '--lib-path', meson.current_build_dir(), '--gir', '@INPUT0@', '--overrides', '@INPUT1@', '--output', '@OUTPUT@'], depends: libnm_gir, ) endif diff --git a/libnm/nm-access-point.c b/libnm/nm-access-point.c index 0bcab458..77ba6527 100644 --- a/libnm/nm-access-point.c +++ b/libnm/nm-access-point.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2011 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2011 Red Hat, Inc. */ #include "nm-default.h" @@ -31,25 +17,9 @@ #include "nm-dbus-interface.h" #include "nm-object-private.h" -G_DEFINE_TYPE (NMAccessPoint, nm_access_point, NM_TYPE_OBJECT) - -#define NM_ACCESS_POINT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACCESS_POINT, NMAccessPointPrivate)) - -typedef struct { - NM80211ApFlags flags; - NM80211ApSecurityFlags wpa_flags; - NM80211ApSecurityFlags rsn_flags; - GBytes *ssid; - guint32 frequency; - char *bssid; - NM80211Mode mode; - guint32 max_bitrate; - guint8 strength; - int last_seen; -} NMAccessPointPrivate; +/*****************************************************************************/ -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE (NMAccessPoint, PROP_FLAGS, PROP_WPA_FLAGS, PROP_RSN_FLAGS, @@ -61,10 +31,36 @@ enum { PROP_STRENGTH, PROP_BSSID, PROP_LAST_SEEN, +); - LAST_PROP +typedef struct { + GBytes *ssid; + char *bssid; + guint32 flags; + guint32 wpa_flags; + guint32 rsn_flags; + guint32 frequency; + guint32 mode; + guint32 max_bitrate; + gint32 last_seen; + guint8 strength; +} NMAccessPointPrivate; + +struct _NMAccessPoint { + NMObject parent; + NMAccessPointPrivate _priv; +}; + +struct _NMAccessPointClass { + NMObjectClass parent; }; +G_DEFINE_TYPE (NMAccessPoint, nm_access_point, NM_TYPE_OBJECT) + +#define NM_ACCESS_POINT_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMAccessPoint, NM_IS_ACCESS_POINT, NMObject) + +/*****************************************************************************/ + /** * nm_access_point_get_flags: * @ap: a #NMAccessPoint @@ -131,9 +127,7 @@ nm_access_point_get_ssid (NMAccessPoint *ap) g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL); priv = NM_ACCESS_POINT_GET_PRIVATE (ap); - if (!priv->ssid || g_bytes_get_size (priv->ssid) == 0) - return NULL; - + nm_assert (!priv->ssid || g_bytes_get_size (priv->ssid) > 0); return priv->ssid; } @@ -167,7 +161,7 @@ nm_access_point_get_bssid (NMAccessPoint *ap) { g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL); - return nm_str_not_empty (NM_ACCESS_POINT_GET_PRIVATE (ap)->bssid); + return _nml_coerce_property_str_not_empty (NM_ACCESS_POINT_GET_PRIVATE (ap)->bssid); } /** @@ -267,6 +261,9 @@ nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection) const char *setting_band; guint32 ap_freq, setting_chan, ap_chan; + g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), FALSE); + g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); + s_con = nm_connection_get_setting_connection (connection); if (!s_con) return FALSE; @@ -372,7 +369,12 @@ GPtrArray * nm_access_point_filter_connections (NMAccessPoint *ap, const GPtrArray *connections) { GPtrArray *filtered; - int i; + guint i; + + g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL); + + if (!connections) + return NULL; filtered = g_ptr_array_new_with_free_func (g_object_unref); for (i = 0; i < connections->len; i++) { @@ -387,6 +389,24 @@ nm_access_point_filter_connections (NMAccessPoint *ap, const GPtrArray *connecti /*****************************************************************************/ +static NMLDBusNotifyUpdatePropFlags +_notify_update_prop_hw_address (NMClient *client, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) +{ + NMAccessPoint *self = NM_ACCESS_POINT (dbobj->nmobj); + NMAccessPointPrivate *priv = NM_ACCESS_POINT_GET_PRIVATE (self); + + g_free (priv->bssid); + priv->bssid = value ? g_variant_dup_string (value, NULL) : 0u; + _notify (self, PROP_HW_ADDRESS); + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY; +} + +/*****************************************************************************/ + static void nm_access_point_init (NMAccessPoint *ap) { @@ -400,7 +420,6 @@ finalize (GObject *object) if (priv->ssid) g_bytes_unref (priv->ssid); - g_free (priv->bssid); G_OBJECT_CLASS (nm_access_point_parent_class)->finalize (object); @@ -454,122 +473,100 @@ get_property (GObject *object, } } -static void -init_dbus (NMObject *object) -{ - NMAccessPointPrivate *priv = NM_ACCESS_POINT_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_ACCESS_POINT_FLAGS, &priv->flags }, - { NM_ACCESS_POINT_WPA_FLAGS, &priv->wpa_flags }, - { NM_ACCESS_POINT_RSN_FLAGS, &priv->rsn_flags }, - { NM_ACCESS_POINT_SSID, &priv->ssid }, - { NM_ACCESS_POINT_FREQUENCY, &priv->frequency }, - /* The D-Bus property is HwAddress, but the GObject property is "bssid" */ - { NM_ACCESS_POINT_HW_ADDRESS, &priv->bssid }, - { NM_ACCESS_POINT_MODE, &priv->mode }, - { NM_ACCESS_POINT_MAX_BITRATE, &priv->max_bitrate }, - { NM_ACCESS_POINT_STRENGTH, &priv->strength }, - { NM_ACCESS_POINT_LAST_SEEN, &priv->last_seen }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_access_point_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_ACCESS_POINT, - property_info); -} +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_accesspoint = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_ACCESS_POINT, + nm_access_point_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_U ("Flags", PROP_FLAGS, NMAccessPoint, _priv.flags ), + NML_DBUS_META_PROPERTY_INIT_U ("Frequency", PROP_FREQUENCY, NMAccessPoint, _priv.frequency ), + NML_DBUS_META_PROPERTY_INIT_FCN ("HwAddress", PROP_BSSID, "s", _notify_update_prop_hw_address ), + NML_DBUS_META_PROPERTY_INIT_I ("LastSeen", PROP_LAST_SEEN, NMAccessPoint, _priv.last_seen ), + NML_DBUS_META_PROPERTY_INIT_U ("MaxBitrate", PROP_MAX_BITRATE, NMAccessPoint, _priv.max_bitrate ), + NML_DBUS_META_PROPERTY_INIT_U ("Mode", PROP_MODE, NMAccessPoint, _priv.mode ), + NML_DBUS_META_PROPERTY_INIT_U ("RsnFlags", PROP_RSN_FLAGS, NMAccessPoint, _priv.rsn_flags ), + NML_DBUS_META_PROPERTY_INIT_AY ("Ssid", PROP_SSID, NMAccessPoint, _priv.ssid ), + NML_DBUS_META_PROPERTY_INIT_Y ("Strength", PROP_STRENGTH, NMAccessPoint, _priv.strength ), + NML_DBUS_META_PROPERTY_INIT_U ("WpaFlags", PROP_WPA_FLAGS, NMAccessPoint, _priv.wpa_flags ), + ), +); static void nm_access_point_class_init (NMAccessPointClass *ap_class) { GObjectClass *object_class = G_OBJECT_CLASS (ap_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (ap_class); - - g_type_class_add_private (ap_class, sizeof (NMAccessPointPrivate)); - /* virtual methods */ object_class->get_property = get_property; - object_class->finalize = finalize; - - nm_object_class->init_dbus = init_dbus; - - /* properties */ + object_class->finalize = finalize; /** * NMAccessPoint:flags: * * The flags of the access point. **/ - g_object_class_install_property - (object_class, PROP_FLAGS, - g_param_spec_flags (NM_ACCESS_POINT_FLAGS, "", "", - NM_TYPE_802_11_AP_FLAGS, - NM_802_11_AP_FLAGS_NONE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_FLAGS] = + g_param_spec_flags (NM_ACCESS_POINT_FLAGS, "", "", + NM_TYPE_802_11_AP_FLAGS, + NM_802_11_AP_FLAGS_NONE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMAccessPoint:wpa-flags: * * The WPA flags of the access point. **/ - g_object_class_install_property - (object_class, PROP_WPA_FLAGS, - g_param_spec_flags (NM_ACCESS_POINT_WPA_FLAGS, "", "", - NM_TYPE_802_11_AP_SECURITY_FLAGS, - NM_802_11_AP_SEC_NONE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_WPA_FLAGS] = + g_param_spec_flags (NM_ACCESS_POINT_WPA_FLAGS, "", "", + NM_TYPE_802_11_AP_SECURITY_FLAGS, + NM_802_11_AP_SEC_NONE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMAccessPoint:rsn-flags: * * The RSN flags of the access point. **/ - g_object_class_install_property - (object_class, PROP_RSN_FLAGS, - g_param_spec_flags (NM_ACCESS_POINT_RSN_FLAGS, "", "", - NM_TYPE_802_11_AP_SECURITY_FLAGS, - NM_802_11_AP_SEC_NONE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_RSN_FLAGS] = + g_param_spec_flags (NM_ACCESS_POINT_RSN_FLAGS, "", "", + NM_TYPE_802_11_AP_SECURITY_FLAGS, + NM_802_11_AP_SEC_NONE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMAccessPoint:ssid: * * The SSID of the access point, or %NULL if it is not known. **/ - g_object_class_install_property - (object_class, PROP_SSID, - g_param_spec_boxed (NM_ACCESS_POINT_SSID, "", "", - G_TYPE_BYTES, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_SSID] = + g_param_spec_boxed (NM_ACCESS_POINT_SSID, "", "", + G_TYPE_BYTES, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMAccessPoint:frequency: * * The frequency of the access point. **/ - g_object_class_install_property - (object_class, PROP_FREQUENCY, - g_param_spec_uint (NM_ACCESS_POINT_FREQUENCY, "", "", - 0, 10000, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_FREQUENCY] = + g_param_spec_uint (NM_ACCESS_POINT_FREQUENCY, "", "", + 0, 10000, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMAccessPoint:bssid: * * The BSSID of the access point. **/ - g_object_class_install_property - (object_class, PROP_BSSID, - g_param_spec_string (NM_ACCESS_POINT_BSSID, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_BSSID] = + g_param_spec_string (NM_ACCESS_POINT_BSSID, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMAccessPoint:hw-address: @@ -578,12 +575,11 @@ nm_access_point_class_init (NMAccessPointClass *ap_class) * * Deprecated: 1.0: use #NMAccessPoint:bssid. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_ACCESS_POINT_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_ACCESS_POINT_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMAccessPoint:mode: @@ -592,37 +588,34 @@ nm_access_point_class_init (NMAccessPointClass *ap_class) * coordinator of the wireless network allowing clients to connect) or * "ad-hoc" (a network with no central controller). **/ - g_object_class_install_property - (object_class, PROP_MODE, - g_param_spec_enum (NM_ACCESS_POINT_MODE, "", "", - NM_TYPE_802_11_MODE, - NM_802_11_MODE_INFRA, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MODE] = + g_param_spec_enum (NM_ACCESS_POINT_MODE, "", "", + NM_TYPE_802_11_MODE, + NM_802_11_MODE_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMAccessPoint:max-bitrate: * * The maximum bit rate of the access point in kbit/s. **/ - g_object_class_install_property - (object_class, PROP_MAX_BITRATE, - g_param_spec_uint (NM_ACCESS_POINT_MAX_BITRATE, "", "", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MAX_BITRATE] = + g_param_spec_uint (NM_ACCESS_POINT_MAX_BITRATE, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMAccessPoint:strength: * * The current signal strength of the access point. **/ - g_object_class_install_property - (object_class, PROP_STRENGTH, - g_param_spec_uchar (NM_ACCESS_POINT_STRENGTH, "", "", - 0, G_MAXUINT8, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_STRENGTH] = + g_param_spec_uchar (NM_ACCESS_POINT_STRENGTH, "", "", + 0, G_MAXUINT8, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMAccessPoint:last-seen: @@ -633,10 +626,11 @@ nm_access_point_class_init (NMAccessPointClass *ap_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_LAST_SEEN, - g_param_spec_int (NM_ACCESS_POINT_LAST_SEEN, "", "", - -1, G_MAXINT, -1, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_LAST_SEEN] = + g_param_spec_int (NM_ACCESS_POINT_LAST_SEEN, "", "", + -1, G_MAXINT, -1, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_accesspoint); } diff --git a/libnm/nm-access-point.h b/libnm/nm-access-point.h index df7270ce..5f7c3150 100644 --- a/libnm/nm-access-point.h +++ b/libnm/nm-access-point.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2011 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2011 Red Hat, Inc. */ #ifndef __NM_ACCESS_POINT_H__ @@ -53,16 +39,7 @@ G_BEGIN_DECLS /** * NMAccessPoint: */ -struct _NMAccessPoint { - NMObject parent; -}; - -typedef struct { - NMObjectClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMAccessPointClass; +typedef struct _NMAccessPointClass NMAccessPointClass; GType nm_access_point_get_type (void); diff --git a/libnm/nm-active-connection.c b/libnm/nm-active-connection.c index 41a8147c..aa8504e6 100644 --- a/libnm/nm-active-connection.c +++ b/libnm/nm-active-connection.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2014 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright (C) 2007 - 2014 Red Hat, Inc. + * Copyright (C) 2008 Novell, Inc. */ #include "nm-default.h" @@ -35,34 +21,9 @@ #include "nm-ip6-config.h" #include "nm-remote-connection.h" -#include "introspection/org.freedesktop.NetworkManager.Connection.Active.h" +/*****************************************************************************/ -G_DEFINE_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT); - -#define NM_ACTIVE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionPrivate)) - -typedef struct { - NMRemoteConnection *connection; - char *id; - char *uuid; - char *type; - char *specific_object_path; - GPtrArray *devices; - NMActiveConnectionState state; - guint state_flags; - gboolean is_default; - NMIPConfig *ip4_config; - NMDhcpConfig *dhcp4_config; - gboolean is_default6; - NMIPConfig *ip6_config; - NMDhcpConfig *dhcp6_config; - gboolean is_vpn; - NMDevice *master; - NMActiveConnectionStateReason reason; -} NMActiveConnectionPrivate; - -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE (NMActiveConnection, PROP_CONNECTION, PROP_ID, PROP_UUID, @@ -79,9 +40,7 @@ enum { PROP_DHCP6_CONFIG, PROP_VPN, PROP_MASTER, - - LAST_PROP -}; +); enum { STATE_CHANGED, @@ -89,7 +48,41 @@ enum { LAST_SIGNAL }; -static guint signals[LAST_SIGNAL] = { 0 }; +static guint signals[LAST_SIGNAL]; + +enum { + PROPERTY_O_IDX_CONNECTION, + PROPERTY_O_IDX_MASTER, + PROPERTY_O_IDX_IP4_CONFIG, + PROPERTY_O_IDX_IP6_CONFIG, + PROPERTY_O_IDX_DHCP4_CONFIG, + PROPERTY_O_IDX_DHCP6_CONFIG, + _PROPERTY_O_IDX_NUM, +}; + +typedef struct _NMActiveConnectionPrivate { + NMLDBusPropertyO property_o[_PROPERTY_O_IDX_NUM]; + NMLDBusPropertyAO devices; + NMRefString *specific_object_path; + char *id; + char *uuid; + char *type; + + guint32 state; + guint32 state_flags; + + bool is_default; + bool is_default6; + bool is_vpn; + + guint32 reason; +} NMActiveConnectionPrivate; + +G_DEFINE_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT); + +#define NM_ACTIVE_CONNECTION_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMActiveConnection, NM_IS_ACTIVE_CONNECTION, NMObject) + +/*****************************************************************************/ /** * nm_active_connection_get_connection: @@ -105,7 +98,7 @@ nm_active_connection_get_connection (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->connection; + return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_CONNECTION]); } /** @@ -122,7 +115,7 @@ nm_active_connection_get_id (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - return nm_str_not_empty (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->id); + return _nml_coerce_property_str_not_empty (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->id); } /** @@ -139,7 +132,7 @@ nm_active_connection_get_uuid (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - return nm_str_not_empty (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->uuid); + return _nml_coerce_property_str_not_empty (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->uuid); } /** @@ -156,7 +149,7 @@ nm_active_connection_get_connection_type (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - return nm_str_not_empty (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->type); + return _nml_coerce_property_str_not_empty (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->type); } /** @@ -179,7 +172,7 @@ nm_active_connection_get_specific_object_path (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->specific_object_path; + return _nml_coerce_property_object_path (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->specific_object_path); } /** @@ -196,7 +189,7 @@ nm_active_connection_get_devices (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices; + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices); } /** @@ -282,7 +275,7 @@ nm_active_connection_get_ip4_config (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->ip4_config; + return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_IP4_CONFIG]); } /** @@ -301,7 +294,7 @@ nm_active_connection_get_dhcp4_config (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->dhcp4_config; + return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_DHCP4_CONFIG]); } /** @@ -335,7 +328,7 @@ nm_active_connection_get_ip6_config (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->ip6_config; + return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_IP6_CONFIG]); } /** @@ -354,7 +347,7 @@ nm_active_connection_get_dhcp6_config (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->dhcp6_config; + return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_DHCP6_CONFIG]); } /** @@ -386,67 +379,63 @@ nm_active_connection_get_master (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); - return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->master; + return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_MASTER]); } +/*****************************************************************************/ + static void -nm_active_connection_init (NMActiveConnection *connection) +_notify_event_state_changed (NMClient *client, + NMClientNotifyEventWithPtr *notify_event) { - NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection); - - priv->devices = g_ptr_array_new (); + gs_unref_object NMActiveConnection *self = notify_event->user_data; + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); + + /* we expose here the value cache in @priv. In practice, this is the same + * value as we received from the signal. In the unexpected case where they + * differ, the cached value of the current instance would still be more correct. */ + g_signal_emit (self, + signals[STATE_CHANGED], + 0, + (guint) priv->state, + (guint) priv->reason); } -static void -state_changed_proxy (NMDBusActiveConnectionProxy *proxy, - NMActiveConnectionState state, - NMActiveConnectionStateReason reason, - gpointer user_data) +void +_nm_active_connection_state_changed_commit (NMActiveConnection *self, + guint32 state, + guint32 reason) { - NMActiveConnection *connection = NM_ACTIVE_CONNECTION (user_data); - NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection); + NMClient *client; + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); - priv->state = state; - priv->reason = reason; - g_signal_emit (connection, signals[STATE_CHANGED], 0, state, reason); - g_object_notify (G_OBJECT (connection), NM_ACTIVE_CONNECTION_STATE); -} + client = _nm_object_get_client (self); -static void -constructed (GObject *object) -{ - GDBusProxy *proxy; + if (priv->state != state) { + priv->state = state; + _nm_client_queue_notify_object (client, + self, + obj_properties[PROP_STATE]); + } - proxy = _nm_object_get_proxy (NM_OBJECT (object), NM_DBUS_INTERFACE_ACTIVE_CONNECTION); - g_signal_connect (proxy, "state-changed", - G_CALLBACK (state_changed_proxy), object); - g_object_unref (proxy); + priv->reason = reason; - G_OBJECT_CLASS (nm_active_connection_parent_class)->constructed (object); + _nm_client_notify_event_queue_with_ptr (client, + NM_CLIENT_NOTIFY_EVENT_PRIO_GPROP + 1, + _notify_event_state_changed, + g_object_ref (self)); } +/*****************************************************************************/ + static void -dispose (GObject *object) +nm_active_connection_init (NMActiveConnection *self) { - NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object); - GDBusProxy *proxy; - - g_clear_pointer (&priv->devices, g_ptr_array_unref); + NMActiveConnectionPrivate *priv; - g_clear_object (&priv->connection); - g_clear_object (&priv->master); - g_clear_object (&priv->ip4_config); - g_clear_object (&priv->dhcp4_config); - g_clear_object (&priv->ip6_config); - g_clear_object (&priv->dhcp6_config); + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionPrivate); - proxy = _nm_object_get_proxy (NM_OBJECT (object), NM_DBUS_INTERFACE_ACTIVE_CONNECTION); - if (proxy) { - g_signal_handlers_disconnect_by_data (proxy, object); - g_object_unref (proxy); - } - - G_OBJECT_CLASS (nm_active_connection_parent_class)->dispose (object); + self->_priv = priv; } static void @@ -457,7 +446,7 @@ finalize (GObject *object) g_free (priv->id); g_free (priv->uuid); g_free (priv->type); - g_free (priv->specific_object_path); + nm_ref_string_unref (priv->specific_object_path); G_OBJECT_CLASS (nm_active_connection_parent_class)->finalize (object); } @@ -525,124 +514,90 @@ get_property (GObject *object, } } -static gboolean -demarshal_specific_object_path (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) -{ - const char *v; - char **param = (char **) field; - - /* We have to demarshal this manually, because the D-Bus property name - * ("SpecificObject"), doesn't match the object property name - * ("specific-object-path"). (The name "specific-object" is reserved for - * future use as an NMObject-valued property.) - */ - if (!g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH)) - return FALSE; - - v = g_variant_get_string (value, NULL); - - g_free (*param); - *param = nm_streq0 (v, "/") ? NULL : g_strdup (v); - return TRUE; -} +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_connection_active = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + nm_active_connection_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Connection", PROP_CONNECTION, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_CONNECTION], nm_remote_connection_get_type ), + NML_DBUS_META_PROPERTY_INIT_B ("Default", PROP_DEFAULT, NMActiveConnectionPrivate, is_default ), + NML_DBUS_META_PROPERTY_INIT_B ("Default6", PROP_DEFAULT6, NMActiveConnectionPrivate, is_default6 ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Devices", PROP_DEVICES, NMActiveConnectionPrivate, devices, nm_device_get_type ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Dhcp4Config", PROP_DHCP4_CONFIG, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_DHCP4_CONFIG], nm_dhcp4_config_get_type ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Dhcp6Config", PROP_DHCP6_CONFIG, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_DHCP6_CONFIG], nm_dhcp6_config_get_type ), + NML_DBUS_META_PROPERTY_INIT_S ("Id", PROP_ID, NMActiveConnectionPrivate, id ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Ip4Config", PROP_IP4_CONFIG, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_IP4_CONFIG], nm_ip4_config_get_type ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Ip6Config", PROP_IP6_CONFIG, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_IP6_CONFIG], nm_ip6_config_get_type ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Master", PROP_MASTER, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_MASTER], nm_device_get_type ), + NML_DBUS_META_PROPERTY_INIT_O ("SpecificObject", PROP_SPECIFIC_OBJECT_PATH, NMActiveConnectionPrivate, specific_object_path ), + NML_DBUS_META_PROPERTY_INIT_U ("State", PROP_STATE, NMActiveConnectionPrivate, state ), + NML_DBUS_META_PROPERTY_INIT_U ("StateFlags", PROP_STATE_FLAGS, NMActiveConnectionPrivate, state_flags ), + NML_DBUS_META_PROPERTY_INIT_S ("Type", PROP_TYPE, NMActiveConnectionPrivate, type ), + NML_DBUS_META_PROPERTY_INIT_S ("Uuid", PROP_UUID, NMActiveConnectionPrivate, uuid ), + NML_DBUS_META_PROPERTY_INIT_B ("Vpn", PROP_VPN, NMActiveConnectionPrivate, is_vpn ), + ), + .base_struct_offset = G_STRUCT_OFFSET (NMActiveConnection, _priv), +); static void -init_dbus (NMObject *object) +nm_active_connection_class_init (NMActiveConnectionClass *klass) { - NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_ACTIVE_CONNECTION_CONNECTION, &priv->connection, NULL, NM_TYPE_REMOTE_CONNECTION }, - { NM_ACTIVE_CONNECTION_ID, &priv->id }, - { NM_ACTIVE_CONNECTION_UUID, &priv->uuid }, - { NM_ACTIVE_CONNECTION_TYPE, &priv->type }, - { "specific-object", &priv->specific_object_path, demarshal_specific_object_path }, - { NM_ACTIVE_CONNECTION_DEVICES, &priv->devices, NULL, NM_TYPE_DEVICE }, - { NM_ACTIVE_CONNECTION_STATE, &priv->state }, - { NM_ACTIVE_CONNECTION_STATE_FLAGS, &priv->state_flags }, - { NM_ACTIVE_CONNECTION_DEFAULT, &priv->is_default }, - { NM_ACTIVE_CONNECTION_IP4_CONFIG, &priv->ip4_config, NULL, NM_TYPE_IP4_CONFIG }, - { NM_ACTIVE_CONNECTION_DHCP4_CONFIG, &priv->dhcp4_config, NULL, NM_TYPE_DHCP4_CONFIG }, - { NM_ACTIVE_CONNECTION_DEFAULT6, &priv->is_default6 }, - { NM_ACTIVE_CONNECTION_IP6_CONFIG, &priv->ip6_config, NULL, NM_TYPE_IP6_CONFIG }, - { NM_ACTIVE_CONNECTION_DHCP6_CONFIG, &priv->dhcp6_config, NULL, NM_TYPE_DHCP6_CONFIG }, - { NM_ACTIVE_CONNECTION_VPN, &priv->is_vpn }, - { NM_ACTIVE_CONNECTION_MASTER, &priv->master, NULL, NM_TYPE_DEVICE }, - - { NULL }, - }; - - NM_OBJECT_CLASS (nm_active_connection_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_ACTIVE_CONNECTION, - property_info); -} + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); -static void -nm_active_connection_class_init (NMActiveConnectionClass *ap_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (ap_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (ap_class); - - g_type_class_add_private (ap_class, sizeof (NMActiveConnectionPrivate)); + g_type_class_add_private (klass, sizeof (NMActiveConnectionPrivate)); - /* virtual methods */ object_class->get_property = get_property; - object_class->constructed = constructed; - object_class->dispose = dispose; - object_class->finalize = finalize; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_INDIRECT (nm_object_class, NMActiveConnection); - /* properties */ + _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_N (nm_object_class, NMActiveConnectionPrivate, property_o); + _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMActiveConnectionPrivate, devices); /** * NMActiveConnection:connection: * * The connection that this is an active instance of. **/ - g_object_class_install_property - (object_class, PROP_CONNECTION, - g_param_spec_object (NM_ACTIVE_CONNECTION_CONNECTION, "", "", - NM_TYPE_REMOTE_CONNECTION, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CONNECTION] = + g_param_spec_object (NM_ACTIVE_CONNECTION_CONNECTION, "", "", + NM_TYPE_REMOTE_CONNECTION, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:id: * * The active connection's ID **/ - g_object_class_install_property - (object_class, PROP_ID, - g_param_spec_string (NM_ACTIVE_CONNECTION_ID, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ID] = + g_param_spec_string (NM_ACTIVE_CONNECTION_ID, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:uuid: * * The active connection's UUID **/ - g_object_class_install_property - (object_class, PROP_UUID, - g_param_spec_string (NM_ACTIVE_CONNECTION_UUID, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_UUID] = + g_param_spec_string (NM_ACTIVE_CONNECTION_UUID, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:type: * * The active connection's type **/ - g_object_class_install_property - (object_class, PROP_TYPE, - g_param_spec_string (NM_ACTIVE_CONNECTION_TYPE, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_TYPE] = + g_param_spec_string (NM_ACTIVE_CONNECTION_TYPE, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:specific-object-path: @@ -650,37 +605,34 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class) * The path to the "specific object" of the active connection; see * nm_active_connection_get_specific_object_path() for more details. **/ - g_object_class_install_property - (object_class, PROP_SPECIFIC_OBJECT_PATH, - g_param_spec_string (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT_PATH, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_SPECIFIC_OBJECT_PATH] = + g_param_spec_string (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT_PATH, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:devices: (type GPtrArray(NMDevice)) * * The devices of the active connection. **/ - g_object_class_install_property - (object_class, PROP_DEVICES, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_DEVICES, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DEVICES] = + g_param_spec_boxed (NM_ACTIVE_CONNECTION_DEVICES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:state: * * The state of the active connection. **/ - g_object_class_install_property - (object_class, PROP_STATE, - g_param_spec_enum (NM_ACTIVE_CONNECTION_STATE, "", "", - NM_TYPE_ACTIVE_CONNECTION_STATE, - NM_ACTIVE_CONNECTION_STATE_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_STATE] = + g_param_spec_enum (NM_ACTIVE_CONNECTION_STATE, "", "", + NM_TYPE_ACTIVE_CONNECTION_STATE, + NM_ACTIVE_CONNECTION_STATE_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:state-flags: @@ -689,109 +641,108 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class) * * Since: 1.10 **/ - g_object_class_install_property - (object_class, PROP_STATE_FLAGS, - g_param_spec_uint (NM_ACTIVE_CONNECTION_STATE_FLAGS, "", "", - 0, G_MAXUINT32, - NM_ACTIVATION_STATE_FLAG_NONE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_STATE_FLAGS] = + g_param_spec_uint (NM_ACTIVE_CONNECTION_STATE_FLAGS, "", "", + 0, G_MAXUINT32, + NM_ACTIVATION_STATE_FLAG_NONE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:default: * * Whether the active connection is the default IPv4 one. **/ - g_object_class_install_property - (object_class, PROP_DEFAULT, - g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DEFAULT] = + g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:ip4-config: * * The IPv4 #NMIPConfig of the connection. **/ - g_object_class_install_property - (object_class, PROP_IP4_CONFIG, - g_param_spec_object (NM_ACTIVE_CONNECTION_IP4_CONFIG, "", "", - NM_TYPE_IP_CONFIG, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_IP4_CONFIG] = + g_param_spec_object (NM_ACTIVE_CONNECTION_IP4_CONFIG, "", "", + NM_TYPE_IP_CONFIG, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:dhcp4-config: * * The IPv4 #NMDhcpConfig of the connection. **/ - g_object_class_install_property - (object_class, PROP_DHCP4_CONFIG, - g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "", - NM_TYPE_DHCP_CONFIG, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DHCP4_CONFIG] = + g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "", + NM_TYPE_DHCP_CONFIG, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:default6: * * Whether the active connection is the default IPv6 one. **/ - g_object_class_install_property - (object_class, PROP_DEFAULT6, - g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT6, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DEFAULT6] = + g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT6, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:ip6-config: * * The IPv6 #NMIPConfig of the connection. **/ - g_object_class_install_property - (object_class, PROP_IP6_CONFIG, - g_param_spec_object (NM_ACTIVE_CONNECTION_IP6_CONFIG, "", "", - NM_TYPE_IP_CONFIG, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_IP6_CONFIG] = + g_param_spec_object (NM_ACTIVE_CONNECTION_IP6_CONFIG, "", "", + NM_TYPE_IP_CONFIG, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:dhcp6-config: * * The IPv6 #NMDhcpConfig of the connection. **/ - g_object_class_install_property - (object_class, PROP_DHCP6_CONFIG, - g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "", - NM_TYPE_DHCP_CONFIG, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DHCP6_CONFIG] = + g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "", + NM_TYPE_DHCP_CONFIG, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:vpn: * * Whether the active connection is a VPN connection. **/ - g_object_class_install_property - (object_class, PROP_VPN, - g_param_spec_boolean (NM_ACTIVE_CONNECTION_VPN, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_VPN] = + g_param_spec_boolean (NM_ACTIVE_CONNECTION_VPN, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMActiveConnection:master: * * The master device if one exists. **/ - g_object_class_install_property - (object_class, PROP_MASTER, - g_param_spec_object (NM_ACTIVE_CONNECTION_MASTER, "", "", - NM_TYPE_DEVICE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MASTER] = + g_param_spec_object (NM_ACTIVE_CONNECTION_MASTER, "", "", + NM_TYPE_DEVICE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_connection_active); + + /* TODO: the state reason should also be exposed as a property in libnm's NMActiveConnection, + * like done for NMDevice's state reason. */ + + /* TODO: the D-Bus API should also expose the state-reason as a property instead of + * a "StateChanged" signal. Like done for Device's "StateReason". */ /** * NMActiveConnection::state-changed: @@ -800,10 +751,10 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class) * @reason: the state change reason (#NMActiveConnectionStateReason) */ signals[STATE_CHANGED] = - g_signal_new ("state-changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 2, - G_TYPE_UINT, G_TYPE_UINT); + g_signal_new ("state-changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 2, + G_TYPE_UINT, G_TYPE_UINT); } diff --git a/libnm/nm-active-connection.h b/libnm/nm-active-connection.h index 2afcbfa9..15f70ca3 100644 --- a/libnm/nm-active-connection.h +++ b/libnm/nm-active-connection.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2014 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright (C) 2007 - 2014 Red Hat, Inc. + * Copyright (C) 2008 Novell, Inc. */ #ifndef __NM_ACTIVE_CONNECTION_H__ @@ -56,16 +42,7 @@ G_BEGIN_DECLS /** * NMActiveConnection: */ -struct _NMActiveConnection { - NMObject parent; -}; - -typedef struct { - NMObjectClass parent; - - /*< private >*/ - gpointer padding[8]; -} NMActiveConnectionClass; +typedef struct _NMActiveConnectionClass NMActiveConnectionClass; GType nm_active_connection_get_type (void); diff --git a/libnm/nm-autoptr.h b/libnm/nm-autoptr.h index 876ff652..78c586d4 100644 --- a/libnm/nm-autoptr.h +++ b/libnm/nm-autoptr.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 Red Hat, Inc. + * Copyright (C) 2018 Red Hat, Inc. */ #ifndef __NM_AUTOPTR_H__ @@ -33,8 +19,47 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMClient, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMAccessPoint, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMActiveConnection, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMCheckpoint, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMConnection, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDevice, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDhcpConfig, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMIPConfig, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMObject, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMRemoteConnection, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSetting, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSimpleConnection, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMWifiP2PPeer, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMWimaxNsp, g_object_unref) + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDevice6Lowpan, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceAdsl, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceBond, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceBridge, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceBt, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceDummy, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceEthernet, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceGeneric, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceIPTunnel, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceInfiniband, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceMacsec, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceMacvlan, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceModem, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceOlpcMesh, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceOvsBridge, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceOvsInterface, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceOvsPort, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDevicePpp, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceTeam, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceTun, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceVlan, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceVxlan, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceWifi, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceWifiP2P, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceWimax, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceWireGuard, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMDeviceWpan, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSetting6Lowpan, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSetting8021x, g_object_unref) @@ -84,6 +109,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingWireless, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingWirelessSecurity, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMSettingWpan, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMVpnConnection, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMVpnEditor, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMVpnEditorPlugin, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (NMVpnPluginInfo, g_object_unref) diff --git a/libnm/nm-checkpoint.c b/libnm/nm-checkpoint.c index 59681807..7c30db97 100644 --- a/libnm/nm-checkpoint.c +++ b/libnm/nm-checkpoint.c @@ -1,26 +1,27 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/>. - * - * Copyright 2017 Red Hat, Inc. + * Copyright (C) 2017 Red Hat, Inc. */ #include "nm-default.h" #include "nm-checkpoint.h" + #include "nm-core-internal.h" #include "nm-dbus-interface.h" #include "nm-device.h" #include "nm-object-private.h" +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_DEVICES, + PROP_CREATED, + PROP_ROLLBACK_TIMEOUT, +); + typedef struct { - GPtrArray *devices; + NMLDBusPropertyAO devices; gint64 created; guint32 rollback_timeout; } NMCheckpointPrivate; @@ -36,16 +37,9 @@ struct _NMCheckpointClass { G_DEFINE_TYPE (NMCheckpoint, nm_checkpoint, NM_TYPE_OBJECT) -#define NM_CHECKPOINT_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMCheckpoint, NM_IS_CHECKPOINT) - -enum { - PROP_0, - PROP_DEVICES, - PROP_CREATED, - PROP_ROLLBACK_TIMEOUT, +#define NM_CHECKPOINT_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMCheckpoint, NM_IS_CHECKPOINT, NMObject) - LAST_PROP -}; +/*****************************************************************************/ /** * nm_checkpoint_get_devices: @@ -62,7 +56,7 @@ nm_checkpoint_get_devices (NMCheckpoint *checkpoint) { g_return_val_if_fail (NM_IS_CHECKPOINT (checkpoint), NULL); - return NM_CHECKPOINT_GET_PRIVATE (checkpoint)->devices; + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_CHECKPOINT_GET_PRIVATE (checkpoint)->devices); } /** @@ -112,16 +106,6 @@ nm_checkpoint_init (NMCheckpoint *checkpoint) } static void -finalize (GObject *object) -{ - NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (NM_CHECKPOINT (object)); - - g_ptr_array_unref (priv->devices); - - G_OBJECT_CLASS (nm_checkpoint_parent_class)->finalize (object); -} - -static void get_property (GObject *object, guint prop_id, GValue *value, @@ -132,7 +116,7 @@ get_property (GObject *object, switch (prop_id) { case PROP_DEVICES: - g_value_take_boxed (value, _nm_utils_copy_object_array (priv->devices)); + g_value_take_boxed (value, _nm_utils_copy_object_array (nm_checkpoint_get_devices (checkpoint))); break; case PROP_CREATED: g_value_set_int64 (value, priv->created); @@ -146,34 +130,28 @@ get_property (GObject *object, } } -static void -init_dbus (NMObject *object) -{ - NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (NM_CHECKPOINT (object)); - const NMPropertiesInfo property_info[] = { - { NM_CHECKPOINT_DEVICES, &priv->devices, NULL, NM_TYPE_DEVICE }, - { NM_CHECKPOINT_CREATED, &priv->created }, - { NM_CHECKPOINT_ROLLBACK_TIMEOUT, &priv->rollback_timeout }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_checkpoint_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_CHECKPOINT, - property_info); -} +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_checkpoint = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_CHECKPOINT, + nm_checkpoint_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_X ("Created", PROP_CREATED, NMCheckpoint, _priv.created ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Devices", PROP_DEVICES, NMCheckpoint, _priv.devices, nm_device_get_type, .is_always_ready = TRUE ), + NML_DBUS_META_PROPERTY_INIT_U ("RollbackTimeout", PROP_ROLLBACK_TIMEOUT, NMCheckpoint, _priv.rollback_timeout ), + ), +); static void -nm_checkpoint_class_init (NMCheckpointClass *checkpoint_class) +nm_checkpoint_class_init (NMCheckpointClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (checkpoint_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (checkpoint_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); object_class->get_property = get_property; - object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMCheckpoint); + + _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMCheckpointPrivate, devices); /** * NMCheckpoint:devices: (type GPtrArray(NMDevice)) @@ -182,12 +160,11 @@ nm_checkpoint_class_init (NMCheckpointClass *checkpoint_class) * * Since: 1.12 **/ - g_object_class_install_property - (object_class, PROP_DEVICES, - g_param_spec_boxed (NM_CHECKPOINT_DEVICES, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DEVICES] = + g_param_spec_boxed (NM_CHECKPOINT_DEVICES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMCheckpoint:created: @@ -196,12 +173,11 @@ nm_checkpoint_class_init (NMCheckpointClass *checkpoint_class) * * Since: 1.12 **/ - g_object_class_install_property - (object_class, PROP_CREATED, - g_param_spec_int64 (NM_CHECKPOINT_CREATED, "", "", - G_MININT64, G_MAXINT64, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CREATED] = + g_param_spec_int64 (NM_CHECKPOINT_CREATED, "", "", + G_MININT64, G_MAXINT64, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMCheckpoint:rollback-timeout: @@ -210,10 +186,11 @@ nm_checkpoint_class_init (NMCheckpointClass *checkpoint_class) * * Since: 1.12 **/ - g_object_class_install_property - (object_class, PROP_ROLLBACK_TIMEOUT, - g_param_spec_uint (NM_CHECKPOINT_ROLLBACK_TIMEOUT, "", "", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ROLLBACK_TIMEOUT] = + g_param_spec_uint (NM_CHECKPOINT_ROLLBACK_TIMEOUT, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_checkpoint); } diff --git a/libnm/nm-checkpoint.h b/libnm/nm-checkpoint.h index d38f99f9..870e1c4e 100644 --- a/libnm/nm-checkpoint.h +++ b/libnm/nm-checkpoint.h @@ -1,14 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/>. - * - * Copyright 2017 Red Hat, Inc. + * Copyright (C) 2017 Red Hat, Inc. */ #ifndef __NM_CHECKPOINT_H__ diff --git a/libnm/nm-client.c b/libnm/nm-client.c index c39f6267..1a1ed256 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2018 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -24,33 +10,16 @@ #include <libudev.h> -#include "nm-utils.h" -#include "nm-manager.h" -#include "nm-dns-manager.h" -#include "nm-remote-settings.h" -#include "nm-device-ethernet.h" -#include "nm-device-wifi.h" -#include "nm-core-internal.h" -#include "nm-active-connection.h" -#include "nm-vpn-connection.h" -#include "nm-remote-connection.h" -#include "nm-dbus-helpers.h" -#include "nm-wimax-nsp.h" -#include "nm-object-private.h" - -#include "introspection/org.freedesktop.NetworkManager.h" -#include "introspection/org.freedesktop.NetworkManager.Device.Wireless.h" -#include "introspection/org.freedesktop.NetworkManager.Device.WifiP2P.h" -#include "introspection/org.freedesktop.NetworkManager.Device.h" -#include "introspection/org.freedesktop.NetworkManager.DnsManager.h" -#include "introspection/org.freedesktop.NetworkManager.Settings.h" -#include "introspection/org.freedesktop.NetworkManager.Settings.Connection.h" -#include "introspection/org.freedesktop.NetworkManager.VPN.Connection.h" -#include "introspection/org.freedesktop.NetworkManager.Connection.Active.h" +#include "nm-std-aux/c-list-util.h" +#include "nm-glib-aux/nm-c-list.h" +#include "nm-glib-aux/nm-dbus-aux.h" +#include "nm-libnm-core-intern/nm-common-macros.h" #include "nm-access-point.h" #include "nm-active-connection.h" #include "nm-checkpoint.h" +#include "nm-core-internal.h" +#include "nm-dbus-helpers.h" #include "nm-device-6lowpan.h" #include "nm-device-adsl.h" #include "nm-device-bond.h" @@ -75,51 +44,156 @@ #include "nm-device-vxlan.h" #include "nm-device-wifi-p2p.h" #include "nm-device-wifi.h" -#include "nm-device-wimax.h" #include "nm-device-wireguard.h" #include "nm-device-wpan.h" #include "nm-dhcp-config.h" #include "nm-dhcp4-config.h" #include "nm-dhcp6-config.h" +#include "nm-dns-manager.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" -#include "nm-manager.h" -#include "nm-wifi-p2p-peer.h" +#include "nm-object-private.h" #include "nm-remote-connection.h" -#include "nm-remote-settings.h" +#include "nm-utils.h" #include "nm-vpn-connection.h" +#include "nm-wifi-p2p-peer.h" -void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled); +/*****************************************************************************/ -static void nm_client_initable_iface_init (GInitableIface *iface); -static void nm_client_async_initable_iface_init (GAsyncInitableIface *iface); +static NM_CACHED_QUARK_FCN ("nm-client-context-busy-watcher", nm_client_context_busy_watcher_quark) -G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_client_initable_iface_init); - G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_client_async_initable_iface_init); - ) +static void +_context_busy_watcher_attach_integration_source_cb (gpointer data, + GObject *where_the_object_was) +{ + nm_g_source_destroy_and_unref (data); +} + +static void +_context_busy_watcher_attach_integration_source (GObject *context_busy_watcher, + GSource *source_take) +{ + /* The problem is... + * + * NMClient is associated with a GMainContext, just like its underlying GDBusConnection + * also queues signals and callbacks on that main context. During operation, NMClient + * will schedule async operations which will return asynchronously on the GMainContext. + * + * Note that depending on whether NMClient got initialized synchronously or asynchronously, + * it has an internal priv->dbus_context that is different from the outer priv->main_context. + * However, the problem is in both cases. + * + * So, as long as there are pending D-Bus calls, the GMainContext is referenced and kept alive. + * When NMClient gets destroyed, the pending calls get cancelled, but the async callback are still + * scheduled to return. + * That means, the main context stays alive until it gets iterated long enough so that all pending + * operations are completed. + * + * Note that pending operations don't keep NMClient alive, so NMClient can already be gone by + * then, but the user still should iterate the main context long enough to process the (cancelled) + * callbacks... at least, if the user cares about whether the remaining memory and file descriptors + * of the GMainContext can be reclaimed. + * + * In hindsight, maybe pending references should kept NMClient alive. But then NMClient would + * need a special "shutdown()" API that the user must invoke, because unrefing would no longer + * be enough to ensure a shutdown (imagine a situation where NMClient receives a constant flow + * of "CheckPermissions" signals, which keeps retriggering an async request). Anyway, we cannot + * add such a shutdown API now, as it would break client's expectations that they can just unref + * the NMClient to destroy it. + * + * So, we allow NMClient to unref, but the user is advised to keep iterating the main context. + * But for how long? Here comes nm_client_get_context_busy_watcher() into play. The user may + * subscribe a weak pointer to that instance and should keep iterating as long as the object + * exists. + * + * Now, back to synchronous initialization. Here we have the internal priv->dbus_context context. + * We also cannot remove that context right away, instead we need to keep it integrated in the + * caller's priv->main_context as long as we have pending calls: that is, as long as the + * context-busy-watcher is alive. + */ + + g_object_weak_ref (context_busy_watcher, + _context_busy_watcher_attach_integration_source_cb, + source_take); +} -#define NM_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CLIENT, NMClientPrivate)) +/*****************************************************************************/ typedef struct { - NMClient *client; - GCancellable *cancellable; - GSimpleAsyncResult *result; - int pending_init; -} NMClientInitData; + + /* It is quite wasteful to require 2 pointers per property (of an instance) only to track whether + * the property got changed. But it's convenient! */ + CList changed_prop_lst; + + GVariant *prop_data_value; +} NMLDBusObjPropData; typedef struct { - NMManager *manager; - NMRemoteSettings *settings; - NMDnsManager *dns_manager; - GDBusObjectManager *object_manager; - GCancellable *new_object_manager_cancellable; - struct udev *udev; - bool udev_inited:1; -} NMClientPrivate; + CList iface_lst; + union { + const NMLDBusMetaIface *meta; + NMRefString *name; + } dbus_iface; + + CList changed_prop_lst_head; + + /* We also keep track of non-well known interfaces. The presence of a D-Bus interface + * is what makes a D-Bus alive or not. As we should track all D-Bus objects, we also + * need to track whether there are any interfaces on it -- even if we otherwise don't + * care about the interface. */ + bool dbus_iface_is_wellknown:1; + + /* if TRUE, the interface is about to be removed. */ + bool iface_removed:1; + + bool nmobj_checked:1; + bool nmobj_compatible:1; + + NMLDBusObjPropData prop_datas[]; +} NMLDBusObjIfaceData; + +/* The dbus_path must be the first element, so when we hash the object by the dbus_path, + * we also can lookup the object by only having a NMRefString at hand + * using nm_pdirect_hash()/nm_pdirect_equal(). */ +G_STATIC_ASSERT (G_STRUCT_OFFSET (NMLDBusObject, dbus_path) == 0); + +typedef void (*NMLDBusObjWatchNotifyFcn) (NMClient *client, + gpointer obj_watcher); + +struct _NMLDBusObjWatcher { + NMLDBusObject *dbobj; + struct { + CList watcher_lst; + NMLDBusObjWatchNotifyFcn notify_fcn; + } _priv; +}; -enum { - PROP_0, +typedef struct { + NMLDBusObjWatcher parent; + gpointer user_data; +} NMLDBusObjWatcherWithPtr; + +/*****************************************************************************/ + +typedef struct { + GCancellable *cancellable; + GSource *cancel_on_idle_source; + gulong cancelled_id; + union { + struct { + GTask *task; + } async; + struct { + GMainLoop *main_loop; + GError **error_location; + } sync; + } data; + bool is_sync:1; +} InitData; + +NM_GOBJECT_PROPERTIES_DEFINE (NMClient, + PROP_DBUS_CONNECTION, + PROP_DBUS_NAME_OWNER, PROP_VERSION, PROP_STATE, PROP_STARTUP, @@ -133,6 +207,7 @@ enum { PROP_WIMAX_HARDWARE_ENABLED, PROP_ACTIVE_CONNECTIONS, PROP_CONNECTIVITY, + PROP_CONNECTIVITY_CHECK_URI, PROP_CONNECTIVITY_CHECK_AVAILABLE, PROP_CONNECTIVITY_CHECK_ENABLED, PROP_PRIMARY_CONNECTION, @@ -147,9 +222,7 @@ enum { PROP_DNS_RC_MANAGER, PROP_DNS_CONFIGURATION, PROP_CHECKPOINTS, - - LAST_PROP -}; +); enum { DEVICE_ADDED, @@ -167,7 +240,150 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; -static const GPtrArray empty = { 0, }; +enum { + PROPERTY_O_IDX_NM_ACTIVATING_CONNECTION = 0, + PROPERTY_O_IDX_NM_PRIMAY_CONNECTION, + _PROPERTY_O_IDX_NM_NUM, +}; + +enum { + PROPERTY_AO_IDX_DEVICES = 0, + PROPERTY_AO_IDX_ALL_DEVICES, + PROPERTY_AO_IDX_ACTIVE_CONNECTIONS, + PROPERTY_AO_IDX_CHECKPOINTS, + _PROPERTY_AO_IDX_NM_NUM, +}; + +typedef struct { + struct udev *udev; + GMainContext *main_context; + GMainContext *dbus_context; + GObject *context_busy_watcher; + GDBusConnection *dbus_connection; + InitData *init_data; + GHashTable *dbus_objects; + CList obj_changed_lst_head; + GCancellable *name_owner_get_cancellable; + GCancellable *get_managed_objects_cancellable; + + CList queue_notify_lst_head; + CList notify_event_lst_head; + + CList dbus_objects_lst_head_watched_only; + CList dbus_objects_lst_head_on_dbus; + CList dbus_objects_lst_head_with_nmobj_not_ready; + CList dbus_objects_lst_head_with_nmobj_ready; + + NMLDBusObject *dbobj_nm; + NMLDBusObject *dbobj_settings; + NMLDBusObject *dbobj_dns_manager; + + GHashTable *permissions; + GCancellable *permissions_cancellable; + + char *name_owner; + guint name_owner_changed_id; + guint dbsid_nm_object_manager; + guint dbsid_dbus_properties_properties_changed; + guint dbsid_nm_settings_connection_updated; + guint dbsid_nm_connection_active_state_changed; + guint dbsid_nm_vpn_connection_state_changed; + guint dbsid_nm_check_permissions; + + bool udev_inited:1; + bool notify_event_lst_changed:1; + bool check_dbobj_visible_all:1; + bool nm_running:1; + + struct { + NMLDBusPropertyO property_o[_PROPERTY_O_IDX_NM_NUM]; + NMLDBusPropertyAO property_ao[_PROPERTY_AO_IDX_NM_NUM]; + char *connectivity_check_uri; + char *version; + guint32 connectivity; + guint32 state; + guint32 metered; + bool connectivity_check_available; + bool connectivity_check_enabled; + bool networking_enabled; + bool startup; + bool wireless_enabled; + bool wireless_hardware_enabled; + bool wwan_enabled; + bool wwan_hardware_enabled; + } nm; + + struct { + NMLDBusPropertyAO connections; + char *hostname; + bool can_modify; + } settings; + + struct { + GPtrArray *configuration; + char *mode; + char *rc_manager; + } dns_manager; + +} NMClientPrivate; + +struct _NMClient { + union { + GObject parent; + NMObjectBase obj_base; + }; + NMClientPrivate _priv; +}; + +struct _NMClientClass { + union { + GObjectClass parent; + NMObjectBaseClass obj_base; + }; +}; + +static void nm_client_initable_iface_init (GInitableIface *iface); +static void nm_client_async_initable_iface_init (GAsyncInitableIface *iface); + +G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_client_initable_iface_init); + G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_client_async_initable_iface_init); + ) + +#define NM_CLIENT_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMClient, NM_IS_CLIENT) + +/*****************************************************************************/ + +static void _init_start_check_complete (NMClient *self); + +static void name_owner_changed_cb (GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data); + +static void name_owner_get_call (NMClient *self); + +static void _set_nm_running (NMClient *self); + +/*****************************************************************************/ + +static NMRefString *_dbus_path_nm = NULL; +static NMRefString *_dbus_path_settings = NULL; +static NMRefString *_dbus_path_dns_manager = NULL; + +/*****************************************************************************/ + +NM_UTILS_LOOKUP_STR_DEFINE_STATIC (nml_dbus_obj_state_to_string, NMLDBusObjState, + NM_UTILS_LOOKUP_DEFAULT_WARN ("???"), + NM_UTILS_LOOKUP_ITEM (NML_DBUS_OBJ_STATE_UNLINKED, "unlinked"), + NM_UTILS_LOOKUP_ITEM (NML_DBUS_OBJ_STATE_WATCHED_ONLY, "watched-only"), + NM_UTILS_LOOKUP_ITEM (NML_DBUS_OBJ_STATE_ON_DBUS, "on-dbus"), + NM_UTILS_LOOKUP_ITEM (NML_DBUS_OBJ_STATE_WITH_NMOBJ_NOT_READY, "not-ready"), + NM_UTILS_LOOKUP_ITEM (NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY, "ready"), +); /*****************************************************************************/ @@ -182,23 +398,3390 @@ NM_CACHED_QUARK_FCN ("nm-client-error-quark", nm_client_error_quark) /*****************************************************************************/ +static InitData * +_init_data_new_sync (GCancellable *cancellable, + GMainLoop *main_loop, + GError **error_location) +{ + InitData *init_data; + + init_data = g_slice_new (InitData); + *init_data = (InitData) { + .cancellable = nm_g_object_ref (cancellable), + .is_sync = TRUE, + .data.sync = { + .main_loop = main_loop, + .error_location = error_location, + }, + }; + return init_data; +} + +static InitData * +_init_data_new_async (GCancellable *cancellable, + GTask *task_take) +{ + InitData *init_data; + + init_data = g_slice_new (InitData); + *init_data = (InitData) { + .cancellable = nm_g_object_ref (cancellable), + .is_sync = FALSE, + .data.async = { + .task = g_steal_pointer (&task_take), + }, + }; + return init_data; +} + +/*****************************************************************************/ + +GError * +_nm_client_new_error_nm_not_running (void) +{ + return g_error_new_literal (NM_CLIENT_ERROR, + NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, + "NetworkManager is not running"); +} + +GError * +_nm_client_new_error_nm_not_cached (void) +{ + return g_error_new_literal (NM_CLIENT_ERROR, + NM_CLIENT_ERROR_FAILED, + "Object is no longer in the client cache"); +} + +static void +_nm_client_dbus_call_simple_cb (GObject *source, GAsyncResult *result, gpointer data) +{ + GAsyncReadyCallback callback; + gpointer user_data; + gs_unref_object GObject *context_busy_watcher = NULL; + + nm_utils_user_data_unpack (data, &callback, &user_data, &context_busy_watcher); + + callback (source, result, user_data); +} + +void +_nm_client_dbus_call_simple (NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, + const GVariantType *reply_type, + GDBusCallFlags flags, + int timeout_msec, + GAsyncReadyCallback callback, + gpointer user_data) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; + + nm_assert (priv->name_owner); + nm_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); + nm_assert (callback); + nm_assert (object_path); + nm_assert (interface_name); + nm_assert (method_name); + nm_assert (parameters); + nm_assert (reply_type); + + dbus_context = nm_g_main_context_push_thread_default_if_necessary (priv->dbus_context); + + g_dbus_connection_call (priv->dbus_connection, + priv->name_owner, + object_path, + interface_name, + method_name, + parameters, + reply_type, + flags, + timeout_msec, + cancellable, + _nm_client_dbus_call_simple_cb, + nm_utils_user_data_pack (callback, user_data, g_object_ref (priv->context_busy_watcher))); +} + +void +_nm_client_dbus_call (NMClient *self, + gpointer source_obj, + gpointer source_tag, + GCancellable *cancellable, + GAsyncReadyCallback user_callback, + gpointer user_callback_data, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, + const GVariantType *reply_type, + GDBusCallFlags flags, + int timeout_msec, + GAsyncReadyCallback internal_callback) +{ + NMClientPrivate *priv; + gs_unref_object GTask *task = NULL; + + nm_assert (!source_obj || G_IS_OBJECT (source_obj)); + nm_assert (source_tag); + nm_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); + nm_assert (internal_callback); + nm_assert (object_path); + nm_assert (interface_name); + nm_assert (method_name); + nm_assert (parameters); + nm_assert (reply_type); + + task = nm_g_task_new (source_obj, cancellable, source_tag, user_callback, user_callback_data); + + if (!self) { + nm_g_variant_unref_floating (parameters); + g_task_return_error (task, _nm_client_new_error_nm_not_cached ()); + return; + } + + priv = NM_CLIENT_GET_PRIVATE (self); + if (!priv->name_owner) { + nm_g_variant_unref_floating (parameters); + g_task_return_error (task, _nm_client_new_error_nm_not_running ()); + return; + } + + _nm_client_dbus_call_simple (self, + cancellable, + object_path, + interface_name, + method_name, + parameters, + reply_type, + flags, + timeout_msec, + internal_callback, + g_steal_pointer (&task)); +} + +GVariant * +_nm_client_dbus_call_sync (NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, + const GVariantType *reply_type, + GDBusCallFlags flags, + int timeout_msec, + gboolean strip_dbus_error, + GError **error) +{ + NMClientPrivate *priv; + gs_unref_variant GVariant *ret = NULL; + + nm_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); + nm_assert (!error || !*error); + nm_assert (object_path); + nm_assert (interface_name); + nm_assert (method_name); + nm_assert (parameters); + nm_assert (reply_type); + + if (!self) { + nm_g_variant_unref_floating (parameters); + nm_g_set_error_take_lazy (error, _nm_client_new_error_nm_not_cached ()); + return NULL; + } + + priv = NM_CLIENT_GET_PRIVATE (self); + if (!priv->name_owner) { + nm_g_variant_unref_floating (parameters); + nm_g_set_error_take_lazy (error, _nm_client_new_error_nm_not_running ()); + return NULL; + } + + ret = g_dbus_connection_call_sync (priv->dbus_connection, + priv->name_owner, + object_path, + interface_name, + method_name, + parameters, + reply_type, + flags, + timeout_msec, + cancellable, + error); + if (!ret) { + if (error && strip_dbus_error) + g_dbus_error_strip_remote_error (*error); + return NULL; + } + + return g_steal_pointer (&ret); +} + +gboolean +_nm_client_dbus_call_sync_void (NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, + GDBusCallFlags flags, + int timeout_msec, + gboolean strip_dbus_error, + GError **error) +{ + gs_unref_variant GVariant *ret = NULL; + + ret = _nm_client_dbus_call_sync (self, + cancellable, + object_path, + interface_name, + method_name, + parameters, + G_VARIANT_TYPE ("()"), + flags, + timeout_msec, + strip_dbus_error, + error); + return !!ret; +} + +void +_nm_client_set_property_sync_legacy (NMClient *self, + const char *object_path, + const char *interface_name, + const char *property_name, + const char *format_string, + ...) +{ + NMClientPrivate *priv; + GVariant *val; + gs_unref_variant GVariant *ret = NULL; + va_list ap; + + nm_assert (!self || NM_IS_CLIENT (self)); + nm_assert (interface_name); + nm_assert (property_name); + nm_assert (format_string); + + if (!self) + return; + + priv = NM_CLIENT_GET_PRIVATE (self); + if (!priv->name_owner) + return; + + va_start (ap, format_string); + val = g_variant_new_va (format_string, NULL, &ap); + va_end (ap); + + nm_assert (val); + + /* A synchronous D-Bus call that is not cancellable an ignores the return value. + * This function only exists for backward compatibility. */ + ret = g_dbus_connection_call_sync (priv->dbus_connection, + priv->name_owner, + object_path, + DBUS_INTERFACE_PROPERTIES, + "Set", + g_variant_new ("(ssv)", + interface_name, + property_name, + val), + NULL, + G_DBUS_CALL_FLAGS_NONE, + 2000, + NULL, + NULL); +} + +/*****************************************************************************/ + +#define _assert_main_context_is_current_source(self, x_context) \ + G_STMT_START { \ + if (NM_MORE_ASSERTS > 0) { \ + GSource *_source = g_main_current_source (); \ + \ + if (_source) { \ + NMClientPrivate *_priv = NM_CLIENT_GET_PRIVATE (self); \ + \ + nm_assert (g_source_get_context (_source) == _priv->x_context); \ + nm_assert (g_main_context_is_owner (_priv->x_context)); \ + } \ + } \ + } G_STMT_END + +#define _assert_main_context_is_current_thread_default(self, x_context) \ + G_STMT_START { \ + if (NM_MORE_ASSERTS > 0) { \ + NMClientPrivate *_priv = NM_CLIENT_GET_PRIVATE (self); \ + \ + nm_assert ((g_main_context_get_thread_default () ?: g_main_context_default ()) == _priv->x_context); \ + nm_assert (g_main_context_is_owner (_priv->x_context)); \ + } \ + } G_STMT_END + +/*****************************************************************************/ + +void +_nm_client_queue_notify_object (NMClient *self, + gpointer nmobj, + const GParamSpec *pspec) +{ + NMObjectBase *base; + + nm_assert (NM_IS_CLIENT (self)); + nm_assert (NM_IS_OBJECT (nmobj) || NM_IS_CLIENT (nmobj)); + + base = (NMObjectBase *) nmobj; + + if (base->is_disposing) { + /* Don't emit property changed signals once the NMClient + * instance is about to shut down. */ + nm_assert (nmobj == self); + return; + } + + if (c_list_is_empty (&base->queue_notify_lst)) { + c_list_link_tail (&NM_CLIENT_GET_PRIVATE (self)->queue_notify_lst_head, + &base->queue_notify_lst); + g_object_ref (nmobj); + g_object_freeze_notify (nmobj); + } + + if (pspec) + g_object_notify_by_pspec (nmobj, (GParamSpec *) pspec); +} + +/*****************************************************************************/ + +gpointer +_nm_client_notify_event_queue (NMClient *self, + int priority, + NMClientNotifyEventCb callback, + gsize event_size) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + NMClientNotifyEvent *notify_event; + + nm_assert (callback); + nm_assert (event_size > sizeof (NMClientNotifyEvent)); + + notify_event = g_malloc (event_size); + notify_event->priority = priority; + notify_event->callback = callback; + c_list_link_tail (&priv->notify_event_lst_head, ¬ify_event->lst); + priv->notify_event_lst_changed = TRUE; + return notify_event; +} + +NMClientNotifyEventWithPtr * +_nm_client_notify_event_queue_with_ptr (NMClient *self, + int priority, + NMClientNotifyEventWithPtrCb callback, + gpointer user_data) +{ + NMClientNotifyEventWithPtr *notify_event; + + notify_event = _nm_client_notify_event_queue (self, + priority, + (NMClientNotifyEventCb) callback, + sizeof (NMClientNotifyEventWithPtr)); + notify_event->user_data = user_data; + return notify_event; +} + +/*****************************************************************************/ + +typedef struct { + NMClientNotifyEvent parent; + GObject *source; + NMObject *obj; + guint signal_id; +} NMClientNotifyEventObjAddedRemove; + +static void +_nm_client_notify_event_queue_emit_obj_signal_cb (NMClient *self, + gpointer notify_event_base) +{ + NMClientNotifyEventObjAddedRemove *notify_event = notify_event_base; + + NML_NMCLIENT_LOG_T (self, "[%s] emit \"%s\" signal for %s", + NM_IS_CLIENT (notify_event->source) + ? "nmclient" + : _nm_object_get_path (notify_event->source), + g_signal_name (notify_event->signal_id), + _nm_object_get_path (notify_event->obj)); + + nm_assert ( NM_IS_OBJECT (notify_event->source) + || NM_IS_CLIENT (notify_event->source)); + + g_signal_emit (notify_event->source, + notify_event->signal_id, + 0, + notify_event->obj); + + g_object_unref (notify_event->obj); + g_object_unref (notify_event->source); +} + +void +_nm_client_notify_event_queue_emit_obj_signal (NMClient *self, + GObject *source, + NMObject *nmobj, + gboolean is_added /* or else removed */, + int prio_offset, + guint signal_id) +{ + NMClientNotifyEventObjAddedRemove *notify_event; + + nm_assert (prio_offset >= 0); + nm_assert (prio_offset < 20); + nm_assert ( NM_IS_OBJECT (source) + || NM_IS_CLIENT (source)); + nm_assert (NM_IS_OBJECT (nmobj)); + + if (((NMObjectBase *) source)->is_disposing) { + nm_assert (NM_IS_CLIENT (source)); + return; + } + + notify_event = _nm_client_notify_event_queue (self, + is_added + ? NM_CLIENT_NOTIFY_EVENT_PRIO_AFTER - 20 + prio_offset + : NM_CLIENT_NOTIFY_EVENT_PRIO_BEFORE + 20 - prio_offset, + _nm_client_notify_event_queue_emit_obj_signal_cb, + sizeof (NMClientNotifyEventObjAddedRemove)); + notify_event->source = g_object_ref (source); + notify_event->obj = g_object_ref (nmobj); + notify_event->signal_id = signal_id; +} + +/*****************************************************************************/ + +static int +_nm_client_notify_event_cmp (const CList *a, + const CList *b, + const void *user_data) +{ + NM_CMP_DIRECT (c_list_entry (a, NMClientNotifyEvent, lst)->priority, + c_list_entry (b, NMClientNotifyEvent, lst)->priority); + return 0; +} + +static void +_nm_client_notify_event_emit_parts (NMClient *self, + int max_priority /* included! */) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + NMClientNotifyEvent *notify_event; + + while (TRUE) { + if (priv->notify_event_lst_changed) { + priv->notify_event_lst_changed = FALSE; + c_list_sort (&priv->notify_event_lst_head, _nm_client_notify_event_cmp, NULL); + } + notify_event = c_list_first_entry (&priv->notify_event_lst_head, NMClientNotifyEvent, lst); + if (!notify_event) + return; + if (notify_event->priority > max_priority) + return; + c_list_unlink_stale (¬ify_event->lst); + notify_event->callback (self, notify_event); + g_free (notify_event); + } +} + +static void +_nm_client_notify_event_emit (NMClient *self) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + NMObjectBase *base; + + _nm_client_notify_event_emit_parts (self, NM_CLIENT_NOTIFY_EVENT_PRIO_GPROP); + + while ((base = c_list_first_entry (&priv->queue_notify_lst_head, NMObjectBase, queue_notify_lst))) { + c_list_unlink (&base->queue_notify_lst); + g_object_thaw_notify (G_OBJECT (base)); + g_object_unref (base); + } + + _nm_client_notify_event_emit_parts (self, G_MAXINT); +} + +/*****************************************************************************/ + +GDBusConnection * +_nm_client_get_dbus_connection (NMClient *self) +{ + return NM_CLIENT_GET_PRIVATE (self)->dbus_connection; +} + +const char * +_nm_client_get_dbus_name_owner (NMClient *self) +{ + return NM_CLIENT_GET_PRIVATE (self)->name_owner; +} + +GMainContext * +_nm_client_get_context_main (NMClient *self) +{ + return NM_CLIENT_GET_PRIVATE (self)->main_context; +} + +GMainContext * +_nm_client_get_context_dbus (NMClient *self) +{ + return NM_CLIENT_GET_PRIVATE (self)->dbus_context; +} + +/** + * nm_client_get_main_context: + * @self: the #NMClient instance + * + * The #NMClient instance is permanently associated with the current + * thread default #GMainContext, referenced the time when the instance + * was created. To receive events, the user must iterate this context + * and can use it to synchronize access to the client. + * + * Note that even after #NMClient instance got destroyed, there might + * still be pending sources registered in the context. That means, to fully + * clean up, the user must continue iterating the context as long as + * the nm_client_get_context_busy_watcher() object is alive. + * + * Returns: (transfer none): the #GMainContext of the client. + * + * Since: 1.22 + */ +GMainContext * +nm_client_get_main_context (NMClient *self) +{ + g_return_val_if_fail (NM_IS_CLIENT (self), NULL); + + return _nm_client_get_context_main (self); +} + +/** + * nm_client_get_context_busy_watcher: + * @self: the NMClient instance. + * + * Returns: (transfer none): a GObject that stays alive as long as there are pending + * D-Bus operations. + * + * NMClient will schedule asynchronous D-Bus requests which will complete on + * the GMainContext associated with the instance. When destroying the NMClient + * instance, those requests are cancelled right away, however their pending requests are + * still outstanding and queued in the GMainContext. These outstanding callbacks + * keep the GMainContext alive. In order to fully release all resources, + * the user must keep iterating the main context until all these callbacks + * are handled. Of course, at this point no more actual callbacks will be invoked + * for the user, those are all internally cancelled. + * + * This just leaves one problem: how long does the user need to keep the + * GMainContext running to ensure everything is cleaned up? The answer is + * this GObject. Subscribe a weak reference to the returned object and keep + * iterating the main context until the object got unreferenced. + * + * Note that after the NMClient instance gets destroyed, the remaining callbacks + * will be invoked right away. That means, the user won't have to iterate the + * main context much longer. + * + * Since: 1.22 + */ +GObject * +nm_client_get_context_busy_watcher (NMClient *self) +{ + GObject *w; + + g_return_val_if_fail (NM_IS_CLIENT (self), NULL); + + w = NM_CLIENT_GET_PRIVATE (self)->context_busy_watcher; + return g_object_get_qdata (w, nm_client_context_busy_watcher_quark ()) + ?: w; +} + +struct udev * +_nm_client_get_udev (NMClient *self) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + + if (G_UNLIKELY (!priv->udev_inited)) { + priv->udev_inited = TRUE; + /* for testing, we don't want to use udev in libnm. */ + if (!nm_streq0 (g_getenv ("LIBNM_USE_NO_UDEV"), "1")) + priv->udev = udev_new (); + } + + return priv->udev; +} + +/*****************************************************************************/ + +static void +_ASSERT_dbobj (NMLDBusObject *dbobj, + NMClient *self) +{ +#if NM_MORE_ASSERTS > 5 + nm_assert (NM_IS_CLIENT (self)); + nm_assert (NML_IS_DBUS_OBJECT (dbobj)); + nm_assert (dbobj == g_hash_table_lookup (NM_CLIENT_GET_PRIVATE (self)->dbus_objects, dbobj)); +#endif +} + +static NMLDBusObject * +nml_dbus_object_new (NMRefString *dbus_path_take) +{ + NMLDBusObject *dbobj; + + nm_assert (NM_IS_REF_STRING (dbus_path_take)); + + dbobj = g_slice_new (NMLDBusObject); + *dbobj = (NMLDBusObject) { + .dbus_path = g_steal_pointer (&dbus_path_take), + .ref_count = 1, + .dbus_objects_lst = C_LIST_INIT (dbobj->dbus_objects_lst), + .iface_lst_head = C_LIST_INIT (dbobj->iface_lst_head), + .watcher_lst_head = C_LIST_INIT (dbobj->watcher_lst_head), + .obj_changed_lst = C_LIST_INIT (dbobj->obj_changed_lst), + .obj_state = NML_DBUS_OBJ_STATE_UNLINKED, + }; + return dbobj; +} + +NMLDBusObject * +nml_dbus_object_ref (NMLDBusObject *dbobj) +{ + nm_assert (dbobj); + nm_assert (dbobj->ref_count > 0); + + dbobj->ref_count++; + return dbobj; +} + +void +nml_dbus_object_unref (NMLDBusObject *dbobj) +{ + nm_assert (dbobj); + nm_assert (dbobj->ref_count > 0); + + if (--dbobj->ref_count > 0) + return; + + nm_assert (c_list_is_empty (&dbobj->obj_changed_lst)); + nm_assert (c_list_is_empty (&dbobj->iface_lst_head)); + nm_assert (c_list_is_empty (&dbobj->watcher_lst_head)); + nm_assert (!dbobj->nmobj); + + nm_ref_string_unref (dbobj->dbus_path); + nm_g_slice_free (dbobj); +} + +static NMLDBusObjIfaceData * +nml_dbus_object_iface_data_get (NMLDBusObject *dbobj, + const char *dbus_iface_name, + gboolean allow_create) +{ + const NMLDBusMetaIface *meta_iface; + NMLDBusObjIfaceData *db_iface_data; + NMLDBusObjPropData *db_prop_data; + guint count = 0; + guint i; + + nm_assert (NML_IS_DBUS_OBJECT (dbobj)); + nm_assert (dbus_iface_name); + +#if NM_MORE_ASSERTS > 10 + { + gboolean expect_well_known = TRUE; + + /* all well-known interfaces must come first in the list. */ + c_list_for_each_entry (db_iface_data, &dbobj->iface_lst_head, iface_lst) { + if (db_iface_data->dbus_iface_is_wellknown == expect_well_known) + continue; + nm_assert (expect_well_known); + expect_well_known = FALSE; + } + } +#endif + + meta_iface = nml_dbus_meta_iface_get (dbus_iface_name); + if (meta_iface) { + c_list_for_each_entry (db_iface_data, &dbobj->iface_lst_head, iface_lst) { + if (!db_iface_data->dbus_iface_is_wellknown) + break; + if (db_iface_data->iface_removed) + continue; + if (db_iface_data->dbus_iface.meta == meta_iface) + return db_iface_data; + count++; + } + } else { + nm_c_list_for_each_entry_prev (db_iface_data, &dbobj->iface_lst_head, iface_lst) { + if (db_iface_data->dbus_iface_is_wellknown) + break; + if (db_iface_data->iface_removed) + continue; + if (nm_streq (db_iface_data->dbus_iface.name->str, dbus_iface_name)) + return db_iface_data; + count++; + } + } + + if (!allow_create) + return NULL; + + if (count > 20) { + /* We track the list of interfaces that an object has in a linked list. + * That is efficient and convenient, if we assume that each object only has a small + * number of interfaces (which very much should be the case). Here, something is very + * odd, maybe there is a bug or the server side is misbehaving. Anyway, error out. */ + return NULL; + } + + db_iface_data = g_malloc ( G_STRUCT_OFFSET (NMLDBusObjIfaceData, prop_datas) + + (meta_iface ? (sizeof (NMLDBusObjPropData) * meta_iface->n_dbus_properties): 0u)); + if (meta_iface) { + *db_iface_data = (NMLDBusObjIfaceData) { + .dbus_iface.meta = meta_iface, + .dbus_iface_is_wellknown = TRUE, + .changed_prop_lst_head = C_LIST_INIT (db_iface_data->changed_prop_lst_head), + .iface_removed = FALSE, + }; + db_prop_data = &db_iface_data->prop_datas[0]; + for (i = 0; i < meta_iface->n_dbus_properties; i++, db_prop_data++) { + *db_prop_data = (NMLDBusObjPropData) { + .prop_data_value = NULL, + .changed_prop_lst = C_LIST_INIT (db_prop_data->changed_prop_lst), + }; + } + c_list_link_front (&dbobj->iface_lst_head, &db_iface_data->iface_lst); + } else { + /* Intentionally don't initialize the other fields. We are not supposed + * to touch them, and a valgrind warning would be preferable. */ + db_iface_data->dbus_iface.name = nm_ref_string_new (dbus_iface_name); + db_iface_data->dbus_iface_is_wellknown = FALSE; + db_iface_data->iface_removed = FALSE; + c_list_link_tail (&dbobj->iface_lst_head, &db_iface_data->iface_lst); + } + + return db_iface_data; +} + static void -nm_client_init (NMClient *client) +nml_dbus_obj_iface_data_destroy (NMLDBusObjIfaceData *db_iface_data) { + guint i; + + nm_assert (db_iface_data); + nm_assert (c_list_is_empty (&db_iface_data->iface_lst)); + + if (db_iface_data->dbus_iface_is_wellknown) { + for (i = 0; i < db_iface_data->dbus_iface.meta->n_dbus_properties; i++) + nm_g_variant_unref (db_iface_data->prop_datas[i].prop_data_value); + } else + nm_ref_string_unref (db_iface_data->dbus_iface.name); + + g_free (db_iface_data); +} + +gpointer +nml_dbus_object_get_property_location (NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + const NMLDBusMetaProperty *meta_property) +{ + char *target_c; + + target_c = (char *) dbobj->nmobj; + if (meta_iface->base_struct_offset > 0) + target_c = *((gpointer *) (&target_c[meta_iface->base_struct_offset])); + return &target_c[meta_property->prop_struct_offset]; +} + +static void +nml_dbus_object_set_obj_state (NMLDBusObject *dbobj, + NMLDBusObjState obj_state, + NMClient *self) +{ + NMClientPrivate *priv; + + nm_assert (NM_IS_CLIENT (self)); + nm_assert (NML_IS_DBUS_OBJECT (dbobj)); + +#if NM_MORE_ASSERTS > 10 + priv = NM_CLIENT_GET_PRIVATE (self); + switch (dbobj->obj_state) { + case NML_DBUS_OBJ_STATE_UNLINKED: nm_assert (c_list_is_empty (&dbobj->dbus_objects_lst)); break; + case NML_DBUS_OBJ_STATE_WATCHED_ONLY: nm_assert (c_list_contains (&priv->dbus_objects_lst_head_watched_only, &dbobj->dbus_objects_lst)); break; + case NML_DBUS_OBJ_STATE_ON_DBUS: nm_assert (c_list_contains (&priv->dbus_objects_lst_head_on_dbus, &dbobj->dbus_objects_lst)); break; + case NML_DBUS_OBJ_STATE_WITH_NMOBJ_NOT_READY: nm_assert (c_list_contains (&priv->dbus_objects_lst_head_with_nmobj_not_ready, &dbobj->dbus_objects_lst)); break; + case NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY: nm_assert (c_list_contains (&priv->dbus_objects_lst_head_with_nmobj_ready, &dbobj->dbus_objects_lst)); break; + } +#endif + + if (dbobj->obj_state == obj_state) + return; + + NML_NMCLIENT_LOG_T (self, "[%s]: set D-Bus object state %s", dbobj->dbus_path->str, nml_dbus_obj_state_to_string (obj_state)); + + priv = NM_CLIENT_GET_PRIVATE (self); + dbobj->obj_state = obj_state; + switch (obj_state) { + case NML_DBUS_OBJ_STATE_UNLINKED: + c_list_unlink (&dbobj->dbus_objects_lst); + c_list_unlink (&dbobj->obj_changed_lst); + dbobj->obj_changed_type = NML_DBUS_OBJ_CHANGED_TYPE_NONE; + break; + case NML_DBUS_OBJ_STATE_WATCHED_ONLY: nm_c_list_move_tail (&priv->dbus_objects_lst_head_watched_only, &dbobj->dbus_objects_lst); break; + case NML_DBUS_OBJ_STATE_ON_DBUS: nm_c_list_move_tail (&priv->dbus_objects_lst_head_on_dbus, &dbobj->dbus_objects_lst); break; + case NML_DBUS_OBJ_STATE_WITH_NMOBJ_NOT_READY: nm_c_list_move_tail (&priv->dbus_objects_lst_head_with_nmobj_not_ready, &dbobj->dbus_objects_lst); break; + case NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY: nm_c_list_move_tail (&priv->dbus_objects_lst_head_with_nmobj_ready, &dbobj->dbus_objects_lst); break; + default: + nm_assert_not_reached (); + } +} + +/*****************************************************************************/ + +static void +nml_dbus_object_obj_changed_link (NMClient *self, + NMLDBusObject *dbobj, + NMLDBusObjChangedType changed_type) +{ + nm_assert (NM_IS_CLIENT (self)); + nm_assert (NML_IS_DBUS_OBJECT (dbobj)); + nm_assert (changed_type != NML_DBUS_OBJ_CHANGED_TYPE_NONE); + + if (!NM_FLAGS_ALL ((NMLDBusObjChangedType ) dbobj->obj_changed_type, changed_type)) + NML_NMCLIENT_LOG_T (self, "[%s] changed-type 0x%02x linked", dbobj->dbus_path->str, (guint) changed_type); + + if (dbobj->obj_changed_type == NML_DBUS_OBJ_CHANGED_TYPE_NONE) { + NMClientPrivate *priv; + + /* We set the changed-type flag. Need to queue the object in the + * changed list. */ + nm_assert (c_list_is_empty (&dbobj->obj_changed_lst)); + priv = NM_CLIENT_GET_PRIVATE (self); + c_list_link_tail (&priv->obj_changed_lst_head, &dbobj->obj_changed_lst); + } else { + /* The object has changes flags and must be linked already. Note that + * this may be priv->obj_changed_lst_head, or a temporary list on the + * stack. + * + * This dance with the temporary list is done to ensure we can enqueue + * objects while we process the changes. */ + nm_assert (!c_list_is_empty (&dbobj->obj_changed_lst)); + } + + dbobj->obj_changed_type |= changed_type; + + nm_assert (NM_FLAGS_ALL (dbobj->obj_changed_type, changed_type)); +} + +static NMLDBusObjChangedType +nml_dbus_object_obj_changed_consume (NMClient *self, + NMLDBusObject *dbobj, + NMLDBusObjChangedType changed_type) +{ + NMClientPrivate *priv; + NMLDBusObjChangedType changed_type_res; + + nm_assert (NM_IS_CLIENT (self)); + nm_assert (NML_IS_DBUS_OBJECT (dbobj)); + nm_assert (changed_type != NML_DBUS_OBJ_CHANGED_TYPE_NONE); + nm_assert (dbobj->obj_changed_type != NML_DBUS_OBJ_CHANGED_TYPE_NONE); + nm_assert (!c_list_is_empty (&dbobj->obj_changed_lst)); + + changed_type_res = dbobj->obj_changed_type & changed_type; + + dbobj->obj_changed_type &= ~changed_type; + + if (dbobj->obj_changed_type == NML_DBUS_OBJ_CHANGED_TYPE_NONE) { + c_list_unlink (&dbobj->obj_changed_lst); + nm_assert (changed_type_res != NML_DBUS_OBJ_CHANGED_TYPE_NONE); + NML_NMCLIENT_LOG_T (self, "[%s] changed-type 0x%02x consumed", dbobj->dbus_path->str, (guint) changed_type_res); + return changed_type_res; + } + + priv = NM_CLIENT_GET_PRIVATE (self); + + nm_assert (!c_list_contains (&priv->obj_changed_lst_head, &dbobj->obj_changed_lst)); + nm_c_list_move_tail (&priv->obj_changed_lst_head, &dbobj->obj_changed_lst); + NML_NMCLIENT_LOG_T (self, "[%s] changed-type 0x%02x consumed (still has 0x%02x)", dbobj->dbus_path->str, (guint) changed_type_res, (guint) dbobj->obj_changed_type); + return changed_type_res; +} + +static gboolean +nml_dbus_object_obj_changed_any_linked (NMClient *self, + NMLDBusObjChangedType changed_type) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + NMLDBusObject *dbobj; + + nm_assert (changed_type != NML_DBUS_OBJ_CHANGED_TYPE_NONE); + + c_list_for_each_entry (dbobj, &priv->obj_changed_lst_head, obj_changed_lst) { + nm_assert (dbobj->obj_changed_type != NML_DBUS_OBJ_CHANGED_TYPE_NONE); + if (NM_FLAGS_ANY (dbobj->obj_changed_type, changed_type)) + return TRUE; + } + return FALSE; +} + +/*****************************************************************************/ + +static void +_dbobjs_notify_watchers_for_dbobj (NMClient *self, + NMLDBusObject *dbobj) +{ + NMLDBusObjWatcher *obj_watcher; + NMLDBusObjWatcher *obj_watcher_safe; + + c_list_for_each_entry_safe (obj_watcher, obj_watcher_safe, &dbobj->watcher_lst_head, _priv.watcher_lst) + obj_watcher->_priv.notify_fcn (self, obj_watcher); } static gboolean -_nm_client_check_nm_running (NMClient *client, GError **error) +_dbobjs_check_dbobj_ready (NMClient *self, + NMLDBusObject *dbobj) { - if (nm_client_get_nm_running (client)) + nm_assert (NM_IS_CLIENT (self)); + nm_assert (NML_IS_DBUS_OBJECT (dbobj)); + nm_assert (G_IS_OBJECT (dbobj->nmobj)); + nm_assert ( NM_IS_OBJECT (dbobj->nmobj) + || NM_IS_CLIENT (dbobj->nmobj)); + nm_assert (NM_IN_SET ((NMLDBusObjState) dbobj->obj_state, NML_DBUS_OBJ_STATE_WITH_NMOBJ_NOT_READY, + NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY)); + + if (G_LIKELY (dbobj->obj_state == NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY)) return TRUE; - else { - g_set_error_literal (error, - NM_CLIENT_ERROR, - NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, - "NetworkManager is not running"); + + if (!NM_OBJECT_GET_CLASS (dbobj->nmobj)->is_ready (NM_OBJECT (dbobj->nmobj))) + return FALSE; + + nml_dbus_object_set_obj_state (dbobj, NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY, self); + + nml_dbus_object_obj_changed_link (self, dbobj, NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ); + _dbobjs_notify_watchers_for_dbobj (self, dbobj); + + return TRUE; +} + +void +_nm_client_notify_object_changed (NMClient *self, + NMLDBusObject *dbobj) +{ + nml_dbus_object_obj_changed_link (self, dbobj, NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ); + _dbobjs_notify_watchers_for_dbobj (self, dbobj); +} + +/*****************************************************************************/ + +static NMLDBusObject * +_dbobjs_dbobj_get_r (NMClient *self, + NMRefString *dbus_path_r) +{ + nm_assert (NM_IS_REF_STRING (dbus_path_r)); + + return g_hash_table_lookup (NM_CLIENT_GET_PRIVATE (self)->dbus_objects, &dbus_path_r); +} + +static NMLDBusObject * +_dbobjs_dbobj_get_s (NMClient *self, + const char *dbus_path) +{ + nm_auto_ref_string NMRefString *dbus_path_r = NULL; + + nm_assert (dbus_path); + dbus_path_r = nm_ref_string_new (dbus_path); + return _dbobjs_dbobj_get_r (self, dbus_path_r); +} + +static NMLDBusObject * +_dbobjs_dbobj_create (NMClient *self, + NMRefString *dbus_path_take) +{ + nm_auto_ref_string NMRefString *dbus_path = g_steal_pointer (&dbus_path_take); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + NMLDBusObject *dbobj; + + nm_assert (!_dbobjs_dbobj_get_r (self, dbus_path)); + + dbobj = nml_dbus_object_new (g_steal_pointer (&dbus_path)); + if (!g_hash_table_add (priv->dbus_objects, dbobj)) + nm_assert_not_reached (); + return dbobj; +} + +static NMLDBusObject * +_dbobjs_dbobj_get_or_create (NMClient *self, + NMRefString *dbus_path_take) +{ + nm_auto_ref_string NMRefString *dbus_path = g_steal_pointer (&dbus_path_take); + NMLDBusObject *dbobj; + + dbobj = _dbobjs_dbobj_get_r (self, dbus_path); + if (dbobj) + return dbobj; + return _dbobjs_dbobj_create (self, g_steal_pointer (&dbus_path)); +} + +static NMLDBusObject * +_dbobjs_get_nmobj (NMClient *self, + const char *dbus_path, + GType gtype) +{ + NMLDBusObject *dbobj; + + nm_assert ( gtype == G_TYPE_NONE + || g_type_is_a (gtype, NM_TYPE_OBJECT)); + + dbobj = _dbobjs_dbobj_get_s (self, dbus_path); + + if (!dbobj) + return NULL; + if (!dbobj->nmobj) + return NULL; + + if ( gtype != G_TYPE_NONE + && !g_type_is_a (G_OBJECT_TYPE (dbobj->nmobj), gtype)) + return NULL; + + return dbobj; +} + +static gpointer +_dbobjs_get_nmobj_unpack_visible (NMClient *self, + const char *dbus_path, + GType gtype) +{ + NMLDBusObject *dbobj; + + dbobj = _dbobjs_get_nmobj (self, dbus_path, gtype); + if (!dbobj) + return NULL; + if (dbobj->obj_state != NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY) + return NULL; + return dbobj->nmobj; +} + +/*****************************************************************************/ + +static gpointer +_dbobjs_obj_watcher_register_o (NMClient *self, + NMLDBusObject *dbobj, + NMLDBusObjWatchNotifyFcn notify_fcn, + gsize struct_size) +{ + NMLDBusObjWatcher *obj_watcher; + + nm_assert (NM_IS_CLIENT (self)); + _ASSERT_dbobj (dbobj, self); + nm_assert (notify_fcn); + nm_assert (struct_size > sizeof (NMLDBusObjWatcher)); + + obj_watcher = g_malloc (struct_size); + obj_watcher->dbobj = dbobj; + obj_watcher->_priv.notify_fcn = notify_fcn; + + /* we must enqueue the item in the front of the list. That is, because while + * invoking notify_fcn(), we iterate the watchers front-to-end. As we want to + * allow the callee to register new watches and unregister itself, this is + * the right way to do it. */ + c_list_link_front (&dbobj->watcher_lst_head, &obj_watcher->_priv.watcher_lst); + + return obj_watcher; +} + +static gpointer +_dbobjs_obj_watcher_register_r (NMClient *self, + NMRefString *dbus_path_take, + NMLDBusObjWatchNotifyFcn notify_fcn, + gsize struct_size) +{ + nm_auto_ref_string NMRefString *dbus_path = g_steal_pointer (&dbus_path_take); + NMLDBusObject *dbobj; + + nm_assert (NM_IS_CLIENT (self)); + nm_assert (notify_fcn); + + dbobj = _dbobjs_dbobj_get_or_create (self, g_steal_pointer (&dbus_path)); + if (dbobj->obj_state == NML_DBUS_OBJ_STATE_UNLINKED) + nml_dbus_object_set_obj_state (dbobj, NML_DBUS_OBJ_STATE_WATCHED_ONLY, self); + return _dbobjs_obj_watcher_register_o (self, dbobj, notify_fcn, struct_size); +} + +static void +_dbobjs_obj_watcher_unregister (NMClient *self, + gpointer obj_watcher_base) +{ + NMLDBusObjWatcher *obj_watcher = obj_watcher_base; + NMLDBusObject *dbobj; + + nm_assert (NM_IS_CLIENT (self)); + nm_assert (obj_watcher); + nm_assert (NML_IS_DBUS_OBJECT (obj_watcher->dbobj)); + nm_assert (g_hash_table_lookup (NM_CLIENT_GET_PRIVATE (self)->dbus_objects, obj_watcher->dbobj) == obj_watcher->dbobj); + nm_assert (c_list_contains (&obj_watcher->dbobj->watcher_lst_head, &obj_watcher->_priv.watcher_lst)); + + c_list_unlink (&obj_watcher->_priv.watcher_lst); + + dbobj = obj_watcher->dbobj; + + g_free (obj_watcher); + + if ( c_list_is_empty (&dbobj->iface_lst_head) + && c_list_is_empty (&dbobj->watcher_lst_head)) { + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + + NML_NMCLIENT_LOG_T (self, "[%s]: drop D-Bus watcher", dbobj->dbus_path->str); + nml_dbus_object_set_obj_state (dbobj, NML_DBUS_OBJ_STATE_UNLINKED, self); + if (!g_hash_table_steal (priv->dbus_objects, dbobj)) + nm_assert_not_reached (); + nml_dbus_object_unref (dbobj); + } +} + +/*****************************************************************************/ + +typedef struct { + NMLDBusObjWatcher parent; + NMLDBusPropertyO *pr_o; +} PropertyOData; + +gpointer +nml_dbus_property_o_get_obj (NMLDBusPropertyO *pr_o) +{ + nm_assert ( !pr_o->nmobj + || nml_dbus_property_o_is_ready (pr_o)); + return pr_o->nmobj; +} + +gboolean +nml_dbus_property_o_is_ready (const NMLDBusPropertyO *pr_o) +{ + return pr_o->is_ready + || !pr_o->owner_dbobj; +} + +static void +nml_dbus_property_o_notify_changed (NMLDBusPropertyO *pr_o, + NMClient *self) +{ + const NMLDBusPropertVTableO *vtable; + GObject *nmobj = NULL; + gboolean is_ready = TRUE; + gboolean changed_ready; + GType gtype; + + nm_assert (pr_o); + nm_assert (NM_IS_CLIENT (self)); + + if (!pr_o->owner_dbobj) + return; + + if (!pr_o->is_changed) { + if (pr_o->is_ready) + return; + goto done; + } + + pr_o->is_changed = FALSE; + + if (!pr_o->obj_watcher) + goto done; + + if (!pr_o->obj_watcher->dbobj->nmobj) { + if (pr_o->obj_watcher->dbobj->obj_state >= NML_DBUS_OBJ_STATE_ON_DBUS) { + NML_NMCLIENT_LOG_W (self, "[%s]: property %s references %s but object is not created", + pr_o->owner_dbobj->dbus_path->str, + pr_o->meta_iface->dbus_properties[pr_o->dbus_property_idx].dbus_property_name, + pr_o->obj_watcher->dbobj->dbus_path->str); + } else { + NML_NMCLIENT_LOG_E (self, "[%s]: property %s references %s but object is not present on D-Bus", + pr_o->owner_dbobj->dbus_path->str, + pr_o->meta_iface->dbus_properties[pr_o->dbus_property_idx].dbus_property_name, + pr_o->obj_watcher->dbobj->dbus_path->str); + } + goto done; + } + + vtable = pr_o->meta_iface->dbus_properties[pr_o->dbus_property_idx].extra.property_vtable_o; + + gtype = vtable->get_o_type_fcn (); + if (!g_type_is_a (G_OBJECT_TYPE (pr_o->obj_watcher->dbobj->nmobj), gtype)) { + NML_NMCLIENT_LOG_E (self, "[%s]: property %s references %s with unexpected GObject type %s instead of %s", + pr_o->owner_dbobj->dbus_path->str, + pr_o->meta_iface->dbus_properties[pr_o->dbus_property_idx].dbus_property_name, + pr_o->obj_watcher->dbobj->dbus_path->str, + G_OBJECT_TYPE_NAME (pr_o->obj_watcher->dbobj->nmobj), + g_type_name (gtype)); + goto done; + } + + if (pr_o->obj_watcher->dbobj == pr_o->owner_dbobj) { + NML_NMCLIENT_LOG_W (self, "[%s]: property %s references itself", + pr_o->owner_dbobj->dbus_path->str, + pr_o->meta_iface->dbus_properties[pr_o->dbus_property_idx].dbus_property_name); + nmobj = pr_o->owner_dbobj->nmobj; + goto done; + } + + pr_o->block_is_changed = TRUE; + is_ready = _dbobjs_check_dbobj_ready (self, pr_o->obj_watcher->dbobj); + pr_o->block_is_changed = FALSE; + + if (!is_ready) { + is_ready = vtable->is_always_ready; + goto done; + } + + nmobj = pr_o->obj_watcher->dbobj->nmobj; + +done: + changed_ready = FALSE; + if (!pr_o->is_ready && is_ready) { + pr_o->is_ready = TRUE; + changed_ready = TRUE; + } + if (pr_o->nmobj != nmobj) { + pr_o->nmobj = nmobj; + _nm_client_queue_notify_object (self, + pr_o->owner_dbobj->nmobj, + pr_o->meta_iface->obj_properties[pr_o->meta_iface->dbus_properties[pr_o->dbus_property_idx].obj_properties_idx]); + } + if ( changed_ready + && pr_o->owner_dbobj->obj_state == NML_DBUS_OBJ_STATE_WITH_NMOBJ_NOT_READY) + nml_dbus_object_obj_changed_link (self, pr_o->owner_dbobj, NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ); +} + +void +nml_dbus_property_o_notify_changed_many (NMLDBusPropertyO *ptr, + guint len, + NMClient *self) +{ + while (len-- > 0) + nml_dbus_property_o_notify_changed (ptr++, self); +} + +static void +nml_dbus_property_o_notify_watch_cb (NMClient *self, + gpointer obj_watcher) +{ + PropertyOData *pr_o_data = obj_watcher; + NMLDBusPropertyO *pr_o = pr_o_data->pr_o; + + nm_assert (pr_o->obj_watcher == obj_watcher); + + if ( !pr_o->block_is_changed + && !pr_o->is_changed) { + pr_o->is_changed = TRUE; + nml_dbus_object_obj_changed_link (self, pr_o->owner_dbobj, NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ); + } +} + +static NMLDBusNotifyUpdatePropFlags +nml_dbus_property_o_notify (NMClient *self, + NMLDBusPropertyO *pr_o, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) +{ + const char *dbus_path = NULL; + gboolean changed = FALSE; + + if (!pr_o->owner_dbobj) { + nm_assert (!pr_o->meta_iface); + nm_assert (pr_o->dbus_property_idx == 0); + nm_assert (!pr_o->is_ready); + pr_o->owner_dbobj = dbobj; + pr_o->meta_iface = meta_iface; + pr_o->dbus_property_idx = dbus_property_idx; + } else { + nm_assert (pr_o->owner_dbobj == dbobj); + nm_assert (pr_o->meta_iface == meta_iface); + nm_assert (pr_o->dbus_property_idx == dbus_property_idx); + } + + if (value) + dbus_path = nm_dbus_path_not_empty (g_variant_get_string (value, NULL)); + + if ( pr_o->obj_watcher + && ( !dbus_path + || !nm_streq (dbus_path, pr_o->obj_watcher->dbobj->dbus_path->str))) { + _dbobjs_obj_watcher_unregister (self, + g_steal_pointer (&pr_o->obj_watcher)); + changed = TRUE; + } + if ( !pr_o->obj_watcher + && dbus_path) { + pr_o->obj_watcher = _dbobjs_obj_watcher_register_r (self, + nm_ref_string_new (dbus_path), + nml_dbus_property_o_notify_watch_cb, + sizeof (PropertyOData)); + ((PropertyOData *) pr_o->obj_watcher)->pr_o = pr_o; + changed = TRUE; + } + + if ( changed + && !pr_o->is_changed) { + pr_o->is_changed = TRUE; + nml_dbus_object_obj_changed_link (self, dbobj, NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ); + } + + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE; +} + +void +nml_dbus_property_o_clear (NMLDBusPropertyO *pr_o, + NMClient *self) +{ + if (pr_o->obj_watcher) { + nm_assert (NM_IS_CLIENT (self)); + _dbobjs_obj_watcher_unregister (self, + g_steal_pointer (&pr_o->obj_watcher)); + } + if ( pr_o->nmobj + && pr_o->owner_dbobj + && pr_o->owner_dbobj->nmobj) { + _nm_client_queue_notify_object (self, + pr_o->owner_dbobj->nmobj, + pr_o->meta_iface->obj_properties[pr_o->meta_iface->dbus_properties[pr_o->dbus_property_idx].obj_properties_idx]); + } + pr_o->owner_dbobj = NULL; + pr_o->meta_iface = NULL; + pr_o->dbus_property_idx = 0; + pr_o->is_ready = FALSE; +} + +void +nml_dbus_property_o_clear_many (NMLDBusPropertyO *pr_o, + guint len, + NMClient *self) +{ + while (len-- > 0) + nml_dbus_property_o_clear (pr_o++, self); +} + +/*****************************************************************************/ + +typedef struct _NMLDBusPropertyAOData { + NMLDBusObjWatcher obj_watcher; + NMLDBusPropertyAO *parent; + CList data_lst; + GObject *nmobj; + struct _NMLDBusPropertyAOData *changed_next; + bool is_ready:1; + bool is_notified:1; + bool is_changed:1; + bool block_is_changed:1; +} PropertyAOData; + +static void +_ASSERT_pr_ao (NMLDBusPropertyAO *pr_ao) +{ + nm_assert (pr_ao); + +#if NM_MORE_ASSERTS > 10 + if (pr_ao->owner_dbobj) { + guint n_not_ready = 0; + guint n_is_changed = 0; + guint n_is_changed_2; + PropertyAOData *pr_ao_data; + + c_list_for_each_entry (pr_ao_data, &pr_ao->data_lst_head, data_lst) { + if (pr_ao_data->is_changed) + n_is_changed++; + if (!pr_ao_data->is_ready) + n_not_ready++; + } + nm_assert (n_not_ready == pr_ao->n_not_ready); + + n_is_changed_2 = 0; + pr_ao_data = pr_ao->changed_head; + while (pr_ao_data) { + nm_assert (pr_ao_data->is_changed); + n_is_changed_2++; + pr_ao_data = pr_ao_data->changed_next; + } + nm_assert (n_is_changed == n_is_changed_2); + } +#endif +} + +static gboolean +nml_dbus_property_ao_notify_changed_ao (PropertyAOData *pr_ao_data, + NMClient *self, + gboolean is_added /* or else removed */) +{ + NMLDBusPropertyAO *pr_ao; + const NMLDBusPropertVTableAO *vtable; + + if (!pr_ao_data->nmobj) + return FALSE; + + nm_assert (pr_ao_data->is_ready); + + if (is_added) { + if (pr_ao_data->is_notified) + return FALSE; + pr_ao_data->is_notified = TRUE; + } else { + if (!pr_ao_data->is_notified) + return FALSE; + pr_ao_data->is_notified = FALSE; + } + + pr_ao = pr_ao_data->parent; + + vtable = pr_ao->meta_iface->dbus_properties[pr_ao->dbus_property_idx].extra.property_vtable_ao; + + if (vtable->notify_changed_ao) + vtable->notify_changed_ao (pr_ao, self, NM_OBJECT (pr_ao_data->nmobj), is_added); + return TRUE; +} + +const GPtrArray * +nml_dbus_property_ao_get_objs_as_ptrarray (NMLDBusPropertyAO *pr_ao) +{ + if (!pr_ao->arr) { + PropertyAOData *pr_ao_data; + gsize n; + + n = 0; + if (pr_ao->owner_dbobj) { + c_list_for_each_entry (pr_ao_data, &pr_ao->data_lst_head, data_lst) { + if (pr_ao_data->nmobj) + n++; + } + } + + pr_ao->arr = g_ptr_array_new_full (n, g_object_unref); + if (pr_ao->owner_dbobj) { + c_list_for_each_entry (pr_ao_data, &pr_ao->data_lst_head, data_lst) { + if (pr_ao_data->nmobj) + g_ptr_array_add (pr_ao->arr, g_object_ref (pr_ao_data->nmobj)); + } + } + } + return pr_ao->arr; +} + +gboolean +nml_dbus_property_ao_is_ready (const NMLDBusPropertyAO *pr_ao) +{ + return pr_ao->n_not_ready == 0; +} + +static void +nml_dbus_property_ao_notify_changed (NMLDBusPropertyAO *pr_ao, + NMClient *self) +{ + gboolean changed_prop = FALSE; + gboolean changed_ready = FALSE; + PropertyAOData *pr_ao_data; + + nm_assert (NM_IS_CLIENT (self)); + _ASSERT_pr_ao (pr_ao); + + if (!pr_ao->owner_dbobj) + return; + + if (!pr_ao->is_changed) { + if (pr_ao->n_not_ready == 0) + return; + goto done; + } + + pr_ao->is_changed = FALSE; + + while (pr_ao->changed_head) { + const NMLDBusPropertVTableAO *vtable; + GObject *nmobj = NULL; + gboolean is_ready = TRUE; + GType gtype; + + pr_ao_data = g_steal_pointer (&pr_ao->changed_head); + nm_assert (pr_ao_data->is_changed); + + pr_ao->changed_head = pr_ao_data->changed_next; + pr_ao_data->is_changed = FALSE; + + if (!pr_ao_data->obj_watcher.dbobj->nmobj) { + if (pr_ao_data->obj_watcher.dbobj->obj_state >= NML_DBUS_OBJ_STATE_ON_DBUS) { + NML_NMCLIENT_LOG_W (self, "[%s]: property %s references %s but object is not created", + pr_ao->owner_dbobj->dbus_path->str, + pr_ao->meta_iface->dbus_properties[pr_ao->dbus_property_idx].dbus_property_name, + pr_ao_data->obj_watcher.dbobj->dbus_path->str); + } else { + NML_NMCLIENT_LOG_E (self, "[%s]: property %s references %s but object is not present on D-Bus", + pr_ao->owner_dbobj->dbus_path->str, + pr_ao->meta_iface->dbus_properties[pr_ao->dbus_property_idx].dbus_property_name, + pr_ao_data->obj_watcher.dbobj->dbus_path->str); + } + goto done_pr_ao_data; + } + + vtable = pr_ao->meta_iface->dbus_properties[pr_ao->dbus_property_idx].extra.property_vtable_ao; + + gtype = vtable->get_o_type_fcn (); + if (!g_type_is_a (G_OBJECT_TYPE (pr_ao_data->obj_watcher.dbobj->nmobj), gtype)) { + NML_NMCLIENT_LOG_E (self, "[%s]: property %s references %s with unexpected GObject type %s instead of %s", + pr_ao->owner_dbobj->dbus_path->str, + pr_ao->meta_iface->dbus_properties[pr_ao->dbus_property_idx].dbus_property_name, + pr_ao_data->obj_watcher.dbobj->dbus_path->str, + G_OBJECT_TYPE_NAME (pr_ao_data->obj_watcher.dbobj->nmobj), + g_type_name (gtype)); + goto done_pr_ao_data; + } + + if (pr_ao_data->obj_watcher.dbobj == pr_ao->owner_dbobj) { + NML_NMCLIENT_LOG_W (self, "[%s]: property %s references itself", + pr_ao->owner_dbobj->dbus_path->str, + pr_ao->meta_iface->dbus_properties[pr_ao->dbus_property_idx].dbus_property_name); + nmobj = pr_ao->owner_dbobj->nmobj; + goto done_pr_ao_data; + } + + pr_ao_data->block_is_changed = TRUE; + is_ready = _dbobjs_check_dbobj_ready (self, pr_ao_data->obj_watcher.dbobj); + pr_ao_data->block_is_changed = FALSE; + + if (!is_ready) { + is_ready = vtable->is_always_ready; + goto done_pr_ao_data; + } + + if ( vtable->check_nmobj_visible_fcn + && !vtable->check_nmobj_visible_fcn (pr_ao_data->obj_watcher.dbobj->nmobj)) { + is_ready = TRUE; + goto done_pr_ao_data; + } + + nmobj = pr_ao_data->obj_watcher.dbobj->nmobj; + +done_pr_ao_data: + + if ( !pr_ao_data->is_ready + && is_ready) { + nm_assert (pr_ao->n_not_ready > 0); + pr_ao->n_not_ready--; + pr_ao_data->is_ready = TRUE; + changed_ready = TRUE; + } + + if (pr_ao_data->nmobj != nmobj) { + if (nml_dbus_property_ao_notify_changed_ao (pr_ao_data, self, FALSE)) + changed_prop = TRUE; + pr_ao_data->nmobj = nmobj; + } + + if (!pr_ao_data->is_notified) { + if (nml_dbus_property_ao_notify_changed_ao (pr_ao_data, self, TRUE)) + changed_prop = TRUE; + } + } + + _ASSERT_pr_ao (pr_ao); + +done: + if (changed_prop) { + nm_clear_pointer (&pr_ao->arr, g_ptr_array_unref); + _nm_client_queue_notify_object (self, + pr_ao->owner_dbobj->nmobj, + pr_ao->meta_iface->obj_properties[pr_ao->meta_iface->dbus_properties[pr_ao->dbus_property_idx].obj_properties_idx]); + } + if ( changed_ready + && pr_ao->n_not_ready == 0 + && pr_ao->owner_dbobj->obj_state == NML_DBUS_OBJ_STATE_WITH_NMOBJ_NOT_READY) + nml_dbus_object_obj_changed_link (self, pr_ao->owner_dbobj, NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ); +} + +void +nml_dbus_property_ao_notify_changed_many (NMLDBusPropertyAO *ptr, + guint len, + NMClient *self) +{ + while (len-- > 0) + nml_dbus_property_ao_notify_changed (ptr++, self); +} + +static void +nml_dbus_property_ao_notify_watch_cb (NMClient *self, + gpointer obj_watcher) +{ + PropertyAOData *pr_ao_data = obj_watcher; + NMLDBusPropertyAO *pr_ao = pr_ao_data->parent; + + nm_assert (g_hash_table_lookup (pr_ao->hash, pr_ao_data) == pr_ao_data); + + if ( !pr_ao_data->block_is_changed + && !pr_ao_data->is_changed) { + pr_ao_data->is_changed = TRUE; + pr_ao_data->changed_next = pr_ao->changed_head; + pr_ao->changed_head = pr_ao_data; + if (!pr_ao->is_changed) { + pr_ao->is_changed = TRUE; + nml_dbus_object_obj_changed_link (self, pr_ao->owner_dbobj, NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ); + } + } + + _ASSERT_pr_ao (pr_ao); +} + +static NMLDBusNotifyUpdatePropFlags +nml_dbus_property_ao_notify (NMClient *self, + NMLDBusPropertyAO *pr_ao, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) +{ + CList stale_lst_head = C_LIST_INIT (stale_lst_head); + PropertyAOData *pr_ao_data; + gboolean changed_prop = FALSE; + gboolean changed_obj = FALSE; + + if (!pr_ao->owner_dbobj) { + nm_assert (!pr_ao->data_lst_head.next); + nm_assert (!pr_ao->data_lst_head.prev); + nm_assert (!pr_ao->hash); + nm_assert (!pr_ao->meta_iface); + nm_assert (pr_ao->dbus_property_idx == 0); + nm_assert (pr_ao->n_not_ready == 0); + nm_assert (!pr_ao->changed_head); + nm_assert (!pr_ao->is_changed); + + c_list_init (&pr_ao->data_lst_head); + pr_ao->hash = g_hash_table_new (nm_ppdirect_hash, nm_ppdirect_equal); + pr_ao->owner_dbobj = dbobj; + pr_ao->meta_iface = meta_iface; + pr_ao->dbus_property_idx = dbus_property_idx; + } else { + nm_assert (pr_ao->data_lst_head.next); + nm_assert (pr_ao->data_lst_head.prev); + nm_assert (pr_ao->hash); + nm_assert (pr_ao->meta_iface == meta_iface); + nm_assert (pr_ao->dbus_property_idx == dbus_property_idx); + } + + c_list_splice (&stale_lst_head, &pr_ao->data_lst_head); + + if (value) { + GVariantIter iter; + const char *path; + + g_variant_iter_init (&iter, value); + while (g_variant_iter_next (&iter, "&o", &path)) { + nm_auto_ref_string NMRefString *dbus_path_r = NULL; + gpointer p_dbus_path_1; + + G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (PropertyAOData, obj_watcher) == 0); + G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (NMLDBusObjWatcher, dbobj) == 0); + G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (NMLDBusObject, dbus_path) == 0); + + if (!nm_dbus_path_not_empty (path)) { + /* should not happen. Anyway, silently skip empty paths. */ + continue; + } + + dbus_path_r = nm_ref_string_new (path); + p_dbus_path_1 = &dbus_path_r; + pr_ao_data = g_hash_table_lookup (pr_ao->hash, &p_dbus_path_1); + + if (pr_ao_data) { + /* With this implementation we cannot track the same path multiple times. + * Of course, for none of the properties where we use this, the server + * should expose the same path more than once, so this limitation is fine + * (maybe even preferable to drop duplicates form NMClient's API). */ + nm_assert (pr_ao_data->obj_watcher.dbobj->dbus_path == dbus_path_r); + if ( !changed_prop + && pr_ao_data->is_notified) { + /* The order of a notified entry changed. That means, we need to signal + * a change of the property. This detection of a change is not always + * correct, in particular we might detect some changes when there were + * none. That's not a serious problem, and fixing it would be expensive + * to implement. */ + changed_prop = (c_list_first (&stale_lst_head) != &pr_ao_data->data_lst); + } + nm_c_list_move_tail (&pr_ao->data_lst_head, &pr_ao_data->data_lst); + } else { + pr_ao_data = _dbobjs_obj_watcher_register_r (self, + g_steal_pointer (&dbus_path_r), + nml_dbus_property_ao_notify_watch_cb, + sizeof (PropertyAOData)), + pr_ao_data->parent = pr_ao; + pr_ao_data->nmobj = NULL; + pr_ao_data->changed_next = NULL; + pr_ao_data->is_changed = TRUE; + pr_ao_data->block_is_changed = FALSE; + pr_ao_data->is_ready = FALSE; + pr_ao_data->is_notified = FALSE; + c_list_link_tail (&pr_ao->data_lst_head, &pr_ao_data->data_lst); + if (!g_hash_table_add (pr_ao->hash, pr_ao_data)) + nm_assert_not_reached (); + nm_assert (pr_ao->n_not_ready < G_MAXUINT); + pr_ao->n_not_ready++; + } + +#if NM_MORE_ASSERTS > 10 + { + nm_auto_ref_string NMRefString *p = nm_ref_string_new (path); + gpointer pp = &p; + + nm_assert (g_hash_table_lookup (pr_ao->hash, &pp) == pr_ao_data); + } +#endif + } + } + + pr_ao->changed_head = NULL; + c_list_for_each_entry (pr_ao_data, &pr_ao->data_lst_head, data_lst) { + if (pr_ao_data->is_changed) { + pr_ao_data->changed_next = pr_ao->changed_head; + pr_ao->changed_head = pr_ao_data; + changed_obj = TRUE; + } + } + + while ((pr_ao_data = c_list_first_entry (&stale_lst_head, PropertyAOData, data_lst))) { + changed_obj = TRUE; + c_list_unlink (&pr_ao_data->data_lst); + if (!g_hash_table_remove (pr_ao->hash, pr_ao_data)) + nm_assert_not_reached (); + if (!pr_ao_data->is_ready) { + nm_assert (pr_ao->n_not_ready > 0); + pr_ao->n_not_ready--; + } else { + if (nml_dbus_property_ao_notify_changed_ao (pr_ao_data, self, FALSE)) + changed_prop = TRUE; + } + _dbobjs_obj_watcher_unregister (self, pr_ao_data); + } + + _ASSERT_pr_ao (pr_ao); + + if (changed_obj) { + pr_ao->is_changed = TRUE; + nml_dbus_object_obj_changed_link (self, dbobj, NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ); + } + + if (changed_prop) { + nm_clear_pointer (&pr_ao->arr, g_ptr_array_unref); + _nm_client_queue_notify_object (self, + pr_ao->owner_dbobj->nmobj, + pr_ao->meta_iface->obj_properties[pr_ao->meta_iface->dbus_properties[pr_ao->dbus_property_idx].obj_properties_idx]); + } + + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE; +} + +void +nml_dbus_property_ao_clear (NMLDBusPropertyAO *pr_ao, + NMClient *self) +{ + _ASSERT_pr_ao (pr_ao); + + if (!pr_ao->owner_dbobj) { + nm_assert (pr_ao->n_not_ready == 0); + nm_assert ( (!pr_ao->data_lst_head.next && !pr_ao->data_lst_head.prev) + || (pr_ao->data_lst_head.next == pr_ao->data_lst_head.prev)); + nm_assert (!pr_ao->hash); + nm_assert (!pr_ao->meta_iface); + nm_assert (pr_ao->dbus_property_idx == 0); + nm_assert (!pr_ao->is_changed); + } else { + PropertyAOData *pr_ao_data; + gboolean changed_prop = FALSE; + + nm_assert (NM_IS_CLIENT (self)); + nm_assert (pr_ao->data_lst_head.next); + nm_assert (pr_ao->data_lst_head.prev); + nm_assert (pr_ao->hash); + nm_assert (pr_ao->meta_iface); + + while ((pr_ao_data = c_list_first_entry (&pr_ao->data_lst_head, PropertyAOData, data_lst))) { + if (!pr_ao_data->is_ready) { + nm_assert (pr_ao->n_not_ready > 0); + pr_ao->n_not_ready--; + } else { + if (nml_dbus_property_ao_notify_changed_ao (pr_ao_data, self, FALSE)) + changed_prop = TRUE; + } + c_list_unlink (&pr_ao_data->data_lst); + if (!g_hash_table_remove (pr_ao->hash, pr_ao_data)) + nm_assert_not_reached (); + _dbobjs_obj_watcher_unregister (self, pr_ao_data); + } + + nm_assert (c_list_is_empty (&pr_ao->data_lst_head)); + nm_assert (pr_ao->n_not_ready == 0); + nm_assert (g_hash_table_size (pr_ao->hash) == 0); + + if ( changed_prop + && pr_ao->owner_dbobj->nmobj) { + _nm_client_queue_notify_object (self, + pr_ao->owner_dbobj->nmobj, + pr_ao->meta_iface->obj_properties[pr_ao->meta_iface->dbus_properties[pr_ao->dbus_property_idx].obj_properties_idx]); + } + + nm_assert (c_list_is_empty (&pr_ao->data_lst_head)); + nm_assert (pr_ao->n_not_ready == 0); + nm_assert (g_hash_table_size (pr_ao->hash) == 0); + nm_clear_pointer (&pr_ao->hash, g_hash_table_unref); + pr_ao->owner_dbobj = NULL; + pr_ao->meta_iface = NULL; + pr_ao->dbus_property_idx = 0; + pr_ao->data_lst_head.next = NULL; + pr_ao->data_lst_head.prev = NULL; + pr_ao->is_changed = FALSE; + } + + nm_clear_pointer (&pr_ao->arr, g_ptr_array_unref); +} + +void +nml_dbus_property_ao_clear_many (NMLDBusPropertyAO *pr_ao, + guint len, + NMClient *self) +{ + while (len-- > 0) + nml_dbus_property_ao_clear (pr_ao++, self); +} + +/*****************************************************************************/ + +NMLDBusNotifyUpdatePropFlags +_nml_dbus_notify_update_prop_ignore (NMClient *self, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) +{ + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE; +} + +NMLDBusNotifyUpdatePropFlags +_nml_dbus_notify_update_prop_o (NMClient *self, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) +{ + const char *path = NULL; + NMRefString **p_property; + + if (value) + path = g_variant_get_string (value, NULL); + + p_property = nml_dbus_object_get_property_location (dbobj, + meta_iface, + &meta_iface->dbus_properties[dbus_property_idx]); + + if (!nm_streq0 (nm_ref_string_get_str (*p_property), path)) { + nm_ref_string_unref (*p_property); + *p_property = nm_ref_string_new (path); + } + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY; +} + +/*****************************************************************************/ + +static void +_obj_handle_dbus_prop_changes (NMClient *self, + NMLDBusObject *dbobj, + NMLDBusObjIfaceData *db_iface_data, + guint dbus_property_idx, + GVariant *value) +{ + const NMLDBusMetaIface *meta_iface = db_iface_data->dbus_iface.meta; + const NMLDBusMetaProperty *meta_property = &meta_iface->dbus_properties[dbus_property_idx]; + gpointer p_property; + const char *dbus_type_s; + const GParamSpec *param_spec; + NMLDBusNotifyUpdatePropFlags notify_update_prop_flags; + + nm_assert (G_IS_OBJECT (dbobj->nmobj)); + + if ( value + && !g_variant_is_of_type (value, meta_property->dbus_type)) { + NML_NMCLIENT_LOG_E (self, "[%s] property %s.%s expected of type \"%s\" but is \"%s\". Ignore", + dbobj->dbus_path->str, + meta_iface->dbus_iface_name, + meta_property->dbus_property_name, + (const char *) meta_property->dbus_type, + (const char *) g_variant_get_type (value)); + value = NULL; + } + + if (meta_property->use_notify_update_prop) { + notify_update_prop_flags = meta_property->notify_update_prop (self, + dbobj, + meta_iface, + dbus_property_idx, + value); + if (notify_update_prop_flags == NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE) + return; + + nm_assert (notify_update_prop_flags == NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY); + nm_assert (G_IS_OBJECT (dbobj->nmobj)); + nm_assert (meta_iface->obj_properties); + nm_assert (meta_property->obj_properties_idx > 0); + param_spec = meta_iface->obj_properties[meta_property->obj_properties_idx]; + goto notify; + } + + p_property = nml_dbus_object_get_property_location (dbobj, meta_iface, meta_property); + + dbus_type_s = (const char *) meta_property->dbus_type; + + nm_assert (G_IS_OBJECT (dbobj->nmobj)); + nm_assert (meta_iface->obj_properties); + nm_assert (meta_property->obj_properties_idx > 0); + param_spec = meta_iface->obj_properties[meta_property->obj_properties_idx]; + + notify_update_prop_flags = NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY; + + switch (dbus_type_s[0]) { + case 'b': + nm_assert (dbus_type_s[1] == '\0'); + if (value) + *((bool *) p_property) = g_variant_get_boolean (value); + else if (param_spec->value_type == G_TYPE_BOOLEAN) + *((bool *) p_property) = ((GParamSpecBoolean *) param_spec)->default_value; + else { + nm_assert_not_reached (); + *((bool *) p_property) = FALSE; + } + break; + case 'y': + nm_assert (dbus_type_s[1] == '\0'); + if (value) + *((guint8 *) p_property) = g_variant_get_byte (value); + else { + nm_assert (nm_utils_g_param_spec_is_default (param_spec)); + *((guint8 *) p_property) = 0; + } + break; + case 'q': + nm_assert (dbus_type_s[1] == '\0'); + if (value) + *((guint16 *) p_property) = g_variant_get_uint16 (value); + else { + nm_assert (nm_utils_g_param_spec_is_default (param_spec)); + *((guint16 *) p_property) = 0; + } + break; + case 'i': + nm_assert (dbus_type_s[1] == '\0'); + if (value) + *((gint32 *) p_property) = g_variant_get_int32 (value); + else if (param_spec->value_type == G_TYPE_INT) + *((gint32 *) p_property) = ((GParamSpecInt *) param_spec)->default_value; + else { + nm_assert (nm_utils_g_param_spec_is_default (param_spec)); + *((gint32 *) p_property) = 0; + } + break; + case 'u': + nm_assert (dbus_type_s[1] == '\0'); + if (value) + *((guint32 *) p_property) = g_variant_get_uint32 (value); + else { + nm_assert (nm_utils_g_param_spec_is_default (param_spec)); + *((guint32 *) p_property) = 0; + } + break; + case 'x': + nm_assert (dbus_type_s[1] == '\0'); + if (value) + *((gint64 *) p_property) = g_variant_get_int64 (value); + else if (param_spec->value_type == G_TYPE_INT64) + *((gint64 *) p_property) = ((GParamSpecInt64 *) param_spec)->default_value; + else { + nm_assert (nm_utils_g_param_spec_is_default (param_spec)); + *((gint64 *) p_property) = 0; + } + break; + case 't': + nm_assert (dbus_type_s[1] == '\0'); + if (value) + *((guint64 *) p_property) = g_variant_get_uint64 (value); + else { + nm_assert (nm_utils_g_param_spec_is_default (param_spec)); + *((guint64 *) p_property) = 0; + } + break; + case 's': + nm_assert (dbus_type_s[1] == '\0'); + nm_clear_g_free ((char **) p_property); + if (value) + *((char **) p_property) = g_variant_dup_string (value, NULL); + else { + nm_assert (nm_utils_g_param_spec_is_default (param_spec)); + *((char **) p_property) = NULL; + } + break; + case 'o': + nm_assert (dbus_type_s[1] == '\0'); + notify_update_prop_flags = nml_dbus_property_o_notify (self, + p_property, + dbobj, + meta_iface, + dbus_property_idx, + value); + break; + case 'a': + switch (dbus_type_s[1]) { + case 'y': + nm_assert (dbus_type_s[2] == '\0'); + { + gconstpointer v; + gsize l; + GBytes *b = NULL; + + if (value) { + v = g_variant_get_fixed_array (value, &l, 1); + + if (l > 0) { + /* empty arrays are coerced to NULL. */ + b = g_bytes_new (v, l); + } + } + + nm_clear_pointer ((GBytes **) p_property, g_bytes_unref); + *((GBytes **) p_property) = b; + } + break; + case 's': + nm_assert (dbus_type_s[2] == '\0'); + nm_assert (param_spec->value_type == G_TYPE_STRV); + + g_strfreev (*((char ***) p_property)); + if (value) + *((char ***) p_property) = g_variant_dup_strv (value, NULL); + else + *((char ***) p_property) = NULL; + break; + case 'o': + nm_assert (dbus_type_s[2] == '\0'); + notify_update_prop_flags = nml_dbus_property_ao_notify (self, + p_property, + dbobj, + meta_iface, + dbus_property_idx, + value); + break; + default: + nm_assert_not_reached (); + } + break; + default: + nm_assert_not_reached (); + } + +notify: + if (NM_FLAGS_HAS (notify_update_prop_flags, NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY)) + g_object_notify_by_pspec (dbobj->nmobj, (GParamSpec *) param_spec); +} + +static void +_obj_handle_dbus_iface_changes (NMClient *self, + NMLDBusObject *dbobj, + NMLDBusObjIfaceData *db_iface_data) +{ + NMLDBusObjPropData *db_prop_data; + gboolean is_self = (G_OBJECT (self) == dbobj->nmobj); + gboolean is_removed; + gboolean type_compatible; + guint8 i_prop; + + nm_assert (NM_IS_CLIENT (self)); + nm_assert (is_self || NM_IS_OBJECT (dbobj->nmobj)); + + if (G_UNLIKELY (!db_iface_data->nmobj_checked)) { + db_iface_data->nmobj_checked = TRUE; + type_compatible = db_iface_data->dbus_iface.meta->get_type_fcn + && g_type_is_a (G_OBJECT_TYPE (dbobj->nmobj), db_iface_data->dbus_iface.meta->get_type_fcn ()); + db_iface_data->nmobj_compatible = type_compatible; + } else + type_compatible = db_iface_data->nmobj_compatible; + + if (!type_compatible) { + /* on D-Bus, we have this interface associate with the object, but apparently + * it is not compatible. This is either a bug, or NetworkManager exposed an + * unexpected interface on D-Bus object for which we create a certain NMObject + * type. */ + return; + } + + is_removed = c_list_is_empty (&db_iface_data->iface_lst); + + nm_assert ( is_removed + || !c_list_is_empty (&db_iface_data->changed_prop_lst_head)); + + _nm_client_queue_notify_object (self, dbobj->nmobj, NULL); + + if (is_removed) { + for (i_prop = 0; i_prop < db_iface_data->dbus_iface.meta->n_dbus_properties; i_prop++) { + _obj_handle_dbus_prop_changes (self, + dbobj, + db_iface_data, + i_prop, + NULL); + } + } else { + while ((db_prop_data = c_list_first_entry (&db_iface_data->changed_prop_lst_head, NMLDBusObjPropData, changed_prop_lst))) { + gs_unref_variant GVariant *prop_data_value = NULL; + + c_list_unlink (&db_prop_data->changed_prop_lst); + + nm_assert (db_prop_data >= db_iface_data->prop_datas); + nm_assert (db_prop_data < &db_iface_data->prop_datas[db_iface_data->dbus_iface.meta->n_dbus_properties]); + nm_assert (db_prop_data->prop_data_value); + + /* Currently NMLDBusObject forgets about the variant. Theoretically, it could cache + * it, but there is no need because we update the property in nmobj (which extracts and + * keeps the property value itself). + * + * Note that we only consume the variant here when we process it. + * That implies that we already created a NMObject for the dbobj + * instance. Unless that happens, we cache the last seen property values. */ + prop_data_value = g_steal_pointer (&db_prop_data->prop_data_value); + + i_prop = (db_prop_data - &db_iface_data->prop_datas[0]); + _obj_handle_dbus_prop_changes (self, + dbobj, + db_iface_data, + i_prop, + prop_data_value); + } + } +} + +static void +_obj_handle_dbus_changes (NMClient *self, + NMLDBusObject *dbobj) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + NMLDBusObjIfaceData *db_iface_data; + NMLDBusObjIfaceData *db_iface_data_safe; + gs_unref_object GObject *nmobj_unregistering = NULL; + + _ASSERT_dbobj (dbobj, self); + + /* In a first step we only remember all the changes that that a D-Bus message brings + * and queue the object to process them. + * + * Here (in step 2) we look at what changed on D-Bus and propagate those changes + * to the NMObject instance. + * + * Note that here we still must not emit any GObject signals. That follows later, + * and again if the object changes, we will just queue that we handle the changes + * later. */ + + c_list_for_each_entry_safe (db_iface_data, db_iface_data_safe, &dbobj->iface_lst_head, iface_lst) { + if (!db_iface_data->iface_removed) + continue; + c_list_unlink (&db_iface_data->iface_lst); + if ( db_iface_data->dbus_iface_is_wellknown + && dbobj->nmobj) + _obj_handle_dbus_iface_changes (self, dbobj, db_iface_data); + nml_dbus_obj_iface_data_destroy (db_iface_data); + } + + if ( G_UNLIKELY (!dbobj->nmobj) + && !c_list_is_empty (&dbobj->iface_lst_head)) { + + /* Try to create a NMObject for this D-Bus object. Note that we detect the type + * based on the interfaces that it has, and if we make a choice once, we don't + * change. That means, one D-Bus object can only be of one type. */ + + if (NM_IN_SET (dbobj->dbus_path, _dbus_path_nm, + _dbus_path_settings, + _dbus_path_dns_manager)) { + /* For the main types, we don't detect them based on the interfaces present, + * but on the path names. Of course, both should correspond anyway. */ + NML_NMCLIENT_LOG_T (self, "[%s]: register NMClient for D-Bus object", + dbobj->dbus_path->str); + dbobj->nmobj = G_OBJECT (self); + if (dbobj->dbus_path == _dbus_path_nm) { + nm_assert (!priv->dbobj_nm); + priv->dbobj_nm = dbobj; + } else if (dbobj->dbus_path == _dbus_path_settings) { + nm_assert (!priv->dbobj_settings); + priv->dbobj_settings = dbobj; + } else { + nm_assert (dbobj->dbus_path == _dbus_path_dns_manager); + nm_assert (!priv->dbobj_dns_manager); + priv->dbobj_dns_manager = dbobj; + } + nml_dbus_object_set_obj_state (dbobj, NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY, self); + } else { + GType gtype = G_TYPE_NONE; + NMLDBusMetaInteracePrio curr_prio = NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW - 1; + + c_list_for_each_entry (db_iface_data, &dbobj->iface_lst_head, iface_lst) { + nm_assert (!db_iface_data->iface_removed); + if (!db_iface_data->dbus_iface_is_wellknown) + break; + if (db_iface_data->dbus_iface.meta->interface_prio <= curr_prio) + continue; + curr_prio = db_iface_data->dbus_iface.meta->interface_prio; + gtype = db_iface_data->dbus_iface.meta->get_type_fcn (); + } + if (gtype != G_TYPE_NONE) { + dbobj->nmobj = g_object_new (gtype, NULL); + + NML_NMCLIENT_LOG_T (self, "[%s]: register new NMObject "NM_HASH_OBFUSCATE_PTR_FMT" of type %s", + dbobj->dbus_path->str, + NM_HASH_OBFUSCATE_PTR (dbobj->nmobj), + g_type_name (gtype)); + + nm_assert (NM_IS_OBJECT (dbobj->nmobj)); + NM_OBJECT_GET_CLASS (dbobj->nmobj)->register_client (NM_OBJECT (dbobj->nmobj), self, dbobj); + nml_dbus_object_set_obj_state (dbobj, NML_DBUS_OBJ_STATE_WITH_NMOBJ_NOT_READY, self); + } + } + } + + c_list_for_each_entry (db_iface_data, &dbobj->iface_lst_head, iface_lst) { + nm_assert (!db_iface_data->iface_removed); + if (!db_iface_data->dbus_iface_is_wellknown) + break; + if (c_list_is_empty (&db_iface_data->changed_prop_lst_head)) + continue; + if (dbobj->nmobj) + _obj_handle_dbus_iface_changes (self, dbobj, db_iface_data); + } + + if ( c_list_is_empty (&dbobj->iface_lst_head) + && dbobj->nmobj) { + + if (dbobj->nmobj == G_OBJECT (self)) { + dbobj->nmobj = NULL; + NML_NMCLIENT_LOG_T (self, "[%s]: unregister NMClient from D-Bus object", + dbobj->dbus_path->str); + if (dbobj->dbus_path == _dbus_path_nm) { + nm_assert (priv->dbobj_nm == dbobj); + priv->dbobj_nm = NULL; + nml_dbus_property_o_clear_many (priv->nm.property_o, G_N_ELEMENTS (priv->nm.property_o), self); + nml_dbus_property_ao_clear_many (priv->nm.property_ao, G_N_ELEMENTS (priv->nm.property_ao), self); + } else if (dbobj->dbus_path == _dbus_path_settings) { + nm_assert (priv->dbobj_settings == dbobj); + priv->dbobj_settings = NULL; + nml_dbus_property_ao_clear (&priv->settings.connections, self); + } else { + nm_assert (dbobj->dbus_path == _dbus_path_dns_manager); + nm_assert (priv->dbobj_dns_manager == dbobj); + priv->dbobj_dns_manager = NULL; + } + } else { + nmobj_unregistering = g_steal_pointer (&dbobj->nmobj); + nml_dbus_object_set_obj_state (dbobj, NML_DBUS_OBJ_STATE_WATCHED_ONLY, self); + NML_NMCLIENT_LOG_T (self, "[%s]: unregister NMObject "NM_HASH_OBFUSCATE_PTR_FMT" of type %s", + dbobj->dbus_path->str, + NM_HASH_OBFUSCATE_PTR (nmobj_unregistering), + g_type_name (G_OBJECT_TYPE (nmobj_unregistering))); + NM_OBJECT_GET_CLASS (nmobj_unregistering)->unregister_client (NM_OBJECT (nmobj_unregistering), self, dbobj); + } + } + + nml_dbus_object_obj_changed_link (self, dbobj, NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ); +} + +/*****************************************************************************/ + +static void +_dbus_handle_obj_changed_nmobj (NMClient *self) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + NMLDBusObject *dbobj; + CList obj_changed_tmp_lst_head = C_LIST_INIT (obj_changed_tmp_lst_head); + + nm_assert (!nml_dbus_object_obj_changed_any_linked (self, ~NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ)); + + /* First we notify all watchers that these objects changed. Note that we only do that + * here for the list before processing the changes below in a loop. That is, because + * processing changes can again enqueue changed objects, and we only want to want to + * notify watchers for the events that happened earlier (not repeatedly notify them). */ + c_list_splice (&obj_changed_tmp_lst_head, &priv->obj_changed_lst_head); + while ((dbobj = c_list_first_entry (&obj_changed_tmp_lst_head, NMLDBusObject, obj_changed_lst))) { + nm_c_list_move_tail (&priv->obj_changed_lst_head, &dbobj->obj_changed_lst); + _dbobjs_notify_watchers_for_dbobj (self, dbobj); + } + +again: + + nm_assert (!nml_dbus_object_obj_changed_any_linked (self, ~NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ)); + + c_list_splice (&obj_changed_tmp_lst_head, &priv->obj_changed_lst_head); + + while ((dbobj = c_list_first_entry (&obj_changed_tmp_lst_head, NMLDBusObject, obj_changed_lst))) { + + if (!nml_dbus_object_obj_changed_consume (self, dbobj, NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ)) { + nm_assert_not_reached (); + continue; + } + + if (!dbobj->nmobj) + continue; + + if (dbobj->nmobj == G_OBJECT (self)) { + if (dbobj == priv->dbobj_nm) { + nml_dbus_property_o_notify_changed_many (priv->nm.property_o, G_N_ELEMENTS (priv->nm.property_o), self); + nml_dbus_property_ao_notify_changed_many (priv->nm.property_ao, G_N_ELEMENTS (priv->nm.property_ao), self); + } else if (dbobj == priv->dbobj_settings) + nml_dbus_property_ao_notify_changed (&priv->settings.connections, self); + else + nm_assert (dbobj == priv->dbobj_dns_manager); + } else + NM_OBJECT_GET_CLASS (dbobj->nmobj)->obj_changed_notify (NM_OBJECT (dbobj->nmobj)); + + _dbobjs_check_dbobj_ready (self, dbobj); + } + + if (!c_list_is_empty (&priv->obj_changed_lst_head)) { + nm_assert (nml_dbus_object_obj_changed_any_linked (self, NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ)); + /* we got new changes enqueued. Need to check again. */ + goto again; + } +} + +static void +_dbus_handle_obj_changed_dbus (NMClient *self, + const char *log_context) +{ + NMClientPrivate *priv; + NMLDBusObject *dbobj; + CList obj_changed_tmp_lst_head = C_LIST_INIT (obj_changed_tmp_lst_head); + + priv = NM_CLIENT_GET_PRIVATE (self); + + /* We move the changed list onto a temporary list and consume that. + * Note that nml_dbus_object_obj_changed_consume() will move the object + * back to the original list if there are changes of another type. + * + * This is done so that we can enqueue more changes while processing the + * change list. */ + c_list_splice (&obj_changed_tmp_lst_head, &priv->obj_changed_lst_head); + + while ((dbobj = c_list_first_entry (&obj_changed_tmp_lst_head, NMLDBusObject, obj_changed_lst))) { + nm_auto_unref_nml_dbusobj NMLDBusObject *dbobj_unref = NULL; + + if (!nml_dbus_object_obj_changed_consume (self, dbobj, NML_DBUS_OBJ_CHANGED_TYPE_DBUS)) + continue; + + nm_assert (dbobj->obj_state >= NML_DBUS_OBJ_STATE_ON_DBUS); + + dbobj_unref = nml_dbus_object_ref (dbobj); + + _obj_handle_dbus_changes (self, dbobj); + + if (dbobj->obj_state == NML_DBUS_OBJ_STATE_UNLINKED) + continue; + + if ( c_list_is_empty (&dbobj->iface_lst_head) + && c_list_is_empty (&dbobj->watcher_lst_head)) { + NML_NMCLIENT_LOG_T (self, "[%s]: drop D-Bus instance", dbobj->dbus_path->str); + nml_dbus_object_set_obj_state (dbobj, NML_DBUS_OBJ_STATE_UNLINKED, self); + if (!g_hash_table_steal (priv->dbus_objects, dbobj)) + nm_assert_not_reached (); + nml_dbus_object_unref (dbobj); + } + } + + /* D-Bus changes can only be enqueued in an earlier stage. We don't expect + * anymore changes of type D-Bus at this point. */ + nm_assert (!nml_dbus_object_obj_changed_any_linked (self, NML_DBUS_OBJ_CHANGED_TYPE_DBUS)); +} + +static void +_dbus_handle_changes_commit (NMClient *self, + gboolean allow_init_start_check_complete) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; + + _dbus_handle_obj_changed_nmobj (self); + + dbus_context = nm_g_main_context_push_thread_default_if_necessary (priv->main_context); + + _nm_client_notify_event_emit (self); + + _set_nm_running (self); + + if (allow_init_start_check_complete) + _init_start_check_complete (self); +} + +static void +_dbus_handle_changes (NMClient *self, + const char *log_context, + gboolean allow_init_start_check_complete) +{ + _dbus_handle_obj_changed_dbus (self, log_context); + _dbus_handle_changes_commit (self, allow_init_start_check_complete); +} + +static gboolean +_dbus_handle_properties_changed (NMClient *self, + const char *log_context, + const char *object_path, + const char *interface_name, + gboolean allow_add_iface, + GVariant *changed_properties, + NMLDBusObject **inout_dbobj) +{ + NMLDBusObject *dbobj = NULL; + NMLDBusObjIfaceData *db_iface_data = NULL; + nm_auto_ref_string NMRefString *dbus_path = NULL; + + nm_assert (!changed_properties || g_variant_is_of_type (changed_properties, G_VARIANT_TYPE ("a{sv}"))); + + { + gs_free char *ss = NULL; + + NML_NMCLIENT_LOG_T (self, "[%s]: %s: properties changed for interface %s { %s }", + object_path, log_context, interface_name, + (ss = g_variant_print (changed_properties, TRUE))); + } + + if (inout_dbobj) { + dbobj = *inout_dbobj; + nm_assert (!dbobj || nm_streq (object_path, dbobj->dbus_path->str)); + } + if (!dbobj) { + dbus_path = nm_ref_string_new (object_path); + dbobj = _dbobjs_dbobj_get_r (self, dbus_path); + } + + if (dbobj) + db_iface_data = nml_dbus_object_iface_data_get (dbobj, interface_name, allow_add_iface); + else if (allow_add_iface) { + dbobj = _dbobjs_dbobj_create (self, g_steal_pointer (&dbus_path)); + nml_dbus_object_set_obj_state (dbobj, NML_DBUS_OBJ_STATE_ON_DBUS, self); + db_iface_data = nml_dbus_object_iface_data_get (dbobj, interface_name, TRUE); + } + + NM_SET_OUT (inout_dbobj, dbobj); + + if (!db_iface_data) { + if (allow_add_iface) + NML_NMCLIENT_LOG_E (self, "%s: [%s] too many interfaces on object. Something is very wrong", log_context, object_path); + else + NML_NMCLIENT_LOG_E (self, "%s: [%s] property changed signal for non existing interface %s", log_context, object_path, interface_name); + nm_assert ( !dbobj + || dbobj->obj_state != NML_DBUS_OBJ_STATE_UNLINKED); return FALSE; } + + if (!db_iface_data->dbus_iface_is_wellknown) + NML_NMCLIENT_LOG_W (self, "%s: [%s] ignore unknown interface %s", log_context, object_path, interface_name); + else if (changed_properties) { + GVariantIter iter_prop; + const char *property_name; + GVariant *property_value_tmp; + + g_variant_iter_init (&iter_prop, changed_properties); + while (g_variant_iter_next (&iter_prop, "{&sv}", &property_name, &property_value_tmp)) { + _nm_unused gs_unref_variant GVariant *property_value = property_value_tmp; + const NMLDBusMetaProperty *meta_property; + NMLDBusObjPropData *db_propdata; + guint property_idx; + + meta_property = nml_dbus_meta_property_get (db_iface_data->dbus_iface.meta, property_name, &property_idx); + if (!meta_property) { + NML_NMCLIENT_LOG_W (self, "%s: [%s]: ignore unknown property %s.%s", log_context, object_path, interface_name, property_name); + continue; + } + + db_propdata = &db_iface_data->prop_datas[property_idx]; + + NML_NMCLIENT_LOG_T (self, "[%s]: %s: %s property %s.%s", + object_path, log_context, + db_propdata->prop_data_value ? "update" : "set", + interface_name, property_name); + + nm_g_variant_unref (db_propdata->prop_data_value); + db_propdata->prop_data_value = g_steal_pointer (&property_value); + nm_c_list_move_tail (&db_iface_data->changed_prop_lst_head, &db_propdata->changed_prop_lst); + } + } + + nml_dbus_object_obj_changed_link (self, dbobj, NML_DBUS_OBJ_CHANGED_TYPE_DBUS); + return TRUE; +} + +static gboolean +_dbus_handle_interface_added (NMClient *self, + const char *log_context, + const char *object_path, + GVariant *ifaces) +{ + gboolean changed = FALSE; + const char *interface_name; + GVariant *changed_properties; + GVariantIter iter_ifaces; + NMLDBusObject *dbobj = NULL; + + nm_assert (g_variant_is_of_type (ifaces, G_VARIANT_TYPE ("a{sa{sv}}"))); + + g_variant_iter_init (&iter_ifaces, ifaces); + while (g_variant_iter_next (&iter_ifaces, "{&s@a{sv}}", &interface_name, &changed_properties)) { + _nm_unused gs_unref_variant GVariant *changed_properties_free = changed_properties; + + if (_dbus_handle_properties_changed (self, log_context, object_path, interface_name, TRUE, changed_properties, &dbobj)) + changed = TRUE; + } + + return changed; +} + +static gboolean +_dbus_handle_interface_removed (NMClient *self, + const char *log_context, + const char *object_path, + NMLDBusObject **inout_dbobj, + const char *const*removed_interfaces) +{ + gboolean changed = FALSE; + NMLDBusObject *dbobj; + gsize i; + + if ( inout_dbobj + && *inout_dbobj) { + dbobj = *inout_dbobj; + nm_assert (dbobj == _dbobjs_dbobj_get_s (self, object_path)); + } else { + dbobj = _dbobjs_dbobj_get_s (self, object_path); + if (!dbobj) { + NML_NMCLIENT_LOG_E (self, "%s: [%s]: receive interface removed event for non existing object", log_context, object_path); + return FALSE; + } + NM_SET_OUT (inout_dbobj, dbobj); + } + + for (i = 0; removed_interfaces[i]; i++) { + NMLDBusObjIfaceData *db_iface_data; + const char *interface_name = removed_interfaces[i]; + + db_iface_data = nml_dbus_object_iface_data_get (dbobj, interface_name, FALSE); + if (!db_iface_data) { + NML_NMCLIENT_LOG_E (self, "%s: [%s] receive interface remove event for unexpected interface %s", log_context, object_path, interface_name); + continue; + } + + NML_NMCLIENT_LOG_T (self, "%s: [%s] receive interface remove event for interface %s", log_context, object_path, interface_name); + db_iface_data->iface_removed = TRUE; + changed = TRUE; + } + + if (changed) + nml_dbus_object_obj_changed_link (self, dbobj, NML_DBUS_OBJ_CHANGED_TYPE_DBUS); + + return changed; +} + +static void +_dbus_managed_objects_changed_cb (const char *object_path, + GVariant *added_interfaces_and_properties, + const char *const*removed_interfaces, + gpointer user_data) +{ + NMClient *self = user_data; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + const char *log_context; + gboolean changed; + + if (priv->get_managed_objects_cancellable) { + /* we still wait for the initial GetManagedObjects(). Ignore the event. */ + return; + } + + if (!added_interfaces_and_properties) { + log_context = "interfaces-removed"; + changed = _dbus_handle_interface_removed (self, log_context, object_path, NULL, removed_interfaces); + } else { + log_context = "interfaces-added"; + changed = _dbus_handle_interface_added (self, log_context, object_path, added_interfaces_and_properties); + } + + if (changed) + _dbus_handle_changes (self, log_context, TRUE); +} + +static void +_dbus_properties_changed_cb (GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + NMClient *self = user_data; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + const char *interface_name; + gs_unref_variant GVariant *changed_properties = NULL; + gs_free const char **invalidated_properties = NULL; + const char *log_context = "properties-changed"; + + if (priv->get_managed_objects_cancellable) { + /* we still wait for the initial GetManagedObjects(). Ignore the event. */ + return; + } + + if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa{sv}as)"))) + return; + + g_variant_get (parameters, + "(&s@a{sv}^a&s)", + &interface_name, + &changed_properties, + &invalidated_properties); + + if (invalidated_properties && invalidated_properties[0]) { + NML_NMCLIENT_LOG_W (self, "%s: [%s] ignore invalidated properties on interface %s", + log_context, object_path, interface_name); + } + + if (_dbus_handle_properties_changed (self, log_context, object_path, interface_name, FALSE, changed_properties, NULL)) + _dbus_handle_changes (self, log_context, TRUE); +} + +static void +_dbus_get_managed_objects_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + NMClient *self; + NMClientPrivate *priv; + gs_unref_variant GVariant *ret = NULL; + gs_unref_variant GVariant *managed_objects = NULL; + gs_free_error GError *error = NULL; + gs_unref_object GObject *context_busy_watcher = NULL; + + nm_utils_user_data_unpack (user_data, &self, &context_busy_watcher); + + ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error); + + nm_assert ((!!ret) != (!!error)); + + if ( !ret + && nm_utils_error_is_cancelled (error, FALSE)) + return; + + priv = NM_CLIENT_GET_PRIVATE (self); + + if (ret) { + nm_assert (g_variant_is_of_type (ret, G_VARIANT_TYPE ("(a{oa{sa{sv}}})"))); + managed_objects = g_variant_get_child_value (ret, 0); + } + + g_clear_object (&priv->get_managed_objects_cancellable); + + if (!managed_objects) { + NML_NMCLIENT_LOG_D (self, "GetManagedObjects() call failed: %s", error->message); + /* hm, now that's odd. Maybe NetworkManager just quit and we are about to get + * a name-owner changed signal soon. Treat this as if we got no managed objects at all. */ + } else + NML_NMCLIENT_LOG_D (self, "GetManagedObjects() completed"); + + if (managed_objects) { + GVariantIter iter; + const char *object_path; + GVariant *ifaces_tmp; + + g_variant_iter_init (&iter, managed_objects); + while (g_variant_iter_next (&iter, "{&o@a{sa{sv}}}", &object_path, &ifaces_tmp)) { + gs_unref_variant GVariant *ifaces = ifaces_tmp; + + _dbus_handle_interface_added (self, "get-managed-objects", object_path, ifaces); + } + } + + /* always call _dbus_handle_changes(), even if nothing changed. We need this to complete + * initialization. */ + _dbus_handle_changes (self, "get-managed-objects", TRUE); +} + +/*****************************************************************************/ + +static void +_nm_client_get_settings_call_cb (GObject *source, GAsyncResult *result, gpointer user_data) +{ + NMRemoteConnection *remote_connection; + NMClient *self; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *settings = NULL; + NMLDBusObject *dbobj; + + ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error); + if ( !ret + && nm_utils_error_is_cancelled (error, FALSE)) + return; + + remote_connection = user_data; + + self = _nm_object_get_client (remote_connection); + + dbobj = _nm_object_get_dbobj (remote_connection); + + _ASSERT_dbobj (dbobj, self); + + if (!ret) { + NML_NMCLIENT_LOG_T (self, "[%s] GetSettings() completed with error: %s", + dbobj->dbus_path->str, + error->message); + } else { + NML_NMCLIENT_LOG_T (self, "[%s] GetSettings() completed with success", + dbobj->dbus_path->str); + g_variant_get (ret, + "(@a{sa{sv}})", + &settings); + } + + _nm_remote_settings_get_settings_commit (remote_connection, settings); + + _dbus_handle_changes_commit (self, TRUE); +} + +void +_nm_client_get_settings_call (NMClient *self, + NMLDBusObject *dbobj) +{ + GCancellable *cancellable; + + cancellable = _nm_remote_settings_get_settings_prepare (NM_REMOTE_CONNECTION (dbobj->nmobj)); + + _nm_client_dbus_call_simple (self, + cancellable, + dbobj->dbus_path->str, + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + "GetSettings", + g_variant_new ("()"), + G_VARIANT_TYPE ("(a{sa{sv}})"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + _nm_client_get_settings_call_cb, + dbobj->nmobj); +} + +static void +_dbus_settings_updated_cb (GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + NMClient *self = user_data; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + const char *log_context = "settings-updated"; + NMLDBusObject *dbobj; + + if (priv->get_managed_objects_cancellable) { + /* we still wait for the initial GetManagedObjects(). Ignore the event. */ + return; + } + + if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()"))) + return; + + dbobj = _dbobjs_dbobj_get_s (self, object_path); + + if ( !dbobj + || !NM_IS_REMOTE_CONNECTION (dbobj->nmobj)) { + NML_NMCLIENT_LOG_W (self, "%s: [%s] ignore Updated signal for non-existing setting", + log_context, object_path); + return; + } + + NML_NMCLIENT_LOG_T (self, "%s: [%s] Updated signal received", + log_context, object_path); + + _nm_client_get_settings_call (self, dbobj); +} + +/*****************************************************************************/ + +static void +_dbus_nm_connection_active_state_changed_cb (GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + NMClient *self = user_data; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + const char *log_context = "active-connection-state-changed"; + NMLDBusObject *dbobj; + guint32 state; + guint32 reason; + + if (priv->get_managed_objects_cancellable) { + /* we still wait for the initial GetManagedObjects(). Ignore the event. */ + return; + } + + if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(uu)"))) { + NML_NMCLIENT_LOG_E (self, "%s: [%s] ignore StateChanged signal with unexpected signature", + log_context, object_path); + return; + } + + dbobj = _dbobjs_dbobj_get_s (self, object_path); + + if ( !dbobj + || !NM_IS_ACTIVE_CONNECTION (dbobj->nmobj)) { + NML_NMCLIENT_LOG_E (self, "%s: [%s] ignore StateChanged signal for non-existing active connection", + log_context, object_path); + return; + } + + g_variant_get (parameters, "(uu)", &state, &reason); + + NML_NMCLIENT_LOG_T (self, "%s: [%s] StateChanged signal received", + log_context, object_path); + + _nm_active_connection_state_changed_commit (NM_ACTIVE_CONNECTION (dbobj->nmobj), + state, + reason); + + _dbus_handle_changes_commit (self, TRUE); +} + +/*****************************************************************************/ + +static void +_dbus_nm_vpn_connection_state_changed_cb (GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + NMClient *self = user_data; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + const char *log_context = "vpn-connection-state-changed"; + NMLDBusObject *dbobj; + guint32 state; + guint32 reason; + + if (priv->get_managed_objects_cancellable) { + /* we still wait for the initial GetManagedObjects(). Ignore the event. */ + return; + } + + if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(uu)"))) { + NML_NMCLIENT_LOG_E (self, "%s: [%s] ignore VpnStateChanged signal with unexpected signature", + log_context, object_path); + return; + } + + dbobj = _dbobjs_dbobj_get_s (self, object_path); + + if ( !dbobj + || !NM_IS_VPN_CONNECTION (dbobj->nmobj)) { + NML_NMCLIENT_LOG_E (self, "%s: [%s] ignore VpnStateChanged signal for non-existing vpn connection", + log_context, object_path); + return; + } + + g_variant_get (parameters, "(uu)", &state, &reason); + + NML_NMCLIENT_LOG_T (self, "%s: [%s] VpnStateChanged signal received", + log_context, object_path); + + _nm_vpn_connection_state_changed_commit (NM_VPN_CONNECTION (dbobj->nmobj), + state, + reason); + + _dbus_handle_changes_commit (self, TRUE); +} + +/*****************************************************************************/ + +static void +_emit_permissions_changed (NMClient *self, + GHashTable *permissions, + gboolean force_unknown) +{ + GHashTableIter iter; + gpointer key; + gpointer value; + + if (!permissions) + return; + if (self->obj_base.is_disposing) + return; + + g_hash_table_iter_init (&iter, permissions); + while (g_hash_table_iter_next (&iter, &key, &value)) { + g_signal_emit (self, + signals[PERMISSION_CHANGED], + 0, + GPOINTER_TO_UINT (key), + force_unknown + ? (guint) NM_CLIENT_PERMISSION_NONE + : GPOINTER_TO_UINT (value)); + } +} + + +static void +_dbus_check_permissions_start_cb (GObject *source, GAsyncResult *result, gpointer user_data) +{ + nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; + NMClient *self; + NMClientPrivate *priv; + gs_unref_variant GVariant *ret = NULL; + nm_auto_free_variant_iter GVariantIter *v_permissions = NULL; + gs_unref_hashtable GHashTable *old_permissions = NULL; + gs_free_error GError *error = NULL; + const char *pkey; + const char *pvalue; + + ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error); + if ( !ret + && nm_utils_error_is_cancelled (error, FALSE)) + return; + + self = user_data; + priv = NM_CLIENT_GET_PRIVATE (self); + + g_clear_object (&priv->permissions_cancellable); + + if (!ret) { + NML_NMCLIENT_LOG_T (self, "GetPermissions call failed: %s", error->message); + return; + } + + NML_NMCLIENT_LOG_T (self, "GetPermissions call finished with success"); + + /* get list of old permissions for change notification */ + old_permissions = g_steal_pointer (&priv->permissions); + priv->permissions = g_hash_table_new (nm_direct_hash, NULL); + + g_variant_get (ret, "(a{ss})", &v_permissions); + while (g_variant_iter_next (v_permissions, "{&s&s}", &pkey, &pvalue)) { + NMClientPermission perm; + NMClientPermissionResult perm_result; + + perm = nm_permission_to_client (pkey); + if (perm == NM_CLIENT_PERMISSION_NONE) + continue; + + perm_result = nm_permission_result_to_client (pvalue); + + g_hash_table_insert (priv->permissions, + GUINT_TO_POINTER (perm), + GUINT_TO_POINTER (perm_result)); + if (old_permissions) { + g_hash_table_remove (old_permissions, + GUINT_TO_POINTER (perm)); + } + } + + dbus_context = nm_g_main_context_push_thread_default_if_necessary (priv->main_context); + _emit_permissions_changed (self, priv->permissions, FALSE); + _emit_permissions_changed (self, old_permissions, TRUE); +} + +static void +_dbus_check_permissions_start (NMClient *self) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + + nm_clear_g_cancellable (&priv->permissions_cancellable); + priv->permissions_cancellable = g_cancellable_new (); + + NML_NMCLIENT_LOG_T (self, "GetPermissions() call started..."); + + _nm_client_dbus_call_simple (self, + priv->permissions_cancellable, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "GetPermissions", + g_variant_new ("()"), + G_VARIANT_TYPE ("(a{ss})"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + _dbus_check_permissions_start_cb, + self); +} + +static void +_dbus_nm_check_permissions_cb (GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *signal_interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + NMClient *self = user_data; + + if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()"))) { + NML_NMCLIENT_LOG_E (self, "ignore CheckPermissions signal with unexpected signature %s", + g_variant_get_type_string (parameters)); + return; + } + + _dbus_check_permissions_start (self); +} + +/*****************************************************************************/ + +static void +_property_ao_notify_changed_connections_cb (NMLDBusPropertyAO *pr_ao, + NMClient *self, + NMObject *nmobj, + gboolean is_added /* or else removed */) +{ + _nm_client_notify_event_queue_emit_obj_signal (self, + G_OBJECT (self), + nmobj, + is_added, + 5, + is_added + ? signals[CONNECTION_ADDED] + : signals[CONNECTION_REMOVED]); +} + +static void +_property_ao_notify_changed_all_devices_cb (NMLDBusPropertyAO *pr_ao, + NMClient *self, + NMObject *nmobj, + gboolean is_added /* or else removed */) +{ + _nm_client_notify_event_queue_emit_obj_signal (self, + G_OBJECT (self), + nmobj, + is_added, + 6, + is_added + ? signals[ANY_DEVICE_ADDED] + : signals[ANY_DEVICE_REMOVED]); +} + +static void +_property_ao_notify_changed_devices_cb (NMLDBusPropertyAO *pr_ao, + NMClient *self, + NMObject *nmobj, + gboolean is_added /* or else removed */) +{ + _nm_client_notify_event_queue_emit_obj_signal (self, + G_OBJECT (self), + nmobj, + is_added, + 7, + is_added + ? signals[DEVICE_ADDED] + : signals[DEVICE_REMOVED]); +} + +static void +_property_ao_notify_changed_active_connections_cb (NMLDBusPropertyAO *pr_ao, + NMClient *self, + NMObject *nmobj, + gboolean is_added /* or else removed */) +{ + _nm_client_notify_event_queue_emit_obj_signal (self, + G_OBJECT (self), + nmobj, + is_added, + 8, + is_added + ? signals[ACTIVE_CONNECTION_ADDED] + : signals[ACTIVE_CONNECTION_REMOVED]); +} + +/*****************************************************************************/ + +typedef struct { + NMLDBusObjWatcherWithPtr *obj_watcher; + const char *op_name; + NMLDBusObject *dbobj; + GTask *task; + GVariant *extra_results; + gpointer result; + GType gtype; + gulong cancellable_id; +} RequestWaitData; + +static void +_request_wait_data_free (RequestWaitData *request_data) +{ + nm_assert (!request_data->obj_watcher); + nm_assert (request_data->cancellable_id == 0); + nm_assert (!request_data->task || G_IS_TASK (request_data->task)); + + nm_g_object_unref (request_data->task); + nm_g_object_unref (request_data->result); + nm_g_variant_unref (request_data->extra_results); + if (request_data->dbobj) + nml_dbus_object_unref (request_data->dbobj); + nm_g_slice_free (request_data); +} + +static void +_request_wait_task_return (RequestWaitData *request_data) +{ + gs_unref_object GTask *task = NULL; + + nm_assert (request_data); + nm_assert (G_IS_TASK (request_data->task)); + nm_assert (request_data->dbobj); + nm_assert (NM_IS_OBJECT (request_data->dbobj->nmobj)); + nm_assert (!request_data->result); + + task = g_steal_pointer (&request_data->task); + + request_data->result = g_object_ref (request_data->dbobj->nmobj); + nm_clear_g_signal_handler (g_task_get_cancellable (task), &request_data->cancellable_id); + nm_clear_pointer (&request_data->dbobj, nml_dbus_object_unref); + g_task_return_pointer (task, request_data, (GDestroyNotify) _request_wait_data_free); +} + +static gboolean +_request_wait_complete (NMClient *self, + RequestWaitData *request_data, + gboolean force_complete) +{ + NMLDBusObject *dbobj; + + nm_assert (request_data); + nm_assert (!request_data->result); + nm_assert (!request_data->obj_watcher); + nm_assert (request_data->dbobj); + + dbobj = request_data->dbobj; + + if (dbobj->obj_state == NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY) { + NML_NMCLIENT_LOG_D (self, "%s() succeeded with %s", request_data->op_name, dbobj->dbus_path->str); + nm_assert (G_TYPE_CHECK_INSTANCE_TYPE (dbobj->nmobj, request_data->gtype)); + _request_wait_task_return (request_data); + return TRUE; + } + + if ( force_complete + || dbobj->obj_state != NML_DBUS_OBJ_STATE_WITH_NMOBJ_NOT_READY) { + if (force_complete) + NML_NMCLIENT_LOG_D (self, "%s() succeeded with %s but object is in an unsuitable state", request_data->op_name, dbobj->dbus_path->str); + else + NML_NMCLIENT_LOG_W (self, "%s() succeeded with %s but object is in an unsuitable state", request_data->op_name, dbobj->dbus_path->str); + + g_task_return_error (request_data->task, g_error_new (NM_CLIENT_ERROR, + NM_CLIENT_ERROR_OBJECT_CREATION_FAILED, + _("request succeeded with %s but object is in an unsuitable state"), + dbobj->dbus_path->str)); + _request_wait_data_free (request_data); + return TRUE; + } + + return FALSE; +} + +static void +_request_wait_complete_cb (NMClient *self, + NMClientNotifyEventWithPtr *notify_event) +{ + _request_wait_complete (self, + notify_event->user_data, + TRUE); +} + +static void +_request_wait_obj_watcher_cb (NMClient *self, + gpointer obj_watcher_base) +{ + NMLDBusObjWatcherWithPtr *obj_watcher = obj_watcher_base; + RequestWaitData *request_data = obj_watcher->user_data; + NMLDBusObject *dbobj; + + dbobj = request_data->dbobj; + + if (dbobj->obj_state == NML_DBUS_OBJ_STATE_WITH_NMOBJ_NOT_READY) + return; + + nm_assert (NM_IN_SET ((NMLDBusObjState) dbobj->obj_state, NML_DBUS_OBJ_STATE_WATCHED_ONLY, + NML_DBUS_OBJ_STATE_ON_DBUS, + NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY)); + + _dbobjs_obj_watcher_unregister (self, g_steal_pointer (&request_data->obj_watcher)); + + nm_clear_g_signal_handler (g_task_get_cancellable (request_data->task), &request_data->cancellable_id); + + _nm_client_notify_event_queue_with_ptr (self, + NM_CLIENT_NOTIFY_EVENT_PRIO_AFTER + 30, + _request_wait_complete_cb, + request_data); +} + +static void +_request_wait_cancelled_cb (GCancellable *cancellable, + gpointer user_data) +{ + RequestWaitData *request_data = user_data; + NMClient *self; + GError *error = NULL; + + nm_assert (cancellable == g_task_get_cancellable (request_data->task)); + + nm_utils_error_set_cancelled (&error, FALSE, NULL); + + self = g_task_get_source_object (request_data->task); + + nm_clear_g_signal_handler (cancellable, &request_data->cancellable_id); + + _dbobjs_obj_watcher_unregister (self, g_steal_pointer (&request_data->obj_watcher)); + + g_task_return_error (request_data->task, error); + + _request_wait_data_free (request_data); +} + +static void +_request_wait_start (GTask *task_take, + const char *op_name, + GType gtype, + const char *dbus_path, + GVariant *extra_results_take) +{ + NMClient *self; + gs_unref_object GTask *task = g_steal_pointer (&task_take); + RequestWaitData *request_data; + GCancellable *cancellable; + NMLDBusObject *dbobj; + + nm_assert (G_IS_TASK (task)); + + self = g_task_get_source_object (task); + + dbobj = _dbobjs_get_nmobj (self, dbus_path, gtype); + + if (!dbobj) { + NML_NMCLIENT_LOG_E (self, "%s() succeeded with %s but object does not exist", op_name, dbus_path); + g_task_return_error (task, g_error_new (NM_CLIENT_ERROR, + NM_CLIENT_ERROR_FAILED, + _("operation succeeded but object %s does not exist"), + dbus_path)); + return; + } + + request_data = g_slice_new (RequestWaitData); + *request_data = (RequestWaitData) { + .task = g_steal_pointer (&task), + .op_name = op_name, + .gtype = gtype, + .dbobj = nml_dbus_object_ref (dbobj), + .obj_watcher = NULL, + .extra_results = g_steal_pointer (&extra_results_take), + .result = NULL, + .cancellable_id = 0, + }; + + if (_request_wait_complete (self, request_data, FALSE)) + return; + + NML_NMCLIENT_LOG_T (self, "%s() succeeded with %s. Wait for object to become ready", op_name, dbobj->dbus_path->str); + + request_data->obj_watcher = _dbobjs_obj_watcher_register_o (self, + dbobj, + _request_wait_obj_watcher_cb, + sizeof (NMLDBusObjWatcherWithPtr)); + request_data->obj_watcher->user_data = request_data; + + cancellable = g_task_get_cancellable (request_data->task); + if (cancellable) { + gulong id; + + id = g_cancellable_connect (cancellable, + G_CALLBACK (_request_wait_cancelled_cb), + request_data, + NULL); + if (id == 0) { + /* the callback was invoked synchronously, which destroyed @request_data. + * We must not touch @info anymore. */ + } else + request_data->cancellable_id = id; + } +} + +static gpointer +_request_wait_finish (NMClient *client, + GAsyncResult *result, + gpointer source_tag, + GVariant **out_result, + GError **error) +{ + RequestWaitData *request_data = NULL; + gpointer r; + + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + g_return_val_if_fail (nm_g_task_is_valid (result, client, source_tag), NULL); + + request_data = g_task_propagate_pointer (G_TASK (result), error); + if (!request_data) { + NM_SET_OUT (out_result, NULL); + return NULL; + } + + nm_assert (NM_IS_OBJECT (request_data->result)); + + NM_SET_OUT (out_result, g_steal_pointer (&request_data->extra_results)); + r = g_steal_pointer (&request_data->result); + + nm_assert (NM_IS_OBJECT (r)); + + _request_wait_data_free (request_data); + return r; +} + +/*****************************************************************************/ + +/** + * nm_client_get_dbus_connection: + * @client: a #NMClient + * + * Gets the %GDBusConnection of the instance. This can be either passed when + * constructing the instance (as "dbus-connection" property), or it will be + * automatically initialized during async/sync init. + * + * Returns: (transfer none): the D-Bus connection of the client, or %NULL if none is set. + * + * Since: 1.22 + **/ +GDBusConnection * +nm_client_get_dbus_connection (NMClient *client) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + + return NM_CLIENT_GET_PRIVATE (client)->dbus_connection; +} + +/** + * nm_client_get_dbus_name_owner: + * @client: a #NMClient + * + * Returns: (transfer none): the current name owner of the D-Bus service of NetworkManager. + * + * Since: 1.22 + **/ +const char * +nm_client_get_dbus_name_owner (NMClient *client) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); + + return NM_CLIENT_GET_PRIVATE (client)->name_owner; } /** @@ -214,10 +3797,7 @@ nm_client_get_version (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - if (!nm_client_get_nm_running (client)) - return NULL; - - return nm_manager_get_version (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->nm.version; } /** @@ -233,10 +3813,7 @@ nm_client_get_state (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN); - if (!nm_client_get_nm_running (client)) - return NM_STATE_UNKNOWN; - - return nm_manager_get_state (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->nm.state; } /** @@ -253,10 +3830,20 @@ nm_client_get_startup (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - if (!nm_client_get_nm_running (client)) - return FALSE; + return NM_CLIENT_GET_PRIVATE (client)->nm.startup; +} + +static void +_set_nm_running (NMClient *self) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + gboolean nm_running; - return nm_manager_get_startup (NM_CLIENT_GET_PRIVATE (client)->manager); + nm_running = priv->name_owner && !priv->get_managed_objects_cancellable; + if (priv->nm_running != nm_running) { + priv->nm_running = nm_running; + _notify (self, PROP_NM_RUNNING); + } } /** @@ -272,7 +3859,23 @@ nm_client_get_nm_running (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - return NM_CLIENT_GET_PRIVATE (client)->manager != NULL; + return NM_CLIENT_GET_PRIVATE (client)->nm_running; +} + +/** + * nm_client_get_metered: + * @client: a #NMClient + * + * Returns: whether the default route is metered. + * + * Since: 1.22 + */ +NMMetered +nm_client_get_metered (NMClient *client) +{ + g_return_val_if_fail (NM_IS_CLIENT (client), NM_METERED_UNKNOWN); + + return NM_CLIENT_GET_PRIVATE (client)->nm.metered; } /** @@ -288,10 +3891,7 @@ nm_client_networking_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - if (!nm_client_get_nm_running (client)) - return FALSE; - - return nm_manager_networking_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->nm.networking_enabled; } /** @@ -305,17 +3905,26 @@ nm_client_networking_get_enabled (NMClient *client) * all controlled interfaces are available for activation. * * Returns: %TRUE on success, %FALSE otherwise + * + * Deprecated: 1.22, use nm_client_networking_set_enabled_async() or GDBusConnection **/ gboolean nm_client_networking_set_enabled (NMClient *client, gboolean enable, GError **error) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - if (!_nm_client_check_nm_running (client, error)) - return FALSE; - - return nm_manager_networking_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, - enable, error); + /* FIXME(libnm-async-api): add nm_client_networking_set_enabled_async(). */ + + return _nm_client_dbus_call_sync_void (client, + NULL, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "Enable", + g_variant_new ("(b)", enable), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); } /** @@ -331,10 +3940,7 @@ nm_client_wireless_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - if (!nm_client_get_nm_running (client)) - return FALSE; - - return nm_manager_wireless_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->nm.wireless_enabled; } /** @@ -343,16 +3949,22 @@ nm_client_wireless_get_enabled (NMClient *client) * @enabled: %TRUE to enable wireless * * Enables or disables wireless devices. - **/ + * + * Deprecated: 1.22, use nm_client_wireless_set_enabled_async() or GDBusConnection + */ void nm_client_wireless_set_enabled (NMClient *client, gboolean enabled) { g_return_if_fail (NM_IS_CLIENT (client)); - if (!nm_client_get_nm_running (client)) - return; + /* FIXME(libnm-async-api): add nm_client_wireless_set_enabled_async(). */ - nm_manager_wireless_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled); + _nm_client_set_property_sync_legacy (client, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "WirelessEnabled", + "b", + enabled); } /** @@ -368,10 +3980,7 @@ nm_client_wireless_hardware_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - if (!nm_client_get_nm_running (client)) - return FALSE; - - return nm_manager_wireless_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->nm.wireless_hardware_enabled; } /** @@ -387,10 +3996,7 @@ nm_client_wwan_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - if (!nm_client_get_nm_running (client)) - return FALSE; - - return nm_manager_wwan_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->nm.wwan_enabled; } /** @@ -405,10 +4011,14 @@ nm_client_wwan_set_enabled (NMClient *client, gboolean enabled) { g_return_if_fail (NM_IS_CLIENT (client)); - if (!_nm_client_check_nm_running (client, NULL)) - return; + /* FIXME(libnm-async-api): add nm_client_wwan_set_enabled_async(). */ - nm_manager_wwan_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled); + _nm_client_set_property_sync_legacy (client, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "WwanEnabled", + "b", + enabled); } /** @@ -424,10 +4034,7 @@ nm_client_wwan_hardware_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - if (!nm_client_get_nm_running (client)) - return FALSE; - - return nm_manager_wwan_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->nm.wwan_hardware_enabled; } /** @@ -437,16 +4044,15 @@ nm_client_wwan_hardware_get_enabled (NMClient *client) * Determines whether WiMAX is enabled. * * Returns: %TRUE if WiMAX is enabled + * + * Deprecated: 1.22 This function always returns FALSE because WiMax is no longer supported **/ gboolean nm_client_wimax_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - if (!nm_client_get_nm_running (client)) - return FALSE; - - return nm_manager_wimax_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); + return FALSE; } /** @@ -455,16 +4061,13 @@ nm_client_wimax_get_enabled (NMClient *client) * @enabled: %TRUE to enable WiMAX * * Enables or disables WiMAX devices. + * + * Deprecated: 1.22 This function does nothing because WiMax is no longer supported **/ void nm_client_wimax_set_enabled (NMClient *client, gboolean enabled) { g_return_if_fail (NM_IS_CLIENT (client)); - - if (!nm_client_get_nm_running (client)) - return; - - nm_manager_wimax_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled); } /** @@ -474,16 +4077,15 @@ nm_client_wimax_set_enabled (NMClient *client, gboolean enabled) * Determines whether the WiMAX hardware is enabled. * * Returns: %TRUE if the WiMAX hardware is enabled + * + * Deprecated: 1.22 This function always returns FALSE because WiMax is no longer supported **/ gboolean nm_client_wimax_hardware_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - if (!nm_client_get_nm_running (client)) - return FALSE; - - return nm_manager_wimax_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); + return FALSE; } /** @@ -503,10 +4105,7 @@ nm_client_connectivity_check_get_available (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - if (!nm_client_get_nm_running (client)) - return FALSE; - - return nm_manager_connectivity_check_get_available (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->nm.connectivity_check_available; } /** @@ -524,10 +4123,7 @@ nm_client_connectivity_check_get_enabled (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - if (!nm_client_get_nm_running (client)) - return FALSE; - - return nm_manager_connectivity_check_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->nm.connectivity_check_enabled; } /** @@ -546,10 +4142,14 @@ nm_client_connectivity_check_set_enabled (NMClient *client, gboolean enabled) { g_return_if_fail (NM_IS_CLIENT (client)); - if (!nm_client_get_nm_running (client)) - return; + /* FIXME(libnm-async-api): add nm_client_wireless_set_enabled_async(). */ - nm_manager_connectivity_check_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled); + _nm_client_set_property_sync_legacy (client, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "ConnectivityCheckEnabled", + "b", + enabled); } /** @@ -568,10 +4168,7 @@ nm_client_connectivity_check_get_uri (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - if (!nm_client_get_nm_running (client)) - return NULL; - - return nm_manager_connectivity_check_get_uri (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->nm.connectivity_check_uri; } /** @@ -585,20 +4182,43 @@ nm_client_connectivity_check_get_uri (NMClient *client) * Gets NetworkManager current logging level and domains. * * Returns: %TRUE on success, %FALSE otherwise + * + * Deprecated: 1.22, use nm_client_get_logging_async() or GDBusConnection **/ gboolean -nm_client_get_logging (NMClient *client, char **level, char **domains, GError **error) +nm_client_get_logging (NMClient *client, + char **level, + char **domains, + GError **error) { + gs_unref_variant GVariant *ret = NULL; + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); g_return_val_if_fail (level == NULL || *level == NULL, FALSE); g_return_val_if_fail (domains == NULL || *domains == NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - if (!_nm_client_check_nm_running (client, error)) + /* FIXME(libnm-async-api): add nm_client_get_logging_async(). */ + + ret = _nm_client_dbus_call_sync (client, + NULL, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "GetLogging", + g_variant_new ("()"), + G_VARIANT_TYPE ("(ss)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); + if (!ret) return FALSE; - return nm_manager_get_logging (NM_CLIENT_GET_PRIVATE (client)->manager, - level, domains, error); + g_variant_get (ret, + "(ss)", + level, + domains); + return TRUE; } /** @@ -612,6 +4232,8 @@ nm_client_get_logging (NMClient *client, char **level, char **domains, GError ** * Sets NetworkManager logging level and/or domains. * * Returns: %TRUE on success, %FALSE otherwise + * + * Deprecated: 1.22, use nm_client_set_logging_async() or GDBusConnection **/ gboolean nm_client_set_logging (NMClient *client, const char *level, const char *domains, GError **error) @@ -619,11 +4241,20 @@ nm_client_set_logging (NMClient *client, const char *level, const char *domains, g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - if (!_nm_client_check_nm_running (client, error)) - return FALSE; - - return nm_manager_set_logging (NM_CLIENT_GET_PRIVATE (client)->manager, - level, domains, error); + /* FIXME(libnm-async-api): add nm_client_set_logging_async(). */ + + return _nm_client_dbus_call_sync_void (client, + NULL, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "SetLogging", + g_variant_new ("(ss)", + level ?: "", + domains ?: ""), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); } /** @@ -639,12 +4270,19 @@ nm_client_set_logging (NMClient *client, const char *level, const char *domains, NMClientPermissionResult nm_client_get_permission_result (NMClient *client, NMClientPermission permission) { + NMClientPrivate *priv; + gpointer result; + g_return_val_if_fail (NM_IS_CLIENT (client), NM_CLIENT_PERMISSION_RESULT_UNKNOWN); - if (!nm_client_get_nm_running (client)) + priv = NM_CLIENT_GET_PRIVATE (client); + if ( !priv->permissions + || !g_hash_table_lookup_extended (priv->permissions, + GUINT_TO_POINTER (permission), + NULL, + &result)) return NM_CLIENT_PERMISSION_RESULT_UNKNOWN; - - return nm_manager_get_permission_result (NM_CLIENT_GET_PRIVATE (client)->manager, permission); + return GPOINTER_TO_UINT (result); } /** @@ -663,10 +4301,7 @@ nm_client_get_connectivity (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN); - if (!nm_client_get_nm_running (client)) - return NM_CONNECTIVITY_UNKNOWN; - - return nm_manager_get_connectivity (NM_CLIENT_GET_PRIVATE (client)->manager); + return NM_CLIENT_GET_PRIVATE (client)->nm.connectivity; } /** @@ -683,39 +4318,52 @@ nm_client_get_connectivity (NMClient *client) * if you do not want to block. * * Returns: the (new) current connectivity state + * + * Deprecated: 1.22, use nm_client_check_connectivity_async() or GDBusConnection */ NMConnectivityState nm_client_check_connectivity (NMClient *client, GCancellable *cancellable, GError **error) { + NMClientPrivate *priv; + gs_unref_variant GVariant *ret = NULL; + guint32 connectivity; + g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN); - if (!_nm_client_check_nm_running (client, error)) + ret = _nm_client_dbus_call_sync (client, + cancellable, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "CheckConnectivity", + g_variant_new ("()"), + G_VARIANT_TYPE ("(u)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); + if (!ret) return NM_CONNECTIVITY_UNKNOWN; - return nm_manager_check_connectivity (NM_CLIENT_GET_PRIVATE (client)->manager, - cancellable, error); -} + g_variant_get (ret, + "(u)", + &connectivity); -static void -check_connectivity_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - NMConnectivityState connectivity; - GError *error = NULL; + /* upon receiving the synchronous response, we hack the NMClient state + * and update the property outside the ordered D-Bus messages (like + * "PropertiesChanged" signals). + * + * This is really ugly, we shouldn't do this. */ - connectivity = nm_manager_check_connectivity_finish (NM_MANAGER (object), - result, &error); - if (!error) - g_simple_async_result_set_op_res_gssize (simple, connectivity); - else - g_simple_async_result_take_error (simple, error); + priv = NM_CLIENT_GET_PRIVATE (client); + + if (priv->nm.connectivity != connectivity) { + priv->nm.connectivity = connectivity; + _notify (client, PROP_CONNECTIVITY); + } - g_simple_async_result_complete (simple); - g_object_unref (simple); + return connectivity; } /** @@ -736,22 +4384,23 @@ nm_client_check_connectivity_async (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; - g_return_if_fail (NM_IS_CLIENT (client)); - - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; - } - - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_check_connectivity_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nm_manager_check_connectivity_async (NM_CLIENT_GET_PRIVATE (client)->manager, - cancellable, check_connectivity_cb, simple); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); + + _nm_client_dbus_call (client, + client, + nm_client_check_connectivity_async, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "CheckConnectivity", + g_variant_new ("()"), + G_VARIANT_TYPE ("(u)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_variant_strip_dbus_error_cb); } /** @@ -770,16 +4419,20 @@ nm_client_check_connectivity_finish (NMClient *client, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; + gs_unref_variant GVariant *ret = NULL; + guint32 connectivity; g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NM_CONNECTIVITY_UNKNOWN); + g_return_val_if_fail (nm_g_task_is_valid (client, result, nm_client_check_connectivity_async), NM_CONNECTIVITY_UNKNOWN); - simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) + ret = g_task_propagate_pointer (G_TASK (result), error); + if (!ret) return NM_CONNECTIVITY_UNKNOWN; - return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple); + + g_variant_get (ret, + "(u)", + &connectivity); + return connectivity; } /** @@ -794,6 +4447,8 @@ nm_client_check_connectivity_finish (NMClient *client, * or cleared. * * Returns: %TRUE if the request was successful, %FALSE if it failed + * + * Deprecated: 1.22, use nm_client_save_hostname_async() or GDBusConnection **/ gboolean nm_client_save_hostname (NMClient *client, @@ -802,29 +4457,18 @@ nm_client_save_hostname (NMClient *client, GError **error) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - - if (!_nm_client_check_nm_running (client, error)) - return FALSE; - - return nm_remote_settings_save_hostname (NM_CLIENT_GET_PRIVATE (client)->settings, - hostname, cancellable, error); -} - -static void -save_hostname_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nm_remote_settings_save_hostname_finish (NM_REMOTE_SETTINGS (object), result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else - g_simple_async_result_take_error (simple, error); - - g_simple_async_result_complete (simple); - g_object_unref (simple); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); + + return _nm_client_dbus_call_sync_void (client, + cancellable, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + "SaveHostname", + g_variant_new ("(s)", hostname ?: ""), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); } /** @@ -846,23 +4490,23 @@ nm_client_save_hostname_async (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; - g_return_if_fail (NM_IS_CLIENT (client)); - - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; - } - - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_save_hostname_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nm_remote_settings_save_hostname_async (NM_CLIENT_GET_PRIVATE (client)->settings, - hostname, - cancellable, save_hostname_cb, simple); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); + + _nm_client_dbus_call (client, + client, + nm_client_save_hostname_async, + cancellable, + callback, + user_data, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + "SaveHostname", + g_variant_new ("(s)", hostname ?: ""), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_strip_dbus_error_cb); } /** @@ -880,20 +4524,14 @@ nm_client_save_hostname_finish (NMClient *client, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, client, nm_client_save_hostname_async), FALSE); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); + return g_task_propagate_boolean (G_TASK (result), error); } /*****************************************************************************/ -/* Devices */ +/* Devices */ /*****************************************************************************/ /** @@ -914,10 +4552,7 @@ nm_client_get_devices (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - if (!nm_client_get_nm_running (client)) - return ∅ - - return nm_manager_get_devices (NM_CLIENT_GET_PRIVATE (client)->manager); + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_CLIENT_GET_PRIVATE (client)->nm.property_ao[PROPERTY_AO_IDX_DEVICES]); } /** @@ -945,10 +4580,7 @@ nm_client_get_all_devices (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - if (!nm_client_get_nm_running (client)) - return ∅ - - return nm_manager_get_all_devices (NM_CLIENT_GET_PRIVATE (client)->manager); + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_CLIENT_GET_PRIVATE (client)->nm.property_ao[PROPERTY_AO_IDX_ALL_DEVICES]); } /** @@ -966,10 +4598,7 @@ nm_client_get_device_by_path (NMClient *client, const char *object_path) g_return_val_if_fail (NM_IS_CLIENT (client), NULL); g_return_val_if_fail (object_path, NULL); - if (!nm_client_get_nm_running (client)) - return NULL; - - return nm_manager_get_device_by_path (NM_CLIENT_GET_PRIVATE (client)->manager, object_path); + return _dbobjs_get_nmobj_unpack_visible (client, object_path, NM_TYPE_DEVICE); } /** @@ -984,13 +4613,21 @@ nm_client_get_device_by_path (NMClient *client, const char *object_path) NMDevice * nm_client_get_device_by_iface (NMClient *client, const char *iface) { + const GPtrArray *devices; + guint i; + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); g_return_val_if_fail (iface, NULL); - if (!nm_client_get_nm_running (client)) - return NULL; + devices = nm_client_get_devices (client); + for (i = 0; i < devices->len; i++) { + NMDevice *candidate = g_ptr_array_index (devices, i); - return nm_manager_get_device_by_iface (NM_CLIENT_GET_PRIVATE (client)->manager, iface); + if (nm_streq0 (nm_device_get_iface (candidate), iface)) + return candidate; + } + + return NULL; } /*****************************************************************************/ @@ -1012,10 +4649,7 @@ nm_client_get_active_connections (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - if (!nm_client_get_nm_running (client)) - return ∅ - - return nm_manager_get_active_connections (NM_CLIENT_GET_PRIVATE (client)->manager); + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_CLIENT_GET_PRIVATE (client)->nm.property_ao[PROPERTY_AO_IDX_ACTIVE_CONNECTIONS]); } /** @@ -1042,10 +4676,7 @@ nm_client_get_primary_connection (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - if (!nm_client_get_nm_running (client)) - return NULL; - - return nm_manager_get_primary_connection (NM_CLIENT_GET_PRIVATE (client)->manager); + return nml_dbus_property_o_get_obj (&NM_CLIENT_GET_PRIVATE (client)->nm.property_o[PROPERTY_O_IDX_NM_PRIMAY_CONNECTION]); } /** @@ -1064,29 +4695,36 @@ nm_client_get_activating_connection (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - if (!nm_client_get_nm_running (client)) - return NULL; - - return nm_manager_get_activating_connection (NM_CLIENT_GET_PRIVATE (client)->manager); + return nml_dbus_property_o_get_obj (&NM_CLIENT_GET_PRIVATE (client)->nm.property_o[PROPERTY_O_IDX_NM_ACTIVATING_CONNECTION]); } +/*****************************************************************************/ + static void -activate_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) +activate_connection_cb (GObject *object, + GAsyncResult *result, + gpointer user_data) { - GSimpleAsyncResult *simple = user_data; - NMActiveConnection *ac; + gs_unref_object GTask *task = user_data; + gs_unref_variant GVariant *ret = NULL; + const char *v_active_connection; GError *error = NULL; - ac = nm_manager_activate_connection_finish (NM_MANAGER (object), result, &error); - if (ac) - g_simple_async_result_set_op_res_gpointer (simple, ac, g_object_unref); - else - g_simple_async_result_take_error (simple, error); + ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (object), result, &error); + if (!ret) { + if (!nm_utils_error_is_cancelled (error, FALSE)) + g_dbus_error_strip_remote_error (error); + g_task_return_error (task, error); + return; + } + + g_variant_get (ret, "(&o)", &v_active_connection); - g_simple_async_result_complete (simple); - g_object_unref (simple); + _request_wait_start (g_steal_pointer (&task), + "ActivateConnection", + NM_TYPE_ACTIVE_CONNECTION, + v_active_connection, + NULL); } /** @@ -1131,27 +4769,45 @@ nm_client_activate_connection_async (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; + const char *arg_connection = NULL; + const char *arg_device = NULL; g_return_if_fail (NM_IS_CLIENT (client)); - if (device) - g_return_if_fail (NM_IS_DEVICE (device)); - if (connection) + + if (connection) { g_return_if_fail (NM_IS_CONNECTION (connection)); + arg_connection = nm_connection_get_path (connection); + g_return_if_fail (arg_connection); + } - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; + if (device) { + g_return_if_fail (NM_IS_DEVICE (device)); + arg_device = nm_object_get_path (NM_OBJECT (device)); + g_return_if_fail (arg_device); } - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_activate_connection_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nm_manager_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager, - connection, device, specific_object, - cancellable, activate_cb, simple); + NML_NMCLIENT_LOG_T (client, "ActivateConnection() for connection \"%s\", device \"%s\", specific_object \"%s", + arg_connection ?: "/", + arg_device ?: "/", + specific_object ?: "/"); + + _nm_client_dbus_call (client, + client, + nm_client_activate_connection_async, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "ActivateConnection", + g_variant_new ("(ooo)", + arg_connection ?: "/", + arg_device ?: "/", + specific_object ?: "/"), + G_VARIANT_TYPE ("(o)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + activate_connection_cb); } /** @@ -1170,37 +4826,153 @@ nm_client_activate_connection_finish (NMClient *client, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; + return NM_ACTIVE_CONNECTION (_request_wait_finish (client, + result, + nm_client_activate_connection_async, + NULL, + error)); +} - g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); +/*****************************************************************************/ - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return NULL; - else - return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); +static void +_add_and_activate_connection_done (GObject *object, + GAsyncResult *result, + gboolean use_add_and_activate_v2, + GTask *task_take) +{ + _nm_unused gs_unref_object GTask *task = task_take; + gs_unref_variant GVariant *ret = NULL; + GError *error = NULL; + gs_unref_variant GVariant *v_result = NULL; + const char *v_active_connection; + const char *v_path; + + ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (object), result, &error); + if (!ret) { + if (!nm_utils_error_is_cancelled (error, FALSE)) + g_dbus_error_strip_remote_error (error); + g_task_return_error (task, error); + return; + } + + if (use_add_and_activate_v2) { + g_variant_get (ret, + "(&o&o@a{sv})", + &v_path, + &v_active_connection, + &v_result); + } else { + g_variant_get (ret, + "(&o&o)", + &v_path, + &v_active_connection); + } + + _request_wait_start (g_steal_pointer (&task), + "AddAndActivateConnection", + NM_TYPE_ACTIVE_CONNECTION, + v_active_connection, + g_steal_pointer (&v_result)); } static void -add_activate_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) +_add_and_activate_connection_v1_cb (GObject *object, GAsyncResult *result, gpointer user_data) { - gs_unref_object GSimpleAsyncResult *simple = user_data; - gs_unref_variant GVariant *result_data = NULL; - gs_unref_object NMActiveConnection *ac = NULL; - GError *error = NULL; + _add_and_activate_connection_done (object, result, FALSE, user_data); +} - ac = nm_manager_add_and_activate_connection_finish (NM_MANAGER (object), result, &result_data, &error); - if (ac) { - g_simple_async_result_set_op_res_gpointer (simple, - _nm_activate_result_new (ac, result_data), - (GDestroyNotify) _nm_activate_result_free); - } else - g_simple_async_result_take_error (simple, error); +static void +_add_and_activate_connection_v2_cb (GObject *object, GAsyncResult *result, gpointer user_data) +{ + _add_and_activate_connection_done (object, result, TRUE, user_data); +} - g_simple_async_result_complete (simple); +static void +_add_and_activate_connection (NMClient *self, + gboolean is_v2, + NMConnection *partial, + NMDevice *device, + const char *specific_object, + GVariant *options, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GVariant *arg_connection = NULL; + gboolean use_add_and_activate_v2 = FALSE; + const char *arg_device = NULL; + gpointer source_tag; + + g_return_if_fail (NM_IS_CLIENT (self)); + g_return_if_fail (!partial || NM_IS_CONNECTION (partial)); + + if (device) { + g_return_if_fail (NM_IS_DEVICE (device)); + arg_device = nm_object_get_path (NM_OBJECT (device)); + g_return_if_fail (arg_device); + } + + if (partial) + arg_connection = nm_connection_to_dbus (partial, NM_CONNECTION_SERIALIZE_ALL); + if (!arg_connection) + arg_connection = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0); + + if (is_v2) { + if (!options) + options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); + use_add_and_activate_v2 = TRUE; + source_tag = nm_client_add_and_activate_connection2; + } else { + if (options) { + if (g_variant_n_children (options) > 0) + use_add_and_activate_v2 = TRUE; + else + nm_clear_pointer (&options, nm_g_variant_unref_floating); + } + source_tag = nm_client_add_and_activate_connection_async; + } + + NML_NMCLIENT_LOG_D (self, "AddAndActivateConnection() started..."); + + if (use_add_and_activate_v2) { + _nm_client_dbus_call (self, + self, + source_tag, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "AddAndActivateConnection2", + g_variant_new ("(@a{sa{sv}}oo@a{sv})", + arg_connection, + arg_device ?: "/", + specific_object ?: "/", + options), + G_VARIANT_TYPE ("(ooa{sv})"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + _add_and_activate_connection_v2_cb); + } else { + _nm_client_dbus_call (self, + self, + source_tag, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "AddAndActivateConnection", + g_variant_new ("(@a{sa{sv}}oo)", + arg_connection, + arg_device ?: "/", + specific_object ?: "/"), + G_VARIANT_TYPE ("(oo)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + _add_and_activate_connection_v1_cb); + } } /** @@ -1217,6 +4989,7 @@ add_activate_cb (GObject *object, * path of a #NMAccessPoint or #NMWimaxNsp owned by @device, which you can * get using nm_object_get_path(), and which will be used to complete the * details of the newly added connection. + * If the variant is floating, it will be consumed. * @cancellable: a #GCancellable, or %NULL * @callback: callback to be called when the activation has started * @user_data: caller-specific data passed to @callback @@ -1241,32 +5014,15 @@ nm_client_add_and_activate_connection_async (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; - - g_return_if_fail (NM_IS_CLIENT (client)); - g_return_if_fail (NM_IS_DEVICE (device)); - if (partial) - g_return_if_fail (NM_IS_CONNECTION (partial)); - - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; - } - - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_add_and_activate_connection_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nm_manager_add_and_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager, - partial, - device, - specific_object, - NULL, - FALSE, - cancellable, - add_activate_cb, - simple); + _add_and_activate_connection (client, + FALSE, + partial, + device, + specific_object, + NULL, + cancellable, + callback, + user_data); } /** @@ -1288,17 +5044,11 @@ nm_client_add_and_activate_connection_finish (NMClient *client, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - _NMActivateResult *r; - - g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return NULL; - r = g_simple_async_result_get_op_res_gpointer (simple); - return g_object_ref (r->active); + return NM_ACTIVE_CONNECTION (_request_wait_finish (client, + result, + nm_client_add_and_activate_connection_async, + NULL, + error)); } /** @@ -1354,32 +5104,15 @@ nm_client_add_and_activate_connection2 (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; - - g_return_if_fail (NM_IS_CLIENT (client)); - g_return_if_fail (NM_IS_DEVICE (device)); - if (partial) - g_return_if_fail (NM_IS_CONNECTION (partial)); - - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; - } - - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_add_and_activate_connection2); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nm_manager_add_and_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager, - partial, - device, - specific_object, - options, - TRUE, - cancellable, - add_activate_cb, - simple); + _add_and_activate_connection (client, + TRUE, + partial, + device, + specific_object, + options, + cancellable, + callback, + user_data); } /** @@ -1405,22 +5138,15 @@ nm_client_add_and_activate_connection2_finish (NMClient *client, GVariant **out_result, GError **error) { - GSimpleAsyncResult *simple; - _NMActivateResult *r; - - g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) { - NM_SET_OUT (out_result, NULL); - return NULL; - } - r = g_simple_async_result_get_op_res_gpointer (simple); - NM_SET_OUT (out_result, nm_g_variant_ref (r->add_and_activate_output)); - return g_object_ref (r->active); + return NM_ACTIVE_CONNECTION (_request_wait_finish (client, + result, + nm_client_add_connection2, + out_result, + error)); } +/*****************************************************************************/ + /** * nm_client_deactivate_connection: * @client: a #NMClient @@ -1431,6 +5157,8 @@ nm_client_add_and_activate_connection2_finish (NMClient *client, * Deactivates an active #NMActiveConnection. * * Returns: success or failure + * + * Deprecated: 1.22, use nm_client_deactivate_connection_async() or GDBusConnection **/ gboolean nm_client_deactivate_connection (NMClient *client, @@ -1438,30 +5166,24 @@ nm_client_deactivate_connection (NMClient *client, GCancellable *cancellable, GError **error) { + const char *active_path; + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (active), FALSE); - if (!nm_client_get_nm_running (client)) - return TRUE; - - return nm_manager_deactivate_connection (NM_CLIENT_GET_PRIVATE (client)->manager, - active, cancellable, error); -} - -static void -deactivated_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nm_manager_deactivate_connection_finish (NM_MANAGER (object), result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else - g_simple_async_result_take_error (simple, error); - g_simple_async_result_complete (simple); - g_object_unref (simple); + active_path = nm_object_get_path (NM_OBJECT (active)); + g_return_val_if_fail (active_path, FALSE); + + return _nm_client_dbus_call_sync_void (client, + cancellable, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "DeactivateConnection", + g_variant_new ("(o)", active_path), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); } /** @@ -1481,26 +5203,28 @@ nm_client_deactivate_connection_async (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; + const char *active_path; g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (NM_IS_ACTIVE_CONNECTION (active)); - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_deactivate_connection_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - if (!_nm_client_check_nm_running (client, NULL)) { - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); - return; - } - - nm_manager_deactivate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager, - active, - cancellable, deactivated_cb, simple); + active_path = nm_object_get_path (NM_OBJECT (active)); + g_return_if_fail (active_path); + + _nm_client_dbus_call (client, + client, + nm_client_deactivate_connection_async, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "DeactivateConnection", + g_variant_new ("(o)", active_path), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_strip_dbus_error_cb); } /** @@ -1518,16 +5242,10 @@ nm_client_deactivate_connection_finish (NMClient *client, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, client, nm_client_deactivate_connection_async), FALSE); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); + return g_task_propagate_boolean (G_TASK (result), error); } /*****************************************************************************/ @@ -1550,10 +5268,7 @@ nm_client_get_connections (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - if (!nm_client_get_nm_running (client)) - return ∅ - - return nm_remote_settings_get_connections (NM_CLIENT_GET_PRIVATE (client)->settings); + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_CLIENT_GET_PRIVATE (client)->settings.connections); } /** @@ -1572,13 +5287,20 @@ nm_client_get_connections (NMClient *client) NMRemoteConnection * nm_client_get_connection_by_id (NMClient *client, const char *id) { + const GPtrArray *arr; + guint i; + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - g_return_val_if_fail (id != NULL, NULL); + g_return_val_if_fail (id, NULL); - if (!nm_client_get_nm_running (client)) - return NULL; + arr = nm_client_get_connections (client); + for (i = 0; i < arr->len; i++) { + NMRemoteConnection *c = NM_REMOTE_CONNECTION (arr->pdata[i]); - return nm_remote_settings_get_connection_by_id (NM_CLIENT_GET_PRIVATE (client)->settings, id); + if (nm_streq0 (id, nm_connection_get_id (NM_CONNECTION (c)))) + return c; + } + return NULL; } /** @@ -1600,10 +5322,7 @@ nm_client_get_connection_by_path (NMClient *client, const char *path) g_return_val_if_fail (NM_IS_CLIENT (client), NULL); g_return_val_if_fail (path != NULL, NULL); - if (!nm_client_get_nm_running (client)) - return NULL; - - return nm_remote_settings_get_connection_by_path (NM_CLIENT_GET_PRIVATE (client)->settings, path); + return _dbobjs_get_nmobj_unpack_visible (client, path, NM_TYPE_REMOTE_CONNECTION); } /** @@ -1622,64 +5341,150 @@ nm_client_get_connection_by_path (NMClient *client, const char *path) NMRemoteConnection * nm_client_get_connection_by_uuid (NMClient *client, const char *uuid) { + const GPtrArray *arr; + guint i; + g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - g_return_val_if_fail (uuid != NULL, NULL); + g_return_val_if_fail (uuid, NULL); - if (!nm_client_get_nm_running (client)) - return NULL; + arr = nm_client_get_connections (client); + for (i = 0; i < arr->len; i++) { + NMRemoteConnection *c = NM_REMOTE_CONNECTION (arr->pdata[i]); - return nm_remote_settings_get_connection_by_uuid (NM_CLIENT_GET_PRIVATE (client)->settings, uuid); + if (nm_streq0 (uuid, nm_connection_get_uuid (NM_CONNECTION (c)))) + return c; + } + return NULL; } -typedef struct { - NMRemoteConnection *connection; - GVariant *results; -} AddConnection2CbData; +/*****************************************************************************/ static void -add_connection2_cb_data_destroy (gpointer user_data) +_add_connection_cb (GObject *source, + GAsyncResult *result, + gboolean with_extra_arg, + gpointer user_data) { - AddConnection2CbData *data = user_data; + gs_unref_variant GVariant *ret = NULL; + gs_unref_object GTask *task = user_data; + gs_unref_variant GVariant *v_result = NULL; + const char *v_path; + GError *error = NULL; + + ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error); + if (!ret) { + if (!nm_utils_error_is_cancelled (error, FALSE)) + g_dbus_error_strip_remote_error (error); + g_task_return_error (task, error); + return; + } + + if (with_extra_arg) { + g_variant_get (ret, + "(&o@a{sv})", + &v_path, + &v_result); + } else { + g_variant_get (ret, + "(&o)", + &v_path); + } - g_object_unref (data->connection); - nm_g_variant_unref (data->results); - nm_g_slice_free (data); + _request_wait_start (g_steal_pointer (&task), + "AddConnection", + NM_TYPE_REMOTE_CONNECTION, + v_path, + g_steal_pointer (&v_result)); } static void -add_connection2_cb (NMRemoteSettings *self, - NMRemoteConnection *connection, - GVariant *results, - GError *error, - gpointer user_data) +_add_connection_cb_without_extra_result (GObject *object, GAsyncResult *result, gpointer user_data) { - gs_unref_object GSimpleAsyncResult *simple = user_data; - - if (error) { - g_simple_async_result_take_error (simple, - g_error_new_literal (error->domain, - error->code, - error->message)); - } else if (g_simple_async_result_get_source_tag (simple) == nm_client_add_connection_async) { - g_simple_async_result_set_op_res_gpointer (simple, - g_object_ref (connection), - g_object_unref); - } else { - AddConnection2CbData *data; + _add_connection_cb (object, result, FALSE, user_data); +} - nm_assert (g_simple_async_result_get_source_tag (simple) == nm_client_add_connection2); +static void +_add_connection_cb_with_extra_result (GObject *object, GAsyncResult *result, gpointer user_data) +{ + _add_connection_cb (object, result, TRUE, user_data); +} - data = g_slice_new (AddConnection2CbData); - *data = (AddConnection2CbData) { - .connection = g_object_ref (connection), - .results = nm_g_variant_ref (results), - }; - g_simple_async_result_set_op_res_gpointer (simple, - data, - add_connection2_cb_data_destroy); - } +static void +_add_connection_call (NMClient *self, + gpointer source_tag, + gboolean ignore_out_result, + GVariant *settings, + NMSettingsAddConnection2Flags flags, + GVariant *args, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_return_if_fail (NM_IS_CLIENT (self)); + g_return_if_fail (!settings || g_variant_is_of_type (settings, G_VARIANT_TYPE ("a{sa{sv}}"))); + g_return_if_fail (!args || g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}"))); - g_simple_async_result_complete (simple); + NML_NMCLIENT_LOG_D (self, "AddConnection() started..."); + + if (!settings) + settings = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0); + + /* Although AddConnection2() being capable to handle also AddConnection() and + * AddConnectionUnsaved() variants, we prefer to use the old D-Bus methods when + * they are sufficient. The reason is that libnm should avoid hard dependencies + * on 1.20 API whenever possible. */ + if ( ignore_out_result + && flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK) { + _nm_client_dbus_call (self, + self, + source_tag, + cancellable, + callback, + user_data, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + "AddConnection", + g_variant_new ("(@a{sa{sv}})", settings), + G_VARIANT_TYPE ("(o)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + _add_connection_cb_without_extra_result); + } else if ( ignore_out_result + && flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY) { + _nm_client_dbus_call (self, + self, + source_tag, + cancellable, + callback, + user_data, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + "AddConnectionUnsaved", + g_variant_new ("(@a{sa{sv}})", settings), + G_VARIANT_TYPE ("(o)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + _add_connection_cb_without_extra_result); + } else { + _nm_client_dbus_call (self, + self, + source_tag, + cancellable, + callback, + user_data, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + "AddConnection2", + g_variant_new ("(@a{sa{sv}}u@a{sv})", + settings, + (guint32) flags, + args + ?: g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0)), + G_VARIANT_TYPE ("(oa{sv})"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + _add_connection_cb_with_extra_result); + } } /** @@ -1715,32 +5520,19 @@ nm_client_add_connection_async (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; - - g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (NM_IS_CONNECTION (connection)); - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; - } - - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_add_connection_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nm_remote_settings_add_connection2 (NM_CLIENT_GET_PRIVATE (client)->settings, - nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL), - save_to_disk - ? NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK - : NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY, - NULL, - TRUE, - cancellable, - add_connection2_cb, - simple); + _add_connection_call (client, + nm_client_add_connection_async, + TRUE, + nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL), + save_to_disk + ? NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK + : NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY, + NULL, + cancellable, + callback, + user_data); } /** @@ -1759,15 +5551,11 @@ nm_client_add_connection_finish (NMClient *client, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - - g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_add_connection_async), NULL); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return NULL; - return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); + return NM_REMOTE_CONNECTION (_request_wait_finish (client, + result, + nm_client_add_connection_async, + NULL, + error)); } /** @@ -1802,33 +5590,15 @@ nm_client_add_connection2 (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; - - g_return_if_fail (NM_IS_CLIENT (client)); - g_return_if_fail (g_variant_is_of_type (settings, G_VARIANT_TYPE ("a{sa{sv}}"))); - g_return_if_fail (!args || g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}"))); - - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; - } - - simple = g_simple_async_result_new (G_OBJECT (client), - callback, - user_data, - nm_client_add_connection2); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nm_remote_settings_add_connection2 (NM_CLIENT_GET_PRIVATE (client)->settings, - settings, - flags, - args, - ignore_out_result, - cancellable, - add_connection2_cb, - simple); + _add_connection_call (client, + nm_client_add_connection2, + ignore_out_result, + settings, + flags, + args, + cancellable, + callback, + user_data); } /** @@ -1852,23 +5622,15 @@ nm_client_add_connection2_finish (NMClient *client, GVariant **out_result, GError **error) { - GSimpleAsyncResult *simple; - AddConnection2CbData *data; - - g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_add_connection2), NULL); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) { - NM_SET_OUT (out_result, NULL); - return NULL; - } - - data = g_simple_async_result_get_op_res_gpointer (simple); - NM_SET_OUT (out_result, g_variant_ref (data->results)); - return g_object_ref (data->connection); + return NM_REMOTE_CONNECTION (_request_wait_finish (client, + result, + nm_client_add_connection2, + out_result, + error)); } +/*****************************************************************************/ + /** * nm_client_load_connections: * @client: the %NMClient @@ -1890,8 +5652,18 @@ nm_client_add_connection2_finish (NMClient *client, * then @failures will be set to a %NULL-terminated array of the * filenames that failed to load. * - * Returns: %TRUE if NetworkManager at least tried to load @filenames, - * %FALSE if an error occurred (eg, permission denied). + * Returns: %TRUE on success. + * + * Warning: before libnm 1.22, the boolean return value was inconsistent. + * That is made worse, because when running against certain server versions + * before 1.20, the server would return wrong values for success/failure. + * This means, if you use this function in libnm before 1.22, you are advised + * to ignore the boolean return value and only look at @failures and @error. + * With libnm >= 1.22, the boolean return value corresponds to whether @error was + * set. Note that even in the success case, you might have individual @failures. + * With 1.22, the return value is consistent with nm_client_load_connections_finish(). + * + * Deprecated: 1.22, use nm_client_load_connections_async() or GDBusConnection **/ gboolean nm_client_load_connections (NMClient *client, @@ -1900,32 +5672,34 @@ nm_client_load_connections (NMClient *client, GCancellable *cancellable, GError **error) { - g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - g_return_val_if_fail (filenames != NULL, FALSE); + gs_unref_variant GVariant *ret = NULL; - if (!_nm_client_check_nm_running (client, error)) + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); + + ret = _nm_client_dbus_call_sync (client, + cancellable, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + "LoadConnections", + g_variant_new ("(^as)", + filenames ?: NM_PTRARRAY_EMPTY (char *)), + G_VARIANT_TYPE ("(bas)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); + if (!ret) { + *failures = NULL; return FALSE; + } - return nm_remote_settings_load_connections (NM_CLIENT_GET_PRIVATE (client)->settings, - filenames, failures, - cancellable, error); -} - -static void -load_connections_cb (GObject *object, GAsyncResult *result, gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - char **failures = NULL; - - if (nm_remote_settings_load_connections_finish (NM_REMOTE_SETTINGS (object), - &failures, result, &error)) - g_simple_async_result_set_op_res_gpointer (simple, failures, (GDestroyNotify) g_strfreev); - else - g_simple_async_result_take_error (simple, error); + g_variant_get (ret, + "(b^as)", + NULL, + &failures); - g_simple_async_result_complete (simple); - g_object_unref (simple); + return TRUE; } /** @@ -1948,24 +5722,24 @@ nm_client_load_connections_async (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; - g_return_if_fail (NM_IS_CLIENT (client)); - g_return_if_fail (filenames != NULL); - - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; - } - - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_load_connections_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nm_remote_settings_load_connections_async (NM_CLIENT_GET_PRIVATE (client)->settings, - filenames, - cancellable, load_connections_cb, simple); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); + + _nm_client_dbus_call (client, + client, + nm_client_load_connections_async, + cancellable, + callback, + user_data, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + "LoadConnections", + g_variant_new ("(^as)", + filenames ?: NM_PTRARRAY_EMPTY (char *)), + G_VARIANT_TYPE ("(bas)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_variant_strip_dbus_error_cb); } /** @@ -1980,8 +5754,8 @@ nm_client_load_connections_async (NMClient *client, * See nm_client_load_connections() for more details. * - * Returns: %TRUE if NetworkManager at least tried to load @filenames, - * %FALSE if an error occurred (eg, permission denied). + * Returns: %TRUE on success. + * Note that even in the success case, you might have individual @failures. **/ gboolean nm_client_load_connections_finish (NMClient *client, @@ -1989,19 +5763,23 @@ nm_client_load_connections_finish (NMClient *client, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; + gs_unref_variant GVariant *ret = NULL; g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, client, nm_client_load_connections_async), FALSE); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) + ret = g_task_propagate_pointer (G_TASK (result), error); + if (!ret) { + *failures = NULL; return FALSE; - else { - if (failures) - *failures = g_strdupv (g_simple_async_result_get_op_res_gpointer (simple)); - return TRUE; } + + g_variant_get (ret, + "(b^as)", + NULL, + &failures); + + return TRUE; } /** @@ -2015,35 +5793,34 @@ nm_client_load_connections_finish (NMClient *client, * the in-memory state matches the on-disk state. * * Return value: %TRUE on success, %FALSE on failure + * + * Deprecated: 1.22, use nm_client_reload_connections_async() or GDBusConnection **/ gboolean nm_client_reload_connections (NMClient *client, GCancellable *cancellable, GError **error) { - g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + gs_unref_variant GVariant *ret = NULL; - if (!_nm_client_check_nm_running (client, error)) + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); + + ret = _nm_client_dbus_call_sync (client, + cancellable, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + "ReloadConnections", + g_variant_new ("()"), + G_VARIANT_TYPE ("(b)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); + if (!ret) return FALSE; - return nm_remote_settings_reload_connections (NM_CLIENT_GET_PRIVATE (client)->settings, - cancellable, error); -} - -static void -reload_connections_cb (GObject *object, GAsyncResult *result, gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nm_remote_settings_reload_connections_finish (NM_REMOTE_SETTINGS (object), - result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else - g_simple_async_result_take_error (simple, error); - - g_simple_async_result_complete (simple); - g_object_unref (simple); + return TRUE; } /** @@ -2063,22 +5840,23 @@ nm_client_reload_connections_async (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; - g_return_if_fail (NM_IS_CLIENT (client)); - - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; - } - - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_reload_connections_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nm_remote_settings_reload_connections_async (NM_CLIENT_GET_PRIVATE (client)->settings, - cancellable, reload_connections_cb, simple); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); + + _nm_client_dbus_call (client, + client, + nm_client_reload_connections_async, + cancellable, + callback, + user_data, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_INTERFACE_SETTINGS, + "ReloadConnections", + g_variant_new ("()"), + G_VARIANT_TYPE ("(b)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_variant_strip_dbus_error_cb); } /** @@ -2096,16 +5874,16 @@ nm_client_reload_connections_finish (NMClient *client, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; + gs_unref_variant GVariant *ret = NULL; g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, client, nm_client_reload_connections_async), FALSE); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) + ret = g_task_propagate_pointer (G_TASK (result), error); + if (!ret) return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); + + return TRUE; } /*****************************************************************************/ @@ -2124,15 +5902,9 @@ nm_client_reload_connections_finish (NMClient *client, const char * nm_client_get_dns_mode (NMClient *client) { - NMClientPrivate *priv; - g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - priv = NM_CLIENT_GET_PRIVATE (client); - if (priv->dns_manager) - return nm_dns_manager_get_mode (priv->dns_manager); - else - return NULL; + return NM_CLIENT_GET_PRIVATE (client)->dns_manager.mode; } /** @@ -2149,15 +5921,9 @@ nm_client_get_dns_mode (NMClient *client) const char * nm_client_get_dns_rc_manager (NMClient *client) { - NMClientPrivate *priv; - g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - priv = NM_CLIENT_GET_PRIVATE (client); - if (priv->dns_manager) - return nm_dns_manager_get_rc_manager (priv->dns_manager); - else - return NULL; + return NM_CLIENT_GET_PRIVATE (client)->dns_manager.rc_manager; } /** @@ -2176,221 +5942,89 @@ nm_client_get_dns_rc_manager (NMClient *client) const GPtrArray * nm_client_get_dns_configuration (NMClient *client) { - NMClientPrivate *priv; - g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - priv = NM_CLIENT_GET_PRIVATE (client); - - if (priv->dns_manager) - return nm_dns_manager_get_configuration (priv->dns_manager); - else - return NULL; -} - -/*****************************************************************************/ - -/** - * nm_client_new: - * @cancellable: a #GCancellable, or %NULL - * @error: location for a #GError, or %NULL - * - * Creates a new #NMClient. - * - * Note that this will do blocking D-Bus calls to initialize the - * client. You can use nm_client_new_async() if you want to avoid - * that. - * - * Returns: a new #NMClient or NULL on an error - **/ -NMClient * -nm_client_new (GCancellable *cancellable, - GError **error) -{ - return g_initable_new (NM_TYPE_CLIENT, cancellable, error, - NULL); -} - -static void -client_inited (GObject *source, GAsyncResult *result, gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (!g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, &error)) - g_simple_async_result_take_error (simple, error); - else - g_simple_async_result_set_op_res_gpointer (simple, source, g_object_unref); - g_simple_async_result_complete (simple); - g_object_unref (simple); -} - -/** - * nm_client_new_async: - * @cancellable: a #GCancellable, or %NULL - * @callback: callback to call when the client is created - * @user_data: data for @callback - * - * Creates a new #NMClient and begins asynchronously initializing it. - * @callback will be called when it is done; use - * nm_client_new_finish() to get the result. Note that on an error, - * the callback can be invoked with two first parameters as NULL. - **/ -void -nm_client_new_async (GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - - simple = g_simple_async_result_new (NULL, callback, user_data, nm_client_new_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - g_async_initable_new_async (NM_TYPE_CLIENT, G_PRIORITY_DEFAULT, - cancellable, client_inited, simple, - NULL); -} - -/** - * nm_client_new_finish: - * @result: a #GAsyncResult - * @error: location for a #GError, or %NULL - * - * Gets the result of an nm_client_new_async() call. - * - * Returns: a new #NMClient, or %NULL on error - **/ -NMClient * -nm_client_new_finish (GAsyncResult *result, GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL, nm_client_new_async), NULL); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return NULL; - else - return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); -} - -static void -subobject_notify (GObject *object, - GParamSpec *pspec, - gpointer client) -{ - if (!g_str_has_suffix (pspec->name, "-internal")) - g_object_notify (client, pspec->name); -} -static void -manager_device_added (NMManager *manager, - NMDevice *device, - gpointer client) -{ - g_signal_emit (client, signals[DEVICE_ADDED], 0, device); + return NM_CLIENT_GET_PRIVATE (client)->dns_manager.configuration; } -static void -manager_device_removed (NMManager *manager, - NMDevice *device, - gpointer client) +static NMLDBusNotifyUpdatePropFlags +_notify_update_prop_dns_manager_configuration (NMClient *self, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) { - g_signal_emit (client, signals[DEVICE_REMOVED], 0, device); -} - -static void -manager_any_device_added (NMManager *manager, - NMDevice *device, - gpointer client) -{ - g_signal_emit (client, signals[ANY_DEVICE_ADDED], 0, device); -} - -static void -manager_any_device_removed (NMManager *manager, - NMDevice *device, - gpointer client) -{ - g_signal_emit (client, signals[ANY_DEVICE_REMOVED], 0, device); -} - -static void -manager_permission_changed (NMManager *manager, - NMClientPermission permission, - NMClientPermissionResult result, - gpointer client) -{ - g_signal_emit (client, signals[PERMISSION_CHANGED], 0, permission, result); -} - -static void -settings_connection_added (NMRemoteSettings *manager, - NMRemoteConnection *connection, - gpointer client) -{ - g_signal_emit (client, signals[CONNECTION_ADDED], 0, connection); -} -static void -settings_connection_removed (NMRemoteSettings *manager, - NMRemoteConnection *connection, - gpointer client) -{ - g_signal_emit (client, signals[CONNECTION_REMOVED], 0, connection); -} + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + gs_unref_ptrarray GPtrArray *configuration_old = NULL; + gs_unref_ptrarray GPtrArray *configuration_new = NULL; + + nm_assert (G_OBJECT (self) == dbobj->nmobj); + + if (value) { + GVariant *entry_var_tmp; + GVariantIter iter; + GPtrArray *array; + + configuration_new = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_dns_entry_unref); + + g_variant_iter_init (&iter, value); + while (g_variant_iter_next (&iter, "@a{sv}", &entry_var_tmp)) { + gs_unref_variant GVariant *entry_var = entry_var_tmp; + nm_auto_free_variant_iter GVariantIter *iterp_nameservers = NULL; + nm_auto_free_variant_iter GVariantIter *iterp_domains = NULL; + gs_free char **nameservers = NULL; + gs_free char **domains = NULL; + gboolean vpn = FALSE; + NMDnsEntry *entry; + char *interface = NULL; + char *str; + gint32 priority = 0; + + if ( !g_variant_lookup (entry_var, "nameservers", "as", &iterp_nameservers) + || !g_variant_lookup (entry_var, "priority", "i", &priority)) { + g_warning ("Ignoring invalid DNS configuration"); + continue; + } -static void -manager_active_connection_added (NMManager *manager, - NMActiveConnection *active_connection, - gpointer client) -{ - g_signal_emit (client, signals[ACTIVE_CONNECTION_ADDED], 0, active_connection); -} + array = g_ptr_array_new (); + while (g_variant_iter_next (iterp_nameservers, "&s", &str)) + g_ptr_array_add (array, str); + g_ptr_array_add (array, NULL); + nameservers = (char **) g_ptr_array_free (array, FALSE); + + if (g_variant_lookup (entry_var, "domains", "as", &iterp_domains)) { + array = g_ptr_array_new (); + while (g_variant_iter_next (iterp_domains, "&s", &str)) + g_ptr_array_add (array, str); + g_ptr_array_add (array, NULL); + domains = (char **) g_ptr_array_free (array, FALSE); + } -static void -manager_active_connection_removed (NMManager *manager, - NMActiveConnection *active_connection, - gpointer client) -{ - g_signal_emit (client, signals[ACTIVE_CONNECTION_REMOVED], 0, active_connection); -} + g_variant_lookup (entry_var, "interface", "&s", &interface); + g_variant_lookup (entry_var, "vpn", "b", &vpn); -static void -dns_notify (GObject *object, - GParamSpec *pspec, - gpointer client) -{ - char pname[128]; + entry = nm_dns_entry_new (interface, + (const char *const*) nameservers, + (const char *const*) domains, + priority, + vpn); + if (!entry) { + g_warning ("Ignoring invalid DNS entry"); + continue; + } - if (NM_IN_STRSET (pspec->name, - NM_DNS_MANAGER_MODE, - NM_DNS_MANAGER_RC_MANAGER, - NM_DNS_MANAGER_CONFIGURATION)) { - nm_sprintf_buf (pname, "dns-%s", pspec->name); - g_object_notify (client, pname); + g_ptr_array_add (configuration_new, entry); + } } -} -static void -checkpoint_create_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - NMCheckpoint *checkpoint; - GError *error = NULL; - - checkpoint = nm_manager_checkpoint_create_finish (NM_MANAGER (object), result, &error); - if (checkpoint) - g_simple_async_result_set_op_res_gpointer (simple, checkpoint, g_object_unref); - else - g_simple_async_result_take_error (simple, error); + configuration_old = priv->dns_manager.configuration; + priv->dns_manager.configuration = g_steal_pointer (&configuration_new); - g_simple_async_result_complete (simple); - g_object_unref (simple); + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY; } +/*****************************************************************************/ + /** * nm_client_get_checkpoints: * @client: a #NMClient @@ -2408,10 +6042,36 @@ nm_client_get_checkpoints (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - if (!nm_client_get_nm_running (client)) - return ∅ + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_CLIENT_GET_PRIVATE (client)->nm.property_ao[PROPERTY_AO_IDX_CHECKPOINTS]); +} - return nm_manager_get_checkpoints (NM_CLIENT_GET_PRIVATE (client)->manager); +static void +checkpoint_create_cb (GObject *object, + GAsyncResult *result, + gpointer user_data) +{ + gs_unref_object GTask *task = user_data; + gs_unref_variant GVariant *ret = NULL; + const char *v_checkpoint_path; + GError *error = NULL; + + ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (object), result, &error); + if (!ret) { + if (!nm_utils_error_is_cancelled (error, FALSE)) + g_dbus_error_strip_remote_error (error); + g_task_return_error (task, error); + return; + } + + g_variant_get (ret, + "(&o)", + &v_checkpoint_path); + + _request_wait_start (g_steal_pointer (&task), + "CheckpointCreate", + NM_TYPE_CHECKPOINT, + v_checkpoint_path, + NULL); } /** @@ -2441,23 +6101,36 @@ nm_client_checkpoint_create (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; + gs_free const char **paths = NULL; + guint i; g_return_if_fail (NM_IS_CLIENT (client)); - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; + if ( devices + && devices->len > 0) { + paths = g_new (const char *, devices->len + 1); + for (i = 0; i < devices->len; i++) + paths[i] = nm_object_get_path (NM_OBJECT (devices->pdata[i])); + paths[i] = NULL; } - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_checkpoint_create); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nm_manager_checkpoint_create (NM_CLIENT_GET_PRIVATE (client)->manager, - devices, rollback_timeout, flags, - cancellable, checkpoint_create_cb, simple); + _nm_client_dbus_call (client, + client, + nm_client_checkpoint_create, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "CheckpointCreate", + g_variant_new ("(^aouu)", + paths ?: NM_PTRARRAY_EMPTY (const char *), + rollback_timeout, + flags), + G_VARIANT_TYPE ("(o)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + checkpoint_create_cb); } /** @@ -2478,33 +6151,11 @@ nm_client_checkpoint_create_finish (NMClient *client, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - - g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return NULL; - else - return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); -} - -static void -checkpoint_destroy_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nm_manager_checkpoint_destroy_finish (NM_MANAGER (object), result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else - g_simple_async_result_take_error (simple, error); - - g_simple_async_result_complete (simple); - g_object_unref (simple); + return NM_CHECKPOINT (_request_wait_finish (client, + result, + nm_client_checkpoint_create, + NULL, + error)); } /** @@ -2526,24 +6177,23 @@ nm_client_checkpoint_destroy (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; - g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (checkpoint_path && checkpoint_path[0] == '/'); - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; - } - - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_checkpoint_destroy); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nm_manager_checkpoint_destroy (NM_CLIENT_GET_PRIVATE (client)->manager, - checkpoint_path, - cancellable, checkpoint_destroy_cb, simple); + _nm_client_dbus_call (client, + client, + nm_client_checkpoint_destroy, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "CheckpointDestroy", + g_variant_new ("(o)", checkpoint_path), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_strip_dbus_error_cb); } /** @@ -2564,35 +6214,10 @@ nm_client_checkpoint_destroy_finish (NMClient *client, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, client, nm_client_checkpoint_destroy), FALSE); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); -} - -static void -checkpoint_rollback_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GHashTable *hash; - GError *error = NULL; - - hash = nm_manager_checkpoint_rollback_finish (NM_MANAGER (object), result, &error); - if (hash) - g_simple_async_result_set_op_res_gpointer (simple, hash, (GDestroyNotify) g_hash_table_unref); - else - g_simple_async_result_take_error (simple, error); - - g_simple_async_result_complete (simple); - g_object_unref (simple); + return g_task_propagate_boolean (G_TASK (result), error); } /** @@ -2614,24 +6239,23 @@ nm_client_checkpoint_rollback (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; - g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (checkpoint_path && checkpoint_path[0] == '/'); - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; - } - - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_checkpoint_rollback); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nm_manager_checkpoint_rollback (NM_CLIENT_GET_PRIVATE (client)->manager, - checkpoint_path, - cancellable, checkpoint_rollback_cb, simple); + _nm_client_dbus_call (client, + client, + nm_client_checkpoint_rollback, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "CheckpointRollback", + g_variant_new ("(o)", checkpoint_path), + G_VARIANT_TYPE ("(a{su})"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_variant_strip_dbus_error_cb); } /** @@ -2653,35 +6277,31 @@ nm_client_checkpoint_rollback_finish (NMClient *client, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; + gs_unref_variant GVariant *ret = NULL; + gs_unref_variant GVariant *v_result = NULL; + GVariantIter iter; GHashTable *hash; + const char *path; + guint32 r; g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); + g_return_val_if_fail (nm_g_task_is_valid (result, client, nm_client_checkpoint_rollback), NULL); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) + ret = g_task_propagate_pointer (G_TASK (result), error); + if (!ret) return NULL; - else { - hash = g_simple_async_result_get_op_res_gpointer (simple); - return g_hash_table_ref (hash); - } -} -static void -checkpoint_adjust_rollback_timeout_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - gs_unref_object GSimpleAsyncResult *simple = user_data; - GError *error = NULL; + g_variant_get (ret, + "(@a{su})", + &v_result); - if (nm_manager_checkpoint_adjust_rollback_timeout_finish (NM_MANAGER (object), result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else - g_simple_async_result_take_error (simple, error); + hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, NULL); - g_simple_async_result_complete (simple); + g_variant_iter_init (&iter, v_result); + while (g_variant_iter_next (&iter, "{&su}", &path, &r)) + g_hash_table_insert (hash, g_strdup (path), GUINT_TO_POINTER (r)); + + return hash; } /** @@ -2707,24 +6327,25 @@ nm_client_checkpoint_adjust_rollback_timeout (NMClient *client, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - GError *error = NULL; - g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (checkpoint_path && checkpoint_path[0] == '/'); - if (!_nm_client_check_nm_running (client, &error)) { - g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); - return; - } - - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, - nm_client_checkpoint_rollback); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nm_manager_checkpoint_adjust_rollback_timeout (NM_CLIENT_GET_PRIVATE (client)->manager, - checkpoint_path, add_timeout, - cancellable, checkpoint_adjust_rollback_timeout_cb, simple); + _nm_client_dbus_call (client, + client, + nm_client_checkpoint_adjust_rollback_timeout, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "CheckpointAdjustRollbackTimeout", + g_variant_new ("(ou)", + checkpoint_path, + add_timeout), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_strip_dbus_error_cb); } /** @@ -2745,654 +6366,559 @@ nm_client_checkpoint_adjust_rollback_timeout_finish (NMClient *client, GError **error) { g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, client, nm_client_checkpoint_adjust_rollback_timeout), FALSE); - return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), - error); + return g_task_propagate_boolean (G_TASK (result), error); } -/****************************************************************/ -/* Object Initialization */ -/****************************************************************/ - -static GType -proxy_type (GDBusObjectManagerClient *manager, - const char *object_path, - const char *interface_name, - gpointer user_data) -{ - /* ObjectManager asks us for an object proxy. Unfortunately, we can't - * decide that by interface name and GDBusObjectManager doesn't allow - * us to look at the known interface list. Thus we need to create a - * generic GDBusObject and only couple a NMObject subclass later. */ - if (!interface_name) - return G_TYPE_DBUS_OBJECT_PROXY; - - /* An interface proxy */ - if (strcmp (interface_name, NM_DBUS_INTERFACE) == 0) - return NMDBUS_TYPE_MANAGER_PROXY; - else if (strcmp (interface_name, NM_DBUS_INTERFACE_DEVICE_WIRELESS) == 0) - return NMDBUS_TYPE_DEVICE_WIFI_PROXY; - else if (strcmp (interface_name, NM_DBUS_INTERFACE_DEVICE_WIFI_P2P) == 0) - return NMDBUS_TYPE_DEVICE_WIFI_P2P_PROXY; - else if (strcmp (interface_name, NM_DBUS_INTERFACE_DEVICE) == 0) - return NMDBUS_TYPE_DEVICE_PROXY; - else if (strcmp (interface_name, NM_DBUS_INTERFACE_SETTINGS_CONNECTION) == 0) - return NMDBUS_TYPE_SETTINGS_CONNECTION_PROXY; - else if (strcmp (interface_name, NM_DBUS_INTERFACE_SETTINGS) == 0) - return NMDBUS_TYPE_SETTINGS_PROXY; - else if (strcmp (interface_name, NM_DBUS_INTERFACE_DNS_MANAGER) == 0) - return NMDBUS_TYPE_DNS_MANAGER_PROXY; - else if (strcmp (interface_name, NM_DBUS_INTERFACE_VPN_CONNECTION) == 0) - return NMDBUS_TYPE_VPN_CONNECTION_PROXY; - else if (strcmp (interface_name, NM_DBUS_INTERFACE_ACTIVE_CONNECTION) == 0) - return NMDBUS_TYPE_ACTIVE_CONNECTION_PROXY; - - /* Use a generic D-Bus Proxy whenever we can. The typed GDBusProxy - * subclasses actually use quite some memory, so they're better avoided. */ - return G_TYPE_DBUS_PROXY; -} - -static NMObject * -obj_nm_for_gdbus_object (NMClient *self, GDBusObject *object, GDBusObjectManager *object_manager) +/** + * nm_client_reload: + * @client: the %NMClient + * @flags: flags indicating what to reload. + * @cancellable: a #GCancellable, or %NULL + * @callback: (scope async): callback to be called when the add operation completes + * @user_data: (closure): caller-specific data passed to @callback + * + * Reload NetworkManager's configuration and perform certain updates, like + * flushing caches or rewriting external state to disk. This is similar to + * sending SIGHUP to NetworkManager but it allows for more fine-grained control + * over what to reload (see @flags). It also allows non-root access via + * PolicyKit and contrary to signals it is synchronous. + * + * Since: 1.22 + **/ +void +nm_client_reload (NMClient *client, + NMManagerReloadFlags flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) { - NMClientPrivate *priv; - GList *interfaces; - GList *l; - GType type = G_TYPE_INVALID; - NMObject *obj_nm; - - g_return_val_if_fail (G_IS_DBUS_OBJECT_PROXY (object), NULL); - - interfaces = g_dbus_object_get_interfaces (object); - for (l = interfaces; l; l = l->next) { - GDBusProxy *proxy = G_DBUS_PROXY (l->data); - const char *ifname = g_dbus_proxy_get_interface_name (proxy); - - /* This is a performance/scalability hack. It makes sense to call it - * from here, since this is in the common object creation path. */ - _nm_dbus_proxy_replace_match (proxy); - - if (strcmp (ifname, NM_DBUS_INTERFACE) == 0) - type = NM_TYPE_MANAGER; - else if (strcmp (ifname, NM_DBUS_INTERFACE_ACCESS_POINT) == 0) - type = NM_TYPE_ACCESS_POINT; - else if (strcmp (ifname, NM_DBUS_INTERFACE_ACTIVE_CONNECTION) == 0 && type != NM_TYPE_VPN_CONNECTION) - type = NM_TYPE_ACTIVE_CONNECTION; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_6LOWPAN) == 0) - type = NM_TYPE_DEVICE_6LOWPAN; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_ADSL) == 0) - type = NM_TYPE_DEVICE_ADSL; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_BOND) == 0) - type = NM_TYPE_DEVICE_BOND; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_BRIDGE) == 0) - type = NM_TYPE_DEVICE_BRIDGE; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_BLUETOOTH) == 0) - type = NM_TYPE_DEVICE_BT; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_DUMMY) == 0) - type = NM_TYPE_DEVICE_DUMMY; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_WIRED) == 0) - type = NM_TYPE_DEVICE_ETHERNET; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_GENERIC) == 0) - type = NM_TYPE_DEVICE_GENERIC; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_INFINIBAND) == 0) - type = NM_TYPE_DEVICE_INFINIBAND; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL) == 0) - type = NM_TYPE_DEVICE_IP_TUNNEL; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_MACSEC) == 0) - type = NM_TYPE_DEVICE_MACSEC; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_MACVLAN) == 0) - type = NM_TYPE_DEVICE_MACVLAN; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_MODEM) == 0) - type = NM_TYPE_DEVICE_MODEM; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_OLPC_MESH) == 0) - type = NM_TYPE_DEVICE_OLPC_MESH; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_OVS_INTERFACE) == 0) - type = NM_TYPE_DEVICE_OVS_INTERFACE; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_OVS_PORT) == 0) - type = NM_TYPE_DEVICE_OVS_PORT; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_OVS_BRIDGE) == 0) - type = NM_TYPE_DEVICE_OVS_BRIDGE; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_WIFI_P2P) == 0) - type = NM_TYPE_DEVICE_WIFI_P2P; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_PPP) == 0) - type = NM_TYPE_DEVICE_PPP; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_TEAM) == 0) - type = NM_TYPE_DEVICE_TEAM; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_TUN) == 0) - type = NM_TYPE_DEVICE_TUN; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_VLAN) == 0) - type = NM_TYPE_DEVICE_VLAN; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_WPAN) == 0) - type = NM_TYPE_DEVICE_WPAN; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_VXLAN) == 0) - type = NM_TYPE_DEVICE_VXLAN; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_WIRELESS) == 0) - type = NM_TYPE_DEVICE_WIFI; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_WIMAX) == 0) - type = NM_TYPE_DEVICE_WIMAX; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DEVICE_WIREGUARD) == 0) - type = NM_TYPE_DEVICE_WIREGUARD; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DHCP4_CONFIG) == 0) - type = NM_TYPE_DHCP4_CONFIG; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DHCP6_CONFIG) == 0) - type = NM_TYPE_DHCP6_CONFIG; - else if (strcmp (ifname, NM_DBUS_INTERFACE_IP4_CONFIG) == 0) - type = NM_TYPE_IP4_CONFIG; - else if (strcmp (ifname, NM_DBUS_INTERFACE_IP6_CONFIG) == 0) - type = NM_TYPE_IP6_CONFIG; - else if (strcmp (ifname, NM_DBUS_INTERFACE_WIFI_P2P_PEER) == 0) - type = NM_TYPE_WIFI_P2P_PEER; - else if (strcmp (ifname, NM_DBUS_INTERFACE_SETTINGS_CONNECTION) == 0) - type = NM_TYPE_REMOTE_CONNECTION; - else if (strcmp (ifname, NM_DBUS_INTERFACE_SETTINGS) == 0) - type = NM_TYPE_REMOTE_SETTINGS; - else if (strcmp (ifname, NM_DBUS_INTERFACE_DNS_MANAGER) == 0) - type = NM_TYPE_DNS_MANAGER; - else if (strcmp (ifname, NM_DBUS_INTERFACE_VPN_CONNECTION) == 0) - type = NM_TYPE_VPN_CONNECTION; - else if (strcmp (ifname, NM_DBUS_INTERFACE_WIMAX_NSP) == 0) - type = NM_TYPE_WIMAX_NSP; - else if (strcmp (ifname, NM_DBUS_INTERFACE_CHECKPOINT) == 0) - type = NM_TYPE_CHECKPOINT; - - if (type != G_TYPE_INVALID) - break; - } - - g_list_free_full (interfaces, g_object_unref); - if (type == G_TYPE_INVALID) - return NULL; + g_return_if_fail (NM_IS_CLIENT (client)); - obj_nm = g_object_new (type, - NM_OBJECT_DBUS_OBJECT, object, - NM_OBJECT_DBUS_OBJECT_MANAGER, object_manager, - NULL); - if (NM_IS_DEVICE (obj_nm)) { - priv = NM_CLIENT_GET_PRIVATE (self); - if (G_UNLIKELY (!priv->udev_inited)) { - priv->udev_inited = TRUE; - /* for testing, we don't want to use udev in libnm. */ - if (!nm_streq0 (g_getenv ("LIBNM_USE_NO_UDEV"), "1")) - priv->udev = udev_new (); - } - if (priv->udev) - _nm_device_set_udev (NM_DEVICE (obj_nm), priv->udev); - } - g_object_set_qdata_full (G_OBJECT (object), _nm_object_obj_nm_quark (), - obj_nm, g_object_unref); - return obj_nm; + _nm_client_dbus_call (client, + client, + nm_client_reload, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "Reload", + g_variant_new ("(u)", (guint32) flags), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_strip_dbus_error_cb); } -static void -obj_nm_inited (GObject *object, GAsyncResult *result, gpointer user_data) +/** + * nm_client_reload_finish: + * @client: an #NMClient + * @result: the result passed to the #GAsyncReadyCallback + * @error: location for a #GError, or %NULL + * + * Gets the result of a call to nm_client_reload(). + * + * Returns: %TRUE on success or %FALSE on failure. + * + * Since: 1.22 + **/ +gboolean +nm_client_reload_finish (NMClient *client, + GAsyncResult *result, + GError **error) { - if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, NULL)) { - /* This is a can-not-happen situation, the NMObject subclasses are not - * supposed to fail initialization. */ - g_warn_if_reached (); - } + g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, client, nm_client_reload), FALSE); + + return g_task_propagate_boolean (G_TASK (result), error); } +/*****************************************************************************/ + static void -object_added (GDBusObjectManager *object_manager, GDBusObject *object, gpointer user_data) +_init_fetch_all (NMClient *self) { - NMClient *client = user_data; - NMObject *obj_nm; - - obj_nm = obj_nm_for_gdbus_object (client, object, object_manager); - if (obj_nm) { - g_async_initable_init_async (G_ASYNC_INITABLE (obj_nm), - G_PRIORITY_DEFAULT, NULL, - obj_nm_inited, NULL); - } + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; + + dbus_context = nm_g_main_context_push_thread_default_if_necessary (priv->dbus_context); + + NML_NMCLIENT_LOG_D (self, "fetch all"); + + nm_assert (!priv->get_managed_objects_cancellable); + + priv->get_managed_objects_cancellable = g_cancellable_new (); + + priv->dbsid_nm_object_manager = nm_dbus_connection_signal_subscribe_object_manager (priv->dbus_connection, + priv->name_owner, + "/org/freedesktop", + _dbus_managed_objects_changed_cb, + self, + NULL); + + priv->dbsid_dbus_properties_properties_changed = nm_dbus_connection_signal_subscribe_properties_changed (priv->dbus_connection, + priv->name_owner, + NULL, + NULL, + _dbus_properties_changed_cb, + self, + NULL); + + priv->dbsid_nm_settings_connection_updated = g_dbus_connection_signal_subscribe (priv->dbus_connection, + priv->name_owner, + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + "Updated", + NULL, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + _dbus_settings_updated_cb, + self, + NULL); + + priv->dbsid_nm_connection_active_state_changed = g_dbus_connection_signal_subscribe (priv->dbus_connection, + priv->name_owner, + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + "StateChanged", + NULL, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + _dbus_nm_connection_active_state_changed_cb, + self, + NULL); + + priv->dbsid_nm_vpn_connection_state_changed = g_dbus_connection_signal_subscribe (priv->dbus_connection, + priv->name_owner, + NM_DBUS_INTERFACE_VPN_CONNECTION, + "VpnStateChanged", + NULL, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + _dbus_nm_vpn_connection_state_changed_cb, + self, + NULL); + + priv->dbsid_nm_check_permissions = g_dbus_connection_signal_subscribe (priv->dbus_connection, + priv->name_owner, + NM_DBUS_INTERFACE, + "CheckPermissions", + NULL, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + _dbus_nm_check_permissions_cb, + self, + NULL); + + g_dbus_connection_call (priv->dbus_connection, + priv->name_owner, + "/org/freedesktop", + DBUS_INTERFACE_OBJECT_MANAGER, + "GetManagedObjects", + NULL, + G_VARIANT_TYPE ("(a{oa{sa{sv}}})"), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + priv->get_managed_objects_cancellable, + _dbus_get_managed_objects_cb, + nm_utils_user_data_pack (self, g_object_ref (priv->context_busy_watcher))); + + _dbus_check_permissions_start (self); } static void -object_removed (GDBusObjectManager *object_manager, GDBusObject *object, gpointer user_data) +_init_release_all (NMClient *self) { - g_object_set_qdata (G_OBJECT (object), _nm_object_obj_nm_quark (), NULL); -} - -static gboolean -objects_created (NMClient *client, GDBusObjectManager *object_manager, GError **error) -{ - NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client); - gs_unref_object GDBusObject *manager = NULL; - gs_unref_object GDBusObject *settings = NULL; - gs_unref_object GDBusObject *dns_manager = NULL; - NMObject *obj_nm; - GList *objects, *iter; - - /* First just ensure all the NMObjects for known GDBusObjects exist. */ - objects = g_dbus_object_manager_get_objects (object_manager); - for (iter = objects; iter; iter = iter->next) - obj_nm_for_gdbus_object (client, iter->data, object_manager); - g_list_free_full (objects, g_object_unref); - - manager = g_dbus_object_manager_get_object (object_manager, NM_DBUS_PATH); - if (!manager) { - g_set_error_literal (error, - NM_CLIENT_ERROR, - NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, - "Manager object not found"); - return FALSE; - } - - obj_nm = g_object_get_qdata (G_OBJECT (manager), _nm_object_obj_nm_quark ()); - if (!obj_nm) { - g_set_error_literal (error, - NM_CLIENT_ERROR, - NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, - "Manager object lacks the proper interface"); - return FALSE; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + CList **dbus_objects_lst_heads; + NMLDBusObject *dbobj; + int i; + + NML_NMCLIENT_LOG_D (self, "release all"); + + nm_clear_g_cancellable (&priv->permissions_cancellable); + nm_clear_g_cancellable (&priv->get_managed_objects_cancellable); + + nm_clear_g_dbus_connection_signal (priv->dbus_connection, + &priv->dbsid_nm_object_manager); + nm_clear_g_dbus_connection_signal (priv->dbus_connection, + &priv->dbsid_dbus_properties_properties_changed); + nm_clear_g_dbus_connection_signal (priv->dbus_connection, + &priv->dbsid_nm_settings_connection_updated); + nm_clear_g_dbus_connection_signal (priv->dbus_connection, + &priv->dbsid_nm_connection_active_state_changed); + nm_clear_g_dbus_connection_signal (priv->dbus_connection, + &priv->dbsid_nm_vpn_connection_state_changed); + nm_clear_g_dbus_connection_signal (priv->dbus_connection, + &priv->dbsid_nm_check_permissions); + + if (priv->permissions) { + gs_unref_hashtable GHashTable *old_permissions = g_steal_pointer (&priv->permissions); + + _emit_permissions_changed (self, old_permissions, TRUE); } - priv->manager = NM_MANAGER (g_object_ref (obj_nm)); - - g_signal_connect (priv->manager, "notify", - G_CALLBACK (subobject_notify), client); - g_signal_connect (priv->manager, "device-added", - G_CALLBACK (manager_device_added), client); - g_signal_connect (priv->manager, "device-removed", - G_CALLBACK (manager_device_removed), client); - g_signal_connect (priv->manager, "any-device-added", - G_CALLBACK (manager_any_device_added), client); - g_signal_connect (priv->manager, "any-device-removed", - G_CALLBACK (manager_any_device_removed), client); - g_signal_connect (priv->manager, "permission-changed", - G_CALLBACK (manager_permission_changed), client); - g_signal_connect (priv->manager, "active-connection-added", - G_CALLBACK (manager_active_connection_added), client); - g_signal_connect (priv->manager, "active-connection-removed", - G_CALLBACK (manager_active_connection_removed), client); - - settings = g_dbus_object_manager_get_object (object_manager, NM_DBUS_PATH_SETTINGS); - if (!settings) { - g_set_error_literal (error, - NM_CLIENT_ERROR, - NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, - "Settings object not found"); - return FALSE; + nm_assert (c_list_is_empty (&priv->obj_changed_lst_head)); + + dbus_objects_lst_heads = ((CList *[]) { + &priv->dbus_objects_lst_head_on_dbus, + &priv->dbus_objects_lst_head_with_nmobj_not_ready, + &priv->dbus_objects_lst_head_with_nmobj_ready, + NULL, + }); + for (i = 0; dbus_objects_lst_heads[i]; i++) { + c_list_for_each_entry (dbobj, dbus_objects_lst_heads[i], dbus_objects_lst) { + NMLDBusObjIfaceData *db_iface_data; + + nm_assert (c_list_is_empty (&dbobj->obj_changed_lst)); + c_list_for_each_entry (db_iface_data, &dbobj->iface_lst_head, iface_lst) + db_iface_data->iface_removed = TRUE; + nml_dbus_object_obj_changed_link (self, dbobj, NML_DBUS_OBJ_CHANGED_TYPE_DBUS); + } } - obj_nm = g_object_get_qdata (G_OBJECT (settings), _nm_object_obj_nm_quark ()); - if (!obj_nm) { - g_set_error_literal (error, - NM_CLIENT_ERROR, - NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, - "Settings object lacks the proper interface"); - return FALSE; - } + _dbus_handle_changes (self, "release-all", FALSE); + + /* We require that when we remove all D-Bus interfaces, that all object will go + * away. Note that a NMLDBusObject can be alive due to a NMLDBusObjWatcher, but + * even those should be all cleaned up. */ + nm_assert (c_list_is_empty (&priv->obj_changed_lst_head)); + nm_assert (c_list_is_empty (&priv->dbus_objects_lst_head_watched_only)); + nm_assert (c_list_is_empty (&priv->dbus_objects_lst_head_on_dbus)); + nm_assert (c_list_is_empty (&priv->dbus_objects_lst_head_with_nmobj_not_ready)); + nm_assert (c_list_is_empty (&priv->dbus_objects_lst_head_with_nmobj_ready)); + nm_assert (g_hash_table_size (priv->dbus_objects) == 0); +} - priv->settings = NM_REMOTE_SETTINGS (g_object_ref (obj_nm)); +/*****************************************************************************/ - g_signal_connect (priv->settings, "notify", - G_CALLBACK (subobject_notify), client); - g_signal_connect (priv->settings, "connection-added", - G_CALLBACK (settings_connection_added), client); - g_signal_connect (priv->settings, "connection-removed", - G_CALLBACK (settings_connection_removed), client); +static void +name_owner_changed (NMClient *self, + const char *name_owner) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + gboolean changed; + gs_free char *old_name_owner_free = NULL; + const char *old_name_owner; + nm_auto_pop_gmaincontext GMainContext *dbus_context = NULL; - dns_manager = g_dbus_object_manager_get_object (object_manager, NM_DBUS_PATH_DNS_MANAGER); - if (dns_manager) { - obj_nm = g_object_get_qdata (G_OBJECT (dns_manager), _nm_object_obj_nm_quark ()); - if (!obj_nm) { - g_set_error_literal (error, - NM_CLIENT_ERROR, - NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, - "DNS manager object lacks the proper interface"); - return FALSE; - } - priv->dns_manager = NM_DNS_MANAGER (g_object_ref (obj_nm)); + name_owner = nm_str_not_empty (name_owner); - g_signal_connect (priv->dns_manager, "notify", - G_CALLBACK (dns_notify), client); - } + changed = !nm_streq0 (priv->name_owner, name_owner); - /* The handlers don't really use the client instance. However - * it makes it convenient to unhook them by data. */ - g_signal_connect (object_manager, "object-added", - G_CALLBACK (object_added), client); - g_signal_connect (object_manager, "object-removed", - G_CALLBACK (object_removed), client); + if ( !name_owner + && priv->main_context != priv->dbus_context) { + gs_unref_object GObject *old_context_busy_watcher = NULL; - return TRUE; -} + NML_NMCLIENT_LOG_D (self, "resync main context as we have no name owner"); -/* Synchronous initialization. */ + nm_clear_g_dbus_connection_signal (priv->dbus_connection, + &priv->name_owner_changed_id); -static void name_owner_changed (GObject *object, GParamSpec *pspec, gpointer user_data); + /* Our instance was initialized synchronously. Usually we must henceforth + * stick to a internal main context. But now we have no name-owner... + * at this point, we anyway are going to do a full resync. Swap the main + * contexts again. */ -static gboolean -_om_has_name_owner (GDBusObjectManager *object_manager) -{ - gs_free char *name_owner = NULL; + old_context_busy_watcher = g_steal_pointer (&priv->context_busy_watcher); + priv->context_busy_watcher = g_object_ref (g_object_get_qdata (old_context_busy_watcher, + nm_client_context_busy_watcher_quark ())); - nm_assert (G_IS_DBUS_OBJECT_MANAGER_CLIENT (object_manager)); + g_main_context_ref (priv->main_context); + g_main_context_unref (priv->dbus_context); + priv->dbus_context = priv->main_context; - name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (object_manager)); - return !!name_owner; -} + dbus_context = nm_g_main_context_push_thread_default_if_necessary (priv->dbus_context); -static gboolean -init_sync (GInitable *initable, GCancellable *cancellable, GError **error) -{ - NMClient *client = NM_CLIENT (initable); - NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client); - GList *objects, *iter; + /* we need to sync again... */ - priv->object_manager = g_dbus_object_manager_client_new_for_bus_sync (_nm_dbus_bus_type (), - G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, - "org.freedesktop.NetworkManager", - "/org/freedesktop", - proxy_type, NULL, NULL, - cancellable, error); + _assert_main_context_is_current_thread_default (self, dbus_context); - if (!priv->object_manager) - return FALSE; + priv->name_owner_changed_id = nm_dbus_connection_signal_subscribe_name_owner_changed (priv->dbus_connection, + NM_DBUS_SERVICE, + name_owner_changed_cb, + self, + NULL); + name_owner_get_call (self); + } else + dbus_context = nm_g_main_context_push_thread_default_if_necessary (priv->dbus_context); + + if (changed) { + NML_NMCLIENT_LOG_D (self, "name owner changed: %s%s%s -> %s%s%s", + NM_PRINT_FMT_QUOTE_STRING (priv->name_owner), + NM_PRINT_FMT_QUOTE_STRING (name_owner)); + old_name_owner_free = priv->name_owner; + priv->name_owner = g_strdup (name_owner); + old_name_owner = old_name_owner_free; + } else + old_name_owner = priv->name_owner; - if (_om_has_name_owner (priv->object_manager)) { - if (!objects_created (client, priv->object_manager, error)) - return FALSE; + if (changed) + _notify (self, PROP_DBUS_NAME_OWNER); - objects = g_dbus_object_manager_get_objects (priv->object_manager); - for (iter = objects; iter; iter = iter->next) { - NMObject *obj_nm; + if ( changed + && old_name_owner) + _init_release_all (self); - obj_nm = g_object_get_qdata (iter->data, _nm_object_obj_nm_quark ()); - if (!obj_nm) - continue; + if ( changed + && priv->name_owner) + _init_fetch_all (self); - if (!g_initable_init (G_INITABLE (obj_nm), cancellable, NULL)) { - /* This is a can-not-happen situation, the NMObject subclasses are not - * supposed to fail initialization. */ - g_warn_if_reached (); - } - } - g_list_free_full (objects, g_object_unref); - } + _set_nm_running (self); - g_signal_connect (priv->object_manager, "notify::name-owner", - G_CALLBACK (name_owner_changed), client); + if (priv->init_data) { + nm_auto_pop_gmaincontext GMainContext *main_context = NULL; - return TRUE; + if (priv->main_context != priv->dbus_context) + main_context = nm_g_main_context_push_thread_default_if_necessary (priv->main_context); + _init_start_check_complete (self); + } } -/* Asynchronous initialization. */ - static void -init_async_complete (NMClientInitData *init_data) +name_owner_changed_cb (GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) { - if (init_data->pending_init > 0) - return; - g_simple_async_result_complete (init_data->result); - g_object_unref (init_data->result); - g_clear_object (&init_data->cancellable); - g_slice_free (NMClientInitData, init_data); -} + NMClient *self = user_data; + NMClientPrivate *priv; + const char *new_owner; -static void -async_inited_obj_nm (GObject *object, GAsyncResult *result, gpointer user_data) -{ - NMClientInitData *init_data = user_data; - GError *error = NULL; + if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sss)"))) + return; - nm_assert (init_data && init_data->pending_init > 0); + priv = NM_CLIENT_GET_PRIVATE (self); + if (priv->name_owner_get_cancellable) + return; - if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error)) - g_simple_async_result_take_error (init_data->result, error); + g_variant_get (parameters, + "(&s&s&s)", + NULL, + NULL, + &new_owner); - init_data->pending_init--; - init_async_complete (init_data); + name_owner_changed (self, new_owner); } static void -init_async (GAsyncInitable *initable, int io_priority, - GCancellable *cancellable, GAsyncReadyCallback callback, - gpointer user_data); - -static void -unhook_om (NMClient *self) +name_owner_get_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) { - NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); - GList *objects, *iter; + NMClient *self; + NMClientPrivate *priv; + gs_unref_object GObject *context_busy_watcher = NULL; + gs_unref_variant GVariant *ret = NULL; + gs_free_error GError *error = NULL; + const char *name_owner = NULL; - if (priv->manager) { - const GPtrArray *active_connections; - const GPtrArray *devices; - int i; + nm_utils_user_data_unpack (user_data, &self, &context_busy_watcher); - active_connections = nm_manager_get_active_connections (priv->manager); - for (i = 0; i < active_connections->len; i++) - g_signal_emit (self, signals[ACTIVE_CONNECTION_REMOVED], 0, active_connections->pdata[i]); + ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error); - devices = nm_manager_get_all_devices (priv->manager); - for (i = 0; i < devices->len; i++) - g_signal_emit (self, signals[DEVICE_REMOVED], 0, devices->pdata[i]); + if ( !ret + && nm_utils_error_is_cancelled (error, FALSE)) + return; - g_signal_handlers_disconnect_by_data (priv->manager, self); - g_clear_object (&priv->manager); - g_object_notify (G_OBJECT (self), NM_CLIENT_ACTIVE_CONNECTIONS); - g_object_notify (G_OBJECT (self), NM_CLIENT_NM_RUNNING); - } - if (priv->settings) { - const GPtrArray *connections; - guint i; + priv = NM_CLIENT_GET_PRIVATE (self); - connections = nm_remote_settings_get_connections (priv->settings); - for (i = 0; i < connections->len; i++) - g_signal_emit (self, signals[CONNECTION_REMOVED], 0, connections->pdata[i]); + g_clear_object (&priv->name_owner_get_cancellable); - g_signal_handlers_disconnect_by_data (priv->settings, self); - g_clear_object (&priv->settings); - g_object_notify (G_OBJECT (self), NM_CLIENT_CONNECTIONS); - g_object_notify (G_OBJECT (self), NM_CLIENT_HOSTNAME); - g_object_notify (G_OBJECT (self), NM_CLIENT_CAN_MODIFY); - } - if (priv->dns_manager) { - g_signal_handlers_disconnect_by_data (priv->dns_manager, self); - g_clear_object (&priv->dns_manager); - } + if (ret) + g_variant_get (ret, "(&s)", &name_owner); - objects = g_dbus_object_manager_get_objects (priv->object_manager); - for (iter = objects; iter; iter = iter->next) - g_object_set_qdata (iter->data, _nm_object_obj_nm_quark (), NULL); - g_list_free_full (objects, g_object_unref); + name_owner_changed (self, name_owner); } static void -new_object_manager (GObject *source_object, GAsyncResult *res, gpointer user_data) +name_owner_get_call (NMClient *self) { - NMClient *self = NM_CLIENT (user_data); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); - g_clear_object (&priv->new_object_manager_cancellable); - g_object_notify (G_OBJECT (user_data), NM_CLIENT_NM_RUNNING); + nm_assert (!priv->name_owner_get_cancellable); + priv->name_owner_get_cancellable = g_cancellable_new (); + + g_dbus_connection_call (priv->dbus_connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "GetNameOwner", + g_variant_new ("(s)", NM_DBUS_SERVICE), + G_VARIANT_TYPE ("(s)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + priv->name_owner_get_cancellable, + name_owner_get_cb, + nm_utils_user_data_pack (self, g_object_ref (priv->context_busy_watcher))); } +/*****************************************************************************/ + static void -got_object_manager (GObject *object, GAsyncResult *result, gpointer user_data) +_init_start_complete (NMClient *self, + GError *error_take) { - NMClientInitData *init_data = user_data; - NMClient *client; - NMClientPrivate *priv; - GList *objects, *iter; - GError *error = NULL; - GDBusObjectManager *object_manager; - - object_manager = g_dbus_object_manager_client_new_for_bus_finish (result, &error); - if (object_manager == NULL) { - g_simple_async_result_take_error (init_data->result, error); - init_async_complete (init_data); - return; - } - - client = init_data->client; - priv = NM_CLIENT_GET_PRIVATE (client); - priv->object_manager = object_manager; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + InitData *init_data; - if (_om_has_name_owner (priv->object_manager)) { - if (!objects_created (client, priv->object_manager, &error)) { - g_simple_async_result_take_error (init_data->result, error); - init_async_complete (init_data); - return; - } + init_data = g_steal_pointer (&priv->init_data); - objects = g_dbus_object_manager_get_objects (priv->object_manager); - for (iter = objects; iter; iter = iter->next) { - NMObject *obj_nm; + NML_NMCLIENT_LOG_D (self, "%s init complete with %s%s%s", + init_data->is_sync ? "sync" : "async", + NM_PRINT_FMT_QUOTED (error_take, "error: ", error_take->message, "", "success")); - obj_nm = g_object_get_qdata (iter->data, _nm_object_obj_nm_quark ()); - if (!obj_nm) - continue; + nm_clear_pointer (&init_data->cancel_on_idle_source, nm_g_source_destroy_and_unref); + nm_clear_g_signal_handler (init_data->cancellable, &init_data->cancelled_id); - init_data->pending_init++; - g_async_initable_init_async (G_ASYNC_INITABLE (obj_nm), - G_PRIORITY_DEFAULT, init_data->cancellable, - async_inited_obj_nm, init_data); - } - g_list_free_full (objects, g_object_unref); + if (init_data->is_sync) { + if (error_take) + g_propagate_error (init_data->data.sync.error_location, error_take); + g_main_loop_quit (init_data->data.sync.main_loop); + } else { + if (error_take) + g_task_return_error (init_data->data.async.task, error_take); + else + g_task_return_boolean (init_data->data.async.task, TRUE); + g_object_unref (init_data->data.async.task); } - - init_async_complete (init_data); - - g_signal_connect (priv->object_manager, "notify::name-owner", - G_CALLBACK (name_owner_changed), client); + nm_g_object_unref (init_data->cancellable); + nm_g_slice_free (init_data); } static void -prepare_object_manager (NMClient *client, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +_init_start_check_complete (NMClient *self) { - NMClientInitData *init_data; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); - init_data = g_slice_new0 (NMClientInitData); - init_data->client = client; - init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - init_data->result = g_simple_async_result_new (G_OBJECT (client), callback, - user_data, init_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (init_data->result, cancellable); - g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE); + _assert_main_context_is_current_thread_default (self, main_context); - g_dbus_object_manager_client_new_for_bus (_nm_dbus_bus_type (), - G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, - "org.freedesktop.NetworkManager", - "/org/freedesktop", - proxy_type, NULL, NULL, - init_data->cancellable, - got_object_manager, - init_data); -} + if (!priv->init_data) + return; -static void -name_owner_changed (GObject *object, GParamSpec *pspec, gpointer user_data) -{ - NMClient *self = user_data; - NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); - GDBusObjectManager *object_manager = G_DBUS_OBJECT_MANAGER (object); + if (priv->get_managed_objects_cancellable) { + /* still initializing. Wait. */ + return; + } - nm_assert (object_manager == priv->object_manager); +#if NM_MORE_ASSERTS > 10 + { + NMLDBusObject *dbobj; - if (_om_has_name_owner (object_manager)) { - g_signal_handlers_disconnect_by_data (priv->object_manager, self); - g_clear_object (&priv->object_manager); - nm_clear_g_cancellable (&priv->new_object_manager_cancellable); - priv->new_object_manager_cancellable = g_cancellable_new (); - prepare_object_manager (self, priv->new_object_manager_cancellable, - new_object_manager, self); - } else { - g_signal_handlers_disconnect_by_func (object_manager, object_added, self); - unhook_om (self); + c_list_for_each_entry (dbobj, &priv->dbus_objects_lst_head_with_nmobj_not_ready, dbus_objects_lst) { + NML_NMCLIENT_LOG_T (self, "init-start waiting for %s", dbobj->dbus_path->str); + break; + } } +#endif + + if (!c_list_is_empty (&priv->dbus_objects_lst_head_with_nmobj_not_ready)) + return; + + _init_start_complete (self, NULL); } static void -init_async (GAsyncInitable *initable, int io_priority, - GCancellable *cancellable, GAsyncReadyCallback callback, - gpointer user_data) +_init_start_cancelled_cb (GCancellable *cancellable, + gpointer user_data) { - prepare_object_manager (NM_CLIENT (initable), cancellable, callback, user_data); + NMClient *self = user_data; + GError *error; + + nm_assert (NM_IS_CLIENT (self)); + nm_assert (NM_CLIENT_GET_PRIVATE (self)->init_data); + nm_assert (NM_CLIENT_GET_PRIVATE (self)->init_data->cancellable == cancellable); + + nm_utils_error_set_cancelled (&error, FALSE, NULL); + _init_start_complete (self, error); } static gboolean -init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error) +_init_start_cancel_on_idle_cb (gpointer user_data) { - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); + NMClient *self = user_data; + GError *error; - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return TRUE; + nm_utils_error_set_cancelled (&error, FALSE, NULL); + _init_start_complete (self, error); + return G_SOURCE_CONTINUE; } static void -dispose (GObject *object) +_init_start_with_bus (NMClient *self) { - NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object); - - nm_clear_g_cancellable (&priv->new_object_manager_cancellable); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); - if (priv->manager) { - g_signal_handlers_disconnect_by_data (priv->manager, object); - g_clear_object (&priv->manager); + if (priv->init_data->cancellable) { + priv->init_data->cancelled_id = g_signal_connect (priv->init_data->cancellable, + "cancelled", + G_CALLBACK (_init_start_cancelled_cb), + self); + if (g_cancellable_is_cancelled (priv->init_data->cancellable)) { + priv->init_data->cancel_on_idle_source = g_idle_source_new (); + g_source_set_callback (priv->init_data->cancel_on_idle_source, _init_start_cancel_on_idle_cb, self, NULL); + g_source_attach (priv->init_data->cancel_on_idle_source, priv->main_context); + return; + } } - if (priv->settings) { - g_signal_handlers_disconnect_by_data (priv->settings, object); - g_clear_object (&priv->settings); - } + _assert_main_context_is_current_thread_default (self, dbus_context); - if (priv->dns_manager) { - g_signal_handlers_disconnect_by_data (priv->dns_manager, object); - g_clear_object (&priv->dns_manager); - } + priv->name_owner_changed_id = nm_dbus_connection_signal_subscribe_name_owner_changed (priv->dbus_connection, + NM_DBUS_SERVICE, + name_owner_changed_cb, + self, + NULL); + name_owner_get_call (self); +} + +static void +_init_start_bus_get_cb (GObject *source, GAsyncResult *result, gpointer user_data) +{ + NMClient *self = user_data; + NMClientPrivate *priv; + GDBusConnection *dbus_connection; + GError *error = NULL; - if (priv->object_manager) { - GList *objects, *iter; + nm_assert (NM_IS_CLIENT (self)); - /* Unhook the NM objects. */ - objects = g_dbus_object_manager_get_objects (priv->object_manager); - for (iter = objects; iter; iter = iter->next) - g_object_set_qdata (G_OBJECT (iter->data), _nm_object_obj_nm_quark (), NULL); - g_list_free_full (objects, g_object_unref); + dbus_connection = g_bus_get_finish (result, &error); - g_signal_handlers_disconnect_by_data (priv->object_manager, object); - g_clear_object (&priv->object_manager); + if (!dbus_connection) { + _init_start_complete (self, error); + return; } - G_OBJECT_CLASS (nm_client_parent_class)->dispose (object); + priv = NM_CLIENT_GET_PRIVATE (self); + priv->dbus_connection = dbus_connection; - if (priv->udev) { - udev_unref (priv->udev); - priv->udev = NULL; - } + _init_start_with_bus (self); } static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) +_init_start (NMClient *self) { - NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); - switch (prop_id) { - case PROP_NETWORKING_ENABLED: - case PROP_WIRELESS_ENABLED: - case PROP_WWAN_ENABLED: - case PROP_WIMAX_ENABLED: - case PROP_CONNECTIVITY_CHECK_ENABLED: - if (priv->manager) - g_object_set_property (G_OBJECT (priv->manager), pspec->name, value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; + NML_NMCLIENT_LOG_D (self, "starting %s initialization...", + priv->init_data->is_sync ? "sync" : "async"); + + if (!priv->dbus_connection) { + g_bus_get (_nm_dbus_bus_type (), + priv->init_data->cancellable, + _init_start_bus_get_cb, + self); + return; } + + _init_start_with_bus (self); } +/*****************************************************************************/ + static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) @@ -3401,6 +6927,12 @@ get_property (GObject *object, guint prop_id, NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object); switch (prop_id) { + case PROP_DBUS_CONNECTION: + g_value_set_object (value, priv->dbus_connection); + break; + case PROP_DBUS_NAME_OWNER: + g_value_set_string (value, nm_client_get_dbus_name_owner (self)); + break; case PROP_NM_RUNNING: g_value_set_boolean (value, nm_client_get_nm_running (self)); break; @@ -3422,28 +6954,19 @@ get_property (GObject *object, guint prop_id, g_value_set_boolean (value, nm_client_wireless_get_enabled (self)); break; case PROP_WIRELESS_HARDWARE_ENABLED: - if (priv->manager) - g_object_get_property (G_OBJECT (priv->manager), pspec->name, value); - else - g_value_set_boolean (value, FALSE); + g_value_set_boolean (value, nm_client_wireless_hardware_get_enabled (self)); break; case PROP_WWAN_ENABLED: g_value_set_boolean (value, nm_client_wwan_get_enabled (self)); break; case PROP_WWAN_HARDWARE_ENABLED: - if (priv->manager) - g_object_get_property (G_OBJECT (priv->manager), pspec->name, value); - else - g_value_set_boolean (value, FALSE); + g_value_set_boolean (value, nm_client_wwan_hardware_get_enabled (self)); break; case PROP_WIMAX_ENABLED: - g_value_set_boolean (value, nm_client_wimax_get_enabled (self)); + g_value_set_boolean (value, FALSE); break; case PROP_WIMAX_HARDWARE_ENABLED: - if (priv->manager) - g_object_get_property (G_OBJECT (priv->manager), pspec->name, value); - else - g_value_set_boolean (value, FALSE); + g_value_set_boolean (value, FALSE); break; case PROP_ACTIVE_CONNECTIONS: g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_active_connections (self))); @@ -3457,6 +6980,9 @@ get_property (GObject *object, guint prop_id, case PROP_CONNECTIVITY_CHECK_ENABLED: g_value_set_boolean (value, nm_client_connectivity_check_get_enabled (self)); break; + case PROP_CONNECTIVITY_CHECK_URI: + g_value_set_string (value, nm_client_connectivity_check_get_uri (self)); + break; case PROP_PRIMARY_CONNECTION: g_value_set_object (value, nm_client_get_primary_connection (self)); break; @@ -3467,59 +6993,39 @@ get_property (GObject *object, guint prop_id, g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_devices (self))); break; case PROP_METERED: - if (priv->manager) - g_object_get_property (G_OBJECT (priv->manager), pspec->name, value); - else - g_value_set_uint (value, NM_METERED_UNKNOWN); + g_value_set_uint (value, nm_client_get_metered (self)); break; case PROP_ALL_DEVICES: g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_all_devices (self))); break; case PROP_CHECKPOINTS: - if (priv->manager) - g_object_get_property (G_OBJECT (priv->manager), pspec->name, value); - else - g_value_take_boxed (value, g_ptr_array_new ()); + g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_checkpoints (self))); break; /* Settings properties. */ case PROP_CONNECTIONS: - if (priv->settings) - g_object_get_property (G_OBJECT (priv->settings), pspec->name, value); - else - g_value_take_boxed (value, _nm_utils_copy_object_array (&empty)); + g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_connections (self))); break; case PROP_HOSTNAME: - if (priv->settings) - g_object_get_property (G_OBJECT (priv->settings), pspec->name, value); - else - g_value_set_string (value, NULL); + g_value_set_string (value, priv->settings.hostname); break; case PROP_CAN_MODIFY: - if (priv->settings) - g_object_get_property (G_OBJECT (priv->settings), pspec->name, value); - else - g_value_set_boolean (value, FALSE); + g_value_set_boolean (value, priv->settings.can_modify); break; /* DNS properties */ case PROP_DNS_MODE: + g_value_set_string (value, nm_client_get_dns_mode (self)); + break; case PROP_DNS_RC_MANAGER: - g_return_if_fail (pspec->name && strlen (pspec->name) > NM_STRLEN ("dns-")); - if (priv->dns_manager) - g_object_get_property (G_OBJECT (priv->dns_manager), - &pspec->name[NM_STRLEN ("dns-")], value); - else - g_value_set_string (value, NULL); + g_value_set_string (value, nm_client_get_dns_rc_manager (self)); break; case PROP_DNS_CONFIGURATION: - if (priv->dns_manager) { - g_object_get_property (G_OBJECT (priv->dns_manager), - NM_DNS_MANAGER_CONFIGURATION, - value); - } else - g_value_take_boxed (value, NULL); + g_value_take_boxed (value, _nm_utils_copy_array (nm_client_get_dns_configuration (self), + (NMUtilsCopyFunc) nm_dns_entry_dup, + (GDestroyNotify) nm_dns_entry_unref)); break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -3527,176 +7033,613 @@ get_property (GObject *object, guint prop_id, } static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMClient *self = NM_CLIENT (object); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + gboolean b; + + switch (prop_id) { + case PROP_DBUS_CONNECTION: + /* construct-only */ + priv->dbus_connection = g_value_dup_object (value); + break; + + case PROP_NETWORKING_ENABLED: + b = g_value_get_boolean (value); + if (priv->nm.networking_enabled != b) { + nm_client_networking_set_enabled (self, + b, + NULL); + /* Let the property value flip when we get the change signal from NM */ + } + break; + case PROP_WIRELESS_ENABLED: + b = g_value_get_boolean (value); + if (priv->nm.wireless_enabled != b) { + nm_client_wireless_set_enabled (self, b); + /* Let the property value flip when we get the change signal from NM */ + } + break; + case PROP_WWAN_ENABLED: + b = g_value_get_boolean (value); + if (priv->nm.wwan_enabled != b) { + nm_client_wwan_set_enabled (self, b); + /* Let the property value flip when we get the change signal from NM */ + } + break; + case PROP_CONNECTIVITY_CHECK_ENABLED: + b = g_value_get_boolean (value); + if (priv->nm.connectivity_check_enabled != b) { + nm_client_connectivity_check_set_enabled (self, b); + /* Let the property value flip when we get the change signal from NM */ + } + break; + case PROP_WIMAX_ENABLED: + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/*****************************************************************************/ + +static gboolean +init_sync (GInitable *initable, GCancellable *cancellable, GError **error) +{ + gs_unref_object NMClient *self = NULL; + NMClientPrivate *priv; + GMainContext *dbus_context; + GError *local_error = NULL; + GMainLoop *main_loop; + GObject *parent_context_busy_watcher; + + g_return_val_if_fail (NM_IS_CLIENT (initable), FALSE); + + self = g_object_ref (NM_CLIENT (initable)); /* keep instance alive. */ + + priv = NM_CLIENT_GET_PRIVATE (self); + + g_return_val_if_fail (!priv->dbus_context, FALSE); + + /* when using init_sync(), we use a separate internal GMainContext for + * all D-Bus operations and use our regular async-init code. That means, + * also in sync-init, we don't actually block waiting for our D-Bus requests, + * instead, we only block (g_main_loop_run()) for the overall result. + * + * Doing this has a performance overhead. Also, we cannot ever fall back + * to the regular main-context (not unless we lose the main-owner and + * need to re-initialize). The reason is that we receive events on our + * dbus_context, and this cannot be brought in sync -- short of full + * reinitalizing. Therefor, using sync init not only is slower during + * construction of the object, but NMClient will stick to the dual GMainContext + * mode. + * + * Aside from this downside, the solution is good: + * + * - we don't duplicate the implementation of async-init. + * - we don't iterate the main-context of the caller while waiting for + * initialization to happen + * - we still invoke all changes under the main_context of the caller. + * - all D-Bus events strictly go through dbus_context and are in order. + */ + + dbus_context = g_main_context_new (); + priv->dbus_context = g_main_context_ref (dbus_context); + + /* We have an inner context. Note that if we loose the name owner, we have a chance + * to resync and drop the inner context. That means, requests made against the inner + * context have a different lifetime. Hence, we create a separate tracking + * object. This "wraps" the outer context-busy-watcher and references it, so + * that the work together. Grep for nm_client_context_busy_watcher_quark() to + * see how this works. */ + parent_context_busy_watcher = g_steal_pointer (&priv->context_busy_watcher); + priv->context_busy_watcher = g_object_new (G_TYPE_OBJECT, NULL); + g_object_set_qdata_full (priv->context_busy_watcher, + nm_client_context_busy_watcher_quark (), + parent_context_busy_watcher, + g_object_unref); + + g_main_context_push_thread_default (dbus_context); + + main_loop = g_main_loop_new (dbus_context, FALSE); + + priv->init_data = _init_data_new_sync (cancellable, main_loop, &local_error); + + _init_start (self); + + g_main_loop_run (main_loop); + + g_main_loop_unref (main_loop); + + g_main_context_pop_thread_default (dbus_context); + + if (priv->main_context != priv->dbus_context) { + GSource *source; + + source = nm_utils_g_main_context_create_integrate_source (priv->dbus_context); + g_source_attach (source, priv->main_context); + _context_busy_watcher_attach_integration_source (priv->context_busy_watcher, + g_steal_pointer (&source)); + } + + g_main_context_unref (dbus_context); + + if (local_error) { + g_propagate_error (error, local_error); + return FALSE; + } + return TRUE; +} + +/*****************************************************************************/ + +static void +init_async (GAsyncInitable *initable, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + NMClientPrivate *priv; + NMClient *self; + nm_auto_pop_gmaincontext GMainContext *context = NULL; + GTask *task; + + g_return_if_fail (NM_IS_CLIENT (initable)); + + self = NM_CLIENT (initable); + priv = NM_CLIENT_GET_PRIVATE (self); + + g_return_if_fail (!priv->dbus_context); + + priv->dbus_context = g_main_context_ref (priv->main_context); + + context = nm_g_main_context_push_thread_default_if_necessary (priv->main_context); + + task = nm_g_task_new (self, cancellable, init_async, callback, user_data); + g_task_set_priority (task, io_priority); + + priv->init_data = _init_data_new_async (cancellable, g_steal_pointer (&task)); + + _init_start (self); +} + +static gboolean +init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error) +{ + g_return_val_if_fail (NM_IS_CLIENT (initable), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, initable, init_async), FALSE); + + return g_task_propagate_boolean (G_TASK (result), error); +} + +/*****************************************************************************/ + +static void +nm_client_init (NMClient *self) +{ + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + + priv->context_busy_watcher = g_object_new (G_TYPE_OBJECT, NULL); + + c_list_init (&self->obj_base.queue_notify_lst); + c_list_init (&priv->queue_notify_lst_head); + c_list_init (&priv->notify_event_lst_head); + + priv->dbus_objects = g_hash_table_new (nm_pdirect_hash, nm_pdirect_equal); + c_list_init (&priv->dbus_objects_lst_head_watched_only); + c_list_init (&priv->dbus_objects_lst_head_on_dbus); + c_list_init (&priv->dbus_objects_lst_head_with_nmobj_not_ready); + c_list_init (&priv->dbus_objects_lst_head_with_nmobj_ready); + c_list_init (&priv->obj_changed_lst_head); +} + +/** + * nm_client_new: + * @cancellable: a #GCancellable, or %NULL + * @error: location for a #GError, or %NULL + * + * Creates a new #NMClient. + * + * Note that this will do blocking D-Bus calls to initialize the + * client. You can use nm_client_new_async() if you want to avoid + * that. + * + * Returns: a new #NMClient or NULL on an error + **/ +NMClient * +nm_client_new (GCancellable *cancellable, + GError **error) +{ + return g_initable_new (NM_TYPE_CLIENT, cancellable, error, + NULL); +} + +/** + * nm_client_new_async: + * @cancellable: a #GCancellable, or %NULL + * @callback: callback to call when the client is created + * @user_data: data for @callback + * + * Creates a new #NMClient and begins asynchronously initializing it. + * @callback will be called when it is done; use + * nm_client_new_finish() to get the result. Note that on an error, + * the callback can be invoked with two first parameters as NULL. + **/ +void +nm_client_new_async (GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_async_initable_new_async (NM_TYPE_CLIENT, + G_PRIORITY_DEFAULT, + cancellable, + callback, + user_data, + NULL); +} + +/** + * nm_client_new_finish: + * @result: a #GAsyncResult + * @error: location for a #GError, or %NULL + * + * Gets the result of an nm_client_new_async() call. + * + * Returns: a new #NMClient, or %NULL on error + **/ +NMClient * +nm_client_new_finish (GAsyncResult *result, GError **error) +{ + gs_unref_object GObject *source_object = NULL; + GObject *object; + + source_object = g_async_result_get_source_object (result); + g_return_val_if_fail (source_object, NULL); + + object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), + result, + error); + g_return_val_if_fail (!object || NM_IS_CLIENT (object), FALSE); + + return NM_CLIENT (object); +} + +static void +constructed (GObject *object) +{ + NMClient *self = NM_CLIENT (object); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + + priv->main_context = g_main_context_ref_thread_default (); + + G_OBJECT_CLASS (nm_client_parent_class)->constructed (object); + + NML_NMCLIENT_LOG_D (self, "new NMClient instance"); +} + +static void +dispose (GObject *object) +{ + NMClient *self = NM_CLIENT (object); + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + + nm_assert (!priv->init_data); + + self->obj_base.is_disposing = TRUE; + + nm_clear_g_cancellable (&priv->name_owner_get_cancellable); + + nm_clear_g_dbus_connection_signal (priv->dbus_connection, + &priv->name_owner_changed_id); + + nm_clear_g_free (&priv->name_owner); + + _init_release_all (self); + + nm_assert (c_list_is_empty (&priv->dbus_objects_lst_head_watched_only)); + nm_assert (c_list_is_empty (&priv->dbus_objects_lst_head_on_dbus)); + nm_assert (c_list_is_empty (&priv->dbus_objects_lst_head_with_nmobj_not_ready)); + nm_assert (c_list_is_empty (&priv->dbus_objects_lst_head_with_nmobj_ready)); + + nm_assert (c_list_is_empty (&priv->queue_notify_lst_head)); + nm_assert (c_list_is_empty (&priv->notify_event_lst_head)); + nm_assert (c_list_is_empty (&self->obj_base.queue_notify_lst)); + nm_assert (!priv->dbus_objects || g_hash_table_size (priv->dbus_objects) == 0); + + nml_dbus_property_o_clear_many (priv->nm.property_o, G_N_ELEMENTS (priv->nm.property_o), NULL); + nml_dbus_property_ao_clear_many (priv->nm.property_ao, G_N_ELEMENTS (priv->nm.property_ao), NULL); + + nm_clear_g_free (&priv->nm.connectivity_check_uri); + nm_clear_g_free (&priv->nm.version); + + nml_dbus_property_ao_clear (&priv->settings.connections, NULL); + nm_clear_g_free (&priv->settings.hostname); + + nm_clear_pointer (&priv->dns_manager.configuration, g_ptr_array_unref); + nm_clear_g_free (&priv->dns_manager.mode); + nm_clear_g_free (&priv->dns_manager.rc_manager); + + nm_clear_pointer (&priv->dbus_objects, g_hash_table_destroy); + + G_OBJECT_CLASS (nm_client_parent_class)->dispose (object); + + nm_clear_pointer (&priv->udev, udev_unref); + + nm_clear_pointer (&priv->dbus_context, g_main_context_unref); + nm_clear_pointer (&priv->main_context, g_main_context_unref); + + nm_clear_pointer (&priv->permissions, g_hash_table_unref); + + g_clear_object (&priv->dbus_connection); + + g_clear_object (&priv->context_busy_watcher); + + nm_clear_g_free (&priv->name_owner); +} + +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_agentmanager = NML_DBUS_META_IFACE_INIT ( + NM_DBUS_INTERFACE_AGENT_MANAGER, + NULL, + NML_DBUS_META_INTERFACE_PRIO_NONE, +); + +const NMLDBusMetaIface _nml_dbus_meta_iface_nm = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE, + nm_client_get_type, + NML_DBUS_META_INTERFACE_PRIO_NMCLIENT, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_O_PROP ("ActivatingConnection", PROP_ACTIVATING_CONNECTION, NMClient, _priv.nm.property_o[PROPERTY_O_IDX_NM_ACTIVATING_CONNECTION], nm_active_connection_get_type ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("ActiveConnections", PROP_ACTIVE_CONNECTIONS, NMClient, _priv.nm.property_ao[PROPERTY_AO_IDX_ACTIVE_CONNECTIONS], nm_active_connection_get_type, .notify_changed_ao = _property_ao_notify_changed_active_connections_cb ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("AllDevices", PROP_ALL_DEVICES, NMClient, _priv.nm.property_ao[PROPERTY_AO_IDX_ALL_DEVICES], nm_device_get_type, .notify_changed_ao = _property_ao_notify_changed_all_devices_cb ), + NML_DBUS_META_PROPERTY_INIT_IGNORE ("Capabilities", "au" ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Checkpoints", PROP_CHECKPOINTS, NMClient, _priv.nm.property_ao[PROPERTY_AO_IDX_CHECKPOINTS], nm_checkpoint_get_type ), + NML_DBUS_META_PROPERTY_INIT_U ("Connectivity", PROP_CONNECTIVITY, NMClient, _priv.nm.connectivity ), + NML_DBUS_META_PROPERTY_INIT_B ("ConnectivityCheckAvailable", PROP_CONNECTIVITY_CHECK_AVAILABLE, NMClient, _priv.nm.connectivity_check_available ), + NML_DBUS_META_PROPERTY_INIT_B ("ConnectivityCheckEnabled", PROP_CONNECTIVITY_CHECK_ENABLED, NMClient, _priv.nm.connectivity_check_enabled ), + NML_DBUS_META_PROPERTY_INIT_S ("ConnectivityCheckUri", PROP_CONNECTIVITY_CHECK_URI, NMClient, _priv.nm.connectivity_check_uri ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Devices", PROP_DEVICES, NMClient, _priv.nm.property_ao[PROPERTY_AO_IDX_DEVICES], nm_device_get_type, .notify_changed_ao = _property_ao_notify_changed_devices_cb ), + NML_DBUS_META_PROPERTY_INIT_IGNORE ("GlobalDnsConfiguration", "a{sv}" ), + NML_DBUS_META_PROPERTY_INIT_U ("Metered", PROP_METERED, NMClient, _priv.nm.metered ), + NML_DBUS_META_PROPERTY_INIT_B ("NetworkingEnabled", PROP_NETWORKING_ENABLED, NMClient, _priv.nm.networking_enabled ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("PrimaryConnection", PROP_PRIMARY_CONNECTION, NMClient, _priv.nm.property_o[PROPERTY_O_IDX_NM_PRIMAY_CONNECTION], nm_active_connection_get_type ), + NML_DBUS_META_PROPERTY_INIT_IGNORE ("PrimaryConnectionType", "s" ), + NML_DBUS_META_PROPERTY_INIT_B ("Startup", PROP_STARTUP, NMClient, _priv.nm.startup ), + NML_DBUS_META_PROPERTY_INIT_U ("State", PROP_STATE, NMClient, _priv.nm.state ), + NML_DBUS_META_PROPERTY_INIT_S ("Version", PROP_VERSION, NMClient, _priv.nm.version ), + NML_DBUS_META_PROPERTY_INIT_IGNORE ("WimaxEnabled", "b" ), + NML_DBUS_META_PROPERTY_INIT_IGNORE ("WimaxHardwareEnabled", "b" ), + NML_DBUS_META_PROPERTY_INIT_B ("WirelessEnabled", PROP_WIRELESS_ENABLED, NMClient, _priv.nm.wireless_enabled ), + NML_DBUS_META_PROPERTY_INIT_B ("WirelessHardwareEnabled", PROP_WIRELESS_HARDWARE_ENABLED, NMClient, _priv.nm.wireless_hardware_enabled ), + NML_DBUS_META_PROPERTY_INIT_B ("WwanEnabled", PROP_WWAN_ENABLED, NMClient, _priv.nm.wwan_enabled ), + NML_DBUS_META_PROPERTY_INIT_B ("WwanHardwareEnabled", PROP_WWAN_HARDWARE_ENABLED, NMClient, _priv.nm.wwan_hardware_enabled ), + ), +); + +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_settings = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_SETTINGS, + nm_client_get_type, + NML_DBUS_META_INTERFACE_PRIO_NMCLIENT, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_B ("CanModify", PROP_CAN_MODIFY, NMClient, _priv.settings.can_modify ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Connections", PROP_CONNECTIONS, NMClient, _priv.settings.connections, nm_remote_connection_get_type, .notify_changed_ao = _property_ao_notify_changed_connections_cb, .check_nmobj_visible_fcn = (gboolean (*) (GObject *)) nm_remote_connection_get_visible ), + NML_DBUS_META_PROPERTY_INIT_S ("Hostname", PROP_HOSTNAME, NMClient, _priv.settings.hostname ), + ), +); + +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_dnsmanager = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DNS_MANAGER, + nm_client_get_type, + NML_DBUS_META_INTERFACE_PRIO_NMCLIENT, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_FCN ("Configuration", PROP_DNS_CONFIGURATION, "aa{sv}", _notify_update_prop_dns_manager_configuration ), + NML_DBUS_META_PROPERTY_INIT_S ("Mode", PROP_DNS_MODE, NMClient, _priv.dns_manager.mode ), + NML_DBUS_META_PROPERTY_INIT_S ("RcManager", PROP_DNS_RC_MANAGER, NMClient, _priv.dns_manager.rc_manager ), + ), +); + +static void nm_client_class_init (NMClientClass *client_class) { GObjectClass *object_class = G_OBJECT_CLASS (client_class); - g_type_class_add_private (client_class, sizeof (NMClientPrivate)); + _dbus_path_nm = nm_ref_string_new (NM_DBUS_PATH); + _dbus_path_settings = nm_ref_string_new (NM_DBUS_PATH_SETTINGS); + _dbus_path_dns_manager = nm_ref_string_new (NM_DBUS_PATH_DNS_MANAGER); - /* virtual methods */ - object_class->set_property = set_property; object_class->get_property = get_property; - object_class->dispose = dispose; + object_class->set_property = set_property; + object_class->constructed = constructed; + object_class->dispose = dispose; + + /** + * NMClient:dbus-connection: + * + * The #GDBusConnection to use. + * + * If this is not set during object construction, the D-Bus connection will + * automatically be chosen during async/sync initalization via g_bus_get(). + * + * Since: 1.22 + */ + obj_properties[PROP_DBUS_CONNECTION] = + g_param_spec_object (NM_CLIENT_DBUS_CONNECTION, "", "", + G_TYPE_DBUS_CONNECTION, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); - /* properties */ + /** + * NMClient:dbus-name-owner: + * + * The name owner of the NetworkManager D-Bus service. + * + * Since: 1.22 + **/ + obj_properties[PROP_DBUS_NAME_OWNER] = + g_param_spec_string (NM_CLIENT_DBUS_NAME_OWNER, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:version: * * The NetworkManager version. **/ - g_object_class_install_property - (object_class, PROP_VERSION, - g_param_spec_string (NM_CLIENT_VERSION, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_VERSION] = + g_param_spec_string (NM_CLIENT_VERSION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:state: * * The current daemon state. **/ - g_object_class_install_property - (object_class, PROP_STATE, - g_param_spec_enum (NM_CLIENT_STATE, "", "", - NM_TYPE_STATE, - NM_STATE_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_STATE] = + g_param_spec_enum (NM_CLIENT_STATE, "", "", + NM_TYPE_STATE, + NM_STATE_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:startup: * * Whether the daemon is still starting up. **/ - g_object_class_install_property - (object_class, PROP_STARTUP, - g_param_spec_boolean (NM_CLIENT_STARTUP, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_STARTUP] = + g_param_spec_boolean (NM_CLIENT_STARTUP, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:nm-running: * * Whether the daemon is running. **/ - g_object_class_install_property - (object_class, PROP_NM_RUNNING, - g_param_spec_boolean (NM_CLIENT_NM_RUNNING, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_NM_RUNNING] = + g_param_spec_boolean (NM_CLIENT_NM_RUNNING, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:networking-enabled: * * Whether networking is enabled. - **/ - g_object_class_install_property - (object_class, PROP_NETWORKING_ENABLED, - g_param_spec_boolean (NM_CLIENT_NETWORKING_ENABLED, "", "", - TRUE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + * + * The property setter is a synchronous D-Bus call. This is deprecated since 1.22. + */ + obj_properties[PROP_NETWORKING_ENABLED] = + g_param_spec_boolean (NM_CLIENT_NETWORKING_ENABLED, "", "", + FALSE, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); /** * NMClient:wireless-enabled: * * Whether wireless is enabled. + * + * The property setter is a synchronous D-Bus call. This is deprecated since 1.22. **/ - g_object_class_install_property - (object_class, PROP_WIRELESS_ENABLED, - g_param_spec_boolean (NM_CLIENT_WIRELESS_ENABLED, "", "", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_WIRELESS_ENABLED] = + g_param_spec_boolean (NM_CLIENT_WIRELESS_ENABLED, "", "", + FALSE, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); /** * NMClient:wireless-hardware-enabled: * * Whether the wireless hardware is enabled. **/ - g_object_class_install_property - (object_class, PROP_WIRELESS_HARDWARE_ENABLED, - g_param_spec_boolean (NM_CLIENT_WIRELESS_HARDWARE_ENABLED, "", "", - TRUE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_WIRELESS_HARDWARE_ENABLED] = + g_param_spec_boolean (NM_CLIENT_WIRELESS_HARDWARE_ENABLED, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:wwan-enabled: * * Whether WWAN functionality is enabled. - **/ - g_object_class_install_property - (object_class, PROP_WWAN_ENABLED, - g_param_spec_boolean (NM_CLIENT_WWAN_ENABLED, "", "", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + * + * The property setter is a synchronous D-Bus call. This is deprecated since 1.22. + */ + obj_properties[PROP_WWAN_ENABLED] = + g_param_spec_boolean (NM_CLIENT_WWAN_ENABLED, "", "", + FALSE, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); /** * NMClient:wwan-hardware-enabled: * * Whether the WWAN hardware is enabled. **/ - g_object_class_install_property - (object_class, PROP_WWAN_HARDWARE_ENABLED, - g_param_spec_boolean (NM_CLIENT_WWAN_HARDWARE_ENABLED, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_WWAN_HARDWARE_ENABLED] = + g_param_spec_boolean (NM_CLIENT_WWAN_HARDWARE_ENABLED, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:wimax-enabled: * * Whether WiMAX functionality is enabled. - **/ - g_object_class_install_property - (object_class, PROP_WIMAX_ENABLED, - g_param_spec_boolean (NM_CLIENT_WIMAX_ENABLED, "", "", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + * + * Deprecated: 1.22: WiMAX is no longer supported and this always returns FALSE. The setter has no effect. + */ + obj_properties[PROP_WIMAX_ENABLED] = + g_param_spec_boolean (NM_CLIENT_WIMAX_ENABLED, "", "", + FALSE, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); /** * NMClient:wimax-hardware-enabled: * * Whether the WiMAX hardware is enabled. + * + * Deprecated: 1.22: WiMAX is no longer supported and this always returns FALSE. **/ - g_object_class_install_property - (object_class, PROP_WIMAX_HARDWARE_ENABLED, - g_param_spec_boolean (NM_CLIENT_WIMAX_HARDWARE_ENABLED, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_WIMAX_HARDWARE_ENABLED] = + g_param_spec_boolean (NM_CLIENT_WIMAX_HARDWARE_ENABLED, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:active-connections: (type GPtrArray(NMActiveConnection)) * * The active connections. **/ - g_object_class_install_property - (object_class, PROP_ACTIVE_CONNECTIONS, - g_param_spec_boxed (NM_CLIENT_ACTIVE_CONNECTIONS, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ACTIVE_CONNECTIONS] = + g_param_spec_boxed (NM_CLIENT_ACTIVE_CONNECTIONS, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:connectivity: * * The network connectivity state. */ - g_object_class_install_property - (object_class, PROP_CONNECTIVITY, - g_param_spec_enum (NM_CLIENT_CONNECTIVITY, "", "", - NM_TYPE_CONNECTIVITY_STATE, - NM_CONNECTIVITY_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CONNECTIVITY] = + g_param_spec_enum (NM_CLIENT_CONNECTIVITY, "", "", + NM_TYPE_CONNECTIVITY_STATE, + NM_CONNECTIVITY_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient::connectivity-check-available @@ -3705,12 +7648,11 @@ nm_client_class_init (NMClientClass *client_class) * * Since: 1.10 */ - g_object_class_install_property - (object_class, PROP_CONNECTIVITY_CHECK_AVAILABLE, - g_param_spec_boolean (NM_CLIENT_CONNECTIVITY_CHECK_AVAILABLE, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CONNECTIVITY_CHECK_AVAILABLE] = + g_param_spec_boolean (NM_CLIENT_CONNECTIVITY_CHECK_AVAILABLE, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient::connectivity-check-enabled @@ -3718,13 +7660,27 @@ nm_client_class_init (NMClientClass *client_class) * Whether a connectivity checking service has been enabled. * * Since: 1.10 + * + * The property setter is a synchronous D-Bus call. This is deprecated since 1.22. */ - g_object_class_install_property - (object_class, PROP_CONNECTIVITY_CHECK_ENABLED, - g_param_spec_boolean (NM_CLIENT_CONNECTIVITY_CHECK_ENABLED, "", "", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CONNECTIVITY_CHECK_ENABLED] = + g_param_spec_boolean (NM_CLIENT_CONNECTIVITY_CHECK_ENABLED, "", "", + FALSE, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); + + /** + * NMClient:connectivity-check-uri: + * + * The used URI for connectivity checking. + * + * Since: 1.22 + **/ + obj_properties[PROP_CONNECTIVITY_CHECK_URI] = + g_param_spec_string (NM_CLIENT_CONNECTIVITY_CHECK_URI, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:primary-connection: @@ -3732,12 +7688,11 @@ nm_client_class_init (NMClientClass *client_class) * The #NMActiveConnection of the device with the default route; * see nm_client_get_primary_connection() for more details. **/ - g_object_class_install_property - (object_class, PROP_PRIMARY_CONNECTION, - g_param_spec_object (NM_CLIENT_PRIMARY_CONNECTION, "", "", - NM_TYPE_ACTIVE_CONNECTION, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PRIMARY_CONNECTION] = + g_param_spec_object (NM_CLIENT_PRIMARY_CONNECTION, "", "", + NM_TYPE_ACTIVE_CONNECTION, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:activating-connection: @@ -3745,24 +7700,22 @@ nm_client_class_init (NMClientClass *client_class) * The #NMActiveConnection of the activating connection that is * likely to become the new #NMClient:primary-connection. **/ - g_object_class_install_property - (object_class, PROP_ACTIVATING_CONNECTION, - g_param_spec_object (NM_CLIENT_ACTIVATING_CONNECTION, "", "", - NM_TYPE_ACTIVE_CONNECTION, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ACTIVATING_CONNECTION] = + g_param_spec_object (NM_CLIENT_ACTIVATING_CONNECTION, "", "", + NM_TYPE_ACTIVE_CONNECTION, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:devices: (type GPtrArray(NMDevice)) * * List of real network devices. Does not include placeholder devices. **/ - g_object_class_install_property - (object_class, PROP_DEVICES, - g_param_spec_boxed (NM_CLIENT_DEVICES, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DEVICES] = + g_param_spec_boxed (NM_CLIENT_DEVICES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:all-devices: (type GPtrArray(NMDevice)) @@ -3770,12 +7723,11 @@ nm_client_class_init (NMClientClass *client_class) * List of both real devices and device placeholders. * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_ALL_DEVICES, - g_param_spec_boxed (NM_CLIENT_ALL_DEVICES, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ALL_DEVICES] = + g_param_spec_boxed (NM_CLIENT_ALL_DEVICES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:connections: (type GPtrArray(NMRemoteConnection)) @@ -3785,12 +7737,11 @@ nm_client_class_init (NMClientClass *client_class) * contain the object paths of connections that the user does not have * permission to read the details of.) */ - g_object_class_install_property - (object_class, PROP_CONNECTIONS, - g_param_spec_boxed (NM_CLIENT_CONNECTIONS, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CONNECTIONS] = + g_param_spec_boxed (NM_CLIENT_CONNECTIONS, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:hostname: @@ -3798,24 +7749,22 @@ nm_client_class_init (NMClientClass *client_class) * The machine hostname stored in persistent configuration. This can be * modified by calling nm_client_save_hostname(). */ - g_object_class_install_property - (object_class, PROP_HOSTNAME, - g_param_spec_string (NM_CLIENT_HOSTNAME, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HOSTNAME] = + g_param_spec_string (NM_CLIENT_HOSTNAME, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:can-modify: * * If %TRUE, adding and modifying connections is supported. */ - g_object_class_install_property - (object_class, PROP_CAN_MODIFY, - g_param_spec_boolean (NM_CLIENT_CAN_MODIFY, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CAN_MODIFY] = + g_param_spec_boolean (NM_CLIENT_CAN_MODIFY, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:metered: @@ -3824,12 +7773,11 @@ nm_client_class_init (NMClientClass *client_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_METERED, - g_param_spec_uint (NM_CLIENT_METERED, "", "", - 0, G_MAXUINT32, NM_METERED_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_METERED] = + g_param_spec_uint (NM_CLIENT_METERED, "", "", + 0, G_MAXUINT32, NM_METERED_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:dns-mode: @@ -3838,12 +7786,11 @@ nm_client_class_init (NMClientClass *client_class) * * Since: 1.6 **/ - g_object_class_install_property - (object_class, PROP_DNS_MODE, - g_param_spec_string (NM_CLIENT_DNS_MODE, "", "", - "", - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DNS_MODE] = + g_param_spec_string (NM_CLIENT_DNS_MODE, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:dns-rc-manager: @@ -3852,12 +7799,11 @@ nm_client_class_init (NMClientClass *client_class) * * Since: 1.6 **/ - g_object_class_install_property - (object_class, PROP_DNS_RC_MANAGER, - g_param_spec_string (NM_CLIENT_DNS_RC_MANAGER, "", "", - "", - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DNS_RC_MANAGER] = + g_param_spec_string (NM_CLIENT_DNS_RC_MANAGER, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:dns-configuration: (type GPtrArray(NMDnsEntry)) @@ -3867,12 +7813,11 @@ nm_client_class_init (NMClientClass *client_class) * * Since: 1.6 **/ - g_object_class_install_property - (object_class, PROP_DNS_CONFIGURATION, - g_param_spec_boxed (NM_CLIENT_DNS_CONFIGURATION, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DNS_CONFIGURATION] = + g_param_spec_boxed (NM_CLIENT_DNS_CONFIGURATION, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMClient:checkpoints: (type GPtrArray(NMCheckpoint)) @@ -3881,14 +7826,15 @@ nm_client_class_init (NMClientClass *client_class) * * Since: 1.12 */ - g_object_class_install_property - (object_class, PROP_CHECKPOINTS, - g_param_spec_boxed (NM_MANAGER_CHECKPOINTS, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CHECKPOINTS] = + g_param_spec_boxed (NM_CLIENT_CHECKPOINTS, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); - /* signals */ + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm, + &_nml_dbus_meta_iface_nm_settings, + &_nml_dbus_meta_iface_nm_dnsmanager); /** * NMClient::device-added: @@ -3899,13 +7845,12 @@ nm_client_class_init (NMClientClass *client_class) * placeholder devices. **/ signals[DEVICE_ADDED] = - g_signal_new (NM_CLIENT_DEVICE_ADDED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, device_added), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); + g_signal_new (NM_CLIENT_DEVICE_ADDED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); /** * NMClient::device-removed: @@ -3916,13 +7861,12 @@ nm_client_class_init (NMClientClass *client_class) * placeholder devices. **/ signals[DEVICE_REMOVED] = - g_signal_new (NM_CLIENT_DEVICE_REMOVED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, device_removed), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); + g_signal_new (NM_CLIENT_DEVICE_REMOVED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); /** * NMClient::any-device-added: @@ -3933,13 +7877,12 @@ nm_client_class_init (NMClientClass *client_class) * regular devices and placeholder devices. **/ signals[ANY_DEVICE_ADDED] = - g_signal_new (NM_CLIENT_ANY_DEVICE_ADDED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, any_device_added), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); + g_signal_new (NM_CLIENT_ANY_DEVICE_ADDED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); /** * NMClient::any-device-removed: @@ -3950,13 +7893,12 @@ nm_client_class_init (NMClientClass *client_class) * regular devices and placeholder devices. **/ signals[ANY_DEVICE_REMOVED] = - g_signal_new (NM_CLIENT_ANY_DEVICE_REMOVED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, any_device_removed), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); + g_signal_new (NM_CLIENT_ANY_DEVICE_REMOVED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); /** * NMClient::permission-changed: @@ -3967,11 +7909,11 @@ nm_client_class_init (NMClientClass *client_class) * Notifies that a permission has changed **/ signals[PERMISSION_CHANGED] = - g_signal_new (NM_CLIENT_PERMISSION_CHANGED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); + g_signal_new (NM_CLIENT_PERMISSION_CHANGED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); /** * NMClient::connection-added: * @client: the settings object that received the signal @@ -3980,13 +7922,12 @@ nm_client_class_init (NMClientClass *client_class) * Notifies that a #NMConnection has been added. **/ signals[CONNECTION_ADDED] = - g_signal_new (NM_CLIENT_CONNECTION_ADDED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, connection_added), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - NM_TYPE_REMOTE_CONNECTION); + g_signal_new (NM_CLIENT_CONNECTION_ADDED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 1, + NM_TYPE_REMOTE_CONNECTION); /** * NMClient::connection-removed: @@ -3996,13 +7937,12 @@ nm_client_class_init (NMClientClass *client_class) * Notifies that a #NMConnection has been removed. **/ signals[CONNECTION_REMOVED] = - g_signal_new (NM_CLIENT_CONNECTION_REMOVED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, connection_removed), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - NM_TYPE_REMOTE_CONNECTION); + g_signal_new (NM_CLIENT_CONNECTION_REMOVED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 1, + NM_TYPE_REMOTE_CONNECTION); /** * NMClient::active-connection-added: @@ -4012,12 +7952,12 @@ nm_client_class_init (NMClientClass *client_class) * Notifies that a #NMActiveConnection has been added. **/ signals[ACTIVE_CONNECTION_ADDED] = - g_signal_new (NM_CLIENT_ACTIVE_CONNECTION_ADDED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 1, - NM_TYPE_ACTIVE_CONNECTION); + g_signal_new (NM_CLIENT_ACTIVE_CONNECTION_ADDED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 1, + NM_TYPE_ACTIVE_CONNECTION); /** * NMClient::active-connection-removed: @@ -4027,12 +7967,12 @@ nm_client_class_init (NMClientClass *client_class) * Notifies that a #NMActiveConnection has been removed. **/ signals[ACTIVE_CONNECTION_REMOVED] = - g_signal_new (NM_CLIENT_ACTIVE_CONNECTION_REMOVED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 1, - NM_TYPE_ACTIVE_CONNECTION); + g_signal_new (NM_CLIENT_ACTIVE_CONNECTION_REMOVED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 1, + NM_TYPE_ACTIVE_CONNECTION); } static void diff --git a/libnm/nm-client.h b/libnm/nm-client.h index ec7022ff..ad17bf38 100644 --- a/libnm/nm-client.h +++ b/libnm/nm-client.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2014 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2014 Red Hat, Inc. */ #ifndef __NM_CLIENT_H__ @@ -36,21 +22,35 @@ G_BEGIN_DECLS #define NM_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_CLIENT)) #define NM_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CLIENT, NMClientClass)) -#define NM_CLIENT_VERSION "version" -#define NM_CLIENT_STATE "state" -#define NM_CLIENT_STARTUP "startup" -#define NM_CLIENT_NM_RUNNING "nm-running" +#define NM_CLIENT_VERSION "version" +#define NM_CLIENT_STATE "state" +#define NM_CLIENT_STARTUP "startup" +#define NM_CLIENT_NM_RUNNING "nm-running" +#define NM_CLIENT_DBUS_CONNECTION "dbus-connection" +#define NM_CLIENT_DBUS_NAME_OWNER "dbus-name-owner" + +_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY #define NM_CLIENT_NETWORKING_ENABLED "networking-enabled" + +_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY #define NM_CLIENT_WIRELESS_ENABLED "wireless-enabled" -#define NM_CLIENT_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled" +_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY #define NM_CLIENT_WWAN_ENABLED "wwan-enabled" -#define NM_CLIENT_WWAN_HARDWARE_ENABLED "wwan-hardware-enabled" +_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY #define NM_CLIENT_WIMAX_ENABLED "wimax-enabled" + +#define NM_CLIENT_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled" +#define NM_CLIENT_WWAN_HARDWARE_ENABLED "wwan-hardware-enabled" #define NM_CLIENT_WIMAX_HARDWARE_ENABLED "wimax-hardware-enabled" + #define NM_CLIENT_ACTIVE_CONNECTIONS "active-connections" #define NM_CLIENT_CONNECTIVITY "connectivity" +#define NM_CLIENT_CONNECTIVITY_CHECK_URI "connectivity-check-uri" #define NM_CLIENT_CONNECTIVITY_CHECK_AVAILABLE "connectivity-check-available" + +_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY #define NM_CLIENT_CONNECTIVITY_CHECK_ENABLED "connectivity-check-enabled" + #define NM_CLIENT_PRIMARY_CONNECTION "primary-connection" #define NM_CLIENT_ACTIVATING_CONNECTION "activating-connection" #define NM_CLIENT_DEVICES "devices" @@ -62,6 +62,7 @@ G_BEGIN_DECLS #define NM_CLIENT_DNS_MODE "dns-mode" #define NM_CLIENT_DNS_RC_MANAGER "dns-rc-manager" #define NM_CLIENT_DNS_CONFIGURATION "dns-configuration" +#define NM_CLIENT_CHECKPOINTS "checkpoints" #define NM_CLIENT_DEVICE_ADDED "device-added" #define NM_CLIENT_DEVICE_REMOVED "device-removed" @@ -200,27 +201,7 @@ gboolean nm_dns_entry_get_vpn (NMDnsEntry *entry); /** * NMClient: */ -struct _NMClient { - GObject parent; -}; - -typedef struct { - GObjectClass parent; - - /* Signals */ - void (*device_added) (NMClient *client, NMDevice *device); - void (*device_removed) (NMClient *client, NMDevice *device); - void (*any_device_added) (NMClient *client, NMDevice *device); - void (*any_device_removed) (NMClient *client, NMDevice *device); - void (*permission_changed) (NMClient *client, - NMClientPermission permission, - NMClientPermissionResult result); - void (*connection_added) (NMClient *client, NMRemoteConnection *connection); - void (*connection_removed) (NMClient *client, NMRemoteConnection *connection); - - /*< private >*/ - gpointer padding[6]; -} NMClientClass; +typedef struct _NMClientClass NMClientClass; GType nm_client_get_type (void); @@ -233,26 +214,55 @@ void nm_client_new_async (GCancellable *cancellable, NMClient *nm_client_new_finish (GAsyncResult *result, GError **error); +NM_AVAILABLE_IN_1_22 +GDBusConnection *nm_client_get_dbus_connection (NMClient *client); + +NM_AVAILABLE_IN_1_22 +GMainContext *nm_client_get_main_context (NMClient *self); + +NM_AVAILABLE_IN_1_22 +GObject *nm_client_get_context_busy_watcher (NMClient *self); + +NM_AVAILABLE_IN_1_22 +const char *nm_client_get_dbus_name_owner (NMClient *client); + const char *nm_client_get_version (NMClient *client); NMState nm_client_get_state (NMClient *client); gboolean nm_client_get_startup (NMClient *client); gboolean nm_client_get_nm_running (NMClient *client); +NM_AVAILABLE_IN_1_22 +NMMetered nm_client_get_metered (NMClient *client); + gboolean nm_client_networking_get_enabled (NMClient *client); + +_NM_DEPRECATED_SYNC_METHOD gboolean nm_client_networking_set_enabled (NMClient *client, gboolean enabled, GError **error); gboolean nm_client_wireless_get_enabled (NMClient *client); + +_NM_DEPRECATED_SYNC_METHOD void nm_client_wireless_set_enabled (NMClient *client, gboolean enabled); + gboolean nm_client_wireless_hardware_get_enabled (NMClient *client); gboolean nm_client_wwan_get_enabled (NMClient *client); + +_NM_DEPRECATED_SYNC_METHOD void nm_client_wwan_set_enabled (NMClient *client, gboolean enabled); + gboolean nm_client_wwan_hardware_get_enabled (NMClient *client); +NM_DEPRECATED_IN_1_22 gboolean nm_client_wimax_get_enabled (NMClient *client); + +NM_DEPRECATED_IN_1_22 +_NM_DEPRECATED_SYNC_METHOD void nm_client_wimax_set_enabled (NMClient *client, gboolean enabled); + +NM_DEPRECATED_IN_1_22 gboolean nm_client_wimax_hardware_get_enabled (NMClient *client); NM_AVAILABLE_IN_1_10 @@ -262,16 +272,20 @@ NM_AVAILABLE_IN_1_10 gboolean nm_client_connectivity_check_get_enabled (NMClient *client); NM_AVAILABLE_IN_1_10 +_NM_DEPRECATED_SYNC_METHOD void nm_client_connectivity_check_set_enabled (NMClient *client, gboolean enabled); NM_AVAILABLE_IN_1_20 const char *nm_client_connectivity_check_get_uri (NMClient *client); +_NM_DEPRECATED_SYNC_METHOD gboolean nm_client_get_logging (NMClient *client, char **level, char **domains, GError **error); + +_NM_DEPRECATED_SYNC_METHOD gboolean nm_client_set_logging (NMClient *client, const char *level, const char *domains, @@ -282,9 +296,12 @@ NMClientPermissionResult nm_client_get_permission_result (NMClient *client, NMConnectivityState nm_client_get_connectivity (NMClient *client); +_NM_DEPRECATED_SYNC_METHOD +NM_DEPRECATED_IN_1_22 NMConnectivityState nm_client_check_connectivity (NMClient *client, GCancellable *cancellable, GError **error); + void nm_client_check_connectivity_async (NMClient *client, GCancellable *cancellable, GAsyncReadyCallback callback, @@ -293,10 +310,12 @@ NMConnectivityState nm_client_check_connectivity_finish (NMClient *client, GAsyncResult *result, GError **error); +_NM_DEPRECATED_SYNC_METHOD gboolean nm_client_save_hostname (NMClient *client, const char *hostname, GCancellable *cancellable, GError **error); + void nm_client_save_hostname_async (NMClient *client, const char *hostname, GCancellable *cancellable, @@ -358,10 +377,12 @@ NMActiveConnection *nm_client_add_and_activate_connection2_finish (NMClient *cli GVariant **out_result, GError **error); +_NM_DEPRECATED_SYNC_METHOD gboolean nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active, GCancellable *cancellable, GError **error); + void nm_client_deactivate_connection_async (NMClient *client, NMActiveConnection *active, GCancellable *cancellable, @@ -405,11 +426,13 @@ NMRemoteConnection *nm_client_add_connection2_finish (NMClient *client, GVariant **out_result, GError **error); +_NM_DEPRECATED_SYNC_METHOD gboolean nm_client_load_connections (NMClient *client, char **filenames, char ***failures, GCancellable *cancellable, GError **error); + void nm_client_load_connections_async (NMClient *client, char **filenames, GCancellable *cancellable, @@ -420,9 +443,11 @@ gboolean nm_client_load_connections_finish (NMClient *client, GAsyncResult *result, GError **error); +_NM_DEPRECATED_SYNC_METHOD gboolean nm_client_reload_connections (NMClient *client, GCancellable *cancellable, GError **error); + void nm_client_reload_connections_async (NMClient *client, GCancellable *cancellable, GAsyncReadyCallback callback, @@ -489,6 +514,17 @@ gboolean nm_client_checkpoint_adjust_rollback_timeout_finish (NMClient *client, GAsyncResult *result, GError **error); +NM_AVAILABLE_IN_1_22 +void nm_client_reload (NMClient *client, + NMManagerReloadFlags flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +NM_AVAILABLE_IN_1_22 +gboolean nm_client_reload_finish (NMClient *client, + GAsyncResult *result, + GError **error); + G_END_DECLS #endif /* __NM_CLIENT_H__ */ diff --git a/libnm/nm-dbus-helpers.c b/libnm/nm-dbus-helpers.c index e8cf0436..a27b7e86 100644 --- a/libnm/nm-dbus-helpers.c +++ b/libnm/nm-dbus-helpers.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2013 Red Hat, Inc. + * Copyright (C) 2013 Red Hat, Inc. */ #include "nm-default.h" @@ -23,137 +9,22 @@ #include "nm-dbus-interface.h" -static GBusType nm_bus = G_BUS_TYPE_SYSTEM; - GBusType _nm_dbus_bus_type (void) { - static gsize init_value = 0; + static volatile int bus_type = G_BUS_TYPE_NONE; + int v; - if (g_once_init_enter (&init_value)) { + v = g_atomic_int_get (&bus_type); + if (G_UNLIKELY (v == G_BUS_TYPE_NONE)) { + v = G_BUS_TYPE_SYSTEM; if (g_getenv ("LIBNM_USE_SESSION_BUS")) - nm_bus = G_BUS_TYPE_SESSION; - - g_once_init_leave (&init_value, 1); + v = G_BUS_TYPE_SESSION; + if (!g_atomic_int_compare_and_exchange (&bus_type, G_BUS_TYPE_NONE, v)) + v = g_atomic_int_get (&bus_type); + nm_assert (v != G_BUS_TYPE_NONE); } - - return nm_bus; -} - -GDBusConnection * -_nm_dbus_new_connection (GCancellable *cancellable, GError **error) -{ - return g_bus_get_sync (_nm_dbus_bus_type (), cancellable, error); -} - -static void -new_connection_async_got_system (GObject *source, GAsyncResult *result, gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GDBusConnection *connection; - GError *error = NULL; - - connection = g_bus_get_finish (result, &error); - if (connection) - g_simple_async_result_set_op_res_gpointer (simple, connection, g_object_unref); - else - g_simple_async_result_take_error (simple, error); - - g_simple_async_result_complete (simple); - g_object_unref (simple); -} - -void -_nm_dbus_new_connection_async (GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - - simple = g_simple_async_result_new (NULL, callback, user_data, _nm_dbus_new_connection_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - g_bus_get (_nm_dbus_bus_type (), - cancellable, - new_connection_async_got_system, simple); -} - -GDBusConnection * -_nm_dbus_new_connection_finish (GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return NULL; - - return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); -} - -gboolean -_nm_dbus_is_connection_private (GDBusConnection *connection) -{ - return g_dbus_connection_get_unique_name (connection) == NULL; -} - -/* D-Bus has an upper limit on number of Match rules and it's rather easy - * to hit as the proxy likes to add one for each object. Let's remove the Match - * rule the proxy added and ensure a less granular rule is present instead. - * - * Also, don't do this immediately since it has a performance penalty. - * Still better than losing the signals altogether. - * - * Ideally, we should be able to tell glib not to hook its rules: - * https://bugzilla.gnome.org/show_bug.cgi?id=758749 - */ -void -_nm_dbus_proxy_replace_match (GDBusProxy *proxy) -{ - GDBusConnection *connection = g_dbus_proxy_get_connection (proxy); - static unsigned match_counter = 1024; - char *match; - - if (match_counter == 1) { - /* If we hit the low matches watermark, install a - * less granular one. */ - g_dbus_connection_call (connection, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus", - "AddMatch", - g_variant_new ("(s)", "type='signal',sender='" NM_DBUS_SERVICE "'"), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - NULL, - NULL); - } - - if (match_counter) - match_counter--; - if (match_counter) - return; - - /* Remove what this proxy added. */ - match = g_strdup_printf ("type='signal',sender='" NM_DBUS_SERVICE "'," - "interface='%s',path='%s'", - g_dbus_proxy_get_interface_name (proxy), - g_dbus_proxy_get_object_path (proxy)); - g_dbus_connection_call (connection, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus", - "RemoveMatch", - g_variant_new ("(s)", match), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - NULL, - NULL); - g_free (match); + return v; } /* Binds the properties on a generated server-side GDBus object to the diff --git a/libnm/nm-dbus-helpers.h b/libnm/nm-dbus-helpers.h index a3bd9b47..f83f2b0d 100644 --- a/libnm/nm-dbus-helpers.h +++ b/libnm/nm-dbus-helpers.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2013 Red Hat, Inc. + * Copyright (C) 2013 Red Hat, Inc. */ #ifndef __NM_DBUS_HELPERS_PRIVATE_H__ @@ -26,20 +12,9 @@ #include "nm-std-aux/nm-dbus-compat.h" -GBusType _nm_dbus_bus_type (void); - -GDBusConnection *_nm_dbus_new_connection (GCancellable *cancellable, - GError **error); - -void _nm_dbus_new_connection_async (GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -GDBusConnection *_nm_dbus_new_connection_finish (GAsyncResult *result, - GError **error); +#define NM_DBUS_DEFAULT_TIMEOUT_MSEC 25000 -gboolean _nm_dbus_is_connection_private (GDBusConnection *connection); - -void _nm_dbus_proxy_replace_match (GDBusProxy *proxy); +GBusType _nm_dbus_bus_type (void); void _nm_dbus_bind_properties (gpointer object, gpointer skeleton); diff --git a/libnm/nm-device-6lowpan.c b/libnm/nm-device-6lowpan.c index 9a305d26..5899df30 100644 --- a/libnm/nm-device-6lowpan.c +++ b/libnm/nm-device-6lowpan.c @@ -1,54 +1,40 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 Red Hat, Inc. + * Copyright (C) 2018 Red Hat, Inc. */ #include "nm-default.h" #include "nm-device-6lowpan.h" + #include "nm-object-private.h" +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_PARENT, + PROP_HW_ADDRESS, +); + typedef struct { - NMDevice *parent; + NMLDBusPropertyO parent; char *hw_address; } NMDevice6LowpanPrivate; -/** - * NMDevice6Lowpan: - */ struct _NMDevice6Lowpan { - NMDevice parent; + NMDevice parent; + NMDevice6LowpanPrivate _priv; }; -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDevice6LowpanClass; +struct _NMDevice6LowpanClass { + NMDeviceClass parent; +}; G_DEFINE_TYPE (NMDevice6Lowpan, nm_device_6lowpan, NM_TYPE_DEVICE) -#define NM_DEVICE_6LOWPAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_6LOWPAN, NMDevice6LowpanPrivate)) +#define NM_DEVICE_6LOWPAN_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDevice6Lowpan, NM_IS_DEVICE_6LOWPAN, NMObject, NMDevice) -NM_GOBJECT_PROPERTIES_DEFINE_BASE ( - PROP_PARENT, - PROP_HW_ADDRESS, -); +/*****************************************************************************/ /** * nm_device_6lowpan_get_parent: @@ -63,7 +49,7 @@ nm_device_6lowpan_get_parent (NMDevice6Lowpan *device) { g_return_val_if_fail (NM_IS_DEVICE_6LOWPAN (device), NULL); - return NM_DEVICE_6LOWPAN_GET_PRIVATE (device)->parent; + return nml_dbus_property_o_get_obj (&NM_DEVICE_6LOWPAN_GET_PRIVATE (device)->parent); } /** @@ -91,7 +77,7 @@ get_hw_address (NMDevice *device) return nm_device_6lowpan_get_hw_address (NM_DEVICE_6LOWPAN (device)); } -/***********************************************************/ +/*****************************************************************************/ static void nm_device_6lowpan_init (NMDevice6Lowpan *device) @@ -99,31 +85,13 @@ nm_device_6lowpan_init (NMDevice6Lowpan *device) } static void -init_dbus (NMObject *object) +dispose (GObject *object) { NMDevice6LowpanPrivate *priv = NM_DEVICE_6LOWPAN_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_6LOWPAN_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE }, - { NM_DEVICE_6LOWPAN_HW_ADDRESS, &priv->hw_address }, - { NULL }, - }; - NM_OBJECT_CLASS (nm_device_6lowpan_parent_class)->init_dbus (object); + G_OBJECT_CLASS (nm_device_6lowpan_parent_class)->dispose (object); - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_6LOWPAN, - property_info); -} - -static void -finalize (GObject *object) -{ - NMDevice6LowpanPrivate *priv = NM_DEVICE_6LOWPAN_GET_PRIVATE (object); - - g_free (priv->hw_address); - g_clear_object (&priv->parent); - - G_OBJECT_CLASS (nm_device_6lowpan_parent_class)->finalize (object); + nm_clear_g_free (&priv->hw_address); } static void @@ -147,6 +115,16 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_lowpan = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_6LOWPAN, + nm_device_6lowpan_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDevice6Lowpan, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDevice6Lowpan, _priv.parent, nm_device_get_type ), + ), +); + static void nm_device_6lowpan_class_init (NMDevice6LowpanClass *klass) { @@ -154,12 +132,12 @@ nm_device_6lowpan_class_init (NMDevice6LowpanClass *klass) NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - g_type_class_add_private (klass, sizeof (NMDevice6LowpanPrivate)); - - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->dispose = dispose; + + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDevice6Lowpan); - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDevice6LowpanPrivate, parent); device_class->get_hw_address = get_hw_address; @@ -171,10 +149,10 @@ nm_device_6lowpan_class_init (NMDevice6LowpanClass *klass) * Since: 1.14 **/ obj_properties[PROP_PARENT] = - g_param_spec_object (NM_DEVICE_6LOWPAN_PARENT, "", "", - NM_TYPE_DEVICE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_object (NM_DEVICE_6LOWPAN_PARENT, "", "", + NM_TYPE_DEVICE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice6Lowpan:hw-address: @@ -184,10 +162,10 @@ nm_device_6lowpan_class_init (NMDevice6LowpanClass *klass) * Since: 1.14 **/ obj_properties[PROP_HW_ADDRESS] = - g_param_spec_string (NM_DEVICE_6LOWPAN_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_string (NM_DEVICE_6LOWPAN_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); - g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_lowpan); } diff --git a/libnm/nm-device-6lowpan.h b/libnm/nm-device-6lowpan.h index 96f34dc3..eba4886e 100644 --- a/libnm/nm-device-6lowpan.h +++ b/libnm/nm-device-6lowpan.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 Red Hat, Inc. + * Copyright (C) 2018 Red Hat, Inc. */ #ifndef __NM_DEVICE_6LOWPAN_H__ @@ -38,6 +24,11 @@ G_BEGIN_DECLS #define NM_DEVICE_6LOWPAN_PARENT "parent" #define NM_DEVICE_6LOWPAN_HW_ADDRESS "hw-address" +/** + * NMDevice6Lowpan: + */ +typedef struct _NMDevice6LowpanClass NMDevice6LowpanClass; + NM_AVAILABLE_IN_1_14 GType nm_device_6lowpan_get_type (void); diff --git a/libnm/nm-device-adsl.c b/libnm/nm-device-adsl.c index 95871efa..56ab49ed 100644 --- a/libnm/nm-device-adsl.c +++ b/libnm/nm-device-adsl.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * author: Pantelis Koukousoulas <pktoss@gmail.com> - * Copyright 2009 - 2011 Red Hat, Inc. + * Author: Pantelis Koukousoulas <pktoss@gmail.com> + * Copyright (C) 2009 - 2011 Red Hat, Inc. */ #include "nm-default.h" @@ -26,21 +12,31 @@ #include "nm-setting-adsl.h" #include "nm-setting-connection.h" -G_DEFINE_TYPE (NMDeviceAdsl, nm_device_adsl, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_ADSL, NMDeviceAdslPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_CARRIER, +); typedef struct { - gboolean carrier; - + bool carrier; } NMDeviceAdslPrivate; -enum { - PROP_0, - PROP_CARRIER, - LAST_PROP +struct _NMDeviceAdsl { + NMDevice parent; + NMDeviceAdslPrivate _priv; +}; + +struct _NMDeviceAdslClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceAdsl, nm_device_adsl, NM_TYPE_DEVICE) + +#define NM_DEVICE_ADSL_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceAdsl, NM_IS_DEVICE_ADSL, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_adsl_get_carrier: * @device: a #NMDeviceAdsl @@ -86,22 +82,6 @@ nm_device_adsl_init (NMDeviceAdsl *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_ADSL_CARRIER, &priv->carrier }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_adsl_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_ADSL, - property_info); -} - -static void get_property (GObject *object, guint prop_id, GValue *value, @@ -119,33 +99,36 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_adsl = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_ADSL, + nm_device_adsl_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceAdsl, _priv.carrier), + ), +); + static void nm_device_adsl_class_init (NMDeviceAdslClass *adsl_class) { GObjectClass *object_class = G_OBJECT_CLASS (adsl_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (adsl_class); NMDeviceClass *device_class = NM_DEVICE_CLASS (adsl_class); - g_type_class_add_private (object_class, sizeof (NMDeviceAdslPrivate)); - - /* virtual methods */ object_class->get_property = get_property; - nm_object_class->init_dbus = init_dbus; - device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; + device_class->get_setting_type = get_setting_type; - /* properties */ /** * NMDeviceAdsl:carrier: * * Whether the device has carrier. **/ - g_object_class_install_property - (object_class, PROP_CARRIER, - g_param_spec_boolean (NM_DEVICE_ADSL_CARRIER, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CARRIER] = + g_param_spec_boolean (NM_DEVICE_ADSL_CARRIER, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_adsl); } diff --git a/libnm/nm-device-adsl.h b/libnm/nm-device-adsl.h index ab61a650..9315cae1 100644 --- a/libnm/nm-device-adsl.h +++ b/libnm/nm-device-adsl.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2011 Pantelis Koukousoulas <pktoss@gmail.com> + * Copyright (C) 2011 Pantelis Koukousoulas <pktoss@gmail.com> */ #ifndef __NM_DEVICE_ADSL_H__ @@ -40,16 +26,7 @@ G_BEGIN_DECLS /** * NMDeviceAdsl: */ -struct _NMDeviceAdsl { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceAdslClass; +typedef struct _NMDeviceAdslClass NMDeviceAdslClass; GType nm_device_adsl_get_type (void); diff --git a/libnm/nm-device-bond.c b/libnm/nm-device-bond.c index 10e4ebd2..66c1bf83 100644 --- a/libnm/nm-device-bond.c +++ b/libnm/nm-device-bond.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2012 Red Hat, Inc. + * Copyright (C) 2012 Red Hat, Inc. */ #include "nm-default.h" @@ -27,25 +13,35 @@ #include "nm-object-private.h" #include "nm-core-internal.h" -G_DEFINE_TYPE (NMDeviceBond, nm_device_bond, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BOND, NMDeviceBondPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, + PROP_CARRIER, + PROP_SLAVES, +); typedef struct { + NMLDBusPropertyAO slaves; char *hw_address; - gboolean carrier; - GPtrArray *slaves; + bool carrier; } NMDeviceBondPrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, - PROP_CARRIER, - PROP_SLAVES, +struct _NMDeviceBond { + NMDevice parent; + NMDeviceBondPrivate _priv; +}; - LAST_PROP +struct _NMDeviceBondClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceBond, nm_device_bond, NM_TYPE_DEVICE) + +#define NM_DEVICE_BOND_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceBond, NM_IS_DEVICE_BOND, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_bond_get_hw_address: * @device: a #NMDeviceBond @@ -60,7 +56,7 @@ nm_device_bond_get_hw_address (NMDeviceBond *device) { g_return_val_if_fail (NM_IS_DEVICE_BOND (device), NULL); - return nm_str_not_empty (NM_DEVICE_BOND_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_BOND_GET_PRIVATE (device)->hw_address); } /** @@ -94,7 +90,7 @@ nm_device_bond_get_slaves (NMDeviceBond *device) { g_return_val_if_fail (NM_IS_DEVICE_BOND (device), FALSE); - return NM_DEVICE_BOND_GET_PRIVATE (device)->slaves; + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_BOND_GET_PRIVATE (device)->slaves); } static gboolean @@ -131,37 +127,6 @@ get_hw_address (NMDevice *device) static void nm_device_bond_init (NMDeviceBond *device) { - NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (device); - - priv->slaves = g_ptr_array_new (); -} - -static void -init_dbus (NMObject *object) -{ - NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_BOND_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_BOND_CARRIER, &priv->carrier }, - { NM_DEVICE_BOND_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_bond_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_BOND, - property_info); -} - -static void -dispose (GObject *object) -{ - NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (object); - - g_clear_pointer (&priv->slaves, g_ptr_array_unref); - - G_OBJECT_CLASS (nm_device_bond_parent_class)->dispose (object); } static void @@ -198,61 +163,67 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bond = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_BOND, + nm_device_bond_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceBond, _priv.carrier ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceBond, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Slaves", PROP_SLAVES, NMDeviceBond, _priv.slaves, nm_device_get_type ), + ), +); + static void -nm_device_bond_class_init (NMDeviceBondClass *bond_class) +nm_device_bond_class_init (NMDeviceBondClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (bond_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (bond_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (bond_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - g_type_class_add_private (bond_class, sizeof (NMDeviceBondPrivate)); - - /* virtual methods */ - object_class->dispose = dispose; - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceBond); - device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; + _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceBondPrivate, slaves); - /* properties */ + device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceBond:hw-address: * * The hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_BOND_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_BOND_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceBond:carrier: * * Whether the device has carrier. **/ - g_object_class_install_property - (object_class, PROP_CARRIER, - g_param_spec_boolean (NM_DEVICE_BOND_CARRIER, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CARRIER] = + g_param_spec_boolean (NM_DEVICE_BOND_CARRIER, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceBond:slaves: (type GPtrArray(NMDevice)) * * The devices enslaved to the bond device. **/ - g_object_class_install_property - (object_class, PROP_SLAVES, - g_param_spec_boxed (NM_DEVICE_BOND_SLAVES, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_SLAVES] = + g_param_spec_boxed (NM_DEVICE_BOND_SLAVES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_bond); } diff --git a/libnm/nm-device-bond.h b/libnm/nm-device-bond.h index 658eb5e7..a65f88f9 100644 --- a/libnm/nm-device-bond.h +++ b/libnm/nm-device-bond.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2012 Red Hat, Inc. + * Copyright (C) 2012 Red Hat, Inc. */ #ifndef __NM_DEVICE_BOND_H__ @@ -42,16 +28,7 @@ G_BEGIN_DECLS /** * NMDeviceBond: */ -struct _NMDeviceBond { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceBondClass; +typedef struct _NMDeviceBondClass NMDeviceBondClass; GType nm_device_bond_get_type (void); diff --git a/libnm/nm-device-bridge.c b/libnm/nm-device-bridge.c index 44cf8a8e..f50054d4 100644 --- a/libnm/nm-device-bridge.c +++ b/libnm/nm-device-bridge.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2012 Red Hat, Inc. + * Copyright (C) 2012 Red Hat, Inc. */ #include "nm-default.h" @@ -27,25 +13,35 @@ #include "nm-object-private.h" #include "nm-core-internal.h" -G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgePrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, + PROP_CARRIER, + PROP_SLAVES, +); typedef struct { + NMLDBusPropertyAO slaves; char *hw_address; - gboolean carrier; - GPtrArray *slaves; + bool carrier; } NMDeviceBridgePrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, - PROP_CARRIER, - PROP_SLAVES, +struct _NMDeviceBridge { + NMDevice parent; + NMDeviceBridgePrivate _priv; +}; - LAST_PROP +struct _NMDeviceBridgeClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE) + +#define NM_DEVICE_BRIDGE_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceBridge, NM_IS_DEVICE_BRIDGE, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_bridge_get_hw_address: * @device: a #NMDeviceBridge @@ -60,7 +56,7 @@ nm_device_bridge_get_hw_address (NMDeviceBridge *device) { g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), NULL); - return nm_str_not_empty (NM_DEVICE_BRIDGE_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_BRIDGE_GET_PRIVATE (device)->hw_address); } /** @@ -94,7 +90,7 @@ nm_device_bridge_get_slaves (NMDeviceBridge *device) { g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE); - return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves; + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves); } static gboolean @@ -136,37 +132,6 @@ get_hw_address (NMDevice *device) static void nm_device_bridge_init (NMDeviceBridge *device) { - NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (device); - - priv->slaves = g_ptr_array_new (); -} - -static void -init_dbus (NMObject *object) -{ - NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_BRIDGE_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_BRIDGE_CARRIER, &priv->carrier }, - { NM_DEVICE_BRIDGE_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_bridge_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_BRIDGE, - property_info); -} - -static void -dispose (GObject *object) -{ - NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object); - - g_clear_pointer (&priv->slaves, g_ptr_array_unref); - - G_OBJECT_CLASS (nm_device_bridge_parent_class)->dispose (object); } static void @@ -203,61 +168,67 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bridge = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_BRIDGE, + nm_device_bridge_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceBridge, _priv.carrier ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceBridge, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Slaves", PROP_SLAVES, NMDeviceBridge, _priv.slaves, nm_device_get_type ), + ), +); + static void -nm_device_bridge_class_init (NMDeviceBridgeClass *bridge_class) +nm_device_bridge_class_init (NMDeviceBridgeClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (bridge_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (bridge_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (bridge_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - g_type_class_add_private (bridge_class, sizeof (NMDeviceBridgePrivate)); - - /* virtual methods */ - object_class->dispose = dispose; - object_class->finalize = finalize; + object_class->finalize = finalize; object_class->get_property = get_property; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceBridge); - device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; + _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceBridgePrivate, slaves); - /* properties */ + device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceBridge:hw-address: * * The hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_BRIDGE_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_BRIDGE_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceBridge:carrier: * * Whether the device has carrier. **/ - g_object_class_install_property - (object_class, PROP_CARRIER, - g_param_spec_boolean (NM_DEVICE_BRIDGE_CARRIER, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CARRIER] = + g_param_spec_boolean (NM_DEVICE_BRIDGE_CARRIER, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceBridge:slaves: (type GPtrArray(NMDevice)) * * The devices enslaved to the bridge device. **/ - g_object_class_install_property - (object_class, PROP_SLAVES, - g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_SLAVES] = + g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_bridge); } diff --git a/libnm/nm-device-bridge.h b/libnm/nm-device-bridge.h index 41583a79..339f44dd 100644 --- a/libnm/nm-device-bridge.h +++ b/libnm/nm-device-bridge.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2012 Red Hat, Inc. + * Copyright (C) 2012 Red Hat, Inc. */ #ifndef __NM_DEVICE_BRIDGE_H__ @@ -42,16 +28,7 @@ G_BEGIN_DECLS /** * NMDeviceBridge: */ -struct _NMDeviceBridge { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceBridgeClass; +typedef struct _NMDeviceBridgeClass NMDeviceBridgeClass; GType nm_device_bridge_get_type (void); diff --git a/libnm/nm-device-bt.c b/libnm/nm-device-bt.c index 47a01f4f..150b5d84 100644 --- a/libnm/nm-device-bt.c +++ b/libnm/nm-device-bt.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2012 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2012 Red Hat, Inc. */ #include "nm-default.h" @@ -28,9 +14,13 @@ #include "nm-object-private.h" #include "nm-enum-types.h" -G_DEFINE_TYPE (NMDeviceBt, nm_device_bt, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_BT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BT, NMDeviceBtPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, + PROP_NAME, + PROP_BT_CAPABILITIES, +); typedef struct { char *hw_address; @@ -38,15 +28,21 @@ typedef struct { guint32 bt_capabilities; } NMDeviceBtPrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, - PROP_NAME, - PROP_BT_CAPABILITIES, +struct _NMDeviceBt { + NMDevice parent; + NMDeviceBtPrivate _priv; +}; - LAST_PROP +struct _NMDeviceBtClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceBt, nm_device_bt, NM_TYPE_DEVICE) + +#define NM_DEVICE_BT_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceBt, NM_IS_DEVICE_BT, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_bt_get_hw_address: * @device: a #NMDeviceBt @@ -61,7 +57,7 @@ nm_device_bt_get_hw_address (NMDeviceBt *device) { g_return_val_if_fail (NM_IS_DEVICE_BT (device), NULL); - return nm_str_not_empty (NM_DEVICE_BT_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_BT_GET_PRIVATE (device)->hw_address); } /** @@ -188,24 +184,6 @@ nm_device_bt_init (NMDeviceBt *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_BT_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_BT_NAME, &priv->name }, - { NM_DEVICE_BT_CAPABILITIES, &priv->bt_capabilities }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_bt_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_BLUETOOTH, - property_info); -} - -static void finalize (GObject *object) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object); @@ -240,62 +218,63 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bluetooth = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_BLUETOOTH, + nm_device_bt_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_U ("BtCapabilities", PROP_BT_CAPABILITIES, NMDeviceBt, _priv.bt_capabilities ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceBt, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_S ("Name", PROP_NAME, NMDeviceBt, _priv.name ), + ), +); + static void nm_device_bt_class_init (NMDeviceBtClass *bt_class) { GObjectClass *object_class = G_OBJECT_CLASS (bt_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (bt_class); NMDeviceClass *device_class = NM_DEVICE_CLASS (bt_class); - g_type_class_add_private (bt_class, sizeof (NMDeviceBtPrivate)); - - /* virtual methods */ - object_class->finalize = finalize; object_class->get_property = get_property; - - nm_object_class->init_dbus = init_dbus; + object_class->finalize = finalize; device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; - - /* properties */ + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceBt:hw-address: * * The hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_BT_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_BT_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceBt:name: * * The name of the bluetooth device. **/ - g_object_class_install_property - (object_class, PROP_NAME, - g_param_spec_string (NM_DEVICE_BT_NAME, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_NAME] = + g_param_spec_string (NM_DEVICE_BT_NAME, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceBt:bt-capabilities: * * The device's bluetooth capabilities, a combination of #NMBluetoothCapabilities. **/ - g_object_class_install_property - (object_class, PROP_BT_CAPABILITIES, - g_param_spec_flags (NM_DEVICE_BT_CAPABILITIES, "", "", - NM_TYPE_BLUETOOTH_CAPABILITIES, - NM_BT_CAPABILITY_NONE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - + obj_properties[PROP_BT_CAPABILITIES] = + g_param_spec_flags (NM_DEVICE_BT_CAPABILITIES, "", "", + NM_TYPE_BLUETOOTH_CAPABILITIES, + NM_BT_CAPABILITY_NONE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_bluetooth); } diff --git a/libnm/nm-device-bt.h b/libnm/nm-device-bt.h index 1db0f474..2633c2dc 100644 --- a/libnm/nm-device-bt.h +++ b/libnm/nm-device-bt.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2008 - 2012 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright (C) 2008 - 2012 Red Hat, Inc. + * Copyright (C) 2008 Novell, Inc. */ #ifndef __NM_DEVICE_BT_H__ @@ -43,16 +29,7 @@ G_BEGIN_DECLS /** * NMDeviceBt: */ -struct _NMDeviceBt { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceBtClass; +typedef struct _NMDeviceBtClass NMDeviceBtClass; GType nm_device_bt_get_type (void); diff --git a/libnm/nm-device-dummy.c b/libnm/nm-device-dummy.c index 3148c6a1..4916cc7d 100644 --- a/libnm/nm-device-dummy.c +++ b/libnm/nm-device-dummy.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017 Red Hat, Inc. + * Copyright (C) 2017 Red Hat, Inc. */ #include "nm-default.h" @@ -25,21 +11,29 @@ #include "nm-setting-dummy.h" #include "nm-setting-connection.h" -G_DEFINE_TYPE (NMDeviceDummy, nm_device_dummy, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_DUMMY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_DUMMY, NMDeviceDummyPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, +); typedef struct { char *hw_address; } NMDeviceDummyPrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, +struct _NMDeviceDummy { + NMDevice parent; + NMDeviceDummyPrivate _priv; +}; - LAST_PROP +struct _NMDeviceDummyClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceDummy, nm_device_dummy, NM_TYPE_DEVICE) + +#define NM_DEVICE_DUMMY_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceDummy, NM_IS_DEVICE_DUMMY, NMObject, NMDevice) + /*****************************************************************************/ /** @@ -58,7 +52,7 @@ nm_device_dummy_get_hw_address (NMDeviceDummy *device) { g_return_val_if_fail (NM_IS_DEVICE_DUMMY (device), NULL); - return nm_str_not_empty (NM_DEVICE_DUMMY_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_DUMMY_GET_PRIVATE (device)->hw_address); } static gboolean @@ -105,29 +99,13 @@ nm_device_dummy_init (NMDeviceDummy *device) } static void -init_dbus (NMObject *object) +finalize (GObject *object) { NMDeviceDummyPrivate *priv = NM_DEVICE_DUMMY_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_DUMMY_HW_ADDRESS, &priv->hw_address }, - { NULL }, - }; - NM_OBJECT_CLASS (nm_device_dummy_parent_class)->init_dbus (object); + g_free (priv->hw_address); - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_DUMMY, - property_info); -} - -static void -dispose (GObject *object) -{ - NMDeviceDummyPrivate *priv = NM_DEVICE_DUMMY_GET_PRIVATE (object); - - g_clear_pointer (&priv->hw_address, g_free); - - G_OBJECT_CLASS (nm_device_dummy_parent_class)->dispose (object); + G_OBJECT_CLASS (nm_device_dummy_parent_class)->finalize (object); } static void @@ -148,23 +126,27 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_dummy = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_DUMMY, + nm_device_dummy_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceDummy, _priv.hw_address ), + ), +); + static void nm_device_dummy_class_init (NMDeviceDummyClass *dummy_class) { GObjectClass *object_class = G_OBJECT_CLASS (dummy_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (dummy_class); NMDeviceClass *device_class = NM_DEVICE_CLASS (dummy_class); - g_type_class_add_private (dummy_class, sizeof (NMDeviceDummyPrivate)); - - object_class->dispose = dispose; object_class->get_property = get_property; - - nm_object_class->init_dbus = init_dbus; + object_class->finalize = finalize; device_class->connection_compatible = connection_compatible; - device_class->get_hw_address = get_hw_address; - device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; + device_class->get_setting_type = get_setting_type; /** * NMDeviceDummy:hw-address: @@ -173,10 +155,11 @@ nm_device_dummy_class_init (NMDeviceDummyClass *dummy_class) * * Since: 1.10 **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_DUMMY_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_DUMMY_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_dummy); } diff --git a/libnm/nm-device-dummy.h b/libnm/nm-device-dummy.h index 45b9032d..4b33490c 100644 --- a/libnm/nm-device-dummy.h +++ b/libnm/nm-device-dummy.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017 Red Hat, Inc. + * Copyright (C) 2017 Red Hat, Inc. */ #ifndef __NM_DEVICE_DUMMY_H__ @@ -40,16 +26,7 @@ G_BEGIN_DECLS /** * NMDeviceDummy: */ -struct _NMDeviceDummy { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceDummyClass; +typedef struct _NMDeviceDummyClass NMDeviceDummyClass; GType nm_device_dummy_get_type (void); NM_AVAILABLE_IN_1_10 diff --git a/libnm/nm-device-ethernet.c b/libnm/nm-device-ethernet.c index 0efb1dc4..7cd5b89f 100644 --- a/libnm/nm-device-ethernet.c +++ b/libnm/nm-device-ethernet.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2012 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2012 Red Hat, Inc. */ #include "nm-default.h" @@ -28,29 +14,39 @@ #include "nm-utils.h" #include "nm-object-private.h" -G_DEFINE_TYPE (NMDeviceEthernet, nm_device_ethernet, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_ETHERNET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_ETHERNET, NMDeviceEthernetPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, + PROP_PERM_HW_ADDRESS, + PROP_SPEED, + PROP_CARRIER, + PROP_S390_SUBCHANNELS, +); typedef struct { + char **s390_subchannels; char *hw_address; char *perm_hw_address; guint32 speed; - gboolean carrier; - char **s390_subchannels; + bool carrier; } NMDeviceEthernetPrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, - PROP_PERM_HW_ADDRESS, - PROP_SPEED, - PROP_CARRIER, - PROP_S390_SUBCHANNELS, +struct _NMDeviceEthernet { + NMDevice parent; + NMDeviceEthernetPrivate _priv; +}; - LAST_PROP +struct _NMDeviceEthernetClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceEthernet, nm_device_ethernet, NM_TYPE_DEVICE) + +#define NM_DEVICE_ETHERNET_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceEthernet, NM_IS_DEVICE_ETHERNET, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_ethernet_get_hw_address: * @device: a #NMDeviceEthernet @@ -65,7 +61,7 @@ nm_device_ethernet_get_hw_address (NMDeviceEthernet *device) { g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), NULL); - return nm_str_not_empty (NM_DEVICE_ETHERNET_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_ETHERNET_GET_PRIVATE (device)->hw_address); } /** @@ -82,7 +78,7 @@ nm_device_ethernet_get_permanent_hw_address (NMDeviceEthernet *device) { g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), NULL); - return nm_str_not_empty (NM_DEVICE_ETHERNET_GET_PRIVATE (device)->perm_hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_ETHERNET_GET_PRIVATE (device)->perm_hw_address); } /** @@ -128,24 +124,12 @@ nm_device_ethernet_get_carrier (NMDeviceEthernet *device) * * Since: 1.2 **/ -const char * const * +const char *const* nm_device_ethernet_get_s390_subchannels (NMDeviceEthernet *device) { g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), NULL); - return (const char * const *) NM_DEVICE_ETHERNET_GET_PRIVATE (device)->s390_subchannels; -} - -static guint32 -_subchannels_count_num (const char * const *array) -{ - int i; - - if (!array) - return 0; - for (i = 0; array[i]; i++) - /* NOP */; - return i; + return (const char *const*) NM_DEVICE_ETHERNET_GET_PRIVATE (device)->s390_subchannels; } static gboolean @@ -153,14 +137,14 @@ match_subchans (NMDeviceEthernet *self, NMSettingWired *s_wired, gboolean *try_m { NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self); const char * const *subchans; - guint32 num1, num2; - int i, j; + gsize num1, num2; + gsize i, j; *try_mac = TRUE; subchans = nm_setting_wired_get_s390_subchannels (s_wired); - num1 = _subchannels_count_num (subchans); - num2 = _subchannels_count_num ((const char * const *) priv->s390_subchannels); + num1 = NM_PTRARRAY_LEN (subchans); + num2 = NM_PTRARRAY_LEN (priv->s390_subchannels); /* connection has no subchannels */ if (num1 == 0) return TRUE; @@ -281,26 +265,6 @@ nm_device_ethernet_init (NMDeviceEthernet *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_ETHERNET_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS, &priv->perm_hw_address }, - { NM_DEVICE_ETHERNET_SPEED, &priv->speed }, - { NM_DEVICE_ETHERNET_CARRIER, &priv->carrier }, - { NM_DEVICE_ETHERNET_S390_SUBCHANNELS, &priv->s390_subchannels }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_ethernet_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_WIRED, - property_info); -} - -static void finalize (GObject *object) { NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (object); @@ -343,74 +307,82 @@ get_property (GObject *object, } } +/* TODO: implemented Veth. */ +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_veth = NML_DBUS_META_IFACE_INIT ( + NM_DBUS_INTERFACE_DEVICE_VETH, + NULL, + NML_DBUS_META_INTERFACE_PRIO_NONE, +); + +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wired = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_WIRED, + nm_device_ethernet_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceEthernet, _priv.carrier ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceEthernet, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_S ("PermHwAddress", PROP_PERM_HW_ADDRESS, NMDeviceEthernet, _priv.perm_hw_address ), + NML_DBUS_META_PROPERTY_INIT_AS ("S390Subchannels", PROP_S390_SUBCHANNELS, NMDeviceEthernet, _priv.s390_subchannels ), + NML_DBUS_META_PROPERTY_INIT_U ("Speed", PROP_SPEED, NMDeviceEthernet, _priv.speed ), + ), +); + static void nm_device_ethernet_class_init (NMDeviceEthernetClass *eth_class) { GObjectClass *object_class = G_OBJECT_CLASS (eth_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (eth_class); NMDeviceClass *device_class = NM_DEVICE_CLASS (eth_class); - g_type_class_add_private (eth_class, sizeof (NMDeviceEthernetPrivate)); - - /* virtual methods */ - object_class->finalize = finalize; object_class->get_property = get_property; - - nm_object_class->init_dbus = init_dbus; + object_class->finalize = finalize; device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; - - /* properties */ + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceEthernet:hw-address: * * The active hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_ETHERNET_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_ETHERNET_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceEthernet:perm-hw-address: * * The permanent hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_PERM_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PERM_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceEthernet:speed: * * The speed of the device. **/ - g_object_class_install_property - (object_class, PROP_SPEED, - g_param_spec_uint (NM_DEVICE_ETHERNET_SPEED, "", "", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_SPEED] = + g_param_spec_uint (NM_DEVICE_ETHERNET_SPEED, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceEthernet:carrier: * * Whether the device has carrier. **/ - g_object_class_install_property - (object_class, PROP_CARRIER, - g_param_spec_boolean (NM_DEVICE_ETHERNET_CARRIER, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CARRIER] = + g_param_spec_boolean (NM_DEVICE_ETHERNET_CARRIER, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceEthernet:s390-subchannels: @@ -420,10 +392,11 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *eth_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_S390_SUBCHANNELS, - g_param_spec_boxed (NM_DEVICE_ETHERNET_S390_SUBCHANNELS, "", "", - G_TYPE_STRV, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_S390_SUBCHANNELS] = + g_param_spec_boxed (NM_DEVICE_ETHERNET_S390_SUBCHANNELS, "", "", + G_TYPE_STRV, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_wired); } diff --git a/libnm/nm-device-ethernet.h b/libnm/nm-device-ethernet.h index 0207aafd..28b95dc2 100644 --- a/libnm/nm-device-ethernet.h +++ b/libnm/nm-device-ethernet.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2012 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2012 Red Hat, Inc. */ #ifndef __NM_DEVICE_ETHERNET_H__ @@ -45,16 +31,7 @@ G_BEGIN_DECLS /** * NMDeviceEthernet: */ -struct _NMDeviceEthernet { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceEthernetClass; +typedef struct _NMDeviceEthernetClass NMDeviceEthernetClass; GType nm_device_ethernet_get_type (void); diff --git a/libnm/nm-device-generic.c b/libnm/nm-device-generic.c index 548334b4..b1c78475 100644 --- a/libnm/nm-device-generic.c +++ b/libnm/nm-device-generic.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2013 Red Hat, Inc. + * Copyright (C) 2013 Red Hat, Inc. */ #include "nm-default.h" @@ -25,23 +11,33 @@ #include "nm-setting-generic.h" #include "nm-setting-connection.h" -G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_GENERIC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_GENERIC, NMDeviceGenericPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, + PROP_TYPE_DESCRIPTION, +); typedef struct { char *hw_address; char *type_description; } NMDeviceGenericPrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, - PROP_TYPE_DESCRIPTION, +struct _NMDeviceGeneric { + NMDevice parent; + NMDeviceGenericPrivate _priv; +}; - LAST_PROP +struct _NMDeviceGenericClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE) + +#define NM_DEVICE_GENERIC_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceGeneric, NM_IS_DEVICE_GENERIC, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_generic_get_hw_address: * @device: a #NMDeviceGeneric @@ -56,7 +52,7 @@ nm_device_generic_get_hw_address (NMDeviceGeneric *device) { g_return_val_if_fail (NM_IS_DEVICE_GENERIC (device), NULL); - return nm_str_not_empty (NM_DEVICE_GENERIC_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_GENERIC_GET_PRIVATE (device)->hw_address); } /*****************************************************************************/ @@ -66,7 +62,7 @@ get_type_description (NMDevice *device) { NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (device); - return nm_str_not_empty (priv->type_description); + return _nml_coerce_property_str_not_empty (priv->type_description); } static const char * @@ -113,23 +109,6 @@ nm_device_generic_init (NMDeviceGeneric *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_GENERIC_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_GENERIC_TYPE_DESCRIPTION, &priv->type_description }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_generic_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_GENERIC, - property_info); -} - -static void finalize (GObject *object) { NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object); @@ -162,36 +141,40 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_generic = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_GENERIC, + nm_device_generic_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceGeneric, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_S ("TypeDescription", PROP_TYPE_DESCRIPTION, NMDeviceGeneric, _priv.type_description ), + ), +); + static void nm_device_generic_class_init (NMDeviceGenericClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - g_type_class_add_private (klass, sizeof (NMDeviceGenericPrivate)); - - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; - - device_class->get_type_description = get_type_description; - device_class->get_hw_address = get_hw_address; + device_class->get_type_description = get_type_description; + device_class->get_hw_address = get_hw_address; device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; + device_class->get_setting_type = get_setting_type; /** * NMDeviceGeneric:hw-address: * * The hardware address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_GENERIC_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_GENERIC_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceGeneric:type-description: @@ -199,10 +182,11 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass) * A description of the specific type of device this is, or %NULL * if not known. **/ - g_object_class_install_property - (object_class, PROP_TYPE_DESCRIPTION, - g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_TYPE_DESCRIPTION] = + g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_generic); } diff --git a/libnm/nm-device-generic.h b/libnm/nm-device-generic.h index 2cc3e0c5..aa52023a 100644 --- a/libnm/nm-device-generic.h +++ b/libnm/nm-device-generic.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2013 Red Hat, Inc. + * Copyright (C) 2013 Red Hat, Inc. */ #ifndef __NM_DEVICE_GENERIC_H__ @@ -41,16 +27,7 @@ G_BEGIN_DECLS /** * NMDeviceGeneric: */ -struct _NMDeviceGeneric { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceGenericClass; +typedef struct _NMDeviceGenericClass NMDeviceGenericClass; GType nm_device_generic_get_type (void); diff --git a/libnm/nm-device-infiniband.c b/libnm/nm-device-infiniband.c index 17de2de4..c3e57c95 100644 --- a/libnm/nm-device-infiniband.c +++ b/libnm/nm-device-infiniband.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2011 - 2012 Red Hat, Inc. + * Copyright (C) 2011 - 2012 Red Hat, Inc. */ #include "nm-default.h" @@ -26,23 +12,33 @@ #include "nm-utils.h" #include "nm-object-private.h" -G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, + PROP_CARRIER, +); typedef struct { char *hw_address; - gboolean carrier; + bool carrier; } NMDeviceInfinibandPrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, - PROP_CARRIER, +struct _NMDeviceInfiniband { + NMDevice parent; + NMDeviceInfinibandPrivate _priv; +}; - LAST_PROP +struct _NMDeviceInfinibandClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE) + +#define NM_DEVICE_INFINIBAND_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceInfiniband, NM_IS_DEVICE_INFINIBAND, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_infiniband_get_hw_address: * @device: a #NMDeviceInfiniband @@ -57,7 +53,7 @@ nm_device_infiniband_get_hw_address (NMDeviceInfiniband *device) { g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (device), NULL); - return nm_str_not_empty (NM_DEVICE_INFINIBAND_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_INFINIBAND_GET_PRIVATE (device)->hw_address); } /** @@ -131,23 +127,6 @@ nm_device_infiniband_init (NMDeviceInfiniband *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_INFINIBAND_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_INFINIBAND_CARRIER, &priv->carrier }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_infiniband_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_INFINIBAND, - property_info); -} - -static void finalize (GObject *object) { NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (object); @@ -178,49 +157,50 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_infiniband = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_INFINIBAND, + nm_device_infiniband_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceInfiniband, _priv.carrier ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceInfiniband, _priv.hw_address ), + ), +); + static void nm_device_infiniband_class_init (NMDeviceInfinibandClass *ib_class) { GObjectClass *object_class = G_OBJECT_CLASS (ib_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (ib_class); NMDeviceClass *device_class = NM_DEVICE_CLASS (ib_class); - g_type_class_add_private (ib_class, sizeof (NMDeviceInfinibandPrivate)); - - /* virtual methods */ - object_class->finalize = finalize; object_class->get_property = get_property; - - nm_object_class->init_dbus = init_dbus; + object_class->finalize = finalize; device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; - - /* properties */ + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceInfiniband:hw-address: * * The hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_INFINIBAND_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_INFINIBAND_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceInfiniband:carrier: * * Whether the device has carrier. **/ - g_object_class_install_property - (object_class, PROP_CARRIER, - g_param_spec_boolean (NM_DEVICE_INFINIBAND_CARRIER, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CARRIER] = + g_param_spec_boolean (NM_DEVICE_INFINIBAND_CARRIER, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_infiniband); } diff --git a/libnm/nm-device-infiniband.h b/libnm/nm-device-infiniband.h index b814aa2c..06a2c257 100644 --- a/libnm/nm-device-infiniband.h +++ b/libnm/nm-device-infiniband.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2011 - 2012 Red Hat, Inc. + * Copyright (C) 2011 - 2012 Red Hat, Inc. */ #ifndef __NM_DEVICE_INFINIBAND_H__ @@ -41,16 +27,7 @@ G_BEGIN_DECLS /** * NMDeviceInfiniband: */ -struct _NMDeviceInfiniband { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceInfinibandClass; +typedef struct _NMDeviceInfinibandClass NMDeviceInfinibandClass; GType nm_device_infiniband_get_type (void); diff --git a/libnm/nm-device-ip-tunnel.c b/libnm/nm-device-ip-tunnel.c index 8197748c..2990e204 100644 --- a/libnm/nm-device-ip-tunnel.c +++ b/libnm/nm-device-ip-tunnel.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2015 Red Hat, Inc. + * Copyright (C) 2015 Red Hat, Inc. */ #include "nm-default.h" @@ -27,27 +13,9 @@ #include "nm-object-private.h" #include "nm-core-internal.h" -G_DEFINE_TYPE (NMDeviceIPTunnel, nm_device_ip_tunnel, NM_TYPE_DEVICE) - -#define NM_DEVICE_IP_TUNNEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_IP_TUNNEL, NMDeviceIPTunnelPrivate)) - -typedef struct { - NMIPTunnelMode mode; - NMDevice *parent; - char *local; - char *remote; - guint8 ttl; - guint8 tos; - gboolean path_mtu_discovery; - char *input_key; - char *output_key; - guint8 encap_limit; - guint32 flow_label; - guint32 flags; -} NMDeviceIPTunnelPrivate; +/*****************************************************************************/ -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_MODE, PROP_PARENT, PROP_LOCAL, @@ -60,10 +28,38 @@ enum { PROP_ENCAPSULATION_LIMIT, PROP_FLOW_LABEL, PROP_FLAGS, +); - LAST_PROP +typedef struct { + NMLDBusPropertyO parent; + char *local; + char *remote; + char *input_key; + char *output_key; + guint32 mode; + guint32 flow_label; + guint32 flags; + guint8 ttl; + guint8 tos; + guint8 encapsulation_limit; + bool path_mtu_discovery; +} NMDeviceIPTunnelPrivate; + +struct _NMDeviceIPTunnel { + NMDevice parent; + NMDeviceIPTunnelPrivate _priv; +}; + +struct _NMDeviceIPTunnelClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceIPTunnel, nm_device_ip_tunnel, NM_TYPE_DEVICE) + +#define NM_DEVICE_IP_TUNNEL_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceIPTunnel, NM_IS_DEVICE_IP_TUNNEL, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_ip_tunnel_get_mode: * @device: a #NMDeviceIPTunnel @@ -93,7 +89,7 @@ nm_device_ip_tunnel_get_parent (NMDeviceIPTunnel *device) { g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL); - return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->parent; + return nml_dbus_property_o_get_obj (&NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->parent); } /** @@ -109,7 +105,7 @@ nm_device_ip_tunnel_get_local (NMDeviceIPTunnel *device) { g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL); - return nm_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->local); + return _nml_coerce_property_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->local); } /** @@ -125,7 +121,7 @@ nm_device_ip_tunnel_get_remote (NMDeviceIPTunnel *device) { g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL); - return nm_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->remote); + return _nml_coerce_property_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->remote); } /** @@ -190,7 +186,7 @@ nm_device_ip_tunnel_get_input_key (NMDeviceIPTunnel *device) { g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL); - return nm_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->input_key); + return _nml_coerce_property_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->input_key); } /** @@ -206,7 +202,7 @@ nm_device_ip_tunnel_get_output_key (NMDeviceIPTunnel *device) { g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL); - return nm_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->output_key); + return _nml_coerce_property_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->output_key); } /** @@ -222,7 +218,7 @@ nm_device_ip_tunnel_get_encapsulation_limit (NMDeviceIPTunnel *device) { g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), 0); - return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->encap_limit; + return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->encapsulation_limit; } /** @@ -286,33 +282,6 @@ nm_device_ip_tunnel_init (NMDeviceIPTunnel *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_IP_TUNNEL_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE }, - { NM_DEVICE_IP_TUNNEL_MODE, &priv->mode }, - { NM_DEVICE_IP_TUNNEL_LOCAL, &priv->local }, - { NM_DEVICE_IP_TUNNEL_REMOTE, &priv->remote }, - { NM_DEVICE_IP_TUNNEL_TTL, &priv->ttl }, - { NM_DEVICE_IP_TUNNEL_TOS, &priv->tos }, - { NM_DEVICE_IP_TUNNEL_PATH_MTU_DISCOVERY, &priv->path_mtu_discovery }, - { NM_DEVICE_IP_TUNNEL_INPUT_KEY, &priv->input_key }, - { NM_DEVICE_IP_TUNNEL_OUTPUT_KEY, &priv->output_key }, - { NM_DEVICE_IP_TUNNEL_ENCAPSULATION_LIMIT, &priv->encap_limit }, - { NM_DEVICE_IP_TUNNEL_FLOW_LABEL, &priv->flow_label }, - { NM_DEVICE_IP_TUNNEL_FLAGS, &priv->flags }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_ip_tunnel_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL, - property_info); -} - -static void finalize (GObject *object) { NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE (object); @@ -321,7 +290,6 @@ finalize (GObject *object) g_free (priv->remote); g_free (priv->input_key); g_free (priv->output_key); - g_clear_object (&priv->parent); G_OBJECT_CLASS (nm_device_ip_tunnel_parent_class)->finalize (object); } @@ -377,25 +345,42 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_iptunnel = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL, + nm_device_ip_tunnel_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_Y ("EncapsulationLimit", PROP_ENCAPSULATION_LIMIT, NMDeviceIPTunnel, _priv.encapsulation_limit ), + NML_DBUS_META_PROPERTY_INIT_U ("Flags", PROP_FLAGS, NMDeviceIPTunnel, _priv.flags ), + NML_DBUS_META_PROPERTY_INIT_U ("FlowLabel", PROP_FLOW_LABEL, NMDeviceIPTunnel, _priv.flow_label ), + NML_DBUS_META_PROPERTY_INIT_S ("InputKey", PROP_INPUT_KEY, NMDeviceIPTunnel, _priv.input_key ), + NML_DBUS_META_PROPERTY_INIT_S ("Local", PROP_LOCAL, NMDeviceIPTunnel, _priv.local ), + NML_DBUS_META_PROPERTY_INIT_U ("Mode", PROP_MODE, NMDeviceIPTunnel, _priv.mode ), + NML_DBUS_META_PROPERTY_INIT_S ("OutputKey", PROP_OUTPUT_KEY, NMDeviceIPTunnel, _priv.output_key ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDeviceIPTunnel, _priv.parent, nm_device_get_type ), + NML_DBUS_META_PROPERTY_INIT_B ("PathMtuDiscovery", PROP_PATH_MTU_DISCOVERY, NMDeviceIPTunnel, _priv.path_mtu_discovery ), + NML_DBUS_META_PROPERTY_INIT_S ("Remote", PROP_REMOTE, NMDeviceIPTunnel, _priv.remote ), + NML_DBUS_META_PROPERTY_INIT_Y ("Tos", PROP_TOS, NMDeviceIPTunnel, _priv.tos ), + NML_DBUS_META_PROPERTY_INIT_Y ("Ttl", PROP_TTL, NMDeviceIPTunnel, _priv.ttl ), + ), +); + static void -nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) +nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (bond_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (bond_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (bond_class); - - g_type_class_add_private (bond_class, sizeof (NMDeviceIPTunnelPrivate)); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - /* virtual methods */ - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceIPTunnel); - device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; + _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceIPTunnelPrivate, parent); - /* properties */ + device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; /** * NMDeviceIPTunnel:mode: @@ -404,12 +389,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_MODE, - g_param_spec_uint (NM_DEVICE_IP_TUNNEL_MODE, "", "", - 0, G_MAXUINT, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MODE] = + g_param_spec_uint (NM_DEVICE_IP_TUNNEL_MODE, "", "", + 0, G_MAXUINT, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceIPTunnel:parent: @@ -418,12 +402,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_PARENT, - g_param_spec_object (NM_DEVICE_IP_TUNNEL_PARENT, "", "", - NM_TYPE_DEVICE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PARENT] = + g_param_spec_object (NM_DEVICE_IP_TUNNEL_PARENT, "", "", + NM_TYPE_DEVICE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceIPTunnel:local: @@ -432,12 +415,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_LOCAL, - g_param_spec_string (NM_DEVICE_IP_TUNNEL_LOCAL, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_LOCAL] = + g_param_spec_string (NM_DEVICE_IP_TUNNEL_LOCAL, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceIPTunnel:remote: @@ -446,12 +428,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_REMOTE, - g_param_spec_string (NM_DEVICE_IP_TUNNEL_REMOTE, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_REMOTE] = + g_param_spec_string (NM_DEVICE_IP_TUNNEL_REMOTE, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceIPTunnel:ttl: @@ -461,12 +442,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_TTL, - g_param_spec_uchar (NM_DEVICE_IP_TUNNEL_TTL, "", "", - 0, 255, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_TTL] = + g_param_spec_uchar (NM_DEVICE_IP_TUNNEL_TTL, "", "", + 0, 255, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceIPTunnel:tos: @@ -476,12 +456,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_TOS, - g_param_spec_uchar (NM_DEVICE_IP_TUNNEL_TOS, "", "", - 0, 255, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_TOS] = + g_param_spec_uchar (NM_DEVICE_IP_TUNNEL_TOS, "", "", + 0, 255, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceIPTunnel:path-mtu-discovery: @@ -490,12 +469,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_PATH_MTU_DISCOVERY, - g_param_spec_boolean (NM_DEVICE_IP_TUNNEL_PATH_MTU_DISCOVERY, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PATH_MTU_DISCOVERY] = + g_param_spec_boolean (NM_DEVICE_IP_TUNNEL_PATH_MTU_DISCOVERY, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceIPTunnel:input-key: @@ -504,12 +482,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_INPUT_KEY, - g_param_spec_string (NM_DEVICE_IP_TUNNEL_INPUT_KEY, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_INPUT_KEY] = + g_param_spec_string (NM_DEVICE_IP_TUNNEL_INPUT_KEY, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceIPTunnel:output-key: @@ -518,12 +495,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_OUTPUT_KEY, - g_param_spec_string (NM_DEVICE_IP_TUNNEL_OUTPUT_KEY, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_OUTPUT_KEY] = + g_param_spec_string (NM_DEVICE_IP_TUNNEL_OUTPUT_KEY, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceIPTunnel:encapsulation-limit: @@ -534,12 +510,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_ENCAPSULATION_LIMIT, - g_param_spec_uchar (NM_DEVICE_IP_TUNNEL_ENCAPSULATION_LIMIT, "", "", - 0, 255, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ENCAPSULATION_LIMIT] = + g_param_spec_uchar (NM_DEVICE_IP_TUNNEL_ENCAPSULATION_LIMIT, "", "", + 0, 255, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceIPTunnel:flow-label: @@ -549,12 +524,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_FLOW_LABEL, - g_param_spec_uint (NM_DEVICE_IP_TUNNEL_FLOW_LABEL, "", "", - 0, (1 << 20) - 1, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_FLOW_LABEL] = + g_param_spec_uint (NM_DEVICE_IP_TUNNEL_FLOW_LABEL, "", "", + 0, (1 << 20) - 1, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceIPTunnel:flags: @@ -563,10 +537,11 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class) * * Since: 1.12 **/ - g_object_class_install_property - (object_class, PROP_FLAGS, - g_param_spec_uint (NM_DEVICE_IP_TUNNEL_FLAGS, "", "", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_FLAGS] = + g_param_spec_uint (NM_DEVICE_IP_TUNNEL_FLAGS, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_iptunnel); } diff --git a/libnm/nm-device-ip-tunnel.h b/libnm/nm-device-ip-tunnel.h index 07a36cd9..08c20860 100644 --- a/libnm/nm-device-ip-tunnel.h +++ b/libnm/nm-device-ip-tunnel.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2015 Red Hat, Inc. + * Copyright (C) 2015 Red Hat, Inc. */ #ifndef __NM_DEVICE_IP_TUNNEL_H__ @@ -52,16 +38,7 @@ G_BEGIN_DECLS /** * NMDeviceIPTunnel: */ -struct _NMDeviceIPTunnel { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceIPTunnelClass; +typedef struct _NMDeviceIPTunnelClass NMDeviceIPTunnelClass; NM_AVAILABLE_IN_1_2 GType nm_device_ip_tunnel_get_type (void); diff --git a/libnm/nm-device-macsec.c b/libnm/nm-device-macsec.c index 2a60dee5..194261f0 100644 --- a/libnm/nm-device-macsec.c +++ b/libnm/nm-device-macsec.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017 Red Hat, Inc. + * Copyright (C) 2017 Red Hat, Inc. */ #include "nm-default.h" @@ -25,26 +11,7 @@ #include "nm-object-private.h" #include "nm-utils.h" -G_DEFINE_TYPE (NMDeviceMacsec, nm_device_macsec, NM_TYPE_DEVICE) - -#define NM_DEVICE_MACSEC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MACSEC, NMDeviceMacsecPrivate)) - -typedef struct { - NMDevice *parent; - char *hw_address; - guint64 sci; - guint64 cipher_suite; - guint8 icv_length; - guint32 window; - guint8 encoding_sa; - gboolean encrypt; - gboolean protect; - gboolean include_sci; - gboolean es; - gboolean scb; - gboolean replay_protect; - char *validation; -} NMDeviceMacsecPrivate; +/*****************************************************************************/ NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_PARENT, @@ -63,6 +30,38 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_VALIDATION, ); +typedef struct { + NMLDBusPropertyO parent; + char *hw_address; + char *validation; + guint64 sci; + guint64 cipher_suite; + guint32 window; + guint8 icv_length; + guint8 encoding_sa; + bool encrypt; + bool protect; + bool include_sci; + bool es; + bool scb; + bool replay_protect; +} NMDeviceMacsecPrivate; + +struct _NMDeviceMacsec { + NMDevice parent; + NMDeviceMacsecPrivate _priv; +}; + +struct _NMDeviceMacsecClass { + NMDeviceClass parent; +}; + +G_DEFINE_TYPE (NMDeviceMacsec, nm_device_macsec, NM_TYPE_DEVICE) + +#define NM_DEVICE_MACSEC_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceMacsec, NM_IS_DEVICE_MACSEC, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_macsec_get_parent: * @device: a #NMDeviceMacsec @@ -76,7 +75,7 @@ nm_device_macsec_get_parent (NMDeviceMacsec *device) { g_return_val_if_fail (NM_IS_DEVICE_MACSEC (device), NULL); - return NM_DEVICE_MACSEC_GET_PRIVATE (device)->parent; + return nml_dbus_property_o_get_obj (&NM_DEVICE_MACSEC_GET_PRIVATE (device)->parent); } /** @@ -333,42 +332,12 @@ nm_device_macsec_init (NMDeviceMacsec *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_MACSEC_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE }, - { NM_DEVICE_MACSEC_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_MACSEC_SCI, &priv->sci }, - { NM_DEVICE_MACSEC_CIPHER_SUITE, &priv->cipher_suite }, - { NM_DEVICE_MACSEC_ICV_LENGTH, &priv->icv_length }, - { NM_DEVICE_MACSEC_WINDOW, &priv->window }, - { NM_DEVICE_MACSEC_ENCODING_SA, &priv->encoding_sa }, - { NM_DEVICE_MACSEC_ENCRYPT, &priv->encrypt }, - { NM_DEVICE_MACSEC_PROTECT, &priv->protect }, - { NM_DEVICE_MACSEC_INCLUDE_SCI, &priv->include_sci }, - { NM_DEVICE_MACSEC_ES, &priv->es }, - { NM_DEVICE_MACSEC_SCB, &priv->scb }, - { NM_DEVICE_MACSEC_REPLAY_PROTECT, &priv->replay_protect }, - { NM_DEVICE_MACSEC_VALIDATION, &priv->validation }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_macsec_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_MACSEC, - property_info); -} - -static void finalize (GObject *object) { NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (object); g_free (priv->validation); g_free (priv->hw_address); - g_clear_object (&priv->parent); G_OBJECT_CLASS (nm_device_macsec_parent_class)->finalize (object); } @@ -430,19 +399,40 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_macsec = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_MACSEC, + nm_device_macsec_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_T ("CipherSuite", PROP_CIPHER_SUITE, NMDeviceMacsec, _priv.cipher_suite ), + NML_DBUS_META_PROPERTY_INIT_Y ("EncodingSa", PROP_ENCODING_SA, NMDeviceMacsec, _priv.encoding_sa ), + NML_DBUS_META_PROPERTY_INIT_B ("Encrypt", PROP_ENCRYPT, NMDeviceMacsec, _priv.encrypt ), + NML_DBUS_META_PROPERTY_INIT_B ("Es", PROP_ES, NMDeviceMacsec, _priv.es ), + NML_DBUS_META_PROPERTY_INIT_Y ("IcvLength", PROP_ICV_LENGTH, NMDeviceMacsec, _priv.icv_length ), + NML_DBUS_META_PROPERTY_INIT_B ("IncludeSci", PROP_INCLUDE_SCI, NMDeviceMacsec, _priv.include_sci ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDeviceMacsec, _priv.parent, nm_device_get_type ), + NML_DBUS_META_PROPERTY_INIT_B ("Protect", PROP_PROTECT, NMDeviceMacsec, _priv.protect ), + NML_DBUS_META_PROPERTY_INIT_B ("ReplayProtect", PROP_REPLAY_PROTECT, NMDeviceMacsec, _priv.replay_protect ), + NML_DBUS_META_PROPERTY_INIT_B ("Scb", PROP_SCB, NMDeviceMacsec, _priv.scb ), + NML_DBUS_META_PROPERTY_INIT_T ("Sci", PROP_SCI, NMDeviceMacsec, _priv.sci ), + NML_DBUS_META_PROPERTY_INIT_S ("Validation", PROP_VALIDATION, NMDeviceMacsec, _priv.validation ), + NML_DBUS_META_PROPERTY_INIT_U ("Window", PROP_WINDOW, NMDeviceMacsec, _priv.window ), + ), +); + static void -nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) +nm_device_macsec_class_init (NMDeviceMacsecClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (macsec_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (macsec_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (macsec_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - g_type_class_add_private (macsec_class, sizeof (NMDeviceMacsecPrivate)); - - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->finalize = finalize; + + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceMacsec); - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceMacsecPrivate, parent); device_class->get_hw_address = get_hw_address; @@ -454,10 +444,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_PARENT] = - g_param_spec_object (NM_DEVICE_MACSEC_PARENT, "", "", - NM_TYPE_DEVICE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_object (NM_DEVICE_MACSEC_PARENT, "", "", + NM_TYPE_DEVICE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:hw-address: @@ -467,10 +457,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_HW_ADDRESS] = - g_param_spec_string (NM_DEVICE_MACSEC_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_string (NM_DEVICE_MACSEC_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:sci: @@ -480,10 +470,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_SCI] = - g_param_spec_uint64 (NM_DEVICE_MACSEC_SCI, "", "", - 0, G_MAXUINT64, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_uint64 (NM_DEVICE_MACSEC_SCI, "", "", + 0, G_MAXUINT64, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:icv-length: @@ -493,10 +483,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_ICV_LENGTH] = - g_param_spec_uchar (NM_DEVICE_MACSEC_ICV_LENGTH, "", "", - 0, G_MAXUINT8, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_uchar (NM_DEVICE_MACSEC_ICV_LENGTH, "", "", + 0, G_MAXUINT8, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:cipher-suite: @@ -506,10 +496,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_CIPHER_SUITE] = - g_param_spec_uint64 (NM_DEVICE_MACSEC_CIPHER_SUITE, "", "", - 0, G_MAXUINT64, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_uint64 (NM_DEVICE_MACSEC_CIPHER_SUITE, "", "", + 0, G_MAXUINT64, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:window: @@ -519,10 +509,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_WINDOW] = - g_param_spec_uint (NM_DEVICE_MACSEC_WINDOW, "", "", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_uint (NM_DEVICE_MACSEC_WINDOW, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:encoding-sa: @@ -533,10 +523,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_ENCODING_SA] = - g_param_spec_uchar (NM_DEVICE_MACSEC_ENCODING_SA, "", "", - 0, G_MAXUINT8, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_uchar (NM_DEVICE_MACSEC_ENCODING_SA, "", "", + 0, G_MAXUINT8, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:validation: @@ -547,10 +537,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_VALIDATION] = - g_param_spec_string (NM_DEVICE_MACSEC_VALIDATION, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_string (NM_DEVICE_MACSEC_VALIDATION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:encrypt: @@ -560,10 +550,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_ENCRYPT] = - g_param_spec_boolean (NM_DEVICE_MACSEC_ENCRYPT, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_boolean (NM_DEVICE_MACSEC_ENCRYPT, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:protect: @@ -573,10 +563,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_PROTECT] = - g_param_spec_boolean (NM_DEVICE_MACSEC_PROTECT, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_boolean (NM_DEVICE_MACSEC_PROTECT, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:include-sci: @@ -587,10 +577,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_INCLUDE_SCI] = - g_param_spec_boolean (NM_DEVICE_MACSEC_INCLUDE_SCI, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_boolean (NM_DEVICE_MACSEC_INCLUDE_SCI, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:es: @@ -601,10 +591,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_ES] = - g_param_spec_boolean (NM_DEVICE_MACSEC_ES, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_boolean (NM_DEVICE_MACSEC_ES, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:scb: @@ -615,10 +605,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_SCB] = - g_param_spec_boolean (NM_DEVICE_MACSEC_SCB, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_boolean (NM_DEVICE_MACSEC_SCB, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacsec:replay-protect: @@ -628,10 +618,10 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class) * Since: 1.6 **/ obj_properties[PROP_REPLAY_PROTECT] = - g_param_spec_boolean (NM_DEVICE_MACSEC_REPLAY_PROTECT, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_boolean (NM_DEVICE_MACSEC_REPLAY_PROTECT, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); - g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_macsec); } diff --git a/libnm/nm-device-macsec.h b/libnm/nm-device-macsec.h index fce07d7a..acf6269b 100644 --- a/libnm/nm-device-macsec.h +++ b/libnm/nm-device-macsec.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017 Red Hat, Inc. + * Copyright (C) 2017 Red Hat, Inc. */ #ifndef __NM_DEVICE_MACSEC_H__ @@ -53,16 +39,7 @@ G_BEGIN_DECLS /** * NMDeviceMacsec: */ -struct _NMDeviceMacsec { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceMacsecClass; +typedef struct _NMDeviceMacsecClass NMDeviceMacsecClass; NM_AVAILABLE_IN_1_6 GType nm_device_macsec_get_type (void); diff --git a/libnm/nm-device-macvlan.c b/libnm/nm-device-macvlan.c index 3de135db..e703cb5c 100644 --- a/libnm/nm-device-macvlan.c +++ b/libnm/nm-device-macvlan.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2015 Red Hat, Inc. + * Copyright (C) 2015 Red Hat, Inc. */ #include "nm-default.h" @@ -27,29 +13,38 @@ #include "nm-device-macvlan.h" #include "nm-object-private.h" -G_DEFINE_TYPE (NMDeviceMacvlan, nm_device_macvlan, NM_TYPE_DEVICE) - -#define NM_DEVICE_MACVLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MACVLAN, NMDeviceMacvlanPrivate)) - -typedef struct { - NMDevice *parent; - char *mode; - gboolean no_promisc; - gboolean tap; - char *hw_address; -} NMDeviceMacvlanPrivate; +/*****************************************************************************/ -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_PARENT, PROP_MODE, PROP_NO_PROMISC, PROP_TAP, PROP_HW_ADDRESS, +); + +typedef struct { + NMLDBusPropertyO parent; + char *mode; + bool no_promisc; + bool tap; +} NMDeviceMacvlanPrivate; - LAST_PROP +struct _NMDeviceMacvlan { + NMDevice parent; + NMDeviceMacvlanPrivate _priv; }; +struct _NMDeviceMacvlanClass { + NMDeviceClass parent; +}; + +G_DEFINE_TYPE (NMDeviceMacvlan, nm_device_macvlan, NM_TYPE_DEVICE) + +#define NM_DEVICE_MACVLAN_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceMacvlan, NM_IS_DEVICE_MACVLAN, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_macvlan_get_parent: * @device: a #NMDeviceMacvlan @@ -63,7 +58,7 @@ nm_device_macvlan_get_parent (NMDeviceMacvlan *device) { g_return_val_if_fail (NM_IS_DEVICE_MACVLAN (device), FALSE); - return NM_DEVICE_MACVLAN_GET_PRIVATE (device)->parent; + return nml_dbus_property_o_get_obj (&NM_DEVICE_MACVLAN_GET_PRIVATE (device)->parent); } /** @@ -82,7 +77,7 @@ nm_device_macvlan_get_mode (NMDeviceMacvlan *device) { g_return_val_if_fail (NM_IS_DEVICE_MACVLAN (device), NULL); - return nm_str_not_empty (NM_DEVICE_MACVLAN_GET_PRIVATE (device)->mode); + return _nml_coerce_property_str_not_empty (NM_DEVICE_MACVLAN_GET_PRIVATE (device)->mode); } /** @@ -131,13 +126,15 @@ nm_device_macvlan_get_tap (NMDeviceMacvlan *device) * device, and must not be modified. * * Since: 1.2 + * + * This property is not implemented yet, and the function always return NULL. **/ const char * nm_device_macvlan_get_hw_address (NMDeviceMacvlan *device) { g_return_val_if_fail (NM_IS_DEVICE_MACVLAN (device), NULL); - return nm_str_not_empty (NM_DEVICE_MACVLAN_GET_PRIVATE (device)->hw_address); + return NULL; } static gboolean @@ -184,33 +181,11 @@ nm_device_macvlan_init (NMDeviceMacvlan *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_MACVLAN_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE }, - { NM_DEVICE_MACVLAN_MODE, &priv->mode }, - { NM_DEVICE_MACVLAN_NO_PROMISC, &priv->no_promisc }, - { NM_DEVICE_MACVLAN_TAP, &priv->tap }, - { NM_DEVICE_MACVLAN_HW_ADDRESS, &priv->hw_address }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_macvlan_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_MACVLAN, - property_info); -} - -static void finalize (GObject *object) { NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (object); g_free (priv->mode); - g_free (priv->hw_address); - g_clear_object (&priv->parent); G_OBJECT_CLASS (nm_device_macvlan_parent_class)->finalize (object); } @@ -245,26 +220,35 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_macvlan = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_MACVLAN, + nm_device_macvlan_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_S ("Mode", PROP_MODE, NMDeviceMacvlan, _priv.mode ), + NML_DBUS_META_PROPERTY_INIT_B ("NoPromisc", PROP_NO_PROMISC, NMDeviceMacvlan, _priv.no_promisc ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDeviceMacvlan, _priv.parent, nm_device_get_type ), + NML_DBUS_META_PROPERTY_INIT_B ("Tap", PROP_TAP, NMDeviceMacvlan, _priv.tap ), + ), +); + static void -nm_device_macvlan_class_init (NMDeviceMacvlanClass *gre_class) +nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (gre_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (gre_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (gre_class); - - g_type_class_add_private (gre_class, sizeof (NMDeviceMacvlanPrivate)); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - /* virtual methods */ - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceMacvlan); - device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; + _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceMacvlanPrivate, parent); - /* properties */ + device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceMacvlan:parent: @@ -273,12 +257,11 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *gre_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_PARENT, - g_param_spec_object (NM_DEVICE_MACVLAN_PARENT, "", "", - NM_TYPE_DEVICE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PARENT] = + g_param_spec_object (NM_DEVICE_MACVLAN_PARENT, "", "", + NM_TYPE_DEVICE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacvlan:mode: @@ -287,12 +270,11 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *gre_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_MODE, - g_param_spec_string (NM_DEVICE_MACVLAN_MODE, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MODE] = + g_param_spec_string (NM_DEVICE_MACVLAN_MODE, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacvlan:no-promisc: @@ -301,12 +283,11 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *gre_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_NO_PROMISC, - g_param_spec_boolean (NM_DEVICE_MACVLAN_NO_PROMISC, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_NO_PROMISC] = + g_param_spec_boolean (NM_DEVICE_MACVLAN_NO_PROMISC, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacvlan:tap: @@ -315,12 +296,11 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *gre_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_TAP, - g_param_spec_boolean (NM_DEVICE_MACVLAN_TAP, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_TAP] = + g_param_spec_boolean (NM_DEVICE_MACVLAN_TAP, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceMacvlan:hw-address: @@ -328,11 +308,14 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *gre_class) * The hardware (MAC) address of the device. * * Since: 1.2 + * + * This property is not implemented yet, and the function always return NULL. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_MACVLAN_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_MACVLAN_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_macvlan); } diff --git a/libnm/nm-device-macvlan.h b/libnm/nm-device-macvlan.h index c9e94c1f..c991f8bd 100644 --- a/libnm/nm-device-macvlan.h +++ b/libnm/nm-device-macvlan.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2015 Red Hat, Inc. + * Copyright (C) 2015 Red Hat, Inc. */ #ifndef __NM_DEVICE_MACVLAN_H__ @@ -44,16 +30,7 @@ G_BEGIN_DECLS /** * NMDeviceMacvlan: */ -struct _NMDeviceMacvlan { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceMacvlanClass; +typedef struct _NMDeviceMacvlanClass NMDeviceMacvlanClass; NM_AVAILABLE_IN_1_2 GType nm_device_macvlan_get_type (void); diff --git a/libnm/nm-device-modem.c b/libnm/nm-device-modem.c index 60c707b8..5e7b064b 100644 --- a/libnm/nm-device-modem.c +++ b/libnm/nm-device-modem.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2011 - 2012 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright (C) 2011 - 2012 Red Hat, Inc. + * Copyright (C) 2008 Novell, Inc. */ #include "nm-default.h" @@ -28,28 +14,39 @@ #include "nm-object-private.h" #include "nm-enum-types.h" -G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_MODEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MODEM, NMDeviceModemPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_MODEM_CAPABILITIES, + PROP_CURRENT_CAPABILITIES, + PROP_DEVICE_ID, + PROP_OPERATOR_CODE, + PROP_APN, +); typedef struct { - NMDeviceModemCapabilities caps; - NMDeviceModemCapabilities current_caps; char *device_id; char *operator_code; char *apn; + guint32 modem_capabilities; + guint32 current_capabilities; } NMDeviceModemPrivate; -enum { - PROP_0, - PROP_MODEM_CAPS, - PROP_CURRENT_CAPS, - PROP_DEVICE_ID, - PROP_OPERATOR_CODE, - PROP_APN, - LAST_PROP +struct _NMDeviceModem { + NMDevice parent; + NMDeviceModemPrivate _priv; +}; + +struct _NMDeviceModemClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE) + +#define NM_DEVICE_MODEM_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceModem, NM_IS_DEVICE_MODEM, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_modem_get_modem_capabilities: * @self: a #NMDeviceModem @@ -65,7 +62,7 @@ nm_device_modem_get_modem_capabilities (NMDeviceModem *self) { g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE); - return NM_DEVICE_MODEM_GET_PRIVATE (self)->caps; + return NM_DEVICE_MODEM_GET_PRIVATE (self)->modem_capabilities; } /** @@ -84,7 +81,7 @@ nm_device_modem_get_current_capabilities (NMDeviceModem *self) { g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE); - return NM_DEVICE_MODEM_GET_PRIVATE (self)->current_caps; + return NM_DEVICE_MODEM_GET_PRIVATE (self)->current_capabilities; } /** @@ -219,26 +216,6 @@ nm_device_modem_init (NMDeviceModem *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_MODEM_MODEM_CAPABILITIES, &priv->caps }, - { NM_DEVICE_MODEM_CURRENT_CAPABILITIES, &priv->current_caps }, - { NM_DEVICE_MODEM_DEVICE_ID, &priv->device_id }, - { NM_DEVICE_MODEM_OPERATOR_CODE, &priv->operator_code }, - { NM_DEVICE_MODEM_APN, &priv->apn }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_modem_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_MODEM, - property_info); -} - -static void finalize (GObject *object) { NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (object); @@ -259,10 +236,10 @@ get_property (GObject *object, NMDeviceModem *self = NM_DEVICE_MODEM (object); switch (prop_id) { - case PROP_MODEM_CAPS: + case PROP_MODEM_CAPABILITIES: g_value_set_flags (value, nm_device_modem_get_modem_capabilities (self)); break; - case PROP_CURRENT_CAPS: + case PROP_CURRENT_CAPABILITIES: g_value_set_flags (value, nm_device_modem_get_current_capabilities (self)); break; case PROP_DEVICE_ID: @@ -280,24 +257,31 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_modem = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_MODEM, + nm_device_modem_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_S ("Apn", PROP_APN, NMDeviceModem, _priv.apn ), + NML_DBUS_META_PROPERTY_INIT_U ("CurrentCapabilities", PROP_CURRENT_CAPABILITIES, NMDeviceModem, _priv.current_capabilities ), + NML_DBUS_META_PROPERTY_INIT_S ("DeviceId", PROP_DEVICE_ID, NMDeviceModem, _priv.device_id ), + NML_DBUS_META_PROPERTY_INIT_U ("ModemCapabilities", PROP_MODEM_CAPABILITIES, NMDeviceModem, _priv.modem_capabilities ), + NML_DBUS_META_PROPERTY_INIT_S ("OperatorCode", PROP_OPERATOR_CODE, NMDeviceModem, _priv.operator_code ), + ), +); + static void nm_device_modem_class_init (NMDeviceModemClass *modem_class) { GObjectClass *object_class = G_OBJECT_CLASS (modem_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (modem_class); NMDeviceClass *device_class = NM_DEVICE_CLASS (modem_class); - g_type_class_add_private (modem_class, sizeof (NMDeviceModemPrivate)); - - /* virtual methods */ - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; - - device_class->get_type_description = get_type_description; + device_class->get_type_description = get_type_description; device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; + device_class->get_setting_type = get_setting_type; /** * NMDeviceModem:modem-capabilities: @@ -307,13 +291,12 @@ nm_device_modem_class_init (NMDeviceModemClass *modem_class) * a firmware reload or other reinitialization to switch between eg * CDMA/EVDO and GSM/UMTS. **/ - g_object_class_install_property - (object_class, PROP_MODEM_CAPS, - g_param_spec_flags (NM_DEVICE_MODEM_MODEM_CAPABILITIES, "", "", - NM_TYPE_DEVICE_MODEM_CAPABILITIES, - NM_DEVICE_MODEM_CAPABILITY_NONE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MODEM_CAPABILITIES] = + g_param_spec_flags (NM_DEVICE_MODEM_MODEM_CAPABILITIES, "", "", + NM_TYPE_DEVICE_MODEM_CAPABILITIES, + NM_DEVICE_MODEM_CAPABILITY_NONE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceModem:current-capabilities: @@ -321,47 +304,45 @@ nm_device_modem_class_init (NMDeviceModemClass *modem_class) * The generic family of access technologies the modem currently supports * without a firmware reload or reinitialization. **/ - g_object_class_install_property - (object_class, PROP_CURRENT_CAPS, - g_param_spec_flags (NM_DEVICE_MODEM_CURRENT_CAPABILITIES, "", "", - NM_TYPE_DEVICE_MODEM_CAPABILITIES, - NM_DEVICE_MODEM_CAPABILITY_NONE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CURRENT_CAPABILITIES] = + g_param_spec_flags (NM_DEVICE_MODEM_CURRENT_CAPABILITIES, "", "", + NM_TYPE_DEVICE_MODEM_CAPABILITIES, + NM_DEVICE_MODEM_CAPABILITY_NONE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceModem:device-id: * * Since: 1.20 **/ - g_object_class_install_property - (object_class, PROP_CURRENT_CAPS, - g_param_spec_string (NM_DEVICE_MODEM_DEVICE_ID, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DEVICE_ID] = + g_param_spec_string (NM_DEVICE_MODEM_DEVICE_ID, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceModem:operator-code: * * Since: 1.20 **/ - g_object_class_install_property - (object_class, PROP_CURRENT_CAPS, - g_param_spec_string (NM_DEVICE_MODEM_OPERATOR_CODE, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_OPERATOR_CODE] = + g_param_spec_string (NM_DEVICE_MODEM_OPERATOR_CODE, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceModem:apn: * * Since: 1.20 **/ - g_object_class_install_property - (object_class, PROP_CURRENT_CAPS, - g_param_spec_string (NM_DEVICE_MODEM_APN, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_APN] = + g_param_spec_string (NM_DEVICE_MODEM_APN, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_modem); } diff --git a/libnm/nm-device-modem.h b/libnm/nm-device-modem.h index f6b1367f..48eed0e8 100644 --- a/libnm/nm-device-modem.h +++ b/libnm/nm-device-modem.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2011 - 2012 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright (C) 2011 - 2012 Red Hat, Inc. + * Copyright (C) 2008 Novell, Inc. */ #ifndef __NM_DEVICE_MODEM_H__ @@ -45,16 +31,7 @@ G_BEGIN_DECLS /** * NMDeviceModem: */ -struct _NMDeviceModem { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceModemClass; +typedef struct _NMDeviceModemClass NMDeviceModemClass; GType nm_device_modem_get_type (void); diff --git a/libnm/nm-device-olpc-mesh.c b/libnm/nm-device-olpc-mesh.c index 0bee96cb..1ad320bf 100644 --- a/libnm/nm-device-olpc-mesh.c +++ b/libnm/nm-device-olpc-mesh.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2012 Red Hat, Inc. + * Copyright (C) 2012 Red Hat, Inc. */ #include "nm-default.h" @@ -26,25 +12,35 @@ #include "nm-object-private.h" #include "nm-device-wifi.h" -G_DEFINE_TYPE (NMDeviceOlpcMesh, nm_device_olpc_mesh, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_OLPC_MESH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_OLPC_MESH, NMDeviceOlpcMeshPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, + PROP_COMPANION, + PROP_ACTIVE_CHANNEL, +); typedef struct { + NMLDBusPropertyO companion; char *hw_address; - NMDeviceWifi *companion; guint32 active_channel; } NMDeviceOlpcMeshPrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, - PROP_COMPANION, - PROP_ACTIVE_CHANNEL, +struct _NMDeviceOlpcMesh { + NMDevice parent; + NMDeviceOlpcMeshPrivate _priv; +}; - LAST_PROP +struct _NMDeviceOlpcMeshClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceOlpcMesh, nm_device_olpc_mesh, NM_TYPE_DEVICE) + +#define NM_DEVICE_OLPC_MESH_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceOlpcMesh, NM_IS_DEVICE_OLPC_MESH, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_olpc_mesh_get_hw_address: * @device: a #NMDeviceOlpcMesh @@ -59,7 +55,7 @@ nm_device_olpc_mesh_get_hw_address (NMDeviceOlpcMesh *device) { g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL); - return nm_str_not_empty (NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->hw_address); } /** @@ -75,7 +71,7 @@ nm_device_olpc_mesh_get_companion (NMDeviceOlpcMesh *device) { g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL); - return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->companion; + return nml_dbus_property_o_get_obj (&NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->companion); } /** @@ -129,34 +125,6 @@ nm_device_olpc_mesh_init (NMDeviceOlpcMesh *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_OLPC_MESH_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_OLPC_MESH_COMPANION, &priv->companion, NULL, NM_TYPE_DEVICE_WIFI }, - { NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL, &priv->active_channel }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_OLPC_MESH, - property_info); -} - -static void -dispose (GObject *object) -{ - NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object); - - g_clear_object (&priv->companion); - - G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->dispose (object); -} - -static void finalize (GObject *object) { NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object); @@ -190,62 +158,67 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_olpcmesh = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_OLPC_MESH, + nm_device_olpc_mesh_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_U ("ActiveChannel", PROP_ACTIVE_CHANNEL, NMDeviceOlpcMesh, _priv.active_channel ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Companion", PROP_COMPANION, NMDeviceOlpcMesh, _priv.companion, nm_device_wifi_get_type ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceOlpcMesh, _priv.hw_address ), + ), +); + static void -nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *olpc_mesh_class) +nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (olpc_mesh_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (olpc_mesh_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (olpc_mesh_class); - - g_type_class_add_private (olpc_mesh_class, sizeof (NMDeviceOlpcMeshPrivate)); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - /* virtual methods */ - object_class->dispose = dispose; - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceOlpcMesh); - device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; + _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceOlpcMeshPrivate, companion); - /* properties */ + device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceOlpcMesh:hw-address: * * The hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_OLPC_MESH_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_OLPC_MESH_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceOlpcMesh:companion: * * The companion device. **/ - g_object_class_install_property - (object_class, PROP_COMPANION, - g_param_spec_object (NM_DEVICE_OLPC_MESH_COMPANION, "", "", - NM_TYPE_DEVICE_WIFI, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_COMPANION] = + g_param_spec_object (NM_DEVICE_OLPC_MESH_COMPANION, "", "", + NM_TYPE_DEVICE_WIFI, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceOlpcMesh:active-channel: * * The device's active channel. **/ - g_object_class_install_property - (object_class, PROP_ACTIVE_CHANNEL, - g_param_spec_uint (NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL, "", "", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ACTIVE_CHANNEL] = + g_param_spec_uint (NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_olpcmesh); } diff --git a/libnm/nm-device-olpc-mesh.h b/libnm/nm-device-olpc-mesh.h index 8faceff1..2794e6ee 100644 --- a/libnm/nm-device-olpc-mesh.h +++ b/libnm/nm-device-olpc-mesh.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2012 Red Hat, Inc. + * Copyright (C) 2012 Red Hat, Inc. */ #ifndef __NM_DEVICE_OLPC_MESH_H__ @@ -42,16 +28,7 @@ G_BEGIN_DECLS /** * NMDeviceOlpcMesh: */ -struct _NMDeviceOlpcMesh { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceOlpcMeshClass; +typedef struct _NMDeviceOlpcMeshClass NMDeviceOlpcMeshClass; GType nm_device_olpc_mesh_get_type (void); diff --git a/libnm/nm-device-ovs-bridge.c b/libnm/nm-device-ovs-bridge.c index 4671c8a9..4b946fca 100644 --- a/libnm/nm-device-ovs-bridge.c +++ b/libnm/nm-device-ovs-bridge.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017,2018 Red Hat, Inc. + * Copyright (C) 2017, 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -27,19 +13,19 @@ #include "nm-setting-connection.h" #include "nm-core-internal.h" -enum { - PROP_0, +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_SLAVES, +); - LAST_PROP -}; +typedef struct { + NMLDBusPropertyAO slaves; +} NMDeviceOvsBridgePrivate; -/** - * NMDeviceOvsBridge: - */ struct _NMDeviceOvsBridge { NMDevice parent; - GPtrArray *slaves; + NMDeviceOvsBridgePrivate _priv; }; struct _NMDeviceOvsBridgeClass { @@ -48,6 +34,8 @@ struct _NMDeviceOvsBridgeClass { G_DEFINE_TYPE (NMDeviceOvsBridge, nm_device_ovs_bridge, NM_TYPE_DEVICE) +#define NM_DEVICE_OVS_BRIDGE_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceOvsBridge, NM_IS_DEVICE_OVS_BRIDGE, NMObject, NMDevice) + /*****************************************************************************/ /** @@ -67,7 +55,7 @@ nm_device_ovs_bridge_get_slaves (NMDeviceOvsBridge *device) { g_return_val_if_fail (NM_IS_DEVICE_OVS_BRIDGE (device), FALSE); - return device->slaves; + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_OVS_BRIDGE_GET_PRIVATE (device)->slaves); } static const char * @@ -109,22 +97,6 @@ get_setting_type (NMDevice *device) /*****************************************************************************/ static void -init_dbus (NMObject *object) -{ - NMDeviceOvsBridge *device = NM_DEVICE_OVS_BRIDGE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_OVS_BRIDGE_SLAVES, &device->slaves, NULL, NM_TYPE_DEVICE }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_ovs_bridge_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_OVS_BRIDGE, - property_info); -} - -static void get_property (GObject *object, guint prop_id, GValue *value, @@ -142,34 +114,51 @@ get_property (GObject *object, } } +/*****************************************************************************/ + static void nm_device_ovs_bridge_init (NMDeviceOvsBridge *device) { } -static void -dispose (GObject *object) -{ - NMDeviceOvsBridge *device = NM_DEVICE_OVS_BRIDGE (object); - - g_clear_pointer (&device->slaves, g_ptr_array_unref); - - G_OBJECT_CLASS (nm_device_ovs_bridge_parent_class)->dispose (object); -} +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsbridge = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_OVS_BRIDGE, + nm_device_ovs_bridge_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Slaves", PROP_SLAVES, NMDeviceOvsBridge, _priv.slaves, nm_device_get_type ), + ), +); static void -nm_device_ovs_bridge_class_init (NMDeviceOvsBridgeClass *ovs_bridge_class) +nm_device_ovs_bridge_class_init (NMDeviceOvsBridgeClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (ovs_bridge_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (ovs_bridge_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (ovs_bridge_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); object_class->get_property = get_property; - object_class->dispose = dispose; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceOvsBridge); + + _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceOvsBridgePrivate, slaves); - device_class->get_type_description = get_type_description; + device_class->get_type_description = get_type_description; device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; + device_class->get_setting_type = get_setting_type; + + /** + * NMDeviceOvsBridge:slaves: (type GPtrArray(NMDevice)) + * + * Gets the ports currently enslaved to the device. + * + * Since: 1.22 + */ + obj_properties[PROP_SLAVES] = + g_param_spec_boxed (NM_DEVICE_OVS_BRIDGE_SLAVES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_ovsbridge); } diff --git a/libnm/nm-device-ovs-bridge.h b/libnm/nm-device-ovs-bridge.h index 13d542a3..78aa352c 100644 --- a/libnm/nm-device-ovs-bridge.h +++ b/libnm/nm-device-ovs-bridge.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017,2018 Red Hat, Inc. + * Copyright (C) 2017, 2018 Red Hat, Inc. */ #ifndef __NM_DEVICE_OVS_BRIDGE_H__ @@ -37,6 +23,9 @@ G_BEGIN_DECLS #define NM_DEVICE_OVS_BRIDGE_SLAVES "slaves" +/** + * NMDeviceOvsBridge: + */ typedef struct _NMDeviceOvsBridgeClass NMDeviceOvsBridgeClass; NM_AVAILABLE_IN_1_10 diff --git a/libnm/nm-device-ovs-interface.c b/libnm/nm-device-ovs-interface.c index b07373e1..a2e3b2cf 100644 --- a/libnm/nm-device-ovs-interface.c +++ b/libnm/nm-device-ovs-interface.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017 Red Hat, Inc. + * Copyright (C) 2017 Red Hat, Inc. */ #include "nm-default.h" @@ -26,9 +12,8 @@ #include "nm-setting-ovs-port.h" #include "nm-setting-connection.h" -/** - * NMDeviceOvsInterface: - */ +/*****************************************************************************/ + struct _NMDeviceOvsInterface { NMDevice parent; }; @@ -84,6 +69,12 @@ nm_device_ovs_interface_init (NMDeviceOvsInterface *device) { } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsinterface = NML_DBUS_META_IFACE_INIT ( + NM_DBUS_INTERFACE_DEVICE_OVS_INTERFACE, + nm_device_ovs_interface_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, +); + static void nm_device_ovs_interface_class_init (NMDeviceOvsInterfaceClass *ovs_interface_class) { diff --git a/libnm/nm-device-ovs-interface.h b/libnm/nm-device-ovs-interface.h index a49db559..d9c81a33 100644 --- a/libnm/nm-device-ovs-interface.h +++ b/libnm/nm-device-ovs-interface.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017 Red Hat, Inc. + * Copyright (C) 2017 Red Hat, Inc. */ #ifndef __NM_DEVICE_OVS_INTERFACE_H__ @@ -35,6 +21,9 @@ G_BEGIN_DECLS #define NM_IS_DEVICE_OVS_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_OVS_INTERFACE)) #define NM_DEVICE_OVS_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_OVS_INTERFACE, NMDeviceOvsInterfaceClass)) +/** + * NMDeviceOvsInterface: + */ typedef struct _NMDeviceOvsInterfaceClass NMDeviceOvsInterfaceClass; NM_AVAILABLE_IN_1_10 diff --git a/libnm/nm-device-ovs-port.c b/libnm/nm-device-ovs-port.c index 49cf11cc..f8b963b1 100644 --- a/libnm/nm-device-ovs-port.c +++ b/libnm/nm-device-ovs-port.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017,2018 Red Hat, Inc. + * Copyright (C) 2017, 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -27,19 +13,19 @@ #include "nm-setting-connection.h" #include "nm-core-internal.h" -enum { - PROP_0, +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_SLAVES, +); - LAST_PROP -}; +typedef struct { + NMLDBusPropertyAO slaves; +} NMDeviceOvsPortPrivate; -/** - * NMDeviceOvsPort: - */ struct _NMDeviceOvsPort { NMDevice parent; - GPtrArray *slaves; + NMDeviceOvsPortPrivate _priv; }; struct _NMDeviceOvsPortClass { @@ -48,6 +34,8 @@ struct _NMDeviceOvsPortClass { G_DEFINE_TYPE (NMDeviceOvsPort, nm_device_ovs_port, NM_TYPE_DEVICE) +#define NM_DEVICE_OVS_PORT_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceOvsPort, NM_IS_DEVICE_OVS_PORT, NMObject, NMDevice) + /*****************************************************************************/ /** @@ -67,7 +55,7 @@ nm_device_ovs_port_get_slaves (NMDeviceOvsPort *device) { g_return_val_if_fail (NM_IS_DEVICE_OVS_PORT (device), FALSE); - return device->slaves; + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_OVS_PORT_GET_PRIVATE (device)->slaves); } static const char * @@ -109,22 +97,6 @@ get_setting_type (NMDevice *device) /*****************************************************************************/ static void -init_dbus (NMObject *object) -{ - NMDeviceOvsPort *device = NM_DEVICE_OVS_PORT (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_OVS_PORT_SLAVES, &device->slaves, NULL, NM_TYPE_DEVICE }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_ovs_port_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_OVS_PORT, - property_info); -} - -static void get_property (GObject *object, guint prop_id, GValue *value, @@ -142,34 +114,51 @@ get_property (GObject *object, } } +/*****************************************************************************/ + static void nm_device_ovs_port_init (NMDeviceOvsPort *device) { } -static void -dispose (GObject *object) -{ - NMDeviceOvsPort *device = NM_DEVICE_OVS_PORT (object); - - g_clear_pointer (&device->slaves, g_ptr_array_unref); - - G_OBJECT_CLASS (nm_device_ovs_port_parent_class)->dispose (object); -} +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsport = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_OVS_PORT, + nm_device_ovs_port_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Slaves", PROP_SLAVES, NMDeviceOvsPort, _priv.slaves, nm_device_get_type ), + ), +); static void -nm_device_ovs_port_class_init (NMDeviceOvsPortClass *ovs_port_class) +nm_device_ovs_port_class_init (NMDeviceOvsPortClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (ovs_port_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (ovs_port_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (ovs_port_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); object_class->get_property = get_property; - object_class->dispose = dispose; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceOvsPort); + + _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceOvsPortPrivate, slaves); - device_class->get_type_description = get_type_description; + device_class->get_type_description = get_type_description; device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; + device_class->get_setting_type = get_setting_type; + + /** + * NMDeviceOvsPort:slaves: (type GPtrArray(NMDevice)) + * + * Gets the interfaces currently enslaved to the device. + * + * Since: 1.22 + */ + obj_properties[PROP_SLAVES] = + g_param_spec_boxed (NM_DEVICE_OVS_PORT_SLAVES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_ovsport); } diff --git a/libnm/nm-device-ovs-port.h b/libnm/nm-device-ovs-port.h index 088e3692..9982104e 100644 --- a/libnm/nm-device-ovs-port.h +++ b/libnm/nm-device-ovs-port.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017,2018 Red Hat, Inc. + * Copyright (C) 2017, 2018 Red Hat, Inc. */ #ifndef __NM_DEVICE_OVS_PORT_H__ @@ -37,6 +23,9 @@ G_BEGIN_DECLS #define NM_DEVICE_OVS_PORT_SLAVES "slaves" +/** + * NMDeviceOvsPort: + */ typedef struct _NMDeviceOvsPortClass NMDeviceOvsPortClass; NM_AVAILABLE_IN_1_10 diff --git a/libnm/nm-device-ppp.c b/libnm/nm-device-ppp.c index 046cf73e..0484546e 100644 --- a/libnm/nm-device-ppp.c +++ b/libnm/nm-device-ppp.c @@ -1,20 +1,16 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Copyright 2017 Red Hat, Inc. + * Copyright (C) 2017 Red Hat, Inc. */ #include "nm-default.h" #include "nm-device-ppp.h" + #include "nm-device.h" +/*****************************************************************************/ + struct _NMDevicePpp { NMDevice parent; }; @@ -25,13 +21,19 @@ struct _NMDevicePppClass { G_DEFINE_TYPE (NMDevicePpp, nm_device_ppp, NM_TYPE_DEVICE) -#define NM_DEVICE_PPP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_PPP, NMDevicePppPrivate)) +/*****************************************************************************/ static void nm_device_ppp_init (NMDevicePpp *device) { } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ppp = NML_DBUS_META_IFACE_INIT ( + NM_DBUS_INTERFACE_DEVICE_PPP, + nm_device_ppp_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, +); + static void nm_device_ppp_class_init (NMDevicePppClass *klass) { diff --git a/libnm/nm-device-ppp.h b/libnm/nm-device-ppp.h index 1163157c..4a71de47 100644 --- a/libnm/nm-device-ppp.h +++ b/libnm/nm-device-ppp.h @@ -1,13 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Copyright 2017 Red Hat, Inc. + * Copyright (C) 2017 Red Hat, Inc. */ #ifndef __NM_DEVICE_PPP_H__ @@ -26,6 +19,9 @@ G_BEGIN_DECLS #define NM_IS_DEVICE_PPP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_PPP)) #define NM_DEVICE_PPP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_PPP, NMDevicePppClass)) +/** + * NMDevicePpp: + */ typedef struct _NMDevicePppClass NMDevicePppClass; GType nm_device_ppp_get_type (void); diff --git a/libnm/nm-device-team.c b/libnm/nm-device-team.c index 54b108be..a1c04c18 100644 --- a/libnm/nm-device-team.c +++ b/libnm/nm-device-team.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2013 Jiri Pirko <jiri@resnulli.us> + * Copyright (C) 2013 Jiri Pirko <jiri@resnulli.us> */ #include "nm-default.h" @@ -27,27 +13,37 @@ #include "nm-object-private.h" #include "nm-core-internal.h" -G_DEFINE_TYPE (NMDeviceTeam, nm_device_team, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_TEAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_TEAM, NMDeviceTeamPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, + PROP_CARRIER, + PROP_SLAVES, + PROP_CONFIG, +); typedef struct { + NMLDBusPropertyAO slaves; char *hw_address; - gboolean carrier; - GPtrArray *slaves; char *config; + bool carrier; } NMDeviceTeamPrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, - PROP_CARRIER, - PROP_SLAVES, - PROP_CONFIG, +struct _NMDeviceTeam { + NMDevice parent; + NMDeviceTeamPrivate _priv; +}; - LAST_PROP +struct _NMDeviceTeamClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceTeam, nm_device_team, NM_TYPE_DEVICE) + +#define NM_DEVICE_TEAM_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceTeam, NM_IS_DEVICE_TEAM, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_team_get_hw_address: * @device: a #NMDeviceTeam @@ -62,7 +58,7 @@ nm_device_team_get_hw_address (NMDeviceTeam *device) { g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), NULL); - return nm_str_not_empty (NM_DEVICE_TEAM_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_TEAM_GET_PRIVATE (device)->hw_address); } /** @@ -96,7 +92,7 @@ nm_device_team_get_slaves (NMDeviceTeam *device) { g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), FALSE); - return NM_DEVICE_TEAM_GET_PRIVATE (device)->slaves; + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_TEAM_GET_PRIVATE (device)->slaves); } /** @@ -115,7 +111,7 @@ nm_device_team_get_config (NMDeviceTeam *device) { g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), NULL); - return nm_str_not_empty (NM_DEVICE_TEAM_GET_PRIVATE (device)->config); + return _nml_coerce_property_str_not_empty (NM_DEVICE_TEAM_GET_PRIVATE (device)->config); } static const char * @@ -152,38 +148,6 @@ get_setting_type (NMDevice *device) static void nm_device_team_init (NMDeviceTeam *device) { - NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (device); - - priv->slaves = g_ptr_array_new (); -} - -static void -init_dbus (NMObject *object) -{ - NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_TEAM_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_TEAM_CARRIER, &priv->carrier }, - { NM_DEVICE_TEAM_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE }, - { NM_DEVICE_TEAM_CONFIG, &priv->config }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_team_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_TEAM, - property_info); -} - -static void -dispose (GObject *object) -{ - NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (object); - - g_clear_pointer (&priv->slaves, g_ptr_array_unref); - - G_OBJECT_CLASS (nm_device_team_parent_class)->dispose (object); } static void @@ -224,63 +188,68 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_team = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_TEAM, + nm_device_team_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceTeam, _priv.carrier ), + NML_DBUS_META_PROPERTY_INIT_S ("Config", PROP_CONFIG, NMDeviceTeam, _priv.config ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceTeam, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Slaves", PROP_SLAVES, NMDeviceTeam, _priv.slaves, nm_device_get_type ), + ), +); + static void -nm_device_team_class_init (NMDeviceTeamClass *team_class) +nm_device_team_class_init (NMDeviceTeamClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (team_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (team_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (team_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - g_type_class_add_private (team_class, sizeof (NMDeviceTeamPrivate)); - - /* virtual methods */ - object_class->dispose = dispose; - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceTeam); - device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; + _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceTeamPrivate, slaves); - /* properties */ + device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceTeam:hw-address: * * The hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_TEAM_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_TEAM_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceTeam:carrier: * * Whether the device has carrier. **/ - g_object_class_install_property - (object_class, PROP_CARRIER, - g_param_spec_boolean (NM_DEVICE_TEAM_CARRIER, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CARRIER] = + g_param_spec_boolean (NM_DEVICE_TEAM_CARRIER, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceTeam:slaves: (type GPtrArray(NMDevice)) * * The devices enslaved to the team device. **/ - g_object_class_install_property - (object_class, PROP_SLAVES, - g_param_spec_boxed (NM_DEVICE_TEAM_SLAVES, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_SLAVES] = + g_param_spec_boxed (NM_DEVICE_TEAM_SLAVES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceTeam:config: @@ -289,10 +258,11 @@ nm_device_team_class_init (NMDeviceTeamClass *team_class) * * Since: 1.4 **/ - g_object_class_install_property - (object_class, PROP_CONFIG, - g_param_spec_string (NM_DEVICE_TEAM_CONFIG, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CONFIG] = + g_param_spec_string (NM_DEVICE_TEAM_CONFIG, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_team); } diff --git a/libnm/nm-device-team.h b/libnm/nm-device-team.h index 5f14c26b..8bc0d2cd 100644 --- a/libnm/nm-device-team.h +++ b/libnm/nm-device-team.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2013 Jiri Pirko <jiri@resnulli.us> + * Copyright (C) 2013 Jiri Pirko <jiri@resnulli.us> */ #ifndef __NM_DEVICE_TEAM_H__ @@ -43,16 +29,7 @@ G_BEGIN_DECLS /** * NMDeviceTeam: */ -struct _NMDeviceTeam { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceTeamClass; +typedef struct _NMDeviceTeamClass NMDeviceTeamClass; GType nm_device_team_get_type (void); diff --git a/libnm/nm-device-tun.c b/libnm/nm-device-tun.c index d81ef473..cc84774b 100644 --- a/libnm/nm-device-tun.c +++ b/libnm/nm-device-tun.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2015 Red Hat, Inc. + * Copyright (C) 2015 Red Hat, Inc. */ #include "nm-default.h" @@ -28,33 +14,43 @@ #include "nm-utils.h" #include "nm-object-private.h" -G_DEFINE_TYPE (NMDeviceTun, nm_device_tun, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_TUN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_TUN, NMDeviceTunPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, + PROP_MODE, + PROP_OWNER, + PROP_GROUP, + PROP_NO_PI, + PROP_VNET_HDR, + PROP_MULTI_QUEUE, +); typedef struct { char *hw_address; char *mode; gint64 owner; gint64 group; - gboolean no_pi; - gboolean vnet_hdr; - gboolean multi_queue; + bool no_pi; + bool vnet_hdr; + bool multi_queue; } NMDeviceTunPrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, - PROP_MODE, - PROP_OWNER, - PROP_GROUP, - PROP_NO_PI, - PROP_VNET_HDR, - PROP_MULTI_QUEUE, +struct _NMDeviceTun { + NMDevice parent; + NMDeviceTunPrivate _priv; +}; - LAST_PROP +struct _NMDeviceTunClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceTun, nm_device_tun, NM_TYPE_DEVICE) + +#define NM_DEVICE_TUN_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceTun, NM_IS_DEVICE_TUN, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_tun_get_hw_address: * @device: a #NMDeviceTun @@ -71,7 +67,7 @@ nm_device_tun_get_hw_address (NMDeviceTun *device) { g_return_val_if_fail (NM_IS_DEVICE_TUN (device), NULL); - return nm_str_not_empty (NM_DEVICE_TUN_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_TUN_GET_PRIVATE (device)->hw_address); } /** @@ -89,7 +85,7 @@ nm_device_tun_get_mode (NMDeviceTun *device) { g_return_val_if_fail (NM_IS_DEVICE_TUN (device), NULL); - return nm_str_not_empty (NM_DEVICE_TUN_GET_PRIVATE (device)->mode); + return _nml_coerce_property_str_not_empty (NM_DEVICE_TUN_GET_PRIVATE (device)->mode); } /** @@ -239,28 +235,6 @@ nm_device_tun_init (NMDeviceTun *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_TUN_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_TUN_MODE, &priv->mode }, - { NM_DEVICE_TUN_OWNER, &priv->owner }, - { NM_DEVICE_TUN_GROUP, &priv->group }, - { NM_DEVICE_TUN_NO_PI, &priv->no_pi }, - { NM_DEVICE_TUN_VNET_HDR, &priv->vnet_hdr }, - { NM_DEVICE_TUN_MULTI_QUEUE, &priv->multi_queue }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_tun_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_TUN, - property_info); -} - -static void finalize (GObject *object) { NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE (object); @@ -308,26 +282,33 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_tun = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_TUN, + nm_device_tun_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_X ("Group", PROP_GROUP, NMDeviceTun, _priv.group ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceTun, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_S ("Mode", PROP_MODE, NMDeviceTun, _priv.mode ), + NML_DBUS_META_PROPERTY_INIT_B ("MultiQueue", PROP_MULTI_QUEUE, NMDeviceTun, _priv.multi_queue ), + NML_DBUS_META_PROPERTY_INIT_B ("NoPi", PROP_NO_PI, NMDeviceTun, _priv.no_pi ), + NML_DBUS_META_PROPERTY_INIT_X ("Owner", PROP_OWNER, NMDeviceTun, _priv.owner ), + NML_DBUS_META_PROPERTY_INIT_B ("VnetHdr", PROP_VNET_HDR, NMDeviceTun, _priv.vnet_hdr ), + ), +); + static void nm_device_tun_class_init (NMDeviceTunClass *gre_class) { GObjectClass *object_class = G_OBJECT_CLASS (gre_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (gre_class); NMDeviceClass *device_class = NM_DEVICE_CLASS (gre_class); - g_type_class_add_private (gre_class, sizeof (NMDeviceTunPrivate)); - - /* virtual methods */ - object_class->finalize = finalize; object_class->get_property = get_property; - - nm_object_class->init_dbus = init_dbus; + object_class->finalize = finalize; device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; - - /* properties */ + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceTun:hw-address: @@ -336,12 +317,11 @@ nm_device_tun_class_init (NMDeviceTunClass *gre_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_TUN_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_TUN_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceTun:mode: @@ -350,12 +330,11 @@ nm_device_tun_class_init (NMDeviceTunClass *gre_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_MODE, - g_param_spec_string (NM_DEVICE_TUN_MODE, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MODE] = + g_param_spec_string (NM_DEVICE_TUN_MODE, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceTun:owner: @@ -364,12 +343,11 @@ nm_device_tun_class_init (NMDeviceTunClass *gre_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_OWNER, - g_param_spec_int64 (NM_DEVICE_TUN_OWNER, "", "", - -1, G_MAXUINT32, -1, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_OWNER] = + g_param_spec_int64 (NM_DEVICE_TUN_OWNER, "", "", + -1, G_MAXUINT32, -1, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceTun:group: @@ -378,12 +356,11 @@ nm_device_tun_class_init (NMDeviceTunClass *gre_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_GROUP, - g_param_spec_int64 (NM_DEVICE_TUN_GROUP, "", "", - -1, G_MAXUINT32, -1, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_GROUP] = + g_param_spec_int64 (NM_DEVICE_TUN_GROUP, "", "", + -1, G_MAXUINT32, -1, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceTun:no-pi: @@ -393,12 +370,11 @@ nm_device_tun_class_init (NMDeviceTunClass *gre_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_NO_PI, - g_param_spec_boolean (NM_DEVICE_TUN_NO_PI, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_NO_PI] = + g_param_spec_boolean (NM_DEVICE_TUN_NO_PI, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceTun:vnet-hdr: @@ -408,12 +384,11 @@ nm_device_tun_class_init (NMDeviceTunClass *gre_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_VNET_HDR, - g_param_spec_boolean (NM_DEVICE_TUN_VNET_HDR, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_VNET_HDR] = + g_param_spec_boolean (NM_DEVICE_TUN_VNET_HDR, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceTun:multi-queue: @@ -424,10 +399,11 @@ nm_device_tun_class_init (NMDeviceTunClass *gre_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_MULTI_QUEUE, - g_param_spec_boolean (NM_DEVICE_TUN_MULTI_QUEUE, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MULTI_QUEUE] = + g_param_spec_boolean (NM_DEVICE_TUN_MULTI_QUEUE, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_tun); } diff --git a/libnm/nm-device-tun.h b/libnm/nm-device-tun.h index 231b956f..bcb2cbb3 100644 --- a/libnm/nm-device-tun.h +++ b/libnm/nm-device-tun.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2015 Red Hat, Inc. + * Copyright (C) 2015 Red Hat, Inc. */ #ifndef __NM_DEVICE_TUN_H__ @@ -46,16 +32,7 @@ G_BEGIN_DECLS /** * NMDeviceTun: */ -struct _NMDeviceTun { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceTunClass; +typedef struct _NMDeviceTunClass NMDeviceTunClass; NM_AVAILABLE_IN_1_2 GType nm_device_tun_get_type (void); diff --git a/libnm/nm-device-vlan.c b/libnm/nm-device-vlan.c index ede50cc7..ee57d0f4 100644 --- a/libnm/nm-device-vlan.c +++ b/libnm/nm-device-vlan.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2012 Red Hat, Inc. + * Copyright (C) 2012 Red Hat, Inc. */ #include "nm-default.h" @@ -27,27 +13,37 @@ #include "nm-utils.h" #include "nm-object-private.h" -G_DEFINE_TYPE (NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE) +/*****************************************************************************/ -#define NM_DEVICE_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_VLAN, NMDeviceVlanPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, + PROP_CARRIER, + PROP_PARENT, + PROP_VLAN_ID, +); typedef struct { + NMLDBusPropertyO parent; char *hw_address; - gboolean carrier; - NMDevice *parent; - guint vlan_id; + guint32 vlan_id; + bool carrier; } NMDeviceVlanPrivate; -enum { - PROP_0, - PROP_HW_ADDRESS, - PROP_CARRIER, - PROP_PARENT, - PROP_VLAN_ID, +struct _NMDeviceVlan { + NMDevice parent; + NMDeviceVlanPrivate _priv; +}; - LAST_PROP +struct _NMDeviceVlanClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE) + +#define NM_DEVICE_VLAN_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceVlan, NM_IS_DEVICE_VLAN, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_vlan_get_hw_address: * @device: a #NMDeviceVlan @@ -62,7 +58,7 @@ nm_device_vlan_get_hw_address (NMDeviceVlan *device) { g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), NULL); - return nm_str_not_empty (NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address); } /** @@ -92,7 +88,7 @@ nm_device_vlan_get_parent (NMDeviceVlan *device) { g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), FALSE); - return NM_DEVICE_VLAN_GET_PRIVATE (device)->parent; + return nml_dbus_property_o_get_obj (&NM_DEVICE_VLAN_GET_PRIVATE (device)->parent); } /** @@ -171,31 +167,11 @@ nm_device_vlan_init (NMDeviceVlan *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_VLAN_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_VLAN_CARRIER, &priv->carrier }, - { NM_DEVICE_VLAN_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE }, - { NM_DEVICE_VLAN_VLAN_ID, &priv->vlan_id }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_vlan_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_VLAN, - property_info); -} - -static void finalize (GObject *object) { NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object); g_free (priv->hw_address); - g_clear_object (&priv->parent); G_OBJECT_CLASS (nm_device_vlan_parent_class)->finalize (object); } @@ -227,72 +203,79 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vlan = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_VLAN, + nm_device_vlan_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceVlan, _priv.carrier ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceVlan, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDeviceVlan, _priv.parent, nm_device_get_type ), + NML_DBUS_META_PROPERTY_INIT_U ("VlanId", PROP_VLAN_ID, NMDeviceVlan, _priv.vlan_id ), + ), +); + static void -nm_device_vlan_class_init (NMDeviceVlanClass *vlan_class) +nm_device_vlan_class_init (NMDeviceVlanClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (vlan_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (vlan_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (vlan_class); - - g_type_class_add_private (vlan_class, sizeof (NMDeviceVlanPrivate)); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - /* virtual methods */ - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceVlan); - device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; + _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceVlanPrivate, parent); - /* properties */ + device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceVlan:hw-address: * * The hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_VLAN_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_VLAN_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVlan:carrier: * * Whether the device has carrier. **/ - g_object_class_install_property - (object_class, PROP_CARRIER, - g_param_spec_boolean (NM_DEVICE_VLAN_CARRIER, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CARRIER] = + g_param_spec_boolean (NM_DEVICE_VLAN_CARRIER, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVlan:parent: * * The devices's parent device. **/ - g_object_class_install_property - (object_class, PROP_PARENT, - g_param_spec_object (NM_DEVICE_VLAN_PARENT, "", "", - NM_TYPE_DEVICE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PARENT] = + g_param_spec_object (NM_DEVICE_VLAN_PARENT, "", "", + NM_TYPE_DEVICE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVlan:vlan-id: * * The device's VLAN ID. **/ - g_object_class_install_property - (object_class, PROP_VLAN_ID, - g_param_spec_uint (NM_DEVICE_VLAN_VLAN_ID, "", "", - 0, 4095, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_VLAN_ID] = + g_param_spec_uint (NM_DEVICE_VLAN_VLAN_ID, "", "", + 0, 4095, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_vlan); } diff --git a/libnm/nm-device-vlan.h b/libnm/nm-device-vlan.h index 352b0488..7a412cb0 100644 --- a/libnm/nm-device-vlan.h +++ b/libnm/nm-device-vlan.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2012 - 2014 Red Hat, Inc. + * Copyright (C) 2012 - 2014 Red Hat, Inc. */ #ifndef __NM_DEVICE_VLAN_H__ @@ -43,16 +29,7 @@ G_BEGIN_DECLS /** * NMDeviceVlan: */ -struct _NMDeviceVlan { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceVlanClass; +typedef struct _NMDeviceVlanClass NMDeviceVlanClass; GType nm_device_vlan_get_type (void); diff --git a/libnm/nm-device-vxlan.c b/libnm/nm-device-vxlan.c index 77eb9a9f..4397977c 100644 --- a/libnm/nm-device-vxlan.c +++ b/libnm/nm-device-vxlan.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2015 Red Hat, Inc. + * Copyright (C) 2015 Red Hat, Inc. */ #include "nm-default.h" @@ -26,33 +12,9 @@ #include "nm-utils.h" #include "nm-object-private.h" -G_DEFINE_TYPE (NMDeviceVxlan, nm_device_vxlan, NM_TYPE_DEVICE) - -#define NM_DEVICE_VXLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_VXLAN, NMDeviceVxlanPrivate)) - -typedef struct { - NMDevice *parent; - char *hw_address; - gboolean carrier; - guint id; - char *group; - char *local; - guint src_port_min; - guint src_port_max; - guint dst_port; - guint tos; - guint ttl; - guint limit; - gboolean learning; - guint ageing; - gboolean proxy; - gboolean rsc; - gboolean l2miss; - gboolean l3miss; -} NMDeviceVxlanPrivate; +/*****************************************************************************/ -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_HW_ADDRESS, PROP_CARRIER, PROP_PARENT, @@ -71,10 +33,43 @@ enum { PROP_RSC, PROP_L2MISS, PROP_L3MISS, +); - LAST_PROP +typedef struct { + NMLDBusPropertyO parent; + char *hw_address; + char *group; + char *local; + guint32 id; + guint32 limit; + guint32 ageing; + guint16 src_port_min; + guint16 src_port_max; + guint16 dst_port; + guint8 tos; + guint8 ttl; + bool learning; + bool proxy; + bool rsc; + bool l2miss; + bool l3miss; +} NMDeviceVxlanPrivate; + +struct _NMDeviceVxlan { + NMDevice parent; + NMDeviceVxlanPrivate _priv; +}; + +struct _NMDeviceVxlanClass { + NMDeviceClass parent; }; +G_DEFINE_TYPE (NMDeviceVxlan, nm_device_vxlan, NM_TYPE_DEVICE) + +#define NM_DEVICE_VXLAN_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceVxlan, NM_IS_DEVICE_VXLAN, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_vxlan_get_hw_address: * @device: a #NMDeviceVxlan @@ -91,7 +86,7 @@ nm_device_vxlan_get_hw_address (NMDeviceVxlan *device) { g_return_val_if_fail (NM_IS_DEVICE_VXLAN (device), NULL); - return nm_str_not_empty (NM_DEVICE_VXLAN_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_VXLAN_GET_PRIVATE (device)->hw_address); } /** @@ -103,13 +98,16 @@ nm_device_vxlan_get_hw_address (NMDeviceVxlan *device) * Returns: %TRUE if the device has carrier. * * Since: 1.2 + * + * This property is not implemented yet, and the function always returns + * FALSE. **/ gboolean nm_device_vxlan_get_carrier (NMDeviceVxlan *device) { g_return_val_if_fail (NM_IS_DEVICE_VXLAN (device), FALSE); - return NM_DEVICE_VXLAN_GET_PRIVATE (device)->carrier; + return FALSE; } /** @@ -125,7 +123,7 @@ nm_device_vxlan_get_parent (NMDeviceVxlan *device) { g_return_val_if_fail (NM_IS_DEVICE_VXLAN (device), NULL); - return NM_DEVICE_VXLAN_GET_PRIVATE (device)->parent; + return nml_dbus_property_o_get_obj (&NM_DEVICE_VXLAN_GET_PRIVATE (device)->parent); } /** @@ -158,7 +156,7 @@ nm_device_vxlan_get_group (NMDeviceVxlan *device) { g_return_val_if_fail (NM_IS_DEVICE_VXLAN (device), NULL); - return nm_str_not_empty (NM_DEVICE_VXLAN_GET_PRIVATE (device)->group); + return _nml_coerce_property_str_not_empty (NM_DEVICE_VXLAN_GET_PRIVATE (device)->group); } /** @@ -174,7 +172,7 @@ nm_device_vxlan_get_local (NMDeviceVxlan *device) { g_return_val_if_fail (NM_IS_DEVICE_VXLAN (device), NULL); - return nm_str_not_empty (NM_DEVICE_VXLAN_GET_PRIVATE (device)->local); + return _nml_coerce_property_str_not_empty (NM_DEVICE_VXLAN_GET_PRIVATE (device)->local); } /** @@ -414,45 +412,11 @@ nm_device_vxlan_init (NMDeviceVxlan *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_VXLAN_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_VXLAN_CARRIER, &priv->carrier }, - { NM_DEVICE_VXLAN_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE }, - { NM_DEVICE_VXLAN_ID, &priv->id }, - { NM_DEVICE_VXLAN_GROUP, &priv->group }, - { NM_DEVICE_VXLAN_LOCAL, &priv->local }, - { NM_DEVICE_VXLAN_SRC_PORT_MIN, &priv->src_port_min }, - { NM_DEVICE_VXLAN_SRC_PORT_MAX, &priv->src_port_max }, - { NM_DEVICE_VXLAN_DST_PORT, &priv->dst_port }, - { NM_DEVICE_VXLAN_TOS, &priv->tos }, - { NM_DEVICE_VXLAN_TTL, &priv->ttl }, - { NM_DEVICE_VXLAN_LIMIT, &priv->limit }, - { NM_DEVICE_VXLAN_LEARNING, &priv->learning }, - { NM_DEVICE_VXLAN_AGEING, &priv->ageing }, - { NM_DEVICE_VXLAN_PROXY, &priv->proxy }, - { NM_DEVICE_VXLAN_RSC, &priv->rsc }, - { NM_DEVICE_VXLAN_L2MISS, &priv->l2miss }, - { NM_DEVICE_VXLAN_L3MISS, &priv->l3miss }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_vxlan_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_VXLAN, - property_info); -} - -static void finalize (GObject *object) { NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE (object); g_free (priv->hw_address); - g_clear_object (&priv->parent); g_free (priv->group); g_free (priv->local); @@ -528,26 +492,48 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vxlan = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_VXLAN, + nm_device_vxlan_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_U ("Ageing", PROP_AGEING, NMDeviceVxlan, _priv.ageing ), + NML_DBUS_META_PROPERTY_INIT_Q ("DstPort", PROP_DST_PORT, NMDeviceVxlan, _priv.dst_port ), + NML_DBUS_META_PROPERTY_INIT_S ("Group", PROP_GROUP, NMDeviceVxlan, _priv.group ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceVxlan, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_U ("Id", PROP_ID, NMDeviceVxlan, _priv.id ), + NML_DBUS_META_PROPERTY_INIT_B ("L2miss", PROP_L2MISS, NMDeviceVxlan, _priv.l2miss ), + NML_DBUS_META_PROPERTY_INIT_B ("L3miss", PROP_L3MISS, NMDeviceVxlan, _priv.l3miss ), + NML_DBUS_META_PROPERTY_INIT_B ("Learning", PROP_LEARNING, NMDeviceVxlan, _priv.learning ), + NML_DBUS_META_PROPERTY_INIT_U ("Limit", PROP_LIMIT, NMDeviceVxlan, _priv.limit ), + NML_DBUS_META_PROPERTY_INIT_S ("Local", PROP_LOCAL, NMDeviceVxlan, _priv.local ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDeviceVxlan, _priv.parent, nm_device_get_type ), + NML_DBUS_META_PROPERTY_INIT_B ("Proxy", PROP_PROXY, NMDeviceVxlan, _priv.proxy ), + NML_DBUS_META_PROPERTY_INIT_B ("Rsc", PROP_RSC, NMDeviceVxlan, _priv.rsc ), + NML_DBUS_META_PROPERTY_INIT_Q ("SrcPortMax", PROP_SRC_PORT_MAX, NMDeviceVxlan, _priv.src_port_max ), + NML_DBUS_META_PROPERTY_INIT_Q ("SrcPortMin", PROP_SRC_PORT_MIN, NMDeviceVxlan, _priv.src_port_min ), + NML_DBUS_META_PROPERTY_INIT_Y ("Tos", PROP_TOS, NMDeviceVxlan, _priv.tos ), + NML_DBUS_META_PROPERTY_INIT_Y ("Ttl", PROP_TTL, NMDeviceVxlan, _priv.ttl ), + ), +); + static void -nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) +nm_device_vxlan_class_init (NMDeviceVxlanClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (vxlan_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (vxlan_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (vxlan_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - g_type_class_add_private (vxlan_class, sizeof (NMDeviceVxlanPrivate)); - - /* virtual methods */ - object_class->finalize = finalize; object_class->get_property = get_property; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceVxlan); - device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; + _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceVxlanPrivate, parent); - /* properties */ + device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceVxlan:hw-address: @@ -556,12 +542,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_VXLAN_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_VXLAN_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:carrier: @@ -569,13 +554,14 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * Whether the device has carrier. * * Since: 1.2 + * + * This property is not implemented yet, and the property is always FALSE. **/ - g_object_class_install_property - (object_class, PROP_CARRIER, - g_param_spec_boolean (NM_DEVICE_VXLAN_CARRIER, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CARRIER] = + g_param_spec_boolean (NM_DEVICE_VXLAN_CARRIER, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:parent: @@ -584,12 +570,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_PARENT, - g_param_spec_object (NM_DEVICE_VXLAN_PARENT, "", "", - NM_TYPE_DEVICE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PARENT] = + g_param_spec_object (NM_DEVICE_VXLAN_PARENT, "", "", + NM_TYPE_DEVICE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:id: @@ -598,12 +583,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_ID, - g_param_spec_uint (NM_DEVICE_VXLAN_ID, "", "", - 0, (1 << 24) - 1, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ID] = + g_param_spec_uint (NM_DEVICE_VXLAN_ID, "", "", + 0, (1 << 24) - 1, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:group: @@ -614,12 +598,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_GROUP, - g_param_spec_string (NM_DEVICE_VXLAN_GROUP, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_GROUP] = + g_param_spec_string (NM_DEVICE_VXLAN_GROUP, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:local: @@ -628,12 +611,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_LOCAL, - g_param_spec_string (NM_DEVICE_VXLAN_LOCAL, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_LOCAL] = + g_param_spec_string (NM_DEVICE_VXLAN_LOCAL, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:tos: @@ -642,12 +624,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_TOS, - g_param_spec_uchar (NM_DEVICE_VXLAN_TOS, "", "", - 0, 255, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_TOS] = + g_param_spec_uchar (NM_DEVICE_VXLAN_TOS, "", "", + 0, 255, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:ttl: @@ -656,12 +637,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_TTL, - g_param_spec_uchar (NM_DEVICE_VXLAN_TTL, "", "", - 0, 255, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_TTL] = + g_param_spec_uchar (NM_DEVICE_VXLAN_TTL, "", "", + 0, 255, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:learning: @@ -671,12 +651,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_LEARNING, - g_param_spec_boolean (NM_DEVICE_VXLAN_LEARNING, "", "", - TRUE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_LEARNING] = + g_param_spec_boolean (NM_DEVICE_VXLAN_LEARNING, "", "", + TRUE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:ageing: @@ -685,12 +664,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_AGEING, - g_param_spec_uint (NM_DEVICE_VXLAN_AGEING, "", "", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_AGEING] = + g_param_spec_uint (NM_DEVICE_VXLAN_AGEING, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:limit: @@ -699,12 +677,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_LIMIT, - g_param_spec_uint (NM_DEVICE_VXLAN_LIMIT, "", "", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_LIMIT] = + g_param_spec_uint (NM_DEVICE_VXLAN_LIMIT, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:dst-port: @@ -714,12 +691,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_DST_PORT, - g_param_spec_uint (NM_DEVICE_VXLAN_DST_PORT, "", "", - 0, 65535, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DST_PORT] = + g_param_spec_uint (NM_DEVICE_VXLAN_DST_PORT, "", "", + 0, 65535, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:src-port-min: @@ -729,12 +705,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_SRC_PORT_MIN, - g_param_spec_uint (NM_DEVICE_VXLAN_SRC_PORT_MIN, "", "", - 0, 65535, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_SRC_PORT_MIN] = + g_param_spec_uint (NM_DEVICE_VXLAN_SRC_PORT_MIN, "", "", + 0, 65535, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:src-port-max: @@ -744,12 +719,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_SRC_PORT_MAX, - g_param_spec_uint (NM_DEVICE_VXLAN_SRC_PORT_MAX, "", "", - 0, 65535, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_SRC_PORT_MAX] = + g_param_spec_uint (NM_DEVICE_VXLAN_SRC_PORT_MAX, "", "", + 0, 65535, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:proxy: @@ -758,12 +732,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_PROXY, - g_param_spec_boolean (NM_DEVICE_VXLAN_PROXY, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PROXY] = + g_param_spec_boolean (NM_DEVICE_VXLAN_PROXY, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:rsc: @@ -772,12 +745,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_RSC, - g_param_spec_boolean (NM_DEVICE_VXLAN_RSC, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_RSC] = + g_param_spec_boolean (NM_DEVICE_VXLAN_RSC, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:l2miss: @@ -786,12 +758,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_L2MISS, - g_param_spec_boolean (NM_DEVICE_VXLAN_L2MISS, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_L2MISS] = + g_param_spec_boolean (NM_DEVICE_VXLAN_L2MISS, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceVxlan:l3miss: @@ -800,10 +771,11 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_L3MISS, - g_param_spec_boolean (NM_DEVICE_VXLAN_L3MISS, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_L3MISS] = + g_param_spec_boolean (NM_DEVICE_VXLAN_L3MISS, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_vxlan); } diff --git a/libnm/nm-device-vxlan.h b/libnm/nm-device-vxlan.h index 305ff1ea..fef2365f 100644 --- a/libnm/nm-device-vxlan.h +++ b/libnm/nm-device-vxlan.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2015 Red Hat, Inc. + * Copyright (C) 2015 Red Hat, Inc. */ #ifndef __NM_DEVICE_VXLAN_H__ @@ -57,16 +43,7 @@ G_BEGIN_DECLS /** * NMDeviceVxlan: */ -struct _NMDeviceVxlan { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMDeviceVxlanClass; +typedef struct _NMDeviceVxlanClass NMDeviceVxlanClass; NM_AVAILABLE_IN_1_2 GType nm_device_vxlan_get_type (void); diff --git a/libnm/nm-device-wifi-p2p.c b/libnm/nm-device-wifi-p2p.c index 01397738..191d30eb 100644 --- a/libnm/nm-device-wifi-p2p.c +++ b/libnm/nm-device-wifi-p2p.c @@ -1,26 +1,13 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 - 2019 Red Hat, Inc. + * Copyright (C) 2018 - 2019 Red Hat, Inc. */ #include "nm-default.h" #include "nm-device-wifi-p2p.h" +#include "nm-glib-aux/nm-dbus-aux.h" #include "nm-setting-connection.h" #include "nm-setting-wifi-p2p.h" #include "nm-utils.h" @@ -29,15 +16,8 @@ #include "nm-core-internal.h" #include "nm-dbus-helpers.h" -#include "introspection/org.freedesktop.NetworkManager.Device.WifiP2P.h" - /*****************************************************************************/ -typedef struct { - NMDeviceWifiP2P *device; - GSimpleAsyncResult *simple; -} RequestScanInfo; - NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_HW_ADDRESS, PROP_PEERS, @@ -53,18 +33,10 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; typedef struct { - NMDBusDeviceWifiP2P *proxy; - + NMLDBusPropertyAO peers; char *hw_address; - - GPtrArray *peers; } NMDeviceWifiP2PPrivate; -/** - * NMDeviceWifiP2P: - * - * Since: 1.16 - */ struct _NMDeviceWifiP2P { NMDevice parent; NMDeviceWifiP2PPrivate _priv; @@ -96,7 +68,7 @@ nm_device_wifi_p2p_get_hw_address (NMDeviceWifiP2P *device) { g_return_val_if_fail (NM_IS_DEVICE_WIFI_P2P (device), NULL); - return nm_str_not_empty (NM_DEVICE_WIFI_P2P_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_WIFI_P2P_GET_PRIVATE (device)->hw_address); } /** @@ -116,7 +88,7 @@ nm_device_wifi_p2p_get_peers (NMDeviceWifiP2P *device) { g_return_val_if_fail (NM_IS_DEVICE_WIFI_P2P (device), NULL); - return NM_DEVICE_WIFI_P2P_GET_PRIVATE (device)->peers; + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_WIFI_P2P_GET_PRIVATE (device)->peers); } /** @@ -156,23 +128,6 @@ nm_device_wifi_p2p_get_peer_by_path (NMDeviceWifiP2P *device, return peer; } -static void -start_find_finished_cb (GObject *obj, - GAsyncResult *res, - gpointer user_data) -{ - NMDBusDeviceWifiP2P *proxy = (NMDBusDeviceWifiP2P*) obj; - gs_unref_object GTask *task = G_TASK (user_data); - GError *error = NULL; - gboolean success; - - success = nmdbus_device_wifi_p2p_call_start_find_finish (proxy, res, &error); - if (!success) - g_task_return_error (task, error); - else - g_task_return_boolean (task, TRUE); -} - /** * nm_device_wifi_p2p_start_find: * @device: a #NMDeviceWifiP2P @@ -191,26 +146,33 @@ start_find_finished_cb (GObject *obj, * Since: 1.16 **/ void -nm_device_wifi_p2p_start_find (NMDeviceWifiP2P *device, - GVariant *options, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +nm_device_wifi_p2p_start_find (NMDeviceWifiP2P *device, + GVariant *options, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) { - NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (device); - GTask *task; - g_return_if_fail (NM_IS_DEVICE_WIFI_P2P (device)); - - task = g_task_new (device, cancellable, callback, user_data); + g_return_if_fail (!options || g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT)); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); if (!options) options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); - nmdbus_device_wifi_p2p_call_start_find (priv->proxy, - options, - cancellable, - start_find_finished_cb, - task); + + _nm_client_dbus_call (_nm_object_get_client (device), + device, + nm_device_wifi_p2p_start_find, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "StartFind", + g_variant_new ("(@a{sv})", options), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_cb); } /** @@ -230,24 +192,10 @@ nm_device_wifi_p2p_start_find_finish (NMDeviceWifiP2P *device, GAsyncResult *result, GError **error) { - return g_task_propagate_boolean (G_TASK (result), error); -} + g_return_val_if_fail (NM_IS_DEVICE_WIFI_P2P (device), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_wifi_p2p_start_find), FALSE); -static void -stop_find_finished_cb (GObject *obj, - GAsyncResult *res, - gpointer user_data) -{ - NMDBusDeviceWifiP2P *proxy = (NMDBusDeviceWifiP2P*) obj; - gs_unref_object GTask *task = G_TASK (user_data); - GError *error = NULL; - gboolean success; - - success = nmdbus_device_wifi_p2p_call_stop_find_finish (proxy, res, &error); - if (!success) - g_task_return_error (task, error); - else - g_task_return_boolean (task, TRUE); + return g_task_propagate_boolean (G_TASK (result), error); } /** @@ -267,17 +215,23 @@ nm_device_wifi_p2p_stop_find (NMDeviceWifiP2P *device, GAsyncReadyCallback callback, gpointer user_data) { - NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (device); - GTask *task; - g_return_if_fail (NM_IS_DEVICE_WIFI_P2P (device)); - - task = g_task_new (device, cancellable, callback, user_data); - - nmdbus_device_wifi_p2p_call_stop_find (priv->proxy, - cancellable, - stop_find_finished_cb, - task); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); + + _nm_client_dbus_call (_nm_object_get_client (device), + device, + nm_device_wifi_p2p_stop_find, + cancellable, + callback, + user_data, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "StopFind", + g_variant_new ("()"), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_cb); } /** @@ -297,22 +251,10 @@ nm_device_wifi_p2p_stop_find_finish (NMDeviceWifiP2P *device, GAsyncResult *result, GError **error) { - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -clean_up_peers (NMDeviceWifiP2P *self) -{ - NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (self); - - while (priv->peers->len > 0) { - NMWifiP2PPeer *peer; - - peer = priv->peers->pdata[priv->peers->len - 1]; - g_ptr_array_remove_index (priv->peers, priv->peers->len - 1); + g_return_val_if_fail (NM_IS_DEVICE_WIFI_P2P (device), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_wifi_p2p_stop_find), FALSE); - g_signal_emit (self, signals[PEER_REMOVED], 0, peer); - } + return g_task_propagate_boolean (G_TASK (result), error); } static gboolean @@ -351,6 +293,24 @@ get_type_description (NMDevice *device) /*****************************************************************************/ static void +_property_ao_notify_changed_peers_cb (NMLDBusPropertyAO *pr_ao, + NMClient *client, + NMObject *nmobj, + gboolean is_added /* or else removed */) +{ + _nm_client_notify_event_queue_emit_obj_signal (client, + G_OBJECT (pr_ao->owner_dbobj->nmobj), + nmobj, + is_added, + 10, + is_added + ? signals[PEER_ADDED] + : signals[PEER_REMOVED]); +} + +/*****************************************************************************/ + +static void get_property (GObject *object, guint prop_id, GValue *value, @@ -371,38 +331,11 @@ get_property (GObject *object, } } -static void -nm_device_wifi_p2p_init (NMDeviceWifiP2P *device) -{ - NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (device); - - priv->peers = g_ptr_array_new (); -} - -static void -init_dbus (NMObject *object) -{ - NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_WIFI_P2P_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_WIFI_P2P_PEERS, &priv->peers, NULL, NM_TYPE_WIFI_P2P_PEER, "peer" }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_wifi_p2p_parent_class)->init_dbus (object); - - priv->proxy = NMDBUS_DEVICE_WIFI_P2P (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_DEVICE_WIFI_P2P)); - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_WIFI_P2P, - property_info); -} +/*****************************************************************************/ static void -dispose (GObject *object) +nm_device_wifi_p2p_init (NMDeviceWifiP2P *device) { - clean_up_peers (NM_DEVICE_WIFI_P2P (object)); - - G_OBJECT_CLASS (nm_device_wifi_p2p_parent_class)->dispose (object); } static void @@ -410,32 +343,40 @@ finalize (GObject *object) { NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (object); - g_clear_object (&priv->proxy); g_free (priv->hw_address); - if (priv->peers) - g_ptr_array_unref (priv->peers); G_OBJECT_CLASS (nm_device_wifi_p2p_parent_class)->finalize (object); } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wifip2p = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_WIFI_P2P, + nm_device_wifi_p2p_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceWifiP2P, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Peers", PROP_PEERS, NMDeviceWifiP2P, _priv.peers, nm_wifi_p2p_peer_get_type, .notify_changed_ao = _property_ao_notify_changed_peers_cb ), + ), +); + static void -nm_device_wifi_p2p_class_init (NMDeviceWifiP2PClass *wifi_class) +nm_device_wifi_p2p_class_init (NMDeviceWifiP2PClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (wifi_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (wifi_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (wifi_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); object_class->get_property = get_property; - object_class->dispose = dispose; object_class->finalize = finalize; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceWifiP2P); + + _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceWifiP2PPrivate, peers); + device_class->connection_compatible = connection_compatible; device_class->get_setting_type = get_setting_type; device_class->get_hw_address = get_hw_address; device_class->get_type_description = get_type_description; - nm_object_class->init_dbus = init_dbus; - /** * NMDeviceWifiP2P:hw-address: * @@ -462,7 +403,7 @@ nm_device_wifi_p2p_class_init (NMDeviceWifiP2PClass *wifi_class) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_wifip2p); /** * NMDeviceWifiP2P::peer-added: diff --git a/libnm/nm-device-wifi-p2p.h b/libnm/nm-device-wifi-p2p.h index ddca122f..83127575 100644 --- a/libnm/nm-device-wifi-p2p.h +++ b/libnm/nm-device-wifi-p2p.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 - 2019 Red Hat, Inc. + * Copyright (C) 2018 - 2019 Red Hat, Inc. */ #ifndef __NM_DEVICE_WIFI_P2P_H__ @@ -39,6 +25,11 @@ G_BEGIN_DECLS #define NM_DEVICE_WIFI_P2P_PEERS "peers" #define NM_DEVICE_WIFI_P2P_WFDIES "wfdies" +/** + * NMDeviceWifiP2P: + * + * Since: 1.16 + */ typedef struct _NMDeviceWifiP2PClass NMDeviceWifiP2PClass; NM_AVAILABLE_IN_1_16 diff --git a/libnm/nm-device-wifi.c b/libnm/nm-device-wifi.c index 3b1c00a4..5d8f742c 100644 --- a/libnm/nm-device-wifi.c +++ b/libnm/nm-device-wifi.c @@ -1,27 +1,14 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2014 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2014 Red Hat, Inc. */ #include "nm-default.h" #include "nm-device-wifi.h" +#include "nm-glib-aux/nm-dbus-aux.h" #include "nm-setting-connection.h" #include "nm-setting-wireless.h" #include "nm-setting-wireless-security.h" @@ -31,48 +18,29 @@ #include "nm-core-internal.h" #include "nm-dbus-helpers.h" -#include "introspection/org.freedesktop.NetworkManager.Device.Wireless.h" - -G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE) - -#define NM_DEVICE_WIFI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_WIFI, NMDeviceWifiPrivate)) - -void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled); -static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data); - -typedef struct { - NMDeviceWifi *device; - GSimpleAsyncResult *simple; -} RequestScanInfo; - -typedef struct { - NMDBusDeviceWifi *proxy; - - char *hw_address; - char *perm_hw_address; - NM80211Mode mode; - guint32 rate; - NMAccessPoint *active_ap; - NMDeviceWifiCapabilities wireless_caps; - GPtrArray *aps; - gint64 last_scan; - - RequestScanInfo *scan_info; -} NMDeviceWifiPrivate; +/*****************************************************************************/ -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_HW_ADDRESS, PROP_PERM_HW_ADDRESS, PROP_MODE, PROP_BITRATE, + PROP_ACCESS_POINTS, PROP_ACTIVE_ACCESS_POINT, PROP_WIRELESS_CAPABILITIES, - PROP_ACCESS_POINTS, PROP_LAST_SCAN, +); - LAST_PROP -}; +typedef struct { + NMLDBusPropertyAO access_points; + NMLDBusPropertyO active_access_point; + char *hw_address; + char *perm_hw_address; + gint64 last_scan; + guint32 mode; + guint32 bitrate; + guint32 wireless_capabilities; +} NMDeviceWifiPrivate; enum { ACCESS_POINT_ADDED, @@ -80,8 +48,24 @@ enum { LAST_SIGNAL }; + static guint signals[LAST_SIGNAL] = { 0 }; +struct _NMDeviceWifi { + NMDevice parent; + NMDeviceWifiPrivate _priv; +}; + +struct _NMDeviceWifiClass { + NMDeviceClass parent; +}; + +G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE) + +#define NM_DEVICE_WIFI_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceWifi, NM_IS_DEVICE_WIFI, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_wifi_get_hw_address: * @device: a #NMDeviceWifi @@ -96,7 +80,7 @@ nm_device_wifi_get_hw_address (NMDeviceWifi *device) { g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL); - return nm_str_not_empty (NM_DEVICE_WIFI_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_WIFI_GET_PRIVATE (device)->hw_address); } /** @@ -113,7 +97,7 @@ nm_device_wifi_get_permanent_hw_address (NMDeviceWifi *device) { g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL); - return nm_str_not_empty (NM_DEVICE_WIFI_GET_PRIVATE (device)->perm_hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_WIFI_GET_PRIVATE (device)->perm_hw_address); } /** @@ -159,7 +143,7 @@ nm_device_wifi_get_bitrate (NMDeviceWifi *device) return 0; } - return NM_DEVICE_WIFI_GET_PRIVATE (device)->rate; + return NM_DEVICE_WIFI_GET_PRIVATE (device)->bitrate; } /** @@ -175,7 +159,7 @@ nm_device_wifi_get_capabilities (NMDeviceWifi *device) { g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), 0); - return NM_DEVICE_WIFI_GET_PRIVATE (device)->wireless_caps; + return NM_DEVICE_WIFI_GET_PRIVATE (device)->wireless_capabilities; } /** @@ -189,27 +173,9 @@ nm_device_wifi_get_capabilities (NMDeviceWifi *device) NMAccessPoint * nm_device_wifi_get_active_access_point (NMDeviceWifi *device) { - NMDeviceState state; - g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL); - state = nm_device_get_state (NM_DEVICE (device)); - switch (state) { - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_IP_CHECK: - case NM_DEVICE_STATE_SECONDARIES: - case NM_DEVICE_STATE_ACTIVATED: - case NM_DEVICE_STATE_DEACTIVATING: - break; - default: - return NULL; - break; - } - - return NM_DEVICE_WIFI_GET_PRIVATE (device)->active_ap; + return nml_dbus_property_o_get_obj (&NM_DEVICE_WIFI_GET_PRIVATE (device)->active_access_point); } /** @@ -227,7 +193,7 @@ nm_device_wifi_get_access_points (NMDeviceWifi *device) { g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL); - return NM_DEVICE_WIFI_GET_PRIVATE (device)->aps; + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_WIFI_GET_PRIVATE (device)->access_points); } /** @@ -287,52 +253,6 @@ nm_device_wifi_get_last_scan (NMDeviceWifi *device) return NM_DEVICE_WIFI_GET_PRIVATE (device)->last_scan; } -static GVariant * -prepare_scan_options (GVariant *options) -{ - - GVariant *variant; - GVariantIter iter; - GVariantBuilder builder; - char *key; - GVariant *value; - - if (!options) - variant = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); - else { - g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); - g_variant_iter_init (&iter, options); - while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) - { - // FIXME: verify options here? - g_variant_builder_add (&builder, "{sv}", key, value); - } - variant = g_variant_builder_end (&builder); - } - return variant; -} - -static gboolean -_device_wifi_request_scan (NMDeviceWifi *device, - GVariant *options, - GCancellable *cancellable, - GError **error) -{ - gboolean ret; - GVariant *variant; - - g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), FALSE); - - variant = prepare_scan_options (options); - - ret = nmdbus_device_wifi_call_request_scan_sync (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy, - variant, - cancellable, error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - /** * nm_device_wifi_request_scan: * @device: a #NMDeviceWifi @@ -345,13 +265,15 @@ _device_wifi_request_scan (NMDeviceWifi *device, * * Returns: %TRUE on success, %FALSE on error, in which case @error will be * set. + * + * Deprecated: 1.22, use nm_device_wifi_request_scan_async() or GDBusConnection **/ gboolean nm_device_wifi_request_scan (NMDeviceWifi *device, GCancellable *cancellable, GError **error) { - return _device_wifi_request_scan (device, NULL, cancellable, error); + return nm_device_wifi_request_scan_options (device, NULL, cancellable, error); } /** @@ -373,6 +295,8 @@ nm_device_wifi_request_scan (NMDeviceWifi *device, * set. * * Since: 1.2 + * + * Deprecated: 1.22, use nm_device_wifi_request_scan_options_async() or GDBusConnection **/ gboolean nm_device_wifi_request_scan_options (NMDeviceWifi *device, @@ -380,76 +304,30 @@ nm_device_wifi_request_scan_options (NMDeviceWifi *device, GCancellable *cancellable, GError **error) { - return _device_wifi_request_scan (device, options, cancellable, error); + g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), FALSE); + g_return_val_if_fail (!options || g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT), FALSE); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); + g_return_val_if_fail (!error || !*error, FALSE); + + if (!options) + options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); + + return _nm_client_dbus_call_sync_void (_nm_object_get_client (device), + cancellable, + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "RequestScan", + g_variant_new ("(@a{sv})", options), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); } NM_BACKPORT_SYMBOL (libnm_1_0_6, gboolean, nm_device_wifi_request_scan_options, (NMDeviceWifi *device, GVariant *options, GCancellable *cancellable, GError **error), (device, options, cancellable, error)); -static void -request_scan_cb (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - RequestScanInfo *info = user_data; - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (info->device); - GError *error = NULL; - - priv->scan_info = NULL; - - if (nmdbus_device_wifi_call_request_scan_finish (NMDBUS_DEVICE_WIFI (source), - result, &error)) - g_simple_async_result_set_op_res_gboolean (info->simple, TRUE); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (info->simple, error); - } - - g_simple_async_result_complete (info->simple); - g_object_unref (info->simple); - g_slice_free (RequestScanInfo, info); -} - -static void -_device_wifi_request_scan_async (NMDeviceWifi *device, - GVariant *options, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); - RequestScanInfo *info; - GSimpleAsyncResult *simple; - GVariant *variant; - - g_return_if_fail (NM_IS_DEVICE_WIFI (device)); - - simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data, - nm_device_wifi_request_scan_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - /* If a scan is in progress, just return */ - if (priv->scan_info) { - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); - return; - } - - info = g_slice_new0 (RequestScanInfo); - info->device = device; - info->simple = simple; - - variant = prepare_scan_options (options); - - priv->scan_info = info; - nmdbus_device_wifi_call_request_scan (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy, - variant, - cancellable, request_scan_cb, info); -} - /** * nm_device_wifi_request_scan_async: * @device: a #NMDeviceWifi @@ -467,7 +345,7 @@ nm_device_wifi_request_scan_async (NMDeviceWifi *device, GAsyncReadyCallback callback, gpointer user_data) { - _device_wifi_request_scan_async (device, NULL, cancellable, callback, user_data); + nm_device_wifi_request_scan_options_async (device, NULL, cancellable, callback, user_data); } /** @@ -486,6 +364,8 @@ nm_device_wifi_request_scan_async (NMDeviceWifi *device, * D-Bus call. Valid options inside the dictionary are: * 'ssids' => array of SSIDs (saay) * + * To complete the request call nm_device_wifi_request_scan_finish(). + * * Since: 1.2 **/ void @@ -495,7 +375,27 @@ nm_device_wifi_request_scan_options_async (NMDeviceWifi *device, GAsyncReadyCallback callback, gpointer user_data) { - _device_wifi_request_scan_async (device, options, cancellable, callback, user_data); + g_return_if_fail (NM_IS_DEVICE_WIFI (device)); + g_return_if_fail (!options || g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT)); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); + + if (!options) + options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); + + _nm_client_dbus_call (_nm_object_get_client (device), + device, + nm_device_wifi_request_scan_async, + cancellable, + callback, + user_data, + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "RequestScan", + g_variant_new ("(@a{sv})", options), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_strip_dbus_error_cb); } NM_BACKPORT_SYMBOL (libnm_1_0_6, void, nm_device_wifi_request_scan_options_async, @@ -508,7 +408,8 @@ NM_BACKPORT_SYMBOL (libnm_1_0_6, void, nm_device_wifi_request_scan_options_async * @result: the result passed to the #GAsyncReadyCallback * @error: location for a #GError, or %NULL * - * Gets the result of a call to nm_device_wifi_request_scan_async(). + * Gets the result of a call to nm_device_wifi_request_scan_async() and + * nm_device_wifi_request_scan_options_async(). * * Returns: %TRUE on success, %FALSE on error, in which case @error will be * set. @@ -518,62 +419,10 @@ nm_device_wifi_request_scan_finish (NMDeviceWifi *device, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_wifi_request_scan_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); -} - -static void -clean_up_aps (NMDeviceWifi *self, gboolean in_dispose) -{ - NMDeviceWifiPrivate *priv; - GPtrArray *aps; - int i; - - g_return_if_fail (NM_IS_DEVICE_WIFI (self)); - - priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - - g_clear_object (&priv->active_ap); - - aps = priv->aps; - - if (in_dispose) - priv->aps = NULL; - else { - priv->aps = g_ptr_array_new (); - - for (i = 0; i < aps->len; i++) { - NMAccessPoint *ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i)); - - g_signal_emit (self, signals[ACCESS_POINT_REMOVED], 0, ap); - } - } - - g_ptr_array_unref (aps); -} - -/** - * _nm_device_wifi_set_wireless_enabled: - * @device: a #NMDeviceWifi - * @enabled: %TRUE to enable the device - * - * Enables or disables the wireless device. - **/ -void -_nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, - gboolean enabled) -{ - g_return_if_fail (NM_IS_DEVICE_WIFI (device)); + g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_wifi_request_scan_async), FALSE); - if (!enabled) - clean_up_aps (device, FALSE); + return g_task_propagate_boolean (G_TASK (result), error); } #define WPA_CAPS (NM_WIFI_DEVICE_CAP_CIPHER_TKIP | \ @@ -636,8 +485,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro if (s_wsec) { /* Connection has security, verify it against the device's capabilities */ key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec); - if ( !g_strcmp0 (key_mgmt, "wpa-none") - || !g_strcmp0 (key_mgmt, "wpa-psk") + if ( !g_strcmp0 (key_mgmt, "wpa-psk") || !g_strcmp0 (key_mgmt, "wpa-eap")) { wifi_caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device)); @@ -676,16 +524,28 @@ get_hw_address (NMDevice *device) /*****************************************************************************/ static void +_property_ao_notify_changed_access_points_cb (NMLDBusPropertyAO *pr_ao, + NMClient *client, + NMObject *nmobj, + gboolean is_added /* or else removed */) +{ + _nm_client_notify_event_queue_emit_obj_signal (client, + G_OBJECT (pr_ao->owner_dbobj->nmobj), + nmobj, + is_added, + 10, + is_added + ? signals[ACCESS_POINT_ADDED] + : signals[ACCESS_POINT_REMOVED]); +} + +/*****************************************************************************/ + +static void nm_device_wifi_init (NMDeviceWifi *device) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); - g_signal_connect (device, - "notify::" NM_DEVICE_STATE, - G_CALLBACK (state_changed_cb), - NULL); - - priv->aps = g_ptr_array_new (); priv->last_scan = -1; } @@ -729,80 +589,6 @@ get_property (GObject *object, } static void -state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data) -{ - NMDeviceWifi *self = NM_DEVICE_WIFI (device); - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - - switch (nm_device_get_state (device)) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_UNAVAILABLE: - case NM_DEVICE_STATE_DISCONNECTED: - case NM_DEVICE_STATE_FAILED: - /* Just clear active AP; don't clear the AP list unless wireless is disabled completely */ - g_clear_object (&priv->active_ap); - _nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT); - priv->rate = 0; - _nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_WIFI_BITRATE); - break; - default: - break; - } -} - -static void -init_dbus (NMObject *object) -{ - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_WIFI_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS, &priv->perm_hw_address }, - { NM_DEVICE_WIFI_MODE, &priv->mode }, - { NM_DEVICE_WIFI_BITRATE, &priv->rate }, - { NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, &priv->active_ap, NULL, NM_TYPE_ACCESS_POINT }, - { NM_DEVICE_WIFI_CAPABILITIES, &priv->wireless_caps }, - { NM_DEVICE_WIFI_ACCESS_POINTS, &priv->aps, NULL, NM_TYPE_ACCESS_POINT, "access-point" }, - { NM_DEVICE_WIFI_LAST_SCAN, &priv->last_scan }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_wifi_parent_class)->init_dbus (object); - - priv->proxy = NMDBUS_DEVICE_WIFI (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_DEVICE_WIRELESS)); - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - property_info); -} - -static void -access_point_removed (NMDeviceWifi *self, NMAccessPoint *ap) -{ - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - - if (ap == priv->active_ap) { - g_clear_object (&priv->active_ap); - _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT); - - priv->rate = 0; - _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIFI_BITRATE); - } -} - -static void -dispose (GObject *object) -{ - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object); - - if (priv->aps) - clean_up_aps (NM_DEVICE_WIFI (object), TRUE); - - g_clear_object (&priv->proxy); - - G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (object); -} - -static void finalize (GObject *object) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object); @@ -813,115 +599,119 @@ finalize (GObject *object) G_OBJECT_CLASS (nm_device_wifi_parent_class)->finalize (object); } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wireless = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + nm_device_wifi_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("AccessPoints", PROP_ACCESS_POINTS, NMDeviceWifi, _priv.access_points, nm_access_point_get_type, .notify_changed_ao = _property_ao_notify_changed_access_points_cb ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("ActiveAccessPoint", PROP_ACTIVE_ACCESS_POINT, NMDeviceWifi, _priv.active_access_point, nm_access_point_get_type ), + NML_DBUS_META_PROPERTY_INIT_U ("Bitrate", PROP_BITRATE, NMDeviceWifi, _priv.bitrate ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceWifi, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_X ("LastScan", PROP_LAST_SCAN, NMDeviceWifi, _priv.last_scan ), + NML_DBUS_META_PROPERTY_INIT_U ("Mode", PROP_MODE, NMDeviceWifi, _priv.mode ), + NML_DBUS_META_PROPERTY_INIT_S ("PermHwAddress", PROP_PERM_HW_ADDRESS, NMDeviceWifi, _priv.perm_hw_address ), + NML_DBUS_META_PROPERTY_INIT_U ("WirelessCapabilities", PROP_WIRELESS_CAPABILITIES, NMDeviceWifi, _priv.wireless_capabilities ), + ), +); + static void -nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class) +nm_device_wifi_class_init (NMDeviceWifiClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (wifi_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (wifi_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (wifi_class); - - g_type_class_add_private (wifi_class, sizeof (NMDeviceWifiPrivate)); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - /* virtual methods */ object_class->get_property = get_property; - object_class->dispose = dispose; - object_class->finalize = finalize; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceWifi); - device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; + _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceWifiPrivate, active_access_point); + _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceWifiPrivate, access_points); - wifi_class->access_point_removed = access_point_removed; - - /* properties */ + device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceWifi:hw-address: * * The hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_WIFI_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_WIFI_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWifi:perm-hw-address: * * The hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_PERM_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PERM_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWifi:mode: * * The mode of the device. **/ - g_object_class_install_property - (object_class, PROP_MODE, - g_param_spec_enum (NM_DEVICE_WIFI_MODE, "", "", - NM_TYPE_802_11_MODE, - NM_802_11_MODE_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MODE] = + g_param_spec_enum (NM_DEVICE_WIFI_MODE, "", "", + NM_TYPE_802_11_MODE, + NM_802_11_MODE_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWifi:bitrate: * * The bit rate of the device in kbit/s. **/ - g_object_class_install_property - (object_class, PROP_BITRATE, - g_param_spec_uint (NM_DEVICE_WIFI_BITRATE, "", "", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_BITRATE] = + g_param_spec_uint (NM_DEVICE_WIFI_BITRATE, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWifi:active-access-point: * * The active #NMAccessPoint of the device. **/ - g_object_class_install_property - (object_class, PROP_ACTIVE_ACCESS_POINT, - g_param_spec_object (NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, "", "", - NM_TYPE_ACCESS_POINT, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ACTIVE_ACCESS_POINT] = + g_param_spec_object (NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, "", "", + NM_TYPE_ACCESS_POINT, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWifi:wireless-capabilities: * * The wireless capabilities of the device. **/ - g_object_class_install_property - (object_class, PROP_WIRELESS_CAPABILITIES, - g_param_spec_flags (NM_DEVICE_WIFI_CAPABILITIES, "", "", - NM_TYPE_DEVICE_WIFI_CAPABILITIES, - NM_WIFI_DEVICE_CAP_NONE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_WIRELESS_CAPABILITIES] = + g_param_spec_flags (NM_DEVICE_WIFI_CAPABILITIES, "", "", + NM_TYPE_DEVICE_WIFI_CAPABILITIES, + NM_WIFI_DEVICE_CAP_NONE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWifi:access-points: (type GPtrArray(NMAccessPoint)) * * List of all Wi-Fi access points the device can see. **/ - g_object_class_install_property - (object_class, PROP_ACCESS_POINTS, - g_param_spec_boxed (NM_DEVICE_WIFI_ACCESS_POINTS, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ACCESS_POINTS] = + g_param_spec_boxed (NM_DEVICE_WIFI_ACCESS_POINTS, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWifi:last-scan: @@ -932,14 +722,13 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class) * * Since: 1.12 **/ - g_object_class_install_property - (object_class, PROP_LAST_SCAN, - g_param_spec_int64 (NM_DEVICE_WIFI_LAST_SCAN, "", "", - -1, G_MAXINT64, -1, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_LAST_SCAN] = + g_param_spec_int64 (NM_DEVICE_WIFI_LAST_SCAN, "", "", + -1, G_MAXINT64, -1, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); - /* signals */ + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_wireless); /** * NMDeviceWifi::access-point-added: @@ -949,14 +738,13 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class) * Notifies that a #NMAccessPoint is added to the Wi-Fi device. **/ signals[ACCESS_POINT_ADDED] = - g_signal_new ("access-point-added", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMDeviceWifiClass, access_point_added), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); + g_signal_new ("access-point-added", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); /** * NMDeviceWifi::access-point-removed: @@ -966,12 +754,11 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class) * Notifies that a #NMAccessPoint is removed from the Wi-Fi device. **/ signals[ACCESS_POINT_REMOVED] = - g_signal_new ("access-point-removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMDeviceWifiClass, access_point_removed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); + g_signal_new ("access-point-removed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); } diff --git a/libnm/nm-device-wifi.h b/libnm/nm-device-wifi.h index ef7d83b7..c64641d3 100644 --- a/libnm/nm-device-wifi.h +++ b/libnm/nm-device-wifi.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2012 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2012 Red Hat, Inc. */ #ifndef __NM_DEVICE_WIFI_H__ @@ -48,20 +34,7 @@ G_BEGIN_DECLS /** * NMDeviceWifi: */ -struct _NMDeviceWifi { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /* Signals */ - void (*access_point_added) (NMDeviceWifi *device, NMAccessPoint *ap); - void (*access_point_removed) (NMDeviceWifi *device, NMAccessPoint *ap); - - /*< private >*/ - gpointer padding[4]; -} NMDeviceWifiClass; +typedef struct _NMDeviceWifiClass NMDeviceWifiClass; GType nm_device_wifi_get_type (void); @@ -80,10 +53,12 @@ const GPtrArray * nm_device_wifi_get_access_points (NMDeviceWifi * NM_AVAILABLE_IN_1_12 gint64 nm_device_wifi_get_last_scan (NMDeviceWifi *device); +_NM_DEPRECATED_SYNC_METHOD gboolean nm_device_wifi_request_scan (NMDeviceWifi *device, GCancellable *cancellable, GError **error); NM_AVAILABLE_IN_1_2 +_NM_DEPRECATED_SYNC_METHOD gboolean nm_device_wifi_request_scan_options (NMDeviceWifi *device, GVariant *options, GCancellable *cancellable, diff --git a/libnm/nm-device-wimax.c b/libnm/nm-device-wimax.c index a526d088..54a972b5 100644 --- a/libnm/nm-device-wimax.c +++ b/libnm/nm-device-wimax.c @@ -1,55 +1,18 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2011 - 2012 Red Hat, Inc. - * Copyright 2009 Novell, Inc. + * Copyright (C) 2011 - 2012 Red Hat, Inc. + * Copyright (C) 2009 Novell, Inc. */ #include "nm-default.h" #include "nm-device-wimax.h" -#include "nm-setting-connection.h" -#include "nm-setting-wimax.h" -#include "nm-utils.h" #include "nm-wimax-nsp.h" -#include "nm-object-private.h" -#include "nm-core-internal.h" - -G_DEFINE_TYPE (NMDeviceWimax, nm_device_wimax, NM_TYPE_DEVICE) -#define NM_DEVICE_WIMAX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_WIMAX, NMDeviceWimaxPrivate)) - -void _nm_device_wimax_set_wireless_enabled (NMDeviceWimax *wimax, gboolean enabled); -static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data); - -typedef struct { - char *hw_address; - NMWimaxNsp *active_nsp; - GPtrArray *nsps; - - guint center_freq; - int rssi; - int cinr; - int tx_power; - char *bsid; -} NMDeviceWimaxPrivate; +/*****************************************************************************/ -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_HW_ADDRESS, PROP_ACTIVE_NSP, PROP_CENTER_FREQ, @@ -58,9 +21,7 @@ enum { PROP_TX_POWER, PROP_BSID, PROP_NSPS, - - LAST_PROP -}; +); enum { NSP_ADDED, @@ -68,8 +29,23 @@ enum { LAST_SIGNAL }; + static guint signals[LAST_SIGNAL] = { 0 }; +struct _NMDeviceWimax { + NMDevice parent; +}; + +struct _NMDeviceWimaxClass { + NMDeviceClass parent; +}; + +G_DEFINE_TYPE (NMDeviceWimax, nm_device_wimax, NM_TYPE_DEVICE) + +#define NM_DEVICE_WIMAX_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceWimax, NM_IS_DEVICE_WIMAX, NMObject, NMDevice) + +/*****************************************************************************/ + /** * nm_device_wimax_get_hw_address: * @wimax: a #NMDeviceWimax @@ -84,9 +60,7 @@ static guint signals[LAST_SIGNAL] = { 0 }; const char * nm_device_wimax_get_hw_address (NMDeviceWimax *wimax) { - g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); - - return nm_str_not_empty (NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->hw_address); + g_return_val_if_reached (NULL); } /** @@ -102,27 +76,7 @@ nm_device_wimax_get_hw_address (NMDeviceWimax *wimax) NMWimaxNsp * nm_device_wimax_get_active_nsp (NMDeviceWimax *wimax) { - NMDeviceState state; - - g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); - - state = nm_device_get_state (NM_DEVICE (wimax)); - switch (state) { - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_IP_CHECK: - case NM_DEVICE_STATE_SECONDARIES: - case NM_DEVICE_STATE_ACTIVATED: - case NM_DEVICE_STATE_DEACTIVATING: - break; - default: - return NULL; - break; - } - - return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->active_nsp; + g_return_val_if_reached (NULL); } /** @@ -140,9 +94,7 @@ nm_device_wimax_get_active_nsp (NMDeviceWimax *wimax) const GPtrArray * nm_device_wimax_get_nsps (NMDeviceWimax *wimax) { - g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); - - return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->nsps; + g_return_val_if_reached (NULL); } /** @@ -160,43 +112,7 @@ NMWimaxNsp * nm_device_wimax_get_nsp_by_path (NMDeviceWimax *wimax, const char *path) { - const GPtrArray *nsps; - int i; - NMWimaxNsp *nsp = NULL; - - g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); - g_return_val_if_fail (path != NULL, NULL); - - nsps = nm_device_wimax_get_nsps (wimax); - if (!nsps) - return NULL; - - for (i = 0; i < nsps->len; i++) { - NMWimaxNsp *candidate = g_ptr_array_index (nsps, i); - if (!strcmp (nm_object_get_path (NM_OBJECT (candidate)), path)) { - nsp = candidate; - break; - } - } - - return nsp; -} - -static void -clean_up_nsps (NMDeviceWimax *self) -{ - NMDeviceWimaxPrivate *priv; - - g_return_if_fail (NM_IS_DEVICE_WIMAX (self)); - - priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); - - if (priv->active_nsp) { - g_object_unref (priv->active_nsp); - priv->active_nsp = NULL; - } - - g_clear_pointer (&priv->nsps, g_ptr_array_unref); + g_return_val_if_reached (NULL); } /** @@ -214,9 +130,7 @@ clean_up_nsps (NMDeviceWimax *self) guint nm_device_wimax_get_center_frequency (NMDeviceWimax *self) { - g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); - - return NM_DEVICE_WIMAX_GET_PRIVATE (self)->center_freq; + g_return_val_if_reached (0); } /** @@ -235,9 +149,7 @@ nm_device_wimax_get_center_frequency (NMDeviceWimax *self) int nm_device_wimax_get_rssi (NMDeviceWimax *self) { - g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); - - return NM_DEVICE_WIMAX_GET_PRIVATE (self)->rssi; + g_return_val_if_reached (0); } /** @@ -255,9 +167,7 @@ nm_device_wimax_get_rssi (NMDeviceWimax *self) int nm_device_wimax_get_cinr (NMDeviceWimax *self) { - g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); - - return NM_DEVICE_WIMAX_GET_PRIVATE (self)->cinr; + g_return_val_if_reached (0); } /** @@ -275,9 +185,7 @@ nm_device_wimax_get_cinr (NMDeviceWimax *self) int nm_device_wimax_get_tx_power (NMDeviceWimax *self) { - g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); - - return NM_DEVICE_WIMAX_GET_PRIVATE (self)->tx_power; + g_return_val_if_reached (0); } /** @@ -293,250 +201,32 @@ nm_device_wimax_get_tx_power (NMDeviceWimax *self) const char * nm_device_wimax_get_bsid (NMDeviceWimax *self) { - g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), NULL); - - return nm_str_not_empty (NM_DEVICE_WIMAX_GET_PRIVATE (self)->bsid); -} - -static gboolean -connection_compatible (NMDevice *device, NMConnection *connection, GError **error) -{ - NMSettingWimax *s_wimax; - const char *hwaddr, *setting_hwaddr; - - if (!NM_DEVICE_CLASS (nm_device_wimax_parent_class)->connection_compatible (device, connection, error)) - return FALSE; - - if (!nm_connection_is_type (connection, NM_SETTING_WIMAX_SETTING_NAME)) { - g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, - _("The connection was not a WiMAX connection.")); - return FALSE; - } - - /* Check MAC address */ - hwaddr = nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device)); - if (hwaddr) { - if (!nm_utils_hwaddr_valid (hwaddr, ETH_ALEN)) { - g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, - _("Invalid device MAC address.")); - return FALSE; - } - s_wimax = nm_connection_get_setting_wimax (connection); - setting_hwaddr = nm_setting_wimax_get_mac_address (s_wimax); - if (setting_hwaddr && !nm_utils_hwaddr_matches (setting_hwaddr, -1, hwaddr, -1)) { - g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, - _("The MACs of the device and the connection didn't match.")); - return FALSE; - } - } - - return TRUE; -} - -static GType -get_setting_type (NMDevice *device) -{ - return NM_TYPE_SETTING_WIMAX; -} - -static const char * -get_hw_address (NMDevice *device) -{ - return nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device)); + g_return_val_if_reached (0); } /*****************************************************************************/ static void -nm_device_wimax_init (NMDeviceWimax *device) -{ - g_signal_connect (device, - "notify::" NM_DEVICE_STATE, - G_CALLBACK (state_changed_cb), - NULL); -} - -static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceWimax *self = NM_DEVICE_WIMAX (object); - - switch (prop_id) { - case PROP_HW_ADDRESS: - g_value_set_string (value, nm_device_wimax_get_hw_address (self)); - break; - case PROP_ACTIVE_NSP: - g_value_set_object (value, nm_device_wimax_get_active_nsp (self)); - break; - case PROP_CENTER_FREQ: - g_value_set_uint (value, nm_device_wimax_get_center_frequency (self)); - break; - case PROP_RSSI: - g_value_set_int (value, nm_device_wimax_get_rssi (self)); - break; - case PROP_CINR: - g_value_set_int (value, nm_device_wimax_get_cinr (self)); - break; - case PROP_TX_POWER: - g_value_set_int (value, nm_device_wimax_get_tx_power (self)); - break; - case PROP_BSID: - g_value_set_string (value, nm_device_wimax_get_bsid (self)); - break; - case PROP_NSPS: - g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_wimax_get_nsps (self))); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -clear_link_status (NMDeviceWimax *self) -{ - NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); - - if (priv->center_freq) { - priv->center_freq = 0; - _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_CENTER_FREQUENCY); - } - - if (priv->rssi) { - priv->rssi = 0; - _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_RSSI); - } - - if (priv->cinr) { - priv->cinr = 0; - _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_CINR); - } - - if (priv->tx_power) { - priv->tx_power = 0; - _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_TX_POWER); - } - - if (priv->bsid) { - g_free (priv->bsid); - priv->bsid = NULL; - _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_BSID); - } -} - -static void -state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data) -{ - NMDeviceWimax *self = NM_DEVICE_WIMAX (device); - NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); - NMDeviceState state; - - state = nm_device_get_state (device); - switch (state) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_UNAVAILABLE: - case NM_DEVICE_STATE_DISCONNECTED: - case NM_DEVICE_STATE_FAILED: - if (priv->active_nsp) { - g_object_unref (priv->active_nsp); - priv->active_nsp = NULL; - } - _nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_WIMAX_ACTIVE_NSP); - clear_link_status (self); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - clear_link_status (self); - break; - default: - break; - } + g_return_if_reached (); } static void -init_dbus (NMObject *object) -{ - NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_WIMAX_HW_ADDRESS, &priv->hw_address }, - { NM_DEVICE_WIMAX_ACTIVE_NSP, &priv->active_nsp, NULL, NM_TYPE_WIMAX_NSP }, - { NM_DEVICE_WIMAX_CENTER_FREQUENCY, &priv->center_freq }, - { NM_DEVICE_WIMAX_RSSI, &priv->rssi }, - { NM_DEVICE_WIMAX_CINR, &priv->cinr }, - { NM_DEVICE_WIMAX_TX_POWER, &priv->tx_power }, - { NM_DEVICE_WIMAX_BSID, &priv->bsid }, - { NM_DEVICE_WIMAX_NSPS, &priv->nsps, NULL, NM_TYPE_WIMAX_NSP, "nsp" }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_wimax_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_WIMAX, - property_info); -} - -static void -nsp_removed (NMDeviceWimax *self, NMWimaxNsp *nsp) +nm_device_wimax_init (NMDeviceWimax *device) { - NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); - - if (nsp == priv->active_nsp) { - g_object_unref (priv->active_nsp); - priv->active_nsp = NULL; - _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_ACTIVE_NSP); - } -} - -static void -dispose (GObject *object) -{ - NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (object); - - if (priv->hw_address) { - g_free (priv->hw_address); - priv->hw_address = NULL; - } - - if (priv->bsid) { - g_free (priv->bsid); - priv->bsid = NULL; - } - - if (priv->nsps) - clean_up_nsps (NM_DEVICE_WIMAX (object)); - - G_OBJECT_CLASS (nm_device_wimax_parent_class)->dispose (object); + g_return_if_reached (); } static void nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) { GObjectClass *object_class = G_OBJECT_CLASS (wimax_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (wimax_class); - NMDeviceClass *device_class = NM_DEVICE_CLASS (wimax_class); - - g_type_class_add_private (wimax_class, sizeof (NMDeviceWimaxPrivate)); - /* virtual methods */ object_class->get_property = get_property; - object_class->dispose = dispose; - - nm_object_class->init_dbus = init_dbus; - - device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; - - wimax_class->nsp_removed = nsp_removed; - - /* properties */ /** * NMDeviceWimax:hw-address: @@ -545,12 +235,11 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) * * Deprecated: 1.2: WiMAX is no longer supported. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_WIMAX_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_WIMAX_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWimax:active-nsp: @@ -559,12 +248,11 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) * * Deprecated: 1.2: WiMAX is no longer supported. **/ - g_object_class_install_property - (object_class, PROP_ACTIVE_NSP, - g_param_spec_object (NM_DEVICE_WIMAX_ACTIVE_NSP, "", "", - NM_TYPE_WIMAX_NSP, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ACTIVE_NSP] = + g_param_spec_object (NM_DEVICE_WIMAX_ACTIVE_NSP, "", "", + NM_TYPE_WIMAX_NSP, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWimax:center-frequency: @@ -575,12 +263,11 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) * * Deprecated: 1.2: WiMAX is no longer supported. **/ - g_object_class_install_property - (object_class, PROP_CENTER_FREQ, - g_param_spec_uint (NM_DEVICE_WIMAX_CENTER_FREQUENCY, "", "", - 0, G_MAXUINT, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CENTER_FREQ] = + g_param_spec_uint (NM_DEVICE_WIMAX_CENTER_FREQUENCY, "", "", + 0, G_MAXUINT, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWimax:rssi: @@ -592,12 +279,11 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) * * Deprecated: 1.2: WiMAX is no longer supported. **/ - g_object_class_install_property - (object_class, PROP_RSSI, - g_param_spec_int (NM_DEVICE_WIMAX_RSSI, "", "", - G_MININT, G_MAXINT, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_RSSI] = + g_param_spec_int (NM_DEVICE_WIMAX_RSSI, "", "", + G_MININT, G_MAXINT, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWimax:cinr: @@ -608,12 +294,11 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) * * Deprecated: 1.2: WiMAX is no longer supported. **/ - g_object_class_install_property - (object_class, PROP_CINR, - g_param_spec_int (NM_DEVICE_WIMAX_CINR, "", "", - G_MININT, G_MAXINT, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CINR] = + g_param_spec_int (NM_DEVICE_WIMAX_CINR, "", "", + G_MININT, G_MAXINT, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWimax:tx-power: @@ -624,12 +309,11 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) * * Deprecated: 1.2: WiMAX is no longer supported. **/ - g_object_class_install_property - (object_class, PROP_TX_POWER, - g_param_spec_int (NM_DEVICE_WIMAX_TX_POWER, "", "", - G_MININT, G_MAXINT, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_TX_POWER] = + g_param_spec_int (NM_DEVICE_WIMAX_TX_POWER, "", "", + G_MININT, G_MAXINT, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWimax:bsid: @@ -639,26 +323,24 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) * * Deprecated: 1.2: WiMAX is no longer supported. **/ - g_object_class_install_property - (object_class, PROP_BSID, - g_param_spec_string (NM_DEVICE_WIMAX_BSID, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_BSID] = + g_param_spec_string (NM_DEVICE_WIMAX_BSID, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDeviceWimax:nsps: (type GPtrArray(NMWimaxNsp)) * * List of all WiMAX Network Service Providers the device can see. **/ - g_object_class_install_property - (object_class, PROP_NSPS, - g_param_spec_boxed (NM_DEVICE_WIMAX_NSPS, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_NSPS] = + g_param_spec_boxed (NM_DEVICE_WIMAX_NSPS, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); - /* signals */ + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); /** * NMDeviceWimax::nsp-added: @@ -670,14 +352,13 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) * Deprecated: 1.2: WiMAX is no longer supported. **/ signals[NSP_ADDED] = - g_signal_new ("nsp-added", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMDeviceWimaxClass, nsp_added), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); + g_signal_new ("nsp-added", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); /** * NMDeviceWimax::nsp-removed: @@ -689,12 +370,11 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) * Deprecated: 1.2: WiMAX is no longer supported. **/ signals[NSP_REMOVED] = - g_signal_new ("nsp-removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMDeviceWimaxClass, nsp_removed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); + g_signal_new ("nsp-removed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); } diff --git a/libnm/nm-device-wimax.h b/libnm/nm-device-wimax.h index 43082881..10d2cd18 100644 --- a/libnm/nm-device-wimax.h +++ b/libnm/nm-device-wimax.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2011 - 2012 Red Hat, Inc. - * Copyright 2009 Novell, Inc. + * Copyright (C) 2011 - 2012 Red Hat, Inc. + * Copyright (C) 2009 Novell, Inc. */ #ifndef __NM_DEVICE_WIMAX_H__ @@ -47,21 +33,10 @@ G_BEGIN_DECLS /** * NMDeviceWimax: + * + * Deprecated: 1.22. WiMAX is no longer supported by NetworkManager since 1.2.0 */ -struct _NMDeviceWimax { - NMDevice parent; -}; - -typedef struct { - NMDeviceClass parent; - - /* Signals */ - void (*nsp_added) (NMDeviceWimax *self, NMWimaxNsp *nsp); - void (*nsp_removed) (NMDeviceWimax *self, NMWimaxNsp *nsp); - - /*< private >*/ - gpointer padding[4]; -} NMDeviceWimaxClass; +typedef struct _NMDeviceWimaxClass NMDeviceWimaxClass; NM_DEPRECATED_IN_1_2 GType nm_device_wimax_get_type (void); diff --git a/libnm/nm-device-wireguard.c b/libnm/nm-device-wireguard.c index 8a76ff44..b4e2f350 100644 --- a/libnm/nm-device-wireguard.c +++ b/libnm/nm-device-wireguard.c @@ -1,38 +1,31 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 Javier Arteaga <jarteaga@jbeta.is> + * Copyright (C) 2018 Javier Arteaga <jarteaga@jbeta.is> */ #include "nm-default.h" #include "nm-device-wireguard.h" + #include "nm-object-private.h" +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_PUBLIC_KEY, + PROP_LISTEN_PORT, + PROP_FWMARK, +); + typedef struct { GBytes *public_key; - guint listen_port; - guint fwmark; + guint32 fwmark; + guint16 listen_port; } NMDeviceWireGuardPrivate; -/** - * NMDeviceWireGuard: - */ struct _NMDeviceWireGuard { NMDevice parent; + NMDeviceWireGuardPrivate _priv; }; struct _NMDeviceWireGuardClass { @@ -41,13 +34,9 @@ struct _NMDeviceWireGuardClass { G_DEFINE_TYPE (NMDeviceWireGuard, nm_device_wireguard, NM_TYPE_DEVICE) -#define NM_DEVICE_WIREGUARD_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_WIREGUARD, NMDeviceWireGuardPrivate)) +#define NM_DEVICE_WIREGUARD_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceWireGuard, NM_IS_DEVICE_WIREGUARD, NMObject, NMDevice) -NM_GOBJECT_PROPERTIES_DEFINE_BASE ( - PROP_PUBLIC_KEY, - PROP_LISTEN_PORT, - PROP_FWMARK, -); +/*****************************************************************************/ /** * nm_device_wireguard_get_public_key: @@ -137,24 +126,6 @@ nm_device_wireguard_init (NMDeviceWireGuard *device) } static void -init_dbus (NMObject *object) -{ - NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_WIREGUARD_PUBLIC_KEY, &priv->public_key }, - { NM_DEVICE_WIREGUARD_LISTEN_PORT, &priv->listen_port }, - { NM_DEVICE_WIREGUARD_FWMARK, &priv->fwmark }, - { NULL } - }; - - NM_OBJECT_CLASS (nm_device_wireguard_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_WIREGUARD, - property_info); -} - -static void finalize (GObject *object) { NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE (object); @@ -164,19 +135,25 @@ finalize (GObject *object) G_OBJECT_CLASS (nm_device_wireguard_parent_class)->finalize (object); } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wireguard = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_WIREGUARD, + nm_device_wireguard_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_U ("FwMark", PROP_FWMARK, NMDeviceWireGuard, _priv.fwmark ), + NML_DBUS_META_PROPERTY_INIT_Q ("ListenPort", PROP_LISTEN_PORT, NMDeviceWireGuard, _priv.listen_port ), + NML_DBUS_META_PROPERTY_INIT_AY ("PublicKey", PROP_PUBLIC_KEY, NMDeviceWireGuard, _priv.public_key ), + ), +); + static void nm_device_wireguard_class_init (NMDeviceWireGuardClass *wireguard_class) { GObjectClass *object_class = G_OBJECT_CLASS (wireguard_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (wireguard_class); - - g_type_class_add_private (wireguard_class, sizeof (NMDeviceWireGuardPrivate)); object_class->get_property = get_property; object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; - /** * NMDeviceWireGuard:public-key: * @@ -216,5 +193,5 @@ nm_device_wireguard_class_init (NMDeviceWireGuardClass *wireguard_class) 0, G_MAXUINT32, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_wireguard); } diff --git a/libnm/nm-device-wireguard.h b/libnm/nm-device-wireguard.h index 37e97a0a..1b2bb840 100644 --- a/libnm/nm-device-wireguard.h +++ b/libnm/nm-device-wireguard.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 Javier Arteaga <jarteaga@jbeta.is> + * Copyright (C) 2018 Javier Arteaga <jarteaga@jbeta.is> */ #ifndef __NM_DEVICE_WIREGUARD_H__ @@ -35,6 +21,9 @@ G_BEGIN_DECLS #define NM_IS_DEVICE_WIREGUARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_WIREGUARD)) #define NM_DEVICE_WIREGUARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_WIREGUARD, NMDeviceWireGuardClass)) +/** + * NMDeviceWireGuard: + */ typedef struct _NMDeviceWireGuardClass NMDeviceWireGuardClass; #define NM_DEVICE_WIREGUARD_PUBLIC_KEY "public-key" diff --git a/libnm/nm-device-wpan.c b/libnm/nm-device-wpan.c index d6acda61..5ddd8af3 100644 --- a/libnm/nm-device-wpan.c +++ b/libnm/nm-device-wpan.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 Lubomir Rintel <lkundrak@v3.sk> + * Copyright (C) 2018 Lubomir Rintel <lkundrak@v3.sk> */ #include "nm-default.h" @@ -25,31 +11,28 @@ #include "nm-setting-wpan.h" #include "nm-setting-connection.h" -enum { - PROP_0, - PROP_HW_ADDRESS, +/*****************************************************************************/ - LAST_PROP -}; +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_HW_ADDRESS, +); typedef struct { - char *hw_address; + char *hw_address; } NMDeviceWpanPrivate; -/** - * NMDeviceWpan: - */ struct _NMDeviceWpan { - NMDevice parent; + NMDevice parent; + NMDeviceWpanPrivate _priv; }; -typedef struct { - NMDeviceClass parent; -} NMDeviceWpanClass; +struct _NMDeviceWpanClass { + NMDeviceClass parent; +}; G_DEFINE_TYPE (NMDeviceWpan, nm_device_wpan, NM_TYPE_DEVICE) -#define NM_DEVICE_WPAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_WPAN, NMDeviceWpanPrivate)) +#define NM_DEVICE_WPAN_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceWpan, NM_IS_DEVICE_WPAN, NMObject, NMDevice) /*****************************************************************************/ @@ -65,9 +48,9 @@ G_DEFINE_TYPE (NMDeviceWpan, nm_device_wpan, NM_TYPE_DEVICE) const char * nm_device_wpan_get_hw_address (NMDeviceWpan *device) { - g_return_val_if_fail (NM_IS_DEVICE_WPAN (device), NULL); + g_return_val_if_fail (NM_IS_DEVICE_WPAN (device), NULL); - return nm_str_not_empty (NM_DEVICE_WPAN_GET_PRIVATE (device)->hw_address); + return _nml_coerce_property_str_not_empty (NM_DEVICE_WPAN_GET_PRIVATE (device)->hw_address); } static gboolean @@ -112,67 +95,55 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) } } -static void -nm_device_wpan_init (NMDeviceWpan *device) -{ -} +/*****************************************************************************/ static void -init_dbus (NMObject *object) +nm_device_wpan_init (NMDeviceWpan *device) { - NMDeviceWpanPrivate *priv = NM_DEVICE_WPAN_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_WPAN_HW_ADDRESS, &priv->hw_address }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_wpan_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE_WPAN, - property_info); } static void finalize (GObject *object) { - NMDeviceWpanPrivate *priv = NM_DEVICE_WPAN_GET_PRIVATE (object); + NMDeviceWpanPrivate *priv = NM_DEVICE_WPAN_GET_PRIVATE (object); - g_free (priv->hw_address); + g_free (priv->hw_address); - G_OBJECT_CLASS (nm_device_wpan_parent_class)->finalize (object); + G_OBJECT_CLASS (nm_device_wpan_parent_class)->finalize (object); } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wpan = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE_WPAN, + nm_device_wpan_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceWpan, _priv.hw_address ), + ), +); + static void nm_device_wpan_class_init (NMDeviceWpanClass *wpan_class) { GObjectClass *object_class = G_OBJECT_CLASS (wpan_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (wpan_class); NMDeviceClass *device_class = NM_DEVICE_CLASS (wpan_class); - g_type_class_add_private (wpan_class, sizeof (NMDeviceWpanPrivate)); - - /* virtual methods */ - object_class->finalize = finalize; object_class->get_property = get_property; - - nm_object_class->init_dbus = init_dbus; + object_class->finalize = finalize; device_class->connection_compatible = connection_compatible; - device_class->get_setting_type = get_setting_type; - device_class->get_hw_address = get_hw_address; - - /* properties */ + device_class->get_setting_type = get_setting_type; + device_class->get_hw_address = get_hw_address; /** * NMDeviceWpan:hw-address: * * The active hardware (MAC) address of the device. **/ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_WPAN_HW_ADDRESS, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_HW_ADDRESS] = + g_param_spec_string (NM_DEVICE_WPAN_HW_ADDRESS, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_wpan); } diff --git a/libnm/nm-device-wpan.h b/libnm/nm-device-wpan.h index d20113dd..43f8b7b3 100644 --- a/libnm/nm-device-wpan.h +++ b/libnm/nm-device-wpan.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 Lubomir Rintel <lkundrak@v3.sk> + * Copyright (C) 2018 Lubomir Rintel <lkundrak@v3.sk> */ #ifndef __NM_DEVICE_WPAN_H__ @@ -37,6 +23,11 @@ G_BEGIN_DECLS #define NM_DEVICE_WPAN_HW_ADDRESS "hw-address" +/** + * NMDeviceWpan: + */ +typedef struct _NMDeviceWpanClass NMDeviceWpanClass; + NM_AVAILABLE_IN_1_14 GType nm_device_wpan_get_type (void); diff --git a/libnm/nm-device.c b/libnm/nm-device.c index b9f4acd4..ade67b04 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2018 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2018 Red Hat, Inc. */ #include "nm-default.h" @@ -24,7 +10,7 @@ #include <libudev.h> -#include "nm-libnm-utils.h" +#include "nm-glib-aux/nm-dbus-aux.h" #include "nm-dbus-interface.h" #include "nm-active-connection.h" #include "nm-device-bt.h" @@ -41,58 +27,9 @@ #include "nm-setting-connection.h" #include "nm-udev-aux/nm-udev-utils.h" -#include "introspection/org.freedesktop.NetworkManager.Device.h" - -static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error); -static NMLldpNeighbor *nm_lldp_neighbor_dup (NMLldpNeighbor *neighbor); - -G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_OBJECT); - -#define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate)) - -typedef struct { - NMDBusDevice *proxy; - - char *iface; - char *ip_iface; - NMDeviceType device_type; - char *udi; - char *driver; - char *driver_version; - char *firmware_version; - char *type_description; - NMMetered metered; - NMDeviceCapabilities capabilities; - gboolean real; - gboolean managed; - gboolean firmware_missing; - gboolean nm_plugin_missing; - gboolean autoconnect; - NMIPConfig *ip4_config; - NMDhcpConfig *dhcp4_config; - NMIPConfig *ip6_config; - NMDhcpConfig *dhcp6_config; - NMConnectivityState ip4_connectivity; - NMConnectivityState ip6_connectivity; - NMDeviceState state; - NMDeviceState last_seen_state; - NMDeviceStateReason reason; - - NMActiveConnection *active_connection; - GPtrArray *available_connections; - - struct udev *udev; - char *product; - char *vendor, *short_vendor; - char *description, *bus_name; - - char *physical_port_id; - guint32 mtu; - GPtrArray *lldp_neighbors; -} NMDevicePrivate; +/*****************************************************************************/ -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE (NMDevice, PROP_INTERFACE, PROP_UDI, PROP_DRIVER, @@ -122,9 +59,8 @@ enum { PROP_LLDP_NEIGHBORS, PROP_IP4_CONNECTIVITY, PROP_IP6_CONNECTIVITY, - - LAST_PROP -}; + PROP_INTERFACE_FLAGS, +); enum { STATE_CHANGED, @@ -134,6 +70,64 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; +enum { + PROPERTY_O_IDX_ACTIVE_CONNECTION, + PROPERTY_O_IDX_IP4_CONFIG, + PROPERTY_O_IDX_IP6_CONFIG, + PROPERTY_O_IDX_DHCP4_CONFIG, + PROPERTY_O_IDX_DHCP6_CONFIG, + _PROPERTY_O_IDX_NUM, +}; + +typedef struct _NMDevicePrivate { + NMLDBusPropertyO property_o[_PROPERTY_O_IDX_NUM]; + NMLDBusPropertyAO available_connections; + GPtrArray *lldp_neighbors; + char *driver; + char *driver_version; + char *interface; + char *ip_interface; + char *firmware_version; + char *physical_port_id; + char *udi; + guint32 capabilities; + guint32 device_type; + guint32 ip4_connectivity; + guint32 ip6_connectivity; + guint32 metered; + guint32 mtu; + guint32 state; + guint32 state_reason; + guint32 interface_flags; + bool firmware_missing; + bool nm_plugin_missing; + bool autoconnect; + bool managed; + bool real; + + guint32 old_state; + + struct udev *udev; + char *type_description; + char *product; + char *vendor; + char *short_vendor; + char *description; + char *bus_name; + +} NMDevicePrivate; + +G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_OBJECT); + +#define NM_DEVICE_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMDevice, NM_IS_DEVICE, NMObject) + +/*****************************************************************************/ + +static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error); +static NMLldpNeighbor *nm_lldp_neighbor_dup (NMLldpNeighbor *neighbor); + +/*****************************************************************************/ + struct _NMLldpNeighbor { guint refcount; GHashTable *attrs; @@ -141,124 +135,132 @@ struct _NMLldpNeighbor { G_DEFINE_BOXED_TYPE (NMLldpNeighbor, nm_lldp_neighbor, nm_lldp_neighbor_dup, nm_lldp_neighbor_unref) +/*****************************************************************************/ + static void -nm_device_init (NMDevice *device) +nm_device_init (NMDevice *self) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); + NMDevicePrivate *priv; - priv->ip4_connectivity = NM_CONNECTIVITY_UNKNOWN; - priv->ip6_connectivity = NM_CONNECTIVITY_UNKNOWN; - priv->state = NM_DEVICE_STATE_UNKNOWN; - priv->reason = NM_DEVICE_STATE_REASON_NONE; - priv->lldp_neighbors = g_ptr_array_new (); -} + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_DEVICE, NMDevicePrivate); -static gboolean -demarshal_state_reason (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) -{ - guint32 *reason_field = field; + self->_priv = priv; - g_variant_get (value, "(uu)", NULL, reason_field); - _nm_object_queue_notify (object, NM_DEVICE_STATE_REASON); - return TRUE; + priv->old_state = NM_DEVICE_STATE_UNKNOWN; } -static gboolean -demarshal_lldp_neighbors (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object); - GVariantIter iter, attrs_iter; - GVariant *variant, *attr_variant; - const char *attr_name; - - g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("aa{sv}")), FALSE); +/*****************************************************************************/ - g_ptr_array_unref (priv->lldp_neighbors); - priv->lldp_neighbors = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_lldp_neighbor_unref); - g_variant_iter_init (&iter, value); +static void +_notify_event_state_changed (NMClient *client, + NMClientNotifyEventWithPtr *notify_event) +{ + gs_unref_object NMDevice *self = notify_event->user_data; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - while (g_variant_iter_next (&iter, "@a{sv}", &variant)) { - NMLldpNeighbor *neigh; + NML_NMCLIENT_LOG_T (_nm_object_get_client (self), + "[%s] emit Device's StateChanged signal %u -> %u, reason: %u", + _nm_object_get_path (self), + (guint) priv->old_state, + (guint) priv->state, + (guint) priv->state_reason); + + g_signal_emit (self, + signals[STATE_CHANGED], + 0, + (guint) priv->state, + (guint) priv->old_state, + (guint) priv->state_reason); +} + +static NMLDBusNotifyUpdatePropFlags +_notify_update_prop_state_reason (NMClient *client, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) +{ + NMDevice *self = NM_DEVICE (dbobj->nmobj); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + guint32 new_state = NM_DEVICE_STATE_UNKNOWN; + guint32 reason = NM_DEVICE_STATE_REASON_NONE; - neigh = nm_lldp_neighbor_new (); - g_variant_iter_init (&attrs_iter, variant); + /* We ignore the "State" property and the "StateChanged" signal of the device. + * This information is redundant to the "StateReason" property, and we rely + * on that one alone. In the best case, the information is identical. If it + * would not be, then we stick to the information from "StateReason" property. */ - while (g_variant_iter_next (&attrs_iter, "{&sv}", &attr_name, &attr_variant)) - g_hash_table_insert (neigh->attrs, g_strdup (attr_name), attr_variant); + if (value) + g_variant_get (value, "(uu)", &new_state, &reason); - g_variant_unref (variant); - g_ptr_array_add (priv->lldp_neighbors, neigh); + if ( priv->state == new_state + && priv->state_reason == reason) { + /* no changes. */ + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE; } - _nm_object_queue_notify (object, NM_DEVICE_LLDP_NEIGHBORS); + if (priv->state != new_state) { + priv->old_state = priv->state; + priv->state = new_state; + _nm_client_queue_notify_object (client, + self, + obj_properties[PROP_STATE]); + } - return TRUE; -} + if (priv->state_reason != reason) { + priv->state_reason = reason; + _nm_client_queue_notify_object (client, + self, + obj_properties[PROP_STATE_REASON]); + } -static void -device_state_reason_changed (GObject *object, GParamSpec *pspec, gpointer user_data); + _nm_client_notify_event_queue_with_ptr (client, + NM_CLIENT_NOTIFY_EVENT_PRIO_GPROP + 1, + _notify_event_state_changed, + g_object_ref (self)); -static void -init_dbus (NMObject *object) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DEVICE_UDI, &priv->udi }, - { NM_DEVICE_INTERFACE, &priv->iface }, - { NM_DEVICE_DEVICE_TYPE, &priv->device_type }, - { NM_DEVICE_IP_INTERFACE, &priv->ip_iface }, - { NM_DEVICE_DRIVER, &priv->driver }, - { NM_DEVICE_DRIVER_VERSION, &priv->driver_version }, - { NM_DEVICE_FIRMWARE_VERSION, &priv->firmware_version }, - { NM_DEVICE_CAPABILITIES, &priv->capabilities }, - { NM_DEVICE_REAL, &priv->real }, - { NM_DEVICE_MANAGED, &priv->managed }, - { NM_DEVICE_AUTOCONNECT, &priv->autoconnect }, - { NM_DEVICE_FIRMWARE_MISSING, &priv->firmware_missing }, - { NM_DEVICE_NM_PLUGIN_MISSING, &priv->nm_plugin_missing }, - { NM_DEVICE_IP4_CONFIG, &priv->ip4_config, NULL, NM_TYPE_IP4_CONFIG }, - { NM_DEVICE_DHCP4_CONFIG, &priv->dhcp4_config, NULL, NM_TYPE_DHCP4_CONFIG }, - { NM_DEVICE_IP6_CONFIG, &priv->ip6_config, NULL, NM_TYPE_IP6_CONFIG }, - { NM_DEVICE_DHCP6_CONFIG, &priv->dhcp6_config, NULL, NM_TYPE_DHCP6_CONFIG }, - { NM_DEVICE_IP4_CONNECTIVITY, &priv->ip4_connectivity }, - { NM_DEVICE_IP6_CONNECTIVITY, &priv->ip6_connectivity }, - { NM_DEVICE_STATE, &priv->state }, - { NM_DEVICE_STATE_REASON, &priv->reason, demarshal_state_reason }, - { NM_DEVICE_ACTIVE_CONNECTION, &priv->active_connection, NULL, NM_TYPE_ACTIVE_CONNECTION }, - { NM_DEVICE_AVAILABLE_CONNECTIONS, &priv->available_connections, NULL, NM_TYPE_REMOTE_CONNECTION }, - { NM_DEVICE_PHYSICAL_PORT_ID, &priv->physical_port_id }, - { NM_DEVICE_MTU, &priv->mtu }, - { NM_DEVICE_METERED, &priv->metered }, - { NM_DEVICE_LLDP_NEIGHBORS, &priv->lldp_neighbors, demarshal_lldp_neighbors }, - - /* Properties that exist in D-Bus but that we don't track */ - { "ip4-address", NULL }, - - { NULL }, - }; - - NM_OBJECT_CLASS (nm_device_parent_class)->init_dbus (object); - - priv->proxy = NMDBUS_DEVICE (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_DEVICE)); - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DEVICE, - property_info); - - g_signal_connect (priv->proxy, "notify::state-reason", - G_CALLBACK (device_state_reason_changed), object); + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE; } -static void -device_state_reason_changed (GObject *object, GParamSpec *pspec, gpointer user_data) +static NMLDBusNotifyUpdatePropFlags +_notify_update_prop_lldp_neighbors (NMClient *client, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) { - NMDevice *self = NM_DEVICE (user_data); + NMDevice *self = NM_DEVICE (dbobj->nmobj); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + gs_unref_ptrarray GPtrArray *old = NULL; + gs_unref_ptrarray GPtrArray *new = NULL; + GVariantIter *attrs_iter; + GVariantIter iter; + + new = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_lldp_neighbor_unref); + + if (value) { + g_variant_iter_init (&iter, value); + while (g_variant_iter_next (&iter, "a{sv}", &attrs_iter)) { + GVariant *attr_variant; + const char *attr_name; + NMLldpNeighbor *neigh; + + neigh = nm_lldp_neighbor_new (); + while (g_variant_iter_next (attrs_iter, "{&sv}", &attr_name, &attr_variant)) + g_hash_table_insert (neigh->attrs, g_strdup (attr_name), attr_variant); + g_ptr_array_add (new, neigh); + + g_variant_iter_free (attrs_iter); + } + } - g_signal_emit (self, signals[STATE_CHANGED], 0, - priv->state, priv->last_seen_state, priv->reason); - priv->last_seen_state = priv->state; + old = g_steal_pointer (&priv->lldp_neighbors); + priv->lldp_neighbors = g_steal_pointer (&new); + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY; } +/*****************************************************************************/ + static NMDeviceType coerce_type (NMDeviceType type) { @@ -299,37 +301,33 @@ coerce_type (NMDeviceType type) return NM_DEVICE_TYPE_UNKNOWN; } +/*****************************************************************************/ + static void -dispose (GObject *object) +register_client (NMObject *nmobj, + NMClient *client, + NMLDBusObject *dbobj) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object); - - g_clear_object (&priv->ip4_config); - g_clear_object (&priv->dhcp4_config); - g_clear_object (&priv->ip6_config); - g_clear_object (&priv->dhcp6_config); - g_clear_object (&priv->active_connection); - - udev_unref (priv->udev); - priv->udev = NULL; - - g_clear_pointer (&priv->available_connections, g_ptr_array_unref); - g_clear_pointer (&priv->lldp_neighbors, g_ptr_array_unref); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (nmobj); - if (priv->proxy) - g_signal_handlers_disconnect_by_func (priv->proxy, device_state_reason_changed, object); - g_clear_object (&priv->proxy); + priv->udev = _nm_client_get_udev (client); + if (priv->udev) + udev_ref (priv->udev); - G_OBJECT_CLASS (nm_device_parent_class)->dispose (object); + NM_OBJECT_CLASS (nm_device_parent_class)->register_client (nmobj, client, dbobj); } +/*****************************************************************************/ + static void finalize (GObject *object) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object); - g_free (priv->iface); - g_free (priv->ip_iface); + g_clear_pointer (&priv->lldp_neighbors, g_ptr_array_unref); + + g_free (priv->interface); + g_free (priv->ip_interface); g_free (priv->udi); g_free (priv->driver); g_free (priv->driver_version); @@ -342,6 +340,8 @@ finalize (GObject *object) g_free (priv->type_description); g_free (priv->physical_port_id); + nm_clear_pointer (&priv->udev, udev_unref); + G_OBJECT_CLASS (nm_device_parent_class)->finalize (object); } @@ -441,6 +441,9 @@ get_property (GObject *object, case PROP_IP6_CONNECTIVITY: g_value_set_enum (value, nm_device_get_connectivity (device, AF_INET6)); break; + case PROP_INTERFACE_FLAGS: + g_value_set_uint (value, nm_device_get_interface_flags (device)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -458,11 +461,6 @@ set_property (GObject *object, gboolean b; switch (prop_id) { - case PROP_MANAGED: - b = g_value_get_boolean (value); - if (priv->managed != b) - nm_device_set_managed (NM_DEVICE (object), b); - break; case PROP_AUTOCONNECT: b = g_value_get_boolean (value); if (priv->autoconnect != b) @@ -474,37 +472,87 @@ set_property (GObject *object, } } +/* TODO: statistics interface not yet implemented. */ +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_statistics = NML_DBUS_META_IFACE_INIT ( + NM_DBUS_INTERFACE_DEVICE_STATISTICS, + NULL, + NML_DBUS_META_INTERFACE_PRIO_NONE, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_TODO ("RefreshRateMs", "u" ), + NML_DBUS_META_PROPERTY_INIT_TODO ("RxBytes", "t" ), + NML_DBUS_META_PROPERTY_INIT_TODO ("TxBytes", "t" ), + ), +); + +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DEVICE, + nm_device_get_type, + NML_DBUS_META_INTERFACE_PRIO_PARENT_TYPE, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_O_PROP ("ActiveConnection", PROP_ACTIVE_CONNECTION, NMDevicePrivate, property_o[PROPERTY_O_IDX_ACTIVE_CONNECTION], nm_active_connection_get_type, .is_always_ready = TRUE ), + NML_DBUS_META_PROPERTY_INIT_B ("Autoconnect", PROP_AUTOCONNECT, NMDevicePrivate, autoconnect ), + NML_DBUS_META_PROPERTY_INIT_AO_PROP ("AvailableConnections", PROP_AVAILABLE_CONNECTIONS, NMDevicePrivate, available_connections, nm_remote_connection_get_type, .is_always_ready = TRUE ), + NML_DBUS_META_PROPERTY_INIT_U ("Capabilities", PROP_CAPABILITIES, NMDevicePrivate, capabilities ), + NML_DBUS_META_PROPERTY_INIT_U ("DeviceType", PROP_DEVICE_TYPE, NMDevicePrivate, device_type ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Dhcp4Config", PROP_DHCP4_CONFIG, NMDevicePrivate, property_o[PROPERTY_O_IDX_DHCP4_CONFIG], nm_dhcp4_config_get_type ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Dhcp6Config", PROP_DHCP6_CONFIG, NMDevicePrivate, property_o[PROPERTY_O_IDX_DHCP6_CONFIG], nm_dhcp6_config_get_type ), + NML_DBUS_META_PROPERTY_INIT_S ("Driver", PROP_DRIVER, NMDevicePrivate, driver ), + NML_DBUS_META_PROPERTY_INIT_S ("DriverVersion", PROP_DRIVER_VERSION, NMDevicePrivate, driver_version ), + NML_DBUS_META_PROPERTY_INIT_B ("FirmwareMissing", PROP_FIRMWARE_MISSING, NMDevicePrivate, firmware_missing ), + NML_DBUS_META_PROPERTY_INIT_S ("FirmwareVersion", PROP_FIRMWARE_VERSION, NMDevicePrivate, firmware_version ), + NML_DBUS_META_PROPERTY_INIT_S ("Interface", PROP_INTERFACE, NMDevicePrivate, interface ), + NML_DBUS_META_PROPERTY_INIT_U ("InterfaceFlags", PROP_INTERFACE_FLAGS, NMDevicePrivate, interface_flags ), + NML_DBUS_META_PROPERTY_INIT_IGNORE ("Ip4Address", "u" ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Ip4Config", PROP_IP4_CONFIG, NMDevicePrivate, property_o[PROPERTY_O_IDX_IP4_CONFIG], nm_ip4_config_get_type ), + NML_DBUS_META_PROPERTY_INIT_U ("Ip4Connectivity", PROP_IP4_CONNECTIVITY, NMDevicePrivate, ip4_connectivity ), + NML_DBUS_META_PROPERTY_INIT_O_PROP ("Ip6Config", PROP_IP6_CONFIG, NMDevicePrivate, property_o[PROPERTY_O_IDX_IP6_CONFIG], nm_ip6_config_get_type ), + NML_DBUS_META_PROPERTY_INIT_U ("Ip6Connectivity", PROP_IP6_CONNECTIVITY, NMDevicePrivate, ip6_connectivity ), + NML_DBUS_META_PROPERTY_INIT_S ("IpInterface", PROP_IP_INTERFACE, NMDevicePrivate, ip_interface ), + NML_DBUS_META_PROPERTY_INIT_FCN ("LldpNeighbors", PROP_LLDP_NEIGHBORS, "aa{sv}", _notify_update_prop_lldp_neighbors ), + NML_DBUS_META_PROPERTY_INIT_B ("Managed", PROP_MANAGED, NMDevicePrivate, managed ), + NML_DBUS_META_PROPERTY_INIT_U ("Metered", PROP_METERED, NMDevicePrivate, metered ), + NML_DBUS_META_PROPERTY_INIT_U ("Mtu", PROP_MTU, NMDevicePrivate, mtu ), + NML_DBUS_META_PROPERTY_INIT_B ("NmPluginMissing", PROP_NM_PLUGIN_MISSING, NMDevicePrivate, nm_plugin_missing ), + NML_DBUS_META_PROPERTY_INIT_S ("PhysicalPortId", PROP_PHYSICAL_PORT_ID, NMDevicePrivate, physical_port_id ), + NML_DBUS_META_PROPERTY_INIT_B ("Real", PROP_REAL, NMDevicePrivate, real ), + NML_DBUS_META_PROPERTY_INIT_IGNORE ("State", "u" ), + NML_DBUS_META_PROPERTY_INIT_FCN ("StateReason", PROP_STATE_REASON, "(uu)", _notify_update_prop_state_reason ), + NML_DBUS_META_PROPERTY_INIT_S ("Udi", PROP_UDI, NMDevicePrivate, udi ), + ), + .base_struct_offset = G_STRUCT_OFFSET (NMDevice, _priv), +); + static void -nm_device_class_init (NMDeviceClass *device_class) +nm_device_class_init (NMDeviceClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (device_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (device_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); - g_type_class_add_private (device_class, sizeof (NMDevicePrivate)); + g_type_class_add_private (klass, sizeof (NMDevicePrivate)); - /* virtual methods */ object_class->get_property = get_property; object_class->set_property = set_property; - object_class->dispose = dispose; - object_class->finalize = finalize; + object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; + nm_object_class->register_client = register_client; - device_class->connection_compatible = connection_compatible; + _NM_OBJECT_CLASS_INIT_PRIV_PTR_INDIRECT (nm_object_class, NMDevice); - /* properties */ + _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_N (nm_object_class, NMDevicePrivate, property_o); + _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDevicePrivate, available_connections); + + klass->connection_compatible = connection_compatible; /** * NMDevice:interface: * * The interface of the device. **/ - g_object_class_install_property - (object_class, PROP_INTERFACE, - g_param_spec_string (NM_DEVICE_INTERFACE, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_INTERFACE] = + g_param_spec_string (NM_DEVICE_INTERFACE, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:ip-interface: @@ -512,25 +560,23 @@ nm_device_class_init (NMDeviceClass *device_class) * The IP interface of the device which should be used for all IP-related * operations like addressing and routing. **/ - g_object_class_install_property - (object_class, PROP_IP_INTERFACE, - g_param_spec_string (NM_DEVICE_IP_INTERFACE, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_IP_INTERFACE] = + g_param_spec_string (NM_DEVICE_IP_INTERFACE, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:device-type: * * The numeric type of the device. **/ - g_object_class_install_property - (object_class, PROP_DEVICE_TYPE, - g_param_spec_enum (NM_DEVICE_DEVICE_TYPE, "", "", - NM_TYPE_DEVICE_TYPE, - NM_DEVICE_TYPE_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DEVICE_TYPE] = + g_param_spec_enum (NM_DEVICE_DEVICE_TYPE, "", "", + NM_TYPE_DEVICE_TYPE, + NM_DEVICE_TYPE_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:udi: * @@ -541,61 +587,56 @@ nm_device_class_init (NMDeviceClass *device_class) * such as Bluez or ModemManager, and clients can use this property to * request more information about the device from those services. **/ - g_object_class_install_property - (object_class, PROP_UDI, - g_param_spec_string (NM_DEVICE_UDI, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_UDI] = + g_param_spec_string (NM_DEVICE_UDI, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:driver: * * The driver of the device. **/ - g_object_class_install_property - (object_class, PROP_DRIVER, - g_param_spec_string (NM_DEVICE_DRIVER, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DRIVER] = + g_param_spec_string (NM_DEVICE_DRIVER, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:driver-version: * * The version of the device driver. **/ - g_object_class_install_property - (object_class, PROP_DRIVER_VERSION, - g_param_spec_string (NM_DEVICE_DRIVER_VERSION, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DRIVER_VERSION] = + g_param_spec_string (NM_DEVICE_DRIVER_VERSION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:firmware-version: * * The firmware version of the device. **/ - g_object_class_install_property - (object_class, PROP_FIRMWARE_VERSION, - g_param_spec_string (NM_DEVICE_FIRMWARE_VERSION, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_FIRMWARE_VERSION] = + g_param_spec_string (NM_DEVICE_FIRMWARE_VERSION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:capabilities: * * The capabilities of the device. **/ - g_object_class_install_property - (object_class, PROP_CAPABILITIES, - g_param_spec_flags (NM_DEVICE_CAPABILITIES, "", "", - NM_TYPE_DEVICE_CAPABILITIES, - NM_DEVICE_CAP_NONE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_CAPABILITIES] = + g_param_spec_flags (NM_DEVICE_CAPABILITIES, "", "", + NM_TYPE_DEVICE_CAPABILITIES, + NM_DEVICE_CAP_NONE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:real: @@ -606,36 +647,35 @@ nm_device_class_init (NMDeviceClass *device_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_REAL, - g_param_spec_boolean (NM_DEVICE_REAL, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_REAL] = + g_param_spec_boolean (NM_DEVICE_REAL, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:managed: * * Whether the device is managed by NetworkManager. **/ - g_object_class_install_property - (object_class, PROP_MANAGED, - g_param_spec_boolean (NM_DEVICE_MANAGED, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MANAGED] = + g_param_spec_boolean (NM_DEVICE_MANAGED, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:autoconnect: * * Whether the device can auto-activate a connection. + * + * The property setter is a synchronous D-Bus call. This is deprecated since 1.22. **/ - g_object_class_install_property - (object_class, PROP_AUTOCONNECT, - g_param_spec_boolean (NM_DEVICE_AUTOCONNECT, "", "", - TRUE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_AUTOCONNECT] = + g_param_spec_boolean (NM_DEVICE_AUTOCONNECT, "", "", + FALSE, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:firmware-missing: @@ -643,12 +683,11 @@ nm_device_class_init (NMDeviceClass *device_class) * When %TRUE indicates the device is likely missing firmware required * for its operation. **/ - g_object_class_install_property - (object_class, PROP_FIRMWARE_MISSING, - g_param_spec_boolean (NM_DEVICE_FIRMWARE_MISSING, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_FIRMWARE_MISSING] = + g_param_spec_boolean (NM_DEVICE_FIRMWARE_MISSING, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:nm-plugin-missing: @@ -658,60 +697,55 @@ nm_device_class_init (NMDeviceClass *device_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_NM_PLUGIN_MISSING, - g_param_spec_boolean (NM_DEVICE_NM_PLUGIN_MISSING, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_NM_PLUGIN_MISSING] = + g_param_spec_boolean (NM_DEVICE_NM_PLUGIN_MISSING, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:ip4-config: * * The #NMIP4Config of the device. **/ - g_object_class_install_property - (object_class, PROP_IP4_CONFIG, - g_param_spec_object (NM_DEVICE_IP4_CONFIG, "", "", - NM_TYPE_IP_CONFIG, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_IP4_CONFIG] = + g_param_spec_object (NM_DEVICE_IP4_CONFIG, "", "", + NM_TYPE_IP_CONFIG, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:dhcp4-config: * * The IPv4 #NMDhcpConfig of the device. **/ - g_object_class_install_property - (object_class, PROP_DHCP4_CONFIG, - g_param_spec_object (NM_DEVICE_DHCP4_CONFIG, "", "", - NM_TYPE_DHCP_CONFIG, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DHCP4_CONFIG] = + g_param_spec_object (NM_DEVICE_DHCP4_CONFIG, "", "", + NM_TYPE_DHCP_CONFIG, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:ip6-config: * * The IPv6 #NMIPConfig of the device. **/ - g_object_class_install_property - (object_class, PROP_IP6_CONFIG, - g_param_spec_object (NM_DEVICE_IP6_CONFIG, "", "", - NM_TYPE_IP_CONFIG, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_IP6_CONFIG] = + g_param_spec_object (NM_DEVICE_IP6_CONFIG, "", "", + NM_TYPE_IP_CONFIG, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:dhcp6-config: * * The IPv6 #NMDhcpConfig of the device. **/ - g_object_class_install_property - (object_class, PROP_DHCP6_CONFIG, - g_param_spec_object (NM_DEVICE_DHCP6_CONFIG, "", "", - NM_TYPE_DHCP_CONFIG, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DHCP6_CONFIG] = + g_param_spec_object (NM_DEVICE_DHCP6_CONFIG, "", "", + NM_TYPE_DHCP_CONFIG, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:ip4-connectivity: @@ -720,13 +754,12 @@ nm_device_class_init (NMDeviceClass *device_class) * * Since: 1.16 **/ - g_object_class_install_property - (object_class, PROP_IP4_CONNECTIVITY, - g_param_spec_enum (NM_DEVICE_IP4_CONNECTIVITY, "", "", - NM_TYPE_CONNECTIVITY_STATE, - NM_CONNECTIVITY_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_IP4_CONNECTIVITY] = + g_param_spec_enum (NM_DEVICE_IP4_CONNECTIVITY, "", "", + NM_TYPE_CONNECTIVITY_STATE, + NM_CONNECTIVITY_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:ip6-connectivity: @@ -735,86 +768,79 @@ nm_device_class_init (NMDeviceClass *device_class) * * Since: 1.16 **/ - g_object_class_install_property - (object_class, PROP_IP6_CONNECTIVITY, - g_param_spec_enum (NM_DEVICE_IP6_CONNECTIVITY, "", "", - NM_TYPE_CONNECTIVITY_STATE, - NM_CONNECTIVITY_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_IP6_CONNECTIVITY] = + g_param_spec_enum (NM_DEVICE_IP6_CONNECTIVITY, "", "", + NM_TYPE_CONNECTIVITY_STATE, + NM_CONNECTIVITY_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:state: * * The state of the device. **/ - g_object_class_install_property - (object_class, PROP_STATE, - g_param_spec_enum (NM_DEVICE_STATE, "", "", - NM_TYPE_DEVICE_STATE, - NM_DEVICE_STATE_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_STATE] = + g_param_spec_enum (NM_DEVICE_STATE, "", "", + NM_TYPE_DEVICE_STATE, + NM_DEVICE_STATE_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:state-reason: * * The reason for the device state. **/ - g_object_class_install_property - (object_class, PROP_STATE_REASON, - g_param_spec_uint (NM_DEVICE_STATE_REASON, "", "", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_STATE_REASON] = + g_param_spec_uint (NM_DEVICE_STATE_REASON, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:active-connection: * * The #NMActiveConnection object that "owns" this device during activation. **/ - g_object_class_install_property - (object_class, PROP_ACTIVE_CONNECTION, - g_param_spec_object (NM_DEVICE_ACTIVE_CONNECTION, "", "", - NM_TYPE_ACTIVE_CONNECTION, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ACTIVE_CONNECTION] = + g_param_spec_object (NM_DEVICE_ACTIVE_CONNECTION, "", "", + NM_TYPE_ACTIVE_CONNECTION, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:available-connections: (type GPtrArray(NMRemoteConnection)) * * The available connections of the device **/ - g_object_class_install_property - (object_class, PROP_AVAILABLE_CONNECTIONS, - g_param_spec_boxed (NM_DEVICE_AVAILABLE_CONNECTIONS, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_AVAILABLE_CONNECTIONS] = + g_param_spec_boxed (NM_DEVICE_AVAILABLE_CONNECTIONS, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:vendor: * * The vendor string of the device. **/ - g_object_class_install_property - (object_class, PROP_VENDOR, - g_param_spec_string (NM_DEVICE_VENDOR, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_VENDOR] = + g_param_spec_string (NM_DEVICE_VENDOR, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:product: * * The product string of the device. **/ - g_object_class_install_property - (object_class, PROP_PRODUCT, - g_param_spec_string (NM_DEVICE_PRODUCT, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PRODUCT] = + g_param_spec_string (NM_DEVICE_PRODUCT, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:physical-port-id: @@ -822,24 +848,22 @@ nm_device_class_init (NMDeviceClass *device_class) * The physical port ID of the device. (See * nm_device_get_physical_port_id().) **/ - g_object_class_install_property - (object_class, PROP_PHYSICAL_PORT_ID, - g_param_spec_string (NM_DEVICE_PHYSICAL_PORT_ID, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PHYSICAL_PORT_ID] = + g_param_spec_string (NM_DEVICE_PHYSICAL_PORT_ID, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:mtu: * * The MTU of the device. **/ - g_object_class_install_property - (object_class, PROP_MTU, - g_param_spec_uint (NM_DEVICE_MTU, "", "", - 0, G_MAXUINT32, 1500, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MTU] = + g_param_spec_uint (NM_DEVICE_MTU, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:metered: @@ -848,26 +872,37 @@ nm_device_class_init (NMDeviceClass *device_class) * * Since: 1.2 **/ - g_object_class_install_property - (object_class, PROP_METERED, - g_param_spec_uint (NM_DEVICE_METERED, "", "", - 0, G_MAXUINT32, NM_METERED_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_METERED] = + g_param_spec_uint (NM_DEVICE_METERED, "", "", + 0, G_MAXUINT32, NM_METERED_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDevice:lldp-neighbors: * * The LLDP neighbors. **/ - g_object_class_install_property - (object_class, PROP_LLDP_NEIGHBORS, - g_param_spec_boxed (NM_DEVICE_LLDP_NEIGHBORS, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_LLDP_NEIGHBORS] = + g_param_spec_boxed (NM_DEVICE_LLDP_NEIGHBORS, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); - /* signals */ + /** + * NMDevice:interface-flags: + * + * The interface flags. + * + * Since: 1.22 + **/ + obj_properties[PROP_INTERFACE_FLAGS] = + g_param_spec_uint (NM_DEVICE_INTERFACE_FLAGS, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device); /** * NMDevice::state-changed: @@ -879,13 +914,12 @@ nm_device_class_init (NMDeviceClass *device_class) * Notifies the state change of a #NMDevice. **/ signals[STATE_CHANGED] = - g_signal_new ("state-changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMDeviceClass, state_changed), - NULL, NULL, NULL, - G_TYPE_NONE, 3, - G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT); + g_signal_new ("state-changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 3, + G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT); } /** @@ -902,7 +936,7 @@ nm_device_get_iface (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->iface); + return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->interface); } /** @@ -920,7 +954,7 @@ nm_device_get_ip_iface (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->ip_iface); + return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->ip_interface); } /** @@ -954,7 +988,7 @@ nm_device_get_udi (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->udi); + return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->udi); } /** @@ -971,7 +1005,7 @@ nm_device_get_driver (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->driver); + return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->driver); } /** @@ -988,7 +1022,7 @@ nm_device_get_driver_version (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->driver_version); + return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->driver_version); } /** @@ -1005,7 +1039,7 @@ nm_device_get_firmware_version (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->firmware_version); + return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->firmware_version); } /** @@ -1030,7 +1064,7 @@ nm_device_get_type_description (NMDevice *device) g_return_val_if_fail (NM_IS_DEVICE (device), NULL); if (priv->type_description) - return nm_str_not_empty (priv->type_description); + return _nml_coerce_property_str_not_empty (priv->type_description); if (NM_DEVICE_GET_CLASS (device)->get_type_description) { desc = NM_DEVICE_GET_CLASS (device)->get_type_description (device); @@ -1043,7 +1077,7 @@ nm_device_get_type_description (NMDevice *device) typename += 8; priv->type_description = g_ascii_strdown (typename, -1); - return nm_str_not_empty (priv->type_description); + return _nml_coerce_property_str_not_empty (priv->type_description); } /** @@ -1106,20 +1140,30 @@ nm_device_get_managed (NMDevice *device) * Enables or disables management of #NMDevice by NetworkManager. * * Since: 1.2 + * + * Deprecated: 1.22, use nm_device_set_managed_async() or GDBusConnection + * + * This function is deprecated because it calls a synchronous D-Bus method + * and modifies the content of the NMClient cache client side. Also, it does + * not emit a property changed signal. **/ void nm_device_set_managed (NMDevice *device, gboolean managed) { g_return_if_fail (NM_IS_DEVICE (device)); + /* FIXME(libnm-async-api): add nm_device_set_managed_async(). */ + managed = !!managed; NM_DEVICE_GET_PRIVATE (device)->managed = managed; - _nm_object_set_property (NM_OBJECT (device), - NM_DBUS_INTERFACE_DEVICE, - "Managed", - "b", managed); + _nm_client_set_property_sync_legacy (_nm_object_get_client (device), + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE, + "Managed", + "b", + managed); } /** @@ -1144,18 +1188,27 @@ nm_device_get_autoconnect (NMDevice *device) * @autoconnect: %TRUE to enable autoconnecting * * Enables or disables automatic activation of the #NMDevice. + * + * Deprecated: 1.22, use nm_device_set_autoconnect_async() or GDBusConnection + * + * This function is deprecated because it calls a synchronous D-Bus method + * and modifies the content of the NMClient cache client side. **/ void nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect) { g_return_if_fail (NM_IS_DEVICE (device)); + /* FIXME(libnm-async-api): add nm_device_set_autoconnect_async(). */ + NM_DEVICE_GET_PRIVATE (device)->autoconnect = autoconnect; - _nm_object_set_property (NM_OBJECT (device), - NM_DBUS_INTERFACE_DEVICE, - "Autoconnect", - "b", autoconnect); + _nm_client_set_property_sync_legacy (_nm_object_get_client (device), + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE, + "AutoConnect", + "b", + autoconnect); } /** @@ -1211,7 +1264,7 @@ nm_device_get_ip4_config (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return NM_DEVICE_GET_PRIVATE (device)->ip4_config; + return nml_dbus_property_o_get_obj (&NM_DEVICE_GET_PRIVATE (device)->property_o[PROPERTY_O_IDX_IP4_CONFIG]); } /** @@ -1231,7 +1284,7 @@ nm_device_get_dhcp4_config (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return NM_DEVICE_GET_PRIVATE (device)->dhcp4_config; + return nml_dbus_property_o_get_obj (&NM_DEVICE_GET_PRIVATE (device)->property_o[PROPERTY_O_IDX_DHCP4_CONFIG]); } /** @@ -1250,7 +1303,7 @@ nm_device_get_ip6_config (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return NM_DEVICE_GET_PRIVATE (device)->ip6_config; + return nml_dbus_property_o_get_obj (&NM_DEVICE_GET_PRIVATE (device)->property_o[PROPERTY_O_IDX_IP6_CONFIG]); } /** @@ -1270,7 +1323,7 @@ nm_device_get_dhcp6_config (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return NM_DEVICE_GET_PRIVATE (device)->dhcp6_config; + return nml_dbus_property_o_get_obj (&NM_DEVICE_GET_PRIVATE (device)->property_o[PROPERTY_O_IDX_DHCP6_CONFIG]); } /** @@ -1304,6 +1357,24 @@ nm_device_get_connectivity (NMDevice *device, int addr_family) } /** + * nm_device_get_interface_flags: + * @device: a #NMDevice + * + * Gets the interface flags of the device. + * + * Returns: the flags + * + * Since: 1.22 + **/ +NMDeviceInterfaceFlags +nm_device_get_interface_flags (NMDevice *device) +{ + g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_INTERFACE_FLAG_NONE); + + return NM_DEVICE_GET_PRIVATE (device)->interface_flags; +} + +/** * nm_device_get_state: * @device: a #NMDevice * @@ -1332,7 +1403,7 @@ nm_device_get_state_reason (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_STATE_REASON_UNKNOWN); - return NM_DEVICE_GET_PRIVATE (device)->reason; + return NM_DEVICE_GET_PRIVATE (device)->state_reason; } /** @@ -1347,9 +1418,14 @@ nm_device_get_state_reason (NMDevice *device) NMActiveConnection * nm_device_get_active_connection (NMDevice *device) { + NMActiveConnection *ac; + g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return NM_DEVICE_GET_PRIVATE (device)->active_connection; + ac = nml_dbus_property_o_get_obj (&NM_DEVICE_GET_PRIVATE (device)->property_o[PROPERTY_O_IDX_ACTIVE_CONNECTION]); + + nm_assert (!ac || NM_IS_ACTIVE_CONNECTION (ac)); + return ac; } /** @@ -1368,7 +1444,7 @@ nm_device_get_available_connections (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return NM_DEVICE_GET_PRIVATE (device)->available_connections; + return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_GET_PRIVATE (device)->available_connections); } static const char * @@ -1471,7 +1547,8 @@ get_bus_name (NMDevice *device) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); struct udev_device *udevice; - const char *ifname, *bus; + const char *ifname; + const char *bus; if (priv->bus_name) goto out; @@ -1509,31 +1586,18 @@ out: return NULL; } -void -_nm_device_set_udev (NMDevice *device, struct udev *udev) -{ - NMDevicePrivate *priv; - - nm_assert (NM_IS_DEVICE (device)); - nm_assert (udev); - - priv = NM_DEVICE_GET_PRIVATE (device); - - nm_assert (!priv->udev); - - priv->udev = udev_ref (udev); -} - static char * _get_udev_property (NMDevice *device, const char *enc_prop, /* ID_XXX_ENC */ const char *db_prop) /* ID_XXX_FROM_DATABASE */ { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); - struct udev_device *udev_device, *tmpdev; + struct udev_device *udev_device; + struct udev_device *tmpdev; const char *ifname; guint32 count = 0; - char *enc_value = NULL, *db_value = NULL; + char *enc_value = NULL; + char *db_value = NULL; if (!priv->udev) return NULL; @@ -1895,7 +1959,7 @@ nm_device_get_physical_port_id (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->physical_port_id); + return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->physical_port_id); } /** @@ -1950,9 +2014,14 @@ NM_BACKPORT_SYMBOL (libnm_1_0_6, NMMetered, nm_device_get_metered, (NMDevice *de GPtrArray * nm_device_get_lldp_neighbors (NMDevice *device) { - g_return_val_if_fail (NM_IS_DEVICE (device), NULL); + NMDevicePrivate *priv; + + g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - return NM_DEVICE_GET_PRIVATE (device)->lldp_neighbors; + priv = NM_DEVICE_GET_PRIVATE (device); + if (!priv->lldp_neighbors) + priv->lldp_neighbors = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_lldp_neighbor_unref); + return priv->lldp_neighbors; } /** @@ -2007,6 +2076,8 @@ nm_device_is_software (NMDevice *device) * Returns: %TRUE on success, %FALSE on error, in which case @error will be set. * * Since: 1.2 + * + * Deprecated: 1.22, use nm_device_reapply_async() or GDBusConnection **/ gboolean nm_device_reapply (NMDevice *device, @@ -2016,40 +2087,31 @@ nm_device_reapply (NMDevice *device, GCancellable *cancellable, GError **error) { - GVariant *dict = NULL; - gboolean ret; + GVariant *arg_connection = NULL; g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); + g_return_val_if_fail (!connection || NM_IS_CONNECTION (connection), FALSE); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); + g_return_val_if_fail (!error || !*error, FALSE); if (connection) - dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); - if (!dict) - dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0); - - ret = nmdbus_device_call_reapply_sync (NM_DEVICE_GET_PRIVATE (device)->proxy, - dict, version_id, flags, cancellable, error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - -static void -device_reapply_cb (GObject *proxy, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nmdbus_device_call_reapply_finish (NMDBUS_DEVICE (proxy), result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - - g_simple_async_result_complete (simple); - g_object_unref (simple); + arg_connection = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); + if (!arg_connection) + arg_connection = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0); + + return _nm_client_dbus_call_sync_void (_nm_object_get_client (device), + cancellable, + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE, + "Reapply", + g_variant_new ("(@a{sa{sv}}tu)", + arg_connection, + version_id, + flags), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); } /** @@ -2080,24 +2142,34 @@ nm_device_reapply_async (NMDevice *device, GAsyncReadyCallback callback, gpointer user_data) { - GVariant *dict = NULL; - GSimpleAsyncResult *simple; + GVariant *arg_connection = NULL; g_return_if_fail (NM_IS_DEVICE (device)); + g_return_if_fail (!connection || NM_IS_CONNECTION (connection)); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); if (connection) - dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); - if (!dict) - dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0); - - simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data, - nm_device_reapply_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nmdbus_device_call_reapply (NM_DEVICE_GET_PRIVATE (device)->proxy, - dict, version_id, flags, cancellable, - device_reapply_cb, simple); + arg_connection = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); + if (!arg_connection) + arg_connection = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0); + + _nm_client_dbus_call (_nm_object_get_client (device), + device, + nm_device_reapply_async, + cancellable, + callback, + user_data, + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE, + "Reapply", + g_variant_new ("(@a{sa{sv}}tu)", + arg_connection, + version_id, + flags), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_strip_dbus_error_cb); } /** @@ -2118,15 +2190,10 @@ nm_device_reapply_finish (NMDevice *device, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_reapply_async), FALSE); + g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_reapply_async), FALSE); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); + return g_task_propagate_boolean (G_TASK (result), error); } /*****************************************************************************/ @@ -2149,6 +2216,8 @@ nm_device_reapply_finish (NMDevice *device, * to nm_connection_verify(). * * Since: 1.2 + * + * Deprecated: 1.22, use nm_device_get_applied_connection_async() or GDBusConnection **/ NMConnection * nm_device_get_applied_connection (NMDevice *device, @@ -2157,80 +2226,42 @@ nm_device_get_applied_connection (NMDevice *device, GCancellable *cancellable, GError **error) { - gs_unref_variant GVariant *dict = NULL; - guint64 my_version_id; - gboolean success; + gs_unref_variant GVariant *ret = NULL; + gs_unref_variant GVariant *v_connection = NULL; + guint64 v_version_id; NMConnection *connection; g_return_val_if_fail (NM_IS_DEVICE (device), NULL); g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL); g_return_val_if_fail (!error || !*error, NULL); - success = nmdbus_device_call_get_applied_connection_sync (NM_DEVICE_GET_PRIVATE (device)->proxy, - flags, &dict, &my_version_id, cancellable, error); - if (!success) { - if (error && *error) - g_dbus_error_strip_remote_error (*error); + ret = _nm_client_dbus_call_sync (_nm_object_get_client (device), + cancellable, + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE, + "GetAppliedConnection", + g_variant_new ("(u)", flags), + G_VARIANT_TYPE ("(a{sa{sv}}t)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); + if (!ret) return NULL; - } - connection = _nm_simple_connection_new_from_dbus (dict, NM_SETTING_PARSE_FLAGS_BEST_EFFORT, error); + g_variant_get (ret, + "(@a{sa{sv}}t)", + &v_connection, + &v_version_id); + + connection = _nm_simple_connection_new_from_dbus (v_connection, NM_SETTING_PARSE_FLAGS_BEST_EFFORT, error); if (!connection) return NULL; - NM_SET_OUT (version_id, my_version_id); + NM_SET_OUT (version_id, v_version_id); return connection; } -typedef struct { - NMConnection *connection; - guint64 version_id; -} GetAppliedConnectionData; - -static void -device_get_applied_connection_data_free (gpointer user_data) -{ - GetAppliedConnectionData *data = user_data; - - g_return_if_fail (data); - - g_object_unref (data->connection); - g_slice_free (GetAppliedConnectionData, data); -} - -static void -device_get_applied_connection_cb (GObject *proxy, - GAsyncResult *result, - gpointer user_data) -{ - gs_unref_object GSimpleAsyncResult *simple = user_data; - gs_unref_variant GVariant *dict = NULL; - guint64 my_version_id; - GError *error = NULL; - NMConnection *connection; - GetAppliedConnectionData *data; - - if (!nmdbus_device_call_get_applied_connection_finish (NMDBUS_DEVICE (proxy), &dict, &my_version_id, result, &error)) { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - goto out; - } - - connection = _nm_simple_connection_new_from_dbus (dict, NM_SETTING_PARSE_FLAGS_BEST_EFFORT, &error); - if (!connection) { - g_simple_async_result_take_error (simple, error); - goto out; - } - - data = g_slice_new (GetAppliedConnectionData); - data->connection = connection; - data->version_id = my_version_id; - g_simple_async_result_set_op_res_gpointer (simple, data, device_get_applied_connection_data_free); - -out: - g_simple_async_result_complete (simple); -} - /** * nm_device_get_applied_connection_async: * @device: a #NMDevice @@ -2250,19 +2281,23 @@ nm_device_get_applied_connection_async (NMDevice *device, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - g_return_if_fail (NM_IS_DEVICE (device)); g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data, - nm_device_get_applied_connection_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nmdbus_device_call_get_applied_connection (NM_DEVICE_GET_PRIVATE (device)->proxy, - flags, cancellable, - device_get_applied_connection_cb, simple); + _nm_client_dbus_call (_nm_object_get_client (device), + device, + nm_device_get_applied_connection_async, + cancellable, + callback, + user_data, + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE, + "GetAppliedConnection", + g_variant_new ("(u)", flags), + G_VARIANT_TYPE ("(a{sa{sv}}t)"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_variant_strip_dbus_error_cb); } /** @@ -2289,23 +2324,30 @@ nm_device_get_applied_connection_finish (NMDevice *device, guint64 *version_id, GError **error) { - GSimpleAsyncResult *simple; - GetAppliedConnectionData *data; + gs_unref_variant GVariant *ret = NULL; + gs_unref_variant GVariant *v_connection = NULL; + guint64 v_version_id; + NMConnection *connection; g_return_val_if_fail (NM_IS_DEVICE (device), NULL); - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_get_applied_connection_async), NULL); + g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_get_applied_connection_async), NULL); g_return_val_if_fail (!error || !*error, NULL); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) + ret = g_task_propagate_pointer (G_TASK (result), error); + if (!ret) return NULL; - data = g_simple_async_result_get_op_res_gpointer (simple); - g_return_val_if_fail (data, NULL); - g_return_val_if_fail (NM_IS_CONNECTION (data->connection), NULL); + g_variant_get (ret, + "(@a{sa{sv}}t)", + &v_connection, + &v_version_id); - NM_SET_OUT (version_id, data->version_id); - return g_object_ref (data->connection); + connection = _nm_simple_connection_new_from_dbus (v_connection, NM_SETTING_PARSE_FLAGS_BEST_EFFORT, error); + if (!connection) + return NULL; + + NM_SET_OUT (version_id, v_version_id); + return connection; } /*****************************************************************************/ @@ -2321,40 +2363,28 @@ nm_device_get_applied_connection_finish (NMDevice *device, * request. * * Returns: %TRUE on success, %FALSE on error, in which case @error will be set. + * + * Deprecated: 1.22, use nm_device_disconnect_async() or GDBusConnection **/ gboolean nm_device_disconnect (NMDevice *device, GCancellable *cancellable, GError **error) { - gboolean ret; - g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); + g_return_val_if_fail (!error || !*error, FALSE); - ret = nmdbus_device_call_disconnect_sync (NM_DEVICE_GET_PRIVATE (device)->proxy, - cancellable, error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - -static void -device_disconnect_cb (GObject *proxy, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nmdbus_device_call_disconnect_finish (NMDBUS_DEVICE (proxy), result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - - g_simple_async_result_complete (simple); - g_object_unref (simple); + return _nm_client_dbus_call_sync_void (_nm_object_get_client (device), + cancellable, + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE, + "Disconnect", + g_variant_new ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); } /** @@ -2374,18 +2404,23 @@ nm_device_disconnect_async (NMDevice *device, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - g_return_if_fail (NM_IS_DEVICE (device)); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data, - nm_device_disconnect_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nmdbus_device_call_disconnect (NM_DEVICE_GET_PRIVATE (device)->proxy, - cancellable, - device_disconnect_cb, simple); + _nm_client_dbus_call (_nm_object_get_client (device), + device, + nm_device_disconnect_async, + cancellable, + callback, + user_data, + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE, + "Disconnect", + g_variant_new ("()"), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_strip_dbus_error_cb); } /** @@ -2404,15 +2439,10 @@ nm_device_disconnect_finish (NMDevice *device, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_disconnect_async), FALSE); + g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_disconnect_async), FALSE); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); + return g_task_propagate_boolean (G_TASK (result), error); } /** @@ -2425,40 +2455,28 @@ nm_device_disconnect_finish (NMDevice *device, * * Returns: %TRUE on success, %FALSE on error, in which case @error * will be set. + * + * Deprecated: 1.22, use nm_device_delete_async() or GDBusConnection **/ gboolean nm_device_delete (NMDevice *device, GCancellable *cancellable, GError **error) { - gboolean ret; - g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); + g_return_val_if_fail (!error || !*error, FALSE); - ret = nmdbus_device_call_delete_sync (NM_DEVICE_GET_PRIVATE (device)->proxy, - cancellable, error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - -static void -device_delete_cb (GObject *proxy, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nmdbus_device_call_delete_finish (NMDBUS_DEVICE (proxy), result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - - g_simple_async_result_complete (simple); - g_object_unref (simple); + return _nm_client_dbus_call_sync_void (_nm_object_get_client (device), + cancellable, + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE, + "Delete", + g_variant_new ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); } /** @@ -2477,18 +2495,23 @@ nm_device_delete_async (NMDevice *device, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *simple; - g_return_if_fail (NM_IS_DEVICE (device)); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data, - nm_device_delete_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nmdbus_device_call_delete (NM_DEVICE_GET_PRIVATE (device)->proxy, - cancellable, - device_delete_cb, simple); + _nm_client_dbus_call (_nm_object_get_client (device), + device, + nm_device_delete_async, + cancellable, + callback, + user_data, + _nm_object_get_path (device), + NM_DBUS_INTERFACE_DEVICE, + "Delete", + g_variant_new ("()"), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_strip_dbus_error_cb); } /** @@ -2507,15 +2530,10 @@ nm_device_delete_finish (NMDevice *device, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_delete_async), FALSE); + g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_delete_async), FALSE); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); + return g_task_propagate_boolean (G_TASK (result), error); } /** diff --git a/libnm/nm-device.h b/libnm/nm-device.h index e8190e90..78130c1b 100644 --- a/libnm/nm-device.h +++ b/libnm/nm-device.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2013 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2013 Red Hat, Inc. */ #ifndef __NM_DEVICE_H__ @@ -46,7 +32,10 @@ G_BEGIN_DECLS #define NM_DEVICE_CAPABILITIES "capabilities" #define NM_DEVICE_REAL "real" #define NM_DEVICE_MANAGED "managed" + +_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY #define NM_DEVICE_AUTOCONNECT "autoconnect" + #define NM_DEVICE_FIRMWARE_MISSING "firmware-missing" #define NM_DEVICE_NM_PLUGIN_MISSING "nm-plugin-missing" #define NM_DEVICE_IP4_CONFIG "ip4-config" @@ -65,36 +54,12 @@ G_BEGIN_DECLS #define NM_DEVICE_LLDP_NEIGHBORS "lldp-neighbors" #define NM_DEVICE_IP4_CONNECTIVITY "ip4-connectivity" #define NM_DEVICE_IP6_CONNECTIVITY "ip6-connectivity" +#define NM_DEVICE_INTERFACE_FLAGS "interface-flags" /** * NMDevice: */ -struct _NMDevice { - NMObject parent; -}; - -typedef struct { - NMObjectClass parent; - - /* Signals */ - void (*state_changed) (NMDevice *device, - NMDeviceState new_state, - NMDeviceState old_state, - NMDeviceStateReason reason); - - /* Methods */ - gboolean (*connection_compatible) (NMDevice *device, - NMConnection *connection, - GError **error); - - const char * (*get_type_description) (NMDevice *device); - const char * (*get_hw_address) (NMDevice *device); - - GType (*get_setting_type) (NMDevice *device); - - /*< private >*/ - gpointer padding[8]; -} NMDeviceClass; +typedef struct _NMDeviceClass NMDeviceClass; typedef struct _NMLldpNeighbor NMLldpNeighbor; @@ -111,10 +76,18 @@ const char * nm_device_get_type_description (NMDevice *device); const char * nm_device_get_hw_address (NMDevice *device); NMDeviceCapabilities nm_device_get_capabilities (NMDevice *device); gboolean nm_device_get_managed (NMDevice *device); + NM_AVAILABLE_IN_1_2 +NM_DEPRECATED_IN_1_22 +_NM_DEPRECATED_SYNC_METHOD void nm_device_set_managed (NMDevice *device, gboolean managed); + gboolean nm_device_get_autoconnect (NMDevice *device); + +NM_DEPRECATED_IN_1_22 +_NM_DEPRECATED_SYNC_METHOD void nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect); + gboolean nm_device_get_firmware_missing (NMDevice *device); NM_AVAILABLE_IN_1_2 gboolean nm_device_get_nm_plugin_missing (NMDevice *device); @@ -141,9 +114,13 @@ NM_AVAILABLE_IN_1_2 NMMetered nm_device_get_metered (NMDevice *device); NM_AVAILABLE_IN_1_2 GPtrArray * nm_device_get_lldp_neighbors (NMDevice *device); +NM_AVAILABLE_IN_1_22 +NMDeviceInterfaceFlags nm_device_get_interface_flags (NMDevice *device); + char ** nm_device_disambiguate_names (NMDevice **devices, int num_devices); NM_AVAILABLE_IN_1_2 +_NM_DEPRECATED_SYNC_METHOD gboolean nm_device_reapply (NMDevice *device, NMConnection *connection, guint64 version_id, @@ -164,6 +141,7 @@ gboolean nm_device_reapply_finish (NMDevice *device, GError **error); NM_AVAILABLE_IN_1_2 +_NM_DEPRECATED_SYNC_METHOD NMConnection *nm_device_get_applied_connection (NMDevice *device, guint32 flags, guint64 *version_id, @@ -181,6 +159,7 @@ NMConnection *nm_device_get_applied_connection_finish (NMDevice *device, guint64 *version_id, GError **error); +_NM_DEPRECATED_SYNC_METHOD gboolean nm_device_disconnect (NMDevice *device, GCancellable *cancellable, GError **error); @@ -192,6 +171,7 @@ gboolean nm_device_disconnect_finish (NMDevice *device, GAsyncResult *result, GError **error); +_NM_DEPRECATED_SYNC_METHOD gboolean nm_device_delete (NMDevice *device, GCancellable *cancellable, GError **error); diff --git a/libnm/nm-dhcp-config.c b/libnm/nm-dhcp-config.c index 39adbaf9..fcafcecc 100644 --- a/libnm/nm-dhcp-config.c +++ b/libnm/nm-dhcp-config.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2008 - 2014 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright (C) 2008 - 2014 Red Hat, Inc. + * Copyright (C) 2008 Novell, Inc. */ #include "nm-default.h" @@ -28,66 +14,63 @@ #include "nm-object-private.h" #include "nm-utils.h" -G_DEFINE_ABSTRACT_TYPE (NMDhcpConfig, nm_dhcp_config, NM_TYPE_OBJECT) +/*****************************************************************************/ -#define NM_DHCP_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_CONFIG, NMDhcpConfigPrivate)) +NM_GOBJECT_PROPERTIES_DEFINE (NMDhcpConfig, + PROP_FAMILY, + PROP_OPTIONS, +); -typedef struct { +typedef struct _NMDhcpConfigPrivate { GHashTable *options; } NMDhcpConfigPrivate; -enum { - PROP_0, - PROP_FAMILY, - PROP_OPTIONS, - - LAST_PROP -}; +G_DEFINE_ABSTRACT_TYPE (NMDhcpConfig, nm_dhcp_config, NM_TYPE_OBJECT) -static void -nm_dhcp_config_init (NMDhcpConfig *config) -{ - NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (config); +#define NM_DHCP_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMDhcpConfig, NM_IS_DHCP_CONFIG, NMObject) - priv->options = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); -} +/*****************************************************************************/ -static gboolean -demarshal_dhcp_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) +static NMLDBusNotifyUpdatePropFlags +_notify_update_prop_options (NMClient *client, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) { - NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object); - GVariantIter iter; - const char *key; - GVariant *opt; + NMDhcpConfig *self = NM_DHCP_CONFIG (dbobj->nmobj); + NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (self); g_hash_table_remove_all (priv->options); - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) { - g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL)); - g_variant_unref (opt); + if (value) { + GVariantIter iter; + const char *key; + GVariant *opt; + + g_variant_iter_init (&iter, value); + while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) { + if (g_variant_is_of_type (opt, G_VARIANT_TYPE_STRING)) + g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL)); + g_variant_unref (opt); + } } - _nm_object_queue_notify (object, NM_DHCP_CONFIG_OPTIONS); - return TRUE; + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY; } +/*****************************************************************************/ + static void -init_dbus (NMObject *object) +nm_dhcp_config_init (NMDhcpConfig *self) { - NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DHCP_CONFIG_OPTIONS, &priv->options, demarshal_dhcp_options }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_dhcp_config_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - (NM_IS_DHCP4_CONFIG (object) ? - NM_DBUS_INTERFACE_DHCP4_CONFIG : - NM_DBUS_INTERFACE_DHCP6_CONFIG), - property_info); + NMDhcpConfigPrivate *priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_DHCP_CONFIG, NMDhcpConfigPrivate); + + self->_priv = priv; + + priv->options = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); } static void @@ -95,8 +78,7 @@ finalize (GObject *object) { NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object); - if (priv->options) - g_hash_table_destroy (priv->options); + g_hash_table_destroy (priv->options); G_OBJECT_CLASS (nm_dhcp_config_parent_class)->finalize (object); } @@ -122,21 +104,35 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_dhcp4config = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DHCP4_CONFIG, + nm_dhcp4_config_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_FCN ("Options", PROP_OPTIONS, "a{sv}", _notify_update_prop_options ), + ), + .base_struct_offset = G_STRUCT_OFFSET (NMDhcpConfig, _priv), +); + +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_dhcp6config = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_DHCP6_CONFIG, + nm_dhcp6_config_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_FCN ("Options", PROP_OPTIONS, "a{sv}", _notify_update_prop_options ), + ), + .base_struct_offset = G_STRUCT_OFFSET (NMDhcpConfig, _priv), +); + static void nm_dhcp_config_class_init (NMDhcpConfigClass *config_class) { GObjectClass *object_class = G_OBJECT_CLASS (config_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class); g_type_class_add_private (config_class, sizeof (NMDhcpConfigPrivate)); - /* virtual methods */ object_class->get_property = get_property; - object_class->finalize = finalize; - - nm_object_class->init_dbus = init_dbus; - - /* properties */ + object_class->finalize = finalize; /** * NMDhcpConfig:family: @@ -144,24 +140,25 @@ nm_dhcp_config_class_init (NMDhcpConfigClass *config_class) * The IP address family of the configuration; either * <literal>AF_INET</literal> or <literal>AF_INET6</literal>. **/ - g_object_class_install_property - (object_class, PROP_FAMILY, - g_param_spec_int (NM_DHCP_CONFIG_FAMILY, "", "", - 0, 255, AF_UNSPEC, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_FAMILY] = + g_param_spec_int (NM_DHCP_CONFIG_FAMILY, "", "", + 0, 255, AF_UNSPEC, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMDhcpConfig:options: (type GHashTable(utf8,utf8)): * * The #GHashTable containing options of the configuration. **/ - g_object_class_install_property - (object_class, PROP_OPTIONS, - g_param_spec_boxed (NM_DHCP_CONFIG_OPTIONS, "", "", - G_TYPE_HASH_TABLE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_OPTIONS] = + g_param_spec_boxed (NM_DHCP_CONFIG_OPTIONS, "", "", + G_TYPE_HASH_TABLE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_dhcp4config, + &_nml_dbus_meta_iface_nm_dhcp6config); } /** diff --git a/libnm/nm-dhcp-config.h b/libnm/nm-dhcp-config.h index d6c56b34..8f967a58 100644 --- a/libnm/nm-dhcp-config.h +++ b/libnm/nm-dhcp-config.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2008 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright (C) 2008 Red Hat, Inc. + * Copyright (C) 2008 Novell, Inc. */ #ifndef __NM_DHCP_CONFIG_H__ @@ -38,16 +24,7 @@ G_BEGIN_DECLS /** * NMDhcpConfig: */ -struct _NMDhcpConfig { - NMObject parent; -}; - -typedef struct { - NMObjectClass parent; - - /*< private >*/ - gpointer padding[8]; -} NMDhcpConfigClass; +typedef struct _NMDhcpConfigClass NMDhcpConfigClass; #define NM_DHCP_CONFIG_FAMILY "family" #define NM_DHCP_CONFIG_OPTIONS "options" diff --git a/libnm/nm-dhcp4-config.c b/libnm/nm-dhcp4-config.c index afe408b9..89d3835e 100644 --- a/libnm/nm-dhcp4-config.c +++ b/libnm/nm-dhcp4-config.c @@ -1,30 +1,26 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2014 Red Hat, Inc. + * Copyright (C) 2014 Red Hat, Inc. */ #include "nm-default.h" #include "nm-dhcp4-config.h" -#include "nm-object-private.h" +/*****************************************************************************/ + +struct _NMDhcp4Config { + NMDhcpConfig parent; +}; + +struct _NMDhcp4ConfigClass{ + NMDhcpConfigClass parent; +}; G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_DHCP_CONFIG) +/*****************************************************************************/ + static void nm_dhcp4_config_init (NMDhcp4Config *config) { diff --git a/libnm/nm-dhcp4-config.h b/libnm/nm-dhcp4-config.h index 32cc101c..7ce4d844 100644 --- a/libnm/nm-dhcp4-config.h +++ b/libnm/nm-dhcp4-config.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2014 Red Hat, Inc. + * Copyright (C) 2014 Red Hat, Inc. */ #ifndef __NM_DHCP4_CONFIG_H__ @@ -31,17 +17,13 @@ #define NM_DHCP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigClass)) #define NM_IS_DHCP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP4_CONFIG)) #define NM_IS_DHCP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP4_CONFIG)) +#define NM_DHCP4_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigClass)) /** * NMDhcp4Config: */ -typedef struct { - NMDhcpConfig parent; -} NMDhcp4Config; - -typedef struct { - NMDhcpConfigClass parent; -} NMDhcp4ConfigClass; +typedef struct _NMDhcp4Config NMDhcp4Config; +typedef struct _NMDhcp4ConfigClass NMDhcp4ConfigClass; GType nm_dhcp4_config_get_type (void); diff --git a/libnm/nm-dhcp6-config.c b/libnm/nm-dhcp6-config.c index 94d42bfe..acb72876 100644 --- a/libnm/nm-dhcp6-config.c +++ b/libnm/nm-dhcp6-config.c @@ -1,30 +1,26 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2014 Red Hat, Inc. + * Copyright (C) 2014 Red Hat, Inc. */ #include "nm-default.h" #include "nm-dhcp6-config.h" -#include "nm-object-private.h" +/*****************************************************************************/ + +struct _NMDhcp6Config { + NMDhcpConfig parent; +}; + +struct _NMDhcp6ConfigClass{ + NMDhcpConfigClass parent; +}; G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_DHCP_CONFIG) +/*****************************************************************************/ + static void nm_dhcp6_config_init (NMDhcp6Config *config) { diff --git a/libnm/nm-dhcp6-config.h b/libnm/nm-dhcp6-config.h index 532f6d2a..05223a16 100644 --- a/libnm/nm-dhcp6-config.h +++ b/libnm/nm-dhcp6-config.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2014 Red Hat, Inc. + * Copyright (C) 2014 Red Hat, Inc. */ #ifndef __NM_DHCP6_CONFIG_H__ @@ -31,17 +17,13 @@ #define NM_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigClass)) #define NM_IS_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP6_CONFIG)) #define NM_IS_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP6_CONFIG)) +#define NM_DHCP6_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigClass)) /** * NMDhcp6Config: */ -typedef struct { - NMDhcpConfig parent; -} NMDhcp6Config; - -typedef struct { - NMDhcpConfigClass parent; -} NMDhcp6ConfigClass; +typedef struct _NMDhcp6Config NMDhcp6Config; +typedef struct _NMDhcp6ConfigClass NMDhcp6ConfigClass; GType nm_dhcp6_config_get_type (void); diff --git a/libnm/nm-dns-manager.c b/libnm/nm-dns-manager.c index 3b2ed90c..9fe759d3 100644 --- a/libnm/nm-dns-manager.c +++ b/libnm/nm-dns-manager.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2016 Red Hat, Inc. + * Copyright (C) 2016 Red Hat, Inc. */ #include "nm-default.h" @@ -28,28 +14,6 @@ #include "nm-dbus-helpers.h" #include "nm-core-internal.h" -#include "introspection/org.freedesktop.NetworkManager.DnsManager.h" - -G_DEFINE_TYPE (NMDnsManager, nm_dns_manager, NM_TYPE_OBJECT) - -#define NM_DNS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DNS_MANAGER, NMDnsManagerPrivate)) - -typedef struct { - NMDBusDnsManager *proxy; - char *mode; - char *rc_manager; - GPtrArray *configuration; -} NMDnsManagerPrivate; - -enum { - PROP_0, - PROP_MODE, - PROP_RC_MANAGER, - PROP_CONFIGURATION, - - LAST_PROP -}; - /***************************************************************************** * NMDnsEntry *****************************************************************************/ @@ -251,196 +215,3 @@ nm_dns_entry_get_priority (NMDnsEntry *entry) return entry->priority; } - -/*****************************************************************************/ - -static gboolean -demarshal_dns_configuration (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) -{ - NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (object); - GVariant *entry_var; - GVariantIter iter, *iterp; - NMDnsEntry *entry; - GPtrArray *array; - - g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("aa{sv}")), FALSE); - - g_variant_iter_init (&iter, value); - g_ptr_array_unref (priv->configuration); - priv->configuration = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_dns_entry_unref); - - while (g_variant_iter_next (&iter, "@a{sv}", &entry_var)) { - char **nameservers = NULL, **domains = NULL; - gboolean vpn = FALSE; - char *interface = NULL, *str; - int priority; - - if ( !g_variant_lookup (entry_var, "nameservers", "as", &iterp) - || !g_variant_lookup (entry_var, "priority", "i", &priority)) { - g_warning ("Ignoring invalid DNS configuration"); - g_variant_unref (entry_var); - continue; - } - - array = g_ptr_array_new (); - while (g_variant_iter_next (iterp, "&s", &str)) - g_ptr_array_add (array, str); - g_ptr_array_add (array, NULL); - nameservers = (char **) g_ptr_array_free (array, FALSE); - g_variant_iter_free (iterp); - - if (g_variant_lookup (entry_var, "domains", "as", &iterp)) { - array = g_ptr_array_new (); - while (g_variant_iter_next (iterp, "&s", &str)) - g_ptr_array_add (array, str); - g_ptr_array_add (array, NULL); - domains = (char **) g_ptr_array_free (array, FALSE); - g_variant_iter_free (iterp); - } - - g_variant_lookup (entry_var, "interface", "&s", &interface); - g_variant_lookup (entry_var, "priority", "i", &priority); - g_variant_lookup (entry_var, "vpn", "b", &vpn); - - entry = nm_dns_entry_new (interface, - (const char * const *) nameservers, - (const char * const *) domains, - priority, - vpn); - g_free (domains); - g_free (nameservers); - g_variant_unref (entry_var); - if (!entry) { - g_warning ("Ignoring invalid DNS entry"); - continue; - } - - g_ptr_array_add (priv->configuration, entry); - } - - _nm_object_queue_notify (object, NM_DNS_MANAGER_CONFIGURATION); - - return TRUE; -} - -/*****************************************************************************/ -const char * -nm_dns_manager_get_mode (NMDnsManager *manager) -{ - return NM_DNS_MANAGER_GET_PRIVATE (manager)->mode; -} - -const char * -nm_dns_manager_get_rc_manager (NMDnsManager *manager) -{ - return NM_DNS_MANAGER_GET_PRIVATE (manager)->rc_manager; -} - -const GPtrArray * -nm_dns_manager_get_configuration (NMDnsManager *manager) -{ - return NM_DNS_MANAGER_GET_PRIVATE (manager)->configuration; -} -/*****************************************************************************/ - -static void -nm_dns_manager_init (NMDnsManager *self) -{ - NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self); - - priv->configuration = g_ptr_array_new (); -} - -static void -init_dbus (NMObject *object) -{ - NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DNS_MANAGER_MODE, &priv->mode }, - { NM_DNS_MANAGER_RC_MANAGER, &priv->rc_manager }, - { NM_DNS_MANAGER_CONFIGURATION, &priv->configuration, demarshal_dns_configuration }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_dns_manager_parent_class)->init_dbus (object); - - priv->proxy = NMDBUS_DNS_MANAGER (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_DNS_MANAGER)); - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DNS_MANAGER, - property_info); -} - -static void -dispose (GObject *object) -{ - NMDnsManager *self = NM_DNS_MANAGER (object); - NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self); - - g_clear_pointer (&priv->mode, g_free); - g_clear_pointer (&priv->rc_manager, g_free); - g_clear_pointer (&priv->configuration, g_ptr_array_unref); - - G_OBJECT_CLASS (nm_dns_manager_parent_class)->dispose (object); -} - -static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_MODE: - g_value_set_string (value, priv->mode); - break; - case PROP_RC_MANAGER: - g_value_set_string (value, priv->rc_manager); - break; - case PROP_CONFIGURATION: - g_value_take_boxed (value, _nm_utils_copy_array (priv->configuration, - (NMUtilsCopyFunc) nm_dns_entry_dup, - (GDestroyNotify) nm_dns_entry_unref)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -nm_dns_manager_class_init (NMDnsManagerClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (class); - - g_type_class_add_private (class, sizeof (NMDnsManagerPrivate)); - - /* Virtual methods */ - object_class->get_property = get_property; - object_class->dispose = dispose; - - nm_object_class->init_dbus = init_dbus; - - /* Properties */ - - g_object_class_install_property - (object_class, PROP_MODE, - g_param_spec_string (NM_DNS_MANAGER_MODE, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_RC_MANAGER, - g_param_spec_string (NM_DNS_MANAGER_RC_MANAGER, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_CONFIGURATION, - g_param_spec_boxed (NM_DNS_MANAGER_CONFIGURATION, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); -} diff --git a/libnm/nm-dns-manager.h b/libnm/nm-dns-manager.h index fbe0caa6..c645e434 100644 --- a/libnm/nm-dns-manager.h +++ b/libnm/nm-dns-manager.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2016 Red Hat, Inc. + * Copyright (C) 2016 Red Hat, Inc. */ #ifndef __NM_DNS_MANAGER_H__ @@ -24,45 +10,13 @@ #error Cannot use this header. #endif -#include "nm-object.h" #include "nm-client.h" -#define NM_TYPE_DNS_MANAGER (nm_dns_manager_get_type ()) -#define NM_DNS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DNS_MANAGER, NMDnsManager)) -#define NM_DNS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DNS_MANAGER, NMDnsManagerClass)) -#define NM_IS_DNS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DNS_MANAGER)) -#define NM_IS_DNS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DNS_MANAGER)) -#define NM_DNS_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DNS_MANAGER, NMDnsManagerClass)) - -#define NM_DNS_MANAGER_MODE "mode" -#define NM_DNS_MANAGER_RC_MANAGER "rc-manager" -#define NM_DNS_MANAGER_CONFIGURATION "configuration" - -typedef struct _NMDnsManager NMDnsManager; -typedef struct _NMDnsManagerClass NMDnsManagerClass; - -/** - * NMDnsManager: - */ -struct _NMDnsManager { - NMObject parent; -}; - -struct _NMDnsManagerClass { - NMObjectClass parent; -}; - -GType nm_dns_manager_get_type (void); - -const char *nm_dns_manager_get_mode (NMDnsManager *manager); -const char *nm_dns_manager_get_rc_manager (NMDnsManager *manager); -const GPtrArray *nm_dns_manager_get_configuration (NMDnsManager *manager); - -NMDnsEntry * nm_dns_entry_new (const char *interface, - const char * const *nameservers, - const char * const *domains, - int priority, - gboolean vpn); -NMDnsEntry * nm_dns_entry_dup (NMDnsEntry *entry); +NMDnsEntry *nm_dns_entry_new (const char *interface, + const char * const *nameservers, + const char * const *domains, + int priority, + gboolean vpn); +NMDnsEntry *nm_dns_entry_dup (NMDnsEntry *entry); #endif /* __NM_DNS_MANAGER_H__ */ diff --git a/libnm/nm-ip-config.c b/libnm/nm-ip-config.c index 9df071d8..f214cdc4 100644 --- a/libnm/nm-ip-config.c +++ b/libnm/nm-ip-config.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2011 Novell, Inc. - * Copyright 2008 - 2014 Red Hat, Inc. + * Copyright (C) 2007 - 2011 Novell, Inc. + * Copyright (C) 2008 - 2014 Red Hat, Inc. */ #include "nm-default.h" @@ -30,24 +16,9 @@ #include "nm-utils.h" #include "nm-core-internal.h" -G_DEFINE_ABSTRACT_TYPE (NMIPConfig, nm_ip_config, NM_TYPE_OBJECT) - -#define NM_IP_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP_CONFIG, NMIPConfigPrivate)) - -typedef struct { - char *gateway; - GPtrArray *addresses; - GPtrArray *routes; - char **nameservers; - char **domains; - char **searches; - char **wins; - - gboolean new_style_data; -} NMIPConfigPrivate; +/*****************************************************************************/ -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE (NMIPConfig, PROP_FAMILY, PROP_GATEWAY, PROP_ADDRESSES, @@ -56,156 +27,214 @@ enum { PROP_DOMAINS, PROP_SEARCHES, PROP_WINS_SERVERS, +); - LAST_PROP -}; - -static void -nm_ip_config_init (NMIPConfig *config) -{ - NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (config); - - priv->addresses = g_ptr_array_new (); - priv->routes = g_ptr_array_new (); - priv->nameservers = g_new0 (char *, 1); - priv->domains = g_new0 (char *, 1); - priv->searches = g_new0 (char *, 1); - priv->wins = g_new0 (char *, 1); -} +typedef struct _NMIPConfigPrivate { + GPtrArray *addresses; + GPtrArray *routes; + char **nameservers; + char **domains; + char **searches; + char **wins_servers; + char *gateway; -static gboolean -demarshal_ip_addresses (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) -{ - NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object); + bool addresses_new_style:1; + bool routes_new_style:1; + bool nameservers_new_style:1; + bool wins_servers_new_style:1; +} NMIPConfigPrivate; - if (priv->new_style_data) - return TRUE; +G_DEFINE_ABSTRACT_TYPE (NMIPConfig, nm_ip_config, NM_TYPE_OBJECT) - g_ptr_array_unref (priv->addresses); - if (NM_IS_IP4_CONFIG (object)) - priv->addresses = nm_utils_ip4_addresses_from_variant (value, NULL); - else - priv->addresses = nm_utils_ip6_addresses_from_variant (value, NULL); - _nm_object_queue_notify (object, NM_IP_CONFIG_ADDRESSES); +#define NM_IP_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMIPConfig, NM_IS_IP_CONFIG, NMObject) - return TRUE; -} +/*****************************************************************************/ -static gboolean -demarshal_ip_address_data (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) +static NMLDBusNotifyUpdatePropFlags +_notify_update_prop_addresses (NMClient *client, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) { - NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object); - - priv->new_style_data = TRUE; - - g_ptr_array_unref (priv->addresses); - if (NM_IS_IP4_CONFIG (object)) - priv->addresses = nm_utils_ip_addresses_from_variant (value, AF_INET); - else - priv->addresses = nm_utils_ip_addresses_from_variant (value, AF_INET6); - _nm_object_queue_notify (object, NM_IP_CONFIG_ADDRESSES); + NMIPConfig *self = NM_IP_CONFIG (dbobj->nmobj); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self); + gs_unref_ptrarray GPtrArray *addresses_old = NULL; + gs_unref_ptrarray GPtrArray *addresses_new = NULL; + int addr_family = meta_iface == &_nml_dbus_meta_iface_nm_ip4config + ? AF_INET : AF_INET6; + gboolean new_style; + + new_style = (((const char *) meta_iface->dbus_properties[dbus_property_idx].dbus_type)[2] == '{'); + + if (priv->addresses_new_style) { + if (!new_style) + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE; + } else + priv->addresses_new_style = new_style; + + if (value) { + if (new_style) + addresses_new = nm_utils_ip_addresses_from_variant (value, addr_family); + else if (addr_family == AF_INET) + addresses_new = nm_utils_ip4_addresses_from_variant (value, NULL); + else + addresses_new = nm_utils_ip6_addresses_from_variant (value, NULL); + nm_assert (addresses_new); + } + if (!addresses_new) + addresses_new = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref); - return TRUE; + addresses_old = priv->addresses; + priv->addresses = g_steal_pointer (&addresses_new); + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY; } -static gboolean -demarshal_ip_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) +static NMLDBusNotifyUpdatePropFlags +_notify_update_prop_routes (NMClient *client, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) { - char ***obj_field; - - obj_field = field; - if (*obj_field) - g_strfreev (*obj_field); - - if (NM_IS_IP4_CONFIG (object)) - *obj_field = nm_utils_ip4_dns_from_variant (value); - else - *obj_field = nm_utils_ip6_dns_from_variant (value); + NMIPConfig *self = NM_IP_CONFIG (dbobj->nmobj); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self); + gs_unref_ptrarray GPtrArray *routes_old = NULL; + gs_unref_ptrarray GPtrArray *routes_new = NULL; + int addr_family = meta_iface == &_nml_dbus_meta_iface_nm_ip4config + ? AF_INET : AF_INET6; + gboolean new_style; + + new_style = (((const char *) meta_iface->dbus_properties[dbus_property_idx].dbus_type)[2] == '{'); + + if (priv->routes_new_style) { + if (!new_style) + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE; + } else + priv->routes_new_style = new_style; + + if (value) { + if (new_style) + routes_new = nm_utils_ip_routes_from_variant (value, addr_family); + else if (addr_family == AF_INET) + routes_new = nm_utils_ip4_routes_from_variant (value); + else + routes_new = nm_utils_ip6_routes_from_variant (value); + nm_assert (routes_new); + } + if (!routes_new) + routes_new = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref); - _nm_object_queue_notify (object, pspec->name); - return TRUE; + routes_old = priv->routes; + priv->routes = g_steal_pointer (&routes_new); + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY; } -static gboolean -demarshal_ip_routes (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) +static NMLDBusNotifyUpdatePropFlags +_notify_update_prop_nameservers (NMClient *client, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) { - NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object); - - if (priv->new_style_data) - return TRUE; + NMIPConfig *self = NM_IP_CONFIG (dbobj->nmobj); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self); + gs_strfreev char **nameservers_new = NULL; + gboolean new_style = TRUE; + int addr_family = meta_iface == &_nml_dbus_meta_iface_nm_ip4config + ? AF_INET : AF_INET6; + + if (addr_family == AF_INET) { + new_style = (((const char *) meta_iface->dbus_properties[dbus_property_idx].dbus_type)[1] == 'a'); + + if (priv->nameservers_new_style) { + if (!new_style) + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE; + } else + priv->nameservers_new_style = new_style; + } - g_ptr_array_unref (priv->routes); - if (NM_IS_IP4_CONFIG (object)) - priv->routes = nm_utils_ip4_routes_from_variant (value); - else - priv->routes = nm_utils_ip6_routes_from_variant (value); - _nm_object_queue_notify (object, NM_IP_CONFIG_ROUTES); + if (value) { + if (addr_family == AF_INET6) + nameservers_new = nm_utils_ip6_dns_from_variant (value); + else if (!new_style) + nameservers_new = nm_utils_ip4_dns_from_variant (value); + else { + GVariantIter iter; + GVariantIter *iter_v; + gs_unref_ptrarray GPtrArray *arr = NULL; + + g_variant_iter_init (&iter, value); + while (g_variant_iter_next (&iter, "a{sv}", &iter_v)) { + const char *key; + GVariant *val; + + while (g_variant_iter_next (iter_v, "{&sv}", &key, &val)) { + if (nm_streq (key, "address")) { + gs_free char *val_str = NULL; + + if (!g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) + goto next; + if (!nm_utils_parse_inaddr (AF_INET, g_variant_get_string (val, NULL), &val_str)) + goto next; + if (!arr) + arr = g_ptr_array_new (); + g_ptr_array_add (arr, g_steal_pointer (&val_str)); + goto next; + } +next: + g_variant_unref (val); + } + g_variant_iter_free (iter_v); + } + if ( arr + && arr->len > 0) + nameservers_new = nm_utils_strv_dup (arr->pdata, arr->len, FALSE); + else + nameservers_new = g_new0 (char *, 1); + } + nm_assert (nameservers_new); + } - return TRUE; + g_strfreev (priv->nameservers); + priv->nameservers = g_steal_pointer (&nameservers_new); + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY; } -static gboolean -demarshal_ip_route_data (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) +static NMLDBusNotifyUpdatePropFlags +_notify_update_prop_wins_servers (NMClient *client, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value) { - NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object); - - priv->new_style_data = TRUE; - - g_ptr_array_unref (priv->routes); - if (NM_IS_IP4_CONFIG (object)) - priv->routes = nm_utils_ip_routes_from_variant (value, AF_INET); - else - priv->routes = nm_utils_ip_routes_from_variant (value, AF_INET6); - _nm_object_queue_notify (object, NM_IP_CONFIG_ROUTES); + NMIPConfig *self = NM_IP_CONFIG (dbobj->nmobj); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self); + gs_strfreev char **wins_servers_new = NULL; + gboolean new_style; + + new_style = (((const char *) meta_iface->dbus_properties[dbus_property_idx].dbus_type)[1] == 's'); + + if (priv->wins_servers_new_style) { + if (!new_style) + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE; + } else + priv->wins_servers_new_style = new_style; + + if (value) { + if (new_style) + wins_servers_new = g_variant_dup_strv (value, NULL); + else + wins_servers_new = nm_utils_ip4_dns_from_variant (value); + nm_assert (wins_servers_new); + } - return TRUE; + g_strfreev (priv->wins_servers); + priv->wins_servers = g_steal_pointer (&wins_servers_new); + return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY; } -static void -init_dbus (NMObject *object) -{ - NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_IP_CONFIG_GATEWAY, &priv->gateway, }, - { NM_IP_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip_addresses }, - { "address-data", &priv->addresses, demarshal_ip_address_data }, - { NM_IP_CONFIG_ROUTES, &priv->routes, demarshal_ip_routes }, - { "route-data", &priv->routes, demarshal_ip_route_data }, - /* Still use deprecated "Nameservers" property instead of "NameserverData" */ - { NM_IP_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip_array }, - { NM_IP_CONFIG_DOMAINS, &priv->domains, }, - { NM_IP_CONFIG_SEARCHES, &priv->searches, }, - /* Still use deprecated "WinsServers" property instead of "WinsServerData" */ - { NM_IP_CONFIG_WINS_SERVERS, &priv->wins, demarshal_ip_array }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_ip_config_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - (NM_IS_IP4_CONFIG (object) ? - NM_DBUS_INTERFACE_IP4_CONFIG : - NM_DBUS_INTERFACE_IP6_CONFIG), - property_info); -} - -static void -finalize (GObject *object) -{ - NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object); - - g_free (priv->gateway); - - g_ptr_array_unref (priv->addresses); - g_ptr_array_unref (priv->routes); - - g_strfreev (priv->nameservers); - g_strfreev (priv->domains); - g_strfreev (priv->searches); - g_strfreev (priv->wins); - - G_OBJECT_CLASS (nm_ip_config_parent_class)->finalize (object); -} +/*****************************************************************************/ static void get_property (GObject *object, @@ -250,21 +279,89 @@ get_property (GObject *object, } } +/*****************************************************************************/ + +static void +nm_ip_config_init (NMIPConfig *self) +{ + NMIPConfigPrivate *priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_IP_CONFIG, NMIPConfigPrivate); + + self->_priv = priv; + + priv->addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref); + priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref); +} + +static void +finalize (GObject *object) +{ + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object); + + g_free (priv->gateway); + + g_ptr_array_unref (priv->routes); + g_ptr_array_unref (priv->addresses); + + g_strfreev (priv->nameservers); + g_strfreev (priv->domains); + g_strfreev (priv->searches); + g_strfreev (priv->wins_servers); + + G_OBJECT_CLASS (nm_ip_config_parent_class)->finalize (object); +} + +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_ip4config = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_IP4_CONFIG, + nm_ip4_config_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_FCN ("AddressData", PROP_ADDRESSES, "aa{sv}", _notify_update_prop_addresses ), + NML_DBUS_META_PROPERTY_INIT_FCN ("Addresses", PROP_ADDRESSES, "aau", _notify_update_prop_addresses, .obj_property_no_reverse_idx = TRUE ), + NML_DBUS_META_PROPERTY_INIT_TODO ("DnsOptions", "as" ), + NML_DBUS_META_PROPERTY_INIT_TODO ("DnsPriority", "i" ), + NML_DBUS_META_PROPERTY_INIT_AS ("Domains", PROP_DOMAINS, NMIPConfigPrivate, domains ), + NML_DBUS_META_PROPERTY_INIT_S ("Gateway", PROP_GATEWAY, NMIPConfigPrivate, gateway ), + NML_DBUS_META_PROPERTY_INIT_FCN ("NameserverData", PROP_NAMESERVERS, "aa{sv}", _notify_update_prop_nameservers ), + NML_DBUS_META_PROPERTY_INIT_FCN ("Nameservers", PROP_NAMESERVERS, "au", _notify_update_prop_nameservers, .obj_property_no_reverse_idx = TRUE ), + NML_DBUS_META_PROPERTY_INIT_FCN ("RouteData", PROP_ROUTES, "aa{sv}", _notify_update_prop_routes ), + NML_DBUS_META_PROPERTY_INIT_FCN ("Routes", PROP_ROUTES, "aau", _notify_update_prop_routes, .obj_property_no_reverse_idx = TRUE ), + NML_DBUS_META_PROPERTY_INIT_AS ("Searches", PROP_SEARCHES, NMIPConfigPrivate, searches ), + NML_DBUS_META_PROPERTY_INIT_FCN ("WinsServerData", PROP_WINS_SERVERS, "as", _notify_update_prop_wins_servers ), + NML_DBUS_META_PROPERTY_INIT_FCN ("WinsServers", PROP_WINS_SERVERS, "au", _notify_update_prop_wins_servers, .obj_property_no_reverse_idx = TRUE ), + ), + .base_struct_offset = G_STRUCT_OFFSET (NMIPConfig, _priv), +); + +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_ip6config = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_IP6_CONFIG, + nm_ip6_config_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_FCN ("AddressData", PROP_ADDRESSES, "aa{sv}", _notify_update_prop_addresses ), + NML_DBUS_META_PROPERTY_INIT_FCN ("Addresses", PROP_ADDRESSES, "a(ayuay)", _notify_update_prop_addresses, .obj_property_no_reverse_idx = TRUE ), + NML_DBUS_META_PROPERTY_INIT_TODO ("DnsOptions", "as" ), + NML_DBUS_META_PROPERTY_INIT_TODO ("DnsPriority", "i" ), + NML_DBUS_META_PROPERTY_INIT_AS ("Domains", PROP_DOMAINS, NMIPConfigPrivate, domains ), + NML_DBUS_META_PROPERTY_INIT_S ("Gateway", PROP_GATEWAY, NMIPConfigPrivate, gateway ), + NML_DBUS_META_PROPERTY_INIT_FCN ("Nameservers", PROP_NAMESERVERS, "aay", _notify_update_prop_nameservers ), + NML_DBUS_META_PROPERTY_INIT_FCN ("RouteData", PROP_ROUTES, "aa{sv}", _notify_update_prop_routes ), + NML_DBUS_META_PROPERTY_INIT_FCN ("Routes", PROP_ROUTES, "a(ayuayu)", _notify_update_prop_routes, .obj_property_no_reverse_idx = TRUE ), + NML_DBUS_META_PROPERTY_INIT_AS ("Searches", PROP_SEARCHES, NMIPConfigPrivate, searches ), + ), + .base_struct_offset = G_STRUCT_OFFSET (NMIPConfig, _priv), +); + static void nm_ip_config_class_init (NMIPConfigClass *config_class) { GObjectClass *object_class = G_OBJECT_CLASS (config_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class); g_type_class_add_private (config_class, sizeof (NMIPConfigPrivate)); - /* virtual methods */ object_class->get_property = get_property; - object_class->finalize = finalize; - - nm_object_class->init_dbus = init_dbus; - - /* properties */ + object_class->finalize = finalize; /** * NMIPConfig:family: @@ -272,84 +369,77 @@ nm_ip_config_class_init (NMIPConfigClass *config_class) * The IP address family of the configuration; either * <literal>AF_INET</literal> or <literal>AF_INET6</literal>. **/ - g_object_class_install_property - (object_class, PROP_FAMILY, - g_param_spec_int (NM_IP_CONFIG_FAMILY, "", "", - 0, 255, AF_UNSPEC, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_FAMILY] = + g_param_spec_int (NM_IP_CONFIG_FAMILY, "", "", + 0, 255, AF_UNSPEC, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMIPConfig:gateway: * * The IP gateway address of the configuration as string. **/ - g_object_class_install_property - (object_class, PROP_GATEWAY, - g_param_spec_string (NM_IP_CONFIG_GATEWAY, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_GATEWAY] = + g_param_spec_string (NM_IP_CONFIG_GATEWAY, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMIPConfig:addresses: * * A #GPtrArray containing the addresses (#NMIPAddress) of the configuration. **/ - g_object_class_install_property - (object_class, PROP_ADDRESSES, - g_param_spec_boxed (NM_IP_CONFIG_ADDRESSES, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ADDRESSES] = + g_param_spec_boxed (NM_IP_CONFIG_ADDRESSES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMIPConfig:routes: (type GPtrArray(NMIPRoute)) * * A #GPtrArray containing the routes (#NMIPRoute) of the configuration. **/ - g_object_class_install_property - (object_class, PROP_ROUTES, - g_param_spec_boxed (NM_IP_CONFIG_ROUTES, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_ROUTES] = + g_param_spec_boxed (NM_IP_CONFIG_ROUTES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMIPConfig:nameservers: * * The array containing name server IP addresses of the configuration. **/ - g_object_class_install_property - (object_class, PROP_NAMESERVERS, - g_param_spec_boxed (NM_IP_CONFIG_NAMESERVERS, "", "", - G_TYPE_STRV, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_NAMESERVERS] = + g_param_spec_boxed (NM_IP_CONFIG_NAMESERVERS, "", "", + G_TYPE_STRV, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMIPConfig:domains: * * The array containing domain strings of the configuration. **/ - g_object_class_install_property - (object_class, PROP_DOMAINS, - g_param_spec_boxed (NM_IP_CONFIG_DOMAINS, "", "", - G_TYPE_STRV, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DOMAINS] = + g_param_spec_boxed (NM_IP_CONFIG_DOMAINS, "", "", + G_TYPE_STRV, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMIPConfig:searches: * * The array containing DNS search strings of the configuration. **/ - g_object_class_install_property - (object_class, PROP_SEARCHES, - g_param_spec_boxed (NM_IP_CONFIG_SEARCHES, "", "", - G_TYPE_STRV, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_SEARCHES] = + g_param_spec_boxed (NM_IP_CONFIG_SEARCHES, "", "", + G_TYPE_STRV, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMIPConfig:wins-servers: @@ -357,12 +447,14 @@ nm_ip_config_class_init (NMIPConfigClass *config_class) * The array containing WINS server IP addresses of the configuration. * (This will always be empty for IPv6 configurations.) **/ - g_object_class_install_property - (object_class, PROP_WINS_SERVERS, - g_param_spec_boxed (NM_IP_CONFIG_WINS_SERVERS, "", "", - G_TYPE_STRV, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_WINS_SERVERS] = + g_param_spec_boxed (NM_IP_CONFIG_WINS_SERVERS, "", "", + G_TYPE_STRV, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_ip4config, + &_nml_dbus_meta_iface_nm_ip6config); } /** @@ -395,7 +487,7 @@ nm_ip_config_get_gateway (NMIPConfig *config) { g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL); - return nm_str_not_empty (NM_IP_CONFIG_GET_PRIVATE (config)->gateway); + return _nml_coerce_property_str_not_empty (NM_IP_CONFIG_GET_PRIVATE (config)->gateway); } /** @@ -425,12 +517,12 @@ nm_ip_config_get_addresses (NMIPConfig *config) * * Returns: (transfer none): the array of nameserver IP addresses **/ -const char * const * +const char *const* nm_ip_config_get_nameservers (NMIPConfig *config) { g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL); - return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->nameservers; + return _nml_coerce_property_strv_not_null (NM_IP_CONFIG_GET_PRIVATE (config)->nameservers); } /** @@ -442,12 +534,12 @@ nm_ip_config_get_nameservers (NMIPConfig *config) * Returns: (transfer none): the array of domains. * (This is never %NULL, though it may be 0-length). **/ -const char * const * +const char *const* nm_ip_config_get_domains (NMIPConfig *config) { g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL); - return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->domains; + return _nml_coerce_property_strv_not_null (NM_IP_CONFIG_GET_PRIVATE (config)->domains); } /** @@ -459,12 +551,12 @@ nm_ip_config_get_domains (NMIPConfig *config) * Returns: (transfer none): the array of DNS search strings. * (This is never %NULL, though it may be 0-length). **/ -const char * const * +const char *const* nm_ip_config_get_searches (NMIPConfig *config) { g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL); - return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->searches; + return _nml_coerce_property_strv_not_null (NM_IP_CONFIG_GET_PRIVATE (config)->searches); } /** @@ -476,12 +568,12 @@ nm_ip_config_get_searches (NMIPConfig *config) * Returns: (transfer none): the arry of WINS server IP address strings. * (This is never %NULL, though it may be 0-length.) **/ -const char * const * +const char *const* nm_ip_config_get_wins_servers (NMIPConfig *config) { g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL); - return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->wins; + return _nml_coerce_property_strv_not_null (NM_IP_CONFIG_GET_PRIVATE (config)->wins_servers); } /** diff --git a/libnm/nm-ip-config.h b/libnm/nm-ip-config.h index c9a44cfb..56beb1aa 100644 --- a/libnm/nm-ip-config.h +++ b/libnm/nm-ip-config.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2008 - 2014 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2008 - 2014 Red Hat, Inc. */ #ifndef __NM_IP_CONFIG_H__ @@ -39,16 +25,7 @@ G_BEGIN_DECLS /** * NMIPConfig: */ -struct _NMIPConfig { - NMObject parent; -}; - -typedef struct { - NMObjectClass parent; - - /*< private >*/ - gpointer padding[8]; -} NMIPConfigClass; +typedef struct _NMIPConfigClass NMIPConfigClass; #define NM_IP_CONFIG_FAMILY "family" #define NM_IP_CONFIG_GATEWAY "gateway" diff --git a/libnm/nm-ip4-config.c b/libnm/nm-ip4-config.c index 1f199c4b..259c20b0 100644 --- a/libnm/nm-ip4-config.c +++ b/libnm/nm-ip4-config.c @@ -1,30 +1,26 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2014 Red Hat, Inc. + * Copyright (C) 2014 Red Hat, Inc. */ #include "nm-default.h" #include "nm-ip4-config.h" -#include "nm-object-private.h" +/*****************************************************************************/ + +struct _NMIP4Config { + NMIPConfig parent; +}; + +struct _NMIP4ConfigClass{ + NMIPConfigClass parent; +}; G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_IP_CONFIG) +/*****************************************************************************/ + static void nm_ip4_config_init (NMIP4Config *config) { diff --git a/libnm/nm-ip4-config.h b/libnm/nm-ip4-config.h index 046472f6..3f6a40bb 100644 --- a/libnm/nm-ip4-config.h +++ b/libnm/nm-ip4-config.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2008 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2008 Red Hat, Inc. */ #ifndef __NM_IP4_CONFIG_H__ @@ -37,13 +23,8 @@ /** * NMIP4Config: */ -typedef struct { - NMIPConfig parent; -} NMIP4Config; - -typedef struct { - NMIPConfigClass parent; -} NMIP4ConfigClass; +typedef struct _NMIP4Config NMIP4Config; +typedef struct _NMIP4ConfigClass NMIP4ConfigClass; GType nm_ip4_config_get_type (void); diff --git a/libnm/nm-ip6-config.c b/libnm/nm-ip6-config.c index af32fdab..9a059edb 100644 --- a/libnm/nm-ip6-config.c +++ b/libnm/nm-ip6-config.c @@ -1,30 +1,26 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2014 Red Hat, Inc. + * Copyright (C) 2014 Red Hat, Inc. */ #include "nm-default.h" #include "nm-ip6-config.h" -#include "nm-object-private.h" +/*****************************************************************************/ + +struct _NMIP6Config { + NMIPConfig parent; +}; + +struct _NMIP6ConfigClass{ + NMIPConfigClass parent; +}; G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_IP_CONFIG) +/*****************************************************************************/ + static void nm_ip6_config_init (NMIP6Config *config) { diff --git a/libnm/nm-ip6-config.h b/libnm/nm-ip6-config.h index 686eaa33..33c65c89 100644 --- a/libnm/nm-ip6-config.h +++ b/libnm/nm-ip6-config.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2008 - 2014 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2008 - 2014 Red Hat, Inc. */ #ifndef __NM_IP6_CONFIG_H__ @@ -37,13 +23,8 @@ /** * NMIP6Config: */ -typedef struct { - NMIPConfig parent; -} NMIP6Config; - -typedef struct { - NMIPConfigClass parent; -} NMIP6ConfigClass; +typedef struct _NMIP6Config NMIP6Config; +typedef struct _NMIP6ConfigClass NMIP6ConfigClass; GType nm_ip6_config_get_type (void); diff --git a/libnm/nm-libnm-utils.c b/libnm/nm-libnm-utils.c index 5515b3d0..73de75e3 100644 --- a/libnm/nm-libnm-utils.c +++ b/libnm/nm-libnm-utils.c @@ -1,27 +1,127 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2018 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2018 Red Hat, Inc. */ #include "nm-default.h" #include "nm-libnm-utils.h" +#include "nm-glib-aux/nm-time-utils.h" +#include "nm-libnm-core-intern/nm-common-macros.h" +#include "nm-object.h" + +/*****************************************************************************/ + +volatile int _nml_dbus_log_level = 0; + +int +_nml_dbus_log_level_init (void) +{ + const GDebugKey keys[] = { + { "trace", _NML_DBUS_LOG_LEVEL_TRACE }, + { "debug", _NML_DBUS_LOG_LEVEL_DEBUG }, + { "warning", _NML_DBUS_LOG_LEVEL_WARN }, + { "error", _NML_DBUS_LOG_LEVEL_ERROR }, + }; + int l; + + l = _NML_DBUS_LOG_LEVEL_INITIALIZED + | nm_utils_parse_debug_string (g_getenv ("LIBNM_CLIENT_DEBUG"), + keys, + G_N_ELEMENTS (keys)); + + if (!g_atomic_int_compare_and_exchange (&_nml_dbus_log_level, 0, l)) + l = g_atomic_int_get (&_nml_dbus_log_level); + + nm_assert (l & _NML_DBUS_LOG_LEVEL_INITIALIZED); + return l; +} + +void +_nml_dbus_log (NMLDBusLogLevel level, + const char *fmt, + ...) { + NMLDBusLogLevel configured_log_level; + gs_free char *msg = NULL; + va_list args; + const char *prefix = ""; + gint64 ts; + + /* we only call _nml_dbus_log() after nml_dbus_log_enabled(), which already does + * an atomic access to the variable. Since the value is only initialized once and + * never changes, we can just access it without additional locking. */ + configured_log_level = _nml_dbus_log_level; + + nm_assert (level & configured_log_level); + + va_start (args, fmt); + msg = g_strdup_vprintf (fmt, args); + va_end (args); + + switch (level) { + case NML_DBUS_LOG_LEVEL_TRACE: + prefix = "<trace> "; + break; + case NML_DBUS_LOG_LEVEL_DEBUG: + prefix = "<debug> "; + break; + case NML_DBUS_LOG_LEVEL_WARN: + prefix = "<warn > "; + if (NM_FLAGS_HAS (configured_log_level, _NML_DBUS_LOG_LEVEL_WARN)) { + g_warning ("libnm-dbus: %s%s", prefix, msg); + return; + } + break; + case NML_DBUS_LOG_LEVEL_ERROR: + prefix = "<error> "; + if (NM_FLAGS_HAS (configured_log_level, _NML_DBUS_LOG_LEVEL_ERROR)) { + g_critical ("libnm-dbus: %s%s", prefix, msg); + return; + } + if (NM_FLAGS_HAS (configured_log_level, _NML_DBUS_LOG_LEVEL_WARN)) { + g_warning ("libnm-dbus: %s%s", prefix, msg); + return; + } + break; + default: + break; + } + + ts = nm_utils_clock_gettime_ns (CLOCK_BOOTTIME); + + g_printerr ("libnm-dbus: %s[%"G_GINT64_FORMAT".%05"G_GINT64_FORMAT"] %s\n", + prefix, + ts / NM_UTILS_NS_PER_SECOND, + (ts / (NM_UTILS_NS_PER_SECOND / 10000)) % 10000, + msg); +} + +/*****************************************************************************/ + +/* Stolen from dbus-glib */ +char * +nm_utils_wincaps_to_dash (const char *caps) +{ + const char *p; + GString *str; + + str = g_string_new (NULL); + p = caps; + while (*p) { + if (g_ascii_isupper (*p)) { + if (str->len > 0 && (str->len < 2 || str->str[str->len-2] != '-')) + g_string_append_c (str, '-'); + g_string_append_c (str, g_ascii_tolower (*p)); + } else + g_string_append_c (str, *p); + ++p; + } + + return g_string_free (str, FALSE); +} + /*****************************************************************************/ static char * @@ -560,3 +660,287 @@ nm_utils_fixup_product_string (const char *desc) return desc_full; } + +/*****************************************************************************/ + +NMClientPermission +nm_permission_to_client (const char *nm) +{ + static const struct { + const char *name; + NMClientPermission perm; + } list[] = { + { NM_AUTH_PERMISSION_CHECKPOINT_ROLLBACK, NM_CLIENT_PERMISSION_CHECKPOINT_ROLLBACK }, + { NM_AUTH_PERMISSION_ENABLE_DISABLE_CONNECTIVITY_CHECK, NM_CLIENT_PERMISSION_ENABLE_DISABLE_CONNECTIVITY_CHECK }, + { NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK, NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK }, + { NM_AUTH_PERMISSION_ENABLE_DISABLE_STATISTICS, NM_CLIENT_PERMISSION_ENABLE_DISABLE_STATISTICS }, + { NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI, NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI }, + { NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX, NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX }, + { NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN, NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN }, + { NM_AUTH_PERMISSION_NETWORK_CONTROL, NM_CLIENT_PERMISSION_NETWORK_CONTROL }, + { NM_AUTH_PERMISSION_RELOAD, NM_CLIENT_PERMISSION_RELOAD }, + { NM_AUTH_PERMISSION_SETTINGS_MODIFY_GLOBAL_DNS, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_GLOBAL_DNS }, + { NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME }, + { NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN }, + { NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM }, + { NM_AUTH_PERMISSION_SLEEP_WAKE, NM_CLIENT_PERMISSION_SLEEP_WAKE }, + { NM_AUTH_PERMISSION_WIFI_SCAN, NM_CLIENT_PERMISSION_WIFI_SCAN }, + { NM_AUTH_PERMISSION_WIFI_SHARE_OPEN, NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN }, + { NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED, NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED }, + }; + gssize idx; + +#if NM_MORE_ASSERTS > 10 + { + static gboolean checked = FALSE; + int i, j; + + if (!checked) { + checked = TRUE; + + for (i = 0; i < G_N_ELEMENTS (list); i++) { + + nm_assert (list[i].perm != NM_CLIENT_PERMISSION_NONE); + nm_assert (list[i].name && list[i].name[0]); + if (i > 0) { + if (strcmp (list[i - 1].name, list[i].name) >= 0) { + g_error ("list is not sorted by name: #%d (%s) should be after #%d (%s)", + i - 1, list[i - 1].name, i, list[i].name); + } + } + for (j = i + 1; j < G_N_ELEMENTS (list); j++) { + nm_assert (list[i].perm != list[j].perm); + } + } + } + } +#endif + + if (nm) { + idx = nm_utils_array_find_binary_search (list, + sizeof (list[0]), + G_N_ELEMENTS (list), + &nm, + nm_strcmp_p_with_data, + NULL); + if (idx >= 0) + return list[idx].perm; + } + return NM_CLIENT_PERMISSION_NONE; +} + +NMClientPermissionResult +nm_permission_result_to_client (const char *nm) +{ + if (!nm) + return NM_CLIENT_PERMISSION_RESULT_UNKNOWN; + if (nm_streq (nm, "yes")) + return NM_CLIENT_PERMISSION_RESULT_YES; + if (nm_streq (nm, "no")) + return NM_CLIENT_PERMISSION_RESULT_NO; + if (nm_streq (nm, "auth")) + return NM_CLIENT_PERMISSION_RESULT_AUTH; + return NM_CLIENT_PERMISSION_RESULT_UNKNOWN; +} + +/*****************************************************************************/ + +const NMLDBusMetaIface *const _nml_dbus_meta_ifaces[] = { + &_nml_dbus_meta_iface_nm, + &_nml_dbus_meta_iface_nm_accesspoint, + &_nml_dbus_meta_iface_nm_agentmanager, + &_nml_dbus_meta_iface_nm_checkpoint, + &_nml_dbus_meta_iface_nm_connection_active, + &_nml_dbus_meta_iface_nm_dhcp4config, + &_nml_dbus_meta_iface_nm_dhcp6config, + &_nml_dbus_meta_iface_nm_device, + &_nml_dbus_meta_iface_nm_device_adsl, + &_nml_dbus_meta_iface_nm_device_bluetooth, + &_nml_dbus_meta_iface_nm_device_bond, + &_nml_dbus_meta_iface_nm_device_bridge, + &_nml_dbus_meta_iface_nm_device_dummy, + &_nml_dbus_meta_iface_nm_device_generic, + &_nml_dbus_meta_iface_nm_device_iptunnel, + &_nml_dbus_meta_iface_nm_device_infiniband, + &_nml_dbus_meta_iface_nm_device_lowpan, + &_nml_dbus_meta_iface_nm_device_macsec, + &_nml_dbus_meta_iface_nm_device_macvlan, + &_nml_dbus_meta_iface_nm_device_modem, + &_nml_dbus_meta_iface_nm_device_olpcmesh, + &_nml_dbus_meta_iface_nm_device_ovsbridge, + &_nml_dbus_meta_iface_nm_device_ovsinterface, + &_nml_dbus_meta_iface_nm_device_ovsport, + &_nml_dbus_meta_iface_nm_device_ppp, + &_nml_dbus_meta_iface_nm_device_statistics, + &_nml_dbus_meta_iface_nm_device_team, + &_nml_dbus_meta_iface_nm_device_tun, + &_nml_dbus_meta_iface_nm_device_veth, + &_nml_dbus_meta_iface_nm_device_vlan, + &_nml_dbus_meta_iface_nm_device_vxlan, + &_nml_dbus_meta_iface_nm_device_wifip2p, + &_nml_dbus_meta_iface_nm_device_wireguard, + &_nml_dbus_meta_iface_nm_device_wired, + &_nml_dbus_meta_iface_nm_device_wireless, + &_nml_dbus_meta_iface_nm_device_wpan, + &_nml_dbus_meta_iface_nm_dnsmanager, + &_nml_dbus_meta_iface_nm_ip4config, + &_nml_dbus_meta_iface_nm_ip6config, + &_nml_dbus_meta_iface_nm_settings, + &_nml_dbus_meta_iface_nm_settings_connection, + &_nml_dbus_meta_iface_nm_vpn_connection, + &_nml_dbus_meta_iface_nm_wifip2ppeer, +}; + +#define COMMON_PREFIX "org.freedesktop.NetworkManager" + +static int +_strcmp_common_prefix (gconstpointer a, gconstpointer b, gpointer user_data) +{ + const NMLDBusMetaIface *iface = a; + const char *dbus_iface_name = b; + + nm_assert (g_str_has_prefix (iface->dbus_iface_name, COMMON_PREFIX)); + + return strcmp (&iface->dbus_iface_name[NM_STRLEN (COMMON_PREFIX)], dbus_iface_name); +} + +const NMLDBusMetaIface * +nml_dbus_meta_iface_get (const char *dbus_iface_name) +{ + gssize idx; + + nm_assert (dbus_iface_name); + + G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (NMLDBusMetaIface, dbus_iface_name) == 0); + + /* we assume that NetworkManager only uses unique interface names. E.g. one + * interface name always has one particular meaning (and offers one set of + * properties, signals and methods). This is a convenient assumption, and + * we sure would never violate it when extending NM's D-Bus API. */ + + if (NM_STR_HAS_PREFIX (dbus_iface_name, COMMON_PREFIX)) { + /* optimize, that in fact all our interfaces have the same prefix. */ + idx = nm_utils_ptrarray_find_binary_search ((gconstpointer *) _nml_dbus_meta_ifaces, + G_N_ELEMENTS (_nml_dbus_meta_ifaces), + &dbus_iface_name[NM_STRLEN (COMMON_PREFIX)], + _strcmp_common_prefix, + NULL, + NULL, + NULL); + } else + return NULL; + + if (idx < 0) + return NULL; + return _nml_dbus_meta_ifaces[idx]; +} + +const NMLDBusMetaProperty * +nml_dbus_meta_property_get (const NMLDBusMetaIface *meta_iface, + const char *dbus_property_name, + guint *out_idx) +{ + gssize idx; + + nm_assert (meta_iface); + nm_assert (dbus_property_name); + + idx = nm_utils_array_find_binary_search (meta_iface->dbus_properties, + sizeof (meta_iface->dbus_properties[0]), + meta_iface->n_dbus_properties, + &dbus_property_name, + nm_strcmp_p_with_data, + NULL); + if (idx < 0) { + NM_SET_OUT (out_idx, meta_iface->n_dbus_properties); + return NULL; + } + NM_SET_OUT (out_idx, idx); + return &meta_iface->dbus_properties[idx]; +} + +void +_nml_dbus_meta_class_init_with_properties_impl (GObjectClass *object_class, + const NMLDBusMetaIface *const*meta_ifaces) +{ + int i_iface; + + nm_assert (G_IS_OBJECT_CLASS (object_class)); + nm_assert (meta_ifaces); + nm_assert (meta_ifaces[0]); + + for (i_iface = 0; meta_ifaces[i_iface]; i_iface++) { + const NMLDBusMetaIface *meta_iface = meta_ifaces[i_iface]; + guint8 *reverse_idx; + guint8 i; + + nm_assert (g_type_is_a (meta_iface->get_type_fcn (), G_OBJECT_CLASS_TYPE (object_class))); + nm_assert (meta_iface->n_obj_properties > 0); + nm_assert (meta_iface->obj_properties); + nm_assert (meta_iface->obj_properties_reverse_idx[0] == 0); + nm_assert (meta_iface->obj_properties == meta_ifaces[0]->obj_properties); + + if (i_iface == 0) + g_object_class_install_properties (object_class, meta_iface->n_obj_properties, (GParamSpec **) meta_iface->obj_properties); + + reverse_idx = (guint8 *) meta_iface->obj_properties_reverse_idx; + + for (i = 0; i < meta_iface->n_obj_properties; i++) + reverse_idx[i] = 0xFFu; + for (i = 0; i < meta_iface->n_dbus_properties; i++) { + const NMLDBusMetaProperty *mpr = &meta_iface->dbus_properties[i]; + + if ( mpr->obj_properties_idx != 0 + && !mpr->obj_property_no_reverse_idx) { + nm_assert (mpr->obj_properties_idx < meta_iface->n_obj_properties); + nm_assert (reverse_idx[mpr->obj_properties_idx] == 0xFFu); + + reverse_idx[mpr->obj_properties_idx] = i; + } + } + } +} + +gboolean +nm_utils_g_param_spec_is_default (const GParamSpec *pspec) +{ + g_return_val_if_fail (pspec, FALSE); + + if (pspec->value_type == G_TYPE_BOOLEAN) + return ((((GParamSpecBoolean *) pspec)->default_value) == FALSE); + if (pspec->value_type == G_TYPE_UCHAR) + return ((((GParamSpecUChar *) pspec)->default_value) == 0u); + if (pspec->value_type == G_TYPE_INT) + return ((((GParamSpecInt *) pspec)->default_value) == 0); + if (pspec->value_type == G_TYPE_UINT) + return ((((GParamSpecUInt *) pspec)->default_value) == 0u); + if (pspec->value_type == G_TYPE_INT64) + return ((((GParamSpecInt64 *) pspec)->default_value) == 0); + if (pspec->value_type == G_TYPE_UINT64) + return ((((GParamSpecUInt64 *) pspec)->default_value) == 0u); + if (g_type_is_a (pspec->value_type, G_TYPE_ENUM)) + return ((((GParamSpecEnum *) pspec)->default_value) == 0); + if (g_type_is_a (pspec->value_type, G_TYPE_FLAGS)) + return ((((GParamSpecFlags *) pspec)->default_value) == 0u); + if (pspec->value_type == G_TYPE_STRING) + return ((((GParamSpecString *) pspec)->default_value) == NULL); + if (NM_IN_SET (pspec->value_type, G_TYPE_BYTES, + G_TYPE_PTR_ARRAY, + G_TYPE_HASH_TABLE, + G_TYPE_STRV)) { + /* boxed types have NULL default. */ + g_return_val_if_fail (G_IS_PARAM_SPEC_BOXED (pspec), FALSE); + g_return_val_if_fail (G_TYPE_IS_BOXED (pspec->value_type), FALSE); + return TRUE; + } + if (g_type_is_a (pspec->value_type, NM_TYPE_OBJECT)) { + /* object types have NULL default. */ + g_return_val_if_fail (G_IS_PARAM_SPEC_OBJECT (pspec), FALSE); + g_return_val_if_fail (G_TYPE_IS_OBJECT (pspec->value_type), FALSE); + return TRUE; + } + + /* This function is only used for asserting/testing. It thus + * strictly asserts and only support argument types that we expect. */ + g_return_val_if_reached (FALSE); +} diff --git a/libnm/nm-libnm-utils.h b/libnm/nm-libnm-utils.h index e1d03d40..8ac05d70 100644 --- a/libnm/nm-libnm-utils.h +++ b/libnm/nm-libnm-utils.h @@ -1,30 +1,962 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2017, 2018 Red Hat, Inc. + * Copyright (C) 2017, 2018 Red Hat, Inc. */ #ifndef __NM_LIBNM_UTILS_H__ #define __NM_LIBNM_UTILS_H__ -#if !((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE) -#error Cannot use this header. -#endif +#include "c-list/src/c-list.h" +#include "nm-glib-aux/nm-ref-string.h" +#include "nm-glib-aux/nm-logging-fwd.h" +#include "nm-types.h" +#include "nm-object.h" +#include "nm-client.h" + +/*****************************************************************************/ + +/* Markers for deprecated sync code in internal API. */ +#define _NM_DEPRECATED_SYNC_METHOD_INTERNAL NM_DEPRECATED_IN_1_22 +#define _NM_DEPRECATED_SYNC_WRITABLE_PROPERTY_INTERNAL NM_DEPRECATED_IN_1_22 + +/*****************************************************************************/ char *nm_utils_fixup_vendor_string (const char *desc); char *nm_utils_fixup_product_string (const char *desc); +char *nm_utils_wincaps_to_dash (const char *caps); + +gboolean nm_utils_g_param_spec_is_default (const GParamSpec *pspec); + +/*****************************************************************************/ + +NMClientPermission nm_permission_to_client (const char *nm); + +NMClientPermissionResult nm_permission_result_to_client (const char *nm); + +/*****************************************************************************/ + +typedef enum { + _NML_DBUS_LOG_LEVEL_INITIALIZED = 0x01, + + _NML_DBUS_LOG_LEVEL_TRACE = 0x02, + + _NML_DBUS_LOG_LEVEL_DEBUG = 0x04, + + /* the difference between a warning and a critical is that it results in + * g_warning() vs. g_critical() messages. Note that we want to use "warnings" + * for unknown D-Bus API that could just result because we run against a + * newer NetworkManager version (such warnings are more graceful, because + * we want that libnm can be forward compatible against newer servers). + * Critial warnings should be emitted when NetworkManager exposes something + * on D-Bus that breaks the current expectations. Usually NetworkManager + * should not break API, hence such issues are more severe. */ + _NML_DBUS_LOG_LEVEL_WARN = 0x08, + _NML_DBUS_LOG_LEVEL_ERROR = 0x10, + + /* ANY is only relevant for nml_dbus_log_enabled() to check whether any of the + * options is on. */ + NML_DBUS_LOG_LEVEL_ANY = _NML_DBUS_LOG_LEVEL_INITIALIZED, + + NML_DBUS_LOG_LEVEL_TRACE = _NML_DBUS_LOG_LEVEL_TRACE, + NML_DBUS_LOG_LEVEL_DEBUG = _NML_DBUS_LOG_LEVEL_DEBUG + | NML_DBUS_LOG_LEVEL_TRACE, + NML_DBUS_LOG_LEVEL_WARN = _NML_DBUS_LOG_LEVEL_WARN + | NML_DBUS_LOG_LEVEL_DEBUG, + NML_DBUS_LOG_LEVEL_ERROR = _NML_DBUS_LOG_LEVEL_ERROR + | NML_DBUS_LOG_LEVEL_WARN, +} NMLDBusLogLevel; + +#undef _LOGL_TRACE +#undef _LOGL_DEBUG +#undef _LOGL_INFO +#undef _LOGL_WARN +#undef _LOGL_ERR + +#define _LOGL_TRACE NML_DBUS_LOG_LEVEL_TRACE +#define _LOGL_DEBUG NML_DBUS_LOG_LEVEL_DEBUG +#define _LOGL_INFO NML_DBUS_LOG_LEVEL_INFO +#define _LOGL_WARN NML_DBUS_LOG_LEVEL_WARN +#define _LOGL_ERR NML_DBUS_LOG_LEVEL_ERR + +extern volatile int _nml_dbus_log_level; + +int _nml_dbus_log_level_init (void); + +static inline gboolean +nml_dbus_log_enabled (NMLDBusLogLevel level) +{ + int l; + + nm_assert (NM_IN_SET (level, NML_DBUS_LOG_LEVEL_ANY, + NML_DBUS_LOG_LEVEL_TRACE, + NML_DBUS_LOG_LEVEL_DEBUG, + NML_DBUS_LOG_LEVEL_WARN, + NML_DBUS_LOG_LEVEL_ERROR)); + + l = g_atomic_int_get (&_nml_dbus_log_level); + if (G_UNLIKELY (l == 0)) + l = _nml_dbus_log_level_init (); + + nm_assert (l & _NML_DBUS_LOG_LEVEL_INITIALIZED); + if (level == NML_DBUS_LOG_LEVEL_ANY) + return l != _NML_DBUS_LOG_LEVEL_INITIALIZED; + return !!(((NMLDBusLogLevel) l) & level); +} + +void _nml_dbus_log (NMLDBusLogLevel level, + const char *fmt, + ...) _nm_printf (2, 3); + +#define NML_DBUS_LOG(level, ...) \ + G_STMT_START { \ + G_STATIC_ASSERT ( (level) == NML_DBUS_LOG_LEVEL_TRACE \ + || (level) == NML_DBUS_LOG_LEVEL_DEBUG \ + || (level) == NML_DBUS_LOG_LEVEL_WARN \ + || (level) == NML_DBUS_LOG_LEVEL_ERROR); \ + \ + if (nml_dbus_log_enabled (level)) { \ + _nml_dbus_log ((level), __VA_ARGS__); \ + } \ + } G_STMT_END + +#define NML_DBUS_LOG_T(...) NML_DBUS_LOG (NML_DBUS_LOG_LEVEL_TRACE, __VA_ARGS__) +#define NML_DBUS_LOG_D(...) NML_DBUS_LOG (NML_DBUS_LOG_LEVEL_DEBUG, __VA_ARGS__) +#define NML_DBUS_LOG_W(...) NML_DBUS_LOG (NML_DBUS_LOG_LEVEL_WARN, __VA_ARGS__) +#define NML_DBUS_LOG_E(...) NML_DBUS_LOG (NML_DBUS_LOG_LEVEL_ERROR, __VA_ARGS__) + +#define NML_NMCLIENT_LOG(level, self, ...) \ + NML_DBUS_LOG ((level), \ + "nmclient["NM_HASH_OBFUSCATE_PTR_FMT"]: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ + NM_HASH_OBFUSCATE_PTR (self) \ + _NM_UTILS_MACRO_REST (__VA_ARGS__)) + +#define NML_NMCLIENT_LOG_T(self, ...) NML_NMCLIENT_LOG (NML_DBUS_LOG_LEVEL_TRACE, self, __VA_ARGS__) +#define NML_NMCLIENT_LOG_D(self, ...) NML_NMCLIENT_LOG (NML_DBUS_LOG_LEVEL_DEBUG, self, __VA_ARGS__) +#define NML_NMCLIENT_LOG_W(self, ...) NML_NMCLIENT_LOG (NML_DBUS_LOG_LEVEL_WARN, self, __VA_ARGS__) +#define NML_NMCLIENT_LOG_E(self, ...) NML_NMCLIENT_LOG (NML_DBUS_LOG_LEVEL_ERROR, self, __VA_ARGS__) + +/*****************************************************************************/ + +static inline const char * +_nml_coerce_property_str_not_null (const char *str) +{ + return str ?: ""; +} + +static inline const char * +_nml_coerce_property_str_not_empty (const char *str) +{ + return str && str[0] ? str : NULL; +} + +static inline const char * +_nml_coerce_property_object_path (NMRefString *path) +{ + if (!path) + return NULL; + return nm_dbus_path_not_empty (path->str); +} + +static inline const char *const* +_nml_coerce_property_strv_not_null (char **strv) +{ + return ((const char *const*) strv) ?: NM_PTRARRAY_EMPTY (const char *); +} + +/*****************************************************************************/ + +typedef struct _NMLDBusObject NMLDBusObject; +typedef struct _NMLDBusObjWatcher NMLDBusObjWatcher; +typedef struct _NMLDBusMetaIface NMLDBusMetaIface; +typedef struct _NMLDBusPropertyO NMLDBusPropertyO; +typedef struct _NMLDBusPropertyAO NMLDBusPropertyAO; + +typedef enum { + /* See comments below for NMLDBusMetaIface.interface_prio. + * + * Higher numbers means more important to detect the GObject type. */ + NML_DBUS_META_INTERFACE_PRIO_NONE = 0, + NML_DBUS_META_INTERFACE_PRIO_NMCLIENT = 1, + NML_DBUS_META_INTERFACE_PRIO_PARENT_TYPE = 2, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW = 3, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH = 4, +} NMLDBusMetaInteracePrio; + +/*****************************************************************************/ + +typedef struct { + GType (*get_o_type_fcn) (void); + + /* Ignore whether the referenced NMObject is ready or not. That means, + * the property is always ready (and if the pointed object itself is + * not yet ready, the property pretends to be %NULL for the moment. */ + bool is_always_ready:1; + +} NMLDBusPropertVTableO; + +struct _NMLDBusPropertyO { + NMLDBusObject *owner_dbobj; + NMLDBusObjWatcher *obj_watcher; + GObject *nmobj; + const NMLDBusMetaIface *meta_iface; + guint dbus_property_idx; + bool is_ready:1; + bool is_changed:1; + bool block_is_changed:1; +}; + +gpointer nml_dbus_property_o_get_obj (NMLDBusPropertyO *pr_o); + +gboolean nml_dbus_property_o_is_ready (const NMLDBusPropertyO *pr_o); + +void nml_dbus_property_o_clear (NMLDBusPropertyO *pr_o, + NMClient *client); + +void nml_dbus_property_o_clear_many (NMLDBusPropertyO *pr_o, + guint len, + NMClient *self); + +void nml_dbus_property_o_notify_changed_many (NMLDBusPropertyO *ptr, + guint len, + NMClient *self); + +/*****************************************************************************/ + +typedef struct { + GType (*get_o_type_fcn) (void); + + void (*notify_changed_ao) (NMLDBusPropertyAO *pr_ao, + NMClient *self, + NMObject *nmobj, + gboolean is_added /* or else removed */); + + gboolean (*check_nmobj_visible_fcn) (GObject *nmobj); + + /* Ignore whether the referenced NMObject is ready or not. That means, + * the property is always ready (and if the pointed object itself is + * not yet ready, the property pretends to be %NULL for the moment. */ + bool is_always_ready:1; + +} NMLDBusPropertVTableAO; + +struct _NMLDBusPropertyAOData; + +struct _NMLDBusPropertyAO { + CList data_lst_head; + GHashTable *hash; + NMLDBusObject *owner_dbobj; + const NMLDBusMetaIface *meta_iface; + GPtrArray *arr; + struct _NMLDBusPropertyAOData *changed_head; + guint dbus_property_idx; + guint n_not_ready; + bool is_changed:1; +}; + +const GPtrArray *nml_dbus_property_ao_get_objs_as_ptrarray (NMLDBusPropertyAO *pr_ao); + +gboolean nml_dbus_property_ao_is_ready (const NMLDBusPropertyAO *pr_ao); + +void nml_dbus_property_ao_clear (NMLDBusPropertyAO *pr_ao, + NMClient *client); + +void nml_dbus_property_ao_clear_many (NMLDBusPropertyAO *pr_ao, + guint len, + NMClient *self); + +void nml_dbus_property_ao_notify_changed_many (NMLDBusPropertyAO *ptr, + guint len, + NMClient *self); + +/*****************************************************************************/ + +typedef enum { + NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE = 0, + NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY = 0x1, +} NMLDBusNotifyUpdatePropFlags; + +NMLDBusNotifyUpdatePropFlags _nml_dbus_notify_update_prop_ignore (NMClient *client, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value); + +NMLDBusNotifyUpdatePropFlags _nml_dbus_notify_update_prop_o (NMClient *client, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value); + +typedef struct { + const char *dbus_property_name; + const GVariantType *dbus_type; + + guint16 prop_struct_offset; + + guint8 obj_properties_idx; + + bool use_notify_update_prop:1; + + bool obj_property_no_reverse_idx:1; + + union { + union { + const NMLDBusPropertVTableO *property_vtable_o; + const NMLDBusPropertVTableAO *property_vtable_ao; + } extra; + + NMLDBusNotifyUpdatePropFlags (*notify_update_prop) (NMClient *client, + NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + guint dbus_property_idx, + GVariant *value); + }; + +} NMLDBusMetaProperty; + +#define NML_DBUS_META_PROPERTY_INIT(v_dbus_property_name, \ + v_dbus_type, \ + v_obj_properties_idx, \ + ...) \ + { \ + .dbus_property_name = ""v_dbus_property_name"", \ + .dbus_type = NM_G_VARIANT_TYPE (""v_dbus_type""), \ + .obj_properties_idx = v_obj_properties_idx, \ + ##__VA_ARGS__ \ + } + +#define _NML_DBUS_META_PROPERTY_INIT_DEFAULT(v_dbus_type, \ + v_exp_type, \ + v_dbus_property_name, \ + v_obj_properties_idx, \ + v_container, \ + v_field) \ + NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \ + v_dbus_type, \ + v_obj_properties_idx, \ + .prop_struct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (v_exp_type, v_container, v_field)) + +#define NML_DBUS_META_PROPERTY_INIT_B(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("b", bool, __VA_ARGS__) +#define NML_DBUS_META_PROPERTY_INIT_Y(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("y", guint8, __VA_ARGS__) +#define NML_DBUS_META_PROPERTY_INIT_Q(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("q", guint16, __VA_ARGS__) +#define NML_DBUS_META_PROPERTY_INIT_I(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("i", gint32, __VA_ARGS__) +#define NML_DBUS_META_PROPERTY_INIT_U(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("u", guint32, __VA_ARGS__) +#define NML_DBUS_META_PROPERTY_INIT_X(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("x", gint64, __VA_ARGS__) +#define NML_DBUS_META_PROPERTY_INIT_T(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("t", guint64, __VA_ARGS__) +#define NML_DBUS_META_PROPERTY_INIT_S(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("s", char *, __VA_ARGS__) +#define NML_DBUS_META_PROPERTY_INIT_AS(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("as", char **, __VA_ARGS__) +#define NML_DBUS_META_PROPERTY_INIT_AY(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("ay", GBytes *, __VA_ARGS__) + +#define NML_DBUS_META_PROPERTY_INIT_O(v_dbus_property_name, \ + v_obj_properties_idx, \ + v_container, \ + v_field) \ + NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \ + "o", \ + v_obj_properties_idx, \ + .prop_struct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (NMRefString *, v_container, v_field), \ + .use_notify_update_prop = TRUE, \ + .notify_update_prop = _nml_dbus_notify_update_prop_o) + +#define NML_DBUS_META_PROPERTY_INIT_O_PROP(v_dbus_property_name, \ + v_obj_properties_idx, \ + v_container, \ + v_field, \ + v_get_o_type_fcn, \ + ...) \ + NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \ + "o", \ + v_obj_properties_idx, \ + .prop_struct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyO, v_container, v_field), \ + .extra.property_vtable_o = &((const NMLDBusPropertVTableO) { \ + .get_o_type_fcn = (v_get_o_type_fcn), \ + ##__VA_ARGS__ \ + })) + +#define NML_DBUS_META_PROPERTY_INIT_AO_PROP(v_dbus_property_name, \ + v_obj_properties_idx, \ + v_container, \ + v_field, \ + v_get_o_type_fcn, \ + ...) \ + NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \ + "ao", \ + v_obj_properties_idx, \ + .prop_struct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyAO, v_container, v_field), \ + .extra.property_vtable_ao = &((const NMLDBusPropertVTableAO) { \ + .get_o_type_fcn = (v_get_o_type_fcn), \ + ##__VA_ARGS__ \ + })) + +#define NML_DBUS_META_PROPERTY_INIT_FCN(v_dbus_property_name, \ + v_obj_properties_idx, \ + v_dbus_type, \ + v_notify_update_prop, \ + ...) \ + NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \ + v_dbus_type, \ + v_obj_properties_idx, \ + .use_notify_update_prop = TRUE, \ + .notify_update_prop = (v_notify_update_prop), \ + ##__VA_ARGS__) + +#define NML_DBUS_META_PROPERTY_INIT_IGNORE(v_dbus_property_name, \ + v_dbus_type) \ + NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \ + v_dbus_type, \ + 0, \ + .use_notify_update_prop = TRUE, \ + .notify_update_prop = _nml_dbus_notify_update_prop_ignore) + +/* "TODO" is like "IGNORE". The difference is that we don't plan to ever implement "IGNORE", but + * "TODO" is something we should add support for. */ +#define NML_DBUS_META_PROPERTY_INIT_TODO(...) \ + NML_DBUS_META_PROPERTY_INIT_IGNORE (__VA_ARGS__) + +struct _NMLDBusMetaIface { + const char *dbus_iface_name; + GType (*get_type_fcn) (void); + + /* Usually there is a one-to-one correspondence between the properties + * on D-Bus (dbus_properties) and the GObject properties (obj_properties). + * + * With: + * meta_iface->obj_properties[o_idx] (o_idx < n_obj_properties) + * &meta_iface->dbus_properties[d_idx] (d_idx < n_dbus_properties) + * it follows that + * assert (meta_iface->obj_properties_reverse_idx[o_idx] == d_idx) + * assert (meta_iface->dbus_properties[d_idx].obj_properties_idx == o_idx) + * if (and only if) two properties correspond. + */ + const GParamSpec *const*obj_properties; + const NMLDBusMetaProperty *dbus_properties; + const guint8 *obj_properties_reverse_idx; + + guint8 n_dbus_properties; + guint8 n_obj_properties; + + /* The offsets "prop_struct_offset" in NMLDBusMetaProperty are based on some base + * struct. If "base_struct_offset" is 0, then the base struct is the GObject pointer + * itself. + * If this is non-null, then we expect at that location a pointer to the offset. + * In this case we need to first find the base pointer via + * *((gpointer *) ((char *) nmobj + meta_iface->base_struct_offset)). + * + * This covers NMDeviceBridge._priv vs. NMDevice._priv. In the second case, + * _priv is a pointer that we first need to follow. + */ + guint8 base_struct_offset; + + /* We create the appropriate NMObject GType based on the D-Bus interfaces that + * are present. For example, if we see a "org.freedesktop.NetworkManager.Device.Bridge" + * interface, we create a NMDeviceBridge. Basically, if it looks like a certain + * object (based on the D-Bus interface), we assume it is. + * + * Some interfaces are purely additional ("org.freedesktop.NetworkManager.Device.Statistics") + * and don't determine the NMObject type (%NML_DBUS_META_INTERFACE_PRIO_NONE). + * + * Some interfaces are of a parent type ("org.freedesktop.NetworkManager.Device" for + * NMDevice), and don't determine the type either (%NML_DBUS_META_INTERFACE_PRIO_PARENT_TYPE). + * + * Some interfaces ("org.freedesktop.NetworkManager.AgentManager") belong to NMClient + * itself. Those have priority %NML_DBUS_META_INTERFACE_PRIO_NMCLIENT. + * + * In most cases, each D-Bus object is expected to have only one D-Bus interface + * to determine the type. While theoretically an object + * "/org/freedesktop/NetworkManager/Devices/3" could have interfaces "org.freedesktop.NetworkManager.Device.Bridge" + * and "org.freedesktop.NetworkManager.Device.Bond" at the same time, in practice it doesn't. + * Note that we also assume that once a D-Bus object gets a NMObject, it cannot change (*). + * NetworkManager's API does not add/remove interfaces after exporting the object the + * first time, so in practice each D-Bus object is expected to have a suitable D-Bus + * interface (and only determining interface, which doesn't change). Those interfaces have + * priority %NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH. + * + * (*) note that nothing bad would happen if a faulty NetworkManager would violate that. + * Of course, something would not work correctly, but the D-Bus interface we find is unexpected + * and wrong. + * + * One exception is "org.freedesktop.NetworkManager.Connection.Active". This can either + * be a NMActiveConnection or a NMVpnConnection. Hence, this profile has priority + * %NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW, and depending on whether there is + * a "org.freedesktop.NetworkManager.VPN.Connection" (with high priority), we create + * one or the other type. + */ + NMLDBusMetaInteracePrio interface_prio:3; +}; + +#define NML_DBUS_META_IFACE_OBJ_PROPERTIES() \ + .obj_properties = (const GParamSpec *const*) (obj_properties), \ + .n_obj_properties = _PROPERTY_ENUMS_LAST, \ + .obj_properties_reverse_idx = ((guint8 [_PROPERTY_ENUMS_LAST]) { }) + +#define NML_DBUS_META_IFACE_DBUS_PROPERTIES(...) \ + .dbus_properties = ((const NMLDBusMetaProperty []) { __VA_ARGS__ }), \ + .n_dbus_properties = sizeof ((const NMLDBusMetaProperty []) { __VA_ARGS__ }) / sizeof (NMLDBusMetaProperty) \ + +#define NML_DBUS_META_IFACE_INIT(v_dbus_iface_name, \ + v_get_type_fcn, \ + v_interface_prio, \ + ...) \ + { \ + .dbus_iface_name = ""v_dbus_iface_name"", \ + .get_type_fcn = v_get_type_fcn, \ + .interface_prio = v_interface_prio, \ + ##__VA_ARGS__ \ + } + +#define NML_DBUS_META_IFACE_INIT_PROP(...) \ + NML_DBUS_META_IFACE_INIT (__VA_ARGS__ \ + NML_DBUS_META_IFACE_OBJ_PROPERTIES ()) + +extern const NMLDBusMetaIface *const _nml_dbus_meta_ifaces[43]; + +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_accesspoint; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_agentmanager; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_checkpoint; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_connection_active; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_adsl; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bluetooth; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bond; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bridge; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_dummy; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_generic; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_infiniband; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_iptunnel; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_lowpan; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_macsec; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_macvlan; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_modem; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_olpcmesh; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsbridge; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsinterface; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsport; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ppp; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_statistics; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_team; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_tun; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_veth; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vlan; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vxlan; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wifip2p; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wired; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wireguard; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wireless; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wpan; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_dhcp4config; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_dhcp6config; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_dnsmanager; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_ip4config; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_ip6config; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_settings; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_settings_connection; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_vpn_connection; +extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_wifip2ppeer; + +const NMLDBusMetaIface *nml_dbus_meta_iface_get (const char *dbus_iface_name); + +const NMLDBusMetaProperty *nml_dbus_meta_property_get (const NMLDBusMetaIface *meta_iface, + const char *dbus_property_name, + guint *out_idx); + +void _nml_dbus_meta_class_init_with_properties_impl (GObjectClass *object_class, const NMLDBusMetaIface *const*meta_iface); +#define _nml_dbus_meta_class_init_with_properties(object_class, ...) \ + _nml_dbus_meta_class_init_with_properties_impl ((object_class), ((const NMLDBusMetaIface *const[]) { __VA_ARGS__, NULL })) + +/*****************************************************************************/ + +typedef enum { + NML_DBUS_OBJ_STATE_UNLINKED = 0, + NML_DBUS_OBJ_STATE_WATCHED_ONLY, + NML_DBUS_OBJ_STATE_ON_DBUS, + NML_DBUS_OBJ_STATE_WITH_NMOBJ_NOT_READY, + NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY, +} NMLDBusObjState; + +typedef enum { + NML_DBUS_OBJ_CHANGED_TYPE_NONE = 0, + NML_DBUS_OBJ_CHANGED_TYPE_DBUS = (1LL << 0), + NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ = (1LL << 1), +} NMLDBusObjChangedType; + +struct _NMLDBusObject { + NMRefString *dbus_path; + + /* While the object is tracked by NMClient, it is linked with this list. + * The lists are partitioned based on the NMLDBusObjState. */ + CList dbus_objects_lst; + + /* The list of D-Bus interface NMLDBusObjIfaceData. + * + * Some may be about to be removed (iface_removed) or + * unknown (!dbus_iface_is_wellknown). */ + CList iface_lst_head; + + /* The list of registered NMLDBusObjWatcher. */ + CList watcher_lst_head; + + /* When an object changes (e.g. because of new information on D-Bus), we often + * don't process the changes right away, but enqueue the object in a changed + * list. This list goes together with obj_changed_type property below, which + * tracks what changed. */ + CList obj_changed_lst; + + GObject *nmobj; + + int ref_count; + + NMLDBusObjState obj_state:4; + + NMLDBusObjChangedType obj_changed_type:3; +}; + +static inline gboolean +NML_IS_DBUS_OBJECT (NMLDBusObject *dbobj) +{ + nm_assert ( !dbobj + || ( NM_IS_REF_STRING (dbobj->dbus_path) + && dbobj->ref_count > 0)); + nm_assert ( !dbobj->nmobj + || NM_IS_OBJECT (dbobj->nmobj) + || NM_IS_CLIENT (dbobj->nmobj)); + return !!dbobj; +} + +NMLDBusObject *nml_dbus_object_ref (NMLDBusObject *dbobj); + +void nml_dbus_object_unref (NMLDBusObject *dbobj); + +NM_AUTO_DEFINE_FCN0 (NMLDBusObject *, _nm_auto_unref_nml_dbusobj, nml_dbus_object_unref) +#define nm_auto_unref_nml_dbusobj nm_auto (_nm_auto_unref_nml_dbusobj) + +gpointer nml_dbus_object_get_property_location (NMLDBusObject *dbobj, + const NMLDBusMetaIface *meta_iface, + const NMLDBusMetaProperty *meta_property); + +/*****************************************************************************/ + +/* NMClient is not an NMObject, but in some aspects we want to track it like + * an NMObject. For that, both NMClient and NMObject "implement" NMObjectBase, + * despite not actually implementing such a GObject type. */ +typedef struct { + GObject parent; + CList queue_notify_lst; + bool is_disposing:1; +} NMObjectBase; + +typedef struct { + GObjectClass parent; +} NMObjectBaseClass; + +struct _NMObjectPrivate; + +struct _NMObject { + union { + GObject parent; + NMObjectBase obj_base; + }; + struct _NMObjectPrivate *_priv; +}; + +typedef struct _NMObjectClassFieldInfo { + const struct _NMObjectClassFieldInfo *parent; + NMObjectClass *klass; + guint16 offset; + guint16 num; +} _NMObjectClassFieldInfo; + +struct _NMObjectClass { + union { + GObjectClass parent; + NMObjectBaseClass obj_base; + }; + + void (*register_client) (NMObject *self, + NMClient *client, + NMLDBusObject *dbobj); + + void (*unregister_client) (NMObject *self, + NMClient *client, + NMLDBusObject *dbobj); + + gboolean (*is_ready) (NMObject *self); + + void (*obj_changed_notify) (NMObject *self); + + const _NMObjectClassFieldInfo *property_o_info; + const _NMObjectClassFieldInfo *property_ao_info; + + guint16 priv_ptr_offset; + + bool priv_ptr_indirect:1; +}; + +#define _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT(nm_object_class, type_name) \ + G_STMT_START { \ + (nm_object_class)->priv_ptr_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (type_name##Private, type_name, _priv); \ + (nm_object_class)->priv_ptr_indirect = FALSE; \ + } G_STMT_END + +#define _NM_OBJECT_CLASS_INIT_PRIV_PTR_INDIRECT(nm_object_class, type_name) \ + G_STMT_START { \ + (nm_object_class)->priv_ptr_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (type_name##Private *, type_name, _priv); \ + (nm_object_class)->priv_ptr_indirect = TRUE; \ + } G_STMT_END + +#define _NM_OBJECT_CLASS_INIT_FIELD_INFO(_nm_object_class, _field_name, _offset, _num) \ + G_STMT_START { \ + (_nm_object_class)->_field_name = ({ \ + static _NMObjectClassFieldInfo _f; \ + \ + _f = (_NMObjectClassFieldInfo) { \ + .parent = (_nm_object_class)->_field_name, \ + .klass = (_nm_object_class), \ + .offset = _offset, \ + .num = _num, \ + }; \ + &_f; \ + }); \ + } G_STMT_END + +#define _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1(nm_object_class, type_name, field_name) \ + _NM_OBJECT_CLASS_INIT_FIELD_INFO (nm_object_class, \ + property_o_info, \ + NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyO, type_name, field_name), \ + 1) + +#define _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_N(nm_object_class, type_name, field_name) \ + _NM_OBJECT_CLASS_INIT_FIELD_INFO (nm_object_class, \ + property_o_info, \ + NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyO *, type_name, field_name), \ + G_N_ELEMENTS (((type_name *) NULL)->field_name)) + +#define _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1(nm_object_class, type_name, field_name) \ + _NM_OBJECT_CLASS_INIT_FIELD_INFO (nm_object_class, \ + property_ao_info, \ + NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyAO, type_name, field_name), \ + 1) + +#define _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_N(nm_object_class, type_name, field_name) \ + _NM_OBJECT_CLASS_INIT_FIELD_INFO (nm_object_class, \ + property_ao_info, \ + NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyAO *, type_name, field_name), \ + G_N_ELEMENTS (((type_name *) NULL)->field_name)) + + +/*****************************************************************************/ + +struct _NMDevicePrivate; + +struct _NMDevice { + NMObject parent; + struct _NMDevicePrivate *_priv; +}; + +struct _NMDeviceClass { + struct _NMObjectClass parent; + + gboolean (*connection_compatible) (NMDevice *device, + NMConnection *connection, + GError **error); + + const char *(*get_type_description) (NMDevice *device); + + const char *(*get_hw_address) (NMDevice *device); + + GType (*get_setting_type) (NMDevice *device); +}; + +/*****************************************************************************/ + +struct _NMActiveConnectionPrivate; + +struct _NMActiveConnection { + NMObject parent; + struct _NMActiveConnectionPrivate *_priv; +}; + +struct _NMActiveConnectionClass { + struct _NMObjectClass parent; +}; + +/*****************************************************************************/ + +struct _NMDhcpConfigPrivate; + +struct _NMDhcpConfig { + NMObject parent; + struct _NMDhcpConfigPrivate *_priv; +}; + +struct _NMDhcpConfigClass { + struct _NMObjectClass parent; +}; + +/*****************************************************************************/ + +struct _NMIPConfigPrivate; + +struct _NMIPConfig { + NMObject parent; + struct _NMIPConfigPrivate *_priv; +}; + +struct _NMIPConfigClass { + struct _NMObjectClass parent; +}; + +/*****************************************************************************/ + +NMLDBusObject *_nm_object_get_dbobj (gpointer self); + +const char *_nm_object_get_path (gpointer self); + +NMClient *_nm_object_get_client (gpointer self); + +GDBusConnection *_nm_client_get_dbus_connection (NMClient *client); + +const char *_nm_client_get_dbus_name_owner (NMClient *client); + +GMainContext *_nm_client_get_context_main (NMClient *client); +GMainContext *_nm_client_get_context_dbus (NMClient *client); + +void _nm_client_queue_notify_object (NMClient *client, + gpointer nmobj, + const GParamSpec *pspec); + +void _nm_client_notify_object_changed (NMClient *self, + NMLDBusObject *dbobj); + +struct udev *_nm_client_get_udev (NMClient *self); + +/*****************************************************************************/ + +#define NM_CLIENT_NOTIFY_EVENT_PRIO_BEFORE (-100) +#define NM_CLIENT_NOTIFY_EVENT_PRIO_GPROP 0 +#define NM_CLIENT_NOTIFY_EVENT_PRIO_AFTER 100 + +typedef struct _NMClientNotifyEvent NMClientNotifyEvent; + +typedef void (*NMClientNotifyEventCb) (NMClient *self, + gpointer notify_event); + +struct _NMClientNotifyEvent { + CList lst; + NMClientNotifyEventCb callback; + int priority; +}; + +gpointer _nm_client_notify_event_queue (NMClient *self, + int priority, + NMClientNotifyEventCb callback, + gsize event_size); + +typedef struct _NMClientNotifyEventWithPtr NMClientNotifyEventWithPtr; + +typedef void (*NMClientNotifyEventWithPtrCb) (NMClient *self, + NMClientNotifyEventWithPtr *notify_event); + +struct _NMClientNotifyEventWithPtr { + NMClientNotifyEvent parent; + gpointer user_data; +}; + +NMClientNotifyEventWithPtr *_nm_client_notify_event_queue_with_ptr (NMClient *self, + int priority, + NMClientNotifyEventWithPtrCb callback, + gpointer user_data); + +void _nm_client_notify_event_queue_emit_obj_signal (NMClient *self, + GObject *source, + NMObject *nmobj, + gboolean is_added /* or else removed */, + int prio_offset, + guint signal_id); + +/*****************************************************************************/ + +GError *_nm_client_new_error_nm_not_running (void); +GError *_nm_client_new_error_nm_not_cached (void); + +void _nm_client_dbus_call_simple (NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, + const GVariantType *reply_type, + GDBusCallFlags flags, + int timeout_msec, + GAsyncReadyCallback callback, + gpointer user_data); + +void _nm_client_dbus_call (NMClient *self, + gpointer source_obj, + gpointer source_tag, + GCancellable *cancellable, + GAsyncReadyCallback user_callback, + gpointer user_callback_data, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, + const GVariantType *reply_type, + GDBusCallFlags flags, + int timeout_msec, + GAsyncReadyCallback internal_callback); + +GVariant *_nm_client_dbus_call_sync (NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, + const GVariantType *reply_type, + GDBusCallFlags flags, + int timeout_msec, + gboolean strip_dbus_error, + GError **error); + +gboolean _nm_client_dbus_call_sync_void (NMClient *self, + GCancellable *cancellable, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant *parameters, + GDBusCallFlags flags, + int timeout_msec, + gboolean strip_dbus_error, + GError **error); + +void _nm_client_set_property_sync_legacy (NMClient *self, + const char *object_path, + const char *interface, + const char *prop_name, + const char *format_string, + ...); + +/*****************************************************************************/ + +void _nm_client_get_settings_call (NMClient *self, + NMLDBusObject *dbobj); + +GCancellable *_nm_remote_settings_get_settings_prepare (NMRemoteConnection *self); + +void _nm_remote_settings_get_settings_commit (NMRemoteConnection *self, + GVariant *settings); + +/*****************************************************************************/ + +void _nm_active_connection_state_changed_commit (NMActiveConnection *self, + guint32 state, + guint32 reason); + +void _nm_vpn_connection_state_changed_commit (NMVpnConnection *self, + guint32 state, + guint32 reason); + +/*****************************************************************************/ + #endif /* __NM_LIBNM_UTILS_H__ */ diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c deleted file mode 100644 index eb788de2..00000000 --- a/libnm/nm-manager.c +++ /dev/null @@ -1,2233 +0,0 @@ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2014 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include "nm-manager.h" - -#include "nm-utils.h" -#include "nm-checkpoint.h" -#include "nm-libnm-core-intern/nm-common-macros.h" -#include "nm-device-ethernet.h" -#include "nm-device-wifi.h" -#include "nm-core-internal.h" -#include "nm-object-private.h" -#include "nm-active-connection.h" -#include "nm-vpn-connection.h" -#include "nm-dbus-helpers.h" -#include "c-list/src/c-list.h" - -#include "introspection/org.freedesktop.NetworkManager.h" - -void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled); - -static void nm_manager_initable_iface_init (GInitableIface *iface); -static void nm_manager_async_initable_iface_init (GAsyncInitableIface *iface); -static GInitableIface *nm_manager_parent_initable_iface; -static GAsyncInitableIface *nm_manager_parent_async_initable_iface; - -G_DEFINE_TYPE_WITH_CODE (NMManager, nm_manager, NM_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_manager_initable_iface_init); - G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_manager_async_initable_iface_init); - ) - -#define NM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MANAGER, NMManagerPrivate)) - -typedef struct { - NMDBusManager *proxy; - GCancellable *props_cancellable; - char *version; - NMState state; - gboolean startup; - GPtrArray *devices; - GPtrArray *all_devices; - GPtrArray *active_connections; - GPtrArray *checkpoints; - GSList *added_checkpoints; - NMConnectivityState connectivity; - NMActiveConnection *primary_connection; - NMActiveConnection *activating_connection; - NMMetered metered; - - GCancellable *perm_call_cancellable; - GHashTable *permissions; - - /* Activations waiting for their NMActiveConnection - * to appear and then their callback to be called. - */ - CList pending_activations; - - gboolean networking_enabled; - gboolean wireless_enabled; - gboolean wireless_hw_enabled; - - gboolean wwan_enabled; - gboolean wwan_hw_enabled; - - gboolean wimax_enabled; - gboolean wimax_hw_enabled; - - gboolean connectivity_check_available; - gboolean connectivity_check_enabled; -} NMManagerPrivate; - -enum { - PROP_0, - PROP_VERSION, - PROP_STATE, - PROP_STARTUP, - PROP_NETWORKING_ENABLED, - PROP_WIRELESS_ENABLED, - PROP_WIRELESS_HARDWARE_ENABLED, - PROP_WWAN_ENABLED, - PROP_WWAN_HARDWARE_ENABLED, - PROP_WIMAX_ENABLED, - PROP_WIMAX_HARDWARE_ENABLED, - PROP_ACTIVE_CONNECTIONS, - PROP_CONNECTIVITY, - PROP_CONNECTIVITY_CHECK_AVAILABLE, - PROP_CONNECTIVITY_CHECK_ENABLED, - PROP_PRIMARY_CONNECTION, - PROP_ACTIVATING_CONNECTION, - PROP_DEVICES, - PROP_CHECKPOINTS, - PROP_METERED, - PROP_ALL_DEVICES, - - LAST_PROP -}; - -enum { - DEVICE_ADDED, - DEVICE_REMOVED, - ANY_DEVICE_ADDED, - ANY_DEVICE_REMOVED, - ACTIVE_CONNECTION_ADDED, - ACTIVE_CONNECTION_REMOVED, - CHECKPOINT_ADDED, - CHECKPOINT_REMOVED, - PERMISSION_CHANGED, - - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -/*****************************************************************************/ - -typedef struct { - NMManager *manager; - GSimpleAsyncResult *simple; - char *path; -} CheckpointInfo; - -static CheckpointInfo * -find_checkpoint_info (NMManager *manager, const char *path) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - CheckpointInfo *info; - GSList *iter; - - for (iter = priv->added_checkpoints; iter; iter = g_slist_next (iter)) { - info = iter->data; - if (nm_streq0 (path, info->path)) - return info; - } - - return NULL; -} - -static void -checkpoint_info_complete (NMManager *self, - CheckpointInfo *info, - NMCheckpoint *checkpoint, - GError *error) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - - g_return_if_fail (info); - - if (checkpoint) { - g_simple_async_result_set_op_res_gpointer (info->simple, - g_object_ref (checkpoint), - g_object_unref); - } else - g_simple_async_result_set_from_error (info->simple, error); - g_simple_async_result_complete (info->simple); - - g_object_unref (info->simple); - priv->added_checkpoints = g_slist_remove (priv->added_checkpoints, info); - - g_free (info->path); - g_slice_free (CheckpointInfo, info); -} - -static void -nm_manager_init (NMManager *manager) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - - c_list_init (&priv->pending_activations); - - priv->state = NM_STATE_UNKNOWN; - priv->connectivity = NM_CONNECTIVITY_UNKNOWN; - - priv->permissions = g_hash_table_new (nm_direct_hash, NULL); - priv->devices = g_ptr_array_new (); - priv->all_devices = g_ptr_array_new (); - priv->active_connections = g_ptr_array_new (); -} - -static void -poke_wireless_devices_with_rf_status (NMManager *manager) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - int i; - - for (i = 0; i < priv->all_devices->len; i++) { - NMDevice *device = g_ptr_array_index (priv->all_devices, i); - - if (NM_IS_DEVICE_WIFI (device)) - _nm_device_wifi_set_wireless_enabled (NM_DEVICE_WIFI (device), priv->wireless_enabled); - } -} - -static void -wireless_enabled_cb (GObject *object, GParamSpec *pspec, gpointer user_data) -{ - poke_wireless_devices_with_rf_status (NM_MANAGER (object)); -} - -static void manager_recheck_permissions (NMDBusManager *proxy, gpointer user_data); - -static void -init_dbus (NMObject *object) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_MANAGER_VERSION, &priv->version }, - { NM_MANAGER_STATE, &priv->state }, - { NM_MANAGER_STARTUP, &priv->startup }, - { NM_MANAGER_NETWORKING_ENABLED, &priv->networking_enabled }, - { NM_MANAGER_WIRELESS_ENABLED, &priv->wireless_enabled }, - { NM_MANAGER_WIRELESS_HARDWARE_ENABLED, &priv->wireless_hw_enabled }, - { NM_MANAGER_WWAN_ENABLED, &priv->wwan_enabled }, - { NM_MANAGER_WWAN_HARDWARE_ENABLED, &priv->wwan_hw_enabled }, - { NM_MANAGER_WIMAX_ENABLED, &priv->wimax_enabled }, - { NM_MANAGER_WIMAX_HARDWARE_ENABLED, &priv->wimax_hw_enabled }, - { NM_MANAGER_ACTIVE_CONNECTIONS, &priv->active_connections, NULL, NM_TYPE_ACTIVE_CONNECTION, "active-connection" }, - { NM_MANAGER_CONNECTIVITY, &priv->connectivity }, - { NM_MANAGER_CONNECTIVITY_CHECK_AVAILABLE, &priv->connectivity_check_available }, - { NM_MANAGER_CONNECTIVITY_CHECK_ENABLED, &priv->connectivity_check_enabled }, - { NM_MANAGER_PRIMARY_CONNECTION, &priv->primary_connection, NULL, NM_TYPE_ACTIVE_CONNECTION }, - { NM_MANAGER_ACTIVATING_CONNECTION, &priv->activating_connection, NULL, NM_TYPE_ACTIVE_CONNECTION }, - { NM_MANAGER_DEVICES, &priv->devices, NULL, NM_TYPE_DEVICE, "device" }, - { NM_MANAGER_CHECKPOINTS, &priv->checkpoints, NULL, NM_TYPE_CHECKPOINT, "checkpoint" }, - { NM_MANAGER_METERED, &priv->metered }, - { NM_MANAGER_ALL_DEVICES, &priv->all_devices, NULL, NM_TYPE_DEVICE, "any-device" }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_manager_parent_class)->init_dbus (object); - - priv->proxy = NMDBUS_MANAGER (_nm_object_get_proxy (object, NM_DBUS_INTERFACE)); - _nm_object_register_properties (object, - NM_DBUS_INTERFACE, - property_info); - - /* Permissions */ - g_signal_connect_object (priv->proxy, "check-permissions", - G_CALLBACK (manager_recheck_permissions), object, 0); -} - -static void -object_creation_failed (NMObject *object, const char *failed_path) -{ - NMManager *self = NM_MANAGER (object); - CheckpointInfo *info; - GError *add_error; - - info = find_checkpoint_info (self, failed_path); - if (info) { - add_error = g_error_new_literal (NM_CLIENT_ERROR, - NM_CLIENT_ERROR_OBJECT_CREATION_FAILED, - _("Checkpoint was removed before it was initialized")); - checkpoint_info_complete (self, info, NULL, add_error); - g_error_free (add_error); - } -} - -static NMClientPermission -nm_permission_to_client (const char *nm) -{ - if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK)) - return NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK; - else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI)) - return NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI; - else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN)) - return NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN; - else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX)) - return NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX; - else if (!strcmp (nm, NM_AUTH_PERMISSION_SLEEP_WAKE)) - return NM_CLIENT_PERMISSION_SLEEP_WAKE; - else if (!strcmp (nm, NM_AUTH_PERMISSION_NETWORK_CONTROL)) - return NM_CLIENT_PERMISSION_NETWORK_CONTROL; - else if (!strcmp (nm, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED)) - return NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED; - else if (!strcmp (nm, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN)) - return NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN; - else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM)) - return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM; - else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN)) - return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN; - else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME)) - return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME; - else if (!strcmp (nm, NM_AUTH_PERMISSION_SETTINGS_MODIFY_GLOBAL_DNS)) - return NM_CLIENT_PERMISSION_SETTINGS_MODIFY_GLOBAL_DNS; - else if (!strcmp (nm, NM_AUTH_PERMISSION_RELOAD)) - return NM_CLIENT_PERMISSION_RELOAD; - else if (!strcmp (nm, NM_AUTH_PERMISSION_CHECKPOINT_ROLLBACK)) - return NM_CLIENT_PERMISSION_CHECKPOINT_ROLLBACK; - else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_STATISTICS)) - return NM_CLIENT_PERMISSION_ENABLE_DISABLE_STATISTICS; - else if (!strcmp (nm, NM_AUTH_PERMISSION_ENABLE_DISABLE_CONNECTIVITY_CHECK)) - return NM_CLIENT_PERMISSION_ENABLE_DISABLE_CONNECTIVITY_CHECK; - else if (!strcmp (nm, NM_AUTH_PERMISSION_WIFI_SCAN)) - return NM_CLIENT_PERMISSION_WIFI_SCAN; - - return NM_CLIENT_PERMISSION_NONE; -} - -static NMClientPermissionResult -nm_permission_result_to_client (const char *nm) -{ - if (!strcmp (nm, "yes")) - return NM_CLIENT_PERMISSION_RESULT_YES; - else if (!strcmp (nm, "no")) - return NM_CLIENT_PERMISSION_RESULT_NO; - else if (!strcmp (nm, "auth")) - return NM_CLIENT_PERMISSION_RESULT_AUTH; - return NM_CLIENT_PERMISSION_RESULT_UNKNOWN; -} - -static void -update_permissions (NMManager *self, GVariant *permissions) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - GHashTableIter iter; - gpointer key, value; - NMClientPermission perm; - NMClientPermissionResult perm_result; - GList *keys, *keys_iter; - - /* get list of old permissions for change notification */ - keys = g_hash_table_get_keys (priv->permissions); - g_hash_table_remove_all (priv->permissions); - - if (permissions) { - GVariantIter viter; - const char *pkey, *pvalue; - - /* Process new permissions */ - g_variant_iter_init (&viter, permissions); - while (g_variant_iter_next (&viter, "{&s&s}", &pkey, &pvalue)) { - perm = nm_permission_to_client (pkey); - perm_result = nm_permission_result_to_client (pvalue); - if (perm) { - g_hash_table_insert (priv->permissions, - GUINT_TO_POINTER (perm), - GUINT_TO_POINTER (perm_result)); - - /* Remove this permission from the list of previous permissions - * we'll be sending NM_CLIENT_PERMISSION_RESULT_UNKNOWN for - * in the change signal since it is still a known permission. - */ - keys = g_list_remove (keys, GUINT_TO_POINTER (perm)); - } - } - } - - /* Signal changes in all updated permissions */ - g_hash_table_iter_init (&iter, priv->permissions); - while (g_hash_table_iter_next (&iter, &key, &value)) { - g_signal_emit (self, signals[PERMISSION_CHANGED], 0, - GPOINTER_TO_UINT (key), - GPOINTER_TO_UINT (value)); - } - - /* And signal changes in all permissions that used to be valid but for - * some reason weren't received in the last request (if any). - */ - for (keys_iter = keys; keys_iter; keys_iter = g_list_next (keys_iter)) { - g_signal_emit (self, signals[PERMISSION_CHANGED], 0, - GPOINTER_TO_UINT (keys_iter->data), - NM_CLIENT_PERMISSION_RESULT_UNKNOWN); - } - g_list_free (keys); -} - -static gboolean -get_permissions_sync (NMManager *self, GError **error) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - GVariant *permissions; - - if (nmdbus_manager_call_get_permissions_sync (priv->proxy, - &permissions, - NULL, error)) { - update_permissions (self, permissions); - g_variant_unref (permissions); - return TRUE; - } else { - if (error && *error) - g_dbus_error_strip_remote_error (*error); - update_permissions (self, NULL); - return FALSE; - } -} - -static void -get_permissions_reply (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - NMManager *self; - NMManagerPrivate *priv; - GVariant *permissions = NULL; - GError *error = NULL; - - /* WARNING: this may be called after the manager is disposed, so we can't - * look at self/priv until after we've determined that that isn't the case. - */ - - nmdbus_manager_call_get_permissions_finish (NMDBUS_MANAGER (object), - &permissions, - result, &error); - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { - /* @self has been disposed. */ - g_error_free (error); - return; - } - - self = user_data; - priv = NM_MANAGER_GET_PRIVATE (self); - - update_permissions (self, permissions); - - g_clear_pointer (&permissions, g_variant_unref); - g_clear_error (&error); - g_clear_object (&priv->perm_call_cancellable); -} - -static void -manager_recheck_permissions (NMDBusManager *proxy, gpointer user_data) -{ - NMManager *self = NM_MANAGER (user_data); - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - - if (priv->perm_call_cancellable) - return; - - priv->perm_call_cancellable = g_cancellable_new (); - nmdbus_manager_call_get_permissions (priv->proxy, - priv->perm_call_cancellable, - get_permissions_reply, - self); -} - -const char * -nm_manager_get_version (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - - return nm_str_not_empty (NM_MANAGER_GET_PRIVATE (manager)->version); -} - -NMState -nm_manager_get_state (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), NM_STATE_UNKNOWN); - - return NM_MANAGER_GET_PRIVATE (manager)->state; -} - -gboolean -nm_manager_get_startup (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), NM_STATE_UNKNOWN); - - return NM_MANAGER_GET_PRIVATE (manager)->startup; -} - -gboolean -nm_manager_networking_get_enabled (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - - return NM_MANAGER_GET_PRIVATE (manager)->networking_enabled; -} - -gboolean -nm_manager_networking_set_enabled (NMManager *manager, gboolean enable, GError **error) -{ - gboolean ret; - - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - - ret = nmdbus_manager_call_enable_sync (NM_MANAGER_GET_PRIVATE (manager)->proxy, - enable, - NULL, error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - -gboolean -nm_manager_wireless_get_enabled (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - - return NM_MANAGER_GET_PRIVATE (manager)->wireless_enabled; -} - -void -nm_manager_wireless_set_enabled (NMManager *manager, gboolean enabled) -{ - g_return_if_fail (NM_IS_MANAGER (manager)); - - _nm_object_set_property (NM_OBJECT (manager), - NM_DBUS_INTERFACE, - "WirelessEnabled", - "b", enabled); -} - -gboolean -nm_manager_wireless_hardware_get_enabled (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - - return NM_MANAGER_GET_PRIVATE (manager)->wireless_hw_enabled; -} - -gboolean -nm_manager_wwan_get_enabled (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - - return NM_MANAGER_GET_PRIVATE (manager)->wwan_enabled; -} - -void -nm_manager_wwan_set_enabled (NMManager *manager, gboolean enabled) -{ - g_return_if_fail (NM_IS_MANAGER (manager)); - - _nm_object_set_property (NM_OBJECT (manager), - NM_DBUS_INTERFACE, - "WwanEnabled", - "b", enabled); -} - -gboolean -nm_manager_wwan_hardware_get_enabled (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - - return NM_MANAGER_GET_PRIVATE (manager)->wwan_hw_enabled; -} - -gboolean -nm_manager_wimax_get_enabled (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - - return NM_MANAGER_GET_PRIVATE (manager)->wimax_enabled; -} - -void -nm_manager_wimax_set_enabled (NMManager *manager, gboolean enabled) -{ - g_return_if_fail (NM_IS_MANAGER (manager)); - - _nm_object_set_property (NM_OBJECT (manager), - NM_DBUS_INTERFACE, - "WimaxEnabled", - "b", enabled); -} - -gboolean -nm_manager_wimax_hardware_get_enabled (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - - return NM_MANAGER_GET_PRIVATE (manager)->wimax_hw_enabled; -} - -gboolean -nm_manager_connectivity_check_get_available (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - - return NM_MANAGER_GET_PRIVATE (manager)->connectivity_check_available; -} - -gboolean -nm_manager_connectivity_check_get_enabled (NMManager *manager) -{ - return NM_MANAGER_GET_PRIVATE (manager)->connectivity_check_enabled; -} - -void -nm_manager_connectivity_check_set_enabled (NMManager *manager, gboolean enabled) -{ - g_return_if_fail (NM_IS_MANAGER (manager)); - - _nm_object_set_property (NM_OBJECT (manager), - NM_DBUS_INTERFACE, - "ConnectivityCheckEnabled", - "b", enabled); -} - -const char * -nm_manager_connectivity_check_get_uri (NMManager *manager) -{ - return nmdbus_manager_get_connectivity_check_uri (NM_MANAGER_GET_PRIVATE (manager)->proxy); -} - -gboolean -nm_manager_get_logging (NMManager *manager, char **level, char **domains, GError **error) -{ - gboolean ret; - - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - g_return_val_if_fail (level == NULL || *level == NULL, FALSE); - g_return_val_if_fail (domains == NULL || *domains == NULL, FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!level && !domains) - return TRUE; - - ret = nmdbus_manager_call_get_logging_sync (NM_MANAGER_GET_PRIVATE (manager)->proxy, - level, domains, - NULL, error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - -gboolean -nm_manager_set_logging (NMManager *manager, const char *level, const char *domains, GError **error) -{ - gboolean ret; - - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!level && !domains) - return TRUE; - - if (!level) - level = ""; - if (!domains) - domains = ""; - - ret = nmdbus_manager_call_set_logging_sync (NM_MANAGER_GET_PRIVATE (manager)->proxy, - level, domains, - NULL, error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - -NMClientPermissionResult -nm_manager_get_permission_result (NMManager *manager, NMClientPermission permission) -{ - gpointer result; - - g_return_val_if_fail (NM_IS_MANAGER (manager), NM_CLIENT_PERMISSION_RESULT_UNKNOWN); - - result = g_hash_table_lookup (NM_MANAGER_GET_PRIVATE (manager)->permissions, - GUINT_TO_POINTER (permission)); - return GPOINTER_TO_UINT (result); -} - -NMConnectivityState -nm_manager_get_connectivity (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), NM_CONNECTIVITY_UNKNOWN); - - return NM_MANAGER_GET_PRIVATE (manager)->connectivity; -} - -NMConnectivityState -nm_manager_check_connectivity (NMManager *manager, - GCancellable *cancellable, - GError **error) -{ - NMManagerPrivate *priv; - guint32 connectivity; - - g_return_val_if_fail (NM_IS_MANAGER (manager), NM_CONNECTIVITY_UNKNOWN); - priv = NM_MANAGER_GET_PRIVATE (manager); - - if (nmdbus_manager_call_check_connectivity_sync (priv->proxy, - &connectivity, - cancellable, error)) { - if (connectivity != priv->connectivity) { - priv->connectivity = connectivity; - g_object_notify (G_OBJECT (manager), NM_MANAGER_CONNECTIVITY); - } - return connectivity; - } - else { - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return NM_CONNECTIVITY_UNKNOWN; - } -} - -static void -check_connectivity_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - guint32 connectivity; - GError *error = NULL; - NMManager *manager; - NMManagerPrivate *priv; - - if (nmdbus_manager_call_check_connectivity_finish (NMDBUS_MANAGER (object), - &connectivity, - result, &error)) { - g_simple_async_result_set_op_res_gssize (simple, connectivity); - - manager = NM_MANAGER (g_async_result_get_source_object (G_ASYNC_RESULT (simple))); - priv = NM_MANAGER_GET_PRIVATE (manager); - if (connectivity != priv->connectivity) { - priv->connectivity = connectivity; - g_object_notify (G_OBJECT (manager), NM_MANAGER_CONNECTIVITY); - } - } else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - - g_simple_async_result_complete (simple); - g_object_unref (simple); -} - -void -nm_manager_check_connectivity_async (NMManager *manager, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - NMManagerPrivate *priv; - GSimpleAsyncResult *simple; - - g_return_if_fail (NM_IS_MANAGER (manager)); - priv = NM_MANAGER_GET_PRIVATE (manager); - - simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data, - nm_manager_check_connectivity_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nmdbus_manager_call_check_connectivity (priv->proxy, - cancellable, - check_connectivity_cb, simple); -} - -NMConnectivityState -nm_manager_check_connectivity_finish (NMManager *manager, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), nm_manager_check_connectivity_async), NM_CONNECTIVITY_UNKNOWN); - - simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return NM_CONNECTIVITY_UNKNOWN; - return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple); -} - -/*****************************************************************************/ -/* Devices */ -/*****************************************************************************/ - -const GPtrArray * -nm_manager_get_devices (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - - return NM_MANAGER_GET_PRIVATE (manager)->devices; -} - -const GPtrArray * -nm_manager_get_all_devices (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - - return NM_MANAGER_GET_PRIVATE (manager)->all_devices; -} - -NMDevice * -nm_manager_get_device_by_path (NMManager *manager, const char *object_path) -{ - const GPtrArray *devices; - guint i; - - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - g_return_val_if_fail (object_path, NULL); - - devices = nm_manager_get_devices (manager); - for (i = 0; i < devices->len; i++) { - NMDevice *candidate = g_ptr_array_index (devices, i); - if (!strcmp (nm_object_get_path (NM_OBJECT (candidate)), object_path)) { - return candidate; - } - } - return NULL; -} - -static NMCheckpoint * -get_checkpoint_by_path (NMManager *manager, const char *object_path) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - NMCheckpoint *candidate; - guint i; - - for (i = 0; i < priv->checkpoints->len; i++) { - candidate = priv->checkpoints->pdata[i]; - if (nm_streq (nm_object_get_path (NM_OBJECT (candidate)), object_path)) - return candidate; - } - return NULL; -} - -NMDevice * -nm_manager_get_device_by_iface (NMManager *manager, const char *iface) -{ - const GPtrArray *devices; - int i; - NMDevice *device = NULL; - - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - g_return_val_if_fail (iface, NULL); - - devices = nm_manager_get_devices (manager); - for (i = 0; i < devices->len; i++) { - NMDevice *candidate = g_ptr_array_index (devices, i); - if (!strcmp (nm_device_get_iface (candidate), iface)) { - device = candidate; - break; - } - } - - return device; -} - -/*****************************************************************************/ -/* Active Connections */ -/*****************************************************************************/ - -const GPtrArray * -nm_manager_get_active_connections (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - - return NM_MANAGER_GET_PRIVATE (manager)->active_connections; -} - -NMActiveConnection * -nm_manager_get_primary_connection (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - - return NM_MANAGER_GET_PRIVATE (manager)->primary_connection; -} - -NMActiveConnection * -nm_manager_get_activating_connection (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - - return NM_MANAGER_GET_PRIVATE (manager)->activating_connection; -} - -typedef enum { - ACTIVATE_TYPE_ACTIVATE_CONNECTION, - ACTIVATE_TYPE_ADD_AND_ACTIVATE_CONNECTION, - ACTIVATE_TYPE_ADD_AND_ACTIVATE_CONNECTION2, -} ActivateType; - -typedef struct { - CList lst; - NMManager *manager; - GSimpleAsyncResult *simple; - GCancellable *cancellable; - char *active_path; - char *new_connection_path; - GVariant *add_and_activate_output; - gulong cancelled_id; - ActivateType activate_type; -} ActivateInfo; - -_NMActivateResult * -_nm_activate_result_new (NMActiveConnection *active, - GVariant *add_and_activate_output) -{ - _NMActivateResult *r; - - nm_assert (!add_and_activate_output || g_variant_is_of_type (add_and_activate_output, G_VARIANT_TYPE ("a{sv}"))); - nm_assert (!add_and_activate_output || !g_variant_is_floating (add_and_activate_output)); - - r = g_slice_new (_NMActivateResult); - *r = (_NMActivateResult) { - .active = g_object_ref (active), - .add_and_activate_output = nm_g_variant_ref (add_and_activate_output), - }; - return r; -} - -void -_nm_activate_result_free (_NMActivateResult *result) -{ - g_object_unref (result->active); - nm_g_variant_unref (result->add_and_activate_output); - g_slice_free (_NMActivateResult, result); -} - -static void -activate_info_complete (ActivateInfo *info, - NMActiveConnection *active, - GError *error) -{ - nm_assert ((!error) != (!active)); - - nm_clear_g_signal_handler (info->cancellable, &info->cancelled_id); - - c_list_unlink_stale (&info->lst); - - if (active) { - g_simple_async_result_set_op_res_gpointer (info->simple, - _nm_activate_result_new (active, - info->add_and_activate_output), - (GDestroyNotify) _nm_activate_result_free); - } else - g_simple_async_result_set_from_error (info->simple, error); - - g_simple_async_result_complete (info->simple); - - nm_g_variant_unref (info->add_and_activate_output); - g_free (info->active_path); - g_free (info->new_connection_path); - g_object_unref (info->simple); - nm_g_object_unref (info->cancellable); - g_slice_free (ActivateInfo, info); -} - -static NMActiveConnection * -find_active_connection_by_path (NMManager *self, const char *ac_path) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - int i; - - for (i = 0; i < priv->active_connections->len; i++) { - NMActiveConnection *candidate = g_ptr_array_index (priv->active_connections, i); - const char *candidate_path = nm_object_get_path (NM_OBJECT (candidate)); - - if (g_strcmp0 (ac_path, candidate_path) == 0) - return candidate; - } - - return NULL; -} - -static void -recheck_pending_activations (NMManager *self) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - CList *iter, *safe; - NMActiveConnection *candidate; - const GPtrArray *devices; - NMDevice *device; - GDBusObjectManager *object_manager = NULL; - GError *error; - - object_manager = _nm_object_get_dbus_object_manager (NM_OBJECT (self)); - - /* For each pending activation, look for an active connection that has the - * pending activation's object path, where the active connection and its - * device have both updated their properties to point to each other, and - * call the pending connection's callback. - */ - c_list_for_each_safe (iter, safe, &priv->pending_activations) { - ActivateInfo *info = c_list_entry (iter, ActivateInfo, lst); - gs_unref_object GDBusObject *dbus_obj = NULL; - - if (!info->active_path) - continue; - - /* Check that the object manager still knows about the object. - * It could be that it vanished before we even learned its name. */ - dbus_obj = g_dbus_object_manager_get_object (object_manager, info->active_path); - if (!dbus_obj) { - error = g_error_new_literal (NM_CLIENT_ERROR, - NM_CLIENT_ERROR_OBJECT_CREATION_FAILED, - _("Active connection removed before it was initialized")); - activate_info_complete (info, NULL, error); - g_clear_error (&error); - break; - } - - candidate = find_active_connection_by_path (self, info->active_path); - if (!candidate) - continue; - - /* Check that the AC and device are both ready */ - devices = nm_active_connection_get_devices (candidate); - if (devices->len == 0) - continue; - - if (!NM_IS_VPN_CONNECTION (candidate)) { - device = devices->pdata[0]; - if (nm_device_get_active_connection (device) != candidate) - continue; - } - - activate_info_complete (info, candidate, NULL); - break; - } -} - -static void -activation_cancelled (GCancellable *cancellable, - gpointer user_data) -{ - ActivateInfo *info = user_data; - GError *error = NULL; - - if (!g_cancellable_set_error_if_cancelled (cancellable, &error)) - return; - - activate_info_complete (info, NULL, error); - g_clear_error (&error); -} - -static void -activate_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - ActivateInfo *info = user_data; - GError *error = NULL; - - if (nmdbus_manager_call_activate_connection_finish (NMDBUS_MANAGER (object), - &info->active_path, - result, &error)) { - if (info->cancellable) { - info->cancelled_id = g_signal_connect (info->cancellable, "cancelled", - G_CALLBACK (activation_cancelled), info); - } - - recheck_pending_activations (info->manager); - } else { - g_dbus_error_strip_remote_error (error); - activate_info_complete (info, NULL, error); - g_clear_error (&error); - } -} - -void -nm_manager_activate_connection_async (NMManager *manager, - NMConnection *connection, - NMDevice *device, - const char *specific_object, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - NMManagerPrivate *priv; - ActivateInfo *info; - - g_return_if_fail (NM_IS_MANAGER (manager)); - if (device) - g_return_if_fail (NM_IS_DEVICE (device)); - if (connection) - g_return_if_fail (NM_IS_CONNECTION (connection)); - - priv = NM_MANAGER_GET_PRIVATE (manager); - - info = g_slice_new0 (ActivateInfo); - info->activate_type = ACTIVATE_TYPE_ACTIVATE_CONNECTION; - info->manager = manager; - info->simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data, - nm_manager_activate_connection_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (info->simple, cancellable); - info->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - - c_list_link_tail (&priv->pending_activations, &info->lst); - - nmdbus_manager_call_activate_connection (priv->proxy, - connection ? nm_connection_get_path (connection) : "/", - device ? nm_object_get_path (NM_OBJECT (device)) : "/", - specific_object ?: "/", - cancellable, - activate_cb, info); -} - -NMActiveConnection * -nm_manager_activate_connection_finish (NMManager *manager, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - _NMActivateResult *r; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), nm_manager_activate_connection_async), NULL); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return NULL; - - r = g_simple_async_result_get_op_res_gpointer (simple); - return g_object_ref (r->active); -} - -static void -add_activate_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - ActivateInfo *info = user_data; - gs_free_error GError *error = NULL; - gboolean success; - - nm_assert (info); - nm_assert (!info->active_path); - nm_assert (!info->add_and_activate_output); - - if (info->activate_type == ACTIVATE_TYPE_ADD_AND_ACTIVATE_CONNECTION) { - success = nmdbus_manager_call_add_and_activate_connection_finish (NMDBUS_MANAGER (object), - NULL, - &info->active_path, - result, - &error); - } else { - success = nmdbus_manager_call_add_and_activate_connection2_finish (NMDBUS_MANAGER (object), - NULL, - &info->active_path, - &info->add_and_activate_output, - result, - &error); - } - if (!success) { - g_dbus_error_strip_remote_error (error); - activate_info_complete (info, NULL, error); - return; - } - - if (info->cancellable) { - info->cancelled_id = g_signal_connect (info->cancellable, "cancelled", - G_CALLBACK (activation_cancelled), info); - } - - recheck_pending_activations (info->manager); -} - -void -nm_manager_add_and_activate_connection_async (NMManager *manager, - NMConnection *partial, - NMDevice *device, - const char *specific_object, - GVariant *options, - gboolean force_v2, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - NMManagerPrivate *priv; - GVariant *dict = NULL; - ActivateInfo *info; - ActivateType activate_type = ACTIVATE_TYPE_ADD_AND_ACTIVATE_CONNECTION; - - g_return_if_fail (NM_IS_MANAGER (manager)); - g_return_if_fail (NM_IS_DEVICE (device)); - if (partial) - g_return_if_fail (NM_IS_CONNECTION (partial)); - - priv = NM_MANAGER_GET_PRIVATE (manager); - - info = g_slice_new0 (ActivateInfo); - info->manager = manager; - info->simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data, - nm_manager_add_and_activate_connection_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (info->simple, cancellable); - info->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - - c_list_link_tail (&priv->pending_activations, &info->lst); - - if (partial) - dict = nm_connection_to_dbus (partial, NM_CONNECTION_SERIALIZE_ALL); - if (!dict) - dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0); - if (force_v2) { - if (!options) - options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); - activate_type = ACTIVATE_TYPE_ADD_AND_ACTIVATE_CONNECTION2; - } else { - if (options) { - if (g_variant_n_children (options) > 0) - activate_type = ACTIVATE_TYPE_ADD_AND_ACTIVATE_CONNECTION2; - else - nm_g_variant_unref_floating (options); - } - } - - info->activate_type = activate_type; - - if (activate_type == ACTIVATE_TYPE_ADD_AND_ACTIVATE_CONNECTION2) { - nmdbus_manager_call_add_and_activate_connection2 (priv->proxy, - dict, - nm_object_get_path (NM_OBJECT (device)), - specific_object ?: "/", - options, - cancellable, - add_activate_cb, - info); - } else { - nmdbus_manager_call_add_and_activate_connection (priv->proxy, - dict, - nm_object_get_path (NM_OBJECT (device)), - specific_object ?: "/", - cancellable, - add_activate_cb, - info); - } -} - -NMActiveConnection * -nm_manager_add_and_activate_connection_finish (NMManager *manager, - GAsyncResult *result, - GVariant **out_result, - GError **error) -{ - GSimpleAsyncResult *simple; - _NMActivateResult *r; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), nm_manager_add_and_activate_connection_async), NULL); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) { - NM_SET_OUT (out_result, NULL); - return NULL; - } - - r = g_simple_async_result_get_op_res_gpointer (simple); - NM_SET_OUT (out_result, nm_g_variant_ref (r->add_and_activate_output)); - return g_object_ref (r->active); -} - -static void -device_ac_changed (GObject *object, GParamSpec *pspec, gpointer user_data) -{ - NMManager *self = user_data; - - recheck_pending_activations (self); -} - -static void -device_added (NMManager *self, NMDevice *device) -{ - g_signal_connect_object (device, "notify::" NM_DEVICE_ACTIVE_CONNECTION, - G_CALLBACK (device_ac_changed), self, 0); -} - -static void -device_removed (NMManager *self, NMDevice *device) -{ - g_signal_handlers_disconnect_by_func (device, G_CALLBACK (device_ac_changed), self); -} - -static void -ac_devices_changed (GObject *object, GParamSpec *pspec, gpointer user_data) -{ - NMManager *self = user_data; - - recheck_pending_activations (self); -} - -static void -active_connection_added (NMManager *self, NMActiveConnection *ac) -{ - g_signal_connect_object (ac, "notify::" NM_ACTIVE_CONNECTION_DEVICES, - G_CALLBACK (ac_devices_changed), self, 0); - recheck_pending_activations (self); -} - -static void -active_connection_removed (NMManager *self, NMActiveConnection *ac) -{ - g_signal_handlers_disconnect_by_func (ac, G_CALLBACK (ac_devices_changed), self); - recheck_pending_activations (self); -} - -static void -checkpoint_added (NMManager *manager, NMCheckpoint *checkpoint) -{ - CheckpointInfo *info; - - info = find_checkpoint_info (manager, nm_object_get_path (NM_OBJECT (checkpoint))); - if (info) - checkpoint_info_complete (manager, info, checkpoint, NULL); -} - -gboolean -nm_manager_deactivate_connection (NMManager *manager, - NMActiveConnection *active, - GCancellable *cancellable, - GError **error) -{ - const char *path; - gboolean ret; - - g_return_val_if_fail (NM_IS_MANAGER (manager), FALSE); - g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (active), FALSE); - - path = nm_object_get_path (NM_OBJECT (active)); - ret = nmdbus_manager_call_deactivate_connection_sync (NM_MANAGER_GET_PRIVATE (manager)->proxy, - path, - cancellable, error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - -static void -deactivated_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nmdbus_manager_call_deactivate_connection_finish (NMDBUS_MANAGER (object), - result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - g_simple_async_result_complete (simple); - g_object_unref (simple); -} - -void -nm_manager_deactivate_connection_async (NMManager *manager, - NMActiveConnection *active, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - const char *path; - GSimpleAsyncResult *simple; - - g_return_if_fail (NM_IS_MANAGER (manager)); - g_return_if_fail (NM_IS_ACTIVE_CONNECTION (active)); - - simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data, - nm_manager_deactivate_connection_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - path = nm_object_get_path (NM_OBJECT (active)); - nmdbus_manager_call_deactivate_connection (NM_MANAGER_GET_PRIVATE (manager)->proxy, - path, - cancellable, - deactivated_cb, simple); -} - -gboolean -nm_manager_deactivate_connection_finish (NMManager *manager, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), nm_manager_deactivate_connection_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); -} - -/*****************************************************************************/ - -static void -free_active_connections (NMManager *manager) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - int i; - - if (!priv->active_connections) - return; - - /* Break circular refs */ - for (i = 0; i < priv->active_connections->len; i++) - g_object_run_dispose (G_OBJECT (priv->active_connections->pdata[i])); - g_ptr_array_unref (priv->active_connections); - priv->active_connections = NULL; -} - -/*****************************************************************************/ - -static const char ** -get_device_paths (const GPtrArray *devices) -{ - const char **array; - guint i; - - array = g_new (const char *, devices->len + 1); - for (i = 0; i < devices->len; i++) - array[i] = nm_object_get_path (NM_OBJECT (devices->pdata[i])); - - array[i] = NULL; - - return array; -} - -const GPtrArray * -nm_manager_get_checkpoints (NMManager *manager) -{ - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - - return NM_MANAGER_GET_PRIVATE (manager)->checkpoints; -} - -static void -checkpoint_created_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - CheckpointInfo *info = user_data; - NMManager *self = info->manager; - gs_free_error GError *error = NULL; - NMCheckpoint *checkpoint; - - nmdbus_manager_call_checkpoint_create_finish (NMDBUS_MANAGER (object), - &info->path, result, &error); - if (error) { - g_dbus_error_strip_remote_error (error); - checkpoint_info_complete (self, info, NULL, error); - return; - } - - checkpoint = get_checkpoint_by_path (self, info->path); - if (!checkpoint) { - /* this is really problematic. The async request returned, but - * we don't yet have a visible (fully initialized) NMCheckpoint instance - * to return. Wait longer for it to appear. However, it's ugly. */ - return; - } - - checkpoint_info_complete (self, info, checkpoint, NULL); -} - -void -nm_manager_checkpoint_create (NMManager *manager, - const GPtrArray *devices, - guint32 rollback_timeout, - NMCheckpointCreateFlags flags, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - gs_free const char **paths = NULL; - CheckpointInfo *info; - - g_return_if_fail (NM_IS_MANAGER (manager)); - - info = g_slice_new0 (CheckpointInfo); - info->manager = manager; - info->simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data, - nm_manager_checkpoint_create); - if (cancellable) - g_simple_async_result_set_check_cancellable (info->simple, cancellable); - paths = get_device_paths (devices); - nmdbus_manager_call_checkpoint_create (NM_MANAGER_GET_PRIVATE (manager)->proxy, - paths, - rollback_timeout, - flags, - cancellable, - checkpoint_created_cb, - info); - priv->added_checkpoints = g_slist_append (priv->added_checkpoints, info); -} - -NMCheckpoint * -nm_manager_checkpoint_create_finish (NMManager *manager, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (NM_IS_MANAGER (manager), NULL); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return NULL; - else - return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); -} - -static void -checkpoint_destroy_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nmdbus_manager_call_checkpoint_destroy_finish (NMDBUS_MANAGER (object), - result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - g_simple_async_result_complete (simple); - g_object_unref (simple); -} - -void -nm_manager_checkpoint_destroy (NMManager *manager, - const char *checkpoint_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - - g_return_if_fail (NM_IS_MANAGER (manager)); - g_return_if_fail (checkpoint_path && checkpoint_path[0] == '/'); - - simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data, - nm_manager_checkpoint_destroy); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nmdbus_manager_call_checkpoint_destroy (NM_MANAGER_GET_PRIVATE (manager)->proxy, - checkpoint_path, - cancellable, - checkpoint_destroy_cb, simple); -} - -gboolean -nm_manager_checkpoint_destroy_finish (NMManager *manager, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), - nm_manager_checkpoint_destroy), - FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); -} - -static void -checkpoint_rollback_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - GVariant *variant = NULL; - GVariantIter iter; - GHashTable *hash; - const char *path; - guint r; - - if (nmdbus_manager_call_checkpoint_rollback_finish (NMDBUS_MANAGER (object), - &variant, - result, - &error)) { - hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, NULL); - g_variant_iter_init (&iter, variant); - while (g_variant_iter_next (&iter, "{&su}", &path, &r)) - g_hash_table_insert (hash, g_strdup (path), GUINT_TO_POINTER (r)); - g_simple_async_result_set_op_res_gpointer (simple, hash, (GDestroyNotify) g_hash_table_unref); - } else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - g_simple_async_result_complete (simple); - g_object_unref (simple); -} - -void -nm_manager_checkpoint_rollback (NMManager *manager, - const char *checkpoint_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - - g_return_if_fail (NM_IS_MANAGER (manager)); - g_return_if_fail (checkpoint_path && checkpoint_path[0] == '/'); - - simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data, - nm_manager_checkpoint_rollback); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nmdbus_manager_call_checkpoint_rollback (NM_MANAGER_GET_PRIVATE (manager)->proxy, - checkpoint_path, - cancellable, - checkpoint_rollback_cb, simple); -} - -GHashTable * -nm_manager_checkpoint_rollback_finish (NMManager *manager, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), - nm_manager_checkpoint_rollback), - NULL); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return NULL; - else - return g_hash_table_ref (g_simple_async_result_get_op_res_gpointer (simple)); -} - -static void -checkpoint_adjust_rollback_timeout_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - gs_unref_object GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nmdbus_manager_call_checkpoint_adjust_rollback_timeout_finish (NMDBUS_MANAGER (object), - result, - &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - g_simple_async_result_complete (simple); -} - -void -nm_manager_checkpoint_adjust_rollback_timeout (NMManager *manager, - const char *checkpoint_path, - guint32 add_timeout, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - - g_return_if_fail (NM_IS_MANAGER (manager)); - g_return_if_fail (checkpoint_path && checkpoint_path[0] == '/'); - - simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data, - nm_manager_checkpoint_adjust_rollback_timeout); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nmdbus_manager_call_checkpoint_adjust_rollback_timeout (NM_MANAGER_GET_PRIVATE (manager)->proxy, - checkpoint_path, - add_timeout, - cancellable, - checkpoint_adjust_rollback_timeout_cb, - simple); -} - -gboolean -nm_manager_checkpoint_adjust_rollback_timeout_finish (NMManager *manager, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), - nm_manager_checkpoint_adjust_rollback_timeout), - FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - return !g_simple_async_result_propagate_error (simple, error); -} - -/*****************************************************************************/ - -static void -constructed (GObject *object) -{ - G_OBJECT_CLASS (nm_manager_parent_class)->constructed (object); - - g_signal_connect (object, "notify::" NM_MANAGER_WIRELESS_ENABLED, - G_CALLBACK (wireless_enabled_cb), NULL); -} - -static gboolean -init_sync (GInitable *initable, GCancellable *cancellable, GError **error) -{ - NMManager *manager = NM_MANAGER (initable); - GError *local_error = NULL; - - if (!nm_manager_parent_initable_iface->init (initable, cancellable, error)) { - /* Never happens. */ - g_return_val_if_reached (FALSE); - } - - if (!get_permissions_sync (manager, &local_error)) { - g_warning ("Unable to get permissions: %s\n", local_error->message); - g_error_free (local_error); - } - - return TRUE; -} - -typedef struct { - NMManager *manager; - GCancellable *cancellable; - GSimpleAsyncResult *result; -} NMManagerInitData; - -static void -init_async_complete (NMManagerInitData *init_data) -{ - g_simple_async_result_complete (init_data->result); - g_object_unref (init_data->result); - g_clear_object (&init_data->cancellable); - g_slice_free (NMManagerInitData, init_data); -} - -static void -init_async_got_permissions (GObject *object, GAsyncResult *result, gpointer user_data) -{ - NMManager *manager = user_data; - GVariant *permissions; - - if (nmdbus_manager_call_get_permissions_finish (NMDBUS_MANAGER (object), - &permissions, - result, NULL)) { - update_permissions (manager, permissions); - g_variant_unref (permissions); - } else - update_permissions (manager, NULL); - - g_object_unref (manager); -} - -static void -init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_data) -{ - NMManagerInitData *init_data = user_data; - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (init_data->manager); - GError *error = NULL; - - if (!nm_manager_parent_async_initable_iface->init_finish (G_ASYNC_INITABLE (source), result, &error)) { - g_simple_async_result_take_error (init_data->result, error); - init_async_complete (init_data); - return; - } - - nmdbus_manager_call_get_permissions (priv->proxy, - init_data->cancellable, - init_async_got_permissions, - g_object_ref (init_data->manager)); - - init_async_complete (init_data); -} - -static void -init_async (GAsyncInitable *initable, int io_priority, - GCancellable *cancellable, GAsyncReadyCallback callback, - gpointer user_data) -{ - NMManagerInitData *init_data; - - init_data = g_slice_new0 (NMManagerInitData); - init_data->manager = NM_MANAGER (initable); - init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback, - user_data, init_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (init_data->result, cancellable); - g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE); - - nm_manager_parent_async_initable_iface->init_async (initable, io_priority, cancellable, - init_async_parent_inited, init_data); -} - -static gboolean -init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error) -{ - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return TRUE; -} - -static void -dispose (GObject *object) -{ - NMManager *manager = NM_MANAGER (object); - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (object); - - nm_clear_g_cancellable (&priv->perm_call_cancellable); - - if (priv->devices) { - g_ptr_array_unref (priv->devices); - priv->devices = NULL; - } - if (priv->all_devices) { - g_ptr_array_unref (priv->all_devices); - priv->all_devices = NULL; - } - - nm_clear_pointer (&priv->checkpoints, g_ptr_array_unref); - - free_active_connections (manager); - g_clear_object (&priv->primary_connection); - g_clear_object (&priv->activating_connection); - - g_clear_object (&priv->proxy); - - /* Each activation should hold a ref on @manager, so if we're being disposed, - * there shouldn't be any pending. - */ - g_warn_if_fail (c_list_is_empty (&priv->pending_activations)); - - g_hash_table_destroy (priv->permissions); - priv->permissions = NULL; - - G_OBJECT_CLASS (nm_manager_parent_class)->dispose (object); -} - -static void -finalize (GObject *object) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (object); - - g_free (priv->version); - - G_OBJECT_CLASS (nm_manager_parent_class)->finalize (object); -} - -static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (object); - gboolean b; - - switch (prop_id) { - case PROP_NETWORKING_ENABLED: - b = g_value_get_boolean (value); - if (priv->networking_enabled != b) { - nm_manager_networking_set_enabled (NM_MANAGER (object), b, NULL); - /* Let the property value flip when we get the change signal from NM */ - } - break; - case PROP_WIRELESS_ENABLED: - b = g_value_get_boolean (value); - if (priv->wireless_enabled != b) { - nm_manager_wireless_set_enabled (NM_MANAGER (object), b); - /* Let the property value flip when we get the change signal from NM */ - } - break; - case PROP_WWAN_ENABLED: - b = g_value_get_boolean (value); - if (priv->wwan_enabled != b) { - nm_manager_wwan_set_enabled (NM_MANAGER (object), b); - /* Let the property value flip when we get the change signal from NM */ - } - break; - case PROP_WIMAX_ENABLED: - b = g_value_get_boolean (value); - if (priv->wimax_enabled != b) { - nm_manager_wimax_set_enabled (NM_MANAGER (object), b); - /* Let the property value flip when we get the change signal from NM */ - } - break; - case PROP_CONNECTIVITY_CHECK_ENABLED: - b = g_value_get_boolean (value); - if (priv->connectivity_check_enabled != b) { - nm_manager_connectivity_check_set_enabled (NM_MANAGER (object), b); - /* Let the property value flip when we get the change signal from NM */ - } - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - NMManager *self = NM_MANAGER (object); - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - - switch (prop_id) { - case PROP_VERSION: - g_value_set_string (value, nm_manager_get_version (self)); - break; - case PROP_STATE: - g_value_set_enum (value, nm_manager_get_state (self)); - break; - case PROP_STARTUP: - g_value_set_boolean (value, nm_manager_get_startup (self)); - break; - case PROP_NETWORKING_ENABLED: - g_value_set_boolean (value, nm_manager_networking_get_enabled (self)); - break; - case PROP_WIRELESS_ENABLED: - g_value_set_boolean (value, priv->wireless_enabled); - break; - case PROP_WIRELESS_HARDWARE_ENABLED: - g_value_set_boolean (value, priv->wireless_hw_enabled); - break; - case PROP_WWAN_ENABLED: - g_value_set_boolean (value, priv->wwan_enabled); - break; - case PROP_WWAN_HARDWARE_ENABLED: - g_value_set_boolean (value, priv->wwan_hw_enabled); - break; - case PROP_WIMAX_ENABLED: - g_value_set_boolean (value, priv->wimax_enabled); - break; - case PROP_WIMAX_HARDWARE_ENABLED: - g_value_set_boolean (value, priv->wimax_hw_enabled); - break; - case PROP_ACTIVE_CONNECTIONS: - g_value_take_boxed (value, _nm_utils_copy_object_array (nm_manager_get_active_connections (self))); - break; - case PROP_CONNECTIVITY: - g_value_set_enum (value, priv->connectivity); - break; - case PROP_CONNECTIVITY_CHECK_AVAILABLE: - g_value_set_boolean (value, priv->connectivity_check_available); - break; - case PROP_CONNECTIVITY_CHECK_ENABLED: - g_value_set_boolean (value, priv->connectivity_check_enabled); - break; - case PROP_PRIMARY_CONNECTION: - g_value_set_object (value, priv->primary_connection); - break; - case PROP_ACTIVATING_CONNECTION: - g_value_set_object (value, priv->activating_connection); - break; - case PROP_DEVICES: - g_value_take_boxed (value, _nm_utils_copy_object_array (nm_manager_get_devices (self))); - break; - case PROP_CHECKPOINTS: - g_value_take_boxed (value, _nm_utils_copy_object_array (nm_manager_get_checkpoints (self))); - break; - case PROP_METERED: - g_value_set_uint (value, priv->metered); - break; - case PROP_ALL_DEVICES: - g_value_take_boxed (value, _nm_utils_copy_object_array (nm_manager_get_all_devices (self))); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -nm_manager_class_init (NMManagerClass *manager_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (manager_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (manager_class); - - g_type_class_add_private (manager_class, sizeof (NMManagerPrivate)); - - /* virtual methods */ - object_class->constructed = constructed; - object_class->set_property = set_property; - object_class->get_property = get_property; - object_class->dispose = dispose; - object_class->finalize = finalize; - - nm_object_class->init_dbus = init_dbus; - nm_object_class->object_creation_failed = object_creation_failed; - - manager_class->device_added = device_added; - manager_class->device_removed = device_removed; - manager_class->active_connection_added = active_connection_added; - manager_class->active_connection_removed = active_connection_removed; - manager_class->checkpoint_added = checkpoint_added; - - /* properties */ - - g_object_class_install_property - (object_class, PROP_VERSION, - g_param_spec_string (NM_MANAGER_VERSION, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_STATE, - g_param_spec_enum (NM_CLIENT_STATE, "", "", - NM_TYPE_STATE, - NM_STATE_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_STARTUP, - g_param_spec_boolean (NM_MANAGER_STARTUP, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_NETWORKING_ENABLED, - g_param_spec_boolean (NM_MANAGER_NETWORKING_ENABLED, "", "", - TRUE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_WIRELESS_ENABLED, - g_param_spec_boolean (NM_MANAGER_WIRELESS_ENABLED, "", "", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_WIRELESS_HARDWARE_ENABLED, - g_param_spec_boolean (NM_MANAGER_WIRELESS_HARDWARE_ENABLED, "", "", - TRUE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_WWAN_ENABLED, - g_param_spec_boolean (NM_MANAGER_WWAN_ENABLED, "", "", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_WWAN_HARDWARE_ENABLED, - g_param_spec_boolean (NM_MANAGER_WWAN_HARDWARE_ENABLED, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_WIMAX_ENABLED, - g_param_spec_boolean (NM_MANAGER_WIMAX_ENABLED, "", "", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_WIMAX_HARDWARE_ENABLED, - g_param_spec_boolean (NM_MANAGER_WIMAX_HARDWARE_ENABLED, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_ACTIVE_CONNECTIONS, - g_param_spec_boxed (NM_MANAGER_ACTIVE_CONNECTIONS, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_CONNECTIVITY, - g_param_spec_enum (NM_CLIENT_CONNECTIVITY, "", "", - NM_TYPE_CONNECTIVITY_STATE, - NM_CONNECTIVITY_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_CONNECTIVITY_CHECK_AVAILABLE, - g_param_spec_boolean (NM_MANAGER_CONNECTIVITY_CHECK_AVAILABLE, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_CONNECTIVITY_CHECK_ENABLED, - g_param_spec_boolean (NM_MANAGER_CONNECTIVITY_CHECK_ENABLED, "", "", - FALSE, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_PRIMARY_CONNECTION, - g_param_spec_object (NM_MANAGER_PRIMARY_CONNECTION, "", "", - NM_TYPE_ACTIVE_CONNECTION, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_ACTIVATING_CONNECTION, - g_param_spec_object (NM_MANAGER_ACTIVATING_CONNECTION, "", "", - NM_TYPE_ACTIVE_CONNECTION, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_DEVICES, - g_param_spec_boxed (NM_MANAGER_DEVICES, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - g_object_class_install_property - (object_class, PROP_CHECKPOINTS, - g_param_spec_boxed (NM_MANAGER_CHECKPOINTS, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - /** - * NMManager:metered: - * - * Whether the connectivity is metered. - * - * Since: 1.2 - **/ - g_object_class_install_property - (object_class, PROP_METERED, - g_param_spec_uint (NM_MANAGER_METERED, "", "", - 0, G_MAXUINT32, NM_METERED_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_ALL_DEVICES, - g_param_spec_boxed (NM_MANAGER_ALL_DEVICES, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - /* signals */ - - signals[DEVICE_ADDED] = - g_signal_new ("device-added", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMManagerClass, device_added), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); - signals[DEVICE_REMOVED] = - g_signal_new ("device-removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMManagerClass, device_removed), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); - signals[ANY_DEVICE_ADDED] = - g_signal_new ("any-device-added", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); - signals[ANY_DEVICE_REMOVED] = - g_signal_new ("any-device-removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); - signals[ACTIVE_CONNECTION_ADDED] = - g_signal_new ("active-connection-added", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMManagerClass, active_connection_added), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); - signals[ACTIVE_CONNECTION_REMOVED] = - g_signal_new ("active-connection-removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMManagerClass, active_connection_removed), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); - signals[CHECKPOINT_ADDED] = - g_signal_new ("checkpoint-added", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMManagerClass, checkpoint_added), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); - signals[CHECKPOINT_REMOVED] = - g_signal_new ("checkpoint-removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMManagerClass, checkpoint_removed), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); - - signals[PERMISSION_CHANGED] = - g_signal_new ("permission-changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); -} - -static void -nm_manager_initable_iface_init (GInitableIface *iface) -{ - nm_manager_parent_initable_iface = g_type_interface_peek_parent (iface); - - iface->init = init_sync; -} - -static void -nm_manager_async_initable_iface_init (GAsyncInitableIface *iface) -{ - nm_manager_parent_async_initable_iface = g_type_interface_peek_parent (iface); - - iface->init_async = init_async; - iface->init_finish = init_finish; -} diff --git a/libnm/nm-manager.h b/libnm/nm-manager.h deleted file mode 100644 index 23f09016..00000000 --- a/libnm/nm-manager.h +++ /dev/null @@ -1,241 +0,0 @@ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2014 Red Hat, Inc. - */ - -#ifndef __NM_MANAGER_H__ -#define __NM_MANAGER_H__ - -#if !((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE) -#error Cannot use this header. -#endif - -#include "nm-object.h" -#include "nm-client.h" - -#define NM_TYPE_MANAGER (nm_manager_get_type ()) -#define NM_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MANAGER, NMManager)) -#define NM_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_MANAGER, NMManagerClass)) -#define NM_IS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_MANAGER)) -#define NM_IS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MANAGER)) -#define NM_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MANAGER, NMManagerClass)) - -#define NM_MANAGER_VERSION "version" -#define NM_MANAGER_STATE "state" -#define NM_MANAGER_STARTUP "startup" -#define NM_MANAGER_NETWORKING_ENABLED "networking-enabled" -#define NM_MANAGER_WIRELESS_ENABLED "wireless-enabled" -#define NM_MANAGER_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled" -#define NM_MANAGER_WWAN_ENABLED "wwan-enabled" -#define NM_MANAGER_WWAN_HARDWARE_ENABLED "wwan-hardware-enabled" -#define NM_MANAGER_WIMAX_ENABLED "wimax-enabled" -#define NM_MANAGER_WIMAX_HARDWARE_ENABLED "wimax-hardware-enabled" -#define NM_MANAGER_ACTIVE_CONNECTIONS "active-connections" -#define NM_MANAGER_CONNECTIVITY "connectivity" -#define NM_MANAGER_CONNECTIVITY_CHECK_AVAILABLE "connectivity-check-available" -#define NM_MANAGER_CONNECTIVITY_CHECK_ENABLED "connectivity-check-enabled" -#define NM_MANAGER_PRIMARY_CONNECTION "primary-connection" -#define NM_MANAGER_ACTIVATING_CONNECTION "activating-connection" -#define NM_MANAGER_DEVICES "devices" -#define NM_MANAGER_CHECKPOINTS "checkpoints" -#define NM_MANAGER_METERED "metered" -#define NM_MANAGER_ALL_DEVICES "all-devices" - -/** - * NMManager: - */ -typedef struct { - NMObject parent; -} NMManager; - -typedef struct { - NMObjectClass parent; - - /* Signals */ - void (*device_added) (NMManager *manager, NMDevice *device); - void (*device_removed) (NMManager *manager, NMDevice *device); - void (*active_connection_added) (NMManager *manager, NMActiveConnection *ac); - void (*active_connection_removed) (NMManager *manager, NMActiveConnection *ac); - void (*checkpoint_added) (NMManager *manager, NMCheckpoint *checkpoint); - void (*checkpoint_removed) (NMManager *manager, NMCheckpoint *checkpoint); - void (*permission_changed) (NMManager *manager, - NMClientPermission permission, - NMClientPermissionResult result); -} NMManagerClass; - -GType nm_manager_get_type (void); - -const char *nm_manager_get_version (NMManager *manager); -NMState nm_manager_get_state (NMManager *manager); -gboolean nm_manager_get_startup (NMManager *manager); - -gboolean nm_manager_networking_get_enabled (NMManager *manager); -gboolean nm_manager_networking_set_enabled (NMManager *manager, - gboolean enabled, - GError **error); - -gboolean nm_manager_wireless_get_enabled (NMManager *manager); -void nm_manager_wireless_set_enabled (NMManager *manager, gboolean enabled); -gboolean nm_manager_wireless_hardware_get_enabled (NMManager *manager); - -gboolean nm_manager_wwan_get_enabled (NMManager *manager); -void nm_manager_wwan_set_enabled (NMManager *manager, gboolean enabled); -gboolean nm_manager_wwan_hardware_get_enabled (NMManager *manager); - -gboolean nm_manager_wimax_get_enabled (NMManager *manager); -void nm_manager_wimax_set_enabled (NMManager *manager, gboolean enabled); -gboolean nm_manager_wimax_hardware_get_enabled (NMManager *manager); - -gboolean nm_manager_connectivity_check_get_available (NMManager *manager); - -gboolean nm_manager_connectivity_check_get_enabled (NMManager *manager); - -void nm_manager_connectivity_check_set_enabled (NMManager *manager, - gboolean enabled); - -const char *nm_manager_connectivity_check_get_uri (NMManager *manager); - -gboolean nm_manager_get_logging (NMManager *manager, - char **level, - char **domains, - GError **error); -gboolean nm_manager_set_logging (NMManager *manager, - const char *level, - const char *domains, - GError **error); - -NMClientPermissionResult nm_manager_get_permission_result (NMManager *manager, - NMClientPermission permission); - -NMConnectivityState nm_manager_get_connectivity (NMManager *manager); - -NMConnectivityState nm_manager_check_connectivity (NMManager *manager, - GCancellable *cancellable, - GError **error); -void nm_manager_check_connectivity_async (NMManager *manager, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -NMConnectivityState nm_manager_check_connectivity_finish (NMManager *manager, - GAsyncResult *result, - GError **error); - -/* Devices */ - -const GPtrArray *nm_manager_get_devices (NMManager *manager); -const GPtrArray *nm_manager_get_all_devices(NMManager *manager); -NMDevice *nm_manager_get_device_by_path (NMManager *manager, const char *object_path); -NMDevice *nm_manager_get_device_by_iface (NMManager *manager, const char *iface); - -/* Active Connections */ - -const GPtrArray *nm_manager_get_active_connections (NMManager *manager); - -NMActiveConnection *nm_manager_get_primary_connection (NMManager *manager); -NMActiveConnection *nm_manager_get_activating_connection (NMManager *manager); - -void nm_manager_activate_connection_async (NMManager *manager, - NMConnection *connection, - NMDevice *device, - const char *specific_object, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -NMActiveConnection *nm_manager_activate_connection_finish (NMManager *manager, - GAsyncResult *result, - GError **error); - -void nm_manager_add_and_activate_connection_async (NMManager *manager, - NMConnection *partial, - NMDevice *device, - const char *specific_object, - GVariant *options, - gboolean force_v2, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -NMActiveConnection *nm_manager_add_and_activate_connection_finish (NMManager *manager, - GAsyncResult *result, - GVariant **out_result, - GError **error); - -gboolean nm_manager_deactivate_connection (NMManager *manager, - NMActiveConnection *active, - GCancellable *cancellable, - GError **error); -void nm_manager_deactivate_connection_async (NMManager *manager, - NMActiveConnection *active, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean nm_manager_deactivate_connection_finish (NMManager *manager, - GAsyncResult *result, - GError **error); - -const GPtrArray *nm_manager_get_checkpoints (NMManager *manager); -void nm_manager_checkpoint_create (NMManager *manager, - const GPtrArray *devices, - guint32 rollback_timeout, - NMCheckpointCreateFlags flags, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -NMCheckpoint *nm_manager_checkpoint_create_finish (NMManager *manager, - GAsyncResult *result, - GError **error); -void nm_manager_checkpoint_destroy (NMManager *manager, - const char *checkpoint_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean nm_manager_checkpoint_destroy_finish (NMManager *manager, - GAsyncResult *result, - GError **error); -void nm_manager_checkpoint_rollback (NMManager *manager, - const char *checkpoint_path, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -GHashTable *nm_manager_checkpoint_rollback_finish (NMManager *manager, - GAsyncResult *result, - GError **error); -void nm_manager_checkpoint_adjust_rollback_timeout (NMManager *manager, - const char *checkpoint_path, - guint32 add_timeout, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean nm_manager_checkpoint_adjust_rollback_timeout_finish (NMManager *manager, - GAsyncResult *result, - GError **error); - -/*****************************************************************************/ - -typedef struct { - NMActiveConnection *active; - GVariant *add_and_activate_output; -} _NMActivateResult; - -_NMActivateResult *_nm_activate_result_new (NMActiveConnection *active, - GVariant *add_and_activate_output); - -void _nm_activate_result_free (_NMActivateResult *result); - -/*****************************************************************************/ - -#endif /* __NM_MANAGER_H__ */ diff --git a/libnm/nm-object-private.h b/libnm/nm-object-private.h index fc4bba60..56532950 100644 --- a/libnm/nm-object-private.h +++ b/libnm/nm-object-private.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2008 - 2011 Red Hat, Inc. + * Copyright (C) 2008 - 2011 Red Hat, Inc. */ #ifndef __NM_OBJECT_PRIVATE_H__ @@ -26,40 +12,4 @@ #include "nm-object.h" -typedef gboolean (*PropertyMarshalFunc) (NMObject *, GParamSpec *, GVariant *, gpointer); - -typedef GObject * (*NMObjectCreatorFunc) (GDBusConnection *, const char *); - -typedef struct { - const char *name; - gpointer field; - PropertyMarshalFunc func; - GType object_type; - const char *signal_prefix; -} NMPropertiesInfo; - -void _nm_object_register_properties (NMObject *object, - const char *interface, - const NMPropertiesInfo *info); - -void _nm_object_queue_notify (NMObject *object, const char *property); - -GDBusObjectManager *_nm_object_get_dbus_object_manager (NMObject *object); - -GQuark _nm_object_obj_nm_quark (void); - -/* DBus property accessors */ - -void _nm_object_set_property (NMObject *object, - const char *interface, - const char *prop_name, - const char *format_string, - ...); - -GDBusProxy *_nm_object_get_proxy (NMObject *object, - const char *interface); - -struct udev; -void _nm_device_set_udev (NMDevice *device, struct udev *udev); - #endif /* __NM_OBJECT_PRIVATE_H__ */ diff --git a/libnm/nm-object.c b/libnm/nm-object.c index 55c3af4f..89dc8bb3 100644 --- a/libnm/nm-object.c +++ b/libnm/nm-object.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2012 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2012 Red Hat, Inc. */ #include "nm-default.h" @@ -33,68 +19,56 @@ #include "nm-core-internal.h" #include "c-list/src/c-list.h" -static gboolean debug = FALSE; -#define dbgmsg(f,...) if (G_UNLIKELY (debug)) { g_message (f, ## __VA_ARGS__ ); } - -NM_CACHED_QUARK_FCN ("nm-obj-nm", _nm_object_obj_nm_quark) - -static void nm_object_initable_iface_init (GInitableIface *iface); -static void nm_object_async_initable_iface_init (GAsyncInitableIface *iface); - -typedef struct { - GSList *interfaces; -} NMObjectClassPrivate; - -#define NM_OBJECT_CLASS_GET_PRIVATE(k) (G_TYPE_CLASS_GET_PRIVATE ((k), NM_TYPE_OBJECT, NMObjectClassPrivate)) +/*****************************************************************************/ -G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMObject, nm_object, G_TYPE_OBJECT, - g_type_add_class_private (g_define_type_id, sizeof (NMObjectClassPrivate)); - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_object_initable_iface_init); - G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_object_async_initable_iface_init); - ) +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_PATH, +); -#define NM_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_OBJECT, NMObjectPrivate)) +typedef struct _NMObjectPrivate { + NMClient *client; + NMLDBusObject *dbobj; +} NMObjectPrivate; -typedef struct { - PropertyMarshalFunc func; - GType object_type; - gpointer field; - const char *signal_prefix; -} PropertyInfo; +G_DEFINE_ABSTRACT_TYPE (NMObject, nm_object, G_TYPE_OBJECT); -static void reload_complete (NMObject *object, gboolean emit_now); -static gboolean demarshal_generic (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field); +#define NM_OBJECT_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMObject, NM_IS_OBJECT) -typedef struct { - GDBusObject *object; - GDBusObjectManager *object_manager; +static NMObjectClass *_nm_object_class = NULL; - GSList *property_tables; - NMObject *parent; +/*****************************************************************************/ - gboolean inited; /* async init finished? */ - GSList *waiters; /* if async init did not finish, users of this object need - * to defer their notifications by adding themselves here. */ +static gpointer +_nm_object_get_private (NMObjectClass *klass, NMObject *self, guint16 extra_offset) +{ + char *ptr; - CList notify_items; - guint notify_id; + nm_assert (klass->priv_ptr_offset > 0); - guint reload_remaining; + ptr = (char *) self; + ptr += klass->priv_ptr_offset; + if (klass->priv_ptr_indirect) + ptr = *((gpointer *) ptr); + return ptr + extra_offset; +} - CList pending; /* ordered list of pending property updates. */ - GPtrArray *proxies; -} NMObjectPrivate; +NMLDBusObject * +_nm_object_get_dbobj (gpointer self) +{ + return NM_OBJECT_GET_PRIVATE (self)->dbobj; +} -enum { - PROP_0, - PROP_PATH, - PROP_DBUS_CONNECTION, - PROP_NM_RUNNING, - PROP_DBUS_OBJECT, - PROP_DBUS_OBJECT_MANAGER, +const char * +_nm_object_get_path (gpointer self) +{ + return NM_OBJECT_GET_PRIVATE (self)->dbobj->dbus_path->str; +} - LAST_PROP -}; +NMClient * +_nm_object_get_client (gpointer self) +{ + return NM_OBJECT_GET_PRIVATE (self)->client; +} /** * nm_object_get_path: @@ -110,568 +84,61 @@ nm_object_get_path (NMObject *object) { g_return_val_if_fail (NM_IS_OBJECT (object), NULL); - return g_dbus_object_get_object_path (NM_OBJECT_GET_PRIVATE (object)->object); -} - -/** - * _nm_object_get_proxy: - * @object: an #NMObject - * @interface: a D-Bus interface implemented by @object - * - * Gets the D-Bus proxy for @interface on @object. - * - * Returns: (transfer none): a D-Bus proxy - */ -GDBusProxy * -_nm_object_get_proxy (NMObject *object, - const char *interface) -{ - NMObjectPrivate *priv; - GDBusInterface *proxy; - - g_return_val_if_fail (NM_IS_OBJECT (object), NULL); - - priv = NM_OBJECT_GET_PRIVATE (object); - if (priv->object == NULL) - return NULL; - - proxy = g_dbus_object_get_interface (priv->object, interface); - g_return_val_if_fail (proxy != NULL, NULL); - - return G_DBUS_PROXY (proxy); -} - -typedef enum { - NOTIFY_SIGNAL_PENDING_NONE, - NOTIFY_SIGNAL_PENDING_ADDED, - NOTIFY_SIGNAL_PENDING_REMOVED, - NOTIFY_SIGNAL_PENDING_ADDED_REMOVED, -} NotifySignalPending; - -typedef struct { - CList lst; - const char *property; - const char *signal_prefix; - NotifySignalPending pending; - NMObject *changed; -} NotifyItem; - -static void -notify_item_free (NotifyItem *item) -{ - c_list_unlink_stale (&item->lst); - g_clear_object (&item->changed); - g_slice_free (NotifyItem, item); -} - -static gboolean -deferred_notify_cb (gpointer data) -{ - NMObject *object = NM_OBJECT (data); - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - NMObjectClass *object_class = NM_OBJECT_GET_CLASS (object); - CList props; - CList *iter, *safe; - - priv->notify_id = 0; - - /* Wait until all reloads are done before notifying */ - if (priv->reload_remaining) - return G_SOURCE_REMOVE; - - /* Clear priv->notify_items early so that an NMObject subclass that - * listens to property changes can queue up other property changes - * during the g_object_notify() call separately from the property - * list we're iterating. - */ - c_list_link_after (&priv->notify_items, &props); - c_list_unlink (&priv->notify_items); - - g_object_ref (object); - - /* Emit added/removed signals first since some of our internal objects - * use the added/removed signals for new object processing. - */ - c_list_for_each (iter, &props) { - NotifyItem *item = c_list_entry (iter, NotifyItem, lst); - char buf[50]; - int ret = 0; - - switch (item->pending) { - case NOTIFY_SIGNAL_PENDING_ADDED: - ret = g_snprintf (buf, sizeof (buf), "%s-added", item->signal_prefix); - break; - case NOTIFY_SIGNAL_PENDING_REMOVED: - ret = g_snprintf (buf, sizeof (buf), "%s-removed", item->signal_prefix); - break; - case NOTIFY_SIGNAL_PENDING_ADDED_REMOVED: - if (object_class->object_creation_failed) - object_class->object_creation_failed (object, nm_object_get_path (item->changed)); - break; - case NOTIFY_SIGNAL_PENDING_NONE: - default: - break; - } - if (ret > 0) { - g_assert (ret < sizeof (buf)); - g_signal_emit_by_name (object, buf, item->changed); - } - } - - /* Emit property change notifications second */ - c_list_for_each (iter, &props) { - NotifyItem *item = c_list_entry (iter, NotifyItem, lst); - - if (item->property) - g_object_notify (G_OBJECT (object), item->property); - } - - g_object_unref (object); - - c_list_for_each_safe (iter, safe, &props) - notify_item_free (c_list_entry (iter, NotifyItem, lst)); - - return G_SOURCE_REMOVE; -} - -static void -_nm_object_defer_notify (NMObject *object) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - - if (!priv->notify_id) - priv->notify_id = g_idle_add_full (G_PRIORITY_LOW, deferred_notify_cb, object, NULL); -} - -static void -_nm_object_queue_notify_full (NMObject *object, - const char *property, - const char *signal_prefix, - gboolean added, - NMObject *changed) -{ - NMObjectPrivate *priv; - NotifyItem *item; - CList *iter; - - g_return_if_fail (NM_IS_OBJECT (object)); - g_return_if_fail (!signal_prefix != !property); - g_return_if_fail (!signal_prefix == !changed); - - priv = NM_OBJECT_GET_PRIVATE (object); - _nm_object_defer_notify (object); - - property = g_intern_string (property); - signal_prefix = g_intern_string (signal_prefix); - c_list_for_each (iter, &priv->notify_items) { - item = c_list_entry (iter, NotifyItem, lst); - - if (property && (property == item->property)) - return; - - /* Collapse signals for the same object (such as "added->removed") to - * ensure we don't emit signals when their sum should have no effect. - * The "added->removed->removed" sequence requires special handling, - * hence the addition of the ADDED_REMOVED state to ensure that no - * signal is emitted in this case: - * - * Without the ADDED_REMOVED state: - * NONE + added -> ADDED - * ADDED + removed -> NONE - * NONE + removed -> REMOVED (would emit 'removed' signal) - * - * With the ADDED_REMOVED state: - * NONE | ADDED_REMOVED + added -> ADDED - * ADDED + removed -> ADDED_REMOVED - * ADDED_REMOVED + removed -> ADDED_REMOVED (emits no signal) - */ - if (signal_prefix && (changed == item->changed) && (item->signal_prefix == signal_prefix)) { - switch (item->pending) { - case NOTIFY_SIGNAL_PENDING_ADDED: - if (!added) - item->pending = NOTIFY_SIGNAL_PENDING_ADDED_REMOVED; - break; - case NOTIFY_SIGNAL_PENDING_REMOVED: - if (added) - item->pending = NOTIFY_SIGNAL_PENDING_NONE; - break; - case NOTIFY_SIGNAL_PENDING_ADDED_REMOVED: - if (added) - item->pending = NOTIFY_SIGNAL_PENDING_ADDED; - break; - case NOTIFY_SIGNAL_PENDING_NONE: - item->pending = added ? NOTIFY_SIGNAL_PENDING_ADDED : NOTIFY_SIGNAL_PENDING_REMOVED; - break; - default: - g_assert_not_reached (); - } - return; - } - } - - item = g_slice_new0 (NotifyItem); - item->property = property; - if (signal_prefix) { - item->signal_prefix = signal_prefix; - item->pending = added ? NOTIFY_SIGNAL_PENDING_ADDED : NOTIFY_SIGNAL_PENDING_REMOVED; - item->changed = changed ? g_object_ref (changed) : NULL; - } - c_list_link_tail (&priv->notify_items, &item->lst); -} - -void -_nm_object_queue_notify (NMObject *object, const char *property) -{ - _nm_object_queue_notify_full (object, property, NULL, FALSE, NULL); -} - -typedef struct { - CList lst_pending; - NMObject *self; - PropertyInfo *pi; - - GObject **objects; - int length, remaining; - - gboolean array; - const char *property_name; -} ObjectCreatedData; - -static void -odata_free (gpointer data) -{ - ObjectCreatedData *odata = data; - - c_list_unlink_stale (&odata->lst_pending); - g_object_unref (odata->self); - g_free (odata->objects); - g_slice_free (ObjectCreatedData, odata); + return NM_OBJECT_GET_PRIVATE (object)->dbobj->dbus_path->str; } -static void object_property_maybe_complete (NMObject *self); - -/* Stolen from dbus-glib */ -static char* -wincaps_to_dash (const char *caps) -{ - const char *p; - GString *str; - - str = g_string_new (NULL); - p = caps; - while (*p) { - if (g_ascii_isupper (*p)) { - if (str->len > 0 && (str->len < 2 || str->str[str->len-2] != '-')) - g_string_append_c (str, '-'); - g_string_append_c (str, g_ascii_tolower (*p)); - } else - g_string_append_c (str, *p); - ++p; - } - - return g_string_free (str, FALSE); -} +/*****************************************************************************/ -/* Adds object to array if it's not already there */ static void -add_to_object_array_unique (GPtrArray *array, GObject *obj) +clear_properties (NMObject *self, + NMClient *client) { - guint i; + NMObjectClass *klass = NM_OBJECT_GET_CLASS (self); + const _NMObjectClassFieldInfo *p; - g_return_if_fail (array != NULL); + nm_assert (NM_IS_OBJECT (self)); + nm_assert (!client || NM_IS_CLIENT (client)); - if (obj != NULL) { - for (i = 0; i < array->len; i++) { - if (g_ptr_array_index (array, i) == obj) { - g_object_unref (obj); - return; - } - } - g_ptr_array_add (array, obj); + for (p = klass->property_o_info; p; p = p->parent) { + nml_dbus_property_o_clear_many (_nm_object_get_private (p->klass, self, p->offset), + p->num, + client); } -} - -/* Places items from 'needles' that are not in 'haystack' into 'diff' */ -static void -array_diff (GPtrArray *needles, GPtrArray *haystack, GPtrArray *diff) -{ - guint i, j; - GObject *obj; - - g_assert (needles); - g_assert (haystack); - g_assert (diff); - - for (i = 0; i < needles->len; i++) { - obj = g_ptr_array_index (needles, i); - for (j = 0; j < haystack->len; j++) { - if (g_ptr_array_index (haystack, j) == obj) - break; - } - - if (j == haystack->len) - g_ptr_array_add (diff, obj); + for (p = klass->property_ao_info; p; p = p->parent) { + nml_dbus_property_ao_clear_many (_nm_object_get_private (p->klass, self, p->offset), + p->num, + client); } } -static void -queue_added_removed_signal (NMObject *self, - const char *signal_prefix, - NMObject *changed, - gboolean added) -{ - _nm_object_queue_notify_full (self, NULL, signal_prefix, added, changed); -} +/*****************************************************************************/ static gboolean -already_awaits (ObjectCreatedData *odata, GObject *object) +is_ready (NMObject *self) { - NMObject *self = odata->self; - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - GSList *iter; - - if ((GObject *)odata->self == object) - return TRUE; - - for (iter = priv->waiters; iter; iter = g_slist_next (iter)) { - if (already_awaits (iter->data, object)) - return TRUE; - } + NMObjectClass *klass = NM_OBJECT_GET_CLASS (self); + NMClient *client = _nm_object_get_client (self); + const _NMObjectClassFieldInfo *p; + guint16 i; - return FALSE; -} + nm_assert (NM_IS_CLIENT (client)); -static void -object_property_maybe_complete (NMObject *self) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - /* The odata may hold the last reference. */ - _nm_unused gs_unref_object NMObject *self_keep_alive = g_object_ref (self); - int i; - CList *iter, *safe; - - c_list_for_each_safe (iter, safe, &priv->pending) { - ObjectCreatedData *odata = c_list_entry (iter, ObjectCreatedData, lst_pending); - PropertyInfo *pi = odata->pi; - gboolean different = TRUE; - - if (odata->remaining > 0) - return; - - /* Only complete the array property load when all the objects are initialized. */ - for (i = 0; i < odata->length; i++) { - GObject *obj = odata->objects[i]; - NMObjectPrivate *obj_priv; - - /* Could not load the object. Perhaps it was removed. */ - if (!obj) - continue; - - obj_priv = NM_OBJECT_GET_PRIVATE (obj); - if (!obj_priv->inited) { - - /* The object is not finished because we block its creation. */ - if (already_awaits (odata, obj)) - continue; - - if (!g_slist_find (obj_priv->waiters, odata)) - obj_priv->waiters = g_slist_prepend (obj_priv->waiters, odata); - return; - } - } + for (p = klass->property_o_info; p; p = p->parent) { + NMLDBusPropertyO *fields = _nm_object_get_private (p->klass, self, p->offset); - if (odata->array) { - GPtrArray *old = *((GPtrArray **) pi->field); - GPtrArray *new; - - /* Build up new array */ - new = g_ptr_array_new_full (odata->length, g_object_unref); - for (i = 0; i < odata->length; i++) - add_to_object_array_unique (new, odata->objects[i]); - - *((GPtrArray **) pi->field) = new; - - if (pi->signal_prefix) { - GPtrArray *added = g_ptr_array_sized_new (3); - GPtrArray *removed = g_ptr_array_sized_new (3); - - if (old) { - /* Find objects in 'old' that do not exist in 'new' */ - array_diff (old, new, removed); - - /* Find objects in 'new' that do not exist in old */ - array_diff (new, old, added); - } else { - for (i = 0; i < new->len; i++) - g_ptr_array_add (added, g_ptr_array_index (new, i)); - } - - /* Emit added & removed */ - for (i = 0; i < removed->len; i++) { - queue_added_removed_signal (self, - pi->signal_prefix, - g_ptr_array_index (removed, i), - FALSE); - } - - for (i = 0; i < added->len; i++) { - queue_added_removed_signal (self, - pi->signal_prefix, - g_ptr_array_index (added, i), - TRUE); - } - - different = removed->len || added->len; - g_ptr_array_unref (added); - g_ptr_array_unref (removed); - } else { - /* No added/removed signals to send, just replace the property with - * the new values. - */ - different = TRUE; - } - - /* Free old array last since it will release references, thus freeing - * any objects in the 'removed' array. - */ - if (old) - g_ptr_array_unref (old); - } else { - GObject **obj_p = pi->field; - - different = (*obj_p != odata->objects[0]); - if (*obj_p) - g_object_unref (*obj_p); - *obj_p = odata->objects[0]; + for (i = 0; i < p->num; i++) { + if (!nml_dbus_property_o_is_ready (&fields[i])) + return FALSE; } - - if (different && odata->property_name) - _nm_object_queue_notify (self, odata->property_name); - - if (--priv->reload_remaining == 0) - reload_complete (self, TRUE); - - odata_free (odata); } -} - -static void -object_created (GObject *obj, const char *path, gpointer user_data) -{ - ObjectCreatedData *odata = user_data; - - /* We assume that on error, the creator_func printed something */ - - if (obj == NULL && g_strcmp0 (path, "/") != 0 ) { - NMObjectClass *object_class = NM_OBJECT_GET_CLASS (odata->self); - - if (object_class->object_creation_failed) - object_class->object_creation_failed (odata->self, path); - } - - odata->objects[odata->length - odata->remaining--] = obj ? g_object_ref (obj) : NULL; - object_property_maybe_complete (odata->self); -} - -static gboolean -handle_object_property (NMObject *self, const char *property_name, GVariant *value, - PropertyInfo *pi) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - gs_unref_object GDBusObject *object = NULL; - GObject *obj; - const char *path; - ObjectCreatedData *odata; - - odata = g_slice_new (ObjectCreatedData); - odata->self = g_object_ref (self); - odata->pi = pi; - odata->objects = g_new0 (GObject *, 1); - odata->length = odata->remaining = 1; - odata->array = FALSE; - odata->property_name = property_name; - - c_list_link_tail (&priv->pending, &odata->lst_pending); - - priv->reload_remaining++; - - path = g_variant_get_string (value, NULL); - if (!strcmp (path, "/")) { - object_created (NULL, path, odata); - return TRUE; - } - - object = g_dbus_object_manager_get_object (priv->object_manager, path); - if (!object) { - /* This is a server bug -- a dangling object path for an object - * that does not exist. - * - * NOTE: We've ignored this before and the server hits the condition - * more often that it should. Given we're able to recover from - * the error, let's lower the severity of the log message to - * avoid unnecessarily bothering the user. This can be removed - * once the issue is fixed on the server. */ -#if NM_MORE_ASSERTS -#define __nm_log_debug g_warning -#else -#define __nm_log_debug g_debug -#endif - __nm_log_debug ("No object known for %s", path); -#undef __nm_log_debug - return FALSE; - } - - obj = g_object_get_qdata (G_OBJECT (object), _nm_object_obj_nm_quark ()); - object_created (obj, path, odata); - - return TRUE; -} - -static gboolean -handle_object_array_property (NMObject *self, const char *property_name, GVariant *value, - PropertyInfo *pi) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - GObject *obj; - GVariantIter iter; - gsize npaths; - const char *path; - ObjectCreatedData *odata; - - npaths = g_variant_n_children (value); - - odata = g_slice_new (ObjectCreatedData); - odata->self = g_object_ref (self); - odata->pi = pi; - odata->objects = g_new0 (GObject *, npaths); - odata->length = odata->remaining = npaths; - odata->array = TRUE; - odata->property_name = property_name; - - c_list_link_tail (&priv->pending, &odata->lst_pending); + for (p = klass->property_ao_info; p; p = p->parent) { + NMLDBusPropertyAO *fields = _nm_object_get_private (p->klass, self, p->offset); - priv->reload_remaining++; - - if (npaths == 0) { - object_property_maybe_complete (self); - return TRUE; - } - - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "&o", &path)) { - gs_unref_object GDBusObject *object = NULL; - - object = g_dbus_object_manager_get_object (priv->object_manager, path); - if (object) { - obj = g_object_get_qdata (G_OBJECT (object), _nm_object_obj_nm_quark ()); - object_created (obj, path, odata); - } else { - g_warning ("no object known for %s\n", path); - odata->remaining--; - odata->length--; - object_property_maybe_complete (self); + for (i = 0; i < p->num; i++) { + if (!nml_dbus_property_ao_is_ready (&fields[i])) + return FALSE; } } @@ -679,559 +146,69 @@ handle_object_array_property (NMObject *self, const char *property_name, GVarian } static void -handle_property_changed (NMObject *self, const char *dbus_name, GVariant *value) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - char *prop_name; - PropertyInfo *pi; - GParamSpec *pspec; - gboolean success = FALSE, found = FALSE; - GSList *iter; - - prop_name = wincaps_to_dash (dbus_name); - - /* Iterate through the object and its parents to find the property */ - for (iter = priv->property_tables; iter; iter = g_slist_next (iter)) { - pi = g_hash_table_lookup ((GHashTable *) iter->data, prop_name); - if (pi) { - if (!pi->field) { - /* We know about this property but aren't tracking changes on it. */ - goto out; - } - - found = TRUE; - break; - } - } - - if (!found) { - dbgmsg ("Property '%s' unhandled.", prop_name); - goto out; - } - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (self)), prop_name); - if (!pspec && pi->func == demarshal_generic) { - dbgmsg ("%s: property '%s' changed but wasn't defined by object type %s.", - __func__, - prop_name, - G_OBJECT_TYPE_NAME (self)); - goto out; - } - - if (G_UNLIKELY (debug)) { - char *s; - s = g_variant_print (value, FALSE); - dbgmsg ("PC: (%p) %s:%s => '%s' (%s%s%s)", - self, G_OBJECT_TYPE_NAME (self), - prop_name, - s, - g_variant_get_type_string (value), - pi->object_type ? " / " : "", - pi->object_type ? g_type_name (pi->object_type) : ""); - g_free (s); - } - - if (pspec && pi->object_type) { - if (g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH)) - success = handle_object_property (self, pspec->name, value, pi); - else if (g_variant_is_of_type (value, G_VARIANT_TYPE ("ao"))) - success = handle_object_array_property (self, pspec->name, value, pi); - else { - g_warn_if_reached (); - goto out; - } - } else - success = (*(pi->func)) (self, pspec, value, pi->field); - - if (!success) { - dbgmsg ("%s: failed to update property '%s' of object type %s.", - __func__, - prop_name, - G_OBJECT_TYPE_NAME (self)); - } - -out: - g_free (prop_name); -} - -static void -properties_changed (GDBusProxy *proxy, - GVariant *changed_properties, - GStrv invalidated_properties, - gpointer user_data) +obj_changed_notify (NMObject *self) { - NMObject *self = NM_OBJECT (user_data); - GVariantIter iter; - const char *name; - GVariant *value; - - g_variant_iter_init (&iter, changed_properties); - while (g_variant_iter_next (&iter, "{&sv}", &name, &value)) { - handle_property_changed (self, name, value); - g_variant_unref (value); - } -} + NMObjectClass *klass = NM_OBJECT_GET_CLASS (self); + NMClient *client = _nm_object_get_client (self); + const _NMObjectClassFieldInfo *p; -#define HANDLE_TYPE_CHECK(vtype, ctype, getter) \ - ({ \ - gboolean _success = FALSE; \ - \ - if (g_variant_is_of_type (value, vtype)) { \ - ctype *param = (ctype *) field; \ - ctype newval = getter (value); \ - different = *param != newval; \ - *param = newval; \ - _success = TRUE; \ - } \ - \ - _success; \ - }) - -#define HANDLE_TYPE(vtype, ctype, getter) \ - G_STMT_START { \ - if (!HANDLE_TYPE_CHECK (vtype, ctype, getter)) {\ - success = FALSE; \ - goto done; \ - } \ - } G_STMT_END + nm_assert (NM_IS_CLIENT (client)); -static gboolean -demarshal_generic (NMObject *object, - GParamSpec *pspec, - GVariant *value, - gpointer field) -{ - gboolean success = TRUE; - gboolean different = FALSE; - - if (pspec->value_type == G_TYPE_STRING) { - if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) { - char **param = (char **) field; - const char *newval = g_variant_get_string (value, NULL); - - different = !!g_strcmp0 (*param, newval); - if (different) { - g_free (*param); - *param = g_strdup (newval); - } - } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH)) { - char **param = (char **) field; - const char *newval = g_variant_get_string (value, NULL); - - /* Handle "NULL" object paths */ - if (g_strcmp0 (newval, "/") == 0) - newval = NULL; - different = !!g_strcmp0 (*param, newval); - if (different) { - g_free (*param); - *param = g_strdup (newval); - } - } else { - success = FALSE; - goto done; - } - } else if (pspec->value_type == G_TYPE_STRV) { - char ***param = (char ***)field; - const char **newval; - gsize i; - - newval = g_variant_get_strv (value, NULL); - if (!*param) - different = TRUE; - else { - if (!_nm_utils_strv_equal ((char **) newval, *param)) { - different = TRUE; - g_strfreev (*param); - } - } - if (different) { - for (i = 0; newval[i]; i++) - newval[i] = g_strdup (newval[i]); - *param = (char **) newval; - } else - g_free (newval); - } else if (pspec->value_type == G_TYPE_BYTES) { - GBytes **param = (GBytes **)field; - gconstpointer val; - gsize length = 0; - - val = g_variant_get_fixed_array (value, &length, 1); - - different = !nm_utils_gbytes_equal_mem (*param, val, length); - if (different) { - if (*param) - g_bytes_unref (*param); - *param = length > 0 ? g_bytes_new (val, length) : NULL; - } - } else if (G_IS_PARAM_SPEC_ENUM (pspec)) { - int *param = (int *) field; - int newval = 0; - - if (g_variant_is_of_type (value, G_VARIANT_TYPE_INT32)) - newval = g_variant_get_int32 (value); - else if (g_variant_is_of_type (value, G_VARIANT_TYPE_UINT32)) - newval = g_variant_get_uint32 (value); - else { - success = FALSE; - goto done; - } - different = *param != newval; - *param = newval; - } else if (G_IS_PARAM_SPEC_FLAGS (pspec)) { - guint *param = (guint *) field; - guint newval = 0; - - if (g_variant_is_of_type (value, G_VARIANT_TYPE_INT32)) - newval = g_variant_get_int32 (value); - else if (g_variant_is_of_type (value, G_VARIANT_TYPE_UINT32)) - newval = g_variant_get_uint32 (value); - else { - success = FALSE; - goto done; - } - different = *param != newval; - *param = newval; - } else if (pspec->value_type == G_TYPE_BOOLEAN) - HANDLE_TYPE (G_VARIANT_TYPE_BOOLEAN, gboolean, g_variant_get_boolean); - else if (pspec->value_type == G_TYPE_UCHAR) - HANDLE_TYPE (G_VARIANT_TYPE_BYTE, guchar, g_variant_get_byte); - else if (pspec->value_type == G_TYPE_DOUBLE) { - NM_PRAGMA_WARNING_DISABLE("-Wfloat-equal") - HANDLE_TYPE (G_VARIANT_TYPE_DOUBLE, double, g_variant_get_double); - NM_PRAGMA_WARNING_REENABLE - } else if (pspec->value_type == G_TYPE_INT) - HANDLE_TYPE (G_VARIANT_TYPE_INT32, int, g_variant_get_int32); - else if (pspec->value_type == G_TYPE_UINT) { - if ( !HANDLE_TYPE_CHECK (G_VARIANT_TYPE_UINT32, guint, g_variant_get_uint32) - && !HANDLE_TYPE_CHECK (G_VARIANT_TYPE_UINT16, guint, g_variant_get_uint16)) - success = FALSE; - } else if (pspec->value_type == G_TYPE_INT64) - HANDLE_TYPE (G_VARIANT_TYPE_INT64, gint64, g_variant_get_int64); - else if (pspec->value_type == G_TYPE_UINT64) - HANDLE_TYPE (G_VARIANT_TYPE_UINT64, guint64, g_variant_get_uint64); - else if (pspec->value_type == G_TYPE_LONG) - HANDLE_TYPE (G_VARIANT_TYPE_INT64, long, g_variant_get_int64); - else if (pspec->value_type == G_TYPE_ULONG) - HANDLE_TYPE (G_VARIANT_TYPE_UINT64, gulong, g_variant_get_uint64); - else { - g_warning ("%s: %s:%s unhandled type %s.", - __func__, - G_OBJECT_TYPE_NAME (object), - pspec->name, - g_type_name (pspec->value_type)); - success = FALSE; - } - -done: - if (success) { - if (different) - _nm_object_queue_notify (object, pspec->name); - } else { - dbgmsg ("%s: %s:%s (type %s) couldn't be set from D-Bus type %s.", - __func__, G_OBJECT_TYPE_NAME (object), pspec->name, - g_type_name (pspec->value_type), g_variant_get_type_string (value)); - } - return success; -} - -void -_nm_object_register_properties (NMObject *object, - const char *interface, - const NMPropertiesInfo *info) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - GDBusProxy *proxy; - static gsize dval = 0; - const char *debugstr; - NMPropertiesInfo *tmp; - GHashTable *instance; - - g_return_if_fail (NM_IS_OBJECT (object)); - g_return_if_fail (interface != NULL); - g_return_if_fail (info != NULL); - - if (g_once_init_enter (&dval)) { - debugstr = getenv ("LIBNM_GLIB_DEBUG"); - if (debugstr && strstr (debugstr, "properties-changed")) - debug = TRUE; - g_once_init_leave (&dval, 1); + for (p = klass->property_o_info; p; p = p->parent) { + nml_dbus_property_o_notify_changed_many (_nm_object_get_private (p->klass, self, p->offset), + p->num, + client); } - proxy = _nm_object_get_proxy (object, interface); - g_signal_connect (proxy, "g-properties-changed", - G_CALLBACK (properties_changed), object); - g_ptr_array_add (priv->proxies, proxy); - - instance = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free); - priv->property_tables = g_slist_prepend (priv->property_tables, instance); - - for (tmp = (NMPropertiesInfo *) info; tmp->name; tmp++) { - PropertyInfo *pi; - - if (!tmp->name || (tmp->func && !tmp->field)) { - g_warning ("%s: missing field in NMPropertiesInfo", __func__); - continue; - } - - pi = g_malloc0 (sizeof (PropertyInfo)); - pi->func = tmp->func ?: demarshal_generic; - pi->object_type = tmp->object_type; - pi->field = tmp->field; - pi->signal_prefix = tmp->signal_prefix; - g_hash_table_insert (instance, g_strdup (tmp->name), pi); + for (p = klass->property_ao_info; p; p = p->parent) { + nml_dbus_property_ao_notify_changed_many (_nm_object_get_private (p->klass, self, p->offset), + p->num, + client); } } -void -_nm_object_set_property (NMObject *object, - const char *interface, - const char *prop_name, - const char *format_string, - ...) -{ - GVariant *val, *ret; - GDBusProxy *proxy; - va_list ap; - - g_return_if_fail (NM_IS_OBJECT (object)); - g_return_if_fail (interface != NULL); - g_return_if_fail (prop_name != NULL); - g_return_if_fail (format_string != NULL); - - va_start (ap, format_string); - val = g_variant_new_va (format_string, NULL, &ap); - va_end (ap); - g_return_if_fail (val != NULL); - - proxy = _nm_object_get_proxy (object, interface); - ret = g_dbus_proxy_call_sync (proxy, - DBUS_INTERFACE_PROPERTIES ".Set", - g_variant_new ("(ssv)", interface, prop_name, val), - G_DBUS_CALL_FLAGS_NONE, 2000, - NULL, NULL); - /* Ignore errors. */ - if (ret) - g_variant_unref (ret); - g_object_unref (proxy); -} - -static void -reload_complete (NMObject *object, gboolean emit_now) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - - if (emit_now) { - nm_clear_g_source (&priv->notify_id); - deferred_notify_cb (object); - } else - _nm_object_defer_notify (object); -} - -GDBusObjectManager * -_nm_object_get_dbus_object_manager (NMObject *self) -{ - return NM_OBJECT_GET_PRIVATE (self)->object_manager; -} - /*****************************************************************************/ static void -init_dbus (NMObject *object) -{ -} - -static void -init_if (GDBusProxy *proxy, NMObject *self) -{ - char **props; - char **prop; - GVariant *val; - char *str; - - nm_assert (G_IS_DBUS_PROXY (proxy)); - nm_assert (NM_IS_OBJECT (self)); - - props = g_dbus_proxy_get_cached_property_names (proxy); - - for (prop = props; prop && *prop; prop++) { - val = g_dbus_proxy_get_cached_property (proxy, *prop); - str = g_variant_print (val, TRUE); - handle_property_changed (self, *prop, val); - g_variant_unref (val); - g_free (str); - } - - g_strfreev (props); -} - -static gboolean -init_sync (GInitable *initable, GCancellable *cancellable, GError **error) +register_client (NMObject *self, + NMClient *client, + NMLDBusObject *dbobj) { - NMObject *self = NM_OBJECT (initable); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - GList *interfaces; - - g_assert (priv->object && priv->object_manager); - - NM_OBJECT_GET_CLASS (self)->init_dbus (self); - - priv->reload_remaining++; - - interfaces = g_dbus_object_get_interfaces (priv->object); - g_list_foreach (interfaces, (GFunc) init_if, self); - g_list_free_full (interfaces, g_object_unref); - - priv->inited = TRUE; - - if (--priv->reload_remaining == 0) - reload_complete (self, TRUE); - - /* There are some object properties whose creation couldn't proceed - * because it depended on this object. */ - while (priv->waiters) { - ObjectCreatedData *odata = priv->waiters->data; - - priv->waiters = g_slist_remove (priv->waiters, odata); - object_property_maybe_complete (odata->self); - } - - return TRUE; -} -/*****************************************************************************/ - -typedef struct { - NMObject *object; - GSimpleAsyncResult *simple; - GCancellable *cancellable; - int proxies_pending; - GError *error; -} NMObjectInitData; + nm_assert (!priv->client); + nm_assert (NML_IS_DBUS_OBJECT (dbobj)); + nm_assert (dbobj->nmobj == G_OBJECT (self)); -static void -init_async_complete (NMObjectInitData *init_data) -{ - if (init_data->error) - g_simple_async_result_take_error (init_data->simple, init_data->error); - else - g_simple_async_result_set_op_res_gboolean (init_data->simple, TRUE); - g_simple_async_result_complete_in_idle (init_data->simple); - g_object_unref (init_data->simple); - g_clear_object (&init_data->cancellable); - g_slice_free (NMObjectInitData, init_data); + priv->client = client; + priv->dbobj = nml_dbus_object_ref (dbobj); } static void -init_async (GAsyncInitable *initable, int io_priority, - GCancellable *cancellable, GAsyncReadyCallback callback, - gpointer user_data) +unregister_client (NMObject *self, + NMClient *client, + NMLDBusObject *dbobj) { - NMObject *self = NM_OBJECT (initable); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - NMObjectInitData *init_data; - GList *interfaces; - - g_assert (priv->object && priv->object_manager); - NM_OBJECT_GET_CLASS (self)->init_dbus (self); + nm_assert (NM_IS_CLIENT (client)); + nm_assert (priv->client == client); + priv->client = NULL; - init_data = g_slice_new0 (NMObjectInitData); - init_data->object = self; - init_data->simple = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (init_data->simple, cancellable); - init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - - interfaces = g_dbus_object_get_interfaces (priv->object); - g_list_foreach (interfaces, (GFunc) init_if, self); - g_list_free_full (interfaces, g_object_unref); - - init_async_complete (init_data); -} - -static gboolean -init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error) -{ - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (initable); - - priv->inited = TRUE; - - /* There are some object properties whose creation couldn't proceed - * because it depended on this object. */ - while (priv->waiters) { - ObjectCreatedData *odata = priv->waiters->data; - - priv->waiters = g_slist_remove (priv->waiters, odata); - object_property_maybe_complete (odata->self); - } - - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return TRUE; + clear_properties (self, client); } /*****************************************************************************/ static void -nm_object_initable_iface_init (GInitableIface *iface) -{ - iface->init = init_sync; -} - -static void -nm_object_async_initable_iface_init (GAsyncInitableIface *iface) -{ - iface->init_async = init_async; - iface->init_finish = init_finish; -} - -static void -nm_object_init (NMObject *object) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - - c_list_init (&priv->notify_items); - c_list_init (&priv->pending); - priv->proxies = g_ptr_array_new (); -} - -static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_DBUS_OBJECT: - /* construct-only */ - priv->object = g_value_dup_object (value); - if (!priv->object) - g_return_if_reached (); - break; - case PROP_DBUS_OBJECT_MANAGER: - /* construct-only */ - priv->object_manager = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); + NMObject *self = NM_OBJECT (object); switch (prop_id) { case PROP_PATH: - g_value_set_string (value, nm_object_get_path (NM_OBJECT (object))); - break; - case PROP_DBUS_CONNECTION: - g_value_set_object (value, g_dbus_object_manager_client_get_connection (G_DBUS_OBJECT_MANAGER_CLIENT (priv->object_manager))); + g_value_set_string (value, nm_object_get_path (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1239,111 +216,67 @@ get_property (GObject *object, guint prop_id, } } +/*****************************************************************************/ + static void -dispose (GObject *object) +nm_object_init (NMObject *object) { - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - CList *iter, *safe; - guint i; - - nm_clear_g_source (&priv->notify_id); - - c_list_for_each_safe (iter, safe, &priv->notify_items) - notify_item_free (c_list_entry (iter, NotifyItem, lst)); + NMObject *self = NM_OBJECT (object); + NMObjectPrivate *priv; - g_slist_free_full (priv->waiters, odata_free); + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_OBJECT, NMObjectPrivate); - g_clear_object (&priv->object); - g_clear_object (&priv->object_manager); + self->_priv = priv; - if (priv->proxies) { - for (i = 0; i < priv->proxies->len; i++) { - g_signal_handlers_disconnect_by_func (priv->proxies->pdata[i], - properties_changed, - object); - g_object_unref (priv->proxies->pdata[i]); - } - g_ptr_array_free (priv->proxies, TRUE); - priv->proxies = NULL; - } - - G_OBJECT_CLASS (nm_object_parent_class)->dispose (object); + c_list_init (&self->obj_base.queue_notify_lst); } static void -finalize (GObject *object) +dispose (GObject *object) { - NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); + NMObject *self = NM_OBJECT (object); + NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); + + self->obj_base.is_disposing = TRUE; + + nm_assert (c_list_is_empty (&self->obj_base.queue_notify_lst)); + nm_assert (!priv->client); + nm_assert (!priv->dbobj || !priv->dbobj->nmobj); - g_slist_free_full (priv->property_tables, (GDestroyNotify) g_hash_table_destroy); + clear_properties (self, NULL); + + G_OBJECT_CLASS (nm_object_parent_class)->dispose (object); - G_OBJECT_CLASS (nm_object_parent_class)->finalize (object); + nm_clear_pointer (&priv->dbobj, nml_dbus_object_unref); } static void -nm_object_class_init (NMObjectClass *nm_object_class) +nm_object_class_init (NMObjectClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (nm_object_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (nm_object_class, sizeof (NMObjectPrivate)); + _nm_object_class = klass; - /* virtual methods */ - object_class->set_property = set_property; - object_class->get_property = get_property; - object_class->dispose = dispose; - object_class->finalize = finalize; + g_type_class_add_private (klass, sizeof (NMObjectPrivate)); - nm_object_class->init_dbus = init_dbus; + object_class->get_property = get_property; + object_class->dispose = dispose; - /* Properties */ + klass->register_client = register_client; + klass->unregister_client = unregister_client; + klass->is_ready = is_ready; + klass->obj_changed_notify = obj_changed_notify; /** * NMObject:path: * * The D-Bus object path. **/ - g_object_class_install_property - (object_class, PROP_PATH, - g_param_spec_string (NM_OBJECT_PATH, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - /** - * NMObject:dbus-connection: (skip) - * - * The #GDBusConnection of the object. - **/ - g_object_class_install_property - (object_class, PROP_DBUS_CONNECTION, - g_param_spec_object (NM_OBJECT_DBUS_CONNECTION, "", "", - G_TYPE_DBUS_CONNECTION, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_PATH] = + g_param_spec_string (NM_OBJECT_PATH, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); - /** - * NMObject:dbus-object: (skip) - * - * The #GDBusObject of the object. - **/ - g_object_class_install_property - (object_class, PROP_DBUS_OBJECT, - g_param_spec_object (NM_OBJECT_DBUS_OBJECT, "", "", - G_TYPE_DBUS_OBJECT, - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - /** - * NMObject:dbus-object-manager: (skip) - * - * The #GDBusObjectManager of the object. - **/ - g_object_class_install_property - (object_class, PROP_DBUS_OBJECT_MANAGER, - g_param_spec_object (NM_OBJECT_DBUS_OBJECT_MANAGER, "", "", - G_TYPE_DBUS_OBJECT_MANAGER, - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); } diff --git a/libnm/nm-object.h b/libnm/nm-object.h index 2dad008c..88c34a9e 100644 --- a/libnm/nm-object.h +++ b/libnm/nm-object.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2012 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2012 Red Hat, Inc. */ #ifndef __NM_OBJECT_H__ @@ -37,33 +23,11 @@ G_BEGIN_DECLS #define NM_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_OBJECT, NMObjectClass)) #define NM_OBJECT_PATH "path" -#define NM_OBJECT_DBUS_CONNECTION "dbus-connection" -#define NM_OBJECT_DBUS_OBJECT "dbus-object" -#define NM_OBJECT_DBUS_OBJECT_MANAGER "dbus-object-manager" /** * NMObject: */ -struct _NMObject { - GObject parent; -}; - -typedef struct { - GObjectClass parent; - - /* Methods */ - void (*init_dbus) (NMObject *object); - - /* The "object-creation-failed" method is PRIVATE for libnm and - * is not meant for any external usage. It indicates that an error - * occurred during creation of an object. - */ - void (*object_creation_failed) (NMObject *master_object, - const char *failed_path); - - /*< private >*/ - gpointer padding[8]; -} NMObjectClass; +typedef struct _NMObjectClass NMObjectClass; GType nm_object_get_type (void); diff --git a/libnm/nm-property-docs.xml b/libnm/nm-property-docs.xml index 8d0e99a1..cdf60f8c 100644 --- a/libnm/nm-property-docs.xml +++ b/libnm/nm-property-docs.xml @@ -57,8 +57,8 @@ <property name="phase1-peaplabel" name_upper="PHASE1_PEAPLABEL" type="string" description="Forces use of the new PEAP label during key derivation. Some RADIUS servers may require forcing the new PEAP label to interoperate with PEAPv1. Set to "1" to force use of the new PEAP label. See the wpa_supplicant documentation for more details." /> <property name="phase1-peapver" name_upper="PHASE1_PEAPVER" type="string" description="Forces which PEAP version is used when PEAP is set as the EAP method in the "eap" property. When unset, the version reported by the server will be used. Sometimes when using older RADIUS servers, it is necessary to force the client to use a particular PEAP version. To do so, this property may be set to "0" or "1" to force that specific PEAP version." /> <property name="phase2-altsubject-matches" name_upper="PHASE2_ALTSUBJECT_MATCHES" type="array of string" description="List of strings to be matched against the altSubjectName of the certificate presented by the authentication server during the inner "phase 2" authentication. If the list is empty, no verification of the server certificate's altSubjectName is performed." /> - <property name="phase2-auth" name_upper="PHASE2_AUTH" type="string" description="Specifies the allowed "phase 2" inner non-EAP authentication methods when an EAP method that uses an inner TLS tunnel is specified in the "eap" property. Recognized non-EAP "phase 2" methods are "pap", "chap", "mschap", "mschapv2", "gtc", "otp", "md5", and "tls". Each "phase 2" inner method requires specific parameters for successful authentication; see the wpa_supplicant documentation for more details." /> - <property name="phase2-autheap" name_upper="PHASE2_AUTHEAP" type="string" description="Specifies the allowed "phase 2" inner EAP-based authentication methods when an EAP method that uses an inner TLS tunnel is specified in the "eap" property. Recognized EAP-based "phase 2" methods are "md5", "mschapv2", "otp", "gtc", and "tls". Each "phase 2" inner method requires specific parameters for successful authentication; see the wpa_supplicant documentation for more details." /> + <property name="phase2-auth" name_upper="PHASE2_AUTH" type="string" description="Specifies the allowed "phase 2" inner non-EAP authentication method when an EAP method that uses an inner TLS tunnel is specified in the "eap" property. Recognized non-EAP "phase 2" methods are "pap", "chap", "mschap", "mschapv2", "gtc", "otp", "md5", and "tls". Each "phase 2" inner method requires specific parameters for successful authentication; see the wpa_supplicant documentation for more details." /> + <property name="phase2-autheap" name_upper="PHASE2_AUTHEAP" type="string" description="Specifies the allowed "phase 2" inner EAP-based authentication method when an EAP method that uses an inner TLS tunnel is specified in the "eap" property. Recognized EAP-based "phase 2" methods are "md5", "mschapv2", "otp", "gtc", and "tls". Each "phase 2" inner method requires specific parameters for successful authentication; see the wpa_supplicant documentation for more details." /> <property name="phase2-ca-cert" name_upper="PHASE2_CA_CERT" type="byte array" description="Contains the "phase 2" CA certificate if used by the EAP method specified in the "phase2-auth" or "phase2-autheap" properties. Certificate data is specified using a "scheme"; two are currently supported: blob and path. When using the blob scheme (which is backwards compatible with NM 0.7.x) this property should be set to the certificate's DER encoded data. When using the path scheme, this property should be set to the full UTF-8 encoded path of the certificate, prefixed with the string "file://" and ending with a terminating NUL byte. This property can be unset even if the EAP method supports CA certificates, but this allows man-in-the-middle attacks and is NOT recommended." /> <property name="phase2-ca-cert-password" name_upper="PHASE2_CA_CERT_PASSWORD" type="string" description="The password used to access the "phase2" CA certificate stored in "phase2-ca-cert" property. Only makes sense if the certificate is stored on a PKCS#11 token that requires a login." /> <property name="phase2-ca-cert-password-flags" name_upper="PHASE2_CA_CERT_PASSWORD_FLAGS" type="NMSettingSecretFlags (uint32)" description="Flags indicating how to handle the "phase2-ca-cert-password" property." /> @@ -147,6 +147,7 @@ </setting> <setting name="gsm" description="GSM-based Mobile Broadband Settings" name_upper="GSM" > <property name="apn" name_upper="APN" type="string" description="The GPRS Access Point Name specifying the APN used when establishing a data session with the GSM-based network. The APN often determines how the user will be billed for their network usage and whether the user has access to the Internet or just a provider-specific walled-garden, so it is important to use the correct APN for the user's mobile broadband plan. The APN may only be composed of the characters a-z, 0-9, ., and - per GSM 03.60 Section 14.9." /> + <property name="auto-config" name_upper="AUTO_CONFIG" type="boolean" default="FALSE" description="When TRUE, the settings such as APN, username, or password will default to values that match the network the modem will register to in the Mobile Broadband Provider database." /> <property name="device-id" name_upper="DEVICE_ID" type="string" description="The device unique identifier (as given by the WWAN management service) which this connection applies to. If given, the connection will only apply to the specified device." /> <property name="home-only" name_upper="HOME_ONLY" type="boolean" default="FALSE" description="When TRUE, only connections to the home network will be allowed. Connections to roaming networks will not be made." /> <property name="mtu" name_upper="MTU" type="uint32" default="0" description="If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple frames." /> @@ -173,6 +174,8 @@ <property name="dhcp-client-id" name_upper="DHCP_CLIENT_ID" type="string" description="A string sent to the DHCP server to identify the local machine which the DHCP server may use to customize the DHCP lease and options. When the property is a hex string ('aa:bb:cc') it is interpreted as a binary client ID, in which case the first byte is assumed to be the 'type' field as per RFC 2132 section 9.14 and the remaining bytes may be an hardware address (e.g. '01:xx:xx:xx:xx:xx:xx' where 1 is the Ethernet ARP type and the rest is a MAC address). If the property is not a hex string it is considered as a non-hardware-address client ID and the 'type' field is set to 0. The special values "mac" and "perm-mac" are supported, which use the current or permanent MAC address of the device to generate a client identifier with type ethernet (01). Currently, these options only work for ethernet type of links. The special value "duid" generates a RFC4361-compliant client identifier based on a hash of the interface name as IAID and /etc/machine-id. The special value "stable" is supported to generate a type 0 client identifier based on the stable-id (see connection.stable-id) and a per-host key. If you set the stable-id, you may want to include the "${DEVICE}" or "${MAC}" specifier to get a per-device key. If unset, a globally configured default is used. If still unset, the default depends on the DHCP plugin." /> <property name="dhcp-fqdn" name_upper="DHCP_FQDN" type="string" description="If the "dhcp-send-hostname" property is TRUE, then the specified FQDN will be sent to the DHCP server when acquiring a lease. This property and "dhcp-hostname" are mutually exclusive and cannot be set at the same time." /> <property name="dhcp-hostname" name_upper="DHCP_HOSTNAME" type="string" description="If the "dhcp-send-hostname" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and "dhcp-fqdn" are mutually exclusive and cannot be set at the same time." /> + <property name="dhcp-hostname-flags" name_upper="DHCP_HOSTNAME_FLAGS" type="uint32" default="0" description="Flags for the DHCP hostname and FQDN. Currently this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests." /> + <property name="dhcp-iaid" name_upper="DHCP_IAID" type="string" description="A string containing the "Identity Association Identifier" (IAID) used by the DHCP client. The property is a 32-bit decimal value or a special value among "mac", "perm-mac", "ifname" and "stable". When set to "mac" (or "perm-mac"), the last 4 bytes of the current (or permanent) MAC address are used as IAID. When set to "ifname", the IAID is computed by hashing the interface name. The special value "stable" can be used to generate an IAID based on the stable-id (see connection.stable-id), a per-host key and the interface name. When the property is unset, the value from global configuration is used; if no global default is set then the IAID is assumed to be "ifname". Note that at the moment this property is ignored for IPv6 by dhclient, which always derives the IAID from the MAC address." /> <property name="dhcp-send-hostname" name_upper="DHCP_SEND_HOSTNAME" type="boolean" default="TRUE" description="If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the "dhcp-hostname" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent." /> <property name="dhcp-timeout" name_upper="DHCP_TIMEOUT" type="int32" default="0" description="A timeout for a DHCP transaction in seconds." /> <property name="dns" name_upper="DNS" type="array of uint32" description="Array of IP addresses of DNS servers." /> @@ -195,6 +198,8 @@ <property name="dad-timeout" name_upper="DAD_TIMEOUT" type="int32" default="-1" description="Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4." /> <property name="dhcp-duid" name_upper="DHCP_DUID" type="string" description="A string containing the DHCPv6 Unique Identifier (DUID) used by the dhcp client to identify itself to DHCPv6 servers (RFC 3315). The DUID is carried in the Client Identifier option. If the property is a hex string ('aa:bb:cc') it is interpreted as a binary DUID and filled as an opaque value in the Client Identifier option. The special value "lease" will retrieve the DUID previously used from the lease file belonging to the connection. If no DUID is found and "dhclient" is the configured dhcp client, the DUID is searched in the system-wide dhclient lease file. If still no DUID is found, or another dhcp client is used, a global and permanent DUID-UUID (RFC 6355) will be generated based on the machine-id. The special values "llt" and "ll" will generate a DUID of type LLT or LL (see RFC 3315) based on the current MAC address of the device. In order to try providing a stable DUID-LLT, the time field will contain a constant timestamp that is used globally (for all profiles) and persisted to disk. The special values "stable-llt", "stable-ll" and "stable-uuid" will generate a DUID of the corresponding type, derived from the connection's stable-id and a per-host unique key. You may want to include the "${DEVICE}" or "${MAC}" specifier in the stable-id, in case this profile gets activated on multiple devices. So, the link-layer address of "stable-ll" and "stable-llt" will be a generated address derived from the stable id. The DUID-LLT time value in the "stable-llt" option will be picked among a static timespan of three years (the upper bound of the interval is the same constant timestamp used in "llt"). When the property is unset, the global value provided for "ipv6.dhcp-duid" is used. If no global value is provided, the default "lease" value is assumed." /> <property name="dhcp-hostname" name_upper="DHCP_HOSTNAME" type="string" description="If the "dhcp-send-hostname" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and "dhcp-fqdn" are mutually exclusive and cannot be set at the same time." /> + <property name="dhcp-hostname-flags" name_upper="DHCP_HOSTNAME_FLAGS" type="uint32" default="0" description="Flags for the DHCP hostname and FQDN. Currently this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests." /> + <property name="dhcp-iaid" name_upper="DHCP_IAID" type="string" description="A string containing the "Identity Association Identifier" (IAID) used by the DHCP client. The property is a 32-bit decimal value or a special value among "mac", "perm-mac", "ifname" and "stable". When set to "mac" (or "perm-mac"), the last 4 bytes of the current (or permanent) MAC address are used as IAID. When set to "ifname", the IAID is computed by hashing the interface name. The special value "stable" can be used to generate an IAID based on the stable-id (see connection.stable-id), a per-host key and the interface name. When the property is unset, the value from global configuration is used; if no global default is set then the IAID is assumed to be "ifname". Note that at the moment this property is ignored for IPv6 by dhclient, which always derives the IAID from the MAC address." /> <property name="dhcp-send-hostname" name_upper="DHCP_SEND_HOSTNAME" type="boolean" default="TRUE" description="If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the "dhcp-hostname" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent." /> <property name="dhcp-timeout" name_upper="DHCP_TIMEOUT" type="int32" default="0" description="A timeout for a DHCP transaction in seconds." /> <property name="dns" name_upper="DNS" type="array of byte array" description="Array of IP addresses of DNS servers." /> @@ -455,7 +460,7 @@ <property name="auth-alg" name_upper="AUTH_ALG" type="string" description="When WEP is used (ie, key-mgmt = "none" or "ieee8021x") indicate the 802.11 authentication algorithm required by the AP here. One of "open" for Open System, "shared" for Shared Key, or "leap" for Cisco LEAP. When using Cisco LEAP (ie, key-mgmt = "ieee8021x" and auth-alg = "leap") the "leap-username" and "leap-password" properties must be specified." /> <property name="fils" name_upper="FILS" type="int32" default="0" description="Indicates whether Fast Initial Link Setup (802.11ai) must be enabled for the connection. One of NM_SETTING_WIRELESS_SECURITY_FILS_DEFAULT (0) (use global default value), NM_SETTING_WIRELESS_SECURITY_FILS_DISABLE (1) (disable FILS), NM_SETTING_WIRELESS_SECURITY_FILS_OPTIONAL (2) (enable FILS if the supplicant and the access point support it) or NM_SETTING_WIRELESS_SECURITY_FILS_REQUIRED (3) (enable FILS and fail if not supported). When set to NM_SETTING_WIRELESS_SECURITY_FILS_DEFAULT (0) and no global default is set, FILS will be optionally enabled." /> <property name="group" name_upper="GROUP" type="array of string" description="A list of group/broadcast encryption algorithms which prevents connections to Wi-Fi networks that do not utilize one of the algorithms in the list. For maximum compatibility leave this property empty. Each list element may be one of "wep40", "wep104", "tkip", or "ccmp"." /> - <property name="key-mgmt" name_upper="KEY_MGMT" type="string" description="Key management used for the connection. One of "none" (WEP), "ieee8021x" (Dynamic WEP), "wpa-none" (Ad-Hoc WPA-PSK), "wpa-psk" (infrastructure WPA-PSK), "sae" (SAE) or "wpa-eap" (WPA-Enterprise). This property must be set for any Wi-Fi connection that uses security." /> + <property name="key-mgmt" name_upper="KEY_MGMT" type="string" description="Key management used for the connection. One of "none" (WEP), "ieee8021x" (Dynamic WEP), "wpa-psk" (infrastructure WPA-PSK), "sae" (SAE) or "wpa-eap" (WPA-Enterprise). This property must be set for any Wi-Fi connection that uses security." /> <property name="leap-password" name_upper="LEAP_PASSWORD" type="string" description="The login password for legacy LEAP connections (ie, key-mgmt = "ieee8021x" and auth-alg = "leap")." /> <property name="leap-password-flags" name_upper="LEAP_PASSWORD_FLAGS" type="NMSettingSecretFlags (uint32)" description="Flags indicating how to handle the "leap-password" property." /> <property name="leap-username" name_upper="LEAP_USERNAME" type="string" description="The login username for legacy LEAP connections (ie, key-mgmt = "ieee8021x" and auth-alg = "leap")." /> diff --git a/libnm/nm-remote-connection-private.h b/libnm/nm-remote-connection-private.h index 86a1c651..5ac24eb8 100644 --- a/libnm/nm-remote-connection-private.h +++ b/libnm/nm-remote-connection-private.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2009 Red Hat, Inc. + * Copyright (C) 2009 Red Hat, Inc. */ #ifndef __NM_REMOTE_CONNECTION_PRIVATE_H__ diff --git a/libnm/nm-remote-connection.c b/libnm/nm-remote-connection.c index 0a46befa..d1cc90d6 100644 --- a/libnm/nm-remote-connection.c +++ b/libnm/nm-remote-connection.c @@ -1,27 +1,14 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2011 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2011 Red Hat, Inc. */ #include "nm-default.h" #include "nm-remote-connection.h" +#include "nm-glib-aux/nm-dbus-aux.h" #include "nm-dbus-interface.h" #include "nm-utils.h" #include "nm-setting-connection.h" @@ -30,8 +17,6 @@ #include "nm-object-private.h" #include "nm-dbus-helpers.h" -#include "introspection/org.freedesktop.NetworkManager.Settings.Connection.h" - /** * SECTION:nm-remote-connection * @short_description: A connection managed by NetworkManager server @@ -40,63 +25,44 @@ * NetworkManager D-Bus interface. **/ -static void nm_remote_connection_connection_iface_init (NMConnectionInterface *iface); -static void nm_remote_connection_initable_iface_init (GInitableIface *iface); -static void nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface); -static GInitableIface *nm_remote_connection_parent_initable_iface; -static GAsyncInitableIface *nm_remote_connection_parent_async_initable_iface; - -G_DEFINE_TYPE_WITH_CODE (NMRemoteConnection, nm_remote_connection, NM_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION, nm_remote_connection_connection_iface_init); - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_remote_connection_initable_iface_init); - G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_remote_connection_async_initable_iface_init); - ) +/*****************************************************************************/ -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE (NMRemoteConnection, PROP_UNSAVED, PROP_FLAGS, PROP_FILENAME, PROP_VISIBLE, - - LAST_PROP -}; +); typedef struct { - NMDBusSettingsConnection *proxy; + GCancellable *get_settings_cancellable; - gboolean unsaved; - guint32 flags; char *filename; + guint32 flags; + bool unsaved; - gboolean visible; + bool visible:1; + bool is_initialized:1; } NMRemoteConnectionPrivate; -#define NM_REMOTE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_REMOTE_CONNECTION, NMRemoteConnectionPrivate)) +struct _NMRemoteConnection { + NMObject parent; + NMRemoteConnectionPrivate _priv; +}; -/*****************************************************************************/ +struct _NMRemoteConnectionClass { + NMObjectClass parent_class; +}; -static void -update2_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - GVariant *v; - - if (nmdbus_settings_connection_call_update2_finish (NMDBUS_SETTINGS_CONNECTION (proxy), - &v, - result, - &error)) - g_simple_async_result_set_op_res_gpointer (simple, - v, - (GDestroyNotify) g_variant_unref); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - g_simple_async_result_complete (simple); - g_object_unref (simple); -} +static void nm_remote_connection_connection_iface_init (NMConnectionInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (NMRemoteConnection, nm_remote_connection, NM_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION, nm_remote_connection_connection_iface_init); + ) + +#define NM_REMOTE_CONNECTION_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMRemoteConnection, NM_IS_REMOTE_CONNECTION, NMObject) + +/*****************************************************************************/ /** * nm_remote_connection_update2: @@ -121,37 +87,33 @@ nm_remote_connection_update2 (NMRemoteConnection *connection, GAsyncReadyCallback callback, gpointer user_data) { - NMRemoteConnectionPrivate *priv; - GSimpleAsyncResult *simple; - GVariantBuilder builder; - g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); g_return_if_fail (!settings || g_variant_is_of_type (settings, NM_VARIANT_TYPE_CONNECTION)); g_return_if_fail (!args || g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}"))); g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); - - simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data, - nm_remote_connection_update2); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - if (!settings) { - g_variant_builder_init (&builder, NM_VARIANT_TYPE_CONNECTION); - settings = g_variant_builder_end (&builder); - } - if (!args) { - g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); - args = g_variant_builder_end (&builder); - } - nmdbus_settings_connection_call_update2 (priv->proxy, - settings, - flags, - args, - cancellable, - update2_cb, - simple); + if (!settings) + settings = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0); + if (!args) + args = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); + + _nm_client_dbus_call (_nm_object_get_client (connection), + connection, + nm_remote_connection_update2, + cancellable, + callback, + user_data, + _nm_object_get_path (connection), + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + "Update2", + g_variant_new ("(@a{sa{sv}}u@a{sv})", + settings, + (guint32) flags, + args), + G_VARIANT_TYPE ("(a{sv})"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_variant_strip_dbus_error_cb); } /** @@ -162,7 +124,7 @@ nm_remote_connection_update2 (NMRemoteConnection *connection, * * Gets the result of a call to nm_remote_connection_commit_changes_async(). * - * Returns: on success, a #GVariant of type "a{sv}" with the result. On failure, + * Returns: (transfer full): on success, a #GVariant of type "a{sv}" with the result. On failure, * %NULL. **/ GVariant * @@ -170,15 +132,21 @@ nm_remote_connection_update2_finish (NMRemoteConnection *connection, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; + gs_unref_variant GVariant *ret = NULL; + GVariant *v_result; - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_update2), FALSE); + g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), NULL); + g_return_val_if_fail (nm_g_task_is_valid (result, connection, nm_remote_connection_update2), NULL); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) + ret = g_task_propagate_pointer (G_TASK (result), error); + if (!ret) return NULL; - else - return g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple)); + + g_variant_get (ret, + "(@a{sv})", + &v_result); + + return v_result; } /*****************************************************************************/ @@ -195,6 +163,8 @@ nm_remote_connection_update2_finish (NMRemoteConnection *connection, * disk; if %FALSE, then only the in-memory representation will be changed. * * Returns: %TRUE on success, %FALSE on error, in which case @error will be set. + * + * Deprecated: 1.22, use nm_remote_connection_commit_changes_async() or GDBusConnection **/ gboolean nm_remote_connection_commit_changes (NMRemoteConnection *connection, @@ -202,49 +172,32 @@ nm_remote_connection_commit_changes (NMRemoteConnection *connection, GCancellable *cancellable, GError **error) { - NMRemoteConnectionPrivate *priv; - gs_unref_variant GVariant *result = NULL; - gboolean ret; - GVariantBuilder args; + gs_unref_variant GVariant *ret = NULL; g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); + + ret = _nm_client_dbus_call_sync (_nm_object_get_client (connection), + cancellable, + _nm_object_get_path (connection), + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + "Update2", + g_variant_new ("(@a{sa{sv}}u@a{sv})", + nm_connection_to_dbus (NM_CONNECTION (connection), + NM_CONNECTION_SERIALIZE_ALL), + (guint32) ( save_to_disk + ? NM_SETTINGS_UPDATE2_FLAG_TO_DISK + : NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY), + g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0)), + G_VARIANT_TYPE ("(a{sv})"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); + if (!ret) + return FALSE; - priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); - - g_variant_builder_init (&args, G_VARIANT_TYPE ("a{sv}")); - ret = nmdbus_settings_connection_call_update2_sync (priv->proxy, - nm_connection_to_dbus (NM_CONNECTION (connection), - NM_CONNECTION_SERIALIZE_ALL), - save_to_disk - ? NM_SETTINGS_UPDATE2_FLAG_TO_DISK - : NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY, - g_variant_builder_end (&args), - &result, - cancellable, - error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - -static void -update_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - gs_unref_variant GVariant *v = NULL; - - if (nmdbus_settings_connection_call_update2_finish (NMDBUS_SETTINGS_CONNECTION (proxy), - &v, - result, - &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - g_simple_async_result_complete (simple); - g_object_unref (simple); + return TRUE; } /** @@ -267,30 +220,19 @@ nm_remote_connection_commit_changes_async (NMRemoteConnection *connection, GAsyncReadyCallback callback, gpointer user_data) { - NMRemoteConnectionPrivate *priv; - GSimpleAsyncResult *simple; - GVariantBuilder args; - g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); - - simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data, - nm_remote_connection_commit_changes_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - g_variant_builder_init (&args, G_VARIANT_TYPE ("a{sv}")); - nmdbus_settings_connection_call_update2 (priv->proxy, - nm_connection_to_dbus (NM_CONNECTION (connection), - NM_CONNECTION_SERIALIZE_ALL), - save_to_disk - ? NM_SETTINGS_UPDATE2_FLAG_TO_DISK - : NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY, - g_variant_builder_end (&args), - cancellable, - update_cb, - simple); + nm_remote_connection_update2 (connection, + nm_connection_to_dbus (NM_CONNECTION (connection), + NM_CONNECTION_SERIALIZE_ALL), + save_to_disk + ? NM_SETTINGS_UPDATE2_FLAG_TO_DISK + : NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY, + NULL, + cancellable, + callback, + user_data); } /** @@ -308,15 +250,10 @@ nm_remote_connection_commit_changes_finish (NMRemoteConnection *connection, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_commit_changes_async), FALSE); + gs_unref_variant GVariant *v_result = NULL; - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); + v_result = nm_remote_connection_update2_finish (connection, result, error); + return !!v_result; } /*****************************************************************************/ @@ -331,40 +268,27 @@ nm_remote_connection_commit_changes_finish (NMRemoteConnection *connection, * been written to disk, or if the connection has never been saved. * * Returns: %TRUE on success, %FALSE on error, in which case @error will be set. + * + * Deprecated: 1.22, use nm_remote_connection_save_async() or GDBusConnection **/ gboolean nm_remote_connection_save (NMRemoteConnection *connection, GCancellable *cancellable, GError **error) { - NMRemoteConnectionPrivate *priv; - gboolean ret; - g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); - priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); - - ret = nmdbus_settings_connection_call_save_sync (priv->proxy, cancellable, error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - -static void -save_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nmdbus_settings_connection_call_save_finish (NMDBUS_SETTINGS_CONNECTION (proxy), - result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - g_simple_async_result_complete (simple); - g_object_unref (simple); + return _nm_client_dbus_call_sync_void (_nm_object_get_client (connection), + cancellable, + _nm_object_get_path (connection), + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + "Save", + g_variant_new ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); } /** @@ -383,18 +307,23 @@ nm_remote_connection_save_async (NMRemoteConnection *connection, GAsyncReadyCallback callback, gpointer user_data) { - NMRemoteConnectionPrivate *priv; - GSimpleAsyncResult *simple; - g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); - - simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data, - nm_remote_connection_save_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nmdbus_settings_connection_call_save (priv->proxy, cancellable, save_cb, simple); + _nm_client_dbus_call (_nm_object_get_client (connection), + connection, + nm_remote_connection_save_async, + cancellable, + callback, + user_data, + _nm_object_get_path (connection), + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + "Save", + g_variant_new ("()"), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_strip_dbus_error_cb); } /** @@ -412,15 +341,10 @@ nm_remote_connection_save_finish (NMRemoteConnection *connection, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_save_async), FALSE); + g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, connection, nm_remote_connection_save_async), FALSE); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); + return g_task_propagate_boolean (G_TASK (result), error); } /*****************************************************************************/ @@ -434,40 +358,26 @@ nm_remote_connection_save_finish (NMRemoteConnection *connection, * Deletes the connection. * * Returns: %TRUE on success, %FALSE on error, in which case @error will be set. + * + * Deprecated: 1.22, use nm_remote_connection_delete_async() or GDBusConnection **/ gboolean nm_remote_connection_delete (NMRemoteConnection *connection, GCancellable *cancellable, GError **error) { - NMRemoteConnectionPrivate *priv; - gboolean ret; - g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE); - priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); - - ret = nmdbus_settings_connection_call_delete_sync (priv->proxy, cancellable, error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - -static void -delete_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nmdbus_settings_connection_call_delete_finish (NMDBUS_SETTINGS_CONNECTION (proxy), - result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - g_simple_async_result_complete (simple); - g_object_unref (simple); + return _nm_client_dbus_call_sync_void (_nm_object_get_client (connection), + cancellable, + _nm_object_get_path (connection), + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + "Delete", + g_variant_new ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); } /** @@ -485,18 +395,23 @@ nm_remote_connection_delete_async (NMRemoteConnection *connection, GAsyncReadyCallback callback, gpointer user_data) { - NMRemoteConnectionPrivate *priv; - GSimpleAsyncResult *simple; - g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); - - simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data, - nm_remote_connection_delete_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - nmdbus_settings_connection_call_delete (priv->proxy, cancellable, delete_cb, simple); + _nm_client_dbus_call (_nm_object_get_client (connection), + connection, + nm_remote_connection_delete_async, + cancellable, + callback, + user_data, + _nm_object_get_path (connection), + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + "Delete", + g_variant_new ("()"), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_void_strip_dbus_error_cb); } /** @@ -514,15 +429,10 @@ nm_remote_connection_delete_finish (NMRemoteConnection *connection, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_delete_async), FALSE); + g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, connection, nm_remote_connection_delete_async), FALSE); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); + return g_task_propagate_boolean (G_TASK (result), error); } /** @@ -535,8 +445,10 @@ nm_remote_connection_delete_finish (NMRemoteConnection *connection, * Request the connection's secrets. Note that this is a blocking D-Bus call, * not a simple property accessor. * - * Returns: a #GVariant of type %NM_VARIANT_TYPE_CONNECTION containing + * Returns: (transfer full): a #GVariant of type %NM_VARIANT_TYPE_CONNECTION containing * @connection's secrets, or %NULL on error. + * + * Deprecated: 1.22, use nm_remote_connection_get_secrets_async() or GDBusConnection **/ GVariant * nm_remote_connection_get_secrets (NMRemoteConnection *connection, @@ -544,42 +456,32 @@ nm_remote_connection_get_secrets (NMRemoteConnection *connection, GCancellable *cancellable, GError **error) { - NMRemoteConnectionPrivate *priv; + gs_unref_variant GVariant *ret = NULL; GVariant *secrets; g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), NULL); - - priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); - - if (nmdbus_settings_connection_call_get_secrets_sync (priv->proxy, - setting_name, - &secrets, - cancellable, error)) - return secrets; - else { - if (error && *error) - g_dbus_error_strip_remote_error (*error); + g_return_val_if_fail (setting_name, NULL); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL); + + ret = _nm_client_dbus_call_sync (_nm_object_get_client (connection), + cancellable, + _nm_object_get_path (connection), + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + "GetSecrets", + g_variant_new ("(s)", setting_name), + G_VARIANT_TYPE ("(a{sa{sv}})"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + TRUE, + error); + if (!ret) return NULL; - } -} -static void -get_secrets_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GVariant *secrets = NULL; - GError *error = NULL; - - if (nmdbus_settings_connection_call_get_secrets_finish (NMDBUS_SETTINGS_CONNECTION (proxy), - &secrets, result, &error)) - g_simple_async_result_set_op_res_gpointer (simple, secrets, (GDestroyNotify) g_variant_unref); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } + g_variant_get (ret, + "(@a{sa{sv}})", + &secrets); - g_simple_async_result_complete (simple); - g_object_unref (simple); + return secrets; } /** @@ -599,22 +501,24 @@ nm_remote_connection_get_secrets_async (NMRemoteConnection *connection, GAsyncReadyCallback callback, gpointer user_data) { - NMRemoteConnectionPrivate *priv; - GSimpleAsyncResult *simple; - g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); + g_return_if_fail (setting_name); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); - - simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data, - nm_remote_connection_get_secrets_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nmdbus_settings_connection_call_get_secrets (priv->proxy, - setting_name, - cancellable, - get_secrets_cb, simple); + _nm_client_dbus_call (_nm_object_get_client (connection), + connection, + nm_remote_connection_get_secrets_async, + cancellable, + callback, + user_data, + _nm_object_get_path (connection), + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + "GetSecrets", + g_variant_new ("(s)", setting_name), + G_VARIANT_TYPE ("(a{sa{sv}})"), + G_DBUS_CALL_FLAGS_NONE, + NM_DBUS_DEFAULT_TIMEOUT_MSEC, + nm_dbus_connection_call_finish_variant_strip_dbus_error_cb); } /** @@ -633,15 +537,21 @@ nm_remote_connection_get_secrets_finish (NMRemoteConnection *connection, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple; + gs_unref_variant GVariant *ret = NULL; + GVariant *secrets; - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_get_secrets_async), FALSE); + g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), NULL); + g_return_val_if_fail (nm_g_task_is_valid (result, connection, nm_remote_connection_get_secrets_async), FALSE); - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) + ret = g_task_propagate_pointer (G_TASK (result), error); + if (!ret) return NULL; - else - return g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple)); + + g_variant_get (ret, + "(@a{sa{sv}})", + &secrets); + + return secrets; } /** @@ -718,193 +628,94 @@ nm_remote_connection_get_visible (NMRemoteConnection *connection) /*****************************************************************************/ -static void -replace_settings (NMRemoteConnection *self, GVariant *new_settings) +GCancellable * +_nm_remote_settings_get_settings_prepare (NMRemoteConnection *self) { - GError *error = NULL; + NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); - if (!_nm_connection_replace_settings ((NMConnection *) self, - new_settings, - NM_SETTING_PARSE_FLAGS_BEST_EFFORT, - &error)) - g_clear_error (&error); + nm_clear_g_cancellable (&priv->get_settings_cancellable); + priv->get_settings_cancellable = g_cancellable_new (); + return priv->get_settings_cancellable; } -static void -updated_get_settings_cb (GObject *proxy, - GAsyncResult *result, - gpointer user_data) +void +_nm_remote_settings_get_settings_commit (NMRemoteConnection *self, + GVariant *settings) { - NMRemoteConnection *self = user_data; NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); - GVariant *new_settings; - gboolean visible; - - if (!nmdbus_settings_connection_call_get_settings_finish (priv->proxy, &new_settings, - result, NULL)) { - /* Connection is no longer visible to this user. */ - nm_connection_clear_settings (NM_CONNECTION (self)); + GError *error = NULL; + gboolean visible = FALSE; + gboolean changed = FALSE; - visible = FALSE; - } else { - replace_settings (self, new_settings); - g_variant_unref (new_settings); + g_clear_object (&priv->get_settings_cancellable); - visible = TRUE; + if (!priv->is_initialized) { + changed = TRUE; + priv->is_initialized = TRUE; } - if (visible != priv->visible) { + if (settings) { + if (!_nm_connection_replace_settings ((NMConnection *) self, + settings, + NM_SETTING_PARSE_FLAGS_BEST_EFFORT, + &error)) { + NML_NMCLIENT_LOG_E (_nm_object_get_client (self), "[%s] failure to update settings: %s", + _nm_object_get_path (self), + error->message); + g_clear_error (&error); + } else + visible = TRUE; + } else + nm_connection_clear_settings (NM_CONNECTION (self)); + + if (priv->visible != visible) { priv->visible = visible; - g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_VISIBLE); + _nm_client_queue_notify_object (_nm_object_get_client (self), + self, + obj_properties[PROP_VISIBLE]); + changed = TRUE; } - g_object_unref (self); -} - -static void -updated_cb (NMDBusSettingsConnection *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 */ - nmdbus_settings_connection_call_get_settings (priv->proxy, - NULL, - updated_get_settings_cb, - g_object_ref (self)); + if (changed) + _nm_client_notify_object_changed (_nm_object_get_client (self), _nm_object_get_dbobj (self)); } /*****************************************************************************/ -static void -init_dbus (NMObject *object) -{ - NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_REMOTE_CONNECTION_UNSAVED, &priv->unsaved }, - { NM_REMOTE_CONNECTION_FLAGS, &priv->flags }, - { NM_REMOTE_CONNECTION_FILENAME, &priv->filename }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_remote_connection_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_SETTINGS_CONNECTION, - property_info); -} - static gboolean -init_sync (GInitable *initable, GCancellable *cancellable, GError **error) +is_ready (NMObject *nmobj) { - NMRemoteConnection *self = NM_REMOTE_CONNECTION (initable); - NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable); - GVariant *settings; - - priv->proxy = NMDBUS_SETTINGS_CONNECTION (_nm_object_get_proxy (NM_OBJECT (initable), NM_DBUS_INTERFACE_SETTINGS_CONNECTION)); - g_signal_connect_object (priv->proxy, "updated", G_CALLBACK (updated_cb), initable, 0); - - if (nmdbus_settings_connection_call_get_settings_sync (priv->proxy, - &settings, - cancellable, - NULL)) { - priv->visible = TRUE; - replace_settings (self, settings); - g_variant_unref (settings); - } + NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (nmobj); - if (!nm_remote_connection_parent_initable_iface->init (initable, cancellable, error)) - return FALSE; + if (!priv->is_initialized) + return FALSE;; - return TRUE; + return NM_OBJECT_CLASS (nm_remote_connection_parent_class)->is_ready (nmobj); } -typedef struct { - NMRemoteConnection *connection; - GCancellable *cancellable; - GSimpleAsyncResult *result; - GAsyncInitable *initable; - int io_priority; -} NMRemoteConnectionInitData; - -static void -init_async_complete (NMRemoteConnectionInitData *init_data, GError *error) -{ - if (error) - g_simple_async_result_take_error (init_data->result, error); - else - g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE); - - g_simple_async_result_complete (init_data->result); - g_object_unref (init_data->result); - g_clear_object (&init_data->cancellable); - g_slice_free (NMRemoteConnectionInitData, init_data); -} - -static void -init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_data) -{ - NMRemoteConnectionInitData *init_data = user_data; - GError *error = NULL; - - init_async_complete (init_data, error); -} +/*****************************************************************************/ static void -init_get_settings_cb (GObject *proxy, - GAsyncResult *result, - gpointer user_data) +register_client (NMObject *nmobj, + NMClient *client, + NMLDBusObject *dbobj) { - NMRemoteConnectionInitData *init_data = user_data; - NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->initable); - GVariant *settings; - GError *error = NULL; - - if (!nmdbus_settings_connection_call_get_settings_finish (priv->proxy, &settings, - result, &error)) { - g_error_free (error); - } else { - priv->visible = TRUE; - replace_settings (NM_REMOTE_CONNECTION (init_data->initable), settings); - g_variant_unref (settings); - } - - nm_remote_connection_parent_async_initable_iface-> - init_async (init_data->initable, init_data->io_priority, init_data->cancellable, init_async_parent_inited, init_data); + NM_OBJECT_CLASS (nm_remote_connection_parent_class)->register_client (nmobj, client, dbobj); + nm_connection_set_path (NM_CONNECTION (nmobj), + dbobj->dbus_path->str); + _nm_client_get_settings_call (client, dbobj); } static void -init_async (GAsyncInitable *initable, int io_priority, - GCancellable *cancellable, GAsyncReadyCallback callback, - gpointer user_data) +unregister_client (NMObject *nmobj, + NMClient *client, + NMLDBusObject *dbobj) { - NMRemoteConnectionInitData *init_data; - NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable); - - init_data = g_slice_new0 (NMRemoteConnectionInitData); - init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback, - user_data, init_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (init_data->result, cancellable); - init_data->initable = initable; - init_data->io_priority = io_priority; - - priv->proxy = NMDBUS_SETTINGS_CONNECTION (_nm_object_get_proxy (NM_OBJECT (initable), - NM_DBUS_INTERFACE_SETTINGS_CONNECTION)); - - g_signal_connect_object (priv->proxy, "updated", - G_CALLBACK (updated_cb), initable, 0); - - nmdbus_settings_connection_call_get_settings (NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->initable)->proxy, - init_data->cancellable, - init_get_settings_cb, init_data); + nm_clear_g_cancellable (&NM_REMOTE_CONNECTION_GET_PRIVATE (nmobj)->get_settings_cancellable); + NM_OBJECT_CLASS (nm_remote_connection_parent_class)->unregister_client (nmobj, client, dbobj); } -static void -nm_remote_connection_init (NMRemoteConnection *self) -{ -} +/*****************************************************************************/ static void get_property (GObject *object, guint prop_id, @@ -929,13 +740,11 @@ get_property (GObject *object, guint prop_id, } } +/*****************************************************************************/ + static void -constructed (GObject *object) +nm_remote_connection_init (NMRemoteConnection *self) { - G_OBJECT_CLASS (nm_remote_connection_parent_class)->constructed (object); - - nm_connection_set_path (NM_CONNECTION (object), - nm_object_get_path (NM_OBJECT (object))); } static void @@ -943,40 +752,46 @@ dispose (GObject *object) { NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (object); - g_clear_object (&priv->proxy); nm_clear_g_free (&priv->filename); G_OBJECT_CLASS (nm_remote_connection_parent_class)->dispose (object); } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_settings_connection = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + nm_remote_connection_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_S ("Filename", PROP_FILENAME, NMRemoteConnection, _priv.filename ), + NML_DBUS_META_PROPERTY_INIT_U ("Flags", PROP_FLAGS, NMRemoteConnection, _priv.flags ), + NML_DBUS_META_PROPERTY_INIT_B ("Unsaved", PROP_UNSAVED, NMRemoteConnection, _priv.unsaved ), + ), +); + static void -nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class) +nm_remote_connection_class_init (NMRemoteConnectionClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (remote_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (remote_class); - - g_type_class_add_private (object_class, sizeof (NMRemoteConnectionPrivate)); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); - /* virtual methods */ - object_class->constructed = constructed; object_class->get_property = get_property; - object_class->dispose = dispose; + object_class->dispose = dispose; - nm_object_class->init_dbus = init_dbus; + nm_object_class->is_ready = is_ready; + nm_object_class->register_client = register_client; + nm_object_class->unregister_client = unregister_client; - /* Properties */ /** * NMRemoteConnection:unsaved: * * %TRUE if the remote connection contains changes that have not been saved * to disk, %FALSE if the connection is the same as its on-disk representation. **/ - g_object_class_install_property - (object_class, PROP_UNSAVED, - g_param_spec_boolean (NM_REMOTE_CONNECTION_UNSAVED, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_UNSAVED] = + g_param_spec_boolean (NM_REMOTE_CONNECTION_UNSAVED, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMRemoteConnection:flags: @@ -986,12 +801,11 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class) * * Since: 1.12 **/ - g_object_class_install_property - (object_class, PROP_FLAGS, - g_param_spec_uint (NM_REMOTE_CONNECTION_FLAGS, "", "", - 0, G_MAXUINT32, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_FLAGS] = + g_param_spec_uint (NM_REMOTE_CONNECTION_FLAGS, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMRemoteConnection:filename: @@ -1001,12 +815,11 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class) * * Since: 1.12 **/ - g_object_class_install_property - (object_class, PROP_FILENAME, - g_param_spec_string (NM_REMOTE_CONNECTION_FILENAME, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_FILENAME] = + g_param_spec_string (NM_REMOTE_CONNECTION_FILENAME, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMRemoteConnection:visible: @@ -1019,31 +832,16 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class) * to callers, but it is possible for a connection's visibility to change * after you already have a reference to it.) **/ - g_object_class_install_property - (object_class, PROP_VISIBLE, - g_param_spec_boolean (NM_REMOTE_CONNECTION_VISIBLE, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); -} + obj_properties[PROP_VISIBLE] = + g_param_spec_boolean (NM_REMOTE_CONNECTION_VISIBLE, "", "", + FALSE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); -static void -nm_remote_connection_connection_iface_init (NMConnectionInterface *iface) -{ -} - -static void -nm_remote_connection_initable_iface_init (GInitableIface *iface) -{ - nm_remote_connection_parent_initable_iface = g_type_interface_peek_parent (iface); - - iface->init = init_sync; + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_settings_connection); } static void -nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface) +nm_remote_connection_connection_iface_init (NMConnectionInterface *iface) { - nm_remote_connection_parent_async_initable_iface = g_type_interface_peek_parent (iface); - - iface->init_async = init_async; } diff --git a/libnm/nm-remote-connection.h b/libnm/nm-remote-connection.h index 1fed4feb..ed05daad 100644 --- a/libnm/nm-remote-connection.h +++ b/libnm/nm-remote-connection.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2011 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2011 Red Hat, Inc. */ #ifndef __NM_REMOTE_CONNECTION_H__ @@ -47,16 +33,7 @@ G_BEGIN_DECLS /** * NMRemoteConnection: */ -struct _NMRemoteConnection { - NMObject parent; -}; - -typedef struct { - NMObjectClass parent_class; - - /*< private >*/ - gpointer padding[8]; -} NMRemoteConnectionClass; +typedef struct _NMRemoteConnectionClass NMRemoteConnectionClass; GType nm_remote_connection_get_type (void); @@ -73,10 +50,12 @@ GVariant *nm_remote_connection_update2_finish (NMRemoteConnection *connection, GAsyncResult *result, GError **error); +_NM_DEPRECATED_SYNC_METHOD gboolean nm_remote_connection_commit_changes (NMRemoteConnection *connection, gboolean save_to_disk, GCancellable *cancellable, GError **error); + void nm_remote_connection_commit_changes_async (NMRemoteConnection *connection, gboolean save_to_disk, GCancellable *cancellable, @@ -86,9 +65,11 @@ gboolean nm_remote_connection_commit_changes_finish (NMRemoteConnection *connect GAsyncResult *result, GError **error); +_NM_DEPRECATED_SYNC_METHOD gboolean nm_remote_connection_save (NMRemoteConnection *connection, GCancellable *cancellable, GError **error); + void nm_remote_connection_save_async (NMRemoteConnection *connection, GCancellable *cancellable, GAsyncReadyCallback callback, @@ -97,9 +78,11 @@ gboolean nm_remote_connection_save_finish (NMRemoteConnection *connection, GAsyncResult *result, GError **error); +_NM_DEPRECATED_SYNC_METHOD gboolean nm_remote_connection_delete (NMRemoteConnection *connection, GCancellable *cancellable, GError **error); + void nm_remote_connection_delete_async (NMRemoteConnection *connection, GCancellable *cancellable, GAsyncReadyCallback callback, @@ -108,10 +91,12 @@ gboolean nm_remote_connection_delete_finish (NMRemoteConnection *connection, GAsyncResult *result, GError **error); +_NM_DEPRECATED_SYNC_METHOD GVariant *nm_remote_connection_get_secrets (NMRemoteConnection *connection, const char *setting_name, GCancellable *cancellable, GError **error); + void nm_remote_connection_get_secrets_async (NMRemoteConnection *connection, const char *setting_name, GCancellable *cancellable, diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c deleted file mode 100644 index 916884ea..00000000 --- a/libnm/nm-remote-settings.c +++ /dev/null @@ -1,825 +0,0 @@ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2008 Novell, Inc. - * Copyright 2009 - 2012 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include "nm-remote-settings.h" - -#include "c-list/src/c-list.h" -#include "nm-dbus-interface.h" -#include "nm-connection.h" -#include "nm-client.h" -#include "nm-remote-connection.h" -#include "nm-remote-connection-private.h" -#include "nm-object-private.h" -#include "nm-dbus-helpers.h" -#include "nm-core-internal.h" - -#include "introspection/org.freedesktop.NetworkManager.Settings.h" - -G_DEFINE_TYPE (NMRemoteSettings, nm_remote_settings, NM_TYPE_OBJECT) - -#define NM_REMOTE_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsPrivate)) - -typedef struct { - NMDBusSettings *proxy; - GPtrArray *all_connections; - GPtrArray *visible_connections; - - /* AddConnectionInfo objects that are waiting for the connection to become initialized */ - CList add_lst_head; - - char *hostname; - gboolean can_modify; -} NMRemoteSettingsPrivate; - -enum { - PROP_0, - PROP_CONNECTIONS, - PROP_HOSTNAME, - PROP_CAN_MODIFY, - - LAST_PROP -}; - -/* Signals */ -enum { - CONNECTION_ADDED, - CONNECTION_REMOVED, - - LAST_SIGNAL -}; -static guint signals[LAST_SIGNAL] = { 0 }; - -/*****************************************************************************/ - -typedef struct { - CList add_lst; - NMRemoteSettings *self; - NMRemoteSettingAddConnection2Callback callback; - gpointer user_data; - GCancellable *cancellable; - char *path; - GVariant *results; - gulong cancellable_id; - NMSettingsAddConnection2Flags flags; - bool ignore_out_result:1; -} AddConnectionInfo; - -static AddConnectionInfo * -_add_connection_info_find (NMRemoteSettings *self, const char *path) -{ - NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); - AddConnectionInfo *info; - - c_list_for_each_entry (info, &priv->add_lst_head, add_lst) { - if (nm_streq0 (info->path, path)) - return info; - } - return NULL; -} - -static void -_add_connection_info_complete (AddConnectionInfo *info, - NMRemoteConnection *connection, - GError *error_take) -{ - nm_assert (info); - - c_list_unlink_stale (&info->add_lst); - - nm_clear_g_signal_handler (info->cancellable, &info->cancellable_id); - - if ( info->cancellable - && !nm_utils_error_is_cancelled (error_take, FALSE)) { - GError *error2 = NULL; - - if (g_cancellable_set_error_if_cancelled (info->cancellable, &error2)) { - g_clear_error (&error_take); - error_take = error2; - connection = NULL; - } - } - - info->callback (info->self, - connection, - connection ? info->results : NULL, - error_take, - info->user_data); - - g_clear_error (&error_take); - - g_object_unref (info->self); - nm_g_object_unref (info->cancellable); - nm_clear_g_free (&info->path); - nm_g_variant_unref (info->results); - - nm_g_slice_free (info); -} - -static void -_add_connection_info_cancelled (GCancellable *cancellable, - AddConnectionInfo *info) -{ - _add_connection_info_complete (info, - NULL, - g_error_new_literal (G_IO_ERROR, - G_IO_ERROR_CANCELLED, - "Operation was cancelled")); -} - -typedef const char * (*ConnectionStringGetter) (NMConnection *); - -static NMRemoteConnection * -get_connection_by_string (NMRemoteSettings *settings, - const char *string, - ConnectionStringGetter get_comparison_string) -{ - NMRemoteSettingsPrivate *priv; - NMConnection *candidate; - int i; - - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - - for (i = 0; i < priv->visible_connections->len; i++) { - candidate = priv->visible_connections->pdata[i]; - if (!g_strcmp0 (string, get_comparison_string (candidate))) - return NM_REMOTE_CONNECTION (candidate); - } - - return NULL; -} - -NMRemoteConnection * -nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, const char *id) -{ - g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL); - g_return_val_if_fail (id != NULL, NULL); - - return get_connection_by_string (settings, id, nm_connection_get_id); -} - -NMRemoteConnection * -nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, const char *path) -{ - g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL); - g_return_val_if_fail (path != NULL, NULL); - - return get_connection_by_string (settings, path, nm_connection_get_path); -} - -NMRemoteConnection * -nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings, const char *uuid) -{ - g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL); - g_return_val_if_fail (uuid != NULL, NULL); - - return get_connection_by_string (settings, uuid, nm_connection_get_uuid); -} - -static void -connection_visible_changed (GObject *object, - GParamSpec *pspec, - gpointer user_data) -{ - NMRemoteConnection *connection = NM_REMOTE_CONNECTION (object); - NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data); - - if (nm_remote_connection_get_visible (connection)) - g_signal_emit (self, signals[CONNECTION_ADDED], 0, connection); - else - g_signal_emit (self, signals[CONNECTION_REMOVED], 0, connection); -} - -static void -cleanup_connection (NMRemoteSettings *self, - NMRemoteConnection *remote) -{ - g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (connection_visible_changed), self); -} - -static void -connection_removed (NMRemoteSettings *self, - NMRemoteConnection *remote) -{ - NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); - gboolean still_exists = FALSE; - int i; - - /* Check if the connection was actually removed or if it just turned invisible. */ - for (i = 0; i < priv->all_connections->len; i++) { - if (remote == priv->all_connections->pdata[i]) { - still_exists = TRUE; - break; - } - } - - if (!still_exists) - cleanup_connection (self, remote); - - /* Allow the signal to propagate if and only if @remote was in visible_connections */ - if (!g_ptr_array_remove (priv->visible_connections, remote)) - g_signal_stop_emission (self, signals[CONNECTION_REMOVED], 0); -} - -static void -connection_added (NMRemoteSettings *self, - NMRemoteConnection *remote) -{ - NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); - AddConnectionInfo *info; - const char *path; - - if (!g_signal_handler_find (remote, G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, 0, NULL, - G_CALLBACK (connection_visible_changed), self)) { - g_signal_connect (remote, - "notify::" NM_REMOTE_CONNECTION_VISIBLE, - G_CALLBACK (connection_visible_changed), - self); - } - - if (nm_remote_connection_get_visible (remote)) - g_ptr_array_add (priv->visible_connections, remote); - else - g_signal_stop_emission (self, signals[CONNECTION_ADDED], 0); - - path = nm_connection_get_path (NM_CONNECTION (remote)); - info = _add_connection_info_find (self, path); - if (info) - _add_connection_info_complete (info, remote, NULL); -} - -static void -object_creation_failed (NMObject *object, - const char *failed_path) -{ - NMRemoteSettings *self = NM_REMOTE_SETTINGS (object); - AddConnectionInfo *info; - - info = _add_connection_info_find (self, failed_path); - if (!info) - return; - - _add_connection_info_complete (info, - NULL, - g_error_new_literal (NM_CLIENT_ERROR, - NM_CLIENT_ERROR_OBJECT_CREATION_FAILED, - _("Connection removed before it was initialized"))); -} - -const GPtrArray * -nm_remote_settings_get_connections (NMRemoteSettings *settings) -{ - g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL); - - return NM_REMOTE_SETTINGS_GET_PRIVATE (settings)->visible_connections; -} - -static void -add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data) -{ - AddConnectionInfo *info = user_data; - GError *error = NULL; - - if ( info->ignore_out_result - && info->flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK) { - nmdbus_settings_call_add_connection_finish (NMDBUS_SETTINGS (proxy), - &info->path, - result, - &error); - } else if ( info->ignore_out_result - && info->flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY) { - nmdbus_settings_call_add_connection_unsaved_finish (NMDBUS_SETTINGS (proxy), - &info->path, - result, - &error); - } else { - nmdbus_settings_call_add_connection2_finish (NMDBUS_SETTINGS (proxy), - &info->path, - &info->results, - result, - &error); - if (info->ignore_out_result) { - /* despite we have the result, the caller didn't ask for it. - * Through it away, so we consistently don't return a result. */ - nm_clear_pointer (&info->results, g_variant_unref); - } - } - - if (error) { - g_dbus_error_strip_remote_error (error); - _add_connection_info_complete (info, NULL, error); - return; - } - - /* On success, we still have to wait until the connection is fully - * initialized before calling the callback. - */ - if (info->cancellable) { - gulong id; - - id = g_cancellable_connect (info->cancellable, - G_CALLBACK (_add_connection_info_cancelled), - info, - NULL); - if (id == 0) { - /* the callback was invoked synchronously, which destroyed @info. - * We must not touch @info anymore. */ - } else - info->cancellable_id = id; - } -} - -void -nm_remote_settings_add_connection2 (NMRemoteSettings *self, - GVariant *settings, - NMSettingsAddConnection2Flags flags, - GVariant *args, - gboolean ignore_out_result, - GCancellable *cancellable, - NMRemoteSettingAddConnection2Callback callback, - gpointer user_data) -{ - NMRemoteSettingsPrivate *priv; - AddConnectionInfo *info; - - nm_assert (NM_IS_REMOTE_SETTINGS (self)); - nm_assert (g_variant_is_of_type (settings, G_VARIANT_TYPE ("a{sa{sv}}"))); - nm_assert (!args || g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}"))); - nm_assert (callback); - - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); - - info = g_slice_new (AddConnectionInfo); - *info = (AddConnectionInfo) { - .self = g_object_ref (self), - .cancellable = nm_g_object_ref (cancellable), - .flags = flags, - .ignore_out_result = ignore_out_result, - .callback = callback, - .user_data = user_data, - }; - c_list_link_tail (&priv->add_lst_head, &info->add_lst); - - /* Although AddConnection2() being capable to handle also AddConnection() and - * AddConnectionUnsaved() variants, we prefer to use the old D-Bus methods when - * they are sufficient. The reason is that libnm should avoid hard dependencies - * on 1.20 API whenever possible. */ - if ( ignore_out_result - && flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK) { - nmdbus_settings_call_add_connection (priv->proxy, - settings, - cancellable, - add_connection_done, - info); - } else if ( ignore_out_result - && flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY) { - nmdbus_settings_call_add_connection_unsaved (priv->proxy, - settings, - cancellable, - add_connection_done, - info); - } else { - nmdbus_settings_call_add_connection2 (priv->proxy, - settings, - flags, - args - ?: g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0), - cancellable, - add_connection_done, - info); - } -} - -gboolean -nm_remote_settings_load_connections (NMRemoteSettings *settings, - char **filenames, - char ***failures, - GCancellable *cancellable, - GError **error) -{ - NMRemoteSettingsPrivate *priv; - gboolean success; - - g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); - g_return_val_if_fail (filenames != NULL, FALSE); - - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - - if (!nmdbus_settings_call_load_connections_sync (priv->proxy, - (const char * const *) filenames, - &success, - failures, - cancellable, error)) { - if (error && *error) - g_dbus_error_strip_remote_error (*error); - success = FALSE; - } - return success; -} - -static void -load_connections_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - gboolean success; - char **failures = NULL; - - if (nmdbus_settings_call_load_connections_finish (NMDBUS_SETTINGS (proxy), - &success, &failures, - result, &error)) - g_simple_async_result_set_op_res_gpointer (simple, failures, (GDestroyNotify) g_strfreev); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - - g_simple_async_result_complete (simple); - g_object_unref (simple); -} - -void -nm_remote_settings_load_connections_async (NMRemoteSettings *settings, - char **filenames, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - NMRemoteSettingsPrivate *priv; - GSimpleAsyncResult *simple; - - g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings)); - g_return_if_fail (filenames != NULL); - - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - - simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data, - nm_remote_settings_load_connections_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nmdbus_settings_call_load_connections (priv->proxy, - (const char * const *) filenames, - cancellable, load_connections_cb, simple); -} - -gboolean -nm_remote_settings_load_connections_finish (NMRemoteSettings *settings, - char ***failures, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (settings), nm_remote_settings_load_connections_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else { - *failures = g_strdupv (g_simple_async_result_get_op_res_gpointer (simple)); - return TRUE; - } -} - -gboolean -nm_remote_settings_reload_connections (NMRemoteSettings *settings, - GCancellable *cancellable, - GError **error) -{ - NMRemoteSettingsPrivate *priv; - gboolean success; - - g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); - - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - - if (!nmdbus_settings_call_reload_connections_sync (priv->proxy, &success, - cancellable, error)) { - if (error && *error) - g_dbus_error_strip_remote_error (*error); - success = FALSE; - } - - return success; -} - -static void -reload_connections_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - gboolean success; - GError *error = NULL; - - if (nmdbus_settings_call_reload_connections_finish (NMDBUS_SETTINGS (proxy), - &success, - result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, success); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - - g_simple_async_result_complete (simple); - g_object_unref (simple); -} - -void -nm_remote_settings_reload_connections_async (NMRemoteSettings *settings, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - NMRemoteSettingsPrivate *priv; - GSimpleAsyncResult *simple; - - g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings)); - - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - - simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data, - nm_remote_settings_reload_connections_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nmdbus_settings_call_reload_connections (priv->proxy, cancellable, - reload_connections_cb, simple); -} - -gboolean -nm_remote_settings_reload_connections_finish (NMRemoteSettings *settings, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (settings), nm_remote_settings_reload_connections_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); -} - -gboolean -nm_remote_settings_save_hostname (NMRemoteSettings *settings, - const char *hostname, - GCancellable *cancellable, - GError **error) -{ - NMRemoteSettingsPrivate *priv; - gboolean ret; - - g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); - - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - - ret = nmdbus_settings_call_save_hostname_sync (priv->proxy, - hostname ?: "", - cancellable, error); - if (error && *error) - g_dbus_error_strip_remote_error (*error); - return ret; -} - -static void -save_hostname_cb (GObject *proxy, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - GError *error = NULL; - - if (nmdbus_settings_call_save_hostname_finish (NMDBUS_SETTINGS (proxy), result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { - g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); - } - g_simple_async_result_complete (simple); - g_object_unref (simple); -} - -void -nm_remote_settings_save_hostname_async (NMRemoteSettings *settings, - const char *hostname, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - NMRemoteSettingsPrivate *priv; - GSimpleAsyncResult *simple; - - g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings)); - - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - - simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data, - nm_remote_settings_save_hostname_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); - - nmdbus_settings_call_save_hostname (priv->proxy, - hostname ?: "", - cancellable, save_hostname_cb, simple); -} - -gboolean -nm_remote_settings_save_hostname_finish (NMRemoteSettings *settings, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (settings), nm_remote_settings_save_hostname_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); -} - -/*****************************************************************************/ - -static void -nm_remote_settings_init (NMRemoteSettings *self) -{ - NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); - - c_list_init (&priv->add_lst_head); - priv->all_connections = g_ptr_array_new (); - priv->visible_connections = g_ptr_array_new (); -} - -static void -init_dbus (NMObject *object) -{ - NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_REMOTE_SETTINGS_CONNECTIONS, &priv->all_connections, NULL, NM_TYPE_REMOTE_CONNECTION, "connection" }, - { NM_REMOTE_SETTINGS_HOSTNAME, &priv->hostname }, - { NM_REMOTE_SETTINGS_CAN_MODIFY, &priv->can_modify }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_remote_settings_parent_class)->init_dbus (object); - - priv->proxy = NMDBUS_SETTINGS (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_SETTINGS)); - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_SETTINGS, - property_info); -} - -static GObject * -constructor (GType type, - guint n_construct_params, - GObjectConstructParam *construct_params) -{ - guint i; - const char *dbus_path; - - /* Fill in the right D-Bus path if none was specified */ - for (i = 0; i < n_construct_params; i++) { - if (strcmp (construct_params[i].pspec->name, NM_OBJECT_PATH) == 0) { - dbus_path = g_value_get_string (construct_params[i].value); - if (dbus_path == NULL) { - g_value_set_static_string (construct_params[i].value, NM_DBUS_PATH_SETTINGS); - } else { - if (!g_variant_is_object_path (dbus_path)) { - g_warning ("Passed D-Bus object path '%s' is invalid; using default '%s' instead", - dbus_path, NM_DBUS_PATH); - g_value_set_static_string (construct_params[i].value, NM_DBUS_PATH_SETTINGS); - } - } - break; - } - } - - return G_OBJECT_CLASS (nm_remote_settings_parent_class)->constructor (type, - n_construct_params, - construct_params); -} - -static void -dispose (GObject *object) -{ - NMRemoteSettings *self = NM_REMOTE_SETTINGS (object); - NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); - guint i; - - if (priv->all_connections) { - for (i = 0; i < priv->all_connections->len; i++) - cleanup_connection (self, priv->all_connections->pdata[i]); - g_clear_pointer (&priv->all_connections, g_ptr_array_unref); - } - - g_clear_pointer (&priv->visible_connections, g_ptr_array_unref); - g_clear_pointer (&priv->hostname, g_free); - g_clear_object (&priv->proxy); - - G_OBJECT_CLASS (nm_remote_settings_parent_class)->dispose (object); -} - -static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_CONNECTIONS: - g_value_take_boxed (value, _nm_utils_copy_object_array (priv->visible_connections)); - break; - case PROP_HOSTNAME: - g_value_set_string (value, priv->hostname); - break; - case PROP_CAN_MODIFY: - g_value_set_boolean (value, priv->can_modify); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -nm_remote_settings_class_init (NMRemoteSettingsClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (class); - - g_type_class_add_private (class, sizeof (NMRemoteSettingsPrivate)); - - /* Virtual methods */ - object_class->constructor = constructor; - object_class->get_property = get_property; - object_class->dispose = dispose; - - nm_object_class->init_dbus = init_dbus; - nm_object_class->object_creation_failed = object_creation_failed; - - class->connection_added = connection_added; - class->connection_removed = connection_removed; - - /* Properties */ - - g_object_class_install_property - (object_class, PROP_CONNECTIONS, - g_param_spec_boxed (NM_REMOTE_SETTINGS_CONNECTIONS, "", "", - G_TYPE_PTR_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_HOSTNAME, - g_param_spec_string (NM_REMOTE_SETTINGS_HOSTNAME, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - g_object_class_install_property - (object_class, PROP_CAN_MODIFY, - g_param_spec_boolean (NM_REMOTE_SETTINGS_CAN_MODIFY, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - /* Signals */ - signals[CONNECTION_ADDED] = - g_signal_new (NM_REMOTE_SETTINGS_CONNECTION_ADDED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMRemoteSettingsClass, connection_added), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - NM_TYPE_REMOTE_CONNECTION); - - signals[CONNECTION_REMOVED] = - g_signal_new (NM_REMOTE_SETTINGS_CONNECTION_REMOVED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMRemoteSettingsClass, connection_removed), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - NM_TYPE_REMOTE_CONNECTION); -} diff --git a/libnm/nm-remote-settings.h b/libnm/nm-remote-settings.h deleted file mode 100644 index bd89cf8c..00000000 --- a/libnm/nm-remote-settings.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2008 Novell, Inc. - * Copyright 2009 - 2011 Red Hat, Inc. - */ - -#ifndef __NM_REMOTE_SETTINGS_H__ -#define __NM_REMOTE_SETTINGS_H__ - -#if !((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE) -#error Cannot use this header. -#endif - -#include "nm-object.h" - -#define NM_TYPE_REMOTE_SETTINGS (nm_remote_settings_get_type ()) -#define NM_REMOTE_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettings)) -#define NM_REMOTE_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsClass)) -#define NM_IS_REMOTE_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_REMOTE_SETTINGS)) -#define NM_IS_REMOTE_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_REMOTE_SETTINGS)) -#define NM_REMOTE_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsClass)) - -#define NM_REMOTE_SETTINGS_CONNECTIONS "connections" -#define NM_REMOTE_SETTINGS_HOSTNAME "hostname" -#define NM_REMOTE_SETTINGS_CAN_MODIFY "can-modify" - -#define NM_REMOTE_SETTINGS_CONNECTION_ADDED "connection-added" -#define NM_REMOTE_SETTINGS_CONNECTION_REMOVED "connection-removed" - -typedef struct _NMRemoteSettings NMRemoteSettings; -typedef struct _NMRemoteSettingsClass NMRemoteSettingsClass; - -/** - * NMRemoteSettings: - */ -struct _NMRemoteSettings { - NMObject parent; -}; - -struct _NMRemoteSettingsClass { - NMObjectClass parent; - - void (*connection_added) (NMRemoteSettings *settings, - NMRemoteConnection *connection); - void (*connection_removed) (NMRemoteSettings *settings, - NMRemoteConnection *connection); -}; - -GType nm_remote_settings_get_type (void); - -const GPtrArray *nm_remote_settings_get_connections (NMRemoteSettings *settings); - -NMRemoteConnection *nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, - const char *id); - -NMRemoteConnection *nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, - const char *path); - -NMRemoteConnection *nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings, - const char *uuid); - -typedef void (*NMRemoteSettingAddConnection2Callback) (NMRemoteSettings *self, - NMRemoteConnection *connection, - GVariant *results, - GError *error, - gpointer user_data); - -void nm_remote_settings_add_connection2 (NMRemoteSettings *self, - GVariant *settings, - NMSettingsAddConnection2Flags flags, - GVariant *args, - gboolean ignore_out_result, - GCancellable *cancellable, - NMRemoteSettingAddConnection2Callback callback, - gpointer user_data); - -gboolean nm_remote_settings_load_connections (NMRemoteSettings *settings, - char **filenames, - char ***failures, - GCancellable *cancellable, - GError **error); -void nm_remote_settings_load_connections_async (NMRemoteSettings *settings, - char **filenames, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean nm_remote_settings_load_connections_finish (NMRemoteSettings *settings, - char ***failures, - GAsyncResult *result, - GError **error); - -gboolean nm_remote_settings_reload_connections (NMRemoteSettings *settings, - GCancellable *cancellable, - GError **error); -void nm_remote_settings_reload_connections_async (NMRemoteSettings *settings, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean nm_remote_settings_reload_connections_finish (NMRemoteSettings *settings, - GAsyncResult *result, - GError **error); - -gboolean nm_remote_settings_save_hostname (NMRemoteSettings *settings, - const char *hostname, - GCancellable *cancellable, - GError **error); -void nm_remote_settings_save_hostname_async (NMRemoteSettings *settings, - const char *hostname, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean nm_remote_settings_save_hostname_finish (NMRemoteSettings *settings, - GAsyncResult *result, - GError **error); - -#endif /* __NM_REMOTE_SETTINGS_H__ */ diff --git a/libnm/nm-secret-agent-old.c b/libnm/nm-secret-agent-old.c index 2f8c4682..f0836b24 100644 --- a/libnm/nm-secret-agent-old.c +++ b/libnm/nm-secret-agent-old.c @@ -1,36 +1,26 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2010 - 2011 Red Hat, Inc. + * Copyright (C) 2010 - 2011 Red Hat, Inc. */ #include "nm-default.h" #include "nm-secret-agent-old.h" +#include "c-list/src/c-list.h" +#include "nm-core-internal.h" +#include "nm-dbus-helpers.h" #include "nm-dbus-interface.h" #include "nm-enum-types.h" -#include "nm-dbus-helpers.h" +#include "nm-glib-aux/nm-dbus-aux.h" +#include "nm-glib-aux/nm-time-utils.h" #include "nm-simple-connection.h" -#include "nm-core-internal.h" -#include "c-list/src/c-list.h" #include "introspection/org.freedesktop.NetworkManager.SecretAgent.h" #include "introspection/org.freedesktop.NetworkManager.AgentManager.h" +#define REGISTER_RETRY_TIMEOUT_MSEC 2000 + /*****************************************************************************/ typedef struct { @@ -59,9 +49,10 @@ typedef struct { NMSecretAgentCapabilities capabilities; + gint64 registering_timeout_msec; + guint registering_try_count; + bool registered:1; - bool registering:1; - bool private_bus:1; bool session_bus:1; bool auto_register:1; bool suppress_auto:1; @@ -79,6 +70,20 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMSecretAgentOld, nm_secret_agent_old, G_TYPE_ /*****************************************************************************/ +#define _NMLOG(level, ...) \ + NML_DBUS_LOG((level), \ + "secret-agent["NM_HASH_OBFUSCATE_PTR_FMT"]: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ + NM_HASH_OBFUSCATE_PTR (self) \ + _NM_UTILS_MACRO_REST (__VA_ARGS__)) + +/*****************************************************************************/ + +static void _register_call_cb (GObject *proxy, + GAsyncResult *result, + gpointer user_data); + +/*****************************************************************************/ + static void _internal_unregister (NMSecretAgentOld *self) { @@ -87,7 +92,7 @@ _internal_unregister (NMSecretAgentOld *self) if (priv->registered) { g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (priv->dbus_secret_agent)); priv->registered = FALSE; - priv->registering = FALSE; + priv->registering_timeout_msec = 0; _notify (self, PROP_REGISTERED); } } @@ -112,7 +117,7 @@ should_auto_register (NMSecretAgentOld *self) return ( priv->auto_register && !priv->suppress_auto && !priv->registered - && !priv->registering); + && priv->registering_timeout_msec == 0); } static void @@ -126,6 +131,9 @@ name_owner_changed (GObject *proxy, GetSecretsInfo *info; owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy)); + + _LOGT ("name owner changed: %s%s%s", NM_PRINT_FMT_QUOTE_STRING (owner)); + if (owner) { if (should_auto_register (self)) nm_secret_agent_old_register_async (self, NULL, NULL, NULL); @@ -155,12 +163,6 @@ verify_sender (NMSecretAgentOld *self, g_return_val_if_fail (context != NULL, FALSE); - /* Private bus connection is always to NetworkManager, which is always - * UID 0. - */ - if (priv->private_bus) - return TRUE; - /* Verify that the sender is the same as NetworkManager's bus name owner. */ owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (priv->manager_proxy)); @@ -465,8 +467,6 @@ check_nm_running (NMSecretAgentOld *self, GError **error) NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); gs_free char *owner = NULL; - if (priv->private_bus) - return TRUE; owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (priv->manager_proxy)); if (owner) return TRUE; @@ -478,6 +478,23 @@ check_nm_running (NMSecretAgentOld *self, GError **error) /*****************************************************************************/ +static gboolean +_register_should_retry (NMSecretAgentOldPrivate *priv, + guint *out_timeout_msec) +{ + guint timeout_msec; + + if (priv->registering_try_count++ == 0) + timeout_msec = 0; + else if (nm_utils_get_monotonic_timestamp_ms () < priv->registering_timeout_msec) + timeout_msec = 1ULL * (1ULL << NM_MIN (7, priv->registering_try_count)); + else + return FALSE; + + *out_timeout_msec = timeout_msec; + return TRUE; +} + /** * nm_secret_agent_old_register: * @self: a #NMSecretAgentOld @@ -506,7 +523,7 @@ nm_secret_agent_old_register (NMSecretAgentOld *self, priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); g_return_val_if_fail (priv->registered == FALSE, FALSE); - g_return_val_if_fail (priv->registering == FALSE, FALSE); + g_return_val_if_fail (priv->registering_timeout_msec == 0, FALSE); g_return_val_if_fail (priv->bus != NULL, FALSE); g_return_val_if_fail (priv->manager_proxy != NULL, FALSE); @@ -528,98 +545,177 @@ nm_secret_agent_old_register (NMSecretAgentOld *self, error)) return FALSE; - priv->registering = TRUE; - if (nmdbus_agent_manager_call_register_with_capabilities_sync (priv->manager_proxy, - priv->identifier, - priv->capabilities, - cancellable, NULL)) - goto success; + priv->registering_timeout_msec = nm_utils_get_monotonic_timestamp_ms () + REGISTER_RETRY_TIMEOUT_MSEC; + priv->registering_try_count = 0; + + while (TRUE) { + gs_free_error GError *local = NULL; + + nmdbus_agent_manager_call_register_with_capabilities_sync (priv->manager_proxy, + priv->identifier, + priv->capabilities, + cancellable, + &local); + if (nm_dbus_error_is (local, NM_DBUS_ERROR_NAME_UNKNOWN_METHOD)) { + guint timeout_msec; + + if (_register_should_retry (priv, &timeout_msec)) { + if (timeout_msec > 0) + g_usleep (timeout_msec * 1000LU); + continue; + } + } - /* Might be an old NetworkManager that doesn't support capabilities; - * fall back to old Register() method instead. - */ - if (nmdbus_agent_manager_call_register_sync (priv->manager_proxy, - priv->identifier, - cancellable, error)) - goto success; + priv->registering_timeout_msec = 0; - /* Failure */ - priv->registering = FALSE; - _internal_unregister (self); - return FALSE; + if (local) { + g_dbus_error_strip_remote_error (local); + g_propagate_error (error, g_steal_pointer (&local)); + _internal_unregister (self); + return FALSE; + } -success: - priv->registering = FALSE; - priv->registered = TRUE; - _notify (self, PROP_REGISTERED); - return TRUE; + priv->registered = TRUE; + _notify (self, PROP_REGISTERED); + return TRUE; + } } +/*****************************************************************************/ + +typedef struct { + GCancellable *cancellable; + GSource *timeout_source; + gulong cancellable_signal_id; +} RegisterData; + static void -reg_result (NMSecretAgentOld *self, GSimpleAsyncResult *simple, GError *error) +_register_data_free (RegisterData *register_data) +{ + nm_clear_g_cancellable_disconnect (register_data->cancellable, ®ister_data->cancellable_signal_id); + nm_clear_g_source_inst (®ister_data->timeout_source); + g_clear_object (®ister_data->cancellable); + nm_g_slice_free (register_data); +} + +static gboolean +_register_retry_cb (gpointer user_data) { + gs_unref_object GTask *task = user_data; + NMSecretAgentOld *self = g_task_get_source_object (task); NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); - _nm_unused gs_unref_object GSimpleAsyncResult *simple_free = simple; + GCancellable *cancellable; - priv->registering = FALSE; + _LOGT ("register: retry registration..."); - if (error) { - g_simple_async_result_take_error (simple, error); - g_simple_async_result_complete (simple); + g_task_set_task_data (task, NULL, NULL); - /* If registration failed we shouldn't expose ourselves on the bus */ - _internal_unregister (self); - } else { - priv->registered = TRUE; - _notify (self, PROP_REGISTERED); + cancellable = g_task_get_cancellable (task); - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - g_simple_async_result_complete (simple); - } + nmdbus_agent_manager_call_register_with_capabilities (priv->manager_proxy, + priv->identifier, + priv->capabilities, + cancellable, + _register_call_cb, + g_steal_pointer (&task)); + return G_SOURCE_REMOVE; } static void -reg_request_cb (GObject *proxy, - GAsyncResult *result, - gpointer user_data) +_register_cancelled_cb (GCancellable *cancellable, + gpointer user_data) { - GSimpleAsyncResult *simple = user_data; - NMSecretAgentOld *self; + gs_unref_object GTask *task = user_data; + NMSecretAgentOld *self = g_task_get_source_object (task); + RegisterData *register_data = g_task_get_task_data (task); GError *error = NULL; - self = NM_SECRET_AGENT_OLD (g_async_result_get_source_object (G_ASYNC_RESULT (simple))); - g_object_unref (self); /* drop extra ref added by get_source_object() */ + nm_clear_g_signal_handler (register_data->cancellable, ®ister_data->cancellable_signal_id); + g_task_set_task_data (task, NULL, NULL); - if (!nmdbus_agent_manager_call_register_finish (NMDBUS_AGENT_MANAGER (proxy), result, &error)) - g_dbus_error_strip_remote_error (error); - reg_result (self, simple, error); + _LOGT ("register: registration cancelled. Stop waiting..."); + + nm_utils_error_set_cancelled (&error, FALSE, NULL); + g_task_return_error (task, error); } static void -reg_with_caps_cb (GObject *proxy, - GAsyncResult *result, - gpointer user_data) +_register_call_cb (GObject *proxy, + GAsyncResult *result, + gpointer user_data) { - GSimpleAsyncResult *simple = user_data; - NMSecretAgentOld *self; - NMSecretAgentOldPrivate *priv; + gs_unref_object GTask *task = user_data; + NMSecretAgentOld *self = g_task_get_source_object (task); + NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); + gs_free_error GError *error = NULL; + + nmdbus_agent_manager_call_register_with_capabilities_finish (NMDBUS_AGENT_MANAGER (proxy), result, &error); + + if (nm_utils_error_is_cancelled (error, FALSE)) { + /* FIXME: we should unregister right away. For now, don't do that, likely the + * application is anyway about to exit. */ + } else if (nm_dbus_error_is (error, NM_DBUS_ERROR_NAME_UNKNOWN_METHOD)) { + gboolean already_cancelled = FALSE; + RegisterData *register_data; + guint timeout_msec; + + if (!_register_should_retry (priv, &timeout_msec)) + goto done; + + _LOGT ("register: registration failed with error \"%s\". Retry in %u msec...", error->message, timeout_msec); + nm_assert (G_IS_TASK (task)); + nm_assert (!g_task_get_task_data (task)); + + register_data = g_slice_new (RegisterData); + + *register_data = (RegisterData) { + .cancellable = nm_g_object_ref (g_task_get_cancellable (task)), + }; + + g_task_set_task_data (task, + register_data, + (GDestroyNotify) _register_data_free); + + if (register_data->cancellable) { + register_data->cancellable_signal_id = g_cancellable_connect (register_data->cancellable, + G_CALLBACK (_register_cancelled_cb), + task, + NULL); + if (register_data->cancellable_signal_id == 0) + already_cancelled = TRUE; + } - self = NM_SECRET_AGENT_OLD (g_async_result_get_source_object (G_ASYNC_RESULT (simple))); - g_object_unref (self); /* drop extra ref added by get_source_object() */ + if (!already_cancelled) { + register_data->timeout_source = nm_g_source_attach (nm_g_timeout_source_new (timeout_msec, + g_task_get_priority (task), + _register_retry_cb, + task, + NULL), + g_task_get_context (task)); + } - priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); + /* The reference of the task is owned by the _register_cancelled_cb and _register_retry_cb actions. + * Whichever completes first, will consume it. */ + g_steal_pointer (&task); + return; + } + +done: + priv->registering_timeout_msec = 0; - if (nmdbus_agent_manager_call_register_with_capabilities_finish (NMDBUS_AGENT_MANAGER (proxy), result, NULL)) { - reg_result (self, simple, NULL); + if (error) { + _LOGT ("register: registration failed with error \"%s\"", error->message); + g_dbus_error_strip_remote_error (error); + _internal_unregister (self); + g_task_return_error (task, g_steal_pointer (&error)); return; } - /* Might be an old NetworkManager that doesn't support capabilities; - * fall back to old Register() method instead. - */ - nmdbus_agent_manager_call_register (priv->manager_proxy, - priv->identifier, - NULL, reg_request_cb, simple); + _LOGT ("register: registration succeeded"); + priv->registered = TRUE; + _notify (self, PROP_REGISTERED); + + g_task_return_boolean (task, TRUE); } /** @@ -644,15 +740,15 @@ nm_secret_agent_old_register_async (NMSecretAgentOld *self, { NMSecretAgentOldPrivate *priv; NMSecretAgentOldClass *class; - gs_unref_object GSimpleAsyncResult *simple = NULL; - GError *error = NULL; + gs_unref_object GTask *task = NULL; + gs_free_error GError *error = NULL; g_return_if_fail (NM_IS_SECRET_AGENT_OLD (self)); priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); g_return_if_fail (priv->registered == FALSE); - g_return_if_fail (priv->registering == FALSE); + g_return_if_fail (priv->registering_timeout_msec == 0); g_return_if_fail (priv->bus != NULL); g_return_if_fail (priv->manager_proxy != NULL); @@ -662,14 +758,11 @@ nm_secret_agent_old_register_async (NMSecretAgentOld *self, g_return_if_fail (class->save_secrets != NULL); g_return_if_fail (class->delete_secrets != NULL); - simple = g_simple_async_result_new (G_OBJECT (self), callback, user_data, - nm_secret_agent_old_register_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); + task = nm_g_task_new (self, cancellable, nm_secret_agent_old_register_async, callback, user_data); if (!check_nm_running (self, &error)) { - g_simple_async_result_take_error (simple, error); - g_simple_async_result_complete_in_idle (simple); + _LOGT ("register: failed because NetworkManager is not running"); + g_task_return_error (task, g_steal_pointer (&error)); return; } @@ -678,20 +771,22 @@ nm_secret_agent_old_register_async (NMSecretAgentOld *self, priv->bus, NM_DBUS_PATH_SECRET_AGENT, &error)) { - g_simple_async_result_take_error (simple, error); - g_simple_async_result_complete_in_idle (simple); + _LOGT ("register: failed to export D-Bus service: %s", error->message); + g_task_return_error (task, g_steal_pointer (&error)); return; } priv->suppress_auto = FALSE; - priv->registering = TRUE; + priv->registering_timeout_msec = nm_utils_get_monotonic_timestamp_ms () + REGISTER_RETRY_TIMEOUT_MSEC; + priv->registering_try_count = 0; + _LOGT ("register: starting asynchronous registration..."); nmdbus_agent_manager_call_register_with_capabilities (priv->manager_proxy, priv->identifier, priv->capabilities, - NULL, - reg_with_caps_cb, - g_steal_pointer (&simple)); + cancellable, + _register_call_cb, + g_steal_pointer (&task)); } /** @@ -709,12 +804,10 @@ nm_secret_agent_old_register_finish (NMSecretAgentOld *self, GAsyncResult *result, GError **error) { - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self), nm_secret_agent_old_register_async), FALSE); + g_return_val_if_fail (NM_IS_SECRET_AGENT_OLD (self), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, self, nm_secret_agent_old_register_async), FALSE); - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) - return FALSE; - else - return TRUE; + return g_task_propagate_boolean (G_TASK (result), error); } /** @@ -757,24 +850,21 @@ nm_secret_agent_old_unregister (NMSecretAgentOld *self, static void unregister_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - gs_unref_object GSimpleAsyncResult *simple = user_data; - NMSecretAgentOld *self; - GError *error = NULL; - - self = NM_SECRET_AGENT_OLD (g_async_result_get_source_object (G_ASYNC_RESULT (simple))); - g_object_unref (self); /* drop extra ref added by get_source_object() */ + gs_unref_object GTask *task = user_data; + NMSecretAgentOld *self = g_task_get_source_object (task); + gs_free_error GError *error = NULL; _internal_unregister (self); - if (nmdbus_agent_manager_call_unregister_finish (NMDBUS_AGENT_MANAGER (proxy), - result, &error)) - g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { + if (!nmdbus_agent_manager_call_unregister_finish (NMDBUS_AGENT_MANAGER (proxy), + result, + &error)) { g_dbus_error_strip_remote_error (error); - g_simple_async_result_take_error (simple, error); + g_task_return_error (task, g_steal_pointer (&error)); + return; } - g_simple_async_result_complete (simple); + g_task_return_boolean (task, TRUE); } /** @@ -795,8 +885,8 @@ nm_secret_agent_old_unregister_async (NMSecretAgentOld *self, gpointer user_data) { NMSecretAgentOldPrivate *priv; - gs_unref_object GSimpleAsyncResult *simple = NULL; - GError *error = NULL; + gs_unref_object GTask *task = NULL; + gs_free_error GError *error = NULL; g_return_if_fail (NM_IS_SECRET_AGENT_OLD (self)); @@ -805,14 +895,10 @@ nm_secret_agent_old_unregister_async (NMSecretAgentOld *self, g_return_if_fail (priv->bus != NULL); g_return_if_fail (priv->manager_proxy != NULL); - simple = g_simple_async_result_new (G_OBJECT (self), callback, user_data, - nm_secret_agent_old_unregister_async); - if (cancellable) - g_simple_async_result_set_check_cancellable (simple, cancellable); + task = nm_g_task_new (self, cancellable, nm_secret_agent_old_unregister_async, callback, user_data); if (!check_nm_running (self, &error)) { - g_simple_async_result_take_error (simple, error); - g_simple_async_result_complete_in_idle (simple); + g_task_return_error (task, g_steal_pointer (&error)); return; } @@ -821,7 +907,7 @@ nm_secret_agent_old_unregister_async (NMSecretAgentOld *self, nmdbus_agent_manager_call_unregister (priv->manager_proxy, cancellable, unregister_cb, - g_steal_pointer (&simple)); + g_steal_pointer (&task)); } /** @@ -839,12 +925,10 @@ nm_secret_agent_old_unregister_finish (NMSecretAgentOld *self, GAsyncResult *result, GError **error) { - g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self), nm_secret_agent_old_unregister_async), FALSE); + g_return_val_if_fail (NM_IS_SECRET_AGENT_OLD (self), FALSE); + g_return_val_if_fail (nm_g_task_is_valid (result, self, nm_secret_agent_old_unregister_async), FALSE); - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error)) - return FALSE; - else - return TRUE; + return g_task_propagate_boolean (G_TASK (result), error); } /** @@ -995,80 +1079,66 @@ init_common (NMSecretAgentOld *self) { NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); - priv->private_bus = _nm_dbus_is_connection_private (priv->bus); - - if (priv->private_bus == FALSE) { - priv->session_bus = _nm_dbus_bus_type () == G_BUS_TYPE_SESSION; + priv->session_bus = _nm_dbus_bus_type () == G_BUS_TYPE_SESSION; - g_signal_connect (priv->manager_proxy, "notify::g-name-owner", - G_CALLBACK (name_owner_changed), self); - } -} - -typedef struct { - NMSecretAgentOld *self; - GCancellable *cancellable; - GSimpleAsyncResult *simple; -} InitData; - -static void -init_async_complete (InitData *init_data, GError *error) -{ - if (!error) - g_simple_async_result_set_op_res_gboolean (init_data->simple, TRUE); - else - g_simple_async_result_take_error (init_data->simple, error); - - g_simple_async_result_complete_in_idle (init_data->simple); - - g_object_unref (init_data->simple); - g_clear_object (&init_data->cancellable); - g_slice_free (InitData, init_data); + g_signal_connect (priv->manager_proxy, "notify::g-name-owner", + G_CALLBACK (name_owner_changed), self); } static void init_async_registered (GObject *object, GAsyncResult *result, gpointer user_data) { - NMSecretAgentOld *self = NM_SECRET_AGENT_OLD (object); - InitData *init_data = user_data; + gs_unref_object GTask *task = user_data; + NMSecretAgentOld *self = g_task_get_source_object (task); GError *error = NULL; nm_secret_agent_old_register_finish (self, result, &error); - init_async_complete (init_data, error); + + if (error) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); } static void init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data) { - InitData *init_data = user_data; - NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (init_data->self); + gs_unref_object GTask *task = user_data; + NMSecretAgentOld *self = g_task_get_source_object (task); + NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); GError *error = NULL; priv->manager_proxy = nmdbus_agent_manager_proxy_new_finish (result, &error); if (!priv->manager_proxy) { - init_async_complete (init_data, error); + g_task_return_error (task, error); return; } - init_common (init_data->self); + init_common (self); + + if (!priv->auto_register) { + g_task_return_boolean (task, TRUE); + return; + } - if (priv->auto_register) { - nm_secret_agent_old_register_async (init_data->self, init_data->cancellable, - init_async_registered, init_data); - } else - init_async_complete (init_data, NULL); + nm_secret_agent_old_register_async (self, + g_task_get_cancellable (task), + init_async_registered, + task); + g_steal_pointer (&task); } static void init_async_got_bus (GObject *initable, GAsyncResult *result, gpointer user_data) { - InitData *init_data = user_data; - NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (init_data->self); + gs_unref_object GTask *task = user_data; + NMSecretAgentOld *self = g_task_get_source_object (task); + NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); GError *error = NULL; - priv->bus = _nm_dbus_new_connection_finish (result, &error); + priv->bus = g_bus_get_finish (result, &error); if (!priv->bus) { - init_async_complete (init_data, error); + g_task_return_error (task, error); return; } @@ -1077,8 +1147,10 @@ init_async_got_bus (GObject *initable, GAsyncResult *result, gpointer user_data) | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NM_DBUS_SERVICE, NM_DBUS_PATH_AGENT_MANAGER, - init_data->cancellable, - init_async_got_proxy, init_data); + g_task_get_cancellable (task), + init_async_got_proxy, + task); + g_steal_pointer (&task); } /*****************************************************************************/ @@ -1147,6 +1219,8 @@ nm_secret_agent_old_init (NMSecretAgentOld *self) { NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); + _LOGT ("create new instance"); + c_list_init (&priv->gsi_lst_head); priv->dbus_secret_agent = nmdbus_secret_agent_skeleton_new (); _nm_dbus_bind_properties (self, priv->dbus_secret_agent); @@ -1164,7 +1238,9 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) NMSecretAgentOld *self = NM_SECRET_AGENT_OLD (initable); NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); - priv->bus = _nm_dbus_new_connection (cancellable, error); + _LOGT ("init-sync"); + + priv->bus = g_bus_get_sync (_nm_dbus_bus_type (), cancellable, error); if (!priv->bus) return FALSE; @@ -1192,33 +1268,17 @@ init_async (GAsyncInitable *initable, int io_priority, gpointer user_data) { NMSecretAgentOld *self = NM_SECRET_AGENT_OLD (initable); - InitData *init_data; - - init_data = g_slice_new (InitData); - *init_data = (InitData) { - .self = self, - .cancellable = nm_g_object_ref (cancellable), - .simple = g_simple_async_result_new (G_OBJECT (initable), - callback, - user_data, - init_async), - }; + GTask *task; - if (cancellable) - g_simple_async_result_set_check_cancellable (init_data->simple, cancellable); + _LOGT ("init-async starting..."); - _nm_dbus_new_connection_async (cancellable, init_async_got_bus, init_data); -} - -static gboolean -init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error) -{ - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); + task = g_task_new (self, cancellable, callback, user_data); + g_task_set_priority (task, io_priority); - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return TRUE; + g_bus_get (_nm_dbus_bus_type (), + cancellable, + init_async_got_bus, + task); } static void @@ -1228,6 +1288,8 @@ dispose (GObject *object) NMSecretAgentOldPrivate *priv = NM_SECRET_AGENT_OLD_GET_PRIVATE (self); GetSecretsInfo *info; + _LOGT ("disposing"); + if (priv->registered) { priv->registered = FALSE; nm_secret_agent_old_unregister_async (self, NULL, NULL, NULL); @@ -1344,5 +1406,5 @@ static void nm_secret_agent_old_async_initable_iface_init (GAsyncInitableIface *iface) { iface->init_async = init_async; - iface->init_finish = init_finish; + /* Use default implementation for init_finish */ } diff --git a/libnm/nm-secret-agent-old.h b/libnm/nm-secret-agent-old.h index 1a5ee742..af0dabe7 100644 --- a/libnm/nm-secret-agent-old.h +++ b/libnm/nm-secret-agent-old.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2010 - 2011 Red Hat, Inc. + * Copyright (C) 2010 - 2011 Red Hat, Inc. */ #ifndef __NM_SECRET_AGENT_OLD_H__ diff --git a/libnm/nm-settings-docs.xml b/libnm/nm-settings-docs.xml index 85e5b7dc..08178df5 100644 --- a/libnm/nm-settings-docs.xml +++ b/libnm/nm-settings-docs.xml @@ -57,8 +57,8 @@ <property name="phase1-peaplabel" name_upper="PHASE1_PEAPLABEL" type="string" description="Forces use of the new PEAP label during key derivation. Some RADIUS servers may require forcing the new PEAP label to interoperate with PEAPv1. Set to "1" to force use of the new PEAP label. See the wpa_supplicant documentation for more details." /> <property name="phase1-peapver" name_upper="PHASE1_PEAPVER" type="string" description="Forces which PEAP version is used when PEAP is set as the EAP method in the "eap" property. When unset, the version reported by the server will be used. Sometimes when using older RADIUS servers, it is necessary to force the client to use a particular PEAP version. To do so, this property may be set to "0" or "1" to force that specific PEAP version." /> <property name="phase2-altsubject-matches" name_upper="PHASE2_ALTSUBJECT_MATCHES" type="array of string" description="List of strings to be matched against the altSubjectName of the certificate presented by the authentication server during the inner "phase 2" authentication. If the list is empty, no verification of the server certificate's altSubjectName is performed." /> - <property name="phase2-auth" name_upper="PHASE2_AUTH" type="string" description="Specifies the allowed "phase 2" inner non-EAP authentication methods when an EAP method that uses an inner TLS tunnel is specified in the "eap" property. Recognized non-EAP "phase 2" methods are "pap", "chap", "mschap", "mschapv2", "gtc", "otp", "md5", and "tls". Each "phase 2" inner method requires specific parameters for successful authentication; see the wpa_supplicant documentation for more details." /> - <property name="phase2-autheap" name_upper="PHASE2_AUTHEAP" type="string" description="Specifies the allowed "phase 2" inner EAP-based authentication methods when an EAP method that uses an inner TLS tunnel is specified in the "eap" property. Recognized EAP-based "phase 2" methods are "md5", "mschapv2", "otp", "gtc", and "tls". Each "phase 2" inner method requires specific parameters for successful authentication; see the wpa_supplicant documentation for more details." /> + <property name="phase2-auth" name_upper="PHASE2_AUTH" type="string" description="Specifies the allowed "phase 2" inner non-EAP authentication method when an EAP method that uses an inner TLS tunnel is specified in the "eap" property. Recognized non-EAP "phase 2" methods are "pap", "chap", "mschap", "mschapv2", "gtc", "otp", "md5", and "tls". Each "phase 2" inner method requires specific parameters for successful authentication; see the wpa_supplicant documentation for more details." /> + <property name="phase2-autheap" name_upper="PHASE2_AUTHEAP" type="string" description="Specifies the allowed "phase 2" inner EAP-based authentication method when an EAP method that uses an inner TLS tunnel is specified in the "eap" property. Recognized EAP-based "phase 2" methods are "md5", "mschapv2", "otp", "gtc", and "tls". Each "phase 2" inner method requires specific parameters for successful authentication; see the wpa_supplicant documentation for more details." /> <property name="phase2-ca-cert" name_upper="PHASE2_CA_CERT" type="byte array" description="Contains the "phase 2" CA certificate if used by the EAP method specified in the "phase2-auth" or "phase2-autheap" properties. Certificate data is specified using a "scheme"; two are currently supported: blob and path. When using the blob scheme (which is backwards compatible with NM 0.7.x) this property should be set to the certificate's DER encoded data. When using the path scheme, this property should be set to the full UTF-8 encoded path of the certificate, prefixed with the string "file://" and ending with a terminating NUL byte. This property can be unset even if the EAP method supports CA certificates, but this allows man-in-the-middle attacks and is NOT recommended." /> <property name="phase2-ca-cert-password" name_upper="PHASE2_CA_CERT_PASSWORD" type="string" description="The password used to access the "phase2" CA certificate stored in "phase2-ca-cert" property. Only makes sense if the certificate is stored on a PKCS#11 token that requires a login." /> <property name="phase2-ca-cert-password-flags" name_upper="PHASE2_CA_CERT_PASSWORD_FLAGS" type="NMSettingSecretFlags (uint32)" description="Flags indicating how to handle the "phase2-ca-cert-password" property." /> @@ -149,6 +149,7 @@ </setting> <setting name="gsm" description="GSM-based Mobile Broadband Settings" name_upper="GSM" > <property name="apn" name_upper="APN" type="string" description="The GPRS Access Point Name specifying the APN used when establishing a data session with the GSM-based network. The APN often determines how the user will be billed for their network usage and whether the user has access to the Internet or just a provider-specific walled-garden, so it is important to use the correct APN for the user's mobile broadband plan. The APN may only be composed of the characters a-z, 0-9, ., and - per GSM 03.60 Section 14.9." /> + <property name="auto-config" name_upper="AUTO_CONFIG" type="boolean" default="FALSE" description="When TRUE, the settings such as APN, username, or password will default to values that match the network the modem will register to in the Mobile Broadband Provider database." /> <property name="device-id" name_upper="DEVICE_ID" type="string" description="The device unique identifier (as given by the WWAN management service) which this connection applies to. If given, the connection will only apply to the specified device." /> <property name="home-only" name_upper="HOME_ONLY" type="boolean" default="FALSE" description="When TRUE, only connections to the home network will be allowed. Connections to roaming networks will not be made." /> <property name="mtu" name_upper="MTU" type="uint32" default="0" description="If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple frames." /> @@ -176,6 +177,8 @@ <property name="dhcp-client-id" name_upper="DHCP_CLIENT_ID" type="string" description="A string sent to the DHCP server to identify the local machine which the DHCP server may use to customize the DHCP lease and options. When the property is a hex string ('aa:bb:cc') it is interpreted as a binary client ID, in which case the first byte is assumed to be the 'type' field as per RFC 2132 section 9.14 and the remaining bytes may be an hardware address (e.g. '01:xx:xx:xx:xx:xx:xx' where 1 is the Ethernet ARP type and the rest is a MAC address). If the property is not a hex string it is considered as a non-hardware-address client ID and the 'type' field is set to 0. The special values "mac" and "perm-mac" are supported, which use the current or permanent MAC address of the device to generate a client identifier with type ethernet (01). Currently, these options only work for ethernet type of links. The special value "duid" generates a RFC4361-compliant client identifier based on a hash of the interface name as IAID and /etc/machine-id. The special value "stable" is supported to generate a type 0 client identifier based on the stable-id (see connection.stable-id) and a per-host key. If you set the stable-id, you may want to include the "${DEVICE}" or "${MAC}" specifier to get a per-device key. If unset, a globally configured default is used. If still unset, the default depends on the DHCP plugin." /> <property name="dhcp-fqdn" name_upper="DHCP_FQDN" type="string" description="If the "dhcp-send-hostname" property is TRUE, then the specified FQDN will be sent to the DHCP server when acquiring a lease. This property and "dhcp-hostname" are mutually exclusive and cannot be set at the same time." /> <property name="dhcp-hostname" name_upper="DHCP_HOSTNAME" type="string" description="If the "dhcp-send-hostname" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and "dhcp-fqdn" are mutually exclusive and cannot be set at the same time." /> + <property name="dhcp-hostname-flags" name_upper="DHCP_HOSTNAME_FLAGS" type="uint32" default="0" description="Flags for the DHCP hostname and FQDN. Currently this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests." /> + <property name="dhcp-iaid" name_upper="DHCP_IAID" type="string" description="A string containing the "Identity Association Identifier" (IAID) used by the DHCP client. The property is a 32-bit decimal value or a special value among "mac", "perm-mac", "ifname" and "stable". When set to "mac" (or "perm-mac"), the last 4 bytes of the current (or permanent) MAC address are used as IAID. When set to "ifname", the IAID is computed by hashing the interface name. The special value "stable" can be used to generate an IAID based on the stable-id (see connection.stable-id), a per-host key and the interface name. When the property is unset, the value from global configuration is used; if no global default is set then the IAID is assumed to be "ifname". Note that at the moment this property is ignored for IPv6 by dhclient, which always derives the IAID from the MAC address." /> <property name="dhcp-send-hostname" name_upper="DHCP_SEND_HOSTNAME" type="boolean" default="TRUE" description="If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the "dhcp-hostname" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent." /> <property name="dhcp-timeout" name_upper="DHCP_TIMEOUT" type="int32" default="0" description="A timeout for a DHCP transaction in seconds." /> <property name="dns" name_upper="DNS" type="array of uint32" description="Array of IP addresses of DNS servers (as network-byte-order integers)" /> @@ -200,6 +203,8 @@ <property name="dad-timeout" name_upper="DAD_TIMEOUT" type="int32" default="-1" description="Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4." /> <property name="dhcp-duid" name_upper="DHCP_DUID" type="string" description="A string containing the DHCPv6 Unique Identifier (DUID) used by the dhcp client to identify itself to DHCPv6 servers (RFC 3315). The DUID is carried in the Client Identifier option. If the property is a hex string ('aa:bb:cc') it is interpreted as a binary DUID and filled as an opaque value in the Client Identifier option. The special value "lease" will retrieve the DUID previously used from the lease file belonging to the connection. If no DUID is found and "dhclient" is the configured dhcp client, the DUID is searched in the system-wide dhclient lease file. If still no DUID is found, or another dhcp client is used, a global and permanent DUID-UUID (RFC 6355) will be generated based on the machine-id. The special values "llt" and "ll" will generate a DUID of type LLT or LL (see RFC 3315) based on the current MAC address of the device. In order to try providing a stable DUID-LLT, the time field will contain a constant timestamp that is used globally (for all profiles) and persisted to disk. The special values "stable-llt", "stable-ll" and "stable-uuid" will generate a DUID of the corresponding type, derived from the connection's stable-id and a per-host unique key. You may want to include the "${DEVICE}" or "${MAC}" specifier in the stable-id, in case this profile gets activated on multiple devices. So, the link-layer address of "stable-ll" and "stable-llt" will be a generated address derived from the stable id. The DUID-LLT time value in the "stable-llt" option will be picked among a static timespan of three years (the upper bound of the interval is the same constant timestamp used in "llt"). When the property is unset, the global value provided for "ipv6.dhcp-duid" is used. If no global value is provided, the default "lease" value is assumed." /> <property name="dhcp-hostname" name_upper="DHCP_HOSTNAME" type="string" description="If the "dhcp-send-hostname" property is TRUE, then the specified name will be sent to the DHCP server when acquiring a lease. This property and "dhcp-fqdn" are mutually exclusive and cannot be set at the same time." /> + <property name="dhcp-hostname-flags" name_upper="DHCP_HOSTNAME_FLAGS" type="uint32" default="0" description="Flags for the DHCP hostname and FQDN. Currently this property only includes flags to control the FQDN flags set in the DHCP FQDN option. Supported FQDN flags are NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) and NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE (0x4). When no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is set, the DHCP FQDN option will contain no flag. Otherwise, if no FQDN flag is set and NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS (0x8) is not set, the standard FQDN flags are set in the request: NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1), NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED (0x2) for IPv4 and NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE (0x1) for IPv6. When this property is set to the default value NM_DHCP_HOSTNAME_FLAG_NONE (0x0), a global default is looked up in NetworkManager configuration. If that value is unset or also NM_DHCP_HOSTNAME_FLAG_NONE (0x0), then the standard FQDN flags described above are sent in the DHCP requests." /> + <property name="dhcp-iaid" name_upper="DHCP_IAID" type="string" description="A string containing the "Identity Association Identifier" (IAID) used by the DHCP client. The property is a 32-bit decimal value or a special value among "mac", "perm-mac", "ifname" and "stable". When set to "mac" (or "perm-mac"), the last 4 bytes of the current (or permanent) MAC address are used as IAID. When set to "ifname", the IAID is computed by hashing the interface name. The special value "stable" can be used to generate an IAID based on the stable-id (see connection.stable-id), a per-host key and the interface name. When the property is unset, the value from global configuration is used; if no global default is set then the IAID is assumed to be "ifname". Note that at the moment this property is ignored for IPv6 by dhclient, which always derives the IAID from the MAC address." /> <property name="dhcp-send-hostname" name_upper="DHCP_SEND_HOSTNAME" type="boolean" default="TRUE" description="If TRUE, a hostname is sent to the DHCP server when acquiring a lease. Some DHCP servers use this hostname to update DNS databases, essentially providing a static hostname for the computer. If the "dhcp-hostname" property is NULL and this property is TRUE, the current persistent hostname of the computer is sent." /> <property name="dhcp-timeout" name_upper="DHCP_TIMEOUT" type="int32" default="0" description="A timeout for a DHCP transaction in seconds." /> <property name="dns" name_upper="DNS" type="array of byte array" description="Array of IP addresses of DNS servers (in network byte order)" /> @@ -467,7 +472,7 @@ <property name="auth-alg" name_upper="AUTH_ALG" type="string" description="When WEP is used (ie, key-mgmt = "none" or "ieee8021x") indicate the 802.11 authentication algorithm required by the AP here. One of "open" for Open System, "shared" for Shared Key, or "leap" for Cisco LEAP. When using Cisco LEAP (ie, key-mgmt = "ieee8021x" and auth-alg = "leap") the "leap-username" and "leap-password" properties must be specified." /> <property name="fils" name_upper="FILS" type="int32" default="0" description="Indicates whether Fast Initial Link Setup (802.11ai) must be enabled for the connection. One of NM_SETTING_WIRELESS_SECURITY_FILS_DEFAULT (0) (use global default value), NM_SETTING_WIRELESS_SECURITY_FILS_DISABLE (1) (disable FILS), NM_SETTING_WIRELESS_SECURITY_FILS_OPTIONAL (2) (enable FILS if the supplicant and the access point support it) or NM_SETTING_WIRELESS_SECURITY_FILS_REQUIRED (3) (enable FILS and fail if not supported). When set to NM_SETTING_WIRELESS_SECURITY_FILS_DEFAULT (0) and no global default is set, FILS will be optionally enabled." /> <property name="group" name_upper="GROUP" type="array of string" description="A list of group/broadcast encryption algorithms which prevents connections to Wi-Fi networks that do not utilize one of the algorithms in the list. For maximum compatibility leave this property empty. Each list element may be one of "wep40", "wep104", "tkip", or "ccmp"." /> - <property name="key-mgmt" name_upper="KEY_MGMT" type="string" description="Key management used for the connection. One of "none" (WEP), "ieee8021x" (Dynamic WEP), "wpa-none" (Ad-Hoc WPA-PSK), "wpa-psk" (infrastructure WPA-PSK), "sae" (SAE) or "wpa-eap" (WPA-Enterprise). This property must be set for any Wi-Fi connection that uses security." /> + <property name="key-mgmt" name_upper="KEY_MGMT" type="string" description="Key management used for the connection. One of "none" (WEP), "ieee8021x" (Dynamic WEP), "wpa-psk" (infrastructure WPA-PSK), "sae" (SAE) or "wpa-eap" (WPA-Enterprise). This property must be set for any Wi-Fi connection that uses security." /> <property name="leap-password" name_upper="LEAP_PASSWORD" type="string" description="The login password for legacy LEAP connections (ie, key-mgmt = "ieee8021x" and auth-alg = "leap")." /> <property name="leap-password-flags" name_upper="LEAP_PASSWORD_FLAGS" type="NMSettingSecretFlags (uint32)" description="Flags indicating how to handle the "leap-password" property." /> <property name="leap-username" name_upper="LEAP_USERNAME" type="string" description="The login username for legacy LEAP connections (ie, key-mgmt = "ieee8021x" and auth-alg = "leap")." /> diff --git a/libnm/nm-settings-ifcfg-rh-docs.xml b/libnm/nm-settings-ifcfg-rh-docs.xml index 0ee1d86a..7bed7f4d 100644 --- a/libnm/nm-settings-ifcfg-rh-docs.xml +++ b/libnm/nm-settings-ifcfg-rh-docs.xml @@ -219,7 +219,9 @@ but in route6-* file instead in the form of command line for 'ip route add& <property name="ignore-auto-routes" variable="IPV6_PEERROUTES(+)" format="" values="" default="yes" example="" description="IPV6_PEERROUTES has the opposite meaning as 'ignore-auto-routes' property."/> <property name="ignore-auto-dns" variable="IPV6_PEERDNS(+)" format="" values="" default="yes" example="" description="IPV6_PEERDNS has the opposite meaning as 'ignore-auto-dns' property."/> <property name="dhcp-hostname" variable="DHCPV6_HOSTNAME" format="" values="" default="" example="" description="Hostname to send the DHCP server."/> -<property name="never-default" variable="IPV6_DEFROUTE(+), (and IPV6_DEFAULTGW, IPV6_DEFAULTDEV in /etc/sysconfig/network)" format="" values="" default="IPV6_DEFROUTE=yes (when no variable specified)" example="" description="IPV6_DEFROUTE=no tells NetworkManager that this connection +<property name="never-default" variable="IPV6_DEFROUTE(+), (and IPV6_DEFAULTGW, IPV6_DEFAULTDEV in /etc/sysconfig/network)" format="" values="" default="IPV6_DEFROUTE=yes (when no variable specified)" example="DHCPV6_HOSTNAME_FLAGS=5 +*/ +" description="IPV6_DEFROUTE=no tells NetworkManager that this connection should not be assigned the default IPv6 route. IPV6_DEFROUTE has the opposite meaning as 'never-default' property."/> <property name="may-fail" variable="IPV6_FAILURE_FATAL(+)" format="" values="" default="no" example="" description="IPV6_FAILURE_FATAL has the opposite meaning as 'may-fail' property."/> diff --git a/libnm/nm-types.h b/libnm/nm-types.h index ce010964..11e9f055 100644 --- a/libnm/nm-types.h +++ b/libnm/nm-types.h @@ -1,20 +1,6 @@ -/* NetworkManager -- Network link manager - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2014 - 2018 Red Hat, Inc. +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2014 - 2018 Red Hat, Inc. */ #ifndef __NM_TYPES_H__ diff --git a/libnm/nm-vpn-connection.c b/libnm/nm-vpn-connection.c index 15e0e645..26980229 100644 --- a/libnm/nm-vpn-connection.c +++ b/libnm/nm-vpn-connection.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2012 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2012 Red Hat, Inc. */ #include "nm-default.h" @@ -28,34 +14,43 @@ #include "nm-active-connection.h" #include "nm-dbus-helpers.h" -#include "introspection/org.freedesktop.NetworkManager.VPN.Connection.h" +/*****************************************************************************/ -G_DEFINE_TYPE (NMVpnConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION) +NM_GOBJECT_PROPERTIES_DEFINE (NMVpnConnection, + PROP_VPN_STATE, + PROP_BANNER, +); -#define NM_VPN_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_VPN_CONNECTION, NMVpnConnectionPrivate)) +enum { + VPN_STATE_CHANGED, -G_STATIC_ASSERT (sizeof (NMVpnConnectionStateReason) == sizeof (NMActiveConnectionStateReason)); + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; typedef struct { char *banner; - NMVpnConnectionState vpn_state; + guint32 vpn_state; + guint32 reason; } NMVpnConnectionPrivate; -enum { - PROP_0, - PROP_VPN_STATE, - PROP_BANNER, +struct _NMVpnConnection { + NMActiveConnection parent; + NMVpnConnectionPrivate _priv; +}; - LAST_PROP +struct _NMVpnConnectionClass { + NMActiveConnectionClass parent; }; -enum { - VPN_STATE_CHANGED, +G_DEFINE_TYPE (NMVpnConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION) - LAST_SIGNAL -}; +#define NM_VPN_CONNECTION_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMVpnConnection, NM_IS_VPN_CONNECTION, NMObject, NMActiveConnection) -static guint signals[LAST_SIGNAL] = { 0 }; +G_STATIC_ASSERT (sizeof (NMVpnConnectionStateReason) == sizeof (NMActiveConnectionStateReason)); + +/*****************************************************************************/ /** * nm_vpn_connection_get_banner: @@ -71,7 +66,7 @@ nm_vpn_connection_get_banner (NMVpnConnection *vpn) { g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), NULL); - return nm_str_not_empty (NM_VPN_CONNECTION_GET_PRIVATE (vpn)->banner); + return _nml_coerce_property_str_not_empty (NM_VPN_CONNECTION_GET_PRIVATE (vpn)->banner); } /** @@ -90,20 +85,48 @@ nm_vpn_connection_get_vpn_state (NMVpnConnection *vpn) return NM_VPN_CONNECTION_GET_PRIVATE (vpn)->vpn_state; } +/*****************************************************************************/ + static void -vpn_state_changed_proxy (NMDBusVpnConnection *proxy, - guint vpn_state, - guint reason, - gpointer user_data) +_notify_event_state_changed (NMClient *client, + NMClientNotifyEventWithPtr *notify_event) +{ + gs_unref_object NMVpnConnection *self = notify_event->user_data; + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); + + /* we expose here the value cache in @priv. In practice, this is the same + * value as we received from the signal. In the unexpected case where they + * differ, the cached value of the current instance would still be more correct. */ + g_signal_emit (self, + signals[VPN_STATE_CHANGED], + 0, + (guint) priv->vpn_state, + (guint) priv->reason); +} + +void +_nm_vpn_connection_state_changed_commit (NMVpnConnection *self, + guint32 state, + guint32 reason) { - NMVpnConnection *connection = NM_VPN_CONNECTION (user_data); - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); + NMClient *client; + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); + + client = _nm_object_get_client (self); - if (priv->vpn_state != vpn_state) { - priv->vpn_state = vpn_state; - g_signal_emit (connection, signals[VPN_STATE_CHANGED], 0, vpn_state, reason); - g_object_notify (G_OBJECT (connection), NM_VPN_CONNECTION_VPN_STATE); + if (priv->vpn_state != state) { + priv->vpn_state = state; + _nm_client_queue_notify_object (client, + self, + obj_properties[PROP_VPN_STATE]); } + + priv->reason = reason; + + _nm_client_notify_event_queue_with_ptr (client, + NM_CLIENT_NOTIFY_EVENT_PRIO_GPROP + 1, + _notify_event_state_changed, + g_object_ref (self)); } /*****************************************************************************/ @@ -111,32 +134,6 @@ vpn_state_changed_proxy (NMDBusVpnConnection *proxy, static void nm_vpn_connection_init (NMVpnConnection *connection) { - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); - - priv->vpn_state = NM_VPN_CONNECTION_STATE_UNKNOWN; -} - -static void -init_dbus (NMObject *object) -{ - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_VPN_CONNECTION_BANNER, &priv->banner }, - { NM_VPN_CONNECTION_VPN_STATE, &priv->vpn_state }, - { NULL }, - }; - GDBusProxy *proxy; - - NM_OBJECT_CLASS (nm_vpn_connection_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_VPN_CONNECTION, - property_info); - - proxy = _nm_object_get_proxy (object, NM_DBUS_INTERFACE_VPN_CONNECTION); - g_signal_connect_object (proxy, "vpn-state-changed", - G_CALLBACK (vpn_state_changed_proxy), object, 0); - g_object_unref (proxy); } static void @@ -170,56 +167,62 @@ get_property (GObject *object, } } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_vpn_connection = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_VPN_CONNECTION, + nm_vpn_connection_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_S ("Banner", PROP_BANNER, NMVpnConnection, _priv.banner ), + NML_DBUS_META_PROPERTY_INIT_U ("VpnState", PROP_VPN_STATE, NMVpnConnection, _priv.vpn_state ), + ), +); + static void nm_vpn_connection_class_init (NMVpnConnectionClass *connection_class) { GObjectClass *object_class = G_OBJECT_CLASS (connection_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (connection_class); - - g_type_class_add_private (connection_class, sizeof (NMVpnConnectionPrivate)); - /* virtual methods */ object_class->get_property = get_property; - object_class->finalize = finalize; - - nm_object_class->init_dbus = init_dbus; - - /* properties */ + object_class->finalize = finalize; /** * NMVpnConnection:vpn-state: * * The VPN state of the active VPN connection. **/ - g_object_class_install_property - (object_class, PROP_VPN_STATE, - g_param_spec_enum (NM_VPN_CONNECTION_VPN_STATE, "", "", - NM_TYPE_VPN_CONNECTION_STATE, - NM_VPN_CONNECTION_STATE_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_VPN_STATE] = + g_param_spec_enum (NM_VPN_CONNECTION_VPN_STATE, "", "", + NM_TYPE_VPN_CONNECTION_STATE, + NM_VPN_CONNECTION_STATE_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMVpnConnection:banner: * * The VPN login banner of the active VPN connection. **/ - g_object_class_install_property - (object_class, PROP_BANNER, - g_param_spec_string (NM_VPN_CONNECTION_BANNER, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - /* signals */ + obj_properties[PROP_BANNER] = + g_param_spec_string (NM_VPN_CONNECTION_BANNER, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_vpn_connection); + + /* TODO: the state reason should also be exposed as a property in libnm's NMVpnConnection, + * like done for NMDevice's state reason. */ + + /* TODO: the D-Bus API should also expose the state-reason as a property instead of + * a "VpnStateChanged" signal. Like done for Device's "StateReason". */ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS signals[VPN_STATE_CHANGED] = - g_signal_new ("vpn-state-changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnConnectionClass, vpn_state_changed), - NULL, NULL, NULL, - G_TYPE_NONE, 2, - G_TYPE_UINT, G_TYPE_UINT); + g_signal_new ("vpn-state-changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 2, + G_TYPE_UINT, G_TYPE_UINT); G_GNUC_END_IGNORE_DEPRECATIONS } diff --git a/libnm/nm-vpn-connection.h b/libnm/nm-vpn-connection.h index 2a9caabd..5c7b4ca1 100644 --- a/libnm/nm-vpn-connection.h +++ b/libnm/nm-vpn-connection.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2010 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2010 Red Hat, Inc. */ #ifndef __NM_VPN_CONNECTION_H__ @@ -43,31 +29,7 @@ G_BEGIN_DECLS /** * NMVpnConnection: */ -struct _NMVpnConnection { - NMActiveConnection parent; -}; - -typedef struct { - NMActiveConnectionClass parent; - - /* Signals */ - - /* NMVpnConnectionStateReason got deprecated in 1.8.0. Thus, vpn_state_changed() - * uses a deprecated type and is itself deprecated. - * - * If you use this signal slot, you are advised to cast the reason - * to the NMActiveConnectionStateReason type, which is fully compatible. - */ - G_GNUC_BEGIN_IGNORE_DEPRECATIONS - NM_DEPRECATED_IN_1_8 - void (*vpn_state_changed) (NMVpnConnection *connection, - NMVpnConnectionState state, - NMVpnConnectionStateReason reason); - G_GNUC_END_IGNORE_DEPRECATIONS - - /*< private >*/ - gpointer padding[4]; -} NMVpnConnectionClass; +typedef struct _NMVpnConnectionClass NMVpnConnectionClass; GType nm_vpn_connection_get_type (void); diff --git a/libnm/nm-vpn-editor.c b/libnm/nm-vpn-editor.c index 4d8f4c8b..1e86279b 100644 --- a/libnm/nm-vpn-editor.c +++ b/libnm/nm-vpn-editor.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2008 - 2010 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright (C) 2008 - 2010 Red Hat, Inc. + * Copyright (C) 2008 Novell, Inc. */ #include "nm-default.h" diff --git a/libnm/nm-vpn-editor.h b/libnm/nm-vpn-editor.h index c6c2103e..17e04535 100644 --- a/libnm/nm-vpn-editor.h +++ b/libnm/nm-vpn-editor.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2008 Novell, Inc. - * Copyright 2008 - 2015 Red Hat, Inc. + * Copyright (C) 2008 Novell, Inc. + * Copyright (C) 2008 - 2015 Red Hat, Inc. */ #ifndef __NM_VPN_EDITOR_H__ diff --git a/libnm/nm-vpn-plugin-old.c b/libnm/nm-vpn-plugin-old.c index a85fcd2a..782fd80d 100644 --- a/libnm/nm-vpn-plugin-old.c +++ b/libnm/nm-vpn-plugin-old.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2008 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2008 Red Hat, Inc. */ #include "nm-default.h" @@ -82,13 +68,10 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_DBUS_SERVICE_NAME, PROP_STATE, - - LAST_PROP -}; +); static GSList *active_plugins = NULL; @@ -1017,16 +1000,13 @@ nm_vpn_plugin_old_class_init (NMVpnPluginOldClass *plugin_class) g_type_class_add_private (object_class, sizeof (NMVpnPluginOldPrivate)); - /* virtual methods */ - object_class->set_property = set_property; object_class->get_property = get_property; + object_class->set_property = set_property; object_class->dispose = dispose; object_class->finalize = finalize; plugin_class->state_changed = state_changed; - /* properties */ - /** * NMVpnPluginOld:service-name: * @@ -1034,13 +1014,12 @@ nm_vpn_plugin_old_class_init (NMVpnPluginOldClass *plugin_class) * * Deprecated: 1.2: replaced by NMVpnServicePlugin */ - g_object_class_install_property - (object_class, PROP_DBUS_SERVICE_NAME, - g_param_spec_string (NM_VPN_PLUGIN_OLD_DBUS_SERVICE_NAME, "", "", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DBUS_SERVICE_NAME] = + g_param_spec_string (NM_VPN_PLUGIN_OLD_DBUS_SERVICE_NAME, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); /** * NMVpnPluginOld:state: @@ -1049,92 +1028,92 @@ nm_vpn_plugin_old_class_init (NMVpnPluginOldClass *plugin_class) * * Deprecated: 1.2: replaced by NMVpnServicePlugin */ - g_object_class_install_property - (object_class, PROP_STATE, - g_param_spec_enum (NM_VPN_PLUGIN_OLD_STATE, "", "", - NM_TYPE_VPN_SERVICE_STATE, - NM_VPN_SERVICE_STATE_INIT, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - - /* signals */ + obj_properties[PROP_STATE] = + g_param_spec_enum (NM_VPN_PLUGIN_OLD_STATE, "", "", + NM_TYPE_VPN_SERVICE_STATE, + NM_VPN_SERVICE_STATE_INIT, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); + signals[STATE_CHANGED] = - g_signal_new ("state-changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginOldClass, state_changed), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_UINT); + g_signal_new ("state-changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnPluginOldClass, state_changed), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_UINT); signals[SECRETS_REQUIRED] = - g_signal_new ("secrets-required", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, - NULL, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRV); + g_signal_new ("secrets-required", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + NULL, + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRV); signals[CONFIG] = - g_signal_new ("config", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginOldClass, config), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_VARIANT); + g_signal_new ("config", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnPluginOldClass, config), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_VARIANT); signals[IP4_CONFIG] = - g_signal_new ("ip4-config", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginOldClass, ip4_config), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_VARIANT); + g_signal_new ("ip4-config", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnPluginOldClass, ip4_config), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_VARIANT); signals[IP6_CONFIG] = - g_signal_new ("ip6-config", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginOldClass, ip6_config), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_VARIANT); + g_signal_new ("ip6-config", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnPluginOldClass, ip6_config), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_VARIANT); signals[LOGIN_BANNER] = - g_signal_new ("login-banner", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginOldClass, login_banner), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_STRING); + g_signal_new ("login-banner", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnPluginOldClass, login_banner), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_STRING); signals[FAILURE] = - g_signal_new ("failure", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginOldClass, failure), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_UINT); + g_signal_new ("failure", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnPluginOldClass, failure), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_UINT); signals[QUIT] = - g_signal_new ("quit", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginOldClass, quit), - NULL, NULL, - NULL, - G_TYPE_NONE, 0, - G_TYPE_NONE); + g_signal_new ("quit", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnPluginOldClass, quit), + NULL, NULL, + NULL, + G_TYPE_NONE, 0, + G_TYPE_NONE); setup_unix_signal_handler (); } diff --git a/libnm/nm-vpn-plugin-old.h b/libnm/nm-vpn-plugin-old.h index b785527f..036b427e 100644 --- a/libnm/nm-vpn-plugin-old.h +++ b/libnm/nm-vpn-plugin-old.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2015 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2015 Red Hat, Inc. */ #ifndef __NM_VPN_PLUGIN_OLD_H__ diff --git a/libnm/nm-vpn-service-plugin.c b/libnm/nm-vpn-service-plugin.c index a2201428..9ebcfd64 100644 --- a/libnm/nm-vpn-service-plugin.c +++ b/libnm/nm-vpn-service-plugin.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2015 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2015 Red Hat, Inc. */ #include "nm-default.h" @@ -85,14 +71,11 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_DBUS_SERVICE_NAME, PROP_DBUS_WATCH_PEER, PROP_STATE, - - LAST_PROP -}; +); static GSList *active_plugins = NULL; @@ -1204,16 +1187,13 @@ nm_vpn_service_plugin_class_init (NMVpnServicePluginClass *plugin_class) g_type_class_add_private (object_class, sizeof (NMVpnServicePluginPrivate)); - /* virtual methods */ - object_class->set_property = set_property; object_class->get_property = get_property; + object_class->set_property = set_property; object_class->dispose = dispose; object_class->finalize = finalize; plugin_class->state_changed = state_changed; - /* properties */ - /** * NMVpnServicePlugin:service-name: * @@ -1221,13 +1201,12 @@ nm_vpn_service_plugin_class_init (NMVpnServicePluginClass *plugin_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_DBUS_SERVICE_NAME, - g_param_spec_string (NM_VPN_SERVICE_PLUGIN_DBUS_SERVICE_NAME, "", "", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_DBUS_SERVICE_NAME] = + g_param_spec_string (NM_VPN_SERVICE_PLUGIN_DBUS_SERVICE_NAME, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); /** * NMVpnServicePlugin:watch-peer: @@ -1236,12 +1215,12 @@ nm_vpn_service_plugin_class_init (NMVpnServicePluginClass *plugin_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_DBUS_WATCH_PEER, - g_param_spec_boolean (NM_VPN_SERVICE_PLUGIN_DBUS_WATCH_PEER, "", "", - FALSE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); + obj_properties[PROP_DBUS_WATCH_PEER] = + g_param_spec_boolean (NM_VPN_SERVICE_PLUGIN_DBUS_WATCH_PEER, "", "", + FALSE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); /** * NMVpnServicePlugin:state: @@ -1250,92 +1229,92 @@ nm_vpn_service_plugin_class_init (NMVpnServicePluginClass *plugin_class) * * Since: 1.2 */ - g_object_class_install_property - (object_class, PROP_STATE, - g_param_spec_enum (NM_VPN_SERVICE_PLUGIN_STATE, "", "", - NM_TYPE_VPN_SERVICE_STATE, - NM_VPN_SERVICE_STATE_INIT, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - - /* signals */ + obj_properties[PROP_STATE] = + g_param_spec_enum (NM_VPN_SERVICE_PLUGIN_STATE, "", "", + NM_TYPE_VPN_SERVICE_STATE, + NM_VPN_SERVICE_STATE_INIT, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); + signals[STATE_CHANGED] = - g_signal_new ("state-changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnServicePluginClass, state_changed), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_UINT); + g_signal_new ("state-changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnServicePluginClass, state_changed), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_UINT); signals[SECRETS_REQUIRED] = - g_signal_new ("secrets-required", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, - NULL, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRV); + g_signal_new ("secrets-required", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + NULL, + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRV); signals[CONFIG] = - g_signal_new ("config", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnServicePluginClass, config), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_VARIANT); + g_signal_new ("config", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnServicePluginClass, config), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_VARIANT); signals[IP4_CONFIG] = - g_signal_new ("ip4-config", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnServicePluginClass, ip4_config), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_VARIANT); + g_signal_new ("ip4-config", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnServicePluginClass, ip4_config), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_VARIANT); signals[IP6_CONFIG] = - g_signal_new ("ip6-config", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnServicePluginClass, ip6_config), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_VARIANT); + g_signal_new ("ip6-config", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnServicePluginClass, ip6_config), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_VARIANT); signals[LOGIN_BANNER] = - g_signal_new ("login-banner", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnServicePluginClass, login_banner), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_STRING); + g_signal_new ("login-banner", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnServicePluginClass, login_banner), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_STRING); signals[FAILURE] = - g_signal_new ("failure", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnServicePluginClass, failure), - NULL, NULL, - NULL, - G_TYPE_NONE, 1, - G_TYPE_UINT); + g_signal_new ("failure", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnServicePluginClass, failure), + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_UINT); signals[QUIT] = - g_signal_new ("quit", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnServicePluginClass, quit), - NULL, NULL, - NULL, - G_TYPE_NONE, 0, - G_TYPE_NONE); + g_signal_new ("quit", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMVpnServicePluginClass, quit), + NULL, NULL, + NULL, + G_TYPE_NONE, 0, + G_TYPE_NONE); setup_unix_signal_handler (); } diff --git a/libnm/nm-vpn-service-plugin.h b/libnm/nm-vpn-service-plugin.h index 1bcb2aa5..2350f0da 100644 --- a/libnm/nm-vpn-service-plugin.h +++ b/libnm/nm-vpn-service-plugin.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2015 Red Hat, Inc. + * Copyright (C) 2007 - 2008 Novell, Inc. + * Copyright (C) 2007 - 2015 Red Hat, Inc. */ #ifndef __NM_VPN_SERVICE_PLUGIN_H__ diff --git a/libnm/nm-wifi-p2p-peer.c b/libnm/nm-wifi-p2p-peer.c index 4dd8545d..50910445 100644 --- a/libnm/nm-wifi-p2p-peer.c +++ b/libnm/nm-wifi-p2p-peer.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 - 2019 Red Hat, Inc. + * Copyright (C) 2018 - 2019 Red Hat, Inc. */ #include "nm-default.h" @@ -44,26 +30,18 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE ( ); typedef struct { + GBytes *wfd_ies; char *name; char *manufacturer; char *model; char *model_number; char *serial; - - GBytes *wfd_ies; - char *hw_address; - - int last_seen; - - NM80211ApFlags flags; - + gint32 last_seen; + guint32 flags; guint8 strength; } NMWifiP2PPeerPrivate; -/** - * NMWifiP2PPeer: - */ struct _NMWifiP2PPeer { NMObject parent; NMWifiP2PPeerPrivate _priv; @@ -357,33 +335,6 @@ nm_wifi_p2p_peer_filter_connections (NMWifiP2PPeer *peer, const GPtrArray *conne /*****************************************************************************/ static void -init_dbus (NMObject *object) -{ - NMWifiP2PPeerPrivate *priv = NM_WIFI_P2P_PEER_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_WIFI_P2P_PEER_FLAGS, &priv->flags }, - { NM_WIFI_P2P_PEER_NAME, &priv->name }, - { NM_WIFI_P2P_PEER_MANUFACTURER, &priv->manufacturer }, - { NM_WIFI_P2P_PEER_MODEL, &priv->model }, - { NM_WIFI_P2P_PEER_MODEL_NUMBER, &priv->model_number }, - { NM_WIFI_P2P_PEER_SERIAL, &priv->serial }, - { NM_WIFI_P2P_PEER_WFD_IES, &priv->wfd_ies }, - { NM_WIFI_P2P_PEER_HW_ADDRESS, &priv->hw_address }, - { NM_WIFI_P2P_PEER_STRENGTH, &priv->strength }, - { NM_WIFI_P2P_PEER_LAST_SEEN, &priv->last_seen }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_wifi_p2p_peer_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_WIFI_P2P_PEER, - property_info); -} - -/*****************************************************************************/ - -static void get_property (GObject *object, guint prop_id, GValue *value, @@ -446,7 +397,6 @@ finalize (GObject *object) g_free (priv->model); g_free (priv->model_number); g_free (priv->serial); - g_free (priv->hw_address); g_bytes_unref (priv->wfd_ies); @@ -454,17 +404,31 @@ finalize (GObject *object) G_OBJECT_CLASS (nm_wifi_p2p_peer_parent_class)->finalize (object); } +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_wifip2ppeer = NML_DBUS_META_IFACE_INIT_PROP ( + NM_DBUS_INTERFACE_WIFI_P2P_PEER, + nm_wifi_p2p_peer_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, + NML_DBUS_META_IFACE_DBUS_PROPERTIES ( + NML_DBUS_META_PROPERTY_INIT_U ("Flags", PROP_FLAGS, NMWifiP2PPeer, _priv.flags ), + NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMWifiP2PPeer, _priv.hw_address ), + NML_DBUS_META_PROPERTY_INIT_I ("LastSeen", PROP_LAST_SEEN, NMWifiP2PPeer, _priv.last_seen ), + NML_DBUS_META_PROPERTY_INIT_S ("Manufacturer", PROP_MANUFACTURER, NMWifiP2PPeer, _priv.manufacturer ), + NML_DBUS_META_PROPERTY_INIT_S ("Model", PROP_MODEL, NMWifiP2PPeer, _priv.model ), + NML_DBUS_META_PROPERTY_INIT_S ("ModelNumber", PROP_MODEL_NUMBER, NMWifiP2PPeer, _priv.model_number ), + NML_DBUS_META_PROPERTY_INIT_S ("Serial", PROP_SERIAL, NMWifiP2PPeer, _priv.serial ), + NML_DBUS_META_PROPERTY_INIT_Y ("Strength", PROP_STRENGTH, NMWifiP2PPeer, _priv.strength ), + NML_DBUS_META_PROPERTY_INIT_AY ("WfdIEs", PROP_WFD_IES, NMWifiP2PPeer, _priv.wfd_ies ), + ), +); + static void nm_wifi_p2p_peer_class_init (NMWifiP2PPeerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); object_class->get_property = get_property; object_class->finalize = finalize; - nm_object_class->init_dbus = init_dbus; - /** * NMWifiP2PPeer:flags: * @@ -596,5 +560,5 @@ nm_wifi_p2p_peer_class_init (NMWifiP2PPeerClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); + _nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_wifip2ppeer); } diff --git a/libnm/nm-wifi-p2p-peer.h b/libnm/nm-wifi-p2p-peer.h index 7d48883b..0a8b4d39 100644 --- a/libnm/nm-wifi-p2p-peer.h +++ b/libnm/nm-wifi-p2p-peer.h @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2018 - 2019 Red Hat, Inc. + * Copyright (C) 2018 - 2019 Red Hat, Inc. */ #ifndef __NM_WIFI_P2P_PEER_H__ @@ -46,6 +32,9 @@ G_BEGIN_DECLS #define NM_WIFI_P2P_PEER_STRENGTH "strength" #define NM_WIFI_P2P_PEER_LAST_SEEN "last-seen" +/** + * NMWifiP2PPeer: + */ typedef struct _NMWifiP2PPeerClass NMWifiP2PPeerClass; NM_AVAILABLE_IN_1_16 diff --git a/libnm/nm-wimax-nsp.c b/libnm/nm-wimax-nsp.c index ecdedecd..d8472838 100644 --- a/libnm/nm-wimax-nsp.c +++ b/libnm/nm-wimax-nsp.c @@ -1,52 +1,34 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2011 Red Hat, Inc. + * Copyright (C) 2011 Red Hat, Inc. */ #include "nm-default.h" #include "nm-wimax-nsp.h" -#include "nm-connection.h" -#include "nm-setting-connection.h" -#include "nm-setting-wimax.h" -#include "nm-dbus-interface.h" -#include "nm-object-private.h" -#include "nm-enum-types.h" - -G_DEFINE_TYPE (NMWimaxNsp, nm_wimax_nsp, NM_TYPE_OBJECT) - -#define NM_WIMAX_NSP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_WIMAX_NSP, NMWimaxNspPrivate)) - -typedef struct { - char *name; - guint32 signal_quality; - NMWimaxNspNetworkType network_type; -} NMWimaxNspPrivate; +/*****************************************************************************/ -enum { - PROP_0, +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_NAME, PROP_SIGNAL_QUALITY, PROP_NETWORK_TYPE, +); + +struct _NMWimaxNsp { + NMObject parent; +}; - LAST_PROP +struct _NMWimaxNspClass { + NMObjectClass parent; }; +G_DEFINE_TYPE (NMWimaxNsp, nm_wimax_nsp, NM_TYPE_OBJECT) + +#define NM_WIMAX_NSP_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMWimaxNsp, NM_IS_WIMAX_NSP, NMObject) + +/*****************************************************************************/ + /** * nm_wimax_nsp_get_name: * @nsp: a #NMWimaxNsp @@ -54,13 +36,13 @@ enum { * Gets the name of the wimax NSP * * Returns: the name + * + * Deprecated: 1.22. WiMAX is no longer supported by NetworkManager since 1.2.0 **/ const char * nm_wimax_nsp_get_name (NMWimaxNsp *nsp) { - g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), NULL); - - return NM_WIMAX_NSP_GET_PRIVATE (nsp)->name; + g_return_val_if_reached (NULL); } /** @@ -70,13 +52,13 @@ nm_wimax_nsp_get_name (NMWimaxNsp *nsp) * Gets the WPA signal quality of the wimax NSP. * * Returns: the signal quality + * + * Deprecated: 1.22. WiMAX is no longer supported by NetworkManager since 1.2.0 **/ guint32 nm_wimax_nsp_get_signal_quality (NMWimaxNsp *nsp) { - g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), 0); - - return NM_WIMAX_NSP_GET_PRIVATE (nsp)->signal_quality; + g_return_val_if_reached (0); } /** @@ -86,13 +68,13 @@ nm_wimax_nsp_get_signal_quality (NMWimaxNsp *nsp) * Gets the network type of the wimax NSP. * * Returns: the network type + * + * Deprecated: 1.22. WiMAX is no longer supported by NetworkManager since 1.2.0 **/ NMWimaxNspNetworkType nm_wimax_nsp_get_network_type (NMWimaxNsp *nsp) { - g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN); - - return NM_WIMAX_NSP_GET_PRIVATE (nsp)->network_type; + g_return_val_if_reached (NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN); } /** @@ -106,36 +88,13 @@ nm_wimax_nsp_get_network_type (NMWimaxNsp *nsp) * * Returns: %TRUE if the connection may be activated with this WiMAX NSP, * %FALSE if it cannot be. + * + * Deprecated: 1.22. WiMAX is no longer supported by NetworkManager since 1.2.0 **/ gboolean nm_wimax_nsp_connection_valid (NMWimaxNsp *nsp, NMConnection *connection) { - NMSettingConnection *s_con; - NMSettingWimax *s_wimax; - const char *ctype; - const char *nsp_name; - const char *setting_name; - - s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); - ctype = nm_setting_connection_get_connection_type (s_con); - if (strcmp (ctype, NM_SETTING_WIMAX_SETTING_NAME) != 0) - return FALSE; - - s_wimax = nm_connection_get_setting_wimax (connection); - if (!s_wimax) - return FALSE; - - setting_name = nm_setting_wimax_get_network_name (s_wimax); - if (!setting_name) - return FALSE; - - nsp_name = nm_wimax_nsp_get_name (nsp); - g_warn_if_fail (nsp_name != NULL); - if (g_strcmp0 (nsp_name, setting_name) != 0) - return FALSE; - - return TRUE; + g_return_val_if_reached (FALSE); } /** @@ -151,133 +110,78 @@ nm_wimax_nsp_connection_valid (NMWimaxNsp *nsp, NMConnection *connection) * Returns: (transfer full) (element-type NMConnection): an array of * #NMConnections that could be activated with the given @nsp. The array should * be freed with g_ptr_array_unref() when it is no longer required. + * + * Deprecated: 1.22. WiMAX is no longer supported by NetworkManager since 1.2.0 **/ GPtrArray * nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, const GPtrArray *connections) { - GPtrArray *filtered; - int i; - - filtered = g_ptr_array_new_with_free_func (g_object_unref); - for (i = 0; i < connections->len; i++) { - NMConnection *candidate = connections->pdata[i]; - - if (nm_wimax_nsp_connection_valid (nsp, candidate)) - g_ptr_array_add (filtered, g_object_ref (candidate)); - } - - return filtered; + g_return_val_if_reached (NULL); } /*****************************************************************************/ static void -nm_wimax_nsp_init (NMWimaxNsp *nsp) -{ -} - -static void -finalize (GObject *object) -{ - NMWimaxNspPrivate *priv = NM_WIMAX_NSP_GET_PRIVATE (object); - - g_free (priv->name); - - G_OBJECT_CLASS (nm_wimax_nsp_parent_class)->finalize (object); -} - -static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMWimaxNsp *nsp = NM_WIMAX_NSP (object); - - switch (prop_id) { - case PROP_NAME: - g_value_set_string (value, nm_wimax_nsp_get_name (nsp)); - break; - case PROP_SIGNAL_QUALITY: - g_value_set_uint (value, nm_wimax_nsp_get_signal_quality (nsp)); - break; - case PROP_NETWORK_TYPE: - g_value_set_enum (value, nm_wimax_nsp_get_network_type (nsp)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + g_return_if_reached (); } static void -init_dbus (NMObject *object) +nm_wimax_nsp_init (NMWimaxNsp *nsp) { - NMWimaxNspPrivate *priv = NM_WIMAX_NSP_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_WIMAX_NSP_NAME, &priv->name }, - { NM_WIMAX_NSP_SIGNAL_QUALITY, &priv->signal_quality }, - { NM_WIMAX_NSP_NETWORK_TYPE, &priv->network_type }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_wimax_nsp_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_WIMAX_NSP, - property_info); + g_return_if_reached (); } static void nm_wimax_nsp_class_init (NMWimaxNspClass *nsp_class) { GObjectClass *object_class = G_OBJECT_CLASS (nsp_class); - NMObjectClass *nm_object_class = NM_OBJECT_CLASS (nsp_class); - g_type_class_add_private (nsp_class, sizeof (NMWimaxNspPrivate)); - - /* virtual methods */ object_class->get_property = get_property; - object_class->finalize = finalize; - - nm_object_class->init_dbus = init_dbus; - - /* properties */ /** * NMWimaxNsp:name: * * The name of the WiMAX NSP. + * + * Deprecated: 1.22. WiMAX is no longer supported by NetworkManager since 1.2.0 **/ - g_object_class_install_property - (object_class, PROP_NAME, - g_param_spec_string (NM_WIMAX_NSP_NAME, "", "", - NULL, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_NAME] = + g_param_spec_string (NM_WIMAX_NSP_NAME, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMWimaxNsp:signal-quality: * * The signal quality of the WiMAX NSP. + * + * Deprecated: 1.22. WiMAX is no longer supported by NetworkManager since 1.2.0 **/ - g_object_class_install_property - (object_class, PROP_SIGNAL_QUALITY, - g_param_spec_uint (NM_WIMAX_NSP_SIGNAL_QUALITY, "", "", - 0, 100, 0, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_SIGNAL_QUALITY] = + g_param_spec_uint (NM_WIMAX_NSP_SIGNAL_QUALITY, "", "", + 0, 100, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); /** * NMWimaxNsp:network-type: * * The network type of the WiMAX NSP. + * + * Deprecated: 1.22. WiMAX is no longer supported by NetworkManager since 1.2.0 **/ - g_object_class_install_property - (object_class, PROP_NETWORK_TYPE, - g_param_spec_enum (NM_WIMAX_NSP_NETWORK_TYPE, "", "", - NM_TYPE_WIMAX_NSP_NETWORK_TYPE, - NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_NETWORK_TYPE] = + g_param_spec_enum (NM_WIMAX_NSP_NETWORK_TYPE, "", "", + NM_TYPE_WIMAX_NSP_NETWORK_TYPE, + NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); } diff --git a/libnm/nm-wimax-nsp.h b/libnm/nm-wimax-nsp.h index 7d9f8cd3..17a10b7d 100644 --- a/libnm/nm-wimax-nsp.h +++ b/libnm/nm-wimax-nsp.h @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2011 Red Hat, Inc. - * Copyright 2009 Novell, Inc. + * Copyright (C) 2011 Red Hat, Inc. + * Copyright (C) 2009 Novell, Inc. */ #ifndef __NM_WIMAX_NSP_H__ @@ -42,27 +28,25 @@ G_BEGIN_DECLS /** * NMWimaxNsp: + * + * Deprecated: 1.22. WiMAX is no longer supported by NetworkManager since 1.2.0 */ -struct _NMWimaxNsp { - NMObject parent; -}; - -typedef struct { - NMObjectClass parent; - - /*< private >*/ - gpointer padding[4]; -} NMWimaxNspClass; +typedef struct _NMWimaxNspClass NMWimaxNspClass; GType nm_wimax_nsp_get_type (void); +NM_DEPRECATED_IN_1_22 const char * nm_wimax_nsp_get_name (NMWimaxNsp *nsp); +NM_DEPRECATED_IN_1_22 guint32 nm_wimax_nsp_get_signal_quality (NMWimaxNsp *nsp); +NM_DEPRECATED_IN_1_22 NMWimaxNspNetworkType nm_wimax_nsp_get_network_type (NMWimaxNsp *nsp); +NM_DEPRECATED_IN_1_22 GPtrArray * nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, const GPtrArray *connections); +NM_DEPRECATED_IN_1_22 gboolean nm_wimax_nsp_connection_valid (NMWimaxNsp *nsp, NMConnection *connection); diff --git a/libnm/tests/meson.build b/libnm/tests/meson.build index 5b72a24f..76c3b287 100644 --- a/libnm/tests/meson.build +++ b/libnm/tests/meson.build @@ -1,11 +1,16 @@ test_units = [ - ['test-libnm', 30], - ['test-nm-client', 90], + ['test-libnm', 30], + ['test-nm-client', 90], ['test-remote-settings-client', 90], - ['test-secret-agent', 90], + ['test-secret-agent', 90], ] -cflags = [ +deps = [ + libnm_core_dep, + libnm_nm_default_dep, +] + +c_flags = [ '-DNETWORKMANAGER_COMPILATION_TEST', '-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIBNM', ] @@ -13,19 +18,10 @@ cflags = [ foreach test_unit: test_units exe = executable( test_unit[0], - [ - test_unit[0] + '.c', - shared_nm_test_utils_impl_c, - ], - dependencies: [ - liblibnm_dep, - libnm_systemd_shared_no_logging_dep, - ], - c_args: cflags, - link_with: [ - liblibnm, - libnm_core, - ], + [test_unit[0] + '.c', nm_test_utils_impl_source, libnm_enum_sources[1]], + dependencies: deps, + c_args: c_flags, + link_with: liblibnm, ) test( @@ -39,8 +35,8 @@ endforeach # just test, that we can build "nm-vpn-plugin-utils.c" libnm_vpn_plugin_utils_test = static_library( 'nm-vpn-plugin-utils-test', - sources: shared_nm_utils_nm_vpn_plugin_utils_c + [libnm_enum[1]], + sources: nm_vpn_plugin_utils_source + [libnm_enum_sources[1]], include_directories: libnm_inc, - dependencies: libnm_core_dep, - c_args: cflags, + dependencies: libnm_nm_default_dep, + c_args: c_flags, ) diff --git a/libnm/tests/test-libnm.c b/libnm/tests/test-libnm.c index 2a64fad8..345fbb07 100644 --- a/libnm/tests/test-libnm.c +++ b/libnm/tests/test-libnm.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0+ /* - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT SC WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2017 Red Hat, Inc. + * Copyright (C) 2017 Red Hat, Inc. */ #include "nm-default.h" @@ -25,8 +11,16 @@ #include <sys/mman.h> +#include "NetworkManager.h" +#include "nm-access-point.h" +#include "nm-checkpoint.h" +#include "nm-dhcp4-config.h" +#include "nm-dhcp6-config.h" +#include "nm-dns-manager.h" +#include "nm-ip4-config.h" +#include "nm-ip6-config.h" #include "nm-libnm-utils.h" - +#include "nm-object.h" #include "nm-vpn-service-plugin.h" #include "nm-utils/nm-test-utils.h" @@ -2430,6 +2424,648 @@ test_nm_vpn_service_plugin_read_vpn_details (void) /*****************************************************************************/ +static void +test_types (void) +{ +#define G(get_type_fcn) \ + ({ \ + GType get_type_fcn (void); \ + \ + get_type_fcn; \ + }) + GType (*get_type_fcns[]) (void) = { + G (nm_802_11_ap_flags_get_type), + G (nm_802_11_ap_security_flags_get_type), + G (nm_802_11_mode_get_type), + G (nm_access_point_get_type), + G (nm_activation_state_flags_get_type), + G (nm_active_connection_get_type), + G (nm_active_connection_state_get_type), + G (nm_active_connection_state_reason_get_type), + G (nm_agent_manager_error_get_type), + G (nm_bluetooth_capabilities_get_type), + G (nm_bridge_vlan_get_type), + G (nm_capability_get_type), + G (nm_checkpoint_create_flags_get_type), + G (nm_checkpoint_get_type), + G (nm_client_error_get_type), + G (nm_client_get_type), + G (nm_client_permission_get_type), + G (nm_client_permission_result_get_type), + G (nm_connection_error_get_type), + G (nm_connection_get_type), + G (nm_connection_multi_connect_get_type), + G (nm_connection_serialization_flags_get_type), + G (nm_connectivity_state_get_type), + G (nm_crypto_error_get_type), + G (nm_device_6lowpan_get_type), + G (nm_device_adsl_get_type), + G (nm_device_bond_get_type), + G (nm_device_bridge_get_type), + G (nm_device_bt_get_type), + G (nm_device_capabilities_get_type), + G (nm_device_dummy_get_type), + G (nm_device_error_get_type), + G (nm_device_ethernet_get_type), + G (nm_device_generic_get_type), + G (nm_device_get_type), + G (nm_device_infiniband_get_type), + G (nm_device_ip_tunnel_get_type), + G (nm_device_macsec_get_type), + G (nm_device_macvlan_get_type), + G (nm_device_modem_capabilities_get_type), + G (nm_device_modem_get_type), + G (nm_device_olpc_mesh_get_type), + G (nm_device_ovs_bridge_get_type), + G (nm_device_ovs_interface_get_type), + G (nm_device_ovs_port_get_type), + G (nm_device_ppp_get_type), + G (nm_device_state_get_type), + G (nm_device_state_reason_get_type), + G (nm_device_team_get_type), + G (nm_device_tun_get_type), + G (nm_device_type_get_type), + G (nm_device_vlan_get_type), + G (nm_device_vxlan_get_type), + G (nm_device_wifi_capabilities_get_type), + G (nm_device_wifi_get_type), + G (nm_device_wifi_p2p_get_type), + G (nm_device_wimax_get_type), + G (nm_device_wireguard_get_type), + G (nm_device_wpan_get_type), + G (nm_dhcp4_config_get_type), + G (nm_dhcp6_config_get_type), + G (nm_dhcp_config_get_type), + G (nm_dns_entry_get_type), + G (nm_ip4_config_get_type), + G (nm_ip6_config_get_type), + G (nm_ip_address_get_type), + G (nm_ip_config_get_type), + G (nm_ip_route_get_type), + G (nm_ip_routing_rule_as_string_flags_get_type), + G (nm_ip_routing_rule_get_type), + G (nm_ip_tunnel_flags_get_type), + G (nm_ip_tunnel_mode_get_type), + G (nm_lldp_neighbor_get_type), + G (nm_manager_error_get_type), + G (nm_manager_reload_flags_get_type), + G (nm_metered_get_type), + G (nm_object_get_type), + G (nm_remote_connection_get_type), + G (nm_secret_agent_capabilities_get_type), + G (nm_secret_agent_error_get_type), + G (nm_secret_agent_get_secrets_flags_get_type), + G (nm_secret_agent_old_get_type), + G (nm_setting_6lowpan_get_type), + G (nm_setting_802_1x_auth_flags_get_type), + G (nm_setting_802_1x_ck_format_get_type), + G (nm_setting_802_1x_ck_scheme_get_type), + G (nm_setting_802_1x_get_type), + G (nm_setting_adsl_get_type), + G (nm_setting_bluetooth_get_type), + G (nm_setting_bond_get_type), + G (nm_setting_bridge_get_type), + G (nm_setting_bridge_port_get_type), + G (nm_setting_cdma_get_type), + G (nm_setting_compare_flags_get_type), + G (nm_setting_connection_autoconnect_slaves_get_type), + G (nm_setting_connection_get_type), + G (nm_setting_connection_lldp_get_type), + G (nm_setting_connection_llmnr_get_type), + G (nm_setting_connection_mdns_get_type), + G (nm_setting_dcb_flags_get_type), + G (nm_setting_dcb_get_type), + G (nm_setting_diff_result_get_type), + G (nm_setting_dummy_get_type), + G (nm_setting_ethtool_get_type), + G (nm_setting_generic_get_type), + G (nm_setting_get_type), + G (nm_setting_gsm_get_type), + G (nm_setting_infiniband_get_type), + G (nm_setting_ip4_config_get_type), + G (nm_setting_ip6_config_addr_gen_mode_get_type), + G (nm_setting_ip6_config_get_type), + G (nm_setting_ip6_config_privacy_get_type), + G (nm_setting_ip_config_get_type), + G (nm_setting_ip_tunnel_get_type), + G (nm_setting_mac_randomization_get_type), + G (nm_setting_macsec_get_type), + G (nm_setting_macsec_mode_get_type), + G (nm_setting_macsec_validation_get_type), + G (nm_setting_macvlan_get_type), + G (nm_setting_macvlan_mode_get_type), + G (nm_setting_match_get_type), + G (nm_setting_olpc_mesh_get_type), + G (nm_setting_ovs_bridge_get_type), + G (nm_setting_ovs_dpdk_get_type), + G (nm_setting_ovs_interface_get_type), + G (nm_setting_ovs_patch_get_type), + G (nm_setting_ovs_port_get_type), + G (nm_setting_ppp_get_type), + G (nm_setting_pppoe_get_type), + G (nm_setting_proxy_get_type), + G (nm_setting_proxy_method_get_type), + G (nm_settings_add_connection2_flags_get_type), + G (nm_settings_connection_flags_get_type), + G (nm_setting_secret_flags_get_type), + G (nm_setting_serial_get_type), + G (nm_setting_serial_parity_get_type), + G (nm_settings_error_get_type), + G (nm_setting_sriov_get_type), + G (nm_settings_update2_flags_get_type), + G (nm_setting_tc_config_get_type), + G (nm_setting_team_get_type), + G (nm_setting_team_port_get_type), + G (nm_setting_tun_get_type), + G (nm_setting_tun_mode_get_type), + G (nm_setting_user_get_type), + G (nm_setting_vlan_get_type), + G (nm_setting_vpn_get_type), + G (nm_setting_vxlan_get_type), + G (nm_setting_wifi_p2p_get_type), + G (nm_setting_wimax_get_type), + G (nm_setting_wired_get_type), + G (nm_setting_wired_wake_on_lan_get_type), + G (nm_setting_wireguard_get_type), + G (nm_setting_wireless_get_type), + G (nm_setting_wireless_powersave_get_type), + G (nm_setting_wireless_security_fils_get_type), + G (nm_setting_wireless_security_get_type), + G (nm_setting_wireless_security_pmf_get_type), + G (nm_setting_wireless_security_wps_method_get_type), + G (nm_setting_wireless_wake_on_wlan_get_type), + G (nm_setting_wpan_get_type), + G (nm_simple_connection_get_type), + G (nm_sriov_vf_get_type), + G (nm_sriov_vf_vlan_protocol_get_type), + G (nm_state_get_type), + G (nm_tc_action_get_type), + G (nm_tc_qdisc_get_type), + G (nm_tc_tfilter_get_type), + G (nm_team_link_watcher_arp_ping_flags_get_type), + G (nm_team_link_watcher_get_type), + G (nm_ternary_get_type), + G (nm_utils_security_type_get_type), + G (nm_vlan_flags_get_type), + G (nm_vlan_priority_map_get_type), + G (nm_vpn_connection_get_type), + G (nm_vpn_connection_state_get_type), + G (nm_vpn_connection_state_reason_get_type), + G (nm_vpn_editor_get_type), + G (nm_vpn_editor_plugin_capability_get_type), + G (nm_vpn_editor_plugin_get_type), + G (nm_vpn_plugin_error_get_type), + G (nm_vpn_plugin_failure_get_type), + G (nm_vpn_plugin_info_get_type), + G (nm_vpn_plugin_old_get_type), + G (nm_vpn_service_plugin_get_type), + G (nm_vpn_service_state_get_type), + G (nm_wep_key_type_get_type), + G (nm_wifi_p2p_peer_get_type), + G (nm_wimax_nsp_get_type), + G (nm_wimax_nsp_network_type_get_type), + G (nm_wireguard_peer_get_type), + }; + guint i_type; + + for (i_type = 0; i_type < G_N_ELEMENTS (get_type_fcns); i_type++) { + nm_auto_unref_gtypeclass GObjectClass *klass_unref = NULL; + GType gtype = (get_type_fcns[i_type]) (); + GObjectClass *klass; + + g_assert (g_str_has_prefix (g_type_name (gtype), "NM")); + + if (G_TYPE_IS_INTERFACE (gtype)) { + if (!NM_IN_STRSET (g_type_name (gtype), "NMConnection", + "NMVpnEditor", + "NMVpnEditorPlugin")) + g_error ("unexpected interface type %s", g_type_name (gtype)); + continue; + } + + if (g_type_is_a (gtype, G_TYPE_BOXED)) + continue; + + /* We only test parts of the types, and avoid initializing all the types. + * That is so that other unit tests in this process randomly run with either + * the class instance already initialized or not. */ + if ((nmtst_get_rand_uint () % 5) == 0) { + klass = (klass_unref = g_type_class_ref (gtype)); + g_assert (klass); + } else { + klass = g_type_class_peek (gtype); + if (!klass) + continue; + } + + if (g_type_is_a (gtype, G_TYPE_ENUM)) + continue; + + if (g_type_is_a (gtype, G_TYPE_FLAGS)) + continue; + + g_assert (g_type_is_a (gtype, G_TYPE_OBJECT)); + g_assert (G_IS_OBJECT_CLASS (klass)); + } +} + +/*****************************************************************************/ + +static void +test_nml_dbus_meta (void) +{ + const NMLDBusMetaIface *meta_iface; + const NMLDBusMetaProperty *meta_property; + guint prop_idx; + gsize i, j; + guint l, m; + + for (i = 0; i < G_N_ELEMENTS (_nml_dbus_meta_ifaces); i++) { + const NMLDBusMetaIface *mif = _nml_dbus_meta_ifaces[i]; + nm_auto_unref_gtypeclass GObjectClass *klass_unref = NULL; + GObjectClass *klass; + GType gtype; + +#define COMMON_PREFIX "org.freedesktop.NetworkManager" + + g_assert (mif); + g_assert (mif->dbus_iface_name); + g_assert ( g_str_has_prefix (mif->dbus_iface_name, COMMON_PREFIX) + && !g_str_has_suffix (mif->dbus_iface_name, ".") + && NM_IN_SET (mif->dbus_iface_name[NM_STRLEN (COMMON_PREFIX)], '\0', '.')); + for (j = i + 1; j < G_N_ELEMENTS (_nml_dbus_meta_ifaces); j++) + g_assert (mif != _nml_dbus_meta_ifaces[j]); + if (i > 0) { + if (strcmp (_nml_dbus_meta_ifaces[i - 1]->dbus_iface_name, mif->dbus_iface_name) >= 0) { + g_error ("meta-ifaces are not properly sorted: [%zu] \"%s\" should be after [%zu] \"%s\"", + i - 1, _nml_dbus_meta_ifaces[i - 1]->dbus_iface_name, i, mif->dbus_iface_name); + } + } + + g_assert ((mif->n_dbus_properties > 0) == (!!mif->dbus_properties)); + + if (mif->interface_prio == NML_DBUS_META_INTERFACE_PRIO_NONE) { + g_assert (!mif->get_type_fcn); + g_assert (!mif->obj_properties); + g_assert (mif->n_obj_properties == 0); + g_assert (!mif->obj_properties_reverse_idx); + if (!NM_IN_STRSET (mif->dbus_iface_name, NM_DBUS_INTERFACE_AGENT_MANAGER, + NM_DBUS_INTERFACE_DEVICE_STATISTICS, + NM_DBUS_INTERFACE_DEVICE_VETH)) + g_error ("D-Bus interface \"%s\" is unexpectedly empty", mif->dbus_iface_name); + if (mif->n_dbus_properties == 0) + continue; + gtype = G_TYPE_NONE; + klass = NULL; + goto check_dbus_properties; + } + + g_assert (NM_IN_SET ((NMLDBusMetaInteracePrio) mif->interface_prio, NML_DBUS_META_INTERFACE_PRIO_NMCLIENT, + NML_DBUS_META_INTERFACE_PRIO_PARENT_TYPE, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH)); + + g_assert (mif->get_type_fcn); + gtype = mif->get_type_fcn (); + g_assert (g_type_is_a (gtype, G_TYPE_OBJECT)); + + if (mif->interface_prio == NML_DBUS_META_INTERFACE_PRIO_NMCLIENT) + g_assert (gtype == NM_TYPE_CLIENT); + else + g_assert (g_type_is_a (gtype, NM_TYPE_OBJECT)); + + /* We only test parts of the types, and avoid initializing all the types. + * That is so that other unit tests in this process randomly run with either + * the class instance already initialized or not. */ + if ((nmtst_get_rand_uint () % 5) == 0) { + klass = (klass_unref = g_type_class_ref (gtype)); + g_assert (klass); + } else + klass = g_type_class_peek (gtype); + + if (klass) { + if (NM_IS_OBJECT_CLASS (klass)) { + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass); + const _NMObjectClassFieldInfo *p_prev; + const _NMObjectClassFieldInfo *p; + + p_prev = NULL; + for (p = nm_object_class->property_o_info; p; p_prev = p, p = p->parent) { + g_assert (p->num > 0); + g_assert (NM_IS_OBJECT_CLASS (p->klass)); + g_assert (g_type_is_a (gtype, G_TYPE_FROM_CLASS (p->klass))); + g_assert (p->klass->property_o_info == p); + if (p_prev) { + g_assert (g_type_is_a (G_TYPE_FROM_CLASS (p_prev->klass), G_TYPE_FROM_CLASS (p->klass))); + g_assert (p_prev->klass != p->klass); + } + } + } else + g_assert (NM_IS_CLIENT_CLASS (klass)); + } + + if (!mif->obj_properties) { + g_assert_cmpint (mif->n_obj_properties, ==, 0); + g_assert (!mif->obj_properties_reverse_idx); + } else { + g_assert (mif->obj_properties); + g_assert (mif->obj_properties[0] == 0); + g_assert_cmpint (mif->n_obj_properties, >, 1); + if (klass) { + for (l = 1; l < mif->n_obj_properties; l++) { + const GParamSpec *sp = mif->obj_properties[l]; + + g_assert (sp); + g_assert (sp->name); + g_assert (strlen (sp->name) > 0); + } + } + + g_assert (mif->obj_properties_reverse_idx); + if (klass) { + g_assert (mif->obj_properties_reverse_idx[0] == 0xFFu); + for (l = 0; l < mif->n_obj_properties; l++) { + guint8 ridx = mif->obj_properties_reverse_idx[l]; + + if (ridx != 0xFFu) { + g_assert_cmpint (ridx, <=, mif->n_dbus_properties); + for (m = l + 1; m < mif->n_obj_properties; m++) + g_assert_cmpint (ridx, !=, mif->obj_properties_reverse_idx[m]); + } + } + } + } + +check_dbus_properties: + for (l = 0; l < mif->n_dbus_properties; l++) { + const NMLDBusMetaProperty *mpr = &mif->dbus_properties[l]; + gs_free char *obj_property_name = NULL; + const struct { + const char *dbus_type; + GType default_gtype; + } *p_expected_type, *p_expected_type_2, expected_types[] = { + { "b", G_TYPE_BOOLEAN }, + { "q", G_TYPE_UINT }, + { "y", G_TYPE_UCHAR }, + { "i", G_TYPE_INT }, + { "u", G_TYPE_UINT }, + { "x", G_TYPE_INT64 }, + { "t", G_TYPE_UINT64 }, + { "s", G_TYPE_STRING }, + { "o", G_TYPE_STRING }, + { "ay", G_TYPE_BYTES }, + { "as", G_TYPE_STRV }, + { "ao", G_TYPE_PTR_ARRAY }, + { "a{sv}", G_TYPE_HASH_TABLE }, + { "aa{sv}", G_TYPE_PTR_ARRAY }, + + { "(uu)", G_TYPE_NONE }, + { "aau", G_TYPE_NONE }, + { "au", G_TYPE_NONE }, + { "a(ayuay)", G_TYPE_NONE }, + { "aay", G_TYPE_NONE }, + { "a(ayuayu)", G_TYPE_NONE }, + + { "u", G_TYPE_FLAGS }, + { "u", G_TYPE_ENUM }, + { "o", NM_TYPE_OBJECT }, + }; + const GParamSpec *pspec = NULL; + + g_assert (mpr->dbus_property_name); + g_assert (g_variant_type_string_is_valid ((const char *) mpr->dbus_type)); + if (l > 0) { + if (strcmp (mif->dbus_properties[l - 1].dbus_property_name, mpr->dbus_property_name) >= 0) { + g_error ("meta-ifaces[%s] must have property #%u \"%s\" after #%u \"%s\"", + mif->dbus_iface_name, l - 1, mif->dbus_properties[l - 1].dbus_property_name, l, mpr->dbus_property_name); + } + } + + obj_property_name = nm_utils_wincaps_to_dash (mpr->dbus_property_name); + g_assert (obj_property_name); + + for (p_expected_type = &expected_types[0]; TRUE; ) { + if (nm_streq ((const char *) mpr->dbus_type, p_expected_type->dbus_type)) + break; + p_expected_type++; + if (p_expected_type >= &expected_types[G_N_ELEMENTS (expected_types)]) { + g_error ("D-Bus type \"%s\" is not implemented (in property %s.%s)", + (const char *) mpr->dbus_type, + mif->dbus_iface_name, + mpr->dbus_property_name); + } + } + + if ( klass + && mpr->obj_properties_idx > 0) { + g_assert_cmpint (mpr->obj_properties_idx, <, mif->n_obj_properties); + if (!mpr->obj_property_no_reverse_idx) + g_assert_cmpint (mif->obj_properties_reverse_idx[mpr->obj_properties_idx], ==, l); + else { + g_assert_cmpint (mif->obj_properties_reverse_idx[mpr->obj_properties_idx], !=, l); + g_assert_cmpint (mif->obj_properties_reverse_idx[mpr->obj_properties_idx], !=, 0xFFu); + } + pspec = mif->obj_properties[mpr->obj_properties_idx]; + } + + if (mpr->use_notify_update_prop) { + g_assert (mpr->notify_update_prop); + } else { + if (klass) + g_assert (pspec); + } + + if (pspec) { + const char *expected_property_name; + + if ( mif == &_nml_dbus_meta_iface_nm_connection_active + && nm_streq (pspec->name, NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT_PATH)) { + g_assert_cmpstr (obj_property_name, ==, "specific-object"); + expected_property_name = NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT_PATH; + } else if ( mif == &_nml_dbus_meta_iface_nm_accesspoint + && nm_streq (pspec->name, NM_ACCESS_POINT_BSSID)) { + g_assert_cmpstr (obj_property_name, ==, "hw-address"); + expected_property_name = NM_ACCESS_POINT_BSSID; + } else if ( mif == &_nml_dbus_meta_iface_nm_device_wireguard + && nm_streq (pspec->name, NM_DEVICE_WIREGUARD_FWMARK)) { + g_assert_cmpstr (obj_property_name, ==, "fw-mark"); + expected_property_name = NM_DEVICE_WIREGUARD_FWMARK; + } else if ( NM_IN_SET (mif, &_nml_dbus_meta_iface_nm_ip4config, + &_nml_dbus_meta_iface_nm_ip6config) + && nm_streq (pspec->name, NM_IP_CONFIG_ADDRESSES)) { + g_assert (NM_IN_STRSET (obj_property_name, "addresses", "address-data")); + expected_property_name = NM_IP_CONFIG_ADDRESSES; + } else if ( NM_IN_SET (mif, &_nml_dbus_meta_iface_nm_ip4config, + &_nml_dbus_meta_iface_nm_ip6config) + && nm_streq (pspec->name, NM_IP_CONFIG_ROUTES)) { + g_assert (NM_IN_STRSET (obj_property_name, "routes", "route-data")); + expected_property_name = NM_IP_CONFIG_ROUTES; + } else if ( NM_IN_SET (mif, &_nml_dbus_meta_iface_nm_ip4config, + &_nml_dbus_meta_iface_nm_ip6config) + && nm_streq (pspec->name, NM_IP_CONFIG_NAMESERVERS)) { + g_assert (NM_IN_STRSET (obj_property_name, "nameservers", "nameserver-data")); + expected_property_name = NM_IP_CONFIG_NAMESERVERS; + } else if ( mif == &_nml_dbus_meta_iface_nm_ip4config + && nm_streq (pspec->name, NM_IP_CONFIG_WINS_SERVERS)) { + g_assert (NM_IN_STRSET (obj_property_name, "wins-servers", "wins-server-data")); + expected_property_name = NM_IP_CONFIG_WINS_SERVERS; + } else if ( mif == &_nml_dbus_meta_iface_nm_dnsmanager + && nm_streq (pspec->name, NM_CLIENT_DNS_CONFIGURATION)) { + g_assert_cmpstr (obj_property_name, ==, "configuration"); + expected_property_name = NM_CLIENT_DNS_CONFIGURATION; + } else if ( mif == &_nml_dbus_meta_iface_nm_dnsmanager + && nm_streq (pspec->name, NM_CLIENT_DNS_MODE)) { + g_assert_cmpstr (obj_property_name, ==, "mode"); + expected_property_name = NM_CLIENT_DNS_MODE; + } else if ( mif == &_nml_dbus_meta_iface_nm_dnsmanager + && nm_streq (pspec->name, NM_CLIENT_DNS_RC_MANAGER)) { + g_assert_cmpstr (obj_property_name, ==, "rc-manager"); + expected_property_name = NM_CLIENT_DNS_RC_MANAGER; + } else + expected_property_name = obj_property_name; + + g_assert_cmpstr (expected_property_name, ==, pspec->name); + + if (!mpr->use_notify_update_prop) { + for (p_expected_type_2 = &expected_types[0]; p_expected_type_2 < &expected_types[G_N_ELEMENTS (expected_types)]; p_expected_type_2++) { + if (!nm_streq ((const char *) mpr->dbus_type, p_expected_type_2->dbus_type)) + continue; + if ( pspec->value_type == p_expected_type_2->default_gtype + || ( p_expected_type_2->default_gtype == G_TYPE_ENUM + && g_type_is_a (pspec->value_type, G_TYPE_ENUM)) + || ( p_expected_type_2->default_gtype == G_TYPE_FLAGS + && g_type_is_a (pspec->value_type, G_TYPE_FLAGS)) + || ( p_expected_type_2->default_gtype == NM_TYPE_OBJECT + && nm_streq ((const char *) mpr->dbus_type, "o") + && g_type_is_a (pspec->value_type, NM_TYPE_OBJECT))) + break; + } + if (p_expected_type_2 >= &expected_types[G_N_ELEMENTS (expected_types)]) { + g_error ("D-Bus property \"%s.%s\" (type \"%s\") maps to property \"%s\", but that has an unexpected property type %s (expected %s)", + mif->dbus_iface_name, + mpr->dbus_property_name, + (const char *) mpr->dbus_type, + pspec->name, + g_type_name (pspec->value_type), + g_type_name (p_expected_type->default_gtype)); + } + } + + if (!nm_utils_g_param_spec_is_default (pspec)) { + /* We expect our properties to have a default value of zero/NULL. + * Except those whitelisted here: */ + if ( ( mif == &_nml_dbus_meta_iface_nm_accesspoint + && nm_streq (pspec->name, NM_ACCESS_POINT_LAST_SEEN)) + || ( mif == &_nml_dbus_meta_iface_nm_device_vxlan + && nm_streq (pspec->name, NM_DEVICE_VXLAN_LEARNING)) + || ( mif == &_nml_dbus_meta_iface_nm_device_wireless + && nm_streq (pspec->name, NM_DEVICE_WIFI_LAST_SCAN)) + || ( mif == &_nml_dbus_meta_iface_nm_wifip2ppeer + && nm_streq (pspec->name, NM_WIFI_P2P_PEER_LAST_SEEN)) + || ( mif == &_nml_dbus_meta_iface_nm_device_tun + && NM_IN_STRSET (pspec->name, NM_DEVICE_TUN_GROUP, + NM_DEVICE_TUN_OWNER))) { + /* pass */ + } else { + g_error ("property %s.%s (%s.%s) does not have a default value of zero", + mif->dbus_iface_name, + mpr->dbus_property_name, + g_type_name (gtype), + pspec->name); + } + } + } + } + + if (klass) { + for (l = 0; l < mif->n_obj_properties; l++) { + guint8 ridx = mif->obj_properties_reverse_idx[l]; + + if (ridx != 0xFFu) + g_assert_cmpint (mif->dbus_properties[ridx].obj_properties_idx, ==, l); + } + } + + g_assert (mif == nml_dbus_meta_iface_get (mif->dbus_iface_name)); + } + + meta_iface = nml_dbus_meta_iface_get (NM_DBUS_INTERFACE); + g_assert (meta_iface); + g_assert (meta_iface == &_nml_dbus_meta_iface_nm); + g_assert_cmpstr (meta_iface->dbus_iface_name, ==, NM_DBUS_INTERFACE); + + meta_property = nml_dbus_meta_property_get (meta_iface, "Version", &prop_idx); + g_assert (meta_property); + g_assert_cmpstr (meta_property->dbus_property_name, ==, "Version"); + g_assert (&meta_iface->dbus_properties[prop_idx] == meta_property); +} + +/*****************************************************************************/ + +static void +test_dbus_meta_types (void) +{ + struct list_data { + const char *dbus_iface_name; + GType gtype; + NMLDBusMetaInteracePrio interface_prio; + } list[] = { + { NM_DBUS_INTERFACE, NM_TYPE_CLIENT, NML_DBUS_META_INTERFACE_PRIO_NMCLIENT, }, + { NM_DBUS_INTERFACE_ACCESS_POINT, NM_TYPE_ACCESS_POINT, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_ACTIVE_CONNECTION, NM_TYPE_ACTIVE_CONNECTION, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW, }, /* otherwise, NM_TYPE_VPN_CONNECTION. */ + { NM_DBUS_INTERFACE_DEVICE_6LOWPAN, NM_TYPE_DEVICE_6LOWPAN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_ADSL, NM_TYPE_DEVICE_ADSL, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_BOND, NM_TYPE_DEVICE_BOND, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_BRIDGE, NM_TYPE_DEVICE_BRIDGE, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_BLUETOOTH, NM_TYPE_DEVICE_BT, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_DUMMY, NM_TYPE_DEVICE_DUMMY, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_WIRED, NM_TYPE_DEVICE_ETHERNET, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_GENERIC, NM_TYPE_DEVICE_GENERIC, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_INFINIBAND, NM_TYPE_DEVICE_INFINIBAND, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL, NM_TYPE_DEVICE_IP_TUNNEL, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_MACSEC, NM_TYPE_DEVICE_MACSEC, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_MACVLAN, NM_TYPE_DEVICE_MACVLAN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_MODEM, NM_TYPE_DEVICE_MODEM, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_OLPC_MESH, NM_TYPE_DEVICE_OLPC_MESH, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_OVS_INTERFACE, NM_TYPE_DEVICE_OVS_INTERFACE, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_OVS_PORT, NM_TYPE_DEVICE_OVS_PORT, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_OVS_BRIDGE, NM_TYPE_DEVICE_OVS_BRIDGE, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_WIFI_P2P, NM_TYPE_DEVICE_WIFI_P2P, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_PPP, NM_TYPE_DEVICE_PPP, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_TEAM, NM_TYPE_DEVICE_TEAM, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_TUN, NM_TYPE_DEVICE_TUN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_VLAN, NM_TYPE_DEVICE_VLAN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_WPAN, NM_TYPE_DEVICE_WPAN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_VXLAN, NM_TYPE_DEVICE_VXLAN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_WIRELESS, NM_TYPE_DEVICE_WIFI, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DEVICE_WIREGUARD, NM_TYPE_DEVICE_WIREGUARD, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DHCP4_CONFIG, NM_TYPE_DHCP4_CONFIG, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_DHCP6_CONFIG, NM_TYPE_DHCP6_CONFIG, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_IP4_CONFIG, NM_TYPE_IP4_CONFIG, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_IP6_CONFIG, NM_TYPE_IP6_CONFIG, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_WIFI_P2P_PEER, NM_TYPE_WIFI_P2P_PEER, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_SETTINGS_CONNECTION, NM_TYPE_REMOTE_CONNECTION, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_SETTINGS, NM_TYPE_CLIENT, NML_DBUS_META_INTERFACE_PRIO_NMCLIENT, }, + { NM_DBUS_INTERFACE_DNS_MANAGER, NM_TYPE_CLIENT, NML_DBUS_META_INTERFACE_PRIO_NMCLIENT, }, + { NM_DBUS_INTERFACE_VPN_CONNECTION, NM_TYPE_VPN_CONNECTION, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + { NM_DBUS_INTERFACE_CHECKPOINT, NM_TYPE_CHECKPOINT, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, }, + }; + guint i; + + /* These iface<->gtype associations are copied from "nm-client.c"'s obj_nm_for_gdbus_object(). + * This is redundant to the meta-data, still check that the meta data matches. */ + for (i = 0; i < G_N_ELEMENTS (list); i++) { + const struct list_data *d = &list[i]; + const NMLDBusMetaIface *meta_iface; + + meta_iface = nml_dbus_meta_iface_get (d->dbus_iface_name); + g_assert (meta_iface); + g_assert_cmpint (meta_iface->interface_prio, ==, d->interface_prio); + g_assert (meta_iface->get_type_fcn() == d->gtype); + } +} +/*****************************************************************************/ + NMTST_DEFINE (); int main (int argc, char **argv) @@ -2439,6 +3075,9 @@ int main (int argc, char **argv) g_test_add_func ("/libnm/general/fixup_product_string", test_fixup_product_string); g_test_add_func ("/libnm/general/fixup_vendor_string", test_fixup_vendor_string); g_test_add_func ("/libnm/general/nm_vpn_service_plugin_read_vpn_details", test_nm_vpn_service_plugin_read_vpn_details); + g_test_add_func ("/libnm/general/test_types", test_types); + g_test_add_func ("/libnm/general/test_nml_dbus_meta", test_nml_dbus_meta); + g_test_add_func ("/libnm/general/test_dbus_meta_types", test_dbus_meta_types); return g_test_run (); } diff --git a/libnm/tests/test-nm-client.c b/libnm/tests/test-nm-client.c index 44cd5b3b..afcc4962 100644 --- a/libnm/tests/test-nm-client.c +++ b/libnm/tests/test-nm-client.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0+ /* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2010 - 2014 Red Hat, Inc. - * + * Copyright (C) 2010 - 2014 Red Hat, Inc. */ #include "nm-default.h" @@ -24,8 +10,9 @@ #include "nm-test-libnm-utils.h" -static GMainLoop *loop = NULL; -static NMTstcServiceInfo *sinfo; +static struct { + GMainLoop *loop; +} gl = { }; /*****************************************************************************/ @@ -61,7 +48,8 @@ devices_notify_cb (NMClient *c, static void test_device_added (void) { - NMClient *client; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; const GPtrArray *devices; NMDevice *device; gboolean notified = FALSE; @@ -71,8 +59,7 @@ test_device_added (void) if (!nmtstc_service_available (sinfo)) return; - client = nm_client_new (NULL, &error); - g_assert_no_error (error); + client = nmtstc_client_new (TRUE); devices = nm_client_get_devices (client); g_assert (devices->len == 0); @@ -103,9 +90,6 @@ test_device_added (void) nm_device_delete (device, NULL, &error); g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_SOFTWARE); g_clear_error (&error); - - g_object_unref (client); - g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*****************************************************************************/ @@ -142,6 +126,8 @@ devices_sai_notify_cb (NMClient *c, const GPtrArray *devices; NMDevice *device; + g_assert_cmpstr (pspec->name, ==, "devices"); + devices = nm_client_get_devices (c); g_assert (devices); g_assert_cmpint (devices->len, ==, 1); @@ -157,18 +143,17 @@ devices_sai_notify_cb (NMClient *c, static void test_device_added_signal_after_init (void) { - NMClient *client; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; const GPtrArray *devices; NMDevice *device; guint result = 0; - GError *error = NULL; sinfo = nmtstc_service_init (); if (!nmtstc_service_available (sinfo)) return; - client = nm_client_new (NULL, &error); - g_assert_no_error (error); + client = nmtstc_client_new (TRUE); devices = nm_client_get_devices (client); g_assert (devices->len == 0); @@ -195,8 +180,8 @@ test_device_added_signal_after_init (void) g_signal_handlers_disconnect_by_func (client, device_sai_added_cb, &result); g_signal_handlers_disconnect_by_func (client, devices_sai_notify_cb, &result); - g_assert ((result & SIGNAL_MASK) == SIGNAL_FIRST); - g_assert ((result & NOTIFY_MASK) == NOTIFY_SECOND); + g_assert ((result & SIGNAL_MASK) == SIGNAL_SECOND); + g_assert ((result & NOTIFY_MASK) == NOTIFY_FIRST); devices = nm_client_get_devices (client); g_assert (devices); @@ -205,9 +190,6 @@ test_device_added_signal_after_init (void) device = g_ptr_array_index (devices, 0); g_assert (device); g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0"); - - g_object_unref (client); - g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*****************************************************************************/ @@ -307,19 +289,19 @@ wifi_ap_remove_notify_cb (NMDeviceWifi *w, static void test_wifi_ap_added_removed (void) { - NMClient *client; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; NMDeviceWifi *wifi; - WifiApInfo info = { loop, FALSE, FALSE, 0, 0 }; + WifiApInfo info = { gl.loop, FALSE, FALSE, 0, 0 }; GVariant *ret; GError *error = NULL; - char *expected_path = NULL; + gs_free char *expected_path = NULL; sinfo = nmtstc_service_init (); if (!nmtstc_service_available (sinfo)) return; - client = nm_client_new (NULL, &error); - g_assert_no_error (error); + client = nmtstc_client_new (TRUE); /*************************************/ /* Add the wifi device */ @@ -358,8 +340,8 @@ test_wifi_ap_added_removed (void) info.quit_count++; /* Wait for libnm to find the AP */ - info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); - g_main_loop_run (loop); + info.quit_id = g_timeout_add_seconds (5, loop_quit, gl.loop); + g_main_loop_run (gl.loop); g_assert (info.signaled); g_assert (info.notified); @@ -397,8 +379,8 @@ test_wifi_ap_added_removed (void) info.quit_count++; /* Wait for libnm to find the AP */ - info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); - g_main_loop_run (loop); + info.quit_id = g_timeout_add_seconds (5, loop_quit, gl.loop); + g_main_loop_run (gl.loop); g_assert (info.signaled); g_assert (info.notified); @@ -406,212 +388,6 @@ test_wifi_ap_added_removed (void) g_signal_handlers_disconnect_by_func (wifi, wifi_ap_remove_notify_cb, &info); g_free (info.ap_path); - g_free (expected_path); - - g_object_unref (client); - g_clear_pointer (&sinfo, nmtstc_service_cleanup); -} - -/*****************************************************************************/ - -static const char *expected_nsp_name = "Clear"; - -typedef struct { - GMainLoop *loop; - gboolean found; - char *nsp_path; - gboolean signaled; - gboolean notified; - guint quit_id; - guint quit_count; -} WimaxNspInfo; - -static void -wimax_check_quit (WimaxNspInfo *info) -{ - info->quit_count--; - if (info->quit_count == 0) { - g_source_remove (info->quit_id); - info->quit_id = 0; - g_main_loop_quit (info->loop); - } -} - -static void -got_nsp_path (WimaxNspInfo *info, const char *path) -{ - if (info->nsp_path) - g_assert_cmpstr (info->nsp_path, ==, path); - else - info->nsp_path = g_strdup (path); -} - -static void -wimax_nsp_added_cb (NMDeviceWimax *w, - NMWimaxNsp *nsp, - WimaxNspInfo *info) -{ - g_assert (nsp); - g_assert_cmpstr (nm_wimax_nsp_get_name (nsp), ==, expected_nsp_name); - got_nsp_path (info, nm_object_get_path (NM_OBJECT (nsp))); - - info->signaled = TRUE; - wimax_check_quit (info); -} - -static void -wimax_nsp_add_notify_cb (NMDeviceWimax *w, - GParamSpec *pspec, - WimaxNspInfo *info) -{ - const GPtrArray *nsps; - NMWimaxNsp *nsp; - - nsps = nm_device_wimax_get_nsps (w); - g_assert (nsps); - g_assert_cmpint (nsps->len, ==, 1); - - nsp = g_ptr_array_index (nsps, 0); - g_assert (nsp); - g_assert_cmpstr (nm_wimax_nsp_get_name (nsp), ==, expected_nsp_name); - got_nsp_path (info, nm_object_get_path (NM_OBJECT (nsp))); - - info->notified = TRUE; - wimax_check_quit (info); -} - -static void -wimax_nsp_removed_cb (NMDeviceWimax *w, - NMWimaxNsp *nsp, - WimaxNspInfo *info) -{ - g_assert (nsp); - g_assert_cmpstr (info->nsp_path, ==, nm_object_get_path (NM_OBJECT (nsp))); - - info->signaled = TRUE; - wimax_check_quit (info); -} - -static void -wimax_nsp_remove_notify_cb (NMDeviceWimax *w, - GParamSpec *pspec, - WimaxNspInfo *info) -{ - const GPtrArray *nsps; - - nsps = nm_device_wimax_get_nsps (w); - g_assert (nsps->len == 0); - - info->notified = TRUE; - wimax_check_quit (info); -} - -static void -test_wimax_nsp_added_removed (void) -{ - NMClient *client; - NMDeviceWimax *wimax; - WimaxNspInfo info = { loop, FALSE, FALSE, 0, 0 }; - GVariant *ret; - GError *error = NULL; - char *expected_path = NULL; - - sinfo = nmtstc_service_init (); - if (!nmtstc_service_available (sinfo)) - return; - - client = nm_client_new (NULL, &error); - g_assert_no_error (error); - - /*************************************/ - /* Add the wimax device */ - wimax = (NMDeviceWimax *) nmtstc_service_add_device (sinfo, client, "AddWimaxDevice", "wmx0"); - g_assert (NM_IS_DEVICE_WIMAX (wimax)); - - /*************************************/ - /* Add the wimax NSP */ - info.signaled = FALSE; - info.notified = FALSE; - info.quit_id = 0; - - ret = g_dbus_proxy_call_sync (sinfo->proxy, - "AddWimaxNsp", - g_variant_new ("(ss)", "wmx0", expected_nsp_name), - G_DBUS_CALL_FLAGS_NO_AUTO_START, - 3000, - NULL, - &error); - g_assert_no_error (error); - g_assert (ret); - g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)"); - g_variant_get (ret, "(o)", &expected_path); - g_variant_unref (ret); - - g_signal_connect (wimax, - "nsp-added", - (GCallback) wimax_nsp_added_cb, - &info); - info.quit_count = 1; - - g_signal_connect (wimax, - "notify::nsps", - (GCallback) wimax_nsp_add_notify_cb, - &info); - info.quit_count++; - - /* Wait for libnm to find the AP */ - info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); - g_main_loop_run (loop); - - g_assert (info.signaled); - g_assert (info.notified); - g_assert (info.nsp_path); - g_assert_cmpstr (info.nsp_path, ==, expected_path); - g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_added_cb, &info); - g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_add_notify_cb, &info); - - /*************************************/ - /* Remove the wimax NSP */ - info.signaled = FALSE; - info.notified = FALSE; - info.quit_id = 0; - - ret = g_dbus_proxy_call_sync (sinfo->proxy, - "RemoveWimaxNsp", - g_variant_new ("(so)", "wmx0", expected_path), - G_DBUS_CALL_FLAGS_NO_AUTO_START, - 3000, - NULL, - &error); - g_assert_no_error (error); - g_clear_pointer (&ret, g_variant_unref); - - g_signal_connect (wimax, - "nsp-removed", - (GCallback) wimax_nsp_removed_cb, - &info); - info.quit_count = 1; - - g_signal_connect (wimax, - "notify::nsps", - (GCallback) wimax_nsp_remove_notify_cb, - &info); - info.quit_count++; - - /* Wait for libnm to find the AP */ - info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); - g_main_loop_run (loop); - - g_assert (info.signaled); - g_assert (info.notified); - g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_removed_cb, &info); - g_signal_handlers_disconnect_by_func (wimax, wimax_nsp_remove_notify_cb, &info); - - g_free (info.nsp_path); - g_free (expected_path); - - g_object_unref (client); - g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*****************************************************************************/ @@ -671,25 +447,11 @@ da_devices_notify_cb (NMClient *c, } static void -new_client_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - NMClient **out_client = user_data; - GError *error = NULL; - - *out_client = nm_client_new_finish (result, &error); - g_assert_no_error (error); - g_assert (*out_client != NULL); - - g_main_loop_quit (loop); -} - -static void test_devices_array (void) { - NMClient *client = NULL; - DaInfo info = { loop }; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; + DaInfo info = { gl.loop }; NMDevice *wlan0, *eth0, *eth1, *device; const GPtrArray *devices; GError *error = NULL; @@ -699,10 +461,7 @@ test_devices_array (void) if (!nmtstc_service_available (sinfo)) return; - /* Make sure that we test the async codepath in at least one test... */ - nm_client_new_async (NULL, new_client_cb, &client); - g_main_loop_run (loop); - g_assert (client != NULL); + client = nmtstc_client_new (TRUE); /*************************************/ /* Add some devices */ @@ -752,8 +511,8 @@ test_devices_array (void) info.quit_count = 2; /* Wait for libnm to notice the changes */ - info.quit_id = g_timeout_add_seconds (5, loop_quit, loop); - g_main_loop_run (loop); + info.quit_id = g_timeout_add_seconds (5, loop_quit, gl.loop); + g_main_loop_run (gl.loop); g_assert_cmpint (info.quit_count, ==, 0); g_signal_handlers_disconnect_by_func (client, da_device_removed_cb, &info); @@ -771,9 +530,6 @@ test_devices_array (void) device = nm_client_get_device_by_iface (client, "eth1"); g_assert (NM_IS_DEVICE_ETHERNET (device)); g_assert (device == eth1); - - g_object_unref (client); - g_clear_pointer (&sinfo, nmtstc_service_cleanup); } static void @@ -784,20 +540,20 @@ nm_running_changed (GObject *client, int *running_changed = user_data; (*running_changed)++; - g_main_loop_quit (loop); + g_main_loop_quit (gl.loop); } static void test_client_nm_running (void) { + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; gs_unref_object NMClient *client1 = NULL; gs_unref_object NMClient *client2 = NULL; guint quit_id; int running_changed = 0; GError *error = NULL; - client1 = nm_client_new (NULL, &error); - g_assert_no_error (error); + client1 = nmtstc_client_new (TRUE); g_assert (!nm_client_get_nm_running (client1)); g_assert_cmpstr (nm_client_get_version (client1), ==, NULL); @@ -817,8 +573,7 @@ test_client_nm_running (void) if (!nmtstc_service_available (sinfo)) return; - client2 = nm_client_new (NULL, &error); - g_assert_no_error (error); + client2 = nmtstc_client_new (FALSE); /* client2 should know that NM is running, but the previously-created * client1 hasn't gotten the news yet. @@ -828,8 +583,8 @@ test_client_nm_running (void) g_signal_connect (client1, "notify::" NM_CLIENT_NM_RUNNING, G_CALLBACK (nm_running_changed), &running_changed); - quit_id = g_timeout_add_seconds (5, loop_quit, loop); - g_main_loop_run (loop); + quit_id = g_timeout_add_seconds (5, loop_quit, gl.loop); + g_main_loop_run (gl.loop); g_assert_cmpint (running_changed, ==, 1); g_assert (nm_client_get_nm_running (client1)); g_source_remove (quit_id); @@ -839,8 +594,8 @@ test_client_nm_running (void) g_assert (nm_client_get_nm_running (client1)); - quit_id = g_timeout_add_seconds (5, loop_quit, loop); - g_main_loop_run (loop); + quit_id = g_timeout_add_seconds (5, loop_quit, gl.loop); + g_main_loop_run (gl.loop); g_assert_cmpint (running_changed, ==, 2); g_assert (!nm_client_get_nm_running (client1)); g_source_remove (quit_id); @@ -851,6 +606,9 @@ typedef struct { NMActiveConnection *ac; int remaining; + + NMDevice *device; + gulong ac_signal_id; } TestACInfo; static void @@ -877,13 +635,18 @@ assert_ac_and_device (NMClient *client) device = devices->pdata[0]; if (device != ac_device && devices->len > 1) device = devices->pdata[1]; - device_ac = nm_device_get_active_connection (device); - g_assert (device_ac != NULL); g_assert_cmpstr (nm_object_get_path (NM_OBJECT (device)), ==, nm_object_get_path (NM_OBJECT (ac_device))); g_assert (device == ac_device); - g_assert_cmpstr (nm_object_get_path (NM_OBJECT (ac)), ==, nm_object_get_path (NM_OBJECT (device_ac))); - g_assert (ac == device_ac); + + device_ac = nm_device_get_active_connection (device); + if (!device_ac) { + /* the stub NetworkManager service starts activating in an idle handler (delayed). That means, the + * device may not yet refer to the active connection at this point. */ + } else { + g_assert_cmpstr (nm_object_get_path (NM_OBJECT (ac)), ==, nm_object_get_path (NM_OBJECT (device_ac))); + g_assert (ac == device_ac); + } } static void @@ -940,18 +703,17 @@ device_ac_changed_cb (GObject *device, static void test_active_connections (void) { - NMClient *client; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; NMDevice *device; NMConnection *conn; - TestACInfo info = { loop, NULL, 0 }; - GError *error = NULL; + TestACInfo info = { gl.loop, NULL, 0 }; sinfo = nmtstc_service_init (); if (!nmtstc_service_available (sinfo)) return; - client = nm_client_new (NULL, &error); - g_assert_no_error (error); + client = nmtstc_client_new (TRUE); /* Tell the test service to add a new device */ device = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); @@ -968,30 +730,25 @@ test_active_connections (void) /* Two signals plus activate_cb */ info.remaining = 3; - g_main_loop_run (loop); + g_main_loop_run (gl.loop); g_signal_handlers_disconnect_by_func (client, client_acs_changed_cb, &info); g_signal_handlers_disconnect_by_func (device, device_ac_changed_cb, &info); g_assert (info.ac != NULL); g_object_unref (info.ac); - g_object_unref (client); + g_clear_object (&client); /* Ensure that we can correctly resolve the recursive property link between the * AC and the Device in a newly-created client. */ - client = nm_client_new (NULL, &error); - g_assert_no_error (error); + client = nmtstc_client_new (TRUE); assert_ac_and_device (client); - g_object_unref (client); + g_clear_object (&client); - client = NULL; - nm_client_new_async (NULL, new_client_cb, &client); - g_main_loop_run (loop); + client = nmtstc_client_new (TRUE); assert_ac_and_device (client); - g_object_unref (client); - - g_clear_pointer (&sinfo, nmtstc_service_cleanup); + g_clear_object (&client); } static void @@ -1019,9 +776,12 @@ client_devices_changed_cb (GObject *client, g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0.1"); if (!nm_device_get_active_connection (device)) { + g_assert (info->ac_signal_id == 0); info->remaining++; - g_signal_connect (device, "notify::" NM_DEVICE_ACTIVE_CONNECTION, - G_CALLBACK (device_ac_changed_cb), info); + info->device = device; + g_object_add_weak_pointer (G_OBJECT (device), (gpointer *) &info->device); + info->ac_signal_id = g_signal_connect (device, "notify::" NM_DEVICE_ACTIVE_CONNECTION, + G_CALLBACK (device_ac_changed_cb), info); } info->remaining--; @@ -1070,20 +830,19 @@ activate_cb (GObject *object, static void test_activate_virtual (void) { - NMClient *client; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; NMConnection *conn; NMSettingConnection *s_con; NMSettingVlan *s_vlan; - TestACInfo info = { loop, NULL, 0 }; - TestConnectionInfo conn_info = { loop, NULL }; - GError *error = NULL; + TestACInfo info = { gl.loop, NULL, 0 }; + TestConnectionInfo conn_info = { gl.loop, NULL }; sinfo = nmtstc_service_init (); if (!nmtstc_service_available (sinfo)) return; - client = nm_client_new (NULL, &error); - g_assert_no_error (error); + client = nmtstc_client_new (TRUE); nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); @@ -1099,7 +858,7 @@ test_activate_virtual (void) nm_client_add_connection_async (client, conn, TRUE, NULL, add_connection_cb, &conn_info); - g_main_loop_run (loop); + g_main_loop_run (gl.loop); g_object_unref (conn); conn = NM_CONNECTION (conn_info.remote); @@ -1119,72 +878,27 @@ test_activate_virtual (void) */ info.remaining = 3; - g_main_loop_run (loop); + g_main_loop_run (gl.loop); g_signal_handlers_disconnect_by_func (client, client_acs_changed_cb, &info); g_signal_handlers_disconnect_by_func (client, client_devices_changed_cb, &info); g_assert (info.ac != NULL); + g_clear_object (&info.ac); - g_object_unref (info.ac); - g_object_unref (client); - - g_clear_pointer (&sinfo, nmtstc_service_cleanup); -} - -static void -activate_failed_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - NMClient *client = NM_CLIENT (object); - NMActiveConnection *ac; - GError *error = NULL; - - ac = nm_client_activate_connection_finish (client, result, &error); - g_assert (ac == NULL); - g_assert_error (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_OBJECT_CREATION_FAILED); - g_clear_error (&error); - - g_main_loop_quit (loop); -} - -static void -test_activate_failed (void) -{ - NMClient *client; - NMDevice *device; - NMConnection *conn; - GError *error = NULL; - - sinfo = nmtstc_service_init (); - if (!nmtstc_service_available (sinfo)) - return; - - client = nm_client_new (NULL, &error); - g_assert_no_error (error); - - device = nmtstc_service_add_device (sinfo, client, "AddWiredDevice", "eth0"); - - /* Note that test-networkmanager-service.py checks for this exact name */ - conn = nmtst_create_minimal_connection ("object-creation-failed-test", NULL, - NM_SETTING_WIRED_SETTING_NAME, NULL); - - nm_client_add_and_activate_connection_async (client, conn, device, NULL, - NULL, activate_failed_cb, NULL); - g_main_loop_run (loop); - - g_object_unref (conn); - g_object_unref (client); - - g_clear_pointer (&sinfo, nmtstc_service_cleanup); + if (info.device) { + g_object_remove_weak_pointer (G_OBJECT (info.device), (gpointer *) &info.device); + nm_clear_g_signal_handler (info.device, &info.ac_signal_id); + } } static void test_device_connection_compatibility (void) { - NMClient *client; - NMDevice *device1, *device2; - NMConnection *conn; + nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL; + gs_unref_object NMClient *client = NULL; + gs_unref_object NMConnection *conn = NULL; + NMDevice *device1; + NMDevice *device2; NMSettingWired *s_wired; GError *error = NULL; const char *subchannels[] = { "0.0.8000", "0.0.8001", "0.0.8002", NULL }; @@ -1197,8 +911,7 @@ test_device_connection_compatibility (void) if (!nmtstc_service_available (sinfo)) return; - client = nm_client_new (NULL, &error); - g_assert_no_error (error); + client = nmtstc_client_new (TRUE); /* Create two devices */ device1 = nmtstc_service_add_wired_device (sinfo, client, "eth0", hw_addr1, subchannels); @@ -1246,11 +959,6 @@ test_device_connection_compatibility (void) nm_device_connection_compatible (device1, conn, &error); g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION); g_clear_error (&error); - - g_object_unref (conn); - g_object_unref (client); - - g_clear_pointer (&sinfo, nmtstc_service_cleanup); } /*****************************************************************************/ @@ -1283,7 +991,6 @@ test_connection_invalid (void) NMSettingConnection *s_con; gs_unref_object NMClient *client = NULL; const GPtrArray *connections; - gs_free_error GError *error = NULL; gs_free char *path0 = NULL; gs_free char *path1 = NULL; gs_free char *path2 = NULL; @@ -1293,6 +1000,8 @@ test_connection_invalid (void) gssize idx[4]; gs_unref_variant GVariant *variant = NULL; + g_assert (g_main_loop_get_context (gl.loop) == (g_main_context_get_thread_default () ?: g_main_context_default ())); + /************************************************************************** * Add three connections before starting libnm. One valid, two invalid. *************************************************************************/ @@ -1334,8 +1043,7 @@ test_connection_invalid (void) FALSE, &path2); - client = nm_client_new (NULL, &error); - g_assert_no_error (error); + client = nmtstc_client_new (TRUE); connections = nm_client_get_connections (client); g_assert (connections); @@ -1370,7 +1078,7 @@ test_connection_invalid (void) FALSE, &path3); - nmtst_main_loop_run (loop, 1000); + nmtst_main_loop_run (gl.loop, 1000); connections = nm_client_get_connections (client); g_assert (connections); @@ -1406,7 +1114,7 @@ test_connection_invalid (void) variant, FALSE); - nmtst_main_loop_run (loop, 100); + nmtst_main_loop_run (gl.loop, 100); connections = nm_client_get_connections (client); g_assert (connections); @@ -1444,7 +1152,7 @@ test_connection_invalid (void) variant, FALSE); - nmtst_main_loop_run (loop, 100); + nmtst_main_loop_run (gl.loop, 100); connections = nm_client_get_connections (client); g_assert (connections); @@ -1479,7 +1187,7 @@ test_connection_invalid (void) connection, FALSE); - nmtst_main_loop_run (loop, 100); + nmtst_main_loop_run (gl.loop, 100); connections = nm_client_get_connections (client); g_assert (connections); @@ -1521,7 +1229,7 @@ test_connection_invalid (void) connection, FALSE); - nmtst_main_loop_run (loop, 100); + nmtst_main_loop_run (gl.loop, 100); connections = nm_client_get_connections (client); g_assert (connections); @@ -1563,7 +1271,7 @@ test_connection_invalid (void) connection, FALSE); - nmtst_main_loop_run (loop, 100); + nmtst_main_loop_run (gl.loop, 100); connections = nm_client_get_connections (client); g_assert (connections); @@ -1602,17 +1310,15 @@ main (int argc, char **argv) nmtst_init (&argc, &argv, TRUE); - loop = g_main_loop_new (NULL, FALSE); + gl.loop = g_main_loop_new (NULL, FALSE); g_test_add_func ("/libnm/device-added", test_device_added); g_test_add_func ("/libnm/device-added-signal-after-init", test_device_added_signal_after_init); g_test_add_func ("/libnm/wifi-ap-added-removed", test_wifi_ap_added_removed); - g_test_add_func ("/libnm/wimax-nsp-added-removed", test_wimax_nsp_added_removed); g_test_add_func ("/libnm/devices-array", test_devices_array); g_test_add_func ("/libnm/client-nm-running", test_client_nm_running); g_test_add_func ("/libnm/active-connections", test_active_connections); g_test_add_func ("/libnm/activate-virtual", test_activate_virtual); - g_test_add_func ("/libnm/activate-failed", test_activate_failed); g_test_add_func ("/libnm/device-connection-compatibility", test_device_connection_compatibility); g_test_add_func ("/libnm/connection/invalid", test_connection_invalid); diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c index 45bf97c8..8483eca8 100644 --- a/libnm/tests/test-remote-settings-client.c +++ b/libnm/tests/test-remote-settings-client.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0+ /* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2010 - 2011 Red Hat, Inc. - * + * Copyright (C) 2010 - 2011 Red Hat, Inc. */ #include "nm-default.h" @@ -22,12 +8,16 @@ #include <sys/types.h> #include <signal.h> +#include "nm-glib-aux/nm-time-utils.h" + #include "nm-test-libnm-utils.h" -static NMTstcServiceInfo *sinfo; -static NMClient *client = NULL; -GDBusConnection *bus = NULL; -NMRemoteConnection *remote = NULL; +static struct { + NMTstcServiceInfo *sinfo; + NMClient *client; + GDBusConnection *bus; + NMRemoteConnection *remote; +} gl = { }; /*****************************************************************************/ @@ -39,17 +29,17 @@ add_cb (GObject *s, gboolean *done = user_data; GError *error = NULL; - remote = nm_client_add_connection_finish (client, result, &error); + gl.remote = nm_client_add_connection_finish (gl.client, result, &error); g_assert_no_error (error); *done = TRUE; - g_object_add_weak_pointer (G_OBJECT (remote), (void **) &remote); + g_object_add_weak_pointer (G_OBJECT (gl.remote), (void **) &gl.remote); /* nm_client_add_connection_finish() adds a ref to @remote, but we * want the weak pointer to be cleared as soon as @client drops its own ref. * So drop ours. */ - g_object_unref (remote); + g_object_unref (gl.remote); } #define TEST_CON_ID "blahblahblah" @@ -58,32 +48,27 @@ static void test_add_connection (void) { NMConnection *connection; - time_t start, now; gboolean done = FALSE; - if (!nmtstc_service_available (sinfo)) + if (!nmtstc_service_available (gl.sinfo)) return; connection = nmtst_create_minimal_connection (TEST_CON_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - nm_client_add_connection_async (client, + nm_client_add_connection_async (gl.client, connection, TRUE, NULL, add_cb, &done); - start = time (NULL); - do { - now = time (NULL); - g_main_context_iteration (NULL, FALSE); - } while ((done == FALSE) && (now - start < 5)); - g_assert (done == TRUE); - g_assert (remote != NULL); + nmtst_main_context_iterate_until (NULL, 5000, done); + + g_assert (gl.remote != NULL); /* Make sure the connection is the same as what we added */ g_assert (nm_connection_compare (connection, - NM_CONNECTION (remote), + NM_CONNECTION (gl.remote), NM_SETTING_COMPARE_FLAG_EXACT) == TRUE); g_object_unref (connection); } @@ -113,7 +98,7 @@ visible_changed_cb (GObject *object, GParamSpec *pspec, gboolean *done) static void connection_removed_cb (NMClient *s, NMRemoteConnection *connection, gboolean *done) { - if (connection == remote) + if (connection == gl.remote) *done = TRUE; } @@ -130,7 +115,6 @@ invis_has_settings_cb (NMSetting *setting, static void test_make_invisible (void) { - time_t start, now; const GPtrArray *conns; int i; GDBusProxy *proxy; @@ -138,17 +122,17 @@ test_make_invisible (void) gboolean has_settings = FALSE; char *path; - if (!nmtstc_service_available (sinfo)) + if (!nmtstc_service_available (gl.sinfo)) return; - g_assert (remote != NULL); + g_assert (gl.remote != NULL); /* Listen for the remove event when the connection becomes invisible */ - g_signal_connect (remote, "notify::" NM_REMOTE_CONNECTION_VISIBLE, G_CALLBACK (visible_changed_cb), &visible_changed); - g_signal_connect (client, "connection-removed", G_CALLBACK (connection_removed_cb), &connection_removed); + g_signal_connect (gl.remote, "notify::" NM_REMOTE_CONNECTION_VISIBLE, G_CALLBACK (visible_changed_cb), &visible_changed); + g_signal_connect (gl.client, "connection-removed", G_CALLBACK (connection_removed_cb), &connection_removed); - path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote))); - proxy = g_dbus_proxy_new_sync (bus, + path = g_strdup (nm_connection_get_path (NM_CONNECTION (gl.remote))); + proxy = g_dbus_proxy_new_sync (gl.bus, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, NM_DBUS_SERVICE, @@ -167,29 +151,23 @@ test_make_invisible (void) set_visible_cb, NULL); /* Wait for the connection to be removed */ - start = time (NULL); - do { - now = time (NULL); - g_main_context_iteration (NULL, FALSE); - } while ((!visible_changed || !connection_removed) && (now - start < 5)); - g_assert (visible_changed == TRUE); - g_assert (connection_removed == TRUE); + nmtst_main_context_iterate_until (NULL, 5000, visible_changed && connection_removed); - g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (visible_changed_cb), &visible_changed); - g_signal_handlers_disconnect_by_func (client, G_CALLBACK (connection_removed_cb), &connection_removed); + g_signal_handlers_disconnect_by_func (gl.remote, G_CALLBACK (visible_changed_cb), &visible_changed); + g_signal_handlers_disconnect_by_func (gl.client, G_CALLBACK (connection_removed_cb), &connection_removed); /* Ensure NMClient no longer has the connection */ - conns = nm_client_get_connections (client); + conns = nm_client_get_connections (gl.client); for (i = 0; i < conns->len; i++) { NMConnection *candidate = NM_CONNECTION (conns->pdata[i]); - g_assert ((gpointer) remote != (gpointer) candidate); + g_assert ((gpointer) gl.remote != (gpointer) candidate); g_assert (strcmp (path, nm_connection_get_path (candidate)) != 0); } /* And ensure the invisible connection no longer has any settings */ - g_assert (remote); - nm_connection_for_each_setting_value (NM_CONNECTION (remote), + g_assert (gl.remote); + nm_connection_for_each_setting_value (NM_CONNECTION (gl.remote), invis_has_settings_cb, &has_settings); g_assert (has_settings == FALSE); @@ -211,7 +189,6 @@ vis_new_connection_cb (NMClient *foo, static void test_make_visible (void) { - time_t start, now; const GPtrArray *conns; int i; GDBusProxy *proxy; @@ -219,17 +196,17 @@ test_make_visible (void) char *path; NMRemoteConnection *new = NULL; - if (!nmtstc_service_available (sinfo)) + if (!nmtstc_service_available (gl.sinfo)) return; - g_assert (remote != NULL); + g_assert (gl.remote != NULL); /* Wait for the new-connection signal when the connection is visible again */ - g_signal_connect (client, NM_CLIENT_CONNECTION_ADDED, + g_signal_connect (gl.client, NM_CLIENT_CONNECTION_ADDED, G_CALLBACK (vis_new_connection_cb), &new); - path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote))); - proxy = g_dbus_proxy_new_sync (bus, + path = g_strdup (nm_connection_get_path (NM_CONNECTION (gl.remote))); + proxy = g_dbus_proxy_new_sync (gl.bus, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, NM_DBUS_SERVICE, @@ -248,24 +225,19 @@ test_make_visible (void) set_visible_cb, NULL); /* Wait for the settings service to announce the connection again */ - start = time (NULL); - do { - now = time (NULL); - g_main_context_iteration (NULL, FALSE); - } while ((new == NULL) && (now - start < 5)); + nmtst_main_context_iterate_until (NULL, 5000, new); /* Ensure the new connection is the same as the one we made visible again */ - g_assert (new); - g_assert (new == remote); + g_assert (new == gl.remote); - g_signal_handlers_disconnect_by_func (client, G_CALLBACK (vis_new_connection_cb), &new); + g_signal_handlers_disconnect_by_func (gl.client, G_CALLBACK (vis_new_connection_cb), &new); /* Ensure NMClient has the connection */ - conns = nm_client_get_connections (client); + conns = nm_client_get_connections (gl.client); for (i = 0; i < conns->len; i++) { NMConnection *candidate = NM_CONNECTION (conns->pdata[i]); - if ((gpointer) remote == (gpointer) candidate) { + if ((gpointer) gl.remote == (gpointer) candidate) { g_assert_cmpstr (path, ==, nm_connection_get_path (candidate)); g_assert_cmpstr (TEST_CON_ID, ==, nm_connection_get_id (candidate)); found = TRUE; @@ -296,7 +268,7 @@ deleted_cb (GObject *proxy, static void removed_cb (NMClient *s, NMRemoteConnection *connection, gboolean *done) { - if (connection == remote) + if (connection == gl.remote) *done = TRUE; } @@ -304,27 +276,26 @@ static void test_remove_connection (void) { NMRemoteConnection *connection; - time_t start, now; const GPtrArray *conns; int i; GDBusProxy *proxy; gboolean done = FALSE; char *path; - if (!nmtstc_service_available (sinfo)) + if (!nmtstc_service_available (gl.sinfo)) return; /* Find a connection to delete */ - conns = nm_client_get_connections (client); + conns = nm_client_get_connections (gl.client); g_assert_cmpint (conns->len, >, 0); connection = NM_REMOTE_CONNECTION (conns->pdata[0]); g_assert (connection); - g_assert (remote == connection); + g_assert (gl.remote == connection); path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection))); - g_signal_connect (client, "connection-removed", G_CALLBACK (removed_cb), &done); + g_signal_connect (gl.client, "connection-removed", G_CALLBACK (removed_cb), &done); - proxy = g_dbus_proxy_new_sync (bus, + proxy = g_dbus_proxy_new_sync (gl.bus, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, NM_DBUS_SERVICE, @@ -342,18 +313,10 @@ test_remove_connection (void) NULL, deleted_cb, NULL); - start = time (NULL); - do { - now = time (NULL); - g_main_context_iteration (NULL, FALSE); - if (done && !remote) - break; - } while (now - start < 5); - g_assert (done == TRUE); - g_assert (!remote); + nmtst_main_context_iterate_until (NULL, 5000, done && !gl.remote); /* Ensure NMClient no longer has the connection */ - conns = nm_client_get_connections (client); + conns = nm_client_get_connections (gl.client); for (i = 0; i < conns->len; i++) { NMConnection *candidate = NM_CONNECTION (conns->pdata[i]); @@ -378,7 +341,7 @@ add_remove_cb (GObject *s, gboolean *done = user_data; gs_free_error GError *error = NULL; - connection = nm_client_add_connection_finish (client, result, &error); + connection = nm_client_add_connection_finish (gl.client, result, &error); g_assert_error (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_OBJECT_CREATION_FAILED); g_assert (connection == NULL); @@ -388,43 +351,34 @@ add_remove_cb (GObject *s, static void test_add_remove_connection (void) { - GVariant *ret; + gs_unref_variant GVariant *ret = NULL; GError *error = NULL; - NMConnection *connection; - time_t start, now; + gs_unref_object NMConnection *connection = NULL; gboolean done = FALSE; - if (!nmtstc_service_available (sinfo)) + if (!nmtstc_service_available (gl.sinfo)) return; /* This will cause the test server to immediately delete the connection * after creating it. */ - ret = g_dbus_proxy_call_sync (sinfo->proxy, + ret = g_dbus_proxy_call_sync (gl.sinfo->proxy, "AutoRemoveNextConnection", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - g_assert_no_error (error); - g_variant_unref (ret); + nmtst_assert_success (ret, error); connection = nmtst_create_minimal_connection (TEST_ADD_REMOVE_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); - nm_client_add_connection_async (client, + nm_client_add_connection_async (gl.client, connection, TRUE, NULL, add_remove_cb, &done); - start = time (NULL); - do { - now = time (NULL); - g_main_context_iteration (NULL, FALSE); - } while ((done == FALSE) && (now - start < 5)); - g_assert (done == TRUE); - - g_object_unref (connection); + nmtst_main_context_iterate_until (NULL, 5000, done); } /*****************************************************************************/ @@ -437,7 +391,7 @@ add_bad_cb (GObject *s, gboolean *done = user_data; gs_free_error GError *error = NULL; - remote = nm_client_add_connection_finish (client, result, &error); + gl.remote = nm_client_add_connection_finish (gl.client, result, &error); g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY); *done = TRUE; @@ -446,31 +400,25 @@ add_bad_cb (GObject *s, static void test_add_bad_connection (void) { - NMConnection *connection; - time_t start, now; + gs_unref_object NMConnection *connection = NULL; gboolean done = FALSE; - if (!nmtstc_service_available (sinfo)) + if (!nmtstc_service_available (gl.sinfo)) return; /* The test daemon doesn't support bond connections */ connection = nmtst_create_minimal_connection ("bad connection test", NULL, NM_SETTING_BOND_SETTING_NAME, NULL); - nm_client_add_connection_async (client, + nm_client_add_connection_async (gl.client, connection, TRUE, NULL, add_bad_cb, &done); - g_object_unref (connection); + g_clear_object (&connection); - start = time (NULL); - do { - now = time (NULL); - g_main_context_iteration (NULL, FALSE); - } while ((done == FALSE) && (now - start < 5)); - g_assert (done == TRUE); - g_assert (remote == NULL); + nmtst_main_context_iterate_until (NULL, 5000, done); + g_assert (gl.remote == NULL); } /*****************************************************************************/ @@ -483,7 +431,7 @@ save_hostname_cb (GObject *s, gboolean *done = user_data; gs_free_error GError *error = NULL; - nm_client_save_hostname_finish (client, result, &error); + nm_client_save_hostname_finish (gl.client, result, &error); g_assert_no_error (error); *done = TRUE; @@ -492,27 +440,30 @@ save_hostname_cb (GObject *s, static void test_save_hostname (void) { - time_t start, now; + gint64 until_ts; gboolean done = FALSE; GError *error = NULL; - if (!nmtstc_service_available (sinfo)) + if (!nmtstc_service_available (gl.sinfo)) return; /* test-networkmanager-service.py requires the hostname to contain a '.' */ - nm_client_save_hostname (client, "foo", NULL, &error); + nm_client_save_hostname (gl.client, "foo", NULL, &error); g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_HOSTNAME); g_clear_error (&error); - nm_client_save_hostname_async (client, "example.com", NULL, save_hostname_cb, &done); + nm_client_save_hostname_async (gl.client, "example.com", NULL, save_hostname_cb, &done); - start = time (NULL); - do { - now = time (NULL); + until_ts = nm_utils_get_monotonic_timestamp_ms () + 5000; + while (TRUE) { g_main_context_iteration (NULL, FALSE); - } while ((done == FALSE) && (now - start < 5)); - g_assert (done == TRUE); - g_assert (remote == NULL); + if (done) + break; + if (nm_utils_get_monotonic_timestamp_ms () >= until_ts) + g_assert_not_reached (); + } + + g_assert (gl.remote == NULL); } /*****************************************************************************/ @@ -529,14 +480,12 @@ main (int argc, char **argv) nmtst_init (&argc, &argv, TRUE); - bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); - g_assert_no_error (error); + gl.bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); + nmtst_assert_success (gl.bus, error); - sinfo = nmtstc_service_init (); + gl.sinfo = nmtstc_service_init (); - client = nm_client_new (NULL, &error); - g_assert_no_error (error); - g_assert (client != NULL); + gl.client = nmtstc_client_new (TRUE); /* FIXME: these tests assume that they get run in order, but g_test_run() * does not actually guarantee that! @@ -551,9 +500,9 @@ main (int argc, char **argv) ret = g_test_run (); - nmtstc_service_cleanup (sinfo); - g_object_unref (client); - g_object_unref (bus); + nm_clear_pointer (&gl.sinfo, nmtstc_service_cleanup); + g_clear_object (&gl.client); + g_clear_object (&gl.bus); return ret; } diff --git a/libnm/tests/test-secret-agent.c b/libnm/tests/test-secret-agent.c index cc060440..fef6071d 100644 --- a/libnm/tests/test-secret-agent.c +++ b/libnm/tests/test-secret-agent.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0+ /* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2010 - 2014 Red Hat, Inc. - * + * Copyright (C) 2010 - 2014 Red Hat, Inc. */ #include "nm-default.h" @@ -248,8 +234,9 @@ test_setup (TestSecretAgentData *sadata, gconstpointer test_data) if (!sadata->sinfo) return; - sadata->client = nm_client_new (NULL, &error); - g_assert_no_error (error); + g_assert (g_main_context_get_thread_default () == NULL); + + sadata->client = nmtstc_client_new (TRUE); sadata->loop = g_main_loop_new (NULL, FALSE); sadata->timeout_id = g_timeout_add_seconds (5, timeout_assert, NULL); |