extend modal functions; refactor status into its own server

This commit is contained in:
bunnie 2021-07-28 01:01:39 +08:00
parent 9b51edfe6c
commit b6c443145c
16 changed files with 385 additions and 125 deletions

28
Cargo.lock generated
View file

@ -740,7 +740,6 @@ name = "gam"
version = "0.1.0"
dependencies = [
"blitstr-ref",
"chrono",
"com",
"content-plugin-api",
"enum_dispatch",
@ -749,14 +748,12 @@ dependencies = [
"ime-plugin-api",
"ime-plugin-shell",
"keyboard",
"llio",
"locales",
"log",
"log-server",
"num-derive",
"num-traits",
"rkyv 0.4.3",
"rtc",
"susres",
"ticktimer-server",
"trng",
@ -1850,6 +1847,31 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "status"
version = "0.1.0"
dependencies = [
"blitstr-ref",
"chrono",
"com",
"content-plugin-api",
"gam",
"graphics-server",
"llio",
"log",
"log-server",
"num-derive",
"num-traits",
"rkyv 0.4.3",
"rtc",
"ticktimer-server",
"trng",
"utralib",
"xous",
"xous-ipc",
"xous-names",
]
[[package]]
name = "strsim"
version = "0.8.0"

View file

@ -8,6 +8,7 @@ default-members = [
"services/com",
"services/trng",
"services/gam",
"services/status",
"imports/blitstr-ref",
"imports/com_rs-ref",
"services/ime-plugin-api",
@ -46,6 +47,7 @@ members = [
"services/kernel-test",
"services/trng",
"services/gam",
"services/status",
"services/benchmark",
"services/benchmark-target",
"services/ime-frontend",

View file

@ -7,7 +7,7 @@ version = "0.1.0"
[dependencies]
blitstr-ref = {path = "../../imports/blitstr-ref"}
com = {path = "../com"}
com = {path = "../com"} # used by the backlight setting on the main menu thread
content-plugin-api = {path = "../content-plugin-api"}
graphics-server = {path = "../graphics-server"}
heapless = "0.7" # used for creating a sortable heap of canvas objects
@ -18,8 +18,6 @@ log = "0.4"
log-server = {path = "../log-server"}
ticktimer-server = {path = "../ticktimer-server"}
trng = {path = "../trng"}
rtc = {path = "../rtc"}
llio = {path = "../llio"}
xous = {path = "../../xous-rs"}
xous-ipc = {path = "../../xous-ipc"}
xous-names = {path = "../xous-names"}
@ -36,10 +34,6 @@ locales = {path = "../../locales"}
[target.'cfg(not(any(windows,unix)))'.dependencies]
utralib = {path = "../../utralib"}
# short circuit the datetime call on hosted mode
[target.'cfg(any(windows,unix))'.dependencies]
chrono = "0.4"
[features]
debugprint = []
slowstatus = [] # used for braille mode, so console isn't overwhelmed with status

0
services/gam/src/layouts.rs Executable file → Normal file
View file

View file

@ -3,8 +3,6 @@
mod api;
use api::*;
mod status;
use status::*;
mod canvas;
use canvas::*;
@ -621,11 +619,20 @@ fn xmain() -> ! {
canvases.insert(status_canvas.gid(), status_canvas).expect("can't store status canvus");
canvases = recompute_canvases(&canvases, Rectangle::new(Point::new(0, 0), screensize));
// make a thread to manage the status bar -- this needs to start late, after the IMEF and most other things are initialized
// the status bar is a trusted element managed by the OS, and we are chosing to domicile this in the GAM process for now
// initialize the status bar -- this needs to start late, after the IMEF and most other things are initialized
// this used to be domiciled in the GAM, but we split it out because this started to pull too much functionality
// into the GAM and was causing circular crate conflicts with sub-functions that the status bar relies upon.
// we do a hack to try and push a GID to the status bar "securely": we introduce a race condition where we hope
// that the GAM is the first thing to talk to the status bar, and the first message is its GID to render on.
// generally should be OK, because during boot, all processes are trusted...
let status_gid = status_canvas.gid().gid();
log::trace!("starting status thread with gid {:?}", status_gid);
xous::create_thread_4(status_thread, status_gid[0] as _, status_gid[1] as _, status_gid[2] as _, status_gid[3] as _).expect("couldn't create status thread");
log::trace!("initializing status bar with gid {:?}", status_gid);
let status_conn = xns.request_connection_blocking("_Status bar GID receiver_").expect("couldn't connect to status bar GID receiver");
xous::send_message(status_conn,
xous::Message::new_scalar(0, // message type doesn't matter because there is only one message it should ever receive
status_gid[0] as usize, status_gid[1] as usize, status_gid[2] as usize, status_gid[3] as usize
)
).expect("couldn't set status GID");
// make a thread to manage the main menu.
log::trace!("starting menu thread");

271
services/gam/src/modal.rs Executable file → Normal file
View file

@ -96,13 +96,15 @@ pub enum TextEntryVisibility {
/// all chars hidden as *
Hidden = 2,
}
#[derive(Debug, Clone)]
#[derive(Copy, Clone)]
pub struct TextEntry {
pub is_password: bool,
pub visibility: TextEntryVisibility,
pub action_conn: xous::CID,
pub action_opcode: u32,
pub action_payload: TextEntryPayload,
// validator borrows the text entry payload, and returns an error message if something didn't go well.
pub validator: Option<fn(TextEntryPayload) -> Option<xous_ipc::String::<512>> >,
}
impl ActionApi for TextEntry {
fn is_password(&self) -> bool {
@ -250,7 +252,7 @@ impl ActionApi for TextEntry {
DrawStyle::new(color, color, 1))
).expect("couldn't draw entry line");
}
fn key_action(&mut self, k: char) {
fn key_action(&mut self, k: char) -> Option<xous_ipc::String::<512>> {
log::trace!("key_action: {}", k);
match k {
'←' => {
@ -280,6 +282,13 @@ impl ActionApi for TextEntry {
}
},
'∴' | '\u{d}' => {
if let Some(validator) = self.validator {
if let Some(err_msg) = validator(self.action_payload) {
self.action_payload.0.clear(); // reset the input field
return Some(err_msg);
}
}
let mut buf = Buffer::into_buf(self.action_payload).expect("couldn't convert message to payload");
buf.lend(self.action_conn, self.action_opcode).map(|_| ()).expect("couldn't send action message");
self.action_payload.volatile_clear(); // ensure the local copy of text is zero'd out
@ -307,6 +316,7 @@ impl ActionApi for TextEntry {
log::trace!("****update payload: {}", self.action_payload.0);
}
}
None
}
}
#[derive(Debug, Copy, Clone)]
@ -371,11 +381,11 @@ trait ActionApi {
fn close(&mut self) {}
fn is_password(&self) -> bool { false }
/// navigation is one of '∴' | '←' | '→' | '↑' | '↓'
fn key_action(&mut self, key: char) {}
fn key_action(&mut self, key: char) -> Option<xous_ipc::String::<512>> {None}
}
#[enum_dispatch(ActionApi)]
#[derive(Debug, Clone)]
#[derive(Copy, Clone)]
pub enum ActionType {
TextEntry,
RadioButtons,
@ -383,7 +393,7 @@ pub enum ActionType {
Slider
}
#[derive(Debug)]
//#[derive(Debug)]
pub struct Modal {
pub sid: xous::SID,
pub gam: Gam,
@ -409,6 +419,86 @@ pub enum ModalOpcode {
Quit,
}
fn recompute_canvas(modal: &mut Modal, action: ActionType, top_text: Option<&str>, bot_text: Option<&str>, style: GlyphStyle) {
// method:
// - we assume the GAM gives us an initial modal with a "maximum" height setting
// - items are populated within this maximal canvas setting, and then the actual height needed is computed
// - the canvas is resized to this actual height
// problems:
// - there is no sanity check on the size of the text boxes. So if you give the UX element a top_text box that's
// huge, it will just overflow the canvas size and nothing else will get drawn.
let mut total_height = modal.margin;
log::trace!("step 0 total_height: {}", total_height);
// compute height of top_text, if any
if let Some(top_str) = top_text {
let mut top_tv = TextView::new(modal.canvas,
TextBounds::GrowableFromTl(
Point::new(modal.margin, total_height),
(modal.canvas_width - modal.margin * 2) as u16
));
top_tv.draw_border = false;
top_tv.style = style;
top_tv.margin = Point::new(0, 0,); // all margin already accounted for in the raw bounds of the text drawing
top_tv.ellipsis = false;
top_tv.invert = modal.inverted;
write!(top_tv.text, "{}", top_str);
log::trace!("posting top tv: {:?}", top_tv);
modal.gam.bounds_compute_textview(&mut top_tv).expect("couldn't simulate top text size");
if let Some(bounds) = top_tv.bounds_computed {
total_height += bounds.br.y - bounds.tl.y;
} else {
log::error!("couldn't compute height for modal top_text: {:?}", top_tv);
panic!("couldn't compute height for modal top_text");
}
modal.top_text = Some(top_tv);
}
total_height += modal.margin;
// compute height of action item
log::trace!("step 1 total_height: {}", total_height);
total_height += modal.action.height(modal.line_height, modal.margin);
total_height += modal.margin;
// compute height of bot_text, if any
log::trace!("step 2 total_height: {}", total_height);
if let Some(bot_str) = bot_text {
let mut bot_tv = TextView::new(modal.canvas,
TextBounds::GrowableFromTl(
Point::new(modal.margin, total_height),
(modal.canvas_width - modal.margin * 2) as u16
));
bot_tv.draw_border = false;
bot_tv.style = style;
bot_tv.margin = Point::new(0, 0,); // all margin already accounted for in the raw bounds of the text drawing
bot_tv.ellipsis = false;
bot_tv.invert = modal.inverted;
write!(bot_tv.text, "{}", bot_str);
modal.gam.bounds_compute_textview(&mut bot_tv).expect("couldn't simulate bot text size");
if let Some(bounds) = bot_tv.bounds_computed {
total_height += bounds.br.y - bounds.tl.y;
} else {
log::error!("couldn't compute height for modal bot_text: {:?}", bot_tv);
panic!("couldn't compute height for modal bot_text");
}
modal.bot_text = Some(bot_tv);
total_height += modal.margin;
}
log::trace!("step 3 total_height: {}", total_height);
let current_bounds = modal.gam.get_canvas_bounds(modal.canvas).expect("couldn't get current bounds");
let mut new_bounds = SetCanvasBoundsRequest {
requested: Point::new(current_bounds.x, total_height),
granted: None,
token_type: TokenType::App,
token: modal.authtoken,
};
log::debug!("applying recomputed bounds of {:?}", new_bounds);
modal.gam.set_canvas_bounds_request(&mut new_bounds).expect("couldn't call set bounds");
}
impl Modal {
pub fn new(name: &str, action: ActionType, top_text: Option<&str>, bot_text: Option<&str>, style: GlyphStyle) -> Modal {
let xns = xous_names::XousNames::new().unwrap();
@ -432,6 +522,7 @@ impl Modal {
let line_height = gam.glyph_height_hint(style).expect("couldn't get glyph height hint") as i16;
let canvas_bounds = gam.get_canvas_bounds(canvas).expect("couldn't get starting canvas bounds");
log::trace!("initializing Modal structure");
// check to see if this is a password field or not
// note: if a modal claims it's a password field but lacks sufficient trust level, the GAM will refuse
// to render the element.
@ -440,7 +531,6 @@ impl Modal {
_ => false
};
log::trace!("initializing Modal structure");
// we now have a canvas that is some minimal height, but with the final width as allowed by the GAM.
// compute the final height based upon the contents within.
let mut modal = Modal {
@ -458,85 +548,7 @@ impl Modal {
inverted,
style,
};
// method:
// - we assume the GAM gives us an initial modal with a "maximum" height setting
// - items are populated within this maximal canvas setting, and then the actual height needed is computed
// - the canvas is resized to this actual height
// problems:
// - there is no sanity check on the size of the text boxes. So if you give the UX element a top_text box that's
// huge, it will just overflow the canvas size and nothing else will get drawn.
let mut total_height = modal.margin;
log::trace!("step 0 total_height: {}", total_height);
// compute height of top_text, if any
if let Some(top_str) = top_text {
let mut top_tv = TextView::new(canvas,
TextBounds::GrowableFromTl(
Point::new(modal.margin, total_height),
(modal.canvas_width - modal.margin * 2) as u16
));
top_tv.draw_border = false;
top_tv.style = style;
top_tv.margin = Point::new(0, 0,); // all margin already accounted for in the raw bounds of the text drawing
top_tv.ellipsis = false;
top_tv.invert = inverted;
write!(top_tv.text, "{}", top_str);
log::trace!("posting top tv: {:?}", top_tv);
modal.gam.bounds_compute_textview(&mut top_tv).expect("couldn't simulate top text size");
if let Some(bounds) = top_tv.bounds_computed {
total_height += bounds.br.y - bounds.tl.y;
} else {
log::error!("couldn't compute height for modal top_text: {:?}", top_tv);
panic!("couldn't compute height for modal top_text");
}
modal.top_text = Some(top_tv);
}
total_height += modal.margin;
// compute height of action item
log::trace!("step 1 total_height: {}", total_height);
total_height += modal.action.height(modal.line_height, modal.margin);
total_height += modal.margin;
// compute height of bot_text, if any
log::trace!("step 2 total_height: {}", total_height);
if let Some(bot_str) = bot_text {
let mut bot_tv = TextView::new(canvas,
TextBounds::GrowableFromTl(
Point::new(modal.margin, total_height),
(modal.canvas_width - modal.margin * 2) as u16
));
bot_tv.draw_border = false;
bot_tv.style = style;
bot_tv.margin = Point::new(0, 0,); // all margin already accounted for in the raw bounds of the text drawing
bot_tv.ellipsis = false;
bot_tv.invert = inverted;
write!(bot_tv.text, "{}", bot_str);
modal.gam.bounds_compute_textview(&mut bot_tv).expect("couldn't simulate bot text size");
if let Some(bounds) = bot_tv.bounds_computed {
total_height += bounds.br.y - bounds.tl.y;
} else {
log::error!("couldn't compute height for modal bot_text: {:?}", bot_tv);
panic!("couldn't compute height for modal bot_text");
}
modal.bot_text = Some(bot_tv);
total_height += modal.margin;
}
log::trace!("step 3 total_height: {}", total_height);
let current_bounds = modal.gam.get_canvas_bounds(modal.canvas).expect("couldn't get current bounds");
let mut new_bounds = SetCanvasBoundsRequest {
requested: Point::new(current_bounds.x, total_height),
granted: None,
token_type: TokenType::App,
token: modal.authtoken,
};
log::debug!("applying recomputed bounds of {:?}", new_bounds);
modal.gam.set_canvas_bounds_request(&mut new_bounds).expect("couldn't call set bounds");
recompute_canvas(&mut modal, action, top_text, bot_text, style);
modal
}
@ -576,19 +588,90 @@ impl Modal {
for &k in keys.iter() {
if k != '\u{0}' {
log::debug!("got key '{}'", k);
self.action.key_action(k); // this is where the action is at
match k {
'∴' | '\u{d}' => {
log::trace!("closing modal");
// if it's a "close" button, invoke the GAM to put our box away
self.gam.relinquish_focus().unwrap();
}
_ => {
// already handled by key_action() above
if let Some(err_msg) = self.action.key_action(k) {
self.modify(None, None, Some(err_msg.to_str()), None);
} else {
match k {
'∴' | '\u{d}' => {
log::trace!("closing modal");
// if it's a "close" button, invoke the GAM to put our box away
self.gam.relinquish_focus().unwrap();
}
_ => {
// already handled by key_action() above
}
}
}
}
}
self.redraw();
}
/// this function will modify UX elements if any of the arguments are Some()
/// if None, the element is unchanged. To remove an element, use remove()
pub fn modify(&mut self, update_action: Option<ActionType>, update_top_text: Option<&str>, update_bot_text: Option<&str>, update_style: Option<GlyphStyle>) {
let action = if let Some(action) = update_action {
action
} else {
self.action
};
let mut top_tv_temp = String::<3072>::new(); // size matches that used in TextView
if let Some(top_text) = update_top_text {
write!(top_tv_temp, "{}", top_text).unwrap();
} else {
if let Some(top_text) = self.top_text {
write!(top_tv_temp, "{}", top_text).unwrap();
}
};
let top_text = if self.top_text.is_none() && update_top_text.is_none() {
None
} else {
Some(top_tv_temp.to_str())
};
let mut bot_tv_temp = String::<3072>::new(); // size matches that used in TextView
if let Some(bot_text) = update_bot_text {
write!(bot_tv_temp, "{}", bot_text).unwrap();
} else {
if let Some(bot_text) = self.bot_text {
write!(bot_tv_temp, "{}", bot_text).unwrap();
}
};
let bot_text = if self.bot_text.is_none() && update_bot_text.is_none() {
None
} else {
Some(bot_tv_temp.to_str())
};
let style = if let Some(style) = update_style {
style
} else {
self.style
};
recompute_canvas(self, action, top_text, bot_text, style);
}
/// only the top and bottom texts are optional, setting either to false will remove them from the UX element
pub fn remove(&mut self, remove_top: bool, remove_bot: bool) {
let mut top_tv_temp = String::<3072>::new(); // size matches that used in TextView
if let Some(top_text) = self.top_text {
write!(top_tv_temp, "{}", top_text).unwrap();
};
let top_text = if remove_top {
None
} else {
Some(top_tv_temp.to_str())
};
let mut bot_tv_temp = String::<3072>::new(); // size matches that used in TextView
if let Some(bot_text) = self.bot_text {
write!(bot_tv_temp, "{}", bot_text).unwrap();
};
let bot_text = if remove_bot {
None
} else {
Some(bot_tv_temp.to_str())
};
recompute_canvas(self, self.action, top_text, bot_text, self.style);
}
}

0
services/gam/src/tokens.rs Executable file → Normal file
View file

View file

@ -62,6 +62,7 @@ pub(crate) struct RootKeys {
password_policy: PasswordRetentionPolicy,
susres: susres::Susres, // for disabling suspend/resume
trng: trng::Trng,
gam: gam::Gam, // for raising UX elements directly
}
impl RootKeys {
@ -124,6 +125,7 @@ impl RootKeys {
password_policy: PasswordRetentionPolicy::AlwaysKeep,
susres: susres::Susres::new_without_hook(&xns).expect("couldn't connect to susres without hook"),
trng: trng::Trng::new(&xns).expect("couldn't connect to TRNG server"),
gam: gam::Gam::new(&xns).expect("couldn't connect to GAM"),
};
keys
@ -224,7 +226,11 @@ impl RootKeys {
self.susres.set_suspendable(true).expect("couldn't re-allow suspend/resume");
}
pub fn test_ux(&mut self, _arg: usize) {
pub fn test_ux(&mut self, arg: usize) {
match arg {
0 => self.gam.raise_modal(ROOTKEY_MODAL_NAME).expect("couldn't raise modal"),
1 => self.gam.relinquish_focus().expect("couldn't hide modal"),
_ => log::info!("test_ux got unrecognized arg: {}", arg),
};
}
}

View file

@ -64,6 +64,7 @@ pub(crate) fn rootkeys_ux_thread() {
action_conn: main_conn,
action_opcode: Opcode::PasswordModalEntry.to_u32().unwrap(),
action_payload: TextEntryPayload::new(),
validator: None,
};
log::trace!("building ux thread modal");
let mut modal = gam::Modal::new(
@ -73,7 +74,6 @@ pub(crate) fn rootkeys_ux_thread() {
None,
GlyphStyle::Small,
);
log::trace!("ux thread modal: {:?}", modal);
loop {
let msg = xous::receive_message(modal.sid).unwrap();

View file

@ -13,6 +13,7 @@ xous-names = { path = "../xous-names" }
log = "0.4"
bitflags = "1.2.1"
llio = {path = "../llio"}
#gam = {path = "../gam"}
xous-ipc = {path = "../../xous-ipc"}
num-derive = {version = "0.3", default-features = false}

View file

@ -530,7 +530,8 @@ fn xmain() -> ! {
// - GAM
// - shellchat/rtc
// - shellchat/sleep x2
let rtc_sid = xns.register_name(api::SERVER_NAME_RTC, Some(4)).expect("can't register server");
// - UX thread
let rtc_sid = xns.register_name(api::SERVER_NAME_RTC, Some(5)).expect("can't register server");
log::trace!("registered with NS -- {:?}", rtc_sid);
CB_TO_MAIN_CONN.store(xous::connect(rtc_sid).unwrap(), Ordering::Relaxed);
@ -681,3 +682,71 @@ fn xmain() -> ! {
log::trace!("quitting");
xous::terminate_process(0)
}
/*
pub(crate) fn rtc_ux_thread() {
let xns = xous_names::XousNames::new().unwrap();
let main_conn = xns.request_connection_blocking(api::SERVER_NAME_RTC).expect("UX thread can't connect to main thread");
let rtc_textentry = gam::modal::TextEntry {
is_password: false,
visibility: gam::modal::TextEntryVisibility::Visible,
action_conn: main_conn,
action_opcode: Opcode::PasswordModalEntry.to_u32().unwrap(),
action_payload: TextEntryPayload::new(),
};
log::trace!("building ux thread modal");
let mut modal = gam::Modal::new(
crate::ROOTKEY_MODAL_NAME,
gam::ActionType::TextEntry(password_action),
Some(t!("rootpass.top", xous::LANG)),
None,
GlyphStyle::Small,
);
log::trace!("ux thread modal: {:?}", modal);
loop {
let msg = xous::receive_message(modal.sid).unwrap();
log::trace!("ux message: {:?}", msg);
match FromPrimitive::from_usize(msg.body.id()) {
Some(ModalOpcode::Redraw) => {
modal.redraw();
},
Some(ModalOpcode::Rawkeys) => msg_scalar_unpack!(msg, k1, k2, k3, k4, {
let keys = [
if let Some(a) = core::char::from_u32(k1 as u32) {
a
} else {
'\u{0000}'
},
if let Some(a) = core::char::from_u32(k2 as u32) {
a
} else {
'\u{0000}'
},
if let Some(a) = core::char::from_u32(k3 as u32) {
a
} else {
'\u{0000}'
},
if let Some(a) = core::char::from_u32(k4 as u32) {
a
} else {
'\u{0000}'
},
];
modal.key_event(keys);
}),
Some(ModalOpcode::Quit) => {
break;
},
None => {
log::error!("unknown opcode {:?}", msg.body.id());
}
}
}
log::trace!("password modal thread exit, destroying servers");
// do we want to add a deregister_ux call to the system?
xous::destroy_server(modal.sid).unwrap();
}
*/

View file

@ -0,0 +1,39 @@
[package]
authors = ["bunnie <bunnie@kosagi.com>"]
description = "Status bar for Xous"
edition = "2018"
name = "status"
version = "0.1.0"
[dependencies]
blitstr-ref = {path = "../../imports/blitstr-ref"}
com = {path = "../com"}
content-plugin-api = {path = "../content-plugin-api"}
log = "0.4"
log-server = {path = "../log-server"}
ticktimer-server = {path = "../ticktimer-server"}
trng = {path = "../trng"}
rtc = {path = "../rtc"}
llio = {path = "../llio"}
xous = {path = "../../xous-rs"}
xous-ipc = {path = "../../xous-ipc"}
xous-names = {path = "../xous-names"}
graphics-server = {path = "../graphics-server"}
gam = {path = "../gam"}
num-derive = {version = "0.3", default-features = false}
num-traits = {version = "0.2", default-features = false}
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
[target.'cfg(not(any(windows,unix)))'.dependencies]
utralib = {path = "../../utralib"}
# short circuit the datetime call on hosted mode
[target.'cfg(any(windows,unix))'.dependencies]
chrono = "0.4"
[features]
debugprint = []
slowstatus = [] # used for braille mode, so console isn't overwhelmed with status
# default = ["debugprint"] # "debugprint"
default = []

View file

@ -1,24 +1,31 @@
#![cfg_attr(target_os = "none", no_std)]
#![cfg_attr(target_os = "none", no_main)]
use log::info;
use com::api::BattStats;
use graphics_server::*;
use core::fmt::Write;
use blitstr_ref as blitstr;
use xous::{send_message, CID, Message, msg_scalar_unpack};
use num_traits::{ToPrimitive, FromPrimitive};
use num_traits::*;
use graphics_server::*;
const SERVER_NAME_STATUS: &str = "_Status bar manager_";
const SERVER_NAME_STATUS_GID: &str = "_Status bar GID receiver_";
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
enum StatusOpcode {
// for passing battstats on to the main thread from the callback
BattStats,
// for passing DateTime
DateTime,
// indicates time for periodic update of the status bar
Pump,
// exists to make clippy happy about unreachable code
Quit,
}
static mut CB_TO_MAIN_CONN: Option<CID> = None;
@ -53,16 +60,38 @@ pub fn pump_thread(conn: usize) {
ticktimer.sleep_ms(1000).unwrap();
}
}
#[xous::xous_main]
fn xmain() -> ! {
log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Info);
log::info!("my PID is {}", xous::process::id());
const SERVER_NAME_STATUS: &str = "_Status bar manager_";
pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usize, canvas_gid_3: usize) {
let canvas_gid = [canvas_gid_0 as u32, canvas_gid_1 as u32, canvas_gid_2 as u32, canvas_gid_3 as u32];
let xns = xous_names::XousNames::new().unwrap();
// 1 connection exactly -- from the GAM to set our canvas GID
let status_gam_getter = xns.register_name(SERVER_NAME_STATUS_GID, Some(1)).expect("can't register server");
let mut canvas_gid: [u32; 4] = [0; 4];
// wait unil we're assigned a GID -- this is a one-time message from the GAM
let msg = xous::receive_message(status_gam_getter).unwrap();
log::trace!("GID assignment message: {:?}", msg);
xous::msg_scalar_unpack!(msg, g0, g1, g2, g3, {
canvas_gid[0] = g0 as u32;
canvas_gid[1] = g1 as u32;
canvas_gid[2] = g2 as u32;
canvas_gid[3] = g3 as u32;
});
match xns.unregister_server(status_gam_getter) {
Err(e) => {
log::error!("couldn't unregister getter server: {:?}", e);
}
_ => {}
}
xous::destroy_server(status_gam_getter).unwrap();
// ok, now that we have a GID, we can continue on with our merry way
let status_gid: Gid = Gid::new(canvas_gid);
log::trace!("|status: my canvas {:?}", status_gid);
log::trace!("|status: registering GAM|status thread");
let xns = xous_names::XousNames::new().unwrap();
// should be only one connection here, from the status main loop
let status_sid = xns.register_name(SERVER_NAME_STATUS, Some(1)).expect("|status: can't register server");
// create a connection for callback hooks
@ -283,7 +312,10 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi
let dt = buffer.to_original::<rtc::DateTime, _>().unwrap();
datetime = Some(dt);
}
None => {log::error!("|status: received unknown Opcode"); break}
Some(StatusOpcode::Quit) => {
break;
}
None => {log::error!("|status: received unknown Opcode");}
}
}
log::trace!("status thread exit, destroying servers");
@ -296,4 +328,5 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi
xns.unregister_server(status_sid).unwrap();
xous::destroy_server(status_sid).unwrap();
log::trace!("status thread quitting");
xous::terminate_process(0)
}

View file

@ -83,6 +83,7 @@ struct Connection {
pub auth_conns: u32, // number of authenticated connections
pub token: Option<[u32; 4]>, // a random number that must be presented to allow for disconnection for single-connection servers
}
#[derive(Debug)]
struct SlowMap {
pub map: [Option<Connection>; 128],
}
@ -128,8 +129,8 @@ impl SlowMap {
if mapping.sid == sid {
name = Some(mapping.name);
*entry = None;
break;
}
break;
}
}
name
@ -278,6 +279,8 @@ fn xmain() -> ! {
info!("{} server has unregistered", name);
xous::return_scalar(msg.sender, 1).unwrap();
} else {
log::error!("couldn't unregister {:?}", gid);
log::error!("table: {:?}", name_table);
xous::return_scalar(msg.sender, 0).unwrap();
}
}),

View file

@ -73,7 +73,7 @@ impl core::fmt::Display for MessageSender {
}
/// Server ID
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct SID([u32; 4]);
impl SID {
pub fn from_bytes(b: &[u8]) -> Option<SID> {

View file

@ -41,6 +41,7 @@ fn main() {
fn try_main() -> Result<(), DynError> {
let hw_pkgs = [
"gam",
"status",
"shellchat",
"ime-frontend",
"ime-plugin-shell",