Skip to content

Commit

Permalink
Add featureflags to content app (dynamic) endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdecenzo committed Jun 24, 2022
1 parent e284e43 commit 1150d25
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "ContentLauncherManager.h"
#include <app-common/zap-generated/attributes/Accessors.h>

using namespace std;
using namespace chip::app;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ class ContentLauncherManager : public ContentLauncherDelegate
CHIP_ERROR HandleGetAcceptHeaderList(AttributeValueEncoder & aEncoder) override;
uint32_t HandleGetSupportedStreamingProtocols() override;

uint32_t GetFeatureMap(chip::EndpointId endpoint) override;

protected:
std::list<std::string> mAcceptHeaderList;
uint32_t mSupportedStreamingProtocols;
std::vector<ContentEntry> mContentList;

private:
EndpointId mEndpointId;
// TODO: set this based upon meta data from app
uint32_t mDynamicEndpointFeatureMap = 3;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
35 changes: 22 additions & 13 deletions src/app/clusters/content-launch-server/content-launch-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -253,7 +262,7 @@ bool emberAfContentLauncherClusterLaunchURLCallback(CommandHandler * commandObj,
app::CommandResponseHelper<Commands::LaunchResponse::Type> 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(),
Expand Down

0 comments on commit 1150d25

Please sign in to comment.