#![allow( clippy::type_complexity, clippy::too_many_arguments, clippy::large_enum_variant )] 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 std::collections::HashMap; use std::error::Error; use std::time::Instant; static LOOPS: i64 = 100; // Create new roles generate_atmp!(MeshedChannels, A, B, C, D, E, F); // Types // SendTimed/RecvTimed type RS = RecvTimed<(), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', End>>; type SR = SendTimed<(), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', End>>; // Roles type R2A = RoleA>; type R2B = RoleB>; type R2C = RoleC>; type R2D = RoleD>; type R2E = RoleE>; type R2F = RoleF>; // A enum Branching0fromFtoA { More( MeshedChannels< RS, RS, RS, RS, RecvTimed< (), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', RecursAtoF>, >, R2F>>>>>, NameA, >, ), Done(MeshedChannels), } type RecursAtoF = RecvTimed; // B enum Branching0fromFtoB { More( MeshedChannels< SR, RS, RS, RS, RecvTimed< (), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', RecursBtoF>, >, R2F>>>>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoF = RecvTimed; // C enum Branching0fromFtoC { More( MeshedChannels< SR, SR, RS, RS, RecvTimed< (), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', RecursCtoF>, >, R2F>>>>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoF = RecvTimed; // D enum Branching0fromFtoD { More( MeshedChannels< SR, SR, SR, RS, RecvTimed< (), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', RecursDtoF>, >, R2F>>>>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoF = RecvTimed; // E enum Branching0fromFtoE { More( MeshedChannels< SR, SR, SR, SR, RecvTimed< (), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', RecursEtoF>, >, R2F>>>>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoF = RecvTimed; // F type Choose0fromFtoA = SendTimed; type Choose0fromFtoB = SendTimed; type Choose0fromFtoC = SendTimed; type Choose0fromFtoD = SendTimed; type Choose0fromFtoE = SendTimed; type EndpointMoreF = MeshedChannels< SendTimed< (), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', Choose0fromFtoA>, >, SendTimed< (), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', Choose0fromFtoB>, >, SendTimed< (), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', Choose0fromFtoC>, >, SendTimed< (), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', Choose0fromFtoD>, >, SendTimed< (), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', Choose0fromFtoE>, >, R2A>>>>, NameF, >; // Creating the MP sessions type EndpointA = MeshedChannels, NameA>; type EndpointB = MeshedChannels, NameB>; type EndpointC = MeshedChannels, NameC>; type EndpointD = MeshedChannels, NameD>; type EndpointE = MeshedChannels, NameE>; type EndpointF = MeshedChannels< Choose0fromFtoA, Choose0fromFtoB, Choose0fromFtoC, Choose0fromFtoD, Choose0fromFtoE, RoleBroadcast, NameF, >; fn endpoint_a(s: EndpointA, all_clocks: &mut HashMap) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); offer_mpst!(s, all_clocks, { Branching0fromFtoA::Done(s) => { s.close() }, Branching0fromFtoA::More(s) => { let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; endpoint_a(s, all_clocks) }, }) } fn endpoint_b(s: EndpointB, all_clocks: &mut HashMap) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); offer_mpst!(s, all_clocks, { Branching0fromFtoB::Done(s) => { s.close() }, Branching0fromFtoB::More(s) => { let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; endpoint_b(s, all_clocks) }, }) } fn endpoint_c(s: EndpointC, all_clocks: &mut HashMap) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); offer_mpst!(s, all_clocks, { Branching0fromFtoC::Done(s) => { s.close() }, Branching0fromFtoC::More(s) => { let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; endpoint_c(s, all_clocks) }, }) } fn endpoint_d(s: EndpointD, all_clocks: &mut HashMap) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); offer_mpst!(s, all_clocks, { Branching0fromFtoD::Done(s) => { s.close() }, Branching0fromFtoD::More(s) => { let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; endpoint_d(s, all_clocks) }, }) } fn endpoint_e(s: EndpointE, all_clocks: &mut HashMap) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); offer_mpst!(s, all_clocks, { Branching0fromFtoE::Done(s) => { s.close() }, Branching0fromFtoE::More(s) => { let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; endpoint_e(s, all_clocks) }, }) } fn endpoint_f(s: EndpointF, all_clocks: &mut HashMap) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); recurs_f(s, LOOPS, all_clocks) } fn recurs_f( s: EndpointF, index: i64, all_clocks: &mut HashMap, ) -> Result<(), Box> { match index { 0 => { let s = choose_mpst_f_to_all!( s, all_clocks, Branching0fromFtoA::Done, Branching0fromFtoB::Done, Branching0fromFtoC::Done, Branching0fromFtoD::Done, Branching0fromFtoE::Done ); s.close() } i => { let s: EndpointMoreF = choose_mpst_f_to_all!( s, all_clocks, Branching0fromFtoA::More, Branching0fromFtoB::More, Branching0fromFtoC::More, Branching0fromFtoD::More, Branching0fromFtoE::More ); let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; recurs_f(s, i - 1, all_clocks) } } } fn main() { let (thread_a, thread_b, thread_c, thread_d, thread_e, thread_f) = fork_mpst( endpoint_a, endpoint_b, endpoint_c, endpoint_d, endpoint_e, endpoint_f, ); thread_a.join().unwrap(); thread_b.join().unwrap(); thread_c.join().unwrap(); thread_d.join().unwrap(); thread_e.join().unwrap(); thread_f.join().unwrap(); }