2024-02-04 18:52:45 +00:00
|
|
|
// 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-04 18:52:45 +00:00
|
|
|
{
|
2024-02-05 11:08:00 +00:00
|
|
|
private readonly PacketDistributor<TPacketIdEnum, TSession> _packetDistributor;
|
2024-02-04 18:52:45 +00:00
|
|
|
|
|
|
|
public PacketDistributorService(IServiceProvider serviceProvider,
|
|
|
|
Assembly[] sourcesContainingPackets)
|
|
|
|
{
|
2024-02-05 11:08:00 +00:00
|
|
|
_packetDistributor = new PacketDistributor<TPacketIdEnum, TSession>(serviceProvider, sourcesContainingPackets);
|
2024-02-04 18:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
|
|
{
|
2024-02-05 11:08:00 +00:00
|
|
|
return _packetDistributor.DequeueRawPacketAsync(cancellationToken);
|
2024-02-04 18:52:45 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 11:08:00 +00:00
|
|
|
public Task AddPacketAsync(byte[] packetData, TPacketIdEnum operationCode, TSession session)
|
2024-02-04 18:52:45 +00:00
|
|
|
{
|
2024-02-05 11:08:00 +00:00
|
|
|
return this._packetDistributor.AddPacketAsync(packetData, operationCode, session);
|
2024-02-04 18:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
}
|