blob: caa278adedb25e40972bb7e58098f4b6baf3dc48 [file] [log] [blame]
{{> header}}
{{#if (chip_has_client_clusters)}}
package chip.devicecontroller;
import androidx.annotation.Nullable;
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);
}
public interface OctetStringAttributeCallback {
/** Indicates a successful read for an OCTET_STRING attribute. */
void onSuccess(byte[] value);
void onError(Exception error);
}
public interface IntegerAttributeCallback {
void onSuccess(int value);
void onError(Exception error);
}
public interface LongAttributeCallback {
void onSuccess(long value);
void onError(Exception error);
}
public interface BooleanAttributeCallback {
void onSuccess(boolean value);
void onError(Exception error);
}
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 {{asUpperCamelCase name}}Cluster(long devicePtr, int endpointId) {
super(devicePtr, endpointId);
}
public static long clusterId() {
return Long.parseUnsignedLong("{{code}}");
}
@Override
public native long initWithDevice(long devicePtr, int endpointId);
{{#chip_cluster_commands}}
public void {{asLowerCamelCase name}}({{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} callback{{>command_arguments}}) {
{{asLowerCamelCase name}}(chipClusterPtr, callback{{#chip_cluster_command_arguments_with_structs_expanded}}, {{asLowerCamelCase label}}{{/chip_cluster_command_arguments_with_structs_expanded}});
}
{{/chip_cluster_commands}}
{{#chip_cluster_commands}}
private native void {{asLowerCamelCase name}}(long chipClusterPtr, {{#if hasSpecificResponse}}{{asUpperCamelCase responseName}}Callback{{else}}DefaultClusterCallback{{/if}} callback{{>command_arguments}});
{{/chip_cluster_commands}}
{{#chip_cluster_responses}}
public interface {{asUpperCamelCase name}}Callback {
void onSuccess({{>command_callback_responses parent=..}});
void onError(Exception error);
}
{{/chip_cluster_responses}}
{{#chip_server_cluster_attributes}}
{{#if isList}}
{{#if isStruct}}
public static class {{asUpperCamelCase name}}Attribute {
{{#chip_attribute_list_entryTypes}}
{{#if isNullable}}
{{! 'unless' blocks are temporary until optional array / struct implemented }}
{{#unless isArray}}
{{#unless isStruct}}
@Nullable
{{/unless}}
{{/unless}}
{{/if}}
{{#if isArray}}
{{! TODO: Add support for lists here }}
{{else if isStruct}}
{{! TODO: Add support for structs here }}
{{else if (isOctetString type)}}
public {{#if isOptional}}Optional<{{/if}}byte[]{{#if isOptional}}>{{/if}} {{asLowerCamelCase name}};
{{else if (isCharString type)}}
public {{#if isOptional}}Optional<{{/if}}String{{#if isOptional}}>{{/if}} {{asLowerCamelCase name}};
{{else}}
public {{#if isOptional}}Optional<{{/if}}{{asJavaBoxedType label type}}{{#if isOptional}}>{{/if}} {{asLowerCamelCase name}};
{{/if}}
{{/chip_attribute_list_entryTypes}}
public {{asUpperCamelCase name}}Attribute(
{{#chip_attribute_list_entryTypes}}
{{#if isNullable}}
{{#unless isArray}}
{{#unless isStruct}}
@Nullable
{{/unless}}
{{/unless}}
{{/if}}
{{#if isArray}}
{{! TODO: Add support for lists here }}
{{else if isStruct}}
{{! TODO: Add support for structs here }}
{{else if (isOctetString type)}}
{{#if isOptional}}Optional<{{/if}}byte[]{{#if isOptional}}>{{/if}} {{asLowerCamelCase name}} {{#notLastSupportedEntryTypes ..}},{{/notLastSupportedEntryTypes}}
{{else if (isCharString type)}}
{{#if isOptional}}Optional<{{/if}}String{{#if isOptional}}>{{/if}} {{asLowerCamelCase name}} {{#notLastSupportedEntryTypes ..}},{{/notLastSupportedEntryTypes}}
{{else}}
{{#if isOptional}}Optional<{{/if}}{{asJavaBoxedType label type}}{{#if isOptional}}>{{/if}} {{asLowerCamelCase name}} {{#notLastSupportedEntryTypes ..}},{{/notLastSupportedEntryTypes}}
{{/if}}
{{/chip_attribute_list_entryTypes}}
) {
{{#chip_attribute_list_entryTypes}}
{{#if isArray}}
{{! TODO: Add support for lists here }}
{{else if isStruct}}
{{! TODO: Add support for structs here }}
{{else}}
this.{{asLowerCamelCase name}} = {{asLowerCamelCase name}};
{{/if}}
{{/chip_attribute_list_entryTypes}}
}
@Override
public String toString() {
StringBuilder output = new StringBuilder("");
{{#chip_attribute_list_entryTypes}}
{{#if isOptional}}
{{! TODO: Add support for optional types here }}
{{else if isNullable}}
{{! TODO: Add support for nullable types here }}
{{else if isArray}}
{{! TODO: Add support for lists here }}
{{else if isStruct}}
{{! TODO: Add support for structs here }}
{{else if (isOctetString type)}}
output.append("byte[] ");
output.append(Arrays.toString({{asLowerCamelCase name}}));
output.append("\n");
{{else if (isCharString type)}}
output.append("String {{asLowerCamelCase name}}: ");
output.append(this.{{asLowerCamelCase name}});
output.append("\n");
{{else}}
output.append("{{asJavaBasicType label type}} {{asLowerCamelCase name}}: ");
output.append(this.{{asLowerCamelCase name}});
output.append("\n");
{{/if}}
{{/chip_attribute_list_entryTypes}}
return output.toString();
}
}
{{/if}}
public interface {{asUpperCamelCase name}}AttributeCallback {
void onSuccess(List<{{#>list_attribute_callback_type}}{{/list_attribute_callback_type}}> valueList);
void onError(Exception ex);
}
{{/if}}
{{/chip_server_cluster_attributes}}
{{#chip_server_cluster_attributes}}
public void read{{asUpperCamelCase name}}Attribute(
{{#if isList}}
{{asUpperCamelCase name}}AttributeCallback callback
{{else}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{/if}}
) {
read{{asUpperCamelCase name}}Attribute(chipClusterPtr, callback);
}
{{#if isWritableAttribute}}
public void write{{asUpperCamelCase name}}Attribute(DefaultClusterCallback callback, {{asJavaBasicType type}} value) {
write{{asUpperCamelCase name}}Attribute(chipClusterPtr, callback, value);
}
{{/if}}
{{#if isReportableAttribute}}
public void subscribe{{asCamelCased name false}}Attribute(DefaultClusterCallback callback, int minInterval, int maxInterval) {
subscribe{{asCamelCased name false}}Attribute(chipClusterPtr, callback, minInterval, maxInterval);
}
public void report{{asCamelCased name false}}Attribute({{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback) {
report{{asCamelCased name false}}Attribute(chipClusterPtr, callback);
}
{{/if}}
{{/chip_server_cluster_attributes}}
{{#chip_server_cluster_attributes}}
private native void read{{asUpperCamelCase name}}Attribute(long chipClusterPtr,
{{#if isList}}
{{asUpperCamelCase name}}AttributeCallback callback
{{else}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{/if}}
);
{{#if isWritableAttribute}}
private native void write{{asUpperCamelCase name}}Attribute(long chipClusterPtr, DefaultClusterCallback callback, {{asJavaBasicType type}} value);
{{/if}}
{{#if isReportableAttribute}}
private native void subscribe{{asCamelCased name false}}Attribute(long chipClusterPtr, DefaultClusterCallback callback, int minInterval, int maxInterval);
private native void report{{asCamelCased name false}}Attribute(long chipClusterPtr, {{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback);
{{/if}}
{{/chip_server_cluster_attributes}}
}
{{#not_last}}
{{/not_last}}
{{/chip_client_clusters}}
}
{{/if}}