KServerPorts now have an HLE handler "template", which is inherited by all ServerSessions created from it.

This commit is contained in:
Subv 2016-12-05 11:02:08 -05:00
parent 2ce61344d6
commit dd8887c8cf
12 changed files with 86 additions and 69 deletions

View file

@ -13,10 +13,18 @@ namespace Kernel {
ClientPort::ClientPort() {}
ClientPort::~ClientPort() {}
void ClientPort::AddWaitingSession(SharedPtr<ServerSession> server_session) {
SharedPtr<ClientSession> ClientPort::Connect() {
// Create a new session pair, let the created sessions inherit the parent port's HLE handler.
auto sessions = ServerSession::CreateSessionPair(server_port->GetName(), server_port->hle_handler);
auto client_session = std::get<SharedPtr<ClientSession>>(sessions);
auto server_session = std::get<SharedPtr<ServerSession>>(sessions);
server_port->pending_sessions.push_back(server_session);
// Wake the threads waiting on the ServerPort
server_port->WakeupAllWaitingThreads();
return std::move(client_session);
}
} // namespace

View file

@ -11,7 +11,7 @@
namespace Kernel {
class ServerPort;
class ServerSession;
class ClientSession;
class ClientPort final : public Object {
public:
@ -29,15 +29,17 @@ public:
}
/**
* Adds the specified server session to the queue of pending sessions of the associated ServerPort
* @param server_session Server session to add to the queue
* Creates a new Session pair, adds the created ServerSession to the associated ServerPort's list of pending sessions,
* and signals the ServerPort, causing any threads waiting on it to awake.
* @returns ClientSession The client endpoint of the created Session pair.
*/
void AddWaitingSession(SharedPtr<ServerSession> server_session);
SharedPtr<ClientSession> Connect();
SharedPtr<ServerPort> server_port; ///< ServerPort associated with this client port.
u32 max_sessions; ///< Maximum number of simultaneous sessions the port can have
u32 active_sessions; ///< Number of currently open sessions to this port
std::string name; ///< Name of client port (optional)
private:
ClientPort();
~ClientPort() override;

View file

@ -20,7 +20,7 @@ ResultVal<SharedPtr<ClientSession>> ClientSession::Create(SharedPtr<ServerSessio
return MakeResult<SharedPtr<ClientSession>>(std::move(client_session));
}
ResultCode ClientSession::HandleSyncRequest() {
ResultCode ClientSession::SendSyncRequest() {
// Signal the server session that new data is available
return server_session->HandleSyncRequest();
}

View file

@ -17,17 +17,12 @@ class ServerSession;
class ClientSession final : public Object {
public:
/**
* Creates a client session.
* @param server_session The server session associated with this client session
* @param name Optional name of client session
* @return The created client session
*/
static ResultVal<SharedPtr<ClientSession>> Create(SharedPtr<ServerSession> server_session, std::string name = "Unknown");
friend class ServerSession;
std::string GetTypeName() const override {
return "ClientSession";
}
std::string GetName() const override {
return name;
}
@ -38,10 +33,10 @@ public:
}
/**
* Handle a SyncRequest from the emulated application.
* Sends an SyncRequest from the current emulated thread.
* @return ResultCode of the operation.
*/
ResultCode HandleSyncRequest();
ResultCode SendSyncRequest();
std::string name; ///< Name of client port (optional)
SharedPtr<ServerSession> server_session; ///< The server session associated with this client session.
@ -49,6 +44,14 @@ public:
private:
ClientSession();
~ClientSession() override;
/**
* Creates a client session.
* @param server_session The server session associated with this client session
* @param name Optional name of client session
* @return The created client session
*/
static ResultVal<SharedPtr<ClientSession>> Create(SharedPtr<ServerSession> server_session, std::string name = "Unknown");
};
} // namespace

View file

@ -24,12 +24,13 @@ void ServerPort::Acquire() {
}
std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> ServerPort::CreatePortPair(
u32 max_sessions, std::string name) {
u32 max_sessions, std::string name, std::shared_ptr<Service::SessionRequestHandler> hle_handler) {
SharedPtr<ServerPort> server_port(new ServerPort);
SharedPtr<ClientPort> client_port(new ClientPort);
server_port->name = name + "_Server";
server_port->hle_handler = hle_handler;
client_port->name = name + "_Client";
client_port->server_port = server_port;
client_port->max_sessions = max_sessions;

View file

@ -9,6 +9,10 @@
#include "common/common_types.h"
#include "core/hle/kernel/kernel.h"
namespace Service {
class SessionRequestHandler;
}
namespace Kernel {
class ClientPort;
@ -19,10 +23,13 @@ public:
* Creates a pair of ServerPort and an associated ClientPort.
* @param max_sessions Maximum number of sessions to the port
* @param name Optional name of the ports
* @param hle_handler Optional HLE handler template for the port,
* ServerSessions crated from this port will inherit a reference to this handler.
* @return The created port tuple
*/
static std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> CreatePortPair(
u32 max_sessions, std::string name = "UnknownPort");
u32 max_sessions, std::string name = "UnknownPort",
std::shared_ptr<Service::SessionRequestHandler> hle_handler = nullptr);
std::string GetTypeName() const override {
return "ServerPort";
@ -41,6 +48,10 @@ public:
std::vector<SharedPtr<WaitObject>>
pending_sessions; ///< ServerSessions waiting to be accepted by the port
/// This session's HLE request handler template (optional)
/// ServerSessions created from this port inherit a reference to this handler.
std::shared_ptr<Service::SessionRequestHandler> hle_handler;
bool ShouldWait() override;
void Acquire() override;

View file

@ -47,10 +47,10 @@ ResultCode ServerSession::HandleSyncRequest() {
}
std::tuple<SharedPtr<ServerSession>, SharedPtr<ClientSession>> ServerSession::CreateSessionPair(const std::string& name, std::shared_ptr<Service::SessionRequestHandler> hle_handler) {
auto server_session = ServerSession::Create(name + "Server", hle_handler).MoveFrom();
auto client_session = ClientSession::Create(server_session, name + "Client").MoveFrom();
auto server_session = ServerSession::Create(name + "_Server", hle_handler).MoveFrom();
auto client_session = ClientSession::Create(server_session, name + "_Client").MoveFrom();
return std::make_tuple(server_session, client_session);
return std::make_tuple(std::move(server_session), std::move(client_session));
}
}

View file

@ -29,20 +29,8 @@ class ClientSession;
* the request, the response is marshalled back to the caller's TLS buffer and control is
* transferred back to it.
*/
class ServerSession : public WaitObject {
class ServerSession final : public WaitObject {
public:
ServerSession();
~ServerSession() override;
/**
* Creates a server session. The server session can have an optional HLE handler,
* which will be invoked to handle the IPC requests that this session receives.
* @param name Optional name of the server session.
* @param hle_handler Optional HLE handler for this server session.
* @return The created server session
*/
static ResultVal<SharedPtr<ServerSession>> Create(std::string name = "Unknown", std::shared_ptr<Service::SessionRequestHandler> hle_handler = nullptr);
std::string GetTypeName() const override {
return "ServerSession";
}
@ -61,10 +49,9 @@ public:
/**
* Handle a sync request from the emulated application.
* Only HLE services should override this function.
* @returns ResultCode from the operation.
*/
virtual ResultCode HandleSyncRequest();
ResultCode HandleSyncRequest();
bool ShouldWait() override;
@ -73,5 +60,18 @@ public:
std::string name; ///< The name of this session (optional)
bool signaled; ///< Whether there's new data available to this ServerSession
std::shared_ptr<Service::SessionRequestHandler> hle_handler; ///< This session's HLE request handler (optional)
private:
ServerSession();
~ServerSession() override;
/**
* Creates a server session. The server session can have an optional HLE handler,
* which will be invoked to handle the IPC requests that this session receives.
* @param name Optional name of the server session.
* @param hle_handler Optional HLE handler for this server session.
* @return The created server session
*/
static ResultVal<SharedPtr<ServerSession>> Create(std::string name = "Unknown", std::shared_ptr<Service::SessionRequestHandler> hle_handler = nullptr);
};
}