Revert "hoc-clk: add live vdd2, live boost clock and basic pwm dimming"
This reverts commit 15b7df8ef1.
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
#include "htcs_data_channel_manager.hpp"
|
||||
#include "../../../htclow/htclow_channel.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
Result DataChannelManager::Receive(void *buffer, s64 buffer_size, u32 task_id) {
|
||||
/* Check that the buffer size is allowable. */
|
||||
R_UNLESS(util::IsIntValueRepresentable<size_t>(buffer_size), htcs::ResultInvalidSize());
|
||||
|
||||
/* Create an htclow channel. */
|
||||
htclow::Channel channel(m_htclow_manager);
|
||||
|
||||
/* Open the channel. */
|
||||
R_ABORT_UNLESS(channel.Open(std::addressof(m_module), GetReceiveDataChannelId(task_id)));
|
||||
|
||||
/* Ensure that we close the channel, when we're done. */
|
||||
ON_SCOPE_EXIT { channel.Close(); };
|
||||
|
||||
/* Set the channel config. */
|
||||
constexpr htclow::ChannelConfig BulkReceiveConfig = {
|
||||
.flow_control_enabled = false,
|
||||
.handshake_enabled = false,
|
||||
.max_packet_size = 0x3E000,
|
||||
};
|
||||
channel.SetConfig(BulkReceiveConfig);
|
||||
|
||||
/* Set the receive buffer. */
|
||||
channel.SetReceiveBuffer(buffer, buffer_size);
|
||||
|
||||
/* Connect the channel. */
|
||||
R_TRY(channel.Connect());
|
||||
|
||||
/* Ensure that we clean up when we're done. */
|
||||
ON_SCOPE_EXIT { channel.Shutdown(); };
|
||||
|
||||
/* Notify the receive task. */
|
||||
R_TRY(m_rpc_client->Notify<ReceiveTask>(task_id));
|
||||
|
||||
/* Wait to receive the data. */
|
||||
R_TRY(channel.WaitReceive(buffer_size));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result DataChannelManager::Send(const void *buffer, s64 buffer_size, u32 task_id) {
|
||||
/* Check that the buffer size is allowable. */
|
||||
R_UNLESS(util::IsIntValueRepresentable<size_t>(buffer_size), htcs::ResultInvalidSize());
|
||||
|
||||
/* Create an htclow channel. */
|
||||
htclow::Channel channel(m_htclow_manager);
|
||||
|
||||
/* Open the channel. */
|
||||
R_ABORT_UNLESS(channel.Open(std::addressof(m_module), GetSendDataChannelId(task_id)));
|
||||
|
||||
/* Ensure that we close the channel, when we're done. */
|
||||
ON_SCOPE_EXIT { channel.Close(); };
|
||||
|
||||
/* Set the channel config. */
|
||||
constexpr htclow::ChannelConfig BulkSendConfig = {
|
||||
.flow_control_enabled = false,
|
||||
.handshake_enabled = false,
|
||||
.max_packet_size = 0x3E000,
|
||||
};
|
||||
channel.SetConfig(BulkSendConfig);
|
||||
|
||||
/* Set the send buffer. */
|
||||
channel.SetSendBufferWithData(buffer, buffer_size);
|
||||
|
||||
/* Connect the channel. */
|
||||
R_TRY(channel.Connect());
|
||||
|
||||
/* Ensure that we clean up when we're done. */
|
||||
ON_SCOPE_EXIT { channel.Shutdown(); };
|
||||
|
||||
/* Wait to send the data. */
|
||||
R_TRY(channel.Flush());
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "../../../htclow/htclow_manager.hpp"
|
||||
#include "../../../htc/server/rpc/htc_rpc_client.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
class DataChannelManager {
|
||||
private:
|
||||
htc::server::rpc::RpcClient* m_rpc_client;
|
||||
htclow::HtclowManager *m_htclow_manager;
|
||||
htclow::Module m_module;
|
||||
public:
|
||||
DataChannelManager(htc::server::rpc::RpcClient *client, htclow::HtclowManager *htclow_manager) : m_rpc_client(client), m_htclow_manager(htclow_manager), m_module(htclow::ModuleId::Htcs) { /* ... */ }
|
||||
public:
|
||||
Result Receive(void *buffer, s64 buffer_size, u32 task_id);
|
||||
Result Send(const void *buffer, s64 buffer_size, u32 task_id);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
Result AcceptTask::SetArguments(s32 server_handle) {
|
||||
/* Check that we're valid. */
|
||||
R_UNLESS(this->IsValid(), htcs::ResultInvalidTask());
|
||||
|
||||
/* Set our arguments. */
|
||||
m_server_handle = server_handle;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void AcceptTask::Complete(htcs::SocketError err, s32 desc) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
m_desc = desc;
|
||||
|
||||
/* Complete. */
|
||||
HtcsSignalingTask::Complete();
|
||||
}
|
||||
|
||||
Result AcceptTask::GetResult(htcs::SocketError *out_err, s32 *out_desc, s32 server_handle) const {
|
||||
/* Check the server handle. */
|
||||
R_UNLESS(m_server_handle == server_handle, htcs::ResultInvalidServerHandle());
|
||||
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
*out_desc = m_desc;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result AcceptTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]), packet->params[1]);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result AcceptTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::Accept,
|
||||
.body_size = 0,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_server_handle,
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
Result BindTask::SetArguments(s32 handle, const HtcsPeerName &peer_name, const HtcsPortName &port_name) {
|
||||
/* Set our arguments. */
|
||||
m_handle = handle;
|
||||
m_peer_name = peer_name;
|
||||
m_port_name = port_name;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void BindTask::Complete(htcs::SocketError err) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
|
||||
/* Complete. */
|
||||
HtcsTask::Complete();
|
||||
}
|
||||
|
||||
Result BindTask::GetResult(htcs::SocketError *out_err) const {
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result BindTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result BindTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::Bind,
|
||||
.body_size = sizeof(m_peer_name) + sizeof(m_port_name),
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_handle,
|
||||
},
|
||||
};
|
||||
std::memcpy(packet->data + 0, std::addressof(m_peer_name), sizeof(m_peer_name));
|
||||
std::memcpy(packet->data + sizeof(m_peer_name), std::addressof(m_port_name), sizeof(m_port_name));
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet) + sizeof(m_peer_name) + sizeof(m_port_name);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
Result CloseTask::SetArguments(s32 handle) {
|
||||
/* Set our arguments. */
|
||||
m_handle = handle;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void CloseTask::Complete(htcs::SocketError err) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
|
||||
/* Complete. */
|
||||
HtcsTask::Complete();
|
||||
}
|
||||
|
||||
Result CloseTask::GetResult(htcs::SocketError *out_err) const {
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result CloseTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result CloseTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::Close,
|
||||
.body_size = 0,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_handle,
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
Result ConnectTask::SetArguments(s32 handle, const HtcsPeerName &peer_name, const HtcsPortName &port_name) {
|
||||
/* Set our arguments. */
|
||||
m_handle = handle;
|
||||
m_peer_name = peer_name;
|
||||
m_port_name = port_name;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void ConnectTask::Complete(htcs::SocketError err) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
|
||||
/* Complete. */
|
||||
HtcsTask::Complete();
|
||||
}
|
||||
|
||||
Result ConnectTask::GetResult(htcs::SocketError *out_err) const {
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ConnectTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ConnectTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::Connect,
|
||||
.body_size = sizeof(m_peer_name) + sizeof(m_port_name),
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_handle,
|
||||
},
|
||||
};
|
||||
std::memcpy(packet->data + 0, std::addressof(m_peer_name), sizeof(m_peer_name));
|
||||
std::memcpy(packet->data + sizeof(m_peer_name), std::addressof(m_port_name), sizeof(m_port_name));
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet) + sizeof(m_peer_name) + sizeof(m_port_name);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
Result FcntlTask::SetArguments(s32 handle, s32 command, s32 value) {
|
||||
/* Set our arguments. */
|
||||
m_handle = handle;
|
||||
m_command = command;
|
||||
m_value = value;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void FcntlTask::Complete(htcs::SocketError err, s32 res) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
m_res = res;
|
||||
|
||||
/* Complete. */
|
||||
HtcsTask::Complete();
|
||||
}
|
||||
|
||||
Result FcntlTask::GetResult(htcs::SocketError *out_err, s32 *out_res) const {
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
*out_res = m_res;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FcntlTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]), packet->params[1]);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result FcntlTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::Fcntl,
|
||||
.body_size = 0,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_handle,
|
||||
m_command,
|
||||
m_value,
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
Result ListenTask::SetArguments(s32 handle, s32 backlog) {
|
||||
/* Set our arguments. */
|
||||
m_handle = handle;
|
||||
m_backlog = backlog;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void ListenTask::Complete(htcs::SocketError err) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
|
||||
/* Complete. */
|
||||
HtcsTask::Complete();
|
||||
}
|
||||
|
||||
Result ListenTask::GetResult(htcs::SocketError *out_err) const {
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ListenTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ListenTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::Listen,
|
||||
.body_size = 0,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_handle,
|
||||
m_backlog,
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
Result ReceiveSmallTask::SetArguments(s32 handle, s64 size, htcs::MessageFlag flags) {
|
||||
/* Check that we're valid. */
|
||||
R_UNLESS(this->IsValid(), htcs::ResultInvalidTask());
|
||||
|
||||
/* Set our arguments. */
|
||||
m_handle = handle;
|
||||
m_size = size;
|
||||
m_flags = flags;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void ReceiveSmallTask::Complete(htcs::SocketError err, s64 size) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
m_result_size = size;
|
||||
|
||||
/* Complete. */
|
||||
HtcsSignalingTask::Complete();
|
||||
}
|
||||
|
||||
Result ReceiveSmallTask::GetResult(htcs::SocketError *out_err, s64 *out_size) const {
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
*out_size = m_result_size;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ReceiveSmallTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Copy the data to our buffer. */
|
||||
std::memcpy(m_buffer, packet->data, packet->body_size);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]), packet->body_size);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ReceiveSmallTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::Receive,
|
||||
.body_size = 0,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_handle,
|
||||
m_size,
|
||||
static_cast<s64>(m_flags),
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
bool ReceiveSmallTask::IsReceiveBufferRequired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
Result ReceiveTask::SetArguments(s32 handle, s64 size, htcs::MessageFlag flags) {
|
||||
/* Check that we're valid. */
|
||||
R_UNLESS(this->IsValid(), htcs::ResultInvalidTask());
|
||||
|
||||
/* Set our arguments. */
|
||||
m_handle = handle;
|
||||
m_size = size;
|
||||
m_flags = flags;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void ReceiveTask::Complete(htcs::SocketError err, s64 size) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
m_result_size = size;
|
||||
|
||||
/* Complete. */
|
||||
HtcsSignalingTask::Complete();
|
||||
}
|
||||
|
||||
Result ReceiveTask::GetResult(htcs::SocketError *out_err, s64 *out_size) const {
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
*out_size = m_result_size;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ReceiveTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]), packet->params[1]);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ReceiveTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::ReceiveLarge,
|
||||
.body_size = 0,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_handle,
|
||||
m_size,
|
||||
static_cast<s64>(m_flags),
|
||||
GetReceiveDataChannelId(task_id),
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ReceiveTask::CreateNotification(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Notification,
|
||||
.type = HtcsPacketType::ReceiveLarge,
|
||||
.body_size = 0,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
/* ... */
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
Result SelectTask::SetArguments(Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec) {
|
||||
/* Check that we're valid. */
|
||||
R_UNLESS(this->IsValid(), htcs::ResultInvalidTask());
|
||||
|
||||
/* Sanity check the spans. */
|
||||
AMS_ASSERT(read_handles.size() < static_cast<size_t>(SocketCountMax));
|
||||
AMS_ASSERT(write_handles.size() < static_cast<size_t>(SocketCountMax));
|
||||
AMS_ASSERT(exception_handles.size() < static_cast<size_t>(SocketCountMax));
|
||||
|
||||
/* Set our arguments. */
|
||||
m_read_handle_count = static_cast<s32>(read_handles.size());
|
||||
m_write_handle_count = static_cast<s32>(write_handles.size());
|
||||
m_exception_handle_count = static_cast<s32>(exception_handles.size());
|
||||
m_tv_sec = tv_sec;
|
||||
m_tv_usec = tv_usec;
|
||||
|
||||
/* Copy the handles. */
|
||||
std::memcpy(m_handles, read_handles.data(), read_handles.size_bytes());
|
||||
std::memcpy(m_handles + m_read_handle_count, write_handles.data(), write_handles.size_bytes());
|
||||
std::memcpy(m_handles + m_read_handle_count + m_write_handle_count, exception_handles.data(), exception_handles.size_bytes());
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void SelectTask::Complete(htcs::SocketError err, s32 read_handle_count, s32 write_handle_count, s32 exception_handle_count, const void *body, s64 body_size) {
|
||||
/* Sanity check the handle counts. */
|
||||
const auto handle_count = read_handle_count + write_handle_count + exception_handle_count;
|
||||
AMS_ASSERT(0 <= read_handle_count && read_handle_count < SocketCountMax);
|
||||
AMS_ASSERT(0 <= write_handle_count && write_handle_count < SocketCountMax);
|
||||
AMS_ASSERT(0 <= exception_handle_count && exception_handle_count < SocketCountMax);
|
||||
AMS_ASSERT(handle_count * static_cast<s64>(sizeof(s32)) == body_size);
|
||||
AMS_UNUSED(handle_count, body_size);
|
||||
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
m_out_read_handle_count = read_handle_count;
|
||||
m_out_write_handle_count = write_handle_count;
|
||||
m_out_exception_handle_count = exception_handle_count;
|
||||
|
||||
/* Copy the handles. */
|
||||
std::memcpy(m_out_handles, static_cast<const s32 *>(body), sizeof(s32) * read_handle_count);
|
||||
std::memcpy(m_out_handles + read_handle_count, static_cast<const s32 *>(body) + read_handle_count, sizeof(s32) * write_handle_count);
|
||||
std::memcpy(m_out_handles + read_handle_count + write_handle_count, static_cast<const s32 *>(body) + read_handle_count + write_handle_count, sizeof(s32) * exception_handle_count);
|
||||
|
||||
/* Complete. */
|
||||
HtcsSignalingTask::Complete();
|
||||
}
|
||||
|
||||
Result SelectTask::GetResult(htcs::SocketError *out_err, bool *out_empty, Span<int> read_handles, Span<int> write_handles, Span<int> exception_handles) const {
|
||||
/* Set the output error. */
|
||||
*out_err = m_err;
|
||||
|
||||
/* Set the output empty value. */
|
||||
const bool empty = m_err == HTCS_ENONE && m_out_read_handle_count == 0 && m_out_write_handle_count == 0 && m_out_exception_handle_count == 0;
|
||||
*out_empty = empty;
|
||||
|
||||
/* Clear the output spans. */
|
||||
std::fill(read_handles.begin(), read_handles.end(), 0);
|
||||
std::fill(write_handles.begin(), write_handles.end(), 0);
|
||||
std::fill(exception_handles.begin(), exception_handles.end(), 0);
|
||||
|
||||
/* Copy the handles. */
|
||||
if (m_err == HTCS_ENONE && !empty) {
|
||||
const s32 * const out_read_start = m_out_handles;
|
||||
const s32 * const out_read_end = out_read_start + m_out_read_handle_count;
|
||||
const s32 * const out_write_start = out_read_end;
|
||||
const s32 * const out_write_end = out_write_start + m_out_write_handle_count;
|
||||
const s32 * const out_exception_start = out_write_end;
|
||||
const s32 * const out_exception_end = out_exception_start + m_out_exception_handle_count;
|
||||
std::copy(out_read_start, out_read_end, read_handles.begin());
|
||||
std::copy(out_write_start, out_write_end, write_handles.begin());
|
||||
std::copy(out_exception_start, out_exception_end, exception_handles.begin());
|
||||
} else {
|
||||
const s32 * const read_start = m_handles;
|
||||
const s32 * const read_end = read_start + m_read_handle_count;
|
||||
const s32 * const write_start = read_end;
|
||||
const s32 * const write_end = write_start + m_write_handle_count;
|
||||
const s32 * const exception_start = write_end;
|
||||
const s32 * const exception_end = exception_start + m_exception_handle_count;
|
||||
std::copy(read_start, read_end, read_handles.begin());
|
||||
std::copy(write_start, write_end, write_handles.begin());
|
||||
std::copy(exception_start, exception_end, exception_handles.begin());
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SelectTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]), packet->params[1], packet->params[2], packet->params[3], packet->data, size - sizeof(*packet));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SelectTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Determine the body size. */
|
||||
const auto handle_count = m_read_handle_count + m_write_handle_count + m_exception_handle_count;
|
||||
const s64 body_size = static_cast<s64>(handle_count * sizeof(s32));
|
||||
AMS_ASSERT(sizeof(HtcsRpcPacket) + body_size <= size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::Select,
|
||||
.body_size = body_size,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_read_handle_count,
|
||||
m_write_handle_count,
|
||||
m_exception_handle_count,
|
||||
m_tv_sec,
|
||||
m_tv_usec,
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the packet body. */
|
||||
std::memcpy(packet->data, m_handles, body_size);
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet) + body_size;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
void SendSmallTask::SetBuffer(const void *buffer, s64 buffer_size) {
|
||||
/* Sanity check the buffer size. */
|
||||
AMS_ASSERT(0 <= buffer_size && buffer_size <= static_cast<s64>(sizeof(m_buffer)));
|
||||
|
||||
/* Set our buffer. */
|
||||
if (buffer_size > 0) {
|
||||
std::memcpy(m_buffer, buffer, buffer_size);
|
||||
}
|
||||
m_buffer_size = buffer_size;
|
||||
}
|
||||
|
||||
void SendSmallTask::NotifyDataChannelReady() {
|
||||
/* Notify. */
|
||||
this->Notify();
|
||||
|
||||
/* Signal our ready event. */
|
||||
m_ready_event.Signal();
|
||||
}
|
||||
|
||||
void SendSmallTask::WaitNotification() {
|
||||
/* Wait on our ready event. */
|
||||
m_ready_event.Wait();
|
||||
}
|
||||
|
||||
Result SendSmallTask::SetArguments(s32 handle, s64 size, htcs::MessageFlag flags) {
|
||||
/* Check that we're valid. */
|
||||
R_UNLESS(this->IsValid(), htcs::ResultInvalidTask());
|
||||
|
||||
/* Set our arguments. */
|
||||
m_handle = handle;
|
||||
m_size = size;
|
||||
m_flags = flags;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void SendSmallTask::Complete(htcs::SocketError err, s64 size) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
m_result_size = size;
|
||||
|
||||
/* Signal our ready event. */
|
||||
m_ready_event.Signal();
|
||||
|
||||
/* Complete. */
|
||||
HtcsSignalingTask::Complete();
|
||||
}
|
||||
|
||||
Result SendSmallTask::GetResult(htcs::SocketError *out_err, s64 *out_size) const {
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
*out_size = m_result_size;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void SendSmallTask::Cancel(htc::server::rpc::RpcTaskCancelReason reason) {
|
||||
/* Cancel the task. */
|
||||
HtcsSignalingTask::Cancel(reason);
|
||||
|
||||
/* Signal our ready event. */
|
||||
m_ready_event.Signal();
|
||||
}
|
||||
|
||||
Result SendSmallTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]), this->GetSize());
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SendSmallTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Sanity check our size. */
|
||||
AMS_ASSERT(sizeof(HtcsRpcPacket) + this->GetBufferSize() <= size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::Send,
|
||||
.body_size = this->GetSize(),
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_handle,
|
||||
m_size,
|
||||
static_cast<s64>(m_flags),
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the body. */
|
||||
if (this->GetSize() > 0) {
|
||||
std::memcpy(packet->data, this->GetBuffer(), this->GetSize());
|
||||
}
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet) + this->GetSize();
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
bool SendSmallTask::IsSendBufferRequired() {
|
||||
return this->GetSize() > 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
void SendTask::SetBuffer(const void *buffer, s64 buffer_size) {
|
||||
/* Set our buffer. */
|
||||
m_buffer = buffer;
|
||||
m_buffer_size = buffer_size;
|
||||
}
|
||||
|
||||
void SendTask::NotifyDataChannelReady() {
|
||||
/* Notify. */
|
||||
this->Notify();
|
||||
|
||||
/* Signal our ready event. */
|
||||
m_ready_event.Signal();
|
||||
}
|
||||
|
||||
void SendTask::WaitNotification() {
|
||||
/* Wait on our ready event. */
|
||||
m_ready_event.Wait();
|
||||
}
|
||||
|
||||
Result SendTask::SetArguments(s32 handle, s64 size, htcs::MessageFlag flags) {
|
||||
/* Check that we're valid. */
|
||||
R_UNLESS(this->IsValid(), htcs::ResultInvalidTask());
|
||||
|
||||
/* Set our arguments. */
|
||||
m_handle = handle;
|
||||
m_size = size;
|
||||
m_flags = flags;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void SendTask::Complete(htcs::SocketError err, s64 size) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
m_result_size = size;
|
||||
|
||||
/* Signal our ready event. */
|
||||
m_ready_event.Signal();
|
||||
|
||||
/* Complete. */
|
||||
HtcsSignalingTask::Complete();
|
||||
}
|
||||
|
||||
Result SendTask::GetResult(htcs::SocketError *out_err, s64 *out_size) const {
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
*out_size = m_result_size;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void SendTask::Cancel(htc::server::rpc::RpcTaskCancelReason reason) {
|
||||
/* Cancel the task. */
|
||||
HtcsSignalingTask::Cancel(reason);
|
||||
|
||||
/* Signal our ready event. */
|
||||
m_ready_event.Signal();
|
||||
}
|
||||
|
||||
Result SendTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]), packet->params[1]);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SendTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::SendLarge,
|
||||
.body_size = 0,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_handle,
|
||||
m_size,
|
||||
static_cast<s64>(m_flags),
|
||||
GetSendDataChannelId(task_id),
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SendTask::ProcessNotification(const char *data, size_t size) {
|
||||
AMS_UNUSED(data, size);
|
||||
|
||||
this->NotifyDataChannelReady();
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SendTask::CreateNotification(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Notification,
|
||||
.type = HtcsPacketType::SendLarge,
|
||||
.body_size = 0,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
/* ... */
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
Result ShutdownTask::SetArguments(s32 handle, ShutdownType how) {
|
||||
/* Set our arguments. */
|
||||
m_handle = handle;
|
||||
m_how = how;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void ShutdownTask::Complete(htcs::SocketError err) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
|
||||
/* Complete. */
|
||||
HtcsTask::Complete();
|
||||
}
|
||||
|
||||
Result ShutdownTask::GetResult(htcs::SocketError *out_err) const {
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ShutdownTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ShutdownTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = this->GetVersion(),
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::Shutdown,
|
||||
.body_size = 0,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
m_handle,
|
||||
static_cast<s64>(m_how),
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int MaxEventCount = 0x22;
|
||||
|
||||
constinit os::SdkMutex g_event_count_mutex;
|
||||
constinit int g_event_count = 0;
|
||||
|
||||
}
|
||||
|
||||
HtcsSignalingTask::HtcsSignalingTask(HtcsTaskType type) : HtcsTask(type), m_is_valid(false) {
|
||||
/* Acquire the exclusive right to create an event. */
|
||||
std::scoped_lock lk(g_event_count_mutex);
|
||||
|
||||
/* Create an event. */
|
||||
if (AMS_LIKELY(g_event_count < MaxEventCount)) {
|
||||
/* Make the event. */
|
||||
R_ABORT_UNLESS(os::CreateSystemEvent(std::addressof(m_system_event), os::EventClearMode_ManualClear, true));
|
||||
|
||||
/* Increment the event count. */
|
||||
++g_event_count;
|
||||
|
||||
/* Mark ourselves as valid. */
|
||||
m_is_valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
HtcsSignalingTask::~HtcsSignalingTask() {
|
||||
/* If we have an event, we need to destroy it. */
|
||||
if (AMS_LIKELY(m_is_valid)) {
|
||||
/* Acquire exclusive access to the event count. */
|
||||
std::scoped_lock lk(g_event_count_mutex);
|
||||
|
||||
/* Destroy our event. */
|
||||
os::DestroySystemEvent(std::addressof(m_system_event));
|
||||
|
||||
/* Decrement the event count. */
|
||||
if ((--g_event_count) < 0) {
|
||||
g_event_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "htcs_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
namespace {
|
||||
|
||||
constinit s16 g_protocol_version = HtcsMaxVersion;
|
||||
|
||||
}
|
||||
|
||||
HtcsTask::HtcsTask(HtcsTaskType type) : m_task_type(type), m_version(g_protocol_version) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
Result SocketTask::SetArguments() {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void SocketTask::Complete(htcs::SocketError err, s32 desc) {
|
||||
/* Set our results. */
|
||||
m_err = err;
|
||||
m_desc = desc;
|
||||
|
||||
/* Complete. */
|
||||
HtcsTask::Complete();
|
||||
}
|
||||
|
||||
Result SocketTask::GetResult(htcs::SocketError *out_err, s32 *out_desc) const {
|
||||
/* Sanity check our state. */
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
|
||||
/* Set the output. */
|
||||
*out_err = m_err;
|
||||
*out_desc = m_desc;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SocketTask::ProcessResponse(const char *data, size_t size) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Convert the input to a packet. */
|
||||
auto *packet = reinterpret_cast<const HtcsRpcPacket *>(data);
|
||||
|
||||
/* Update the global protocol version. */
|
||||
g_protocol_version = std::min(g_protocol_version, packet->version);
|
||||
|
||||
/* Complete the task. */
|
||||
this->Complete(static_cast<htcs::SocketError>(packet->params[0]), packet->params[1]);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SocketTask::CreateRequest(size_t *out, char *data, size_t size, u32 task_id) {
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Create the packet. */
|
||||
auto *packet = reinterpret_cast<HtcsRpcPacket *>(data);
|
||||
*packet = {
|
||||
.protocol = HtcsProtocol,
|
||||
.version = 3,
|
||||
.category = HtcsPacketCategory::Request,
|
||||
.type = HtcsPacketType::Socket,
|
||||
.body_size = 0,
|
||||
.task_id = task_id,
|
||||
.params = {
|
||||
/* ... */
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the output size. */
|
||||
*out = sizeof(*packet);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,473 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 "../../../htc/server/rpc/htc_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htcs::impl::rpc {
|
||||
|
||||
enum class HtcsTaskType {
|
||||
Receive = 0,
|
||||
Send = 1,
|
||||
Shutdown = 2,
|
||||
Close = 3,
|
||||
Connect = 4,
|
||||
Listen = 5,
|
||||
Accept = 6,
|
||||
Socket = 7,
|
||||
Bind = 8,
|
||||
Fcntl = 9,
|
||||
ReceiveSmall = 10,
|
||||
SendSmall = 11,
|
||||
Select = 12,
|
||||
};
|
||||
|
||||
constexpr inline s16 HtcsProtocol = 5;
|
||||
constexpr inline const s16 HtcsMaxVersion = 4;
|
||||
|
||||
enum class HtcsPacketCategory : s16 {
|
||||
Request = 0,
|
||||
Response = 1,
|
||||
Notification = 2,
|
||||
};
|
||||
|
||||
enum class HtcsPacketType : s16 {
|
||||
Receive = 32,
|
||||
Send = 33,
|
||||
Shutdown = 34,
|
||||
Close = 35,
|
||||
Connect = 36,
|
||||
Listen = 37,
|
||||
Accept = 38,
|
||||
Socket = 39,
|
||||
Bind = 40,
|
||||
Fcntl = 41,
|
||||
ReceiveLarge = 42,
|
||||
SendLarge = 43,
|
||||
Select = 44,
|
||||
};
|
||||
|
||||
struct HtcsRpcPacket {
|
||||
s16 protocol;
|
||||
s16 version;
|
||||
HtcsPacketCategory category;
|
||||
HtcsPacketType type;
|
||||
s64 body_size;
|
||||
u32 task_id{};
|
||||
s64 params[5];
|
||||
char data[];
|
||||
};
|
||||
static_assert(sizeof(HtcsRpcPacket) == 0x40);
|
||||
|
||||
constexpr inline u16 ReceiveDataChannelIdBegin = htc::server::rpc::MaxRpcCount;
|
||||
constexpr inline u16 ReceiveDataChannelIdEnd = ReceiveDataChannelIdBegin + htc::server::rpc::MaxRpcCount;
|
||||
static_assert(ReceiveDataChannelIdEnd - ReceiveDataChannelIdBegin == htc::server::rpc::MaxRpcCount);
|
||||
|
||||
constexpr inline u16 SendDataChannelIdBegin = ReceiveDataChannelIdEnd;
|
||||
constexpr inline u16 SendDataChannelIdEnd = SendDataChannelIdBegin + htc::server::rpc::MaxRpcCount;
|
||||
static_assert(SendDataChannelIdEnd - SendDataChannelIdBegin == htc::server::rpc::MaxRpcCount);
|
||||
|
||||
constexpr inline u16 GetReceiveDataChannelId(u32 task_id) {
|
||||
const u16 channel_id = task_id + ReceiveDataChannelIdBegin;
|
||||
AMS_ASSERT(ReceiveDataChannelIdBegin <= channel_id && channel_id < ReceiveDataChannelIdEnd);
|
||||
|
||||
return channel_id;
|
||||
}
|
||||
|
||||
constexpr inline u16 GetSendDataChannelId(u32 task_id) {
|
||||
const u16 channel_id = task_id + SendDataChannelIdBegin;
|
||||
AMS_ASSERT(SendDataChannelIdBegin <= channel_id && channel_id < SendDataChannelIdEnd);
|
||||
|
||||
return channel_id;
|
||||
}
|
||||
|
||||
class HtcsTask : public htc::server::rpc::Task {
|
||||
private:
|
||||
HtcsTaskType m_task_type;
|
||||
s16 m_version;
|
||||
public:
|
||||
HtcsTask(HtcsTaskType type); /* Defined in socket_task.cpp, for namespacing reasons. */
|
||||
|
||||
HtcsTaskType GetTaskType() const { return m_task_type; }
|
||||
s16 GetVersion() const { return m_version; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
concept IsHtcsTask = std::derived_from<T, HtcsTask>;
|
||||
|
||||
class HtcsSignalingTask : public HtcsTask {
|
||||
private:
|
||||
os::SystemEventType m_system_event;
|
||||
bool m_is_valid;
|
||||
public:
|
||||
HtcsSignalingTask(HtcsTaskType type);
|
||||
virtual ~HtcsSignalingTask();
|
||||
|
||||
bool IsValid() const { return m_is_valid; }
|
||||
|
||||
void Complete() {
|
||||
os::SignalSystemEvent(std::addressof(m_system_event));
|
||||
HtcsTask::Complete();
|
||||
}
|
||||
public:
|
||||
virtual void Cancel(htc::server::rpc::RpcTaskCancelReason reason) override {
|
||||
HtcsTask::Cancel(reason);
|
||||
os::SignalSystemEvent(std::addressof(m_system_event));
|
||||
}
|
||||
|
||||
virtual os::SystemEventType *GetSystemEvent() override { return std::addressof(m_system_event); }
|
||||
};
|
||||
|
||||
class ReceiveTask : public HtcsSignalingTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::Receive;
|
||||
private:
|
||||
s32 m_handle;
|
||||
s64 m_size;
|
||||
htcs::MessageFlag m_flags;
|
||||
void *m_buffer;
|
||||
s64 m_buffer_size;
|
||||
htcs::SocketError m_err;
|
||||
s64 m_result_size;
|
||||
public:
|
||||
ReceiveTask() : HtcsSignalingTask(TaskType) { /* ... */ }
|
||||
|
||||
s32 GetHandle() const { return m_handle; }
|
||||
s64 GetSize() const { return m_size; }
|
||||
htcs::MessageFlag GetFlags() const { return m_flags; }
|
||||
void *GetBuffer() const { return m_buffer; }
|
||||
s64 GetBufferSize() const { return m_buffer_size; }
|
||||
|
||||
s64 GetResultSize() const {
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
return m_result_size;
|
||||
}
|
||||
public:
|
||||
Result SetArguments(s32 handle, s64 size, htcs::MessageFlag flags);
|
||||
void Complete(htcs::SocketError err, s64 size);
|
||||
Result GetResult(htcs::SocketError *out_err, s64 *out_size) const;
|
||||
public:
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
virtual Result CreateNotification(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
};
|
||||
|
||||
class SendTask : public HtcsSignalingTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::Send;
|
||||
private:
|
||||
os::Event m_ready_event;
|
||||
s32 m_handle;
|
||||
s64 m_size;
|
||||
htcs::MessageFlag m_flags;
|
||||
const void *m_buffer;
|
||||
s64 m_buffer_size;
|
||||
htcs::SocketError m_err;
|
||||
s64 m_result_size;
|
||||
public:
|
||||
SendTask() : HtcsSignalingTask(TaskType), m_ready_event(os::EventClearMode_ManualClear) { /* ... */ }
|
||||
|
||||
s32 GetHandle() const { return m_handle; }
|
||||
s64 GetSize() const { return m_size; }
|
||||
htcs::MessageFlag GetFlags() const { return m_flags; }
|
||||
const void *GetBuffer() const { return m_buffer; }
|
||||
s64 GetBufferSize() const { return m_buffer_size; }
|
||||
|
||||
void SetBuffer(const void *buffer, s64 buffer_size);
|
||||
void NotifyDataChannelReady();
|
||||
void WaitNotification();
|
||||
public:
|
||||
Result SetArguments(s32 handle, s64 size, htcs::MessageFlag flags);
|
||||
void Complete(htcs::SocketError err, s64 size);
|
||||
Result GetResult(htcs::SocketError *out_err, s64 *out_size) const;
|
||||
public:
|
||||
virtual void Cancel(htc::server::rpc::RpcTaskCancelReason reason) override;
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
virtual Result ProcessNotification(const char *data, size_t size) override;
|
||||
virtual Result CreateNotification(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
};
|
||||
|
||||
class ShutdownTask : public HtcsTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::Shutdown;
|
||||
private:
|
||||
s32 m_handle;
|
||||
ShutdownType m_how;
|
||||
htcs::SocketError m_err;
|
||||
public:
|
||||
ShutdownTask() : HtcsTask(TaskType) { /* ... */ }
|
||||
|
||||
s32 GetHandle() const { return m_handle; }
|
||||
ShutdownType GetHow() const { return m_how; }
|
||||
public:
|
||||
Result SetArguments(s32 handle, ShutdownType how);
|
||||
void Complete(htcs::SocketError err);
|
||||
Result GetResult(htcs::SocketError *out_err) const;
|
||||
public:
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
};
|
||||
|
||||
class CloseTask : public HtcsTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::Close;
|
||||
private:
|
||||
s32 m_handle;
|
||||
htcs::SocketError m_err;
|
||||
public:
|
||||
CloseTask() : HtcsTask(TaskType) { /* ... */ }
|
||||
|
||||
s32 GetHandle() const { return m_handle; }
|
||||
public:
|
||||
Result SetArguments(s32 handle);
|
||||
void Complete(htcs::SocketError err);
|
||||
Result GetResult(htcs::SocketError *out_err) const;
|
||||
public:
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
};
|
||||
|
||||
class ConnectTask : public HtcsTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::Connect;
|
||||
private:
|
||||
s32 m_handle;
|
||||
HtcsPeerName m_peer_name;
|
||||
HtcsPortName m_port_name;
|
||||
htcs::SocketError m_err;
|
||||
public:
|
||||
ConnectTask() : HtcsTask(TaskType) { /* ... */ }
|
||||
|
||||
s32 GetHandle() const { return m_handle; }
|
||||
const HtcsPeerName &GetPeerName() const { return m_peer_name; }
|
||||
const HtcsPortName &GetPortName() const { return m_port_name; }
|
||||
public:
|
||||
Result SetArguments(s32 handle, const HtcsPeerName &peer_name, const HtcsPortName &port_name);
|
||||
void Complete(htcs::SocketError err);
|
||||
Result GetResult(htcs::SocketError *out_err) const;
|
||||
public:
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
};
|
||||
|
||||
class ListenTask : public HtcsTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::Listen;
|
||||
private:
|
||||
s32 m_handle;
|
||||
s32 m_backlog;
|
||||
htcs::SocketError m_err;
|
||||
public:
|
||||
ListenTask() : HtcsTask(TaskType) { /* ... */ }
|
||||
|
||||
s32 GetHandle() const { return m_handle; }
|
||||
s32 GetBacklog() const { return m_backlog; }
|
||||
public:
|
||||
Result SetArguments(s32 handle, s32 backlog);
|
||||
void Complete(htcs::SocketError err);
|
||||
Result GetResult(htcs::SocketError *out_err) const;
|
||||
public:
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
};
|
||||
|
||||
class AcceptTask : public HtcsSignalingTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::Accept;
|
||||
private:
|
||||
s32 m_server_handle;
|
||||
htcs::SocketError m_err;
|
||||
s32 m_desc;
|
||||
public:
|
||||
AcceptTask() : HtcsSignalingTask(TaskType) { /* ... */ }
|
||||
|
||||
s32 GetServerHandle() const { return m_server_handle; }
|
||||
public:
|
||||
Result SetArguments(s32 server_handle);
|
||||
void Complete(htcs::SocketError err, s32 desc);
|
||||
Result GetResult(htcs::SocketError *out_err, s32 *out_desc, s32 server_handle) const;
|
||||
public:
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
};
|
||||
|
||||
class SocketTask : public HtcsTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::Socket;
|
||||
private:
|
||||
htcs::SocketError m_err;
|
||||
s32 m_desc;
|
||||
public:
|
||||
SocketTask() : HtcsTask(TaskType) { /* ... */ }
|
||||
public:
|
||||
Result SetArguments();
|
||||
void Complete(htcs::SocketError err, s32 desc);
|
||||
Result GetResult(htcs::SocketError *out_err, s32 *out_desc) const;
|
||||
public:
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
};
|
||||
|
||||
class BindTask : public HtcsTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::Bind;
|
||||
private:
|
||||
s32 m_handle;
|
||||
HtcsPeerName m_peer_name;
|
||||
HtcsPortName m_port_name;
|
||||
htcs::SocketError m_err;
|
||||
public:
|
||||
BindTask() : HtcsTask(TaskType) { /* ... */ }
|
||||
|
||||
s32 GetHandle() const { return m_handle; }
|
||||
const HtcsPeerName &GetPeerName() const { return m_peer_name; }
|
||||
const HtcsPortName &GetPortName() const { return m_port_name; }
|
||||
public:
|
||||
Result SetArguments(s32 handle, const HtcsPeerName &peer_name, const HtcsPortName &port_name);
|
||||
void Complete(htcs::SocketError err);
|
||||
Result GetResult(htcs::SocketError *out_err) const;
|
||||
public:
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
};
|
||||
|
||||
class FcntlTask : public HtcsTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::Fcntl;
|
||||
private:
|
||||
s32 m_handle;
|
||||
s32 m_command;
|
||||
s32 m_value;
|
||||
htcs::SocketError m_err;
|
||||
s32 m_res;
|
||||
public:
|
||||
FcntlTask() : HtcsTask(TaskType) { /* ... */ }
|
||||
|
||||
s32 GetHandle() const { return m_handle; }
|
||||
s32 GetCommand() const { return m_command; }
|
||||
s32 GetValue() const { return m_value; }
|
||||
public:
|
||||
Result SetArguments(s32 handle, s32 command, s32 value);
|
||||
void Complete(htcs::SocketError err, s32 res);
|
||||
Result GetResult(htcs::SocketError *out_err, s32 *out_res) const;
|
||||
public:
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
};
|
||||
|
||||
class ReceiveSmallTask : public HtcsSignalingTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::ReceiveSmall;
|
||||
private:
|
||||
s32 m_handle;
|
||||
s64 m_size;
|
||||
htcs::MessageFlag m_flags;
|
||||
char m_buffer[0xE000];
|
||||
htcs::SocketError m_err;
|
||||
s64 m_result_size;
|
||||
public:
|
||||
ReceiveSmallTask() : HtcsSignalingTask(TaskType) { /* ... */ }
|
||||
|
||||
s32 GetHandle() const { return m_handle; }
|
||||
s64 GetSize() const { return m_size; }
|
||||
htcs::MessageFlag GetFlags() const { return m_flags; }
|
||||
void *GetBuffer() { return m_buffer; }
|
||||
s64 GetBufferSize() const { return static_cast<s64>(sizeof(m_buffer)); }
|
||||
|
||||
s64 GetResultSize() const {
|
||||
AMS_ASSERT(this->GetTaskState() == htc::server::rpc::RpcTaskState::Completed);
|
||||
return m_result_size;
|
||||
}
|
||||
public:
|
||||
Result SetArguments(s32 handle, s64 size, htcs::MessageFlag flags);
|
||||
void Complete(htcs::SocketError err, s64 size);
|
||||
Result GetResult(htcs::SocketError *out_err, s64 *out_size) const;
|
||||
public:
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
virtual bool IsReceiveBufferRequired() override;
|
||||
};
|
||||
|
||||
class SendSmallTask : public HtcsSignalingTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::SendSmall;
|
||||
private:
|
||||
os::Event m_ready_event;
|
||||
s32 m_handle;
|
||||
s64 m_size;
|
||||
htcs::MessageFlag m_flags;
|
||||
char m_buffer[0xE000];
|
||||
s64 m_buffer_size;
|
||||
htcs::SocketError m_err;
|
||||
s64 m_result_size;
|
||||
public:
|
||||
SendSmallTask() : HtcsSignalingTask(TaskType), m_ready_event(os::EventClearMode_ManualClear) { /* ... */ }
|
||||
|
||||
s32 GetHandle() const { return m_handle; }
|
||||
s64 GetSize() const { return m_size; }
|
||||
htcs::MessageFlag GetFlags() const { return m_flags; }
|
||||
void *GetBuffer() { return m_buffer; }
|
||||
s64 GetBufferSize() const { return m_buffer_size; }
|
||||
|
||||
void SetBuffer(const void *buffer, s64 buffer_size);
|
||||
void NotifyDataChannelReady();
|
||||
void WaitNotification();
|
||||
public:
|
||||
Result SetArguments(s32 handle, s64 size, htcs::MessageFlag flags);
|
||||
void Complete(htcs::SocketError err, s64 size);
|
||||
Result GetResult(htcs::SocketError *out_err, s64 *out_size) const;
|
||||
public:
|
||||
virtual void Cancel(htc::server::rpc::RpcTaskCancelReason reason) override;
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
virtual bool IsSendBufferRequired() override;
|
||||
};
|
||||
|
||||
class SelectTask : public HtcsSignalingTask {
|
||||
public:
|
||||
static constexpr inline HtcsTaskType TaskType = HtcsTaskType::Select;
|
||||
private:
|
||||
s32 m_handles[SocketCountMax * 3];
|
||||
s32 m_read_handle_count;
|
||||
s32 m_write_handle_count;
|
||||
s32 m_exception_handle_count;
|
||||
s64 m_tv_sec;
|
||||
s64 m_tv_usec;
|
||||
htcs::SocketError m_err;
|
||||
s32 m_out_handles[SocketCountMax * 3];
|
||||
s32 m_out_read_handle_count;
|
||||
s32 m_out_write_handle_count;
|
||||
s32 m_out_exception_handle_count;
|
||||
public:
|
||||
SelectTask() : HtcsSignalingTask(TaskType) { /* ... */ }
|
||||
|
||||
const s32 *GetHandles() const { return m_handles; }
|
||||
s32 GetReadHandleCount() const { return m_read_handle_count; }
|
||||
s32 GetWriteHandleCount() const { return m_write_handle_count; }
|
||||
s32 GetExceptionHandleCount() const { return m_exception_handle_count; }
|
||||
s64 GetTimeoutSeconds() const { return m_tv_sec; }
|
||||
s64 GetTimeoutMicroSeconds() const { return m_tv_usec; }
|
||||
public:
|
||||
Result SetArguments(Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec);
|
||||
void Complete(htcs::SocketError err, s32 read_handle_count, s32 write_handle_count, s32 exception_handle_count, const void *body, s64 body_size);
|
||||
Result GetResult(htcs::SocketError *out_err, bool *out_empty, Span<int> read_handles, Span<int> write_handles, Span<int> exception_handles) const;
|
||||
public:
|
||||
virtual Result ProcessResponse(const char *data, size_t size) override;
|
||||
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user