Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to replace initial mDNS and DevAtt post-construction #193

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions rs-matter/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,31 @@ impl<'a> Matter<'a> {
self.port
}

/// A utility method to replace the initial mDNS implementation with another one.
///
/// Useful in particular with `MdnsService::Provided`, where the user would still like
/// to create the `Matter` instance in a const-context, as in e.g.:
/// `const MATTER: Matter<'static> = Matter::new(...);`
///
/// The above const-creation is incompatible with `MdnsService::Provided` which carries a
/// `&dyn Mdns` pointer, which cannot be initialized from within a const context with anything
/// else than a `const`. (At least not yet - there is an unstable nightly Rust feature for that).
///
/// The solution is to const-construct the `Matter` object with `MdnsService::Disabled`, and
/// after that - while/if we still have exclusive, mutable access to the `Matter` object -
/// replace the `MdnsService::Disabled` initial impl with another, like `MdnsService::Provided`.
pub fn replace_mdns(&mut self, mdns: MdnsService<'a>) {
self.transport_mgr
.replace_mdns(mdns.new_impl(self.dev_det, self.port));
}

/// A utility method to replace the initial Device Attestation Data Fetcher with another one.
///
/// Reasoning and use-cases explained in the documentation of `replace_mdns`.
pub fn replace_dev_att(&mut self, dev_att: &'a dyn DevAttDataFetcher) {
self.dev_att = dev_att;
}

pub fn load_fabrics(&self, data: &[u8]) -> Result<(), Error> {
self.fabric_mgr
.borrow_mut()
Expand Down
4 changes: 4 additions & 0 deletions rs-matter/src/transport/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ impl<'m> TransportMgr<'m> {
}
}

pub(crate) fn replace_mdns(&mut self, mdns: MdnsImpl<'m>) {
self.mdns = mdns;
}

#[cfg(all(feature = "large-buffers", feature = "alloc"))]
pub fn initialize_buffers(&self) -> Result<(), Error> {
let mut rx = self.rx.try_lock().map_err(|_| ErrorCode::InvalidState)?;
Expand Down
Loading