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 #ifndef USCRIPT_COMMAND_H 16 #define USCRIPT_COMMAND_H 17 18 #include <memory> 19 #include <string> 20 #include <pthread.h> 21 #include "applypatch/block_set.h" 22 #include "applypatch/block_writer.h" 23 #include "pkg_manager.h" 24 #include "script_instruction.h" 25 #include "script_manager.h" 26 27 namespace Updater { 28 enum CommandType { 29 ABORT, 30 BSDIFF, 31 IMGDIFF, 32 ERASE, 33 FREE, 34 MOVE, 35 NEW, 36 STASH, 37 ZERO, 38 LAST, 39 }; 40 41 enum CommandResult { 42 FAILED = -1, 43 SUCCESS = 0, 44 NEED_RETRY = 1 45 }; 46 47 class Command { 48 public: Command()49 Command() {} 50 virtual ~Command(); 51 52 virtual bool Init(const std::string &cmd_line); 53 CommandType GetCommandType() const; 54 std::string GetArgumentByPos(size_t pos) const; 55 void SetFileDescriptor(int fd); 56 int GetFileDescriptor() const; 57 std::string GetCommandLine() const; 58 private: 59 CommandType ParseCommandType(const std::string &first_cmd); 60 61 CommandType type_ {LAST}; 62 std::string cmdLine_ {}; 63 std::vector<std::string> tokens_ {}; 64 std::unique_ptr<int> fd_ {}; 65 }; 66 } // namespace Updater 67 #endif 68