示例#1
0
 def __init__(self, element_field_class, length):
     utils._check_type(element_field_class, _FieldClass)
     utils._check_uint64(length)
     ptr = native_bt.field_class_array_create(element_field_class._ptr,
                                              length)
     self._check_create_status(ptr)
     super().__init__(ptr)
示例#2
0
    def _create_packet_end_message(self, packet, default_clock_snapshot=None):
        utils._check_type(packet, bt2_packet._Packet)

        if packet.stream.cls.packets_have_end_default_clock_snapshot:
            if default_clock_snapshot is None:
                raise ValueError(
                    "packet end messages in this stream must have a default clock snapshot"
                )

            utils._check_uint64(default_clock_snapshot)
            ptr = native_bt.message_packet_end_create_with_default_clock_snapshot(
                self._bt_ptr, packet._ptr, default_clock_snapshot)
        else:
            if default_clock_snapshot is not None:
                raise ValueError(
                    "packet end messages in this stream must not have a default clock snapshot"
                )

            ptr = native_bt.message_packet_end_create(self._bt_ptr,
                                                      packet._ptr)

        if ptr is None:
            raise bt2._MemoryError('cannot create packet end message object')

        return bt2_message._PacketEndMessage(ptr)
示例#3
0
    def create_stream(self, stream_class, id=None, name=None):
        utils._check_type(stream_class, bt2_stream_class._StreamClass)

        if stream_class.assigns_automatic_stream_id:
            if id is not None:
                raise ValueError(
                    "id provided, but stream class assigns automatic stream ids"
                )

            stream_ptr = native_bt.stream_create(stream_class._ptr, self._ptr)
        else:
            if id is None:
                raise ValueError(
                    "id not provided, but stream class does not assign automatic stream ids"
                )

            utils._check_uint64(id)
            stream_ptr = native_bt.stream_create_with_id(
                stream_class._ptr, self._ptr, id
            )

        if stream_ptr is None:
            raise bt2._MemoryError('cannot create stream object')

        stream = bt2_stream._Stream._create_from_ptr(stream_ptr)

        if name is not None:
            stream._name = name

        return stream
示例#4
0
 def __init__(self, element_field_class, length_name):
     utils._check_type(element_field_class, _FieldClass)
     utils._check_str(length_name)
     ptr = native_bt.field_class_sequence_create(element_field_class._ptr,
                                                length_name)
     self._check_create_status(ptr)
     super().__init__(ptr)
示例#5
0
    def append_option(self, name, field_class, ranges, user_attributes=None):
        utils._check_str(name)
        utils._check_type(field_class, _FieldClass)
        utils._check_type(ranges, self._variant_option_pycls._range_set_pycls)

        if name in self:
            raise ValueError("duplicate option name '{}'".format(name))

        if len(ranges) == 0:
            raise ValueError('range set is empty')

        user_attributes_value = None

        if user_attributes is not None:
            # check now that user attributes are valid
            user_attributes_value = bt2.create_value(user_attributes)

        # TODO: check overlaps (precondition of self._append_option())

        status = self._append_option(self._ptr, name, field_class._ptr, ranges._ptr)
        utils._handle_func_status(
            status, 'cannot append option to variant field class object'
        )

        if user_attributes is not None:
            self[name]._user_attributes = user_attributes_value
 def __setitem__(self, key, value):
     utils._check_type(key, bt2.ClockClass)
     utils._check_uint64(value)
     ret = native_bt.clock_class_priority_map_add_clock_class(self._ptr,
                                                              key._ptr,
                                                              value)
     utils._handle_ret(ret, "cannot set clock class's priority in clock class priority map object")
示例#7
0
 def __init__(self, element_field_type, length_name):
     utils._check_type(element_field_type, _FieldType)
     utils._check_str(length_name)
     ptr = native_bt.ctf_field_type_sequence_create(element_field_type._ptr,
                                                    length_name)
     self._check_create_status(ptr)
     super().__init__(ptr)
示例#8
0
 def __init__(self, element_field_class, length_name):
     utils._check_type(element_field_class, _FieldClass)
     utils._check_str(length_name)
     ptr = native_bt.field_class_sequence_create(element_field_class._ptr,
                                                 length_name)
     self._check_create_status(ptr)
     super().__init__(ptr)
示例#9
0
 def append_field(self, name, field_class):
     utils._check_str(name)
     utils._check_type(field_class, _FieldClass)
     ret = self._add_field(field_class._ptr, name)
     utils._handle_ret(
         ret, "cannot add field to {} field class object".format(
             self._NAME.lower()))
示例#10
0
    def __init__(self, stream):
        utils._check_type(stream, bt2.stream._Stream)
        ptr = native_bt.notification_stream_end_create(stream._ptr)

        if ptr is None:
            raise bt2.CreationError('cannot create end of stream notification object')

        super().__init__(ptr)
示例#11
0
    def __init__(self, packet):
        utils._check_type(packet, bt2.packet._Packet)
        ptr = native_bt.notification_packet_end_create(packet._ptr)

        if ptr is None:
            raise bt2.CreationError('cannot create end of packet notification object')

        super().__init__(ptr)
示例#12
0
    def __init__(self, event):
        utils._check_type(event, bt2.event._Event)
        ptr = native_bt.notification_event_create(event._ptr)

        if ptr is None:
            raise bt2.CreationError('cannot create trace event notification object')

        super().__init__(ptr)
示例#13
0
 def offset(self, offset):
     utils._check_type(offset, ClockClassOffset)
     ret = native_bt.clock_class_set_offset_s(self._ptr, offset.seconds)
     utils._handle_ret(ret,
                       "cannot set clock class object's offset (seconds)")
     ret = native_bt.clock_class_set_offset_cycles(self._ptr, offset.cycles)
     utils._handle_ret(ret,
                       "cannot set clock class object's offset (cycles)")
示例#14
0
    def __init__(self, trace):
        utils._check_type(trace, bt2.Trace)
        ptr = native_bt.notification_new_trace_create(trace._ptr)

        if ptr is None:
            raise bt2.CreationError('cannot create new trace notification object')

        super().__init__(ptr)
示例#15
0
    def __init__(self, stream):
        utils._check_type(stream, bt2.stream._Stream)
        ptr = native_bt.message_stream_end_create(stream._ptr)

        if ptr is None:
            raise bt2.CreationError('cannot create stream end message object')

        super().__init__(ptr)
示例#16
0
 def _specific_context_field_class(self, context_field_class):
     if context_field_class is not None:
         utils._check_type(context_field_class,
                           bt2_field_class._StructureFieldClass)
         status = native_bt.event_class_set_specific_context_field_class(
             self._ptr, context_field_class._ptr)
         utils._handle_func_status(
             status, "cannot set event class object's context field class")
示例#17
0
    def __init__(self, stream):
        utils._check_type(stream, bt2.stream._Stream)
        ptr = native_bt.message_stream_end_create(stream._ptr)

        if ptr is None:
            raise bt2.CreationError('cannot create stream end message object')

        super().__init__(ptr)
示例#18
0
    def __init__(self, packet):
        utils._check_type(packet, bt2.packet._Packet)
        ptr = native_bt.message_packet_end_create(packet._ptr)

        if ptr is None:
            raise bt2.CreationError('cannot create packet end message object')

        super().__init__(ptr)
示例#19
0
 def _payload_field_class(self, payload_field_class):
     if payload_field_class is not None:
         utils._check_type(payload_field_class,
                           bt2_field_class._StructureFieldClass)
         status = native_bt.event_class_set_payload_field_class(
             self._ptr, payload_field_class._ptr)
         utils._handle_func_status(
             status, "cannot set event class object's payload field class")
示例#20
0
 def offset(self, offset):
     utils._check_type(offset, bt2.ClockClassOffset)
     ret = native_bt.ctf_clock_set_offset_s(self._ptr, offset.seconds)
     utils._handle_ret(
         ret, "cannot set CTF writer clock object's offset (seconds)")
     ret = native_bt.ctf_clock_set_offset(self._ptr, offset.cycles)
     utils._handle_ret(
         ret, "cannot set CTF writer clock object's offset (cycles)")
示例#21
0
    def __init__(self, stream_class):
        utils._check_type(stream_class, bt2.StreamClass)
        ptr = native_bt.notification_new_stream_class_create(stream_class._ptr)

        if ptr is None:
            raise bt2.CreationError('cannot create new stream class notification object')

        super().__init__(ptr)
示例#22
0
    def __init__(self, packet):
        utils._check_type(packet, bt2.packet._Packet)
        ptr = native_bt.message_packet_end_create(packet._ptr)

        if ptr is None:
            raise bt2.CreationError('cannot create packet end message object')

        super().__init__(ptr)
示例#23
0
    def __init__(self, stream):
        utils._check_type(stream, bt2.stream._Stream)
        ptr = native_bt.notification_stream_end_create(stream._ptr)

        if ptr is None:
            raise bt2.CreationError(
                'cannot create end of stream notification object')

        super().__init__(ptr)
示例#24
0
    def header_field(self, header_field):
        header_field_ptr = None

        if header_field is not None:
            utils._check_type(header_field, bt2.fields._Field)
            header_field_ptr = header_field._ptr

        ret = native_bt.ctf_event_set_header(self._ptr, header_field_ptr)
        utils._handle_ret(ret, "cannot set event object's header field")
示例#25
0
    def context_field(self, context):
        context_ptr = None

        if context is not None:
            utils._check_type(context, bt2.fields._Field)
            context_ptr = context._ptr

        ret = native_bt.ctf_event_set_event_context(self._ptr, context_ptr)
        utils._handle_ret(ret, "cannot set event object's context field")
示例#26
0
    def context_field_type(self, context_field_type):
        context_field_type_ptr = None

        if context_field_type is not None:
            utils._check_type(context_field_type, bt2.field_types._FieldType)
            context_field_type_ptr = context_field_type._ptr

        ret = native_bt.event_class_set_context_type(self._ptr, context_field_type_ptr)
        utils._handle_ret(ret, "cannot set event class object's context field type")
示例#27
0
 def __setitem__(self, key, value):
     utils._check_type(key, bt2.ClockClass)
     utils._check_uint64(value)
     ret = native_bt.clock_class_priority_map_add_clock_class(
         self._ptr, key._ptr, value)
     utils._handle_ret(
         ret,
         "cannot set clock class's priority in clock class priority map object"
     )
示例#28
0
    def header_field(self, header_field):
        header_field_ptr = None

        if header_field is not None:
            utils._check_type(header_field, bt2.fields._Field)
            header_field_ptr = header_field._ptr

        ret = native_bt.ctf_event_set_header(self._ptr, header_field_ptr)
        utils._handle_ret(ret, "cannot set event object's header field")
示例#29
0
    def __init__(self, stream_class):
        utils._check_type(stream_class, bt2.StreamClass)
        ptr = native_bt.notification_new_stream_class_create(stream_class._ptr)

        if ptr is None:
            raise bt2.CreationError(
                'cannot create new stream class notification object')

        super().__init__(ptr)
示例#30
0
    def __init__(self, event):
        utils._check_type(event, bt2.event._Event)
        ptr = native_bt.notification_event_create(event._ptr)

        if ptr is None:
            raise bt2.CreationError(
                'cannot create trace event notification object')

        super().__init__(ptr)
示例#31
0
    def context_field(self, context):
        context_ptr = None

        if context is not None:
            utils._check_type(context, bt2.fields._Field)
            context_ptr = context._ptr

        ret = native_bt.ctf_event_set_event_context(self._ptr, context_ptr)
        utils._handle_ret(ret, "cannot set event object's context field")
示例#32
0
    def __init__(self, packet):
        utils._check_type(packet, bt2.packet._Packet)
        ptr = native_bt.notification_packet_end_create(packet._ptr)

        if ptr is None:
            raise bt2.CreationError(
                'cannot create end of packet notification object')

        super().__init__(ptr)
示例#33
0
    def __getitem__(self, key):
        utils._check_type(key, bt2.ClockClass)
        ret, prio = native_bt.clock_class_priority_map_get_clock_class_priority(
            self._ptr, key._ptr)

        if ret != 0:
            raise KeyError(key)

        return prio
示例#34
0
    def __init__(self, trace):
        utils._check_type(trace, bt2.Trace)
        ptr = native_bt.notification_new_trace_create(trace._ptr)

        if ptr is None:
            raise bt2.CreationError(
                'cannot create new trace notification object')

        super().__init__(ptr)
示例#35
0
    def payload_field_type(self, payload_field_type):
        payload_field_type_ptr = None

        if payload_field_type is not None:
            utils._check_type(payload_field_type, bt2.field_types._FieldType)
            payload_field_type_ptr = payload_field_type._ptr

        ret = native_bt.event_class_set_payload_type(self._ptr, payload_field_type_ptr)
        utils._handle_ret(ret, "cannot set event class object's payload field type")
示例#36
0
    def context_field(self, context_field):
        context_field_ptr = None

        if context_field is not None:
            utils._check_type(context_field, bt2.field._Field)
            context_field_ptr = context_field._ptr

        ret = native_bt.packet_set_context(self._ptr, context_field_ptr)
        utils._handle_ret(ret, "cannot set packet object's context field")
示例#37
0
    def payload_field(self, payload):
        payload_ptr = None

        if payload is not None:
            utils._check_type(payload, bt2.fields._Field)
            payload_ptr = payload._ptr

        ret = native_bt.ctf_event_set_payload_field(self._ptr, payload_ptr)
        utils._handle_ret(ret, "cannot set event object's payload field")
示例#38
0
 def connect_ports(self, upstream_port, downstream_port):
     utils._check_type(upstream_port, bt2.port._OutputPort)
     utils._check_type(downstream_port, bt2.port._InputPort)
     status, conn_ptr = native_bt.graph_connect_ports(self._ptr,
                                                      upstream_port._ptr,
                                                      downstream_port._ptr)
     self._handle_status(status, 'cannot connect component ports within graph')
     assert(conn_ptr)
     return bt2.connection._Connection._create_from_ptr(conn_ptr)
示例#39
0
    def payload_field(self, payload):
        payload_ptr = None

        if payload is not None:
            utils._check_type(payload, bt2.fields._Field)
            payload_ptr = payload._ptr

        ret = native_bt.ctf_event_set_payload_field(self._ptr, payload_ptr)
        utils._handle_ret(ret, "cannot set event object's payload field")
示例#40
0
    def context_field(self, context_field):
        context_field_ptr = None

        if context_field is not None:
            utils._check_type(context_field, bt2.field._Field)
            context_field_ptr = context_field._ptr

        ret = native_bt.packet_set_context(self._ptr, context_field_ptr)
        utils._handle_ret(ret, "cannot set packet object's context field")
    def __getitem__(self, key):
        utils._check_type(key, bt2.ClockClass)
        ret, prio = native_bt.clock_class_priority_map_get_clock_class_priority(self._ptr,
                                                                                key._ptr)

        if ret != 0:
            raise KeyError(key)

        return prio
示例#42
0
    def _get_from_bt(self):
        # this can raise anything: it's catched by the system
        notif = self._get()
        utils._check_type(notif, bt2.notification._Notification)

        # steal the underlying native notification object for the caller
        notif_ptr = notif._ptr
        notif._ptr = None
        return int(notif_ptr)
示例#43
0
    def create_static_array_field_class(self, elem_fc, length):
        utils._check_type(elem_fc, bt2_field_class._FieldClass)
        utils._check_uint64(length)
        ptr = native_bt.field_class_array_static_create(
            self._ptr, elem_fc._ptr, length)
        self._check_create_status(ptr, 'static array')

        return bt2_field_class._StaticArrayFieldClass._create_from_ptr_and_get_ref(
            ptr)
示例#44
0
 def connect_ports(self, upstream_port, downstream_port):
     utils._check_type(upstream_port, bt2_port._OutputPortConst)
     utils._check_type(downstream_port, bt2_port._InputPortConst)
     status, conn_ptr = native_bt.graph_connect_ports(
         self._ptr, upstream_port._ptr, downstream_port._ptr
     )
     utils._handle_func_status(status, 'cannot connect component ports within graph')
     assert conn_ptr
     return bt2_connection._ConnectionConst._create_from_ptr(conn_ptr)
示例#45
0
    def packet_context_field_type(self, packet_context_field_type):
        packet_context_field_type_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

        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")
示例#46
0
    def __getitem__(self, clock_class):
        utils._check_type(clock_class, bt2.ClockClass)
        clock_snapshot_ptr = native_bt.message_inactivity_get_clock_snapshot(self._msg._ptr,
                                                                            clock_class._ptr)

        if clock_snapshot_ptr is None:
            return

        clock_snapshot = bt2.clock_snapshot._create_clock_snapshot_from_ptr(clock_snapshot_ptr)
        return clock_snapshot
示例#47
0
    def _create_message_iterator_inactivity_message(self, clock_class,
                                                    clock_snapshot):
        utils._check_type(clock_class, bt2_clock_class._ClockClass)
        ptr = native_bt.message_message_iterator_inactivity_create(
            self._bt_ptr, clock_class._ptr, clock_snapshot)

        if ptr is None:
            raise bt2._MemoryError('cannot create inactivity message object')

        return bt2_message._MessageIteratorInactivityMessage(ptr)
示例#48
0
    def create_variant_field_class(self, selector_fc=None):
        selector_fc_ptr = None

        if selector_fc is not None:
            utils._check_type(selector_fc, bt2_field_class._IntegerFieldClass)
            selector_fc_ptr = selector_fc._ptr

        ptr = native_bt.field_class_variant_create(self._ptr, selector_fc_ptr)
        self._check_create_status(ptr, 'variant')
        return bt2_field_class._create_field_class_from_ptr_and_get_ref(ptr)
示例#49
0
    def _create_input_port_message_iterator(self, input_port):
        utils._check_type(input_port, bt2_port._UserComponentInputPort)

        msg_iter_ptr = native_bt.self_component_port_input_message_iterator_create_from_message_iterator(
            self._bt_ptr, input_port._ptr)

        if msg_iter_ptr is None:
            raise bt2.CreationError('cannot create message iterator object')

        return _UserComponentInputPortMessageIterator(msg_iter_ptr)
示例#50
0
    def stream_event_context_field(self, stream_event_context):
        stream_event_context_ptr = None

        if stream_event_context is not None:
            utils._check_type(stream_event_context, bt2.fields._Field)
            stream_event_context_ptr = stream_event_context._ptr

        ret = native_bt.ctf_event_set_stream_event_context(self._ptr,
                                                           stream_event_context_ptr)
        utils._handle_ret(ret, "cannot set event object's stream event context field")
示例#51
0
    def packet_context_field(self, packet_context_field):
        packet_context_field_ptr = None

        if packet_context_field is not None:
            utils._check_type(packet_context_field, bt2.fields._Field)
            packet_context_field_ptr = packet_context_field._ptr

        ret = native_bt.stream_set_packet_context(self._ptr,
                                                  packet_context_field_ptr)
        utils._handle_ret(ret, "cannot set CTF writer stream object's packet context field")
示例#52
0
    def event_context_field_class(self, event_context_field_class):
        event_context_field_class_ptr = None

        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.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")
示例#53
0
    def packet_context_field_class(self, packet_context_field_class):
        packet_context_field_class_ptr = None

        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.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")
示例#54
0
    def get_clock_value(self, clock_class):
        utils._check_type(clock_class, bt2.ClockClass)
        clock_value_ptr = native_bt.ctf_event_get_clock_value(self._ptr,
                                                              clock_class._ptr)

        if clock_value_ptr is None:
            return

        clock_value = bt2.clock_class._create_clock_value_from_ptr(clock_value_ptr)
        return clock_value
示例#55
0
    def packet_header_field_class(self, packet_header_field_class):
        packet_header_field_class_ptr = None

        if packet_header_field_class is not None:
            utils._check_type(packet_header_field_class, bt2.field_class._FieldClass)
            packet_header_field_class_ptr = packet_header_field_class._ptr

        ret = native_bt.trace_set_packet_header_type(self._ptr,
                                                     packet_header_field_class_ptr)
        utils._handle_ret(ret, "cannot set trace class object's packet header field class")
示例#56
0
    def field(self, tag_field=None):
        if tag_field is None:
            field_ptr = native_bt.ctf_field_variant_get_current_field(self._ptr)
            utils._handle_ptr(field_ptr, "cannot get variant field object's selected field")
        else:
            utils._check_type(tag_field, _EnumerationField)
            field_ptr = native_bt.ctf_field_variant_get_field(self._ptr, tag_field._ptr)
            utils._handle_ptr(field_ptr, "cannot select variant field object's field")

        return _create_from_ptr(field_ptr)
示例#57
0
    def packet_header_field_type(self, packet_header_field_type):
        packet_header_field_type_ptr = None

        if packet_header_field_type is not None:
            utils._check_type(packet_header_field_type, bt2.field_types._FieldType)
            packet_header_field_type_ptr = packet_header_field_type._ptr

        ret = native_bt.trace_set_packet_header_type(self._ptr,
                                                     packet_header_field_type_ptr)
        utils._handle_ret(ret, "cannot set trace class object's packet header field type")
示例#58
0
    def event_context_field_type(self, event_context_field_type):
        event_context_field_type_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

        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")