KSession.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Ryujinx.HLE.HOS.Kernel.Common;
  2. using Ryujinx.HLE.HOS.Kernel.Process;
  3. using System;
  4. namespace Ryujinx.HLE.HOS.Kernel.Ipc
  5. {
  6. class KSession : KAutoObject, IDisposable
  7. {
  8. public KServerSession ServerSession { get; }
  9. public KClientSession ClientSession { get; }
  10. private bool _hasBeenInitialized;
  11. public KSession(KernelContext context, KClientPort parentPort = null) : base(context)
  12. {
  13. ServerSession = new KServerSession(context, this);
  14. ClientSession = new KClientSession(context, this, parentPort);
  15. _hasBeenInitialized = true;
  16. }
  17. public void DisconnectClient()
  18. {
  19. if (ClientSession.State == ChannelState.Open)
  20. {
  21. ClientSession.State = ChannelState.ClientDisconnected;
  22. ServerSession.CancelAllRequestsClientDisconnected();
  23. }
  24. }
  25. public void DisconnectServer()
  26. {
  27. if (ClientSession.State == ChannelState.Open)
  28. {
  29. ClientSession.State = ChannelState.ServerDisconnected;
  30. }
  31. }
  32. public void Dispose()
  33. {
  34. Dispose(true);
  35. }
  36. protected virtual void Dispose(bool disposing)
  37. {
  38. if (disposing && ClientSession.Service is IDisposable disposableService)
  39. {
  40. disposableService.Dispose();
  41. }
  42. }
  43. protected override void Destroy()
  44. {
  45. if (_hasBeenInitialized)
  46. {
  47. ClientSession.DisconnectFromPort();
  48. KProcess creatorProcess = ClientSession.CreatorProcess;
  49. creatorProcess.ResourceLimit?.Release(LimitableResource.Session, 1);
  50. creatorProcess.DecrementReferenceCount();
  51. }
  52. }
  53. }
  54. }