From 048671d1aa137b068fd27ad5702023fadae8c086 Mon Sep 17 00:00:00 2001 From: Sharad Binjola Date: Tue, 12 Dec 2023 14:44:02 -0800 Subject: [PATCH] Initial code for LaunchURL --- .../tv-casting-app/tv-casting-common/BUILD.gn | 1 + .../clusters/ContentLauncherCluster.cpp | 53 +++++++++++++++++++ .../clusters/ContentLauncherCluster.h | 5 +- .../tv-casting-common/core/CastingPlayer.h | 5 ++ .../tv-casting-common/core/Cluster.h | 5 +- .../tv-casting-common/core/Endpoint.h | 5 +- .../support/EndpointListLoader.h | 19 +++---- .../support/MediaClusterBase.h | 41 ++++++++++++++ 8 files changed, 111 insertions(+), 23 deletions(-) create mode 100644 examples/tv-casting-app/tv-casting-common/clusters/ContentLauncherCluster.cpp create mode 100644 examples/tv-casting-app/tv-casting-common/support/MediaClusterBase.h diff --git a/examples/tv-casting-app/tv-casting-common/BUILD.gn b/examples/tv-casting-app/tv-casting-common/BUILD.gn index 39c997b4b41180..ee7963ec042a1f 100644 --- a/examples/tv-casting-app/tv-casting-common/BUILD.gn +++ b/examples/tv-casting-app/tv-casting-common/BUILD.gn @@ -93,6 +93,7 @@ chip_data_model("tv-casting-common") { # Add simplified casting API files here sources += [ + "clusters/ContentLauncherCluster.cpp", "clusters/ContentLauncherCluster.h", "clusters/MediaPlaybackCluster.h", "clusters/TargetNavigatorCluster.h", diff --git a/examples/tv-casting-app/tv-casting-common/clusters/ContentLauncherCluster.cpp b/examples/tv-casting-app/tv-casting-common/clusters/ContentLauncherCluster.cpp new file mode 100644 index 00000000000000..2e91477fd85be7 --- /dev/null +++ b/examples/tv-casting-app/tv-casting-common/clusters/ContentLauncherCluster.cpp @@ -0,0 +1,53 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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 "ContentLauncherCluster.h" + +namespace matter { +namespace casting { +namespace clusters { + +CHIP_ERROR ContentLauncherCluster::LaunchURL(const char * contentUrl, const char * contentDisplayStr, + chip::Optional brandingInformation) +{ + memory::Strong endpoint = this->GetEndpoint().lock(); + + if(endpoint) + { + endpoint->GetCastingPlayer()->FindOrEstablishSession( + nullptr, + [](void * context, chip::Messaging::ExchangeManager & exchangeMgr, const chip::SessionHandle & sessionHandle) { + //support::MediaClusterBase cluster(exchangeMgr, sessionHandle, endpoint->GetId()); + + }, + [](void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error) { + ChipLogError(AppServer, "ContentLauncherCluster::LaunchURL failed"); + }); + + } + else + { + + } + + return CHIP_NO_ERROR; +} + +}; // namespace clusters +}; // namespace casting +}; // namespace matter diff --git a/examples/tv-casting-app/tv-casting-common/clusters/ContentLauncherCluster.h b/examples/tv-casting-app/tv-casting-common/clusters/ContentLauncherCluster.h index a8d5ad847a003b..c554a78eb0fa16 100644 --- a/examples/tv-casting-app/tv-casting-common/clusters/ContentLauncherCluster.h +++ b/examples/tv-casting-app/tv-casting-common/clusters/ContentLauncherCluster.h @@ -34,9 +34,8 @@ class ContentLauncherCluster : public core::BaseCluster public: ContentLauncherCluster(memory::Weak endpoint) : core::BaseCluster(endpoint) {} - // TODO: - // LaunchURL(const char * contentUrl, const char * contentDisplayStr, - // chip::Optional brandingInformation); + CHIP_ERROR LaunchURL(const char * contentUrl, const char * contentDisplayStr, + chip::Optional brandingInformation); }; }; // namespace clusters diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h index 60aba39b94c254..f0a056f9da1a34 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h @@ -20,6 +20,8 @@ #include "Endpoint.h" #include "Types.h" +#include "clusters/ContentLauncherCluster.h" +#include "core/Cluster.h" #include "support/ChipDeviceEventHandler.h" #include "support/EndpointListLoader.h" @@ -84,6 +86,7 @@ enum ConnectionState class ConnectionContext; class CastingPlayer; using ConnectCallback = std::function; +class BaseCluster; /** * @brief CastingPlayer represents a Matter commissioner that is able to play media to a physical @@ -222,6 +225,8 @@ class CastingPlayer : public std::enable_shared_from_this friend class ConnectionContext; friend class support::EndpointListLoader; + friend class BaseCluster; + friend class clusters::ContentLauncherCluster; }; class ConnectionContext diff --git a/examples/tv-casting-app/tv-casting-common/core/Cluster.h b/examples/tv-casting-app/tv-casting-common/core/Cluster.h index 678e55caf4237d..2f317cff2103a3 100644 --- a/examples/tv-casting-app/tv-casting-common/core/Cluster.h +++ b/examples/tv-casting-app/tv-casting-common/core/Cluster.h @@ -32,10 +32,6 @@ class Endpoint; // Base cluster class class BaseCluster { -private: -protected: - memory::Weak mEndpoint; - public: BaseCluster(memory::Weak endpoint) { this->mEndpoint = endpoint; } @@ -47,6 +43,7 @@ class BaseCluster protected: memory::Weak GetEndpoint() const { return mEndpoint.lock(); } + memory::Weak mEndpoint; }; }; // namespace core diff --git a/examples/tv-casting-app/tv-casting-common/core/Endpoint.h b/examples/tv-casting-app/tv-casting-common/core/Endpoint.h index a481882b6de80e..9009db959a4d9c 100644 --- a/examples/tv-casting-app/tv-casting-common/core/Endpoint.h +++ b/examples/tv-casting-app/tv-casting-common/core/Endpoint.h @@ -59,9 +59,6 @@ class Endpoint : public std::enable_shared_from_this EndpointAttributes mAttributes; std::map> mClusters; -protected: - CastingPlayer * GetCastingPlayer() const { return mCastingPlayer; } - public: Endpoint(CastingPlayer * castingPlayer, const EndpointAttributes & attributes) { @@ -75,6 +72,8 @@ class Endpoint : public std::enable_shared_from_this Endpoint(Endpoint & other) = delete; void operator=(const Endpoint &) = delete; + CastingPlayer * GetCastingPlayer() const { return mCastingPlayer; } + /** * @brief Compares based on the Id */ diff --git a/examples/tv-casting-app/tv-casting-common/support/EndpointListLoader.h b/examples/tv-casting-app/tv-casting-common/support/EndpointListLoader.h index 4905e281e94fd6..21958c776cf383 100644 --- a/examples/tv-casting-app/tv-casting-common/support/EndpointListLoader.h +++ b/examples/tv-casting-app/tv-casting-common/support/EndpointListLoader.h @@ -18,6 +18,7 @@ #pragma once +#include "support/MediaClusterBase.h" #include "core/Endpoint.h" #include "core/Types.h" @@ -27,8 +28,12 @@ namespace matter { namespace casting { -namespace support { +namespace core { + class EndpointAttributes; +}; + +namespace support { /** * @brief EndpointListLoader builds Endpoints corresponding to the CastingPlayer::GetTargetCastingPlayer by reading Bindings and * fetching Endpoint attributes (like VendorID, ProductID, DeviceTypeList, ServerList, etc). It then loads all of these Endpoints @@ -102,18 +107,6 @@ enum DesiredAttributes kTotalDesiredAttributes }; -/** - * @brief MediaClusterBase is used by the EndpointListLoader to invoke controller/CHIPCluster.h#ReadAttribute() API calls - */ -class MediaClusterBase : public chip::Controller::ClusterBase -{ -public: - MediaClusterBase(chip::Messaging::ExchangeManager & exchangeManager, const chip::SessionHandle & session, - chip::EndpointId endpoint) : - ClusterBase(exchangeManager, session, endpoint) - {} -}; - }; // namespace support }; // namespace casting }; // namespace matter diff --git a/examples/tv-casting-app/tv-casting-common/support/MediaClusterBase.h b/examples/tv-casting-app/tv-casting-common/support/MediaClusterBase.h new file mode 100644 index 00000000000000..641f98f375634a --- /dev/null +++ b/examples/tv-casting-app/tv-casting-common/support/MediaClusterBase.h @@ -0,0 +1,41 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#pragma once + +#include + +namespace matter { +namespace casting { +namespace support { + +/** + * @brief MediaClusterBase is used to invoke controller/CHIPCluster.h#ReadAttribute() API calls + */ +class MediaClusterBase : public chip::Controller::ClusterBase +{ +public: + MediaClusterBase(chip::Messaging::ExchangeManager & exchangeManager, const chip::SessionHandle & session, + chip::EndpointId endpoint) : + ClusterBase(exchangeManager, session, endpoint) + {} +}; + +}; // namespace support +}; // namespace casting +}; // namespace matter