2017-06-05 04:52:19 +00:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-06-09 06:52:30 +00:00
|
|
|
#include <array>
|
2017-06-06 05:39:26 +00:00
|
|
|
#include <memory>
|
2017-06-05 04:52:19 +00:00
|
|
|
#include <vector>
|
2017-06-09 06:52:30 +00:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "core/hle/ipc.h"
|
2017-06-05 04:52:19 +00:00
|
|
|
#include "core/hle/kernel/kernel.h"
|
2017-06-07 04:20:52 +00:00
|
|
|
#include "core/hle/kernel/server_session.h"
|
2017-06-05 04:52:19 +00:00
|
|
|
|
2017-06-07 04:20:52 +00:00
|
|
|
namespace Service {
|
|
|
|
class ServiceFrameworkBase;
|
|
|
|
}
|
2017-06-05 04:52:19 +00:00
|
|
|
|
2017-06-07 04:20:52 +00:00
|
|
|
namespace Kernel {
|
2017-06-05 04:52:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-06-06 05:39:26 +00:00
|
|
|
class SessionRequestHandler : public std::enable_shared_from_this<SessionRequestHandler> {
|
2017-06-05 04:52:19 +00:00
|
|
|
public:
|
2017-06-06 21:51:42 +00:00
|
|
|
virtual ~SessionRequestHandler() = default;
|
|
|
|
|
2017-06-05 04:52:19 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-06-06 21:51:42 +00:00
|
|
|
virtual void HandleSyncRequest(SharedPtr<ServerSession> server_session) = 0;
|
2017-06-05 04:52:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-06-06 21:51:42 +00:00
|
|
|
void ClientConnected(SharedPtr<ServerSession> server_session);
|
2017-06-05 04:52:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that a client has just disconnected from this HLE handler and releases the
|
|
|
|
* associated ServerSession.
|
|
|
|
* @param server_session ServerSession associated with the connection.
|
|
|
|
*/
|
2017-06-06 21:51:42 +00:00
|
|
|
void ClientDisconnected(SharedPtr<ServerSession> server_session);
|
2017-06-05 04:52:19 +00:00
|
|
|
|
|
|
|
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.
|
2017-06-06 21:51:42 +00:00
|
|
|
std::vector<SharedPtr<ServerSession>> connected_sessions;
|
2017-06-05 04:52:19 +00:00
|
|
|
};
|
|
|
|
|
2017-06-07 04:20:52 +00:00
|
|
|
/**
|
|
|
|
* Class containing information about an in-flight IPC request being handled by an HLE service
|
|
|
|
* implementation. Services should avoid using old global APIs (e.g. Kernel::GetCommandBuffer()) and
|
|
|
|
* when possible use the APIs in this class to service the request.
|
|
|
|
*/
|
|
|
|
class HLERequestContext {
|
|
|
|
public:
|
|
|
|
~HLERequestContext();
|
|
|
|
|
|
|
|
/// Returns a pointer to the IPC command buffer for this request.
|
2017-06-09 06:52:30 +00:00
|
|
|
u32* CommandBuffer() {
|
|
|
|
return cmd_buf.data();
|
2017-06-07 04:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the session through which this request was made. This can be used as a map key to
|
|
|
|
* access per-client data on services.
|
|
|
|
*/
|
|
|
|
SharedPtr<ServerSession> Session() const {
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2017-06-09 06:55:18 +00:00
|
|
|
SharedPtr<Object> GetIncomingHandle(Handle id_from_cmdbuf) const;
|
|
|
|
Handle AddOutgoingHandle(SharedPtr<Object> object);
|
|
|
|
|
2017-06-07 04:20:52 +00:00
|
|
|
private:
|
|
|
|
friend class Service::ServiceFrameworkBase;
|
|
|
|
|
2017-06-09 06:52:30 +00:00
|
|
|
std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf;
|
2017-06-07 04:20:52 +00:00
|
|
|
SharedPtr<ServerSession> session;
|
|
|
|
};
|
|
|
|
|
2017-06-05 04:52:19 +00:00
|
|
|
} // namespace Kernel
|