From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: Howard Chung <howardchung@google.com>
Cc: "linux-bluetooth@vger.kernel.org"
<linux-bluetooth@vger.kernel.org>,
Miao-chen Chou <mcchou@chromium.org>
Subject: Re: [Bluez PATCH v1 01/14] lib: add hash functions for bt_uuid_t
Date: Thu, 8 Jul 2021 22:21:04 -0700 [thread overview]
Message-ID: <CABBYNZKjc+2ur81SR2_jTiba6SgxNQh9piXqhmfKro511=QN8Q@mail.gmail.com> (raw)
In-Reply-To: <20210708142059.Bluez.v1.1.I69278fab3bf86adb578c5cba0a39e5bcf7f9581e@changeid>
Hi Howard,
On Wed, Jul 7, 2021 at 11:23 PM Howard Chung <howardchung@google.com> wrote:
>
> This adds function GHashFunc and GEqualFunc for bt_uuid_t.
> With these functions, we can add uuids into a GHashTable with bt_uuid_t
> format.
We will likely move away from GLib dependency so I wouldn't want to
introduce a dependency to it specially as part of libbluetooth.
> Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
> ---
>
> lib/uuid.c | 27 +++++++++++++++++++++++++++
> lib/uuid.h | 3 +++
> 2 files changed, 30 insertions(+)
>
> diff --git a/lib/uuid.c b/lib/uuid.c
> index 3d97dc8359c7..a09f5c428b87 100644
> --- a/lib/uuid.c
> +++ b/lib/uuid.c
> @@ -16,6 +16,7 @@
> #include <string.h>
> #include <stdlib.h>
> #include <errno.h>
> +#include <glib.h>
>
> #include "lib/bluetooth.h"
> #include "uuid.h"
> @@ -120,6 +121,32 @@ int bt_uuid_cmp(const bt_uuid_t *uuid1, const bt_uuid_t *uuid2)
> return bt_uuid128_cmp(&u1, &u2);
> }
>
> +guint bt_uuid_hash(gconstpointer key)
> +{
> + const bt_uuid_t *uuid = key;
> + bt_uuid_t uuid_128;
> + uint64_t *val;
> +
> + if (!uuid)
> + return 0;
> +
> + bt_uuid_to_uuid128(uuid, &uuid_128);
> + val = (uint64_t *)&uuid_128.value.u128;
> +
> + return g_int64_hash(val) ^ g_int64_hash(val+1);
> +}
> +
> +gboolean bt_uuid_equal(gconstpointer v1, gconstpointer v2)
> +{
> + const bt_uuid_t *uuid1 = v1;
> + const bt_uuid_t *uuid2 = v2;
> +
> + if (!uuid1 || !uuid2)
> + return !uuid1 && !uuid2;
> +
> + return bt_uuid_cmp(uuid1, uuid2) == 0;
> +}
> +
> /*
> * convert the UUID to string, copying a maximum of n characters.
> */
> diff --git a/lib/uuid.h b/lib/uuid.h
> index 1a4029b68730..e47ccccb9fd2 100644
> --- a/lib/uuid.h
> +++ b/lib/uuid.h
> @@ -17,6 +17,7 @@ extern "C" {
> #endif
>
> #include <stdint.h>
> +#include <glib.h>
>
> #define GENERIC_AUDIO_UUID "00001203-0000-1000-8000-00805f9b34fb"
>
> @@ -167,6 +168,8 @@ int bt_uuid128_create(bt_uuid_t *btuuid, uint128_t value);
>
> int bt_uuid_cmp(const bt_uuid_t *uuid1, const bt_uuid_t *uuid2);
> void bt_uuid_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst);
> +guint bt_uuid_hash(gconstpointer key);
> +gboolean bt_uuid_equal(gconstpointer v1, gconstpointer v2);
>
> #define MAX_LEN_UUID_STR 37
>
> --
> 2.32.0.93.g670b81a890-goog
>
--
Luiz Augusto von Dentz
next prev parent reply other threads:[~2021-07-09 5:21 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-08 6:23 [Bluez PATCH v1 00/14] Howard Chung
2021-07-08 6:23 ` [Bluez PATCH v1 01/14] lib: add hash functions for bt_uuid_t Howard Chung
2021-07-08 6:36 ` [Bluez,v1,01/14] " bluez.test.bot
2021-07-09 5:21 ` Luiz Augusto von Dentz [this message]
2021-07-12 3:20 ` [Bluez PATCH v1 01/14] " Yun-hao Chung
2021-07-08 6:23 ` [Bluez PATCH v1 02/14] unit: add uuid unit tests Howard Chung
2021-07-08 6:23 ` [Bluez PATCH v1 03/14] core: add is_allowed property in btd_service Howard Chung
2021-07-08 6:23 ` [Bluez PATCH v1 04/14] core: add adapter and device allowed_uuid functions Howard Chung
2021-07-08 6:23 ` [Bluez PATCH v1 05/14] core: add device state and state callbacks Howard Chung
2021-07-09 5:34 ` Luiz Augusto von Dentz
2021-07-12 3:56 ` Yun-hao Chung
2021-07-08 6:23 ` [Bluez PATCH v1 06/14] audio: Remove Media1 interface when a2dp source disallowed Howard Chung
2021-07-09 5:49 ` Luiz Augusto von Dentz
2021-07-12 8:16 ` Yun-hao Chung
2021-07-12 16:37 ` Luiz Augusto von Dentz
2021-07-08 6:23 ` [Bluez PATCH v1 07/14] plugins: add a new plugin for admin_policy Howard Chung
2021-07-08 6:23 ` [Bluez PATCH v1 08/14] plugins/admin_policy: add admin_policy adapter driver Howard Chung
2021-07-08 6:23 ` [Bluez PATCH v1 09/14] plugins/admin_policy: add ServiceAllowList method Howard Chung
2021-07-09 6:01 ` Luiz Augusto von Dentz
2021-07-12 9:09 ` Yun-hao Chung
2021-07-12 16:41 ` Luiz Augusto von Dentz
2021-07-08 6:23 ` [Bluez PATCH v1 10/14] plugins/admin_policy: add ServiceAllowList property Howard Chung
2021-07-08 6:23 ` [Bluez PATCH v1 11/14] plugins/admin_policy: add device state callback Howard Chung
2021-07-08 6:23 ` [Bluez PATCH v1 12/14] plugins/admin_policy: add AffectedByPolicy property Howard Chung
2021-07-08 6:23 ` [Bluez PATCH v1 13/14] plugins/admin_policy: persist policy settings Howard Chung
2021-07-08 6:23 ` [Bluez PATCH v1 14/14] core: fix a possible crash when removing devices Howard Chung
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABBYNZKjc+2ur81SR2_jTiba6SgxNQh9piXqhmfKro511=QN8Q@mail.gmail.com' \
--to=luiz.dentz@gmail.com \
--cc=howardchung@google.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=mcchou@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).