| {{#if header}} |
| {{#*inline "callbackType"}} |
| {{#if partial-type}} |
| {{#if (isStrEqual partial-type "Command")}} |
| {{> @partial-block}}Type |
| {{else}} |
| {{> @partial-block}} |
| {{/if}} |
| {{else}} |
| {{> @partial-block}} |
| {{/if}} |
| {{/inline}} |
| class MTR{{> @partial-block}}Bridge : public MTRCallbackBridge<{{>callbackType}}> |
| { |
| public: |
| MTR{{> @partial-block}}Bridge(dispatch_queue_t queue, ResponseHandler handler) |
| : MTRCallbackBridge<{{>callbackType}}>(queue, handler, OnSuccessFn) |
| {}; |
| |
| MTR{{> @partial-block}}Bridge(dispatch_queue_t queue, ResponseHandler handler, MTRActionBlock action) |
| : MTRCallbackBridge<{{>callbackType}}>(queue, handler, action, OnSuccessFn) |
| {}; |
| |
| static void OnSuccessFn(void * context |
| {{#if partial-type}} |
| {{#if (isStrEqual partial-type "Status")}} |
| {{! No more args in this case }} |
| {{else if (isStrEqual partial-type "Command")}} |
| , const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & data |
| {{else if (isStrEqual partial-type "CommandStatus")}} |
| , const chip::app::DataModel::NullObjectType & |
| {{else}} |
| UNEXPECTED PARTIAL TYPE |
| {{/if}} |
| {{else}} |
| , {{zapTypeToDecodableClusterObjectType type ns=ns isArgument=true}} value |
| {{/if}} |
| ); |
| }; |
| |
| {{#unless partial-type}} |
| class MTR{{> @partial-block}}SubscriptionBridge : public MTR{{> @partial-block}}Bridge |
| { |
| public: |
| MTR{{> @partial-block}}SubscriptionBridge(dispatch_queue_t queue, ResponseHandler handler, MTRActionBlock action, MTRSubscriptionEstablishedHandler establishedHandler) |
| : MTR{{> @partial-block}}Bridge(queue, handler, action), |
| mEstablishedHandler(establishedHandler) |
| {} |
| |
| void OnSubscriptionEstablished(); |
| using MTR{{> @partial-block}}Bridge::OnDone; |
| using MTR{{> @partial-block}}Bridge::KeepAliveOnCallback; |
| |
| private: |
| MTRSubscriptionEstablishedHandler mEstablishedHandler; |
| }; |
| {{/unless}} |
| |
| {{else}} |
| void MTR{{> @partial-block}}Bridge::OnSuccessFn(void * context |
| {{#if partial-type}} |
| {{#if (isStrEqual partial-type "Status")}} |
| {{! No more args in this case }} |
| {{else if (isStrEqual partial-type "Command")}} |
| , const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & data |
| {{else if (isStrEqual partial-type "CommandStatus")}} |
| , const chip::app::DataModel::NullObjectType & |
| {{else}} |
| UNEXPECTED PARTIAL TYPE |
| {{/if}} |
| {{else}} |
| , {{zapTypeToDecodableClusterObjectType type ns=ns isArgument=true}} value |
| {{/if}} |
| ) |
| { |
| {{#if partial-type}} |
| {{#if (isStrEqual partial-type "Status")}} |
| DispatchSuccess(context, nil); |
| {{else if (isStrEqual partial-type "Command")}} |
| auto * response = [MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}}Params new]; |
| {{#chip_cluster_response_arguments}} |
| { |
| {{>decode_value target=(concat "response." (asStructPropertyName label)) source=(concat "data." (asLowerCamelCase label)) cluster=parent.parent.name errorCode="OnFailureFn(context, err); return;" depth=0}} |
| } |
| {{/chip_cluster_response_arguments}} |
| DispatchSuccess(context, response); |
| {{else if (isStrEqual partial-type "CommandStatus")}} |
| DispatchSuccess(context, nil); |
| {{else}} |
| UNEXPECTED PARTIAL TYPE |
| {{/if}} |
| {{else}} |
| {{asObjectiveCType type ns}} objCValue; |
| {{>decode_value target="objCValue" source="value" cluster=ns errorCode="OnFailureFn(context, err); return;" depth=0}} |
| DispatchSuccess(context, objCValue); |
| {{/if}} |
| }; |
| |
| {{#unless partial-type}} |
| void MTR{{> @partial-block}}SubscriptionBridge::OnSubscriptionEstablished() |
| { |
| if (!mQueue) { |
| return; |
| } |
| |
| if (mEstablishedHandler != nil) { |
| dispatch_async(mQueue, mEstablishedHandler); |
| // On failure, mEstablishedHandler will be cleaned up by our destructor, |
| // but we can clean it up earlier on successful subscription |
| // establishment. |
| mEstablishedHandler = nil; |
| } |
| } |
| |
| {{/unless}} |
| {{/if}} |