k_port.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. ~KPort() override;
  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. KServerPort server;
  48. KClientPort client;
  49. State state{State::Invalid};
  50. bool is_light{};
  51. };
  52. } // namespace Kernel