bt2: Adapt test_trace.py and make it pass
[babeltrace.git] / bindings / python / bt2 / bt2 / stream_class.py
index 17c6de0f975bff9e6866683f9d2f637025ab46fa..ccf3a84f8589fae3dc199aaff05922f02e50938f 100644 (file)
@@ -21,7 +21,7 @@
 # THE SOFTWARE.
 
 from bt2 import native_bt, object, utils
-import bt2.field_types
+import bt2.field_class
 import collections.abc
 import bt2.ctf_writer
 import bt2.stream
@@ -38,21 +38,24 @@ class _EventClassIterator(collections.abc.Iterator):
         if self._at == len(self._stream_class):
             raise StopIteration
 
-        ec_ptr = native_bt.ctf_stream_class_get_event_class_by_index(self._stream_class._ptr,
-                                                                     self._at)
+        ec_ptr = native_bt.stream_class_get_event_class_by_index(self._stream_class._ptr,
+                                                                 self._at)
         assert(ec_ptr)
-        ev_id = native_bt.ctf_event_class_get_id(ec_ptr)
+        ev_id = native_bt.event_class_get_id(ec_ptr)
         native_bt.put(ec_ptr)
         utils._handle_ret(ev_id, "cannot get event class object's ID")
         self._at += 1
         return ev_id
 
 
-class StreamClass(object._Object, collections.abc.Mapping):
-    def __init__(self, name=None, id=None, packet_context_field_type=None,
-                 event_header_field_type=None, event_context_field_type=None,
+class StreamClass(object._SharedObject, collections.abc.Mapping):
+    _get_ref = staticmethod(native_bt.stream_class_get_ref)
+    _put_ref = staticmethod(native_bt.stream_class_put_ref)
+
+    def __init__(self, name=None, id=None, packet_context_field_class=None,
+                 event_header_field_class=None, event_context_field_class=None,
                  event_classes=None):
-        ptr = native_bt.ctf_stream_class_create_empty(None)
+        ptr = native_bt.stream_class_create_empty(None)
 
         if ptr is None:
             raise bt2.CreationError('cannot create stream class object')
@@ -65,14 +68,14 @@ class StreamClass(object._Object, collections.abc.Mapping):
         if id is not None:
             self.id = id
 
-        if packet_context_field_type is not None:
-            self.packet_context_field_type = packet_context_field_type
+        if packet_context_field_class is not None:
+            self.packet_context_field_class = packet_context_field_class
 
-        if event_header_field_type is not None:
-            self.event_header_field_type = event_header_field_type
+        if event_header_field_class is not None:
+            self.event_header_field_class = event_header_field_class
 
-        if event_context_field_type is not None:
-            self.event_context_field_type = event_context_field_type
+        if event_context_field_class is not None:
+            self.event_context_field_class = event_context_field_class
 
         if event_classes is not None:
             for event_class in event_classes:
@@ -80,8 +83,8 @@ class StreamClass(object._Object, collections.abc.Mapping):
 
     def __getitem__(self, key):
         utils._check_int64(key)
-        ec_ptr = native_bt.ctf_stream_class_get_event_class_by_id(self._ptr,
-                                                                  key)
+        ec_ptr = native_bt.stream_class_get_event_class_by_id(self._ptr,
+                                                              key)
 
         if ec_ptr is None:
             raise KeyError(key)
@@ -89,7 +92,7 @@ class StreamClass(object._Object, collections.abc.Mapping):
         return bt2.EventClass._create_from_ptr(ec_ptr)
 
     def __len__(self):
-        count = native_bt.ctf_stream_class_get_event_class_count(self._ptr)
+        count = native_bt.stream_class_get_event_class_count(self._ptr)
         assert(count >= 0)
         return count
 
@@ -98,29 +101,39 @@ class StreamClass(object._Object, collections.abc.Mapping):
 
     def add_event_class(self, event_class):
         utils._check_type(event_class, bt2.EventClass)
-        ret = native_bt.ctf_stream_class_add_event_class(self._ptr, event_class._ptr)
+        ret = native_bt.stream_class_add_event_class(self._ptr, event_class._ptr)
         utils._handle_ret(ret, "cannot add event class object to stream class object's")
 
     @property
     def trace(self):
-        tc_ptr = native_bt.ctf_stream_class_get_trace(self._ptr)
+        tc_ptr = native_bt.stream_class_get_trace(self._ptr)
 
         if tc_ptr is not None:
             return bt2.Trace._create_from_ptr(tc_ptr)
 
     @property
     def name(self):
-        return native_bt.ctf_stream_class_get_name(self._ptr)
+        return native_bt.stream_class_get_name(self._ptr)
 
     @name.setter
     def name(self, name):
         utils._check_str(name)
-        ret = native_bt.ctf_stream_class_set_name(self._ptr, name)
+        ret = native_bt.stream_class_set_name(self._ptr, name)
         utils._handle_ret(ret, "cannot set stream class object's name")
 
+    @property
+    def assigns_automatic_stream_id(self):
+        return native_bt.stream_class_assigns_automatic_stream_id(self._ptr)
+
+    def _assigns_automatic_stream_id(self, auto_id):
+        utils._check_bool(auto_id)
+        return native_bt.stream_class_set_assigns_automatic_stream_id(self._ptr, auto_id)
+
+    _assigns_automatic_stream_id = property(fset=_assigns_automatic_stream_id)
+
     @property
     def id(self):
-        id = native_bt.ctf_stream_class_get_id(self._ptr)
+        id = native_bt.stream_class_get_id(self._ptr)
 
         if id < 0:
             return
@@ -130,12 +143,12 @@ class StreamClass(object._Object, collections.abc.Mapping):
     @id.setter
     def id(self, id):
         utils._check_int64(id)
-        ret = native_bt.ctf_stream_class_set_id(self._ptr, id)
+        ret = native_bt.stream_class_set_id(self._ptr, id)
         utils._handle_ret(ret, "cannot set stream class object's ID")
 
     @property
     def clock(self):
-        clock_ptr = native_bt.ctf_stream_class_get_clock(self._ptr)
+        clock_ptr = native_bt.stream_class_get_clock(self._ptr)
 
         if clock_ptr is None:
             return
@@ -145,80 +158,80 @@ class StreamClass(object._Object, collections.abc.Mapping):
     @clock.setter
     def clock(self, clock):
         utils._check_type(clock, bt2.ctf_writer.CtfWriterClock)
-        ret = native_bt.ctf_stream_class_set_clock(self._ptr, clock._ptr)
+        ret = native_bt.stream_class_set_clock(self._ptr, clock._ptr)
         utils._handle_ret(ret, "cannot set stream class object's CTF writer clock object")
 
     @property
-    def packet_context_field_type(self):
-        ft_ptr = native_bt.ctf_stream_class_get_packet_context_type(self._ptr)
+    def packet_context_field_class(self):
+        fc_ptr = native_bt.stream_class_get_packet_context_type(self._ptr)
 
-        if ft_ptr is None:
+        if fc_ptr is None:
             return
 
-        return bt2.field_types._create_from_ptr(ft_ptr)
+        return bt2.field_class._create_from_ptr(fc_ptr)
 
-    @packet_context_field_type.setter
-    def packet_context_field_type(self, packet_context_field_type):
-        packet_context_field_type_ptr = None
+    @packet_context_field_class.setter
+    def packet_context_field_class(self, packet_context_field_class):
+        packet_context_field_class_ptr = None
 
-        if packet_context_field_type is not None:
-            utils._check_type(packet_context_field_type, bt2.field_types._FieldType)
-            packet_context_field_type_ptr = packet_context_field_type._ptr
+        if packet_context_field_class is not None:
+            utils._check_type(packet_context_field_class, bt2.field_class._FieldClass)
+            packet_context_field_class_ptr = packet_context_field_class._ptr
 
-        ret = native_bt.ctf_stream_class_set_packet_context_type(self._ptr,
-                                                                 packet_context_field_type_ptr)
-        utils._handle_ret(ret, "cannot set stream class object's packet context field type")
+        ret = native_bt.stream_class_set_packet_context_type(self._ptr,
+                                                             packet_context_field_class_ptr)
+        utils._handle_ret(ret, "cannot set stream class object's packet context field class")
 
     @property
-    def event_header_field_type(self):
-        ft_ptr = native_bt.ctf_stream_class_get_event_header_type(self._ptr)
+    def event_header_field_class(self):
+        fc_ptr = native_bt.stream_class_get_event_header_type(self._ptr)
 
-        if ft_ptr is None:
+        if fc_ptr is None:
             return
 
-        return bt2.field_types._create_from_ptr(ft_ptr)
+        return bt2.field_class._create_from_ptr(fc_ptr)
 
-    @event_header_field_type.setter
-    def event_header_field_type(self, event_header_field_type):
-        event_header_field_type_ptr = None
+    @event_header_field_class.setter
+    def event_header_field_class(self, event_header_field_class):
+        event_header_field_class_ptr = None
 
-        if event_header_field_type is not None:
-            utils._check_type(event_header_field_type, bt2.field_types._FieldType)
-            event_header_field_type_ptr = event_header_field_type._ptr
+        if event_header_field_class is not None:
+            utils._check_type(event_header_field_class, bt2.field_class._FieldClass)
+            event_header_field_class_ptr = event_header_field_class._ptr
 
-        ret = native_bt.ctf_stream_class_set_event_header_type(self._ptr,
-                                                               event_header_field_type_ptr)
-        utils._handle_ret(ret, "cannot set stream class object's event header field type")
+        ret = native_bt.stream_class_set_event_header_type(self._ptr,
+                                                           event_header_field_class_ptr)
+        utils._handle_ret(ret, "cannot set stream class object's event header field class")
 
     @property
-    def event_context_field_type(self):
-        ft_ptr = native_bt.ctf_stream_class_get_event_context_type(self._ptr)
+    def event_context_field_class(self):
+        fc_ptr = native_bt.stream_class_get_event_context_type(self._ptr)
 
-        if ft_ptr is None:
+        if fc_ptr is None:
             return
 
-        return bt2.field_types._create_from_ptr(ft_ptr)
+        return bt2.field_class._create_from_ptr(fc_ptr)
 
-    @event_context_field_type.setter
-    def event_context_field_type(self, event_context_field_type):
-        event_context_field_type_ptr = None
+    @event_context_field_class.setter
+    def event_context_field_class(self, event_context_field_class):
+        event_context_field_class_ptr = None
 
-        if event_context_field_type is not None:
-            utils._check_type(event_context_field_type, bt2.field_types._FieldType)
-            event_context_field_type_ptr = event_context_field_type._ptr
+        if event_context_field_class is not None:
+            utils._check_type(event_context_field_class, bt2.field_class._FieldClass)
+            event_context_field_class_ptr = event_context_field_class._ptr
 
-        ret = native_bt.ctf_stream_class_set_event_context_type(self._ptr,
-                                                               event_context_field_type_ptr)
-        utils._handle_ret(ret, "cannot set stream class object's event context field type")
+        ret = native_bt.stream_class_set_event_context_type(self._ptr,
+                                                            event_context_field_class_ptr)
+        utils._handle_ret(ret, "cannot set stream class object's event context field class")
 
     def __call__(self, name=None, id=None):
         if name is not None:
             utils._check_str(name)
 
         if id is None:
-            stream_ptr = native_bt.ctf_stream_create(self._ptr, name)
+            stream_ptr = native_bt.stream_create(self._ptr, name)
         else:
-            stream_ptr = native_bt.ctf_stream_create_with_id(self._ptr, name, id)
+            stream_ptr = native_bt.stream_create_with_id(self._ptr, name, id)
 
         if stream_ptr is None:
             raise bt2.CreationError('cannot create stream object')
@@ -238,24 +251,24 @@ class StreamClass(object._Object, collections.abc.Mapping):
             self_event_classes,
             self.name,
             self.id,
-            self.packet_context_field_type,
-            self.event_header_field_type,
-            self.event_context_field_type,
+            self.packet_context_field_class,
+            self.event_header_field_class,
+            self.event_context_field_class,
             self.clock,
         )
         other_props = (
             other_event_classes,
             other.name,
             other.id,
-            other.packet_context_field_type,
-            other.event_header_field_type,
-            other.event_context_field_type,
+            other.packet_context_field_class,
+            other.event_header_field_class,
+            other.event_context_field_class,
             other.clock,
         )
 
         return self_props == other_props
 
-    def _copy(self, ft_copy_func, ev_copy_func):
+    def _copy(self, fc_copy_func, ev_copy_func):
         cpy = StreamClass()
 
         if self.id is not None:
@@ -267,9 +280,9 @@ class StreamClass(object._Object, collections.abc.Mapping):
         if self.clock is not None:
             cpy.clock = self.clock
 
-        cpy.packet_context_field_type = ft_copy_func(self.packet_context_field_type)
-        cpy.event_header_field_type = ft_copy_func(self.event_header_field_type)
-        cpy.event_context_field_type = ft_copy_func(self.event_context_field_type)
+        cpy.packet_context_field_class = fc_copy_func(self.packet_context_field_class)
+        cpy.event_header_field_class = fc_copy_func(self.event_header_field_class)
+        cpy.event_context_field_class = fc_copy_func(self.event_context_field_class)
 
         for event_class in self.values():
             cpy.add_event_class(ev_copy_func(event_class))
@@ -277,7 +290,7 @@ class StreamClass(object._Object, collections.abc.Mapping):
         return cpy
 
     def __copy__(self):
-        return self._copy(lambda ft: ft, copy.copy)
+        return self._copy(lambda fc: fc, copy.copy)
 
     def __deepcopy__(self, memo):
         cpy = self._copy(copy.deepcopy, copy.deepcopy)
This page took 0.0301 seconds and 4 git commands to generate.