lib: make packets and packet messages optional, disabled by default
[babeltrace.git] / src / bindings / python / bt2 / bt2 / stream_class.py
index 54b5b38bba0587bf1f83e5ff9f3f44e549a32043..cf34cf4c05f285808619724aed60f2d43f89394d 100644 (file)
@@ -103,8 +103,9 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
 
     def _name(self, name):
         utils._check_str(name)
-        ret = native_bt.stream_class_set_name(self._ptr, name)
-        utils._handle_ret(ret, "cannot set stream class object's name")
+        status = native_bt.stream_class_set_name(self._ptr, name)
+        utils._handle_func_status(status,
+                                  "cannot set stream class object's name")
 
     _name = property(fset=_name)
 
@@ -128,25 +129,30 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
 
     _assigns_automatic_stream_id = property(fset=_assigns_automatic_stream_id)
 
+    @property
+    def supports_packets(self):
+        return native_bt.stream_class_supports_packets(self._ptr)
+
     @property
     def packets_have_beginning_default_clock_snapshot(self):
         return native_bt.stream_class_packets_have_beginning_default_clock_snapshot(self._ptr)
 
-    def _packets_have_beginning_default_clock_snapshot(self, value):
-        utils._check_bool(value)
-        native_bt.stream_class_set_packets_have_beginning_default_clock_snapshot(self._ptr, value)
-
-    _packets_have_beginning_default_clock_snapshot = property(fset=_packets_have_beginning_default_clock_snapshot)
-
     @property
     def packets_have_end_default_clock_snapshot(self):
         return native_bt.stream_class_packets_have_end_default_clock_snapshot(self._ptr)
 
-    def _packets_have_end_default_clock_snapshot(self, value):
-        utils._check_bool(value)
-        native_bt.stream_class_set_packets_have_end_default_clock_snapshot(self._ptr, value)
+    def _set_supports_packets(self, supports, with_begin_cs=False, with_end_cs=False):
+        utils._check_bool(supports)
+        utils._check_bool(with_begin_cs)
+        utils._check_bool(with_end_cs)
+
+        if not supports and (with_begin_cs or with_end_cs):
+            raise ValueError('cannot not support packets, but have default clock snapshots')
 
-    _packets_have_end_default_clock_snapshot = property(fset=_packets_have_end_default_clock_snapshot)
+        if not supports and self.packet_context_field_class is not None:
+            raise ValueError('stream class already has a packet context field class')
+
+        native_bt.stream_class_set_supports_packets(self._ptr, supports, with_begin_cs, with_end_cs)
 
     @property
     def supports_discarded_events(self):
@@ -173,6 +179,9 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
         utils._check_bool(supports)
         utils._check_bool(with_cs)
 
+        if supports and not self.supports_packets:
+            raise ValueError('cannot support discarded packets, but not support packets')
+
         if not supports and with_cs:
             raise ValueError('cannot not support discarded packets, but have default clock snapshots')
 
@@ -194,8 +203,8 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
     @id.setter
     def id(self, id):
         utils._check_int64(id)
-        ret = native_bt.stream_class_set_id(self._ptr, id)
-        utils._handle_ret(ret, "cannot set stream class object's ID")
+        status = native_bt.stream_class_set_id(self._ptr, id)
+        utils._handle_func_status(status, "cannot set stream class object's ID")
 
     @property
     def packet_context_field_class(self):
@@ -210,9 +219,14 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
         if packet_context_field_class is not None:
             utils._check_type(packet_context_field_class,
                               bt2.field_class._StructureFieldClass)
-            ret = native_bt.stream_class_set_packet_context_field_class(self._ptr,
-                                                                        packet_context_field_class._ptr)
-            utils._handle_ret(ret, "cannot set stream class' packet context field class")
+
+            if not self.supports_packets:
+                raise ValueError('stream class does not support packets')
+
+            status = native_bt.stream_class_set_packet_context_field_class(self._ptr,
+                                                                           packet_context_field_class._ptr)
+            utils._handle_func_status(status,
+                                      "cannot set stream class' packet context field class")
 
     _packet_context_field_class = property(fset=_packet_context_field_class)
 
@@ -231,9 +245,9 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
                               bt2.field_class._StructureFieldClass)
 
             set_context_fn = native_bt.stream_class_set_event_common_context_field_class
-            ret = set_context_fn(self._ptr, event_common_context_field_class._ptr)
-
-            utils._handle_ret(ret, "cannot set stream class' event context field type")
+            status = set_context_fn(self._ptr, event_common_context_field_class._ptr)
+            utils._handle_func_status(status,
+                                      "cannot set stream class' event context field type")
 
     _event_common_context_field_class = property(fset=_event_common_context_field_class)
 
This page took 0.024693 seconds and 4 git commands to generate.