server_port.h 1.8 KB

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