2021-02-08 07:13:04 +00:00
|
|
|
/*
|
2021-02-08 07:37:16 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2021-02-08 07:13:04 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include "driver/htclow_i_driver.hpp"
|
|
|
|
#include "ctrl/htclow_ctrl_service.hpp"
|
|
|
|
#include "mux/htclow_mux.hpp"
|
|
|
|
|
|
|
|
namespace ams::htclow {
|
|
|
|
|
|
|
|
class Worker {
|
2021-02-08 22:11:01 +00:00
|
|
|
private:
|
|
|
|
static_assert(sizeof(ctrl::HtcctrlPacketHeader) <= sizeof(PacketHeader));
|
|
|
|
static_assert(sizeof(ctrl::HtcctrlPacketBody) <= sizeof(PacketBody));
|
2021-02-08 07:13:04 +00:00
|
|
|
private:
|
|
|
|
u32 m_thread_stack_size;
|
2021-02-09 09:05:43 +00:00
|
|
|
u8 m_send_buffer[sizeof(PacketHeader) + sizeof(PacketBody)];
|
2021-02-08 22:11:01 +00:00
|
|
|
u8 m_receive_packet_body[sizeof(PacketBody)];
|
2021-02-08 07:13:04 +00:00
|
|
|
mem::StandardAllocator *m_allocator;
|
|
|
|
mux::Mux *m_mux;
|
|
|
|
ctrl::HtcctrlService *m_service;
|
|
|
|
driver::IDriver *m_driver;
|
|
|
|
os::ThreadType m_receive_thread;
|
|
|
|
os::ThreadType m_send_thread;
|
2021-02-08 09:25:10 +00:00
|
|
|
os::Event m_event;
|
2021-02-08 07:13:04 +00:00
|
|
|
void *m_receive_thread_stack;
|
|
|
|
void *m_send_thread_stack;
|
2021-02-08 13:45:23 +00:00
|
|
|
bool m_cancelled;
|
|
|
|
private:
|
|
|
|
static void ReceiveThreadEntry(void *arg) {
|
|
|
|
static_cast<Worker *>(arg)->ReceiveThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SendThreadEntry(void *arg) {
|
|
|
|
static_cast<Worker *>(arg)->SendThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReceiveThread();
|
|
|
|
void SendThread();
|
2021-02-08 07:13:04 +00:00
|
|
|
public:
|
|
|
|
Worker(mem::StandardAllocator *allocator, mux::Mux *mux, ctrl::HtcctrlService *ctrl_srv);
|
2021-02-08 13:45:23 +00:00
|
|
|
|
|
|
|
void SetDriver(driver::IDriver *driver);
|
|
|
|
|
|
|
|
void Start();
|
2021-02-10 03:07:51 +00:00
|
|
|
void Cancel();
|
2021-02-08 13:45:23 +00:00
|
|
|
void Wait();
|
|
|
|
private:
|
|
|
|
Result ProcessReceive();
|
|
|
|
Result ProcessSend();
|
2021-02-08 22:11:01 +00:00
|
|
|
|
|
|
|
Result ProcessReceive(const ctrl::HtcctrlPacketHeader &header);
|
|
|
|
Result ProcessReceive(const PacketHeader &header);
|
2021-02-08 07:13:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|