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

commonMain.org.brightify.hyperdrive.krpc.impl.DefaultServiceRegistry.kt Maven / Gradle / Ivy

package org.brightify.hyperdrive.krpc.impl

import org.brightify.hyperdrive.krpc.MutableServiceRegistry
import org.brightify.hyperdrive.krpc.description.RunnableCallDescription
import org.brightify.hyperdrive.krpc.description.ServiceCallIdentifier
import org.brightify.hyperdrive.krpc.description.ServiceDescription
import kotlin.reflect.KClass

class DefaultServiceRegistry: MutableServiceRegistry {
    private val services: MutableMap = mutableMapOf()
    private val serviceCalls: MutableMap>> = mutableMapOf()

    override fun register(description: ServiceDescription) {
        services[description.identifier] = description

        serviceCalls[description.identifier] = description.calls.map {
            it.identifier.callId to it
        }.toMap()
    }

    override fun > getCallById(id: ServiceCallIdentifier, type: KClass): T? {
        val knownCall = serviceCalls[id.serviceId]?.get(id.callId) ?: return null
        return if (type.isInstance(knownCall)) {
            @Suppress("UNCHECKED_CAST")
            knownCall as T
        } else {
            null
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy