• 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 enum EXIT_CODES {
34     EXIT_INVALID_ARGS = EXIT_SUCCESS + 1,
35     EXIT_READ_PACKAGE_ERROR = 2,
36     EXIT_FOUND_SCRIPT_ERROR = 3,
37     EXIT_PARSE_SCRIPT_ERROR = 4,
38     EXIT_EXEC_SCRIPT_ERROR = 5,
39 };
40 
41 int ProcessUpdater(bool retry, int pipeFd, const std::string &packagePath, const std::string &keyPath);
42 void GetPartitionPathFromName(const std::string &partitionName, std::string &partitionPath);
43 
44 class UpdaterInstructionFactory : public UScriptInstructionFactory {
45 public:
46     virtual int32_t CreateInstructionInstance(UScriptInstructionPtr& instr, const std::string& name);
UpdaterInstructionFactory()47     UpdaterInstructionFactory() {}
~UpdaterInstructionFactory()48     virtual ~UpdaterInstructionFactory() {}
49 };
50 
51 class UScriptInstructionRawImageWrite : public Uscript::UScriptInstruction {
52 public:
UScriptInstructionRawImageWrite()53     UScriptInstructionRawImageWrite() {}
~UScriptInstructionRawImageWrite()54     virtual ~UScriptInstructionRawImageWrite() {}
55     int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override;
56 
57 private:
58     static int RawImageWriteProcessor(const Hpackage::PkgBuffer &buffer, size_t size, size_t start, bool isFinish,
59         const void* context);
60     int GetWritePathAndOffset(const std::string &partitionName, std::string &writePath, uint64_t &offset,
61         uint64_t &partitionSize);
62     static size_t totalSize_;
63     static size_t readSize_;
64 };
65 } // Updater
66 #endif /* UPDATE_PROCESSOR_H */
67