device-haptic: Apply HAL ABI versioning rule 60/309360/3
authorYunhee Seo <yuni.seo@samsung.com>
Tue, 9 Apr 2024 02:22:46 +0000 (11:22 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 15 Apr 2024 07:28:08 +0000 (07:28 +0000)
In HAL-API-[module], source file name should follow hal-api-[module].c format
for applying HAL ABI versioning.

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

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

Change-Id: I2386416788e4b1458bf8d95132a9ba630888ac41
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/hal-api-device-haptic.c [new file with mode: 0644]
src/haptic.c [deleted file]

diff --git a/src/hal-api-device-haptic.c b/src/hal-api-device-haptic.c
new file mode 100644 (file)
index 0000000..ba7b7b3
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <hal/hal-common.h>
+
+#include "hal-device-haptic.h"
+#include "hal-device-haptic-interface.h"
+
+#include "common.h"
+
+static hal_backend_device_haptic_funcs *hal_device_haptic_funcs = NULL;
+/*
+-1 : failed to initialize
+0  : not initialized
+1  : succeeded to initialize
+*/
+static int hal_initialized = 0;
+
+int hal_device_haptic_get_backend(void)
+{
+       int ret;
+
+       if (hal_device_haptic_funcs)
+               return 0;
+
+       hal_device_haptic_funcs = calloc(1, sizeof(hal_backend_device_haptic_funcs));
+       if (!hal_device_haptic_funcs)
+               return -ENOMEM;
+
+       ret = hal_common_get_backend(HAL_MODULE_DEVICE_HAPTIC, (void **)&hal_device_haptic_funcs);
+       if (ret < 0) {
+               _E("Failed to get device-haptic backend");
+               free(hal_device_haptic_funcs);
+               hal_device_haptic_funcs = NULL;
+               hal_initialized = -1;
+               return -ENODEV;
+       }
+
+       hal_initialized = 1;
+       return 0;
+}
+
+int hal_device_haptic_put_backend(void)
+{
+       if (!hal_device_haptic_funcs)
+               return -ENODEV;
+
+       hal_common_put_backend(HAL_MODULE_DEVICE_HAPTIC, (void *)hal_device_haptic_funcs);
+       free(hal_device_haptic_funcs);
+       hal_device_haptic_funcs = NULL;
+       hal_initialized = 0;
+
+       return 0;
+}
+
+int hal_device_haptic_check_backend(void)
+{
+       if (!hal_device_haptic_funcs)
+               return -ENODEV;
+
+       return 0;
+}
+
+int hal_device_haptic_get_device_count(int *count)
+{
+       int ret;
+
+       if (!hal_device_haptic_funcs && !hal_initialized) {
+               if ((ret = hal_device_haptic_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->get_device_count)
+               return -ENODEV;
+
+       if(!count)
+               return -EINVAL;
+
+       return hal_device_haptic_funcs->get_device_count(count);
+}
+
+int hal_device_haptic_open_device(int *handle)
+{
+       int ret;
+
+       if (!hal_device_haptic_funcs && !hal_initialized) {
+               if ((ret = hal_device_haptic_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->open_device)
+               return -ENODEV;
+
+       if (!handle)
+               return -EINVAL;
+
+       return hal_device_haptic_funcs->open_device(handle);
+}
+
+int hal_device_haptic_close_device(int handle)
+{
+       int ret;
+
+       if (!hal_device_haptic_funcs && !hal_initialized) {
+               if ((ret = hal_device_haptic_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->close_device)
+               return -ENODEV;
+
+       return hal_device_haptic_funcs->close_device(handle);
+}
+
+bool hal_device_haptic_is_valid(void)
+{
+       int ret;
+
+       if (!hal_device_haptic_funcs && !hal_initialized) {
+               if ((ret = hal_device_haptic_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->is_valid)
+               return -ENODEV;
+
+       return hal_device_haptic_funcs->is_valid();
+}
+
+int hal_device_haptic_vibrate(int handle, int duration, int frequency, int overdrive, int level, int intensity, int priority)
+{
+       int ret;
+
+       if (!hal_device_haptic_funcs && !hal_initialized) {
+               if ((ret = hal_device_haptic_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->vibrate_monotone)
+               return -ENODEV;
+
+       return hal_device_haptic_funcs->vibrate_monotone(handle, duration, frequency, overdrive,
+                                                                                       level, intensity, priority);
+}
+
+int hal_device_haptic_stop_device(int handle)
+{
+       int ret;
+
+       if (!hal_device_haptic_funcs && !hal_initialized) {
+               if ((ret = hal_device_haptic_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->stop_device)
+               return -ENODEV;
+
+       return hal_device_haptic_funcs->stop_device(handle);
+}
diff --git a/src/haptic.c b/src/haptic.c
deleted file mode 100644 (file)
index dabb892..0000000
+++ /dev/null
@@ -1,172 +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 <stdio.h>
-#include <hal/hal-common.h>
-
-#include "hal-device-haptic.h"
-#include "hal-device-haptic-interface.h"
-
-#include "common.h"
-
-static hal_backend_device_haptic_funcs *hal_device_haptic_funcs = NULL;
-/*
--1 : failed to initialize
-0  : not initialized
-1  : succeeded to initialize
-*/
-static int hal_initialized = 0;
-
-int hal_device_haptic_get_backend(void)
-{
-       int ret;
-
-       if (hal_device_haptic_funcs)
-               return 0;
-
-       ret = hal_common_get_backend(HAL_MODULE_DEVICE_HAPTIC, (void **)&hal_device_haptic_funcs);
-       if (ret < 0) {
-                _E("Failed to get haptic backend");
-               hal_initialized = -1;
-               return -ENODEV;
-       }
-
-       if (!hal_device_haptic_funcs->is_valid || !(hal_device_haptic_funcs->is_valid())) {
-               hal_device_haptic_put_backend();
-               hal_initialized = -1;
-               return -ENODEV;
-       }
-
-       hal_initialized = 1;
-       return 0;
-}
-
-int hal_device_haptic_put_backend(void)
-{
-       if (!hal_device_haptic_funcs)
-               return -ENODEV;
-
-       hal_common_put_backend(HAL_MODULE_DEVICE_HAPTIC, (void *)hal_device_haptic_funcs);
-       hal_device_haptic_funcs = NULL;
-       hal_initialized = 0;
-
-       return 0;
-}
-
-int hal_device_haptic_check_backend(void)
-{
-       if (!hal_device_haptic_funcs)
-               return -ENODEV;
-
-       return 0;
-}
-
-int hal_device_haptic_get_device_count(int *count)
-{
-       int ret;
-
-       if (!hal_device_haptic_funcs && !hal_initialized) {
-               if ((ret = hal_device_haptic_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->get_device_count)
-               return -ENODEV;
-
-       if(!count)
-               return -EINVAL;
-
-       return hal_device_haptic_funcs->get_device_count(count);
-}
-
-int hal_device_haptic_open_device(int *handle)
-{
-       int ret;
-
-       if (!hal_device_haptic_funcs && !hal_initialized) {
-               if ((ret = hal_device_haptic_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->open_device)
-               return -ENODEV;
-
-       if (!handle)
-               return -EINVAL;
-
-       return hal_device_haptic_funcs->open_device(handle);
-}
-
-int hal_device_haptic_close_device(int handle)
-{
-       int ret;
-
-       if (!hal_device_haptic_funcs && !hal_initialized) {
-               if ((ret = hal_device_haptic_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->close_device)
-               return -ENODEV;
-
-       return hal_device_haptic_funcs->close_device(handle);
-}
-
-bool hal_device_haptic_is_valid(void)
-{
-       int ret;
-
-       if (!hal_device_haptic_funcs && !hal_initialized) {
-               if ((ret = hal_device_haptic_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->is_valid)
-               return -ENODEV;
-
-       return hal_device_haptic_funcs->is_valid();
-}
-
-int hal_device_haptic_vibrate(int handle, int duration, int frequency, int overdrive, int level, int intensity, int priority)
-{
-       int ret;
-
-       if (!hal_device_haptic_funcs && !hal_initialized) {
-               if ((ret = hal_device_haptic_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->vibrate_monotone)
-               return -ENODEV;
-
-       return hal_device_haptic_funcs->vibrate_monotone(handle, duration, frequency, overdrive,
-                                                                                       level, intensity, priority);
-}
-
-int hal_device_haptic_stop_device(int handle)
-{
-       int ret;
-
-       if (!hal_device_haptic_funcs && !hal_initialized) {
-               if ((ret = hal_device_haptic_get_backend()) < 0)
-                       return ret;
-       }
-
-       if (!hal_device_haptic_funcs || !hal_device_haptic_funcs->stop_device)
-               return -ENODEV;
-
-       return hal_device_haptic_funcs->stop_device(handle);
-}