6 #ifndef API_HANDLER_HPP
7 #define API_HANDLER_HPP
18 #include "boost/shared_ptr.hpp"
19 #include "boost/any.hpp"
29 #include <type_traits>
32 #include <string_view>
69 template <
typename Integer,
72 static const std::vector<Integer> acceptable_errors {
75 return std::any_of( acceptable_errors.begin(), acceptable_errors.end(),
76 [error_code](
auto listed)->bool { return listed == error_code; }
80 template <
typename... types_t>
92 int ret =
fcn_( _comm, _t... );
97 return ERROR( ret,
"fail" );
111 template<
typename... types_t>
115 std::stringstream msg;
116 msg <<
"empty operation key [" << _op <<
"]";
126 template<
typename... types_t>
137 using fcn_t = std::function<
int(
rsComm_t*, types_t...)>;
143 memset( &rei, 0,
sizeof( rei ) );
154 error finally_err = invoke_policy_enforcement_point(re_ctx_mgr,
158 forward<types_t>(_t)...);
160 if (!finally_err.
ok()) {
168 error pre_err = invoke_policy_enforcement_point(
173 std::forward<types_t>(_t)...);
178 error except_err = invoke_policy_enforcement_point(
183 std::forward<types_t>(_t)...);
185 if (!except_err.
ok()) {
189 return pre_err.
code();
194 op_err = adapted_fcn(ctx, _comm, forward<types_t>(_t)...);
198 error except_err = invoke_policy_enforcement_point(
203 forward<types_t>(_t)...);
205 if (!except_err.
ok()) {
209 return op_err.
code();
213 error post_err = invoke_policy_enforcement_point(
218 forward<types_t>(_t)...);
219 if (!post_err.
ok()) {
221 error except_err = invoke_policy_enforcement_point(
226 forward<types_t>(_t)...);
228 if (!except_err.
ok()) {
232 return post_err.
code();
235 return op_err.
code();
238 return op_err.
code();
240 return fcn(_comm, _t...);
243 catch (
const boost::bad_any_cast&) {
244 std::string msg(
"failed for call - " );
295 template<
typename... types_t>
296 error invoke_policy_enforcement_point(
299 const std::string& _operation_name,
300 const std::string& _class,
308 std::string rule_name = ns +
"pep_" + _operation_name +
"_" + _class;
311 if (_re_ctx_mgr.rule_exists(rule_name, ret).ok() && ret) {
312 error op_err = _re_ctx_mgr.exec_rule(rule_name,
instance_name_, _ctx, std::forward<types_t>(_t)...);
315 rodsLog(
LOG_DEBUG,
"%s-pep rule [%s] failed with error code [%d]", _class.c_str(), rule_name.c_str(), op_err.
code());
316 saved_op_err = op_err;
319 skip_op_err = op_err;
321 if (_class !=
"pre") {
322 rodsLog(
LOG_WARNING,
"RULE_ENGINE_SKIP_OPERATION (%d) incorrectly returned from PEP [%s]! "
323 "RULE_ENGINE_SKIP_OPERATION should only be returned from pre-PEPs!",
329 rodsLog(
LOG_DEBUG10,
"Rule [%s] passes regex test, but does not exist", rule_name.c_str());
334 if (!saved_op_err.
ok()) {
352 :
public lookup_table<api_entry_ptr, size_t, boost::hash<size_t>>
357 auto is_plugin_loaded(std::string_view plugin_name) -> bool;
358 auto mark_plugin_as_loaded(std::string_view plugin_name) -> void;
369 bool _cli_flg =
true );