Merge branch 'master' of ssh://efficios.com/home/efficios/git/babeltrace
[babeltrace.git] / formats / ctf / types / sequence.c
1 /*
2 * Common Trace Format
3 *
4 * Sequence format access functions.
5 *
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
7 *
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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
21 #include <babeltrace/ctf/types.h>
22
23 int ctf_sequence_read(struct stream_pos *ppos, struct definition *definition)
24 {
25 struct definition_sequence *sequence_definition =
26 container_of(definition, struct definition_sequence, p);
27 struct declaration_sequence *sequence_declaration =
28 sequence_definition->declaration;
29 struct declaration *elem = sequence_declaration->elem;
30 struct ctf_stream_pos *pos = ctf_pos(ppos);
31
32 if (elem->id == CTF_TYPE_INTEGER) {
33 struct declaration_integer *integer_declaration =
34 container_of(elem, struct declaration_integer, p);
35
36 if (integer_declaration->encoding == CTF_STRING_UTF8
37 || integer_declaration->encoding == CTF_STRING_ASCII) {
38
39 if (integer_declaration->len == CHAR_BIT
40 && integer_declaration->p.alignment == CHAR_BIT) {
41 uint64_t len = sequence_len(sequence_definition);
42
43 ctf_align_pos(pos, integer_declaration->p.alignment);
44 if (!ctf_pos_access_ok(pos, len * CHAR_BIT))
45 return -EFAULT;
46
47 g_string_assign(sequence_definition->string, "");
48 g_string_insert_len(sequence_definition->string,
49 0, (char *) ctf_get_pos_addr(pos), len);
50 ctf_move_pos(pos, len * CHAR_BIT);
51 return 0;
52 }
53 }
54 }
55 return sequence_rw(ppos, definition);
56 }
57
58 int ctf_sequence_write(struct stream_pos *ppos, struct definition *definition)
59 {
60 struct definition_sequence *sequence_definition =
61 container_of(definition, struct definition_sequence, p);
62 struct declaration_sequence *sequence_declaration =
63 sequence_definition->declaration;
64 struct declaration *elem = sequence_declaration->elem;
65 struct ctf_stream_pos *pos = ctf_pos(ppos);
66
67 if (elem->id == CTF_TYPE_INTEGER) {
68 struct declaration_integer *integer_declaration =
69 container_of(elem, struct declaration_integer, p);
70
71 if (integer_declaration->encoding == CTF_STRING_UTF8
72 || integer_declaration->encoding == CTF_STRING_ASCII) {
73
74 if (integer_declaration->len == CHAR_BIT
75 && integer_declaration->p.alignment == CHAR_BIT) {
76 uint64_t len = sequence_len(sequence_definition);
77
78 ctf_align_pos(pos, integer_declaration->p.alignment);
79 if (!ctf_pos_access_ok(pos, len * CHAR_BIT))
80 return -EFAULT;
81
82 memcpy((char *) ctf_get_pos_addr(pos),
83 sequence_definition->string->str, len);
84 ctf_move_pos(pos, len * CHAR_BIT);
85 return 0;
86 }
87 }
88 }
89 return sequence_rw(ppos, definition);
90 }
This page took 0.03026 seconds and 4 git commands to generate.