forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEndpoint.h
158 lines (133 loc) · 4.65 KB
/
Endpoint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
*
* 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 "BaseCluster.h"
#include "CastingPlayer.h"
#include "Types.h"
#include "lib/support/logging/CHIPLogging.h"
#include <app-common/zap-generated/cluster-objects.h>
#include <iostream>
#include <map>
#include <memory>
#include <type_traits>
#include <vector>
namespace matter {
namespace casting {
namespace core {
class EndpointAttributes
{
public:
// value of 0 means the attribute could not be read for the corresponding Endpoint
chip::EndpointId mId = 0;
uint16_t mVendorId = 0;
uint16_t mProductId = 0;
std::vector<chip::app::Clusters::Descriptor::Structs::DeviceTypeStruct::DecodableType> mDeviceTypeList;
};
class CastingPlayer;
class BaseCluster;
/**
* @brief An Endpoint on a CastingPlayer e.g. a Speaker or a Matter Content App
*/
class Endpoint : public std::enable_shared_from_this<Endpoint>
{
private:
CastingPlayer * mCastingPlayer;
EndpointAttributes mAttributes;
std::map<chip::ClusterId, memory::Strong<BaseCluster>> mClusters;
public:
Endpoint(CastingPlayer * castingPlayer, const EndpointAttributes & attributes)
{
this->mCastingPlayer = castingPlayer;
this->mAttributes = attributes;
}
~Endpoint() {}
Endpoint() = delete;
Endpoint(Endpoint & other) = delete;
void operator=(const Endpoint &) = delete;
CastingPlayer * GetCastingPlayer() const { return mCastingPlayer; }
/**
* @brief Compares based on the Id
*/
bool operator==(const Endpoint & other) const { return this->mAttributes.mId == other.mAttributes.mId; }
chip::EndpointId GetId() const { return mAttributes.mId; }
/**
* @return uint16_t - value 0 indicates no ProductId was returned for this Endpoint
*/
uint16_t GetProductId() const { return mAttributes.mProductId; }
/**
* @return uint16_t - value 0 indicates no VendorId was returned for this Endpoint
*/
uint16_t GetVendorId() const { return mAttributes.mVendorId; }
/**
* @return uint16_t - empty vector indicates no DeviceTypeList was returned for this Endpoint
*/
std::vector<chip::app::Clusters::Descriptor::Structs::DeviceTypeStruct::DecodableType> GetDeviceTypeList() const
{
return mAttributes.mDeviceTypeList;
}
/**
* @return uint16_t - empty vector indicates no ServerList was returned for this Endpoint
*/
std::vector<chip::ClusterId> GetServerList()
{
std::vector<chip::ClusterId> serverList;
for (auto const & cluster : mClusters)
{
serverList.push_back(cluster.first);
}
return serverList;
}
void RegisterClusters(std::vector<chip::ClusterId> clusters);
/**
* @brief Registers a cluster of type T against the passed in clusterId
* for this Endpoint
*/
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());
cluster->SetUp();
mClusters[clusterId] = std::static_pointer_cast<BaseCluster>(cluster);
}
/**
* @brief Returns a cluster of type T, if applicable. Returns nullptr otherwise
*/
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 : mClusters)
{
auto cluster = std::dynamic_pointer_cast<T>(pair.second);
if (cluster)
{
return cluster;
}
}
return nullptr;
}
void LogDetail() const
{
ChipLogProgress(AppServer, "Endpoint::LogDetail() Endpoint ID: %d, Vendor ID: %d, Product ID: %d, Clusters: %d",
mAttributes.mId, mAttributes.mVendorId, mAttributes.mProductId, static_cast<int>(mClusters.size()));
}
};
}; // namespace core
}; // namespace casting
}; // namespace matter