Commit c6c41eb1 authored by Thomas Haller's avatar Thomas Haller

libnm: various cleanup of NMP2PPeer and NMDeviceP2PWifi

- fix leaking hw_address in finalize().

- reorder code.

- avoid double tabs in GObject property definitions.

- hide struct definitions from header.

- don't use signal slots in class structure.

- use NM_GOBJECT_PROPERTIES_DEFINE_BASE().

- add missing NM_AVAILABLE_IN_1_16 annotations.
parent 41b2d8c6
......@@ -14,8 +14,7 @@
* 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 2018 - 2019 Red Hat, Inc.
*/
#include "nm-default.h"
......@@ -35,45 +34,63 @@
#include "introspection/org.freedesktop.NetworkManager.Device.P2PWireless.h"
G_DEFINE_TYPE (NMDeviceP2PWifi, nm_device_p2p_wifi, NM_TYPE_DEVICE)
#define NM_DEVICE_P2P_WIFI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_P2P_WIFI, NMDeviceP2PWifiPrivate))
void _nm_device_p2p_wifi_set_p2p_wireless_enabled (NMDeviceP2PWifi *device, gboolean enabled);
static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data);
/*****************************************************************************/
typedef struct {
NMDeviceP2PWifi *device;
GSimpleAsyncResult *simple;
} RequestScanInfo;
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_HW_ADDRESS,
PROP_GROUP_OWNER,
PROP_WFDIES,
PROP_PEERS,
);
enum {
PEER_ADDED,
PEER_REMOVED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct {
NMDBusDeviceP2PWifi *proxy;
char *hw_address;
gboolean group_owner;
GByteArray *wfd_ies;
GPtrArray *peers;
gboolean group_owner;
} NMDeviceP2PWifiPrivate;
enum {
PROP_0,
PROP_HW_ADDRESS,
PROP_GROUP_OWNER,
PROP_WFDIES,
PROP_PEERS,
/**
* NMDeviceP2PWifi:
*
* Since: 1.16
*/
struct _NMDeviceP2PWifi {
NMDevice parent;
NMDeviceP2PWifiPrivate _priv;
};
LAST_PROP
struct _NMDeviceP2PWifiClass {
NMDeviceClass parent;
};
enum {
PEER_ADDED,
PEER_REMOVED,
G_DEFINE_TYPE (NMDeviceP2PWifi, nm_device_p2p_wifi, NM_TYPE_DEVICE)
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
#define NM_DEVICE_P2P_WIFI_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDeviceP2PWifi, NM_IS_DEVICE_P2P_WIFI, NMDevice, NMObject)
/*****************************************************************************/
static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data);
/*****************************************************************************/
/**
* nm_device_p2p_wifi_get_hw_address:
......@@ -406,20 +423,15 @@ nm_device_p2p_wifi_class_init (NMDeviceP2PWifiClass *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 (NMDeviceP2PWifiPrivate));
/* virtual methods */
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
object_class->dispose = dispose;
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;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
/* properties */
nm_object_class->init_dbus = init_dbus;
/**
* NMDeviceP2PWifi:hw-address:
......@@ -428,12 +440,11 @@ nm_device_p2p_wifi_class_init (NMDeviceP2PWifiClass *wifi_class)
*
* Since: 1.16
**/
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,
g_param_spec_string (NM_DEVICE_P2P_WIFI_HW_ADDRESS, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
obj_properties[PROP_HW_ADDRESS] =
g_param_spec_string (NM_DEVICE_P2P_WIFI_HW_ADDRESS, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
/**
......@@ -443,12 +454,11 @@ nm_device_p2p_wifi_class_init (NMDeviceP2PWifiClass *wifi_class)
*
* Since: 1.16
**/
g_object_class_install_property
(object_class, PROP_GROUP_OWNER,
g_param_spec_boolean (NM_DEVICE_P2P_WIFI_GROUP_OWNER, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
obj_properties[PROP_GROUP_OWNER] =
g_param_spec_boolean (NM_DEVICE_P2P_WIFI_GROUP_OWNER, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
/**
* NMDeviceP2PWifi:wfd-ies:
......@@ -457,13 +467,12 @@ nm_device_p2p_wifi_class_init (NMDeviceP2PWifiClass *wifi_class)
*
* Since: 1.16
**/
g_object_class_install_property
(object_class, PROP_WFDIES,
g_param_spec_variant (NM_DEVICE_P2P_WIFI_WFDIES, "", "",
G_VARIANT_TYPE ("ay"),
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
obj_properties[PROP_WFDIES] =
g_param_spec_variant (NM_DEVICE_P2P_WIFI_WFDIES, "", "",
G_VARIANT_TYPE ("ay"),
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
/**
* NMDeviceP2PWifi:peers: (type GPtrArray(NMP2PPeer))
......@@ -472,14 +481,13 @@ nm_device_p2p_wifi_class_init (NMDeviceP2PWifiClass *wifi_class)
*
* Since: 1.16
**/
g_object_class_install_property
(object_class, PROP_PEERS,
g_param_spec_boxed (NM_DEVICE_P2P_WIFI_PEERS, "", "",
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
obj_properties[PROP_PEERS] =
g_param_spec_boxed (NM_DEVICE_P2P_WIFI_PEERS, "", "",
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
/* signals */
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
/**
* NMDeviceP2PWifi::peer-added:
......@@ -491,14 +499,13 @@ nm_device_p2p_wifi_class_init (NMDeviceP2PWifiClass *wifi_class)
* Since: 1.16
**/
signals[PEER_ADDED] =
g_signal_new ("peer-added",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMDeviceP2PWifiClass, peer_added),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
g_signal_new ("peer-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);
/**
* NMDeviceP2PWifi::peer-removed:
......@@ -510,12 +517,11 @@ nm_device_p2p_wifi_class_init (NMDeviceP2PWifiClass *wifi_class)
* Since: 1.16
**/
signals[PEER_REMOVED] =
g_signal_new ("peer-removed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMDeviceP2PWifiClass, peer_removed),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
g_signal_new ("peer-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);
}
......@@ -14,8 +14,7 @@
* 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 2018 - 2019 Red Hat, Inc.
*/
#ifndef __NM_DEVICE_P2P_WIFI_H__
......@@ -41,41 +40,34 @@ G_BEGIN_DECLS
#define NM_DEVICE_P2P_WIFI_PEERS "peers"
#define NM_DEVICE_P2P_WIFI_WFDIES "wfdies"
/**
* NMDeviceP2PWifi:
*/
struct _NMDeviceP2PWifi {
NMDevice parent;
};
typedef struct {
NMDeviceClass parent;
/* Signals */
void (*peer_added) (NMDeviceP2PWifi *device, NMP2PPeer *peer);
void (*peer_removed) (NMDeviceP2PWifi *device, NMP2PPeer *peer);
/*< private >*/
gpointer padding[4];
} NMDeviceP2PWifiClass;
typedef struct _NMDeviceP2PWifiClass NMDeviceP2PWifiClass;
NM_AVAILABLE_IN_1_16
GType nm_device_p2p_wifi_get_type (void);
NM_AVAILABLE_IN_1_16
const char * nm_device_p2p_wifi_get_hw_address (NMDeviceP2PWifi *device);
NM_AVAILABLE_IN_1_16
gboolean nm_device_p2p_wifi_get_group_owner (NMDeviceP2PWifi *device);
#if 0
gboolean nm_device_p2p_wifi_get_wfdies (NMDeviceP2PWifi *device);
#endif
NM_AVAILABLE_IN_1_16
NMP2PPeer * nm_device_p2p_wifi_get_peer_by_path (NMDeviceP2PWifi *device,
const char *path);
NM_AVAILABLE_IN_1_16
const GPtrArray * nm_device_p2p_wifi_get_peers (NMDeviceP2PWifi *device);
NM_AVAILABLE_IN_1_16
gboolean nm_device_p2p_wifi_start_find (NMDeviceP2PWifi *device,
GCancellable *cancellable,
GError **error);
NM_AVAILABLE_IN_1_16
gboolean nm_device_p2p_wifi_stop_find (NMDeviceP2PWifi *device,
GCancellable *cancellable,
GError **error);
......
This diff is collapsed.
......@@ -14,8 +14,7 @@
* 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 2018 - 2019 Red Hat, Inc.
*/
#ifndef __NM_P2P_PEER_H__
......@@ -47,21 +46,7 @@ G_BEGIN_DECLS
#define NM_P2P_PEER_STRENGTH "strength"
#define NM_P2P_PEER_LAST_SEEN "last-seen"
/**
* NMP2PPeer:
*/
NM_AVAILABLE_IN_1_16
struct _NMP2PPeer {
NMObject parent;
};
NM_AVAILABLE_IN_1_16
typedef struct {
NMObjectClass parent;
/*< private >*/
gpointer padding[4];
} NMP2PPeerClass;
typedef struct _NMP2PPeerClass NMP2PPeerClass;
NM_AVAILABLE_IN_1_16
GType nm_p2p_peer_get_type (void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment