diff options
author | Tom Cherry <tomcherry@google.com> | 2018-02-13 15:25:29 -0800 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2018-02-13 15:26:14 -0800 |
commit | 0f6417f232e92aad0d712ab1b131c0829869cddd (patch) | |
tree | 1443f21b57b95cc361fe7d903091dc8eee83478b /init/action_parser.cpp | |
parent | cd2fa1f43215b829bd4359bf7725daa220b08dbf (diff) |
Move ActionParser to its own file
Bug: 36970783
Test: build
Change-Id: Idd5b923e4789760bb9ef67c10982b2642bc6a31a
Diffstat (limited to 'init/action_parser.cpp')
-rw-r--r-- | init/action_parser.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/init/action_parser.cpp b/init/action_parser.cpp new file mode 100644 index 000000000..fd085b82d --- /dev/null +++ b/init/action_parser.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "action_parser.h" + +#include <android-base/strings.h> + +using android::base::StartsWith; + +namespace android { +namespace init { + +Result<Success> 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) { + return Error() << "Actions must have a trigger"; + } + + Subcontext* action_subcontext = nullptr; + if (subcontexts_) { + for (auto& subcontext : *subcontexts_) { + if (StartsWith(filename, subcontext.path_prefix())) { + action_subcontext = &subcontext; + break; + } + } + } + + auto action = std::make_unique<Action>(false, action_subcontext, filename, line); + + if (auto result = action->InitTriggers(triggers); !result) { + return Error() << "InitTriggers() failed: " << result.error(); + } + + action_ = std::move(action); + return Success(); +} + +Result<Success> ActionParser::ParseLineSection(std::vector<std::string>&& args, int line) { + return action_ ? action_->AddCommand(std::move(args), line) : Success(); +} + +Result<Success> ActionParser::EndSection() { + if (action_ && action_->NumCommands() > 0) { + action_manager_->AddAction(std::move(action_)); + } + + return Success(); +} + +} // namespace init +} // namespace android |