2018-12-18 06:33:36 +01:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2019-09-19 02:45:11 +02:00
|
|
|
using Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy;
|
2018-03-19 19:58:46 +01:00
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.SystemState
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-09-19 01:36:43 +02:00
|
|
|
class AppletStateMgr
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
private ConcurrentQueue<MessageInfo> _messages;
|
2018-03-19 19:58:46 +01:00
|
|
|
|
|
|
|
public FocusState FocusState { get; private set; }
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public KEvent MessageEvent { get; private set; }
|
2018-03-19 19:58:46 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public AppletStateMgr(Horizon system)
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_messages = new ConcurrentQueue<MessageInfo>();
|
2018-03-19 19:58:46 +01:00
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
MessageEvent = new KEvent(system.KernelContext);
|
2018-03-19 19:58:46 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public void SetFocus(bool isFocused)
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
FocusState = isFocused
|
2018-03-19 19:58:46 +01:00
|
|
|
? FocusState.InFocus
|
|
|
|
: FocusState.OutOfFocus;
|
|
|
|
|
|
|
|
EnqueueMessage(MessageInfo.FocusStateChanged);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public void EnqueueMessage(MessageInfo message)
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_messages.Enqueue(message);
|
2018-03-19 19:58:46 +01:00
|
|
|
|
2018-09-23 20:11:46 +02:00
|
|
|
MessageEvent.ReadableEvent.Signal();
|
2018-03-19 19:58:46 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public bool TryDequeueMessage(out MessageInfo message)
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (_messages.Count < 2)
|
2018-03-19 19:58:46 +01:00
|
|
|
{
|
2018-09-23 20:11:46 +02:00
|
|
|
MessageEvent.ReadableEvent.Clear();
|
2018-03-19 19:58:46 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return _messages.TryDequeue(out message);
|
2018-03-19 19:58:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|