modality_trace_recorder_plugin/
context.rs

1use modality_api::TimelineId;
2use std::hash::Hash;
3use trace_recorder_parser::{snapshot, streaming, time::Timestamp, types::ObjectHandle};
4
5#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
6pub enum ContextSwitchOutcome {
7    /// Current task/ISR is already marked as active, we're on the same timeline
8    Same,
9    /// Switched to a new task/ISR, return the remote (previous) timeline ID and
10    /// the last event timestamped logged on the previous timeline
11    Different(TimelineId, Timestamp),
12}
13
14#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
15pub enum ContextHandle {
16    Task(ObjectHandle),
17    Isr(ObjectHandle),
18}
19
20impl ContextHandle {
21    pub fn object_handle(self) -> ObjectHandle {
22        match self {
23            ContextHandle::Task(h) => h,
24            ContextHandle::Isr(h) => h,
25        }
26    }
27}
28
29impl From<snapshot::event::TaskEvent> for ContextHandle {
30    fn from(event: snapshot::event::TaskEvent) -> Self {
31        ContextHandle::Task(event.handle)
32    }
33}
34
35impl From<snapshot::event::IsrEvent> for ContextHandle {
36    fn from(event: snapshot::event::IsrEvent) -> Self {
37        ContextHandle::Isr(event.handle)
38    }
39}
40
41impl From<streaming::event::TaskEvent> for ContextHandle {
42    fn from(event: streaming::event::TaskEvent) -> Self {
43        ContextHandle::Task(event.handle)
44    }
45}
46
47impl From<streaming::event::IsrEvent> for ContextHandle {
48    fn from(event: streaming::event::IsrEvent) -> Self {
49        ContextHandle::Isr(event.handle)
50    }
51}