• 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 #ifndef UPDATE_PROCESSOR_H
16 #define UPDATE_PROCESSOR_H
17 
18 #include <cstdio>
19 #include <string>
20 #include <sys/wait.h>
21 #include <unistd.h>
22 #include "applypatch/data_writer.h"
23 #include "pkg_manager.h"
24 #include "script_instruction.h"
25 #include "script_manager.h"
26 
27 using uscript::UScriptEnv;
28 using uscript::UScriptInstructionFactory;
29 using uscript::UScriptInstructionFactoryPtr;
30 using uscript::UScriptInstructionPtr;
31 
32 namespace updater {
33 class UpdaterInstructionFactory : public UScriptInstructionFactory {
34 public:
35     virtual int32_t CreateInstructionInstance(UScriptInstructionPtr& instr, const std::string& name);
UpdaterInstructionFactory()36     UpdaterInstructionFactory() {}
~UpdaterInstructionFactory()37     virtual ~UpdaterInstructionFactory() {}
38 };
39 
40 class UScriptInstructionSparseImageWrite : public uscript::UScriptInstruction {
41 public:
UScriptInstructionSparseImageWrite()42     UScriptInstructionSparseImageWrite() {}
~UScriptInstructionSparseImageWrite()43     virtual ~UScriptInstructionSparseImageWrite() {}
44     int32_t Execute(uscript::UScriptEnv &env, uscript::UScriptContext &context) override;
45 };
46 
47 class UScriptInstructionRawImageWrite : public uscript::UScriptInstruction {
48 public:
UScriptInstructionRawImageWrite()49     UScriptInstructionRawImageWrite() {}
~UScriptInstructionRawImageWrite()50     virtual ~UScriptInstructionRawImageWrite() {}
51     int32_t Execute(uscript::UScriptEnv &env, uscript::UScriptContext &context) override;
52 private:
53     static int RawImageWriteProcessor(const hpackage::PkgBuffer &buffer, size_t size, size_t start, bool isFinish,
54         const void* context);
55     static size_t totalSize_;
56     static size_t readSize_;
57 };
58 } // updater
59 
60 enum EXIT_CODES {
61     EXIT_INVALID_ARGS = EXIT_SUCCESS + 1,
62     EXIT_READ_PACKAGE_ERROR = 2,
63     EXIT_FOUND_SCRIPT_ERROR = 3,
64     EXIT_PARSE_SCRIPT_ERROR = 4,
65     EXIT_EXEC_SCRIPT_ERROR = 5,
66 };
67 
68 int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const std::string &keyPath);
69 
70 #endif /* UPDATE_PROCESSOR_H */
71