mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add an api for content canvas plugins
some calls are mandatory, such as supporting a redraw of the canvas
This commit is contained in:
parent
07a9cbb02d
commit
6d6d62f794
2 changed files with 65 additions and 0 deletions
14
services/content-plugin-api/Cargo.toml
Normal file
14
services/content-plugin-api/Cargo.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "content-plugin-api"
|
||||
version = "0.1.0"
|
||||
authors = ["bunnie <bunnie@kosagi.com>"]
|
||||
edition = "2018"
|
||||
description = "Content Canvas Plugin Common APIs"
|
||||
|
||||
[dependencies]
|
||||
xous = { path = "../../xous-rs" }
|
||||
rkyv = { version = "0.3.1", default_features = false }
|
||||
graphics-server = { path="../graphics-server"} # this is used by the IMEF portion of the API
|
||||
xous-names = {path="../xous-names"} # used by the IMEF for registering listeners
|
||||
log = "0.4"
|
||||
|
||||
51
services/content-plugin-api/src/lib.rs
Normal file
51
services/content-plugin-api/src/lib.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
|
||||
use xous::{CID, send_message, Message, ScalarMessage};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Opcode {
|
||||
/// request a redraw of our canvas
|
||||
Redraw,
|
||||
}
|
||||
|
||||
impl core::convert::TryFrom<& Message> for Opcode {
|
||||
type Error = &'static str;
|
||||
fn try_from(message: & Message) -> Result<Self, Self::Error> {
|
||||
match message {
|
||||
Message::Scalar(m) => match m.id {
|
||||
0 => Ok(Opcode::Redraw),
|
||||
_ => Err("SHCH api: unknown Scalar ID"),
|
||||
},
|
||||
_ => Err("SHCH api: unhandled message type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Message> for Opcode {
|
||||
fn into(self) -> Message {
|
||||
match self {
|
||||
Opcode::Redraw => Message::Scalar(ScalarMessage {
|
||||
id: 0, arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
// _ => panic!("SHCH api: Opcode type not handled by Into(), refer to helper method"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ContentCanvasApi {
|
||||
fn redraw_canvas(&self) -> Result<(), xous::Error>;
|
||||
}
|
||||
|
||||
pub struct ContentCanvasConnection {
|
||||
pub connection: Option<CID>,
|
||||
}
|
||||
|
||||
impl ContentCanvasApi for ContentCanvasConnection {
|
||||
fn redraw_canvas(&self) -> Result<(), xous::Error> {
|
||||
match self.connection {
|
||||
Some(cid) => send_message(cid, Opcode::Redraw.into()).map(|_| ()),
|
||||
_ => Err(xous::Error::UseBeforeInit),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue