/* * WhackerLink - WhackerLinkLib * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Copyright (C) 2024-2025 Caleb, K4PHP * */ using WhackerLinkLib.Models.Radio; using WhackerLinkLib.Network; namespace WhackerLinkConsoleV2 { /// /// WhackerLink peer/client websocket manager for having multiple systems /// public class FneSystemManager { private readonly Dictionary _webSocketHandlers; /// /// Creates an instance of /// public FneSystemManager() { _webSocketHandlers = new Dictionary(); } /// /// Create a new for a new system /// /// public void AddFneSystem(string systemId, Codeplug.System system, MainWindow mainWindow) { if (!_webSocketHandlers.ContainsKey(systemId)) { _webSocketHandlers[systemId] = new PeerSystem(mainWindow, system); } } /// /// Return a by looking up a systemid /// /// /// /// public PeerSystem GetFneSystem(string systemId) { if (_webSocketHandlers.TryGetValue(systemId, out var handler)) { return handler; } throw new KeyNotFoundException($"WebSocketHandler for system '{systemId}' not found."); } /// /// Delete a by system id /// /// public void RemoveFneSystem(string systemId) { if (_webSocketHandlers.TryGetValue(systemId, out var handler)) { handler.peer.Stop(); _webSocketHandlers.Remove(systemId); } } /// /// Check if the manager has a handler /// /// /// public bool HasFneSystem(string systemId) { return _webSocketHandlers.ContainsKey(systemId); } /// /// Cleanup /// public void ClearAll() { foreach (var handler in _webSocketHandlers.Values) { handler.peer.Stop(); } _webSocketHandlers.Clear(); } } }