int (*custom_lcd_off) (enum deviced_event reason);
int (*on_by_reason) (const char *reason, int timeout);
int (*off_by_reason) (const char *reason);
+ int (*get_brightness) (int *brightness);
+ int (*set_brightness) (int brightness);
+ int (*set_brightness_smooth) (int start_brightness, int end_brightness, int step);
} syscommon_plugin_backend_deviced_display_funcs;
#ifdef __cplusplus
*/
int syscommon_plugin_deviced_display_off_by_reason(const char *reason);
+/**
+ * @breif Plugin implementation for getting display brightness
+ * @param[out] brightness Get current brightness
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int syscommon_plugin_deviced_display_get_brightness(int *brightness);
+
+/**
+ * @breif Plugin implementation for setting display brightness
+ * @param[in] brightness Brightness value to set
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int syscommon_plugin_deviced_display_set_brightness(int brightness);
+
+/**
+ * @breif Plugin implementation for setting display brightness smoothly
+ * @param[in] start_brightness Start brightness
+ * @param[in] end_brightness End brightnes
+ * @param[in] step How many steps to change from start to end brightness
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int syscommon_plugin_deviced_display_set_brightness_smooth(int start_brightness,
+ int end_brightness, int step);
+
#ifdef __cplusplus
}
#endif
return g_display_funcs->off_by_reason(reason);
}
+
+EXPORT
+int syscommon_plugin_deviced_display_get_brightness(int *brightness)
+{
+ int ret = 0;
+
+ if (!g_display_funcs) {
+ ret = syscommon_plugin_deviced_display_get_backend();
+ if (ret < 0)
+ return -ENOTSUP;
+ }
+
+ assert(g_display_funcs);
+
+ if (!g_display_funcs->get_brightness)
+ return -EOPNOTSUPP;
+
+ return g_display_funcs->get_brightness(brightness);
+}
+
+EXPORT
+int syscommon_plugin_deviced_display_set_brightness(int brightness)
+{
+ int ret = 0;
+
+ if (!g_display_funcs) {
+ ret = syscommon_plugin_deviced_display_get_backend();
+ if (ret < 0)
+ return -ENOTSUP;
+ }
+
+ assert(g_display_funcs);
+
+ if (!g_display_funcs->set_brightness)
+ return -EOPNOTSUPP;
+
+ return g_display_funcs->set_brightness(brightness);
+}
+
+EXPORT
+int syscommon_plugin_deviced_display_set_brightness_smooth(int start_brightness,
+ int end_brightness, int step)
+{
+ int ret = 0;
+
+ if (!g_display_funcs) {
+ ret = syscommon_plugin_deviced_display_get_backend();
+ if (ret < 0)
+ return -ENOTSUP;
+ }
+
+ assert(g_display_funcs);
+
+ if (!g_display_funcs->set_brightness_smooth)
+ return -EOPNOTSUPP;
+
+ return g_display_funcs->set_brightness_smooth(start_brightness, end_brightness, step);
+}
return 0;
}
+static int get_brightness(int *brightness)
+{
+ check_expected(brightness);
+
+ return 0;
+}
+
+static int set_brightness(int brightness)
+{
+ check_expected(brightness);
+
+ return 0;
+}
+
+static int set_brightness_smooth(int start_brightness, int end_brightness, int step)
+{
+ check_expected(start_brightness);
+ check_expected(end_brightness);
+ check_expected(step);
+
+ return 0;
+}
+
static syscommon_plugin_backend_deviced_display_funcs g_display_funcs = {
.load_display_config = load_display_config,
.on_changed_setting_value = on_changed_setting_value,
.custom_lcd_off = custom_lcd_off,
.on_by_reason = on_by_reason,
.off_by_reason = off_by_reason,
+ .get_brightness = get_brightness,
+ .set_brightness = set_brightness,
+ .set_brightness_smooth = set_brightness_smooth,
};
static int deviced_display_init(void **data)
ret = syscommon_plugin_deviced_display_off_by_reason("reason");
assert_int_equal(ret, 0);
+}
+
+static void test_get_brightness(void **state)
+{
+ int ret;
+ int value;
+
+ expect_value(get_brightness, brightness, &value);
+ ret = syscommon_plugin_deviced_display_get_brightness(&value);
+ assert_int_equal(ret, 0);
+}
+
+static void test_set_brightness(void **state)
+{
+ int ret;
+
+ expect_value(set_brightness, brightness, 100);
+
+ ret = syscommon_plugin_deviced_display_set_brightness(100);
+ assert_int_equal(ret, 0);
+}
+
+static void test_set_brightness_smooth(void **data)
+{
+ int ret;
+
+ expect_value(set_brightness_smooth, start_brightness, 100);
+ expect_value(set_brightness_smooth, end_brightness, 0);
+ expect_value(set_brightness_smooth, step, 30);
+
+ ret = syscommon_plugin_deviced_display_set_brightness_smooth(100, 0, 30);
+ assert_int_equal(ret, 0);
}
static const struct CMUnitTest testsuite_plugin_api_deviced[] = {
cmocka_unit_test(test_custom_lcd_off),
cmocka_unit_test(test_on_by_reason),
cmocka_unit_test(test_off_by_reason),
+ cmocka_unit_test(test_get_brightness),
+ cmocka_unit_test(test_set_brightness),
+ cmocka_unit_test(test_set_brightness_smooth),
};
TESTSUITE_FIXTURE(testsuite_plugin_api_deviced, setup_plugin_deviced, teardown_plugin_deviced)