aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.HLE/HOS/Kernel/Ipc/KPort.cs
blob: 84ebcbc3ebe4aac16b0854f0531bc5ce903cac60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.Horizon.Common;

namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
    class KPort : KAutoObject
    {
        public KServerPort ServerPort { get; }
        public KClientPort ClientPort { get; }

#pragma warning disable IDE0052 // Remove unread private member
        private readonly string _name;
#pragma warning restore IDE0052

        private readonly ChannelState _state;

        public bool IsLight { get; private set; }

        public KPort(KernelContext context, int maxSessions, bool isLight, string name) : base(context)
        {
            ServerPort = new KServerPort(context, this);
            ClientPort = new KClientPort(context, this, maxSessions);

            IsLight = isLight;
            _name = name;

            _state = ChannelState.Open;
        }

        public Result EnqueueIncomingSession(KServerSession session)
        {
            Result result;

            KernelContext.CriticalSection.Enter();

            if (_state == ChannelState.Open)
            {
                ServerPort.EnqueueIncomingSession(session);

                result = Result.Success;
            }
            else
            {
                result = KernelResult.PortClosed;
            }

            KernelContext.CriticalSection.Leave();

            return result;
        }

        public Result EnqueueIncomingLightSession(KLightServerSession session)
        {
            Result result;

            KernelContext.CriticalSection.Enter();

            if (_state == ChannelState.Open)
            {
                ServerPort.EnqueueIncomingLightSession(session);

                result = Result.Success;
            }
            else
            {
                result = KernelResult.PortClosed;
            }

            KernelContext.CriticalSection.Leave();

            return result;
        }
    }
}