citra-emu
/
citra
Archived
1
0
Fork 0

Merge pull request #2752 from yuriks/move-session-request-handler

HLE: Move SessionRequestHandler from Service:: to Kernel::
This commit is contained in:
Yuri Kunde Schlesner 2017-06-06 08:01:18 -07:00 committed by GitHub
commit 7d59c3acbf
14 changed files with 100 additions and 73 deletions

View File

@ -46,6 +46,7 @@ set(SRCS
hle/kernel/client_session.cpp hle/kernel/client_session.cpp
hle/kernel/event.cpp hle/kernel/event.cpp
hle/kernel/handle_table.cpp hle/kernel/handle_table.cpp
hle/kernel/hle_ipc.cpp
hle/kernel/kernel.cpp hle/kernel/kernel.cpp
hle/kernel/memory.cpp hle/kernel/memory.cpp
hle/kernel/mutex.cpp hle/kernel/mutex.cpp
@ -239,6 +240,7 @@ set(HEADERS
hle/kernel/errors.h hle/kernel/errors.h
hle/kernel/event.h hle/kernel/event.h
hle/kernel/handle_table.h hle/kernel/handle_table.h
hle/kernel/hle_ipc.h
hle/kernel/kernel.h hle/kernel/kernel.h
hle/kernel/memory.h hle/kernel/memory.h
hle/kernel/mutex.h hle/kernel/mutex.h

View File

@ -6,6 +6,7 @@
#include "core/hle/kernel/client_port.h" #include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/client_session.h" #include "core/hle/kernel/client_session.h"
#include "core/hle/kernel/errors.h" #include "core/hle/kernel/errors.h"
#include "core/hle/kernel/hle_ipc.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/server_port.h" #include "core/hle/kernel/server_port.h"
#include "core/hle/kernel/server_session.h" #include "core/hle/kernel/server_session.h"

View File

@ -5,6 +5,8 @@
#include "common/assert.h" #include "common/assert.h"
#include "core/hle/kernel/client_session.h" #include "core/hle/kernel/client_session.h"
#include "core/hle/kernel/errors.h"
#include "core/hle/kernel/hle_ipc.h"
#include "core/hle/kernel/server_session.h" #include "core/hle/kernel/server_session.h"
namespace Kernel { namespace Kernel {

View File

@ -0,0 +1,22 @@
// Copyright 2017 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <boost/range/algorithm_ext/erase.hpp>
#include "common/assert.h"
#include "common/common_types.h"
#include "core/hle/kernel/hle_ipc.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/server_session.h"
namespace Kernel {
void SessionRequestHandler::ClientConnected(SharedPtr<ServerSession> server_session) {
connected_sessions.push_back(server_session);
}
void SessionRequestHandler::ClientDisconnected(SharedPtr<ServerSession> server_session) {
boost::range::remove_erase(connected_sessions, server_session);
}
} // namespace Kernel

View File

@ -0,0 +1,52 @@
// Copyright 2017 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <vector>
#include "core/hle/kernel/kernel.h"
namespace Kernel {
class ServerSession;
/**
* Interface implemented by HLE Session handlers.
* This can be provided to a ServerSession in order to hook into several relevant events
* (such as a new connection or a SyncRequest) so they can be implemented in the emulator.
*/
class SessionRequestHandler {
public:
/**
* Handles a sync request from the emulated application.
* @param server_session The ServerSession that was triggered for this sync request,
* it should be used to differentiate which client (As in ClientSession) we're answering to.
* TODO(Subv): Use a wrapper structure to hold all the information relevant to
* this request (ServerSession, Originator thread, Translated command buffer, etc).
* @returns ResultCode the result code of the translate operation.
*/
virtual void HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) = 0;
/**
* Signals that a client has just connected to this HLE handler and keeps the
* associated ServerSession alive for the duration of the connection.
* @param server_session Owning pointer to the ServerSession associated with the connection.
*/
void ClientConnected(Kernel::SharedPtr<Kernel::ServerSession> server_session);
/**
* Signals that a client has just disconnected from this HLE handler and releases the
* associated ServerSession.
* @param server_session ServerSession associated with the connection.
*/
void ClientDisconnected(Kernel::SharedPtr<Kernel::ServerSession> server_session);
protected:
/// List of sessions that are connected to this handler.
/// A ServerSession whose server endpoint is an HLE implementation is kept alive by this list
// for the duration of the connection.
std::vector<Kernel::SharedPtr<Kernel::ServerSession>> connected_sessions;
};
} // namespace Kernel

View File

@ -24,8 +24,7 @@ void ServerPort::Acquire(Thread* thread) {
} }
std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> ServerPort::CreatePortPair( std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> ServerPort::CreatePortPair(
u32 max_sessions, std::string name, u32 max_sessions, std::string name, std::shared_ptr<SessionRequestHandler> hle_handler) {
std::shared_ptr<Service::SessionRequestHandler> hle_handler) {
SharedPtr<ServerPort> server_port(new ServerPort); SharedPtr<ServerPort> server_port(new ServerPort);
SharedPtr<ClientPort> client_port(new ClientPort); SharedPtr<ClientPort> client_port(new ClientPort);

View File

@ -11,13 +11,10 @@
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/wait_object.h" #include "core/hle/kernel/wait_object.h"
namespace Service {
class SessionRequestHandler;
}
namespace Kernel { namespace Kernel {
class ClientPort; class ClientPort;
class SessionRequestHandler;
class ServerPort final : public WaitObject { class ServerPort final : public WaitObject {
public: public:
@ -31,7 +28,7 @@ public:
*/ */
static std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> CreatePortPair( 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::shared_ptr<SessionRequestHandler> hle_handler = nullptr);
std::string GetTypeName() const override { std::string GetTypeName() const override {
return "ServerPort"; return "ServerPort";
@ -52,7 +49,7 @@ public:
/// This session's HLE request handler template (optional) /// This session's HLE request handler template (optional)
/// ServerSessions created from this port inherit a reference to this handler. /// ServerSessions created from this port inherit a reference to this handler.
std::shared_ptr<Service::SessionRequestHandler> hle_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;

View File

@ -4,8 +4,11 @@
#include <tuple> #include <tuple>
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/client_session.h" #include "core/hle/kernel/client_session.h"
#include "core/hle/kernel/hle_ipc.h"
#include "core/hle/kernel/server_session.h" #include "core/hle/kernel/server_session.h"
#include "core/hle/kernel/session.h"
#include "core/hle/kernel/thread.h" #include "core/hle/kernel/thread.h"
namespace Kernel { namespace Kernel {
@ -26,7 +29,7 @@ ServerSession::~ServerSession() {
} }
ResultVal<SharedPtr<ServerSession>> ServerSession::Create( ResultVal<SharedPtr<ServerSession>> ServerSession::Create(
std::string name, std::shared_ptr<Service::SessionRequestHandler> hle_handler) { std::string name, std::shared_ptr<SessionRequestHandler> hle_handler) {
SharedPtr<ServerSession> server_session(new ServerSession); SharedPtr<ServerSession> server_session(new ServerSession);
server_session->name = std::move(name); server_session->name = std::move(name);
@ -69,7 +72,7 @@ ResultCode ServerSession::HandleSyncRequest() {
} }
ServerSession::SessionPair ServerSession::CreateSessionPair( ServerSession::SessionPair ServerSession::CreateSessionPair(
const std::string& name, std::shared_ptr<Service::SessionRequestHandler> hle_handler, const std::string& name, std::shared_ptr<SessionRequestHandler> hle_handler,
SharedPtr<ClientPort> port) { SharedPtr<ClientPort> port) {
auto server_session = auto server_session =

View File

@ -12,7 +12,6 @@
#include "core/hle/kernel/session.h" #include "core/hle/kernel/session.h"
#include "core/hle/kernel/wait_object.h" #include "core/hle/kernel/wait_object.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/hle/service/service.h"
#include "core/memory.h" #include "core/memory.h"
namespace Kernel { namespace Kernel {
@ -20,6 +19,7 @@ namespace Kernel {
class ClientSession; class ClientSession;
class ClientPort; class ClientPort;
class ServerSession; class ServerSession;
class SessionRequestHandler;
class Thread; class Thread;
/** /**
@ -56,7 +56,7 @@ public:
*/ */
static SessionPair CreateSessionPair( static SessionPair CreateSessionPair(
const std::string& name = "Unknown", const std::string& name = "Unknown",
std::shared_ptr<Service::SessionRequestHandler> hle_handler = nullptr, std::shared_ptr<SessionRequestHandler> hle_handler = nullptr,
SharedPtr<ClientPort> client_port = nullptr); SharedPtr<ClientPort> client_port = nullptr);
/** /**
@ -72,7 +72,7 @@ public:
std::string name; ///< The name of this session (optional) std::string name; ///< The name of this session (optional)
bool signaled; ///< Whether there's new data available to this ServerSession bool signaled; ///< Whether there's new data available to this ServerSession
std::shared_ptr<Session> parent; ///< The parent session, which links to the client endpoint. std::shared_ptr<Session> parent; ///< The parent session, which links to the client endpoint.
std::shared_ptr<Service::SessionRequestHandler> std::shared_ptr<SessionRequestHandler>
hle_handler; ///< This session's HLE request handler (optional) hle_handler; ///< This session's HLE request handler (optional)
private: private:
@ -87,8 +87,7 @@ private:
* @return The created server session * @return The created server session
*/ */
static ResultVal<SharedPtr<ServerSession>> Create( static ResultVal<SharedPtr<ServerSession>> Create(
std::string name = "Unknown", std::string name = "Unknown", std::shared_ptr<SessionRequestHandler> hle_handler = nullptr);
std::shared_ptr<Service::SessionRequestHandler> hle_handler = nullptr);
}; };
/** /**

View File

@ -25,6 +25,7 @@
#include "core/file_sys/errors.h" #include "core/file_sys/errors.h"
#include "core/file_sys/file_backend.h" #include "core/file_sys/file_backend.h"
#include "core/hle/kernel/client_session.h" #include "core/hle/kernel/client_session.h"
#include "core/hle/kernel/server_session.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/hle/service/fs/archive.h" #include "core/hle/service/fs/archive.h"
#include "core/hle/service/fs/fs_user.h" #include "core/hle/service/fs/fs_user.h"

View File

@ -8,7 +8,7 @@
#include <string> #include <string>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/file_sys/archive_backend.h" #include "core/file_sys/archive_backend.h"
#include "core/hle/kernel/server_session.h" #include "core/hle/kernel/hle_ipc.h"
#include "core/hle/result.h" #include "core/hle/result.h"
namespace FileSys { namespace FileSys {
@ -43,7 +43,7 @@ enum class MediaType : u32 { NAND = 0, SDMC = 1, GameCard = 2 };
typedef u64 ArchiveHandle; typedef u64 ArchiveHandle;
class File final : public SessionRequestHandler, public std::enable_shared_from_this<File> { class File final : public Kernel::SessionRequestHandler, public std::enable_shared_from_this<File> {
public: public:
File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path& path); File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path& path);
~File(); ~File();
@ -60,7 +60,7 @@ protected:
void HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) override; void HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) override;
}; };
class Directory final : public SessionRequestHandler { class Directory final : public Kernel::SessionRequestHandler {
public: public:
Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path& path); Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path& path);
~Directory(); ~Directory();

View File

@ -11,6 +11,7 @@
#include "core/core.h" #include "core/core.h"
#include "core/file_sys/errors.h" #include "core/file_sys/errors.h"
#include "core/hle/kernel/client_session.h" #include "core/hle/kernel/client_session.h"
#include "core/hle/kernel/server_session.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/hle/service/fs/archive.h" #include "core/hle/service/fs/archive.h"
#include "core/hle/service/fs/fs_user.h" #include "core/hle/service/fs/fs_user.h"

View File

@ -2,11 +2,10 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <boost/range/algorithm_ext/erase.hpp>
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/string_util.h" #include "common/string_util.h"
#include "core/hle/kernel/server_port.h" #include "core/hle/kernel/server_port.h"
#include "core/hle/kernel/server_session.h"
#include "core/hle/service/ac/ac.h" #include "core/hle/service/ac/ac.h"
#include "core/hle/service/act/act.h" #include "core/hle/service/act/act.h"
#include "core/hle/service/am/am.h" #include "core/hle/service/am/am.h"
@ -66,16 +65,6 @@ static std::string MakeFunctionString(const char* name, const char* port_name,
return function_string; return function_string;
} }
void SessionRequestHandler::ClientConnected(
Kernel::SharedPtr<Kernel::ServerSession> server_session) {
connected_sessions.push_back(server_session);
}
void SessionRequestHandler::ClientDisconnected(
Kernel::SharedPtr<Kernel::ServerSession> server_session) {
boost::range::remove_erase(connected_sessions, server_session);
}
Interface::Interface(u32 max_sessions) : max_sessions(max_sessions) {} Interface::Interface(u32 max_sessions) : max_sessions(max_sessions) {}
Interface::~Interface() = default; Interface::~Interface() = default;

View File

@ -12,13 +12,10 @@
#include "core/hle/ipc.h" #include "core/hle/ipc.h"
#include "core/hle/ipc_helpers.h" #include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/client_port.h" #include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/hle_ipc.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/memory.h" #include "core/memory.h"
namespace Kernel {
class ServerSession;
}
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Namespace Service // Namespace Service
@ -28,49 +25,11 @@ static const int kMaxPortSize = 8; ///< Maximum size of a port name (8 character
/// Arbitrary default number of maximum connections to an HLE service. /// Arbitrary default number of maximum connections to an HLE service.
static const u32 DefaultMaxSessions = 10; static const u32 DefaultMaxSessions = 10;
/**
* Interface implemented by HLE Session handlers.
* This can be provided to a ServerSession in order to hook into several relevant events
* (such as a new connection or a SyncRequest) so they can be implemented in the emulator.
*/
class SessionRequestHandler {
public:
/**
* Handles a sync request from the emulated application.
* @param server_session The ServerSession that was triggered for this sync request,
* it should be used to differentiate which client (As in ClientSession) we're answering to.
* TODO(Subv): Use a wrapper structure to hold all the information relevant to
* this request (ServerSession, Originator thread, Translated command buffer, etc).
* @returns ResultCode the result code of the translate operation.
*/
virtual void HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) = 0;
/**
* Signals that a client has just connected to this HLE handler and keeps the
* associated ServerSession alive for the duration of the connection.
* @param server_session Owning pointer to the ServerSession associated with the connection.
*/
void ClientConnected(Kernel::SharedPtr<Kernel::ServerSession> server_session);
/**
* Signals that a client has just disconnected from this HLE handler and releases the
* associated ServerSession.
* @param server_session ServerSession associated with the connection.
*/
void ClientDisconnected(Kernel::SharedPtr<Kernel::ServerSession> server_session);
protected:
/// List of sessions that are connected to this handler.
/// A ServerSession whose server endpoint is an HLE implementation is kept alive by this list
// for the duration of the connection.
std::vector<Kernel::SharedPtr<Kernel::ServerSession>> connected_sessions;
};
/** /**
* Framework for implementing HLE service handlers which dispatch incoming SyncRequests based on a * Framework for implementing HLE service handlers which dispatch incoming SyncRequests based on a
* table mapping header ids to handler functions. * table mapping header ids to handler functions.
*/ */
class Interface : public SessionRequestHandler { class Interface : public Kernel::SessionRequestHandler {
public: public:
/** /**
* Creates an HLE interface with the specified max sessions. * Creates an HLE interface with the specified max sessions.