添加契约和网络传输类库
This commit is contained in:
@@ -9,6 +9,8 @@ namespace SHH.CameraSdk;
|
||||
/// </summary>
|
||||
public class SmartFrame : IDisposable
|
||||
{
|
||||
public List<string> SubscriberIds { get; } = new List<string>(16);
|
||||
|
||||
#region --- 私有资源与状态 (Private Resources & States) ---
|
||||
|
||||
/// <summary> 所属帧池:用于引用归零后自动回收复用 </summary>
|
||||
@@ -114,6 +116,10 @@ public class SmartFrame : IDisposable
|
||||
TargetMat = null;
|
||||
}
|
||||
ScaleType = FrameScaleType.None;
|
||||
|
||||
// 2. [核心逻辑] 清空订阅者列表
|
||||
// 注意:Clear() 只是把 Count 设为 0,底层数组容量不变,不会触发 GC
|
||||
SubscriberIds.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -30,6 +30,38 @@ public static class GlobalStreamDispatcher
|
||||
|
||||
#endregion
|
||||
|
||||
// =================================================================
|
||||
// 1. 新增:真正的全局广播总线 (上帝模式)
|
||||
// 任何订阅了这个事件的人,都能收到【所有设备】的每一帧
|
||||
// =================================================================
|
||||
public static event Action<long, SmartFrame> OnGlobalFrame;
|
||||
|
||||
// =================================================================
|
||||
// 2. 原有:定向分发逻辑 (保留不动,给图像处理集群用)
|
||||
// =================================================================
|
||||
// private static ConcurrentDictionary<string, ...> _subscribers ...
|
||||
|
||||
/// <summary>
|
||||
/// 统一入口:驱动层调用此方法分发图像
|
||||
/// </summary>
|
||||
public static void Dispatch(long deviceId, SmartFrame frame)
|
||||
{
|
||||
// A. 优先触发全局广播 (给 ZeroMQ 用)
|
||||
try
|
||||
{
|
||||
// ?.Invoke 是线程安全的,如果设备被删除了,驱动层不调用 Dispatch,这里自然就不会触发
|
||||
// 如果新设备增加了,驱动层开始调用 Dispatch,这里自动就会触发
|
||||
OnGlobalFrame?.Invoke(deviceId, frame);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[GlobalBus Error] 广播异常: {ex.Message}");
|
||||
}
|
||||
|
||||
// B. 执行你原有的定向分发逻辑 (给处理链用)
|
||||
// DispatchToTargets(deviceId, frame);
|
||||
}
|
||||
|
||||
#region --- 2. 动态路由表 (Dynamic Routing Table) ---
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user