#include <system_info.h>
#include "haltest.h"
-#include "hal-thermal.h"
+#include "hal-device-thermal.h"
class THERMAL : public testing::Test
{
bool THERMAL::battery = false;
// dummy
-static void __updated_cb(struct thermal_info *info, void *data)
+static void __updated_cb(hal_device_thermal_info_s *info, void *data)
{
EXPECT_NE(info, nullptr) << "Failed to get thermal information";
}
TEST_F(THERMAL, GetInfoP)
{
int ret_val;
- struct thermal_info info;
+ hal_device_thermal_info_s info;
if (!THERMAL::supported) {
SKIP_MESSAGE("Thermal not supported");
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __HAL_DEVICE_TEMPERATURE_INTERFACE_1_H__
+#define __HAL_DEVICE_TEMPERATURE_INTERFACE_1_H__
+
+#include "hal-device-thermal-types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _hal_backend_device_thermal_funcs {
+ /* Get thermal state */
+ int (*get_info)(hal_device_thermal_e type, hal_device_thermal_info_s *info);
+
+ /* Register thermal event */
+ int (*register_changed_event)(hal_device_thermal_updated_cb updated_cb, void *data);
+ int (*unregister_changed_event)(hal_device_thermal_updated_cb updated_cb);
+} hal_backend_device_thermal_funcs;
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_DEVICE_TEMPERATURE_INTERFACE_1_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __HAL_DEVICE_TEMPERATURE_INTERFACE_H__
+#define __HAL_DEVICE_TEMPERATURE_INTERFACE_H__
+
+#include "hal-device-thermal-types.h"
+#include "hal-device-thermal-interface-1.h"
+
+#endif /* __HAL_DEVICE_TEMPERATURE_INTERFACE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __HAL_DEVICE_TEMPERATURE_TYPES_H__
+#define __HAL_DEVICE_TEMPERATURE_TYPES_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumeration for types of thermal.
+ * @since HAL_MODULE_DEVICE_THERMAL 1.0
+ */
+typedef enum {
+ HAL_DEVICE_THERMAL_AP, /**< AP temperature (Since HAL_MODULE_DEVICE_THERMAL 1.0) */
+ HAL_DEVICE_THERMAL_CP, /**< CP temperature (Since HAL_MODULE_DEVICE_THERMAL 1.0) */
+ HAL_DEVICE_THERMAL_BATTERY, /**< Battery temperature (Since HAL_MODULE_DEVICE_THERMAL 1.0) */
+} hal_device_thermal_e;
+
+/**
+ * @brief Structure for thermal information.
+ * @since HAL_MODULE_DEVICE_THERMAL 1.0
+ */
+typedef struct {
+ int temp;
+ int adc;
+} hal_device_thermal_info_s;
+
+/**
+ * @brief Called when a thermal information is handled.
+ * @since HAL_MODULE_DEVICE_THERMAL 1.0
+ * @param[out] info Thermal information
+ * @param[out] user_data User data passed
+ */
+typedef void (*hal_device_thermal_updated_cb)(hal_device_thermal_info_s *info, void *data);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_DEVICE_TEMPERATURE_TYPES_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __HAL_DEVICE_TEMPERATURE_H__
+#define __HAL_DEVICE_TEMPERATURE_H__
+
+#include <hal/hal-common.h>
+#include "hal-device-thermal-interface.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int hal_device_thermal_get_backend(void);
+int hal_device_thermal_put_backend(void);
+int hal_device_thermal_get_info(hal_device_thermal_e type, hal_device_thermal_info_s *info);
+int hal_device_thermal_register_changed_event(hal_device_thermal_updated_cb updated_cb, void *data);
+int hal_device_thermal_unregister_changed_event(hal_device_thermal_updated_cb updated_cb);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __HAL_DEVICE_TEMPERATURE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __HAL_TEMPERATURE_INTERFACE_H__
-#define __HAL_TEMPERATURE_INTERFACE_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum
-{
- HAL_DEVICE_THERMAL_AP, /* AP temperature */
- HAL_DEVICE_THERMAL_CP, /* CP temperature */
- HAL_DEVICE_THERMAL_BATTERY, /* Battery temperature */
-} hal_device_thermal_e;
-
-struct thermal_info {
- int temp;
- int adc;
-};
-
-typedef void (*ThermalUpdated)(struct thermal_info *info, void *data);
-
-typedef struct _hal_backend_thermal_funcs {
- /* Get thermal state */
- int (*get_info)(hal_device_thermal_e type, struct thermal_info *info);
-
- /* Register thermal event */
- int (*register_changed_event)(ThermalUpdated updated_cb, void *data);
- int (*unregister_changed_event)(ThermalUpdated updated_cb);
-} hal_backend_thermal_funcs;
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* __HAL_TEMPERATURE_INTERFACE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __HAL_TEMPERATURE_H__
-#define __HAL_TEMPERATURE_H__
-
-#include <hal/hal-common.h>
-#include "hal-thermal-interface.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int hal_device_thermal_get_backend(void);
-int hal_device_thermal_put_backend(void);
-int hal_device_thermal_get_info(hal_device_thermal_e type, struct thermal_info *info);
-int hal_device_thermal_register_changed_event(ThermalUpdated updated_cb, void *data);
-int hal_device_thermal_unregister_changed_event(ThermalUpdated updated_cb);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* __HAL_TEMPERATURE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdlib.h>
+
+#include <hal/hal-common.h>
+
+#include "common.h"
+#include "hal-device-thermal-interface.h"
+
+static hal_backend_device_thermal_funcs *hal_device_thermal_funcs = NULL;
+
+int hal_device_thermal_get_backend(void)
+{
+ int ret;
+
+ if (hal_device_thermal_funcs)
+ return 0;
+
+ hal_device_thermal_funcs = calloc(1, sizeof(hal_backend_device_thermal_funcs));
+ if (!hal_device_thermal_funcs)
+ return -ENOMEM;
+
+ ret = hal_common_get_backend(HAL_MODULE_DEVICE_THERMAL, (void **)&hal_device_thermal_funcs);
+ if (ret < 0) {
+ _E("Failed to get device-thermal backend");
+ free(hal_device_thermal_funcs);
+ hal_device_thermal_funcs = NULL;
+ return -ENOTSUP;
+ }
+
+ return 0;
+}
+
+int hal_device_thermal_put_backend(void)
+{
+ int ret = 0;
+
+ if (!hal_device_thermal_funcs)
+ return 0;
+
+ ret = hal_common_put_backend(HAL_MODULE_DEVICE_THERMAL, (void *)hal_device_thermal_funcs);
+ if (ret < 0) {
+ _E("Failed to put device-thermal backend");
+ return ret;
+ }
+
+ free(hal_device_thermal_funcs);
+ hal_device_thermal_funcs = NULL;
+
+ return 0;
+}
+
+int hal_device_thermal_get_info(hal_device_thermal_e type, hal_device_thermal_info_s *info)
+{
+ int ret;
+
+ if (!info)
+ return -EINVAL;
+
+ if (!hal_device_thermal_funcs) {
+ if ((ret = hal_device_thermal_get_backend()) < 0)
+ return ret;
+ }
+
+ if (!hal_device_thermal_funcs ||
+ !hal_device_thermal_funcs->get_info)
+ return -ENOTSUP;
+
+ return hal_device_thermal_funcs->get_info(type, info);
+}
+
+int hal_device_thermal_register_changed_event(hal_device_thermal_updated_cb updated_cb, void *data)
+{
+ int ret;
+
+ if (!updated_cb || !data)
+ return -EINVAL;
+
+ if (!hal_device_thermal_funcs) {
+ if ((ret = hal_device_thermal_get_backend()) < 0)
+ return ret;
+ }
+
+ if (!hal_device_thermal_funcs ||
+ !hal_device_thermal_funcs->register_changed_event)
+ return -ENOTSUP;
+
+ return hal_device_thermal_funcs->register_changed_event(updated_cb, data);
+}
+
+int hal_device_thermal_unregister_changed_event(hal_device_thermal_updated_cb updated_cb)
+{
+ int ret;
+
+ if (!updated_cb)
+ return -EINVAL;
+
+ if (!hal_device_thermal_funcs) {
+ if ((ret = hal_device_thermal_get_backend()) < 0)
+ return ret;
+ }
+
+ if (!hal_device_thermal_funcs ||
+ !hal_device_thermal_funcs->unregister_changed_event)
+ return -ENOTSUP;
+
+ return hal_device_thermal_funcs->unregister_changed_event(updated_cb);
+}
+
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hal/hal-common.h>
-
-#include "common.h"
-#include "hal-thermal-interface.h"
-
-static hal_backend_thermal_funcs *hal_thermal_funcs = NULL;
-
-int hal_device_thermal_get_backend(void)
-{
- int ret;
-
- if (hal_thermal_funcs)
- return 0;
-
- ret = hal_common_get_backend(HAL_MODULE_DEVICE_THERMAL, (void **)&hal_thermal_funcs);
- if (ret < 0) {
- _E("Failed to get thermal backend");
- return -EINVAL;
- }
-
- return 0;
-}
-
-int hal_device_thermal_put_backend(void)
-{
- if (!hal_thermal_funcs)
- return 0;
-
- hal_common_put_backend(HAL_MODULE_DEVICE_THERMAL, (void *)hal_thermal_funcs);
- hal_thermal_funcs = NULL;
-
- return 0;
-}
-
-int hal_device_thermal_get_info(hal_device_thermal_e type, struct thermal_info *info)
-{
- int ret;
-
- if (!hal_thermal_funcs) {
- if ((ret = hal_device_thermal_get_backend()) < 0)
- return ret;
- }
-
- if (!hal_thermal_funcs ||
- !hal_thermal_funcs->get_info)
- return -ENODEV;
-
- return hal_thermal_funcs->get_info(type, info);
-}
-
-int hal_device_thermal_register_changed_event(ThermalUpdated updated_cb, void *data)
-{
- int ret;
-
- if (!hal_thermal_funcs) {
- if ((ret = hal_device_thermal_get_backend()) < 0)
- return ret;
- }
-
- if (!hal_thermal_funcs ||
- !hal_thermal_funcs->register_changed_event)
- return -ENODEV;
-
- return hal_thermal_funcs->register_changed_event(updated_cb, data);
-}
-
-int hal_device_thermal_unregister_changed_event(ThermalUpdated updated_cb)
-{
- int ret;
-
- if (!hal_thermal_funcs) {
- if ((ret = hal_device_thermal_get_backend()) < 0)
- return ret;
- }
-
- if (!hal_thermal_funcs ||
- !hal_thermal_funcs->unregister_changed_event)
- return -ENODEV;
-
- return hal_thermal_funcs->unregister_changed_event(updated_cb);
-}
-