/src/openvswitch/lib/uuid.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (c) 2008, 2009, 2010, 2016, 2017 Nicira, Inc. |
2 | | * |
3 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | * you may not use this file except in compliance with the License. |
5 | | * You may obtain a copy of the License at: |
6 | | * |
7 | | * http://www.apache.org/licenses/LICENSE-2.0 |
8 | | * |
9 | | * Unless required by applicable law or agreed to in writing, software |
10 | | * distributed under the License is distributed on an "AS IS" BASIS, |
11 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | * See the License for the specific language governing permissions and |
13 | | * limitations under the License. |
14 | | */ |
15 | | |
16 | | #ifndef UUID_H |
17 | | #define UUID_H 1 |
18 | | |
19 | | #include "openvswitch/uuid.h" |
20 | | |
21 | | #ifdef __cplusplus |
22 | | extern "C" { |
23 | | #endif |
24 | | |
25 | | /* An initializer or expression for an all-zero UUID. */ |
26 | 1.14k | #define UUID_ZERO ((struct uuid) { .parts = { 0, 0, 0, 0 } }) |
27 | | |
28 | | /* Formats a UUID as a string, in the conventional format. |
29 | | * |
30 | | * Example: |
31 | | * struct uuid uuid = ...; |
32 | | * printf("This UUID is "UUID_FMT"\n", UUID_ARGS(&uuid)); |
33 | | * |
34 | | */ |
35 | 96 | #define UUID_LEN 36 |
36 | 0 | #define UUID_FMT "%08x-%04x-%04x-%04x-%04x%08x" |
37 | | #define UUID_ARGS(UUID) \ |
38 | 0 | ((unsigned int) ((UUID)->parts[0])), \ |
39 | 0 | ((unsigned int) ((UUID)->parts[1] >> 16)), \ |
40 | 0 | ((unsigned int) ((UUID)->parts[1] & 0xffff)), \ |
41 | 0 | ((unsigned int) ((UUID)->parts[2] >> 16)), \ |
42 | 0 | ((unsigned int) ((UUID)->parts[2] & 0xffff)), \ |
43 | 0 | ((unsigned int) ((UUID)->parts[3])) |
44 | | |
45 | | /* Returns a hash value for 'uuid'. This hash value is the same regardless of |
46 | | * whether we are running on a 32-bit or 64-bit or big-endian or little-endian |
47 | | * architecture. */ |
48 | | static inline size_t |
49 | | uuid_hash(const struct uuid *uuid) |
50 | 0 | { |
51 | 0 | return uuid->parts[0]; |
52 | 0 | } Unexecuted instantiation: odp-util.c:uuid_hash Unexecuted instantiation: uuid.c:uuid_hash Unexecuted instantiation: json.c:uuid_hash Unexecuted instantiation: ofp-print.c:uuid_hash Unexecuted instantiation: ofp-prop.c:uuid_hash Unexecuted instantiation: ofp-util.c:uuid_hash Unexecuted instantiation: smap.c:uuid_hash Unexecuted instantiation: dpif.c:uuid_hash Unexecuted instantiation: ofp-packet.c:uuid_hash Unexecuted instantiation: userspace-tso.c:uuid_hash Unexecuted instantiation: dpif-netdev.c:uuid_hash Unexecuted instantiation: dpdk-stub.c:uuid_hash Unexecuted instantiation: vswitch-idl.c:uuid_hash Unexecuted instantiation: ovsdb-data.c:uuid_hash Unexecuted instantiation: ovsdb-idl.c:uuid_hash Unexecuted instantiation: ovsdb-map-op.c:uuid_hash Unexecuted instantiation: ovsdb-set-op.c:uuid_hash Unexecuted instantiation: ovsdb-types.c:uuid_hash Unexecuted instantiation: ovsdb-cs.c:uuid_hash Unexecuted instantiation: ovsdb-session.c:uuid_hash |
53 | | |
54 | | /* Returns true if 'a == b', false otherwise. */ |
55 | | static inline bool |
56 | | uuid_equals(const struct uuid *a, const struct uuid *b) |
57 | 0 | { |
58 | 0 | return (a->parts[0] == b->parts[0] |
59 | 0 | && a->parts[1] == b->parts[1] |
60 | 0 | && a->parts[2] == b->parts[2] |
61 | 0 | && a->parts[3] == b->parts[3]); |
62 | 0 | } Unexecuted instantiation: odp-util.c:uuid_equals Unexecuted instantiation: uuid.c:uuid_equals Unexecuted instantiation: json.c:uuid_equals Unexecuted instantiation: ofp-print.c:uuid_equals Unexecuted instantiation: ofp-prop.c:uuid_equals Unexecuted instantiation: ofp-util.c:uuid_equals Unexecuted instantiation: smap.c:uuid_equals Unexecuted instantiation: dpif.c:uuid_equals Unexecuted instantiation: ofp-packet.c:uuid_equals Unexecuted instantiation: userspace-tso.c:uuid_equals Unexecuted instantiation: dpif-netdev.c:uuid_equals Unexecuted instantiation: dpdk-stub.c:uuid_equals Unexecuted instantiation: vswitch-idl.c:uuid_equals Unexecuted instantiation: ovsdb-data.c:uuid_equals Unexecuted instantiation: ovsdb-idl.c:uuid_equals Unexecuted instantiation: ovsdb-map-op.c:uuid_equals Unexecuted instantiation: ovsdb-set-op.c:uuid_equals Unexecuted instantiation: ovsdb-types.c:uuid_equals Unexecuted instantiation: ovsdb-cs.c:uuid_equals Unexecuted instantiation: ovsdb-session.c:uuid_equals |
63 | | |
64 | | /* Returns the first 'n' hex digits of 'uuid', for 0 < 'n' <= 8. |
65 | | * |
66 | | * This is useful for displaying a few leading digits of the uuid, e.g. to |
67 | | * display 4 digits: |
68 | | * printf("%04x", uuid_prefix(uuid, 4)); |
69 | | */ |
70 | | static inline unsigned int |
71 | | uuid_prefix(const struct uuid *uuid, int digits) |
72 | 0 | { |
73 | 0 | return (uuid->parts[0] >> (32 - 4 * digits)); |
74 | 0 | } Unexecuted instantiation: odp-util.c:uuid_prefix Unexecuted instantiation: uuid.c:uuid_prefix Unexecuted instantiation: json.c:uuid_prefix Unexecuted instantiation: ofp-print.c:uuid_prefix Unexecuted instantiation: ofp-prop.c:uuid_prefix Unexecuted instantiation: ofp-util.c:uuid_prefix Unexecuted instantiation: smap.c:uuid_prefix Unexecuted instantiation: dpif.c:uuid_prefix Unexecuted instantiation: ofp-packet.c:uuid_prefix Unexecuted instantiation: userspace-tso.c:uuid_prefix Unexecuted instantiation: dpif-netdev.c:uuid_prefix Unexecuted instantiation: dpdk-stub.c:uuid_prefix Unexecuted instantiation: vswitch-idl.c:uuid_prefix Unexecuted instantiation: ovsdb-data.c:uuid_prefix Unexecuted instantiation: ovsdb-idl.c:uuid_prefix Unexecuted instantiation: ovsdb-map-op.c:uuid_prefix Unexecuted instantiation: ovsdb-set-op.c:uuid_prefix Unexecuted instantiation: ovsdb-types.c:uuid_prefix Unexecuted instantiation: ovsdb-cs.c:uuid_prefix Unexecuted instantiation: ovsdb-session.c:uuid_prefix |
75 | | |
76 | | void uuid_init(void); |
77 | | void uuid_generate(struct uuid *); |
78 | | struct uuid uuid_random(void); |
79 | | void uuid_zero(struct uuid *); |
80 | | bool uuid_is_zero(const struct uuid *); |
81 | | int uuid_compare_3way(const struct uuid *, const struct uuid *); |
82 | | bool uuid_from_string(struct uuid *, const char *); |
83 | | bool uuid_from_string_prefix(struct uuid *, const char *); |
84 | | int uuid_is_partial_string(const char *); |
85 | | int uuid_is_partial_match(const struct uuid *, const char *match); |
86 | | void uuid_set_bits_v4(struct uuid *); |
87 | | |
88 | | #ifdef __cplusplus |
89 | | } |
90 | | #endif |
91 | | |
92 | | #endif /* uuid.h */ |