init: Queue Triggers instead of Actions
When init queues a trigger, it actually enqueues all of the Actions
that match with that given trigger. This works currently because
all init scripts are loaded and therefore all Actions are available
before init starts queueing any triggers.
To support loading init scripts after init has started queueing
triggers, this change enqueues Trigger objects instead of their
matching Actions. Each Trigger object then matches its associated
Actions during its execution.
Additionally, this makes a few cosmetic clean ups related to triggers.
Bug: 23186545
Change-Id: I5d177458e6df1c4b32b1072cf77e87ef952c87e4
diff --git a/init/action.h b/init/action.h
index ae28fe1..5088c71 100644
--- a/init/action.h
+++ b/init/action.h
@@ -54,6 +54,12 @@
std::vector<Command*> commands_;
};
+class Trigger {
+public:
+ virtual ~Trigger() { }
+ virtual bool CheckTriggers(const Action* action) = 0;
+};
+
class ActionManager {
public:
static ActionManager& GetInstance();
@@ -74,9 +80,10 @@
ActionManager(ActionManager const&) = delete;
void operator=(ActionManager const&) = delete;
- std::vector<Action*> action_list_;
- std::queue<Action*> action_queue_;
- std::size_t cur_command_;
+ std::vector<Action*> actions_;
+ std::queue<std::unique_ptr<Trigger>> trigger_queue_;
+ std::vector<Action*> current_executing_actions_;
+ std::size_t current_command_;
};
#endif