2021-04-14 00:48:37 +00:00
|
|
|
// Copyright 2021 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#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 {
|
|
|
|
|
|
|
|
class KSession final : public KAutoObjectWithSlabHeapAndContainer<KSession, KAutoObjectWithList> {
|
|
|
|
KERNEL_AUTOOBJECT_TRAITS(KSession, KAutoObject);
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum class State : u8 {
|
|
|
|
Invalid = 0,
|
|
|
|
Normal = 1,
|
|
|
|
ClientClosed = 2,
|
|
|
|
ServerClosed = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit KSession(KernelCore& kernel);
|
|
|
|
virtual ~KSession() override;
|
|
|
|
|
2021-04-24 04:50:04 +00:00
|
|
|
void Initialize(KClientPort* port_, const std::string& name_);
|
2021-04-14 00:48:37 +00:00
|
|
|
|
|
|
|
virtual void Finalize() override;
|
|
|
|
|
|
|
|
virtual bool IsInitialized() const override {
|
|
|
|
return initialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uintptr_t GetPostDestroyArgument() const override {
|
|
|
|
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 04:43:25 +00:00
|
|
|
const KClientPort* GetParent() const {
|
2021-04-14 00:48:37 +00:00
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SetState(State state) {
|
|
|
|
atomic_state = static_cast<u8>(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
State GetState() const {
|
|
|
|
return static_cast<State>(atomic_state.load());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
KServerSession server;
|
|
|
|
KClientSession client;
|
|
|
|
std::atomic<std::underlying_type<State>::type> atomic_state{
|
|
|
|
static_cast<std::underlying_type<State>::type>(State::Invalid)};
|
2021-04-22 04:43:25 +00:00
|
|
|
KClientPort* port{};
|
2021-04-14 00:48:37 +00:00
|
|
|
Process* process{};
|
|
|
|
bool initialized{};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Kernel
|