mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-25 09:40:49 +02:00
mobile: convert to device removed signals
Instead of having NMManager listen directly to the ModemManager for modem removal signals, have the NMDeviceModem and NMDeviceBt listen for them (since they obviously have a pointer to the backing NMModem object) and then re-emit any necessary device removal signals to the manager.
This commit is contained in:
parent
ee66964208
commit
8e9b9fe423
7 changed files with 63 additions and 80 deletions
|
|
@ -560,6 +560,34 @@ modem_stage1 (NMDeviceBt *self, NMModem *modem, NMDeviceStateReason *reason)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
modem_cleanup (NMDeviceBt *self)
|
||||
{
|
||||
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (self);
|
||||
|
||||
if (priv->modem) {
|
||||
g_signal_handlers_disconnect_matched (priv->modem, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, self);
|
||||
g_clear_object (&priv->modem);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
modem_removed_cb (NMModem *modem, gpointer user_data)
|
||||
{
|
||||
NMDeviceBt *self = NM_DEVICE_BT (user_data);
|
||||
NMDeviceState state;
|
||||
|
||||
/* Fail the device if the modem was removed while active */
|
||||
state = nm_device_get_state (NM_DEVICE (self));
|
||||
if ( state == NM_DEVICE_STATE_ACTIVATED
|
||||
|| nm_device_is_activating (NM_DEVICE (self))) {
|
||||
nm_device_state_changed (NM_DEVICE (self),
|
||||
NM_DEVICE_STATE_FAILED,
|
||||
NM_DEVICE_STATE_REASON_BT_FAILED);
|
||||
} else
|
||||
modem_cleanup (self);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_device_bt_modem_added (NMDeviceBt *self,
|
||||
NMModem *modem,
|
||||
|
|
@ -614,7 +642,7 @@ nm_device_bt_modem_added (NMDeviceBt *self,
|
|||
|
||||
if (priv->modem) {
|
||||
g_warn_if_reached ();
|
||||
g_object_unref (priv->modem);
|
||||
modem_cleanup (self);
|
||||
}
|
||||
|
||||
priv->modem = g_object_ref (modem);
|
||||
|
|
@ -624,6 +652,7 @@ nm_device_bt_modem_added (NMDeviceBt *self,
|
|||
g_signal_connect (modem, NM_MODEM_IP4_CONFIG_RESULT, G_CALLBACK (modem_ip4_config_result), self);
|
||||
g_signal_connect (modem, NM_MODEM_AUTH_REQUESTED, G_CALLBACK (modem_auth_requested), self);
|
||||
g_signal_connect (modem, NM_MODEM_AUTH_RESULT, G_CALLBACK (modem_auth_result), self);
|
||||
g_signal_connect (modem, NM_MODEM_REMOVED, G_CALLBACK (modem_removed_cb), self);
|
||||
|
||||
/* In the old ModemManager the data port is known from the very beginning;
|
||||
* while in the new ModemManager the data port is set afterwards when the bearer gets
|
||||
|
|
@ -639,35 +668,6 @@ nm_device_bt_modem_added (NMDeviceBt *self,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_device_bt_modem_removed (NMDeviceBt *self, NMModem *modem)
|
||||
{
|
||||
NMDeviceBtPrivate *priv;
|
||||
NMDeviceState state;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DEVICE_BT (self), FALSE);
|
||||
g_return_val_if_fail (NM_IS_MODEM (modem), FALSE);
|
||||
|
||||
priv = NM_DEVICE_BT_GET_PRIVATE (self);
|
||||
|
||||
if (modem != priv->modem)
|
||||
return FALSE;
|
||||
|
||||
/* Fail the device if the modem was removed while active */
|
||||
state = nm_device_get_state (NM_DEVICE (self));
|
||||
if ( state == NM_DEVICE_STATE_ACTIVATED
|
||||
|| nm_device_is_activating (NM_DEVICE (self))) {
|
||||
nm_device_state_changed (NM_DEVICE (self),
|
||||
NM_DEVICE_STATE_FAILED,
|
||||
NM_DEVICE_STATE_REASON_BT_FAILED);
|
||||
} else {
|
||||
g_object_unref (priv->modem);
|
||||
priv->modem = NULL;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
modem_find_timeout (gpointer user_data)
|
||||
{
|
||||
|
|
@ -905,8 +905,7 @@ deactivate (NMDevice *device)
|
|||
NM_DEVICE_STATE_DISCONNECTED,
|
||||
NM_DEVICE_STATE_ACTIVATED,
|
||||
NM_DEVICE_STATE_REASON_USER_REQUESTED);
|
||||
g_object_unref (priv->modem);
|
||||
priv->modem = NULL;
|
||||
modem_cleanup (NM_DEVICE_BT (device));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1166,7 +1165,7 @@ dispose (GObject *object)
|
|||
}
|
||||
priv->dbus_mgr = NULL;
|
||||
|
||||
g_clear_object (&priv->modem);
|
||||
modem_cleanup (NM_DEVICE_BT (object));
|
||||
g_clear_object (&priv->bt_device);
|
||||
|
||||
G_OBJECT_CLASS (nm_device_bt_parent_class)->dispose (object);
|
||||
|
|
|
|||
|
|
@ -69,8 +69,6 @@ gboolean nm_device_bt_modem_added (NMDeviceBt *device,
|
|||
NMModem *modem,
|
||||
const char *driver);
|
||||
|
||||
gboolean nm_device_bt_modem_removed (NMDeviceBt *device, NMModem *modem);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_DEVICE_BT_H */
|
||||
|
|
|
|||
|
|
@ -196,6 +196,12 @@ modem_connected_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
modem_removed_cb (NMModem *modem, gpointer user_data)
|
||||
{
|
||||
g_signal_emit_by_name (NM_DEVICE (user_data), NM_DEVICE_REMOVED);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMModem *
|
||||
|
|
@ -398,6 +404,7 @@ set_modem (NMDeviceModem *self, NMModem *modem)
|
|||
g_signal_connect (modem, NM_MODEM_AUTH_RESULT, G_CALLBACK (modem_auth_result), self);
|
||||
g_signal_connect (modem, "notify::" NM_MODEM_ENABLED, G_CALLBACK (modem_enabled_cb), self);
|
||||
g_signal_connect (modem, "notify::" NM_MODEM_CONNECTED, G_CALLBACK (modem_connected_cb), self);
|
||||
g_signal_connect (modem, NM_MODEM_REMOVED, G_CALLBACK (modem_removed_cb), self);
|
||||
|
||||
/* In the old ModemManager the data port is known from the very beginning;
|
||||
* while in the new ModemManager the data port is set afterwards when the bearer gets
|
||||
|
|
|
|||
|
|
@ -63,8 +63,6 @@ struct _NMModemManagerPrivate {
|
|||
|
||||
enum {
|
||||
MODEM_ADDED,
|
||||
MODEM_REMOVED,
|
||||
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
|
|
@ -159,7 +157,7 @@ modem_removed (DBusGProxy *proxy, const char *path, gpointer user_data)
|
|||
|
||||
modem = (NMModem *) g_hash_table_lookup (self->priv->modems, path);
|
||||
if (modem) {
|
||||
g_signal_emit (self, signals[MODEM_REMOVED], 0, modem);
|
||||
nm_modem_emit_removed (modem);
|
||||
g_hash_table_remove (self->priv->modems, path);
|
||||
}
|
||||
}
|
||||
|
|
@ -274,8 +272,7 @@ modem_manager_appeared (NMModemManager *self, gboolean enumerate_devices)
|
|||
static gboolean
|
||||
remove_one_modem (gpointer key, gpointer value, gpointer user_data)
|
||||
{
|
||||
g_signal_emit (user_data, signals[MODEM_REMOVED], 0, value);
|
||||
|
||||
nm_modem_emit_removed (NM_MODEM (value));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -426,7 +423,7 @@ modem_object_removed (MMManager *manager,
|
|||
if (!modem)
|
||||
return;
|
||||
|
||||
g_signal_emit (self, signals[MODEM_REMOVED], 0, modem);
|
||||
nm_modem_emit_removed (modem);
|
||||
g_hash_table_remove (self->priv->modems, path);
|
||||
}
|
||||
|
||||
|
|
@ -760,12 +757,4 @@ nm_modem_manager_class_init (NMModemManagerClass *klass)
|
|||
G_STRUCT_OFFSET (NMModemManagerClass, modem_added),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_STRING);
|
||||
|
||||
signals[MODEM_REMOVED] =
|
||||
g_signal_new ("modem-removed",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMModemManagerClass, modem_removed),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1, G_TYPE_OBJECT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ enum {
|
|||
IP4_CONFIG_RESULT,
|
||||
AUTH_REQUESTED,
|
||||
AUTH_RESULT,
|
||||
REMOVED,
|
||||
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
|
@ -126,6 +127,12 @@ nm_modem_get_mm_connected (NMModem *self)
|
|||
return NM_MODEM_GET_PRIVATE (self)->mm_connected;
|
||||
}
|
||||
|
||||
void
|
||||
nm_modem_emit_removed (NMModem *self)
|
||||
{
|
||||
g_signal_emit (self, signals[REMOVED], 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* IP method PPP */
|
||||
|
||||
|
|
@ -988,6 +995,14 @@ nm_modem_class_init (NMModemClass *klass)
|
|||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1, G_TYPE_POINTER);
|
||||
|
||||
signals[REMOVED] =
|
||||
g_signal_new (NM_MODEM_REMOVED,
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMModemClass, removed),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
dbus_g_error_domain_register (NM_MODEM_ERROR,
|
||||
NM_DBUS_INTERFACE_DEVICE_MODEM,
|
||||
NM_TYPE_MODEM_ERROR);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ G_BEGIN_DECLS
|
|||
#define NM_MODEM_IP4_CONFIG_RESULT "ip4-config-result"
|
||||
#define NM_MODEM_AUTH_REQUESTED "auth-requested"
|
||||
#define NM_MODEM_AUTH_RESULT "auth-result"
|
||||
#define NM_MODEM_REMOVED "removed"
|
||||
|
||||
#define MM_MODEM_IP_METHOD_PPP 0
|
||||
#define MM_MODEM_IP_METHOD_STATIC 1
|
||||
|
|
@ -119,6 +120,8 @@ typedef struct {
|
|||
|
||||
void (*auth_requested) (NMModem *self);
|
||||
void (*auth_result) (NMModem *self, GError *error);
|
||||
|
||||
void (*removed) (NMModem *self);
|
||||
} NMModemClass;
|
||||
|
||||
GType nm_modem_get_type (void);
|
||||
|
|
@ -182,6 +185,9 @@ void nm_modem_set_mm_enabled (NMModem *self, gboolean enabled);
|
|||
|
||||
gboolean nm_modem_get_mm_connected (NMModem *self);
|
||||
|
||||
/* For the modem-manager only */
|
||||
void nm_modem_emit_removed (NMModem *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_MODEM_H */
|
||||
|
|
|
|||
|
|
@ -237,7 +237,6 @@ typedef struct {
|
|||
|
||||
NMModemManager *modem_manager;
|
||||
guint modem_added_id;
|
||||
guint modem_removed_id;
|
||||
|
||||
DBusGProxy *aipd_proxy;
|
||||
NMSleepMonitor *sleep_monitor;
|
||||
|
|
@ -842,30 +841,6 @@ device_removed_cb (NMDevice *device, gpointer user_data)
|
|||
remove_device (NM_MANAGER (user_data), device, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
modem_removed (NMModemManager *modem_manager,
|
||||
NMModem *modem,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMManager *self = NM_MANAGER (user_data);
|
||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
||||
NMDevice *found;
|
||||
GSList *iter;
|
||||
|
||||
/* Give Bluetooth DUN devices first chance to handle the modem removal */
|
||||
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
|
||||
if (nm_device_get_device_type (iter->data) == NM_DEVICE_TYPE_BT) {
|
||||
if (nm_device_bt_modem_removed (NM_DEVICE_BT (iter->data), modem))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Otherwise remove the standalone modem */
|
||||
found = nm_manager_get_device_by_udi (self, nm_modem_get_path (modem));
|
||||
if (found)
|
||||
remove_device (self, found, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
aipd_handle_event (DBusGProxy *proxy,
|
||||
const char *event,
|
||||
|
|
@ -4886,8 +4861,6 @@ nm_manager_init (NMManager *manager)
|
|||
priv->modem_manager = nm_modem_manager_get ();
|
||||
priv->modem_added_id = g_signal_connect (priv->modem_manager, "modem-added",
|
||||
G_CALLBACK (modem_added), manager);
|
||||
priv->modem_removed_id = g_signal_connect (priv->modem_manager, "modem-removed",
|
||||
G_CALLBACK (modem_removed), manager);
|
||||
|
||||
priv->vpn_manager = nm_vpn_manager_get ();
|
||||
|
||||
|
|
@ -5111,10 +5084,6 @@ dispose (GObject *object)
|
|||
g_source_remove (priv->modem_added_id);
|
||||
priv->modem_added_id = 0;
|
||||
}
|
||||
if (priv->modem_removed_id) {
|
||||
g_source_remove (priv->modem_removed_id);
|
||||
priv->modem_removed_id = 0;
|
||||
}
|
||||
g_clear_object (&priv->modem_manager);
|
||||
|
||||
/* Unregister property filter */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue