2018-02-20 21:09:23 +01:00
|
|
|
using Ryujinx.Core.OsHle.Utilities;
|
2018-02-05 00:08:20 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-02-20 21:09:23 +01:00
|
|
|
namespace Ryujinx.Core.OsHle.Handles
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
class HDomain : HSession
|
|
|
|
{
|
|
|
|
private Dictionary<int, object> Objects;
|
|
|
|
|
|
|
|
private IdPool ObjIds;
|
|
|
|
|
|
|
|
public HDomain(HSession Session) : base(Session)
|
|
|
|
{
|
|
|
|
Objects = new Dictionary<int, object>();
|
|
|
|
|
|
|
|
ObjIds = new IdPool();
|
|
|
|
}
|
|
|
|
|
2018-02-10 19:31:40 +01:00
|
|
|
public int GenerateObjectId(object Obj)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
int Id = ObjIds.GenerateId();
|
|
|
|
|
|
|
|
if (Id == -1)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
Objects.Add(Id, Obj);
|
|
|
|
|
|
|
|
return Id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DeleteObject(int Id)
|
|
|
|
{
|
|
|
|
if (Objects.TryGetValue(Id, out object Obj))
|
|
|
|
{
|
|
|
|
if (Obj is IDisposable DisposableObj)
|
|
|
|
{
|
|
|
|
DisposableObj.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjIds.DeleteId(Id);
|
|
|
|
Objects.Remove(Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public object GetObject(int Id)
|
|
|
|
{
|
|
|
|
if (Objects.TryGetValue(Id, out object Obj))
|
|
|
|
{
|
|
|
|
return Obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|