server_port.h 2.3 KB

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