com: don't use internal xous_names register api

This API is now private.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-02-10 15:03:35 +08:00
parent 8ba7496f64
commit 704c0f47bf
3 changed files with 17 additions and 13 deletions

View file

@ -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")

View file

@ -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::Result, xous::Error> {
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
// note to future self: add other event listener registrations (such as network events) here

View file

@ -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"),