diff --git a/examples/java-matter-controller/include/CHIPProjectAppConfig.h b/examples/java-matter-controller/include/CHIPProjectAppConfig.h index 5805016d714427..09183cc4485256 100644 --- a/examples/java-matter-controller/include/CHIPProjectAppConfig.h +++ b/examples/java-matter-controller/include/CHIPProjectAppConfig.h @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @file - * Project configuration for Matter Controller. - * - */ #ifndef CHIPPROJECTCONFIG_H #define CHIPPROJECTCONFIG_H diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/Argument.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/Argument.kt index 905eba96f2860b..ac8d6ae942bac5 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/Argument.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/Argument.kt @@ -171,7 +171,7 @@ class Argument { isValidArgument = try { val ipAddress = this.value as IPAddress - ipAddress.setAddress(InetAddress.getByName(value)) + ipAddress.address = InetAddress.getByName(value) true } catch (e: UnknownHostException) { false diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CredentialsIssuer.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CredentialsIssuer.kt index d3e6d4e84fb48b..a0a384860af93c 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CredentialsIssuer.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/CredentialsIssuer.kt @@ -19,6 +19,6 @@ package com.matter.controller.commands.common /** * Credentials Issuer which contains all credential information of the issuer of the command, such - * as operational credentials for a given fabric, the DAC verifier of the commisioner, etc .. + * as operational credentials for a given fabric, the DAC verifier of the commissioner, etc .. */ class CredentialsIssuer diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.kt index c04abd99188e9b..5fe4b5240dce3d 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.kt @@ -30,13 +30,8 @@ import java.util.logging.Logger */ class FutureResult { private var realResult: RealResult? = null - private var timeoutMs: Long = 0 - private val logger = Logger.getLogger(FutureResult::class.java.name) private val lock = Object() - - fun setTimeoutMs(timeoutMs: Long) { - this.timeoutMs = timeoutMs - } + var timeoutMs: Long = 0 fun setRealResult(realResult: RealResult) { synchronized(lock) { @@ -52,17 +47,21 @@ class FutureResult { val start = System.currentTimeMillis() synchronized(lock) { while (realResult == null) { + val remainingTime = timeoutMs - (System.currentTimeMillis() - start) + if (remainingTime <= 0) { + throw TimeoutException("Timeout!") + } + try { - if (System.currentTimeMillis() > start + timeoutMs) { - throw TimeoutException("Timeout!") - } - lock.wait() + lock.wait(remainingTime) } catch (e: InterruptedException) { logger.log(Level.INFO, "Wait Result failed with exception: " + e.message) } } - if (realResult?.result == false) { - logger.log(Level.INFO, "Error: ${realResult?.error}") + + val errorResult = realResult as? RealResult.Error + if (errorResult != null) { + logger.log(Level.INFO, "Error: ${errorResult.error}") throw TimeoutException("Received failure test result") } } @@ -71,4 +70,8 @@ class FutureResult { fun clear() { synchronized(lock) { realResult = null } } + + companion object { + private val logger = Logger.getLogger(FutureResult::class.java.name) + } } diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/IPAddress.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/IPAddress.kt index d86a9caf40f751..c28ce9c5d5a055 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/IPAddress.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/IPAddress.kt @@ -19,15 +19,7 @@ package com.matter.controller.commands.common import java.net.InetAddress -class IPAddress(private var address: InetAddress) { - fun setAddress(address: InetAddress) { - this.address = address - } - - fun getHostAddress(): String { - return address.hostAddress - } - +class IPAddress(var address: InetAddress) { override fun toString(): String { return address.toString() } diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/MatterCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/MatterCommand.kt index 8732ad6a3b521d..e4f3b20e8a97a9 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/MatterCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/MatterCommand.kt @@ -103,7 +103,7 @@ abstract class MatterCommand( } fun waitCompleteMs(timeoutMs: Long) { - futureResult.setTimeoutMs(timeoutMs) + futureResult.timeoutMs = timeoutMs futureResult.waitResult() } diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/RealResult.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/RealResult.kt index 5ea218e32a2522..50debc33f0d014 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/RealResult.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/RealResult.kt @@ -19,24 +19,23 @@ package com.matter.controller.commands.common /** - * Implements a Result where an error string is associated with its failure state. + * Represents a result that can either indicate success or failure with an associated error message. * - *

A `Result` is just a booean of true/false that is exposed via `getResult`. This class will - * contain either a `true` value for `Success` or a `false` value in which case the failure will - * also have an error string explaining the reason of the failure associated with it. + * In the context of RealResult, success is represented by [Success] and failure by [Error]. When + * there is an error, an error message explains the reason for the failure. */ -class RealResult(val result: Boolean, val error: String?) { - constructor() : this(true, null) +sealed class RealResult { + data class Error(val error: String) : RealResult() - constructor(error: String?) : this(false, error) + object Success : RealResult() companion object { fun success(): RealResult { - return RealResult() + return Success } fun error(error: String?): RealResult { - return RealResult(error) + return error?.let { Error(it) } ?: Success } } } diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.kt index 183b9bf3d86b61..c3c608fa8d1554 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.kt @@ -43,7 +43,7 @@ class PairAddressPaseCommand(controller: ChipDeviceController, credsIssue: Crede currentCommissioner() .establishPaseConnection( getNodeId(), - getRemoteAddr().getHostAddress(), + getRemoteAddr().address.hostAddress, getRemotePort(), getSetupPINCode() ) diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.kt index fa5a9041f87879..e11fb8694e4e79 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.kt @@ -35,7 +35,7 @@ class PairAlreadyDiscoveredCommand( currentCommissioner() .pairDeviceWithAddress( getNodeId(), - getRemoteAddr().getHostAddress(), + getRemoteAddr().address.hostAddress, getRemotePort(), getDiscriminator(), getSetupPINCode(), diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.kt index 6d05e5ff6cc876..4769a8bf85bf22 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.kt @@ -38,7 +38,7 @@ class PairOnNetworkLongCommand( currentCommissioner() .pairDeviceWithAddress( getNodeId(), - getRemoteAddr().getHostAddress(), + getRemoteAddr().address.hostAddress, MATTER_PORT, getDiscriminator(), getSetupPINCode(), diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt index 73eab9eb15537f..59e1ccff6dbdf9 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt @@ -129,7 +129,7 @@ class PairOnNetworkLongImInvokeCommand( currentCommissioner() .pairDeviceWithAddress( getNodeId(), - getRemoteAddr().getHostAddress(), + getRemoteAddr().address.hostAddress, MATTER_PORT, getDiscriminator(), getSetupPINCode(), diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt index e5f5711e359aef..80587a37fdf992 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt @@ -172,7 +172,7 @@ class PairOnNetworkLongImReadCommand( currentCommissioner() .pairDeviceWithAddress( getNodeId(), - getRemoteAddr().getHostAddress(), + getRemoteAddr().address.hostAddress, MATTER_PORT, getDiscriminator(), getSetupPINCode(), diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImSubscribeCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImSubscribeCommand.kt index f7de0942f0c2cc..1c0957db981232 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImSubscribeCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImSubscribeCommand.kt @@ -84,7 +84,7 @@ class PairOnNetworkLongImSubscribeCommand( currentCommissioner() .pairDeviceWithAddress( getNodeId(), - getRemoteAddr().getHostAddress(), + getRemoteAddr().address.hostAddress, MATTER_PORT, getDiscriminator(), getSetupPINCode(), diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt index 10945a4e67af9f..6d116fc922a35a 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt @@ -97,7 +97,7 @@ class PairOnNetworkLongImWriteCommand( currentCommissioner() .pairDeviceWithAddress( getNodeId(), - getRemoteAddr().getHostAddress(), + getRemoteAddr().address.hostAddress, MATTER_PORT, getDiscriminator(), getSetupPINCode(),