init: ServiceList FindInterface

FindService can't be used w/ interfaces due
to the fact that multiple interfaces can be
added to any given interface.

Bug: 79418581
Test: boot device, manually use ctl commands
Change-Id: I7c152630462c9b7509473bc190f5b30460fcc2bc
This commit is contained in:
Steven Moreland 2018-05-08 13:46:39 -07:00
parent 612d7a47bd
commit 6227e345e7
2 changed files with 28 additions and 29 deletions

View File

@ -277,40 +277,29 @@ void HandleControlMessage(const std::string& msg, const std::string& name, pid_t
const ControlMessageFunction& function = it->second;
if (function.target == ControlTarget::SERVICE) {
Service* svc = ServiceList::GetInstance().FindService(name);
if (svc == nullptr) {
LOG(ERROR) << "No such service '" << name << "' for ctl." << msg;
return;
}
if (auto result = function.action(svc); !result) {
LOG(ERROR) << "Could not ctl." << msg << " for service " << name << ": "
<< result.error();
}
Service* svc = nullptr;
switch (function.target) {
case ControlTarget::SERVICE:
svc = ServiceList::GetInstance().FindService(name);
break;
case ControlTarget::INTERFACE:
svc = ServiceList::GetInstance().FindInterface(name);
break;
default:
LOG(ERROR) << "Invalid function target from static map key '" << msg << "': "
<< static_cast<std::underlying_type<ControlTarget>::type>(function.target);
return;
}
if (svc == nullptr) {
LOG(ERROR) << "Could not find '" << name << "' for ctl." << msg;
return;
}
if (function.target == ControlTarget::INTERFACE) {
for (const auto& svc : ServiceList::GetInstance()) {
if (svc->interfaces().count(name) == 0) {
continue;
}
if (auto result = function.action(svc.get()); !result) {
LOG(ERROR) << "Could not handle ctl." << msg << " for service " << svc->name()
<< " with interface " << name << ": " << result.error();
}
return;
}
LOG(ERROR) << "Could not find service hosting interface " << name;
return;
if (auto result = function.action(svc); !result) {
LOG(ERROR) << "Could not ctl." << msg << " for '" << name << "': " << result.error();
}
LOG(ERROR) << "Invalid function target from static map key '" << msg
<< "': " << static_cast<std::underlying_type<ControlTarget>::type>(function.target);
}
static Result<Success> wait_for_coldboot_done_action(const BuiltinArguments& args) {

View File

@ -244,6 +244,16 @@ class ServiceList {
return nullptr;
}
Service* FindInterface(const std::string& interface_name) {
for (const auto& svc : services_) {
if (svc->interfaces().count(interface_name) > 0) {
return svc.get();
}
}
return nullptr;
}
void DumpState() const;
auto begin() const { return services_.begin(); }