continuity/Rai.PacketMediator/PacketDistributorService.cs

32 lines
1.1 KiB
C#

// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
using System.Reflection;
namespace Rai.PacketMediator;
public class PacketDistributorService<TPacketIdEnum, TSession> : Microsoft.Extensions.Hosting.IHostedService
where TPacketIdEnum : Enum
{
private readonly PacketDistributor<TPacketIdEnum, TSession> _packetDistributor;
public PacketDistributorService(IServiceProvider serviceProvider,
Assembly[] sourcesContainingPackets)
{
_packetDistributor = new PacketDistributor<TPacketIdEnum, TSession>(serviceProvider, sourcesContainingPackets);
}
public Task StartAsync(CancellationToken cancellationToken)
{
return _packetDistributor.DequeueRawPacketAsync(cancellationToken);
}
public Task AddPacketAsync(byte[] packetData, TPacketIdEnum operationCode, TSession session)
{
return this._packetDistributor.AddPacketAsync(packetData, operationCode, session);
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}