blob: 6b46eb80978a2307afea2a6d5c9440b329c95e99 [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/gamepad/gamepad_data_fetcher_manager.h"
#include "device/gamepad/gamepad_data_fetcher.h"
#include "device/gamepad/gamepad_platform_data_fetcher.h"
namespace device {
namespace {
GamepadDataFetcherManager* g_gamepad_data_fetcher_manager = 0;
}
GamepadDataFetcherManager::GamepadDataFetcherManager() : provider_(nullptr) {}
GamepadDataFetcherManager::~GamepadDataFetcherManager() {}
GamepadDataFetcherManager* GamepadDataFetcherManager::GetInstance() {
if (!g_gamepad_data_fetcher_manager) {
g_gamepad_data_fetcher_manager = new GamepadDataFetcherManager;
// Add platform specific data fetchers
AddGamepadPlatformDataFetchers(g_gamepad_data_fetcher_manager);
}
return g_gamepad_data_fetcher_manager;
}
void GamepadDataFetcherManager::AddFactory(GamepadDataFetcherFactory* factory) {
factories_.push_back(factory);
if (provider_) {
provider_->AddGamepadDataFetcher(factory->CreateDataFetcher());
}
}
void GamepadDataFetcherManager::RemoveSourceFactory(GamepadSource source) {
if (provider_)
provider_->RemoveSourceGamepadDataFetcher(source);
for (FactoryVector::iterator it = factories_.begin(); it != factories_.end();
++it) {
if ((*it)->source() == source) {
delete (*it);
factories_.erase(it);
}
}
}
void GamepadDataFetcherManager::InitializeProvider(GamepadProvider* provider) {
DCHECK(!provider_);
provider_ = provider;
for (const auto& it : factories_) {
provider_->AddGamepadDataFetcher(it->CreateDataFetcher());
}
}
void GamepadDataFetcherManager::ClearProvider() {
provider_ = nullptr;
}
} // namespace device