Skip to content

Commit a51e83c

Browse files
committed
more XPC structure
1 parent da51f2b commit a51e83c

File tree

4 files changed

+68
-14
lines changed

4 files changed

+68
-14
lines changed

src/darwin/Framework/CHIP/MTRDevice+XPC.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
#import <Foundation/Foundation.h>
19+
1820
#import <Matter/Matter.h>
1921

2022
NS_ASSUME_NONNULL_BEGIN
@@ -33,14 +35,21 @@ typedef void (^MTRDeviceXPCServerAttributeReadResult)(NSDictionary<NSString *, i
3335
params:(MTRReadParams * _Nullable)params
3436
resultHandler:(MTRDeviceXPCServerAttributeReadResult)resultHandler;
3537

36-
// TODO: more methods! kmo 26 jul 2924 10h28
38+
// TODO: more methods! kmo 26 jul 2024 10h28
39+
40+
@end
41+
42+
@protocol MTRDeviceXPCClientProtocol <NSObject>
43+
44+
// TODO: more methods! kmo 26 jul 2024 10h28
3745

3846
@end
3947

4048

4149
@interface MTRDevice (XPC)
4250

43-
+ (NSXPCInterface *)xpcInterfaceForServerProtocol MTR_UNSTABLE_API;
51+
+ (NSXPCInterface *)xpcInterfaceForServerProtocol;
52+
+ (NSXPCInterface *)xpcInterfaceForClientProtocol;
4453

4554
@end
4655

src/darwin/Framework/CHIP/MTRDevice+XPC.m

+32-2
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,46 @@
1515
* limitations under the License.
1616
*/
1717

18-
#import <Foundation/Foundation.h>
1918
#import "MTRDevice+XPC.h"
19+
#import <Foundation/Foundation.h>
2020

2121
NS_ASSUME_NONNULL_BEGIN
2222

23+
// this is objective-C++ so it doesn't work in this objective-C file. maybe
24+
// the file should be objective-C++ anyways?
25+
// kmo 28 jul 2024 18h52
26+
//static NSSet * GetMTRDeviceXPCAllowedClasses()
27+
//{
28+
// static NSSet * const sMTRDeviceXPCAllowedClasses = [NSSet setWithArray:@[
29+
// [NSString class], [NSNumber class], [NSData class], [NSArray class], [NSDictionary class], [NSError class]
30+
// ]];
31+
// return sMTRDeviceXPCAllowedClasses;
32+
//}
33+
2334
@implementation MTRDevice (XPC)
2435

2536

26-
+ (NSXPCInterface *)xpcInterfaceForServerProtocol {
37+
+ (NSXPCInterface *)xpcInterfaceForServerProtocol {
38+
// TODO: allowed data types kmo 28 jul 2024 17h51
2739
NSXPCInterface * xpcInterface = [NSXPCInterface interfaceWithProtocol:@protocol(MTRDeviceXPCServerProtocol)];
40+
41+
NSSet * const sMTRDeviceXPCAllowedClasses = [NSSet setWithArray:@[
42+
[NSString class], [NSNumber class], [NSData class], [NSArray class], [NSDictionary class], [NSError class]
43+
]];
44+
45+
[xpcInterface setClasses:sMTRDeviceXPCAllowedClasses
46+
forSelector:@selector(readAttributeWithEndpointID:clusterID:attributeID:params:resultHandler:)
47+
argumentIndex:0
48+
ofReply:YES];
49+
50+
return xpcInterface;
51+
}
52+
53+
+ (NSXPCInterface *)xpcInterfaceForClientProtocol {
54+
// TODO: allowed data types kmo 28 jul 2024 17h53
55+
56+
57+
NSXPCInterface * xpcInterface = [NSXPCInterface interfaceWithProtocol:@protocol(MTRDeviceXPCClientProtocol)];
2858
return xpcInterface;
2959
}
3060

src/darwin/Framework/CHIP/Matter.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#import <Matter/MTRCommissioningParameters.h>
3939
#import <Matter/MTRDefines.h>
4040
#import <Matter/MTRDevice.h>
41+
#import <Matter/MTRDevice+XPC.h>
4142
#import <Matter/MTRDeviceAttestationDelegate.h>
4243
#import <Matter/MTRDeviceAttestationInfo.h>
4344
#import <Matter/MTRDeviceController+XPC.h>

src/darwin/Framework/CHIPTests/MTRDeviceXPCTests.m

+24-10
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,54 @@
1515
* limitations under the License.
1616
*/
1717

18-
#import <XCTest/XCTest.h>
1918
#import <Matter/Matter.h>
2019

21-
@interface MTRDeviceXPCTests : XCTestCase
20+
#import <XCTest/XCTest.h>
21+
22+
@interface MTRDeviceXPCTests<NSXPCListenerDelegate> : XCTestCase
2223
@property (nonatomic, readonly, strong) NSXPCInterface * serviceInterface;
2324
@property (nonatomic, readonly, strong) NSXPCInterface * clientInterface;
2425
@property (nonatomic, readonly, strong) NSXPCListener * xpcListener;
2526
@end
2627

2728
@implementation MTRDeviceXPCTests
2829

30+
31+
// NSXPCListener
32+
33+
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection
34+
{
35+
return true;
36+
}
2937
- (instancetype)init
3038
{
3139
_serviceInterface = [MTRDevice xpcInterfaceForServerProtocol];
40+
_clientInterface = [MTRDevice xpcInterfaceForClientProtocol];
41+
return self;
3242
}
3343

3444
- (void)setUp {
35-
// Put setup code here. This method is called before the invocation of each test method in the class.
45+
self.continueAfterFailure = NO;
46+
47+
_xpcListener = [NSXPCListener anonymousListener];
48+
_xpcListener.delegate = (id<NSXPCListenerDelegate>)self;
49+
_serviceInterface = [MTRDevice xpcInterfaceForServerProtocol];
50+
_clientInterface = [MTRDevice xpcInterfaceForClientProtocol];
51+
52+
[_xpcListener resume];
53+
// TODO: create remote MTRDevice?
3654
}
3755

3856
- (void)tearDown {
3957
// Put teardown code here. This method is called after the invocation of each test method in the class.
58+
[_xpcListener suspend];
59+
_xpcListener = nil;
4060
}
4161

4262
- (void)testExample {
4363
// This is an example of a functional test case.
4464
// Use XCTAssert and related functions to verify your tests produce the correct results.
45-
}
46-
47-
- (void)testPerformanceExample {
48-
// This is an example of a performance test case.
49-
[self measureBlock:^{
50-
// Put the code you want to measure the time of here.
51-
}];
65+
5266
}
5367

5468
@end

0 commit comments

Comments
 (0)