2020-09-21 12:04:26 +02:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
|
2020-09-25 16:35:10 +02:00
|
|
|
#include <cxxabi.h>
|
2021-03-20 17:52:08 +01:00
|
|
|
#include <common/trace.h>
|
2020-09-21 12:04:26 +02:00
|
|
|
#include "base_service.h"
|
|
|
|
|
|
|
|
namespace skyline::service {
|
|
|
|
const std::string &BaseService::GetName() {
|
|
|
|
if (name.empty()) {
|
2020-09-26 07:17:57 +02:00
|
|
|
auto mangledName{typeid(*this).name()};
|
2020-09-21 12:04:26 +02:00
|
|
|
|
|
|
|
int status{};
|
|
|
|
size_t length{};
|
|
|
|
std::unique_ptr<char, decltype(&std::free)> demangled{abi::__cxa_demangle(mangledName, nullptr, &length, &status), std::free};
|
|
|
|
|
|
|
|
name = (status == 0) ? std::string(demangled.get() + std::char_traits<char>::length("skyline::service::")) : mangledName;
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result service::BaseService::HandleRequest(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
2021-03-19 20:49:55 +01:00
|
|
|
ServiceFunctionDescriptor function;
|
2020-09-21 12:04:26 +02:00
|
|
|
try {
|
|
|
|
function = GetServiceFunction(request.payload->value);
|
2021-03-19 20:49:55 +01:00
|
|
|
state.logger->DebugNoPrefix("Service: {}", function.name);
|
2020-09-21 12:04:26 +02:00
|
|
|
} catch (const std::out_of_range &) {
|
|
|
|
state.logger->Warn("Cannot find function in service '{0}': 0x{1:X} ({1})", GetName(), static_cast<u32>(request.payload->value));
|
|
|
|
return {};
|
|
|
|
}
|
2021-03-20 17:52:08 +01:00
|
|
|
TRACE_EVENT("service", perfetto::StaticString{function.name});
|
2020-09-21 12:04:26 +02:00
|
|
|
try {
|
2021-03-19 20:49:55 +01:00
|
|
|
return function(session, request, response);
|
2020-09-21 12:04:26 +02:00
|
|
|
} catch (const std::exception &e) {
|
2021-03-19 20:49:55 +01:00
|
|
|
throw exception("{} (Service: {})", e.what(), function.name);
|
2020-09-21 12:04:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|