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>
|
2019-04-06 07:36:50 +02:00
|
|
|
#include <utility>
|
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"
|
2018-10-06 08:49:01 +02:00
|
|
|
#include "core/hle/result.h"
|
2016-05-22 18:22:49 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2016-05-22 19:30:13 +02:00
|
|
|
class ClientPort;
|
2018-08-28 18:30:33 +02:00
|
|
|
class KernelCore;
|
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:
|
2019-11-25 02:15:51 +01:00
|
|
|
explicit ServerPort(KernelCore& kernel);
|
|
|
|
~ServerPort() override;
|
|
|
|
|
2019-03-11 15:28:16 +01:00
|
|
|
using HLEHandler = std::shared_ptr<SessionRequestHandler>;
|
2019-11-25 02:15:51 +01:00
|
|
|
using PortPair = std::pair<std::shared_ptr<ServerPort>, std::shared_ptr<ClientPort>>;
|
2019-03-11 15:28:16 +01:00
|
|
|
|
2016-05-22 18:22:49 +02:00
|
|
|
/**
|
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
|
|
|
*
|
2018-08-28 18:30:33 +02:00
|
|
|
* @param kernel The kernel instance to create the port pair under.
|
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
|
|
|
|
*/
|
2019-04-06 07:36:50 +02:00
|
|
|
static PortPair CreatePortPair(KernelCore& kernel, 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
|
|
|
|
2019-04-11 22:30:52 +02:00
|
|
|
static constexpr 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.
|
|
|
|
*/
|
2019-11-25 02:15:51 +01:00
|
|
|
ResultVal<std::shared_ptr<ServerSession>> Accept();
|
2017-06-23 08:57:05 +02:00
|
|
|
|
2019-03-11 15:28:16 +01:00
|
|
|
/// Whether or not this server port has an HLE handler available.
|
|
|
|
bool HasHLEHandler() const {
|
|
|
|
return hle_handler != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the HLE handler for this port.
|
|
|
|
HLEHandler GetHLEHandler() const {
|
|
|
|
return hle_handler;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2019-03-11 15:28:16 +01:00
|
|
|
void SetHleHandler(HLEHandler hle_handler_) {
|
2017-06-06 07:39:26 +02:00
|
|
|
hle_handler = std::move(hle_handler_);
|
|
|
|
}
|
|
|
|
|
2019-03-11 15:28:16 +01:00
|
|
|
/// Appends a ServerSession to the collection of ServerSessions
|
|
|
|
/// waiting to be accepted by this port.
|
2019-11-25 02:15:51 +01:00
|
|
|
void AppendPendingSession(std::shared_ptr<ServerSession> pending_session);
|
2016-12-05 17:02:08 +01:00
|
|
|
|
2019-04-02 00:19:42 +02:00
|
|
|
bool ShouldWait(const Thread* thread) const override;
|
2017-01-01 22:53:22 +01:00
|
|
|
void Acquire(Thread* thread) override;
|
2016-05-22 18:22:49 +02:00
|
|
|
|
|
|
|
private:
|
2019-03-11 15:28:16 +01:00
|
|
|
/// ServerSessions waiting to be accepted by the port
|
2019-11-25 02:15:51 +01:00
|
|
|
std::vector<std::shared_ptr<ServerSession>> pending_sessions;
|
2019-03-11 15:28:16 +01:00
|
|
|
|
|
|
|
/// This session's HLE request handler template (optional)
|
|
|
|
/// ServerSessions created from this port inherit a reference to this handler.
|
|
|
|
HLEHandler hle_handler;
|
|
|
|
|
|
|
|
/// Name of the port (optional)
|
|
|
|
std::string name;
|
2016-05-22 18:22:49 +02:00
|
|
|
};
|
|
|
|
|
2018-01-20 08:48:02 +01:00
|
|
|
} // namespace Kernel
|