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