14
14
#import "NSStringSpanConversion.h"
15
15
#import "NSDataSpanConversion.h"
16
16
17
+ #include <app-common/zap-generated/cluster-objects.h>
17
18
#include <controller/CHIPCluster.h>
18
19
#include <lib/support/CHIPListUtils.h>
19
20
#include <platform/CHIPDeviceLayer.h>
@@ -53,7 +54,6 @@ using chip::System::Clock::Seconds16;
53
54
{{! This is used as the implementation for both the new-name and old-name bits, so check for both here. }}
54
55
{{#if (or (isSupported cluster command=command)
55
56
(isSupported (compatClusterNameRemapping parent.name) command=(compatCommandNameRemapping parent.name name)))}}
56
- {{#*inline "callbackName"}}{{#if hasSpecificResponse}}{{cluster}}Cluster{{asUpperCamelCase responseName preserveAcronyms=true}}{{else}}CommandSuccess{{/if}}{{/inline}}
57
57
{{#*inline "paramsType"}}
58
58
{{#unless (isSupported cluster command=command)}}
59
59
MTR{{compatClusterNameRemapping parent.name}}Cluster{{compatCommandNameRemapping parent.name name}}Params
@@ -69,61 +69,39 @@ MTR{{cluster}}Cluster{{command}}Params
69
69
{{/unless}}
70
70
- (void){{asLowerCamelCase name}}WithParams: ({{> paramsType}} * {{#unless commandHasRequiredField}}_Nullable{{/unless}})params completion:({{>command_completion_type command=.}})completion
71
71
{
72
- // Make a copy of params before we go async.
73
- params = [params copy];
74
- auto * bridge = new MTR{{>callbackName}}CallbackBridge(self.callbackQueue,
75
- {{#if hasSpecificResponse}}
76
- {{! This treats completion as taking an id for the data. This is
77
- not great from a type-safety perspective, of course. }}
78
- completion,
79
- {{else}}
80
- {{! For now, don't change the bridge API; instead just use an adapter
81
- to invoke our completion handler. This is not great from a
82
- type-safety perspective, of course. }}
83
- ^(id _Nullable value, NSError * _Nullable error) {
84
- completion(error);
85
- },
86
- {{/if}}
87
- ^(ExchangeManager & exchangeManager, const SessionHandle & session, {{>callbackName}}CallbackType successCb, MTRErrorCallback failureCb, MTRCallbackBridgeBase * bridge) {
88
- auto * typedBridge = static_cast<MTR{{>callbackName}}CallbackBridge *>(bridge);
89
- Optional<uint16_t> timedInvokeTimeoutMs;
90
- Optional<Timeout> invokeTimeout;
91
- ListFreer listFreer;
92
- {{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Type request;
93
- if (params != nil) {
94
- if (params.timedInvokeTimeoutMs != nil) {
95
- params.timedInvokeTimeoutMs = MTRClampedNumber(params.timedInvokeTimeoutMs, @(1), @(UINT16_MAX));
96
- timedInvokeTimeoutMs.SetValue(params.timedInvokeTimeoutMs.unsignedShortValue);
97
- }
98
- if (params.serverSideProcessingTimeout != nil) {
99
- // Clamp to a number of seconds that will not overflow 32-bit
100
- // int when converted to ms.
101
- auto * serverSideProcessingTimeout = MTRClampedNumber(params.serverSideProcessingTimeout, @(0), @(UINT16_MAX));
102
- invokeTimeout.SetValue(Seconds16(serverSideProcessingTimeout.unsignedShortValue));
103
- }
104
- }
105
- {{#if mustUseTimedInvoke}}
106
- if (!timedInvokeTimeoutMs.HasValue()) {
107
- timedInvokeTimeoutMs.SetValue(10000);
108
- }
72
+ if (params == nil) {
73
+ params = [[{{> paramsType}} alloc] init];
74
+ }
75
+
76
+ auto responseHandler = ^(id _Nullable response, NSError * _Nullable error) {
77
+ {{#if hasSpecificResponse}}
78
+ completion(response, error);
79
+ {{else}}
80
+ completion(error);
109
81
{{/if}}
110
- {{#zcl_command_arguments}}
111
- {{#first}}
112
- {{#unless parent.commandHasRequiredField}}
113
- if (params != nil) {
114
- {{/unless}}
115
- {{/first}}
116
- {{>encode_value target=(concat "request." (asLowerCamelCase label)) source=(concat "params." (asStructPropertyName label)) cluster=parent.parent.name errorCode="return CHIP_ERROR_INVALID_ARGUMENT;" depth=0}}
117
- {{#last}}
118
- {{#unless parent.commandHasRequiredField}}
119
- }
120
- {{/unless}}
121
- {{/last}}
122
- {{/zcl_command_arguments}}
82
+ };
123
83
124
- return MTRStartInvokeInteraction(typedBridge, request, exchangeManager, session, successCb, failureCb, self.endpoint, timedInvokeTimeoutMs, invokeTimeout);
125
- });
126
- std::move(*bridge).DispatchAction(self.device);
84
+ auto * timedInvokeTimeoutMs = params.timedInvokeTimeoutMs;
85
+ {{#if mustUseTimedInvoke}}
86
+ if (timedInvokeTimeoutMs == nil) {
87
+ timedInvokeTimeoutMs = @(10000);
88
+ }
89
+ {{/if}}
90
+
91
+ using RequestType = {{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Type;
92
+ [self.device _invokeKnownCommandWithEndpointID:@(self.endpoint)
93
+ clusterID:@(RequestType::GetClusterId())
94
+ commandID:@(RequestType::GetCommandId())
95
+ commandPayload:params
96
+ timedInvokeTimeout:timedInvokeTimeoutMs
97
+ serverSideProcessingTimeout:params.serverSideProcessingTimeout
98
+ {{#if hasSpecificResponse}}
99
+ responseClass:MTR{{cluster}}Cluster{{asUpperCamelCase responseName preserveAcronyms=true}}Params.class
100
+ {{else}}
101
+ responseClass:nil
102
+ {{/if}}
103
+ queue:self.callbackQueue
104
+ completion:responseHandler];
127
105
}
128
106
{{/if}}
129
107
{{/inline}}
0 commit comments