19#include <boost/algorithm/string.hpp>
20#include <boost/algorithm/string/classification.hpp>
21#include <boost/algorithm/string/constants.hpp>
22#include <boost/algorithm/string/split.hpp>
23#include <boost/algorithm/string/trim.hpp>
24#include <boost/process/v2/process.hpp>
25#include <boost/process/v2/stdio.hpp>
27#include <fairlogger/Logger.h>
30#include <fmt/format.h>
35#include <ext_data_clnt.hh>
38#include <system_error>
44namespace fs = std::filesystem;
47 bool Check_exist(std::string_view exe)
49 auto exe_path = fs::path{ exe };
50 return fs::exists(exe_path) || fs::is_symlink(exe_path);
55 void Append_elements(std::vector<T>& base, std::vector<T> to_append)
57 base.reserve(base.size() + to_append.size());
58 for (
auto& ele : to_append)
60 base.emplace_back(std::move(ele));
64 void Append_lmds(std::vector<std::string>& lmds, std::string_view filename_regex)
74 auto option_regex = std::regex{
"^--[0-9A-z,=\\-]+" };
75 auto lmd_regex = std::regex{
"^.*\\.lmd$" };
77 for (
auto& split_item : splits)
79 if (std::regex_match(split_item, option_regex))
81 result.options.emplace_back(std::move(split_item));
83 else if (std::regex_match(split_item, lmd_regex))
85 Append_lmds(result.lmds, split_item);
87 else if (Check_exist(split_item))
90 if (not result.executable.empty())
92 R3BLOG(info, fmt::format(
"Ucesb Executable has been set to \"{}\" ", result.executable));
93 R3BLOG(error, fmt::format(
"Found another executable \"{}\" but only one is allowed!", split_item));
96 R3BLOG(info, fmt::format(
"Ucesb Executable is set to \"{}\" ", split_item));
97 result.executable = std::move(split_item);
102 result.others.emplace_back(std::move(split_item));
108 void lmd_filenames_sorting(std::vector<std::string>& filenames)
111 std::sort(filenames.begin(), filenames.end());
120 R3BLOG(debug, fmt::format(
"Resolving string command: {}", cmd));
122 auto splits = std::vector<std::string>{};
123 boost::split(splits, cmd, boost::is_any_of(
" "), boost::token_compress_on);
128 auto results = parse_splits(std::move(splits));
129 lmd_filenames_sorting(results.lmds);
142 R3BLOG(error, fmt::format(
"An unpacker executable doesn't exist in options {:?}", command_string));
149 fmt::format(
"Ucesb command after resolving wildcard filename: \n {} {}",
157 std::make_unique<bpv2::process>(
ios_,
160 bpv2::process_stdio{ .in = nullptr, .out = server_pipe_, .err = stderr });
164 R3BLOG(error,
"ext_data_clnt::connect() failed");
174 if (
auto ret_val =
client_->close(); ret_val != 0)
176 R3BLOG(error,
"ext_data_clnt::close() failed");
178 auto err_code = std::error_code{};
180 [](
const std::error_code& err,
int ret)
184 LOGP(error,
"Error occured from ucesb server. Error message: {}", err.message());
186 LOGP(info,
"Ucesb server is closed successfully with the return value: {}", ret);
#define R3BLOG(severity, x)
constexpr auto CHILD_CLOSE_WAITING_TIME
constexpr auto UCESB_NULL_STR_MSG
std::unique_ptr< bpv2::process > ucesb_server_
void SetLaunchCmd(const std::string &command_string)
ResolveResult launch_strings_
boost::asio::io_context ios_
boost::asio::readable_pipe server_pipe_
std::vector< std::string > launch_args
auto GetFilesFromRegex(std::string_view filename_regex) -> std::vector< std::string >