抽离自车状态回调监听

Signed-off-by: 董宏宇 <martindhy@gmail.com>
This commit is contained in:
董宏宇
2021-11-02 14:21:03 +08:00
parent 246998e46c
commit 7fd5b7e9d6
9 changed files with 115 additions and 39 deletions

View File

@@ -1,7 +1,6 @@
package com.mogo.eagle.core.function.call.autopilot
import androidx.annotation.Nullable
import com.mogo.eagle.core.data.autopilot.AutopilotCarStateInfo
import com.mogo.eagle.core.data.autopilot.AutopilotGuardianStatusInfo
import com.mogo.eagle.core.data.autopilot.AutopilotStationInfo
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo
@@ -121,22 +120,6 @@ object CallerAutoPilotStatusListenerManager : CallerBase() {
}
}
/**
* 车辆状态数据 回调
* @param autoPilotCarStateInfo
*/
@Synchronized
fun invokeAutopilotCarStateData(autoPilotCarStateInfo: AutopilotCarStateInfo?) {
//Logger.d(TAG, "$autoPilotCarStateInfo")
M_AUTOPILOT_STATUS_LISTENERS.forEach {
val tag = it.key
val listener = it.value
//Logger.d(TAG, "tag:$tag listener:$listener")
listener.onAutopilotCarStateData(autoPilotCarStateInfo)
}
}
/**
* 工控机获取SN 回调
*/

View File

@@ -0,0 +1,78 @@
package com.mogo.eagle.core.function.call.autopilot
import androidx.annotation.Nullable
import com.mogo.eagle.core.data.autopilot.AutopilotCarStateInfo
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotCarStateListener
import com.mogo.eagle.core.function.call.base.CallerBase
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
/**
* @author xiaoyuzhou
* @date 2021/9/30 5:48 下午
* 车辆状态&定位 数据 数据 回调监听
*/
object CallerAutopilotCarStatusListenerManager : CallerBase() {
private val TAG = "CallerAutopilotCarStatusListenerManager"
// 存储所有注册了监听的对象invokeXXXX进行遍历回调将信息同步
private val M_AUTOPILOT_STATUS_LISTENERS: HashMap<String, IMoGoAutopilotCarStateListener> =
HashMap()
/**
* 添加监听
* @param tag 标记,用来注销监听使用
* @param listener 监听回调
*/
fun addListener(
@Nullable tag: String,
@Nullable listener: IMoGoAutopilotCarStateListener
) {
if (M_AUTOPILOT_STATUS_LISTENERS.containsKey(tag)) {
Logger.e(TAG, "Tag:$tag already exists,please use other tag")
return
}
M_AUTOPILOT_STATUS_LISTENERS[tag] = listener
}
/**
* 删除监听
* @param tag 标记,用来注销监听使用
*/
fun removeListener(@Nullable tag: String) {
if (!M_AUTOPILOT_STATUS_LISTENERS.containsKey(tag)) {
Logger.e(TAG, "Tag:$tag not exists")
return
}
M_AUTOPILOT_STATUS_LISTENERS.remove(tag)
}
/**
* 删除自动驾驶按钮选中监听
* @param listener 要删除的监听对象
*/
fun removeListener(@Nullable listener: IMoGoAutopilotCarStateListener) {
M_AUTOPILOT_STATUS_LISTENERS.forEach {
if (it.value == listener) {
M_AUTOPILOT_STATUS_LISTENERS.remove(it.key)
}
}
}
/**
* 车辆状态数据 回调
* @param autoPilotCarStateInfo
*/
@Synchronized
fun invokeAutopilotCarStateData(autoPilotCarStateInfo: AutopilotCarStateInfo?) {
//Logger.d(TAG, "$autoPilotCarStateInfo")
M_AUTOPILOT_STATUS_LISTENERS.forEach {
val tag = it.key
val listener = it.value
//Logger.d(TAG, "tag:$tag listener:$listener")
listener.onAutopilotCarStateData(autoPilotCarStateInfo)
}
}
}