modem: fix modem type checking for various operations
After the DUN branch merge (I think?) a number of NM_IS_MODEM calls were left around which now always return FALSE since NMDeviceCdma and NMDeviceGsm aren't subclasses of NMModem anymore. But we still need generic "is this a modem subclass" checks in a few places, so add a modem base class that both the GSM and CDMA device classes inherit from and use that. Plus, we want to consolidate a ton of the common code in nm-device-gsm.c and nm-device-cdma.c into the base class in the future anyway.
This commit is contained in:
@@ -94,6 +94,8 @@ NetworkManager_SOURCES = \
|
||||
nm-device-olpc-mesh.h \
|
||||
nm-device-bt.c \
|
||||
nm-device-bt.h \
|
||||
nm-device-modem.h \
|
||||
nm-device-modem.c \
|
||||
nm-device-cdma.c \
|
||||
nm-device-cdma.h \
|
||||
nm-device-gsm.c \
|
||||
|
@@ -36,7 +36,7 @@
|
||||
|
||||
static void device_interface_init (NMDeviceInterface *iface_class);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (NMDeviceCdma, nm_device_cdma, NM_TYPE_DEVICE, 0,
|
||||
G_DEFINE_TYPE_EXTENDED (NMDeviceCdma, nm_device_cdma, NM_TYPE_DEVICE_MODEM, 0,
|
||||
G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_INTERFACE, device_interface_init))
|
||||
|
||||
#define NM_DEVICE_CDMA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_CDMA, NMDeviceCdmaPrivate))
|
||||
@@ -312,6 +312,14 @@ modem_enabled_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static NMModem *
|
||||
real_get_modem (NMDeviceModem *device)
|
||||
{
|
||||
return NM_DEVICE_CDMA_GET_PRIVATE (NM_DEVICE_CDMA (device))->modem;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMDevice *
|
||||
nm_device_cdma_new (NMModemCdma *modem, const char *driver)
|
||||
{
|
||||
@@ -371,6 +379,7 @@ nm_device_cdma_class_init (NMDeviceCdmaClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
|
||||
NMDeviceModemClass *modem_class = NM_DEVICE_MODEM_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (NMDeviceCdmaPrivate));
|
||||
|
||||
@@ -389,6 +398,8 @@ nm_device_cdma_class_init (NMDeviceCdmaClass *klass)
|
||||
device_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
|
||||
device_class->deactivate_quickly = real_deactivate_quickly;
|
||||
|
||||
modem_class->get_modem = real_get_modem;
|
||||
|
||||
/* Signals */
|
||||
signals[PPP_STATS] =
|
||||
g_signal_new ("ppp-stats",
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#ifndef NM_DEVICE_CDMA_H
|
||||
#define NM_DEVICE_CDMA_H
|
||||
|
||||
#include "nm-device.h"
|
||||
#include "nm-device-modem.h"
|
||||
#include "nm-modem-cdma.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
@@ -34,11 +34,11 @@ G_BEGIN_DECLS
|
||||
#define NM_DEVICE_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_CDMA, NMDeviceCdmaClass))
|
||||
|
||||
typedef struct {
|
||||
NMDevice parent;
|
||||
NMDeviceModem parent;
|
||||
} NMDeviceCdma;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceClass parent;
|
||||
NMDeviceModemClass parent;
|
||||
|
||||
/* Signals */
|
||||
void (*signal_quality) (NMDeviceCdma *self, guint32 quality);
|
||||
|
@@ -36,7 +36,7 @@
|
||||
|
||||
static void device_interface_init (NMDeviceInterface *iface_class);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (NMDeviceGsm, nm_device_gsm, NM_TYPE_DEVICE, 0,
|
||||
G_DEFINE_TYPE_EXTENDED (NMDeviceGsm, nm_device_gsm, NM_TYPE_DEVICE_MODEM, 0,
|
||||
G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_INTERFACE, device_interface_init))
|
||||
|
||||
#define NM_DEVICE_GSM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_GSM, NMDeviceGsmPrivate))
|
||||
@@ -312,6 +312,14 @@ modem_enabled_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static NMModem *
|
||||
real_get_modem (NMDeviceModem *device)
|
||||
{
|
||||
return NM_DEVICE_GSM_GET_PRIVATE (NM_DEVICE_GSM (device))->modem;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMDevice *
|
||||
nm_device_gsm_new (NMModemGsm *modem, const char *driver)
|
||||
{
|
||||
@@ -371,6 +379,7 @@ nm_device_gsm_class_init (NMDeviceGsmClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
|
||||
NMDeviceModemClass *modem_class = NM_DEVICE_MODEM_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (NMDeviceGsmPrivate));
|
||||
|
||||
@@ -389,6 +398,8 @@ nm_device_gsm_class_init (NMDeviceGsmClass *klass)
|
||||
device_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
|
||||
device_class->deactivate_quickly = real_deactivate_quickly;
|
||||
|
||||
modem_class->get_modem = real_get_modem;
|
||||
|
||||
/* Signals */
|
||||
signals[PPP_STATS] =
|
||||
g_signal_new ("ppp-stats",
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#ifndef NM_DEVICE_GSM_H
|
||||
#define NM_DEVICE_GSM_H
|
||||
|
||||
#include "nm-device.h"
|
||||
#include "nm-device-modem.h"
|
||||
#include "nm-modem-gsm.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
@@ -34,11 +34,11 @@ G_BEGIN_DECLS
|
||||
#define NM_DEVICE_GSM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_GSM, NMDeviceGsmClass))
|
||||
|
||||
typedef struct {
|
||||
NMDevice parent;
|
||||
NMDeviceModem parent;
|
||||
} NMDeviceGsm;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceClass parent;
|
||||
NMDeviceModemClass parent;
|
||||
|
||||
/* Signals */
|
||||
void (*signal_quality) (NMDeviceGsm *self, guint32 quality);
|
||||
|
@@ -379,6 +379,16 @@ nm_device_interface_set_enabled (NMDeviceInterface *device, gboolean enabled)
|
||||
g_return_if_fail (NM_IS_DEVICE_INTERFACE (device));
|
||||
|
||||
if (NM_DEVICE_INTERFACE_GET_INTERFACE (device)->set_enabled)
|
||||
return NM_DEVICE_INTERFACE_GET_INTERFACE (device)->set_enabled (device, enabled);
|
||||
NM_DEVICE_INTERFACE_GET_INTERFACE (device)->set_enabled (device, enabled);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_device_interface_get_enabled (NMDeviceInterface *device)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_DEVICE_INTERFACE (device), FALSE);
|
||||
|
||||
if (NM_DEVICE_INTERFACE_GET_INTERFACE (device)->get_enabled)
|
||||
return NM_DEVICE_INTERFACE_GET_INTERFACE (device)->get_enabled (device);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@@ -103,6 +103,8 @@ struct _NMDeviceInterface {
|
||||
|
||||
void (*set_enabled) (NMDeviceInterface *device, gboolean enabled);
|
||||
|
||||
gboolean (*get_enabled) (NMDeviceInterface *device);
|
||||
|
||||
/* Signals */
|
||||
void (*state_changed) (NMDeviceInterface *device,
|
||||
NMDeviceState new_state,
|
||||
@@ -137,6 +139,8 @@ NMConnection * nm_device_interface_connection_match_config (NMDeviceInterface *d
|
||||
|
||||
gboolean nm_device_interface_can_assume_connection (NMDeviceInterface *device);
|
||||
|
||||
gboolean nm_device_interface_get_enabled (NMDeviceInterface *device);
|
||||
|
||||
void nm_device_interface_set_enabled (NMDeviceInterface *device, gboolean enabled);
|
||||
|
||||
#endif /* NM_DEVICE_INTERFACE_H */
|
||||
|
64
src/nm-device-modem.c
Normal file
64
src/nm-device-modem.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* -*- 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) 2008 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "nm-device-modem.h"
|
||||
#include "nm-device-interface.h"
|
||||
#include "nm-modem.h"
|
||||
|
||||
static void device_interface_init (NMDeviceInterface *iface_class);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE, G_TYPE_FLAG_ABSTRACT,
|
||||
G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_INTERFACE, device_interface_init))
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
real_get_enabled (NMDeviceInterface *device)
|
||||
{
|
||||
NMDeviceModem *self = NM_DEVICE_MODEM (device);
|
||||
NMModem *modem;
|
||||
|
||||
g_assert (NM_DEVICE_MODEM_GET_CLASS (self)->get_modem);
|
||||
modem = NM_DEVICE_MODEM_GET_CLASS (self)->get_modem (self);
|
||||
|
||||
g_message ("%s: modem %p", __func__, modem);
|
||||
return modem ? nm_modem_get_mm_enabled (modem) : TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
device_interface_init (NMDeviceInterface *iface_class)
|
||||
{
|
||||
iface_class->get_enabled = real_get_enabled;
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_modem_init (NMDeviceModem *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_modem_class_init (NMDeviceModemClass *config_class)
|
||||
{
|
||||
}
|
||||
|
49
src/nm-device-modem.h
Normal file
49
src/nm-device-modem.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* -*- 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) 2010 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NM_DEVICE_MODEM_H
|
||||
#define NM_DEVICE_MODEM_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "nm-device.h"
|
||||
#include "nm-modem.h"
|
||||
|
||||
#define NM_TYPE_DEVICE_MODEM (nm_device_modem_get_type ())
|
||||
#define NM_DEVICE_MODEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_MODEM, NMDeviceModem))
|
||||
#define NM_DEVICE_MODEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_MODEM, NMDeviceModemClass))
|
||||
#define NM_IS_DEVICE_MODEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_MODEM))
|
||||
#define NM_IS_DEVICE_MODEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DEVICE_MODEM))
|
||||
#define NM_DEVICE_MODEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_MODEM, NMDeviceModemClass))
|
||||
|
||||
typedef struct {
|
||||
NMDevice parent;
|
||||
} NMDeviceModem;
|
||||
|
||||
typedef struct {
|
||||
NMDeviceClass parent;
|
||||
|
||||
NMModem * (*get_modem) (NMDeviceModem *modem);
|
||||
} NMDeviceModemClass;
|
||||
|
||||
GType nm_device_modem_get_type (void);
|
||||
|
||||
#endif /* NM_DEVICE_MODEM_H */
|
@@ -30,7 +30,6 @@
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-vpn-manager.h"
|
||||
#include "nm-modem-manager.h"
|
||||
#include "nm-modem.h"
|
||||
#include "nm-device-bt.h"
|
||||
#include "nm-device-interface.h"
|
||||
#include "nm-device-private.h"
|
||||
@@ -1345,9 +1344,11 @@ nm_manager_get_modem_enabled_state (NMManager *self)
|
||||
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
|
||||
NMDevice *candidate = NM_DEVICE (iter->data);
|
||||
RfKillState candidate_state = RFKILL_UNBLOCKED;
|
||||
RfKillType devtype = RFKILL_TYPE_UNKNOWN;
|
||||
|
||||
if (NM_IS_MODEM (candidate)) {
|
||||
if (nm_modem_get_mm_enabled (NM_MODEM (candidate)) == FALSE)
|
||||
g_object_get (G_OBJECT (candidate), NM_DEVICE_INTERFACE_RFKILL_TYPE, &devtype, NULL);
|
||||
if (devtype == RFKILL_TYPE_WWAN) {
|
||||
if (!nm_device_interface_get_enabled (NM_DEVICE_INTERFACE (candidate)))
|
||||
candidate_state = RFKILL_SOFT_BLOCKED;
|
||||
|
||||
if (candidate_state > wwan_state)
|
||||
@@ -1458,7 +1459,7 @@ add_device (NMManager *self, NMDevice *device)
|
||||
iface = nm_device_get_ip_iface (device);
|
||||
g_assert (iface);
|
||||
|
||||
if (!NM_IS_MODEM (device) && find_device_by_iface (self, iface)) {
|
||||
if (!NM_IS_DEVICE_MODEM (device) && find_device_by_iface (self, iface)) {
|
||||
g_object_unref (device);
|
||||
return;
|
||||
}
|
||||
@@ -1490,7 +1491,7 @@ add_device (NMManager *self, NMDevice *device)
|
||||
nm_manager_rfkill_update (self, RFKILL_TYPE_WLAN);
|
||||
nm_device_interface_set_enabled (NM_DEVICE_INTERFACE (device),
|
||||
priv->radio_states[RFKILL_TYPE_WLAN].enabled);
|
||||
} else if (NM_IS_MODEM (device)) {
|
||||
} else if (NM_IS_DEVICE_MODEM (device)) {
|
||||
g_signal_connect (device, "notify::" NM_MODEM_ENABLED,
|
||||
G_CALLBACK (manager_modem_enabled_changed),
|
||||
self);
|
||||
|
@@ -34,13 +34,13 @@
|
||||
#include "nm-device.h"
|
||||
#include "nm-device-wifi.h"
|
||||
#include "nm-device-ethernet.h"
|
||||
#include "nm-device-modem.h"
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-setting-ip4-config.h"
|
||||
#include "nm-setting-connection.h"
|
||||
#include "nm-system.h"
|
||||
#include "nm-named-manager.h"
|
||||
#include "nm-vpn-manager.h"
|
||||
#include "nm-modem.h"
|
||||
#include "nm-policy-hosts.h"
|
||||
|
||||
typedef struct LookupThread LookupThread;
|
||||
@@ -235,7 +235,7 @@ get_best_device (NMManager *manager, NMActRequest **out_req)
|
||||
}
|
||||
}
|
||||
|
||||
if (!can_default && !NM_IS_MODEM (dev))
|
||||
if (!can_default && !NM_IS_DEVICE_MODEM (dev))
|
||||
continue;
|
||||
|
||||
/* 'never-default' devices can't ever be the default */
|
||||
|
Reference in New Issue
Block a user