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