mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
incremental changes toward a manifest-format app system
This commit is contained in:
parent
de81cf62c3
commit
05df4486ee
6 changed files with 25 additions and 36 deletions
|
|
@ -6,6 +6,7 @@ use ball::*;
|
|||
use num_traits::*;
|
||||
use xous::Message;
|
||||
|
||||
// This name should be (1) unique (2) under 64 characters long and (3) ideally descriptive.
|
||||
const BALL_SERVER_NAME: &'static str = "User app 'ball'";
|
||||
|
||||
/// Opcodes for the application main loop
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ pub(crate) enum ReplOp {
|
|||
Quit,
|
||||
}
|
||||
|
||||
// This name should be (1) unique (2) under 64 characters long and (3) ideally descriptive.
|
||||
pub(crate) const SERVER_NAME_REPL: &str = "_REPL demo application_";
|
||||
|
||||
#[xous::xous_main]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ pub mod modal;
|
|||
pub use modal::*;
|
||||
pub mod menu;
|
||||
pub use menu::*;
|
||||
pub mod apps;
|
||||
pub use apps::*;
|
||||
|
||||
use graphics_server::api::{TextOp, TextView};
|
||||
use graphics_server::api::{Point, Gid, Line, Rectangle, Circle, RoundedRectangle, TokenClaim};
|
||||
|
|
@ -32,8 +34,6 @@ pub const SHARED_MODAL_NAME: &'static str = "shared modal";
|
|||
pub const STATUS_BAR_NAME: &'static str = "status";
|
||||
pub const APP_NAME_SHELLCHAT: &'static str = "shellchat";
|
||||
pub const APP_MENU_NAME: &'static str = "app menu";
|
||||
pub const APP_NAME_BALL: &'static str = "ball demo app";
|
||||
pub const APP_NAME_REPL: &'static str = "repl demo app";
|
||||
|
||||
/// UX context registry. Names here are authorized by the GAM to have Canvases.
|
||||
pub const EXPECTED_BOOT_CONTEXTS: &[&'static str] = &[
|
||||
|
|
@ -46,8 +46,6 @@ pub const EXPECTED_BOOT_CONTEXTS: &[&'static str] = &[
|
|||
SHARED_MODAL_NAME,
|
||||
PDDB_MENU_NAME,
|
||||
APP_MENU_NAME,
|
||||
APP_NAME_BALL,
|
||||
APP_NAME_REPL,
|
||||
];
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use gam::EXPECTED_BOOT_CONTEXTS;
|
||||
use gam::{EXPECTED_BOOT_CONTEXTS, EXPECTED_APP_CONTEXTS};
|
||||
|
||||
/*
|
||||
Authentication tokens to the GAM are created on a first-come, first-serve basis,
|
||||
|
|
@ -29,7 +29,7 @@ impl<'a> TokenManager {
|
|||
}
|
||||
/// checks to see if all the slots have been occupied. We can't allow untrusted code to run until all slots have checked in
|
||||
pub(crate) fn allow_untrusted_code(&self) -> bool {
|
||||
if self.tokens.len() == EXPECTED_BOOT_CONTEXTS.len() {
|
||||
if self.tokens.len() == (EXPECTED_BOOT_CONTEXTS.len() + EXPECTED_APP_CONTEXTS.len()) {
|
||||
true
|
||||
} else {
|
||||
// throw a bone to the dev who has to debug this error. This typically only triggers after a major
|
||||
|
|
@ -44,8 +44,15 @@ impl<'a> TokenManager {
|
|||
pub(crate) fn claim_token(&mut self, name: &str) -> Option<[u32; 4]> {
|
||||
log::trace!("claiming token {}", name);
|
||||
// first check if the name is valid
|
||||
if EXPECTED_BOOT_CONTEXTS.iter().find(|&&context| context == name).is_none() {
|
||||
log::error!("Server {} is not pre-registered in gam/lib.rs/EXPECTED_BOOT_CONTEXTS. Did you forget to register it?", name);
|
||||
let mut found = false;
|
||||
if EXPECTED_BOOT_CONTEXTS.iter().find(|&&context| context == name).is_some() {
|
||||
found = true;
|
||||
}
|
||||
if EXPECTED_APP_CONTEXTS.iter().find(|&&context| context == name).is_some() {
|
||||
found = true;
|
||||
}
|
||||
if !found {
|
||||
log::error!("Server {} is not pre-registered in gam/lib.rs/EXPECTED_BOOT_CONTEXTS or apps.rs/EXPECTED_APP_CONTEXTS. Did you forget to register it?", name);
|
||||
return None
|
||||
}
|
||||
// now check if it hasn't already been registered
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use gam::*;
|
|||
use locales::t;
|
||||
use num_traits::*;
|
||||
|
||||
use crate::StatusOpcode;
|
||||
use crate::{StatusOpcode, app_autogen};
|
||||
|
||||
pub fn create_app_menu(status_conn: xous::CID) {
|
||||
let mut menu_items = Vec::<MenuItem>::new();
|
||||
|
|
@ -15,21 +15,8 @@ pub fn create_app_menu(status_conn: xous::CID) {
|
|||
close_on_select: true,
|
||||
});
|
||||
|
||||
menu_items.push(MenuItem {
|
||||
name: xous_ipc::String::from_str(t!("appmenu.ball", xous::LANG)),
|
||||
action_conn: Some(status_conn),
|
||||
action_opcode: StatusOpcode::SwitchToBall.to_u32().unwrap(),
|
||||
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
});
|
||||
|
||||
menu_items.push(MenuItem {
|
||||
name: xous_ipc::String::from_str(t!("appmenu.repl", xous::LANG)),
|
||||
action_conn: Some(status_conn),
|
||||
action_opcode: StatusOpcode::SwitchToRepl.to_u32().unwrap(),
|
||||
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
});
|
||||
// insert the application menu items
|
||||
app_autogen::app_menu_items(&mut menu_items, status_conn);
|
||||
|
||||
menu_items.push(MenuItem {
|
||||
name: xous_ipc::String::from_str(t!("mainmenu.closemenu", xous::LANG)),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ mod mainmenu;
|
|||
use mainmenu::*;
|
||||
mod appmenu;
|
||||
use appmenu::*;
|
||||
mod app_autogen;
|
||||
|
||||
use com::api::*;
|
||||
use core::fmt::Write;
|
||||
|
|
@ -31,7 +32,7 @@ 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 {
|
||||
pub(crate) enum StatusOpcode {
|
||||
/// for passing battstats on to the main thread from the callback
|
||||
BattStats,
|
||||
/// for passing DateTime
|
||||
|
|
@ -50,10 +51,8 @@ enum StatusOpcode {
|
|||
|
||||
/// Raise the Shellchat app
|
||||
SwitchToShellchat,
|
||||
/// Raise the Ball app
|
||||
SwitchToBall,
|
||||
/// Raise the REPL demo app
|
||||
SwitchToRepl,
|
||||
/// Switch to an app
|
||||
SwitchToApp,
|
||||
|
||||
/// Suspend handler from the main menu
|
||||
TrySuspend,
|
||||
|
|
@ -694,14 +693,10 @@ fn xmain() -> ! {
|
|||
ticktimer.sleep_ms(100).ok();
|
||||
gam.switch_to_app(gam::APP_NAME_SHELLCHAT, security_tv.token.unwrap()).expect("couldn't raise shellchat");
|
||||
},
|
||||
Some(StatusOpcode::SwitchToBall) => {
|
||||
Some(StatusOpcode::SwitchToApp) => msg_scalar_unpack!(msg, index, _, _, _, {
|
||||
ticktimer.sleep_ms(100).ok();
|
||||
gam.switch_to_app(gam::APP_NAME_BALL, security_tv.token.unwrap()).expect("couldn't raise ball demo");
|
||||
},
|
||||
Some(StatusOpcode::SwitchToRepl) => {
|
||||
ticktimer.sleep_ms(100).ok();
|
||||
gam.switch_to_app(gam::APP_NAME_REPL, security_tv.token.unwrap()).expect("couldn't raise repl demo");
|
||||
},
|
||||
app_autogen::app_dispatch(&gam, security_tv.token.unwrap(), index);
|
||||
}),
|
||||
Some(StatusOpcode::TrySuspend) => {
|
||||
if ((llio.adc_vbus().unwrap() as f64) * 0.005033) > 1.5 {
|
||||
modals.show_notification(t!("mainmenu.cant_sleep", xous::LANG)).expect("couldn't notify that power is plugged in");
|
||||
|
|
|
|||
Loading…
Reference in a new issue