1 # The MIT License (MIT)
3 # Copyright (c) 2015-2020 Philippe Proulx <pproulx@efficios.com>
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 import barectf
.version
as barectf_version
25 from typing
import Optional
, Any
, FrozenSet
, Mapping
, Iterator
, Set
, Union
, Callable
27 from barectf
.typing
import Count
, Alignment
, _OptStr
, Id
28 import collections
.abc
36 class ByteOrder(enum
.Enum
):
43 def alignment(self
) -> Alignment
:
44 raise NotImplementedError
47 def size_is_dynamic(self
):
51 class _BitArrayFieldType(_FieldType
):
52 def __init__(self
, size
: Count
, alignment
: Alignment
= Alignment(1)):
54 self
._alignment
= alignment
57 def size(self
) -> Count
:
61 def alignment(self
) -> Alignment
:
62 return self
._alignment
65 class DisplayBase(enum
.Enum
):
72 class _IntegerFieldType(_BitArrayFieldType
):
73 def __init__(self
, size
: Count
, alignment
: Optional
[Alignment
] = None,
74 preferred_display_base
: DisplayBase
= DisplayBase
.DECIMAL
):
76 alignment
= Alignment(8 if size
% 8 == 0 else 1)
78 super().__init
__(size
, alignment
)
79 self
._preferred
_display
_base
= preferred_display_base
82 def preferred_display_base(self
) -> DisplayBase
:
83 return self
._preferred
_display
_base
86 class UnsignedIntegerFieldType(_IntegerFieldType
):
87 def __init__(self
, *args
):
88 super().__init
__(*args
)
89 self
._mapped
_clk
_type
_name
= None
92 class SignedIntegerFieldType(_IntegerFieldType
):
96 class EnumerationFieldTypeMappingRange
:
97 def __init__(self
, lower
: int, upper
: int):
102 def lower(self
) -> int:
106 def upper(self
) -> int:
109 def __eq__(self
, other
: Any
) -> bool:
110 if type(other
) is not type(self
):
113 return (self
._lower
, self
._upper
) == (other
._lower
, other
._upper
)
115 def __hash__(self
) -> int:
116 return hash((self
._lower
, self
._upper
))
118 def contains(self
, value
: int) -> bool:
119 return self
._lower
<= value
<= self
._upper
122 class EnumerationFieldTypeMapping
:
123 def __init__(self
, ranges
: Set
[EnumerationFieldTypeMappingRange
]):
124 self
._ranges
= frozenset(ranges
)
127 def ranges(self
) -> FrozenSet
[EnumerationFieldTypeMappingRange
]:
130 def ranges_contain_value(self
, value
: int) -> bool:
131 return any([rg
.contains(value
) for rg
in self
._ranges
])
134 _EnumFtMappings
= Mapping
[str, EnumerationFieldTypeMapping
]
137 class EnumerationFieldTypeMappings(collections
.abc
.Mapping
):
138 def __init__(self
, mappings
: _EnumFtMappings
):
139 self
._mappings
= {label
: mapping
for label
, mapping
in mappings
.items()}
141 def __getitem__(self
, key
: str) -> EnumerationFieldTypeMapping
:
142 return self
._mappings
[key
]
144 def __iter__(self
) -> Iterator
[str]:
145 return iter(self
._mappings
)
147 def __len__(self
) -> int:
148 return len(self
._mappings
)
151 class _EnumerationFieldType(_IntegerFieldType
):
152 def __init__(self
, size
: Count
, alignment
: Optional
[Alignment
] = None,
153 preferred_display_base
: DisplayBase
= DisplayBase
.DECIMAL
,
154 mappings
: Optional
[_EnumFtMappings
] = None):
155 super().__init
__(size
, alignment
, preferred_display_base
)
156 self
._mappings
= EnumerationFieldTypeMappings({})
158 if mappings
is not None:
159 self
._mappings
= EnumerationFieldTypeMappings(mappings
)
162 def mappings(self
) -> EnumerationFieldTypeMappings
:
163 return self
._mappings
165 def labels_for_value(self
, value
: int) -> Set
[str]:
168 for label
, mapping
in self
._mappings
.items():
169 if mapping
.ranges_contain_value(value
):
175 class UnsignedEnumerationFieldType(_EnumerationFieldType
, UnsignedIntegerFieldType
):
179 class SignedEnumerationFieldType(_EnumerationFieldType
, SignedIntegerFieldType
):
183 class RealFieldType(_BitArrayFieldType
):
187 class StringFieldType(_FieldType
):
189 def alignment(self
) -> Alignment
:
193 def size_is_dynamic(self
):
197 class _ArrayFieldType(_FieldType
):
198 def __init__(self
, element_field_type
: _FieldType
):
199 self
._element
_field
_type
= element_field_type
202 def element_field_type(self
) -> _FieldType
:
203 return self
._element
_field
_type
206 def alignment(self
) -> Alignment
:
207 return self
._element
_field
_type
.alignment
210 class StaticArrayFieldType(_ArrayFieldType
):
211 def __init__(self
, length
: Count
, element_field_type
: _FieldType
):
212 super().__init
__(element_field_type
)
213 self
._length
= length
216 def length(self
) -> Count
:
220 class StructureFieldTypeMember
:
221 def __init__(self
, field_type
: _FieldType
):
222 self
._field
_type
= field_type
225 def field_type(self
) -> _FieldType
:
226 return self
._field
_type
229 _StructFtMembers
= Mapping
[str, StructureFieldTypeMember
]
232 class StructureFieldTypeMembers(collections
.abc
.Mapping
):
233 def __init__(self
, members
: _StructFtMembers
):
234 self
._members
= collections
.OrderedDict()
236 for name
, member
in members
.items():
237 assert type(member
) is StructureFieldTypeMember
238 self
._members
[name
] = member
240 def __getitem__(self
, key
: str) -> StructureFieldTypeMember
:
241 return self
._members
[key
]
243 def __iter__(self
) -> Iterator
[str]:
244 return iter(self
._members
)
246 def __len__(self
) -> int:
247 return len(self
._members
)
250 class StructureFieldType(_FieldType
):
251 def __init__(self
, minimum_alignment
: Alignment
= Alignment(1),
252 members
: Optional
[_StructFtMembers
] = None):
253 self
._minimum
_alignment
= minimum_alignment
254 self
._members
= StructureFieldTypeMembers({})
256 if members
is not None:
257 self
._members
= StructureFieldTypeMembers(members
)
259 self
._set
_alignment
()
261 def _set_alignment(self
):
262 self
._alignment
: Alignment
= self
._minimum
_alignment
264 for member
in self
._members
.values():
265 if member
.field_type
.alignment
> self
._alignment
:
266 self
._alignment
= member
.field_type
.alignment
269 def minimum_alignment(self
) -> Alignment
:
270 return self
._minimum
_alignment
273 def alignment(self
) -> Alignment
:
274 return self
._alignment
277 def size_is_dynamic(self
):
278 return any([member
.field_type
.size_is_dynamic
for member
in self
.members
.values()])
281 def members(self
) -> StructureFieldTypeMembers
:
288 def __eq__(self
, other
: Any
) -> bool:
289 if type(other
) is not type(self
):
292 return self
._name
== other
._name
294 def __lt__(self
, other
: '_UniqueByName'):
295 assert type(self
) is type(other
)
296 return self
._name
< other
._name
298 def __hash__(self
) -> int:
299 return hash(self
._name
)
302 _OptFt
= Optional
[_FieldType
]
303 _OptStructFt
= Optional
[StructureFieldType
]
304 LogLevel
= typing
.NewType('LogLevel', int)
307 class EventType(_UniqueByName
):
308 def __init__(self
, name
: str, log_level
: Optional
[LogLevel
] = None,
309 specific_context_field_type
: _OptStructFt
= None, payload_field_type
: _OptStructFt
= None):
310 self
._id
: Optional
[Id
] = None
312 self
._log
_level
= log_level
313 self
._specific
_context
_field
_type
= specific_context_field_type
314 self
._payload
_field
_type
= payload_field_type
317 def id(self
) -> Optional
[Id
]:
321 def name(self
) -> str:
325 def log_level(self
) -> Optional
[LogLevel
]:
326 return self
._log
_level
329 def specific_context_field_type(self
) -> _OptStructFt
:
330 return self
._specific
_context
_field
_type
333 def payload_field_type(self
) -> _OptStructFt
:
334 return self
._payload
_field
_type
337 class ClockTypeOffset
:
338 def __init__(self
, seconds
: int = 0, cycles
: Count
= Count(0)):
339 self
._seconds
= seconds
340 self
._cycles
= cycles
343 def seconds(self
) -> int:
347 def cycles(self
) -> Count
:
351 _OptUuid
= Optional
[uuidp
.UUID
]
354 class ClockType(_UniqueByName
):
355 def __init__(self
, name
: str, frequency
: Count
= Count(int(1e9
)), uuid
: _OptUuid
= None,
356 description
: _OptStr
= None, precision
: Count
= Count(0),
357 offset
: Optional
[ClockTypeOffset
] = None, origin_is_unix_epoch
: bool = False):
359 self
._frequency
= frequency
361 self
._description
= description
362 self
._precision
= precision
363 self
._offset
= ClockTypeOffset()
365 if offset
is not None:
366 self
._offset
= offset
368 self
._origin
_is
_unix
_epoch
= origin_is_unix_epoch
371 def name(self
) -> str:
375 def frequency(self
) -> Count
:
376 return self
._frequency
379 def uuid(self
) -> _OptUuid
:
383 def description(self
) -> _OptStr
:
384 return self
._description
387 def precision(self
) -> Count
:
388 return self
._precision
391 def offset(self
) -> ClockTypeOffset
:
395 def origin_is_unix_epoch(self
) -> bool:
396 return self
._origin
_is
_unix
_epoch
399 DEFAULT_FIELD_TYPE
= 'default'
400 _DefaultableUIntFt
= Union
[str, UnsignedIntegerFieldType
]
401 _OptDefaultableUIntFt
= Optional
[_DefaultableUIntFt
]
402 _OptUIntFt
= Optional
[UnsignedIntegerFieldType
]
405 class StreamTypePacketFeatures
:
406 def __init__(self
, total_size_field_type
: _DefaultableUIntFt
= DEFAULT_FIELD_TYPE
,
407 content_size_field_type
: _DefaultableUIntFt
= DEFAULT_FIELD_TYPE
,
408 beginning_time_field_type
: _OptDefaultableUIntFt
= None,
409 end_time_field_type
: _OptDefaultableUIntFt
= None,
410 discarded_events_counter_field_type
: _OptDefaultableUIntFt
= None):
411 def get_ft(user_ft
: _OptDefaultableUIntFt
) -> _OptUIntFt
:
412 if user_ft
== DEFAULT_FIELD_TYPE
:
413 return UnsignedIntegerFieldType(64)
415 return typing
.cast(_OptUIntFt
, user_ft
)
417 self
._total
_size
_field
_type
= get_ft(total_size_field_type
)
418 self
._content
_size
_field
_type
= get_ft(content_size_field_type
)
419 self
._beginning
_time
_field
_type
= get_ft(beginning_time_field_type
)
420 self
._end
_time
_field
_type
= get_ft(end_time_field_type
)
421 self
._discarded
_events
_counter
_field
_type
= get_ft(discarded_events_counter_field_type
)
424 def total_size_field_type(self
) -> _OptUIntFt
:
425 return self
._total
_size
_field
_type
428 def content_size_field_type(self
) -> _OptUIntFt
:
429 return self
._content
_size
_field
_type
432 def beginning_time_field_type(self
) -> _OptUIntFt
:
433 return self
._beginning
_time
_field
_type
436 def end_time_field_type(self
) -> _OptUIntFt
:
437 return self
._end
_time
_field
_type
440 def discarded_events_counter_field_type(self
) -> _OptUIntFt
:
441 return self
._discarded
_events
_counter
_field
_type
444 class StreamTypeEventFeatures
:
445 def __init__(self
, type_id_field_type
: _OptDefaultableUIntFt
= DEFAULT_FIELD_TYPE
,
446 time_field_type
: _OptDefaultableUIntFt
= None):
447 def get_ft(user_ft
: _OptDefaultableUIntFt
) -> _OptUIntFt
:
448 if user_ft
== DEFAULT_FIELD_TYPE
:
449 return UnsignedIntegerFieldType(64)
451 return typing
.cast(_OptUIntFt
, user_ft
)
453 self
._type
_id
_field
_type
= get_ft(type_id_field_type
)
454 self
._time
_field
_type
= get_ft(time_field_type
)
457 def type_id_field_type(self
) -> _OptUIntFt
:
458 return self
._type
_id
_field
_type
461 def time_field_type(self
) -> _OptUIntFt
:
462 return self
._time
_field
_type
465 class StreamTypeFeatures
:
466 def __init__(self
, packet_features
: Optional
[StreamTypePacketFeatures
] = None,
467 event_features
: Optional
[StreamTypeEventFeatures
] = None):
468 if packet_features
is None:
469 self
._packet
_features
= StreamTypePacketFeatures()
471 self
._packet
_features
= packet_features
473 if event_features
is None:
474 self
._event
_features
= StreamTypeEventFeatures()
476 self
._event
_features
= event_features
479 def packet_features(self
) -> StreamTypePacketFeatures
:
480 return self
._packet
_features
483 def event_features(self
) -> StreamTypeEventFeatures
:
484 return self
._event
_features
487 class StreamType(_UniqueByName
):
488 def __init__(self
, name
: str, event_types
: Set
[EventType
],
489 default_clock_type
: Optional
[ClockType
] = None,
490 features
: Optional
[StreamTypeFeatures
] = None,
491 packet_context_field_type_extra_members
: Optional
[_StructFtMembers
] = None,
492 event_common_context_field_type
: _OptStructFt
= None):
493 self
._id
: Optional
[Id
] = None
495 self
._default
_clock
_type
= default_clock_type
496 self
._event
_common
_context
_field
_type
= event_common_context_field_type
497 self
._event
_types
= frozenset(event_types
)
500 for index
, ev_type
in enumerate(sorted(self
._event
_types
, key
=lambda evt
: evt
.name
)):
501 assert ev_type
._id
is None
502 ev_type
._id
= Id(index
)
504 self
._set
_features
(features
)
505 self
._packet
_context
_field
_type
_extra
_members
= StructureFieldTypeMembers({})
507 if packet_context_field_type_extra_members
is not None:
508 self
._packet
_context
_field
_type
_extra
_members
= StructureFieldTypeMembers(packet_context_field_type_extra_members
)
510 self
._set
_pkt
_ctx
_ft
()
511 self
._set
_ev
_header
_ft
()
513 def _set_features(self
, features
: Optional
[StreamTypeFeatures
]):
514 if features
is not None:
515 self
._features
= features
519 pkt_beginning_time_ft
= None
520 pkt_end_time_ft
= None
522 if self
._default
_clock
_type
is not None:
523 # Automatic time field types because the stream type has a
524 # default clock type.
525 ev_time_ft
= DEFAULT_FIELD_TYPE
526 pkt_beginning_time_ft
= DEFAULT_FIELD_TYPE
527 pkt_end_time_ft
= DEFAULT_FIELD_TYPE
529 self
._features
= StreamTypeFeatures(StreamTypePacketFeatures(beginning_time_field_type
=pkt_beginning_time_ft
,
530 end_time_field_type
=pkt_end_time_ft
),
531 StreamTypeEventFeatures(time_field_type
=ev_time_ft
))
533 def _set_ft_mapped_clk_type_name(self
, ft
: Optional
[UnsignedIntegerFieldType
]):
537 if self
._default
_clock
_type
is not None:
538 assert isinstance(ft
, UnsignedIntegerFieldType
)
539 ft
._mapped
_clk
_type
_name
= self
._default
_clock
_type
.name
541 def _set_pkt_ctx_ft(self
):
544 def add_member_if_exists(name
: str, ft
: _FieldType
, set_mapped_clk_type_name
: bool = False):
548 if set_mapped_clk_type_name
:
549 self
._set
_ft
_mapped
_clk
_type
_name
(typing
.cast(UnsignedIntegerFieldType
, ft
))
551 members
[name
] = StructureFieldTypeMember(ft
)
553 members
= collections
.OrderedDict([
556 StructureFieldTypeMember(self
._features
.packet_features
.total_size_field_type
)
560 StructureFieldTypeMember(self
._features
.packet_features
.content_size_field_type
)
564 add_member_if_exists('timestamp_begin',
565 self
._features
.packet_features
.beginning_time_field_type
, True)
566 add_member_if_exists('timestamp_end', self
._features
.packet_features
.end_time_field_type
,
568 add_member_if_exists('events_discarded',
569 self
._features
.packet_features
.discarded_events_counter_field_type
)
571 if self
._packet
_context
_field
_type
_extra
_members
is not None:
572 for name
, field_type
in self
._packet
_context
_field
_type
_extra
_members
.items():
573 assert name
not in members
574 members
[name
] = field_type
576 self
._pkt
_ctx
_ft
= StructureFieldType(8, members
)
578 def _set_ev_header_ft(self
):
579 members
= collections
.OrderedDict()
581 if self
._features
.event_features
.type_id_field_type
is not None:
582 members
['id'] = StructureFieldTypeMember(self
._features
.event_features
.type_id_field_type
)
584 if self
._features
.event_features
.time_field_type
is not None:
585 ft
= self
._features
.event_features
.time_field_type
586 self
._set
_ft
_mapped
_clk
_type
_name
(ft
)
587 members
['timestamp'] = StructureFieldTypeMember(ft
)
589 self
._ev
_header
_ft
= StructureFieldType(8, members
)
592 def id(self
) -> Optional
[Id
]:
596 def name(self
) -> str:
600 def default_clock_type(self
) -> Optional
[ClockType
]:
601 return self
._default
_clock
_type
604 def features(self
) -> StreamTypeFeatures
:
605 return self
._features
608 def packet_context_field_type_extra_members(self
) -> StructureFieldTypeMembers
:
609 return self
._packet
_context
_field
_type
_extra
_members
612 def event_common_context_field_type(self
) -> _OptStructFt
:
613 return self
._event
_common
_context
_field
_type
616 def event_types(self
) -> FrozenSet
[EventType
]:
617 return self
._event
_types
620 _OptUuidFt
= Optional
[Union
[str, StaticArrayFieldType
]]
623 class TraceTypeFeatures
:
624 def __init__(self
, magic_field_type
: _OptDefaultableUIntFt
= DEFAULT_FIELD_TYPE
,
625 uuid_field_type
: _OptUuidFt
= None,
626 stream_type_id_field_type
: _OptDefaultableUIntFt
= DEFAULT_FIELD_TYPE
):
627 def get_field_type(user_ft
: Optional
[Union
[str, _FieldType
]],
628 create_default_ft
: Callable
[[], _FieldType
]) -> _OptFt
:
629 if user_ft
== DEFAULT_FIELD_TYPE
:
630 return create_default_ft()
632 return typing
.cast(_OptFt
, user_ft
)
634 def create_default_magic_ft():
635 return UnsignedIntegerFieldType(32)
637 def create_default_uuid_ft():
638 return StaticArrayFieldType(Count(16), UnsignedIntegerFieldType(8))
640 def create_default_stream_type_id_ft():
641 return UnsignedIntegerFieldType(64)
643 self
._magic
_field
_type
= typing
.cast(_OptUIntFt
, get_field_type(magic_field_type
, create_default_magic_ft
))
644 self
._uuid
_field
_type
= typing
.cast(Optional
[StaticArrayFieldType
],
645 get_field_type(uuid_field_type
, create_default_uuid_ft
))
646 self
._stream
_type
_id
_field
_type
= typing
.cast(_OptUIntFt
,
647 get_field_type(stream_type_id_field_type
,
648 create_default_stream_type_id_ft
))
651 def magic_field_type(self
) -> _OptUIntFt
:
652 return self
._magic
_field
_type
655 def uuid_field_type(self
) -> Optional
[StaticArrayFieldType
]:
656 return self
._uuid
_field
_type
659 def stream_type_id_field_type(self
) -> _OptUIntFt
:
660 return self
._stream
_type
_id
_field
_type
664 def __init__(self
, stream_types
: Set
[StreamType
], uuid
: _OptUuid
= None,
665 features
: Optional
[TraceTypeFeatures
] = None):
666 self
._stream
_types
= frozenset(stream_types
)
669 for index
, stream_type
in enumerate(sorted(self
._stream
_types
, key
=lambda st
: st
.name
)):
670 assert stream_type
._id
is None
671 stream_type
._id
= Id(index
)
674 self
._set
_features
(features
)
675 self
._set
_pkt
_header
_ft
()
677 def _set_features(self
, features
: Optional
[TraceTypeFeatures
]):
678 if features
is not None:
679 self
._features
= features
682 # automatic UUID field type because the trace type has a UUID
683 uuid_ft
= None if self
._uuid
is None else DEFAULT_FIELD_TYPE
684 self
._features
= TraceTypeFeatures(uuid_field_type
=uuid_ft
)
686 def _set_pkt_header_ft(self
):
687 members
= collections
.OrderedDict()
689 def add_member_if_exists(name
: str, ft
: _OptFt
):
693 members
[name
] = StructureFieldTypeMember(ft
)
695 add_member_if_exists('magic', self
._features
.magic_field_type
)
696 add_member_if_exists('uuid', self
._features
.uuid_field_type
)
697 add_member_if_exists('stream_id', self
._features
.stream_type_id_field_type
)
698 self
._pkt
_header
_ft
= StructureFieldType(8, members
)
701 def uuid(self
) -> _OptUuid
:
705 def stream_types(self
) -> FrozenSet
[StreamType
]:
706 return self
._stream
_types
708 def stream_type(self
, name
: str) -> Optional
[StreamType
]:
709 for cand_stream_type
in self
._stream
_types
:
710 if cand_stream_type
.name
== name
:
711 return cand_stream_type
716 def features(self
) -> TraceTypeFeatures
:
717 return self
._features
720 def clock_types(self
) -> Set
[ClockType
]:
723 for stream_type
in self
._stream
_types
:
724 if stream_type
.default_clock_type
is not None:
725 clk_types
.add(stream_type
.default_clock_type
)
730 _EnvEntry
= Union
[str, int]
731 _EnvEntries
= Mapping
[str, _EnvEntry
]
734 class TraceEnvironment(collections
.abc
.Mapping
):
735 def __init__(self
, environment
: _EnvEntries
):
736 self
._env
= {name
: value
for name
, value
in environment
.items()}
738 def __getitem__(self
, key
: str) -> _EnvEntry
:
739 return self
._env
[key
]
741 def __iter__(self
) -> Iterator
[str]:
742 return iter(self
._env
)
744 def __len__(self
) -> int:
745 return len(self
._env
)
749 def __init__(self
, type: TraceType
, environment
: Optional
[_EnvEntries
] = None):
751 self
._set
_env
(environment
)
753 def _set_env(self
, environment
: Optional
[_EnvEntries
]):
754 init_env
= collections
.OrderedDict([
756 ('tracer_name', 'barectf'),
757 ('tracer_major', barectf_version
.__major
_version
__),
758 ('tracer_minor', barectf_version
.__minor
_version
__),
759 ('tracer_patch', barectf_version
.__patch
_version
__),
760 ('barectf_gen_date', str(datetime
.datetime
.now().isoformat())),
763 if environment
is None:
766 init_env
.update(environment
)
767 self
._env
= TraceEnvironment(typing
.cast(_EnvEntries
, init_env
))
770 def type(self
) -> TraceType
:
774 def environment(self
) -> TraceEnvironment
:
778 _ClkTypeCTypes
= Mapping
[ClockType
, str]
781 class ClockTypeCTypes(collections
.abc
.Mapping
):
782 def __init__(self
, c_types
: _ClkTypeCTypes
):
783 self
._c
_types
= {clk_type
: c_type
for clk_type
, c_type
in c_types
.items()}
785 def __getitem__(self
, key
: ClockType
) -> str:
786 return self
._c
_types
[key
]
788 def __iter__(self
) -> Iterator
[ClockType
]:
789 return iter(self
._c
_types
)
791 def __len__(self
) -> int:
792 return len(self
._c
_types
)
795 class ConfigurationCodeGenerationHeaderOptions
:
796 def __init__(self
, identifier_prefix_definition
: bool = False,
797 default_stream_type_name_definition
: bool = False):
798 self
._identifier
_prefix
_definition
= identifier_prefix_definition
799 self
._default
_stream
_type
_name
_definition
= default_stream_type_name_definition
802 def identifier_prefix_definition(self
) -> bool:
803 return self
._identifier
_prefix
_definition
806 def default_stream_type_name_definition(self
) -> bool:
807 return self
._default
_stream
_type
_name
_definition
810 class ConfigurationCodeGenerationOptions
:
811 def __init__(self
, identifier_prefix
: str = 'barectf_', file_name_prefix
: str = 'barectf',
812 default_stream_type
: Optional
[StreamType
] = None,
813 header_options
: Optional
[ConfigurationCodeGenerationHeaderOptions
] = None,
814 clock_type_c_types
: Optional
[_ClkTypeCTypes
] = None):
815 self
._identifier
_prefix
= identifier_prefix
816 self
._file
_name
_prefix
= file_name_prefix
817 self
._default
_stream
_type
= default_stream_type
819 self
._header
_options
= ConfigurationCodeGenerationHeaderOptions()
821 if header_options
is not None:
822 self
._header
_options
= header_options
824 self
._clock
_type
_c
_types
= ClockTypeCTypes({})
826 if clock_type_c_types
is not None:
827 self
._clock
_type
_c
_types
= ClockTypeCTypes(clock_type_c_types
)
830 def identifier_prefix(self
) -> str:
831 return self
._identifier
_prefix
834 def file_name_prefix(self
) -> str:
835 return self
._file
_name
_prefix
838 def default_stream_type(self
) -> Optional
[StreamType
]:
839 return self
._default
_stream
_type
842 def header_options(self
) -> ConfigurationCodeGenerationHeaderOptions
:
843 return self
._header
_options
846 def clock_type_c_types(self
) -> ClockTypeCTypes
:
847 return self
._clock
_type
_c
_types
850 class ConfigurationOptions
:
852 code_generation_options
: Optional
[ConfigurationCodeGenerationOptions
] = None):
853 self
._code
_generation
_options
= ConfigurationCodeGenerationOptions()
855 if code_generation_options
is not None:
856 self
._code
_generation
_options
= code_generation_options
859 def code_generation_options(self
) -> ConfigurationCodeGenerationOptions
:
860 return self
._code
_generation
_options
864 def __init__(self
, trace
: Trace
, target_byte_order
: ByteOrder
,
865 options
: Optional
[ConfigurationOptions
] = None):
867 self
._options
= ConfigurationOptions()
868 self
._target
_byte
_order
= target_byte_order
870 if options
is not None:
871 self
._options
= options
873 clk_type_c_types
= self
._options
.code_generation_options
.clock_type_c_types
875 for stream_type
in trace
.type.stream_types
:
876 def_clk_type
= stream_type
.default_clock_type
878 if def_clk_type
is None:
881 if def_clk_type
not in clk_type_c_types
:
882 clk_type_c_types
._c
_types
[def_clk_type
] = 'uint32_t'
885 def trace(self
) -> Trace
:
889 def target_byte_order(self
):
890 return self
._target
_byte
_order
893 def options(self
) -> ConfigurationOptions
: