Commit 4d37f7a1 authored by Thomas Haller's avatar Thomas Haller
Browse files

core: refactor private data in "src"

- use _NM_GET_PRIVATE() and _NM_GET_PRIVATE_PTR() everywhere.

- reorder statements, to have GObject related functions (init, dispose,
  constructed) at the bottom of each file and in a consistent order w.r.t.
  each other.

- unify whitespaces in signal and properties declarations.

- use NM_GOBJECT_PROPERTIES_DEFINE() and _notify()

- drop unused signal slots in class structures

- drop unused header files for device factories
parent 92e9822e
......@@ -24,26 +24,48 @@
#include <gudev/gudev.h>
#include <gmodule.h>
#include "nm-atm-manager.h"
#include "nm-setting-adsl.h"
#include "nm-device-adsl.h"
#include "nm-device-factory.h"
#include "nm-platform.h"
/*****************************************************************************/
#define NM_TYPE_ATM_MANAGER (nm_atm_manager_get_type ())
#define NM_ATM_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ATM_MANAGER, NMAtmManager))
#define NM_ATM_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_ATM_MANAGER, NMAtmManagerClass))
#define NM_IS_ATM_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_ATM_MANAGER))
#define NM_IS_ATM_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_ATM_MANAGER))
#define NM_ATM_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ATM_MANAGER, NMAtmManagerClass))
typedef struct _NMAtmManager NMAtmManager;
typedef struct _NMAtmManagerClass NMAtmManagerClass;
static GType nm_atm_manager_get_type (void);
/*****************************************************************************/
typedef struct {
GUdevClient *client;
GSList *devices;
} NMAtmManagerPrivate;
#define NM_ATM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ATM_MANAGER, NMAtmManagerPrivate))
struct _NMAtmManager {
GObject parent;
NMAtmManagerPrivate _priv;
};
static GType nm_atm_manager_get_type (void);
struct _NMAtmManagerClass {
GObjectClass parent;
};
static void device_factory_interface_init (NMDeviceFactoryInterface *factory_iface);
G_DEFINE_TYPE_EXTENDED (NMAtmManager, nm_atm_manager, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_FACTORY, device_factory_interface_init))
#define NM_ATM_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMAtmManager, NM_IS_ATM_MANAGER)
/*****************************************************************************/
G_MODULE_EXPORT NMDeviceFactory *
......@@ -225,23 +247,6 @@ NM_DEVICE_FACTORY_DECLARE_TYPES (
/*****************************************************************************/
static void
nm_atm_manager_init (NMAtmManager *self)
{
NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self);
const char *subsys[] = { "atm", NULL };
priv->client = g_udev_client_new (subsys);
g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self);
}
static void
device_factory_interface_init (NMDeviceFactoryInterface *factory_iface)
{
factory_iface->get_supported_types = get_supported_types;
factory_iface->start = start;
}
static void
dispose (GObject *object)
{
......@@ -249,9 +254,10 @@ dispose (GObject *object)
NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self);
GSList *iter;
if (priv->client)
if (priv->client) {
g_signal_handlers_disconnect_by_func (priv->client, handle_uevent, self);
g_clear_object (&priv->client);
g_clear_object (&priv->client);
}
for (iter = priv->devices; iter; iter = iter->next)
g_object_weak_unref (G_OBJECT (iter->data), device_destroyed, self);
......@@ -265,8 +271,24 @@ nm_atm_manager_class_init (NMAtmManagerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (NMAtmManagerPrivate));
/* virtual methods */
object_class->dispose = dispose;
}
/*****************************************************************************/
static void
nm_atm_manager_init (NMAtmManager *self)
{
NMAtmManagerPrivate *priv = NM_ATM_MANAGER_GET_PRIVATE (self);
const char *subsys[] = { "atm", NULL };
priv->client = g_udev_client_new (subsys);
g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self);
}
static void
device_factory_interface_init (NMDeviceFactoryInterface *factory_iface)
{
factory_iface->get_supported_types = get_supported_types;
factory_iface->start = start;
}
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* 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 (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2014 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_ATM_MANAGER_H__
#define __NETWORKMANAGER_ATM_MANAGER_H__
#define NM_TYPE_ATM_MANAGER (nm_atm_manager_get_type ())
#define NM_ATM_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ATM_MANAGER, NMAtmManager))
typedef struct {
GObject parent;
} NMAtmManager;
typedef struct {
GObjectClass parent;
} NMAtmManagerClass;
#endif /* __NETWORKMANAGER_ATM_MANAGER_H__ */
......@@ -20,24 +20,23 @@
#include "nm-default.h"
#include "nm-device-adsl.h"
#include <sys/socket.h>
#include <linux/atmdev.h>
#include <linux/atmbr2684.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "nm-device-adsl.h"
#include "nm-device-private.h"
#include "nm-enum-types.h"
#include "nm-platform.h"
#include "ppp-manager/nm-ppp-manager.h"
#include "ppp-manager/nm-ppp-status.h"
#include "nm-setting-adsl.h"
#include "nm-utils.h"
......@@ -46,18 +45,11 @@
#include "nm-device-logging.h"
_LOG_DECLARE_SELF (NMDeviceAdsl);
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))
/*****************************************************************************/
enum {
PROP_0,
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_ATM_INDEX,
LAST_PROP
};
/*****************************************************************************/
);
typedef struct {
guint carrier_poll_id;
......@@ -74,6 +66,19 @@ typedef struct {
guint nas_update_count;
} NMDeviceAdslPrivate;
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)
/*****************************************************************************/
static NMDeviceCapabilities
......@@ -547,57 +552,13 @@ carrier_update_cb (gpointer user_data)
/*****************************************************************************/
NMDevice *
nm_device_adsl_new (const char *udi,
const char *iface,
const char *driver,
int atm_index)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (atm_index >= 0, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_ADSL,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_ADSL_ATM_INDEX, atm_index,
NM_DEVICE_TYPE_DESC, "ADSL",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ADSL,
NULL);
}
static void
constructed (GObject *object)
{
NMDeviceAdsl *self = NM_DEVICE_ADSL (object);
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self);
G_OBJECT_CLASS (nm_device_adsl_parent_class)->constructed (object);
priv->carrier_poll_id = g_timeout_add_seconds (5, carrier_update_cb, self);
_LOGD (LOGD_ADSL, "ATM device index %d", priv->atm_index);
g_return_if_fail (priv->atm_index >= 0);
}
static void
dispose (GObject *object)
{
adsl_cleanup (NM_DEVICE_ADSL (object));
nm_clear_g_source (&NM_DEVICE_ADSL_GET_PRIVATE (object)->carrier_poll_id);
G_OBJECT_CLASS (nm_device_adsl_parent_class)->dispose (object);
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
switch (prop_id) {
case PROP_ATM_INDEX:
g_value_set_int (value, NM_DEVICE_ADSL_GET_PRIVATE (object)->atm_index);
g_value_set_int (value, NM_DEVICE_ADSL_GET_PRIVATE ((NMDeviceAdsl *) object)->atm_index);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -612,7 +573,7 @@ set_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_ATM_INDEX:
/* construct only */
NM_DEVICE_ADSL_GET_PRIVATE (object)->atm_index = g_value_get_int (value);
NM_DEVICE_ADSL_GET_PRIVATE ((NMDeviceAdsl *) object)->atm_index = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -620,19 +581,63 @@ set_property (GObject *object, guint prop_id,
}
}
/*****************************************************************************/
static void
nm_device_adsl_init (NMDeviceAdsl *self)
{
}
static void
constructed (GObject *object)
{
NMDeviceAdsl *self = NM_DEVICE_ADSL (object);
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self);
G_OBJECT_CLASS (nm_device_adsl_parent_class)->constructed (object);
priv->carrier_poll_id = g_timeout_add_seconds (5, carrier_update_cb, self);
_LOGD (LOGD_ADSL, "ATM device index %d", priv->atm_index);
g_return_if_fail (priv->atm_index >= 0);
}
NMDevice *
nm_device_adsl_new (const char *udi,
const char *iface,
const char *driver,
int atm_index)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (atm_index >= 0, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_ADSL,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_ADSL_ATM_INDEX, atm_index,
NM_DEVICE_TYPE_DESC, "ADSL",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ADSL,
NULL);
}
static void
dispose (GObject *object)
{
adsl_cleanup (NM_DEVICE_ADSL (object));
nm_clear_g_source (&NM_DEVICE_ADSL_GET_PRIVATE ((NMDeviceAdsl *) object)->carrier_poll_id);
G_OBJECT_CLASS (nm_device_adsl_parent_class)->dispose (object);
}
static void
nm_device_adsl_class_init (NMDeviceAdslClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMDeviceClass *parent_class = NM_DEVICE_CLASS (klass);
g_type_class_add_private (object_class, sizeof (NMDeviceAdslPrivate));
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->get_property = get_property;
......@@ -647,13 +652,13 @@ nm_device_adsl_class_init (NMDeviceAdslClass *klass)
parent_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
parent_class->deactivate = deactivate;
/* properties */
g_object_class_install_property
(object_class, PROP_ATM_INDEX,
g_param_spec_int (NM_DEVICE_ADSL_ATM_INDEX, "", "",
-1, G_MAXINT, -1,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
obj_properties[PROP_ATM_INDEX] =
g_param_spec_int (NM_DEVICE_ADSL_ATM_INDEX, "", "",
-1, G_MAXINT, -1,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
NMDBUS_TYPE_DEVICE_ADSL_SKELETON,
......
......@@ -22,7 +22,6 @@
#ifndef __NETWORKMANAGER_DEVICE_ADSL_H__
#define __NETWORKMANAGER_DEVICE_ADSL_H__
// Parent class
#include "nm-device.h"
#define NM_TYPE_DEVICE_ADSL (nm_device_adsl_get_type ())
......@@ -34,13 +33,8 @@
#define NM_DEVICE_ADSL_ATM_INDEX "atm-index"
typedef struct {
NMDevice parent;
} NMDeviceAdsl;
typedef struct {
NMDeviceClass parent;
} NMDeviceAdslClass;
typedef struct _NMDeviceAdsl NMDeviceAdsl;
typedef struct _NMDeviceAdslClass NMDeviceAdslClass;
GType nm_device_adsl_get_type (void);
......
......@@ -33,7 +33,6 @@ SYMBOL_VIS_FILE=$(srcdir)/exports.ver
libnm_device_plugin_bluetooth_la_SOURCES = \
nm-bluez-manager.c \
nm-bluez-manager.h \
nm-bluez-common.h \
nm-bluez-device.c \
nm-bluez-device.h \
......
......@@ -39,5 +39,6 @@
#define BLUEZ4_SERIAL_INTERFACE "org.bluez.Serial"
#define BLUEZ4_NETWORK_INTERFACE "org.bluez.Network"
#endif /* NM_BLUEZ_COMMON_H */
#define NM_BLUEZ_MANAGER_BDADDR_ADDED "bdaddr-added"
#endif /* NM_BLUEZ_COMMON_H */
......@@ -21,13 +21,13 @@
#include "nm-default.h"
#include "nm-bluez-device.h"
#include <string.h>
#include "nm-core-internal.h"
#include "nm-bt-error.h"
#include "nm-bluez-common.h"
#include "nm-bluez-device.h"
#include "nm-settings.h"
#include "nm-settings-connection.h"
#include "NetworkManagerUtils.h"
......@@ -36,9 +36,31 @@
#include "nm-bluez5-dun.h"
#endif
G_DEFINE_TYPE (NMBluezDevice, nm_bluez_device, G_TYPE_OBJECT)
/*****************************************************************************/
#define VARIANT_IS_OF_TYPE_BOOLEAN(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_BOOLEAN) ))
#define VARIANT_IS_OF_TYPE_STRING(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_STRING) ))
#define VARIANT_IS_OF_TYPE_OBJECT_PATH(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_OBJECT_PATH) ))
#define VARIANT_IS_OF_TYPE_STRING_ARRAY(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_STRING_ARRAY) ))
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE (NMBluezDevice,
PROP_PATH,
PROP_ADDRESS,
PROP_NAME,
PROP_CAPABILITIES,
PROP_USABLE,
PROP_CONNECTED,
);
enum {
INITIALIZED,
REMOVED,
LAST_SIGNAL
};
#define NM_BLUEZ_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_BLUEZ_DEVICE, NMBluezDevicePrivate))
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct {
char *path;
......@@ -75,38 +97,25 @@ typedef struct {
gboolean pan_connection_no_autocreate;
} NMBluezDevicePrivate;
enum {
PROP_0,
PROP_PATH,
PROP_ADDRESS,
PROP_NAME,
PROP_CAPABILITIES,
PROP_USABLE,
PROP_CONNECTED,
LAST_PROP
struct _NMBluezDevice {
GObject parent;
NMBluezDevicePrivate _priv;
};
/* Signals */
enum {
INITIALIZED,
REMOVED,
LAST_SIGNAL
struct _NMBluezDeviceClass {
GObjectClass parent;
};
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (NMBluezDevice, nm_bluez_device, G_TYPE_OBJECT)
#define NM_BLUEZ_DEVICE_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMBluezDevice, NM_IS_BLUEZ_DEVICE)
/*****************************************************************************/
static void cp_connection_added (NMSettings *settings,
NMConnection *connection, NMBluezDevice *self);
static gboolean connection_compatible (NMBluezDevice *self, NMConnection *connection);
#define VARIANT_IS_OF_TYPE_BOOLEAN(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_BOOLEAN) ))
#define VARIANT_IS_OF_TYPE_STRING(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_STRING) ))
#define VARIANT_IS_OF_TYPE_OBJECT_PATH(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_OBJECT_PATH) ))
#define VARIANT_IS_OF_TYPE_STRING_ARRAY(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_STRING_ARRAY) ))
/*****************************************************************************/
const char *
......@@ -292,7 +301,7 @@ check_emit_usable (NMBluezDevice *self)
END:
if (new_usable != priv->usable) {
priv->usable = new_usable;
g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_USABLE);
_notify (self, PROP_USABLE);
}
return G_SOURCE_REMOVE;
......@@ -424,7 +433,7 @@ bluez_disconnect_cb (GDBusConnection *dbus_connection,
GAsyncResult *res,
gpointer user_data)
{
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (user_data);
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE ((NMBluezDevice *) user_data);
GError *error = NULL;
GVariant *variant;
......@@ -628,7 +637,7 @@ nm_bluez_device_connect_finish (NMBluezDevice *self,
device = (const char *) g_simple_async_result_get_op_res_gpointer (simple);
if (device && priv->bluez_version == 5) {
priv->connected = TRUE;
g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_CONNECTED);
_notify (self, PROP_CONNECTED);
}
return device;
......@@ -695,7 +704,7 @@ _set_property_capabilities (NMBluezDevice *self, const char **uuids)
((uint_val & NM_BT_CAPABILITY_DUN) && (uint_val &NM_BT_CAPABILITY_NAP)) ? " | " : "",
uint_val & NM_BT_CAPABILITY_DUN ? "DUN" : "");
priv->capabilities = uint_val;
g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_CAPABILITIES);
_notify (self, PROP_CAPABILITIES);
}
}
......@@ -727,7 +736,7 @@ _set_property_address (NMBluezDevice *self, const char *addr)
}
priv->address = g_strdup (addr);
g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_ADDRESS);
_notify (self, PROP_ADDRESS);
}
static void
......@@ -749,7 +758,7 @@ _take_variant_property_name (NMBluezDevice *self, GVariant *v)
if (g_strcmp0 (priv->name, str)) {
g_free (priv->name);
priv->name = g_strdup (str);
g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_NAME);
_notify (self, PROP_NAME);
}
}
if (v)
......@@ -779,7 +788,7 @@ _take_variant_property_connected (NMBluezDevice *self, GVariant *v)
if (priv->connected != connected) {
priv->connected = connected;
g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_CONNECTED);
_notify (self, PROP_CONNECTED);
}
}
if (v)
......@@ -1029,6 +1038,61 @@ on_bus_acquired (GObject *object, GAsyncResult *res, NMBluezDevice *self)
/*****************************************************************************/
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE ((NMBluezDevice *) object);
switch (prop_id) {
case PROP_PATH:
g_value_set_string (value, priv->path);
break;
case PROP_ADDRESS:
g_value_set_string (value, priv->address);
break;
case PROP_NAME:
g_value_set_string (value, priv->name);
break;