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>
|
|
|
|
|
|
|
|
namespace ams::htclow::mux {
|
|
|
|
|
|
|
|
constexpr inline int MaxTaskCount = 0x80;
|
|
|
|
|
2021-02-08 13:45:23 +00:00
|
|
|
enum EventTrigger : u8 {
|
2021-02-09 11:21:45 +00:00
|
|
|
EventTrigger_Disconnect = 1,
|
|
|
|
EventTrigger_ReceiveData = 2,
|
2021-02-10 03:51:52 +00:00
|
|
|
EventTrigger_SendComplete = 4,
|
2021-02-09 11:21:45 +00:00
|
|
|
EventTrigger_SendReady = 5,
|
|
|
|
EventTrigger_SendBufferEmpty = 10,
|
|
|
|
EventTrigger_ConnectReady = 11,
|
2021-02-08 13:45:23 +00:00
|
|
|
};
|
|
|
|
|
2021-02-08 07:13:04 +00:00
|
|
|
class TaskManager {
|
|
|
|
private:
|
2021-02-08 13:45:23 +00:00
|
|
|
enum TaskType : u8 {
|
|
|
|
TaskType_Receive = 0,
|
|
|
|
TaskType_Send = 1,
|
|
|
|
TaskType_Flush = 6,
|
|
|
|
TaskType_Connect = 7,
|
|
|
|
};
|
|
|
|
|
2021-02-08 07:13:04 +00:00
|
|
|
struct Task {
|
|
|
|
impl::ChannelInternalType channel;
|
|
|
|
os::EventType event;
|
2021-02-08 13:45:23 +00:00
|
|
|
bool has_event_trigger;
|
|
|
|
EventTrigger event_trigger;
|
|
|
|
TaskType type;
|
2021-02-08 22:11:01 +00:00
|
|
|
size_t size;
|
2021-02-08 07:13:04 +00:00
|
|
|
};
|
|
|
|
private:
|
|
|
|
bool m_valid[MaxTaskCount];
|
|
|
|
Task m_tasks[MaxTaskCount];
|
|
|
|
public:
|
|
|
|
TaskManager() : m_valid() { /* ... */ }
|
2021-02-08 13:45:23 +00:00
|
|
|
|
2021-02-10 03:07:51 +00:00
|
|
|
Result AllocateTask(u32 *out_task_id, impl::ChannelInternalType channel);
|
|
|
|
void FreeTask(u32 task_id);
|
|
|
|
|
2021-02-09 20:36:37 +00:00
|
|
|
os::EventType *GetTaskEvent(u32 task_id);
|
2021-02-10 03:07:51 +00:00
|
|
|
EventTrigger GetTrigger(u32 task_id);
|
|
|
|
|
|
|
|
void ConfigureConnectTask(u32 task_id);
|
|
|
|
void ConfigureFlushTask(u32 task_id);
|
|
|
|
void ConfigureReceiveTask(u32 task_id, size_t size);
|
|
|
|
void ConfigureSendTask(u32 task_id);
|
2021-02-09 20:36:37 +00:00
|
|
|
|
2021-02-08 13:45:23 +00:00
|
|
|
void NotifyDisconnect(impl::ChannelInternalType channel);
|
2021-02-08 22:11:01 +00:00
|
|
|
void NotifyReceiveData(impl::ChannelInternalType channel, size_t size);
|
2021-02-09 11:21:45 +00:00
|
|
|
void NotifySendReady();
|
|
|
|
void NotifySendBufferEmpty(impl::ChannelInternalType channel);
|
2021-02-08 13:45:23 +00:00
|
|
|
void NotifyConnectReady();
|
2021-02-10 03:07:51 +00:00
|
|
|
|
2021-02-08 13:45:23 +00:00
|
|
|
void CompleteTask(int index, EventTrigger trigger);
|
2021-02-08 07:13:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|