continuity/Rai.PacketMediator/PacketDistributorService.cs

33 lines
1.1 KiB
C#
Raw Normal View History

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