2021-02-08 11:37:30 +00:00
|
|
|
/*
|
|
|
|
* 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:
|
2021-02-24 09:45:55 +00:00
|
|
|
m_socket_driver.Open();
|
|
|
|
m_open_driver = std::addressof(m_socket_driver);
|
|
|
|
break;
|
2021-02-08 11:37:30 +00:00
|
|
|
case impl::DriverType::Usb:
|
2021-02-08 11:38:20 +00:00
|
|
|
m_usb_driver.Open();
|
|
|
|
m_open_driver = std::addressof(m_usb_driver);
|
|
|
|
break;
|
2021-02-08 11:37:30 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-02-10 01:42:39 +00:00
|
|
|
/* Set the driver type. */
|
|
|
|
m_driver_type = driver_type;
|
|
|
|
|
2021-02-08 11:37:30 +00:00
|
|
|
return ResultSuccess();
|
|
|
|
}
|
|
|
|
|
2021-02-10 03:07:51 +00:00
|
|
|
void DriverManager::CloseDriver() {
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_mutex);
|
|
|
|
|
|
|
|
/* Clear our driver type. */
|
2021-07-08 10:37:26 +01:00
|
|
|
m_driver_type = util::nullopt;
|
2021-02-10 03:07:51 +00:00
|
|
|
|
|
|
|
/* Close our driver. */
|
|
|
|
if (m_open_driver != nullptr) {
|
|
|
|
m_open_driver->Close();
|
|
|
|
m_open_driver = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-10 01:42:39 +00:00
|
|
|
impl::DriverType DriverManager::GetDriverType() {
|
|
|
|
/* Lock ourselves. */
|
2021-02-10 01:44:12 +00:00
|
|
|
std::scoped_lock lk(m_mutex);
|
|
|
|
|
2021-02-10 01:42:39 +00:00
|
|
|
return m_driver_type.value_or(impl::DriverType::Unknown);
|
|
|
|
}
|
|
|
|
|
2021-02-08 11:37:30 +00:00
|
|
|
IDriver *DriverManager::GetCurrentDriver() {
|
|
|
|
/* Lock ourselves. */
|
|
|
|
std::scoped_lock lk(m_mutex);
|
|
|
|
|
|
|
|
return m_open_driver;
|
|
|
|
}
|
|
|
|
|
2021-02-10 03:07:51 +00:00
|
|
|
void DriverManager::Cancel() {
|
|
|
|
m_open_driver->CancelSendReceive();
|
|
|
|
}
|
|
|
|
|
2021-02-09 20:36:37 +00:00
|
|
|
void DriverManager::SetDebugDriver(IDriver *driver) {
|
|
|
|
m_debug_driver = driver;
|
|
|
|
m_driver_type = impl::DriverType::Debug;
|
|
|
|
}
|
|
|
|
|
2021-02-08 11:37:30 +00:00
|
|
|
}
|