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,
mm_port_probe_get_port_subsys (probe),
mm_port_probe_get_port_name (probe),
mm_port_probe_get_parent_path (probe),
ptype,
pflags,
error);

View File

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

View File

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

View File

@@ -79,7 +79,8 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (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,
error);
}

View File

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

View File

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

View File

@@ -80,6 +80,7 @@ grab_port (MMPlugin *self,
return mm_base_modem_grab_port (modem,
mm_port_probe_get_port_subsys (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 */
pflags,
error);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -162,6 +162,7 @@ gboolean
mm_base_modem_grab_port (MMBaseModem *self,
const gchar *subsys,
const gchar *name,
const gchar *parent_path,
MMPortType ptype,
MMPortSerialAtFlag at_pflags,
GError **error)
@@ -306,6 +307,11 @@ mm_base_modem_grab_port (MMBaseModem *self,
* Note: 'key' and 'port' now owned by the HT. */
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;
}

View File

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

View File

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

View File

@@ -123,6 +123,7 @@ struct _MMPortProbePrivate {
/* Properties */
MMDevice *device;
GUdevDevice *port;
GUdevDevice *parent;
/* Probing results */
guint32 flags;
@@ -1646,6 +1647,14 @@ mm_port_probe_get_port_subsys (MMPortProbe *self)
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 *
@@ -1682,6 +1691,7 @@ set_property (GObject *object,
case PROP_PORT:
/* construct only */
self->priv->port = g_value_dup_object (value);
self->priv->parent = g_udev_device_get_parent (self->priv->port);
break;
default:
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 */
self->priv->device = NULL;
g_clear_object (&self->priv->parent);
g_clear_object (&self->priv->port);
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);
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_parent_path (MMPortProbe *self);
/* Probing result setters */
void mm_port_probe_set_result_at (MMPortProbe *self,

View File

@@ -29,15 +29,17 @@ enum {
PROP_SUBSYS,
PROP_TYPE,
PROP_CONNECTED,
PROP_PARENT_PATH,
LAST_PROP
};
struct _MMPortPrivate {
char *device;
gchar *device;
MMPortSubsys subsys;
MMPortType ptype;
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
@@ -126,6 +136,10 @@ set_property (GObject *object,
case PROP_CONNECTED:
self->priv->connected = g_value_get_boolean (value);
break;
case PROP_PARENT_PATH:
g_free (self->priv->parent_path);
self->priv->parent_path = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -151,6 +165,9 @@ get_property (GObject *object, guint prop_id,
case PROP_CONNECTED:
g_value_set_boolean (value, self->priv->connected);
break;
case PROP_PARENT_PATH:
g_value_set_string (value, self->priv->parent_path);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -163,6 +180,7 @@ finalize (GObject *object)
MMPort *self = MM_PORT (object);
g_free (self->priv->device);
g_free (self->priv->parent_path);
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",
FALSE,
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_PORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PORT, MMPortClass))
#define MM_PORT_DEVICE "device"
#define MM_PORT_SUBSYS "subsys"
#define MM_PORT_TYPE "type"
#define MM_PORT_CONNECTED "connected"
#define MM_PORT_DEVICE "device"
#define MM_PORT_SUBSYS "subsys"
#define MM_PORT_TYPE "type"
#define MM_PORT_CONNECTED "connected"
#define MM_PORT_PARENT_PATH "parent-path"
typedef struct _MMPort MMPort;
typedef struct _MMPortClass MMPortClass;
@@ -69,14 +70,11 @@ struct _MMPortClass {
GType mm_port_get_type (void);
const char * mm_port_get_device (MMPort *self);
MMPortSubsys mm_port_get_subsys (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);
const gchar *mm_port_get_device (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);
gboolean mm_port_get_connected (MMPort *self);
void mm_port_set_connected (MMPort *self, gboolean connected);
#endif /* MM_PORT_H */