| 1 |
/* |
| 2 |
* Common Trace Format |
| 3 |
* |
| 4 |
* Enumeration mapping strings (quarks) from/to integers. |
| 5 |
* |
| 6 |
* Copyright 2010-2011 EfficiOS Inc. and Linux Foundation |
| 7 |
* |
| 8 |
* Author: Mathieu Desnoyers <[email protected]> |
| 9 |
* |
| 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: |
| 16 |
* |
| 17 |
* The above copyright notice and this permission notice shall be included in |
| 18 |
* all copies or substantial portions of the Software. |
| 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. |
| 27 |
*/ |
| 28 |
|
| 29 |
#include <babeltrace/ctf/types.h> |
| 30 |
#include <inttypes.h> |
| 31 |
#include <stdint.h> |
| 32 |
#include <glib.h> |
| 33 |
|
| 34 |
int ctf_enum_read(struct bt_stream_pos *ppos, struct bt_definition *definition) |
| 35 |
{ |
| 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; |
| 45 |
int ret; |
| 46 |
|
| 47 |
ret = ctf_integer_read(ppos, &integer_definition->p); |
| 48 |
if (ret) |
| 49 |
return ret; |
| 50 |
if (!integer_declaration->signedness) { |
| 51 |
qs = bt_enum_uint_to_quark_set(enum_declaration, |
| 52 |
integer_definition->value._unsigned); |
| 53 |
if (!qs) { |
| 54 |
fprintf(stderr, "[warning] Unknown value %" PRIu64 " in enum.\n", |
| 55 |
integer_definition->value._unsigned); |
| 56 |
} |
| 57 |
} else { |
| 58 |
qs = bt_enum_int_to_quark_set(enum_declaration, |
| 59 |
integer_definition->value._signed); |
| 60 |
if (!qs) { |
| 61 |
fprintf(stderr, "[warning] Unknown value %" PRId64 " in enum.\n", |
| 62 |
integer_definition->value._signed); |
| 63 |
} |
| 64 |
} |
| 65 |
/* unref previous quark set */ |
| 66 |
if (enum_definition->value) |
| 67 |
g_array_unref(enum_definition->value); |
| 68 |
enum_definition->value = qs; |
| 69 |
return 0; |
| 70 |
} |
| 71 |
|
| 72 |
int ctf_enum_write(struct bt_stream_pos *pos, struct bt_definition *definition) |
| 73 |
{ |
| 74 |
struct definition_enum *enum_definition = |
| 75 |
container_of(definition, struct definition_enum, p); |
| 76 |
struct definition_integer *integer_definition = |
| 77 |
enum_definition->integer; |
| 78 |
|
| 79 |
return ctf_integer_write(pos, &integer_definition->p); |
| 80 |
} |