#![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::broadcast::RoleBroadcast; use mpstthree::role::end::RoleEnd; use rand::{thread_rng, Rng}; use std::collections::HashMap; use std::error::Error; use std::time::Instant; generate_atmp!(MeshedChannels, A, C, S); // Types of the payloads struct Int; struct Empty4 { payload: Int, } struct Empty2 { payload: Int, } struct Empty1 { payload: Int, } struct Empty3 { payload: Int, } struct Quit; struct Empty5 { payload: Int, } struct Ok { payload: Int, } // Binary sessions in depth 0 // Binary sessions for A type Message_0_v_0_FromAToS = SendTimed; type Message_0_v_1_FromAToS = RecvTimed; type Message_0_v_2_FromAToS = End; type Message_0_v_0_FromAToC = SendTimed; type Message_0_v_1_FromAToC = RecvTimed; // Binary sessions for C type Message_0_v_0_FromCToA = RecvTimed; type Message_0_v_1_FromCToA = SendTimed; type Message_0_v_0_FromCToS = RecvTimed; type Message_0_v_1_FromCToS = SendTimed; // Binary sessions for S type Message_0_v_0_FromSToA = RecvTimed; type Message_0_v_1_FromSToA = SendTimed; type Message_0_v_2_FromSToA = End; type Message_0_v_0_FromSToC = SendTimed; type Message_0_v_1_FromSToC = RecvTimed; // Binary sessions in depth 0.1 // Binary sessions for S type Message_0_1_v_0_FromSToA = End; type Message_0_1_v_0_FromSToC = RecvTimed; type Message_0_1_v_1_FromSToC = End; // Binary sessions for A type Message_0_1_v_0_FromAToC = RecvTimed; type Message_0_1_v_1_FromAToC = End; type Message_0_1_v_0_FromAToS = End; // Binary sessions for C type Message_0_1_v_0_FromCToS = SendTimed; type Message_0_1_v_1_FromCToS = End; type Message_0_1_v_0_FromCToA = SendTimed; type Message_0_1_v_1_FromCToA = End; // Binary sessions in depth 0.0 // Binary sessions for A type Message_0_0_v_0_FromAToC = RecvTimed; type Message_0_0_v_1_FromAToC = End; type Message_0_0_v_0_FromAToS = End; // Binary sessions for C type Message_0_0_v_0_FromCToS = SendTimed; type Message_0_0_v_1_FromCToS = RecvTimed; type Message_0_0_v_2_FromCToS = End; type Message_0_0_v_0_FromCToA = SendTimed; type Message_0_0_v_1_FromCToA = End; // Binary sessions for S type Message_0_0_v_0_FromSToA = End; type Message_0_0_v_0_FromSToC = RecvTimed; type Message_0_0_v_1_FromSToC = SendTimed; type Message_0_0_v_2_FromSToC = End; // Stacks in depth 0 // Stacks for S type Ordering_0_v_0_ForS = RoleA; type Ordering_0_v_1_ForS = RoleA; type Ordering_0_v_2_ForS = RoleC; type Ordering_0_v_3_ForS = RoleC; // Stacks for C type Ordering_0_v_0_ForC = RoleS; type Ordering_0_v_1_ForC = RoleA; type Ordering_0_v_2_ForC = RoleBroadcast; // Stacks for A type Ordering_0_v_0_ForA = RoleS; type Ordering_0_v_1_ForA = RoleS; type Ordering_0_v_2_ForA = RoleC; type Ordering_0_v_3_ForA = RoleC; // Stacks in depth 0.1 // Stacks for A type Ordering_0_1_v_0_ForA = RoleC; type Ordering_0_1_v_1_ForA = RoleEnd; // Stacks for C type Ordering_0_1_v_0_ForC = RoleA; type Ordering_0_1_v_1_ForC = RoleS; type Ordering_0_1_v_2_ForC = RoleEnd; // Stacks for S type Ordering_0_1_v_0_ForS = RoleC; type Ordering_0_1_v_1_ForS = RoleEnd; // Stacks in depth 0.0 // Stacks for A type Ordering_0_0_v_0_ForA = RoleC; type Ordering_0_0_v_1_ForA = RoleEnd; // Stacks for C type Ordering_0_0_v_0_ForC = RoleA; type Ordering_0_0_v_1_ForC = RoleS; type Ordering_0_0_v_2_ForC = RoleS; type Ordering_0_0_v_3_ForC = RoleEnd; // Stacks for S type Ordering_0_0_v_0_ForS = RoleC; type Ordering_0_0_v_1_ForS = RoleC; type Ordering_0_0_v_2_ForS = RoleEnd; // Enums (Branchings) in depth 0 // Enums (Branchings) for A enum Choice_0_FromCToA { Branching0(Endpoint_0_0_ForA), Branching1(Endpoint_0_1_ForA), } // Enums (Branchings) for S enum Choice_0_FromCToS { Branching0(Endpoint_0_0_ForS), Branching1(Endpoint_0_1_ForS), } // Endpoints in depth 0 // Endpoint for role A type Endpoint_0_ForA = MeshedChannels; // Endpoint for role C type Endpoint_0_ForC = MeshedChannels; // Endpoint for role S type Endpoint_0_ForS = MeshedChannels; // Endpoints in depth 0.1 // Endpoint for role A type Endpoint_0_1_ForA = MeshedChannels< Message_0_1_v_0_FromAToC, Message_0_1_v_0_FromAToS, Ordering_0_1_v_0_ForA, NameA, >; // Endpoint for role C type Endpoint_0_1_ForC = MeshedChannels< Message_0_1_v_0_FromCToA, Message_0_1_v_0_FromCToS, Ordering_0_1_v_0_ForC, NameC, >; // Endpoint for role S type Endpoint_0_1_ForS = MeshedChannels< Message_0_1_v_0_FromSToA, Message_0_1_v_0_FromSToC, Ordering_0_1_v_0_ForS, NameS, >; // Endpoints in depth 0.0 // Endpoint for role A type Endpoint_0_0_ForA = MeshedChannels< Message_0_0_v_0_FromAToC, Message_0_0_v_0_FromAToS, Ordering_0_0_v_0_ForA, NameA, >; // Endpoint for role C type Endpoint_0_0_ForC = MeshedChannels< Message_0_0_v_0_FromCToA, Message_0_0_v_0_FromCToS, Ordering_0_0_v_0_ForC, NameC, >; // Endpoint for role S type Endpoint_0_0_ForS = MeshedChannels< Message_0_0_v_0_FromSToA, Message_0_0_v_0_FromSToC, Ordering_0_0_v_0_ForS, NameS, >; // 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(Empty1 { payload: Int }, all_clocks)?; let (_empty2, s) = s.recv(all_clocks)?; let s = s.send(Empty4 { payload: Int }, all_clocks)?; offer_mpst!(s, all_clocks, { Choice_0_FromCToA::Branching0(s) => { let (_ok, s) = s.recv(all_clocks)?; s.close() }, Choice_0_FromCToA::Branching1(s) => { let (_ok, 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 (_empty3, s) = s.recv(all_clocks)?; let (_empty4, s) = s.recv(all_clocks)?; let choice: i32 = thread_rng().gen_range(1..=3); if choice != 1 { let s: Endpoint_0_0_ForC = choose_mpst_c_to_all!( s, all_clocks, Choice_0_FromCToA::Branching0, Choice_0_FromCToS::Branching0, ); let s = s.send(Ok { payload: Int }, all_clocks)?; let s = s.send(Ok { payload: Int }, all_clocks)?; let (_empty5, s) = s.recv(all_clocks)?; s.close() } else { let s: Endpoint_0_1_ForC = choose_mpst_c_to_all!( s, all_clocks, Choice_0_FromCToA::Branching1, Choice_0_FromCToS::Branching1, ); let s = s.send(Quit, all_clocks)?; let s = s.send(Quit, all_clocks)?; s.close() } } fn endpoint_s_0_v_0( s: Endpoint_0_ForS, all_clocks: &mut HashMap, ) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); let (_empty1, s) = s.recv(all_clocks)?; let s = s.send(Empty2 { payload: Int }, all_clocks)?; let s = s.send(Empty3 { payload: Int }, all_clocks)?; offer_mpst!(s, all_clocks, { Choice_0_FromCToS::Branching0(s) => { let (_ok, s) = s.recv(all_clocks)?; let s = s.send(Empty5 { payload: Int }, all_clocks)?; s.close() }, Choice_0_FromCToS::Branching1(s) => { let (_ok, s) = s.recv(all_clocks)?; s.close() }, }) } fn main() { let (thread_a, thread_c, thread_s) = fork_mpst(endpoint_a_0_v_0, endpoint_c_0_v_0, endpoint_s_0_v_0); println!("Thread A: {:?}", thread_a.join()); println!("Thread C: {:?}", thread_c.join()); println!("Thread S: {:?}", thread_s.join()); }