15
15
*/
16
16
17
17
#import " MTRDeviceController_XPC.h"
18
+ #import " MTRXPCServiceProtocol.h"
18
19
#import " MTRLogging_Internal.h"
20
+ #import " MTRDeviceController_Internal.h"
19
21
20
22
@interface MTRDeviceController_XPC ()
21
- @property (nonatomic , strong ) NSXPCConnection * xpcConnection;
23
+ @property (retain , readwrite ) NSXPCConnection * xpcConnection;
24
+ @property (retain , readwrite ) id <MTRXPCServiceProtocol> xpcRemoteObjectProxy;
25
+
26
+ // testing only
27
+ @property (retain , readwrite ) NSXPCListener * testListener;
28
+
29
+ @end
30
+
31
+ @implementation MTRDeviceController_XPC (TestXPCListener)
32
+
22
33
@end
23
34
24
35
@implementation MTRDeviceController_XPC
25
36
37
+ - (id )initWithTestXPCListener {
38
+ // TODO: update with well-known service name
39
+ // self.xpcConnection = [[NSXPCConnection alloc] initWithServiceName:@"wellknown"];
40
+
41
+ // testing mode
42
+ self.testListener = [NSXPCListener anonymousListener ];
43
+ [self .testListener setDelegate: self ];
44
+ [self .testListener resume ];
45
+ NSXPCConnection * xpcConnection = [[NSXPCConnection alloc ] initWithListenerEndpoint: self .testListener.endpoint];
46
+
47
+ return [self initWithXPCConnection: xpcConnection];
48
+ }
49
+
50
+ - (id )initWithXPCConnection : (NSXPCConnection *)newConnection
51
+ {
52
+ // if (!(self = [super initForSubclasses])) {
53
+ // return nil;
54
+ // }
55
+
56
+ self.xpcConnection .remoteObjectInterface = [NSXPCInterface interfaceWithProtocol: @protocol (MTRXPCServiceProtocol)];
57
+ self.xpcRemoteObjectProxy = self.xpcConnection .remoteObjectProxy ;
58
+ [self .xpcConnection resume ];
59
+
60
+ // ping and meaning of life just as a test
61
+ [self .xpcRemoteObjectProxy ping ];
62
+ NSNumber * lifeMeaning = [self .xpcRemoteObjectProxy synchronouslyGetMeaningOfLife ];
63
+ NSLog (@" meaning of life appears to be %@ " , lifeMeaning);
64
+
65
+ return self;
66
+ }
67
+
26
68
- (nullable instancetype )initWithParameters : (MTRDeviceControllerAbstractParameters *)parameters
27
69
error : (NSError * __autoreleasing *)error
28
70
{
@@ -35,21 +77,8 @@ - (BOOL)setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload
35
77
newNodeID : (NSNumber *)newNodeID
36
78
error : (NSError * __autoreleasing *)error
37
79
{
38
- // xpc things obviously! kmo 14 aug 2024 12h35
39
- // transform async work to sync work
40
-
41
- MTR_LOG_ERROR (" unimplemented method %s called" , __PRETTY_FUNCTION__);
42
- return false ;
43
- }
44
-
45
- typedef void (^BoolReplyBlock)(bool );
46
- - (void )_xpc_setupCommissioningSessionWithPayload : (MTRSetupPayload *)payload
47
- newNodeID : (NSNumber *)newNodeID
48
- error : (NSError * __autoreleasing *)error
49
- reply : (BoolReplyBlock)reply
50
- {
51
- MTR_LOG_ERROR (" unimplemented XPC method %s called" , __PRETTY_FUNCTION__);
52
- reply (false );
80
+ MTR_LOG_DEBUG (" called XPC stub %s" , __PRETTY_FUNCTION__);
81
+ return [self .xpcRemoteObjectProxy setupCommissioningSessionWithPayload: payload newNodeID: newNodeID error: error];
53
82
}
54
83
55
84
@end
0 commit comments