mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-12-26 20:41:21 -08:00
ee81ab547e
* am: Initial swkbd implementation Currently only implements the full screen keyboard, inline keyboard will come later. * Remove unnecessary logging * Miscellaneous tidy up * am: Always pop incoming interactive session data * am: Add a reminder to implement the full config struct * am: Check for a max length of zero We should only limit/truncate text when the max length is set to a non-zero value. * Add documentation * am: Return IStorage not available when queue is empty We should be returning the appropriate error code when the FIFO is empty, rather than just throwing an exception and killing the emulator. * Fix typo * Code style changes
121 lines
2.5 KiB
C#
121 lines
2.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Am.AppletAE
|
|
{
|
|
internal class AppletFifo<T> : IAppletFifo<T>
|
|
{
|
|
private ConcurrentQueue<T> _dataQueue;
|
|
|
|
public event EventHandler DataAvailable;
|
|
|
|
public bool IsSynchronized
|
|
{
|
|
get { return ((ICollection)_dataQueue).IsSynchronized; }
|
|
}
|
|
|
|
public object SyncRoot
|
|
{
|
|
get { return ((ICollection)_dataQueue).SyncRoot; }
|
|
}
|
|
|
|
public int Count
|
|
{
|
|
get { return _dataQueue.Count; }
|
|
}
|
|
|
|
public AppletFifo()
|
|
{
|
|
_dataQueue = new ConcurrentQueue<T>();
|
|
}
|
|
|
|
public void Push(T item)
|
|
{
|
|
_dataQueue.Enqueue(item);
|
|
|
|
DataAvailable?.Invoke(this, null);
|
|
}
|
|
|
|
public bool TryAdd(T item)
|
|
{
|
|
try
|
|
{
|
|
this.Push(item);
|
|
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public T Pop()
|
|
{
|
|
if (_dataQueue.TryDequeue(out T result))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
throw new InvalidOperationException("FIFO empty.");
|
|
}
|
|
|
|
public bool TryPop(out T result)
|
|
{
|
|
return _dataQueue.TryDequeue(out result);
|
|
}
|
|
|
|
public bool TryTake(out T item)
|
|
{
|
|
return this.TryPop(out item);
|
|
}
|
|
|
|
public T Peek()
|
|
{
|
|
if (_dataQueue.TryPeek(out T result))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
throw new InvalidOperationException("FIFO empty.");
|
|
}
|
|
|
|
public bool TryPeek(out T result)
|
|
{
|
|
return _dataQueue.TryPeek(out result);
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
_dataQueue.Clear();
|
|
}
|
|
|
|
public T[] ToArray()
|
|
{
|
|
return _dataQueue.ToArray();
|
|
}
|
|
|
|
public void CopyTo(T[] array, int arrayIndex)
|
|
{
|
|
_dataQueue.CopyTo(array, arrayIndex);
|
|
}
|
|
|
|
public void CopyTo(Array array, int index)
|
|
{
|
|
this.CopyTo((T[])array, index);
|
|
}
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
{
|
|
return _dataQueue.GetEnumerator();
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return _dataQueue.GetEnumerator();
|
|
}
|
|
}
|
|
}
|