HDomain.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Ryujinx.Core.OsHle.Utilities;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.Core.OsHle.Handles
  5. {
  6. class HDomain : HSession
  7. {
  8. private Dictionary<int, object> Objects;
  9. private IdPool ObjIds;
  10. public HDomain(HSession Session) : base(Session)
  11. {
  12. Objects = new Dictionary<int, object>();
  13. ObjIds = new IdPool();
  14. }
  15. public int GenerateObjectId(object Obj)
  16. {
  17. int Id = ObjIds.GenerateId();
  18. if (Id == -1)
  19. {
  20. throw new InvalidOperationException();
  21. }
  22. Objects.Add(Id, Obj);
  23. return Id;
  24. }
  25. public void DeleteObject(int Id)
  26. {
  27. if (Objects.TryGetValue(Id, out object Obj))
  28. {
  29. if (Obj is IDisposable DisposableObj)
  30. {
  31. DisposableObj.Dispose();
  32. }
  33. ObjIds.DeleteId(Id);
  34. Objects.Remove(Id);
  35. }
  36. }
  37. public object GetObject(int Id)
  38. {
  39. if (Objects.TryGetValue(Id, out object Obj))
  40. {
  41. return Obj;
  42. }
  43. return null;
  44. }
  45. }
  46. }