device-bezel: Add hal-api IPC module using TIDL generated code 62/321562/6
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 25 Mar 2025 03:48:32 +0000 (12:48 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 7 Apr 2025 04:03:50 +0000 (13:03 +0900)
To support IPC mode, the ipc code has been added using tidl-generated
proxy code.
 - Connect or disconnect to hal-backend-service
 - Handle losing connsection to hal-backend-service
 - Send request to hal-backend-service

Change-Id: I4340f9b644b768cbb48b93bc48087956ff75fba9
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/hal-api-device-bezel-ipc.c [new file with mode: 0644]
src/hal-api-device-bezel-ipc.h [new file with mode: 0644]

diff --git a/src/hal-api-device-bezel-ipc.c b/src/hal-api-device-bezel-ipc.c
new file mode 100644 (file)
index 0000000..b96889d
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2025 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 <stdbool.h>
+#include <assert.h>
+#include <glib.h>
+
+#include <hal/hal-common.h>
+
+#include "hal-api-device-bezel-ipc.h"
+#include "src/generated/hal_device_bezel_proxy_1.h"
+
+#include "common.h"
+
+static bool g_hal_backend_service_connected = false;
+static rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_h g_hal_device_bezel_ipc_h = NULL;
+
+static void hal_device_bezel_ipc_connected_cb(rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_h h,
+                                                                               void *user_data)
+{
+       g_hal_backend_service_connected = true;
+
+       _I("device-bezel: Connected to hal-backend-service");
+}
+
+static void hal_device_bezel_ipc_disconnected_cb(rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_h h,
+                                                                               void *user_data)
+{
+       int ret = 0;
+
+       g_hal_backend_service_connected = false;
+       ret = hal_device_bezel_ipc_put_backend();
+       if (ret < 0)
+               _W("device-bezel: Cannot put ipc backend");
+}
+
+static void hal_device_bezel_ipc_rejected_cb(rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_h h,
+                                                                               void *user_data)
+{
+       int ret = 0;
+
+       g_hal_backend_service_connected = false;
+       ret = hal_device_bezel_ipc_put_backend();
+       if (ret < 0)
+               _W("device-bezel: Cannot put ipc backend");
+}
+
+int hal_device_bezel_ipc_get_backend(void)
+{
+       int ret = 0;
+       const char *stub_proc_name = NULL;
+
+       if (g_hal_device_bezel_ipc_h)
+               return 0;
+
+       ret = hal_common_get_stub_proc_name(HAL_MODULE_DEVICE_BEZEL, &stub_proc_name);
+       if (ret != 0) {
+               _E("Failed to get stub proc name for device-bezel: ret(%d)", ret);
+               return ret;
+       }
+
+       rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_callback_s callback = {
+               .connected = hal_device_bezel_ipc_connected_cb,
+               .disconnected = hal_device_bezel_ipc_disconnected_cb,
+               .rejected = hal_device_bezel_ipc_rejected_cb
+       };
+
+       ret = rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_create(stub_proc_name,
+                                                               &callback, NULL, &g_hal_device_bezel_ipc_h);
+       if (ret != RPC_PORT_ERROR_NONE) {
+               _E("Failed to create bezel ipc handle(%d)", ret);
+               goto ipc_init_fail;
+       }
+
+       ret = rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_connect_sync(g_hal_device_bezel_ipc_h);
+       if (ret != RPC_PORT_ERROR_NONE) {
+               _E("Failed to connect bezel ipc handle(%d)", ret);
+               goto ipc_init_fail;
+       }
+
+       return 0;
+
+ipc_init_fail:
+       g_hal_backend_service_connected = false;
+       if (g_hal_device_bezel_ipc_h)
+               rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_destroy(g_hal_device_bezel_ipc_h);
+       g_hal_device_bezel_ipc_h = NULL;
+       return ret;
+}
+
+int hal_device_bezel_ipc_put_backend(void)
+{
+       int ret = 0;
+
+       if (!g_hal_device_bezel_ipc_h)
+               return 0;
+
+       ret = rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_disconnect(g_hal_device_bezel_ipc_h);
+       if (ret != RPC_PORT_ERROR_NONE)
+               _W("Cannot disconnect bezel ipc proxy handle(%d)", ret);
+
+       ret = rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_destroy(g_hal_device_bezel_ipc_h);
+       if (ret != RPC_PORT_ERROR_NONE)
+               _W("Cannot destroy bezel ipc proxy handle(%d)", ret);
+
+       g_hal_device_bezel_ipc_h = NULL;
+       return ret;
+}
+
+int hal_device_bezel_ipc_get_state(hal_device_bezel_state_e *state)
+{
+       if (!state)
+               return -EINVAL;
+
+       if (!g_hal_backend_service_connected) {
+               if (hal_device_bezel_ipc_get_backend() != RPC_PORT_ERROR_NONE) {
+                       return -ENOTSUP;
+               }
+       }
+
+       return rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_invoke_get_state(
+                       g_hal_device_bezel_ipc_h,
+                       (rpc_port_proxy_hal_device_bezel_proxy_1_enums_state_e *) state);
+
+}
+
+int hal_device_bezel_ipc_set_state(hal_device_bezel_state_e state)
+{
+       if (!g_hal_backend_service_connected) {
+               if (hal_device_bezel_ipc_get_backend() != RPC_PORT_ERROR_NONE) {
+                       return -ENOTSUP;
+               }
+       }
+
+       return rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_invoke_set_state(
+                       g_hal_device_bezel_ipc_h,
+                       (rpc_port_proxy_hal_device_bezel_proxy_1_enums_state_e) state);
+}
+
+int hal_device_bezel_ipc_get_sw_state(hal_device_bezel_state_e *state)
+{
+       if (!state)
+               return -EINVAL;
+
+       if (!g_hal_backend_service_connected) {
+               if (hal_device_bezel_ipc_get_backend() != RPC_PORT_ERROR_NONE) {
+                       return -ENOTSUP;
+               }
+       }
+
+       return rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_invoke_get_sw_state(
+                       g_hal_device_bezel_ipc_h,
+                       (rpc_port_proxy_hal_device_bezel_proxy_1_enums_state_e *) state);
+}
+
+int hal_device_bezel_ipc_set_sw_state(hal_device_bezel_state_e state)
+{
+       if (!g_hal_backend_service_connected) {
+               if (hal_device_bezel_ipc_get_backend() != RPC_PORT_ERROR_NONE) {
+                       return -ENOTSUP;
+               }
+       }
+
+       return rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_invoke_set_sw_state(
+                       g_hal_device_bezel_ipc_h,
+                       (rpc_port_proxy_hal_device_bezel_proxy_1_enums_state_e) state);
+}
+
+int hal_device_bezel_ipc_get_vib_state(hal_device_bezel_vib_state_e *state)
+{
+       if (!state)
+               return -EINVAL;
+
+       if (!g_hal_backend_service_connected) {
+               if (hal_device_bezel_ipc_get_backend() != RPC_PORT_ERROR_NONE) {
+                       return -ENOTSUP;
+               }
+       }
+
+       return rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_invoke_get_vib_state(
+                       g_hal_device_bezel_ipc_h,
+                       (rpc_port_proxy_hal_device_bezel_proxy_1_enums_vib_state_e *) state);
+}
+
+int hal_device_bezel_ipc_set_vib_state(hal_device_bezel_vib_state_e state)
+{
+       if (!g_hal_backend_service_connected) {
+               if (hal_device_bezel_ipc_get_backend() != RPC_PORT_ERROR_NONE) {
+                       return -ENOTSUP;
+               }
+       }
+
+       return rpc_port_proxy_hal_device_bezel_proxy_1_device_bezel_invoke_set_vib_state(
+                       g_hal_device_bezel_ipc_h,
+                       (rpc_port_proxy_hal_device_bezel_proxy_1_enums_vib_state_e) state);
+}
diff --git a/src/hal-api-device-bezel-ipc.h b/src/hal-api-device-bezel-ipc.h
new file mode 100644 (file)
index 0000000..63a2ec3
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2025 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_API_DEVICE_BEZEL_IPC_H__
+#define __HAL_API_DEVICE_BEZEL_IPC_H__
+
+#include "hal-device-bezel-interface.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int hal_device_bezel_ipc_get_backend(void);
+int hal_device_bezel_ipc_put_backend(void);
+int hal_device_bezel_ipc_get_state(hal_device_bezel_state_e *state);
+int hal_device_bezel_ipc_set_state(hal_device_bezel_state_e state);
+int hal_device_bezel_ipc_get_sw_state(hal_device_bezel_state_e *state);
+int hal_device_bezel_ipc_set_sw_state(hal_device_bezel_state_e state);
+int hal_device_bezel_ipc_get_vib_state(hal_device_bezel_vib_state_e *state);
+int hal_device_bezel_ipc_set_vib_state(hal_device_bezel_vib_state_e state);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_API_DEVICE_BEZEL_IPC_H__ */