-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc4f841
commit 936dbbc
Showing
10 changed files
with
3,983 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/app/zap-templates/templates/chip/CHIPClustersObjc-src.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
{{> header}} | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "CHIPCallbackBridge.h" | ||
#import "CHIPDevice.h" | ||
#import "CHIPDevice_Internal.h" | ||
#import "CHIPClustersObjc.h" | ||
|
||
#include <controller/CHIPClusters.h> | ||
|
||
{{#chip_server_clusters}} | ||
|
||
@interface CHIP{{asCamelCased name false}} () | ||
|
||
@property (readonly) chip::Controller::{{asCamelCased name false}}Cluster cppCluster; | ||
@property (readonly, nonatomic) dispatch_queue_t callbackQueue; | ||
@end | ||
|
||
@implementation CHIP{{asCamelCased name false}} | ||
|
||
- (instancetype)initWithDevice:(CHIPDevice *)device endpoint:(chip::EndpointId)endpoint queue:(dispatch_queue_t)queue | ||
{ | ||
CHIP_ERROR err = _cppCluster.Associate([device internalDevice], endpoint); | ||
|
||
if (err != CHIP_NO_ERROR) { | ||
return nil; | ||
} | ||
|
||
if (self = [super init]) { | ||
_callbackQueue = queue; | ||
} | ||
return self; | ||
} | ||
|
||
{{#chip_server_cluster_commands}} | ||
- (BOOL){{asCamelCased name}}:(CHIPDeviceCallback)onCompletion{{#chip_server_cluster_command_arguments}} {{asCamelCased label}}:({{chipType}}){{asCamelCased label}}{{/chip_server_cluster_command_arguments}} | ||
{ | ||
CHIPCallbackBridge * callback = new CHIPCallbackBridge(onCompletion, _callbackQueue); | ||
if (!callback) { | ||
return NO; | ||
} | ||
|
||
CHIP_ERROR err = self.cppCluster.{{asCamelCased name false}}(callback{{#chip_server_cluster_command_arguments}}, {{asCamelCased label}}{{/chip_server_cluster_command_arguments}}); | ||
if (err != CHIP_NO_ERROR) { | ||
callback->Cancel(); | ||
delete callback; | ||
return NO; | ||
} | ||
return YES; | ||
} | ||
{{/chip_server_cluster_commands}} | ||
|
||
{{#chip_server_cluster_attributes}} | ||
- (BOOL)readAttribute{{asCamelCased name false}}:(CHIPDeviceCallback)onCompletion | ||
{ | ||
CHIPCallbackBridge * callback = new CHIPCallbackBridge(onCompletion, _callbackQueue); | ||
if (!callback) { | ||
return NO; | ||
} | ||
|
||
CHIP_ERROR err = self.cppCluster.ReadAttribute{{asCamelCased name false}}(callback); | ||
if (err != CHIP_NO_ERROR) { | ||
callback->Cancel(); | ||
delete callback; | ||
return NO; | ||
} | ||
return YES; | ||
} | ||
|
||
{{#if (isWritableAttribute)}} | ||
- (BOOL)writeAttribute{{asCamelCased name false}}:(CHIPDeviceCallback)onCompletion value:({{asUnderlyingZclType type}})value | ||
{ | ||
CHIPCallbackBridge * callback = new CHIPCallbackBridge(onCompletion, _callbackQueue); | ||
if (!callback) { | ||
return NO; | ||
} | ||
|
||
CHIP_ERROR err = self.cppCluster.WriteAttribute{{asCamelCased name false}}(callback, value); | ||
if (err != CHIP_NO_ERROR) { | ||
callback->Cancel(); | ||
delete callback; | ||
return NO; | ||
} | ||
return YES; | ||
} | ||
|
||
{{/if}} | ||
{{#if (isReportableAttribute)}} | ||
- (BOOL) reportAttribute{{asCamelCased name false}}:(CHIPDeviceCallback)onCompletion onChange:(CHIPDeviceCallback)onChange minInterval:(uint16_t)minInterval maxInterval:(uint16_t)maxInterval{{#unless (isDiscreteType)}} change:({{chipType}})change{{/unless}} | ||
{ | ||
CHIPCallbackBridge * completionCallback = new CHIPCallbackBridge(onCompletion, _callbackQueue); | ||
if (!completionCallback) { | ||
return NO; | ||
} | ||
|
||
CHIPCallbackBridge * changeCallback = new CHIPCallbackBridge(onChange, _callbackQueue); | ||
if (!changeCallback) { | ||
return NO; | ||
} | ||
|
||
CHIP_ERROR err = self.cppCluster.ReportAttribute{{asCamelCased name false}}(completionCallback, changeCallback, minInterval, maxInterval{{#unless (isDiscreteType)}}, change{{/unless}}); | ||
if (err != CHIP_NO_ERROR) { | ||
completionCallback->Cancel(); | ||
changeCallback->Cancel(); | ||
delete completionCallback; | ||
delete changeCallback; | ||
return NO; | ||
} | ||
return YES; | ||
} | ||
|
||
{{/if}} | ||
{{/chip_server_cluster_attributes}} | ||
|
||
@end | ||
|
||
{{/chip_server_clusters}} |
40 changes: 40 additions & 0 deletions
40
src/app/zap-templates/templates/chip/CHIPClustersObjc.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{{> header}} | ||
|
||
#ifndef CHIP_CLUSTERS_H | ||
#define CHIP_CLUSTERS_H | ||
|
||
#import <CHIP/CHIPDeviceCallback.h> | ||
#import <Foundation/Foundation.h> | ||
|
||
@class CHIPDevice; | ||
|
||
{{#chip_server_clusters}} | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface CHIP{{asCamelCased name false}} : NSObject | ||
|
||
- (nullable instancetype)initWithDevice:(CHIPDevice *)device endpoint:(uint8_t)endpoint queue:(dispatch_queue_t)queue; | ||
{{#chip_server_cluster_commands}} | ||
- (BOOL){{asCamelCased name}}:(CHIPDeviceCallback)onCompletion{{#chip_server_cluster_command_arguments}} {{asCamelCased label}}:({{#if (isStrEqual chipType "chip::ClusterId")}}uint16_t{{else}}{{chipType}}{{/if}}){{asCamelCased label}}{{/chip_server_cluster_command_arguments}}; | ||
{{/chip_server_cluster_commands}} | ||
|
||
{{#chip_server_cluster_attributes}} | ||
- (BOOL)readAttribute{{asCamelCased name false}}:(CHIPDeviceCallback)onCompletion; | ||
{{#if (isWritableAttribute)}} | ||
- (BOOL)writeAttribute{{asCamelCased name false}}:(CHIPDeviceCallback)onCompletion value:({{asUnderlyingZclType type}})value; | ||
{{/if}} | ||
{{#if (isReportableAttribute)}} | ||
- (BOOL) reportAttribute{{asCamelCased name false}}:(CHIPDeviceCallback)onCompletion onChange:(CHIPDeviceCallback)onChange minInterval:(uint16_t)minInterval maxInterval:(uint16_t)maxInterval{{#unless (isDiscreteType)}} change:({{chipType}})change{{/unless}}; | ||
{{/if}} | ||
{{/chip_server_cluster_attributes}} | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
+ (instancetype)new NS_UNAVAILABLE; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
{{/chip_server_clusters}} | ||
|
||
#endif /* CHIP_CLUSTERS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.