@@ -44,6 +44,45 @@ @interface MTRDeviceController_XPC ()
44
44
45
45
@implementation MTRDeviceController_XPC
46
46
47
+ #pragma mark - Device Node ID Commands
48
+
49
+ - (void )_registerNodeID : (NSNumber *)nodeID
50
+ {
51
+ @try {
52
+ [[self .xpcConnection remoteObjectProxyWithErrorHandler: ^(NSError * _Nonnull error) {
53
+ MTR_LOG_ERROR (" Register node error: %@ nodeID: %@" , error, nodeID);
54
+ }] deviceController: self .uniqueIdentifier registerNodeID: nodeID];
55
+ } @catch (NSException * exception ) {
56
+ MTR_LOG_ERROR (" Exception registering nodeID: %@" , exception );
57
+ }
58
+ }
59
+
60
+ - (void )_unregisterNodeID : (NSNumber *)nodeID
61
+ {
62
+ @try {
63
+ [[self .xpcConnection remoteObjectProxyWithErrorHandler: ^(NSError * _Nonnull error) {
64
+ MTR_LOG_ERROR (" Unregister node error: %@ nodeID: %@" , error, nodeID);
65
+ }] deviceController: self .uniqueIdentifier unregisterNodeID: nodeID];
66
+ } @catch (NSException * exception ) {
67
+ MTR_LOG_ERROR (" Exception registering nodeID: %@" , exception );
68
+ }
69
+ }
70
+
71
+ - (void )_checkinWithContext : (NSDictionary *)context
72
+ {
73
+ @try {
74
+ if (!context)
75
+ context = [NSDictionary dictionary ];
76
+
77
+ [[self .xpcConnection remoteObjectProxyWithErrorHandler: ^(NSError * _Nonnull error) {
78
+ MTR_LOG_ERROR (" Checkin error: %@" , error);
79
+ }] deviceController: self .uniqueIdentifier checkInWithContext: context];
80
+ } @catch (NSException * exception ) {
81
+ MTR_LOG_ERROR (" Exception registering nodeID: %@" , exception );
82
+ }
83
+ }
84
+
85
+ #pragma mark - XPC
47
86
+ (NSMutableSet *)_allowedClasses
48
87
{
49
88
static NSArray * sBaseAllowedClasses = @[
@@ -202,22 +241,15 @@ - (BOOL)_setupXPCConnection
202
241
MTR_LOG (" %@ Activating new XPC connection" , self);
203
242
[self .xpcConnection activate ];
204
243
205
- [[self .xpcConnection remoteObjectProxyWithErrorHandler: ^(NSError * _Nonnull error) {
206
- MTR_LOG_ERROR (" Checkin error: %@" , error);
207
- }] deviceController: self .uniqueIdentifier checkInWithContext: [NSDictionary dictionary ]];
244
+ [self _checkinWithContext: [NSDictionary dictionary ]];
208
245
209
246
// FIXME: Trying to kick all the MTRDevices attached to this controller to re-establish connections
210
247
// This state needs to be stored properly and re-established at connnection time
211
248
212
249
MTR_LOG (" %@ Starting existing NodeID Registration" , self);
213
250
for (NSNumber * nodeID in [self .nodeIDToDeviceMap keyEnumerator ]) {
214
251
MTR_LOG (" %@ => Registering nodeID: %@" , self, nodeID);
215
- mtr_weakify (self);
216
-
217
- [[self .xpcConnection remoteObjectProxyWithErrorHandler: ^(NSError * _Nonnull error) {
218
- mtr_strongify (self);
219
- MTR_LOG_ERROR (" %@ Registration error for device nodeID: %@ : %@" , self, nodeID, error);
220
- }] deviceController: self .uniqueIdentifier registerNodeID: nodeID];
252
+ [self _registerNodeID: nodeID];
221
253
}
222
254
223
255
MTR_LOG (" %@ Done existing NodeID Registration" , self);
@@ -308,11 +340,7 @@ - (MTRDevice *)_setupDeviceForNodeID:(NSNumber *)nodeID prefetchedClusterData:(N
308
340
[self .nodeIDToDeviceMap setObject: deviceToReturn forKey: nodeID];
309
341
MTR_LOG (" %s: returning XPC device for node id %@" , __PRETTY_FUNCTION__, nodeID);
310
342
311
- mtr_weakify (self);
312
- [[self .xpcConnection remoteObjectProxyWithErrorHandler: ^(NSError * _Nonnull error) {
313
- mtr_strongify (self);
314
- MTR_LOG_ERROR (" %@ Registration error for device nodeID: %@ : %@" , self, nodeID, error);
315
- }] deviceController: self .uniqueIdentifier registerNodeID: nodeID];
343
+ [self _registerNodeID: nodeID];
316
344
317
345
return deviceToReturn;
318
346
}
0 commit comments