• 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 HDC_DAEMON_UPDATER_H
16 #define HDC_DAEMON_UPDATER_H
17 #include <cstdlib>
18 
19 #include "securec.h"
20 #include "transfer.h"
21 
22 namespace Hdc {
23 #define FLASHDAEMON_CHECK(retCode, exper, ...) \
24     if (!(retCode)) { \
25         WRITE_LOG(LOG_FATAL, __VA_ARGS__); \
26         exper; \
27     }
28 
29 class DaemonUpdater : public HdcTransferBase {
30 public:
31     explicit DaemonUpdater(HTaskInfo hTaskInfo);
32     virtual ~DaemonUpdater();
33     bool CommandDispatch(const uint16_t command, uint8_t *payload, const int payloadSize) override;
34 #ifdef UPDATER_UT
35     void DoTransferFinish();
36 #endif
37 private:
38     virtual void WhenTransferFinish(CtxFile *context) override;
39     void ProcessUpdateCheck(const uint8_t *payload, const int payloadSize);
40     void RunUpdateShell(uint8_t type, const std::string &options, const std::string &package);
41     void AsyncUpdateFinish(uint8_t type, int32_t retCode, const string &result);
42     void SendProgress(size_t dataLen);
43 #ifdef UPDATER_UT
SendToAnother(const uint16_t command,uint8_t * bufPtr,const int size)44     bool SendToAnother(const uint16_t command, uint8_t *bufPtr, const int size)
45     {
46         WRITE_LOG(LOG_DEBUG, "SendToAnother %d size %d", command, size);
47         return true;
48     }
TaskFinish()49     void TaskFinish()
50     {
51         WRITE_LOG(LOG_DEBUG, "TaskFinish ");
52         return;
53     }
54 #endif
55 private:
56     double currSize_ = 0;
57     double totalSize_ = 0;
58     int32_t percentage_ = 0;
59     void* flashHandle_ = nullptr;
60     std::string errorMsg_ {};
61 };
62 } // namespace Hdc
63 #endif