device: split `MMDevice' creation and plugin setting

We want to be able to create the MMDevice way before we have decided which
plugin to use.
This commit is contained in:
Aleksander Morgado
2012-07-10 07:00:46 +02:00
parent 815693661c
commit 0aff871b04
3 changed files with 20 additions and 10 deletions

View File

@@ -262,6 +262,15 @@ mm_device_get_udev_device (MMDevice *self)
return G_UDEV_DEVICE (g_object_ref (self->priv->udev_device)); return G_UDEV_DEVICE (g_object_ref (self->priv->udev_device));
} }
void
mm_device_set_plugin (MMDevice *self,
MMPlugin *plugin)
{
g_object_set (self,
MM_DEVICE_PLUGIN, plugin,
NULL);
}
MMPlugin * MMPlugin *
mm_device_peek_plugin (MMDevice *self) mm_device_peek_plugin (MMDevice *self)
{ {
@@ -271,7 +280,9 @@ mm_device_peek_plugin (MMDevice *self)
MMPlugin * MMPlugin *
mm_device_get_plugin (MMDevice *self) mm_device_get_plugin (MMDevice *self)
{ {
return MM_PLUGIN (g_object_ref (self->priv->plugin)); return (self->priv->plugin ?
MM_PLUGIN (g_object_ref (self->priv->plugin)) :
NULL);
} }
MMBaseModem * MMBaseModem *
@@ -293,12 +304,10 @@ mm_device_get_modem (MMDevice *self)
/*****************************************************************************/ /*****************************************************************************/
MMDevice * MMDevice *
mm_device_new (GUdevDevice *udev_device, mm_device_new (GUdevDevice *udev_device)
MMPlugin *plugin)
{ {
return MM_DEVICE (g_object_new (MM_TYPE_DEVICE, return MM_DEVICE (g_object_new (MM_TYPE_DEVICE,
MM_DEVICE_UDEV_DEVICE, udev_device, MM_DEVICE_UDEV_DEVICE, udev_device,
MM_DEVICE_PLUGIN, plugin,
NULL)); NULL));
} }
@@ -325,7 +334,7 @@ set_property (GObject *object,
self->priv->udev_device = g_value_dup_object (value); self->priv->udev_device = g_value_dup_object (value);
break; break;
case PROP_PLUGIN: case PROP_PLUGIN:
/* construct only */ g_clear_object (&(self->priv->plugin));
self->priv->plugin = g_value_dup_object (value); self->priv->plugin = g_value_dup_object (value);
break; break;
case PROP_MODEM: case PROP_MODEM:
@@ -400,7 +409,7 @@ mm_device_class_init (MMDeviceClass *klass)
"Plugin", "Plugin",
"Best plugin to manage this device", "Best plugin to manage this device",
MM_TYPE_PLUGIN, MM_TYPE_PLUGIN,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_PLUGIN, properties[PROP_PLUGIN]); g_object_class_install_property (object_class, PROP_PLUGIN, properties[PROP_PLUGIN]);
properties[PROP_MODEM] = properties[PROP_MODEM] =

View File

@@ -49,8 +49,7 @@ struct _MMDeviceClass {
GType mm_device_get_type (void); GType mm_device_get_type (void);
MMDevice *mm_device_new (GUdevDevice *udev_device, MMDevice *mm_device_new (GUdevDevice *udev_device);
MMPlugin *plugin);
void mm_device_grab_port (MMDevice *self, void mm_device_grab_port (MMDevice *self,
GUdevDevice *udev_port); GUdevDevice *udev_port);
@@ -66,6 +65,8 @@ void mm_device_remove_modem (MMDevice *self);
GUdevDevice *mm_device_peek_udev_device (MMDevice *self); GUdevDevice *mm_device_peek_udev_device (MMDevice *self);
GUdevDevice *mm_device_get_udev_device (MMDevice *self); GUdevDevice *mm_device_get_udev_device (MMDevice *self);
void mm_device_set_plugin (MMDevice *self,
MMPlugin *plugin);
MMPlugin *mm_device_peek_plugin (MMDevice *self); MMPlugin *mm_device_peek_plugin (MMDevice *self);
MMPlugin *mm_device_get_plugin (MMDevice *self); MMPlugin *mm_device_get_plugin (MMDevice *self);
MMBaseModem *mm_device_peek_modem (MMDevice *self); MMBaseModem *mm_device_peek_modem (MMDevice *self);

View File

@@ -173,8 +173,8 @@ find_port_support_ready_cb (MMPluginManager *plugin_manager,
if (!device) { if (!device) {
/* Create a generic device to track the available ports, and add it to the /* Create a generic device to track the available ports, and add it to the
* manager. */ * manager. */
device = mm_device_new (ctx->physical_device, device = mm_device_new (ctx->physical_device);
best_plugin); mm_device_set_plugin (device, best_plugin);
g_hash_table_insert (ctx->manager->priv->devices, g_hash_table_insert (ctx->manager->priv->devices,
g_strdup (g_udev_device_get_sysfs_path (mm_device_peek_udev_device (device))), g_strdup (g_udev_device_get_sysfs_path (mm_device_peek_udev_device (device))),
device); device);