8f9bf992e9d49e18360e09f976d72a4636585f85
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>
30 off_t offset
; /* offset of the packet in the file, in bytes */
31 size_t packet_size
; /* packet size, in bits */
32 size_t content_size
; /* content size, in bits */
36 * Always update stream_pos with move_pos and init_pos.
39 int fd
; /* backing file fd. -1 if unset. */
40 GArray
*packet_index
; /* contains struct packet_index */
41 int prot
; /* mmap protection */
42 int flags
; /* mmap flags */
44 /* Current position */
45 off_t mmap_offset
; /* mmap offset in the file, in bytes */
46 size_t packet_size
; /* current packet size, in bits */
47 size_t content_size
; /* current content size, in bits */
48 uint32_t *content_size_loc
; /* pointer to current content size */
49 char *base
; /* mmap base address */
50 size_t offset
; /* offset from base, in bits */
51 size_t cur_index
; /* current index in packet index */
53 int dummy
; /* dummy position, for length calculation */
57 * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
60 * All write primitives, as well as read for dynamically sized entities, can
61 * receive a NULL ptr/dest parameter. In this case, no write is performed, but
62 * the size is returned.
65 uint64_t ctf_uint_read(struct stream_pos
*pos
,
66 const struct declaration_integer
*integer_declaration
);
67 int64_t ctf_int_read(struct stream_pos
*pos
,
68 const struct declaration_integer
*integer_declaration
);
69 void ctf_uint_write(struct stream_pos
*pos
,
70 const struct declaration_integer
*integer_declaration
,
72 void ctf_int_write(struct stream_pos
*pos
,
73 const struct declaration_integer
*integer_declaration
,
76 double ctf_double_read(struct stream_pos
*pos
,
77 const struct declaration_float
*src
);
78 void ctf_double_write(struct stream_pos
*pos
,
79 const struct declaration_float
*dest
,
81 long double ctf_ldouble_read(struct stream_pos
*pos
,
82 const struct declaration_float
*src
);
83 void ctf_ldouble_write(struct stream_pos
*pos
,
84 const struct declaration_float
*dest
,
86 void ctf_float_copy(struct stream_pos
*destp
,
87 struct stream_pos
*srcp
,
88 const struct declaration_float
*float_declaration
);
90 void ctf_string_copy(struct stream_pos
*dest
, struct stream_pos
*src
,
91 const struct declaration_string
*string_declaration
);
92 void ctf_string_read(char **dest
, struct stream_pos
*src
,
93 const struct declaration_string
*string_declaration
);
94 void ctf_string_write(struct stream_pos
*dest
, const char *src
,
95 const struct declaration_string
*string_declaration
);
96 void ctf_string_free_temp(char *string
);
98 GArray
*ctf_enum_read(struct stream_pos
*pos
,
99 const struct declaration_enum
*src
);
100 void ctf_enum_write(struct stream_pos
*pos
,
101 const struct declaration_enum
*dest
,
103 void ctf_struct_begin(struct stream_pos
*pos
,
104 const struct declaration_struct
*struct_declaration
);
105 void ctf_struct_end(struct stream_pos
*pos
,
106 const struct declaration_struct
*struct_declaration
);
107 void ctf_variant_begin(struct stream_pos
*pos
,
108 const struct declaration_variant
*variant_declaration
);
109 void ctf_variant_end(struct stream_pos
*pos
,
110 const struct declaration_variant
*variant_declaration
);
111 void ctf_array_begin(struct stream_pos
*pos
,
112 const struct declaration_array
*array_declaration
);
113 void ctf_array_end(struct stream_pos
*pos
,
114 const struct declaration_array
*array_declaration
);
115 void ctf_sequence_begin(struct stream_pos
*pos
,
116 const struct declaration_sequence
*sequence_declaration
);
117 void ctf_sequence_end(struct stream_pos
*pos
,
118 const struct declaration_sequence
*sequence_declaration
);
120 void move_pos_slow(struct stream_pos
*pos
, size_t offset
);
122 void init_pos(struct stream_pos
*pos
, int fd
);
123 void fini_pos(struct stream_pos
*pos
);
126 * move_pos - move position of a relative bit offset
128 * TODO: allow larger files by updating base too.
131 void move_pos(struct stream_pos
*pos
, size_t bit_offset
)
134 if (((pos
->prot
== PROT_READ
)
135 && (pos
->offset
+ bit_offset
>= pos
->content_size
))
136 || ((pos
->prot
== PROT_WRITE
)
137 && (pos
->offset
+ bit_offset
>= pos
->packet_size
))) {
138 move_pos_slow(pos
, bit_offset
);
142 pos
->offset
+= bit_offset
;
146 * align_pos - align position on a bit offset (> 0)
148 * TODO: allow larger files by updating base too.
151 void align_pos(struct stream_pos
*pos
, size_t bit_offset
)
153 move_pos(pos
, offset_align(pos
->offset
, bit_offset
));
157 char *get_pos_addr(struct stream_pos
*pos
)
159 /* Only makes sense to get the address after aligning on CHAR_BIT */
160 assert(!(pos
->offset
% CHAR_BIT
));
161 return pos
->base
+ (pos
->offset
/ CHAR_BIT
);
165 void dummy_pos(struct stream_pos
*pos
, struct stream_pos
*dummy
)
167 memcpy(dummy
, pos
, sizeof(struct stream_pos
));
173 * Check if current packet can hold data.
174 * Returns 0 for success, negative error otherwise.
177 int pos_packet(struct stream_pos
*dummy
)
179 if (dummy
->offset
> dummy
->packet_size
)
185 void pos_pad_packet(struct stream_pos
*pos
)
187 move_pos(pos
, pos
->packet_size
- pos
->offset
);
190 #endif /* _BABELTRACE_CTF_TYPES_H */
This page took 0.033036 seconds and 3 git commands to generate.