diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4781ff8280d868..bdfb51adeec423 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -143,6 +143,7 @@ jobs: src/app/zap-templates/zcl/data-model/chip/low-power-cluster.xml \ src/app/zap-templates/zcl/data-model/chip/media-input-cluster.xml \ src/app/zap-templates/zcl/data-model/chip/media-playback-cluster.xml \ + src/app/zap-templates/zcl/data-model/chip/messages-cluster.xml \ src/app/zap-templates/zcl/data-model/chip/mode-base-cluster.xml \ src/app/zap-templates/zcl/data-model/chip/mode-select-cluster.xml \ src/app/zap-templates/zcl/data-model/chip/network-commissioning-cluster.xml \ diff --git a/docs/clusters.md b/docs/clusters.md index 510dce18b0d3e6..28a817e0a044a9 100644 --- a/docs/clusters.md +++ b/docs/clusters.md @@ -79,6 +79,7 @@ Generally regenerate using one of: | 129 | 0x81 | ValveConfigurationAndControl | | 145 | 0x91 | ElectricalEnergyMeasurement | | 150 | 0x96 | DemandResponseLoadControl | +| 151 | 0x97 | Messages | | 152 | 0x98 | DeviceEnergyManagement | | 153 | 0x99 | EnergyEvse | | 155 | 0x9B | EnergyPreference | diff --git a/scripts/rules.matterlint b/scripts/rules.matterlint index 438d62e9bd883c..d2fff0f9a53750 100644 --- a/scripts/rules.matterlint +++ b/scripts/rules.matterlint @@ -54,6 +54,7 @@ load "../src/app/zap-templates/zcl/data-model/chip/low-power-cluster.xml"; load "../src/app/zap-templates/zcl/data-model/chip/matter-devices.xml"; load "../src/app/zap-templates/zcl/data-model/chip/media-input-cluster.xml"; load "../src/app/zap-templates/zcl/data-model/chip/media-playback-cluster.xml"; +load "../src/app/zap-templates/zcl/data-model/chip/messages-cluster.xml"; load "../src/app/zap-templates/zcl/data-model/chip/mode-base-cluster.xml"; load "../src/app/zap-templates/zcl/data-model/chip/mode-select-cluster.xml"; load "../src/app/zap-templates/zcl/data-model/chip/network-commissioning-cluster.xml"; diff --git a/src/app/clusters/messages-server/messages-server.cpp b/src/app/clusters/messages-server/messages-server.cpp new file mode 100644 index 00000000000000..38cf972c9fccf2 --- /dev/null +++ b/src/app/clusters/messages-server/messages-server.cpp @@ -0,0 +1,40 @@ +#include "messages-server.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters::Messages; +using chip::Protocols::InteractionModel::Status; + +bool emberAfMessagesClusterPresentMessagesRequestCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::Messages::Commands::PresentMessagesRequest::DecodableType & commandData) +{ + return true; +} +/** + * @brief Messages Cluster CancelMessagesRequest Command callback (from client) + */ + +bool emberAfMessagesClusterCancelMessagesRequestCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::Messages::Commands::CancelMessagesRequest::DecodableType & commandData) +{ + return true; +} + +void MatterMessagesPluginServerInitCallback() {} diff --git a/src/app/clusters/messages-server/messages-server.h b/src/app/clusters/messages-server/messages-server.h new file mode 100644 index 00000000000000..767534f8f880b8 --- /dev/null +++ b/src/app/clusters/messages-server/messages-server.h @@ -0,0 +1,29 @@ +/** + * + * 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. + */ + +#pragma once + +#include +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace Messaging {} // namespace Messaging +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/src/app/zap-templates/zcl/data-model/all.xml b/src/app/zap-templates/zcl/data-model/all.xml index a17f6b026ed266..ac22765069d4d6 100644 --- a/src/app/zap-templates/zcl/data-model/all.xml +++ b/src/app/zap-templates/zcl/data-model/all.xml @@ -55,6 +55,7 @@ + diff --git a/src/app/zap-templates/zcl/data-model/chip/messages-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/messages-cluster.xml new file mode 100644 index 00000000000000..0029e1066f96f0 --- /dev/null +++ b/src/app/zap-templates/zcl/data-model/chip/messages-cluster.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Messages + General + This cluster provides an interface for passing messages to be presented by a device. + 0x0097 + MESSAGES_CLUSTER + true + true + + Messages + ActiveMessageIDs + + + Command for requesting messages be presented + + + + + + Command for cancelling message present requests + + + + + This event SHALL be generated when the message is confirmed by the user, or when the expiration date of the message is reached. + + + + This event SHALL be generated when the message is presented to the user. + + + + This event SHALL be generated when the message is confirmed by the user, or when the expiration date of the message is reached. + + + + + + + \ No newline at end of file diff --git a/src/app/zap-templates/zcl/zcl-with-test-extensions.json b/src/app/zap-templates/zcl/zcl-with-test-extensions.json index f45b05dd2c43e8..ebf77014acc5b3 100644 --- a/src/app/zap-templates/zcl/zcl-with-test-extensions.json +++ b/src/app/zap-templates/zcl/zcl-with-test-extensions.json @@ -73,6 +73,7 @@ "low-power-cluster.xml", "media-input-cluster.xml", "media-playback-cluster.xml", + "messages-cluster.xml", "mode-base-cluster.xml", "mode-select-cluster.xml", "mode-select-extensions.xml", diff --git a/src/app/zap-templates/zcl/zcl.json b/src/app/zap-templates/zcl/zcl.json index dc9847b3427890..b0d50dc7ba2c44 100644 --- a/src/app/zap-templates/zcl/zcl.json +++ b/src/app/zap-templates/zcl/zcl.json @@ -71,6 +71,7 @@ "low-power-cluster.xml", "media-input-cluster.xml", "media-playback-cluster.xml", + "messages-cluster.xml", "mode-base-cluster.xml", "mode-select-cluster.xml", "network-commissioning-cluster.xml", diff --git a/src/app/zap_cluster_list.json b/src/app/zap_cluster_list.json index 44442c18a486a3..8c496c03782325 100644 --- a/src/app/zap_cluster_list.json +++ b/src/app/zap_cluster_list.json @@ -64,6 +64,7 @@ "MEDIA_INPUT_CLUSTER": [], "MEDIA_PLAYBACK_CLUSTER": [], "MICROWAVE_OVEN_CONTROL_CLUSTER": [], + "MESSAGES_CLUSTER": [], "MODE_SELECT_CLUSTER": [], "NETWORK_COMMISSIONING_CLUSTER": [], "SAMPLE_MEI_CLUSTER": [], @@ -213,6 +214,7 @@ "MEDIA_INPUT_CLUSTER": ["media-input-server"], "MEDIA_PLAYBACK_CLUSTER": ["media-playback-server"], "MICROWAVE_OVEN_CONTROL_CLUSTER": ["microwave-oven-control-server"], + "MESSAGES_CLUSTER": ["messages-server"], "MODE_SELECT_CLUSTER": ["mode-select-server"], "NETWORK_COMMISSIONING_CLUSTER": ["network-commissioning"], "NITROGEN_DIOXIDE_CONCENTRATION_MEASUREMENT_CLUSTER": [ diff --git a/src/controller/data_model/controller-clusters.matter b/src/controller/data_model/controller-clusters.matter index 1fc83174a5d656..925f665448bd53 100644 --- a/src/controller/data_model/controller-clusters.matter +++ b/src/controller/data_model/controller-clusters.matter @@ -4372,6 +4372,93 @@ provisional cluster DemandResponseLoadControl = 150 { command ClearLoadControlEventsRequest(): DefaultSuccess = 4; } +/** This cluster provides an interface for passing messages to be presented by a device. */ +cluster Messages = 151 { + revision 3; + + enum FutureMessagePreferenceEnum : enum8 { + kAllowed = 0; + kIncreased = 1; + kReduced = 2; + kDisallowed = 3; + kBanned = 4; + } + + enum MessagePriorityEnum : enum8 { + kLow = 0; + kMedium = 1; + kHigh = 2; + kCritical = 3; + } + + bitmap Feature : bitmap32 { + kReceivedConfirmation = 0x1; + kConfirmationResponse = 0x2; + kConfirmationReply = 0x4; + kProtectedMessages = 0x8; + } + + bitmap MessageControlBitmap : bitmap8 { + kConfirmationRequired = 0x1; + kResponseRequired = 0x2; + kReplyMessage = 0x4; + kMessageConfirmed = 0x8; + kMessageProtected = 0x10; + } + + struct MessageResponseOptionStruct { + optional int32u messageResponseID = 0; + optional char_string<32> label = 1; + } + + struct MessageStruct { + octet_string<16> messageID = 0; + MessagePriorityEnum priority = 1; + MessageControlBitmap messageControl = 2; + nullable epoch_s startTime = 3; + nullable int16u duration = 4; + char_string<256> messageText = 5; + optional MessageResponseOptionStruct responses[] = 6; + } + + info event MessageQueued = 0 { + octet_string messageID = 0; + } + + info event MessagePresented = 1 { + octet_string messageID = 0; + } + + info event MessageComplete = 2 { + octet_string messageID = 0; + optional nullable int32u responseID = 1; + optional nullable char_string reply = 2; + nullable FutureMessagePreferenceEnum futureMessagesPreference = 3; + } + + readonly attribute MessageStruct messages[] = 0; + readonly attribute octet_string activeMessageIDs[] = 1; + readonly attribute command_id generatedCommandList[] = 65528; + readonly attribute command_id acceptedCommandList[] = 65529; + readonly attribute event_id eventList[] = 65530; + readonly attribute attrib_id attributeList[] = 65531; + readonly attribute bitmap32 featureMap = 65532; + readonly attribute int16u clusterRevision = 65533; + + request struct PresentMessagesRequestRequest { + MessageStruct messages[] = 0; + } + + request struct CancelMessagesRequestRequest { + octet_string messageIDs[] = 0; + } + + /** Command for requesting messages be presented */ + fabric command PresentMessagesRequest(PresentMessagesRequestRequest): DefaultSuccess = 0; + /** Command for cancelling message present requests */ + fabric command CancelMessagesRequest(CancelMessagesRequestRequest): DefaultSuccess = 1; +} + /** This cluster allows a client to manage the power draw of a device. An example of such a client could be an Energy Management System (EMS) which controls an Energy Smart Appliance (ESA). */ provisional cluster DeviceEnergyManagement = 152 { revision 3; diff --git a/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java b/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java index b47a9322d958fc..d5de31ddb4ceea 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java +++ b/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java @@ -29186,6 +29186,293 @@ public void onSuccess(byte[] tlv) { } } + public static class MessagesCluster extends BaseChipCluster { + public static final long CLUSTER_ID = 151L; + + private static final long MESSAGES_ATTRIBUTE_ID = 0L; + private static final long ACTIVE_MESSAGE_I_DS_ATTRIBUTE_ID = 1L; + private static final long GENERATED_COMMAND_LIST_ATTRIBUTE_ID = 65528L; + private static final long ACCEPTED_COMMAND_LIST_ATTRIBUTE_ID = 65529L; + private static final long EVENT_LIST_ATTRIBUTE_ID = 65530L; + private static final long ATTRIBUTE_LIST_ATTRIBUTE_ID = 65531L; + private static final long FEATURE_MAP_ATTRIBUTE_ID = 65532L; + private static final long CLUSTER_REVISION_ATTRIBUTE_ID = 65533L; + + public MessagesCluster(long devicePtr, int endpointId) { + super(devicePtr, endpointId, CLUSTER_ID); + } + + @Override + @Deprecated + public long initWithDevice(long devicePtr, int endpointId) { + return 0L; + } + + public void presentMessagesRequest(DefaultClusterCallback callback, ArrayList messages) { + presentMessagesRequest(callback, messages, 0); + } + + public void presentMessagesRequest(DefaultClusterCallback callback, ArrayList messages, int timedInvokeTimeoutMs) { + final long commandId = 0L; + + ArrayList elements = new ArrayList<>(); + final long messagesFieldID = 0L; + BaseTLVType messagestlvValue = ArrayType.generateArrayType(messages, (elementmessages) -> elementmessages.encodeTlv()); + elements.add(new StructElement(messagesFieldID, messagestlvValue)); + + StructType value = new StructType(elements); + invoke(new InvokeCallbackImpl(callback) { + @Override + public void onResponse(StructType invokeStructValue) { + callback.onSuccess(); + }}, commandId, value, timedInvokeTimeoutMs); + } + + public void cancelMessagesRequest(DefaultClusterCallback callback, ArrayList messageIDs) { + cancelMessagesRequest(callback, messageIDs, 0); + } + + public void cancelMessagesRequest(DefaultClusterCallback callback, ArrayList messageIDs, int timedInvokeTimeoutMs) { + final long commandId = 1L; + + ArrayList elements = new ArrayList<>(); + final long messageIDsFieldID = 0L; + BaseTLVType messageIDstlvValue = ArrayType.generateArrayType(messageIDs, (elementmessageIDs) -> new ByteArrayType(elementmessageIDs)); + elements.add(new StructElement(messageIDsFieldID, messageIDstlvValue)); + + StructType value = new StructType(elements); + invoke(new InvokeCallbackImpl(callback) { + @Override + public void onResponse(StructType invokeStructValue) { + callback.onSuccess(); + }}, commandId, value, timedInvokeTimeoutMs); + } + + public interface MessagesAttributeCallback extends BaseAttributeCallback { + void onSuccess(List value); + } + + public interface ActiveMessageIDsAttributeCallback extends BaseAttributeCallback { + void onSuccess(List value); + } + + public interface GeneratedCommandListAttributeCallback extends BaseAttributeCallback { + void onSuccess(List value); + } + + public interface AcceptedCommandListAttributeCallback extends BaseAttributeCallback { + void onSuccess(List value); + } + + public interface EventListAttributeCallback extends BaseAttributeCallback { + void onSuccess(List value); + } + + public interface AttributeListAttributeCallback extends BaseAttributeCallback { + void onSuccess(List value); + } + + public void readMessagesAttribute( + MessagesAttributeCallback callback) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, MESSAGES_ATTRIBUTE_ID); + + readAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + callback.onSuccess(value); + } + }, MESSAGES_ATTRIBUTE_ID, true); + } + + public void subscribeMessagesAttribute( + MessagesAttributeCallback callback, int minInterval, int maxInterval) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, MESSAGES_ATTRIBUTE_ID); + + subscribeAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + } + }, MESSAGES_ATTRIBUTE_ID, minInterval, maxInterval); + } + + public void readActiveMessageIDsAttribute( + ActiveMessageIDsAttributeCallback callback) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, ACTIVE_MESSAGE_I_DS_ATTRIBUTE_ID); + + readAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + callback.onSuccess(value); + } + }, ACTIVE_MESSAGE_I_DS_ATTRIBUTE_ID, true); + } + + public void subscribeActiveMessageIDsAttribute( + ActiveMessageIDsAttributeCallback callback, int minInterval, int maxInterval) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, ACTIVE_MESSAGE_I_DS_ATTRIBUTE_ID); + + subscribeAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + } + }, ACTIVE_MESSAGE_I_DS_ATTRIBUTE_ID, minInterval, maxInterval); + } + + public void readGeneratedCommandListAttribute( + GeneratedCommandListAttributeCallback callback) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, GENERATED_COMMAND_LIST_ATTRIBUTE_ID); + + readAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + callback.onSuccess(value); + } + }, GENERATED_COMMAND_LIST_ATTRIBUTE_ID, true); + } + + public void subscribeGeneratedCommandListAttribute( + GeneratedCommandListAttributeCallback callback, int minInterval, int maxInterval) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, GENERATED_COMMAND_LIST_ATTRIBUTE_ID); + + subscribeAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + } + }, GENERATED_COMMAND_LIST_ATTRIBUTE_ID, minInterval, maxInterval); + } + + public void readAcceptedCommandListAttribute( + AcceptedCommandListAttributeCallback callback) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, ACCEPTED_COMMAND_LIST_ATTRIBUTE_ID); + + readAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + callback.onSuccess(value); + } + }, ACCEPTED_COMMAND_LIST_ATTRIBUTE_ID, true); + } + + public void subscribeAcceptedCommandListAttribute( + AcceptedCommandListAttributeCallback callback, int minInterval, int maxInterval) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, ACCEPTED_COMMAND_LIST_ATTRIBUTE_ID); + + subscribeAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + } + }, ACCEPTED_COMMAND_LIST_ATTRIBUTE_ID, minInterval, maxInterval); + } + + public void readEventListAttribute( + EventListAttributeCallback callback) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, EVENT_LIST_ATTRIBUTE_ID); + + readAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + callback.onSuccess(value); + } + }, EVENT_LIST_ATTRIBUTE_ID, true); + } + + public void subscribeEventListAttribute( + EventListAttributeCallback callback, int minInterval, int maxInterval) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, EVENT_LIST_ATTRIBUTE_ID); + + subscribeAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + } + }, EVENT_LIST_ATTRIBUTE_ID, minInterval, maxInterval); + } + + public void readAttributeListAttribute( + AttributeListAttributeCallback callback) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, ATTRIBUTE_LIST_ATTRIBUTE_ID); + + readAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + callback.onSuccess(value); + } + }, ATTRIBUTE_LIST_ATTRIBUTE_ID, true); + } + + public void subscribeAttributeListAttribute( + AttributeListAttributeCallback callback, int minInterval, int maxInterval) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, ATTRIBUTE_LIST_ATTRIBUTE_ID); + + subscribeAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + List value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + } + }, ATTRIBUTE_LIST_ATTRIBUTE_ID, minInterval, maxInterval); + } + + public void readFeatureMapAttribute( + LongAttributeCallback callback) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, FEATURE_MAP_ATTRIBUTE_ID); + + readAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + Long value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + callback.onSuccess(value); + } + }, FEATURE_MAP_ATTRIBUTE_ID, true); + } + + public void subscribeFeatureMapAttribute( + LongAttributeCallback callback, int minInterval, int maxInterval) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, FEATURE_MAP_ATTRIBUTE_ID); + + subscribeAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + Long value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + } + }, FEATURE_MAP_ATTRIBUTE_ID, minInterval, maxInterval); + } + + public void readClusterRevisionAttribute( + IntegerAttributeCallback callback) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, CLUSTER_REVISION_ATTRIBUTE_ID); + + readAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + Integer value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + callback.onSuccess(value); + } + }, CLUSTER_REVISION_ATTRIBUTE_ID, true); + } + + public void subscribeClusterRevisionAttribute( + IntegerAttributeCallback callback, int minInterval, int maxInterval) { + ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, CLUSTER_REVISION_ATTRIBUTE_ID); + + subscribeAttribute(new ReportCallbackImpl(callback, path) { + @Override + public void onSuccess(byte[] tlv) { + Integer value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv); + } + }, CLUSTER_REVISION_ATTRIBUTE_ID, minInterval, maxInterval); + } + } + public static class DeviceEnergyManagementCluster extends BaseChipCluster { public static final long CLUSTER_ID = 152L; diff --git a/src/controller/java/generated/java/chip/devicecontroller/ChipEventStructs.java b/src/controller/java/generated/java/chip/devicecontroller/ChipEventStructs.java index 2fce0d9f588dfc..b759822df155b5 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/ChipEventStructs.java +++ b/src/controller/java/generated/java/chip/devicecontroller/ChipEventStructs.java @@ -3760,6 +3760,189 @@ public String toString() { return output.toString(); } } +public static class MessagesClusterMessageQueuedEvent { + public byte[] messageID; + private static final long MESSAGE_I_D_ID = 0L; + + public MessagesClusterMessageQueuedEvent( + byte[] messageID + ) { + this.messageID = messageID; + } + + public StructType encodeTlv() { + ArrayList values = new ArrayList<>(); + values.add(new StructElement(MESSAGE_I_D_ID, new ByteArrayType(messageID))); + + return new StructType(values); + } + + public static MessagesClusterMessageQueuedEvent decodeTlv(BaseTLVType tlvValue) { + if (tlvValue == null || tlvValue.type() != TLVType.Struct) { + return null; + } + byte[] messageID = null; + for (StructElement element: ((StructType)tlvValue).value()) { + if (element.contextTagNum() == MESSAGE_I_D_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.ByteArray) { + ByteArrayType castingValue = element.value(ByteArrayType.class); + messageID = castingValue.value(byte[].class); + } + } + } + return new MessagesClusterMessageQueuedEvent( + messageID + ); + } + + @Override + public String toString() { + StringBuilder output = new StringBuilder(); + output.append("MessagesClusterMessageQueuedEvent {\n"); + output.append("\tmessageID: "); + output.append(Arrays.toString(messageID)); + output.append("\n"); + output.append("}\n"); + return output.toString(); + } +} +public static class MessagesClusterMessagePresentedEvent { + public byte[] messageID; + private static final long MESSAGE_I_D_ID = 0L; + + public MessagesClusterMessagePresentedEvent( + byte[] messageID + ) { + this.messageID = messageID; + } + + public StructType encodeTlv() { + ArrayList values = new ArrayList<>(); + values.add(new StructElement(MESSAGE_I_D_ID, new ByteArrayType(messageID))); + + return new StructType(values); + } + + public static MessagesClusterMessagePresentedEvent decodeTlv(BaseTLVType tlvValue) { + if (tlvValue == null || tlvValue.type() != TLVType.Struct) { + return null; + } + byte[] messageID = null; + for (StructElement element: ((StructType)tlvValue).value()) { + if (element.contextTagNum() == MESSAGE_I_D_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.ByteArray) { + ByteArrayType castingValue = element.value(ByteArrayType.class); + messageID = castingValue.value(byte[].class); + } + } + } + return new MessagesClusterMessagePresentedEvent( + messageID + ); + } + + @Override + public String toString() { + StringBuilder output = new StringBuilder(); + output.append("MessagesClusterMessagePresentedEvent {\n"); + output.append("\tmessageID: "); + output.append(Arrays.toString(messageID)); + output.append("\n"); + output.append("}\n"); + return output.toString(); + } +} +public static class MessagesClusterMessageCompleteEvent { + public byte[] messageID; + public @Nullable Optional responseID; + public @Nullable Optional reply; + public @Nullable Integer futureMessagesPreference; + private static final long MESSAGE_I_D_ID = 0L; + private static final long RESPONSE_I_D_ID = 1L; + private static final long REPLY_ID = 2L; + private static final long FUTURE_MESSAGES_PREFERENCE_ID = 3L; + + public MessagesClusterMessageCompleteEvent( + byte[] messageID, + @Nullable Optional responseID, + @Nullable Optional reply, + @Nullable Integer futureMessagesPreference + ) { + this.messageID = messageID; + this.responseID = responseID; + this.reply = reply; + this.futureMessagesPreference = futureMessagesPreference; + } + + public StructType encodeTlv() { + ArrayList values = new ArrayList<>(); + values.add(new StructElement(MESSAGE_I_D_ID, new ByteArrayType(messageID))); + values.add(new StructElement(RESPONSE_I_D_ID, responseID != null ? responseID.map((nonOptionalresponseID) -> new UIntType(nonOptionalresponseID)).orElse(new EmptyType()) : new NullType())); + values.add(new StructElement(REPLY_ID, reply != null ? reply.map((nonOptionalreply) -> new StringType(nonOptionalreply)).orElse(new EmptyType()) : new NullType())); + values.add(new StructElement(FUTURE_MESSAGES_PREFERENCE_ID, futureMessagesPreference != null ? new UIntType(futureMessagesPreference) : new NullType())); + + return new StructType(values); + } + + public static MessagesClusterMessageCompleteEvent decodeTlv(BaseTLVType tlvValue) { + if (tlvValue == null || tlvValue.type() != TLVType.Struct) { + return null; + } + byte[] messageID = null; + @Nullable Optional responseID = null; + @Nullable Optional reply = null; + @Nullable Integer futureMessagesPreference = null; + for (StructElement element: ((StructType)tlvValue).value()) { + if (element.contextTagNum() == MESSAGE_I_D_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.ByteArray) { + ByteArrayType castingValue = element.value(ByteArrayType.class); + messageID = castingValue.value(byte[].class); + } + } else if (element.contextTagNum() == RESPONSE_I_D_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.UInt) { + UIntType castingValue = element.value(UIntType.class); + responseID = Optional.of(castingValue.value(Long.class)); + } + } else if (element.contextTagNum() == REPLY_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.String) { + StringType castingValue = element.value(StringType.class); + reply = Optional.of(castingValue.value(String.class)); + } + } else if (element.contextTagNum() == FUTURE_MESSAGES_PREFERENCE_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.UInt) { + UIntType castingValue = element.value(UIntType.class); + futureMessagesPreference = castingValue.value(Integer.class); + } + } + } + return new MessagesClusterMessageCompleteEvent( + messageID, + responseID, + reply, + futureMessagesPreference + ); + } + + @Override + public String toString() { + StringBuilder output = new StringBuilder(); + output.append("MessagesClusterMessageCompleteEvent {\n"); + output.append("\tmessageID: "); + output.append(Arrays.toString(messageID)); + output.append("\n"); + output.append("\tresponseID: "); + output.append(responseID); + output.append("\n"); + output.append("\treply: "); + output.append(reply); + output.append("\n"); + output.append("\tfutureMessagesPreference: "); + output.append(futureMessagesPreference); + output.append("\n"); + output.append("}\n"); + return output.toString(); + } +} public static class DeviceEnergyManagementClusterPowerAdjustStartEvent { public DeviceEnergyManagementClusterPowerAdjustStartEvent( diff --git a/src/controller/java/generated/java/chip/devicecontroller/ChipStructs.java b/src/controller/java/generated/java/chip/devicecontroller/ChipStructs.java index 3dc2b0b9904ef8..cfc67037e90260 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/ChipStructs.java +++ b/src/controller/java/generated/java/chip/devicecontroller/ChipStructs.java @@ -6459,6 +6459,203 @@ public String toString() { return output.toString(); } } +public static class MessagesClusterMessageResponseOptionStruct { + public Optional messageResponseID; + public Optional label; + private static final long MESSAGE_RESPONSE_I_D_ID = 0L; + private static final long LABEL_ID = 1L; + + public MessagesClusterMessageResponseOptionStruct( + Optional messageResponseID, + Optional label + ) { + this.messageResponseID = messageResponseID; + this.label = label; + } + + public StructType encodeTlv() { + ArrayList values = new ArrayList<>(); + values.add(new StructElement(MESSAGE_RESPONSE_I_D_ID, messageResponseID.map((nonOptionalmessageResponseID) -> new UIntType(nonOptionalmessageResponseID)).orElse(new EmptyType()))); + values.add(new StructElement(LABEL_ID, label.map((nonOptionallabel) -> new StringType(nonOptionallabel)).orElse(new EmptyType()))); + + return new StructType(values); + } + + public static MessagesClusterMessageResponseOptionStruct decodeTlv(BaseTLVType tlvValue) { + if (tlvValue == null || tlvValue.type() != TLVType.Struct) { + return null; + } + Optional messageResponseID = Optional.empty(); + Optional label = Optional.empty(); + for (StructElement element: ((StructType)tlvValue).value()) { + if (element.contextTagNum() == MESSAGE_RESPONSE_I_D_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.UInt) { + UIntType castingValue = element.value(UIntType.class); + messageResponseID = Optional.of(castingValue.value(Long.class)); + } + } else if (element.contextTagNum() == LABEL_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.String) { + StringType castingValue = element.value(StringType.class); + label = Optional.of(castingValue.value(String.class)); + } + } + } + return new MessagesClusterMessageResponseOptionStruct( + messageResponseID, + label + ); + } + + @Override + public String toString() { + StringBuilder output = new StringBuilder(); + output.append("MessagesClusterMessageResponseOptionStruct {\n"); + output.append("\tmessageResponseID: "); + output.append(messageResponseID); + output.append("\n"); + output.append("\tlabel: "); + output.append(label); + output.append("\n"); + output.append("}\n"); + return output.toString(); + } +} +public static class MessagesClusterMessageStruct { + public byte[] messageID; + public Integer priority; + public Integer messageControl; + public @Nullable Long startTime; + public @Nullable Integer duration; + public String messageText; + public Optional> responses; + private static final long MESSAGE_I_D_ID = 0L; + private static final long PRIORITY_ID = 1L; + private static final long MESSAGE_CONTROL_ID = 2L; + private static final long START_TIME_ID = 3L; + private static final long DURATION_ID = 4L; + private static final long MESSAGE_TEXT_ID = 5L; + private static final long RESPONSES_ID = 6L; + + public MessagesClusterMessageStruct( + byte[] messageID, + Integer priority, + Integer messageControl, + @Nullable Long startTime, + @Nullable Integer duration, + String messageText, + Optional> responses + ) { + this.messageID = messageID; + this.priority = priority; + this.messageControl = messageControl; + this.startTime = startTime; + this.duration = duration; + this.messageText = messageText; + this.responses = responses; + } + + public StructType encodeTlv() { + ArrayList values = new ArrayList<>(); + values.add(new StructElement(MESSAGE_I_D_ID, new ByteArrayType(messageID))); + values.add(new StructElement(PRIORITY_ID, new UIntType(priority))); + values.add(new StructElement(MESSAGE_CONTROL_ID, new UIntType(messageControl))); + values.add(new StructElement(START_TIME_ID, startTime != null ? new UIntType(startTime) : new NullType())); + values.add(new StructElement(DURATION_ID, duration != null ? new UIntType(duration) : new NullType())); + values.add(new StructElement(MESSAGE_TEXT_ID, new StringType(messageText))); + values.add(new StructElement(RESPONSES_ID, responses.map((nonOptionalresponses) -> ArrayType.generateArrayType(nonOptionalresponses, (elementnonOptionalresponses) -> elementnonOptionalresponses.encodeTlv())).orElse(new EmptyType()))); + + return new StructType(values); + } + + public static MessagesClusterMessageStruct decodeTlv(BaseTLVType tlvValue) { + if (tlvValue == null || tlvValue.type() != TLVType.Struct) { + return null; + } + byte[] messageID = null; + Integer priority = null; + Integer messageControl = null; + @Nullable Long startTime = null; + @Nullable Integer duration = null; + String messageText = null; + Optional> responses = Optional.empty(); + for (StructElement element: ((StructType)tlvValue).value()) { + if (element.contextTagNum() == MESSAGE_I_D_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.ByteArray) { + ByteArrayType castingValue = element.value(ByteArrayType.class); + messageID = castingValue.value(byte[].class); + } + } else if (element.contextTagNum() == PRIORITY_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.UInt) { + UIntType castingValue = element.value(UIntType.class); + priority = castingValue.value(Integer.class); + } + } else if (element.contextTagNum() == MESSAGE_CONTROL_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.UInt) { + UIntType castingValue = element.value(UIntType.class); + messageControl = castingValue.value(Integer.class); + } + } else if (element.contextTagNum() == START_TIME_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.UInt) { + UIntType castingValue = element.value(UIntType.class); + startTime = castingValue.value(Long.class); + } + } else if (element.contextTagNum() == DURATION_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.UInt) { + UIntType castingValue = element.value(UIntType.class); + duration = castingValue.value(Integer.class); + } + } else if (element.contextTagNum() == MESSAGE_TEXT_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.String) { + StringType castingValue = element.value(StringType.class); + messageText = castingValue.value(String.class); + } + } else if (element.contextTagNum() == RESPONSES_ID) { + if (element.value(BaseTLVType.class).type() == TLVType.Array) { + ArrayType castingValue = element.value(ArrayType.class); + responses = Optional.of(castingValue.map((elementcastingValue) -> ChipStructs.MessagesClusterMessageResponseOptionStruct.decodeTlv(elementcastingValue))); + } + } + } + return new MessagesClusterMessageStruct( + messageID, + priority, + messageControl, + startTime, + duration, + messageText, + responses + ); + } + + @Override + public String toString() { + StringBuilder output = new StringBuilder(); + output.append("MessagesClusterMessageStruct {\n"); + output.append("\tmessageID: "); + output.append(Arrays.toString(messageID)); + output.append("\n"); + output.append("\tpriority: "); + output.append(priority); + output.append("\n"); + output.append("\tmessageControl: "); + output.append(messageControl); + output.append("\n"); + output.append("\tstartTime: "); + output.append(startTime); + output.append("\n"); + output.append("\tduration: "); + output.append(duration); + output.append("\n"); + output.append("\tmessageText: "); + output.append(messageText); + output.append("\n"); + output.append("\tresponses: "); + output.append(responses); + output.append("\n"); + output.append("}\n"); + return output.toString(); + } +} public static class DeviceEnergyManagementClusterCostStruct { public Integer costType; public Long value; diff --git a/src/controller/java/generated/java/chip/devicecontroller/ClusterIDMapping.java b/src/controller/java/generated/java/chip/devicecontroller/ClusterIDMapping.java index 6a95ee17097bc7..92a679fe443b26 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/ClusterIDMapping.java +++ b/src/controller/java/generated/java/chip/devicecontroller/ClusterIDMapping.java @@ -229,6 +229,9 @@ public static BaseCluster getCluster(long clusterId) { if (clusterId == DemandResponseLoadControl.ID) { return new DemandResponseLoadControl(); } + if (clusterId == Messages.ID) { + return new Messages(); + } if (clusterId == DeviceEnergyManagement.ID) { return new DeviceEnergyManagement(); } @@ -9309,6 +9312,147 @@ public long getCommandID(String name) throws IllegalArgumentException { return Command.valueOf(name).getID(); } } + public static class Messages implements BaseCluster { + public static final long ID = 151L; + public long getID() { + return ID; + } + + public enum Attribute { + Messages(0L), + ActiveMessageIDs(1L), + GeneratedCommandList(65528L), + AcceptedCommandList(65529L), + EventList(65530L), + AttributeList(65531L), + FeatureMap(65532L), + ClusterRevision(65533L),; + private final long id; + Attribute(long id) { + this.id = id; + } + + public long getID() { + return id; + } + + public static Attribute value(long id) throws NoSuchFieldError { + for (Attribute attribute : Attribute.values()) { + if (attribute.getID() == id) { + return attribute; + } + } + throw new NoSuchFieldError(); + } + } + + public enum Event { + MessageQueued(0L), + MessagePresented(1L), + MessageComplete(2L),; + private final long id; + Event(long id) { + this.id = id; + } + + public long getID() { + return id; + } + + public static Event value(long id) throws NoSuchFieldError { + for (Event event : Event.values()) { + if (event.getID() == id) { + return event; + } + } + throw new NoSuchFieldError(); + } + } + + public enum Command { + PresentMessagesRequest(0L), + CancelMessagesRequest(1L),; + private final long id; + Command(long id) { + this.id = id; + } + + public long getID() { + return id; + } + + public static Command value(long id) throws NoSuchFieldError { + for (Command command : Command.values()) { + if (command.getID() == id) { + return command; + } + } + throw new NoSuchFieldError(); + } + }public enum PresentMessagesRequestCommandField {Messages(0),; + private final int id; + PresentMessagesRequestCommandField(int id) { + this.id = id; + } + + public int getID() { + return id; + } + public static PresentMessagesRequestCommandField value(int id) throws NoSuchFieldError { + for (PresentMessagesRequestCommandField field : PresentMessagesRequestCommandField.values()) { + if (field.getID() == id) { + return field; + } + } + throw new NoSuchFieldError(); + } + }public enum CancelMessagesRequestCommandField {MessageIDs(0),; + private final int id; + CancelMessagesRequestCommandField(int id) { + this.id = id; + } + + public int getID() { + return id; + } + public static CancelMessagesRequestCommandField value(int id) throws NoSuchFieldError { + for (CancelMessagesRequestCommandField field : CancelMessagesRequestCommandField.values()) { + if (field.getID() == id) { + return field; + } + } + throw new NoSuchFieldError(); + } + }@Override + public String getAttributeName(long id) throws NoSuchFieldError { + return Attribute.value(id).toString(); + } + + @Override + public String getEventName(long id) throws NoSuchFieldError { + return Event.value(id).toString(); + } + + @Override + public String getCommandName(long id) throws NoSuchFieldError { + return Command.value(id).toString(); + } + + @Override + public long getAttributeID(String name) throws IllegalArgumentException { + return Attribute.valueOf(name).getID(); + } + + @Override + public long getEventID(String name) throws IllegalArgumentException { + return Event.valueOf(name).getID(); + } + + @Override + public long getCommandID(String name) throws IllegalArgumentException { + return Command.valueOf(name).getID(); + } + } public static class DeviceEnergyManagement implements BaseCluster { public static final long ID = 152L; public long getID() { diff --git a/src/controller/java/generated/java/chip/devicecontroller/ClusterInfoMapping.java b/src/controller/java/generated/java/chip/devicecontroller/ClusterInfoMapping.java index 1232c45d640ae7..70c1e3f12787d7 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/ClusterInfoMapping.java +++ b/src/controller/java/generated/java/chip/devicecontroller/ClusterInfoMapping.java @@ -10306,6 +10306,132 @@ public void onError(Exception ex) { } } + public static class DelegatedMessagesClusterMessagesAttributeCallback implements ChipClusters.MessagesCluster.MessagesAttributeCallback, DelegatedClusterCallback { + private ClusterCommandCallback callback; + @Override + public void setCallbackDelegate(ClusterCommandCallback callback) { + this.callback = callback; + } + + @Override + public void onSuccess(List valueList) { + Map responseValues = new LinkedHashMap<>(); + CommandResponseInfo commandResponseInfo = new CommandResponseInfo("valueList", "List"); + responseValues.put(commandResponseInfo, valueList); + callback.onSuccess(responseValues); + } + + @Override + public void onError(Exception ex) { + callback.onFailure(ex); + } + } + + public static class DelegatedMessagesClusterActiveMessageIDsAttributeCallback implements ChipClusters.MessagesCluster.ActiveMessageIDsAttributeCallback, DelegatedClusterCallback { + private ClusterCommandCallback callback; + @Override + public void setCallbackDelegate(ClusterCommandCallback callback) { + this.callback = callback; + } + + @Override + public void onSuccess(List valueList) { + Map responseValues = new LinkedHashMap<>(); + CommandResponseInfo commandResponseInfo = new CommandResponseInfo("valueList", "List"); + responseValues.put(commandResponseInfo, valueList); + callback.onSuccess(responseValues); + } + + @Override + public void onError(Exception ex) { + callback.onFailure(ex); + } + } + + public static class DelegatedMessagesClusterGeneratedCommandListAttributeCallback implements ChipClusters.MessagesCluster.GeneratedCommandListAttributeCallback, DelegatedClusterCallback { + private ClusterCommandCallback callback; + @Override + public void setCallbackDelegate(ClusterCommandCallback callback) { + this.callback = callback; + } + + @Override + public void onSuccess(List valueList) { + Map responseValues = new LinkedHashMap<>(); + CommandResponseInfo commandResponseInfo = new CommandResponseInfo("valueList", "List"); + responseValues.put(commandResponseInfo, valueList); + callback.onSuccess(responseValues); + } + + @Override + public void onError(Exception ex) { + callback.onFailure(ex); + } + } + + public static class DelegatedMessagesClusterAcceptedCommandListAttributeCallback implements ChipClusters.MessagesCluster.AcceptedCommandListAttributeCallback, DelegatedClusterCallback { + private ClusterCommandCallback callback; + @Override + public void setCallbackDelegate(ClusterCommandCallback callback) { + this.callback = callback; + } + + @Override + public void onSuccess(List valueList) { + Map responseValues = new LinkedHashMap<>(); + CommandResponseInfo commandResponseInfo = new CommandResponseInfo("valueList", "List"); + responseValues.put(commandResponseInfo, valueList); + callback.onSuccess(responseValues); + } + + @Override + public void onError(Exception ex) { + callback.onFailure(ex); + } + } + + public static class DelegatedMessagesClusterEventListAttributeCallback implements ChipClusters.MessagesCluster.EventListAttributeCallback, DelegatedClusterCallback { + private ClusterCommandCallback callback; + @Override + public void setCallbackDelegate(ClusterCommandCallback callback) { + this.callback = callback; + } + + @Override + public void onSuccess(List valueList) { + Map responseValues = new LinkedHashMap<>(); + CommandResponseInfo commandResponseInfo = new CommandResponseInfo("valueList", "List"); + responseValues.put(commandResponseInfo, valueList); + callback.onSuccess(responseValues); + } + + @Override + public void onError(Exception ex) { + callback.onFailure(ex); + } + } + + public static class DelegatedMessagesClusterAttributeListAttributeCallback implements ChipClusters.MessagesCluster.AttributeListAttributeCallback, DelegatedClusterCallback { + private ClusterCommandCallback callback; + @Override + public void setCallbackDelegate(ClusterCommandCallback callback) { + this.callback = callback; + } + + @Override + public void onSuccess(List valueList) { + Map responseValues = new LinkedHashMap<>(); + CommandResponseInfo commandResponseInfo = new CommandResponseInfo("valueList", "List"); + responseValues.put(commandResponseInfo, valueList); + callback.onSuccess(responseValues); + } + + @Override + public void onError(Exception ex) { + callback.onFailure(ex); + } + } + public static class DelegatedDeviceEnergyManagementClusterPowerAdjustmentCapabilityAttributeCallback implements ChipClusters.DeviceEnergyManagementCluster.PowerAdjustmentCapabilityAttributeCallback, DelegatedClusterCallback { private ClusterCommandCallback callback; @Override @@ -20351,6 +20477,10 @@ public Map initializeClusterMap() { (ptr, endpointId) -> new ChipClusters.DemandResponseLoadControlCluster(ptr, endpointId), new HashMap<>()); clusterMap.put("demandResponseLoadControl", demandResponseLoadControlClusterInfo); + ClusterInfo messagesClusterInfo = new ClusterInfo( + (ptr, endpointId) -> new ChipClusters.MessagesCluster(ptr, endpointId), new HashMap<>()); + clusterMap.put("messages", messagesClusterInfo); + ClusterInfo deviceEnergyManagementClusterInfo = new ClusterInfo( (ptr, endpointId) -> new ChipClusters.DeviceEnergyManagementCluster(ptr, endpointId), new HashMap<>()); clusterMap.put("deviceEnergyManagement", deviceEnergyManagementClusterInfo); @@ -20614,6 +20744,7 @@ public void combineCommand(Map destination, Map> getCommandMap() { commandMap.put("demandResponseLoadControl", demandResponseLoadControlClusterInteractionInfoMap); + Map messagesClusterInteractionInfoMap = new LinkedHashMap<>(); + + Map messagespresentMessagesRequestCommandParams = new LinkedHashMap(); + + InteractionInfo messagespresentMessagesRequestInteractionInfo = new InteractionInfo( + (cluster, callback, commandArguments) -> { + ((ChipClusters.MessagesCluster) cluster) + .presentMessagesRequest((DefaultClusterCallback) callback + , (ArrayList) + commandArguments.get("messages") + ); + }, + () -> new DelegatedDefaultClusterCallback(), + messagespresentMessagesRequestCommandParams + ); + messagesClusterInteractionInfoMap.put("presentMessagesRequest", messagespresentMessagesRequestInteractionInfo); + + Map messagescancelMessagesRequestCommandParams = new LinkedHashMap(); + + CommandParameterInfo messagescancelMessagesRequestmessageIDsCommandParameterInfo = new CommandParameterInfo("messageIDs", ArrayList.class, ArrayList.class); + messagescancelMessagesRequestCommandParams.put("messageIDs",messagescancelMessagesRequestmessageIDsCommandParameterInfo); + InteractionInfo messagescancelMessagesRequestInteractionInfo = new InteractionInfo( + (cluster, callback, commandArguments) -> { + ((ChipClusters.MessagesCluster) cluster) + .cancelMessagesRequest((DefaultClusterCallback) callback + , (ArrayList) + commandArguments.get("messageIDs") + ); + }, + () -> new DelegatedDefaultClusterCallback(), + messagescancelMessagesRequestCommandParams + ); + messagesClusterInteractionInfoMap.put("cancelMessagesRequest", messagescancelMessagesRequestInteractionInfo); + + commandMap.put("messages", messagesClusterInteractionInfoMap); + Map deviceEnergyManagementClusterInteractionInfoMap = new LinkedHashMap<>(); Map deviceEnergyManagementpowerAdjustRequestCommandParams = new LinkedHashMap(); diff --git a/src/controller/java/generated/java/chip/devicecontroller/ClusterReadMapping.java b/src/controller/java/generated/java/chip/devicecontroller/ClusterReadMapping.java index efa3c4658bb5b8..a7fe287e152a5b 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/ClusterReadMapping.java +++ b/src/controller/java/generated/java/chip/devicecontroller/ClusterReadMapping.java @@ -9214,6 +9214,98 @@ private static Map readDemandResponseLoadControlInterac return result; } + private static Map readMessagesInteractionInfo() { + Map result = new LinkedHashMap<>();Map readMessagesMessagesCommandParams = new LinkedHashMap(); + InteractionInfo readMessagesMessagesAttributeInteractionInfo = new InteractionInfo( + (cluster, callback, commandArguments) -> { + ((ChipClusters.MessagesCluster) cluster).readMessagesAttribute( + (ChipClusters.MessagesCluster.MessagesAttributeCallback) callback + ); + }, + () -> new ClusterInfoMapping.DelegatedMessagesClusterMessagesAttributeCallback(), + readMessagesMessagesCommandParams + ); + result.put("readMessagesAttribute", readMessagesMessagesAttributeInteractionInfo); + Map readMessagesActiveMessageIDsCommandParams = new LinkedHashMap(); + InteractionInfo readMessagesActiveMessageIDsAttributeInteractionInfo = new InteractionInfo( + (cluster, callback, commandArguments) -> { + ((ChipClusters.MessagesCluster) cluster).readActiveMessageIDsAttribute( + (ChipClusters.MessagesCluster.ActiveMessageIDsAttributeCallback) callback + ); + }, + () -> new ClusterInfoMapping.DelegatedMessagesClusterActiveMessageIDsAttributeCallback(), + readMessagesActiveMessageIDsCommandParams + ); + result.put("readActiveMessageIDsAttribute", readMessagesActiveMessageIDsAttributeInteractionInfo); + Map readMessagesGeneratedCommandListCommandParams = new LinkedHashMap(); + InteractionInfo readMessagesGeneratedCommandListAttributeInteractionInfo = new InteractionInfo( + (cluster, callback, commandArguments) -> { + ((ChipClusters.MessagesCluster) cluster).readGeneratedCommandListAttribute( + (ChipClusters.MessagesCluster.GeneratedCommandListAttributeCallback) callback + ); + }, + () -> new ClusterInfoMapping.DelegatedMessagesClusterGeneratedCommandListAttributeCallback(), + readMessagesGeneratedCommandListCommandParams + ); + result.put("readGeneratedCommandListAttribute", readMessagesGeneratedCommandListAttributeInteractionInfo); + Map readMessagesAcceptedCommandListCommandParams = new LinkedHashMap(); + InteractionInfo readMessagesAcceptedCommandListAttributeInteractionInfo = new InteractionInfo( + (cluster, callback, commandArguments) -> { + ((ChipClusters.MessagesCluster) cluster).readAcceptedCommandListAttribute( + (ChipClusters.MessagesCluster.AcceptedCommandListAttributeCallback) callback + ); + }, + () -> new ClusterInfoMapping.DelegatedMessagesClusterAcceptedCommandListAttributeCallback(), + readMessagesAcceptedCommandListCommandParams + ); + result.put("readAcceptedCommandListAttribute", readMessagesAcceptedCommandListAttributeInteractionInfo); + Map readMessagesEventListCommandParams = new LinkedHashMap(); + InteractionInfo readMessagesEventListAttributeInteractionInfo = new InteractionInfo( + (cluster, callback, commandArguments) -> { + ((ChipClusters.MessagesCluster) cluster).readEventListAttribute( + (ChipClusters.MessagesCluster.EventListAttributeCallback) callback + ); + }, + () -> new ClusterInfoMapping.DelegatedMessagesClusterEventListAttributeCallback(), + readMessagesEventListCommandParams + ); + result.put("readEventListAttribute", readMessagesEventListAttributeInteractionInfo); + Map readMessagesAttributeListCommandParams = new LinkedHashMap(); + InteractionInfo readMessagesAttributeListAttributeInteractionInfo = new InteractionInfo( + (cluster, callback, commandArguments) -> { + ((ChipClusters.MessagesCluster) cluster).readAttributeListAttribute( + (ChipClusters.MessagesCluster.AttributeListAttributeCallback) callback + ); + }, + () -> new ClusterInfoMapping.DelegatedMessagesClusterAttributeListAttributeCallback(), + readMessagesAttributeListCommandParams + ); + result.put("readAttributeListAttribute", readMessagesAttributeListAttributeInteractionInfo); + Map readMessagesFeatureMapCommandParams = new LinkedHashMap(); + InteractionInfo readMessagesFeatureMapAttributeInteractionInfo = new InteractionInfo( + (cluster, callback, commandArguments) -> { + ((ChipClusters.MessagesCluster) cluster).readFeatureMapAttribute( + (ChipClusters.LongAttributeCallback) callback + ); + }, + () -> new ClusterInfoMapping.DelegatedLongAttributeCallback(), + readMessagesFeatureMapCommandParams + ); + result.put("readFeatureMapAttribute", readMessagesFeatureMapAttributeInteractionInfo); + Map readMessagesClusterRevisionCommandParams = new LinkedHashMap(); + InteractionInfo readMessagesClusterRevisionAttributeInteractionInfo = new InteractionInfo( + (cluster, callback, commandArguments) -> { + ((ChipClusters.MessagesCluster) cluster).readClusterRevisionAttribute( + (ChipClusters.IntegerAttributeCallback) callback + ); + }, + () -> new ClusterInfoMapping.DelegatedIntegerAttributeCallback(), + readMessagesClusterRevisionCommandParams + ); + result.put("readClusterRevisionAttribute", readMessagesClusterRevisionAttributeInteractionInfo); + + return result; + } private static Map readDeviceEnergyManagementInteractionInfo() { Map result = new LinkedHashMap<>();Map readDeviceEnergyManagementESATypeCommandParams = new LinkedHashMap(); InteractionInfo readDeviceEnergyManagementESATypeAttributeInteractionInfo = new InteractionInfo( @@ -20114,6 +20206,7 @@ public Map> getReadAttributeMap() { put("valveConfigurationAndControl", readValveConfigurationAndControlInteractionInfo()); put("electricalEnergyMeasurement", readElectricalEnergyMeasurementInteractionInfo()); put("demandResponseLoadControl", readDemandResponseLoadControlInteractionInfo()); + put("messages", readMessagesInteractionInfo()); put("deviceEnergyManagement", readDeviceEnergyManagementInteractionInfo()); put("energyEvse", readEnergyEvseInteractionInfo()); put("energyPreference", readEnergyPreferenceInteractionInfo()); diff --git a/src/controller/java/generated/java/chip/devicecontroller/ClusterWriteMapping.java b/src/controller/java/generated/java/chip/devicecontroller/ClusterWriteMapping.java index 9d4a24661bf16a..f9357edc588b82 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/ClusterWriteMapping.java +++ b/src/controller/java/generated/java/chip/devicecontroller/ClusterWriteMapping.java @@ -1282,6 +1282,8 @@ public Map> getWriteAttributeMap() { ); writeDemandResponseLoadControlInteractionInfo.put("writeDefaultRandomDurationAttribute", writeDemandResponseLoadControlDefaultRandomDurationAttributeInteractionInfo); writeAttributeMap.put("demandResponseLoadControl", writeDemandResponseLoadControlInteractionInfo); + Map writeMessagesInteractionInfo = new LinkedHashMap<>(); + writeAttributeMap.put("messages", writeMessagesInteractionInfo); Map writeDeviceEnergyManagementInteractionInfo = new LinkedHashMap<>(); writeAttributeMap.put("deviceEnergyManagement", writeDeviceEnergyManagementInteractionInfo); Map writeEnergyEvseInteractionInfo = new LinkedHashMap<>(); diff --git a/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt b/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt new file mode 100644 index 00000000000000..d885f26d3d9b8b --- /dev/null +++ b/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt @@ -0,0 +1,119 @@ +/* + * + * 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 chip.devicecontroller.cluster.eventstructs + +import chip.devicecontroller.cluster.* +import java.util.Optional +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvReader +import matter.tlv.TlvWriter + +class MessagesClusterMessageCompleteEvent( + val messageID: ByteArray, + val responseID: Optional?, + val reply: Optional?, + val futureMessagesPreference: UInt? +) { + override fun toString(): String = buildString { + append("MessagesClusterMessageCompleteEvent {\n") + append("\tmessageID : $messageID\n") + append("\tresponseID : $responseID\n") + append("\treply : $reply\n") + append("\tfutureMessagesPreference : $futureMessagesPreference\n") + append("}\n") + } + + fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { + tlvWriter.apply { + startStructure(tlvTag) + put(ContextSpecificTag(TAG_MESSAGE_I_D), messageID) + if (responseID != null) { + if (responseID.isPresent) { + val optresponseID = responseID.get() + put(ContextSpecificTag(TAG_RESPONSE_I_D), optresponseID) + } + } else { + putNull(ContextSpecificTag(TAG_RESPONSE_I_D)) + } + if (reply != null) { + if (reply.isPresent) { + val optreply = reply.get() + put(ContextSpecificTag(TAG_REPLY), optreply) + } + } else { + putNull(ContextSpecificTag(TAG_REPLY)) + } + if (futureMessagesPreference != null) { + put(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE), futureMessagesPreference) + } else { + putNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) + } + endStructure() + } + } + + companion object { + private const val TAG_MESSAGE_I_D = 0 + private const val TAG_RESPONSE_I_D = 1 + private const val TAG_REPLY = 2 + private const val TAG_FUTURE_MESSAGES_PREFERENCE = 3 + + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageCompleteEvent { + tlvReader.enterStructure(tlvTag) + val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_I_D)) + val responseID = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSE_I_D))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_RESPONSE_I_D))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_RESPONSE_I_D)) + null + } + val reply = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_REPLY))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_REPLY))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_REPLY)) + null + } + val futureMessagesPreference = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) + null + } + + tlvReader.exitContainer() + + return MessagesClusterMessageCompleteEvent( + messageID, + responseID, + reply, + futureMessagesPreference + ) + } + } +} diff --git a/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt b/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt new file mode 100644 index 00000000000000..a2e39882f9ab4a --- /dev/null +++ b/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt @@ -0,0 +1,52 @@ +/* + * + * 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 chip.devicecontroller.cluster.eventstructs + +import chip.devicecontroller.cluster.* +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvReader +import matter.tlv.TlvWriter + +class MessagesClusterMessagePresentedEvent(val messageID: ByteArray) { + override fun toString(): String = buildString { + append("MessagesClusterMessagePresentedEvent {\n") + append("\tmessageID : $messageID\n") + append("}\n") + } + + fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { + tlvWriter.apply { + startStructure(tlvTag) + put(ContextSpecificTag(TAG_MESSAGE_I_D), messageID) + endStructure() + } + } + + companion object { + private const val TAG_MESSAGE_I_D = 0 + + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessagePresentedEvent { + tlvReader.enterStructure(tlvTag) + val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_I_D)) + + tlvReader.exitContainer() + + return MessagesClusterMessagePresentedEvent(messageID) + } + } +} diff --git a/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt b/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt new file mode 100644 index 00000000000000..db5ed28fae6de0 --- /dev/null +++ b/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt @@ -0,0 +1,52 @@ +/* + * + * 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 chip.devicecontroller.cluster.eventstructs + +import chip.devicecontroller.cluster.* +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvReader +import matter.tlv.TlvWriter + +class MessagesClusterMessageQueuedEvent(val messageID: ByteArray) { + override fun toString(): String = buildString { + append("MessagesClusterMessageQueuedEvent {\n") + append("\tmessageID : $messageID\n") + append("}\n") + } + + fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { + tlvWriter.apply { + startStructure(tlvTag) + put(ContextSpecificTag(TAG_MESSAGE_I_D), messageID) + endStructure() + } + } + + companion object { + private const val TAG_MESSAGE_I_D = 0 + + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageQueuedEvent { + tlvReader.enterStructure(tlvTag) + val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_I_D)) + + tlvReader.exitContainer() + + return MessagesClusterMessageQueuedEvent(messageID) + } + } +} diff --git a/src/controller/java/generated/java/chip/devicecontroller/cluster/files.gni b/src/controller/java/generated/java/chip/devicecontroller/cluster/files.gni index 2af0e85f583ec8..d5fe7ad8fcc5ce 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/cluster/files.gni +++ b/src/controller/java/generated/java/chip/devicecontroller/cluster/files.gni @@ -77,6 +77,8 @@ structs_sources = [ "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MediaPlaybackClusterPlaybackPositionStruct.kt", "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MediaPlaybackClusterTrackAttributesStruct.kt", "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MediaPlaybackClusterTrackStruct.kt", + "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt", + "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MessagesClusterMessageStruct.kt", "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MicrowaveOvenModeClusterModeOptionStruct.kt", "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MicrowaveOvenModeClusterModeTagStruct.kt", "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ModeSelectClusterModeOptionStruct.kt", @@ -170,6 +172,9 @@ eventstructs_sources = [ "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/GeneralDiagnosticsClusterNetworkFaultChangeEvent.kt", "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/GeneralDiagnosticsClusterRadioFaultChangeEvent.kt", "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MediaPlaybackClusterStateChangedEvent.kt", + "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt", + "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt", + "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt", "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/OperationalStateClusterOperationalErrorEvent.kt", "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/OperationalStateClusterOperationCompletionEvent.kt", "${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterDownloadErrorEvent.kt", diff --git a/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt b/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt new file mode 100644 index 00000000000000..5a151b76c6954a --- /dev/null +++ b/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt @@ -0,0 +1,76 @@ +/* + * + * 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 chip.devicecontroller.cluster.structs + +import chip.devicecontroller.cluster.* +import java.util.Optional +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvReader +import matter.tlv.TlvWriter + +class MessagesClusterMessageResponseOptionStruct( + val messageResponseID: Optional, + val label: Optional +) { + override fun toString(): String = buildString { + append("MessagesClusterMessageResponseOptionStruct {\n") + append("\tmessageResponseID : $messageResponseID\n") + append("\tlabel : $label\n") + append("}\n") + } + + fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { + tlvWriter.apply { + startStructure(tlvTag) + if (messageResponseID.isPresent) { + val optmessageResponseID = messageResponseID.get() + put(ContextSpecificTag(TAG_MESSAGE_RESPONSE_I_D), optmessageResponseID) + } + if (label.isPresent) { + val optlabel = label.get() + put(ContextSpecificTag(TAG_LABEL), optlabel) + } + endStructure() + } + } + + companion object { + private const val TAG_MESSAGE_RESPONSE_I_D = 0 + private const val TAG_LABEL = 1 + + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageResponseOptionStruct { + tlvReader.enterStructure(tlvTag) + val messageResponseID = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MESSAGE_RESPONSE_I_D))) { + Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_MESSAGE_RESPONSE_I_D))) + } else { + Optional.empty() + } + val label = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) + } else { + Optional.empty() + } + + tlvReader.exitContainer() + + return MessagesClusterMessageResponseOptionStruct(messageResponseID, label) + } + } +} diff --git a/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MessagesClusterMessageStruct.kt b/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MessagesClusterMessageStruct.kt new file mode 100644 index 00000000000000..d1749289a3b652 --- /dev/null +++ b/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/MessagesClusterMessageStruct.kt @@ -0,0 +1,134 @@ +/* + * + * 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 chip.devicecontroller.cluster.structs + +import chip.devicecontroller.cluster.* +import java.util.Optional +import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvReader +import matter.tlv.TlvWriter + +class MessagesClusterMessageStruct( + val messageID: ByteArray, + val priority: UInt, + val messageControl: UInt, + val startTime: ULong?, + val duration: UInt?, + val messageText: String, + val responses: Optional> +) { + override fun toString(): String = buildString { + append("MessagesClusterMessageStruct {\n") + append("\tmessageID : $messageID\n") + append("\tpriority : $priority\n") + append("\tmessageControl : $messageControl\n") + append("\tstartTime : $startTime\n") + append("\tduration : $duration\n") + append("\tmessageText : $messageText\n") + append("\tresponses : $responses\n") + append("}\n") + } + + fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { + tlvWriter.apply { + startStructure(tlvTag) + put(ContextSpecificTag(TAG_MESSAGE_I_D), messageID) + put(ContextSpecificTag(TAG_PRIORITY), priority) + put(ContextSpecificTag(TAG_MESSAGE_CONTROL), messageControl) + if (startTime != null) { + put(ContextSpecificTag(TAG_START_TIME), startTime) + } else { + putNull(ContextSpecificTag(TAG_START_TIME)) + } + if (duration != null) { + put(ContextSpecificTag(TAG_DURATION), duration) + } else { + putNull(ContextSpecificTag(TAG_DURATION)) + } + put(ContextSpecificTag(TAG_MESSAGE_TEXT), messageText) + if (responses.isPresent) { + val optresponses = responses.get() + startArray(ContextSpecificTag(TAG_RESPONSES)) + for (item in optresponses.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() + } + endStructure() + } + } + + companion object { + private const val TAG_MESSAGE_I_D = 0 + private const val TAG_PRIORITY = 1 + private const val TAG_MESSAGE_CONTROL = 2 + private const val TAG_START_TIME = 3 + private const val TAG_DURATION = 4 + private const val TAG_MESSAGE_TEXT = 5 + private const val TAG_RESPONSES = 6 + + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageStruct { + tlvReader.enterStructure(tlvTag) + val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_I_D)) + val priority = tlvReader.getUInt(ContextSpecificTag(TAG_PRIORITY)) + val messageControl = tlvReader.getUInt(ContextSpecificTag(TAG_MESSAGE_CONTROL)) + val startTime = + if (!tlvReader.isNull()) { + tlvReader.getULong(ContextSpecificTag(TAG_START_TIME)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_START_TIME)) + null + } + val duration = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_DURATION)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DURATION)) + null + } + val messageText = tlvReader.getString(ContextSpecificTag(TAG_MESSAGE_TEXT)) + val responses = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSES))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_RESPONSES)) + while (!tlvReader.isEndOfContainer()) { + add(MessagesClusterMessageResponseOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + + tlvReader.exitContainer() + + return MessagesClusterMessageStruct( + messageID, + priority, + messageControl, + startTime, + duration, + messageText, + responses + ) + } + } +} diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt new file mode 100644 index 00000000000000..7793725b8d9cce --- /dev/null +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt @@ -0,0 +1,904 @@ +/* + * + * 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.controller.cluster.clusters + +import java.time.Duration +import java.util.logging.Level +import java.util.logging.Logger +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.transform +import matter.controller.InvokeRequest +import matter.controller.InvokeResponse +import matter.controller.MatterController +import matter.controller.ReadData +import matter.controller.ReadRequest +import matter.controller.SubscribeRequest +import matter.controller.SubscriptionState +import matter.controller.UIntSubscriptionState +import matter.controller.UShortSubscriptionState +import matter.controller.cluster.structs.* +import matter.controller.model.AttributePath +import matter.controller.model.CommandPath +import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.TlvReader +import matter.tlv.TlvWriter + +class MessagesCluster(private val controller: MatterController, private val endpointId: UShort) { + class MessagesAttribute(val value: List) + + sealed class MessagesAttributeSubscriptionState { + data class Success(val value: List) : + MessagesAttributeSubscriptionState() + + data class Error(val exception: Exception) : MessagesAttributeSubscriptionState() + + object SubscriptionEstablished : MessagesAttributeSubscriptionState() + } + + class ActiveMessageIDsAttribute(val value: List) + + sealed class ActiveMessageIDsAttributeSubscriptionState { + data class Success(val value: List) : ActiveMessageIDsAttributeSubscriptionState() + + data class Error(val exception: Exception) : ActiveMessageIDsAttributeSubscriptionState() + + object SubscriptionEstablished : ActiveMessageIDsAttributeSubscriptionState() + } + + class GeneratedCommandListAttribute(val value: List) + + sealed class GeneratedCommandListAttributeSubscriptionState { + data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() + + data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() + + object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() + } + + class AcceptedCommandListAttribute(val value: List) + + sealed class AcceptedCommandListAttributeSubscriptionState { + data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() + + data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() + + object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() + } + + class EventListAttribute(val value: List) + + sealed class EventListAttributeSubscriptionState { + data class Success(val value: List) : EventListAttributeSubscriptionState() + + data class Error(val exception: Exception) : EventListAttributeSubscriptionState() + + object SubscriptionEstablished : EventListAttributeSubscriptionState() + } + + class AttributeListAttribute(val value: List) + + sealed class AttributeListAttributeSubscriptionState { + data class Success(val value: List) : AttributeListAttributeSubscriptionState() + + data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() + + object SubscriptionEstablished : AttributeListAttributeSubscriptionState() + } + + suspend fun presentMessagesRequest( + messages: List, + timedInvokeTimeout: Duration? = null + ) { + val commandId: UInt = 0u + + val tlvWriter = TlvWriter() + tlvWriter.startStructure(AnonymousTag) + + val TAG_MESSAGES_REQ: Int = 0 + tlvWriter.startArray(ContextSpecificTag(TAG_MESSAGES_REQ)) + for (item in messages.iterator()) { + item.toTlv(AnonymousTag, tlvWriter) + } + tlvWriter.endArray() + tlvWriter.endStructure() + + val request: InvokeRequest = + InvokeRequest( + CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), + tlvPayload = tlvWriter.getEncoded(), + timedRequest = timedInvokeTimeout + ) + + val response: InvokeResponse = controller.invoke(request) + logger.log(Level.FINE, "Invoke command succeeded: ${response}") + } + + suspend fun cancelMessagesRequest( + messageIDs: List, + timedInvokeTimeout: Duration? = null + ) { + val commandId: UInt = 1u + + val tlvWriter = TlvWriter() + tlvWriter.startStructure(AnonymousTag) + + val TAG_MESSAGE_I_DS_REQ: Int = 0 + tlvWriter.startArray(ContextSpecificTag(TAG_MESSAGE_I_DS_REQ)) + for (item in messageIDs.iterator()) { + tlvWriter.put(AnonymousTag, item) + } + tlvWriter.endArray() + tlvWriter.endStructure() + + val request: InvokeRequest = + InvokeRequest( + CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), + tlvPayload = tlvWriter.getEncoded(), + timedRequest = timedInvokeTimeout + ) + + val response: InvokeResponse = controller.invoke(request) + logger.log(Level.FINE, "Invoke command succeeded: ${response}") + } + + suspend fun readMessagesAttribute(): MessagesAttribute { + val ATTRIBUTE_ID: UInt = 0u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Messages attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MessagesClusterMessageStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + + return MessagesAttribute(decodedValue) + } + + suspend fun subscribeMessagesAttribute( + minInterval: Int, + maxInterval: Int + ): Flow { + val ATTRIBUTE_ID: UInt = 0u + val attributePaths = + listOf( + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + ) + + val subscribeRequest: SubscribeRequest = + SubscribeRequest( + eventPaths = emptyList(), + attributePaths = attributePaths, + minInterval = Duration.ofSeconds(minInterval.toLong()), + maxInterval = Duration.ofSeconds(maxInterval.toLong()) + ) + + return controller.subscribe(subscribeRequest).transform { subscriptionState -> + when (subscriptionState) { + is SubscriptionState.SubscriptionErrorNotification -> { + emit( + MessagesAttributeSubscriptionState.Error( + Exception( + "Subscription terminated with error code: ${subscriptionState.terminationCause}" + ) + ) + ) + } + is SubscriptionState.NodeStateUpdate -> { + val attributeData = + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Messages attribute not found in Node State update" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(MessagesClusterMessageStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + + emit(MessagesAttributeSubscriptionState.Success(decodedValue)) + } + SubscriptionState.SubscriptionEstablished -> { + emit(MessagesAttributeSubscriptionState.SubscriptionEstablished) + } + } + } + } + + suspend fun readActiveMessageIDsAttribute(): ActiveMessageIDsAttribute { + val ATTRIBUTE_ID: UInt = 1u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Activemessageids attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + + return ActiveMessageIDsAttribute(decodedValue) + } + + suspend fun subscribeActiveMessageIDsAttribute( + minInterval: Int, + maxInterval: Int + ): Flow { + val ATTRIBUTE_ID: UInt = 1u + val attributePaths = + listOf( + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + ) + + val subscribeRequest: SubscribeRequest = + SubscribeRequest( + eventPaths = emptyList(), + attributePaths = attributePaths, + minInterval = Duration.ofSeconds(minInterval.toLong()), + maxInterval = Duration.ofSeconds(maxInterval.toLong()) + ) + + return controller.subscribe(subscribeRequest).transform { subscriptionState -> + when (subscriptionState) { + is SubscriptionState.SubscriptionErrorNotification -> { + emit( + ActiveMessageIDsAttributeSubscriptionState.Error( + Exception( + "Subscription terminated with error code: ${subscriptionState.terminationCause}" + ) + ) + ) + } + is SubscriptionState.NodeStateUpdate -> { + val attributeData = + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Activemessageids attribute not found in Node State update" + } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getByteArray(AnonymousTag)) + } + tlvReader.exitContainer() + } + + emit(ActiveMessageIDsAttributeSubscriptionState.Success(decodedValue)) + } + SubscriptionState.SubscriptionEstablished -> { + emit(ActiveMessageIDsAttributeSubscriptionState.SubscriptionEstablished) + } + } + } + } + + suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { + val ATTRIBUTE_ID: UInt = 65528u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Generatedcommandlist attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + + return GeneratedCommandListAttribute(decodedValue) + } + + suspend fun subscribeGeneratedCommandListAttribute( + minInterval: Int, + maxInterval: Int + ): Flow { + val ATTRIBUTE_ID: UInt = 65528u + val attributePaths = + listOf( + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + ) + + val subscribeRequest: SubscribeRequest = + SubscribeRequest( + eventPaths = emptyList(), + attributePaths = attributePaths, + minInterval = Duration.ofSeconds(minInterval.toLong()), + maxInterval = Duration.ofSeconds(maxInterval.toLong()) + ) + + return controller.subscribe(subscribeRequest).transform { subscriptionState -> + when (subscriptionState) { + is SubscriptionState.SubscriptionErrorNotification -> { + emit( + GeneratedCommandListAttributeSubscriptionState.Error( + Exception( + "Subscription terminated with error code: ${subscriptionState.terminationCause}" + ) + ) + ) + } + is SubscriptionState.NodeStateUpdate -> { + val attributeData = + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Generatedcommandlist attribute not found in Node State update" + } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + + emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) + } + SubscriptionState.SubscriptionEstablished -> { + emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) + } + } + } + } + + suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute { + val ATTRIBUTE_ID: UInt = 65529u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Acceptedcommandlist attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + + return AcceptedCommandListAttribute(decodedValue) + } + + suspend fun subscribeAcceptedCommandListAttribute( + minInterval: Int, + maxInterval: Int + ): Flow { + val ATTRIBUTE_ID: UInt = 65529u + val attributePaths = + listOf( + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + ) + + val subscribeRequest: SubscribeRequest = + SubscribeRequest( + eventPaths = emptyList(), + attributePaths = attributePaths, + minInterval = Duration.ofSeconds(minInterval.toLong()), + maxInterval = Duration.ofSeconds(maxInterval.toLong()) + ) + + return controller.subscribe(subscribeRequest).transform { subscriptionState -> + when (subscriptionState) { + is SubscriptionState.SubscriptionErrorNotification -> { + emit( + AcceptedCommandListAttributeSubscriptionState.Error( + Exception( + "Subscription terminated with error code: ${subscriptionState.terminationCause}" + ) + ) + ) + } + is SubscriptionState.NodeStateUpdate -> { + val attributeData = + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Acceptedcommandlist attribute not found in Node State update" + } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + + emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) + } + SubscriptionState.SubscriptionEstablished -> { + emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) + } + } + } + } + + suspend fun readEventListAttribute(): EventListAttribute { + val ATTRIBUTE_ID: UInt = 65530u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Eventlist attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + + return EventListAttribute(decodedValue) + } + + suspend fun subscribeEventListAttribute( + minInterval: Int, + maxInterval: Int + ): Flow { + val ATTRIBUTE_ID: UInt = 65530u + val attributePaths = + listOf( + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + ) + + val subscribeRequest: SubscribeRequest = + SubscribeRequest( + eventPaths = emptyList(), + attributePaths = attributePaths, + minInterval = Duration.ofSeconds(minInterval.toLong()), + maxInterval = Duration.ofSeconds(maxInterval.toLong()) + ) + + return controller.subscribe(subscribeRequest).transform { subscriptionState -> + when (subscriptionState) { + is SubscriptionState.SubscriptionErrorNotification -> { + emit( + EventListAttributeSubscriptionState.Error( + Exception( + "Subscription terminated with error code: ${subscriptionState.terminationCause}" + ) + ) + ) + } + is SubscriptionState.NodeStateUpdate -> { + val attributeData = + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Eventlist attribute not found in Node State update" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + + emit(EventListAttributeSubscriptionState.Success(decodedValue)) + } + SubscriptionState.SubscriptionEstablished -> { + emit(EventListAttributeSubscriptionState.SubscriptionEstablished) + } + } + } + } + + suspend fun readAttributeListAttribute(): AttributeListAttribute { + val ATTRIBUTE_ID: UInt = 65531u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Attributelist attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + + return AttributeListAttribute(decodedValue) + } + + suspend fun subscribeAttributeListAttribute( + minInterval: Int, + maxInterval: Int + ): Flow { + val ATTRIBUTE_ID: UInt = 65531u + val attributePaths = + listOf( + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + ) + + val subscribeRequest: SubscribeRequest = + SubscribeRequest( + eventPaths = emptyList(), + attributePaths = attributePaths, + minInterval = Duration.ofSeconds(minInterval.toLong()), + maxInterval = Duration.ofSeconds(maxInterval.toLong()) + ) + + return controller.subscribe(subscribeRequest).transform { subscriptionState -> + when (subscriptionState) { + is SubscriptionState.SubscriptionErrorNotification -> { + emit( + AttributeListAttributeSubscriptionState.Error( + Exception( + "Subscription terminated with error code: ${subscriptionState.terminationCause}" + ) + ) + ) + } + is SubscriptionState.NodeStateUpdate -> { + val attributeData = + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Attributelist attribute not found in Node State update" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + + emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) + } + SubscriptionState.SubscriptionEstablished -> { + emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) + } + } + } + } + + suspend fun readFeatureMapAttribute(): UInt { + val ATTRIBUTE_ID: UInt = 65532u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Featuremap attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: UInt = tlvReader.getUInt(AnonymousTag) + + return decodedValue + } + + suspend fun subscribeFeatureMapAttribute( + minInterval: Int, + maxInterval: Int + ): Flow { + val ATTRIBUTE_ID: UInt = 65532u + val attributePaths = + listOf( + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + ) + + val subscribeRequest: SubscribeRequest = + SubscribeRequest( + eventPaths = emptyList(), + attributePaths = attributePaths, + minInterval = Duration.ofSeconds(minInterval.toLong()), + maxInterval = Duration.ofSeconds(maxInterval.toLong()) + ) + + return controller.subscribe(subscribeRequest).transform { subscriptionState -> + when (subscriptionState) { + is SubscriptionState.SubscriptionErrorNotification -> { + emit( + UIntSubscriptionState.Error( + Exception( + "Subscription terminated with error code: ${subscriptionState.terminationCause}" + ) + ) + ) + } + is SubscriptionState.NodeStateUpdate -> { + val attributeData = + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { "Featuremap attribute not found in Node State update" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: UInt = tlvReader.getUInt(AnonymousTag) + + emit(UIntSubscriptionState.Success(decodedValue)) + } + SubscriptionState.SubscriptionEstablished -> { + emit(UIntSubscriptionState.SubscriptionEstablished) + } + } + } + } + + suspend fun readClusterRevisionAttribute(): UShort { + val ATTRIBUTE_ID: UInt = 65533u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Clusterrevision attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: UShort = tlvReader.getUShort(AnonymousTag) + + return decodedValue + } + + suspend fun subscribeClusterRevisionAttribute( + minInterval: Int, + maxInterval: Int + ): Flow { + val ATTRIBUTE_ID: UInt = 65533u + val attributePaths = + listOf( + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + ) + + val subscribeRequest: SubscribeRequest = + SubscribeRequest( + eventPaths = emptyList(), + attributePaths = attributePaths, + minInterval = Duration.ofSeconds(minInterval.toLong()), + maxInterval = Duration.ofSeconds(maxInterval.toLong()) + ) + + return controller.subscribe(subscribeRequest).transform { subscriptionState -> + when (subscriptionState) { + is SubscriptionState.SubscriptionErrorNotification -> { + emit( + UShortSubscriptionState.Error( + Exception( + "Subscription terminated with error code: ${subscriptionState.terminationCause}" + ) + ) + ) + } + is SubscriptionState.NodeStateUpdate -> { + val attributeData = + subscriptionState.updateState.successes + .filterIsInstance() + .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } + + requireNotNull(attributeData) { + "Clusterrevision attribute not found in Node State update" + } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: UShort = tlvReader.getUShort(AnonymousTag) + + emit(UShortSubscriptionState.Success(decodedValue)) + } + SubscriptionState.SubscriptionEstablished -> { + emit(UShortSubscriptionState.SubscriptionEstablished) + } + } + } + } + + companion object { + private val logger = Logger.getLogger(MessagesCluster::class.java.name) + const val CLUSTER_ID: UInt = 151u + } +} diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt new file mode 100644 index 00000000000000..4c30c4ec20bd82 --- /dev/null +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt @@ -0,0 +1,119 @@ +/* + * + * 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.controller.cluster.eventstructs + +import java.util.Optional +import matter.controller.cluster.* +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvReader +import matter.tlv.TlvWriter + +class MessagesClusterMessageCompleteEvent( + val messageID: ByteArray, + val responseID: Optional?, + val reply: Optional?, + val futureMessagesPreference: UByte? +) { + override fun toString(): String = buildString { + append("MessagesClusterMessageCompleteEvent {\n") + append("\tmessageID : $messageID\n") + append("\tresponseID : $responseID\n") + append("\treply : $reply\n") + append("\tfutureMessagesPreference : $futureMessagesPreference\n") + append("}\n") + } + + fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { + tlvWriter.apply { + startStructure(tlvTag) + put(ContextSpecificTag(TAG_MESSAGE_I_D), messageID) + if (responseID != null) { + if (responseID.isPresent) { + val optresponseID = responseID.get() + put(ContextSpecificTag(TAG_RESPONSE_I_D), optresponseID) + } + } else { + putNull(ContextSpecificTag(TAG_RESPONSE_I_D)) + } + if (reply != null) { + if (reply.isPresent) { + val optreply = reply.get() + put(ContextSpecificTag(TAG_REPLY), optreply) + } + } else { + putNull(ContextSpecificTag(TAG_REPLY)) + } + if (futureMessagesPreference != null) { + put(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE), futureMessagesPreference) + } else { + putNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) + } + endStructure() + } + } + + companion object { + private const val TAG_MESSAGE_I_D = 0 + private const val TAG_RESPONSE_I_D = 1 + private const val TAG_REPLY = 2 + private const val TAG_FUTURE_MESSAGES_PREFERENCE = 3 + + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageCompleteEvent { + tlvReader.enterStructure(tlvTag) + val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_I_D)) + val responseID = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSE_I_D))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_RESPONSE_I_D))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_RESPONSE_I_D)) + null + } + val reply = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(ContextSpecificTag(TAG_REPLY))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_REPLY))) + } else { + Optional.empty() + } + } else { + tlvReader.getNull(ContextSpecificTag(TAG_REPLY)) + null + } + val futureMessagesPreference = + if (!tlvReader.isNull()) { + tlvReader.getUByte(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE)) + null + } + + tlvReader.exitContainer() + + return MessagesClusterMessageCompleteEvent( + messageID, + responseID, + reply, + futureMessagesPreference + ) + } + } +} diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt new file mode 100644 index 00000000000000..7ca3f028ab4b99 --- /dev/null +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt @@ -0,0 +1,52 @@ +/* + * + * 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.controller.cluster.eventstructs + +import matter.controller.cluster.* +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvReader +import matter.tlv.TlvWriter + +class MessagesClusterMessagePresentedEvent(val messageID: ByteArray) { + override fun toString(): String = buildString { + append("MessagesClusterMessagePresentedEvent {\n") + append("\tmessageID : $messageID\n") + append("}\n") + } + + fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { + tlvWriter.apply { + startStructure(tlvTag) + put(ContextSpecificTag(TAG_MESSAGE_I_D), messageID) + endStructure() + } + } + + companion object { + private const val TAG_MESSAGE_I_D = 0 + + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessagePresentedEvent { + tlvReader.enterStructure(tlvTag) + val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_I_D)) + + tlvReader.exitContainer() + + return MessagesClusterMessagePresentedEvent(messageID) + } + } +} diff --git a/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt new file mode 100644 index 00000000000000..6292136f5419a8 --- /dev/null +++ b/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt @@ -0,0 +1,52 @@ +/* + * + * 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.controller.cluster.eventstructs + +import matter.controller.cluster.* +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvReader +import matter.tlv.TlvWriter + +class MessagesClusterMessageQueuedEvent(val messageID: ByteArray) { + override fun toString(): String = buildString { + append("MessagesClusterMessageQueuedEvent {\n") + append("\tmessageID : $messageID\n") + append("}\n") + } + + fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { + tlvWriter.apply { + startStructure(tlvTag) + put(ContextSpecificTag(TAG_MESSAGE_I_D), messageID) + endStructure() + } + } + + companion object { + private const val TAG_MESSAGE_I_D = 0 + + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageQueuedEvent { + tlvReader.enterStructure(tlvTag) + val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_I_D)) + + tlvReader.exitContainer() + + return MessagesClusterMessageQueuedEvent(messageID) + } + } +} diff --git a/src/controller/java/generated/java/matter/controller/cluster/files.gni b/src/controller/java/generated/java/matter/controller/cluster/files.gni index 948acea4fffff5..83a43a79ffe791 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/files.gni +++ b/src/controller/java/generated/java/matter/controller/cluster/files.gni @@ -77,6 +77,8 @@ matter_structs_sources = [ "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterPlaybackPositionStruct.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackAttributesStruct.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/MediaPlaybackClusterTrackStruct.kt", + "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt", + "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeOptionStruct.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/MicrowaveOvenModeClusterModeTagStruct.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/ModeSelectClusterModeOptionStruct.kt", @@ -170,6 +172,9 @@ matter_eventstructs_sources = [ "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterNetworkFaultChangeEvent.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/GeneralDiagnosticsClusterRadioFaultChangeEvent.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MediaPlaybackClusterStateChangedEvent.kt", + "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageCompleteEvent.kt", + "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessagePresentedEvent.kt", + "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/MessagesClusterMessageQueuedEvent.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationalErrorEvent.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OperationalStateClusterOperationCompletionEvent.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/OtaSoftwareUpdateRequestorClusterDownloadErrorEvent.kt", @@ -273,6 +278,7 @@ matter_clusters_sources = [ "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/clusters/LowPowerCluster.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaInputCluster.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/clusters/MediaPlaybackCluster.kt", + "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/clusters/MessagesCluster.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenControlCluster.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/clusters/MicrowaveOvenModeCluster.kt", "${chip_root}/src/controller/java/generated/java/matter/controller/cluster/clusters/ModeSelectCluster.kt", diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt new file mode 100644 index 00000000000000..8323af66ea03ca --- /dev/null +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageResponseOptionStruct.kt @@ -0,0 +1,76 @@ +/* + * + * 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.controller.cluster.structs + +import java.util.Optional +import matter.controller.cluster.* +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvReader +import matter.tlv.TlvWriter + +class MessagesClusterMessageResponseOptionStruct( + val messageResponseID: Optional, + val label: Optional +) { + override fun toString(): String = buildString { + append("MessagesClusterMessageResponseOptionStruct {\n") + append("\tmessageResponseID : $messageResponseID\n") + append("\tlabel : $label\n") + append("}\n") + } + + fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { + tlvWriter.apply { + startStructure(tlvTag) + if (messageResponseID.isPresent) { + val optmessageResponseID = messageResponseID.get() + put(ContextSpecificTag(TAG_MESSAGE_RESPONSE_I_D), optmessageResponseID) + } + if (label.isPresent) { + val optlabel = label.get() + put(ContextSpecificTag(TAG_LABEL), optlabel) + } + endStructure() + } + } + + companion object { + private const val TAG_MESSAGE_RESPONSE_I_D = 0 + private const val TAG_LABEL = 1 + + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageResponseOptionStruct { + tlvReader.enterStructure(tlvTag) + val messageResponseID = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_MESSAGE_RESPONSE_I_D))) { + Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_MESSAGE_RESPONSE_I_D))) + } else { + Optional.empty() + } + val label = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_LABEL))) { + Optional.of(tlvReader.getString(ContextSpecificTag(TAG_LABEL))) + } else { + Optional.empty() + } + + tlvReader.exitContainer() + + return MessagesClusterMessageResponseOptionStruct(messageResponseID, label) + } + } +} diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt new file mode 100644 index 00000000000000..8560beb0a72ce1 --- /dev/null +++ b/src/controller/java/generated/java/matter/controller/cluster/structs/MessagesClusterMessageStruct.kt @@ -0,0 +1,134 @@ +/* + * + * 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.controller.cluster.structs + +import java.util.Optional +import matter.controller.cluster.* +import matter.tlv.AnonymousTag +import matter.tlv.ContextSpecificTag +import matter.tlv.Tag +import matter.tlv.TlvReader +import matter.tlv.TlvWriter + +class MessagesClusterMessageStruct( + val messageID: ByteArray, + val priority: UByte, + val messageControl: UByte, + val startTime: UInt?, + val duration: UShort?, + val messageText: String, + val responses: Optional> +) { + override fun toString(): String = buildString { + append("MessagesClusterMessageStruct {\n") + append("\tmessageID : $messageID\n") + append("\tpriority : $priority\n") + append("\tmessageControl : $messageControl\n") + append("\tstartTime : $startTime\n") + append("\tduration : $duration\n") + append("\tmessageText : $messageText\n") + append("\tresponses : $responses\n") + append("}\n") + } + + fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { + tlvWriter.apply { + startStructure(tlvTag) + put(ContextSpecificTag(TAG_MESSAGE_I_D), messageID) + put(ContextSpecificTag(TAG_PRIORITY), priority) + put(ContextSpecificTag(TAG_MESSAGE_CONTROL), messageControl) + if (startTime != null) { + put(ContextSpecificTag(TAG_START_TIME), startTime) + } else { + putNull(ContextSpecificTag(TAG_START_TIME)) + } + if (duration != null) { + put(ContextSpecificTag(TAG_DURATION), duration) + } else { + putNull(ContextSpecificTag(TAG_DURATION)) + } + put(ContextSpecificTag(TAG_MESSAGE_TEXT), messageText) + if (responses.isPresent) { + val optresponses = responses.get() + startArray(ContextSpecificTag(TAG_RESPONSES)) + for (item in optresponses.iterator()) { + item.toTlv(AnonymousTag, this) + } + endArray() + } + endStructure() + } + } + + companion object { + private const val TAG_MESSAGE_I_D = 0 + private const val TAG_PRIORITY = 1 + private const val TAG_MESSAGE_CONTROL = 2 + private const val TAG_START_TIME = 3 + private const val TAG_DURATION = 4 + private const val TAG_MESSAGE_TEXT = 5 + private const val TAG_RESPONSES = 6 + + fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageStruct { + tlvReader.enterStructure(tlvTag) + val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_I_D)) + val priority = tlvReader.getUByte(ContextSpecificTag(TAG_PRIORITY)) + val messageControl = tlvReader.getUByte(ContextSpecificTag(TAG_MESSAGE_CONTROL)) + val startTime = + if (!tlvReader.isNull()) { + tlvReader.getUInt(ContextSpecificTag(TAG_START_TIME)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_START_TIME)) + null + } + val duration = + if (!tlvReader.isNull()) { + tlvReader.getUShort(ContextSpecificTag(TAG_DURATION)) + } else { + tlvReader.getNull(ContextSpecificTag(TAG_DURATION)) + null + } + val messageText = tlvReader.getString(ContextSpecificTag(TAG_MESSAGE_TEXT)) + val responses = + if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSES))) { + Optional.of( + buildList { + tlvReader.enterArray(ContextSpecificTag(TAG_RESPONSES)) + while (!tlvReader.isEndOfContainer()) { + add(MessagesClusterMessageResponseOptionStruct.fromTlv(AnonymousTag, tlvReader)) + } + tlvReader.exitContainer() + } + ) + } else { + Optional.empty() + } + + tlvReader.exitContainer() + + return MessagesClusterMessageStruct( + messageID, + priority, + messageControl, + startTime, + duration, + messageText, + responses + ) + } + } +} diff --git a/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp b/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp index bad7740f5be819..8afc7c33e1da24 100644 --- a/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp +++ b/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp @@ -21830,6 +21830,341 @@ jobject DecodeAttributeValue(const app::ConcreteAttributePath & aPath, TLV::TLVR } break; } + case app::Clusters::Messages::Id: { + using namespace app::Clusters::Messages; + switch (aPath.mAttributeId) + { + case Attributes::Messages::Id: { + using TypeInfo = Attributes::Messages::TypeInfo; + TypeInfo::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value; + chip::JniReferences::GetInstance().CreateArrayList(value); + + auto iter_value_0 = cppValue.begin(); + while (iter_value_0.Next()) + { + auto & entry_0 = iter_value_0.GetValue(); + jobject newElement_0; + jobject newElement_0_messageID; + jbyteArray newElement_0_messageIDByteArray = env->NewByteArray(static_cast(entry_0.messageID.size())); + env->SetByteArrayRegion(newElement_0_messageIDByteArray, 0, static_cast(entry_0.messageID.size()), + reinterpret_cast(entry_0.messageID.data())); + newElement_0_messageID = newElement_0_messageIDByteArray; + jobject newElement_0_priority; + std::string newElement_0_priorityClassName = "java/lang/Integer"; + std::string newElement_0_priorityCtorSignature = "(I)V"; + jint jninewElement_0_priority = static_cast(entry_0.priority); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0_priorityClassName.c_str(), + newElement_0_priorityCtorSignature.c_str(), + jninewElement_0_priority, newElement_0_priority); + jobject newElement_0_messageControl; + std::string newElement_0_messageControlClassName = "java/lang/Integer"; + std::string newElement_0_messageControlCtorSignature = "(I)V"; + jint jninewElement_0_messageControl = static_cast(entry_0.messageControl.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_messageControlClassName.c_str(), newElement_0_messageControlCtorSignature.c_str(), + jninewElement_0_messageControl, newElement_0_messageControl); + jobject newElement_0_startTime; + if (entry_0.startTime.IsNull()) + { + newElement_0_startTime = nullptr; + } + else + { + std::string newElement_0_startTimeClassName = "java/lang/Long"; + std::string newElement_0_startTimeCtorSignature = "(J)V"; + jlong jninewElement_0_startTime = static_cast(entry_0.startTime.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0_startTimeClassName.c_str(), + newElement_0_startTimeCtorSignature.c_str(), + jninewElement_0_startTime, newElement_0_startTime); + } + jobject newElement_0_duration; + if (entry_0.duration.IsNull()) + { + newElement_0_duration = nullptr; + } + else + { + std::string newElement_0_durationClassName = "java/lang/Integer"; + std::string newElement_0_durationCtorSignature = "(I)V"; + jint jninewElement_0_duration = static_cast(entry_0.duration.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0_durationClassName.c_str(), + newElement_0_durationCtorSignature.c_str(), + jninewElement_0_duration, newElement_0_duration); + } + jobject newElement_0_messageText; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(entry_0.messageText, newElement_0_messageText)); + jobject newElement_0_responses; + if (!entry_0.responses.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_responses); + } + else + { + jobject newElement_0_responsesInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(newElement_0_responsesInsideOptional); + + auto iter_newElement_0_responsesInsideOptional_3 = entry_0.responses.Value().begin(); + while (iter_newElement_0_responsesInsideOptional_3.Next()) + { + auto & entry_3 = iter_newElement_0_responsesInsideOptional_3.GetValue(); + jobject newElement_3; + jobject newElement_3_messageResponseID; + if (!entry_3.messageResponseID.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_3_messageResponseID); + } + else + { + jobject newElement_3_messageResponseIDInsideOptional; + std::string newElement_3_messageResponseIDInsideOptionalClassName = "java/lang/Long"; + std::string newElement_3_messageResponseIDInsideOptionalCtorSignature = "(J)V"; + jlong jninewElement_3_messageResponseIDInsideOptional = + static_cast(entry_3.messageResponseID.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_3_messageResponseIDInsideOptionalClassName.c_str(), + newElement_3_messageResponseIDInsideOptionalCtorSignature.c_str(), + jninewElement_3_messageResponseIDInsideOptional, newElement_3_messageResponseIDInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(newElement_3_messageResponseIDInsideOptional, + newElement_3_messageResponseID); + } + jobject newElement_3_label; + if (!entry_3.label.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_3_label); + } + else + { + jobject newElement_3_labelInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_3.label.Value(), + newElement_3_labelInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_3_labelInsideOptional, newElement_3_label); + } + + jclass messageResponseOptionStructStructClass_4; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$MessagesClusterMessageResponseOptionStruct", + messageResponseOptionStructStructClass_4); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$MessagesClusterMessageResponseOptionStruct"); + return nullptr; + } + + jmethodID messageResponseOptionStructStructCtor_4; + err = chip::JniReferences::GetInstance().FindMethod(env, messageResponseOptionStructStructClass_4, "", + "(Ljava/util/Optional;Ljava/util/Optional;)V", + &messageResponseOptionStructStructCtor_4); + if (err != CHIP_NO_ERROR || messageResponseOptionStructStructCtor_4 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$MessagesClusterMessageResponseOptionStruct constructor"); + return nullptr; + } + + newElement_3 = + env->NewObject(messageResponseOptionStructStructClass_4, messageResponseOptionStructStructCtor_4, + newElement_3_messageResponseID, newElement_3_label); + chip::JniReferences::GetInstance().AddToList(newElement_0_responsesInsideOptional, newElement_3); + } + chip::JniReferences::GetInstance().CreateOptional(newElement_0_responsesInsideOptional, newElement_0_responses); + } + + jclass messageStructStructClass_1; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$MessagesClusterMessageStruct", messageStructStructClass_1); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$MessagesClusterMessageStruct"); + return nullptr; + } + + jmethodID messageStructStructCtor_1; + err = + chip::JniReferences::GetInstance().FindMethod(env, messageStructStructClass_1, "", + "([BLjava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Long;Ljava/" + "lang/Integer;Ljava/lang/String;Ljava/util/Optional;)V", + &messageStructStructCtor_1); + if (err != CHIP_NO_ERROR || messageStructStructCtor_1 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$MessagesClusterMessageStruct constructor"); + return nullptr; + } + + newElement_0 = env->NewObject(messageStructStructClass_1, messageStructStructCtor_1, newElement_0_messageID, + newElement_0_priority, newElement_0_messageControl, newElement_0_startTime, + newElement_0_duration, newElement_0_messageText, newElement_0_responses); + chip::JniReferences::GetInstance().AddToList(value, newElement_0); + } + return value; + } + case Attributes::ActiveMessageIDs::Id: { + using TypeInfo = Attributes::ActiveMessageIDs::TypeInfo; + TypeInfo::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value; + chip::JniReferences::GetInstance().CreateArrayList(value); + + auto iter_value_0 = cppValue.begin(); + while (iter_value_0.Next()) + { + auto & entry_0 = iter_value_0.GetValue(); + jobject newElement_0; + jbyteArray newElement_0ByteArray = env->NewByteArray(static_cast(entry_0.size())); + env->SetByteArrayRegion(newElement_0ByteArray, 0, static_cast(entry_0.size()), + reinterpret_cast(entry_0.data())); + newElement_0 = newElement_0ByteArray; + chip::JniReferences::GetInstance().AddToList(value, newElement_0); + } + return value; + } + case Attributes::GeneratedCommandList::Id: { + using TypeInfo = Attributes::GeneratedCommandList::TypeInfo; + TypeInfo::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value; + chip::JniReferences::GetInstance().CreateArrayList(value); + + auto iter_value_0 = cppValue.begin(); + while (iter_value_0.Next()) + { + auto & entry_0 = iter_value_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Long"; + std::string newElement_0CtorSignature = "(J)V"; + jlong jninewElement_0 = static_cast(entry_0); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), jninewElement_0, newElement_0); + chip::JniReferences::GetInstance().AddToList(value, newElement_0); + } + return value; + } + case Attributes::AcceptedCommandList::Id: { + using TypeInfo = Attributes::AcceptedCommandList::TypeInfo; + TypeInfo::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value; + chip::JniReferences::GetInstance().CreateArrayList(value); + + auto iter_value_0 = cppValue.begin(); + while (iter_value_0.Next()) + { + auto & entry_0 = iter_value_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Long"; + std::string newElement_0CtorSignature = "(J)V"; + jlong jninewElement_0 = static_cast(entry_0); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), jninewElement_0, newElement_0); + chip::JniReferences::GetInstance().AddToList(value, newElement_0); + } + return value; + } + case Attributes::EventList::Id: { + using TypeInfo = Attributes::EventList::TypeInfo; + TypeInfo::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value; + chip::JniReferences::GetInstance().CreateArrayList(value); + + auto iter_value_0 = cppValue.begin(); + while (iter_value_0.Next()) + { + auto & entry_0 = iter_value_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Long"; + std::string newElement_0CtorSignature = "(J)V"; + jlong jninewElement_0 = static_cast(entry_0); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), jninewElement_0, newElement_0); + chip::JniReferences::GetInstance().AddToList(value, newElement_0); + } + return value; + } + case Attributes::AttributeList::Id: { + using TypeInfo = Attributes::AttributeList::TypeInfo; + TypeInfo::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value; + chip::JniReferences::GetInstance().CreateArrayList(value); + + auto iter_value_0 = cppValue.begin(); + while (iter_value_0.Next()) + { + auto & entry_0 = iter_value_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Long"; + std::string newElement_0CtorSignature = "(J)V"; + jlong jninewElement_0 = static_cast(entry_0); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), jninewElement_0, newElement_0); + chip::JniReferences::GetInstance().AddToList(value, newElement_0); + } + return value; + } + case Attributes::FeatureMap::Id: { + using TypeInfo = Attributes::FeatureMap::TypeInfo; + TypeInfo::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value; + std::string valueClassName = "java/lang/Long"; + std::string valueCtorSignature = "(J)V"; + jlong jnivalue = static_cast(cppValue); + chip::JniReferences::GetInstance().CreateBoxedObject(valueClassName.c_str(), valueCtorSignature.c_str(), + jnivalue, value); + return value; + } + case Attributes::ClusterRevision::Id: { + using TypeInfo = Attributes::ClusterRevision::TypeInfo; + TypeInfo::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value; + std::string valueClassName = "java/lang/Integer"; + std::string valueCtorSignature = "(I)V"; + jint jnivalue = static_cast(cppValue); + chip::JniReferences::GetInstance().CreateBoxedObject(valueClassName.c_str(), valueCtorSignature.c_str(), jnivalue, + value); + return value; + } + default: + *aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB; + break; + } + break; + } case app::Clusters::DeviceEnergyManagement::Id: { using namespace app::Clusters::DeviceEnergyManagement; switch (aPath.mAttributeId) diff --git a/src/controller/java/zap-generated/CHIPEventTLVValueDecoder.cpp b/src/controller/java/zap-generated/CHIPEventTLVValueDecoder.cpp index c69aaf67df9e4d..4795647b3e242f 100644 --- a/src/controller/java/zap-generated/CHIPEventTLVValueDecoder.cpp +++ b/src/controller/java/zap-generated/CHIPEventTLVValueDecoder.cpp @@ -5130,6 +5130,182 @@ jobject DecodeEventValue(const app::ConcreteEventPath & aPath, TLV::TLVReader & } break; } + case app::Clusters::Messages::Id: { + using namespace app::Clusters::Messages; + switch (aPath.mEventId) + { + case Events::MessageQueued::Id: { + Events::MessageQueued::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value_messageID; + jbyteArray value_messageIDByteArray = env->NewByteArray(static_cast(cppValue.messageID.size())); + env->SetByteArrayRegion(value_messageIDByteArray, 0, static_cast(cppValue.messageID.size()), + reinterpret_cast(cppValue.messageID.data())); + value_messageID = value_messageIDByteArray; + + jclass messageQueuedStructClass; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipEventStructs$MessagesClusterMessageQueuedEvent", messageQueuedStructClass); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipEventStructs$MessagesClusterMessageQueuedEvent"); + return nullptr; + } + + jmethodID messageQueuedStructCtor; + err = chip::JniReferences::GetInstance().FindMethod(env, messageQueuedStructClass, "", "([B)V", + &messageQueuedStructCtor); + if (err != CHIP_NO_ERROR || messageQueuedStructCtor == nullptr) + { + ChipLogError(Zcl, "Could not find ChipEventStructs$MessagesClusterMessageQueuedEvent constructor"); + return nullptr; + } + + jobject value = env->NewObject(messageQueuedStructClass, messageQueuedStructCtor, value_messageID); + + return value; + } + case Events::MessagePresented::Id: { + Events::MessagePresented::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value_messageID; + jbyteArray value_messageIDByteArray = env->NewByteArray(static_cast(cppValue.messageID.size())); + env->SetByteArrayRegion(value_messageIDByteArray, 0, static_cast(cppValue.messageID.size()), + reinterpret_cast(cppValue.messageID.data())); + value_messageID = value_messageIDByteArray; + + jclass messagePresentedStructClass; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipEventStructs$MessagesClusterMessagePresentedEvent", messagePresentedStructClass); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipEventStructs$MessagesClusterMessagePresentedEvent"); + return nullptr; + } + + jmethodID messagePresentedStructCtor; + err = chip::JniReferences::GetInstance().FindMethod(env, messagePresentedStructClass, "", "([B)V", + &messagePresentedStructCtor); + if (err != CHIP_NO_ERROR || messagePresentedStructCtor == nullptr) + { + ChipLogError(Zcl, "Could not find ChipEventStructs$MessagesClusterMessagePresentedEvent constructor"); + return nullptr; + } + + jobject value = env->NewObject(messagePresentedStructClass, messagePresentedStructCtor, value_messageID); + + return value; + } + case Events::MessageComplete::Id: { + Events::MessageComplete::DecodableType cppValue; + *aError = app::DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) + { + return nullptr; + } + jobject value_messageID; + jbyteArray value_messageIDByteArray = env->NewByteArray(static_cast(cppValue.messageID.size())); + env->SetByteArrayRegion(value_messageIDByteArray, 0, static_cast(cppValue.messageID.size()), + reinterpret_cast(cppValue.messageID.data())); + value_messageID = value_messageIDByteArray; + + jobject value_responseID; + if (!cppValue.responseID.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, value_responseID); + } + else + { + jobject value_responseIDInsideOptional; + if (cppValue.responseID.Value().IsNull()) + { + value_responseIDInsideOptional = nullptr; + } + else + { + std::string value_responseIDInsideOptionalClassName = "java/lang/Long"; + std::string value_responseIDInsideOptionalCtorSignature = "(J)V"; + jlong jnivalue_responseIDInsideOptional = static_cast(cppValue.responseID.Value().Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + value_responseIDInsideOptionalClassName.c_str(), value_responseIDInsideOptionalCtorSignature.c_str(), + jnivalue_responseIDInsideOptional, value_responseIDInsideOptional); + } + chip::JniReferences::GetInstance().CreateOptional(value_responseIDInsideOptional, value_responseID); + } + + jobject value_reply; + if (!cppValue.reply.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, value_reply); + } + else + { + jobject value_replyInsideOptional; + if (cppValue.reply.Value().IsNull()) + { + value_replyInsideOptional = nullptr; + } + else + { + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(cppValue.reply.Value().Value(), + value_replyInsideOptional)); + } + chip::JniReferences::GetInstance().CreateOptional(value_replyInsideOptional, value_reply); + } + + jobject value_futureMessagesPreference; + if (cppValue.futureMessagesPreference.IsNull()) + { + value_futureMessagesPreference = nullptr; + } + else + { + std::string value_futureMessagesPreferenceClassName = "java/lang/Integer"; + std::string value_futureMessagesPreferenceCtorSignature = "(I)V"; + jint jnivalue_futureMessagesPreference = static_cast(cppValue.futureMessagesPreference.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + value_futureMessagesPreferenceClassName.c_str(), value_futureMessagesPreferenceCtorSignature.c_str(), + jnivalue_futureMessagesPreference, value_futureMessagesPreference); + } + + jclass messageCompleteStructClass; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipEventStructs$MessagesClusterMessageCompleteEvent", messageCompleteStructClass); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipEventStructs$MessagesClusterMessageCompleteEvent"); + return nullptr; + } + + jmethodID messageCompleteStructCtor; + err = chip::JniReferences::GetInstance().FindMethod(env, messageCompleteStructClass, "", + "([BLjava/util/Optional;Ljava/util/Optional;Ljava/lang/Integer;)V", + &messageCompleteStructCtor); + if (err != CHIP_NO_ERROR || messageCompleteStructCtor == nullptr) + { + ChipLogError(Zcl, "Could not find ChipEventStructs$MessagesClusterMessageCompleteEvent constructor"); + return nullptr; + } + + jobject value = env->NewObject(messageCompleteStructClass, messageCompleteStructCtor, value_messageID, value_responseID, + value_reply, value_futureMessagesPreference); + + return value; + } + default: + *aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB; + break; + } + break; + } case app::Clusters::DeviceEnergyManagement::Id: { using namespace app::Clusters::DeviceEnergyManagement; switch (aPath.mEventId) diff --git a/src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp b/src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp new file mode 100644 index 00000000000000..81f52531281c3d --- /dev/null +++ b/src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp @@ -0,0 +1,8525 @@ +/* + * + * Copyright (c) 2022 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. + */ + +// THIS FILE IS GENERATED BY ZAP +#include "CHIPInvokeCallbacks.h" +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace chip { + +CHIPGroupsClusterAddGroupResponseCallback::CHIPGroupsClusterAddGroupResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPGroupsClusterAddGroupResponseCallback::~CHIPGroupsClusterAddGroupResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGroupsClusterAddGroupResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Groups::Commands::AddGroupResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject GroupID; + std::string GroupIDClassName = "java/lang/Integer"; + std::string GroupIDCtorSignature = "(I)V"; + jint jniGroupID = static_cast(dataResponse.groupID); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupIDClassName.c_str(), GroupIDCtorSignature.c_str(), jniGroupID, + GroupID); + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, GroupID); +} +CHIPGroupsClusterViewGroupResponseCallback::CHIPGroupsClusterViewGroupResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPGroupsClusterViewGroupResponseCallback::~CHIPGroupsClusterViewGroupResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGroupsClusterViewGroupResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Groups::Commands::ViewGroupResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/String;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject GroupID; + std::string GroupIDClassName = "java/lang/Integer"; + std::string GroupIDCtorSignature = "(I)V"; + jint jniGroupID = static_cast(dataResponse.groupID); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupIDClassName.c_str(), GroupIDCtorSignature.c_str(), jniGroupID, + GroupID); + jobject GroupName; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.groupName, GroupName)); + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, GroupID, GroupName); +} +CHIPGroupsClusterGetGroupMembershipResponseCallback::CHIPGroupsClusterGetGroupMembershipResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPGroupsClusterGetGroupMembershipResponseCallback::~CHIPGroupsClusterGetGroupMembershipResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGroupsClusterGetGroupMembershipResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Groups::Commands::GetGroupMembershipResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/ArrayList;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Capacity; + if (dataResponse.capacity.IsNull()) + { + Capacity = nullptr; + } + else + { + std::string CapacityClassName = "java/lang/Integer"; + std::string CapacityCtorSignature = "(I)V"; + jint jniCapacity = static_cast(dataResponse.capacity.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(CapacityClassName.c_str(), CapacityCtorSignature.c_str(), + jniCapacity, Capacity); + } + jobject GroupList; + chip::JniReferences::GetInstance().CreateArrayList(GroupList); + + auto iter_GroupList_0 = dataResponse.groupList.begin(); + while (iter_GroupList_0.Next()) + { + auto & entry_0 = iter_GroupList_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + jint jninewElement_0 = static_cast(entry_0); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), + jninewElement_0, newElement_0); + chip::JniReferences::GetInstance().AddToList(GroupList, newElement_0); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Capacity, GroupList); +} +CHIPGroupsClusterRemoveGroupResponseCallback::CHIPGroupsClusterRemoveGroupResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPGroupsClusterRemoveGroupResponseCallback::~CHIPGroupsClusterRemoveGroupResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGroupsClusterRemoveGroupResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Groups::Commands::RemoveGroupResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject GroupID; + std::string GroupIDClassName = "java/lang/Integer"; + std::string GroupIDCtorSignature = "(I)V"; + jint jniGroupID = static_cast(dataResponse.groupID); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupIDClassName.c_str(), GroupIDCtorSignature.c_str(), jniGroupID, + GroupID); + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, GroupID); +} +CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback::CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback::~CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOtaSoftwareUpdateProviderClusterQueryImageResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImageResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/" + "Optional;Ljava/util/Optional;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject DelayedActionTime; + if (!dataResponse.delayedActionTime.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, DelayedActionTime); + } + else + { + jobject DelayedActionTimeInsideOptional; + std::string DelayedActionTimeInsideOptionalClassName = "java/lang/Long"; + std::string DelayedActionTimeInsideOptionalCtorSignature = "(J)V"; + jlong jniDelayedActionTimeInsideOptional = static_cast(dataResponse.delayedActionTime.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + DelayedActionTimeInsideOptionalClassName.c_str(), DelayedActionTimeInsideOptionalCtorSignature.c_str(), + jniDelayedActionTimeInsideOptional, DelayedActionTimeInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(DelayedActionTimeInsideOptional, DelayedActionTime); + } + jobject ImageURI; + if (!dataResponse.imageURI.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, ImageURI); + } + else + { + jobject ImageURIInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.imageURI.Value(), ImageURIInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(ImageURIInsideOptional, ImageURI); + } + jobject SoftwareVersion; + if (!dataResponse.softwareVersion.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, SoftwareVersion); + } + else + { + jobject SoftwareVersionInsideOptional; + std::string SoftwareVersionInsideOptionalClassName = "java/lang/Long"; + std::string SoftwareVersionInsideOptionalCtorSignature = "(J)V"; + jlong jniSoftwareVersionInsideOptional = static_cast(dataResponse.softwareVersion.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + SoftwareVersionInsideOptionalClassName.c_str(), SoftwareVersionInsideOptionalCtorSignature.c_str(), + jniSoftwareVersionInsideOptional, SoftwareVersionInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(SoftwareVersionInsideOptional, SoftwareVersion); + } + jobject SoftwareVersionString; + if (!dataResponse.softwareVersionString.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, SoftwareVersionString); + } + else + { + jobject SoftwareVersionStringInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.softwareVersionString.Value(), + SoftwareVersionStringInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(SoftwareVersionStringInsideOptional, SoftwareVersionString); + } + jobject UpdateToken; + if (!dataResponse.updateToken.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, UpdateToken); + } + else + { + jobject UpdateTokenInsideOptional; + jbyteArray UpdateTokenInsideOptionalByteArray = + env->NewByteArray(static_cast(dataResponse.updateToken.Value().size())); + env->SetByteArrayRegion(UpdateTokenInsideOptionalByteArray, 0, static_cast(dataResponse.updateToken.Value().size()), + reinterpret_cast(dataResponse.updateToken.Value().data())); + UpdateTokenInsideOptional = UpdateTokenInsideOptionalByteArray; + chip::JniReferences::GetInstance().CreateOptional(UpdateTokenInsideOptional, UpdateToken); + } + jobject UserConsentNeeded; + if (!dataResponse.userConsentNeeded.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, UserConsentNeeded); + } + else + { + jobject UserConsentNeededInsideOptional; + std::string UserConsentNeededInsideOptionalClassName = "java/lang/Boolean"; + std::string UserConsentNeededInsideOptionalCtorSignature = "(Z)V"; + jboolean jniUserConsentNeededInsideOptional = static_cast(dataResponse.userConsentNeeded.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + UserConsentNeededInsideOptionalClassName.c_str(), UserConsentNeededInsideOptionalCtorSignature.c_str(), + jniUserConsentNeededInsideOptional, UserConsentNeededInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(UserConsentNeededInsideOptional, UserConsentNeeded); + } + jobject MetadataForRequestor; + if (!dataResponse.metadataForRequestor.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, MetadataForRequestor); + } + else + { + jobject MetadataForRequestorInsideOptional; + jbyteArray MetadataForRequestorInsideOptionalByteArray = + env->NewByteArray(static_cast(dataResponse.metadataForRequestor.Value().size())); + env->SetByteArrayRegion(MetadataForRequestorInsideOptionalByteArray, 0, + static_cast(dataResponse.metadataForRequestor.Value().size()), + reinterpret_cast(dataResponse.metadataForRequestor.Value().data())); + MetadataForRequestorInsideOptional = MetadataForRequestorInsideOptionalByteArray; + chip::JniReferences::GetInstance().CreateOptional(MetadataForRequestorInsideOptional, MetadataForRequestor); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, DelayedActionTime, ImageURI, SoftwareVersion, SoftwareVersionString, + UpdateToken, UserConsentNeeded, MetadataForRequestor); +} +CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback::CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback::~CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOtaSoftwareUpdateProviderClusterApplyUpdateResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Long;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Action; + std::string ActionClassName = "java/lang/Integer"; + std::string ActionCtorSignature = "(I)V"; + jint jniAction = static_cast(dataResponse.action); + chip::JniReferences::GetInstance().CreateBoxedObject(ActionClassName.c_str(), ActionCtorSignature.c_str(), jniAction, + Action); + jobject DelayedActionTime; + std::string DelayedActionTimeClassName = "java/lang/Long"; + std::string DelayedActionTimeCtorSignature = "(J)V"; + jlong jniDelayedActionTime = static_cast(dataResponse.delayedActionTime); + chip::JniReferences::GetInstance().CreateBoxedObject( + DelayedActionTimeClassName.c_str(), DelayedActionTimeCtorSignature.c_str(), jniDelayedActionTime, DelayedActionTime); + + env->CallVoidMethod(javaCallbackRef, javaMethod, Action, DelayedActionTime); +} +CHIPGeneralCommissioningClusterArmFailSafeResponseCallback::CHIPGeneralCommissioningClusterArmFailSafeResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPGeneralCommissioningClusterArmFailSafeResponseCallback::~CHIPGeneralCommissioningClusterArmFailSafeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGeneralCommissioningClusterArmFailSafeResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::GeneralCommissioning::Commands::ArmFailSafeResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject ErrorCode; + std::string ErrorCodeClassName = "java/lang/Integer"; + std::string ErrorCodeCtorSignature = "(I)V"; + jint jniErrorCode = static_cast(dataResponse.errorCode); + chip::JniReferences::GetInstance().CreateBoxedObject(ErrorCodeClassName.c_str(), ErrorCodeCtorSignature.c_str(), + jniErrorCode, ErrorCode); + jobject DebugText; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.debugText, DebugText)); + + env->CallVoidMethod(javaCallbackRef, javaMethod, ErrorCode, DebugText); +} +CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback:: +CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback::~ +CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGeneralCommissioningClusterSetRegulatoryConfigResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::GeneralCommissioning::Commands::SetRegulatoryConfigResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject ErrorCode; + std::string ErrorCodeClassName = "java/lang/Integer"; + std::string ErrorCodeCtorSignature = "(I)V"; + jint jniErrorCode = static_cast(dataResponse.errorCode); + chip::JniReferences::GetInstance().CreateBoxedObject(ErrorCodeClassName.c_str(), ErrorCodeCtorSignature.c_str(), + jniErrorCode, ErrorCode); + jobject DebugText; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.debugText, DebugText)); + + env->CallVoidMethod(javaCallbackRef, javaMethod, ErrorCode, DebugText); +} +CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback:: +CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback::~ +CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGeneralCommissioningClusterCommissioningCompleteResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::GeneralCommissioning::Commands::CommissioningCompleteResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject ErrorCode; + std::string ErrorCodeClassName = "java/lang/Integer"; + std::string ErrorCodeCtorSignature = "(I)V"; + jint jniErrorCode = static_cast(dataResponse.errorCode); + chip::JniReferences::GetInstance().CreateBoxedObject(ErrorCodeClassName.c_str(), ErrorCodeCtorSignature.c_str(), + jniErrorCode, ErrorCode); + jobject DebugText; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.debugText, DebugText)); + + env->CallVoidMethod(javaCallbackRef, javaMethod, ErrorCode, DebugText); +} +CHIPNetworkCommissioningClusterScanNetworksResponseCallback::CHIPNetworkCommissioningClusterScanNetworksResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPNetworkCommissioningClusterScanNetworksResponseCallback::~CHIPNetworkCommissioningClusterScanNetworksResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterScanNetworksResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::NetworkCommissioning::Commands::ScanNetworksResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject NetworkingStatus; + std::string NetworkingStatusClassName = "java/lang/Integer"; + std::string NetworkingStatusCtorSignature = "(I)V"; + jint jniNetworkingStatus = static_cast(dataResponse.networkingStatus); + chip::JniReferences::GetInstance().CreateBoxedObject( + NetworkingStatusClassName.c_str(), NetworkingStatusCtorSignature.c_str(), jniNetworkingStatus, NetworkingStatus); + jobject DebugText; + if (!dataResponse.debugText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, DebugText); + } + else + { + jobject DebugTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.debugText.Value(), DebugTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(DebugTextInsideOptional, DebugText); + } + jobject WiFiScanResults; + if (!dataResponse.wiFiScanResults.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, WiFiScanResults); + } + else + { + jobject WiFiScanResultsInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(WiFiScanResultsInsideOptional); + + auto iter_WiFiScanResultsInsideOptional_1 = dataResponse.wiFiScanResults.Value().begin(); + while (iter_WiFiScanResultsInsideOptional_1.Next()) + { + auto & entry_1 = iter_WiFiScanResultsInsideOptional_1.GetValue(); + jobject newElement_1; + jobject newElement_1_security; + std::string newElement_1_securityClassName = "java/lang/Integer"; + std::string newElement_1_securityCtorSignature = "(I)V"; + jint jninewElement_1_security = static_cast(entry_1.security.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_1_securityClassName.c_str(), + newElement_1_securityCtorSignature.c_str(), + jninewElement_1_security, newElement_1_security); + jobject newElement_1_ssid; + jbyteArray newElement_1_ssidByteArray = env->NewByteArray(static_cast(entry_1.ssid.size())); + env->SetByteArrayRegion(newElement_1_ssidByteArray, 0, static_cast(entry_1.ssid.size()), + reinterpret_cast(entry_1.ssid.data())); + newElement_1_ssid = newElement_1_ssidByteArray; + jobject newElement_1_bssid; + jbyteArray newElement_1_bssidByteArray = env->NewByteArray(static_cast(entry_1.bssid.size())); + env->SetByteArrayRegion(newElement_1_bssidByteArray, 0, static_cast(entry_1.bssid.size()), + reinterpret_cast(entry_1.bssid.data())); + newElement_1_bssid = newElement_1_bssidByteArray; + jobject newElement_1_channel; + std::string newElement_1_channelClassName = "java/lang/Integer"; + std::string newElement_1_channelCtorSignature = "(I)V"; + jint jninewElement_1_channel = static_cast(entry_1.channel); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_1_channelClassName.c_str(), + newElement_1_channelCtorSignature.c_str(), + jninewElement_1_channel, newElement_1_channel); + jobject newElement_1_wiFiBand; + std::string newElement_1_wiFiBandClassName = "java/lang/Integer"; + std::string newElement_1_wiFiBandCtorSignature = "(I)V"; + jint jninewElement_1_wiFiBand = static_cast(entry_1.wiFiBand); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_1_wiFiBandClassName.c_str(), + newElement_1_wiFiBandCtorSignature.c_str(), + jninewElement_1_wiFiBand, newElement_1_wiFiBand); + jobject newElement_1_rssi; + std::string newElement_1_rssiClassName = "java/lang/Integer"; + std::string newElement_1_rssiCtorSignature = "(I)V"; + jint jninewElement_1_rssi = static_cast(entry_1.rssi); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_1_rssiClassName.c_str(), + newElement_1_rssiCtorSignature.c_str(), jninewElement_1_rssi, + newElement_1_rssi); + + jclass wiFiInterfaceScanResultStructStructClass_2; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct", + wiFiInterfaceScanResultStructStructClass_2); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct"); + return; + } + + jmethodID wiFiInterfaceScanResultStructStructCtor_2; + err = chip::JniReferences::GetInstance().FindMethod( + env, wiFiInterfaceScanResultStructStructClass_2, "", + "(Ljava/lang/Integer;[B[BLjava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", + &wiFiInterfaceScanResultStructStructCtor_2); + if (err != CHIP_NO_ERROR || wiFiInterfaceScanResultStructStructCtor_2 == nullptr) + { + ChipLogError(Zcl, + "Could not find ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct constructor"); + return; + } + + newElement_1 = env->NewObject(wiFiInterfaceScanResultStructStructClass_2, wiFiInterfaceScanResultStructStructCtor_2, + newElement_1_security, newElement_1_ssid, newElement_1_bssid, newElement_1_channel, + newElement_1_wiFiBand, newElement_1_rssi); + chip::JniReferences::GetInstance().AddToList(WiFiScanResultsInsideOptional, newElement_1); + } + chip::JniReferences::GetInstance().CreateOptional(WiFiScanResultsInsideOptional, WiFiScanResults); + } + jobject ThreadScanResults; + if (!dataResponse.threadScanResults.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, ThreadScanResults); + } + else + { + jobject ThreadScanResultsInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(ThreadScanResultsInsideOptional); + + auto iter_ThreadScanResultsInsideOptional_1 = dataResponse.threadScanResults.Value().begin(); + while (iter_ThreadScanResultsInsideOptional_1.Next()) + { + auto & entry_1 = iter_ThreadScanResultsInsideOptional_1.GetValue(); + jobject newElement_1; + jobject newElement_1_panId; + std::string newElement_1_panIdClassName = "java/lang/Integer"; + std::string newElement_1_panIdCtorSignature = "(I)V"; + jint jninewElement_1_panId = static_cast(entry_1.panId); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_1_panIdClassName.c_str(), + newElement_1_panIdCtorSignature.c_str(), + jninewElement_1_panId, newElement_1_panId); + jobject newElement_1_extendedPanId; + std::string newElement_1_extendedPanIdClassName = "java/lang/Long"; + std::string newElement_1_extendedPanIdCtorSignature = "(J)V"; + jlong jninewElement_1_extendedPanId = static_cast(entry_1.extendedPanId); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_1_extendedPanIdClassName.c_str(), + newElement_1_extendedPanIdCtorSignature.c_str(), + jninewElement_1_extendedPanId, newElement_1_extendedPanId); + jobject newElement_1_networkName; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_1.networkName, newElement_1_networkName)); + jobject newElement_1_channel; + std::string newElement_1_channelClassName = "java/lang/Integer"; + std::string newElement_1_channelCtorSignature = "(I)V"; + jint jninewElement_1_channel = static_cast(entry_1.channel); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_1_channelClassName.c_str(), + newElement_1_channelCtorSignature.c_str(), + jninewElement_1_channel, newElement_1_channel); + jobject newElement_1_version; + std::string newElement_1_versionClassName = "java/lang/Integer"; + std::string newElement_1_versionCtorSignature = "(I)V"; + jint jninewElement_1_version = static_cast(entry_1.version); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_1_versionClassName.c_str(), + newElement_1_versionCtorSignature.c_str(), + jninewElement_1_version, newElement_1_version); + jobject newElement_1_extendedAddress; + jbyteArray newElement_1_extendedAddressByteArray = + env->NewByteArray(static_cast(entry_1.extendedAddress.size())); + env->SetByteArrayRegion(newElement_1_extendedAddressByteArray, 0, static_cast(entry_1.extendedAddress.size()), + reinterpret_cast(entry_1.extendedAddress.data())); + newElement_1_extendedAddress = newElement_1_extendedAddressByteArray; + jobject newElement_1_rssi; + std::string newElement_1_rssiClassName = "java/lang/Integer"; + std::string newElement_1_rssiCtorSignature = "(I)V"; + jint jninewElement_1_rssi = static_cast(entry_1.rssi); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_1_rssiClassName.c_str(), + newElement_1_rssiCtorSignature.c_str(), jninewElement_1_rssi, + newElement_1_rssi); + jobject newElement_1_lqi; + std::string newElement_1_lqiClassName = "java/lang/Integer"; + std::string newElement_1_lqiCtorSignature = "(I)V"; + jint jninewElement_1_lqi = static_cast(entry_1.lqi); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_1_lqiClassName.c_str(), newElement_1_lqiCtorSignature.c_str(), jninewElement_1_lqi, newElement_1_lqi); + + jclass threadInterfaceScanResultStructStructClass_2; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct", + threadInterfaceScanResultStructStructClass_2); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct"); + return; + } + + jmethodID threadInterfaceScanResultStructStructCtor_2; + err = chip::JniReferences::GetInstance().FindMethod( + env, threadInterfaceScanResultStructStructClass_2, "", + "(Ljava/lang/Integer;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;[BLjava/lang/" + "Integer;Ljava/lang/Integer;)V", + &threadInterfaceScanResultStructStructCtor_2); + if (err != CHIP_NO_ERROR || threadInterfaceScanResultStructStructCtor_2 == nullptr) + { + ChipLogError(Zcl, + "Could not find ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct constructor"); + return; + } + + newElement_1 = + env->NewObject(threadInterfaceScanResultStructStructClass_2, threadInterfaceScanResultStructStructCtor_2, + newElement_1_panId, newElement_1_extendedPanId, newElement_1_networkName, newElement_1_channel, + newElement_1_version, newElement_1_extendedAddress, newElement_1_rssi, newElement_1_lqi); + chip::JniReferences::GetInstance().AddToList(ThreadScanResultsInsideOptional, newElement_1); + } + chip::JniReferences::GetInstance().CreateOptional(ThreadScanResultsInsideOptional, ThreadScanResults); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, NetworkingStatus, DebugText, WiFiScanResults, ThreadScanResults); +} +CHIPNetworkCommissioningClusterNetworkConfigResponseCallback::CHIPNetworkCommissioningClusterNetworkConfigResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPNetworkCommissioningClusterNetworkConfigResponseCallback::~CHIPNetworkCommissioningClusterNetworkConfigResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterNetworkConfigResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::NetworkCommissioning::Commands::NetworkConfigResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject NetworkingStatus; + std::string NetworkingStatusClassName = "java/lang/Integer"; + std::string NetworkingStatusCtorSignature = "(I)V"; + jint jniNetworkingStatus = static_cast(dataResponse.networkingStatus); + chip::JniReferences::GetInstance().CreateBoxedObject( + NetworkingStatusClassName.c_str(), NetworkingStatusCtorSignature.c_str(), jniNetworkingStatus, NetworkingStatus); + jobject DebugText; + if (!dataResponse.debugText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, DebugText); + } + else + { + jobject DebugTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.debugText.Value(), DebugTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(DebugTextInsideOptional, DebugText); + } + jobject NetworkIndex; + if (!dataResponse.networkIndex.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NetworkIndex); + } + else + { + jobject NetworkIndexInsideOptional; + std::string NetworkIndexInsideOptionalClassName = "java/lang/Integer"; + std::string NetworkIndexInsideOptionalCtorSignature = "(I)V"; + jint jniNetworkIndexInsideOptional = static_cast(dataResponse.networkIndex.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(NetworkIndexInsideOptionalClassName.c_str(), + NetworkIndexInsideOptionalCtorSignature.c_str(), + jniNetworkIndexInsideOptional, NetworkIndexInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(NetworkIndexInsideOptional, NetworkIndex); + } + jobject ClientIdentity; + if (!dataResponse.clientIdentity.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, ClientIdentity); + } + else + { + jobject ClientIdentityInsideOptional; + jbyteArray ClientIdentityInsideOptionalByteArray = + env->NewByteArray(static_cast(dataResponse.clientIdentity.Value().size())); + env->SetByteArrayRegion(ClientIdentityInsideOptionalByteArray, 0, + static_cast(dataResponse.clientIdentity.Value().size()), + reinterpret_cast(dataResponse.clientIdentity.Value().data())); + ClientIdentityInsideOptional = ClientIdentityInsideOptionalByteArray; + chip::JniReferences::GetInstance().CreateOptional(ClientIdentityInsideOptional, ClientIdentity); + } + jobject PossessionSignature; + if (!dataResponse.possessionSignature.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, PossessionSignature); + } + else + { + jobject PossessionSignatureInsideOptional; + jbyteArray PossessionSignatureInsideOptionalByteArray = + env->NewByteArray(static_cast(dataResponse.possessionSignature.Value().size())); + env->SetByteArrayRegion(PossessionSignatureInsideOptionalByteArray, 0, + static_cast(dataResponse.possessionSignature.Value().size()), + reinterpret_cast(dataResponse.possessionSignature.Value().data())); + PossessionSignatureInsideOptional = PossessionSignatureInsideOptionalByteArray; + chip::JniReferences::GetInstance().CreateOptional(PossessionSignatureInsideOptional, PossessionSignature); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, NetworkingStatus, DebugText, NetworkIndex, ClientIdentity, + PossessionSignature); +} +CHIPNetworkCommissioningClusterConnectNetworkResponseCallback::CHIPNetworkCommissioningClusterConnectNetworkResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPNetworkCommissioningClusterConnectNetworkResponseCallback::~CHIPNetworkCommissioningClusterConnectNetworkResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterConnectNetworkResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::NetworkCommissioning::Commands::ConnectNetworkResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/lang/Long;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject NetworkingStatus; + std::string NetworkingStatusClassName = "java/lang/Integer"; + std::string NetworkingStatusCtorSignature = "(I)V"; + jint jniNetworkingStatus = static_cast(dataResponse.networkingStatus); + chip::JniReferences::GetInstance().CreateBoxedObject( + NetworkingStatusClassName.c_str(), NetworkingStatusCtorSignature.c_str(), jniNetworkingStatus, NetworkingStatus); + jobject DebugText; + if (!dataResponse.debugText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, DebugText); + } + else + { + jobject DebugTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.debugText.Value(), DebugTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(DebugTextInsideOptional, DebugText); + } + jobject ErrorValue; + if (dataResponse.errorValue.IsNull()) + { + ErrorValue = nullptr; + } + else + { + std::string ErrorValueClassName = "java/lang/Long"; + std::string ErrorValueCtorSignature = "(J)V"; + jlong jniErrorValue = static_cast(dataResponse.errorValue.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(ErrorValueClassName.c_str(), ErrorValueCtorSignature.c_str(), + jniErrorValue, ErrorValue); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, NetworkingStatus, DebugText, ErrorValue); +} +CHIPNetworkCommissioningClusterQueryIdentityResponseCallback::CHIPNetworkCommissioningClusterQueryIdentityResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPNetworkCommissioningClusterQueryIdentityResponseCallback::~CHIPNetworkCommissioningClusterQueryIdentityResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPNetworkCommissioningClusterQueryIdentityResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::NetworkCommissioning::Commands::QueryIdentityResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([BLjava/util/Optional;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Identity; + jbyteArray IdentityByteArray = env->NewByteArray(static_cast(dataResponse.identity.size())); + env->SetByteArrayRegion(IdentityByteArray, 0, static_cast(dataResponse.identity.size()), + reinterpret_cast(dataResponse.identity.data())); + Identity = IdentityByteArray; + jobject PossessionSignature; + if (!dataResponse.possessionSignature.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, PossessionSignature); + } + else + { + jobject PossessionSignatureInsideOptional; + jbyteArray PossessionSignatureInsideOptionalByteArray = + env->NewByteArray(static_cast(dataResponse.possessionSignature.Value().size())); + env->SetByteArrayRegion(PossessionSignatureInsideOptionalByteArray, 0, + static_cast(dataResponse.possessionSignature.Value().size()), + reinterpret_cast(dataResponse.possessionSignature.Value().data())); + PossessionSignatureInsideOptional = PossessionSignatureInsideOptionalByteArray; + chip::JniReferences::GetInstance().CreateOptional(PossessionSignatureInsideOptional, PossessionSignature); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Identity, PossessionSignature); +} +CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback::CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback::~CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDiagnosticLogsClusterRetrieveLogsResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DiagnosticLogs::Commands::RetrieveLogsResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;[BLjava/util/Optional;Ljava/util/Optional;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject LogContent; + jbyteArray LogContentByteArray = env->NewByteArray(static_cast(dataResponse.logContent.size())); + env->SetByteArrayRegion(LogContentByteArray, 0, static_cast(dataResponse.logContent.size()), + reinterpret_cast(dataResponse.logContent.data())); + LogContent = LogContentByteArray; + jobject UTCTimeStamp; + if (!dataResponse.UTCTimeStamp.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, UTCTimeStamp); + } + else + { + jobject UTCTimeStampInsideOptional; + std::string UTCTimeStampInsideOptionalClassName = "java/lang/Long"; + std::string UTCTimeStampInsideOptionalCtorSignature = "(J)V"; + jlong jniUTCTimeStampInsideOptional = static_cast(dataResponse.UTCTimeStamp.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(UTCTimeStampInsideOptionalClassName.c_str(), + UTCTimeStampInsideOptionalCtorSignature.c_str(), + jniUTCTimeStampInsideOptional, UTCTimeStampInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(UTCTimeStampInsideOptional, UTCTimeStamp); + } + jobject TimeSinceBoot; + if (!dataResponse.timeSinceBoot.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, TimeSinceBoot); + } + else + { + jobject TimeSinceBootInsideOptional; + std::string TimeSinceBootInsideOptionalClassName = "java/lang/Long"; + std::string TimeSinceBootInsideOptionalCtorSignature = "(J)V"; + jlong jniTimeSinceBootInsideOptional = static_cast(dataResponse.timeSinceBoot.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(TimeSinceBootInsideOptionalClassName.c_str(), + TimeSinceBootInsideOptionalCtorSignature.c_str(), + jniTimeSinceBootInsideOptional, TimeSinceBootInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(TimeSinceBootInsideOptional, TimeSinceBoot); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, LogContent, UTCTimeStamp, TimeSinceBoot); +} +CHIPGeneralDiagnosticsClusterTimeSnapshotResponseCallback::CHIPGeneralDiagnosticsClusterTimeSnapshotResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPGeneralDiagnosticsClusterTimeSnapshotResponseCallback::~CHIPGeneralDiagnosticsClusterTimeSnapshotResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGeneralDiagnosticsClusterTimeSnapshotResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::GeneralDiagnostics::Commands::TimeSnapshotResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Long;Ljava/lang/Long;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject SystemTimeMs; + std::string SystemTimeMsClassName = "java/lang/Long"; + std::string SystemTimeMsCtorSignature = "(J)V"; + jlong jniSystemTimeMs = static_cast(dataResponse.systemTimeMs); + chip::JniReferences::GetInstance().CreateBoxedObject(SystemTimeMsClassName.c_str(), SystemTimeMsCtorSignature.c_str(), + jniSystemTimeMs, SystemTimeMs); + jobject PosixTimeMs; + if (dataResponse.posixTimeMs.IsNull()) + { + PosixTimeMs = nullptr; + } + else + { + std::string PosixTimeMsClassName = "java/lang/Long"; + std::string PosixTimeMsCtorSignature = "(J)V"; + jlong jniPosixTimeMs = static_cast(dataResponse.posixTimeMs.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(PosixTimeMsClassName.c_str(), PosixTimeMsCtorSignature.c_str(), + jniPosixTimeMs, PosixTimeMs); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, SystemTimeMs, PosixTimeMs); +} +CHIPTimeSynchronizationClusterSetTimeZoneResponseCallback::CHIPTimeSynchronizationClusterSetTimeZoneResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPTimeSynchronizationClusterSetTimeZoneResponseCallback::~CHIPTimeSynchronizationClusterSetTimeZoneResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPTimeSynchronizationClusterSetTimeZoneResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::TimeSynchronization::Commands::SetTimeZoneResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Boolean;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject DSTOffsetRequired; + std::string DSTOffsetRequiredClassName = "java/lang/Boolean"; + std::string DSTOffsetRequiredCtorSignature = "(Z)V"; + jboolean jniDSTOffsetRequired = static_cast(dataResponse.DSTOffsetRequired); + chip::JniReferences::GetInstance().CreateBoxedObject( + DSTOffsetRequiredClassName.c_str(), DSTOffsetRequiredCtorSignature.c_str(), jniDSTOffsetRequired, DSTOffsetRequired); + + env->CallVoidMethod(javaCallbackRef, javaMethod, DSTOffsetRequired); +} +CHIPOperationalCredentialsClusterAttestationResponseCallback::CHIPOperationalCredentialsClusterAttestationResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPOperationalCredentialsClusterAttestationResponseCallback::~CHIPOperationalCredentialsClusterAttestationResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOperationalCredentialsClusterAttestationResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::OperationalCredentials::Commands::AttestationResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([B[B)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject AttestationElements; + jbyteArray AttestationElementsByteArray = env->NewByteArray(static_cast(dataResponse.attestationElements.size())); + env->SetByteArrayRegion(AttestationElementsByteArray, 0, static_cast(dataResponse.attestationElements.size()), + reinterpret_cast(dataResponse.attestationElements.data())); + AttestationElements = AttestationElementsByteArray; + jobject AttestationSignature; + jbyteArray AttestationSignatureByteArray = env->NewByteArray(static_cast(dataResponse.attestationSignature.size())); + env->SetByteArrayRegion(AttestationSignatureByteArray, 0, static_cast(dataResponse.attestationSignature.size()), + reinterpret_cast(dataResponse.attestationSignature.data())); + AttestationSignature = AttestationSignatureByteArray; + + env->CallVoidMethod(javaCallbackRef, javaMethod, AttestationElements, AttestationSignature); +} +CHIPOperationalCredentialsClusterCertificateChainResponseCallback:: +CHIPOperationalCredentialsClusterCertificateChainResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPOperationalCredentialsClusterCertificateChainResponseCallback::~ +CHIPOperationalCredentialsClusterCertificateChainResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOperationalCredentialsClusterCertificateChainResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::OperationalCredentials::Commands::CertificateChainResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([B)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Certificate; + jbyteArray CertificateByteArray = env->NewByteArray(static_cast(dataResponse.certificate.size())); + env->SetByteArrayRegion(CertificateByteArray, 0, static_cast(dataResponse.certificate.size()), + reinterpret_cast(dataResponse.certificate.data())); + Certificate = CertificateByteArray; + + env->CallVoidMethod(javaCallbackRef, javaMethod, Certificate); +} +CHIPOperationalCredentialsClusterCSRResponseCallback::CHIPOperationalCredentialsClusterCSRResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPOperationalCredentialsClusterCSRResponseCallback::~CHIPOperationalCredentialsClusterCSRResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOperationalCredentialsClusterCSRResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::OperationalCredentials::Commands::CSRResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([B[B)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject NOCSRElements; + jbyteArray NOCSRElementsByteArray = env->NewByteArray(static_cast(dataResponse.NOCSRElements.size())); + env->SetByteArrayRegion(NOCSRElementsByteArray, 0, static_cast(dataResponse.NOCSRElements.size()), + reinterpret_cast(dataResponse.NOCSRElements.data())); + NOCSRElements = NOCSRElementsByteArray; + jobject AttestationSignature; + jbyteArray AttestationSignatureByteArray = env->NewByteArray(static_cast(dataResponse.attestationSignature.size())); + env->SetByteArrayRegion(AttestationSignatureByteArray, 0, static_cast(dataResponse.attestationSignature.size()), + reinterpret_cast(dataResponse.attestationSignature.data())); + AttestationSignature = AttestationSignatureByteArray; + + env->CallVoidMethod(javaCallbackRef, javaMethod, NOCSRElements, AttestationSignature); +} +CHIPOperationalCredentialsClusterNOCResponseCallback::CHIPOperationalCredentialsClusterNOCResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPOperationalCredentialsClusterNOCResponseCallback::~CHIPOperationalCredentialsClusterNOCResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOperationalCredentialsClusterNOCResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::OperationalCredentials::Commands::NOCResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject StatusCode; + std::string StatusCodeClassName = "java/lang/Integer"; + std::string StatusCodeCtorSignature = "(I)V"; + jint jniStatusCode = static_cast(dataResponse.statusCode); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusCodeClassName.c_str(), StatusCodeCtorSignature.c_str(), + jniStatusCode, StatusCode); + jobject FabricIndex; + if (!dataResponse.fabricIndex.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, FabricIndex); + } + else + { + jobject FabricIndexInsideOptional; + std::string FabricIndexInsideOptionalClassName = "java/lang/Integer"; + std::string FabricIndexInsideOptionalCtorSignature = "(I)V"; + jint jniFabricIndexInsideOptional = static_cast(dataResponse.fabricIndex.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(FabricIndexInsideOptionalClassName.c_str(), + FabricIndexInsideOptionalCtorSignature.c_str(), + jniFabricIndexInsideOptional, FabricIndexInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(FabricIndexInsideOptional, FabricIndex); + } + jobject DebugText; + if (!dataResponse.debugText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, DebugText); + } + else + { + jobject DebugTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.debugText.Value(), DebugTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(DebugTextInsideOptional, DebugText); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, StatusCode, FabricIndex, DebugText); +} +CHIPGroupKeyManagementClusterKeySetReadResponseCallback::CHIPGroupKeyManagementClusterKeySetReadResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPGroupKeyManagementClusterKeySetReadResponseCallback::~CHIPGroupKeyManagementClusterKeySetReadResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGroupKeyManagementClusterKeySetReadResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::GroupKeyManagement::Commands::KeySetReadResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", "(Lchip/devicecontroller/ChipStructs$GroupKeyManagementClusterGroupKeySetStruct;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject GroupKeySet; + jobject GroupKeySet_groupKeySetID; + std::string GroupKeySet_groupKeySetIDClassName = "java/lang/Integer"; + std::string GroupKeySet_groupKeySetIDCtorSignature = "(I)V"; + jint jniGroupKeySet_groupKeySetID = static_cast(dataResponse.groupKeySet.groupKeySetID); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupKeySet_groupKeySetIDClassName.c_str(), + GroupKeySet_groupKeySetIDCtorSignature.c_str(), + jniGroupKeySet_groupKeySetID, GroupKeySet_groupKeySetID); + jobject GroupKeySet_groupKeySecurityPolicy; + std::string GroupKeySet_groupKeySecurityPolicyClassName = "java/lang/Integer"; + std::string GroupKeySet_groupKeySecurityPolicyCtorSignature = "(I)V"; + jint jniGroupKeySet_groupKeySecurityPolicy = static_cast(dataResponse.groupKeySet.groupKeySecurityPolicy); + chip::JniReferences::GetInstance().CreateBoxedObject( + GroupKeySet_groupKeySecurityPolicyClassName.c_str(), GroupKeySet_groupKeySecurityPolicyCtorSignature.c_str(), + jniGroupKeySet_groupKeySecurityPolicy, GroupKeySet_groupKeySecurityPolicy); + jobject GroupKeySet_epochKey0; + if (dataResponse.groupKeySet.epochKey0.IsNull()) + { + GroupKeySet_epochKey0 = nullptr; + } + else + { + jbyteArray GroupKeySet_epochKey0ByteArray = + env->NewByteArray(static_cast(dataResponse.groupKeySet.epochKey0.Value().size())); + env->SetByteArrayRegion(GroupKeySet_epochKey0ByteArray, 0, + static_cast(dataResponse.groupKeySet.epochKey0.Value().size()), + reinterpret_cast(dataResponse.groupKeySet.epochKey0.Value().data())); + GroupKeySet_epochKey0 = GroupKeySet_epochKey0ByteArray; + } + jobject GroupKeySet_epochStartTime0; + if (dataResponse.groupKeySet.epochStartTime0.IsNull()) + { + GroupKeySet_epochStartTime0 = nullptr; + } + else + { + std::string GroupKeySet_epochStartTime0ClassName = "java/lang/Long"; + std::string GroupKeySet_epochStartTime0CtorSignature = "(J)V"; + jlong jniGroupKeySet_epochStartTime0 = static_cast(dataResponse.groupKeySet.epochStartTime0.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupKeySet_epochStartTime0ClassName.c_str(), + GroupKeySet_epochStartTime0CtorSignature.c_str(), + jniGroupKeySet_epochStartTime0, GroupKeySet_epochStartTime0); + } + jobject GroupKeySet_epochKey1; + if (dataResponse.groupKeySet.epochKey1.IsNull()) + { + GroupKeySet_epochKey1 = nullptr; + } + else + { + jbyteArray GroupKeySet_epochKey1ByteArray = + env->NewByteArray(static_cast(dataResponse.groupKeySet.epochKey1.Value().size())); + env->SetByteArrayRegion(GroupKeySet_epochKey1ByteArray, 0, + static_cast(dataResponse.groupKeySet.epochKey1.Value().size()), + reinterpret_cast(dataResponse.groupKeySet.epochKey1.Value().data())); + GroupKeySet_epochKey1 = GroupKeySet_epochKey1ByteArray; + } + jobject GroupKeySet_epochStartTime1; + if (dataResponse.groupKeySet.epochStartTime1.IsNull()) + { + GroupKeySet_epochStartTime1 = nullptr; + } + else + { + std::string GroupKeySet_epochStartTime1ClassName = "java/lang/Long"; + std::string GroupKeySet_epochStartTime1CtorSignature = "(J)V"; + jlong jniGroupKeySet_epochStartTime1 = static_cast(dataResponse.groupKeySet.epochStartTime1.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupKeySet_epochStartTime1ClassName.c_str(), + GroupKeySet_epochStartTime1CtorSignature.c_str(), + jniGroupKeySet_epochStartTime1, GroupKeySet_epochStartTime1); + } + jobject GroupKeySet_epochKey2; + if (dataResponse.groupKeySet.epochKey2.IsNull()) + { + GroupKeySet_epochKey2 = nullptr; + } + else + { + jbyteArray GroupKeySet_epochKey2ByteArray = + env->NewByteArray(static_cast(dataResponse.groupKeySet.epochKey2.Value().size())); + env->SetByteArrayRegion(GroupKeySet_epochKey2ByteArray, 0, + static_cast(dataResponse.groupKeySet.epochKey2.Value().size()), + reinterpret_cast(dataResponse.groupKeySet.epochKey2.Value().data())); + GroupKeySet_epochKey2 = GroupKeySet_epochKey2ByteArray; + } + jobject GroupKeySet_epochStartTime2; + if (dataResponse.groupKeySet.epochStartTime2.IsNull()) + { + GroupKeySet_epochStartTime2 = nullptr; + } + else + { + std::string GroupKeySet_epochStartTime2ClassName = "java/lang/Long"; + std::string GroupKeySet_epochStartTime2CtorSignature = "(J)V"; + jlong jniGroupKeySet_epochStartTime2 = static_cast(dataResponse.groupKeySet.epochStartTime2.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupKeySet_epochStartTime2ClassName.c_str(), + GroupKeySet_epochStartTime2CtorSignature.c_str(), + jniGroupKeySet_epochStartTime2, GroupKeySet_epochStartTime2); + } + + jclass groupKeySetStructStructClass_0; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$GroupKeyManagementClusterGroupKeySetStruct", groupKeySetStructStructClass_0); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$GroupKeyManagementClusterGroupKeySetStruct"); + return; + } + + jmethodID groupKeySetStructStructCtor_0; + err = chip::JniReferences::GetInstance().FindMethod( + env, groupKeySetStructStructClass_0, "", + "(Ljava/lang/Integer;Ljava/lang/Integer;[BLjava/lang/Long;[BLjava/lang/Long;[BLjava/lang/Long;)V", + &groupKeySetStructStructCtor_0); + if (err != CHIP_NO_ERROR || groupKeySetStructStructCtor_0 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$GroupKeyManagementClusterGroupKeySetStruct constructor"); + return; + } + + GroupKeySet = + env->NewObject(groupKeySetStructStructClass_0, groupKeySetStructStructCtor_0, GroupKeySet_groupKeySetID, + GroupKeySet_groupKeySecurityPolicy, GroupKeySet_epochKey0, GroupKeySet_epochStartTime0, + GroupKeySet_epochKey1, GroupKeySet_epochStartTime1, GroupKeySet_epochKey2, GroupKeySet_epochStartTime2); + + env->CallVoidMethod(javaCallbackRef, javaMethod, GroupKeySet); +} +CHIPGroupKeyManagementClusterKeySetReadAllIndicesResponseCallback:: +CHIPGroupKeyManagementClusterKeySetReadAllIndicesResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPGroupKeyManagementClusterKeySetReadAllIndicesResponseCallback::~ +CHIPGroupKeyManagementClusterKeySetReadAllIndicesResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPGroupKeyManagementClusterKeySetReadAllIndicesResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::GroupKeyManagement::Commands::KeySetReadAllIndicesResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/util/ArrayList;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject GroupKeySetIDs; + chip::JniReferences::GetInstance().CreateArrayList(GroupKeySetIDs); + + auto iter_GroupKeySetIDs_0 = dataResponse.groupKeySetIDs.begin(); + while (iter_GroupKeySetIDs_0.Next()) + { + auto & entry_0 = iter_GroupKeySetIDs_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + jint jninewElement_0 = static_cast(entry_0); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), + jninewElement_0, newElement_0); + chip::JniReferences::GetInstance().AddToList(GroupKeySetIDs, newElement_0); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, GroupKeySetIDs); +} +CHIPIcdManagementClusterRegisterClientResponseCallback::CHIPIcdManagementClusterRegisterClientResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPIcdManagementClusterRegisterClientResponseCallback::~CHIPIcdManagementClusterRegisterClientResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPIcdManagementClusterRegisterClientResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::IcdManagement::Commands::RegisterClientResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Long;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject ICDCounter; + std::string ICDCounterClassName = "java/lang/Long"; + std::string ICDCounterCtorSignature = "(J)V"; + jlong jniICDCounter = static_cast(dataResponse.ICDCounter); + chip::JniReferences::GetInstance().CreateBoxedObject(ICDCounterClassName.c_str(), ICDCounterCtorSignature.c_str(), + jniICDCounter, ICDCounter); + + env->CallVoidMethod(javaCallbackRef, javaMethod, ICDCounter); +} +CHIPIcdManagementClusterStayActiveResponseCallback::CHIPIcdManagementClusterStayActiveResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPIcdManagementClusterStayActiveResponseCallback::~CHIPIcdManagementClusterStayActiveResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPIcdManagementClusterStayActiveResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::IcdManagement::Commands::StayActiveResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Long;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject PromisedActiveDuration; + std::string PromisedActiveDurationClassName = "java/lang/Long"; + std::string PromisedActiveDurationCtorSignature = "(J)V"; + jlong jniPromisedActiveDuration = static_cast(dataResponse.promisedActiveDuration); + chip::JniReferences::GetInstance().CreateBoxedObject(PromisedActiveDurationClassName.c_str(), + PromisedActiveDurationCtorSignature.c_str(), + jniPromisedActiveDuration, PromisedActiveDuration); + + env->CallVoidMethod(javaCallbackRef, javaMethod, PromisedActiveDuration); +} +CHIPOvenCavityOperationalStateClusterOperationalCommandResponseCallback:: +CHIPOvenCavityOperationalStateClusterOperationalCommandResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPOvenCavityOperationalStateClusterOperationalCommandResponseCallback::~ +CHIPOvenCavityOperationalStateClusterOperationalCommandResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOvenCavityOperationalStateClusterOperationalCommandResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::OvenCavityOperationalState::Commands::OperationalCommandResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Lchip/devicecontroller/ChipStructs$OvenCavityOperationalStateClusterErrorStateStruct;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject CommandResponseState; + jobject CommandResponseState_errorStateID; + std::string CommandResponseState_errorStateIDClassName = "java/lang/Integer"; + std::string CommandResponseState_errorStateIDCtorSignature = "(I)V"; + jint jniCommandResponseState_errorStateID = static_cast(dataResponse.commandResponseState.errorStateID); + chip::JniReferences::GetInstance().CreateBoxedObject( + CommandResponseState_errorStateIDClassName.c_str(), CommandResponseState_errorStateIDCtorSignature.c_str(), + jniCommandResponseState_errorStateID, CommandResponseState_errorStateID); + jobject CommandResponseState_errorStateLabel; + if (!dataResponse.commandResponseState.errorStateLabel.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, CommandResponseState_errorStateLabel); + } + else + { + jobject CommandResponseState_errorStateLabelInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF( + dataResponse.commandResponseState.errorStateLabel.Value(), CommandResponseState_errorStateLabelInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(CommandResponseState_errorStateLabelInsideOptional, + CommandResponseState_errorStateLabel); + } + jobject CommandResponseState_errorStateDetails; + if (!dataResponse.commandResponseState.errorStateDetails.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, CommandResponseState_errorStateDetails); + } + else + { + jobject CommandResponseState_errorStateDetailsInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF( + dataResponse.commandResponseState.errorStateDetails.Value(), CommandResponseState_errorStateDetailsInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(CommandResponseState_errorStateDetailsInsideOptional, + CommandResponseState_errorStateDetails); + } + + jclass errorStateStructStructClass_0; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$OvenCavityOperationalStateClusterErrorStateStruct", errorStateStructStructClass_0); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$OvenCavityOperationalStateClusterErrorStateStruct"); + return; + } + + jmethodID errorStateStructStructCtor_0; + err = chip::JniReferences::GetInstance().FindMethod(env, errorStateStructStructClass_0, "", + "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;)V", + &errorStateStructStructCtor_0); + if (err != CHIP_NO_ERROR || errorStateStructStructCtor_0 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$OvenCavityOperationalStateClusterErrorStateStruct constructor"); + return; + } + + CommandResponseState = + env->NewObject(errorStateStructStructClass_0, errorStateStructStructCtor_0, CommandResponseState_errorStateID, + CommandResponseState_errorStateLabel, CommandResponseState_errorStateDetails); + + env->CallVoidMethod(javaCallbackRef, javaMethod, CommandResponseState); +} +CHIPOvenModeClusterChangeToModeResponseCallback::CHIPOvenModeClusterChangeToModeResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPOvenModeClusterChangeToModeResponseCallback::~CHIPOvenModeClusterChangeToModeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOvenModeClusterChangeToModeResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::OvenMode::Commands::ChangeToModeResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject StatusText; + if (!dataResponse.statusText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, StatusText); + } + else + { + jobject StatusTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.statusText.Value(), StatusTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(StatusTextInsideOptional, StatusText); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, StatusText); +} +CHIPLaundryWasherModeClusterChangeToModeResponseCallback::CHIPLaundryWasherModeClusterChangeToModeResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPLaundryWasherModeClusterChangeToModeResponseCallback::~CHIPLaundryWasherModeClusterChangeToModeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPLaundryWasherModeClusterChangeToModeResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::LaundryWasherMode::Commands::ChangeToModeResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject StatusText; + if (!dataResponse.statusText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, StatusText); + } + else + { + jobject StatusTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.statusText.Value(), StatusTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(StatusTextInsideOptional, StatusText); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, StatusText); +} +CHIPRefrigeratorAndTemperatureControlledCabinetModeClusterChangeToModeResponseCallback:: +CHIPRefrigeratorAndTemperatureControlledCabinetModeClusterChangeToModeResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPRefrigeratorAndTemperatureControlledCabinetModeClusterChangeToModeResponseCallback::~ +CHIPRefrigeratorAndTemperatureControlledCabinetModeClusterChangeToModeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPRefrigeratorAndTemperatureControlledCabinetModeClusterChangeToModeResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::RefrigeratorAndTemperatureControlledCabinetMode::Commands::ChangeToModeResponse::DecodableType & + dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject StatusText; + if (!dataResponse.statusText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, StatusText); + } + else + { + jobject StatusTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.statusText.Value(), StatusTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(StatusTextInsideOptional, StatusText); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, StatusText); +} +CHIPRvcRunModeClusterChangeToModeResponseCallback::CHIPRvcRunModeClusterChangeToModeResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPRvcRunModeClusterChangeToModeResponseCallback::~CHIPRvcRunModeClusterChangeToModeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPRvcRunModeClusterChangeToModeResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::RvcRunMode::Commands::ChangeToModeResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject StatusText; + if (!dataResponse.statusText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, StatusText); + } + else + { + jobject StatusTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.statusText.Value(), StatusTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(StatusTextInsideOptional, StatusText); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, StatusText); +} +CHIPRvcCleanModeClusterChangeToModeResponseCallback::CHIPRvcCleanModeClusterChangeToModeResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPRvcCleanModeClusterChangeToModeResponseCallback::~CHIPRvcCleanModeClusterChangeToModeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPRvcCleanModeClusterChangeToModeResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::RvcCleanMode::Commands::ChangeToModeResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject StatusText; + if (!dataResponse.statusText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, StatusText); + } + else + { + jobject StatusTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.statusText.Value(), StatusTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(StatusTextInsideOptional, StatusText); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, StatusText); +} +CHIPDishwasherModeClusterChangeToModeResponseCallback::CHIPDishwasherModeClusterChangeToModeResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPDishwasherModeClusterChangeToModeResponseCallback::~CHIPDishwasherModeClusterChangeToModeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDishwasherModeClusterChangeToModeResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DishwasherMode::Commands::ChangeToModeResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject StatusText; + if (!dataResponse.statusText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, StatusText); + } + else + { + jobject StatusTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.statusText.Value(), StatusTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(StatusTextInsideOptional, StatusText); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, StatusText); +} +CHIPOperationalStateClusterOperationalCommandResponseCallback::CHIPOperationalStateClusterOperationalCommandResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPOperationalStateClusterOperationalCommandResponseCallback::~CHIPOperationalStateClusterOperationalCommandResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPOperationalStateClusterOperationalCommandResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::OperationalState::Commands::OperationalCommandResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Lchip/devicecontroller/ChipStructs$OperationalStateClusterErrorStateStruct;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject CommandResponseState; + jobject CommandResponseState_errorStateID; + std::string CommandResponseState_errorStateIDClassName = "java/lang/Integer"; + std::string CommandResponseState_errorStateIDCtorSignature = "(I)V"; + jint jniCommandResponseState_errorStateID = static_cast(dataResponse.commandResponseState.errorStateID); + chip::JniReferences::GetInstance().CreateBoxedObject( + CommandResponseState_errorStateIDClassName.c_str(), CommandResponseState_errorStateIDCtorSignature.c_str(), + jniCommandResponseState_errorStateID, CommandResponseState_errorStateID); + jobject CommandResponseState_errorStateLabel; + if (!dataResponse.commandResponseState.errorStateLabel.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, CommandResponseState_errorStateLabel); + } + else + { + jobject CommandResponseState_errorStateLabelInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF( + dataResponse.commandResponseState.errorStateLabel.Value(), CommandResponseState_errorStateLabelInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(CommandResponseState_errorStateLabelInsideOptional, + CommandResponseState_errorStateLabel); + } + jobject CommandResponseState_errorStateDetails; + if (!dataResponse.commandResponseState.errorStateDetails.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, CommandResponseState_errorStateDetails); + } + else + { + jobject CommandResponseState_errorStateDetailsInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF( + dataResponse.commandResponseState.errorStateDetails.Value(), CommandResponseState_errorStateDetailsInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(CommandResponseState_errorStateDetailsInsideOptional, + CommandResponseState_errorStateDetails); + } + + jclass errorStateStructStructClass_0; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$OperationalStateClusterErrorStateStruct", errorStateStructStructClass_0); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$OperationalStateClusterErrorStateStruct"); + return; + } + + jmethodID errorStateStructStructCtor_0; + err = chip::JniReferences::GetInstance().FindMethod(env, errorStateStructStructClass_0, "", + "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;)V", + &errorStateStructStructCtor_0); + if (err != CHIP_NO_ERROR || errorStateStructStructCtor_0 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$OperationalStateClusterErrorStateStruct constructor"); + return; + } + + CommandResponseState = + env->NewObject(errorStateStructStructClass_0, errorStateStructStructCtor_0, CommandResponseState_errorStateID, + CommandResponseState_errorStateLabel, CommandResponseState_errorStateDetails); + + env->CallVoidMethod(javaCallbackRef, javaMethod, CommandResponseState); +} +CHIPRvcOperationalStateClusterOperationalCommandResponseCallback::CHIPRvcOperationalStateClusterOperationalCommandResponseCallback( + jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPRvcOperationalStateClusterOperationalCommandResponseCallback::~ +CHIPRvcOperationalStateClusterOperationalCommandResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPRvcOperationalStateClusterOperationalCommandResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::RvcOperationalState::Commands::OperationalCommandResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", "(Lchip/devicecontroller/ChipStructs$RvcOperationalStateClusterErrorStateStruct;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject CommandResponseState; + jobject CommandResponseState_errorStateID; + std::string CommandResponseState_errorStateIDClassName = "java/lang/Integer"; + std::string CommandResponseState_errorStateIDCtorSignature = "(I)V"; + jint jniCommandResponseState_errorStateID = static_cast(dataResponse.commandResponseState.errorStateID); + chip::JniReferences::GetInstance().CreateBoxedObject( + CommandResponseState_errorStateIDClassName.c_str(), CommandResponseState_errorStateIDCtorSignature.c_str(), + jniCommandResponseState_errorStateID, CommandResponseState_errorStateID); + jobject CommandResponseState_errorStateLabel; + if (!dataResponse.commandResponseState.errorStateLabel.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, CommandResponseState_errorStateLabel); + } + else + { + jobject CommandResponseState_errorStateLabelInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF( + dataResponse.commandResponseState.errorStateLabel.Value(), CommandResponseState_errorStateLabelInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(CommandResponseState_errorStateLabelInsideOptional, + CommandResponseState_errorStateLabel); + } + jobject CommandResponseState_errorStateDetails; + if (!dataResponse.commandResponseState.errorStateDetails.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, CommandResponseState_errorStateDetails); + } + else + { + jobject CommandResponseState_errorStateDetailsInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF( + dataResponse.commandResponseState.errorStateDetails.Value(), CommandResponseState_errorStateDetailsInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(CommandResponseState_errorStateDetailsInsideOptional, + CommandResponseState_errorStateDetails); + } + + jclass errorStateStructStructClass_0; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$RvcOperationalStateClusterErrorStateStruct", errorStateStructStructClass_0); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$RvcOperationalStateClusterErrorStateStruct"); + return; + } + + jmethodID errorStateStructStructCtor_0; + err = chip::JniReferences::GetInstance().FindMethod(env, errorStateStructStructClass_0, "", + "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;)V", + &errorStateStructStructCtor_0); + if (err != CHIP_NO_ERROR || errorStateStructStructCtor_0 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$RvcOperationalStateClusterErrorStateStruct constructor"); + return; + } + + CommandResponseState = + env->NewObject(errorStateStructStructClass_0, errorStateStructStructCtor_0, CommandResponseState_errorStateID, + CommandResponseState_errorStateLabel, CommandResponseState_errorStateDetails); + + env->CallVoidMethod(javaCallbackRef, javaMethod, CommandResponseState); +} +CHIPScenesManagementClusterAddSceneResponseCallback::CHIPScenesManagementClusterAddSceneResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPScenesManagementClusterAddSceneResponseCallback::~CHIPScenesManagementClusterAddSceneResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesManagementClusterAddSceneResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ScenesManagement::Commands::AddSceneResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject GroupID; + std::string GroupIDClassName = "java/lang/Integer"; + std::string GroupIDCtorSignature = "(I)V"; + jint jniGroupID = static_cast(dataResponse.groupID); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupIDClassName.c_str(), GroupIDCtorSignature.c_str(), jniGroupID, + GroupID); + jobject SceneID; + std::string SceneIDClassName = "java/lang/Integer"; + std::string SceneIDCtorSignature = "(I)V"; + jint jniSceneID = static_cast(dataResponse.sceneID); + chip::JniReferences::GetInstance().CreateBoxedObject(SceneIDClassName.c_str(), SceneIDCtorSignature.c_str(), jniSceneID, + SceneID); + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, GroupID, SceneID); +} +CHIPScenesManagementClusterViewSceneResponseCallback::CHIPScenesManagementClusterViewSceneResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPScenesManagementClusterViewSceneResponseCallback::~CHIPScenesManagementClusterViewSceneResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesManagementClusterViewSceneResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ScenesManagement::Commands::ViewSceneResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject GroupID; + std::string GroupIDClassName = "java/lang/Integer"; + std::string GroupIDCtorSignature = "(I)V"; + jint jniGroupID = static_cast(dataResponse.groupID); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupIDClassName.c_str(), GroupIDCtorSignature.c_str(), jniGroupID, + GroupID); + jobject SceneID; + std::string SceneIDClassName = "java/lang/Integer"; + std::string SceneIDCtorSignature = "(I)V"; + jint jniSceneID = static_cast(dataResponse.sceneID); + chip::JniReferences::GetInstance().CreateBoxedObject(SceneIDClassName.c_str(), SceneIDCtorSignature.c_str(), jniSceneID, + SceneID); + jobject TransitionTime; + if (!dataResponse.transitionTime.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, TransitionTime); + } + else + { + jobject TransitionTimeInsideOptional; + std::string TransitionTimeInsideOptionalClassName = "java/lang/Long"; + std::string TransitionTimeInsideOptionalCtorSignature = "(J)V"; + jlong jniTransitionTimeInsideOptional = static_cast(dataResponse.transitionTime.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(TransitionTimeInsideOptionalClassName.c_str(), + TransitionTimeInsideOptionalCtorSignature.c_str(), + jniTransitionTimeInsideOptional, TransitionTimeInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(TransitionTimeInsideOptional, TransitionTime); + } + jobject SceneName; + if (!dataResponse.sceneName.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, SceneName); + } + else + { + jobject SceneNameInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.sceneName.Value(), SceneNameInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(SceneNameInsideOptional, SceneName); + } + jobject ExtensionFieldSets; + if (!dataResponse.extensionFieldSets.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, ExtensionFieldSets); + } + else + { + jobject ExtensionFieldSetsInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(ExtensionFieldSetsInsideOptional); + + auto iter_ExtensionFieldSetsInsideOptional_1 = dataResponse.extensionFieldSets.Value().begin(); + while (iter_ExtensionFieldSetsInsideOptional_1.Next()) + { + auto & entry_1 = iter_ExtensionFieldSetsInsideOptional_1.GetValue(); + jobject newElement_1; + jobject newElement_1_clusterID; + std::string newElement_1_clusterIDClassName = "java/lang/Long"; + std::string newElement_1_clusterIDCtorSignature = "(J)V"; + jlong jninewElement_1_clusterID = static_cast(entry_1.clusterID); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_1_clusterIDClassName.c_str(), + newElement_1_clusterIDCtorSignature.c_str(), + jninewElement_1_clusterID, newElement_1_clusterID); + jobject newElement_1_attributeValueList; + chip::JniReferences::GetInstance().CreateArrayList(newElement_1_attributeValueList); + + auto iter_newElement_1_attributeValueList_3 = entry_1.attributeValueList.begin(); + while (iter_newElement_1_attributeValueList_3.Next()) + { + auto & entry_3 = iter_newElement_1_attributeValueList_3.GetValue(); + jobject newElement_3; + jobject newElement_3_attributeID; + std::string newElement_3_attributeIDClassName = "java/lang/Long"; + std::string newElement_3_attributeIDCtorSignature = "(J)V"; + jlong jninewElement_3_attributeID = static_cast(entry_3.attributeID); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_3_attributeIDClassName.c_str(), + newElement_3_attributeIDCtorSignature.c_str(), + jninewElement_3_attributeID, newElement_3_attributeID); + jobject newElement_3_attributeValue; + std::string newElement_3_attributeValueClassName = "java/lang/Long"; + std::string newElement_3_attributeValueCtorSignature = "(J)V"; + jlong jninewElement_3_attributeValue = static_cast(entry_3.attributeValue); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_3_attributeValueClassName.c_str(), newElement_3_attributeValueCtorSignature.c_str(), + jninewElement_3_attributeValue, newElement_3_attributeValue); + + jclass attributeValuePairStructClass_4; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$ScenesManagementClusterAttributeValuePair", + attributeValuePairStructClass_4); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ScenesManagementClusterAttributeValuePair"); + return; + } + + jmethodID attributeValuePairStructCtor_4; + err = chip::JniReferences::GetInstance().FindMethod(env, attributeValuePairStructClass_4, "", + "(Ljava/lang/Long;Ljava/lang/Long;)V", + &attributeValuePairStructCtor_4); + if (err != CHIP_NO_ERROR || attributeValuePairStructCtor_4 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ScenesManagementClusterAttributeValuePair constructor"); + return; + } + + newElement_3 = env->NewObject(attributeValuePairStructClass_4, attributeValuePairStructCtor_4, + newElement_3_attributeID, newElement_3_attributeValue); + chip::JniReferences::GetInstance().AddToList(newElement_1_attributeValueList, newElement_3); + } + + jclass extensionFieldSetStructClass_2; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$ScenesManagementClusterExtensionFieldSet", extensionFieldSetStructClass_2); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ScenesManagementClusterExtensionFieldSet"); + return; + } + + jmethodID extensionFieldSetStructCtor_2; + err = chip::JniReferences::GetInstance().FindMethod(env, extensionFieldSetStructClass_2, "", + "(Ljava/lang/Long;Ljava/util/ArrayList;)V", + &extensionFieldSetStructCtor_2); + if (err != CHIP_NO_ERROR || extensionFieldSetStructCtor_2 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ScenesManagementClusterExtensionFieldSet constructor"); + return; + } + + newElement_1 = env->NewObject(extensionFieldSetStructClass_2, extensionFieldSetStructCtor_2, newElement_1_clusterID, + newElement_1_attributeValueList); + chip::JniReferences::GetInstance().AddToList(ExtensionFieldSetsInsideOptional, newElement_1); + } + chip::JniReferences::GetInstance().CreateOptional(ExtensionFieldSetsInsideOptional, ExtensionFieldSets); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, GroupID, SceneID, TransitionTime, SceneName, ExtensionFieldSets); +} +CHIPScenesManagementClusterRemoveSceneResponseCallback::CHIPScenesManagementClusterRemoveSceneResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPScenesManagementClusterRemoveSceneResponseCallback::~CHIPScenesManagementClusterRemoveSceneResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesManagementClusterRemoveSceneResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ScenesManagement::Commands::RemoveSceneResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject GroupID; + std::string GroupIDClassName = "java/lang/Integer"; + std::string GroupIDCtorSignature = "(I)V"; + jint jniGroupID = static_cast(dataResponse.groupID); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupIDClassName.c_str(), GroupIDCtorSignature.c_str(), jniGroupID, + GroupID); + jobject SceneID; + std::string SceneIDClassName = "java/lang/Integer"; + std::string SceneIDCtorSignature = "(I)V"; + jint jniSceneID = static_cast(dataResponse.sceneID); + chip::JniReferences::GetInstance().CreateBoxedObject(SceneIDClassName.c_str(), SceneIDCtorSignature.c_str(), jniSceneID, + SceneID); + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, GroupID, SceneID); +} +CHIPScenesManagementClusterRemoveAllScenesResponseCallback::CHIPScenesManagementClusterRemoveAllScenesResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPScenesManagementClusterRemoveAllScenesResponseCallback::~CHIPScenesManagementClusterRemoveAllScenesResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesManagementClusterRemoveAllScenesResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ScenesManagement::Commands::RemoveAllScenesResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject GroupID; + std::string GroupIDClassName = "java/lang/Integer"; + std::string GroupIDCtorSignature = "(I)V"; + jint jniGroupID = static_cast(dataResponse.groupID); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupIDClassName.c_str(), GroupIDCtorSignature.c_str(), jniGroupID, + GroupID); + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, GroupID); +} +CHIPScenesManagementClusterStoreSceneResponseCallback::CHIPScenesManagementClusterStoreSceneResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPScenesManagementClusterStoreSceneResponseCallback::~CHIPScenesManagementClusterStoreSceneResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesManagementClusterStoreSceneResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ScenesManagement::Commands::StoreSceneResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject GroupID; + std::string GroupIDClassName = "java/lang/Integer"; + std::string GroupIDCtorSignature = "(I)V"; + jint jniGroupID = static_cast(dataResponse.groupID); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupIDClassName.c_str(), GroupIDCtorSignature.c_str(), jniGroupID, + GroupID); + jobject SceneID; + std::string SceneIDClassName = "java/lang/Integer"; + std::string SceneIDCtorSignature = "(I)V"; + jint jniSceneID = static_cast(dataResponse.sceneID); + chip::JniReferences::GetInstance().CreateBoxedObject(SceneIDClassName.c_str(), SceneIDCtorSignature.c_str(), jniSceneID, + SceneID); + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, GroupID, SceneID); +} +CHIPScenesManagementClusterGetSceneMembershipResponseCallback::CHIPScenesManagementClusterGetSceneMembershipResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPScenesManagementClusterGetSceneMembershipResponseCallback::~CHIPScenesManagementClusterGetSceneMembershipResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesManagementClusterGetSceneMembershipResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ScenesManagement::Commands::GetSceneMembershipResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject Capacity; + if (dataResponse.capacity.IsNull()) + { + Capacity = nullptr; + } + else + { + std::string CapacityClassName = "java/lang/Integer"; + std::string CapacityCtorSignature = "(I)V"; + jint jniCapacity = static_cast(dataResponse.capacity.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(CapacityClassName.c_str(), CapacityCtorSignature.c_str(), + jniCapacity, Capacity); + } + jobject GroupID; + std::string GroupIDClassName = "java/lang/Integer"; + std::string GroupIDCtorSignature = "(I)V"; + jint jniGroupID = static_cast(dataResponse.groupID); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupIDClassName.c_str(), GroupIDCtorSignature.c_str(), jniGroupID, + GroupID); + jobject SceneList; + if (!dataResponse.sceneList.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, SceneList); + } + else + { + jobject SceneListInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(SceneListInsideOptional); + + auto iter_SceneListInsideOptional_1 = dataResponse.sceneList.Value().begin(); + while (iter_SceneListInsideOptional_1.Next()) + { + auto & entry_1 = iter_SceneListInsideOptional_1.GetValue(); + jobject newElement_1; + std::string newElement_1ClassName = "java/lang/Integer"; + std::string newElement_1CtorSignature = "(I)V"; + jint jninewElement_1 = static_cast(entry_1); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_1ClassName.c_str(), newElement_1CtorSignature.c_str(), jninewElement_1, newElement_1); + chip::JniReferences::GetInstance().AddToList(SceneListInsideOptional, newElement_1); + } + chip::JniReferences::GetInstance().CreateOptional(SceneListInsideOptional, SceneList); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, Capacity, GroupID, SceneList); +} +CHIPScenesManagementClusterCopySceneResponseCallback::CHIPScenesManagementClusterCopySceneResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPScenesManagementClusterCopySceneResponseCallback::~CHIPScenesManagementClusterCopySceneResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPScenesManagementClusterCopySceneResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ScenesManagement::Commands::CopySceneResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject GroupIdentifierFrom; + std::string GroupIdentifierFromClassName = "java/lang/Integer"; + std::string GroupIdentifierFromCtorSignature = "(I)V"; + jint jniGroupIdentifierFrom = static_cast(dataResponse.groupIdentifierFrom); + chip::JniReferences::GetInstance().CreateBoxedObject(GroupIdentifierFromClassName.c_str(), + GroupIdentifierFromCtorSignature.c_str(), jniGroupIdentifierFrom, + GroupIdentifierFrom); + jobject SceneIdentifierFrom; + std::string SceneIdentifierFromClassName = "java/lang/Integer"; + std::string SceneIdentifierFromCtorSignature = "(I)V"; + jint jniSceneIdentifierFrom = static_cast(dataResponse.sceneIdentifierFrom); + chip::JniReferences::GetInstance().CreateBoxedObject(SceneIdentifierFromClassName.c_str(), + SceneIdentifierFromCtorSignature.c_str(), jniSceneIdentifierFrom, + SceneIdentifierFrom); + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, GroupIdentifierFrom, SceneIdentifierFrom); +} +CHIPEnergyEvseClusterGetTargetsResponseCallback::CHIPEnergyEvseClusterGetTargetsResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPEnergyEvseClusterGetTargetsResponseCallback::~CHIPEnergyEvseClusterGetTargetsResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPEnergyEvseClusterGetTargetsResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::EnergyEvse::Commands::GetTargetsResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/util/ArrayList;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject ChargingTargetSchedules; + chip::JniReferences::GetInstance().CreateArrayList(ChargingTargetSchedules); + + auto iter_ChargingTargetSchedules_0 = dataResponse.chargingTargetSchedules.begin(); + while (iter_ChargingTargetSchedules_0.Next()) + { + auto & entry_0 = iter_ChargingTargetSchedules_0.GetValue(); + jobject newElement_0; + jobject newElement_0_dayOfWeekForSequence; + std::string newElement_0_dayOfWeekForSequenceClassName = "java/lang/Integer"; + std::string newElement_0_dayOfWeekForSequenceCtorSignature = "(I)V"; + jint jninewElement_0_dayOfWeekForSequence = static_cast(entry_0.dayOfWeekForSequence.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_dayOfWeekForSequenceClassName.c_str(), newElement_0_dayOfWeekForSequenceCtorSignature.c_str(), + jninewElement_0_dayOfWeekForSequence, newElement_0_dayOfWeekForSequence); + jobject newElement_0_chargingTargets; + chip::JniReferences::GetInstance().CreateArrayList(newElement_0_chargingTargets); + + auto iter_newElement_0_chargingTargets_2 = entry_0.chargingTargets.begin(); + while (iter_newElement_0_chargingTargets_2.Next()) + { + auto & entry_2 = iter_newElement_0_chargingTargets_2.GetValue(); + jobject newElement_2; + jobject newElement_2_targetTimeMinutesPastMidnight; + std::string newElement_2_targetTimeMinutesPastMidnightClassName = "java/lang/Integer"; + std::string newElement_2_targetTimeMinutesPastMidnightCtorSignature = "(I)V"; + jint jninewElement_2_targetTimeMinutesPastMidnight = static_cast(entry_2.targetTimeMinutesPastMidnight); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_2_targetTimeMinutesPastMidnightClassName.c_str(), + newElement_2_targetTimeMinutesPastMidnightCtorSignature.c_str(), jninewElement_2_targetTimeMinutesPastMidnight, + newElement_2_targetTimeMinutesPastMidnight); + jobject newElement_2_targetSoC; + if (!entry_2.targetSoC.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_2_targetSoC); + } + else + { + jobject newElement_2_targetSoCInsideOptional; + std::string newElement_2_targetSoCInsideOptionalClassName = "java/lang/Integer"; + std::string newElement_2_targetSoCInsideOptionalCtorSignature = "(I)V"; + jint jninewElement_2_targetSoCInsideOptional = static_cast(entry_2.targetSoC.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_2_targetSoCInsideOptionalClassName.c_str(), + newElement_2_targetSoCInsideOptionalCtorSignature.c_str(), jninewElement_2_targetSoCInsideOptional, + newElement_2_targetSoCInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(newElement_2_targetSoCInsideOptional, newElement_2_targetSoC); + } + jobject newElement_2_addedEnergy; + if (!entry_2.addedEnergy.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_2_addedEnergy); + } + else + { + jobject newElement_2_addedEnergyInsideOptional; + std::string newElement_2_addedEnergyInsideOptionalClassName = "java/lang/Long"; + std::string newElement_2_addedEnergyInsideOptionalCtorSignature = "(J)V"; + jlong jninewElement_2_addedEnergyInsideOptional = static_cast(entry_2.addedEnergy.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_2_addedEnergyInsideOptionalClassName.c_str(), + newElement_2_addedEnergyInsideOptionalCtorSignature.c_str(), jninewElement_2_addedEnergyInsideOptional, + newElement_2_addedEnergyInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(newElement_2_addedEnergyInsideOptional, newElement_2_addedEnergy); + } + + jclass chargingTargetStructStructClass_3; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$EnergyEvseClusterChargingTargetStruct", chargingTargetStructStructClass_3); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$EnergyEvseClusterChargingTargetStruct"); + return; + } + + jmethodID chargingTargetStructStructCtor_3; + err = chip::JniReferences::GetInstance().FindMethod(env, chargingTargetStructStructClass_3, "", + "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;)V", + &chargingTargetStructStructCtor_3); + if (err != CHIP_NO_ERROR || chargingTargetStructStructCtor_3 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$EnergyEvseClusterChargingTargetStruct constructor"); + return; + } + + newElement_2 = + env->NewObject(chargingTargetStructStructClass_3, chargingTargetStructStructCtor_3, + newElement_2_targetTimeMinutesPastMidnight, newElement_2_targetSoC, newElement_2_addedEnergy); + chip::JniReferences::GetInstance().AddToList(newElement_0_chargingTargets, newElement_2); + } + + jclass chargingTargetScheduleStructStructClass_1; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$EnergyEvseClusterChargingTargetScheduleStruct", + chargingTargetScheduleStructStructClass_1); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$EnergyEvseClusterChargingTargetScheduleStruct"); + return; + } + + jmethodID chargingTargetScheduleStructStructCtor_1; + err = chip::JniReferences::GetInstance().FindMethod(env, chargingTargetScheduleStructStructClass_1, "", + "(Ljava/lang/Integer;Ljava/util/ArrayList;)V", + &chargingTargetScheduleStructStructCtor_1); + if (err != CHIP_NO_ERROR || chargingTargetScheduleStructStructCtor_1 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$EnergyEvseClusterChargingTargetScheduleStruct constructor"); + return; + } + + newElement_0 = env->NewObject(chargingTargetScheduleStructStructClass_1, chargingTargetScheduleStructStructCtor_1, + newElement_0_dayOfWeekForSequence, newElement_0_chargingTargets); + chip::JniReferences::GetInstance().AddToList(ChargingTargetSchedules, newElement_0); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, ChargingTargetSchedules); +} +CHIPEnergyEvseModeClusterChangeToModeResponseCallback::CHIPEnergyEvseModeClusterChangeToModeResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPEnergyEvseModeClusterChangeToModeResponseCallback::~CHIPEnergyEvseModeClusterChangeToModeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPEnergyEvseModeClusterChangeToModeResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::EnergyEvseMode::Commands::ChangeToModeResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject StatusText; + if (!dataResponse.statusText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, StatusText); + } + else + { + jobject StatusTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.statusText.Value(), StatusTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(StatusTextInsideOptional, StatusText); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, StatusText); +} +CHIPDeviceEnergyManagementModeClusterChangeToModeResponseCallback:: +CHIPDeviceEnergyManagementModeClusterChangeToModeResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPDeviceEnergyManagementModeClusterChangeToModeResponseCallback::~ +CHIPDeviceEnergyManagementModeClusterChangeToModeResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDeviceEnergyManagementModeClusterChangeToModeResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::DeviceEnergyManagementMode::Commands::ChangeToModeResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject StatusText; + if (!dataResponse.statusText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, StatusText); + } + else + { + jobject StatusTextInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.statusText.Value(), StatusTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(StatusTextInsideOptional, StatusText); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, StatusText); +} +CHIPDoorLockClusterGetWeekDayScheduleResponseCallback::CHIPDoorLockClusterGetWeekDayScheduleResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPDoorLockClusterGetWeekDayScheduleResponseCallback::~CHIPDoorLockClusterGetWeekDayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetWeekDayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetWeekDayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/" + "Optional;Ljava/util/Optional;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject WeekDayIndex; + std::string WeekDayIndexClassName = "java/lang/Integer"; + std::string WeekDayIndexCtorSignature = "(I)V"; + jint jniWeekDayIndex = static_cast(dataResponse.weekDayIndex); + chip::JniReferences::GetInstance().CreateBoxedObject(WeekDayIndexClassName.c_str(), WeekDayIndexCtorSignature.c_str(), + jniWeekDayIndex, WeekDayIndex); + jobject UserIndex; + std::string UserIndexClassName = "java/lang/Integer"; + std::string UserIndexCtorSignature = "(I)V"; + jint jniUserIndex = static_cast(dataResponse.userIndex); + chip::JniReferences::GetInstance().CreateBoxedObject(UserIndexClassName.c_str(), UserIndexCtorSignature.c_str(), + jniUserIndex, UserIndex); + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject DaysMask; + if (!dataResponse.daysMask.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, DaysMask); + } + else + { + jobject DaysMaskInsideOptional; + std::string DaysMaskInsideOptionalClassName = "java/lang/Integer"; + std::string DaysMaskInsideOptionalCtorSignature = "(I)V"; + jint jniDaysMaskInsideOptional = static_cast(dataResponse.daysMask.Value().Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject(DaysMaskInsideOptionalClassName.c_str(), + DaysMaskInsideOptionalCtorSignature.c_str(), + jniDaysMaskInsideOptional, DaysMaskInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(DaysMaskInsideOptional, DaysMask); + } + jobject StartHour; + if (!dataResponse.startHour.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, StartHour); + } + else + { + jobject StartHourInsideOptional; + std::string StartHourInsideOptionalClassName = "java/lang/Integer"; + std::string StartHourInsideOptionalCtorSignature = "(I)V"; + jint jniStartHourInsideOptional = static_cast(dataResponse.startHour.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(StartHourInsideOptionalClassName.c_str(), + StartHourInsideOptionalCtorSignature.c_str(), + jniStartHourInsideOptional, StartHourInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(StartHourInsideOptional, StartHour); + } + jobject StartMinute; + if (!dataResponse.startMinute.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, StartMinute); + } + else + { + jobject StartMinuteInsideOptional; + std::string StartMinuteInsideOptionalClassName = "java/lang/Integer"; + std::string StartMinuteInsideOptionalCtorSignature = "(I)V"; + jint jniStartMinuteInsideOptional = static_cast(dataResponse.startMinute.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(StartMinuteInsideOptionalClassName.c_str(), + StartMinuteInsideOptionalCtorSignature.c_str(), + jniStartMinuteInsideOptional, StartMinuteInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(StartMinuteInsideOptional, StartMinute); + } + jobject EndHour; + if (!dataResponse.endHour.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, EndHour); + } + else + { + jobject EndHourInsideOptional; + std::string EndHourInsideOptionalClassName = "java/lang/Integer"; + std::string EndHourInsideOptionalCtorSignature = "(I)V"; + jint jniEndHourInsideOptional = static_cast(dataResponse.endHour.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(EndHourInsideOptionalClassName.c_str(), + EndHourInsideOptionalCtorSignature.c_str(), + jniEndHourInsideOptional, EndHourInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(EndHourInsideOptional, EndHour); + } + jobject EndMinute; + if (!dataResponse.endMinute.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, EndMinute); + } + else + { + jobject EndMinuteInsideOptional; + std::string EndMinuteInsideOptionalClassName = "java/lang/Integer"; + std::string EndMinuteInsideOptionalCtorSignature = "(I)V"; + jint jniEndMinuteInsideOptional = static_cast(dataResponse.endMinute.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(EndMinuteInsideOptionalClassName.c_str(), + EndMinuteInsideOptionalCtorSignature.c_str(), + jniEndMinuteInsideOptional, EndMinuteInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(EndMinuteInsideOptional, EndMinute); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, WeekDayIndex, UserIndex, Status, DaysMask, StartHour, StartMinute, EndHour, + EndMinute); +} +CHIPDoorLockClusterGetYearDayScheduleResponseCallback::CHIPDoorLockClusterGetYearDayScheduleResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPDoorLockClusterGetYearDayScheduleResponseCallback::~CHIPDoorLockClusterGetYearDayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetYearDayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetYearDayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject YearDayIndex; + std::string YearDayIndexClassName = "java/lang/Integer"; + std::string YearDayIndexCtorSignature = "(I)V"; + jint jniYearDayIndex = static_cast(dataResponse.yearDayIndex); + chip::JniReferences::GetInstance().CreateBoxedObject(YearDayIndexClassName.c_str(), YearDayIndexCtorSignature.c_str(), + jniYearDayIndex, YearDayIndex); + jobject UserIndex; + std::string UserIndexClassName = "java/lang/Integer"; + std::string UserIndexCtorSignature = "(I)V"; + jint jniUserIndex = static_cast(dataResponse.userIndex); + chip::JniReferences::GetInstance().CreateBoxedObject(UserIndexClassName.c_str(), UserIndexCtorSignature.c_str(), + jniUserIndex, UserIndex); + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject LocalStartTime; + if (!dataResponse.localStartTime.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, LocalStartTime); + } + else + { + jobject LocalStartTimeInsideOptional; + std::string LocalStartTimeInsideOptionalClassName = "java/lang/Long"; + std::string LocalStartTimeInsideOptionalCtorSignature = "(J)V"; + jlong jniLocalStartTimeInsideOptional = static_cast(dataResponse.localStartTime.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(LocalStartTimeInsideOptionalClassName.c_str(), + LocalStartTimeInsideOptionalCtorSignature.c_str(), + jniLocalStartTimeInsideOptional, LocalStartTimeInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(LocalStartTimeInsideOptional, LocalStartTime); + } + jobject LocalEndTime; + if (!dataResponse.localEndTime.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, LocalEndTime); + } + else + { + jobject LocalEndTimeInsideOptional; + std::string LocalEndTimeInsideOptionalClassName = "java/lang/Long"; + std::string LocalEndTimeInsideOptionalCtorSignature = "(J)V"; + jlong jniLocalEndTimeInsideOptional = static_cast(dataResponse.localEndTime.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(LocalEndTimeInsideOptionalClassName.c_str(), + LocalEndTimeInsideOptionalCtorSignature.c_str(), + jniLocalEndTimeInsideOptional, LocalEndTimeInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(LocalEndTimeInsideOptional, LocalEndTime); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, YearDayIndex, UserIndex, Status, LocalStartTime, LocalEndTime); +} +CHIPDoorLockClusterGetHolidayScheduleResponseCallback::CHIPDoorLockClusterGetHolidayScheduleResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPDoorLockClusterGetHolidayScheduleResponseCallback::~CHIPDoorLockClusterGetHolidayScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetHolidayScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetHolidayScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject HolidayIndex; + std::string HolidayIndexClassName = "java/lang/Integer"; + std::string HolidayIndexCtorSignature = "(I)V"; + jint jniHolidayIndex = static_cast(dataResponse.holidayIndex); + chip::JniReferences::GetInstance().CreateBoxedObject(HolidayIndexClassName.c_str(), HolidayIndexCtorSignature.c_str(), + jniHolidayIndex, HolidayIndex); + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject LocalStartTime; + if (!dataResponse.localStartTime.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, LocalStartTime); + } + else + { + jobject LocalStartTimeInsideOptional; + std::string LocalStartTimeInsideOptionalClassName = "java/lang/Long"; + std::string LocalStartTimeInsideOptionalCtorSignature = "(J)V"; + jlong jniLocalStartTimeInsideOptional = static_cast(dataResponse.localStartTime.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(LocalStartTimeInsideOptionalClassName.c_str(), + LocalStartTimeInsideOptionalCtorSignature.c_str(), + jniLocalStartTimeInsideOptional, LocalStartTimeInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(LocalStartTimeInsideOptional, LocalStartTime); + } + jobject LocalEndTime; + if (!dataResponse.localEndTime.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, LocalEndTime); + } + else + { + jobject LocalEndTimeInsideOptional; + std::string LocalEndTimeInsideOptionalClassName = "java/lang/Long"; + std::string LocalEndTimeInsideOptionalCtorSignature = "(J)V"; + jlong jniLocalEndTimeInsideOptional = static_cast(dataResponse.localEndTime.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(LocalEndTimeInsideOptionalClassName.c_str(), + LocalEndTimeInsideOptionalCtorSignature.c_str(), + jniLocalEndTimeInsideOptional, LocalEndTimeInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(LocalEndTimeInsideOptional, LocalEndTime); + } + jobject OperatingMode; + if (!dataResponse.operatingMode.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, OperatingMode); + } + else + { + jobject OperatingModeInsideOptional; + std::string OperatingModeInsideOptionalClassName = "java/lang/Integer"; + std::string OperatingModeInsideOptionalCtorSignature = "(I)V"; + jint jniOperatingModeInsideOptional = static_cast(dataResponse.operatingMode.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(OperatingModeInsideOptionalClassName.c_str(), + OperatingModeInsideOptionalCtorSignature.c_str(), + jniOperatingModeInsideOptional, OperatingModeInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(OperatingModeInsideOptional, OperatingMode); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, HolidayIndex, Status, LocalStartTime, LocalEndTime, OperatingMode); +} +CHIPDoorLockClusterGetUserResponseCallback::CHIPDoorLockClusterGetUserResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPDoorLockClusterGetUserResponseCallback::~CHIPDoorLockClusterGetUserResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetUserResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetUserResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr cppCallback( + reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/" + "ArrayList;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject UserIndex; + std::string UserIndexClassName = "java/lang/Integer"; + std::string UserIndexCtorSignature = "(I)V"; + jint jniUserIndex = static_cast(dataResponse.userIndex); + chip::JniReferences::GetInstance().CreateBoxedObject(UserIndexClassName.c_str(), UserIndexCtorSignature.c_str(), + jniUserIndex, UserIndex); + jobject UserName; + if (dataResponse.userName.IsNull()) + { + UserName = nullptr; + } + else + { + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.userName.Value(), UserName)); + } + jobject UserUniqueID; + if (dataResponse.userUniqueID.IsNull()) + { + UserUniqueID = nullptr; + } + else + { + std::string UserUniqueIDClassName = "java/lang/Long"; + std::string UserUniqueIDCtorSignature = "(J)V"; + jlong jniUserUniqueID = static_cast(dataResponse.userUniqueID.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + UserUniqueIDClassName.c_str(), UserUniqueIDCtorSignature.c_str(), jniUserUniqueID, UserUniqueID); + } + jobject UserStatus; + if (dataResponse.userStatus.IsNull()) + { + UserStatus = nullptr; + } + else + { + std::string UserStatusClassName = "java/lang/Integer"; + std::string UserStatusCtorSignature = "(I)V"; + jint jniUserStatus = static_cast(dataResponse.userStatus.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(UserStatusClassName.c_str(), UserStatusCtorSignature.c_str(), + jniUserStatus, UserStatus); + } + jobject UserType; + if (dataResponse.userType.IsNull()) + { + UserType = nullptr; + } + else + { + std::string UserTypeClassName = "java/lang/Integer"; + std::string UserTypeCtorSignature = "(I)V"; + jint jniUserType = static_cast(dataResponse.userType.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(UserTypeClassName.c_str(), UserTypeCtorSignature.c_str(), + jniUserType, UserType); + } + jobject CredentialRule; + if (dataResponse.credentialRule.IsNull()) + { + CredentialRule = nullptr; + } + else + { + std::string CredentialRuleClassName = "java/lang/Integer"; + std::string CredentialRuleCtorSignature = "(I)V"; + jint jniCredentialRule = static_cast(dataResponse.credentialRule.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + CredentialRuleClassName.c_str(), CredentialRuleCtorSignature.c_str(), jniCredentialRule, CredentialRule); + } + jobject Credentials; + if (dataResponse.credentials.IsNull()) + { + Credentials = nullptr; + } + else + { + chip::JniReferences::GetInstance().CreateArrayList(Credentials); + + auto iter_Credentials_1 = dataResponse.credentials.Value().begin(); + while (iter_Credentials_1.Next()) + { + auto & entry_1 = iter_Credentials_1.GetValue(); + jobject newElement_1; + jobject newElement_1_credentialType; + std::string newElement_1_credentialTypeClassName = "java/lang/Integer"; + std::string newElement_1_credentialTypeCtorSignature = "(I)V"; + jint jninewElement_1_credentialType = static_cast(entry_1.credentialType); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_1_credentialTypeClassName.c_str(), + newElement_1_credentialTypeCtorSignature.c_str(), + jninewElement_1_credentialType, newElement_1_credentialType); + jobject newElement_1_credentialIndex; + std::string newElement_1_credentialIndexClassName = "java/lang/Integer"; + std::string newElement_1_credentialIndexCtorSignature = "(I)V"; + jint jninewElement_1_credentialIndex = static_cast(entry_1.credentialIndex); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_1_credentialIndexClassName.c_str(), newElement_1_credentialIndexCtorSignature.c_str(), + jninewElement_1_credentialIndex, newElement_1_credentialIndex); + + jclass credentialStructStructClass_2; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$DoorLockClusterCredentialStruct", credentialStructStructClass_2); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$DoorLockClusterCredentialStruct"); + return; + } + + jmethodID credentialStructStructCtor_2; + err = chip::JniReferences::GetInstance().FindMethod(env, credentialStructStructClass_2, "", + "(Ljava/lang/Integer;Ljava/lang/Integer;)V", + &credentialStructStructCtor_2); + if (err != CHIP_NO_ERROR || credentialStructStructCtor_2 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$DoorLockClusterCredentialStruct constructor"); + return; + } + + newElement_1 = env->NewObject(credentialStructStructClass_2, credentialStructStructCtor_2, newElement_1_credentialType, + newElement_1_credentialIndex); + chip::JniReferences::GetInstance().AddToList(Credentials, newElement_1); + } + } + jobject CreatorFabricIndex; + if (dataResponse.creatorFabricIndex.IsNull()) + { + CreatorFabricIndex = nullptr; + } + else + { + std::string CreatorFabricIndexClassName = "java/lang/Integer"; + std::string CreatorFabricIndexCtorSignature = "(I)V"; + jint jniCreatorFabricIndex = static_cast(dataResponse.creatorFabricIndex.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(CreatorFabricIndexClassName.c_str(), + CreatorFabricIndexCtorSignature.c_str(), jniCreatorFabricIndex, + CreatorFabricIndex); + } + jobject LastModifiedFabricIndex; + if (dataResponse.lastModifiedFabricIndex.IsNull()) + { + LastModifiedFabricIndex = nullptr; + } + else + { + std::string LastModifiedFabricIndexClassName = "java/lang/Integer"; + std::string LastModifiedFabricIndexCtorSignature = "(I)V"; + jint jniLastModifiedFabricIndex = static_cast(dataResponse.lastModifiedFabricIndex.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(LastModifiedFabricIndexClassName.c_str(), + LastModifiedFabricIndexCtorSignature.c_str(), + jniLastModifiedFabricIndex, LastModifiedFabricIndex); + } + jobject NextUserIndex; + if (dataResponse.nextUserIndex.IsNull()) + { + NextUserIndex = nullptr; + } + else + { + std::string NextUserIndexClassName = "java/lang/Integer"; + std::string NextUserIndexCtorSignature = "(I)V"; + jint jniNextUserIndex = static_cast(dataResponse.nextUserIndex.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + NextUserIndexClassName.c_str(), NextUserIndexCtorSignature.c_str(), jniNextUserIndex, NextUserIndex); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, UserIndex, UserName, UserUniqueID, UserStatus, UserType, CredentialRule, + Credentials, CreatorFabricIndex, LastModifiedFabricIndex, NextUserIndex); +} +CHIPDoorLockClusterSetCredentialResponseCallback::CHIPDoorLockClusterSetCredentialResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPDoorLockClusterSetCredentialResponseCallback::~CHIPDoorLockClusterSetCredentialResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterSetCredentialResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::SetCredentialResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject UserIndex; + if (dataResponse.userIndex.IsNull()) + { + UserIndex = nullptr; + } + else + { + std::string UserIndexClassName = "java/lang/Integer"; + std::string UserIndexCtorSignature = "(I)V"; + jint jniUserIndex = static_cast(dataResponse.userIndex.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(UserIndexClassName.c_str(), UserIndexCtorSignature.c_str(), + jniUserIndex, UserIndex); + } + jobject NextCredentialIndex; + if (dataResponse.nextCredentialIndex.IsNull()) + { + NextCredentialIndex = nullptr; + } + else + { + std::string NextCredentialIndexClassName = "java/lang/Integer"; + std::string NextCredentialIndexCtorSignature = "(I)V"; + jint jniNextCredentialIndex = static_cast(dataResponse.nextCredentialIndex.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(NextCredentialIndexClassName.c_str(), + NextCredentialIndexCtorSignature.c_str(), jniNextCredentialIndex, + NextCredentialIndex); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, UserIndex, NextCredentialIndex); +} +CHIPDoorLockClusterGetCredentialStatusResponseCallback::CHIPDoorLockClusterGetCredentialStatusResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPDoorLockClusterGetCredentialStatusResponseCallback::~CHIPDoorLockClusterGetCredentialStatusResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPDoorLockClusterGetCredentialStatusResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::DoorLock::Commands::GetCredentialStatusResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Boolean;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject CredentialExists; + std::string CredentialExistsClassName = "java/lang/Boolean"; + std::string CredentialExistsCtorSignature = "(Z)V"; + jboolean jniCredentialExists = static_cast(dataResponse.credentialExists); + chip::JniReferences::GetInstance().CreateBoxedObject( + CredentialExistsClassName.c_str(), CredentialExistsCtorSignature.c_str(), jniCredentialExists, CredentialExists); + jobject UserIndex; + if (dataResponse.userIndex.IsNull()) + { + UserIndex = nullptr; + } + else + { + std::string UserIndexClassName = "java/lang/Integer"; + std::string UserIndexCtorSignature = "(I)V"; + jint jniUserIndex = static_cast(dataResponse.userIndex.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(UserIndexClassName.c_str(), UserIndexCtorSignature.c_str(), + jniUserIndex, UserIndex); + } + jobject CreatorFabricIndex; + if (dataResponse.creatorFabricIndex.IsNull()) + { + CreatorFabricIndex = nullptr; + } + else + { + std::string CreatorFabricIndexClassName = "java/lang/Integer"; + std::string CreatorFabricIndexCtorSignature = "(I)V"; + jint jniCreatorFabricIndex = static_cast(dataResponse.creatorFabricIndex.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(CreatorFabricIndexClassName.c_str(), + CreatorFabricIndexCtorSignature.c_str(), jniCreatorFabricIndex, + CreatorFabricIndex); + } + jobject LastModifiedFabricIndex; + if (dataResponse.lastModifiedFabricIndex.IsNull()) + { + LastModifiedFabricIndex = nullptr; + } + else + { + std::string LastModifiedFabricIndexClassName = "java/lang/Integer"; + std::string LastModifiedFabricIndexCtorSignature = "(I)V"; + jint jniLastModifiedFabricIndex = static_cast(dataResponse.lastModifiedFabricIndex.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(LastModifiedFabricIndexClassName.c_str(), + LastModifiedFabricIndexCtorSignature.c_str(), + jniLastModifiedFabricIndex, LastModifiedFabricIndex); + } + jobject NextCredentialIndex; + if (dataResponse.nextCredentialIndex.IsNull()) + { + NextCredentialIndex = nullptr; + } + else + { + std::string NextCredentialIndexClassName = "java/lang/Integer"; + std::string NextCredentialIndexCtorSignature = "(I)V"; + jint jniNextCredentialIndex = static_cast(dataResponse.nextCredentialIndex.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(NextCredentialIndexClassName.c_str(), + NextCredentialIndexCtorSignature.c_str(), jniNextCredentialIndex, + NextCredentialIndex); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, CredentialExists, UserIndex, CreatorFabricIndex, LastModifiedFabricIndex, + NextCredentialIndex); +} +CHIPThermostatClusterGetWeeklyScheduleResponseCallback::CHIPThermostatClusterGetWeeklyScheduleResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPThermostatClusterGetWeeklyScheduleResponseCallback::~CHIPThermostatClusterGetWeeklyScheduleResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPThermostatClusterGetWeeklyScheduleResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Thermostat::Commands::GetWeeklyScheduleResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/ArrayList;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject NumberOfTransitionsForSequence; + std::string NumberOfTransitionsForSequenceClassName = "java/lang/Integer"; + std::string NumberOfTransitionsForSequenceCtorSignature = "(I)V"; + jint jniNumberOfTransitionsForSequence = static_cast(dataResponse.numberOfTransitionsForSequence); + chip::JniReferences::GetInstance().CreateBoxedObject(NumberOfTransitionsForSequenceClassName.c_str(), + NumberOfTransitionsForSequenceCtorSignature.c_str(), + jniNumberOfTransitionsForSequence, NumberOfTransitionsForSequence); + jobject DayOfWeekForSequence; + std::string DayOfWeekForSequenceClassName = "java/lang/Integer"; + std::string DayOfWeekForSequenceCtorSignature = "(I)V"; + jint jniDayOfWeekForSequence = static_cast(dataResponse.dayOfWeekForSequence.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject(DayOfWeekForSequenceClassName.c_str(), + DayOfWeekForSequenceCtorSignature.c_str(), jniDayOfWeekForSequence, + DayOfWeekForSequence); + jobject ModeForSequence; + std::string ModeForSequenceClassName = "java/lang/Integer"; + std::string ModeForSequenceCtorSignature = "(I)V"; + jint jniModeForSequence = static_cast(dataResponse.modeForSequence.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject( + ModeForSequenceClassName.c_str(), ModeForSequenceCtorSignature.c_str(), jniModeForSequence, ModeForSequence); + jobject Transitions; + chip::JniReferences::GetInstance().CreateArrayList(Transitions); + + auto iter_Transitions_0 = dataResponse.transitions.begin(); + while (iter_Transitions_0.Next()) + { + auto & entry_0 = iter_Transitions_0.GetValue(); + jobject newElement_0; + jobject newElement_0_transitionTime; + std::string newElement_0_transitionTimeClassName = "java/lang/Integer"; + std::string newElement_0_transitionTimeCtorSignature = "(I)V"; + jint jninewElement_0_transitionTime = static_cast(entry_0.transitionTime); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0_transitionTimeClassName.c_str(), + newElement_0_transitionTimeCtorSignature.c_str(), + jninewElement_0_transitionTime, newElement_0_transitionTime); + jobject newElement_0_heatSetpoint; + if (entry_0.heatSetpoint.IsNull()) + { + newElement_0_heatSetpoint = nullptr; + } + else + { + std::string newElement_0_heatSetpointClassName = "java/lang/Integer"; + std::string newElement_0_heatSetpointCtorSignature = "(I)V"; + jint jninewElement_0_heatSetpoint = static_cast(entry_0.heatSetpoint.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0_heatSetpointClassName.c_str(), + newElement_0_heatSetpointCtorSignature.c_str(), + jninewElement_0_heatSetpoint, newElement_0_heatSetpoint); + } + jobject newElement_0_coolSetpoint; + if (entry_0.coolSetpoint.IsNull()) + { + newElement_0_coolSetpoint = nullptr; + } + else + { + std::string newElement_0_coolSetpointClassName = "java/lang/Integer"; + std::string newElement_0_coolSetpointCtorSignature = "(I)V"; + jint jninewElement_0_coolSetpoint = static_cast(entry_0.coolSetpoint.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0_coolSetpointClassName.c_str(), + newElement_0_coolSetpointCtorSignature.c_str(), + jninewElement_0_coolSetpoint, newElement_0_coolSetpoint); + } + + jclass weeklyScheduleTransitionStructStructClass_1; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$ThermostatClusterWeeklyScheduleTransitionStruct", + weeklyScheduleTransitionStructStructClass_1); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ThermostatClusterWeeklyScheduleTransitionStruct"); + return; + } + + jmethodID weeklyScheduleTransitionStructStructCtor_1; + err = chip::JniReferences::GetInstance().FindMethod(env, weeklyScheduleTransitionStructStructClass_1, "", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V", + &weeklyScheduleTransitionStructStructCtor_1); + if (err != CHIP_NO_ERROR || weeklyScheduleTransitionStructStructCtor_1 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ThermostatClusterWeeklyScheduleTransitionStruct constructor"); + return; + } + + newElement_0 = env->NewObject(weeklyScheduleTransitionStructStructClass_1, weeklyScheduleTransitionStructStructCtor_1, + newElement_0_transitionTime, newElement_0_heatSetpoint, newElement_0_coolSetpoint); + chip::JniReferences::GetInstance().AddToList(Transitions, newElement_0); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, NumberOfTransitionsForSequence, DayOfWeekForSequence, ModeForSequence, + Transitions); +} +CHIPChannelClusterChangeChannelResponseCallback::CHIPChannelClusterChangeChannelResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPChannelClusterChangeChannelResponseCallback::~CHIPChannelClusterChangeChannelResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPChannelClusterChangeChannelResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Channel::Commands::ChangeChannelResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject Data; + if (!dataResponse.data.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Data); + } + else + { + jobject DataInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.data.Value(), DataInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(DataInsideOptional, Data); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, Data); +} +CHIPChannelClusterProgramGuideResponseCallback::CHIPChannelClusterProgramGuideResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPChannelClusterProgramGuideResponseCallback::~CHIPChannelClusterProgramGuideResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPChannelClusterProgramGuideResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::Channel::Commands::ProgramGuideResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Lchip/devicecontroller/ChipStructs$ChannelClusterChannelPagingStruct;Ljava/util/ArrayList;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Paging; + jobject Paging_previousToken; + if (!dataResponse.paging.previousToken.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Paging_previousToken); + } + else + { + jobject Paging_previousTokenInsideOptional; + if (dataResponse.paging.previousToken.Value().IsNull()) + { + Paging_previousTokenInsideOptional = nullptr; + } + else + { + jobject Paging_previousTokenInsideOptional_limit; + if (!dataResponse.paging.previousToken.Value().Value().limit.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Paging_previousTokenInsideOptional_limit); + } + else + { + jobject Paging_previousTokenInsideOptional_limitInsideOptional; + std::string Paging_previousTokenInsideOptional_limitInsideOptionalClassName = "java/lang/Integer"; + std::string Paging_previousTokenInsideOptional_limitInsideOptionalCtorSignature = "(I)V"; + jint jniPaging_previousTokenInsideOptional_limitInsideOptional = + static_cast(dataResponse.paging.previousToken.Value().Value().limit.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + Paging_previousTokenInsideOptional_limitInsideOptionalClassName.c_str(), + Paging_previousTokenInsideOptional_limitInsideOptionalCtorSignature.c_str(), + jniPaging_previousTokenInsideOptional_limitInsideOptional, + Paging_previousTokenInsideOptional_limitInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(Paging_previousTokenInsideOptional_limitInsideOptional, + Paging_previousTokenInsideOptional_limit); + } + jobject Paging_previousTokenInsideOptional_after; + if (!dataResponse.paging.previousToken.Value().Value().after.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Paging_previousTokenInsideOptional_after); + } + else + { + jobject Paging_previousTokenInsideOptional_afterInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF( + dataResponse.paging.previousToken.Value().Value().after.Value(), + Paging_previousTokenInsideOptional_afterInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(Paging_previousTokenInsideOptional_afterInsideOptional, + Paging_previousTokenInsideOptional_after); + } + jobject Paging_previousTokenInsideOptional_before; + if (!dataResponse.paging.previousToken.Value().Value().before.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Paging_previousTokenInsideOptional_before); + } + else + { + jobject Paging_previousTokenInsideOptional_beforeInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF( + dataResponse.paging.previousToken.Value().Value().before.Value(), + Paging_previousTokenInsideOptional_beforeInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(Paging_previousTokenInsideOptional_beforeInsideOptional, + Paging_previousTokenInsideOptional_before); + } + + jclass pageTokenStructStructClass_3; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$ChannelClusterPageTokenStruct", pageTokenStructStructClass_3); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ChannelClusterPageTokenStruct"); + return; + } + + jmethodID pageTokenStructStructCtor_3; + err = chip::JniReferences::GetInstance().FindMethod(env, pageTokenStructStructClass_3, "", + "(Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;)V", + &pageTokenStructStructCtor_3); + if (err != CHIP_NO_ERROR || pageTokenStructStructCtor_3 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ChannelClusterPageTokenStruct constructor"); + return; + } + + Paging_previousTokenInsideOptional = + env->NewObject(pageTokenStructStructClass_3, pageTokenStructStructCtor_3, Paging_previousTokenInsideOptional_limit, + Paging_previousTokenInsideOptional_after, Paging_previousTokenInsideOptional_before); + } + chip::JniReferences::GetInstance().CreateOptional(Paging_previousTokenInsideOptional, Paging_previousToken); + } + jobject Paging_nextToken; + if (!dataResponse.paging.nextToken.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Paging_nextToken); + } + else + { + jobject Paging_nextTokenInsideOptional; + if (dataResponse.paging.nextToken.Value().IsNull()) + { + Paging_nextTokenInsideOptional = nullptr; + } + else + { + jobject Paging_nextTokenInsideOptional_limit; + if (!dataResponse.paging.nextToken.Value().Value().limit.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Paging_nextTokenInsideOptional_limit); + } + else + { + jobject Paging_nextTokenInsideOptional_limitInsideOptional; + std::string Paging_nextTokenInsideOptional_limitInsideOptionalClassName = "java/lang/Integer"; + std::string Paging_nextTokenInsideOptional_limitInsideOptionalCtorSignature = "(I)V"; + jint jniPaging_nextTokenInsideOptional_limitInsideOptional = + static_cast(dataResponse.paging.nextToken.Value().Value().limit.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + Paging_nextTokenInsideOptional_limitInsideOptionalClassName.c_str(), + Paging_nextTokenInsideOptional_limitInsideOptionalCtorSignature.c_str(), + jniPaging_nextTokenInsideOptional_limitInsideOptional, Paging_nextTokenInsideOptional_limitInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(Paging_nextTokenInsideOptional_limitInsideOptional, + Paging_nextTokenInsideOptional_limit); + } + jobject Paging_nextTokenInsideOptional_after; + if (!dataResponse.paging.nextToken.Value().Value().after.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Paging_nextTokenInsideOptional_after); + } + else + { + jobject Paging_nextTokenInsideOptional_afterInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.paging.nextToken.Value().Value().after.Value(), + Paging_nextTokenInsideOptional_afterInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(Paging_nextTokenInsideOptional_afterInsideOptional, + Paging_nextTokenInsideOptional_after); + } + jobject Paging_nextTokenInsideOptional_before; + if (!dataResponse.paging.nextToken.Value().Value().before.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Paging_nextTokenInsideOptional_before); + } + else + { + jobject Paging_nextTokenInsideOptional_beforeInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.paging.nextToken.Value().Value().before.Value(), + Paging_nextTokenInsideOptional_beforeInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(Paging_nextTokenInsideOptional_beforeInsideOptional, + Paging_nextTokenInsideOptional_before); + } + + jclass pageTokenStructStructClass_3; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$ChannelClusterPageTokenStruct", pageTokenStructStructClass_3); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ChannelClusterPageTokenStruct"); + return; + } + + jmethodID pageTokenStructStructCtor_3; + err = chip::JniReferences::GetInstance().FindMethod(env, pageTokenStructStructClass_3, "", + "(Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;)V", + &pageTokenStructStructCtor_3); + if (err != CHIP_NO_ERROR || pageTokenStructStructCtor_3 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ChannelClusterPageTokenStruct constructor"); + return; + } + + Paging_nextTokenInsideOptional = + env->NewObject(pageTokenStructStructClass_3, pageTokenStructStructCtor_3, Paging_nextTokenInsideOptional_limit, + Paging_nextTokenInsideOptional_after, Paging_nextTokenInsideOptional_before); + } + chip::JniReferences::GetInstance().CreateOptional(Paging_nextTokenInsideOptional, Paging_nextToken); + } + + jclass channelPagingStructStructClass_0; + err = chip::JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/ChipStructs$ChannelClusterChannelPagingStruct", + channelPagingStructStructClass_0); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ChannelClusterChannelPagingStruct"); + return; + } + + jmethodID channelPagingStructStructCtor_0; + err = chip::JniReferences::GetInstance().FindMethod(env, channelPagingStructStructClass_0, "", + "(Ljava/util/Optional;Ljava/util/Optional;)V", + &channelPagingStructStructCtor_0); + if (err != CHIP_NO_ERROR || channelPagingStructStructCtor_0 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ChannelClusterChannelPagingStruct constructor"); + return; + } + + Paging = + env->NewObject(channelPagingStructStructClass_0, channelPagingStructStructCtor_0, Paging_previousToken, Paging_nextToken); + jobject ProgramList; + chip::JniReferences::GetInstance().CreateArrayList(ProgramList); + + auto iter_ProgramList_0 = dataResponse.programList.begin(); + while (iter_ProgramList_0.Next()) + { + auto & entry_0 = iter_ProgramList_0.GetValue(); + jobject newElement_0; + jobject newElement_0_identifier; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.identifier, newElement_0_identifier)); + jobject newElement_0_channel; + jobject newElement_0_channel_majorNumber; + std::string newElement_0_channel_majorNumberClassName = "java/lang/Integer"; + std::string newElement_0_channel_majorNumberCtorSignature = "(I)V"; + jint jninewElement_0_channel_majorNumber = static_cast(entry_0.channel.majorNumber); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_channel_majorNumberClassName.c_str(), newElement_0_channel_majorNumberCtorSignature.c_str(), + jninewElement_0_channel_majorNumber, newElement_0_channel_majorNumber); + jobject newElement_0_channel_minorNumber; + std::string newElement_0_channel_minorNumberClassName = "java/lang/Integer"; + std::string newElement_0_channel_minorNumberCtorSignature = "(I)V"; + jint jninewElement_0_channel_minorNumber = static_cast(entry_0.channel.minorNumber); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_channel_minorNumberClassName.c_str(), newElement_0_channel_minorNumberCtorSignature.c_str(), + jninewElement_0_channel_minorNumber, newElement_0_channel_minorNumber); + jobject newElement_0_channel_name; + if (!entry_0.channel.name.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_channel_name); + } + else + { + jobject newElement_0_channel_nameInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.channel.name.Value(), + newElement_0_channel_nameInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_channel_nameInsideOptional, newElement_0_channel_name); + } + jobject newElement_0_channel_callSign; + if (!entry_0.channel.callSign.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_channel_callSign); + } + else + { + jobject newElement_0_channel_callSignInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.channel.callSign.Value(), + newElement_0_channel_callSignInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_channel_callSignInsideOptional, + newElement_0_channel_callSign); + } + jobject newElement_0_channel_affiliateCallSign; + if (!entry_0.channel.affiliateCallSign.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_channel_affiliateCallSign); + } + else + { + jobject newElement_0_channel_affiliateCallSignInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF( + entry_0.channel.affiliateCallSign.Value(), newElement_0_channel_affiliateCallSignInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_channel_affiliateCallSignInsideOptional, + newElement_0_channel_affiliateCallSign); + } + jobject newElement_0_channel_identifier; + if (!entry_0.channel.identifier.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_channel_identifier); + } + else + { + jobject newElement_0_channel_identifierInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.channel.identifier.Value(), + newElement_0_channel_identifierInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_channel_identifierInsideOptional, + newElement_0_channel_identifier); + } + jobject newElement_0_channel_type; + if (!entry_0.channel.type.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_channel_type); + } + else + { + jobject newElement_0_channel_typeInsideOptional; + std::string newElement_0_channel_typeInsideOptionalClassName = "java/lang/Integer"; + std::string newElement_0_channel_typeInsideOptionalCtorSignature = "(I)V"; + jint jninewElement_0_channel_typeInsideOptional = static_cast(entry_0.channel.type.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0_channel_typeInsideOptionalClassName.c_str(), + newElement_0_channel_typeInsideOptionalCtorSignature.c_str(), + jninewElement_0_channel_typeInsideOptional, + newElement_0_channel_typeInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_channel_typeInsideOptional, newElement_0_channel_type); + } + + jclass channelInfoStructStructClass_2; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$ChannelClusterChannelInfoStruct", channelInfoStructStructClass_2); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ChannelClusterChannelInfoStruct"); + return; + } + + jmethodID channelInfoStructStructCtor_2; + err = + chip::JniReferences::GetInstance().FindMethod(env, channelInfoStructStructClass_2, "", + "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/" + "Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;)V", + &channelInfoStructStructCtor_2); + if (err != CHIP_NO_ERROR || channelInfoStructStructCtor_2 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ChannelClusterChannelInfoStruct constructor"); + return; + } + + newElement_0_channel = + env->NewObject(channelInfoStructStructClass_2, channelInfoStructStructCtor_2, newElement_0_channel_majorNumber, + newElement_0_channel_minorNumber, newElement_0_channel_name, newElement_0_channel_callSign, + newElement_0_channel_affiliateCallSign, newElement_0_channel_identifier, newElement_0_channel_type); + jobject newElement_0_startTime; + std::string newElement_0_startTimeClassName = "java/lang/Long"; + std::string newElement_0_startTimeCtorSignature = "(J)V"; + jlong jninewElement_0_startTime = static_cast(entry_0.startTime); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0_startTimeClassName.c_str(), + newElement_0_startTimeCtorSignature.c_str(), + jninewElement_0_startTime, newElement_0_startTime); + jobject newElement_0_endTime; + std::string newElement_0_endTimeClassName = "java/lang/Long"; + std::string newElement_0_endTimeCtorSignature = "(J)V"; + jlong jninewElement_0_endTime = static_cast(entry_0.endTime); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0_endTimeClassName.c_str(), + newElement_0_endTimeCtorSignature.c_str(), + jninewElement_0_endTime, newElement_0_endTime); + jobject newElement_0_title; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.title, newElement_0_title)); + jobject newElement_0_subtitle; + if (!entry_0.subtitle.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_subtitle); + } + else + { + jobject newElement_0_subtitleInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(entry_0.subtitle.Value(), newElement_0_subtitleInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_subtitleInsideOptional, newElement_0_subtitle); + } + jobject newElement_0_description; + if (!entry_0.description.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_description); + } + else + { + jobject newElement_0_descriptionInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.description.Value(), + newElement_0_descriptionInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_descriptionInsideOptional, newElement_0_description); + } + jobject newElement_0_audioLanguages; + if (!entry_0.audioLanguages.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_audioLanguages); + } + else + { + jobject newElement_0_audioLanguagesInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(newElement_0_audioLanguagesInsideOptional); + + auto iter_newElement_0_audioLanguagesInsideOptional_3 = entry_0.audioLanguages.Value().begin(); + while (iter_newElement_0_audioLanguagesInsideOptional_3.Next()) + { + auto & entry_3 = iter_newElement_0_audioLanguagesInsideOptional_3.GetValue(); + jobject newElement_3; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_3, newElement_3)); + chip::JniReferences::GetInstance().AddToList(newElement_0_audioLanguagesInsideOptional, newElement_3); + } + chip::JniReferences::GetInstance().CreateOptional(newElement_0_audioLanguagesInsideOptional, + newElement_0_audioLanguages); + } + jobject newElement_0_ratings; + if (!entry_0.ratings.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_ratings); + } + else + { + jobject newElement_0_ratingsInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(newElement_0_ratingsInsideOptional); + + auto iter_newElement_0_ratingsInsideOptional_3 = entry_0.ratings.Value().begin(); + while (iter_newElement_0_ratingsInsideOptional_3.Next()) + { + auto & entry_3 = iter_newElement_0_ratingsInsideOptional_3.GetValue(); + jobject newElement_3; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_3, newElement_3)); + chip::JniReferences::GetInstance().AddToList(newElement_0_ratingsInsideOptional, newElement_3); + } + chip::JniReferences::GetInstance().CreateOptional(newElement_0_ratingsInsideOptional, newElement_0_ratings); + } + jobject newElement_0_thumbnailUrl; + if (!entry_0.thumbnailUrl.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_thumbnailUrl); + } + else + { + jobject newElement_0_thumbnailUrlInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.thumbnailUrl.Value(), + newElement_0_thumbnailUrlInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_thumbnailUrlInsideOptional, newElement_0_thumbnailUrl); + } + jobject newElement_0_posterArtUrl; + if (!entry_0.posterArtUrl.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_posterArtUrl); + } + else + { + jobject newElement_0_posterArtUrlInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.posterArtUrl.Value(), + newElement_0_posterArtUrlInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_posterArtUrlInsideOptional, newElement_0_posterArtUrl); + } + jobject newElement_0_dvbiUrl; + if (!entry_0.dvbiUrl.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_dvbiUrl); + } + else + { + jobject newElement_0_dvbiUrlInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(entry_0.dvbiUrl.Value(), newElement_0_dvbiUrlInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_dvbiUrlInsideOptional, newElement_0_dvbiUrl); + } + jobject newElement_0_releaseDate; + if (!entry_0.releaseDate.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_releaseDate); + } + else + { + jobject newElement_0_releaseDateInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.releaseDate.Value(), + newElement_0_releaseDateInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_releaseDateInsideOptional, newElement_0_releaseDate); + } + jobject newElement_0_parentalGuidanceText; + if (!entry_0.parentalGuidanceText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_parentalGuidanceText); + } + else + { + jobject newElement_0_parentalGuidanceTextInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.parentalGuidanceText.Value(), + newElement_0_parentalGuidanceTextInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_parentalGuidanceTextInsideOptional, + newElement_0_parentalGuidanceText); + } + jobject newElement_0_recordingFlag; + if (!entry_0.recordingFlag.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_recordingFlag); + } + else + { + jobject newElement_0_recordingFlagInsideOptional; + std::string newElement_0_recordingFlagInsideOptionalClassName = "java/lang/Long"; + std::string newElement_0_recordingFlagInsideOptionalCtorSignature = "(J)V"; + jlong jninewElement_0_recordingFlagInsideOptional = static_cast(entry_0.recordingFlag.Value().Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_recordingFlagInsideOptionalClassName.c_str(), + newElement_0_recordingFlagInsideOptionalCtorSignature.c_str(), jninewElement_0_recordingFlagInsideOptional, + newElement_0_recordingFlagInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(newElement_0_recordingFlagInsideOptional, newElement_0_recordingFlag); + } + jobject newElement_0_seriesInfo; + if (!entry_0.seriesInfo.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_seriesInfo); + } + else + { + jobject newElement_0_seriesInfoInsideOptional; + if (entry_0.seriesInfo.Value().IsNull()) + { + newElement_0_seriesInfoInsideOptional = nullptr; + } + else + { + jobject newElement_0_seriesInfoInsideOptional_season; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.seriesInfo.Value().Value().season, + newElement_0_seriesInfoInsideOptional_season)); + jobject newElement_0_seriesInfoInsideOptional_episode; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF( + entry_0.seriesInfo.Value().Value().episode, newElement_0_seriesInfoInsideOptional_episode)); + + jclass seriesInfoStructStructClass_4; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$ChannelClusterSeriesInfoStruct", seriesInfoStructStructClass_4); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ChannelClusterSeriesInfoStruct"); + return; + } + + jmethodID seriesInfoStructStructCtor_4; + err = chip::JniReferences::GetInstance().FindMethod(env, seriesInfoStructStructClass_4, "", + "(Ljava/lang/String;Ljava/lang/String;)V", + &seriesInfoStructStructCtor_4); + if (err != CHIP_NO_ERROR || seriesInfoStructStructCtor_4 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ChannelClusterSeriesInfoStruct constructor"); + return; + } + + newElement_0_seriesInfoInsideOptional = + env->NewObject(seriesInfoStructStructClass_4, seriesInfoStructStructCtor_4, + newElement_0_seriesInfoInsideOptional_season, newElement_0_seriesInfoInsideOptional_episode); + } + chip::JniReferences::GetInstance().CreateOptional(newElement_0_seriesInfoInsideOptional, newElement_0_seriesInfo); + } + jobject newElement_0_categoryList; + if (!entry_0.categoryList.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_categoryList); + } + else + { + jobject newElement_0_categoryListInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(newElement_0_categoryListInsideOptional); + + auto iter_newElement_0_categoryListInsideOptional_3 = entry_0.categoryList.Value().begin(); + while (iter_newElement_0_categoryListInsideOptional_3.Next()) + { + auto & entry_3 = iter_newElement_0_categoryListInsideOptional_3.GetValue(); + jobject newElement_3; + jobject newElement_3_category; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_3.category, newElement_3_category)); + jobject newElement_3_subCategory; + if (!entry_3.subCategory.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_3_subCategory); + } + else + { + jobject newElement_3_subCategoryInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_3.subCategory.Value(), + newElement_3_subCategoryInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(newElement_3_subCategoryInsideOptional, + newElement_3_subCategory); + } + + jclass programCategoryStructStructClass_4; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$ChannelClusterProgramCategoryStruct", + programCategoryStructStructClass_4); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ChannelClusterProgramCategoryStruct"); + return; + } + + jmethodID programCategoryStructStructCtor_4; + err = chip::JniReferences::GetInstance().FindMethod(env, programCategoryStructStructClass_4, "", + "(Ljava/lang/String;Ljava/util/Optional;)V", + &programCategoryStructStructCtor_4); + if (err != CHIP_NO_ERROR || programCategoryStructStructCtor_4 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ChannelClusterProgramCategoryStruct constructor"); + return; + } + + newElement_3 = env->NewObject(programCategoryStructStructClass_4, programCategoryStructStructCtor_4, + newElement_3_category, newElement_3_subCategory); + chip::JniReferences::GetInstance().AddToList(newElement_0_categoryListInsideOptional, newElement_3); + } + chip::JniReferences::GetInstance().CreateOptional(newElement_0_categoryListInsideOptional, newElement_0_categoryList); + } + jobject newElement_0_castList; + if (!entry_0.castList.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_castList); + } + else + { + jobject newElement_0_castListInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(newElement_0_castListInsideOptional); + + auto iter_newElement_0_castListInsideOptional_3 = entry_0.castList.Value().begin(); + while (iter_newElement_0_castListInsideOptional_3.Next()) + { + auto & entry_3 = iter_newElement_0_castListInsideOptional_3.GetValue(); + jobject newElement_3; + jobject newElement_3_name; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_3.name, newElement_3_name)); + jobject newElement_3_role; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_3.role, newElement_3_role)); + + jclass programCastStructStructClass_4; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$ChannelClusterProgramCastStruct", programCastStructStructClass_4); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ChannelClusterProgramCastStruct"); + return; + } + + jmethodID programCastStructStructCtor_4; + err = chip::JniReferences::GetInstance().FindMethod(env, programCastStructStructClass_4, "", + "(Ljava/lang/String;Ljava/lang/String;)V", + &programCastStructStructCtor_4); + if (err != CHIP_NO_ERROR || programCastStructStructCtor_4 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ChannelClusterProgramCastStruct constructor"); + return; + } + + newElement_3 = env->NewObject(programCastStructStructClass_4, programCastStructStructCtor_4, newElement_3_name, + newElement_3_role); + chip::JniReferences::GetInstance().AddToList(newElement_0_castListInsideOptional, newElement_3); + } + chip::JniReferences::GetInstance().CreateOptional(newElement_0_castListInsideOptional, newElement_0_castList); + } + jobject newElement_0_externalIDList; + if (!entry_0.externalIDList.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, newElement_0_externalIDList); + } + else + { + jobject newElement_0_externalIDListInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(newElement_0_externalIDListInsideOptional); + + auto iter_newElement_0_externalIDListInsideOptional_3 = entry_0.externalIDList.Value().begin(); + while (iter_newElement_0_externalIDListInsideOptional_3.Next()) + { + auto & entry_3 = iter_newElement_0_externalIDListInsideOptional_3.GetValue(); + jobject newElement_3; + jobject newElement_3_name; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_3.name, newElement_3_name)); + jobject newElement_3_role; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_3.role, newElement_3_role)); + + jclass programCastStructStructClass_4; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$ChannelClusterProgramCastStruct", programCastStructStructClass_4); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ChannelClusterProgramCastStruct"); + return; + } + + jmethodID programCastStructStructCtor_4; + err = chip::JniReferences::GetInstance().FindMethod(env, programCastStructStructClass_4, "", + "(Ljava/lang/String;Ljava/lang/String;)V", + &programCastStructStructCtor_4); + if (err != CHIP_NO_ERROR || programCastStructStructCtor_4 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ChannelClusterProgramCastStruct constructor"); + return; + } + + newElement_3 = env->NewObject(programCastStructStructClass_4, programCastStructStructCtor_4, newElement_3_name, + newElement_3_role); + chip::JniReferences::GetInstance().AddToList(newElement_0_externalIDListInsideOptional, newElement_3); + } + chip::JniReferences::GetInstance().CreateOptional(newElement_0_externalIDListInsideOptional, + newElement_0_externalIDList); + } + + jclass programStructStructClass_1; + err = chip::JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/ChipStructs$ChannelClusterProgramStruct", + programStructStructClass_1); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$ChannelClusterProgramStruct"); + return; + } + + jmethodID programStructStructCtor_1; + err = chip::JniReferences::GetInstance().FindMethod( + env, programStructStructClass_1, "", + "(Ljava/lang/String;Lchip/devicecontroller/ChipStructs$ChannelClusterChannelInfoStruct;Ljava/lang/Long;Ljava/lang/" + "Long;Ljava/lang/String;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/" + "Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/" + "util/Optional;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;)V", + &programStructStructCtor_1); + if (err != CHIP_NO_ERROR || programStructStructCtor_1 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$ChannelClusterProgramStruct constructor"); + return; + } + + newElement_0 = env->NewObject( + programStructStructClass_1, programStructStructCtor_1, newElement_0_identifier, newElement_0_channel, + newElement_0_startTime, newElement_0_endTime, newElement_0_title, newElement_0_subtitle, newElement_0_description, + newElement_0_audioLanguages, newElement_0_ratings, newElement_0_thumbnailUrl, newElement_0_posterArtUrl, + newElement_0_dvbiUrl, newElement_0_releaseDate, newElement_0_parentalGuidanceText, newElement_0_recordingFlag, + newElement_0_seriesInfo, newElement_0_categoryList, newElement_0_castList, newElement_0_externalIDList); + chip::JniReferences::GetInstance().AddToList(ProgramList, newElement_0); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Paging, ProgramList); +} +CHIPTargetNavigatorClusterNavigateTargetResponseCallback::CHIPTargetNavigatorClusterNavigateTargetResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPTargetNavigatorClusterNavigateTargetResponseCallback::~CHIPTargetNavigatorClusterNavigateTargetResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPTargetNavigatorClusterNavigateTargetResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::TargetNavigator::Commands::NavigateTargetResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject Data; + if (!dataResponse.data.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Data); + } + else + { + jobject DataInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.data.Value(), DataInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(DataInsideOptional, Data); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, Data); +} +CHIPMediaPlaybackClusterPlaybackResponseCallback::CHIPMediaPlaybackClusterPlaybackResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPMediaPlaybackClusterPlaybackResponseCallback::~CHIPMediaPlaybackClusterPlaybackResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPMediaPlaybackClusterPlaybackResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject Data; + if (!dataResponse.data.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Data); + } + else + { + jobject DataInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.data.Value(), DataInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(DataInsideOptional, Data); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, Data); +} +CHIPKeypadInputClusterSendKeyResponseCallback::CHIPKeypadInputClusterSendKeyResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPKeypadInputClusterSendKeyResponseCallback::~CHIPKeypadInputClusterSendKeyResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPKeypadInputClusterSendKeyResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::KeypadInput::Commands::SendKeyResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status); +} +CHIPContentLauncherClusterLauncherResponseCallback::CHIPContentLauncherClusterLauncherResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPContentLauncherClusterLauncherResponseCallback::~CHIPContentLauncherClusterLauncherResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPContentLauncherClusterLauncherResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ContentLauncher::Commands::LauncherResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject Data; + if (!dataResponse.data.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Data); + } + else + { + jobject DataInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.data.Value(), DataInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(DataInsideOptional, Data); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, Data); +} +CHIPApplicationLauncherClusterLauncherResponseCallback::CHIPApplicationLauncherClusterLauncherResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPApplicationLauncherClusterLauncherResponseCallback::~CHIPApplicationLauncherClusterLauncherResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPApplicationLauncherClusterLauncherResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ApplicationLauncher::Commands::LauncherResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject Data; + if (!dataResponse.data.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Data); + } + else + { + jobject DataInsideOptional; + jbyteArray DataInsideOptionalByteArray = env->NewByteArray(static_cast(dataResponse.data.Value().size())); + env->SetByteArrayRegion(DataInsideOptionalByteArray, 0, static_cast(dataResponse.data.Value().size()), + reinterpret_cast(dataResponse.data.Value().data())); + DataInsideOptional = DataInsideOptionalByteArray; + chip::JniReferences::GetInstance().CreateOptional(DataInsideOptional, Data); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, Data); +} +CHIPAccountLoginClusterGetSetupPINResponseCallback::CHIPAccountLoginClusterGetSetupPINResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPAccountLoginClusterGetSetupPINResponseCallback::~CHIPAccountLoginClusterGetSetupPINResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPAccountLoginClusterGetSetupPINResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::AccountLogin::Commands::GetSetupPINResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/String;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject SetupPIN; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.setupPIN, SetupPIN)); + + env->CallVoidMethod(javaCallbackRef, javaMethod, SetupPIN); +} +CHIPContentControlClusterResetPINResponseCallback::CHIPContentControlClusterResetPINResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPContentControlClusterResetPINResponseCallback::~CHIPContentControlClusterResetPINResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPContentControlClusterResetPINResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::ContentControl::Commands::ResetPINResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/String;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject PINCode; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.PINCode, PINCode)); + + env->CallVoidMethod(javaCallbackRef, javaMethod, PINCode); +} +CHIPContentAppObserverClusterContentAppMessageResponseCallback::CHIPContentAppObserverClusterContentAppMessageResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPContentAppObserverClusterContentAppMessageResponseCallback::~CHIPContentAppObserverClusterContentAppMessageResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPContentAppObserverClusterContentAppMessageResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::ContentAppObserver::Commands::ContentAppMessageResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject Status; + std::string StatusClassName = "java/lang/Integer"; + std::string StatusCtorSignature = "(I)V"; + jint jniStatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(StatusClassName.c_str(), StatusCtorSignature.c_str(), jniStatus, + Status); + jobject Data; + if (!dataResponse.data.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, Data); + } + else + { + jobject DataInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.data.Value(), DataInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(DataInsideOptional, Data); + } + jobject EncodingHint; + if (!dataResponse.encodingHint.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, EncodingHint); + } + else + { + jobject EncodingHintInsideOptional; + LogErrorOnFailure( + chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.encodingHint.Value(), EncodingHintInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(EncodingHintInsideOptional, EncodingHint); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, Status, Data, EncodingHint); +} +CHIPElectricalMeasurementClusterGetProfileInfoResponseCommandCallback:: +CHIPElectricalMeasurementClusterGetProfileInfoResponseCommandCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPElectricalMeasurementClusterGetProfileInfoResponseCommandCallback::~ +CHIPElectricalMeasurementClusterGetProfileInfoResponseCommandCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPElectricalMeasurementClusterGetProfileInfoResponseCommandCallback::CallbackFn( + void * context, + const chip::app::Clusters::ElectricalMeasurement::Commands::GetProfileInfoResponseCommand::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/ArrayList;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject profileCount; + std::string profileCountClassName = "java/lang/Integer"; + std::string profileCountCtorSignature = "(I)V"; + jint jniprofileCount = static_cast(dataResponse.profileCount); + chip::JniReferences::GetInstance().CreateBoxedObject(profileCountClassName.c_str(), profileCountCtorSignature.c_str(), + jniprofileCount, profileCount); + jobject profileIntervalPeriod; + std::string profileIntervalPeriodClassName = "java/lang/Integer"; + std::string profileIntervalPeriodCtorSignature = "(I)V"; + jint jniprofileIntervalPeriod = static_cast(dataResponse.profileIntervalPeriod); + chip::JniReferences::GetInstance().CreateBoxedObject(profileIntervalPeriodClassName.c_str(), + profileIntervalPeriodCtorSignature.c_str(), jniprofileIntervalPeriod, + profileIntervalPeriod); + jobject maxNumberOfIntervals; + std::string maxNumberOfIntervalsClassName = "java/lang/Integer"; + std::string maxNumberOfIntervalsCtorSignature = "(I)V"; + jint jnimaxNumberOfIntervals = static_cast(dataResponse.maxNumberOfIntervals); + chip::JniReferences::GetInstance().CreateBoxedObject(maxNumberOfIntervalsClassName.c_str(), + maxNumberOfIntervalsCtorSignature.c_str(), jnimaxNumberOfIntervals, + maxNumberOfIntervals); + jobject listOfAttributes; + chip::JniReferences::GetInstance().CreateArrayList(listOfAttributes); + + auto iter_listOfAttributes_0 = dataResponse.listOfAttributes.begin(); + while (iter_listOfAttributes_0.Next()) + { + auto & entry_0 = iter_listOfAttributes_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + jint jninewElement_0 = static_cast(entry_0); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), + jninewElement_0, newElement_0); + chip::JniReferences::GetInstance().AddToList(listOfAttributes, newElement_0); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, profileCount, profileIntervalPeriod, maxNumberOfIntervals, listOfAttributes); +} +CHIPElectricalMeasurementClusterGetMeasurementProfileResponseCommandCallback:: +CHIPElectricalMeasurementClusterGetMeasurementProfileResponseCommandCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPElectricalMeasurementClusterGetMeasurementProfileResponseCommandCallback::~ +CHIPElectricalMeasurementClusterGetMeasurementProfileResponseCommandCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPElectricalMeasurementClusterGetMeasurementProfileResponseCommandCallback::CallbackFn( + void * context, + const chip::app::Clusters::ElectricalMeasurement::Commands::GetMeasurementProfileResponseCommand::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Long;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/ArrayList;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject startTime; + std::string startTimeClassName = "java/lang/Long"; + std::string startTimeCtorSignature = "(J)V"; + jlong jnistartTime = static_cast(dataResponse.startTime); + chip::JniReferences::GetInstance().CreateBoxedObject(startTimeClassName.c_str(), startTimeCtorSignature.c_str(), + jnistartTime, startTime); + jobject status; + std::string statusClassName = "java/lang/Integer"; + std::string statusCtorSignature = "(I)V"; + jint jnistatus = static_cast(dataResponse.status); + chip::JniReferences::GetInstance().CreateBoxedObject(statusClassName.c_str(), statusCtorSignature.c_str(), jnistatus, + status); + jobject profileIntervalPeriod; + std::string profileIntervalPeriodClassName = "java/lang/Integer"; + std::string profileIntervalPeriodCtorSignature = "(I)V"; + jint jniprofileIntervalPeriod = static_cast(dataResponse.profileIntervalPeriod); + chip::JniReferences::GetInstance().CreateBoxedObject(profileIntervalPeriodClassName.c_str(), + profileIntervalPeriodCtorSignature.c_str(), jniprofileIntervalPeriod, + profileIntervalPeriod); + jobject numberOfIntervalsDelivered; + std::string numberOfIntervalsDeliveredClassName = "java/lang/Integer"; + std::string numberOfIntervalsDeliveredCtorSignature = "(I)V"; + jint jninumberOfIntervalsDelivered = static_cast(dataResponse.numberOfIntervalsDelivered); + chip::JniReferences::GetInstance().CreateBoxedObject(numberOfIntervalsDeliveredClassName.c_str(), + numberOfIntervalsDeliveredCtorSignature.c_str(), + jninumberOfIntervalsDelivered, numberOfIntervalsDelivered); + jobject attributeId; + std::string attributeIdClassName = "java/lang/Integer"; + std::string attributeIdCtorSignature = "(I)V"; + jint jniattributeId = static_cast(dataResponse.attributeId); + chip::JniReferences::GetInstance().CreateBoxedObject(attributeIdClassName.c_str(), attributeIdCtorSignature.c_str(), + jniattributeId, attributeId); + jobject intervals; + chip::JniReferences::GetInstance().CreateArrayList(intervals); + + auto iter_intervals_0 = dataResponse.intervals.begin(); + while (iter_intervals_0.Next()) + { + auto & entry_0 = iter_intervals_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + jint jninewElement_0 = static_cast(entry_0); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), + jninewElement_0, newElement_0); + chip::JniReferences::GetInstance().AddToList(intervals, newElement_0); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, startTime, status, profileIntervalPeriod, numberOfIntervalsDelivered, + attributeId, intervals); +} +CHIPUnitTestingClusterTestSpecificResponseCallback::CHIPUnitTestingClusterTestSpecificResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestSpecificResponseCallback::~CHIPUnitTestingClusterTestSpecificResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestSpecificResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::TestSpecificResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject returnValue; + std::string returnValueClassName = "java/lang/Integer"; + std::string returnValueCtorSignature = "(I)V"; + jint jnireturnValue = static_cast(dataResponse.returnValue); + chip::JniReferences::GetInstance().CreateBoxedObject(returnValueClassName.c_str(), returnValueCtorSignature.c_str(), + jnireturnValue, returnValue); + + env->CallVoidMethod(javaCallbackRef, javaMethod, returnValue); +} +CHIPUnitTestingClusterTestAddArgumentsResponseCallback::CHIPUnitTestingClusterTestAddArgumentsResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestAddArgumentsResponseCallback::~CHIPUnitTestingClusterTestAddArgumentsResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestAddArgumentsResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::TestAddArgumentsResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject returnValue; + std::string returnValueClassName = "java/lang/Integer"; + std::string returnValueCtorSignature = "(I)V"; + jint jnireturnValue = static_cast(dataResponse.returnValue); + chip::JniReferences::GetInstance().CreateBoxedObject(returnValueClassName.c_str(), returnValueCtorSignature.c_str(), + jnireturnValue, returnValue); + + env->CallVoidMethod(javaCallbackRef, javaMethod, returnValue); +} +CHIPUnitTestingClusterTestSimpleArgumentResponseCallback::CHIPUnitTestingClusterTestSimpleArgumentResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestSimpleArgumentResponseCallback::~CHIPUnitTestingClusterTestSimpleArgumentResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestSimpleArgumentResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::TestSimpleArgumentResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Boolean;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject returnValue; + std::string returnValueClassName = "java/lang/Boolean"; + std::string returnValueCtorSignature = "(Z)V"; + jboolean jnireturnValue = static_cast(dataResponse.returnValue); + chip::JniReferences::GetInstance().CreateBoxedObject(returnValueClassName.c_str(), returnValueCtorSignature.c_str(), + jnireturnValue, returnValue); + + env->CallVoidMethod(javaCallbackRef, javaMethod, returnValue); +} +CHIPUnitTestingClusterTestStructArrayArgumentResponseCallback::CHIPUnitTestingClusterTestStructArrayArgumentResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestStructArrayArgumentResponseCallback::~CHIPUnitTestingClusterTestStructArrayArgumentResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestStructArrayArgumentResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::TestStructArrayArgumentResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/util/ArrayList;Ljava/util/ArrayList;Ljava/util/ArrayList;Ljava/util/" + "ArrayList;Ljava/lang/Integer;Ljava/lang/Boolean;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject arg1; + chip::JniReferences::GetInstance().CreateArrayList(arg1); + + auto iter_arg1_0 = dataResponse.arg1.begin(); + while (iter_arg1_0.Next()) + { + auto & entry_0 = iter_arg1_0.GetValue(); + jobject newElement_0; + jobject newElement_0_a; + std::string newElement_0_aClassName = "java/lang/Integer"; + std::string newElement_0_aCtorSignature = "(I)V"; + jint jninewElement_0_a = static_cast(entry_0.a); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_aClassName.c_str(), newElement_0_aCtorSignature.c_str(), jninewElement_0_a, newElement_0_a); + jobject newElement_0_b; + std::string newElement_0_bClassName = "java/lang/Boolean"; + std::string newElement_0_bCtorSignature = "(Z)V"; + jboolean jninewElement_0_b = static_cast(entry_0.b); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_bClassName.c_str(), newElement_0_bCtorSignature.c_str(), jninewElement_0_b, newElement_0_b); + jobject newElement_0_c; + jobject newElement_0_c_a; + std::string newElement_0_c_aClassName = "java/lang/Integer"; + std::string newElement_0_c_aCtorSignature = "(I)V"; + jint jninewElement_0_c_a = static_cast(entry_0.c.a); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_c_aClassName.c_str(), newElement_0_c_aCtorSignature.c_str(), jninewElement_0_c_a, newElement_0_c_a); + jobject newElement_0_c_b; + std::string newElement_0_c_bClassName = "java/lang/Boolean"; + std::string newElement_0_c_bCtorSignature = "(Z)V"; + jboolean jninewElement_0_c_b = static_cast(entry_0.c.b); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_c_bClassName.c_str(), newElement_0_c_bCtorSignature.c_str(), jninewElement_0_c_b, newElement_0_c_b); + jobject newElement_0_c_c; + std::string newElement_0_c_cClassName = "java/lang/Integer"; + std::string newElement_0_c_cCtorSignature = "(I)V"; + jint jninewElement_0_c_c = static_cast(entry_0.c.c); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_c_cClassName.c_str(), newElement_0_c_cCtorSignature.c_str(), jninewElement_0_c_c, newElement_0_c_c); + jobject newElement_0_c_d; + jbyteArray newElement_0_c_dByteArray = env->NewByteArray(static_cast(entry_0.c.d.size())); + env->SetByteArrayRegion(newElement_0_c_dByteArray, 0, static_cast(entry_0.c.d.size()), + reinterpret_cast(entry_0.c.d.data())); + newElement_0_c_d = newElement_0_c_dByteArray; + jobject newElement_0_c_e; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.c.e, newElement_0_c_e)); + jobject newElement_0_c_f; + std::string newElement_0_c_fClassName = "java/lang/Integer"; + std::string newElement_0_c_fCtorSignature = "(I)V"; + jint jninewElement_0_c_f = static_cast(entry_0.c.f.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_c_fClassName.c_str(), newElement_0_c_fCtorSignature.c_str(), jninewElement_0_c_f, newElement_0_c_f); + jobject newElement_0_c_g; + std::string newElement_0_c_gClassName = "java/lang/Float"; + std::string newElement_0_c_gCtorSignature = "(F)V"; + jfloat jninewElement_0_c_g = static_cast(entry_0.c.g); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_c_gClassName.c_str(), newElement_0_c_gCtorSignature.c_str(), jninewElement_0_c_g, newElement_0_c_g); + jobject newElement_0_c_h; + std::string newElement_0_c_hClassName = "java/lang/Double"; + std::string newElement_0_c_hCtorSignature = "(D)V"; + jdouble jninewElement_0_c_h = static_cast(entry_0.c.h); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_c_hClassName.c_str(), newElement_0_c_hCtorSignature.c_str(), jninewElement_0_c_h, newElement_0_c_h); + + jclass simpleStructStructClass_2; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$UnitTestingClusterSimpleStruct", simpleStructStructClass_2); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$UnitTestingClusterSimpleStruct"); + return; + } + + jmethodID simpleStructStructCtor_2; + err = chip::JniReferences::GetInstance().FindMethod(env, simpleStructStructClass_2, "", + "(Ljava/lang/Integer;Ljava/lang/Boolean;Ljava/lang/Integer;[BLjava/" + "lang/String;Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Double;)V", + &simpleStructStructCtor_2); + if (err != CHIP_NO_ERROR || simpleStructStructCtor_2 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$UnitTestingClusterSimpleStruct constructor"); + return; + } + + newElement_0_c = env->NewObject(simpleStructStructClass_2, simpleStructStructCtor_2, newElement_0_c_a, newElement_0_c_b, + newElement_0_c_c, newElement_0_c_d, newElement_0_c_e, newElement_0_c_f, newElement_0_c_g, + newElement_0_c_h); + jobject newElement_0_d; + chip::JniReferences::GetInstance().CreateArrayList(newElement_0_d); + + auto iter_newElement_0_d_2 = entry_0.d.begin(); + while (iter_newElement_0_d_2.Next()) + { + auto & entry_2 = iter_newElement_0_d_2.GetValue(); + jobject newElement_2; + jobject newElement_2_a; + std::string newElement_2_aClassName = "java/lang/Integer"; + std::string newElement_2_aCtorSignature = "(I)V"; + jint jninewElement_2_a = static_cast(entry_2.a); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_2_aClassName.c_str(), newElement_2_aCtorSignature.c_str(), jninewElement_2_a, newElement_2_a); + jobject newElement_2_b; + std::string newElement_2_bClassName = "java/lang/Boolean"; + std::string newElement_2_bCtorSignature = "(Z)V"; + jboolean jninewElement_2_b = static_cast(entry_2.b); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_2_bClassName.c_str(), newElement_2_bCtorSignature.c_str(), jninewElement_2_b, newElement_2_b); + jobject newElement_2_c; + std::string newElement_2_cClassName = "java/lang/Integer"; + std::string newElement_2_cCtorSignature = "(I)V"; + jint jninewElement_2_c = static_cast(entry_2.c); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_2_cClassName.c_str(), newElement_2_cCtorSignature.c_str(), jninewElement_2_c, newElement_2_c); + jobject newElement_2_d; + jbyteArray newElement_2_dByteArray = env->NewByteArray(static_cast(entry_2.d.size())); + env->SetByteArrayRegion(newElement_2_dByteArray, 0, static_cast(entry_2.d.size()), + reinterpret_cast(entry_2.d.data())); + newElement_2_d = newElement_2_dByteArray; + jobject newElement_2_e; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_2.e, newElement_2_e)); + jobject newElement_2_f; + std::string newElement_2_fClassName = "java/lang/Integer"; + std::string newElement_2_fCtorSignature = "(I)V"; + jint jninewElement_2_f = static_cast(entry_2.f.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_2_fClassName.c_str(), newElement_2_fCtorSignature.c_str(), jninewElement_2_f, newElement_2_f); + jobject newElement_2_g; + std::string newElement_2_gClassName = "java/lang/Float"; + std::string newElement_2_gCtorSignature = "(F)V"; + jfloat jninewElement_2_g = static_cast(entry_2.g); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_2_gClassName.c_str(), newElement_2_gCtorSignature.c_str(), jninewElement_2_g, newElement_2_g); + jobject newElement_2_h; + std::string newElement_2_hClassName = "java/lang/Double"; + std::string newElement_2_hCtorSignature = "(D)V"; + jdouble jninewElement_2_h = static_cast(entry_2.h); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_2_hClassName.c_str(), newElement_2_hCtorSignature.c_str(), jninewElement_2_h, newElement_2_h); + + jclass simpleStructStructClass_3; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$UnitTestingClusterSimpleStruct", simpleStructStructClass_3); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$UnitTestingClusterSimpleStruct"); + return; + } + + jmethodID simpleStructStructCtor_3; + err = chip::JniReferences::GetInstance().FindMethod( + env, simpleStructStructClass_3, "", + "(Ljava/lang/Integer;Ljava/lang/Boolean;Ljava/lang/Integer;[BLjava/lang/String;Ljava/lang/Integer;Ljava/lang/" + "Float;Ljava/lang/Double;)V", + &simpleStructStructCtor_3); + if (err != CHIP_NO_ERROR || simpleStructStructCtor_3 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$UnitTestingClusterSimpleStruct constructor"); + return; + } + + newElement_2 = + env->NewObject(simpleStructStructClass_3, simpleStructStructCtor_3, newElement_2_a, newElement_2_b, newElement_2_c, + newElement_2_d, newElement_2_e, newElement_2_f, newElement_2_g, newElement_2_h); + chip::JniReferences::GetInstance().AddToList(newElement_0_d, newElement_2); + } + jobject newElement_0_e; + chip::JniReferences::GetInstance().CreateArrayList(newElement_0_e); + + auto iter_newElement_0_e_2 = entry_0.e.begin(); + while (iter_newElement_0_e_2.Next()) + { + auto & entry_2 = iter_newElement_0_e_2.GetValue(); + jobject newElement_2; + std::string newElement_2ClassName = "java/lang/Long"; + std::string newElement_2CtorSignature = "(J)V"; + jlong jninewElement_2 = static_cast(entry_2); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_2ClassName.c_str(), newElement_2CtorSignature.c_str(), jninewElement_2, newElement_2); + chip::JniReferences::GetInstance().AddToList(newElement_0_e, newElement_2); + } + jobject newElement_0_f; + chip::JniReferences::GetInstance().CreateArrayList(newElement_0_f); + + auto iter_newElement_0_f_2 = entry_0.f.begin(); + while (iter_newElement_0_f_2.Next()) + { + auto & entry_2 = iter_newElement_0_f_2.GetValue(); + jobject newElement_2; + jbyteArray newElement_2ByteArray = env->NewByteArray(static_cast(entry_2.size())); + env->SetByteArrayRegion(newElement_2ByteArray, 0, static_cast(entry_2.size()), + reinterpret_cast(entry_2.data())); + newElement_2 = newElement_2ByteArray; + chip::JniReferences::GetInstance().AddToList(newElement_0_f, newElement_2); + } + jobject newElement_0_g; + chip::JniReferences::GetInstance().CreateArrayList(newElement_0_g); + + auto iter_newElement_0_g_2 = entry_0.g.begin(); + while (iter_newElement_0_g_2.Next()) + { + auto & entry_2 = iter_newElement_0_g_2.GetValue(); + jobject newElement_2; + std::string newElement_2ClassName = "java/lang/Integer"; + std::string newElement_2CtorSignature = "(I)V"; + jint jninewElement_2 = static_cast(entry_2); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_2ClassName.c_str(), newElement_2CtorSignature.c_str(), jninewElement_2, newElement_2); + chip::JniReferences::GetInstance().AddToList(newElement_0_g, newElement_2); + } + + jclass nestedStructListStructClass_1; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$UnitTestingClusterNestedStructList", nestedStructListStructClass_1); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$UnitTestingClusterNestedStructList"); + return; + } + + jmethodID nestedStructListStructCtor_1; + err = chip::JniReferences::GetInstance().FindMethod( + env, nestedStructListStructClass_1, "", + "(Ljava/lang/Integer;Ljava/lang/Boolean;Lchip/devicecontroller/ChipStructs$UnitTestingClusterSimpleStruct;Ljava/util/" + "ArrayList;Ljava/util/ArrayList;Ljava/util/ArrayList;Ljava/util/ArrayList;)V", + &nestedStructListStructCtor_1); + if (err != CHIP_NO_ERROR || nestedStructListStructCtor_1 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$UnitTestingClusterNestedStructList constructor"); + return; + } + + newElement_0 = env->NewObject(nestedStructListStructClass_1, nestedStructListStructCtor_1, newElement_0_a, newElement_0_b, + newElement_0_c, newElement_0_d, newElement_0_e, newElement_0_f, newElement_0_g); + chip::JniReferences::GetInstance().AddToList(arg1, newElement_0); + } + jobject arg2; + chip::JniReferences::GetInstance().CreateArrayList(arg2); + + auto iter_arg2_0 = dataResponse.arg2.begin(); + while (iter_arg2_0.Next()) + { + auto & entry_0 = iter_arg2_0.GetValue(); + jobject newElement_0; + jobject newElement_0_a; + std::string newElement_0_aClassName = "java/lang/Integer"; + std::string newElement_0_aCtorSignature = "(I)V"; + jint jninewElement_0_a = static_cast(entry_0.a); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_aClassName.c_str(), newElement_0_aCtorSignature.c_str(), jninewElement_0_a, newElement_0_a); + jobject newElement_0_b; + std::string newElement_0_bClassName = "java/lang/Boolean"; + std::string newElement_0_bCtorSignature = "(Z)V"; + jboolean jninewElement_0_b = static_cast(entry_0.b); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_bClassName.c_str(), newElement_0_bCtorSignature.c_str(), jninewElement_0_b, newElement_0_b); + jobject newElement_0_c; + std::string newElement_0_cClassName = "java/lang/Integer"; + std::string newElement_0_cCtorSignature = "(I)V"; + jint jninewElement_0_c = static_cast(entry_0.c); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_cClassName.c_str(), newElement_0_cCtorSignature.c_str(), jninewElement_0_c, newElement_0_c); + jobject newElement_0_d; + jbyteArray newElement_0_dByteArray = env->NewByteArray(static_cast(entry_0.d.size())); + env->SetByteArrayRegion(newElement_0_dByteArray, 0, static_cast(entry_0.d.size()), + reinterpret_cast(entry_0.d.data())); + newElement_0_d = newElement_0_dByteArray; + jobject newElement_0_e; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(entry_0.e, newElement_0_e)); + jobject newElement_0_f; + std::string newElement_0_fClassName = "java/lang/Integer"; + std::string newElement_0_fCtorSignature = "(I)V"; + jint jninewElement_0_f = static_cast(entry_0.f.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_fClassName.c_str(), newElement_0_fCtorSignature.c_str(), jninewElement_0_f, newElement_0_f); + jobject newElement_0_g; + std::string newElement_0_gClassName = "java/lang/Float"; + std::string newElement_0_gCtorSignature = "(F)V"; + jfloat jninewElement_0_g = static_cast(entry_0.g); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_gClassName.c_str(), newElement_0_gCtorSignature.c_str(), jninewElement_0_g, newElement_0_g); + jobject newElement_0_h; + std::string newElement_0_hClassName = "java/lang/Double"; + std::string newElement_0_hCtorSignature = "(D)V"; + jdouble jninewElement_0_h = static_cast(entry_0.h); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0_hClassName.c_str(), newElement_0_hCtorSignature.c_str(), jninewElement_0_h, newElement_0_h); + + jclass simpleStructStructClass_1; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$UnitTestingClusterSimpleStruct", simpleStructStructClass_1); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$UnitTestingClusterSimpleStruct"); + return; + } + + jmethodID simpleStructStructCtor_1; + err = chip::JniReferences::GetInstance().FindMethod(env, simpleStructStructClass_1, "", + "(Ljava/lang/Integer;Ljava/lang/Boolean;Ljava/lang/Integer;[BLjava/" + "lang/String;Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Double;)V", + &simpleStructStructCtor_1); + if (err != CHIP_NO_ERROR || simpleStructStructCtor_1 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$UnitTestingClusterSimpleStruct constructor"); + return; + } + + newElement_0 = + env->NewObject(simpleStructStructClass_1, simpleStructStructCtor_1, newElement_0_a, newElement_0_b, newElement_0_c, + newElement_0_d, newElement_0_e, newElement_0_f, newElement_0_g, newElement_0_h); + chip::JniReferences::GetInstance().AddToList(arg2, newElement_0); + } + jobject arg3; + chip::JniReferences::GetInstance().CreateArrayList(arg3); + + auto iter_arg3_0 = dataResponse.arg3.begin(); + while (iter_arg3_0.Next()) + { + auto & entry_0 = iter_arg3_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + jint jninewElement_0 = static_cast(entry_0); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), + jninewElement_0, newElement_0); + chip::JniReferences::GetInstance().AddToList(arg3, newElement_0); + } + jobject arg4; + chip::JniReferences::GetInstance().CreateArrayList(arg4); + + auto iter_arg4_0 = dataResponse.arg4.begin(); + while (iter_arg4_0.Next()) + { + auto & entry_0 = iter_arg4_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Boolean"; + std::string newElement_0CtorSignature = "(Z)V"; + jboolean jninewElement_0 = static_cast(entry_0); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), jninewElement_0, newElement_0); + chip::JniReferences::GetInstance().AddToList(arg4, newElement_0); + } + jobject arg5; + std::string arg5ClassName = "java/lang/Integer"; + std::string arg5CtorSignature = "(I)V"; + jint jniarg5 = static_cast(dataResponse.arg5); + chip::JniReferences::GetInstance().CreateBoxedObject(arg5ClassName.c_str(), arg5CtorSignature.c_str(), jniarg5, arg5); + jobject arg6; + std::string arg6ClassName = "java/lang/Boolean"; + std::string arg6CtorSignature = "(Z)V"; + jboolean jniarg6 = static_cast(dataResponse.arg6); + chip::JniReferences::GetInstance().CreateBoxedObject(arg6ClassName.c_str(), arg6CtorSignature.c_str(), jniarg6, arg6); + + env->CallVoidMethod(javaCallbackRef, javaMethod, arg1, arg2, arg3, arg4, arg5, arg6); +} +CHIPUnitTestingClusterTestListInt8UReverseResponseCallback::CHIPUnitTestingClusterTestListInt8UReverseResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestListInt8UReverseResponseCallback::~CHIPUnitTestingClusterTestListInt8UReverseResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestListInt8UReverseResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::TestListInt8UReverseResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/util/ArrayList;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject arg1; + chip::JniReferences::GetInstance().CreateArrayList(arg1); + + auto iter_arg1_0 = dataResponse.arg1.begin(); + while (iter_arg1_0.Next()) + { + auto & entry_0 = iter_arg1_0.GetValue(); + jobject newElement_0; + std::string newElement_0ClassName = "java/lang/Integer"; + std::string newElement_0CtorSignature = "(I)V"; + jint jninewElement_0 = static_cast(entry_0); + chip::JniReferences::GetInstance().CreateBoxedObject(newElement_0ClassName.c_str(), newElement_0CtorSignature.c_str(), + jninewElement_0, newElement_0); + chip::JniReferences::GetInstance().AddToList(arg1, newElement_0); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, arg1); +} +CHIPUnitTestingClusterTestEnumsResponseCallback::CHIPUnitTestingClusterTestEnumsResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestEnumsResponseCallback::~CHIPUnitTestingClusterTestEnumsResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestEnumsResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::TestEnumsResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Integer;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject arg1; + std::string arg1ClassName = "java/lang/Integer"; + std::string arg1CtorSignature = "(I)V"; + jint jniarg1 = static_cast(dataResponse.arg1); + chip::JniReferences::GetInstance().CreateBoxedObject(arg1ClassName.c_str(), arg1CtorSignature.c_str(), jniarg1, arg1); + jobject arg2; + std::string arg2ClassName = "java/lang/Integer"; + std::string arg2CtorSignature = "(I)V"; + jint jniarg2 = static_cast(dataResponse.arg2); + chip::JniReferences::GetInstance().CreateBoxedObject(arg2ClassName.c_str(), arg2CtorSignature.c_str(), jniarg2, arg2); + + env->CallVoidMethod(javaCallbackRef, javaMethod, arg1, arg2); +} +CHIPUnitTestingClusterTestNullableOptionalResponseCallback::CHIPUnitTestingClusterTestNullableOptionalResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestNullableOptionalResponseCallback::~CHIPUnitTestingClusterTestNullableOptionalResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestNullableOptionalResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::TestNullableOptionalResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", "(Ljava/lang/Boolean;Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject wasPresent; + std::string wasPresentClassName = "java/lang/Boolean"; + std::string wasPresentCtorSignature = "(Z)V"; + jboolean jniwasPresent = static_cast(dataResponse.wasPresent); + chip::JniReferences::GetInstance().CreateBoxedObject(wasPresentClassName.c_str(), wasPresentCtorSignature.c_str(), + jniwasPresent, wasPresent); + jobject wasNull; + if (!dataResponse.wasNull.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, wasNull); + } + else + { + jobject wasNullInsideOptional; + std::string wasNullInsideOptionalClassName = "java/lang/Boolean"; + std::string wasNullInsideOptionalCtorSignature = "(Z)V"; + jboolean jniwasNullInsideOptional = static_cast(dataResponse.wasNull.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(wasNullInsideOptionalClassName.c_str(), + wasNullInsideOptionalCtorSignature.c_str(), + jniwasNullInsideOptional, wasNullInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(wasNullInsideOptional, wasNull); + } + jobject value; + if (!dataResponse.value.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, value); + } + else + { + jobject valueInsideOptional; + std::string valueInsideOptionalClassName = "java/lang/Integer"; + std::string valueInsideOptionalCtorSignature = "(I)V"; + jint jnivalueInsideOptional = static_cast(dataResponse.value.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(valueInsideOptionalClassName.c_str(), + valueInsideOptionalCtorSignature.c_str(), jnivalueInsideOptional, + valueInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(valueInsideOptional, value); + } + jobject originalValue; + if (!dataResponse.originalValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, originalValue); + } + else + { + jobject originalValueInsideOptional; + if (dataResponse.originalValue.Value().IsNull()) + { + originalValueInsideOptional = nullptr; + } + else + { + std::string originalValueInsideOptionalClassName = "java/lang/Integer"; + std::string originalValueInsideOptionalCtorSignature = "(I)V"; + jint jnioriginalValueInsideOptional = static_cast(dataResponse.originalValue.Value().Value()); + chip::JniReferences::GetInstance().CreateBoxedObject(originalValueInsideOptionalClassName.c_str(), + originalValueInsideOptionalCtorSignature.c_str(), + jnioriginalValueInsideOptional, originalValueInsideOptional); + } + chip::JniReferences::GetInstance().CreateOptional(originalValueInsideOptional, originalValue); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, wasPresent, wasNull, value, originalValue); +} +CHIPUnitTestingClusterTestComplexNullableOptionalResponseCallback:: +CHIPUnitTestingClusterTestComplexNullableOptionalResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestComplexNullableOptionalResponseCallback::~ +CHIPUnitTestingClusterTestComplexNullableOptionalResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestComplexNullableOptionalResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::UnitTesting::Commands::TestComplexNullableOptionalResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Boolean;Ljava/util/Optional;Ljava/lang/Boolean;Ljava/util/Optional;Ljava/lang/Boolean;Ljava/util/" + "Optional;Ljava/util/Optional;Ljava/lang/Boolean;Ljava/util/Optional;Ljava/lang/Boolean;Ljava/util/Optional;Ljava/lang/" + "Boolean;Ljava/util/Optional;Ljava/util/Optional;Ljava/lang/Boolean;Ljava/util/Optional;Ljava/lang/Boolean;Ljava/util/" + "Optional;Ljava/lang/Boolean;Ljava/util/Optional;Ljava/util/Optional;Ljava/lang/Boolean;Ljava/util/Optional;Ljava/lang/" + "Boolean;Ljava/util/Optional;Ljava/lang/Boolean;Ljava/util/Optional;Ljava/util/Optional;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject NullableIntWasNull; + std::string NullableIntWasNullClassName = "java/lang/Boolean"; + std::string NullableIntWasNullCtorSignature = "(Z)V"; + jboolean jniNullableIntWasNull = static_cast(dataResponse.nullableIntWasNull); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableIntWasNullClassName.c_str(), NullableIntWasNullCtorSignature.c_str(), jniNullableIntWasNull, NullableIntWasNull); + jobject NullableIntValue; + if (!dataResponse.nullableIntValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableIntValue); + } + else + { + jobject NullableIntValueInsideOptional; + std::string NullableIntValueInsideOptionalClassName = "java/lang/Integer"; + std::string NullableIntValueInsideOptionalCtorSignature = "(I)V"; + jint jniNullableIntValueInsideOptional = static_cast(dataResponse.nullableIntValue.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableIntValueInsideOptionalClassName.c_str(), NullableIntValueInsideOptionalCtorSignature.c_str(), + jniNullableIntValueInsideOptional, NullableIntValueInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(NullableIntValueInsideOptional, NullableIntValue); + } + jobject OptionalIntWasPresent; + std::string OptionalIntWasPresentClassName = "java/lang/Boolean"; + std::string OptionalIntWasPresentCtorSignature = "(Z)V"; + jboolean jniOptionalIntWasPresent = static_cast(dataResponse.optionalIntWasPresent); + chip::JniReferences::GetInstance().CreateBoxedObject(OptionalIntWasPresentClassName.c_str(), + OptionalIntWasPresentCtorSignature.c_str(), + jniOptionalIntWasPresent, OptionalIntWasPresent); + jobject OptionalIntValue; + if (!dataResponse.optionalIntValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, OptionalIntValue); + } + else + { + jobject OptionalIntValueInsideOptional; + std::string OptionalIntValueInsideOptionalClassName = "java/lang/Integer"; + std::string OptionalIntValueInsideOptionalCtorSignature = "(I)V"; + jint jniOptionalIntValueInsideOptional = static_cast(dataResponse.optionalIntValue.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + OptionalIntValueInsideOptionalClassName.c_str(), OptionalIntValueInsideOptionalCtorSignature.c_str(), + jniOptionalIntValueInsideOptional, OptionalIntValueInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(OptionalIntValueInsideOptional, OptionalIntValue); + } + jobject NullableOptionalIntWasPresent; + std::string NullableOptionalIntWasPresentClassName = "java/lang/Boolean"; + std::string NullableOptionalIntWasPresentCtorSignature = "(Z)V"; + jboolean jniNullableOptionalIntWasPresent = static_cast(dataResponse.nullableOptionalIntWasPresent); + chip::JniReferences::GetInstance().CreateBoxedObject(NullableOptionalIntWasPresentClassName.c_str(), + NullableOptionalIntWasPresentCtorSignature.c_str(), + jniNullableOptionalIntWasPresent, NullableOptionalIntWasPresent); + jobject NullableOptionalIntWasNull; + if (!dataResponse.nullableOptionalIntWasNull.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableOptionalIntWasNull); + } + else + { + jobject NullableOptionalIntWasNullInsideOptional; + std::string NullableOptionalIntWasNullInsideOptionalClassName = "java/lang/Boolean"; + std::string NullableOptionalIntWasNullInsideOptionalCtorSignature = "(Z)V"; + jboolean jniNullableOptionalIntWasNullInsideOptional = + static_cast(dataResponse.nullableOptionalIntWasNull.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableOptionalIntWasNullInsideOptionalClassName.c_str(), + NullableOptionalIntWasNullInsideOptionalCtorSignature.c_str(), jniNullableOptionalIntWasNullInsideOptional, + NullableOptionalIntWasNullInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(NullableOptionalIntWasNullInsideOptional, NullableOptionalIntWasNull); + } + jobject NullableOptionalIntValue; + if (!dataResponse.nullableOptionalIntValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableOptionalIntValue); + } + else + { + jobject NullableOptionalIntValueInsideOptional; + std::string NullableOptionalIntValueInsideOptionalClassName = "java/lang/Integer"; + std::string NullableOptionalIntValueInsideOptionalCtorSignature = "(I)V"; + jint jniNullableOptionalIntValueInsideOptional = static_cast(dataResponse.nullableOptionalIntValue.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableOptionalIntValueInsideOptionalClassName.c_str(), NullableOptionalIntValueInsideOptionalCtorSignature.c_str(), + jniNullableOptionalIntValueInsideOptional, NullableOptionalIntValueInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(NullableOptionalIntValueInsideOptional, NullableOptionalIntValue); + } + jobject NullableStringWasNull; + std::string NullableStringWasNullClassName = "java/lang/Boolean"; + std::string NullableStringWasNullCtorSignature = "(Z)V"; + jboolean jniNullableStringWasNull = static_cast(dataResponse.nullableStringWasNull); + chip::JniReferences::GetInstance().CreateBoxedObject(NullableStringWasNullClassName.c_str(), + NullableStringWasNullCtorSignature.c_str(), + jniNullableStringWasNull, NullableStringWasNull); + jobject NullableStringValue; + if (!dataResponse.nullableStringValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableStringValue); + } + else + { + jobject NullableStringValueInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.nullableStringValue.Value(), + NullableStringValueInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(NullableStringValueInsideOptional, NullableStringValue); + } + jobject OptionalStringWasPresent; + std::string OptionalStringWasPresentClassName = "java/lang/Boolean"; + std::string OptionalStringWasPresentCtorSignature = "(Z)V"; + jboolean jniOptionalStringWasPresent = static_cast(dataResponse.optionalStringWasPresent); + chip::JniReferences::GetInstance().CreateBoxedObject(OptionalStringWasPresentClassName.c_str(), + OptionalStringWasPresentCtorSignature.c_str(), + jniOptionalStringWasPresent, OptionalStringWasPresent); + jobject OptionalStringValue; + if (!dataResponse.optionalStringValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, OptionalStringValue); + } + else + { + jobject OptionalStringValueInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.optionalStringValue.Value(), + OptionalStringValueInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(OptionalStringValueInsideOptional, OptionalStringValue); + } + jobject NullableOptionalStringWasPresent; + std::string NullableOptionalStringWasPresentClassName = "java/lang/Boolean"; + std::string NullableOptionalStringWasPresentCtorSignature = "(Z)V"; + jboolean jniNullableOptionalStringWasPresent = static_cast(dataResponse.nullableOptionalStringWasPresent); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableOptionalStringWasPresentClassName.c_str(), NullableOptionalStringWasPresentCtorSignature.c_str(), + jniNullableOptionalStringWasPresent, NullableOptionalStringWasPresent); + jobject NullableOptionalStringWasNull; + if (!dataResponse.nullableOptionalStringWasNull.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableOptionalStringWasNull); + } + else + { + jobject NullableOptionalStringWasNullInsideOptional; + std::string NullableOptionalStringWasNullInsideOptionalClassName = "java/lang/Boolean"; + std::string NullableOptionalStringWasNullInsideOptionalCtorSignature = "(Z)V"; + jboolean jniNullableOptionalStringWasNullInsideOptional = + static_cast(dataResponse.nullableOptionalStringWasNull.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableOptionalStringWasNullInsideOptionalClassName.c_str(), + NullableOptionalStringWasNullInsideOptionalCtorSignature.c_str(), jniNullableOptionalStringWasNullInsideOptional, + NullableOptionalStringWasNullInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(NullableOptionalStringWasNullInsideOptional, + NullableOptionalStringWasNull); + } + jobject NullableOptionalStringValue; + if (!dataResponse.nullableOptionalStringValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableOptionalStringValue); + } + else + { + jobject NullableOptionalStringValueInsideOptional; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.nullableOptionalStringValue.Value(), + NullableOptionalStringValueInsideOptional)); + chip::JniReferences::GetInstance().CreateOptional(NullableOptionalStringValueInsideOptional, NullableOptionalStringValue); + } + jobject NullableStructWasNull; + std::string NullableStructWasNullClassName = "java/lang/Boolean"; + std::string NullableStructWasNullCtorSignature = "(Z)V"; + jboolean jniNullableStructWasNull = static_cast(dataResponse.nullableStructWasNull); + chip::JniReferences::GetInstance().CreateBoxedObject(NullableStructWasNullClassName.c_str(), + NullableStructWasNullCtorSignature.c_str(), + jniNullableStructWasNull, NullableStructWasNull); + jobject NullableStructValue; + if (!dataResponse.nullableStructValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableStructValue); + } + else + { + jobject NullableStructValueInsideOptional; + jobject NullableStructValueInsideOptional_a; + std::string NullableStructValueInsideOptional_aClassName = "java/lang/Integer"; + std::string NullableStructValueInsideOptional_aCtorSignature = "(I)V"; + jint jniNullableStructValueInsideOptional_a = static_cast(dataResponse.nullableStructValue.Value().a); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableStructValueInsideOptional_aClassName.c_str(), NullableStructValueInsideOptional_aCtorSignature.c_str(), + jniNullableStructValueInsideOptional_a, NullableStructValueInsideOptional_a); + jobject NullableStructValueInsideOptional_b; + std::string NullableStructValueInsideOptional_bClassName = "java/lang/Boolean"; + std::string NullableStructValueInsideOptional_bCtorSignature = "(Z)V"; + jboolean jniNullableStructValueInsideOptional_b = static_cast(dataResponse.nullableStructValue.Value().b); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableStructValueInsideOptional_bClassName.c_str(), NullableStructValueInsideOptional_bCtorSignature.c_str(), + jniNullableStructValueInsideOptional_b, NullableStructValueInsideOptional_b); + jobject NullableStructValueInsideOptional_c; + std::string NullableStructValueInsideOptional_cClassName = "java/lang/Integer"; + std::string NullableStructValueInsideOptional_cCtorSignature = "(I)V"; + jint jniNullableStructValueInsideOptional_c = static_cast(dataResponse.nullableStructValue.Value().c); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableStructValueInsideOptional_cClassName.c_str(), NullableStructValueInsideOptional_cCtorSignature.c_str(), + jniNullableStructValueInsideOptional_c, NullableStructValueInsideOptional_c); + jobject NullableStructValueInsideOptional_d; + jbyteArray NullableStructValueInsideOptional_dByteArray = + env->NewByteArray(static_cast(dataResponse.nullableStructValue.Value().d.size())); + env->SetByteArrayRegion(NullableStructValueInsideOptional_dByteArray, 0, + static_cast(dataResponse.nullableStructValue.Value().d.size()), + reinterpret_cast(dataResponse.nullableStructValue.Value().d.data())); + NullableStructValueInsideOptional_d = NullableStructValueInsideOptional_dByteArray; + jobject NullableStructValueInsideOptional_e; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.nullableStructValue.Value().e, + NullableStructValueInsideOptional_e)); + jobject NullableStructValueInsideOptional_f; + std::string NullableStructValueInsideOptional_fClassName = "java/lang/Integer"; + std::string NullableStructValueInsideOptional_fCtorSignature = "(I)V"; + jint jniNullableStructValueInsideOptional_f = static_cast(dataResponse.nullableStructValue.Value().f.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableStructValueInsideOptional_fClassName.c_str(), NullableStructValueInsideOptional_fCtorSignature.c_str(), + jniNullableStructValueInsideOptional_f, NullableStructValueInsideOptional_f); + jobject NullableStructValueInsideOptional_g; + std::string NullableStructValueInsideOptional_gClassName = "java/lang/Float"; + std::string NullableStructValueInsideOptional_gCtorSignature = "(F)V"; + jfloat jniNullableStructValueInsideOptional_g = static_cast(dataResponse.nullableStructValue.Value().g); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableStructValueInsideOptional_gClassName.c_str(), NullableStructValueInsideOptional_gCtorSignature.c_str(), + jniNullableStructValueInsideOptional_g, NullableStructValueInsideOptional_g); + jobject NullableStructValueInsideOptional_h; + std::string NullableStructValueInsideOptional_hClassName = "java/lang/Double"; + std::string NullableStructValueInsideOptional_hCtorSignature = "(D)V"; + jdouble jniNullableStructValueInsideOptional_h = static_cast(dataResponse.nullableStructValue.Value().h); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableStructValueInsideOptional_hClassName.c_str(), NullableStructValueInsideOptional_hCtorSignature.c_str(), + jniNullableStructValueInsideOptional_h, NullableStructValueInsideOptional_h); + + jclass simpleStructStructClass_1; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$UnitTestingClusterSimpleStruct", simpleStructStructClass_1); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$UnitTestingClusterSimpleStruct"); + return; + } + + jmethodID simpleStructStructCtor_1; + err = chip::JniReferences::GetInstance().FindMethod(env, simpleStructStructClass_1, "", + "(Ljava/lang/Integer;Ljava/lang/Boolean;Ljava/lang/Integer;[BLjava/" + "lang/String;Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Double;)V", + &simpleStructStructCtor_1); + if (err != CHIP_NO_ERROR || simpleStructStructCtor_1 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$UnitTestingClusterSimpleStruct constructor"); + return; + } + + NullableStructValueInsideOptional = env->NewObject( + simpleStructStructClass_1, simpleStructStructCtor_1, NullableStructValueInsideOptional_a, + NullableStructValueInsideOptional_b, NullableStructValueInsideOptional_c, NullableStructValueInsideOptional_d, + NullableStructValueInsideOptional_e, NullableStructValueInsideOptional_f, NullableStructValueInsideOptional_g, + NullableStructValueInsideOptional_h); + chip::JniReferences::GetInstance().CreateOptional(NullableStructValueInsideOptional, NullableStructValue); + } + jobject OptionalStructWasPresent; + std::string OptionalStructWasPresentClassName = "java/lang/Boolean"; + std::string OptionalStructWasPresentCtorSignature = "(Z)V"; + jboolean jniOptionalStructWasPresent = static_cast(dataResponse.optionalStructWasPresent); + chip::JniReferences::GetInstance().CreateBoxedObject(OptionalStructWasPresentClassName.c_str(), + OptionalStructWasPresentCtorSignature.c_str(), + jniOptionalStructWasPresent, OptionalStructWasPresent); + jobject OptionalStructValue; + if (!dataResponse.optionalStructValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, OptionalStructValue); + } + else + { + jobject OptionalStructValueInsideOptional; + jobject OptionalStructValueInsideOptional_a; + std::string OptionalStructValueInsideOptional_aClassName = "java/lang/Integer"; + std::string OptionalStructValueInsideOptional_aCtorSignature = "(I)V"; + jint jniOptionalStructValueInsideOptional_a = static_cast(dataResponse.optionalStructValue.Value().a); + chip::JniReferences::GetInstance().CreateBoxedObject( + OptionalStructValueInsideOptional_aClassName.c_str(), OptionalStructValueInsideOptional_aCtorSignature.c_str(), + jniOptionalStructValueInsideOptional_a, OptionalStructValueInsideOptional_a); + jobject OptionalStructValueInsideOptional_b; + std::string OptionalStructValueInsideOptional_bClassName = "java/lang/Boolean"; + std::string OptionalStructValueInsideOptional_bCtorSignature = "(Z)V"; + jboolean jniOptionalStructValueInsideOptional_b = static_cast(dataResponse.optionalStructValue.Value().b); + chip::JniReferences::GetInstance().CreateBoxedObject( + OptionalStructValueInsideOptional_bClassName.c_str(), OptionalStructValueInsideOptional_bCtorSignature.c_str(), + jniOptionalStructValueInsideOptional_b, OptionalStructValueInsideOptional_b); + jobject OptionalStructValueInsideOptional_c; + std::string OptionalStructValueInsideOptional_cClassName = "java/lang/Integer"; + std::string OptionalStructValueInsideOptional_cCtorSignature = "(I)V"; + jint jniOptionalStructValueInsideOptional_c = static_cast(dataResponse.optionalStructValue.Value().c); + chip::JniReferences::GetInstance().CreateBoxedObject( + OptionalStructValueInsideOptional_cClassName.c_str(), OptionalStructValueInsideOptional_cCtorSignature.c_str(), + jniOptionalStructValueInsideOptional_c, OptionalStructValueInsideOptional_c); + jobject OptionalStructValueInsideOptional_d; + jbyteArray OptionalStructValueInsideOptional_dByteArray = + env->NewByteArray(static_cast(dataResponse.optionalStructValue.Value().d.size())); + env->SetByteArrayRegion(OptionalStructValueInsideOptional_dByteArray, 0, + static_cast(dataResponse.optionalStructValue.Value().d.size()), + reinterpret_cast(dataResponse.optionalStructValue.Value().d.data())); + OptionalStructValueInsideOptional_d = OptionalStructValueInsideOptional_dByteArray; + jobject OptionalStructValueInsideOptional_e; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.optionalStructValue.Value().e, + OptionalStructValueInsideOptional_e)); + jobject OptionalStructValueInsideOptional_f; + std::string OptionalStructValueInsideOptional_fClassName = "java/lang/Integer"; + std::string OptionalStructValueInsideOptional_fCtorSignature = "(I)V"; + jint jniOptionalStructValueInsideOptional_f = static_cast(dataResponse.optionalStructValue.Value().f.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject( + OptionalStructValueInsideOptional_fClassName.c_str(), OptionalStructValueInsideOptional_fCtorSignature.c_str(), + jniOptionalStructValueInsideOptional_f, OptionalStructValueInsideOptional_f); + jobject OptionalStructValueInsideOptional_g; + std::string OptionalStructValueInsideOptional_gClassName = "java/lang/Float"; + std::string OptionalStructValueInsideOptional_gCtorSignature = "(F)V"; + jfloat jniOptionalStructValueInsideOptional_g = static_cast(dataResponse.optionalStructValue.Value().g); + chip::JniReferences::GetInstance().CreateBoxedObject( + OptionalStructValueInsideOptional_gClassName.c_str(), OptionalStructValueInsideOptional_gCtorSignature.c_str(), + jniOptionalStructValueInsideOptional_g, OptionalStructValueInsideOptional_g); + jobject OptionalStructValueInsideOptional_h; + std::string OptionalStructValueInsideOptional_hClassName = "java/lang/Double"; + std::string OptionalStructValueInsideOptional_hCtorSignature = "(D)V"; + jdouble jniOptionalStructValueInsideOptional_h = static_cast(dataResponse.optionalStructValue.Value().h); + chip::JniReferences::GetInstance().CreateBoxedObject( + OptionalStructValueInsideOptional_hClassName.c_str(), OptionalStructValueInsideOptional_hCtorSignature.c_str(), + jniOptionalStructValueInsideOptional_h, OptionalStructValueInsideOptional_h); + + jclass simpleStructStructClass_1; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$UnitTestingClusterSimpleStruct", simpleStructStructClass_1); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$UnitTestingClusterSimpleStruct"); + return; + } + + jmethodID simpleStructStructCtor_1; + err = chip::JniReferences::GetInstance().FindMethod(env, simpleStructStructClass_1, "", + "(Ljava/lang/Integer;Ljava/lang/Boolean;Ljava/lang/Integer;[BLjava/" + "lang/String;Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Double;)V", + &simpleStructStructCtor_1); + if (err != CHIP_NO_ERROR || simpleStructStructCtor_1 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$UnitTestingClusterSimpleStruct constructor"); + return; + } + + OptionalStructValueInsideOptional = env->NewObject( + simpleStructStructClass_1, simpleStructStructCtor_1, OptionalStructValueInsideOptional_a, + OptionalStructValueInsideOptional_b, OptionalStructValueInsideOptional_c, OptionalStructValueInsideOptional_d, + OptionalStructValueInsideOptional_e, OptionalStructValueInsideOptional_f, OptionalStructValueInsideOptional_g, + OptionalStructValueInsideOptional_h); + chip::JniReferences::GetInstance().CreateOptional(OptionalStructValueInsideOptional, OptionalStructValue); + } + jobject NullableOptionalStructWasPresent; + std::string NullableOptionalStructWasPresentClassName = "java/lang/Boolean"; + std::string NullableOptionalStructWasPresentCtorSignature = "(Z)V"; + jboolean jniNullableOptionalStructWasPresent = static_cast(dataResponse.nullableOptionalStructWasPresent); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableOptionalStructWasPresentClassName.c_str(), NullableOptionalStructWasPresentCtorSignature.c_str(), + jniNullableOptionalStructWasPresent, NullableOptionalStructWasPresent); + jobject NullableOptionalStructWasNull; + if (!dataResponse.nullableOptionalStructWasNull.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableOptionalStructWasNull); + } + else + { + jobject NullableOptionalStructWasNullInsideOptional; + std::string NullableOptionalStructWasNullInsideOptionalClassName = "java/lang/Boolean"; + std::string NullableOptionalStructWasNullInsideOptionalCtorSignature = "(Z)V"; + jboolean jniNullableOptionalStructWasNullInsideOptional = + static_cast(dataResponse.nullableOptionalStructWasNull.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableOptionalStructWasNullInsideOptionalClassName.c_str(), + NullableOptionalStructWasNullInsideOptionalCtorSignature.c_str(), jniNullableOptionalStructWasNullInsideOptional, + NullableOptionalStructWasNullInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(NullableOptionalStructWasNullInsideOptional, + NullableOptionalStructWasNull); + } + jobject NullableOptionalStructValue; + if (!dataResponse.nullableOptionalStructValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableOptionalStructValue); + } + else + { + jobject NullableOptionalStructValueInsideOptional; + jobject NullableOptionalStructValueInsideOptional_a; + std::string NullableOptionalStructValueInsideOptional_aClassName = "java/lang/Integer"; + std::string NullableOptionalStructValueInsideOptional_aCtorSignature = "(I)V"; + jint jniNullableOptionalStructValueInsideOptional_a = static_cast(dataResponse.nullableOptionalStructValue.Value().a); + chip::JniReferences::GetInstance().CreateBoxedObject(NullableOptionalStructValueInsideOptional_aClassName.c_str(), + NullableOptionalStructValueInsideOptional_aCtorSignature.c_str(), + jniNullableOptionalStructValueInsideOptional_a, + NullableOptionalStructValueInsideOptional_a); + jobject NullableOptionalStructValueInsideOptional_b; + std::string NullableOptionalStructValueInsideOptional_bClassName = "java/lang/Boolean"; + std::string NullableOptionalStructValueInsideOptional_bCtorSignature = "(Z)V"; + jboolean jniNullableOptionalStructValueInsideOptional_b = + static_cast(dataResponse.nullableOptionalStructValue.Value().b); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableOptionalStructValueInsideOptional_bClassName.c_str(), + NullableOptionalStructValueInsideOptional_bCtorSignature.c_str(), jniNullableOptionalStructValueInsideOptional_b, + NullableOptionalStructValueInsideOptional_b); + jobject NullableOptionalStructValueInsideOptional_c; + std::string NullableOptionalStructValueInsideOptional_cClassName = "java/lang/Integer"; + std::string NullableOptionalStructValueInsideOptional_cCtorSignature = "(I)V"; + jint jniNullableOptionalStructValueInsideOptional_c = static_cast(dataResponse.nullableOptionalStructValue.Value().c); + chip::JniReferences::GetInstance().CreateBoxedObject(NullableOptionalStructValueInsideOptional_cClassName.c_str(), + NullableOptionalStructValueInsideOptional_cCtorSignature.c_str(), + jniNullableOptionalStructValueInsideOptional_c, + NullableOptionalStructValueInsideOptional_c); + jobject NullableOptionalStructValueInsideOptional_d; + jbyteArray NullableOptionalStructValueInsideOptional_dByteArray = + env->NewByteArray(static_cast(dataResponse.nullableOptionalStructValue.Value().d.size())); + env->SetByteArrayRegion(NullableOptionalStructValueInsideOptional_dByteArray, 0, + static_cast(dataResponse.nullableOptionalStructValue.Value().d.size()), + reinterpret_cast(dataResponse.nullableOptionalStructValue.Value().d.data())); + NullableOptionalStructValueInsideOptional_d = NullableOptionalStructValueInsideOptional_dByteArray; + jobject NullableOptionalStructValueInsideOptional_e; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.nullableOptionalStructValue.Value().e, + NullableOptionalStructValueInsideOptional_e)); + jobject NullableOptionalStructValueInsideOptional_f; + std::string NullableOptionalStructValueInsideOptional_fClassName = "java/lang/Integer"; + std::string NullableOptionalStructValueInsideOptional_fCtorSignature = "(I)V"; + jint jniNullableOptionalStructValueInsideOptional_f = + static_cast(dataResponse.nullableOptionalStructValue.Value().f.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject(NullableOptionalStructValueInsideOptional_fClassName.c_str(), + NullableOptionalStructValueInsideOptional_fCtorSignature.c_str(), + jniNullableOptionalStructValueInsideOptional_f, + NullableOptionalStructValueInsideOptional_f); + jobject NullableOptionalStructValueInsideOptional_g; + std::string NullableOptionalStructValueInsideOptional_gClassName = "java/lang/Float"; + std::string NullableOptionalStructValueInsideOptional_gCtorSignature = "(F)V"; + jfloat jniNullableOptionalStructValueInsideOptional_g = + static_cast(dataResponse.nullableOptionalStructValue.Value().g); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableOptionalStructValueInsideOptional_gClassName.c_str(), + NullableOptionalStructValueInsideOptional_gCtorSignature.c_str(), jniNullableOptionalStructValueInsideOptional_g, + NullableOptionalStructValueInsideOptional_g); + jobject NullableOptionalStructValueInsideOptional_h; + std::string NullableOptionalStructValueInsideOptional_hClassName = "java/lang/Double"; + std::string NullableOptionalStructValueInsideOptional_hCtorSignature = "(D)V"; + jdouble jniNullableOptionalStructValueInsideOptional_h = + static_cast(dataResponse.nullableOptionalStructValue.Value().h); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableOptionalStructValueInsideOptional_hClassName.c_str(), + NullableOptionalStructValueInsideOptional_hCtorSignature.c_str(), jniNullableOptionalStructValueInsideOptional_h, + NullableOptionalStructValueInsideOptional_h); + + jclass simpleStructStructClass_1; + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$UnitTestingClusterSimpleStruct", simpleStructStructClass_1); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$UnitTestingClusterSimpleStruct"); + return; + } + + jmethodID simpleStructStructCtor_1; + err = chip::JniReferences::GetInstance().FindMethod(env, simpleStructStructClass_1, "", + "(Ljava/lang/Integer;Ljava/lang/Boolean;Ljava/lang/Integer;[BLjava/" + "lang/String;Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Double;)V", + &simpleStructStructCtor_1); + if (err != CHIP_NO_ERROR || simpleStructStructCtor_1 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$UnitTestingClusterSimpleStruct constructor"); + return; + } + + NullableOptionalStructValueInsideOptional = + env->NewObject(simpleStructStructClass_1, simpleStructStructCtor_1, NullableOptionalStructValueInsideOptional_a, + NullableOptionalStructValueInsideOptional_b, NullableOptionalStructValueInsideOptional_c, + NullableOptionalStructValueInsideOptional_d, NullableOptionalStructValueInsideOptional_e, + NullableOptionalStructValueInsideOptional_f, NullableOptionalStructValueInsideOptional_g, + NullableOptionalStructValueInsideOptional_h); + chip::JniReferences::GetInstance().CreateOptional(NullableOptionalStructValueInsideOptional, NullableOptionalStructValue); + } + jobject NullableListWasNull; + std::string NullableListWasNullClassName = "java/lang/Boolean"; + std::string NullableListWasNullCtorSignature = "(Z)V"; + jboolean jniNullableListWasNull = static_cast(dataResponse.nullableListWasNull); + chip::JniReferences::GetInstance().CreateBoxedObject(NullableListWasNullClassName.c_str(), + NullableListWasNullCtorSignature.c_str(), jniNullableListWasNull, + NullableListWasNull); + jobject NullableListValue; + if (!dataResponse.nullableListValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableListValue); + } + else + { + jobject NullableListValueInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(NullableListValueInsideOptional); + + auto iter_NullableListValueInsideOptional_1 = dataResponse.nullableListValue.Value().begin(); + while (iter_NullableListValueInsideOptional_1.Next()) + { + auto & entry_1 = iter_NullableListValueInsideOptional_1.GetValue(); + jobject newElement_1; + std::string newElement_1ClassName = "java/lang/Integer"; + std::string newElement_1CtorSignature = "(I)V"; + jint jninewElement_1 = static_cast(entry_1); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_1ClassName.c_str(), newElement_1CtorSignature.c_str(), jninewElement_1, newElement_1); + chip::JniReferences::GetInstance().AddToList(NullableListValueInsideOptional, newElement_1); + } + chip::JniReferences::GetInstance().CreateOptional(NullableListValueInsideOptional, NullableListValue); + } + jobject OptionalListWasPresent; + std::string OptionalListWasPresentClassName = "java/lang/Boolean"; + std::string OptionalListWasPresentCtorSignature = "(Z)V"; + jboolean jniOptionalListWasPresent = static_cast(dataResponse.optionalListWasPresent); + chip::JniReferences::GetInstance().CreateBoxedObject(OptionalListWasPresentClassName.c_str(), + OptionalListWasPresentCtorSignature.c_str(), + jniOptionalListWasPresent, OptionalListWasPresent); + jobject OptionalListValue; + if (!dataResponse.optionalListValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, OptionalListValue); + } + else + { + jobject OptionalListValueInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(OptionalListValueInsideOptional); + + auto iter_OptionalListValueInsideOptional_1 = dataResponse.optionalListValue.Value().begin(); + while (iter_OptionalListValueInsideOptional_1.Next()) + { + auto & entry_1 = iter_OptionalListValueInsideOptional_1.GetValue(); + jobject newElement_1; + std::string newElement_1ClassName = "java/lang/Integer"; + std::string newElement_1CtorSignature = "(I)V"; + jint jninewElement_1 = static_cast(entry_1); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_1ClassName.c_str(), newElement_1CtorSignature.c_str(), jninewElement_1, newElement_1); + chip::JniReferences::GetInstance().AddToList(OptionalListValueInsideOptional, newElement_1); + } + chip::JniReferences::GetInstance().CreateOptional(OptionalListValueInsideOptional, OptionalListValue); + } + jobject NullableOptionalListWasPresent; + std::string NullableOptionalListWasPresentClassName = "java/lang/Boolean"; + std::string NullableOptionalListWasPresentCtorSignature = "(Z)V"; + jboolean jniNullableOptionalListWasPresent = static_cast(dataResponse.nullableOptionalListWasPresent); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableOptionalListWasPresentClassName.c_str(), NullableOptionalListWasPresentCtorSignature.c_str(), + jniNullableOptionalListWasPresent, NullableOptionalListWasPresent); + jobject NullableOptionalListWasNull; + if (!dataResponse.nullableOptionalListWasNull.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableOptionalListWasNull); + } + else + { + jobject NullableOptionalListWasNullInsideOptional; + std::string NullableOptionalListWasNullInsideOptionalClassName = "java/lang/Boolean"; + std::string NullableOptionalListWasNullInsideOptionalCtorSignature = "(Z)V"; + jboolean jniNullableOptionalListWasNullInsideOptional = + static_cast(dataResponse.nullableOptionalListWasNull.Value()); + chip::JniReferences::GetInstance().CreateBoxedObject( + NullableOptionalListWasNullInsideOptionalClassName.c_str(), + NullableOptionalListWasNullInsideOptionalCtorSignature.c_str(), jniNullableOptionalListWasNullInsideOptional, + NullableOptionalListWasNullInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(NullableOptionalListWasNullInsideOptional, NullableOptionalListWasNull); + } + jobject NullableOptionalListValue; + if (!dataResponse.nullableOptionalListValue.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NullableOptionalListValue); + } + else + { + jobject NullableOptionalListValueInsideOptional; + chip::JniReferences::GetInstance().CreateArrayList(NullableOptionalListValueInsideOptional); + + auto iter_NullableOptionalListValueInsideOptional_1 = dataResponse.nullableOptionalListValue.Value().begin(); + while (iter_NullableOptionalListValueInsideOptional_1.Next()) + { + auto & entry_1 = iter_NullableOptionalListValueInsideOptional_1.GetValue(); + jobject newElement_1; + std::string newElement_1ClassName = "java/lang/Integer"; + std::string newElement_1CtorSignature = "(I)V"; + jint jninewElement_1 = static_cast(entry_1); + chip::JniReferences::GetInstance().CreateBoxedObject( + newElement_1ClassName.c_str(), newElement_1CtorSignature.c_str(), jninewElement_1, newElement_1); + chip::JniReferences::GetInstance().AddToList(NullableOptionalListValueInsideOptional, newElement_1); + } + chip::JniReferences::GetInstance().CreateOptional(NullableOptionalListValueInsideOptional, NullableOptionalListValue); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, NullableIntWasNull, NullableIntValue, OptionalIntWasPresent, OptionalIntValue, + NullableOptionalIntWasPresent, NullableOptionalIntWasNull, NullableOptionalIntValue, NullableStringWasNull, + NullableStringValue, OptionalStringWasPresent, OptionalStringValue, NullableOptionalStringWasPresent, + NullableOptionalStringWasNull, NullableOptionalStringValue, NullableStructWasNull, NullableStructValue, + OptionalStructWasPresent, OptionalStructValue, NullableOptionalStructWasPresent, + NullableOptionalStructWasNull, NullableOptionalStructValue, NullableListWasNull, NullableListValue, + OptionalListWasPresent, OptionalListValue, NullableOptionalListWasPresent, NullableOptionalListWasNull, + NullableOptionalListValue); +} +CHIPUnitTestingClusterBooleanResponseCallback::CHIPUnitTestingClusterBooleanResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterBooleanResponseCallback::~CHIPUnitTestingClusterBooleanResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterBooleanResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::BooleanResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Boolean;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject value; + std::string valueClassName = "java/lang/Boolean"; + std::string valueCtorSignature = "(Z)V"; + jboolean jnivalue = static_cast(dataResponse.value); + chip::JniReferences::GetInstance().CreateBoxedObject(valueClassName.c_str(), valueCtorSignature.c_str(), jnivalue, + value); + + env->CallVoidMethod(javaCallbackRef, javaMethod, value); +} +CHIPUnitTestingClusterSimpleStructResponseCallback::CHIPUnitTestingClusterSimpleStructResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterSimpleStructResponseCallback::~CHIPUnitTestingClusterSimpleStructResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterSimpleStructResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::SimpleStructResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod( + env, javaCallbackRef, "onSuccess", "(Lchip/devicecontroller/ChipStructs$UnitTestingClusterSimpleStruct;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject arg1; + jobject arg1_a; + std::string arg1_aClassName = "java/lang/Integer"; + std::string arg1_aCtorSignature = "(I)V"; + jint jniarg1_a = static_cast(dataResponse.arg1.a); + chip::JniReferences::GetInstance().CreateBoxedObject(arg1_aClassName.c_str(), arg1_aCtorSignature.c_str(), jniarg1_a, + arg1_a); + jobject arg1_b; + std::string arg1_bClassName = "java/lang/Boolean"; + std::string arg1_bCtorSignature = "(Z)V"; + jboolean jniarg1_b = static_cast(dataResponse.arg1.b); + chip::JniReferences::GetInstance().CreateBoxedObject(arg1_bClassName.c_str(), arg1_bCtorSignature.c_str(), jniarg1_b, + arg1_b); + jobject arg1_c; + std::string arg1_cClassName = "java/lang/Integer"; + std::string arg1_cCtorSignature = "(I)V"; + jint jniarg1_c = static_cast(dataResponse.arg1.c); + chip::JniReferences::GetInstance().CreateBoxedObject(arg1_cClassName.c_str(), arg1_cCtorSignature.c_str(), jniarg1_c, + arg1_c); + jobject arg1_d; + jbyteArray arg1_dByteArray = env->NewByteArray(static_cast(dataResponse.arg1.d.size())); + env->SetByteArrayRegion(arg1_dByteArray, 0, static_cast(dataResponse.arg1.d.size()), + reinterpret_cast(dataResponse.arg1.d.data())); + arg1_d = arg1_dByteArray; + jobject arg1_e; + LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(dataResponse.arg1.e, arg1_e)); + jobject arg1_f; + std::string arg1_fClassName = "java/lang/Integer"; + std::string arg1_fCtorSignature = "(I)V"; + jint jniarg1_f = static_cast(dataResponse.arg1.f.Raw()); + chip::JniReferences::GetInstance().CreateBoxedObject(arg1_fClassName.c_str(), arg1_fCtorSignature.c_str(), jniarg1_f, + arg1_f); + jobject arg1_g; + std::string arg1_gClassName = "java/lang/Float"; + std::string arg1_gCtorSignature = "(F)V"; + jfloat jniarg1_g = static_cast(dataResponse.arg1.g); + chip::JniReferences::GetInstance().CreateBoxedObject(arg1_gClassName.c_str(), arg1_gCtorSignature.c_str(), jniarg1_g, + arg1_g); + jobject arg1_h; + std::string arg1_hClassName = "java/lang/Double"; + std::string arg1_hCtorSignature = "(D)V"; + jdouble jniarg1_h = static_cast(dataResponse.arg1.h); + chip::JniReferences::GetInstance().CreateBoxedObject(arg1_hClassName.c_str(), arg1_hCtorSignature.c_str(), jniarg1_h, + arg1_h); + + jclass simpleStructStructClass_0; + err = chip::JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/ChipStructs$UnitTestingClusterSimpleStruct", + simpleStructStructClass_0); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Could not find class ChipStructs$UnitTestingClusterSimpleStruct"); + return; + } + + jmethodID simpleStructStructCtor_0; + err = chip::JniReferences::GetInstance().FindMethod(env, simpleStructStructClass_0, "", + "(Ljava/lang/Integer;Ljava/lang/Boolean;Ljava/lang/Integer;[BLjava/lang/" + "String;Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Double;)V", + &simpleStructStructCtor_0); + if (err != CHIP_NO_ERROR || simpleStructStructCtor_0 == nullptr) + { + ChipLogError(Zcl, "Could not find ChipStructs$UnitTestingClusterSimpleStruct constructor"); + return; + } + + arg1 = env->NewObject(simpleStructStructClass_0, simpleStructStructCtor_0, arg1_a, arg1_b, arg1_c, arg1_d, arg1_e, arg1_f, + arg1_g, arg1_h); + + env->CallVoidMethod(javaCallbackRef, javaMethod, arg1); +} +CHIPUnitTestingClusterTestEmitTestEventResponseCallback::CHIPUnitTestingClusterTestEmitTestEventResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestEmitTestEventResponseCallback::~CHIPUnitTestingClusterTestEmitTestEventResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestEmitTestEventResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::TestEmitTestEventResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Long;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject value; + std::string valueClassName = "java/lang/Long"; + std::string valueCtorSignature = "(J)V"; + jlong jnivalue = static_cast(dataResponse.value); + chip::JniReferences::GetInstance().CreateBoxedObject(valueClassName.c_str(), valueCtorSignature.c_str(), jnivalue, + value); + + env->CallVoidMethod(javaCallbackRef, javaMethod, value); +} +CHIPUnitTestingClusterTestEmitTestFabricScopedEventResponseCallback:: +CHIPUnitTestingClusterTestEmitTestFabricScopedEventResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestEmitTestFabricScopedEventResponseCallback::~ +CHIPUnitTestingClusterTestEmitTestFabricScopedEventResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestEmitTestFabricScopedEventResponseCallback::CallbackFn( + void * context, + const chip::app::Clusters::UnitTesting::Commands::TestEmitTestFabricScopedEventResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Long;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject value; + std::string valueClassName = "java/lang/Long"; + std::string valueCtorSignature = "(J)V"; + jlong jnivalue = static_cast(dataResponse.value); + chip::JniReferences::GetInstance().CreateBoxedObject(valueClassName.c_str(), valueCtorSignature.c_str(), jnivalue, + value); + + env->CallVoidMethod(javaCallbackRef, javaMethod, value); +} +CHIPUnitTestingClusterTestBatchHelperResponseCallback::CHIPUnitTestingClusterTestBatchHelperResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestBatchHelperResponseCallback::~CHIPUnitTestingClusterTestBatchHelperResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestBatchHelperResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::TestBatchHelperResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "([B)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject buffer; + jbyteArray bufferByteArray = env->NewByteArray(static_cast(dataResponse.buffer.size())); + env->SetByteArrayRegion(bufferByteArray, 0, static_cast(dataResponse.buffer.size()), + reinterpret_cast(dataResponse.buffer.data())); + buffer = bufferByteArray; + + env->CallVoidMethod(javaCallbackRef, javaMethod, buffer); +} +CHIPUnitTestingClusterTestDifferentVendorMeiResponseCallback::CHIPUnitTestingClusterTestDifferentVendorMeiResponseCallback( + jobject javaCallback) : Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPUnitTestingClusterTestDifferentVendorMeiResponseCallback::~CHIPUnitTestingClusterTestDifferentVendorMeiResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPUnitTestingClusterTestDifferentVendorMeiResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::UnitTesting::Commands::TestDifferentVendorMeiResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/Long;)V", + &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject arg1; + std::string arg1ClassName = "java/lang/Integer"; + std::string arg1CtorSignature = "(I)V"; + jint jniarg1 = static_cast(dataResponse.arg1); + chip::JniReferences::GetInstance().CreateBoxedObject(arg1ClassName.c_str(), arg1CtorSignature.c_str(), jniarg1, arg1); + jobject eventNumber; + std::string eventNumberClassName = "java/lang/Long"; + std::string eventNumberCtorSignature = "(J)V"; + jlong jnieventNumber = static_cast(dataResponse.eventNumber); + chip::JniReferences::GetInstance().CreateBoxedObject(eventNumberClassName.c_str(), eventNumberCtorSignature.c_str(), + jnieventNumber, eventNumber); + + env->CallVoidMethod(javaCallbackRef, javaMethod, arg1, eventNumber); +} +CHIPSampleMeiClusterAddArgumentsResponseCallback::CHIPSampleMeiClusterAddArgumentsResponseCallback(jobject javaCallback) : + Callback::Callback(CallbackFn, this) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPSampleMeiClusterAddArgumentsResponseCallback::~CHIPSampleMeiClusterAddArgumentsResponseCallback() +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +}; + +void CHIPSampleMeiClusterAddArgumentsResponseCallback::CallbackFn( + void * context, const chip::app::Clusters::SampleMei::Commands::AddArgumentsResponse::DecodableType & dataResponse) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + jmethodID javaMethod; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); + + std::unique_ptr + cppCallback(reinterpret_cast(context), + chip::Platform::Delete); + VerifyOrReturn(cppCallback != nullptr, ChipLogError(Zcl, "Error invoking Java callback: failed to cast native callback")); + + javaCallbackRef = cppCallback->javaCallbackRef; + // Java callback is allowed to be null, exit early if this is the case. + VerifyOrReturn(javaCallbackRef != nullptr); + + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); + + jobject returnValue; + std::string returnValueClassName = "java/lang/Integer"; + std::string returnValueCtorSignature = "(I)V"; + jint jnireturnValue = static_cast(dataResponse.returnValue); + chip::JniReferences::GetInstance().CreateBoxedObject(returnValueClassName.c_str(), returnValueCtorSignature.c_str(), + jnireturnValue, returnValue); + + env->CallVoidMethod(javaCallbackRef, javaMethod, returnValue); +} +} // namespace chip diff --git a/src/controller/python/chip/clusters/CHIPClusters.py b/src/controller/python/chip/clusters/CHIPClusters.py index dd1af821617b0f..3d2d8ead23e721 100644 --- a/src/controller/python/chip/clusters/CHIPClusters.py +++ b/src/controller/python/chip/clusters/CHIPClusters.py @@ -6560,6 +6560,76 @@ class ChipClusters: }, }, } + _MESSAGES_CLUSTER_INFO = { + "clusterName": "Messages", + "clusterId": 0x00000097, + "commands": { + 0x00000000: { + "commandId": 0x00000000, + "commandName": "PresentMessagesRequest", + "args": { + "messages": "MessageStruct", + }, + }, + 0x00000001: { + "commandId": 0x00000001, + "commandName": "CancelMessagesRequest", + "args": { + "messageIDs": "bytes", + }, + }, + }, + "attributes": { + 0x00000000: { + "attributeName": "Messages", + "attributeId": 0x00000000, + "type": "", + "reportable": True, + }, + 0x00000001: { + "attributeName": "ActiveMessageIDs", + "attributeId": 0x00000001, + "type": "bytes", + "reportable": True, + }, + 0x0000FFF8: { + "attributeName": "GeneratedCommandList", + "attributeId": 0x0000FFF8, + "type": "int", + "reportable": True, + }, + 0x0000FFF9: { + "attributeName": "AcceptedCommandList", + "attributeId": 0x0000FFF9, + "type": "int", + "reportable": True, + }, + 0x0000FFFA: { + "attributeName": "EventList", + "attributeId": 0x0000FFFA, + "type": "int", + "reportable": True, + }, + 0x0000FFFB: { + "attributeName": "AttributeList", + "attributeId": 0x0000FFFB, + "type": "int", + "reportable": True, + }, + 0x0000FFFC: { + "attributeName": "FeatureMap", + "attributeId": 0x0000FFFC, + "type": "int", + "reportable": True, + }, + 0x0000FFFD: { + "attributeName": "ClusterRevision", + "attributeId": 0x0000FFFD, + "type": "int", + "reportable": True, + }, + }, + } _DEVICE_ENERGY_MANAGEMENT_CLUSTER_INFO = { "clusterName": "DeviceEnergyManagement", "clusterId": 0x00000098, @@ -14325,6 +14395,7 @@ class ChipClusters: 0x00000081: _VALVE_CONFIGURATION_AND_CONTROL_CLUSTER_INFO, 0x00000091: _ELECTRICAL_ENERGY_MEASUREMENT_CLUSTER_INFO, 0x00000096: _DEMAND_RESPONSE_LOAD_CONTROL_CLUSTER_INFO, + 0x00000097: _MESSAGES_CLUSTER_INFO, 0x00000098: _DEVICE_ENERGY_MANAGEMENT_CLUSTER_INFO, 0x00000099: _ENERGY_EVSE_CLUSTER_INFO, 0x0000009B: _ENERGY_PREFERENCE_CLUSTER_INFO, @@ -14443,6 +14514,7 @@ class ChipClusters: "ValveConfigurationAndControl": _VALVE_CONFIGURATION_AND_CONTROL_CLUSTER_INFO, "ElectricalEnergyMeasurement": _ELECTRICAL_ENERGY_MEASUREMENT_CLUSTER_INFO, "DemandResponseLoadControl": _DEMAND_RESPONSE_LOAD_CONTROL_CLUSTER_INFO, + "Messages": _MESSAGES_CLUSTER_INFO, "DeviceEnergyManagement": _DEVICE_ENERGY_MANAGEMENT_CLUSTER_INFO, "EnergyEvse": _ENERGY_EVSE_CLUSTER_INFO, "EnergyPreference": _ENERGY_PREFERENCE_CLUSTER_INFO, diff --git a/src/controller/python/chip/clusters/Objects.py b/src/controller/python/chip/clusters/Objects.py index 1eca5fdaacf105..cd71b6ea9c03fd 100644 --- a/src/controller/python/chip/clusters/Objects.py +++ b/src/controller/python/chip/clusters/Objects.py @@ -23155,6 +23155,335 @@ def descriptor(cls) -> ClusterObjectDescriptor: heatingSourceControl: 'typing.Union[None, Nullable, DemandResponseLoadControl.Structs.HeatingSourceControlStruct]' = None +@dataclass +class Messages(Cluster): + id: typing.ClassVar[int] = 0x00000097 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor(Label="messages", Tag=0x00000000, Type=typing.List[Messages.Structs.MessageStruct]), + ClusterObjectFieldDescriptor(Label="activeMessageIDs", Tag=0x00000001, Type=typing.List[bytes]), + ClusterObjectFieldDescriptor(Label="generatedCommandList", Tag=0x0000FFF8, Type=typing.List[uint]), + ClusterObjectFieldDescriptor(Label="acceptedCommandList", Tag=0x0000FFF9, Type=typing.List[uint]), + ClusterObjectFieldDescriptor(Label="eventList", Tag=0x0000FFFA, Type=typing.List[uint]), + ClusterObjectFieldDescriptor(Label="attributeList", Tag=0x0000FFFB, Type=typing.List[uint]), + ClusterObjectFieldDescriptor(Label="featureMap", Tag=0x0000FFFC, Type=uint), + ClusterObjectFieldDescriptor(Label="clusterRevision", Tag=0x0000FFFD, Type=uint), + ]) + + messages: 'typing.List[Messages.Structs.MessageStruct]' = None + activeMessageIDs: 'typing.List[bytes]' = None + generatedCommandList: 'typing.List[uint]' = None + acceptedCommandList: 'typing.List[uint]' = None + eventList: 'typing.List[uint]' = None + attributeList: 'typing.List[uint]' = None + featureMap: 'uint' = None + clusterRevision: 'uint' = None + + class Enums: + class FutureMessagePreferenceEnum(MatterIntEnum): + kAllowed = 0x00 + kIncreased = 0x01 + kReduced = 0x02 + kDisallowed = 0x03 + kBanned = 0x04 + # All received enum values that are not listed above will be mapped + # to kUnknownEnumValue. This is a helper enum value that should only + # be used by code to process how it handles receiving and unknown + # enum value. This specific should never be transmitted. + kUnknownEnumValue = 5, + + class MessagePriorityEnum(MatterIntEnum): + kLow = 0x00 + kMedium = 0x01 + kHigh = 0x02 + kCritical = 0x03 + # All received enum values that are not listed above will be mapped + # to kUnknownEnumValue. This is a helper enum value that should only + # be used by code to process how it handles receiving and unknown + # enum value. This specific should never be transmitted. + kUnknownEnumValue = 4, + + class Bitmaps: + class Feature(IntFlag): + kReceivedConfirmation = 0x1 + kConfirmationResponse = 0x2 + kConfirmationReply = 0x4 + kProtectedMessages = 0x8 + + class MessageControlBitmap(IntFlag): + kConfirmationRequired = 0x1 + kResponseRequired = 0x2 + kReplyMessage = 0x4 + kMessageConfirmed = 0x8 + kMessageProtected = 0x10 + + class Structs: + @dataclass + class MessageResponseOptionStruct(ClusterObject): + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor(Label="messageResponseID", Tag=0, Type=typing.Optional[uint]), + ClusterObjectFieldDescriptor(Label="label", Tag=1, Type=typing.Optional[str]), + ]) + + messageResponseID: 'typing.Optional[uint]' = None + label: 'typing.Optional[str]' = None + + @dataclass + class MessageStruct(ClusterObject): + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor(Label="messageID", Tag=0, Type=bytes), + ClusterObjectFieldDescriptor(Label="priority", Tag=1, Type=Messages.Enums.MessagePriorityEnum), + ClusterObjectFieldDescriptor(Label="messageControl", Tag=2, Type=uint), + ClusterObjectFieldDescriptor(Label="startTime", Tag=3, Type=typing.Union[Nullable, uint]), + ClusterObjectFieldDescriptor(Label="duration", Tag=4, Type=typing.Union[Nullable, uint]), + ClusterObjectFieldDescriptor(Label="messageText", Tag=5, Type=str), + ClusterObjectFieldDescriptor(Label="responses", Tag=6, Type=typing.Optional[typing.List[Messages.Structs.MessageResponseOptionStruct]]), + ]) + + messageID: 'bytes' = b"" + priority: 'Messages.Enums.MessagePriorityEnum' = 0 + messageControl: 'uint' = 0 + startTime: 'typing.Union[Nullable, uint]' = NullValue + duration: 'typing.Union[Nullable, uint]' = NullValue + messageText: 'str' = "" + responses: 'typing.Optional[typing.List[Messages.Structs.MessageResponseOptionStruct]]' = None + + class Commands: + @dataclass + class PresentMessagesRequest(ClusterCommand): + cluster_id: typing.ClassVar[int] = 0x00000097 + command_id: typing.ClassVar[int] = 0x00000000 + is_client: typing.ClassVar[bool] = True + response_type: typing.ClassVar[str] = None + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor(Label="messages", Tag=0, Type=typing.List[Messages.Structs.MessageStruct]), + ]) + + messages: 'typing.List[Messages.Structs.MessageStruct]' = field(default_factory=lambda: []) + + @dataclass + class CancelMessagesRequest(ClusterCommand): + cluster_id: typing.ClassVar[int] = 0x00000097 + command_id: typing.ClassVar[int] = 0x00000001 + is_client: typing.ClassVar[bool] = True + response_type: typing.ClassVar[str] = None + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor(Label="messageIDs", Tag=0, Type=typing.List[bytes]), + ]) + + messageIDs: 'typing.List[bytes]' = field(default_factory=lambda: []) + + class Attributes: + @dataclass + class Messages(ClusterAttributeDescriptor): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x00000097 + + @ChipUtility.classproperty + def attribute_id(cls) -> int: + return 0x00000000 + + @ChipUtility.classproperty + def attribute_type(cls) -> ClusterObjectFieldDescriptor: + return ClusterObjectFieldDescriptor(Type=typing.List[Messages.Structs.MessageStruct]) + + value: 'typing.List[Messages.Structs.MessageStruct]' = field(default_factory=lambda: []) + + @dataclass + class ActiveMessageIDs(ClusterAttributeDescriptor): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x00000097 + + @ChipUtility.classproperty + def attribute_id(cls) -> int: + return 0x00000001 + + @ChipUtility.classproperty + def attribute_type(cls) -> ClusterObjectFieldDescriptor: + return ClusterObjectFieldDescriptor(Type=typing.List[bytes]) + + value: 'typing.List[bytes]' = field(default_factory=lambda: []) + + @dataclass + class GeneratedCommandList(ClusterAttributeDescriptor): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x00000097 + + @ChipUtility.classproperty + def attribute_id(cls) -> int: + return 0x0000FFF8 + + @ChipUtility.classproperty + def attribute_type(cls) -> ClusterObjectFieldDescriptor: + return ClusterObjectFieldDescriptor(Type=typing.List[uint]) + + value: 'typing.List[uint]' = field(default_factory=lambda: []) + + @dataclass + class AcceptedCommandList(ClusterAttributeDescriptor): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x00000097 + + @ChipUtility.classproperty + def attribute_id(cls) -> int: + return 0x0000FFF9 + + @ChipUtility.classproperty + def attribute_type(cls) -> ClusterObjectFieldDescriptor: + return ClusterObjectFieldDescriptor(Type=typing.List[uint]) + + value: 'typing.List[uint]' = field(default_factory=lambda: []) + + @dataclass + class EventList(ClusterAttributeDescriptor): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x00000097 + + @ChipUtility.classproperty + def attribute_id(cls) -> int: + return 0x0000FFFA + + @ChipUtility.classproperty + def attribute_type(cls) -> ClusterObjectFieldDescriptor: + return ClusterObjectFieldDescriptor(Type=typing.List[uint]) + + value: 'typing.List[uint]' = field(default_factory=lambda: []) + + @dataclass + class AttributeList(ClusterAttributeDescriptor): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x00000097 + + @ChipUtility.classproperty + def attribute_id(cls) -> int: + return 0x0000FFFB + + @ChipUtility.classproperty + def attribute_type(cls) -> ClusterObjectFieldDescriptor: + return ClusterObjectFieldDescriptor(Type=typing.List[uint]) + + value: 'typing.List[uint]' = field(default_factory=lambda: []) + + @dataclass + class FeatureMap(ClusterAttributeDescriptor): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x00000097 + + @ChipUtility.classproperty + def attribute_id(cls) -> int: + return 0x0000FFFC + + @ChipUtility.classproperty + def attribute_type(cls) -> ClusterObjectFieldDescriptor: + return ClusterObjectFieldDescriptor(Type=uint) + + value: 'uint' = 0 + + @dataclass + class ClusterRevision(ClusterAttributeDescriptor): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x00000097 + + @ChipUtility.classproperty + def attribute_id(cls) -> int: + return 0x0000FFFD + + @ChipUtility.classproperty + def attribute_type(cls) -> ClusterObjectFieldDescriptor: + return ClusterObjectFieldDescriptor(Type=uint) + + value: 'uint' = 0 + + class Events: + @dataclass + class MessageQueued(ClusterEvent): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x00000097 + + @ChipUtility.classproperty + def event_id(cls) -> int: + return 0x00000000 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor(Label="messageID", Tag=0, Type=bytes), + ]) + + messageID: 'bytes' = b"" + + @dataclass + class MessagePresented(ClusterEvent): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x00000097 + + @ChipUtility.classproperty + def event_id(cls) -> int: + return 0x00000001 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor(Label="messageID", Tag=0, Type=bytes), + ]) + + messageID: 'bytes' = b"" + + @dataclass + class MessageComplete(ClusterEvent): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x00000097 + + @ChipUtility.classproperty + def event_id(cls) -> int: + return 0x00000002 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor(Label="messageID", Tag=0, Type=bytes), + ClusterObjectFieldDescriptor(Label="responseID", Tag=1, Type=typing.Union[None, Nullable, uint]), + ClusterObjectFieldDescriptor(Label="reply", Tag=2, Type=typing.Union[None, Nullable, str]), + ClusterObjectFieldDescriptor(Label="futureMessagesPreference", Tag=3, Type=typing.Union[Nullable, Messages.Enums.FutureMessagePreferenceEnum]), + ]) + + messageID: 'bytes' = b"" + responseID: 'typing.Union[None, Nullable, uint]' = None + reply: 'typing.Union[None, Nullable, str]' = None + futureMessagesPreference: 'typing.Union[Nullable, Messages.Enums.FutureMessagePreferenceEnum]' = NullValue + + @dataclass class DeviceEnergyManagement(Cluster): id: typing.ClassVar[int] = 0x00000098 diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRAttributeSpecifiedCheck.mm b/src/darwin/Framework/CHIP/zap-generated/MTRAttributeSpecifiedCheck.mm index e190bc97debd9d..3685e445500fd0 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRAttributeSpecifiedCheck.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRAttributeSpecifiedCheck.mm @@ -3023,6 +3023,39 @@ static BOOL AttributeIsSpecifiedInDemandResponseLoadControlCluster(AttributeId a } } } +static BOOL AttributeIsSpecifiedInMessagesCluster(AttributeId aAttributeId) +{ + using namespace Clusters::Messages; + switch (aAttributeId) { + case Attributes::Messages::Id: { + return YES; + } + case Attributes::ActiveMessageIDs::Id: { + return YES; + } + case Attributes::GeneratedCommandList::Id: { + return YES; + } + case Attributes::AcceptedCommandList::Id: { + return YES; + } + case Attributes::EventList::Id: { + return YES; + } + case Attributes::AttributeList::Id: { + return YES; + } + case Attributes::FeatureMap::Id: { + return YES; + } + case Attributes::ClusterRevision::Id: { + return YES; + } + default: { + return NO; + } + } +} static BOOL AttributeIsSpecifiedInDeviceEnergyManagementCluster(AttributeId aAttributeId) { using namespace Clusters::DeviceEnergyManagement; @@ -6558,6 +6591,9 @@ BOOL MTRAttributeIsSpecified(ClusterId aClusterId, AttributeId aAttributeId) case Clusters::DemandResponseLoadControl::Id: { return AttributeIsSpecifiedInDemandResponseLoadControlCluster(aAttributeId); } + case Clusters::Messages::Id: { + return AttributeIsSpecifiedInMessagesCluster(aAttributeId); + } case Clusters::DeviceEnergyManagement::Id: { return AttributeIsSpecifiedInDeviceEnergyManagementCluster(aAttributeId); } diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm b/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm index 3913c23eae31f8..75ec47f5e9587e 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm @@ -8251,6 +8251,124 @@ static id _Nullable DecodeAttributeValueForDemandResponseLoadControlCluster(Attr *aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB; return nil; } +static id _Nullable DecodeAttributeValueForMessagesCluster(AttributeId aAttributeId, TLV::TLVReader & aReader, CHIP_ERROR * aError) +{ + using namespace Clusters::Messages; + switch (aAttributeId) { + case Attributes::Messages::Id: { + using TypeInfo = Attributes::Messages::TypeInfo; + TypeInfo::DecodableType cppValue; + *aError = DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) { + return nil; + } + NSArray * _Nonnull value; + { // Scope for our temporary variables + auto * array_0 = [NSMutableArray new]; + auto iter_0 = cppValue.begin(); + while (iter_0.Next()) { + auto & entry_0 = iter_0.GetValue(); + MTRMessagesClusterMessageStruct * newElement_0; + newElement_0 = [MTRMessagesClusterMessageStruct new]; + newElement_0.messageID = AsData(entry_0.messageID); + newElement_0.priority = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.priority)]; + newElement_0.messageControl = [NSNumber numberWithUnsignedChar:entry_0.messageControl.Raw()]; + if (entry_0.startTime.IsNull()) { + newElement_0.startTime = nil; + } else { + newElement_0.startTime = [NSNumber numberWithUnsignedInt:entry_0.startTime.Value()]; + } + if (entry_0.duration.IsNull()) { + newElement_0.duration = nil; + } else { + newElement_0.duration = [NSNumber numberWithUnsignedShort:entry_0.duration.Value()]; + } + newElement_0.messageText = AsString(entry_0.messageText); + if (newElement_0.messageText == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } + if (entry_0.responses.HasValue()) { + { // Scope for our temporary variables + auto * array_3 = [NSMutableArray new]; + auto iter_3 = entry_0.responses.Value().begin(); + while (iter_3.Next()) { + auto & entry_3 = iter_3.GetValue(); + MTRMessagesClusterMessageResponseOptionStruct * newElement_3; + newElement_3 = [MTRMessagesClusterMessageResponseOptionStruct new]; + if (entry_3.messageResponseID.HasValue()) { + newElement_3.messageResponseID = [NSNumber numberWithUnsignedInt:entry_3.messageResponseID.Value()]; + } else { + newElement_3.messageResponseID = nil; + } + if (entry_3.label.HasValue()) { + newElement_3.label = AsString(entry_3.label.Value()); + if (newElement_3.label == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } + } else { + newElement_3.label = nil; + } + [array_3 addObject:newElement_3]; + } + CHIP_ERROR err = iter_3.GetStatus(); + if (err != CHIP_NO_ERROR) { + *aError = err; + return nil; + } + newElement_0.responses = array_3; + } + } else { + newElement_0.responses = nil; + } + [array_0 addObject:newElement_0]; + } + CHIP_ERROR err = iter_0.GetStatus(); + if (err != CHIP_NO_ERROR) { + *aError = err; + return nil; + } + value = array_0; + } + return value; + } + case Attributes::ActiveMessageIDs::Id: { + using TypeInfo = Attributes::ActiveMessageIDs::TypeInfo; + TypeInfo::DecodableType cppValue; + *aError = DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) { + return nil; + } + NSArray * _Nonnull value; + { // Scope for our temporary variables + auto * array_0 = [NSMutableArray new]; + auto iter_0 = cppValue.begin(); + while (iter_0.Next()) { + auto & entry_0 = iter_0.GetValue(); + NSData * newElement_0; + newElement_0 = AsData(entry_0); + [array_0 addObject:newElement_0]; + } + CHIP_ERROR err = iter_0.GetStatus(); + if (err != CHIP_NO_ERROR) { + *aError = err; + return nil; + } + value = array_0; + } + return value; + } + default: { + break; + } + } + + *aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB; + return nil; +} static id _Nullable DecodeAttributeValueForDeviceEnergyManagementCluster(AttributeId aAttributeId, TLV::TLVReader & aReader, CHIP_ERROR * aError) { using namespace Clusters::DeviceEnergyManagement; @@ -18843,6 +18961,9 @@ id _Nullable MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::T case Clusters::DemandResponseLoadControl::Id: { return DecodeAttributeValueForDemandResponseLoadControlCluster(aPath.mAttributeId, aReader, aError); } + case Clusters::Messages::Id: { + return DecodeAttributeValueForMessagesCluster(aPath.mAttributeId, aReader, aError); + } case Clusters::DeviceEnergyManagement::Id: { return DecodeAttributeValueForDeviceEnergyManagementCluster(aPath.mAttributeId, aReader, aError); } diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h index d696bb1b611d10..c0c29601f3e00a 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h @@ -7495,6 +7495,92 @@ MTR_PROVISIONALLY_AVAILABLE @end +/** + * Cluster Messages + * + * This cluster provides an interface for passing messages to be presented by a device. + */ +MTR_PROVISIONALLY_AVAILABLE +@interface MTRBaseClusterMessages : MTRGenericBaseCluster + +/** + * Command PresentMessagesRequest + * + * Command for requesting messages be presented + */ +- (void)presentMessagesRequestWithParams:(MTRMessagesClusterPresentMessagesRequestParams *)params completion:(MTRStatusCompletion)completion MTR_PROVISIONALLY_AVAILABLE; +/** + * Command CancelMessagesRequest + * + * Command for cancelling message present requests + */ +- (void)cancelMessagesRequestWithParams:(MTRMessagesClusterCancelMessagesRequestParams *)params completion:(MTRStatusCompletion)completion MTR_PROVISIONALLY_AVAILABLE; + +- (void)readAttributeMessagesWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; +- (void)subscribeAttributeMessagesWithParams:(MTRSubscribeParams *)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler MTR_PROVISIONALLY_AVAILABLE; ++ (void)readAttributeMessagesWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; + +- (void)readAttributeActiveMessageIDsWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; +- (void)subscribeAttributeActiveMessageIDsWithParams:(MTRSubscribeParams *)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler MTR_PROVISIONALLY_AVAILABLE; ++ (void)readAttributeActiveMessageIDsWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; + +- (void)readAttributeGeneratedCommandListWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; +- (void)subscribeAttributeGeneratedCommandListWithParams:(MTRSubscribeParams *)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler MTR_PROVISIONALLY_AVAILABLE; ++ (void)readAttributeGeneratedCommandListWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; + +- (void)readAttributeAcceptedCommandListWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; +- (void)subscribeAttributeAcceptedCommandListWithParams:(MTRSubscribeParams *)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler MTR_PROVISIONALLY_AVAILABLE; ++ (void)readAttributeAcceptedCommandListWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; + +- (void)readAttributeEventListWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; +- (void)subscribeAttributeEventListWithParams:(MTRSubscribeParams *)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler MTR_PROVISIONALLY_AVAILABLE; ++ (void)readAttributeEventListWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; + +- (void)readAttributeAttributeListWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; +- (void)subscribeAttributeAttributeListWithParams:(MTRSubscribeParams *)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler MTR_PROVISIONALLY_AVAILABLE; ++ (void)readAttributeAttributeListWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; + +- (void)readAttributeFeatureMapWithCompletion:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; +- (void)subscribeAttributeFeatureMapWithParams:(MTRSubscribeParams *)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))reportHandler MTR_PROVISIONALLY_AVAILABLE; ++ (void)readAttributeFeatureMapWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; + +- (void)readAttributeClusterRevisionWithCompletion:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; +- (void)subscribeAttributeClusterRevisionWithParams:(MTRSubscribeParams *)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))reportHandler MTR_PROVISIONALLY_AVAILABLE; ++ (void)readAttributeClusterRevisionWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; + +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)new NS_UNAVAILABLE; + +@end + +@interface MTRBaseClusterMessages (Availability) + +/** + * For all instance methods (reads, writes, commands) that take a completion, + * the completion will be called on the provided queue. + */ +- (instancetype _Nullable)initWithDevice:(MTRBaseDevice *)device + endpointID:(NSNumber *)endpointID + queue:(dispatch_queue_t)queue MTR_PROVISIONALLY_AVAILABLE; + +@end + /** * Cluster Device Energy Management * @@ -17530,6 +17616,36 @@ typedef NS_OPTIONS(uint32_t, MTRDemandResponseLoadControlFeature) { MTRDemandResponseLoadControlFeatureHeatingSource MTR_PROVISIONALLY_AVAILABLE = 0x40, } MTR_PROVISIONALLY_AVAILABLE; +typedef NS_ENUM(uint8_t, MTRMessagesFutureMessagePreference) { + MTRMessagesFutureMessagePreferenceAllowed MTR_PROVISIONALLY_AVAILABLE = 0x00, + MTRMessagesFutureMessagePreferenceIncreased MTR_PROVISIONALLY_AVAILABLE = 0x01, + MTRMessagesFutureMessagePreferenceReduced MTR_PROVISIONALLY_AVAILABLE = 0x02, + MTRMessagesFutureMessagePreferenceDisallowed MTR_PROVISIONALLY_AVAILABLE = 0x03, + MTRMessagesFutureMessagePreferenceBanned MTR_PROVISIONALLY_AVAILABLE = 0x04, +} MTR_PROVISIONALLY_AVAILABLE; + +typedef NS_ENUM(uint8_t, MTRMessagesMessagePriority) { + MTRMessagesMessagePriorityLow MTR_PROVISIONALLY_AVAILABLE = 0x00, + MTRMessagesMessagePriorityMedium MTR_PROVISIONALLY_AVAILABLE = 0x01, + MTRMessagesMessagePriorityHigh MTR_PROVISIONALLY_AVAILABLE = 0x02, + MTRMessagesMessagePriorityCritical MTR_PROVISIONALLY_AVAILABLE = 0x03, +} MTR_PROVISIONALLY_AVAILABLE; + +typedef NS_OPTIONS(uint32_t, MTRMessagesFeature) { + MTRMessagesFeatureReceivedConfirmation MTR_PROVISIONALLY_AVAILABLE = 0x1, + MTRMessagesFeatureConfirmationResponse MTR_PROVISIONALLY_AVAILABLE = 0x2, + MTRMessagesFeatureConfirmationReply MTR_PROVISIONALLY_AVAILABLE = 0x4, + MTRMessagesFeatureProtectedMessages MTR_PROVISIONALLY_AVAILABLE = 0x8, +} MTR_PROVISIONALLY_AVAILABLE; + +typedef NS_OPTIONS(uint8_t, MTRMessagesMessageControlBitmap) { + MTRMessagesMessageControlBitmapConfirmationRequired MTR_PROVISIONALLY_AVAILABLE = 0x1, + MTRMessagesMessageControlBitmapResponseRequired MTR_PROVISIONALLY_AVAILABLE = 0x2, + MTRMessagesMessageControlBitmapReplyMessage MTR_PROVISIONALLY_AVAILABLE = 0x4, + MTRMessagesMessageControlBitmapMessageConfirmed MTR_PROVISIONALLY_AVAILABLE = 0x8, + MTRMessagesMessageControlBitmapMessageProtected MTR_PROVISIONALLY_AVAILABLE = 0x10, +} MTR_PROVISIONALLY_AVAILABLE; + typedef NS_ENUM(uint8_t, MTRDeviceEnergyManagementAdjustmentCause) { MTRDeviceEnergyManagementAdjustmentCauseLocalOptimization MTR_PROVISIONALLY_AVAILABLE = 0x00, MTRDeviceEnergyManagementAdjustmentCauseGridOptimization MTR_PROVISIONALLY_AVAILABLE = 0x01, diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm index 7a02734aca7b6e..0df20ec55b9d5a 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm @@ -51008,6 +51008,347 @@ + (void)readAttributeClusterRevisionWithClusterStateCache:(MTRClusterStateCacheC @end +@implementation MTRBaseClusterMessages + +- (void)presentMessagesRequestWithParams:(MTRMessagesClusterPresentMessagesRequestParams *)params completion:(MTRStatusCompletion)completion +{ + if (params == nil) { + params = [[MTRMessagesClusterPresentMessagesRequestParams + alloc] init]; + } + + auto responseHandler = ^(id _Nullable response, NSError * _Nullable error) { + completion(error); + }; + + auto * timedInvokeTimeoutMs = params.timedInvokeTimeoutMs; + + using RequestType = Messages::Commands::PresentMessagesRequest::Type; + [self.device _invokeKnownCommandWithEndpointID:self.endpointID + clusterID:@(RequestType::GetClusterId()) + commandID:@(RequestType::GetCommandId()) + commandPayload:params + timedInvokeTimeout:timedInvokeTimeoutMs + serverSideProcessingTimeout:params.serverSideProcessingTimeout + responseClass:nil + queue:self.callbackQueue + completion:responseHandler]; +} +- (void)cancelMessagesRequestWithParams:(MTRMessagesClusterCancelMessagesRequestParams *)params completion:(MTRStatusCompletion)completion +{ + if (params == nil) { + params = [[MTRMessagesClusterCancelMessagesRequestParams + alloc] init]; + } + + auto responseHandler = ^(id _Nullable response, NSError * _Nullable error) { + completion(error); + }; + + auto * timedInvokeTimeoutMs = params.timedInvokeTimeoutMs; + + using RequestType = Messages::Commands::CancelMessagesRequest::Type; + [self.device _invokeKnownCommandWithEndpointID:self.endpointID + clusterID:@(RequestType::GetClusterId()) + commandID:@(RequestType::GetCommandId()) + commandPayload:params + timedInvokeTimeout:timedInvokeTimeoutMs + serverSideProcessingTimeout:params.serverSideProcessingTimeout + responseClass:nil + queue:self.callbackQueue + completion:responseHandler]; +} + +- (void)readAttributeMessagesWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::Messages::TypeInfo; + [self.device _readKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:nil + queue:self.callbackQueue + completion:completion]; +} + +- (void)subscribeAttributeMessagesWithParams:(MTRSubscribeParams * _Nonnull)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler +{ + using TypeInfo = Messages::Attributes::Messages::TypeInfo; + [self.device _subscribeToKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:params + queue:self.callbackQueue + reportHandler:reportHandler + subscriptionEstablished:subscriptionEstablished]; +} + ++ (void)readAttributeMessagesWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::Messages::TypeInfo; + [clusterStateCacheContainer + _readKnownCachedAttributeWithEndpointID:static_cast([endpoint unsignedShortValue]) + clusterID:TypeInfo::GetClusterId() + attributeID:TypeInfo::GetAttributeId() + queue:queue + completion:completion]; +} + +- (void)readAttributeActiveMessageIDsWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::ActiveMessageIDs::TypeInfo; + [self.device _readKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:nil + queue:self.callbackQueue + completion:completion]; +} + +- (void)subscribeAttributeActiveMessageIDsWithParams:(MTRSubscribeParams * _Nonnull)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler +{ + using TypeInfo = Messages::Attributes::ActiveMessageIDs::TypeInfo; + [self.device _subscribeToKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:params + queue:self.callbackQueue + reportHandler:reportHandler + subscriptionEstablished:subscriptionEstablished]; +} + ++ (void)readAttributeActiveMessageIDsWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::ActiveMessageIDs::TypeInfo; + [clusterStateCacheContainer + _readKnownCachedAttributeWithEndpointID:static_cast([endpoint unsignedShortValue]) + clusterID:TypeInfo::GetClusterId() + attributeID:TypeInfo::GetAttributeId() + queue:queue + completion:completion]; +} + +- (void)readAttributeGeneratedCommandListWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::GeneratedCommandList::TypeInfo; + [self.device _readKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:nil + queue:self.callbackQueue + completion:completion]; +} + +- (void)subscribeAttributeGeneratedCommandListWithParams:(MTRSubscribeParams * _Nonnull)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler +{ + using TypeInfo = Messages::Attributes::GeneratedCommandList::TypeInfo; + [self.device _subscribeToKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:params + queue:self.callbackQueue + reportHandler:reportHandler + subscriptionEstablished:subscriptionEstablished]; +} + ++ (void)readAttributeGeneratedCommandListWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::GeneratedCommandList::TypeInfo; + [clusterStateCacheContainer + _readKnownCachedAttributeWithEndpointID:static_cast([endpoint unsignedShortValue]) + clusterID:TypeInfo::GetClusterId() + attributeID:TypeInfo::GetAttributeId() + queue:queue + completion:completion]; +} + +- (void)readAttributeAcceptedCommandListWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::AcceptedCommandList::TypeInfo; + [self.device _readKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:nil + queue:self.callbackQueue + completion:completion]; +} + +- (void)subscribeAttributeAcceptedCommandListWithParams:(MTRSubscribeParams * _Nonnull)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler +{ + using TypeInfo = Messages::Attributes::AcceptedCommandList::TypeInfo; + [self.device _subscribeToKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:params + queue:self.callbackQueue + reportHandler:reportHandler + subscriptionEstablished:subscriptionEstablished]; +} + ++ (void)readAttributeAcceptedCommandListWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::AcceptedCommandList::TypeInfo; + [clusterStateCacheContainer + _readKnownCachedAttributeWithEndpointID:static_cast([endpoint unsignedShortValue]) + clusterID:TypeInfo::GetClusterId() + attributeID:TypeInfo::GetAttributeId() + queue:queue + completion:completion]; +} + +- (void)readAttributeEventListWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::EventList::TypeInfo; + [self.device _readKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:nil + queue:self.callbackQueue + completion:completion]; +} + +- (void)subscribeAttributeEventListWithParams:(MTRSubscribeParams * _Nonnull)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler +{ + using TypeInfo = Messages::Attributes::EventList::TypeInfo; + [self.device _subscribeToKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:params + queue:self.callbackQueue + reportHandler:reportHandler + subscriptionEstablished:subscriptionEstablished]; +} + ++ (void)readAttributeEventListWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::EventList::TypeInfo; + [clusterStateCacheContainer + _readKnownCachedAttributeWithEndpointID:static_cast([endpoint unsignedShortValue]) + clusterID:TypeInfo::GetClusterId() + attributeID:TypeInfo::GetAttributeId() + queue:queue + completion:completion]; +} + +- (void)readAttributeAttributeListWithCompletion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::AttributeList::TypeInfo; + [self.device _readKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:nil + queue:self.callbackQueue + completion:completion]; +} + +- (void)subscribeAttributeAttributeListWithParams:(MTRSubscribeParams * _Nonnull)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler +{ + using TypeInfo = Messages::Attributes::AttributeList::TypeInfo; + [self.device _subscribeToKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:params + queue:self.callbackQueue + reportHandler:reportHandler + subscriptionEstablished:subscriptionEstablished]; +} + ++ (void)readAttributeAttributeListWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::AttributeList::TypeInfo; + [clusterStateCacheContainer + _readKnownCachedAttributeWithEndpointID:static_cast([endpoint unsignedShortValue]) + clusterID:TypeInfo::GetClusterId() + attributeID:TypeInfo::GetAttributeId() + queue:queue + completion:completion]; +} + +- (void)readAttributeFeatureMapWithCompletion:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::FeatureMap::TypeInfo; + [self.device _readKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:nil + queue:self.callbackQueue + completion:completion]; +} + +- (void)subscribeAttributeFeatureMapWithParams:(MTRSubscribeParams * _Nonnull)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))reportHandler +{ + using TypeInfo = Messages::Attributes::FeatureMap::TypeInfo; + [self.device _subscribeToKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:params + queue:self.callbackQueue + reportHandler:reportHandler + subscriptionEstablished:subscriptionEstablished]; +} + ++ (void)readAttributeFeatureMapWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::FeatureMap::TypeInfo; + [clusterStateCacheContainer + _readKnownCachedAttributeWithEndpointID:static_cast([endpoint unsignedShortValue]) + clusterID:TypeInfo::GetClusterId() + attributeID:TypeInfo::GetAttributeId() + queue:queue + completion:completion]; +} + +- (void)readAttributeClusterRevisionWithCompletion:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::ClusterRevision::TypeInfo; + [self.device _readKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:nil + queue:self.callbackQueue + completion:completion]; +} + +- (void)subscribeAttributeClusterRevisionWithParams:(MTRSubscribeParams * _Nonnull)params + subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished + reportHandler:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))reportHandler +{ + using TypeInfo = Messages::Attributes::ClusterRevision::TypeInfo; + [self.device _subscribeToKnownAttributeWithEndpointID:self.endpointID + clusterID:@(TypeInfo::GetClusterId()) + attributeID:@(TypeInfo::GetAttributeId()) + params:params + queue:self.callbackQueue + reportHandler:reportHandler + subscriptionEstablished:subscriptionEstablished]; +} + ++ (void)readAttributeClusterRevisionWithClusterStateCache:(MTRClusterStateCacheContainer *)clusterStateCacheContainer endpoint:(NSNumber *)endpoint queue:(dispatch_queue_t)queue completion:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completion +{ + using TypeInfo = Messages::Attributes::ClusterRevision::TypeInfo; + [clusterStateCacheContainer + _readKnownCachedAttributeWithEndpointID:static_cast([endpoint unsignedShortValue]) + clusterID:TypeInfo::GetClusterId() + attributeID:TypeInfo::GetAttributeId() + queue:queue + completion:completion]; +} + +@end + @implementation MTRBaseClusterDeviceEnergyManagement - (void)powerAdjustRequestWithParams:(MTRDeviceEnergyManagementClusterPowerAdjustRequestParams *)params completion:(MTRStatusCompletion)completion diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h b/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h index 6cf1cb51a92c82..0264d42d26f001 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h @@ -151,6 +151,7 @@ typedef NS_ENUM(uint32_t, MTRClusterIDType) { MTRClusterIDTypeValveConfigurationAndControlID MTR_PROVISIONALLY_AVAILABLE = 0x00000081, MTRClusterIDTypeElectricalEnergyMeasurementID MTR_PROVISIONALLY_AVAILABLE = 0x00000091, MTRClusterIDTypeDemandResponseLoadControlID MTR_PROVISIONALLY_AVAILABLE = 0x00000096, + MTRClusterIDTypeMessagesID MTR_PROVISIONALLY_AVAILABLE = 0x00000097, MTRClusterIDTypeDeviceEnergyManagementID MTR_PROVISIONALLY_AVAILABLE = 0x00000098, MTRClusterIDTypeEnergyEVSEID MTR_PROVISIONALLY_AVAILABLE = 0x00000099, MTRClusterIDTypeEnergyPreferenceID MTR_PROVISIONALLY_AVAILABLE = 0x0000009B, @@ -2607,6 +2608,16 @@ typedef NS_ENUM(uint32_t, MTRAttributeIDType) { MTRAttributeIDTypeClusterDemandResponseLoadControlAttributeFeatureMapID MTR_PROVISIONALLY_AVAILABLE = MTRAttributeIDTypeGlobalAttributeFeatureMapID, MTRAttributeIDTypeClusterDemandResponseLoadControlAttributeClusterRevisionID MTR_PROVISIONALLY_AVAILABLE = MTRAttributeIDTypeGlobalAttributeClusterRevisionID, + // Cluster Messages attributes + MTRAttributeIDTypeClusterMessagesAttributeMessagesID MTR_PROVISIONALLY_AVAILABLE = 0x00000000, + MTRAttributeIDTypeClusterMessagesAttributeActiveMessageIDsID MTR_PROVISIONALLY_AVAILABLE = 0x00000001, + MTRAttributeIDTypeClusterMessagesAttributeGeneratedCommandListID MTR_PROVISIONALLY_AVAILABLE = MTRAttributeIDTypeGlobalAttributeGeneratedCommandListID, + MTRAttributeIDTypeClusterMessagesAttributeAcceptedCommandListID MTR_PROVISIONALLY_AVAILABLE = MTRAttributeIDTypeGlobalAttributeAcceptedCommandListID, + MTRAttributeIDTypeClusterMessagesAttributeEventListID MTR_PROVISIONALLY_AVAILABLE = MTRAttributeIDTypeGlobalAttributeEventListID, + MTRAttributeIDTypeClusterMessagesAttributeAttributeListID MTR_PROVISIONALLY_AVAILABLE = MTRAttributeIDTypeGlobalAttributeAttributeListID, + MTRAttributeIDTypeClusterMessagesAttributeFeatureMapID MTR_PROVISIONALLY_AVAILABLE = MTRAttributeIDTypeGlobalAttributeFeatureMapID, + MTRAttributeIDTypeClusterMessagesAttributeClusterRevisionID MTR_PROVISIONALLY_AVAILABLE = MTRAttributeIDTypeGlobalAttributeClusterRevisionID, + // Cluster DeviceEnergyManagement attributes MTRAttributeIDTypeClusterDeviceEnergyManagementAttributeESATypeID MTR_PROVISIONALLY_AVAILABLE = 0x00000000, MTRAttributeIDTypeClusterDeviceEnergyManagementAttributeESACanGenerateID MTR_PROVISIONALLY_AVAILABLE = 0x00000001, @@ -6231,6 +6242,10 @@ typedef NS_ENUM(uint32_t, MTRCommandIDType) { MTRCommandIDTypeClusterDemandResponseLoadControlCommandRemoveLoadControlEventRequestID MTR_PROVISIONALLY_AVAILABLE = 0x00000003, MTRCommandIDTypeClusterDemandResponseLoadControlCommandClearLoadControlEventsRequestID MTR_PROVISIONALLY_AVAILABLE = 0x00000004, + // Cluster Messages commands + MTRCommandIDTypeClusterMessagesCommandPresentMessagesRequestID MTR_PROVISIONALLY_AVAILABLE = 0x00000000, + MTRCommandIDTypeClusterMessagesCommandCancelMessagesRequestID MTR_PROVISIONALLY_AVAILABLE = 0x00000001, + // Cluster DeviceEnergyManagement commands MTRCommandIDTypeClusterDeviceEnergyManagementCommandPowerAdjustRequestID MTR_PROVISIONALLY_AVAILABLE = 0x00000000, MTRCommandIDTypeClusterDeviceEnergyManagementCommandCancelPowerAdjustRequestID MTR_PROVISIONALLY_AVAILABLE = 0x00000001, @@ -7152,6 +7167,11 @@ typedef NS_ENUM(uint32_t, MTREventIDType) { // Cluster DemandResponseLoadControl events MTREventIDTypeClusterDemandResponseLoadControlEventLoadControlEventStatusChangeID MTR_PROVISIONALLY_AVAILABLE = 0x00000000, + // Cluster Messages events + MTREventIDTypeClusterMessagesEventMessageQueuedID MTR_PROVISIONALLY_AVAILABLE = 0x00000000, + MTREventIDTypeClusterMessagesEventMessagePresentedID MTR_PROVISIONALLY_AVAILABLE = 0x00000001, + MTREventIDTypeClusterMessagesEventMessageCompleteID MTR_PROVISIONALLY_AVAILABLE = 0x00000002, + // Cluster DeviceEnergyManagement events MTREventIDTypeClusterDeviceEnergyManagementEventPowerAdjustStartID MTR_PROVISIONALLY_AVAILABLE = 0x00000000, MTREventIDTypeClusterDeviceEnergyManagementEventPowerAdjustEndID MTR_PROVISIONALLY_AVAILABLE = 0x00000001, diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRClusters.h b/src/darwin/Framework/CHIP/zap-generated/MTRClusters.h index 9cbe6921ee0b60..f9cfd98a478930 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRClusters.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRClusters.h @@ -3553,6 +3553,49 @@ MTR_PROVISIONALLY_AVAILABLE @end +/** + * Cluster Messages + * This cluster provides an interface for passing messages to be presented by a device. + */ +MTR_PROVISIONALLY_AVAILABLE +@interface MTRClusterMessages : MTRGenericCluster + +- (void)presentMessagesRequestWithParams:(MTRMessagesClusterPresentMessagesRequestParams *)params expectedValues:(NSArray *> * _Nullable)expectedDataValueDictionaries expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(MTRStatusCompletion)completion MTR_PROVISIONALLY_AVAILABLE; +- (void)cancelMessagesRequestWithParams:(MTRMessagesClusterCancelMessagesRequestParams *)params expectedValues:(NSArray *> * _Nullable)expectedDataValueDictionaries expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(MTRStatusCompletion)completion MTR_PROVISIONALLY_AVAILABLE; + +- (NSDictionary * _Nullable)readAttributeMessagesWithParams:(MTRReadParams * _Nullable)params MTR_PROVISIONALLY_AVAILABLE; + +- (NSDictionary * _Nullable)readAttributeActiveMessageIDsWithParams:(MTRReadParams * _Nullable)params MTR_PROVISIONALLY_AVAILABLE; + +- (NSDictionary * _Nullable)readAttributeGeneratedCommandListWithParams:(MTRReadParams * _Nullable)params MTR_PROVISIONALLY_AVAILABLE; + +- (NSDictionary * _Nullable)readAttributeAcceptedCommandListWithParams:(MTRReadParams * _Nullable)params MTR_PROVISIONALLY_AVAILABLE; + +- (NSDictionary * _Nullable)readAttributeEventListWithParams:(MTRReadParams * _Nullable)params MTR_PROVISIONALLY_AVAILABLE; + +- (NSDictionary * _Nullable)readAttributeAttributeListWithParams:(MTRReadParams * _Nullable)params MTR_PROVISIONALLY_AVAILABLE; + +- (NSDictionary * _Nullable)readAttributeFeatureMapWithParams:(MTRReadParams * _Nullable)params MTR_PROVISIONALLY_AVAILABLE; + +- (NSDictionary * _Nullable)readAttributeClusterRevisionWithParams:(MTRReadParams * _Nullable)params MTR_PROVISIONALLY_AVAILABLE; + +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)new NS_UNAVAILABLE; + +@end + +@interface MTRClusterMessages (Availability) + +/** + * For all instance methods that take a completion (i.e. command invocations), + * the completion will be called on the provided queue. + */ +- (instancetype _Nullable)initWithDevice:(MTRDevice *)device + endpointID:(NSNumber *)endpointID + queue:(dispatch_queue_t)queue MTR_PROVISIONALLY_AVAILABLE; + +@end + /** * Cluster Device Energy Management * This cluster allows a client to manage the power draw of a device. An example of such a client could be an Energy Management System (EMS) which controls an Energy Smart Appliance (ESA). diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm b/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm index 63edcb6fb3e1b6..855d65f15475ad 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm @@ -9457,6 +9457,104 @@ - (void)writeAttributeDefaultRandomDurationWithValue:(NSDictionary *> * _Nullable)expectedValues expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(MTRStatusCompletion)completion +{ + if (params == nil) { + params = [[MTRMessagesClusterPresentMessagesRequestParams + alloc] init]; + } + + auto responseHandler = ^(id _Nullable response, NSError * _Nullable error) { + completion(error); + }; + + auto * timedInvokeTimeoutMs = params.timedInvokeTimeoutMs; + + using RequestType = Messages::Commands::PresentMessagesRequest::Type; + [self.device _invokeKnownCommandWithEndpointID:self.endpointID + clusterID:@(RequestType::GetClusterId()) + commandID:@(RequestType::GetCommandId()) + commandPayload:params + expectedValues:expectedValues + expectedValueInterval:expectedValueIntervalMs + timedInvokeTimeout:timedInvokeTimeoutMs + serverSideProcessingTimeout:params.serverSideProcessingTimeout + responseClass:nil + queue:self.callbackQueue + completion:responseHandler]; +} + +- (void)cancelMessagesRequestWithParams:(MTRMessagesClusterCancelMessagesRequestParams *)params expectedValues:(NSArray *> * _Nullable)expectedValues expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(MTRStatusCompletion)completion +{ + if (params == nil) { + params = [[MTRMessagesClusterCancelMessagesRequestParams + alloc] init]; + } + + auto responseHandler = ^(id _Nullable response, NSError * _Nullable error) { + completion(error); + }; + + auto * timedInvokeTimeoutMs = params.timedInvokeTimeoutMs; + + using RequestType = Messages::Commands::CancelMessagesRequest::Type; + [self.device _invokeKnownCommandWithEndpointID:self.endpointID + clusterID:@(RequestType::GetClusterId()) + commandID:@(RequestType::GetCommandId()) + commandPayload:params + expectedValues:expectedValues + expectedValueInterval:expectedValueIntervalMs + timedInvokeTimeout:timedInvokeTimeoutMs + serverSideProcessingTimeout:params.serverSideProcessingTimeout + responseClass:nil + queue:self.callbackQueue + completion:responseHandler]; +} + +- (NSDictionary * _Nullable)readAttributeMessagesWithParams:(MTRReadParams * _Nullable)params +{ + return [self.device readAttributeWithEndpointID:self.endpointID clusterID:@(MTRClusterIDTypeMessagesID) attributeID:@(MTRAttributeIDTypeClusterMessagesAttributeMessagesID) params:params]; +} + +- (NSDictionary * _Nullable)readAttributeActiveMessageIDsWithParams:(MTRReadParams * _Nullable)params +{ + return [self.device readAttributeWithEndpointID:self.endpointID clusterID:@(MTRClusterIDTypeMessagesID) attributeID:@(MTRAttributeIDTypeClusterMessagesAttributeActiveMessageIDsID) params:params]; +} + +- (NSDictionary * _Nullable)readAttributeGeneratedCommandListWithParams:(MTRReadParams * _Nullable)params +{ + return [self.device readAttributeWithEndpointID:self.endpointID clusterID:@(MTRClusterIDTypeMessagesID) attributeID:@(MTRAttributeIDTypeClusterMessagesAttributeGeneratedCommandListID) params:params]; +} + +- (NSDictionary * _Nullable)readAttributeAcceptedCommandListWithParams:(MTRReadParams * _Nullable)params +{ + return [self.device readAttributeWithEndpointID:self.endpointID clusterID:@(MTRClusterIDTypeMessagesID) attributeID:@(MTRAttributeIDTypeClusterMessagesAttributeAcceptedCommandListID) params:params]; +} + +- (NSDictionary * _Nullable)readAttributeEventListWithParams:(MTRReadParams * _Nullable)params +{ + return [self.device readAttributeWithEndpointID:self.endpointID clusterID:@(MTRClusterIDTypeMessagesID) attributeID:@(MTRAttributeIDTypeClusterMessagesAttributeEventListID) params:params]; +} + +- (NSDictionary * _Nullable)readAttributeAttributeListWithParams:(MTRReadParams * _Nullable)params +{ + return [self.device readAttributeWithEndpointID:self.endpointID clusterID:@(MTRClusterIDTypeMessagesID) attributeID:@(MTRAttributeIDTypeClusterMessagesAttributeAttributeListID) params:params]; +} + +- (NSDictionary * _Nullable)readAttributeFeatureMapWithParams:(MTRReadParams * _Nullable)params +{ + return [self.device readAttributeWithEndpointID:self.endpointID clusterID:@(MTRClusterIDTypeMessagesID) attributeID:@(MTRAttributeIDTypeClusterMessagesAttributeFeatureMapID) params:params]; +} + +- (NSDictionary * _Nullable)readAttributeClusterRevisionWithParams:(MTRReadParams * _Nullable)params +{ + return [self.device readAttributeWithEndpointID:self.endpointID clusterID:@(MTRClusterIDTypeMessagesID) attributeID:@(MTRAttributeIDTypeClusterMessagesAttributeClusterRevisionID) params:params]; +} + +@end + @implementation MTRClusterDeviceEnergyManagement - (void)powerAdjustRequestWithParams:(MTRDeviceEnergyManagementClusterPowerAdjustRequestParams *)params expectedValues:(NSArray *> * _Nullable)expectedValues expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(MTRStatusCompletion)completion diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h index d64c9fceddec05..6dd11137d0f2d8 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h @@ -5511,6 +5511,66 @@ MTR_PROVISIONALLY_AVAILABLE @property (nonatomic, copy, nullable) NSNumber * serverSideProcessingTimeout; @end +MTR_PROVISIONALLY_AVAILABLE +@interface MTRMessagesClusterPresentMessagesRequestParams : NSObject + +@property (nonatomic, copy) NSArray * _Nonnull messages MTR_PROVISIONALLY_AVAILABLE; +/** + * Controls whether the command is a timed command (using Timed Invoke). + * + * If nil (the default value), a regular invoke is done for commands that do + * not require a timed invoke and a timed invoke with some default timed request + * timeout is done for commands that require a timed invoke. + * + * If not nil, a timed invoke is done, with the provided value used as the timed + * request timeout. The value should be chosen small enough to provide the + * desired security properties but large enough that it will allow a round-trip + * from the sever to the client (for the status response and actual invoke + * request) within the timeout window. + * + */ +@property (nonatomic, copy, nullable) NSNumber * timedInvokeTimeoutMs; + +/** + * Controls how much time, in seconds, we will allow for the server to process the command. + * + * The command will then time out if that much time, plus an allowance for retransmits due to network failures, passes. + * + * If nil, the framework will try to select an appropriate timeout value itself. + */ +@property (nonatomic, copy, nullable) NSNumber * serverSideProcessingTimeout; +@end + +MTR_PROVISIONALLY_AVAILABLE +@interface MTRMessagesClusterCancelMessagesRequestParams : NSObject + +@property (nonatomic, copy) NSArray * _Nonnull messageIDs MTR_PROVISIONALLY_AVAILABLE; +/** + * Controls whether the command is a timed command (using Timed Invoke). + * + * If nil (the default value), a regular invoke is done for commands that do + * not require a timed invoke and a timed invoke with some default timed request + * timeout is done for commands that require a timed invoke. + * + * If not nil, a timed invoke is done, with the provided value used as the timed + * request timeout. The value should be chosen small enough to provide the + * desired security properties but large enough that it will allow a round-trip + * from the sever to the client (for the status response and actual invoke + * request) within the timeout window. + * + */ +@property (nonatomic, copy, nullable) NSNumber * timedInvokeTimeoutMs; + +/** + * Controls how much time, in seconds, we will allow for the server to process the command. + * + * The command will then time out if that much time, plus an allowance for retransmits due to network failures, passes. + * + * If nil, the framework will try to select an appropriate timeout value itself. + */ +@property (nonatomic, copy, nullable) NSNumber * serverSideProcessingTimeout; +@end + MTR_PROVISIONALLY_AVAILABLE @interface MTRDeviceEnergyManagementClusterPowerAdjustRequestParams : NSObject diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm index 8411366a4fd937..3358d9fa790561 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm @@ -15415,6 +15415,253 @@ - (CHIP_ERROR)_encodeToTLVReader:(chip::System::PacketBufferTLVReader &)reader } @end +@implementation MTRMessagesClusterPresentMessagesRequestParams +- (instancetype)init +{ + if (self = [super init]) { + + _messages = [NSArray array]; + _timedInvokeTimeoutMs = nil; + _serverSideProcessingTimeout = nil; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone; +{ + auto other = [[MTRMessagesClusterPresentMessagesRequestParams alloc] init]; + + other.messages = self.messages; + other.timedInvokeTimeoutMs = self.timedInvokeTimeoutMs; + other.serverSideProcessingTimeout = self.serverSideProcessingTimeout; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = [NSString stringWithFormat:@"<%@: messages:%@; >", NSStringFromClass([self class]), _messages]; + return descriptionString; +} + +@end + +@implementation MTRMessagesClusterPresentMessagesRequestParams (InternalMethods) + +- (CHIP_ERROR)_encodeToTLVReader:(chip::System::PacketBufferTLVReader &)reader +{ + chip::app::Clusters::Messages::Commands::PresentMessagesRequest::Type encodableStruct; + ListFreer listFreer; + { + { + using ListType_0 = std::remove_reference_t; + using ListMemberType_0 = ListMemberTypeGetter::Type; + if (self.messages.count != 0) { + auto * listHolder_0 = new ListHolder(self.messages.count); + if (listHolder_0 == nullptr || listHolder_0->mList == nullptr) { + return CHIP_ERROR_INVALID_ARGUMENT; + } + listFreer.add(listHolder_0); + for (size_t i_0 = 0; i_0 < self.messages.count; ++i_0) { + if (![self.messages[i_0] isKindOfClass:[MTRMessagesClusterMessageStruct class]]) { + // Wrong kind of value. + return CHIP_ERROR_INVALID_ARGUMENT; + } + auto element_0 = (MTRMessagesClusterMessageStruct *) self.messages[i_0]; + listHolder_0->mList[i_0].messageID = AsByteSpan(element_0.messageID); + listHolder_0->mList[i_0].priority = static_castmList[i_0].priority)>>(element_0.priority.unsignedCharValue); + listHolder_0->mList[i_0].messageControl = static_castmList[i_0].messageControl)>>(element_0.messageControl.unsignedCharValue); + if (element_0.startTime == nil) { + listHolder_0->mList[i_0].startTime.SetNull(); + } else { + auto & nonNullValue_2 = listHolder_0->mList[i_0].startTime.SetNonNull(); + nonNullValue_2 = element_0.startTime.unsignedIntValue; + } + if (element_0.duration == nil) { + listHolder_0->mList[i_0].duration.SetNull(); + } else { + auto & nonNullValue_2 = listHolder_0->mList[i_0].duration.SetNonNull(); + nonNullValue_2 = element_0.duration.unsignedShortValue; + } + listHolder_0->mList[i_0].messageText = AsCharSpan(element_0.messageText); + if (element_0.responses != nil) { + auto & definedValue_2 = listHolder_0->mList[i_0].responses.Emplace(); + { + using ListType_3 = std::remove_reference_t; + using ListMemberType_3 = ListMemberTypeGetter::Type; + if (element_0.responses.count != 0) { + auto * listHolder_3 = new ListHolder(element_0.responses.count); + if (listHolder_3 == nullptr || listHolder_3->mList == nullptr) { + return CHIP_ERROR_INVALID_ARGUMENT; + } + listFreer.add(listHolder_3); + for (size_t i_3 = 0; i_3 < element_0.responses.count; ++i_3) { + if (![element_0.responses[i_3] isKindOfClass:[MTRMessagesClusterMessageResponseOptionStruct class]]) { + // Wrong kind of value. + return CHIP_ERROR_INVALID_ARGUMENT; + } + auto element_3 = (MTRMessagesClusterMessageResponseOptionStruct *) element_0.responses[i_3]; + if (element_3.messageResponseID != nil) { + auto & definedValue_5 = listHolder_3->mList[i_3].messageResponseID.Emplace(); + definedValue_5 = element_3.messageResponseID.unsignedIntValue; + } + if (element_3.label != nil) { + auto & definedValue_5 = listHolder_3->mList[i_3].label.Emplace(); + definedValue_5 = AsCharSpan(element_3.label); + } + } + definedValue_2 = ListType_3(listHolder_3->mList, element_0.responses.count); + } else { + definedValue_2 = ListType_3(); + } + } + } + } + encodableStruct.messages = ListType_0(listHolder_0->mList, self.messages.count); + } else { + encodableStruct.messages = ListType_0(); + } + } + } + + auto buffer = chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSizeWithoutReserve, 0); + if (buffer.IsNull()) { + return CHIP_ERROR_NO_MEMORY; + } + + chip::System::PacketBufferTLVWriter writer; + // Commands never need chained buffers, since they cannot be chunked. + writer.Init(std::move(buffer), /* useChainedBuffers = */ false); + + ReturnErrorOnFailure(chip::app::DataModel::Encode(writer, chip::TLV::AnonymousTag(), encodableStruct)); + + ReturnErrorOnFailure(writer.Finalize(&buffer)); + + reader.Init(std::move(buffer)); + return reader.Next(chip::TLV::kTLVType_Structure, chip::TLV::AnonymousTag()); +} + +- (NSDictionary * _Nullable)_encodeAsDataValue:(NSError * __autoreleasing *)error +{ + chip::System::PacketBufferTLVReader reader; + CHIP_ERROR err = [self _encodeToTLVReader:reader]; + if (err != CHIP_NO_ERROR) { + if (error) { + *error = [MTRError errorForCHIPErrorCode:err]; + } + return nil; + } + + auto decodedObj = MTRDecodeDataValueDictionaryFromCHIPTLV(&reader); + if (decodedObj == nil) { + if (error) { + *error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE]; + } + } + return decodedObj; +} +@end + +@implementation MTRMessagesClusterCancelMessagesRequestParams +- (instancetype)init +{ + if (self = [super init]) { + + _messageIDs = [NSArray array]; + _timedInvokeTimeoutMs = nil; + _serverSideProcessingTimeout = nil; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone; +{ + auto other = [[MTRMessagesClusterCancelMessagesRequestParams alloc] init]; + + other.messageIDs = self.messageIDs; + other.timedInvokeTimeoutMs = self.timedInvokeTimeoutMs; + other.serverSideProcessingTimeout = self.serverSideProcessingTimeout; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = [NSString stringWithFormat:@"<%@: messageIDs:%@; >", NSStringFromClass([self class]), _messageIDs]; + return descriptionString; +} + +@end + +@implementation MTRMessagesClusterCancelMessagesRequestParams (InternalMethods) + +- (CHIP_ERROR)_encodeToTLVReader:(chip::System::PacketBufferTLVReader &)reader +{ + chip::app::Clusters::Messages::Commands::CancelMessagesRequest::Type encodableStruct; + ListFreer listFreer; + { + { + using ListType_0 = std::remove_reference_t; + using ListMemberType_0 = ListMemberTypeGetter::Type; + if (self.messageIDs.count != 0) { + auto * listHolder_0 = new ListHolder(self.messageIDs.count); + if (listHolder_0 == nullptr || listHolder_0->mList == nullptr) { + return CHIP_ERROR_INVALID_ARGUMENT; + } + listFreer.add(listHolder_0); + for (size_t i_0 = 0; i_0 < self.messageIDs.count; ++i_0) { + if (![self.messageIDs[i_0] isKindOfClass:[NSData class]]) { + // Wrong kind of value. + return CHIP_ERROR_INVALID_ARGUMENT; + } + auto element_0 = (NSData *) self.messageIDs[i_0]; + listHolder_0->mList[i_0] = AsByteSpan(element_0); + } + encodableStruct.messageIDs = ListType_0(listHolder_0->mList, self.messageIDs.count); + } else { + encodableStruct.messageIDs = ListType_0(); + } + } + } + + auto buffer = chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSizeWithoutReserve, 0); + if (buffer.IsNull()) { + return CHIP_ERROR_NO_MEMORY; + } + + chip::System::PacketBufferTLVWriter writer; + // Commands never need chained buffers, since they cannot be chunked. + writer.Init(std::move(buffer), /* useChainedBuffers = */ false); + + ReturnErrorOnFailure(chip::app::DataModel::Encode(writer, chip::TLV::AnonymousTag(), encodableStruct)); + + ReturnErrorOnFailure(writer.Finalize(&buffer)); + + reader.Init(std::move(buffer)); + return reader.Next(chip::TLV::kTLVType_Structure, chip::TLV::AnonymousTag()); +} + +- (NSDictionary * _Nullable)_encodeAsDataValue:(NSError * __autoreleasing *)error +{ + chip::System::PacketBufferTLVReader reader; + CHIP_ERROR err = [self _encodeToTLVReader:reader]; + if (err != CHIP_NO_ERROR) { + if (error) { + *error = [MTRError errorForCHIPErrorCode:err]; + } + return nil; + } + + auto decodedObj = MTRDecodeDataValueDictionaryFromCHIPTLV(&reader); + if (decodedObj == nil) { + if (error) { + *error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE]; + } + } + return decodedObj; +} +@end + @implementation MTRDeviceEnergyManagementClusterPowerAdjustRequestParams - (instancetype)init { diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloads_Internal.h b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloads_Internal.h index e38b528d3dc220..bfa3ba9db6d782 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloads_Internal.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloads_Internal.h @@ -1030,6 +1030,18 @@ NS_ASSUME_NONNULL_BEGIN @end +@interface MTRMessagesClusterPresentMessagesRequestParams (InternalMethods) + +- (NSDictionary * _Nullable)_encodeAsDataValue:(NSError * __autoreleasing *)error; + +@end + +@interface MTRMessagesClusterCancelMessagesRequestParams (InternalMethods) + +- (NSDictionary * _Nullable)_encodeAsDataValue:(NSError * __autoreleasing *)error; + +@end + @interface MTRDeviceEnergyManagementClusterPowerAdjustRequestParams (InternalMethods) - (NSDictionary * _Nullable)_encodeAsDataValue:(NSError * __autoreleasing *)error; diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRCommandTimedCheck.mm b/src/darwin/Framework/CHIP/zap-generated/MTRCommandTimedCheck.mm index 0a5c1a48b5e8c8..e0269f1690b533 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRCommandTimedCheck.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRCommandTimedCheck.mm @@ -608,6 +608,15 @@ static BOOL CommandNeedsTimedInvokeInDemandResponseLoadControlCluster(AttributeI } } } +static BOOL CommandNeedsTimedInvokeInMessagesCluster(AttributeId aAttributeId) +{ + using namespace Clusters::Messages; + switch (aAttributeId) { + default: { + return NO; + } + } +} static BOOL CommandNeedsTimedInvokeInDeviceEnergyManagementCluster(AttributeId aAttributeId) { using namespace Clusters::DeviceEnergyManagement; @@ -1293,6 +1302,9 @@ BOOL MTRCommandNeedsTimedInvoke(NSNumber * _Nonnull aClusterID, NSNumber * _Nonn case Clusters::DemandResponseLoadControl::Id: { return CommandNeedsTimedInvokeInDemandResponseLoadControlCluster(commandID); } + case Clusters::Messages::Id: { + return CommandNeedsTimedInvokeInMessagesCluster(commandID); + } case Clusters::DeviceEnergyManagement::Id: { return CommandNeedsTimedInvokeInDeviceEnergyManagementCluster(commandID); } diff --git a/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm b/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm index 106ae0cfbcda04..431d29dac94ef3 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm @@ -2790,6 +2790,109 @@ static id _Nullable DecodeEventPayloadForDemandResponseLoadControlCluster(EventI *aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB; return nil; } +static id _Nullable DecodeEventPayloadForMessagesCluster(EventId aEventId, TLV::TLVReader & aReader, CHIP_ERROR * aError) +{ + using namespace Clusters::Messages; + switch (aEventId) { + case Events::MessageQueued::Id: { + Events::MessageQueued::DecodableType cppValue; + *aError = DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) { + return nil; + } + + __auto_type * value = [MTRMessagesClusterMessageQueuedEvent new]; + + do { + NSData * _Nonnull memberValue; + memberValue = AsData(cppValue.messageID); + value.messageID = memberValue; + } while (0); + + return value; + } + case Events::MessagePresented::Id: { + Events::MessagePresented::DecodableType cppValue; + *aError = DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) { + return nil; + } + + __auto_type * value = [MTRMessagesClusterMessagePresentedEvent new]; + + do { + NSData * _Nonnull memberValue; + memberValue = AsData(cppValue.messageID); + value.messageID = memberValue; + } while (0); + + return value; + } + case Events::MessageComplete::Id: { + Events::MessageComplete::DecodableType cppValue; + *aError = DataModel::Decode(aReader, cppValue); + if (*aError != CHIP_NO_ERROR) { + return nil; + } + + __auto_type * value = [MTRMessagesClusterMessageCompleteEvent new]; + + do { + NSData * _Nonnull memberValue; + memberValue = AsData(cppValue.messageID); + value.messageID = memberValue; + } while (0); + do { + NSNumber * _Nullable memberValue; + if (cppValue.responseID.HasValue()) { + if (cppValue.responseID.Value().IsNull()) { + memberValue = nil; + } else { + memberValue = [NSNumber numberWithUnsignedInt:cppValue.responseID.Value().Value()]; + } + } else { + memberValue = nil; + } + value.responseID = memberValue; + } while (0); + do { + NSString * _Nullable memberValue; + if (cppValue.reply.HasValue()) { + if (cppValue.reply.Value().IsNull()) { + memberValue = nil; + } else { + memberValue = AsString(cppValue.reply.Value().Value()); + if (memberValue == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } + } + } else { + memberValue = nil; + } + value.reply = memberValue; + } while (0); + do { + NSNumber * _Nullable memberValue; + if (cppValue.futureMessagesPreference.IsNull()) { + memberValue = nil; + } else { + memberValue = [NSNumber numberWithUnsignedChar:chip::to_underlying(cppValue.futureMessagesPreference.Value())]; + } + value.futureMessagesPreference = memberValue; + } while (0); + + return value; + } + default: { + break; + } + } + + *aError = CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB; + return nil; +} static id _Nullable DecodeEventPayloadForDeviceEnergyManagementCluster(EventId aEventId, TLV::TLVReader & aReader, CHIP_ERROR * aError) { using namespace Clusters::DeviceEnergyManagement; @@ -4535,6 +4638,9 @@ id _Nullable MTRDecodeEventPayload(const ConcreteEventPath & aPath, TLV::TLVRead case Clusters::DemandResponseLoadControl::Id: { return DecodeEventPayloadForDemandResponseLoadControlCluster(aPath.mEventId, aReader, aError); } + case Clusters::Messages::Id: { + return DecodeEventPayloadForMessagesCluster(aPath.mEventId, aReader, aError); + } case Clusters::DeviceEnergyManagement::Id: { return DecodeEventPayloadForDeviceEnergyManagementCluster(aPath.mEventId, aReader, aError); } diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h index 68069d30942dd7..395497c0bfc648 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h @@ -1187,6 +1187,41 @@ MTR_PROVISIONALLY_AVAILABLE @property (nonatomic, copy) MTRDemandResponseLoadControlClusterHeatingSourceControlStruct * _Nullable heatingSourceControl MTR_PROVISIONALLY_AVAILABLE; @end +MTR_PROVISIONALLY_AVAILABLE +@interface MTRMessagesClusterMessageResponseOptionStruct : NSObject +@property (nonatomic, copy) NSNumber * _Nullable messageResponseID MTR_PROVISIONALLY_AVAILABLE; +@property (nonatomic, copy) NSString * _Nullable label MTR_PROVISIONALLY_AVAILABLE; +@end + +MTR_PROVISIONALLY_AVAILABLE +@interface MTRMessagesClusterMessageStruct : NSObject +@property (nonatomic, copy) NSData * _Nonnull messageID MTR_PROVISIONALLY_AVAILABLE; +@property (nonatomic, copy) NSNumber * _Nonnull priority MTR_PROVISIONALLY_AVAILABLE; +@property (nonatomic, copy) NSNumber * _Nonnull messageControl MTR_PROVISIONALLY_AVAILABLE; +@property (nonatomic, copy) NSNumber * _Nullable startTime MTR_PROVISIONALLY_AVAILABLE; +@property (nonatomic, copy) NSNumber * _Nullable duration MTR_PROVISIONALLY_AVAILABLE; +@property (nonatomic, copy) NSString * _Nonnull messageText MTR_PROVISIONALLY_AVAILABLE; +@property (nonatomic, copy) NSArray * _Nullable responses MTR_PROVISIONALLY_AVAILABLE; +@end + +MTR_PROVISIONALLY_AVAILABLE +@interface MTRMessagesClusterMessageQueuedEvent : NSObject +@property (nonatomic, copy) NSData * _Nonnull messageID MTR_PROVISIONALLY_AVAILABLE; +@end + +MTR_PROVISIONALLY_AVAILABLE +@interface MTRMessagesClusterMessagePresentedEvent : NSObject +@property (nonatomic, copy) NSData * _Nonnull messageID MTR_PROVISIONALLY_AVAILABLE; +@end + +MTR_PROVISIONALLY_AVAILABLE +@interface MTRMessagesClusterMessageCompleteEvent : NSObject +@property (nonatomic, copy) NSData * _Nonnull messageID MTR_PROVISIONALLY_AVAILABLE; +@property (nonatomic, copy) NSNumber * _Nullable responseID MTR_PROVISIONALLY_AVAILABLE; +@property (nonatomic, copy) NSString * _Nullable reply MTR_PROVISIONALLY_AVAILABLE; +@property (nonatomic, copy) NSNumber * _Nullable futureMessagesPreference MTR_PROVISIONALLY_AVAILABLE; +@end + MTR_PROVISIONALLY_AVAILABLE @interface MTRDeviceEnergyManagementClusterCostStruct : NSObject @property (nonatomic, copy) NSNumber * _Nonnull costType MTR_PROVISIONALLY_AVAILABLE; diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm index 235a28427843fd..00c787feacb3c0 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm @@ -4813,6 +4813,171 @@ - (NSString *)description @end +@implementation MTRMessagesClusterMessageResponseOptionStruct +- (instancetype)init +{ + if (self = [super init]) { + + _messageResponseID = nil; + + _label = nil; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone +{ + auto other = [[MTRMessagesClusterMessageResponseOptionStruct alloc] init]; + + other.messageResponseID = self.messageResponseID; + other.label = self.label; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = [NSString stringWithFormat:@"<%@: messageResponseID:%@; label:%@; >", NSStringFromClass([self class]), _messageResponseID, _label]; + return descriptionString; +} + +@end + +@implementation MTRMessagesClusterMessageStruct +- (instancetype)init +{ + if (self = [super init]) { + + _messageID = [NSData data]; + + _priority = @(0); + + _messageControl = @(0); + + _startTime = nil; + + _duration = nil; + + _messageText = @""; + + _responses = nil; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone +{ + auto other = [[MTRMessagesClusterMessageStruct alloc] init]; + + other.messageID = self.messageID; + other.priority = self.priority; + other.messageControl = self.messageControl; + other.startTime = self.startTime; + other.duration = self.duration; + other.messageText = self.messageText; + other.responses = self.responses; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = [NSString stringWithFormat:@"<%@: messageID:%@; priority:%@; messageControl:%@; startTime:%@; duration:%@; messageText:%@; responses:%@; >", NSStringFromClass([self class]), [_messageID base64EncodedStringWithOptions:0], _priority, _messageControl, _startTime, _duration, _messageText, _responses]; + return descriptionString; +} + +@end + +@implementation MTRMessagesClusterMessageQueuedEvent +- (instancetype)init +{ + if (self = [super init]) { + + _messageID = [NSData data]; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone +{ + auto other = [[MTRMessagesClusterMessageQueuedEvent alloc] init]; + + other.messageID = self.messageID; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = [NSString stringWithFormat:@"<%@: messageID:%@; >", NSStringFromClass([self class]), [_messageID base64EncodedStringWithOptions:0]]; + return descriptionString; +} + +@end + +@implementation MTRMessagesClusterMessagePresentedEvent +- (instancetype)init +{ + if (self = [super init]) { + + _messageID = [NSData data]; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone +{ + auto other = [[MTRMessagesClusterMessagePresentedEvent alloc] init]; + + other.messageID = self.messageID; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = [NSString stringWithFormat:@"<%@: messageID:%@; >", NSStringFromClass([self class]), [_messageID base64EncodedStringWithOptions:0]]; + return descriptionString; +} + +@end + +@implementation MTRMessagesClusterMessageCompleteEvent +- (instancetype)init +{ + if (self = [super init]) { + + _messageID = [NSData data]; + + _responseID = nil; + + _reply = nil; + + _futureMessagesPreference = nil; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone +{ + auto other = [[MTRMessagesClusterMessageCompleteEvent alloc] init]; + + other.messageID = self.messageID; + other.responseID = self.responseID; + other.reply = self.reply; + other.futureMessagesPreference = self.futureMessagesPreference; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = [NSString stringWithFormat:@"<%@: messageID:%@; responseID:%@; reply:%@; futureMessagesPreference:%@; >", NSStringFromClass([self class]), [_messageID base64EncodedStringWithOptions:0], _responseID, _reply, _futureMessagesPreference]; + return descriptionString; +} + +@end + @implementation MTRDeviceEnergyManagementClusterCostStruct - (instancetype)init { diff --git a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp index bf67f266e9635d..912428b16a4b25 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp @@ -10209,6 +10209,74 @@ EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value) } // namespace Attributes } // namespace DemandResponseLoadControl +namespace Messages { +namespace Attributes { + +namespace FeatureMap { + +EmberAfStatus Get(chip::EndpointId endpoint, uint32_t * value) +{ + using Traits = NumericAttributeTraits; + Traits::StorageType temp; + uint8_t * readable = Traits::ToAttributeStoreRepresentation(temp); + EmberAfStatus status = emberAfReadAttribute(endpoint, Clusters::Messages::Id, Id, readable, sizeof(temp)); + VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == status, status); + if (!Traits::CanRepresentValue(/* isNullable = */ false, temp)) + { + return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; + } + *value = Traits::StorageToWorking(temp); + return status; +} +EmberAfStatus Set(chip::EndpointId endpoint, uint32_t value) +{ + using Traits = NumericAttributeTraits; + if (!Traits::CanRepresentValue(/* isNullable = */ false, value)) + { + return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; + } + Traits::StorageType storageValue; + Traits::WorkingToStorage(value, storageValue); + uint8_t * writable = Traits::ToAttributeStoreRepresentation(storageValue); + return emberAfWriteAttribute(endpoint, Clusters::Messages::Id, Id, writable, ZCL_BITMAP32_ATTRIBUTE_TYPE); +} + +} // namespace FeatureMap + +namespace ClusterRevision { + +EmberAfStatus Get(chip::EndpointId endpoint, uint16_t * value) +{ + using Traits = NumericAttributeTraits; + Traits::StorageType temp; + uint8_t * readable = Traits::ToAttributeStoreRepresentation(temp); + EmberAfStatus status = emberAfReadAttribute(endpoint, Clusters::Messages::Id, Id, readable, sizeof(temp)); + VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == status, status); + if (!Traits::CanRepresentValue(/* isNullable = */ false, temp)) + { + return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; + } + *value = Traits::StorageToWorking(temp); + return status; +} +EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value) +{ + using Traits = NumericAttributeTraits; + if (!Traits::CanRepresentValue(/* isNullable = */ false, value)) + { + return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; + } + Traits::StorageType storageValue; + Traits::WorkingToStorage(value, storageValue); + uint8_t * writable = Traits::ToAttributeStoreRepresentation(storageValue); + return emberAfWriteAttribute(endpoint, Clusters::Messages::Id, Id, writable, ZCL_INT16U_ATTRIBUTE_TYPE); +} + +} // namespace ClusterRevision + +} // namespace Attributes +} // namespace Messages + namespace DeviceEnergyManagement { namespace Attributes { diff --git a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h index 8f343ba053a42f..841ec992bfc42d 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h +++ b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h @@ -1993,6 +1993,22 @@ EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value); } // namespace Attributes } // namespace DemandResponseLoadControl +namespace Messages { +namespace Attributes { + +namespace FeatureMap { +EmberAfStatus Get(chip::EndpointId endpoint, uint32_t * value); // bitmap32 +EmberAfStatus Set(chip::EndpointId endpoint, uint32_t value); +} // namespace FeatureMap + +namespace ClusterRevision { +EmberAfStatus Get(chip::EndpointId endpoint, uint16_t * value); // int16u +EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value); +} // namespace ClusterRevision + +} // namespace Attributes +} // namespace Messages + namespace DeviceEnergyManagement { namespace Attributes { diff --git a/zzz_generated/app-common/app-common/zap-generated/callback.h b/zzz_generated/app-common/app-common/zap-generated/callback.h index c06aaf26cb8abf..9989e8424bbe87 100644 --- a/zzz_generated/app-common/app-common/zap-generated/callback.h +++ b/zzz_generated/app-common/app-common/zap-generated/callback.h @@ -368,6 +368,11 @@ void emberAfElectricalEnergyMeasurementClusterInitCallback(chip::EndpointId endp */ void emberAfDemandResponseLoadControlClusterInitCallback(chip::EndpointId endpoint); +/** + * @param endpoint Endpoint that is being initialized + */ +void emberAfMessagesClusterInitCallback(chip::EndpointId endpoint); + /** * @param endpoint Endpoint that is being initialized */ @@ -3195,6 +3200,45 @@ chip::Protocols::InteractionModel::Status MatterDemandResponseLoadControlCluster */ void emberAfDemandResponseLoadControlClusterServerTickCallback(chip::EndpointId endpoint); +// +// Messages Cluster +// + +/** + * @param endpoint Endpoint that is being initialized + */ +void emberAfMessagesClusterServerInitCallback(chip::EndpointId endpoint); + +/** + * @param endpoint Endpoint that is being shutdown + */ +void MatterMessagesClusterServerShutdownCallback(chip::EndpointId endpoint); + +/** + * @param endpoint Endpoint that is being initialized + */ +void emberAfMessagesClusterClientInitCallback(chip::EndpointId endpoint); + +/** + * @param attributePath Concrete attribute path that changed + */ +void MatterMessagesClusterServerAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath); + +/** + * @param attributePath Concrete attribute path to be changed + * @param attributeType Attribute type + * @param size Attribute size + * @param value Attribute value + */ +chip::Protocols::InteractionModel::Status +MatterMessagesClusterServerPreAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath, + EmberAfAttributeType attributeType, uint16_t size, uint8_t * value); + +/** + * @param endpoint Endpoint that is being served + */ +void emberAfMessagesClusterServerTickCallback(chip::EndpointId endpoint); + // // Device Energy Management Cluster // @@ -5600,6 +5644,18 @@ bool emberAfDemandResponseLoadControlClusterRemoveLoadControlEventRequestCallbac bool emberAfDemandResponseLoadControlClusterClearLoadControlEventsRequestCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DemandResponseLoadControl::Commands::ClearLoadControlEventsRequest::DecodableType & commandData); +/** + * @brief Messages Cluster PresentMessagesRequest Command callback (from client) + */ +bool emberAfMessagesClusterPresentMessagesRequestCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::Messages::Commands::PresentMessagesRequest::DecodableType & commandData); +/** + * @brief Messages Cluster CancelMessagesRequest Command callback (from client) + */ +bool emberAfMessagesClusterCancelMessagesRequestCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::Messages::Commands::CancelMessagesRequest::DecodableType & commandData); /** * @brief Door Lock Cluster LockDoor Command callback (from client) */ diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-enums-check.h b/zzz_generated/app-common/app-common/zap-generated/cluster-enums-check.h index 9afff5f67ad63c..988e6b713a862e 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-enums-check.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-enums-check.h @@ -1641,6 +1641,36 @@ static auto __attribute__((unused)) EnsureKnownEnumValue(DemandResponseLoadContr } } +static auto __attribute__((unused)) EnsureKnownEnumValue(Messages::FutureMessagePreferenceEnum val) +{ + using EnumType = Messages::FutureMessagePreferenceEnum; + switch (val) + { + case EnumType::kAllowed: + case EnumType::kIncreased: + case EnumType::kReduced: + case EnumType::kDisallowed: + case EnumType::kBanned: + return val; + default: + return static_cast(5); + } +} +static auto __attribute__((unused)) EnsureKnownEnumValue(Messages::MessagePriorityEnum val) +{ + using EnumType = Messages::MessagePriorityEnum; + switch (val) + { + case EnumType::kLow: + case EnumType::kMedium: + case EnumType::kHigh: + case EnumType::kCritical: + return val; + default: + return static_cast(4); + } +} + static auto __attribute__((unused)) EnsureKnownEnumValue(DeviceEnergyManagement::AdjustmentCauseEnum val) { using EnumType = DeviceEnergyManagement::AdjustmentCauseEnum; diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h b/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h index a3ba215efcd0a1..17d692d6930bc8 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h @@ -2369,6 +2369,57 @@ enum class Feature : uint32_t }; } // namespace DemandResponseLoadControl +namespace Messages { + +// Enum for FutureMessagePreferenceEnum +enum class FutureMessagePreferenceEnum : uint8_t +{ + kAllowed = 0x00, + kIncreased = 0x01, + kReduced = 0x02, + kDisallowed = 0x03, + kBanned = 0x04, + // All received enum values that are not listed above will be mapped + // to kUnknownEnumValue. This is a helper enum value that should only + // be used by code to process how it handles receiving and unknown + // enum value. This specific should never be transmitted. + kUnknownEnumValue = 5, +}; + +// Enum for MessagePriorityEnum +enum class MessagePriorityEnum : uint8_t +{ + kLow = 0x00, + kMedium = 0x01, + kHigh = 0x02, + kCritical = 0x03, + // All received enum values that are not listed above will be mapped + // to kUnknownEnumValue. This is a helper enum value that should only + // be used by code to process how it handles receiving and unknown + // enum value. This specific should never be transmitted. + kUnknownEnumValue = 4, +}; + +// Bitmap for Feature +enum class Feature : uint32_t +{ + kReceivedConfirmation = 0x1, + kConfirmationResponse = 0x2, + kConfirmationReply = 0x4, + kProtectedMessages = 0x8, +}; + +// Bitmap for MessageControlBitmap +enum class MessageControlBitmap : uint8_t +{ + kConfirmationRequired = 0x1, + kResponseRequired = 0x2, + kReplyMessage = 0x4, + kMessageConfirmed = 0x8, + kMessageProtected = 0x10, +}; +} // namespace Messages + namespace DeviceEnergyManagement { // Enum for AdjustmentCauseEnum diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp index ba89586525a20f..8b0a7d22694475 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp @@ -14847,6 +14847,339 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace Events } // namespace DemandResponseLoadControl +namespace Messages { +namespace Structs { + +namespace MessageResponseOptionStruct { +CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const +{ + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMessageResponseID), messageResponseID); + encoder.Encode(to_underlying(Fields::kLabel), label); + return encoder.Finalize(); +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + detail::StructDecodeIterator __iterator(reader); + while (true) + { + auto __element = __iterator.Next(); + if (std::holds_alternative(__element)) + { + return std::get(__element); + } + + CHIP_ERROR err = CHIP_NO_ERROR; + const uint8_t __context_tag = std::get(__element); + + if (__context_tag == to_underlying(Fields::kMessageResponseID)) + { + err = DataModel::Decode(reader, messageResponseID); + } + else if (__context_tag == to_underlying(Fields::kLabel)) + { + err = DataModel::Decode(reader, label); + } + else + { + } + + ReturnErrorOnFailure(err); + } +} + +} // namespace MessageResponseOptionStruct + +namespace MessageStruct { +CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const +{ + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMessageID), messageID); + encoder.Encode(to_underlying(Fields::kPriority), priority); + encoder.Encode(to_underlying(Fields::kMessageControl), messageControl); + encoder.Encode(to_underlying(Fields::kStartTime), startTime); + encoder.Encode(to_underlying(Fields::kDuration), duration); + encoder.Encode(to_underlying(Fields::kMessageText), messageText); + encoder.Encode(to_underlying(Fields::kResponses), responses); + return encoder.Finalize(); +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + detail::StructDecodeIterator __iterator(reader); + while (true) + { + auto __element = __iterator.Next(); + if (std::holds_alternative(__element)) + { + return std::get(__element); + } + + CHIP_ERROR err = CHIP_NO_ERROR; + const uint8_t __context_tag = std::get(__element); + + if (__context_tag == to_underlying(Fields::kMessageID)) + { + err = DataModel::Decode(reader, messageID); + } + else if (__context_tag == to_underlying(Fields::kPriority)) + { + err = DataModel::Decode(reader, priority); + } + else if (__context_tag == to_underlying(Fields::kMessageControl)) + { + err = DataModel::Decode(reader, messageControl); + } + else if (__context_tag == to_underlying(Fields::kStartTime)) + { + err = DataModel::Decode(reader, startTime); + } + else if (__context_tag == to_underlying(Fields::kDuration)) + { + err = DataModel::Decode(reader, duration); + } + else if (__context_tag == to_underlying(Fields::kMessageText)) + { + err = DataModel::Decode(reader, messageText); + } + else if (__context_tag == to_underlying(Fields::kResponses)) + { + err = DataModel::Decode(reader, responses); + } + else + { + } + + ReturnErrorOnFailure(err); + } +} + +} // namespace MessageStruct +} // namespace Structs + +namespace Commands { +namespace PresentMessagesRequest { +CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const +{ + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMessages), messages); + return encoder.Finalize(); +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + detail::StructDecodeIterator __iterator(reader); + while (true) + { + auto __element = __iterator.Next(); + if (std::holds_alternative(__element)) + { + return std::get(__element); + } + + CHIP_ERROR err = CHIP_NO_ERROR; + const uint8_t __context_tag = std::get(__element); + + if (__context_tag == to_underlying(Fields::kMessages)) + { + err = DataModel::Decode(reader, messages); + } + else + { + } + + ReturnErrorOnFailure(err); + } +} +} // namespace PresentMessagesRequest. +namespace CancelMessagesRequest { +CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const +{ + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kMessageIDs), messageIDs); + return encoder.Finalize(); +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + detail::StructDecodeIterator __iterator(reader); + while (true) + { + auto __element = __iterator.Next(); + if (std::holds_alternative(__element)) + { + return std::get(__element); + } + + CHIP_ERROR err = CHIP_NO_ERROR; + const uint8_t __context_tag = std::get(__element); + + if (__context_tag == to_underlying(Fields::kMessageIDs)) + { + err = DataModel::Decode(reader, messageIDs); + } + else + { + } + + ReturnErrorOnFailure(err); + } +} +} // namespace CancelMessagesRequest. +} // namespace Commands + +namespace Attributes { +CHIP_ERROR TypeInfo::DecodableType::Decode(TLV::TLVReader & reader, const ConcreteAttributePath & path) +{ + switch (path.mAttributeId) + { + case Attributes::Messages::TypeInfo::GetAttributeId(): + return DataModel::Decode(reader, messages); + case Attributes::ActiveMessageIDs::TypeInfo::GetAttributeId(): + return DataModel::Decode(reader, activeMessageIDs); + case Attributes::GeneratedCommandList::TypeInfo::GetAttributeId(): + return DataModel::Decode(reader, generatedCommandList); + case Attributes::AcceptedCommandList::TypeInfo::GetAttributeId(): + return DataModel::Decode(reader, acceptedCommandList); + case Attributes::EventList::TypeInfo::GetAttributeId(): + return DataModel::Decode(reader, eventList); + case Attributes::AttributeList::TypeInfo::GetAttributeId(): + return DataModel::Decode(reader, attributeList); + case Attributes::FeatureMap::TypeInfo::GetAttributeId(): + return DataModel::Decode(reader, featureMap); + case Attributes::ClusterRevision::TypeInfo::GetAttributeId(): + return DataModel::Decode(reader, clusterRevision); + default: + return CHIP_NO_ERROR; + } +} +} // namespace Attributes + +namespace Events { +namespace MessageQueued { +CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const +{ + TLV::TLVType outer; + ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); + ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMessageID), messageID)); + return aWriter.EndContainer(outer); +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + detail::StructDecodeIterator __iterator(reader); + while (true) + { + auto __element = __iterator.Next(); + if (std::holds_alternative(__element)) + { + return std::get(__element); + } + + CHIP_ERROR err = CHIP_NO_ERROR; + const uint8_t __context_tag = std::get(__element); + + if (__context_tag == to_underlying(Fields::kMessageID)) + { + err = DataModel::Decode(reader, messageID); + } + else + { + } + + ReturnErrorOnFailure(err); + } +} +} // namespace MessageQueued. +namespace MessagePresented { +CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const +{ + TLV::TLVType outer; + ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); + ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMessageID), messageID)); + return aWriter.EndContainer(outer); +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + detail::StructDecodeIterator __iterator(reader); + while (true) + { + auto __element = __iterator.Next(); + if (std::holds_alternative(__element)) + { + return std::get(__element); + } + + CHIP_ERROR err = CHIP_NO_ERROR; + const uint8_t __context_tag = std::get(__element); + + if (__context_tag == to_underlying(Fields::kMessageID)) + { + err = DataModel::Decode(reader, messageID); + } + else + { + } + + ReturnErrorOnFailure(err); + } +} +} // namespace MessagePresented. +namespace MessageComplete { +CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const +{ + TLV::TLVType outer; + ReturnErrorOnFailure(aWriter.StartContainer(aTag, TLV::kTLVType_Structure, outer)); + ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kMessageID), messageID)); + ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kResponseID), responseID)); + ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kReply), reply)); + ReturnErrorOnFailure(DataModel::Encode(aWriter, TLV::ContextTag(Fields::kFutureMessagesPreference), futureMessagesPreference)); + return aWriter.EndContainer(outer); +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + detail::StructDecodeIterator __iterator(reader); + while (true) + { + auto __element = __iterator.Next(); + if (std::holds_alternative(__element)) + { + return std::get(__element); + } + + CHIP_ERROR err = CHIP_NO_ERROR; + const uint8_t __context_tag = std::get(__element); + + if (__context_tag == to_underlying(Fields::kMessageID)) + { + err = DataModel::Decode(reader, messageID); + } + else if (__context_tag == to_underlying(Fields::kResponseID)) + { + err = DataModel::Decode(reader, responseID); + } + else if (__context_tag == to_underlying(Fields::kReply)) + { + err = DataModel::Decode(reader, reply); + } + else if (__context_tag == to_underlying(Fields::kFutureMessagesPreference)) + { + err = DataModel::Decode(reader, futureMessagesPreference); + } + else + { + } + + ReturnErrorOnFailure(err); + } +} +} // namespace MessageComplete. +} // namespace Events + +} // namespace Messages namespace DeviceEnergyManagement { namespace Structs { @@ -29533,6 +29866,17 @@ bool CommandIsFabricScoped(ClusterId aCluster, CommandId aCommand) return false; } } + case Clusters::Messages::Id: { + switch (aCommand) + { + case Clusters::Messages::Commands::PresentMessagesRequest::Id: + return true; + case Clusters::Messages::Commands::CancelMessagesRequest::Id: + return true; + default: + return false; + } + } case Clusters::DeviceEnergyManagement::Id: { switch (aCommand) { diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h index ae1b3ab26c5ee1..0a56f821cb37f8 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h @@ -21006,6 +21006,354 @@ struct DecodableType } // namespace LoadControlEventStatusChange } // namespace Events } // namespace DemandResponseLoadControl +namespace Messages { +namespace Structs { +namespace MessageResponseOptionStruct { +enum class Fields : uint8_t +{ + kMessageResponseID = 0, + kLabel = 1, +}; + +struct Type +{ +public: + Optional messageResponseID; + Optional label; + + CHIP_ERROR Decode(TLV::TLVReader & reader); + + static constexpr bool kIsFabricScoped = false; + + CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const; +}; + +using DecodableType = Type; + +} // namespace MessageResponseOptionStruct +namespace MessageStruct { +enum class Fields : uint8_t +{ + kMessageID = 0, + kPriority = 1, + kMessageControl = 2, + kStartTime = 3, + kDuration = 4, + kMessageText = 5, + kResponses = 6, +}; + +struct Type +{ +public: + chip::ByteSpan messageID; + MessagePriorityEnum priority = static_cast(0); + chip::BitMask messageControl = static_cast>(0); + DataModel::Nullable startTime; + DataModel::Nullable duration; + chip::CharSpan messageText; + Optional> responses; + + static constexpr bool kIsFabricScoped = false; + + CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const; +}; + +struct DecodableType +{ +public: + chip::ByteSpan messageID; + MessagePriorityEnum priority = static_cast(0); + chip::BitMask messageControl = static_cast>(0); + DataModel::Nullable startTime; + DataModel::Nullable duration; + chip::CharSpan messageText; + Optional> responses; + + CHIP_ERROR Decode(TLV::TLVReader & reader); + + static constexpr bool kIsFabricScoped = false; +}; + +} // namespace MessageStruct +} // namespace Structs + +namespace Commands { +// Forward-declarations so we can reference these later. + +namespace PresentMessagesRequest { +struct Type; +struct DecodableType; +} // namespace PresentMessagesRequest + +namespace CancelMessagesRequest { +struct Type; +struct DecodableType; +} // namespace CancelMessagesRequest + +} // namespace Commands + +namespace Commands { +namespace PresentMessagesRequest { +enum class Fields : uint8_t +{ + kMessages = 0, +}; + +struct Type +{ +public: + // Use GetCommandId instead of commandId directly to avoid naming conflict with CommandIdentification in ExecutionOfACommand + static constexpr CommandId GetCommandId() { return Commands::PresentMessagesRequest::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + + DataModel::List messages; + + CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const; + + using ResponseType = DataModel::NullObjectType; + + static constexpr bool MustUseTimedInvoke() { return false; } +}; + +struct DecodableType +{ +public: + static constexpr CommandId GetCommandId() { return Commands::PresentMessagesRequest::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + + DataModel::DecodableList messages; + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; +}; // namespace PresentMessagesRequest +namespace CancelMessagesRequest { +enum class Fields : uint8_t +{ + kMessageIDs = 0, +}; + +struct Type +{ +public: + // Use GetCommandId instead of commandId directly to avoid naming conflict with CommandIdentification in ExecutionOfACommand + static constexpr CommandId GetCommandId() { return Commands::CancelMessagesRequest::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + + DataModel::List messageIDs; + + CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const; + + using ResponseType = DataModel::NullObjectType; + + static constexpr bool MustUseTimedInvoke() { return false; } +}; + +struct DecodableType +{ +public: + static constexpr CommandId GetCommandId() { return Commands::CancelMessagesRequest::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + + DataModel::DecodableList messageIDs; + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; +}; // namespace CancelMessagesRequest +} // namespace Commands + +namespace Attributes { + +namespace Messages { +struct TypeInfo +{ + using Type = chip::app::DataModel::List; + using DecodableType = chip::app::DataModel::DecodableList; + using DecodableArgType = + const chip::app::DataModel::DecodableList &; + + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + static constexpr AttributeId GetAttributeId() { return Attributes::Messages::Id; } + static constexpr bool MustUseTimedWrite() { return false; } +}; +} // namespace Messages +namespace ActiveMessageIDs { +struct TypeInfo +{ + using Type = chip::app::DataModel::List; + using DecodableType = chip::app::DataModel::DecodableList; + using DecodableArgType = const chip::app::DataModel::DecodableList &; + + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + static constexpr AttributeId GetAttributeId() { return Attributes::ActiveMessageIDs::Id; } + static constexpr bool MustUseTimedWrite() { return false; } +}; +} // namespace ActiveMessageIDs +namespace GeneratedCommandList { +struct TypeInfo : public Clusters::Globals::Attributes::GeneratedCommandList::TypeInfo +{ + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } +}; +} // namespace GeneratedCommandList +namespace AcceptedCommandList { +struct TypeInfo : public Clusters::Globals::Attributes::AcceptedCommandList::TypeInfo +{ + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } +}; +} // namespace AcceptedCommandList +namespace EventList { +struct TypeInfo : public Clusters::Globals::Attributes::EventList::TypeInfo +{ + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } +}; +} // namespace EventList +namespace AttributeList { +struct TypeInfo : public Clusters::Globals::Attributes::AttributeList::TypeInfo +{ + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } +}; +} // namespace AttributeList +namespace FeatureMap { +struct TypeInfo : public Clusters::Globals::Attributes::FeatureMap::TypeInfo +{ + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } +}; +} // namespace FeatureMap +namespace ClusterRevision { +struct TypeInfo : public Clusters::Globals::Attributes::ClusterRevision::TypeInfo +{ + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } +}; +} // namespace ClusterRevision + +struct TypeInfo +{ + struct DecodableType + { + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + + CHIP_ERROR Decode(TLV::TLVReader & reader, const ConcreteAttributePath & path); + + Attributes::Messages::TypeInfo::DecodableType messages; + Attributes::ActiveMessageIDs::TypeInfo::DecodableType activeMessageIDs; + Attributes::GeneratedCommandList::TypeInfo::DecodableType generatedCommandList; + Attributes::AcceptedCommandList::TypeInfo::DecodableType acceptedCommandList; + Attributes::EventList::TypeInfo::DecodableType eventList; + Attributes::AttributeList::TypeInfo::DecodableType attributeList; + Attributes::FeatureMap::TypeInfo::DecodableType featureMap = static_cast(0); + Attributes::ClusterRevision::TypeInfo::DecodableType clusterRevision = static_cast(0); + }; +}; +} // namespace Attributes +namespace Events { +namespace MessageQueued { +static constexpr PriorityLevel kPriorityLevel = PriorityLevel::Info; + +enum class Fields : uint8_t +{ + kMessageID = 0, +}; + +struct Type +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::MessageQueued::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + static constexpr bool kIsFabricScoped = false; + + chip::ByteSpan messageID; + + CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const; +}; + +struct DecodableType +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::MessageQueued::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + + chip::ByteSpan messageID; + + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; +} // namespace MessageQueued +namespace MessagePresented { +static constexpr PriorityLevel kPriorityLevel = PriorityLevel::Info; + +enum class Fields : uint8_t +{ + kMessageID = 0, +}; + +struct Type +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::MessagePresented::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + static constexpr bool kIsFabricScoped = false; + + chip::ByteSpan messageID; + + CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const; +}; + +struct DecodableType +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::MessagePresented::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + + chip::ByteSpan messageID; + + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; +} // namespace MessagePresented +namespace MessageComplete { +static constexpr PriorityLevel kPriorityLevel = PriorityLevel::Info; + +enum class Fields : uint8_t +{ + kMessageID = 0, + kResponseID = 1, + kReply = 2, + kFutureMessagesPreference = 3, +}; + +struct Type +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::MessageComplete::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + static constexpr bool kIsFabricScoped = false; + + chip::ByteSpan messageID; + Optional> responseID; + Optional> reply; + DataModel::Nullable futureMessagesPreference; + + CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const; +}; + +struct DecodableType +{ +public: + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return Events::MessageComplete::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::Messages::Id; } + + chip::ByteSpan messageID; + Optional> responseID; + Optional> reply; + DataModel::Nullable futureMessagesPreference; + + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; +} // namespace MessageComplete +} // namespace Events +} // namespace Messages namespace DeviceEnergyManagement { namespace Structs { namespace CostStruct { diff --git a/zzz_generated/app-common/app-common/zap-generated/ids/Attributes.h b/zzz_generated/app-common/app-common/zap-generated/ids/Attributes.h index 08c0d60d94afb0..f42ceca8f55b74 100644 --- a/zzz_generated/app-common/app-common/zap-generated/ids/Attributes.h +++ b/zzz_generated/app-common/app-common/zap-generated/ids/Attributes.h @@ -3761,6 +3761,44 @@ static constexpr AttributeId Id = Globals::Attributes::ClusterRevision::Id; } // namespace Attributes } // namespace DemandResponseLoadControl +namespace Messages { +namespace Attributes { + +namespace Messages { +static constexpr AttributeId Id = 0x00000000; +} // namespace Messages + +namespace ActiveMessageIDs { +static constexpr AttributeId Id = 0x00000001; +} // namespace ActiveMessageIDs + +namespace GeneratedCommandList { +static constexpr AttributeId Id = Globals::Attributes::GeneratedCommandList::Id; +} // namespace GeneratedCommandList + +namespace AcceptedCommandList { +static constexpr AttributeId Id = Globals::Attributes::AcceptedCommandList::Id; +} // namespace AcceptedCommandList + +namespace EventList { +static constexpr AttributeId Id = Globals::Attributes::EventList::Id; +} // namespace EventList + +namespace AttributeList { +static constexpr AttributeId Id = Globals::Attributes::AttributeList::Id; +} // namespace AttributeList + +namespace FeatureMap { +static constexpr AttributeId Id = Globals::Attributes::FeatureMap::Id; +} // namespace FeatureMap + +namespace ClusterRevision { +static constexpr AttributeId Id = Globals::Attributes::ClusterRevision::Id; +} // namespace ClusterRevision + +} // namespace Attributes +} // namespace Messages + namespace DeviceEnergyManagement { namespace Attributes { diff --git a/zzz_generated/app-common/app-common/zap-generated/ids/Clusters.h b/zzz_generated/app-common/app-common/zap-generated/ids/Clusters.h index 1f5d58367686ad..6fabd081faaa7f 100644 --- a/zzz_generated/app-common/app-common/zap-generated/ids/Clusters.h +++ b/zzz_generated/app-common/app-common/zap-generated/ids/Clusters.h @@ -226,6 +226,9 @@ static constexpr ClusterId Id = 0x00000091; namespace DemandResponseLoadControl { static constexpr ClusterId Id = 0x00000096; } // namespace DemandResponseLoadControl +namespace Messages { +static constexpr ClusterId Id = 0x00000097; +} // namespace Messages namespace DeviceEnergyManagement { static constexpr ClusterId Id = 0x00000098; } // namespace DeviceEnergyManagement diff --git a/zzz_generated/app-common/app-common/zap-generated/ids/Commands.h b/zzz_generated/app-common/app-common/zap-generated/ids/Commands.h index d3097ba5188c2c..3f944364a87260 100644 --- a/zzz_generated/app-common/app-common/zap-generated/ids/Commands.h +++ b/zzz_generated/app-common/app-common/zap-generated/ids/Commands.h @@ -955,6 +955,20 @@ static constexpr CommandId Id = 0x00000004; } // namespace Commands } // namespace DemandResponseLoadControl +namespace Messages { +namespace Commands { + +namespace PresentMessagesRequest { +static constexpr CommandId Id = 0x00000000; +} // namespace PresentMessagesRequest + +namespace CancelMessagesRequest { +static constexpr CommandId Id = 0x00000001; +} // namespace CancelMessagesRequest + +} // namespace Commands +} // namespace Messages + namespace DeviceEnergyManagement { namespace Commands { diff --git a/zzz_generated/app-common/app-common/zap-generated/ids/Events.h b/zzz_generated/app-common/app-common/zap-generated/ids/Events.h index 07c7f2537fdff8..ffc9326338b763 100644 --- a/zzz_generated/app-common/app-common/zap-generated/ids/Events.h +++ b/zzz_generated/app-common/app-common/zap-generated/ids/Events.h @@ -431,6 +431,24 @@ static constexpr EventId Id = 0x00000000; } // namespace Events } // namespace DemandResponseLoadControl +namespace Messages { +namespace Events { + +namespace MessageQueued { +static constexpr EventId Id = 0x00000000; +} // namespace MessageQueued + +namespace MessagePresented { +static constexpr EventId Id = 0x00000001; +} // namespace MessagePresented + +namespace MessageComplete { +static constexpr EventId Id = 0x00000002; +} // namespace MessageComplete + +} // namespace Events +} // namespace Messages + namespace DeviceEnergyManagement { namespace Events { diff --git a/zzz_generated/app-common/app-common/zap-generated/print-cluster.h b/zzz_generated/app-common/app-common/zap-generated/print-cluster.h index e59c7f22b61049..56d3b193f69f35 100644 --- a/zzz_generated/app-common/app-common/zap-generated/print-cluster.h +++ b/zzz_generated/app-common/app-common/zap-generated/print-cluster.h @@ -458,6 +458,12 @@ #define CHIP_PRINTCLUSTER_DEMAND_RESPONSE_LOAD_CONTROL_CLUSTER #endif +#if defined(ZCL_USING_MESSAGES_CLUSTER_SERVER) || defined(ZCL_USING_MESSAGES_CLUSTER_CLIENT) +#define CHIP_PRINTCLUSTER_MESSAGES_CLUSTER { chip::app::Clusters::Messages::Id, "Messages" }, +#else +#define CHIP_PRINTCLUSTER_MESSAGES_CLUSTER +#endif + #if defined(ZCL_USING_DEVICE_ENERGY_MANAGEMENT_CLUSTER_SERVER) || defined(ZCL_USING_DEVICE_ENERGY_MANAGEMENT_CLUSTER_CLIENT) #define CHIP_PRINTCLUSTER_DEVICE_ENERGY_MANAGEMENT_CLUSTER \ { chip::app::Clusters::DeviceEnergyManagement::Id, "Device Energy Management" }, @@ -847,6 +853,7 @@ CHIP_PRINTCLUSTER_VALVE_CONFIGURATION_AND_CONTROL_CLUSTER \ CHIP_PRINTCLUSTER_ELECTRICAL_ENERGY_MEASUREMENT_CLUSTER \ CHIP_PRINTCLUSTER_DEMAND_RESPONSE_LOAD_CONTROL_CLUSTER \ + CHIP_PRINTCLUSTER_MESSAGES_CLUSTER \ CHIP_PRINTCLUSTER_DEVICE_ENERGY_MANAGEMENT_CLUSTER \ CHIP_PRINTCLUSTER_ENERGY_EVSE_CLUSTER \ CHIP_PRINTCLUSTER_ENERGY_PREFERENCE_CLUSTER \ diff --git a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h index c4eb22e920597c..ac81a48f41d711 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h @@ -102,6 +102,7 @@ | ValveConfigurationAndControl | 0x0081 | | ElectricalEnergyMeasurement | 0x0091 | | DemandResponseLoadControl | 0x0096 | +| Messages | 0x0097 | | DeviceEnergyManagement | 0x0098 | | EnergyEvse | 0x0099 | | EnergyPreference | 0x009B | @@ -6796,6 +6797,108 @@ class DemandResponseLoadControlClearLoadControlEventsRequest : public ClusterCom chip::app::Clusters::DemandResponseLoadControl::Commands::ClearLoadControlEventsRequest::Type mRequest; }; +/*----------------------------------------------------------------------------*\ +| Cluster Messages | 0x0097 | +|------------------------------------------------------------------------------| +| Commands: | | +| * PresentMessagesRequest | 0x00 | +| * CancelMessagesRequest | 0x01 | +|------------------------------------------------------------------------------| +| Attributes: | | +| * Messages | 0x0000 | +| * ActiveMessageIDs | 0x0001 | +| * GeneratedCommandList | 0xFFF8 | +| * AcceptedCommandList | 0xFFF9 | +| * EventList | 0xFFFA | +| * AttributeList | 0xFFFB | +| * FeatureMap | 0xFFFC | +| * ClusterRevision | 0xFFFD | +|------------------------------------------------------------------------------| +| Events: | | +| * MessageQueued | 0x0000 | +| * MessagePresented | 0x0001 | +| * MessageComplete | 0x0002 | +\*----------------------------------------------------------------------------*/ + +/* + * Command PresentMessagesRequest + */ +class MessagesPresentMessagesRequest : public ClusterCommand +{ +public: + MessagesPresentMessagesRequest(CredentialIssuerCommands * credsIssuerConfig) : + ClusterCommand("present-messages-request", credsIssuerConfig), mComplex_Messages(&mRequest.messages) + { + AddArgument("Messages", &mComplex_Messages); + ClusterCommand::AddArguments(); + } + + CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector endpointIds) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId commandId = chip::app::Clusters::Messages::Commands::PresentMessagesRequest::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on endpoint %u", clusterId, + commandId, endpointIds.at(0)); + return ClusterCommand::SendCommand(device, endpointIds.at(0), clusterId, commandId, mRequest); + } + + CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId commandId = chip::app::Clusters::Messages::Commands::PresentMessagesRequest::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on Group %u", clusterId, commandId, + groupId); + + return ClusterCommand::SendGroupCommand(groupId, fabricIndex, clusterId, commandId, mRequest); + } + +private: + chip::app::Clusters::Messages::Commands::PresentMessagesRequest::Type mRequest; + TypedComplexArgument> + mComplex_Messages; +}; + +/* + * Command CancelMessagesRequest + */ +class MessagesCancelMessagesRequest : public ClusterCommand +{ +public: + MessagesCancelMessagesRequest(CredentialIssuerCommands * credsIssuerConfig) : + ClusterCommand("cancel-messages-request", credsIssuerConfig), mComplex_MessageIDs(&mRequest.messageIDs) + { + AddArgument("MessageIDs", &mComplex_MessageIDs); + ClusterCommand::AddArguments(); + } + + CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector endpointIds) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId commandId = chip::app::Clusters::Messages::Commands::CancelMessagesRequest::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on endpoint %u", clusterId, + commandId, endpointIds.at(0)); + return ClusterCommand::SendCommand(device, endpointIds.at(0), clusterId, commandId, mRequest); + } + + CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId commandId = chip::app::Clusters::Messages::Commands::CancelMessagesRequest::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on Group %u", clusterId, commandId, + groupId); + + return ClusterCommand::SendGroupCommand(groupId, fabricIndex, clusterId, commandId, mRequest); + } + +private: + chip::app::Clusters::Messages::Commands::CancelMessagesRequest::Type mRequest; + TypedComplexArgument> mComplex_MessageIDs; +}; + /*----------------------------------------------------------------------------*\ | Cluster DeviceEnergyManagement | 0x0098 | |------------------------------------------------------------------------------| @@ -20206,6 +20309,74 @@ void registerClusterDemandResponseLoadControl(Commands & commands, CredentialIss commands.RegisterCluster(clusterName, clusterCommands); } +void registerClusterMessages(Commands & commands, CredentialIssuerCommands * credsIssuerConfig) +{ + using namespace chip::app::Clusters::Messages; + + const char * clusterName = "Messages"; + + commands_list clusterCommands = { + // + // Commands + // + make_unique(Id, credsIssuerConfig), // + make_unique(credsIssuerConfig), // + make_unique(credsIssuerConfig), // + // + // Attributes + // + make_unique(Id, credsIssuerConfig), // + make_unique(Id, "messages", Attributes::Messages::Id, credsIssuerConfig), // + make_unique(Id, "active-message-ids", Attributes::ActiveMessageIDs::Id, credsIssuerConfig), // + make_unique(Id, "generated-command-list", Attributes::GeneratedCommandList::Id, credsIssuerConfig), // + make_unique(Id, "accepted-command-list", Attributes::AcceptedCommandList::Id, credsIssuerConfig), // + make_unique(Id, "event-list", Attributes::EventList::Id, credsIssuerConfig), // + make_unique(Id, "attribute-list", Attributes::AttributeList::Id, credsIssuerConfig), // + make_unique(Id, "feature-map", Attributes::FeatureMap::Id, credsIssuerConfig), // + make_unique(Id, "cluster-revision", Attributes::ClusterRevision::Id, credsIssuerConfig), // + make_unique>(Id, credsIssuerConfig), // + make_unique< + WriteAttributeAsComplex>>( + Id, "messages", Attributes::Messages::Id, WriteCommandType::kForceWrite, credsIssuerConfig), // + make_unique>>( + Id, "active-message-ids", Attributes::ActiveMessageIDs::Id, WriteCommandType::kForceWrite, credsIssuerConfig), // + make_unique>>( + Id, "generated-command-list", Attributes::GeneratedCommandList::Id, WriteCommandType::kForceWrite, + credsIssuerConfig), // + make_unique>>( + Id, "accepted-command-list", Attributes::AcceptedCommandList::Id, WriteCommandType::kForceWrite, credsIssuerConfig), // + make_unique>>( + Id, "event-list", Attributes::EventList::Id, WriteCommandType::kForceWrite, credsIssuerConfig), // + make_unique>>( + Id, "attribute-list", Attributes::AttributeList::Id, WriteCommandType::kForceWrite, credsIssuerConfig), // + make_unique>(Id, "feature-map", 0, UINT32_MAX, Attributes::FeatureMap::Id, + WriteCommandType::kForceWrite, credsIssuerConfig), // + make_unique>(Id, "cluster-revision", 0, UINT16_MAX, Attributes::ClusterRevision::Id, + WriteCommandType::kForceWrite, credsIssuerConfig), // + make_unique(Id, credsIssuerConfig), // + make_unique(Id, "messages", Attributes::Messages::Id, credsIssuerConfig), // + make_unique(Id, "active-message-ids", Attributes::ActiveMessageIDs::Id, credsIssuerConfig), // + make_unique(Id, "generated-command-list", Attributes::GeneratedCommandList::Id, credsIssuerConfig), // + make_unique(Id, "accepted-command-list", Attributes::AcceptedCommandList::Id, credsIssuerConfig), // + make_unique(Id, "event-list", Attributes::EventList::Id, credsIssuerConfig), // + make_unique(Id, "attribute-list", Attributes::AttributeList::Id, credsIssuerConfig), // + make_unique(Id, "feature-map", Attributes::FeatureMap::Id, credsIssuerConfig), // + make_unique(Id, "cluster-revision", Attributes::ClusterRevision::Id, credsIssuerConfig), // + // + // Events + // + make_unique(Id, credsIssuerConfig), // + make_unique(Id, "message-queued", Events::MessageQueued::Id, credsIssuerConfig), // + make_unique(Id, "message-presented", Events::MessagePresented::Id, credsIssuerConfig), // + make_unique(Id, "message-complete", Events::MessageComplete::Id, credsIssuerConfig), // + make_unique(Id, credsIssuerConfig), // + make_unique(Id, "message-queued", Events::MessageQueued::Id, credsIssuerConfig), // + make_unique(Id, "message-presented", Events::MessagePresented::Id, credsIssuerConfig), // + make_unique(Id, "message-complete", Events::MessageComplete::Id, credsIssuerConfig), // + }; + + commands.RegisterCluster(clusterName, clusterCommands); +} void registerClusterDeviceEnergyManagement(Commands & commands, CredentialIssuerCommands * credsIssuerConfig) { using namespace chip::app::Clusters::DeviceEnergyManagement; @@ -26425,6 +26596,7 @@ void registerClusters(Commands & commands, CredentialIssuerCommands * credsIssue registerClusterValveConfigurationAndControl(commands, credsIssuerConfig); registerClusterElectricalEnergyMeasurement(commands, credsIssuerConfig); registerClusterDemandResponseLoadControl(commands, credsIssuerConfig); + registerClusterMessages(commands, credsIssuerConfig); registerClusterDeviceEnergyManagement(commands, credsIssuerConfig); registerClusterEnergyEvse(commands, credsIssuerConfig); registerClusterEnergyPreference(commands, credsIssuerConfig); diff --git a/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp b/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp index 302cafb0a0b37b..5813b0e5b12105 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp +++ b/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp @@ -2789,6 +2789,106 @@ void ComplexArgumentParser::Finalize( ComplexArgumentParser::Finalize(request.randomDurationMinutes); } +CHIP_ERROR ComplexArgumentParser::Setup(const char * label, + chip::app::Clusters::Messages::Structs::MessageResponseOptionStruct::Type & request, + Json::Value & value) +{ + VerifyOrReturnError(value.isObject(), CHIP_ERROR_INVALID_ARGUMENT); + + // Copy to track which members we already processed. + Json::Value valueCopy(value); + + char labelWithMember[kMaxLabelLength]; + if (value.isMember("messageResponseID")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "messageResponseID"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.messageResponseID, value["messageResponseID"])); + } + valueCopy.removeMember("messageResponseID"); + + if (value.isMember("label")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "label"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.label, value["label"])); + } + valueCopy.removeMember("label"); + + return ComplexArgumentParser::EnsureNoMembersRemaining(label, valueCopy); +} + +void ComplexArgumentParser::Finalize(chip::app::Clusters::Messages::Structs::MessageResponseOptionStruct::Type & request) +{ + ComplexArgumentParser::Finalize(request.messageResponseID); + ComplexArgumentParser::Finalize(request.label); +} + +CHIP_ERROR ComplexArgumentParser::Setup(const char * label, chip::app::Clusters::Messages::Structs::MessageStruct::Type & request, + Json::Value & value) +{ + VerifyOrReturnError(value.isObject(), CHIP_ERROR_INVALID_ARGUMENT); + + // Copy to track which members we already processed. + Json::Value valueCopy(value); + + ReturnErrorOnFailure( + ComplexArgumentParser::EnsureMemberExist("MessageStruct.messageID", "messageID", value.isMember("messageID"))); + ReturnErrorOnFailure( + ComplexArgumentParser::EnsureMemberExist("MessageStruct.priority", "priority", value.isMember("priority"))); + ReturnErrorOnFailure(ComplexArgumentParser::EnsureMemberExist("MessageStruct.messageControl", "messageControl", + value.isMember("messageControl"))); + ReturnErrorOnFailure( + ComplexArgumentParser::EnsureMemberExist("MessageStruct.startTime", "startTime", value.isMember("startTime"))); + ReturnErrorOnFailure( + ComplexArgumentParser::EnsureMemberExist("MessageStruct.duration", "duration", value.isMember("duration"))); + ReturnErrorOnFailure( + ComplexArgumentParser::EnsureMemberExist("MessageStruct.messageText", "messageText", value.isMember("messageText"))); + + char labelWithMember[kMaxLabelLength]; + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "messageID"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.messageID, value["messageID"])); + valueCopy.removeMember("messageID"); + + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "priority"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.priority, value["priority"])); + valueCopy.removeMember("priority"); + + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "messageControl"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.messageControl, value["messageControl"])); + valueCopy.removeMember("messageControl"); + + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "startTime"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.startTime, value["startTime"])); + valueCopy.removeMember("startTime"); + + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "duration"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.duration, value["duration"])); + valueCopy.removeMember("duration"); + + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "messageText"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.messageText, value["messageText"])); + valueCopy.removeMember("messageText"); + + if (value.isMember("responses")) + { + snprintf(labelWithMember, sizeof(labelWithMember), "%s.%s", label, "responses"); + ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithMember, request.responses, value["responses"])); + } + valueCopy.removeMember("responses"); + + return ComplexArgumentParser::EnsureNoMembersRemaining(label, valueCopy); +} + +void ComplexArgumentParser::Finalize(chip::app::Clusters::Messages::Structs::MessageStruct::Type & request) +{ + ComplexArgumentParser::Finalize(request.messageID); + ComplexArgumentParser::Finalize(request.priority); + ComplexArgumentParser::Finalize(request.messageControl); + ComplexArgumentParser::Finalize(request.startTime); + ComplexArgumentParser::Finalize(request.duration); + ComplexArgumentParser::Finalize(request.messageText); + ComplexArgumentParser::Finalize(request.responses); +} + CHIP_ERROR ComplexArgumentParser::Setup(const char * label, chip::app::Clusters::DeviceEnergyManagement::Structs::CostStruct::Type & request, Json::Value & value) diff --git a/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.h b/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.h index a05d064f16e66e..5a049d98f82048 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.h @@ -342,6 +342,16 @@ static CHIP_ERROR Setup(const char * label, static void Finalize(chip::app::Clusters::DemandResponseLoadControl::Structs::LoadControlProgramStruct::Type & request); +static CHIP_ERROR Setup(const char * label, chip::app::Clusters::Messages::Structs::MessageResponseOptionStruct::Type & request, + Json::Value & value); + +static void Finalize(chip::app::Clusters::Messages::Structs::MessageResponseOptionStruct::Type & request); + +static CHIP_ERROR Setup(const char * label, chip::app::Clusters::Messages::Structs::MessageStruct::Type & request, + Json::Value & value); + +static void Finalize(chip::app::Clusters::Messages::Structs::MessageStruct::Type & request); + static CHIP_ERROR Setup(const char * label, chip::app::Clusters::DeviceEnergyManagement::Structs::CostStruct::Type & request, Json::Value & value); diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp index dc78dc02a54ee7..ed55791683b074 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp @@ -2464,6 +2464,97 @@ CHIP_ERROR DataModelLogger::LogValue( return CHIP_NO_ERROR; } +CHIP_ERROR +DataModelLogger::LogValue(const char * label, size_t indent, + const chip::app::Clusters::Messages::Structs::MessageResponseOptionStruct::DecodableType & value) +{ + DataModelLogger::LogString(label, indent, "{"); + { + CHIP_ERROR err = LogValue("MessageResponseID", indent + 1, value.messageResponseID); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'MessageResponseID'"); + return err; + } + } + { + CHIP_ERROR err = LogValue("Label", indent + 1, value.label); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'Label'"); + return err; + } + } + DataModelLogger::LogString(indent, "}"); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, + const chip::app::Clusters::Messages::Structs::MessageStruct::DecodableType & value) +{ + DataModelLogger::LogString(label, indent, "{"); + { + CHIP_ERROR err = LogValue("MessageID", indent + 1, value.messageID); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'MessageID'"); + return err; + } + } + { + CHIP_ERROR err = LogValue("Priority", indent + 1, value.priority); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'Priority'"); + return err; + } + } + { + CHIP_ERROR err = LogValue("MessageControl", indent + 1, value.messageControl); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'MessageControl'"); + return err; + } + } + { + CHIP_ERROR err = LogValue("StartTime", indent + 1, value.startTime); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'StartTime'"); + return err; + } + } + { + CHIP_ERROR err = LogValue("Duration", indent + 1, value.duration); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'Duration'"); + return err; + } + } + { + CHIP_ERROR err = LogValue("MessageText", indent + 1, value.messageText); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'MessageText'"); + return err; + } + } + { + CHIP_ERROR err = LogValue("Responses", indent + 1, value.responses); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'Responses'"); + return err; + } + } + DataModelLogger::LogString(indent, "}"); + + return CHIP_NO_ERROR; +} + CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const chip::app::Clusters::DeviceEnergyManagement::Structs::CostStruct::DecodableType & value) { @@ -6019,6 +6110,78 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, return CHIP_NO_ERROR; } +CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, + const Messages::Events::MessageQueued::DecodableType & value) +{ + DataModelLogger::LogString(label, indent, "{"); + { + CHIP_ERROR err = DataModelLogger::LogValue("MessageID", indent + 1, value.messageID); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'MessageID'"); + return err; + } + } + DataModelLogger::LogString(indent, "}"); + + return CHIP_NO_ERROR; +} +CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, + const Messages::Events::MessagePresented::DecodableType & value) +{ + DataModelLogger::LogString(label, indent, "{"); + { + CHIP_ERROR err = DataModelLogger::LogValue("MessageID", indent + 1, value.messageID); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'MessageID'"); + return err; + } + } + DataModelLogger::LogString(indent, "}"); + + return CHIP_NO_ERROR; +} +CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, + const Messages::Events::MessageComplete::DecodableType & value) +{ + DataModelLogger::LogString(label, indent, "{"); + { + CHIP_ERROR err = DataModelLogger::LogValue("MessageID", indent + 1, value.messageID); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'MessageID'"); + return err; + } + } + { + CHIP_ERROR err = DataModelLogger::LogValue("ResponseID", indent + 1, value.responseID); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'ResponseID'"); + return err; + } + } + { + CHIP_ERROR err = DataModelLogger::LogValue("Reply", indent + 1, value.reply); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'Reply'"); + return err; + } + } + { + CHIP_ERROR err = DataModelLogger::LogValue("FutureMessagesPreference", indent + 1, value.futureMessagesPreference); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for 'FutureMessagesPreference'"); + return err; + } + } + DataModelLogger::LogString(indent, "}"); + + return CHIP_NO_ERROR; +} CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const DeviceEnergyManagement::Events::PowerAdjustStart::DecodableType & value) { @@ -12243,6 +12406,52 @@ CHIP_ERROR DataModelLogger::LogAttribute(const chip::app::ConcreteDataAttributeP } break; } + case Messages::Id: { + switch (path.mAttributeId) + { + case Messages::Attributes::Messages::Id: { + chip::app::DataModel::DecodableList value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("Messages", 1, value); + } + case Messages::Attributes::ActiveMessageIDs::Id: { + chip::app::DataModel::DecodableList value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("ActiveMessageIDs", 1, value); + } + case Messages::Attributes::GeneratedCommandList::Id: { + chip::app::DataModel::DecodableList value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("GeneratedCommandList", 1, value); + } + case Messages::Attributes::AcceptedCommandList::Id: { + chip::app::DataModel::DecodableList value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("AcceptedCommandList", 1, value); + } + case Messages::Attributes::EventList::Id: { + chip::app::DataModel::DecodableList value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("EventList", 1, value); + } + case Messages::Attributes::AttributeList::Id: { + chip::app::DataModel::DecodableList value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("AttributeList", 1, value); + } + case Messages::Attributes::FeatureMap::Id: { + uint32_t value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("FeatureMap", 1, value); + } + case Messages::Attributes::ClusterRevision::Id: { + uint16_t value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("ClusterRevision", 1, value); + } + } + break; + } case DeviceEnergyManagement::Id: { switch (path.mAttributeId) { @@ -18568,6 +18777,27 @@ CHIP_ERROR DataModelLogger::LogEvent(const chip::app::EventHeader & header, chip } break; } + case Messages::Id: { + switch (header.mPath.mEventId) + { + case Messages::Events::MessageQueued::Id: { + chip::app::Clusters::Messages::Events::MessageQueued::DecodableType value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("MessageQueued", 1, value); + } + case Messages::Events::MessagePresented::Id: { + chip::app::Clusters::Messages::Events::MessagePresented::DecodableType value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("MessagePresented", 1, value); + } + case Messages::Events::MessageComplete::Id: { + chip::app::Clusters::Messages::Events::MessageComplete::DecodableType value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("MessageComplete", 1, value); + } + } + break; + } case DeviceEnergyManagement::Id: { switch (header.mPath.mEventId) { diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h index ee12e5116bd09a..fd4d6895f7ea44 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h @@ -217,6 +217,12 @@ static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::DemandResponseLoadControl::Structs::LoadControlProgramStruct::DecodableType & value); +static CHIP_ERROR LogValue(const char * label, size_t indent, + const chip::app::Clusters::Messages::Structs::MessageResponseOptionStruct::DecodableType & value); + +static CHIP_ERROR LogValue(const char * label, size_t indent, + const chip::app::Clusters::Messages::Structs::MessageStruct::DecodableType & value); + static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::DeviceEnergyManagement::Structs::CostStruct::DecodableType & value); @@ -504,6 +510,12 @@ LogValue(const char * label, size_t indent, static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::DemandResponseLoadControl::Events::LoadControlEventStatusChange::DecodableType & value); +static CHIP_ERROR LogValue(const char * label, size_t indent, + const chip::app::Clusters::Messages::Events::MessageQueued::DecodableType & value); +static CHIP_ERROR LogValue(const char * label, size_t indent, + const chip::app::Clusters::Messages::Events::MessagePresented::DecodableType & value); +static CHIP_ERROR LogValue(const char * label, size_t indent, + const chip::app::Clusters::Messages::Events::MessageComplete::DecodableType & value); static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::DeviceEnergyManagement::Events::PowerAdjustStart::DecodableType & value); static CHIP_ERROR LogValue(const char * label, size_t indent, diff --git a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h index 3b62137fe4f5c7..b68a2b4974cb32 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h @@ -104,6 +104,7 @@ | ValveConfigurationAndControl | 0x0081 | | ElectricalEnergyMeasurement | 0x0091 | | DemandResponseLoadControl | 0x0096 | +| Messages | 0x0097 | | DeviceEnergyManagement | 0x0098 | | EnergyEvse | 0x0099 | | EnergyPreference | 0x009B | @@ -79038,6 +79039,875 @@ class SubscribeAttributeDemandResponseLoadControlClusterRevision : public Subscr } }; +#endif // MTR_ENABLE_PROVISIONAL +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL +/*----------------------------------------------------------------------------*\ +| Cluster Messages | 0x0097 | +|------------------------------------------------------------------------------| +| Commands: | | +| * PresentMessagesRequest | 0x00 | +| * CancelMessagesRequest | 0x01 | +|------------------------------------------------------------------------------| +| Attributes: | | +| * Messages | 0x0000 | +| * ActiveMessageIDs | 0x0001 | +| * GeneratedCommandList | 0xFFF8 | +| * AcceptedCommandList | 0xFFF9 | +| * EventList | 0xFFFA | +| * AttributeList | 0xFFFB | +| * FeatureMap | 0xFFFC | +| * ClusterRevision | 0xFFFD | +|------------------------------------------------------------------------------| +| Events: | | +| * MessageQueued | 0x0000 | +| * MessagePresented | 0x0001 | +| * MessageComplete | 0x0002 | +\*----------------------------------------------------------------------------*/ + +#if MTR_ENABLE_PROVISIONAL +/* + * Command PresentMessagesRequest + */ +class MessagesPresentMessagesRequest : public ClusterCommand { +public: + MessagesPresentMessagesRequest() + : ClusterCommand("present-messages-request") + , mComplex_Messages(&mRequest.messages) + { +#if MTR_ENABLE_PROVISIONAL + AddArgument("Messages", &mComplex_Messages); +#endif // MTR_ENABLE_PROVISIONAL + ClusterCommand::AddArguments(); + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId commandId = chip::app::Clusters::Messages::Commands::PresentMessagesRequest::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on endpoint %u", clusterId, commandId, endpointId); + + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + __auto_type * params = [[MTRMessagesClusterPresentMessagesRequestParams alloc] init]; + params.timedInvokeTimeoutMs = mTimedInteractionTimeoutMs.HasValue() ? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()] : nil; +#if MTR_ENABLE_PROVISIONAL + { // Scope for our temporary variables + auto * array_0 = [NSMutableArray new]; + for (auto & entry_0 : mRequest.messages) { + MTRMessagesClusterMessageStruct * newElement_0; + newElement_0 = [MTRMessagesClusterMessageStruct new]; + newElement_0.messageID = [NSData dataWithBytes:entry_0.messageID.data() length:entry_0.messageID.size()]; + newElement_0.priority = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.priority)]; + newElement_0.messageControl = [NSNumber numberWithUnsignedChar:entry_0.messageControl.Raw()]; + if (entry_0.startTime.IsNull()) { + newElement_0.startTime = nil; + } else { + newElement_0.startTime = [NSNumber numberWithUnsignedInt:entry_0.startTime.Value()]; + } + if (entry_0.duration.IsNull()) { + newElement_0.duration = nil; + } else { + newElement_0.duration = [NSNumber numberWithUnsignedShort:entry_0.duration.Value()]; + } + newElement_0.messageText = [[NSString alloc] initWithBytes:entry_0.messageText.data() length:entry_0.messageText.size() encoding:NSUTF8StringEncoding]; + if (entry_0.responses.HasValue()) { + { // Scope for our temporary variables + auto * array_3 = [NSMutableArray new]; + for (auto & entry_3 : entry_0.responses.Value()) { + MTRMessagesClusterMessageResponseOptionStruct * newElement_3; + newElement_3 = [MTRMessagesClusterMessageResponseOptionStruct new]; + if (entry_3.messageResponseID.HasValue()) { + newElement_3.messageResponseID = [NSNumber numberWithUnsignedInt:entry_3.messageResponseID.Value()]; + } else { + newElement_3.messageResponseID = nil; + } + if (entry_3.label.HasValue()) { + newElement_3.label = [[NSString alloc] initWithBytes:entry_3.label.Value().data() length:entry_3.label.Value().size() encoding:NSUTF8StringEncoding]; + } else { + newElement_3.label = nil; + } + [array_3 addObject:newElement_3]; + } + newElement_0.responses = array_3; + } + } else { + newElement_0.responses = nil; + } + [array_0 addObject:newElement_0]; + } + params.messages = array_0; + } +#endif // MTR_ENABLE_PROVISIONAL + uint16_t repeatCount = mRepeatCount.ValueOr(1); + uint16_t __block responsesNeeded = repeatCount; + while (repeatCount--) { + [cluster presentMessagesRequestWithParams:params completion: + ^(NSError * _Nullable error) { + responsesNeeded--; + if (error != nil) { + mError = error; + LogNSError("Error", error); + RemoteDataModelLogger::LogCommandErrorAsJSON(@(endpointId), @(clusterId), @(commandId), error); + } + if (responsesNeeded == 0) { + SetCommandExitStatus(mError); + } + }]; + } + return CHIP_NO_ERROR; + } + +private: + chip::app::Clusters::Messages::Commands::PresentMessagesRequest::Type mRequest; + TypedComplexArgument> mComplex_Messages; +}; + +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL +/* + * Command CancelMessagesRequest + */ +class MessagesCancelMessagesRequest : public ClusterCommand { +public: + MessagesCancelMessagesRequest() + : ClusterCommand("cancel-messages-request") + , mComplex_MessageIDs(&mRequest.messageIDs) + { +#if MTR_ENABLE_PROVISIONAL + AddArgument("MessageIDs", &mComplex_MessageIDs); +#endif // MTR_ENABLE_PROVISIONAL + ClusterCommand::AddArguments(); + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId commandId = chip::app::Clusters::Messages::Commands::CancelMessagesRequest::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on endpoint %u", clusterId, commandId, endpointId); + + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + __auto_type * params = [[MTRMessagesClusterCancelMessagesRequestParams alloc] init]; + params.timedInvokeTimeoutMs = mTimedInteractionTimeoutMs.HasValue() ? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()] : nil; +#if MTR_ENABLE_PROVISIONAL + { // Scope for our temporary variables + auto * array_0 = [NSMutableArray new]; + for (auto & entry_0 : mRequest.messageIDs) { + NSData * newElement_0; + newElement_0 = [NSData dataWithBytes:entry_0.data() length:entry_0.size()]; + [array_0 addObject:newElement_0]; + } + params.messageIDs = array_0; + } +#endif // MTR_ENABLE_PROVISIONAL + uint16_t repeatCount = mRepeatCount.ValueOr(1); + uint16_t __block responsesNeeded = repeatCount; + while (repeatCount--) { + [cluster cancelMessagesRequestWithParams:params completion: + ^(NSError * _Nullable error) { + responsesNeeded--; + if (error != nil) { + mError = error; + LogNSError("Error", error); + RemoteDataModelLogger::LogCommandErrorAsJSON(@(endpointId), @(clusterId), @(commandId), error); + } + if (responsesNeeded == 0) { + SetCommandExitStatus(mError); + } + }]; + } + return CHIP_NO_ERROR; + } + +private: + chip::app::Clusters::Messages::Commands::CancelMessagesRequest::Type mRequest; + TypedComplexArgument> mComplex_MessageIDs; +}; + +#endif // MTR_ENABLE_PROVISIONAL + +#if MTR_ENABLE_PROVISIONAL + +/* + * Attribute Messages + */ +class ReadMessagesMessages : public ReadAttribute { +public: + ReadMessagesMessages() + : ReadAttribute("messages") + { + } + + ~ReadMessagesMessages() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::AttributeId attributeId = chip::app::Clusters::Messages::Attributes::Messages::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReadAttribute (0x%08" PRIX32 ") on endpoint %u", endpointId, clusterId, attributeId); + + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + [cluster readAttributeMessagesWithCompletion:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.Messages response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + LogNSError("Messages Messages read Error", error); + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + return CHIP_NO_ERROR; + } +}; + +class SubscribeAttributeMessagesMessages : public SubscribeAttribute { +public: + SubscribeAttributeMessagesMessages() + : SubscribeAttribute("messages") + { + } + + ~SubscribeAttributeMessagesMessages() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId attributeId = chip::app::Clusters::Messages::Attributes::Messages::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReportAttribute (0x%08" PRIX32 ") on endpoint %u", clusterId, attributeId, endpointId); + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + __auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)]; + if (mKeepSubscriptions.HasValue()) { + params.replaceExistingSubscriptions = !mKeepSubscriptions.Value(); + } + if (mFabricFiltered.HasValue()) { + params.filterByFabric = mFabricFiltered.Value(); + } + if (mAutoResubscribe.HasValue()) { + params.resubscribeAutomatically = mAutoResubscribe.Value(); + } + [cluster subscribeAttributeMessagesWithParams:params + subscriptionEstablished:^() { mSubscriptionEstablished = YES; } + reportHandler:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.Messages response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + + return CHIP_NO_ERROR; + } +}; + +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + +/* + * Attribute ActiveMessageIDs + */ +class ReadMessagesActiveMessageIDs : public ReadAttribute { +public: + ReadMessagesActiveMessageIDs() + : ReadAttribute("active-message-ids") + { + } + + ~ReadMessagesActiveMessageIDs() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::AttributeId attributeId = chip::app::Clusters::Messages::Attributes::ActiveMessageIDs::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReadAttribute (0x%08" PRIX32 ") on endpoint %u", endpointId, clusterId, attributeId); + + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + [cluster readAttributeActiveMessageIDsWithCompletion:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.ActiveMessageIDs response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + LogNSError("Messages ActiveMessageIDs read Error", error); + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + return CHIP_NO_ERROR; + } +}; + +class SubscribeAttributeMessagesActiveMessageIDs : public SubscribeAttribute { +public: + SubscribeAttributeMessagesActiveMessageIDs() + : SubscribeAttribute("active-message-ids") + { + } + + ~SubscribeAttributeMessagesActiveMessageIDs() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId attributeId = chip::app::Clusters::Messages::Attributes::ActiveMessageIDs::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReportAttribute (0x%08" PRIX32 ") on endpoint %u", clusterId, attributeId, endpointId); + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + __auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)]; + if (mKeepSubscriptions.HasValue()) { + params.replaceExistingSubscriptions = !mKeepSubscriptions.Value(); + } + if (mFabricFiltered.HasValue()) { + params.filterByFabric = mFabricFiltered.Value(); + } + if (mAutoResubscribe.HasValue()) { + params.resubscribeAutomatically = mAutoResubscribe.Value(); + } + [cluster subscribeAttributeActiveMessageIDsWithParams:params + subscriptionEstablished:^() { mSubscriptionEstablished = YES; } + reportHandler:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.ActiveMessageIDs response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + + return CHIP_NO_ERROR; + } +}; + +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + +/* + * Attribute GeneratedCommandList + */ +class ReadMessagesGeneratedCommandList : public ReadAttribute { +public: + ReadMessagesGeneratedCommandList() + : ReadAttribute("generated-command-list") + { + } + + ~ReadMessagesGeneratedCommandList() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::AttributeId attributeId = chip::app::Clusters::Messages::Attributes::GeneratedCommandList::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReadAttribute (0x%08" PRIX32 ") on endpoint %u", endpointId, clusterId, attributeId); + + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + [cluster readAttributeGeneratedCommandListWithCompletion:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.GeneratedCommandList response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + LogNSError("Messages GeneratedCommandList read Error", error); + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + return CHIP_NO_ERROR; + } +}; + +class SubscribeAttributeMessagesGeneratedCommandList : public SubscribeAttribute { +public: + SubscribeAttributeMessagesGeneratedCommandList() + : SubscribeAttribute("generated-command-list") + { + } + + ~SubscribeAttributeMessagesGeneratedCommandList() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId attributeId = chip::app::Clusters::Messages::Attributes::GeneratedCommandList::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReportAttribute (0x%08" PRIX32 ") on endpoint %u", clusterId, attributeId, endpointId); + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + __auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)]; + if (mKeepSubscriptions.HasValue()) { + params.replaceExistingSubscriptions = !mKeepSubscriptions.Value(); + } + if (mFabricFiltered.HasValue()) { + params.filterByFabric = mFabricFiltered.Value(); + } + if (mAutoResubscribe.HasValue()) { + params.resubscribeAutomatically = mAutoResubscribe.Value(); + } + [cluster subscribeAttributeGeneratedCommandListWithParams:params + subscriptionEstablished:^() { mSubscriptionEstablished = YES; } + reportHandler:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.GeneratedCommandList response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + + return CHIP_NO_ERROR; + } +}; + +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + +/* + * Attribute AcceptedCommandList + */ +class ReadMessagesAcceptedCommandList : public ReadAttribute { +public: + ReadMessagesAcceptedCommandList() + : ReadAttribute("accepted-command-list") + { + } + + ~ReadMessagesAcceptedCommandList() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::AttributeId attributeId = chip::app::Clusters::Messages::Attributes::AcceptedCommandList::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReadAttribute (0x%08" PRIX32 ") on endpoint %u", endpointId, clusterId, attributeId); + + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + [cluster readAttributeAcceptedCommandListWithCompletion:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.AcceptedCommandList response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + LogNSError("Messages AcceptedCommandList read Error", error); + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + return CHIP_NO_ERROR; + } +}; + +class SubscribeAttributeMessagesAcceptedCommandList : public SubscribeAttribute { +public: + SubscribeAttributeMessagesAcceptedCommandList() + : SubscribeAttribute("accepted-command-list") + { + } + + ~SubscribeAttributeMessagesAcceptedCommandList() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId attributeId = chip::app::Clusters::Messages::Attributes::AcceptedCommandList::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReportAttribute (0x%08" PRIX32 ") on endpoint %u", clusterId, attributeId, endpointId); + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + __auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)]; + if (mKeepSubscriptions.HasValue()) { + params.replaceExistingSubscriptions = !mKeepSubscriptions.Value(); + } + if (mFabricFiltered.HasValue()) { + params.filterByFabric = mFabricFiltered.Value(); + } + if (mAutoResubscribe.HasValue()) { + params.resubscribeAutomatically = mAutoResubscribe.Value(); + } + [cluster subscribeAttributeAcceptedCommandListWithParams:params + subscriptionEstablished:^() { mSubscriptionEstablished = YES; } + reportHandler:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.AcceptedCommandList response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + + return CHIP_NO_ERROR; + } +}; + +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + +/* + * Attribute EventList + */ +class ReadMessagesEventList : public ReadAttribute { +public: + ReadMessagesEventList() + : ReadAttribute("event-list") + { + } + + ~ReadMessagesEventList() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::AttributeId attributeId = chip::app::Clusters::Messages::Attributes::EventList::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReadAttribute (0x%08" PRIX32 ") on endpoint %u", endpointId, clusterId, attributeId); + + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + [cluster readAttributeEventListWithCompletion:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.EventList response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + LogNSError("Messages EventList read Error", error); + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + return CHIP_NO_ERROR; + } +}; + +class SubscribeAttributeMessagesEventList : public SubscribeAttribute { +public: + SubscribeAttributeMessagesEventList() + : SubscribeAttribute("event-list") + { + } + + ~SubscribeAttributeMessagesEventList() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId attributeId = chip::app::Clusters::Messages::Attributes::EventList::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReportAttribute (0x%08" PRIX32 ") on endpoint %u", clusterId, attributeId, endpointId); + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + __auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)]; + if (mKeepSubscriptions.HasValue()) { + params.replaceExistingSubscriptions = !mKeepSubscriptions.Value(); + } + if (mFabricFiltered.HasValue()) { + params.filterByFabric = mFabricFiltered.Value(); + } + if (mAutoResubscribe.HasValue()) { + params.resubscribeAutomatically = mAutoResubscribe.Value(); + } + [cluster subscribeAttributeEventListWithParams:params + subscriptionEstablished:^() { mSubscriptionEstablished = YES; } + reportHandler:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.EventList response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + + return CHIP_NO_ERROR; + } +}; + +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + +/* + * Attribute AttributeList + */ +class ReadMessagesAttributeList : public ReadAttribute { +public: + ReadMessagesAttributeList() + : ReadAttribute("attribute-list") + { + } + + ~ReadMessagesAttributeList() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::AttributeId attributeId = chip::app::Clusters::Messages::Attributes::AttributeList::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReadAttribute (0x%08" PRIX32 ") on endpoint %u", endpointId, clusterId, attributeId); + + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + [cluster readAttributeAttributeListWithCompletion:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.AttributeList response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + LogNSError("Messages AttributeList read Error", error); + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + return CHIP_NO_ERROR; + } +}; + +class SubscribeAttributeMessagesAttributeList : public SubscribeAttribute { +public: + SubscribeAttributeMessagesAttributeList() + : SubscribeAttribute("attribute-list") + { + } + + ~SubscribeAttributeMessagesAttributeList() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId attributeId = chip::app::Clusters::Messages::Attributes::AttributeList::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReportAttribute (0x%08" PRIX32 ") on endpoint %u", clusterId, attributeId, endpointId); + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + __auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)]; + if (mKeepSubscriptions.HasValue()) { + params.replaceExistingSubscriptions = !mKeepSubscriptions.Value(); + } + if (mFabricFiltered.HasValue()) { + params.filterByFabric = mFabricFiltered.Value(); + } + if (mAutoResubscribe.HasValue()) { + params.resubscribeAutomatically = mAutoResubscribe.Value(); + } + [cluster subscribeAttributeAttributeListWithParams:params + subscriptionEstablished:^() { mSubscriptionEstablished = YES; } + reportHandler:^(NSArray * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.AttributeList response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + + return CHIP_NO_ERROR; + } +}; + +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + +/* + * Attribute FeatureMap + */ +class ReadMessagesFeatureMap : public ReadAttribute { +public: + ReadMessagesFeatureMap() + : ReadAttribute("feature-map") + { + } + + ~ReadMessagesFeatureMap() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::AttributeId attributeId = chip::app::Clusters::Messages::Attributes::FeatureMap::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReadAttribute (0x%08" PRIX32 ") on endpoint %u", endpointId, clusterId, attributeId); + + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + [cluster readAttributeFeatureMapWithCompletion:^(NSNumber * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.FeatureMap response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + LogNSError("Messages FeatureMap read Error", error); + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + return CHIP_NO_ERROR; + } +}; + +class SubscribeAttributeMessagesFeatureMap : public SubscribeAttribute { +public: + SubscribeAttributeMessagesFeatureMap() + : SubscribeAttribute("feature-map") + { + } + + ~SubscribeAttributeMessagesFeatureMap() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId attributeId = chip::app::Clusters::Messages::Attributes::FeatureMap::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReportAttribute (0x%08" PRIX32 ") on endpoint %u", clusterId, attributeId, endpointId); + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + __auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)]; + if (mKeepSubscriptions.HasValue()) { + params.replaceExistingSubscriptions = !mKeepSubscriptions.Value(); + } + if (mFabricFiltered.HasValue()) { + params.filterByFabric = mFabricFiltered.Value(); + } + if (mAutoResubscribe.HasValue()) { + params.resubscribeAutomatically = mAutoResubscribe.Value(); + } + [cluster subscribeAttributeFeatureMapWithParams:params + subscriptionEstablished:^() { mSubscriptionEstablished = YES; } + reportHandler:^(NSNumber * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.FeatureMap response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + + return CHIP_NO_ERROR; + } +}; + +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + +/* + * Attribute ClusterRevision + */ +class ReadMessagesClusterRevision : public ReadAttribute { +public: + ReadMessagesClusterRevision() + : ReadAttribute("cluster-revision") + { + } + + ~ReadMessagesClusterRevision() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::AttributeId attributeId = chip::app::Clusters::Messages::Attributes::ClusterRevision::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReadAttribute (0x%08" PRIX32 ") on endpoint %u", endpointId, clusterId, attributeId); + + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + [cluster readAttributeClusterRevisionWithCompletion:^(NSNumber * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.ClusterRevision response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + LogNSError("Messages ClusterRevision read Error", error); + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + return CHIP_NO_ERROR; + } +}; + +class SubscribeAttributeMessagesClusterRevision : public SubscribeAttribute { +public: + SubscribeAttributeMessagesClusterRevision() + : SubscribeAttribute("cluster-revision") + { + } + + ~SubscribeAttributeMessagesClusterRevision() + { + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::Messages::Id; + constexpr chip::CommandId attributeId = chip::app::Clusters::Messages::Attributes::ClusterRevision::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReportAttribute (0x%08" PRIX32 ") on endpoint %u", clusterId, attributeId, endpointId); + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterMessages alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + __auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)]; + if (mKeepSubscriptions.HasValue()) { + params.replaceExistingSubscriptions = !mKeepSubscriptions.Value(); + } + if (mFabricFiltered.HasValue()) { + params.filterByFabric = mFabricFiltered.Value(); + } + if (mAutoResubscribe.HasValue()) { + params.resubscribeAutomatically = mAutoResubscribe.Value(); + } + [cluster subscribeAttributeClusterRevisionWithParams:params + subscriptionEstablished:^() { mSubscriptionEstablished = YES; } + reportHandler:^(NSNumber * _Nullable value, NSError * _Nullable error) { + NSLog(@"Messages.ClusterRevision response %@", [value description]); + if (error == nil) { + RemoteDataModelLogger::LogAttributeAsJSON(@(endpointId), @(clusterId), @(attributeId), value); + } else { + RemoteDataModelLogger::LogAttributeErrorAsJSON(@(endpointId), @(clusterId), @(attributeId), error); + } + SetCommandExitStatus(error); + }]; + + return CHIP_NO_ERROR; + } +}; + #endif // MTR_ENABLE_PROVISIONAL #endif // MTR_ENABLE_PROVISIONAL #if MTR_ENABLE_PROVISIONAL @@ -183070,6 +183940,63 @@ void registerClusterDemandResponseLoadControl(Commands & commands) commands.RegisterCluster(clusterName, clusterCommands); #endif // MTR_ENABLE_PROVISIONAL } +void registerClusterMessages(Commands & commands) +{ +#if MTR_ENABLE_PROVISIONAL + using namespace chip::app::Clusters::Messages; + + const char * clusterName = "Messages"; + + commands_list clusterCommands = { + make_unique(Id), // +#if MTR_ENABLE_PROVISIONAL + make_unique(), // +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + make_unique(), // +#endif // MTR_ENABLE_PROVISIONAL + make_unique(Id), // + make_unique(Id), // + make_unique(Id), // +#if MTR_ENABLE_PROVISIONAL + make_unique(), // + make_unique(), // +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + make_unique(), // + make_unique(), // +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + make_unique(), // + make_unique(), // +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + make_unique(), // + make_unique(), // +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + make_unique(), // + make_unique(), // +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + make_unique(), // + make_unique(), // +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + make_unique(), // + make_unique(), // +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + make_unique(), // + make_unique(), // +#endif // MTR_ENABLE_PROVISIONAL + make_unique(Id), // + make_unique(Id), // + }; + + commands.RegisterCluster(clusterName, clusterCommands); +#endif // MTR_ENABLE_PROVISIONAL +} void registerClusterDeviceEnergyManagement(Commands & commands) { #if MTR_ENABLE_PROVISIONAL @@ -186975,6 +187902,7 @@ void registerClusters(Commands & commands) registerClusterValveConfigurationAndControl(commands); registerClusterElectricalEnergyMeasurement(commands); registerClusterDemandResponseLoadControl(commands); + registerClusterMessages(commands); registerClusterDeviceEnergyManagement(commands); registerClusterEnergyEvse(commands); registerClusterEnergyPreference(commands);