From 74ba475914dcbd1404bd96c248b2c71d35c74b16 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 7 Nov 2025 14:21:10 -0800 Subject: [PATCH] [border-agent] move TXT data management to `TxtData` class (#12120) Moves the management of MeshCoP service TXT data from the `BorderAgent::Manager` class into the `TxtData` class. This change improves separation of concerns by isolating all TXT data-related logic, including vendor TXT data, change callbacks, and notifier event handling, within the `TxtData` class. The `BorderAgent::Manager` is simplified and its responsibilities are more focused. A new public method, `Refresh()`, is introduced on `TxtData` to provide a clear API for other modules to signal that the MeshCoP service TXT data needs to be re-evaluated and updated. --- src/core/api/border_agent_api.cpp | 4 +- src/core/border_router/routing_manager.cpp | 2 +- src/core/common/notifier.cpp | 1 + src/core/instance/instance.cpp | 2 +- src/core/instance/instance.hpp | 2 +- src/core/meshcop/border_agent.cpp | 80 +++++----------------- src/core/meshcop/border_agent.hpp | 68 ++++-------------- src/core/meshcop/border_agent_txt_data.cpp | 49 +++++++++++++ src/core/meshcop/border_agent_txt_data.hpp | 78 ++++++++++++++++++++- tests/nexus/test_border_agent.cpp | 6 +- tests/unit/test_tasklet.cpp | 9 ++- 11 files changed, 171 insertions(+), 130 deletions(-) diff --git a/src/core/api/border_agent_api.cpp b/src/core/api/border_agent_api.cpp index 814c352ef..ebd1b5075 100644 --- a/src/core/api/border_agent_api.cpp +++ b/src/core/api/border_agent_api.cpp @@ -67,7 +67,7 @@ otError otBorderAgentSetMeshCoPServiceBaseName(otInstance *aInstance, const char void otBorderAgentSetVendorTxtData(otInstance *aInstance, const uint8_t *aVendorData, uint16_t aVendorDataLength) { - AsCoreType(aInstance).Get().SetVendorTxtData(aVendorData, aVendorDataLength); + AsCoreType(aInstance).Get().SetVendorData(aVendorData, aVendorDataLength); } #endif @@ -106,7 +106,7 @@ void otBorderAgentSetMeshCoPServiceChangedCallback(otInstance otBorderAgentMeshCoPServiceChangedCallback aCallback, void *aContext) { - AsCoreType(aInstance).Get().SetServiceChangedCallback(aCallback, aContext); + AsCoreType(aInstance).Get().SetChangedCallback(aCallback, aContext); } otError otBorderAgentGetMeshCoPServiceTxtData(otInstance *aInstance, otBorderAgentMeshCoPServiceTxtData *aTxtData) diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 226aea6a1..06dd00f94 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -827,7 +827,7 @@ void RoutingManager::OmrPrefixManager::SetFavoredPrefix(const OmrPrefix &aOmrPre if (oldFavoredPrefix != mFavoredPrefix) { #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE - Get().HandleFavoredOmrPrefixChanged(); + Get().Refresh(); #endif LogInfo("Favored OMR prefix: %s -> %s", FavoredToString(oldFavoredPrefix).AsCString(), FavoredToString(mFavoredPrefix).AsCString()); diff --git a/src/core/common/notifier.cpp b/src/core/common/notifier.cpp index ad09b7793..3c0576dd9 100644 --- a/src/core/common/notifier.cpp +++ b/src/core/common/notifier.cpp @@ -132,6 +132,7 @@ void Notifier::EmitEvents(void) #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE Get().HandleNotifierEvents(events); + Get().HandleNotifierEvents(events); #endif #if OPENTHREAD_CONFIG_MLR_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE) Get().HandleNotifierEvents(events); diff --git a/src/core/instance/instance.cpp b/src/core/instance/instance.cpp index 1e399390b..0b853db47 100644 --- a/src/core/instance/instance.cpp +++ b/src/core/instance/instance.cpp @@ -172,8 +172,8 @@ Instance::Instance(void) , mNetworkDiagnosticClient(*this) #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE - , mBorderAgentManager(*this) , mBorderAgentTxtData(*this) + , mBorderAgentManager(*this) #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE && OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE , mBorderAgentEphemeralKeyManager(*this) diff --git a/src/core/instance/instance.hpp b/src/core/instance/instance.hpp index 274b8286b..ec4438816 100644 --- a/src/core/instance/instance.hpp +++ b/src/core/instance/instance.hpp @@ -592,8 +592,8 @@ private: #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE - MeshCoP::BorderAgent::Manager mBorderAgentManager; MeshCoP::BorderAgent::TxtData mBorderAgentTxtData; + MeshCoP::BorderAgent::Manager mBorderAgentManager; #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE && OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE diff --git a/src/core/meshcop/border_agent.cpp b/src/core/meshcop/border_agent.cpp index daa2e58ee..b2a1c4509 100644 --- a/src/core/meshcop/border_agent.cpp +++ b/src/core/meshcop/border_agent.cpp @@ -60,13 +60,11 @@ Manager::Manager(Instance &aInstance) #if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE , mIdInitialized(false) #endif - , mServiceTask(aInstance) { ClearAllBytes(mCounters); #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE ClearAllBytes(mServiceName); - PostServiceTask(); static_assert(sizeof(kDefaultBaseServiceName) - 1 <= kBaseServiceNameMaxLen, "OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME is too long"); @@ -105,7 +103,8 @@ void Manager::SetId(const Id &aId) Get().Save(aId); mId = aId; mIdInitialized = true; - PostServiceTask(); + + Get().Refresh(); exit: return; @@ -117,6 +116,9 @@ void Manager::SetEnabled(bool aEnabled) VerifyOrExit(mEnabled != aEnabled); mEnabled = aEnabled; LogInfo("%sabling Border Agent", mEnabled ? "En" : "Dis"); + + Get().Refresh(); + UpdateState(); #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE @@ -160,10 +162,10 @@ void Manager::Start(void) pskc.Clear(); mIsRunning = true; - PostServiceTask(); - LogInfo("Border Agent start listening on port %u", GetUdpPort()); + Get().Refresh(); + exit: if (!mIsRunning) { @@ -179,23 +181,17 @@ void Manager::Stop(void) mDtlsTransport.Close(); mIsRunning = false; - PostServiceTask(); LogInfo("Border Agent stopped"); + Get().Refresh(); + exit: return; } uint16_t Manager::GetUdpPort(void) const { return mDtlsTransport.GetUdpPort(); } -void Manager::SetServiceChangedCallback(ServiceChangedCallback aCallback, void *aContext) -{ - mServiceChangedCallback.Set(aCallback, aContext); - - PostServiceTask(); -} - void Manager::HandleNotifierEvents(Events aEvents) { if (aEvents.Contains(kEventThreadRoleChanged)) @@ -205,12 +201,6 @@ void Manager::HandleNotifierEvents(Events aEvents) VerifyOrExit(mEnabled); - if (aEvents.ContainsAny(kEventThreadRoleChanged | kEventThreadExtPanIdChanged | kEventThreadNetworkNameChanged | - kEventThreadBackboneRouterStateChanged | kEventActiveDatasetChanged)) - { - PostServiceTask(); - } - if (aEvents.ContainsAny(kEventPskcChanged)) { Pskc pskc; @@ -358,33 +348,6 @@ exit: return; } -void Manager::PostServiceTask(void) -{ - VerifyOrExit(mEnabled); - -#if !OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE - VerifyOrExit(mServiceChangedCallback.IsSet()); -#endif - - mServiceTask.Post(); - -exit: - return; -} - -void Manager::HandleServiceTask(void) -{ - VerifyOrExit(mEnabled); - -#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE - RegisterService(); -#endif - mServiceChangedCallback.InvokeIfSet(); - -exit: - return; -} - #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE Error Manager::SetServiceBaseName(const char *aBaseName) @@ -407,17 +370,6 @@ exit: return error; } -void Manager::SetVendorTxtData(const uint8_t *aVendorData, uint16_t aVendorDataLength) -{ - VerifyOrExit(!mVendorTxtData.Matches(aVendorData, aVendorDataLength)); - - SuccessOrAssert(mVendorTxtData.SetFrom(aVendorData, aVendorDataLength)); - PostServiceTask(); - -exit: - return; -} - const char *Manager::GetServiceName(void) { if (IsServiceNameEmpty()) @@ -438,6 +390,7 @@ void Manager::ConstrcutServiceName(const char *aBaseName, Dns::Name::LabelBuffer void Manager::RegisterService(void) { Dnssd::Service service; + uint16_t vendorDataLength; uint8_t *txtDataBuffer; uint16_t txtDataBufferSize; uint16_t txtDataLength; @@ -450,16 +403,17 @@ void Manager::RegisterService(void) // TXT data. The vendor TXT Data is appended at the // end. - txtDataBufferSize = kTxtDataMaxSize + mVendorTxtData.GetLength(); + vendorDataLength = Get().GetVendorData().GetLength(); + txtDataBufferSize = kTxtDataMaxSize + vendorDataLength; txtDataBuffer = reinterpret_cast(Heap::CAlloc(txtDataBufferSize, sizeof(uint8_t))); OT_ASSERT(txtDataBuffer != nullptr); SuccessOrAssert(Get().Prepare(txtDataBuffer, txtDataBufferSize, txtDataLength)); - if (mVendorTxtData.GetLength() != 0) + if (vendorDataLength != 0) { - mVendorTxtData.CopyBytesTo(txtDataBuffer + txtDataLength); - txtDataLength += mVendorTxtData.GetLength(); + Get().GetVendorData().CopyBytesTo(txtDataBuffer + txtDataLength); + txtDataLength += vendorDataLength; } service.Clear(); @@ -553,16 +507,16 @@ void EphemeralKeyManager::SetEnabled(bool aEnabled) { VerifyOrExit(mState == kStateDisabled); SetState(kStateStopped); - Get().PostServiceTask(); } else { VerifyOrExit(mState != kStateDisabled); Stop(); SetState(kStateDisabled); - Get().PostServiceTask(); } + Get().Refresh(); + exit: return; } diff --git a/src/core/meshcop/border_agent.hpp b/src/core/meshcop/border_agent.hpp index adce91d75..4f03e4bf5 100644 --- a/src/core/meshcop/border_agent.hpp +++ b/src/core/meshcop/border_agent.hpp @@ -45,13 +45,13 @@ #include "common/appender.hpp" #include "common/as_core_type.hpp" #include "common/heap_allocatable.hpp" -#include "common/heap_data.hpp" #include "common/linked_list.hpp" #include "common/locator.hpp" #include "common/non_copyable.hpp" #include "common/notifier.hpp" #include "common/owned_ptr.hpp" #include "common/tasklet.hpp" +#include "meshcop/border_agent_txt_data.hpp" #include "meshcop/dataset.hpp" #include "meshcop/secure_transport.hpp" #include "net/dns_types.hpp" @@ -102,9 +102,6 @@ struct Id : public otBorderAgentId, public Clearable, public Equatable class Manager : public InstanceLocator, private NonCopyable { -#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE - friend class ot::BorderRouter::RoutingManager; -#endif #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE friend ot::Dnssd; #endif @@ -113,13 +110,13 @@ class Manager : public InstanceLocator, private NonCopyable #endif friend class ot::Notifier; friend class Tmf::Agent; + friend class TxtData; class CoapDtlsSession; public: - typedef otBorderAgentCounters Counters; ///< Border Agent Counters. - typedef otBorderAgentSessionInfo SessionInfo; ///< A session info. - typedef otBorderAgentMeshCoPServiceChangedCallback ServiceChangedCallback; ///< Service changed callback. + typedef otBorderAgentCounters Counters; ///< Border Agent Counters. + typedef otBorderAgentSessionInfo SessionInfo; ///< A session info. /** * Represents an iterator for secure sessions. @@ -223,21 +220,6 @@ public: */ uint16_t GetUdpPort(void) const; - /** - * Sets the callback function used by the Border Agent to notify any changes on the MeshCoP service TXT values. - * - * The callback is invoked when the state of MeshCoP service TXT values changes. For example, it is - * invoked when the network name or the extended PAN ID changes and pass the updated encoded TXT data to the - * application layer. - * - * This callback is invoked once right after this API is called to provide initial states of the MeshCoP - * service to the application. - * - * @param[in] aCallback The callback to invoke when there are any changes of the MeshCoP service. - * @param[in] aContext A pointer to application-specific context. - */ - void SetServiceChangedCallback(ServiceChangedCallback aCallback, void *aContext); - #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE /** * Sets the base name to construct the service instance name used when advertising the mDNS `_meshcop._udp` service @@ -249,27 +231,6 @@ public: * @retval kErrorInvalidArgs The name is too long or invalid. */ Error SetServiceBaseName(const char *aBaseName); - - /** - * Sets the vendor extra TXT data to be included when the Border Agent advertises the mDNS `_meshcop._udp` service. - * - * The provided @p aVendorData bytes are appended as they appear in the buffer to the end of the TXT data generated - * by the Border Agent itself, and are then included in the advertised mDNS `_meshcop._udp` service. - * - * This method itself does not perform any validation of the format of the provided @p aVendorData. Therefore, the - * caller MUST ensure it is formatted properly. Per the Thread specification, vendor-specific Key-Value TXT data - * pairs use TXT keys starting with 'v'. For example, `vn` for vendor name. - * - * The `BorderAgent` will create and retain its own copy of the bytes in @p aVendorData. So, the buffer passed to - * this method does not need to persist beyond the scope of the call. - * - * The vendor TXT data can be set at any time while the Border Agent is in any state. If there is a change from the - * previously set value, it will trigger an update of the registered mDNS service to advertise the new TXT data. - * - * @param[in] aVendorData A pointer to the buffer containing the vendor TXT data. - * @param[in] aVendorDataLength The length of @p aVendorData in bytes. - */ - void SetVendorTxtData(const uint8_t *aVendorData, uint16_t aVendorDataLength); #endif /** @@ -359,6 +320,8 @@ private: void UpdateState(void); void Start(void); void Stop(void); + + // Callback from Notifier void HandleNotifierEvents(Events aEvents); template void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); @@ -373,24 +336,20 @@ private: void HandleSessionDisconnected(CoapDtlsSession &aSession, CoapDtlsSession::ConnectEvent aEvent); void HandleCommissionerPetitionAccepted(CoapDtlsSession &aSession); - void PostServiceTask(void); - void HandleServiceTask(void); -#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE - // Callback from `RoutingManager` - void HandleFavoredOmrPrefixChanged(void) { PostServiceTask(); } -#endif - #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE + // Callback from `BorderAgent::TxtData`. + void HandleServiceTxtDataChanged(void) { RegisterService(); } + + // Callback from `Dnssd` + void HandleDnssdPlatformStateChange(void) { RegisterService(); } + const char *GetServiceName(void); bool IsServiceNameEmpty(void) const { return mServiceName[0] == kNullChar; } void ConstrcutServiceName(const char *aBaseName, Dns::Name::LabelBuffer &aNameBuffer); void RegisterService(void); void UnregisterService(void); - void HandleDnssdPlatformStateChange(void) { PostServiceTask(); } #endif - using ServiceTask = TaskletIn; - #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE static const char kServiceType[]; static const char kDefaultBaseServiceName[]; @@ -403,11 +362,8 @@ private: Id mId; bool mIdInitialized; #endif - Callback mServiceChangedCallback; - ServiceTask mServiceTask; #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE Dns::Name::LabelBuffer mServiceName; - Heap::Data mVendorTxtData; #endif Counters mCounters; }; diff --git a/src/core/meshcop/border_agent_txt_data.cpp b/src/core/meshcop/border_agent_txt_data.cpp index 8a9047bff..9ae6824d6 100644 --- a/src/core/meshcop/border_agent_txt_data.cpp +++ b/src/core/meshcop/border_agent_txt_data.cpp @@ -64,6 +64,9 @@ const char TxtData::Key::kModelName[] = "mn"; TxtData::TxtData(Instance &aInstance) : InstanceLocator(aInstance) +#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE + , mChangedTask(aInstance) +#endif { } @@ -160,6 +163,50 @@ Error TxtData::Prepare(ServiceTxtData &aTxtData) return Prepare(aTxtData.mData, sizeof(aTxtData.mData), aTxtData.mLength); } +void TxtData::SetChangedCallback(ChangedCallback aCallback, void *aContext) +{ + mChangedCallback.Set(aCallback, aContext); + Refresh(); +} + +void TxtData::HandleNotifierEvents(Events aEvents) +{ + if (aEvents.ContainsAny(kEventThreadRoleChanged | kEventThreadExtPanIdChanged | kEventThreadNetworkNameChanged | + kEventThreadBackboneRouterStateChanged | kEventActiveDatasetChanged)) + { + Refresh(); + } +} + +void TxtData::HandleChangedTask(void) +{ + VerifyOrExit(Get().IsEnabled()); + +#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE + Get().HandleServiceTxtDataChanged(); +#endif + + mChangedCallback.InvokeIfSet(); + +exit: + return; +} + +#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE + +void TxtData::SetVendorData(const uint8_t *aVendorData, uint16_t aVendorDataLength) +{ + VerifyOrExit(!mVendorData.Matches(aVendorData, aVendorDataLength)); + + SuccessOrAssert(mVendorData.SetFrom(aVendorData, aVendorDataLength)); + Refresh(); + +exit: + return; +} + +#endif + uint32_t TxtData::StateBitmap::Determine(Instance &aInstance) { uint32_t bitmap = 0; @@ -206,6 +253,8 @@ uint32_t TxtData::StateBitmap::Determine(Instance &aInstance) #endif // OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE +//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + #if OPENTHREAD_CONFIG_BORDER_AGENT_TXT_DATA_PARSER_ENABLE Error TxtData::Info::ParseFrom(const uint8_t *aTxtData, uint16_t aTxtDataLength) diff --git a/src/core/meshcop/border_agent_txt_data.hpp b/src/core/meshcop/border_agent_txt_data.hpp index 76e63303f..e08f75c09 100644 --- a/src/core/meshcop/border_agent_txt_data.hpp +++ b/src/core/meshcop/border_agent_txt_data.hpp @@ -40,10 +40,14 @@ #include #include "common/as_core_type.hpp" +#include "common/callback.hpp" #include "common/clearable.hpp" #include "common/encoding.hpp" #include "common/error.hpp" +#include "common/heap_data.hpp" #include "common/locator.hpp" +#include "common/notifier.hpp" +#include "common/tasklet.hpp" #include "common/type_traits.hpp" #include "net/dns_types.hpp" #include "net/ip6_address.hpp" @@ -56,6 +60,8 @@ namespace BorderAgent { class TxtData : public InstanceLocator { + friend class ot::Notifier; + public: typedef otBorderAgentConnMode ConnMode; ///< Connection Mode in a Border Agent State Bitmap. typedef otBorderAgentThreadIfState IfState; ///< Thread Interface State in a Border Agent State Bitmap. @@ -147,7 +153,8 @@ public: #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE - typedef otBorderAgentMeshCoPServiceTxtData ServiceTxtData; ///< Service TXT Data. + typedef otBorderAgentMeshCoPServiceTxtData ServiceTxtData; ///< Service TXT Data. + typedef otBorderAgentMeshCoPServiceChangedCallback ChangedCallback; ///< Service TXT Data changed callback. /** * Prepares the MeshCoP service TXT data. @@ -171,6 +178,60 @@ public: */ Error Prepare(ServiceTxtData &aTxtData); + /** + * Sets the callback function used to notify any changes on the MeshCoP service TXT Data. + * + * The callback is invoked when the state of MeshCoP service TXT values changes. For example, it is + * invoked when the network name or the extended PAN ID changes. + * + * This callback is invoked once right after this API is called to provide initial states of the MeshCoP + * service to the application. + * + * @param[in] aCallback The callback to invoke when there are any changes of the MeshCoP service. + * @param[in] aContext A pointer to application-specific context. + */ + void SetChangedCallback(ChangedCallback aCallback, void *aContext); + + /** + * Requests a refresh of the MeshCoP service TXT data. + * + * This method is used to notify the `TxtData` module that a network parameter impacting one of the MeshCoP service + * TXT data entries has changed. For example, `RoutingManager` uses this method when the favored OMR prefix is + * changed. + */ + void Refresh(void) { mChangedTask.Post(); } + +#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE + /** + * Returns the vendor TXT data. + * + * @returns The vendor TXT data. + */ + const Heap::Data &GetVendorData(void) const { return mVendorData; } + + /** + * Sets the vendor extra TXT data to be included when the Border Agent advertises the mDNS `_meshcop._udp` service. + * + * The provided @p aVendorData bytes are appended as they appear in the buffer to the end of the TXT data generated + * by the Border Agent itself, and are then included in the advertised mDNS `_meshcop._udp` service. + * + * This method itself does not perform any validation of the format of the provided @p aVendorData. Therefore, the + * caller MUST ensure it is formatted properly. Per the Thread specification, vendor-specific Key-Value TXT data + * pairs use TXT keys starting with 'v'. For example, `vn` for vendor name. + * + * The `BorderAgent` will create and retain its own copy of the bytes in @p aVendorData. So, the buffer passed to + * this method does not need to persist beyond the scope of the call. + * + * The vendor TXT data can be set at any time while the Border Agent is in any state. If there is a change from the + * previously set value, it will trigger an update of the registered mDNS service to advertise the new TXT data. + * + * @param[in] aVendorData A pointer to the buffer containing the vendor TXT data. + * @param[in] aVendorDataLength The length of @p aVendorData in bytes. + */ + void SetVendorData(const uint8_t *aVendorData, uint16_t aVendorDataLength); + +#endif // OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE + #endif // OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE private: @@ -243,6 +304,21 @@ private: static uint32_t Determine(Instance &aInstance); #endif }; + +#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE + // Callback from Notifier + void HandleNotifierEvents(Events aEvents); + + void HandleChangedTask(void); + + using ChangedTask = TaskletIn; + + Callback mChangedCallback; + ChangedTask mChangedTask; +#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE + Heap::Data mVendorData; +#endif +#endif }; #endif // OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE || OPENTHREAD_CONFIG_BORDER_AGENT_TXT_DATA_PARSER_ENABLE diff --git a/tests/nexus/test_border_agent.cpp b/tests/nexus/test_border_agent.cpp index 5b02f2f8d..b5458d1d2 100644 --- a/tests/nexus/test_border_agent.cpp +++ b/tests/nexus/test_border_agent.cpp @@ -1403,7 +1403,7 @@ void TestBorderAgentTxtDataCallback(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Set MeshCoP service change callback. Will get initial values. Log("Set MeshCoP service change callback and check initial values"); - node0.Get().SetServiceChangedCallback(HandleServiceChanged, &callbackInvoked); + node0.Get().SetChangedCallback(HandleServiceChanged, &callbackInvoked); nexus.AdvanceTime(1); // Check the initial TXT entries @@ -1904,7 +1904,7 @@ void TestBorderAgentServiceRegistration(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Set vendor TXT data and validate that it is included in the registered mDNS service"); - node0.Get().SetVendorTxtData(kVendorTxtData, sizeof(kVendorTxtData)); + node0.Get().SetVendorData(kVendorTxtData, sizeof(kVendorTxtData)); nexus.AdvanceTime(5 * Time::kOneSecondInMsec); iterator = node0.Get().AllocateIterator(); @@ -1942,7 +1942,7 @@ void TestBorderAgentServiceRegistration(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Clear vendor TXT data and validate that the registered mDNS service is updated accordingly"); - node0.Get().SetVendorTxtData(nullptr, 0); + node0.Get().SetVendorData(nullptr, 0); nexus.AdvanceTime(5 * Time::kOneSecondInMsec); iterator = node0.Get().AllocateIterator(); diff --git a/tests/unit/test_tasklet.cpp b/tests/unit/test_tasklet.cpp index 7c8ef8c18..06c1b71cd 100644 --- a/tests/unit/test_tasklet.cpp +++ b/tests/unit/test_tasklet.cpp @@ -106,14 +106,19 @@ void TestTasklet(void) sInstance = static_cast(testInitInstance()); VerifyOrQuit(sInstance != nullptr); - sInstance->Get().ProcessQueuedTasklets(); - { Tasklet::Scheduler &scheduler = sInstance->Get(); Tasklet task1(*sInstance, HandleTask1); Tasklet task2(*sInstance, HandleTask2); Tasklet task3(*sInstance, HandleTask3); + Log("Process all initially posted tasks after `Instance` initialization"); + + while (scheduler.AreTaskletsPending()) + { + scheduler.ProcessQueuedTasklets(); + } + VerifyOrQuit(!task1.IsPosted()); VerifyOrQuit(!task2.IsPosted()); VerifyOrQuit(!task3.IsPosted());