use core::fmt::{Debug, Display, Formatter};
use core::ops::Deref;
use core::ptr::null;
use crate::posix::types::{EventBits, EventGroupHandle, TickType};
use crate::traits::{EventGroupFn, ToTick};
use crate::utils::Result;
pub struct EventGroup(EventGroupHandle);
unsafe impl Send for EventGroup {}
unsafe impl Sync for EventGroup {}
impl EventGroup {
pub const MAX_MASK: EventBits = EventBits::MAX >> 8;
pub fn wait_with_to_tick(&self, mask: EventBits, timeout_ticks: impl ToTick) -> EventBits {
self.wait(mask, timeout_ticks.to_ticks())
}
pub fn new() -> Result<Self> {
Ok(Self(null()))
}
}
impl EventGroupFn for EventGroup {
fn set(&self, _bits: EventBits) -> EventBits {
0
}
fn set_from_isr(&self, _bits: EventBits) -> Result<()> {
Ok(())
}
fn get(&self) -> EventBits {
0
}
fn get_from_isr(&self) -> EventBits {
0
}
fn clear(&self, _bits: EventBits) -> EventBits {
0
}
fn clear_from_isr(&self, _bits: EventBits) -> Result<()> {
Ok(())
}
fn wait(&self, _mask: EventBits, _timeout_ticks: TickType) -> EventBits {
0
}
fn delete(&mut self) {
self.0 = null();
}
}
impl Drop for EventGroup {
fn drop(&mut self) {
self.0 = null();
}
}
impl Deref for EventGroup {
type Target = EventGroupHandle;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Debug for EventGroup {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "EventGroup {{ handle: {:?} }}", self.0)
}
}
impl Display for EventGroup {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "EventGroup {{ handle: {:?} }}", self.0)
}
}