From 704c0f47bf1c233b89295bc79cbab3be0e9453cf Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Wed, 10 Feb 2021 15:03:35 +0800 Subject: [PATCH] com: don't use internal xous_names register api This API is now private. Signed-off-by: Sean Cross --- services/com/src/api.rs | 11 ++++++----- services/com/src/lib.rs | 8 ++++++-- services/com/src/main.rs | 11 +++++------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/services/com/src/api.rs b/services/com/src/api.rs index e10c9d727..410d4c8a0 100644 --- a/services/com/src/api.rs +++ b/services/com/src/api.rs @@ -1,4 +1,4 @@ -use xous::{Message, ScalarMessage}; +use xous::{Message, ScalarMessage, MemoryMessage}; // NOTE: the use of ComState "verbs" as commands is not meant as a 1:1 mapping of commands // It's just a convenient abuse of already-defined constants. However, it's intended that @@ -7,7 +7,8 @@ use com_rs_ref as com_rs; use com_rs::*; // subtype constants for registering service listeners from the COM -pub const SUBTYPE_REGISTER_BATTSTATS_LISTENER: u16 = 0; +// pub const SUBTYPE_REGISTER_BATTSTATS_LISTENER: u16 = 0; +pub const REGISTER_BATTSTATS_LISTENER: u32 = 0x0022_0000; #[derive(Debug, Default, Copy, Clone)] pub struct BattStats { @@ -105,7 +106,7 @@ pub enum Opcode<'a> { RxStatsAgent, /// request for a listener to BattStats events - RegisterBattStatsListener(xous_names::api::Registration), + RegisterBattStatsListener(xous_names::api::XousServerName), } impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> { @@ -154,9 +155,9 @@ impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> { ) }; Ok(Opcode::Wf200PdsLine(core::str::from_utf8(s).unwrap())) - } else if xous_names::api::Registration::match_subtype(m.id, SUBTYPE_REGISTER_BATTSTATS_LISTENER) { + } else if m.id as u32 == REGISTER_BATTSTATS_LISTENER { Ok(Opcode::RegisterBattStatsListener({ - unsafe { *( (m.buf.as_mut_ptr()) as *mut xous_names::api::Registration) } + unsafe { *( (m.buf.as_mut_ptr()) as *mut xous_names::api::XousServerName) } })) } else { Err("COM: unknown borrow ID") diff --git a/services/com/src/lib.rs b/services/com/src/lib.rs index 919578b06..589d972e5 100644 --- a/services/com/src/lib.rs +++ b/services/com/src/lib.rs @@ -1,5 +1,7 @@ #![cfg_attr(target_os = "none", no_std)] +use core::convert::TryInto; + /// This is the API that other servers use to call the COM. Read this code as if you /// are calling these functions inside a different process. pub mod api; @@ -63,7 +65,9 @@ pub fn get_rx_stats_agent(cid: CID) -> Result<(), Error> { // event relay request API pub fn request_battstat_events(name: &str, com_conn: xous::CID) -> Result { - xous_names::request_core(name, com_conn, api::SUBTYPE_REGISTER_BATTSTATS_LISTENER) + let s: xous_names::api::XousServerName = name.try_into()?; + let sendable = xous::ipc::Sendable::new(s)?; + sendable.lend(com_conn, api::REGISTER_BATTSTATS_LISTENER) } -// note to future self: add other event listener registrations (such as network events) here \ No newline at end of file +// note to future self: add other event listener registrations (such as network events) here diff --git a/services/com/src/main.rs b/services/com/src/main.rs index 101a32931..12ca494f2 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -245,12 +245,11 @@ fn xmain() -> ! { let com_sid = xous_names::register_name(xous::names::SERVER_NAME_COM).expect("COM: can't register server"); info!("COM: registered with NS -- {:?}", com_sid); - let agent_conn: usize; - if cfg!(feature = "fccagent") { - agent_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_FCCAGENT).expect("FCCAGENT: can't connect to COM"); + let agent_conn= if cfg!(feature = "fccagent") { + xous_names::request_connection_blocking(xous::names::SERVER_NAME_FCCAGENT).expect("FCCAGENT: can't connect to COM") } else { - agent_conn = 0; // bogus value - } + 0 // bogus value + }; // Create a new com object let mut com = XousCom::new(); @@ -351,7 +350,7 @@ fn xmain() -> ! { } } Opcode::RegisterBattStatsListener(registration) => { - let cid = xous_names::request_connection_blocking(registration.name.to_str()).expect("COM: can't connect to requested listener for reporting events"); + let cid = xous_names::request_connection_blocking(registration.to_str()).expect("COM: can't connect to requested listener for reporting events"); battstats_conns.push(cid).expect("COM: probably ran out of slots for battstats event reporting"); } _ => error!("unknown opcode"),