diff --git a/examples/tv-casting-app/tv-casting-common/BUILD.gn b/examples/tv-casting-app/tv-casting-common/BUILD.gn index 4e87c59f118a99..6d13f2aa575127 100644 --- a/examples/tv-casting-app/tv-casting-common/BUILD.gn +++ b/examples/tv-casting-app/tv-casting-common/BUILD.gn @@ -93,12 +93,16 @@ chip_data_model("tv-casting-common") { # Add simplified casting API files here sources += [ + #"core/Attribute.h", "core/CastingApp.cpp", "core/CastingApp.h", "core/CastingPlayer.cpp", "core/CastingPlayer.h", "core/CastingPlayerDiscovery.cpp", "core/CastingPlayerDiscovery.h", + "core/Cluster.h", + + #"core/Endpoint.h", "core/Types.h", "support/AppParameters.h", "support/CastingStore.cpp", diff --git a/examples/tv-casting-app/tv-casting-common/core/Attribute.h b/examples/tv-casting-app/tv-casting-common/core/Attribute.h new file mode 100644 index 00000000000000..862cec7095901a --- /dev/null +++ b/examples/tv-casting-app/tv-casting-common/core/Attribute.h @@ -0,0 +1,76 @@ +/* + * + * 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 "Types.h" +#include "Cluster.h" + +#include "lib/support/logging/CHIPLogging.h" + +namespace matter { +namespace casting { +namespace core { + +enum ReadAttributeError +{ + READ_ATTRIBUTE_NO_ERROR +}; + +enum WriteAttributeError +{ + WRITE_ATTRIBUTE_NO_ERROR +}; + +template +using ReadAttributeCallback = std::function before, ValueType after, ReadAttributeError)>; + +using WriteAttributeCallback = std::function; + +class BaseCluster; + +template +class Attribute +{ +private: + memory::Weak cluster; + ValueType value; + +public: + Attribute(memory::Weak cluster) { this->cluster = cluster; } + + ~Attribute() {} + + Attribute() = delete; + Attribute(Attribute & other) = delete; + void operator=(const Attribute &) = delete; + +protected: + memory::Strong GetCluster() const { return cluster.lock(); } + +public: + ValueType GetValue(); + void Read(ReadAttributeCallback onRead); + void Write(ValueType value, WriteAttributeCallback onWrite); + bool SubscribeAttribute(AttributeId attributeId, ReadAttributeCallback callback); + bool UnsubscribeAttribute(AttributeId attributeId, ReadAttributeCallback callback); +}; + +}; // namespace core +}; // namespace casting +}; // namespace matter diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp index 9cc11a774e1564..b78ffc28809826 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp @@ -17,10 +17,17 @@ */ #include "CastingPlayer.h" +#include "Endpoint.h" + #include "support/CastingStore.h" #include +#include + +#include + + namespace matter { namespace casting { namespace core { @@ -101,16 +108,42 @@ void CastingPlayer::VerifyOrEstablishConnection(ConnectCallback onCompleted, uns exit: if (err != CHIP_NO_ERROR) { + ChipLogError(AppServer, "CastingPlayer::VerifyOrEstablishConnection failed with %" CHIP_ERROR_FORMAT, err.Format()); support::ChipDeviceEventHandler::SetUdcStatus(false); mConnectionState = CASTING_PLAYER_NOT_CONNECTED; mCommissioningWindowTimeoutSec = kCommissioningWindowTimeoutSec; - mOnCompleted = nullptr; mTargetCastingPlayer = nullptr; - ChipLogError(AppServer, "CastingPlayer::VerifyOrEstablishConnection failed with %" CHIP_ERROR_FORMAT, err.Format()); mOnCompleted(err, nullptr); + mOnCompleted = nullptr; } } + +class MediaClusterBase : public chip::Controller::ClusterBase + { + public: + MediaClusterBase(chip::Messaging::ExchangeManager & exchangeManager, const chip::SessionHandle & session, + chip::EndpointId endpoint) : + ClusterBase(exchangeManager, session, endpoint) + {} + }; + +CHIP_ERROR GetPartsList(chip::Messaging::ExchangeManager & exchangeMgr, const chip::SessionHandle & sessionHandle) +{ + MediaClusterBase cluster(exchangeMgr, sessionHandle, 1); + + return cluster.template ReadAttribute(nullptr, + [](void * context, chip::app::Clusters::Descriptor::Attributes::PartsList::TypeInfo::DecodableArgType responseData) + { + + }, + [](void * context, CHIP_ERROR err) + { + + }); + +} + #if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT CHIP_ERROR CastingPlayer::SendUserDirectedCommissioningRequest() { diff --git a/examples/tv-casting-app/tv-casting-common/core/Cluster.h b/examples/tv-casting-app/tv-casting-common/core/Cluster.h new file mode 100644 index 00000000000000..90a75f684417de --- /dev/null +++ b/examples/tv-casting-app/tv-casting-common/core/Cluster.h @@ -0,0 +1,54 @@ +/* + * + * 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 "Types.h" +#include "Endpoint.h" + +#include "lib/support/logging/CHIPLogging.h" + +namespace matter { +namespace casting { +namespace core { + +class Endpoint; + +// Base cluster class +class BaseCluster +{ +private: +protected: + memory::Weak endpoint; + +public: + BaseCluster(memory::Weak endpoint) { this->endpoint = endpoint; } + + virtual ~BaseCluster() {} + + BaseCluster() = delete; + BaseCluster(BaseCluster & other) = delete; + void operator=(const BaseCluster &) = delete; + +protected: + memory::Weak GetEndpoint() const { return endpoint.lock(); } +}; + +}; // namespace core +}; // namespace casting +}; // namespace matter diff --git a/examples/tv-casting-app/tv-casting-common/core/Endpoint.h b/examples/tv-casting-app/tv-casting-common/core/Endpoint.h new file mode 100644 index 00000000000000..c052757b19c763 --- /dev/null +++ b/examples/tv-casting-app/tv-casting-common/core/Endpoint.h @@ -0,0 +1,108 @@ +/* + * + * 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 "Cluster.h" +#include "Types.h" + +#include "lib/support/logging/CHIPLogging.h" + +#include +#include +#include +#include + +namespace matter { +namespace casting { +namespace core { + +class EndpointAttributes +{ +public: + chip::EndpointId id = 0; + uint16_t vendorId = 0; + uint16_t productId = 0; + uint32_t type = 0; + chip::CharSpan name; +}; + +class Endpoint : public std::enable_shared_from_this +{ + +private: + memory::Weak player; + + std::map> clusters; + EndpointAttributes attributes; + +public: + Endpoint(memory::Weak player, const EndpointAttributes & attributes) + { + this->player = player; + this->attributes = attributes; + } + + ~Endpoint() {} + + Endpoint() = delete; + Endpoint(Endpoint & other) = delete; + void operator=(const Endpoint &) = delete; + +protected: + memory::Strong GetCastingPlayer() const { return player.lock(); } + +public: + chip::EndpointId GetId() const { return attributes.id; } + + chip::CharSpan GetName() const { return attributes.name; } + + uint16_t GetProductId() const { return attributes.productId; } + + uint16_t GetVendorId() const { return attributes.vendorId; } + + uint32_t GetType() const { return attributes.type; } + +public: + template + void RegisterCluster(const chip::ClusterId clusterId) + { + static_assert(std::is_base_of::value, "T must be derived from BaseCluster"); + auto cluster = std::make_shared(shared_from_this()); + clusters[clusterId] = cluster; + } + + template + memory::Strong GetCluster() + { + static_assert(std::is_base_of::value, "T must be derived from BaseCluster"); + for (const auto & pair : clusters) + { + auto cluster = std::dynamic_pointer_cast(pair.second); + if (cluster) + { + return cluster; + } + } + return nullptr; + } +}; + +}; // namespace core +}; // namespace casting +}; // namespace matter