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 SetSrcFileDescriptor(int fd); 40 int GetSrcFileDescriptor() const; 41 void SetTargetFileDescriptor(int fd); 42 int GetTargetFileDescriptor() const; 43 44 TransferParams* GetTransferParams() const; 45 std::string GetCommandLine() const; 46 std::string GetCommandHead() const; 47 void SetIsStreamCmd(bool isStreamCmd); 48 bool IsStreamCmd() const; 49 50 private: 51 CommandType ParseCommandType(const std::string &first_cmd); 52 53 CommandType type_ {LAST}; 54 std::string cmdhead_ {}; 55 std::string cmdLine_ {}; 56 std::vector<std::string> tokens_ {}; 57 std::unique_ptr<int> srcFd_ {}; 58 std::unique_ptr<int> targetFd_ {}; 59 TransferParams* transferParams_; 60 bool isStreamCmd_ {false}; 61 }; 62 } // namespace Updater 63 #endif 64