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. | |
6dc2ca62 MD |
19 | */ |
20 | ||
d79865b9 | 21 | #include <babeltrace/ctf/types.h> |
7388fc97 | 22 | #include <inttypes.h> |
6dc2ca62 MD |
23 | #include <stdint.h> |
24 | #include <glib.h> | |
25 | ||
c5e74408 | 26 | int ctf_enum_read(struct stream_pos *ppos, struct definition *definition) |
448d3cc7 | 27 | { |
d11e9c49 MD |
28 | struct definition_enum *enum_definition = |
29 | container_of(definition, struct definition_enum, p); | |
30 | const struct declaration_enum *enum_declaration = | |
31 | enum_definition->declaration; | |
32 | struct definition_integer *integer_definition = | |
33 | enum_definition->integer; | |
34 | const struct declaration_integer *integer_declaration = | |
35 | integer_definition->declaration; | |
36 | GArray *qs; | |
c5e74408 | 37 | int ret; |
d11e9c49 | 38 | |
c5e74408 MD |
39 | ret = ctf_integer_read(ppos, &integer_definition->p); |
40 | if (ret) | |
41 | return ret; | |
7388fc97 | 42 | if (!integer_declaration->signedness) { |
d11e9c49 MD |
43 | qs = enum_uint_to_quark_set(enum_declaration, |
44 | integer_definition->value._unsigned); | |
7388fc97 MD |
45 | if (!qs) { |
46 | fprintf(stderr, "[warning] Unknown value %" PRIu64 " in enum.\n", | |
47 | integer_definition->value._unsigned); | |
48 | } | |
49 | } else { | |
d11e9c49 MD |
50 | qs = enum_int_to_quark_set(enum_declaration, |
51 | integer_definition->value._signed); | |
7388fc97 MD |
52 | if (!qs) { |
53 | fprintf(stderr, "[warning] Unknown value %" PRId64 " in enum.\n", | |
54 | integer_definition->value._signed); | |
55 | } | |
56 | } | |
d11e9c49 MD |
57 | /* unref previous quark set */ |
58 | if (enum_definition->value) | |
59 | g_array_unref(enum_definition->value); | |
60 | enum_definition->value = qs; | |
c5e74408 | 61 | return 0; |
448d3cc7 MD |
62 | } |
63 | ||
c5e74408 | 64 | int ctf_enum_write(struct stream_pos *pos, struct definition *definition) |
448d3cc7 | 65 | { |
d11e9c49 MD |
66 | struct definition_enum *enum_definition = |
67 | container_of(definition, struct definition_enum, p); | |
68 | struct definition_integer *integer_definition = | |
69 | enum_definition->integer; | |
448d3cc7 | 70 | |
c5e74408 | 71 | return ctf_integer_write(pos, &integer_definition->p); |
6dc2ca62 | 72 | } |