aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Horizon/Arp/Ipc/Writer.cs
blob: 29c98b779850318ca97e75f9e7ea6f7959439a45 (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
75
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Arp;
using Ryujinx.Horizon.Sdk.Arp.Detail;
using Ryujinx.Horizon.Sdk.OsTypes;
using Ryujinx.Horizon.Sdk.Sf;

namespace Ryujinx.Horizon.Arp.Ipc
{
    partial class Writer : IWriter, IServiceObject
    {
        private readonly ApplicationInstanceManager _applicationInstanceManager;

        public Writer(ApplicationInstanceManager applicationInstanceManager)
        {
            _applicationInstanceManager = applicationInstanceManager;
        }

        [CmifCommand(0)]
        public Result AcquireRegistrar(out IRegistrar registrar)
        {
            if (_applicationInstanceManager.Entries[0] != null)
            {
                if (_applicationInstanceManager.Entries[1] != null)
                {
                    registrar = null;

                    return ArpResult.NoFreeInstance;
                }
                else
                {
                    _applicationInstanceManager.Entries[1] = new ApplicationInstance();

                    registrar = new Registrar(_applicationInstanceManager.Entries[1]);
                }
            }
            else
            {
                _applicationInstanceManager.Entries[0] = new ApplicationInstance();

                registrar = new Registrar(_applicationInstanceManager.Entries[0]);
            }

            return Result.Success;
        }

        [CmifCommand(1)]
        public Result UnregisterApplicationInstance(ulong applicationInstanceId)
        {
            if (_applicationInstanceManager.Entries[applicationInstanceId] != null)
            {
                _applicationInstanceManager.Entries[applicationInstanceId] = null;
            }

            Os.SignalSystemEvent(ref _applicationInstanceManager.SystemEvent);

            return Result.Success;
        }

        [CmifCommand(2)]
        public Result AcquireApplicationProcessPropertyUpdater(out IUpdater updater, ulong applicationInstanceId)
        {
            updater = new Updater(_applicationInstanceManager, applicationInstanceId, false);

            return Result.Success;
        }

        [CmifCommand(3)]
        public Result AcquireApplicationCertificateUpdater(out IUpdater updater, ulong applicationInstanceId)
        {
            updater = new Updater(_applicationInstanceManager, applicationInstanceId, true);

            return Result.Success;
        }
    }
}