package com.dlc.chemical.mqtt

import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Binder
import android.os.IBinder
import com.dlc.chemical.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.applicationContext)
            MqttManager.instance.connect()
        }

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

        fun subscribe(topicFilter: String, qos: Int) {
            MqttManager.instance.subscribe(topicFilter, qos)
        }
    }

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

}