Skip to content

Commit

Permalink
First implementation of iOS CHIP.framework and iOS code parser app (p…
Browse files Browse the repository at this point in the history
…roject-chip#537)

* First implementation of iOS CHP.framework and iOS code parser app

* Readded workspace and fixed copyright

* Rename to CHIP.framework and move to correct folder hierarchy

* Restyled by clang-format

* Restyled by prettier-json

* Rename folder

* Changed CHP to CHIP

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
shana-apple and restyled-commits authored May 5, 2020
1 parent 0f1b502 commit 9ffc90f
Show file tree
Hide file tree
Showing 31 changed files with 2,588 additions and 1 deletion.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@ third_party/mbedtls/

# Example specific rules
examples/**/sdkconfig
examples/**/sdkconfig.old

# Xcode
*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
*.xcuserstate
project.xcworkspace/
xcuserdata/
*.xcodeproj/*
*.xcworkspace/*
504 changes: 504 additions & 0 deletions src/CHIP_Framework_iOS/CHIP/CHIP.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/CHIP_Framework_iOS/CHIP/CHIP/CHIP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// CHIP.h
// CHIP
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>
#import "CHIPSetupPayload.h"
#import "CHIPQRCodeSetupPayloadParser.h"
#import "CHIPManualSetupPayloadParser.h"
#import "CHIPError.h"
//! Project version number for CHIP.
FOUNDATION_EXPORT double CHIPVersionNumber;

//! Project version string for CHIP.
FOUNDATION_EXPORT const unsigned char CHIPVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <CHIP/PublicHeader.h>
39 changes: 39 additions & 0 deletions src/CHIP_Framework_iOS/CHIP/CHIP/CHIPError.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// CHIPError.h
// CHIPQRCodeReader
//
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN
FOUNDATION_EXPORT NSErrorDomain const CHIPErrorDomain;

typedef NS_ERROR_ENUM(CHIPErrorDomain, CHIPErrorCode) {
CHIPErrorCodeUndefinedError = 0,
CHIPErrorCodeInvalidStringLength = 1,
CHIPErrorCodeInvalidIntegerValue = 2,
CHIPErrorCodeInvalidArgument = 3,
CHIPErrorCodeInvalidMessageLength = 4,
};

@interface CHIPError : NSObject
+ (nullable NSError *)errorForCHIPErrorCode:(int32_t)errorCode;
@end

NS_ASSUME_NONNULL_END
54 changes: 54 additions & 0 deletions src/CHIP_Framework_iOS/CHIP/CHIP/CHIPError.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// CHIPError.m
// CHIPQRCodeReader
//
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "CHIPError.h"

NSString * const CHIPErrorDomain = @"CHIPErrorDomain";

@implementation CHIPError

+ (NSError *)errorForCHIPErrorCode:(int32_t)errorCode
{
switch (errorCode) {
case 4030:
return [NSError errorWithDomain:CHIPErrorDomain
code:CHIPErrorCodeInvalidStringLength
userInfo:@{ NSLocalizedDescriptionKey : NSLocalizedString(@"A list length is invalid.", nil) }];
case 4145:
return [NSError errorWithDomain:CHIPErrorDomain
code:CHIPErrorCodeInvalidIntegerValue
userInfo:@{ NSLocalizedDescriptionKey : NSLocalizedString(@"Unexpected integer value.", nil) }];
case 4046:
return [NSError errorWithDomain:CHIPErrorDomain
code:CHIPErrorCodeInvalidArgument
userInfo:@{ NSLocalizedDescriptionKey : NSLocalizedString(@"An argument is invalid.", nil) }];
case 4023:
return [NSError errorWithDomain:CHIPErrorDomain
code:CHIPErrorCodeInvalidMessageLength
userInfo:@{ NSLocalizedDescriptionKey : NSLocalizedString(@"A message length is invalid.", nil) }];
default:
return [NSError errorWithDomain:CHIPErrorDomain
code:CHIPErrorCodeUndefinedError
userInfo:@{ NSLocalizedDescriptionKey : NSLocalizedString(@"Undefined error.", nil) }];
;
}
}
@end
32 changes: 32 additions & 0 deletions src/CHIP_Framework_iOS/CHIP/CHIP/CHIPManualSetupPayloadParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// CHIPManualSetupPayloadParser.h
// CHIPQRCodeReader
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>
#import "CHIPSetupPayload.h"
#import "CHIPError.h"

NS_ASSUME_NONNULL_BEGIN

@interface CHIPManualSetupPayloadParser : NSObject
- (id)initWithDecimalStringRepresentation:(NSString *)decimalStringRepresentation;
- (CHIPSetupPayload *)populatePayload:(NSError * __autoreleasing *)error;
@end

NS_ASSUME_NONNULL_END
55 changes: 55 additions & 0 deletions src/CHIP_Framework_iOS/CHIP/CHIP/CHIPManualSetupPayloadParser.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// CHIPManualSetupPayloadParser.m
// CHIPQRCodeReader
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "CHIPManualSetupPayloadParser.h"

#import <setup_payload/ManualSetupPayloadParser.h>
#import <setup_payload/SetupPayload.h>

@implementation CHIPManualSetupPayloadParser {
NSString *_decimalStringRepresentation;
chip::ManualSetupPayloadParser *_chipManualSetupPayloadParser;
}

- (id)initWithDecimalStringRepresentation:(NSString *)decimalStringRepresentation
{
if(self = [super init]) {
_decimalStringRepresentation = decimalStringRepresentation;
_chipManualSetupPayloadParser = new chip::ManualSetupPayloadParser(std::string([decimalStringRepresentation UTF8String]));
}
return self;
}

- (CHIPSetupPayload *)populatePayload:(NSError *__autoreleasing *)error
{
chip::SetupPayload cPlusPluspayload;
CHIP_ERROR chipError = _chipManualSetupPayloadParser->populatePayload(cPlusPluspayload);

CHIPSetupPayload *payload;
if (chipError == 0) {
payload = [[CHIPSetupPayload alloc] initWithSetupPayload:cPlusPluspayload];
} else if (error) {
*error = [CHIPError errorForCHIPErrorCode:chipError];
}

return payload;
}

@end
31 changes: 31 additions & 0 deletions src/CHIP_Framework_iOS/CHIP/CHIP/CHIPQRCodeSetupPayloadParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// CHIPQRCodeSetupPayloadParser.h
// CHIPQRCodeReader
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
#import "CHIPSetupPayload.h"
#import "CHIPError.h"

NS_ASSUME_NONNULL_BEGIN

@interface CHIPQRCodeSetupPayloadParser : NSObject
- (id)initWithBase45Representation:(NSString *)base45Representation;
- (CHIPSetupPayload *)populatePayload:(NSError * __autoreleasing *)error;
@end
;
NS_ASSUME_NONNULL_END
54 changes: 54 additions & 0 deletions src/CHIP_Framework_iOS/CHIP/CHIP/CHIPQRCodeSetupPayloadParser.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// CHIPQRCodeSetupPayloadParser.m
// CHIPQRCodeReader
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "CHIPQRCodeSetupPayloadParser.h"
#import "CHIPError.h"

#import <setup_payload/QRCodeSetupPayloadParser.h>
#import <setup_payload/SetupPayload.h>

@implementation CHIPQRCodeSetupPayloadParser {
NSString *_base45Representation;
chip::QRCodeSetupPayloadParser *_chipQRCodeSetupPayloadParser;
}

- (id)initWithBase45Representation:(NSString *)base45Representation
{
if(self = [super init]) {
_base45Representation = base45Representation;
_chipQRCodeSetupPayloadParser = new chip::QRCodeSetupPayloadParser(std::string([base45Representation UTF8String]));
}
return self;
}

- (CHIPSetupPayload *)populatePayload:(NSError *__autoreleasing *)error
{
chip::SetupPayload cPlusPluspayload;
CHIP_ERROR chipError = _chipQRCodeSetupPayloadParser->populatePayload(cPlusPluspayload);

CHIPSetupPayload *payload;
if (chipError == 0) {
payload = [[CHIPSetupPayload alloc] initWithSetupPayload:cPlusPluspayload];
} else if (error) {
*error = [CHIPError errorForCHIPErrorCode:chipError];
}
return payload;
}
@end
45 changes: 45 additions & 0 deletions src/CHIP_Framework_iOS/CHIP/CHIP/CHIPSetupPayload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// CHIPSetupPayload.h
// CHIPQRCodeReader
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

#ifdef __cplusplus
#import <setup_payload/SetupPayload.h>
#endif

NS_ASSUME_NONNULL_BEGIN

@interface CHIPSetupPayload : NSObject

@property (nonatomic, strong) NSNumber * version;
@property (nonatomic, strong) NSNumber * vendorID;
@property (nonatomic, strong) NSNumber * productID;
@property (nonatomic, assign) BOOL requiresCustomFlow;
@property (nonatomic, strong) NSNumber * rendezvousInformation;
@property (nonatomic, strong) NSNumber * discriminator;
@property (nonatomic, strong) NSNumber * setUpPINCode;

#ifdef __cplusplus
- (id)initWithSetupPayload:(chip::SetupPayload)setupPayload;
#endif

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 9ffc90f

Please sign in to comment.