mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-09 13:41:43 +00:00
Stratosphere: Skeleton templated IPC Server code
This commit is contained in:
parent
5345d7c206
commit
8e25534912
4 changed files with 100 additions and 0 deletions
35
stratosphere/loader/source/serviceserver.cpp
Normal file
35
stratosphere/loader/source/serviceserver.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <switch.h>
|
||||
|
||||
#include "serviceserver.hpp"
|
||||
|
||||
template <typename T>
|
||||
ServiceServer<T>::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<T> *[this->max_sessions];
|
||||
for (unsigned int i = 0; i < this->max_sessions; i++) {
|
||||
this->sessions[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ServiceServer<T>::~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 <typename T>
|
||||
Result ServiceServer<T>::process() {
|
||||
/* TODO */
|
||||
return 0;
|
||||
}
|
24
stratosphere/loader/source/serviceserver.hpp
Normal file
24
stratosphere/loader/source/serviceserver.hpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <type_traits>
|
||||
|
||||
#include "iserviceobject.hpp"
|
||||
#include "servicesession.hpp"
|
||||
|
||||
template <typename T>
|
||||
class ServiceSession;
|
||||
|
||||
template <typename T>
|
||||
class ServiceServer {
|
||||
static_assert(std::is_base_of<IServiceObject, T>::value, "Service Objects must derive from IServiceObject");
|
||||
|
||||
Handle port_handle;
|
||||
unsigned int max_sessions;
|
||||
ServiceSession<T> **sessions;
|
||||
|
||||
public:
|
||||
ServiceServer(const char *service_name, unsigned int max_s);
|
||||
~ServiceServer();
|
||||
Result process();
|
||||
|
||||
};
|
4
stratosphere/loader/source/servicesession.cpp
Normal file
4
stratosphere/loader/source/servicesession.cpp
Normal file
|
@ -0,0 +1,4 @@
|
|||
#include <switch.h>
|
||||
|
||||
#include "servicesession.hpp"
|
||||
|
37
stratosphere/loader/source/servicesession.hpp
Normal file
37
stratosphere/loader/source/servicesession.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <type_traits>
|
||||
|
||||
#include "iserviceobject.hpp"
|
||||
#include "serviceserver.hpp"
|
||||
|
||||
template <typename T>
|
||||
class ServiceServer;
|
||||
|
||||
template <typename T>
|
||||
class ServiceSession {
|
||||
static_assert(std::is_base_of<IServiceObject, T>::value, "Service Objects must derive from IServiceObject");
|
||||
|
||||
T *service_object;
|
||||
ServiceServer<T> *server;
|
||||
Handle server_handle;
|
||||
Handle client_handle;
|
||||
public:
|
||||
ServiceSession(ServiceServer<T> *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; }
|
||||
};
|
Loading…
Reference in a new issue