init mtxchat with bones of mtxcli

This commit is contained in:
nworbnhoj 2023-07-29 07:21:14 +10:00
parent 7c64863ef8
commit 081c669b43
5 changed files with 138 additions and 0 deletions

View file

@ -74,6 +74,7 @@ members = [
"services/early_settings",
"apps/ball",
"apps/hello",
"apps/mtxchat",
"apps/mtxcli",
"apps/repl",
"apps/vault",

View file

@ -35,6 +35,14 @@
}
}
},
"mtxchat": {
"context_name": "Matrix chat",
"menu_name": {
"appmenu.mtxchat": {
"en": "Matrix chat"
}
}
},
"repl": {
"context_name": "repl demo app",
"menu_name": {

38
apps/mtxchat/Cargo.toml Normal file
View file

@ -0,0 +1,38 @@
[package]
name = "mtxchat"
version = "0.1.0"
authors = ["john <john@nhoj.info>"]
edition = "2018"
description = "Matrix chat"
# Dependency versions enforced by Cargo.lock.
[dependencies]
log = "0.4.14"
num-derive = { version = "0.3.3", default-features = false}
num-traits = { version = "0.2.14", default-features = false}
xous = "0.9.47"
xous-ipc = "0.9.47"
log-server = { package = "xous-api-log", version = "0.1.43" }
ticktimer-server = { package = "xous-api-ticktimer", version = "0.9.43" }
xous-names = { package = "xous-api-names", version = "0.9.45" }
gam = { path = "../../services/gam" }
graphics-server = { path = "../../services/graphics-server" }
trng = { path = "../../services/trng"}
locales = { path = "../../locales"}
ime-plugin-api = { path = "../../services/ime-plugin-api"}
ime-plugin-shell = { path = "../../services/ime-plugin-shell"}
content-plugin-api = { path = "../../services/content-plugin-api"} # all content canvas providers must provide this API
codec = { path = "../../services/codec"}
com = { path = "../../services/com"}
com_rs = { git = "https://github.com/betrusted-io/com_rs", rev = "891bdd3ca8e41f81510d112483e178aea3e3a921" }
llio = { path = "../../services/llio"}
net = { path = "../../services/net" }
pddb = { path = "../../services/pddb" }
status = { path = "../../services/status" }
# new dependencies for mtxcli
percent-encoding = "2.2"
serde = { version = "1.0", features = [ "derive" ] }
ureq = { version = "2.5", features = ["json"] }
[features]
default = []

17
apps/mtxchat/src/api.rs Normal file
View file

@ -0,0 +1,17 @@
use rkyv::{Archive, Deserialize, Serialize};
pub(crate) const SERVER_NAME_MTXCHAT: &str = "_Matrix chat_";
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
pub enum MtxchatOp {
/// chat ui event
Event = 0,
/// chat ui user post
Post,
/// chat ui keystroke
Rawkeys,
/// exit the application
Quit,
}

74
apps/mtxchat/src/main.rs Normal file
View file

@ -0,0 +1,74 @@
#![cfg_attr(target_os = "none", no_std)]
#![cfg_attr(target_os = "none", no_main)]
mod api;
use api::*;
use num_traits::*;
use xous_ipc::Buffer;
fn main () -> ! {
let stack_size = 1024 * 1024;
std::thread::Builder::new()
.stack_size(stack_size)
.spawn(wrapped_main)
.unwrap()
.join()
.unwrap()
}
fn wrapped_main() -> ! {
log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Info);
log::info!("my PID is {}", xous::process::id());
const HEAP_LARGER_LIMIT: usize = 2048 * 1024;
let new_limit = HEAP_LARGER_LIMIT;
let result = xous::rsyscall(xous::SysCall::AdjustProcessLimit(
xous::Limits::HeapMaximum as usize,
0,
new_limit,
));
if let Ok(xous::Result::Scalar2(1, current_limit)) = result {
xous::rsyscall(xous::SysCall::AdjustProcessLimit(
xous::Limits::HeapMaximum as usize,
current_limit,
new_limit,
))
.unwrap();
log::info!("Heap limit increased to: {}", new_limit);
} else {
panic!("Unsupported syscall!");
}
let xns = xous_names::XousNames::new().unwrap();
let sid = xns
.register_name(SERVER_NAME_MTXCHAT, None)
.expect("can't register server");
// log::trace!("registered with NS -- {:?}", sid);
loop {
let msg = xous::receive_message(sid).unwrap();
log::debug!("got message {:?}", msg);
match FromPrimitive::from_usize(msg.body.id()) {
Some(MtxchatOp::Event) => {
}
Some(MtxchatOp::Post) => {
log::info!("TODO Post to Matrix server");
}
Some(MtxchatOp::Rawkeys) => {}
Some(MtxchatOp::Quit) => {
log::error!("got Quit");
chat.forward(msg);
break;
}
_ => (),
}
}
// clean up our program
log::error!("main loop exit, destroying servers");
xns.unregister_server(sid).unwrap();
xous::destroy_server(sid).unwrap();
log::trace!("quitting");
xous::terminate_process(0)
}