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