k_server_session.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <list>
  5. #include <memory>
  6. #include <string>
  7. #include <utility>
  8. #include <boost/intrusive/list.hpp>
  9. #include "core/hle/kernel/hle_ipc.h"
  10. #include "core/hle/kernel/k_light_lock.h"
  11. #include "core/hle/kernel/k_session_request.h"
  12. #include "core/hle/kernel/k_synchronization_object.h"
  13. #include "core/hle/result.h"
  14. namespace Kernel {
  15. class HLERequestContext;
  16. class KernelCore;
  17. class KSession;
  18. class SessionRequestManager;
  19. class KThread;
  20. class KServerSession final : public KSynchronizationObject,
  21. public boost::intrusive::list_base_hook<> {
  22. KERNEL_AUTOOBJECT_TRAITS(KServerSession, KSynchronizationObject);
  23. friend class ServiceThread;
  24. public:
  25. explicit KServerSession(KernelCore& kernel_);
  26. ~KServerSession() override;
  27. void Destroy() override;
  28. void Initialize(KSession* parent_session_, std::string&& name_);
  29. KSession* GetParent() {
  30. return parent;
  31. }
  32. const KSession* GetParent() const {
  33. return parent;
  34. }
  35. bool IsSignaled() const override;
  36. void OnClientClosed();
  37. /// TODO: flesh these out to match the real kernel
  38. Result OnRequest(KSessionRequest* request);
  39. Result SendReply(bool is_hle = false);
  40. Result ReceiveRequest(std::shared_ptr<HLERequestContext>* out_context = nullptr,
  41. std::weak_ptr<SessionRequestManager> manager = {});
  42. Result SendReplyHLE() {
  43. return SendReply(true);
  44. }
  45. private:
  46. /// Frees up waiting client sessions when this server session is about to die
  47. void CleanupRequests();
  48. /// KSession that owns this KServerSession
  49. KSession* parent{};
  50. /// List of threads which are pending a reply.
  51. boost::intrusive::list<KSessionRequest> m_request_list;
  52. KSessionRequest* m_current_request{};
  53. KLightLock m_lock;
  54. };
  55. } // namespace Kernel