Skip to content

Commit

Permalink
[java-matter-controller] Convert from java to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Feb 27, 2023
1 parent 7a62c12 commit c9193a3
Show file tree
Hide file tree
Showing 63 changed files with 1,760 additions and 1,777 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build:0.6.40
image: connectedhomeip/chip-build-java:0.6.42
options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0
net.ipv4.conf.all.forwarding=0 net.ipv6.conf.all.forwarding=0"

Expand Down
81 changes: 47 additions & 34 deletions examples/java-matter-controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,67 @@ import("//build_overrides/chip.gni")
import("${chip_root}/build/chip/java/rules.gni")
import("${chip_root}/build/chip/tools.gni")

java_binary("java-matter-controller") {
output_name = "java-matter-controller"
java_library("java") {
output_name = "JavaMatterController.jar"
deps = [
"${chip_root}/src/controller/java",
"${chip_root}/src/setup_payload/java",
"${chip_root}/third_party/java_deps:annotation",
]

sources = [
"java/src/com/matter/controller/Main.java",
"java/src/com/matter/controller/commands/common/Argument.java",
"java/src/com/matter/controller/commands/common/ArgumentType.java",
"java/src/com/matter/controller/commands/common/Command.java",
"java/src/com/matter/controller/commands/common/CommandManager.java",
"java/src/com/matter/controller/commands/common/CredentialsIssuer.java",
"java/src/com/matter/controller/commands/common/FutureResult.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/discover/DiscoverCommand.java",
"java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.java",
"java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.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/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" ]
}

kotlin_binary("java-matter-controller") {
output_name = "java-matter-controller"
deps = [
":java",
"${chip_root}/third_party/java_deps:kotlin-stdlib",
]

sources = [
"java/src/com/matter/controller/Main.kt",
"java/src/com/matter/controller/commands/common/Argument.kt",
"java/src/com/matter/controller/commands/common/ArgumentType.kt",
"java/src/com/matter/controller/commands/common/Command.kt",
"java/src/com/matter/controller/commands/common/CommandManager.kt",
"java/src/com/matter/controller/commands/common/CredentialsIssuer.kt",
"java/src/com/matter/controller/commands/common/IPAddress.kt",
"java/src/com/matter/controller/commands/common/MatterCommand.kt",
"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/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" ]
}

group("default") {
deps = [ ":java-matter-controller" ]
}
4 changes: 2 additions & 2 deletions examples/java-matter-controller/Manifest.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Main-Class: com.matter.controller.Main
Class-Path: ../lib/third_party/connectedhomeip/src/controller/java/CHIPController.jar ../lib/third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar ../lib/third_party/connectedhomeip/third_party/java_deps/stub_src/Android.jar ../lib/third_party/connectedhomeip/third_party/java_deps/json-20220924.jar ../lib/third_party/connectedhomeip/third_party/java_deps/jsr305-3.0.2.jar
Main-Class: com.matter.controller.MainKt
Class-Path: ../lib/third_party/connectedhomeip/src/controller/java/CHIPController.jar ../lib/third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar ../lib/third_party/connectedhomeip/third_party/java_deps/stub_src/Android.jar ../lib/third_party/connectedhomeip/third_party/java_deps/json-20220924.jar ../lib/third_party/connectedhomeip/third_party/java_deps/jsr305-3.0.2.jar ../lib/third_party/connectedhomeip/third_party/java_deps/kotlin-stdlib-1.3.31.jar

100 changes: 100 additions & 0 deletions examples/java-matter-controller/java/src/com/matter/controller/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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

import chip.devicecontroller.ChipDeviceController
import chip.devicecontroller.ControllerParams
import com.matter.controller.commands.common.*
import com.matter.controller.commands.discover.*
import com.matter.controller.commands.pairing.*
import java.util.ArrayList

private fun registerCommandsDiscover(
controller: ChipDeviceController,
commandManager: CommandManager,
credentialsIssuer: CredentialsIssuer
) {
val clusterCommands: ArrayList<Command> = ArrayList<Command>()
val discoverCommand = DiscoverCommand(controller, credentialsIssuer)
val discoverCommissionablesCommand = DiscoverCommissionablesCommand(controller, credentialsIssuer)
val discoverCommissionersCommand = DiscoverCommissionersCommand(controller, credentialsIssuer)
clusterCommands.add(discoverCommand)
clusterCommands.add(discoverCommissionablesCommand)
clusterCommands.add(discoverCommissionersCommand)
commandManager.register("discover", clusterCommands)
}

private fun registerCommandsPairing(
controller: ChipDeviceController,
commandManager: CommandManager,
credentialsIssuer: CredentialsIssuer
) {
val clusterCommands: ArrayList<Command> = ArrayList<Command>()
val unpairCommand = UnpairCommand(controller, credentialsIssuer)
val pairCodeCommand = PairCodeCommand(controller, credentialsIssuer)
val pairCodePaseCommand = PairCodePaseCommand(controller, credentialsIssuer)
val pairCodeWifiCommand = PairCodeWifiCommand(controller, credentialsIssuer)
val pairCodeThreadCommand = PairCodeThreadCommand(controller, credentialsIssuer)
val pairAddressPaseCommand = PairAddressPaseCommand(controller, credentialsIssuer)
val pairAlreadyDiscoveredCommand = PairAlreadyDiscoveredCommand(controller, credentialsIssuer)
val pairOnNetworkCommand = PairOnNetworkCommand(controller, credentialsIssuer)
val pairOnNetworkShortCommand = PairOnNetworkShortCommand(controller, credentialsIssuer)
val pairOnNetworkLongCommand = PairOnNetworkLongCommand(controller, credentialsIssuer)
val pairOnNetworkVendorCommand = PairOnNetworkVendorCommand(controller, credentialsIssuer)
val pairOnNetworkCommissioningModeCommand = PairOnNetworkCommissioningModeCommand(controller, credentialsIssuer)
val pairOnNetworkCommissionerCommand = PairOnNetworkCommissionerCommand(controller, credentialsIssuer)
val pairOnNetworkDeviceTypeCommand = PairOnNetworkDeviceTypeCommand(controller, credentialsIssuer)
val pairOnNetworkInstanceNameCommand = PairOnNetworkInstanceNameCommand(controller, credentialsIssuer)
clusterCommands.add(unpairCommand)
clusterCommands.add(pairCodeCommand)
clusterCommands.add(pairCodePaseCommand)
clusterCommands.add(pairCodeWifiCommand)
clusterCommands.add(pairCodeThreadCommand)
clusterCommands.add(pairAddressPaseCommand)
clusterCommands.add(pairAlreadyDiscoveredCommand)
clusterCommands.add(pairOnNetworkCommand)
clusterCommands.add(pairOnNetworkShortCommand)
clusterCommands.add(pairOnNetworkLongCommand)
clusterCommands.add(pairOnNetworkVendorCommand)
clusterCommands.add(pairOnNetworkCommissioningModeCommand)
clusterCommands.add(pairOnNetworkCommissionerCommand)
clusterCommands.add(pairOnNetworkDeviceTypeCommand)
clusterCommands.add(pairOnNetworkInstanceNameCommand)
commandManager.register("pairing", clusterCommands)
}

fun main(args: Array<String>) {
val controller = ChipDeviceController(
ControllerParams.newBuilder()
.setUdpListenPort(0)
.setControllerVendorId(0xFFF1)
.setCountryCode("US")
.build()
)
val credentialsIssuer = CredentialsIssuer()
val commandManager = CommandManager()
registerCommandsDiscover(controller, commandManager, credentialsIssuer)
registerCommandsPairing(controller, commandManager, credentialsIssuer)
try {
commandManager.run(args)
} catch (e: Exception) {
println("Run command failed with exception: " + e.message)
System.exit(1)
}
controller.shutdownCommissioning()
}

This file was deleted.

Loading

0 comments on commit c9193a3

Please sign in to comment.