Changeset View
Changeset View
Standalone View
Standalone View
extern/audaspace/src/devices/DeviceManager.cpp
- This file was added.
| /******************************************************************************* | |||||
| * Copyright 2009-2015 Jörg Müller | |||||
| * | |||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | |||||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||||
| * | |||||
| * Unless required by applicable law or agreed to in writing, software | |||||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| * See the License for the specific language governing permissions and | |||||
| * limitations under the License. | |||||
| ******************************************************************************/ | |||||
| #include "devices/DeviceManager.h" | |||||
| #include "devices/IDeviceFactory.h" | |||||
| #include "devices/IDevice.h" | |||||
| #include "devices/I3DDevice.h" | |||||
| #include <limits> | |||||
| #include <string> | |||||
| AUD_NAMESPACE_BEGIN | |||||
| std::unordered_map<std::string, std::shared_ptr<IDeviceFactory>> DeviceManager::m_factories; | |||||
| std::shared_ptr<IDevice> DeviceManager::m_device; | |||||
| void DeviceManager::registerDevice(std::string name, std::shared_ptr<IDeviceFactory> factory) | |||||
| { | |||||
| m_factories[name] = factory; | |||||
| } | |||||
| std::shared_ptr<IDeviceFactory> DeviceManager::getDeviceFactory(std::string name) | |||||
| { | |||||
| return m_factories[name]; | |||||
| } | |||||
| std::shared_ptr<IDeviceFactory> DeviceManager::getDefaultDeviceFactory() | |||||
| { | |||||
| int min = std::numeric_limits<int>::min(); | |||||
| std::shared_ptr<IDeviceFactory> result; | |||||
| for(auto factory : m_factories) | |||||
| { | |||||
| if(factory.second->getPriority() >= min) | |||||
| { | |||||
| result = factory.second; | |||||
| min = result->getPriority(); | |||||
| } | |||||
| } | |||||
| return result; | |||||
| } | |||||
| void DeviceManager::setDevice(std::shared_ptr<IDevice> device) | |||||
| { | |||||
| m_device = device; | |||||
| } | |||||
| void DeviceManager::openDevice(std::string name) | |||||
| { | |||||
| setDevice(getDeviceFactory(name)->openDevice()); | |||||
| } | |||||
| void DeviceManager::openDefaultDevice() | |||||
| { | |||||
| setDevice(getDefaultDeviceFactory()->openDevice()); | |||||
| } | |||||
| void DeviceManager::releaseDevice() | |||||
| { | |||||
| m_device = nullptr; | |||||
| } | |||||
| std::shared_ptr<IDevice> DeviceManager::getDevice() | |||||
| { | |||||
| return m_device; | |||||
| } | |||||
| std::shared_ptr<I3DDevice> DeviceManager::get3DDevice() | |||||
| { | |||||
| return std::dynamic_pointer_cast<I3DDevice>(m_device); | |||||
| } | |||||
| AUD_NAMESPACE_END | |||||