use mpstthree::binary::struct_trait::{end::End, recv::Recv, send::Send, session::Session};
use mpstthree::generate;
use mpstthree::role::broadcast::RoleBroadcast;
use mpstthree::role::end::RoleEnd;
use std::error::Error;
generate!("recursive", MeshedChannels, C, S);
type Choose0fromCtoS = Send<Branching0fromCtoS, End>;
type EndpointC0 = MeshedChannels<Recv<(), Choose0fromCtoS>, RoleS<RoleBroadcast>, NameC>;
enum Branching0fromCtoS {
Continue(MeshedChannels<Recv<(), Choose1fromStoC>, RoleC<RoleBroadcast>, NameS>),
Quit(MeshedChannels<Recv<(), End>, RoleC<RoleEnd>, NameS>),
}
type Offer0fromCtoS = <Choose0fromCtoS as Session>::Dual;
type EndpointS0 = MeshedChannels<Send<(), Offer0fromCtoS>, RoleC<RoleC<RoleEnd>>, NameS>;
enum Branching1fromStoC {
Continue(MeshedChannels<Recv<(), Choose2fromCtoS>, RoleS<RoleBroadcast>, NameC>),
Loop(MeshedChannels<Recv<(), Offer1fromStoC>, RoleS<RoleS<RoleEnd>>, NameC>),
}
type Offer1fromStoC = <Choose1fromStoC as Session>::Dual;
type EndpointC1 = MeshedChannels<Offer1fromStoC, RoleS<RoleEnd>, NameC>;
type Choose1fromStoC = Send<Branching1fromStoC, End>;
type EndpointS1 = MeshedChannels<Choose1fromStoC, RoleBroadcast, NameS>;
type Choose2fromCtoS = Send<Branching2fromCtoS, End>;
type EndpointC2 = MeshedChannels<Choose2fromCtoS, RoleBroadcast, NameC>;
enum Branching2fromCtoS {
Continue(
MeshedChannels<Recv<(), Send<(), Offer3fromCtoS>>, RoleC<RoleC<RoleC<RoleEnd>>>, NameS>,
),
Quit(MeshedChannels<Recv<(), End>, RoleC<RoleEnd>, NameS>),
}
type Offer2fromCtoS = <Choose2fromCtoS as Session>::Dual;
type EndpointS2 = MeshedChannels<Offer2fromCtoS, RoleC<RoleEnd>, NameS>;
type Choose3fromCtoS = Send<Branching3fromCtoS, End>;
type EndpointC3 = MeshedChannels<Choose3fromCtoS, RoleBroadcast, NameC>;
enum Branching3fromCtoS {
Continue(MeshedChannels<Recv<(), Choose4fromStoC>, RoleC<RoleBroadcast>, NameS>),
Quit(MeshedChannels<Recv<(), End>, RoleC<RoleEnd>, NameS>),
}
type Offer3fromCtoS = <Choose3fromCtoS as Session>::Dual;
type EndpointS3 = MeshedChannels<Offer3fromCtoS, RoleC<RoleEnd>, NameS>;
enum Branching4fromStoC {
Continue(MeshedChannels<Recv<(), Choose5fromCtoS>, RoleS<RoleBroadcast>, NameC>),
Loop(MeshedChannels<Recv<(), Offer4fromStoC>, RoleS<RoleS<RoleEnd>>, NameC>),
}
type Offer4fromStoC = <Choose4fromStoC as Session>::Dual;
type EndpointC4 = MeshedChannels<Offer4fromStoC, RoleS<RoleEnd>, NameC>;
type Choose4fromStoC = Send<Branching4fromStoC, End>;
type EndpointS4 = MeshedChannels<Choose4fromStoC, RoleBroadcast, NameS>;
type Choose5fromCtoS = Send<Branching5fromCtoS, End>;
type EndpointC5 = MeshedChannels<Choose5fromCtoS, RoleBroadcast, NameC>;
enum Branching5fromCtoS {
Continue(MeshedChannels<Recv<(), Choose6fromStoC>, RoleC<RoleBroadcast>, NameS>),
Quit(MeshedChannels<Recv<(), End>, RoleC<RoleEnd>, NameS>),
}
type Offer5fromCtoS = <Choose5fromCtoS as Session>::Dual;
type EndpointS5 = MeshedChannels<Offer5fromCtoS, RoleC<RoleEnd>, NameS>;
enum Branching6fromStoC {
Continue(MeshedChannels<Recv<(), Choose7fromCtoS>, RoleS<RoleBroadcast>, NameC>),
Loop(MeshedChannels<Recv<(), Offer6fromStoC>, RoleS<RoleS<RoleEnd>>, NameC>),
}
type Offer6fromStoC = <Choose6fromStoC as Session>::Dual;
type EndpointC6 = MeshedChannels<Offer6fromStoC, RoleS<RoleEnd>, NameC>;
type Choose6fromStoC = Send<Branching6fromStoC, End>;
type EndpointS6 = MeshedChannels<Choose6fromStoC, RoleBroadcast, NameS>;
type Choose7fromCtoS = Send<Branching7fromCtoS, End>;
type EndpointC7 = MeshedChannels<Choose7fromCtoS, RoleBroadcast, NameC>;
enum Branching7fromCtoS {
Continue(MeshedChannels<Recv<(), Choose8fromStoC>, RoleC<RoleBroadcast>, NameS>),
Quit(MeshedChannels<Recv<(), End>, RoleC<RoleEnd>, NameS>),
}
type Offer7fromCtoS = <Choose7fromCtoS as Session>::Dual;
type EndpointS7 = MeshedChannels<Offer7fromCtoS, RoleC<RoleEnd>, NameS>;
enum Branching8fromStoC {
Continue(MeshedChannels<Recv<(), Choose9fromCtoS>, RoleS<RoleBroadcast>, NameC>),
Loop(MeshedChannels<Recv<(), Choose7fromCtoS>, RoleS<RoleBroadcast>, NameC>),
}
type Offer8fromStoC = <Choose8fromStoC as Session>::Dual;
type EndpointC8 = MeshedChannels<Offer8fromStoC, RoleS<RoleEnd>, NameC>;
type Choose8fromStoC = Send<Branching8fromStoC, End>;
type EndpointS8 = MeshedChannels<Choose8fromStoC, RoleBroadcast, NameS>;
type Choose9fromCtoS = Send<Branching9fromCtoS, End>;
type EndpointC9 = MeshedChannels<Choose9fromCtoS, RoleBroadcast, NameC>;
enum Branching9fromCtoS {
Continue(
MeshedChannels<
Recv<(), Send<(), Recv<(), Recv<(), Offer10fromCtoS>>>>,
RoleC<RoleC<RoleC<RoleC<RoleC<RoleEnd>>>>>,
NameS,
>,
),
Loop(MeshedChannels<Recv<(), Send<(), Offer9fromCtoS>>, RoleC<RoleC<RoleC<RoleEnd>>>, NameS>),
}
type Offer9fromCtoS = <Choose9fromCtoS as Session>::Dual;
type EndpointS9 = MeshedChannels<Offer9fromCtoS, RoleC<RoleEnd>, NameS>;
type Choose10fromCtoS = Send<Branching10fromCtoS, End>;
type EndpointC10 = MeshedChannels<Choose10fromCtoS, RoleBroadcast, NameC>;
enum Branching10fromCtoS {
Data(MeshedChannels<Recv<(), Recv<(), Offer10fromCtoS>>, RoleC<RoleC<RoleC<RoleEnd>>>, NameS>),
Subject(
MeshedChannels<Recv<(), Recv<(), Offer10fromCtoS>>, RoleC<RoleC<RoleC<RoleEnd>>>, NameS>,
),
End(MeshedChannels<Recv<(), Send<(), Offer7fromCtoS>>, RoleC<RoleC<RoleC<RoleEnd>>>, NameS>),
}
type Offer10fromCtoS = <Choose10fromCtoS as Session>::Dual;
type EndpointS10 = MeshedChannels<Offer10fromCtoS, RoleC<RoleEnd>, NameS>;
fn endpoint_c_init(s: EndpointC0) -> Result<(), Box<dyn Error>> {
endpoint_c_0(s, 100)
}
fn endpoint_c_0(s: EndpointC0, loops: i32) -> Result<(), Box<dyn Error>> {
let (_, s) = s.recv();
match loops {
0 => {
let s = choose_mpst_c_to_all!(s, Branching0fromCtoS::Quit);
let s = s.send(());
s.close()
}
_ => {
let s = choose_mpst_c_to_all!(s, Branching0fromCtoS::Continue);
let s = s.send(());
endpoint_c_1(s, loops)
}
}
}
fn endpoint_c_1(s: EndpointC1, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, {
Branching1fromStoC::Continue(s) => {
let (_, s) = s.recv();
endpoint_c_2(s, loops)
},
Branching1fromStoC::Loop(s) => {
let (_, s) = s.recv();
endpoint_c_1(s, loops)
},
})
}
fn endpoint_c_2(s: EndpointC2, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_c_to_all!(s, Branching2fromCtoS::Quit);
let s = s.send(());
s.close()
}
_ => {
let s = choose_mpst_c_to_all!(s, Branching2fromCtoS::Continue);
let s = s.send(());
let (_, s) = s.recv();
endpoint_c_3(s, loops)
}
}
}
fn endpoint_c_3(s: EndpointC3, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_c_to_all!(s, Branching3fromCtoS::Quit);
let s = s.send(());
s.close()
}
_ => {
let s = choose_mpst_c_to_all!(s, Branching3fromCtoS::Continue);
let s = s.send(());
endpoint_c_4(s, loops)
}
}
}
fn endpoint_c_4(s: EndpointC4, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, {
Branching4fromStoC::Continue(s) => {
let (_, s) = s.recv();
endpoint_c_5(s, loops)
},
Branching4fromStoC::Loop(s) => {
let (_, s) = s.recv();
endpoint_c_4(s, loops)
},
})
}
fn endpoint_c_5(s: EndpointC5, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_c_to_all!(s, Branching5fromCtoS::Quit);
let s = s.send(());
s.close()
}
_ => {
let s = choose_mpst_c_to_all!(s, Branching5fromCtoS::Continue);
let s = s.send(());
endpoint_c_6(s, loops)
}
}
}
fn endpoint_c_6(s: EndpointC6, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, {
Branching6fromStoC::Continue(s) => {
let (_, s) = s.recv();
endpoint_c_7(s, loops)
},
Branching6fromStoC::Loop(s) => {
let (_, s) = s.recv();
endpoint_c_6(s, loops)
},
})
}
fn endpoint_c_7(s: EndpointC7, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_c_to_all!(s, Branching7fromCtoS::Quit);
let s = s.send(());
s.close()
}
_ => {
let s = choose_mpst_c_to_all!(s, Branching7fromCtoS::Continue);
let s = s.send(());
endpoint_c_8(s, loops)
}
}
}
fn endpoint_c_8(s: EndpointC8, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, {
Branching8fromStoC::Continue(s) => {
let (_, s) = s.recv();
endpoint_c_9(s, loops)
},
Branching8fromStoC::Loop(s) => {
let (_, s) = s.recv();
endpoint_c_7(s, loops)
},
})
}
fn endpoint_c_9(s: EndpointC9, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_c_to_all!(s, Branching9fromCtoS::Loop);
let s = s.send(());
let (_, s) = s.recv();
endpoint_c_9(s, loops)
}
_ => {
let s = choose_mpst_c_to_all!(s, Branching9fromCtoS::Continue);
let s = s.send(());
let (_, s) = s.recv();
let s = s.send(());
let s = s.send(());
endpoint_c_10(s, loops)
}
}
}
fn endpoint_c_10(s: EndpointC10, loops: i32) -> Result<(), Box<dyn Error>> {
if loops == 0 {
let s = choose_mpst_c_to_all!(s, Branching10fromCtoS::End);
let s = s.send(());
let (_, s) = s.recv();
endpoint_c_7(s, loops)
} else if loops % 2 == 1 {
let s = choose_mpst_c_to_all!(s, Branching10fromCtoS::Subject);
let s = s.send(());
let s = s.send(());
endpoint_c_10(s, loops - 1)
} else {
let s = choose_mpst_c_to_all!(s, Branching10fromCtoS::Data);
let s = s.send(());
let s = s.send(());
endpoint_c_10(s, loops - 1)
}
}
fn endpoint_s_init(s: EndpointS0) -> Result<(), Box<dyn Error>> {
endpoint_s_0(s, 100)
}
fn endpoint_s_0(s: EndpointS0, loops: i32) -> Result<(), Box<dyn Error>> {
let s = s.send(());
offer_mpst!(s, {
Branching0fromCtoS::Quit(s) => {
let (_, s) = s.recv();
s.close()
},
Branching0fromCtoS::Continue(s) => {
let (_, s) = s.recv();
endpoint_s_1(s, loops)
},
})
}
fn endpoint_s_1(s: EndpointS1, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_s_to_all!(s, Branching1fromStoC::Loop);
let s = s.send(());
endpoint_s_1(s, loops)
}
_ => {
let s = choose_mpst_s_to_all!(s, Branching1fromStoC::Continue);
let s = s.send(());
endpoint_s_2(s, loops)
}
}
}
fn endpoint_s_2(s: EndpointS2, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, {
Branching2fromCtoS::Quit(s) => {
let (_, s) = s.recv();
s.close()
},
Branching2fromCtoS::Continue(s) => {
let (_, s) = s.recv();
let s = s.send(());
endpoint_s_3(s, loops)
},
})
}
fn endpoint_s_3(s: EndpointS3, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, {
Branching3fromCtoS::Quit(s) => {
let (_, s) = s.recv();
s.close()
},
Branching3fromCtoS::Continue(s) => {
let (_, s) = s.recv();
endpoint_s_4(s, loops)
},
})
}
fn endpoint_s_4(s: EndpointS4, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_s_to_all!(s, Branching4fromStoC::Loop);
let s = s.send(());
endpoint_s_4(s, loops)
}
_ => {
let s = choose_mpst_s_to_all!(s, Branching4fromStoC::Continue);
let s = s.send(());
endpoint_s_5(s, loops)
}
}
}
fn endpoint_s_5(s: EndpointS5, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, {
Branching5fromCtoS::Quit(s) => {
let (_, s) = s.recv();
s.close()
},
Branching5fromCtoS::Continue(s) => {
let (_, s) = s.recv();
endpoint_s_6(s, loops)
},
})
}
fn endpoint_s_6(s: EndpointS6, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_s_to_all!(s, Branching6fromStoC::Loop);
let s = s.send(());
endpoint_s_6(s, loops)
}
_ => {
let s = choose_mpst_s_to_all!(s, Branching6fromStoC::Continue);
let s = s.send(());
endpoint_s_7(s, loops)
}
}
}
fn endpoint_s_7(s: EndpointS7, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, {
Branching7fromCtoS::Quit(s) => {
let (_, s) = s.recv();
s.close()
},
Branching7fromCtoS::Continue(s) => {
let (_, s) = s.recv();
endpoint_s_8(s, loops)
},
})
}
fn endpoint_s_8(s: EndpointS8, loops: i32) -> Result<(), Box<dyn Error>> {
match loops {
0 => {
let s = choose_mpst_s_to_all!(s, Branching8fromStoC::Loop);
let s = s.send(());
endpoint_s_7(s, loops)
}
_ => {
let s = choose_mpst_s_to_all!(s, Branching8fromStoC::Continue);
let s = s.send(());
endpoint_s_9(s, loops)
}
}
}
fn endpoint_s_9(s: EndpointS9, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, {
Branching9fromCtoS::Loop(s) => {
let (_, s) = s.recv();
let s = s.send(());
endpoint_s_9(s, loops)
},
Branching9fromCtoS::Continue(s) => {
let (_, s) = s.recv();
let s = s.send(());
let (_, s) = s.recv();
let (_, s) = s.recv();
endpoint_s_10(s, loops)
},
})
}
fn endpoint_s_10(s: EndpointS10, loops: i32) -> Result<(), Box<dyn Error>> {
offer_mpst!(s, {
Branching10fromCtoS::Data(s) => {
let (_, s) = s.recv();
let (_, s) = s.recv();
endpoint_s_10(s, loops - 1)
},
Branching10fromCtoS::Subject(s) => {
let (_, s) = s.recv();
let (_, s) = s.recv();
endpoint_s_10(s, loops - 1)
},
Branching10fromCtoS::End(s) => {
let (_, s) = s.recv();
let s = s.send(());
endpoint_s_7(s, loops - 1)
},
})
}
fn main() {
let (thread_c, thread_s) = fork_mpst(endpoint_c_init, endpoint_s_init);
thread_c.join().unwrap();
thread_s.join().unwrap();
}