summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunhee Seo <yuni.seo@samsung.com>2022-12-13 15:50:51 +0900
committeryunhee seo <yuni.seo@samsung.com>2022-12-14 10:40:42 +0000
commit2b1bd811c34ffc5bdef9baeabc48b778e55dfcfe (patch)
treee43b96937ab345430fecfe00a2e9c613d310a020
parent857108e36e5f72271c55ed102cd65d53a7be73c3 (diff)
downloaddevice-common-2b1bd811c34ffc5bdef9baeabc48b778e55dfcfe.tar.gz
device-common-2b1bd811c34ffc5bdef9baeabc48b778e55dfcfe.tar.bz2
device-common-2b1bd811c34ffc5bdef9baeabc48b778e55dfcfe.zip
input: add getter/setter for controlling input device event
Add a getter and setter function of input device event status Input device event can be enabled/disabled by kernel inhibited node which exist under the /sys/class/input/input(id) path. These are function prototype to be added. int hal_backend_device_common_input_set_event_state(int input_device_id, int on); -> As follow above path, "(id)" will be replaced to input_device_id. and this function will set the on parameter value to inhibited node(path) int hal_backend_device_common_input_get_event_state(int input_device_id, int* on); -> As follow above path, this function will read the inhibited node value through the input_device_id. Change-Id: I742edbbaec64cb7aeb2428aca7c50b0e7872accc Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
-rw-r--r--CMakeLists.txt3
-rw-r--r--include/hal-backend-device-common-file.h92
-rw-r--r--include/hal-backend-device-common-input.h30
-rw-r--r--packaging/hal-backend-device-common.spec1
-rw-r--r--src/hal-backend-device-common-file.c133
-rw-r--r--src/input/input.c72
6 files changed, 331 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 305621a..ac66f46 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,6 +5,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
SET(SRCS
src/udev/udev.c
+ src/input/input.c
+ src/hal-backend-device-common-file.c
)
INCLUDE(FindPkgConfig)
@@ -31,6 +33,7 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibr
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.Apache-2.0 DESTINATION ${HAL_LICENSE_DIR}/${PROJECT_NAME})
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/hal-backend-common.h DESTINATION ${HAL_INCLUDE_DIR}/device)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/hal-backend-common-udev.h DESTINATION ${HAL_INCLUDE_DIR}/device)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/hal-backend-device-common-input.h DESTINATION ${HAL_INCLUDE_DIR}/device)
CONFIGURE_FILE(hal-backend-device-common.pc.in hal-backend-device-common.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hal-backend-device-common.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
diff --git a/include/hal-backend-device-common-file.h b/include/hal-backend-device-common-file.h
new file mode 100644
index 0000000..14a9be8
--- /dev/null
+++ b/include/hal-backend-device-common-file.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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_BACKEND_DEVICE_COMMON_FILE_H__
+#define __HAL_BACKEND_DEVICE_COMMON_FILE_H__
+
+#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Open file, read and close
+ *
+ * @param[in] file File name
+ * @param[in] len Length of buffer
+ * @param[out] buf Buffer that stores read data
+ *
+ * @return read length if read was successful else negative error value
+ */
+int hal_backend_device_common_read_buf(char *file, char *buf, int len);
+
+/**
+ * @brief Open file, write and close
+ *
+ * @param[in] file File name
+ * @param[out] buf Buffer that stores data to write
+ *
+ * @return zero on success otherwise negative error value
+ */
+int hal_backend_device_common_write_buf(char *file, char *buf);
+
+/**
+ * @brief Read integer from file
+ *
+ * @param[in] fname File name
+ * @param[out] val integer value that read from file
+ *
+ * @return read length if reading integer was successful else negative error value
+ */
+int hal_backend_device_common_get_int(char *fname, int *val);
+
+/**
+ * @brief Read string from file
+ *
+ * @param[in] fname File name
+ * @param[in] len String length
+ * @param[out] str Buffer
+ *
+ * @return zero on success otherwise negative error value
+ */
+int hal_backend_device_common_get_str(char *fname, char *str, int len);
+
+/**
+ * @brief Write integer to file
+ *
+ * @param[in] fname File name
+ * @param[in] val Integer value to write
+ *
+ * @return zero on success otherwise negative error value
+ */
+int hal_backend_device_common_set_int(char *fname, int val);
+
+/**
+ * @brief Write string to file
+ *
+ * @param[in] fname File name
+ * @param[out] val String to write
+ *
+ * @return zero on success otherwise negative error value
+ */
+int hal_backend_device_common_set_str(char *fname, char *val);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __HAL_BACKEND_DEVICE_COMMON_FILE_H__ */ \ No newline at end of file
diff --git a/include/hal-backend-device-common-input.h b/include/hal-backend-device-common-input.h
new file mode 100644
index 0000000..8ffa246
--- /dev/null
+++ b/include/hal-backend-device-common-input.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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_BACKEND_DEVICE_COMMON_INPUT_H__
+#define __HAL_BACKEND_DEVICE_COMMON_INPUT_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int hal_backend_device_common_input_set_event_state(int input_device_id, int on);
+int hal_backend_device_common_input_get_event_state(int input_device_id, int* on);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_BACKEND_DEVICE_COMMON_INPUT_H__ */ \ No newline at end of file
diff --git a/packaging/hal-backend-device-common.spec b/packaging/hal-backend-device-common.spec
index 68fa440..84c1a4f 100644
--- a/packaging/hal-backend-device-common.spec
+++ b/packaging/hal-backend-device-common.spec
@@ -47,4 +47,5 @@ make %{?jobs:-j%jobs}
%manifest %{name}.manifest
%{_hal_licensedir}/%{name}/LICENSE.Apache-2.0
%{_hal_includedir}/device/hal-backend-common*.h
+%{_hal_includedir}/device/hal-backend-device-common*.h
%{_libdir}/pkgconfig/*.pc
diff --git a/src/hal-backend-device-common-file.c b/src/hal-backend-device-common-file.c
new file mode 100644
index 0000000..537c814
--- /dev/null
+++ b/src/hal-backend-device-common-file.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "hal-backend-common.h"
+#include "hal-backend-device-common-file.h"
+
+#define SHARED_H_BUF_MAX 255
+
+int hal_backend_device_common_read_buf(char *file, char *buf, int len)
+{
+ int fd, r;
+ if (!file || !buf || len < 0)
+ return -EINVAL;
+
+ fd = open(file, O_RDONLY);
+ if (fd == -1)
+ return -errno;
+
+ r = read(fd, buf, len);
+ if ((r >= 0) && (r < len))
+ buf[r] = '\0';
+ else {
+ buf[0] = '\0';
+ r = -EIO;
+ }
+
+ close(fd);
+
+ return r;
+}
+
+int hal_backend_device_common_write_buf(char *file, char *buf)
+{
+ int fd, r;
+
+ if (!file || !buf)
+ return -EINVAL;
+
+ fd = open(file, O_WRONLY);
+ if (fd == -1)
+ return -errno;
+
+ r = write(fd, buf, strlen(buf));
+ if (r < 0)
+ r = -EIO;
+
+ close(fd);
+
+ return 0;
+}
+
+int hal_backend_device_common_get_int(char *fname, int *val)
+{
+ char buf[SHARED_H_BUF_MAX];
+ int r;
+
+ if (!fname || !val)
+ return -EINVAL;
+
+ r = hal_backend_device_common_read_buf(fname, buf, sizeof(buf));
+ if (r > 0) {
+ *val = atoi(buf);
+ } else {
+ *val = -1;
+ r = -EIO;
+ }
+
+ return r;
+}
+
+int hal_backend_device_common_get_str(char *fname, char *str, int len)
+{
+ int r;
+
+ if (!fname || !str || len < 0)
+ return -EINVAL;
+
+ r = hal_backend_device_common_read_buf(fname, str, len);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
+int hal_backend_device_common_set_int(char *fname, int val)
+{
+ char buf[SHARED_H_BUF_MAX];
+ int r;
+
+ if (!fname)
+ return -EINVAL;
+
+ snprintf(buf, sizeof(buf), "%d", val);
+ r = hal_backend_device_common_write_buf(fname, buf);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
+int hal_backend_device_common_set_str(char *fname, char *val)
+{
+ int r;
+
+ if (!fname || !val)
+ return -EINVAL;
+
+ r = hal_backend_device_common_write_buf(fname, val);
+ if (r < 0)
+ return r;
+
+ return 0;
+} \ No newline at end of file
diff --git a/src/input/input.c b/src/input/input.c
new file mode 100644
index 0000000..6dc4112
--- /dev/null
+++ b/src/input/input.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 <stdbool.h>
+#include <errno.h>
+#include <glib.h>
+#include <string.h>
+
+#include "hal-backend-common.h"
+#include "hal-backend-device-common-file.h"
+#include "hal-backend-device-common-input.h"
+
+#define INPUT_DEVICE_EVENT_NODE "/sys/class/input/input"
+#define INHIBITED "/inhibited"
+#define MAX_NODE_LENGTH 40
+#define MAX_ID_LENGTH 7
+
+EXPORT int hal_backend_device_common_input_set_event_state(int input_device_id, int on)
+{
+ int ret = 0, input_dev_id_len;
+ char input_dev_id[MAX_ID_LENGTH];
+ char input_dev_event_node[MAX_NODE_LENGTH];
+
+ input_dev_id_len = snprintf(NULL, 0, "%d", input_device_id);
+ snprintf(input_dev_id, input_dev_id_len+1, "%d", input_device_id);
+ snprintf(input_dev_event_node, MAX_NODE_LENGTH, "%s%s%s",
+ INPUT_DEVICE_EVENT_NODE, input_dev_id, INHIBITED);
+
+ ret = hal_backend_device_common_set_int(input_dev_event_node, on);
+ if(ret < 0) {
+ _E("Failed to hal_device_common_set_int (%d)", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+EXPORT int hal_backend_device_common_input_get_event_state(int input_device_id, int* on)
+{
+ int ret = 0, val, input_dev_id_len;
+ char input_dev_id[MAX_ID_LENGTH];
+ char input_dev_event_node[MAX_NODE_LENGTH];
+
+ input_dev_id_len = snprintf(NULL, 0, "%d", input_device_id);
+ snprintf(input_dev_id, input_dev_id_len+1, "%d", input_device_id);
+ snprintf(input_dev_event_node, MAX_NODE_LENGTH, "%s%s%s",
+ INPUT_DEVICE_EVENT_NODE, input_dev_id, INHIBITED);
+
+ ret = hal_backend_device_common_get_int(input_dev_event_node, &val);
+ if(ret < 0) {
+ _E("Failed to hal_device_common_get_int (%d)", ret);
+ return ret;
+ }
+
+ *on = val;
+
+ return 0;
+} \ No newline at end of file