package com.dlc.exam.mqtt

import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Binder
import android.os.IBinder
import com.dlc.exam.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() {
            MqttManager.instance.initMqtt(CommonUtils.getAndroidId(context), context.applicationContext)
            MqttManager.instance.connect()
        }

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

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

}