2022-04-23 04:59:50 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-04-13 20:48:37 -04: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-04 22:26:48 -04:00
|
|
|
class SessionRequestManager;
|
|
|
|
|
2021-04-13 20:48:37 -04:00
|
|
|
class KSession final : public KAutoObjectWithSlabHeapAndContainer<KSession, KAutoObjectWithList> {
|
|
|
|
KERNEL_AUTOOBJECT_TRAITS(KSession, KAutoObject);
|
|
|
|
|
|
|
|
public:
|
2021-05-08 12:11:36 -04:00
|
|
|
explicit KSession(KernelCore& kernel_);
|
2021-05-29 02:49:07 -04:00
|
|
|
~KSession() override;
|
2021-04-13 20:48:37 -04:00
|
|
|
|
2023-03-06 20:34:25 -05:00
|
|
|
void Initialize(KClientPort* port, uintptr_t name);
|
2021-05-29 02:49:07 -04:00
|
|
|
void Finalize() override;
|
2021-04-13 20:48:37 -04:00
|
|
|
|
2021-05-29 02:49:07 -04:00
|
|
|
bool IsInitialized() const override {
|
2023-03-06 20:34:25 -05:00
|
|
|
return m_initialized;
|
2021-04-13 20:48:37 -04:00
|
|
|
}
|
|
|
|
|
2021-05-29 02:49:07 -04:00
|
|
|
uintptr_t GetPostDestroyArgument() const override {
|
2023-03-06 20:34:25 -05:00
|
|
|
return reinterpret_cast<uintptr_t>(m_process);
|
2021-04-13 20:48:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2023-03-06 20:34:25 -05:00
|
|
|
return m_client;
|
2021-04-13 20:48:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
KServerSession& GetServerSession() {
|
2023-03-06 20:34:25 -05:00
|
|
|
return m_server;
|
2021-04-13 20:48:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const KClientSession& GetClientSession() const {
|
2023-03-06 20:34:25 -05:00
|
|
|
return m_client;
|
2021-04-13 20:48:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const KServerSession& GetServerSession() const {
|
2023-03-06 20:34:25 -05:00
|
|
|
return m_server;
|
2021-04-13 20:48:37 -04:00
|
|
|
}
|
|
|
|
|
2021-04-22 00:43:25 -04:00
|
|
|
const KClientPort* GetParent() const {
|
2023-03-06 20:34:25 -05:00
|
|
|
return m_port;
|
2021-05-16 02:49:03 -04:00
|
|
|
}
|
|
|
|
|
2021-05-01 15:48:41 -04:00
|
|
|
private:
|
|
|
|
enum class State : u8 {
|
|
|
|
Invalid = 0,
|
|
|
|
Normal = 1,
|
|
|
|
ClientClosed = 2,
|
|
|
|
ServerClosed = 3,
|
|
|
|
};
|
|
|
|
|
2021-04-13 20:48:37 -04:00
|
|
|
void SetState(State state) {
|
2023-03-06 20:34:25 -05:00
|
|
|
m_atomic_state = static_cast<u8>(state);
|
2021-04-13 20:48:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
State GetState() const {
|
2023-03-06 20:34:25 -05:00
|
|
|
return static_cast<State>(m_atomic_state.load());
|
2021-04-13 20:48:37 -04:00
|
|
|
}
|
|
|
|
|
2023-03-06 20:34:25 -05:00
|
|
|
KServerSession m_server;
|
|
|
|
KClientSession m_client;
|
|
|
|
KClientPort* m_port{};
|
|
|
|
uintptr_t m_name{};
|
|
|
|
KProcess* m_process{};
|
|
|
|
std::atomic<u8> m_atomic_state{static_cast<u8>(State::Invalid)};
|
|
|
|
bool m_initialized{};
|
2021-04-13 20:48:37 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Kernel
|