Пример #1
0
void
GamepadManager::Update(const GamepadChangeEvent& aEvent)
{
    if (aEvent.type() == GamepadChangeEvent::TGamepadAdded) {
        const GamepadAdded& a = aEvent.get_GamepadAdded();
        AddGamepad(a.index(), a.id(),
                   static_cast<GamepadMappingType>(a.mapping()),
                   a.num_buttons(), a.num_axes());
        return;
    }
    if (aEvent.type() == GamepadChangeEvent::TGamepadRemoved) {
        const GamepadRemoved& a = aEvent.get_GamepadRemoved();
        RemoveGamepad(a.index());
        return;
    }
    if (aEvent.type() == GamepadChangeEvent::TGamepadButtonInformation) {
        const GamepadButtonInformation& a = aEvent.get_GamepadButtonInformation();
        NewButtonEvent(a.index(), a.button(), a.pressed(), a.value());
        return;
    }
    if (aEvent.type() == GamepadChangeEvent::TGamepadAxisInformation) {
        const GamepadAxisInformation& a = aEvent.get_GamepadAxisInformation();
        NewAxisMoveEvent(a.index(), a.axis(), a.value());
        return;
    }

    MOZ_CRASH("We shouldn't be here!");

}
mozilla::ipc::IPCResult
GamepadTestChannelParent::RecvGamepadTestEvent(const uint32_t& aID,
                                               const GamepadChangeEvent& aEvent)
{
  mozilla::ipc::AssertIsOnBackgroundThread();
  RefPtr<GamepadPlatformService>  service =
    GamepadPlatformService::GetParentService();
  MOZ_ASSERT(service);
  if (aEvent.type() == GamepadChangeEvent::TGamepadAdded) {
    const GamepadAdded& a = aEvent.get_GamepadAdded();
    nsCString gamepadID;
    LossyCopyUTF16toASCII(a.id(), gamepadID);
    uint32_t index = service->AddGamepad(gamepadID.get(),
                                         static_cast<GamepadMappingType>(a.mapping()),
                                         a.hand(),
                                         a.num_buttons(),
                                         a.num_axes(),
                                         a.num_haptics());
    if (!mShuttingdown) {
      Unused << SendReplyGamepadIndex(aID, index);
    }
    return IPC_OK();
  }
  if (aEvent.type() == GamepadChangeEvent::TGamepadRemoved) {
    const GamepadRemoved& a = aEvent.get_GamepadRemoved();
    service->RemoveGamepad(a.index());
    return IPC_OK();
  }
  if (aEvent.type() == GamepadChangeEvent::TGamepadButtonInformation) {
    const GamepadButtonInformation& a = aEvent.get_GamepadButtonInformation();
    service->NewButtonEvent(a.index(), a.button(), a.pressed(), a.touched(),
                            a.value());
    return IPC_OK();
  }
  if (aEvent.type() == GamepadChangeEvent::TGamepadAxisInformation) {
    const GamepadAxisInformation& a = aEvent.get_GamepadAxisInformation();
    service->NewAxisMoveEvent(a.index(), a.axis(), a.value());
    return IPC_OK();
  }
  if (aEvent.type() == GamepadChangeEvent::TGamepadPoseInformation) {
    const GamepadPoseInformation& a = aEvent.get_GamepadPoseInformation();
    service->NewPoseEvent(a.index(), a.pose_state());
    return IPC_OK();
  }

  NS_WARNING("Unknown event type.");
  return IPC_FAIL_NO_REASON(this);
}