session.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2019 yuzu emulator team
  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 <utility>
  8. #include "core/hle/kernel/synchronization_object.h"
  9. namespace Kernel {
  10. class ClientSession;
  11. class ServerSession;
  12. /**
  13. * Parent structure to link the client and server endpoints of a session with their associated
  14. * client port.
  15. */
  16. class Session final : public SynchronizationObject {
  17. public:
  18. explicit Session(KernelCore& kernel);
  19. ~Session() override;
  20. using SessionPair = std::pair<std::shared_ptr<ClientSession>, std::shared_ptr<ServerSession>>;
  21. static SessionPair Create(KernelCore& kernel, std::string name = "Unknown");
  22. std::string GetName() const override {
  23. return name;
  24. }
  25. static constexpr HandleType HANDLE_TYPE = HandleType::Session;
  26. HandleType GetHandleType() const override {
  27. return HANDLE_TYPE;
  28. }
  29. bool ShouldWait(const Thread* thread) const override;
  30. bool IsSignaled() const override;
  31. void Acquire(Thread* thread) override;
  32. std::shared_ptr<ClientSession> Client() {
  33. if (auto result{client.lock()}) {
  34. return result;
  35. }
  36. return {};
  37. }
  38. std::shared_ptr<ServerSession> Server() {
  39. if (auto result{server.lock()}) {
  40. return result;
  41. }
  42. return {};
  43. }
  44. private:
  45. std::string name;
  46. std::weak_ptr<ClientSession> client;
  47. std::weak_ptr<ServerSession> server;
  48. };
  49. } // namespace Kernel