Skip to content

Commit 018cec3

Browse files
committed
Trigger Poll::Ready for ReqInner via gcoap_req_resp_handler(), clean up
1 parent e2eedeb commit 018cec3

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

examples/xbd-net/src/xbd/callback.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub type Ptr32Send = u32;
1313
enum ApiCallback {
1414
Timeout(Ptr32Send),
1515
_GcoapPing(Ptr32Send),
16-
GcoapReq(Ptr32Send),
16+
// GcoapReq(Ptr32Send),
1717
}
1818

1919
static mut SD: XStreamData<ApiCallback, 64> = XStream::init();
@@ -25,9 +25,9 @@ fn add_api_callback(cb: ApiCallback) {
2525
pub fn add_xbd_timeout_callback(arg_ptr: CVoidPtr) {
2626
add_api_callback(ApiCallback::Timeout(arg_ptr as Ptr32Send));
2727
}
28-
pub fn add_xbd_gcoap_req_callback(arg_ptr: CVoidPtr) {
29-
add_api_callback(ApiCallback::GcoapReq(arg_ptr as Ptr32Send));
30-
}
28+
// pub fn add_xbd_gcoap_req_callback(arg_ptr: CVoidPtr) {
29+
// add_api_callback(ApiCallback::GcoapReq(arg_ptr as Ptr32Send));
30+
// }
3131

3232
pub async fn process_api_stream() -> Result<(), i8> {
3333
let mut xs = XStream::get(static_borrow_mut!(SD));
@@ -44,10 +44,10 @@ pub async fn process_api_stream() -> Result<(), i8> {
4444
call(cb_ptr, ());
4545
},
4646
ApiCallback::_GcoapPing(_) => todo!(),
47-
ApiCallback::GcoapReq(arg_ptr) => {
48-
let (cb_ptr, out) = arg_from::<GcoapMemoState>(arg_ptr);
49-
call(cb_ptr, out);
50-
},
47+
// ApiCallback::GcoapReq(arg_ptr) => {
48+
// let (cb_ptr, out) = arg_from::<GcoapMemoState>(arg_ptr);
49+
// call(cb_ptr, out);
50+
// },
5151
}
5252
}
5353

examples/xbd-net/src/xbd/gcoap.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub struct ReqInner {
118118
blockwise: bool,
119119
blockwise_state_index: Option<usize>,
120120
blockwise_hdr: Option<heapless::Vec<u8, BLOCKWISE_HDR_MAX>>,
121-
out: Rc<RefCell<Option<GcoapMemoState>>>,
121+
// out: Rc<RefCell<Option<GcoapMemoState>>>,
122122
_waker: Option<AtomicWaker>,
123123
finale: Option<Finale>,// !!!! !!!!
124124
}
@@ -137,7 +137,7 @@ impl ReqInner {
137137
blockwise,
138138
blockwise_state_index,
139139
blockwise_hdr,
140-
out: Rc::new(RefCell::new(None)),
140+
// out: Rc::new(RefCell::new(None)),
141141
_waker: Some(AtomicWaker::new()),
142142
finale: None,// !!!! !!!!
143143
}
@@ -151,16 +151,12 @@ impl Future for ReqInner {
151151
if let Some(_waker) = self._waker.take() {
152152
_waker.register(&cx.waker());
153153

154-
/*let outc = self.out.clone();
155-
let cb = move |out| {
156-
outc.borrow_mut().replace(out);
157-
_waker.wake();
158-
};*/
159-
let cb = |_out| {
160-
//outc.borrow_mut().replace(out);
154+
//let outc = self.out.clone();
155+
let cb = move |_out| {
156+
//outc.borrow_mut().replace(_out);
161157
//_waker.wake();
162158
//==== !!!!
163-
panic!("mmm");
159+
panic!("debug");
164160
};
165161
match self.method {
166162
COAP_METHOD_GET => {
@@ -197,9 +193,13 @@ impl Future for ReqInner {
197193

198194
Poll::Pending
199195
} else {
196+
//Poll::Ready(self.out.take().unwrap())
197+
//==== !!!!
200198
crate::println!("!!!! before Poll::Ready !!!! finale: {:?}", self.finale);
201-
202-
Poll::Ready(self.out.take().unwrap())
199+
let out = GcoapMemoState::new(// TODO heapless represent `out` from `gcoap_req_resp_handler`
200+
GCOAP_MEMO_RESP,
201+
Some(self.finale.as_ref().unwrap().1.as_slice().to_vec())); // dummy
202+
Poll::Ready(out)
203203
}
204204
}
205205
}

examples/xbd-net/src/xbd/mod.rs

+23-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ mod callback;
22
pub use callback::process_api_stream;
33
use callback::{
44
add_xbd_timeout_callback,
5-
add_xbd_gcoap_req_callback};
5+
// add_xbd_gcoap_req_callback
6+
};
67

78
mod server;
89
pub use server::process_gcoap_server_stream;
@@ -171,26 +172,25 @@ impl Xbd {
171172
*const u8, *const u8, u8,
172173
*const u8, usize, bool, usize, *const c_void, *const c_void);
173174

174-
if 1 == 1 {// ok
175+
if 0 == 1 {// waypoint, ok
175176
let (waker, hv) = unsafe { &mut *finale_ptr };
176177
hv.push(42).unwrap();
177178
hv.push(42+1).unwrap();
178179
hv.push(42+2).unwrap();
179180
waker.wake();
181+
return;
180182
}
181-
if 0 == 1 {
182-
assert_eq!(blockwise, blockwise_state_index.is_some());
183-
unsafe {
184-
(get_xbd_fn!("xbd_gcoap_req_send", Ty))(
185-
addr_cstr.as_ptr(),
186-
uri_cstr.as_ptr(),
187-
method, payload_ptr, payload_len,
188-
blockwise, blockwise_state_index.unwrap_or(0 /* to be ignored */),
189-
// callback::into_raw(cb), // context !!!!!!!!! push `waker` how??????????
190-
// waker_ptr as *const c_void, // !!!!
191-
finale_ptr as *const c_void, // !!!!
192-
Self::gcoap_req_resp_handler as *const c_void);
193-
}
183+
184+
assert_eq!(blockwise, blockwise_state_index.is_some());
185+
unsafe {
186+
(get_xbd_fn!("xbd_gcoap_req_send", Ty))(
187+
addr_cstr.as_ptr(),
188+
uri_cstr.as_ptr(),
189+
method, payload_ptr, payload_len,
190+
blockwise, blockwise_state_index.unwrap_or(0 /* to be ignored */),
191+
//callback::into_raw(cb), // context !!!!
192+
finale_ptr as *const c_void, // context !!!! WIP
193+
Self::gcoap_req_resp_handler as *const c_void);
194194
}
195195
}
196196

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

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

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

0 commit comments

Comments
 (0)