diff --git a/stratosphere/loader/source/serviceserver.cpp b/stratosphere/loader/source/serviceserver.cpp new file mode 100644 index 000000000..9e428b262 --- /dev/null +++ b/stratosphere/loader/source/serviceserver.cpp @@ -0,0 +1,35 @@ +#include + +#include "serviceserver.hpp" + +template +ServiceServer::ServiceServer(const char *service_name, unsigned int max_s) : max_sessions(max_s) { + if (R_FAILED(smRegisterService(&this->port_handle, service_name, false, this->max_sessions))) { + /* TODO: Panic. */ + } + this->sessions = new ServiceSession *[this->max_sessions]; + for (unsigned int i = 0; i < this->max_sessions; i++) { + this->sessions[i] = NULL; + } +} + +template +ServiceServer::~ServiceServer() { + for (unsigned int i = 0; i < this->max_sessions; i++) { + if (this->sessions[i]) { + delete this->sessions[i]; + } + + delete this->sessions; + } + + if (port_handle) { + svcCloseHandle(port_handle); + } +} + +template +Result ServiceServer::process() { + /* TODO */ + return 0; +} \ No newline at end of file diff --git a/stratosphere/loader/source/serviceserver.hpp b/stratosphere/loader/source/serviceserver.hpp new file mode 100644 index 000000000..817e2b127 --- /dev/null +++ b/stratosphere/loader/source/serviceserver.hpp @@ -0,0 +1,24 @@ +#pragma once +#include +#include + +#include "iserviceobject.hpp" +#include "servicesession.hpp" + +template +class ServiceSession; + +template +class ServiceServer { + static_assert(std::is_base_of::value, "Service Objects must derive from IServiceObject"); + + Handle port_handle; + unsigned int max_sessions; + ServiceSession **sessions; + + public: + ServiceServer(const char *service_name, unsigned int max_s); + ~ServiceServer(); + Result process(); + +}; \ No newline at end of file diff --git a/stratosphere/loader/source/servicesession.cpp b/stratosphere/loader/source/servicesession.cpp new file mode 100644 index 000000000..550eafa8f --- /dev/null +++ b/stratosphere/loader/source/servicesession.cpp @@ -0,0 +1,4 @@ +#include + +#include "servicesession.hpp" + diff --git a/stratosphere/loader/source/servicesession.hpp b/stratosphere/loader/source/servicesession.hpp new file mode 100644 index 000000000..76cbc508e --- /dev/null +++ b/stratosphere/loader/source/servicesession.hpp @@ -0,0 +1,37 @@ +#pragma once +#include +#include + +#include "iserviceobject.hpp" +#include "serviceserver.hpp" + +template +class ServiceServer; + +template +class ServiceSession { + static_assert(std::is_base_of::value, "Service Objects must derive from IServiceObject"); + + T *service_object; + ServiceServer *server; + Handle server_handle; + Handle client_handle; + public: + ServiceSession(ServiceServer *s, Handle s_h, Handle c_h) : server(s), server_handle(s_h), client_handle(c_h) { + this->service_object = new T(); + } + + ~ServiceSession() { + delete this->service_object; + if (server_handle) { + svcCloseHandle(server_handle); + } + if (client_handle) { + svcCloseHandle(client_handle); + } + } + + T *get_service_object() { return this->service_object; } + Handle get_server_handle() { return this->server_handle; } + Handle get_client_handle() { return this->client_handle; } +}; \ No newline at end of file