Give frontend access to the hle service interfaces

This commit is contained in:
B3n30 2018-10-03 19:05:31 +02:00
parent 874a95cea7
commit d3694a930e
3 changed files with 24 additions and 6 deletions

View file

@ -7,11 +7,11 @@
#include <string> #include <string>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/kernel/object.h" #include "core/hle/kernel/object.h"
#include "core/hle/kernel/server_port.h"
#include "core/hle/result.h" #include "core/hle/result.h"
namespace Kernel { namespace Kernel {
class ServerPort;
class ClientSession; class ClientSession;
class ClientPort final : public Object { class ClientPort final : public Object {
@ -29,6 +29,10 @@ public:
return HANDLE_TYPE; return HANDLE_TYPE;
} }
SharedPtr<ServerPort> GetServerPort() const {
return server_port;
}
/** /**
* Creates a new Session pair, adds the created ServerSession to the associated ServerPort's * 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 * list of pending sessions, and signals the ServerPort, causing any threads

View file

@ -4,9 +4,7 @@
#include <tuple> #include <tuple>
#include "common/assert.h" #include "common/assert.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/server_port.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/hle/service/sm/sm.h" #include "core/hle/service/sm/sm.h"
#include "core/hle/service/sm/srv.h" #include "core/hle/service/sm/srv.h"

View file

@ -6,16 +6,16 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <type_traits>
#include <unordered_map> #include <unordered_map>
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/object.h" #include "core/hle/kernel/object.h"
#include "core/hle/kernel/server_port.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
namespace Kernel { namespace Kernel {
class ClientPort;
class ClientSession; class ClientSession;
class ServerPort;
class SessionRequestHandler; class SessionRequestHandler;
} // namespace Kernel } // namespace Kernel
@ -46,6 +46,22 @@ public:
ResultVal<Kernel::SharedPtr<Kernel::ClientPort>> GetServicePort(const std::string& name); ResultVal<Kernel::SharedPtr<Kernel::ClientPort>> GetServicePort(const std::string& name);
ResultVal<Kernel::SharedPtr<Kernel::ClientSession>> ConnectToService(const std::string& name); ResultVal<Kernel::SharedPtr<Kernel::ClientSession>> ConnectToService(const std::string& name);
template <typename T>
std::shared_ptr<T> GetService(const std::string& service_name) {
static_assert(std::is_base_of_v<Kernel::SessionRequestHandler, T>,
"Not a base of ServiceFrameworkBase");
auto service = registered_services.find(service_name);
if (service == registered_services.end()) {
LOG_DEBUG(Service, "Can't find service: {}", service_name);
return nullptr;
}
auto port = service->second->GetServerPort();
if (port == nullptr) {
return nullptr;
}
return std::dynamic_pointer_cast<T>(port->hle_handler);
}
private: private:
std::weak_ptr<SRV> srv_interface; std::weak_ptr<SRV> srv_interface;