init: rename ServiceManager to ServiceList and clean it up
ServiceManager is essentially just a list now that the rest of its
functionality has been moved elsewhere, so the class is renamed
appropriately.
The ServiceList::Find* functions have been cleaned up into a single
smaller interface.
The ServiceList::ForEach functions have been removed in favor of
ServiceList itself being directly iterable.
Test: boot bullhead
Change-Id: Ibd57c103338f03b83d81e8b48ea0e46cd48fd8f0
diff --git a/init/init.cpp b/init/init.cpp
index a12afae..8f946f7 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -98,22 +98,22 @@
std::vector<std::string> late_import_paths;
void DumpState() {
- ServiceManager::GetInstance().DumpState();
+ ServiceList::GetInstance().DumpState();
ActionManager::GetInstance().DumpState();
}
-Parser CreateParser(ActionManager& action_manager, ServiceManager& service_manager) {
+Parser CreateParser(ActionManager& action_manager, ServiceList& service_list) {
Parser parser;
- parser.AddSectionParser("service", std::make_unique<ServiceParser>(&service_manager));
+ parser.AddSectionParser("service", std::make_unique<ServiceParser>(&service_list));
parser.AddSectionParser("on", std::make_unique<ActionParser>(&action_manager));
parser.AddSectionParser("import", std::make_unique<ImportParser>(&parser));
return parser;
}
-static void LoadBootScripts(ActionManager& action_manager, ServiceManager& service_manager) {
- Parser parser = CreateParser(action_manager, service_manager);
+static void LoadBootScripts(ActionManager& action_manager, ServiceList& service_list) {
+ Parser parser = CreateParser(action_manager, service_list);
std::string bootscript = GetProperty("ro.boot.init_rc", "");
if (bootscript.empty()) {
@@ -221,8 +221,8 @@
static std::optional<boot_clock::time_point> RestartProcesses() {
std::optional<boot_clock::time_point> next_process_restart_time;
- ServiceManager::GetInstance().ForEachService([&next_process_restart_time](Service* s) {
- if (!(s->flags() & SVC_RESTARTING)) return;
+ for (const auto& s : ServiceList::GetInstance()) {
+ if (!(s->flags() & SVC_RESTARTING)) continue;
auto restart_time = s->time_started() + 5s;
if (boot_clock::now() > restart_time) {
@@ -232,12 +232,12 @@
next_process_restart_time = restart_time;
}
}
- });
+ }
return next_process_restart_time;
}
void handle_control_message(const std::string& msg, const std::string& name) {
- Service* svc = ServiceManager::GetInstance().FindServiceByName(name);
+ Service* svc = ServiceList::GetInstance().FindService(name);
if (svc == nullptr) {
LOG(ERROR) << "no such service '" << name << "'";
return;
@@ -1139,7 +1139,7 @@
Action::set_function_map(&function_map);
ActionManager& am = ActionManager::GetInstance();
- ServiceManager& sm = ServiceManager::GetInstance();
+ ServiceList& sm = ServiceList::GetInstance();
LoadBootScripts(am, sm);