1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-27 14:22:17 +00:00
Atmosphere/libraries/libstratosphere/source/htclow/driver/htclow_driver_manager.cpp

94 lines
2.9 KiB
C++

/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "htclow_driver_manager.hpp"
namespace ams::htclow::driver {
Result DriverManager::OpenDriver(impl::DriverType driver_type) {
/* Lock ourselves. */
std::scoped_lock lk(m_mutex);
/* Check that we're not already open. */
R_UNLESS(m_open_driver == nullptr, htclow::ResultDriverOpened());
/* Open the driver. */
switch (driver_type) {
case impl::DriverType::Debug:
R_TRY(m_debug_driver->Open());
m_open_driver = m_debug_driver;
break;
case impl::DriverType::Socket:
m_socket_driver.Open();
m_open_driver = std::addressof(m_socket_driver);
break;
case impl::DriverType::Usb:
m_usb_driver.Open();
m_open_driver = std::addressof(m_usb_driver);
break;
case impl::DriverType::PlainChannel:
//m_plain_channel_driver.Open();
//m_open_driver = std::addressof(m_plain_channel_driver);
//break;
return htclow::ResultUnknownDriverType();
default:
return htclow::ResultUnknownDriverType();
}
/* Set the driver type. */
m_driver_type = driver_type;
return ResultSuccess();
}
void DriverManager::CloseDriver() {
/* Lock ourselves. */
std::scoped_lock lk(m_mutex);
/* Clear our driver type. */
m_driver_type = std::nullopt;
/* Close our driver. */
if (m_open_driver != nullptr) {
m_open_driver->Close();
m_open_driver = nullptr;
}
}
impl::DriverType DriverManager::GetDriverType() {
/* Lock ourselves. */
std::scoped_lock lk(m_mutex);
return m_driver_type.value_or(impl::DriverType::Unknown);
}
IDriver *DriverManager::GetCurrentDriver() {
/* Lock ourselves. */
std::scoped_lock lk(m_mutex);
return m_open_driver;
}
void DriverManager::Cancel() {
m_open_driver->CancelSendReceive();
}
void DriverManager::SetDebugDriver(IDriver *driver) {
m_debug_driver = driver;
m_driver_type = impl::DriverType::Debug;
}
}