Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6227e345 authored by Steven Moreland's avatar Steven Moreland
Browse files

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
parent 612d7a47
Loading
Loading
Loading
Loading
+17 −28
Original line number Diff line number Diff line
@@ -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 (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();
            }

    if (svc == nullptr) {
        LOG(ERROR) << "Could not find '" << name << "' for ctl." << msg;
        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) {
+10 −0
Original line number Diff line number Diff line
@@ -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(); }