Skip to content

Commit

Permalink
[java-matter-controller] Convert from java to kotlin phase II
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Mar 7, 2023
1 parent 2a6f4ef commit 5496cab
Show file tree
Hide file tree
Showing 42 changed files with 1,032 additions and 824 deletions.
44 changes: 22 additions & 22 deletions examples/java-matter-controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,7 @@ java_library("java") {
"java/src/com/matter/controller/commands/common/IPAddress.java",
"java/src/com/matter/controller/commands/common/MatterCommand.java",
"java/src/com/matter/controller/commands/common/RealResult.java",
"java/src/com/matter/controller/commands/pairing/CloseSessionCommand.java",
"java/src/com/matter/controller/commands/pairing/DiscoveryFilterType.java",
"java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.java",
"java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.java",
"java/src/com/matter/controller/commands/pairing/PairCodeCommand.java",
"java/src/com/matter/controller/commands/pairing/PairCodePaseCommand.java",
"java/src/com/matter/controller/commands/pairing/PairCodeThreadCommand.java",
"java/src/com/matter/controller/commands/pairing/PairCodeWifiCommand.java",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkCommand.java",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissionerCommand.java",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissioningModeCommand.java",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkDeviceTypeCommand.java",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkFabricCommand.java",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.java",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.java",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.java",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.java",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.java",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkVendorCommand.java",
"java/src/com/matter/controller/commands/pairing/PairingCommand.java",
"java/src/com/matter/controller/commands/pairing/PairingModeType.java",
"java/src/com/matter/controller/commands/pairing/PairingNetworkType.java",
"java/src/com/matter/controller/commands/pairing/UnpairCommand.java",
]

javac_flags = [ "-Xlint:deprecation" ]
Expand All @@ -76,6 +54,28 @@ kotlin_binary("java-matter-controller") {
"java/src/com/matter/controller/commands/discover/DiscoverCommand.kt",
"java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt",
"java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.kt",
"java/src/com/matter/controller/commands/pairing/CloseSessionCommand.kt",
"java/src/com/matter/controller/commands/pairing/DiscoveryFilterType.kt",
"java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairCodeCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairCodePaseCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairCodeThreadCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairCodeWifiCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissionerCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissioningModeCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkDeviceTypeCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkFabricCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairOnNetworkVendorCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairingCommand.kt",
"java/src/com/matter/controller/commands/pairing/PairingModeType.kt",
"java/src/com/matter/controller/commands/pairing/PairingNetworkType.kt",
"java/src/com/matter/controller/commands/pairing/UnpairCommand.kt",
]

kotlinc_flags = [ "-Xlint:deprecation" ]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 com.matter.controller.commands.pairing

import chip.devicecontroller.ChipDeviceController
import com.matter.controller.commands.common.CredentialsIssuer
import com.matter.controller.commands.common.MatterCommand
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong

class CloseSessionCommand(controller: ChipDeviceController, credsIssuer: CredentialsIssuer?) :
MatterCommand(controller, "close-session", credsIssuer) {
private val destinationId: AtomicLong = AtomicLong()
private val timeoutSecs: AtomicInteger = AtomicInteger()

init {
addArgument("destination-id", 0, Long.MAX_VALUE, destinationId, null, false)
addArgument(
"timeout", 0.toShort(), Short.MAX_VALUE,
timeoutSecs,
"Time, in seconds, before this command is considered to have timed out.",
false
)
}

override fun runCommand() {}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
/*
* Copyright (c) 2022 Project CHIP Authors
* All rights reserved.
*
* 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 com.matter.controller.commands.pairing;

public enum DiscoveryFilterType {
NONE,
SHORT_DISCRIMINATOR,
LONG_DISCRIMINATOR,
VENDOR_ID,
DEVICE_TYPE,
COMMISSIONING_MODE,
INSTANCE_NAME,
COMMISSIONER,
COMPRESSED_FABRIC_ID,
}
/*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 com.matter.controller.commands.pairing

enum class DiscoveryFilterType {
NONE, SHORT_DISCRIMINATOR, LONG_DISCRIMINATOR, VENDOR_ID, DEVICE_TYPE, COMMISSIONING_MODE, INSTANCE_NAME, COMMISSIONER, COMPRESSED_FABRIC_ID
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 com.matter.controller.commands.pairing

import chip.devicecontroller.ChipDeviceController
import com.matter.controller.commands.common.CredentialsIssuer
import java.util.logging.Level
import java.util.logging.Logger

class PairAddressPaseCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : PairingCommand(
controller,
"address-paseonly",
PairingModeType.ADDRESS_PASE_ONLY,
PairingNetworkType.NONE,
credsIssue
) {
private val logger = Logger.getLogger(PairAddressPaseCommand::class.java.name)

override fun onPairingComplete(errorCode: Int) {
logger.log(Level.INFO, "onPairingComplete with error code: $errorCode")
if (errorCode == 0) {
setSuccess()
} else {
setFailure("onPairingComplete failure")
}
}

override fun runCommand() {
currentCommissioner()
.establishPaseConnection(
getNodeId(),
getRemoteAddr().getHostAddress(),
getRemotePort(),
getSetupPINCode()
)
currentCommissioner().setCompletionListener(this)
waitCompleteMs(getTimeoutMillis())
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 com.matter.controller.commands.pairing

import chip.devicecontroller.ChipDeviceController
import com.matter.controller.commands.common.CredentialsIssuer

class PairAlreadyDiscoveredCommand(
controller: ChipDeviceController, credsIssue: CredentialsIssuer?
) : PairingCommand(
controller,
"already-discovered",
PairingModeType.ALREADY_DISCOVERED,
PairingNetworkType.NONE,
credsIssue
) {
override fun runCommand() {
currentCommissioner()
.pairDeviceWithAddress(
getNodeId(),
getRemoteAddr().getHostAddress(),
getRemotePort(),
getDiscriminator(),
getSetupPINCode(),
null
)
currentCommissioner().setCompletionListener(this)
waitCompleteMs(getTimeoutMillis())
}
}

This file was deleted.

Loading

0 comments on commit 5496cab

Please sign in to comment.