-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP * WIP * New mDNS API * Generate random delays as per spec * Move handler as a parameter to run() * Fix service type and subtype records * Ipv4 address now optional * Fill-in the additional section as well * Process legacy queries * Remove unwraps * Make the broadcast signal a shared resource * Implement Display; fix bugs * Lower logging level * Always add the root label to NameLabels * Rename NameLabels to NameSlice * Create queries using the visitor pattern as well * Host questions chaining * Fix chaining * Fix chaining * Allow shared buffers * Switch to rs-matter-style buffers
- Loading branch information
Showing
10 changed files
with
1,532 additions
and
562 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use core::ops::{Deref, DerefMut}; | ||
|
||
use embassy_sync::{ | ||
blocking_mutex::raw::RawMutex, | ||
mutex::{Mutex, MutexGuard}, | ||
}; | ||
|
||
/// A trait for getting access to a `&mut T` buffer, potentially awaiting until a buffer becomes available. | ||
pub trait BufferAccess<T> | ||
where | ||
T: ?Sized, | ||
{ | ||
type Buffer<'a>: DerefMut<Target = T> | ||
where | ||
Self: 'a; | ||
|
||
/// Get a reference to a buffer. | ||
/// Might await until a buffer is available, as it might be in use by somebody else. | ||
/// | ||
/// Depending on its internal implementation details, access to a buffer might also be denied | ||
/// immediately, or after a certain amount of time (subject to the concrete implementation of the method). | ||
/// In that case, the method will return `None`. | ||
async fn get(&self) -> Option<Self::Buffer<'_>>; | ||
} | ||
|
||
impl<B, T> BufferAccess<T> for &B | ||
where | ||
B: BufferAccess<T>, | ||
T: ?Sized, | ||
{ | ||
type Buffer<'a> = B::Buffer<'a> where Self: 'a; | ||
|
||
async fn get(&self) -> Option<Self::Buffer<'_>> { | ||
(*self).get().await | ||
} | ||
} | ||
|
||
pub struct VecBufAccess<M, const N: usize>(Mutex<M, heapless::Vec<u8, N>>) | ||
where | ||
M: RawMutex; | ||
|
||
impl<M, const N: usize> VecBufAccess<M, N> | ||
where | ||
M: RawMutex, | ||
{ | ||
pub const fn new() -> Self { | ||
Self(Mutex::new(heapless::Vec::new())) | ||
} | ||
} | ||
|
||
pub struct VecBuf<'a, M, const N: usize>(MutexGuard<'a, M, heapless::Vec<u8, N>>) | ||
where | ||
M: RawMutex; | ||
|
||
impl<'a, M, const N: usize> Drop for VecBuf<'a, M, N> | ||
where | ||
M: RawMutex, | ||
{ | ||
fn drop(&mut self) { | ||
self.0.clear(); | ||
} | ||
} | ||
|
||
impl<'a, M, const N: usize> Deref for VecBuf<'a, M, N> | ||
where | ||
M: RawMutex, | ||
{ | ||
type Target = [u8]; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl<'a, M, const N: usize> DerefMut for VecBuf<'a, M, N> | ||
where | ||
M: RawMutex, | ||
{ | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.0 | ||
} | ||
} | ||
|
||
impl<M, const N: usize> BufferAccess<[u8]> for VecBufAccess<M, N> | ||
where | ||
M: RawMutex, | ||
{ | ||
type Buffer<'a> = VecBuf<'a, M, N> where Self: 'a; | ||
|
||
async fn get(&self) -> Option<Self::Buffer<'_>> { | ||
let mut guard = self.0.lock().await; | ||
|
||
guard.resize_default(N).unwrap(); | ||
|
||
Some(VecBuf(guard)) | ||
} | ||
} | ||
|
||
impl<M, const N: usize> Default for VecBufAccess<M, N> | ||
where | ||
M: RawMutex, | ||
{ | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
Oops, something went wrong.