GamepadTestChannelParent.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "GamepadTestChannelParent.h"
  5. #include "mozilla/dom/GamepadPlatformService.h"
  6. #include "mozilla/ipc/BackgroundParent.h"
  7. #include "mozilla/Unused.h"
  8. namespace mozilla {
  9. namespace dom {
  10. bool
  11. GamepadTestChannelParent::RecvGamepadTestEvent(const uint32_t& aID,
  12. const GamepadChangeEvent& aEvent)
  13. {
  14. mozilla::ipc::AssertIsOnBackgroundThread();
  15. RefPtr<GamepadPlatformService> service =
  16. GamepadPlatformService::GetParentService();
  17. MOZ_ASSERT(service);
  18. if (aEvent.type() == GamepadChangeEvent::TGamepadAdded) {
  19. const GamepadAdded& a = aEvent.get_GamepadAdded();
  20. nsCString gamepadID;
  21. LossyCopyUTF16toASCII(a.id(), gamepadID);
  22. uint32_t index = service->AddGamepad(gamepadID.get(),
  23. static_cast<GamepadMappingType>(a.mapping()),
  24. a.num_buttons(),
  25. a.num_axes());
  26. if (!mShuttingdown) {
  27. Unused << SendReplyGamepadIndex(aID, index);
  28. }
  29. return true;
  30. }
  31. if (aEvent.type() == GamepadChangeEvent::TGamepadRemoved) {
  32. const GamepadRemoved& a = aEvent.get_GamepadRemoved();
  33. service->RemoveGamepad(a.index());
  34. return true;
  35. }
  36. if (aEvent.type() == GamepadChangeEvent::TGamepadButtonInformation) {
  37. const GamepadButtonInformation& a = aEvent.get_GamepadButtonInformation();
  38. service->NewButtonEvent(a.index(), a.button(), a.pressed(), a.value());
  39. return true;
  40. }
  41. if (aEvent.type() == GamepadChangeEvent::TGamepadAxisInformation) {
  42. const GamepadAxisInformation& a = aEvent.get_GamepadAxisInformation();
  43. service->NewAxisMoveEvent(a.index(), a.axis(), a.value());
  44. return true;
  45. }
  46. NS_WARNING("Unknown event type.");
  47. return false;
  48. }
  49. bool
  50. GamepadTestChannelParent::RecvShutdownChannel()
  51. {
  52. mShuttingdown = true;
  53. Unused << Send__delete__(this);
  54. return true;
  55. }
  56. } // namespace dom
  57. } // namespace mozilla