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

View file

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

View file

@ -3,8 +3,8 @@
namespace LibHac.Common namespace LibHac.Common
{ {
[AttributeUsage(AttributeTargets.Struct)] [AttributeUsage(AttributeTargets.Struct)]
public sealed class NonCopyableAttribute : System.Attribute { } public sealed class NonCopyableAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Struct)] [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()); serviceObject.SetByMove(ref derivedObject.Ref());
return Result.Success; return Result.Success;
} }
public void Dispose() { }
} }
private class FileSystemProxyForLoaderService : IServiceObject private class FileSystemProxyForLoaderService : IServiceObject
@ -221,6 +223,8 @@ namespace LibHac.FsSrv
serviceObject.SetByMove(ref derivedObject.Ref()); serviceObject.SetByMove(ref derivedObject.Ref());
return Result.Success; return Result.Success;
} }
public void Dispose() { }
} }
private class ProgramRegistryService : IServiceObject private class ProgramRegistryService : IServiceObject
@ -238,6 +242,8 @@ namespace LibHac.FsSrv
serviceObject.SetByMove(ref derivedObject.Ref()); serviceObject.SetByMove(ref derivedObject.Ref());
return Result.Success; return Result.Success;
} }
public void Dispose() { }
} }
private class DummyStackUsageReporter : IStackUsageReporter 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 // This interface is being used as a stop-gap solution so we can
// have at least some sort of service system for now // have at least some sort of service system for now
public interface IServiceObject public interface IServiceObject : IDisposable
{ {
Result GetServiceObject(ref SharedRef<IDisposable> serviceObject); Result GetServiceObject(ref SharedRef<IDisposable> serviceObject);
} }