Skip to content

Commit

Permalink
Updated code per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarkov committed Dec 15, 2021
1 parent 673d019 commit cc7d4db
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14476,7 +14476,7 @@
],
"attributes": [
{
"name": "accepts header list",
"name": "accept header list",
"code": 0,
"mfgCode": null,
"side": "server",
Expand Down
10 changes: 0 additions & 10 deletions examples/all-clusters-app/linux/include/tv-callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,3 @@ bool lowPowerClusterSleep()
{
return true;
}

uint32_t contentLauncherClusterGetSupportedStreamingProtocols()
{
return 0;
}

std::list<std::string> contentLauncherClusterGetAcceptsHeaderList()
{
return { "example", "example" };
}
2 changes: 1 addition & 1 deletion examples/thermostat/thermostat-common/thermostat.zap
Original file line number Diff line number Diff line change
Expand Up @@ -13136,7 +13136,7 @@
],
"attributes": [
{
"name": "accepts header list",
"name": "accept header list",
"code": 0,
"mfgCode": null,
"side": "server",
Expand Down
23 changes: 12 additions & 11 deletions examples/tv-app/android/java/ContentLauncherManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ using namespace chip;
ContentLauncherManager ContentLauncherManager::sInstance;

ContentLaunchResponse ContentLauncherManager::HandleLaunchContent(chip::EndpointId endpointId,
std::list<ContentLaunchParamater> parameterList, bool autoplay,
const std::list<ContentLaunchParamater> & parameterList,
bool autoplay,
const chip::CharSpan & data)
{
ContentLaunchResponse response;
Expand Down Expand Up @@ -102,7 +103,7 @@ ContentLaunchResponse ContentLauncherManager::HandleLaunchContent(chip::Endpoint

ContentLaunchResponse ContentLauncherManager::HandleLaunchUrl(const chip::CharSpan & contentUrl,
const chip::CharSpan & displayString,
ContentLaunchBrandingInformation & brandingInformation)
const ContentLaunchBrandingInformation & brandingInformation)
{
ContentLaunchResponse response;
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -156,23 +157,23 @@ ContentLaunchResponse ContentLauncherManager::HandleLaunchUrl(const chip::CharSp
return response;
}

std::list<std::string> ContentLauncherManager::HandleGetAcceptsHeaderList()
std::list<std::string> ContentLauncherManager::HandleGetAcceptHeaderList()
{
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
std::list<std::string> acceptedHeadersList;

ChipLogProgress(Zcl, "Received ContentLauncherManager::GetAcceptsHeader");
ChipLogProgress(Zcl, "Received ContentLauncherManager::GetAcceptHeader");
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetAcceptsHeaderMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetAcceptHeaderMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

{
jobjectArray acceptedHeadersArray =
(jobjectArray) env->CallObjectMethod(mContentLauncherManagerObject, mGetAcceptsHeaderMethod);
(jobjectArray) env->CallObjectMethod(mContentLauncherManagerObject, mGetAcceptHeaderMethod);
if (env->ExceptionCheck())
{
ChipLogError(Zcl, "Java exception in ContentLauncherManager::GetAcceptsHeader");
ChipLogError(Zcl, "Java exception in ContentLauncherManager::GetAcceptHeader");
env->ExceptionDescribe();
env->ExceptionClear();
err = CHIP_ERROR_INCORRECT_STATE;
Expand All @@ -193,7 +194,7 @@ std::list<std::string> ContentLauncherManager::HandleGetAcceptsHeaderList()
exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "ContentLauncherManager::GetAcceptsHeader status error: %s", err.AsString());
ChipLogError(Zcl, "ContentLauncherManager::GetAcceptHeader status error: %s", err.AsString());
}

return acceptedHeadersList;
Expand All @@ -216,7 +217,7 @@ uint32_t ContentLauncherManager::HandleGetSupportedStreamingProtocols()
supportedStreamingProtocols = (uint32_t) jSupportedStreamingProtocols;
if (env->ExceptionCheck())
{
ChipLogError(Zcl, "Java exception in ContentLauncherManager::GetAcceptsHeader");
ChipLogError(Zcl, "Java exception in ContentLauncherManager::GetAcceptHeader");
env->ExceptionDescribe();
env->ExceptionClear();
err = CHIP_ERROR_INCORRECT_STATE;
Expand Down Expand Up @@ -244,8 +245,8 @@ void ContentLauncherManager::InitializeWithObjects(jobject managerObject)
jclass ContentLauncherClass = env->GetObjectClass(managerObject);
VerifyOrReturn(ContentLauncherClass != nullptr, ChipLogError(Zcl, "Failed to get ContentLauncherManager Java class"));

mGetAcceptsHeaderMethod = env->GetMethodID(ContentLauncherClass, "getAcceptsHeader", "()[Ljava/lang/String;");
if (mGetAcceptsHeaderMethod == nullptr)
mGetAcceptHeaderMethod = env->GetMethodID(ContentLauncherClass, "getAcceptHeader", "()[Ljava/lang/String;");
if (mGetAcceptHeaderMethod == nullptr)
{
ChipLogError(Zcl, "Failed to access MediaInputManager 'getInputList' method");
env->ExceptionClear();
Expand Down
8 changes: 4 additions & 4 deletions examples/tv-app/android/java/ContentLauncherManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ class ContentLauncherManager : public chip::app::Clusters::ContentLauncher::Dele
public:
void InitializeWithObjects(jobject managerObject);

ContentLaunchResponse HandleLaunchContent(chip::EndpointId endpointId, std::list<ContentLaunchParamater> parameterList,
ContentLaunchResponse HandleLaunchContent(chip::EndpointId endpointId, const std::list<ContentLaunchParamater> & parameterList,
bool autoplay, const chip::CharSpan & data) override;
ContentLaunchResponse HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString,
ContentLaunchBrandingInformation & brandingInformation) override;
std::list<std::string> HandleGetAcceptsHeaderList() override;
const std::list<ContentLaunchBrandingInformation> & brandingInformation) override;
std::list<std::string> HandleGetAcceptHeaderList() override;
uint32_t HandleGetSupportedStreamingProtocols() override;

private:
friend ContentLauncherManager & ContentLauncherMgr();

static ContentLauncherManager sInstance;
jobject mContentLauncherManagerObject = nullptr;
jmethodID mGetAcceptsHeaderMethod = nullptr;
jmethodID mGetAcceptHeaderMethod = nullptr;
jmethodID mGetSupportedStreamingProtocolsMethod = nullptr;
jmethodID mLaunchContentMethod = nullptr;
jmethodID mLaunchUrlMethod = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public interface ContentLaunchManager {
* @return The list of content types supported by the Video Player or Content App in the form of
* entries in the HTTP "Accept" request header.
*/
String[] getAcceptsHeader();
String[] getAcceptHeader();

/** @return The list information about supported streaming protocols in STREAMING_TYPE_XXX. */
int[] getSupportedStreamingTypes();
int[] getSupportedStreamingProtocols();

/**
* Launch the specified content with optional search criteria.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ContentLaunchManagerStub implements ContentLaunchManager {
private final String TAG = ContentLaunchManagerStub.class.getSimpleName();

@Override
public String[] getAcceptsHeader() {
public String[] getAcceptHeader() {
String[] headers =
new String[] {
"application/dash+xml", "application/vnd.apple.mpegurl", "text/html",
Expand All @@ -17,7 +17,7 @@ public String[] getAcceptsHeader() {
}

@Override
public int[] getSupportedStreamingTypes() {
public int[] getSupportedStreamingProtocols() {
int[] types = new int[] {STREAMING_TYPE_DASH, STREAMING_TYPE_HLS};
return types;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tv-app/linux/AppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();

// Declare Content Launcher cluster attributes
DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(contentLauncherAttrs)
DECLARE_DYNAMIC_ATTRIBUTE(ZCL_CONTENT_LAUNCHER_ACCEPTS_HEADER_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize,
DECLARE_DYNAMIC_ATTRIBUTE(ZCL_CONTENT_LAUNCHER_ACCEPT_HEADER_ATTRIBUTE_ID, ARRAY, kDescriptorAttributeArraySize,
0), /* accept header list */
DECLARE_DYNAMIC_ATTRIBUTE(ZCL_CONTENT_LAUNCHER_SUPPORTED_STREAMING_PROTOCOLS_ATTRIBUTE_ID, BITMAP32, 1,
0), /* streaming protocols */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using namespace std;
using namespace chip::AppPlatform;

ContentLaunchResponse ContentLauncherManager::HandleLaunchContent(chip::EndpointId endpointId,
std::list<ContentLaunchParamater> parameterList, bool autoplay,
const std::list<ContentLaunchParamater> & parameterList, bool autoplay,
const chip::CharSpan & data)
{
ChipLogProgress(Zcl, "ContentLauncherManager::HandleLaunchContent ");
Expand All @@ -63,7 +63,7 @@ ContentLaunchResponse ContentLauncherManager::HandleLaunchContent(chip::Endpoint

ContentLaunchResponse ContentLauncherManager::HandleLaunchUrl(const chip::CharSpan & contentUrl,
const chip::CharSpan & displayString,
ContentLaunchBrandingInformation & brandingInformation)
const std::list<ContentLaunchBrandingInformation> & brandingInformation)
{
ChipLogProgress(Zcl, "ContentLauncherManager::HandleLaunchUrl");

Expand All @@ -78,9 +78,9 @@ ContentLaunchResponse ContentLauncherManager::HandleLaunchUrl(const chip::CharSp
return response;
}

std::list<std::string> ContentLauncherManager::HandleGetAcceptsHeaderList()
std::list<std::string> ContentLauncherManager::HandleGetAcceptHeaderList()
{
ChipLogProgress(Zcl, "ContentLauncherManager::HandleGetAcceptsHeaderList");
ChipLogProgress(Zcl, "ContentLauncherManager::HandleGetAcceptHeaderList");
return { "example", "example" };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
class ContentLauncherManager : public chip::app::Clusters::ContentLauncher::Delegate
{
public:
ContentLaunchResponse HandleLaunchContent(chip::EndpointId endpointId, std::list<ContentLaunchParamater> parameterList,
ContentLaunchResponse HandleLaunchContent(chip::EndpointId endpointId, const std::list<ContentLaunchParamater> & parameterList,
bool autoplay, const chip::CharSpan & data) override;
ContentLaunchResponse HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString,
ContentLaunchBrandingInformation & brandingInformation) override;
std::list<std::string> HandleGetAcceptsHeaderList() override;
const std::list<ContentLaunchBrandingInformation> & brandingInformation) override;
std::list<std::string> HandleGetAcceptHeaderList() override;
uint32_t HandleGetSupportedStreamingProtocols() override;
};
6 changes: 3 additions & 3 deletions examples/tv-app/tv-common/tv-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -7491,7 +7491,7 @@
],
"attributes": [
{
"name": "accepts header list",
"name": "accept header list",
"code": 0,
"mfgCode": null,
"side": "server",
Expand Down Expand Up @@ -9209,7 +9209,7 @@
],
"attributes": [
{
"name": "accepts header list",
"name": "accept header list",
"code": 0,
"mfgCode": null,
"side": "server",
Expand Down Expand Up @@ -9697,7 +9697,7 @@
],
"attributes": [
{
"name": "accepts header list",
"name": "accept header list",
"code": 0,
"mfgCode": null,
"side": "server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12542,7 +12542,7 @@
],
"attributes": [
{
"name": "accepts header list",
"name": "accept header list",
"code": 0,
"mfgCode": null,
"side": "server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ namespace ContentLauncher {
class Delegate
{
public:
virtual ContentLaunchResponse HandleLaunchContent(chip::EndpointId endpointId, std::list<ContentLaunchParamater> parameterList,
virtual ContentLaunchResponse HandleLaunchContent(chip::EndpointId endpointId, const std::list<ContentLaunchParamater> & parameterList,
bool autoplay, const chip::CharSpan & data) = 0;

virtual ContentLaunchResponse HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString,
ContentLaunchBrandingInformation & brandingInformation) = 0;
const std::list<ContentLaunchBrandingInformation> & brandingInformation) = 0;

virtual std::list<std::string> HandleGetAcceptsHeaderList() = 0;
virtual std::list<std::string> HandleGetAcceptHeaderList() = 0;

virtual uint32_t HandleGetSupportedStreamingProtocols() = 0;

Expand Down
44 changes: 25 additions & 19 deletions src/app/clusters/content-launch-server/content-launch-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ Delegate * GetDelegate(EndpointId endpoint)
return (ep == 0xFFFF ? NULL : gDelegateTable[ep]);
}

bool SendStatusIfDelegateNull(EndpointId endpoint)
bool SendStatusIfDelegateNull(Delegate * delegate, EndpointId endpoint)
{
if (GetDelegate(endpoint) == nullptr)
if (delegate == nullptr)
{
ChipLogError(Zcl, "No ContentLauncher Delegate set for ep:%" PRIu16, endpoint);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_UNSUP_COMMAND);
Expand Down Expand Up @@ -119,7 +119,7 @@ class ContentLauncherAttrAccess : public app::AttributeAccessInterface
CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override;

private:
CHIP_ERROR ReadAcceptsHeaderAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate);
CHIP_ERROR ReadAcceptHeaderAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate);
CHIP_ERROR ReadSupportedStreamingProtocols(app::AttributeValueEncoder & aEncoder, Delegate * delegate);
};

Expand All @@ -129,15 +129,15 @@ CHIP_ERROR ContentLauncherAttrAccess::Read(const app::ConcreteReadAttributePath
{
EndpointId endpoint = aPath.mEndpointId;
Delegate * delegate = GetDelegate(endpoint);
if (SendStatusIfDelegateNull(endpoint))
if (SendStatusIfDelegateNull(delegate, endpoint))
{
return CHIP_NO_ERROR;
}

switch (aPath.mAttributeId)
{
case app::Clusters::ContentLauncher::Attributes::AcceptsHeaderList::Id: {
return ReadAcceptsHeaderAttribute(aEncoder, delegate);
case app::Clusters::ContentLauncher::Attributes::AcceptHeaderList::Id: {
return ReadAcceptHeaderAttribute(aEncoder, delegate);
}
case app::Clusters::ContentLauncher::Attributes::SupportedStreamingProtocols::Id: {
return ReadSupportedStreamingProtocols(aEncoder, delegate);
Expand All @@ -149,13 +149,13 @@ CHIP_ERROR ContentLauncherAttrAccess::Read(const app::ConcreteReadAttributePath
return CHIP_NO_ERROR;
}

CHIP_ERROR ContentLauncherAttrAccess::ReadAcceptsHeaderAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate)
CHIP_ERROR ContentLauncherAttrAccess::ReadAcceptHeaderAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate)
{
std::list<std::string> acceptsHeaderList = delegate->HandleGetAcceptsHeaderList();
return aEncoder.EncodeList([acceptsHeaderList](const auto & encoder) -> CHIP_ERROR {
for (std::string acceptedHeader : acceptsHeaderList)
std::list<std::string> acceptHeaderList = delegate->HandleGetAcceptHeaderList();
return aEncoder.EncodeList([acceptHeaderList](const auto & encoder) -> CHIP_ERROR {
for (const auto & acceptedHeader : acceptHeaderList)
{
CharSpan span(acceptedHeader.c_str(), strlen(acceptedHeader.c_str()));
CharSpan span(acceptedHeader.c_str(), acceptedHeader.length());
ReturnErrorOnFailure(encoder.Encode(span));
}
return CHIP_NO_ERROR;
Expand All @@ -181,12 +181,14 @@ bool emberAfContentLauncherClusterLaunchContentCallback(
chip::app::Clusters::ContentLauncher::Commands::LaunchContentResponse::Type response;
EndpointId endpoint = commandPath.mEndpointId;

auto & autoplay = commandData.autoPlay;
auto & data = commandData.data;
auto & autoplay = commandData.autoPlay;
auto & data = commandData.data;
// TODO: Decode the paramater and pass it to delegate
// auto searchIterator = commandData.search.begin();
std::list<ContentLaunchParamater> parameterList;

Delegate * delegate = GetDelegate(endpoint);
if (SendStatusIfDelegateNull(endpoint))
if (SendStatusIfDelegateNull(delegate, endpoint))
{
return true;
}
Expand Down Expand Up @@ -219,17 +221,21 @@ bool emberAfContentLauncherClusterLaunchURLCallback(
chip::app::Clusters::ContentLauncher::Commands::LaunchURLResponse::Type response;
EndpointId endpoint = commandPath.mEndpointId;

auto & contentUrl = commandData.contentURL;
auto & displayString = commandData.displayString;
ContentLaunchBrandingInformation brandingInformation;

auto & contentUrl = commandData.contentURL;
auto & displayString = commandData.displayString;
// TODO: Decode the paramater and pass it to delegate
// auto brandingInformationIterator = commandData.brandingInformation.begin();
std::list<ContentLaunchBrandingInformation> brandingInformationList;


Delegate * delegate = GetDelegate(endpoint);
if (SendStatusIfDelegateNull(endpoint))
if (SendStatusIfDelegateNull(delegate, endpoint))
{
return true;
}

ContentLaunchResponse resp = delegate->HandleLaunchUrl(contentUrl, displayString, brandingInformation);
ContentLaunchResponse resp = delegate->HandleLaunchUrl(contentUrl, displayString, brandingInformationList);
VerifyOrExit(resp.err == CHIP_NO_ERROR, err = resp.err);

response.contentLaunchStatus = resp.status;
Expand Down
4 changes: 2 additions & 2 deletions src/app/tests/suites/TV_ContentLauncherCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ tests:
cluster: "DelayCommands"
command: "WaitForCommissionee"

- label: "Read attribute accepts header list"
- label: "Read attribute accept header list"
command: "readAttribute"
attribute: "accepts header list"
attribute: "accept header list"
response:
value: ["example", "example"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ limitations under the License.
<!-- TODO: Add feature map once it is supported -->
<description>This cluster provides an interface for launching content on a media player device such as a TV or Speaker.</description>

<attribute side="server" code="0x0000" define="CONTENT_LAUNCHER_ACCEPTS_HEADER" type="ARRAY" entryType="CHAR_STRING" length="254" writable="false" optional="false">accepts header list</attribute>
<attribute side="server" code="0x0000" define="CONTENT_LAUNCHER_ACCEPT_HEADER" type="ARRAY" entryType="CHAR_STRING" length="254" writable="false" optional="false">accept header list</attribute>
<attribute side="server" code="0x0001" define="CONTENT_LAUNCHER_SUPPORTED_STREAMING_PROTOCOLS" type="BITMAP32" writable="true" optional="false">supported streaming protocols</attribute>

<command source="client" code="0x00" name="LaunchContent" optional="false">
Expand Down
Loading

0 comments on commit cc7d4db

Please sign in to comment.