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