1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef FACTORY_RESET_H 16 #define FACTORY_RESET_H 17 18 #include <iostream> 19 #include <string> 20 #include <functional> 21 #include "updater/updater.h" 22 #include "updater_main.h" 23 24 namespace Updater { 25 using CommonResetPostFunc = std::function<int(bool)>; 26 using FactoryResetPreFunc = std::function<int(void)>; 27 using FactoryResetPostFunc = std::function<int(int)>; 28 class FactoryResetProcess { 29 DISALLOW_COPY_MOVE(FactoryResetProcess); 30 public: 31 FactoryResetProcess(); 32 virtual ~FactoryResetProcess() = default; 33 34 static FactoryResetProcess &GetInstance(); 35 using ResetFunc = std::function<int(const std::string &)>; 36 void RegisterCommonResetPostFunc(CommonResetPostFunc ptr); 37 void RegisterFactoryResetPreFunc(FactoryResetPreFunc ptr); 38 void RegisterFactoryResetPostFunc(FactoryResetPostFunc ptr); 39 int FactoryResetFunc(FactoryResetMode mode, const std::string &path); 40 41 private: 42 CommonResetPostFunc CommonResetPostFunc_ = nullptr; 43 FactoryResetPreFunc FactoryResetPreFunc_ = nullptr; 44 FactoryResetPostFunc FactoryResetPostFunc_ = nullptr; 45 std::unordered_map<FactoryResetMode, ResetFunc> resetTab_; 46 47 int DoUserReset(const std::string &path); 48 int DoFactoryReset(const std::string &path); 49 void RegisterFunc(FactoryResetMode mode, ResetFunc func); 50 }; 51 52 } // namespace Updater 53 #endif // FACTORY_RESET_H