1 /*
2  * Copyright (c) 2021 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 "thermal_sensor_info.h"
17 #include "thermal_common.h"
18 #include "thermal_service.h"
19 
20 namespace OHOS {
21 namespace PowerMgr {
22 namespace {
23 }
24 
GetTypeTempMap()25 TypeTempMap ThermalSensorInfo::GetTypeTempMap()
26 {
27     std::lock_guard<std::mutex> lock(mutex_);
28     return this->typeTempMap_;
29 }
30 
SetTypeTempMap(TypeTempMap & typeTempMap)31 void ThermalSensorInfo::SetTypeTempMap(TypeTempMap &typeTempMap)
32 {
33     std::lock_guard<std::mutex> lock(mutex_);
34     this->typeTempMap_ = typeTempMap;
35 }
36 
GetTemp(std::string type)37 int32_t ThermalSensorInfo::GetTemp(std::string type)
38 {
39     std::lock_guard<std::mutex> lock(mutex_);
40     TypeTempMap::iterator iter = this->typeTempMap_.find(type);
41     if (iter == this->typeTempMap_.end()) {
42         THERMAL_HILOGW(COMP_SVC, "failed to find sensor info");
43         return ERR_INVALID_VALUE;
44     }
45     temp_ = (int32_t) this->typeTempMap_[type];
46     return temp_;
47 }
48 
GetHistoryTemperature(std::string type)49 std::list<int> ThermalSensorInfo::GetHistoryTemperature(std::string type)
50 {
51     historyMap_ = typeHistoryMap_[type];
52     return historyMap_;
53 }
54 
NotifyObserver()55 void ThermalSensorInfo::NotifyObserver()
56 {
57     auto tms = ThermalService::GetInstance();
58     tms->GetObserver()->OnReceivedSensorInfo(GetTypeTempMap());
59 }
60 } // PowerMgr
61 } // OHOS