Add wait_async client function
This commit is contained in:
parent
2304c939a1
commit
b8e49f71ae
@ -1,7 +1,7 @@
|
|||||||
#![allow(clippy::result_unit_err)]
|
#![allow(clippy::result_unit_err)]
|
||||||
|
|
||||||
use std::{os::mikros::{
|
use std::{os::mikros::{
|
||||||
ipc::rpc::{self, IncomingCall},
|
ipc::rpc::{self, CallId, IncomingCall},
|
||||||
Errno,
|
Errno,
|
||||||
}, path::PathBuf};
|
}, path::PathBuf};
|
||||||
|
|
||||||
@ -28,6 +28,25 @@ pub trait Server: Send + Sync {
|
|||||||
fn get_cwd(&self, from: u64) -> PathBuf;
|
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)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Client(u64);
|
pub struct Client(u64);
|
||||||
|
|
||||||
@ -78,6 +97,10 @@ impl Client {
|
|||||||
.unwrap()
|
.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> {
|
pub fn get_processes(&self) -> Vec<Process> {
|
||||||
postcard::from_bytes(
|
postcard::from_bytes(
|
||||||
&rpc::send_call(self.0, PROTO, 8, &[]).get_return(),
|
&rpc::send_call(self.0, PROTO, 8, &[]).get_return(),
|
||||||
@ -85,14 +108,14 @@ impl Client {
|
|||||||
.unwrap()
|
.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(
|
postcard::from_bytes(
|
||||||
&rpc::send_call(self.0, PROTO, 9, &postcard::to_stdvec(&(pid, path)).unwrap()).get_return(),
|
&rpc::send_call(self.0, PROTO, 9, &postcard::to_stdvec(&(pid, path)).unwrap()).get_return(),
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cwd(&self) -> PathBuf {
|
pub fn get_cwd(&self) -> PathBuf {
|
||||||
postcard::from_bytes(
|
postcard::from_bytes(
|
||||||
&rpc::send_call(self.0, PROTO, 10, &[]).get_return(),
|
&rpc::send_call(self.0, PROTO, 10, &[]).get_return(),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user