From: Yunhee Seo Date: Mon, 9 Jan 2023 10:16:52 +0000 (+0900) Subject: input: add input device information functions X-Git-Tag: accepted/tizen/unified/20230118.172018^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff4ec82bbb7529f85a6b0d5ff6ddea79b1616968;p=platform%2Fcore%2Fapi%2Fdevice.git input: add input device information functions Add input functions to get device information. Input event on/off option can be handled by device id number. Input device id numbers can be get by below functions. Also, input device name can be obtained by device id number. These are function prototype to be added. int device_input_get_devices(device_input_type_e input_type, int** input_ids, int* num_input_ids) -> With device_input_type_e, input device id list can be obtained by this function. input_ids will be filled with input device ids. num_input_ids will be set with number of input device ids. int device_input_put_devices(int** input_ids) -> If input id list(input_ids) is no longer in use, it can be free by this function. int device_input_get_default_device(device_input_type_e input_type, int *input_dev_id) -> With device_input_type_e, input default device id number can be get from config file. int device_input_get_device_name(int input_device_id, char **input_device_name) -> With input device id number, input device name can be get by this function. Change-Id: I0afd1340ecc6d7f0a8dd1c4083da169c77b88e3a Signed-off-by: Yunhee Seo --- diff --git a/include/input-internal.h b/include/input-internal.h index 613925a..25b5e0a 100644 --- a/include/input-internal.h +++ b/include/input-internal.h @@ -40,6 +40,40 @@ typedef enum } device_input_type_e; /** + * @brief Get input default device id by input device type + * @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_type The type to get input device information \n + * @param[out] input_device_id The id value to be get from the input devices by input_device_type \n + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported in this device + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation not permitted + */ +int device_input_get_default_device(device_input_type_e input_device_type, int *input_device_id); + +/** + * @brief Get input device id list by input device type. + * @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 + * after using input_device_ids, it should be freed by caller \n + * @param[in] input_device_type The type to get input devices information \n + * @param[out] input_deivce_ids The id list value to be get from the input devices \n + * @param[out] num_input_device_ids The number of ids to be get from the input devices \n + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported in this device + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation not permitted + */ +int device_input_get_devices(device_input_type_e input_device_type, int **input_deivce_ids, int *num_input_device_ids); + +/** * @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 @@ -71,6 +105,23 @@ int device_input_set_event_state(int input_device_id, bool on); */ int device_input_get_event_state(int input_device_id, bool *on); +/** + * @brief Get input device name 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 + * after using input_device_name, it should be freed by caller \n + * @param[in] input_device_type The type to get input device information \n + * @param[out] input_device_name The name value to be get from the input devices by input_device_type \n + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported in this device + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation not permitted + */ +int device_input_get_device_name(int input_device_id, char **input_device_name); + #ifdef __cplusplus } #endif diff --git a/src/input-internal.c b/src/input-internal.c index 67a6fa9..fb15c83 100644 --- a/src/input-internal.c +++ b/src/input-internal.c @@ -17,14 +17,118 @@ #include #include #include +#include #include #include "input-internal.h" #include "common.h" +#define METHOD_INPUT_GET_DEFAULT_DEVICE "InputGetDefaultDevice" +#define METHOD_INPUT_GET_DEVICES "InputGetDevices" #define METHOD_INPUT_SET_EVENT_STATE "InputSetEventState" #define METHOD_INPUT_GET_EVENT_STATE "InputGetEventState" +#define METHOD_INPUT_GET_DEVICE_NAME "InputGetDeviceName" + +static bool input_is_supported_input_type(device_input_type_e input_device_type) +{ + switch (input_device_type) { + case DEVICE_INPUT_TYPE_UNKNOWN: + case DEVICE_INPUT_TYPE_MOUSE: + case DEVICE_INPUT_TYPE_KEYBOARD: + case DEVICE_INPUT_TYPE_CUSTOM_KNOB: + break; + default: + return false; + } + return true; +} + +int device_input_get_default_device(device_input_type_e input_device_type, int *input_device_id) +{ + int ret, reply; + + if (!input_is_supported_input_type(input_device_type)) { + _E("Undefined input device type"); + return DEVICE_ERROR_INVALID_PARAMETER; + } + + if (!input_device_id) { + _E("Invalid parameters"); + return DEVICE_ERROR_INVALID_PARAMETER; + } + + ret = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, + DEVICED_PATH_INPUT, DEVICED_INTERFACE_INPUT, + METHOD_INPUT_GET_DEFAULT_DEVICE, + g_variant_new("(i)", (int)input_device_type), + &reply); + if (ret < 0) { + _E("Failed to call dbus method to get input default device, return value(%d)", ret); + return errno_to_device_error(ret); + } + + if (reply < 0) { + _E("Failed to get default input device id of input type(%d)", input_device_type); + return DEVICE_ERROR_OPERATION_FAILED; + } + + *input_device_id = (int)reply; + + return DEVICE_ERROR_NONE; +} + +int device_input_get_devices(device_input_type_e input_device_type, + int **input_device_ids, int *num_input_device_ids) +{ + int ret; + GVariant* reply; + GVariantIter *iter = NULL; + int index = 0; + int temp_input_device_id = 0; + int *temp_input_device_ids = NULL; + + if (!input_is_supported_input_type(input_device_type)) { + _E("Undefined input device type"); + return DEVICE_ERROR_INVALID_PARAMETER; + } + + if (!input_device_ids || !num_input_device_ids) { + _E("Invalid parameters"); + return DEVICE_ERROR_INVALID_PARAMETER; + } + + ret = gdbus_call_sync_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_INPUT, DEVICED_INTERFACE_INPUT, + METHOD_INPUT_GET_DEVICES, + g_variant_new("(i)", (int)input_device_type), + &reply); + if (ret < 0) { + _E("Failed to call dbus method to get input devices, return value(%d)", ret); + return errno_to_device_error(ret); + } + + g_variant_get(reply, "(ai)", &iter); + *num_input_device_ids = g_variant_iter_n_children(iter); + if (*num_input_device_ids == 0) { + _W("There are no devices of input type(%d)", input_device_type); + return DEVICE_ERROR_NONE; + } + + temp_input_device_ids = calloc(*num_input_device_ids, sizeof(int)); + if (!temp_input_device_ids) { + _E("Cannot alloc memory for input device id list"); + return DEVICE_ERROR_OPERATION_FAILED; + } + + while (g_variant_iter_loop(iter, "i", &temp_input_device_id)) + temp_input_device_ids[index++] = temp_input_device_id; + g_variant_iter_free(iter); + + *input_device_ids = temp_input_device_ids; + + return DEVICE_ERROR_NONE; +} int device_input_set_event_state(int input_device_id, bool on) { @@ -63,4 +167,37 @@ int device_input_get_event_state(int input_device_id, bool* on) *on = (bool)reply; return DEVICE_ERROR_NONE; +} + +int device_input_get_device_name(int input_device_id, char **input_device_name) +{ + int ret; + GVariant* reply; + char* temp_input_device_name; + int ret_val; + + if (!input_device_name) { + _E("Invalid parameters"); + return DEVICE_ERROR_INVALID_PARAMETER; + } + + ret = gdbus_call_sync_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_INPUT, DEVICED_INTERFACE_INPUT, + METHOD_INPUT_GET_DEVICE_NAME, + g_variant_new("(i)", (int)input_device_id), + &reply); + if (ret < 0) { + _E("Failed to call dbus method to get device name, return value(%d)", ret); + return errno_to_device_error(ret); + } + + g_variant_get(reply, "(is)", &ret_val, &temp_input_device_name); + if (ret_val < 0) { + _E("Failed to get name of input device id(%d)", input_device_id); + return DEVICE_ERROR_OPERATION_FAILED; + } + + *input_device_name = temp_input_device_name; + + return DEVICE_ERROR_NONE; } \ No newline at end of file