diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/client_port.cpp | 23 | ||||
| -rw-r--r-- | src/core/hle/kernel/client_port.h | 29 | ||||
| -rw-r--r-- | src/core/hle/service/service.cpp | 12 | ||||
| -rw-r--r-- | src/core/hle/service/service.h | 12 |
4 files changed, 52 insertions, 24 deletions
diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp index 5ee7679eb..9a9cd4bfd 100644 --- a/src/core/hle/kernel/client_port.cpp +++ b/src/core/hle/kernel/client_port.cpp | |||
| @@ -7,16 +7,39 @@ | |||
| 7 | #include "core/hle/kernel/kernel.h" | 7 | #include "core/hle/kernel/kernel.h" |
| 8 | #include "core/hle/kernel/server_port.h" | 8 | #include "core/hle/kernel/server_port.h" |
| 9 | #include "core/hle/kernel/server_session.h" | 9 | #include "core/hle/kernel/server_session.h" |
| 10 | #include "core/hle/service/service.h" | ||
| 10 | 11 | ||
| 11 | namespace Kernel { | 12 | namespace Kernel { |
| 12 | 13 | ||
| 13 | ClientPort::ClientPort() {} | 14 | ClientPort::ClientPort() {} |
| 14 | ClientPort::~ClientPort() {} | 15 | ClientPort::~ClientPort() {} |
| 15 | 16 | ||
| 17 | Kernel::SharedPtr<ClientPort> ClientPort::CreateForHLE(u32 max_sessions, std::unique_ptr<Service::Interface> hle_interface) { | ||
| 18 | SharedPtr<ClientPort> client_port(new ClientPort); | ||
| 19 | client_port->max_sessions = max_sessions; | ||
| 20 | client_port->active_sessions = 0; | ||
| 21 | client_port->name = hle_interface->GetPortName(); | ||
| 22 | client_port->hle_interface = std::move(hle_interface); | ||
| 23 | |||
| 24 | return client_port; | ||
| 25 | } | ||
| 26 | |||
| 16 | void ClientPort::AddWaitingSession(SharedPtr<ServerSession> server_session) { | 27 | void ClientPort::AddWaitingSession(SharedPtr<ServerSession> server_session) { |
| 28 | // A port that has an associated HLE interface doesn't have a server port. | ||
| 29 | if (hle_interface != nullptr) | ||
| 30 | return; | ||
| 31 | |||
| 17 | server_port->pending_sessions.push_back(server_session); | 32 | server_port->pending_sessions.push_back(server_session); |
| 18 | // Wake the threads waiting on the ServerPort | 33 | // Wake the threads waiting on the ServerPort |
| 19 | server_port->WakeupAllWaitingThreads(); | 34 | server_port->WakeupAllWaitingThreads(); |
| 20 | } | 35 | } |
| 21 | 36 | ||
| 37 | ResultCode ClientPort::HandleSyncRequest() { | ||
| 38 | // Forward the request to the associated HLE interface if it exists | ||
| 39 | if (hle_interface != nullptr) | ||
| 40 | return hle_interface->HandleSyncRequest(); | ||
| 41 | |||
| 42 | return RESULT_SUCCESS; | ||
| 43 | } | ||
| 44 | |||
| 22 | } // namespace | 45 | } // namespace |
diff --git a/src/core/hle/kernel/client_port.h b/src/core/hle/kernel/client_port.h index eb0882870..ee65606ba 100644 --- a/src/core/hle/kernel/client_port.h +++ b/src/core/hle/kernel/client_port.h | |||
| @@ -5,19 +5,32 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <string> | 7 | #include <string> |
| 8 | #include <memory> | ||
| 8 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 9 | #include "core/hle/kernel/kernel.h" | 10 | #include "core/hle/kernel/kernel.h" |
| 10 | 11 | ||
| 12 | namespace Service { | ||
| 13 | class Interface; | ||
| 14 | } | ||
| 15 | |||
| 11 | namespace Kernel { | 16 | namespace Kernel { |
| 12 | 17 | ||
| 13 | class ServerPort; | 18 | class ServerPort; |
| 14 | class ServerSession; | 19 | class ServerSession; |
| 15 | 20 | ||
| 16 | class ClientPort : public Object { | 21 | class ClientPort final : public Object { |
| 17 | public: | 22 | public: |
| 18 | friend class ServerPort; | 23 | friend class ServerPort; |
| 19 | 24 | ||
| 20 | /** | 25 | /** |
| 26 | * Creates a serverless ClientPort that represents a bridge between the HLE implementation of a service/port and the emulated application. | ||
| 27 | * @param max_sessions Maximum number of sessions that this port is able to handle concurrently. | ||
| 28 | * @param hle_interface Interface object that implements the commands of the service. | ||
| 29 | * @returns ClientPort for the given HLE interface. | ||
| 30 | */ | ||
| 31 | static Kernel::SharedPtr<ClientPort> CreateForHLE(u32 max_sessions, std::unique_ptr<Service::Interface> hle_interface); | ||
| 32 | |||
| 33 | /** | ||
| 21 | * Adds the specified server session to the queue of pending sessions of the associated ServerPort | 34 | * Adds the specified server session to the queue of pending sessions of the associated ServerPort |
| 22 | * @param server_session Server session to add to the queue | 35 | * @param server_session Server session to add to the queue |
| 23 | */ | 36 | */ |
| @@ -25,10 +38,9 @@ public: | |||
| 25 | 38 | ||
| 26 | /** | 39 | /** |
| 27 | * Handle a sync request from the emulated application. | 40 | * Handle a sync request from the emulated application. |
| 28 | * Only HLE services should override this function. | ||
| 29 | * @returns ResultCode from the operation. | 41 | * @returns ResultCode from the operation. |
| 30 | */ | 42 | */ |
| 31 | virtual ResultCode HandleSyncRequest() { return RESULT_SUCCESS; } | 43 | ResultCode HandleSyncRequest(); |
| 32 | 44 | ||
| 33 | std::string GetTypeName() const override { return "ClientPort"; } | 45 | std::string GetTypeName() const override { return "ClientPort"; } |
| 34 | std::string GetName() const override { return name; } | 46 | std::string GetName() const override { return name; } |
| @@ -38,12 +50,13 @@ public: | |||
| 38 | return HANDLE_TYPE; | 50 | return HANDLE_TYPE; |
| 39 | } | 51 | } |
| 40 | 52 | ||
| 41 | SharedPtr<ServerPort> server_port; ///< ServerPort associated with this client port. | 53 | SharedPtr<ServerPort> server_port = nullptr; ///< ServerPort associated with this client port. |
| 42 | u32 max_sessions; ///< Maximum number of simultaneous sessions the port can have | 54 | u32 max_sessions; ///< Maximum number of simultaneous sessions the port can have |
| 43 | u32 active_sessions; ///< Number of currently open sessions to this port | 55 | u32 active_sessions; ///< Number of currently open sessions to this port |
| 44 | std::string name; ///< Name of client port (optional) | 56 | std::string name; ///< Name of client port (optional) |
| 57 | std::unique_ptr<Service::Interface> hle_interface = nullptr; ///< HLE implementation of this port's request handler | ||
| 45 | 58 | ||
| 46 | protected: | 59 | private: |
| 47 | ClientPort(); | 60 | ClientPort(); |
| 48 | ~ClientPort() override; | 61 | ~ClientPort() override; |
| 49 | }; | 62 | }; |
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index f51a042ff..abfc1806b 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -97,17 +97,13 @@ void Interface::Register(const FunctionInfo* functions, size_t n) { | |||
| 97 | // Module interface | 97 | // Module interface |
| 98 | 98 | ||
| 99 | static void AddNamedPort(Interface* interface_) { | 99 | static void AddNamedPort(Interface* interface_) { |
| 100 | interface_->name = interface_->GetPortName(); | 100 | auto client_port = Kernel::ClientPort::CreateForHLE(interface_->GetMaxSessions(), std::unique_ptr<Interface>(interface_)); |
| 101 | interface_->active_sessions = 0; | 101 | g_kernel_named_ports.emplace(interface_->GetPortName(), client_port); |
| 102 | interface_->max_sessions = interface_->GetMaxSessions(); | ||
| 103 | g_kernel_named_ports.emplace(interface_->GetPortName(), interface_); | ||
| 104 | } | 102 | } |
| 105 | 103 | ||
| 106 | void AddService(Interface* interface_) { | 104 | void AddService(Interface* interface_) { |
| 107 | interface_->name = interface_->GetPortName(); | 105 | auto client_port = Kernel::ClientPort::CreateForHLE(interface_->GetMaxSessions(), std::unique_ptr<Interface>(interface_)); |
| 108 | interface_->active_sessions = 0; | 106 | g_srv_services.emplace(interface_->GetPortName(), client_port); |
| 109 | interface_->max_sessions = interface_->GetMaxSessions(); | ||
| 110 | g_srv_services.emplace(interface_->GetPortName(), interface_); | ||
| 111 | } | 107 | } |
| 112 | 108 | ||
| 113 | /// Initialize ServiceManager | 109 | /// Initialize ServiceManager |
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 8df968b2e..b22caca07 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h | |||
| @@ -22,18 +22,16 @@ static const int kMaxPortSize = 8; ///< Maximum size of a port name (8 character | |||
| 22 | static const u32 DefaultMaxSessions = 10; ///< Arbitrary default number of maximum connections to an HLE port | 22 | static const u32 DefaultMaxSessions = 10; ///< Arbitrary default number of maximum connections to an HLE port |
| 23 | 23 | ||
| 24 | /// Interface to a CTROS service | 24 | /// Interface to a CTROS service |
| 25 | class Interface : public Kernel::ClientPort { | 25 | class Interface { |
| 26 | // TODO(yuriks): An "Interface" being a Kernel::Object is mostly non-sense. Interface should be | ||
| 27 | // just something that encapsulates a session and acts as a helper to implement service | ||
| 28 | // processes. | ||
| 29 | public: | 26 | public: |
| 30 | std::string GetName() const override { | 27 | std::string GetName() const { |
| 31 | return GetPortName(); | 28 | return GetPortName(); |
| 32 | } | 29 | } |
| 33 | 30 | ||
| 34 | virtual void SetVersion(u32 raw_version) { | 31 | virtual void SetVersion(u32 raw_version) { |
| 35 | version.raw = raw_version; | 32 | version.raw = raw_version; |
| 36 | } | 33 | } |
| 34 | virtual ~Interface() {} | ||
| 37 | 35 | ||
| 38 | /** | 36 | /** |
| 39 | * Gets the maximum allowed number of sessions that can be connected to this port at the same time. | 37 | * Gets the maximum allowed number of sessions that can be connected to this port at the same time. |
| @@ -42,8 +40,6 @@ public: | |||
| 42 | */ | 40 | */ |
| 43 | virtual u32 GetMaxSessions() const { return DefaultMaxSessions; } | 41 | virtual u32 GetMaxSessions() const { return DefaultMaxSessions; } |
| 44 | 42 | ||
| 45 | void AddWaitingSession(Kernel::SharedPtr<Kernel::ServerSession> server_session) override { } | ||
| 46 | |||
| 47 | typedef void (*Function)(Interface*); | 43 | typedef void (*Function)(Interface*); |
| 48 | 44 | ||
| 49 | struct FunctionInfo { | 45 | struct FunctionInfo { |
| @@ -60,7 +56,7 @@ public: | |||
| 60 | return "[UNKNOWN SERVICE PORT]"; | 56 | return "[UNKNOWN SERVICE PORT]"; |
| 61 | } | 57 | } |
| 62 | 58 | ||
| 63 | ResultCode HandleSyncRequest() override; | 59 | ResultCode HandleSyncRequest(); |
| 64 | 60 | ||
| 65 | protected: | 61 | protected: |
| 66 | /** | 62 | /** |