2021-02-11 03:36:35 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2021-02-11 03:36:35 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include "htcs_manager_service_object.hpp"
|
|
|
|
#include "htcs_socket_service_object.hpp"
|
2021-02-17 12:08:58 +00:00
|
|
|
#include "htcs_service_object_allocator.hpp"
|
|
|
|
#include "../impl/htcs_manager.hpp"
|
|
|
|
#include "../impl/htcs_impl.hpp"
|
2021-02-11 03:36:35 +00:00
|
|
|
|
|
|
|
namespace ams::htcs::server {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class StaticAllocatorInitializer {
|
|
|
|
public:
|
|
|
|
StaticAllocatorInitializer() {
|
|
|
|
ServiceObjectAllocator::Initialize(lmem::CreateOption_ThreadSafe);
|
|
|
|
}
|
|
|
|
} g_static_allocator_initializer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerServiceObject::GetPeerNameAny(sf::Out<htcs::HtcsPeerName> out) {
|
2021-02-17 12:08:58 +00:00
|
|
|
*out = impl::GetPeerNameAny();
|
|
|
|
return ResultSuccess();
|
2021-02-11 03:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerServiceObject::GetDefaultHostName(sf::Out<htcs::HtcsPeerName> out) {
|
2021-02-17 12:08:58 +00:00
|
|
|
*out = impl::GetDefaultHostName();
|
|
|
|
return ResultSuccess();
|
2021-02-11 03:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerServiceObject::CreateSocketOld(sf::Out<s32> out_err, sf::Out<sf::SharedPointer<tma::ISocket>> out) {
|
|
|
|
return this->CreateSocket(out_err, out, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerServiceObject::CreateSocket(sf::Out<s32> out_err, sf::Out<sf::SharedPointer<tma::ISocket>> out, bool enable_disconnection_emulation) {
|
2021-02-17 12:08:58 +00:00
|
|
|
/* Get the htcs manager. */
|
|
|
|
auto *manager = impl::HtcsManagerHolder::GetHtcsManager();
|
|
|
|
|
|
|
|
/* Create a new socket. */
|
|
|
|
s32 desc;
|
|
|
|
manager->Socket(out_err.GetPointer(), std::addressof(desc), enable_disconnection_emulation);
|
|
|
|
|
|
|
|
/* If an error occurred, we're done. */
|
|
|
|
R_SUCCEED_IF(*out_err != 0);
|
|
|
|
|
|
|
|
/* Create a new socket object. */
|
|
|
|
*out = ServiceObjectFactory::CreateSharedEmplaced<tma::ISocket, SocketServiceObject>(this, desc);
|
|
|
|
|
|
|
|
return ResultSuccess();
|
2021-02-11 03:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerServiceObject::RegisterProcessId(const sf::ClientProcessId &client_pid) {
|
2021-02-11 13:47:41 +00:00
|
|
|
/* NOTE: Nintendo does nothing here. */
|
2021-02-11 03:36:35 +00:00
|
|
|
return ResultSuccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerServiceObject::MonitorManager(const sf::ClientProcessId &client_pid) {
|
2021-02-11 13:47:41 +00:00
|
|
|
/* NOTE: Nintendo does nothing here. */
|
2021-02-11 03:36:35 +00:00
|
|
|
return ResultSuccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
Result ManagerServiceObject::StartSelect(sf::Out<u32> out_task_id, sf::OutCopyHandle out_event, const sf::InMapAliasArray<s32> &read_handles, const sf::InMapAliasArray<s32> &write_handles, const sf::InMapAliasArray<s32> &exception_handles, s64 tv_sec, s64 tv_usec) {
|
2021-02-17 12:08:58 +00:00
|
|
|
/* Get the htcs manager. */
|
|
|
|
auto *manager = impl::HtcsManagerHolder::GetHtcsManager();
|
|
|
|
|
|
|
|
/* Start the select. */
|
2021-02-19 05:24:30 +00:00
|
|
|
R_TRY(manager->StartSelect(out_task_id.GetPointer(), out_event.GetHandlePointer(), read_handles.ToSpan(), write_handles.ToSpan(), exception_handles.ToSpan(), tv_sec, tv_usec));
|
|
|
|
|
|
|
|
/* Mark the output event as managed. */
|
|
|
|
out_event.SetManaged(true);
|
|
|
|
return ResultSuccess();
|
2021-02-11 03:36:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 03:14:59 +00:00
|
|
|
Result ManagerServiceObject::EndSelect(sf::Out<s32> out_err, sf::Out<s32> out_count, const sf::OutMapAliasArray<s32> &read_handles, const sf::OutMapAliasArray<s32> &write_handles, const sf::OutMapAliasArray<s32> &exception_handles, u32 task_id) {
|
2021-02-17 12:08:58 +00:00
|
|
|
/* Get the htcs manager. */
|
|
|
|
auto *manager = impl::HtcsManagerHolder::GetHtcsManager();
|
|
|
|
|
|
|
|
/* End the select. */
|
2021-02-18 03:14:59 +00:00
|
|
|
return manager->EndSelect(out_err.GetPointer(), out_count.GetPointer(), read_handles.ToSpan(), write_handles.ToSpan(), exception_handles.ToSpan(), task_id);
|
2021-02-11 03:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|