Use SharedRef in the bcat IPC interfaces

This commit is contained in:
Alex Barney 2021-10-31 15:30:34 -07:00
parent f07e515048
commit e14a20b4fa
5 changed files with 16 additions and 13 deletions

View file

@ -1,11 +1,12 @@
using System;
using LibHac.Common;
namespace LibHac.Bcat.Impl.Ipc
{
public interface IDeliveryCacheStorageService : IDisposable
{
Result CreateFileService(out IDeliveryCacheFileService fileService);
Result CreateDirectoryService(out IDeliveryCacheDirectoryService directoryService);
Result CreateFileService(ref SharedRef<IDeliveryCacheFileService> outFileService);
Result CreateDirectoryService(ref SharedRef<IDeliveryCacheDirectoryService> outDirectoryService);
Result EnumerateDeliveryCacheDirectory(out int namesRead, Span<DirectoryName> nameBuffer);
}
}

View file

@ -25,32 +25,28 @@ namespace LibHac.Bcat.Impl.Service
Access = accessControl;
}
public Result CreateFileService(out IDeliveryCacheFileService service)
public Result CreateFileService(ref SharedRef<IDeliveryCacheFileService> service)
{
lock (Locker)
{
UnsafeHelpers.SkipParamInit(out service);
if (FileServiceOpenCount >= MaxOpenCount)
return ResultBcat.ServiceOpenLimitReached.Log();
service = new DeliveryCacheFileService(Server, this, ApplicationId, Access);
service.Reset(new DeliveryCacheFileService(Server, this, ApplicationId, Access));
FileServiceOpenCount++;
return Result.Success;
}
}
public Result CreateDirectoryService(out IDeliveryCacheDirectoryService service)
public Result CreateDirectoryService(ref SharedRef<IDeliveryCacheDirectoryService> service)
{
lock (Locker)
{
UnsafeHelpers.SkipParamInit(out service);
if (DirectoryServiceOpenCount >= MaxOpenCount)
return ResultBcat.ServiceOpenLimitReached.Log();
service = new DeliveryCacheDirectoryService(Server, this, ApplicationId, Access);
service.Reset(new DeliveryCacheDirectoryService(Server, this, ApplicationId, Access));
DirectoryServiceOpenCount++;
return Result.Success;

View file

@ -3,8 +3,8 @@
namespace LibHac.Common
{
[AttributeUsage(AttributeTargets.Struct)]
public sealed class NonCopyableAttribute : System.Attribute { }
public sealed class NonCopyableAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Struct)]
public sealed class NonCopyableDisposableAttribute : System.Attribute { }
public sealed class NonCopyableDisposableAttribute : Attribute { }
}

View file

@ -204,6 +204,8 @@ namespace LibHac.FsSrv
serviceObject.SetByMove(ref derivedObject.Ref());
return Result.Success;
}
public void Dispose() { }
}
private class FileSystemProxyForLoaderService : IServiceObject
@ -221,6 +223,8 @@ namespace LibHac.FsSrv
serviceObject.SetByMove(ref derivedObject.Ref());
return Result.Success;
}
public void Dispose() { }
}
private class ProgramRegistryService : IServiceObject
@ -238,6 +242,8 @@ namespace LibHac.FsSrv
serviceObject.SetByMove(ref derivedObject.Ref());
return Result.Success;
}
public void Dispose() { }
}
private class DummyStackUsageReporter : IStackUsageReporter

View file

@ -5,7 +5,7 @@ namespace LibHac.Sm
{
// This interface is being used as a stop-gap solution so we can
// have at least some sort of service system for now
public interface IServiceObject
public interface IServiceObject : IDisposable
{
Result GetServiceObject(ref SharedRef<IDisposable> serviceObject);
}