INotificationService.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Ryujinx.HLE.HOS.Ipc;
  2. using Ryujinx.HLE.HOS.Kernel.Common;
  3. using Ryujinx.HLE.HOS.Kernel.Threading;
  4. using Ryujinx.HLE.Utilities;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace Ryujinx.HLE.HOS.Services.Friend
  8. {
  9. class INotificationService : IpcService
  10. {
  11. private UInt128 _userId;
  12. private KEvent _notificationEvent;
  13. private int _notificationEventHandle = 0;
  14. private Dictionary<int, ServiceProcessRequest> _commands;
  15. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  16. public INotificationService(UInt128 userId)
  17. {
  18. _commands = new Dictionary<int, ServiceProcessRequest>
  19. {
  20. { 0, GetEvent }, // 2.0.0+
  21. //{ 1, Clear }, // 2.0.0+
  22. //{ 2, Pop }, // 2.0.0+
  23. };
  24. _userId = userId;
  25. }
  26. public long GetEvent(ServiceCtx context)
  27. {
  28. if (_notificationEventHandle == 0)
  29. {
  30. _notificationEvent = new KEvent(context.Device.System);
  31. if (context.Process.HandleTable.GenerateHandle(_notificationEvent.ReadableEvent, out _notificationEventHandle) != KernelResult.Success)
  32. {
  33. throw new InvalidOperationException("Out of handles!");
  34. }
  35. }
  36. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_notificationEventHandle);
  37. return 0;
  38. }
  39. }
  40. }