client_port.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 <string>
  6. #include "common/common_types.h"
  7. #include "core/hle/kernel/object.h"
  8. #include "core/hle/result.h"
  9. namespace Kernel {
  10. class ClientSession;
  11. class KernelCore;
  12. class ServerPort;
  13. class ClientPort final : public Object {
  14. public:
  15. explicit ClientPort(KernelCore& kernel);
  16. ~ClientPort() override;
  17. friend class ServerPort;
  18. std::string GetTypeName() const override {
  19. return "ClientPort";
  20. }
  21. std::string GetName() const override {
  22. return name;
  23. }
  24. static constexpr HandleType HANDLE_TYPE = HandleType::ClientPort;
  25. HandleType GetHandleType() const override {
  26. return HANDLE_TYPE;
  27. }
  28. std::shared_ptr<ServerPort> GetServerPort() const;
  29. /**
  30. * Creates a new Session pair, adds the created ServerSession to the associated ServerPort's
  31. * list of pending sessions, and signals the ServerPort, causing any threads
  32. * waiting on it to awake.
  33. * @returns ClientSession The client endpoint of the created Session pair, or error code.
  34. */
  35. ResultVal<std::shared_ptr<ClientSession>> Connect();
  36. /**
  37. * Signifies that a previously active connection has been closed,
  38. * decreasing the total number of active connections to this port.
  39. */
  40. void ConnectionClosed();
  41. private:
  42. std::shared_ptr<ServerPort> server_port; ///< ServerPort associated with this client port.
  43. u32 max_sessions = 0; ///< Maximum number of simultaneous sessions the port can have
  44. u32 active_sessions = 0; ///< Number of currently open sessions to this port
  45. std::string name; ///< Name of client port (optional)
  46. };
  47. } // namespace Kernel