add initialize values for the display_policy interface
[platform/core/api/efl-util.git] / src / efl_util.c
index 897d291..0e0ca0c 100644 (file)
 #undef LOG_TAG
 #endif
 
+/* Determine Tizen profile at runtime */
+#include <system_info.h>
+typedef enum {
+   TIZEN_PROFILE_UNKNOWN = 0,
+   TIZEN_PROFILE_MOBILE = 0x1,
+   TIZEN_PROFILE_WEARABLE = 0x2,
+   TIZEN_PROFILE_TV = 0x4,
+   TIZEN_PROFILE_IVI = 0x8,
+   TIZEN_PROFILE_COMMON = 0x10,
+} tizen_profile_t;
+static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
+static tizen_profile_t _get_tizen_profile()
+{
+   char *profileName;
+   system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
+   switch (*profileName) {
+   case 'm':
+   case 'M':
+     profile = TIZEN_PROFILE_MOBILE;
+     break;
+   case 'w':
+   case 'W':
+     profile = TIZEN_PROFILE_WEARABLE;
+     break;
+   case 't':
+   case 'T':
+     profile = TIZEN_PROFILE_TV;
+     break;
+   case 'i':
+   case 'I':
+     profile = TIZEN_PROFILE_IVI;
+     break;
+   default: // common or unknown ==> ALL ARE COMMON.
+     profile = TIZEN_PROFILE_COMMON;
+   }
+   free(profileName);
+
+   return profile;
+}
+static inline tizen_profile_t get_tizen_profile()
+{
+   if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+     return profile;
+   return _get_tizen_profile();
+}
+
+
 #define LOG_TAG "TIZEN_N_EFL_UTIL"
 
 
@@ -142,7 +189,8 @@ static Efl_Util_Data _eflutil =
       NULL, NULL,
       { NULL, NULL, NULL }, /* tizen_policy protocol */
       { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
-      { NULL, -1 } /* tizen_input_device_manager protocol */
+      { NULL, -1 }, /* tizen_input_device_manager protocol */
+      { NULL, NULL } /* display_policy protocol */
    },
    {
       { NULL, 0 }, /* handler for notification level */
@@ -308,6 +356,7 @@ _wl_init(void)
 
    reg = wl_display_get_registry(display_wrapper);
    wl_proxy_wrapper_destroy(display_wrapper);
+   display_wrapper = NULL;
    EINA_SAFETY_ON_NULL_GOTO(reg, fail);
 
    wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
@@ -1044,12 +1093,15 @@ efl_util_get_window_screen_mode(Evas_Object *window,
      return EFL_UTIL_ERROR_INVALID_PARAMETER;
 }
 
-#ifndef TIZEN_WEARABLE
 API int
 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
                                          efl_util_window_screen_mode_error_cb callback,
                                          void *user_data)
 {
+   /* Wearable device cannot use this. */
+   if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
+     return EFL_UTIL_ERROR_NO_SUCH_DEVICE;
+
    dlog_print(DLOG_WARN, LOG_TAG,
      "DEPRECATION WARNING: efl_util_set_window_screen_mode_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_window_screen_mode() instead.");
 
@@ -1070,6 +1122,10 @@ efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
 API int
 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
 {
+   /* Wearable device cannot use this. */
+   if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
+     return EFL_UTIL_ERROR_NO_SUCH_DEVICE;
+
    dlog_print(DLOG_WARN, LOG_TAG,
      "DEPRECATION WARNING: efl_util_unset_window_screen_mode_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_window_screen_mode() instead.");
 
@@ -1082,7 +1138,6 @@ efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
 
    return EFL_UTIL_ERROR_NONE;
 }
-#endif
 
 API int
 efl_util_set_window_brightness(Evas_Object *window, int brightness)
@@ -1207,6 +1262,7 @@ efl_util_get_window_brightness(Evas_Object *window, int *brightness)
 struct _efl_util_inputgen_h
 {
    unsigned int init_type;
+   char name[32];
 };
 
 static void
@@ -1333,6 +1389,73 @@ out:
    return NULL;
 }
 
+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;
+   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));
+   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;
+
+   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;
+
+   set_last_result(ret);
+   if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
+     goto out;
+
+   return inputgen_h;
+
+out:
+   if (inputgen_h)
+     {
+        free(inputgen_h);
+        inputgen_h = NULL;
+     }
+   return NULL;
+}
+
+
 API int
 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
 {
@@ -1558,15 +1681,16 @@ efl_util_screenshot_initialize(int width, int height)
         wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
 
         display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
-        EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_init);
+        EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_memory);
 
         _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy);
-        EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_init);
+        EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_memory);
 
         wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.shot.queue);
 
         reg = wl_display_get_registry(display_wrapper);
         wl_proxy_wrapper_destroy(display_wrapper);
+        display_wrapper = NULL;
         EINA_SAFETY_ON_NULL_GOTO(reg, fail_init);
 
         wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL);
@@ -1627,15 +1751,13 @@ fail_memory:
      wl_proxy_wrapper_destroy(display_wrapper);
    set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
    return NULL;
-/* LCOV_EXCL_STOP */
 fail_init:
    if (screenshot)
      efl_util_screenshot_deinitialize(screenshot);
    _screenshot_mutex_unlock();
-   if (display_wrapper)
-     wl_proxy_wrapper_destroy(display_wrapper);
    set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
    return NULL;
+/* LCOV_EXCL_STOP */
 }
 
 API int