package com.ccnet.acc.native

object VpnNativeDispatcher {
    val JNI_CLAZZ_NAME = VpnNativeDispatcher::class.java.name.replace(".", "/")

    private val NATIVE_CALLBACKS: MutableMap<String, NativeCallback> = mutableMapOf()

    @JvmStatic
    fun registerCallback(key: String, listener: NativeCallback) {
        NATIVE_CALLBACKS[key] = listener
    }

    @JvmStatic
    private fun onStart() {
        for (eventListener in NATIVE_CALLBACKS.values) {
            eventListener.onStart()
        }
    }

    @JvmStatic
    fun onError(code: Int, error: String) {
        for (eventListener in NATIVE_CALLBACKS.values) {
            eventListener.onError(NativeCallback.ErrorCode.from(code), error)
        }
    }

    @JvmStatic
    fun onFatal(code: Int, error: String) {
        for (eventListener in NATIVE_CALLBACKS.values) {
            eventListener.onFatal(NativeCallback.ErrorCode.from(code), error)
        }
    }
}