ecore-drm: Port ecore_drm_output backlight init code to use Eeze
authorChris Michael <cp.michael@samsung.com>
Tue, 23 Sep 2014 19:45:53 +0000 (15:45 -0400)
committerChris Michael <cp.michael@samsung.com>
Tue, 23 Sep 2014 19:47:04 +0000 (15:47 -0400)
Summary: This ports the current backlight_init code to use Eeze
library instead of udev functions directly.

@fix

Signed-off-by: Chris Michael <cp.michael@samsung.com>
src/lib/ecore_drm/ecore_drm_output.c

index 105440e..8f85f8b 100644 (file)
@@ -291,69 +291,63 @@ _ecore_drm_output_mode_add(Ecore_Drm_Output *output, drmModeModeInfo *info)
 }
 
 static Ecore_Drm_Backlight *
-_ecore_drm_backlight_init(Ecore_Drm_Device *dev, uint32_t conn_type)
+_ecore_drm_backlight_init(Ecore_Drm_Device *dev EINA_UNUSED, uint32_t conn_type)
 {
    Ecore_Drm_Backlight *backlight = NULL;
    Ecore_Drm_Backlight_Type type = 0;
-   struct udev_enumerate *enumerate;
-   struct udev_device *device;
-   struct udev_list_entry *item, *first;
-   const char *dev_type, *backlight_path;
-   int ret;
-
-   enumerate = udev_enumerate_new(udev);
-   if (!enumerate) return NULL;
-
-   udev_enumerate_add_match_subsystem(enumerate, "backlight");
-   ret = udev_enumerate_scan_devices(enumerate);
-   if (ret < 0)
-     {
-        udev_enumerate_add_match_subsystem(enumerate, "leds");
-        ret = udev_enumerate_scan_devices(enumerate);
-        if (ret < 0)
-          {
-             udev_enumerate_unref(enumerate);
-             return NULL;
-          }
-     }
+   Eina_List *devs, *l;
+   Eina_Bool found = EINA_FALSE;
+   const char *device, *devtype, *tmpdevice;
+
+   if (!(devs = eeze_udev_find_by_type(EEZE_UDEV_TYPE_BACKLIGHT, NULL)))
+     devs = eeze_udev_find_by_type(EEZE_UDEV_TYPE_LEDS, NULL);
 
-   first = udev_enumerate_get_list_entry(enumerate);
-   udev_list_entry_foreach(item, first)
+   if (!devs) return NULL;
+
+   EINA_LIST_FOREACH(devs, l, device)
      {
-        backlight_path = udev_list_entry_get_name(item);
-        device = udev_device_new_from_syspath(udev, backlight_path);
+        if (!(devtype = eeze_udev_syspath_get_sysattr(device, "type")))
+          continue;
 
-        dev_type = udev_device_get_sysattr_value(device, "type");
-        if (!dev_type)
-          {
-             udev_device_unref(device);
-             udev_enumerate_unref(enumerate);
-             return NULL;
-          }
-        if (!strcmp(dev_type, "raw"))
+        if (!strcmp(devtype, "raw"))
           type = ECORE_DRM_BACKLIGHT_RAW;
-        else if (!strcmp(dev_type, "platform"))
+        else if (!strcmp(devtype, "platform"))
           type = ECORE_DRM_BACKLIGHT_PLATFORM;
-        else if (!strcmp(dev_type, "firmware"))
+        else if (!strcmp(devtype, "firmware"))
           type = ECORE_DRM_BACKLIGHT_FIRMWARE;
 
-        if (conn_type != DRM_MODE_CONNECTOR_LVDS &&
-            conn_type != DRM_MODE_CONNECTOR_eDP)
+        if ((conn_type != DRM_MODE_CONNECTOR_LVDS) && 
+            (conn_type != DRM_MODE_CONNECTOR_eDP))
           {
-             if (type != ECORE_DRM_BACKLIGHT_RAW)
-               {
-                  udev_device_unref(device);
-                  udev_enumerate_unref(enumerate);
-                  return NULL;
-               }
+             if (type != ECORE_DRM_BACKLIGHT_RAW) goto cont;
+          }
+
+        found = EINA_TRUE;
+cont:
+        eina_stringshare_del(devtype);
+        if (found)
+          {
+             tmpdevice = eina_stringshare_add(device);
+             break;
           }
-        udev_device_unref(device);
      }
-   udev_enumerate_unref(enumerate);
 
-   backlight = (Ecore_Drm_Backlight *)malloc(sizeof(Ecore_Drm_Backlight));
-   backlight->type = type;
-   backlight->dir_path = eina_stringshare_add(backlight_path);
+   EINA_LIST_FREE(devs, device)
+     eina_stringshare_del(device);
+
+   if (!found) return NULL;
+
+   if ((backlight = calloc(1, sizeof(Ecore_Drm_Backlight))))
+     {
+        backlight->type = type;
+        /* NB: This sets backlight directory path to /dev/...
+         * Am not sure yet if this is the desired path, or if we want the 
+         * actual /sys path. If we want Just the syspath then 'tmpdevice' is 
+         * already equal to that */
+        backlight->dir_path = eeze_udev_syspath_get_devpath(tmpdevice);
+     }
+
+   eina_stringshare_del(tmpdevice);
 
    return backlight;
 }