mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-10-19 15:15:46 +02:00
* Stratosphere: Use modern C++ idioms in some places * algorithms like std::for_each are used instead of raw loops * Stratosphere: Replace more raw loops with algorithms * Stratosphere: Add a utility predicate function to test for equality with a reference element This can be used to rewrite some common raw loops using algorithms instead * fs.mitm: Use variant * fs.mitm: Use enum class * fs.mitm: Turn RomFSSourceInfo::Cleanup into a destructor This obsoletes the need for a custom deleter in other places * fs.mitm: Use enum class some more * fs.mitm: Use unique_ptr * fs.mitm: Simplify initialization * Stratosphere: Simplify initialization * fs.mitm: Use unique_ptr (fix memory leak along the way) The previous code was using "delete" rather than "delete[]" * fs.mitm: Use vector::emplace_back rather than push_back emplace_back constructs elements in-place, hence avoiding a redundant element copy. * Stratosphere: Replace more raw loops with algorithms * Stratosphere: Use unique_ptr * fs.mitm: Replace more raw loops with algorithms * Stratosphere: Prefer move-construction over copy-construction when moving sink parameters around
56 lines
1.6 KiB
C++
56 lines
1.6 KiB
C++
#pragma once
|
|
#include <switch.h>
|
|
#include <algorithm>
|
|
#include <type_traits>
|
|
|
|
#include "iserviceobject.hpp"
|
|
#include "iwaitable.hpp"
|
|
#include "isession.hpp"
|
|
|
|
template <typename T>
|
|
class ISession;
|
|
|
|
template <typename T>
|
|
class IServer : public IWaitable {
|
|
static_assert(std::is_base_of<IServiceObject, T>::value, "Service Objects must derive from IServiceObject");
|
|
protected:
|
|
Handle port_handle;
|
|
unsigned int max_sessions;
|
|
bool supports_domains;
|
|
|
|
public:
|
|
IServer(const char *service_name, unsigned int max_s, bool s_d = false) : max_sessions(max_s), supports_domains(s_d) {
|
|
|
|
}
|
|
|
|
virtual ~IServer() {
|
|
if (port_handle) {
|
|
svcCloseHandle(port_handle);
|
|
}
|
|
}
|
|
|
|
virtual ISession<T> *get_new_session(Handle session_h) = 0;
|
|
|
|
/* IWaitable */
|
|
virtual Handle get_handle() {
|
|
return this->port_handle;
|
|
}
|
|
|
|
|
|
virtual void handle_deferred() {
|
|
/* TODO: Panic, because we can never defer a server. */
|
|
}
|
|
|
|
virtual Result handle_signaled(u64 timeout) {
|
|
/* If this server's port was signaled, accept a new session. */
|
|
Handle session_h;
|
|
Result rc = svcAcceptSession(&session_h, this->port_handle);
|
|
if (R_FAILED(rc)) {
|
|
return rc;
|
|
}
|
|
|
|
this->get_manager()->add_waitable(this->get_new_session(session_h));
|
|
return 0;
|
|
}
|
|
};
|