Ryujinx/Ryujinx.HLE/HOS/SystemState/AppletStateMgr.cs

48 lines
1.2 KiB
C#
Raw Normal View History

using Ryujinx.HLE.HOS.Kernel;
using Ryujinx.HLE.HOS.Services.Am;
using System.Collections.Concurrent;
namespace Ryujinx.HLE.HOS.SystemState
{
class AppletStateMgr
{
2018-12-01 20:01:59 +00:00
private ConcurrentQueue<MessageInfo> _messages;
public FocusState FocusState { get; private set; }
public KEvent MessageEvent { get; private set; }
2018-12-01 20:01:59 +00:00
public AppletStateMgr(Horizon system)
{
2018-12-01 20:01:59 +00:00
_messages = new ConcurrentQueue<MessageInfo>();
2018-12-01 20:01:59 +00:00
MessageEvent = new KEvent(system);
}
2018-12-01 20:01:59 +00:00
public void SetFocus(bool isFocused)
{
2018-12-01 20:01:59 +00:00
FocusState = isFocused
? FocusState.InFocus
: FocusState.OutOfFocus;
EnqueueMessage(MessageInfo.FocusStateChanged);
}
2018-12-01 20:01:59 +00:00
public void EnqueueMessage(MessageInfo message)
{
2018-12-01 20:01:59 +00:00
_messages.Enqueue(message);
MessageEvent.ReadableEvent.Signal();
}
2018-12-01 20:01:59 +00:00
public bool TryDequeueMessage(out MessageInfo message)
{
2018-12-01 20:01:59 +00:00
if (_messages.Count < 2)
{
MessageEvent.ReadableEvent.Clear();
}
2018-12-01 20:01:59 +00:00
return _messages.TryDequeue(out message);
}
}
}