forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBridgedDeviceManager.h
119 lines (105 loc) · 4.53 KB
/
BridgedDeviceManager.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
/*
*
* Copyright (c) 2024 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 <platform/CHIPDeviceLayer.h>
#include "BridgedDevice.h"
class BridgedDeviceManager
{
public:
BridgedDeviceManager() = default;
/**
* @brief Initializes the BridgedDeviceManager.
*
* This function sets up the initial state of the BridgedDeviceManager, clearing
* any existing devices and setting the starting dynamic endpoint ID.
*/
void Init();
/**
* @brief Adds a device to a dynamic endpoint.
*
* This function attempts to add a device to a dynamic endpoint. It tries to find an available
* endpoint slot and retries the addition process up to a specified maximum number of times if
* the endpoint already exists. If the addition is successful, it returns the index of the
* dynamic endpoint; otherwise, it returns -1.
*
* @param dev A pointer to the device to be added.
* @param parentEndpointId The parent endpoint ID. Defaults to an invalid endpoint ID.
* @return int The index of the dynamic endpoint if successful, -1 otherwise.
*/
int AddDeviceEndpoint(BridgedDevice * dev, chip::EndpointId parentEndpointId = chip::kInvalidEndpointId);
/**
* @brief Removes a device from a dynamic endpoint.
*
* This function attempts to remove a device from a dynamic endpoint by iterating through the
* available endpoints and checking if the device matches. If the device is found, it clears the
* dynamic endpoint, logs the removal, and returns the index of the removed endpoint.
* If the device is not found, it returns -1.
*
* @param dev A pointer to the device to be removed.
* @return int The index of the removed dynamic endpoint if successful, -1 otherwise.
*/
int RemoveDeviceEndpoint(BridgedDevice * dev);
/**
* @brief Gets a device from its endpoint ID.
*
* This function iterates through the available devices and returns the device that matches the
* specified endpoint ID. If no device matches the endpoint ID, it returns nullptr.
*
* @param endpointId The endpoint ID of the device to be retrieved.
* @return BridgedDevice* A pointer to the device if found, nullptr otherwise.
*/
BridgedDevice * GetDevice(chip::EndpointId endpointId) const;
/**
* @brief Gets a device from its NodeId.
*
* This function iterates through the available devices and returns the device that matches the
* specified NodeId. If no device matches the NodeId, it returns nullptr.
*
* @param nodeId The NodeId of the device to be retrieved.
* @return BridgedDevice* A pointer to the device if found, nullptr otherwise.
*/
BridgedDevice * GetDeviceByNodeId(chip::NodeId nodeId) const;
/**
* @brief Removes a device from a dynamic endpoint by its NodeId.
*
* This function attempts to remove a device from a dynamic endpoint by iterating through the
* available endpoints and checking if the device matches the specified NodeId. If the device is
* found, it clears the dynamic endpoint, logs the removal, and returns the index of the removed
* endpoint. If the device is not found, it returns -1.
*
* @param nodeId The NodeId of the device to be removed.
* @return int The index of the removed dynamic endpoint if successful, -1 otherwise.
*/
int RemoveDeviceByNodeId(chip::NodeId nodeId);
private:
friend BridgedDeviceManager & BridgeDeviceMgr();
static BridgedDeviceManager sInstance;
chip::EndpointId mCurrentEndpointId;
chip::EndpointId mFirstDynamicEndpointId;
BridgedDevice * mDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT + 1];
};
/**
* Returns the public interface of the BridgedDeviceManager singleton object.
*
* Applications should use this to access features of the BridgedDeviceManager
* object.
*/
inline BridgedDeviceManager & BridgeDeviceMgr()
{
return BridgedDeviceManager::sInstance;
}