Commit | Line | Data |
---|---|---|
188edac1 SM |
1 | import bt2 |
2 | ||
3 | ||
4 | class TheIteratorOfAllEvil(bt2._UserMessageIterator): | |
8d8b141d | 5 | def __init__(self, config, port): |
188edac1 SM |
6 | tc, sc, ec1, ec2, params = port.user_data |
7 | trace = tc() | |
8 | stream = trace.create_stream(sc) | |
9 | ||
e90ed87f SM |
10 | if params['with-packet-msgs']: |
11 | packet = stream.create_packet() | |
188edac1 SM |
12 | |
13 | if params['with-stream-msgs-cs']: | |
14 | sb_msg = self._create_stream_beginning_message(stream, 100) | |
15 | else: | |
16 | sb_msg = self._create_stream_beginning_message(stream) | |
17 | ||
e90ed87f SM |
18 | parent = packet if params['with-packet-msgs'] else stream |
19 | ||
20 | ev_msg1 = self._create_event_message(ec1, parent, 300) | |
21 | ev_msg2 = self._create_event_message(ec2, parent, 400) | |
188edac1 SM |
22 | |
23 | if params['with-stream-msgs-cs']: | |
24 | se_msg = self._create_stream_end_message(stream, 1000) | |
25 | else: | |
26 | se_msg = self._create_stream_end_message(stream) | |
27 | ||
e90ed87f SM |
28 | self._msgs = [] |
29 | ||
30 | self._msgs.append(sb_msg) | |
31 | ||
32 | if params['with-packet-msgs']: | |
33 | self._msgs.append(self._create_packet_beginning_message(packet, 200)) | |
34 | ||
35 | self._msgs.append(ev_msg1) | |
36 | self._msgs.append(ev_msg2) | |
37 | ||
38 | if params['with-packet-msgs']: | |
39 | self._msgs.append(self._create_packet_end_message(packet, 900)) | |
40 | ||
41 | self._msgs.append(se_msg) | |
42 | ||
188edac1 | 43 | self._at = 0 |
c0e46a7c | 44 | config.can_seek_forward = True |
188edac1 | 45 | |
6a91742b | 46 | def _user_seek_beginning(self): |
188edac1 SM |
47 | self._at = 0 |
48 | ||
49 | def __next__(self): | |
50 | if self._at < len(self._msgs): | |
51 | msg = self._msgs[self._at] | |
52 | self._at += 1 | |
53 | return msg | |
54 | else: | |
55 | raise StopIteration | |
56 | ||
cfbd7cf3 | 57 | |
188edac1 | 58 | @bt2.plugin_component_class |
cfbd7cf3 FD |
59 | class TheSourceOfAllEvil( |
60 | bt2._UserSourceComponent, message_iterator_class=TheIteratorOfAllEvil | |
61 | ): | |
59225a3e | 62 | def __init__(self, config, params, obj): |
188edac1 SM |
63 | tc = self._create_trace_class() |
64 | ||
e90ed87f SM |
65 | with_packets = bool(params['with-packet-msgs']) |
66 | ||
188edac1 SM |
67 | # Use a clock class with an offset, so we can test with --begin or --end |
68 | # smaller than this offset (in other words, a time that it's not | |
69 | # possible to represent with this clock class). | |
70 | cc = self._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(10000)) | |
cfbd7cf3 FD |
71 | sc = tc.create_stream_class( |
72 | default_clock_class=cc, | |
e90ed87f SM |
73 | supports_packets=with_packets, |
74 | packets_have_beginning_default_clock_snapshot=with_packets, | |
75 | packets_have_end_default_clock_snapshot=with_packets, | |
cfbd7cf3 | 76 | ) |
188edac1 SM |
77 | ec1 = sc.create_event_class(name='event 1') |
78 | ec2 = sc.create_event_class(name='event 2') | |
79 | self._add_output_port('out', (tc, sc, ec1, ec2, params)) | |
80 | ||
81 | ||
82 | bt2.register_plugin(__name__, 'test-trimmer') |