mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 13:11:31 +00:00
implement support for creating domains
This commit is contained in:
@ -160,10 +160,24 @@ impl XsdSocket {
|
||||
typ: u32,
|
||||
string: &str,
|
||||
) -> Result<XsdResponse, XsdBusError> {
|
||||
let path = CString::new(string)?;
|
||||
let buf = path.as_bytes_with_nul();
|
||||
let text = CString::new(string)?;
|
||||
let buf = text.as_bytes_with_nul();
|
||||
self.send(tx, typ, buf)
|
||||
}
|
||||
|
||||
pub fn send_multiple(
|
||||
&mut self,
|
||||
tx: u32,
|
||||
typ: u32,
|
||||
array: &[&str],
|
||||
) -> Result<XsdResponse, XsdBusError> {
|
||||
let mut buf: Vec<u8> = Vec::new();
|
||||
for item in array {
|
||||
buf.extend_from_slice(item.as_bytes());
|
||||
buf.push(0);
|
||||
}
|
||||
self.send(tx, typ, buf.as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for XsdSocket {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::bus::{XsdBusError, XsdSocket};
|
||||
use crate::sys::{
|
||||
XSD_DIRECTORY, XSD_GET_DOMAIN_PATH, XSD_MKDIR, XSD_READ, XSD_RM, XSD_TRANSACTION_END,
|
||||
XSD_TRANSACTION_START, XSD_WRITE,
|
||||
XSD_DIRECTORY, XSD_GET_DOMAIN_PATH, XSD_INTRODUCE, XSD_MKDIR, XSD_READ, XSD_RM,
|
||||
XSD_TRANSACTION_END, XSD_TRANSACTION_START, XSD_WRITE,
|
||||
};
|
||||
use std::ffi::CString;
|
||||
|
||||
@ -12,7 +12,9 @@ pub struct XsdClient {
|
||||
pub trait XsdInterface {
|
||||
fn list(&mut self, path: &str) -> Result<Vec<String>, XsdBusError>;
|
||||
fn read(&mut self, path: &str) -> Result<Vec<u8>, XsdBusError>;
|
||||
fn read_string(&mut self, path: &str) -> Result<String, XsdBusError>;
|
||||
fn write(&mut self, path: &str, data: Vec<u8>) -> Result<bool, XsdBusError>;
|
||||
fn write_string(&mut self, path: &str, data: String) -> Result<bool, XsdBusError>;
|
||||
fn mkdir(&mut self, path: &str) -> Result<bool, XsdBusError>;
|
||||
fn rm(&mut self, path: &str) -> Result<bool, XsdBusError>;
|
||||
}
|
||||
@ -62,6 +64,24 @@ impl XsdClient {
|
||||
.send_single(0, XSD_GET_DOMAIN_PATH, domid.to_string().as_str())?;
|
||||
response.parse_string()
|
||||
}
|
||||
|
||||
pub fn introduce_domain(
|
||||
&mut self,
|
||||
domid: u32,
|
||||
mfn: u32,
|
||||
eventchn: u32,
|
||||
) -> Result<String, XsdBusError> {
|
||||
let response = self.socket.send_multiple(
|
||||
0,
|
||||
XSD_INTRODUCE,
|
||||
&[
|
||||
domid.to_string().as_str(),
|
||||
mfn.to_string().as_str(),
|
||||
eventchn.to_string().as_str(),
|
||||
],
|
||||
)?;
|
||||
response.parse_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct XsdTransaction<'a> {
|
||||
@ -78,10 +98,18 @@ impl XsdInterface for XsdClient {
|
||||
self.read(0, path)
|
||||
}
|
||||
|
||||
fn read_string(&mut self, path: &str) -> Result<String, XsdBusError> {
|
||||
Ok(String::from_utf8(self.read(0, path)?)?)
|
||||
}
|
||||
|
||||
fn write(&mut self, path: &str, data: Vec<u8>) -> Result<bool, XsdBusError> {
|
||||
self.write(0, path, data)
|
||||
}
|
||||
|
||||
fn write_string(&mut self, path: &str, data: String) -> Result<bool, XsdBusError> {
|
||||
self.write(0, path, data.into_bytes())
|
||||
}
|
||||
|
||||
fn mkdir(&mut self, path: &str) -> Result<bool, XsdBusError> {
|
||||
self.mkdir(0, path)
|
||||
}
|
||||
@ -100,10 +128,18 @@ impl XsdInterface for XsdTransaction<'_> {
|
||||
self.client.read(self.tx, path)
|
||||
}
|
||||
|
||||
fn read_string(&mut self, path: &str) -> Result<String, XsdBusError> {
|
||||
Ok(String::from_utf8(self.client.read(self.tx, path)?)?)
|
||||
}
|
||||
|
||||
fn write(&mut self, path: &str, data: Vec<u8>) -> Result<bool, XsdBusError> {
|
||||
self.client.write(self.tx, path, data)
|
||||
}
|
||||
|
||||
fn write_string(&mut self, path: &str, data: String) -> Result<bool, XsdBusError> {
|
||||
self.client.write(self.tx, path, data.into_bytes())
|
||||
}
|
||||
|
||||
fn mkdir(&mut self, path: &str) -> Result<bool, XsdBusError> {
|
||||
self.client.mkdir(self.tx, path)
|
||||
}
|
||||
|
Reference in New Issue
Block a user