using server.Services;
///
/// 多线程通信总线
///
public sealed class MsgBus
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
// private static RtspStreamService _rtspStreamService = new RtspStreamService(new UsbCameraCapture());
private static readonly UDPServer udpServer = new UDPServer(1234, 12);
///
/// 获取UDP服务器
///
public static UDPServer UDPServer { get { return udpServer; } }
// 添加静态ProgressTracker引用
private static ProgressTracker? _progressTracker;
///
/// 设置全局ProgressTracker实例
///
public static void SetProgressTracker(ProgressTracker progressTracker)
{
_progressTracker = progressTracker;
}
public static ProgressTracker ProgressTracker
{
get
{
if (_progressTracker == null)
{
throw new InvalidOperationException("ProgressTracker is not set.");
}
return _progressTracker;
}
}
private static bool isRunning = false;
///
/// 获取通信总线运行状态
///
public static bool IsRunning { get { return isRunning; } }
private MsgBus() { }
static MsgBus() { }
///
/// 通信总线初始化
///
/// 无
public static async void Init()
{
if (!ArpClient.IsAdministrator())
{
logger.Error($"非管理员运行,ARP无法更新,请用管理员权限运行");
// throw new Exception($"非管理员运行,ARP无法更新,请用管理员权限运行");
}
udpServer.Start();
// _rtspStreamService.ConfigureVideo(1920, 1080, 30);
// await _rtspStreamService.StartAsync();
isRunning = true;
}
///
/// 关闭通信总线
///
/// 无
public static void Exit()
{
udpServer.Stop();
isRunning = false;
}
}