embody 'devman' in libdeviced 06/14306/3
authorjy910.yun <jy910.yun@samsung.com>
Fri, 21 Jun 2013 12:06:39 +0000 (21:06 +0900)
committerKrzysztof Sasiak <k.sasiak@samsung.com>
Tue, 7 Jan 2014 12:45:42 +0000 (13:45 +0100)
libdevman is only wrapper library to libdeviced.
All of real operation is in libdeviced.

Change-Id: I506b599851c4d96f271390d9e4997f6b4aae125b
Signed-off-by: Krzysztof Sasiak <k.sasiak@samsung.com>
CMakeLists.txt
devman/CMakeLists.txt
devman/include/devman.h
devman/src/if_legacy.c
packaging/system-server.spec
src/deviced/dd-battery.h
src/deviced/dd-display.h [new file with mode: 0644]
src/deviced/dd-led.h [new file with mode: 0644]
src/shared/battery.c
src/shared/display.c [new file with mode: 0644]
src/shared/led.c [new file with mode: 0644]

index fe84a61..61d34d3 100755 (executable)
@@ -43,10 +43,14 @@ SET(SRCS ${SRCS}
 
 # libdeviced
 SET(DEVICED_SRCS
-       src/shared/battery.c)
+       src/shared/battery.c
+       src/shared/display.c
+       src/shared/led.c)
 
 SET(DEVICED_HEADERS
-       src/deviced/dd-battery.h)
+       src/deviced/dd-battery.h
+       src/deviced/dd-display.h
+       src/deviced/dd-led.h)
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} 
                ${CMAKE_CURRENT_SOURCE_DIR}/src 
@@ -119,7 +123,7 @@ CONFIGURE_FILE(${DEVICED_NAME}.pc.in ${DEVICED_NAME}.pc @ONLY)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DEVICED_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
 ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl" "-ludev" "-lsmack")
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl" "-ludev")
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
 
 INSTALL(FILES ${MOVINAND_FORMAT} DESTINATION bin)
index 8c825f2..3f618ab 100644 (file)
@@ -40,7 +40,8 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
 ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS} ${TARGET_SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${rpkgs_LDFLAGS})
+ADD_DEPENDENCIES(${PROJECT_NAME} ${DEVICED_NAME})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${rpkgs_LDFLAGS} -L${CMAKE_BINARY_DIR} -ldeviced)
 SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION})
 
 ADD_EXECUTABLE(display_wd src/display_wd.c)
index c1d104f..6cb6dd9 100644 (file)
@@ -245,6 +245,7 @@ typedef enum {
  */
        int device_is_battery_full(void);
 
+#ifndef __DD_BATTERY_H__
 /**
  * @par Description:
  *  Battery health status
@@ -259,6 +260,7 @@ typedef enum {
                BAT_COLD,                       /**< */
                BAT_HEALTH_MAX,         /**< */
        };
+#endif
 
 /**
  * @par Description:
index b14d7e9..22d82b1 100644 (file)
 #include <vconf.h>
 #include <errno.h>
 #include <device-node.h>
+#include <dd-display.h>
+#include <dd-battery.h>
+#include <dd-led.h>
 
 #include "devman.h"
-#include "devman_internal.h"
 #include "devlog.h"
 
-#define DISPLAY_MAX_BRIGHTNESS  100
-#define DISPLAY_MIN_BRIGHTNESS  0
-
-#define DISP_INDEX_BIT                      4
-#define COMBINE_DISP_CMD(cmd, prop, index)  (cmd = (prop | (index << DISP_INDEX_BIT)))
-
-#define SET_FLAG(var, bit)              (var |= (1<<bit))
-#define UNSET_FLAG(var, bit)            (var &= (~(1<<bit)))
-#define BRT_BIT                 1
-#define LED_BIT                 4
-
-static unsigned int disp_flag = 0x0;
-
 API int device_get_battery_pct(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY, &val);
-       if (ret < 0)
-               return ret;
-
-       if (val < 0 || val > 100) {
-               DEVERR("capacity value is wrong");
-               return DEVMAN_ERROR_OPERATION_FAILED;
-       }
-
-       return val;
+       return battery_get_percent();
 }
 
 API int device_is_battery_full(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CHARGE_FULL, &val);
-       if (ret < 0)
-               return ret;
-
-       if (val != 0 && val != 1) {
-               DEVERR("charge_full value is wrong");
-               return DEVMAN_ERROR_OPERATION_FAILED;
-       }
-
-       return val;
+       return battery_is_full();
 }
 
 API int device_get_battery_health(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_HEALTH, &val);
-       if (ret < 0)
-               return ret;
-
-       if (val < BAT_UNKNOWN || val > BAT_COLD) {
-               DEVERR("battery health value is wrong");
-               return DEVMAN_ERROR_OPERATION_FAILED;
-       }
-
-       return val;
+       return battery_get_health();
 }
 
 API int device_get_battery_pct_raw(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY_RAW, &val);
-       if (ret < 0)
-               return ret;
-
-       if (val > 10000)
-               return 10000;
-
-       return val;
+       return battery_get_percent_raw();
 }
 
 API int device_get_display_brt(display_num_t lcdnum)
 {
-       int val;
-       int cmd;
-       int ret;
-
-       COMBINE_DISP_CMD(cmd, PROP_DISPLAY_BRIGHTNESS, lcdnum);
-       ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &val);
-       if (ret < 0)
-               return ret;
-
-       return val;
+       return display_get_brightness();
 }
 
 API int device_set_display_brt_with_settings(display_num_t lcdnum, int val)
 {
-       int auto_brt_state;
-       int cmd;
-       int ret;
-
-       if (vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &auto_brt_state) != 0) {
-               DEVERR("Failed to get VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT value");
-               return DEVMAN_ERROR_OPERATION_FAILED;
-       }
-
-       if (auto_brt_state == SETTING_BRIGHTNESS_AUTOMATIC_ON) {
-               DEVLOG("auto_brightness state is ON, can not change the brightness value");
-               return DEVMAN_ERROR_NONE;
-       }
-
-       COMBINE_DISP_CMD(cmd, PROP_DISPLAY_BRIGHTNESS, lcdnum);
-       ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, val);
-       if (ret < 0)
-               return ret;
-
-       if (vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, val) != 0) {
-               DEVERR("Failed to set VCONFKEY_SETAPPL_LCD_BRIGHTNESS value");
-       }
-
-       if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, val) != 0) {
-               DEVERR("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value");
-       }
-
-       return DEVMAN_ERROR_NONE;
+       return display_set_brightness_with_setting(val);
 }
 
 API int device_set_display_brt(display_num_t lcdnum, int val)
 {
-       int auto_brt_state;
-       int cmd;
-       int ret;
-
-       if (vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &auto_brt_state) != 0) {
-               DEVERR("Failed to get VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT value");
-               return DEVMAN_ERROR_OPERATION_FAILED;
-       }
-
-       vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON);
-       COMBINE_DISP_CMD(cmd, PROP_DISPLAY_BRIGHTNESS, lcdnum);
-       ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, val);
-       if (ret < 0)
-               return ret;
-
-       if (auto_brt_state == SETTING_BRIGHTNESS_AUTOMATIC_ON) {
-               DEVLOG("Auto brightness will be paused");
-               vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE);
-       }
-
-       if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, val) != 0) {
-               DEVERR("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value");
-       }
-
-       if (!disp_flag)
-               ret = display_register_postjob();
-       if (ret == 0)
-               SET_FLAG(disp_flag, BRT_BIT);
-       return DEVMAN_ERROR_NONE;
+       return display_set_brightness(val);
 }
 
 API int device_release_brt_ctrl(display_num_t lcdnum)
 {
-       int bat_state;
-       int setting_val;
-       int auto_brt_state;
-       int charger_state;
-       int brt_changed_state;
-       int cmd;
-       int ret;
-
-       if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) != 0) {
-               DEVERR("Failed to get VCONFKEY_SYSMAN_BATTERY_STATUS_LOW value");
-               return DEVMAN_ERROR_OPERATION_FAILED;
-       }
-
-       if (vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger_state) != 0) {
-               DEVERR("Failed to get VCONFKEY_SYSMAN_CHARGER_STATUS value");
-               return DEVMAN_ERROR_OPERATION_FAILED;
-       }
-
-       if (vconf_get_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, &brt_changed_state) != 0) {
-               DEVERR("Failed to get VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM value");
-               return DEVMAN_ERROR_OPERATION_FAILED;
-       }
-
-       if (vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting_val) != 0) {
-               DEVERR("Failed to get VCONFKEY_SETAPPL_LCD_BRIGHTNESS value");
-               return DEVMAN_ERROR_OPERATION_FAILED;
-       }
-
-       if (vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &auto_brt_state) != 0) {
-               DEVERR("Failed to get VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT value");
-               return DEVMAN_ERROR_OPERATION_FAILED;
-       }
-
-       vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF);
-
-       // check dim state
-       if (bat_state <= VCONFKEY_SYSMAN_BAT_WARNING_LOW &&
-               charger_state == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !brt_changed_state) {
-               DEVLOG("batt warning low : brightness is not changed!");
-               COMBINE_DISP_CMD(cmd, PROP_DISPLAY_BRIGHTNESS, lcdnum);
-               device_set_property(DEVICE_TYPE_DISPLAY, cmd, 0);
-               return DEVMAN_ERROR_NONE;
-       }
-
-       if (auto_brt_state == SETTING_BRIGHTNESS_AUTOMATIC_OFF) {
-               COMBINE_DISP_CMD(cmd, PROP_DISPLAY_BRIGHTNESS, lcdnum);
-               device_set_property(DEVICE_TYPE_DISPLAY, cmd, setting_val);
-               if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, setting_val) != 0) {
-                       DEVERR("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value");
-               }
-       } else if (auto_brt_state == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) {
-               DEVLOG("Auto brightness will be enable");
-               vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON);
-       }
-
-       UNSET_FLAG(disp_flag, BRT_BIT);
-       if (!disp_flag)
-               display_cancel_postjob();
-       return DEVMAN_ERROR_NONE;
+       return display_release_brightness();
 }
 
 API int device_get_max_brt(display_num_t lcdnum)
 {
-       return DISPLAY_MAX_BRIGHTNESS;
+       return display_get_max_brightness();
 }
 
 API int device_get_min_brt(display_num_t lcdnum)
 {
-       return DISPLAY_MIN_BRIGHTNESS;
+       return display_get_min_brightness();
 }
 
 API int device_get_display_gamma(display_num_t lcdnum)
@@ -275,200 +96,90 @@ API int device_release_gamma_ctrl(display_num_t lcdnum, display_gamma_t org_val)
 
 API int device_get_display_count(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_DISPLAY_COUNT, &val);
-       if (ret < 0)
-               return ret;
-
-       return val;
+       return display_get_count();
 }
 
 API int device_get_image_enhance_mode(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_IMAGE_ENHANCE_MODE, &val);
-       if (ret < 0)
-               return ret;
-
-       return val;
+       DEVERR("Not support this api");
+       return DEVMAN_ERROR_NOT_SUPPORTED;
 }
 
 API int device_set_image_enhance_mode(int val)
 {
-       int ret;
-
-       ret = device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_IMAGE_ENHANCE_MODE, val);
-       if (ret < 0)
-               return ret;
-
-       return DEVMAN_ERROR_NONE;
+       DEVERR("Not support this api");
+       return DEVMAN_ERROR_NOT_SUPPORTED;
 }
 
 API int device_get_image_enhance_scenario(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_IMAGE_ENHANCE_SCENARIO, &val);
-       if (ret < 0)
-               return ret;
-
-       return val;
+       DEVERR("Not support this api");
+       return DEVMAN_ERROR_NOT_SUPPORTED;
 }
 
 API int device_set_image_enhance_scenario(int val)
 {
-       int ret;
-
-       ret = device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_IMAGE_ENHANCE_SCENARIO, val);
-       if (ret < 0)
-               return ret;
-
-       return DEVMAN_ERROR_NONE;
+       DEVERR("Not support this api");
+       return DEVMAN_ERROR_NOT_SUPPORTED;
 }
 
 API int device_get_image_enhance_tone(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_IMAGE_ENHANCE_TONE, &val);
-       if (ret < 0)
-               return ret;
-
-       return val;
+       DEVERR("Not support this api");
+       return DEVMAN_ERROR_NOT_SUPPORTED;
 }
 
 API int device_set_image_enhance_tone(int val)
 {
-       int ret;
-
-       ret = device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_IMAGE_ENHANCE_TONE, val);
-       if (ret < 0)
-               return ret;
-
-       return DEVMAN_ERROR_NONE;
+       DEVERR("Not support this api");
+       return DEVMAN_ERROR_NOT_SUPPORTED;
 }
 
 API int device_get_image_enhance_outdoor(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_IMAGE_ENHANCE_OUTDOOR, &val);
-       if (ret < 0)
-               return ret;
-
-       return val;
+       DEVERR("Not support this api");
+       return DEVMAN_ERROR_NOT_SUPPORTED;
 }
 
 API int device_set_image_enhance_outdoor(int val)
 {
-       int ret;
-
-       ret = device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_IMAGE_ENHANCE_OUTDOOR, val);
-       if (ret < 0)
-               return ret;
-
-       return DEVMAN_ERROR_NONE;
+       DEVERR("Not support this api");
+       return DEVMAN_ERROR_NOT_SUPPORTED;
 }
 
 API int device_get_image_enhance_info(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_IMAGE_ENHANCE_INFO, &val);
-       if (ret < 0)
-               return ret;
-
-       return val;
+       DEVERR("Not support this api");
+       return DEVMAN_ERROR_NOT_SUPPORTED;
 }
 
 API int device_get_led_brt(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_LED, PROP_LED_BRIGHTNESS, &val);
-       if (ret < 0)
-               return ret;
-
-       return val;
+       return led_get_brightness();
 }
 
 API int device_set_led_brt(int val)
 {
-       int ret;
-
-       ret = device_set_property(DEVICE_TYPE_LED, PROP_LED_BRIGHTNESS, val);
-       if (ret < 0)
-               return ret;
-
-       if (val == 0) {
-               UNSET_FLAG(disp_flag, LED_BIT);
-               if (!disp_flag)
-                       display_cancel_postjob();
-       } else {
-               if (!disp_flag)
-                       ret = display_register_postjob();
-               if (ret == 0)
-                       SET_FLAG(disp_flag, LED_BIT);
-       }
-
-       return DEVMAN_ERROR_NONE;
+       DEVERR("Not support this api");
+       return DEVMAN_ERROR_NOT_SUPPORTED;
 }
 
 API int device_set_led_brt_without_noti(int val)
 {
-       int ret;
-
-       ret = device_set_property(DEVICE_TYPE_LED, PROP_LED_BRIGHTNESS, val);
-       if (ret < 0)
-               return ret;
-
-       return DEVMAN_ERROR_NONE;
+       return led_set_brightness(val);
 }
 
 API int device_get_max_led(void)
 {
-       int val;
-       int ret;
-
-       ret = device_get_property(DEVICE_TYPE_LED, PROP_LED_MAX_BRIGHTNESS, &val);
-       if (ret < 0)
-               return ret;
-
-       return val;
+       return led_get_max_brightness();
 }
 
 API int device_get_acl_control_status(display_num_t num)
 {
-       int val;
-       int cmd;
-       int ret;
-
-       COMBINE_DISP_CMD(cmd, PROP_DISPLAY_ACL_CONTROL, num);
-       ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &val);
-       if (ret < 0)
-               return ret;
-
-       return val;
+       return display_get_acl_status();
 }
 
 API int device_set_acl_control_status(display_num_t num, int val)
 {
-       int cmd;
-       int ret;
-
-       COMBINE_DISP_CMD(cmd, PROP_DISPLAY_ACL_CONTROL, num);
-       ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, val);
-       if (ret < 0)
-               return ret;
-
-       return DEVMAN_ERROR_NONE;
+       return display_set_acl_status(val);
 }
index 47b5e76..ed542ff 100755 (executable)
@@ -409,6 +409,8 @@ systemctl daemon-reload
 %files -n libdeviced-devel
 %defattr(-,root,root,-)
 %{_includedir}/deviced/dd-battery.h
+%{_includedir}/deviced/dd-display.h
+%{_includedir}/deviced/dd-led.h
 %{_libdir}/libdeviced.so
 %{_libdir}/pkgconfig/deviced.pc
 
index 78fd9b3..f368b56 100644 (file)
@@ -29,6 +29,22 @@ extern "C" {
  * @brief       This file provides for control of battery
  */
 
+enum {
+       BAT_UNKNOWN = 0,
+       BAT_GOOD,
+       BAT_OVERHEAT,
+       BAT_DEAD,
+       BAT_OVERVOLTAGE,
+       BAT_UNSPECIFIED,
+       BAT_COLD,
+       BAT_HEALTH_MAX,
+};
+
+int battery_get_percent(void);
+int battery_get_percent_raw(void);
+int battery_is_full(void);
+int battery_get_health(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/deviced/dd-display.h b/src/deviced/dd-display.h
new file mode 100644 (file)
index 0000000..929291e
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * deviced
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __DD_DISPLAY_H__
+#define __DD_DISPLAY_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file        dd-display.h
+ * @ingroup     DEVICED_LIBRARY
+ * @brief       This file provides for control of display
+ */
+
+int display_get_count(void);
+int display_get_max_brightness(void);
+int display_get_min_brightness(void);
+int display_get_brightness(void);
+int display_set_brightness_with_setting(int val);
+int display_set_brightness(int val);
+int display_release_brightness(void);
+int display_get_acl_status(void);
+int display_set_acl_status(int val);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src/deviced/dd-led.h b/src/deviced/dd-led.h
new file mode 100644 (file)
index 0000000..1ba3684
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * deviced
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __DD_LED_H__
+#define __DD_LED_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file        dd-led.h
+ * @ingroup     DEVICED_LIBRARY
+ * @brief       This file provides for control of led
+ */
+
+int led_get_brightness(void);
+int led_get_max_brightness(void);
+int led_set_brightness(int val);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
index 7d7d238..baf02d4 100644 (file)
 
 #include "log.h"
 #include "dd-battery.h"
+
+API int battery_get_percent(void)
+{
+       int val;
+       int r;
+
+       r = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY, &val);
+       if (r < 0)
+               return r;
+
+       if (val < 0 || val > 100) {
+               _E("capacity value is wrong");
+               errno = EPERM;
+               return -1;
+       }
+
+       return val;
+}
+
+API int battery_get_percent_raw(void)
+{
+       int val;
+       int r;
+
+       r = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY_RAW, &val);
+       if (r < 0)
+               return r;
+
+       if (val > 10000)
+               return 10000;
+
+       return val;
+}
+
+API int battery_is_full(void)
+{
+       int val;
+       int r;
+
+       r = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CHARGE_FULL, &val);
+       if (r < 0)
+               return r;
+
+       if (val != 0 && val != 1) {
+               _E("charge_full value is wrong");
+               errno = EPERM;
+               return -1;
+       }
+
+       return val;
+}
+
+API int battery_get_health(void)
+{
+       int val;
+       int r;
+
+       r = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_HEALTH, &val);
+       if (r < 0)
+               return r;
+
+       if (val < BAT_UNKNOWN || val > BAT_COLD) {
+               _E("battery health value is wrong");
+               errno = EPERM;
+               return -1;
+       }
+
+       return val;
+}
diff --git a/src/shared/display.c b/src/shared/display.c
new file mode 100644 (file)
index 0000000..d1eb642
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ * deviced
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <vconf.h>
+#include <errno.h>
+#include <device-node.h>
+
+#include "log.h"
+#include "dd-display.h"
+
+#define DISPLAY_MAX_BRIGHTNESS  100
+#define DISPLAY_MIN_BRIGHTNESS  0
+
+API int display_get_count(void)
+{
+       int val;
+       int r;
+
+       r = device_get_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_DISPLAY_COUNT, &val);
+       if (r < 0)
+               return r;
+
+       return val;
+}
+
+API int display_get_max_brightness(void)
+{
+       return DISPLAY_MAX_BRIGHTNESS;
+}
+
+API int display_get_min_brightness(void)
+{
+       return DISPLAY_MIN_BRIGHTNESS;
+}
+
+API int display_get_brightness(void)
+{
+       int val;
+       int r;
+
+       r = device_get_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_BRIGHTNESS, &val);
+       if (r < 0)
+               return r;
+
+       return val;
+}
+
+API int display_set_brightness_with_setting(int val)
+{
+       int auto_brt_state;
+       int r;
+
+       if (vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &auto_brt_state) != 0) {
+               _E("Failed to get VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT value");
+               errno = EPERM;
+               return -1;
+       }
+
+       if (auto_brt_state == SETTING_BRIGHTNESS_AUTOMATIC_ON) {
+               _D("auto_brightness state is ON, can not change the brightness value");
+               return 0;
+       }
+
+       r = device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_BRIGHTNESS, val);
+       if (r < 0)
+               return r;
+
+       if (vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, val) != 0) {
+               _E("Failed to set VCONFKEY_SETAPPL_LCD_BRIGHTNESS value");
+       }
+
+       if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, val) != 0) {
+               _E("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value");
+       }
+
+       return 0;
+}
+
+API int display_set_brightness(int val)
+{
+       int auto_brt_state;
+       int r;
+
+       if (vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &auto_brt_state) != 0) {
+               _E("Failed to get VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT value");
+               errno = EPERM;
+               return -1;
+       }
+
+       vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON);
+       r = device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_BRIGHTNESS, val);
+       if (r < 0)
+               return r;
+
+       if (auto_brt_state == SETTING_BRIGHTNESS_AUTOMATIC_ON) {
+               _D("Auto brightness will be paused");
+               vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE);
+       }
+
+       if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, val) != 0) {
+               _E("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value");
+       }
+
+       return 0;
+}
+
+API int display_release_brightness(void)
+{
+       int bat_state;
+       int setting_val;
+       int auto_brt_state;
+       int charger_state;
+       int brt_changed_state;
+       int r;
+
+       if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) != 0) {
+               _E("Failed to get VCONFKEY_SYSMAN_BATTERY_STATUS_LOW value");
+               errno = EPERM;
+               return -1;
+       }
+
+       if (vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger_state) != 0) {
+               _E("Failed to get VCONFKEY_SYSMAN_CHARGER_STATUS value");
+               errno = EPERM;
+               return -1;
+       }
+
+       if (vconf_get_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, &brt_changed_state) != 0) {
+               _E("Failed to get VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM value");
+               errno = EPERM;
+               return -1;
+       }
+
+       if (vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting_val) != 0) {
+               _E("Failed to get VCONFKEY_SETAPPL_LCD_BRIGHTNESS value");
+               errno = EPERM;
+               return -1;
+       }
+
+       if (vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &auto_brt_state) != 0) {
+               _E("Failed to get VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT value");
+               errno = EPERM;
+               return -1;
+       }
+
+       vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF);
+       if (bat_state < VCONFKEY_SYSMAN_BAT_WARNING_LOW) {
+               _D("can not set brightness for low battery");
+               return 0;
+       }
+
+       // check dim state
+       if (bat_state == VCONFKEY_SYSMAN_BAT_WARNING_LOW &&
+               charger_state == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !brt_changed_state) {
+               _D("batt warning low : brightness is not changed!");
+               device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_BRIGHTNESS, 0);
+               return 0;
+       }
+
+       if (auto_brt_state == SETTING_BRIGHTNESS_AUTOMATIC_OFF) {
+               device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_BRIGHTNESS, setting_val);
+       } else if (auto_brt_state == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) {
+               _D("Auto brightness will be enable");
+               vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON);
+       }
+
+       return 0;
+}
+
+API int display_get_acl_status(void)
+{
+       int val;
+       int r;
+
+       r = device_get_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_ACL_CONTROL, &val);
+       if (r < 0)
+               return r;
+
+       return val;
+}
+
+API int display_set_acl_status(int val)
+{
+       int r;
+
+       r = device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_ACL_CONTROL, val);
+       if (r < 0)
+               return r;
+
+       return 0;
+}
diff --git a/src/shared/led.c b/src/shared/led.c
new file mode 100644 (file)
index 0000000..af70de2
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * deviced
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <vconf.h>
+#include <errno.h>
+#include <device-node.h>
+
+#include "log.h"
+#include "dd-led.h"
+
+API int led_get_brightness(void)
+{
+       int val;
+       int r;
+
+       r = device_get_property(DEVICE_TYPE_LED, PROP_LED_BRIGHTNESS, &val);
+       if (r < 0)
+               return r;
+
+       return val;
+}
+
+API int led_get_max_brightness(void)
+{
+       int val;
+       int r;
+
+       r = device_get_property(DEVICE_TYPE_LED, PROP_LED_MAX_BRIGHTNESS, &val);
+       if (r < 0)
+               return r;
+
+       return val;
+}
+
+API int led_set_brightness(int val)
+{
+       int r;
+
+       r = device_set_property(DEVICE_TYPE_LED, PROP_LED_BRIGHTNESS, val);
+       if (r < 0)
+               return r;
+
+       return 0;
+}