2021-07-08 06:25:50

by Yun-hao Chung

[permalink] [raw]
Subject: [Bluez PATCH v1 01/14] lib: add hash functions for bt_uuid_t

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.

Reviewed-by: Miao-chen Chou <[email protected]>
---

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


2021-07-08 06:37:04

by bluez.test.bot

[permalink] [raw]
Subject: RE: [Bluez,v1,01/14] lib: add hash functions for bt_uuid_t

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=512335

---Test result---

Test Summary:
CheckPatch FAIL 3.75 seconds
GitLint PASS 1.46 seconds
Prep - Setup ELL PASS 40.49 seconds
Build - Prep PASS 0.10 seconds
Build - Configure PASS 7.11 seconds
Build - Make FAIL 65.27 seconds
Make Check FAIL 0.32 seconds
Make Distcheck FAIL 84.18 seconds
Build w/ext ELL - Configure PASS 7.17 seconds
Build w/ext ELL - Make FAIL 54.38 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script with rule in .checkpatch.conf
Output:
plugins/admin_policy: add ServiceAllowList property
ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
#62: FILE: plugins/admin_policy.c:185:
+ const GDBusPropertyTable *property,
^

- total: 1 errors, 0 warnings, 81 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

"[PATCH] plugins/admin_policy: add ServiceAllowList property" has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

plugins/admin_policy: add AffectedByPolicy property
ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
#65: FILE: plugins/admin_policy.c:294:
+ const GDBusPropertyTable *property,
^

- total: 1 errors, 0 warnings, 133 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

"[PATCH] plugins/admin_policy: add AffectedByPolicy property" has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

plugins/admin_policy: persist policy settings
WARNING:LINE_SPACING: Missing a blank line after declarations
#153: FILE: plugins/admin_policy.c:334:
+ struct queue *uuid_list = NULL;
+ gchar **uuids = NULL;

- total: 0 errors, 1 warnings, 207 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

"[PATCH] plugins/admin_policy: persist policy settings" has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: GitLint - PASS
Desc: Run gitlint with rule in .gitlint

##############################
Test: Prep - Setup ELL - PASS
Desc: Clone, build, and install ELL

##############################
Test: Build - Prep - PASS
Desc: Prepare environment for build

##############################
Test: Build - Configure - PASS
Desc: Configure the BlueZ source tree

##############################
Test: Build - Make - FAIL
Desc: Build the BlueZ source tree
Output:
/usr/bin/ld: lib/.libs/libbluetooth-internal.a(uuid.o): in function `bt_uuid_hash':
/github/workspace/src/lib/uuid.c:136: undefined reference to `g_int64_hash'
/usr/bin/ld: /github/workspace/src/lib/uuid.c:136: undefined reference to `g_int64_hash'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:5351: peripheral/btsensor] Error 1
make: *** [Makefile:4140: all] Error 2


##############################
Test: Make Check - FAIL
Desc: Run 'make check'
Output:
/usr/bin/ld: lib/.libs/libbluetooth-internal.a(uuid.o): in function `bt_uuid_hash':
/github/workspace/src/lib/uuid.c:136: undefined reference to `g_int64_hash'
/usr/bin/ld: /github/workspace/src/lib/uuid.c:136: undefined reference to `g_int64_hash'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:5351: peripheral/btsensor] Error 1
make: *** [Makefile:10429: check] Error 2


##############################
Test: Make Distcheck - FAIL
Desc: Run distcheck to check the distribution
Output:
/usr/bin/ld: lib/.libs/libbluetooth-internal.a(uuid.o): in function `bt_uuid_hash':
/github/workspace/src/bluez-5.60/_build/sub/../../lib/uuid.c:136: undefined reference to `g_int64_hash'
/usr/bin/ld: /github/workspace/src/bluez-5.60/_build/sub/../../lib/uuid.c:136: undefined reference to `g_int64_hash'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:5692: tools/btgatt-client] Error 1
make[1]: *** [Makefile:4140: all] Error 2
make: *** [Makefile:10350: distcheck] Error 1


##############################
Test: Build w/ext ELL - Configure - PASS
Desc: Configure BlueZ source with '--enable-external-ell' configuration

##############################
Test: Build w/ext ELL - Make - FAIL
Desc: Build BlueZ source with '--enable-external-ell' configuration
Output:
/usr/bin/ld: lib/.libs/libbluetooth-internal.a(uuid.o): in function `bt_uuid_hash':
/github/workspace/src2/lib/uuid.c:136: undefined reference to `g_int64_hash'
/usr/bin/ld: /github/workspace/src2/lib/uuid.c:136: undefined reference to `g_int64_hash'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:5351: peripheral/btsensor] Error 1
make: *** [Makefile:4140: all] Error 2




---
Regards,
Linux Bluetooth

2021-07-09 05:24:17

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [Bluez PATCH v1 01/14] lib: add hash functions for bt_uuid_t

Hi Howard,

On Wed, Jul 7, 2021 at 11:23 PM Howard Chung <[email protected]> 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 <[email protected]>
> ---
>
> 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

2021-07-12 03:23:04

by Yun-hao Chung

[permalink] [raw]
Subject: Re: [Bluez PATCH v1 01/14] lib: add hash functions for bt_uuid_t

Got it. Will move bt_uuid_hash and bt_uuid_equal to src/adapter.c

On Fri, Jul 9, 2021 at 1:21 PM Luiz Augusto von Dentz
<[email protected]> wrote:
>
> Hi Howard,
>
> On Wed, Jul 7, 2021 at 11:23 PM Howard Chung <[email protected]> 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 <[email protected]>
> > ---
> >
> > 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