[netdata] perform SynchronizeServerData() from a Tasklet (#7823)

This commit adds a `Taskelt` in `NetworkData::Notifier` to perform
`SynchronizeServerData()` and post this tasklet when there is a
change and `HandleServerDataUpdated()` is called. This ensures that
if there are multiple changes triggered within the same flow of
execution, they are all synchronized together and included in the
same message to register with leader.
This commit is contained in:
Abtin Keshavarzian
2022-06-21 09:55:20 -07:00
committed by Jonathan Hui
parent 481a064f03
commit ea611dc1f1
2 changed files with 16 additions and 2 deletions
+8 -2
View File
@@ -46,7 +46,8 @@ namespace NetworkData {
Notifier::Notifier(Instance &aInstance)
: InstanceLocator(aInstance)
, mTimer(aInstance, Notifier::HandleTimer)
, mTimer(aInstance, HandleTimer)
, mSynchronizeDataTask(aInstance, HandleSynchronizeDataTask)
, mNextDelay(0)
, mWaitingForResponse(false)
{
@@ -55,7 +56,12 @@ Notifier::Notifier(Instance &aInstance)
void Notifier::HandleServerDataUpdated(void)
{
mNextDelay = 0;
SynchronizeServerData();
mSynchronizeDataTask.Post();
}
void Notifier::HandleSynchronizeDataTask(Tasklet &aTasklet)
{
aTasklet.Get<Notifier>().SynchronizeServerData();
}
void Notifier::SynchronizeServerData(void)
@@ -42,6 +42,7 @@
#include "common/message.hpp"
#include "common/non_copyable.hpp"
#include "common/notifier.hpp"
#include "common/tasklet.hpp"
namespace ot {
namespace NetworkData {
@@ -66,6 +67,10 @@ public:
/**
* Call this method to inform the notifier that new server data is available.
*
* This method posts a tasklet to sync new server data with leader so if there are multiple changes within the same
* flow of execution (multiple calls to this method) they are all synchronized together and included in the same
* message to the leader.
*
*/
void HandleServerDataUpdated(void);
@@ -85,9 +90,12 @@ private:
Error aResult);
void HandleCoapResponse(Error aResult);
static void HandleSynchronizeDataTask(Tasklet &aTasklet);
void SynchronizeServerData(void);
TimerMilli mTimer;
Tasklet mSynchronizeDataTask;
uint32_t mNextDelay;
bool mWaitingForResponse;
};