Refactor out the wakeup_callback function pointer

This commit is contained in:
Hamish Milne 2020-01-06 20:03:40 +00:00 committed by zhupengfei
parent 7019561fd5
commit 116d22d562
24 changed files with 533 additions and 295 deletions

View file

@ -71,12 +71,7 @@ void File::Read(Kernel::HLERequestContext& ctx) {
rb.PushMappedBuffer(buffer);
std::chrono::nanoseconds read_timeout_ns{backend->GetReadDelayNs(length)};
ctx.SleepClientThread("file::read", read_timeout_ns,
[](std::shared_ptr<Kernel::Thread> /*thread*/,
Kernel::HLERequestContext& /*ctx*/,
Kernel::ThreadWakeupReason /*reason*/) {
// Nothing to do here
});
ctx.SleepClientThread("file::read", read_timeout_ns, nullptr);
}
void File::Write(Kernel::HLERequestContext& ctx) {

View file

@ -76,12 +76,7 @@ void FS_USER::OpenFile(Kernel::HLERequestContext& ctx) {
LOG_ERROR(Service_FS, "failed to get a handle for file {}", file_path.DebugStr());
}
ctx.SleepClientThread("fs_user::open", open_timeout_ns,
[](std::shared_ptr<Kernel::Thread> /*thread*/,
Kernel::HLERequestContext& /*ctx*/,
Kernel::ThreadWakeupReason /*reason*/) {
// Nothing to do here
});
ctx.SleepClientThread("fs_user::open", open_timeout_ns, nullptr);
}
void FS_USER::OpenFileDirectly(Kernel::HLERequestContext& ctx) {
@ -134,12 +129,7 @@ void FS_USER::OpenFileDirectly(Kernel::HLERequestContext& ctx) {
file_path.DebugStr(), mode.hex, attributes);
}
ctx.SleepClientThread("fs_user::open_directly", open_timeout_ns,
[](std::shared_ptr<Kernel::Thread> /*thread*/,
Kernel::HLERequestContext& /*ctx*/,
Kernel::ThreadWakeupReason /*reason*/) {
// Nothing to do here
});
ctx.SleepClientThread("fs_user::open_directly", open_timeout_ns, nullptr);
}
void FS_USER::DeleteFile(Kernel::HLERequestContext& ctx) {

View file

@ -1170,6 +1170,29 @@ void NWM_UDS::GetChannel(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_NWM, "called");
}
class NWM_UDS::ThreadCallback : public Kernel::HLERequestContext::WakeupCallback {
public:
ThreadCallback(u16 command_id_) : command_id(command_id_) {}
void WakeUp(std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx,
Kernel::ThreadWakeupReason reason) {
// TODO(B3N30): Add error handling for host full and timeout
IPC::RequestBuilder rb(ctx, command_id, 1, 0);
rb.Push(RESULT_SUCCESS);
LOG_DEBUG(Service_NWM, "connection sequence finished");
}
private:
ThreadCallback() = default;
u16 command_id;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& command_id;
}
friend class boost::serialization::access;
};
void NWM_UDS::ConnectToNetwork(Kernel::HLERequestContext& ctx, u16 command_id,
const u8* network_info_buffer, std::size_t network_info_size,
u8 connection_type, std::vector<u8> passphrase) {
@ -1183,15 +1206,8 @@ void NWM_UDS::ConnectToNetwork(Kernel::HLERequestContext& ctx, u16 command_id,
// Since this timing is handled by core_timing it could differ from the 'real world' time
static constexpr std::chrono::nanoseconds UDSConnectionTimeout{300000000};
connection_event = ctx.SleepClientThread(
"uds::ConnectToNetwork", UDSConnectionTimeout,
[command_id](std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx,
Kernel::ThreadWakeupReason reason) {
// TODO(B3N30): Add error handling for host full and timeout
IPC::RequestBuilder rb(ctx, command_id, 1, 0);
rb.Push(RESULT_SUCCESS);
LOG_DEBUG(Service_NWM, "connection sequence finished");
});
connection_event = ctx.SleepClientThread("uds::ConnectToNetwork", UDSConnectionTimeout,
std::make_shared<ThreadCallback>(command_id));
}
void NWM_UDS::ConnectToNetwork(Kernel::HLERequestContext& ctx) {
@ -1418,3 +1434,5 @@ NWM_UDS::~NWM_UDS() {
}
} // namespace Service::NWM
SERIALIZE_EXPORT_IMPL(Service::NWM::NWM_UDS::ThreadCallback)

View file

@ -15,6 +15,7 @@
#include <unordered_map>
#include <vector>
#include <boost/optional.hpp>
#include <boost/serialization/export.hpp>
#include "common/common_types.h"
#include "common/swap.h"
#include "core/hle/service/service.h"
@ -127,6 +128,8 @@ public:
explicit NWM_UDS(Core::System& system);
~NWM_UDS();
class ThreadCallback;
private:
Core::System& system;
@ -560,3 +563,4 @@ private:
SERVICE_CONSTRUCT(Service::NWM::NWM_UDS)
BOOST_CLASS_EXPORT_KEY(Service::NWM::NWM_UDS)
BOOST_CLASS_EXPORT_KEY(Service::NWM::NWM_UDS::ThreadCallback)

View file

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <tuple>
#include "common/archives.h"
#include "common/common_types.h"
#include "common/logging/log.h"
#include "core/core.h"
@ -71,6 +72,46 @@ void SRV::EnableNotification(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_SRV, "(STUBBED) called");
}
class SRV::ThreadCallback : public Kernel::HLERequestContext::WakeupCallback {
public:
ThreadCallback(Core::System& system_, std::string name_) : system(system_), name(name_) {}
void WakeUp(std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx,
Kernel::ThreadWakeupReason reason) {
LOG_ERROR(Service_SRV, "called service={} wakeup", name);
auto client_port = system.ServiceManager().GetServicePort(name);
auto session = client_port.Unwrap()->Connect();
if (session.Succeeded()) {
LOG_DEBUG(Service_SRV, "called service={} -> session={}", name,
(*session)->GetObjectId());
IPC::RequestBuilder rb(ctx, 0x5, 1, 2);
rb.Push(session.Code());
rb.PushMoveObjects(std::move(session).Unwrap());
} else if (session.Code() == Kernel::ERR_MAX_CONNECTIONS_REACHED) {
LOG_ERROR(Service_SRV, "called service={} -> ERR_MAX_CONNECTIONS_REACHED", name);
UNREACHABLE();
} else {
LOG_ERROR(Service_SRV, "called service={} -> error 0x{:08X}", name, session.Code().raw);
IPC::RequestBuilder rb(ctx, 0x5, 1, 0);
rb.Push(session.Code());
}
}
private:
Core::System& system;
std::string name;
ThreadCallback() : system(Core::Global<Core::System>()) {}
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& name;
}
friend class boost::serialization::access;
};
/**
* SRV::GetServiceHandle service function
* Inputs:
@ -100,28 +141,7 @@ void SRV::GetServiceHandle(Kernel::HLERequestContext& ctx) {
// TODO(yuriks): Permission checks go here
auto get_handle = [name, this](std::shared_ptr<Kernel::Thread> thread,
Kernel::HLERequestContext& ctx,
Kernel::ThreadWakeupReason reason) {
LOG_ERROR(Service_SRV, "called service={} wakeup", name);
auto client_port = system.ServiceManager().GetServicePort(name);
auto session = client_port.Unwrap()->Connect();
if (session.Succeeded()) {
LOG_DEBUG(Service_SRV, "called service={} -> session={}", name,
(*session)->GetObjectId());
IPC::RequestBuilder rb(ctx, 0x5, 1, 2);
rb.Push(session.Code());
rb.PushMoveObjects(std::move(session).Unwrap());
} else if (session.Code() == Kernel::ERR_MAX_CONNECTIONS_REACHED) {
LOG_ERROR(Service_SRV, "called service={} -> ERR_MAX_CONNECTIONS_REACHED", name);
UNREACHABLE();
} else {
LOG_ERROR(Service_SRV, "called service={} -> error 0x{:08X}", name, session.Code().raw);
IPC::RequestBuilder rb(ctx, 0x5, 1, 0);
rb.Push(session.Code());
}
};
auto get_handle = std::make_shared<ThreadCallback>(system, name);
auto client_port = system.ServiceManager().GetServicePort(name);
if (client_port.Failed()) {
@ -266,3 +286,5 @@ SRV::SRV(Core::System& system) : ServiceFramework("srv:", 4), system(system) {
SRV::~SRV() = default;
} // namespace Service::SM
SERIALIZE_EXPORT_IMPL(Service::SM::SRV::ThreadCallback)

View file

@ -6,6 +6,7 @@
#include <memory>
#include <unordered_map>
#include <boost/serialization/export.hpp>
#include "core/hle/service/service.h"
namespace Core {
@ -25,6 +26,8 @@ public:
explicit SRV(Core::System& system);
~SRV();
class ThreadCallback;
private:
void RegisterClient(Kernel::HLERequestContext& ctx);
void EnableNotification(Kernel::HLERequestContext& ctx);
@ -40,3 +43,5 @@ private:
};
} // namespace Service::SM
BOOST_CLASS_EXPORT_KEY(Service::SM::SRV::ThreadCallback)