remove the duplication of creating a efl_util_inputgen_h 93/277993/1
authorSooChan Lim <sc1.lim@samsung.com>
Mon, 18 Jul 2022 01:07:59 +0000 (10:07 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 18 Jul 2022 01:07:59 +0000 (10:07 +0900)
Change-Id: I58bccc832dc9515aefc37dd5c8829c34ecf220b4

src/efl_util.c

index 39022cf..59f6a9b 100644 (file)
@@ -1477,10 +1477,9 @@ _efl_util_input_initialize_add_wait_device(const char *name, unsigned int dev_ty
      _efl_util_input_initialize_append_device(name, ECORE_DEVICE_CLASS_MOUSE);
 }
 
-API efl_util_inputgen_h
-efl_util_input_initialize_generator(unsigned int dev_type)
+static efl_util_inputgen_h
+_efl_util_input_create_inputgen(unsigned int dev_type, const char *name, int *ret, int with_name)
 {
-   int ret = EFL_UTIL_ERROR_NONE;
    efl_util_inputgen_h inputgen_h = NULL;
    unsigned int clas = 0x0;
 
@@ -1501,9 +1500,14 @@ efl_util_input_initialize_generator(unsigned int dev_type)
      }
 
    inputgen_h->init_type |= dev_type;
+   if (with_name)
+     {
+        if (name) strncpy(inputgen_h->name, name, 31);
+        else strncpy(inputgen_h->name, "Input Generator", 31);
+     }
 
-   ret = _wl_init();
-   if (ret == (int)EINA_FALSE)
+   *ret = _wl_init();
+   if (*ret == (int)EINA_FALSE)
      {
         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
         goto out;
@@ -1519,16 +1523,20 @@ efl_util_input_initialize_generator(unsigned int dev_type)
    while (!_eflutil.wl.devmgr.devicemgr)
      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
 
-   tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr, clas);
+   if (with_name)
+      tizen_input_device_manager_init_generator_with_name(_eflutil.wl.devmgr.devicemgr, clas, inputgen_h->name);
+   else
+      tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr, clas);
+
 
    while (_eflutil.wl.devmgr.request_notified == -1)
      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
 
-   ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
+   *ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
    _eflutil.wl.devmgr.request_notified = -1;
 
-   set_last_result(ret);
-   if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
+   set_last_result(*ret);
+   if (*ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
      goto out;
 
    return inputgen_h;
@@ -1543,69 +1551,29 @@ out:
 }
 
 API efl_util_inputgen_h
-efl_util_input_initialize_generator_with_name(unsigned int dev_type, const char *name)
+efl_util_input_initialize_generator(unsigned int dev_type)
 {
    int ret = EFL_UTIL_ERROR_NONE;
    efl_util_inputgen_h inputgen_h = NULL;
-   unsigned int clas = 0x0;
 
-   if (!dev_type ||
-        dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
-                    | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
-                    | EFL_UTIL_INPUT_DEVTYPE_POINTER))
-     {
-        set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
-        goto out;
-     }
-
-   inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
+   inputgen_h = _efl_util_input_create_inputgen(dev_type, NULL, &ret, 0);
    if (!inputgen_h)
-     {
-        set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
-        goto out;
-     }
-
-   inputgen_h->init_type |= dev_type;
-   strncpy(inputgen_h->name, name, 31);
-
-   ret = _wl_init();
-   if (ret == (int)EINA_FALSE)
-     {
-        set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
-        goto out;
-     }
-
-   if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
-     clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
-   if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
-     clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
-   if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
-     clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
+      return NULL;
 
-   while (!_eflutil.wl.devmgr.devicemgr)
-     wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
-
-   tizen_input_device_manager_init_generator_with_name(_eflutil.wl.devmgr.devicemgr, clas, inputgen_h->name);
-
-   while (_eflutil.wl.devmgr.request_notified == -1)
-     wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
+   return inputgen_h;
+}
 
-   ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
-   _eflutil.wl.devmgr.request_notified = -1;
+API efl_util_inputgen_h
+efl_util_input_initialize_generator_with_name(unsigned int dev_type, const char *name)
+{
+   int ret = EFL_UTIL_ERROR_NONE;
+   efl_util_inputgen_h inputgen_h = NULL;
 
-   set_last_result(ret);
-   if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
-     goto out;
+   inputgen_h = _efl_util_input_create_inputgen(dev_type, name, &ret, 1);
+   if (!inputgen_h)
+      return NULL;
 
    return inputgen_h;
-
-out:
-   if (inputgen_h)
-     {
-        free(inputgen_h);
-        inputgen_h = NULL;
-     }
-   return NULL;
 }
 
 API efl_util_inputgen_h
@@ -1613,63 +1581,18 @@ efl_util_input_initialize_generator_with_sync(unsigned int dev_type, const char
 {
    int ret = EFL_UTIL_ERROR_NONE;
    efl_util_inputgen_h inputgen_h = NULL;
-   unsigned int clas = 0x0;
-
-   if (!dev_type ||
-        dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
-                    | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
-                    | EFL_UTIL_INPUT_DEVTYPE_POINTER))
-     {
-        set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
-        goto out;
-     }
 
-   inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
+   inputgen_h = efl_util_input_initialize_generator_with_name(dev_type, name);
    if (!inputgen_h)
-     {
-        set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
-        goto out;
-     }
-
-   inputgen_h->init_type |= dev_type;
-   if (name) strncpy(inputgen_h->name, name, 31);
-   else strncpy(inputgen_h->name, "Input Generator", 31);
-
-   ret = _wl_init();
-   if (ret == (int)EINA_FALSE)
-     {
-        set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
-        goto out;
-     }
-
-   if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
-     clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
-   if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
-     clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
-   if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
-     clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
-
-   while (!_eflutil.wl.devmgr.devicemgr)
-     wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
-
-   tizen_input_device_manager_init_generator_with_name(_eflutil.wl.devmgr.devicemgr, clas, inputgen_h->name);
-
-   while (_eflutil.wl.devmgr.request_notified == -1)
-     wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
-
-   ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
-   _eflutil.wl.devmgr.request_notified = -1;
+      return NULL;
 
-   if (ret == EFL_UTIL_ERROR_NONE)
-     {
-        _efl_util_input_initialize_add_wait_device(inputgen_h->name, dev_type);
-        _efl_util_input_initialize_wait_device();
-        if (_eflutil.wl.devmgr.request_notified != -1)
-          {
-             ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
-             _eflutil.wl.devmgr.request_notified = -1;
-          }
-     }
+   _efl_util_input_initialize_add_wait_device(inputgen_h->name, dev_type);
+   _efl_util_input_initialize_wait_device();
+   if (_eflutil.wl.devmgr.request_notified != -1)
+      {
+         ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
+         _eflutil.wl.devmgr.request_notified = -1;
+      }
 
    set_last_result(ret);
    if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
@@ -1683,6 +1606,7 @@ out:
         free(inputgen_h);
         inputgen_h = NULL;
      }
+
    return NULL;
 }