bt2: add user attributes property support
[babeltrace.git] / src / bindings / python / bt2 / bt2 / stream_class.py
index 08186333f1257f7591edcfe367d09f062c47b3a4..2c33dae8ddfa8d8a11ded5eedaadce48bd646139 100644 (file)
 # THE SOFTWARE.
 
 from bt2 import native_bt, object, utils
-import bt2.field_class
-import bt2.event_class
+from bt2 import field_class as bt2_field_class
+from bt2 import event_class as bt2_event_class
+from bt2 import trace_class as bt2_trace_class
+from bt2 import clock_class as bt2_clock_class
+from bt2 import value as bt2_value
 import collections.abc
-import bt2.stream
-import bt2
 
 
 class _StreamClass(object._SharedObject, collections.abc.Mapping):
@@ -39,7 +40,7 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
         if ec_ptr is None:
             raise KeyError(key)
 
-        return bt2.event_class._EventClass._create_from_ptr_and_get_ref(ec_ptr)
+        return bt2_event_class._EventClass._create_from_ptr_and_get_ref(ec_ptr)
 
     def __len__(self):
         count = native_bt.stream_class_get_event_class_count(self._ptr)
@@ -62,6 +63,7 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
         self,
         id=None,
         name=None,
+        user_attributes=None,
         log_level=None,
         emf_uri=None,
         specific_context_field_class=None,
@@ -83,11 +85,14 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
             utils._check_uint64(id)
             ec_ptr = native_bt.event_class_create_with_id(self._ptr, id)
 
-        event_class = bt2.event_class._EventClass._create_from_ptr(ec_ptr)
+        event_class = bt2_event_class._EventClass._create_from_ptr(ec_ptr)
 
         if name is not None:
             event_class._name = name
 
+        if user_attributes is not None:
+            event_class._user_attributes = user_attributes
+
         if log_level is not None:
             event_class._log_level = log_level
 
@@ -107,7 +112,20 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
         tc_ptr = native_bt.stream_class_borrow_trace_class_const(self._ptr)
 
         if tc_ptr is not None:
-            return bt2._TraceClass._create_from_ptr_and_get_ref(tc_ptr)
+            return bt2_trace_class._TraceClass._create_from_ptr_and_get_ref(tc_ptr)
+
+    @property
+    def user_attributes(self):
+        ptr = native_bt.stream_class_borrow_user_attributes(self._ptr)
+        assert ptr is not None
+        return bt2_value._create_from_ptr_and_get_ref(ptr)
+
+    def _user_attributes(self, user_attributes):
+        value = bt2_value.create_value(user_attributes)
+        utils._check_type(value, bt2_value.MapValue)
+        native_bt.stream_class_set_user_attributes(self._ptr, value._ptr)
+
+    _user_attributes = property(fset=_user_attributes)
 
     @property
     def name(self):
@@ -235,12 +253,6 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
 
         return id
 
-    @id.setter
-    def id(self, id):
-        utils._check_int64(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):
         fc_ptr = native_bt.stream_class_borrow_packet_context_field_class_const(
@@ -250,12 +262,12 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
         if fc_ptr is None:
             return
 
-        return bt2.field_class._create_field_class_from_ptr_and_get_ref(fc_ptr)
+        return bt2_field_class._create_field_class_from_ptr_and_get_ref(fc_ptr)
 
     def _packet_context_field_class(self, packet_context_field_class):
         if packet_context_field_class is not None:
             utils._check_type(
-                packet_context_field_class, bt2.field_class._StructureFieldClass
+                packet_context_field_class, bt2_field_class._StructureFieldClass
             )
 
             if not self.supports_packets:
@@ -279,12 +291,12 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
         if fc_ptr is None:
             return
 
-        return bt2.field_class._create_field_class_from_ptr_and_get_ref(fc_ptr)
+        return bt2_field_class._create_field_class_from_ptr_and_get_ref(fc_ptr)
 
     def _event_common_context_field_class(self, event_common_context_field_class):
         if event_common_context_field_class is not None:
             utils._check_type(
-                event_common_context_field_class, bt2.field_class._StructureFieldClass
+                event_common_context_field_class, bt2_field_class._StructureFieldClass
             )
 
             set_context_fn = native_bt.stream_class_set_event_common_context_field_class
@@ -301,10 +313,10 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping):
         if cc_ptr is None:
             return
 
-        return bt2.clock_class._ClockClass._create_from_ptr_and_get_ref(cc_ptr)
+        return bt2_clock_class._ClockClass._create_from_ptr_and_get_ref(cc_ptr)
 
     def _default_clock_class(self, clock_class):
-        utils._check_type(clock_class, bt2.clock_class._ClockClass)
+        utils._check_type(clock_class, bt2_clock_class._ClockClass)
         native_bt.stream_class_set_default_clock_class(self._ptr, clock_class._ptr)
 
     _default_clock_class = property(fset=_default_clock_class)
This page took 0.026248 seconds and 4 git commands to generate.