diff --git a/include/stratosphere/mitm/mitm_server.hpp b/include/stratosphere/mitm/mitm_server.hpp index 0529c851..5dd20ff1 100644 --- a/include/stratosphere/mitm/mitm_server.hpp +++ b/include/stratosphere/mitm/mitm_server.hpp @@ -21,7 +21,7 @@ #include "sm_mitm.h" #include "mitm_session.hpp" -template +template class MitmServer : public IWaitable { static_assert(std::is_base_of::value, "MitM Service Objects must derive from IMitmServiceObject"); private: @@ -29,8 +29,14 @@ class MitmServer : public IWaitable { unsigned int max_sessions; char mitm_name[9]; + std::tuple args; + + template + static std::shared_ptr ConstructionDetailHelper(std::shared_ptr forward_service, u64 client_pid, std::tuple &&tuple, std::index_sequence) { + return std::make_shared(forward_service, client_pid, std::forward(std::get(std::forward>(tuple)))...); + } public: - MitmServer(Handle *out_query_h, const char *service_name, unsigned int max_s) : port_handle(0), max_sessions(max_s) { + MitmServer(Handle *out_query_h, const char *service_name, unsigned int max_s, Args... args) : port_handle(0), max_sessions(max_s), args(std::forward_as_tuple(std::forward(args))...) { Handle tmp_hnd; Result rc = smMitMInitialize(); if (R_FAILED(rc)) { @@ -97,16 +103,16 @@ class MitmServer : public IWaitable { smMitMExit(); - this->GetSessionManager()->AddWaitable(new MitmSession(session_h, client_pid, forward_service, std::make_shared(forward_service, client_pid))); + this->GetSessionManager()->AddWaitable(new MitmSession(session_h, client_pid, forward_service, ConstructionDetailHelper(forward_service, client_pid, std::forward>(args), std::index_sequence_for()))); return 0; } }; -template -static void AddMitmServerToManager(SessionManagerBase *manager, const char *srv_name, unsigned int max_sessions) { +template +static void AddMitmServerToManager(SessionManagerBase *manager, const char *srv_name, unsigned int max_sessions, Args... args) { Handle query_h; - auto *srv = new MitmServer(&query_h, srv_name, max_sessions); + auto *srv = new MitmServer(&query_h, srv_name, max_sessions, std::forward(args)...); manager->AddSession(query_h, std::move(ServiceObjectHolder(std::move(std::make_shared>())))); manager->AddWaitable(srv); } diff --git a/include/stratosphere/servers.hpp b/include/stratosphere/servers.hpp index 7771157f..08479762 100644 --- a/include/stratosphere/servers.hpp +++ b/include/stratosphere/servers.hpp @@ -17,18 +17,27 @@ #pragma once #include +#include + #include "iwaitable.hpp" #include "ipc.hpp" -template +template class IServer : public IWaitable { static_assert(std::is_base_of::value, "Service Objects must derive from IServiceObject"); protected: Handle port_handle; unsigned int max_sessions; - + + private: + std::tuple args; + + template + static std::shared_ptr ConstructionDetailHelper(std::tuple &&tuple, std::index_sequence) { + return std::make_shared(std::forward(std::get(std::forward>(tuple)))...); + } public: - IServer(unsigned int max_s) : port_handle(0), max_sessions(max_s) { } + IServer(unsigned int max_s, Args... args) : port_handle(0), max_sessions(max_s), args(std::forward_as_tuple(std::forward(args))...) { } virtual ~IServer() { if (port_handle) { @@ -53,35 +62,35 @@ class IServer : public IWaitable { return rc; } - this->GetSessionManager()->AddSession(session_h, std::move(ServiceObjectHolder(std::move(std::make_shared())))); + this->GetSessionManager()->AddSession(session_h, std::move(ServiceObjectHolder(std::move(ConstructionDetailHelper(std::forward>(args), std::index_sequence_for()))))); return 0; } }; -template -class ServiceServer : public IServer { +template +class ServiceServer : public IServer { public: - ServiceServer(const char *service_name, unsigned int max_s) : IServer(max_s) { + ServiceServer(const char *service_name, unsigned int max_s, Args... args) : IServer(max_s, std::forward(args)...) { if (R_FAILED(smRegisterService(&this->port_handle, service_name, false, this->max_sessions))) { /* TODO: Panic. */ } } }; -template -class ExistingPortServer : public IServer { +template +class ExistingPortServer : public IServer { public: - ExistingPortServer(Handle port_h, unsigned int max_s) : IServer(max_s) { + ExistingPortServer(Handle port_h, unsigned int max_s, Args... args) : IServer(max_s, args...) { this->port_handle = port_h; } }; -template -class ManagedPortServer : public IServer { +template +class ManagedPortServer : public IServer { public: - ManagedPortServer(const char *service_name, unsigned int max_s) : IServer(max_s) { + ManagedPortServer(const char *service_name, unsigned int max_s, Args... args) : IServer(max_s, args...) { if (R_FAILED(svcManageNamedPort(&this->port_handle, service_name, this->max_sessions))) { /* TODO: panic */ } } -}; \ No newline at end of file +};