k_port.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <string>
  5. #include "common/common_types.h"
  6. #include "core/hle/kernel/k_client_port.h"
  7. #include "core/hle/kernel/k_server_port.h"
  8. #include "core/hle/kernel/slab_helpers.h"
  9. #include "core/hle/result.h"
  10. namespace Kernel {
  11. class KLightServerSession;
  12. class KServerSession;
  13. class KPort final : public KAutoObjectWithSlabHeapAndContainer<KPort, KAutoObjectWithList> {
  14. KERNEL_AUTOOBJECT_TRAITS(KPort, KAutoObject);
  15. public:
  16. explicit KPort(KernelCore& kernel);
  17. ~KPort() override;
  18. static void PostDestroy(uintptr_t arg) {}
  19. void Initialize(s32 max_sessions, bool is_light, uintptr_t name);
  20. void OnClientClosed();
  21. void OnServerClosed();
  22. uintptr_t GetName() const {
  23. return m_name;
  24. }
  25. bool IsLight() const {
  26. return m_is_light;
  27. }
  28. bool IsServerClosed() const;
  29. Result EnqueueSession(KServerSession* session);
  30. Result EnqueueSession(KLightServerSession* session);
  31. KClientPort& GetClientPort() {
  32. return m_client;
  33. }
  34. KServerPort& GetServerPort() {
  35. return m_server;
  36. }
  37. const KClientPort& GetClientPort() const {
  38. return m_client;
  39. }
  40. const KServerPort& GetServerPort() const {
  41. return m_server;
  42. }
  43. private:
  44. enum class State : u8 {
  45. Invalid = 0,
  46. Normal = 1,
  47. ClientClosed = 2,
  48. ServerClosed = 3,
  49. };
  50. KServerPort m_server;
  51. KClientPort m_client;
  52. uintptr_t m_name;
  53. State m_state{State::Invalid};
  54. bool m_is_light{};
  55. };
  56. } // namespace Kernel