-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement initial Kotlin generator (#30009)
- Loading branch information
1 parent
6e86760
commit 7f25fb2
Showing
104 changed files
with
34,566 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
scripts/py_matter_idl/matter_idl/generators/kotlin/MatterClusters.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
{%- macro encode_value(source, encodable, depth) -%} | ||
{%- if encodable.is_nullable and encodable.is_optional -%} | ||
{{encode_value(source, encodable.without_nullable().without_optional(), depth + 1)}}? | ||
{%- elif encodable.is_nullable -%} | ||
{{encode_value(source, encodable.without_nullable(), depth + 1)}}? | ||
{%- elif encodable.is_optional -%} | ||
{{encode_value(source, encodable.without_optional(), depth + 1)}}? | ||
{%- elif encodable.is_list -%} | ||
ArrayList<{{encode_value(source, encodable.without_list(), depth + 1)}}> | ||
{%- elif encodable.is_struct -%} | ||
{%- set struct = encodable.get_underlying_struct() -%} | ||
ChipStructs.{{source.name}}Cluster{{struct.name}} | ||
{%- else -%} | ||
{{encodable.boxed_java_type}} | ||
{%- endif -%} | ||
{%- endmacro -%} | ||
|
||
{%- macro encode_value_without_optional(source, encodable, depth) -%} | ||
{%- if encodable.is_nullable -%} | ||
{{encode_value_without_optional(source, encodable.without_nullable(), depth + 1)}}? | ||
{%- elif encodable.is_list -%} | ||
List<{{encode_value_without_optional(source, encodable.without_list(), depth + 1)}}> | ||
{%- elif encodable.is_struct -%} | ||
{%- set struct = encodable.get_underlying_struct() -%} | ||
ChipStructs.{{source.name}}Cluster{{struct.name}} | ||
{%- else -%} | ||
{{encodable.boxed_java_type}} | ||
{%- endif -%} | ||
{%- endmacro -%} | ||
|
||
{%- macro encode_value_without_optional_nullable(source, encodable, depth) -%} | ||
{%- if encodable.is_list -%} | ||
ArrayList<{{encode_value_without_optional_nullable(source, encodable.without_list(), depth + 1)}}> | ||
{%- elif encodable.is_struct -%} | ||
{%- set struct = encodable.get_underlying_struct() -%} | ||
ChipStructs.{{source.name}}Cluster{{struct.name}} | ||
{%- else -%} | ||
{{encodable.boxed_java_type}} | ||
{%- endif -%} | ||
{%- endmacro -%} | ||
|
||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package matter.devicecontroller.cluster.clusters | ||
|
||
import java.util.ArrayList | ||
{% set typeLookup = idl | createLookupContext(cluster) %} | ||
class {{cluster.name}}Cluster(private val endpointId: UShort) { | ||
companion object { | ||
const val CLUSTER_ID: UInt = {{cluster.code}}u | ||
} | ||
{% for command in cluster.commands | sort(attribute='code') -%} | ||
{%- set callbackName = command | javaCommandCallbackName() -%} | ||
{%- if not command.is_timed_invoke %} | ||
fun {{command.name | lowfirst_except_acronym}}(callback: {{callbackName}}Callback | ||
{%- if command.input_param -%} | ||
{%- for field in (cluster.structs | named(command.input_param)).fields -%} | ||
, {{field.name | lowfirst_except_acronym}}: {{encode_value(cluster, field | asEncodable(typeLookup), 0)}} | ||
{%- endfor -%} | ||
{%- endif -%} | ||
) { | ||
// Implementation needs to be added here | ||
} | ||
{%- endif %} | ||
|
||
fun {{command.name | lowfirst_except_acronym}}(callback: {{callbackName}}Callback | ||
{%- if command.input_param -%} | ||
{%- for field in (cluster.structs | named(command.input_param)).fields -%} | ||
, {{field.name | lowfirst_except_acronym}}: {{encode_value(cluster, field | asEncodable(typeLookup), 0)}} | ||
{%- endfor -%} | ||
{%- endif -%} | ||
, timedInvokeTimeoutMs: Int) { | ||
// Implementation needs to be added here | ||
} | ||
{% endfor %} | ||
{%- set already_handled_command = [] -%} | ||
{%- for command in cluster.commands | sort(attribute='code') -%} | ||
{%- if command | isCommandNotDefaultCallback() -%} | ||
{%- set callbackName = command | javaCommandCallbackName() -%} | ||
{%- if callbackName not in already_handled_command %} | ||
interface {{callbackName}}Callback { | ||
fun onSuccess( | ||
{%- for field in (cluster.structs | named(command.output_param)).fields -%} | ||
{{field.name | lowfirst_except_acronym}}: {{encode_value(cluster, field | asEncodable(typeLookup), 0)}}{% if not loop.last %}, {% endif %} | ||
{%- endfor -%} | ||
) | ||
fun onError(error: Exception) | ||
} | ||
{% if already_handled_command.append(callbackName) -%} | ||
{%- endif -%} | ||
{%- endif -%} | ||
{%- endif -%} | ||
{%- endfor %} | ||
{%- set already_handled_attribute = [] -%} | ||
{% for attribute in cluster.attributes | rejectattr('definition', 'is_field_global_name', typeLookup) %} | ||
{%- set encodable = attribute.definition | asEncodable(typeLookup) -%} | ||
{%- set interfaceName = attribute | javaAttributeCallbackName(typeLookup) -%} | ||
{%- if interfaceName not in already_handled_attribute %} | ||
interface {{interfaceName}} { | ||
fun onSuccess(value: {{encode_value(cluster, encodable, 0)}}) | ||
fun onError(ex: Exception) | ||
fun onSubscriptionEstablished(subscriptionId: Long) | ||
} | ||
{% if already_handled_attribute.append(interfaceName) -%} | ||
{#- This block does nothing, it only exists to append to already_handled_attribute. -#} | ||
{%- endif -%} | ||
{%- endif -%} | ||
{% endfor -%} | ||
{% for attribute in cluster.attributes | sort(attribute='code') %} | ||
fun read{{ attribute.definition.name | upfirst }}Attribute( | ||
callback: {{ attribute | javaAttributeCallbackName(typeLookup) }} | ||
) { | ||
// Implementation needs to be added here | ||
} | ||
{% if attribute | isFabricScopedList(typeLookup) %} | ||
fun read{{ attribute.definition.name | upfirst }}AttributeWithFabricFilter( | ||
callback: {{ attribute | javaAttributeCallbackName(typeLookup) }}, | ||
isFabricFiltered: Boolean | ||
) { | ||
// Implementation needs to be added here | ||
} | ||
|
||
{% endif -%} | ||
{%- if attribute.is_writable %} | ||
{%- set encodable = attribute.definition | asEncodable(typeLookup) -%} | ||
{%- set encodable2 = attribute.definition | asEncodable(typeLookup) -%} | ||
{%- if not attribute.requires_timed_write %} | ||
fun write{{ attribute.definition.name | upfirst }}Attribute( | ||
callback: DefaultClusterCallback, | ||
value: {{ encode_value_without_optional_nullable(cluster, encodable, 0) }} | ||
) { | ||
// Implementation needs to be added here | ||
} | ||
{% endif %} | ||
fun write{{ attribute.definition.name | upfirst }}Attribute( | ||
callback: DefaultClusterCallback, | ||
value: {{ encode_value_without_optional_nullable(cluster, encodable2, 0) }}, | ||
timedWriteTimeoutMs: Int | ||
) { | ||
// Implementation needs to be added here | ||
} | ||
{% endif %} | ||
{%- if attribute.is_subscribable %} | ||
fun subscribe{{ attribute.definition.name | upfirst }}Attribute( | ||
callback: {{ attribute | javaAttributeCallbackName(typeLookup) }}, | ||
minInterval: Int, | ||
maxInterval: Int | ||
) { | ||
// Implementation needs to be added here | ||
} | ||
{% endif -%} | ||
{%- endfor -%} | ||
} |
9 changes: 9 additions & 0 deletions
9
scripts/py_matter_idl/matter_idl/generators/kotlin/MatterFiles_gni.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import("//build_overrides/build.gni") | ||
import("//build_overrides/chip.gni") | ||
|
||
matter_clusters_sources = [ | ||
{%- for cluster in clientClusters | sort(attribute='name') %} | ||
{%- set typeLookup = idl | createLookupContext(cluster) %} | ||
"${chip_root}/src/controller/java/generated/java/matter/devicecontroller/cluster/clusters/{{cluster.name}}Cluster.kt", | ||
{%- endfor %} | ||
] |
Oops, something went wrong.