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

Commit bbcbc2ff authored by Tom Cherry's avatar Tom Cherry
Browse files

init: replace Result<Success> with Result<void>

Now that Result<T> is actually expected<T, ...>, and the expected
proposal states expected<void, ...> as the way to indicate an expected
object that returns either successfully with no object or an error,
let's move init's Result<Success> to the preferred Result<void>.

Bug: 132145659
Test: boot, init unit tests
Change-Id: Ib2f98396d8e6e274f95a496fcdfd8341f77585ee
parent caa95d55
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -28,9 +28,8 @@ using android::base::Join;
namespace android {
namespace init {

Result<Success> RunBuiltinFunction(const BuiltinFunction& function,
                                   const std::vector<std::string>& args,
                                   const std::string& context) {
Result<void> RunBuiltinFunction(const BuiltinFunction& function,
                                const std::vector<std::string>& args, const std::string& context) {
    auto builtin_arguments = BuiltinArguments(context);

    builtin_arguments.args.resize(args.size());
@@ -51,7 +50,7 @@ Command::Command(BuiltinFunction f, bool execute_in_subcontext, std::vector<std:
      args_(std::move(args)),
      line_(line) {}

Result<Success> Command::InvokeFunc(Subcontext* subcontext) const {
Result<void> Command::InvokeFunc(Subcontext* subcontext) const {
    if (subcontext) {
        if (execute_in_subcontext_) {
            return subcontext->Execute(args_);
@@ -83,7 +82,7 @@ Action::Action(bool oneshot, Subcontext* subcontext, const std::string& filename

const KeywordFunctionMap* Action::function_map_ = nullptr;

Result<Success> Action::AddCommand(std::vector<std::string>&& args, int line) {
Result<void> Action::AddCommand(std::vector<std::string>&& args, int line) {
    if (!function_map_) {
        return Error() << "no function map available";
    }
@@ -92,7 +91,7 @@ Result<Success> Action::AddCommand(std::vector<std::string>&& args, int line) {
    if (!function) return Error() << function.error();

    commands_.emplace_back(function->second, function->first, std::move(args), line);
    return Success();
    return {};
}

void Action::AddCommand(BuiltinFunction f, std::vector<std::string>&& args, int line) {
+4 −4
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@
namespace android {
namespace init {

Result<Success> RunBuiltinFunction(const BuiltinFunction& function,
Result<void> RunBuiltinFunction(const BuiltinFunction& function,
                                const std::vector<std::string>& args, const std::string& context);

class Command {
@@ -39,7 +39,7 @@ class Command {
    Command(BuiltinFunction f, bool execute_in_subcontext, std::vector<std::string>&& args,
            int line);

    Result<Success> InvokeFunc(Subcontext* subcontext) const;
    Result<void> InvokeFunc(Subcontext* subcontext) const;
    std::string BuildCommandString() const;

    int line() const { return line_; }
@@ -61,7 +61,7 @@ class Action {
           const std::string& event_trigger,
           const std::map<std::string, std::string>& property_triggers);

    Result<Success> AddCommand(std::vector<std::string>&& args, int line);
    Result<void> AddCommand(std::vector<std::string>&& args, int line);
    void AddCommand(BuiltinFunction f, std::vector<std::string>&& args, int line);
    std::size_t NumCommands() const;
    void ExecuteOneCommand(std::size_t command) const;
+14 −14
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ bool IsActionableProperty(Subcontext* subcontext, const std::string& prop_name)
    return CanReadProperty(subcontext->context(), prop_name);
}

Result<Success> ParsePropertyTrigger(const std::string& trigger, Subcontext* subcontext,
Result<void> ParsePropertyTrigger(const std::string& trigger, Subcontext* subcontext,
                                  std::map<std::string, std::string>* property_triggers) {
    const static std::string prop_str("property:");
    std::string prop_name(trigger.substr(prop_str.length()));
@@ -74,10 +74,10 @@ Result<Success> ParsePropertyTrigger(const std::string& trigger, Subcontext* sub
    if (auto [it, inserted] = property_triggers->emplace(prop_name, prop_value); !inserted) {
        return Error() << "multiple property triggers found for same property";
    }
    return Success();
    return {};
}

Result<Success> ParseTriggers(const std::vector<std::string>& args, Subcontext* subcontext,
Result<void> ParseTriggers(const std::vector<std::string>& args, Subcontext* subcontext,
                           std::string* event_trigger,
                           std::map<std::string, std::string>* property_triggers) {
    const static std::string prop_str("property:");
@@ -108,12 +108,12 @@ Result<Success> ParseTriggers(const std::vector<std::string>& args, Subcontext*
        }
    }

    return Success();
    return {};
}

}  // namespace

Result<Success> ActionParser::ParseSection(std::vector<std::string>&& args,
Result<void> ActionParser::ParseSection(std::vector<std::string>&& args,
                                        const std::string& filename, int line) {
    std::vector<std::string> triggers(args.begin() + 1, args.end());
    if (triggers.size() < 1) {
@@ -142,19 +142,19 @@ Result<Success> ActionParser::ParseSection(std::vector<std::string>&& args,
                                           property_triggers);

    action_ = std::move(action);
    return Success();
    return {};
}

Result<Success> ActionParser::ParseLineSection(std::vector<std::string>&& args, int line) {
    return action_ ? action_->AddCommand(std::move(args), line) : Success();
Result<void> ActionParser::ParseLineSection(std::vector<std::string>&& args, int line) {
    return action_ ? action_->AddCommand(std::move(args), line) : Result<void>{};
}

Result<Success> ActionParser::EndSection() {
Result<void> ActionParser::EndSection() {
    if (action_ && action_->NumCommands() > 0) {
        action_manager_->AddAction(std::move(action_));
    }

    return Success();
    return {};
}

}  // namespace init
+4 −4
Original line number Diff line number Diff line
@@ -32,10 +32,10 @@ class ActionParser : public SectionParser {
  public:
    ActionParser(ActionManager* action_manager, std::vector<Subcontext>* subcontexts)
        : action_manager_(action_manager), subcontexts_(subcontexts), action_(nullptr) {}
    Result<Success> ParseSection(std::vector<std::string>&& args, const std::string& filename,
    Result<void> ParseSection(std::vector<std::string>&& args, const std::string& filename,
                              int line) override;
    Result<Success> ParseLineSection(std::vector<std::string>&& args, int line) override;
    Result<Success> EndSection() override;
    Result<void> ParseLineSection(std::vector<std::string>&& args, int line) override;
    Result<void> EndSection() override;

  private:
    ActionManager* action_manager_;
+7 −7
Original line number Diff line number Diff line
@@ -165,20 +165,20 @@ static void bootchart_thread_main() {
  LOG(INFO) << "Bootcharting finished";
}

static Result<Success> do_bootchart_start() {
static Result<void> do_bootchart_start() {
    // We don't care about the content, but we do care that /data/bootchart/enabled actually exists.
    std::string start;
    if (!android::base::ReadFileToString("/data/bootchart/enabled", &start)) {
        LOG(VERBOSE) << "Not bootcharting";
        return Success();
        return {};
    }

    g_bootcharting_thread = new std::thread(bootchart_thread_main);
    return Success();
    return {};
}

static Result<Success> do_bootchart_stop() {
    if (!g_bootcharting_thread) return Success();
static Result<void> do_bootchart_stop() {
    if (!g_bootcharting_thread) return {};

    // Tell the worker thread it's time to quit.
    {
@@ -190,10 +190,10 @@ static Result<Success> do_bootchart_stop() {
    g_bootcharting_thread->join();
    delete g_bootcharting_thread;
    g_bootcharting_thread = nullptr;
    return Success();
    return {};
}

Result<Success> do_bootchart(const BuiltinArguments& args) {
Result<void> do_bootchart(const BuiltinArguments& args) {
    if (args[1] == "start") return do_bootchart_start();
    return do_bootchart_stop();
}
Loading