IDeliveryCacheStorageService.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using LibHac;
  2. using LibHac.Bcat;
  3. using LibHac.Common;
  4. using System.Runtime.InteropServices;
  5. namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
  6. {
  7. class IDeliveryCacheStorageService : DisposableIpcService
  8. {
  9. private SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService> _base;
  10. public IDeliveryCacheStorageService(ServiceCtx context, ref SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService> baseService)
  11. {
  12. _base = SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService>.CreateMove(ref baseService);
  13. }
  14. [CommandHipc(0)]
  15. // CreateFileService() -> object<nn::bcat::detail::ipc::IDeliveryCacheFileService>
  16. public ResultCode CreateFileService(ServiceCtx context)
  17. {
  18. using var service = new SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheFileService>();
  19. Result result = _base.Get.CreateFileService(ref service.Ref);
  20. if (result.IsSuccess())
  21. {
  22. MakeObject(context, new IDeliveryCacheFileService(ref service.Ref));
  23. }
  24. return (ResultCode)result.Value;
  25. }
  26. [CommandHipc(1)]
  27. // CreateDirectoryService() -> object<nn::bcat::detail::ipc::IDeliveryCacheDirectoryService>
  28. public ResultCode CreateDirectoryService(ServiceCtx context)
  29. {
  30. using var service = new SharedRef<LibHac.Bcat.Impl.Ipc.IDeliveryCacheDirectoryService>();
  31. Result result = _base.Get.CreateDirectoryService(ref service.Ref);
  32. if (result.IsSuccess())
  33. {
  34. MakeObject(context, new IDeliveryCacheDirectoryService(ref service.Ref));
  35. }
  36. return (ResultCode)result.Value;
  37. }
  38. [CommandHipc(10)]
  39. // EnumerateDeliveryCacheDirectory() -> (u32, buffer<nn::bcat::DirectoryName, 6>)
  40. public ResultCode EnumerateDeliveryCacheDirectory(ServiceCtx context)
  41. {
  42. ulong bufferAddress = context.Request.ReceiveBuff[0].Position;
  43. ulong bufferLen = context.Request.ReceiveBuff[0].Size;
  44. using (var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true))
  45. {
  46. Result result = _base.Get.EnumerateDeliveryCacheDirectory(out int count, MemoryMarshal.Cast<byte, DirectoryName>(region.Memory.Span));
  47. context.ResponseData.Write(count);
  48. return (ResultCode)result.Value;
  49. }
  50. }
  51. protected override void Dispose(bool isDisposing)
  52. {
  53. if (isDisposing)
  54. {
  55. _base.Destroy();
  56. }
  57. }
  58. }
  59. }