device-thermal: Apply HAL ABI versioning rule 95/309995/1
authorYunhee Seo <yuni.seo@samsung.com>
Fri, 19 Apr 2024 04:00:27 +0000 (13:00 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Fri, 19 Apr 2024 04:35:46 +0000 (13:35 +0900)
In HAL-API-[module], source file name should follow hal-api-[module].c format
for applying HAL ABI versioning.

hal-api-device-thermal.c
 -> HAL-INTERFACE Wrapper call according to major version and implemenation of
    functions declared in hal-device-thermal.h

To apply HAL ABI versioning, the backend function structure memory allocation part
was moved to hal-api-device-thermal.

Furthermore, existing interface file is devided.
Below is a description of the purpose of header files.

hal-device-thermal-types.h
 -> Common data types like structures or enums used between the device-thermal
    HAL-API and HAL-BACKEND
hal-device-thermal-interface-1.h
 -> Declaration of functions to be implemented in the device-thermal HAL-BACKEND(Major version 1),
    as well as definitions of data structures used between the HAL-API and HAL-BACKEND(Major version 1)
hal-device-thermal-interface.h
 -> Includes the hal-device-thermal-interface-[major].h files for each supported
    major version.
hal-device-thermal.h
 -> Declaration of the device-thermal HAL-API functions

As applying HAL ABI versioning, definitions are also chaged in Native API style.
The module names that are not being used well have been modified to proper names.
"thermal" -> "device-thermal"

Change-Id: I1c8b25258edbfa32a539f681f50a9bd0b4d4f294
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
haltest/thermal.cpp
include/hal-device-thermal-interface-1.h [new file with mode: 0644]
include/hal-device-thermal-interface.h [new file with mode: 0644]
include/hal-device-thermal-types.h [new file with mode: 0644]
include/hal-device-thermal.h [new file with mode: 0644]
include/hal-thermal-interface.h [deleted file]
include/hal-thermal.h [deleted file]
src/hal-api-device-thermal.c [new file with mode: 0644]
src/thermal.c [deleted file]

index 2cb4efccbfd5fca99209d4a0c794c751f49d9290..33d3d8d6f0b8a4979b0deb8f3ebb63c0748283aa 100644 (file)
@@ -1,7 +1,7 @@
 #include <system_info.h>
 
 #include "haltest.h"
-#include "hal-thermal.h"
+#include "hal-device-thermal.h"
 
 class THERMAL : public testing::Test
 {
@@ -35,7 +35,7 @@ bool THERMAL::ap = false;
 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";
 }
@@ -43,7 +43,7 @@ static void __updated_cb(struct thermal_info *info, void *data)
 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");
diff --git a/include/hal-device-thermal-interface-1.h b/include/hal-device-thermal-interface-1.h
new file mode 100644 (file)
index 0000000..e996466
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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__ */
diff --git a/include/hal-device-thermal-interface.h b/include/hal-device-thermal-interface.h
new file mode 100644 (file)
index 0000000..a025fe9
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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__ */
diff --git a/include/hal-device-thermal-types.h b/include/hal-device-thermal-types.h
new file mode 100644 (file)
index 0000000..f2a7f02
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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__ */
diff --git a/include/hal-device-thermal.h b/include/hal-device-thermal.h
new file mode 100644 (file)
index 0000000..94c0527
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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__ */
diff --git a/include/hal-thermal-interface.h b/include/hal-thermal-interface.h
deleted file mode 100644 (file)
index 76fc3e6..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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__ */
diff --git a/include/hal-thermal.h b/include/hal-thermal.h
deleted file mode 100644 (file)
index f01153f..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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__ */
diff --git a/src/hal-api-device-thermal.c b/src/hal-api-device-thermal.c
new file mode 100644 (file)
index 0000000..5b63038
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * 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);
+}
+
diff --git a/src/thermal.c b/src/thermal.c
deleted file mode 100644 (file)
index 2958df0..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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);
-}
-