2018-12-17 21:33:36 -08:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
2023-01-04 14:15:45 -08:00
|
|
|
using Ryujinx.Horizon.Common;
|
2018-12-17 21:33:36 -08:00
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Ipc
|
2018-11-28 14:18:09 -08:00
|
|
|
{
|
|
|
|
class KPort : KAutoObject
|
|
|
|
{
|
2019-01-18 14:26:39 -08:00
|
|
|
public KServerPort ServerPort { get; }
|
|
|
|
public KClientPort ClientPort { get; }
|
2018-11-28 14:18:09 -08:00
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
private string _name;
|
2018-11-28 14:18:09 -08:00
|
|
|
|
2019-01-18 14:26:39 -08:00
|
|
|
private ChannelState _state;
|
|
|
|
|
|
|
|
public bool IsLight { get; private set; }
|
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
public KPort(KernelContext context, int maxSessions, bool isLight, string name) : base(context)
|
2018-11-28 14:18:09 -08:00
|
|
|
{
|
2020-05-03 20:41:29 -07:00
|
|
|
ServerPort = new KServerPort(context, this);
|
|
|
|
ClientPort = new KClientPort(context, this, maxSessions);
|
2019-01-18 14:26:39 -08:00
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
IsLight = isLight;
|
|
|
|
_name = name;
|
2019-01-18 14:26:39 -08:00
|
|
|
|
|
|
|
_state = ChannelState.Open;
|
2018-11-28 14:18:09 -08:00
|
|
|
}
|
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
public Result EnqueueIncomingSession(KServerSession session)
|
2018-11-28 14:18:09 -08:00
|
|
|
{
|
2023-01-04 14:15:45 -08:00
|
|
|
Result result;
|
2018-11-28 14:18:09 -08:00
|
|
|
|
2020-05-03 20:41:29 -07:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2019-01-18 14:26:39 -08:00
|
|
|
|
|
|
|
if (_state == ChannelState.Open)
|
|
|
|
{
|
|
|
|
ServerPort.EnqueueIncomingSession(session);
|
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
result = Result.Success;
|
2019-01-18 14:26:39 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = KernelResult.PortClosed;
|
|
|
|
}
|
|
|
|
|
2020-05-03 20:41:29 -07:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 14:26:39 -08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
public Result EnqueueIncomingLightSession(KLightServerSession session)
|
2019-01-18 14:26:39 -08:00
|
|
|
{
|
2023-01-04 14:15:45 -08:00
|
|
|
Result result;
|
2019-01-18 14:26:39 -08:00
|
|
|
|
2020-05-03 20:41:29 -07:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2019-01-18 14:26:39 -08:00
|
|
|
|
|
|
|
if (_state == ChannelState.Open)
|
|
|
|
{
|
|
|
|
ServerPort.EnqueueIncomingLightSession(session);
|
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
result = Result.Success;
|
2019-01-18 14:26:39 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = KernelResult.PortClosed;
|
|
|
|
}
|
|
|
|
|
2020-05-03 20:41:29 -07:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 14:26:39 -08:00
|
|
|
|
|
|
|
return result;
|
2018-11-28 14:18:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|