Skip to content

Commit

Permalink
Initial code for LaunchURL
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Dec 12, 2023
1 parent a898f3f commit 048671d
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 23 deletions.
1 change: 1 addition & 0 deletions examples/tv-casting-app/tv-casting-common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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<chip::app::Clusters::ContentLauncher::Structs::BrandingInformationStruct::Type> brandingInformation)
{
memory::Strong<core::Endpoint> 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
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ class ContentLauncherCluster : public core::BaseCluster
public:
ContentLauncherCluster(memory::Weak<core::Endpoint> endpoint) : core::BaseCluster(endpoint) {}

// TODO:
// LaunchURL(const char * contentUrl, const char * contentDisplayStr,
// chip::Optional<chip::app::Clusters::ContentLauncher::Structs::BrandingInformationStruct::Type> brandingInformation);
CHIP_ERROR LaunchURL(const char * contentUrl, const char * contentDisplayStr,
chip::Optional<chip::app::Clusters::ContentLauncher::Structs::BrandingInformationStruct::Type> brandingInformation);
};

}; // namespace clusters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -84,6 +86,7 @@ enum ConnectionState
class ConnectionContext;
class CastingPlayer;
using ConnectCallback = std::function<void(CHIP_ERROR, CastingPlayer *)>;
class BaseCluster;

/**
* @brief CastingPlayer represents a Matter commissioner that is able to play media to a physical
Expand Down Expand Up @@ -222,6 +225,8 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>

friend class ConnectionContext;
friend class support::EndpointListLoader;
friend class BaseCluster;
friend class clusters::ContentLauncherCluster;
};

class ConnectionContext
Expand Down
5 changes: 1 addition & 4 deletions examples/tv-casting-app/tv-casting-common/core/Cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ class Endpoint;
// Base cluster class
class BaseCluster
{
private:
protected:
memory::Weak<Endpoint> mEndpoint;

public:
BaseCluster(memory::Weak<Endpoint> endpoint) { this->mEndpoint = endpoint; }

Expand All @@ -47,6 +43,7 @@ class BaseCluster

protected:
memory::Weak<Endpoint> GetEndpoint() const { return mEndpoint.lock(); }
memory::Weak<Endpoint> mEndpoint;
};

}; // namespace core
Expand Down
5 changes: 2 additions & 3 deletions examples/tv-casting-app/tv-casting-common/core/Endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ class Endpoint : public std::enable_shared_from_this<Endpoint>
EndpointAttributes mAttributes;
std::map<chip::ClusterId, memory::Strong<BaseCluster>> mClusters;

protected:
CastingPlayer * GetCastingPlayer() const { return mCastingPlayer; }

public:
Endpoint(CastingPlayer * castingPlayer, const EndpointAttributes & attributes)
{
Expand All @@ -75,6 +72,8 @@ class Endpoint : public std::enable_shared_from_this<Endpoint>
Endpoint(Endpoint & other) = delete;
void operator=(const Endpoint &) = delete;

CastingPlayer * GetCastingPlayer() const { return mCastingPlayer; }

/**
* @brief Compares based on the Id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#pragma once

#include "support/MediaClusterBase.h"
#include "core/Endpoint.h"
#include "core/Types.h"

Expand All @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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 <controller/CHIPCluster.h>

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

0 comments on commit 048671d

Please sign in to comment.