library.GroupDoipTcpConnectionMessageHandler.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-sim-ecu-dsl Show documentation
Show all versions of doip-sim-ecu-dsl Show documentation
This is a kotlin based domain specific language (dsl), to quickly and intuitively write custom DoIP ECU simulations.
package library
import io.ktor.utils.io.ByteWriteChannel
public open class GroupDoipTcpConnectionMessageHandler(
entities: List>,
socket: DoipTcpSocket,
tlsOptions: TlsOptions?,
) : DefaultDoipEntityTcpConnectionMessageHandler(entities.first(), socket, entities.first().config.logicalAddress.toShort(), entities.first(), tlsOptions) {
private val diagnosticMessageHandler: List = entities.map { it }
init {
super.diagMessageHandler = GroupHandler(diagnosticMessageHandler)
}
public class GroupHandler(private val list: List) : DiagnosticMessageHandler {
override fun existsTargetAddress(targetAddress: Short): Boolean =
list.any { it.existsTargetAddress(targetAddress) }
override suspend fun onIncomingDiagMessage(
diagMessage: DoipTcpDiagMessage,
output: ByteWriteChannel
) {
val handler = list.filter { it.existsTargetAddress(diagMessage.targetAddress) }
handler.forEach { it.onIncomingDiagMessage(diagMessage, output) }
}
}
}