Ram Chandrasekar | 14a48f5 | 2021-04-06 13:25:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021, The Linux Foundation. All rights reserved. |
Manaf Meethalavalappu Pallikunhi | ab1e3c5 | 2022-05-14 01:53:29 +0530 | [diff] [blame] | 3 | * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. |
Ram Chandrasekar | 14a48f5 | 2021-04-06 13:25:32 -0700 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * * Neither the name of The Linux Foundation nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived |
| 16 | * from this software without specific prior written permission. |
| 17 | * |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 20 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 26 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 29 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
Bavyasritha Alahari | 0a344f4 | 2023-04-26 17:16:51 -0700 | [diff] [blame^] | 32 | /* Changes from Qualcomm Innovation Center are provided under the following license: |
| 33 | |
| 34 | Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. |
| 35 | SPDX-License-Identifier: BSD-3-Clause-Clear */ |
Ram Chandrasekar | 14a48f5 | 2021-04-06 13:25:32 -0700 | [diff] [blame] | 36 | |
| 37 | #ifndef THERMAL_THERMAL_MONITOR_NETLINK_H__ |
| 38 | #define THERMAL_THERMAL_MONITOR_NETLINK_H__ |
| 39 | |
| 40 | #include <thread> |
| 41 | #include <netlink/genl/genl.h> |
| 42 | #include <netlink/genl/mngt.h> |
| 43 | #include <netlink/genl/ctrl.h> |
| 44 | #include <netlink/netlink.h> |
Bavyasritha Alahari | 0a344f4 | 2023-04-26 17:16:51 -0700 | [diff] [blame^] | 45 | #include <aidl/android/hardware/thermal/BnThermal.h> |
Ram Chandrasekar | 14a48f5 | 2021-04-06 13:25:32 -0700 | [diff] [blame] | 46 | |
Bavyasritha Alahari | 0a344f4 | 2023-04-26 17:16:51 -0700 | [diff] [blame^] | 47 | namespace aidl{ |
Ram Chandrasekar | 14a48f5 | 2021-04-06 13:25:32 -0700 | [diff] [blame] | 48 | namespace android { |
| 49 | namespace hardware { |
| 50 | namespace thermal { |
Ram Chandrasekar | 14a48f5 | 2021-04-06 13:25:32 -0700 | [diff] [blame] | 51 | |
| 52 | using eventMonitorCB = std::function<void(int, int)>; |
Manaf Meethalavalappu Pallikunhi | ab1e3c5 | 2022-05-14 01:53:29 +0530 | [diff] [blame] | 53 | using eventCreateMonitorCB = std::function<void(int, const char *)>; |
Ram Chandrasekar | 14a48f5 | 2021-04-06 13:25:32 -0700 | [diff] [blame] | 54 | |
| 55 | class ThermalMonitor { |
| 56 | public: |
| 57 | ThermalMonitor(const eventMonitorCB &inp_event_cb, |
Manaf Meethalavalappu Pallikunhi | ab1e3c5 | 2022-05-14 01:53:29 +0530 | [diff] [blame] | 58 | const eventMonitorCB &inp_sample_cb, |
| 59 | const eventCreateMonitorCB &inp_event_create_cb); |
Ram Chandrasekar | 14a48f5 | 2021-04-06 13:25:32 -0700 | [diff] [blame] | 60 | ~ThermalMonitor(); |
| 61 | |
| 62 | void parse_and_notify(char *inp_buf, ssize_t len); |
| 63 | bool stopPolling() |
| 64 | { |
| 65 | return monitor_shutdown; |
| 66 | } |
| 67 | void start(); |
| 68 | int family_msg_cb(struct nl_msg *msg, void *data); |
| 69 | int event_parse(struct nl_msg *n, void *data); |
| 70 | int sample_parse(struct nl_msg *n, void *data); |
| 71 | private: |
| 72 | std::thread event_th, sample_th; |
| 73 | struct nl_sock *event_soc, *sample_soc; |
| 74 | int event_group, sample_group; |
| 75 | bool monitor_shutdown; |
| 76 | eventMonitorCB event_cb, sample_cb; |
Manaf Meethalavalappu Pallikunhi | ab1e3c5 | 2022-05-14 01:53:29 +0530 | [diff] [blame] | 77 | eventCreateMonitorCB event_create_cb; |
Ram Chandrasekar | 14a48f5 | 2021-04-06 13:25:32 -0700 | [diff] [blame] | 78 | |
| 79 | int fetch_group_id(); |
| 80 | int send_nl_msg(struct nl_msg *msg); |
| 81 | }; |
| 82 | |
Ram Chandrasekar | 14a48f5 | 2021-04-06 13:25:32 -0700 | [diff] [blame] | 83 | } // namespace thermal |
| 84 | } // namespace hardware |
| 85 | } // namespace android |
Bavyasritha Alahari | 0a344f4 | 2023-04-26 17:16:51 -0700 | [diff] [blame^] | 86 | } // namespace aidl |
Ram Chandrasekar | 14a48f5 | 2021-04-06 13:25:32 -0700 | [diff] [blame] | 87 | |
| 88 | #endif // THERMAL_THERMAL_MONITOR_NETLINK_H__ |