2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-04-14 02:48:37 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "core/hle/kernel/k_client_session.h"
|
|
|
|
#include "core/hle/kernel/k_server_session.h"
|
|
|
|
#include "core/hle/kernel/slab_helpers.h"
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-06-05 04:26:48 +02:00
|
|
|
class SessionRequestManager;
|
|
|
|
|
2021-04-14 02:48:37 +02:00
|
|
|
class KSession final : public KAutoObjectWithSlabHeapAndContainer<KSession, KAutoObjectWithList> {
|
|
|
|
KERNEL_AUTOOBJECT_TRAITS(KSession, KAutoObject);
|
|
|
|
|
|
|
|
public:
|
2021-05-08 18:11:36 +02:00
|
|
|
explicit KSession(KernelCore& kernel_);
|
2021-05-29 08:49:07 +02:00
|
|
|
~KSession() override;
|
2021-04-14 02:48:37 +02:00
|
|
|
|
2021-06-05 04:26:48 +02:00
|
|
|
void Initialize(KClientPort* port_, const std::string& name_,
|
|
|
|
std::shared_ptr<SessionRequestManager> manager_ = nullptr);
|
2021-04-14 02:48:37 +02:00
|
|
|
|
2021-05-29 08:49:07 +02:00
|
|
|
void Finalize() override;
|
2021-04-14 02:48:37 +02:00
|
|
|
|
2021-05-29 08:49:07 +02:00
|
|
|
bool IsInitialized() const override {
|
2021-04-14 02:48:37 +02:00
|
|
|
return initialized;
|
|
|
|
}
|
|
|
|
|
2021-05-29 08:49:07 +02:00
|
|
|
uintptr_t GetPostDestroyArgument() const override {
|
2021-04-14 02:48:37 +02:00
|
|
|
return reinterpret_cast<uintptr_t>(process);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PostDestroy(uintptr_t arg);
|
|
|
|
|
|
|
|
void OnServerClosed();
|
|
|
|
|
|
|
|
void OnClientClosed();
|
|
|
|
|
|
|
|
bool IsServerClosed() const {
|
|
|
|
return this->GetState() != State::Normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsClientClosed() const {
|
|
|
|
return this->GetState() != State::Normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
KClientSession& GetClientSession() {
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
KServerSession& GetServerSession() {
|
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
|
|
|
const KClientSession& GetClientSession() const {
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
const KServerSession& GetServerSession() const {
|
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
2021-04-22 06:43:25 +02:00
|
|
|
const KClientPort* GetParent() const {
|
2021-04-14 02:48:37 +02:00
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
2021-05-16 08:49:03 +02:00
|
|
|
KClientPort* GetParent() {
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:48:41 +02:00
|
|
|
private:
|
|
|
|
enum class State : u8 {
|
|
|
|
Invalid = 0,
|
|
|
|
Normal = 1,
|
|
|
|
ClientClosed = 2,
|
|
|
|
ServerClosed = 3,
|
|
|
|
};
|
|
|
|
|
2021-04-14 02:48:37 +02:00
|
|
|
void SetState(State state) {
|
|
|
|
atomic_state = static_cast<u8>(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
State GetState() const {
|
2021-05-01 21:48:41 +02:00
|
|
|
return static_cast<State>(atomic_state.load(std::memory_order_relaxed));
|
2021-04-14 02:48:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KServerSession server;
|
|
|
|
KClientSession client;
|
2021-05-01 21:48:41 +02:00
|
|
|
std::atomic<std::underlying_type_t<State>> atomic_state{
|
|
|
|
static_cast<std::underlying_type_t<State>>(State::Invalid)};
|
2021-04-22 06:43:25 +02:00
|
|
|
KClientPort* port{};
|
2021-04-24 07:04:28 +02:00
|
|
|
KProcess* process{};
|
2021-04-14 02:48:37 +02:00
|
|
|
bool initialized{};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Kernel
|