From 282be700c255d07eb0e5e37d74e5489a9a501866 Mon Sep 17 00:00:00 2001 From: erwinpan1 Date: Tue, 20 Aug 2024 21:42:45 +0800 Subject: [PATCH] Not writing the MediaInput cluster through RPC --- .../common/pigweed/rpc_services/Attributes.h | 63 ------------------- .../media-input-server/media-input-server.cpp | 25 -------- 2 files changed, 88 deletions(-) diff --git a/examples/common/pigweed/rpc_services/Attributes.h b/examples/common/pigweed/rpc_services/Attributes.h index 4fc1baef1ed8a5..d89522964d97a1 100644 --- a/examples/common/pigweed/rpc_services/Attributes.h +++ b/examples/common/pigweed/rpc_services/Attributes.h @@ -22,10 +22,8 @@ #include "pigweed/rpc_services/internal/StatusUtils.h" #include -#include #include #include -#include #include #include #include @@ -44,99 +42,38 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service ::pw::Status Write(const chip_rpc_AttributeWrite & request, pw_protobuf_Empty & response) { const void * data; - size_t data_len = 0; DeviceLayer::StackLock lock; switch (request.data.which_data) { case chip_rpc_AttributeData_data_bool_tag: data = &request.data.data.data_bool; - data_len = sizeof(request.data.data.data_bool); break; case chip_rpc_AttributeData_data_uint8_tag: data = &request.data.data.data_uint8; - data_len = sizeof(request.data.data.data_uint8); break; case chip_rpc_AttributeData_data_uint16_tag: data = &request.data.data.data_uint16; - data_len = sizeof(request.data.data.data_uint16); break; case chip_rpc_AttributeData_data_uint32_tag: data = &request.data.data.data_uint32; - data_len = sizeof(request.data.data.data_uint32); break; case chip_rpc_AttributeData_data_int8_tag: data = &request.data.data.data_int8; - data_len = sizeof(request.data.data.data_int8); break; case chip_rpc_AttributeData_data_int16_tag: data = &request.data.data.data_int16; - data_len = sizeof(request.data.data.data_int16); break; case chip_rpc_AttributeData_data_int32_tag: data = &request.data.data.data_int32; - data_len = sizeof(request.data.data.data_int32); break; case chip_rpc_AttributeData_data_bytes_tag: data = &request.data.data.data_bytes; - data_len = sizeof(request.data.data.data_bytes); break; default: return pw::Status::InvalidArgument(); } -#if 1 // Refering Duplicate WriteSingleClusterData to calling AttributeInterface when available - if (data_len == 0) { - ChipLogError(Zcl, "Invalid writing to PW RPC with data length: 0"); - return pw::Status::InvalidArgument(); - } - if (auto * attrOverride = chip::app::GetAttributeAccessOverride(request.metadata.endpoint, request.metadata.cluster)) - { - Access::SubjectDescriptor aSubjectDescriptor{ .authMode = chip::Access::AuthMode::kPase }; - app::ConcreteDataAttributePath aPath(request.metadata.endpoint, request.metadata.cluster, request.metadata.attribute_id); - - uint8_t tlvBuffer[128] = { 0 }; - uint8_t value = *(static_cast(data)); - - TLV::TLVReader aReader; - - TLV::TLVType outerContainerType; - TLV::TLVWriter writer; - writer.Init(tlvBuffer); - writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, outerContainerType); - writer.Put(TLV::AnonymousTag(), value); - writer.EndContainer(outerContainerType); - writer.Finalize(); - - aReader.Init(tlvBuffer); - app::AttributeValueDecoder valueDecoder(aReader, aSubjectDescriptor); - -#if 1 // Test Decode - app::DataModel::Nullable nullableValue; - - CHIP_ERROR err = valueDecoder.Decode(nullableValue); - if (CHIP_NO_ERROR != err) { - ChipLogError(Zcl, "Invalid writing to PW RPC due to data decoding failed"); - return pw::Status::InvalidArgument(); - } - - if (nullableValue.IsNull()) { - ChipLogError(Zcl, "Invalid writing to PW RPC with null data"); - return pw::Status::InvalidArgument(); - } - - ChipLogError(Zcl, "Writing to PW RPC with data: %u", nullableValue.Value()); -#endif - - PW_TRY(ChipErrorToPwStatus(attrOverride->Write(aPath, valueDecoder))); - - if (valueDecoder.TriedDecode()) // TBD - { - MatterReportingAttributeChangeCallback(aPath); - return pw::OkStatus(); - } - } -#endif RETURN_STATUS_IF_NOT_OK( emberAfWriteAttribute(request.metadata.endpoint, request.metadata.cluster, request.metadata.attribute_id, const_cast(static_cast(data)), request.metadata.type)); diff --git a/src/app/clusters/media-input-server/media-input-server.cpp b/src/app/clusters/media-input-server/media-input-server.cpp index bfc2fa98b423d7..67961ecc1c165d 100644 --- a/src/app/clusters/media-input-server/media-input-server.cpp +++ b/src/app/clusters/media-input-server/media-input-server.cpp @@ -126,7 +126,6 @@ class MediaInputAttrAccess : public app::AttributeAccessInterface MediaInputAttrAccess() : app::AttributeAccessInterface(Optional::Missing(), chip::app::Clusters::MediaInput::Id) {} CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override; - CHIP_ERROR Write(const app::ConcreteDataAttributePath & aPath, app::AttributeValueDecoder & aDecoder) override; private: CHIP_ERROR ReadInputListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); @@ -166,30 +165,6 @@ CHIP_ERROR MediaInputAttrAccess::Read(const app::ConcreteReadAttributePath & aPa return CHIP_NO_ERROR; } -CHIP_ERROR WriteCurrentInput(EndpointId endpoint, uint8_t newInput) -{ - Delegate * delegate = GetDelegate(endpoint); - VerifyOrReturnError(!isDelegateNull(delegate, endpoint), CHIP_ERROR_INTERNAL); - - return delegate->HandleSetCurrentInput(newInput) ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL; -} - -CHIP_ERROR MediaInputAttrAccess::Write(const app::ConcreteDataAttributePath & aPath, app::AttributeValueDecoder & aDecoder) -{ - app::DataModel::Nullable nullableValue; - ReturnErrorOnFailure(aDecoder.Decode(nullableValue)); - VerifyOrReturnError(!nullableValue.IsNull(), CHIP_ERROR_INVALID_ARGUMENT); - - switch (aPath.mAttributeId) - { - case app::Clusters::MediaInput::Attributes::CurrentInput::Id: - return WriteCurrentInput(aPath.mEndpointId, nullableValue.Value()); - } - - ChipLogError(Zcl, "Unsupport MediaInput cluster attribute write %u", aPath.mAttributeId); - return CHIP_ERROR_INTERNAL; -} - CHIP_ERROR MediaInputAttrAccess::ReadInputListAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) { return delegate->HandleGetInputList(aEncoder);