Skip to content

Commit ded1e18

Browse files
committedAug 15, 2024
store WIP for rebase
1 parent f754957 commit ded1e18

File tree

6 files changed

+84
-24
lines changed

6 files changed

+84
-24
lines changed
 

‎src/darwin/Framework/CHIP/MTRDeviceController_XPC.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
NS_ASSUME_NONNULL_BEGIN
2121

22-
@interface MTRDeviceController_XPC : MTRDeviceController
22+
@interface MTRDeviceController_XPC : MTRDeviceController<NSXPCListenerDelegate> // temporarily XPCListenerDelegate
2323

2424
@end
2525

‎src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm

+45-16
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,56 @@
1515
*/
1616

1717
#import "MTRDeviceController_XPC.h"
18+
#import "MTRXPCServiceProtocol.h"
1819
#import "MTRLogging_Internal.h"
20+
#import "MTRDeviceController_Internal.h"
1921

2022
@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+
2233
@end
2334

2435
@implementation MTRDeviceController_XPC
2536

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+
2668
- (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParameters *)parameters
2769
error:(NSError * __autoreleasing *)error
2870
{
@@ -35,21 +77,8 @@ - (BOOL)setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload
3577
newNodeID:(NSNumber *)newNodeID
3678
error:(NSError * __autoreleasing *)error
3779
{
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];
5382
}
5483

5584
@end

‎src/darwin/Framework/CHIP/MTRXPCService.mm

+13-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,21 @@ - (void)ping
3333
MTR_LOG_DEBUG("PONG! %s", __PRETTY_FUNCTION__);
3434
}
3535

36-
- (void)getMeaningOfLifeWithReplyBlock:(MTRXPCServiceIntReplyBlock)reply
36+
- (nonnull NSNumber *)synchronouslyGetMeaningOfLife {
37+
return @(42);
38+
}
39+
40+
- (void)getMeaningOfLifeWithReplyBlock:(nonnull MTRXPCServiceIntReplyBlock)reply
3741
{
3842
reply(42);
3943
}
4044

45+
- (BOOL)setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload
46+
newNodeID:(NSNumber *)newNodeID
47+
error:(NSError * __autoreleasing *)error
48+
{
49+
// temporary stub implementation
50+
return false;
51+
}
52+
4153
@end

‎src/darwin/Framework/CHIP/MTRXPCServiceProtocol.h

+13-6
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@ typedef void (^MTRXPCServiceBoolReplyBlock)(BOOL);
2525

2626
@protocol MTRXPCServiceProtocol <NSObject>
2727
- (void)ping;
28+
- (NSNumber *)synchronouslyGetMeaningOfLife;
2829
- (void)getMeaningOfLifeWithReplyBlock:(MTRXPCServiceIntReplyBlock)reply;
2930

30-
// these real methods will be optional for now, but not when we are done building here.
31-
@optional
32-
- (void)setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload
33-
newNodeID:(NSNumber *)newNodeID
34-
error:(NSError * __autoreleasing *)error
35-
reply:(MTRXPCServiceBoolReplyBlock)reply;
31+
// temporary inclusion
32+
- (BOOL)setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload
33+
newNodeID:(NSNumber *)newNodeID
34+
error:(NSError * __autoreleasing *)error;
35+
36+
@end
37+
38+
@protocol MTRXPCServiceDeviceControllerProtocol <NSObject>
39+
40+
- (BOOL)setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload
41+
newNodeID:(NSNumber *)newNodeID
42+
error:(NSError * __autoreleasing *)error;
3643

3744
@end
3845

‎src/darwin/Framework/CHIPTests/MTRXPCServiceTestsDummyService.m

+10
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,14 @@ - (void)getMeaningOfLifeWithReplyBlock:(MTRXPCServiceIntReplyBlock)reply
3030
reply(42);
3131
}
3232

33+
- (BOOL)setupCommissioningSessionWithPayload:(nonnull MTRSetupPayload *)payload newNodeID:(nonnull NSNumber *)newNodeID error:(NSError *__autoreleasing _Nullable * _Nullable)error {
34+
return false;
35+
}
36+
37+
38+
- (nonnull NSNumber *)synchronouslyGetMeaningOfLife {
39+
return @42;
40+
}
41+
42+
3343
@end

‎src/darwin/Framework/Matter.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
99AECC802798A57F00B6355B /* MTRCommissioningParameters.mm in Sources */ = {isa = PBXBuildFile; fileRef = 99AECC7F2798A57E00B6355B /* MTRCommissioningParameters.mm */; };
303303
99C65E10267282F1003402F6 /* MTRControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 99C65E0F267282F1003402F6 /* MTRControllerTests.m */; };
304304
99D466E12798936D0089A18F /* MTRCommissioningParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 99D466E02798936D0089A18F /* MTRCommissioningParameters.h */; settings = {ATTRIBUTES = (Public, ); }; };
305+
9B4143812C6E662300B86FBD /* MTRXPCServiceTestsDummyService.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BC0649B2C6C152E00996FEF /* MTRXPCServiceTestsDummyService.m */; };
305306
9BC064942C6BCB6F00996FEF /* MTRXPCService.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BC064922C6BCB6F00996FEF /* MTRXPCService.h */; };
306307
9BC064952C6BCB6F00996FEF /* MTRXPCService.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BC064932C6BCB6F00996FEF /* MTRXPCService.mm */; };
307308
9BC064972C6BCBAE00996FEF /* MTRXPCServiceProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BC064962C6BCBAE00996FEF /* MTRXPCServiceProtocol.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -2016,6 +2017,7 @@
20162017
5ACDDD7D27CD16D200EFD68A /* MTRClusterStateCacheContainer.mm in Sources */,
20172018
75B3269E2BCDB9EA00E17C4E /* MTRDeviceConnectivityMonitor.mm in Sources */,
20182019
513DDB8A2761F6F900DAA01A /* MTRAttributeTLVValueDecoder.mm in Sources */,
2020+
9B4143812C6E662300B86FBD /* MTRXPCServiceTestsDummyService.m in Sources */,
20192021
5117DD3829A931AE00FFA1AA /* MTROperationalBrowser.mm in Sources */,
20202022
514C79F02B62ADDA00DD6D7B /* descriptor.cpp in Sources */,
20212023
3D843757294AD25A0070D20A /* MTRCertificateInfo.mm in Sources */,

0 commit comments

Comments
 (0)