htclow: add Channel wrapper class
This commit is contained in:
@@ -211,6 +211,9 @@ namespace ams::htclow::mux {
|
||||
}
|
||||
|
||||
Result Mux::ConnectEnd(impl::ChannelInternalType channel, u32 task_id) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Get the trigger for the task. */
|
||||
const auto trigger = m_task_manager.GetTrigger(task_id);
|
||||
|
||||
@@ -255,6 +258,9 @@ namespace ams::htclow::mux {
|
||||
}
|
||||
|
||||
Result Mux::FlushEnd(u32 task_id) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Get the trigger for the task. */
|
||||
const auto trigger = m_task_manager.GetTrigger(task_id);
|
||||
|
||||
@@ -287,6 +293,9 @@ namespace ams::htclow::mux {
|
||||
}
|
||||
|
||||
Result Mux::ReceiveEnd(size_t *out, void *dst, size_t dst_size, impl::ChannelInternalType channel, u32 task_id) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Free the task. */
|
||||
m_task_manager.FreeTask(task_id);
|
||||
|
||||
@@ -317,6 +326,9 @@ namespace ams::htclow::mux {
|
||||
}
|
||||
|
||||
Result Mux::SendEnd(u32 task_id) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Get the trigger for the task. */
|
||||
const auto trigger = m_task_manager.GetTrigger(task_id);
|
||||
|
||||
@@ -329,6 +341,38 @@ namespace ams::htclow::mux {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result Mux::WaitReceiveBegin(u32 *out_task_id, impl::ChannelInternalType channel, size_t size) {
|
||||
return this->ReceiveBegin(out_task_id, channel, size);
|
||||
}
|
||||
|
||||
Result Mux::WaitReceiveEnd(u32 task_id) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Get the trigger for the task. */
|
||||
const auto trigger = m_task_manager.GetTrigger(task_id);
|
||||
|
||||
/* Free the task. */
|
||||
m_task_manager.FreeTask(task_id);
|
||||
|
||||
/* Check that we didn't hit a disconnect. */
|
||||
R_UNLESS(trigger != EventTrigger_Disconnect, htclow::ResultInvalidChannelStateDisconnected());
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void Mux::SetConfig(impl::ChannelInternalType channel, const ChannelConfig &config) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Find the channel. */
|
||||
auto it = m_channel_impl_map.GetMap().find(channel);
|
||||
AMS_ABORT_UNLESS(it != m_channel_impl_map.GetMap().end());
|
||||
|
||||
/* Perform the connection. */
|
||||
return m_channel_impl_map[it->second].SetConfig(config);
|
||||
}
|
||||
|
||||
void Mux::SetSendBuffer(impl::ChannelInternalType channel, void *buf, size_t buf_size, size_t max_packet_size) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
@@ -74,6 +74,11 @@ namespace ams::htclow::mux {
|
||||
Result SendBegin(u32 *out_task_id, size_t *out, const void *src, size_t src_size, impl::ChannelInternalType channel);
|
||||
Result SendEnd(u32 task_id);
|
||||
|
||||
Result WaitReceiveBegin(u32 *out_task_id, impl::ChannelInternalType channel, size_t size);
|
||||
Result WaitReceiveEnd(u32 task_id);
|
||||
|
||||
void SetConfig(impl::ChannelInternalType channel, const ChannelConfig &config);
|
||||
|
||||
void SetSendBuffer(impl::ChannelInternalType channel, void *buf, size_t buf_size, size_t max_packet_size);
|
||||
void SetReceiveBuffer(impl::ChannelInternalType channel, void *buf, size_t buf_size);
|
||||
void SetSendBufferWithData(impl::ChannelInternalType channel, const void *buf, size_t buf_size, size_t max_packet_size);
|
||||
|
||||
@@ -425,6 +425,17 @@ namespace ams::htclow::mux {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void ChannelImpl::SetConfig(const ChannelConfig &config) {
|
||||
/* Check our state. */
|
||||
R_ABORT_UNLESS(this->CheckState({ChannelState_Unconnectable, ChannelState_Connectable}));
|
||||
|
||||
/* Set our config. */
|
||||
m_config = config;
|
||||
|
||||
/* Set flow control for our send buffer. */
|
||||
m_send_buffer.SetFlowControlEnabled(m_config.flow_control_enabled);
|
||||
}
|
||||
|
||||
void ChannelImpl::SetSendBuffer(void *buf, size_t buf_size, size_t max_packet_size) {
|
||||
/* Set buffer. */
|
||||
m_send_buffer.SetBuffer(buf, buf_size);
|
||||
|
||||
@@ -80,6 +80,8 @@ namespace ams::htclow::mux {
|
||||
|
||||
Result DoShutdown();
|
||||
|
||||
void SetConfig(const ChannelConfig &config);
|
||||
|
||||
void SetSendBuffer(void *buf, size_t buf_size, size_t max_packet_size);
|
||||
void SetReceiveBuffer(void *buf, size_t buf_size);
|
||||
void SetSendBufferWithData(const void *buf, size_t buf_size, size_t max_packet_size);
|
||||
|
||||
@@ -41,6 +41,11 @@ namespace ams::htclow::mux {
|
||||
m_version = version;
|
||||
}
|
||||
|
||||
void SendBuffer::SetFlowControlEnabled(bool en) {
|
||||
/* Set flow control enabled. */
|
||||
m_flow_control_enabled = en;
|
||||
}
|
||||
|
||||
void SendBuffer::MakeDataPacketHeader(PacketHeader *header, int body_size, s16 version, u64 share, u32 offset) const {
|
||||
/* Set all packet fields. */
|
||||
header->signature = HtcGen2Signature;
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace ams::htclow::mux {
|
||||
~SendBuffer();
|
||||
|
||||
void SetVersion(s16 version);
|
||||
void SetFlowControlEnabled(bool en);
|
||||
|
||||
bool QueryNextPacket(PacketHeader *header, PacketBody *body, int *out_body_size, u64 max_data, u64 total_send_size, bool has_share, u64 share);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user