All Downloads are FREE. Search and download functionalities are using the official Maven repository.

library.GroupDoipTcpConnectionMessageHandler.kt Maven / Gradle / Ivy

Go to download

This is a kotlin based domain specific language (dsl), to quickly and intuitively write custom DoIP ECU simulations.

There is a newer version: 0.15.1
Show newest version
package library

import io.ktor.utils.io.ByteWriteChannel

public 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.firstOrNull { it.existsTargetAddress(diagMessage.targetAddress) } ?: list.first()
            handler.onIncomingDiagMessage(diagMessage, output)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy