1 #ifndef _BABELTRACE_CTF_TYPES_H
2 #define _BABELTRACE_CTF_TYPES_H
9 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
22 #include <babeltrace/types.h>
28 off_t offset
; /* offset of the packet in the file, in bytes */
29 size_t packet_size
; /* packet size, in bits */
30 size_t content_size
; /* content size, in bits */
34 * Always update stream_pos with move_pos and init_pos.
37 int fd
; /* backing file fd. -1 if unset. */
38 GArray
*packet_index
; /* contains struct packet_index */
40 /* Current position */
41 off_t mmap_offset
; /* mmap offset in the file, in bytes */
42 size_t packet_size
; /* current packet size, in bits */
43 size_t content_size
; /* current content size, in bits */
44 char *base
; /* mmap base address */
45 size_t offset
; /* offset from base, in bits */
47 int dummy
; /* dummy position, for length calculation */
51 * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
54 * All write primitives, as well as read for dynamically sized entities, can
55 * receive a NULL ptr/dest parameter. In this case, no write is performed, but
56 * the size is returned.
59 uint64_t ctf_uint_read(struct stream_pos
*pos
,
60 const struct declaration_integer
*integer_declaration
);
61 int64_t ctf_int_read(struct stream_pos
*pos
,
62 const struct declaration_integer
*integer_declaration
);
63 void ctf_uint_write(struct stream_pos
*pos
,
64 const struct declaration_integer
*integer_declaration
,
66 void ctf_int_write(struct stream_pos
*pos
,
67 const struct declaration_integer
*integer_declaration
,
70 double ctf_double_read(struct stream_pos
*pos
,
71 const struct declaration_float
*src
);
72 void ctf_double_write(struct stream_pos
*pos
,
73 const struct declaration_float
*dest
,
75 long double ctf_ldouble_read(struct stream_pos
*pos
,
76 const struct declaration_float
*src
);
77 void ctf_ldouble_write(struct stream_pos
*pos
,
78 const struct declaration_float
*dest
,
80 void ctf_float_copy(struct stream_pos
*destp
,
81 struct stream_pos
*srcp
,
82 const struct declaration_float
*float_declaration
);
84 void ctf_string_copy(struct stream_pos
*dest
, struct stream_pos
*src
,
85 const struct declaration_string
*string_declaration
);
86 void ctf_string_read(char **dest
, struct stream_pos
*src
,
87 const struct declaration_string
*string_declaration
);
88 void ctf_string_write(struct stream_pos
*dest
, const char *src
,
89 const struct declaration_string
*string_declaration
);
90 void ctf_string_free_temp(char *string
);
92 GArray
*ctf_enum_read(struct stream_pos
*pos
,
93 const struct declaration_enum
*src
);
94 void ctf_enum_write(struct stream_pos
*pos
,
95 const struct declaration_enum
*dest
,
97 void ctf_struct_begin(struct stream_pos
*pos
,
98 const struct declaration_struct
*struct_declaration
);
99 void ctf_struct_end(struct stream_pos
*pos
,
100 const struct declaration_struct
*struct_declaration
);
101 void ctf_variant_begin(struct stream_pos
*pos
,
102 const struct declaration_variant
*variant_declaration
);
103 void ctf_variant_end(struct stream_pos
*pos
,
104 const struct declaration_variant
*variant_declaration
);
105 void ctf_array_begin(struct stream_pos
*pos
,
106 const struct declaration_array
*array_declaration
);
107 void ctf_array_end(struct stream_pos
*pos
,
108 const struct declaration_array
*array_declaration
);
109 void ctf_sequence_begin(struct stream_pos
*pos
,
110 const struct declaration_sequence
*sequence_declaration
);
111 void ctf_sequence_end(struct stream_pos
*pos
,
112 const struct declaration_sequence
*sequence_declaration
);
114 void move_pos_slow(struct stream_pos
*pos
, size_t offset
);
117 void init_pos(struct stream_pos
*pos
, int fd
)
120 pos
->mmap_offset
= 0;
121 pos
->packet_size
= 0;
122 pos
->content_size
= 0;
129 * move_pos - move position of a relative bit offset
131 * TODO: allow larger files by updating base too.
134 void move_pos(struct stream_pos
*pos
, size_t offset
)
136 if (pos
->fd
>= 0 && (pos
->offset
+ offset
>= pos
->content_size
))
137 move_pos_slow(pos
, offset
);
139 pos
->offset
+= offset
;
143 * align_pos - align position on a bit offset (> 0)
145 * TODO: allow larger files by updating base too.
148 void align_pos(struct stream_pos
*pos
, size_t offset
)
150 pos
->offset
+= offset_align(pos
->offset
, offset
);
154 void copy_pos(struct stream_pos
*dest
, struct stream_pos
*src
)
156 memcpy(dest
, src
, sizeof(struct stream_pos
));
160 char *get_pos_addr(struct stream_pos
*pos
)
162 /* Only makes sense to get the address after aligning on CHAR_BIT */
163 assert(!(pos
->offset
% CHAR_BIT
));
164 return pos
->base
+ (pos
->offset
/ CHAR_BIT
);
167 #endif /* _BABELTRACE_CTF_TYPES_H */
This page took 0.034089 seconds and 5 git commands to generate.