k_port.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <string>
  6. #include "common/common_types.h"
  7. #include "core/hle/kernel/k_client_port.h"
  8. #include "core/hle/kernel/k_server_port.h"
  9. #include "core/hle/kernel/slab_helpers.h"
  10. #include "core/hle/result.h"
  11. namespace Kernel {
  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([[maybe_unused]] uintptr_t arg) {}
  19. void Initialize(s32 max_sessions_, bool is_light_, const std::string& name_);
  20. void OnClientClosed();
  21. void OnServerClosed();
  22. bool IsLight() const {
  23. return is_light;
  24. }
  25. bool IsServerClosed() const;
  26. ResultCode EnqueueSession(KServerSession* session);
  27. KClientPort& GetClientPort() {
  28. return client;
  29. }
  30. KServerPort& GetServerPort() {
  31. return server;
  32. }
  33. const KClientPort& GetClientPort() const {
  34. return client;
  35. }
  36. const KServerPort& GetServerPort() const {
  37. return server;
  38. }
  39. private:
  40. enum class State : u8 {
  41. Invalid = 0,
  42. Normal = 1,
  43. ClientClosed = 2,
  44. ServerClosed = 3,
  45. };
  46. KServerPort server;
  47. KClientPort client;
  48. State state{State::Invalid};
  49. bool is_light{};
  50. };
  51. } // namespace Kernel