mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
improve cb test structure and try out bool-based cb registration
This commit is contained in:
parent
c2eaece3c8
commit
1994b730b7
5 changed files with 109 additions and 71 deletions
|
|
@ -9,16 +9,16 @@ const SERVER_NAME: &str = "_CB test client 1_";
|
||||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||||
enum Opcode {
|
enum Opcode {
|
||||||
Tick,
|
Tick,
|
||||||
Sum,
|
Result,
|
||||||
}
|
}
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
static CB_TO_MAIN_CONN: AtomicU32 = AtomicU32::new(0);
|
static CB_TO_MAIN_CONN: AtomicU32 = AtomicU32::new(0);
|
||||||
fn do_add(sum: u32) {
|
fn do_result(result: u32) {
|
||||||
let cb_to_main_conn = CB_TO_MAIN_CONN.load(Ordering::Relaxed);
|
let cb_to_main_conn = CB_TO_MAIN_CONN.load(Ordering::Relaxed);
|
||||||
if cb_to_main_conn != 0 {
|
if cb_to_main_conn != 0 {
|
||||||
xous::send_message(cb_to_main_conn,
|
xous::send_message(cb_to_main_conn,
|
||||||
xous::Message::new_scalar(Opcode::Sum.to_usize().unwrap(), sum as usize, 0, 0, 0)
|
xous::Message::new_scalar(Opcode::Result.to_usize().unwrap(), result as usize, 0, 0, 0)
|
||||||
).unwrap();
|
).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,7 +26,7 @@ fn do_add(sum: u32) {
|
||||||
#[xous::xous_main]
|
#[xous::xous_main]
|
||||||
fn xmain() -> ! {
|
fn xmain() -> ! {
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
log::set_max_level(log::LevelFilter::Trace);
|
log::set_max_level(log::LevelFilter::Info);
|
||||||
log::info!("my PID is {}", xous::process::id());
|
log::info!("my PID is {}", xous::process::id());
|
||||||
|
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
|
|
@ -41,22 +41,29 @@ fn xmain() -> ! {
|
||||||
|
|
||||||
log::trace!("ready to accept requests");
|
log::trace!("ready to accept requests");
|
||||||
let mut state = 0;
|
let mut state = 0;
|
||||||
|
let mut hooked = false;
|
||||||
loop {
|
loop {
|
||||||
let msg = xous::receive_message(sid).unwrap();
|
let msg = xous::receive_message(sid).unwrap();
|
||||||
match FromPrimitive::from_usize(msg.body.id()) {
|
match FromPrimitive::from_usize(msg.body.id()) {
|
||||||
Some(Opcode::Tick) => xous::msg_scalar_unpack!(msg, _, _, _, _, {
|
Some(Opcode::Tick) => xous::msg_scalar_unpack!(msg, _, _, _, _, {
|
||||||
if (state % 2) == 0 {
|
if (state % 2) == 0 {
|
||||||
log::trace!("hook1");
|
log::trace!("hook1");
|
||||||
cb_serv.hook_add_callback(do_add).unwrap();
|
cb_serv.hook_req_callback(do_result).unwrap();
|
||||||
cb_serv.add(1).unwrap();
|
hooked = true;
|
||||||
|
cb_serv.req().unwrap();
|
||||||
} else {
|
} else {
|
||||||
log::trace!("unhook1");
|
log::trace!("idle1");
|
||||||
cb_serv.unhook_add_callback().unwrap();
|
|
||||||
}
|
}
|
||||||
state += 1;
|
state += 1;
|
||||||
}),
|
}),
|
||||||
Some(Opcode::Sum) => xous::msg_scalar_unpack!(msg, s, _, _, _, {
|
Some(Opcode::Result) => xous::msg_scalar_unpack!(msg, result, _, _, _, {
|
||||||
log::info!("C1 sum: {}", s);
|
log::info!("C1 result: {}", result);
|
||||||
|
if hooked == false {
|
||||||
|
log::info!("**C1 without hook");
|
||||||
|
}
|
||||||
|
cb_serv.unhook_req_callback().unwrap();
|
||||||
|
hooked = false;
|
||||||
|
log::trace!("unhook1");
|
||||||
}),
|
}),
|
||||||
None => {
|
None => {
|
||||||
log::error!("couldn't convert opcode");
|
log::error!("couldn't convert opcode");
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,16 @@ const SERVER_NAME: &str = "_CB test client 2_";
|
||||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||||
enum Opcode {
|
enum Opcode {
|
||||||
Tick,
|
Tick,
|
||||||
Sum,
|
Result,
|
||||||
}
|
}
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
static CB_TO_MAIN_CONN: AtomicU32 = AtomicU32::new(0);
|
static CB_TO_MAIN_CONN: AtomicU32 = AtomicU32::new(0);
|
||||||
fn do_add(sum: u32) {
|
fn do_result(result: u32) {
|
||||||
let cb_to_main_conn = CB_TO_MAIN_CONN.load(Ordering::Relaxed);
|
let cb_to_main_conn = CB_TO_MAIN_CONN.load(Ordering::Relaxed);
|
||||||
if cb_to_main_conn != 0 {
|
if cb_to_main_conn != 0 {
|
||||||
xous::send_message(cb_to_main_conn,
|
xous::send_message(cb_to_main_conn,
|
||||||
xous::Message::new_scalar(Opcode::Sum.to_usize().unwrap(), sum as usize, 0, 0, 0)
|
xous::Message::new_scalar(Opcode::Result.to_usize().unwrap(), result as usize, 0, 0, 0)
|
||||||
).unwrap();
|
).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,7 +26,7 @@ fn do_add(sum: u32) {
|
||||||
#[xous::xous_main]
|
#[xous::xous_main]
|
||||||
fn xmain() -> ! {
|
fn xmain() -> ! {
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
log::set_max_level(log::LevelFilter::Trace);
|
log::set_max_level(log::LevelFilter::Info);
|
||||||
log::info!("my PID is {}", xous::process::id());
|
log::info!("my PID is {}", xous::process::id());
|
||||||
|
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
|
|
@ -41,24 +41,29 @@ fn xmain() -> ! {
|
||||||
|
|
||||||
log::trace!("ready to accept requests");
|
log::trace!("ready to accept requests");
|
||||||
let mut state = 0;
|
let mut state = 0;
|
||||||
|
let mut hooked = false;
|
||||||
loop {
|
loop {
|
||||||
let msg = xous::receive_message(sid).unwrap();
|
let msg = xous::receive_message(sid).unwrap();
|
||||||
match FromPrimitive::from_usize(msg.body.id()) {
|
match FromPrimitive::from_usize(msg.body.id()) {
|
||||||
Some(Opcode::Tick) => xous::msg_scalar_unpack!(msg, _, _, _, _, {
|
Some(Opcode::Tick) => xous::msg_scalar_unpack!(msg, _, _, _, _, {
|
||||||
if (state % 3) == 0 {
|
if (state % 4) == 0 {
|
||||||
log::trace!("hook2");
|
log::trace!("hook2");
|
||||||
cb_serv.hook_add_callback(do_add).unwrap();
|
cb_serv.hook_req_callback(do_result).unwrap();
|
||||||
cb_serv.add(1).unwrap();
|
hooked = true;
|
||||||
} else if (state % 3) == 2 {
|
cb_serv.req().unwrap();
|
||||||
log::trace!("unhook2");
|
|
||||||
cb_serv.unhook_add_callback().unwrap();
|
|
||||||
} else {
|
} else {
|
||||||
log::trace!("idle2");
|
log::trace!("idle2");
|
||||||
}
|
}
|
||||||
state += 1;
|
state += 1;
|
||||||
}),
|
}),
|
||||||
Some(Opcode::Sum) => xous::msg_scalar_unpack!(msg, s, _, _, _, {
|
Some(Opcode::Result) => xous::msg_scalar_unpack!(msg, result, _, _, _, {
|
||||||
log::info!("C2 sum: {}", s);
|
log::info!("C2 result: {}", result);
|
||||||
|
if hooked == false {
|
||||||
|
log::info!("**C2 without hook");
|
||||||
|
}
|
||||||
|
cb_serv.unhook_req_callback().unwrap();
|
||||||
|
hooked = false;
|
||||||
|
log::trace!("unhook1");
|
||||||
}),
|
}),
|
||||||
None => {
|
None => {
|
||||||
log::error!("couldn't convert opcode");
|
log::error!("couldn't convert opcode");
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ pub(crate) const SERVER_NAME: &str = "_Callback test server_";
|
||||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||||
pub(crate) enum Opcode {
|
pub(crate) enum Opcode {
|
||||||
RegisterTickListener,
|
RegisterTickListener,
|
||||||
RegisterAddListener,
|
RegisterReqListener,
|
||||||
Tick,
|
Tick,
|
||||||
Add,
|
Req,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||||
|
|
@ -15,8 +15,8 @@ pub enum TickCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||||
pub enum AddCallback {
|
pub enum ResultCallback {
|
||||||
Sum,
|
Result,
|
||||||
Drop,
|
Drop,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,21 +8,21 @@ use num_traits::{ToPrimitive, FromPrimitive};
|
||||||
pub struct CbTestServer {
|
pub struct CbTestServer {
|
||||||
conn: CID,
|
conn: CID,
|
||||||
tick_cb_sid: Option<xous::SID>,
|
tick_cb_sid: Option<xous::SID>,
|
||||||
add_cb_sid: Option<xous::SID>,
|
req_cb_sid: Option<xous::SID>,
|
||||||
}
|
}
|
||||||
static mut ADD_CB: Option<fn(u32)> = None;
|
static mut REQ_CB: Option<fn(u32)> = None;
|
||||||
impl CbTestServer {
|
impl CbTestServer {
|
||||||
pub fn new(xns: &xous_names::XousNames) -> Result<Self, xous::Error> {
|
pub fn new(xns: &xous_names::XousNames) -> Result<Self, xous::Error> {
|
||||||
let conn = xns.request_connection_blocking(api::SERVER_NAME).expect("Can't connect to callback test server");
|
let conn = xns.request_connection_blocking(api::SERVER_NAME).expect("Can't connect to callback test server");
|
||||||
Ok(CbTestServer {
|
Ok(CbTestServer {
|
||||||
conn,
|
conn,
|
||||||
tick_cb_sid: None,
|
tick_cb_sid: None,
|
||||||
add_cb_sid: None,
|
req_cb_sid: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn add(&mut self, a: u32) -> Result<(), xous::Error> {
|
pub fn req(&mut self) -> Result<(), xous::Error> {
|
||||||
send_message(self.conn,
|
send_message(self.conn,
|
||||||
Message::new_scalar(Opcode::Add.to_usize().unwrap(), a as _, 0, 0, 0,)
|
Message::new_scalar(Opcode::Req.to_usize().unwrap(), 0, 0, 0, 0,)
|
||||||
).map(|_|())
|
).map(|_|())
|
||||||
}
|
}
|
||||||
pub fn hook_tick_callback(&mut self, id: u32, cid: CID) -> Result<(), xous::Error> {
|
pub fn hook_tick_callback(&mut self, id: u32, cid: CID) -> Result<(), xous::Error> {
|
||||||
|
|
@ -42,44 +42,44 @@ impl CbTestServer {
|
||||||
Err(xous::Error::MemoryInUse) // can't hook it twice
|
Err(xous::Error::MemoryInUse) // can't hook it twice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn hook_add_callback(&mut self, cb: fn(u32)) -> Result<(), xous::Error> {
|
pub fn hook_req_callback(&mut self, cb: fn(u32)) -> Result<(), xous::Error> {
|
||||||
log::trace!("hooking add callback");
|
log::trace!("hooking req callback");
|
||||||
if unsafe{ADD_CB}.is_some() {
|
if unsafe{REQ_CB}.is_some() {
|
||||||
return Err(xous::Error::MemoryInUse)
|
return Err(xous::Error::MemoryInUse)
|
||||||
}
|
}
|
||||||
unsafe{ADD_CB = Some(cb)};
|
unsafe{REQ_CB = Some(cb)};
|
||||||
if self.add_cb_sid.is_none() {
|
if self.req_cb_sid.is_none() {
|
||||||
let sid = xous::create_server().unwrap();
|
let sid = xous::create_server().unwrap();
|
||||||
self.add_cb_sid = Some(sid);
|
self.req_cb_sid = Some(sid);
|
||||||
let sid_tuple = sid.to_u32();
|
let sid_tuple = sid.to_u32();
|
||||||
xous::create_thread_4(add_cb_server, sid_tuple.0 as usize, sid_tuple.1 as usize, sid_tuple.2 as usize, sid_tuple.3 as usize).unwrap();
|
xous::create_thread_4(req_cb_server, sid_tuple.0 as usize, sid_tuple.1 as usize, sid_tuple.2 as usize, sid_tuple.3 as usize).unwrap();
|
||||||
xous::send_message(self.conn,
|
xous::send_message(self.conn,
|
||||||
Message::new_scalar(Opcode::RegisterAddListener.to_usize().unwrap(),
|
Message::new_scalar(Opcode::RegisterReqListener.to_usize().unwrap(),
|
||||||
sid_tuple.0 as usize, sid_tuple.1 as usize, sid_tuple.2 as usize, sid_tuple.3 as usize
|
sid_tuple.0 as usize, sid_tuple.1 as usize, sid_tuple.2 as usize, sid_tuple.3 as usize
|
||||||
)).unwrap();
|
)).unwrap();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn unhook_add_callback(&mut self) -> Result<(), xous::Error> {
|
pub fn unhook_req_callback(&mut self) -> Result<(), xous::Error> {
|
||||||
if let Some(sid) = self.add_cb_sid.take() {
|
if let Some(sid) = self.req_cb_sid.take() {
|
||||||
// tell my handler thread to quit
|
// tell my handler thread to quit
|
||||||
log::trace!("connect for unhook");
|
log::trace!("connect for unhook");
|
||||||
let cid = xous::connect(sid).expect("can't connect to CB server for disconnect message");
|
let cid = xous::connect(sid).expect("can't connect to CB server for disconnect message");
|
||||||
log::trace!("sending drop to conn {}", cid);
|
log::trace!("sending drop to conn {}", cid);
|
||||||
send_message(cid,
|
send_message(cid,
|
||||||
Message::new_scalar(AddCallback::Drop.to_usize().unwrap(), 0, 0, 0, 0)
|
Message::new_scalar(ResultCallback::Drop.to_usize().unwrap(), 0, 0, 0, 0)
|
||||||
).unwrap();
|
).unwrap();
|
||||||
log::trace!("disconnecting unhook connection");
|
log::trace!("disconnecting unhook connection");
|
||||||
unsafe{
|
unsafe{
|
||||||
match xous::disconnect(cid) {
|
match xous::disconnect(cid) {
|
||||||
Ok(_) => log::trace!("disconnected unhook connection"),
|
Ok(_) => log::trace!("disconnected unhook connection"),
|
||||||
Err(e) => log::error!("unhook add got error: {:?}", e),
|
Err(e) => log::error!("unhook req got error: {:?}", e),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log::trace!("nullifying local state");
|
log::trace!("nullifying local state");
|
||||||
self.add_cb_sid = None;
|
self.req_cb_sid = None;
|
||||||
unsafe{ADD_CB = None};
|
unsafe{REQ_CB = None};
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -91,8 +91,8 @@ fn drop_conn(sid: xous::SID, id: usize) {
|
||||||
}
|
}
|
||||||
impl Drop for CbTestServer {
|
impl Drop for CbTestServer {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Some(sid) = self.add_cb_sid.take() {
|
if let Some(sid) = self.req_cb_sid.take() {
|
||||||
drop_conn(sid, AddCallback::Drop.to_usize().unwrap());
|
drop_conn(sid, ResultCallback::Drop.to_usize().unwrap());
|
||||||
}
|
}
|
||||||
if let Some(sid) = self.tick_cb_sid.take() {
|
if let Some(sid) = self.tick_cb_sid.take() {
|
||||||
drop_conn(sid, TickCallback::Drop.to_usize().unwrap());
|
drop_conn(sid, TickCallback::Drop.to_usize().unwrap());
|
||||||
|
|
@ -122,30 +122,30 @@ fn tick_cb_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
||||||
xous::destroy_server(sid).unwrap();
|
xous::destroy_server(sid).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_cb_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
fn req_cb_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
||||||
let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32);
|
let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32);
|
||||||
log::trace!("add callback server started");
|
log::trace!("req callback server started");
|
||||||
loop {
|
loop {
|
||||||
let msg = xous::receive_message(sid).unwrap();
|
let msg = xous::receive_message(sid).unwrap();
|
||||||
log::trace!("add callback got msg: {:?}", msg);
|
log::trace!("req callback got msg: {:?}", msg);
|
||||||
match FromPrimitive::from_usize(msg.body.id()) {
|
match FromPrimitive::from_usize(msg.body.id()) {
|
||||||
Some(AddCallback::Sum) => msg_scalar_unpack!(msg, sum, _, _, _, {
|
Some(ResultCallback::Result) => msg_scalar_unpack!(msg, result, _, _, _, {
|
||||||
unsafe {
|
unsafe {
|
||||||
if let Some(cb) = ADD_CB {
|
if let Some(cb) = REQ_CB {
|
||||||
cb(sum as u32)
|
cb(result as u32)
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Some(AddCallback::Drop) => {
|
Some(ResultCallback::Drop) => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
log::error!("got unrecognized message in add CB server, ignoring");
|
log::error!("got unrecognized message in req CB server, ignoring");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log::trace!("add callback server exiting");
|
log::trace!("req callback server exiting");
|
||||||
xous::destroy_server(sid).expect("can't destroy my server on exit!");
|
xous::destroy_server(sid).expect("can't destroy my server on exit!");
|
||||||
}
|
}
|
||||||
|
|
@ -26,13 +26,14 @@ fn pump_thread() {
|
||||||
loop {
|
loop {
|
||||||
xous::send_message(server_conn,
|
xous::send_message(server_conn,
|
||||||
xous::Message::new_scalar(Opcode::Tick.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't send Tick message");
|
xous::Message::new_scalar(Opcode::Tick.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't send Tick message");
|
||||||
ticktimer.sleep_ms(2_000).expect("couldn't sleep");
|
ticktimer.sleep_ms(500).expect("couldn't sleep");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[xous::xous_main]
|
#[xous::xous_main]
|
||||||
fn shell_main() -> ! {
|
fn shell_main() -> ! {
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
|
log::set_max_level(log::LevelFilter::Debug);
|
||||||
log::info!("my PID is {}", xous::process::id());
|
log::info!("my PID is {}", xous::process::id());
|
||||||
|
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
|
|
@ -42,9 +43,10 @@ fn shell_main() -> ! {
|
||||||
log::info!("pump thread started");
|
log::info!("pump thread started");
|
||||||
|
|
||||||
let mut tick_cb: [Option<ScalarCallback>; 32] = [None; 32];
|
let mut tick_cb: [Option<ScalarCallback>; 32] = [None; 32];
|
||||||
let mut add_cb: [Option<CID>; 32] = [None; 32];
|
let mut req_cb: [bool; 32] = [false; 32];
|
||||||
|
|
||||||
let mut sum = 0;
|
let mut ticks = 0;
|
||||||
|
let mut state = 0;
|
||||||
loop {
|
loop {
|
||||||
let msg = xous::receive_message(server).unwrap();
|
let msg = xous::receive_message(server).unwrap();
|
||||||
log::trace!("Message: {:?}", msg);
|
log::trace!("Message: {:?}", msg);
|
||||||
|
|
@ -64,17 +66,26 @@ fn shell_main() -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log::trace!("ticks: {}", ticks);
|
||||||
|
ticks += 1;
|
||||||
|
state += 1;
|
||||||
},
|
},
|
||||||
Some(Opcode::RegisterTickListener) => {
|
Some(Opcode::RegisterTickListener) => {
|
||||||
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 hookdata = buffer.to_original::<ScalarHook, _>().unwrap();
|
let hookdata = buffer.to_original::<ScalarHook, _>().unwrap();
|
||||||
do_hook(hookdata, &mut tick_cb);
|
do_hook(hookdata, &mut tick_cb);
|
||||||
},
|
},
|
||||||
Some(Opcode::RegisterAddListener) => msg_scalar_unpack!(msg, sid0, sid1, sid2, sid3, {
|
Some(Opcode::RegisterReqListener) => msg_scalar_unpack!(msg, sid0, sid1, sid2, sid3, {
|
||||||
let sid = xous::SID::from_u32(sid0 as _, sid1 as _, sid2 as _, sid3 as _);
|
let sid = xous::SID::from_u32(sid0 as _, sid1 as _, sid2 as _, sid3 as _);
|
||||||
let cid = Some(xous::connect(sid).unwrap());
|
let cid = xous::connect(sid).unwrap();
|
||||||
|
if (cid as usize) < req_cb.len() {
|
||||||
|
req_cb[cid as usize] = true;
|
||||||
|
} else {
|
||||||
|
log::error!("cid out of allowable range");
|
||||||
|
}
|
||||||
|
/*
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
for entry in add_cb.iter_mut() {
|
for entry in req_cb.iter_mut() {
|
||||||
if *entry == None {
|
if *entry == None {
|
||||||
*entry = cid;
|
*entry = cid;
|
||||||
found = true;
|
found = true;
|
||||||
|
|
@ -83,23 +94,38 @@ fn shell_main() -> ! {
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
log::error!("RegisterTickListener ran out of space registering callback");
|
log::error!("RegisterTickListener ran out of space registering callback");
|
||||||
}
|
}*/
|
||||||
}),
|
}),
|
||||||
Some(Opcode::Add) => msg_scalar_unpack!(msg, s, _, _, _, {
|
Some(Opcode::Req) => msg_scalar_unpack!(msg, _, _, _, _, {
|
||||||
sum += s;
|
//log::debug!("req_cb: {:?}", req_cb);
|
||||||
// send results to add listeners
|
// send results to request listeners
|
||||||
for maybe_conn in add_cb.iter_mut() {
|
for cid in 1..req_cb.len() { // 0 is not a valid connection
|
||||||
if let Some(conn) = maybe_conn {
|
if req_cb[cid as usize] {
|
||||||
match xous::send_message(*conn,
|
match xous::send_message(cid as u32,
|
||||||
xous::Message::new_scalar(api::AddCallback::Sum.to_usize().unwrap(), sum, 0, 0, 0)) {
|
xous::Message::new_scalar(api::ResultCallback::Result.to_usize().unwrap(), state as _, 0, 0, 0)) {
|
||||||
Err(xous::Error::ServerNotFound) => {
|
Err(xous::Error::ServerNotFound) => {
|
||||||
*maybe_conn = None // automatically de-allocate callbacks for clients that have dropped
|
log::info!("de-allocate ReqCallback");
|
||||||
|
req_cb[cid] = false;
|
||||||
},
|
},
|
||||||
Ok(xous::Result::Ok) => {}
|
Ok(xous::Result::Ok) => {}
|
||||||
_ => panic!("unhandled error or result in callback processing")
|
_ => panic!("unhandled error or result in callback processing")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
for maybe_conn in req_cb.iter_mut() {
|
||||||
|
if let Some(conn) = maybe_conn {
|
||||||
|
match xous::send_message(*conn,
|
||||||
|
xous::Message::new_scalar(api::ResultCallback::Result.to_usize().unwrap(), state as _, 0, 0, 0)) {
|
||||||
|
Err(xous::Error::ServerNotFound) => {
|
||||||
|
log::info!("de-allocate ReqCallback");
|
||||||
|
*maybe_conn = None // automatically de-allocate callbacks for clients that have dropped
|
||||||
|
},
|
||||||
|
Ok(xous::Result::Ok) => {}
|
||||||
|
_ => panic!("unhandled error or result in callback processing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}),
|
}),
|
||||||
None => {
|
None => {
|
||||||
log::error!("couldn't convert opcode");
|
log::error!("couldn't convert opcode");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue