• 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_HOST_UPDATER_H
16 #define HDC_HOST_UPDATER_H
17 #include "common.h"
18 #include "transfer.h"
19 
20 namespace Hdc {
21 #define HOSTUPDATER_CHECK(retCode, exper, ...) \
22     if (!(retCode)) { \
23         LogMsg(MSG_FAIL, __VA_ARGS__); \
24         exper; \
25     }
26 
27 class HostUpdater : public HdcTransferBase {
28 public:
29     explicit HostUpdater(HTaskInfo hTaskInfo);
30     virtual ~HostUpdater();
31     bool CommandDispatch(const uint16_t command, uint8_t *payload, const int payloadSize) override;
32 
33     static bool CheckMatchUpdate(const std::string &input, std::string &stringError, uint16_t &cmdFlag, bool &bJumpDo);
34     static bool ConfirmCommand(const string &commandIn, bool &closeInput);
35 #ifdef UPDATER_UT
OpenFile()36     void OpenFile()
37     {
38         CheckMaster(&ctxNow);
39     }
40     static void SetInput(const std::string &input);
41 #endif
42 private:
43     void CheckMaster(CtxFile *context) override;
44     bool BeginTransfer(CtxFile &context,
45         const std::string &function, const char *payload, int minParam, int fileIndex);
46     bool CheckUpdateContinue(const uint16_t command, const uint8_t *payload, int payloadSize);
47     void RunQueue(CtxFile &context);
48     std::string GetFileName(const std::string &fileName) const;
49     void ProcessProgress(uint32_t percentage);
50     void SendRawData(uint8_t *bufPtr, const int size);
51 #ifdef UPDATER_UT
LogMsg(MessageLevel level,const char * msg,...)52     void LogMsg(MessageLevel level, const char *msg, ...)
53     {
54         return;
55     }
SendToAnother(const uint16_t command,uint8_t * bufPtr,const int size)56     bool SendToAnother(const uint16_t command, uint8_t *bufPtr, const int size)
57     {
58         std::string s((char *)bufPtr, size);
59         WRITE_LOG(LOG_DEBUG, "SendToAnother command %d size %d %s", command, size, s.c_str());
60         return true;
61     }
62 #endif
63 private:
64     bool CheckCmd(const std::string &function, const char *payload, int param);
65     bool sendProgress = false;
66 };
67 }
68 #endif