2018-06-10 20:46:42 -04:00
|
|
|
using Ryujinx.HLE.OsHle.Handles;
|
|
|
|
using Ryujinx.HLE.OsHle.Services.Am;
|
2018-03-19 14:58:46 -04:00
|
|
|
using System;
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
2018-08-14 18:02:42 -04:00
|
|
|
namespace Ryujinx.HLE.OsHle.SystemState
|
2018-03-19 14:58:46 -04:00
|
|
|
{
|
|
|
|
class AppletStateMgr : IDisposable
|
|
|
|
{
|
|
|
|
private ConcurrentQueue<MessageInfo> Messages;
|
|
|
|
|
|
|
|
public FocusState FocusState { get; private set; }
|
|
|
|
|
|
|
|
public KEvent MessageEvent { get; private set; }
|
|
|
|
|
|
|
|
public AppletStateMgr()
|
|
|
|
{
|
|
|
|
Messages = new ConcurrentQueue<MessageInfo>();
|
|
|
|
|
|
|
|
MessageEvent = new KEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetFocus(bool IsFocused)
|
|
|
|
{
|
2018-04-18 22:52:23 -04:00
|
|
|
FocusState = IsFocused
|
2018-03-19 14:58:46 -04:00
|
|
|
? FocusState.InFocus
|
|
|
|
: FocusState.OutOfFocus;
|
|
|
|
|
|
|
|
EnqueueMessage(MessageInfo.FocusStateChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void EnqueueMessage(MessageInfo Message)
|
|
|
|
{
|
|
|
|
Messages.Enqueue(Message);
|
|
|
|
|
2018-04-18 22:52:23 -04:00
|
|
|
MessageEvent.WaitEvent.Set();
|
2018-03-19 14:58:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool TryDequeueMessage(out MessageInfo Message)
|
|
|
|
{
|
|
|
|
if (Messages.Count < 2)
|
|
|
|
{
|
2018-04-18 22:52:23 -04:00
|
|
|
MessageEvent.WaitEvent.Reset();
|
2018-03-19 14:58:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return Messages.TryDequeue(out Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool Disposing)
|
|
|
|
{
|
|
|
|
if (Disposing)
|
|
|
|
{
|
|
|
|
MessageEvent.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|