2018-10-17 17:15:50 +00:00
|
|
|
|
using Ryujinx.Common.Logging;
|
2019-11-14 05:18:44 +00:00
|
|
|
|
using Ryujinx.HLE.HOS.Applets;
|
2018-10-17 17:15:50 +00:00
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2018-12-18 05:33:36 +00:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2018-09-23 18:11:46 +00:00
|
|
|
|
using System;
|
2018-06-02 22:46:09 +00:00
|
|
|
|
|
2019-09-19 00:45:11 +00:00
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.LibraryAppletCreator
|
2018-06-02 22:46:09 +00:00
|
|
|
|
{
|
|
|
|
|
class ILibraryAppletAccessor : IpcService
|
|
|
|
|
{
|
2019-11-14 05:18:44 +00:00
|
|
|
|
private IApplet _applet;
|
|
|
|
|
|
2019-11-18 11:16:26 +00:00
|
|
|
|
private AppletSession _normalSession;
|
|
|
|
|
private AppletSession _interactiveSession;
|
2019-11-14 05:18:44 +00:00
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
private KEvent _stateChangedEvent;
|
2019-11-18 11:16:26 +00:00
|
|
|
|
private KEvent _normalOutDataEvent;
|
|
|
|
|
private KEvent _interactiveOutDataEvent;
|
2018-06-02 22:46:09 +00:00
|
|
|
|
|
2019-11-14 05:18:44 +00:00
|
|
|
|
public ILibraryAppletAccessor(AppletId appletId, Horizon system)
|
2018-06-02 22:46:09 +00:00
|
|
|
|
{
|
2020-05-04 03:41:29 +00:00
|
|
|
|
_stateChangedEvent = new KEvent(system.KernelContext);
|
|
|
|
|
_normalOutDataEvent = new KEvent(system.KernelContext);
|
|
|
|
|
_interactiveOutDataEvent = new KEvent(system.KernelContext);
|
2019-11-14 05:18:44 +00:00
|
|
|
|
|
2019-11-18 11:16:26 +00:00
|
|
|
|
_applet = AppletManager.Create(appletId, system);
|
|
|
|
|
|
|
|
|
|
_normalSession = new AppletSession();
|
|
|
|
|
_interactiveSession = new AppletSession();
|
|
|
|
|
|
|
|
|
|
_applet.AppletStateChanged += OnAppletStateChanged;
|
|
|
|
|
_normalSession.DataAvailable += OnNormalOutData;
|
|
|
|
|
_interactiveSession.DataAvailable += OnInteractiveOutData;
|
2019-11-14 05:18:44 +00:00
|
|
|
|
|
|
|
|
|
Logger.PrintInfo(LogClass.ServiceAm, $"Applet '{appletId}' created.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAppletStateChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-11-18 11:16:26 +00:00
|
|
|
|
_stateChangedEvent.WritableEvent.Signal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnNormalOutData(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_normalOutDataEvent.WritableEvent.Signal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnInteractiveOutData(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_interactiveOutDataEvent.WritableEvent.Signal();
|
2018-06-02 22:46:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
|
[Command(0)]
|
|
|
|
|
// GetAppletStateChangedEvent() -> handle<copy>
|
2019-07-14 19:04:38 +00:00
|
|
|
|
public ResultCode GetAppletStateChangedEvent(ServiceCtx context)
|
2018-06-02 22:46:09 +00:00
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(_stateChangedEvent.ReadableEvent, out int handle) != KernelResult.Success)
|
2018-09-23 18:11:46 +00:00
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
2018-06-02 22:46:09 +00:00
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
2018-06-02 22:46:09 +00:00
|
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
|
return ResultCode.Success;
|
2018-06-02 22:46:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
|
[Command(10)]
|
|
|
|
|
// Start()
|
2019-07-14 19:04:38 +00:00
|
|
|
|
public ResultCode Start(ServiceCtx context)
|
2018-06-02 22:46:09 +00:00
|
|
|
|
{
|
2019-11-18 11:16:26 +00:00
|
|
|
|
return (ResultCode)_applet.Start(_normalSession.GetConsumer(),
|
|
|
|
|
_interactiveSession.GetConsumer());
|
2018-06-02 22:46:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
|
[Command(30)]
|
|
|
|
|
// GetResult()
|
2019-07-14 19:04:38 +00:00
|
|
|
|
public ResultCode GetResult(ServiceCtx context)
|
2018-06-02 22:46:09 +00:00
|
|
|
|
{
|
2019-11-14 05:18:44 +00:00
|
|
|
|
return (ResultCode)_applet.GetResult();
|
2018-06-02 22:46:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
|
[Command(100)]
|
|
|
|
|
// PushInData(object<nn::am::service::IStorage>)
|
2019-07-14 19:04:38 +00:00
|
|
|
|
public ResultCode PushInData(ServiceCtx context)
|
2018-06-02 22:46:09 +00:00
|
|
|
|
{
|
2019-11-14 05:18:44 +00:00
|
|
|
|
IStorage data = GetObject<IStorage>(context, 0);
|
|
|
|
|
|
2019-11-18 11:16:26 +00:00
|
|
|
|
_normalSession.Push(data.Data);
|
2018-06-02 22:46:09 +00:00
|
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
|
return ResultCode.Success;
|
2018-06-02 22:46:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
|
[Command(101)]
|
|
|
|
|
// PopOutData() -> object<nn::am::service::IStorage>
|
2019-07-14 19:04:38 +00:00
|
|
|
|
public ResultCode PopOutData(ServiceCtx context)
|
2018-06-02 22:46:09 +00:00
|
|
|
|
{
|
2019-11-18 11:16:26 +00:00
|
|
|
|
if(_normalSession.TryPop(out byte[] data))
|
|
|
|
|
{
|
|
|
|
|
MakeObject(context, new IStorage(data));
|
|
|
|
|
|
|
|
|
|
_normalOutDataEvent.WritableEvent.Clear();
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultCode.NotAvailable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command(103)]
|
|
|
|
|
// PushInteractiveInData(object<nn::am::service::IStorage>)
|
|
|
|
|
public ResultCode PushInteractiveInData(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
IStorage data = GetObject<IStorage>(context, 0);
|
|
|
|
|
|
|
|
|
|
_interactiveSession.Push(data.Data);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command(104)]
|
|
|
|
|
// PopInteractiveOutData() -> object<nn::am::service::IStorage>
|
|
|
|
|
public ResultCode PopInteractiveOutData(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
if(_interactiveSession.TryPop(out byte[] data))
|
|
|
|
|
{
|
|
|
|
|
MakeObject(context, new IStorage(data));
|
|
|
|
|
|
|
|
|
|
_interactiveOutDataEvent.WritableEvent.Clear();
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultCode.NotAvailable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command(105)]
|
|
|
|
|
// GetPopOutDataEvent() -> handle<copy>
|
|
|
|
|
public ResultCode GetPopOutDataEvent(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(_normalOutDataEvent.ReadableEvent, out int handle) != KernelResult.Success)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command(106)]
|
|
|
|
|
// GetPopInteractiveOutDataEvent() -> handle<copy>
|
|
|
|
|
public ResultCode GetPopInteractiveOutDataEvent(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
if (context.Process.HandleTable.GenerateHandle(_interactiveOutDataEvent.ReadableEvent, out int handle) != KernelResult.Success)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
2018-06-02 22:46:09 +00:00
|
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
|
return ResultCode.Success;
|
2018-06-02 22:46:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-14 05:18:44 +00:00
|
|
|
|
}
|