|
1 | 1 | /**
|
2 | 2 | *
|
3 |
| - * Copyright (c) 2020 Project CHIP Authors |
| 3 | + * Copyright (c) 2020-2024 Project CHIP Authors |
4 | 4 | *
|
5 | 5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | 6 | * you may not use this file except in compliance with the License.
|
|
14 | 14 | * See the License for the specific language governing permissions and
|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
| 17 | + |
17 | 18 | #import "MTRManualSetupPayloadParser.h"
|
18 | 19 |
|
19 | 20 | #import "MTRError_Internal.h"
|
20 |
| -#import "MTRFramework.h" |
21 |
| -#import "MTRLogging_Internal.h" |
22 |
| -#import "MTRSetupPayload_Internal.h" |
23 |
| - |
24 |
| -#import <setup_payload/ManualSetupPayloadParser.h> |
25 |
| -#import <setup_payload/SetupPayload.h> |
26 |
| - |
27 |
| -#include <string> |
| 21 | +#import "MTRSetupPayload.h" |
28 | 22 |
|
29 | 23 | @implementation MTRManualSetupPayloadParser {
|
30 | 24 | NSString * _decimalStringRepresentation;
|
31 |
| - chip::ManualSetupPayloadParser * _chipManualSetupPayloadParser; |
32 |
| -} |
33 |
| - |
34 |
| -+ (void)initialize |
35 |
| -{ |
36 |
| - MTRFrameworkInit(); |
37 | 25 | }
|
38 | 26 |
|
39 | 27 | - (id)initWithDecimalStringRepresentation:(NSString *)decimalStringRepresentation
|
40 | 28 | {
|
41 |
| - if (self = [super init]) { |
42 |
| - _decimalStringRepresentation = decimalStringRepresentation; |
43 |
| - _chipManualSetupPayloadParser = new chip::ManualSetupPayloadParser(std::string([decimalStringRepresentation UTF8String])); |
44 |
| - } |
| 29 | + self = [super init]; |
| 30 | + _decimalStringRepresentation = decimalStringRepresentation; |
45 | 31 | return self;
|
46 | 32 | }
|
47 | 33 |
|
48 | 34 | - (MTRSetupPayload *)populatePayload:(NSError * __autoreleasing *)error
|
49 | 35 | {
|
50 |
| - chip::SetupPayload cPlusPluspayload; |
51 |
| - MTRSetupPayload * payload; |
52 |
| - |
53 |
| - CHIP_ERROR chipError = _chipManualSetupPayloadParser->populatePayload(cPlusPluspayload); |
54 |
| - if (chipError == CHIP_NO_ERROR) { |
55 |
| - payload = [[MTRSetupPayload alloc] initWithSetupPayload:cPlusPluspayload]; |
56 |
| - } else if (error) { |
57 |
| - *error = [MTRError errorForCHIPErrorCode:chipError]; |
| 36 | + MTRSetupPayload * payload = [[MTRSetupPayload alloc] initWithManualPairingCode:_decimalStringRepresentation]; |
| 37 | + if (!payload && error) { |
| 38 | + *error = [MTRError errorWithCode:MTRErrorCodeInvalidArgument]; |
58 | 39 | }
|
59 |
| - |
60 | 40 | return payload;
|
61 | 41 | }
|
62 | 42 |
|
63 |
| -- (void)dealloc |
64 |
| -{ |
65 |
| - delete _chipManualSetupPayloadParser; |
66 |
| - _chipManualSetupPayloadParser = nullptr; |
67 |
| -} |
68 |
| - |
69 | 43 | @end
|
0 commit comments