diff options
author | Richard Hughes <richard@hughsie.com> | 2010-03-30 14:26:54 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2010-03-30 14:26:54 +0100 |
commit | 2c94682f1455a69f532faf8a3bb7e06241e53d8b (patch) | |
tree | 33cafe8f186413d3e376fd029d9bee54b6f5af37 | |
parent | 3d627783770c9674d44b9af84389e06dc5bb9169 (diff) |
Do not allow client programs to enumerate the device list more than once
-rw-r--r-- | libupower-glib/up-client.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libupower-glib/up-client.c b/libupower-glib/up-client.c index 12201cd..e92d0e9 100644 --- a/libupower-glib/up-client.c +++ b/libupower-glib/up-client.c @@ -64,6 +64,7 @@ struct _UpClientPrivate gboolean on_battery; gboolean on_low_battery; gboolean lid_is_present; + gboolean done_enumerate; }; enum { @@ -116,6 +117,8 @@ up_client_get_device (UpClient *client, const gchar *object_path) * @client: a #UpClient instance. * * Get a copy of the device objects. + * You must have called up_client_enumerate_devices_sync() before calling this + * function. * * Return value: an array of #UpDevice objects, free with g_ptr_array_unref() * @@ -124,6 +127,8 @@ up_client_get_device (UpClient *client, const gchar *object_path) GPtrArray * up_client_get_devices (UpClient *client) { + g_return_val_if_fail (UP_IS_CLIENT (client), NULL); + g_return_val_if_fail (client->priv->done_enumerate, NULL); return g_ptr_array_ref (client->priv->array); } @@ -818,6 +823,10 @@ up_client_enumerate_devices_sync (UpClient *client, GCancellable *cancellable, G guint i; gboolean ret = TRUE; + /* already done */ + if (client->priv->done_enumerate) + goto out; + /* coldplug */ devices = up_client_get_devices_private (client, error); if (devices == NULL) { @@ -828,6 +837,9 @@ up_client_enumerate_devices_sync (UpClient *client, GCancellable *cancellable, G object_path = (const gchar *) g_ptr_array_index (devices, i); up_client_add (client, object_path); } + + /* only do this once per instance */ + client->priv->done_enumerate = TRUE; out: return ret; } @@ -844,6 +856,7 @@ up_client_init (UpClient *client) client->priv = UP_CLIENT_GET_PRIVATE (client); client->priv->array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); client->priv->have_properties = FALSE; + client->priv->done_enumerate = FALSE; /* get on the bus */ client->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); |