k_session.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <atomic>
  5. #include <string>
  6. #include "core/hle/kernel/k_client_session.h"
  7. #include "core/hle/kernel/k_server_session.h"
  8. #include "core/hle/kernel/slab_helpers.h"
  9. namespace Kernel {
  10. class SessionRequestManager;
  11. class KSession final : public KAutoObjectWithSlabHeapAndContainer<KSession, KAutoObjectWithList> {
  12. KERNEL_AUTOOBJECT_TRAITS(KSession, KAutoObject);
  13. public:
  14. explicit KSession(KernelCore& kernel);
  15. ~KSession() override;
  16. void Initialize(KClientPort* port, uintptr_t name);
  17. void Finalize() override;
  18. bool IsInitialized() const override {
  19. return m_initialized;
  20. }
  21. uintptr_t GetPostDestroyArgument() const override {
  22. return reinterpret_cast<uintptr_t>(m_process);
  23. }
  24. static void PostDestroy(uintptr_t arg);
  25. void OnServerClosed();
  26. void OnClientClosed();
  27. bool IsServerClosed() const {
  28. return this->GetState() != State::Normal;
  29. }
  30. bool IsClientClosed() const {
  31. return this->GetState() != State::Normal;
  32. }
  33. Result OnRequest(KSessionRequest* request) {
  34. R_RETURN(m_server.OnRequest(request));
  35. }
  36. KClientSession& GetClientSession() {
  37. return m_client;
  38. }
  39. KServerSession& GetServerSession() {
  40. return m_server;
  41. }
  42. const KClientSession& GetClientSession() const {
  43. return m_client;
  44. }
  45. const KServerSession& GetServerSession() const {
  46. return m_server;
  47. }
  48. const KClientPort* GetParent() const {
  49. return m_port;
  50. }
  51. private:
  52. enum class State : u8 {
  53. Invalid = 0,
  54. Normal = 1,
  55. ClientClosed = 2,
  56. ServerClosed = 3,
  57. };
  58. void SetState(State state) {
  59. m_atomic_state = static_cast<u8>(state);
  60. }
  61. State GetState() const {
  62. return static_cast<State>(m_atomic_state.load());
  63. }
  64. KServerSession m_server;
  65. KClientSession m_client;
  66. KClientPort* m_port{};
  67. uintptr_t m_name{};
  68. KProcess* m_process{};
  69. std::atomic<u8> m_atomic_state{static_cast<u8>(State::Invalid)};
  70. bool m_initialized{};
  71. };
  72. } // namespace Kernel