2019-01-18 17:26:39 -05:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
2018-03-19 14:58:46 -04:00
|
|
|
using System;
|
|
|
|
|
2018-12-18 00:33:36 -05:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Ipc
|
2018-03-19 14:58:46 -04:00
|
|
|
{
|
2019-01-18 17:26:39 -05:00
|
|
|
class KSession : KAutoObject, IDisposable
|
2018-03-19 14:58:46 -04:00
|
|
|
{
|
2019-01-18 17:26:39 -05:00
|
|
|
public KServerSession ServerSession { get; }
|
|
|
|
public KClientSession ClientSession { get; }
|
2018-03-19 14:58:46 -04:00
|
|
|
|
2019-01-18 17:26:39 -05:00
|
|
|
private bool _hasBeenInitialized;
|
2018-04-06 01:38:59 -04:00
|
|
|
|
2019-01-18 17:26:39 -05:00
|
|
|
public KSession(Horizon system) : base(system)
|
2018-03-19 14:58:46 -04:00
|
|
|
{
|
2019-01-18 17:26:39 -05:00
|
|
|
ServerSession = new KServerSession(system, this);
|
|
|
|
ClientSession = new KClientSession(system, this);
|
|
|
|
|
|
|
|
_hasBeenInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DisconnectClient()
|
|
|
|
{
|
|
|
|
if (ClientSession.State == ChannelState.Open)
|
|
|
|
{
|
|
|
|
ClientSession.State = ChannelState.ClientDisconnected;
|
|
|
|
|
|
|
|
ServerSession.CancelAllRequestsClientDisconnected();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DisconnectServer()
|
|
|
|
{
|
|
|
|
if (ClientSession.State == ChannelState.Open)
|
|
|
|
{
|
|
|
|
ClientSession.State = ChannelState.ServerDisconnected;
|
|
|
|
}
|
2018-03-19 14:58:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
protected virtual void Dispose(bool disposing)
|
2018-03-19 14:58:46 -04:00
|
|
|
{
|
2019-01-18 17:26:39 -05:00
|
|
|
if (disposing && ClientSession.Service is IDisposable disposableService)
|
2018-03-19 14:58:46 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
disposableService.Dispose();
|
2018-03-19 14:58:46 -04:00
|
|
|
}
|
|
|
|
}
|
2019-01-18 17:26:39 -05:00
|
|
|
|
|
|
|
protected override void Destroy()
|
|
|
|
{
|
|
|
|
if (_hasBeenInitialized)
|
|
|
|
{
|
|
|
|
KProcess creatorProcess = ClientSession.CreatorProcess;
|
|
|
|
|
|
|
|
creatorProcess.ResourceLimit?.Release(LimitableResource.Session, 1);
|
|
|
|
|
|
|
|
creatorProcess.DecrementReferenceCount();
|
|
|
|
}
|
|
|
|
}
|
2018-03-19 14:58:46 -04:00
|
|
|
}
|
|
|
|
}
|