forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMTRDeviceController_Concrete.h
249 lines (218 loc) · 10.2 KB
/
MTRDeviceController_Concrete.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/**
*
* Copyright (c) 2020-2023 Project CHIP Authors
*
* 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.
*/
#import <Foundation/Foundation.h>
#import <Matter/MTRAccessGrant.h>
#import <Matter/MTRBaseDevice.h>
#import <Matter/MTRDefines.h>
#import <Matter/MTRDeviceController.h>
#import <Matter/MTRDeviceControllerFactory.h>
#import <Matter/MTRDeviceControllerStorageDelegate.h>
#import <Matter/MTRDeviceStorageBehaviorConfiguration.h>
#import <Matter/MTROTAProviderDelegate.h>
#import "MTRAsyncWorkQueue.h"
#import "MTRDeviceConnectionBridge.h"
#import "MTRDeviceControllerDataStore.h"
#import "MTRDeviceControllerStartupParams_Internal.h"
#include <credentials/FabricTable.h>
#include <lib/core/DataModelTypes.h>
NS_ASSUME_NONNULL_BEGIN
@interface MTRDeviceController_Concrete : MTRDeviceController
/**
* Init a newly created controller.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (nullable instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory
queue:(dispatch_queue_t)queue
storageDelegate:(id<MTRDeviceControllerStorageDelegate> _Nullable)storageDelegate
storageDelegateQueue:(dispatch_queue_t _Nullable)storageDelegateQueue
otaProviderDelegate:(id<MTROTAProviderDelegate> _Nullable)otaProviderDelegate
otaProviderDelegateQueue:(dispatch_queue_t _Nullable)otaProviderDelegateQueue
uniqueIdentifier:(NSUUID *)uniqueIdentifier
concurrentSubscriptionPoolSize:(NSUInteger)concurrentSubscriptionPoolSize
storageBehaviorConfiguration:(MTRDeviceStorageBehaviorConfiguration *)storageBehaviorConfiguration
startSuspended:(BOOL)startSuspended;
/**
* Start a new controller. Returns whether startup succeeded. If this fails,
* it guarantees that it has called controllerShuttingDown on the
* MTRDeviceControllerFactory.
*
* The return value will always match [controller isRunning] for this
* controller.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (BOOL)startup:(MTRDeviceControllerStartupParamsInternal *)startupParams;
/**
* Shut down the underlying C++ controller. Must be called on the Matter work
* queue or after the Matter work queue has been shut down.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (void)shutDownCppController;
/**
* Notification that the MTRDeviceControllerFactory has finished shutting down
* this controller and will not be touching it anymore. This is guaranteed to
* be called after initWithFactory succeeds.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (void)deinitFromFactory;
/**
* Check whether this controller is running on the given fabric, as represented
* by the provided FabricTable and fabric index. The provided fabric table may
* not be the same as the fabric table this controller is using. This method
* MUST be called from the Matter work queue.
*
* Might return failure, in which case we don't know whether it's running on the
* given fabric. Otherwise it will set *isRunning to the right boolean value.
*
* Only MTRDeviceControllerFactory should be calling this.
*/
- (CHIP_ERROR)isRunningOnFabric:(chip::FabricTable *)fabricTable
fabricIndex:(chip::FabricIndex)fabricIndex
isRunning:(BOOL *)isRunning;
/**
* Takes an assertion to keep the controller running. If `-[MTRDeviceController shutdown]` is called while an assertion
* is held, the shutdown will be honored only after all assertions are released. Invoking this method multiple times increases
* the number of assertions and needs to be matched with equal amount of '-[MTRDeviceController removeRunAssertion]` to release
* the assertion.
*/
- (void)addRunAssertion;
/**
* Removes an assertion to allow the controller to shutdown once all assertions have been released.
* Invoking this method once all assertions have been released in a noop.
*/
- (void)removeRunAssertion;
/**
* This method returns TRUE if this controller matches the fabric reference and node ID as listed in the parameters.
*/
- (BOOL)matchesPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate;
/**
* Clear any pending shutdown request.
*/
- (void)clearPendingShutdown;
/**
* Ensure we have a CASE session to the given node ID and then call the provided
* connection callback. This may be called on any queue (including the Matter
* event queue) and on success will always call the provided connection callback
* on the Matter queue, asynchronously. Consumers must be prepared to run on
* the Matter queue (an in particular must not use any APIs that will try to do
* sync dispatch to the Matter queue).
*
* If the controller is not running when this function is called, it will
* synchronously invoke the completion with an error, on whatever queue
* getSessionForNode was called on.
*
* If the controller is not running when the async dispatch on the Matter queue
* happens, the completion will be invoked with an error on the Matter queue.
*/
- (void)getSessionForNode:(chip::NodeId)nodeID completion:(MTRInternalDeviceConnectionCallback)completion;
/**
* Since getSessionForNode now enqueues by the subscription pool for Thread
* devices, MTRDevice_Concrete needs a direct non-queued access because it already
* makes use of the subscription pool.
*/
- (void)directlyGetSessionForNode:(chip::NodeId)nodeID completion:(MTRInternalDeviceConnectionCallback)completion;
/**
* Get a session for the commissionee device with the given device id. This may
* be called on any queue (including the Matter event queue) and on success will
* always call the provided connection callback on the Matter queue,
* asynchronously. Consumers must be prepared to run on the Matter queue (an in
* particular must not use any APIs that will try to do sync dispatch to the
* Matter queue).
*
* If the controller is not running when this function is called, it will
* synchronously invoke the completion with an error, on whatever queue
* getSessionForCommissioneeDevice was called on.
*
* If the controller is not running when the async dispatch on the Matter queue
* happens, the completion will be invoked with an error on the Matter queue.
*/
- (void)getSessionForCommissioneeDevice:(chip::NodeId)deviceID completion:(MTRInternalDeviceConnectionCallback)completion;
/**
* Notify the controller that a new operational instance with the given node id
* and a compressed fabric id that matches this controller has been observed.
*/
- (void)operationalInstanceAdded:(NSNumber *)nodeID;
/**
* Get the access grants that apply for the given cluster path.
*/
- (NSArray<MTRAccessGrant *> *)accessGrantsForClusterPath:(MTRClusterPath *)clusterPath;
/**
* Get the privilege level needed to read the given attribute. There's no
* endpoint provided because the expectation is that this information is the
* same for all cluster instances.
*
* Returns nil if we have no such attribute defined on any endpoint, otherwise
* one of MTRAccessControlEntry* constants wrapped in NSNumber.
*
* Only called on the Matter queue.
*/
- (nullable NSNumber *)neededReadPrivilegeForClusterID:(NSNumber *)clusterID attributeID:(NSNumber *)attributeID;
/**
* Try to asynchronously dispatch the given block on the Matter queue. If the
* controller is not running either at call time or when the block would be
* about to run, the provided error handler will be called with an error. Note
* that this means the error handler might be called on an arbitrary queue, and
* might be called before this function returns or after it returns.
*
* The DeviceCommissioner pointer passed to the callback should only be used
* synchronously during the callback invocation.
*
* If the error handler is nil, failure to run the block will be silent.
*/
- (void)asyncGetCommissionerOnMatterQueue:(void (^)(chip::Controller::DeviceCommissioner *))block
errorHandler:(nullable MTRDeviceErrorHandler)errorHandler;
/**
* Returns the transport used by the current session with the given device,
* or `MTRTransportTypeUndefined` if no session is currently active.
*/
- (MTRTransportType)sessionTransportTypeForDevice:(MTRBaseDevice *)device;
/**
* Invalidate the CASE session for the given node ID. This is a temporary thing
* just to support MTRBaseDevice's invalidateCASESession. Must not be called on
* the Matter event queue.
*/
- (void)invalidateCASESessionForNode:(NSNumber *)nodeID;
/**
* Download log of the desired type from the device.
*/
- (void)downloadLogFromNodeWithID:(NSNumber *)nodeID
type:(MTRDiagnosticLogType)type
timeout:(NSTimeInterval)timeout
queue:(dispatch_queue_t)queue
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion;
/**
* Returns YES if the MTRDevice corrresponding to the given node ID is known to be a thread device, NO otherwise.
*/
- (BOOL)definitelyUsesThreadForDevice:(chip::NodeId)nodeID;
/**
* Will return chip::kUndefinedFabricIndex if we do not have a fabric index.
*/
@property (readonly) chip::FabricIndex fabricIndex;
/**
* A queue with a fixed width that allows a number of MTRDevice objects to perform
* subscription at the same time.
*/
@property (nonatomic, readonly) MTRAsyncWorkQueue<MTRDeviceController *> * concurrentSubscriptionPool;
/**
* The per-controller data store this controller was initialized with, if any.
*/
@property (nonatomic, readonly, nullable) MTRDeviceControllerDataStore * controllerDataStore;
@end
NS_ASSUME_NONNULL_END