NotificationEventHandler.cs 2.5 KB

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