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; }
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); }
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; } } }
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); }