/* * Copyright (c) 2021 Huawei Device Co., Ltd. * 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 "applypatch/command_function.h" #include "command_process.h" namespace Updater { extern "C" __attribute__((constructor)) void RegistBlockUpdateCommandFunction(void) { const std::unordered_map()>> COMMANDFUNC = { { "abort", []() { return std::make_unique(); } }, { "bsdiff", []() { return std::make_unique(); } }, { "new", []() { return std::make_unique(); } }, { "pkgdiff", []() { return std::make_unique(); } }, { "zero", []() { return std::make_unique(); } }, { "erase", []() { return std::make_unique(); } }, { "free", []() { return std::make_unique(); } }, { "move", []() { return std::make_unique(); } }, { "stash", []() { return std::make_unique(); } } }; for (auto &iter : COMMANDFUNC) { CommandFunctionFactory::GetInstance().RegistCommandFunction(iter.first, iter.second()); } } CommandFunctionFactory &CommandFunctionFactory::GetInstance() { static CommandFunctionFactory instance; return instance; } CommandFunction* CommandFunctionFactory::GetCommandFunction(std::string command) { auto iter = commandFunctionMap_.find(command); if (iter != commandFunctionMap_.end()) { return iter->second.get(); } return nullptr; } void CommandFunctionFactory::RegistCommandFunction(std::string command, std::unique_ptr commandFunction) { commandFunctionMap_.emplace(command, std::move(commandFunction)); } }