1 /*
2 * Copyright (c) 2022-2025 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
16 #include "enabled_comps_dump.h"
17
18 #include "dh_utils_tool.h"
19
20 namespace OHOS {
21 namespace DistributedHardware {
22 IMPLEMENT_SINGLE_INSTANCE(EnabledCompsDump);
23
DumpEnabledComp(const std::string & networkId,const DHType dhType,const std::string & dhId)24 void EnabledCompsDump::DumpEnabledComp(const std::string &networkId, const DHType dhType, const std::string &dhId)
25 {
26 HidumpCompInfo info(networkId, dhType, dhId);
27
28 std::lock_guard<std::mutex> lock(compInfosMutex_);
29 compInfoSet_.emplace(info);
30 }
31
DumpDisabledComp(const std::string & networkId,const DHType dhType,const std::string & dhId)32 void EnabledCompsDump::DumpDisabledComp(const std::string &networkId, const DHType dhType, const std::string &dhId)
33 {
34 HidumpCompInfo info(networkId, dhType, dhId);
35
36 std::lock_guard<std::mutex> lock(compInfosMutex_);
37 auto it = compInfoSet_.find(info);
38 if (it != compInfoSet_.end()) {
39 compInfoSet_.erase(it);
40 }
41 }
42
Dump(std::set<HidumpCompInfo> & compInfoSet)43 void EnabledCompsDump::Dump(std::set<HidumpCompInfo> &compInfoSet)
44 {
45 std::lock_guard<std::mutex> lock(compInfosMutex_);
46 compInfoSet = compInfoSet_;
47 }
48 } // namespace DistributedHardware
49 } // namespace OHOS
50