aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.HLE/HOS/Kernel/Ipc/KSession.cs
blob: 13cf4b51bba215319da6e0d5dce2bdef6cdc0f92 (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
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;

namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
    class KSession : KAutoObject
    {
        public KServerSession ServerSession { get; }
        public KClientSession ClientSession { get; }

        private bool _hasBeenInitialized;

        public KSession(KernelContext context, KClientPort parentPort = null) : base(context)
        {
            IncrementReferenceCount();

            ServerSession = new KServerSession(context, this);
            ClientSession = new KClientSession(context, this, parentPort);

            _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;
            }
        }

        protected override void Destroy()
        {
            if (_hasBeenInitialized)
            {
                ClientSession.DisconnectFromPort();

                KProcess creatorProcess = ClientSession.CreatorProcess;

                creatorProcess.ResourceLimit?.Release(LimitableResource.Session, 1);
                creatorProcess.DecrementReferenceCount();
            }
        }
    }
}