Skip to content

Commit

Permalink
[Fabric Sync] Have ECOINFO mark attribute dirty when new entry added … (
Browse files Browse the repository at this point in the history
  • Loading branch information
tehampson authored Oct 17, 2024
1 parent ed7ef1b commit 5fe4409
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ CHIP_ERROR EcosystemInformationServer::AddDeviceInfo(EndpointId aEndpoint, std::

auto & deviceInfo = mDevicesMap[aEndpoint];
deviceInfo.mDeviceDirectory.push_back(std::move(aDevice));
mMatterContext.MarkDirty(aEndpoint, Attributes::DeviceDirectory::Id);
return CHIP_NO_ERROR;
}

Expand All @@ -282,6 +283,7 @@ CHIP_ERROR EcosystemInformationServer::AddLocationInfo(EndpointId aEndpoint, con
VerifyOrReturnError((deviceInfo.mLocationDirectory.find(key) == deviceInfo.mLocationDirectory.end()),
CHIP_ERROR_INVALID_ARGUMENT);
deviceInfo.mLocationDirectory[key] = std::move(aLocation);
mMatterContext.MarkDirty(aEndpoint, Attributes::LocationDirectory::Id);
return CHIP_NO_ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/reporting/reporting.h>

#include <app/AttributeAccessInterface.h>

Expand All @@ -35,6 +36,21 @@ namespace app {
namespace Clusters {
namespace EcosystemInformation {

class MatterContext
{
public:
virtual ~MatterContext() = default;
// MarkDirty
virtual void MarkDirty(EndpointId endpointId, AttributeId attributeId)
{
MatterReportingAttributeChangeCallback(endpointId, Id, attributeId);
}
};

class TestOnlyParameter
{
};

// This intentionally mirrors Structs::EcosystemDeviceStruct::Type but has ownership
// of underlying types.
class EcosystemDeviceStruct
Expand Down Expand Up @@ -144,11 +160,14 @@ class EcosystemLocationStruct
uint64_t mLocationDescriptorLastEditEpochUs;
};

class EcosystemInformationServer
class EcosystemInformationServer : public MatterContext
{
public:
static EcosystemInformationServer & Instance();

EcosystemInformationServer() : mMatterContext(*this){};
EcosystemInformationServer(TestOnlyParameter _, MatterContext & aMatterContext) : mMatterContext(aMatterContext){};

/**
* @brief Add EcosystemInformation Cluster to endpoint so we respond appropriately on endpoint
*
Expand Down Expand Up @@ -212,6 +231,7 @@ class EcosystemInformationServer
CHIP_ERROR EncodeDeviceDirectoryAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
CHIP_ERROR EncodeLocationStructAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);

MatterContext & mMatterContext;
std::map<EndpointId, DeviceInfo> mDevicesMap;

static EcosystemInformationServer mInstance;
Expand Down
49 changes: 49 additions & 0 deletions src/app/tests/TestEcosystemInformationCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,28 @@ const ClusterId kEcosystemInfoClusterId = EcosystemInformation::Id;
const AttributeId kDeviceDirectoryAttributeId = EcosystemInformation::Attributes::DeviceDirectory::Id;
const AttributeId kLocationDirectoryAttributeId = EcosystemInformation::Attributes::LocationDirectory::Id;

class MockMatterContext : public MatterContext
{
public:
virtual void MarkDirty(EndpointId endpointId, AttributeId attributeId) override
{
ConcreteAttributePath path(endpointId, kEcosystemInfoClusterId, attributeId);
mDirtyMarkedList.push_back(path);
}

std::vector<ConcreteAttributePath> & GetDirtyList() { return mDirtyMarkedList; }

private:
std::vector<ConcreteAttributePath> mDirtyMarkedList;
};

} // namespace

class TestEcosystemInformationCluster : public ::testing::Test
{
public:
TestEcosystemInformationCluster() : mClusterServer(TestOnlyParameter(), mMockMatterContext) {}

static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }

Expand All @@ -80,7 +97,10 @@ class TestEcosystemInformationCluster : public ::testing::Test
return locationInfo;
}

MockMatterContext & GetMockMatterContext() { return mMockMatterContext; }

private:
MockMatterContext mMockMatterContext;
Clusters::EcosystemInformation::EcosystemInformationServer mClusterServer;
};

Expand Down Expand Up @@ -265,6 +285,19 @@ TEST_F(TestEcosystemInformationCluster, AddDeviceInfo)
ASSERT_FALSE(iterator.Next());
}

TEST_F(TestEcosystemInformationCluster, AddDeviceInfoResultInMarkDirty)
{
std::unique_ptr<EcosystemDeviceStruct> deviceInfo = CreateSimplestValidDeviceStruct();
ASSERT_EQ(EcoInfoCluster().AddDeviceInfo(kValidEndpointId, std::move(deviceInfo)), CHIP_NO_ERROR);

auto markedDirtyList = GetMockMatterContext().GetDirtyList();
ASSERT_EQ(markedDirtyList.size(), 1u);
ConcreteAttributePath path = markedDirtyList[0];
ASSERT_EQ(path.mEndpointId, kValidEndpointId);
ASSERT_EQ(path.mClusterId, kEcosystemInfoClusterId);
ASSERT_EQ(path.mAttributeId, kDeviceDirectoryAttributeId);
}

TEST_F(TestEcosystemInformationCluster, BuildingEcosystemLocationStruct)
{
EcosystemLocationStruct::Builder locationInfoBuilder;
Expand Down Expand Up @@ -388,5 +421,21 @@ TEST_F(TestEcosystemInformationCluster, AddLocationInfo)
ASSERT_FALSE(iterator.Next());
}

TEST_F(TestEcosystemInformationCluster, AddLocationInfoResultInMarkDirty)
{
std::unique_ptr<EcosystemLocationStruct> locationInfo = CreateValidLocationStruct();
const char * kValidLocationIdStr = "SomeLocationIdString";
ASSERT_EQ(EcoInfoCluster().AddLocationInfo(kValidEndpointId, kValidLocationIdStr, Testing::kAdminSubjectDescriptor.fabricIndex,
std::move(locationInfo)),
CHIP_NO_ERROR);

auto markedDirtyList = GetMockMatterContext().GetDirtyList();
ASSERT_EQ(markedDirtyList.size(), 1u);
ConcreteAttributePath path = markedDirtyList[0];
ASSERT_EQ(path.mEndpointId, kValidEndpointId);
ASSERT_EQ(path.mClusterId, kEcosystemInfoClusterId);
ASSERT_EQ(path.mAttributeId, kLocationDirectoryAttributeId);
}

} // namespace app
} // namespace chip

0 comments on commit 5fe4409

Please sign in to comment.