Commit | Line | Data |
---|---|---|
6dc2ca62 MD |
1 | /* |
2 | * Common Trace Format | |
3 | * | |
4 | * Enumeration mapping strings (quarks) from/to integers. | |
5 | * | |
64fa3fec MD |
6 | * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation |
7 | * | |
8 | * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
6dc2ca62 | 9 | * |
ccd7e1c8 MD |
10 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
11 | * of this software and associated documentation files (the "Software"), to deal | |
12 | * in the Software without restriction, including without limitation the rights | |
13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
14 | * copies of the Software, and to permit persons to whom the Software is | |
15 | * furnished to do so, subject to the following conditions: | |
de0ba614 | 16 | * |
ccd7e1c8 MD |
17 | * The above copyright notice and this permission notice shall be included in |
18 | * all copies or substantial portions of the Software. | |
c462e188 MD |
19 | * |
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
26 | * SOFTWARE. | |
6dc2ca62 MD |
27 | */ |
28 | ||
d79865b9 | 29 | #include <babeltrace/ctf/types.h> |
7388fc97 | 30 | #include <inttypes.h> |
6dc2ca62 MD |
31 | #include <stdint.h> |
32 | #include <glib.h> | |
33 | ||
0d69b916 | 34 | int ctf_enum_read(struct bt_stream_pos *ppos, struct bt_definition *definition) |
448d3cc7 | 35 | { |
d11e9c49 MD |
36 | struct definition_enum *enum_definition = |
37 | container_of(definition, struct definition_enum, p); | |
38 | const struct declaration_enum *enum_declaration = | |
39 | enum_definition->declaration; | |
40 | struct definition_integer *integer_definition = | |
41 | enum_definition->integer; | |
42 | const struct declaration_integer *integer_declaration = | |
43 | integer_definition->declaration; | |
44 | GArray *qs; | |
c5e74408 | 45 | int ret; |
d11e9c49 | 46 | |
c5e74408 MD |
47 | ret = ctf_integer_read(ppos, &integer_definition->p); |
48 | if (ret) | |
49 | return ret; | |
7388fc97 | 50 | if (!integer_declaration->signedness) { |
2399b6f4 | 51 | qs = bt_enum_uint_to_quark_set(enum_declaration, |
d11e9c49 | 52 | integer_definition->value._unsigned); |
7388fc97 MD |
53 | if (!qs) { |
54 | fprintf(stderr, "[warning] Unknown value %" PRIu64 " in enum.\n", | |
55 | integer_definition->value._unsigned); | |
56 | } | |
57 | } else { | |
2399b6f4 | 58 | qs = bt_enum_int_to_quark_set(enum_declaration, |
d11e9c49 | 59 | integer_definition->value._signed); |
7388fc97 MD |
60 | if (!qs) { |
61 | fprintf(stderr, "[warning] Unknown value %" PRId64 " in enum.\n", | |
62 | integer_definition->value._signed); | |
63 | } | |
64 | } | |
d11e9c49 MD |
65 | /* unref previous quark set */ |
66 | if (enum_definition->value) | |
67 | g_array_unref(enum_definition->value); | |
68 | enum_definition->value = qs; | |
c5e74408 | 69 | return 0; |
448d3cc7 MD |
70 | } |
71 | ||
0d69b916 | 72 | int ctf_enum_write(struct bt_stream_pos *pos, struct bt_definition *definition) |
448d3cc7 | 73 | { |
d11e9c49 MD |
74 | struct definition_enum *enum_definition = |
75 | container_of(definition, struct definition_enum, p); | |
76 | struct definition_integer *integer_definition = | |
77 | enum_definition->integer; | |
448d3cc7 | 78 | |
c5e74408 | 79 | return ctf_integer_write(pos, &integer_definition->p); |
6dc2ca62 | 80 | } |