mirror of
https://github.com/espressif/openthread.git
synced 2026-08-14 06:37:46 +00:00
[notifier] add Notifier::Receiver (#5052)
This commit adds `Notifier::Receiver` class which is inherited by OpenThread core types/classes to register themselves as a receiver of `Notifier` events. This change helps simplify and replace the previous `Notifier` callback model.
This commit is contained in:
committed by
Jonathan Hui
parent
adb57991e8
commit
f177acfc4a
@@ -40,13 +40,11 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
Notifier::Callback::Callback(Instance &aInstance, Handler aHandler, void *aOwner)
|
||||
: OwnerLocator(aOwner)
|
||||
, mHandler(aHandler)
|
||||
Notifier::Receiver::Receiver(Instance &aInstance, Handler aHandler)
|
||||
: mHandler(aHandler)
|
||||
, mNext(NULL)
|
||||
{
|
||||
OT_ASSERT(aHandler != NULL);
|
||||
aInstance.Get<Notifier>().RegisterCallback(*this);
|
||||
aInstance.Get<Notifier>().RegisterReceiver(*this);
|
||||
}
|
||||
|
||||
Notifier::Notifier(Instance &aInstance)
|
||||
@@ -54,7 +52,7 @@ Notifier::Notifier(Instance &aInstance)
|
||||
, mEventsToSignal()
|
||||
, mSignaledEvents()
|
||||
, mTask(aInstance, &Notifier::EmitEvents, this)
|
||||
, mCallbacks()
|
||||
, mReceivers()
|
||||
{
|
||||
for (unsigned int i = 0; i < kMaxExternalHandlers; i++)
|
||||
{
|
||||
@@ -63,9 +61,9 @@ Notifier::Notifier(Instance &aInstance)
|
||||
}
|
||||
}
|
||||
|
||||
void Notifier::RegisterCallback(Callback &aCallback)
|
||||
void Notifier::RegisterReceiver(Receiver &aReceiver)
|
||||
{
|
||||
mCallbacks.Push(aCallback);
|
||||
mReceivers.Push(aReceiver);
|
||||
}
|
||||
|
||||
otError Notifier::RegisterCallback(otStateChangedCallback aCallback, void *aContext)
|
||||
@@ -154,9 +152,9 @@ void Notifier::EmitEvents(void)
|
||||
|
||||
LogEvents(events);
|
||||
|
||||
for (Callback *callback = mCallbacks.GetHead(); callback != NULL; callback = callback->GetNext())
|
||||
for (Receiver *receiver = mReceivers.GetHead(); receiver != NULL; receiver = receiver->GetNext())
|
||||
{
|
||||
callback->Invoke(events);
|
||||
receiver->Emit(events);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < kMaxExternalHandlers; i++)
|
||||
|
||||
@@ -188,8 +188,8 @@ private:
|
||||
*
|
||||
* Two callback models are provided:
|
||||
*
|
||||
* - A `Notifier::Callback` object that upon initialization (from its constructor) auto-registers itself with
|
||||
* the `Notifier`. This model is mainly used by OpenThread core modules.
|
||||
* - A `Notifier::Receiver` class which should be inherited by OpenThread core types to register themselves as a
|
||||
* receiver of `Notifier` events.
|
||||
*
|
||||
* - A `otStateChangedCallback` callback handler which needs to be explicitly registered with the `Notifier`. This is
|
||||
* commonly used by external users (provided as an OpenThread public API). Max number of such callbacks that can be
|
||||
@@ -200,39 +200,38 @@ class Notifier : public InstanceLocator, private NonCopyable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This class defines a `Notifier` callback instance.
|
||||
* This class defines a `Notifier::Receiver` instance.
|
||||
*
|
||||
*/
|
||||
class Callback : public OwnerLocator, public LinkedListEntry<Callback>
|
||||
class Receiver : public LinkedListEntry<Receiver>
|
||||
{
|
||||
friend class Notifier;
|
||||
friend class LinkedListEntry<Callback>;
|
||||
friend class LinkedListEntry<Receiver>;
|
||||
|
||||
public:
|
||||
/**
|
||||
* This type defines the function pointer which is called to notify of events (state/configuration changes)..
|
||||
* This type defines the function reference which is invoked to notify of events (state/configuration changes)..
|
||||
*
|
||||
* @param[in] aCallback A reference to callback instance.
|
||||
* @param[in] aReceiver A reference to `Receiver` instance.
|
||||
* @param[in] aEvents The list of events.
|
||||
*
|
||||
*/
|
||||
typedef void (*Handler)(Callback &aCallback, Events aEvents);
|
||||
typedef void (&Handler)(Receiver &aReceiver, Events aEvents);
|
||||
|
||||
/**
|
||||
* This constructor initializes a `Callback` instance and registers it with `Notifier`.
|
||||
* This constructor initializes a `Receiver` instance and registers it with `Notifier`.
|
||||
*
|
||||
* @param[in] aInstance A reference to OpenThread instance.
|
||||
* @param[in] aHandler A function pointer to the callback handler.
|
||||
* @param[in] aOwner A pointer to the owner of the `Callback` instance.
|
||||
* @param[in] aHandler The handler function reference.
|
||||
*
|
||||
*/
|
||||
Callback(Instance &aInstance, Handler aHandler, void *aOwner);
|
||||
Receiver(Instance &aInstance, Handler aHandler);
|
||||
|
||||
private:
|
||||
void Invoke(const Events aEvents) { mHandler(*this, aEvents); }
|
||||
void Emit(Events aEvents) { mHandler(*this, aEvents); }
|
||||
|
||||
Handler mHandler;
|
||||
Callback *mNext;
|
||||
Receiver *mNext;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -349,7 +348,7 @@ private:
|
||||
void * mContext;
|
||||
};
|
||||
|
||||
void RegisterCallback(Callback &aCallback);
|
||||
void RegisterReceiver(Receiver &aReceiver);
|
||||
static void EmitEvents(Tasklet &aTasklet);
|
||||
void EmitEvents(void);
|
||||
|
||||
@@ -359,7 +358,7 @@ private:
|
||||
Events mEventsToSignal;
|
||||
Events mSignaledEvents;
|
||||
Tasklet mTask;
|
||||
LinkedList<Callback> mCallbacks;
|
||||
LinkedList<Receiver> mReceivers;
|
||||
ExternalCallback mExternalCallbacks[kMaxExternalHandlers];
|
||||
};
|
||||
|
||||
|
||||
@@ -333,6 +333,7 @@ void BorderAgent::HandleRequest<&BorderAgent::mProxyTransmit>(void *
|
||||
|
||||
BorderAgent::BorderAgent(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, Notifier::Receiver(aInstance, BorderAgent::HandleNotifierEvents)
|
||||
, mCommissionerPetition(OT_URI_PATH_COMMISSIONER_PETITION,
|
||||
BorderAgent::HandleRequest<&BorderAgent::mCommissionerPetition>,
|
||||
this)
|
||||
@@ -351,7 +352,6 @@ BorderAgent::BorderAgent(Instance &aInstance)
|
||||
, mUdpReceiver(BorderAgent::HandleUdpReceive, this)
|
||||
, mTimer(aInstance, HandleTimeout, this)
|
||||
, mState(OT_BORDER_AGENT_STATE_STOPPED)
|
||||
, mNotifierCallback(aInstance, &BorderAgent::HandleNotifierEvents, this)
|
||||
{
|
||||
mCommissionerAloc.Clear();
|
||||
mCommissionerAloc.mPrefixLength = 64;
|
||||
@@ -361,9 +361,9 @@ BorderAgent::BorderAgent(Instance &aInstance)
|
||||
mCommissionerAloc.mScopeOverrideValid = true;
|
||||
}
|
||||
|
||||
void BorderAgent::HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents)
|
||||
void BorderAgent::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<BorderAgent>().HandleNotifierEvents(aEvents);
|
||||
static_cast<BorderAgent &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void BorderAgent::HandleNotifierEvents(Events aEvents)
|
||||
|
||||
@@ -49,7 +49,7 @@ class ThreadNetif;
|
||||
|
||||
namespace MeshCoP {
|
||||
|
||||
class BorderAgent : public InstanceLocator
|
||||
class BorderAgent : public InstanceLocator, public Notifier::Receiver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
void ApplyMeshLocalPrefix(void);
|
||||
|
||||
private:
|
||||
static void HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents);
|
||||
void HandleNotifierEvents(Events aEvents);
|
||||
|
||||
static void HandleConnected(bool aConnected, void *aContext)
|
||||
@@ -162,8 +162,6 @@ private:
|
||||
|
||||
TimerMilli mTimer;
|
||||
otBorderAgentState mState;
|
||||
|
||||
Notifier::Callback mNotifierCallback;
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
|
||||
@@ -55,10 +55,10 @@ namespace MeshCoP {
|
||||
|
||||
JoinerRouter::JoinerRouter(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, Notifier::Receiver(aInstance, JoinerRouter::HandleNotifierEvents)
|
||||
, mSocket(aInstance.Get<Ip6::Udp>())
|
||||
, mRelayTransmit(OT_URI_PATH_RELAY_TX, &JoinerRouter::HandleRelayTransmit, this)
|
||||
, mTimer(aInstance, JoinerRouter::HandleTimer, this)
|
||||
, mNotifierCallback(aInstance, &JoinerRouter::HandleNotifierEvents, this)
|
||||
, mJoinerUdpPort(0)
|
||||
, mIsJoinerPortConfigured(false)
|
||||
, mExpectJoinEntRsp(false)
|
||||
@@ -66,9 +66,9 @@ JoinerRouter::JoinerRouter(Instance &aInstance)
|
||||
Get<Coap::Coap>().AddResource(mRelayTransmit);
|
||||
}
|
||||
|
||||
void JoinerRouter::HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents)
|
||||
void JoinerRouter::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<JoinerRouter>().HandleNotifierEvents(aEvents);
|
||||
static_cast<JoinerRouter &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void JoinerRouter::HandleNotifierEvents(Events aEvents)
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace ot {
|
||||
|
||||
namespace MeshCoP {
|
||||
|
||||
class JoinerRouter : public InstanceLocator
|
||||
class JoinerRouter : public InstanceLocator, public Notifier::Receiver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ private:
|
||||
Kek mKek; // KEK used by MAC layer to encode this message.
|
||||
};
|
||||
|
||||
static void HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents);
|
||||
void HandleNotifierEvents(Events aEvents);
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||
@@ -124,8 +124,6 @@ private:
|
||||
TimerMilli mTimer;
|
||||
MessageQueue mDelayedJoinEnts;
|
||||
|
||||
Notifier::Callback mNotifierCallback;
|
||||
|
||||
uint16_t mJoinerUdpPort;
|
||||
|
||||
bool mIsJoinerPortConfigured : 1;
|
||||
|
||||
@@ -112,7 +112,7 @@ exit:
|
||||
|
||||
AnnounceSender::AnnounceSender(Instance &aInstance)
|
||||
: AnnounceSenderBase(aInstance, AnnounceSender::HandleTimer)
|
||||
, mNotifierCallback(aInstance, HandleNotifierEvents, this)
|
||||
, Notifier::Receiver(aInstance, AnnounceSender::HandleNotifierEvents)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -175,9 +175,9 @@ void AnnounceSender::Stop(void)
|
||||
otLogInfoMle("Stopping periodic MLE Announcements tx");
|
||||
}
|
||||
|
||||
void AnnounceSender::HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents)
|
||||
void AnnounceSender::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<AnnounceSender>().HandleNotifierEvents(aEvents);
|
||||
static_cast<AnnounceSender &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void AnnounceSender::HandleNotifierEvents(Events aEvents)
|
||||
|
||||
@@ -134,7 +134,7 @@ private:
|
||||
* This class implements an AnnounceSender.
|
||||
*
|
||||
*/
|
||||
class AnnounceSender : public AnnounceSenderBase
|
||||
class AnnounceSender : public AnnounceSenderBase, public Notifier::Receiver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -157,10 +157,8 @@ private:
|
||||
void CheckState(void);
|
||||
void Stop(void);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
static void HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents);
|
||||
void HandleNotifierEvents(Events aEvents);
|
||||
|
||||
Notifier::Callback mNotifierCallback;
|
||||
};
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace ot {
|
||||
|
||||
EnergyScanServer::EnergyScanServer(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, Notifier::Receiver(aInstance, EnergyScanServer::HandleNotifierEvents)
|
||||
, mChannelMask(0)
|
||||
, mChannelMaskCurrent(0)
|
||||
, mPeriod(0)
|
||||
@@ -56,7 +57,6 @@ EnergyScanServer::EnergyScanServer(Instance &aInstance)
|
||||
, mActive(false)
|
||||
, mScanResultsLength(0)
|
||||
, mTimer(aInstance, EnergyScanServer::HandleTimer, this)
|
||||
, mNotifierCallback(aInstance, &EnergyScanServer::HandleNotifierEvents, this)
|
||||
, mEnergyScan(OT_URI_PATH_ENERGY_SCAN, &EnergyScanServer::HandleRequest, this)
|
||||
{
|
||||
Get<Coap::Coap>().AddResource(mEnergyScan);
|
||||
@@ -212,9 +212,9 @@ exit:
|
||||
mActive = false;
|
||||
}
|
||||
|
||||
void EnergyScanServer::HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents)
|
||||
void EnergyScanServer::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<EnergyScanServer>().HandleNotifierEvents(aEvents);
|
||||
static_cast<EnergyScanServer &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void EnergyScanServer::HandleNotifierEvents(Events aEvents)
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace ot {
|
||||
* This class implements handling Energy Scan Requests.
|
||||
*
|
||||
*/
|
||||
class EnergyScanServer : public InstanceLocator
|
||||
class EnergyScanServer : public InstanceLocator, public Notifier::Receiver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
static void HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents);
|
||||
void HandleNotifierEvents(Events aEvents);
|
||||
|
||||
void SendReport(void);
|
||||
@@ -93,8 +93,6 @@ private:
|
||||
|
||||
TimerMilli mTimer;
|
||||
|
||||
Notifier::Callback mNotifierCallback;
|
||||
|
||||
Coap::Resource mEnergyScan;
|
||||
};
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ namespace Mle {
|
||||
|
||||
Mle::Mle(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, Notifier::Receiver(aInstance, Mle::HandleNotifierEvents)
|
||||
, mRetrieveNewNetworkData(false)
|
||||
, mRole(kRoleDisabled)
|
||||
, mDeviceMode(DeviceMode::kModeRxOnWhenIdle | DeviceMode::kModeSecureDataRequest)
|
||||
@@ -108,7 +109,6 @@ Mle::Mle(Instance &aInstance)
|
||||
, mAlternateChannel(0)
|
||||
, mAlternatePanId(Mac::kPanIdBroadcast)
|
||||
, mAlternateTimestamp(0)
|
||||
, mNotifierCallback(aInstance, &Mle::HandleNotifierEvents, this)
|
||||
, mParentResponseCb(NULL)
|
||||
, mParentResponseCbContext(NULL)
|
||||
{
|
||||
@@ -1486,9 +1486,9 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Mle::HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents)
|
||||
void Mle::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<Mle>().HandleNotifierEvents(aEvents);
|
||||
static_cast<Mle &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void Mle::HandleNotifierEvents(Events aEvents)
|
||||
|
||||
@@ -305,7 +305,7 @@ private:
|
||||
* This class implements MLE functionality required by the Thread EndDevices, Router, and Leader roles.
|
||||
*
|
||||
*/
|
||||
class Mle : public InstanceLocator
|
||||
class Mle : public InstanceLocator, public Notifier::Receiver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -1696,7 +1696,7 @@ private:
|
||||
TimeMilli mSendTime; // Time when the message shall be sent.
|
||||
};
|
||||
|
||||
static void HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents);
|
||||
void HandleNotifierEvents(Events aEvents);
|
||||
static void HandleAttachTimer(Timer &aTimer);
|
||||
void HandleAttachTimer(void);
|
||||
@@ -1823,8 +1823,6 @@ private:
|
||||
Ip6::NetifMulticastAddress mLinkLocalAllThreadNodes;
|
||||
Ip6::NetifMulticastAddress mRealmLocalAllThreadNodes;
|
||||
|
||||
Notifier::Callback mNotifierCallback;
|
||||
|
||||
otThreadParentResponseCallback mParentResponseCb;
|
||||
void * mParentResponseCbContext;
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace NetworkData {
|
||||
|
||||
Notifier::Notifier(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, mNotifierCallback(aInstance, &Notifier::HandleNotifierEvents, this)
|
||||
, ot::Notifier::Receiver(aInstance, Notifier::HandleNotifierEvents)
|
||||
, mTimer(aInstance, Notifier::HandleTimer, this)
|
||||
, mNextDelay(0)
|
||||
, mWaitingForResponse(false)
|
||||
@@ -101,9 +101,9 @@ exit:
|
||||
}
|
||||
}
|
||||
|
||||
void Notifier::HandleNotifierEvents(ot::Notifier::Callback &aCallback, Events aEvents)
|
||||
void Notifier::HandleNotifierEvents(ot::Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<Notifier>().HandleNotifierEvents(aEvents);
|
||||
static_cast<Notifier &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void Notifier::HandleNotifierEvents(Events aEvents)
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace NetworkData {
|
||||
* This class implements the SVR_DATA.ntf transmission logic.
|
||||
*
|
||||
*/
|
||||
class Notifier : public InstanceLocator
|
||||
class Notifier : public InstanceLocator, public ot::Notifier::Receiver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -74,7 +74,7 @@ private:
|
||||
kDelaySynchronizeServerData = 300000, ///< milliseconds
|
||||
};
|
||||
|
||||
static void HandleNotifierEvents(ot::Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(ot::Notifier::Receiver &aReceiver, Events aEvents);
|
||||
void HandleNotifierEvents(Events aEvents);
|
||||
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
@@ -88,10 +88,9 @@ private:
|
||||
|
||||
void SynchronizeServerData(void);
|
||||
|
||||
ot::Notifier::Callback mNotifierCallback;
|
||||
TimerMilli mTimer;
|
||||
uint32_t mNextDelay;
|
||||
bool mWaitingForResponse;
|
||||
TimerMilli mTimer;
|
||||
uint32_t mNextDelay;
|
||||
bool mWaitingForResponse;
|
||||
};
|
||||
|
||||
} // namespace NetworkData
|
||||
|
||||
@@ -51,6 +51,7 @@ namespace ot {
|
||||
|
||||
TimeSync::TimeSync(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, Notifier::Receiver(aInstance, TimeSync::HandleNotifierEvents)
|
||||
, mTimeSyncRequired(false)
|
||||
, mTimeSyncSeq(OT_TIME_SYNC_INVALID_SEQ)
|
||||
, mTimeSyncPeriod(OPENTHREAD_CONFIG_TIME_SYNC_PERIOD)
|
||||
@@ -62,7 +63,6 @@ TimeSync::TimeSync(Instance &aInstance)
|
||||
, mNetworkTimeOffset(0)
|
||||
, mTimeSyncCallback(NULL)
|
||||
, mTimeSyncCallbackContext(NULL)
|
||||
, mNotifierCallback(aInstance, &TimeSync::HandleNotifierEvents, this)
|
||||
, mTimer(aInstance, HandleTimeout, this)
|
||||
, mCurrentStatus(OT_NETWORK_TIME_UNSYNCHRONIZED)
|
||||
{
|
||||
@@ -209,9 +209,9 @@ void TimeSync::HandleTimeout(void)
|
||||
CheckAndHandleChanges(false);
|
||||
}
|
||||
|
||||
void TimeSync::HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents)
|
||||
void TimeSync::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<TimeSync>().HandleNotifierEvents(aEvents);
|
||||
static_cast<TimeSync &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void TimeSync::HandleTimeout(Timer &aTimer)
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace ot {
|
||||
* This class implements OpenThread Time Synchronization Service.
|
||||
*
|
||||
*/
|
||||
class TimeSync : public InstanceLocator
|
||||
class TimeSync : public InstanceLocator, public Notifier::Receiver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -173,7 +173,7 @@ private:
|
||||
* @param[in] aFlags Flags that denote the state change events.
|
||||
*
|
||||
*/
|
||||
static void HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents);
|
||||
|
||||
/**
|
||||
* Callback to be called when timer expires.
|
||||
@@ -216,7 +216,6 @@ private:
|
||||
otNetworkTimeSyncCallbackFn
|
||||
mTimeSyncCallback; ///< The callback to be called when time sync is handled or status updated.
|
||||
void * mTimeSyncCallbackContext; ///< The context to be passed to callback.
|
||||
Notifier::Callback mNotifierCallback; ///< Callback for thread state changes.
|
||||
TimerMilli mTimer; ///< Timer for checking if a resync is required.
|
||||
otNetworkTimeStatus mCurrentStatus; ///< Current network time status.
|
||||
};
|
||||
|
||||
@@ -48,10 +48,10 @@ namespace Utils {
|
||||
|
||||
ChannelManager::ChannelManager(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, Notifier::Receiver(aInstance, ChannelManager::HandleNotifierEvents)
|
||||
, mSupportedChannelMask(0)
|
||||
, mFavoredChannelMask(0)
|
||||
, mActiveTimestamp(0)
|
||||
, mNotifierCallback(aInstance, &ChannelManager::HandleNotifierEvents, this)
|
||||
, mDelay(kMinimumDelay)
|
||||
, mChannel(0)
|
||||
, mState(kStateIdle)
|
||||
@@ -252,9 +252,9 @@ void ChannelManager::HandleTimer(void)
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelManager::HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents)
|
||||
void ChannelManager::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<ChannelManager>().HandleNotifierEvents(aEvents);
|
||||
static_cast<ChannelManager &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void ChannelManager::HandleNotifierEvents(Events aEvents)
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Utils {
|
||||
* This class implements the Channel Manager.
|
||||
*
|
||||
*/
|
||||
class ChannelManager : public InstanceLocator, private NonCopyable
|
||||
class ChannelManager : public InstanceLocator, public Notifier::Receiver, private NonCopyable
|
||||
{
|
||||
public:
|
||||
enum
|
||||
@@ -272,7 +272,7 @@ private:
|
||||
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
static void HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents);
|
||||
void HandleNotifierEvents(Events aEvents);
|
||||
void PreparePendingDataset(void);
|
||||
void StartAutoSelectTimer(void);
|
||||
@@ -282,16 +282,15 @@ private:
|
||||
bool ShouldAttemptChannelChange(void);
|
||||
#endif
|
||||
|
||||
Mac::ChannelMask mSupportedChannelMask;
|
||||
Mac::ChannelMask mFavoredChannelMask;
|
||||
uint64_t mActiveTimestamp;
|
||||
Notifier::Callback mNotifierCallback;
|
||||
uint16_t mDelay;
|
||||
uint8_t mChannel;
|
||||
State mState;
|
||||
TimerMilli mTimer;
|
||||
uint32_t mAutoSelectInterval;
|
||||
bool mAutoSelectEnabled;
|
||||
Mac::ChannelMask mSupportedChannelMask;
|
||||
Mac::ChannelMask mFavoredChannelMask;
|
||||
uint64_t mActiveTimestamp;
|
||||
uint16_t mDelay;
|
||||
uint8_t mChannel;
|
||||
State mState;
|
||||
TimerMilli mTimer;
|
||||
uint32_t mAutoSelectInterval;
|
||||
bool mAutoSelectEnabled;
|
||||
};
|
||||
|
||||
#else // OPENTHREAD_FTD
|
||||
|
||||
@@ -49,9 +49,9 @@ namespace Utils {
|
||||
|
||||
ChildSupervisor::ChildSupervisor(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, Notifier::Receiver(aInstance, ChildSupervisor::HandleNotifierEvents)
|
||||
, mSupervisionInterval(kDefaultSupervisionInterval)
|
||||
, mTimer(aInstance, ChildSupervisor::HandleTimer, this)
|
||||
, mNotifierCallback(aInstance, &ChildSupervisor::HandleNotifierEvents, this)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -162,9 +162,9 @@ void ChildSupervisor::CheckState(void)
|
||||
}
|
||||
}
|
||||
|
||||
void ChildSupervisor::HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents)
|
||||
void ChildSupervisor::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<ChildSupervisor>().HandleNotifierEvents(aEvents);
|
||||
static_cast<ChildSupervisor &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void ChildSupervisor::HandleNotifierEvents(Events aEvents)
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace Utils {
|
||||
* This class implements a child supervisor.
|
||||
*
|
||||
*/
|
||||
class ChildSupervisor : public InstanceLocator
|
||||
class ChildSupervisor : public InstanceLocator, public Notifier::Receiver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -160,12 +160,11 @@ private:
|
||||
void CheckState(void);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
static void HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents);
|
||||
void HandleNotifierEvents(Events aEvents);
|
||||
|
||||
uint16_t mSupervisionInterval;
|
||||
TimerMilli mTimer;
|
||||
Notifier::Callback mNotifierCallback;
|
||||
uint16_t mSupervisionInterval;
|
||||
TimerMilli mTimer;
|
||||
};
|
||||
|
||||
#else // #if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE && OPENTHREAD_FTD
|
||||
|
||||
@@ -47,9 +47,9 @@ namespace Utils {
|
||||
|
||||
JamDetector::JamDetector(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, Notifier::Receiver(aInstance, JamDetector::HandleNotifierEvents)
|
||||
, mHandler(NULL)
|
||||
, mContext(NULL)
|
||||
, mNotifierCallback(aInstance, HandleNotifierEvents, this)
|
||||
, mTimer(aInstance, JamDetector::HandleTimer, this)
|
||||
, mHistoryBitmap(0)
|
||||
, mCurSecondStartTime(0)
|
||||
@@ -271,9 +271,9 @@ void JamDetector::SetJamState(bool aNewState)
|
||||
}
|
||||
}
|
||||
|
||||
void JamDetector::HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents)
|
||||
void JamDetector::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<JamDetector>().HandleNotifierEvents(aEvents);
|
||||
static_cast<JamDetector &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void JamDetector::HandleNotifierEvents(Events aEvents)
|
||||
|
||||
@@ -48,7 +48,7 @@ class ThreadNetif;
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class JamDetector : public InstanceLocator
|
||||
class JamDetector : public InstanceLocator, public Notifier::Receiver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -190,22 +190,21 @@ private:
|
||||
void HandleTimer(void);
|
||||
void UpdateHistory(bool aDidExceedThreshold);
|
||||
void UpdateJamState(void);
|
||||
static void HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents);
|
||||
void HandleNotifierEvents(Events aEvents);
|
||||
|
||||
Handler mHandler; // Handler/callback to inform about jamming state
|
||||
void * mContext; // Context for handler/callback
|
||||
Notifier::Callback mNotifierCallback; // Notifier callback
|
||||
TimerMilli mTimer; // RSSI sample timer
|
||||
uint64_t mHistoryBitmap; // History bitmap, each bit correspond to 1 sec interval
|
||||
TimeMilli mCurSecondStartTime; // Start time for current 1 sec interval
|
||||
uint16_t mSampleInterval; // Current sample interval
|
||||
uint8_t mWindow : 6; // Window (in sec) to monitor jamming
|
||||
uint8_t mBusyPeriod : 6; // BusyPeriod (in sec) with mWindow to alert jamming
|
||||
bool mEnabled : 1; // If jam detection is enabled
|
||||
bool mAlwaysAboveThreshold : 1; // State for current 1 sec interval
|
||||
bool mJamState : 1; // Current jam state
|
||||
int8_t mRssiThreshold; // RSSI threshold for jam detection
|
||||
Handler mHandler; // Handler/callback to inform about jamming state
|
||||
void * mContext; // Context for handler/callback
|
||||
TimerMilli mTimer; // RSSI sample timer
|
||||
uint64_t mHistoryBitmap; // History bitmap, each bit correspond to 1 sec interval
|
||||
TimeMilli mCurSecondStartTime; // Start time for current 1 sec interval
|
||||
uint16_t mSampleInterval; // Current sample interval
|
||||
uint8_t mWindow : 6; // Window (in sec) to monitor jamming
|
||||
uint8_t mBusyPeriod : 6; // BusyPeriod (in sec) with mWindow to alert jamming
|
||||
bool mEnabled : 1; // If jam detection is enabled
|
||||
bool mAlwaysAboveThreshold : 1; // State for current 1 sec interval
|
||||
bool mJamState : 1; // Current jam state
|
||||
int8_t mRssiThreshold; // RSSI threshold for jam detection
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,9 +86,9 @@ void Otns::EmitStatus(const char *aFmt, ...)
|
||||
otPlatOtnsStatus(statusStr);
|
||||
}
|
||||
|
||||
void Otns::HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents)
|
||||
void Otns::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<Otns>().HandleNotifierEvents(aEvents);
|
||||
static_cast<Otns &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void Otns::HandleNotifierEvents(Events aEvents)
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Utils {
|
||||
* This class implements the OTNS Stub that interacts with OTNS.
|
||||
*
|
||||
*/
|
||||
class Otns : public InstanceLocator, private NonCopyable
|
||||
class Otns : public InstanceLocator, public Notifier::Receiver, private NonCopyable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
*/
|
||||
explicit Otns(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, mNotifierCallback(aInstance, &Otns::HandleNotifierEvents, this)
|
||||
, Notifier::Receiver(aInstance, Otns::HandleNotifierEvents)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -127,10 +127,8 @@ public:
|
||||
private:
|
||||
static void EmitStatus(const char *aFmt, ...);
|
||||
|
||||
static void HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents);
|
||||
void HandleNotifierEvents(Events aEvents);
|
||||
|
||||
Notifier::Callback mNotifierCallback;
|
||||
};
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
@@ -49,9 +49,9 @@ namespace Utils {
|
||||
|
||||
Slaac::Slaac(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, Notifier::Receiver(aInstance, Slaac::HandleNotifierEvents)
|
||||
, mEnabled(true)
|
||||
, mFilter(NULL)
|
||||
, mNotifierCallback(aInstance, &Slaac::HandleNotifierEvents, this)
|
||||
{
|
||||
memset(mAddresses, 0, sizeof(mAddresses));
|
||||
}
|
||||
@@ -99,9 +99,9 @@ bool Slaac::ShouldFilter(const otIp6Prefix &aPrefix) const
|
||||
return (mFilter != NULL) && mFilter(&GetInstance(), &aPrefix);
|
||||
}
|
||||
|
||||
void Slaac::HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents)
|
||||
void Slaac::HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents)
|
||||
{
|
||||
aCallback.GetOwner<Slaac>().HandleNotifierEvents(aEvents);
|
||||
static_cast<Slaac &>(aReceiver).HandleNotifierEvents(aEvents);
|
||||
}
|
||||
|
||||
void Slaac::HandleNotifierEvents(Events aEvents)
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Utils {
|
||||
* This class implements the SLAAC utility for Thread protocol.
|
||||
*
|
||||
*/
|
||||
class Slaac : public InstanceLocator
|
||||
class Slaac : public InstanceLocator, public Notifier::Receiver
|
||||
{
|
||||
public:
|
||||
enum
|
||||
@@ -161,12 +161,11 @@ private:
|
||||
bool ShouldFilter(const otIp6Prefix &aPrefix) const;
|
||||
void Update(UpdateMode aMode);
|
||||
void GetIidSecretKey(IidSecretKey &aKey) const;
|
||||
static void HandleNotifierEvents(Notifier::Callback &aCallback, Events aEvents);
|
||||
static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents);
|
||||
void HandleNotifierEvents(Events aEvents);
|
||||
|
||||
bool mEnabled;
|
||||
otIp6SlaacPrefixFilter mFilter;
|
||||
Notifier::Callback mNotifierCallback;
|
||||
Ip6::NetifUnicastAddress mAddresses[OPENTHREAD_CONFIG_IP6_SLAAC_NUM_ADDRESSES];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user