0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2024-12-23 12:45:48 +00:00
Ryujinx/Ryujinx.Horizon/Sdk/Sm/SmApi.cs
gdkchan 08831eecf7
IPC refactor part 3+4: New server HIPC message processor (#4188)
* IPC refactor part 3 + 4: New server HIPC message processor with source generator based serialization

* Make types match on calls to AlignUp/AlignDown

* Formatting

* Address some PR feedback

* Move BitfieldExtensions to Ryujinx.Common.Utilities and consolidate implementations

* Rename Reader/Writer to SpanReader/SpanWriter and move to Ryujinx.Common.Memory

* Implement EventType

* Address more PR feedback

* Log request processing errors since they are not normal

* Rename waitable to multiwait and add missing lock

* PR feedback

* Ac_K PR feedback
2023-01-04 23:15:45 +01:00

107 lines
2.8 KiB
C#

using Ryujinx.Common.Memory;
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Sf.Cmif;
using System;
namespace Ryujinx.Horizon.Sdk.Sm
{
class SmApi
{
private int _portHandle;
public Result Initialize()
{
Result result = HorizonStatic.Syscall.ConnectToNamedPort(out int portHandle, "sm:");
while (result == KernelResult.NotFound)
{
HorizonStatic.Syscall.SleepThread(50000000L);
result = HorizonStatic.Syscall.ConnectToNamedPort(out portHandle, "sm:");
}
if (result.IsFailure)
{
return result;
}
_portHandle = portHandle;
return RegisterClient();
}
private Result RegisterClient()
{
Span<byte> data = stackalloc byte[8];
SpanWriter writer = new SpanWriter(data);
writer.Write(0UL);
return ServiceUtil.SendRequest(out _, _portHandle, 0, sendPid: true, data);
}
public Result GetServiceHandle(out int handle, ServiceName name)
{
Span<byte> data = stackalloc byte[8];
SpanWriter writer = new SpanWriter(data);
writer.Write(name);
Result result = ServiceUtil.SendRequest(out CmifResponse response, _portHandle, 1, sendPid: false, data);
if (result.IsFailure)
{
handle = 0;
return result;
}
handle = response.MoveHandles[0];
return Result.Success;
}
public Result RegisterService(out int handle, ServiceName name, int maxSessions, bool isLight)
{
Span<byte> data = stackalloc byte[16];
SpanWriter writer = new SpanWriter(data);
writer.Write(name);
writer.Write(isLight ? 1 : 0);
writer.Write(maxSessions);
Result result = ServiceUtil.SendRequest(out CmifResponse response, _portHandle, 2, sendPid: false, data);
if (result.IsFailure)
{
handle = 0;
return result;
}
handle = response.MoveHandles[0];
return Result.Success;
}
public Result UnregisterService(ServiceName name)
{
Span<byte> data = stackalloc byte[8];
SpanWriter writer = new SpanWriter(data);
writer.Write(name);
return ServiceUtil.SendRequest(out _, _portHandle, 3, sendPid: false, data);
}
public Result DetachClient()
{
Span<byte> data = stackalloc byte[8];
SpanWriter writer = new SpanWriter(data);
writer.Write(0UL);
return ServiceUtil.SendRequest(out _, _portHandle, 4, sendPid: true, data);
}
}
}