2026-01-26 14:51:28 +09:00

58 lines
2.0 KiB
C#

/*
* Copyright (c) 2025 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using Aurora;
using Aurora.Api;
using VisionCommon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using VisionSequence.Pattern;
namespace VisionUI.Pattern {
/// <summary>
/// 강제 OK 핸들러
/// </summary>
public static class ForceOkHandler {
private static object _lock = new object();
private static Logger _logger = new Logger(typeof(ForceOkHandler).Name);
private static Dictionary<FovInfo, IDisposable> _forceOkHandlers = new Dictionary<FovInfo, IDisposable>();
/// <summary>
/// 핸들러 추가
/// </summary>
/// <param name="fovInfo">핸들러 사전 키 (Fov 정보)</param>
public static void SetHandler(FovInfo fovInfo) {
lock (_lock) {
if (!_forceOkHandlers.ContainsKey(fovInfo)) {
_forceOkHandlers.Add(fovInfo, CreateHandler(fovInfo));
}
}
}
private static IDisposable CreateHandler(FovInfo fovInfo) {
return VisionEnv.AuroraEnv.EventObservable.AsObservable(VisionEventId.REQUEST_PATTERN_FORCE_OK)
.Where(x => x.From == fovInfo.GetKey())
.Subscribe(em => DoEvent(em));
}
private static void DoEvent(EventMessage em) {
_logger.FuncI();
Task.Run(() => {
lock (_lock) {
var forceOkReqParam = em.Param as ForceOkReqParam;
forceOkReqParam.PatternResult = ForceOkWindow.Show(
forceOkReqParam.FovInfo,
forceOkReqParam.PatternIndex,
forceOkReqParam.FindImage,
forceOkReqParam.PatternResult);
forceOkReqParam.IsDone = true;
}
});
}
}
}