1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-18 16:32:05 +00:00
Atmosphere/libraries/libstratosphere/source/htclow/htclow_worker.hpp
2021-02-24 04:06:54 -08:00

71 lines
2.4 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/>.
*/
#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 {
private:
static_assert(sizeof(ctrl::HtcctrlPacketHeader) <= sizeof(PacketHeader));
static_assert(sizeof(ctrl::HtcctrlPacketBody) <= sizeof(PacketBody));
private:
u32 m_thread_stack_size;
u8 m_packet_header[sizeof(PacketHeader)];
u8 m_send_packet_body[sizeof(PacketBody)];
u8 m_receive_packet_body[sizeof(PacketBody)];
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;
os::Event m_event;
void *m_receive_thread_stack;
void *m_send_thread_stack;
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();
public:
Worker(mem::StandardAllocator *allocator, mux::Mux *mux, ctrl::HtcctrlService *ctrl_srv);
void SetDriver(driver::IDriver *driver);
void Start();
void Wait();
private:
void Cancel();
Result ProcessReceive();
Result ProcessSend();
Result ProcessReceive(const ctrl::HtcctrlPacketHeader &header);
Result ProcessReceive(const PacketHeader &header);
};
}