regex search/replace instances of xous_ipc::String to String

split into multiple commits for easier committing
This commit is contained in:
bunnie 2024-09-22 14:17:03 +08:00
parent 6d7a8fdc09
commit 52ffd88b40
6 changed files with 38 additions and 33 deletions

View file

@ -30,8 +30,9 @@ cos_table = { path = "../../libs/cos_table" }
pddb = { path = "../../services/pddb" } pddb = { path = "../../services/pddb" }
enumset = "1.1.2" enumset = "1.1.2"
rkyv = { version = "0.4.3", default-features = false, features = [ rkyv = { version = "0.8.8", default-features = false, features = [
"const_generics", "std",
"alloc",
] } ] }
[features] [features]

View file

@ -69,24 +69,24 @@ pub const POST_TEXT_MAX: usize = 3072;
#[derive(Archive, Serialize, Deserialize, Debug)] #[derive(Archive, Serialize, Deserialize, Debug)]
pub struct Find { pub struct Find {
pub author: xous_ipc::String<128>, pub author: String,
pub timestamp: u64, pub timestamp: u64,
pub key: Option<usize>, // the return post key if found. pub key: Option<usize>, // the return post key if found.
} }
#[derive(Archive, Serialize, Deserialize, Debug)] #[derive(Archive, Serialize, Deserialize, Debug)]
pub struct Dialogue { pub struct Dialogue {
pub dict: xous_ipc::String<128>, pub dict: String,
pub key: Option<xous_ipc::String<128>>, pub key: Option<String>,
} }
#[derive(Archive, Serialize, Deserialize, Debug)] #[derive(Archive, Serialize, Deserialize, Debug)]
pub struct Post { pub struct Post {
pub dialogue_id: xous_ipc::String<128>, pub dialogue_id: String,
pub author: xous_ipc::String<128>, pub author: String,
pub timestamp: u64, pub timestamp: u64,
pub text: xous_ipc::String<POST_TEXT_MAX>, pub text: String<POST_TEXT_MAX>,
pub attach_url: Option<xous_ipc::String<128>>, pub attach_url: Option<String>,
} }
/// Events are sent to the Chat App when key things occur in the Chat UI /// Events are sent to the Chat App when key things occur in the Chat UI
@ -128,5 +128,5 @@ pub enum AuthorFlag {
#[derive(Archive, Serialize, Deserialize, Debug)] #[derive(Archive, Serialize, Deserialize, Debug)]
pub struct BusyMessage { pub struct BusyMessage {
pub busy_msg: xous_ipc::String<128>, pub busy_msg: String,
} }

View file

@ -176,8 +176,8 @@ impl Chat {
/// * `pddb_key` - the pddb key holding a Dialogue /// * `pddb_key` - the pddb key holding a Dialogue
pub fn dialogue_set(&self, pddb_dict: &str, pddb_key: Option<&str>) -> Result<(), Error> { pub fn dialogue_set(&self, pddb_dict: &str, pddb_key: Option<&str>) -> Result<(), Error> {
let dialogue = api::Dialogue { let dialogue = api::Dialogue {
dict: xous_ipc::String::from_str(pddb_dict), dict: String::from(pddb_dict),
key: pddb_key.map(|key| xous_ipc::String::from_str(key)), key: pddb_key.map(|key| String::from(key)),
}; };
match Buffer::into_buf(dialogue) { match Buffer::into_buf(dialogue) {
Ok(buf) => buf.send(self.cid, ChatOp::DialogueSet as u32).map(|_| ()), Ok(buf) => buf.send(self.cid, ChatOp::DialogueSet as u32).map(|_| ()),
@ -224,12 +224,12 @@ impl Chat {
attach_url: Option<&str>, attach_url: Option<&str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let mut post = api::Post { let mut post = api::Post {
dialogue_id: xous_ipc::String::new(), dialogue_id: String::new(),
author: xous_ipc::String::new(), author: String::new(),
timestamp, timestamp,
text: xous_ipc::String::new(), text: String::new(),
attach_url: match attach_url { attach_url: match attach_url {
Some(url) => Some(xous_ipc::String::from_str(url)), Some(url) => Some(String::from(url)),
None => None, None => None,
}, },
}; };
@ -262,7 +262,7 @@ impl Chat {
/// ///
/// Error if unable to send the msg to the Chat UI server /// Error if unable to send the msg to the Chat UI server
pub fn post_find(&self, author: &str, timestamp: u64) -> Result<Option<usize>, Error> { pub fn post_find(&self, author: &str, timestamp: u64) -> Result<Option<usize>, Error> {
let mut find = Find { author: xous_ipc::String::new(), timestamp, key: None }; let mut find = Find { author: String::new(), timestamp, key: None };
find.author.append(author).unwrap(); find.author.append(author).unwrap();
match Buffer::into_buf(find) { match Buffer::into_buf(find) {
Ok(mut buf) => match buf.lend_mut(self.cid, ChatOp::PostFind as u32) { Ok(mut buf) => match buf.lend_mut(self.cid, ChatOp::PostFind as u32) {
@ -299,7 +299,7 @@ impl Chat {
/// ///
/// This method implements the latest recommendation of panicing on internal errors. /// This method implements the latest recommendation of panicing on internal errors.
pub fn set_status_text(&self, msg: &str) { pub fn set_status_text(&self, msg: &str) {
let bm = BusyMessage { busy_msg: xous_ipc::String::from_str(msg) }; let bm = BusyMessage { busy_msg: String::from(msg) };
Buffer::into_buf(bm) Buffer::into_buf(bm)
.expect("internal error") .expect("internal error")
.send(self.cid, ChatOp::SetStatusText as u32) .send(self.cid, ChatOp::SetStatusText as u32)
@ -326,7 +326,7 @@ impl Chat {
/// and update the text, especially when we have multiple potential servers vying /// and update the text, especially when we have multiple potential servers vying
/// to set a busy state. /// to set a busy state.
pub fn set_status_idle_text(&self, msg: &str) { pub fn set_status_idle_text(&self, msg: &str) {
let bm = BusyMessage { busy_msg: xous_ipc::String::from_str(msg) }; let bm = BusyMessage { busy_msg: String::from(msg) };
Buffer::into_buf(bm) Buffer::into_buf(bm)
.expect("internal error") .expect("internal error")
.send(self.cid, ChatOp::SetStatusIdleText as u32) .send(self.cid, ChatOp::SetStatusIdleText as u32)
@ -427,12 +427,12 @@ pub fn server(
Some(ChatOp::SetStatusText) => { Some(ChatOp::SetStatusText) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let s = buffer.to_original::<BusyMessage, _>().unwrap(); let s = buffer.to_original::<BusyMessage, _>().unwrap();
ui.set_status_text(s.busy_msg.as_str().unwrap()); ui.set_status_text(s.busy_msg.as_str());
} }
Some(ChatOp::SetStatusIdleText) => { Some(ChatOp::SetStatusIdleText) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let s = buffer.to_original::<BusyMessage, _>().unwrap(); let s = buffer.to_original::<BusyMessage, _>().unwrap();
ui.set_status_idle_text(s.busy_msg.as_str().unwrap()); ui.set_status_idle_text(s.busy_msg.as_str());
} }
Some(ChatOp::SetBusyAnimationState) => msg_scalar_unpack!(msg, state, _, _, _, { Some(ChatOp::SetBusyAnimationState) => msg_scalar_unpack!(msg, state, _, _, _, {
if state != 0 { if state != 0 {
@ -467,7 +467,7 @@ pub fn server(
Some(key) => Some(key.to_string()), Some(key) => Some(key.to_string()),
None => None, None => None,
}; };
ui.dialogue_set(dialogue.dict.as_str().unwrap(), dialogue_key.as_deref()); ui.dialogue_set(dialogue.dict.as_str(), dialogue_key.as_deref());
} }
Some(ChatOp::GamChangeFocus) => { Some(ChatOp::GamChangeFocus) => {
log::info!("ChatOp::GamChangeFocus"); log::info!("ChatOp::GamChangeFocus");
@ -487,7 +487,7 @@ pub fn server(
Some(ChatOp::GamLine) => { Some(ChatOp::GamLine) => {
log::info!("got ChatOp::GamLine"); log::info!("got ChatOp::GamLine");
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let s = buffer.as_flat::<xous_ipc::String<4000>, _>().unwrap(); let s = buffer.as_flat::<String, _>().unwrap();
match s.as_str() { match s.as_str() {
"\u{0011}" => {} "\u{0011}" => {}
"\u{0012}" => {} "\u{0012}" => {}
@ -588,9 +588,9 @@ pub fn server(
Ok(post) => ui Ok(post) => ui
.post_add( .post_add(
&dialogue_id, &dialogue_id,
post.author.as_str().unwrap(), post.author.as_str(),
post.timestamp, post.timestamp,
post.text.as_str().unwrap(), post.text.as_str(),
None, // TODO implement None, // TODO implement
) )
.unwrap(), .unwrap(),
@ -610,7 +610,7 @@ pub fn server(
log::info!("ChatOp::PostAdd"); log::info!("ChatOp::PostAdd");
let mut buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let mut buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
if let Ok(mut find) = buffer.to_original::<Find, _>() { if let Ok(mut find) = buffer.to_original::<Find, _>() {
find.key = ui.post_find(find.author.as_str().unwrap(), find.timestamp); find.key = ui.post_find(find.author.as_str(), find.timestamp);
buffer.replace(find).expect("couldn't serialize return"); buffer.replace(find).expect("couldn't serialize return");
} else { } else {
log::warn!("failed to serialize Find"); log::warn!("failed to serialize Find");
@ -648,7 +648,7 @@ pub fn now() -> u64 { SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_s
/// "context-free" (cf) communication with the chat object. /// "context-free" (cf) communication with the chat object.
/// This is accomplished by making a copy of the connection to the chat server. /// This is accomplished by making a copy of the connection to the chat server.
pub fn cf_set_status_text(chat_cid: xous::CID, msg: &str) { pub fn cf_set_status_text(chat_cid: xous::CID, msg: &str) {
let bm = BusyMessage { busy_msg: xous_ipc::String::from_str(msg) }; let bm = BusyMessage { busy_msg: String::from(msg) };
Buffer::into_buf(bm) Buffer::into_buf(bm)
.expect("internal error") .expect("internal error")
.send(chat_cid, ChatOp::SetStatusText as u32) .send(chat_cid, ChatOp::SetStatusText as u32)

View file

@ -40,7 +40,7 @@ pub struct VisualProperties {
pub(crate) struct Ui { pub(crate) struct Ui {
// optional structures that indicate new input to the Chat loop per iteration // optional structures that indicate new input to the Chat loop per iteration
// an input string // an input string
pub input: Option<xous_ipc::String<{ POST_TEXT_MAX }>>, pub input: Option<String<{ POST_TEXT_MAX }>>,
// messages from other servers // messages from other servers
msg: Option<MessageEnvelope>, msg: Option<MessageEnvelope>,
@ -105,9 +105,9 @@ impl Ui {
let token = gam let token = gam
.register_ux(UxRegistration { .register_ux(UxRegistration {
app_name: xous_ipc::String::<128>::from_str(app_name), app_name: String::from(app_name),
ux_type: gam::UxType::Chat, ux_type: gam::UxType::Chat,
predictor: Some(xous_ipc::String::<64>::from_str(crate::icontray::SERVER_NAME_ICONTRAY)), predictor: Some(String::from(crate::icontray::SERVER_NAME_ICONTRAY)),
listener: sid.to_array(), /* note disclosure of our SID to the GAM -- the secret is now listener: sid.to_array(), /* note disclosure of our SID to the GAM -- the secret is now
* shared with the GAM! */ * shared with the GAM! */
redraw_id: ChatOp::GamRedraw as u32, redraw_id: ChatOp::GamRedraw as u32,

View file

@ -12,8 +12,9 @@ utralib = { version = "0.1.24", default-features = false, features = [
"cramium-soc", "cramium-soc",
] } ] }
bitflags = "1.2.1" bitflags = "1.2.1"
rkyv = { version = "0.4.3", default-features = false, features = [ rkyv = { version = "0.8.8", default-features = false, features = [
"const_generics", "std",
"alloc",
], optional = true } ], optional = true }
num-derive = { version = "0.3.3", default-features = false } num-derive = { version = "0.3.3", default-features = false }
num-traits = { version = "0.2.14", default-features = false } num-traits = { version = "0.2.14", default-features = false }

View file

@ -21,7 +21,10 @@ pddb = { path = "../../services/pddb" }
der = { version = "0.7.6", features = ["derive"] } der = { version = "0.7.6", features = ["derive"] }
locales = { path = "../../locales" } locales = { path = "../../locales" }
rkyv = "0.4.3" rkyv = { version = "0.8.8", default-features = false, features = [
"std",
"alloc",
] }
sha2 = { version = "0.10.8" } sha2 = { version = "0.10.8" }
# note requirement for patch to xous-ring in workspace Cargo.toml # note requirement for patch to xous-ring in workspace Cargo.toml