Beispiel #1
0
    def create_packet(self):
        packet_ptr = native_bt.packet_create(self._ptr)

        if packet_ptr is None:
            raise bt2.CreationError('cannot create packet object')

        return bt2.packet._Packet._create_from_ptr(packet_ptr)
Beispiel #2
0
    def __init__(self):
        ptr = native_bt.graph_create()

        if ptr is None:
            raise bt2.CreationError('cannot create graph object')

        super().__init__(ptr)
Beispiel #3
0
    def __init__(self):
        ptr = native_bt.query_executor_create()

        if ptr is None:
            raise bt2.CreationError('cannot create query executor object')

        super().__init__(ptr)
Beispiel #4
0
    def __init__(self,
                 name,
                 id=None,
                 log_level=None,
                 emf_uri=None,
                 context_field_class=None,
                 payload_field_class=None):
        utils._check_str(name)
        ptr = native_bt.event_class_create(name)

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

        super().__init__(ptr)

        if id is not None:
            self.id = id

        if log_level is not None:
            self.log_level = log_level

        if emf_uri is not None:
            self.emf_uri = emf_uri

        if context_field_class is not None:
            self.context_field_class = context_field_class

        if payload_field_class is not None:
            self.payload_field_class = payload_field_class
Beispiel #5
0
    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.stream_class_create_empty(None)

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

        super().__init__(ptr)

        if name is not None:
            self.name = name

        if id is not None:
            self.id = id

        if packet_context_field_class is not None:
            self.packet_context_field_class = packet_context_field_class

        if event_header_field_class is not None:
            self.event_header_field_class = event_header_field_class

        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:
                self.add_event_class(event_class)
Beispiel #6
0
    def __init__(self,
                 name,
                 description=None,
                 frequency=None,
                 precision=None,
                 offset=None,
                 is_absolute=None,
                 uuid=None):
        utils._check_str(name)
        ptr = native_bt.ctf_clock_create(name)

        if ptr is None:
            raise bt2.CreationError('cannot create CTF writer clock object')

        super().__init__(ptr)

        if description is not None:
            self.description = description

        if frequency is not None:
            self.frequency = frequency

        if precision is not None:
            self.precision = precision

        if offset is not None:
            self.offset = offset

        if is_absolute is not None:
            self.is_absolute = is_absolute

        if uuid is not None:
            self.uuid = uuid
Beispiel #7
0
    def __call__(self):
        event_ptr = native_bt.ctf_event_create(self._ptr)

        if event_ptr is None:
            raise bt2.CreationError('cannot create event field object')

        return bt2.event._create_from_ptr(event_ptr)
Beispiel #8
0
    def __init__(self, name=None, native_byte_order=None, env=None,
                 packet_header_field_class=None, clock_classes=None,
                 stream_classes=None):
        ptr = native_bt.trace_create()

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

        super().__init__(ptr)

        if name is not None:
            self.name = name

        if native_byte_order is not None:
            self.native_byte_order = native_byte_order

        if packet_header_field_class is not None:
            self.packet_header_field_class = packet_header_field_class

        if env is not None:
            for key, value in env.items():
                self.env[key] = value

        if clock_classes is not None:
            for clock_class in clock_classes:
                self.add_clock_class(clock_class)

        if stream_classes is not None:
            for stream_class in stream_classes:
                self.add_stream_class(stream_class)
Beispiel #9
0
    def __init__(self,
                 name,
                 id=None,
                 context_field_type=None,
                 payload_field_type=None,
                 attributes=None):
        utils._check_str(name)
        ptr = native_bt.ctf_event_class_create(name)

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

        super().__init__(ptr)

        if id is not None:
            self.id = id

        if context_field_type is not None:
            self.context_field_type = context_field_type

        if payload_field_type is not None:
            self.payload_field_type = payload_field_type

        if attributes is not None:
            for name, value in attributes.items():
                self.attributes[name] = value
Beispiel #10
0
    def __init__(cls, class_name, bases, namespace, **kwargs):
        super().__init__(class_name, bases, namespace)

        # skip our own bases; they are never directly instantiated by the user
        own_bases = (
            '_UserComponent',
            '_UserFilterSinkComponent',
            '_UserSourceComponent',
            '_UserFilterComponent',
            '_UserSinkComponent',
        )

        if class_name in own_bases:
            return

        comp_cls_name = kwargs.get('name', class_name)
        utils._check_str(comp_cls_name)
        comp_cls_descr = None
        comp_cls_help = None

        if hasattr(cls, '__doc__') and cls.__doc__ is not None:
            utils._check_str(cls.__doc__)
            docstring = _trim_docstring(cls.__doc__)
            lines = docstring.splitlines()

            if len(lines) >= 1:
                comp_cls_descr = lines[0]

            if len(lines) >= 3:
                comp_cls_help = '\n'.join(lines[2:])

        iter_cls = kwargs.get('notification_iterator_class')

        if _UserSourceComponent in bases:
            _UserComponentType._set_iterator_class(cls, iter_cls)
            cc_ptr = native_bt.py3_component_class_source_create(
                cls, comp_cls_name, comp_cls_descr, comp_cls_help)
        elif _UserFilterComponent in bases:
            _UserComponentType._set_iterator_class(cls, iter_cls)
            cc_ptr = native_bt.py3_component_class_filter_create(
                cls, comp_cls_name, comp_cls_descr, comp_cls_help)
        elif _UserSinkComponent in bases:
            if not hasattr(cls, '_consume'):
                raise bt2.IncompleteUserClass(
                    "cannot create component class '{}': missing a _consume() method"
                    .format(class_name))

            cc_ptr = native_bt.py3_component_class_sink_create(
                cls, comp_cls_name, comp_cls_descr, comp_cls_help)
        else:
            raise bt2.IncompleteUserClass(
                "cannot find a known component class base in the bases of '{}'"
                .format(class_name))

        if cc_ptr is None:
            raise bt2.CreationError(
                "cannot create component class '{}'".format(class_name))

        cls._cc_ptr = cc_ptr
Beispiel #11
0
    def __init__(self, clock_class_ptr, cycles):
        utils._check_uint64(cycles)
        ptr = native_bt.ctf_clock_value_create(clock_class_ptr, cycles)

        if ptr is None:
            raise bt2.CreationError('cannot create clock value object')

        super().__init__(ptr)
Beispiel #12
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)
Beispiel #13
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)
Beispiel #14
0
    def __init__(self, path):
        utils._check_str(path)
        ptr = native_bt.ctf_writer_create(path)

        if ptr is None:
            raise bt2.CreationError('cannot create CTF writer object')

        super().__init__(ptr)
Beispiel #15
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)
Beispiel #16
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)
Beispiel #17
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)
Beispiel #18
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)
Beispiel #19
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)
Beispiel #20
0
    def __call__(self, params=None, name=None):
        params = bt2.create_value(params)
        comp_ptr = native_bt.component_create_with_init_method_data(
            self._ptr, name, params._ptr, None)

        if comp_ptr is None:
            raise bt2.CreationError('cannot create component object')

        return _create_generic_component_from_ptr(comp_ptr)
Beispiel #21
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)
Beispiel #22
0
    def __call__(self, name=None):
        if name is not None:
            utils._check_str(name)

        stream_ptr = native_bt.ctf_stream_create(self._ptr, name)

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

        return bt2.stream._create_from_ptr(stream_ptr)
Beispiel #23
0
    def create_notification_iterator(self):
        iter_ptr = native_bt.component_filter_create_notification_iterator_with_init_method_data(
            self._ptr, None)

        if iter_ptr is None:
            raise bt2.CreationError(
                'cannot create notification iterator object')

        return bt2.notification_iterator._GenericNotificationIterator._create_from_ptr(
            iter_ptr)
Beispiel #24
0
    def __init__(self, clock_class_priorities=None):
        ptr = native_bt.clock_class_priority_map_create()

        if ptr is None:
            raise bt2.CreationError(
                'cannot create clock class priority map object')

        super().__init__(ptr)

        if clock_class_priorities is not None:
            for clock_class, priority in clock_class_priorities.items():
                self[clock_class] = priority
Beispiel #25
0
    def __call__(self, value=None):
        field_ptr = native_bt.ctf_field_create(self._ptr)

        if field_ptr is None:
            raise bt2.CreationError('cannot create {} field object'.format(self._NAME.lower()))

        field = bt2.fields._create_from_ptr(field_ptr)

        if value is not None:
            if not isinstance(field, (bt2.fields._IntegerField, bt2.fields._FloatingPointNumberField, bt2.fields._StringField)):
                raise bt2.Error('cannot assign an initial value to a {} field object'.format(field._NAME))

            field.value = value

        return field
Beispiel #26
0
    def __init__(self, cc_prio_map=None):
        if cc_prio_map is not None:
            utils._check_type(
                cc_prio_map,
                bt2.clock_class_priority_map.ClockClassPriorityMap)
            cc_prio_map_ptr = cc_prio_map._ptr
        else:
            cc_prio_map_ptr = None

        ptr = native_bt.message_inactivity_create(cc_prio_map_ptr)

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

        super().__init__(ptr)
Beispiel #27
0
    def __call__(cls, *args, **kwargs):
        # create instance
        self = cls.__new__(cls)

        # assign native component pointer received from caller
        self._ptr = kwargs.get('__comp_ptr')
        name = kwargs.get('name')

        if self._ptr is None:
            # called from Python code
            self._belongs_to_native_component = False

            # py3_component_create() will call self.__init__() with the
            # desired arguments and keyword arguments. This is needed
            # because functions such as
            # bt_component_sink_set_minimum_input_count() can only be
            # called _during_ the bt_component_create() call (in
            # Python words: during self.__init__()).
            #
            # The arguments and keyword arguments to use for
            # self.__init__() are put in the object itself to find them
            # from the bt_component_create() function.
            self._init_args = args
            self._init_kwargs = kwargs
            native_bt.py3_component_create(cls._cc_ptr, self, name)

            # At this point, self._ptr should be set to non-None. If
            # it's not, an error occured during the
            # native_bt.py3_component_create() call. We consider this a
            # creation error.
            if self._ptr is None:
                raise bt2.CreationError(
                    "cannot create component object from component class '{}'".
                    format(cls.__name__))
        else:
            # Called from non-Python code (within
            # bt_component_create()): call __init__() here, after
            # removing the __comp_ptr keyword argument which is just for
            # this __call__() method.
            self._belongs_to_native_component = True
            del kwargs['__comp_ptr']

            # inject `name` into the keyword arguments
            kwargs['name'] = self.name
            self.__init__(*args, **kwargs)

        return self
Beispiel #28
0
    def create_message_iterator(self,
                                message_types=None,
                                colander_component_name=None):
        msg_types = bt2.message._msg_types_from_msg_classes(message_types)

        if colander_component_name is not None:
            utils._check_str(colander_component_name)

        msg_iter_ptr = native_bt.py3_create_output_port_msg_iter(
            int(self._ptr), colander_component_name, msg_types)

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

        return bt2.message_iterator._OutputPortMessageIterator._create_from_ptr(
            msg_iter_ptr)
Beispiel #29
0
    def __init__(self, event, cc_prio_map=None):
        utils._check_type(event, bt2.event._Event)

        if cc_prio_map is not None:
            utils._check_type(
                cc_prio_map,
                bt2.clock_class_priority_map.ClockClassPriorityMap)
            cc_prio_map_ptr = cc_prio_map._ptr
        else:
            cc_prio_map_ptr = None

        ptr = native_bt.notification_event_create(event._ptr, cc_prio_map_ptr)

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

        super().__init__(ptr)
Beispiel #30
0
    def create_notification_iterator(self,
                                     notification_types=None,
                                     colander_component_name=None):
        notif_types = bt2.notification._notif_types_from_notif_classes(
            notification_types)

        if colander_component_name is not None:
            utils._check_str(colander_component_name)

        notif_iter_ptr = native_bt.py3_create_output_port_notif_iter(
            int(self._ptr), colander_component_name, notif_types)

        if notif_iter_ptr is None:
            raise bt2.CreationError(
                'cannot create output port notification iterator')

        return bt2.notification_iterator._OutputPortNotificationIterator._create_from_ptr(
            notif_iter_ptr)