From fc4a2e5cefee4168092baacd732d0142aa6de232 Mon Sep 17 00:00:00 2001 From: Matt Swartwout Date: Wed, 17 Apr 2024 23:20:55 +0000 Subject: [PATCH] A few more fixes --- .../GenericConnectivityManagerImpl_Thread.ipp | 10 +++--- ...nericThreadStackManagerImpl_OpenThread.hpp | 32 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.ipp b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.ipp index b2ee27a424c730..23b626033593ef 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.ipp +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.ipp @@ -71,11 +71,11 @@ void GenericConnectivityManagerImpl_Thread::UpdateServiceConnectivity { ChipDeviceEvent event{ .Type = DeviceEventType::kServiceConnectivityChange, - .ServiceConnectivityChange = { - .Overall = { .Result = event.ServiceConnectivityChange.ViaThread.Result }, - .ViaThread = { .Result = (haveServiceConnectivity) ? kConnectivity_Established - : kConnectivity_Lost } } }; - CHIP_ERROR status = PlatformMgr().PostEvent(&event); + .ServiceConnectivityChange = { .ViaThread = { .Result = (haveServiceConnectivity) + ? kConnectivity_Established + : kConnectivity_Lost } } }; + event.ServiceConnectivityChange.Overall.Result = event.ServiceConnectivityChange.ViaThread.Result; + CHIP_ERROR status = PlatformMgr().PostEvent(&event); if (status != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "Failed to post thread connectivity change: %" CHIP_ERROR_FORMAT, status.Format()); diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp index 15f9f80115cd3a..7183263d32d3ae 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp @@ -122,13 +122,17 @@ NetworkCommissioning::otScanResponseIterator void GenericThreadStackManagerImpl_OpenThread::OnOpenThreadStateChange(uint32_t flags, void * context) { - ChipDeviceEvent event; - event.Type = DeviceEventType::kThreadStateChange; - event.ThreadStateChange.RoleChanged = (flags & OT_CHANGED_THREAD_ROLE) != 0; - event.ThreadStateChange.AddressChanged = (flags & (OT_CHANGED_IP6_ADDRESS_ADDED | OT_CHANGED_IP6_ADDRESS_REMOVED)) != 0; - event.ThreadStateChange.NetDataChanged = (flags & OT_CHANGED_THREAD_NETDATA) != 0; - event.ThreadStateChange.ChildNodesChanged = (flags & (OT_CHANGED_THREAD_CHILD_ADDED | OT_CHANGED_THREAD_CHILD_REMOVED)) != 0; - event.ThreadStateChange.OpenThread.Flags = flags; + ChipDeviceEvent event + { + .Type = DeviceEventType::kThreadStateChange; + .ThreadStateChange = { + .RoleChanged = (flags & OT_CHANGED_THREAD_ROLE) != 0, + .AddressChanged = (flags & (OT_CHANGED_IP6_ADDRESS_ADDED | OT_CHANGED_IP6_ADDRESS_REMOVED)) != 0, + .NetDataChanged = (flags & OT_CHANGED_THREAD_NETDATA) != 0, + .ChildNodesChanged = (flags & (OT_CHANGED_THREAD_CHILD_ADDED | OT_CHANGED_THREAD_CHILD_REMOVED)) != 0, + .OpenThread = { .Flags = flags } + } + }; CHIP_ERROR status = PlatformMgr().PostEvent(&event); if (status != CHIP_NO_ERROR) @@ -210,11 +214,10 @@ void GenericThreadStackManagerImpl_OpenThread::_OnPlatformEvent(const // Avoid sending muliple events if the attachement state didn't change (Child->router or disable->Detached) if (event->ThreadStateChange.RoleChanged && (isThreadAttached != mIsAttached)) { - ChipDeviceEvent attachEvent; - attachEvent.Clear(); - attachEvent.Type = DeviceEventType::kThreadConnectivityChange; - attachEvent.ThreadConnectivityChange.Result = (isThreadAttached) ? kConnectivity_Established : kConnectivity_Lost; - CHIP_ERROR status = PlatformMgr().PostEvent(&attachEvent); + ChipDeviceEvent attachEvent{ .Type = DeviceEventType::kThreadConnectivityChange, + .ThreadConnectivityChange = { .Result = (isThreadAttached) ? kConnectivity_Established + : kConnectivity_Lost } }; + CHIP_ERROR status = PlatformMgr().PostEvent(&attachEvent); if (status == CHIP_NO_ERROR) { mIsAttached = isThreadAttached; @@ -300,9 +303,8 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetThreadProvis } // post an event alerting other subsystems about change in provisioning state - ChipDeviceEvent event; - event.Type = DeviceEventType::kServiceProvisioningChange; - event.ServiceProvisioningChange.IsServiceProvisioned = true; + ChipDeviceEvent event{ .Type = DeviceEventType::kServiceProvisioningChange, + .ServiceProvisioningChange = { .IsServiceProvisioned = true } }; return PlatformMgr().PostEvent(&event); }