From 1150d2587d14860ed108fab11ee6914e44711053 Mon Sep 17 00:00:00 2001 From: chrisdecenzo Date: Thu, 23 Jun 2022 17:28:19 -0700 Subject: [PATCH] Add featureflags to content app (dynamic) endpoints --- .../ContentLauncherManager.cpp | 15 ++++++++ .../content-launcher/ContentLauncherManager.h | 4 +++ .../content-launch-delegate.h | 4 +++ .../content-launch-server.cpp | 35 ++++++++++++------- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.cpp b/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.cpp index a56323156587ed..f80f24674ecc6b 100644 --- a/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.cpp +++ b/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.cpp @@ -17,6 +17,7 @@ */ #include "ContentLauncherManager.h" +#include using namespace std; using namespace chip::app; @@ -186,3 +187,17 @@ uint32_t ContentLauncherManager::HandleGetSupportedStreamingProtocols() ChipLogProgress(Zcl, "ContentLauncherManager::HandleGetSupportedStreamingProtocols"); return mSupportedStreamingProtocols; } + +uint32_t ContentLauncherManager::GetFeatureMap(chip::EndpointId endpoint) +{ + if (endpoint >= EMBER_AF_CONTENT_LAUNCH_CLUSTER_SERVER_ENDPOINT_COUNT) + { + return mDynamicEndpointFeatureMap; + } + else + { + uint32_t featureMap = 0; + Attributes::FeatureMap::Get(endpoint, &featureMap); + return featureMap; + } +} diff --git a/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.h b/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.h index 6033ac68275737..7073d89dd05c9e 100644 --- a/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.h +++ b/examples/tv-app/linux/include/content-launcher/ContentLauncherManager.h @@ -51,6 +51,8 @@ class ContentLauncherManager : public ContentLauncherDelegate CHIP_ERROR HandleGetAcceptHeaderList(AttributeValueEncoder & aEncoder) override; uint32_t HandleGetSupportedStreamingProtocols() override; + uint32_t GetFeatureMap(chip::EndpointId endpoint) override; + protected: std::list mAcceptHeaderList; uint32_t mSupportedStreamingProtocols; @@ -58,4 +60,6 @@ class ContentLauncherManager : public ContentLauncherDelegate private: EndpointId mEndpointId; + // TODO: set this based upon meta data from app + uint32_t mDynamicEndpointFeatureMap = 3; }; diff --git a/src/app/clusters/content-launch-server/content-launch-delegate.h b/src/app/clusters/content-launch-server/content-launch-delegate.h index 5fb6e02e5450e3..1cc40b07a0ef94 100644 --- a/src/app/clusters/content-launch-server/content-launch-delegate.h +++ b/src/app/clusters/content-launch-server/content-launch-delegate.h @@ -51,6 +51,10 @@ class Delegate virtual uint32_t HandleGetSupportedStreamingProtocols() = 0; + bool HasFeature(chip::EndpointId endpoint, ContentLauncherFeature feature); + + virtual uint32_t GetFeatureMap(chip::EndpointId endpoint) = 0; + virtual ~Delegate() = default; }; diff --git a/src/app/clusters/content-launch-server/content-launch-server.cpp b/src/app/clusters/content-launch-server/content-launch-server.cpp index 77224806dfda04..ae1f1ebdc211e3 100644 --- a/src/app/clusters/content-launch-server/content-launch-server.cpp +++ b/src/app/clusters/content-launch-server/content-launch-server.cpp @@ -120,18 +120,10 @@ void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate) } } -bool HasFeature(chip::EndpointId endpoint, ContentLauncherFeature feature) +bool Delegate::HasFeature(chip::EndpointId endpoint, ContentLauncherFeature feature) { - bool hasFeature = false; - uint32_t featureMap = 0; - - EmberAfStatus status = Attributes::FeatureMap::Get(endpoint, &featureMap); - if (EMBER_ZCL_STATUS_SUCCESS == status) - { - hasFeature = (featureMap & chip::to_underlying(feature)); - } - - return hasFeature; + uint32_t featureMap = GetFeatureMap(endpoint); + return (featureMap & chip::to_underlying(feature)); } } // namespace ContentLauncher @@ -154,6 +146,7 @@ class ContentLauncherAttrAccess : public app::AttributeAccessInterface private: CHIP_ERROR ReadAcceptHeaderAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); CHIP_ERROR ReadSupportedStreamingProtocolsAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate); + CHIP_ERROR ReadFeatureFlagAttribute(EndpointId endpoint, app::AttributeValueEncoder & aEncoder, Delegate * delegate); }; ContentLauncherAttrAccess gContentLauncherAttrAccess; @@ -181,6 +174,14 @@ CHIP_ERROR ContentLauncherAttrAccess::Read(const app::ConcreteReadAttributePath return ReadSupportedStreamingProtocolsAttribute(aEncoder, delegate); } + case app::Clusters::ContentLauncher::Attributes::FeatureMap::Id: + if (isDelegateNull(delegate, endpoint)) + { + return CHIP_NO_ERROR; + } + + return ReadFeatureFlagAttribute(endpoint, aEncoder, delegate); + default: { break; } @@ -189,6 +190,13 @@ CHIP_ERROR ContentLauncherAttrAccess::Read(const app::ConcreteReadAttributePath return CHIP_NO_ERROR; } +CHIP_ERROR ContentLauncherAttrAccess::ReadFeatureFlagAttribute(EndpointId endpoint, app::AttributeValueEncoder & aEncoder, + Delegate * delegate) +{ + uint32_t featureFlag = delegate->GetFeatureMap(endpoint); + return aEncoder.Encode(featureFlag); +} + CHIP_ERROR ContentLauncherAttrAccess::ReadAcceptHeaderAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate) { return delegate->HandleGetAcceptHeaderList(aEncoder); @@ -220,7 +228,8 @@ bool emberAfContentLauncherClusterLaunchContentCallback(CommandHandler * command Delegate * delegate = GetDelegate(endpoint); - VerifyOrExit(isDelegateNull(delegate, endpoint) != true && HasFeature(endpoint, ContentLauncherFeature::kContentSearch), + VerifyOrExit(isDelegateNull(delegate, endpoint) != true && + delegate->HasFeature(endpoint, ContentLauncherFeature::kContentSearch), err = CHIP_ERROR_INCORRECT_STATE); delegate->HandleLaunchContent(responder, decodableParameterList, autoplay, data.HasValue() ? data.Value() : CharSpan()); @@ -253,7 +262,7 @@ bool emberAfContentLauncherClusterLaunchURLCallback(CommandHandler * commandObj, app::CommandResponseHelper responder(commandObj, commandPath); Delegate * delegate = GetDelegate(endpoint); - VerifyOrExit(isDelegateNull(delegate, endpoint) != true && HasFeature(endpoint, ContentLauncherFeature::kURLPlayback), + VerifyOrExit(isDelegateNull(delegate, endpoint) != true && delegate->HasFeature(endpoint, ContentLauncherFeature::kURLPlayback), err = CHIP_ERROR_INCORRECT_STATE); { delegate->HandleLaunchUrl(responder, contentUrl, displayString.HasValue() ? displayString.Value() : CharSpan(),