blob: e630dbb54b043cfaac028fa5a03e662f6cc37798 [file] [log] [blame]
{{> header}}
{{#if (chip_has_client_clusters)}}
package chip.devicecontroller;
import androidx.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() {}
}
public interface OctetStringAttributeCallback {
/** Indicates a successful read for an OCTET_STRING attribute. */
void onSuccess(byte[] value);
void onError(Exception error);
default void onSubscriptionEstablished() {}
}
public interface IntegerAttributeCallback {
void onSuccess(int value);
void onError(Exception error);
default void onSubscriptionEstablished() {}
}
public interface LongAttributeCallback {
void onSuccess(long value);
void onError(Exception error);
default void onSubscriptionEstablished() {}
}
public interface BooleanAttributeCallback {
void onSuccess(boolean value);
void onError(Exception error);
default void onSubscriptionEstablished() {}
}
public interface FloatAttributeCallback {
void onSuccess(float value);
void onError(Exception error);
default void onSubscriptionEstablished() {}
}
public interface DoubleAttributeCallback {
void onSuccess(double value);
void onError(Exception error);
default void onSubscriptionEstablished() {}
}
public static abstract class BaseChipCluster {
protected long chipClusterPtr;
public BaseChipCluster(long devicePtr, int endpointId) {
chipClusterPtr = initWithDevice(devicePtr, endpointId);
}
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;
}
}
}
{{#chip_client_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);
{{#chip_cluster_commands}}
{{#unless mustUseTimedInvoke}}
public void {{asLowerCamelCase name}}({{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} callback
{{#chip_cluster_command_arguments}}, {{asJavaType type chipType parent.parent.name includeAnnotations=true}} {{asLowerCamelCase label}}{{/chip_cluster_command_arguments}}) {
{{asLowerCamelCase name}}(chipClusterPtr, callback{{#chip_cluster_command_arguments}}, {{asLowerCamelCase label}}{{/chip_cluster_command_arguments}}, null);
}
{{/unless}}
public void {{asLowerCamelCase name}}({{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} callback
{{#chip_cluster_command_arguments}}, {{asJavaType type chipType parent.parent.name includeAnnotations=true}} {{asLowerCamelCase label}}{{/chip_cluster_command_arguments}}
, int timedInvokeTimeoutMs) {
{{asLowerCamelCase name}}(chipClusterPtr, callback{{#chip_cluster_command_arguments}}, {{asLowerCamelCase label}}{{/chip_cluster_command_arguments}}, timedInvokeTimeoutMs);
}
{{/chip_cluster_commands}}
{{#chip_cluster_commands}}
private native void {{asLowerCamelCase name}}(long chipClusterPtr, {{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} Callback
{{#chip_cluster_command_arguments}}, {{asJavaType type chipType parent.parent.name includeAnnotations=true}} {{asLowerCamelCase label}}{{/chip_cluster_command_arguments}}
, @Nullable Integer timedInvokeTimeoutMs);
{{/chip_cluster_commands}}
{{#chip_cluster_responses}}
public interface {{asUpperCamelCase name}}Callback {
void onSuccess({{#chip_cluster_response_arguments}}{{#not_first}}, {{/not_first}}{{asJavaType type chipType parent.parent.name includeAnnotations=true}} {{asLowerCamelCase label}}{{/chip_cluster_response_arguments}});
void onError(Exception error);
}
{{/chip_cluster_responses}}
{{#chip_server_cluster_attributes}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_basic_global_response}}
{{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() {}
}
{{else}}
public interface {{asUpperCamelCase name}}AttributeCallback {
void onSuccess({{#if isNullable}}@Nullable{{/if}} {{>asJavaTypeForEntry isArray=false}} value);
void onError(Exception ex);
default void onSubscriptionEstablished() {}
}
{{/if}}
{{/if_basic_global_response}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{#chip_server_cluster_attributes}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
public void read{{asUpperCamelCase name}}Attribute(
{{#if_basic_global_response}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}}
) {
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_global_response}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}},
int minInterval, int maxInterval) {
subscribe{{asCamelCased name false}}Attribute(chipClusterPtr, callback, minInterval, maxInterval);
}
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{#chip_server_cluster_attributes}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
private native void read{{asUpperCamelCase name}}Attribute(long chipClusterPtr,
{{#if_basic_global_response}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}}
);
{{#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_global_response}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}}, int minInterval, int maxInterval);
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
}
{{#not_last}}
{{/not_last}}
{{/chip_client_clusters}}
}
{{/if}}