函数
ExecuteOneCommand函数:
- ActionManager中std::queue<const Action*> current_executing_actions_;在64行向current_executing_actions_插入一个action,在处理完这个action中的所有command,在89行删除current_executing_actions_元素。
- 在61中轮询actions中的action, 如果某个action被满足event_queue_队列中触发条件,则会把这个action放入current_executing_actions_队列中。
58 void ActionManager::ExecuteOneCommand() {
59 // Loop through the event queue until we have an action to execute
60 while (current_executing_actions_.empty() && !event_queue_.empty()) {
61 for (const auto& action : actions_) {
62 if (std::visit([&action](const auto& event) { return action->CheckEvent(event); },
63 event_queue_.front())) {
64 current_executing_actions_.emplace(action.get());
65 }
66 }
67 event_queue_.pop();
68 }
69
70 if (current_executing_actions_.empty()) {
71 return;
72 }
73
74 auto action = current_executing_actions_.front();
75
76 if (current_command_ == 0) {
77 std::string trigger_name = action->BuildTriggersString();
78 LOG(INFO) << "processing action (" << trigger_name << ") from (" << action->filename()
79 << ":" << action->line() << ")";
80 }
81
82 action->ExecuteOneCommand(current_command_);
83
84 // If this was the last command in the current action, then remove
85 // the action from the executing list.
86 // If this action was oneshot, then also remove it from actions_.
87 ++current_command_;
88 if (current_command_ == action->NumCommands()) {
89 current_executing_actions_.pop();
90 current_command_ = 0;
91 if (action->oneshot()) {
92 auto eraser = [&action](std::unique_ptr<Action>& a) { return a.get() == action; };
93 actions_.erase(std::remove_if(actions_.begin(), actions_.end(), eraser));
94 }
95 }
96 }
通过打印信息知道:
init: 7 early-init
init: 7 init
init: 7
init: 7 load_persist_props_action
init: 7 firmware_mounts_complete
init: 7 late-init
可以知道actions_中包含event_name为early-init,init,load_persist_props_action,firmware_mounts_complete和late-init的action。
从打印中,可以看出init 的action中的命令没有执行完毕。