#![allow(dead_code, non_camel_case_types, unused_variables)] use mpstthree::binary::struct_trait::end::End; use mpstthree::binary_atmp::struct_trait::{recv::RecvTimed, send::SendTimed}; use mpstthree::generate_atmp; use mpstthree::role::end::RoleEnd; use std::collections::HashMap; use std::error::Error; use std::time::Instant; use std::thread::sleep; // Used for pausing a thread use std::time::Duration; // Used for declaring the duration for sleep generate_atmp!(MeshedChannels, A, B, C); // Types of the payloads struct Payload; struct Integer; struct Stri; struct Test4 { payload: Payload, } struct Test5 { payload: Payload, } struct Test2 { payload: Integer, } struct Test3 { payload: Stri, } struct Test1; // Binary sessions in depth 0 // Binary sessions for B type Message_0_v_0_FromBToC = SendTimed; type Message_0_v_1_FromBToC = End; type Message_0_v_0_FromBToA = RecvTimed; type Message_0_v_1_FromBToA = RecvTimed; type Message_0_v_2_FromBToA = RecvTimed; type Message_0_v_3_FromBToA = RecvTimed; type Message_0_v_4_FromBToA = RecvTimed; type Message_0_v_5_FromBToA = RecvTimed; type Message_0_v_6_FromBToA = RecvTimed; type Message_0_v_7_FromBToA = End; // Binary sessions for C type Message_0_v_0_FromCToB = RecvTimed; type Message_0_v_1_FromCToB = End; type Message_0_v_0_FromCToA = End; // Binary sessions for A type Message_0_v_0_FromAToB = SendTimed; type Message_0_v_1_FromAToB = SendTimed; type Message_0_v_2_FromAToB = SendTimed; type Message_0_v_3_FromAToB = SendTimed; type Message_0_v_4_FromAToB = SendTimed; type Message_0_v_5_FromAToB = SendTimed; type Message_0_v_6_FromAToB = SendTimed; type Message_0_v_7_FromAToB = End; type Message_0_v_0_FromAToC = End; // Stacks in depth 0 // Stacks for A type Ordering_0_v_0_ForA = RoleB; type Ordering_0_v_1_ForA = RoleB; type Ordering_0_v_2_ForA = RoleB; type Ordering_0_v_3_ForA = RoleB; type Ordering_0_v_4_ForA = RoleB; type Ordering_0_v_5_ForA = RoleB; type Ordering_0_v_6_ForA = RoleB; type Ordering_0_v_7_ForA = RoleEnd; // Stacks for B type Ordering_0_v_0_ForB = RoleA; type Ordering_0_v_1_ForB = RoleC; type Ordering_0_v_2_ForB = RoleA; type Ordering_0_v_3_ForB = RoleA; type Ordering_0_v_4_ForB = RoleA; type Ordering_0_v_5_ForB = RoleA; type Ordering_0_v_6_ForB = RoleA; type Ordering_0_v_7_ForB = RoleA; type Ordering_0_v_8_ForB = RoleEnd; // Stacks for C type Ordering_0_v_0_ForC = RoleB; type Ordering_0_v_1_ForC = RoleEnd; // Endpoints in depth 0 // Endpoint for role A type Endpoint_0_ForA = MeshedChannels; // Endpoint for role B type Endpoint_0_ForB = MeshedChannels; // Endpoint for role C type Endpoint_0_ForC = MeshedChannels; // Fill in the functions here. fn endpoint_a_0_v_0( s: Endpoint_0_ForA, all_clocks: &mut HashMap, ) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); let s = s.send(Test1, all_clocks)?; let s = s.send(Test1, all_clocks)?; let s = s.send(Test1, all_clocks)?; sleep(Duration::from_secs(1)); let s = s.send(Test5 { payload: Payload }, all_clocks)?; let s = s.send(Test2 { payload: Integer }, all_clocks)?; let s = s.send(Test3 { payload: Stri }, all_clocks)?; let s = s.send(Test4 { payload: Payload }, all_clocks)?; s.close() } fn endpoint_b_0_v_0( s: Endpoint_0_ForB, all_clocks: &mut HashMap, ) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); let (_, s) = s.recv(all_clocks)?; let s = s.send(Test1, all_clocks)?; let (_, s) = s.recv(all_clocks)?; let (_, s) = s.recv(all_clocks)?; sleep(Duration::from_secs(1)); let (_, s) = s.recv(all_clocks)?; let (_, s) = s.recv(all_clocks)?; let (_, s) = s.recv(all_clocks)?; let (_, s) = s.recv(all_clocks)?; s.close() } fn endpoint_c_0_v_0( s: Endpoint_0_ForC, all_clocks: &mut HashMap, ) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); let (_, s) = s.recv(all_clocks)?; s.close() } pub fn main() { let (thread_a, thread_b, thread_c) = fork_mpst(endpoint_a_0_v_0, endpoint_b_0_v_0, endpoint_c_0_v_0); println!("Thread A: {:?}", thread_a.join()); println!("Thread B: {:?}", thread_b.join()); println!("Thread C: {:?}", thread_c.join()); }