2018-10-21 02:01:22 -04:00
|
|
|
|
using Ryujinx.Common.Logging;
|
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2018-12-18 00:33:36 -05:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2018-10-21 02:01:22 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Psm
|
|
|
|
|
{
|
|
|
|
|
class IPsmSession : IpcService
|
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
private Dictionary<int, ServiceProcessRequest> _commands;
|
2018-10-21 02:01:22 -04:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
|
2018-10-21 02:01:22 -04:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
private KEvent _stateChangeEvent;
|
|
|
|
|
private int _stateChangeEventHandle;
|
2018-10-21 02:01:22 -04:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public IPsmSession(Horizon system)
|
2018-10-21 02:01:22 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
_commands = new Dictionary<int, ServiceProcessRequest>
|
2018-10-21 02:01:22 -04:00
|
|
|
|
{
|
|
|
|
|
{ 0, BindStateChangeEvent },
|
|
|
|
|
{ 1, UnbindStateChangeEvent },
|
|
|
|
|
{ 2, SetChargerTypeChangeEventEnabled },
|
|
|
|
|
{ 3, SetPowerSupplyChangeEventEnabled },
|
|
|
|
|
{ 4, SetBatteryVoltageStateChangeEventEnabled }
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
_stateChangeEvent = new KEvent(system);
|
|
|
|
|
_stateChangeEventHandle = -1;
|
2018-10-21 02:01:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BindStateChangeEvent() -> KObject
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long BindStateChangeEvent(ServiceCtx context)
|
2018-10-21 02:01:22 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (_stateChangeEventHandle == -1)
|
2018-10-21 02:01:22 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
KernelResult resultCode = context.Process.HandleTable.GenerateHandle(_stateChangeEvent, out int stateChangeEventHandle);
|
2018-10-21 02:01:22 -04:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (resultCode != KernelResult.Success)
|
2018-10-21 02:01:22 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
return (long)resultCode;
|
2018-10-21 02:01:22 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_stateChangeEventHandle);
|
2018-10-21 02:01:22 -04:00
|
|
|
|
|
|
|
|
|
Logger.PrintStub(LogClass.ServicePsm, "Stubbed.");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UnbindStateChangeEvent()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long UnbindStateChangeEvent(ServiceCtx context)
|
2018-10-21 02:01:22 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (_stateChangeEventHandle != -1)
|
2018-10-21 02:01:22 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
context.Process.HandleTable.CloseHandle(_stateChangeEventHandle);
|
|
|
|
|
_stateChangeEventHandle = -1;
|
2018-10-21 02:01:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.PrintStub(LogClass.ServicePsm, "Stubbed.");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetChargerTypeChangeEventEnabled(u8)
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long SetChargerTypeChangeEventEnabled(ServiceCtx context)
|
2018-10-21 02:01:22 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
bool chargerTypeChangeEventEnabled = context.RequestData.ReadBoolean();
|
2018-10-21 02:01:22 -04:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
Logger.PrintStub(LogClass.ServicePsm, $"Stubbed. ChargerTypeChangeEventEnabled: {chargerTypeChangeEventEnabled}");
|
2018-10-21 02:01:22 -04:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetPowerSupplyChangeEventEnabled(u8)
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long SetPowerSupplyChangeEventEnabled(ServiceCtx context)
|
2018-10-21 02:01:22 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
bool powerSupplyChangeEventEnabled = context.RequestData.ReadBoolean();
|
2018-10-21 02:01:22 -04:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
Logger.PrintStub(LogClass.ServicePsm, $"Stubbed. PowerSupplyChangeEventEnabled: {powerSupplyChangeEventEnabled}");
|
2018-10-21 02:01:22 -04:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetBatteryVoltageStateChangeEventEnabled(u8)
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long SetBatteryVoltageStateChangeEventEnabled(ServiceCtx context)
|
2018-10-21 02:01:22 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
bool batteryVoltageStateChangeEventEnabled = context.RequestData.ReadBoolean();
|
2018-10-21 02:01:22 -04:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
Logger.PrintStub(LogClass.ServicePsm, $"Stubbed. BatteryVoltageStateChangeEventEnabled: {batteryVoltageStateChangeEventEnabled}");
|
2018-10-21 02:01:22 -04:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|