mirror of
https://github.com/espressif/openthread.git
synced 2026-08-04 18:07:47 +00:00
[settings] use Equatable/Clearable in Settings structures (#5281)
This commit is contained in:
@@ -252,7 +252,7 @@ otError Settings::SaveNetworkInfo(const NetworkInfo &aNetworkInfo)
|
||||
uint16_t length = sizeof(prevNetworkInfo);
|
||||
|
||||
if ((Read(kKeyNetworkInfo, &prevNetworkInfo, length) == OT_ERROR_NONE) && (length == sizeof(NetworkInfo)) &&
|
||||
(memcmp(&prevNetworkInfo, &aNetworkInfo, sizeof(NetworkInfo)) == 0))
|
||||
(prevNetworkInfo == aNetworkInfo))
|
||||
{
|
||||
LogNetworkInfo("Re-saved", aNetworkInfo);
|
||||
ExitNow();
|
||||
@@ -298,7 +298,7 @@ otError Settings::SaveParentInfo(const ParentInfo &aParentInfo)
|
||||
uint16_t length = sizeof(ParentInfo);
|
||||
|
||||
if ((Read(kKeyParentInfo, &prevParentInfo, length) == OT_ERROR_NONE) && (length == sizeof(ParentInfo)) &&
|
||||
(memcmp(&prevParentInfo, &aParentInfo, sizeof(ParentInfo)) == 0))
|
||||
(prevParentInfo == aParentInfo))
|
||||
{
|
||||
LogParentInfo("Re-saved", aParentInfo);
|
||||
ExitNow();
|
||||
@@ -413,7 +413,7 @@ otError Settings::SaveDadInfo(const DadInfo &aDadInfo)
|
||||
uint16_t length = sizeof(DadInfo);
|
||||
|
||||
if ((Read(kKeyDadInfo, &prevDadInfo, length) == OT_ERROR_NONE) && (length == sizeof(DadInfo)) &&
|
||||
(memcmp(&prevDadInfo, &aDadInfo, sizeof(DadInfo)) == 0))
|
||||
(prevDadInfo == aDadInfo))
|
||||
{
|
||||
LogDadInfo("Re-saved", aDadInfo);
|
||||
ExitNow();
|
||||
|
||||
@@ -36,7 +36,9 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
#include "common/clearable.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
#include "common/equatable.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/non_copyable.hpp"
|
||||
#include "mac/mac_types.hpp"
|
||||
@@ -183,16 +185,16 @@ public:
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class NetworkInfo
|
||||
class NetworkInfo : public Equatable<NetworkInfo>, private Clearable<NetworkInfo>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method clears the struct object (setting all the fields to zero).
|
||||
* This method initializes the `NetworkInfo` object.
|
||||
*
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
memset(this, 0, sizeof(*this));
|
||||
Clear();
|
||||
SetVersion(OT_THREAD_VERSION_1_1);
|
||||
}
|
||||
|
||||
@@ -383,16 +385,16 @@ public:
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class ParentInfo
|
||||
class ParentInfo : public Equatable<ParentInfo>, private Clearable<ParentInfo>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method clears the struct object (setting all the fields to zero).
|
||||
* This method initializes the `ParentInfo` object.
|
||||
*
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
memset(this, 0, sizeof(*this));
|
||||
Clear();
|
||||
SetVersion(OT_THREAD_VERSION_1_1);
|
||||
}
|
||||
|
||||
@@ -544,14 +546,14 @@ public:
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class DadInfo
|
||||
class DadInfo : public Equatable<DadInfo>, private Clearable<DadInfo>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method clears the struct object (setting all the fields to zero).
|
||||
* This method initializes the `DadInfo` object.
|
||||
*
|
||||
*/
|
||||
void Init(void) { memset(this, 0, sizeof(*this)); }
|
||||
void Init(void) { Clear(); }
|
||||
|
||||
/**
|
||||
* This method returns the Dad Counter.
|
||||
|
||||
Reference in New Issue
Block a user