Move stream pos declaration into CTF header
[babeltrace.git] / include / babeltrace / ctf / types.h
CommitLineData
d79865b9
MD
1#ifndef _BABELTRACE_CTF_TYPES_H
2#define _BABELTRACE_CTF_TYPES_H
6dc2ca62
MD
3
4/*
5 * Common Trace Format
6 *
7 * Type header
8 *
ccd7e1c8 9 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6dc2ca62 10 *
ccd7e1c8
MD
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
de0ba614 17 *
ccd7e1c8
MD
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
6dc2ca62
MD
20 */
21
4c8bfb7e 22#include <babeltrace/types.h>
6dc2ca62
MD
23#include <stdint.h>
24#include <glib.h>
25
dd2544fd
MD
26/*
27 * Always update stream_pos with move_pos and init_pos.
28 */
29struct stream_pos {
30 char *base; /* Base address */
31 size_t offset; /* Offset from base, in bits */
32 int dummy; /* Dummy position, for length calculation */
33};
34
35static inline
36void init_pos(struct stream_pos *pos, char *base)
37{
38 pos->base = base; /* initial base, page-aligned */
39 pos->offset = 0;
40 pos->dummy = false;
41}
42
43/*
44 * move_pos - move position of a relative bit offset
45 *
46 * TODO: allow larger files by updating base too.
47 */
48static inline
49void move_pos(struct stream_pos *pos, size_t offset)
50{
51 pos->offset = pos->offset + offset;
52}
53
54/*
55 * align_pos - align position on a bit offset (> 0)
56 *
57 * TODO: allow larger files by updating base too.
58 */
59static inline
60void align_pos(struct stream_pos *pos, size_t offset)
61{
62 pos->offset += offset_align(pos->offset, offset);
63}
64
65static inline
66void copy_pos(struct stream_pos *dest, struct stream_pos *src)
67{
68 memcpy(dest, src, sizeof(struct stream_pos));
69}
70
71static inline
72char *get_pos_addr(struct stream_pos *pos)
73{
74 /* Only makes sense to get the address after aligning on CHAR_BIT */
75 assert(!(pos->offset % CHAR_BIT));
76 return pos->base + (pos->offset / CHAR_BIT);
77}
78
6dc2ca62 79/*
de0ba614
MD
80 * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
81 * *not* in bytes.
82 *
83 * All write primitives, as well as read for dynamically sized entities, can
6dc2ca62
MD
84 * receive a NULL ptr/dest parameter. In this case, no write is performed, but
85 * the size is returned.
86 */
87
bed864a7 88uint64_t ctf_uint_read(struct stream_pos *pos,
f6625916 89 const struct declaration_integer *integer_declaration);
bed864a7 90int64_t ctf_int_read(struct stream_pos *pos,
f6625916 91 const struct declaration_integer *integer_declaration);
bed864a7 92void ctf_uint_write(struct stream_pos *pos,
f6625916 93 const struct declaration_integer *integer_declaration,
bed864a7
MD
94 uint64_t v);
95void ctf_int_write(struct stream_pos *pos,
f6625916 96 const struct declaration_integer *integer_declaration,
bed864a7 97 int64_t v);
6dc2ca62 98
bed864a7 99double ctf_double_read(struct stream_pos *pos,
f6625916 100 const struct declaration_float *src);
bed864a7 101void ctf_double_write(struct stream_pos *pos,
f6625916 102 const struct declaration_float *dest,
bed864a7
MD
103 double v);
104long double ctf_ldouble_read(struct stream_pos *pos,
f6625916 105 const struct declaration_float *src);
bed864a7 106void ctf_ldouble_write(struct stream_pos *pos,
f6625916 107 const struct declaration_float *dest,
bed864a7 108 long double v);
4c8bfb7e
MD
109void ctf_float_copy(struct stream_pos *destp,
110 struct stream_pos *srcp,
f6625916 111 const struct declaration_float *float_declaration);
6dc2ca62 112
bed864a7 113void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
f6625916 114 const struct declaration_string *string_declaration);
47e0f2e2 115void ctf_string_read(char **dest, struct stream_pos *src,
f6625916 116 const struct declaration_string *string_declaration);
47e0f2e2 117void ctf_string_write(struct stream_pos *dest, const char *src,
f6625916 118 const struct declaration_string *string_declaration);
47e0f2e2 119void ctf_string_free_temp(char *string);
6dc2ca62 120
47e0f2e2 121GArray *ctf_enum_read(struct stream_pos *pos,
f6625916 122 const struct declaration_enum *src);
bed864a7 123void ctf_enum_write(struct stream_pos *pos,
f6625916 124 const struct declaration_enum *dest,
bed864a7 125 GQuark q);
11796b96 126void ctf_struct_begin(struct stream_pos *pos,
f6625916 127 const struct declaration_struct *struct_declaration);
11796b96 128void ctf_struct_end(struct stream_pos *pos,
f6625916 129 const struct declaration_struct *struct_declaration);
6b71274a 130void ctf_variant_begin(struct stream_pos *pos,
f6625916 131 const struct declaration_variant *variant_declaration);
6b71274a 132void ctf_variant_end(struct stream_pos *pos,
f6625916 133 const struct declaration_variant *variant_declaration);
d06d03db 134void ctf_array_begin(struct stream_pos *pos,
f6625916 135 const struct declaration_array *array_declaration);
d06d03db 136void ctf_array_end(struct stream_pos *pos,
f6625916 137 const struct declaration_array *array_declaration);
d06d03db 138void ctf_sequence_begin(struct stream_pos *pos,
f6625916 139 const struct declaration_sequence *sequence_declaration);
d06d03db 140void ctf_sequence_end(struct stream_pos *pos,
f6625916 141 const struct declaration_sequence *sequence_declaration);
6dc2ca62 142
d79865b9 143#endif /* _BABELTRACE_CTF_TYPES_H */
This page took 0.029358 seconds and 4 git commands to generate.