• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 auto g_service = DelayedSpSingleton<ThermalService>::GetInstance();
24 }
25 
GetTypeTempMap()26 TypeTempMap ThermalSensorInfo::GetTypeTempMap()
27 {
28     std::lock_guard<std::mutex> lock(mutex_);
29     return this->typeTempMap_;
30 }
31 
SetTypeTempMap(TypeTempMap & typeTempMap)32 void ThermalSensorInfo::SetTypeTempMap(TypeTempMap &typeTempMap)
33 {
34     std::lock_guard<std::mutex> lock(mutex_);
35     this->typeTempMap_ = typeTempMap;
36 }
37 
GetTemp(std::string type)38 int32_t ThermalSensorInfo::GetTemp(std::string type)
39 {
40     std::lock_guard<std::mutex> lock(mutex_);
41     TypeTempMap::iterator iter = this->typeTempMap_.find(type);
42     if (iter == this->typeTempMap_.end()) {
43         THERMAL_HILOGW(COMP_SVC, "failed to find sensor info");
44         return ERR_INVALID_VALUE;
45     }
46     temp_ = (int32_t) this->typeTempMap_[type];
47     return temp_;
48 }
49 
GetHistoryTemperature(std::string type)50 std::list<int> ThermalSensorInfo::GetHistoryTemperature(std::string type)
51 {
52     historyMap_ = typeHistoryMap_[type];
53     return historyMap_;
54 }
55 
NotifyObserver()56 void ThermalSensorInfo::NotifyObserver()
57 {
58     g_service->GetObserver()->OnReceivedSensorInfo(GetTypeTempMap());
59 }
60 } // PowerMgr
61 } // OHOS