Move Python bindings to babeltrace subfolder
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 11 May 2016 19:47:35 +0000 (15:47 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 13 May 2016 18:52:14 +0000 (14:52 -0400)
This change reflects the arborescence used to install Babeltrace's
python bindings and allows Babeltrace's tests to use the normal
module name namespace.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
28 files changed:
bindings/python/Makefile.am
bindings/python/__init__.py.in [deleted file]
bindings/python/babeltrace/Makefile.am [new file with mode: 0644]
bindings/python/babeltrace/__init__.py.in [new file with mode: 0644]
bindings/python/babeltrace/common.py [new file with mode: 0644]
bindings/python/babeltrace/examples/babeltrace_and_lttng.py [new file with mode: 0644]
bindings/python/babeltrace/examples/ctf_writer.py [new file with mode: 0644]
bindings/python/babeltrace/examples/example-api-test.py [new file with mode: 0644]
bindings/python/babeltrace/examples/sched_switch.py [new file with mode: 0644]
bindings/python/babeltrace/examples/sequence_test.py [new file with mode: 0644]
bindings/python/babeltrace/nativebt.i [new file with mode: 0644]
bindings/python/babeltrace/python-complements.c [new file with mode: 0644]
bindings/python/babeltrace/python-complements.h [new file with mode: 0644]
bindings/python/babeltrace/reader.py [new file with mode: 0644]
bindings/python/babeltrace/writer.py [new file with mode: 0644]
bindings/python/common.py [deleted file]
bindings/python/examples/babeltrace_and_lttng.py [deleted file]
bindings/python/examples/ctf_writer.py [deleted file]
bindings/python/examples/example-api-test.py [deleted file]
bindings/python/examples/sched_switch.py [deleted file]
bindings/python/examples/sequence_test.py [deleted file]
bindings/python/nativebt.i [deleted file]
bindings/python/python-complements.c [deleted file]
bindings/python/python-complements.h [deleted file]
bindings/python/reader.py [deleted file]
bindings/python/writer.py [deleted file]
configure.ac
doc/bindings/python/Makefile.am

index 5564203d7376e925342acf2c92845974473a28b1..4398289860e4e4c441edc2eced34a83b5c78176b 100644 (file)
@@ -1,34 +1 @@
-NATIVEBT_PY = nativebt.py
-NATIVEBT_WRAP_C = nativebt_wrap.c
-INIT_PY = __init__.py
-INIT_PY_IN = $(srcdir)/$(INIT_PY).in
-NATIVEBT_I = $(srcdir)/nativebt.i
-
-all-local: $(INIT_PY)
-
-$(INIT_PY): $(INIT_PY_IN)
-       sed "s/BABELTRACE_VERSION_STR/$(PACKAGE_VERSION)/g" < $< > $@
-
-AM_CFLAGS = $(PYTHON_INCLUDE) -I$(top_srcdir)/include/ -I$(top_srcdir)/bindings/python
-
-EXTRA_DIST = common.py reader.py writer.py $(INIT_PY_IN) $(NATIVEBT_I)
-nodist_btpackage_PYTHON = $(INIT_PY) $(NATIVEBT_PY) common.py reader.py writer.py
-nativebtlib_LTLIBRARIES = _nativebt.la
-
-btpackagedir = $(pythondir)/babeltrace
-nativebtlibdir = $(btpackagedir)
-
-MAINTAINERCLEANFILES = $(NATIVEBT_PY) $(NATIVEBT_WRAP_C)
-
-nodist__nativebt_la_SOURCES = $(NATIVEBT_WRAP_C)
-_nativebt_la_SOURCES = python-complements.h python-complements.c
-_nativebt_la_LDFLAGS = -module
-_nativebt_la_CFLAGS = $(GLIB_CFLAGS) $(AM_CFLAGS)
-_nativebt_la_LIBS = $(GLIB_LIBS)
-_nativebt_la_LIBADD = $(top_builddir)/formats/ctf/libbabeltrace-ctf.la
-
-# SWIG 'warning md variable unused' fixed after SWIG build:
-$(NATIVEBT_WRAP_C): $(NATIVEBT_I)
-       $(SWIG) -python -Wall -I$(srcdir) -I$(top_srcdir)/include -outcurrentdir $<
-
-CLEANFILES = $(NATIVEBT_PY) $(NATIVEBT_WRAP_C) $(INIT_PY)
+SUBDIRS = babeltrace
diff --git a/bindings/python/__init__.py.in b/bindings/python/__init__.py.in
deleted file mode 100644 (file)
index a1d4d17..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-# backward compatibility with old `babeltrace` module: import common members
-from .common import \
-    CTFStringEncoding, \
-    ByteOrder, \
-    CTFTypeId, \
-    CTFScope
-
-
-# backward compatibility with old `babeltrace` module: import reader API members
-from .reader import \
-    TraceCollection, \
-    TraceHandle, \
-    Event, \
-    FieldError, \
-    EventDeclaration, \
-    FieldDeclaration, \
-    IntegerFieldDeclaration, \
-    EnumerationFieldDeclaration, \
-    ArrayFieldDeclaration, \
-    SequenceFieldDeclaration, \
-    FloatFieldDeclaration, \
-    StructureFieldDeclaration, \
-    StringFieldDeclaration, \
-    VariantFieldDeclaration
-
-
-# backward compatibility with old `babeltrace` module: import CTF writer API
-# module as `CTFWriter`, since `CTFWriter` used to be a class in the
-# `babeltrace` module
-import babeltrace.writer as CTFWriter
-
-
-__version__ = 'BABELTRACE_VERSION_STR'
diff --git a/bindings/python/babeltrace/Makefile.am b/bindings/python/babeltrace/Makefile.am
new file mode 100644 (file)
index 0000000..26f388c
--- /dev/null
@@ -0,0 +1,34 @@
+NATIVEBT_PY = nativebt.py
+NATIVEBT_WRAP_C = nativebt_wrap.c
+INIT_PY = __init__.py
+INIT_PY_IN = $(srcdir)/$(INIT_PY).in
+NATIVEBT_I = $(srcdir)/nativebt.i
+
+all-local: $(INIT_PY)
+
+$(INIT_PY): $(INIT_PY_IN)
+       sed "s/BABELTRACE_VERSION_STR/$(PACKAGE_VERSION)/g" < $< > $@
+
+AM_CFLAGS = $(PYTHON_INCLUDE) -I$(top_srcdir)/include/ -I$(srcdir)
+
+EXTRA_DIST = common.py reader.py writer.py $(INIT_PY_IN) $(NATIVEBT_I)
+nodist_btpackage_PYTHON = $(INIT_PY) $(NATIVEBT_PY) common.py reader.py writer.py
+nativebtlib_LTLIBRARIES = _nativebt.la
+
+btpackagedir = $(pythondir)/babeltrace
+nativebtlibdir = $(btpackagedir)
+
+MAINTAINERCLEANFILES = $(NATIVEBT_PY) $(NATIVEBT_WRAP_C)
+
+nodist__nativebt_la_SOURCES = $(NATIVEBT_WRAP_C)
+_nativebt_la_SOURCES = python-complements.h python-complements.c
+_nativebt_la_LDFLAGS = -module
+_nativebt_la_CFLAGS = $(GLIB_CFLAGS) $(AM_CFLAGS)
+_nativebt_la_LIBS = $(GLIB_LIBS)
+_nativebt_la_LIBADD = $(top_builddir)/formats/ctf/libbabeltrace-ctf.la
+
+# SWIG 'warning md variable unused' fixed after SWIG build:
+$(NATIVEBT_WRAP_C): $(NATIVEBT_I)
+       $(SWIG) -python -Wall -I$(srcdir) -I$(top_srcdir)/include -outcurrentdir $<
+
+CLEANFILES = $(NATIVEBT_PY) $(NATIVEBT_WRAP_C) $(INIT_PY)
diff --git a/bindings/python/babeltrace/__init__.py.in b/bindings/python/babeltrace/__init__.py.in
new file mode 100644 (file)
index 0000000..a1d4d17
--- /dev/null
@@ -0,0 +1,33 @@
+# backward compatibility with old `babeltrace` module: import common members
+from .common import \
+    CTFStringEncoding, \
+    ByteOrder, \
+    CTFTypeId, \
+    CTFScope
+
+
+# backward compatibility with old `babeltrace` module: import reader API members
+from .reader import \
+    TraceCollection, \
+    TraceHandle, \
+    Event, \
+    FieldError, \
+    EventDeclaration, \
+    FieldDeclaration, \
+    IntegerFieldDeclaration, \
+    EnumerationFieldDeclaration, \
+    ArrayFieldDeclaration, \
+    SequenceFieldDeclaration, \
+    FloatFieldDeclaration, \
+    StructureFieldDeclaration, \
+    StringFieldDeclaration, \
+    VariantFieldDeclaration
+
+
+# backward compatibility with old `babeltrace` module: import CTF writer API
+# module as `CTFWriter`, since `CTFWriter` used to be a class in the
+# `babeltrace` module
+import babeltrace.writer as CTFWriter
+
+
+__version__ = 'BABELTRACE_VERSION_STR'
diff --git a/bindings/python/babeltrace/common.py b/bindings/python/babeltrace/common.py
new file mode 100644 (file)
index 0000000..466f2c6
--- /dev/null
@@ -0,0 +1,169 @@
+# common.py
+#
+# Babeltrace Python module common definitions
+#
+# Copyright 2012-2015 EfficiOS Inc.
+#
+# Author: Danny Serres <danny.serres@efficios.com>
+# Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+
+class CTFStringEncoding:
+    """
+    CTF string encodings.
+    """
+
+    #: None
+    NONE = 0
+
+    #: UTF-8
+    UTF8 = 1
+
+    #: ASCII
+    ASCII = 2
+
+    #: Unknown
+    UNKNOWN = 3
+
+
+# Based on the enum in ctf-writer/writer.h
+class ByteOrder:
+    """
+    Byte orders.
+    """
+
+    #: Native byte order
+    BYTE_ORDER_NATIVE = 0
+
+    #: Little-endian
+    BYTE_ORDER_LITTLE_ENDIAN = 1
+
+    #: Big-endian
+    BYTE_ORDER_BIG_ENDIAN = 2
+
+    #: Network byte order (big-endian)
+    BYTE_ORDER_NETWORK = 3
+
+    #: Unknown byte order
+    BYTE_ORDER_UNKNOWN = 4  # Python-specific entry
+
+
+# enum equivalent, accessible constants
+# These are taken directly from ctf/events.h
+# All changes to enums must also be made here
+class CTFTypeId:
+    """
+    CTF numeric type identifiers.
+    """
+
+    #: Unknown type
+    UNKNOWN = 0
+
+    #: Integer
+    INTEGER = 1
+
+    #: Floating point number
+    FLOAT = 2
+
+    #: Enumeration
+    ENUM = 3
+
+    #: String
+    STRING = 4
+
+    #: Structure
+    STRUCT = 5
+
+    #: Untagged variant
+    UNTAGGED_VARIANT = 6
+
+    #: Variant
+    VARIANT = 7
+
+    #: Array
+    ARRAY = 8
+
+    #: Sequence
+    SEQUENCE = 9
+
+    NR_CTF_TYPES = 10
+
+    def type_name(id):
+        """
+        Returns the name of the CTF numeric type identifier *id*.
+        """
+
+        name = "UNKNOWN_TYPE"
+        constants = [
+            attr for attr in dir(CTFTypeId) if not callable(
+                getattr(
+                    CTFTypeId,
+                    attr)) and not attr.startswith("__")]
+
+        for attr in constants:
+            if getattr(CTFTypeId, attr) == id:
+                name = attr
+                break
+
+        return name
+
+
+class CTFScope:
+    """
+    CTF scopes.
+    """
+
+    #: Packet header
+    TRACE_PACKET_HEADER = 0
+
+    #: Packet context
+    STREAM_PACKET_CONTEXT = 1
+
+    #: Event header
+    STREAM_EVENT_HEADER = 2
+
+    #: Stream event context
+    STREAM_EVENT_CONTEXT = 3
+
+    #: Event context
+    EVENT_CONTEXT = 4
+
+    #: Event fields
+    EVENT_FIELDS = 5
+
+    def scope_name(scope):
+        """
+        Returns the name of the CTF scope *scope*.
+        """
+
+        name = "UNKNOWN_SCOPE"
+        constants = [
+            attr for attr in dir(CTFScope) if not callable(
+                getattr(
+                    CTFScope,
+                    attr)) and not attr.startswith("__")]
+
+        for attr in constants:
+            if getattr(CTFScope, attr) == scope:
+                name = attr
+                break
+
+        return name
diff --git a/bindings/python/babeltrace/examples/babeltrace_and_lttng.py b/bindings/python/babeltrace/examples/babeltrace_and_lttng.py
new file mode 100644 (file)
index 0000000..651fa2d
--- /dev/null
@@ -0,0 +1,130 @@
+#!/usr/bin/env python3
+# babeltrace_and_lttng.py
+#
+# Babeltrace and LTTng example script
+#
+# Copyright 2012 EfficiOS Inc.
+#
+# Author: Danny Serres <danny.serres@efficios.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+
+# This script uses both lttng-tools and babeltrace
+# python modules.  It creates a session, enables
+# events, starts tracing for 2 seconds, stops tracing,
+# destroys the session and outputs the trace in the
+# specified output file.
+#
+# WARNING: will destroy any existing trace having
+#          the same name as ses_name
+
+
+# ------------------------------------------------------
+ses_name = "babeltrace-lttng-test"
+trace_path = "/lttng-traces/babeltrace-lttng-trace/"
+out_file = "babeltrace-lttng-trace-text-output.txt"
+# ------------------------------------------------------
+
+
+import time
+try:
+    import babeltrace.reader
+    import lttng
+except ImportError:
+    raise ImportError( "both babeltrace and lttng-tools "
+                       "python modules must be installed")
+
+
+# Errors to raise if something goes wrong
+class LTTngError(Exception):
+    pass
+
+
+class BabeltraceError(Exception):
+    pass
+
+
+# LTTNG-TOOLS
+
+# Making sure session does not already exist
+lttng.destroy(ses_name)
+
+# Creating a new session and handle
+ret = lttng.create(ses_name, trace_path)
+if ret < 0:
+    raise LTTngError(lttng.strerror(ret))
+
+domain = lttng.Domain()
+domain.type = lttng.DOMAIN_KERNEL
+
+han = None
+han = lttng.Handle(ses_name, domain)
+if han is None:
+    raise LTTngError("Handle not created")
+
+
+# Enabling all events
+event = lttng.Event()
+event.type = lttng.EVENT_ALL
+event.loglevel_type = lttng.EVENT_LOGLEVEL_ALL
+ret = lttng.enable_event(han, event, None)
+if ret < 0:
+    raise LTTngError(lttng.strerror(ret))
+
+# Start, wait, stop
+ret = lttng.start(ses_name)
+if ret < 0:
+    raise LTTngError(lttng.strerror(ret))
+print("Tracing...")
+time.sleep(2)
+print("Stopped.")
+ret = lttng.stop(ses_name)
+if ret < 0:
+    raise LTTngError(lttng.strerror(ret))
+
+
+# Destroying tracing session
+ret = lttng.destroy(ses_name)
+if ret < 0:
+    raise LTTngError(lttng.strerror(ret))
+
+
+# BABELTRACE
+
+# Create TraceCollecion and add trace:
+traces = babeltrace.reader.TraceCollection()
+ret = traces.add_trace(trace_path + "/kernel", "ctf")
+if ret is None:
+    raise BabeltraceError("Error adding trace")
+
+# Reading events from trace
+# and outputting timestamps and event names
+# in out_file
+print("Writing trace file...")
+output = open(out_file, "wt")
+
+for event in traces.events:
+    output.write("TS: {}, {} : {}\n".format(
+        event.timestamp, event.cycles, event.name))
+
+# Closing file
+output.close()
+
+print("Done.")
diff --git a/bindings/python/babeltrace/examples/ctf_writer.py b/bindings/python/babeltrace/examples/ctf_writer.py
new file mode 100644 (file)
index 0000000..d60eb3d
--- /dev/null
@@ -0,0 +1,145 @@
+#!/usr/bin/env python3
+# ctf_writer.py
+#
+# Babeltrace CTF Writer example script.
+#
+# Copyright 2013 EfficiOS Inc.
+#
+# Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+import sys
+import tempfile
+import babeltrace.writer as btw
+
+
+trace_path = tempfile.mkdtemp()
+
+print("Writing trace at {}".format(trace_path))
+writer = btw.Writer(trace_path)
+
+clock = btw.Clock("A_clock")
+print("Clock name is \"{}\"".format(clock.name))
+clock.description = "Simple clock"
+print("Clock description is \"{}\"".format(clock.description))
+print("Clock frequency is {}".format(clock.frequency))
+print("Clock precision is {}".format(clock.precision))
+print("Clock offset_seconds is {}".format(clock.offset_seconds))
+print("Clock offset is {}".format(clock.offset))
+print("Clock is absolute: {}".format(clock.absolute))
+print("Clock time is {}".format(clock.time))
+print("Clock UUID is {}".format(clock.uuid))
+
+writer.add_clock(clock)
+writer.add_environment_field("Python_version", str(sys.version_info))
+
+stream_class = btw.StreamClass("test_stream")
+stream_class.clock = clock
+
+event_class = btw.EventClass("SimpleEvent")
+
+# Create a int32_t equivalent type
+int32_type = btw.IntegerFieldDeclaration(32)
+int32_type.signed = True
+
+# Create a uint16_t equivalent type
+uint16_type = btw.IntegerFieldDeclaration(16)
+uint16_type.signed = False
+
+# Add a custom uint16_t field in the stream's packet context
+packet_context_type = stream_class.packet_context_type
+print("\nFields in default packet context:")
+for field in packet_context_type.fields:
+    print(str(type(field[1])) + " " + field[0])
+packet_context_type.add_field(uint16_type, "a_custom_packet_context_field")
+stream_class.packet_context_type = packet_context_type
+
+# Create a string type
+string_type = btw.StringFieldDeclaration()
+
+# Create a structure type containing both an integer and a string
+structure_type = btw.StructureFieldDeclaration()
+structure_type.add_field(int32_type, "an_integer")
+structure_type.add_field(string_type, "a_string_field")
+event_class.add_field(structure_type, "structure_field")
+
+# Create a floating point type
+floating_point_type = btw.FloatFieldDeclaration()
+floating_point_type.exponent_digits = btw.FloatFieldDeclaration.FLT_EXP_DIG
+floating_point_type.mantissa_digits = btw.FloatFieldDeclaration.FLT_MANT_DIG
+event_class.add_field(floating_point_type, "float_field")
+
+# Create an enumeration type
+int10_type = btw.IntegerFieldDeclaration(10)
+enumeration_type = btw.EnumerationFieldDeclaration(int10_type)
+enumeration_type.add_mapping("FIRST_ENTRY", 0, 4)
+enumeration_type.add_mapping("SECOND_ENTRY", 5, 5)
+enumeration_type.add_mapping("THIRD_ENTRY", 6, 10)
+event_class.add_field(enumeration_type, "enum_field")
+
+# Create an array type
+array_type = btw.ArrayFieldDeclaration(int10_type, 5)
+event_class.add_field(array_type, "array_field")
+
+# Create a sequence type
+sequence_type = btw.SequenceFieldDeclaration(int32_type, "sequence_len")
+event_class.add_field(uint16_type, "sequence_len")
+event_class.add_field(sequence_type, "sequence_field")
+
+stream_class.add_event_class(event_class)
+stream = writer.create_stream(stream_class)
+
+for i in range(100):
+    event = btw.Event(event_class)
+
+    clock.time = i * 1000
+    structure_field = event.payload("structure_field")
+    integer_field = structure_field.field("an_integer")
+    integer_field.value = i
+
+    string_field = structure_field.field("a_string_field")
+    string_field.value = "Test string."
+
+    float_field = event.payload("float_field")
+    float_field.value = float(i) + (float(i) / 100.0)
+
+    array_field = event.payload("array_field")
+    for j in range(5):
+        element = array_field.field(j)
+        element.value = i + j
+
+    event.payload("sequence_len").value = i % 10
+    sequence_field = event.payload("sequence_field")
+    sequence_field.length = event.payload("sequence_len")
+    for j in range(event.payload("sequence_len").value):
+        sequence_field.field(j).value = i + j
+
+    enumeration_field = event.payload("enum_field")
+    integer_field = enumeration_field.container
+    enumeration_field.value = i % 10
+
+    stream.append_event(event)
+
+# Populate custom packet context field before flushing
+packet_context = stream.packet_context
+field = packet_context.field("a_custom_packet_context_field")
+field.value = 42
+
+stream.flush()
diff --git a/bindings/python/babeltrace/examples/example-api-test.py b/bindings/python/babeltrace/examples/example-api-test.py
new file mode 100644 (file)
index 0000000..1bdea6c
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/env python3
+# example_api_test.py
+#
+# Babeltrace example script based on the Babeltrace API test script
+#
+# Copyright 2012 EfficiOS Inc.
+#
+# Author: Danny Serres <danny.serres@efficios.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+# This example uses the babeltrace python module
+# to partially test the api.
+
+import sys
+import babeltrace.reader
+
+
+# Check for path arg:
+if len(sys.argv) < 2:
+    raise TypeError("Usage: python example-api-test.py path/to/file")
+
+# Create TraceCollection and add trace:
+traces = babeltrace.reader.TraceCollection()
+trace_handle = traces.add_trace(sys.argv[1], "ctf")
+if trace_handle is None:
+    raise IOError("Error adding trace")
+
+# Listing events
+print("--- Event list ---")
+for event_declaration in trace_handle.events:
+    print("event : {}".format(event_declaration.name))
+    if event_declaration.name == "sched_switch":
+        for field_declaration in event_declaration.fields:
+            print(field_declaration)
+print("--- Done ---")
+
+for event in traces.events:
+    print("TS: {}, {} : {}".format(event.timestamp, event.cycles, event.name))
+
+    if event.name == "sched_switch":
+        prev_comm = event["prev_comm"]
+        if prev_comm is None:
+            print("ERROR: Missing prev_comm context info")
+        else:
+            print("sched_switch prev_comm: {}".format(prev_comm))
+
+    if event.name == "exit_syscall":
+        ret_code = event["ret"]
+        if ret_code is None:
+            print("ERROR: Unable to extract ret")
+        else:
+            print("exit_syscall ret: {}".format(ret_code))
diff --git a/bindings/python/babeltrace/examples/sched_switch.py b/bindings/python/babeltrace/examples/sched_switch.py
new file mode 100644 (file)
index 0000000..0deb4a5
--- /dev/null
@@ -0,0 +1,79 @@
+#!/usr/bin/env python3
+# sched_switch.py
+#
+# Babeltrace example script with sched_switch events
+#
+# Copyright 2012 EfficiOS Inc.
+#
+# Author: Danny Serres <danny.serres@efficios.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+# The script takes one optional argument (pid)
+# The script will read events based on pid and
+# print the scheduler switches happening with the process.
+# If no arguments are passed, it displays all the scheduler switches.
+# This can be used to understand which tasks schedule out the current
+# process being traced, and when it gets scheduled in again.
+# The trace needs PID context (lttng add-context -k -t pid)
+
+import sys
+import babeltrace.reader
+import babeltrace.common
+
+
+if len(sys.argv) < 2 or len(sys.argv) > 3:
+    raise TypeError("Usage: python sched_switch.py [pid] path/to/trace")
+elif len(sys.argv) == 3:
+    filterPID = True
+else:
+    filterPID = False
+
+traces = babeltrace.reader.TraceCollection()
+ret = traces.add_trace(sys.argv[len(sys.argv) - 1], "ctf")
+if ret is None:
+    raise IOError("Error adding trace")
+
+for event in traces.events:
+    if event.name != "sched_switch":
+        continue
+
+    # Getting PID
+    pid = event.field_with_scope("pid", babeltrace.common.CTFScope.STREAM_EVENT_CONTEXT)
+    if pid is None:
+        print("ERROR: Missing PID info for sched_switch")
+        continue  # Next event
+
+    if filterPID and (pid != long(sys.argv[1])):
+        continue  # Next event
+
+    prev_comm = event["prev_comm"]
+    prev_tid = event["prev_tid"]
+    prev_prio = event["prev_prio"]
+    prev_state = event["prev_state"]
+    next_comm = event["next_comm"]
+    next_tid = event["next_tid"]
+    next_prio = event["next_prio"]
+
+    # Output
+    print("sched_switch, pid = {}, TS = {}, prev_comm = {},\n\t"
+          "prev_tid = {}, prev_prio = {}, prev_state = {},\n\t"
+          "next_comm = {}, next_tid = {}, next_prio = {}".format(
+              pid, event.timestamp, prev_comm, prev_tid,
+              prev_prio, prev_state, next_comm, next_tid, next_prio))
diff --git a/bindings/python/babeltrace/examples/sequence_test.py b/bindings/python/babeltrace/examples/sequence_test.py
new file mode 100644 (file)
index 0000000..e9116ce
--- /dev/null
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+# sequence_test.py
+#
+# Babeltrace example script based on the Babeltrace API test script
+#
+# Copyright 2013 Xiaona Han
+# Copyright 2012 EfficiOS Inc.
+#
+# Author: Danny Serres <danny.serres@efficios.com>
+# Author: Xiaona Han <xiaonahappy13@163.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+# This example uses the babeltrace python module
+# to partially test the sequence API
+
+import sys
+import babeltrace.reader
+
+
+# Check for path arg:
+if len(sys.argv) < 2:
+    raise TypeError("Usage: sequence_test.py path/to/file")
+
+# Create TraceCollection and add trace:
+traces = babeltrace.reader.TraceCollection()
+trace_handle = traces.add_trace(sys.argv[1], "ctf")
+if trace_handle is None:
+    raise IOError("Error adding trace")
+
+# Listing events
+print("--- Event list ---")
+for event_declaration in trace_handle.events:
+    print("event : {}".format(event_declaration.name))
+print("--- Done ---")
+
+for event in traces.events:
+    print("TS: {}, {} : {}".format(event.timestamp,
+                                   event.cycles, event.name))
+
+    try:
+        sequence = event["seq_int_field"]
+        print("int sequence values: {}". format(sequence))
+    except KeyError:
+        pass
+
+    try:
+        sequence = event["seq_long_field"]
+        print("long sequence values: {}". format(sequence))
+    except KeyError:
+        pass
diff --git a/bindings/python/babeltrace/nativebt.i b/bindings/python/babeltrace/nativebt.i
new file mode 100644 (file)
index 0000000..15726ba
--- /dev/null
@@ -0,0 +1,646 @@
+/*
+ * nativebt.i.in
+ *
+ * Babeltrace native interface Python module
+ *
+ * Copyright 2012 EfficiOS Inc.
+ *
+ * Author: Danny Serres <danny.serres@efficios.com>
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+%module nativebt
+
+
+%include "stdint.i"
+%include "typemaps.i"
+%{
+#define SWIG_FILE_WITH_INIT
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/trace-handle.h>
+#include <babeltrace/trace-handle-internal.h>
+#include <babeltrace/context.h>
+#include <babeltrace/context-internal.h>
+#include <babeltrace/iterator.h>
+#include <babeltrace/iterator-internal.h>
+#include <babeltrace/format.h>
+#include <babeltrace/list.h>
+#include <babeltrace/types.h>
+#include <babeltrace/ctf/iterator.h>
+#include "python-complements.h"
+#include <babeltrace/ctf-writer/clock.h>
+#include <babeltrace/ctf-writer/event-fields.h>
+#include <babeltrace/ctf-writer/event-types.h>
+#include <babeltrace/ctf-writer/event.h>
+#include <babeltrace/ctf-writer/stream.h>
+#include <babeltrace/ctf-writer/writer.h>
+%}
+
+
+typedef int bt_intern_str;
+typedef int64_t ssize_t;
+
+
+/* python-complements.h */
+struct bt_definition **_bt_python_field_listcaller(
+               const struct bt_ctf_event *ctf_event,
+               const struct bt_definition *scope,
+               unsigned int *OUTPUT);
+struct bt_definition *_bt_python_field_one_from_list(
+               struct bt_definition **list, int index);
+struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
+               int handle_id,
+               struct bt_context *ctx,
+               unsigned int *OUTPUT);
+struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
+               struct bt_ctf_event_decl **list, int index);
+struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
+               struct bt_ctf_event_decl *event_decl,
+               enum ctf_scope scope,
+               unsigned int *OUTPUT);
+struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
+               struct bt_ctf_field_decl **list, int index);
+struct definition_array *_bt_python_get_array_from_def(
+               struct bt_definition *field);
+struct definition_sequence *_bt_python_get_sequence_from_def(
+               struct bt_definition *field);
+struct bt_declaration *_bt_python_get_array_element_declaration(
+               struct bt_declaration *field);
+struct bt_declaration *_bt_python_get_sequence_element_declaration(
+               struct bt_declaration *field);
+const char *_bt_python_get_array_string(struct bt_definition *field);
+const char *_bt_python_get_sequence_string(struct bt_definition *field);
+int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
+enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
+const char *_bt_python_ctf_field_type_enumeration_get_mapping(
+               struct bt_ctf_field_type *enumeration, size_t index,
+               int64_t *OUTPUT, int64_t *OUTPUT);
+const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
+               struct bt_ctf_field_type *enumeration, size_t index,
+               uint64_t *OUTPUT, uint64_t *OUTPUT);
+const char *_bt_python_ctf_field_type_structure_get_field_name(
+               struct bt_ctf_field_type *structure, size_t index);
+struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
+               struct bt_ctf_field_type *structure, size_t index);
+const char *_bt_python_ctf_field_type_variant_get_field_name(
+               struct bt_ctf_field_type *variant, size_t index);
+struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
+               struct bt_ctf_field_type *variant, size_t index);
+const char *_bt_python_ctf_event_class_get_field_name(
+               struct bt_ctf_event_class *event_class, size_t index);
+struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
+               struct bt_ctf_event_class *event_class, size_t index);
+int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char *OUTPUT);
+int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char value);
+struct bt_iter_pos *_bt_python_create_iter_pos(void);
+struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect(
+               struct bt_context *ctx,
+               struct bt_iter_pos *inter_begin_pos,
+               struct bt_iter_pos *inter_end_pos);
+int _bt_python_trace_collection_has_intersection(struct bt_context *ctx);
+
+/* context.h, context-internal.h */
+%rename("_bt_context_create") bt_context_create(void);
+%rename("_bt_context_add_trace") bt_context_add_trace(
+               struct bt_context *ctx, const char *path, const char *format,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
+               struct bt_mmap_stream_list *stream_list, FILE *metadata);
+%rename("_bt_context_remove_trace") bt_context_remove_trace(
+               struct bt_context *ctx, int trace_id);
+%rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
+%rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
+%rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
+               const struct bt_ctf_event *event);
+
+struct bt_context *bt_context_create(void);
+int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
+               struct bt_mmap_stream_list *stream_list, FILE *metadata);
+void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
+void bt_context_get(struct bt_context *ctx);
+void bt_context_put(struct bt_context *ctx);
+struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
+
+
+/* format.h */
+%rename("lookup_format") bt_lookup_format(bt_intern_str qname);
+%rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
+%rename("register_format") bt_register_format(struct format *format);
+%rename("unregister_format") bt_unregister_format(struct bt_format *format);
+
+extern struct format *bt_lookup_format(bt_intern_str qname);
+extern void bt_fprintf_format_list(FILE *fp);
+extern int bt_register_format(struct bt_format *format);
+extern void bt_unregister_format(struct bt_format *format);
+
+
+/* iterator.h, iterator-internal.h */
+%rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
+               const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
+%rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
+%rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
+%rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
+%rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
+%rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
+               const struct bt_iter_pos *pos);
+%rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
+               uint64_t timestamp);
+
+struct bt_iter *bt_iter_create(struct bt_context *ctx,
+               const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
+void bt_iter_destroy(struct bt_iter *iter);
+int bt_iter_next(struct bt_iter *iter);
+struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
+void bt_iter_free_pos(struct bt_iter_pos *pos);
+int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
+struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
+
+%rename("_bt_iter_pos") bt_iter_pos;
+%rename("SEEK_TIME") BT_SEEK_TIME;
+%rename("SEEK_RESTORE") BT_SEEK_RESTORE;
+%rename("SEEK_CUR") BT_SEEK_CUR;
+%rename("SEEK_BEGIN") BT_SEEK_BEGIN;
+%rename("SEEK_LAST") BT_SEEK_LAST;
+
+
+/*
+ * This struct is taken from iterator.h
+ * All changes to the struct must also be made here.
+ */
+struct bt_iter_pos {
+       enum {
+               BT_SEEK_TIME,           /* uses u.seek_time */
+               BT_SEEK_RESTORE,        /* uses u.restore */
+               BT_SEEK_CUR,
+               BT_SEEK_BEGIN,
+               BT_SEEK_LAST
+       } type;
+       union {
+               uint64_t seek_time;
+               struct bt_saved_pos *restore;
+       } u;
+};
+
+
+/* trace-handle.h, trace-handle-internal.h */
+%rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
+%rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
+struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
+void bt_trace_handle_destroy(struct bt_trace_handle *bt);
+
+%rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
+               int handle_id);
+%rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
+               struct bt_context *ctx, int handle_id, enum bt_clock_type type,
+                int64_t *timestamp);
+%rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
+               struct bt_context *ctx, int handle_id, enum bt_clock_type type,
+                int64_t *timestamp);
+const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
+int bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
+               enum bt_clock_type type, int64_t *OUTPUT);
+int bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
+               enum bt_clock_type type, int64_t *OUTPUT);
+
+%rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
+               const struct bt_ctf_event *event);
+int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
+
+
+/* iterator.h, events.h */
+%rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
+               const struct bt_iter_pos *begin_pos,
+               const struct bt_iter_pos *end_pos);
+%rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
+%rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
+%rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
+
+struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
+               const struct bt_iter_pos *begin_pos,
+               const struct bt_iter_pos *end_pos);
+struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
+void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
+struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
+
+
+/* events.h */
+%rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
+               bt_ctf_event *event, enum ctf_scope scope);
+%rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
+%rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
+               const struct bt_ctf_event *ctf_event, int64_t *OUTPUT);
+%rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
+               const struct bt_ctf_event *ctf_event);
+
+%rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
+               const struct bt_definition *scope,      const char *field);
+%rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
+               const struct bt_definition *field,      unsigned int index);
+%rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
+%rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
+%rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
+               const struct bt_declaration *field);
+%rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
+%rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
+               const struct bt_declaration *field);
+%rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
+%rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
+%rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
+%rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
+%rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
+%rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
+%rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
+%rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
+%rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
+%rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
+%rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
+%rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
+%rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
+               bt_ctf_event_decl *event);
+%rename("_bt_ctf_get_decl_event_id") bt_ctf_get_decl_event_id(const struct
+               bt_ctf_event_decl *event);
+%rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
+               const struct bt_ctf_field_decl *field);
+%rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
+               const struct bt_definition *field);
+%rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
+               const struct bt_ctf_field_decl *field);
+%rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
+%rename("_bt_sequence_len")  bt_sequence_len(struct definition_sequence *sequence);
+%rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
+%rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
+%rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
+
+const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
+               enum ctf_scope scope);
+const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
+int bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event, int64_t *OUTPUT);
+uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
+const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
+               const struct bt_definition *scope,
+               const char *field);
+const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
+               const struct bt_definition *field,
+               unsigned int index);
+const char *bt_ctf_field_name(const struct bt_definition *field);
+enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
+int bt_ctf_get_int_signedness(const struct bt_declaration *field);
+int bt_ctf_get_int_base(const struct bt_declaration *field);
+int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
+ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
+const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
+const char *bt_ctf_get_enum_str(const struct bt_definition *field);
+enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
+int bt_ctf_get_array_len(const struct bt_declaration *field);
+struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
+uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
+int64_t bt_ctf_get_int64(const struct bt_definition *field);
+char *bt_ctf_get_char_array(const struct bt_definition *field);
+char *bt_ctf_get_string(const struct bt_definition *field);
+double bt_ctf_get_float(const struct bt_definition *field);
+const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
+int bt_ctf_field_get_error(void);
+const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
+uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
+const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
+const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
+const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
+uint64_t bt_sequence_len(struct definition_sequence *sequence);
+struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
+uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
+const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
+
+
+/* CTF Writer */
+
+/* clock.h */
+%rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
+%rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
+%rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
+%rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
+%rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
+%rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
+%rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
+%rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
+%rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock, int64_t *offset_s);
+%rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, int64_t offset_s);
+%rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock, int64_t *offset);
+%rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, int64_t offset);
+%rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
+%rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
+%rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock, int64_t *time);
+%rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, int64_t time);
+%rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
+%rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
+
+struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
+const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
+const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
+int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
+uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
+int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
+uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
+int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
+int bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock, int64_t *OUTPUT);
+int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, int64_t offset_s);
+int bt_ctf_clock_get_offset(struct bt_ctf_clock *clock, int64_t *OUTPUT);
+int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, int64_t offset);
+int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
+int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
+int bt_ctf_clock_get_time(struct bt_ctf_clock *clock, int64_t *OUTPUT);
+int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, int64_t time);
+void bt_ctf_clock_get(struct bt_ctf_clock *clock);
+void bt_ctf_clock_put(struct bt_ctf_clock *clock);
+
+
+/* event-types.h */
+%rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
+%rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
+%rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
+%rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
+%rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
+%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);
+%rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
+%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);
+%rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
+%rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
+%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);
+%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);
+%rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
+%rename("_bt_ctf_field_type_enumeration_get_mapping") bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, int index, const char **name, int64_t *range_start, int64_t *range_end);
+%rename("_bt_ctf_field_type_enumeration_get_mapping_unsigned") bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, int index, const char **name, uint64_t *range_start, uint64_t *range_end);
+%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);
+%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);
+%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);
+%rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
+%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);
+%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);
+%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);
+%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);
+%rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
+%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);
+%rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
+%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, int index);
+%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);
+%rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
+%rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
+%rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
+%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);
+%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);
+%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);
+%rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
+%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, int index);
+%rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
+%rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
+%rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
+%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);
+%rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
+%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);
+%rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
+%rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
+%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);
+%rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
+%rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
+%rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
+%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);
+%rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
+%rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
+%rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
+
+struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
+int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
+int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
+int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
+enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
+int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
+enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
+int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
+struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
+struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
+int bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *name, int64_t range_start, int64_t range_end);
+int 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);
+int bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
+int bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, int index, const char **OUTPUT, int64_t *OUTPUT, int64_t *OUTPUT);
+int bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, int index, const char **OUTPUT, uint64_t *OUTPUT, uint64_t *OUTPUT);
+int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name);
+int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value);
+int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value);
+struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
+int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
+int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
+int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
+int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
+struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
+int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name);
+int bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
+int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, int index);
+struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name(struct bt_ctf_field_type *structure, const char *field_name);
+struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
+struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
+const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
+int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field_type, const char *field_name);
+struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name(struct bt_ctf_field_type *variant, const char *field_name);
+struct 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);
+int bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
+int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, int index);
+struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
+struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
+int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
+struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
+struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
+const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
+struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
+enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
+int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
+int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
+int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
+enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
+int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
+enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
+void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
+void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
+
+
+/* event-fields.h */
+%rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
+%rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
+%rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
+%rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
+%rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
+%rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
+%rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
+%rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
+%rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
+%rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
+%rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
+%rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
+%rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
+%rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
+%rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
+%rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
+%rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
+%rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
+%rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
+%rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
+
+struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
+struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
+struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
+struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
+int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
+struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
+struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
+struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
+const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
+int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
+int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
+int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
+int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
+int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
+int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
+const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
+int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
+struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
+void bt_ctf_field_get(struct bt_ctf_field *field);
+void bt_ctf_field_put(struct bt_ctf_field *field);
+
+
+/* event-class.h */
+%rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
+%rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
+%rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
+%rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
+%rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
+%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);
+%rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
+%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, int index);
+%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);
+%rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
+%rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
+
+struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
+const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
+int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
+int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
+struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
+int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
+int bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
+int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, int index);
+struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
+void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
+void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
+
+
+/* event.h */
+%rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
+%rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
+%rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
+%rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
+%rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
+%rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, int index);
+%rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
+%rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
+
+struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
+struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
+struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
+struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
+int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
+struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, int index);
+void bt_ctf_event_get(struct bt_ctf_event *event);
+void bt_ctf_event_put(struct bt_ctf_event *event);
+
+
+/* stream-class.h */
+%rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
+%rename("_bt_ctf_stream_class_get_name") bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
+%rename("_bt_ctf_stream_class_get_clock") bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
+%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);
+%rename("_bt_ctf_stream_class_get_id") bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
+%rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
+%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);
+%rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
+%rename("_bt_ctf_stream_class_get_event_class") bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, int index);
+%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);
+%rename("_bt_ctf_stream_class_get_packet_context_type") bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
+%rename("_bt_ctf_stream_class_set_packet_context_type") bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
+%rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
+%rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
+
+struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
+const char *bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
+struct bt_ctf_clock *bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
+int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
+int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
+int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
+int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
+int bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
+struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, int index);
+struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
+struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
+int bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
+void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
+void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
+
+
+/* stream.h */
+%rename("_bt_ctf_stream_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
+%rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
+%rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
+%rename("_bt_ctf_stream_get_packet_context") bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
+%rename("_bt_ctf_stream_set_packet_context") bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
+%rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
+%rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
+%rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
+
+int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
+void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
+int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
+struct bt_ctf_field *bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
+int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
+int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
+void bt_ctf_stream_get(struct bt_ctf_stream *stream);
+void bt_ctf_stream_put(struct bt_ctf_stream *stream);
+
+
+/* writer.h */
+%rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
+%rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
+%rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
+%rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
+%newobject bt_ctf_writer_get_metadata_string;
+%rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
+%rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
+%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);
+%rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
+%rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
+
+struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
+struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
+int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
+int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
+char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
+void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
+int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
+void bt_ctf_writer_get(struct bt_ctf_writer *writer);
+void bt_ctf_writer_put(struct bt_ctf_writer *writer);
diff --git a/bindings/python/babeltrace/python-complements.c b/bindings/python/babeltrace/python-complements.c
new file mode 100644 (file)
index 0000000..0e3bbdf
--- /dev/null
@@ -0,0 +1,423 @@
+/*
+ * python-complements.c
+ *
+ * Babeltrace Python module complements, required for Python bindings
+ *
+ * Copyright 2012 EfficiOS Inc.
+ *
+ * Author: Danny Serres <danny.serres@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ */
+
+#include "python-complements.h"
+#include <babeltrace/ctf-ir/field-types-internal.h>
+#include <babeltrace/ctf-ir/fields-internal.h>
+#include <babeltrace/ctf-ir/field-types.h>
+#include <babeltrace/ctf-ir/event.h>
+#include <babeltrace/ctf-ir/event-class.h>
+#include <babeltrace/ctf-ir/clock-internal.h>
+#include <babeltrace/iterator.h>
+#include <babeltrace/ctf/iterator.h>
+#include <babeltrace/ctf/events-internal.h>
+#include <glib.h>
+
+/* List-related functions
+   ----------------------------------------------------
+*/
+
+/* ctf-field-list */
+struct bt_definition **_bt_python_field_listcaller(
+               const struct bt_ctf_event *ctf_event,
+               const struct bt_definition *scope,
+               unsigned int *len)
+{
+       struct bt_definition **list;
+       int ret;
+
+       ret = bt_ctf_get_field_list(ctf_event, scope,
+               (const struct bt_definition * const **)&list, len);
+
+       if (ret < 0)    /* For python to know an error occured */
+               list = NULL;
+
+       return list;
+}
+
+struct bt_definition *_bt_python_field_one_from_list(
+               struct bt_definition **list, int index)
+{
+       return list[index];
+}
+
+/* event_decl_list */
+struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
+               int handle_id,
+               struct bt_context *ctx,
+               unsigned int *len)
+{
+       struct bt_ctf_event_decl **list;
+       int ret;
+
+       ret = bt_ctf_get_event_decl_list(handle_id, ctx,
+               (struct bt_ctf_event_decl * const **)&list, len);
+
+       if (ret < 0)    /* For python to know an error occured */
+               list = NULL;
+
+       return list;
+}
+
+struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
+               struct bt_ctf_event_decl **list, int index)
+{
+       return list[index];
+}
+
+/* decl_fields */
+struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
+               struct bt_ctf_event_decl *event_decl,
+               enum ctf_scope scope,
+               unsigned int *len)
+{
+       struct bt_ctf_field_decl **list;
+       int ret;
+
+       ret = bt_ctf_get_decl_fields(event_decl, scope,
+               (const struct bt_ctf_field_decl * const **)&list, len);
+
+       if (ret < 0)    /* For python to know an error occured */
+               list = NULL;
+
+       return list;
+}
+
+struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
+               struct bt_ctf_field_decl **list, int index)
+{
+       return list[index];
+}
+
+struct definition_array *_bt_python_get_array_from_def(
+               struct bt_definition *field)
+{
+       const struct bt_declaration *array_decl;
+       struct definition_array *array = NULL;
+
+       if (!field) {
+               goto end;
+       }
+
+       array_decl = bt_ctf_get_decl_from_def(field);
+       if (bt_ctf_field_type(array_decl) == CTF_TYPE_ARRAY) {
+               array = container_of(field, struct definition_array, p);
+       }
+end:
+       return array;
+}
+
+struct bt_declaration *_bt_python_get_array_element_declaration(
+               struct bt_declaration *field)
+{
+       struct declaration_array *array_decl;
+       struct bt_declaration *ret = NULL;
+
+       if (!field) {
+               goto end;
+       }
+
+       array_decl = container_of(field, struct declaration_array, p);
+       ret = array_decl->elem;
+end:
+       return ret;
+}
+
+struct bt_declaration *_bt_python_get_sequence_element_declaration(
+               struct bt_declaration *field)
+{
+       struct declaration_sequence *sequence_decl;
+       struct bt_declaration *ret = NULL;
+
+       if (!field) {
+               goto end;
+       }
+
+       sequence_decl = container_of(field, struct declaration_sequence, p);
+       ret = sequence_decl->elem;
+end:
+       return ret;
+}
+
+const char *_bt_python_get_array_string(struct bt_definition *field)
+{
+       struct definition_array *array;
+       const char *ret = NULL;
+
+       if (!field) {
+               goto end;
+       }
+
+       array = container_of(field, struct definition_array, p);
+       ret = array->string->str;
+end:
+       return ret;
+}
+
+const char *_bt_python_get_sequence_string(struct bt_definition *field)
+{
+       struct definition_sequence *sequence;
+       const char *ret = NULL;
+
+       if (!field) {
+               goto end;
+       }
+
+       sequence = container_of(field, struct definition_sequence, p);
+       ret = sequence->string->str;
+end:
+       return ret;
+}
+
+struct definition_sequence *_bt_python_get_sequence_from_def(
+               struct bt_definition *field)
+{
+       if (field && bt_ctf_field_type(
+               bt_ctf_get_decl_from_def(field)) == CTF_TYPE_SEQUENCE) {
+               return container_of(field, struct definition_sequence, p);
+       }
+
+       return NULL;
+}
+
+int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field)
+{
+       int ret;
+
+       if (!field || field->type->declaration->id != CTF_TYPE_INTEGER) {
+               ret = -1;
+               goto end;
+       }
+
+       const struct bt_ctf_field_type_integer *type = container_of(field->type,
+               const struct bt_ctf_field_type_integer, parent);
+       ret = type->declaration.signedness;
+end:
+       return ret;
+}
+
+enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field)
+{
+       enum ctf_type_id type_id = CTF_TYPE_UNKNOWN;
+
+       if (!field) {
+               goto end;
+       }
+
+       type_id = field->type->declaration->id;
+end:
+       return type_id;
+}
+
+/*
+ * Swig doesn't handle returning pointers via output arguments properly...
+ * These functions only wrap the ctf-ir functions to provide them directly
+ * as regular return values.
+ */
+const char *_bt_python_ctf_field_type_enumeration_get_mapping(
+               struct bt_ctf_field_type *enumeration, size_t index,
+               int64_t *range_start, int64_t *range_end)
+{
+       int ret;
+       const char *name;
+
+       ret = bt_ctf_field_type_enumeration_get_mapping(enumeration, index,
+               &name, range_start, range_end);
+       return !ret ? name : NULL;
+}
+
+const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
+               struct bt_ctf_field_type *enumeration, size_t index,
+               uint64_t *range_start, uint64_t *range_end)
+{
+       int ret;
+       const char *name;
+
+       ret = bt_ctf_field_type_enumeration_get_mapping_unsigned(enumeration,
+               index, &name, range_start, range_end);
+       return !ret ? name : NULL;
+}
+
+const char *_bt_python_ctf_field_type_structure_get_field_name(
+               struct bt_ctf_field_type *structure, size_t index)
+{
+       int ret;
+       const char *name;
+       struct bt_ctf_field_type *type;
+
+       ret = bt_ctf_field_type_structure_get_field(structure, &name, &type,
+               index);
+       if (ret) {
+               name = NULL;
+               goto end;
+       }
+
+       bt_ctf_field_type_put(type);
+end:
+       return name;
+}
+
+struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
+               struct bt_ctf_field_type *structure, size_t index)
+{
+       int ret;
+       const char *name;
+       struct bt_ctf_field_type *type;
+
+       ret = bt_ctf_field_type_structure_get_field(structure, &name, &type,
+               index);
+       return !ret ? type : NULL;
+}
+
+const char *_bt_python_ctf_field_type_variant_get_field_name(
+               struct bt_ctf_field_type *variant, size_t index)
+{
+       int ret;
+       const char *name;
+       struct bt_ctf_field_type *type;
+
+       ret = bt_ctf_field_type_variant_get_field(variant, &name, &type,
+               index);
+       if (ret) {
+               name = NULL;
+               goto end;
+       }
+
+       bt_ctf_field_type_put(type);
+end:
+       return name;
+}
+
+struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
+               struct bt_ctf_field_type *variant, size_t index)
+{
+       int ret;
+       const char *name;
+       struct bt_ctf_field_type *type;
+
+       ret = bt_ctf_field_type_variant_get_field(variant, &name, &type,
+               index);
+       return !ret ? type : NULL;
+}
+
+const char *_bt_python_ctf_event_class_get_field_name(
+               struct bt_ctf_event_class *event_class, size_t index)
+{
+       int ret;
+       const char *name;
+       struct bt_ctf_field_type *type;
+
+       ret = bt_ctf_event_class_get_field(event_class, &name, &type,
+               index);
+       if (ret) {
+               name = NULL;
+               goto end;
+       }
+
+       bt_ctf_field_type_put(type);
+end:
+       return name;
+}
+
+struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
+               struct bt_ctf_event_class *event_class, size_t index)
+{
+       int ret;
+       const char *name;
+       struct bt_ctf_field_type *type;
+
+       ret = bt_ctf_event_class_get_field(event_class, &name, &type,
+               index);
+       return !ret ? type : NULL;
+}
+
+int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char *value)
+{
+       int ret = 0;
+       const unsigned char *uuid;
+
+       if (index >= 16) {
+               ret = -1;
+               goto end;
+       }
+
+       uuid = bt_ctf_clock_get_uuid(clock);
+       if (!uuid) {
+               ret = -1;
+               goto end;
+       }
+
+       *value = uuid[index];
+end:
+       return ret;
+}
+
+int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char value)
+{
+       int ret = 0;
+
+       if (index >= 16) {
+               ret = -1;
+               goto end;
+       }
+
+       clock->uuid[index] = value;
+end:
+       return ret;
+}
+
+/*
+ * Python 3.5 changes the StopIteration exception clearing behaviour which
+ * erroneously marks swig clean-up function as having failed. This explicit
+ * allocation function is intended as a work-around so SWIG doesn't manage
+ * the lifetime of a "temporary" object by itself.
+ */
+struct bt_iter_pos *_bt_python_create_iter_pos(void)
+{
+       return g_new0(struct bt_iter_pos, 1);
+}
+
+struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect(
+               struct bt_context *ctx,
+               struct bt_iter_pos *inter_begin_pos,
+               struct bt_iter_pos *inter_end_pos)
+{
+       return bt_ctf_iter_create_intersect(ctx, &inter_begin_pos,
+                       &inter_end_pos);
+}
+
+int _bt_python_trace_collection_has_intersection(struct bt_context *ctx)
+{
+       int ret;
+       int64_t begin, end;
+
+       ret = ctf_find_tc_stream_packet_intersection_union(ctx, &begin, &end);
+
+       return ret == 0 ? 1 : 0;
+}
diff --git a/bindings/python/babeltrace/python-complements.h b/bindings/python/babeltrace/python-complements.h
new file mode 100644 (file)
index 0000000..8c8ce87
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * python-complements.h
+ *
+ * Babeltrace Python module complements header, required for Python bindings
+ *
+ * Copyright 2012 EfficiOS Inc.
+ *
+ * Author: Danny Serres <danny.serres@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ */
+
+#include <stdio.h>
+#include <glib.h>
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/format.h>
+#include <babeltrace/ctf-ir/metadata.h>
+#include <babeltrace/ctf/events.h>
+#include <babeltrace/iterator-internal.h>
+#include <babeltrace/ctf/events-internal.h>
+#include <babeltrace/ctf-writer/event-fields.h>
+#include <babeltrace/ctf-writer/clock.h>
+
+/* ctf-field-list */
+struct bt_definition **_bt_python_field_listcaller(
+               const struct bt_ctf_event *ctf_event,
+               const struct bt_definition *scope,
+               unsigned int *len);
+struct bt_definition *_bt_python_field_one_from_list(
+               struct bt_definition **list, int index);
+
+/* event_decl_list */
+struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
+               int handle_id,
+               struct bt_context *ctx,
+               unsigned int *len);
+struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
+               struct bt_ctf_event_decl **list, int index);
+
+/* decl_fields */
+struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
+               struct bt_ctf_event_decl *event_decl,
+               enum ctf_scope scope,
+               unsigned int *len);
+struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
+               struct bt_ctf_field_decl **list, int index);
+
+/* definitions */
+struct definition_array *_bt_python_get_array_from_def(
+               struct bt_definition *field);
+struct definition_sequence *_bt_python_get_sequence_from_def(
+               struct bt_definition *field);
+struct bt_declaration *_bt_python_get_array_element_declaration(
+               struct bt_declaration *field);
+struct bt_declaration *_bt_python_get_sequence_element_declaration(
+               struct bt_declaration *field);
+const char *_bt_python_get_array_string(struct bt_definition *field);
+const char *_bt_python_get_sequence_string(struct bt_definition *field);
+
+/* ctf ir */
+int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
+enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
+const char *_bt_python_ctf_field_type_enumeration_get_mapping(
+               struct bt_ctf_field_type *enumeration, size_t index,
+               int64_t *range_start, int64_t *range_end);
+const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
+               struct bt_ctf_field_type *enumeration, size_t index,
+               uint64_t *range_start, uint64_t *range_end);
+const char *_bt_python_ctf_field_type_structure_get_field_name(
+               struct bt_ctf_field_type *structure, size_t index);
+struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
+               struct bt_ctf_field_type *structure, size_t index);
+const char *_bt_python_ctf_field_type_variant_get_field_name(
+               struct bt_ctf_field_type *variant, size_t index);
+struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
+               struct bt_ctf_field_type *variant, size_t index);
+const char *_bt_python_ctf_event_class_get_field_name(
+               struct bt_ctf_event_class *event_class, size_t index);
+struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
+               struct bt_ctf_event_class *event_class, size_t index);
+int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char *value);
+int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char value);
+
+/* iterator */
+struct bt_iter_pos *_bt_python_create_iter_pos(void);
+struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect(
+               struct bt_context *ctx,
+               struct bt_iter_pos *inter_begin_pos,
+               struct bt_iter_pos *inter_end_pos);
+int _bt_python_trace_collection_has_intersection(struct bt_context *ctx);
diff --git a/bindings/python/babeltrace/reader.py b/bindings/python/babeltrace/reader.py
new file mode 100644 (file)
index 0000000..7756db1
--- /dev/null
@@ -0,0 +1,1266 @@
+# reader.py
+#
+# Babeltrace reader interface Python module
+#
+# Copyright 2012-2015 EfficiOS Inc.
+#
+# Author: Danny Serres <danny.serres@efficios.com>
+# Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+import babeltrace.nativebt as nbt
+import babeltrace.common as common
+import collections
+import os
+from datetime import datetime
+
+
+class TraceCollection:
+    """
+    A :class:`TraceCollection` is a collection of opened traces.
+
+    Once a trace collection is created, you can add traces to the
+    collection by using the :meth:`add_trace` or
+    :meth:`add_traces_recursive`, and then iterate on the merged
+    events using :attr:`events`.
+
+    You may use :meth:`remove_trace` to close and remove a specific
+    trace from a trace collection.
+    """
+
+    def __init__(self, intersect_mode=False):
+        """
+        Creates an empty trace collection.
+        """
+
+        self._tc = nbt._bt_context_create()
+        self._intersect_mode = intersect_mode
+
+    def __del__(self):
+        nbt._bt_context_put(self._tc)
+
+    def add_trace(self, path, format_str):
+        """
+        Adds a trace to the trace collection.
+
+        *path* is the exact path of the trace on the filesystem.
+
+        *format_str* is a string indicating the type of trace to
+        add. ``ctf`` is currently the only supported trace format.
+
+        Returns the corresponding :class:`TraceHandle` instance for
+        this opened trace on success, or ``None`` on error.
+
+        This function **does not** recurse directories to find a
+        trace.  See :meth:`add_traces_recursive` for a recursive
+        version of this function.
+        """
+
+        ret = nbt._bt_context_add_trace(self._tc, path, format_str,
+                                        None, None, None)
+
+        if ret < 0:
+            return None
+
+        th = TraceHandle.__new__(TraceHandle)
+        th._id = ret
+        th._trace_collection = self
+
+        return th
+
+    def add_traces_recursive(self, path, format_str):
+        """
+        Adds traces to this trace collection by recursively searching
+        in the *path* directory.
+
+        *format_str* is a string indicating the type of trace to add.
+        ``ctf`` is currently the only supported trace format.
+
+        Returns a :class:`dict` object mapping full paths to trace
+        handles for each trace found, or ``None`` on error.
+
+        See also :meth:`add_trace`.
+        """
+
+        trace_handles = {}
+        noTrace = True
+        error = False
+
+        for fullpath, dirs, files in os.walk(path):
+            if "metadata" in files:
+                trace_handle = self.add_trace(fullpath, format_str)
+
+                if trace_handle is None:
+                    error = True
+                    continue
+
+                trace_handles[fullpath] = trace_handle
+                noTrace = False
+
+        if noTrace and error:
+            return None
+
+        return trace_handles
+
+    def remove_trace(self, trace_handle):
+        """
+        Removes a trace from the trace collection using its trace
+        handle *trace_handle*.
+
+        :class:`TraceHandle` objects are returned by :meth:`add_trace`
+        and :meth:`add_traces_recursive`.
+        """
+
+        try:
+            nbt._bt_context_remove_trace(self._tc, trace_handle._id)
+        except AttributeError:
+            raise TypeError("in remove_trace, argument 2 must be a TraceHandle instance")
+
+    @property
+    def intersect_mode(self):
+        return self._intersect_mode
+
+    @property
+    def has_intersection(self):
+        return nbt._bt_python_trace_collection_has_intersection(self._tc)
+
+    @property
+    def events(self):
+        """
+        Generates the ordered :class:`Event` objects of all the opened
+        traces contained in this trace collection.
+
+        Due to limitations of the native Babeltrace API, only one event
+        may be "alive" at a given time, i.e. a user **should never**
+        store a copy of the events returned by this function for
+        ulterior use. Users shall make sure to copy the information
+        they need *from* an event before accessing the next one.
+        """
+
+        begin_pos_ptr = nbt._bt_python_create_iter_pos()
+        end_pos_ptr = nbt._bt_python_create_iter_pos()
+
+        if not self.intersect_mode:
+            begin_pos_ptr.type = nbt.SEEK_BEGIN
+            end_pos_ptr.type = nbt.SEEK_LAST
+
+        for event in self._events(begin_pos_ptr, end_pos_ptr):
+            yield event
+
+        nbt._bt_iter_free_pos(begin_pos_ptr)
+        nbt._bt_iter_free_pos(end_pos_ptr)
+
+    def events_timestamps(self, timestamp_begin, timestamp_end):
+        """
+        Generates the ordered :class:`Event` objects of all the opened
+        traces contained in this trace collection from *timestamp_begin*
+        to *timestamp_end*.
+
+        *timestamp_begin* and *timestamp_end* are given in nanoseconds
+        since Epoch.
+
+        See :attr:`events` for notes and limitations.
+        """
+
+        begin_pos_ptr = nbt._bt_python_create_iter_pos()
+        end_pos_ptr = nbt._bt_python_create_iter_pos()
+        begin_pos_ptr.type = end_pos_ptr.type = nbt.SEEK_TIME
+        begin_pos_ptr.u.seek_time = timestamp_begin
+        end_pos_ptr.u.seek_time = timestamp_end
+
+        for event in self._events(begin_pos_ptr, end_pos_ptr):
+            yield event
+
+        nbt._bt_iter_free_pos(begin_pos_ptr)
+        nbt._bt_iter_free_pos(end_pos_ptr)
+
+    @property
+    def timestamp_begin(self):
+        """
+        Begin timestamp of this trace collection (nanoseconds since
+        Epoch).
+        """
+
+        pos_ptr = nbt._bt_iter_pos()
+        pos_ptr.type = nbt.SEEK_BEGIN
+
+        return self._timestamp_at_pos(pos_ptr)
+
+    @property
+    def timestamp_end(self):
+        """
+        End timestamp of this trace collection (nanoseconds since
+        Epoch).
+        """
+
+        pos_ptr = nbt._bt_iter_pos()
+        pos_ptr.type = nbt.SEEK_LAST
+
+        return self._timestamp_at_pos(pos_ptr)
+
+    def _timestamp_at_pos(self, pos_ptr):
+        ctf_it_ptr = nbt._bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
+
+        if ctf_it_ptr is None:
+            raise NotImplementedError("Creation of multiple iterators is unsupported.")
+
+        ev_ptr = nbt._bt_ctf_iter_read_event(ctf_it_ptr)
+        nbt._bt_ctf_iter_destroy(ctf_it_ptr)
+
+        ev = Event.__new__(Event)
+        ev._e = ev_ptr
+
+        return ev.timestamp
+
+    def _events(self, begin_pos_ptr, end_pos_ptr):
+        if self.intersect_mode:
+            if not self.has_intersection:
+                # There are no events to provide.
+                return
+
+            ctf_it_ptr = nbt._bt_python_ctf_iter_create_intersect(
+                self._tc, begin_pos_ptr, end_pos_ptr
+            )
+        else:
+            ctf_it_ptr = nbt._bt_ctf_iter_create(
+                self._tc, begin_pos_ptr, end_pos_ptr
+            )
+
+        if ctf_it_ptr is None:
+            raise NotImplementedError("Creation of multiple iterators is unsupported.")
+
+        while True:
+            ev_ptr = nbt._bt_ctf_iter_read_event(ctf_it_ptr)
+
+            if ev_ptr is None:
+                break
+
+            ev = Event.__new__(Event)
+            ev._e = ev_ptr
+
+            try:
+                yield ev
+            except GeneratorExit:
+                break
+
+            ret = nbt._bt_iter_next(nbt._bt_ctf_get_iter(ctf_it_ptr))
+
+            if ret != 0:
+                break
+
+        nbt._bt_ctf_iter_destroy(ctf_it_ptr)
+
+
+# Based on enum bt_clock_type in clock-type.h
+class _ClockType:
+    CLOCK_CYCLES = 0
+    CLOCK_REAL = 1
+
+
+class TraceHandle:
+    """
+    A :class:`TraceHandle` is a handle allowing the user to manipulate
+    a specific trace directly. It is a unique identifier representing a
+    trace, and is not meant to be instantiated by the user.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("TraceHandle cannot be instantiated")
+
+    def __repr__(self):
+        return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
+
+    @property
+    def id(self):
+        """
+        Numeric ID of this trace handle.
+        """
+
+        return self._id
+
+    @property
+    def path(self):
+        """
+        Path of the underlying trace.
+        """
+
+        return nbt._bt_trace_handle_get_path(self._trace_collection._tc,
+                                             self._id)
+
+    @property
+    def timestamp_begin(self):
+        """
+        Buffers creation timestamp (nanoseconds since Epoch) of the
+        underlying trace.
+        """
+
+        ret, value = nbt._bt_trace_handle_get_timestamp_begin(
+            self._trace_collection._tc, self._id, _ClockType.CLOCK_REAL)
+        if ret != 0:
+            raise ValueError("Invalid TraceHandle")
+        return value
+
+    @property
+    def timestamp_end(self):
+        """
+        Buffers destruction timestamp (nanoseconds since Epoch) of the
+        underlying trace.
+        """
+
+        ret, value = nbt._bt_trace_handle_get_timestamp_end(
+            self._trace_collection._tc, self._id, _ClockType.CLOCK_REAL)
+        if ret != 0:
+            raise ValueError("Invalid TraceHandle")
+        return value
+
+    @property
+    def events(self):
+        """
+        Generates all the :class:`EventDeclaration` objects of the
+        underlying trace.
+        """
+
+        ret = nbt._bt_python_event_decl_listcaller(self.id,
+                                                   self._trace_collection._tc)
+
+        if not isinstance(ret, list):
+            return
+
+        ptr_list, count = ret
+
+        for i in range(count):
+            tmp = EventDeclaration.__new__(EventDeclaration)
+            tmp._ed = nbt._bt_python_decl_one_from_list(ptr_list, i)
+            yield tmp
+
+
+
+
+# Priority of the scopes when searching for event fields
+_scopes = [
+    common.CTFScope.EVENT_FIELDS,
+    common.CTFScope.EVENT_CONTEXT,
+    common.CTFScope.STREAM_EVENT_CONTEXT,
+    common.CTFScope.STREAM_EVENT_HEADER,
+    common.CTFScope.STREAM_PACKET_CONTEXT,
+    common.CTFScope.TRACE_PACKET_HEADER
+]
+
+
+class Event(collections.Mapping):
+    """
+    An :class:`Event` object represents a trace event. :class:`Event`
+    objects are returned by :attr:`TraceCollection.events` and are
+    not meant to be instantiated by the user.
+
+    :class:`Event` has a :class:`dict`-like interface for accessing
+    an event's field value by field name:
+
+    .. code-block:: python
+
+       event['my_field']
+
+    If a field name exists in multiple scopes, the value of the first
+    field found is returned. The scopes are searched in the following
+    order:
+
+    1. Event fields (:attr:`babeltrace.common.CTFScope.EVENT_FIELDS`)
+    2. Event context (:attr:`babeltrace.common.CTFScope.EVENT_CONTEXT`)
+    3. Stream event context (:attr:`babeltrace.common.CTFScope.STREAM_EVENT_CONTEXT`)
+    4. Event header (:attr:`babeltrace.common.CTFScope.STREAM_EVENT_HEADER`)
+    5. Packet context (:attr:`babeltrace.common.CTFScope.STREAM_PACKET_CONTEXT`)
+    6. Packet header (:attr:`babeltrace.common.CTFScope.TRACE_PACKET_HEADER`)
+
+    It is still possible to obtain a field's value from a specific
+    scope using :meth:`field_with_scope`.
+
+    Field values are returned as native Python types, that is:
+
+    +-----------------------+----------------------------------+
+    | Field type            | Python type                      |
+    +=======================+==================================+
+    | Integer               | :class:`int`                     |
+    +-----------------------+----------------------------------+
+    | Floating point number | :class:`float`                   |
+    +-----------------------+----------------------------------+
+    | Enumeration           | :class:`str` (enumeration label) |
+    +-----------------------+----------------------------------+
+    | String                | :class:`str`                     |
+    +-----------------------+----------------------------------+
+    | Array                 | :class:`list` of native Python   |
+    |                       | objects                          |
+    +-----------------------+----------------------------------+
+    | Sequence              | :class:`list` of native Python   |
+    |                       | objects                          |
+    +-----------------------+----------------------------------+
+    | Structure             | :class:`dict` mapping field      |
+    |                       | names to native Python objects   |
+    +-----------------------+----------------------------------+
+
+    For example, printing the third element of a sequence named ``seq``
+    in a structure named ``my_struct`` of the ``event``'s field named
+    ``my_field`` is done this way:
+
+    .. code-block:: python
+
+       print(event['my_field']['my_struct']['seq'][2])
+    """
+
+    def __init__(self):
+        raise NotImplementedError("Event cannot be instantiated")
+
+    @property
+    def name(self):
+        """
+        Event name or ``None`` on error.
+        """
+
+        return nbt._bt_ctf_event_name(self._e)
+
+    @property
+    def cycles(self):
+        """
+        Event timestamp in cycles or -1 on error.
+        """
+
+        return nbt._bt_ctf_get_cycles(self._e)
+
+    @property
+    def timestamp(self):
+        """
+        Event timestamp (nanoseconds since Epoch).
+        """
+
+        ret, value = nbt._bt_ctf_get_timestamp(self._e)
+        if ret < 0:
+            raise RuntimeError("Failed to get event timestamp")
+        return value
+
+    @property
+    def datetime(self):
+        """
+        Event timestamp as a standard :class:`datetime.datetime`
+        object.
+
+        Note that the :class:`datetime.datetime` class' precision
+        is limited to microseconds, whereas :attr:`timestamp` provides
+        the event's timestamp with a nanosecond resolution.
+        """
+
+        return datetime.fromtimestamp(self.timestamp / 1E9)
+
+    def field_with_scope(self, field_name, scope):
+        """
+        Returns the value of a field named *field_name* within the
+        scope *scope*, or ``None`` if the field cannot be found.
+
+        *scope* must be one of :class:`babeltrace.common.CTFScope`
+        constants.
+        """
+
+        if scope not in _scopes:
+            raise ValueError("Invalid scope provided")
+
+        field = self._field_with_scope(field_name, scope)
+
+        if field is not None:
+            return field.value
+
+    def field_list_with_scope(self, scope):
+        """
+        Returns a list of field names in the scope *scope*.
+        """
+
+        if scope not in _scopes:
+            raise ValueError("Invalid scope provided")
+
+        field_names = []
+
+        for field in self._field_list_with_scope(scope):
+            field_names.append(field.name)
+
+        return field_names
+
+    @property
+    def handle(self):
+        """
+        :class:`TraceHandle` object containing this event, or ``None``
+        on error.
+        """
+
+        ret = nbt._bt_ctf_event_get_handle_id(self._e)
+
+        if ret < 0:
+            return None
+
+        th = TraceHandle.__new__(TraceHandle)
+        th._id = ret
+        th._trace_collection = self.get_trace_collection()
+
+        return th
+
+    @property
+    def trace_collection(self):
+        """
+        :class:`TraceCollection` object containing this event, or
+        ``None`` on error.
+        """
+
+        trace_collection = TraceCollection()
+        trace_collection._tc = nbt._bt_ctf_event_get_context(self._e)
+
+        if trace_collection._tc is not None:
+            return trace_collection
+
+    def __getitem__(self, field_name):
+        field = self._field(field_name)
+
+        if field is not None:
+            return field.value
+
+        raise KeyError(field_name)
+
+    def __iter__(self):
+        for key in self.keys():
+            yield key
+
+    def __len__(self):
+        count = 0
+
+        for scope in _scopes:
+            scope_ptr = nbt._bt_ctf_get_top_level_scope(self._e, scope)
+            ret = nbt._bt_python_field_listcaller(self._e, scope_ptr)
+
+            if isinstance(ret, list):
+                count += ret[1]
+
+        return count
+
+    def __contains__(self, field_name):
+        return self._field(field_name) is not None
+
+    def keys(self):
+        """
+        Returns the list of field names.
+
+        Note: field names are unique within the returned list, although
+        a field name could exist in multiple scopes. Use
+        :meth:`field_list_with_scope` to obtain the list of field names
+        of a given scope.
+        """
+
+        field_names = set()
+
+        for scope in _scopes:
+            for name in self.field_list_with_scope(scope):
+                field_names.add(name)
+
+        return list(field_names)
+
+    def get(self, field_name, default=None):
+        """
+        Returns the value of the field named *field_name*, or *default*
+        when not found.
+
+        See :class:`Event` note about how fields are retrieved by
+        name when multiple fields share the same name in different
+        scopes.
+        """
+
+        field = self._field(field_name)
+
+        if field is None:
+            return default
+
+        return field.value
+
+    def items(self):
+        """
+        Generates pairs of (field name, field value).
+
+        This method iterates :meth:`keys` to find field names, which
+        means some fields could be unavailable if other fields share
+        their names in scopes with higher priorities.
+        """
+
+        for field in self.keys():
+            yield (field, self[field])
+
+    def _field_with_scope(self, field_name, scope):
+        scope_ptr = nbt._bt_ctf_get_top_level_scope(self._e, scope)
+
+        if scope_ptr is None:
+            return None
+
+        definition_ptr = nbt._bt_ctf_get_field(self._e, scope_ptr, field_name)
+
+        if definition_ptr is None:
+            return None
+
+        field = _Definition(definition_ptr, scope)
+
+        return field
+
+    def _field(self, field_name):
+        field = None
+
+        for scope in _scopes:
+            field = self._field_with_scope(field_name, scope)
+
+            if field is not None:
+                break
+
+        return field
+
+    def _field_list_with_scope(self, scope):
+        fields = []
+        scope_ptr = nbt._bt_ctf_get_top_level_scope(self._e, scope)
+
+        # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
+        # provide the "count" return value
+        count = 0
+        list_ptr = None
+        ret = nbt._bt_python_field_listcaller(self._e, scope_ptr)
+
+        if isinstance(ret, list):
+            list_ptr, count = ret
+
+        for i in range(count):
+            definition_ptr = nbt._bt_python_field_one_from_list(list_ptr, i)
+
+            if definition_ptr is not None:
+                definition = _Definition(definition_ptr, scope)
+                fields.append(definition)
+
+        return fields
+
+
+class FieldError(Exception):
+    """
+    Field error, raised when the value of a field cannot be accessed.
+    """
+
+    def __init__(self, value):
+        self.value = value
+
+    def __str__(self):
+        return repr(self.value)
+
+
+class EventDeclaration:
+    """
+    An event declaration contains the properties of a class of events,
+    that is, the common properties and fields layout of all the actual
+    recorded events associated with this declaration.
+
+    This class is not meant to be instantiated by the user. It is
+    returned by :attr:`TraceHandle.events`.
+    """
+
+    MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
+
+    def __init__(self):
+        raise NotImplementedError("EventDeclaration cannot be instantiated")
+
+    @property
+    def name(self):
+        """
+        Event name, or ``None`` on error.
+        """
+
+        return nbt._bt_ctf_get_decl_event_name(self._ed)
+
+    @property
+    def id(self):
+        """
+        Event numeric ID, or -1 on error.
+        """
+
+        id = nbt._bt_ctf_get_decl_event_id(self._ed)
+
+        if id == self.MAX_UINT64:
+            id = -1
+
+        return id
+
+    @property
+    def fields(self):
+        """
+        Generates all the field declarations of this event, going
+        through each scope in the following order:
+
+        1. Event fields (:attr:`babeltrace.common.CTFScope.EVENT_FIELDS`)
+        2. Event context (:attr:`babeltrace.common.CTFScope.EVENT_CONTEXT`)
+        3. Stream event context (:attr:`babeltrace.common.CTFScope.STREAM_EVENT_CONTEXT`)
+        4. Event header (:attr:`babeltrace.common.CTFScope.STREAM_EVENT_HEADER`)
+        5. Packet context (:attr:`babeltrace.common.CTFScope.STREAM_PACKET_CONTEXT`)
+        6. Packet header (:attr:`babeltrace.common.CTFScope.TRACE_PACKET_HEADER`)
+
+        All the generated field declarations inherit
+        :class:`FieldDeclaration`, and are among:
+
+        * :class:`IntegerFieldDeclaration`
+        * :class:`FloatFieldDeclaration`
+        * :class:`EnumerationFieldDeclaration`
+        * :class:`StringFieldDeclaration`
+        * :class:`ArrayFieldDeclaration`
+        * :class:`SequenceFieldDeclaration`
+        * :class:`StructureFieldDeclaration`
+        * :class:`VariantFieldDeclaration`
+        """
+
+        for scope in _scopes:
+            for declaration in self.fields_scope(scope):
+                yield declaration
+
+    def fields_scope(self, scope):
+        """
+        Generates all the field declarations of the event's scope
+        *scope*.
+
+        *scope* must be one of :class:`babeltrace.common.CTFScope` constants.
+
+        All the generated field declarations inherit
+        :class:`FieldDeclaration`, and are among:
+
+        * :class:`IntegerFieldDeclaration`
+        * :class:`FloatFieldDeclaration`
+        * :class:`EnumerationFieldDeclaration`
+        * :class:`StringFieldDeclaration`
+        * :class:`ArrayFieldDeclaration`
+        * :class:`SequenceFieldDeclaration`
+        * :class:`StructureFieldDeclaration`
+        * :class:`VariantFieldDeclaration`
+        """
+        ret = nbt._by_python_field_decl_listcaller(self._ed, scope)
+
+        if not isinstance(ret, list):
+            return
+
+        list_ptr, count = ret
+
+        for i in range(count):
+            field_decl_ptr = nbt._bt_python_field_decl_one_from_list(list_ptr, i)
+
+            if field_decl_ptr is not None:
+                decl_ptr = nbt._bt_ctf_get_decl_from_field_decl(field_decl_ptr)
+                name = nbt._bt_ctf_get_decl_field_name(field_decl_ptr)
+                field_declaration = _create_field_declaration(decl_ptr, name,
+                                                              scope)
+                yield field_declaration
+
+
+class FieldDeclaration:
+    """
+    Base class for concrete field declarations.
+
+    This class is not meant to be instantiated by the user.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("FieldDeclaration cannot be instantiated")
+
+    def __repr__(self):
+        return "({0}) {1} {2}".format(common.CTFScope.scope_name(self.scope),
+                                      common.CTFTypeId.type_name(self.type),
+                                      self.name)
+
+    @property
+    def name(self):
+        """
+        Field name, or ``None`` on error.
+        """
+
+        return self._name
+
+    @property
+    def type(self):
+        """
+        Field type (one of :class:`babeltrace.common.CTFTypeId`
+        constants).
+        """
+
+        return nbt._bt_ctf_field_type(self._fd)
+
+    @property
+    def scope(self):
+        """
+        Field scope (one of:class:`babeltrace.common.CTFScope`
+        constants).
+        """
+
+        return self._s
+
+
+class IntegerFieldDeclaration(FieldDeclaration):
+    """
+    Integer field declaration.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
+
+    @property
+    def signedness(self):
+        """
+        0 if this integer is unsigned, 1 if signed, or -1 on error.
+        """
+
+        return nbt._bt_ctf_get_int_signedness(self._fd)
+
+    @property
+    def base(self):
+        """
+        Integer base (:class:`int`), or a negative value on error.
+        """
+
+        return nbt._bt_ctf_get_int_base(self._fd)
+
+    @property
+    def byte_order(self):
+        """
+        Integer byte order (one of
+        :class:`babeltrace.common.ByteOrder` constants).
+        """
+
+        ret = nbt._bt_ctf_get_int_byte_order(self._fd)
+
+        if ret == 1234:
+            return common.ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
+        elif ret == 4321:
+            return common.ByteOrder.BYTE_ORDER_BIG_ENDIAN
+        else:
+            return common.ByteOrder.BYTE_ORDER_UNKNOWN
+
+    @property
+    def size(self):
+        """
+        Integer size in bits, or a negative value on error.
+        """
+        return nbt._bt_ctf_get_int_len(self._fd)
+
+    @property
+    def length(self):
+        return self.size
+
+    @property
+    def encoding(self):
+        """
+        Integer encoding (one of
+        :class:`babeltrace.common.CTFStringEncoding` constants).
+        """
+
+        return nbt._bt_ctf_get_encoding(self._fd)
+
+
+class EnumerationFieldDeclaration(FieldDeclaration):
+    """
+    Enumeration field declaration.
+
+    .. note::
+
+       As of this version, this class is missing some properties.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
+
+
+class ArrayFieldDeclaration(FieldDeclaration):
+    """
+    Static array field declaration.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
+
+    @property
+    def length(self):
+        """
+        Fixed length of this static array (number of contained
+        elements), or a negative value on error.
+        """
+
+        return nbt._bt_ctf_get_array_len(self._fd)
+
+    @property
+    def element_declaration(self):
+        """
+        Field declaration of the underlying element.
+        """
+
+        field_decl_ptr = nbt._bt_python_get_array_element_declaration(self._fd)
+
+        return _create_field_declaration(field_decl_ptr, "", self.scope)
+
+
+class SequenceFieldDeclaration(FieldDeclaration):
+    """
+    Sequence (dynamic array) field declaration.
+
+    .. note::
+
+       As of this version, this class is missing some properties.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
+
+    @property
+    def element_declaration(self):
+        """
+        Field declaration of the underlying element.
+        """
+
+        field_decl_ptr = nbt._bt_python_get_sequence_element_declaration(self._fd)
+
+        return _create_field_declaration(field_decl_ptr, "", self.scope)
+
+
+class FloatFieldDeclaration(FieldDeclaration):
+    """
+    Floating point number field declaration.
+
+    .. note::
+
+       As of this version, this class is missing some properties.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
+
+
+class StructureFieldDeclaration(FieldDeclaration):
+    """
+    Structure (ordered map of field names to field declarations) field
+    declaration.
+
+    .. note::
+
+       As of this version, this class is missing some properties.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
+
+
+class StringFieldDeclaration(FieldDeclaration):
+    """
+    String (NULL-terminated array of bytes) field declaration.
+
+    .. note::
+
+       As of this version, this class is missing some properties.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
+
+
+class VariantFieldDeclaration(FieldDeclaration):
+    """
+    Variant (dynamic selection between different types) field declaration.
+
+    .. note::
+
+       As of this version, this class is missing some properties.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
+
+
+def field_error():
+    """
+    Return the last error code encountered while
+    accessing a field and reset the error flag.
+    Return 0 if no error, a negative value otherwise.
+    """
+
+    return nbt._bt_ctf_field_get_error()
+
+
+def _create_field_declaration(declaration_ptr, name, scope):
+    """
+    Private field declaration factory.
+    """
+
+    if declaration_ptr is None:
+        raise ValueError("declaration_ptr must be valid")
+    if scope not in _scopes:
+        raise ValueError("Invalid scope provided")
+
+    type = nbt._bt_ctf_field_type(declaration_ptr)
+    declaration = None
+
+    if type == common.CTFTypeId.INTEGER:
+        declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
+    elif type == common.CTFTypeId.ENUM:
+        declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
+    elif type == common.CTFTypeId.ARRAY:
+        declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
+    elif type == common.CTFTypeId.SEQUENCE:
+        declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
+    elif type == common.CTFTypeId.FLOAT:
+        declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
+    elif type == common.CTFTypeId.STRUCT:
+        declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
+    elif type == common.CTFTypeId.STRING:
+        declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
+    elif type == common.CTFTypeId.VARIANT:
+        declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
+    else:
+        return declaration
+
+    declaration._fd = declaration_ptr
+    declaration._s = scope
+    declaration._name = name
+
+    return declaration
+
+
+class _Definition:
+    def __init__(self, definition_ptr, scope):
+        self._d = definition_ptr
+        self._s = scope
+
+        if scope not in _scopes:
+            ValueError("Invalid scope provided")
+
+    @property
+    def name(self):
+        """Return the name of a field or None on error."""
+
+        return nbt._bt_ctf_field_name(self._d)
+
+    @property
+    def type(self):
+        """Return the type of a field or -1 if unknown."""
+
+        return nbt._bt_ctf_field_type(nbt._bt_ctf_get_decl_from_def(self._d))
+
+    @property
+    def declaration(self):
+        """Return the associated Definition object."""
+
+        return _create_field_declaration(
+            nbt._bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
+
+    def _get_enum_str(self):
+        """
+        Return the string matching the current enumeration.
+        Return None on error.
+        """
+
+        return nbt._bt_ctf_get_enum_str(self._d)
+
+    def _get_array_element_at(self, index):
+        """
+        Return the array's element at position index.
+        Return None on error
+        """
+
+        array_ptr = nbt._bt_python_get_array_from_def(self._d)
+
+        if array_ptr is None:
+            return None
+
+        definition_ptr = nbt._bt_array_index(array_ptr, index)
+
+        if definition_ptr is None:
+            return None
+
+        return _Definition(definition_ptr, self.scope)
+
+    def _get_sequence_len(self):
+        """
+        Return the len of a sequence or a negative
+        value on error.
+        """
+
+        seq = nbt._bt_python_get_sequence_from_def(self._d)
+
+        return nbt._bt_sequence_len(seq)
+
+    def _get_sequence_element_at(self, index):
+        """
+        Return the sequence's element at position index,
+        otherwise return None
+        """
+
+        seq = nbt._bt_python_get_sequence_from_def(self._d)
+
+        if seq is not None:
+            definition_ptr = nbt._bt_sequence_index(seq, index)
+
+            if definition_ptr is not None:
+                return _Definition(definition_ptr, self.scope)
+
+    def _get_uint64(self):
+        """
+        Return the value associated with the field.
+        If the field does not exist or is not of the type requested,
+        the value returned is undefined. To check if an error occured,
+        use the field_error() function after accessing a field.
+        """
+
+        return nbt._bt_ctf_get_uint64(self._d)
+
+    def _get_int64(self):
+        """
+        Return the value associated with the field.
+        If the field does not exist or is not of the type requested,
+        the value returned is undefined. To check if an error occured,
+        use the field_error() function after accessing a field.
+        """
+
+        return nbt._bt_ctf_get_int64(self._d)
+
+    def _get_char_array(self):
+        """
+        Return the value associated with the field.
+        If the field does not exist or is not of the type requested,
+        the value returned is undefined. To check if an error occurred,
+        use the field_error() function after accessing a field.
+        """
+
+        return nbt._bt_ctf_get_char_array(self._d)
+
+    def _get_str(self):
+        """
+        Return the value associated with the field.
+        If the field does not exist or is not of the type requested,
+        the value returned is undefined. To check if an error occurred,
+        use the field_error() function after accessing a field.
+        """
+
+        return nbt._bt_ctf_get_string(self._d)
+
+    def _get_float(self):
+        """
+        Return the value associated with the field.
+        If the field does not exist or is not of the type requested,
+        the value returned is undefined. To check if an error occurred,
+        use the field_error() function after accessing a field.
+        """
+
+        return nbt._bt_ctf_get_float(self._d)
+
+    def _get_variant(self):
+        """
+        Return the variant's selected field.
+        If the field does not exist or is not of the type requested,
+        the value returned is undefined. To check if an error occurred,
+        use the field_error() function after accessing a field.
+        """
+
+        return nbt._bt_ctf_get_variant(self._d)
+
+    def _get_struct_field_count(self):
+        """
+        Return the number of fields contained in the structure.
+        If the field does not exist or is not of the type requested,
+        the value returned is undefined.
+        """
+
+        return nbt._bt_ctf_get_struct_field_count(self._d)
+
+    def _get_struct_field_at(self, i):
+        """
+        Return the structure's field at position i.
+        If the field does not exist or is not of the type requested,
+        the value returned is undefined. To check if an error occurred,
+        use the field_error() function after accessing a field.
+        """
+
+        return nbt._bt_ctf_get_struct_field_index(self._d, i)
+
+    @property
+    def value(self):
+        """
+        Return the value associated with the field according to its type.
+        Return None on error.
+        """
+
+        id = self.type
+        value = None
+
+        if id == common.CTFTypeId.STRING:
+            value = self._get_str()
+        elif id == common.CTFTypeId.ARRAY:
+            element_decl = self.declaration.element_declaration
+
+            if ((element_decl.type == common.CTFTypeId.INTEGER
+                    and element_decl.length == 8)
+                    and (element_decl.encoding == common.CTFStringEncoding.ASCII or element_decl.encoding == common.CTFStringEncoding.UTF8)):
+                value = nbt._bt_python_get_array_string(self._d)
+            else:
+                value = []
+
+                for i in range(self.declaration.length):
+                    element = self._get_array_element_at(i)
+                    value.append(element.value)
+        elif id == common.CTFTypeId.INTEGER:
+            if self.declaration.signedness == 0:
+                value = self._get_uint64()
+            else:
+                value = self._get_int64()
+        elif id == common.CTFTypeId.ENUM:
+            value = self._get_enum_str()
+        elif id == common.CTFTypeId.SEQUENCE:
+            element_decl = self.declaration.element_declaration
+
+            if ((element_decl.type == common.CTFTypeId.INTEGER
+                    and element_decl.length == 8)
+                    and (element_decl.encoding == common.CTFStringEncoding.ASCII or element_decl.encoding == common.CTFStringEncoding.UTF8)):
+                value = nbt._bt_python_get_sequence_string(self._d)
+            else:
+                seq_len = self._get_sequence_len()
+                value = []
+
+                for i in range(seq_len):
+                    evDef = self._get_sequence_element_at(i)
+                    value.append(evDef.value)
+        elif id == common.CTFTypeId.FLOAT:
+            value = self._get_float()
+        elif id == common.CTFTypeId.VARIANT:
+            variant = _Definition.__new__(_Definition)
+            variant._d = self._get_variant()
+            value = variant.value
+        elif id == common.CTFTypeId.STRUCT:
+            value = {}
+
+            for i in range(self._get_struct_field_count()):
+                member = _Definition(self._get_struct_field_at(i), self.scope)
+                value[member.name] = member.value
+
+        if field_error():
+            raise FieldError(
+                "Error occurred while accessing field {} of type {}".format(
+                    self.name,
+                    common.CTFTypeId.type_name(id)))
+
+        return value
+
+    @property
+    def scope(self):
+        """Return the scope of a field or None on error."""
+
+        return self._s
diff --git a/bindings/python/babeltrace/writer.py b/bindings/python/babeltrace/writer.py
new file mode 100644 (file)
index 0000000..dc65b24
--- /dev/null
@@ -0,0 +1,2147 @@
+# writer.py
+#
+# Babeltrace writer interface Python module
+#
+# Copyright 2012-2015 EfficiOS Inc.
+#
+# Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+import babeltrace.nativebt as nbt
+import babeltrace.common as common
+from uuid import UUID
+
+
+# Used to compare to -1ULL in error checks
+_MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
+
+
+class EnumerationMapping:
+    """
+    Mapping from an enumeration label to a range of integers.
+    """
+
+    def __init__(self, name, start, end):
+        """
+        Creates an enumeration mapping, where label *name* is mapped to
+        the [*start*, *end*] range of integers (*end* is included).
+
+        Set *start* and *end* to the same value to create an enumeration
+        mapping to a single value.
+        """
+
+        self.name = name
+        self.start = start
+        self.end = end
+
+
+class Clock:
+    """
+    A CTF clock allows the description of the system's clock topology, as
+    well as the definition of each clock's parameters.
+
+    :class:`Clock` objects must be registered to a :class:`Writer`
+    object (see :meth:`Writer.add_clock`), as well as be registered to
+    a :class:`StreamClass` object (see :attr:`StreamClass.clock`).
+    """
+
+    def __init__(self, name):
+        """
+        Creates a default CTF clock named *name*.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        self._c = nbt._bt_ctf_clock_create(name)
+
+        if self._c is None:
+            raise ValueError("Invalid clock name.")
+
+    def __del__(self):
+        nbt._bt_ctf_clock_put(self._c)
+
+    @property
+    def name(self):
+        """
+        Clock name.
+
+        Set this attribute to change the clock's name.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        name = nbt._bt_ctf_clock_get_name(self._c)
+
+        if name is None:
+            raise ValueError("Invalid clock instance.")
+
+        return name
+
+    @property
+    def description(self):
+        """
+        Clock description (string).
+
+        Set this attribute to change the clock's description.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        return nbt._bt_ctf_clock_get_description(self._c)
+
+    @description.setter
+    def description(self, desc):
+        ret = nbt._bt_ctf_clock_set_description(self._c, str(desc))
+
+        if ret < 0:
+            raise ValueError("Invalid clock description.")
+
+    @property
+    def frequency(self):
+        """
+        Clock frequency in Hz (integer).
+
+        Set this attribute to change the clock's frequency.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        freq = nbt._bt_ctf_clock_get_frequency(self._c)
+
+        if freq == _MAX_UINT64:
+            raise ValueError("Invalid clock instance")
+
+        return freq
+
+    @frequency.setter
+    def frequency(self, freq):
+        ret = nbt._bt_ctf_clock_set_frequency(self._c, freq)
+
+        if ret < 0:
+            raise ValueError("Invalid frequency value.")
+
+    @property
+    def precision(self):
+        """
+        Clock precision in clock ticks (integer).
+
+        Set this attribute to change the clock's precision.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        precision = nbt._bt_ctf_clock_get_precision(self._c)
+
+        if precision == _MAX_UINT64:
+            raise ValueError("Invalid clock instance")
+
+        return precision
+
+    @precision.setter
+    def precision(self, precision):
+        ret = nbt._bt_ctf_clock_set_precision(self._c, precision)
+
+        if ret < 0:
+            raise ValueError("Invalid precision value.")
+
+    @property
+    def offset_seconds(self):
+        """
+        Clock offset in seconds since POSIX.1 Epoch (integer).
+
+        Set this attribute to change the clock's offset in seconds.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret, offset_s = nbt._bt_ctf_clock_get_offset_s(self._c)
+
+        if ret < 0:
+            raise ValueError("Invalid clock instance")
+
+        return offset_s
+
+    @offset_seconds.setter
+    def offset_seconds(self, offset_s):
+        ret = nbt._bt_ctf_clock_set_offset_s(self._c, offset_s)
+
+        if ret < 0:
+            raise ValueError("Invalid offset value.")
+
+    @property
+    def offset(self):
+        """
+        Clock offset in ticks since (POSIX.1 Epoch +
+        :attr:`offset_seconds`).
+
+        Set this attribute to change the clock's offset.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret, offset = nbt._bt_ctf_clock_get_offset(self._c)
+
+        if ret < 0:
+            raise ValueError("Invalid clock instance")
+
+        return offset
+
+    @offset.setter
+    def offset(self, offset):
+        ret = nbt._bt_ctf_clock_set_offset(self._c, offset)
+
+        if ret < 0:
+            raise ValueError("Invalid offset value.")
+
+    @property
+    def absolute(self):
+        """
+        ``True`` if this clock is absolute, i.e. if the clock is a
+        global reference across the other clocks of the trace.
+
+        Set this attribute to change the clock's absolute state
+        (boolean).
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        is_absolute = nbt._bt_ctf_clock_get_is_absolute(self._c)
+
+        if is_absolute == -1:
+            raise ValueError("Invalid clock instance")
+
+        return False if is_absolute == 0 else True
+
+    @absolute.setter
+    def absolute(self, is_absolute):
+        ret = nbt._bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
+
+        if ret < 0:
+            raise ValueError("Could not set the clock absolute attribute.")
+
+    @property
+    def uuid(self):
+        """
+        Clock UUID (an :class:`uuid.UUID` object).
+
+        Set this attribute to change the clock's UUID.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        uuid_list = []
+
+        for i in range(16):
+            ret, value = nbt._bt_python_ctf_clock_get_uuid_index(self._c, i)
+
+            if ret < 0:
+                raise ValueError("Invalid clock instance")
+
+            uuid_list.append(value)
+
+        return UUID(bytes=bytes(uuid_list))
+
+    @uuid.setter
+    def uuid(self, uuid):
+        uuid_bytes = uuid.bytes
+
+        if len(uuid_bytes) != 16:
+            raise ValueError("Invalid UUID provided. UUID length must be 16 bytes")
+
+        for i in range(len(uuid_bytes)):
+            ret = nbt._bt_python_ctf_clock_set_uuid_index(self._c, i,
+                                                          uuid_bytes[i])
+
+            if ret < 0:
+                raise ValueError("Invalid clock instance")
+
+    @property
+    def time(self):
+        """
+        Clock current time; nanoseconds (integer) since clock origin
+        (POSIX.1 Epoch + :attr:`offset_seconds` + :attr:`offset`).
+
+        Set this attribute to change the clock's current time.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret, time = nbt._bt_ctf_clock_get_time(self._c)
+
+        if ret < 0:
+            raise ValueError("Invalid clock instance")
+
+        return time
+
+    @time.setter
+    def time(self, time):
+        ret = nbt._bt_ctf_clock_set_time(self._c, time)
+
+        if ret < 0:
+            raise ValueError("Invalid time value.")
+
+
+class IntegerBase:
+    """
+    Display base of an integer.
+    """
+
+    #: Unknown
+    UNKNOWN = -1
+
+    #: Binary
+    BIN = 2
+
+    #: Octal
+    OCT = 8
+
+    #: Decimal
+    DEC = 10
+
+    #: Hexadecimal
+    HEX = 16
+
+    # keep this for backward compatibility
+    INTEGER_BASE_UNKNOWN = -1
+    INTEGER_BASE_BINARY = 2
+    INTEGER_BASE_OCTAL = 8
+    INTEGER_BASE_DECIMAL = 10
+    INTEGER_BASE_HEXADECIMAL = 16
+
+
+class FieldDeclaration:
+    """
+    Base class of all field declarations. This class is not meant to
+    be instantiated by the user; use one of the concrete field
+    declaration subclasses instead.
+    """
+
+    class IntegerBase(IntegerBase):
+        pass
+
+    def __init__(self):
+        if self._ft is None:
+            raise ValueError("FieldDeclaration creation failed.")
+
+    def __del__(self):
+        nbt._bt_ctf_field_type_put(self._ft)
+
+    @staticmethod
+    def _create_field_declaration_from_native_instance(
+            native_field_declaration):
+        type_dict = {
+            common.CTFTypeId.INTEGER: IntegerFieldDeclaration,
+            common.CTFTypeId.FLOAT: FloatFieldDeclaration,
+            common.CTFTypeId.ENUM: EnumerationFieldDeclaration,
+            common.CTFTypeId.STRING: StringFieldDeclaration,
+            common.CTFTypeId.STRUCT: StructureFieldDeclaration,
+            common.CTFTypeId.VARIANT: VariantFieldDeclaration,
+            common.CTFTypeId.ARRAY: ArrayFieldDeclaration,
+            common.CTFTypeId.SEQUENCE: SequenceFieldDeclaration
+        }
+
+        field_type_id = nbt._bt_ctf_field_type_get_type_id(native_field_declaration)
+
+        if field_type_id == common.CTFTypeId.UNKNOWN:
+            raise TypeError("Invalid field instance")
+
+        declaration = Field.__new__(Field)
+        declaration._ft = native_field_declaration
+        declaration.__class__ = type_dict[field_type_id]
+
+        return declaration
+
+    @property
+    def alignment(self):
+        """
+        Field alignment in bits (integer).
+
+        Set this attribute to change this field's alignment.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        return nbt._bt_ctf_field_type_get_alignment(self._ft)
+
+    @alignment.setter
+    def alignment(self, alignment):
+        ret = nbt._bt_ctf_field_type_set_alignment(self._ft, alignment)
+
+        if ret < 0:
+            raise ValueError("Invalid alignment value.")
+
+    @property
+    def byte_order(self):
+        """
+        Field byte order (one of :class:`babeltrace.common.ByteOrder`
+        constants).
+
+        Set this attribute to change this field's byte order.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        return nbt._bt_ctf_field_type_get_byte_order(self._ft)
+
+    @byte_order.setter
+    def byte_order(self, byte_order):
+        ret = nbt._bt_ctf_field_type_set_byte_order(self._ft, byte_order)
+
+        if ret < 0:
+            raise ValueError("Could not set byte order value.")
+
+
+class IntegerFieldDeclaration(FieldDeclaration):
+    """
+    Integer field declaration.
+    """
+
+    def __init__(self, size):
+        """
+        Creates an integer field declaration of size *size* bits.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        self._ft = nbt._bt_ctf_field_type_integer_create(size)
+        super().__init__()
+
+    @property
+    def size(self):
+        """
+        Integer size in bits (integer).
+
+        Set this attribute to change this integer's size.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_integer_get_size(self._ft)
+
+        if ret < 0:
+            raise ValueError("Could not get Integer size attribute.")
+        else:
+            return ret
+
+    @property
+    def signed(self):
+        """
+        ``True`` if this integer is signed.
+
+        Set this attribute to change this integer's signedness
+        (boolean).
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_integer_get_signed(self._ft)
+
+        if ret < 0:
+            raise ValueError("Could not get Integer signed attribute.")
+        elif ret > 0:
+            return True
+        else:
+            return False
+
+    @signed.setter
+    def signed(self, signed):
+        ret = nbt._bt_ctf_field_type_integer_set_signed(self._ft, signed)
+
+        if ret < 0:
+            raise ValueError("Could not set Integer signed attribute.")
+
+    @property
+    def base(self):
+        """
+        Integer display base (one of :class:`IntegerBase` constants).
+
+        Set this attribute to change this integer's display base.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        return nbt._bt_ctf_field_type_integer_get_base(self._ft)
+
+    @base.setter
+    def base(self, base):
+        ret = nbt._bt_ctf_field_type_integer_set_base(self._ft, base)
+
+        if ret < 0:
+            raise ValueError("Could not set Integer base.")
+
+    @property
+    def encoding(self):
+        """
+        Integer encoding (one of
+        :class:`babeltrace.common.CTFStringEncoding` constants).
+
+        Set this attribute to change this integer's encoding.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        return nbt._bt_ctf_field_type_integer_get_encoding(self._ft)
+
+    @encoding.setter
+    def encoding(self, encoding):
+        ret = nbt._bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
+
+        if ret < 0:
+            raise ValueError("Could not set Integer encoding.")
+
+
+class EnumerationFieldDeclaration(FieldDeclaration):
+    """
+    Enumeration field declaration. A CTF enumeration maps labels to
+    ranges of integers.
+    """
+
+    def __init__(self, integer_type):
+        """
+        Creates an enumeration field declaration, with *integer_type*
+        being the underlying :class:`IntegerFieldDeclaration` for storing
+        the integer.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        isinst = isinstance(integer_type, IntegerFieldDeclaration)
+
+        if integer_type is None or not isinst:
+            raise TypeError("Invalid integer container.")
+
+        self._ft = nbt._bt_ctf_field_type_enumeration_create(integer_type._ft)
+        super().__init__()
+
+    @property
+    def container(self):
+        """
+        Underlying container (:class:`IntegerFieldDeclaration`).
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_enumeration_get_container_type(self._ft)
+
+        if ret is None:
+            raise TypeError("Invalid enumeration declaration")
+
+        return FieldDeclaration._create_field_declaration_from_native_instance(ret)
+
+    def add_mapping(self, name, range_start, range_end):
+        """
+        Adds a mapping to the enumeration field declaration, from the
+        label named *name* to range [*range_start*, *range_end*], where
+        *range_start* and *range_end* are integers included in the
+        range.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        if range_start < 0 or range_end < 0:
+            ret = nbt._bt_ctf_field_type_enumeration_add_mapping(self._ft,
+                                                                 str(name),
+                                                                 range_start,
+                                                                 range_end)
+        else:
+            ret = nbt._bt_ctf_field_type_enumeration_add_mapping_unsigned(self._ft,
+                                                                          str(name),
+                                                                          range_start,
+                                                                          range_end)
+
+        if ret < 0:
+            raise ValueError("Could not add mapping to enumeration declaration.")
+
+    @property
+    def mappings(self):
+        """
+        Generates the mappings of this enumeration field declaration
+        (:class:`EnumerationMapping` objects).
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        signed = self.container.signed
+
+        count = nbt._bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
+
+        for i in range(count):
+            if signed:
+                ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping(self._ft, i)
+            else:
+                ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, i)
+
+            if len(ret) != 3:
+                msg = "Could not get Enumeration mapping at index {}".format(i)
+                raise TypeError(msg)
+
+            name, range_start, range_end = ret
+            yield EnumerationMapping(name, range_start, range_end)
+
+    def get_mapping_by_name(self, name):
+        """
+        Returns the :class:`EnumerationMapping` object for the label
+        named *name*.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        index = nbt._bt_ctf_field_type_enumeration_get_mapping_index_by_name(self._ft, name)
+
+        if index < 0:
+            return None
+
+        if self.container.signed:
+            ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
+        else:
+            ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
+
+        if len(ret) != 3:
+            msg = "Could not get Enumeration mapping at index {}".format(i)
+            raise TypeError(msg)
+
+        name, range_start, range_end = ret
+
+        return EnumerationMapping(name, range_start, range_end)
+
+    def get_mapping_by_value(self, value):
+        """
+        Returns the :class:`EnumerationMapping` object for the value
+        *value* (integer).
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        if value < 0:
+            index = nbt._bt_ctf_field_type_enumeration_get_mapping_index_by_value(self._ft, value)
+        else:
+            index = nbt._bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(self._ft, value)
+
+        if index < 0:
+            return None
+
+        if self.container.signed:
+            ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
+        else:
+            ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
+
+        if len(ret) != 3:
+            msg = "Could not get Enumeration mapping at index {}".format(i)
+            raise TypeError(msg)
+
+        name, range_start, range_end = ret
+
+        return EnumerationMapping(name, range_start, range_end)
+
+
+class FloatingPointFieldDeclaration(FieldDeclaration):
+    """
+    Floating point number field declaration.
+
+    A CTF floating point number is a made of three sections: the sign
+    bit, the exponent bits, and the mantissa bits. The most significant
+    bit of the resulting binary word is the sign bit, and is included
+    in the number of mantissa bits.
+
+    For example, the
+    `IEEE 754 <http://en.wikipedia.org/wiki/IEEE_floating_point>`_
+    single precision floating point number is represented on a 32-bit
+    word using an 8-bit exponent (``e``) and a 24-bit mantissa (``m``),
+    the latter count including the sign bit (``s``)::
+
+        s eeeeeeee mmmmmmmmmmmmmmmmmmmmmmm
+
+    The IEEE 754 double precision floating point number uses an
+    11-bit exponent and a 53-bit mantissa.
+    """
+
+    #: IEEE 754 single precision floating point number exponent size
+    FLT_EXP_DIG = 8
+
+    #: IEEE 754 double precision floating point number exponent size
+    DBL_EXP_DIG = 11
+
+    #: IEEE 754 single precision floating point number mantissa size
+    FLT_MANT_DIG = 24
+
+    #: IEEE 754 double precision floating point number mantissa size
+    DBL_MANT_DIG = 53
+
+    def __init__(self):
+        """
+        Creates a floating point number field declaration.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        self._ft = nbt._bt_ctf_field_type_floating_point_create()
+        super().__init__()
+
+    @property
+    def exponent_digits(self):
+        """
+        Floating point number exponent section size in bits (integer).
+
+        Set this attribute to change the floating point number's
+        exponent section's size. You may use :attr:`FLT_EXP_DIG` or
+        :attr:`DBL_EXP_DIG` for IEEE 754 floating point numbers.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_floating_point_get_exponent_digits(self._ft)
+
+        if ret < 0:
+            raise TypeError(
+                "Could not get Floating point exponent digit count")
+
+        return ret
+
+    @exponent_digits.setter
+    def exponent_digits(self, exponent_digits):
+        ret = nbt._bt_ctf_field_type_floating_point_set_exponent_digits(self._ft,
+                                                                        exponent_digits)
+
+        if ret < 0:
+            raise ValueError("Could not set exponent digit count.")
+
+    @property
+    def mantissa_digits(self):
+        """
+        Floating point number mantissa section size in bits (integer).
+
+        Set this attribute to change the floating point number's
+        mantissa section's size. You may use :attr:`FLT_MANT_DIG` or
+        :attr:`DBL_MANT_DIG` for IEEE 754 floating point numbers.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_floating_point_get_mantissa_digits(self._ft)
+
+        if ret < 0:
+            raise TypeError("Could not get Floating point mantissa digit count")
+
+        return ret
+
+    @mantissa_digits.setter
+    def mantissa_digits(self, mantissa_digits):
+        ret = nbt._bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft,
+                                                                        mantissa_digits)
+
+        if ret < 0:
+            raise ValueError("Could not set mantissa digit count.")
+
+
+class FloatFieldDeclaration(FloatingPointFieldDeclaration):
+    pass
+
+
+class StructureFieldDeclaration(FieldDeclaration):
+    """
+    Structure field declaration, i.e. an ordered mapping from field
+    names to field declarations.
+    """
+
+    def __init__(self):
+        """
+        Creates an empty structure field declaration.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        self._ft = nbt._bt_ctf_field_type_structure_create()
+        super().__init__()
+
+    def add_field(self, field_type, field_name):
+        """
+        Appends one :class:`FieldDeclaration` *field_type* named
+        *field_name* to the structure's ordered map.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_structure_add_field(self._ft,
+                                                         field_type._ft,
+                                                         str(field_name))
+
+        if ret < 0:
+            raise ValueError("Could not add field to structure.")
+
+    @property
+    def fields(self):
+        """
+        Generates the (field name, :class:`FieldDeclaration`) pairs
+        of this structure.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        count = nbt._bt_ctf_field_type_structure_get_field_count(self._ft)
+
+        if count < 0:
+            raise TypeError("Could not get Structure field count")
+
+        for i in range(count):
+            field_name = nbt._bt_python_ctf_field_type_structure_get_field_name(self._ft, i)
+
+            if field_name is None:
+                msg = "Could not get Structure field name at index {}".format(i)
+                raise TypeError(msg)
+
+            field_type_native = nbt._bt_python_ctf_field_type_structure_get_field_type(self._ft, i)
+
+            if field_type_native is None:
+                msg = "Could not get Structure field type at index {}".format(i)
+                raise TypeError(msg)
+
+            field_type = FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
+            yield (field_name, field_type)
+
+    def get_field_by_name(self, name):
+        """
+        Returns the :class:`FieldDeclaration` mapped to the field name
+        *name* in this structure.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        field_type_native = nbt._bt_ctf_field_type_structure_get_field_type_by_name(self._ft, name)
+
+        if field_type_native is None:
+            msg = "Could not find Structure field with name {}".format(name)
+            raise TypeError(msg)
+
+        return FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
+
+
+class VariantFieldDeclaration(FieldDeclaration):
+    """
+    Variant field declaration.
+
+    A CTF variant is a dynamic selection between different fields.
+    The value of a *tag* (a CTF enumeration) determines what is the
+    current selected field. All the possible fields must be added to
+    its field declaration before using an actual variant field.
+    """
+
+    def __init__(self, enum_tag, tag_name):
+        """
+        Creates an empty variant field declaration with tag field
+        declaration *enum_tag* (instance of
+        :class:`EnumerationFieldDeclaration`) named *tag_name*
+        (string).
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        isinst = isinstance(enum_tag, EnumerationFieldDeclaration)
+        if enum_tag is None or not isinst:
+            raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
+
+        self._ft = nbt._bt_ctf_field_type_variant_create(enum_tag._ft,
+                                                         str(tag_name))
+        super().__init__()
+
+    @property
+    def tag_name(self):
+        """
+        Variant field declaration tag name.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_variant_get_tag_name(self._ft)
+
+        if ret is None:
+            raise TypeError("Could not get Variant tag name")
+
+        return ret
+
+    @property
+    def tag_type(self):
+        """
+        Variant field declaration tag field declaration
+        (:class:`EnumerationFieldDeclaration` object).
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_variant_get_tag_type(self._ft)
+
+        if ret is None:
+            raise TypeError("Could not get Variant tag type")
+
+        return FieldDeclaration._create_field_declaration_from_native_instance(ret)
+
+    def add_field(self, field_type, field_name):
+        """
+        Registers the :class:`FieldDeclaration` object *field_type*
+        as the variant's selected type when the variant's tag's current
+        label is *field_name*.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_variant_add_field(self._ft,
+                                                       field_type._ft,
+                                                       str(field_name))
+
+        if ret < 0:
+            raise ValueError("Could not add field to variant.")
+
+    @property
+    def fields(self):
+        """
+        Generates the (field name, :class:`FieldDeclaration`) pairs
+        of this variant field declaration.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        count = nbt._bt_ctf_field_type_variant_get_field_count(self._ft)
+
+        if count < 0:
+            raise TypeError("Could not get Variant field count")
+
+        for i in range(count):
+            field_name = nbt._bt_python_ctf_field_type_variant_get_field_name(self._ft, i)
+
+            if field_name is None:
+                msg = "Could not get Variant field name at index {}".format(i)
+                raise TypeError(msg)
+
+            field_type_native = nbt._bt_python_ctf_field_type_variant_get_field_type(self._ft, i)
+
+            if field_type_native is None:
+                msg = "Could not get Variant field type at index {}".format(i)
+                raise TypeError(msg)
+
+            field_type = FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
+            yield (field_name, field_type)
+
+    def get_field_by_name(self, name):
+        """
+        Returns the :class:`FieldDeclaration` selected when the
+        variant's tag's current label is *name*.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        field_type_native = nbt._bt_ctf_field_type_variant_get_field_type_by_name(self._ft,
+                                                                                  name)
+
+        if field_type_native is None:
+            msg = "Could not find Variant field with name {}".format(name)
+            raise TypeError(msg)
+
+        return FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
+
+    def get_field_from_tag(self, tag):
+        """
+        Returns the :class:`FieldDeclaration` selected by the current
+        label of the :class:`EnumerationField` *tag*.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        field_type_native = nbt._bt_ctf_field_type_variant_get_field_type_from_tag(self._ft, tag._f)
+
+        if field_type_native is None:
+            msg = "Could not find Variant field with tag value {}".format(tag.value)
+            raise TypeError(msg)
+
+        return FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
+
+
+class ArrayFieldDeclaration(FieldDeclaration):
+    """
+    Static array field declaration.
+    """
+
+    def __init__(self, element_type, length):
+        """
+        Creates a static array field declaration of *length*
+        elements of type *element_type* (:class:`FieldDeclaration`).
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        self._ft = nbt._bt_ctf_field_type_array_create(element_type._ft,
+                                                       length)
+        super().__init__()
+
+    @property
+    def element_type(self):
+        """
+        Type of the elements of this this static array (subclass of
+        :class:`FieldDeclaration`).
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_array_get_element_type(self._ft)
+
+        if ret is None:
+            raise TypeError("Could not get Array element type")
+
+        return FieldDeclaration._create_field_declaration_from_native_instance(ret)
+
+    @property
+    def length(self):
+        """
+        Length of this static array (integer).
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_array_get_length(self._ft)
+
+        if ret < 0:
+            raise TypeError("Could not get Array length")
+
+        return ret
+
+
+class SequenceFieldDeclaration(FieldDeclaration):
+    """
+    Sequence (dynamic array) field declaration.
+    """
+
+    def __init__(self, element_type, length_field_name):
+        """
+        Creates a sequence field declaration of
+        elements of type *element_type* (:class:`FieldDeclaration`).
+        The length of a sequence field based on this sequence field
+        declaration is obtained by retrieving the dynamic integer
+        value of the field named *length_field_name*.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        self._ft = nbt._bt_ctf_field_type_sequence_create(element_type._ft,
+                                                          str(length_field_name))
+        super().__init__()
+
+    @property
+    def element_type(self):
+        """
+        Type of the elements of this sequence (subclass of
+        :class:`FieldDeclaration`).
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_sequence_get_element_type(self._ft)
+
+        if ret is None:
+            raise TypeError("Could not get Sequence element type")
+
+        return FieldDeclaration._create_field_declaration_from_native_instance(ret)
+
+    @property
+    def length_field_name(self):
+        """
+        Name of the integer field defining the dynamic length of
+        sequence fields based on this sequence field declaration.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_field_type_sequence_get_length_field_name(self._ft)
+
+        if ret is None:
+            raise TypeError("Could not get Sequence length field name")
+
+        return ret
+
+
+class StringFieldDeclaration(FieldDeclaration):
+    """
+    String (NULL-terminated array of bytes) field declaration.
+    """
+
+    def __init__(self):
+        """
+        Creates a string field declaration.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        self._ft = nbt._bt_ctf_field_type_string_create()
+        super().__init__()
+
+    @property
+    def encoding(self):
+        """
+        String encoding (one of
+        :class:`babeltrace.common.CTFStringEncoding` constants).
+
+        Set this attribute to change this string's encoding.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        return nbt._bt_ctf_field_type_string_get_encoding(self._ft)
+
+    @encoding.setter
+    def encoding(self, encoding):
+        ret = nbt._bt_ctf_field_type_string_set_encoding(self._ft, encoding)
+        if ret < 0:
+            raise ValueError("Could not set string encoding.")
+
+
+@staticmethod
+def create_field(field_type):
+    """
+    Create an instance of a field.
+    """
+    isinst = isinstance(field_type, FieldDeclaration)
+
+    if field_type is None or not isinst:
+        raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
+
+    if isinstance(field_type, IntegerFieldDeclaration):
+        return IntegerField(field_type)
+    elif isinstance(field_type, EnumerationFieldDeclaration):
+        return EnumerationField(field_type)
+    elif isinstance(field_type, FloatFieldDeclaration):
+        return FloatingPointField(field_type)
+    elif isinstance(field_type, StructureFieldDeclaration):
+        return StructureField(field_type)
+    elif isinstance(field_type, VariantFieldDeclaration):
+        return VariantField(field_type)
+    elif isinstance(field_type, ArrayFieldDeclaration):
+        return ArrayField(field_type)
+    elif isinstance(field_type, SequenceFieldDeclaration):
+        return SequenceField(field_type)
+    elif isinstance(field_type, StringFieldDeclaration):
+        return StringField(field_type)
+
+
+class Field:
+    """
+    Base class of all fields. This class is not meant to be
+    instantiated by the user, and neither are its subclasses. Use
+    :meth:`Event.payload` to access specific, concrete fields of
+    an event.
+    """
+
+    def __init__(self, field_type):
+        if not isinstance(field_type, FieldDeclaration):
+            raise TypeError("Invalid field_type argument.")
+
+        self._f = nbt._bt_ctf_field_create(field_type._ft)
+
+        if self._f is None:
+            raise ValueError("Field creation failed.")
+
+    def __del__(self):
+        nbt._bt_ctf_field_put(self._f)
+
+    @staticmethod
+    def _create_field_from_native_instance(native_field_instance):
+        type_dict = {
+            common.CTFTypeId.INTEGER: IntegerField,
+            common.CTFTypeId.FLOAT: FloatingPointField,
+            common.CTFTypeId.ENUM: EnumerationField,
+            common.CTFTypeId.STRING: StringField,
+            common.CTFTypeId.STRUCT: StructureField,
+            common.CTFTypeId.VARIANT: VariantField,
+            common.CTFTypeId.ARRAY: ArrayField,
+            common.CTFTypeId.SEQUENCE: SequenceField
+        }
+
+        field_type = nbt._bt_python_get_field_type(native_field_instance)
+
+        if field_type == common.CTFTypeId.UNKNOWN:
+            raise TypeError("Invalid field instance")
+
+        field = Field.__new__(Field)
+        field._f = native_field_instance
+        field.__class__ = type_dict[field_type]
+
+        return field
+
+    @property
+    def declaration(self):
+        """
+        Field declaration (subclass of :class:`FieldDeclaration`).
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        native_field_type = nbt._bt_ctf_field_get_type(self._f)
+
+        if native_field_type is None:
+            raise TypeError("Invalid field instance")
+        return FieldDeclaration._create_field_declaration_from_native_instance(
+            native_field_type)
+
+
+class IntegerField(Field):
+    """
+    Integer field, based on an :class:`IntegerFieldDeclaration` object.
+    """
+
+    @property
+    def value(self):
+        """
+        Integer value (:class:`int`).
+
+        Set this attribute to change the integer field's value.
+
+        :exc:`ValueError` or :exc:`TypeError` are raised on error.
+        """
+
+        signedness = nbt._bt_python_field_integer_get_signedness(self._f)
+
+        if signedness < 0:
+            raise TypeError("Invalid integer instance.")
+
+        if signedness == 0:
+            ret, value = nbt._bt_ctf_field_unsigned_integer_get_value(self._f)
+        else:
+            ret, value = nbt._bt_ctf_field_signed_integer_get_value(self._f)
+
+        if ret < 0:
+            raise ValueError("Could not get integer field value.")
+
+        return value
+
+    @value.setter
+    def value(self, value):
+        if not isinstance(value, int):
+            raise TypeError("IntegerField's value must be an int")
+
+        signedness = nbt._bt_python_field_integer_get_signedness(self._f)
+        if signedness < 0:
+            raise TypeError("Invalid integer instance.")
+
+        if signedness == 0:
+            ret = nbt._bt_ctf_field_unsigned_integer_set_value(self._f, value)
+        else:
+            ret = nbt._bt_ctf_field_signed_integer_set_value(self._f, value)
+
+        if ret < 0:
+            raise ValueError("Could not set integer field value.")
+
+
+class EnumerationField(Field):
+    """
+    Enumeration field, based on an
+    :class:`EnumerationFieldDeclaration` object.
+    """
+
+    @property
+    def container(self):
+        """
+        Underlying container (:class:`IntegerField`).
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        container = IntegerField.__new__(IntegerField)
+        container._f = nbt._bt_ctf_field_enumeration_get_container(self._f)
+
+        if container._f is None:
+            raise TypeError("Invalid enumeration field type.")
+
+        return container
+
+    @property
+    def value(self):
+        """
+        Current label of this enumeration field (:class:`str`).
+
+        Set this attribute to an integer (:class:`int`) to change the
+        enumeration field's value.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        value = nbt._bt_ctf_field_enumeration_get_mapping_name(self._f)
+
+        if value is None:
+            raise ValueError("Could not get enumeration mapping name.")
+
+        return value
+
+    @value.setter
+    def value(self, value):
+        if not isinstance(value, int):
+            raise TypeError("EnumerationField value must be an int")
+
+        self.container.value = value
+
+
+class FloatingPointField(Field):
+    """
+    Floating point number field, based on a
+    :class:`FloatingPointFieldDeclaration` object.
+    """
+
+    @property
+    def value(self):
+        """
+        Floating point number value (:class:`float`).
+
+        Set this attribute to change the floating point number field's
+        value.
+
+        :exc:`ValueError` or :exc:`TypeError` are raised on error.
+        """
+
+        ret, value = nbt._bt_ctf_field_floating_point_get_value(self._f)
+
+        if ret < 0:
+            raise ValueError("Could not get floating point field value.")
+
+        return value
+
+    @value.setter
+    def value(self, value):
+        if not isinstance(value, int) and not isinstance(value, float):
+            raise TypeError("Value must be either a float or an int")
+
+        ret = nbt._bt_ctf_field_floating_point_set_value(self._f, float(value))
+
+        if ret < 0:
+            raise ValueError("Could not set floating point field value.")
+
+
+# oops!! This class is provided to ensure backward-compatibility since
+# a stable release publicly exposed this abomination.
+class FloatFieldingPoint(FloatingPointField):
+    pass
+
+
+class StructureField(Field):
+    """
+    Structure field, based on a
+    :class:`StructureFieldDeclaration` object.
+    """
+
+    def field(self, field_name):
+        """
+        Returns the structure :class:`Field` named *field_name*.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        native_instance = nbt._bt_ctf_field_structure_get_field(self._f,
+                                                                str(field_name))
+
+        if native_instance is None:
+            raise ValueError("Invalid field_name provided.")
+
+        return Field._create_field_from_native_instance(native_instance)
+
+
+class VariantField(Field):
+    """
+    Variant field, based on a
+    :class:`VariantFieldDeclaration` object.
+    """
+
+    def field(self, tag):
+        """
+        Returns the :class:`Field` selected by the current label of
+        *tag* (:class:`EnumerationField`).
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        native_instance = nbt._bt_ctf_field_variant_get_field(self._f, tag._f)
+
+        if native_instance is None:
+            raise ValueError("Invalid tag provided.")
+
+        return Field._create_field_from_native_instance(native_instance)
+
+
+class ArrayField(Field):
+    """
+    Static array field, based on an
+    :class:`ArrayFieldDeclaration` object.
+    """
+
+    def field(self, index):
+        """
+        Returns the :class:`Field` at index *index* in this static
+        array.
+
+        :exc:`IndexError` is raised on error.
+        """
+
+        native_instance = nbt._bt_ctf_field_array_get_field(self._f, index)
+
+        if native_instance is None:
+            raise IndexError("Invalid index provided.")
+
+        return Field._create_field_from_native_instance(native_instance)
+
+
+class SequenceField(Field):
+    """
+    Sequence (dynamic array) field, based on a
+    :class:`SequenceFieldDeclaration` object.
+    """
+
+    @property
+    def length(self):
+        """
+        Sequence length (:class:`IntegerField`).
+
+        Set this attribute to change the sequence length's integer
+        field (integer must be unsigned).
+
+        :exc:`ValueError` or :exc:`TypeError` are raised on error.
+        """
+
+        native_instance = nbt._bt_ctf_field_sequence_get_length(self._f)
+
+        if native_instance is None:
+            length = -1
+
+        return Field._create_field_from_native_instance(native_instance)
+
+    @length.setter
+    def length(self, length_field):
+        if not isinstance(length_field, IntegerField):
+            raise TypeError("Invalid length field.")
+
+        if length_field.declaration.signed:
+            raise TypeError("Sequence field length must be unsigned")
+
+        ret = nbt._bt_ctf_field_sequence_set_length(self._f, length_field._f)
+
+        if ret < 0:
+            raise ValueError("Could not set sequence length.")
+
+    def field(self, index):
+        """
+        Returns the :class:`Field` at index *index* in this sequence.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        native_instance = nbt._bt_ctf_field_sequence_get_field(self._f, index)
+
+        if native_instance is None:
+            raise ValueError("Could not get sequence element at index.")
+
+        return Field._create_field_from_native_instance(native_instance)
+
+
+class StringField(Field):
+    """
+    String (NULL-terminated array of bytes) field.
+    """
+
+    @property
+    def value(self):
+        """
+        String value (:class:`str`).
+
+        Set this attribute to change the string's value.
+
+        :exc:`ValueError` or :exc:`TypeError` are raised on error.
+        """
+
+        return nbt._bt_ctf_field_string_get_value(self._f)
+
+    @value.setter
+    def value(self, value):
+        ret = nbt._bt_ctf_field_string_set_value(self._f, str(value))
+
+        if ret < 0:
+            raise ValueError("Could not set string field value.")
+
+
+class EventClass:
+    """
+    An event class contains the properties of specific
+    events (:class:`Event`). Any concrete event must be linked with an
+    :class:`EventClass`.
+
+    Some attributes are automatically set when creating an event class.
+    For example, if no numeric ID is explicitly set using the
+    :attr:`id` attribute, a default, unique ID within the stream class
+    containing this event class will be created when needed.
+    """
+
+    def __init__(self, name):
+        """
+        Creates an event class named *name*.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        self._ec = nbt._bt_ctf_event_class_create(name)
+
+        if self._ec is None:
+            raise ValueError("Event class creation failed.")
+
+    def __del__(self):
+        nbt._bt_ctf_event_class_put(self._ec)
+
+    def add_field(self, field_type, field_name):
+        """
+        Adds a field declaration *field_type* named *field_name* to
+        this event class.
+
+        *field_type* must be one of:
+
+        * :class:`IntegerFieldDeclaration`
+        * :class:`FloatingPointFieldDeclaration`
+        * :class:`EnumerationFieldDeclaration`
+        * :class:`StringFieldDeclaration`
+        * :class:`ArrayFieldDeclaration`
+        * :class:`SequenceFieldDeclaration`
+        * :class:`StructureFieldDeclaration`
+        * :class:`VariantFieldDeclaration`
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_event_class_add_field(self._ec, field_type._ft,
+                                                str(field_name))
+
+        if ret < 0:
+            raise ValueError("Could not add field to event class.")
+
+    @property
+    def name(self):
+        """
+        Event class' name.
+        """
+
+        name = nbt._bt_ctf_event_class_get_name(self._ec)
+
+        if name is None:
+            raise TypeError("Could not get EventClass name")
+
+        return name
+
+    @property
+    def id(self):
+        """
+        Event class' numeric ID.
+
+        Set this attribute to assign a numeric ID to this event class.
+        This ID must be unique amongst all the event class IDs of a
+        given stream class.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        id = nbt._bt_ctf_event_class_get_id(self._ec)
+
+        if id < 0:
+            raise TypeError("Could not get EventClass id")
+
+        return id
+
+    @id.setter
+    def id(self, id):
+        ret = nbt._bt_ctf_event_class_set_id(self._ec, id)
+
+        if ret < 0:
+            raise TypeError("Can't change an Event Class id after it has been assigned to a stream class")
+
+    @property
+    def stream_class(self):
+        """
+        :class:`StreamClass` object containing this event class,
+        or ``None`` if not set.
+        """
+
+        stream_class_native = nbt._bt_ctf_event_class_get_stream_class(self._ec)
+
+        if stream_class_native is None:
+            return None
+
+        stream_class = StreamClass.__new__(StreamClass)
+        stream_class._sc = stream_class_native
+
+        return stream_class
+
+    @property
+    def fields(self):
+        """
+        Generates the (field name, :class:`FieldDeclaration`) pairs of
+        this event class.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        count = nbt._bt_ctf_event_class_get_field_count(self._ec)
+
+        if count < 0:
+            raise TypeError("Could not get EventClass' field count")
+
+        for i in range(count):
+            field_name = nbt._bt_python_ctf_event_class_get_field_name(self._ec, i)
+
+            if field_name is None:
+                msg = "Could not get EventClass' field name at index {}".format(i)
+                raise TypeError(msg)
+
+            field_type_native = nbt._bt_python_ctf_event_class_get_field_type(self._ec, i)
+
+            if field_type_native is None:
+                msg = "Could not get EventClass' field type at index {}".format(i)
+                raise TypeError(msg)
+
+            field_type = FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
+            yield (field_name, field_type)
+
+    def get_field_by_name(self, name):
+        """
+        Returns the :class:`FieldDeclaration` object named *name* in
+        this event class.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        field_type_native = nbt._bt_ctf_event_class_get_field_by_name(self._ec, name)
+
+        if field_type_native is None:
+            msg = "Could not find EventClass field with name {}".format(name)
+            raise TypeError(msg)
+
+        return FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
+
+
+class Event:
+    """
+    Events are specific instances of event classes
+    (:class:`EventClass`), which means they may contain actual,
+    concrete field values.
+    """
+
+    def __init__(self, event_class):
+        """
+        Creates an event linked with the :class:`EventClass`
+        *event_class*.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        if not isinstance(event_class, EventClass):
+            raise TypeError("Invalid event_class argument.")
+
+        self._e = nbt._bt_ctf_event_create(event_class._ec)
+
+        if self._e is None:
+            raise ValueError("Event creation failed.")
+
+    def __del__(self):
+        nbt._bt_ctf_event_put(self._e)
+
+    @property
+    def event_class(self):
+        """
+        :class:`EventClass` object to which this event is linked.
+        """
+
+        event_class_native = nbt._bt_ctf_event_get_class(self._e)
+
+        if event_class_native is None:
+            return None
+
+        event_class = EventClass.__new__(EventClass)
+        event_class._ec = event_class_native
+
+        return event_class
+
+    def clock(self):
+        """
+        :class:`Clock` object used by this object, or ``None`` if
+        the event class is not registered to a stream class.
+        """
+
+        clock_instance = nbt._bt_ctf_event_get_clock(self._e)
+
+        if clock_instance is None:
+            return None
+
+        clock = Clock.__new__(Clock)
+        clock._c = clock_instance
+
+        return clock
+
+    def payload(self, field_name):
+        """
+        Returns the :class:`Field` object named *field_name* in this
+        event.
+
+        The returned field object is created using the event class'
+        field declaration named *field_name*.
+
+        The return type is one of:
+
+        * :class:`IntegerField`
+        * :class:`FloatingPointField`
+        * :class:`EnumerationField`
+        * :class:`StringField`
+        * :class:`ArrayField`
+        * :class:`SequenceField`
+        * :class:`StructureField`
+        * :class:`VariantField`
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        native_instance = nbt._bt_ctf_event_get_payload(self._e,
+                                                        str(field_name))
+
+        if native_instance is None:
+            raise ValueError("Could not get event payload.")
+
+        return Field._create_field_from_native_instance(native_instance)
+
+    def set_payload(self, field_name, value_field):
+        """
+        Set the event's field named *field_name* to the manually
+        created :class:`Field` object *value_field*.
+
+        *value_field*'s type must be one of:
+
+        * :class:`IntegerField`
+        * :class:`FloatingPointField`
+        * :class:`EnumerationField`
+        * :class:`StringField`
+        * :class:`ArrayField`
+        * :class:`SequenceField`
+        * :class:`StructureField`
+        * :class:`VariantField`
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        if not isinstance(value, Field):
+            raise TypeError("Invalid value type.")
+
+        ret = nbt._bt_ctf_event_set_payload(self._e, str(field_name),
+                                            value_field._f)
+
+        if ret < 0:
+            raise ValueError("Could not set event field payload.")
+
+
+class StreamClass:
+    """
+    A stream class contains the properties of specific
+    streams (:class:`Stream`). Any concrete stream must be linked with
+    a :class:`StreamClass`, usually by calling
+    :meth:`Writer.create_stream`.
+
+    Some attributes are automatically set when creating a stream class.
+    For example, if no clock is explicitly set using the
+    :attr:`clock` attribute, a default clock will be created
+    when needed.
+    """
+
+    def __init__(self, name):
+        """
+        Creates a stream class named *name*.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        self._sc = nbt._bt_ctf_stream_class_create(name)
+
+        if self._sc is None:
+            raise ValueError("Stream class creation failed.")
+
+    def __del__(self):
+        nbt._bt_ctf_stream_class_put(self._sc)
+
+    @property
+    def name(self):
+        """
+        Stream class' name.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        name = nbt._bt_ctf_stream_class_get_name(self._sc)
+
+        if name is None:
+            raise TypeError("Could not get StreamClass name")
+
+        return name
+
+    @property
+    def clock(self):
+        """
+        Stream class' clock (:class:`Clock` object).
+
+        Set this attribute to change the clock of this stream class.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        clock_instance = nbt._bt_ctf_stream_class_get_clock(self._sc)
+
+        if clock_instance is None:
+            return None
+
+        clock = Clock.__new__(Clock)
+        clock._c = clock_instance
+
+        return clock
+
+    @clock.setter
+    def clock(self, clock):
+        if not isinstance(clock, Clock):
+            raise TypeError("Invalid clock type.")
+
+        ret = nbt._bt_ctf_stream_class_set_clock(self._sc, clock._c)
+
+        if ret < 0:
+            raise ValueError("Could not set stream class clock.")
+
+    @property
+    def id(self):
+        """
+        Stream class' numeric ID.
+
+        Set this attribute to change the ID of this stream class.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_stream_class_get_id(self._sc)
+
+        if ret < 0:
+            raise TypeError("Could not get StreamClass id")
+
+        return ret
+
+    @id.setter
+    def id(self, id):
+        ret = nbt._bt_ctf_stream_class_set_id(self._sc, id)
+
+        if ret < 0:
+            raise TypeError("Could not set stream class id.")
+
+    @property
+    def event_classes(self):
+        """
+        Generates the event classes (:class:`EventClass` objects) of
+        this stream class.
+
+        :exc:`TypeError` is raised on error.
+        """
+
+        count = nbt._bt_ctf_stream_class_get_event_class_count(self._sc)
+
+        if count < 0:
+            raise TypeError("Could not get StreamClass' event class count")
+
+        for i in range(count):
+            event_class_native = nbt._bt_ctf_stream_class_get_event_class(self._sc, i)
+
+            if event_class_native is None:
+                msg = "Could not get StreamClass' event class at index {}".format(i)
+                raise TypeError(msg)
+
+            event_class = EventClass.__new__(EventClass)
+            event_class._ec = event_class_native
+            yield event_class
+
+    def add_event_class(self, event_class):
+        """
+        Registers the :class:`EventClass` *event_class* to this stream
+        class.
+
+        Once the event class is registered, it will be generated as one
+        of the event classes generated by :attr:`event_classes`.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        if not isinstance(event_class, EventClass):
+            raise TypeError("Invalid event_class type.")
+
+        ret = nbt._bt_ctf_stream_class_add_event_class(self._sc,
+                                                       event_class._ec)
+
+        if ret < 0:
+            raise ValueError("Could not add event class.")
+
+    @property
+    def packet_context_type(self):
+        """
+        Stream packet context declaration.
+
+        Set this attribute to change the stream packet context
+        declaration (must be an instance of
+        :class:`StructureFieldDeclaration`).
+
+        :exc:`ValueError` is raised on error.
+
+        """
+
+        field_type_native = nbt._bt_ctf_stream_class_get_packet_context_type(self._sc)
+
+        if field_type_native is None:
+            raise ValueError("Invalid StreamClass")
+
+        field_type = FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
+
+        return field_type
+
+    @packet_context_type.setter
+    def packet_context_type(self, field_type):
+        if not isinstance(field_type, StructureFieldDeclaration):
+            raise TypeError("field_type argument must be of type StructureFieldDeclaration.")
+
+        ret = nbt._bt_ctf_stream_class_set_packet_context_type(self._sc,
+                                                               field_type._ft)
+
+        if ret < 0:
+            raise ValueError("Failed to set packet context type.")
+
+
+class Stream:
+    """
+    Streams are specific instances of stream classes, which means they
+    may contain actual, concrete events.
+
+    :class:`Stream` objects are returned by
+    :meth:`Writer.create_stream`; they are not meant to be
+    instantiated by the user.
+
+    Concrete :class:`Event` objects are appended to
+    :class:`Stream` objects using :meth:`append_event`.
+
+    When :meth:`flush` is called, a CTF packet is created, containing
+    all the appended events since the last flush. Although the stream
+    is flushed on object destruction, it is **strongly recommended**
+    that the user call :meth:`flush` manually before exiting the
+    script, as :meth:`__del__` is not always reliable.
+    """
+
+    def __init__(self):
+        raise NotImplementedError("Stream cannot be instantiated; use Writer.create_stream()")
+
+    def __del__(self):
+        nbt._bt_ctf_stream_put(self._s)
+
+    @property
+    def discarded_events(self):
+        """
+        Number of discarded (lost) events in this stream so far.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret, count = nbt._bt_ctf_stream_get_discarded_events_count(self._s)
+
+        if ret < 0:
+            raise ValueError("Could not get the stream discarded events count")
+
+        return count
+
+    def append_discarded_events(self, event_count):
+        """
+        Appends *event_count* discarded events to this stream.
+        """
+
+        nbt._bt_ctf_stream_append_discarded_events(self._s, event_count)
+
+    def append_event(self, event):
+        """
+        Appends event *event* (:class:`Event` object) to this stream.
+
+        The stream's associated clock will be sampled during this call.
+        *event* **shall not** be modified after being appended to this
+        stream.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_stream_append_event(self._s, event._e)
+
+        if ret < 0:
+            raise ValueError("Could not append event to stream.")
+
+    @property
+    def packet_context(self):
+        """
+        Stream packet context field (instance of
+        :class:`StructureField`).
+
+        Set this attribute to assign a stream packet context field
+        to this stream.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        native_field = nbt._bt_ctf_stream_get_packet_context(self._s)
+
+        if native_field is None:
+            raise ValueError("Invalid Stream.")
+
+        return Field._create_field_from_native_instance(native_field)
+
+    @packet_context.setter
+    def packet_context(self, field):
+        if not isinstance(field, StructureField):
+            raise TypeError("Argument field must be of type StructureField")
+
+        ret = nbt._bt_ctf_stream_set_packet_context(self._s, field._f)
+
+        if ret < 0:
+            raise ValueError("Invalid packet context field.")
+
+    def flush(self):
+        """
+        Flushes the current packet of this stream to disk. Events
+        subsequently appended to the stream will be added to a new
+        packet.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_stream_flush(self._s)
+
+        if ret < 0:
+            raise ValueError("Could not flush stream.")
+
+
+class Writer:
+    """
+    This object is the CTF writer API context. It oversees its streams
+    and clocks, and is responsible for writing one CTF trace.
+    """
+
+    def __init__(self, path):
+        """
+        Creates a CTF writer, initializing a new CTF trace at path
+        *path*.
+
+        *path* must be an existing directory, since a CTF trace is
+        made of multiple files.
+
+        :exc:`ValueError` is raised if the creation fails.
+        """
+
+        self._w = nbt._bt_ctf_writer_create(path)
+
+        if self._w is None:
+            raise ValueError("Writer creation failed.")
+
+    def __del__(self):
+        nbt._bt_ctf_writer_put(self._w)
+
+    def create_stream(self, stream_class):
+        """
+        Creates and registers a new stream based on stream class
+        *stream_class*.
+
+        This is the standard way of creating a :class:`Stream` object:
+        the user is not allowed to instantiate this class.
+
+        Returns a new :class:`Stream` object.
+        """
+
+        if not isinstance(stream_class, StreamClass):
+            raise TypeError("Invalid stream_class type.")
+
+        stream = Stream.__new__(Stream)
+        stream._s = nbt._bt_ctf_writer_create_stream(self._w, stream_class._sc)
+
+        return stream
+
+    def add_environment_field(self, name, value):
+        """
+        Sets the CTF environment variable named *name* to value *value*
+        (converted to a string).
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        ret = nbt._bt_ctf_writer_add_environment_field(self._w, str(name),
+                                                       str(value))
+
+        if ret < 0:
+            raise ValueError("Could not add environment field to trace.")
+
+    def add_clock(self, clock):
+        """
+        Registers :class:`Clock` object *clock* to the writer.
+
+        You *must* register CTF clocks assigned to stream classes
+        to the writer.
+
+        :exc:`ValueError` is raised if the creation fails.
+        """
+
+        ret = nbt._bt_ctf_writer_add_clock(self._w, clock._c)
+
+        if ret < 0:
+            raise ValueError("Could not add clock to Writer.")
+
+    @property
+    def metadata(self):
+        """
+        Current metadata of this trace (:class:`str`).
+        """
+
+        return nbt._bt_ctf_writer_get_metadata_string(self._w)
+
+    def flush_metadata(self):
+        """
+        Flushes the trace's metadata to the metadata file.
+        """
+
+        nbt._bt_ctf_writer_flush_metadata(self._w)
+
+    @property
+    def byte_order(self):
+        """
+        Native byte order of this trace (one of
+        :class:`babeltrace.common.ByteOrder` constants).
+
+        This is the actual byte order that is used when a field
+        declaration has the
+        :attr:`babeltrace.common.ByteOrder.BYTE_ORDER_NATIVE`
+        value.
+
+        Set this attribute to change the trace's native byte order.
+
+        Defaults to the host machine's endianness.
+
+        :exc:`ValueError` is raised on error.
+        """
+
+        raise NotImplementedError("Getter not implemented.")
+
+    @byte_order.setter
+    def byte_order(self, byte_order):
+        ret = nbt._bt_ctf_writer_set_byte_order(self._w, byte_order)
+
+        if ret < 0:
+            raise ValueError("Could not set trace byte order.")
diff --git a/bindings/python/common.py b/bindings/python/common.py
deleted file mode 100644 (file)
index 466f2c6..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-# common.py
-#
-# Babeltrace Python module common definitions
-#
-# Copyright 2012-2015 EfficiOS Inc.
-#
-# Author: Danny Serres <danny.serres@efficios.com>
-# Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-
-class CTFStringEncoding:
-    """
-    CTF string encodings.
-    """
-
-    #: None
-    NONE = 0
-
-    #: UTF-8
-    UTF8 = 1
-
-    #: ASCII
-    ASCII = 2
-
-    #: Unknown
-    UNKNOWN = 3
-
-
-# Based on the enum in ctf-writer/writer.h
-class ByteOrder:
-    """
-    Byte orders.
-    """
-
-    #: Native byte order
-    BYTE_ORDER_NATIVE = 0
-
-    #: Little-endian
-    BYTE_ORDER_LITTLE_ENDIAN = 1
-
-    #: Big-endian
-    BYTE_ORDER_BIG_ENDIAN = 2
-
-    #: Network byte order (big-endian)
-    BYTE_ORDER_NETWORK = 3
-
-    #: Unknown byte order
-    BYTE_ORDER_UNKNOWN = 4  # Python-specific entry
-
-
-# enum equivalent, accessible constants
-# These are taken directly from ctf/events.h
-# All changes to enums must also be made here
-class CTFTypeId:
-    """
-    CTF numeric type identifiers.
-    """
-
-    #: Unknown type
-    UNKNOWN = 0
-
-    #: Integer
-    INTEGER = 1
-
-    #: Floating point number
-    FLOAT = 2
-
-    #: Enumeration
-    ENUM = 3
-
-    #: String
-    STRING = 4
-
-    #: Structure
-    STRUCT = 5
-
-    #: Untagged variant
-    UNTAGGED_VARIANT = 6
-
-    #: Variant
-    VARIANT = 7
-
-    #: Array
-    ARRAY = 8
-
-    #: Sequence
-    SEQUENCE = 9
-
-    NR_CTF_TYPES = 10
-
-    def type_name(id):
-        """
-        Returns the name of the CTF numeric type identifier *id*.
-        """
-
-        name = "UNKNOWN_TYPE"
-        constants = [
-            attr for attr in dir(CTFTypeId) if not callable(
-                getattr(
-                    CTFTypeId,
-                    attr)) and not attr.startswith("__")]
-
-        for attr in constants:
-            if getattr(CTFTypeId, attr) == id:
-                name = attr
-                break
-
-        return name
-
-
-class CTFScope:
-    """
-    CTF scopes.
-    """
-
-    #: Packet header
-    TRACE_PACKET_HEADER = 0
-
-    #: Packet context
-    STREAM_PACKET_CONTEXT = 1
-
-    #: Event header
-    STREAM_EVENT_HEADER = 2
-
-    #: Stream event context
-    STREAM_EVENT_CONTEXT = 3
-
-    #: Event context
-    EVENT_CONTEXT = 4
-
-    #: Event fields
-    EVENT_FIELDS = 5
-
-    def scope_name(scope):
-        """
-        Returns the name of the CTF scope *scope*.
-        """
-
-        name = "UNKNOWN_SCOPE"
-        constants = [
-            attr for attr in dir(CTFScope) if not callable(
-                getattr(
-                    CTFScope,
-                    attr)) and not attr.startswith("__")]
-
-        for attr in constants:
-            if getattr(CTFScope, attr) == scope:
-                name = attr
-                break
-
-        return name
diff --git a/bindings/python/examples/babeltrace_and_lttng.py b/bindings/python/examples/babeltrace_and_lttng.py
deleted file mode 100644 (file)
index 651fa2d..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-#!/usr/bin/env python3
-# babeltrace_and_lttng.py
-#
-# Babeltrace and LTTng example script
-#
-# Copyright 2012 EfficiOS Inc.
-#
-# Author: Danny Serres <danny.serres@efficios.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-
-# This script uses both lttng-tools and babeltrace
-# python modules.  It creates a session, enables
-# events, starts tracing for 2 seconds, stops tracing,
-# destroys the session and outputs the trace in the
-# specified output file.
-#
-# WARNING: will destroy any existing trace having
-#          the same name as ses_name
-
-
-# ------------------------------------------------------
-ses_name = "babeltrace-lttng-test"
-trace_path = "/lttng-traces/babeltrace-lttng-trace/"
-out_file = "babeltrace-lttng-trace-text-output.txt"
-# ------------------------------------------------------
-
-
-import time
-try:
-    import babeltrace.reader
-    import lttng
-except ImportError:
-    raise ImportError( "both babeltrace and lttng-tools "
-                       "python modules must be installed")
-
-
-# Errors to raise if something goes wrong
-class LTTngError(Exception):
-    pass
-
-
-class BabeltraceError(Exception):
-    pass
-
-
-# LTTNG-TOOLS
-
-# Making sure session does not already exist
-lttng.destroy(ses_name)
-
-# Creating a new session and handle
-ret = lttng.create(ses_name, trace_path)
-if ret < 0:
-    raise LTTngError(lttng.strerror(ret))
-
-domain = lttng.Domain()
-domain.type = lttng.DOMAIN_KERNEL
-
-han = None
-han = lttng.Handle(ses_name, domain)
-if han is None:
-    raise LTTngError("Handle not created")
-
-
-# Enabling all events
-event = lttng.Event()
-event.type = lttng.EVENT_ALL
-event.loglevel_type = lttng.EVENT_LOGLEVEL_ALL
-ret = lttng.enable_event(han, event, None)
-if ret < 0:
-    raise LTTngError(lttng.strerror(ret))
-
-# Start, wait, stop
-ret = lttng.start(ses_name)
-if ret < 0:
-    raise LTTngError(lttng.strerror(ret))
-print("Tracing...")
-time.sleep(2)
-print("Stopped.")
-ret = lttng.stop(ses_name)
-if ret < 0:
-    raise LTTngError(lttng.strerror(ret))
-
-
-# Destroying tracing session
-ret = lttng.destroy(ses_name)
-if ret < 0:
-    raise LTTngError(lttng.strerror(ret))
-
-
-# BABELTRACE
-
-# Create TraceCollecion and add trace:
-traces = babeltrace.reader.TraceCollection()
-ret = traces.add_trace(trace_path + "/kernel", "ctf")
-if ret is None:
-    raise BabeltraceError("Error adding trace")
-
-# Reading events from trace
-# and outputting timestamps and event names
-# in out_file
-print("Writing trace file...")
-output = open(out_file, "wt")
-
-for event in traces.events:
-    output.write("TS: {}, {} : {}\n".format(
-        event.timestamp, event.cycles, event.name))
-
-# Closing file
-output.close()
-
-print("Done.")
diff --git a/bindings/python/examples/ctf_writer.py b/bindings/python/examples/ctf_writer.py
deleted file mode 100644 (file)
index d60eb3d..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-#!/usr/bin/env python3
-# ctf_writer.py
-#
-# Babeltrace CTF Writer example script.
-#
-# Copyright 2013 EfficiOS Inc.
-#
-# Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-import sys
-import tempfile
-import babeltrace.writer as btw
-
-
-trace_path = tempfile.mkdtemp()
-
-print("Writing trace at {}".format(trace_path))
-writer = btw.Writer(trace_path)
-
-clock = btw.Clock("A_clock")
-print("Clock name is \"{}\"".format(clock.name))
-clock.description = "Simple clock"
-print("Clock description is \"{}\"".format(clock.description))
-print("Clock frequency is {}".format(clock.frequency))
-print("Clock precision is {}".format(clock.precision))
-print("Clock offset_seconds is {}".format(clock.offset_seconds))
-print("Clock offset is {}".format(clock.offset))
-print("Clock is absolute: {}".format(clock.absolute))
-print("Clock time is {}".format(clock.time))
-print("Clock UUID is {}".format(clock.uuid))
-
-writer.add_clock(clock)
-writer.add_environment_field("Python_version", str(sys.version_info))
-
-stream_class = btw.StreamClass("test_stream")
-stream_class.clock = clock
-
-event_class = btw.EventClass("SimpleEvent")
-
-# Create a int32_t equivalent type
-int32_type = btw.IntegerFieldDeclaration(32)
-int32_type.signed = True
-
-# Create a uint16_t equivalent type
-uint16_type = btw.IntegerFieldDeclaration(16)
-uint16_type.signed = False
-
-# Add a custom uint16_t field in the stream's packet context
-packet_context_type = stream_class.packet_context_type
-print("\nFields in default packet context:")
-for field in packet_context_type.fields:
-    print(str(type(field[1])) + " " + field[0])
-packet_context_type.add_field(uint16_type, "a_custom_packet_context_field")
-stream_class.packet_context_type = packet_context_type
-
-# Create a string type
-string_type = btw.StringFieldDeclaration()
-
-# Create a structure type containing both an integer and a string
-structure_type = btw.StructureFieldDeclaration()
-structure_type.add_field(int32_type, "an_integer")
-structure_type.add_field(string_type, "a_string_field")
-event_class.add_field(structure_type, "structure_field")
-
-# Create a floating point type
-floating_point_type = btw.FloatFieldDeclaration()
-floating_point_type.exponent_digits = btw.FloatFieldDeclaration.FLT_EXP_DIG
-floating_point_type.mantissa_digits = btw.FloatFieldDeclaration.FLT_MANT_DIG
-event_class.add_field(floating_point_type, "float_field")
-
-# Create an enumeration type
-int10_type = btw.IntegerFieldDeclaration(10)
-enumeration_type = btw.EnumerationFieldDeclaration(int10_type)
-enumeration_type.add_mapping("FIRST_ENTRY", 0, 4)
-enumeration_type.add_mapping("SECOND_ENTRY", 5, 5)
-enumeration_type.add_mapping("THIRD_ENTRY", 6, 10)
-event_class.add_field(enumeration_type, "enum_field")
-
-# Create an array type
-array_type = btw.ArrayFieldDeclaration(int10_type, 5)
-event_class.add_field(array_type, "array_field")
-
-# Create a sequence type
-sequence_type = btw.SequenceFieldDeclaration(int32_type, "sequence_len")
-event_class.add_field(uint16_type, "sequence_len")
-event_class.add_field(sequence_type, "sequence_field")
-
-stream_class.add_event_class(event_class)
-stream = writer.create_stream(stream_class)
-
-for i in range(100):
-    event = btw.Event(event_class)
-
-    clock.time = i * 1000
-    structure_field = event.payload("structure_field")
-    integer_field = structure_field.field("an_integer")
-    integer_field.value = i
-
-    string_field = structure_field.field("a_string_field")
-    string_field.value = "Test string."
-
-    float_field = event.payload("float_field")
-    float_field.value = float(i) + (float(i) / 100.0)
-
-    array_field = event.payload("array_field")
-    for j in range(5):
-        element = array_field.field(j)
-        element.value = i + j
-
-    event.payload("sequence_len").value = i % 10
-    sequence_field = event.payload("sequence_field")
-    sequence_field.length = event.payload("sequence_len")
-    for j in range(event.payload("sequence_len").value):
-        sequence_field.field(j).value = i + j
-
-    enumeration_field = event.payload("enum_field")
-    integer_field = enumeration_field.container
-    enumeration_field.value = i % 10
-
-    stream.append_event(event)
-
-# Populate custom packet context field before flushing
-packet_context = stream.packet_context
-field = packet_context.field("a_custom_packet_context_field")
-field.value = 42
-
-stream.flush()
diff --git a/bindings/python/examples/example-api-test.py b/bindings/python/examples/example-api-test.py
deleted file mode 100644 (file)
index 1bdea6c..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/env python3
-# example_api_test.py
-#
-# Babeltrace example script based on the Babeltrace API test script
-#
-# Copyright 2012 EfficiOS Inc.
-#
-# Author: Danny Serres <danny.serres@efficios.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-# This example uses the babeltrace python module
-# to partially test the api.
-
-import sys
-import babeltrace.reader
-
-
-# Check for path arg:
-if len(sys.argv) < 2:
-    raise TypeError("Usage: python example-api-test.py path/to/file")
-
-# Create TraceCollection and add trace:
-traces = babeltrace.reader.TraceCollection()
-trace_handle = traces.add_trace(sys.argv[1], "ctf")
-if trace_handle is None:
-    raise IOError("Error adding trace")
-
-# Listing events
-print("--- Event list ---")
-for event_declaration in trace_handle.events:
-    print("event : {}".format(event_declaration.name))
-    if event_declaration.name == "sched_switch":
-        for field_declaration in event_declaration.fields:
-            print(field_declaration)
-print("--- Done ---")
-
-for event in traces.events:
-    print("TS: {}, {} : {}".format(event.timestamp, event.cycles, event.name))
-
-    if event.name == "sched_switch":
-        prev_comm = event["prev_comm"]
-        if prev_comm is None:
-            print("ERROR: Missing prev_comm context info")
-        else:
-            print("sched_switch prev_comm: {}".format(prev_comm))
-
-    if event.name == "exit_syscall":
-        ret_code = event["ret"]
-        if ret_code is None:
-            print("ERROR: Unable to extract ret")
-        else:
-            print("exit_syscall ret: {}".format(ret_code))
diff --git a/bindings/python/examples/sched_switch.py b/bindings/python/examples/sched_switch.py
deleted file mode 100644 (file)
index 0deb4a5..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/usr/bin/env python3
-# sched_switch.py
-#
-# Babeltrace example script with sched_switch events
-#
-# Copyright 2012 EfficiOS Inc.
-#
-# Author: Danny Serres <danny.serres@efficios.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-# The script takes one optional argument (pid)
-# The script will read events based on pid and
-# print the scheduler switches happening with the process.
-# If no arguments are passed, it displays all the scheduler switches.
-# This can be used to understand which tasks schedule out the current
-# process being traced, and when it gets scheduled in again.
-# The trace needs PID context (lttng add-context -k -t pid)
-
-import sys
-import babeltrace.reader
-import babeltrace.common
-
-
-if len(sys.argv) < 2 or len(sys.argv) > 3:
-    raise TypeError("Usage: python sched_switch.py [pid] path/to/trace")
-elif len(sys.argv) == 3:
-    filterPID = True
-else:
-    filterPID = False
-
-traces = babeltrace.reader.TraceCollection()
-ret = traces.add_trace(sys.argv[len(sys.argv) - 1], "ctf")
-if ret is None:
-    raise IOError("Error adding trace")
-
-for event in traces.events:
-    if event.name != "sched_switch":
-        continue
-
-    # Getting PID
-    pid = event.field_with_scope("pid", babeltrace.common.CTFScope.STREAM_EVENT_CONTEXT)
-    if pid is None:
-        print("ERROR: Missing PID info for sched_switch")
-        continue  # Next event
-
-    if filterPID and (pid != long(sys.argv[1])):
-        continue  # Next event
-
-    prev_comm = event["prev_comm"]
-    prev_tid = event["prev_tid"]
-    prev_prio = event["prev_prio"]
-    prev_state = event["prev_state"]
-    next_comm = event["next_comm"]
-    next_tid = event["next_tid"]
-    next_prio = event["next_prio"]
-
-    # Output
-    print("sched_switch, pid = {}, TS = {}, prev_comm = {},\n\t"
-          "prev_tid = {}, prev_prio = {}, prev_state = {},\n\t"
-          "next_comm = {}, next_tid = {}, next_prio = {}".format(
-              pid, event.timestamp, prev_comm, prev_tid,
-              prev_prio, prev_state, next_comm, next_tid, next_prio))
diff --git a/bindings/python/examples/sequence_test.py b/bindings/python/examples/sequence_test.py
deleted file mode 100644 (file)
index e9116ce..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/env python3
-# sequence_test.py
-#
-# Babeltrace example script based on the Babeltrace API test script
-#
-# Copyright 2013 Xiaona Han
-# Copyright 2012 EfficiOS Inc.
-#
-# Author: Danny Serres <danny.serres@efficios.com>
-# Author: Xiaona Han <xiaonahappy13@163.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-# This example uses the babeltrace python module
-# to partially test the sequence API
-
-import sys
-import babeltrace.reader
-
-
-# Check for path arg:
-if len(sys.argv) < 2:
-    raise TypeError("Usage: sequence_test.py path/to/file")
-
-# Create TraceCollection and add trace:
-traces = babeltrace.reader.TraceCollection()
-trace_handle = traces.add_trace(sys.argv[1], "ctf")
-if trace_handle is None:
-    raise IOError("Error adding trace")
-
-# Listing events
-print("--- Event list ---")
-for event_declaration in trace_handle.events:
-    print("event : {}".format(event_declaration.name))
-print("--- Done ---")
-
-for event in traces.events:
-    print("TS: {}, {} : {}".format(event.timestamp,
-                                   event.cycles, event.name))
-
-    try:
-        sequence = event["seq_int_field"]
-        print("int sequence values: {}". format(sequence))
-    except KeyError:
-        pass
-
-    try:
-        sequence = event["seq_long_field"]
-        print("long sequence values: {}". format(sequence))
-    except KeyError:
-        pass
diff --git a/bindings/python/nativebt.i b/bindings/python/nativebt.i
deleted file mode 100644 (file)
index 15726ba..0000000
+++ /dev/null
@@ -1,646 +0,0 @@
-/*
- * nativebt.i.in
- *
- * Babeltrace native interface Python module
- *
- * Copyright 2012 EfficiOS Inc.
- *
- * Author: Danny Serres <danny.serres@efficios.com>
- * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-%module nativebt
-
-
-%include "stdint.i"
-%include "typemaps.i"
-%{
-#define SWIG_FILE_WITH_INIT
-#include <babeltrace/babeltrace.h>
-#include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/trace-handle.h>
-#include <babeltrace/trace-handle-internal.h>
-#include <babeltrace/context.h>
-#include <babeltrace/context-internal.h>
-#include <babeltrace/iterator.h>
-#include <babeltrace/iterator-internal.h>
-#include <babeltrace/format.h>
-#include <babeltrace/list.h>
-#include <babeltrace/types.h>
-#include <babeltrace/ctf/iterator.h>
-#include "python-complements.h"
-#include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-writer/event-types.h>
-#include <babeltrace/ctf-writer/event.h>
-#include <babeltrace/ctf-writer/stream.h>
-#include <babeltrace/ctf-writer/writer.h>
-%}
-
-
-typedef int bt_intern_str;
-typedef int64_t ssize_t;
-
-
-/* python-complements.h */
-struct bt_definition **_bt_python_field_listcaller(
-               const struct bt_ctf_event *ctf_event,
-               const struct bt_definition *scope,
-               unsigned int *OUTPUT);
-struct bt_definition *_bt_python_field_one_from_list(
-               struct bt_definition **list, int index);
-struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
-               int handle_id,
-               struct bt_context *ctx,
-               unsigned int *OUTPUT);
-struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
-               struct bt_ctf_event_decl **list, int index);
-struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
-               struct bt_ctf_event_decl *event_decl,
-               enum ctf_scope scope,
-               unsigned int *OUTPUT);
-struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
-               struct bt_ctf_field_decl **list, int index);
-struct definition_array *_bt_python_get_array_from_def(
-               struct bt_definition *field);
-struct definition_sequence *_bt_python_get_sequence_from_def(
-               struct bt_definition *field);
-struct bt_declaration *_bt_python_get_array_element_declaration(
-               struct bt_declaration *field);
-struct bt_declaration *_bt_python_get_sequence_element_declaration(
-               struct bt_declaration *field);
-const char *_bt_python_get_array_string(struct bt_definition *field);
-const char *_bt_python_get_sequence_string(struct bt_definition *field);
-int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
-enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
-const char *_bt_python_ctf_field_type_enumeration_get_mapping(
-               struct bt_ctf_field_type *enumeration, size_t index,
-               int64_t *OUTPUT, int64_t *OUTPUT);
-const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
-               struct bt_ctf_field_type *enumeration, size_t index,
-               uint64_t *OUTPUT, uint64_t *OUTPUT);
-const char *_bt_python_ctf_field_type_structure_get_field_name(
-               struct bt_ctf_field_type *structure, size_t index);
-struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
-               struct bt_ctf_field_type *structure, size_t index);
-const char *_bt_python_ctf_field_type_variant_get_field_name(
-               struct bt_ctf_field_type *variant, size_t index);
-struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
-               struct bt_ctf_field_type *variant, size_t index);
-const char *_bt_python_ctf_event_class_get_field_name(
-               struct bt_ctf_event_class *event_class, size_t index);
-struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
-               struct bt_ctf_event_class *event_class, size_t index);
-int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
-               size_t index, unsigned char *OUTPUT);
-int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
-               size_t index, unsigned char value);
-struct bt_iter_pos *_bt_python_create_iter_pos(void);
-struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect(
-               struct bt_context *ctx,
-               struct bt_iter_pos *inter_begin_pos,
-               struct bt_iter_pos *inter_end_pos);
-int _bt_python_trace_collection_has_intersection(struct bt_context *ctx);
-
-/* context.h, context-internal.h */
-%rename("_bt_context_create") bt_context_create(void);
-%rename("_bt_context_add_trace") bt_context_add_trace(
-               struct bt_context *ctx, const char *path, const char *format,
-               void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
-               struct bt_mmap_stream_list *stream_list, FILE *metadata);
-%rename("_bt_context_remove_trace") bt_context_remove_trace(
-               struct bt_context *ctx, int trace_id);
-%rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
-%rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
-%rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
-               const struct bt_ctf_event *event);
-
-struct bt_context *bt_context_create(void);
-int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
-               void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
-               struct bt_mmap_stream_list *stream_list, FILE *metadata);
-void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
-void bt_context_get(struct bt_context *ctx);
-void bt_context_put(struct bt_context *ctx);
-struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
-
-
-/* format.h */
-%rename("lookup_format") bt_lookup_format(bt_intern_str qname);
-%rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
-%rename("register_format") bt_register_format(struct format *format);
-%rename("unregister_format") bt_unregister_format(struct bt_format *format);
-
-extern struct format *bt_lookup_format(bt_intern_str qname);
-extern void bt_fprintf_format_list(FILE *fp);
-extern int bt_register_format(struct bt_format *format);
-extern void bt_unregister_format(struct bt_format *format);
-
-
-/* iterator.h, iterator-internal.h */
-%rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
-               const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
-%rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
-%rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
-%rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
-%rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
-%rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
-               const struct bt_iter_pos *pos);
-%rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
-               uint64_t timestamp);
-
-struct bt_iter *bt_iter_create(struct bt_context *ctx,
-               const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
-void bt_iter_destroy(struct bt_iter *iter);
-int bt_iter_next(struct bt_iter *iter);
-struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
-void bt_iter_free_pos(struct bt_iter_pos *pos);
-int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
-struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
-
-%rename("_bt_iter_pos") bt_iter_pos;
-%rename("SEEK_TIME") BT_SEEK_TIME;
-%rename("SEEK_RESTORE") BT_SEEK_RESTORE;
-%rename("SEEK_CUR") BT_SEEK_CUR;
-%rename("SEEK_BEGIN") BT_SEEK_BEGIN;
-%rename("SEEK_LAST") BT_SEEK_LAST;
-
-
-/*
- * This struct is taken from iterator.h
- * All changes to the struct must also be made here.
- */
-struct bt_iter_pos {
-       enum {
-               BT_SEEK_TIME,           /* uses u.seek_time */
-               BT_SEEK_RESTORE,        /* uses u.restore */
-               BT_SEEK_CUR,
-               BT_SEEK_BEGIN,
-               BT_SEEK_LAST
-       } type;
-       union {
-               uint64_t seek_time;
-               struct bt_saved_pos *restore;
-       } u;
-};
-
-
-/* trace-handle.h, trace-handle-internal.h */
-%rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
-%rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
-struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
-void bt_trace_handle_destroy(struct bt_trace_handle *bt);
-
-%rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
-               int handle_id);
-%rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
-               struct bt_context *ctx, int handle_id, enum bt_clock_type type,
-                int64_t *timestamp);
-%rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
-               struct bt_context *ctx, int handle_id, enum bt_clock_type type,
-                int64_t *timestamp);
-const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
-int bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
-               enum bt_clock_type type, int64_t *OUTPUT);
-int bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
-               enum bt_clock_type type, int64_t *OUTPUT);
-
-%rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
-               const struct bt_ctf_event *event);
-int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
-
-
-/* iterator.h, events.h */
-%rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
-               const struct bt_iter_pos *begin_pos,
-               const struct bt_iter_pos *end_pos);
-%rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
-%rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
-%rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
-
-struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
-               const struct bt_iter_pos *begin_pos,
-               const struct bt_iter_pos *end_pos);
-struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
-void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
-struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
-
-
-/* events.h */
-%rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
-               bt_ctf_event *event, enum ctf_scope scope);
-%rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
-%rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
-               const struct bt_ctf_event *ctf_event, int64_t *OUTPUT);
-%rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
-               const struct bt_ctf_event *ctf_event);
-
-%rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
-               const struct bt_definition *scope,      const char *field);
-%rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
-               const struct bt_definition *field,      unsigned int index);
-%rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
-%rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
-%rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
-               const struct bt_declaration *field);
-%rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
-%rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
-               const struct bt_declaration *field);
-%rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
-%rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
-%rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
-%rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
-%rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
-%rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
-%rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
-%rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
-%rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
-%rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
-%rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
-%rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
-%rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
-               bt_ctf_event_decl *event);
-%rename("_bt_ctf_get_decl_event_id") bt_ctf_get_decl_event_id(const struct
-               bt_ctf_event_decl *event);
-%rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
-               const struct bt_ctf_field_decl *field);
-%rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
-               const struct bt_definition *field);
-%rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
-               const struct bt_ctf_field_decl *field);
-%rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
-%rename("_bt_sequence_len")  bt_sequence_len(struct definition_sequence *sequence);
-%rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
-%rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
-%rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
-
-const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
-               enum ctf_scope scope);
-const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
-int bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event, int64_t *OUTPUT);
-uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
-const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
-               const struct bt_definition *scope,
-               const char *field);
-const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
-               const struct bt_definition *field,
-               unsigned int index);
-const char *bt_ctf_field_name(const struct bt_definition *field);
-enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
-int bt_ctf_get_int_signedness(const struct bt_declaration *field);
-int bt_ctf_get_int_base(const struct bt_declaration *field);
-int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
-ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
-const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
-const char *bt_ctf_get_enum_str(const struct bt_definition *field);
-enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
-int bt_ctf_get_array_len(const struct bt_declaration *field);
-struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
-uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
-int64_t bt_ctf_get_int64(const struct bt_definition *field);
-char *bt_ctf_get_char_array(const struct bt_definition *field);
-char *bt_ctf_get_string(const struct bt_definition *field);
-double bt_ctf_get_float(const struct bt_definition *field);
-const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
-int bt_ctf_field_get_error(void);
-const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
-uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
-const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
-const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
-const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
-uint64_t bt_sequence_len(struct definition_sequence *sequence);
-struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
-uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
-const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
-
-
-/* CTF Writer */
-
-/* clock.h */
-%rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
-%rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
-%rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
-%rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
-%rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
-%rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
-%rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
-%rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
-%rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock, int64_t *offset_s);
-%rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, int64_t offset_s);
-%rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock, int64_t *offset);
-%rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, int64_t offset);
-%rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
-%rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
-%rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock, int64_t *time);
-%rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, int64_t time);
-%rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
-%rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
-
-struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
-const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
-const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
-int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
-uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
-int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
-uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
-int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
-int bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock, int64_t *OUTPUT);
-int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, int64_t offset_s);
-int bt_ctf_clock_get_offset(struct bt_ctf_clock *clock, int64_t *OUTPUT);
-int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, int64_t offset);
-int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
-int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
-int bt_ctf_clock_get_time(struct bt_ctf_clock *clock, int64_t *OUTPUT);
-int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, int64_t time);
-void bt_ctf_clock_get(struct bt_ctf_clock *clock);
-void bt_ctf_clock_put(struct bt_ctf_clock *clock);
-
-
-/* event-types.h */
-%rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
-%rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
-%rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
-%rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
-%rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
-%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);
-%rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
-%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);
-%rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
-%rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
-%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);
-%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);
-%rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
-%rename("_bt_ctf_field_type_enumeration_get_mapping") bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, int index, const char **name, int64_t *range_start, int64_t *range_end);
-%rename("_bt_ctf_field_type_enumeration_get_mapping_unsigned") bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, int index, const char **name, uint64_t *range_start, uint64_t *range_end);
-%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);
-%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);
-%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);
-%rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
-%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);
-%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);
-%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);
-%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);
-%rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
-%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);
-%rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
-%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, int index);
-%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);
-%rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
-%rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
-%rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
-%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);
-%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);
-%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);
-%rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
-%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, int index);
-%rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
-%rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
-%rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
-%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);
-%rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
-%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);
-%rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
-%rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
-%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);
-%rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
-%rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
-%rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
-%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);
-%rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
-%rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
-%rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
-
-struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
-int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
-int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
-int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
-enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
-int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
-enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
-int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
-struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
-struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
-int bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *name, int64_t range_start, int64_t range_end);
-int 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);
-int bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
-int bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, int index, const char **OUTPUT, int64_t *OUTPUT, int64_t *OUTPUT);
-int bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, int index, const char **OUTPUT, uint64_t *OUTPUT, uint64_t *OUTPUT);
-int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name);
-int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value);
-int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value);
-struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
-int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
-int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
-int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
-int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
-struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
-int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name);
-int bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
-int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, int index);
-struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name(struct bt_ctf_field_type *structure, const char *field_name);
-struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
-struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
-const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
-int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field_type, const char *field_name);
-struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name(struct bt_ctf_field_type *variant, const char *field_name);
-struct 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);
-int bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
-int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, int index);
-struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
-struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
-int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
-struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
-struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
-const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
-struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
-enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
-int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
-int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
-int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
-enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
-int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
-enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
-void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
-void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
-
-
-/* event-fields.h */
-%rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
-%rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
-%rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
-%rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
-%rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
-%rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
-%rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
-%rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
-%rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
-%rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
-%rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
-%rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
-%rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
-%rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
-%rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
-%rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
-%rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
-%rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
-%rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
-%rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
-
-struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
-struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
-struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
-struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
-int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
-struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
-struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
-struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
-const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
-int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
-int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
-int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
-int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
-int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
-int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
-const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
-int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
-struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
-void bt_ctf_field_get(struct bt_ctf_field *field);
-void bt_ctf_field_put(struct bt_ctf_field *field);
-
-
-/* event-class.h */
-%rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
-%rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
-%rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
-%rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
-%rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
-%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);
-%rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
-%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, int index);
-%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);
-%rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
-%rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
-
-struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
-const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
-int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
-int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
-struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
-int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
-int bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
-int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, int index);
-struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
-void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
-void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
-
-
-/* event.h */
-%rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
-%rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
-%rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
-%rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
-%rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
-%rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, int index);
-%rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
-%rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
-
-struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
-struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
-struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
-struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
-int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
-struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, int index);
-void bt_ctf_event_get(struct bt_ctf_event *event);
-void bt_ctf_event_put(struct bt_ctf_event *event);
-
-
-/* stream-class.h */
-%rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
-%rename("_bt_ctf_stream_class_get_name") bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
-%rename("_bt_ctf_stream_class_get_clock") bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
-%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);
-%rename("_bt_ctf_stream_class_get_id") bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
-%rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
-%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);
-%rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
-%rename("_bt_ctf_stream_class_get_event_class") bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, int index);
-%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);
-%rename("_bt_ctf_stream_class_get_packet_context_type") bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
-%rename("_bt_ctf_stream_class_set_packet_context_type") bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
-%rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
-%rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
-
-struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
-const char *bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
-struct bt_ctf_clock *bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
-int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
-int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
-int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
-int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
-int bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
-struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, int index);
-struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
-struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
-int bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
-void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
-void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
-
-
-/* stream.h */
-%rename("_bt_ctf_stream_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
-%rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
-%rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
-%rename("_bt_ctf_stream_get_packet_context") bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
-%rename("_bt_ctf_stream_set_packet_context") bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
-%rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
-%rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
-%rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
-
-int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
-void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
-int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
-struct bt_ctf_field *bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
-int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
-int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
-void bt_ctf_stream_get(struct bt_ctf_stream *stream);
-void bt_ctf_stream_put(struct bt_ctf_stream *stream);
-
-
-/* writer.h */
-%rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
-%rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
-%rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
-%rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
-%newobject bt_ctf_writer_get_metadata_string;
-%rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
-%rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
-%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);
-%rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
-%rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
-
-struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
-struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
-int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
-int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
-char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
-void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
-int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
-void bt_ctf_writer_get(struct bt_ctf_writer *writer);
-void bt_ctf_writer_put(struct bt_ctf_writer *writer);
diff --git a/bindings/python/python-complements.c b/bindings/python/python-complements.c
deleted file mode 100644 (file)
index 0e3bbdf..0000000
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
- * python-complements.c
- *
- * Babeltrace Python module complements, required for Python bindings
- *
- * Copyright 2012 EfficiOS Inc.
- *
- * Author: Danny Serres <danny.serres@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- */
-
-#include "python-complements.h"
-#include <babeltrace/ctf-ir/field-types-internal.h>
-#include <babeltrace/ctf-ir/fields-internal.h>
-#include <babeltrace/ctf-ir/field-types.h>
-#include <babeltrace/ctf-ir/event.h>
-#include <babeltrace/ctf-ir/event-class.h>
-#include <babeltrace/ctf-ir/clock-internal.h>
-#include <babeltrace/iterator.h>
-#include <babeltrace/ctf/iterator.h>
-#include <babeltrace/ctf/events-internal.h>
-#include <glib.h>
-
-/* List-related functions
-   ----------------------------------------------------
-*/
-
-/* ctf-field-list */
-struct bt_definition **_bt_python_field_listcaller(
-               const struct bt_ctf_event *ctf_event,
-               const struct bt_definition *scope,
-               unsigned int *len)
-{
-       struct bt_definition **list;
-       int ret;
-
-       ret = bt_ctf_get_field_list(ctf_event, scope,
-               (const struct bt_definition * const **)&list, len);
-
-       if (ret < 0)    /* For python to know an error occured */
-               list = NULL;
-
-       return list;
-}
-
-struct bt_definition *_bt_python_field_one_from_list(
-               struct bt_definition **list, int index)
-{
-       return list[index];
-}
-
-/* event_decl_list */
-struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
-               int handle_id,
-               struct bt_context *ctx,
-               unsigned int *len)
-{
-       struct bt_ctf_event_decl **list;
-       int ret;
-
-       ret = bt_ctf_get_event_decl_list(handle_id, ctx,
-               (struct bt_ctf_event_decl * const **)&list, len);
-
-       if (ret < 0)    /* For python to know an error occured */
-               list = NULL;
-
-       return list;
-}
-
-struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
-               struct bt_ctf_event_decl **list, int index)
-{
-       return list[index];
-}
-
-/* decl_fields */
-struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
-               struct bt_ctf_event_decl *event_decl,
-               enum ctf_scope scope,
-               unsigned int *len)
-{
-       struct bt_ctf_field_decl **list;
-       int ret;
-
-       ret = bt_ctf_get_decl_fields(event_decl, scope,
-               (const struct bt_ctf_field_decl * const **)&list, len);
-
-       if (ret < 0)    /* For python to know an error occured */
-               list = NULL;
-
-       return list;
-}
-
-struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
-               struct bt_ctf_field_decl **list, int index)
-{
-       return list[index];
-}
-
-struct definition_array *_bt_python_get_array_from_def(
-               struct bt_definition *field)
-{
-       const struct bt_declaration *array_decl;
-       struct definition_array *array = NULL;
-
-       if (!field) {
-               goto end;
-       }
-
-       array_decl = bt_ctf_get_decl_from_def(field);
-       if (bt_ctf_field_type(array_decl) == CTF_TYPE_ARRAY) {
-               array = container_of(field, struct definition_array, p);
-       }
-end:
-       return array;
-}
-
-struct bt_declaration *_bt_python_get_array_element_declaration(
-               struct bt_declaration *field)
-{
-       struct declaration_array *array_decl;
-       struct bt_declaration *ret = NULL;
-
-       if (!field) {
-               goto end;
-       }
-
-       array_decl = container_of(field, struct declaration_array, p);
-       ret = array_decl->elem;
-end:
-       return ret;
-}
-
-struct bt_declaration *_bt_python_get_sequence_element_declaration(
-               struct bt_declaration *field)
-{
-       struct declaration_sequence *sequence_decl;
-       struct bt_declaration *ret = NULL;
-
-       if (!field) {
-               goto end;
-       }
-
-       sequence_decl = container_of(field, struct declaration_sequence, p);
-       ret = sequence_decl->elem;
-end:
-       return ret;
-}
-
-const char *_bt_python_get_array_string(struct bt_definition *field)
-{
-       struct definition_array *array;
-       const char *ret = NULL;
-
-       if (!field) {
-               goto end;
-       }
-
-       array = container_of(field, struct definition_array, p);
-       ret = array->string->str;
-end:
-       return ret;
-}
-
-const char *_bt_python_get_sequence_string(struct bt_definition *field)
-{
-       struct definition_sequence *sequence;
-       const char *ret = NULL;
-
-       if (!field) {
-               goto end;
-       }
-
-       sequence = container_of(field, struct definition_sequence, p);
-       ret = sequence->string->str;
-end:
-       return ret;
-}
-
-struct definition_sequence *_bt_python_get_sequence_from_def(
-               struct bt_definition *field)
-{
-       if (field && bt_ctf_field_type(
-               bt_ctf_get_decl_from_def(field)) == CTF_TYPE_SEQUENCE) {
-               return container_of(field, struct definition_sequence, p);
-       }
-
-       return NULL;
-}
-
-int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field)
-{
-       int ret;
-
-       if (!field || field->type->declaration->id != CTF_TYPE_INTEGER) {
-               ret = -1;
-               goto end;
-       }
-
-       const struct bt_ctf_field_type_integer *type = container_of(field->type,
-               const struct bt_ctf_field_type_integer, parent);
-       ret = type->declaration.signedness;
-end:
-       return ret;
-}
-
-enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field)
-{
-       enum ctf_type_id type_id = CTF_TYPE_UNKNOWN;
-
-       if (!field) {
-               goto end;
-       }
-
-       type_id = field->type->declaration->id;
-end:
-       return type_id;
-}
-
-/*
- * Swig doesn't handle returning pointers via output arguments properly...
- * These functions only wrap the ctf-ir functions to provide them directly
- * as regular return values.
- */
-const char *_bt_python_ctf_field_type_enumeration_get_mapping(
-               struct bt_ctf_field_type *enumeration, size_t index,
-               int64_t *range_start, int64_t *range_end)
-{
-       int ret;
-       const char *name;
-
-       ret = bt_ctf_field_type_enumeration_get_mapping(enumeration, index,
-               &name, range_start, range_end);
-       return !ret ? name : NULL;
-}
-
-const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
-               struct bt_ctf_field_type *enumeration, size_t index,
-               uint64_t *range_start, uint64_t *range_end)
-{
-       int ret;
-       const char *name;
-
-       ret = bt_ctf_field_type_enumeration_get_mapping_unsigned(enumeration,
-               index, &name, range_start, range_end);
-       return !ret ? name : NULL;
-}
-
-const char *_bt_python_ctf_field_type_structure_get_field_name(
-               struct bt_ctf_field_type *structure, size_t index)
-{
-       int ret;
-       const char *name;
-       struct bt_ctf_field_type *type;
-
-       ret = bt_ctf_field_type_structure_get_field(structure, &name, &type,
-               index);
-       if (ret) {
-               name = NULL;
-               goto end;
-       }
-
-       bt_ctf_field_type_put(type);
-end:
-       return name;
-}
-
-struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
-               struct bt_ctf_field_type *structure, size_t index)
-{
-       int ret;
-       const char *name;
-       struct bt_ctf_field_type *type;
-
-       ret = bt_ctf_field_type_structure_get_field(structure, &name, &type,
-               index);
-       return !ret ? type : NULL;
-}
-
-const char *_bt_python_ctf_field_type_variant_get_field_name(
-               struct bt_ctf_field_type *variant, size_t index)
-{
-       int ret;
-       const char *name;
-       struct bt_ctf_field_type *type;
-
-       ret = bt_ctf_field_type_variant_get_field(variant, &name, &type,
-               index);
-       if (ret) {
-               name = NULL;
-               goto end;
-       }
-
-       bt_ctf_field_type_put(type);
-end:
-       return name;
-}
-
-struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
-               struct bt_ctf_field_type *variant, size_t index)
-{
-       int ret;
-       const char *name;
-       struct bt_ctf_field_type *type;
-
-       ret = bt_ctf_field_type_variant_get_field(variant, &name, &type,
-               index);
-       return !ret ? type : NULL;
-}
-
-const char *_bt_python_ctf_event_class_get_field_name(
-               struct bt_ctf_event_class *event_class, size_t index)
-{
-       int ret;
-       const char *name;
-       struct bt_ctf_field_type *type;
-
-       ret = bt_ctf_event_class_get_field(event_class, &name, &type,
-               index);
-       if (ret) {
-               name = NULL;
-               goto end;
-       }
-
-       bt_ctf_field_type_put(type);
-end:
-       return name;
-}
-
-struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
-               struct bt_ctf_event_class *event_class, size_t index)
-{
-       int ret;
-       const char *name;
-       struct bt_ctf_field_type *type;
-
-       ret = bt_ctf_event_class_get_field(event_class, &name, &type,
-               index);
-       return !ret ? type : NULL;
-}
-
-int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
-               size_t index, unsigned char *value)
-{
-       int ret = 0;
-       const unsigned char *uuid;
-
-       if (index >= 16) {
-               ret = -1;
-               goto end;
-       }
-
-       uuid = bt_ctf_clock_get_uuid(clock);
-       if (!uuid) {
-               ret = -1;
-               goto end;
-       }
-
-       *value = uuid[index];
-end:
-       return ret;
-}
-
-int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
-               size_t index, unsigned char value)
-{
-       int ret = 0;
-
-       if (index >= 16) {
-               ret = -1;
-               goto end;
-       }
-
-       clock->uuid[index] = value;
-end:
-       return ret;
-}
-
-/*
- * Python 3.5 changes the StopIteration exception clearing behaviour which
- * erroneously marks swig clean-up function as having failed. This explicit
- * allocation function is intended as a work-around so SWIG doesn't manage
- * the lifetime of a "temporary" object by itself.
- */
-struct bt_iter_pos *_bt_python_create_iter_pos(void)
-{
-       return g_new0(struct bt_iter_pos, 1);
-}
-
-struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect(
-               struct bt_context *ctx,
-               struct bt_iter_pos *inter_begin_pos,
-               struct bt_iter_pos *inter_end_pos)
-{
-       return bt_ctf_iter_create_intersect(ctx, &inter_begin_pos,
-                       &inter_end_pos);
-}
-
-int _bt_python_trace_collection_has_intersection(struct bt_context *ctx)
-{
-       int ret;
-       int64_t begin, end;
-
-       ret = ctf_find_tc_stream_packet_intersection_union(ctx, &begin, &end);
-
-       return ret == 0 ? 1 : 0;
-}
diff --git a/bindings/python/python-complements.h b/bindings/python/python-complements.h
deleted file mode 100644 (file)
index 8c8ce87..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * python-complements.h
- *
- * Babeltrace Python module complements header, required for Python bindings
- *
- * Copyright 2012 EfficiOS Inc.
- *
- * Author: Danny Serres <danny.serres@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- */
-
-#include <stdio.h>
-#include <glib.h>
-#include <babeltrace/babeltrace.h>
-#include <babeltrace/format.h>
-#include <babeltrace/ctf-ir/metadata.h>
-#include <babeltrace/ctf/events.h>
-#include <babeltrace/iterator-internal.h>
-#include <babeltrace/ctf/events-internal.h>
-#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-writer/clock.h>
-
-/* ctf-field-list */
-struct bt_definition **_bt_python_field_listcaller(
-               const struct bt_ctf_event *ctf_event,
-               const struct bt_definition *scope,
-               unsigned int *len);
-struct bt_definition *_bt_python_field_one_from_list(
-               struct bt_definition **list, int index);
-
-/* event_decl_list */
-struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
-               int handle_id,
-               struct bt_context *ctx,
-               unsigned int *len);
-struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
-               struct bt_ctf_event_decl **list, int index);
-
-/* decl_fields */
-struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
-               struct bt_ctf_event_decl *event_decl,
-               enum ctf_scope scope,
-               unsigned int *len);
-struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
-               struct bt_ctf_field_decl **list, int index);
-
-/* definitions */
-struct definition_array *_bt_python_get_array_from_def(
-               struct bt_definition *field);
-struct definition_sequence *_bt_python_get_sequence_from_def(
-               struct bt_definition *field);
-struct bt_declaration *_bt_python_get_array_element_declaration(
-               struct bt_declaration *field);
-struct bt_declaration *_bt_python_get_sequence_element_declaration(
-               struct bt_declaration *field);
-const char *_bt_python_get_array_string(struct bt_definition *field);
-const char *_bt_python_get_sequence_string(struct bt_definition *field);
-
-/* ctf ir */
-int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
-enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
-const char *_bt_python_ctf_field_type_enumeration_get_mapping(
-               struct bt_ctf_field_type *enumeration, size_t index,
-               int64_t *range_start, int64_t *range_end);
-const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
-               struct bt_ctf_field_type *enumeration, size_t index,
-               uint64_t *range_start, uint64_t *range_end);
-const char *_bt_python_ctf_field_type_structure_get_field_name(
-               struct bt_ctf_field_type *structure, size_t index);
-struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
-               struct bt_ctf_field_type *structure, size_t index);
-const char *_bt_python_ctf_field_type_variant_get_field_name(
-               struct bt_ctf_field_type *variant, size_t index);
-struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
-               struct bt_ctf_field_type *variant, size_t index);
-const char *_bt_python_ctf_event_class_get_field_name(
-               struct bt_ctf_event_class *event_class, size_t index);
-struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
-               struct bt_ctf_event_class *event_class, size_t index);
-int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
-               size_t index, unsigned char *value);
-int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
-               size_t index, unsigned char value);
-
-/* iterator */
-struct bt_iter_pos *_bt_python_create_iter_pos(void);
-struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect(
-               struct bt_context *ctx,
-               struct bt_iter_pos *inter_begin_pos,
-               struct bt_iter_pos *inter_end_pos);
-int _bt_python_trace_collection_has_intersection(struct bt_context *ctx);
diff --git a/bindings/python/reader.py b/bindings/python/reader.py
deleted file mode 100644 (file)
index 7756db1..0000000
+++ /dev/null
@@ -1,1266 +0,0 @@
-# reader.py
-#
-# Babeltrace reader interface Python module
-#
-# Copyright 2012-2015 EfficiOS Inc.
-#
-# Author: Danny Serres <danny.serres@efficios.com>
-# Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-import babeltrace.nativebt as nbt
-import babeltrace.common as common
-import collections
-import os
-from datetime import datetime
-
-
-class TraceCollection:
-    """
-    A :class:`TraceCollection` is a collection of opened traces.
-
-    Once a trace collection is created, you can add traces to the
-    collection by using the :meth:`add_trace` or
-    :meth:`add_traces_recursive`, and then iterate on the merged
-    events using :attr:`events`.
-
-    You may use :meth:`remove_trace` to close and remove a specific
-    trace from a trace collection.
-    """
-
-    def __init__(self, intersect_mode=False):
-        """
-        Creates an empty trace collection.
-        """
-
-        self._tc = nbt._bt_context_create()
-        self._intersect_mode = intersect_mode
-
-    def __del__(self):
-        nbt._bt_context_put(self._tc)
-
-    def add_trace(self, path, format_str):
-        """
-        Adds a trace to the trace collection.
-
-        *path* is the exact path of the trace on the filesystem.
-
-        *format_str* is a string indicating the type of trace to
-        add. ``ctf`` is currently the only supported trace format.
-
-        Returns the corresponding :class:`TraceHandle` instance for
-        this opened trace on success, or ``None`` on error.
-
-        This function **does not** recurse directories to find a
-        trace.  See :meth:`add_traces_recursive` for a recursive
-        version of this function.
-        """
-
-        ret = nbt._bt_context_add_trace(self._tc, path, format_str,
-                                        None, None, None)
-
-        if ret < 0:
-            return None
-
-        th = TraceHandle.__new__(TraceHandle)
-        th._id = ret
-        th._trace_collection = self
-
-        return th
-
-    def add_traces_recursive(self, path, format_str):
-        """
-        Adds traces to this trace collection by recursively searching
-        in the *path* directory.
-
-        *format_str* is a string indicating the type of trace to add.
-        ``ctf`` is currently the only supported trace format.
-
-        Returns a :class:`dict` object mapping full paths to trace
-        handles for each trace found, or ``None`` on error.
-
-        See also :meth:`add_trace`.
-        """
-
-        trace_handles = {}
-        noTrace = True
-        error = False
-
-        for fullpath, dirs, files in os.walk(path):
-            if "metadata" in files:
-                trace_handle = self.add_trace(fullpath, format_str)
-
-                if trace_handle is None:
-                    error = True
-                    continue
-
-                trace_handles[fullpath] = trace_handle
-                noTrace = False
-
-        if noTrace and error:
-            return None
-
-        return trace_handles
-
-    def remove_trace(self, trace_handle):
-        """
-        Removes a trace from the trace collection using its trace
-        handle *trace_handle*.
-
-        :class:`TraceHandle` objects are returned by :meth:`add_trace`
-        and :meth:`add_traces_recursive`.
-        """
-
-        try:
-            nbt._bt_context_remove_trace(self._tc, trace_handle._id)
-        except AttributeError:
-            raise TypeError("in remove_trace, argument 2 must be a TraceHandle instance")
-
-    @property
-    def intersect_mode(self):
-        return self._intersect_mode
-
-    @property
-    def has_intersection(self):
-        return nbt._bt_python_trace_collection_has_intersection(self._tc)
-
-    @property
-    def events(self):
-        """
-        Generates the ordered :class:`Event` objects of all the opened
-        traces contained in this trace collection.
-
-        Due to limitations of the native Babeltrace API, only one event
-        may be "alive" at a given time, i.e. a user **should never**
-        store a copy of the events returned by this function for
-        ulterior use. Users shall make sure to copy the information
-        they need *from* an event before accessing the next one.
-        """
-
-        begin_pos_ptr = nbt._bt_python_create_iter_pos()
-        end_pos_ptr = nbt._bt_python_create_iter_pos()
-
-        if not self.intersect_mode:
-            begin_pos_ptr.type = nbt.SEEK_BEGIN
-            end_pos_ptr.type = nbt.SEEK_LAST
-
-        for event in self._events(begin_pos_ptr, end_pos_ptr):
-            yield event
-
-        nbt._bt_iter_free_pos(begin_pos_ptr)
-        nbt._bt_iter_free_pos(end_pos_ptr)
-
-    def events_timestamps(self, timestamp_begin, timestamp_end):
-        """
-        Generates the ordered :class:`Event` objects of all the opened
-        traces contained in this trace collection from *timestamp_begin*
-        to *timestamp_end*.
-
-        *timestamp_begin* and *timestamp_end* are given in nanoseconds
-        since Epoch.
-
-        See :attr:`events` for notes and limitations.
-        """
-
-        begin_pos_ptr = nbt._bt_python_create_iter_pos()
-        end_pos_ptr = nbt._bt_python_create_iter_pos()
-        begin_pos_ptr.type = end_pos_ptr.type = nbt.SEEK_TIME
-        begin_pos_ptr.u.seek_time = timestamp_begin
-        end_pos_ptr.u.seek_time = timestamp_end
-
-        for event in self._events(begin_pos_ptr, end_pos_ptr):
-            yield event
-
-        nbt._bt_iter_free_pos(begin_pos_ptr)
-        nbt._bt_iter_free_pos(end_pos_ptr)
-
-    @property
-    def timestamp_begin(self):
-        """
-        Begin timestamp of this trace collection (nanoseconds since
-        Epoch).
-        """
-
-        pos_ptr = nbt._bt_iter_pos()
-        pos_ptr.type = nbt.SEEK_BEGIN
-
-        return self._timestamp_at_pos(pos_ptr)
-
-    @property
-    def timestamp_end(self):
-        """
-        End timestamp of this trace collection (nanoseconds since
-        Epoch).
-        """
-
-        pos_ptr = nbt._bt_iter_pos()
-        pos_ptr.type = nbt.SEEK_LAST
-
-        return self._timestamp_at_pos(pos_ptr)
-
-    def _timestamp_at_pos(self, pos_ptr):
-        ctf_it_ptr = nbt._bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
-
-        if ctf_it_ptr is None:
-            raise NotImplementedError("Creation of multiple iterators is unsupported.")
-
-        ev_ptr = nbt._bt_ctf_iter_read_event(ctf_it_ptr)
-        nbt._bt_ctf_iter_destroy(ctf_it_ptr)
-
-        ev = Event.__new__(Event)
-        ev._e = ev_ptr
-
-        return ev.timestamp
-
-    def _events(self, begin_pos_ptr, end_pos_ptr):
-        if self.intersect_mode:
-            if not self.has_intersection:
-                # There are no events to provide.
-                return
-
-            ctf_it_ptr = nbt._bt_python_ctf_iter_create_intersect(
-                self._tc, begin_pos_ptr, end_pos_ptr
-            )
-        else:
-            ctf_it_ptr = nbt._bt_ctf_iter_create(
-                self._tc, begin_pos_ptr, end_pos_ptr
-            )
-
-        if ctf_it_ptr is None:
-            raise NotImplementedError("Creation of multiple iterators is unsupported.")
-
-        while True:
-            ev_ptr = nbt._bt_ctf_iter_read_event(ctf_it_ptr)
-
-            if ev_ptr is None:
-                break
-
-            ev = Event.__new__(Event)
-            ev._e = ev_ptr
-
-            try:
-                yield ev
-            except GeneratorExit:
-                break
-
-            ret = nbt._bt_iter_next(nbt._bt_ctf_get_iter(ctf_it_ptr))
-
-            if ret != 0:
-                break
-
-        nbt._bt_ctf_iter_destroy(ctf_it_ptr)
-
-
-# Based on enum bt_clock_type in clock-type.h
-class _ClockType:
-    CLOCK_CYCLES = 0
-    CLOCK_REAL = 1
-
-
-class TraceHandle:
-    """
-    A :class:`TraceHandle` is a handle allowing the user to manipulate
-    a specific trace directly. It is a unique identifier representing a
-    trace, and is not meant to be instantiated by the user.
-    """
-
-    def __init__(self):
-        raise NotImplementedError("TraceHandle cannot be instantiated")
-
-    def __repr__(self):
-        return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
-
-    @property
-    def id(self):
-        """
-        Numeric ID of this trace handle.
-        """
-
-        return self._id
-
-    @property
-    def path(self):
-        """
-        Path of the underlying trace.
-        """
-
-        return nbt._bt_trace_handle_get_path(self._trace_collection._tc,
-                                             self._id)
-
-    @property
-    def timestamp_begin(self):
-        """
-        Buffers creation timestamp (nanoseconds since Epoch) of the
-        underlying trace.
-        """
-
-        ret, value = nbt._bt_trace_handle_get_timestamp_begin(
-            self._trace_collection._tc, self._id, _ClockType.CLOCK_REAL)
-        if ret != 0:
-            raise ValueError("Invalid TraceHandle")
-        return value
-
-    @property
-    def timestamp_end(self):
-        """
-        Buffers destruction timestamp (nanoseconds since Epoch) of the
-        underlying trace.
-        """
-
-        ret, value = nbt._bt_trace_handle_get_timestamp_end(
-            self._trace_collection._tc, self._id, _ClockType.CLOCK_REAL)
-        if ret != 0:
-            raise ValueError("Invalid TraceHandle")
-        return value
-
-    @property
-    def events(self):
-        """
-        Generates all the :class:`EventDeclaration` objects of the
-        underlying trace.
-        """
-
-        ret = nbt._bt_python_event_decl_listcaller(self.id,
-                                                   self._trace_collection._tc)
-
-        if not isinstance(ret, list):
-            return
-
-        ptr_list, count = ret
-
-        for i in range(count):
-            tmp = EventDeclaration.__new__(EventDeclaration)
-            tmp._ed = nbt._bt_python_decl_one_from_list(ptr_list, i)
-            yield tmp
-
-
-
-
-# Priority of the scopes when searching for event fields
-_scopes = [
-    common.CTFScope.EVENT_FIELDS,
-    common.CTFScope.EVENT_CONTEXT,
-    common.CTFScope.STREAM_EVENT_CONTEXT,
-    common.CTFScope.STREAM_EVENT_HEADER,
-    common.CTFScope.STREAM_PACKET_CONTEXT,
-    common.CTFScope.TRACE_PACKET_HEADER
-]
-
-
-class Event(collections.Mapping):
-    """
-    An :class:`Event` object represents a trace event. :class:`Event`
-    objects are returned by :attr:`TraceCollection.events` and are
-    not meant to be instantiated by the user.
-
-    :class:`Event` has a :class:`dict`-like interface for accessing
-    an event's field value by field name:
-
-    .. code-block:: python
-
-       event['my_field']
-
-    If a field name exists in multiple scopes, the value of the first
-    field found is returned. The scopes are searched in the following
-    order:
-
-    1. Event fields (:attr:`babeltrace.common.CTFScope.EVENT_FIELDS`)
-    2. Event context (:attr:`babeltrace.common.CTFScope.EVENT_CONTEXT`)
-    3. Stream event context (:attr:`babeltrace.common.CTFScope.STREAM_EVENT_CONTEXT`)
-    4. Event header (:attr:`babeltrace.common.CTFScope.STREAM_EVENT_HEADER`)
-    5. Packet context (:attr:`babeltrace.common.CTFScope.STREAM_PACKET_CONTEXT`)
-    6. Packet header (:attr:`babeltrace.common.CTFScope.TRACE_PACKET_HEADER`)
-
-    It is still possible to obtain a field's value from a specific
-    scope using :meth:`field_with_scope`.
-
-    Field values are returned as native Python types, that is:
-
-    +-----------------------+----------------------------------+
-    | Field type            | Python type                      |
-    +=======================+==================================+
-    | Integer               | :class:`int`                     |
-    +-----------------------+----------------------------------+
-    | Floating point number | :class:`float`                   |
-    +-----------------------+----------------------------------+
-    | Enumeration           | :class:`str` (enumeration label) |
-    +-----------------------+----------------------------------+
-    | String                | :class:`str`                     |
-    +-----------------------+----------------------------------+
-    | Array                 | :class:`list` of native Python   |
-    |                       | objects                          |
-    +-----------------------+----------------------------------+
-    | Sequence              | :class:`list` of native Python   |
-    |                       | objects                          |
-    +-----------------------+----------------------------------+
-    | Structure             | :class:`dict` mapping field      |
-    |                       | names to native Python objects   |
-    +-----------------------+----------------------------------+
-
-    For example, printing the third element of a sequence named ``seq``
-    in a structure named ``my_struct`` of the ``event``'s field named
-    ``my_field`` is done this way:
-
-    .. code-block:: python
-
-       print(event['my_field']['my_struct']['seq'][2])
-    """
-
-    def __init__(self):
-        raise NotImplementedError("Event cannot be instantiated")
-
-    @property
-    def name(self):
-        """
-        Event name or ``None`` on error.
-        """
-
-        return nbt._bt_ctf_event_name(self._e)
-
-    @property
-    def cycles(self):
-        """
-        Event timestamp in cycles or -1 on error.
-        """
-
-        return nbt._bt_ctf_get_cycles(self._e)
-
-    @property
-    def timestamp(self):
-        """
-        Event timestamp (nanoseconds since Epoch).
-        """
-
-        ret, value = nbt._bt_ctf_get_timestamp(self._e)
-        if ret < 0:
-            raise RuntimeError("Failed to get event timestamp")
-        return value
-
-    @property
-    def datetime(self):
-        """
-        Event timestamp as a standard :class:`datetime.datetime`
-        object.
-
-        Note that the :class:`datetime.datetime` class' precision
-        is limited to microseconds, whereas :attr:`timestamp` provides
-        the event's timestamp with a nanosecond resolution.
-        """
-
-        return datetime.fromtimestamp(self.timestamp / 1E9)
-
-    def field_with_scope(self, field_name, scope):
-        """
-        Returns the value of a field named *field_name* within the
-        scope *scope*, or ``None`` if the field cannot be found.
-
-        *scope* must be one of :class:`babeltrace.common.CTFScope`
-        constants.
-        """
-
-        if scope not in _scopes:
-            raise ValueError("Invalid scope provided")
-
-        field = self._field_with_scope(field_name, scope)
-
-        if field is not None:
-            return field.value
-
-    def field_list_with_scope(self, scope):
-        """
-        Returns a list of field names in the scope *scope*.
-        """
-
-        if scope not in _scopes:
-            raise ValueError("Invalid scope provided")
-
-        field_names = []
-
-        for field in self._field_list_with_scope(scope):
-            field_names.append(field.name)
-
-        return field_names
-
-    @property
-    def handle(self):
-        """
-        :class:`TraceHandle` object containing this event, or ``None``
-        on error.
-        """
-
-        ret = nbt._bt_ctf_event_get_handle_id(self._e)
-
-        if ret < 0:
-            return None
-
-        th = TraceHandle.__new__(TraceHandle)
-        th._id = ret
-        th._trace_collection = self.get_trace_collection()
-
-        return th
-
-    @property
-    def trace_collection(self):
-        """
-        :class:`TraceCollection` object containing this event, or
-        ``None`` on error.
-        """
-
-        trace_collection = TraceCollection()
-        trace_collection._tc = nbt._bt_ctf_event_get_context(self._e)
-
-        if trace_collection._tc is not None:
-            return trace_collection
-
-    def __getitem__(self, field_name):
-        field = self._field(field_name)
-
-        if field is not None:
-            return field.value
-
-        raise KeyError(field_name)
-
-    def __iter__(self):
-        for key in self.keys():
-            yield key
-
-    def __len__(self):
-        count = 0
-
-        for scope in _scopes:
-            scope_ptr = nbt._bt_ctf_get_top_level_scope(self._e, scope)
-            ret = nbt._bt_python_field_listcaller(self._e, scope_ptr)
-
-            if isinstance(ret, list):
-                count += ret[1]
-
-        return count
-
-    def __contains__(self, field_name):
-        return self._field(field_name) is not None
-
-    def keys(self):
-        """
-        Returns the list of field names.
-
-        Note: field names are unique within the returned list, although
-        a field name could exist in multiple scopes. Use
-        :meth:`field_list_with_scope` to obtain the list of field names
-        of a given scope.
-        """
-
-        field_names = set()
-
-        for scope in _scopes:
-            for name in self.field_list_with_scope(scope):
-                field_names.add(name)
-
-        return list(field_names)
-
-    def get(self, field_name, default=None):
-        """
-        Returns the value of the field named *field_name*, or *default*
-        when not found.
-
-        See :class:`Event` note about how fields are retrieved by
-        name when multiple fields share the same name in different
-        scopes.
-        """
-
-        field = self._field(field_name)
-
-        if field is None:
-            return default
-
-        return field.value
-
-    def items(self):
-        """
-        Generates pairs of (field name, field value).
-
-        This method iterates :meth:`keys` to find field names, which
-        means some fields could be unavailable if other fields share
-        their names in scopes with higher priorities.
-        """
-
-        for field in self.keys():
-            yield (field, self[field])
-
-    def _field_with_scope(self, field_name, scope):
-        scope_ptr = nbt._bt_ctf_get_top_level_scope(self._e, scope)
-
-        if scope_ptr is None:
-            return None
-
-        definition_ptr = nbt._bt_ctf_get_field(self._e, scope_ptr, field_name)
-
-        if definition_ptr is None:
-            return None
-
-        field = _Definition(definition_ptr, scope)
-
-        return field
-
-    def _field(self, field_name):
-        field = None
-
-        for scope in _scopes:
-            field = self._field_with_scope(field_name, scope)
-
-            if field is not None:
-                break
-
-        return field
-
-    def _field_list_with_scope(self, scope):
-        fields = []
-        scope_ptr = nbt._bt_ctf_get_top_level_scope(self._e, scope)
-
-        # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
-        # provide the "count" return value
-        count = 0
-        list_ptr = None
-        ret = nbt._bt_python_field_listcaller(self._e, scope_ptr)
-
-        if isinstance(ret, list):
-            list_ptr, count = ret
-
-        for i in range(count):
-            definition_ptr = nbt._bt_python_field_one_from_list(list_ptr, i)
-
-            if definition_ptr is not None:
-                definition = _Definition(definition_ptr, scope)
-                fields.append(definition)
-
-        return fields
-
-
-class FieldError(Exception):
-    """
-    Field error, raised when the value of a field cannot be accessed.
-    """
-
-    def __init__(self, value):
-        self.value = value
-
-    def __str__(self):
-        return repr(self.value)
-
-
-class EventDeclaration:
-    """
-    An event declaration contains the properties of a class of events,
-    that is, the common properties and fields layout of all the actual
-    recorded events associated with this declaration.
-
-    This class is not meant to be instantiated by the user. It is
-    returned by :attr:`TraceHandle.events`.
-    """
-
-    MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
-
-    def __init__(self):
-        raise NotImplementedError("EventDeclaration cannot be instantiated")
-
-    @property
-    def name(self):
-        """
-        Event name, or ``None`` on error.
-        """
-
-        return nbt._bt_ctf_get_decl_event_name(self._ed)
-
-    @property
-    def id(self):
-        """
-        Event numeric ID, or -1 on error.
-        """
-
-        id = nbt._bt_ctf_get_decl_event_id(self._ed)
-
-        if id == self.MAX_UINT64:
-            id = -1
-
-        return id
-
-    @property
-    def fields(self):
-        """
-        Generates all the field declarations of this event, going
-        through each scope in the following order:
-
-        1. Event fields (:attr:`babeltrace.common.CTFScope.EVENT_FIELDS`)
-        2. Event context (:attr:`babeltrace.common.CTFScope.EVENT_CONTEXT`)
-        3. Stream event context (:attr:`babeltrace.common.CTFScope.STREAM_EVENT_CONTEXT`)
-        4. Event header (:attr:`babeltrace.common.CTFScope.STREAM_EVENT_HEADER`)
-        5. Packet context (:attr:`babeltrace.common.CTFScope.STREAM_PACKET_CONTEXT`)
-        6. Packet header (:attr:`babeltrace.common.CTFScope.TRACE_PACKET_HEADER`)
-
-        All the generated field declarations inherit
-        :class:`FieldDeclaration`, and are among:
-
-        * :class:`IntegerFieldDeclaration`
-        * :class:`FloatFieldDeclaration`
-        * :class:`EnumerationFieldDeclaration`
-        * :class:`StringFieldDeclaration`
-        * :class:`ArrayFieldDeclaration`
-        * :class:`SequenceFieldDeclaration`
-        * :class:`StructureFieldDeclaration`
-        * :class:`VariantFieldDeclaration`
-        """
-
-        for scope in _scopes:
-            for declaration in self.fields_scope(scope):
-                yield declaration
-
-    def fields_scope(self, scope):
-        """
-        Generates all the field declarations of the event's scope
-        *scope*.
-
-        *scope* must be one of :class:`babeltrace.common.CTFScope` constants.
-
-        All the generated field declarations inherit
-        :class:`FieldDeclaration`, and are among:
-
-        * :class:`IntegerFieldDeclaration`
-        * :class:`FloatFieldDeclaration`
-        * :class:`EnumerationFieldDeclaration`
-        * :class:`StringFieldDeclaration`
-        * :class:`ArrayFieldDeclaration`
-        * :class:`SequenceFieldDeclaration`
-        * :class:`StructureFieldDeclaration`
-        * :class:`VariantFieldDeclaration`
-        """
-        ret = nbt._by_python_field_decl_listcaller(self._ed, scope)
-
-        if not isinstance(ret, list):
-            return
-
-        list_ptr, count = ret
-
-        for i in range(count):
-            field_decl_ptr = nbt._bt_python_field_decl_one_from_list(list_ptr, i)
-
-            if field_decl_ptr is not None:
-                decl_ptr = nbt._bt_ctf_get_decl_from_field_decl(field_decl_ptr)
-                name = nbt._bt_ctf_get_decl_field_name(field_decl_ptr)
-                field_declaration = _create_field_declaration(decl_ptr, name,
-                                                              scope)
-                yield field_declaration
-
-
-class FieldDeclaration:
-    """
-    Base class for concrete field declarations.
-
-    This class is not meant to be instantiated by the user.
-    """
-
-    def __init__(self):
-        raise NotImplementedError("FieldDeclaration cannot be instantiated")
-
-    def __repr__(self):
-        return "({0}) {1} {2}".format(common.CTFScope.scope_name(self.scope),
-                                      common.CTFTypeId.type_name(self.type),
-                                      self.name)
-
-    @property
-    def name(self):
-        """
-        Field name, or ``None`` on error.
-        """
-
-        return self._name
-
-    @property
-    def type(self):
-        """
-        Field type (one of :class:`babeltrace.common.CTFTypeId`
-        constants).
-        """
-
-        return nbt._bt_ctf_field_type(self._fd)
-
-    @property
-    def scope(self):
-        """
-        Field scope (one of:class:`babeltrace.common.CTFScope`
-        constants).
-        """
-
-        return self._s
-
-
-class IntegerFieldDeclaration(FieldDeclaration):
-    """
-    Integer field declaration.
-    """
-
-    def __init__(self):
-        raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
-
-    @property
-    def signedness(self):
-        """
-        0 if this integer is unsigned, 1 if signed, or -1 on error.
-        """
-
-        return nbt._bt_ctf_get_int_signedness(self._fd)
-
-    @property
-    def base(self):
-        """
-        Integer base (:class:`int`), or a negative value on error.
-        """
-
-        return nbt._bt_ctf_get_int_base(self._fd)
-
-    @property
-    def byte_order(self):
-        """
-        Integer byte order (one of
-        :class:`babeltrace.common.ByteOrder` constants).
-        """
-
-        ret = nbt._bt_ctf_get_int_byte_order(self._fd)
-
-        if ret == 1234:
-            return common.ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
-        elif ret == 4321:
-            return common.ByteOrder.BYTE_ORDER_BIG_ENDIAN
-        else:
-            return common.ByteOrder.BYTE_ORDER_UNKNOWN
-
-    @property
-    def size(self):
-        """
-        Integer size in bits, or a negative value on error.
-        """
-        return nbt._bt_ctf_get_int_len(self._fd)
-
-    @property
-    def length(self):
-        return self.size
-
-    @property
-    def encoding(self):
-        """
-        Integer encoding (one of
-        :class:`babeltrace.common.CTFStringEncoding` constants).
-        """
-
-        return nbt._bt_ctf_get_encoding(self._fd)
-
-
-class EnumerationFieldDeclaration(FieldDeclaration):
-    """
-    Enumeration field declaration.
-
-    .. note::
-
-       As of this version, this class is missing some properties.
-    """
-
-    def __init__(self):
-        raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
-
-
-class ArrayFieldDeclaration(FieldDeclaration):
-    """
-    Static array field declaration.
-    """
-
-    def __init__(self):
-        raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
-
-    @property
-    def length(self):
-        """
-        Fixed length of this static array (number of contained
-        elements), or a negative value on error.
-        """
-
-        return nbt._bt_ctf_get_array_len(self._fd)
-
-    @property
-    def element_declaration(self):
-        """
-        Field declaration of the underlying element.
-        """
-
-        field_decl_ptr = nbt._bt_python_get_array_element_declaration(self._fd)
-
-        return _create_field_declaration(field_decl_ptr, "", self.scope)
-
-
-class SequenceFieldDeclaration(FieldDeclaration):
-    """
-    Sequence (dynamic array) field declaration.
-
-    .. note::
-
-       As of this version, this class is missing some properties.
-    """
-
-    def __init__(self):
-        raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
-
-    @property
-    def element_declaration(self):
-        """
-        Field declaration of the underlying element.
-        """
-
-        field_decl_ptr = nbt._bt_python_get_sequence_element_declaration(self._fd)
-
-        return _create_field_declaration(field_decl_ptr, "", self.scope)
-
-
-class FloatFieldDeclaration(FieldDeclaration):
-    """
-    Floating point number field declaration.
-
-    .. note::
-
-       As of this version, this class is missing some properties.
-    """
-
-    def __init__(self):
-        raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
-
-
-class StructureFieldDeclaration(FieldDeclaration):
-    """
-    Structure (ordered map of field names to field declarations) field
-    declaration.
-
-    .. note::
-
-       As of this version, this class is missing some properties.
-    """
-
-    def __init__(self):
-        raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
-
-
-class StringFieldDeclaration(FieldDeclaration):
-    """
-    String (NULL-terminated array of bytes) field declaration.
-
-    .. note::
-
-       As of this version, this class is missing some properties.
-    """
-
-    def __init__(self):
-        raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
-
-
-class VariantFieldDeclaration(FieldDeclaration):
-    """
-    Variant (dynamic selection between different types) field declaration.
-
-    .. note::
-
-       As of this version, this class is missing some properties.
-    """
-
-    def __init__(self):
-        raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
-
-
-def field_error():
-    """
-    Return the last error code encountered while
-    accessing a field and reset the error flag.
-    Return 0 if no error, a negative value otherwise.
-    """
-
-    return nbt._bt_ctf_field_get_error()
-
-
-def _create_field_declaration(declaration_ptr, name, scope):
-    """
-    Private field declaration factory.
-    """
-
-    if declaration_ptr is None:
-        raise ValueError("declaration_ptr must be valid")
-    if scope not in _scopes:
-        raise ValueError("Invalid scope provided")
-
-    type = nbt._bt_ctf_field_type(declaration_ptr)
-    declaration = None
-
-    if type == common.CTFTypeId.INTEGER:
-        declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
-    elif type == common.CTFTypeId.ENUM:
-        declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
-    elif type == common.CTFTypeId.ARRAY:
-        declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
-    elif type == common.CTFTypeId.SEQUENCE:
-        declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
-    elif type == common.CTFTypeId.FLOAT:
-        declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
-    elif type == common.CTFTypeId.STRUCT:
-        declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
-    elif type == common.CTFTypeId.STRING:
-        declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
-    elif type == common.CTFTypeId.VARIANT:
-        declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
-    else:
-        return declaration
-
-    declaration._fd = declaration_ptr
-    declaration._s = scope
-    declaration._name = name
-
-    return declaration
-
-
-class _Definition:
-    def __init__(self, definition_ptr, scope):
-        self._d = definition_ptr
-        self._s = scope
-
-        if scope not in _scopes:
-            ValueError("Invalid scope provided")
-
-    @property
-    def name(self):
-        """Return the name of a field or None on error."""
-
-        return nbt._bt_ctf_field_name(self._d)
-
-    @property
-    def type(self):
-        """Return the type of a field or -1 if unknown."""
-
-        return nbt._bt_ctf_field_type(nbt._bt_ctf_get_decl_from_def(self._d))
-
-    @property
-    def declaration(self):
-        """Return the associated Definition object."""
-
-        return _create_field_declaration(
-            nbt._bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
-
-    def _get_enum_str(self):
-        """
-        Return the string matching the current enumeration.
-        Return None on error.
-        """
-
-        return nbt._bt_ctf_get_enum_str(self._d)
-
-    def _get_array_element_at(self, index):
-        """
-        Return the array's element at position index.
-        Return None on error
-        """
-
-        array_ptr = nbt._bt_python_get_array_from_def(self._d)
-
-        if array_ptr is None:
-            return None
-
-        definition_ptr = nbt._bt_array_index(array_ptr, index)
-
-        if definition_ptr is None:
-            return None
-
-        return _Definition(definition_ptr, self.scope)
-
-    def _get_sequence_len(self):
-        """
-        Return the len of a sequence or a negative
-        value on error.
-        """
-
-        seq = nbt._bt_python_get_sequence_from_def(self._d)
-
-        return nbt._bt_sequence_len(seq)
-
-    def _get_sequence_element_at(self, index):
-        """
-        Return the sequence's element at position index,
-        otherwise return None
-        """
-
-        seq = nbt._bt_python_get_sequence_from_def(self._d)
-
-        if seq is not None:
-            definition_ptr = nbt._bt_sequence_index(seq, index)
-
-            if definition_ptr is not None:
-                return _Definition(definition_ptr, self.scope)
-
-    def _get_uint64(self):
-        """
-        Return the value associated with the field.
-        If the field does not exist or is not of the type requested,
-        the value returned is undefined. To check if an error occured,
-        use the field_error() function after accessing a field.
-        """
-
-        return nbt._bt_ctf_get_uint64(self._d)
-
-    def _get_int64(self):
-        """
-        Return the value associated with the field.
-        If the field does not exist or is not of the type requested,
-        the value returned is undefined. To check if an error occured,
-        use the field_error() function after accessing a field.
-        """
-
-        return nbt._bt_ctf_get_int64(self._d)
-
-    def _get_char_array(self):
-        """
-        Return the value associated with the field.
-        If the field does not exist or is not of the type requested,
-        the value returned is undefined. To check if an error occurred,
-        use the field_error() function after accessing a field.
-        """
-
-        return nbt._bt_ctf_get_char_array(self._d)
-
-    def _get_str(self):
-        """
-        Return the value associated with the field.
-        If the field does not exist or is not of the type requested,
-        the value returned is undefined. To check if an error occurred,
-        use the field_error() function after accessing a field.
-        """
-
-        return nbt._bt_ctf_get_string(self._d)
-
-    def _get_float(self):
-        """
-        Return the value associated with the field.
-        If the field does not exist or is not of the type requested,
-        the value returned is undefined. To check if an error occurred,
-        use the field_error() function after accessing a field.
-        """
-
-        return nbt._bt_ctf_get_float(self._d)
-
-    def _get_variant(self):
-        """
-        Return the variant's selected field.
-        If the field does not exist or is not of the type requested,
-        the value returned is undefined. To check if an error occurred,
-        use the field_error() function after accessing a field.
-        """
-
-        return nbt._bt_ctf_get_variant(self._d)
-
-    def _get_struct_field_count(self):
-        """
-        Return the number of fields contained in the structure.
-        If the field does not exist or is not of the type requested,
-        the value returned is undefined.
-        """
-
-        return nbt._bt_ctf_get_struct_field_count(self._d)
-
-    def _get_struct_field_at(self, i):
-        """
-        Return the structure's field at position i.
-        If the field does not exist or is not of the type requested,
-        the value returned is undefined. To check if an error occurred,
-        use the field_error() function after accessing a field.
-        """
-
-        return nbt._bt_ctf_get_struct_field_index(self._d, i)
-
-    @property
-    def value(self):
-        """
-        Return the value associated with the field according to its type.
-        Return None on error.
-        """
-
-        id = self.type
-        value = None
-
-        if id == common.CTFTypeId.STRING:
-            value = self._get_str()
-        elif id == common.CTFTypeId.ARRAY:
-            element_decl = self.declaration.element_declaration
-
-            if ((element_decl.type == common.CTFTypeId.INTEGER
-                    and element_decl.length == 8)
-                    and (element_decl.encoding == common.CTFStringEncoding.ASCII or element_decl.encoding == common.CTFStringEncoding.UTF8)):
-                value = nbt._bt_python_get_array_string(self._d)
-            else:
-                value = []
-
-                for i in range(self.declaration.length):
-                    element = self._get_array_element_at(i)
-                    value.append(element.value)
-        elif id == common.CTFTypeId.INTEGER:
-            if self.declaration.signedness == 0:
-                value = self._get_uint64()
-            else:
-                value = self._get_int64()
-        elif id == common.CTFTypeId.ENUM:
-            value = self._get_enum_str()
-        elif id == common.CTFTypeId.SEQUENCE:
-            element_decl = self.declaration.element_declaration
-
-            if ((element_decl.type == common.CTFTypeId.INTEGER
-                    and element_decl.length == 8)
-                    and (element_decl.encoding == common.CTFStringEncoding.ASCII or element_decl.encoding == common.CTFStringEncoding.UTF8)):
-                value = nbt._bt_python_get_sequence_string(self._d)
-            else:
-                seq_len = self._get_sequence_len()
-                value = []
-
-                for i in range(seq_len):
-                    evDef = self._get_sequence_element_at(i)
-                    value.append(evDef.value)
-        elif id == common.CTFTypeId.FLOAT:
-            value = self._get_float()
-        elif id == common.CTFTypeId.VARIANT:
-            variant = _Definition.__new__(_Definition)
-            variant._d = self._get_variant()
-            value = variant.value
-        elif id == common.CTFTypeId.STRUCT:
-            value = {}
-
-            for i in range(self._get_struct_field_count()):
-                member = _Definition(self._get_struct_field_at(i), self.scope)
-                value[member.name] = member.value
-
-        if field_error():
-            raise FieldError(
-                "Error occurred while accessing field {} of type {}".format(
-                    self.name,
-                    common.CTFTypeId.type_name(id)))
-
-        return value
-
-    @property
-    def scope(self):
-        """Return the scope of a field or None on error."""
-
-        return self._s
diff --git a/bindings/python/writer.py b/bindings/python/writer.py
deleted file mode 100644 (file)
index dc65b24..0000000
+++ /dev/null
@@ -1,2147 +0,0 @@
-# writer.py
-#
-# Babeltrace writer interface Python module
-#
-# Copyright 2012-2015 EfficiOS Inc.
-#
-# Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-import babeltrace.nativebt as nbt
-import babeltrace.common as common
-from uuid import UUID
-
-
-# Used to compare to -1ULL in error checks
-_MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
-
-
-class EnumerationMapping:
-    """
-    Mapping from an enumeration label to a range of integers.
-    """
-
-    def __init__(self, name, start, end):
-        """
-        Creates an enumeration mapping, where label *name* is mapped to
-        the [*start*, *end*] range of integers (*end* is included).
-
-        Set *start* and *end* to the same value to create an enumeration
-        mapping to a single value.
-        """
-
-        self.name = name
-        self.start = start
-        self.end = end
-
-
-class Clock:
-    """
-    A CTF clock allows the description of the system's clock topology, as
-    well as the definition of each clock's parameters.
-
-    :class:`Clock` objects must be registered to a :class:`Writer`
-    object (see :meth:`Writer.add_clock`), as well as be registered to
-    a :class:`StreamClass` object (see :attr:`StreamClass.clock`).
-    """
-
-    def __init__(self, name):
-        """
-        Creates a default CTF clock named *name*.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        self._c = nbt._bt_ctf_clock_create(name)
-
-        if self._c is None:
-            raise ValueError("Invalid clock name.")
-
-    def __del__(self):
-        nbt._bt_ctf_clock_put(self._c)
-
-    @property
-    def name(self):
-        """
-        Clock name.
-
-        Set this attribute to change the clock's name.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        name = nbt._bt_ctf_clock_get_name(self._c)
-
-        if name is None:
-            raise ValueError("Invalid clock instance.")
-
-        return name
-
-    @property
-    def description(self):
-        """
-        Clock description (string).
-
-        Set this attribute to change the clock's description.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        return nbt._bt_ctf_clock_get_description(self._c)
-
-    @description.setter
-    def description(self, desc):
-        ret = nbt._bt_ctf_clock_set_description(self._c, str(desc))
-
-        if ret < 0:
-            raise ValueError("Invalid clock description.")
-
-    @property
-    def frequency(self):
-        """
-        Clock frequency in Hz (integer).
-
-        Set this attribute to change the clock's frequency.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        freq = nbt._bt_ctf_clock_get_frequency(self._c)
-
-        if freq == _MAX_UINT64:
-            raise ValueError("Invalid clock instance")
-
-        return freq
-
-    @frequency.setter
-    def frequency(self, freq):
-        ret = nbt._bt_ctf_clock_set_frequency(self._c, freq)
-
-        if ret < 0:
-            raise ValueError("Invalid frequency value.")
-
-    @property
-    def precision(self):
-        """
-        Clock precision in clock ticks (integer).
-
-        Set this attribute to change the clock's precision.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        precision = nbt._bt_ctf_clock_get_precision(self._c)
-
-        if precision == _MAX_UINT64:
-            raise ValueError("Invalid clock instance")
-
-        return precision
-
-    @precision.setter
-    def precision(self, precision):
-        ret = nbt._bt_ctf_clock_set_precision(self._c, precision)
-
-        if ret < 0:
-            raise ValueError("Invalid precision value.")
-
-    @property
-    def offset_seconds(self):
-        """
-        Clock offset in seconds since POSIX.1 Epoch (integer).
-
-        Set this attribute to change the clock's offset in seconds.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret, offset_s = nbt._bt_ctf_clock_get_offset_s(self._c)
-
-        if ret < 0:
-            raise ValueError("Invalid clock instance")
-
-        return offset_s
-
-    @offset_seconds.setter
-    def offset_seconds(self, offset_s):
-        ret = nbt._bt_ctf_clock_set_offset_s(self._c, offset_s)
-
-        if ret < 0:
-            raise ValueError("Invalid offset value.")
-
-    @property
-    def offset(self):
-        """
-        Clock offset in ticks since (POSIX.1 Epoch +
-        :attr:`offset_seconds`).
-
-        Set this attribute to change the clock's offset.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret, offset = nbt._bt_ctf_clock_get_offset(self._c)
-
-        if ret < 0:
-            raise ValueError("Invalid clock instance")
-
-        return offset
-
-    @offset.setter
-    def offset(self, offset):
-        ret = nbt._bt_ctf_clock_set_offset(self._c, offset)
-
-        if ret < 0:
-            raise ValueError("Invalid offset value.")
-
-    @property
-    def absolute(self):
-        """
-        ``True`` if this clock is absolute, i.e. if the clock is a
-        global reference across the other clocks of the trace.
-
-        Set this attribute to change the clock's absolute state
-        (boolean).
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        is_absolute = nbt._bt_ctf_clock_get_is_absolute(self._c)
-
-        if is_absolute == -1:
-            raise ValueError("Invalid clock instance")
-
-        return False if is_absolute == 0 else True
-
-    @absolute.setter
-    def absolute(self, is_absolute):
-        ret = nbt._bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
-
-        if ret < 0:
-            raise ValueError("Could not set the clock absolute attribute.")
-
-    @property
-    def uuid(self):
-        """
-        Clock UUID (an :class:`uuid.UUID` object).
-
-        Set this attribute to change the clock's UUID.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        uuid_list = []
-
-        for i in range(16):
-            ret, value = nbt._bt_python_ctf_clock_get_uuid_index(self._c, i)
-
-            if ret < 0:
-                raise ValueError("Invalid clock instance")
-
-            uuid_list.append(value)
-
-        return UUID(bytes=bytes(uuid_list))
-
-    @uuid.setter
-    def uuid(self, uuid):
-        uuid_bytes = uuid.bytes
-
-        if len(uuid_bytes) != 16:
-            raise ValueError("Invalid UUID provided. UUID length must be 16 bytes")
-
-        for i in range(len(uuid_bytes)):
-            ret = nbt._bt_python_ctf_clock_set_uuid_index(self._c, i,
-                                                          uuid_bytes[i])
-
-            if ret < 0:
-                raise ValueError("Invalid clock instance")
-
-    @property
-    def time(self):
-        """
-        Clock current time; nanoseconds (integer) since clock origin
-        (POSIX.1 Epoch + :attr:`offset_seconds` + :attr:`offset`).
-
-        Set this attribute to change the clock's current time.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret, time = nbt._bt_ctf_clock_get_time(self._c)
-
-        if ret < 0:
-            raise ValueError("Invalid clock instance")
-
-        return time
-
-    @time.setter
-    def time(self, time):
-        ret = nbt._bt_ctf_clock_set_time(self._c, time)
-
-        if ret < 0:
-            raise ValueError("Invalid time value.")
-
-
-class IntegerBase:
-    """
-    Display base of an integer.
-    """
-
-    #: Unknown
-    UNKNOWN = -1
-
-    #: Binary
-    BIN = 2
-
-    #: Octal
-    OCT = 8
-
-    #: Decimal
-    DEC = 10
-
-    #: Hexadecimal
-    HEX = 16
-
-    # keep this for backward compatibility
-    INTEGER_BASE_UNKNOWN = -1
-    INTEGER_BASE_BINARY = 2
-    INTEGER_BASE_OCTAL = 8
-    INTEGER_BASE_DECIMAL = 10
-    INTEGER_BASE_HEXADECIMAL = 16
-
-
-class FieldDeclaration:
-    """
-    Base class of all field declarations. This class is not meant to
-    be instantiated by the user; use one of the concrete field
-    declaration subclasses instead.
-    """
-
-    class IntegerBase(IntegerBase):
-        pass
-
-    def __init__(self):
-        if self._ft is None:
-            raise ValueError("FieldDeclaration creation failed.")
-
-    def __del__(self):
-        nbt._bt_ctf_field_type_put(self._ft)
-
-    @staticmethod
-    def _create_field_declaration_from_native_instance(
-            native_field_declaration):
-        type_dict = {
-            common.CTFTypeId.INTEGER: IntegerFieldDeclaration,
-            common.CTFTypeId.FLOAT: FloatFieldDeclaration,
-            common.CTFTypeId.ENUM: EnumerationFieldDeclaration,
-            common.CTFTypeId.STRING: StringFieldDeclaration,
-            common.CTFTypeId.STRUCT: StructureFieldDeclaration,
-            common.CTFTypeId.VARIANT: VariantFieldDeclaration,
-            common.CTFTypeId.ARRAY: ArrayFieldDeclaration,
-            common.CTFTypeId.SEQUENCE: SequenceFieldDeclaration
-        }
-
-        field_type_id = nbt._bt_ctf_field_type_get_type_id(native_field_declaration)
-
-        if field_type_id == common.CTFTypeId.UNKNOWN:
-            raise TypeError("Invalid field instance")
-
-        declaration = Field.__new__(Field)
-        declaration._ft = native_field_declaration
-        declaration.__class__ = type_dict[field_type_id]
-
-        return declaration
-
-    @property
-    def alignment(self):
-        """
-        Field alignment in bits (integer).
-
-        Set this attribute to change this field's alignment.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        return nbt._bt_ctf_field_type_get_alignment(self._ft)
-
-    @alignment.setter
-    def alignment(self, alignment):
-        ret = nbt._bt_ctf_field_type_set_alignment(self._ft, alignment)
-
-        if ret < 0:
-            raise ValueError("Invalid alignment value.")
-
-    @property
-    def byte_order(self):
-        """
-        Field byte order (one of :class:`babeltrace.common.ByteOrder`
-        constants).
-
-        Set this attribute to change this field's byte order.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        return nbt._bt_ctf_field_type_get_byte_order(self._ft)
-
-    @byte_order.setter
-    def byte_order(self, byte_order):
-        ret = nbt._bt_ctf_field_type_set_byte_order(self._ft, byte_order)
-
-        if ret < 0:
-            raise ValueError("Could not set byte order value.")
-
-
-class IntegerFieldDeclaration(FieldDeclaration):
-    """
-    Integer field declaration.
-    """
-
-    def __init__(self, size):
-        """
-        Creates an integer field declaration of size *size* bits.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        self._ft = nbt._bt_ctf_field_type_integer_create(size)
-        super().__init__()
-
-    @property
-    def size(self):
-        """
-        Integer size in bits (integer).
-
-        Set this attribute to change this integer's size.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_integer_get_size(self._ft)
-
-        if ret < 0:
-            raise ValueError("Could not get Integer size attribute.")
-        else:
-            return ret
-
-    @property
-    def signed(self):
-        """
-        ``True`` if this integer is signed.
-
-        Set this attribute to change this integer's signedness
-        (boolean).
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_integer_get_signed(self._ft)
-
-        if ret < 0:
-            raise ValueError("Could not get Integer signed attribute.")
-        elif ret > 0:
-            return True
-        else:
-            return False
-
-    @signed.setter
-    def signed(self, signed):
-        ret = nbt._bt_ctf_field_type_integer_set_signed(self._ft, signed)
-
-        if ret < 0:
-            raise ValueError("Could not set Integer signed attribute.")
-
-    @property
-    def base(self):
-        """
-        Integer display base (one of :class:`IntegerBase` constants).
-
-        Set this attribute to change this integer's display base.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        return nbt._bt_ctf_field_type_integer_get_base(self._ft)
-
-    @base.setter
-    def base(self, base):
-        ret = nbt._bt_ctf_field_type_integer_set_base(self._ft, base)
-
-        if ret < 0:
-            raise ValueError("Could not set Integer base.")
-
-    @property
-    def encoding(self):
-        """
-        Integer encoding (one of
-        :class:`babeltrace.common.CTFStringEncoding` constants).
-
-        Set this attribute to change this integer's encoding.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        return nbt._bt_ctf_field_type_integer_get_encoding(self._ft)
-
-    @encoding.setter
-    def encoding(self, encoding):
-        ret = nbt._bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
-
-        if ret < 0:
-            raise ValueError("Could not set Integer encoding.")
-
-
-class EnumerationFieldDeclaration(FieldDeclaration):
-    """
-    Enumeration field declaration. A CTF enumeration maps labels to
-    ranges of integers.
-    """
-
-    def __init__(self, integer_type):
-        """
-        Creates an enumeration field declaration, with *integer_type*
-        being the underlying :class:`IntegerFieldDeclaration` for storing
-        the integer.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        isinst = isinstance(integer_type, IntegerFieldDeclaration)
-
-        if integer_type is None or not isinst:
-            raise TypeError("Invalid integer container.")
-
-        self._ft = nbt._bt_ctf_field_type_enumeration_create(integer_type._ft)
-        super().__init__()
-
-    @property
-    def container(self):
-        """
-        Underlying container (:class:`IntegerFieldDeclaration`).
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_enumeration_get_container_type(self._ft)
-
-        if ret is None:
-            raise TypeError("Invalid enumeration declaration")
-
-        return FieldDeclaration._create_field_declaration_from_native_instance(ret)
-
-    def add_mapping(self, name, range_start, range_end):
-        """
-        Adds a mapping to the enumeration field declaration, from the
-        label named *name* to range [*range_start*, *range_end*], where
-        *range_start* and *range_end* are integers included in the
-        range.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        if range_start < 0 or range_end < 0:
-            ret = nbt._bt_ctf_field_type_enumeration_add_mapping(self._ft,
-                                                                 str(name),
-                                                                 range_start,
-                                                                 range_end)
-        else:
-            ret = nbt._bt_ctf_field_type_enumeration_add_mapping_unsigned(self._ft,
-                                                                          str(name),
-                                                                          range_start,
-                                                                          range_end)
-
-        if ret < 0:
-            raise ValueError("Could not add mapping to enumeration declaration.")
-
-    @property
-    def mappings(self):
-        """
-        Generates the mappings of this enumeration field declaration
-        (:class:`EnumerationMapping` objects).
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        signed = self.container.signed
-
-        count = nbt._bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
-
-        for i in range(count):
-            if signed:
-                ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping(self._ft, i)
-            else:
-                ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, i)
-
-            if len(ret) != 3:
-                msg = "Could not get Enumeration mapping at index {}".format(i)
-                raise TypeError(msg)
-
-            name, range_start, range_end = ret
-            yield EnumerationMapping(name, range_start, range_end)
-
-    def get_mapping_by_name(self, name):
-        """
-        Returns the :class:`EnumerationMapping` object for the label
-        named *name*.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        index = nbt._bt_ctf_field_type_enumeration_get_mapping_index_by_name(self._ft, name)
-
-        if index < 0:
-            return None
-
-        if self.container.signed:
-            ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
-        else:
-            ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
-
-        if len(ret) != 3:
-            msg = "Could not get Enumeration mapping at index {}".format(i)
-            raise TypeError(msg)
-
-        name, range_start, range_end = ret
-
-        return EnumerationMapping(name, range_start, range_end)
-
-    def get_mapping_by_value(self, value):
-        """
-        Returns the :class:`EnumerationMapping` object for the value
-        *value* (integer).
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        if value < 0:
-            index = nbt._bt_ctf_field_type_enumeration_get_mapping_index_by_value(self._ft, value)
-        else:
-            index = nbt._bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(self._ft, value)
-
-        if index < 0:
-            return None
-
-        if self.container.signed:
-            ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
-        else:
-            ret = nbt._bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
-
-        if len(ret) != 3:
-            msg = "Could not get Enumeration mapping at index {}".format(i)
-            raise TypeError(msg)
-
-        name, range_start, range_end = ret
-
-        return EnumerationMapping(name, range_start, range_end)
-
-
-class FloatingPointFieldDeclaration(FieldDeclaration):
-    """
-    Floating point number field declaration.
-
-    A CTF floating point number is a made of three sections: the sign
-    bit, the exponent bits, and the mantissa bits. The most significant
-    bit of the resulting binary word is the sign bit, and is included
-    in the number of mantissa bits.
-
-    For example, the
-    `IEEE 754 <http://en.wikipedia.org/wiki/IEEE_floating_point>`_
-    single precision floating point number is represented on a 32-bit
-    word using an 8-bit exponent (``e``) and a 24-bit mantissa (``m``),
-    the latter count including the sign bit (``s``)::
-
-        s eeeeeeee mmmmmmmmmmmmmmmmmmmmmmm
-
-    The IEEE 754 double precision floating point number uses an
-    11-bit exponent and a 53-bit mantissa.
-    """
-
-    #: IEEE 754 single precision floating point number exponent size
-    FLT_EXP_DIG = 8
-
-    #: IEEE 754 double precision floating point number exponent size
-    DBL_EXP_DIG = 11
-
-    #: IEEE 754 single precision floating point number mantissa size
-    FLT_MANT_DIG = 24
-
-    #: IEEE 754 double precision floating point number mantissa size
-    DBL_MANT_DIG = 53
-
-    def __init__(self):
-        """
-        Creates a floating point number field declaration.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        self._ft = nbt._bt_ctf_field_type_floating_point_create()
-        super().__init__()
-
-    @property
-    def exponent_digits(self):
-        """
-        Floating point number exponent section size in bits (integer).
-
-        Set this attribute to change the floating point number's
-        exponent section's size. You may use :attr:`FLT_EXP_DIG` or
-        :attr:`DBL_EXP_DIG` for IEEE 754 floating point numbers.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_floating_point_get_exponent_digits(self._ft)
-
-        if ret < 0:
-            raise TypeError(
-                "Could not get Floating point exponent digit count")
-
-        return ret
-
-    @exponent_digits.setter
-    def exponent_digits(self, exponent_digits):
-        ret = nbt._bt_ctf_field_type_floating_point_set_exponent_digits(self._ft,
-                                                                        exponent_digits)
-
-        if ret < 0:
-            raise ValueError("Could not set exponent digit count.")
-
-    @property
-    def mantissa_digits(self):
-        """
-        Floating point number mantissa section size in bits (integer).
-
-        Set this attribute to change the floating point number's
-        mantissa section's size. You may use :attr:`FLT_MANT_DIG` or
-        :attr:`DBL_MANT_DIG` for IEEE 754 floating point numbers.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_floating_point_get_mantissa_digits(self._ft)
-
-        if ret < 0:
-            raise TypeError("Could not get Floating point mantissa digit count")
-
-        return ret
-
-    @mantissa_digits.setter
-    def mantissa_digits(self, mantissa_digits):
-        ret = nbt._bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft,
-                                                                        mantissa_digits)
-
-        if ret < 0:
-            raise ValueError("Could not set mantissa digit count.")
-
-
-class FloatFieldDeclaration(FloatingPointFieldDeclaration):
-    pass
-
-
-class StructureFieldDeclaration(FieldDeclaration):
-    """
-    Structure field declaration, i.e. an ordered mapping from field
-    names to field declarations.
-    """
-
-    def __init__(self):
-        """
-        Creates an empty structure field declaration.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        self._ft = nbt._bt_ctf_field_type_structure_create()
-        super().__init__()
-
-    def add_field(self, field_type, field_name):
-        """
-        Appends one :class:`FieldDeclaration` *field_type* named
-        *field_name* to the structure's ordered map.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_structure_add_field(self._ft,
-                                                         field_type._ft,
-                                                         str(field_name))
-
-        if ret < 0:
-            raise ValueError("Could not add field to structure.")
-
-    @property
-    def fields(self):
-        """
-        Generates the (field name, :class:`FieldDeclaration`) pairs
-        of this structure.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        count = nbt._bt_ctf_field_type_structure_get_field_count(self._ft)
-
-        if count < 0:
-            raise TypeError("Could not get Structure field count")
-
-        for i in range(count):
-            field_name = nbt._bt_python_ctf_field_type_structure_get_field_name(self._ft, i)
-
-            if field_name is None:
-                msg = "Could not get Structure field name at index {}".format(i)
-                raise TypeError(msg)
-
-            field_type_native = nbt._bt_python_ctf_field_type_structure_get_field_type(self._ft, i)
-
-            if field_type_native is None:
-                msg = "Could not get Structure field type at index {}".format(i)
-                raise TypeError(msg)
-
-            field_type = FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
-            yield (field_name, field_type)
-
-    def get_field_by_name(self, name):
-        """
-        Returns the :class:`FieldDeclaration` mapped to the field name
-        *name* in this structure.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        field_type_native = nbt._bt_ctf_field_type_structure_get_field_type_by_name(self._ft, name)
-
-        if field_type_native is None:
-            msg = "Could not find Structure field with name {}".format(name)
-            raise TypeError(msg)
-
-        return FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
-
-
-class VariantFieldDeclaration(FieldDeclaration):
-    """
-    Variant field declaration.
-
-    A CTF variant is a dynamic selection between different fields.
-    The value of a *tag* (a CTF enumeration) determines what is the
-    current selected field. All the possible fields must be added to
-    its field declaration before using an actual variant field.
-    """
-
-    def __init__(self, enum_tag, tag_name):
-        """
-        Creates an empty variant field declaration with tag field
-        declaration *enum_tag* (instance of
-        :class:`EnumerationFieldDeclaration`) named *tag_name*
-        (string).
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        isinst = isinstance(enum_tag, EnumerationFieldDeclaration)
-        if enum_tag is None or not isinst:
-            raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
-
-        self._ft = nbt._bt_ctf_field_type_variant_create(enum_tag._ft,
-                                                         str(tag_name))
-        super().__init__()
-
-    @property
-    def tag_name(self):
-        """
-        Variant field declaration tag name.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_variant_get_tag_name(self._ft)
-
-        if ret is None:
-            raise TypeError("Could not get Variant tag name")
-
-        return ret
-
-    @property
-    def tag_type(self):
-        """
-        Variant field declaration tag field declaration
-        (:class:`EnumerationFieldDeclaration` object).
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_variant_get_tag_type(self._ft)
-
-        if ret is None:
-            raise TypeError("Could not get Variant tag type")
-
-        return FieldDeclaration._create_field_declaration_from_native_instance(ret)
-
-    def add_field(self, field_type, field_name):
-        """
-        Registers the :class:`FieldDeclaration` object *field_type*
-        as the variant's selected type when the variant's tag's current
-        label is *field_name*.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_variant_add_field(self._ft,
-                                                       field_type._ft,
-                                                       str(field_name))
-
-        if ret < 0:
-            raise ValueError("Could not add field to variant.")
-
-    @property
-    def fields(self):
-        """
-        Generates the (field name, :class:`FieldDeclaration`) pairs
-        of this variant field declaration.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        count = nbt._bt_ctf_field_type_variant_get_field_count(self._ft)
-
-        if count < 0:
-            raise TypeError("Could not get Variant field count")
-
-        for i in range(count):
-            field_name = nbt._bt_python_ctf_field_type_variant_get_field_name(self._ft, i)
-
-            if field_name is None:
-                msg = "Could not get Variant field name at index {}".format(i)
-                raise TypeError(msg)
-
-            field_type_native = nbt._bt_python_ctf_field_type_variant_get_field_type(self._ft, i)
-
-            if field_type_native is None:
-                msg = "Could not get Variant field type at index {}".format(i)
-                raise TypeError(msg)
-
-            field_type = FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
-            yield (field_name, field_type)
-
-    def get_field_by_name(self, name):
-        """
-        Returns the :class:`FieldDeclaration` selected when the
-        variant's tag's current label is *name*.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        field_type_native = nbt._bt_ctf_field_type_variant_get_field_type_by_name(self._ft,
-                                                                                  name)
-
-        if field_type_native is None:
-            msg = "Could not find Variant field with name {}".format(name)
-            raise TypeError(msg)
-
-        return FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
-
-    def get_field_from_tag(self, tag):
-        """
-        Returns the :class:`FieldDeclaration` selected by the current
-        label of the :class:`EnumerationField` *tag*.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        field_type_native = nbt._bt_ctf_field_type_variant_get_field_type_from_tag(self._ft, tag._f)
-
-        if field_type_native is None:
-            msg = "Could not find Variant field with tag value {}".format(tag.value)
-            raise TypeError(msg)
-
-        return FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
-
-
-class ArrayFieldDeclaration(FieldDeclaration):
-    """
-    Static array field declaration.
-    """
-
-    def __init__(self, element_type, length):
-        """
-        Creates a static array field declaration of *length*
-        elements of type *element_type* (:class:`FieldDeclaration`).
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        self._ft = nbt._bt_ctf_field_type_array_create(element_type._ft,
-                                                       length)
-        super().__init__()
-
-    @property
-    def element_type(self):
-        """
-        Type of the elements of this this static array (subclass of
-        :class:`FieldDeclaration`).
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_array_get_element_type(self._ft)
-
-        if ret is None:
-            raise TypeError("Could not get Array element type")
-
-        return FieldDeclaration._create_field_declaration_from_native_instance(ret)
-
-    @property
-    def length(self):
-        """
-        Length of this static array (integer).
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_array_get_length(self._ft)
-
-        if ret < 0:
-            raise TypeError("Could not get Array length")
-
-        return ret
-
-
-class SequenceFieldDeclaration(FieldDeclaration):
-    """
-    Sequence (dynamic array) field declaration.
-    """
-
-    def __init__(self, element_type, length_field_name):
-        """
-        Creates a sequence field declaration of
-        elements of type *element_type* (:class:`FieldDeclaration`).
-        The length of a sequence field based on this sequence field
-        declaration is obtained by retrieving the dynamic integer
-        value of the field named *length_field_name*.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        self._ft = nbt._bt_ctf_field_type_sequence_create(element_type._ft,
-                                                          str(length_field_name))
-        super().__init__()
-
-    @property
-    def element_type(self):
-        """
-        Type of the elements of this sequence (subclass of
-        :class:`FieldDeclaration`).
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_sequence_get_element_type(self._ft)
-
-        if ret is None:
-            raise TypeError("Could not get Sequence element type")
-
-        return FieldDeclaration._create_field_declaration_from_native_instance(ret)
-
-    @property
-    def length_field_name(self):
-        """
-        Name of the integer field defining the dynamic length of
-        sequence fields based on this sequence field declaration.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_field_type_sequence_get_length_field_name(self._ft)
-
-        if ret is None:
-            raise TypeError("Could not get Sequence length field name")
-
-        return ret
-
-
-class StringFieldDeclaration(FieldDeclaration):
-    """
-    String (NULL-terminated array of bytes) field declaration.
-    """
-
-    def __init__(self):
-        """
-        Creates a string field declaration.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        self._ft = nbt._bt_ctf_field_type_string_create()
-        super().__init__()
-
-    @property
-    def encoding(self):
-        """
-        String encoding (one of
-        :class:`babeltrace.common.CTFStringEncoding` constants).
-
-        Set this attribute to change this string's encoding.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        return nbt._bt_ctf_field_type_string_get_encoding(self._ft)
-
-    @encoding.setter
-    def encoding(self, encoding):
-        ret = nbt._bt_ctf_field_type_string_set_encoding(self._ft, encoding)
-        if ret < 0:
-            raise ValueError("Could not set string encoding.")
-
-
-@staticmethod
-def create_field(field_type):
-    """
-    Create an instance of a field.
-    """
-    isinst = isinstance(field_type, FieldDeclaration)
-
-    if field_type is None or not isinst:
-        raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
-
-    if isinstance(field_type, IntegerFieldDeclaration):
-        return IntegerField(field_type)
-    elif isinstance(field_type, EnumerationFieldDeclaration):
-        return EnumerationField(field_type)
-    elif isinstance(field_type, FloatFieldDeclaration):
-        return FloatingPointField(field_type)
-    elif isinstance(field_type, StructureFieldDeclaration):
-        return StructureField(field_type)
-    elif isinstance(field_type, VariantFieldDeclaration):
-        return VariantField(field_type)
-    elif isinstance(field_type, ArrayFieldDeclaration):
-        return ArrayField(field_type)
-    elif isinstance(field_type, SequenceFieldDeclaration):
-        return SequenceField(field_type)
-    elif isinstance(field_type, StringFieldDeclaration):
-        return StringField(field_type)
-
-
-class Field:
-    """
-    Base class of all fields. This class is not meant to be
-    instantiated by the user, and neither are its subclasses. Use
-    :meth:`Event.payload` to access specific, concrete fields of
-    an event.
-    """
-
-    def __init__(self, field_type):
-        if not isinstance(field_type, FieldDeclaration):
-            raise TypeError("Invalid field_type argument.")
-
-        self._f = nbt._bt_ctf_field_create(field_type._ft)
-
-        if self._f is None:
-            raise ValueError("Field creation failed.")
-
-    def __del__(self):
-        nbt._bt_ctf_field_put(self._f)
-
-    @staticmethod
-    def _create_field_from_native_instance(native_field_instance):
-        type_dict = {
-            common.CTFTypeId.INTEGER: IntegerField,
-            common.CTFTypeId.FLOAT: FloatingPointField,
-            common.CTFTypeId.ENUM: EnumerationField,
-            common.CTFTypeId.STRING: StringField,
-            common.CTFTypeId.STRUCT: StructureField,
-            common.CTFTypeId.VARIANT: VariantField,
-            common.CTFTypeId.ARRAY: ArrayField,
-            common.CTFTypeId.SEQUENCE: SequenceField
-        }
-
-        field_type = nbt._bt_python_get_field_type(native_field_instance)
-
-        if field_type == common.CTFTypeId.UNKNOWN:
-            raise TypeError("Invalid field instance")
-
-        field = Field.__new__(Field)
-        field._f = native_field_instance
-        field.__class__ = type_dict[field_type]
-
-        return field
-
-    @property
-    def declaration(self):
-        """
-        Field declaration (subclass of :class:`FieldDeclaration`).
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        native_field_type = nbt._bt_ctf_field_get_type(self._f)
-
-        if native_field_type is None:
-            raise TypeError("Invalid field instance")
-        return FieldDeclaration._create_field_declaration_from_native_instance(
-            native_field_type)
-
-
-class IntegerField(Field):
-    """
-    Integer field, based on an :class:`IntegerFieldDeclaration` object.
-    """
-
-    @property
-    def value(self):
-        """
-        Integer value (:class:`int`).
-
-        Set this attribute to change the integer field's value.
-
-        :exc:`ValueError` or :exc:`TypeError` are raised on error.
-        """
-
-        signedness = nbt._bt_python_field_integer_get_signedness(self._f)
-
-        if signedness < 0:
-            raise TypeError("Invalid integer instance.")
-
-        if signedness == 0:
-            ret, value = nbt._bt_ctf_field_unsigned_integer_get_value(self._f)
-        else:
-            ret, value = nbt._bt_ctf_field_signed_integer_get_value(self._f)
-
-        if ret < 0:
-            raise ValueError("Could not get integer field value.")
-
-        return value
-
-    @value.setter
-    def value(self, value):
-        if not isinstance(value, int):
-            raise TypeError("IntegerField's value must be an int")
-
-        signedness = nbt._bt_python_field_integer_get_signedness(self._f)
-        if signedness < 0:
-            raise TypeError("Invalid integer instance.")
-
-        if signedness == 0:
-            ret = nbt._bt_ctf_field_unsigned_integer_set_value(self._f, value)
-        else:
-            ret = nbt._bt_ctf_field_signed_integer_set_value(self._f, value)
-
-        if ret < 0:
-            raise ValueError("Could not set integer field value.")
-
-
-class EnumerationField(Field):
-    """
-    Enumeration field, based on an
-    :class:`EnumerationFieldDeclaration` object.
-    """
-
-    @property
-    def container(self):
-        """
-        Underlying container (:class:`IntegerField`).
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        container = IntegerField.__new__(IntegerField)
-        container._f = nbt._bt_ctf_field_enumeration_get_container(self._f)
-
-        if container._f is None:
-            raise TypeError("Invalid enumeration field type.")
-
-        return container
-
-    @property
-    def value(self):
-        """
-        Current label of this enumeration field (:class:`str`).
-
-        Set this attribute to an integer (:class:`int`) to change the
-        enumeration field's value.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        value = nbt._bt_ctf_field_enumeration_get_mapping_name(self._f)
-
-        if value is None:
-            raise ValueError("Could not get enumeration mapping name.")
-
-        return value
-
-    @value.setter
-    def value(self, value):
-        if not isinstance(value, int):
-            raise TypeError("EnumerationField value must be an int")
-
-        self.container.value = value
-
-
-class FloatingPointField(Field):
-    """
-    Floating point number field, based on a
-    :class:`FloatingPointFieldDeclaration` object.
-    """
-
-    @property
-    def value(self):
-        """
-        Floating point number value (:class:`float`).
-
-        Set this attribute to change the floating point number field's
-        value.
-
-        :exc:`ValueError` or :exc:`TypeError` are raised on error.
-        """
-
-        ret, value = nbt._bt_ctf_field_floating_point_get_value(self._f)
-
-        if ret < 0:
-            raise ValueError("Could not get floating point field value.")
-
-        return value
-
-    @value.setter
-    def value(self, value):
-        if not isinstance(value, int) and not isinstance(value, float):
-            raise TypeError("Value must be either a float or an int")
-
-        ret = nbt._bt_ctf_field_floating_point_set_value(self._f, float(value))
-
-        if ret < 0:
-            raise ValueError("Could not set floating point field value.")
-
-
-# oops!! This class is provided to ensure backward-compatibility since
-# a stable release publicly exposed this abomination.
-class FloatFieldingPoint(FloatingPointField):
-    pass
-
-
-class StructureField(Field):
-    """
-    Structure field, based on a
-    :class:`StructureFieldDeclaration` object.
-    """
-
-    def field(self, field_name):
-        """
-        Returns the structure :class:`Field` named *field_name*.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        native_instance = nbt._bt_ctf_field_structure_get_field(self._f,
-                                                                str(field_name))
-
-        if native_instance is None:
-            raise ValueError("Invalid field_name provided.")
-
-        return Field._create_field_from_native_instance(native_instance)
-
-
-class VariantField(Field):
-    """
-    Variant field, based on a
-    :class:`VariantFieldDeclaration` object.
-    """
-
-    def field(self, tag):
-        """
-        Returns the :class:`Field` selected by the current label of
-        *tag* (:class:`EnumerationField`).
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        native_instance = nbt._bt_ctf_field_variant_get_field(self._f, tag._f)
-
-        if native_instance is None:
-            raise ValueError("Invalid tag provided.")
-
-        return Field._create_field_from_native_instance(native_instance)
-
-
-class ArrayField(Field):
-    """
-    Static array field, based on an
-    :class:`ArrayFieldDeclaration` object.
-    """
-
-    def field(self, index):
-        """
-        Returns the :class:`Field` at index *index* in this static
-        array.
-
-        :exc:`IndexError` is raised on error.
-        """
-
-        native_instance = nbt._bt_ctf_field_array_get_field(self._f, index)
-
-        if native_instance is None:
-            raise IndexError("Invalid index provided.")
-
-        return Field._create_field_from_native_instance(native_instance)
-
-
-class SequenceField(Field):
-    """
-    Sequence (dynamic array) field, based on a
-    :class:`SequenceFieldDeclaration` object.
-    """
-
-    @property
-    def length(self):
-        """
-        Sequence length (:class:`IntegerField`).
-
-        Set this attribute to change the sequence length's integer
-        field (integer must be unsigned).
-
-        :exc:`ValueError` or :exc:`TypeError` are raised on error.
-        """
-
-        native_instance = nbt._bt_ctf_field_sequence_get_length(self._f)
-
-        if native_instance is None:
-            length = -1
-
-        return Field._create_field_from_native_instance(native_instance)
-
-    @length.setter
-    def length(self, length_field):
-        if not isinstance(length_field, IntegerField):
-            raise TypeError("Invalid length field.")
-
-        if length_field.declaration.signed:
-            raise TypeError("Sequence field length must be unsigned")
-
-        ret = nbt._bt_ctf_field_sequence_set_length(self._f, length_field._f)
-
-        if ret < 0:
-            raise ValueError("Could not set sequence length.")
-
-    def field(self, index):
-        """
-        Returns the :class:`Field` at index *index* in this sequence.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        native_instance = nbt._bt_ctf_field_sequence_get_field(self._f, index)
-
-        if native_instance is None:
-            raise ValueError("Could not get sequence element at index.")
-
-        return Field._create_field_from_native_instance(native_instance)
-
-
-class StringField(Field):
-    """
-    String (NULL-terminated array of bytes) field.
-    """
-
-    @property
-    def value(self):
-        """
-        String value (:class:`str`).
-
-        Set this attribute to change the string's value.
-
-        :exc:`ValueError` or :exc:`TypeError` are raised on error.
-        """
-
-        return nbt._bt_ctf_field_string_get_value(self._f)
-
-    @value.setter
-    def value(self, value):
-        ret = nbt._bt_ctf_field_string_set_value(self._f, str(value))
-
-        if ret < 0:
-            raise ValueError("Could not set string field value.")
-
-
-class EventClass:
-    """
-    An event class contains the properties of specific
-    events (:class:`Event`). Any concrete event must be linked with an
-    :class:`EventClass`.
-
-    Some attributes are automatically set when creating an event class.
-    For example, if no numeric ID is explicitly set using the
-    :attr:`id` attribute, a default, unique ID within the stream class
-    containing this event class will be created when needed.
-    """
-
-    def __init__(self, name):
-        """
-        Creates an event class named *name*.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        self._ec = nbt._bt_ctf_event_class_create(name)
-
-        if self._ec is None:
-            raise ValueError("Event class creation failed.")
-
-    def __del__(self):
-        nbt._bt_ctf_event_class_put(self._ec)
-
-    def add_field(self, field_type, field_name):
-        """
-        Adds a field declaration *field_type* named *field_name* to
-        this event class.
-
-        *field_type* must be one of:
-
-        * :class:`IntegerFieldDeclaration`
-        * :class:`FloatingPointFieldDeclaration`
-        * :class:`EnumerationFieldDeclaration`
-        * :class:`StringFieldDeclaration`
-        * :class:`ArrayFieldDeclaration`
-        * :class:`SequenceFieldDeclaration`
-        * :class:`StructureFieldDeclaration`
-        * :class:`VariantFieldDeclaration`
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_event_class_add_field(self._ec, field_type._ft,
-                                                str(field_name))
-
-        if ret < 0:
-            raise ValueError("Could not add field to event class.")
-
-    @property
-    def name(self):
-        """
-        Event class' name.
-        """
-
-        name = nbt._bt_ctf_event_class_get_name(self._ec)
-
-        if name is None:
-            raise TypeError("Could not get EventClass name")
-
-        return name
-
-    @property
-    def id(self):
-        """
-        Event class' numeric ID.
-
-        Set this attribute to assign a numeric ID to this event class.
-        This ID must be unique amongst all the event class IDs of a
-        given stream class.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        id = nbt._bt_ctf_event_class_get_id(self._ec)
-
-        if id < 0:
-            raise TypeError("Could not get EventClass id")
-
-        return id
-
-    @id.setter
-    def id(self, id):
-        ret = nbt._bt_ctf_event_class_set_id(self._ec, id)
-
-        if ret < 0:
-            raise TypeError("Can't change an Event Class id after it has been assigned to a stream class")
-
-    @property
-    def stream_class(self):
-        """
-        :class:`StreamClass` object containing this event class,
-        or ``None`` if not set.
-        """
-
-        stream_class_native = nbt._bt_ctf_event_class_get_stream_class(self._ec)
-
-        if stream_class_native is None:
-            return None
-
-        stream_class = StreamClass.__new__(StreamClass)
-        stream_class._sc = stream_class_native
-
-        return stream_class
-
-    @property
-    def fields(self):
-        """
-        Generates the (field name, :class:`FieldDeclaration`) pairs of
-        this event class.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        count = nbt._bt_ctf_event_class_get_field_count(self._ec)
-
-        if count < 0:
-            raise TypeError("Could not get EventClass' field count")
-
-        for i in range(count):
-            field_name = nbt._bt_python_ctf_event_class_get_field_name(self._ec, i)
-
-            if field_name is None:
-                msg = "Could not get EventClass' field name at index {}".format(i)
-                raise TypeError(msg)
-
-            field_type_native = nbt._bt_python_ctf_event_class_get_field_type(self._ec, i)
-
-            if field_type_native is None:
-                msg = "Could not get EventClass' field type at index {}".format(i)
-                raise TypeError(msg)
-
-            field_type = FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
-            yield (field_name, field_type)
-
-    def get_field_by_name(self, name):
-        """
-        Returns the :class:`FieldDeclaration` object named *name* in
-        this event class.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        field_type_native = nbt._bt_ctf_event_class_get_field_by_name(self._ec, name)
-
-        if field_type_native is None:
-            msg = "Could not find EventClass field with name {}".format(name)
-            raise TypeError(msg)
-
-        return FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
-
-
-class Event:
-    """
-    Events are specific instances of event classes
-    (:class:`EventClass`), which means they may contain actual,
-    concrete field values.
-    """
-
-    def __init__(self, event_class):
-        """
-        Creates an event linked with the :class:`EventClass`
-        *event_class*.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        if not isinstance(event_class, EventClass):
-            raise TypeError("Invalid event_class argument.")
-
-        self._e = nbt._bt_ctf_event_create(event_class._ec)
-
-        if self._e is None:
-            raise ValueError("Event creation failed.")
-
-    def __del__(self):
-        nbt._bt_ctf_event_put(self._e)
-
-    @property
-    def event_class(self):
-        """
-        :class:`EventClass` object to which this event is linked.
-        """
-
-        event_class_native = nbt._bt_ctf_event_get_class(self._e)
-
-        if event_class_native is None:
-            return None
-
-        event_class = EventClass.__new__(EventClass)
-        event_class._ec = event_class_native
-
-        return event_class
-
-    def clock(self):
-        """
-        :class:`Clock` object used by this object, or ``None`` if
-        the event class is not registered to a stream class.
-        """
-
-        clock_instance = nbt._bt_ctf_event_get_clock(self._e)
-
-        if clock_instance is None:
-            return None
-
-        clock = Clock.__new__(Clock)
-        clock._c = clock_instance
-
-        return clock
-
-    def payload(self, field_name):
-        """
-        Returns the :class:`Field` object named *field_name* in this
-        event.
-
-        The returned field object is created using the event class'
-        field declaration named *field_name*.
-
-        The return type is one of:
-
-        * :class:`IntegerField`
-        * :class:`FloatingPointField`
-        * :class:`EnumerationField`
-        * :class:`StringField`
-        * :class:`ArrayField`
-        * :class:`SequenceField`
-        * :class:`StructureField`
-        * :class:`VariantField`
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        native_instance = nbt._bt_ctf_event_get_payload(self._e,
-                                                        str(field_name))
-
-        if native_instance is None:
-            raise ValueError("Could not get event payload.")
-
-        return Field._create_field_from_native_instance(native_instance)
-
-    def set_payload(self, field_name, value_field):
-        """
-        Set the event's field named *field_name* to the manually
-        created :class:`Field` object *value_field*.
-
-        *value_field*'s type must be one of:
-
-        * :class:`IntegerField`
-        * :class:`FloatingPointField`
-        * :class:`EnumerationField`
-        * :class:`StringField`
-        * :class:`ArrayField`
-        * :class:`SequenceField`
-        * :class:`StructureField`
-        * :class:`VariantField`
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        if not isinstance(value, Field):
-            raise TypeError("Invalid value type.")
-
-        ret = nbt._bt_ctf_event_set_payload(self._e, str(field_name),
-                                            value_field._f)
-
-        if ret < 0:
-            raise ValueError("Could not set event field payload.")
-
-
-class StreamClass:
-    """
-    A stream class contains the properties of specific
-    streams (:class:`Stream`). Any concrete stream must be linked with
-    a :class:`StreamClass`, usually by calling
-    :meth:`Writer.create_stream`.
-
-    Some attributes are automatically set when creating a stream class.
-    For example, if no clock is explicitly set using the
-    :attr:`clock` attribute, a default clock will be created
-    when needed.
-    """
-
-    def __init__(self, name):
-        """
-        Creates a stream class named *name*.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        self._sc = nbt._bt_ctf_stream_class_create(name)
-
-        if self._sc is None:
-            raise ValueError("Stream class creation failed.")
-
-    def __del__(self):
-        nbt._bt_ctf_stream_class_put(self._sc)
-
-    @property
-    def name(self):
-        """
-        Stream class' name.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        name = nbt._bt_ctf_stream_class_get_name(self._sc)
-
-        if name is None:
-            raise TypeError("Could not get StreamClass name")
-
-        return name
-
-    @property
-    def clock(self):
-        """
-        Stream class' clock (:class:`Clock` object).
-
-        Set this attribute to change the clock of this stream class.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        clock_instance = nbt._bt_ctf_stream_class_get_clock(self._sc)
-
-        if clock_instance is None:
-            return None
-
-        clock = Clock.__new__(Clock)
-        clock._c = clock_instance
-
-        return clock
-
-    @clock.setter
-    def clock(self, clock):
-        if not isinstance(clock, Clock):
-            raise TypeError("Invalid clock type.")
-
-        ret = nbt._bt_ctf_stream_class_set_clock(self._sc, clock._c)
-
-        if ret < 0:
-            raise ValueError("Could not set stream class clock.")
-
-    @property
-    def id(self):
-        """
-        Stream class' numeric ID.
-
-        Set this attribute to change the ID of this stream class.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_stream_class_get_id(self._sc)
-
-        if ret < 0:
-            raise TypeError("Could not get StreamClass id")
-
-        return ret
-
-    @id.setter
-    def id(self, id):
-        ret = nbt._bt_ctf_stream_class_set_id(self._sc, id)
-
-        if ret < 0:
-            raise TypeError("Could not set stream class id.")
-
-    @property
-    def event_classes(self):
-        """
-        Generates the event classes (:class:`EventClass` objects) of
-        this stream class.
-
-        :exc:`TypeError` is raised on error.
-        """
-
-        count = nbt._bt_ctf_stream_class_get_event_class_count(self._sc)
-
-        if count < 0:
-            raise TypeError("Could not get StreamClass' event class count")
-
-        for i in range(count):
-            event_class_native = nbt._bt_ctf_stream_class_get_event_class(self._sc, i)
-
-            if event_class_native is None:
-                msg = "Could not get StreamClass' event class at index {}".format(i)
-                raise TypeError(msg)
-
-            event_class = EventClass.__new__(EventClass)
-            event_class._ec = event_class_native
-            yield event_class
-
-    def add_event_class(self, event_class):
-        """
-        Registers the :class:`EventClass` *event_class* to this stream
-        class.
-
-        Once the event class is registered, it will be generated as one
-        of the event classes generated by :attr:`event_classes`.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        if not isinstance(event_class, EventClass):
-            raise TypeError("Invalid event_class type.")
-
-        ret = nbt._bt_ctf_stream_class_add_event_class(self._sc,
-                                                       event_class._ec)
-
-        if ret < 0:
-            raise ValueError("Could not add event class.")
-
-    @property
-    def packet_context_type(self):
-        """
-        Stream packet context declaration.
-
-        Set this attribute to change the stream packet context
-        declaration (must be an instance of
-        :class:`StructureFieldDeclaration`).
-
-        :exc:`ValueError` is raised on error.
-
-        """
-
-        field_type_native = nbt._bt_ctf_stream_class_get_packet_context_type(self._sc)
-
-        if field_type_native is None:
-            raise ValueError("Invalid StreamClass")
-
-        field_type = FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
-
-        return field_type
-
-    @packet_context_type.setter
-    def packet_context_type(self, field_type):
-        if not isinstance(field_type, StructureFieldDeclaration):
-            raise TypeError("field_type argument must be of type StructureFieldDeclaration.")
-
-        ret = nbt._bt_ctf_stream_class_set_packet_context_type(self._sc,
-                                                               field_type._ft)
-
-        if ret < 0:
-            raise ValueError("Failed to set packet context type.")
-
-
-class Stream:
-    """
-    Streams are specific instances of stream classes, which means they
-    may contain actual, concrete events.
-
-    :class:`Stream` objects are returned by
-    :meth:`Writer.create_stream`; they are not meant to be
-    instantiated by the user.
-
-    Concrete :class:`Event` objects are appended to
-    :class:`Stream` objects using :meth:`append_event`.
-
-    When :meth:`flush` is called, a CTF packet is created, containing
-    all the appended events since the last flush. Although the stream
-    is flushed on object destruction, it is **strongly recommended**
-    that the user call :meth:`flush` manually before exiting the
-    script, as :meth:`__del__` is not always reliable.
-    """
-
-    def __init__(self):
-        raise NotImplementedError("Stream cannot be instantiated; use Writer.create_stream()")
-
-    def __del__(self):
-        nbt._bt_ctf_stream_put(self._s)
-
-    @property
-    def discarded_events(self):
-        """
-        Number of discarded (lost) events in this stream so far.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret, count = nbt._bt_ctf_stream_get_discarded_events_count(self._s)
-
-        if ret < 0:
-            raise ValueError("Could not get the stream discarded events count")
-
-        return count
-
-    def append_discarded_events(self, event_count):
-        """
-        Appends *event_count* discarded events to this stream.
-        """
-
-        nbt._bt_ctf_stream_append_discarded_events(self._s, event_count)
-
-    def append_event(self, event):
-        """
-        Appends event *event* (:class:`Event` object) to this stream.
-
-        The stream's associated clock will be sampled during this call.
-        *event* **shall not** be modified after being appended to this
-        stream.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_stream_append_event(self._s, event._e)
-
-        if ret < 0:
-            raise ValueError("Could not append event to stream.")
-
-    @property
-    def packet_context(self):
-        """
-        Stream packet context field (instance of
-        :class:`StructureField`).
-
-        Set this attribute to assign a stream packet context field
-        to this stream.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        native_field = nbt._bt_ctf_stream_get_packet_context(self._s)
-
-        if native_field is None:
-            raise ValueError("Invalid Stream.")
-
-        return Field._create_field_from_native_instance(native_field)
-
-    @packet_context.setter
-    def packet_context(self, field):
-        if not isinstance(field, StructureField):
-            raise TypeError("Argument field must be of type StructureField")
-
-        ret = nbt._bt_ctf_stream_set_packet_context(self._s, field._f)
-
-        if ret < 0:
-            raise ValueError("Invalid packet context field.")
-
-    def flush(self):
-        """
-        Flushes the current packet of this stream to disk. Events
-        subsequently appended to the stream will be added to a new
-        packet.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_stream_flush(self._s)
-
-        if ret < 0:
-            raise ValueError("Could not flush stream.")
-
-
-class Writer:
-    """
-    This object is the CTF writer API context. It oversees its streams
-    and clocks, and is responsible for writing one CTF trace.
-    """
-
-    def __init__(self, path):
-        """
-        Creates a CTF writer, initializing a new CTF trace at path
-        *path*.
-
-        *path* must be an existing directory, since a CTF trace is
-        made of multiple files.
-
-        :exc:`ValueError` is raised if the creation fails.
-        """
-
-        self._w = nbt._bt_ctf_writer_create(path)
-
-        if self._w is None:
-            raise ValueError("Writer creation failed.")
-
-    def __del__(self):
-        nbt._bt_ctf_writer_put(self._w)
-
-    def create_stream(self, stream_class):
-        """
-        Creates and registers a new stream based on stream class
-        *stream_class*.
-
-        This is the standard way of creating a :class:`Stream` object:
-        the user is not allowed to instantiate this class.
-
-        Returns a new :class:`Stream` object.
-        """
-
-        if not isinstance(stream_class, StreamClass):
-            raise TypeError("Invalid stream_class type.")
-
-        stream = Stream.__new__(Stream)
-        stream._s = nbt._bt_ctf_writer_create_stream(self._w, stream_class._sc)
-
-        return stream
-
-    def add_environment_field(self, name, value):
-        """
-        Sets the CTF environment variable named *name* to value *value*
-        (converted to a string).
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        ret = nbt._bt_ctf_writer_add_environment_field(self._w, str(name),
-                                                       str(value))
-
-        if ret < 0:
-            raise ValueError("Could not add environment field to trace.")
-
-    def add_clock(self, clock):
-        """
-        Registers :class:`Clock` object *clock* to the writer.
-
-        You *must* register CTF clocks assigned to stream classes
-        to the writer.
-
-        :exc:`ValueError` is raised if the creation fails.
-        """
-
-        ret = nbt._bt_ctf_writer_add_clock(self._w, clock._c)
-
-        if ret < 0:
-            raise ValueError("Could not add clock to Writer.")
-
-    @property
-    def metadata(self):
-        """
-        Current metadata of this trace (:class:`str`).
-        """
-
-        return nbt._bt_ctf_writer_get_metadata_string(self._w)
-
-    def flush_metadata(self):
-        """
-        Flushes the trace's metadata to the metadata file.
-        """
-
-        nbt._bt_ctf_writer_flush_metadata(self._w)
-
-    @property
-    def byte_order(self):
-        """
-        Native byte order of this trace (one of
-        :class:`babeltrace.common.ByteOrder` constants).
-
-        This is the actual byte order that is used when a field
-        declaration has the
-        :attr:`babeltrace.common.ByteOrder.BYTE_ORDER_NATIVE`
-        value.
-
-        Set this attribute to change the trace's native byte order.
-
-        Defaults to the host machine's endianness.
-
-        :exc:`ValueError` is raised on error.
-        """
-
-        raise NotImplementedError("Getter not implemented.")
-
-    @byte_order.setter
-    def byte_order(self, byte_order):
-        ret = nbt._bt_ctf_writer_set_byte_order(self._w, byte_order)
-
-        if ret < 0:
-            raise ValueError("Could not set trace byte order.")
index 7a31bc7b698bdc1c96da9c272bbe49ec0ee7b85e..e843c7a78d99bf17693224e4e09ecd60b27d0bc1 100644 (file)
@@ -345,6 +345,7 @@ AC_CONFIG_FILES([
        include/Makefile
        bindings/Makefile
        bindings/python/Makefile
+       bindings/python/babeltrace/Makefile
        tests/Makefile
        tests/bin/Makefile
        tests/bin/intersection/Makefile
index 2d7dac3b2add920a179b376a977972ee97c1581a..955e2c35666838aa1edf561795c862507c898078 100644 (file)
@@ -26,15 +26,15 @@ $(SPHINX_DIRHTML_TARGET): $(SPHINX_SRC) $(BABELTRACE_PYTHON_DEPS)
        $(LOCAL_SPHINXBUILD) -b dirhtml -E $(SPHINX_SOURCE_DIR) $(SPHINX_BUILD_DIRHTML_DIR)
 
 swig-libs:
-       $(LN_S) $(abs_top_builddir)/bindings/python/.libs $@
+       $(LN_S) $(abs_top_builddir)/bindings/python/babeltrace/.libs $@
 
 babeltrace:
        $(mkdir_p) $@
-       $(LN_S) $(abs_top_builddir)/bindings/python/__init__.py $@/__init__.py
-       $(LN_S) $(abs_top_srcdir)/bindings/python/common.py $@/common.py
-       $(LN_S) $(abs_top_srcdir)/bindings/python/reader.py $@/reader.py
-       $(LN_S) $(abs_top_srcdir)/bindings/python/writer.py $@/writer.py
-       $(LN_S) $(abs_top_builddir)/bindings/python/nativebt.py $@/nativebt.py
+       $(LN_S) $(abs_top_builddir)/bindings/python/babeltrace/__init__.py $@/__init__.py
+       $(LN_S) $(abs_top_srcdir)/bindings/python/babeltrace/common.py $@/common.py
+       $(LN_S) $(abs_top_srcdir)/bindings/python/babeltrace/reader.py $@/reader.py
+       $(LN_S) $(abs_top_srcdir)/bindings/python/babeltrace/writer.py $@/writer.py
+       $(LN_S) $(abs_top_builddir)/bindings/python/babeltrace/nativebt.py $@/nativebt.py
 
 clean-local:
        rm -rf $(SPHINX_BUILD_DIR) swig-libs babeltrace
This page took 0.153986 seconds and 4 git commands to generate.