mirror of
https://github.com/espressif/openthread.git
synced 2026-09-18 15:10:12 +00:00
[border-agent] use Notifier to update the state (#4788)
This commit is contained in:
committed by
Jonathan Hui
parent
a6adf0322a
commit
92796224b8
@@ -350,6 +350,7 @@ BorderAgent::BorderAgent(Instance &aInstance)
|
||||
, mUdpReceiver(BorderAgent::HandleUdpReceive, this)
|
||||
, mTimer(aInstance, HandleTimeout, this)
|
||||
, mState(OT_BORDER_AGENT_STATE_STOPPED)
|
||||
, mNotifierCallback(aInstance, &BorderAgent::HandleStateChanged, this)
|
||||
{
|
||||
mCommissionerAloc.Clear();
|
||||
mCommissionerAloc.mPrefixLength = 64;
|
||||
@@ -359,6 +360,28 @@ BorderAgent::BorderAgent(Instance &aInstance)
|
||||
mCommissionerAloc.mScopeOverrideValid = true;
|
||||
}
|
||||
|
||||
void BorderAgent::HandleStateChanged(Notifier::Callback &aCallback, otChangedFlags aFlags)
|
||||
{
|
||||
aCallback.GetOwner<BorderAgent>().HandleStateChanged(aFlags);
|
||||
}
|
||||
|
||||
void BorderAgent::HandleStateChanged(otChangedFlags aFlags)
|
||||
{
|
||||
VerifyOrExit((aFlags & OT_CHANGED_THREAD_ROLE) != 0);
|
||||
|
||||
if (Get<Mle::MleRouter>().IsAttached())
|
||||
{
|
||||
Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void BorderAgent::HandleProxyTransmit(const Coap::Message &aMessage)
|
||||
{
|
||||
Message * message = NULL;
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
#include "coap/coap.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/notifier.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
|
||||
namespace ot {
|
||||
@@ -63,7 +64,7 @@ public:
|
||||
* This method starts the Border Agent service.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully started the Border Agent service.
|
||||
* @retval OT_ERROR_ALREADY Already started.
|
||||
* @retval OT_ERROR_ALREADY Border Agent is already started.
|
||||
*
|
||||
*/
|
||||
otError Start(void);
|
||||
@@ -71,7 +72,8 @@ public:
|
||||
/**
|
||||
* This method stops the Border Agent service.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully stopped the Border Agent service.
|
||||
* @retval OT_ERROR_NONE Successfully stopped the Border Agent service.
|
||||
* @retval OT_ERROR_ALREADY Border Agent is already stopped.
|
||||
*
|
||||
*/
|
||||
otError Stop(void);
|
||||
@@ -85,6 +87,9 @@ public:
|
||||
otBorderAgentState GetState(void) const { return mState; }
|
||||
|
||||
private:
|
||||
static void HandleStateChanged(Notifier::Callback &aCallback, otChangedFlags aFlags);
|
||||
void HandleStateChanged(otChangedFlags aFlags);
|
||||
|
||||
static void HandleConnected(bool aConnected, void *aContext)
|
||||
{
|
||||
static_cast<BorderAgent *>(aContext)->HandleConnected(aConnected);
|
||||
@@ -151,6 +156,8 @@ private:
|
||||
|
||||
TimerMilli mTimer;
|
||||
otBorderAgentState mState;
|
||||
|
||||
Notifier::Callback mNotifierCallback;
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
|
||||
@@ -374,17 +374,6 @@ void Mle::SetRole(DeviceRole aRole)
|
||||
mParent.SetState(Neighbor::kStateInvalid);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
if (IsAttached())
|
||||
{
|
||||
SuccessOrExit(Get<MeshCoP::BorderAgent>().Start());
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(Get<MeshCoP::BorderAgent>().Stop());
|
||||
}
|
||||
#endif
|
||||
|
||||
exit:
|
||||
OT_UNUSED_VARIABLE(oldRole);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user