input: add getter/setter for controlling input device event 42/285442/9 accepted/tizen/unified/20221220.180313
authorYunhee Seo <yuni.seo@samsung.com>
Tue, 13 Dec 2022 02:40:24 +0000 (11:40 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 16 Dec 2022 06:59:41 +0000 (06:59 +0000)
Add a getter and setter function of input device event status

These are function prototype to be added.
int device_input_set_event_state(int input_device_id, bool on);
int device_input_get_event_state(int input_device_id, bool *on);
With input_device_id parameter, it is possible to enable/disable event of input device.

This enum is a structure for managing input devices
by distinguishing input device types.
To get input_device_id number, these input types will be used.
typedef enum
{
DEVICE_INPUT_TYPE_UNKNOWN = 0, /**< Input device type which is not defined. */
DEVICE_INPUT_TYPE_ALL, /**< Input device type which is all kinds of input devices */
DEVICE_INPUT_TYPE_MOUSE, /**< Input device type which is mouse-type */
DEVICE_INPUT_TYPE_KEYBOARD, /**< Input device type which is keyboard-type */
DEVICE_INPUT_TYPE_CUSTOM_KNOB, /**< Input device type which is customed knob-type */
} device_input_type_e;

Change-Id: Idd6eec3bf0226bd8f0a156e0ac1c7be13f03aa15
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
include/input-internal.h [new file with mode: 0644]
src/input-internal.c [new file with mode: 0644]

diff --git a/include/input-internal.h b/include/input-internal.h
new file mode 100644 (file)
index 0000000..613925a
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2022 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 __TIZEN_SYSTEM_INPUT_INTERNAL_H__
+#define __TIZEN_SYSTEM_INPUT_INTERNAL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+
+#include "device-error.h"
+
+/**
+ * @brief Enumeration for the distinction of input device types.
+ * @since_tizen 7.0
+ */
+typedef enum
+{
+       DEVICE_INPUT_TYPE_UNKNOWN = 0, /**< Input device type which is not defined. */
+       DEVICE_INPUT_TYPE_ALL, /**< Input device type which is all kinds of input devices */
+       DEVICE_INPUT_TYPE_MOUSE, /**< Input device type which is mouse-type */
+       DEVICE_INPUT_TYPE_KEYBOARD, /**< Input device type which is keyboard-type */
+
+       DEVICE_INPUT_TYPE_CUSTOM_KNOB = 1000, /**< Input device type which is customed knob-type */
+} device_input_type_e;
+
+/**
+ * @brief Change input device event state by input device id.
+ * @since_tizen 7.0
+ * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the trying to control DEVICE_INPUT_TYPE_KEYBOARD device
+ *          and following feature is not supported: %http://tizen.org/feature/input.keyboard \n
+ * @param[in] input_device_id The input id of the input device under the sys/class/input node \n
+ *                            This is for the distinction and control of input devices. \n
+ * @param[in] on The value to be set for the input device event state \n
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #DEVICE_ERROR_NONE Successful
+ * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported in this device
+ * @retval #DEVICE_ERROR_OPERATION_FAILED Operation not permitted
+ */
+int device_input_set_event_state(int input_device_id, bool on);
+
+/**
+ * @brief Get input device event state by input device id.
+ * @since_tizen 7.0
+ * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the trying to control DEVICE_INPUT_TYPE_KEYBOARD device
+ *          and following feature is not supported: %http://tizen.org/feature/input.keyboard \n
+ * @param[in] input_device_id The input id of the input device under the sys/class/input node \n
+ *                            This is for the distinction and control of input devices. \n
+ * @param[out] on The value to be get from the input device event state \n
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #DEVICE_ERROR_NONE Successful
+ * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported in this device
+ * @retval #DEVICE_ERROR_OPERATION_FAILED Operation not permitted
+ */
+int device_input_get_event_state(int input_device_id, bool *on);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SYSTEM_INPUT_INTERNAL_H__ */
\ No newline at end of file
diff --git a/src/input-internal.c b/src/input-internal.c
new file mode 100644 (file)
index 0000000..67a6fa9
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2022 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 <string.h>
+#include <gio/gio.h>
+
+#include <libsyscommon/libgdbus.h>
+
+#include "input-internal.h"
+#include "common.h"
+
+#define METHOD_INPUT_SET_EVENT_STATE           "InputSetEventState"
+#define METHOD_INPUT_GET_EVENT_STATE           "InputGetEventState"
+
+int device_input_set_event_state(int input_device_id, bool on)
+{
+       int ret, reply;
+       ret = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME,
+                               DEVICED_PATH_INPUT, DEVICED_INTERFACE_INPUT,
+                               METHOD_INPUT_SET_EVENT_STATE, g_variant_new("(ii)",
+                               input_device_id, (int)on),
+                               &reply);
+       if (ret < 0)
+               return errno_to_device_error(ret);
+
+       if (reply < 0) {
+               _E("Failed to set input device event state");
+               return DEVICE_ERROR_OPERATION_FAILED;
+       }
+
+       return DEVICE_ERROR_NONE;
+}
+
+int device_input_get_event_state(int input_device_id, bool* on)
+{
+       int ret, reply;
+       ret = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME,
+                               DEVICED_PATH_INPUT, DEVICED_INTERFACE_INPUT,
+                               METHOD_INPUT_GET_EVENT_STATE, g_variant_new("(i)", input_device_id),
+                               &reply);
+       if (ret < 0)
+               return errno_to_device_error(ret);
+
+       if (reply < 0) {
+               _E("Failed to get input device event state");
+               return DEVICE_ERROR_OPERATION_FAILED;
+       }
+
+       *on = (bool)reply;
+
+       return DEVICE_ERROR_NONE;
+}
\ No newline at end of file