base-modem: set dbus id as soon as object is created

This commit is contained in:
Aleksander Morgado
2020-03-28 16:31:01 +01:00
parent 850d302d24
commit 9e50dda400
3 changed files with 16 additions and 3 deletions

View File

@@ -61,6 +61,7 @@ static GParamSpec *properties[PROP_LAST];
struct _MMBaseModemPrivate {
/* The connection to the system bus */
GDBusConnection *connection;
guint dbus_id;
/* Modem-wide cancellable. If it ever gets cancelled, no further operations
* should be done by the modem. */
@@ -113,6 +114,12 @@ struct _MMBaseModemPrivate {
#endif
};
guint
mm_base_modem_get_dbus_id (MMBaseModem *self)
{
return self->priv->dbus_id;
}
static gchar *
get_hash_key (const gchar *subsys,
const gchar *name)
@@ -1518,11 +1525,16 @@ teardown_ports_table (MMBaseModem *self)
static void
mm_base_modem_init (MMBaseModem *self)
{
static guint id = 0;
/* Initialize private data */
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
MM_TYPE_BASE_MODEM,
MMBaseModemPrivate);
/* Each modem is given a unique id to build its own DBus path */
self->priv->dbus_id = id++;
/* Setup authorization provider */
self->priv->authp = mm_auth_provider_get ();
self->priv->authp_cancellable = g_cancellable_new ();

View File

@@ -105,6 +105,8 @@ struct _MMBaseModemClass {
GType mm_base_modem_get_type (void);
guint mm_base_modem_get_dbus_id (MMBaseModem *self);
gboolean mm_base_modem_grab_port (MMBaseModem *self,
MMKernelDevice *kernel_device,
MMPortType ptype,

View File

@@ -251,8 +251,7 @@ static void
export_modem (MMDevice *self)
{
GDBusConnection *connection = NULL;
static guint32 id = 0;
gchar *path;
gchar *path;
g_assert (MM_IS_BASE_MODEM (self->priv->modem));
g_assert (G_IS_DBUS_OBJECT_MANAGER (self->priv->object_manager));
@@ -275,7 +274,7 @@ export_modem (MMDevice *self)
/* No outstanding port tasks, so if the modem is valid we can export it */
path = g_strdup_printf (MM_DBUS_MODEM_PREFIX "/%d", id++);
path = g_strdup_printf (MM_DBUS_MODEM_PREFIX "/%d", mm_base_modem_get_dbus_id (self->priv->modem));
g_object_get (self->priv->object_manager,
"connection", &connection,
NULL);