fix missing function name
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
parent
bf2bdd1b5d
commit
883de836c6
@ -374,13 +374,13 @@ auto fuse_base::init_impl(struct fuse_conn_info *conn) -> void * {
|
|||||||
if (not utils::file::change_to_process_directory()) {
|
if (not utils::file::change_to_process_directory()) {
|
||||||
utils::error::raise_error(function_name,
|
utils::error::raise_error(function_name,
|
||||||
"failed to change to process directory");
|
"failed to change to process directory");
|
||||||
event_system::instance().raise<unmount_requested>();
|
event_system::instance().raise<unmount_requested>(function_name);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not console_enabled_ && not repertory::project_initialize()) {
|
if (not console_enabled_ && not repertory::project_initialize()) {
|
||||||
utils::error::raise_error(function_name, "failed to initialize repertory");
|
utils::error::raise_error(function_name, "failed to initialize repertory");
|
||||||
event_system::instance().raise<unmount_requested>();
|
event_system::instance().raise<unmount_requested>(function_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -259,7 +259,7 @@ auto remote_fuse_drive::init_impl(struct fuse_conn_info *conn) -> void * {
|
|||||||
if (remote_instance_->fuse_init() != 0) {
|
if (remote_instance_->fuse_init() != 0) {
|
||||||
utils::error::raise_error(function_name,
|
utils::error::raise_error(function_name,
|
||||||
"failed to connect to remote server");
|
"failed to connect to remote server");
|
||||||
event_system::instance().raise<unmount_requested>();
|
event_system::instance().raise<unmount_requested>(function_name);
|
||||||
} else {
|
} else {
|
||||||
server_ = std::make_shared<server>(config_);
|
server_ = std::make_shared<server>(config_);
|
||||||
server_->start();
|
server_->start();
|
||||||
|
@ -1,187 +1,189 @@
|
|||||||
/*
|
/*
|
||||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "rpc/server/server.hpp"
|
#include "rpc/server/server.hpp"
|
||||||
|
|
||||||
#include "app_config.hpp"
|
#include "app_config.hpp"
|
||||||
#include "events/event_system.hpp"
|
#include "events/event_system.hpp"
|
||||||
#include "events/types/service_start_begin.hpp"
|
#include "events/types/service_start_begin.hpp"
|
||||||
#include "events/types/service_start_end.hpp"
|
#include "events/types/service_start_end.hpp"
|
||||||
#include "events/types/service_stop_begin.hpp"
|
#include "events/types/service_stop_begin.hpp"
|
||||||
#include "events/types/service_stop_end.hpp"
|
#include "events/types/service_stop_end.hpp"
|
||||||
#include "events/types/unmount_requested.hpp"
|
#include "events/types/unmount_requested.hpp"
|
||||||
#include "rpc/common.hpp"
|
#include "rpc/common.hpp"
|
||||||
#include "utils/error_utils.hpp"
|
#include "utils/error_utils.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
server::server(app_config &config) : config_(config) {}
|
server::server(app_config &config) : config_(config) {}
|
||||||
|
|
||||||
void server::handle_get_config(const httplib::Request & /*req*/,
|
void server::handle_get_config(const httplib::Request & /*req*/,
|
||||||
httplib::Response &res) {
|
httplib::Response &res) {
|
||||||
auto data = config_.get_json();
|
auto data = config_.get_json();
|
||||||
clean_json_config(config_.get_provider_type(), data);
|
clean_json_config(config_.get_provider_type(), data);
|
||||||
res.set_content(data.dump(), "application/json");
|
res.set_content(data.dump(), "application/json");
|
||||||
res.status = http_error_codes::ok;
|
res.status = http_error_codes::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void server::handle_get_config_value_by_name(const httplib::Request &req,
|
void server::handle_get_config_value_by_name(const httplib::Request &req,
|
||||||
httplib::Response &res) {
|
httplib::Response &res) {
|
||||||
auto name = req.get_param_value("name");
|
auto name = req.get_param_value("name");
|
||||||
auto data = json({{
|
auto data = json({{
|
||||||
"value",
|
"value",
|
||||||
clean_json_value(name, config_.get_value_by_name(name)),
|
clean_json_value(name, config_.get_value_by_name(name)),
|
||||||
}});
|
}});
|
||||||
res.set_content(data.dump(), "application/json");
|
res.set_content(data.dump(), "application/json");
|
||||||
res.status = http_error_codes::ok;
|
res.status = http_error_codes::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void server::handle_set_config_value_by_name(const httplib::Request &req,
|
void server::handle_set_config_value_by_name(const httplib::Request &req,
|
||||||
httplib::Response &res) {
|
httplib::Response &res) {
|
||||||
auto name = req.get_param_value("name");
|
auto name = req.get_param_value("name");
|
||||||
auto value = req.get_param_value("value");
|
auto value = req.get_param_value("value");
|
||||||
|
|
||||||
json data = {{
|
json data = {{
|
||||||
"value",
|
"value",
|
||||||
clean_json_value(name, config_.set_value_by_name(name, value)),
|
clean_json_value(name, config_.set_value_by_name(name, value)),
|
||||||
}};
|
}};
|
||||||
res.set_content(data.dump(), "application/json");
|
res.set_content(data.dump(), "application/json");
|
||||||
res.status = http_error_codes::ok;
|
res.status = http_error_codes::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void server::handle_unmount(const httplib::Request & /*req*/,
|
void server::handle_unmount(const httplib::Request & /*req*/,
|
||||||
httplib::Response &res) {
|
httplib::Response &res) {
|
||||||
event_system::instance().raise<unmount_requested>();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
res.status = http_error_codes::ok;
|
|
||||||
}
|
event_system::instance().raise<unmount_requested>(function_name);
|
||||||
|
res.status = http_error_codes::ok;
|
||||||
void server::initialize(httplib::Server &inst) {
|
}
|
||||||
inst.Get("/api/v1/" + rpc_method::get_config, [this](auto &&req, auto &&res) {
|
|
||||||
handle_get_config(std::forward<decltype(req)>(req),
|
void server::initialize(httplib::Server &inst) {
|
||||||
std::forward<decltype(res)>(res));
|
inst.Get("/api/v1/" + rpc_method::get_config, [this](auto &&req, auto &&res) {
|
||||||
});
|
handle_get_config(std::forward<decltype(req)>(req),
|
||||||
|
std::forward<decltype(res)>(res));
|
||||||
inst.Get("/api/v1/" + rpc_method::get_config_value_by_name,
|
});
|
||||||
[this](auto &&req, auto &&res) {
|
|
||||||
handle_get_config_value_by_name(std::forward<decltype(req)>(req),
|
inst.Get("/api/v1/" + rpc_method::get_config_value_by_name,
|
||||||
std::forward<decltype(res)>(res));
|
[this](auto &&req, auto &&res) {
|
||||||
});
|
handle_get_config_value_by_name(std::forward<decltype(req)>(req),
|
||||||
|
std::forward<decltype(res)>(res));
|
||||||
inst.Post("/api/v1/" + rpc_method::set_config_value_by_name,
|
});
|
||||||
[this](auto &&req, auto &&res) {
|
|
||||||
handle_set_config_value_by_name(std::forward<decltype(req)>(req),
|
inst.Post("/api/v1/" + rpc_method::set_config_value_by_name,
|
||||||
std::forward<decltype(res)>(res));
|
[this](auto &&req, auto &&res) {
|
||||||
});
|
handle_set_config_value_by_name(std::forward<decltype(req)>(req),
|
||||||
|
std::forward<decltype(res)>(res));
|
||||||
inst.Post("/api/v1/" + rpc_method::unmount, [this](auto &&req, auto &&res) {
|
});
|
||||||
handle_unmount(std::forward<decltype(req)>(req),
|
|
||||||
std::forward<decltype(res)>(res));
|
inst.Post("/api/v1/" + rpc_method::unmount, [this](auto &&req, auto &&res) {
|
||||||
});
|
handle_unmount(std::forward<decltype(req)>(req),
|
||||||
}
|
std::forward<decltype(res)>(res));
|
||||||
|
});
|
||||||
void server::start() {
|
}
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
|
||||||
|
void server::start() {
|
||||||
mutex_lock lock(start_stop_mutex_);
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
if (server_thread_) {
|
|
||||||
return;
|
mutex_lock lock(start_stop_mutex_);
|
||||||
}
|
if (server_thread_) {
|
||||||
|
return;
|
||||||
event_system::instance().raise<service_start_begin>(function_name, "server");
|
}
|
||||||
|
|
||||||
server_ = std::make_unique<httplib::Server>();
|
event_system::instance().raise<service_start_begin>(function_name, "server");
|
||||||
|
|
||||||
server_->set_exception_handler([](const httplib::Request &req,
|
server_ = std::make_unique<httplib::Server>();
|
||||||
httplib::Response &res,
|
|
||||||
std::exception_ptr ptr) {
|
server_->set_exception_handler([](const httplib::Request &req,
|
||||||
json data = {{"path", req.path}};
|
httplib::Response &res,
|
||||||
|
std::exception_ptr ptr) {
|
||||||
try {
|
json data = {{"path", req.path}};
|
||||||
std::rethrow_exception(ptr);
|
|
||||||
} catch (std::exception &e) {
|
try {
|
||||||
data["error"] = (e.what() == nullptr) ? "unknown error" : e.what();
|
std::rethrow_exception(ptr);
|
||||||
utils::error::raise_error(function_name, e,
|
} catch (std::exception &e) {
|
||||||
"failed request: " + req.path);
|
data["error"] = (e.what() == nullptr) ? "unknown error" : e.what();
|
||||||
} catch (...) {
|
utils::error::raise_error(function_name, e,
|
||||||
data["error"] = "unknown error";
|
"failed request: " + req.path);
|
||||||
utils::error::raise_error(function_name, "unknown error",
|
} catch (...) {
|
||||||
"failed request: " + req.path);
|
data["error"] = "unknown error";
|
||||||
}
|
utils::error::raise_error(function_name, "unknown error",
|
||||||
|
"failed request: " + req.path);
|
||||||
res.set_content(data.dump(), "application/json");
|
}
|
||||||
res.status = http_error_codes::internal_error;
|
|
||||||
});
|
res.set_content(data.dump(), "application/json");
|
||||||
|
res.status = http_error_codes::internal_error;
|
||||||
server_->set_pre_routing_handler(
|
});
|
||||||
[this](auto &&req, auto &&res) -> httplib::Server::HandlerResponse {
|
|
||||||
if (rpc::check_authorization(config_, req)) {
|
server_->set_pre_routing_handler(
|
||||||
return httplib::Server::HandlerResponse::Unhandled;
|
[this](auto &&req, auto &&res) -> httplib::Server::HandlerResponse {
|
||||||
}
|
if (rpc::check_authorization(config_, req)) {
|
||||||
|
return httplib::Server::HandlerResponse::Unhandled;
|
||||||
res.status = http_error_codes::unauthorized;
|
}
|
||||||
return httplib::Server::HandlerResponse::Handled;
|
|
||||||
});
|
res.status = http_error_codes::unauthorized;
|
||||||
|
return httplib::Server::HandlerResponse::Handled;
|
||||||
initialize(*server_);
|
});
|
||||||
|
|
||||||
server_thread_ = std::make_unique<std::thread>([this]() {
|
initialize(*server_);
|
||||||
server_->set_socket_options([](auto &&sock) {
|
|
||||||
#if defined(_WIN32)
|
server_thread_ = std::make_unique<std::thread>([this]() {
|
||||||
int enable{1};
|
server_->set_socket_options([](auto &&sock) {
|
||||||
setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
|
#if defined(_WIN32)
|
||||||
reinterpret_cast<const char *>(&enable), sizeof(enable));
|
int enable{1};
|
||||||
#else // !defined(_WIN32)
|
setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
|
||||||
linger opt{1, 0};
|
reinterpret_cast<const char *>(&enable), sizeof(enable));
|
||||||
setsockopt(sock, SOL_SOCKET, SO_LINGER,
|
#else // !defined(_WIN32)
|
||||||
reinterpret_cast<const char *>(&opt), sizeof(opt));
|
linger opt{1, 0};
|
||||||
#endif // defined(_WIN32)
|
setsockopt(sock, SOL_SOCKET, SO_LINGER,
|
||||||
});
|
reinterpret_cast<const char *>(&opt), sizeof(opt));
|
||||||
|
#endif // defined(_WIN32)
|
||||||
server_->listen("127.0.0.1", config_.get_api_port());
|
});
|
||||||
});
|
|
||||||
event_system::instance().raise<service_start_end>(function_name, "server");
|
server_->listen("127.0.0.1", config_.get_api_port());
|
||||||
}
|
});
|
||||||
|
event_system::instance().raise<service_start_end>(function_name, "server");
|
||||||
void server::stop() {
|
}
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
|
||||||
|
void server::stop() {
|
||||||
unique_mutex_lock lock(start_stop_mutex_);
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
if (not server_thread_) {
|
|
||||||
return;
|
unique_mutex_lock lock(start_stop_mutex_);
|
||||||
}
|
if (not server_thread_) {
|
||||||
|
return;
|
||||||
event_system::instance().raise<service_stop_begin>(function_name, "server");
|
}
|
||||||
|
|
||||||
server_->stop();
|
event_system::instance().raise<service_stop_begin>(function_name, "server");
|
||||||
|
|
||||||
std::unique_ptr<std::thread> thread{nullptr};
|
server_->stop();
|
||||||
std::swap(thread, server_thread_);
|
|
||||||
lock.unlock();
|
std::unique_ptr<std::thread> thread{nullptr};
|
||||||
|
std::swap(thread, server_thread_);
|
||||||
thread->join();
|
lock.unlock();
|
||||||
thread.reset();
|
|
||||||
|
thread->join();
|
||||||
lock.lock();
|
thread.reset();
|
||||||
server_.reset();
|
|
||||||
lock.unlock();
|
lock.lock();
|
||||||
|
server_.reset();
|
||||||
event_system::instance().raise<service_stop_end>(function_name, "server");
|
lock.unlock();
|
||||||
}
|
|
||||||
} // namespace repertory
|
event_system::instance().raise<service_stop_end>(function_name, "server");
|
||||||
|
}
|
||||||
|
} // namespace repertory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user