hxb
2022-11-24 535d69817e83737f3da6250fc6fb70da25fc1a4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.common.openapi;
 
import android.os.Message;
 
import com.common.openapi.entity.DeviceLocalCacheData;
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessRunnable;
import com.mm.android.deviceaddmodule.mobilecommon.base.LCBusinessHandler;
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.BusinessErrorTip;
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.HandleMessageCode;
 
public class DeviceLocalCacheService {
 
    /**
     * 添加设备缓存信息
     * @param localCacheData
     */
    public void addLocalCache(final DeviceLocalCacheData localCacheData) {
        new BusinessRunnable(null) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    DeviceLocalCacheManager deviceLocalCacheManager = ClassInstanceManager.newInstance().getDeviceLocalCacheManager();
                    deviceLocalCacheManager.addLocalCache(localCacheData);
                } catch (Throwable e) {
                    throw e;
                }
            }
        };
    }
 
    /**
     * 获取设备缓存信息
     * @param localCacheData
     * @param deviceCacheCallBack
     */
    public void findLocalCache(final DeviceLocalCacheData localCacheData, final IGetDeviceInfoCallBack.IDeviceCacheCallBack deviceCacheCallBack) {
        final LCBusinessHandler handler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if (deviceCacheCallBack == null) {
                    return;
                }
                if (msg.what == HandleMessageCode.HMC_SUCCESS) {
                    //成功
                    deviceCacheCallBack.deviceCache((DeviceLocalCacheData) msg.obj);
                } else {
                    //失败
                    deviceCacheCallBack.onError(BusinessErrorTip.throwError(msg));
                }
            }
        };
        new BusinessRunnable(handler) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    DeviceLocalCacheData localCache = ClassInstanceManager.newInstance().getDeviceLocalCacheManager().findLocalCache(localCacheData);
                    if (localCache != null) {
                        handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, localCache).sendToTarget();
                    } else {
                        throw new BusinessException("null point");
                    }
                } catch (Throwable e) {
                    throw e;
                }
            }
        };
    }
}