24#ifndef IFW_FCF_DEVMGR_COMMON_FCF_COMM_HELPERS_HPP_
25#define IFW_FCF_DEVMGR_COMMON_FCF_COMM_HELPERS_HPP_
35#include <fmt/format.h>
37#include <ifw/fnd/defs/iCommAdapter.hpp>
39#include <eso/uatools/ualib/client.hpp>
58 template <
typename... Args>
59 std::vector<ifw::fnd::defs::CallArgument>
62 ifw::fnd::defs::CallArgument{
64 ifw::fnd::defs::Value(std::forward<Args>(args))
85 const std::string& what,
86 const std::function<std::string(
short)>& error_message_fn) {
88 if (result.status != ifw::fnd::defs::Status::Ok) {
89 throw std::runtime_error(fmt::format(
90 "RPC {} failed: {}", what, result.message));
95 if (result.output_arguments.empty()) {
96 throw std::runtime_error(fmt::format(
97 "RPC {} returned no output (ICD mismatch)", what));
99 const auto& out_val = result.output_arguments.front().data.value;
102 reply = std::get<short>(out_val);
103 }
catch (
const std::bad_variant_access&) {
104 throw std::runtime_error(fmt::format(
105 "RPC {} return type does not match a short (check the ICD)",
109 throw std::runtime_error(error_message_fn(reply));
134 const std::string& method_node_id,
135 std::vector<ifw::fnd::defs::CallArgument> args,
136 const std::string& what,
137 const std::function<std::string(
short)>& error_message_fn,
138 const std::string& object_node_id =
"") {
139 ifw::fnd::defs::CallRequest req;
140 req.method = method_node_id;
141 req.input_arguments = std::move(args);
148 if (!object_node_id.empty()) {
149 req.options.properties.Set(
"object", object_node_id);
151 auto res = comm.Call(req);
ActionMgr class source file.
Definition actionMgr.cpp:28
constexpr std::chrono::milliseconds kRpcTimeout
Convenience: call + check in one go. Most FCF RPC call sites become a single line with this.
Definition fcfCommHelpers.hpp:130
void ExecuteRpcCall(ifw::fnd::defs::ICommAdapter &comm, const std::string &method_node_id, std::vector< ifw::fnd::defs::CallArgument > args, const std::string &what, const std::function< std::string(short)> &error_message_fn, const std::string &object_node_id="")
Definition fcfCommHelpers.hpp:133
void CheckRpcReply(const ifw::fnd::defs::CallResult &result, const std::string &what, const std::function< std::string(short)> &error_message_fn)
Translate the short-typed reply of an FCF RPC call into a throw-if-non-zero check.
Definition fcfCommHelpers.hpp:84
std::vector< ifw::fnd::defs::CallArgument > MakeCallArgs(Args &&... args)
Build a vector of positional CallArguments from any number of typed values.
Definition fcfCommHelpers.hpp:60