Python bindings clean-up: missing file headers style fixes
[babeltrace.git] / bindings / python / babeltrace.i.in
CommitLineData
24a3136a
DS
1/*
2 * babeltrace.i.in
3 *
4 * Babeltrace Python Module interface file
5 *
6 * Copyright 2012 EfficiOS Inc.
7 *
8 * Author: Danny Serres <danny.serres@efficios.com>
74ea15ad 9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
24a3136a
DS
10 *
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:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 */
21
22
23%define DOCSTRING
24"BABELTRACE_VERSION_STR
25
26Babeltrace is a trace viewer and converter reading and writing the
27Common Trace Format (CTF). Its main use is to pretty-print CTF
28traces into a human-readable text output.
29
74ea15ad 30To use this module, the first step is to create a TraceCollection and add a
24a3136a
DS
31trace to it."
32%enddef
33
34%module(docstring=DOCSTRING) babeltrace
35
38f28df6 36%include "stdint.i"
24a3136a
DS
37%include "typemaps.i"
38%{
39#define SWIG_FILE_WITH_INIT
40#include <babeltrace/babeltrace.h>
41#include <babeltrace/babeltrace-internal.h>
42#include <babeltrace/trace-handle.h>
43#include <babeltrace/trace-handle-internal.h>
44#include <babeltrace/context.h>
45#include <babeltrace/context-internal.h>
46#include <babeltrace/iterator.h>
47#include <babeltrace/iterator-internal.h>
48#include <babeltrace/format.h>
49#include <babeltrace/list.h>
24a3136a
DS
50#include <babeltrace/types.h>
51#include <babeltrace/ctf/iterator.h>
52#include "python-complements.h"
ec8c88d7
JG
53#include <babeltrace/ctf-writer/clock.h>
54#include <babeltrace/ctf-writer/event-fields.h>
55#include <babeltrace/ctf-writer/event-types.h>
56#include <babeltrace/ctf-writer/event.h>
57#include <babeltrace/ctf-writer/stream.h>
58#include <babeltrace/ctf-writer/writer.h>
24a3136a
DS
59%}
60
24a3136a 61typedef int bt_intern_str;
5792eb34 62typedef int64_t ssize_t;
24a3136a 63
b7d5d20c 64/* python-complements.h */
cebae8c3
JG
65struct bt_definition **_bt_python_field_listcaller(
66 const struct bt_ctf_event *ctf_event,
67 const struct bt_definition *scope,
68 unsigned int *OUTPUT);
69struct bt_definition *_bt_python_field_one_from_list(
70 struct bt_definition **list, int index);
71struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
72 int handle_id,
73 struct bt_context *ctx,
74 unsigned int *OUTPUT);
75struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
76 struct bt_ctf_event_decl **list, int index);
77struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
78 struct bt_ctf_event_decl *event_decl,
79 enum bt_ctf_scope scope,
80 unsigned int *OUTPUT);
81struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
82 struct bt_ctf_field_decl **list, int index);
83struct definition_array *_bt_python_get_array_from_def(
84 struct bt_definition *field);
85struct definition_sequence *_bt_python_get_sequence_from_def(
86 struct bt_definition *field);
5792eb34
JG
87struct bt_declaration *_bt_python_get_array_element_declaration(
88 struct bt_declaration *field);
3866c850
JG
89struct bt_declaration *_bt_python_get_sequence_element_declaration(
90 struct bt_declaration *field);
5792eb34 91const char *_bt_python_get_array_string(struct bt_definition *field);
3866c850 92const char *_bt_python_get_sequence_string(struct bt_definition *field);
ec8c88d7
JG
93int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
94enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
b4b5e4b5
JG
95const char *_bt_python_ctf_field_type_enumeration_get_mapping(
96 struct bt_ctf_field_type *enumeration, size_t index,
97 int64_t *OUTPUT, int64_t *OUTPUT);
98const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
99 struct bt_ctf_field_type *enumeration, size_t index,
100 uint64_t *OUTPUT, uint64_t *OUTPUT);
101const char *_bt_python_ctf_field_type_structure_get_field_name(
102 struct bt_ctf_field_type *structure, size_t index);
103struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
104 struct bt_ctf_field_type *structure, size_t index);
105const char *_bt_python_ctf_field_type_variant_get_field_name(
106 struct bt_ctf_field_type *variant, size_t index);
107struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
108 struct bt_ctf_field_type *variant, size_t index);
38f28df6
JG
109const char *_bt_python_ctf_event_class_get_field_name(
110 struct bt_ctf_event_class *event_class, size_t index);
111struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
112 struct bt_ctf_event_class *event_class, size_t index);
da64442f
JG
113int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
114 size_t index, unsigned char *OUTPUT);
115int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
116 size_t index, unsigned char value);
cebae8c3 117
b7d5d20c 118/* context.h, context-internal.h */
24a3136a
DS
119%rename("_bt_context_create") bt_context_create(void);
120%rename("_bt_context_add_trace") bt_context_add_trace(
121 struct bt_context *ctx, const char *path, const char *format,
2c0df204
XH
122 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
123 struct bt_mmap_stream_list *stream_list, FILE *metadata);
24a3136a
DS
124%rename("_bt_context_remove_trace") bt_context_remove_trace(
125 struct bt_context *ctx, int trace_id);
126%rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
127%rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
128%rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
129 const struct bt_ctf_event *event);
130
131struct bt_context *bt_context_create(void);
132int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
2c0df204
XH
133 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
134 struct bt_mmap_stream_list *stream_list, FILE *metadata);
24a3136a
DS
135void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
136void bt_context_get(struct bt_context *ctx);
137void bt_context_put(struct bt_context *ctx);
138struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
139
b7d5d20c 140/* class TraceCollection to prevent direct access to struct bt_context */
24a3136a 141%pythoncode%{
24a3136a 142
be02a6e6 143class TraceCollection:
74ea15ad 144
be02a6e6
JG
145 """
146 The TraceCollection is the object that contains all currently opened traces.
147 """
148
149 def __init__(self):
150 self._tc = _bt_context_create()
151
152 def __del__(self):
153 _bt_context_put(self._tc)
154
155 def add_trace(self, path, format_str):
156 """
157 Add a trace by path to the TraceCollection.
158
159 Open a trace.
160
161 path is the path to the trace, it is not recursive.
162 If "path" is None, stream_list is used instead as a list
163 of mmap streams to open for the trace.
164
165 format is a string containing the format name in which the trace was
166 produced.
167
168 Return: the corresponding TraceHandle on success or None on error.
169 """
170 ret = _bt_context_add_trace(
171 self._tc,
172 path,
173 format_str,
174 None,
175 None,
176 None)
177 if ret < 0:
178 return None
179
180 th = TraceHandle.__new__(TraceHandle)
181 th._id = ret
182 th._trace_collection = self
183 return th
184
185 def add_traces_recursive(self, path, format_str):
186 """
187 Open a trace recursively.
188
189 Find each trace present in the subdirectory starting from the given
190 path, and add them to the TraceCollection.
191
192 Return a dict of TraceHandle instances (the full path is the key).
193 Return None on error.
194 """
195
196 import os
197
198 trace_handles = {}
199
200 noTrace = True
201 error = False
202
203 for fullpath, dirs, files in os.walk(path):
204 if "metadata" in files:
205 trace_handle = self.add_trace(fullpath, format_str)
206 if trace_handle is None:
207 error = True
208 continue
209
210 trace_handles[fullpath] = trace_handle
211 noTrace = False
212
213 if noTrace and error:
214 return None
215 return trace_handles
216
217 def remove_trace(self, trace_handle):
218 """
219 Remove a trace from the TraceCollection.
220 Effectively closing the trace.
221 """
222 try:
223 _bt_context_remove_trace(self._tc, trace_handle._id)
224 except AttributeError:
225 raise TypeError("in remove_trace, "
226 "argument 2 must be a TraceHandle instance")
227
228 @property
229 def events(self):
230 """
231 Generator function to iterate over the events of open in the current
232 TraceCollection.
233
234 Due to limitations of the native Babeltrace API, only one event
235 may be "alive" at a time (i.e. a user should never store a copy
236 of the events returned by this function for ulterior use). Users
237 shall make sure to copy the information they need from an event
238 before accessing the next one.
239
240 Furthermore, event objects become invalid when the generator goes
241 out of scope as the underlying iterator will be reclaimed. Using an
242 event after the the generator has gone out of scope may result in a
243 crash or data corruption.
244 """
245 begin_pos_ptr = _bt_iter_pos()
246 end_pos_ptr = _bt_iter_pos()
247 begin_pos_ptr.type = SEEK_BEGIN
248 end_pos_ptr.type = SEEK_LAST
249
250 for event in self._events(begin_pos_ptr, end_pos_ptr):
251 yield event
252
253 def events_timestamps(self, timestamp_begin, timestamp_end):
254 """
255 Generator function to iterate over the events of open in the current
256 TraceCollection from timestamp_begin to timestamp_end.
257 """
258 begin_pos_ptr = _bt_iter_pos()
259 end_pos_ptr = _bt_iter_pos()
260 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
261 begin_pos_ptr.u.seek_time = timestamp_begin
262 end_pos_ptr.u.seek_time = timestamp_end
263
264 for event in self._events(begin_pos_ptr, end_pos_ptr):
265 yield event
266
267 @property
268 def timestamp_begin(self):
269 pos_ptr = _bt_iter_pos()
270 pos_ptr.type = SEEK_BEGIN
271 return self._timestamp_at_pos(pos_ptr)
272
273 @property
274 def timestamp_end(self):
275 pos_ptr = _bt_iter_pos()
276 pos_ptr.type = SEEK_LAST
277 return self._timestamp_at_pos(pos_ptr)
278
279 def _timestamp_at_pos(self, pos_ptr):
280 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
281 if ctf_it_ptr is None:
282 raise NotImplementedError(
283 "Creation of multiple iterators is unsupported.")
284 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
285 _bt_ctf_iter_destroy(ctf_it_ptr)
286 if ev_ptr is None:
287 return None
288
289 def _events(self, begin_pos_ptr, end_pos_ptr):
290 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
291 if ctf_it_ptr is None:
292 raise NotImplementedError(
293 "Creation of multiple iterators is unsupported.")
294
295 while True:
296 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
297 if ev_ptr is None:
298 break
299
300 ev = Event.__new__(Event)
301 ev._e = ev_ptr
302 try:
303 yield ev
304 except GeneratorExit:
305 break
306
307 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
308 if ret != 0:
309 break
310
311 _bt_ctf_iter_destroy(ctf_it_ptr)
24a3136a
DS
312%}
313
314
315
b7d5d20c 316/* format.h */
24a3136a
DS
317%rename("lookup_format") bt_lookup_format(bt_intern_str qname);
318%rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
319%rename("register_format") bt_register_format(struct format *format);
cc26a15a 320%rename("unregister_format") bt_unregister_format(struct bt_format *format);
24a3136a
DS
321
322extern struct format *bt_lookup_format(bt_intern_str qname);
323extern void bt_fprintf_format_list(FILE *fp);
2c0df204 324extern int bt_register_format(struct bt_format *format);
cc26a15a 325extern void bt_unregister_format(struct bt_format *format);
24a3136a 326
24a3136a
DS
327%pythoncode %{
328
329def print_format_list(babeltrace_file):
be02a6e6
JG
330 """
331 Print a list of available formats to file.
332
333 babeltrace_file must be a File instance opened in write mode.
334 """
335 try:
336 if babeltrace_file._file is not None:
337 _bt_print_format_list(babeltrace_file._file)
338 except AttributeError:
339 raise TypeError("in print_format_list, "
340 "argument 1 must be a File instance")
24a3136a
DS
341
342%}
343
b7d5d20c 344/* iterator.h, iterator-internal.h */
24a3136a
DS
345%rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
346 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
347%rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
348%rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
349%rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
350%rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
351%rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
352 const struct bt_iter_pos *pos);
353%rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
354 uint64_t timestamp);
355
356struct bt_iter *bt_iter_create(struct bt_context *ctx,
357 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
358void bt_iter_destroy(struct bt_iter *iter);
359int bt_iter_next(struct bt_iter *iter);
360struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
361void bt_iter_free_pos(struct bt_iter_pos *pos);
362int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
363struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
364
365%rename("_bt_iter_pos") bt_iter_pos;
366%rename("SEEK_TIME") BT_SEEK_TIME;
367%rename("SEEK_RESTORE") BT_SEEK_RESTORE;
368%rename("SEEK_CUR") BT_SEEK_CUR;
369%rename("SEEK_BEGIN") BT_SEEK_BEGIN;
ef42f9eb 370%rename("SEEK_LAST") BT_SEEK_LAST;
24a3136a 371
b7d5d20c
JG
372/*
373 * This struct is taken from iterator.h
374 * All changes to the struct must also be made here.
375 */
24a3136a
DS
376struct bt_iter_pos {
377 enum {
378 BT_SEEK_TIME, /* uses u.seek_time */
379 BT_SEEK_RESTORE, /* uses u.restore */
380 BT_SEEK_CUR,
381 BT_SEEK_BEGIN,
ef42f9eb 382 BT_SEEK_LAST
24a3136a
DS
383 } type;
384 union {
385 uint64_t seek_time;
386 struct bt_saved_pos *restore;
387 } u;
388};
389
b7d5d20c 390/* trace-handle.h, trace-handle-internal.h */
24a3136a
DS
391%rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
392%rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
393struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
394void bt_trace_handle_destroy(struct bt_trace_handle *bt);
395
396%rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
397 int handle_id);
398%rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
399 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
400%rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
401 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
24a3136a
DS
402const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
403uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
404 enum bt_clock_type type);
405uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
406 enum bt_clock_type type);
407
408%rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
409 const struct bt_ctf_event *event);
410int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
411
412
413%pythoncode%{
414
8a2cd19a 415# Based on enum bt_clock_type in clock-type.h
464425e1 416class ClockType:
be02a6e6
JG
417 CLOCK_CYCLES = 0
418 CLOCK_REAL = 1
464425e1 419
8bb27181 420
be02a6e6 421class TraceHandle(object):
8bb27181 422
be02a6e6
JG
423 """
424 The TraceHandle allows the user to manipulate a trace file directly.
425 It is a unique identifier representing a trace file.
426 Do not instantiate.
427 """
428
429 def __init__(self):
430 raise NotImplementedError("TraceHandle cannot be instantiated")
431
432 def __repr__(self):
433 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
434
435 @property
436 def id(self):
437 """Return the TraceHandle id."""
438 return self._id
439
440 @property
441 def path(self):
442 """Return the path of a TraceHandle."""
443 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
444
445 @property
446 def timestamp_begin(self):
447 """Return the creation time of the buffers of a trace."""
448 return _bt_trace_handle_get_timestamp_begin(
449 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
450
451 @property
452 def timestamp_end(self):
453 """Return the destruction timestamp of the buffers of a trace."""
454 return _bt_trace_handle_get_timestamp_end(
455 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
456
457 @property
458 def events(self):
459 """
460 Generator returning all events (EventDeclaration) in a trace.
461 """
462 ret = _bt_python_event_decl_listcaller(
463 self.id,
464 self._trace_collection._tc)
465
466 if not isinstance(ret, list):
467 return
468
469 ptr_list, count = ret
470 for i in range(count):
471 tmp = EventDeclaration.__new__(EventDeclaration)
472 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
473 yield tmp
8bb27181 474
24a3136a
DS
475%}
476
b7d5d20c 477/* iterator.h, events.h */
24a3136a
DS
478%rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
479 const struct bt_iter_pos *begin_pos,
480 const struct bt_iter_pos *end_pos);
481%rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
482%rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
483%rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
484
485struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
486 const struct bt_iter_pos *begin_pos,
487 const struct bt_iter_pos *end_pos);
488struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
489void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
490struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
491
492
b7d5d20c 493/* events.h */
24a3136a
DS
494%rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
495 bt_ctf_event *event, enum bt_ctf_scope scope);
496%rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
497%rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
498 const struct bt_ctf_event *ctf_event);
499%rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
500 const struct bt_ctf_event *ctf_event);
501
502%rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
2c0df204 503 const struct bt_definition *scope, const char *field);
24a3136a 504%rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
2c0df204
XH
505 const struct bt_definition *field, unsigned int index);
506%rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
507%rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
24a3136a 508%rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
2c0df204
XH
509 const struct bt_declaration *field);
510%rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
24a3136a 511%rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
2c0df204
XH
512 const struct bt_declaration *field);
513%rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
4191bcd2
XH
514%rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
515%rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
2c0df204
XH
516%rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
517%rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
518%rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
519%rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
520%rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
521%rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
e5a73b90 522%rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
812e6682 523%rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
24a3136a
DS
524%rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
525%rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
526 bt_ctf_event_decl *event);
78564612
AM
527%rename("_bt_ctf_get_decl_event_id") bt_ctf_get_decl_event_id(const struct
528 bt_ctf_event_decl *event);
24a3136a
DS
529%rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
530 const struct bt_ctf_field_decl *field);
f01efa78 531%rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
2c0df204 532 const struct bt_definition *field);
8bb27181
JG
533%rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
534 const struct bt_ctf_field_decl *field);
3c2ce778 535%rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
786207e0
XH
536%rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
537%rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
3a068915
JG
538%rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
539%rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
24a3136a 540
2c0df204 541const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
24a3136a
DS
542 enum bt_ctf_scope scope);
543const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
544uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
545uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
2c0df204
XH
546const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
547 const struct bt_definition *scope,
24a3136a 548 const char *field);
2c0df204
XH
549const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
550 const struct bt_definition *field,
24a3136a 551 unsigned int index);
2c0df204
XH
552const char *bt_ctf_field_name(const struct bt_definition *field);
553enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
554int bt_ctf_get_int_signedness(const struct bt_declaration *field);
555int bt_ctf_get_int_base(const struct bt_declaration *field);
556int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
557ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
4191bcd2
XH
558const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
559const char *bt_ctf_get_enum_str(const struct bt_definition *field);
2c0df204
XH
560enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
561int bt_ctf_get_array_len(const struct bt_declaration *field);
3c2ce778 562struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
2c0df204
XH
563uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
564int64_t bt_ctf_get_int64(const struct bt_definition *field);
565char *bt_ctf_get_char_array(const struct bt_definition *field);
566char *bt_ctf_get_string(const struct bt_definition *field);
e5a73b90 567double bt_ctf_get_float(const struct bt_definition *field);
812e6682 568const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
24a3136a
DS
569int bt_ctf_field_get_error(void);
570const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
78564612 571uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
24a3136a 572const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
2c0df204 573const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
8bb27181 574const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
786207e0
XH
575uint64_t bt_sequence_len(struct definition_sequence *sequence);
576struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
3a068915
JG
577uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
578const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
24a3136a
DS
579
580%pythoncode%{
581
24d5c942 582class CTFStringEncoding:
be02a6e6
JG
583 NONE = 0
584 UTF8 = 1
585 ASCII = 2
586 UNKNOWN = 3
24d5c942 587
8bb27181
JG
588# Based on the enum in ctf-writer/writer.h
589class ByteOrder:
be02a6e6
JG
590 BYTE_ORDER_NATIVE = 0
591 BYTE_ORDER_LITTLE_ENDIAN = 1
592 BYTE_ORDER_BIG_ENDIAN = 2
593 BYTE_ORDER_NETWORK = 3
594 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
595
596# enum equivalent, accessible constants
597# These are taken directly from ctf/events.h
598# All changes to enums must also be made here
24d5c942 599class CTFTypeId:
be02a6e6
JG
600 UNKNOWN = 0
601 INTEGER = 1
602 FLOAT = 2
603 ENUM = 3
604 STRING = 4
605 STRUCT = 5
606 UNTAGGED_VARIANT = 6
607 VARIANT = 7
608 ARRAY = 8
609 SEQUENCE = 9
610 NR_CTF_TYPES = 10
611
612 def type_name(id):
613 name = "UNKNOWN_TYPE"
614 constants = [
615 attr for attr in dir(CTFTypeId) if not callable(
616 getattr(
617 CTFTypeId,
618 attr)) and not attr.startswith("__")]
619 for attr in constants:
620 if getattr(CTFTypeId, attr) == id:
621 name = attr
622 break
623 return name
624
24d5c942 625
8bb27181 626class CTFScope:
be02a6e6
JG
627 TRACE_PACKET_HEADER = 0
628 STREAM_PACKET_CONTEXT = 1
629 STREAM_EVENT_HEADER = 2
630 STREAM_EVENT_CONTEXT = 3
631 EVENT_CONTEXT = 4
632 EVENT_FIELDS = 5
633
634 def scope_name(scope):
635 name = "UNKNOWN_SCOPE"
636 constants = [
637 attr for attr in dir(CTFScope) if not callable(
638 getattr(
639 CTFScope,
640 attr)) and not attr.startswith("__")]
641 for attr in constants:
642 if getattr(CTFScope, attr) == scope:
643 name = attr
644 break
645 return name
8bb27181 646
e404272a 647# Priority of the scopes when searching for event fields
8bb27181 648_scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
be02a6e6 649 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
e404272a 650
78d714e8 651import collections
49a04569 652from datetime import datetime
be02a6e6
JG
653
654
78d714e8 655class Event(collections.Mapping):
78d714e8 656
be02a6e6
JG
657 """
658 This class represents an event from the trace.
659 It is obtained using the TraceCollection generator functions.
660 Do not instantiate.
661 """
662
663 def __init__(self):
664 raise NotImplementedError("Event cannot be instantiated")
665
666 @property
667 def name(self):
668 """Return the name of the event or None on error."""
669 return _bt_ctf_event_name(self._e)
670
671 @property
672 def cycles(self):
673 """
674 Return the timestamp of the event as written in
675 the packet (in cycles) or -1ULL on error.
676 """
677 return _bt_ctf_get_cycles(self._e)
678
679 @property
680 def timestamp(self):
681 """
682 Return the timestamp of the event offset with the
683 system clock source or -1ULL on error.
684 """
685 return _bt_ctf_get_timestamp(self._e)
686
687 @property
688 def datetime(self):
689 """
690 Return a datetime object based on the event's
691 timestamp. Note that the datetime class' precision
692 is limited to microseconds.
693 """
694 return datetime.fromtimestamp(self.timestamp / 1E9)
695
696 def field_with_scope(self, field_name, scope):
697 """
698 Get field_name's value in scope.
699 None is returned if no field matches field_name.
700 """
701 if not scope in _scopes:
702 raise ValueError("Invalid scope provided")
703 field = self._field_with_scope(field_name, scope)
704 if field is not None:
705 return field.value
706 return None
707
708 def field_list_with_scope(self, scope):
709 """Return a list of field names in scope."""
710 if not scope in _scopes:
711 raise ValueError("Invalid scope provided")
712 field_names = []
713 for field in self._field_list_with_scope(scope):
714 field_names.append(field.name)
715 return field_names
716
717 @property
718 def handle(self):
719 """
720 Get the TraceHandle associated with this event
721 Return None on error
722 """
723 ret = _bt_ctf_event_get_handle_id(self._e)
724 if ret < 0:
725 return None
726
727 th = TraceHandle.__new__(TraceHandle)
728 th._id = ret
729 th._trace_collection = self.get_trace_collection()
730 return th
731
732 @property
733 def trace_collection(self):
734 """
735 Get the TraceCollection associated with this event.
736 Return None on error.
737 """
738 trace_collection = TraceCollection()
739 trace_collection._tc = _bt_ctf_event_get_context(self._e)
740 if trace_collection._tc is None:
741 return None
742 else:
743 return trace_collection
744
745 def __getitem__(self, field_name):
746 """
747 Get field_name's value. If the field_name exists in multiple
748 scopes, the first field found is returned. The scopes are searched
749 in the following order:
750 1) EVENT_FIELDS
751 2) EVENT_CONTEXT
752 3) STREAM_EVENT_CONTEXT
753 4) STREAM_EVENT_HEADER
754 5) STREAM_PACKET_CONTEXT
755 6) TRACE_PACKET_HEADER
756 None is returned if no field matches field_name.
757
758 Use field_with_scope() to explicitly access fields in a given
759 scope.
760 """
761 field = self._field(field_name)
762 if field is not None:
763 return field.value
764 raise KeyError(field_name)
765
766 def __iter__(self):
767 for key in self.keys():
768 yield key
769
770 def __len__(self):
771 count = 0
772 for scope in _scopes:
773 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
774 ret = _bt_python_field_listcaller(self._e, scope_ptr)
775 if isinstance(ret, list):
776 count += ret[1]
777 return count
778
779 def __contains__(self, field_name):
780 return self._field(field_name) is not None
781
782 def keys(self):
783 """Return a list of field names."""
784 field_names = set()
785 for scope in _scopes:
786 for name in self.field_list_with_scope(scope):
787 field_names.add(name)
788 return list(field_names)
789
790 def get(self, field_name, default=None):
791 field = self._field(field_name)
792 if field is None:
793 return default
794 return field.value
795
796 def items(self):
797 for field in self.keys():
798 yield (field, self[field])
799
800 def _field_with_scope(self, field_name, scope):
801 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
802 if scope_ptr is None:
803 return None
804
805 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
806 if definition_ptr is None:
807 return None
808
809 field = _Definition(definition_ptr, scope)
810 return field
811
812 def _field(self, field_name):
813 field = None
814 for scope in _scopes:
815 field = self._field_with_scope(field_name, scope)
816 if field is not None:
817 break
818 return field
819
820 def _field_list_with_scope(self, scope):
821 fields = []
822 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
823
824 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
825 # provide the "count" return value
826 count = 0
827 list_ptr = None
828 ret = _bt_python_field_listcaller(self._e, scope_ptr)
829 if isinstance(ret, list):
830 list_ptr, count = ret
831
832 for i in range(count):
833 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
834 if definition_ptr is not None:
835 definition = _Definition(definition_ptr, scope)
836 fields.append(definition)
837 return fields
78d714e8 838
78d714e8
JG
839
840class FieldError(Exception):
78d714e8 841
be02a6e6
JG
842 def __init__(self, value):
843 self.value = value
844
845 def __str__(self):
846 return repr(self.value)
847
78d714e8 848
cb1fcc68 849class EventDeclaration(object):
be02a6e6
JG
850
851 """Event declaration class. Do not instantiate."""
852 MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
853
854 def __init__(self):
855 raise NotImplementedError("EventDeclaration cannot be instantiated")
856
857 @property
858 def name(self):
859 """Return the name of the event or None on error"""
860 return _bt_ctf_get_decl_event_name(self._ed)
861
862 @property
863 def id(self):
864 """Return the event-ID of the event or -1 on error"""
865 id = _bt_ctf_get_decl_event_id(self._ed)
866 if id == self.MAX_UINT64:
867 id = -1
868 return id
869
870 @property
871 def fields(self):
872 """
873 Generator returning all FieldDeclarations of an event, going through
874 each scope in the following order:
875 1) EVENT_FIELDS
876 2) EVENT_CONTEXT
877 3) STREAM_EVENT_CONTEXT
878 4) STREAM_EVENT_HEADER
879 5) STREAM_PACKET_CONTEXT
880 6) TRACE_PACKET_HEADER
881 """
882 for scope in _scopes:
883 for declaration in self.fields_scope(scope):
884 yield declaration
885
886 def fields_scope(self, scope):
887 """
888 Generator returning FieldDeclarations of the current event in scope.
889 """
890 ret = _by_python_field_decl_listcaller(self._ed, scope)
891
892 if not isinstance(ret, list):
893 return
894
895 list_ptr, count = ret
896 for i in range(count):
897 field_declaration_ptr = _bt_python_field_decl_one_from_list(
898 list_ptr,
899 i)
900 if field_declaration_ptr is not None:
901 declaration_ptr = _bt_ctf_get_decl_from_field_decl(
902 field_declaration_ptr)
903 field_declaration = _create_field_declaration(
904 declaration_ptr,
905 _bt_ctf_get_decl_field_name(field_declaration_ptr),
906 scope)
907 yield field_declaration
908
cb1fcc68
JG
909
910class FieldDeclaration(object):
78d714e8 911
be02a6e6 912 """Field declaration class. Do not instantiate."""
8bb27181 913
be02a6e6
JG
914 def __init__(self):
915 raise NotImplementedError("FieldDeclaration cannot be instantiated")
8bb27181 916
be02a6e6
JG
917 def __repr__(self):
918 return "({0}) {1} {2}".format(
919 CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
8bb27181 920
be02a6e6
JG
921 @property
922 def name(self):
923 """Return the name of a FieldDeclaration or None on error."""
924 return self._name
8bb27181 925
be02a6e6
JG
926 @property
927 def type(self):
928 """
929 Return the FieldDeclaration's type. One of the entries in class
930 CTFTypeId.
931 """
932 return _bt_ctf_field_type(self._fd)
8bb27181 933
be02a6e6
JG
934 @property
935 def scope(self):
936 """
937 Return the FieldDeclaration's scope.
938 """
939 return self._s
8bb27181 940
8bb27181 941
be02a6e6 942class IntegerFieldDeclaration(FieldDeclaration):
8bb27181 943
be02a6e6
JG
944 """Do not instantiate."""
945
946 def __init__(self):
947 raise NotImplementedError(
948 "IntegerFieldDeclaration cannot be instantiated")
949
950 @property
951 def signedness(self):
952 """
953 Return the signedness of an integer:
954 0 if unsigned; 1 if signed; -1 on error.
955 """
956 return _bt_ctf_get_int_signedness(self._fd)
957
958 @property
959 def base(self):
960 """Return the base of an int or a negative value on error."""
961 return _bt_ctf_get_int_base(self._fd)
962
963 @property
964 def byte_order(self):
965 """
966 Return the byte order. One of class ByteOrder's entries.
967 """
968 ret = _bt_ctf_get_int_byte_order(self._fd)
969 if ret == 1234:
970 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
971 elif ret == 4321:
972 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
973 else:
974 return ByteOrder.BYTE_ORDER_UNKNOWN
975
976 @property
977 def length(self):
978 """
979 Return the size, in bits, of an int or a negative
980 value on error.
981 """
982 return _bt_ctf_get_int_len(self._fd)
983
984 @property
985 def encoding(self):
986 """
987 Return the encoding. One of class CTFStringEncoding's entries.
988 Return a negative value on error.
989 """
990 return _bt_ctf_get_encoding(self._fd)
8bb27181 991
8bb27181
JG
992
993class EnumerationFieldDeclaration(FieldDeclaration):
be02a6e6
JG
994
995 """Do not instantiate."""
996
997 def __init__(self):
998 raise NotImplementedError(
999 "EnumerationFieldDeclaration cannot be instantiated")
1000
8bb27181
JG
1001
1002class ArrayFieldDeclaration(FieldDeclaration):
8bb27181 1003
be02a6e6
JG
1004 """Do not instantiate."""
1005
1006 def __init__(self):
1007 raise NotImplementedError(
1008 "ArrayFieldDeclaration cannot be instantiated")
1009
1010 @property
1011 def length(self):
1012 """
1013 Return the length of an array or a negative
1014 value on error.
1015 """
1016 return _bt_ctf_get_array_len(self._fd)
1017
1018 @property
1019 def element_declaration(self):
1020 """
1021 Return element declaration.
1022 """
1023 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
1024 return _create_field_declaration(field_decl_ptr, "", self.scope)
8bb27181 1025
5792eb34 1026
8bb27181 1027class SequenceFieldDeclaration(FieldDeclaration):
8bb27181 1028
be02a6e6
JG
1029 """Do not instantiate."""
1030
1031 def __init__(self):
1032 raise NotImplementedError(
1033 "SequenceFieldDeclaration cannot be instantiated")
1034
1035 @property
1036 def element_declaration(self):
1037 """
1038 Return element declaration.
1039 """
1040 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
1041 return _create_field_declaration(field_decl_ptr, "", self.scope)
1042
3866c850 1043
8bb27181 1044class FloatFieldDeclaration(FieldDeclaration):
be02a6e6
JG
1045
1046 """Do not instantiate."""
1047
1048 def __init__(self):
1049 raise NotImplementedError(
1050 "FloatFieldDeclaration cannot be instantiated")
1051
8bb27181
JG
1052
1053class StructureFieldDeclaration(FieldDeclaration):
8bb27181 1054
be02a6e6 1055 """Do not instantiate."""
8bb27181 1056
be02a6e6
JG
1057 def __init__(self):
1058 raise NotImplementedError(
1059 "StructureFieldDeclaration cannot be instantiated")
78d714e8 1060
78d714e8 1061
be02a6e6 1062class StringFieldDeclaration(FieldDeclaration):
78d714e8 1063
be02a6e6 1064 """Do not instantiate."""
78d714e8 1065
be02a6e6
JG
1066 def __init__(self):
1067 raise NotImplementedError(
1068 "StringFieldDeclaration cannot be instantiated")
78d714e8 1069
78d714e8 1070
be02a6e6 1071class VariantFieldDeclaration(FieldDeclaration):
78d714e8 1072
be02a6e6 1073 """Do not instantiate."""
78d714e8 1074
be02a6e6
JG
1075 def __init__(self):
1076 raise NotImplementedError(
1077 "VariantFieldDeclaration cannot be instantiated")
78d714e8 1078
78d714e8 1079
be02a6e6
JG
1080def field_error():
1081 """
1082 Return the last error code encountered while
1083 accessing a field and reset the error flag.
1084 Return 0 if no error, a negative value otherwise.
1085 """
1086 return _bt_ctf_field_get_error()
78d714e8 1087
78d714e8 1088
be02a6e6
JG
1089def _create_field_declaration(declaration_ptr, name, scope):
1090 """
1091 Private field declaration factory.
1092 """
1093 if declaration_ptr is None:
1094 raise ValueError("declaration_ptr must be valid")
1095 if not scope in _scopes:
1096 raise ValueError("Invalid scope provided")
1097
1098 type = _bt_ctf_field_type(declaration_ptr)
1099 declaration = None
1100 if type == CTFTypeId.INTEGER:
1101 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1102 elif type == CTFTypeId.ENUM:
1103 declaration = EnumerationFieldDeclaration.__new__(
1104 EnumerationFieldDeclaration)
1105 elif type == CTFTypeId.ARRAY:
1106 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1107 elif type == CTFTypeId.SEQUENCE:
1108 declaration = SequenceFieldDeclaration.__new__(
1109 SequenceFieldDeclaration)
1110 elif type == CTFTypeId.FLOAT:
1111 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1112 elif type == CTFTypeId.STRUCT:
1113 declaration = StructureFieldDeclaration.__new__(
1114 StructureFieldDeclaration)
1115 elif type == CTFTypeId.STRING:
1116 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1117 elif type == CTFTypeId.VARIANT:
1118 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1119 else:
1120 return declaration
1121
1122 declaration._fd = declaration_ptr
1123 declaration._s = scope
1124 declaration._name = name
1125 return declaration
78d714e8 1126
78d714e8 1127
be02a6e6
JG
1128class _Definition(object):
1129
1130 def __init__(self, definition_ptr, scope):
1131 self._d = definition_ptr
1132 self._s = scope
1133 if not scope in _scopes:
1134 ValueError("Invalid scope provided")
1135
1136 @property
1137 def name(self):
1138 """Return the name of a field or None on error."""
1139 return _bt_ctf_field_name(self._d)
1140
1141 @property
1142 def type(self):
1143 """Return the type of a field or -1 if unknown."""
1144 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1145
1146 @property
1147 def declaration(self):
1148 """Return the associated Definition object."""
1149 return _create_field_declaration(
1150 _bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1151
1152 def _get_enum_str(self):
1153 """
1154 Return the string matching the current enumeration.
1155 Return None on error.
1156 """
1157 return _bt_ctf_get_enum_str(self._d)
1158
1159 def _get_array_element_at(self, index):
1160 """
1161 Return the array's element at position index.
1162 Return None on error
1163 """
1164 array_ptr = _bt_python_get_array_from_def(self._d)
1165 if array_ptr is None:
1166 return None
1167
1168 definition_ptr = _bt_array_index(array_ptr, index)
1169 if definition_ptr is None:
1170 return None
1171 return _Definition(definition_ptr, self.scope)
1172
1173 def _get_sequence_len(self):
1174 """
1175 Return the len of a sequence or a negative
1176 value on error.
1177 """
1178 seq = _bt_python_get_sequence_from_def(self._d)
1179 return _bt_sequence_len(seq)
1180
1181 def _get_sequence_element_at(self, index):
1182 """
1183 Return the sequence's element at position index,
1184 otherwise return None
1185 """
1186 seq = _bt_python_get_sequence_from_def(self._d)
1187 if seq is not None:
1188 definition_ptr = _bt_sequence_index(seq, index)
1189 if definition_ptr is not None:
1190 return _Definition(definition_ptr, self.scope)
1191 return None
1192
1193 def _get_uint64(self):
1194 """
1195 Return the value associated with the field.
1196 If the field does not exist or is not of the type requested,
1197 the value returned is undefined. To check if an error occured,
1198 use the field_error() function after accessing a field.
1199 """
1200 return _bt_ctf_get_uint64(self._d)
1201
1202 def _get_int64(self):
1203 """
1204 Return the value associated with the field.
1205 If the field does not exist or is not of the type requested,
1206 the value returned is undefined. To check if an error occured,
1207 use the field_error() function after accessing a field.
1208 """
1209 return _bt_ctf_get_int64(self._d)
1210
1211 def _get_char_array(self):
1212 """
1213 Return the value associated with the field.
1214 If the field does not exist or is not of the type requested,
1215 the value returned is undefined. To check if an error occurred,
1216 use the field_error() function after accessing a field.
1217 """
1218 return _bt_ctf_get_char_array(self._d)
1219
1220 def _get_str(self):
1221 """
1222 Return the value associated with the field.
1223 If the field does not exist or is not of the type requested,
1224 the value returned is undefined. To check if an error occurred,
1225 use the field_error() function after accessing a field.
1226 """
1227 return _bt_ctf_get_string(self._d)
1228
1229 def _get_float(self):
1230 """
1231 Return the value associated with the field.
1232 If the field does not exist or is not of the type requested,
1233 the value returned is undefined. To check if an error occurred,
1234 use the field_error() function after accessing a field.
1235 """
1236 return _bt_ctf_get_float(self._d)
1237
1238 def _get_variant(self):
1239 """
1240 Return the variant's selected field.
1241 If the field does not exist or is not of the type requested,
1242 the value returned is undefined. To check if an error occurred,
1243 use the field_error() function after accessing a field.
1244 """
1245 return _bt_ctf_get_variant(self._d)
1246
1247 def _get_struct_field_count(self):
1248 """
1249 Return the number of fields contained in the structure.
1250 If the field does not exist or is not of the type requested,
1251 the value returned is undefined.
1252 """
1253 return _bt_ctf_get_struct_field_count(self._d)
1254
1255 def _get_struct_field_at(self, i):
1256 """
1257 Return the structure's field at position i.
1258 If the field does not exist or is not of the type requested,
1259 the value returned is undefined. To check if an error occurred,
1260 use the field_error() function after accessing a field.
1261 """
1262 return _bt_ctf_get_struct_field_index(self._d, i)
1263
1264 @property
1265 def value(self):
1266 """
1267 Return the value associated with the field according to its type.
1268 Return None on error.
1269 """
1270 id = self.type
1271 value = None
1272
1273 if id == CTFTypeId.STRING:
1274 value = self._get_str()
1275 elif id == CTFTypeId.ARRAY:
1276 element_decl = self.declaration.element_declaration
1277 if ((element_decl.type == CTFTypeId.INTEGER
1278 and element_decl.length == 8)
1279 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1280 value = _bt_python_get_array_string(self._d)
1281 else:
1282 value = []
1283 for i in range(self.declaration.length):
1284 element = self._get_array_element_at(i)
1285 value.append(element.value)
1286 elif id == CTFTypeId.INTEGER:
1287 if self.declaration.signedness == 0:
1288 value = self._get_uint64()
1289 else:
1290 value = self._get_int64()
1291 elif id == CTFTypeId.ENUM:
1292 value = self._get_enum_str()
1293 elif id == CTFTypeId.SEQUENCE:
1294 element_decl = self.declaration.element_declaration
1295 if ((element_decl.type == CTFTypeId.INTEGER
1296 and element_decl.length == 8)
1297 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1298 value = _bt_python_get_sequence_string(self._d)
1299 else:
1300 seq_len = self._get_sequence_len()
1301 value = []
1302 for i in range(seq_len):
1303 evDef = self._get_sequence_element_at(i)
1304 value.append(evDef.value)
1305 elif id == CTFTypeId.FLOAT:
1306 value = self._get_float()
1307 elif id == CTFTypeId.VARIANT:
1308 variant = _Definition.__new__(_Definition)
1309 variant._d = self._get_variant()
1310 value = variant.value
1311 elif id == CTFTypeId.STRUCT:
1312 value = {}
1313 for i in range(self._get_struct_field_count()):
1314 member = _Definition(self._get_struct_field_at(i), self.scope)
1315 value[member.name] = member.value
1316
1317 if field_error():
1318 raise FieldError(
1319 "Error occurred while accessing field {} of type {}".format(
1320 self.name,
1321 CTFTypeId.type_name(id)))
1322 return value
1323
1324 @property
1325 def scope(self):
1326 """Return the scope of a field or None on error."""
1327 return self._s
78d714e8 1328
24a3136a
DS
1329%}
1330
b7d5d20c 1331/* CTF Writer */
ec8c88d7 1332
93ccbea6 1333/* clock.h */
ec8c88d7 1334%rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
b0bb560c
JG
1335%rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1336%rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
ec8c88d7 1337%rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
b0bb560c 1338%rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
ec8c88d7 1339%rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
b0bb560c 1340%rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
ec8c88d7 1341%rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
b0bb560c 1342%rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
ec8c88d7 1343%rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
b0bb560c 1344%rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
ec8c88d7 1345%rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
b0bb560c 1346%rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
ec8c88d7 1347%rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
b0bb560c 1348%rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
ec8c88d7
JG
1349%rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1350%rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1351%rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1352
1353struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
b0bb560c
JG
1354const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1355const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
ec8c88d7 1356int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
b0bb560c 1357uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
ec8c88d7 1358int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
b0bb560c 1359uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
ec8c88d7 1360int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
b0bb560c 1361uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
ec8c88d7 1362int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
b0bb560c 1363uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
ec8c88d7 1364int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
b0bb560c 1365int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
ec8c88d7 1366int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
b0bb560c 1367uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
ec8c88d7
JG
1368int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1369void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1370void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1371
93ccbea6 1372/* event-types.h */
ec8c88d7 1373%rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
b4b5e4b5
JG
1374%rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1375%rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
ec8c88d7 1376%rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
b4b5e4b5 1377%rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
ec8c88d7 1378%rename("_bt_ctf_field_type_integer_set_base") bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
b4b5e4b5 1379%rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
ec8c88d7
JG
1380%rename("_bt_ctf_field_type_integer_set_encoding") bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1381%rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
b4b5e4b5
JG
1382%rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1383%rename("_bt_ctf_field_type_enumeration_add_mapping") bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *name, int64_t range_start, int64_t range_end);
1384%rename("_bt_ctf_field_type_enumeration_add_mapping_unsigned") bt_ctf_field_type_enumeration_add_mapping_unsigned(struct bt_ctf_field_type *enumeration, const char *name, uint64_t range_start, uint64_t range_end);
1385%rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1386%rename("_bt_ctf_field_type_enumeration_get_mapping") bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, size_t index, const char **name, int64_t *range_start, int64_t *range_end);
1387%rename("_bt_ctf_field_type_enumeration_get_mapping_unsigned") bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, size_t index, const char **name, uint64_t *range_start, uint64_t *range_end);
1388%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_name") bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *index);
1389%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_value") bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *index);
1390%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value") bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *index);
ec8c88d7 1391%rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
b4b5e4b5 1392%rename("_bt_ctf_field_type_floating_point_get_exponent_digits") bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
ec8c88d7 1393%rename("_bt_ctf_field_type_floating_point_set_exponent_digits") bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
b4b5e4b5 1394%rename("_bt_ctf_field_type_floating_point_get_mantissa_digits") bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
ec8c88d7
JG
1395%rename("_bt_ctf_field_type_floating_point_set_mantissa_digits") bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1396%rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1397%rename("_bt_ctf_field_type_structure_add_field") bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name);
b4b5e4b5
JG
1398%rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1399%rename("_bt_ctf_field_type_structure_get_field") bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1400%rename("_bt_ctf_field_type_structure_get_field_type_by_name") bt_ctf_field_type_structure_get_field_type_by_name(struct bt_ctf_field_type *structure, const char *field_name);
ec8c88d7 1401%rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
b4b5e4b5
JG
1402%rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1403%rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
ec8c88d7 1404%rename("_bt_ctf_field_type_variant_add_field") bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field_type, const char *field_name);
b4b5e4b5
JG
1405%rename("_bt_ctf_field_type_variant_get_field_type_by_name") bt_ctf_field_type_variant_get_field_type_by_name(struct bt_ctf_field_type *variant, const char *field_name);
1406%rename("_bt_ctf_field_type_variant_get_field_type_from_tag") bt_ctf_field_type_variant_get_field_type_from_tag(struct bt_ctf_field_type *variant, struct bt_ctf_field *tag);
1407%rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1408%rename("_bt_ctf_field_type_variant_get_field") bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
ec8c88d7 1409%rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
b4b5e4b5
JG
1410%rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1411%rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
ec8c88d7 1412%rename("_bt_ctf_field_type_sequence_create") bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
b4b5e4b5
JG
1413%rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1414%rename("_bt_ctf_field_type_sequence_get_length_field_name") bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
ec8c88d7 1415%rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
b4b5e4b5
JG
1416%rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1417%rename("_bt_ctf_field_type_string_set_encoding") bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1418%rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
ec8c88d7 1419%rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
b4b5e4b5 1420%rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
ec8c88d7 1421%rename("_bt_ctf_field_type_set_byte_order") bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
b4b5e4b5 1422%rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
ec8c88d7
JG
1423%rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1424%rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1425
1426struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
b4b5e4b5
JG
1427int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1428int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
ec8c88d7 1429int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
b4b5e4b5 1430enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
ec8c88d7 1431int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
b4b5e4b5 1432enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
ec8c88d7
JG
1433int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1434struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
b4b5e4b5
JG
1435struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1436int bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *name, int64_t range_start, int64_t range_end);
1437int bt_ctf_field_type_enumeration_add_mapping_unsigned(struct bt_ctf_field_type *enumeration, const char *name, uint64_t range_start, uint64_t range_end);
1438int64_t bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1439int bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, size_t index, const char **OUTPUT, int64_t *OUTPUT, int64_t *OUTPUT);
1440int bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, size_t index, const char **OUTPUT, uint64_t *OUTPUT, uint64_t *OUTPUT);
1441int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *OUTPUT);
1442int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *OUTPUT);
1443int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *OUTPUT);
ec8c88d7 1444struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
b4b5e4b5 1445int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
ec8c88d7 1446int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
b4b5e4b5 1447int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
ec8c88d7
JG
1448int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1449struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1450int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name);
b4b5e4b5
JG
1451int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1452int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, size_t index);
1453struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name(struct bt_ctf_field_type *structure, const char *field_name);
ec8c88d7 1454struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
b4b5e4b5
JG
1455struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1456const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
ec8c88d7 1457int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field_type, const char *field_name);
b4b5e4b5
JG
1458struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name(struct bt_ctf_field_type *variant, const char *field_name);
1459struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag(struct bt_ctf_field_type *variant, struct bt_ctf_field *tag);
1460int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1461int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, size_t index);
ec8c88d7 1462struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
b4b5e4b5
JG
1463struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1464int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
ec8c88d7 1465struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
b4b5e4b5
JG
1466struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1467const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
ec8c88d7 1468struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
b4b5e4b5
JG
1469enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1470int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1471int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
ec8c88d7 1472int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
b4b5e4b5 1473enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
ec8c88d7 1474int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
b4b5e4b5 1475enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
ec8c88d7
JG
1476void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1477void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1478
93ccbea6 1479/* event-fields.h */
ec8c88d7
JG
1480%rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1481%rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1482%rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
821ca76c 1483%rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
ec8c88d7
JG
1484%rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1485%rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1486%rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1487%rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
821ca76c
JG
1488%rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1489%rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
ec8c88d7 1490%rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
821ca76c 1491%rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
ec8c88d7 1492%rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
821ca76c 1493%rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
ec8c88d7 1494%rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
b4b5e4b5
JG
1495%rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1496%rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
821ca76c 1497%rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
ec8c88d7
JG
1498%rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1499%rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1500
1501struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1502struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1503struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
821ca76c 1504struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
ec8c88d7
JG
1505int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1506struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1507struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1508struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
821ca76c
JG
1509const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1510int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
ec8c88d7 1511int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
821ca76c 1512int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
ec8c88d7 1513int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
821ca76c 1514int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
ec8c88d7 1515int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
b4b5e4b5
JG
1516const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1517int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
821ca76c 1518struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
ec8c88d7
JG
1519void bt_ctf_field_get(struct bt_ctf_field *field);
1520void bt_ctf_field_put(struct bt_ctf_field *field);
1521
93ccbea6 1522/* event-class.h */
ec8c88d7 1523%rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
38f28df6
JG
1524%rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1525%rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1526%rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1527%rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
ec8c88d7 1528%rename("_bt_ctf_event_class_add_field") bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
38f28df6
JG
1529%rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1530%rename("_bt_ctf_event_class_get_field") bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1531%rename("_bt_ctf_event_class_get_field_by_name") bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
ec8c88d7
JG
1532%rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1533%rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
ec8c88d7
JG
1534
1535struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
38f28df6
JG
1536const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1537int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1538int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1539struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
ec8c88d7 1540int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
38f28df6
JG
1541int64_t bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1542int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1543struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
ec8c88d7
JG
1544void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1545void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
93ccbea6
JG
1546
1547/* event.h */
1548%rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1549%rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
1550%rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
1551%rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1552%rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1553%rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1554%rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1555%rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1556
ec8c88d7 1557struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
38f28df6
JG
1558struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
1559struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
ec8c88d7 1560struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
38f28df6
JG
1561int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1562struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
ec8c88d7
JG
1563void bt_ctf_event_get(struct bt_ctf_event *event);
1564void bt_ctf_event_put(struct bt_ctf_event *event);
1565
93ccbea6 1566/* stream-class.h */
ec8c88d7 1567%rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
f6c2aa83
JG
1568%rename("_bt_ctf_stream_class_get_name") bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1569%rename("_bt_ctf_stream_class_get_clock") bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
ec8c88d7 1570%rename("_bt_ctf_stream_class_set_clock") bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
f6c2aa83
JG
1571%rename("_bt_ctf_stream_class_get_id") bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1572%rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
ec8c88d7 1573%rename("_bt_ctf_stream_class_add_event_class") bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
f6c2aa83
JG
1574%rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1575%rename("_bt_ctf_stream_class_get_event_class") bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index);
1576%rename("_bt_ctf_stream_class_get_event_class_by_name") bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
7df927c7
JG
1577%rename("_bt_ctf_stream_class_get_packet_context_type") bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1578%rename("_bt_ctf_stream_class_set_packet_context_type") bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
ec8c88d7
JG
1579%rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1580%rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
ec8c88d7
JG
1581
1582struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
f6c2aa83
JG
1583const char *bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1584struct bt_ctf_clock *bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
ec8c88d7 1585int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
f6c2aa83
JG
1586int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1587int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
ec8c88d7 1588int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
f6c2aa83
JG
1589int64_t bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1590struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index);
1591struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
7df927c7
JG
1592struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1593int bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
ec8c88d7
JG
1594void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1595void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
93ccbea6
JG
1596
1597/* stream.h */
1598%rename("_bt_ctf_stream_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
1599%rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1600%rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1601%rename("_bt_ctf_stream_get_packet_context") bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1602%rename("_bt_ctf_stream_set_packet_context") bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
1603%rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1604%rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1605%rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1606
708e628a 1607int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
ec8c88d7
JG
1608void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1609int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
7df927c7
JG
1610struct bt_ctf_field *bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1611int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
ec8c88d7
JG
1612int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1613void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1614void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1615
93ccbea6 1616/* writer.h */
ec8c88d7
JG
1617%rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1618%rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1619%rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1620%rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1621%newobject bt_ctf_writer_get_metadata_string;
1622%rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1623%rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1624%rename("_bt_ctf_writer_set_byte_order") bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1625%rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1626%rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1627
1628struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1629struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1630int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1631int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1632char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1633void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1634int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1635void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1636void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1637
1638%pythoncode %{
be02a6e6
JG
1639
1640from uuid import UUID
1641
ec8c88d7
JG
1642
1643class CTFWriter:
be02a6e6
JG
1644 # Used to compare to -1ULL in error checks
1645 _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
ec8c88d7 1646
be02a6e6 1647 """
b4b5e4b5
JG
1648 Enumeration mapping class. start and end values are inclusive.
1649 """
be02a6e6 1650 class EnumerationMapping:
b4b5e4b5 1651
be02a6e6
JG
1652 def __init__(self, name, start, end):
1653 self.name = name
1654 self.start = start
1655 self.end = end
ec8c88d7 1656
be02a6e6 1657 class Clock:
ec8c88d7 1658
be02a6e6
JG
1659 def __init__(self, name):
1660 self._c = _bt_ctf_clock_create(name)
1661 if self._c is None:
1662 raise ValueError("Invalid clock name.")
1663
1664 def __del__(self):
1665 _bt_ctf_clock_put(self._c)
1666
1667 """
b0bb560c
JG
1668 Get the clock's name.
1669 """
be02a6e6
JG
1670 @property
1671 def name(self):
1672 name = _bt_ctf_clock_get_name(self._c)
1673 if name is None:
1674 raise ValueError("Invalid clock instance.")
1675 return name
b0bb560c 1676
be02a6e6 1677 """
b0bb560c 1678 Get the clock's description. None if unset.
14001277 1679 """
be02a6e6
JG
1680 @property
1681 def description(self):
1682 return _bt_ctf_clock_get_description(self._c)
14001277 1683
be02a6e6 1684 """
ec8c88d7
JG
1685 Set the clock's description. The description appears in the clock's TSDL
1686 meta-data.
1687 """
be02a6e6
JG
1688 @description.setter
1689 def description(self, desc):
1690 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1691 if ret < 0:
1692 raise ValueError("Invalid clock description.")
ec8c88d7 1693
be02a6e6 1694 """
14001277
JG
1695 Get the clock's frequency (Hz).
1696 """
be02a6e6
JG
1697 @property
1698 def frequency(self):
1699 freq = _bt_ctf_clock_get_frequency(self._c)
1700 if freq == CTFWriter._MAX_UINT64:
1701 raise ValueError("Invalid clock instance")
1702 return freq
14001277 1703
be02a6e6 1704 """
ec8c88d7
JG
1705 Set the clock's frequency (Hz).
1706 """
be02a6e6
JG
1707 @frequency.setter
1708 def frequency(self, freq):
1709 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1710 if ret < 0:
1711 raise ValueError("Invalid frequency value.")
ec8c88d7 1712
be02a6e6 1713 """
14001277
JG
1714 Get the clock's precision (in clock ticks).
1715 """
be02a6e6
JG
1716 @property
1717 def precision(self):
1718 precision = _bt_ctf_clock_get_precision(self._c)
1719 if precision == CTFWriter._MAX_UINT64:
1720 raise ValueError("Invalid clock instance")
1721 return precision
14001277 1722
be02a6e6 1723 """
ec8c88d7
JG
1724 Set the clock's precision (in clock ticks).
1725 """
be02a6e6
JG
1726 @precision.setter
1727 def precision(self, precision):
1728 ret = _bt_ctf_clock_set_precision(self._c, precision)
ec8c88d7 1729
be02a6e6 1730 """
14001277
JG
1731 Get the clock's offset in seconds from POSIX.1 Epoch.
1732 """
be02a6e6
JG
1733 @property
1734 def offset_seconds(self):
1735 offset_s = _bt_ctf_clock_get_offset_s(self._c)
1736 if offset_s == CTFWriter._MAX_UINT64:
1737 raise ValueError("Invalid clock instance")
1738 return offset_s
14001277 1739
be02a6e6 1740 """
ec8c88d7
JG
1741 Set the clock's offset in seconds from POSIX.1 Epoch.
1742 """
be02a6e6
JG
1743 @offset_seconds.setter
1744 def offset_seconds(self, offset_s):
1745 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1746 if ret < 0:
1747 raise ValueError("Invalid offset value.")
ec8c88d7 1748
be02a6e6 1749 """
14001277
JG
1750 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1751 """
be02a6e6
JG
1752 @property
1753 def offset(self):
1754 offset = _bt_ctf_clock_get_offset(self._c)
1755 if offset == CTFWriter._MAX_UINT64:
1756 raise ValueError("Invalid clock instance")
1757 return offset
14001277 1758
be02a6e6 1759 """
ec8c88d7
JG
1760 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1761 """
be02a6e6
JG
1762 @offset.setter
1763 def offset(self, offset):
1764 ret = _bt_ctf_clock_set_offset(self._c, offset)
1765 if ret < 0:
1766 raise ValueError("Invalid offset value.")
ec8c88d7 1767
be02a6e6 1768 """
14001277
JG
1769 Get a clock's absolute attribute. A clock is absolute if the clock
1770 is a global reference across the trace's other clocks.
1771 """
be02a6e6
JG
1772 @property
1773 def absolute(self):
1774 is_absolute = _bt_ctf_clock_get_is_absolute(self._c)
1775 if is_absolute == -1:
1776 raise ValueError("Invalid clock instance")
1777 return False if is_absolute == 0 else True
14001277 1778
be02a6e6 1779 """
ec8c88d7
JG
1780 Set a clock's absolute attribute. A clock is absolute if the clock
1781 is a global reference across the trace's other clocks.
1782 """
be02a6e6
JG
1783 @absolute.setter
1784 def absolute(self, is_absolute):
1785 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1786 if ret < 0:
1787 raise ValueError(
1788 "Could not set the clock's absolute attribute.")
ec8c88d7 1789
be02a6e6 1790 """
da64442f
JG
1791 Get a clock's UUID (an object of type UUID).
1792 """
be02a6e6
JG
1793 @property
1794 def uuid(self):
1795 uuid_list = []
1796 for i in range(16):
1797 ret, value = _bt_python_ctf_clock_get_uuid_index(self._c, i)
1798 if ret < 0:
1799 raise ValueError("Invalid clock instance")
1800 uuid_list.append(value)
1801 return UUID(bytes=bytes(uuid_list))
1802
1803 """
da64442f
JG
1804 Set a clock's UUID (an object of type UUID).
1805 """
be02a6e6
JG
1806 @uuid.setter
1807 def uuid(self, uuid):
1808 uuid_bytes = uuid.bytes
1809 if len(uuid_bytes) != 16:
1810 raise ValueError(
1811 "Invalid UUID provided. UUID length must be 16 bytes")
1812 for i in range(len(uuid_bytes)):
1813 ret = _bt_python_ctf_clock_set_uuid_index(
1814 self._c,
1815 i,
1816 uuid_bytes[i])
1817 if ret < 0:
1818 raise ValueError("Invalid clock instance")
1819
1820 """
14001277
JG
1821 Get the current time in nanoseconds since the clock's origin (offset and
1822 offset_s attributes).
1823 """
be02a6e6
JG
1824 @property
1825 def time(self):
1826 time = _bt_ctf_clock_get_time(self._c)
1827 if time == CTFWriter._MAX_UINT64:
1828 raise ValueError("Invalid clock instance")
1829 return time
14001277 1830
be02a6e6 1831 """
ec8c88d7
JG
1832 Set the current time in nanoseconds since the clock's origin (offset and
1833 offset_s attributes). The clock's value will be sampled as events are
1834 appended to a stream.
1835 """
be02a6e6
JG
1836 @time.setter
1837 def time(self, time):
1838 ret = _bt_ctf_clock_set_time(self._c, time)
1839 if ret < 0:
1840 raise ValueError("Invalid time value.")
1841
1842 class FieldDeclaration:
1843
1844 """
1845 FieldDeclaration should not be instantiated directly. Instantiate
1846 one of the concrete FieldDeclaration classes.
1847 """
1848 class IntegerBase:
1849 # These values are based on the bt_ctf_integer_base enum
1850 # declared in event-types.h.
1851 INTEGER_BASE_UNKNOWN = -1
1852 INTEGER_BASE_BINARY = 2
1853 INTEGER_BASE_OCTAL = 8
1854 INTEGER_BASE_DECIMAL = 10
1855 INTEGER_BASE_HEXADECIMAL = 16
1856
1857 def __init__(self):
1858 if self._ft is None:
1859 raise ValueError("FieldDeclaration creation failed.")
1860
1861 def __del__(self):
1862 _bt_ctf_field_type_put(self._ft)
1863
1864 @staticmethod
1865 def _create_field_declaration_from_native_instance(
1866 native_field_declaration):
1867 type_dict = {
1868 CTFTypeId.INTEGER: CTFWriter.IntegerFieldDeclaration,
1869 CTFTypeId.FLOAT: CTFWriter.FloatFieldDeclaration,
1870 CTFTypeId.ENUM: CTFWriter.EnumerationFieldDeclaration,
1871 CTFTypeId.STRING: CTFWriter.StringFieldDeclaration,
1872 CTFTypeId.STRUCT: CTFWriter.StructureFieldDeclaration,
1873 CTFTypeId.VARIANT: CTFWriter.VariantFieldDeclaration,
1874 CTFTypeId.ARRAY: CTFWriter.ArrayFieldDeclaration,
1875 CTFTypeId.SEQUENCE: CTFWriter.SequenceFieldDeclaration
1876 }
1877
1878 field_type_id = _bt_ctf_field_type_get_type_id(
1879 native_field_declaration)
1880 if field_type_id == CTFTypeId.UNKNOWN:
1881 raise TypeError("Invalid field instance")
1882
1883 declaration = CTFWriter.Field.__new__(CTFWriter.Field)
1884 declaration._ft = native_field_declaration
1885 declaration.__class__ = type_dict[field_type_id]
1886 return declaration
1887
1888 """
b4b5e4b5 1889 Get the field declaration's alignment. Returns -1 on error.
14001277 1890 """
be02a6e6
JG
1891 @property
1892 def alignment(self):
1893 return _bt_ctf_field_type_get_alignment(self._ft)
14001277 1894
be02a6e6 1895 """
b4b5e4b5 1896 Set the field declaration's alignment. Defaults to 1 (bit-aligned). However,
ec8c88d7
JG
1897 some types, such as structures and string, may impose other alignment
1898 constraints.
1899 """
be02a6e6
JG
1900 @alignment.setter
1901 def alignment(self, alignment):
1902 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1903 if ret < 0:
1904 raise ValueError("Invalid alignment value.")
ec8c88d7 1905
be02a6e6 1906 """
b4b5e4b5 1907 Get the field declaration's byte order. One of the ByteOrder's constant.
14001277 1908 """
be02a6e6
JG
1909 @property
1910 def byte_order(self):
1911 return _bt_ctf_field_type_get_byte_order(self._ft)
14001277 1912
be02a6e6 1913 """
b4b5e4b5 1914 Set the field declaration's byte order. Use constants defined in the ByteOrder
ec8c88d7
JG
1915 class.
1916 """
be02a6e6
JG
1917 @byte_order.setter
1918 def byte_order(self, byte_order):
1919 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1920 if ret < 0:
1921 raise ValueError("Could not set byte order value.")
ec8c88d7 1922
be02a6e6 1923 class IntegerFieldDeclaration(FieldDeclaration):
ec8c88d7 1924
be02a6e6
JG
1925 """
1926 Create a new integer field declaration of the given size.
1927 """
1928
1929 def __init__(self, size):
1930 self._ft = _bt_ctf_field_type_integer_create(size)
1931 super().__init__()
1932
1933 """
b4b5e4b5
JG
1934 Get an integer's size.
1935 """
be02a6e6
JG
1936 @property
1937 def size(self):
1938 ret = _bt_ctf_field_type_integer_get_size(self._ft)
1939 if ret < 0:
1940 raise ValueError("Could not get Integer's size attribute.")
1941 else:
1942 return ret
b4b5e4b5 1943
be02a6e6 1944 """
14001277
JG
1945 Get an integer's signedness attribute.
1946 """
be02a6e6
JG
1947 @property
1948 def signed(self):
1949 ret = _bt_ctf_field_type_integer_get_signed(self._ft)
1950 if ret < 0:
1951 raise ValueError("Could not get Integer's signed attribute.")
1952 elif ret > 0:
1953 return True
1954 else:
1955 return False
1956
1957 """
14001277 1958 Set an integer's signedness attribute.
ec8c88d7 1959 """
be02a6e6
JG
1960 @signed.setter
1961 def signed(self, signed):
1962 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1963 if ret < 0:
1964 raise ValueError("Could not set Integer's signed attribute.")
ec8c88d7 1965
be02a6e6 1966 """
14001277 1967 Get the integer's base used to pretty-print the resulting trace.
b4b5e4b5 1968 Returns a constant from the FieldDeclaration.IntegerBase class.
14001277 1969 """
be02a6e6
JG
1970 @property
1971 def base(self):
1972 return _bt_ctf_field_type_integer_get_base(self._ft)
14001277 1973
be02a6e6 1974 """
14001277 1975 Set the integer's base used to pretty-print the resulting trace.
b4b5e4b5 1976 The base must be a constant of the FieldDeclarationIntegerBase class.
ec8c88d7 1977 """
be02a6e6
JG
1978 @base.setter
1979 def base(self, base):
1980 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1981 if ret < 0:
1982 raise ValueError("Could not set Integer's base.")
ec8c88d7 1983
be02a6e6 1984 """
14001277
JG
1985 Get the integer's encoding (one of the constants of the
1986 CTFStringEncoding class).
b4b5e4b5 1987 Returns a constant from the CTFStringEncoding class.
14001277 1988 """
be02a6e6
JG
1989 @property
1990 def encoding(self):
1991 return _bt_ctf_field_type_integer_get_encoding(self._ft)
14001277 1992
be02a6e6 1993 """
ec8c88d7
JG
1994 An integer encoding may be set to signal that the integer must be printed
1995 as a text character. Must be a constant from the CTFStringEncoding class.
1996 """
be02a6e6
JG
1997 @encoding.setter
1998 def encoding(self, encoding):
1999 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
2000 if ret < 0:
2001 raise ValueError("Could not set Integer's encoding.")
ec8c88d7 2002
be02a6e6 2003 class EnumerationFieldDeclaration(FieldDeclaration):
ec8c88d7 2004
be02a6e6
JG
2005 """
2006 Create a new enumeration field declaration with the given underlying container type.
2007 """
ec8c88d7 2008
be02a6e6
JG
2009 def __init__(self, integer_type):
2010 if integer_type is None or not isinstance(
2011 integer_type, CTFWriter.IntegerFieldDeclaration):
2012 raise TypeError("Invalid integer container.")
2013
2014 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
2015 super().__init__()
2016
2017 """
b4b5e4b5
JG
2018 Get the enumeration's underlying container type.
2019 """
be02a6e6
JG
2020 @property
2021 def container(self):
2022 ret = _bt_ctf_field_type_enumeration_get_container_type(self._ft)
2023 if ret is None:
2024 raise TypeError("Invalid enumeration declaration")
2025 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2026 ret)
b4b5e4b5 2027
be02a6e6 2028 """
ec8c88d7
JG
2029 Add a mapping to the enumeration. The range's values are inclusive.
2030 """
b4b5e4b5 2031
be02a6e6
JG
2032 def add_mapping(self, name, range_start, range_end):
2033 if range_start < 0 or range_end < 0:
2034 ret = _bt_ctf_field_type_enumeration_add_mapping(
2035 self._ft,
2036 str(name),
2037 range_start,
2038 range_end)
2039 else:
2040 ret = _bt_ctf_field_type_enumeration_add_mapping_unsigned(
2041 self._ft,
2042 str(name),
2043 range_start,
2044 range_end)
2045
2046 if ret < 0:
2047 raise ValueError(
2048 "Could not add mapping to enumeration declaration.")
2049
2050 """
b4b5e4b5
JG
2051 Generator returning instances of EnumerationMapping.
2052 """
be02a6e6
JG
2053 @property
2054 def mappings(self):
2055 signed = self.container.signed
2056
2057 count = _bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
2058 for i in range(count):
2059 if signed:
2060 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2061 self._ft,
2062 i)
2063 else:
2064 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2065 self._ft,
2066 i)
2067
2068 if len(ret) != 3:
2069 raise TypeError(
2070 "Could not get Enumeration mapping at index {}".format(i))
2071 name, range_start, range_end = ret
2072 yield CTFWriter.EnumerationMapping(name, range_start, range_end)
2073
2074 """
b4b5e4b5
JG
2075 Get a mapping by name (EnumerationMapping).
2076 """
b4b5e4b5 2077
be02a6e6
JG
2078 def get_mapping_by_name(self, name):
2079 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name(
2080 self._ft, name)
2081 if ret < 0:
2082 return None
2083
2084 if self.container.signed:
2085 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2086 self._ft,
2087 index)
2088 else:
2089 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2090 self._ft,
2091 index)
2092
2093 if len(ret) != 3:
2094 raise TypeError(
2095 "Could not get Enumeration mapping at index {}".format(i))
2096 name, range_start, range_end = ret
2097 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2098
2099 """
b4b5e4b5
JG
2100 Get a mapping by value (EnumerationMapping).
2101 """
b4b5e4b5 2102
be02a6e6
JG
2103 def get_mapping_by_value(self, value):
2104 if value < 0:
2105 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value(
2106 self._ft, value)
2107 else:
2108 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(
2109 self._ft, value)
2110
2111 if ret < 0:
2112 return None
2113
2114 if self.container.signed:
2115 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2116 self._ft,
2117 index)
2118 else:
2119 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2120 self._ft,
2121 index)
2122
2123 if len(ret) != 3:
2124 raise TypeError(
2125 "Could not get Enumeration mapping at index {}".format(i))
2126 name, range_start, range_end = ret
2127 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2128
2129 class FloatFieldDeclaration(FieldDeclaration):
2130 FLT_EXP_DIG = 8
2131 DBL_EXP_DIG = 11
2132 FLT_MANT_DIG = 24
2133 DBL_MANT_DIG = 53
2134
2135 """
b4b5e4b5 2136 Create a new floating point field declaration.
ec8c88d7 2137 """
ec8c88d7 2138
be02a6e6
JG
2139 def __init__(self):
2140 self._ft = _bt_ctf_field_type_floating_point_create()
2141 super().__init__()
2142
2143 """
b4b5e4b5 2144 Get the number of exponent digits used to store the floating point field.
14001277 2145 """
be02a6e6
JG
2146 @property
2147 def exponent_digits(self):
2148 ret = _bt_ctf_field_type_floating_point_get_exponent_digits(
2149 self._ft)
2150 if ret < 0:
2151 raise TypeError(
2152 "Could not get Floating point exponent digit count")
2153 return ret
14001277 2154
be02a6e6 2155 """
14001277 2156 Set the number of exponent digits to use to store the floating point field.
ec8c88d7
JG
2157 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
2158 are defined as constants of this class.
2159 """
be02a6e6
JG
2160 @exponent_digits.setter
2161 def exponent_digits(self, exponent_digits):
2162 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(
2163 self._ft,
2164 exponent_digits)
2165 if ret < 0:
2166 raise ValueError("Could not set exponent digit count.")
ec8c88d7 2167
be02a6e6 2168 """
b4b5e4b5 2169 Get the number of mantissa digits used to store the floating point field.
14001277 2170 """
be02a6e6
JG
2171 @property
2172 def mantissa_digits(self):
2173 ret = _bt_ctf_field_type_floating_point_get_mantissa_digits(
2174 self._ft)
2175 if ret < 0:
2176 raise TypeError(
2177 "Could not get Floating point mantissa digit count")
2178 return ret
14001277 2179
be02a6e6 2180 """
14001277 2181 Set the number of mantissa digits to use to store the floating point field.
ec8c88d7
JG
2182 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
2183 are defined as constants of this class.
2184 """
be02a6e6
JG
2185 @mantissa_digits.setter
2186 def mantissa_digits(self, mantissa_digits):
2187 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(
2188 self._ft,
2189 mantissa_digits)
2190 if ret < 0:
2191 raise ValueError("Could not set mantissa digit count.")
ec8c88d7 2192
be02a6e6 2193 class StructureFieldDeclaration(FieldDeclaration):
ec8c88d7 2194
be02a6e6
JG
2195 """
2196 Create a new structure field declaration.
2197 """
2198
2199 def __init__(self):
2200 self._ft = _bt_ctf_field_type_structure_create()
2201 super().__init__()
2202
2203 """
ec8c88d7
JG
2204 Add a field of type "field_type" to the structure.
2205 """
ec8c88d7 2206
be02a6e6
JG
2207 def add_field(self, field_type, field_name):
2208 ret = _bt_ctf_field_type_structure_add_field(
2209 self._ft,
2210 field_type._ft,
2211 str(field_name))
2212 if ret < 0:
2213 raise ValueError("Could not add field to structure.")
2214
2215 """
b4b5e4b5
JG
2216 Generator returning the structure's field as tuples of (field name, field declaration).
2217 """
be02a6e6
JG
2218 @property
2219 def fields(self):
2220 count = _bt_ctf_field_type_structure_get_field_count(self._ft)
2221 if count < 0:
2222 raise TypeError("Could not get Structure field count")
2223
2224 for i in range(count):
2225 field_name = _bt_python_ctf_field_type_structure_get_field_name(
2226 self._ft,
2227 i)
2228 if field_name is None:
2229 raise TypeError(
2230 "Could not get Structure field name at index {}".format(i))
2231
2232 field_type_native = _bt_python_ctf_field_type_structure_get_field_type(
2233 self._ft,
2234 i)
2235 if field_type_native is None:
2236 raise TypeError(
2237 "Could not get Structure field type at index {}".format(i))
2238
2239 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2240 field_type_native)
2241 yield (field_name, field_type)
2242
2243 """
2244 Get a field declaration by name (FieldDeclaration).
2245 """
b4b5e4b5 2246
be02a6e6
JG
2247 def get_field_by_name(self, name):
2248 field_type_native = _bt_ctf_field_type_structure_get_field_type_by_name(
2249 self._ft,
2250 name)
2251 if field_type_native is None:
2252 raise TypeError(
2253 "Could not find Structure field with name {}".format(name))
b4b5e4b5 2254
be02a6e6
JG
2255 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2256 field_type_native)
b4b5e4b5 2257
be02a6e6 2258 class VariantFieldDeclaration(FieldDeclaration):
b4b5e4b5 2259
be02a6e6
JG
2260 """
2261 Create a new variant field declaration.
2262 """
b4b5e4b5 2263
be02a6e6
JG
2264 def __init__(self, enum_tag, tag_name):
2265 if enum_tag is None or not isinstance(
2266 enum_tag, CTFWriter.EnumerationFieldDeclaration):
2267 raise TypeError(
2268 "Invalid tag type; must be of type EnumerationFieldDeclaration.")
ec8c88d7 2269
be02a6e6
JG
2270 self._ft = _bt_ctf_field_type_variant_create(
2271 enum_tag._ft,
2272 str(tag_name))
2273 super().__init__()
ec8c88d7 2274
be02a6e6 2275 """
b4b5e4b5
JG
2276 Get the variant's tag name.
2277 """
be02a6e6
JG
2278 @property
2279 def tag_name(self):
2280 ret = _bt_ctf_field_type_variant_get_tag_name(self._ft)
2281 if ret is None:
2282 raise TypeError("Could not get Variant tag name")
2283 return ret
b4b5e4b5 2284
be02a6e6 2285 """
b4b5e4b5
JG
2286 Get the variant's tag type.
2287 """
be02a6e6
JG
2288 @property
2289 def tag_type(self):
2290 ret = _bt_ctf_field_type_variant_get_tag_type(self._ft)
2291 if ret is None:
2292 raise TypeError("Could not get Variant tag type")
2293 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2294 ret)
b4b5e4b5 2295
be02a6e6 2296 """
ec8c88d7
JG
2297 Add a field of type "field_type" to the variant.
2298 """
b4b5e4b5 2299
be02a6e6
JG
2300 def add_field(self, field_type, field_name):
2301 ret = _bt_ctf_field_type_variant_add_field(
2302 self._ft,
2303 field_type._ft,
2304 str(field_name))
2305 if ret < 0:
2306 raise ValueError("Could not add field to variant.")
b4b5e4b5 2307
be02a6e6
JG
2308 """
2309 Generator returning the variant's field as tuples of (field name, field declaration).
b4b5e4b5 2310 """
be02a6e6
JG
2311 @property
2312 def fields(self):
2313 count = _bt_ctf_field_type_variant_get_field_count(self._ft)
2314 if count < 0:
2315 raise TypeError("Could not get Variant field count")
2316
2317 for i in range(count):
2318 field_name = _bt_python_ctf_field_type_variant_get_field_name(
2319 self._ft,
2320 i)
2321 if field_name is None:
2322 raise TypeError(
2323 "Could not get Variant field name at index {}".format(i))
2324
2325 field_type_native = _bt_python_ctf_field_type_variant_get_field_type(
2326 self._ft,
2327 i)
2328 if field_type_native is None:
2329 raise TypeError(
2330 "Could not get Variant field type at index {}".format(i))
2331
2332 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2333 field_type_native)
2334 yield (field_name, field_type)
2335
2336 """
b4b5e4b5
JG
2337 Get a field declaration by name (FieldDeclaration).
2338 """
b4b5e4b5 2339
be02a6e6
JG
2340 def get_field_by_name(self, name):
2341 field_type_native = _bt_ctf_field_type_variant_get_field_type_by_name(
2342 self._ft,
2343 name)
2344 if field_type_native is None:
2345 raise TypeError(
2346 "Could not find Variant field with name {}".format(name))
b4b5e4b5 2347
be02a6e6
JG
2348 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2349 field_type_native)
2350
2351 """
b4b5e4b5
JG
2352 Get a field declaration from tag (EnumerationField).
2353 """
b4b5e4b5 2354
be02a6e6
JG
2355 def get_field_from_tag(self, tag):
2356 field_type_native = _bt_ctf_field_type_variant_get_field_type_from_tag(
2357 self._ft,
2358 tag._f)
2359 if field_type_native is None:
2360 raise TypeError(
2361 "Could not find Variant field with tag value {}".format(
2362 tag.value))
b4b5e4b5 2363
be02a6e6
JG
2364 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2365 field_type_native)
ec8c88d7 2366
be02a6e6
JG
2367 class ArrayFieldDeclaration(FieldDeclaration):
2368
2369 """
2370 Create a new array field declaration.
2371 """
2372
2373 def __init__(self, element_type, length):
2374 self._ft = _bt_ctf_field_type_array_create(
2375 element_type._ft,
2376 length)
2377 super().__init__()
2378
2379 """
b4b5e4b5
JG
2380 Get the array's element type.
2381 """
be02a6e6
JG
2382 @property
2383 def element_type(self):
2384 ret = _bt_ctf_field_type_array_get_element_type(self._ft)
2385 if ret is None:
2386 raise TypeError("Could not get Array element type")
2387 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2388 ret)
b4b5e4b5 2389
be02a6e6 2390 """
b4b5e4b5
JG
2391 Get the array's length.
2392 """
be02a6e6
JG
2393 @property
2394 def length(self):
2395 ret = _bt_ctf_field_type_array_get_length(self._ft)
2396 if ret < 0:
2397 raise TypeError("Could not get Array length")
2398 return ret
b4b5e4b5 2399
be02a6e6 2400 class SequenceFieldDeclaration(FieldDeclaration):
ec8c88d7 2401
be02a6e6
JG
2402 """
2403 Create a new sequence field declaration.
2404 """
2405
2406 def __init__(self, element_type, length_field_name):
2407 self._ft = _bt_ctf_field_type_sequence_create(
2408 element_type._ft,
2409 str(length_field_name))
2410 super().__init__()
2411
2412 """
b4b5e4b5
JG
2413 Get the sequence's element type.
2414 """
be02a6e6
JG
2415 @property
2416 def element_type(self):
2417 ret = _bt_ctf_field_type_sequence_get_element_type(self._ft)
2418 if ret is None:
2419 raise TypeError("Could not get Sequence element type")
2420 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2421 ret)
b4b5e4b5 2422
be02a6e6 2423 """
b4b5e4b5
JG
2424 Get the sequence's length field name.
2425 """
be02a6e6
JG
2426 @property
2427 def length_field_name(self):
2428 ret = _bt_ctf_field_type_sequence_get_length_field_name(self._ft)
2429 if ret is None:
2430 raise TypeError("Could not get Sequence length field name")
2431 return ret
b4b5e4b5 2432
be02a6e6 2433 class StringFieldDeclaration(FieldDeclaration):
ec8c88d7 2434
be02a6e6
JG
2435 """
2436 Create a new string field declaration.
2437 """
2438
2439 def __init__(self):
2440 self._ft = _bt_ctf_field_type_string_create()
2441 super().__init__()
2442
2443 """
b4b5e4b5 2444 Get a string declaration's encoding (a constant from the CTFStringEncoding class).
14001277 2445 """
be02a6e6
JG
2446 @property
2447 def encoding(self):
2448 return _bt_ctf_field_type_string_get_encoding(self._ft)
14001277 2449
be02a6e6 2450 """
b4b5e4b5 2451 Set a string declaration's encoding. Must be a constant from the CTFStringEncoding class.
ec8c88d7 2452 """
be02a6e6
JG
2453 @encoding.setter
2454 def encoding(self, encoding):
2455 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
2456 if ret < 0:
2457 raise ValueError("Could not set string encoding.")
ec8c88d7 2458
be02a6e6 2459 """
ec8c88d7
JG
2460 Create an instance of a field.
2461 """
be02a6e6
JG
2462 @staticmethod
2463 def create_field(field_type):
2464 if field_type is None or not isinstance(
2465 field_type, CTFWriter.FieldDeclaration):
2466 raise TypeError(
2467 "Invalid field_type. Type must be a FieldDeclaration-derived class.")
2468
2469 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
2470 return CTFWriter.IntegerField(field_type)
2471 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
2472 return CTFWriter.EnumerationField(field_type)
2473 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
2474 return CTFWriter.FloatFieldingPoint(field_type)
2475 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
2476 return CTFWriter.StructureField(field_type)
2477 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
2478 return CTFWriter.VariantField(field_type)
2479 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
2480 return CTFWriter.ArrayField(field_type)
2481 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
2482 return CTFWriter.SequenceField(field_type)
2483 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
2484 return CTFWriter.StringField(field_type)
2485
2486 class Field:
2487
2488 """
2489 Base class, do not instantiate.
2490 """
2491
2492 def __init__(self, field_type):
2493 if not isinstance(field_type, CTFWriter.FieldDeclaration):
2494 raise TypeError("Invalid field_type argument.")
2495
2496 self._f = _bt_ctf_field_create(field_type._ft)
2497 if self._f is None:
2498 raise ValueError("Field creation failed.")
2499
2500 def __del__(self):
2501 _bt_ctf_field_put(self._f)
2502
2503 @staticmethod
2504 def _create_field_from_native_instance(native_field_instance):
2505 type_dict = {
2506 CTFTypeId.INTEGER: CTFWriter.IntegerField,
2507 CTFTypeId.FLOAT: CTFWriter.FloatFieldingPoint,
2508 CTFTypeId.ENUM: CTFWriter.EnumerationField,
2509 CTFTypeId.STRING: CTFWriter.StringField,
2510 CTFTypeId.STRUCT: CTFWriter.StructureField,
2511 CTFTypeId.VARIANT: CTFWriter.VariantField,
2512 CTFTypeId.ARRAY: CTFWriter.ArrayField,
2513 CTFTypeId.SEQUENCE: CTFWriter.SequenceField
2514 }
2515
2516 field_type = _bt_python_get_field_type(native_field_instance)
2517 if field_type == CTFTypeId.UNKNOWN:
2518 raise TypeError("Invalid field instance")
2519
2520 field = CTFWriter.Field.__new__(CTFWriter.Field)
2521 field._f = native_field_instance
2522 field.__class__ = type_dict[field_type]
2523 return field
2524
2525 @property
2526 def declaration(self):
2527 native_field_type = _bt_ctf_field_get_type(self._f)
2528 if native_field_type is None:
2529 raise TypeError("Invalid field instance")
2530 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2531 native_field_type)
2532
2533 class IntegerField(Field):
2534
2535 """
2536 Get an integer field's value.
2537 """
2538 @property
2539 def value(self):
2540 signedness = _bt_python_field_integer_get_signedness(self._f)
2541 if signedness < 0:
2542 raise TypeError("Invalid integer instance.")
2543
2544 if signedness == 0:
2545 ret, value = _bt_ctf_field_unsigned_integer_get_value(self._f)
2546 else:
2547 ret, value = _bt_ctf_field_signed_integer_get_value(self._f)
2548
2549 if ret < 0:
2550 raise ValueError("Could not get integer field value.")
2551 return value
2552
2553 """
ec8c88d7
JG
2554 Set an integer field's value.
2555 """
be02a6e6
JG
2556 @value.setter
2557 def value(self, value):
2558 if not isinstance(value, int):
2559 raise TypeError("IntegerField's value must be an int")
2560
2561 signedness = _bt_python_field_integer_get_signedness(self._f)
2562 if signedness < 0:
2563 raise TypeError("Invalid integer instance.")
2564
2565 if signedness == 0:
2566 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
2567 else:
2568 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
2569
2570 if ret < 0:
2571 raise ValueError("Could not set integer field value.")
2572
2573 class EnumerationField(Field):
2574
2575 """
2576 Return the enumeration's underlying container field (an integer field).
2577 """
2578 @property
2579 def container(self):
2580 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
2581 container._f = _bt_ctf_field_enumeration_get_container(self._f)
2582 if container._f is None:
2583 raise TypeError("Invalid enumeration field type.")
2584 return container
2585
2586 """
821ca76c
JG
2587 Get the enumeration field's mapping name.
2588 """
be02a6e6
JG
2589 @property
2590 def value(self):
2591 value = _bt_ctf_field_enumeration_get_mapping_name(self._f)
2592 if value is None:
2593 raise ValueError("Could not get enumeration's mapping name.")
2594 return value
821ca76c 2595
be02a6e6 2596 """
821ca76c
JG
2597 Set the enumeration field's value. Must be an integer as mapping names
2598 may be ambiguous.
2599 """
be02a6e6
JG
2600 @value.setter
2601 def value(self, value):
2602 if not isinstance(value, int):
2603 raise TypeError("EnumerationField value must be an int")
2604 self.container.value = value
2605
2606 class FloatFieldingPoint(Field):
2607
2608 """
2609 Get a floating point field's value.
2610 """
2611 @property
2612 def value(self):
2613 ret, value = _bt_ctf_field_floating_point_get_value(self._f)
2614 if ret < 0:
2615 raise ValueError("Could not get floating point field value.")
2616 return value
2617
2618 """
ec8c88d7
JG
2619 Set a floating point field's value.
2620 """
be02a6e6
JG
2621 @value.setter
2622 def value(self, value):
2623 if not isinstance(value, int) and not isinstance(value, float):
2624 raise TypeError("Value must be either a float or an int")
2625
2626 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
2627 if ret < 0:
2628 raise ValueError("Could not set floating point field value.")
2629
2630 class StructureField(Field):
2631
2632 """
2633 Get the structure's field corresponding to the provided field name.
2634 """
2635
2636 def field(self, field_name):
2637 native_instance = _bt_ctf_field_structure_get_field(
2638 self._f,
2639 str(field_name))
2640 if native_instance is None:
2641 raise ValueError("Invalid field_name provided.")
2642 return CTFWriter.Field._create_field_from_native_instance(
2643 native_instance)
2644
2645 class VariantField(Field):
2646
2647 """
2648 Return the variant's selected field. The "tag" field is the selector enum field.
2649 """
2650
2651 def field(self, tag):
2652 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
2653 if native_instance is None:
2654 raise ValueError("Invalid tag provided.")
2655 return CTFWriter.Field._create_field_from_native_instance(
2656 native_instance)
2657
2658 class ArrayField(Field):
2659
2660 """
2661 Return the array's field at position "index".
2662 """
2663
2664 def field(self, index):
2665 native_instance = _bt_ctf_field_array_get_field(self._f, index)
2666 if native_instance is None:
2667 raise IndexError("Invalid index provided.")
2668 return CTFWriter.Field._create_field_from_native_instance(
2669 native_instance)
2670
2671 class SequenceField(Field):
2672
2673 """
2674 Get the sequence's length field (IntegerField).
2675 """
2676 @property
2677 def length(self):
2678 native_instance = _bt_ctf_field_sequence_get_length(self._f)
2679 if native_instance is None:
2680 length = -1
2681 return CTFWriter.Field._create_field_from_native_instance(
2682 native_instance)
2683
2684 """
2685 Set the sequence's length field (IntegerField).
ec8c88d7 2686 """
be02a6e6
JG
2687 @length.setter
2688 def length(self, length_field):
2689 if not isinstance(length_field, CTFWriter.IntegerField):
2690 raise TypeError("Invalid length field.")
2691 if length_field.declaration.signed:
2692 raise TypeError("Sequence field length must be unsigned")
2693 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2694 if ret < 0:
2695 raise ValueError("Could not set sequence length.")
2696
2697 """
2698 Return the sequence's field at position "index".
ec8c88d7 2699 """
ec8c88d7 2700
be02a6e6
JG
2701 def field(self, index):
2702 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2703 if native_instance is None:
2704 raise ValueError("Could not get sequence element at index.")
2705 return CTFWriter.Field._create_field_from_native_instance(
2706 native_instance)
ec8c88d7 2707
be02a6e6 2708 class StringField(Field):
14001277 2709
be02a6e6
JG
2710 """
2711 Get a string field's value.
2712 """
2713 @property
2714 def value(self):
2715 return _bt_ctf_field_string_get_value(self._f)
ec8c88d7 2716
be02a6e6
JG
2717 """
2718 Set a string field's value.
ec8c88d7 2719 """
be02a6e6
JG
2720 @value.setter
2721 def value(self, value):
2722 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2723 if ret < 0:
2724 raise ValueError("Could not set string field value.")
ec8c88d7 2725
be02a6e6 2726 class EventClass:
14001277 2727
be02a6e6
JG
2728 """
2729 Create a new event class of the given name.
2730 """
ec8c88d7 2731
be02a6e6
JG
2732 def __init__(self, name):
2733 self._ec = _bt_ctf_event_class_create(name)
2734 if self._ec is None:
2735 raise ValueError("Event class creation failed.")
ec8c88d7 2736
be02a6e6
JG
2737 def __del__(self):
2738 _bt_ctf_event_class_put(self._ec)
ec8c88d7 2739
be02a6e6 2740 """
ec8c88d7
JG
2741 Add a field of type "field_type" to the event class.
2742 """
ec8c88d7 2743
be02a6e6
JG
2744 def add_field(self, field_type, field_name):
2745 ret = _bt_ctf_event_class_add_field(
2746 self._ec,
2747 field_type._ft,
2748 str(field_name))
2749 if ret < 0:
2750 raise ValueError("Could not add field to event class.")
2751
2752 """
38f28df6
JG
2753 Get the event class' name.
2754 """
be02a6e6
JG
2755 @property
2756 def name(self):
2757 name = _bt_ctf_event_class_get_name(self._ec)
2758 if name is None:
2759 raise TypeError("Could not get EventClass name")
2760 return name
38f28df6 2761
be02a6e6 2762 """
38f28df6
JG
2763 Get the event class' id. Returns a negative value if unset.
2764 """
be02a6e6
JG
2765 @property
2766 def id(self):
2767 id = _bt_ctf_event_class_get_id(self._ec)
2768 if id < 0:
2769 raise TypeError("Could not get EventClass id")
2770 return id
38f28df6 2771
be02a6e6 2772 """
38f28df6
JG
2773 Set the event class' id. Throws a TypeError if the event class
2774 is already registered to a stream class.
2775 """
be02a6e6
JG
2776 @id.setter
2777 def id(self, id):
2778 ret = _bt_ctf_event_class_set_id(self._ec, id)
2779 if ret < 0:
2780 raise TypeError(
2781 "Can't change an Event Class's id after it has been assigned to a stream class")
38f28df6 2782
be02a6e6 2783 """
38f28df6
JG
2784 Get the event class' stream class. Returns None if unset.
2785 """
be02a6e6
JG
2786 @property
2787 def stream_class(self):
2788 stream_class_native = _bt_ctf_event_class_get_stream_class(
2789 self._ec)
2790 if stream_class_native is None:
2791 return None
2792 stream_class = CTFWriter.StreamClass.__new__(CTFWriter.StreamClass)
2793 stream_class._sc = stream_class_native
2794 return stream_class
2795
2796 """
38f28df6
JG
2797 Generator returning the event class' fields as tuples of (field name, field declaration).
2798 """
be02a6e6
JG
2799 @property
2800 def fields(self):
2801 count = _bt_ctf_event_class_get_field_count(self._ec)
2802 if count < 0:
2803 raise TypeError("Could not get EventClass' field count")
2804
2805 for i in range(count):
2806 field_name = _bt_python_ctf_event_class_get_field_name(
2807 self._ec,
2808 i)
2809 if field_name is None:
2810 raise TypeError(
2811 "Could not get EventClass' field name at index {}".format(i))
2812
2813 field_type_native = _bt_python_ctf_event_class_get_field_type(
2814 self._ec,
2815 i)
2816 if field_type_native is None:
2817 raise TypeError(
2818 "Could not get EventClass' field type at index {}".format(i))
2819
2820 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2821 field_type_native)
2822 yield (field_name, field_type)
2823
2824 """
2825 Get a field declaration by name (FieldDeclaration).
2826 """
38f28df6 2827
be02a6e6
JG
2828 def get_field_by_name(self, name):
2829 field_type_native = _bt_ctf_event_class_get_field_by_name(
2830 self._ec,
2831 name)
2832 if field_type_native is None:
2833 raise TypeError(
2834 "Could not find EventClass field with name {}".format(name))
2835 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2836 field_type_native)
38f28df6 2837
be02a6e6 2838 class Event:
38f28df6 2839
be02a6e6
JG
2840 """
2841 Create a new event of the given event class.
2842 """
38f28df6 2843
be02a6e6
JG
2844 def __init__(self, event_class):
2845 if not isinstance(event_class, CTFWriter.EventClass):
2846 raise TypeError("Invalid event_class argument.")
ec8c88d7 2847
be02a6e6
JG
2848 self._e = _bt_ctf_event_create(event_class._ec)
2849 if self._e is None:
2850 raise ValueError("Event creation failed.")
ec8c88d7 2851
be02a6e6
JG
2852 def __del__(self):
2853 _bt_ctf_event_put(self._e)
ec8c88d7 2854
be02a6e6 2855 """
38f28df6 2856 Get the event's class.
ec8c88d7 2857 """
be02a6e6
JG
2858 @property
2859 def event_class(self):
2860 event_class_native = _bt_ctf_event_get_class(self._e)
2861 if event_class_native is None:
2862 return None
2863 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2864 event_class._ec = event_class_native
2865 return event_class
38f28df6 2866
be02a6e6 2867 """
38f28df6
JG
2868 Get a clock from event. Returns None if the event's class
2869 is not registered to a stream class.
2870 """
ec8c88d7 2871
be02a6e6
JG
2872 def clock(self):
2873 clock_instance = _bt_ctf_event_get_clock(self._e)
2874 if clock_instance is None:
2875 return None
2876 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2877 clock._c = clock_instance
2878 return clock
2879
2880 """
14001277 2881 Get a field from event.
ec8c88d7 2882 """
ec8c88d7 2883
be02a6e6
JG
2884 def payload(self, field_name):
2885 native_instance = _bt_ctf_event_get_payload(
2886 self._e,
2887 str(field_name))
2888 if native_instance is None:
2889 raise ValueError("Could not get event payload.")
2890 return CTFWriter.Field._create_field_from_native_instance(
2891 native_instance)
2892
2893 """
38f28df6
JG
2894 Set a manually created field as an event's payload.
2895 """
38f28df6 2896
be02a6e6
JG
2897 def set_payload(self, field_name, value_field):
2898 if not isinstance(value, CTFWriter.Field):
2899 raise TypeError("Invalid value type.")
2900 ret = _bt_ctf_event_set_payload(
2901 self._e,
2902 str(field_name),
2903 value_field._f)
2904 if ret < 0:
2905 raise ValueError("Could not set event field payload.")
ec8c88d7 2906
be02a6e6 2907 class StreamClass:
ec8c88d7 2908
be02a6e6
JG
2909 """
2910 Create a new stream class of the given name.
2911 """
2912
2913 def __init__(self, name):
2914 self._sc = _bt_ctf_stream_class_create(name)
2915 if self._sc is None:
2916 raise ValueError("Stream class creation failed.")
2917
2918 def __del__(self):
2919 _bt_ctf_stream_class_put(self._sc)
2920
2921 """
f6c2aa83
JG
2922 Get a stream class' name.
2923 """
be02a6e6
JG
2924 @property
2925 def name(self):
2926 name = _bt_ctf_stream_class_get_name(self._sc)
2927 if name is None:
2928 raise TypeError("Could not get StreamClass name")
2929 return name
f6c2aa83 2930
be02a6e6 2931 """
14001277
JG
2932 Get a stream class' clock.
2933 """
be02a6e6
JG
2934 @property
2935 def clock(self):
2936 clock_instance = _bt_ctf_stream_class_get_clock(self._sc)
2937 if clock_instance is None:
2938 return None
2939 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2940 clock._c = clock_instance
2941 return clock
14001277 2942
be02a6e6 2943 """
ec8c88d7
JG
2944 Assign a clock to a stream class.
2945 """
be02a6e6
JG
2946 @clock.setter
2947 def clock(self, clock):
2948 if not isinstance(clock, CTFWriter.Clock):
2949 raise TypeError("Invalid clock type.")
ec8c88d7 2950
be02a6e6
JG
2951 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2952 if ret < 0:
2953 raise ValueError("Could not set stream class clock.")
ec8c88d7 2954
be02a6e6 2955 """
f6c2aa83
JG
2956 Get a stream class' id.
2957 """
be02a6e6
JG
2958 @property
2959 def id(self):
2960 ret = _bt_ctf_stream_class_get_id(self._sc)
2961 if ret < 0:
2962 raise TypeError("Could not get StreamClass id")
2963 return ret
f6c2aa83 2964
be02a6e6 2965 """
f6c2aa83
JG
2966 Assign an id to a stream class.
2967 """
be02a6e6
JG
2968 @id.setter
2969 def id(self, id):
2970 ret = _bt_ctf_stream_class_set_id(self._sc, id)
2971 if ret < 0:
2972 raise TypeError("Could not set stream class id.")
f6c2aa83 2973
be02a6e6 2974 """
f6c2aa83
JG
2975 Generator returning the stream class' event classes.
2976 """
be02a6e6
JG
2977 @property
2978 def event_classes(self):
2979 count = _bt_ctf_stream_class_get_event_class_count(self._sc)
2980 if count < 0:
2981 raise TypeError("Could not get StreamClass' event class count")
2982
2983 for i in range(count):
2984 event_class_native = _bt_ctf_stream_class_get_event_class(
2985 self._sc,
2986 i)
2987 if event_class_native is None:
2988 raise TypeError(
2989 "Could not get StreamClass' event class at index {}".format(i))
2990
2991 event_class = CTFWriter.EventClass.__new__(
2992 CTFWriter.EventClass)
2993 event_class._ec = event_class_native
2994 yield event_class
2995
2996 """
ec8c88d7 2997 Add an event class to a stream class. New events can be added even after a
14001277 2998 stream has been instantiated and events have been appended. However, a stream
a5e4f94c
JG
2999 will not accept events of a class that has not been added to the stream
3000 class beforehand.
ec8c88d7 3001 """
ec8c88d7 3002
be02a6e6
JG
3003 def add_event_class(self, event_class):
3004 if not isinstance(event_class, CTFWriter.EventClass):
3005 raise TypeError("Invalid event_class type.")
ec8c88d7 3006
be02a6e6
JG
3007 ret = _bt_ctf_stream_class_add_event_class(
3008 self._sc,
3009 event_class._ec)
3010 if ret < 0:
3011 raise ValueError("Could not add event class.")
7df927c7 3012
be02a6e6
JG
3013 """
3014 Get the StreamClass' packet context type (StructureFieldDeclaration)
7df927c7 3015 """
be02a6e6
JG
3016 @property
3017 def packet_context_type(self):
3018 field_type_native = _bt_ctf_stream_class_get_packet_context_type(
3019 self._sc)
3020 if field_type_native is None:
3021 raise ValueError("Invalid StreamClass")
3022 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
3023 field_type_native)
3024 return field_type
3025
3026 """
7df927c7
JG
3027 Set a StreamClass' packet context type. Must be of type
3028 StructureFieldDeclaration.
3029 """
be02a6e6
JG
3030 @packet_context_type.setter
3031 def packet_context_type(self, field_type):
3032 if not isinstance(field_type, CTFWriter.StructureFieldDeclaration):
3033 raise TypeError(
3034 "field_type argument must be of type StructureFieldDeclaration.")
3035 ret = _bt_ctf_stream_class_set_packet_context_type(
3036 self._sc,
3037 field_type._ft)
3038 if ret < 0:
3039 raise ValueError("Failed to set packet context type.")
7df927c7 3040
be02a6e6 3041 class Stream:
ec8c88d7 3042
be02a6e6
JG
3043 """
3044 Create a stream of the given class.
3045 """
ec8c88d7 3046
be02a6e6
JG
3047 def __init__(self, stream_class):
3048 if not isinstance(stream_class, CTFWriter.StreamClass):
3049 raise TypeError(
3050 "Invalid stream_class argument must be of type StreamClass.")
ec8c88d7 3051
be02a6e6
JG
3052 self._s = _bt_ctf_stream_create(stream_class._sc)
3053 if self._s is None:
3054 raise ValueError("Stream creation failed.")
3055
3056 def __del__(self):
3057 _bt_ctf_stream_put(self._s)
3058
3059 """
708e628a
JG
3060 Get a stream's discarded event count.
3061 """
be02a6e6
JG
3062 @property
3063 def discarded_events(self):
3064 ret, count = _bt_ctf_stream_get_discarded_events_count(self._s)
3065 if ret < 0:
3066 raise ValueError(
3067 "Could not get the stream's discarded events count")
3068 return count
708e628a 3069
be02a6e6 3070 """
ec8c88d7
JG
3071 Increase the current packet's discarded event count.
3072 """
ec8c88d7 3073
be02a6e6
JG
3074 def append_discarded_events(self, event_count):
3075 _bt_ctf_stream_append_discarded_events(self._s, event_count)
3076
3077 """
ec8c88d7
JG
3078 Append "event" to the stream's current packet. The stream's associated clock
3079 will be sampled during this call. The event shall not be modified after
3080 being appended to a stream.
3081 """
ec8c88d7 3082
be02a6e6
JG
3083 def append_event(self, event):
3084 ret = _bt_ctf_stream_append_event(self._s, event._e)
3085 if ret < 0:
3086 raise ValueError("Could not append event to stream.")
3087
3088 """
7df927c7
JG
3089 Get a Stream's packet context field (a StructureField).
3090 """
be02a6e6
JG
3091 @property
3092 def packet_context(self):
3093 native_field = _bt_ctf_stream_get_packet_context(self._s)
3094 if native_field is None:
3095 raise ValueError("Invalid Stream.")
3096 return CTFWriter.Field._create_field_from_native_instance(
3097 native_field)
7df927c7 3098
be02a6e6 3099 """
7df927c7
JG
3100 Set a Stream's packet context field (must be a StructureField).
3101 """
be02a6e6
JG
3102 @packet_context.setter
3103 def packet_context(self, field):
3104 if not isinstance(field, CTFWriter.StructureField):
3105 raise TypeError(
3106 "Argument field must be of type StructureField")
3107 ret = _bt_ctf_stream_set_packet_context(self._s, field._f)
3108 if ret < 0:
3109 raise ValueError("Invalid packet context field.")
7df927c7 3110
be02a6e6 3111 """
ec8c88d7
JG
3112 The stream's current packet's events will be flushed to disk. Events
3113 subsequently appended to the stream will be added to a new packet.
3114 """
ec8c88d7 3115
be02a6e6
JG
3116 def flush(self):
3117 ret = _bt_ctf_stream_flush(self._s)
3118 if ret < 0:
3119 raise ValueError("Could not flush stream.")
ec8c88d7 3120
be02a6e6 3121 class Writer:
ec8c88d7 3122
be02a6e6
JG
3123 """
3124 Create a new writer that will produce a trace in the given path.
3125 """
3126
3127 def __init__(self, path):
3128 self._w = _bt_ctf_writer_create(path)
3129 if self._w is None:
3130 raise ValueError("Writer creation failed.")
3131
3132 def __del__(self):
3133 _bt_ctf_writer_put(self._w)
3134
3135 """
ec8c88d7
JG
3136 Create a new stream instance and register it to the writer.
3137 """
ec8c88d7 3138
be02a6e6
JG
3139 def create_stream(self, stream_class):
3140 if not isinstance(stream_class, CTFWriter.StreamClass):
3141 raise TypeError("Invalid stream_class type.")
ec8c88d7 3142
be02a6e6
JG
3143 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
3144 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
3145 return stream
3146
3147 """
ec8c88d7
JG
3148 Add an environment field to the trace.
3149 """
ec8c88d7 3150
be02a6e6
JG
3151 def add_environment_field(self, name, value):
3152 ret = _bt_ctf_writer_add_environment_field(
3153 self._w,
3154 str(name),
3155 str(value))
3156 if ret < 0:
3157 raise ValueError("Could not add environment field to trace.")
3158
3159 """
ec8c88d7
JG
3160 Add a clock to the trace. Clocks assigned to stream classes must be
3161 registered to the writer.
3162 """
ec8c88d7 3163
be02a6e6
JG
3164 def add_clock(self, clock):
3165 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
3166 if ret < 0:
3167 raise ValueError("Could not add clock to Writer.")
3168
3169 """
ec8c88d7
JG
3170 Get the trace's TSDL meta-data.
3171 """
be02a6e6
JG
3172 @property
3173 def metadata(self):
3174 return _bt_ctf_writer_get_metadata_string(self._w)
ec8c88d7 3175
be02a6e6 3176 """
ec8c88d7
JG
3177 Flush the trace's metadata to the metadata file.
3178 """
ec8c88d7 3179
be02a6e6
JG
3180 def flush_metadata(self):
3181 _bt_ctf_writer_flush_metadata(self._w)
3182
3183 """
14001277
JG
3184 Get the trace's byte order. Must be a constant from the ByteOrder
3185 class.
3186 """
be02a6e6
JG
3187 @property
3188 def byte_order(self):
3189 raise NotImplementedError("Getter not implemented.")
14001277 3190
be02a6e6 3191 """
ec8c88d7
JG
3192 Set the trace's byte order. Must be a constant from the ByteOrder
3193 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
3194 """
be02a6e6
JG
3195 @byte_order.setter
3196 def byte_order(self, byte_order):
3197 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
3198 if ret < 0:
3199 raise ValueError("Could not set trace's byte order.")
ec8c88d7
JG
3200
3201%}
This page took 0.16984 seconds and 4 git commands to generate.