package com.dlc.eboard.mqtt

import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Binder
import android.os.IBinder
import com.dlc.eboard.common.CommonUtils

/**
 * info
 *
 * @author ReiChin_
 */
class MqttService : Service() {

    private val mBinder by lazy {
        MqttBinder(this)
    }

    override fun onBind(intent: Intent?): IBinder {
        return mBinder
    }

    class MqttBinder(val context: Context) : Binder() {

        fun initMqtt(subId: String) {
            MqttManager.instance.initMqtt(subId, CommonUtils.getAndroidId(), context.applicationContext)
            MqttManager.instance.connect()
        }

        fun releaseMqtt() {
            MqttManager.instance.release()
        }
    }

    override fun onDestroy() {
        MqttManager.instance.release()
        super.onDestroy()
    }

}