[MM] [PATCH 1/2] core: add 'hotplugged' flag to indicate if modem is newly plugged in
- From: Ben Chan <benchan chromium org>
- To: networkmanager-list gnome org
- Cc: Aleksander Morgado <aleksander lanedo com>
- Subject: [MM] [PATCH 1/2] core: add 'hotplugged' flag to indicate if modem is newly plugged in
- Date: Thu, 17 Jan 2013 23:11:09 -0800
This patch adds a 'hotplugged' flag to MMBaseModem to indicate if a
modem is newly plugged in. A plugin can use this information to
determine if, for example, the modem needs to be soft reset using the
ATZ command.
Dan Williams <dcbw redhat com> contributed the idea of implementation.
---
src/mm-base-modem.c | 18 ++++++++++++++++++
src/mm-base-modem.h | 4 ++++
src/mm-device.c | 21 +++++++++++++++++----
src/mm-device.h | 4 +++-
src/mm-manager.c | 15 ++++++++-------
src/mm-plugin.c | 2 ++
6 files changed, 52 insertions(+), 12 deletions(-)
diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c
index c66ec53..86ff812 100644
--- a/src/mm-base-modem.c
+++ b/src/mm-base-modem.c
@@ -67,6 +67,7 @@ struct _MMBaseModemPrivate {
guint vendor_id;
guint product_id;
+ gboolean hotplugged;
gboolean valid;
guint max_timeouts;
@@ -411,6 +412,23 @@ mm_base_modem_initialize (MMBaseModem *self,
}
void
+mm_base_modem_set_hotplugged (MMBaseModem *self,
+ gboolean hotplugged)
+{
+ g_return_if_fail (MM_IS_BASE_MODEM (self));
+
+ self->priv->hotplugged = hotplugged;
+}
+
+gboolean
+mm_base_modem_get_hotplugged (MMBaseModem *self)
+{
+ g_return_val_if_fail (MM_IS_BASE_MODEM (self), FALSE);
+
+ return self->priv->hotplugged;
+}
+
+void
mm_base_modem_set_valid (MMBaseModem *self,
gboolean new_valid)
{
diff --git a/src/mm-base-modem.h b/src/mm-base-modem.h
index bdacf86..9d4e3a1 100644
--- a/src/mm-base-modem.h
+++ b/src/mm-base-modem.h
@@ -143,6 +143,10 @@ MMAtSerialPort *mm_base_modem_get_best_at_port (MMBaseModem *self, GError
MMPort *mm_base_modem_get_best_data_port (MMBaseModem *self);
GList *mm_base_modem_get_data_ports (MMBaseModem *self);
+void mm_base_modem_set_hotplugged (MMBaseModem *self,
+ gboolean hotplugged);
+gboolean mm_base_modem_get_hotplugged (MMBaseModem *self);
+
void mm_base_modem_set_valid (MMBaseModem *self,
gboolean valid);
gboolean mm_base_modem_get_valid (MMBaseModem *self);
diff --git a/src/mm-device.c b/src/mm-device.c
index e8330d6..a37b26d 100644
--- a/src/mm-device.c
+++ b/src/mm-device.c
@@ -68,6 +68,9 @@ struct _MMDevicePrivate {
/* When exported, a reference to the object manager */
GDBusObjectManagerServer *object_manager;
+
+ /* Whether the device was hot-plugged. */
+ gboolean hotplugged;
};
/*****************************************************************************/
@@ -593,14 +596,24 @@ mm_device_get_port_probe_list (MMDevice *self)
return copy;
}
+gboolean
+mm_device_get_hotplugged (MMDevice *self)
+{
+ return self->priv->hotplugged;
+}
+
/*****************************************************************************/
MMDevice *
-mm_device_new (GUdevDevice *udev_device)
+mm_device_new (GUdevDevice *udev_device, gboolean hotplugged)
{
- return MM_DEVICE (g_object_new (MM_TYPE_DEVICE,
- MM_DEVICE_UDEV_DEVICE, udev_device,
- NULL));
+ MMDevice *device;
+
+ device = MM_DEVICE (g_object_new (MM_TYPE_DEVICE,
+ MM_DEVICE_UDEV_DEVICE, udev_device,
+ NULL));
+ device->priv->hotplugged = hotplugged;
+ return device;
}
static void
diff --git a/src/mm-device.h b/src/mm-device.h
index 4849905..e7065ed 100644
--- a/src/mm-device.h
+++ b/src/mm-device.h
@@ -58,7 +58,7 @@ struct _MMDeviceClass {
GType mm_device_get_type (void);
-MMDevice *mm_device_new (GUdevDevice *udev_device);
+MMDevice *mm_device_new (GUdevDevice *udev_device, gboolean hotplugged);
void mm_device_grab_port (MMDevice *self,
GUdevDevice *udev_port);
@@ -96,4 +96,6 @@ GList *mm_device_get_port_probe_list (MMDevice *self);
const gchar *mm_device_utils_get_port_driver (GUdevDevice *udev_port);
+gboolean mm_device_get_hotplugged (MMDevice *self);
+
#endif /* MM_DEVICE_H */
diff --git a/src/mm-manager.c b/src/mm-manager.c
index c5185b3..688348f 100644
--- a/src/mm-manager.c
+++ b/src/mm-manager.c
@@ -216,7 +216,8 @@ find_physical_device (GUdevDevice *child)
static void
device_added (MMManager *manager,
- GUdevDevice *port)
+ GUdevDevice *port,
+ gboolean hotplugged)
{
MMDevice *device;
const char *subsys, *name, *physdev_path, *physdev_subsys;
@@ -292,7 +293,7 @@ device_added (MMManager *manager,
FindDeviceSupportContext *ctx;
/* Keep the device listed in the Manager */
- device = mm_device_new (physdev);
+ device = mm_device_new (physdev, hotplugged);
g_hash_table_insert (manager->priv->devices,
g_strdup (physdev_path),
device);
@@ -394,7 +395,7 @@ handle_uevent (GUdevClient *client,
name = g_udev_device_get_name (device);
if ( (g_str_equal (action, "add") || g_str_equal (action, "move") || g_str_equal (action, "change"))
&& (!g_str_has_prefix (subsys, "usb") || (name && g_str_has_prefix (name, "cdc-wdm"))))
- device_added (self, device);
+ device_added (self, device, TRUE);
else if (g_str_equal (action, "remove"))
device_removed (self, device);
}
@@ -411,14 +412,14 @@ mm_manager_start (MMManager *manager)
devices = g_udev_client_query_by_subsystem (manager->priv->udev, "tty");
for (iter = devices; iter; iter = g_list_next (iter)) {
- device_added (manager, G_UDEV_DEVICE (iter->data));
+ device_added (manager, G_UDEV_DEVICE (iter->data), FALSE);
g_object_unref (G_OBJECT (iter->data));
}
g_list_free (devices);
devices = g_udev_client_query_by_subsystem (manager->priv->udev, "net");
for (iter = devices; iter; iter = g_list_next (iter)) {
- device_added (manager, G_UDEV_DEVICE (iter->data));
+ device_added (manager, G_UDEV_DEVICE (iter->data), FALSE);
g_object_unref (G_OBJECT (iter->data));
}
g_list_free (devices);
@@ -429,7 +430,7 @@ mm_manager_start (MMManager *manager)
name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data));
if (name && g_str_has_prefix (name, "cdc-wdm"))
- device_added (manager, G_UDEV_DEVICE (iter->data));
+ device_added (manager, G_UDEV_DEVICE (iter->data), FALSE);
g_object_unref (G_OBJECT (iter->data));
}
g_list_free (devices);
@@ -441,7 +442,7 @@ mm_manager_start (MMManager *manager)
name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data));
if (name && g_str_has_prefix (name, "cdc-wdm"))
- device_added (manager, G_UDEV_DEVICE (iter->data));
+ device_added (manager, G_UDEV_DEVICE (iter->data), FALSE);
g_object_unref (G_OBJECT (iter->data));
}
g_list_free (devices);
diff --git a/src/mm-plugin.c b/src/mm-plugin.c
index c7a58b7..b6889ef 100644
--- a/src/mm-plugin.c
+++ b/src/mm-plugin.c
@@ -802,6 +802,8 @@ mm_plugin_create_modem (MMPlugin *self,
port_probes,
error);
if (modem) {
+ mm_base_modem_set_hotplugged (modem, mm_device_get_hotplugged (device));
+
/* Grab each port */
for (l = port_probes; l; l = g_list_next (l)) {
GError *inner_error = NULL;
--
1.7.7.3
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]