Commit | Line | Data |
---|---|---|
6dc2ca62 MD |
1 | /* |
2 | * Common Trace Format | |
3 | * | |
4 | * Enumeration mapping strings (quarks) from/to integers. | |
5 | * | |
c054553d | 6 | * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
6dc2ca62 | 7 | * |
ccd7e1c8 MD |
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | * of this software and associated documentation files (the "Software"), to deal | |
10 | * in the Software without restriction, including without limitation the rights | |
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
12 | * copies of the Software, and to permit persons to whom the Software is | |
13 | * furnished to do so, subject to the following conditions: | |
de0ba614 | 14 | * |
ccd7e1c8 MD |
15 | * The above copyright notice and this permission notice shall be included in |
16 | * all copies or substantial portions of the Software. | |
6dc2ca62 MD |
17 | */ |
18 | ||
d79865b9 | 19 | #include <babeltrace/ctf/types.h> |
6dc2ca62 MD |
20 | #include <stdint.h> |
21 | #include <glib.h> | |
22 | ||
c5e74408 | 23 | int ctf_enum_read(struct stream_pos *ppos, struct definition *definition) |
448d3cc7 | 24 | { |
d11e9c49 MD |
25 | struct definition_enum *enum_definition = |
26 | container_of(definition, struct definition_enum, p); | |
27 | const struct declaration_enum *enum_declaration = | |
28 | enum_definition->declaration; | |
29 | struct definition_integer *integer_definition = | |
30 | enum_definition->integer; | |
31 | const struct declaration_integer *integer_declaration = | |
32 | integer_definition->declaration; | |
33 | GArray *qs; | |
c5e74408 | 34 | int ret; |
d11e9c49 | 35 | |
c5e74408 MD |
36 | ret = ctf_integer_read(ppos, &integer_definition->p); |
37 | if (ret) | |
38 | return ret; | |
d11e9c49 MD |
39 | if (!integer_declaration->signedness) |
40 | qs = enum_uint_to_quark_set(enum_declaration, | |
41 | integer_definition->value._unsigned); | |
42 | else | |
43 | qs = enum_int_to_quark_set(enum_declaration, | |
44 | integer_definition->value._signed); | |
45 | assert(qs); | |
46 | /* unref previous quark set */ | |
47 | if (enum_definition->value) | |
48 | g_array_unref(enum_definition->value); | |
49 | enum_definition->value = qs; | |
c5e74408 | 50 | return 0; |
448d3cc7 MD |
51 | } |
52 | ||
c5e74408 | 53 | int ctf_enum_write(struct stream_pos *pos, struct definition *definition) |
448d3cc7 | 54 | { |
d11e9c49 MD |
55 | struct definition_enum *enum_definition = |
56 | container_of(definition, struct definition_enum, p); | |
57 | struct definition_integer *integer_definition = | |
58 | enum_definition->integer; | |
448d3cc7 | 59 | |
c5e74408 | 60 | return ctf_integer_write(pos, &integer_definition->p); |
6dc2ca62 | 61 | } |