Skip to content

Commit

Permalink
Prefix InteractionModel namespace with protocols (#34376)
Browse files Browse the repository at this point in the history
* Update namespace access for InteractionModel

* Undo change that is from other PR

* Pulled 2 more files

* Pulled one more file

---------

Co-authored-by: Andrei Litvin <andreilitvin@google.com>
  • Loading branch information
2 people authored and pull[bot] committed Sep 13, 2024
1 parent cd9714c commit 1265680
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ bool emberAfAdministratorCommissioningClusterOpenCommissioningWindowCallback(
auto & iterations = commandData.iterations;
auto & salt = commandData.salt;

Optional<StatusCode> status = Optional<StatusCode>::Missing();
InteractionModel::Status globalStatus = InteractionModel::Status::Success;
Optional<StatusCode> status = Optional<StatusCode>::Missing();
Status globalStatus = Status::Success;
Spake2pVerifier verifier;

ChipLogProgress(Zcl, "Received command to open commissioning window");
Expand All @@ -110,11 +110,9 @@ bool emberAfAdministratorCommissioningClusterOpenCommissioningWindowCallback(
VerifyOrExit(iterations <= kSpake2p_Max_PBKDF_Iterations, status.Emplace(StatusCode::kPAKEParameterError));
VerifyOrExit(salt.size() >= kSpake2p_Min_PBKDF_Salt_Length, status.Emplace(StatusCode::kPAKEParameterError));
VerifyOrExit(salt.size() <= kSpake2p_Max_PBKDF_Salt_Length, status.Emplace(StatusCode::kPAKEParameterError));
VerifyOrExit(commissioningTimeout <= commissionMgr.MaxCommissioningTimeout(),
globalStatus = InteractionModel::Status::InvalidCommand);
VerifyOrExit(commissioningTimeout >= commissionMgr.MinCommissioningTimeout(),
globalStatus = InteractionModel::Status::InvalidCommand);
VerifyOrExit(discriminator <= kMaxDiscriminatorValue, globalStatus = InteractionModel::Status::InvalidCommand);
VerifyOrExit(commissioningTimeout <= commissionMgr.MaxCommissioningTimeout(), globalStatus = Status::InvalidCommand);
VerifyOrExit(commissioningTimeout >= commissionMgr.MinCommissioningTimeout(), globalStatus = Status::InvalidCommand);
VerifyOrExit(discriminator <= kMaxDiscriminatorValue, globalStatus = Status::InvalidCommand);

VerifyOrExit(verifier.Deserialize(pakeVerifier) == CHIP_NO_ERROR, status.Emplace(StatusCode::kPAKEParameterError));
VerifyOrExit(commissionMgr.OpenEnhancedCommissioningWindow(commissioningTimeout, discriminator, verifier, iterations, salt,
Expand All @@ -130,7 +128,7 @@ bool emberAfAdministratorCommissioningClusterOpenCommissioningWindowCallback(
}
else
{
if (globalStatus != InteractionModel::Status::Success)
if (globalStatus != Status::Success)
{
ChipLogError(Zcl, "Failed to open commissioning window. Global status " ChipLogFormatIMStatus,
ChipLogValueIMStatus(globalStatus));
Expand All @@ -147,8 +145,8 @@ bool emberAfAdministratorCommissioningClusterOpenBasicCommissioningWindowCallbac
MATTER_TRACE_SCOPE("OpenBasicCommissioningWindow", "AdministratorCommissioning");
auto commissioningTimeout = System::Clock::Seconds16(commandData.commissioningTimeout);

Optional<StatusCode> status = Optional<StatusCode>::Missing();
InteractionModel::Status globalStatus = InteractionModel::Status::Success;
Optional<StatusCode> status = Optional<StatusCode>::Missing();
Status globalStatus = Status::Success;
ChipLogProgress(Zcl, "Received command to open basic commissioning window");

FabricIndex fabricIndex = commandObj->GetAccessingFabricIndex();
Expand All @@ -160,10 +158,8 @@ bool emberAfAdministratorCommissioningClusterOpenBasicCommissioningWindowCallbac

VerifyOrExit(!commissionMgr.IsCommissioningWindowOpen(), status.Emplace(StatusCode::kBusy));
VerifyOrExit(failSafeContext.IsFailSafeFullyDisarmed(), status.Emplace(StatusCode::kBusy));
VerifyOrExit(commissioningTimeout <= commissionMgr.MaxCommissioningTimeout(),
globalStatus = InteractionModel::Status::InvalidCommand);
VerifyOrExit(commissioningTimeout >= commissionMgr.MinCommissioningTimeout(),
globalStatus = InteractionModel::Status::InvalidCommand);
VerifyOrExit(commissioningTimeout <= commissionMgr.MaxCommissioningTimeout(), globalStatus = Status::InvalidCommand);
VerifyOrExit(commissioningTimeout >= commissionMgr.MinCommissioningTimeout(), globalStatus = Status::InvalidCommand);
VerifyOrExit(commissionMgr.OpenBasicCommissioningWindowForAdministratorCommissioningCluster(
commissioningTimeout, fabricIndex, fabricInfo->GetVendorId()) == CHIP_NO_ERROR,
status.Emplace(StatusCode::kPAKEParameterError));
Expand All @@ -177,7 +173,7 @@ bool emberAfAdministratorCommissioningClusterOpenBasicCommissioningWindowCallbac
}
else
{
if (globalStatus != InteractionModel::Status::Success)
if (globalStatus != Status::Success)
{
ChipLogError(Zcl, "Failed to open commissioning window. Global status " ChipLogFormatIMStatus,
ChipLogValueIMStatus(globalStatus));
Expand Down
42 changes: 21 additions & 21 deletions src/app/clusters/icd-management-server/icd-management-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ Status ICDManagementServer::RegisterClient(CommandHandler * commandObj, const Co
bool isClientAdmin = false;

// Check if ClientType is valid
VerifyOrReturnError(clientType != ClientTypeEnum::kUnknownEnumValue, InteractionModel::Status::ConstraintError);
VerifyOrReturnError(clientType != ClientTypeEnum::kUnknownEnumValue, Status::ConstraintError);

// Check if client is admin
VerifyOrReturnError(CHIP_NO_ERROR == CheckAdmin(commandObj, commandPath, isClientAdmin), InteractionModel::Status::Failure);
VerifyOrReturnError(CHIP_NO_ERROR == CheckAdmin(commandObj, commandPath, isClientAdmin), Status::Failure);

bool isFirstEntryForFabric = false;
ICDMonitoringTable table(*mStorage, fabricIndex, mICDConfigurationData->GetClientsSupportedPerFabric(), mSymmetricKeystore);
Expand All @@ -275,22 +275,22 @@ Status ICDManagementServer::RegisterClient(CommandHandler * commandObj, const Co
// Existing entry: Validate Key if, and only if, the ISD does NOT have administrator permissions
if (!isClientAdmin)
{
VerifyOrReturnError(verificationKey.HasValue(), InteractionModel::Status::Failure);
VerifyOrReturnError(entry.IsKeyEquivalent(verificationKey.Value()), InteractionModel::Status::Failure);
VerifyOrReturnError(verificationKey.HasValue(), Status::Failure);
VerifyOrReturnError(entry.IsKeyEquivalent(verificationKey.Value()), Status::Failure);
}
}
else if (CHIP_ERROR_NOT_FOUND == err)
{
// New entry
VerifyOrReturnError(entry.index < table.Limit(), InteractionModel::Status::ResourceExhausted);
VerifyOrReturnError(entry.index < table.Limit(), Status::ResourceExhausted);

// Check if it's going to be the first entry for fabric
isFirstEntryForFabric = table.IsEmpty();
}
else
{
// Error
return InteractionModel::Status::Failure;
return Status::Failure;
}

// Save
Expand All @@ -304,8 +304,8 @@ Status ICDManagementServer::RegisterClient(CommandHandler * commandObj, const Co
}

err = entry.SetKey(key);
VerifyOrReturnError(CHIP_ERROR_INVALID_ARGUMENT != err, InteractionModel::Status::ConstraintError);
VerifyOrReturnError(CHIP_NO_ERROR == err, InteractionModel::Status::Failure);
VerifyOrReturnError(CHIP_ERROR_INVALID_ARGUMENT != err, Status::ConstraintError);
VerifyOrReturnError(CHIP_NO_ERROR == err, Status::Failure);
err = table.Set(entry.index, entry);

// Delete key upon failure to prevent key storage leakage.
Expand All @@ -314,8 +314,8 @@ Status ICDManagementServer::RegisterClient(CommandHandler * commandObj, const Co
entry.DeleteKey();
}

VerifyOrReturnError(CHIP_ERROR_INVALID_ARGUMENT != err, InteractionModel::Status::ConstraintError);
VerifyOrReturnError(CHIP_NO_ERROR == err, InteractionModel::Status::Failure);
VerifyOrReturnError(CHIP_ERROR_INVALID_ARGUMENT != err, Status::ConstraintError);
VerifyOrReturnError(CHIP_NO_ERROR == err, Status::Failure);

if (isFirstEntryForFabric)
{
Expand All @@ -324,7 +324,7 @@ Status ICDManagementServer::RegisterClient(CommandHandler * commandObj, const Co
}

icdCounter = mICDConfigurationData->GetICDCounter().GetValue();
return InteractionModel::Status::Success;
return Status::Success;
}

Status ICDManagementServer::UnregisterClient(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
Expand All @@ -336,32 +336,32 @@ Status ICDManagementServer::UnregisterClient(CommandHandler * commandObj, const
bool isClientAdmin = false;

// Check if client is admin
VerifyOrReturnError(CHIP_NO_ERROR == CheckAdmin(commandObj, commandPath, isClientAdmin), InteractionModel::Status::Failure);
VerifyOrReturnError(CHIP_NO_ERROR == CheckAdmin(commandObj, commandPath, isClientAdmin), Status::Failure);

ICDMonitoringTable table(*mStorage, fabricIndex, mICDConfigurationData->GetClientsSupportedPerFabric(), mSymmetricKeystore);

// Get current entry, if exists
ICDMonitoringEntry entry(mSymmetricKeystore);
CHIP_ERROR err = table.Find(nodeId, entry);
VerifyOrReturnError(CHIP_ERROR_NOT_FOUND != err, InteractionModel::Status::NotFound);
VerifyOrReturnError(CHIP_NO_ERROR == err, InteractionModel::Status::Failure);
VerifyOrReturnError(CHIP_ERROR_NOT_FOUND != err, Status::NotFound);
VerifyOrReturnError(CHIP_NO_ERROR == err, Status::Failure);

// Existing entry: Validate Key if, and only if, the ISD has NOT administrator permissions
if (!isClientAdmin)
{
VerifyOrReturnError(verificationKey.HasValue(), InteractionModel::Status::Failure);
VerifyOrReturnError(entry.IsKeyEquivalent(verificationKey.Value()), InteractionModel::Status::Failure);
VerifyOrReturnError(verificationKey.HasValue(), Status::Failure);
VerifyOrReturnError(entry.IsKeyEquivalent(verificationKey.Value()), Status::Failure);
}

err = table.Remove(entry.index);
VerifyOrReturnError(CHIP_NO_ERROR == err, InteractionModel::Status::Failure);
VerifyOrReturnError(CHIP_NO_ERROR == err, Status::Failure);

if (table.IsEmpty())
{
TriggerICDMTableUpdatedEvent();
}

return InteractionModel::Status::Success;
return Status::Success;
}

void ICDManagementServer::TriggerICDMTableUpdatedEvent()
Expand Down Expand Up @@ -396,9 +396,9 @@ bool emberAfIcdManagementClusterRegisterClientCallback(CommandHandler * commandO
uint32_t icdCounter = 0;

ICDManagementServer server;
InteractionModel::Status status = server.RegisterClient(commandObj, commandPath, commandData, icdCounter);
Status status = server.RegisterClient(commandObj, commandPath, commandData, icdCounter);

if (InteractionModel::Status::Success == status)
if (Status::Success == status)
{
// Response
IcdManagement::Commands::RegisterClientResponse::Type response{ .ICDCounter = icdCounter };
Expand All @@ -419,7 +419,7 @@ bool emberAfIcdManagementClusterUnregisterClientCallback(CommandHandler * comman
const Commands::UnregisterClient::DecodableType & commandData)
{
ICDManagementServer server;
InteractionModel::Status status = server.UnregisterClient(commandObj, commandPath, commandData);
Status status = server.UnregisterClient(commandObj, commandPath, commandData);

commandObj->AddStatus(commandPath, status);
return true;
Expand Down
30 changes: 15 additions & 15 deletions src/app/tests/TestCommandInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,27 +165,25 @@ struct BadFields
}
};

InteractionModel::Status ServerClusterCommandExists(const ConcreteCommandPath & aRequestCommandPath)
Protocols::InteractionModel::Status ServerClusterCommandExists(const ConcreteCommandPath & aRequestCommandPath)
{
// Mock cluster catalog, only support commands on one cluster on one endpoint.
using InteractionModel::Status;

if (aRequestCommandPath.mEndpointId != kTestEndpointId)
{
return Status::UnsupportedEndpoint;
return Protocols::InteractionModel::Status::UnsupportedEndpoint;
}

if (aRequestCommandPath.mClusterId != kTestClusterId)
{
return Status::UnsupportedCluster;
return Protocols::InteractionModel::Status::UnsupportedCluster;
}

if (aRequestCommandPath.mCommandId == kTestNonExistCommandId)
{
return Status::UnsupportedCommand;
return Protocols::InteractionModel::Status::UnsupportedCommand;
}

return Status::Success;
return Protocols::InteractionModel::Status::Success;
}

void DispatchSingleClusterCommand(const ConcreteCommandPath & aRequestCommandPath, chip::TLV::TLVReader & aReader,
Expand Down Expand Up @@ -346,7 +344,7 @@ class MockCommandHandlerCallback : public CommandHandlerImpl::Callback
{
DispatchSingleClusterCommand(aCommandPath, apPayload, &apCommandObj);
}
InteractionModel::Status CommandExists(const ConcreteCommandPath & aCommandPath)
Protocols::InteractionModel::Status CommandExists(const ConcreteCommandPath & aCommandPath)
{
return ServerClusterCommandExists(aCommandPath);
}
Expand Down Expand Up @@ -1255,7 +1253,8 @@ TEST_F(TestCommandInteraction, TestCommandHandler_WithOnInvokeReceivedNotExistCo

mockCommandHandlerDelegate.ResetCounter();
MockCommandResponder mockCommandResponder;
InteractionModel::Status status = commandHandler.OnInvokeCommandRequest(mockCommandResponder, std::move(commandDatabuf), false);
Protocols::InteractionModel::Status status =
commandHandler.OnInvokeCommandRequest(mockCommandResponder, std::move(commandDatabuf), false);

EXPECT_EQ(status, Protocols::InteractionModel::Status::InvalidAction);
EXPECT_TRUE(mockCommandResponder.mChunks.IsNull());
Expand Down Expand Up @@ -1650,8 +1649,8 @@ TEST_F_FROM_FIXTURE(TestCommandInteraction, TestCommandHandler_RejectsMultipleCo
mockCommandHandlerDelegate.ResetCounter();
commandDispatchedCount = 0;

InteractionModel::Status status = commandHandler.ProcessInvokeRequest(std::move(commandDatabuf), false);
EXPECT_EQ(status, InteractionModel::Status::InvalidAction);
Protocols::InteractionModel::Status status = commandHandler.ProcessInvokeRequest(std::move(commandDatabuf), false);
EXPECT_EQ(status, Protocols::InteractionModel::Status::InvalidAction);

EXPECT_EQ(commandDispatchedCount, 0u);
}
Expand Down Expand Up @@ -1703,8 +1702,9 @@ TEST_F_FROM_FIXTURE(TestCommandInteraction, TestCommandHandler_RejectMultipleCom

CommandHandlerImpl commandHandler(&mockCommandHandlerDelegate);
MockCommandResponder mockCommandResponder;
InteractionModel::Status status = commandHandler.OnInvokeCommandRequest(mockCommandResponder, std::move(commandDatabuf), false);
EXPECT_EQ(status, InteractionModel::Status::InvalidAction);
Protocols::InteractionModel::Status status =
commandHandler.OnInvokeCommandRequest(mockCommandResponder, std::move(commandDatabuf), false);
EXPECT_EQ(status, Protocols::InteractionModel::Status::InvalidAction);
EXPECT_TRUE(mockCommandResponder.mChunks.IsNull());

EXPECT_EQ(commandDispatchedCount, 0u);
Expand Down Expand Up @@ -1759,8 +1759,8 @@ TEST_F_FROM_FIXTURE(TestCommandInteraction, TestCommandHandler_AcceptMultipleCom
mockCommandHandlerDelegate.ResetCounter();
commandDispatchedCount = 0;

InteractionModel::Status status = commandHandler.ProcessInvokeRequest(std::move(commandDatabuf), false);
EXPECT_EQ(status, InteractionModel::Status::Success);
Protocols::InteractionModel::Status status = commandHandler.ProcessInvokeRequest(std::move(commandDatabuf), false);
EXPECT_EQ(status, Protocols::InteractionModel::Status::Success);

EXPECT_EQ(commandDispatchedCount, 2u);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@
#include "InteractionModel.h"

using namespace chip;
using namespace chip::app;

using chip::app::AttributePathParams;
using chip::app::CommandSender;
using chip::app::ConcreteAttributePath;
using chip::app::ConcreteCommandPath;
using chip::app::ConcreteDataAttributePath;
using chip::app::DataVersionFilter;
using chip::app::EventHeader;
using chip::app::EventPathParams;
using chip::app::InteractionModelEngine;
using chip::app::ReadClient;
using chip::app::ReadPrepareParams;
using chip::app::StatusIB;
using chip::app::WriteClient;

namespace chip {
namespace test_utils {
Expand Down
16 changes: 8 additions & 8 deletions src/controller/tests/data_model/DataModelFixtures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,15 @@ CHIP_ERROR WriteSingleClusterData(const Access::SubjectDescriptor & aSubjectDesc
// Boolean attribute of unit testing cluster triggers "multiple errors" case.
if (aPath.mClusterId == Clusters::UnitTesting::Id && aPath.mAttributeId == Attributes::Boolean::TypeInfo::GetAttributeId())
{
InteractionModel::ClusterStatusCode status{ Protocols::InteractionModel::Status::InvalidValue };
Protocols::InteractionModel::ClusterStatusCode status{ Protocols::InteractionModel::Status::InvalidValue };

if (gWriteResponseDirective == WriteResponseDirective::kSendMultipleSuccess)
{
status = InteractionModel::Status::Success;
status = Protocols::InteractionModel::Status::Success;
}
else if (gWriteResponseDirective == WriteResponseDirective::kSendMultipleErrors)
{
status = InteractionModel::Status::Failure;
status = Protocols::InteractionModel::Status::Failure;
}
else
{
Expand All @@ -337,14 +337,14 @@ CHIP_ERROR WriteSingleClusterData(const Access::SubjectDescriptor & aSubjectDesc

if (aPath.mClusterId == Clusters::UnitTesting::Id && aPath.mAttributeId == Attributes::Int8u::TypeInfo::GetAttributeId())
{
InteractionModel::ClusterStatusCode status{ Protocols::InteractionModel::Status::InvalidValue };
Protocols::InteractionModel::ClusterStatusCode status{ Protocols::InteractionModel::Status::InvalidValue };
if (gWriteResponseDirective == WriteResponseDirective::kSendClusterSpecificSuccess)
{
status = InteractionModel::ClusterStatusCode::ClusterSpecificSuccess(kExampleClusterSpecificSuccess);
status = Protocols::InteractionModel::ClusterStatusCode::ClusterSpecificSuccess(kExampleClusterSpecificSuccess);
}
else if (gWriteResponseDirective == WriteResponseDirective::kSendClusterSpecificFailure)
{
status = InteractionModel::ClusterStatusCode::ClusterSpecificFailure(kExampleClusterSpecificFailure);
status = Protocols::InteractionModel::ClusterStatusCode::ClusterSpecificFailure(kExampleClusterSpecificFailure);
}
else
{
Expand Down Expand Up @@ -446,10 +446,10 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, chip
}
}

InteractionModel::Status ServerClusterCommandExists(const ConcreteCommandPath & aCommandPath)
Protocols::InteractionModel::Status ServerClusterCommandExists(const ConcreteCommandPath & aCommandPath)
{
// Mock cluster catalog, only support commands on one cluster on one endpoint.
using InteractionModel::Status;
using Protocols::InteractionModel::Status;

if (aCommandPath.mEndpointId != kTestEndpointId)
{
Expand Down
4 changes: 2 additions & 2 deletions src/controller/tests/data_model/TestCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ TEST_F(TestCommands, TestMultipleSuccessNoDataResponses)
// not safe to do so.
auto onSuccessCb = [&successCalls, &statusCheck](const ConcreteCommandPath & commandPath, const StatusIB & aStatus,
const auto & dataResponse) {
statusCheck = (aStatus.mStatus == InteractionModel::Status::Success);
statusCheck = (aStatus.mStatus == Protocols::InteractionModel::Status::Success);
++successCalls;
};

Expand Down Expand Up @@ -290,7 +290,7 @@ TEST_F(TestCommands, TestMultipleFailures)
// Passing of stack variables by reference is only safe because of synchronous completion of the interaction. Otherwise, it's
// not safe to do so.
auto onFailureCb = [&failureCalls, &statusCheck](CHIP_ERROR aError) {
statusCheck = aError.IsIMStatus() && StatusIB(aError).mStatus == InteractionModel::Status::Failure;
statusCheck = aError.IsIMStatus() && StatusIB(aError).mStatus == Protocols::InteractionModel::Status::Failure;
++failureCalls;
};

Expand Down

0 comments on commit 1265680

Please sign in to comment.