Skip to content

Commit 07e038a

Browse files
vivien-applepull[bot]
authored andcommitted
[Darwin] Use InvokeCommand instead of CHIPClusters.cpp for commands (#11628)
* Use InvokeCommand instead of CHIPClusters.cpp for commands * Update gen code
1 parent e73a3eb commit 07e038a

11 files changed

+2399
-914
lines changed

src/darwin/Framework/CHIP.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
1ED276E026C57CF000547A89 /* CHIPCallbackBridge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1ED276DF26C57CF000547A89 /* CHIPCallbackBridge.mm */; };
3939
1ED276E226C5812A00547A89 /* CHIPCluster.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1ED276E126C5812A00547A89 /* CHIPCluster.mm */; };
4040
1ED276E426C5832500547A89 /* CHIPCluster.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED276E326C5832500547A89 /* CHIPCluster.h */; settings = {ATTRIBUTES = (Public, ); }; };
41+
1EF900A0273AC39C006A4018 /* CHIPClustersInvoke.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1EF9009E273AC39C006A4018 /* CHIPClustersInvoke.cpp */; };
4142
2C1B027A2641DB4E00780EF1 /* CHIPOperationalCredentialsDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2C1B02782641DB4E00780EF1 /* CHIPOperationalCredentialsDelegate.mm */; };
4243
2C1B027B2641DB4E00780EF1 /* CHIPOperationalCredentialsDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C1B02792641DB4E00780EF1 /* CHIPOperationalCredentialsDelegate.h */; };
4344
2C222AD0255C620600E446B9 /* CHIPDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C222ACE255C620600E446B9 /* CHIPDevice.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -124,6 +125,7 @@
124125
1ED276DF26C57CF000547A89 /* CHIPCallbackBridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CHIPCallbackBridge.mm; path = "zap-generated/CHIPCallbackBridge.mm"; sourceTree = "<group>"; };
125126
1ED276E126C5812A00547A89 /* CHIPCluster.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CHIPCluster.mm; sourceTree = "<group>"; };
126127
1ED276E326C5832500547A89 /* CHIPCluster.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHIPCluster.h; sourceTree = "<group>"; };
128+
1EF9009E273AC39C006A4018 /* CHIPClustersInvoke.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CHIPClustersInvoke.cpp; path = "../../../../zzz_generated/controller-clusters/zap-generated/CHIPClustersInvoke.cpp"; sourceTree = "<group>"; };
127129
2C1B02782641DB4E00780EF1 /* CHIPOperationalCredentialsDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CHIPOperationalCredentialsDelegate.mm; sourceTree = "<group>"; };
128130
2C1B02792641DB4E00780EF1 /* CHIPOperationalCredentialsDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHIPOperationalCredentialsDelegate.h; sourceTree = "<group>"; };
129131
2C222ACE255C620600E446B9 /* CHIPDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHIPDevice.h; sourceTree = "<group>"; };
@@ -222,6 +224,7 @@
222224
1EC4CE5825CC26AB00D7304F /* CHIPGeneratedFiles */ = {
223225
isa = PBXGroup;
224226
children = (
227+
1EF9009E273AC39C006A4018 /* CHIPClustersInvoke.cpp */,
225228
1EC3238C271999E2002A8BF0 /* cluster-objects.cpp */,
226229
1E16A8F926B9835600683C53 /* CHIPTestClustersObjc.h */,
227230
1E16A8FA26B9835700683C53 /* CHIPTestClustersObjc.mm */,
@@ -517,6 +520,7 @@
517520
B2E0D7B6245B0B5C003C5B48 /* CHIPManualSetupPayloadParser.mm in Sources */,
518521
1E85732826551A490050A4D9 /* attribute-table.cpp in Sources */,
519522
1E85732626551A490050A4D9 /* attribute-storage.cpp in Sources */,
523+
1EF900A0273AC39C006A4018 /* CHIPClustersInvoke.cpp in Sources */,
520524
1E85732C26551A490050A4D9 /* DataModelHandler.cpp in Sources */,
521525
1E85733126551A490050A4D9 /* chip-message-send.cpp in Sources */,
522526
1E85730F265519AE0050A4D9 /* attribute-size.cpp in Sources */,

src/darwin/Framework/CHIP/CHIPCallbackBridgeBase_internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#import "zap-generated/CHIPClientCallbacks.h"
2222
#import "zap-generated/CHIPClustersObjc.h"
2323

24+
#include <app/data-model/NullObject.h>
2425
#include <platform/CHIPDeviceLayer.h>
2526

2627
typedef CHIP_ERROR (^CHIPActionBlock)(chip::Callback::Cancelable * success, chip::Callback::Cancelable * failure);

src/darwin/Framework/CHIP/templates/CHIPCallbackBridge_internal.zapt

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
#include <app/data-model/DecodableList.h>
88
#include <app-common/zap-generated/cluster-objects.h>
99

10+
typedef void (*CHIPDefaultSuccessCallbackType)(void *, const chip::app::DataModel::NullObjectType &);
11+
typedef void (*CHIPDefaultFailureCallbackType)(void *, EmberAfStatus);
12+
13+
{{#chip_client_clusters}}
14+
{{#chip_cluster_responses}}
15+
typedef void (*CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}CallbackType)(void *, const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType &);
16+
{{/chip_cluster_responses}}
17+
{{/chip_client_clusters}}
18+
1019
{{#>CHIPCallbackBridge header="1" partial-type="" }}DefaultSuccessCallback{{/CHIPCallbackBridge}}
1120
{{#>CHIPCallbackBridge header="1" partial-type="Octet_String"}}OctetStringAttributeCallback{{/CHIPCallbackBridge}}
1221
{{#>CHIPCallbackBridge header="1" partial-type="Char_String" }}CharStringAttributeCallback{{/CHIPCallbackBridge}}

src/darwin/Framework/CHIP/templates/CHIPClustersObjc-src.zapt

+7-13
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
#import "CHIPDevice.h"
1010
#import "CHIPDevice_Internal.h"
1111

12+
using chip::Callback::Callback;
1213
using chip::Callback::Cancelable;
14+
using namespace chip::app::Clusters;
1315

1416
{{#chip_client_clusters}}
15-
1617
@implementation CHIP{{asUpperCamelCase name}}
1718

1819
- (chip::Controller::ClusterBase *)getCluster
@@ -22,25 +23,18 @@ using chip::Callback::Cancelable;
2223

2324
{{#chip_cluster_commands}}
2425
{{#*inline "callbackName"}}{{#if hasSpecificResponse}}{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase responseName}}{{else}}DefaultSuccess{{/if}}{{/inline}}
25-
{{#*inline "callbackParams"}}{{#chip_cluster_command_arguments_with_structs_expanded}},
26-
{{#if_chip_enum type}}
27-
static_cast<{{chipType}}>({{asLowerCamelCase label}})
28-
{{else if (isOctetString type)}}
29-
[self asByteSpan:{{asLowerCamelCase label}}]
30-
{{else if (isCharString type)}}
31-
[self asCharSpan:{{asLowerCamelCase label}}]
32-
{{else}}
33-
{{asLowerCamelCase label}}
34-
{{/if_chip_enum}}
35-
{{/chip_cluster_command_arguments_with_structs_expanded}}{{/inline}}
3626
{{#if (zcl_command_arguments_count this.id)}}
3727
- (void){{asLowerCamelCase name}}:{{#chip_cluster_command_arguments_with_structs_expanded}}{{#not_first}}{{asLowerCamelCase label}}:{{/not_first}}({{asObjectiveCBasicType type}}){{asLowerCamelCase label}} {{/chip_cluster_command_arguments_with_structs_expanded}}responseHandler:(ResponseHandler)responseHandler
3828
{{else}}
3929
- (void){{asLowerCamelCase name}}:(ResponseHandler)responseHandler
4030
{{/if}}
4131
{
32+
{{>encode_command}}
33+
4234
new CHIP{{>callbackName}}CallbackBridge(self.callbackQueue, responseHandler, ^(Cancelable * success, Cancelable * failure) {
43-
return self.cppCluster.{{asUpperCamelCase name}}(success, failure{{>callbackParams}});
35+
auto successFn = Callback<CHIP{{>callbackName}}CallbackType>::FromCancelable(success);
36+
auto failureFn = Callback<CHIPDefaultFailureCallbackType>::FromCancelable(failure);
37+
return self.cppCluster.InvokeCommand(request, successFn->mContext, successFn->mCall, failureFn->mCall);
4438
});
4539
}
4640
{{/chip_cluster_commands}}

src/darwin/Framework/CHIP/templates/partials/CHIPCallbackBridge.zapt

+7-18
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{{#if header}}
2-
class CHIP{{> @partial-block}}Bridge : public CHIPCallbackBridge<{{> @partial-block}}>
2+
{{#*inline "callbackType"}}{{#if (isStrEqual partial-type "Command")}}CHIP{{> @partial-block}}Type{{else}}{{> @partial-block}}{{/if}}{{/inline}}
3+
class CHIP{{> @partial-block}}Bridge : public CHIPCallbackBridge<{{>callbackType}}>
34
{
45
public:
56
CHIP{{> @partial-block}}Bridge(dispatch_queue_t queue, ResponseHandler handler, CHIPActionBlock action, bool keepAlive = false)
6-
: CHIPCallbackBridge<{{> @partial-block}}>(queue, handler, action, OnSuccessFn, keepAlive)
7+
: CHIPCallbackBridge<{{>callbackType}}>(queue, handler, action, OnSuccessFn, keepAlive)
78
{};
89

910
static void OnSuccessFn(void * context
1011
{{#if (isStrEqual partial-type "Command")}}
11-
{{#chip_cluster_response_arguments}}, {{asUnderlyingZclType type}} {{asSymbol label}}{{/chip_cluster_response_arguments}}
12+
, const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & data
1213
{{else if (isStrEqual partial-type "List")}}
1314
, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} list
1415
{{else if partial-type}}
@@ -20,7 +21,7 @@ public:
2021
{{else}}
2122
void CHIP{{> @partial-block}}Bridge::OnSuccessFn(void * context
2223
{{#if (isStrEqual partial-type "Command")}}
23-
{{#chip_cluster_response_arguments}}, {{asUnderlyingZclType type}} {{asSymbol label}}{{/chip_cluster_response_arguments}}
24+
, const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & data
2425
{{else if (isStrEqual partial-type "List")}}
2526
, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} list
2627
{{else if partial-type}}
@@ -30,20 +31,8 @@ void CHIP{{> @partial-block}}Bridge::OnSuccessFn(void * context
3031
)
3132
{
3233
{{#if (isStrEqual partial-type "Command")}}
33-
DispatchSuccess(context, @{
34-
{{#chip_cluster_response_arguments}}
35-
{{#if isArray}}
36-
// {{asSymbol label}} : {{asUnderlyingZclType type}}
37-
// Conversion from this type to Objc is not properly implemented yet
38-
{{else if (isOctetString type)}}
39-
@"{{asSymbol label}}" : [NSData dataWithBytes:{{asSymbol label}}.data() length:{{asSymbol label}}.size()],
40-
{{else if (isCharString type)}}
41-
@"{{asSymbol label}}" : [[NSString alloc] initWithBytes:{{asSymbol label}}.data() length:{{asSymbol label}}.size() encoding:NSUTF8StringEncoding],
42-
{{else}}
43-
@"{{asSymbol label}}" : [NSNumber numberWith{{asObjectiveCNumberType label type false}}:{{asSymbol label}}],
44-
{{/if}}
45-
{{/chip_cluster_response_arguments}}
46-
});
34+
{{>decode_response}}
35+
DispatchSuccess(context, response);
4736
{{else if (isStrEqual partial-type "List")}}
4837
id array = [[NSMutableArray alloc] init];
4938
auto iter = list.begin();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
id response = @{
2+
{{#chip_cluster_response_arguments}}
3+
@"{{asSymbol label}}": {{#if isOptional}}data.{{asLowerCamelCase label}}.HasValue() == false ? [NSNull null] : {{#if isNullable}}data.{{asLowerCamelCase label}}.Value().IsNull() ? [NSNull null] : {{/if}}{{/if}}
4+
{{~#*inline "item"}}data.{{asLowerCamelCase name}}{{#if isOptional}}.Value(){{/if}}{{#if isNullable}}.Value(){{/if}}{{/inline}}
5+
{{#if isArray}}
6+
[NSNull null], /* Array - Conversion from this type to Objc is not properly implemented yet */
7+
{{else if (isOctetString type)}}
8+
[NSData dataWithBytes:{{>item}}.data() length:{{>item}}.size()],
9+
{{else if (isCharString type)}}
10+
[[NSString alloc] initWithBytes:{{>item}}.data() length:{{>item}}.size() encoding:NSUTF8StringEncoding],
11+
{{else}}
12+
[NSNumber numberWith{{asObjectiveCNumberType label type false}}:{{>item}}],
13+
{{/if}}
14+
{{/chip_cluster_response_arguments}}
15+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Type request;
2+
{{#chip_cluster_command_arguments}}
3+
{{#*inline "value"}}
4+
{{! TODO Implement complex types parsing in order to properly set the request parameters }}
5+
{{#if isArray}}
6+
{{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}();
7+
{{else if isStruct}}
8+
{{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}();
9+
{{else if (isOctetString type)}}
10+
[self asByteSpan:{{asLowerCamelCase label}}]
11+
{{else if (isCharString type)}}
12+
[self asCharSpan:{{asLowerCamelCase label}}]
13+
{{else if isBitmap}}
14+
static_cast<decltype(request.{{asLowerCamelCase label}})>({{asLowerCamelCase label}})
15+
{{else}}
16+
{{#if_chip_enum type}}
17+
static_cast<decltype(request.{{asLowerCamelCase label}})>({{asLowerCamelCase label}})
18+
{{else}}
19+
{{asLowerCamelCase label}}
20+
{{/if_chip_enum}}
21+
{{/if}}
22+
{{/inline}}
23+
request.{{asLowerCamelCase label}} = {{#if isOptional}}{{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}({{/if}}{{#if isNullable}}chip::app::DataModel::Nullable<{{chipType}}>({{/if}}{{>value}}{{#if isNullable}}){{/if}}{{#if isOptional}}){{/if}};
24+
{{/chip_cluster_command_arguments}}

src/darwin/Framework/CHIP/templates/templates.json

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
{
2424
"name": "CHIPCallbackBridge",
2525
"path": "partials/CHIPCallbackBridge.zapt"
26+
},
27+
{
28+
"name": "encode_command",
29+
"path": "partials/encode_command.zapt"
30+
},
31+
{
32+
"name": "decode_response",
33+
"path": "partials/decode_response.zapt"
2634
}
2735
],
2836
"templates": [

0 commit comments

Comments
 (0)