From: David Zeuthen Date: Mon, 3 Oct 2011 20:04:55 +0000 (-0400) Subject: UDisksClient: add get_object() and peek_object() convenience methods X-Git-Tag: upstream/2.1.2~464 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=820370b7d7b86f8e10c1b78f373c6f7a81fa9349;p=platform%2Fupstream%2Fudisks2.git UDisksClient: add get_object() and peek_object() convenience methods Signed-off-by: David Zeuthen --- diff --git a/doc/udisks2-sections.txt b/doc/udisks2-sections.txt index cbab86d..1eb3a98 100644 --- a/doc/udisks2-sections.txt +++ b/doc/udisks2-sections.txt @@ -38,6 +38,8 @@ UDisksClient udisks_client_new udisks_client_new_finish udisks_client_new_sync +udisks_client_get_object +udisks_client_peek_object udisks_client_get_object_manager udisks_client_get_manager udisks_client_settle diff --git a/udisks/udisksclient.c b/udisks/udisksclient.c index 7b467ca..7906023 100644 --- a/udisks/udisksclient.c +++ b/udisks/udisksclient.c @@ -469,6 +469,52 @@ udisks_client_settle (UDisksClient *client) ; } +/* ---------------------------------------------------------------------------------------------------- */ + +/** + * udisks_client_get_object: + * @client: A #UDisksClient. + * @object_path: Object path. + * + * Convenience function for looking up an #UDisksObject for @object_path. + * + * Returns: (transfer full): A #UDisksObject corresponding to + * @object_path or %NULL if not found. The returned object must be + * freed with g_object_unref(). + */ +UDisksObject * +udisks_client_get_object (UDisksClient *client, + const gchar *object_path) +{ + g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL); + return (UDisksObject *) g_dbus_object_manager_get_object (client->object_manager, object_path); +} + +/** + * udisks_client_peek_object: + * @client: A #UDisksClient. + * @object_path: Object path. + * + * Like udisks_client_get_object() but doesn't increase the reference + * count on the returned #UDisksObject. + * + * The returned object is only valid until removed so it is only safe to use this function on the thread where @client was constructed. Use udisks_client_get_object() if on another thread. + * + * Returns: (transfer none): A #UDisksObject corresponding to + * @object_path or %NULL if not found. + */ +UDisksObject * +udisks_client_peek_object (UDisksClient *client, + const gchar *object_path) +{ + UDisksObject *ret; + ret = udisks_client_get_object (client, object_path); + if (ret != NULL) + g_object_unref (ret); + return ret; +} + +/* ---------------------------------------------------------------------------------------------------- */ static GList * get_top_level_blocks_for_drive (UDisksClient *client, diff --git a/udisks/udisksclient.h b/udisks/udisksclient.h index 26f4a83..532696c 100644 --- a/udisks/udisksclient.h +++ b/udisks/udisksclient.h @@ -46,6 +46,11 @@ GDBusObjectManager *udisks_client_get_object_manager (UDisksClient *clien UDisksManager *udisks_client_get_manager (UDisksClient *client); void udisks_client_settle (UDisksClient *client); +UDisksObject *udisks_client_get_object (UDisksClient *client, + const gchar *object_path); +UDisksObject *udisks_client_peek_object (UDisksClient *client, + const gchar *object_path); + UDisksBlock *udisks_client_get_block_for_drive (UDisksClient *client, UDisksDrive *drive, gboolean get_physical);