blob: a535be1a73dfd3d7686e46efc20774fefe702fc6 [file] [log] [blame]
{{#if (chip_has_client_clusters)}}
{{> header}}
#import <Foundation/Foundation.h>
#import <CHIP/CHIPError_Internal.h>
#import "CHIPCallbackBridge_internal.h"
#import "CHIPCluster_internal.h"
#import "CHIPDevice.h"
#import "CHIPDevice_Internal.h"
#import "zap-generated/tests/CHIPClustersTest.h"
#import "zap-generated/CHIPTestClustersObjc.h"
#include <lib/support/CHIPListUtils.h>
#include <type_traits>
using chip::Callback::Callback;
using chip::Callback::Cancelable;
using namespace chip::app::Clusters;
{{#chip_client_clusters}}
@interface CHIPTest{{asUpperCamelCase name}} ()
@property (readonly) chip::Controller::{{asUpperCamelCase name}}ClusterTest cppCluster;
@end
@implementation CHIPTest{{asUpperCamelCase name}}
- (chip::Controller::ClusterBase *)getCluster
{
return &_cppCluster;
}
{{#chip_server_cluster_attributes}}
{{#unless isWritableAttribute}}
{{#*inline "attribute"}}Attribute{{asUpperCamelCase name}}{{/inline}}
{{#*inline "callbackName"}}DefaultSuccess{{/inline}}
- (void)write{{>attribute}}WithValue:({{asObjectiveCType type parent.name}})value completionHandler:(StatusCompletion)completionHandler
{
new CHIP{{>callbackName}}CallbackBridge(self.callbackQueue,
{{! For now, don't change the bridge API; instead just use an adapter
to invoke our completion handler. This is not great from a
type-safety perspective, of course. }}
^(id _Nullable ignored, NSError * _Nullable error) {
completionHandler(error);
},
^(Cancelable * success, Cancelable * failure) {
ListFreer listFreer;
using TypeInfo = {{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::TypeInfo;
TypeInfo::Type cppValue;
{{>encode_value target="cppValue" source="value" cluster=parent.name errorCode="return CHIP_ERROR_INVALID_ARGUMENT;" depth=0}}
auto successFn = Callback<CHIP{{>callbackName}}CallbackType>::FromCancelable(success);
auto failureFn = Callback<CHIPDefaultFailureCallbackType>::FromCancelable(failure);
return self.cppCluster.WriteAttribute<TypeInfo>(cppValue, successFn->mContext, successFn->mCall, failureFn->mCall);
});
}
{{/unless}}
{{/chip_server_cluster_attributes}}
@end
{{/chip_client_clusters}}
{{/if}}