#include <gio/gio.h>
#include <libsyscommon/libgdbus.h>
#include <libsyscommon/list.h>
+#include <system_info.h>
#include "callback.h"
#include "battery.h"
return -EINVAL;
}
+static int device_callback_check_feature_supported(device_callback_e type)
+{
+ static bool f_display = false;
+ static bool f_battery = false;
+ static bool f_flash = false;
+
+ int retval;
+ bool supported;
+
+ switch (type) {
+ case DEVICE_CALLBACK_BATTERY_CAPACITY:
+ case DEVICE_CALLBACK_BATTERY_LEVEL:
+ case DEVICE_CALLBACK_BATTERY_CHARGING:
+ if (f_battery)
+ return 0;
+
+ retval = system_info_get_platform_bool("http://tizen.org/feature/battery", &supported);
+ if (retval != SYSTEM_INFO_ERROR_NONE || !supported)
+ return -ENOTSUP;
+
+ f_battery = true;
+ return 0;
+ case DEVICE_CALLBACK_DISPLAY_STATE:
+ if (f_display)
+ return 0;
+
+ retval = system_info_get_platform_bool("http://tizen.org/feature/display", &supported);
+ if (retval != SYSTEM_INFO_ERROR_NONE || !supported)
+ return -ENOTSUP;
+ retval = system_info_get_platform_bool("http://tizen.org/feature/display.state", &supported);
+ if (retval != SYSTEM_INFO_ERROR_NONE || !supported)
+ return -ENOTSUP;
+
+ f_display = true;
+ return 0;
+ case DEVICE_CALLBACK_FLASH_BRIGHTNESS:
+ if (f_flash)
+ return 0;
+
+ retval = system_info_get_platform_bool("http://tizen.org/feature/camera.back.flash", &supported);
+ if (retval != SYSTEM_INFO_ERROR_NONE || !supported)
+ return -ENOTSUP;
+
+ f_flash = true;
+ return 0;
+ default:
+ return -EINVAL;
+ }
+}
+
int device_add_callback(device_callback_e type, device_changed_cb cb, void *data)
{
struct device_cb_info *cb_info;
GList *elem, *elem_next;
int ret_request, n;
- if (!is_feature_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE)
- return DEVICE_ERROR_NOT_SUPPORTED;
-
if (type < 0 || type >= DEVICE_CALLBACK_MAX)
return DEVICE_ERROR_INVALID_PARAMETER;
if (!cb)
return DEVICE_ERROR_INVALID_PARAMETER;
+ if (device_callback_check_feature_supported(type) != 0)
+ return DEVICE_ERROR_NOT_SUPPORTED;
+
/* check if it is the first request */
n = SYS_G_LIST_LENGTH(device_cb_list[type]);
if (n == 0) {
GList *elem, *elem_next;
int ret_request, n;
- if (!is_feature_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE)
- return DEVICE_ERROR_NOT_SUPPORTED;
-
if (type < 0 || type >= DEVICE_CALLBACK_MAX)
return DEVICE_ERROR_INVALID_PARAMETER;
if (!cb)
return DEVICE_ERROR_INVALID_PARAMETER;
+ if (device_callback_check_feature_supported(type) != 0)
+ return DEVICE_ERROR_NOT_SUPPORTED;
+
/* search for the same element with callback */
SYS_G_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info) {
if (cb_info->cb == cb)