blob: 1f6b97e9a2b24e8b4cb60e95686cdc302db77fbe [file] [log] [blame]
{{#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, bool keepAlive = false)
: MTRCallbackBridge<{{>callbackType}}>(queue, handler, OnSuccessFn, keepAlive)
{};
MTR{{> @partial-block}}Bridge(dispatch_queue_t queue, ResponseHandler handler, MTRActionBlock action, bool keepAlive = false)
: MTRCallbackBridge<{{>callbackType}}>(queue, handler, action, OnSuccessFn, keepAlive)
{};
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, true),
mEstablishedHandler(establishedHandler)
{}
static void OnSubscriptionEstablished(void * context);
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}}Cluster{{asUpperCamelCase name}}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(void * context)
{
auto * self = static_cast<MTR{{> @partial-block}}SubscriptionBridge *>(context);
if (!self->mQueue) {
return;
}
if (self->mEstablishedHandler != nil) {
dispatch_async(self->mQueue, self->mEstablishedHandler);
// On failure, mEstablishedHandler will be cleaned up by our destructor,
// but we can clean it up earlier on successful subscription
// establishment.
self->mEstablishedHandler = nil;
}
}
{{/unless}}
{{/if}}