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.

The newest version!
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) }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy