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 "applypatch/command_const.h" 24 #include "applypatch/transfer_manager.h" 25 #include "pkg_manager.h" 26 #include "script_instruction.h" 27 #include "script_manager.h" 28 29 namespace Updater { 30 struct TransferParams; 31 class Command { 32 public: Command(TransferParams * transferParams)33 explicit Command(TransferParams* transferParams):transferParams_(transferParams) {} 34 virtual ~Command(); 35 36 virtual bool Init(const std::string &cmd_line); 37 CommandType GetCommandType() const; 38 std::string GetArgumentByPos(size_t pos) const; 39 void SetFileDescriptor(int fd); 40 int GetFileDescriptor() const; 41 TransferParams* GetTransferParams() const; 42 std::string GetCommandLine() const; 43 std::string GetCommandHead() const; 44 private: 45 CommandType ParseCommandType(const std::string &first_cmd); 46 47 CommandType type_ {LAST}; 48 std::string cmdhead_ {}; 49 std::string cmdLine_ {}; 50 std::vector<std::string> tokens_ {}; 51 std::unique_ptr<int> fd_ {}; 52 TransferParams* transferParams_; 53 }; 54 } // namespace Updater 55 #endif 56