mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2025-09-19 12:47:55 -05:00
Migrate friends service to new IPC (#6174)
* Migrate friends service to new IPC * Add a note that the pointer buffer size and domain counts are wrong * Wrong length * Format whitespace * PR feedback * Fill in structs from PR feedback * Missed that one * Somehow forgot to save that one * Fill in enums from PR review * Language enum, NotificationTime * Format whitespace * Fix the warning
This commit is contained in:
49
src/Ryujinx.Horizon/Friends/FriendsIpcServer.cs
Normal file
49
src/Ryujinx.Horizon/Friends/FriendsIpcServer.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Ryujinx.Horizon.Sdk.Sf.Hipc;
|
||||
using Ryujinx.Horizon.Sdk.Sm;
|
||||
|
||||
namespace Ryujinx.Horizon.Friends
|
||||
{
|
||||
class FriendsIpcServer
|
||||
{
|
||||
private const int MaxSessionsCount = 8;
|
||||
private const int TotalMaxSessionsCount = MaxSessionsCount * 5;
|
||||
|
||||
private const int PointerBufferSize = 0xA00;
|
||||
private const int MaxDomains = 64;
|
||||
private const int MaxDomainObjects = 16;
|
||||
private const int MaxPortsCount = 5;
|
||||
|
||||
private static readonly ManagerOptions _managerOptions = new(PointerBufferSize, MaxDomains, MaxDomainObjects, false);
|
||||
|
||||
private SmApi _sm;
|
||||
private FriendsServerManager _serverManager;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
HeapAllocator allocator = new();
|
||||
|
||||
_sm = new SmApi();
|
||||
_sm.Initialize().AbortOnFailure();
|
||||
|
||||
_serverManager = new FriendsServerManager(allocator, _sm, MaxPortsCount, _managerOptions, TotalMaxSessionsCount);
|
||||
|
||||
#pragma warning disable IDE0055 // Disable formatting
|
||||
_serverManager.RegisterServer((int)FriendsPortIndex.Admin, ServiceName.Encode("friend:a"), MaxSessionsCount);
|
||||
_serverManager.RegisterServer((int)FriendsPortIndex.User, ServiceName.Encode("friend:u"), MaxSessionsCount);
|
||||
_serverManager.RegisterServer((int)FriendsPortIndex.Viewer, ServiceName.Encode("friend:v"), MaxSessionsCount);
|
||||
_serverManager.RegisterServer((int)FriendsPortIndex.Manager, ServiceName.Encode("friend:m"), MaxSessionsCount);
|
||||
_serverManager.RegisterServer((int)FriendsPortIndex.System, ServiceName.Encode("friend:s"), MaxSessionsCount);
|
||||
#pragma warning restore IDE0055
|
||||
}
|
||||
|
||||
public void ServiceRequests()
|
||||
{
|
||||
_serverManager.ServiceRequests();
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
_serverManager.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
17
src/Ryujinx.Horizon/Friends/FriendsMain.cs
Normal file
17
src/Ryujinx.Horizon/Friends/FriendsMain.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace Ryujinx.Horizon.Friends
|
||||
{
|
||||
class FriendsMain : IService
|
||||
{
|
||||
public static void Main(ServiceTable serviceTable)
|
||||
{
|
||||
FriendsIpcServer ipcServer = new();
|
||||
|
||||
ipcServer.Initialize();
|
||||
|
||||
serviceTable.SignalServiceReady();
|
||||
|
||||
ipcServer.ServiceRequests();
|
||||
ipcServer.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
11
src/Ryujinx.Horizon/Friends/FriendsPortIndex.cs
Normal file
11
src/Ryujinx.Horizon/Friends/FriendsPortIndex.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Ryujinx.Horizon.Friends
|
||||
{
|
||||
enum FriendsPortIndex
|
||||
{
|
||||
Admin,
|
||||
User,
|
||||
Viewer,
|
||||
Manager,
|
||||
System,
|
||||
}
|
||||
}
|
36
src/Ryujinx.Horizon/Friends/FriendsServerManager.cs
Normal file
36
src/Ryujinx.Horizon/Friends/FriendsServerManager.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Ryujinx.Horizon.Common;
|
||||
using Ryujinx.Horizon.Sdk.Account;
|
||||
using Ryujinx.Horizon.Sdk.Friends.Detail.Ipc;
|
||||
using Ryujinx.Horizon.Sdk.Sf.Hipc;
|
||||
using Ryujinx.Horizon.Sdk.Sm;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.Horizon.Friends
|
||||
{
|
||||
class FriendsServerManager : ServerManager
|
||||
{
|
||||
private readonly IEmulatorAccountManager _accountManager;
|
||||
private readonly NotificationEventHandler _notificationEventHandler;
|
||||
|
||||
public FriendsServerManager(HeapAllocator allocator, SmApi sm, int maxPorts, ManagerOptions options, int maxSessions) : base(allocator, sm, maxPorts, options, maxSessions)
|
||||
{
|
||||
_accountManager = HorizonStatic.Options.AccountManager;
|
||||
_notificationEventHandler = new();
|
||||
}
|
||||
|
||||
protected override Result OnNeedsToAccept(int portIndex, Server server)
|
||||
{
|
||||
return (FriendsPortIndex)portIndex switch
|
||||
{
|
||||
#pragma warning disable IDE0055 // Disable formatting
|
||||
FriendsPortIndex.Admin => AcceptImpl(server, new ServiceCreator(_accountManager, _notificationEventHandler, FriendsServicePermissionLevel.Admin)),
|
||||
FriendsPortIndex.User => AcceptImpl(server, new ServiceCreator(_accountManager, _notificationEventHandler, FriendsServicePermissionLevel.User)),
|
||||
FriendsPortIndex.Viewer => AcceptImpl(server, new ServiceCreator(_accountManager, _notificationEventHandler, FriendsServicePermissionLevel.Viewer)),
|
||||
FriendsPortIndex.Manager => AcceptImpl(server, new ServiceCreator(_accountManager, _notificationEventHandler, FriendsServicePermissionLevel.Manager)),
|
||||
FriendsPortIndex.System => AcceptImpl(server, new ServiceCreator(_accountManager, _notificationEventHandler, FriendsServicePermissionLevel.System)),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(portIndex)),
|
||||
#pragma warning restore IDE0055
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user