diff --git a/Cargo.lock b/Cargo.lock index 274c1b7c3..74baa1aa4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1074,6 +1074,22 @@ dependencies = [ "xous-names", ] +[[package]] +name = "shellchat" +version = "0.1.0" +dependencies = [ + "gam", + "heapless", + "ime-plugin-api", + "log", + "log-server", + "rkyv", + "ticktimer-server", + "utralib", + "xous", + "xous-names", +] + [[package]] name = "shlex" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 585278411..40b9ef23b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ members = [ "services/benchmark-target", "services/ime-frontend", "services/ime-plugin-shell", + "services/shellchat", "svd2utra", "xtask", "imports/blitstr-ref", @@ -45,6 +46,7 @@ default-members = [ "services/benchmark-target", "services/ime-frontend", "services/ime-plugin-shell", + "services/shellchat", "services/llio", "services/trng-tester", ] diff --git a/services/ime-frontend/src/main.rs b/services/ime-frontend/src/main.rs index 1ee381c49..82d354ac3 100644 --- a/services/ime-frontend/src/main.rs +++ b/services/ime-frontend/src/main.rs @@ -615,8 +615,10 @@ fn xmain() -> ! { } }, rkyv::Archived::::RegisterListener(registration) => { + let s: xous::String<256> = registration.unarchive(); // note second copy down below, this is put in early-init because we're likely to get these requests early on - let cid = xous_names::request_connection_blocking(registration.as_str()).expect("IMEF: can't connect to requested listener for reporting events"); + let cid = xous_names::request_connection_blocking(s.as_str().expect("IMEF: can't decode RegisterListener string")) + .expect("IMEF: can't connect to requested listener for reporting events"); listeners.push(cid).expect("IMEF: probably ran out of slots for input event reporting"); }, _ => panic!("IME_SH: invalid response from server -- corruption occurred in MemoryMessage") @@ -667,7 +669,10 @@ fn xmain() -> ! { } }, rkyv::Archived::::RegisterListener(registration) => { - let cid = xous_names::request_connection_blocking(registration.as_str()).expect("IMEF: can't connect to requested listener for reporting events"); + let s: xous::String<256> = registration.unarchive(); + // note first copy above, put in early-init because we're likely to get these requests early on + let cid = xous_names::request_connection_blocking(s.as_str().expect("IMEF: can't decode RegisterListener string")) + .expect("IMEF: can't connect to requested listener for reporting events"); listeners.push(cid).expect("IMEF: probably ran out of slots for input event reporting"); }, _ => panic!("IME_SH: invalid response from server -- corruption occurred in MemoryMessage") diff --git a/services/ime-plugin-api/src/lib.rs b/services/ime-plugin-api/src/lib.rs index 3bcc05d76..9605e141f 100644 --- a/services/ime-plugin-api/src/lib.rs +++ b/services/ime-plugin-api/src/lib.rs @@ -232,7 +232,7 @@ pub enum ImefOpcode { SetPredictionServer(xous::String<256>), /// register a listener for finalized inputs - RegisterListener(xous_names::api::XousServerName), + RegisterListener(xous::String<256>), /// this is the event opcode used by listeners GotInputLine(xous::String<4000>), @@ -270,6 +270,7 @@ pub trait ImeFrontEndApi { fn set_input_canvas(&self, g: graphics_server::Gid) -> Result<(), xous::Error>; fn set_prediction_canvas(&self, g: graphics_server::Gid) -> Result<(), xous::Error>; fn set_predictor(&self, servername: &str) -> Result<(), xous::Error>; + fn register_listener(&self, servername: &str) -> Result<(), xous::Error>; } pub struct ImeFrontEnd { @@ -314,4 +315,22 @@ impl ImeFrontEndApi for ImeFrontEnd { _ => Err(xous::Error::UseBeforeInit) } } + + fn register_listener(&self, servername: &str) -> Result<(), xous::Error> { + match self.connection { + Some(cid) => { + let mut server = xous::String::<256>::new(); + use core::fmt::Write; + write!(server, "{}", servername).expect("IMEF: couldn't write set_predictor server name"); + let ime_op = ImefOpcode::RegisterListener(server); + + use rkyv::Write as ArchiveWrite; + let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096)); + let pos = writer.archive(&ime_op).expect("IMEF: couldn't archive SetPredictionServer"); + writer.into_inner().lend(cid, pos as u32).expect("IMEF: SetPredicitonServer request failure"); + Ok(()) + }, + _ => Err(xous::Error::UseBeforeInit) + } + } } \ No newline at end of file diff --git a/services/shellchat/Cargo.toml b/services/shellchat/Cargo.toml new file mode 100644 index 000000000..a72dddc4d --- /dev/null +++ b/services/shellchat/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "shellchat" +version = "0.1.0" +authors = ["bunnie "] +edition = "2018" +description = "A shell with a chat-like interface" + +[dependencies] +xous = { path = "../../xous-rs" } +heapless = "0.5.6" +log-server = { path = "../log-server" } +ticktimer-server = { path = "../ticktimer-server" } +xous-names = { path = "../xous-names" } +gam = {path="../gam"} +ime-plugin-api = {path="../ime-plugin-api"} +log = "0.4" +rkyv = { version = "0.3.1", default_features = false } + + +[target.'cfg(not(any(windows,unix)))'.dependencies] +utralib = { path = "../../utralib"} + +[features] +debugprint = [] +default = [] # "debugprint" diff --git a/services/shellchat/src/main.rs b/services/shellchat/src/main.rs new file mode 100644 index 000000000..0828e4ed1 --- /dev/null +++ b/services/shellchat/src/main.rs @@ -0,0 +1,67 @@ +#![cfg_attr(target_os = "none", no_std)] +#![cfg_attr(target_os = "none", no_main)] + +use log::{error, info}; + +use core::fmt::Write; + +use rkyv::Unarchive; +use rkyv::archived_value; +use core::pin::Pin; + +use ime_plugin_api::{ImeFrontEndApi, ImeFrontEnd}; + +use heapless::spsc::Queue; +use heapless::consts::U4; + +fn repl(history: &mut Queue, U4>) -> Result<(), xous::Error> { + for &s in history.iter() { + info!("SHCH: command history {}", s); + } + + Ok(()) +} + +#[xous::xous_main] +fn xmain() -> ! { + log_server::init_wait().unwrap(); + info!("SHCH: my PID is {}", xous::process::id()); + + let shch_sid = xous_names::register_name(xous::names::SERVER_NAME_SHELLCHAT).expect("SHCH: can't register server"); + info!("SHCH: registered with NS -- {:?}", shch_sid); + + let imef_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_IME_FRONT).expect("SHCH: can't connect to IMEF"); + let imef = ImeFrontEnd { connection: Some(imef_conn) }; + imef.register_listener(xous::names::SERVER_NAME_IME_FRONT).expect("SHCH: couldn't request events from IMEF"); + + let mut history: Queue, U4> = Queue::new(); // this has 2^4 elements = 16??? + + info!("SHCH: starting main loop"); + loop { + let envelope = xous::receive_message(shch_sid).unwrap(); + if let xous::Message::Move(m) = &envelope.body { + let buf = unsafe { xous::XousBuffer::from_memory_message(m) }; + let bytes = Pin::new(buf.as_ref()); + let value = unsafe { + archived_value::(&bytes, m.id as usize) + }; + match &*value { + rkyv::Archived::::GotInputLine(rkyv_s) => { + let s: xous::String<4000> = rkyv_s.unarchive(); + let mut local: xous::String<1024> = xous::String::new(); + write!(local, "{}", s.as_str().expect("SHCH: couldn't convert incoming string")).expect("SHCH: probably exceeded input length"); + + if history.len() == history.capacity() { + history.dequeue().expect("SHCH: couldn't dequeue historye"); + } + history.enqueue(local).expect("SHCH: couldn't store input line"); + + repl(&mut history).expect("SHCH: repl experienced an error"); + }, + _ => panic!("SHCH: invalid response from server -- corruption occurred in MemoryMessage") + }; + } else { + error!("SHCH: couldn't convert message"); + } + } +} diff --git a/xous-rs/src/names.rs b/xous-rs/src/names.rs index e8873bdd4..394d73af2 100644 --- a/xous-rs/src/names.rs +++ b/xous-rs/src/names.rs @@ -15,6 +15,7 @@ pub const SERVER_NAME_GAM: &str = "_Graphical Abstraction Manager_"; pub const SERVER_NAME_STATUS: &str = "_Status bar manager_"; pub const SERVER_NAME_IME_FRONT: &str = "_IME front end_"; pub const SERVER_NAME_IME_PLUGIN_SHELL: &str = "_IME shell plugin_"; +pub const SERVER_NAME_SHELLCHAT: &str = "_Shell chat application_"; pub const SERVER_NAME_FCCAGENT: &str = "_Agent for EMC Testing_"; pub const SERVER_NAME_BENCHMARK: &str= "_Benchmark target_"; diff --git a/xtask/src/main.rs b/xtask/src/main.rs index b167bdb3b..fbe4cbb04 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -39,6 +39,7 @@ fn try_main() -> Result<(), DynError> { let hw_pkgs = [ "gam", //"shell", + "shellchat", "ime-frontend", "ime-plugin-shell", "graphics-server", @@ -194,6 +195,7 @@ fn run(debug: bool) -> Result<(), DynError> { "gam", "ime-frontend", "ime-plugin-shell", + "shellchat", //"benchmark", //"benchmark-target", "log-server",