Exemplo n.º 1
0
uint32_t
GamepadService::AddGamepad(const char* aId,
                           GamepadMappingType aMapping,
                           uint32_t aNumButtons,
                           uint32_t aNumAxes)
{
  //TODO: bug 852258: get initial button/axis state
  nsRefPtr<Gamepad> gamepad =
    new Gamepad(nullptr,
                NS_ConvertUTF8toUTF16(nsDependentCString(aId)),
                0,
                aMapping,
                aNumButtons,
                aNumAxes);
  int index = -1;
  for (uint32_t i = 0; i < mGamepads.Length(); i++) {
    if (!mGamepads[i]) {
      mGamepads[i] = gamepad;
      index = i;
      break;
    }
  }
  if (index == -1) {
    mGamepads.AppendElement(gamepad);
    index = mGamepads.Length() - 1;
  }

  gamepad->SetIndex(index);
  NewConnectionEvent(index, true);

  return index;
}
Exemplo n.º 2
0
void
GamepadService::RemoveGamepad(uint32_t aIndex)
{
  RefPtr<Gamepad> gamepad = GetGamepad(aIndex);
  if (!gamepad) {
    NS_WARNING("Trying to delete gamepad with invalid index");
    return;
  }
  gamepad->SetConnected(false);
    NewConnectionEvent(aIndex, false);
  mGamepads.Remove(aIndex);
}
Exemplo n.º 3
0
void
GamepadService::RemoveGamepad(uint32_t aIndex)
{
  if (aIndex < mGamepads.Length()) {
    mGamepads[aIndex]->SetConnected(false);
    NewConnectionEvent(aIndex, false);
    // If this is the last entry in the list, just remove it.
    if (aIndex == mGamepads.Length() - 1) {
      mGamepads.RemoveElementAt(aIndex);
    } else {
      // Otherwise just null it out and leave it, so the
      // indices of the following entries remain valid.
      mGamepads[aIndex] = nullptr;
    }
  }
}
Exemplo n.º 4
0
void
GamepadService::AddGamepad(uint32_t aIndex,
                           const nsAString& aId,
                           GamepadMappingType aMapping,
                           uint32_t aNumButtons,
                           uint32_t aNumAxes)
{
  //TODO: bug 852258: get initial button/axis state
  RefPtr<Gamepad> gamepad =
    new Gamepad(nullptr,
                aId,
                0, // index is set by global window
                aMapping,
                aNumButtons,
                aNumAxes);

  // We store the gamepad related to its index given by the parent process.
  mGamepads.Put(aIndex, gamepad);
  NewConnectionEvent(aIndex, true);
}