13#ifndef OPENVPN_COMMON_ACTION_H
14#define OPENVPN_COMMON_ACTION_H
20#include <unordered_set>
30struct Action :
public RC<thread_unsafe_refcount>
39 throw Exception(
"Action::to_json() virtual method not implemented");
71 insert(end(), other.begin(), other.end());
78 const std::string cmp = action->to_string();
81 if (a->to_string() == cmp)
98 virtual std::unordered_set<std::string>
execute(std::ostream &
os)
100 std::unordered_set<std::string> failed_actions;
106 return failed_actions;
107 auto &action = this->at(i.
index());
112 catch (
const std::exception &e)
114 os <<
"action exception: " << e.what() << std::endl;
115 failed_actions.insert(action->mark);
119 return failed_actions;
124 std::ostringstream
os;
135 ret += (*this)[i.
index()]->to_string();
177 erase(std::remove_if(
180 auto remove = !a->mark.empty() && marks.count(a->mark) > 0;
183 os <<
"Action '" << a->to_string() <<
"' will be removed\n";
193 Iter(
size_t size,
const bool reverse)
Iter(size_t size, const bool reverse)
void destroy(std::ostream &os) override
bool exists(const Action::Ptr &action) const
void add(const Action::Ptr &action)
virtual std::unordered_set< std::string > execute(std::ostream &os)
Executes a sequence of actions and returns marks of failed actions.
void remove_marked(const std::unordered_set< std::string > &marks, std::ostream &os)
Removes actions with specified marks and logs the removals.
void add(const ActionList &other)
void enable_destroy(const bool state)
std::string to_string() const
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
#define OPENVPN_LOG_STRING(str)
virtual ActionList::Ptr new_action_list()=0
RCPtr< ActionListFactory > Ptr
virtual std::string to_string() const =0
virtual void execute(std::ostream &os)=0
virtual ~Action()=default
virtual Json::Value to_json() const
server addresses push_back({address, port})