plugin: allow creating 'virtual' modems with 'virtual' ports

This commit is contained in:
Aleksander Morgado
2013-11-22 23:40:55 +01:00
parent c182a04f64
commit 2d9d15f892

View File

@@ -836,10 +836,14 @@ mm_plugin_create_modem (MMPlugin *self,
MMDevice *device, MMDevice *device,
GError **error) GError **error)
{ {
MMBaseModem *modem = NULL; MMBaseModem *modem;
GList *port_probes, *l; GList *port_probes = NULL;
const gchar **virtual_ports = NULL;
if (!mm_device_is_virtual (device))
port_probes = mm_device_peek_port_probe_list (device); port_probes = mm_device_peek_port_probe_list (device);
else
virtual_ports = mm_device_virtual_peek_ports (device);
/* Let the plugin create the modem from the port probe results */ /* Let the plugin create the modem from the port probe results */
modem = MM_PLUGIN_GET_CLASS (self)->create_modem (MM_PLUGIN (self), modem = MM_PLUGIN_GET_CLASS (self)->create_modem (MM_PLUGIN (self),
@@ -849,9 +853,14 @@ mm_plugin_create_modem (MMPlugin *self,
mm_device_get_product (device), mm_device_get_product (device),
port_probes, port_probes,
error); error);
if (modem) { if (!modem)
return NULL;
mm_base_modem_set_hotplugged (modem, mm_device_get_hotplugged (device)); mm_base_modem_set_hotplugged (modem, mm_device_get_hotplugged (device));
if (port_probes) {
GList *l;
/* Grab each port */ /* Grab each port */
for (l = port_probes; l; l = g_list_next (l)) { for (l = port_probes; l; l = g_list_next (l)) {
GError *inner_error = NULL; GError *inner_error = NULL;
@@ -911,11 +920,29 @@ mm_plugin_create_modem (MMPlugin *self,
g_clear_error (&inner_error); g_clear_error (&inner_error);
} }
} }
} else if (virtual_ports) {
guint i;
for (i = 0; virtual_ports[i]; i++) {
GError *inner_error = NULL;
if (!mm_base_modem_grab_port (modem,
"virtual",
virtual_ports[i],
MM_PORT_TYPE_AT,
MM_PORT_SERIAL_AT_FLAG_NONE,
&inner_error)) {
mm_warn ("Could not grab port (virtual/%s): '%s'",
virtual_ports[i],
inner_error ? inner_error->message : "unknown error");
g_clear_error (&inner_error);
}
}
}
/* If organizing ports fails, consider the modem invalid */ /* If organizing ports fails, consider the modem invalid */
if (!mm_base_modem_organize_ports (modem, error)) if (!mm_base_modem_organize_ports (modem, error))
g_clear_object (&modem); g_clear_object (&modem);
}
return modem; return modem;
} }