plugins: allow plugins to more easily suggest port types
ZTE modems need to use udev rules to assign port type hints, so generalize that and port all the plugins over to suggested port types in the MMModem interface's grab_port() function.
This commit is contained in:
+12
-7
@@ -85,6 +85,7 @@ static gboolean
|
||||
grab_port (MMModem *modem,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
MMPortType suggested_type,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
@@ -94,24 +95,28 @@ grab_port (MMModem *modem,
|
||||
MMPort *port;
|
||||
|
||||
g_return_val_if_fail (!strcmp (subsys, "net") || !strcmp (subsys, "tty"), FALSE);
|
||||
if (priv->primary)
|
||||
g_return_val_if_fail (suggested_type != MM_PORT_TYPE_PRIMARY, FALSE);
|
||||
|
||||
if (!strcmp (subsys, "tty")) {
|
||||
if (!priv->primary)
|
||||
ptype = MM_PORT_TYPE_PRIMARY;
|
||||
else if (!priv->secondary)
|
||||
ptype = MM_PORT_TYPE_SECONDARY;
|
||||
if (suggested_type != MM_PORT_TYPE_UNKNOWN)
|
||||
ptype = suggested_type;
|
||||
else {
|
||||
if (!priv->primary)
|
||||
ptype = MM_PORT_TYPE_PRIMARY;
|
||||
else if (!priv->secondary)
|
||||
ptype = MM_PORT_TYPE_SECONDARY;
|
||||
}
|
||||
}
|
||||
|
||||
port = mm_modem_base_add_port (MM_MODEM_BASE (self), subsys, name, ptype);
|
||||
if (MM_IS_SERIAL_PORT (port)) {
|
||||
if (port && MM_IS_SERIAL_PORT (port)) {
|
||||
g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL);
|
||||
mm_serial_port_set_response_parser (MM_SERIAL_PORT (port),
|
||||
mm_serial_parser_v1_parse,
|
||||
mm_serial_parser_v1_new (),
|
||||
mm_serial_parser_v1_destroy);
|
||||
}
|
||||
|
||||
if (MM_IS_SERIAL_PORT (port)) {
|
||||
if (ptype == MM_PORT_TYPE_PRIMARY) {
|
||||
priv->primary = MM_SERIAL_PORT (port);
|
||||
if (!priv->data) {
|
||||
|
||||
+13
-5
@@ -217,7 +217,7 @@ mm_generic_gsm_grab_port (MMGenericGsm *self,
|
||||
g_return_val_if_fail (!strcmp (subsys, "net") || !strcmp (subsys, "tty"), FALSE);
|
||||
|
||||
port = mm_modem_base_add_port (MM_MODEM_BASE (self), subsys, name, ptype);
|
||||
if (MM_IS_SERIAL_PORT (port)) {
|
||||
if (port && MM_IS_SERIAL_PORT (port)) {
|
||||
mm_serial_port_set_response_parser (MM_SERIAL_PORT (port),
|
||||
mm_serial_parser_v1_parse,
|
||||
mm_serial_parser_v1_new (),
|
||||
@@ -252,6 +252,7 @@ static gboolean
|
||||
grab_port (MMModem *modem,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
MMPortType suggested_type,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
@@ -259,11 +260,18 @@ grab_port (MMModem *modem,
|
||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (self);
|
||||
MMPortType ptype = MM_PORT_TYPE_IGNORED;
|
||||
|
||||
if (priv->primary)
|
||||
g_return_val_if_fail (suggested_type != MM_PORT_TYPE_PRIMARY, FALSE);
|
||||
|
||||
if (!strcmp (subsys, "tty")) {
|
||||
if (!priv->primary)
|
||||
ptype = MM_PORT_TYPE_PRIMARY;
|
||||
else if (!priv->secondary)
|
||||
ptype = MM_PORT_TYPE_SECONDARY;
|
||||
if (suggested_type != MM_PORT_TYPE_UNKNOWN)
|
||||
ptype = suggested_type;
|
||||
else {
|
||||
if (!priv->primary)
|
||||
ptype = MM_PORT_TYPE_PRIMARY;
|
||||
else if (!priv->secondary)
|
||||
ptype = MM_PORT_TYPE_SECONDARY;
|
||||
}
|
||||
}
|
||||
|
||||
return !!mm_generic_gsm_grab_port (self, subsys, name, ptype, error);
|
||||
|
||||
+2
-1
@@ -300,6 +300,7 @@ gboolean
|
||||
mm_modem_grab_port (MMModem *self,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
MMPortType suggested_type,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
@@ -309,7 +310,7 @@ mm_modem_grab_port (MMModem *self,
|
||||
g_return_val_if_fail (name, FALSE);
|
||||
|
||||
g_assert (MM_MODEM_GET_INTERFACE (self)->grab_port);
|
||||
return MM_MODEM_GET_INTERFACE (self)->grab_port (self, subsys, name, user_data, error);
|
||||
return MM_MODEM_GET_INTERFACE (self)->grab_port (self, subsys, name, suggested_type, user_data, error);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "mm-port.h"
|
||||
|
||||
#define MM_TYPE_MODEM (mm_modem_get_type ())
|
||||
#define MM_MODEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM, MMModem))
|
||||
#define MM_IS_MODEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM))
|
||||
@@ -78,6 +80,7 @@ struct _MMModem {
|
||||
gboolean (*grab_port) (MMModem *self,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
MMPortType suggested_type,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
|
||||
@@ -117,6 +120,7 @@ gboolean mm_modem_owns_port (MMModem *self,
|
||||
gboolean mm_modem_grab_port (MMModem *self,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
MMPortType suggested_type,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user