37b1fdab16a8399380ed702a12fa14046078e474
1 # SPDX-License-Identifier: GPL-2.0-only
2 # Copyright (C) 2020 Geneviève Bastien <gbastien@versatic.net>
7 class TheIteratorOfProblems(bt2
._UserMessageIterator
):
8 def __init__(self
, config
, port
):
9 tc
, sc
, ec1
, params
= port
.user_data
11 stream
= trace
.create_stream(sc
)
12 event_value
= params
["value"]
15 self
._msgs
.append(self
._create
_stream
_beginning
_message
(stream
))
17 ev_msg1
= self
._create
_event
_message
(ec1
, stream
)
18 ev_msg1
.event
.payload_field
["enum_field"] = event_value
20 self
._msgs
.append(ev_msg1
)
22 self
._msgs
.append(self
._create
_stream
_end
_message
(stream
))
25 config
.can_seek_forward
= True
27 def _user_seek_beginning(self
):
31 if self
._at
< len(self
._msgs
):
32 msg
= self
._msgs
[self
._at
]
39 @bt2.plugin_component_class
40 class TheSourceOfProblems(
41 bt2
._UserSourceComponent
, message_iterator_class
=TheIteratorOfProblems
43 def __init__(self
, config
, params
, obj
):
44 tc
= self
._create
_trace
_class
()
46 enum_values_str
= params
["enum-values"]
48 sc
= tc
.create_stream_class()
50 # Create the enumeration field with the values in parameter
51 if params
["enum-signed"]:
52 enumfc
= tc
.create_signed_enumeration_field_class()
54 enumfc
= tc
.create_unsigned_enumeration_field_class()
56 groups
= str(enum_values_str
).split(" ")
59 bt2
.SignedIntegerRangeSet
60 if params
["enum-signed"]
61 else bt2
.UnsignedIntegerRangeSet
64 label
, low
, high
= group
.split(",")
66 if label
not in mappings
.keys():
67 mappings
[label
] = range_set_type()
69 mappings
[label
].add((int(low
), int(high
)))
71 for x
, y
in mappings
.items():
72 enumfc
.add_mapping(x
, y
)
74 # Create the struct field to contain the enum field class
75 struct_fc
= tc
.create_structure_field_class()
76 struct_fc
.append_member("enum_field", enumfc
)
78 # Create an event class on this stream with the struct field
79 ec1
= sc
.create_event_class(name
="with_enum", payload_field_class
=struct_fc
)
80 self
._add
_output
_port
("out", (tc
, sc
, ec1
, params
))
83 bt2
.register_plugin(__name__
, "test-pretty")
This page took 0.032366 seconds and 5 git commands to generate.