port: store parent sysfs path in each MMPort

This commit is contained in:
Aleksander Morgado
2014-06-22 17:29:50 +02:00
parent 7752c9920d
commit 7c347aa3ec
20 changed files with 75 additions and 18 deletions

View File

@@ -174,6 +174,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
ptype, ptype,
pflags, pflags,
error); error);

View File

@@ -548,6 +548,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
mm_port_probe_get_port_type (probe), mm_port_probe_get_port_type (probe),
pflags, pflags,
error); error);

View File

@@ -238,6 +238,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
ptype, ptype,
pflags, pflags,
error); error);

View File

@@ -79,7 +79,8 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_port_type(probe), mm_port_probe_get_parent_path (probe),
mm_port_probe_get_port_type (probe),
pflags, pflags,
error); error);
} }

View File

@@ -86,6 +86,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
mm_port_probe_get_port_type (probe), mm_port_probe_get_port_type (probe),
pflags, pflags,
error); error);

View File

@@ -134,12 +134,11 @@ grab_port (MMPlugin *self,
MMPortProbe *probe, MMPortProbe *probe,
GError **error) GError **error)
{ {
const gchar *name, *subsys; const gchar *subsys;
MMPortSerialAtFlag pflags = MM_PORT_SERIAL_AT_FLAG_NONE; MMPortSerialAtFlag pflags = MM_PORT_SERIAL_AT_FLAG_NONE;
MMPortType port_type; MMPortType port_type;
subsys = mm_port_probe_get_port_subsys (probe); subsys = mm_port_probe_get_port_subsys (probe);
name = mm_port_probe_get_port_name (probe);
port_type = mm_port_probe_get_port_type (probe); port_type = mm_port_probe_get_port_type (probe);
/* Detect AT port types */ /* Detect AT port types */
@@ -161,7 +160,8 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
subsys, subsys,
name, mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
port_type, port_type,
pflags, pflags,
error); error);

View File

@@ -80,6 +80,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
MM_PORT_TYPE_AT, /* we only allow AT ports here */ MM_PORT_TYPE_AT, /* we only allow AT ports here */
pflags, pflags,
error); error);

View File

@@ -121,6 +121,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
ptype, ptype,
pflags, pflags,
error); error);

View File

@@ -295,6 +295,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
ptype, ptype,
pflags, pflags,
error); error);

View File

@@ -99,6 +99,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
ptype, ptype,
pflags, pflags,
error); error);

View File

@@ -92,6 +92,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
ptype, ptype,
pflags, pflags,
error); error);

View File

@@ -254,6 +254,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
ptype, ptype,
pflags, pflags,
error); error);

View File

@@ -151,6 +151,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem, return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
ptype, ptype,
pflags, pflags,
error); error);

View File

@@ -162,6 +162,7 @@ gboolean
mm_base_modem_grab_port (MMBaseModem *self, mm_base_modem_grab_port (MMBaseModem *self,
const gchar *subsys, const gchar *subsys,
const gchar *name, const gchar *name,
const gchar *parent_path,
MMPortType ptype, MMPortType ptype,
MMPortSerialAtFlag at_pflags, MMPortSerialAtFlag at_pflags,
GError **error) GError **error)
@@ -306,6 +307,11 @@ mm_base_modem_grab_port (MMBaseModem *self,
* Note: 'key' and 'port' now owned by the HT. */ * Note: 'key' and 'port' now owned by the HT. */
g_hash_table_insert (self->priv->ports, key, port); g_hash_table_insert (self->priv->ports, key, port);
/* Store parent path */
g_object_set (port,
MM_PORT_PARENT_PATH, parent_path,
NULL);
return TRUE; return TRUE;
} }

View File

@@ -106,6 +106,7 @@ GType mm_base_modem_get_type (void);
gboolean mm_base_modem_grab_port (MMBaseModem *self, gboolean mm_base_modem_grab_port (MMBaseModem *self,
const gchar *subsys, const gchar *subsys,
const gchar *name, const gchar *name,
const gchar *parent_path,
MMPortType ptype, MMPortType ptype,
MMPortSerialAtFlag at_pflags, MMPortSerialAtFlag at_pflags,
GError **error); GError **error);

View File

@@ -909,6 +909,7 @@ mm_plugin_create_modem (MMPlugin *self,
grabbed = mm_base_modem_grab_port (modem, grabbed = mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe), mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
mm_port_probe_get_port_type (probe), mm_port_probe_get_port_type (probe),
MM_PORT_SERIAL_AT_FLAG_NONE, MM_PORT_SERIAL_AT_FLAG_NONE,
&inner_error); &inner_error);
@@ -929,6 +930,7 @@ mm_plugin_create_modem (MMPlugin *self,
if (!mm_base_modem_grab_port (modem, if (!mm_base_modem_grab_port (modem,
"virtual", "virtual",
virtual_ports[i], virtual_ports[i],
NULL,
MM_PORT_TYPE_AT, MM_PORT_TYPE_AT,
MM_PORT_SERIAL_AT_FLAG_NONE, MM_PORT_SERIAL_AT_FLAG_NONE,
&inner_error)) { &inner_error)) {

View File

@@ -123,6 +123,7 @@ struct _MMPortProbePrivate {
/* Properties */ /* Properties */
MMDevice *device; MMDevice *device;
GUdevDevice *port; GUdevDevice *port;
GUdevDevice *parent;
/* Probing results */ /* Probing results */
guint32 flags; guint32 flags;
@@ -1646,6 +1647,14 @@ mm_port_probe_get_port_subsys (MMPortProbe *self)
return g_udev_device_get_subsystem (self->priv->port); return g_udev_device_get_subsystem (self->priv->port);
} }
const gchar *
mm_port_probe_get_parent_path (MMPortProbe *self)
{
g_return_val_if_fail (MM_IS_PORT_PROBE (self), NULL);
return (self->priv->parent ? g_udev_device_get_sysfs_path (self->priv->parent) : NULL);
}
/*****************************************************************************/ /*****************************************************************************/
MMPortProbe * MMPortProbe *
@@ -1682,6 +1691,7 @@ set_property (GObject *object,
case PROP_PORT: case PROP_PORT:
/* construct only */ /* construct only */
self->priv->port = g_value_dup_object (value); self->priv->port = g_value_dup_object (value);
self->priv->parent = g_udev_device_get_parent (self->priv->port);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1732,6 +1742,7 @@ dispose (GObject *object)
/* We didn't get a reference to the device */ /* We didn't get a reference to the device */
self->priv->device = NULL; self->priv->device = NULL;
g_clear_object (&self->priv->parent);
g_clear_object (&self->priv->port); g_clear_object (&self->priv->port);
G_OBJECT_CLASS (mm_port_probe_parent_class)->dispose (object); G_OBJECT_CLASS (mm_port_probe_parent_class)->dispose (object);

View File

@@ -87,6 +87,7 @@ GUdevDevice *mm_port_probe_peek_port (MMPortProbe *self);
GUdevDevice *mm_port_probe_get_port (MMPortProbe *self); GUdevDevice *mm_port_probe_get_port (MMPortProbe *self);
const gchar *mm_port_probe_get_port_name (MMPortProbe *self); const gchar *mm_port_probe_get_port_name (MMPortProbe *self);
const gchar *mm_port_probe_get_port_subsys (MMPortProbe *self); const gchar *mm_port_probe_get_port_subsys (MMPortProbe *self);
const gchar *mm_port_probe_get_parent_path (MMPortProbe *self);
/* Probing result setters */ /* Probing result setters */
void mm_port_probe_set_result_at (MMPortProbe *self, void mm_port_probe_set_result_at (MMPortProbe *self,

View File

@@ -29,15 +29,17 @@ enum {
PROP_SUBSYS, PROP_SUBSYS,
PROP_TYPE, PROP_TYPE,
PROP_CONNECTED, PROP_CONNECTED,
PROP_PARENT_PATH,
LAST_PROP LAST_PROP
}; };
struct _MMPortPrivate { struct _MMPortPrivate {
char *device; gchar *device;
MMPortSubsys subsys; MMPortSubsys subsys;
MMPortType ptype; MMPortType ptype;
gboolean connected; gboolean connected;
gchar *parent_path;
}; };
/*****************************************************************************/ /*****************************************************************************/
@@ -94,6 +96,14 @@ mm_port_set_connected (MMPort *self, gboolean connected)
} }
} }
const gchar *
mm_port_get_parent_path (MMPort *self)
{
g_return_val_if_fail (MM_IS_PORT (self), NULL);
return self->priv->parent_path;
}
/*****************************************************************************/ /*****************************************************************************/
static void static void
@@ -126,6 +136,10 @@ set_property (GObject *object,
case PROP_CONNECTED: case PROP_CONNECTED:
self->priv->connected = g_value_get_boolean (value); self->priv->connected = g_value_get_boolean (value);
break; break;
case PROP_PARENT_PATH:
g_free (self->priv->parent_path);
self->priv->parent_path = g_value_dup_string (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@@ -151,6 +165,9 @@ get_property (GObject *object, guint prop_id,
case PROP_CONNECTED: case PROP_CONNECTED:
g_value_set_boolean (value, self->priv->connected); g_value_set_boolean (value, self->priv->connected);
break; break;
case PROP_PARENT_PATH:
g_value_set_string (value, self->priv->parent_path);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@@ -163,6 +180,7 @@ finalize (GObject *object)
MMPort *self = MM_PORT (object); MMPort *self = MM_PORT (object);
g_free (self->priv->device); g_free (self->priv->device);
g_free (self->priv->parent_path);
G_OBJECT_CLASS (mm_port_parent_class)->finalize (object); G_OBJECT_CLASS (mm_port_parent_class)->finalize (object);
} }
@@ -214,4 +232,12 @@ mm_port_class_init (MMPortClass *klass)
"Is connected for data and not usable for control", "Is connected for data and not usable for control",
FALSE, FALSE,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property
(object_class, PROP_PARENT_PATH,
g_param_spec_string (MM_PORT_PARENT_PATH,
"Parent path",
"sysfs path of the parent device",
NULL,
G_PARAM_READWRITE));
} }

View File

@@ -49,10 +49,11 @@ typedef enum { /*< underscore_name=mm_port_type >*/
#define MM_IS_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PORT)) #define MM_IS_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PORT))
#define MM_PORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PORT, MMPortClass)) #define MM_PORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PORT, MMPortClass))
#define MM_PORT_DEVICE "device" #define MM_PORT_DEVICE "device"
#define MM_PORT_SUBSYS "subsys" #define MM_PORT_SUBSYS "subsys"
#define MM_PORT_TYPE "type" #define MM_PORT_TYPE "type"
#define MM_PORT_CONNECTED "connected" #define MM_PORT_CONNECTED "connected"
#define MM_PORT_PARENT_PATH "parent-path"
typedef struct _MMPort MMPort; typedef struct _MMPort MMPort;
typedef struct _MMPortClass MMPortClass; typedef struct _MMPortClass MMPortClass;
@@ -69,14 +70,11 @@ struct _MMPortClass {
GType mm_port_get_type (void); GType mm_port_get_type (void);
const char * mm_port_get_device (MMPort *self); const gchar *mm_port_get_device (MMPort *self);
MMPortSubsys mm_port_get_subsys (MMPort *self);
MMPortSubsys mm_port_get_subsys (MMPort *self); MMPortType mm_port_get_port_type (MMPort *self);
const gchar *mm_port_get_parent_path (MMPort *self);
MMPortType mm_port_get_port_type (MMPort *self); gboolean mm_port_get_connected (MMPort *self);
void mm_port_set_connected (MMPort *self, gboolean connected);
gboolean mm_port_get_connected (MMPort *self);
void mm_port_set_connected (MMPort *self, gboolean connected);
#endif /* MM_PORT_H */ #endif /* MM_PORT_H */