• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #include "applypatch/command_function.h"
17 #include "command_process.h"
18 
19 namespace updater {
GetCommandFunction(const CommandType type)20 std::unique_ptr<CommandFunction> CommandFunctionFactory::GetCommandFunction(const CommandType type)
21 {
22     switch (type) {
23         case CommandType::ABORT:
24         {
25             std::unique_ptr<AbortCommandFn> instr(std::make_unique<AbortCommandFn>());
26             return std::move(instr);
27         }
28         case CommandType::NEW:
29         {
30             std::unique_ptr<NewCommandFn> instr(std::make_unique<NewCommandFn>());
31             return std::move(instr);
32         }
33         case CommandType::BSDIFF:
34         {
35             std::unique_ptr<DiffAndMoveCommandFn> instr(std::make_unique<DiffAndMoveCommandFn>());
36             return std::move(instr);
37         }
38         case CommandType::IMGDIFF:
39         {
40             std::unique_ptr<DiffAndMoveCommandFn> instr(std::make_unique<DiffAndMoveCommandFn>());
41             return std::move(instr);
42         }
43         case CommandType::ERASE:
44         {
45             std::unique_ptr<ZeroAndEraseCommandFn> instr(std::make_unique<ZeroAndEraseCommandFn>());
46             return std::move(instr);
47         }
48         case CommandType::ZERO:
49         {
50             std::unique_ptr<ZeroAndEraseCommandFn> instr(std::make_unique<ZeroAndEraseCommandFn>());
51             return std::move(instr);
52         }
53         case CommandType::FREE:
54         {
55             std::unique_ptr<FreeCommandFn> instr(std::make_unique<FreeCommandFn>());
56             return std::move(instr);
57         }
58         case CommandType::MOVE:
59         {
60             std::unique_ptr<DiffAndMoveCommandFn> instr(std::make_unique<DiffAndMoveCommandFn>());
61             return std::move(instr);
62         }
63         case CommandType::STASH:
64         {
65             std::unique_ptr<StashCommandFn> instr(std::make_unique<StashCommandFn>());
66             return std::move(instr);
67         }
68         default:
69             break;
70     }
71     return nullptr;
72 }
73 
ReleaseCommandFunction(std::unique_ptr<CommandFunction> & instr)74 void CommandFunctionFactory::ReleaseCommandFunction(std::unique_ptr<CommandFunction> &instr)
75 {
76     instr.reset();
77 }
78 }