Add wait_async client function

This commit is contained in:
pjht 2024-11-20 13:59:55 -06:00
parent 2304c939a1
commit b8e49f71ae
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A

View File

@ -1,7 +1,7 @@
#![allow(clippy::result_unit_err)]
use std::{os::mikros::{
ipc::rpc::{self, IncomingCall},
ipc::rpc::{self, CallId, IncomingCall},
Errno,
}, path::PathBuf};
@ -28,6 +28,25 @@ pub trait Server: Send + Sync {
fn get_cwd(&self, from: u64) -> PathBuf;
}
#[derive(Copy, Clone)]
pub struct PendingWait(CallId);
impl PendingWait {
pub fn get_return(self) -> Result<WaitResult, Errno> {
postcard::from_bytes(&self.0.get_return()).unwrap()
}
pub fn try_get_return(self) -> Result<Option<WaitResult>, Errno> {
match self.0.try_get_return() {
Some(ret) => {
let ret: Result<WaitResult, Errno> = postcard::from_bytes(&ret).unwrap();
Ok(Some(ret?))
},
None => Ok(None),
}
}
}
#[derive(Copy, Clone)]
pub struct Client(u64);
@ -78,6 +97,10 @@ impl Client {
.unwrap()
}
pub fn wait_async(&self, pid: u64) -> PendingWait {
PendingWait(rpc::send_call(self.0, PROTO, 5, &postcard::to_stdvec(&(pid, true)).unwrap()))
}
pub fn get_processes(&self) -> Vec<Process> {
postcard::from_bytes(
&rpc::send_call(self.0, PROTO, 8, &[]).get_return(),
@ -85,14 +108,14 @@ impl Client {
.unwrap()
}
fn set_cwd(&self, pid: u64, path: PathBuf) -> Result<(), Errno> {
pub fn set_cwd(&self, pid: u64, path: PathBuf) -> Result<(), Errno> {
postcard::from_bytes(
&rpc::send_call(self.0, PROTO, 9, &postcard::to_stdvec(&(pid, path)).unwrap()).get_return(),
)
.unwrap()
}
fn get_cwd(&self) -> PathBuf {
pub fn get_cwd(&self) -> PathBuf {
postcard::from_bytes(
&rpc::send_call(self.0, PROTO, 10, &[]).get_return(),
)