Commit | Line | Data |
---|---|---|
d126826c MJ |
1 | #ifndef _BABELTRACE_COMMON_UUID_H |
2 | #define _BABELTRACE_COMMON_UUID_H | |
3 | ||
4 | /* | |
5 | * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com> | |
6 | * | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
23 | * SOFTWARE. | |
24 | */ | |
25 | ||
26 | #include <stdint.h> | |
27 | #include "common/macros.h" | |
28 | ||
29 | #define BT_UUID_STR_LEN 36 /* Excludes final \0 */ | |
30 | #define BT_UUID_LEN 16 | |
31 | #define BT_UUID_VER 4 | |
32 | ||
33 | #define BT_UUID_FMT \ | |
34 | "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "-%02" SCNx8 \ | |
35 | "%02" SCNx8 "-%02" SCNx8 "%02" SCNx8 "-%02" SCNx8 "%02" SCNx8 \ | |
36 | "-%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 \ | |
37 | "%02" SCNx8 | |
38 | ||
39 | #define BT_UUID_FMT_VALUES(uuid) \ | |
40 | (uuid)[0], (uuid)[1], (uuid)[2], (uuid)[3], (uuid)[4], (uuid)[5], \ | |
41 | (uuid)[6], (uuid)[7], (uuid)[8], (uuid)[9], (uuid)[10], (uuid)[11], \ | |
42 | (uuid)[12], (uuid)[13], (uuid)[14], (uuid)[15] | |
43 | ||
44 | #define BT_UUID_SCAN_VALUES(uuid) \ | |
45 | &(uuid)[0], &(uuid)[1], &(uuid)[2], &(uuid)[3], &(uuid)[4], &(uuid)[5], \ | |
46 | &(uuid)[6], &(uuid)[7], &(uuid)[8], &(uuid)[9], &(uuid)[10], &(uuid)[11], \ | |
47 | &(uuid)[12], &(uuid)[13], &(uuid)[14], &(uuid)[15] | |
48 | ||
49 | typedef uint8_t bt_uuid_t[BT_UUID_LEN]; | |
50 | ||
51 | BT_HIDDEN void bt_uuid_generate(bt_uuid_t uuid_out); | |
52 | BT_HIDDEN void bt_uuid_to_str(const bt_uuid_t uuid_in, char *str_out); | |
53 | BT_HIDDEN int bt_uuid_from_str(const char *str_in, bt_uuid_t uuid_out); | |
54 | BT_HIDDEN int bt_uuid_compare(const bt_uuid_t uuid_a, const bt_uuid_t uuid_b); | |
55 | BT_HIDDEN void bt_uuid_copy(bt_uuid_t uuid_dest, const bt_uuid_t uuid_src); | |
56 | ||
57 | #endif /* _BABELTRACE_COMMON_UUID_H */ |