forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3ef405
commit 8e4f7cf
Showing
5 changed files
with
277 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
examples/tv-casting-app/tv-casting-common/core/Attribute.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <typename ValueType> | ||
using ReadAttributeCallback = std::function<void(Optional<ValueType> before, ValueType after, ReadAttributeError)>; | ||
|
||
using WriteAttributeCallback = std::function<void(WriteAttributeError)>; | ||
|
||
class BaseCluster; | ||
|
||
template <typename ValueType> | ||
class Attribute | ||
{ | ||
private: | ||
memory::Weak<BaseCluster> cluster; | ||
ValueType value; | ||
|
||
public: | ||
Attribute(memory::Weak<BaseCluster> cluster) { this->cluster = cluster; } | ||
|
||
~Attribute() {} | ||
|
||
Attribute() = delete; | ||
Attribute(Attribute & other) = delete; | ||
void operator=(const Attribute &) = delete; | ||
|
||
protected: | ||
memory::Strong<BaseCluster> GetCluster() const { return cluster.lock(); } | ||
|
||
public: | ||
ValueType GetValue(); | ||
void Read(ReadAttributeCallback<ValueType> onRead); | ||
void Write(ValueType value, WriteAttributeCallback onWrite); | ||
bool SubscribeAttribute(AttributeId attributeId, ReadAttributeCallback<ValueType> callback); | ||
bool UnsubscribeAttribute(AttributeId attributeId, ReadAttributeCallback<ValueType> callback); | ||
}; | ||
|
||
}; // namespace core | ||
}; // namespace casting | ||
}; // namespace matter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> endpoint; | ||
|
||
public: | ||
BaseCluster(memory::Weak<Endpoint> endpoint) { this->endpoint = endpoint; } | ||
|
||
virtual ~BaseCluster() {} | ||
|
||
BaseCluster() = delete; | ||
BaseCluster(BaseCluster & other) = delete; | ||
void operator=(const BaseCluster &) = delete; | ||
|
||
protected: | ||
memory::Weak<Endpoint> GetEndpoint() const { return endpoint.lock(); } | ||
}; | ||
|
||
}; // namespace core | ||
}; // namespace casting | ||
}; // namespace matter |
108 changes: 108 additions & 0 deletions
108
examples/tv-casting-app/tv-casting-common/core/Endpoint.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <iostream> | ||
#include <map> | ||
#include <memory> | ||
#include <type_traits> | ||
|
||
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<Endpoint> | ||
{ | ||
|
||
private: | ||
memory::Weak<CastingPlayer> player; | ||
|
||
std::map<chip::ClusterId, memory::Strong<BaseCluster>> clusters; | ||
EndpointAttributes attributes; | ||
|
||
public: | ||
Endpoint(memory::Weak<CastingPlayer> 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<CastingPlayer> 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 <typename T> | ||
void RegisterCluster(const chip::ClusterId clusterId) | ||
{ | ||
static_assert(std::is_base_of<BaseCluster, T>::value, "T must be derived from BaseCluster"); | ||
auto cluster = std::make_shared<T>(shared_from_this()); | ||
clusters[clusterId] = cluster; | ||
} | ||
|
||
template <typename T> | ||
memory::Strong<T> GetCluster() | ||
{ | ||
static_assert(std::is_base_of<BaseCluster, T>::value, "T must be derived from BaseCluster"); | ||
for (const auto & pair : clusters) | ||
{ | ||
auto cluster = std::dynamic_pointer_cast<T>(pair.second); | ||
if (cluster) | ||
{ | ||
return cluster; | ||
} | ||
} | ||
return nullptr; | ||
} | ||
}; | ||
|
||
}; // namespace core | ||
}; // namespace casting | ||
}; // namespace matter |