Add ActiveDevice + DeviceRegistry + HubEnvelopes + IDeviceClient/Channel implementations
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace backend.DeviceHub;
|
||||
|
||||
public class DeviceRegistry
|
||||
{
|
||||
private readonly ConcurrentDictionary<Guid, ActiveDevice> _online = new();
|
||||
|
||||
public bool TryRegister(ActiveDevice dev)
|
||||
=> _online.TryAdd(dev.DeviceId, dev);
|
||||
|
||||
public bool Unregister(Guid deviceId)
|
||||
=> _online.TryRemove(deviceId, out _);
|
||||
|
||||
public ActiveDevice? Get(Guid deviceId)
|
||||
=> _online.TryGetValue(deviceId, out var d) ? d : null;
|
||||
|
||||
public bool IsOnline(Guid deviceId) => _online.ContainsKey(deviceId);
|
||||
|
||||
public int OnlineCount => _online.Count;
|
||||
}
|
||||
Reference in New Issue
Block a user