aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Horizon/Sm/SmMain.cs
blob: 024d569f6e614e2c6204962cb3fd11061ca2775d (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
using Ryujinx.Horizon.Sdk.Sf.Hipc;
using Ryujinx.Horizon.Sdk.Sm;
using Ryujinx.Horizon.Sm.Impl;
using Ryujinx.Horizon.Sm.Types;

namespace Ryujinx.Horizon.Sm
{
    public class SmMain
    {
        private const int SmMaxSessionsCount = 64;
        private const int SmmMaxSessionsCount = 1;
        private const int SmTotalMaxSessionsCount = SmMaxSessionsCount + SmmMaxSessionsCount;

        private const int MaxPortsCount = 2;

        private SmServerManager _serverManager;

        private readonly ServiceManager _serviceManager = new();

        public void Main()
        {
            HorizonStatic.Syscall.ManageNamedPort(out int smHandle, "sm:", SmMaxSessionsCount).AbortOnFailure();

            _serverManager = new SmServerManager(_serviceManager, null, null, MaxPortsCount, ManagerOptions.Default, SmTotalMaxSessionsCount);

            _serverManager.RegisterServer((int)SmPortIndex.User, smHandle);
            _serviceManager.RegisterServiceForSelf(out int smmHandle, ServiceName.Encode("sm:m"), SmmMaxSessionsCount).AbortOnFailure();
            _serverManager.RegisterServer((int)SmPortIndex.Manager, smmHandle);
            _serverManager.ServiceRequests();
        }
    }
}