1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_HARDWARE_THERMAL_V2_0_THERMAL_H
18 #define ANDROID_HARDWARE_THERMAL_V2_0_THERMAL_H
19 
20 #include <android/hardware/thermal/2.0/IThermal.h>
21 #include <hidl/MQDescriptor.h>
22 #include <hidl/Status.h>
23 
24 namespace android {
25 namespace hardware {
26 namespace thermal {
27 namespace V2_0 {
28 namespace implementation {
29 
30 using ::android::sp;
31 using ::android::hardware::hidl_array;
32 using ::android::hardware::hidl_memory;
33 using ::android::hardware::hidl_string;
34 using ::android::hardware::hidl_vec;
35 using ::android::hardware::Return;
36 using ::android::hardware::Void;
37 using ::android::hardware::thermal::V1_0::CpuUsage;
38 using ::android::hardware::thermal::V2_0::CoolingType;
39 using ::android::hardware::thermal::V2_0::IThermal;
40 using CoolingDevice_1_0 = ::android::hardware::thermal::V1_0::CoolingDevice;
41 using CoolingDevice_2_0 = ::android::hardware::thermal::V2_0::CoolingDevice;
42 using Temperature_1_0 = ::android::hardware::thermal::V1_0::Temperature;
43 using Temperature_2_0 = ::android::hardware::thermal::V2_0::Temperature;
44 using ::android::hardware::thermal::V2_0::IThermalChangedCallback;
45 using ::android::hardware::thermal::V2_0::TemperatureThreshold;
46 using ::android::hardware::thermal::V2_0::TemperatureType;
47 
48 struct CallbackSetting {
CallbackSettingCallbackSetting49     CallbackSetting(sp<IThermalChangedCallback> callback, bool is_filter_type, TemperatureType type)
50         : callback(callback), is_filter_type(is_filter_type), type(type) {}
51     sp<IThermalChangedCallback> callback;
52     bool is_filter_type;
53     TemperatureType type;
54 };
55 
56 class Thermal : public IThermal {
57    public:
58     // Methods from ::android::hardware::thermal::V1_0::IThermal follow.
59     Return<void> getTemperatures(getTemperatures_cb _hidl_cb) override;
60     Return<void> getCpuUsages(getCpuUsages_cb _hidl_cb) override;
61     Return<void> getCoolingDevices(getCoolingDevices_cb _hidl_cb) override;
62 
63     // Methods from ::android::hardware::thermal::V2_0::IThermal follow.
64     Return<void> getCurrentTemperatures(bool filterType, TemperatureType type,
65                                         getCurrentTemperatures_cb _hidl_cb) override;
66     Return<void> getTemperatureThresholds(bool filterType, TemperatureType type,
67                                           getTemperatureThresholds_cb _hidl_cb) override;
68     Return<void> registerThermalChangedCallback(
69         const sp<IThermalChangedCallback>& callback, bool filterType, TemperatureType type,
70         registerThermalChangedCallback_cb _hidl_cb) override;
71     Return<void> unregisterThermalChangedCallback(
72         const sp<IThermalChangedCallback>& callback,
73         unregisterThermalChangedCallback_cb _hidl_cb) override;
74     Return<void> getCurrentCoolingDevices(bool filterType, CoolingType type,
75                                           getCurrentCoolingDevices_cb _hidl_cb) override;
76 
77    private:
78     std::mutex thermal_callback_mutex_;
79     std::vector<CallbackSetting> callbacks_;
80 };
81 
82 }  // namespace implementation
83 }  // namespace V2_0
84 }  // namespace thermal
85 }  // namespace hardware
86 }  // namespace android
87 
88 #endif  // ANDROID_HARDWARE_THERMAL_V2_0_THERMAL_H
89