Separated orchid-host and orchid-extension

This is an architectural change that allows me to implment specifics first and generalize along observed symmetries in orchid-base
This commit is contained in:
2024-05-01 21:20:17 +02:00
parent aa3f7e99ab
commit bc3b10674b
25 changed files with 562 additions and 357 deletions

View File

@@ -1,19 +1,23 @@
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use hashbrown::HashMap;
use itertools::Itertools;
use orchid_api::proto::{ExtMsgSet, ExtensionHeader, HostExtNotif, HostExtReq, HostHeader};
use orchid_api_traits::{Decode, Encode};
use orchid_base::child::{recv_parent_msg, send_parent_msg};
use orchid_base::clone;
use orchid_base::intern::{init_replica, sweep_replica};
use orchid_base::reqnot::{ReqNot, Requester};
pub struct ExtensionData {}
use crate::data::ExtensionData;
use crate::msg::{recv_parent_msg, send_parent_msg};
pub fn main(data: &mut ExtensionData) {
pub fn main(data: ExtensionData) {
HostHeader::decode(&mut &recv_parent_msg().unwrap()[..]);
let mut buf = Vec::new();
ExtensionHeader { systems: vec![] }.encode(&mut buf);
let decls = data.systems.iter().map(|sys| sys.decl()).collect_vec();
let systems = Arc::new(Mutex::new(HashMap::new()));
ExtensionHeader { systems: decls.clone() }.encode(&mut buf);
send_parent_msg(&buf).unwrap();
let exiting = Arc::new(AtomicBool::new(false));
let rn = ReqNot::<ExtMsgSet>::new(
@@ -22,11 +26,17 @@ pub fn main(data: &mut ExtensionData) {
HostExtNotif::Exit => exiting.store(true, Ordering::Relaxed),
_ => todo!(),
}),
|req| match req.req() {
clone!(systems; move |req| match req.req() {
HostExtReq::Ping(ping) => req.handle(ping, &()),
HostExtReq::Sweep(sweep) => req.handle(sweep, &sweep_replica()),
HostExtReq::NewSystem(new_sys) => {
let i = decls.iter().enumerate().find(|(_, s)| s.id == new_sys.system).unwrap().0;
let system = data.systems[i].new_system(new_sys, req.reqnot());
systems.lock().unwrap().insert(new_sys.id, system);
req.handle(new_sys, &())
},
_ => todo!(),
},
}),
);
init_replica(rn.clone().map());
while !exiting.load(Ordering::Relaxed) {