Skip to content

Commit 05c6234

Browse files
authored
[border-agent] shorten method and variable names (openthread#11456)
This commit updates `BorderAgent` method and variable names to use shorter forms where possible. Specifically, the term `MeshCoP` is removed from many variable and method names, as the `BorderAgent` class itself is already defined within the `MeshCoP` namespace. This commit is purely a style and naming change and contains no modification to the code logic.
1 parent b3c4a7e commit 05c6234

5 files changed

Lines changed: 85 additions & 84 deletions

File tree

src/core/api/border_agent_api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ void otBorderAgentSetMeshCoPServiceChangedCallback(otInstance
8080
otBorderAgentMeshCoPServiceChangedCallback aCallback,
8181
void *aContext)
8282
{
83-
AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().SetMeshCoPServiceChangedCallback(aCallback, aContext);
83+
AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().SetServiceChangedCallback(aCallback, aContext);
8484
}
8585

8686
otError otBorderAgentGetMeshCoPServiceTxtData(otInstance *aInstance, otBorderAgentMeshCoPServiceTxtData *aTxtData)
8787
{
88-
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().GetMeshCoPServiceTxtData(*aTxtData);
88+
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().PrepareServiceTxtData(*aTxtData);
8989
}
9090

9191
const otBorderAgentCounters *otBorderAgentGetCounters(otInstance *aInstance)

src/core/border_router/routing_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,7 @@ void RoutingManager::OmrPrefixManager::SetFavordPrefix(const OmrPrefix &aOmrPref
26342634
if (oldFavoredPrefix != mFavoredPrefix)
26352635
{
26362636
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
2637-
Get<MeshCoP::BorderAgent>().PostNotifyMeshCoPServiceChangedTask();
2637+
Get<MeshCoP::BorderAgent>().HandleFavoredOmrPrefixChanged();
26382638
#endif
26392639
LogInfo("Favored OMR prefix: %s -> %s", FavoredToString(oldFavoredPrefix).AsCString(),
26402640
FavoredToString(mFavoredPrefix).AsCString());

src/core/meshcop/border_agent.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ BorderAgent::BorderAgent(Instance &aInstance)
5252
#if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE
5353
, mIdInitialized(false)
5454
#endif
55-
, mNotifyMeshCoPServiceChangedTask(aInstance)
55+
, mServiceTask(aInstance)
5656
#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE
5757
, mEphemeralKeyManager(aInstance)
5858
#endif
@@ -115,7 +115,7 @@ void BorderAgent::Start(void)
115115
pskc.Clear();
116116

117117
mIsRunning = true;
118-
PostNotifyMeshCoPServiceChangedTask();
118+
PostServiceTask();
119119

120120
LogInfo("Border Agent start listening on port %u", GetUdpPort());
121121

@@ -134,7 +134,7 @@ void BorderAgent::Stop(void)
134134

135135
mDtlsTransport.Close();
136136
mIsRunning = false;
137-
PostNotifyMeshCoPServiceChangedTask();
137+
PostServiceTask();
138138

139139
LogInfo("Border Agent stopped");
140140

@@ -144,18 +144,18 @@ void BorderAgent::Stop(void)
144144

145145
uint16_t BorderAgent::GetUdpPort(void) const { return mDtlsTransport.GetUdpPort(); }
146146

147-
void BorderAgent::SetMeshCoPServiceChangedCallback(MeshCoPServiceChangedCallback aCallback, void *aContext)
147+
void BorderAgent::SetServiceChangedCallback(ServiceChangedCallback aCallback, void *aContext)
148148
{
149-
mMeshCoPServiceChangedCallback.Set(aCallback, aContext);
149+
mServiceChangedCallback.Set(aCallback, aContext);
150150

151-
mNotifyMeshCoPServiceChangedTask.Post();
151+
PostServiceTask();
152152
}
153153

154-
Error BorderAgent::GetMeshCoPServiceTxtData(MeshCoPServiceTxtData &aTxtData) const
154+
Error BorderAgent::PrepareServiceTxtData(ServiceTxtData &aTxtData) const
155155
{
156-
MeshCoPTxtEncoder meshCoPTxtEncoder(GetInstance(), aTxtData);
156+
TxtEncoder encoder(GetInstance(), aTxtData);
157157

158-
return meshCoPTxtEncoder.EncodeTxtData();
158+
return encoder.EncodeTxtData();
159159
}
160160

161161
void BorderAgent::HandleNotifierEvents(Events aEvents)
@@ -175,7 +175,7 @@ void BorderAgent::HandleNotifierEvents(Events aEvents)
175175
if (aEvents.ContainsAny(kEventThreadRoleChanged | kEventThreadExtPanIdChanged | kEventThreadNetworkNameChanged |
176176
kEventThreadBackboneRouterStateChanged | kEventActiveDatasetChanged))
177177
{
178-
PostNotifyMeshCoPServiceChangedTask();
178+
PostServiceTask();
179179
}
180180

181181
if (aEvents.ContainsAny(kEventPskcChanged))
@@ -347,33 +347,33 @@ template <> void BorderAgent::HandleTmf<kUriRelayRx>(Coap::Message &aMessage, co
347347
FreeMessageOnError(message, error);
348348
}
349349

350-
void BorderAgent::NotifyMeshCoPServiceChanged(void) { mMeshCoPServiceChangedCallback.InvokeIfSet(); }
350+
void BorderAgent::HandleServiceTask(void) { mServiceChangedCallback.InvokeIfSet(); }
351351

352-
void BorderAgent::PostNotifyMeshCoPServiceChangedTask(void)
352+
void BorderAgent::PostServiceTask(void)
353353
{
354-
if (mMeshCoPServiceChangedCallback.IsSet())
354+
if (mServiceChangedCallback.IsSet())
355355
{
356-
mNotifyMeshCoPServiceChangedTask.Post();
356+
mServiceTask.Post();
357357
}
358358
}
359359

360360
//----------------------------------------------------------------------------------------------------------------------
361-
// BorderAgent::MeshCoPTxtEncoder
361+
// BorderAgent::TxtEncoder
362362

363-
Error BorderAgent::MeshCoPTxtEncoder::AppendTxtEntry(const char *aKey, const void *aValue, uint16_t aValueLength)
363+
Error BorderAgent::TxtEncoder::AppendTxtEntry(const char *aKey, const void *aValue, uint16_t aValueLength)
364364
{
365365
Dns::TxtEntry txtEntry;
366366

367367
txtEntry.Init(aKey, reinterpret_cast<const uint8_t *>(aValue), aValueLength);
368368
return txtEntry.AppendTo(mAppender);
369369
}
370370

371-
template <> Error BorderAgent::MeshCoPTxtEncoder::AppendTxtEntry<NameData>(const char *aKey, const NameData &aObject)
371+
template <> Error BorderAgent::TxtEncoder::AppendTxtEntry<NameData>(const char *aKey, const NameData &aObject)
372372
{
373373
return AppendTxtEntry(aKey, aObject.GetBuffer(), aObject.GetLength());
374374
}
375375

376-
Error BorderAgent::MeshCoPTxtEncoder::EncodeTxtData(void)
376+
Error BorderAgent::TxtEncoder::EncodeTxtData(void)
377377
{
378378
Error error = kErrorNone;
379379
#if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE
@@ -418,7 +418,7 @@ Error BorderAgent::MeshCoPTxtEncoder::EncodeTxtData(void)
418418
}
419419

420420
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
421-
Error BorderAgent::MeshCoPTxtEncoder::AppendBbrTxtEntry(StateBitmap aState)
421+
Error BorderAgent::TxtEncoder::AppendBbrTxtEntry(StateBitmap aState)
422422
{
423423
Error error = kErrorNone;
424424
const DomainName &domainName = Get<MeshCoP::NetworkNameManager>().GetDomainName();
@@ -441,7 +441,7 @@ Error BorderAgent::MeshCoPTxtEncoder::AppendBbrTxtEntry(StateBitmap aState)
441441
#endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
442442

443443
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
444-
Error BorderAgent::MeshCoPTxtEncoder::AppendOmrTxtEntry(void)
444+
Error BorderAgent::TxtEncoder::AppendOmrTxtEntry(void)
445445
{
446446
Error error = kErrorNone;
447447
Ip6::Prefix prefix;
@@ -462,7 +462,7 @@ Error BorderAgent::MeshCoPTxtEncoder::AppendOmrTxtEntry(void)
462462
}
463463
#endif
464464

465-
BorderAgent::MeshCoPTxtEncoder::StateBitmap BorderAgent::MeshCoPTxtEncoder::GetStateBitmap(void)
465+
BorderAgent::TxtEncoder::StateBitmap BorderAgent::TxtEncoder::GetStateBitmap(void)
466466
{
467467
StateBitmap state;
468468

@@ -561,14 +561,14 @@ void BorderAgent::EphemeralKeyManager::SetEnabled(bool aEnabled)
561561
{
562562
VerifyOrExit(mState == kStateDisabled);
563563
SetState(kStateStopped);
564-
Get<BorderAgent>().PostNotifyMeshCoPServiceChangedTask();
564+
Get<BorderAgent>().PostServiceTask();
565565
}
566566
else
567567
{
568568
VerifyOrExit(mState != kStateDisabled);
569569
Stop();
570570
SetState(kStateDisabled);
571-
Get<BorderAgent>().PostNotifyMeshCoPServiceChangedTask();
571+
Get<BorderAgent>().PostServiceTask();
572572
}
573573

574574
exit:

src/core/meshcop/border_agent.hpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ class BorderAgent : public InstanceLocator, private NonCopyable
7777
class CoapDtlsSession;
7878

7979
public:
80-
typedef otBorderAgentId Id; ///< Border Agent ID.
81-
typedef otBorderAgentCounters Counters; ///< Border Agent Counters.
82-
typedef otBorderAgentSessionInfo SessionInfo; ///< A session info.
80+
typedef otBorderAgentId Id; ///< Border Agent ID.
81+
typedef otBorderAgentCounters Counters; ///< Border Agent Counters.
82+
typedef otBorderAgentSessionInfo SessionInfo; ///< A session info.
83+
typedef otBorderAgentMeshCoPServiceChangedCallback ServiceChangedCallback; ///< Service changed callback.
84+
typedef otBorderAgentMeshCoPServiceTxtData ServiceTxtData; ///< Service TXT data.
8385

8486
/**
8587
* Represents an iterator for secure sessions.
@@ -163,8 +165,6 @@ class BorderAgent : public InstanceLocator, private NonCopyable
163165
*/
164166
bool IsRunning(void) const { return mIsRunning; }
165167

166-
typedef otBorderAgentMeshCoPServiceChangedCallback MeshCoPServiceChangedCallback;
167-
168168
/**
169169
* Sets the callback function used by the Border Agent to notify any changes on the MeshCoP service TXT values.
170170
*
@@ -178,19 +178,17 @@ class BorderAgent : public InstanceLocator, private NonCopyable
178178
* @param[in] aCallback The callback to invoke when there are any changes of the MeshCoP service.
179179
* @param[in] aContext A pointer to application-specific context.
180180
*/
181-
void SetMeshCoPServiceChangedCallback(MeshCoPServiceChangedCallback aCallback, void *aContext);
182-
183-
typedef otBorderAgentMeshCoPServiceTxtData MeshCoPServiceTxtData;
181+
void SetServiceChangedCallback(ServiceChangedCallback aCallback, void *aContext);
184182

185183
/**
186-
* Gets the MeshCoP service TXT data.
184+
* Prepares the MeshCoP service TXT data.
187185
*
188186
* @param[out] aTxtData A reference to a MeshCoP Service TXT data struct to get the data.
189187
*
190188
* @retval kErrorNone If successfully retrieved the Border Agent MeshCoP Service TXT data.
191189
* @retval kErrorNoBufs If the buffer in @p aTxtData doesn't have enough size.
192190
*/
193-
Error GetMeshCoPServiceTxtData(MeshCoPServiceTxtData &aTxtData) const;
191+
Error PrepareServiceTxtData(ServiceTxtData &aTxtData) const;
194192

195193
#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE
196194
/**
@@ -434,10 +432,10 @@ class BorderAgent : public InstanceLocator, private NonCopyable
434432
uint64_t mAllocationTime;
435433
};
436434

437-
class MeshCoPTxtEncoder : public InstanceLocator
435+
class TxtEncoder : public InstanceLocator
438436
{
439437
public:
440-
MeshCoPTxtEncoder(Instance &aInstance, MeshCoPServiceTxtData &aTxtData)
438+
TxtEncoder(Instance &aInstance, ServiceTxtData &aTxtData)
441439
: InstanceLocator(aInstance)
442440
, mTxtData(aTxtData)
443441
, mAppender(mTxtData.mData, sizeof(mTxtData.mData))
@@ -532,8 +530,8 @@ class BorderAgent : public InstanceLocator, private NonCopyable
532530

533531
StateBitmap GetStateBitmap(void);
534532

535-
MeshCoPServiceTxtData &mTxtData;
536-
Appender mAppender;
533+
ServiceTxtData &mTxtData;
534+
Appender mAppender;
537535
};
538536

539537
void Start(void);
@@ -554,19 +552,23 @@ class BorderAgent : public InstanceLocator, private NonCopyable
554552

555553
static Coap::Message::Code CoapCodeFromError(Error aError);
556554

557-
void PostNotifyMeshCoPServiceChangedTask(void);
558-
void NotifyMeshCoPServiceChanged(void);
555+
void PostServiceTask(void);
556+
void HandleServiceTask(void);
557+
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
558+
// Callback from `RoutingManager`
559+
void HandleFavoredOmrPrefixChanged(void) { PostServiceTask(); }
560+
#endif
559561

560-
using NotifyMeshCoPServiceChangedTask = TaskletIn<BorderAgent, &BorderAgent::NotifyMeshCoPServiceChanged>;
562+
using ServiceTask = TaskletIn<BorderAgent, &BorderAgent::HandleServiceTask>;
561563

562564
bool mIsRunning;
563565
Dtls::Transport mDtlsTransport;
564566
#if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE
565567
Id mId;
566568
bool mIdInitialized;
567569
#endif
568-
Callback<MeshCoPServiceChangedCallback> mMeshCoPServiceChangedCallback;
569-
NotifyMeshCoPServiceChangedTask mNotifyMeshCoPServiceChangedTask;
570+
Callback<ServiceChangedCallback> mServiceChangedCallback;
571+
ServiceTask mServiceTask;
570572
#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE
571573
EphemeralKeyManager mEphemeralKeyManager;
572574
#endif

0 commit comments

Comments
 (0)