Skip to content

Commit

Permalink
Trigger Poll::Ready for ReqInner via gcoap_req_resp_handler(), …
Browse files Browse the repository at this point in the history
…clean up
  • Loading branch information
j-devel committed Jun 11, 2024
1 parent e2eedeb commit 018cec3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
16 changes: 8 additions & 8 deletions examples/xbd-net/src/xbd/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub type Ptr32Send = u32;
enum ApiCallback {
Timeout(Ptr32Send),
_GcoapPing(Ptr32Send),
GcoapReq(Ptr32Send),
// GcoapReq(Ptr32Send),
}

static mut SD: XStreamData<ApiCallback, 64> = XStream::init();
Expand All @@ -25,9 +25,9 @@ fn add_api_callback(cb: ApiCallback) {
pub fn add_xbd_timeout_callback(arg_ptr: CVoidPtr) {
add_api_callback(ApiCallback::Timeout(arg_ptr as Ptr32Send));
}
pub fn add_xbd_gcoap_req_callback(arg_ptr: CVoidPtr) {
add_api_callback(ApiCallback::GcoapReq(arg_ptr as Ptr32Send));
}
// pub fn add_xbd_gcoap_req_callback(arg_ptr: CVoidPtr) {
// add_api_callback(ApiCallback::GcoapReq(arg_ptr as Ptr32Send));
// }

pub async fn process_api_stream() -> Result<(), i8> {
let mut xs = XStream::get(static_borrow_mut!(SD));
Expand All @@ -44,10 +44,10 @@ pub async fn process_api_stream() -> Result<(), i8> {
call(cb_ptr, ());
},
ApiCallback::_GcoapPing(_) => todo!(),
ApiCallback::GcoapReq(arg_ptr) => {
let (cb_ptr, out) = arg_from::<GcoapMemoState>(arg_ptr);
call(cb_ptr, out);
},
// ApiCallback::GcoapReq(arg_ptr) => {
// let (cb_ptr, out) = arg_from::<GcoapMemoState>(arg_ptr);
// call(cb_ptr, out);
// },
}
}

Expand Down
24 changes: 12 additions & 12 deletions examples/xbd-net/src/xbd/gcoap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub struct ReqInner {
blockwise: bool,
blockwise_state_index: Option<usize>,
blockwise_hdr: Option<heapless::Vec<u8, BLOCKWISE_HDR_MAX>>,
out: Rc<RefCell<Option<GcoapMemoState>>>,
// out: Rc<RefCell<Option<GcoapMemoState>>>,
_waker: Option<AtomicWaker>,
finale: Option<Finale>,// !!!! !!!!
}
Expand All @@ -137,7 +137,7 @@ impl ReqInner {
blockwise,
blockwise_state_index,
blockwise_hdr,
out: Rc::new(RefCell::new(None)),
// out: Rc::new(RefCell::new(None)),
_waker: Some(AtomicWaker::new()),
finale: None,// !!!! !!!!
}
Expand All @@ -151,16 +151,12 @@ impl Future for ReqInner {
if let Some(_waker) = self._waker.take() {
_waker.register(&cx.waker());

/*let outc = self.out.clone();
let cb = move |out| {
outc.borrow_mut().replace(out);
_waker.wake();
};*/
let cb = |_out| {
//outc.borrow_mut().replace(out);
//let outc = self.out.clone();
let cb = move |_out| {
//outc.borrow_mut().replace(_out);
//_waker.wake();
//==== !!!!
panic!("mmm");
panic!("debug");
};
match self.method {
COAP_METHOD_GET => {
Expand Down Expand Up @@ -197,9 +193,13 @@ impl Future for ReqInner {

Poll::Pending
} else {
//Poll::Ready(self.out.take().unwrap())
//==== !!!!
crate::println!("!!!! before Poll::Ready !!!! finale: {:?}", self.finale);

Poll::Ready(self.out.take().unwrap())
let out = GcoapMemoState::new(// TODO heapless represent `out` from `gcoap_req_resp_handler`
GCOAP_MEMO_RESP,
Some(self.finale.as_ref().unwrap().1.as_slice().to_vec())); // dummy
Poll::Ready(out)
}
}
}
Expand Down
40 changes: 23 additions & 17 deletions examples/xbd-net/src/xbd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ mod callback;
pub use callback::process_api_stream;
use callback::{
add_xbd_timeout_callback,
add_xbd_gcoap_req_callback};
// add_xbd_gcoap_req_callback
};

mod server;
pub use server::process_gcoap_server_stream;
Expand Down Expand Up @@ -171,26 +172,25 @@ impl Xbd {
*const u8, *const u8, u8,
*const u8, usize, bool, usize, *const c_void, *const c_void);

if 1 == 1 {// ok
if 0 == 1 {// waypoint, ok
let (waker, hv) = unsafe { &mut *finale_ptr };
hv.push(42).unwrap();
hv.push(42+1).unwrap();
hv.push(42+2).unwrap();
waker.wake();
return;
}
if 0 == 1 {
assert_eq!(blockwise, blockwise_state_index.is_some());
unsafe {
(get_xbd_fn!("xbd_gcoap_req_send", Ty))(
addr_cstr.as_ptr(),
uri_cstr.as_ptr(),
method, payload_ptr, payload_len,
blockwise, blockwise_state_index.unwrap_or(0 /* to be ignored */),
// callback::into_raw(cb), // context !!!!!!!!! push `waker` how??????????
// waker_ptr as *const c_void, // !!!!
finale_ptr as *const c_void, // !!!!
Self::gcoap_req_resp_handler as *const c_void);
}

assert_eq!(blockwise, blockwise_state_index.is_some());
unsafe {
(get_xbd_fn!("xbd_gcoap_req_send", Ty))(
addr_cstr.as_ptr(),
uri_cstr.as_ptr(),
method, payload_ptr, payload_len,
blockwise, blockwise_state_index.unwrap_or(0 /* to be ignored */),
//callback::into_raw(cb), // context !!!!
finale_ptr as *const c_void, // context !!!! WIP
Self::gcoap_req_resp_handler as *const c_void);
}
}

Expand All @@ -214,8 +214,14 @@ impl Xbd {
};
let out = GcoapMemoState::new(memo_state, payload);

add_xbd_gcoap_req_callback(
Box::into_raw(Box::new((context /* cb_ptr */, out))) as *const c_void); // arg_ptr
// add_xbd_gcoap_req_callback(
// Box::into_raw(Box::new((context /* cb_ptr */, out))) as *const c_void); // arg_ptr
//==== !!!! TODO hv <<<< out, heepless--ly
let (waker, hv) = unsafe { &mut *(context as *mut Finale) };
hv.push(42).unwrap();
hv.push(42+1).unwrap();
hv.push(42+2).unwrap();
waker.wake();
}

pub fn async_sleep(msec: u32) -> impl Future<Output = ()> + 'static {
Expand Down

0 comments on commit 018cec3

Please sign in to comment.