|
18 | 18 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; |
19 | 19 |
|
20 | 20 | use crate::data_model::{ |
21 | | - cluster_basic_information::BasicInfoConfig, |
| 21 | + cluster_basic_information::{BasicInfoConfig, BasicInfoSettings}, |
22 | 22 | sdm::{dev_att::DevAttDataFetcher, failsafe::FailSafe}, |
23 | 23 | }; |
24 | 24 | use crate::error::*; |
@@ -54,6 +54,7 @@ pub struct Matter<'a> { |
54 | 54 | pub fabric_mgr: RefCell<FabricMgr>, // Public for tests |
55 | 55 | pub(crate) pase_mgr: RefCell<PaseMgr>, |
56 | 56 | pub(crate) failsafe: RefCell<FailSafe>, |
| 57 | + pub(crate) basic_info_settings: RefCell<BasicInfoSettings>, |
57 | 58 | pub transport_mgr: TransportMgr<'a>, // Public for tests |
58 | 59 | persist_notification: Notification<NoopRawMutex>, |
59 | 60 | epoch: Epoch, |
@@ -122,6 +123,7 @@ impl<'a> Matter<'a> { |
122 | 123 | pase_mgr: RefCell::new(PaseMgr::new(epoch, rand)), |
123 | 124 | failsafe: RefCell::new(FailSafe::new(epoch, rand)), |
124 | 125 | transport_mgr: TransportMgr::new(mdns, dev_det, port, epoch, rand), |
| 126 | + basic_info_settings: RefCell::new(BasicInfoSettings::new()), |
125 | 127 | persist_notification: Notification::new(), |
126 | 128 | epoch, |
127 | 129 | rand, |
@@ -189,6 +191,7 @@ impl<'a> Matter<'a> { |
189 | 191 | pase_mgr <- RefCell::init(PaseMgr::init(epoch, rand)), |
190 | 192 | failsafe: RefCell::new(FailSafe::new(epoch, rand)), |
191 | 193 | transport_mgr <- TransportMgr::init(mdns, dev_det, port, epoch, rand), |
| 194 | + basic_info_settings <- RefCell::init(BasicInfoSettings::init()), |
192 | 195 | persist_notification: Notification::new(), |
193 | 196 | epoch, |
194 | 197 | rand, |
@@ -274,6 +277,18 @@ impl<'a> Matter<'a> { |
274 | 277 | self.fabric_mgr.borrow().is_changed() |
275 | 278 | } |
276 | 279 |
|
| 280 | + pub fn load_basic_info(&self, data: &[u8]) -> Result<(), Error> { |
| 281 | + self.basic_info_settings.borrow_mut().load(data) |
| 282 | + } |
| 283 | + |
| 284 | + pub fn store_basic_info<'b>(&self, buf: &'b mut [u8]) -> Result<Option<&'b [u8]>, Error> { |
| 285 | + self.basic_info_settings.borrow_mut().store(buf) |
| 286 | + } |
| 287 | + |
| 288 | + pub fn basic_info_changed(&self) -> bool { |
| 289 | + self.basic_info_settings.borrow().changed |
| 290 | + } |
| 291 | + |
277 | 292 | /// Return `true` if there is at least one commissioned fabric |
278 | 293 | // |
279 | 294 | // TODO: |
@@ -346,6 +361,8 @@ impl<'a> Matter<'a> { |
346 | 361 | S: NetworkSend, |
347 | 362 | R: NetworkReceive, |
348 | 363 | { |
| 364 | + // TODO: Figure out why chip-tool-tests expect the device to still be in commissioning mode |
| 365 | + // post device reboot, even if it was already commissioned |
349 | 366 | if !self.is_commissioned() { |
350 | 367 | self.enable_basic_commissioning(discovery_capabilities, 0 /*TODO*/) |
351 | 368 | .await?; |
@@ -390,24 +407,24 @@ impl<'a> Matter<'a> { |
390 | 407 | .await |
391 | 408 | } |
392 | 409 |
|
393 | | - /// Notify that the ACLs or Fabrics _might_ have changed |
394 | | - /// This method is supposed to be called after processing SC and IM messages that might affect the ACLs or Fabrics. |
| 410 | + /// Notify that the ACLs, Fabrics or Basic Info _might_ have changed |
| 411 | + /// This method is supposed to be called after processing SC and IM messages that might affect the ACLs, Fabrics or Basic Info. |
395 | 412 | /// |
396 | 413 | /// The default IM and SC handlers (`DataModel` and `SecureChannel`) do call this method after processing the messages. |
397 | 414 | /// |
398 | 415 | /// TODO: Fix the method name as it is not clear enough. Potentially revamp the whole persistence notification logic |
399 | | - pub fn notify_fabrics_maybe_changed(&self) { |
400 | | - if self.fabrics_changed() { |
| 416 | + pub fn notify_persist(&self) { |
| 417 | + if self.fabrics_changed() || self.basic_info_changed() { |
401 | 418 | self.persist_notification.notify(); |
402 | 419 | } |
403 | 420 | } |
404 | 421 |
|
405 | | - /// A hook for user persistence code to wait for potential changes in ACLs and/or Fabrics. |
406 | | - /// Once this future resolves, user code is supposed to inspect ACLs and Fabrics for changes, and |
| 422 | + /// A hook for user persistence code to wait for potential changes in ACLs, Fabrics or basic info. |
| 423 | + /// Once this future resolves, user code is supposed to inspect ACLs, Fabrics and basic info for changes, and |
407 | 424 | /// if there are changes, persist them. |
408 | 425 | /// |
409 | 426 | /// TODO: Fix the method name as it is not clear enough. Potentially revamp the whole persistence notification logic |
410 | | - pub async fn wait_fabrics_changed(&self) { |
| 427 | + pub async fn wait_persist(&self) { |
411 | 428 | self.persist_notification.wait().await |
412 | 429 | } |
413 | 430 | } |
0 commit comments