KSession.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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(Horizon system) : base(system)
  12. {
  13. ServerSession = new KServerSession(system, this);
  14. ClientSession = new KClientSession(system, this);
  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. KProcess creatorProcess = ClientSession.CreatorProcess;
  48. creatorProcess.ResourceLimit?.Release(LimitableResource.Session, 1);
  49. creatorProcess.DecrementReferenceCount();
  50. }
  51. }
  52. }
  53. }