Skip to content

Commit

Permalink
Create ember-compatibility-functions.h to represent what `ember-com…
Browse files Browse the repository at this point in the history
…patibility-functions.cpp` contains (#32623)

* Create a ember-compatibility-functions header to define what the cpp contains

* Fix includes of ember compatibility functions

* Fix lint

* Restyle

* Remove reporting.h since that actually declares what ember-compatibility-functions.cpp implements

* Revert "Remove reporting.h since that actually declares what ember-compatibility-functions.cpp implements"

This reverts commit 297f526.

* Move the reporting bits into reporting.cpp

* Restyle

* Remove some unused includes

* Add reporting.cpp to cmake builds

* Fix rpc builds with new includes

* Fix oven and java matter controller compilation

* Some additional minor comments for the dynamic dispatcher ... unfortunately deps seem a bit strict

* Restyle

* Add reporting.cpp to the list of know issues (it is the same as ember-compatibility-functions)

* Add reporting.cpp to xcode

* Fix darwin compile

* Remove extra comment based on code review

* Comment rephrase

---------

Co-authored-by: Andrei Litvin <andreilitvin@google.com>
  • Loading branch information
andy31415 and andreilitvin authored Mar 20, 2024
1 parent 907883f commit d338455
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 121 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ jobs:
--known-failure app/CommandSenderLegacyCallback.h \
--known-failure app/data-model/ListLargeSystemExtensions.h \
--known-failure app/ReadHandler.h \
--known-failure app/reporting/reporting.cpp \
--known-failure app/reporting/tests/MockReportScheduler.cpp \
--known-failure app/reporting/tests/MockReportScheduler.h \
--known-failure app/TestEventTriggerDelegate.h \
Expand All @@ -111,6 +112,7 @@ jobs:
--known-failure app/util/DataModelHandler.cpp \
--known-failure app/util/DataModelHandler.h \
--known-failure app/util/ember-compatibility-functions.cpp \
--known-failure app/util/ember-compatibility-functions.h \
--known-failure app/util/endpoint-config-api.h \
--known-failure app/util/generic-callbacks.h \
--known-failure app/util/generic-callback-stubs.cpp \
Expand Down
4 changes: 3 additions & 1 deletion examples/common/pigweed/rpc_services/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

#pragma once

#include "app/util/attribute-storage.h"
#include "attributes_service/attributes_service.rpc.pb.h"
#include "pigweed/rpc_services/internal/StatusUtils.h"

#include <app-common/zap-generated/attribute-type.h>
#include <app/InteractionModelEngine.h>
#include <app/MessageDef/AttributeReportIBs.h>
#include <app/util/attribute-storage.h>
#include <app/util/ember-compatibility-functions.h>
#include <lib/core/TLV.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVTypes.h>
Expand Down
7 changes: 7 additions & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ static_library("interaction-model") {
"reporting/ReportSchedulerImpl.h",
"reporting/SynchronizedReportSchedulerImpl.cpp",
"reporting/SynchronizedReportSchedulerImpl.h",

# TODO: reporting header is part of interaction-model, however actual implementation depends
# on generated code as subscriptions depend on attribute data versioning to determine
# when "data changed" reports should be sent.
#
# This breaks having `.h` and `.cpp` based off the same compilation unit and
# should ideally be cleaned up.
"reporting/reporting.h",
]

Expand Down
1 change: 1 addition & 0 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <app/AppConfig.h>
#include <app/RequiredPrivilege.h>
#include <app/util/af-types.h>
#include <app/util/ember-compatibility-functions.h>
#include <app/util/endpoint-config-api.h>
#include <lib/core/Global.h>
#include <lib/core/TLVUtilities.h>
Expand Down
64 changes: 0 additions & 64 deletions src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -678,76 +678,12 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, chip::TLV::TLVReader & aReader,
CommandHandler * apCommandObj);

/**
* Check whether the given cluster exists on the given endpoint and supports
* the given command. If it does, Success will be returned. If it does not,
* one of UnsupportedEndpoint, UnsupportedCluster, or UnsupportedCommand
* will be returned, depending on how the command fails to exist.
*/
Protocols::InteractionModel::Status ServerClusterCommandExists(const ConcreteCommandPath & aCommandPath);

/**
* Fetch attribute value and version info and write to the AttributeReport provided.
* The ReadSingleClusterData will do everything required for encoding an attribute, i.e. it will try to put one or more
* AttributeReportIB to the AttributeReportIBs::Builder.
* When the endpoint / cluster / attribute data specified by aPath does not exist, corresponding interaction
* model error code will be put into aAttributeReports, and CHIP_NO_ERROR will be returned. If the data exists on the server, the
* data (with tag kData) and the data version (with tag kDataVersion) will be put into aAttributeReports. TLVWriter error will be
* returned if any error occurred while encoding these values. This function is implemented by CHIP as a part of cluster data
* storage & management.
*
* @param[in] aSubjectDescriptor The subject descriptor for the read.
* @param[in] aPath The concrete path of the data being read.
* @param[in] aAttributeReports The TLV Builder for Cluter attribute builder.
*
* @retval CHIP_NO_ERROR on success
*/
CHIP_ERROR ReadSingleClusterData(const Access::SubjectDescriptor & aSubjectDescriptor, bool aIsFabricFiltered,
const ConcreteReadAttributePath & aPath, AttributeReportIBs::Builder & aAttributeReports,
AttributeValueEncoder::AttributeEncodeState * apEncoderState);

/**
* Check whether concrete attribute path is an "existent attribute path" in spec terms.
* @param[in] aPath The concrete path of the data being read.
* @retval boolean true if the concrete attribute path indicates an attribute that exists on the node.
*/
bool ConcreteAttributePathExists(const ConcreteAttributePath & aPath);

/**
* Get the registered attribute access override. nullptr when attribute access override is not found.
*
* TODO(#16806): This function and registerAttributeAccessOverride can be member functions of InteractionModelEngine.
*/
AttributeAccessInterface * GetAttributeAccessOverride(EndpointId aEndpointId, ClusterId aClusterId);

/**
* TODO: Document.
*/
CHIP_ERROR WriteSingleClusterData(const Access::SubjectDescriptor & aSubjectDescriptor,
const ConcreteDataAttributePath & aAttributePath, TLV::TLVReader & aReader,
WriteHandler * apWriteHandler);

/**
* Check if the given cluster has the given DataVersion.
*/
bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, DataVersion aRequiredVersion);

/**
* Returns true if device type is on endpoint, false otherwise.
*/
bool IsDeviceTypeOnEndpoint(DeviceTypeId deviceType, EndpointId endpoint);

/**
* Returns the metadata of the attribute for the given path.
*
* @retval The metadata of the attribute, will return null if the given attribute does not exists.
*/
const EmberAfAttributeMetadata * GetAttributeMetadata(const ConcreteAttributePath & aPath);

/**
* Returns the event support status for the given event, as an interaction model status.
*/
Protocols::InteractionModel::Status CheckEventSupportStatus(const ConcreteEventPath & aPath);

} // namespace app
} // namespace chip
1 change: 1 addition & 0 deletions src/app/WriteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <app/WriteHandler.h>
#include <app/reporting/Engine.h>
#include <app/util/MatterCallbacks.h>
#include <app/util/ember-compatibility-functions.h>
#include <credentials/GroupDataProvider.h>
#include <lib/support/TypeTraits.h>

Expand Down
1 change: 1 addition & 0 deletions src/app/chip_data_model.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function(chip_configure_data_model APP_TARGET)
target_sources(${APP_TARGET} ${SCOPE}
${CHIP_APP_BASE_DIR}/../../zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp
${CHIP_APP_BASE_DIR}/../../zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp
${CHIP_APP_BASE_DIR}/reporting/reporting.cpp
${CHIP_APP_BASE_DIR}/util/attribute-storage.cpp
${CHIP_APP_BASE_DIR}/util/attribute-table.cpp
${CHIP_APP_BASE_DIR}/util/binding-table.cpp
Expand Down
1 change: 1 addition & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ template("chip_data_model") {

if (!chip_build_controller_dynamic_server) {
sources += [
"${_app_root}/reporting/reporting.cpp",
"${_app_root}/util/DataModelHandler.cpp",
"${_app_root}/util/attribute-storage.cpp",
"${_app_root}/util/attribute-table.cpp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <app/clusters/mode-base-server/mode-base-server.h>
#include <app/reporting/reporting.h>
#include <app/util/attribute-storage.h>
#include <app/util/ember-compatibility-functions.h>

using namespace chip;
using namespace chip::app;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <app/InteractionModelEngine.h>
#include <app/util/attribute-storage.h>
#include <app/util/config.h>
#include <app/util/ember-compatibility-functions.h>

using namespace chip;
using namespace chip::app;
Expand Down
5 changes: 5 additions & 0 deletions src/app/dynamic_server/AccessControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include <lib/core/CHIPError.h>
#include <lib/core/Global.h>

// TODO: this include is unclear as dynamic server should NOT link those.
// we should probably have some separate includes here for dynamic
// server
#include <app/util/ember-compatibility-functions.h>

using namespace chip;
using namespace chip::Access;
using namespace chip::app::Clusters;
Expand Down
1 change: 1 addition & 0 deletions src/app/dynamic_server/DynamicDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <app/util/ember-compatibility-functions.h>

#include <access/SubjectDescriptor.h>
#include <app-common/zap-generated/callback.h>
Expand Down
1 change: 1 addition & 0 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <app/RequiredPrivilege.h>
#include <app/reporting/Engine.h>
#include <app/util/MatterCallbacks.h>
#include <app/util/ember-compatibility-functions.h>

using namespace chip::Access;

Expand Down
79 changes: 79 additions & 0 deletions src/app/reporting/reporting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "reporting.h"

#include <app/AttributePathParams.h>
#include <app/InteractionModelEngine.h>
#include <app/util/af.h>
#include <platform/LockTracker.h>

using namespace chip;
using namespace chip::app;

namespace {

void IncreaseClusterDataVersion(const ConcreteClusterPath & aConcreteClusterPath)
{
DataVersion * version = emberAfDataVersionStorage(aConcreteClusterPath);
if (version == nullptr)
{
ChipLogError(DataManagement, "Endpoint %x, Cluster " ChipLogFormatMEI " not found in IncreaseClusterDataVersion!",
aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId));
}
else
{
(*(version))++;
ChipLogDetail(DataManagement, "Endpoint %x, Cluster " ChipLogFormatMEI " update version to %" PRIx32,
aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId), *(version));
}
}

} // namespace

void MatterReportingAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId)
{
// Attribute writes have asserted this already, but this assert should catch
// applications notifying about changes from their end.
assertChipStackLockedByCurrentThread();

AttributePathParams info;
info.mClusterId = clusterId;
info.mAttributeId = attributeId;
info.mEndpointId = endpoint;

IncreaseClusterDataVersion(ConcreteClusterPath(endpoint, clusterId));
InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(info);
}

void MatterReportingAttributeChangeCallback(const ConcreteAttributePath & aPath)
{
return MatterReportingAttributeChangeCallback(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId);
}

void MatterReportingAttributeChangeCallback(EndpointId endpoint)
{
// Attribute writes have asserted this already, but this assert should catch
// applications notifying about changes from their end.
assertChipStackLockedByCurrentThread();

AttributePathParams info;
info.mEndpointId = endpoint;

// We are adding or enabling a whole endpoint, in this case, we do not touch the cluster data version.

InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(info);
}
1 change: 1 addition & 0 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <app/server/Dnssd.h>
#include <app/server/EchoHandler.h>
#include <app/util/DataModelHandler.h>
#include <app/util/ember-compatibility-functions.h>

#if CONFIG_NETWORK_LAYER_BLE
#include <ble/BLEEndPoint.h>
Expand Down
57 changes: 1 addition & 56 deletions src/app/util/ember-compatibility-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* Contains the functions for compatibility with ember ZCL inner state
* when calling ember callbacks.
*/
#include <app/util/ember-compatibility-functions.h>

#include <access/AccessControl.h>
#include <app/CommandHandlerInterface.h>
Expand Down Expand Up @@ -272,22 +267,6 @@ CHIP_ERROR ReadClusterDataVersion(const ConcreteClusterPath & aConcreteClusterPa
return CHIP_NO_ERROR;
}

void IncreaseClusterDataVersion(const ConcreteClusterPath & aConcreteClusterPath)
{
DataVersion * version = emberAfDataVersionStorage(aConcreteClusterPath);
if (version == nullptr)
{
ChipLogError(DataManagement, "Endpoint %x, Cluster " ChipLogFormatMEI " not found in IncreaseClusterDataVersion!",
aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId));
}
else
{
(*(version))++;
ChipLogDetail(DataManagement, "Endpoint %x, Cluster " ChipLogFormatMEI " update version to %" PRIx32,
aConcreteClusterPath.mEndpointId, ChipLogValueMEI(aConcreteClusterPath.mClusterId), *(version));
}
}

CHIP_ERROR SendSuccessStatus(AttributeReportIB::Builder & aAttributeReport, AttributeDataIB::Builder & aAttributeDataIBBuilder)
{
ReturnErrorOnFailure(aAttributeDataIBBuilder.EndOfAttributeDataIB());
Expand Down Expand Up @@ -1123,37 +1102,3 @@ Protocols::InteractionModel::Status CheckEventSupportStatus(const ConcreteEventP

} // namespace app
} // namespace chip

void MatterReportingAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId)
{
// Attribute writes have asserted this already, but this assert should catch
// applications notifying about changes from their end.
assertChipStackLockedByCurrentThread();

AttributePathParams info;
info.mClusterId = clusterId;
info.mAttributeId = attributeId;
info.mEndpointId = endpoint;

IncreaseClusterDataVersion(ConcreteClusterPath(endpoint, clusterId));
InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(info);
}

void MatterReportingAttributeChangeCallback(const ConcreteAttributePath & aPath)
{
return MatterReportingAttributeChangeCallback(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId);
}

void MatterReportingAttributeChangeCallback(EndpointId endpoint)
{
// Attribute writes have asserted this already, but this assert should catch
// applications notifying about changes from their end.
assertChipStackLockedByCurrentThread();

AttributePathParams info;
info.mEndpointId = endpoint;

// We are adding or enabling a whole endpoint, in this case, we do not touch the cluster data version.

InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(info);
}
Loading

0 comments on commit d338455

Please sign in to comment.