Skip to content

Commit

Permalink
Add Kotlin ICD Client Info
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed Apr 26, 2024
1 parent 22d1c67 commit 67f2312
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 60 deletions.
2 changes: 2 additions & 0 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,14 @@ kotlin_library("kotlin_matter_controller") {
sources = [
"src/matter/controller/CompletionListenerAdapter.kt",
"src/matter/controller/ControllerParams.kt",
"src/matter/controller/ICDClientInfo.kt",
"src/matter/controller/InteractionClient.kt",
"src/matter/controller/InvokeCallback.kt",
"src/matter/controller/InvokeCallbackJni.kt",
"src/matter/controller/MatterController.kt",
"src/matter/controller/MatterControllerException.kt",
"src/matter/controller/MatterControllerImpl.kt",
"src/matter/controller/MatterICDClientImpl.kt",
"src/matter/controller/Messages.kt",
"src/matter/controller/OperationalKeyConfig.kt",
"src/matter/controller/ReportCallback.kt",
Expand Down
31 changes: 31 additions & 0 deletions src/controller/java/src/matter/controller/ICDClientInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 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 matter.controller

/** Class for holding ICD Client information. */
data class ICDClientInfo(
val peerNodeId: Long,
val startCounter: Long,
val offset: Long,
val monitoredSubject: Long,
val icdAesKey: ByteArray,
val icdHmacKey: ByteArray
) {
override fun toString(): String = "$peerNodeId/$startCounter/$offset/$monitoredSubject"
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ interface InteractionClient {
* operation.
*/
suspend fun invoke(request: InvokeRequest): InvokeResponse

fun getRemoteDeviceId(devicePtr: Long): Long

fun getFabricIndex(devicePtr: Long): Int
}
68 changes: 8 additions & 60 deletions src/controller/java/src/matter/controller/MatterControllerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ class MatterControllerImpl(params: ControllerParams) : MatterController {
reportHandler,
resubscriptionAttemptHandler
)

val fabricIndex = getFabricIndex(devicePtr)
val deviceId = getRemoteDeviceId(devicePtr)
subscribe(
deviceControllerPtr,
reportCallbackJni.getJniHandle(),
Expand All @@ -215,7 +218,7 @@ class MatterControllerImpl(params: ControllerParams) : MatterController {
request.keepSubscriptions,
request.fabricFiltered,
CHIP_IM_TIMEOUT_MS,
false
MatterICDClientImpl.isPeerICDClient(fabricIndex, deviceId)
)

awaitClose { logger.log(Level.FINE, "Closing flow") }
Expand Down Expand Up @@ -452,6 +455,10 @@ class MatterControllerImpl(params: ControllerParams) : MatterController {
imTimeoutMs: Int
)

override external fun getRemoteDeviceId(devicePtr: Long): Long

override external fun getFabricIndex(devicePtr: Long): Int

override fun close() {
logger.log(Level.INFO, "MatterController is closed")
deviceController.shutdownCommissioning()
Expand Down Expand Up @@ -479,65 +486,6 @@ class MatterControllerImpl(params: ControllerParams) : MatterController {
}
}

// private fun ChipAttributePath.wrap(): AttributePath {
// return AttributePath(
// endpointId.getId().toUShort(),
// clusterId.getId().toUInt(),
// attributeId.getId().toUInt()
// )
// }

// private fun ChipEventPath.wrap(): EventPath {
// return EventPath(
// endpointId.getId().toUShort(),
// clusterId.getId().toUInt(),
// eventId.getId().toUInt()
// )
// }

// private fun chip.devicecontroller.model.NodeState.wrap(): NodeState {
// return NodeState(
// endpoints = endpointStates.mapValues { (id, value) -> value.wrap(id) }.toMutableMap(),
// )
// }

// private fun chip.devicecontroller.model.EndpointState.wrap(id: Int): EndpointState {
// return EndpointState(
// id,
// clusterStates.mapValues { (id, value) -> value.wrap(id) }.toMutableMap()
// )
// }

// private fun chip.devicecontroller.model.ClusterState.wrap(id: Long): ClusterState {
// return ClusterState(
// id,
// attributeStates.mapValues { (id, value) -> value.wrap(id) }.toMutableMap(),
// eventStates
// .mapValues { (id, value) ->
// value.map { eventState -> eventState.wrap(id) }.toMutableList()
// }
// .toMutableMap()
// )
// }

// private fun chip.devicecontroller.model.AttributeState.wrap(id: Long): AttributeState {
// return AttributeState(id, tlv, json.toString(), AttributePath(0U, 0U, id.toUInt()), value)
// }

// private fun chip.devicecontroller.model.EventState.wrap(id: Long): EventState {
// return EventState(
// id,
// eventNumber,
// priorityLevel,
// timestampType,
// timestampValue,
// tlv,
// EventPath(0U, 0U, id.toUInt()),
// json.toString(),
// value
// )
// }

init {
val config: OperationalKeyConfig? = params.operationalKeyConfig
val paramsBuilder =
Expand Down
28 changes: 28 additions & 0 deletions src/controller/java/src/matter/controller/MatterICDClientImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 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 matter.controller

object MatterICDClientImpl {
fun isPeerICDClient(fabricIndex: Int, deviceId: Long): Boolean {
val clientInfo = getICDClientInfo(fabricIndex) ?: return false
return clientInfo.firstOrNull { it.peerNodeId == deviceId } != null
}

external fun getICDClientInfo(fabricIndex: Int): List<ICDClientInfo>?
}

0 comments on commit 67f2312

Please sign in to comment.