k_port.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <memory>
  6. #include <string>
  7. #include "common/common_types.h"
  8. #include "core/hle/kernel/k_client_port.h"
  9. #include "core/hle/kernel/k_server_port.h"
  10. #include "core/hle/kernel/slab_helpers.h"
  11. #include "core/hle/result.h"
  12. namespace Kernel {
  13. class KServerSession;
  14. class KPort final : public KAutoObjectWithSlabHeapAndContainer<KPort, KAutoObjectWithList> {
  15. KERNEL_AUTOOBJECT_TRAITS(KPort, KAutoObject);
  16. public:
  17. explicit KPort(KernelCore& kernel);
  18. virtual ~KPort();
  19. static void PostDestroy([[maybe_unused]] uintptr_t arg) {}
  20. void Initialize(s32 max_sessions_, bool is_light_, const std::string& name_);
  21. void OnClientClosed();
  22. void OnServerClosed();
  23. bool IsLight() const {
  24. return is_light;
  25. }
  26. bool IsServerClosed() const;
  27. ResultCode EnqueueSession(KServerSession* session);
  28. KClientPort& GetClientPort() {
  29. return client;
  30. }
  31. KServerPort& GetServerPort() {
  32. return server;
  33. }
  34. const KClientPort& GetClientPort() const {
  35. return client;
  36. }
  37. const KServerPort& GetServerPort() const {
  38. return server;
  39. }
  40. private:
  41. enum class State : u8 {
  42. Invalid = 0,
  43. Normal = 1,
  44. ClientClosed = 2,
  45. ServerClosed = 3,
  46. };
  47. private:
  48. KServerPort server;
  49. KClientPort client;
  50. State state{State::Invalid};
  51. bool is_light{};
  52. };
  53. } // namespace Kernel