Struct optee_utee::extension::LoadablePlugin
source · pub struct LoadablePlugin { /* private fields */ }
Implementations§
source§impl LoadablePlugin
impl LoadablePlugin
pub fn new(uuid: &Uuid) -> Self
sourcepub fn invoke(
&self,
command_id: u32,
subcommand_id: u32,
data: &[u8]
) -> Result<Vec<u8>>
pub fn invoke( &self, command_id: u32, subcommand_id: u32, data: &[u8] ) -> Result<Vec<u8>>
Invoke plugin with given request data, use when you want to post something into REE.
let plugin = LoadablePlugin::new(&uuid);
let result = plugin.invoke(command_id, subcommand_id, &request_data)?;
Caution: the size of the shared buffer is set to the len of data, you could get a ShortBuffer error if Plugin return more data than shared buffer, in that case, use invoke_with_capacity and set the capacity manually.
sourcepub fn invoke_with_capacity<'a>(
&'a self,
command_id: u32,
subcommand_id: u32,
capacity: usize
) -> LoadablePluginCommand<'a>
pub fn invoke_with_capacity<'a>( &'a self, command_id: u32, subcommand_id: u32, capacity: usize ) -> LoadablePluginCommand<'a>
Construct a command with shared buffer up to capacity size, write the buffer and call it manually, use when you need to control details of the invoking process.
let mut cmd = plugin.invoke_with_capacity(command_id, sub_command_id, capacity);
cmd.write_body(&request_data);
let result = cmd.call()?;
You can also imply a wrapper for performance, for example, imply a std::io::Write so serde_json can write to the buffer directly.
struct Wrapper<'a, 'b>(&'b mut LoadablePluginCommand<'a>);
impl<'a, 'b> std::io::Write for Wrapper<'a, 'b> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.0.write_body(buf);
Ok(buf.len())
}
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}
// serialize data into command directly
let request_data = serde_json::json!({
"age": 100,
"name": "name"
});
let mut cmd = plugin.invoke_with_capacity(command_id, subcommand_id, capacity);
serde_json::to_writer(Wrapper(&mut cmd), &request_data).map_err(|err| {
trace_println!("serde error: {:?}", err);
ErrorKind::Unknown
})?;
let result = cmd.call()?;
Notice: the shared buffer could grow to fit the request data automatically.
Auto Trait Implementations§
impl Freeze for LoadablePlugin
impl RefUnwindSafe for LoadablePlugin
impl Send for LoadablePlugin
impl Sync for LoadablePlugin
impl Unpin for LoadablePlugin
impl UnwindSafe for LoadablePlugin
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more