Line data Source code
1 : /**
2 : * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #ifndef TSD_PACKAGE_CHECK_CODE_SERVICE_H
12 : #define TSD_PACKAGE_CHECK_CODE_SERVICE_H
13 :
14 : #include "device_comm_agent.h"
15 : #include "capability_manager.h"
16 : #include "package_env_info.h"
17 : #include "package_hash_store.h"
18 : #include "package_context.h"
19 : #include "hdc_message_builder.h"
20 : #include "proto/tsd_message.pb.h"
21 : #include "basic_define.h"
22 :
23 : #include <string>
24 :
25 : namespace tsd {
26 :
27 : class PackageCheckCodeService {
28 : public:
29 : PackageCheckCodeService(
30 : DeviceCommAgent& commAgent, CapabilityManager& capabilityMgr, PackageEnvInfo& envInfo,
31 : PackageHashStore& hashStore, PackageContext& ctx);
32 : ~PackageCheckCodeService() = default;
33 :
34 : TSD_StatusT InitTsdClient();
35 : TSD_StatusT WaitPkgRsp(const uint32_t timeout, const bool ignoreRecvErr = false);
36 : TSD_StatusT GetDeviceCheckCode();
37 : TSD_StatusT GetDeviceCheckCodeOnce(const HDCMessage& msg);
38 : TSD_StatusT GetDeviceCheckCodeRetry(const HDCMessage& msg);
39 : void GetDeviceCheckCodeRetrySupport();
40 : TSD_StatusT PrepareForCheckCode();
41 : TSD_StatusT GetDeviceHsPkgCheckCode(
42 : const uint32_t checkCode, const HDCMessage::MsgType msgType, const bool beforeSendFlag,
43 : const MessageContext& baseCtx);
44 : TSD_StatusT GetCannHsPkgCheckCode(
45 : const std::string& pkgPureName, const std::string& hostPkgHash, const MessageContext& baseCtx);
46 : void HandleNormalPackageCheckCodeRsp(const HDCMessage& msg);
47 : void HandleCannHsCheckCodeRsp(const HDCMessage& msg);
48 : void SaveDeviceCheckCode(const HDCMessage& msg);
49 262 : uint32_t GetHostCheckCode(TsdLoadPackageType type) const { return ctx_.hostCheckCode[static_cast<uint32_t>(type)]; }
50 8 : uint32_t GetPeerCheckCode(uint32_t type) const { return ctx_.peerCheckCode[type]; }
51 20 : void SetPeerCheckCode(uint32_t type, uint32_t code) { ctx_.peerCheckCode[type] = code; }
52 1 : void SetHostCheckCodeByIndex(uint32_t type, uint32_t code) { ctx_.hostCheckCode[type] = code; }
53 4 : ResponseCode& GetPkgRspCode() { return ctx_.pkgRspCode; }
54 : const ResponseCode& GetPkgRspCode() const { return ctx_.pkgRspCode; }
55 :
56 : private:
57 : void SetHostCheckCode(HDCMessage& msg, TsdLoadPackageType type);
58 :
59 : DeviceCommAgent& commAgent_;
60 : CapabilityManager& capabilityMgr_;
61 : PackageEnvInfo& envInfo_;
62 : PackageHashStore& hashStore_;
63 : PackageContext& ctx_;
64 : };
65 :
66 : } // namespace tsd
67 :
68 : #endif // TSD_PACKAGE_CHECK_CODE_SERVICE_H
|