blob: 59cd477d802c89f33c1911e3822c958d6eef2b9b [file] [log] [blame]
{{> header}}
package chip.devicecontroller;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class ChipClusters {
public interface DefaultClusterCallback {
void onSuccess();
void onError(Exception error);
}
public interface CharStringAttributeCallback {
/** Indicates a successful read for a CHAR_STRING attribute. */
void onSuccess(String value);
void onError(Exception error);
{{! TODO: use SubscriptionEstablishedCallback instead, here and below. }}
default void onSubscriptionEstablished(long subscriptionId) {}
}
public interface OctetStringAttributeCallback {
/** Indicates a successful read for an OCTET_STRING attribute. */
void onSuccess(byte[] value);
void onError(Exception error);
default void onSubscriptionEstablished(long subscriptionId) {}
}
public interface IntegerAttributeCallback {
void onSuccess(int value);
void onError(Exception error);
default void onSubscriptionEstablished(long subscriptionId) {}
}
public interface LongAttributeCallback {
void onSuccess(long value);
void onError(Exception error);
default void onSubscriptionEstablished(long subscriptionId) {}
}
public interface BooleanAttributeCallback {
void onSuccess(boolean value);
void onError(Exception error);
default void onSubscriptionEstablished(long subscriptionId) {}
}
public interface FloatAttributeCallback {
void onSuccess(float value);
void onError(Exception error);
default void onSubscriptionEstablished(long subscriptionId) {}
}
public interface DoubleAttributeCallback {
void onSuccess(double value);
void onError(Exception error);
default void onSubscriptionEstablished(long subscriptionId) {}
}
public static abstract class BaseChipCluster {
protected long chipClusterPtr;
public BaseChipCluster(long devicePtr, int endpointId) {
chipClusterPtr = initWithDevice(devicePtr, endpointId);
}
/**
* Sets the timeout, in milliseconds, after which commands sent through this cluster will fail
* with a timeout (regardless of whether or not a response has been received). If set to an
* empty optional, the default timeout will be used.
*/
public void setCommandTimeout(Optional<Long> timeoutMillis) {
setCommandTimeout(chipClusterPtr, timeoutMillis);
}
private native void setCommandTimeout(long clusterPtr, Optional<Long> timeoutMillis);
/** Returns the current timeout (in milliseconds) for commands sent through this cluster. */
public Optional<Long> getCommandTimeout() {
Optional<Long> timeout = getCommandTimeout(chipClusterPtr);
return timeout == null ? Optional.empty() : timeout;
}
private native Optional<Long> getCommandTimeout(long clusterPtr);
public abstract long initWithDevice(long devicePtr, int endpointId);
public native void deleteCluster(long chipClusterPtr);
@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();
if (chipClusterPtr != 0) {
deleteCluster(chipClusterPtr);
chipClusterPtr = 0;
}
}
}
{{#zcl_clusters}}
public static class {{asUpperCamelCase name}}Cluster extends BaseChipCluster {
public static final long CLUSTER_ID = {{code}}L;
public {{asUpperCamelCase name}}Cluster(long devicePtr, int endpointId) {
super(devicePtr, endpointId);
}
@Override
public native long initWithDevice(long devicePtr, int endpointId);
{{#all_user_cluster_generated_commands}}
{{#if_compare clusterId ../id operator='=='}}
{{#if (is_str_equal commandSource 'client')}}
{{#unless mustUseTimedInvoke}}
public void {{asLowerCamelCase name}}({{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} callback
{{#zcl_command_arguments}}, {{asJavaType type chipType parent.parent.name includeAnnotations=true clusterId=parent.parent.id}} {{asLowerCamelCase label}}{{/zcl_command_arguments}}) {
{{asLowerCamelCase name}}(chipClusterPtr, callback{{#zcl_command_arguments}}, {{asLowerCamelCase label}}{{/zcl_command_arguments}}, null);
}
{{/unless}}
public void {{asLowerCamelCase name}}({{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} callback
{{#zcl_command_arguments}}, {{asJavaType type chipType parent.parent.name includeAnnotations=true clusterId=parent.parent.id}} {{asLowerCamelCase label}}{{/zcl_command_arguments}}
, int timedInvokeTimeoutMs) {
{{asLowerCamelCase name}}(chipClusterPtr, callback{{#zcl_command_arguments}}, {{asLowerCamelCase label}}{{/zcl_command_arguments}}, timedInvokeTimeoutMs);
}
{{/if}}
{{/if_compare}}
{{/all_user_cluster_generated_commands}}
{{#all_user_cluster_generated_commands}}
{{#if_compare clusterId ../id operator='=='}}
{{#if (is_str_equal commandSource 'client')}}
private native void {{asLowerCamelCase name}}(long chipClusterPtr, {{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} Callback
{{#zcl_command_arguments}}, {{asJavaType type chipType parent.parent.name includeAnnotations=true clusterId=parent.parent.id}} {{asLowerCamelCase label}}{{/zcl_command_arguments}}
, @Nullable Integer timedInvokeTimeoutMs);
{{/if}}
{{/if_compare}}
{{/all_user_cluster_generated_commands}}
{{#all_user_cluster_generated_commands}}
{{#if_compare clusterId ../id operator='=='}}
{{#if (is_str_equal commandSource 'server')}}
public interface {{asUpperCamelCase name}}Callback {
void onSuccess({{#zcl_command_arguments}}{{#not_first}}, {{/not_first}}{{asJavaType type chipType parent.parent.name includeAnnotations=true clusterId=parent.parent.id}} {{asLowerCamelCase label}}{{/zcl_command_arguments}});
void onError(Exception error);
}
{{/if}}
{{/if_compare}}
{{/all_user_cluster_generated_commands}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{#if_unsupported_attribute_callback type isArray ../id}}
{{else}}
{{#if_basic_attribute type ../id}}
{{else}}
{{! NOTE: asJavaType ends up sniffing for isArray on the context. Since we want the type of our _entry_, force isArray to
false. }}
{{~#*inline "asJavaTypeForEntry"}}{{asJavaType type null parent.name forceNotList=true}}{{/inline~}}
{{#if isArray}}
public interface {{asUpperCamelCase name}}AttributeCallback {
void onSuccess({{#if isNullable}}@Nullable{{/if}} List<{{>asJavaTypeForEntry isArray=false}}> valueList);
void onError(Exception ex);
default void onSubscriptionEstablished(long subscriptionId) {}
}
{{else}}
public interface {{asUpperCamelCase name}}AttributeCallback {
void onSuccess({{#if isNullable}}@Nullable{{/if}} {{>asJavaTypeForEntry isArray=false}} value);
void onError(Exception ex);
default void onSubscriptionEstablished(long subscriptionId) {}
}
{{/if}}
{{/if_basic_attribute}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{! TODO: Add support for struct-typed attributes }}
{{#if_unsupported_attribute_callback type isArray ../id}}
{{else}}
public void read{{asUpperCamelCase name}}Attribute(
{{#if_basic_attribute type ../id}}
{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_attribute}}
) {
read{{asUpperCamelCase name}}Attribute(chipClusterPtr, callback);
}
{{#if isWritableAttribute}}
{{#unless mustUseTimedWrite}}
public void write{{asUpperCamelCase name}}Attribute(DefaultClusterCallback callback, {{asJavaType type chipType parent.name}} value) {
write{{asUpperCamelCase name}}Attribute(chipClusterPtr, callback, value, null);
}
{{/unless}}
public void write{{asUpperCamelCase name}}Attribute(DefaultClusterCallback callback, {{asJavaType type chipType parent.name}} value, int timedWriteTimeoutMs) {
write{{asUpperCamelCase name}}Attribute(chipClusterPtr, callback, value, timedWriteTimeoutMs);
}
{{/if}}
{{#if isReportableAttribute}}
public void subscribe{{asCamelCased name false}}Attribute(
{{#if_basic_attribute type ../id}}
{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_attribute}},
int minInterval, int maxInterval) {
subscribe{{asCamelCased name false}}Attribute(chipClusterPtr, callback, minInterval, maxInterval);
}
{{/if}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{! TODO: Add support for struct-typed attributes }}
{{#if_unsupported_attribute_callback type isArray ../id }}
{{else}}
private native void read{{asUpperCamelCase name}}Attribute(long chipClusterPtr,
{{#if_basic_attribute type ../id}}
{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_attribute}}
);
{{#if isWritableAttribute}}
private native void write{{asUpperCamelCase name}}Attribute(long chipClusterPtr, DefaultClusterCallback callback, {{asJavaType type chipType parent.name}} value, @Nullable Integer timedWriteTimeoutMs);
{{/if}}
{{#if isReportableAttribute}}
private native void subscribe{{asCamelCased name false}}Attribute(long chipClusterPtr,
{{#if_basic_attribute type ../id}}
{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_attribute}}, int minInterval, int maxInterval);
{{/if}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}
}
{{#not_last}}
{{/not_last}}
{{/zcl_clusters}}
}