server_port.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. namespace Service {
  11. class SessionRequestHandler;
  12. }
  13. namespace Kernel {
  14. class ClientPort;
  15. class ServerPort final : public WaitObject {
  16. public:
  17. /**
  18. * Creates a pair of ServerPort and an associated ClientPort.
  19. * @param max_sessions Maximum number of sessions to the port
  20. * @param name Optional name of the ports
  21. * @param hle_handler Optional HLE handler template for the port,
  22. * ServerSessions crated from this port will inherit a reference to this handler.
  23. * @return The created port tuple
  24. */
  25. static std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> CreatePortPair(
  26. u32 max_sessions, std::string name = "UnknownPort",
  27. std::shared_ptr<Service::SessionRequestHandler> hle_handler = nullptr);
  28. std::string GetTypeName() const override {
  29. return "ServerPort";
  30. }
  31. std::string GetName() const override {
  32. return name;
  33. }
  34. static const HandleType HANDLE_TYPE = HandleType::ServerPort;
  35. HandleType GetHandleType() const override {
  36. return HANDLE_TYPE;
  37. }
  38. std::string name; ///< Name of port (optional)
  39. std::vector<SharedPtr<WaitObject>>
  40. pending_sessions; ///< ServerSessions waiting to be accepted by the port
  41. /// This session's HLE request handler template (optional)
  42. /// ServerSessions created from this port inherit a reference to this handler.
  43. std::shared_ptr<Service::SessionRequestHandler> hle_handler;
  44. bool ShouldWait() override;
  45. void Acquire() override;
  46. private:
  47. ServerPort();
  48. ~ServerPort() override;
  49. };
  50. } // namespace