2016-05-22 18:22:49 +02:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2016-12-05 18:05:00 +01:00
|
|
|
#include <memory>
|
2016-05-22 18:22:49 +02:00
|
|
|
#include <string>
|
2016-05-22 19:30:13 +02:00
|
|
|
#include <tuple>
|
2018-07-31 14:06:09 +02:00
|
|
|
#include <vector>
|
2016-05-22 18:22:49 +02:00
|
|
|
#include "common/common_types.h"
|
2018-08-02 04:40:00 +02:00
|
|
|
#include "core/hle/kernel/object.h"
|
2017-05-30 00:45:30 +02:00
|
|
|
#include "core/hle/kernel/wait_object.h"
|
2016-05-22 18:22:49 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2016-05-22 19:30:13 +02:00
|
|
|
class ClientPort;
|
2017-06-23 08:57:05 +02:00
|
|
|
class ServerSession;
|
2017-06-05 06:52:19 +02:00
|
|
|
class SessionRequestHandler;
|
2016-05-22 19:30:13 +02:00
|
|
|
|
2016-05-22 18:22:49 +02:00
|
|
|
class ServerPort final : public WaitObject {
|
|
|
|
public:
|
|
|
|
/**
|
2016-05-22 19:30:13 +02:00
|
|
|
* Creates a pair of ServerPort and an associated ClientPort.
|
2017-06-06 07:39:26 +02:00
|
|
|
*
|
2016-05-22 18:22:49 +02:00
|
|
|
* @param max_sessions Maximum number of sessions to the port
|
|
|
|
* @param name Optional name of the ports
|
|
|
|
* @return The created port tuple
|
|
|
|
*/
|
2016-09-19 03:01:46 +02:00
|
|
|
static std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> CreatePortPair(
|
2017-06-06 07:39:26 +02:00
|
|
|
u32 max_sessions, std::string name = "UnknownPort");
|
2016-05-22 18:22:49 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
std::string GetTypeName() const override {
|
|
|
|
return "ServerPort";
|
|
|
|
}
|
|
|
|
std::string GetName() const override {
|
|
|
|
return name;
|
|
|
|
}
|
2016-05-22 18:22:49 +02:00
|
|
|
|
|
|
|
static const HandleType HANDLE_TYPE = HandleType::ServerPort;
|
2016-09-18 02:38:01 +02:00
|
|
|
HandleType GetHandleType() const override {
|
|
|
|
return HANDLE_TYPE;
|
|
|
|
}
|
2016-05-22 18:22:49 +02:00
|
|
|
|
2017-06-23 08:57:05 +02:00
|
|
|
/**
|
|
|
|
* Accepts a pending incoming connection on this port. If there are no pending sessions, will
|
|
|
|
* return ERR_NO_PENDING_SESSIONS.
|
|
|
|
*/
|
|
|
|
ResultVal<SharedPtr<ServerSession>> Accept();
|
|
|
|
|
2017-06-06 07:39:26 +02:00
|
|
|
/**
|
|
|
|
* Sets the HLE handler template for the port. ServerSessions crated by connecting to this port
|
|
|
|
* will inherit a reference to this handler.
|
|
|
|
*/
|
|
|
|
void SetHleHandler(std::shared_ptr<SessionRequestHandler> hle_handler_) {
|
|
|
|
hle_handler = std::move(hle_handler_);
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
std::string name; ///< Name of port (optional)
|
2016-05-22 18:22:49 +02:00
|
|
|
|
2017-06-23 08:57:05 +02:00
|
|
|
/// ServerSessions waiting to be accepted by the port
|
|
|
|
std::vector<SharedPtr<ServerSession>> pending_sessions;
|
2016-05-22 18:22:49 +02:00
|
|
|
|
2016-12-05 17:02:08 +01:00
|
|
|
/// This session's HLE request handler template (optional)
|
|
|
|
/// ServerSessions created from this port inherit a reference to this handler.
|
2017-06-05 06:52:19 +02:00
|
|
|
std::shared_ptr<SessionRequestHandler> hle_handler;
|
2016-12-05 17:02:08 +01:00
|
|
|
|
2017-01-01 22:53:22 +01:00
|
|
|
bool ShouldWait(Thread* thread) const override;
|
|
|
|
void Acquire(Thread* thread) override;
|
2016-05-22 18:22:49 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
ServerPort();
|
|
|
|
~ServerPort() override;
|
|
|
|
};
|
|
|
|
|
2018-01-20 08:48:02 +01:00
|
|
|
} // namespace Kernel
|