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 : #include "package_hash_store.h"
12 : #include "tsd_log.h"
13 :
14 : namespace tsd {
15 :
16 1 : void PackageHashStore::SetDeviceCommonSinkPackHashValue(const std::string& pkgName, const std::string& hashValue)
17 : {
18 1 : pkgDeviceHashValue_[pkgName] = hashValue;
19 1 : TSD_INFO("update device package:%s hash value:%s", pkgName.c_str(), hashValue.c_str());
20 1 : }
21 :
22 13 : std::string PackageHashStore::GetDeviceCommonSinkPackHashValue(const std::string& pkgName) const
23 : {
24 13 : auto iter = pkgDeviceHashValue_.find(pkgName);
25 13 : if (iter != pkgDeviceHashValue_.end()) {
26 5 : TSD_INFO("get device package:%s, hash value:%s", pkgName.c_str(), iter->second.c_str());
27 5 : return iter->second;
28 : }
29 16 : return "";
30 : }
31 :
32 15 : void PackageHashStore::SetHostCommonSinkPackHashValue(const std::string& pkgName, const std::string& hashValue)
33 : {
34 15 : pkgHostHashValue_[pkgName] = hashValue;
35 15 : TSD_INFO("update host package:%s hash value:%s", pkgName.c_str(), hashValue.c_str());
36 15 : }
37 :
38 17 : std::string PackageHashStore::GetHostCommonSinkPackHashValue(const std::string& pkgName) const
39 : {
40 17 : auto iter = pkgHostHashValue_.find(pkgName);
41 17 : if (iter != pkgHostHashValue_.end()) {
42 17 : TSD_INFO("get host package:%s, hash value:%s", pkgName.c_str(), iter->second.c_str());
43 17 : return iter->second;
44 : }
45 0 : return "";
46 : }
47 :
48 13 : bool PackageHashStore::IsCommonSinkHostAndDevicePkgSame(const std::string& pkgName) const
49 : {
50 : return (
51 30 : (GetHostCommonSinkPackHashValue(pkgName) == GetDeviceCommonSinkPackHashValue(pkgName)) &&
52 30 : (!GetHostCommonSinkPackHashValue(pkgName).empty()));
53 : }
54 :
55 96 : void PackageHashStore::StoreAllPkgHashValue(const HDCMessage& msg)
56 : {
57 192 : if ((msg.type() != HDCMessage::TSD_UPDATE_PACKAGE_PROCESS_CONFIG_RSP) &&
58 96 : (msg.type() != HDCMessage::TSD_GET_DEVICE_PACKAGE_CHECKCODE_NORMAL_RSP)) {
59 96 : return;
60 : }
61 :
62 0 : for (int32_t j = 0; j < msg.package_hash_code_list_size(); j++) {
63 0 : SinkPackageHashCodeInfo tempNode = msg.package_hash_code_list(j);
64 0 : SetDeviceCommonSinkPackHashValue(tempNode.package_name(), tempNode.hash_code());
65 0 : }
66 : }
67 :
68 23 : void PackageHashStore::Clear()
69 : {
70 23 : pkgHostHashValue_.clear();
71 23 : pkgDeviceHashValue_.clear();
72 23 : }
73 :
74 : } // namespace tsd
|