--- /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 <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);
+}
+++ /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 <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);
-}