server_port.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2016 Citra 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 <tuple>
  8. #include "common/common_types.h"
  9. #include "core/hle/kernel/kernel.h"
  10. #include "core/hle/kernel/wait_object.h"
  11. namespace Kernel {
  12. class ClientPort;
  13. class ServerSession;
  14. class SessionRequestHandler;
  15. class ServerPort final : public WaitObject {
  16. public:
  17. /**
  18. * Creates a pair of ServerPort and an associated ClientPort.
  19. *
  20. * @param max_sessions Maximum number of sessions to the port
  21. * @param name Optional name of the ports
  22. * @return The created port tuple
  23. */
  24. static std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> CreatePortPair(
  25. u32 max_sessions, std::string name = "UnknownPort");
  26. std::string GetTypeName() const override {
  27. return "ServerPort";
  28. }
  29. std::string GetName() const override {
  30. return name;
  31. }
  32. static const HandleType HANDLE_TYPE = HandleType::ServerPort;
  33. HandleType GetHandleType() const override {
  34. return HANDLE_TYPE;
  35. }
  36. /**
  37. * Accepts a pending incoming connection on this port. If there are no pending sessions, will
  38. * return ERR_NO_PENDING_SESSIONS.
  39. */
  40. ResultVal<SharedPtr<ServerSession>> Accept();
  41. /**
  42. * Sets the HLE handler template for the port. ServerSessions crated by connecting to this port
  43. * will inherit a reference to this handler.
  44. */
  45. void SetHleHandler(std::shared_ptr<SessionRequestHandler> hle_handler_) {
  46. hle_handler = std::move(hle_handler_);
  47. }
  48. std::string name; ///< Name of port (optional)
  49. /// ServerSessions waiting to be accepted by the port
  50. std::vector<SharedPtr<ServerSession>> pending_sessions;
  51. /// This session's HLE request handler template (optional)
  52. /// ServerSessions created from this port inherit a reference to this handler.
  53. std::shared_ptr<SessionRequestHandler> hle_handler;
  54. bool ShouldWait(Thread* thread) const override;
  55. void Acquire(Thread* thread) override;
  56. private:
  57. ServerPort();
  58. ~ServerPort() override;
  59. };
  60. } // namespace