mirror of https://git.suyu.dev/suyu/suyu
hle: kernel: Migrate KPort, KClientPort, and KServerPort to KAutoObject.
parent
7a06864100
commit
626f746971
@ -0,0 +1,68 @@
|
|||||||
|
// Copyright 2021 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "core/hle/kernel/hle_ipc.h"
|
||||||
|
#include "core/hle/kernel/k_port.h"
|
||||||
|
#include "core/hle/kernel/k_scheduler.h"
|
||||||
|
#include "core/hle/kernel/svc_results.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
KPort::KPort(KernelCore& kernel)
|
||||||
|
: KAutoObjectWithSlabHeapAndContainer{kernel}, server{kernel}, client{kernel} {}
|
||||||
|
|
||||||
|
KPort::~KPort() = default;
|
||||||
|
|
||||||
|
void KPort::Initialize(s32 max_sessions_, bool is_light_, const std::string& name_) {
|
||||||
|
// Open a new reference count to the initialized port.
|
||||||
|
Open();
|
||||||
|
|
||||||
|
// Create and initialize our server/client pair.
|
||||||
|
KAutoObject::Create(std::addressof(server));
|
||||||
|
KAutoObject::Create(std::addressof(client));
|
||||||
|
server.Initialize(this, name_ + ":Server");
|
||||||
|
client.Initialize(this, max_sessions_, name_ + ":Client");
|
||||||
|
|
||||||
|
// Set our member variables.
|
||||||
|
is_light = is_light_;
|
||||||
|
name = name_;
|
||||||
|
state = State::Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPort::OnClientClosed() {
|
||||||
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
|
if (state == State::Normal) {
|
||||||
|
state = State::ClientClosed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KPort::OnServerClosed() {
|
||||||
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
|
if (state == State::Normal) {
|
||||||
|
state = State::ServerClosed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KPort::IsServerClosed() const {
|
||||||
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
return state == State::ServerClosed;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultCode KPort::EnqueueSession(KServerSession* session) {
|
||||||
|
KScopedSchedulerLock sl{kernel};
|
||||||
|
|
||||||
|
R_UNLESS(state == State::Normal, ResultPortClosed);
|
||||||
|
|
||||||
|
if (server.HasHLEHandler()) {
|
||||||
|
server.GetHLEHandler()->ClientConnected(session);
|
||||||
|
} else {
|
||||||
|
server.EnqueueSession(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Kernel
|
@ -0,0 +1,87 @@
|
|||||||
|
// Copyright 2021 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "common/common_types.h"
|
||||||
|
#include "core/hle/kernel/k_client_port.h"
|
||||||
|
#include "core/hle/kernel/k_server_port.h"
|
||||||
|
#include "core/hle/kernel/slab_helpers.h"
|
||||||
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KServerSession;
|
||||||
|
|
||||||
|
class KPort final : public KAutoObjectWithSlabHeapAndContainer<KPort, KAutoObjectWithList> {
|
||||||
|
KERNEL_AUTOOBJECT_TRAITS(KPort, KAutoObject);
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit KPort(KernelCore& kernel);
|
||||||
|
virtual ~KPort();
|
||||||
|
|
||||||
|
static void PostDestroy([[maybe_unused]] uintptr_t arg) {}
|
||||||
|
|
||||||
|
void Initialize(s32 max_sessions_, bool is_light_, const std::string& name_);
|
||||||
|
void OnClientClosed();
|
||||||
|
void OnServerClosed();
|
||||||
|
|
||||||
|
bool IsLight() const {
|
||||||
|
return is_light;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsServerClosed() const;
|
||||||
|
|
||||||
|
ResultCode EnqueueSession(KServerSession* session);
|
||||||
|
|
||||||
|
KClientPort& GetClientPort() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
KServerPort& GetServerPort() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
const KClientPort& GetClientPort() const {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
const KServerPort& GetServerPort() const {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DEPRECATED
|
||||||
|
|
||||||
|
friend class ServerPort;
|
||||||
|
std::string GetTypeName() const override {
|
||||||
|
return "Port";
|
||||||
|
}
|
||||||
|
std::string GetName() const override {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
HandleType GetHandleType() const override {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void Finalize() override {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class State : u8 {
|
||||||
|
Invalid = 0,
|
||||||
|
Normal = 1,
|
||||||
|
ClientClosed = 2,
|
||||||
|
ServerClosed = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
KServerPort server;
|
||||||
|
KClientPort client;
|
||||||
|
State state{State::Invalid};
|
||||||
|
bool is_light{};
|
||||||
|
|
||||||
|
std::string name; ///< Name of client port (optional)
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Kernel
|
Loading…
Reference in New Issue