mirror of
https://github.com/yuzu-emu/yuzu-mainline.git
synced 2024-12-27 20:15:26 +00:00
kernel/server_port: Make data members private
With this, all kernel objects finally have all of their data members behind an interface, making it nicer to reason about interactions with other code (as external code no longer has the freedom to totally alter internals and potentially messing up invariants).
This commit is contained in:
parent
0aa824b12f
commit
aa44eb639b
|
@ -33,10 +33,11 @@ ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() {
|
||||||
// Create a new session pair, let the created sessions inherit the parent port's HLE handler.
|
// Create a new session pair, let the created sessions inherit the parent port's HLE handler.
|
||||||
auto sessions = ServerSession::CreateSessionPair(kernel, server_port->GetName(), this);
|
auto sessions = ServerSession::CreateSessionPair(kernel, server_port->GetName(), this);
|
||||||
|
|
||||||
if (server_port->hle_handler)
|
if (server_port->HasHLEHandler()) {
|
||||||
server_port->hle_handler->ClientConnected(std::get<SharedPtr<ServerSession>>(sessions));
|
server_port->GetHLEHandler()->ClientConnected(std::get<SharedPtr<ServerSession>>(sessions));
|
||||||
else
|
} else {
|
||||||
server_port->pending_sessions.push_back(std::get<SharedPtr<ServerSession>>(sessions));
|
server_port->AppendPendingSession(std::get<SharedPtr<ServerSession>>(sessions));
|
||||||
|
}
|
||||||
|
|
||||||
// Wake the threads waiting on the ServerPort
|
// Wake the threads waiting on the ServerPort
|
||||||
server_port->WakeupAllWaitingThreads();
|
server_port->WakeupAllWaitingThreads();
|
||||||
|
|
|
@ -26,6 +26,10 @@ ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() {
|
||||||
return MakeResult(std::move(session));
|
return MakeResult(std::move(session));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerPort::AppendPendingSession(SharedPtr<ServerSession> pending_session) {
|
||||||
|
pending_sessions.push_back(std::move(pending_session));
|
||||||
|
}
|
||||||
|
|
||||||
bool ServerPort::ShouldWait(Thread* thread) const {
|
bool ServerPort::ShouldWait(Thread* thread) const {
|
||||||
// If there are no pending sessions, we wait until a new one is added.
|
// If there are no pending sessions, we wait until a new one is added.
|
||||||
return pending_sessions.empty();
|
return pending_sessions.empty();
|
||||||
|
|
|
@ -22,6 +22,8 @@ class SessionRequestHandler;
|
||||||
|
|
||||||
class ServerPort final : public WaitObject {
|
class ServerPort final : public WaitObject {
|
||||||
public:
|
public:
|
||||||
|
using HLEHandler = std::shared_ptr<SessionRequestHandler>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a pair of ServerPort and an associated ClientPort.
|
* Creates a pair of ServerPort and an associated ClientPort.
|
||||||
*
|
*
|
||||||
|
@ -51,22 +53,27 @@ public:
|
||||||
*/
|
*/
|
||||||
ResultVal<SharedPtr<ServerSession>> Accept();
|
ResultVal<SharedPtr<ServerSession>> Accept();
|
||||||
|
|
||||||
|
/// 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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the HLE handler template for the port. ServerSessions crated by connecting to this port
|
* Sets the HLE handler template for the port. ServerSessions crated by connecting to this port
|
||||||
* will inherit a reference to this handler.
|
* will inherit a reference to this handler.
|
||||||
*/
|
*/
|
||||||
void SetHleHandler(std::shared_ptr<SessionRequestHandler> hle_handler_) {
|
void SetHleHandler(HLEHandler hle_handler_) {
|
||||||
hle_handler = std::move(hle_handler_);
|
hle_handler = std::move(hle_handler_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name; ///< Name of port (optional)
|
/// Appends a ServerSession to the collection of ServerSessions
|
||||||
|
/// waiting to be accepted by this port.
|
||||||
/// ServerSessions waiting to be accepted by the port
|
void AppendPendingSession(SharedPtr<ServerSession> pending_session);
|
||||||
std::vector<SharedPtr<ServerSession>> pending_sessions;
|
|
||||||
|
|
||||||
/// This session's HLE request handler template (optional)
|
|
||||||
/// ServerSessions created from this port inherit a reference to this handler.
|
|
||||||
std::shared_ptr<SessionRequestHandler> hle_handler;
|
|
||||||
|
|
||||||
bool ShouldWait(Thread* thread) const override;
|
bool ShouldWait(Thread* thread) const override;
|
||||||
void Acquire(Thread* thread) override;
|
void Acquire(Thread* thread) override;
|
||||||
|
@ -74,6 +81,16 @@ public:
|
||||||
private:
|
private:
|
||||||
explicit ServerPort(KernelCore& kernel);
|
explicit ServerPort(KernelCore& kernel);
|
||||||
~ServerPort() override;
|
~ServerPort() override;
|
||||||
|
|
||||||
|
/// ServerSessions waiting to be accepted by the port
|
||||||
|
std::vector<SharedPtr<ServerSession>> pending_sessions;
|
||||||
|
|
||||||
|
/// 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
|
@ -67,7 +67,7 @@ public:
|
||||||
if (port == nullptr) {
|
if (port == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return std::static_pointer_cast<T>(port->hle_handler);
|
return std::static_pointer_cast<T>(port->GetHLEHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InvokeControlRequest(Kernel::HLERequestContext& context);
|
void InvokeControlRequest(Kernel::HLERequestContext& context);
|
||||||
|
|
Loading…
Reference in a new issue