Lines Matching refs:Action
17 #include "action.h"
65 Action::Action(bool oneshot) : oneshot_(oneshot) {
68 const KeywordMap<BuiltinFunction>* Action::function_map_ = nullptr;
70 bool Action::AddCommand(const std::vector<std::string>& args,
91 void Action::AddCommand(BuiltinFunction f,
97 void Action::CombineAction(const Action& action) {
98 for (const auto& c : action.commands_) {
103 std::size_t Action::NumCommands() const {
107 void Action::ExecuteOneCommand(std::size_t command) const {
111 void Action::ExecuteAllCommands() const {
117 void Action::ExecuteCommand(const Command& command) const {
126 INFO("Command '%s' action=%s%s returned %d took %.2fs\n",
132 bool Action::ParsePropertyTrigger(const std::string& trigger, std::string* err) {
152 bool Action::InitTriggers(const std::vector<std::string>& args, std::string* err) {
181 bool Action::InitSingleTrigger(const std::string& trigger) {
194 bool Action::CheckPropertyTriggers(const std::string& name,
221 bool Action::CheckEventTrigger(const std::string& trigger) const {
227 bool Action::CheckPropertyTrigger(const std::string& name,
232 bool Action::TriggersEqual(const Action& other) const {
237 std::string Action::BuildTriggersString() const {
254 void Action::DumpState() const {
269 bool CheckTriggers(const Action& action) const override {
270 return action.CheckEventTrigger(trigger_);
281 bool CheckTriggers(const Action& action) const override {
282 return action.CheckPropertyTrigger(name_, value_);
291 BuiltinTrigger(Action* action) : action_(action) {
293 bool CheckTriggers(const Action& action) const override {
294 return action_ == &action;
297 const Action* action_;
308 void ActionManager::AddAction(std::unique_ptr<Action> action) {
311 [&action] (std::unique_ptr<Action>& a) {
312 return action->TriggersEqual(*a);
316 (*old_action_it)->CombineAction(*action);
318 actions_.emplace_back(std::move(action));
337 auto action = std::make_unique<Action>(true);
340 if (!action->InitSingleTrigger(name)) {
344 action->AddCommand(func, name_vector);
346 trigger_queue_.push(std::make_unique<BuiltinTrigger>(action.get()));
347 actions_.emplace_back(std::move(action));
351 // Loop through the trigger queue until we have an action to execute
353 for (const auto& action : actions_) {
354 if (trigger_queue_.front()->CheckTriggers(*action)) {
355 current_executing_actions_.emplace(action.get());
365 auto action = current_executing_actions_.front();
368 std::string trigger_name = action->BuildTriggersString();
369 INFO("processing action (%s)\n", trigger_name.c_str());
372 action->ExecuteOneCommand(current_command_);
374 // If this was the last command in the current action, then remove
375 // the action from the executing list.
376 // If this action was oneshot, then also remove it from actions_.
378 if (current_command_ == action->NumCommands()) {
381 if (action->oneshot()) {
382 auto eraser = [&action] (std::unique_ptr<Action>& a) {
383 return a.get() == action;
409 auto action = std::make_unique<Action>(false);
410 if (!action->InitTriggers(triggers, err)) {
414 action_ = std::move(action);