} 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
*/
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
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
+#include <glib.h>
#include <libsyscommon/libgdbus.h>
#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)
{
*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