Committing for reference
This commit is contained in:
@@ -1,24 +1,20 @@
|
||||
use std::io::{self, BufRead as _, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::mpsc::{SyncSender, sync_channel};
|
||||
use std::sync::mpsc::sync_channel;
|
||||
use std::{process, thread};
|
||||
|
||||
use async_std::sync::Mutex;
|
||||
use orchid_api_traits::{Decode, Encode};
|
||||
use orchid_base::builtin::{ExtInit, ExtPort};
|
||||
use orchid_base::logging::Logger;
|
||||
use orchid_base::msg::{recv_msg, send_msg};
|
||||
|
||||
use crate::api;
|
||||
use crate::extension::{ExtensionPort, OnMessage};
|
||||
|
||||
pub struct Subprocess {
|
||||
child: Mutex<process::Child>,
|
||||
stdin: Mutex<process::ChildStdin>,
|
||||
set_onmessage: SyncSender<OnMessage>,
|
||||
header: api::ExtensionHeader,
|
||||
}
|
||||
impl Subprocess {
|
||||
pub fn new(mut cmd: process::Command, logger: Logger) -> io::Result<Self> {
|
||||
pub struct ExtensionCommand(pub process::Command, pub Logger);
|
||||
impl ExtFactory for ExtensionCommand {
|
||||
fn run(self: Box<Self>, onmessage: OnMessage) -> ExtInit {
|
||||
let Self(mut cmd, logger) = *self;
|
||||
let prog_pbuf = PathBuf::from(cmd.get_program());
|
||||
let prog = prog_pbuf.file_stem().unwrap_or(cmd.get_program()).to_string_lossy().to_string();
|
||||
let mut child = cmd
|
||||
@@ -54,19 +50,32 @@ impl Subprocess {
|
||||
logger.log(buf);
|
||||
}
|
||||
})?;
|
||||
Ok(Self { child: Mutex::new(child), stdin: Mutex::new(stdin), set_onmessage, header })
|
||||
Ok(Subprocess { child: Mutex::new(child), stdin: Mutex::new(stdin), set_onmessage, header })
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Subprocess {
|
||||
child: Mutex<process::Child>,
|
||||
stdin: Mutex<process::ChildStdin>,
|
||||
stdout: Mutex<process::ChildStdout>,
|
||||
header: api::ExtensionHeader,
|
||||
}
|
||||
impl Subprocess {
|
||||
pub fn new(mut cmd: process::Command, logger: Logger) -> io::Result<Self> {}
|
||||
}
|
||||
impl Drop for Subprocess {
|
||||
fn drop(&mut self) { self.child.lock().unwrap().wait().expect("Extension exited with error"); }
|
||||
}
|
||||
impl ExtensionPort for Subprocess {
|
||||
fn set_onmessage(&self, callback: OnMessage) { self.set_onmessage.send(callback).unwrap(); }
|
||||
fn header(&self) -> &orchid_api::ExtensionHeader { &self.header }
|
||||
impl ExtPort for Subprocess {
|
||||
fn send(&self, msg: &[u8]) {
|
||||
if msg.starts_with(&[0, 0, 0, 0x1c]) {
|
||||
panic!("Received unnecessary prefix");
|
||||
}
|
||||
send_msg(&mut *self.stdin.lock().unwrap(), msg).unwrap()
|
||||
}
|
||||
fn recv<'a>(&self, cb: Box<dyn FnOnce(&[u8]) + Send + 'a>) -> futures::future::BoxFuture<()> {
|
||||
async {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user