diff options
Diffstat (limited to 'libnm/nm-device-wifi-p2p.c')
| -rw-r--r-- | libnm/nm-device-wifi-p2p.c | 237 |
1 files changed, 89 insertions, 148 deletions
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: |