device-external_connection: Add hal-api passthrough mode 65/321865/3
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 31 Mar 2025 01:04:00 +0000 (10:04 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 7 Apr 2025 04:04:12 +0000 (13:04 +0900)
It is necessary to switch passthrough/ipc by transport. Therefore,
added code for passthrough only.

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

diff --git a/src/hal-api-device-external_connection-passthrough.c b/src/hal-api-device-external_connection-passthrough.c
new file mode 100644 (file)
index 0000000..4123e0d
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * 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 <stdio.h>
+
+#include <hal/hal-common.h>
+
+#include "hal-device-external_connection-interface.h"
+#include "common.h"
+
+static hal_backend_device_external_connection_funcs *hal_device_external_connection_funcs = NULL;
+
+int hal_device_external_connection_passthrough_get_backend(void)
+{
+       int ret;
+
+       if (hal_device_external_connection_funcs)
+               return 0;
+
+       hal_device_external_connection_funcs = calloc(1, sizeof(hal_backend_device_external_connection_funcs));
+       if (!hal_device_external_connection_funcs)
+               return -ENOMEM;
+
+       ret = hal_common_get_backend(HAL_MODULE_DEVICE_EXTERNAL_CONNECTION, (void **)&hal_device_external_connection_funcs);
+       if (ret < 0) {
+               _E("Failed to get device-external-connection backend");
+               free(hal_device_external_connection_funcs);
+               hal_device_external_connection_funcs = NULL;
+               return -ENOTSUP;
+       }
+
+       return 0;
+}
+
+int hal_device_external_connection_passthrough_put_backend(void)
+{
+       int ret = 0;
+
+       if (!hal_device_external_connection_funcs)
+               return 0;
+
+       ret = hal_common_put_backend(HAL_MODULE_DEVICE_EXTERNAL_CONNECTION, (void *)hal_device_external_connection_funcs);
+       if (ret < 0) {
+               _E("Failed to put device-exeternal-connection backend");
+               return ret;
+       }
+
+       free(hal_device_external_connection_funcs);
+       hal_device_external_connection_funcs = NULL;
+
+       return 0;
+}
+
+
+int hal_device_external_connection_passthrough_register_changed_event(hal_device_external_connection_updated_cb updated_cb, void *user_data)
+{
+       int ret;
+
+       if (!updated_cb)
+               return -EINVAL;
+
+       if (!hal_device_external_connection_funcs) {
+               if ((ret = hal_device_external_connection_passthrough_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_external_connection_funcs ||
+               !hal_device_external_connection_funcs->register_changed_event)
+               return -ENOTSUP;
+
+       return hal_device_external_connection_funcs->register_changed_event(updated_cb, user_data);
+}
+
+int hal_device_external_connection_passthrough_unregister_changed_event(hal_device_external_connection_updated_cb updated_cb)
+{
+       int ret;
+
+       if (!updated_cb)
+               return -EINVAL;
+
+       if (!hal_device_external_connection_funcs) {
+               if ((ret = hal_device_external_connection_passthrough_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_external_connection_funcs ||
+               !hal_device_external_connection_funcs->unregister_changed_event)
+               return -ENOTSUP;
+
+       hal_device_external_connection_funcs->unregister_changed_event(updated_cb);
+       return 0;
+}
+
+int hal_device_external_connection_passthrough_get_current_state(hal_device_external_connection_updated_cb updated_cb, void *user_data)
+{
+       int ret;
+
+       if (!updated_cb)
+               return -EINVAL;
+
+       if (!hal_device_external_connection_funcs) {
+               if ((ret = hal_device_external_connection_passthrough_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_external_connection_funcs ||
+               !hal_device_external_connection_funcs->get_current_state)
+               return -ENOTSUP;
+
+       return hal_device_external_connection_funcs->get_current_state(updated_cb, user_data);
+}
diff --git a/src/hal-api-device-external_connection-passthrough.h b/src/hal-api-device-external_connection-passthrough.h
new file mode 100644 (file)
index 0000000..5368732
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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_EXTERNAL_CONNECTION_PASSTHROUGH_H__
+#define __HAL_DEVICE_EXTERNAL_CONNECTION_PASSTHROUGH_H__
+
+#include "hal-device-external_connection-interface.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int hal_device_external_connection_passthrough_get_backend(void);
+int hal_device_external_connection_passthrough_put_backend(void);
+int hal_device_external_connection_passthrough_register_changed_event(hal_device_external_connection_updated_cb updated_cb, void *data);
+int hal_device_external_connection_passthrough_unregister_changed_event(hal_device_external_connection_updated_cb updated_cb);
+int hal_device_external_connection_passthrough_get_current_state(hal_device_external_connection_updated_cb updated_cb, void *data);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif  /* __HAL_DEVICE_EXTERNAL_CONNECTION_PASSTHROUGH_H__ */