Ram Chandrasekar | dac8f7d | 2020-06-10 12:23:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 22 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 25 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 27 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 28 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef ANDROID_QTI_VENDOR_THERMAL_H |
| 32 | #define ANDROID_QTI_VENDOR_THERMAL_H |
| 33 | |
| 34 | #include <mutex> |
| 35 | #include <thread> |
| 36 | |
| 37 | #include <android/hardware/thermal/2.0/IThermal.h> |
| 38 | #include <hidl/MQDescriptor.h> |
| 39 | #include <android/hardware/thermal/2.0/IThermalChangedCallback.h> |
| 40 | |
| 41 | #include <hidl/Status.h> |
| 42 | |
| 43 | #include "thermalUtils.h" |
| 44 | #include "thermalData.h" |
| 45 | |
| 46 | namespace android { |
| 47 | namespace hardware { |
| 48 | namespace thermal { |
| 49 | namespace V2_0 { |
| 50 | namespace implementation { |
| 51 | |
| 52 | struct CallbackSetting { |
| 53 | sp<IThermalChangedCallback> callback; |
| 54 | bool is_filter_type; |
| 55 | TemperatureType type; |
| 56 | |
| 57 | CallbackSetting(sp<IThermalChangedCallback> callback, |
| 58 | bool is_filter_type, TemperatureType type) |
| 59 | : callback(callback), |
| 60 | is_filter_type(is_filter_type), type(type) {} |
| 61 | }; |
| 62 | |
| 63 | class Thermal : public IThermal { |
| 64 | public: |
| 65 | Thermal(); |
| 66 | ~Thermal() = default; |
| 67 | |
| 68 | Thermal(const Thermal &) = delete; |
| 69 | void operator=(const Thermal &) = delete; |
| 70 | |
| 71 | Return<void> getTemperatures( |
| 72 | getTemperatures_cb _hidl_cb) override; |
| 73 | Return<void> getCpuUsages(getCpuUsages_cb _hidl_cb) override; |
| 74 | Return<void> getCoolingDevices( |
| 75 | getCoolingDevices_cb _hidl_cb) override; |
| 76 | |
| 77 | Return<void> getCurrentTemperatures( |
| 78 | bool filterType, |
| 79 | TemperatureType type, |
| 80 | getCurrentTemperatures_cb _hidl_cb) override; |
| 81 | Return<void> getTemperatureThresholds( |
| 82 | bool filterType, |
| 83 | TemperatureType type, |
| 84 | getTemperatureThresholds_cb _hidl_cb) override; |
| 85 | Return<void> registerThermalChangedCallback( |
| 86 | const sp<IThermalChangedCallback> &callback, |
| 87 | bool filterType, |
| 88 | TemperatureType type, |
| 89 | registerThermalChangedCallback_cb _hidl_cb) |
| 90 | override; |
| 91 | Return<void> unregisterThermalChangedCallback( |
| 92 | const sp<IThermalChangedCallback> &callback, |
| 93 | unregisterThermalChangedCallback_cb _hidl_cb) |
| 94 | override; |
| 95 | Return<void> getCurrentCoolingDevices( |
| 96 | bool filterType, |
| 97 | CoolingType type, |
| 98 | getCurrentCoolingDevices_cb _hidl_cb) override; |
| 99 | |
| 100 | void sendThrottlingChangeCB(const Temperature &t); |
| 101 | |
| 102 | private: |
| 103 | std::mutex thermal_cb_mutex; |
| 104 | std::vector<CallbackSetting> cb; |
| 105 | ThermalUtils utils; |
| 106 | }; |
| 107 | |
| 108 | } // namespace implementation |
| 109 | } // namespace V2_0 |
| 110 | } // namespace thermal |
| 111 | } // namespace hardware |
| 112 | } // namespace android |
| 113 | |
| 114 | #endif // ANDROID_QTI_VENDOR_THERMAL_H |