| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef BABELTRACE_COMMON_UUID_H |
| 8 | #define BABELTRACE_COMMON_UUID_H |
| 9 | |
| 10 | #include <inttypes.h> |
| 11 | #include <stdint.h> |
| 12 | #include "common/macros.h" |
| 13 | |
| 14 | #ifdef __cplusplus |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
| 18 | #define BT_UUID_STR_LEN 36 /* Excludes final \0 */ |
| 19 | #define BT_UUID_LEN 16 |
| 20 | #define BT_UUID_VER 4 |
| 21 | |
| 22 | #define BT_UUID_FMT \ |
| 23 | "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "-%02" SCNx8 \ |
| 24 | "%02" SCNx8 "-%02" SCNx8 "%02" SCNx8 "-%02" SCNx8 "%02" SCNx8 \ |
| 25 | "-%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 \ |
| 26 | "%02" SCNx8 |
| 27 | |
| 28 | #define BT_UUID_FMT_VALUES(uuid) \ |
| 29 | (uuid)[0], (uuid)[1], (uuid)[2], (uuid)[3], (uuid)[4], (uuid)[5], \ |
| 30 | (uuid)[6], (uuid)[7], (uuid)[8], (uuid)[9], (uuid)[10], (uuid)[11], \ |
| 31 | (uuid)[12], (uuid)[13], (uuid)[14], (uuid)[15] |
| 32 | |
| 33 | #define BT_UUID_SCAN_VALUES(uuid) \ |
| 34 | &(uuid)[0], &(uuid)[1], &(uuid)[2], &(uuid)[3], &(uuid)[4], &(uuid)[5], \ |
| 35 | &(uuid)[6], &(uuid)[7], &(uuid)[8], &(uuid)[9], &(uuid)[10], &(uuid)[11], \ |
| 36 | &(uuid)[12], &(uuid)[13], &(uuid)[14], &(uuid)[15] |
| 37 | |
| 38 | typedef uint8_t bt_uuid_t[BT_UUID_LEN]; |
| 39 | |
| 40 | void bt_uuid_generate(bt_uuid_t uuid_out); |
| 41 | void bt_uuid_to_str(const bt_uuid_t uuid_in, char *str_out); |
| 42 | int bt_uuid_from_c_str(const char *str, bt_uuid_t uuid_out); |
| 43 | int bt_uuid_from_str(const char *begin, const char *end, bt_uuid_t uuid_out); |
| 44 | int bt_uuid_compare(const bt_uuid_t uuid_a, const bt_uuid_t uuid_b); |
| 45 | void bt_uuid_copy(bt_uuid_t uuid_dest, const bt_uuid_t uuid_src); |
| 46 | |
| 47 | #ifdef __cplusplus |
| 48 | } |
| 49 | #endif |
| 50 | |
| 51 | #endif /* BABELTRACE_COMMON_UUID_H */ |