[dataset] remove mType from Dataset (#6831)

This commit is contained in:
Yakun Xu
2021-07-20 13:44:12 +08:00
committed by GitHub
parent 71e00eb20f
commit 2cc89cbfcb
9 changed files with 54 additions and 54 deletions
+1 -1
View File
@@ -876,7 +876,7 @@ otError Dataset::ProcessSet(Arg aArgs[])
}
{
MeshCoP::Dataset dataset(datasetType);
MeshCoP::Dataset dataset;
MeshCoP::Dataset::Info datasetInfo;
uint16_t tlvsLength = MeshCoP::Dataset::kMaxSize;
+11 -13
View File
@@ -150,10 +150,9 @@ exit:
return isSubset;
}
Dataset::Dataset(Type aType)
Dataset::Dataset(void)
: mUpdateTime(0)
, mLength(0)
, mType(aType)
{
memset(mTlvs, 0, sizeof(mTlvs));
}
@@ -263,12 +262,12 @@ void Dataset::ConvertTo(otOperationalDatasetTlvs &aDataset) const
aDataset.mLength = static_cast<uint8_t>(mLength);
}
void Dataset::Set(const Dataset &aDataset)
void Dataset::Set(Type aType, const Dataset &aDataset)
{
memcpy(mTlvs, aDataset.mTlvs, aDataset.mLength);
mLength = aDataset.mLength;
if (mType == kActive)
if (aType == kActive)
{
RemoveTlv(Tlv::kPendingTimestamp);
RemoveTlv(Tlv::kDelayTimer);
@@ -372,11 +371,11 @@ Error Dataset::SetFrom(const Info &aDatasetInfo)
return error;
}
const Timestamp *Dataset::GetTimestamp(void) const
const Timestamp *Dataset::GetTimestamp(Type aType) const
{
const Timestamp *timestamp = nullptr;
if (mType == kActive)
if (aType == kActive)
{
const ActiveTimestampTlv *tlv = GetTlv<ActiveTimestampTlv>();
VerifyOrExit(tlv != nullptr);
@@ -393,9 +392,9 @@ exit:
return timestamp;
}
void Dataset::SetTimestamp(const Timestamp &aTimestamp)
void Dataset::SetTimestamp(Type aType, const Timestamp &aTimestamp)
{
IgnoreError(SetTlv((mType == kActive) ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp, aTimestamp));
IgnoreError(SetTlv((aType == kActive) ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp, aTimestamp));
}
Error Dataset::SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength)
@@ -461,7 +460,7 @@ exit:
return;
}
Error Dataset::AppendMleDatasetTlv(Message &aMessage) const
Error Dataset::AppendMleDatasetTlv(Type aType, Message &aMessage) const
{
Error error = kErrorNone;
Mle::Tlv tlv;
@@ -469,7 +468,7 @@ Error Dataset::AppendMleDatasetTlv(Message &aMessage) const
VerifyOrExit(mLength > 0);
type = (mType == kActive ? Mle::Tlv::kActiveDataset : Mle::Tlv::kPendingDataset);
type = (aType == kActive ? Mle::Tlv::kActiveDataset : Mle::Tlv::kPendingDataset);
tlv.SetType(type);
tlv.SetLength(static_cast<uint8_t>(mLength) - sizeof(Tlv) - sizeof(Timestamp));
@@ -477,8 +476,8 @@ Error Dataset::AppendMleDatasetTlv(Message &aMessage) const
for (const Tlv *cur = GetTlvsStart(); cur < GetTlvsEnd(); cur = cur->GetNext())
{
if (((mType == kActive) && (cur->GetType() == Tlv::kActiveTimestamp)) ||
((mType == kPending) && (cur->GetType() == Tlv::kPendingTimestamp)))
if (((aType == kActive) && (cur->GetType() == Tlv::kActiveTimestamp)) ||
((aType == kPending) && (cur->GetType() == Tlv::kPendingTimestamp)))
{
; // skip Active or Pending Timestamp TLV
}
@@ -608,7 +607,6 @@ void Dataset::ConvertToActive(void)
{
RemoveTlv(Tlv::kPendingTimestamp);
RemoveTlv(Tlv::kDelayTimer);
mType = kActive;
}
const char *Dataset::TypeToString(Type aType)
+10 -8
View File
@@ -615,10 +615,8 @@ public:
/**
* This constructor initializes the object.
*
* @param[in] aType The type of the dataset, active or pending.
*
*/
explicit Dataset(Type aType);
Dataset(void);
/**
* This method clears the Dataset.
@@ -735,18 +733,21 @@ public:
/**
* This method returns a reference to the Timestamp.
*
* @param[in] aType The type of the dataset, active or pending.
*
* @returns A pointer to the Timestamp.
*
*/
const Timestamp *GetTimestamp(void) const;
const Timestamp *GetTimestamp(Type aType) const;
/**
* This method sets the Timestamp value.
*
* @param[in] aType The type of the dataset, active or pending.
* @param[in] aTimestamp A Timestamp.
*
*/
void SetTimestamp(const Timestamp &aTimestamp);
void SetTimestamp(Type aType, const Timestamp &aTimestamp);
/**
* This method sets a TLV in the Dataset.
@@ -810,10 +811,11 @@ public:
* If this Dataset is an Active Dataset, any Pending Timestamp and Delay Timer TLVs will be omitted in the copy
* from @p aDataset.
*
* @param[in] aType The type of the dataset, active or pending.
* @param[in] aDataset The input Dataset.
*
*/
void Set(const Dataset &aDataset);
void Set(Type aType, const Dataset &aDataset);
/**
* This method sets the Dataset from a given structure representation.
@@ -845,13 +847,14 @@ public:
/**
* This method appends the MLE Dataset TLV but excluding MeshCoP Sub Timestamp TLV.
*
* @param[in] aType The type of the dataset, active or pending.
* @param[in] aMessage A message to append to.
*
* @retval kErrorNone Successfully append MLE Dataset TLV without MeshCoP Sub Timestamp TLV.
* @retval kErrorNoBufs Insufficient available buffers to append the message with MLE Dataset TLV.
*
*/
Error AppendMleDatasetTlv(Message &aMessage) const;
Error AppendMleDatasetTlv(Type aType, Message &aMessage) const;
/**
* This method applies the Active or Pending Dataset to the Thread interface.
@@ -923,7 +926,6 @@ private:
uint8_t mTlvs[kMaxSize]; ///< The Dataset buffer
TimeMilli mUpdateTime; ///< Local time last updated
uint16_t mLength; ///< The number of valid bytes in @var mTlvs
Type mType; ///< Active or Pending
};
/**
+6 -6
View File
@@ -77,7 +77,7 @@ Error DatasetLocal::Restore(Dataset &aDataset)
SuccessOrExit(error);
mSaved = true;
timestamp = aDataset.GetTimestamp();
timestamp = aDataset.GetTimestamp(mType);
if (timestamp != nullptr)
{
@@ -128,7 +128,7 @@ exit:
Error DatasetLocal::Read(Dataset::Info &aDatasetInfo) const
{
Dataset dataset(mType);
Dataset dataset;
Error error;
aDatasetInfo.Clear();
@@ -142,7 +142,7 @@ exit:
Error DatasetLocal::Read(otOperationalDatasetTlvs &aDataset) const
{
Dataset dataset(mType);
Dataset dataset;
Error error;
memset(&aDataset, 0, sizeof(aDataset));
@@ -157,7 +157,7 @@ exit:
Error DatasetLocal::Save(const Dataset::Info &aDatasetInfo)
{
Error error;
Dataset dataset(mType);
Dataset dataset;
SuccessOrExit(error = dataset.SetFrom(aDatasetInfo));
SuccessOrExit(error = Save(dataset));
@@ -168,7 +168,7 @@ exit:
Error DatasetLocal::Save(const otOperationalDatasetTlvs &aDataset)
{
Dataset dataset(mType);
Dataset dataset;
dataset.SetFrom(aDataset);
@@ -194,7 +194,7 @@ Error DatasetLocal::Save(const Dataset &aDataset)
otLogInfoMeshCoP("%s dataset set", Dataset::TypeToString(mType));
}
timestamp = aDataset.GetTimestamp();
timestamp = aDataset.GetTimestamp(mType);
if (timestamp != nullptr)
{
+16 -16
View File
@@ -81,7 +81,7 @@ int DatasetManager::Compare(const Timestamp &aTimestamp) const
Error DatasetManager::Restore(void)
{
Error error;
Dataset dataset(GetType());
Dataset dataset;
const Timestamp *timestamp;
mTimer.Stop();
@@ -90,7 +90,7 @@ Error DatasetManager::Restore(void)
SuccessOrExit(error = mLocal.Restore(dataset));
timestamp = dataset.GetTimestamp();
timestamp = dataset.GetTimestamp(GetType());
if (timestamp != nullptr)
{
@@ -112,7 +112,7 @@ exit:
Error DatasetManager::ApplyConfiguration(void) const
{
Error error;
Dataset dataset(GetType());
Dataset dataset;
SuccessOrExit(error = Read(dataset));
SuccessOrExit(error = dataset.ApplyConfiguration(GetInstance()));
@@ -142,7 +142,7 @@ Error DatasetManager::Save(const Dataset &aDataset)
int compare;
bool isNetworkkeyUpdated = false;
timestamp = aDataset.GetTimestamp();
timestamp = aDataset.GetTimestamp(GetType());
if (timestamp != nullptr)
{
@@ -249,7 +249,7 @@ Error DatasetManager::GetChannelMask(Mac::ChannelMask &aChannelMask) const
Error error;
const MeshCoP::ChannelMaskTlv *channelMaskTlv;
uint32_t mask;
Dataset dataset(GetType());
Dataset dataset;
SuccessOrExit(error = Read(dataset));
@@ -275,7 +275,7 @@ void DatasetManager::SendSet(void)
Error error;
Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo;
Dataset dataset(GetType());
Dataset dataset;
VerifyOrExit(!mCoapPending, error = kErrorBusy);
VerifyOrExit(Get<Mle::MleRouter>().IsChild() || Get<Mle::MleRouter>().IsRouter(), error = kErrorInvalidState);
@@ -283,7 +283,7 @@ void DatasetManager::SendSet(void)
if (IsActiveDataset())
{
Dataset pendingDataset(Dataset::kPending);
Dataset pendingDataset;
IgnoreError(Get<PendingDataset>().Read(pendingDataset));
const ActiveTimestampTlv *tlv = pendingDataset.GetTlv<ActiveTimestampTlv>();
@@ -402,7 +402,7 @@ void DatasetManager::SendGetResponse(const Coap::Message & aRequest,
{
Error error = kErrorNone;
Coap::Message *message;
Dataset dataset(GetType());
Dataset dataset;
IgnoreError(Read(dataset));
@@ -451,7 +451,7 @@ exit:
Error DatasetManager::AppendDatasetToMessage(const Dataset::Info &aDatasetInfo, Message &aMessage) const
{
Error error;
Dataset dataset(GetType());
Dataset dataset;
SuccessOrExit(error = dataset.SetFrom(aDatasetInfo));
error = aMessage.AppendBytes(dataset.GetBytes(), dataset.GetSize());
@@ -670,10 +670,10 @@ exit:
Error ActiveDataset::Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength)
{
Error error = kErrorNone;
Dataset dataset(GetType());
Dataset dataset;
SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength));
dataset.SetTimestamp(aTimestamp);
dataset.SetTimestamp(Dataset::kActive, aTimestamp);
IgnoreError(DatasetManager::Save(dataset));
exit:
@@ -715,7 +715,7 @@ void PendingDataset::Clear(void)
void PendingDataset::ClearNetwork(void)
{
Dataset dataset(GetType());
Dataset dataset;
mTimestamp.Init();
mTimestampValid = false;
@@ -758,10 +758,10 @@ exit:
Error PendingDataset::Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength)
{
Error error = kErrorNone;
Dataset dataset(GetType());
Dataset dataset;
SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength));
dataset.SetTimestamp(aTimestamp);
dataset.SetTimestamp(Dataset::kPending, aTimestamp);
IgnoreError(DatasetManager::Save(dataset));
StartDelayTimer();
@@ -772,7 +772,7 @@ exit:
void PendingDataset::StartDelayTimer(void)
{
DelayTimerTlv *delayTimer;
Dataset dataset(GetType());
Dataset dataset;
IgnoreError(Read(dataset));
@@ -801,7 +801,7 @@ void PendingDataset::HandleDelayTimer(Timer &aTimer)
void PendingDataset::HandleDelayTimer(void)
{
DelayTimerTlv *delayTimer;
Dataset dataset(GetType());
Dataset dataset;
IgnoreError(Read(dataset));
+6 -6
View File
@@ -61,11 +61,11 @@ namespace MeshCoP {
Error DatasetManager::AppendMleDatasetTlv(Message &aMessage) const
{
Dataset dataset(GetType());
Dataset dataset;
IgnoreError(Read(dataset));
return dataset.AppendMleDatasetTlv(aMessage);
return dataset.AppendMleDatasetTlv(GetType(), aMessage);
}
Error DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
@@ -79,7 +79,7 @@ Error DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInfo
bool doesAffectNetworkKey = false;
bool hasNetworkKey = false;
StateTlv::State state = StateTlv::kReject;
Dataset dataset(GetType());
Dataset dataset;
ActiveTimestampTlv activeTimestamp;
PendingTimestampTlv pendingTimestamp;
@@ -309,7 +309,7 @@ exit:
Error ActiveDataset::GenerateLocal(void)
{
Error error = kErrorNone;
Dataset dataset(GetType());
Dataset dataset;
VerifyOrExit(Get<Mle::MleRouter>().IsAttached(), error = kErrorInvalidState);
VerifyOrExit(!mLocal.IsTimestampPresent(), error = kErrorAlready);
@@ -457,7 +457,7 @@ exit:
void PendingDataset::ApplyActiveDataset(const Timestamp &aTimestamp, Coap::Message &aMessage)
{
uint16_t offset = aMessage.GetOffset();
Dataset dataset(GetType());
Dataset dataset;
VerifyOrExit(Get<Mle::MleRouter>().IsAttached());
@@ -474,7 +474,7 @@ void PendingDataset::ApplyActiveDataset(const Timestamp &aTimestamp, Coap::Messa
IgnoreError(dataset.SetTlv(Tlv::kDelayTimer, Get<Leader>().GetDelayTimerMinimal()));
// add pending timestamp tlv
dataset.SetTimestamp(aTimestamp);
dataset.SetTimestamp(Dataset::kPending, aTimestamp);
IgnoreError(DatasetManager::Save(dataset));
// reset delay timer
+2 -2
View File
@@ -105,7 +105,7 @@ void DatasetUpdater::HandleTimer(void)
void DatasetUpdater::PreparePendingDataset(void)
{
Dataset dataset(Dataset::kPending);
Dataset dataset;
MeshCoP::Dataset::Info requestedDataset;
Error error;
@@ -145,7 +145,7 @@ void DatasetUpdater::PreparePendingDataset(void)
}
timestamp.AdvanceRandomTicks();
dataset.SetTimestamp(timestamp);
dataset.SetTimestamp(Dataset::kPending, timestamp);
}
{
+1 -1
View File
@@ -314,7 +314,7 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void)
{
Error error;
Coap::Message *message = nullptr;
Dataset dataset(Dataset::kActive);
Dataset dataset;
NetworkNameTlv networkName;
const Tlv * tlv;
+1 -1
View File
@@ -601,7 +601,7 @@ otError RadioSpinel<InterfaceType, ProcessContextType>::ThreadDatasetHandler(con
otOperationalDataset opDataset;
bool isActive = ((mWaitingKey == SPINEL_PROP_THREAD_ACTIVE_DATASET) ? true : false);
Spinel::Decoder decoder;
MeshCoP::Dataset dataset(isActive ? MeshCoP::Dataset::kActive : MeshCoP::Dataset::kPending);
MeshCoP::Dataset dataset;
memset(&opDataset, 0, sizeof(otOperationalDataset));
decoder.Init(aBuffer, aLength);