2023-02-16 23:54:23 +00:00
|
|
|
|
using System.Reflection.Metadata;
|
|
|
|
|
using Dalamud.Logging;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2023-02-16 09:25:33 +00:00
|
|
|
|
|
2023-03-30 20:01:43 +00:00
|
|
|
|
namespace Pal.Client.Scheduled;
|
|
|
|
|
|
|
|
|
|
internal interface IQueueOnFrameworkThread
|
2022-12-22 00:01:09 +00:00
|
|
|
|
{
|
2023-03-30 20:01:43 +00:00
|
|
|
|
internal interface IHandler
|
2022-12-22 00:01:09 +00:00
|
|
|
|
{
|
2023-03-30 20:01:43 +00:00
|
|
|
|
void RunIfCompatible(IQueueOnFrameworkThread queued, ref bool recreateLayout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal abstract class Handler<T> : IHandler
|
|
|
|
|
where T : IQueueOnFrameworkThread
|
|
|
|
|
{
|
|
|
|
|
protected readonly ILogger<Handler<T>> _logger;
|
|
|
|
|
|
|
|
|
|
protected Handler(ILogger<Handler<T>> logger)
|
2023-02-16 09:25:33 +00:00
|
|
|
|
{
|
2023-03-30 20:01:43 +00:00
|
|
|
|
_logger = logger;
|
2023-02-16 09:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-30 20:01:43 +00:00
|
|
|
|
protected abstract void Run(T queued, ref bool recreateLayout);
|
2023-02-16 23:54:23 +00:00
|
|
|
|
|
2023-03-30 20:01:43 +00:00
|
|
|
|
public void RunIfCompatible(IQueueOnFrameworkThread queued, ref bool recreateLayout)
|
|
|
|
|
{
|
|
|
|
|
if (queued is T t)
|
2023-02-16 23:54:23 +00:00
|
|
|
|
{
|
2023-03-30 20:01:43 +00:00
|
|
|
|
_logger.LogDebug("Handling {QueuedType}", queued.GetType());
|
|
|
|
|
Run(t, ref recreateLayout);
|
2023-02-16 23:54:23 +00:00
|
|
|
|
}
|
2023-03-30 20:01:43 +00:00
|
|
|
|
else
|
2023-02-16 09:25:33 +00:00
|
|
|
|
{
|
2023-03-30 20:01:43 +00:00
|
|
|
|
_logger.LogError("Could not use queue handler {QueuedType}", queued.GetType());
|
2023-02-16 09:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-22 00:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|