#![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, G); // 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>; type R2G = RoleG>; // A enum Branching0fromGtoA { More( MeshedChannels< RS, RS, RS, RS, RS, RecvTimed< (), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', RecursAtoG>, >, R2G>>>>>>, NameA, >, ), Done(MeshedChannels), } type RecursAtoG = RecvTimed; // B enum Branching0fromGtoB { More( MeshedChannels< SR, RS, RS, RS, RS, RecvTimed< (), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', RecursBtoG>, >, R2G>>>>>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoG = RecvTimed; // C enum Branching0fromGtoC { More( MeshedChannels< SR, SR, RS, RS, RS, RecvTimed< (), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', RecursCtoG>, >, R2G>>>>>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoG = RecvTimed; // D enum Branching0fromGtoD { More( MeshedChannels< SR, SR, SR, RS, RS, RecvTimed< (), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', RecursDtoG>, >, R2G>>>>>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoG = RecvTimed; // E enum Branching0fromGtoE { More( MeshedChannels< SR, SR, SR, SR, RS, RecvTimed< (), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', RecursEtoG>, >, R2G>>>>>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoG = RecvTimed; // F enum Branching0fromGtoF { More( MeshedChannels< SR, SR, SR, SR, SR, RecvTimed< (), 'a', 0, true, 10, true, ' ', SendTimed<(), 'a', 0, true, 10, true, ' ', RecursFtoG>, >, R2G>>>>>>, NameF, >, ), Done(MeshedChannels), } type RecursFtoG = RecvTimed; // F type Choose0fromGtoA = SendTimed; type Choose0fromGtoB = SendTimed; type Choose0fromGtoC = SendTimed; type Choose0fromGtoD = SendTimed; type Choose0fromGtoE = SendTimed; type Choose0fromGtoF = SendTimed; type EndpointMoreG = MeshedChannels< SendTimed< (), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', Choose0fromGtoA>, >, SendTimed< (), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', Choose0fromGtoB>, >, SendTimed< (), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', Choose0fromGtoC>, >, SendTimed< (), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', Choose0fromGtoD>, >, SendTimed< (), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', Choose0fromGtoE>, >, SendTimed< (), 'a', 0, true, 10, true, ' ', RecvTimed<(), 'a', 0, true, 10, true, ' ', Choose0fromGtoF>, >, R2A>>>>>, NameG, >; // 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, NameF>; type EndpointG = MeshedChannels< Choose0fromGtoA, Choose0fromGtoB, Choose0fromGtoC, Choose0fromGtoD, Choose0fromGtoE, Choose0fromGtoF, RoleBroadcast, NameG, >; fn endpoint_a(s: EndpointA, all_clocks: &mut HashMap) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); offer_mpst!(s, all_clocks, { Branching0fromGtoA::Done(s) => { s.close() }, Branching0fromGtoA::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)?; 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, { Branching0fromGtoB::Done(s) => { s.close() }, Branching0fromGtoB::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)?; 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, { Branching0fromGtoC::Done(s) => { s.close() }, Branching0fromGtoC::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)?; 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, { Branching0fromGtoD::Done(s) => { s.close() }, Branching0fromGtoD::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)?; 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, { Branching0fromGtoE::Done(s) => { s.close() }, Branching0fromGtoE::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)?; let (_, s) = s.recv(all_clocks)?; let s = s.send((), all_clocks)?; endpoint_e(s, all_clocks) }, }) } fn endpoint_f(s: EndpointF, all_clocks: &mut HashMap) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); offer_mpst!(s, all_clocks, { Branching0fromGtoF::Done(s) => { s.close() }, Branching0fromGtoF::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)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; endpoint_f(s, all_clocks) }, }) } fn endpoint_g(s: EndpointG, all_clocks: &mut HashMap) -> Result<(), Box> { all_clocks.insert('a', Instant::now()); recurs_g(s, LOOPS, all_clocks) } fn recurs_g( s: EndpointG, index: i64, all_clocks: &mut HashMap, ) -> Result<(), Box> { match index { 0 => { let s = choose_mpst_g_to_all!( s, all_clocks, Branching0fromGtoA::Done, Branching0fromGtoB::Done, Branching0fromGtoC::Done, Branching0fromGtoD::Done, Branching0fromGtoE::Done, Branching0fromGtoF::Done ); s.close() } i => { let s: EndpointMoreG = choose_mpst_g_to_all!( s, all_clocks, Branching0fromGtoA::More, Branching0fromGtoB::More, Branching0fromGtoC::More, Branching0fromGtoD::More, Branching0fromGtoE::More, Branching0fromGtoF::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)?; let s = s.send((), all_clocks)?; let (_, s) = s.recv(all_clocks)?; recurs_g(s, i - 1, all_clocks) } } } fn main() { let (thread_a, thread_b, thread_c, thread_d, thread_e, thread_f, thread_g) = fork_mpst( endpoint_a, endpoint_b, endpoint_c, endpoint_d, endpoint_e, endpoint_f, endpoint_g, ); thread_a.join().unwrap(); thread_b.join().unwrap(); thread_c.join().unwrap(); thread_d.join().unwrap(); thread_e.join().unwrap(); thread_f.join().unwrap(); thread_g.join().unwrap(); }