use super::*;
#[derive(Debug)]
pub struct SendObserve<IC> {
phantom: PhantomData<IC>,
}
impl<IC> SendDescUnicast for SendObserve<IC> {}
impl<IC> Default for SendObserve<IC> {
fn default() -> Self {
Self::new()
}
}
impl<IC> SendObserve<IC> {
pub(crate) fn new() -> Self {
Self {
phantom: PhantomData,
}
}
#[inline(always)]
pub fn nonconfirmable(self) -> Nonconfirmable<SendObserve<IC>> {
Default::default()
}
#[inline(always)]
pub fn multicast(self) -> Multicast<SendObserve<IC>> {
Default::default()
}
}
impl<IC: InboundContext> SendDesc<IC, ()> for SendObserve<IC> {
fn delay_to_restart(&self) -> Option<Duration> {
Some(Duration::from_secs(60))
}
fn write_options(
&self,
msg: &mut dyn OptionInsert,
socket_addr: &IC::SocketAddr,
start: Bound<OptionNumber>,
end: Bound<OptionNumber>,
) -> Result<(), Error> {
write_options!((msg, socket_addr, start, end) {
OBSERVE => Some(OBSERVE_REGISTER),
})
}
fn write_payload(
&self,
msg: &mut dyn MessageWrite,
_socket_addr: &IC::SocketAddr,
) -> Result<(), Error> {
msg.set_msg_code(MsgCode::MethodGet);
Ok(())
}
fn handler(&mut self, context: Result<&IC, Error>) -> Result<ResponseStatus<()>, Error> {
context?;
Ok(ResponseStatus::Continue)
}
}