EzIPC experiments

This commit is contained in:
RisaDev
2024-03-11 00:17:09 +03:00
parent 57c91eb834
commit e9b3fc4d3d
9 changed files with 54 additions and 64 deletions

View File

@@ -1,4 +1,5 @@
using Dalamud.Plugin.Ipc;
using ECommons.EzIpcManager;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -8,20 +9,16 @@ using static Penumbra.Api.Ipc;
namespace CustomizePlus.Api;
//I'm not a big fan of having functions and variables/properties
//grouped up like that but it makes sense here
public partial class CustomizePlusIpc : IDisposable
public partial class CustomizePlusIpc
{
private readonly (int Breaking, int Feature) _apiVersion = (4, 0);
/// <summary>
/// When there are breaking changes the first number is bumped up and second one is reset.
/// When there are non-breaking changes only second number is bumped up.
/// In general clients should not try to use IPC if they encounter unexpected Breaking version.
/// </summary>
private readonly (int Breaking, int Feature) _apiVersion = (4, 0);
private const string _providerGetApiVersionLabel = $"CustomizePlus.General.{nameof(GetApiVersion)}";
private ICallGateProvider<(int, int)>? _providerGetApiVersion;
[EzIPC($"General.{nameof(GetApiVersion)}")]
private (int, int) GetApiVersion()
{
return _apiVersion;
@@ -32,30 +29,11 @@ public partial class CustomizePlusIpc : IDisposable
/// This only indicates that no fatal errors occured in Customize+.
/// This will still be true if, for example, user turns off Customize+ in its settings.
/// </summary>
private const string _providerIsValidLabel = $"CustomizePlus.General.{nameof(IsValid)}";
private ICallGateProvider<bool>? _providerIsValid;
[EzIPC($"General.{nameof(IsValid)}")]
private bool IsValid()
{
return !IPCFailed &&
!_hookingService.RenderHookFailed &&
!_hookingService.MovementHookFailed;
}
private void InitializeGeneralProviders()
{
_logger.Debug("Initializing General Customize+ IPC providers.");
_providerGetApiVersion = _pluginInterface.GetIpcProvider<(int, int)>(_providerGetApiVersionLabel);
_providerGetApiVersion.RegisterFunc(GetApiVersion);
_providerIsValid = _pluginInterface.GetIpcProvider<bool>(_providerIsValidLabel);
_providerIsValid.RegisterFunc(IsValid);
}
private void DisposeGeneralProviders()
{
_logger.Debug("Disposing General Customize+ IPC providers.");
_providerGetApiVersion?.UnregisterFunc();
}
}

View File

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace CustomizePlus.Api;
public partial class CustomizePlusIpc : IDisposable
public partial class CustomizePlusIpc
{
}

View File

@@ -1,11 +1,12 @@
using CustomizePlus.Core.Services;
using Dalamud.Plugin;
using ECommons.EzIpcManager;
using OtterGui.Log;
using System;
namespace CustomizePlus.Api;
public partial class CustomizePlusIpc : IDisposable
public partial class CustomizePlusIpc
{
private readonly DalamudPluginInterface _pluginInterface;
private readonly Logger _logger;
@@ -25,32 +26,6 @@ public partial class CustomizePlusIpc : IDisposable
_logger = logger;
_hookingService = hookingService;
InitializeProviders();
}
private void InitializeProviders()
{
try
{
InitializeGeneralProviders();
}
catch(Exception ex)
{
_logger.Fatal($"Fatal error while initializing Customize+ IPC: {ex}");
IPCFailed = true;
DisposeProviders();
}
}
private void DisposeProviders()
{
DisposeGeneralProviders();
}
public void Dispose()
{
DisposeProviders();
EzIPC.Init(this, "CustomizePlus");
}
}