NotificationEventHandler.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Ryujinx.HLE.HOS.Services.Account.Acc;
  2. using Ryujinx.HLE.Utilities;
  3. namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.NotificationService
  4. {
  5. public sealed class NotificationEventHandler
  6. {
  7. private static NotificationEventHandler instance;
  8. private static object instanceLock = new object();
  9. private INotificationService[] _registry;
  10. public static NotificationEventHandler Instance
  11. {
  12. get
  13. {
  14. lock (instanceLock)
  15. {
  16. if (instance == null)
  17. {
  18. instance = new NotificationEventHandler();
  19. }
  20. return instance;
  21. }
  22. }
  23. }
  24. NotificationEventHandler()
  25. {
  26. _registry = new INotificationService[0x20];
  27. }
  28. internal void RegisterNotificationService(INotificationService service)
  29. {
  30. // NOTE: in case there isn't space anymore in the registry array, Nintendo doesn't return any errors.
  31. for (int i = 0; i < _registry.Length; i++)
  32. {
  33. if (_registry[i] == null)
  34. {
  35. _registry[i] = service;
  36. break;
  37. }
  38. }
  39. }
  40. internal void UnregisterNotificationService(INotificationService service)
  41. {
  42. // NOTE: in case there isn't the entry in the registry array, Nintendo doesn't return any errors.
  43. for (int i = 0; i < _registry.Length; i++)
  44. {
  45. if (_registry[i] == service)
  46. {
  47. _registry[i] = null;
  48. break;
  49. }
  50. }
  51. }
  52. // TODO: Use this when we will have enough things to go online.
  53. public void SignalFriendListUpdate(UserId targetId)
  54. {
  55. for (int i = 0; i < _registry.Length; i++)
  56. {
  57. if (_registry[i] != null)
  58. {
  59. _registry[i].SignalFriendListUpdate(targetId);
  60. }
  61. }
  62. }
  63. // TODO: Use this when we will have enough things to go online.
  64. public void SignalNewFriendRequest(UserId targetId)
  65. {
  66. for (int i = 0; i < _registry.Length; i++)
  67. {
  68. if (_registry[i] != null)
  69. {
  70. _registry[i].SignalNewFriendRequest(targetId);
  71. }
  72. }
  73. }
  74. }
  75. }