1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Configuration and events for communication logging.

use serde::{Serialize, Deserialize};

/// Configuration information about a communication thread.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Serialize, Deserialize)]
pub struct CommunicationSetup {
    /// `true` when this is a send thread (or the receive thread).
    pub sender: bool,
    /// The process id of the thread.
    pub process: usize,
    /// The remote process id.
    pub remote: Option<usize>,
}

/// Various communication events.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Serialize, Deserialize)]
pub enum CommunicationEvent {
    /// An observed message.
    Message(MessageEvent),
    /// A state transition.
    State(StateEvent),
}

/// An observed message.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Serialize, Deserialize)]
pub struct MessageEvent {
    /// `true` for send event, `false` for receive event
    pub is_send: bool,
    /// associated message header.
    pub header: crate::networking::MessageHeader,
}

/// Starting or stopping communication threads.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Serialize, Deserialize)]
pub struct StateEvent {
    /// Is the thread a send (vs a recv) thread.
    pub send: bool,
    /// The host process id.
    pub process: usize,
    /// The remote process id.
    pub remote: usize,
    /// Is the thread starting or stopping.
    pub start: bool,
}

impl From<MessageEvent> for CommunicationEvent {
    fn from(v: MessageEvent) -> CommunicationEvent { CommunicationEvent::Message(v) }
}
impl From<StateEvent> for CommunicationEvent {
    fn from(v: StateEvent) -> CommunicationEvent { CommunicationEvent::State(v) }
}