-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[java-matter-controller] Convert from java to kotlin phase I (#25384)
* [java-matter-controller] Convert from java to kotlin phase I * Address review comments * Move constants outside the class instance
- Loading branch information
1 parent
ad33a94
commit 18424d6
Showing
12 changed files
with
281 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.8.10.jar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 0 additions & 125 deletions
125
examples/java-matter-controller/java/src/com/matter/controller/Main.java
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
examples/java-matter-controller/java/src/com/matter/controller/Main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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.* | ||
|
||
private fun getDiscoveryCommands( | ||
controller: ChipDeviceController, | ||
credentialsIssuer: CredentialsIssuer | ||
): List<Command> { | ||
return listOf( | ||
DiscoverCommand(controller, credentialsIssuer), | ||
DiscoverCommissionablesCommand(controller, credentialsIssuer), | ||
DiscoverCommissionersCommand(controller, credentialsIssuer), | ||
) | ||
} | ||
|
||
private fun getPairingCommands( | ||
controller: ChipDeviceController, | ||
credentialsIssuer: CredentialsIssuer | ||
): List<Command> { | ||
return listOf( | ||
UnpairCommand(controller, credentialsIssuer), | ||
PairCodeCommand(controller, credentialsIssuer), | ||
PairCodePaseCommand(controller, credentialsIssuer), | ||
PairCodeWifiCommand(controller, credentialsIssuer), | ||
PairCodeThreadCommand(controller, credentialsIssuer), | ||
PairAddressPaseCommand(controller, credentialsIssuer), | ||
PairAlreadyDiscoveredCommand(controller, credentialsIssuer), | ||
PairOnNetworkCommand(controller, credentialsIssuer), | ||
PairOnNetworkShortCommand(controller, credentialsIssuer), | ||
PairOnNetworkLongCommand(controller, credentialsIssuer), | ||
PairOnNetworkVendorCommand(controller, credentialsIssuer), | ||
PairOnNetworkCommissioningModeCommand(controller, credentialsIssuer), | ||
PairOnNetworkCommissionerCommand(controller, credentialsIssuer), | ||
PairOnNetworkDeviceTypeCommand(controller, credentialsIssuer), | ||
PairOnNetworkInstanceNameCommand(controller, credentialsIssuer), | ||
) | ||
} | ||
|
||
fun main(args: Array<String>) { | ||
val controller = ChipDeviceController( | ||
ControllerParams.newBuilder() | ||
.setUdpListenPort(0) | ||
.setControllerVendorId(0xFFF1) | ||
.setCountryCode("US") | ||
.build() | ||
) | ||
val credentialsIssuer = CredentialsIssuer() | ||
val commandManager = CommandManager() | ||
|
||
commandManager.register("discover", getDiscoveryCommands(controller, credentialsIssuer)) | ||
commandManager.register("pairing", getPairingCommands(controller, credentialsIssuer)) | ||
|
||
try { | ||
commandManager.run(args) | ||
} catch (e: Exception) { | ||
println("Run command failed with exception: " + e.message) | ||
System.exit(1) | ||
} | ||
controller.shutdownCommissioning() | ||
} |
Oops, something went wrong.