From a31327ab9359f83e889a14c43c2f675a36362e05 Mon Sep 17 00:00:00 2001 From: "jy910.yun" Date: Fri, 7 Nov 2014 23:27:37 +0900 Subject: [PATCH] deviced: Merge Tizen 2.3 source code into tizen branch Deviced is a new device daemon instead of system-server. We have a plan to upgrade system-server to deviced. But there are more than 500 different patches. Besides some patches in Tizen 2.3 has mobile product features. And deviced should provide some library which have provided by system-server to keep compatibility with another modules. So I merge Tizen 2.3 source code into public branch manually. (Remove mobile product features and Keep library compatibility) Signed-off-by: jy910.yun Change-Id: I53d5cfb76ae05c4a240f00cab719e4c699b70592 --- AUTHORS | 2 - CMakeLists.txt | 108 +- LICENSE.Apache-2.0 | 2 + NOTICE | 3 +- README.error.code | 9 + deviced.pc.in | 4 +- packaging/deviced.spec | 33 +- scripts/deviced-pre.sh | 15 - src/CMakeLists.txt | 3 + src/apps/apps.c | 5 + src/apps/apps.h | 6 +- src/auto-test/CMakeLists.txt | 33 - src/auto-test/test.c | 70 - src/auto-test/test.h | 101 - src/{display/battery.c => battery/battery-time.c} | 126 +- src/battery/battery.conf | 7 + src/{core/sysnoti.h => battery/battery.h} | 31 +- src/battery/config.c | 73 + src/{display/battery.h => battery/config.h} | 23 +- src/battery/lowbat-handler.c | 686 ++++--- src/control/control.c | 102 +- src/core/common.c | 228 ++- src/core/common.h | 106 +- src/core/config-parser.c | 127 ++ src/{auto-test/main.c => core/config-parser.h} | 37 +- src/core/core.c | 180 -- src/core/device-change-handler.c | 1478 ++++++++------ src/core/device-handler.h | 86 +- src/core/device-notifier.c | 98 +- src/core/device-notifier.h | 8 + src/core/devices.c | 23 + src/core/devices.h | 69 +- src/core/edbus-handler.c | 406 +++- src/core/edbus-handler.h | 91 +- src/core/execute.c | 101 + src/core/launch.c | 20 +- src/core/launch.h | 14 +- src/core/list.h | 95 +- src/core/log.c | 2 + src/core/log.h | 7 +- src/core/main.c | 36 +- src/core/noti.c | 86 - src/core/noti.h | 27 - src/core/power-supply.c | 856 ++++++++ src/core/power-supply.h | 39 + src/core/predefine.c | 198 -- src/core/predefine.h | 28 - src/core/queue.c | 295 --- src/core/queue.h | 66 - src/core/sig-handler.c | 6 +- src/core/sysnoti.c | 337 ---- src/core/udev.h | 65 +- src/cpu/cpu-handler.c | 640 +++--- src/devicectl/CMakeLists.txt | 40 + src/devicectl/devicectl.c | 250 +++ src/devicectl/usb.c | 284 +++ src/{core/core.h => devicectl/usb.h} | 20 +- src/deviced/dd-battery.h | 99 +- src/{libdeviced/common.h => deviced/dd-common.h} | 18 +- src/deviced/dd-control.h | 63 +- src/deviced/dd-deviced-managed.h | 98 +- src/deviced/dd-deviced.h | 227 ++- src/deviced/dd-display.h | 353 +++- src/deviced/dd-haptic.h | 89 +- src/deviced/dd-led.h | 78 +- src/deviced/dd-mmc.h | 135 ++ src/deviced/dd-storage.h | 77 + src/deviced/dd-usbhost.h | 259 +++ src/deviced/deviced_doc.h | 42 + src/deviced/haptic-module.h | 11 +- src/deviced/haptic-plugin-intf.h | 4 +- src/display/auto-brightness.c | 740 +++++++ src/display/brightness.c | 253 +++ src/display/brightness.h | 33 + src/display/conf.c | 84 - src/display/core.c | 2034 ++++++++++++++------ src/display/core.h | 74 +- src/display/{llinterface.c => device-interface.c} | 333 +++- src/display/{llinterface.h => device-interface.h} | 44 +- src/display/display-actor.c | 102 + src/display/display-actor.h | 52 + src/display/display-dbus.c | 684 ++++++- src/display/display-mobile.conf | 31 + src/display/display-ops.c | 74 + src/{libdeviced/dbus.h => display/display-ops.h} | 43 +- src/display/display-wearable.conf | 45 + src/display/key-filter.c | 727 +++++-- src/display/lock-detector.c | 223 +++ src/display/lock-detector.h | 35 + src/display/lsensor.c | 390 ---- src/display/poll.c | 164 +- src/display/poll.h | 32 +- src/display/setting.c | 121 +- src/display/setting.h | 28 +- src/display/util.c | 202 -- src/display/util.h | 70 +- src/display/x-lcd-on.c | 52 +- src/earjack/earjack.c | 141 ++ src/fsck-msdos/LICENSE | 30 - src/gpio/buzzer.c | 97 + src/gpio/gpio.c | 124 ++ src/gpio/gpio.h | 63 + src/gpio/hall.c | 97 + src/gpio/sim.c | 97 + src/haptic/README.standard | 13 + src/haptic/emulator.c | 148 ++ src/haptic/external.c | 99 + src/haptic/haptic-micro.conf | 15 + src/haptic/haptic-mobile.conf | 24 + src/haptic/haptic.c | 606 ++++-- src/{pm_event/pm_event.c => haptic/haptic.h} | 57 +- src/haptic/standard.c | 500 +++++ src/led/ir.c | 73 + src/led/led.c | 235 --- src/led/noti.c | 74 + src/led/torch.c | 120 ++ src/{display/conf.h => led/torch.h} | 10 +- src/libdeviced/CMakeLists.txt | 12 +- src/libdeviced/battery.c | 75 +- src/libdeviced/control.c | 90 +- src/libdeviced/dbus.c | 261 ++- src/libdeviced/deviced-conf.c | 79 +- src/libdeviced/deviced-noti.c | 378 ++-- src/libdeviced/deviced-util.c | 24 +- src/libdeviced/display.c | 293 ++- src/libdeviced/haptic.c | 308 +-- src/libdeviced/led.c | 132 +- src/libdeviced/mmc.c | 221 +++ src/libdeviced/storage.c | 75 + src/libdeviced/usbhost.c | 254 +++ src/libdevman/CMakeLists.txt | 1 - src/libdevman/TC/build.sh | 20 - src/libdevman/TC/execute.sh | 19 - src/libdevman/TC/tet_code | 12 - src/libdevman/TC/tet_scen | 7 - src/libdevman/TC/tetbuild.cfg | 3 - src/libdevman/TC/tetclean.cfg | 2 - src/libdevman/TC/tetexec.cfg | 1 - src/libdevman/TC/unit/Makefile | 42 - src/libdevman/TC/unit/tc_gen.sh | 28 - src/libdevman/TC/unit/tslist | 19 - src/libdevman/TC/unit/utc_MODULE_API_func.c.in | 64 - .../utc_SystemFW_device_get_battery_pct_func.c | 64 - .../utc_SystemFW_device_get_display_brt_func.c | 66 - .../utc_SystemFW_device_get_display_gamma_func.c | 66 - .../TC/unit/utc_SystemFW_device_get_max_brt_func.c | 66 - .../unit/utc_SystemFW_device_get_property_func.c | 69 - .../unit/utc_SystemFW_device_haptic_close_func.c | 78 - ...SystemFW_device_haptic_get_file_duration_func.c | 84 - ...temFW_device_haptic_get_pattern_duration_func.c | 82 - .../TC/unit/utc_SystemFW_device_haptic_open_func.c | 71 - .../utc_SystemFW_device_haptic_play_file_func.c | 82 - ...utc_SystemFW_device_haptic_play_monotone_func.c | 79 - .../utc_SystemFW_device_haptic_play_pattern_func.c | 81 - .../utc_SystemFW_device_haptic_stop_play_func.c | 101 - .../utc_SystemFW_device_is_battery_full_func.c | 66 - .../utc_SystemFW_device_release_brt_ctrl_func.c | 73 - .../utc_SystemFW_device_release_gamma_ctrl_func.c | 67 - .../utc_SystemFW_device_set_display_brt_func.c | 65 - .../utc_SystemFW_device_set_display_gamma_func.c | 65 - .../unit/utc_SystemFW_device_set_property_func.c | 68 - src/libdevman/image/SLP_devman_PG_architecture.png | Bin 59818 -> 0 bytes src/libhaptic/TC/build.sh | 20 - src/libhaptic/TC/execute.sh | 19 - src/libhaptic/TC/tet_code | 12 - src/libhaptic/TC/tet_scen | 7 - src/libhaptic/TC/tetbuild.cfg | 3 - src/libhaptic/TC/tetclean.cfg | 2 - src/libhaptic/TC/tetexec.cfg | 1 - src/libhaptic/TC/unit/Makefile | 28 - src/libhaptic/TC/unit/tc_gen.sh | 28 - src/libhaptic/TC/unit/tslist | 6 - src/libhaptic/TC/unit/utc_MODULE_API_func.c.in | 64 - .../TC/unit/utc_SystemFW_haptic_close_func.c | 78 - .../utc_SystemFW_haptic_get_file_duration_func.c | 84 - .../TC/unit/utc_SystemFW_haptic_open_func.c | 71 - .../TC/unit/utc_SystemFW_haptic_play_file_func.c | 82 - .../unit/utc_SystemFW_haptic_play_monotone_func.c | 79 - .../TC/unit/utc_SystemFW_haptic_stop_play_func.c | 101 - .../image/SLP_devman_PG_haptic_architecture.png | Bin 21787 -> 0 bytes src/libslp-pm/TC/build.sh | 20 - src/libslp-pm/TC/execute.sh | 19 - src/libslp-pm/TC/tet_code | 12 - src/libslp-pm/TC/tet_scen | 7 - src/libslp-pm/TC/tetbuild.cfg | 3 - src/libslp-pm/TC/tetclean.cfg | 2 - src/libslp-pm/TC/tetexec.cfg | 1 - src/libslp-pm/TC/unit/Makefile | 24 - src/libslp-pm/TC/unit/tc_gen.sh | 28 - src/libslp-pm/TC/unit/tslist | 3 - src/libslp-pm/TC/unit/utc_MODULE_API_func.c.in | 64 - .../TC/unit/utc_SystemFW_pm_change_state_func.c | 63 - .../TC/unit/utc_SystemFW_pm_lock_state_func.c | 65 - .../TC/unit/utc_SystemFW_pm_unlock_state_func.c | 72 - src/libslp-pm/image/SLP_pm_PG_architecture.png | Bin 15990 -> 0 bytes src/libslp-pm/image/SLP_pm_PG_state_diagram.png | Bin 50427 -> 0 bytes src/libsysman/TC/build.sh | 20 - src/libsysman/TC/execute.sh | 19 - src/libsysman/TC/tet_code | 12 - src/libsysman/TC/tet_scen | 7 - src/libsysman/TC/tetbuild.cfg | 3 - src/libsysman/TC/tetclean.cfg | 2 - src/libsysman/TC/tetexec.cfg | 1 - src/libsysman/TC/unit/Makefile | 31 - src/libsysman/TC/unit/tc_gen.sh | 28 - src/libsysman/TC/unit/tslist | 8 - src/libsysman/TC/unit/utc_MODULE_API_func.c.in | 64 - .../TC/unit/utc_SystemFW_sysconf_is_vip_func.c | 64 - ...utc_SystemFW_sysconf_set_mempolicy_bypid_func.c | 66 - .../unit/utc_SystemFW_sysconf_set_mempolicy_func.c | 64 - ...utc_SystemFW_sysconf_set_permanent_bypid_func.c | 64 - .../unit/utc_SystemFW_sysconf_set_permanent_func.c | 65 - .../TC/unit/utc_SystemFW_sysconf_set_vip_func.c | 65 - .../TC/unit/utc_SystemFW_sysman_get_apppath_func.c | 66 - .../utc_SystemFW_sysman_get_cmdline_name_func.c | 64 - .../TC/unit/utc_SystemFW_sysman_get_pid_func.c | 64 - .../unit/utc_SystemFW_sysman_set_datetime_func.c | 64 - src/mmc/config.c | 104 + src/{core/data.h => mmc/config.h} | 16 +- src/mmc/ext4.c | 193 +- src/mmc/mmc-handler.c | 1134 ++++++----- src/mmc/mmc-handler.h | 64 +- src/mmc/mmc.conf | 3 + src/mmc/uevent.c | 149 ++ src/mmc/vfat.c | 139 +- src/newfs-msdos/CMakeLists.txt | 33 + src/newfs-msdos/LICENSE | 0 src/newfs-msdos/newfs-msdos.c | 1075 +++++++++++ src/pm_event/CMakeLists.txt | 34 - src/power/power-handler.c | 796 ++++---- src/power/power-handler.h | 46 + src/predefine_act_plugin/xxx-predefine.c | 13 +- src/proc/cpu-info.c | 151 ++ src/proc/lowmem-handler.c | 554 ------ src/proc/pmon-handler.c | 37 +- src/proc/proc-handler.c | 463 ++++- src/proc/proc-handler.h | 19 +- src/restarter/restart.c | 15 +- src/shared/CMakeLists.txt | 18 + src/shared/common.h | 49 + src/shared/dbus.c | 452 +++++ src/shared/dbus.h | 239 +++ src/{libdeviced => shared}/deviced-internal.h | 6 +- src/{libdeviced => shared}/deviced-priv.h | 6 +- src/shared/list.h | 50 + src/{libdeviced => shared}/log-macro.h | 0 src/{libdeviced => shared}/log.h | 4 +- src/shared/score-defines.h | 31 + src/storage/storage.c | 454 +++++ src/storage/storage.conf | 7 + src/sys_event/CMakeLists.txt | 31 - src/sys_event/sys_event.c | 32 - src/sys_pci_noti/CMakeLists.txt | 30 - src/sys_pci_noti/po_sys_pci_noti/CMakeLists.txt | 24 - src/sys_pci_noti/po_sys_pci_noti/ar.po | 6 - src/sys_pci_noti/po_sys_pci_noti/az.po | 6 - src/sys_pci_noti/po_sys_pci_noti/bg.po | 6 - src/sys_pci_noti/po_sys_pci_noti/ca.po | 6 - src/sys_pci_noti/po_sys_pci_noti/cs.po | 6 - src/sys_pci_noti/po_sys_pci_noti/da.po | 6 - src/sys_pci_noti/po_sys_pci_noti/de_DE.po | 6 - src/sys_pci_noti/po_sys_pci_noti/el_GR.po | 6 - src/sys_pci_noti/po_sys_pci_noti/en.po | 6 - src/sys_pci_noti/po_sys_pci_noti/en_PH.po | 6 - src/sys_pci_noti/po_sys_pci_noti/en_US.po | 6 - src/sys_pci_noti/po_sys_pci_noti/es_ES.po | 6 - src/sys_pci_noti/po_sys_pci_noti/es_MX.po | 6 - src/sys_pci_noti/po_sys_pci_noti/es_US.po | 6 - src/sys_pci_noti/po_sys_pci_noti/et.po | 6 - src/sys_pci_noti/po_sys_pci_noti/eu.po | 6 - src/sys_pci_noti/po_sys_pci_noti/fi.po | 6 - src/sys_pci_noti/po_sys_pci_noti/fr_CA.po | 6 - src/sys_pci_noti/po_sys_pci_noti/fr_FR.po | 6 - src/sys_pci_noti/po_sys_pci_noti/ga.po | 6 - src/sys_pci_noti/po_sys_pci_noti/gl.po | 6 - src/sys_pci_noti/po_sys_pci_noti/hi.po | 6 - src/sys_pci_noti/po_sys_pci_noti/hr.po | 6 - src/sys_pci_noti/po_sys_pci_noti/hu.po | 6 - src/sys_pci_noti/po_sys_pci_noti/hy.po | 6 - src/sys_pci_noti/po_sys_pci_noti/is.po | 6 - src/sys_pci_noti/po_sys_pci_noti/it_IT.po | 6 - src/sys_pci_noti/po_sys_pci_noti/ja_JP.po | 6 - src/sys_pci_noti/po_sys_pci_noti/ka.po | 6 - src/sys_pci_noti/po_sys_pci_noti/kk.po | 6 - src/sys_pci_noti/po_sys_pci_noti/ko_KR.po | 6 - src/sys_pci_noti/po_sys_pci_noti/lt.po | 6 - src/sys_pci_noti/po_sys_pci_noti/lv.po | 6 - src/sys_pci_noti/po_sys_pci_noti/mk.po | 6 - src/sys_pci_noti/po_sys_pci_noti/nb.po | 6 - src/sys_pci_noti/po_sys_pci_noti/nl_NL.po | 6 - src/sys_pci_noti/po_sys_pci_noti/pl.po | 6 - src/sys_pci_noti/po_sys_pci_noti/pt_BR.po | 6 - src/sys_pci_noti/po_sys_pci_noti/pt_PT.po | 6 - src/sys_pci_noti/po_sys_pci_noti/ro.po | 6 - src/sys_pci_noti/po_sys_pci_noti/ru_RU.po | 6 - src/sys_pci_noti/po_sys_pci_noti/sk.po | 6 - src/sys_pci_noti/po_sys_pci_noti/sl.po | 6 - src/sys_pci_noti/po_sys_pci_noti/sr.po | 6 - src/sys_pci_noti/po_sys_pci_noti/sv.po | 6 - src/sys_pci_noti/po_sys_pci_noti/tr_TR.po | 6 - src/sys_pci_noti/po_sys_pci_noti/uk.po | 6 - src/sys_pci_noti/po_sys_pci_noti/uz.po | 6 - src/sys_pci_noti/po_sys_pci_noti/zh_CN.po | 6 - src/sys_pci_noti/po_sys_pci_noti/zh_HK.po | 6 - src/sys_pci_noti/po_sys_pci_noti/zh_SG.po | 6 - src/sys_pci_noti/po_sys_pci_noti/zh_TW.po | 6 - src/sys_pci_noti/sys_pci_noti.c | 86 - src/sys_pci_noti/sys_pci_noti.h | 40 - src/ta/ta-handler.c | 33 +- src/telephony/telephony.c | 423 ++++ src/time/time-handler.c | 59 +- src/usb/usb-handler.c | 3 +- src/vibrator/vibrator.c | 327 ---- 313 files changed, 19629 insertions(+), 12584 deletions(-) delete mode 100644 AUTHORS create mode 100644 README.error.code create mode 100755 src/CMakeLists.txt delete mode 100644 src/auto-test/CMakeLists.txt delete mode 100644 src/auto-test/test.c delete mode 100644 src/auto-test/test.h rename src/{display/battery.c => battery/battery-time.c} (82%) create mode 100644 src/battery/battery.conf rename src/{core/sysnoti.h => battery/battery.h} (54%) create mode 100644 src/battery/config.c rename src/{display/battery.h => battery/config.h} (57%) create mode 100644 src/core/config-parser.c rename src/{auto-test/main.c => core/config-parser.h} (51%) delete mode 100644 src/core/core.c create mode 100755 src/core/execute.c delete mode 100644 src/core/noti.c delete mode 100644 src/core/noti.h create mode 100644 src/core/power-supply.c create mode 100644 src/core/power-supply.h delete mode 100644 src/core/predefine.c delete mode 100644 src/core/predefine.h delete mode 100644 src/core/queue.c delete mode 100644 src/core/queue.h delete mode 100644 src/core/sysnoti.c create mode 100755 src/devicectl/CMakeLists.txt create mode 100644 src/devicectl/devicectl.c create mode 100644 src/devicectl/usb.c rename src/{core/core.h => devicectl/usb.h} (54%) rename src/{libdeviced/common.h => deviced/dd-common.h} (76%) create mode 100644 src/deviced/dd-mmc.h create mode 100644 src/deviced/dd-storage.h create mode 100644 src/deviced/dd-usbhost.h create mode 100644 src/deviced/deviced_doc.h create mode 100644 src/display/auto-brightness.c create mode 100644 src/display/brightness.c create mode 100644 src/display/brightness.h delete mode 100644 src/display/conf.c rename src/display/{llinterface.c => device-interface.c} (54%) rename src/display/{llinterface.h => device-interface.h} (63%) create mode 100644 src/display/display-actor.c create mode 100644 src/display/display-actor.h create mode 100644 src/display/display-mobile.conf create mode 100644 src/display/display-ops.c rename src/{libdeviced/dbus.h => display/display-ops.h} (51%) create mode 100644 src/display/display-wearable.conf create mode 100644 src/display/lock-detector.c create mode 100644 src/display/lock-detector.h delete mode 100644 src/display/lsensor.c delete mode 100644 src/display/util.c create mode 100644 src/earjack/earjack.c create mode 100644 src/gpio/buzzer.c create mode 100644 src/gpio/gpio.c create mode 100644 src/gpio/gpio.h create mode 100644 src/gpio/hall.c create mode 100644 src/gpio/sim.c create mode 100644 src/haptic/README.standard create mode 100644 src/haptic/emulator.c create mode 100644 src/haptic/external.c create mode 100644 src/haptic/haptic-micro.conf create mode 100644 src/haptic/haptic-mobile.conf rename src/{pm_event/pm_event.c => haptic/haptic.h} (50%) create mode 100644 src/haptic/standard.c create mode 100644 src/led/ir.c delete mode 100644 src/led/led.c create mode 100644 src/led/noti.c create mode 100644 src/led/torch.c rename src/{display/conf.h => led/torch.h} (80%) create mode 100644 src/libdeviced/mmc.c create mode 100644 src/libdeviced/storage.c create mode 100644 src/libdeviced/usbhost.c delete mode 100755 src/libdevman/TC/build.sh delete mode 100755 src/libdevman/TC/execute.sh delete mode 100644 src/libdevman/TC/tet_code delete mode 100644 src/libdevman/TC/tet_scen delete mode 100644 src/libdevman/TC/tetbuild.cfg delete mode 100644 src/libdevman/TC/tetclean.cfg delete mode 100644 src/libdevman/TC/tetexec.cfg delete mode 100644 src/libdevman/TC/unit/Makefile delete mode 100755 src/libdevman/TC/unit/tc_gen.sh delete mode 100644 src/libdevman/TC/unit/tslist delete mode 100644 src/libdevman/TC/unit/utc_MODULE_API_func.c.in delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_get_battery_pct_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_get_display_brt_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_get_display_gamma_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_get_max_brt_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_get_property_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_haptic_close_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_haptic_get_file_duration_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_haptic_get_pattern_duration_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_haptic_open_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_haptic_play_file_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_haptic_play_monotone_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_haptic_play_pattern_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_haptic_stop_play_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_is_battery_full_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_release_brt_ctrl_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_release_gamma_ctrl_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_set_display_brt_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_set_display_gamma_func.c delete mode 100644 src/libdevman/TC/unit/utc_SystemFW_device_set_property_func.c delete mode 100644 src/libdevman/image/SLP_devman_PG_architecture.png delete mode 100755 src/libhaptic/TC/build.sh delete mode 100755 src/libhaptic/TC/execute.sh delete mode 100644 src/libhaptic/TC/tet_code delete mode 100644 src/libhaptic/TC/tet_scen delete mode 100644 src/libhaptic/TC/tetbuild.cfg delete mode 100644 src/libhaptic/TC/tetclean.cfg delete mode 100644 src/libhaptic/TC/tetexec.cfg delete mode 100644 src/libhaptic/TC/unit/Makefile delete mode 100755 src/libhaptic/TC/unit/tc_gen.sh delete mode 100644 src/libhaptic/TC/unit/tslist delete mode 100644 src/libhaptic/TC/unit/utc_MODULE_API_func.c.in delete mode 100644 src/libhaptic/TC/unit/utc_SystemFW_haptic_close_func.c delete mode 100644 src/libhaptic/TC/unit/utc_SystemFW_haptic_get_file_duration_func.c delete mode 100644 src/libhaptic/TC/unit/utc_SystemFW_haptic_open_func.c delete mode 100644 src/libhaptic/TC/unit/utc_SystemFW_haptic_play_file_func.c delete mode 100644 src/libhaptic/TC/unit/utc_SystemFW_haptic_play_monotone_func.c delete mode 100644 src/libhaptic/TC/unit/utc_SystemFW_haptic_stop_play_func.c delete mode 100644 src/libhaptic/image/SLP_devman_PG_haptic_architecture.png delete mode 100755 src/libslp-pm/TC/build.sh delete mode 100755 src/libslp-pm/TC/execute.sh delete mode 100755 src/libslp-pm/TC/tet_code delete mode 100755 src/libslp-pm/TC/tet_scen delete mode 100755 src/libslp-pm/TC/tetbuild.cfg delete mode 100755 src/libslp-pm/TC/tetclean.cfg delete mode 100755 src/libslp-pm/TC/tetexec.cfg delete mode 100644 src/libslp-pm/TC/unit/Makefile delete mode 100755 src/libslp-pm/TC/unit/tc_gen.sh delete mode 100644 src/libslp-pm/TC/unit/tslist delete mode 100644 src/libslp-pm/TC/unit/utc_MODULE_API_func.c.in delete mode 100644 src/libslp-pm/TC/unit/utc_SystemFW_pm_change_state_func.c delete mode 100644 src/libslp-pm/TC/unit/utc_SystemFW_pm_lock_state_func.c delete mode 100644 src/libslp-pm/TC/unit/utc_SystemFW_pm_unlock_state_func.c delete mode 100755 src/libslp-pm/image/SLP_pm_PG_architecture.png delete mode 100755 src/libslp-pm/image/SLP_pm_PG_state_diagram.png delete mode 100755 src/libsysman/TC/build.sh delete mode 100755 src/libsysman/TC/execute.sh delete mode 100644 src/libsysman/TC/tet_code delete mode 100644 src/libsysman/TC/tet_scen delete mode 100644 src/libsysman/TC/tetbuild.cfg delete mode 100644 src/libsysman/TC/tetclean.cfg delete mode 100644 src/libsysman/TC/tetexec.cfg delete mode 100644 src/libsysman/TC/unit/Makefile delete mode 100755 src/libsysman/TC/unit/tc_gen.sh delete mode 100644 src/libsysman/TC/unit/tslist delete mode 100644 src/libsysman/TC/unit/utc_MODULE_API_func.c.in delete mode 100644 src/libsysman/TC/unit/utc_SystemFW_sysconf_is_vip_func.c delete mode 100644 src/libsysman/TC/unit/utc_SystemFW_sysconf_set_mempolicy_bypid_func.c delete mode 100644 src/libsysman/TC/unit/utc_SystemFW_sysconf_set_mempolicy_func.c delete mode 100644 src/libsysman/TC/unit/utc_SystemFW_sysconf_set_permanent_bypid_func.c delete mode 100644 src/libsysman/TC/unit/utc_SystemFW_sysconf_set_permanent_func.c delete mode 100644 src/libsysman/TC/unit/utc_SystemFW_sysconf_set_vip_func.c delete mode 100644 src/libsysman/TC/unit/utc_SystemFW_sysman_get_apppath_func.c delete mode 100644 src/libsysman/TC/unit/utc_SystemFW_sysman_get_cmdline_name_func.c delete mode 100644 src/libsysman/TC/unit/utc_SystemFW_sysman_get_pid_func.c delete mode 100644 src/libsysman/TC/unit/utc_SystemFW_sysman_set_datetime_func.c create mode 100644 src/mmc/config.c rename src/{core/data.h => mmc/config.h} (74%) create mode 100644 src/mmc/mmc.conf create mode 100644 src/mmc/uevent.c create mode 100644 src/newfs-msdos/CMakeLists.txt create mode 100644 src/newfs-msdos/LICENSE create mode 100644 src/newfs-msdos/newfs-msdos.c delete mode 100755 src/pm_event/CMakeLists.txt mode change 100755 => 100644 src/power/power-handler.c create mode 100644 src/power/power-handler.h create mode 100644 src/proc/cpu-info.c delete mode 100644 src/proc/lowmem-handler.c create mode 100755 src/shared/CMakeLists.txt create mode 100644 src/shared/common.h create mode 100644 src/shared/dbus.c create mode 100644 src/shared/dbus.h rename src/{libdeviced => shared}/deviced-internal.h (88%) rename src/{libdeviced => shared}/deviced-priv.h (91%) create mode 100644 src/shared/list.h rename src/{libdeviced => shared}/log-macro.h (100%) rename src/{libdeviced => shared}/log.h (92%) create mode 100644 src/shared/score-defines.h create mode 100755 src/storage/storage.c create mode 100644 src/storage/storage.conf delete mode 100644 src/sys_event/CMakeLists.txt delete mode 100644 src/sys_event/sys_event.c delete mode 100755 src/sys_pci_noti/CMakeLists.txt delete mode 100644 src/sys_pci_noti/po_sys_pci_noti/CMakeLists.txt delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/ar.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/az.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/bg.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/ca.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/cs.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/da.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/de_DE.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/el_GR.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/en.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/en_PH.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/en_US.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/es_ES.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/es_MX.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/es_US.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/et.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/eu.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/fi.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/fr_CA.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/fr_FR.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/ga.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/gl.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/hi.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/hr.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/hu.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/hy.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/is.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/it_IT.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/ja_JP.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/ka.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/kk.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/ko_KR.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/lt.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/lv.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/mk.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/nb.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/nl_NL.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/pl.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/pt_BR.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/pt_PT.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/ro.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/ru_RU.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/sk.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/sl.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/sr.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/sv.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/tr_TR.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/uk.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/uz.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/zh_CN.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/zh_HK.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/zh_SG.po delete mode 100755 src/sys_pci_noti/po_sys_pci_noti/zh_TW.po delete mode 100755 src/sys_pci_noti/sys_pci_noti.c delete mode 100755 src/sys_pci_noti/sys_pci_noti.h create mode 100644 src/telephony/telephony.c delete mode 100644 src/vibrator/vibrator.c diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index 6edd069..0000000 --- a/AUTHORS +++ /dev/null @@ -1,2 +0,0 @@ -Giyeol Ok -Taesoo Jun diff --git a/CMakeLists.txt b/CMakeLists.txt index 140ee35..a394339 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,37 +22,45 @@ SET(CONFDIR "/etc/${PROJECT_NAME}") SET(VERSION 0.1.0) SET(SRCS + src/battery/battery-time.c + src/battery/config.c src/battery/lowbat-handler.c - src/bs/bs.c + src/core/common.c + src/core/config-parser.c + src/core/device-change-handler.c src/core/device-notifier.c - src/core/main.c - src/core/sysnoti.c - src/core/launch.c - src/core/queue.c - src/core/core.c src/core/devices.c - src/core/sig-handler.c - src/core/log.c - src/core/device-change-handler.c - src/core/predefine.c - src/core/noti.c - src/core/common.c src/core/edbus-handler.c - src/cpu/cpu-handler.c - src/mmc/mmc-handler.c - src/mmc/vfat.c - src/power/power-handler.c - src/proc/lowmem-handler.c - src/proc/pmon-handler.c + src/core/execute.c + src/core/launch.c + src/core/log.c + src/core/main.c + src/core/power-supply.c + src/core/sig-handler.c + src/earjack/earjack.c + src/proc/cpu-info.c src/proc/proc-handler.c src/ta/ta-handler.c src/time/time-handler.c src/usb/usb-handler.c - src/vibrator/vibrator.c ) SET(SRCS ${SRCS} - src/apps/apps.c + src/gpio/gpio.c + src/gpio/buzzer.c + src/gpio/hall.c + src/gpio/sim.c +) + +SET(SRCS ${SRCS} + src/power/power-handler.c +) + +SET(SRCS ${SRCS} + src/mmc/config.c + src/mmc/mmc-handler.c + src/mmc/uevent.c + src/mmc/vfat.c ) FIND_PROGRAM(UNAME NAMES uname) @@ -64,46 +72,48 @@ SET(SRCS ${SRCS} ENDIF(USE_EMULATOR) SET(SRCS ${SRCS} - src/display/util.c - src/display/llinterface.c - src/display/conf.c - src/display/setting.c - src/display/poll.c + src/display/auto-brightness.c + src/display/brightness.c src/display/core.c + src/display/device-interface.c + src/display/display-actor.c src/display/display-dbus.c - src/display/lsensor.c + src/display/display-ops.c src/display/key-filter.c - src/display/battery.c) + src/display/lock-detector.c + src/display/poll.c + src/display/setting.c +) SET(SRCS ${SRCS} - src/led/led.c) + src/led/ir.c + src/led/noti.c + src/led/torch.c +) SET(SRCS ${SRCS} src/control/control.c) SET(SRCS ${SRCS} - src/haptic/haptic.c) + src/haptic/haptic.c + src/haptic/external.c + src/haptic/standard.c + src/haptic/emulator.c) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/sysman) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced ${CMAKE_CURRENT_SOURCE_DIR}/src/proc) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced) SET(PKG_MODULES ecore - ecore-file edbus eina vconf - heynoti - tapi dlog - syspopup-caller device-node + capi-base-common sensor - notification - libsmack - libsystemd-daemon + tapi libtzplatform-config ) @@ -120,29 +130,33 @@ FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Werror") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt") +MESSAGE("FLAGS: ${CMAKE_C_FLAGS}") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") +ADD_DEFINITIONS("-DLIBDIR=\"${LIBDIR}\"") ADD_DEFINITIONS("-DENABLE_KEY_FILTER") ADD_DEFINITIONS("-DENABLE_X_LCD_ONOFF") -ADD_DEFINITIONS("-DENABLE_CRASHD_DLOG") ADD_DEFINITIONS("-DENABLE_DEVICED_DLOG") ADD_DEFINITIONS("-DENABLE_LIBDEVICED_DLOG") ADD_DEFINITIONS("-DENABLE_PM_LOG") IF(USE_ARM) ADD_DEFINITIONS("-DTARGET") +ELSEIF(USE_EMULATOR) + ADD_DEFINITIONS("-DEMULATOR") ENDIF() ADD_DEFINITIONS("-DDEBUG") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl" "-lm" "-ludev") +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl" "-lm" "-ludev" "-ledbus" shared) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/deviced/ DESTINATION include/${PROJECT_NAME} FILES_MATCHING + PATTERN "*_doc.h" EXCLUDE PATTERN "*.h") CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) @@ -161,14 +175,12 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/s PATTERN "*.service" PATTERN "*.socket") +ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(src/libdeviced) -ADD_SUBDIRECTORY(src/restarter) -ADD_SUBDIRECTORY(src/sys_event) -ADD_SUBDIRECTORY(src/pm_event) -ADD_SUBDIRECTORY(src/sys_pci_noti) +ADD_SUBDIRECTORY(src/fsck-msdos) +ADD_SUBDIRECTORY(src/newfs-msdos) +ADD_SUBDIRECTORY(src/devicectl) ADD_SUBDIRECTORY(src/libsysman) ADD_SUBDIRECTORY(src/libslp-pm) ADD_SUBDIRECTORY(src/libhaptic) ADD_SUBDIRECTORY(src/libdevman) -ADD_SUBDIRECTORY(src/fsck-msdos) -ADD_SUBDIRECTORY(src/auto-test) diff --git a/LICENSE.Apache-2.0 b/LICENSE.Apache-2.0 index d645695..8f17f50 100644 --- a/LICENSE.Apache-2.0 +++ b/LICENSE.Apache-2.0 @@ -1,3 +1,4 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. Apache License Version 2.0, January 2004 @@ -200,3 +201,4 @@ 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. + diff --git a/NOTICE b/NOTICE index 7aad3b0..dc3f273 100644 --- a/NOTICE +++ b/NOTICE @@ -1,3 +1,4 @@ +Copyright (c) The Android Open Source Project Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. -Except as noted, This software is licensed under Apache License, Version 2. +Except as noted, this software is licensed under Apache License, Version 2. Please, see the LICENSE.Apache-2.0 file for Apache License terms and conditions. diff --git a/README.error.code b/README.error.code new file mode 100644 index 0000000..61cd9c6 --- /dev/null +++ b/README.error.code @@ -0,0 +1,9 @@ +DBus Error note + +Functions Defines Values +====================================================================== +dbus_bus_get EPERM 1 +dbus_message_get_args ENOMSG 42 +dbus_connection_send_with_reply_and_block ECOMM 70 +dbus_connection_send ECOMM 70 +dbus_message_new_method_call EBADMSG 74 diff --git a/deviced.pc.in b/deviced.pc.in index dac0fcc..6ce4c9b 100644 --- a/deviced.pc.in +++ b/deviced.pc.in @@ -2,10 +2,10 @@ prefix=@PREFIX@ exec_prefix=@EXEC_PREFIX@ -libdir=@LIBDIR@ +libdir=/usr/lib includedir=/usr/include/deviced -Name: deviced library +Name: deviced Description: Tizen platform device control library Version: @VERSION@ Requires: diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 93fbb86..01818b3 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -17,7 +17,6 @@ Source6: devman.manifest BuildRequires: cmake BuildRequires: libattr-devel BuildRequires: pkgconfig(ecore) -BuildRequires: pkgconfig(heynoti) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(edbus) @@ -26,8 +25,6 @@ BuildRequires: pkgconfig(syspopup-caller) %if %{with x} BuildRequires: pkgconfig(x11) %endif -BuildRequires: pkgconfig(notification) -BuildRequires: pkgconfig(usbutils) BuildRequires: pkgconfig(udev) BuildRequires: pkgconfig(device-node) BuildRequires: pkgconfig(libsmack) @@ -35,6 +32,7 @@ BuildRequires: pkgconfig(sensor) BuildRequires: gettext BuildRequires: pkgconfig(libsystemd-daemon) BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(libtzplatform-config) %{?systemd_requires} @@ -195,10 +193,6 @@ rm -rf %{buildroot} %install_service graphical.target.wants zbooting-done.service %install_service graphical.target.wants devicectl-stop@.service -%if 0%{?simulator} -rm -f %{buildroot}%{_bindir}/restart -%endif - %post #memory type vconf key init users_gid=$(getent group $TZ_SYS_USER_GROUP | cut -f3 -d':') @@ -239,20 +233,6 @@ vconftool set -t int memory/pm/custom_brightness_status 0 -i -g $users_gid vconftool set -t bool memory/pm/brt_changed_lpm 0 -i vconftool set -t int memory/pm/current_brt 60 -i -g $users_gid -heynotitool set system_wakeup -heynotitool set pm_event - -heynotitool set power_off_start - -heynotitool set mmcblk_add -heynotitool set mmcblk_remove -heynotitool set device_charge_chgdet -heynotitool set device_usb_host_add -heynotitool set device_usb_host_remove -heynotitool set device_pci_keyboard_add -heynotitool set device_pci_keyboard_remove - - systemctl daemon-reload if [ "$1" == "1" ]; then systemctl restart deviced.service @@ -296,20 +276,16 @@ systemctl daemon-reload %config %{_sysconfdir}/dbus-1/system.d/deviced.conf %{_bindir}/deviced-pre.sh %{_bindir}/deviced -%if %{undefined simulator} -%{_bindir}/restart -%endif +%{_bindir}/devicectl %{_bindir}/movi_format.sh %{_bindir}/mmc-smack-label %{_bindir}/fsck_msdosfs +%{_bindir}/newfs_msdos %{_datadir}/license/fsck_msdosfs -%{_bindir}/sys_event -%{_bindir}/pm_event +%{_datadir}/license/newfs_msdos %{_bindir}/regpmon %{_bindir}/set_pmon %{_bindir}/pmon -%{_bindir}/sys_pci_noti -%{_bindir}/deviced-auto-test %{_unitdir}/multi-user.target.wants/deviced.service %{_unitdir}/sockets.target.wants/deviced.socket %{_unitdir}/graphical.target.wants/zbooting-done.service @@ -320,7 +296,6 @@ systemctl daemon-reload %{_unitdir}/zbooting-done.service %{_unitdir}/devicectl-start@.service %{_unitdir}/devicectl-stop@.service -%{_datadir}/deviced/sys_pci_noti/res/locale/*/LC_MESSAGES/*.mo %files -n libdeviced %defattr(-,root,root,-) diff --git a/scripts/deviced-pre.sh b/scripts/deviced-pre.sh index 85850be..f714a95 100755 --- a/scripts/deviced-pre.sh +++ b/scripts/deviced-pre.sh @@ -31,24 +31,9 @@ for file in /sys/class/input/event*; do fi done -for file in /sys/class/lcd/*; do - if [ -e $file ]; then - hbm_state=`/bin/cat ${file}/device/hbm` - if [ "$hbm_state" != 0 ]; then - HBM_NODE=${file}/device/hbm - fi - alpm_state=`/bin/cat ${file}/device/alpm` - if [ "$alpm_state" != 0 ]; then - ALPM_NODE=${file}/device/alpm - fi - fi -done - echo "PM_INPUT=$DEV_INPUT" >> $DEVICED_ENV_F echo "PM_TOUCHSCREEN=$DEV_TOUCHSCREEN" >> $DEVICED_ENV_F echo "PM_TOUCHKEY=$DEV_TOUCHKEY" >> $DEVICED_ENV_F -echo "HBM_NODE=$HBM_NODE" >> $DEVICED_ENV_F -echo "ALPM_NODE=$ALPM_NODE" >> $DEVICED_ENV_F echo "PM_TO_NORMAL=30000" >> $DEVICED_ENV_F echo "PM_TO_LCDDIM=5000" >> $DEVICED_ENV_F echo "PM_SYS_DIMBRT=0" >> $DEVICED_ENV_F diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100755 index 0000000..c17e8b8 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,3 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +ADD_SUBDIRECTORY(shared) diff --git a/src/apps/apps.c b/src/apps/apps.c index 1560d1e..a4d1530 100644 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -43,6 +43,11 @@ static void apps_init(void *data) static int initialized =0; if (!initialized) { + DD_LIST_FOREACH(apps_head, elem, dev) { + _D("[%s] initialize", dev->name); + if (dev->init) + dev->init(); + } initialized = 1; return; } diff --git a/src/apps/apps.h b/src/apps/apps.h index 8dd93d9..eb01510 100644 --- a/src/apps/apps.h +++ b/src/apps/apps.h @@ -22,7 +22,11 @@ #include "core/edbus-handler.h" #include "core/common.h" -#include "core/data.h" + +enum apps_enable_type{ + APPS_DISABLE = 0, + APPS_ENABLE = 1, +}; #define APPS_OPS_REGISTER(dev) \ static void __CONSTRUCTOR__ module_init(void) \ diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt deleted file mode 100644 index a3e0d18..0000000 --- a/src/auto-test/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(deviced-auto-test C) - -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) - -SET(SRCS - test.c - main.c -) - -INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED edbus) - -FOREACH(flag ${pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") -MESSAGE("FLAGS: ${CMAKE_C_FLAGS}") - -IF("$ENV{CFLAGS}" MATCHES "-DMICRO_DD") - OPTION(USE_MICRO_DD "Use Micro DD" ON) -ENDIF() - -ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") -ADD_DEFINITIONS("-DENABLE_TEST_DLOG") - -ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} libdeviced) - -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/src/auto-test/test.c b/src/auto-test/test.c deleted file mode 100644 index 7066feb..0000000 --- a/src/auto-test/test.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * test - * - * Copyright (c) 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 "test.h" - -static dd_list *dd_head; - -void add_test(const struct test_ops *d) -{ - if (d->priority == TEST_PRIORITY_HIGH) - DD_LIST_PREPEND(dd_head, d); - else - DD_LIST_APPEND(dd_head, d); -} - -void remove_test(const struct test_ops *d) -{ - DD_LIST_REMOVE(dd_head, d); -} - -const struct test_ops *find_test(const char *name) -{ - dd_list *elem; - const struct test_ops *d; - - DD_LIST_FOREACH(dd_head, elem, d) { - if (!strcmp(d->name, name)) - return d; - } - return NULL; -} - -void test_init(void *data) -{ - dd_list *elem; - const struct test_ops *d; - - DD_LIST_FOREACH(dd_head, elem, d) { - _D("[%s] initialize", d->name); - if (d->init) - d->init(data); - } -} - -void test_exit(void *data) -{ - dd_list *elem; - const struct test_ops *d; - - DD_LIST_FOREACH(dd_head, elem, d) { - _D("[%s] deinitialize", d->name); - if (d->exit) - d->exit(data); - } -} diff --git a/src/auto-test/test.h b/src/auto-test/test.h deleted file mode 100644 index 5b89b77..0000000 --- a/src/auto-test/test.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * test - * - * Copyright (c) 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 __TEST_H__ -#define __TEST_H__ -#include -#include - -#include "core/list.h" -#include "core/common.h" -#include "libdeviced/dbus.h" - -#ifdef ENABLE_TEST_DLOG -#define ENABLE_DLOG -#endif - -#define LOG_TAG "AUTO_TEST" -#include "libdeviced/log-macro.h" - -enum test_priority { - TEST_PRIORITY_NORMAL = 0, - TEST_PRIORITY_HIGH, -}; - -struct test_ops { - enum test_priority priority; - char *name; - void (*init) (void *data); - void (*exit) (void *data); - int (*start) (void); - int (*stop) (void); - int (*status) (void); -}; - -enum test_ops_status { - TEST_OPS_STATUS_UNINIT, - TEST_OPS_STATUS_START, - TEST_OPS_STATUS_STOP, - TEST_OPS_STATUS_MAX, -}; - -void test_init(void *data); -void test_exit(void *data); - -static inline int test_start(const struct test_ops *c) -{ - if (c && c->start) - return c->start(); - - return -EINVAL; -} - -static inline int test_stop(const struct test_ops *c) -{ - if (c && c->stop) - return c->stop(); - - return -EINVAL; -} - -static inline int test_get_status(const struct test_ops *c) -{ - if (c && c->status) - return c->status(); - - return -EINVAL; -} - -#define TEST_OPS_REGISTER(c) \ -static void __CONSTRUCTOR__ module_init(void) \ -{ \ - add_test(c); \ -} \ -static void __DESTRUCTOR__ module_exit(void) \ -{ \ - remove_test(c); \ -} -DBusMessage *deviced_dbus_method_sync_with_reply(const char *dest, const char *path, - const char *interface, const char *method, - const char *sig, char *param[]); -void add_test(const struct test_ops *c); -void remove_test(const struct test_ops *c); -const struct test_ops *find_test(const char *name); - -#endif diff --git a/src/display/battery.c b/src/battery/battery-time.c similarity index 82% rename from src/display/battery.c rename to src/battery/battery-time.c index 7edd2ff..3759949 100644 --- a/src/display/battery.c +++ b/src/battery/battery-time.c @@ -21,10 +21,12 @@ #include #include #include +#include +#include -#include "util.h" -#include "core.h" -#include "battery.h" +#include "core/common.h" +#include "core/devices.h" +#include "core/log.h" #define CHARGING_STATE(x) ((x) & CHRGR_FLAG) #define FULL_CAPACITY_RAW (10000) @@ -33,8 +35,9 @@ #define MAX_COUNT_UNCHARGING (10) #define MAX_COUNT_CHARGING (10) #define PRINT_ALL_BATT_NODE(x) /*print_all_batt_node(x)*/ +#define POLLING_TIME (30) /* seconds */ -int (*get_battery_capacity)(); +int (*get_battery_capacity_cb)(void); enum state_b { B_UNCHARGING = 0, @@ -56,7 +59,6 @@ enum state_a { }; static Ecore_Timer *timeout_id = NULL; -static int noti_fd = 0; static Batt_node *batt_head[B_END]; static Batt_node *batt_tail[B_END]; @@ -68,6 +70,57 @@ static int charging_state = 0; static int multiply_value[B_END] = {-1, 1}; extern int system_wakeup_flag; +static int get_battery_capacity(void) +{ + int value = 0; + int ret = -1; + + ret = device_get_property(DEVICE_TYPE_POWER, + PROP_POWER_CAPACITY, &value); + + if (ret < 0) + return ret; + + if (value < 0) + return 0; + + return value; +} + +static int get_battery_capacity_raw(void) +{ + int value = 0; + int ret = -1; + + ret = device_get_property(DEVICE_TYPE_POWER, + PROP_POWER_CAPACITY_RAW, &value); + + if (ret < 0) + return ret; + + if (value < 0) + return 0; + + return value; +} + +static int get_battery_charge_full(void) +{ + int value = 0; + int ret = -1; + + ret = device_get_property(DEVICE_TYPE_POWER, + PROP_POWER_CHARGE_FULL, &value); + + if (ret < 0) + return ret; + + if (value < 0) + return 0; + + return value; +} + static void print_all_batt_node(enum state_b b_index) { Batt_node *node = NULL; @@ -273,14 +326,14 @@ static void update_time(enum state_a a_index, int seconds) } } -int battinfo_calculation(void) +static int battinfo_calculation(void) { time_t clock; int capacity = 0; int estimated_time = 0; int tmp = 0; - capacity = get_battery_capacity(); + capacity = get_battery_capacity_cb(); if(capacity <= 0) return -1; @@ -297,7 +350,7 @@ int battinfo_calculation(void) del_all_batt_node(B_UNCHARGING); if((capacity * 100 / full_capacity) >= BATTERY_FULL_THRESHOLD) { - if(battery_ops.get_charge_full()) { + if (get_battery_charge_full()) { del_all_batt_node(B_CHARGING); _I("battery fully charged!"); update_time(A_TIMETOFULL, 0); @@ -341,17 +394,17 @@ static int init_battery_func(void) { int ret = -1; - ret = battery_ops.get_capacity_raw(); + ret = get_battery_capacity_raw(); if(ret >= 0) { - get_battery_capacity = battery_ops.get_capacity_raw; + get_battery_capacity_cb = get_battery_capacity_raw; full_capacity = FULL_CAPACITY_RAW; _I("init_battery_func : full capacity(%d)", full_capacity); return 0; } - ret = battery_ops.get_capacity(); + ret = get_battery_capacity(); if(ret >= 0) { - get_battery_capacity = battery_ops.get_capacity; + get_battery_capacity_cb = get_battery_capacity; full_capacity = FULL_CAPACITY; _I("init_battery_func : full capacity(%d)", full_capacity); return 0; @@ -361,13 +414,13 @@ static int init_battery_func(void) return -1; } -int start_battinfo_gathering(int timeout) +static int start_battinfo_gathering(int timeout) { int ret; _I("Start battery gathering!"); - if(timeout < 0) { + if(timeout <= 0) { _E("invalid timeout value [%d]!", timeout); return -1; } @@ -381,30 +434,12 @@ int start_battinfo_gathering(int timeout) /* Using g_timer for gathering battery info */ timeout_id = ecore_timer_add(timeout, (Ecore_Task_Cb)battinfo_cb, NULL); - } else if(timeout == 0) { - /* Using heynoti from system-server(udev) - for gathering battery info */ - if((noti_fd = heynoti_init()) < 0) { - _E("heynoti init failed!"); - return -1; - } - ret = heynoti_subscribe(noti_fd, "device_charge_chgdet", - (void *)battinfo_calculation, (void *)NULL); - if(ret != 0) { - _E("heynoti subscribe fail!"); - return -1; - } - - ret = heynoti_attach_handler(noti_fd); - if(ret != 0) { - _E("heynoti attach handler fail!"); - return -1; - } } + return 0; } -void end_battinfo_gathering(void) +static void end_battinfo_gathering(void) { _I("End battery gathering!"); @@ -412,12 +447,27 @@ void end_battinfo_gathering(void) ecore_timer_del(timeout_id); timeout_id = NULL; } - if (noti_fd > 0) { - heynoti_close(noti_fd); - noti_fd = 0; - } del_all_batt_node(B_UNCHARGING); del_all_batt_node(B_CHARGING); } +static void battery_init(void *data) +{ + start_battinfo_gathering(POLLING_TIME); +} + +static void battery_exit(void *data) +{ + end_battinfo_gathering(); +} + +static const struct device_ops battery_time_device_ops = { + .priority = DEVICE_PRIORITY_NORMAL, + .name = "battery-time", + .init = battery_init, + .exit = battery_exit, +}; + +DEVICE_OPS_REGISTER(&battery_time_device_ops) + diff --git a/src/battery/battery.conf b/src/battery/battery.conf new file mode 100644 index 0000000..48402cc --- /dev/null +++ b/src/battery/battery.conf @@ -0,0 +1,7 @@ +[LOWBAT] +#low battery level +Normal=100 +Warning=15 +Critical=5 +PowerOff=1 +RealOff=0 diff --git a/src/core/sysnoti.h b/src/battery/battery.h similarity index 54% rename from src/core/sysnoti.h rename to src/battery/battery.h index f2cd853..b1828bd 100644 --- a/src/core/sysnoti.h +++ b/src/battery/battery.h @@ -17,18 +17,27 @@ */ -#ifndef __SS_SYSNOTI_H__ -#define __SS_SYSNOTI_H__ +#ifndef __BATTERY_H__ +#define __BATTERY_H__ -#define SYSMAN_MAXARG 16 +#define BATTERY_LEVEL_CHECK_FULL 95 +#define BATTERY_LEVEL_CHECK_HIGH 15 +#define BATTERY_LEVEL_CHECK_LOW 5 +#define BATTERY_LEVEL_CHECK_CRITICAL 1 -struct sysnoti { - int pid; - int cmd; - char *type; - char *path; - int argc; - char *argv[SYSMAN_MAXARG]; +#define LOWBAT_OPT_WARNING 1 +#define LOWBAT_OPT_POWEROFF 2 +#define LOWBAT_OPT_CHARGEERR 3 +#define LOWBAT_OPT_CHECK 4 + +struct battery_config_info { + int normal; + int warning; + int critical; + int poweroff; + int realoff; }; -#endif /* __SS_SYSNOTI_H__ */ +int battery_charge_err_low_act(void *data); +int battery_charge_err_high_act(void *data); +#endif /* __BATTERY_H__ */ diff --git a/src/battery/config.c b/src/battery/config.c new file mode 100644 index 0000000..4dd42c1 --- /dev/null +++ b/src/battery/config.c @@ -0,0 +1,73 @@ +/* + * deviced + * + * Copyright (c) 2014 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 +#include +#include +#include +#include +#include +#include + +#include "core/log.h" +#include "core/common.h" +#include "core/config-parser.h" +#include "battery.h" +#include "config.h" + +#define BAT_CONF_FILE "/etc/deviced/battery.conf" + +static int load_config(struct parse_result *result, void *user_data) +{ + struct battery_config_info *info = user_data; + char *name; + char *value; + + _D("%s,%s,%s", result->section, result->name, result->value); + + if (!info) + return -EINVAL; + + if (!MATCH(result->section, "LOWBAT")) + return -EINVAL; + + name = result->name; + value = result->value; + if (MATCH(name, "Normal")) + info->normal = atoi(value); + else if (MATCH(name, "Warning")) + info->warning = atoi(value); + else if (MATCH(name, "Critical")) + info->critical = atoi(value); + else if (MATCH(name, "PowerOff")) + info->poweroff = atoi(value); + else if (MATCH(name, "RealOff")) + info->realoff = atoi(value); + + return 0; +} + +void battery_config_load(struct battery_config_info *info) +{ + int ret; + + ret = config_parse(BAT_CONF_FILE, load_config, info); + if (ret < 0) + _E("Failed to load %s, %d Use default value!", BAT_CONF_FILE, ret); +} diff --git a/src/display/battery.h b/src/battery/config.h similarity index 57% rename from src/display/battery.h rename to src/battery/config.h index c5156fc..6acd38f 100644 --- a/src/display/battery.h +++ b/src/battery/config.h @@ -1,7 +1,7 @@ /* * deviced * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * Copyright (c) 2014 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. @@ -17,12 +17,19 @@ */ -#ifndef __PM_BATTERY_H_ -#define __PM_BATTERY_H_ - -#define BATTERY_POLLING_PERIOD 30 /* second */ - -int start_battinfo_gathering(int timeout); -void end_battinfo_gathering(); +#ifndef __BATTERY_CONFIG_H__ +#define __BATTERY_CONFIG_H__ +#define BATTERY_FULL 100 +#define BATTERY_NORMAL BATTERY_FULL +#define BATTERY_WARNING 15 +#define BATTERY_CRITICAL 5 +#ifdef MICRO_DD +#define BATTERY_POWEROFF 3 +#else +#define BATTERY_POWEROFF 1 #endif +#define BATTERY_REALOFF 0 + +void battery_config_load(struct battery_config_info *info); +#endif /* __BATTERY_CONFIG_H__ */ diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index c14859c..7d9bb93 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -20,48 +20,31 @@ #include #include #include -#include #include #include -#include +#include "battery.h" +#include "config.h" #include "core/log.h" #include "core/launch.h" -#include "core/noti.h" -#include "core/queue.h" -#include "core/data.h" #include "core/devices.h" #include "core/device-handler.h" +#include "core/device-notifier.h" #include "core/common.h" +#include "core/list.h" #include "device-node.h" #include "display/setting.h" +#include "display/poll.h" +#include "core/edbus-handler.h" +#include "core/power-supply.h" +#include "power/power-handler.h" -#define PREDEF_LOWBAT "lowbat" +#define CHARGE_POWERSAVE_FREQ_ACT "charge_powersave_freq_act" +#define CHARGE_RELEASE_FREQ_ACT "charge_release_freq_act" -#define BAT_MON_INTERVAL 30 -#define BAT_MON_INTERVAL_MIN 2 -#define BATTERY_CHARGING 65535 +#define BATTERY_CHARGING 65535 #define BATTERY_UNKNOWN -1 -#define BATTERY_FULL 100 -#define BATTERY_NORMAL 100 -#define BATTERY_WARNING_LOW 15 -#define BATTERY_CRITICAL_LOW 5 -#define BATTERY_POWER_OFF 1 -#define BATTERY_REAL_POWER_OFF 0 - -#define MAX_BATTERY_ERROR 10 -#define RESET_RETRY_COUNT 3 - -#define BATTERY_LEVEL_CHECK_FULL 95 -#define BATTERY_LEVEL_CHECK_HIGH 15 -#define BATTERY_LEVEL_CHECK_LOW 5 -#define BATTERY_LEVEL_CHECK_CRITICAL 1 - -#define LOWBAT_OPT_WARNING 1 -#define LOWBAT_OPT_POWEROFF 2 -#define LOWBAT_OPT_CHARGEERR 3 -#define LOWBAT_OPT_CHECK 4 #define WARNING_LOW_BAT_ACT "warning_low_bat_act" #define CRITICAL_LOW_BAT_ACT "critical_low_bat_act" @@ -69,46 +52,100 @@ #define CHARGE_BAT_ACT "charge_bat_act" #define CHARGE_CHECK_ACT "charge_check_act" #define CHARGE_ERROR_ACT "charge_error_act" +#define CHARGE_ERROR_LOW_ACT "charge_error_low_act" +#define CHARGE_ERROR_HIGH_ACT "charge_error_high_act" +#define CHARGE_ERROR_OVP_ACT "charge_error_ovp_act" +#define WAITING_INTERVAL 10 -#define _SYS_LOW_POWER "LOW_POWER" +#define LOWBAT_CPU_CTRL_ID "id6" +#define LOWBAT_CPU_FREQ_RATE (0.7) -#define WAITING_INTERVAL 10 +#define LOWBAT_POPUP_NAME "lowbat-syspopup" +#define LOWBAT_EXEC_PATH PREFIX"/bin/lowbatt-popup" + +struct popup_data { + char *name; + char *key; + char *value; +}; struct lowbat_process_entry { - unsigned cur_bat_state; - unsigned new_bat_state; - int (*action) (void *); + int old; + int now; + int (*func) (void *data); }; -static Ecore_Timer *lowbat_timer; static int cur_bat_state = BATTERY_UNKNOWN; static int cur_bat_capacity = -1; -static int bat_err_count = 0; - -static Ecore_Timer *lowbat_popup_id = NULL; static int lowbat_popup_option = 0; - -int battery_warning_low_act(void *ad); -int battery_critical_low_act(void *ad); -int battery_power_off_act(void *ad); - -static struct lowbat_process_entry lpe[] = { - {BATTERY_NORMAL, BATTERY_WARNING_LOW, battery_warning_low_act}, - {BATTERY_WARNING_LOW, BATTERY_CRITICAL_LOW, battery_critical_low_act}, - {BATTERY_CRITICAL_LOW, BATTERY_POWER_OFF, battery_critical_low_act}, - {BATTERY_POWER_OFF, BATTERY_REAL_POWER_OFF, battery_power_off_act}, - {BATTERY_NORMAL, BATTERY_CRITICAL_LOW, battery_critical_low_act}, - {BATTERY_WARNING_LOW, BATTERY_POWER_OFF, battery_critical_low_act}, - {BATTERY_CRITICAL_LOW, BATTERY_REAL_POWER_OFF, battery_power_off_act}, - {BATTERY_NORMAL, BATTERY_POWER_OFF, battery_critical_low_act}, - {BATTERY_WARNING_LOW, BATTERY_REAL_POWER_OFF, battery_power_off_act}, - {BATTERY_NORMAL, BATTERY_REAL_POWER_OFF, battery_power_off_act}, +static int lowbat_freq = -1; +static struct battery_config_info battery_info = { + .normal = BATTERY_NORMAL, + .warning = BATTERY_WARNING, + .critical = BATTERY_CRITICAL, + .poweroff = BATTERY_POWEROFF, + .realoff = BATTERY_REALOFF, }; -/* - * TODO: remove this function - */ +static dd_list *lpe = NULL; +static int scenario_count = 0; + +static int lowbat_initialized(void *data) +{ + static int status; + + if (!data) + return status; + + status = *(int *)data; + return status; +} + +static int lowbat_scenario(int old, int now, void *data) +{ + dd_list *n; + struct lowbat_process_entry *scenario; + int found = 0; + + DD_LIST_FOREACH(lpe, n, scenario) { + if (old != scenario->old || now != scenario->now) + continue; + if (!scenario->func) + continue; + scenario->func(data); + found = 1; + break; + } + return found; +} + +static int lowbat_add_scenario(int old, int now, int (*func)(void *data)) +{ + struct lowbat_process_entry *scenario; + + _I("%d %d, %x", old, now, func); + + if (!func) { + _E("invalid func address!"); + return -EINVAL; + } + + scenario = malloc(sizeof(struct lowbat_process_entry)); + if (!scenario) { + _E("Fail to malloc for notifier!"); + return -ENOMEM; + } + + scenario->old = old; + scenario->now = now; + scenario->func = func; + + DD_LIST_APPEND(lpe, scenario); + scenario_count++; + return 0; +} + static void print_lowbat_state(unsigned int bat_percent) { #if 0 @@ -118,77 +155,235 @@ static void print_lowbat_state(unsigned int bat_percent) #endif } -int battery_warning_low_act(void *data) +static int power_execute(void) { - char lowbat_noti_name[NAME_MAX]; + static const struct device_ops *ops = NULL; + + FIND_DEVICE_INT(ops, POWER_OPS_NAME); + + return ops->execute(INTERNAL_PWROFF); +} + +static int booting_done(void *data) +{ + static int done = 0; + + if (data == NULL) + goto out; + done = (int)data; + if (!done) + goto out; + _I("booting done"); +out: + return done; +} + +static int lowbat_popup(char *option) +{ + static int launched_poweroff = 0; + static const struct device_ops *apps = NULL; + struct popup_data *params; + int ret, state=0; + int r_disturb, s_disturb, r_block, s_block; + char *value; + pid_t pid; + + if (!option) + return -1; + + if (strcmp(option, POWER_OFF_BAT_ACT)) + launched_poweroff = 0; + + if (!strcmp(option, CRITICAL_LOW_BAT_ACT)) { +#ifdef MICRO_DD + value = "lowbattery_critical"; +#else + value = "critical"; +#endif + lowbat_popup_option = LOWBAT_OPT_CHECK; + } else if (!strcmp(option, WARNING_LOW_BAT_ACT)) { +#ifdef MICRO_DD + value = "lowbattery_warning"; +#else + value = "warning"; +#endif + lowbat_popup_option = LOWBAT_OPT_WARNING; + } else if (!strcmp(option, POWER_OFF_BAT_ACT)) { + value = "poweroff"; + lowbat_popup_option = LOWBAT_OPT_POWEROFF; + } else if (!strcmp(option, CHARGE_ERROR_ACT)) { + value = "chargeerr"; + lowbat_popup_option = LOWBAT_OPT_CHARGEERR; + } else if (!strcmp(option, CHARGE_ERROR_LOW_ACT)) { + value = "chargeerrlow"; + lowbat_popup_option = LOWBAT_OPT_CHARGEERR; + } else if (!strcmp(option, CHARGE_ERROR_HIGH_ACT)) { + value = "chargeerrhigh"; + lowbat_popup_option = LOWBAT_OPT_CHARGEERR; + } else if (!strcmp(option, CHARGE_ERROR_OVP_ACT)) { + value = "chargeerrovp"; + lowbat_popup_option = LOWBAT_OPT_CHARGEERR; + } else if (!strcmp(option, CHARGE_CHECK_ACT)) { + launched_poweroff = 0; + return 0; + } else + return -1; + _D("%s", value); + ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state); + if (state == 1 || ret != 0 || booting_done(NULL)) { + + if (launched_poweroff == 1) { + _I("will be foreced power off"); + power_execute(); + return 0; + } + + if (lowbat_popup_option == LOWBAT_OPT_POWEROFF) + launched_poweroff = 1; + + pid = get_exec_pid(LOWBAT_EXEC_PATH); + if (pid > 0) { + _I("pre launched %s destroy", LOWBAT_EXEC_PATH); + kill(pid, SIGTERM); + } + + FIND_DEVICE_INT(apps, "apps"); + + params = malloc(sizeof(struct popup_data)); + if (params == NULL) { + _E("Malloc failed"); + return -1; + } + r_disturb = vconf_get_int("memory/shealth/sleep/do_not_disturb", &s_disturb); + r_block = vconf_get_bool("db/setting/blockmode_wearable", &s_block); + if ((r_disturb != 0 && r_block != 0) || + (s_disturb == 0 && s_block == 0) || + lowbat_popup_option == LOWBAT_OPT_CHARGEERR) + pm_change_internal(getpid(), LCD_NORMAL); + else + _I("block LCD"); + params->name = LOWBAT_POPUP_NAME; + params->key = POPUP_KEY_CONTENT; + params->value = strdup(value); + apps->init((void *)params); + free(params->value); + free(params); + } else { + _D("boot-animation running yet"); + } - heynoti_get_snoti_name(_SYS_LOW_POWER, lowbat_noti_name, NAME_MAX); - ss_noti_send(lowbat_noti_name); + return 0; +} - action_entry_call_internal(PREDEF_LOWBAT, 1, WARNING_LOW_BAT_ACT); +static int battery_check_act(void *data) +{ + lowbat_popup(CHARGE_CHECK_ACT); return 0; } -int battery_critical_low_act(void *data) +static int battery_warning_low_act(void *data) { - action_entry_call_internal(PREDEF_LOWBAT, 1, CRITICAL_LOW_BAT_ACT); + lowbat_popup(WARNING_LOW_BAT_ACT); + return 0; +} + +static int battery_critical_low_act(void *data) +{ + lowbat_popup(CRITICAL_LOW_BAT_ACT); return 0; } int battery_power_off_act(void *data) { - action_entry_call_internal(PREDEF_LOWBAT, 1, POWER_OFF_BAT_ACT); + vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, VCONFKEY_SYSMAN_POWER_OFF_DIRECT); return 0; } int battery_charge_err_act(void *data) { - action_entry_call_internal(PREDEF_LOWBAT, 1, CHARGE_ERROR_ACT); + lowbat_popup(CHARGE_ERROR_ACT); return 0; } - -static int battery_charge_act(void *data) +int battery_charge_err_low_act(void *data) { + lowbat_popup(CHARGE_ERROR_LOW_ACT); return 0; } -int ss_lowbat_set_charge_on(int on) +int battery_charge_err_high_act(void *data) { - static bool state = -1; + lowbat_popup(CHARGE_ERROR_HIGH_ACT); + return 0; +} - if (state == on) - return 0; - if (CONNECTED(on)) - extcon_set_count(EXTCON_TA); - if (vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, on) != 0) { - _E("fail to set charge vconf value"); - return -EPERM; - } +int battery_charge_err_ovp_act(void *data) +{ + lowbat_popup(CHARGE_ERROR_OVP_ACT); + return 0; +} - if (update_pm_setting) - update_pm_setting(SETTING_CHARGING, on); +static int battery_charge_act(void *data) +{ +#ifdef NOUSE + int val; + char argstr[128]; - state = on; + /* instead of adding action to the queue, execute it right here */ + if (device_get_property(DEVTYPE_JACK, JACK_PROP_TA_ONLINE, &val) == 0 + && val == 1) { + snprintf(argstr, 128, "-t 4"); + launch_after_kill_if_exist(LOWBAT_EXEC_PATH, argstr); + } +#endif return 0; } -int ss_lowbat_is_charge_in_now(void) +static void lowbat_scenario_init(void) { - int val = 0; - if (device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CHARGE_NOW, &val) < 0) { - _E("fail to read charge now from kernel"); - ss_lowbat_set_charge_on(0); - return 0; + lowbat_add_scenario(battery_info.normal, battery_info.warning, battery_warning_low_act); + lowbat_add_scenario(battery_info.warning, battery_info.critical, battery_critical_low_act); + lowbat_add_scenario(battery_info.poweroff, battery_info.realoff, battery_power_off_act); + lowbat_add_scenario(battery_info.normal, battery_info.critical, battery_critical_low_act); + lowbat_add_scenario(battery_info.warning, battery_info.poweroff, battery_critical_low_act); + lowbat_add_scenario(battery_info.critical, battery_info.realoff, battery_power_off_act); + lowbat_add_scenario(battery_info.normal, battery_info.poweroff, battery_critical_low_act); + lowbat_add_scenario(battery_info.warning, battery_info.realoff, battery_power_off_act); + lowbat_add_scenario(battery_info.normal, battery_info.realoff, battery_power_off_act); + lowbat_add_scenario(battery_info.realoff, battery_info.realoff, battery_power_off_act); + lowbat_add_scenario(battery_info.realoff, battery_info.normal, battery_check_act); + lowbat_add_scenario(battery_info.realoff, battery_info.warning, battery_check_act); + lowbat_add_scenario(battery_info.realoff, battery_info.critical, battery_check_act); + lowbat_add_scenario(battery_info.realoff, battery_info.poweroff, battery_check_act); +} + +static void change_lowbat_level(int bat_percent) +{ + int prev, now; + + if (cur_bat_capacity == bat_percent) + return; + + if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &prev) < 0) { + _E("vconf_get_int() failed"); + return; } - if (val == 1) { - ss_lowbat_set_charge_on(1); - return 1; + + if (bat_percent > BATTERY_LEVEL_CHECK_FULL) { + now = VCONFKEY_SYSMAN_BAT_LEVEL_FULL; + } else if (bat_percent > BATTERY_LEVEL_CHECK_HIGH) { + now = VCONFKEY_SYSMAN_BAT_LEVEL_HIGH; + } else if (bat_percent > BATTERY_LEVEL_CHECK_LOW) { + now = VCONFKEY_SYSMAN_BAT_LEVEL_LOW; + } else if (bat_percent > BATTERY_LEVEL_CHECK_CRITICAL) { + now = VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL; } else { - ss_lowbat_set_charge_on(0); - return 0; + now = VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY; } + + if (prev != now) + vconf_set_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, now); } static int lowbat_process(int bat_percent, void *ad) @@ -196,14 +391,20 @@ static int lowbat_process(int bat_percent, void *ad) int new_bat_capacity; int new_bat_state; int vconf_state = -1; - int bat_full = -1; int i, ret = 0; - int val = 0; int status = -1; + bool low_bat = false; + bool full_bat = false; +#ifdef MICRO_DD + int extreme = 0; +#endif + int result = 0; + int lock = -1; new_bat_capacity = bat_percent; if (new_bat_capacity < 0) - return -1; + return -EINVAL; + change_lowbat_level(new_bat_capacity); if (new_bat_capacity != cur_bat_capacity) { _D("[BAT_MON] cur = %d new = %d", cur_bat_capacity, new_bat_capacity); @@ -213,42 +414,39 @@ static int lowbat_process(int bat_percent, void *ad) if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &vconf_state) < 0) { _E("vconf_get_int() failed"); - return -1; + result = -EIO; + goto exit; } - if (new_bat_capacity <= BATTERY_REAL_POWER_OFF) { - if (device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CHARGE_NOW, &val) < 0) { - _E("fail to read charge now from kernel"); - } - _D("charge_now status %d",val); - if (val == 1) { - new_bat_state = BATTERY_POWER_OFF; + if (new_bat_capacity <= battery_info.realoff) { + if (battery.charge_now) { + new_bat_state = battery_info.poweroff; if (vconf_state != VCONFKEY_SYSMAN_BAT_POWER_OFF) status = VCONFKEY_SYSMAN_BAT_POWER_OFF; } else { - new_bat_state = BATTERY_REAL_POWER_OFF; + new_bat_state = battery_info.realoff; if (vconf_state != VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF) status = VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF; } - } else if (new_bat_capacity <= BATTERY_POWER_OFF) { - new_bat_state = BATTERY_POWER_OFF; + } else if (new_bat_capacity <= battery_info.poweroff) { + new_bat_state = battery_info.poweroff; if (vconf_state != VCONFKEY_SYSMAN_BAT_POWER_OFF) status = VCONFKEY_SYSMAN_BAT_POWER_OFF; - } else if (new_bat_capacity <= BATTERY_CRITICAL_LOW) { - new_bat_state = BATTERY_CRITICAL_LOW; + } else if (new_bat_capacity <= battery_info.critical) { + new_bat_state = battery_info.critical; if (vconf_state != VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) status = VCONFKEY_SYSMAN_BAT_CRITICAL_LOW; - } else if (new_bat_capacity <= BATTERY_WARNING_LOW) { - new_bat_state = BATTERY_WARNING_LOW; + } else if (new_bat_capacity <= battery_info.warning) { + new_bat_state = battery_info.warning; if (vconf_state != VCONFKEY_SYSMAN_BAT_WARNING_LOW) status = VCONFKEY_SYSMAN_BAT_WARNING_LOW; } else { - new_bat_state = BATTERY_NORMAL; + new_bat_state = battery_info.normal; if (new_bat_capacity == BATTERY_FULL) { - device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CHARGE_FULL, &bat_full); - if (bat_full == 1) { + if (battery.charge_full) { if (vconf_state != VCONFKEY_SYSMAN_BAT_FULL) status = VCONFKEY_SYSMAN_BAT_FULL; + full_bat = true; } else { if (vconf_state != VCONFKEY_SYSMAN_BAT_NORMAL) status = VCONFKEY_SYSMAN_BAT_NORMAL; @@ -260,130 +458,88 @@ static int lowbat_process(int bat_percent, void *ad) } if (status != -1) { + lock = pm_lock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, STAY_CUR_STATE, 0); ret = vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, status); + power_supply_broadcast(CHARGE_LEVEL_SIGNAL, status); if (update_pm_setting) update_pm_setting(SETTING_LOW_BATT, status); } - if (ret < 0) - return -1; - - ss_lowbat_is_charge_in_now(); - - if (cur_bat_state == new_bat_state) { - return 0; + if (ret < 0) { + result = -EIO; + goto exit; } +#ifdef MICRO_DD + if (vconf_get_int(VCONFKEY_PM_KEY_IGNORE, &extreme) == 0 && extreme == TRUE && + (status > VCONFKEY_SYSMAN_BAT_POWER_OFF && status <= VCONFKEY_SYSMAN_BAT_FULL)) + if (vconf_set_int(VCONFKEY_PM_KEY_IGNORE, FALSE) == 0) + _I("release key ignore"); +#endif + if (new_bat_capacity <= battery_info.warning) + low_bat = true; - if (cur_bat_state == BATTERY_UNKNOWN) { - for (i = 0; - i < sizeof(lpe) / sizeof(struct lowbat_process_entry); - i++) { - if (new_bat_state == lpe[i].new_bat_state) { - lpe[i].action(ad); - cur_bat_state = new_bat_state; - return 0; - } - } - } else { - for (i = 0; - i < sizeof(lpe) / sizeof(struct lowbat_process_entry); - i++) { - if ((cur_bat_state == lpe[i].cur_bat_state) - && (new_bat_state == lpe[i].new_bat_state)) { - lpe[i].action(ad); - cur_bat_state = new_bat_state; - return 0; - } - } - } - _D("[BATMON] Unknown battery state cur:%d new:%d", cur_bat_state, new_bat_state); - cur_bat_state = new_bat_state; - return -1; -} + device_notify(DEVICE_NOTIFIER_LOWBAT, (void*)low_bat); -static int lowbat_read() -{ - int bat_percent; + if (cur_bat_state == new_bat_state && new_bat_state > battery_info.realoff) + goto exit; - device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY, &bat_percent); + if (cur_bat_state == BATTERY_UNKNOWN) + cur_bat_state = battery_info.normal; + result = lowbat_scenario(cur_bat_state, new_bat_state, NULL); + if (result) + _I("cur %d, new %d(capacity %d)", + cur_bat_state, new_bat_state, bat_percent); + cur_bat_state = new_bat_state; +exit: + if (lock == 0) + pm_unlock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, PM_SLEEP_MARGIN); - return bat_percent; + return result; } -static void __ss_change_lowbat_level(int bat_percent) +static int lowbat_read(void) { - int prev, now; + int bat_percent, r; - if (cur_bat_capacity == bat_percent) - return; + r = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY, &bat_percent); + if (r < 0) + return r; - if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &prev) < 0) { - _E("vconf_get_int() failed"); - return; - } - - - if (bat_percent > BATTERY_LEVEL_CHECK_FULL) { - now = VCONFKEY_SYSMAN_BAT_LEVEL_FULL; - } else if (bat_percent > BATTERY_LEVEL_CHECK_HIGH) { - now = VCONFKEY_SYSMAN_BAT_LEVEL_HIGH; - } else if (bat_percent > BATTERY_LEVEL_CHECK_LOW) { - now = VCONFKEY_SYSMAN_BAT_LEVEL_LOW; - } else if (bat_percent > BATTERY_LEVEL_CHECK_CRITICAL) { - now = VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL; - } else { - now = VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY; - } - - if (prev != now) - vconf_set_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, now); + return bat_percent; } -static int __check_lowbat_percent(void) +static int check_lowbat_percent(int *pct) { int bat_percent; bat_percent = lowbat_read(); if (bat_percent < 0) { - ecore_timer_interval_set(lowbat_timer, BAT_MON_INTERVAL_MIN); - bat_err_count++; - if (bat_err_count > MAX_BATTERY_ERROR) { - _E("[BATMON] Cannot read battery gage. stop read fuel gage"); - return 0; - } - return 1; + _E("[BATMON] Cannot read battery gage. stop read fuel gage"); + return -ENODEV; } if (bat_percent > 100) bat_percent = 100; - __ss_change_lowbat_level(bat_percent); - return bat_percent; -} - -Eina_Bool ss_lowbat_monitor(void *data) -{ - int bat_percent; - struct ss_main_data *ad = (struct ss_main_data *)data; - - bat_percent = __check_lowbat_percent(); - print_lowbat_state(bat_percent); - - if (lowbat_process(bat_percent, ad) < 0) - ecore_timer_interval_set(lowbat_timer, BAT_MON_INTERVAL_MIN); - else - ecore_timer_interval_set(lowbat_timer, BAT_MON_INTERVAL); - - return EINA_TRUE; + change_lowbat_level(bat_percent); + *pct = bat_percent; + return 0; } -static int wakeup_cb(keynode_t *key_nodes, void *data) +void lowbat_monitor(void *data) { - int pm_state = 0; + int bat_percent, r; - if ((pm_state = - vconf_keynode_get_int(key_nodes)) == VCONFKEY_PM_STATE_LCDOFF) - ss_lowbat_monitor(NULL); + r = lowbat_initialized(NULL); + if (!r) + return; - return 0; + if (data == NULL) { + r = check_lowbat_percent(&bat_percent); + if (r < 0) + return; + } else + bat_percent = *(int *)data; + print_lowbat_state(bat_percent); + lowbat_process(bat_percent, NULL); } /* for debugging (request by kernel) */ @@ -400,109 +556,57 @@ static int check_battery() return ret; } -static Eina_Bool lowbat_popup(void *data) +static int check_power_save_mode(void) { - int ret = -1, state = 0; - ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state); - if (state == 1 || ret != 0) { - bundle *b = NULL; - b = bundle_create(); - if (lowbat_popup_option == LOWBAT_OPT_WARNING || lowbat_popup_option == LOWBAT_OPT_CHECK) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); - } else if(lowbat_popup_option == LOWBAT_OPT_POWEROFF) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "poweroff"); - } else if(lowbat_popup_option == LOWBAT_OPT_CHARGEERR) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "chargeerr"); - } else - goto out; - - ret = syspopup_launch("lowbat-syspopup", b); - if (ret < 0) { - _E("popup lauch failed"); - bundle_free(b); - return EINA_TRUE; - } -out: - if (lowbat_popup_id != NULL) { - ecore_timer_del(lowbat_popup_id); - lowbat_popup_id = NULL; - } - lowbat_popup_option = 0; - bundle_free(b); - return EINA_FALSE; + int ret = 0; + int power_saving_cpu_stat = -1; + + ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, + &power_saving_cpu_stat); + if (ret < 0) { + _E("failed to get vconf key"); + return ret; } - _D("boot-animation running yet"); - return EINA_FALSE; + + if (power_saving_cpu_stat == 1) + ret = 1; + return ret; } -int lowbat_def_predefine_action(int argc, char **argv) +static int lowbat_monitor_init(void *data) { - int ret, state=0; - char argstr[128]; - char* option = NULL; - - if (argc < 1) - return -1; - - if (lowbat_popup_id != NULL) { - ecore_timer_del(lowbat_popup_id); - lowbat_popup_id = NULL; - } - - bundle *b = NULL; - b = bundle_create(); - if (!strcmp(argv[0],CRITICAL_LOW_BAT_ACT)) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); - lowbat_popup_option = LOWBAT_OPT_CHECK; - } else if(!strcmp(argv[0],WARNING_LOW_BAT_ACT)) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); - lowbat_popup_option = LOWBAT_OPT_WARNING; - } else if(!strcmp(argv[0],POWER_OFF_BAT_ACT)) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "poweroff"); - lowbat_popup_option = LOWBAT_OPT_POWEROFF; - } else if(!strcmp(argv[0],CHARGE_ERROR_ACT)) { - bundle_add(b, "_SYSPOPUP_CONTENT_", "chargeerr"); - lowbat_popup_option = LOWBAT_OPT_CHARGEERR; - } - - ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state); - if (state == 1 || ret != 0) { - if (predefine_control_launch("lowbat-syspopup", b, lowbat_popup_option) < 0) { - _E("popup lauch failed\n"); - bundle_free(b); - lowbat_popup_option = 0; - return -1; - } - } else { - _D("boot-animation running yet"); - lowbat_popup_id = ecore_timer_add(WAITING_INTERVAL, lowbat_popup, NULL); - } - bundle_free(b); + int status = 1; + + lowbat_initialized(&status); + unregister_notifier(DEVICE_NOTIFIER_POWER_SUPPLY, lowbat_monitor_init); + battery_config_load(&battery_info); + _I("%d %d %d %d %d", battery_info.normal, battery_info.warning, + battery_info.critical, battery_info.poweroff, battery_info.realoff); + lowbat_scenario_init(); + check_lowbat_percent(&battery.capacity); + lowbat_process(battery.capacity, NULL); return 0; } static void lowbat_init(void *data) { - struct ss_main_data *ad = (struct ss_main_data*)data; - - action_entry_add_internal(PREDEF_LOWBAT, lowbat_def_predefine_action, - NULL, NULL); - - /* need check battery */ - lowbat_timer = - ecore_timer_add(BAT_MON_INTERVAL_MIN, ss_lowbat_monitor, ad); - - __check_lowbat_percent(); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_POWER_SUPPLY, lowbat_monitor_init); +} - ss_lowbat_is_charge_in_now(); +static void lowbat_exit(void *data) +{ + int status = 0; - vconf_notify_key_changed(VCONFKEY_PM_STATE, (void *)wakeup_cb, NULL); + lowbat_initialized(&status); + unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); } static const struct device_ops lowbat_device_ops = { .priority = DEVICE_PRIORITY_NORMAL, .name = "lowbat", .init = lowbat_init, + .exit = lowbat_exit, }; DEVICE_OPS_REGISTER(&lowbat_device_ops) diff --git a/src/control/control.c b/src/control/control.c index a0c9968..950d531 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -27,14 +27,17 @@ #include "core/common.h" #include "core/devices.h" #include "core/edbus-handler.h" -#include "mmc/mmc-handler.h" + +#define CONTROL_HANDLER_NAME "control" +#define CONTROL_GETTER_NAME "getcontrol" static const struct control_device { const int id; - const struct device_ops *ops; + const char *name; } devices[] = { /* Add id & ops to provide start/stop control */ - { DEVICE_CONTROL_MMC, &mmc_device_ops }, + { DEVICE_CONTROL_MMC, "mmc" }, + { DEVICE_CONTROL_USBCLIENT, "usbclient" }, }; static int control_handler(int argc, char **argv) @@ -44,6 +47,7 @@ static int control_handler(int argc, char **argv) int device; bool enable; int ret; + const struct device_ops *dev_ops = NULL; _I("argc : %d", argc); for (i = 0; i < argc; ++i) @@ -66,15 +70,51 @@ static int control_handler(int argc, char **argv) if (i >= ARRAY_SIZE(devices)) return -EINVAL; - + FIND_DEVICE_INT(dev_ops, devices[i].name); if (enable) - ret = device_start(devices[i].ops); + ret = device_start(dev_ops); else - ret = device_stop(devices[i].ops); + ret = device_stop(dev_ops); return ret; } +static int get_control_handler(int argc, char **argv) +{ + int i; + int pid; + int device; + bool enable; + int ret; + const struct device_ops *dev_ops = NULL; + + _I("argc : %d", argc); + for (i = 0; i < argc; ++i) + _I("[%2d] %s", i, argv[i]); + + if (argc > 4) { + _E("Invalid argument"); + errno = EINVAL; + return -1; + } + + pid = atoi(argv[0]); + device = atoi(argv[1]); + _I("pid : %d, device : %d", pid, device); + + for (i = 0; i < ARRAY_SIZE(devices); i++) + if (devices[i].id == device) + break; + + if (i >= ARRAY_SIZE(devices)) + return -EINVAL; + + FIND_DEVICE_INT(dev_ops, devices[i].name); + + return device_get_status(dev_ops); +} + + static DBusMessage *dbus_control_handler(E_DBus_Object *obj, DBusMessage *msg) { DBusError err; @@ -121,8 +161,54 @@ out: return reply; } +static DBusMessage *dbus_get_control_handler(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusError err; + DBusMessageIter iter; + DBusMessage *reply; + pid_t pid; + int ret; + int argc; + char *type_str; + char *argv[2]; + + dbus_error_init(&err); + + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &type_str, + DBUS_TYPE_INT32, &argc, + DBUS_TYPE_STRING, &argv[0], + DBUS_TYPE_STRING, &argv[1], DBUS_TYPE_INVALID)) { + _E("there is no message"); + ret = -EINVAL; + goto out; + } + + if (argc < 0) { + _E("message is invalid!"); + ret = -EINVAL; + goto out; + } + + pid = get_edbus_sender_pid(msg); + if (kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored!", pid); + ret = -ESRCH; + goto out; + } + + ret = get_control_handler(argc, (char **)&argv); +out: + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + + return reply; +} + static const struct edbus_method edbus_methods[] = { - { CONTROL_HANDLER_NAME, "sisss", "i", dbus_control_handler }, + { CONTROL_HANDLER_NAME, "sisss", "i", dbus_control_handler }, + { CONTROL_GETTER_NAME , "siss", "i", dbus_get_control_handler }, }; static void control_init(void *data) @@ -132,8 +218,6 @@ static void control_init(void *data) ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods)); if (ret < 0) _E("fail to init edbus method(%d)", ret); - - action_entry_add_internal(CONTROL_HANDLER_NAME, control_handler, NULL, NULL); } static const struct device_ops control_device_ops = { diff --git a/src/core/common.c b/src/core/common.c index 2558412..b43835d 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -31,10 +32,12 @@ #include #include #include +#include #include "log.h" #define PERMANENT_DIR "/tmp/permanent" #define VIP_DIR "/tmp/vip" +#define BUFF_MAX 255 /** * Opens "/proc/$pid/oom_score_adj" file for w/r; @@ -55,6 +58,7 @@ int get_exec_pid(const char *execpath) DIR *dp; struct dirent *dentry; int pid = -1, fd; + int ret; char buf[PATH_MAX]; char buf2[PATH_MAX]; @@ -74,12 +78,14 @@ int get_exec_pid(const char *execpath) fd = open(buf, O_RDONLY); if (fd < 0) continue; - if (read(fd, buf2, PATH_MAX) < 0) { - close(fd); - continue; - } + ret = read(fd, buf2, PATH_MAX); close(fd); + if (ret < 0 || ret >= PATH_MAX) + continue; + + buf2[ret] = '\0'; + if (!strcmp(buf2, execpath)) { closedir(dp); return pid; @@ -138,3 +144,217 @@ int is_vip(int pid) else return 0; } + +static int remove_dir_internal(int fd) +{ + DIR *dir; + struct dirent *de; + int subfd, ret = 0; + + dir = fdopendir(fd); + if (!dir) + return -1; + while ((de = readdir(dir))) { + if (de->d_type == DT_DIR) { + if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) + continue; + subfd = openat(fd, de->d_name, O_RDONLY | O_DIRECTORY); + if (subfd < 0) { + _SE("Couldn't openat %s: %s\n", de->d_name, strerror(errno)); + ret = -1; + continue; + } + if (remove_dir_internal(subfd)) { + ret = -1; + } + close(subfd); + if (unlinkat(fd, de->d_name, AT_REMOVEDIR) < 0) { + _SE("Couldn't unlinkat %s: %s\n", de->d_name, strerror(errno)); + ret = -1; + } + } else { + if (unlinkat(fd, de->d_name, 0) < 0) { + _SE("Couldn't unlinkat %s: %s\n", de->d_name, strerror(errno)); + ret = -1; + } + } + } + closedir(dir); + return ret; +} + +int remove_dir(char *path, int del_dir) +{ + int fd, ret = 0; + + if (!path) + return -1; + fd = open(path, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW); + if (fd < 0) { + _SE("Couldn't opendir %s: %s\n", path, strerror(errno)); + return -errno; + } + ret = remove_dir_internal(fd); + close(fd); + + if (del_dir) { + if (rmdir(path)) { + _SE("Couldn't rmdir %s: %s\n", path, strerror(errno)); + ret = -1; + } + } + return ret; +} + +/* + * Helper function + * - Read from sysfs entry + * - Write to sysfs entry + */ +int sys_check_node(char *path) +{ + int fd; + + fd = open(path, O_RDONLY); + if (fd == -1) + return -1; + + close(fd); + return 0; +} + +static int sys_read_buf(char *file, char *buf) +{ + int fd; + int r; + int ret = 0; + + fd = open(file, O_RDONLY); + if (fd == -1) + return -ENOENT; + + r = read(fd, buf, BUFF_MAX); + if ((r >= 0) && (r < BUFF_MAX)) + buf[r] = '\0'; + else + ret = -EIO; + + close(fd); + + return ret; +} + +static int sys_write_buf(char *file, char *buf) +{ + int fd; + int r; + int ret = 0; + + fd = open(file, O_WRONLY); + if (fd == -1) + return -ENOENT; + + r = write(fd, buf, strlen(buf)); + if (r < 0) + ret = -EIO; + + close(fd); + + return ret; +} + +int sys_get_int(char *fname, int *val) +{ + char buf[BUFF_MAX]; + int ret = 0; + + if (sys_read_buf(fname, buf) == 0) { + *val = atoi(buf); + } else { + *val = -1; + ret = -EIO; + } + + return ret; +} + +int sys_set_int(char *fname, int val) +{ + char buf[BUFF_MAX]; + int ret = 0; + + snprintf(buf, sizeof(buf), "%d", val); + + if (sys_write_buf(fname, buf) != 0) + ret = -EIO; + + return ret; +} + +int sys_get_str(char *fname, char *str) +{ + char buf[BUFF_MAX] = {0}; + + if (sys_read_buf(fname, buf) == 0) { + strncpy(str, buf, strlen(buf)); + return 0; + } + + return -1; +} + +int sys_set_str(char *fname, char *val) +{ + int r = -1; + + if (val != NULL) { + if (sys_write_buf(fname, val) == 0) + r = 0; + } + + return r; +} + +int terminate_process(const char* partition, bool force) +{ + const char *argv[7] = {"/sbin/fuser", "-m", "-k", "-S", NULL, NULL, NULL}; + int argc; + + if (force) + argv[4] = "-SIGKILL"; + else + argv[4] = "-SIGTERM"; + argv[5] = partition; + argc = sizeof(argv) / sizeof(argv[0]); + return run_child(argc, argv); +} + +int mount_check(const char* path) +{ + int ret = false; + struct mntent* mnt; + const char* table = "/etc/mtab"; + FILE* fp; + + fp = setmntent(table, "r"); + if (!fp) + return ret; + while (mnt=getmntent(fp)) { + if (!strcmp(mnt->mnt_dir, path)) { + ret = true; + break; + } + } + endmntent(fp); + return ret; +} + +void print_time(const char *prefix) +{ + struct timeval tv; + struct tm *tm; + gettimeofday(&tv, NULL); + tm = localtime(&(tv.tv_sec)); + _D("%s --> %d:%02d:%02d %d", + prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); +} diff --git a/src/core/common.h b/src/core/common.h index b363abb..9754d14 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -17,13 +17,33 @@ */ -#ifndef __COMMON_H__ -#define __COMMON_H__ +#ifndef __CORE_COMMON_H__ +#define __CORE_COMMON_H__ +#include #include +#include +#include #include #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) + +/* + * One byte digit has 3 position in decimal representation + * 2 - 5 + * 4 - 10 + * 8 - 20 + * >8 - compile time error + * plus 1 null termination byte + * plus 1 for negative prefix + */ +#define MAX_DEC_SIZE(type) \ + (2 + (sizeof(type) <= 1 ? 3 : \ + sizeof(type) <= 2 ? 5 : \ + sizeof(type) <= 4 ? 10 : \ + sizeof(type) <= 8 ? 20 : \ + sizeof(int[-2*(sizeof(type) > 8)]))) + #ifndef __CONSTRUCTOR__ #define __CONSTRUCTOR__ __attribute__ ((constructor)) #endif @@ -31,18 +51,94 @@ #ifndef __DESTRUCTOR__ #define __DESTRUCTOR__ __attribute__ ((destructor)) #endif + +#ifndef __WEAK__ +#define __WEAK__ __attribute__ ((weak)) +#endif + #ifndef max -#define max(a,b) ((a) > (b) ? (a) : (b)) +#define max(a, b) \ + __extension__ ({ \ + typeof(a) _a = (a); \ + typeof(b) _b = (b); \ + _a > _b ? _a : _b; \ + }) #endif #ifndef min -#define min(a,b) ((a) < (b) ? (a) : (b)) +#define min(a, b) \ + __extension__ ({ \ + typeof(a) _a = (a); \ + typeof(b) _b = (b); \ + _a < _b ? _a : _b; \ + }) #endif +#ifndef clamp +#define clamp(x, low, high) \ + __extension__ ({ \ + typeof(x) _x = (x); \ + typeof(low) _low = (low); \ + typeof(high) _high = (high); \ + ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \ + }) +#endif + +#ifndef SEC_TO_MSEC +#define SEC_TO_MSEC(x) ((x)*1000) +#endif +#ifndef NSEC_TO_MSEC +#define NSEC_TO_MSEC(x) ((double)x/1000000) +#endif +#ifndef USEC_TO_MSEC +#define USEC_TO_MSEC(x) ((double)x/1000) +#endif + +#ifndef safe_free +#define safe_free(x) safe_free_memory((void**)&(x)) +#endif + +static inline void safe_free_memory(void** mem) +{ + if (mem && *mem) { + free(*mem); + *mem = NULL; + } +} + +#define ret_value_if(expr, val) do { \ + if (expr) { \ + _E("(%s)", #expr); \ + return (val); \ + } \ +} while (0) + +#define ret_value_msg_if(expr, val, fmt, arg...) do { \ + if (expr) { \ + _E(fmt, ##arg); \ + return val; \ + } \ +} while (0) + +#define ret_msg_if(expr, fmt, arg...) do { \ + if (expr) { \ + _E(fmt, ##arg); \ + return; \ + } \ +} while (0) + FILE * open_proc_oom_score_adj_file(int pid, const char *mode); int get_exec_pid(const char *execpath); int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size); int is_vip(int pid); +int run_child(int argc, const char *argv[]); +int remove_dir(const char *path, int del_dir); +int sys_check_node(char *path); +int sys_get_int(char *fname, int *val); +int sys_set_int(char *fname, int val); +int terminate_process(const char* partition, bool force); +int mount_check(const char* path); +void print_time(const char *prefix); -#endif /* __COMMON_H__ */ +#endif /* __CORE_COMMON_H__ */ diff --git a/src/core/config-parser.c b/src/core/config-parser.c new file mode 100644 index 0000000..b7e164b --- /dev/null +++ b/src/core/config-parser.c @@ -0,0 +1,127 @@ +/* + * deviced + * + * Copyright (c) 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 +#include +#include +#include "log.h" +#include "config-parser.h" + +#define MAX_LINE 128 +#define MAX_SECTION 64 +#define WHITESPACE " \t" +#define NEWLINE "\n\r" +#define COMMENT '#' + +static inline char *trim_str(char *s) +{ + char *t; + /* left trim */ + s += strspn(s, WHITESPACE); + + /* right trim */ + for (t = strchr(s, 0); t > s; t--) + if (!strchr(WHITESPACE, t[-1])) + break; + *t = 0; + return s; +} + +int config_parse(const char *file_name, int cb(struct parse_result *result, + void *user_data), void *user_data) +{ + FILE *f = NULL; + struct parse_result result; + /* use stack for parsing */ + char line[MAX_LINE]; + char section[MAX_SECTION]; + char *start, *end, *name, *value; + int lineno = 0, ret = 0; + + if (!file_name || !cb) { + ret = -EINVAL; + goto error; + } + + /* open conf file */ + f = fopen(file_name, "r"); + if (!f) { + _E("Failed to open file %s", file_name); + ret = -EIO; + goto error; + } + + /* parsing line by line */ + while (fgets(line, MAX_LINE, f) != NULL) { + lineno++; + + start = line; + start[strcspn(start, NEWLINE)] = '\0'; + start = trim_str(start); + + if (*start == COMMENT) { + continue; + } else if (*start == '[') { + /* parse section */ + end = strchr(start, ']'); + if (!end || *end != ']') { + ret = -EBADMSG; + goto error; + } + + *end = '\0'; + strncpy(section, start + 1, sizeof(section)); + section[MAX_SECTION-1] = '\0'; + } else if (*start) { + /* parse name & value */ + end = strchr(start, '='); + if (!end || *end != '=') { + ret = -EBADMSG; + goto error; + } + *end = '\0'; + name = trim_str(start); + value = trim_str(end + 1); + end = strchr(value, COMMENT); + if (end && *end == COMMENT) { + *end = '\0'; + value = trim_str(value); + } + + result.section = section; + result.name = name; + result.value = value; + /* callback with parse result */ + ret = cb(&result, user_data); + if (ret < 0) { + ret = -EBADMSG; + goto error; + } + } + } + _D("Success to load %s", file_name); + fclose(f); + return 0; + +error: + if (f) + fclose(f); + _E("Failed to read %s:%d!", file_name, lineno); + return ret; +} + diff --git a/src/auto-test/main.c b/src/core/config-parser.h similarity index 51% rename from src/auto-test/main.c rename to src/core/config-parser.h index 1cdd0d3..ed3675f 100644 --- a/src/auto-test/main.c +++ b/src/core/config-parser.h @@ -1,5 +1,5 @@ /* - * test + * deviced * * Copyright (c) 2013 Samsung Electronics Co., Ltd. * @@ -17,20 +17,27 @@ */ -#include "test.h" +#ifndef __CONFIG_PARSER_H__ +#define __CONFIG_PARSER_H__ -static int test_main(int argc, char **argv) -{ - test_init((void *)NULL); - ecore_main_loop_begin(); - test_exit((void *)NULL); - ecore_shutdown(); - return 0; -} +#define MATCH(a, b) (!strncmp(a, b, strlen(a))) +#define SET_CONF(a, b) (a = (b > 0.0 ? b : a)) -int main(int argc, char **argv) -{ - ecore_init(); - return test_main(argc, argv); -} +struct parse_result { + char *section; + char *name; + char *value; +}; + +/** + * @brief Parse config file and call callback\n + * @param[in] file_name conf file. + * @param[in] cb cb is called when conf file is parsed line by line. + * @param[in] user_data user data is passed to cb. + * @return 0 on success, negative if failed + */ +int config_parse(const char *file_name, int cb(struct parse_result *result, + void *user_data), void *user_data); + +#endif diff --git a/src/core/core.c b/src/core/core.c deleted file mode 100644 index 1e685de..0000000 --- a/src/core/core.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * 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 "data.h" -#include "queue.h" -#include "log.h" -#include "predefine.h" -#include "core.h" -#include "devices.h" -#include "common.h" - -enum ss_core_cmd_type { - SS_CORE_ACT_RUN, - SS_CORE_ACT_CLEAR -}; - -struct _internal_msg { - int type; - int pid; -}; - -static int core_pipe[2]; -Ecore_Fd_Handler *g_pipe_efd = NULL; - -static int __pipe_start(struct ss_main_data *ad); -static int __pipe_stop(int fd); - -static int _ss_core_action_run(void *user_data, - struct ss_run_queue_entry *rq_entry) -{ - struct ss_action_entry *act_entry = rq_entry->action_entry; - int ret; - char tmp[128]; - - rq_entry->state = SS_STATE_RUNNING; - ret = act_entry->predefine_action(rq_entry->argc, rq_entry->argv); - if (ret <= 0) { - if (ret < 0) - _E("[SYSMAN] predefine action failed"); - goto fast_done; - } else { - snprintf(tmp, sizeof(tmp), "/proc/%d/status", ret); - if (access(tmp, R_OK) == 0) - rq_entry->forked_pid = ret; - else - goto fast_done; - } - return 0; - - fast_done: - rq_entry->forked_pid = -1; - rq_entry->state = SS_STATE_DONE; - ss_core_action_clear(-1); - return 0; -} - -static Eina_Bool core_pipe_cb(void *userdata, Ecore_Fd_Handler * fd_handler) -{ - struct ss_main_data *ad = (struct ss_main_data *)userdata; - struct _internal_msg p_msg; - int retry_count = 0; - int r = -1; - if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { - _E("ecore_main_fd_handler_active_get error , return"); - return EINA_TRUE; - } - - while (retry_count < 5) { - r = read(core_pipe[0], &p_msg, sizeof(struct _internal_msg)); - if (r < 0) { - if (errno == EINTR) { - _D("Re-read for error(EINTR)"); - retry_count++; - continue; - } else { - __pipe_stop(core_pipe[0]); - __pipe_stop(core_pipe[1]); - _D("restart pipe fd"); - __pipe_start(ad); - } - } else { - break; - } - } - - switch (p_msg.type) { - case SS_CORE_ACT_RUN: - ss_run_queue_run(SS_STATE_INIT, _ss_core_action_run, ad); - break; - case SS_CORE_ACT_CLEAR: - ss_run_queue_del_bypid(p_msg.pid); - break; - } - return EINA_TRUE; -} - -int ss_core_action_run() -{ - struct _internal_msg p_msg; - - p_msg.type = SS_CORE_ACT_RUN; - p_msg.pid = 0; - write(core_pipe[1], &p_msg, sizeof(struct _internal_msg)); - - return 0; -} - -int ss_core_action_clear(int pid) -{ - struct _internal_msg p_msg; - - p_msg.type = SS_CORE_ACT_CLEAR; - p_msg.pid = pid; - write(core_pipe[1], &p_msg, sizeof(struct _internal_msg)); - - return 0; -} - -static int __pipe_start(struct ss_main_data *ad) -{ - if (pipe(core_pipe) < 0) { - _E("pipe cannot create"); - exit(EXIT_FAILURE); - } - - g_pipe_efd = ecore_main_fd_handler_add(core_pipe[0], ECORE_FD_READ, - core_pipe_cb, ad, NULL, NULL); - if (!g_pipe_efd) { - _E("error ecore_main_fd_handler_add"); - return -1; - } - return 0; -} - -static int __pipe_stop(int fd) -{ - if (g_pipe_efd) { - ecore_main_fd_handler_del(g_pipe_efd); - g_pipe_efd = NULL; - } - if (fd >=0) - close(fd); - - return 0; -} - -static void core_init(void *data) -{ - struct ss_main_data *ad = (struct ss_main_data*)data; - - __pipe_stop(core_pipe[0]); - __pipe_stop(core_pipe[1]); - - if (__pipe_start(ad) == -1) - _E("fail pipe control fd init"); -} - -static const struct device_ops core_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "core", - .init = core_init, -}; - -DEVICE_OPS_REGISTER(&core_device_ops) diff --git a/src/core/device-change-handler.c b/src/core/device-change-handler.c index deca8eb..4765d11 100644 --- a/src/core/device-change-handler.c +++ b/src/core/device-change-handler.c @@ -17,6 +17,7 @@ */ +#include #include #include #include @@ -25,32 +26,28 @@ #include #include #include -#include -#include -#include #include -#include #include #include "dd-deviced.h" -#include "queue.h" #include "log.h" #include "device-notifier.h" #include "device-handler.h" #include "device-node.h" -#include "noti.h" -#include "data.h" -#include "predefine.h" #include "display/poll.h" #include "devices.h" -#include "sys_pci_noti/sys_pci_noti.h" #include "udev.h" #include "common.h" +#include "list.h" #include "proc/proc-handler.h" +#include "edbus-handler.h" +#include "devices.h" +#include "power-supply.h" +#include "display/setting.h" +#include "display/core.h" -#define PREDEF_USBCON "usbcon" -#define PREDEF_EARJACKCON "earjack_predef_internal" #define PREDEF_DEVICE_CHANGED "device_changed" -#define PREDEF_BATTERY_CF_OPENED "battery_cf_opened" +#define PREDEF_POWER_CHANGED POWER_SUBSYSTEM +#define PREDEF_UDEV_CONTROL UDEV #define TVOUT_X_BIN "/usr/bin/xberc" #define TVOUT_FLAG 0x00000001 @@ -58,9 +55,10 @@ #define MOVINAND_MOUNT_POINT "/opt/media" #define BUFF_MAX 255 #define SYS_CLASS_INPUT "/sys/class/input" -#define USBCON_EXEC_PATH PREFIX"/bin/usb-server" -#define DEFAULT_USB_INFO_PATH "/tmp/usb_default" -#define STORE_DEFAULT_USB_INFO "usb-devices > "DEFAULT_USB_INFO_PATH + +#define USB_STATE_PLATFORM_PATH "/sys/devices/platform/jack/usb_online" +#define USB_STATE_SWITCH_PATH "/sys/devices/virtual/switch/usb_cable/state" + #define HDMI_NOT_SUPPORTED (-1) #ifdef ENABLE_EDBUS_USE #include @@ -74,18 +72,6 @@ struct input_event { int value; }; -typedef enum { - DEVICE_NOTI_BATT_CHARGE = 0, - DEVICE_NOTI_BATT_LOW, - DEVICE_NOTI_BATT_FULL, - DEVICE_NOTI_MAX, -} cb_noti_type; - -typedef enum { - DEVICE_NOTI_OFF = 0, - DEVICE_NOTI_ON = 1, -} cb_noti_onoff_type; - enum snd_jack_types { SND_JACK_HEADPHONE = 0x0001, SND_JACK_MICROPHONE = 0x0002, @@ -98,40 +84,115 @@ enum snd_jack_types { #define CHANGE_ACTION "change" #define ENV_FILTER "CHGDET" -#define USB_NAME "usb" -#define USB_NAME_LEN 3 +#define USB_NAME "usb" +#define USB_NAME_LEN 3 + +#define CHARGER_NAME "charger" +#define CHARGER_NAME_LEN 7 + +#define EARJACK_NAME "earjack" +#define EARJACK_NAME_LEN 7 -#define CHARGER_NAME "charger" -#define CHARGER_NAME_LEN 7 +#define EARKEY_NAME "earkey" +#define EARKEY_NAME_LEN 6 -#define EARJACK_NAME "earjack" -#define EARJACK_NAME_LEN 7 +#define TVOUT_NAME "tvout" +#define TVOUT_NAME_LEN 5 -#define EARKEY_NAME "earkey" -#define EARKEY_NAME_LEN 6 +#define HDMI_NAME "hdmi" +#define HDMI_NAME_LEN 4 -#define TVOUT_NAME "tvout" -#define TVOUT_NAME_LEN 5 +#define HDCP_NAME "hdcp" +#define HDCP_NAME_LEN 4 -#define HDMI_NAME "hdmi" -#define HDMI_NAME_LEN 4 +#define HDMI_AUDIO_NAME "ch_hdmi_audio" +#define HDMI_AUDIO_LEN 13 -#define KEYBOARD_NAME "keyboard" -#define KEYBOARD_NAME_LEN 8 +#define CRADLE_NAME "cradle" +#define CRADLE_NAME_LEN 6 -#define POWER_SUPPLY_NAME_LEN 12 +#define KEYBOARD_NAME "keyboard" +#define KEYBOARD_NAME_LEN 8 + +#define POWER_SUPPLY_NAME_LEN 12 + +#define CHARGE_NAME_LEN 17 +#define BATTERY_NAME "battery" +#define BATTERY_NAME_LEN 7 +#define CHARGEFULL_NAME "Full" +#define CHARGEFULL_NAME_LEN 4 +#define CHARGENOW_NAME "Charging" +#define CHARGENOW_NAME_LEN 8 +#define DISCHARGE_NAME "Discharging" +#define DISCHARGE_NAME_LEN 11 +#define NOTCHARGE_NAME "Not charging" +#define NOTCHARGE_NAME_LEN 12 +#define OVERHEAT_NAME "Overheat" +#define OVERHEAT_NAME_LEN 8 +#define TEMPCOLD_NAME "Cold" +#define TEMPCOLD_NAME_LEN 4 +#define OVERVOLT_NAME "Over voltage" +#define OVERVOLT_NAME_LEN 12 #define SWITCH_DEVICE_USB "usb_cable" -#define ABNORMAL_POPUP_COUNTER 5 +#define METHOD_GET_HDMI "GetHDMI" +#define METHOD_GET_HDCP "GetHDCP" +#define METHOD_GET_HDMI_AUDIO "GetHDMIAudio" +#define SIGNAL_HDMI_STATE "ChangedHDMI" +#define SIGNAL_HDCP_STATE "ChangedHDCP" +#define SIGNAL_HDMI_AUDIO_STATE "ChangedHDMIAudio" + +#define HDCP_HDMI_VALUE(HDCP, HDMI) ((HDCP << 1) | HDMI) + +#define METHOD_GET_CRADLE "GetCradle" +#define SIGNAL_CRADLE_STATE "ChangedCradle" + +struct ticker_data { + char *name; + int type; +}; + +struct popup_data { + char *name; + char *key; + char *value; +}; + +struct siop_data { + int siop; + int rear; +}; static int ss_flags = 0; static int input_device_number; -static struct udev_monitor *mon = NULL; +/* Uevent */ static struct udev *udev = NULL; +/* Kernel Uevent */ +static struct udev_monitor *mon = NULL; static Ecore_Fd_Handler *ufdh = NULL; +static int ufd = -1; +static int hdmi_status = 0; + +enum udev_subsystem_type { + UDEV_INPUT, + UDEV_PLATFORM, + UDEV_POWER, + UDEV_SWITCH, +}; + +static const struct udev_subsystem { + const enum udev_subsystem_type type; + const char *str; + const char *devtype; +} udev_subsystems[] = { + { UDEV_INPUT, INPUT_SUBSYSTEM, NULL }, + { UDEV_PLATFORM, PLATFORM_SUBSYSTEM, NULL }, + { UDEV_POWER, POWER_SUBSYSTEM, NULL}, + { UDEV_SWITCH, SWITCH_SUBSYSTEM, NULL }, +}; static struct extcon_device { const enum extcon_type type; @@ -143,57 +204,8 @@ static struct extcon_device { { EXTCON_EARJACK, "/csa/factory/earjack_count", 0, 0}, }; -struct battery_status { - int capacity; - int charge_full; - int charge_now; - int health; - int present; -}; - -static struct battery_status battery; - -static Eina_Bool uevent_control_cb(void *data, Ecore_Fd_Handler *fd_handler); extern int battery_power_off_act(void *data); extern int battery_charge_err_act(void *data); -static int check_lowbat_charge_device(int bInserted) -{ - static int bChargeDeviceInserted = 0; - int val = -1; - int bat_state = -1; - int ret = -1; - if (bInserted == 1) { - if (battery.charge_now == 1) - bChargeDeviceInserted = 1; - return 0; - } else if (bInserted == 0) { - if (battery.charge_now == 0 && bChargeDeviceInserted == 1) { - bChargeDeviceInserted = 0; - //low bat popup during charging device removing - if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) == 0) { - if(bat_state < VCONFKEY_SYSMAN_BAT_NORMAL - || bat_state == VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF) { - bundle *b = NULL; - b = bundle_create(); - if(bat_state == VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF) - bundle_add(b,"_SYSPOPUP_CONTENT_", "poweroff"); - else - bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); - ret = syspopup_launch("lowbat-syspopup", b); - if (ret < 0) { - _E("popup lauch failed"); - } - bundle_free(b); - } - } else { - _E("failed to get vconf key"); - return -1; - } - } - return 0; - } - return -1; -} int extcon_set_count(int index) { @@ -287,30 +299,57 @@ static int extcon_count_init(void) return ret; } +int get_usb_state_direct(void) +{ + FILE *fp; + char str[2]; + int state; + char *path; + + if (access(USB_STATE_PLATFORM_PATH, F_OK) == 0) + path = USB_STATE_PLATFORM_PATH; + else if (access(USB_STATE_SWITCH_PATH, F_OK) == 0) + path = USB_STATE_SWITCH_PATH; + else { + _E("Cannot get direct path"); + return -ENOENT; + } + + fp = fopen(path, "r"); + if (!fp) { + _E("Cannot open jack node"); + return -ENOMEM; + } + + if (!fgets(str, sizeof(str), fp)) { + _E("cannot get string from jack node"); + fclose(fp); + return -ENOMEM; + } + + fclose(fp); + + return atoi(str); +} + static void usb_chgdet_cb(void *data) { int val = -1; int ret = 0; char params[BUFF_MAX]; - predefine_pm_change_state(LCD_NORMAL); - - /* check charging now */ - ss_lowbat_is_charge_in_now(); - /* check current battery level */ - ss_lowbat_monitor(NULL); - action_entry_call_internal(PREDEF_USBCON, 0); - if (data == NULL) ret = device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_USB_ONLINE, &val); else val = *(int *)data; if (ret == 0) { + if (val < 0) + val = get_usb_state_direct(); + _I("jack - usb changed %d",val); check_lowbat_charge_device(val); if (val==1) { - snprintf(params, sizeof(params), "%d", DEVICE_NOTI_BATT_CHARGE); - ss_launch_if_noexist("/usr/bin/sys_device_noti", params); + battery_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); _D("usb device notification"); } } else { @@ -318,75 +357,184 @@ static void usb_chgdet_cb(void *data) } } -static void __sync_usb_status(void) +static int display_changed(void *data) { - int val = -1; - int status = -1; - if ((device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_USB_ONLINE, &val) != 0) || - vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS,&status) != 0) + enum state_t state = (enum state_t)data; + int ret, cradle = 0; + + if (battery.charge_now == CHARGER_ABNORMAL && battery.health == HEALTH_BAD) { + pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); + return 0; + } + + if (state != S_NORMAL) + return 0; + + ret = vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &cradle); + if (ret >= 0 && cradle == DOCK_SOUND) { + pm_lock_internal(getpid(), LCD_DIM, STAY_CUR_STATE, 0); + _I("sound dock is connected! dim lock is on."); + } + if (hdmi_status) { + pm_lock_internal(getpid(), LCD_DIM, STAY_CUR_STATE, 0); + _I("hdmi is connected! dim lock is on."); + } + return 0; +} + +static void cradle_send_broadcast(int status) +{ + static int old = 0; + char *arr[1]; + char str_status[32]; + + if (old == status) return; - if ((val == 1 && status == VCONFKEY_SYSMAN_USB_DISCONNECTED) || - (val == 0 && status == VCONFKEY_SYSMAN_USB_AVAILABLE)) - action_entry_call_internal(PREDEF_USBCON, 0); + + _I("broadcast cradle status %d", status); + old = status; + snprintf(str_status, sizeof(str_status), "%d", status); + arr[0] = str_status; + + broadcast_edbus_signal(DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + SIGNAL_CRADLE_STATE, "i", arr); } -static void ta_chgdet_cb(struct ss_main_data *ad) +static int cradle_cb(void *data) { - int val = -1; - int ret = -1; - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; - char params[BUFF_MAX]; + static int old = 0; + int val = 0; + int ret = 0; + + if (data == NULL) + return old; - predefine_pm_change_state(LCD_NORMAL); + val = *(int *)data; - /* check charging now */ - ss_lowbat_is_charge_in_now(); - /* check current battery level */ - ss_lowbat_monitor(NULL); + if (old == val) + return old; - if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_TA_ONLINE, &val) == 0) { - _I("jack - ta changed %d",val); - check_lowbat_charge_device(val); - vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, val); - if (val == 0) { - pm_unlock_internal(getpid(), LCD_OFF, STAY_CUR_STATE); - } else { - pm_lock_internal(getpid(), LCD_OFF, STAY_CUR_STATE, 0); - snprintf(params, sizeof(params), "%d", DEVICE_NOTI_BATT_CHARGE); - ss_launch_if_noexist("/usr/bin/sys_device_noti", params); - _D("ta device notification"); - device_notify(DEVICE_NOTIFIER_TA, (void *)TRUE); + old = val; + cradle_send_broadcast(old); + return old; +} + +static void cradle_chgdet_cb(void *data) +{ + int val; + int ret = 0; + + pm_change_internal(getpid(), LCD_NORMAL); + + if (data) + val = *(int *)data; + else { + ret = device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_CRADLE_ONLINE, &val); + if (ret != 0) { + _E("failed to get status"); + return; } - __sync_usb_status(); } - else - _E("failed to get ta status"); + + _I("jack - cradle changed %d", val); + cradle_cb((void *)&val); + if (vconf_set_int(VCONFKEY_SYSMAN_CRADLE_STATUS, val) != 0) { + _E("failed to set vconf status"); + return; + } + + if (val == DOCK_SOUND) + pm_lock_internal(getpid(), LCD_DIM, STAY_CUR_STATE, 0); + else if (val == DOCK_NONE) + pm_unlock_internal(getpid(), LCD_DIM, PM_SLEEP_MARGIN); } -static void earjack_chgdet_cb(struct ss_main_data *ad) +void sync_cradle_status(void) { - _I("jack - earjack changed"); - action_entry_call_internal(PREDEF_EARJACKCON, 0); + int val; + int status; + if ((device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_CRADLE_ONLINE, &val) != 0) || + vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &status) != 0) + return; + if ((val != 0 && status == 0) || (val == 0 && status != 0)) + cradle_chgdet_cb(NULL); } -static void earkey_chgdet_cb(struct ss_main_data *ad) +static void earkey_chgdet_cb(void *data) { int val; - _I("jack - earkey changed"); - if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_EARKEY_ONLINE, &val) == 0) - vconf_set_int(VCONFKEY_SYSMAN_EARJACKKEY, val); + int ret = 0; + + if (data) + val = *(int *)data; + else { + ret = device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_EARKEY_ONLINE, &val); + if (ret != 0) { + _E("failed to get status"); + return; + } + } + _I("jack - earkey changed %d", val); + vconf_set_int(VCONFKEY_SYSMAN_EARJACKKEY, val); } -static void tvout_chgdet_cb(struct ss_main_data *ad) +static void tvout_chgdet_cb(void *data) { _I("jack - tvout changed"); pm_change_internal(getpid(), LCD_NORMAL); } -static void hdmi_chgdet_cb(struct ss_main_data *ad) +static void hdcp_hdmi_send_broadcast(int status) +{ + static int old = 0; + char *arr[1]; + char str_status[32]; + + if (old == status) + return; + + _I("broadcast hdmi status %d", status); + old = status; + snprintf(str_status, sizeof(str_status), "%d", status); + arr[0] = str_status; + + broadcast_edbus_signal(DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + SIGNAL_HDMI_STATE, "i", arr); +} + +static int hdcp_hdmi_cb(void *data) +{ + static int old = 0; + int val = 0; + int ret = 0; + + if (data == NULL) + return old; + + val = *(int *)data; + val = HDCP_HDMI_VALUE(val, hdmi_status); + + if (old == val) + return old; + + old = val; + hdcp_hdmi_send_broadcast(old); + return old; +} + +static int hdmi_cec_execute(void *data) +{ + static const struct device_ops *ops = NULL; + + FIND_DEVICE_INT(ops, "hdmi-cec"); + + return ops->execute(data); +} + +static void hdmi_chgdet_cb(void *data) { int val; - int ret = -1; + int ret = 0; pm_change_internal(getpid(), LCD_NORMAL); if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_HDMI_SUPPORT, &val) == 0) { @@ -396,165 +544,124 @@ static void hdmi_chgdet_cb(struct ss_main_data *ad) return; } } - if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_HDMI_ONLINE, &val) == 0) { - _I("jack - hdmi changed %d", val); - vconf_set_int(VCONFKEY_SYSMAN_HDMI,val); - if(val == 1) - pm_lock_internal(getpid(), LCD_NORMAL, GOTO_STATE_NOW, 0); - else - pm_unlock_internal(getpid(), LCD_NORMAL, PM_SLEEP_MARGIN); - } else { - _E("failed to get hdmi_online status"); + + if (data) + val = *(int *)data; + else { + ret = device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_HDMI_ONLINE, &val); + if (ret != 0) { + _E("failed to get status"); + return; + } } -} -static void keyboard_chgdet_cb(struct ss_main_data *ad) -{ - int val = -1; + _I("jack - hdmi changed %d", val); + vconf_set_int(VCONFKEY_SYSMAN_HDMI, val); + hdmi_status = val; + device_notify(DEVICE_NOTIFIER_HDMI, (void *)val); - if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_KEYBOARD_ONLINE, &val) == 0) { - _I("jack - keyboard changed %d", val); - if(val != 1) - val = 0; - vconf_set_int(VCONFKEY_SYSMAN_SLIDING_KEYBOARD, val); + if(val == 1) { + pm_lock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, STAY_CUR_STATE, 0); } else { - vconf_set_int(VCONFKEY_SYSMAN_SLIDING_KEYBOARD, VCONFKEY_SYSMAN_SLIDING_KEYBOARD_NOT_SUPPORTED); + pm_unlock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, PM_SLEEP_MARGIN); } + hdmi_cec_execute((void *)val); } -static void mmc_chgdet_cb(void *data) +static void hdcp_send_broadcast(int status) { - static int inserted; - int ret = -1; - int val = -1; + static int old = 0; + char *arr[1]; + char str_status[32]; - if (data == NULL) { - _I("mmc removed"); - ss_mmc_removed(); - inserted = 0; - } else { - _I("mmc added"); - if (inserted) - return; - inserted = 1; - ret = ss_mmc_inserted(); - if (ret == -1) { - vconf_get_int(VCONFKEY_SYSMAN_MMC_MOUNT,&val); - if (val == VCONFKEY_SYSMAN_MMC_MOUNT_FAILED) { - bundle *b = NULL; - b = bundle_create(); - if (b == NULL) { - _E("error bundle_create()"); - return; - } - bundle_add(b, "_SYSPOPUP_CONTENT_", "mounterr"); - ret = syspopup_launch("mmc-syspopup", b); - if (ret < 0) { - _E("popup launch failed"); - } - bundle_free(b); - } else if (val == VCONFKEY_SYSMAN_MMC_MOUNT_COMPLETED) { - bundle *b = NULL; - b = bundle_create(); - if (b == NULL) { - _E("error bundle_create()"); - return; - } - bundle_add(b, "_SYSPOPUP_CONTENT_", "mountrdonly"); - ret = syspopup_launch("mmc-syspopup", b); - if (ret < 0) { - _E("popup launch failed"); - } - bundle_free(b); - } - } - } -} + if (old == status) + return; -static void ums_unmount_cb(void *data) -{ - umount(MOVINAND_MOUNT_POINT); + _D("broadcast hdcp status %d", status); + old = status; + snprintf(str_status, sizeof(str_status), "%d", status); + arr[0] = str_status; + + broadcast_edbus_signal(DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + SIGNAL_HDCP_STATE, "i", arr); } -static int __check_abnormal_popup_launch(void) +static int hdcp_chgdet_cb(void *data) { - static int noti_count = 0; - if (noti_count >= ABNORMAL_POPUP_COUNTER) { - noti_count = 0; - return 0; - } else { - noti_count++; - return -EAGAIN; - } + static int old = 0; + int val = 0; + + if (data == NULL) + return old; + + val = *(int *)data; + if (old == val) + return old; + + old = val; + hdcp_send_broadcast(old); + return old; } -static void charge_cb(struct ss_main_data *ad) +static void hdmi_audio_send_broadcast(int status) { - int val = -1; - int charge_now = -1; - int capacity = -1; - int ret; - char params[BUFF_MAX]; - static int bat_full_noti = 0; - static int present_status = 1; - - ss_lowbat_monitor(NULL); + static int old = 0; + char *arr[1]; + char str_status[32]; - if (device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CHARGE_NOW, &charge_now) != 0 || - device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY, &capacity) != 0) - _E("fail to get battery node value"); - if (charge_now == 0 && capacity == 0) { - _I("target will be shut down"); - battery_power_off_act(NULL); + if (old == status) return; - } - ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_PRESENT, &val); - if (ret != 0) - _E("fail to get battery present value"); - if (val == 0 && present_status == 1) { - present_status = 0; - _I("battery cf is opened"); - if (charge_now) - action_entry_call_internal(PREDEF_BATTERY_CF_OPENED, 0); - } + _D("broadcast hdmi audio status %d", status); + old = status; + snprintf(str_status, sizeof(str_status), "%d", status); + arr[0] = str_status; - if (val == 1 && present_status == 0) { - present_status = 1; - _I("battery cf is closed again"); - } + broadcast_edbus_signal(DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + SIGNAL_HDMI_AUDIO_STATE, "i", arr); +} + +static int hdmi_audio_chgdet_cb(void *data) +{ + static int old = 0; + int val = 0; + + if (data == NULL) + return old; - if (device_get_property(DEVICE_TYPE_POWER, PROP_POWER_HEALTH, &val) == 0) { - if (val==BATTERY_OVERHEAT || val==BATTERY_COLD) { - _I("Battery health status is not good (%d)", val); + val = *(int *)data; + if (old == val) + return old; - if (__check_abnormal_popup_launch() != 0) - return; + old = val; + hdmi_audio_send_broadcast(old); + return old; +} - if (device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY, &val) == 0 && val <= 0) - battery_power_off_act(NULL); - else - battery_charge_err_act(NULL); +static void keyboard_chgdet_cb(void *data) +{ + int val = -1; + int ret = 0; + + if (data) + val = *(int *)data; + else { + ret = device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_KEYBOARD_ONLINE, &val); + if (ret != 0) { + _E("failed to get status"); + vconf_set_int(VCONFKEY_SYSMAN_SLIDING_KEYBOARD, VCONFKEY_SYSMAN_SLIDING_KEYBOARD_NOT_SUPPORTED); return; } - } else { - _E("failed to get battery health status"); - } - device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CHARGE_FULL, &val); - if (val==0) { - if (bat_full_noti==1) { - snprintf(params, sizeof(params), "%d %d", DEVICE_NOTI_BATT_FULL, DEVICE_NOTI_OFF); - ss_launch_if_noexist("/usr/bin/sys_device_noti", params); - } - bat_full_noti = 0; - } else { - if (val==1 && bat_full_noti==0) { - bat_full_noti = 1; - _D("battery full noti"); - snprintf(params, sizeof(params), "%d %d", DEVICE_NOTI_BATT_FULL, DEVICE_NOTI_ON); - ss_launch_if_noexist("/usr/bin/sys_device_noti", params); - } } + _I("jack - keyboard changed %d", val); + if(val != 1) + val = 0; + vconf_set_int(VCONFKEY_SYSMAN_SLIDING_KEYBOARD, val); +} + +static void ums_unmount_cb(void *data) +{ + umount(MOVINAND_MOUNT_POINT); } #ifdef ENABLE_EDBUS_USE @@ -562,9 +669,6 @@ static void cb_xxxxx_signaled(void *data, DBusMessage * msg) { char *args; DBusError err; - struct ss_main_data *ad; - - ad = data; dbus_error_init(&err); if (dbus_message_get_args @@ -576,47 +680,269 @@ static void cb_xxxxx_signaled(void *data, DBusMessage * msg) } #endif /* ENABLE_EDBUS_USE */ -static void usb_host_chgdet_cb(keynode_t *in_key, struct ss_main_data *ad) +static void check_capacity_status(const char *env_value) { - int status; - int ret = vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &status); - if (ret != 0) { - _E("vconf get failed(VCONFKEY_SYSMAN_USB_HOST_STATUS)"); - return ; + if (env_value == NULL) + return; + battery.capacity = atoi(env_value); +} + +static void check_charge_status(const char *env_value) +{ + if (env_value == NULL) + return; + if (strncmp(env_value, CHARGEFULL_NAME , CHARGEFULL_NAME_LEN) == 0) { + battery.charge_full = CHARGING_FULL; + battery.charge_now = CHARGER_DISCHARGING; + } else if (strncmp(env_value, CHARGENOW_NAME, CHARGENOW_NAME_LEN) == 0) { + battery.charge_full = CHARGING_NOT_FULL; + battery.charge_now = CHARGER_CHARGING; + } else if (strncmp(env_value, DISCHARGE_NAME, DISCHARGE_NAME_LEN) == 0) { + battery.charge_full = CHARGING_NOT_FULL; + battery.charge_now = CHARGER_DISCHARGING; + } else if (strncmp(env_value, NOTCHARGE_NAME, NOTCHARGE_NAME_LEN) == 0) { + battery.charge_full = CHARGING_NOT_FULL; + battery.charge_now = CHARGER_ABNORMAL; + } else { + battery.charge_full = CHARGING_NOT_FULL; + battery.charge_now = CHARGER_DISCHARGING; } +} - if(VCONFKEY_SYSMAN_USB_HOST_CONNECTED == status) { - int pid = ss_launch_if_noexist(USBCON_EXEC_PATH, NULL); - if (pid < 0) { - _E("usb-server launching failed"); - return; - } +static void check_health_status(const char *env_value) +{ + if (env_value == NULL) { + battery.health = HEALTH_GOOD; + battery.temp = TEMP_LOW; + battery.ovp = OVP_NORMAL; + return; + } + if (strncmp(env_value, OVERHEAT_NAME, OVERHEAT_NAME_LEN) == 0) { + battery.health = HEALTH_BAD; + battery.temp = TEMP_HIGH; + battery.ovp = OVP_NORMAL; + } else if (strncmp(env_value, TEMPCOLD_NAME, TEMPCOLD_NAME_LEN) == 0) { + battery.health = HEALTH_BAD; + battery.temp = TEMP_LOW; + battery.ovp = OVP_NORMAL; + } else if (strncmp(env_value, OVERVOLT_NAME, OVERVOLT_NAME_LEN) == 0) { + battery.health = HEALTH_GOOD; + battery.temp = TEMP_LOW; + battery.ovp = OVP_ABNORMAL; + } else { + battery.health = HEALTH_GOOD; + battery.temp = TEMP_LOW; + battery.ovp = OVP_NORMAL; } } -static void usb_host_add_cb() +static void check_online_status(const char *env_value) { - int status; - int ret = vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &status); - if (ret != 0) { - _E("vconf get failed ()"); + if (env_value == NULL) return; + battery.online = atoi(env_value); +} + +static void check_present_status(const char *env_value) +{ + if (env_value == NULL) { + battery.present = PRESENT_NORMAL; + return; + } + battery.present = atoi(env_value); +} + +static int earjack_execute(void *data) +{ + static const struct device_ops *ops = NULL; + + FIND_DEVICE_INT(ops, "earjack"); + + return ops->execute(data); +} + +static int siop_execute(const char *siop, const char *rear) +{ + static const struct device_ops *ops = NULL; + struct siop_data params; + + FIND_DEVICE_INT(ops, PROC_OPS_NAME); + + if (!siop) + params.siop = 0; + else + params.siop = atoi(siop); + if (!rear) + params.rear = 0; + else + params.rear = atoi(rear); + return ops->execute((void *)¶ms); +} + +static int changed_device(const char *name, const char *value) +{ + int val = 0; + int *state = NULL; + int i; + + if (!name) + goto out; + + if (value) { + val = atoi(value); + state = &val; + } + + if (strncmp(name, USB_NAME, USB_NAME_LEN) == 0) + usb_chgdet_cb((void *)state); + else if (strncmp(name, EARJACK_NAME, EARJACK_NAME_LEN) == 0) + earjack_execute((void *)state); + else if (strncmp(name, EARKEY_NAME, EARKEY_NAME_LEN) == 0) + earkey_chgdet_cb((void *)state); + else if (strncmp(name, TVOUT_NAME, TVOUT_NAME_LEN) == 0) + tvout_chgdet_cb((void *)state); + else if (strncmp(name, HDMI_NAME, HDMI_NAME_LEN) == 0) + hdmi_chgdet_cb((void *)state); + else if (strncmp(name, HDCP_NAME, HDCP_NAME_LEN) == 0) { + hdcp_chgdet_cb((void *)state); + hdcp_hdmi_cb((void *)state); + } + else if (strncmp(name, HDMI_AUDIO_NAME, HDMI_AUDIO_LEN) == 0) + hdmi_audio_chgdet_cb((void *)state); + else if (strncmp(name, CRADLE_NAME, CRADLE_NAME_LEN) == 0) + cradle_chgdet_cb((void *)state); + else if (strncmp(name, KEYBOARD_NAME, KEYBOARD_NAME_LEN) == 0) + keyboard_chgdet_cb((void *)state); + else if (strncmp(name, POWER_SUBSYSTEM, POWER_SUPPLY_NAME_LEN) == 0) + power_supply((void *)state); +out: + return 0; +} + +static int booting_done(void *data) +{ + static int done = 0; + int ret; + int val; + + if (data == NULL) + return done; + done = (int)data; + if (done == 0) + return done; + + _I("booting done"); + + power_supply_timer_stop(); + power_supply_init(NULL); + + /* set initial state for devices */ + input_device_number = 0; + cradle_chgdet_cb(NULL); + keyboard_chgdet_cb(NULL); + hdmi_chgdet_cb(NULL); + return done; +} + +static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handler) +{ + struct udev_device *dev = NULL; + struct udev_list_entry *list_entry = NULL; + const char *subsystem = NULL; + const char *env_name = NULL; + const char *env_value = NULL; + const char *devpath; + const char *devnode; + const char *action; + int ret = -1; + int i, len; + + if ((dev = udev_monitor_receive_device(mon)) == NULL) + return EINA_TRUE; + + subsystem = udev_device_get_subsystem(dev); + + for (i = 0; i < ARRAY_SIZE(udev_subsystems); i++) { + len = strlen(udev_subsystems[i].str); + if (!strncmp(subsystem, udev_subsystems[i].str, len)) + break; } - if (-1 == status) { /* '-1' means that USB host mode is not loaded yet */ - _D("This usb device is connected defaultly"); + if (i >= ARRAY_SIZE(udev_subsystems)) + goto out; + + devpath = udev_device_get_devpath(dev); - ret = system(STORE_DEFAULT_USB_INFO); - _D("Return value of usb-devices: %d\n", ret); - if (0 != access(DEFAULT_USB_INFO_PATH, F_OK)) { - ret = system(STORE_DEFAULT_USB_INFO); - _D("Return value of usb-devices: %d\n", ret); + switch (udev_subsystems[i].type) { + case UDEV_INPUT: + /* check new input device */ + if (!fnmatch(INPUT_PATH, devpath, 0)) { + action = udev_device_get_action(dev); + devnode = udev_device_get_devnode(dev); + if (!strcmp(action, UDEV_ADD)) + device_notify(DEVICE_NOTIFIER_INPUT_ADD, (void *)devnode); + else if (!strcmp(action, UDEV_REMOVE)) + device_notify(DEVICE_NOTIFIER_INPUT_REMOVE, (void *)devnode); + goto out; + } + break; + case UDEV_SWITCH: + env_name = udev_device_get_property_value(dev, "SWITCH_NAME"); + env_value = udev_device_get_property_value(dev, "SWITCH_STATE"); + changed_device(env_name, env_value); + break; + case UDEV_PLATFORM: + env_value = udev_device_get_property_value(dev, ENV_FILTER); + if (!env_value) + break; + changed_device(env_value, NULL); + break; + case UDEV_POWER: + udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(dev)) { + env_name = udev_list_entry_get_name(list_entry); + if (env_name == NULL) + continue; + if (strncmp(env_name, CHARGE_NAME, CHARGE_NAME_LEN) == 0) { + env_value = udev_list_entry_get_value(list_entry); + if (env_value == NULL) + continue; + if (strncmp(env_value, BATTERY_NAME, BATTERY_NAME_LEN) == 0) { + ret = 0; + break; + } + } } + if (ret != 0) + goto out; + env_value = udev_device_get_property_value(dev, CHARGE_STATUS); + check_charge_status(env_value); + env_value = udev_device_get_property_value(dev, CHARGE_ONLINE); + check_online_status(env_value); + env_value = udev_device_get_property_value(dev, CHARGE_HEALTH); + check_health_status(env_value); + env_value = udev_device_get_property_value(dev, CHARGE_PRESENT); + check_present_status(env_value); + env_value = udev_device_get_property_value(dev, CAPACITY); + check_capacity_status(env_value); + ret = booting_done(NULL); + if (ret) + battery_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); + if (env_value) + changed_device(subsystem, env_value); + else + changed_device(subsystem, NULL); + break; } + +out: + udev_device_unref(dev); + return EINA_TRUE; } -static int uevent_control_stop(int ufd) +static int uevent_kernel_control_stop(void) { + struct udev_device *dev = NULL; + if (ufdh) { ecore_main_fd_handler_del(ufdh); ufdh = NULL; @@ -626,6 +952,11 @@ static int uevent_control_stop(int ufd) ufd = -1; } if (mon) { + dev = udev_monitor_receive_device(mon); + if (dev) { + udev_device_unref(dev); + dev = NULL; + } udev_monitor_unref(mon); mon = NULL; } @@ -636,352 +967,362 @@ static int uevent_control_stop(int ufd) return 0; } -static int uevent_control_start(void) +static int uevent_kernel_control_start(void) { - int ufd = -1; + int i, ret; - udev = udev_new(); - if (!udev) { - _E("error create udev"); + if (udev && mon) { + _E("uevent control routine is alreay started"); return -EINVAL; } - mon = udev_monitor_new_from_netlink(udev, "kernel"); + if (!udev) { + udev = udev_new(); + if (!udev) { + _E("error create udev"); + return -EINVAL; + } + } + + mon = udev_monitor_new_from_netlink(udev, UDEV); if (mon == NULL) { _E("error udev_monitor create"); - uevent_control_stop(-1); - return -EINVAL; + goto stop; } - if (udev_monitor_set_receive_buffer_size(mon, 1024) != 0) { + if (udev_monitor_set_receive_buffer_size(mon, UDEV_MONITOR_SIZE) != 0) { _E("fail to set receive buffer size"); - return -EINVAL; + goto stop; } - if (udev_monitor_filter_add_match_subsystem_devtype(mon, "platform", NULL) < 0 || - udev_monitor_filter_add_match_subsystem_devtype(mon, "input", NULL) < 0) { - _E("error apply subsystem filter"); - uevent_control_stop(-1); - return -1; + for (i = 0; i < ARRAY_SIZE(udev_subsystems); i++) { + ret = udev_monitor_filter_add_match_subsystem_devtype(mon, + udev_subsystems[i].str, udev_subsystems[i].devtype); + if (ret < 0) { + _E("error apply subsystem filter"); + goto stop; + } } + ret = udev_monitor_filter_update(mon); + if (ret < 0) + _E("error udev_monitor_filter_update"); + ufd = udev_monitor_get_fd(mon); if (ufd == -1) { _E("error udev_monitor_get_fd"); - uevent_control_stop(ufd); - return -EINVAL; + goto stop; } - ufdh = ecore_main_fd_handler_add(ufd, ECORE_FD_READ, uevent_control_cb, NULL, NULL, NULL); + ufdh = ecore_main_fd_handler_add(ufd, ECORE_FD_READ, + uevent_kernel_control_cb, NULL, NULL, NULL); if (!ufdh) { _E("error ecore_main_fd_handler_add"); - uevent_control_stop(ufd); - return -EINVAL; + goto stop; } if (udev_monitor_enable_receiving(mon) < 0) { _E("error unable to subscribe to udev events"); - uevent_control_stop(ufd); - return -EINVAL; + goto stop; } return 0; +stop: + uevent_kernel_control_stop(); + return -EINVAL; + } -static void power_supply(void *data) +int uevent_udev_get_path(const char *subsystem, dd_list **list) { - static int old; + struct udev_enumerate *enumerate = NULL; + struct udev_list_entry *devices, *dev_list_entry; int ret; - char params[BUFF_MAX]; - static int bat_full_noti = 0; - static int present_status = 1; - - ss_lowbat_monitor(NULL); - if ((battery.charge_now == 1 || battery.charge_full == 1) && - old == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED) { - old = VCONFKEY_SYSMAN_CHARGER_CONNECTED; - vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, old); - } else if (battery.charge_now == 0 && battery.charge_full == 0 && - old == VCONFKEY_SYSMAN_CHARGER_CONNECTED) { - old = VCONFKEY_SYSMAN_CHARGER_DISCONNECTED; - vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, old); + if (!udev) { + udev = udev_new(); + if (!udev) { + _E("error create udev"); + return -EIO; + } } - if (battery.charge_now == 0 && battery.capacity == 0) { - _I("target will be shut down"); - battery_power_off_act(NULL); - return; - } + enumerate = udev_enumerate_new(udev); + if (!enumerate) + return -EIO; - if (battery.present == 0 && present_status == 1) { - present_status = 0; - _I("battery cf is opened"); - if (battery.charge_now) - action_entry_call_internal(PREDEF_BATTERY_CF_OPENED, 0); - } + ret = udev_enumerate_add_match_subsystem(enumerate, subsystem); + if (ret < 0) + return -EIO; - if (battery.present == 1 && present_status == 0) { - present_status = 1; - _I("battery cf is closed again"); - } - if (battery.health == 0) { - _I("Battery health status is not good"); - if (__check_abnormal_popup_launch() != 0) - return; - if (battery.capacity <= 0) - battery_power_off_act(NULL); - else - battery_charge_err_act(NULL); - return; - } + ret = udev_enumerate_scan_devices(enumerate); + if (ret < 0) + return -EIO; - if (battery.charge_full == 0) { - if (bat_full_noti==1) { - snprintf(params, sizeof(params), "%d %d", DEVICE_NOTI_BATT_FULL, DEVICE_NOTI_OFF); - ss_launch_if_noexist("/usr/bin/sys_device_noti", params); - } - bat_full_noti = 0; - } else { - if (battery.charge_full==1 && bat_full_noti==0) { - bat_full_noti = 1; - _D("battery full noti"); - snprintf(params, sizeof(params), "%d %d", DEVICE_NOTI_BATT_FULL, DEVICE_NOTI_ON); - ss_launch_if_noexist("/usr/bin/sys_device_noti", params); - } + devices = udev_enumerate_get_list_entry(enumerate); + + udev_list_entry_foreach(dev_list_entry, devices) { + const char *path; + path = udev_list_entry_get_name(dev_list_entry); + _D("subsystem : %s, path : %s", subsystem, path); + DD_LIST_APPEND(*list, (void*)path); } + return 0; } -static Eina_Bool uevent_control_cb(void *data, Ecore_Fd_Handler *fd_handler) +static DBusMessage *dbus_cradle_handler(E_DBus_Object *obj, DBusMessage *msg) { - struct udev_device *dev = NULL; - struct udev_list_entry *list_entry = NULL; - const char *env_name = NULL; - const char *env_value = NULL; - const char *devpath; - const char *devnode; - const char *action; - int ufd = -1; - int ret = -1; - int i, len; + DBusMessageIter iter; + DBusMessage *reply; + int ret; - if (!ecore_main_fd_handler_active_get(fd_handler,ECORE_FD_READ)) - goto out; - if ((ufd = ecore_main_fd_handler_fd_get(fd_handler)) == -1) - goto out; - if ((dev = udev_monitor_receive_device(mon)) == NULL) - goto out; + ret = cradle_cb(NULL); + _I("cradle %d", ret); - env_name = udev_device_get_subsystem(dev); - if (strncmp(env_name, INPUT_SUBSYSTEM, strlen(INPUT_SUBSYSTEM)) == 0) { - devpath = udev_device_get_devpath(dev); - /* check new input device */ - if (!fnmatch(INPUT_PATH, devpath, 0)) { - action = udev_device_get_action(dev); - devnode = udev_device_get_devnode(dev); - if (!strcmp(action, ADD)) - device_notify(DEVICE_NOTIFIER_INPUT_ADD, (void *)devnode); - else if (!strcmp(action, REMOVE)) - device_notify(DEVICE_NOTIFIER_INPUT_REMOVE, (void *)devnode); - udev_device_unref(dev); - uevent_control_stop(ufd); - uevent_control_start(); - return EINA_TRUE; - } - } + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} - udev_list_entry_foreach(list_entry,udev_device_get_properties_list_entry(dev)) { - env_name = udev_list_entry_get_name(list_entry); - if (strncmp(env_name, ENV_FILTER, strlen(ENV_FILTER)) == 0) { - env_value = udev_list_entry_get_value(list_entry); - ret = 0; - break; - } - } +static DBusMessage *dbus_hdcp_hdmi_handler(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret; - if (ret != 0) { - udev_device_unref(dev); - goto out; - } + ret = hdcp_hdmi_cb(NULL); + _I("hdmi %d", ret); - _I("UEVENT DETECTED (%s)", env_value); - action_entry_call_internal(PREDEF_DEVICE_CHANGED,1,env_value); + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} - udev_device_unref(dev); - uevent_control_stop(ufd); - uevent_control_start(); -out: - return EINA_TRUE; +static DBusMessage *dbus_hdcp_handler(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret; + + ret = hdcp_chgdet_cb(NULL); + _I("hdcp %d", ret); + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; } -static int changed_device(int argc, char **argv) +static DBusMessage *dbus_hdmi_audio_handler(E_DBus_Object *obj, DBusMessage *msg) { - int val = 0; - int *state = NULL; - int i; + DBusMessageIter iter; + DBusMessage *reply; + int ret; - for (i = 0 ; i < argc ; i++) { - if (argv[i] == NULL) { - _E("param is failed"); - return -EINVAL; - } + ret = hdmi_audio_chgdet_cb(NULL); + _I("hdmi audio %d", ret); + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static DBusMessage *dbus_device_handler(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusError err; + DBusMessageIter iter; + DBusMessage *reply; + pid_t pid; + int ret; + int argc; + char *type_str; + char *argv[2]; + + dbus_error_init(&err); + + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &type_str, + DBUS_TYPE_INT32, &argc, + DBUS_TYPE_STRING, &argv[0], + DBUS_TYPE_STRING, &argv[1], DBUS_TYPE_INVALID)) { + _E("there is no message"); + ret = -EINVAL; + goto out; } - if (argc == 2) { - if (argv[1] == NULL) - val = 0; - else - val = atoi(argv[1]); - state = &val; + if (argc < 0) { + _E("message is invalid!"); + ret = -EINVAL; + goto out; } - if (strncmp(argv[0], USB_NAME, USB_NAME_LEN) == 0) - usb_chgdet_cb(state); - else if (strncmp(argv[0], EARJACK_NAME, EARJACK_NAME_LEN) == 0) - earjack_chgdet_cb((void *)state); - else if (strncmp(argv[0], EARKEY_NAME, EARKEY_NAME_LEN) == 0) - earkey_chgdet_cb((void *)state); - else if (strncmp(argv[0], TVOUT_NAME, TVOUT_NAME_LEN) == 0) - tvout_chgdet_cb((void *)state); - else if (strncmp(argv[0], HDMI_NAME, HDMI_NAME_LEN) == 0) - hdmi_chgdet_cb((void *)state); - else if (strncmp(argv[0], KEYBOARD_NAME, KEYBOARD_NAME_LEN) == 0) - keyboard_chgdet_cb((void *)state); - else if (strncmp(argv[0], POWER_SUBSYSTEM, POWER_SUPPLY_NAME_LEN) == 0) - power_supply(state); + pid = get_edbus_sender_pid(msg); + if (kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored!", pid); + ret = -ESRCH; + goto out; + } - return 0; + changed_device(argv[0], argv[1]); + +out: + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + + return reply; } -static int changed_dev_usb(int argc, char **argv) +static DBusMessage *dbus_battery_handler(E_DBus_Object *obj, DBusMessage *msg) { - int pid; - int val = -1; - int ret = -1; - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; - - if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_USB_ONLINE, &val) == 0) { - if (val == 0) { - vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, - VCONFKEY_SYSMAN_USB_DISCONNECTED); - pm_unlock_internal(getpid(), LCD_OFF, STAY_CUR_STATE); - return 0; - } - if ( vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &val) == 0 && val == VCONFKEY_SYSMAN_USB_AVAILABLE) - return 0; - vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, - VCONFKEY_SYSMAN_USB_AVAILABLE); - pm_lock_internal(getpid(), LCD_OFF, STAY_CUR_STATE, 0); - pid = ss_launch_if_noexist(USBCON_EXEC_PATH, NULL); - if (pid < 0) { - _E("usb predefine action failed\n"); - return -1; - } - return pid; + DBusError err; + DBusMessageIter iter; + DBusMessage *reply; + pid_t pid; + int ret; + int argc; + char *type_str; + char *argv[5]; + + dbus_error_init(&err); + + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &type_str, + DBUS_TYPE_INT32, &argc, + DBUS_TYPE_STRING, &argv[0], + DBUS_TYPE_STRING, &argv[1], + DBUS_TYPE_STRING, &argv[2], + DBUS_TYPE_STRING, &argv[3], + DBUS_TYPE_STRING, &argv[4], DBUS_TYPE_INVALID)) { + _E("there is no message"); + ret = -EINVAL; + goto out; } - _E("failed to get usb status\n"); - return -1; -} -static int changed_dev_earjack(int argc, char **argv) -{ - int val; + if (argc < 0) { + _E("message is invalid!"); + ret = -EINVAL; + goto out; + } - _E("earjack_normal predefine action"); - if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_EARJACK_ONLINE, &val) == 0) { - if (CONNECTED(val)) - extcon_set_count(EXTCON_EARJACK); - return vconf_set_int(VCONFKEY_SYSMAN_EARJACK, val); + pid = get_edbus_sender_pid(msg); + if (kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored!", pid); + ret = -ESRCH; + goto out; } + check_capacity_status(argv[0]); + check_charge_status(argv[1]); + check_health_status(argv[2]); + check_online_status(argv[3]); + check_present_status(argv[4]); + _I("%d %d %d %d %d %d %d %d", + battery.capacity, + battery.charge_full, + battery.charge_now, + battery.health, + battery.online, + battery.ovp, + battery.present, + battery.temp); + battery_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); + changed_device(POWER_SUBSYSTEM, argv[0]); +out: + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - return -1; + return reply; } -static int changed_battery_cf(int argc, char **argv) +static DBusMessage *dbus_udev_handler(E_DBus_Object *obj, DBusMessage *msg) { + DBusError err; + DBusMessageIter iter; + DBusMessage *reply; + pid_t pid; int ret; - static int present_status = 1; - bundle *b; + int argc; + char *type_str; + char *argv; - b = bundle_create(); - if (!b) { - _E("fail to create bundle"); - return -EINVAL; + dbus_error_init(&err); + + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &type_str, + DBUS_TYPE_INT32, &argc, + DBUS_TYPE_STRING, &argv, DBUS_TYPE_INVALID)) { + _E("there is no message"); + ret = -EINVAL; + goto out; } - ret = bundle_add(b, "_SYSPOPUP_CONTENT_", "battdisconnect"); - if (ret != 0) { - _E("fail to add bundle"); + if (argc < 0) { + _E("message is invalid!"); + ret = -EINVAL; goto out; } - ret = syspopup_launch("lowbat-syspopup", b); - if (ret < 0) - _E("popup launch failed"); + pid = get_edbus_sender_pid(msg); + if (kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored!", pid); + ret = -ESRCH; + goto out; + } + + if (strncmp(argv, "start", strlen("start")) == 0) { + uevent_kernel_control_start(); + } else if (strncmp(argv, "stop", strlen("stop")) == 0) { + uevent_kernel_control_stop(); + } out: - bundle_free(b); - return ret; + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + + return reply; } -static void pci_keyboard_add_cb(struct ss_main_data *ad) +void internal_pm_change_state(unsigned int s_bits) { - char params[BUFF_MAX]; - _D("pci- keyboard inserted\n"); - pm_change_internal(getpid(), LCD_NORMAL); + pm_change_internal(getpid(), s_bits); +} - snprintf(params, sizeof(params), "%d", CB_NOTI_PCI_INSERTED); - ss_launch_if_noexist("/usr/bin/sys_pci_noti", params); +static const struct edbus_method edbus_methods[] = { + { PREDEF_DEVICE_CHANGED, "siss", "i", dbus_device_handler }, + { PREDEF_POWER_CHANGED, "sisssss", "i", dbus_battery_handler }, + { PREDEF_UDEV_CONTROL, "sis","i", dbus_udev_handler }, + { METHOD_GET_HDCP, NULL, "i", dbus_hdcp_handler }, + { METHOD_GET_HDMI_AUDIO, NULL, "i", dbus_hdmi_audio_handler }, + { METHOD_GET_HDMI, NULL, "i", dbus_hdcp_hdmi_handler }, + { METHOD_GET_CRADLE, NULL, "i", dbus_cradle_handler }, +}; -} -static void pci_keyboard_remove_cb(struct ss_main_data *ad) +static int device_change_poweroff(void *data) { - char params[BUFF_MAX]; - _D("pci- keyboard removed\n"); - pm_change_internal(getpid(), LCD_NORMAL); - - snprintf(params, sizeof(params), "%d", CB_NOTI_PCI_REMOVED); - ss_launch_if_noexist("/usr/bin/sys_pci_noti", params); + uevent_kernel_control_stop(); + return 0; } static void device_change_init(void *data) { + int ret; + + power_supply_timer_start(); if (extcon_count_init() != 0) _E("fail to init extcon files"); - action_entry_add_internal(PREDEF_USBCON, changed_dev_usb, NULL, NULL); - action_entry_add_internal(PREDEF_EARJACKCON, changed_dev_earjack, NULL, NULL); - action_entry_add_internal(PREDEF_BATTERY_CF_OPENED, changed_battery_cf, NULL, NULL); - action_entry_add_internal(PREDEF_DEVICE_CHANGED, changed_device, NULL, NULL); - - if (uevent_control_start() != 0) { - _E("fail uevent control init"); - return; - } + register_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_LCD, display_changed); + ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods)); + if (ret < 0) + _E("fail to init edbus method(%d)", ret); - /* for simple noti change cb */ - ss_noti_add("device_usb_chgdet", (void *)usb_chgdet_cb, NULL); - ss_noti_add("device_ta_chgdet", (void *)ta_chgdet_cb, data); - ss_noti_add("device_earjack_chgdet", (void *)earjack_chgdet_cb, data); - ss_noti_add("device_earkey_chgdet", (void *)earkey_chgdet_cb, data); - ss_noti_add("device_tvout_chgdet", (void *)tvout_chgdet_cb, data); - ss_noti_add("device_hdmi_chgdet", (void *)hdmi_chgdet_cb, data); - ss_noti_add("device_keyboard_chgdet", (void *)keyboard_chgdet_cb, data); - ss_noti_add("device_usb_host_add", (void *)usb_host_add_cb, data); - ss_noti_add("mmcblk_add", (void *)mmc_chgdet_cb, (void *)1); - ss_noti_add("mmcblk_remove", (void *)mmc_chgdet_cb, NULL); - ss_noti_add("unmount_ums", (void *)ums_unmount_cb, NULL); - ss_noti_add("device_charge_chgdet", (void *)charge_cb, data); - ss_noti_add("device_pci_keyboard_add", (void *)pci_keyboard_add_cb, data); - ss_noti_add("device_pci_keyboard_remove", (void *)pci_keyboard_remove_cb, data); - - if (vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS, - (void *)usb_host_chgdet_cb, NULL) < 0) { - _E("vconf key notify failed(VCONFKEY_SYSMAN_USB_HOST_STATUS)"); - } - - /* check and set earjack init status */ - changed_dev_earjack(0, NULL); /* dbus noti change cb */ #ifdef ENABLE_EDBUS_USE e_dbus_init(); @@ -993,17 +1334,18 @@ static void device_change_init(void *data) "system.uevent.xxxxx", "Change", cb_xxxxx_signaled, data); #endif /* ENABLE_EDBUS_USE */ - - /* set initial state for devices */ - input_device_number = 0; - keyboard_chgdet_cb(NULL); - hdmi_chgdet_cb(NULL); - system(STORE_DEFAULT_USB_INFO); + if (uevent_kernel_control_start() != 0) { + _E("fail uevent control init"); + return; + } } static void device_change_exit(void *data) { int i; + unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff); + unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + unregister_notifier(DEVICE_NOTIFIER_LCD, display_changed); for (i = 0; i < ARRAY_SIZE(extcon_devices); i++) { if (extcon_devices[i].fd <= 0) continue; diff --git a/src/core/device-handler.h b/src/core/device-handler.h index ed9c2be..49f0b55 100644 --- a/src/core/device-handler.h +++ b/src/core/device-handler.h @@ -17,30 +17,90 @@ */ -#ifndef __SS_DEVICE_HANDLER_H__ -#define __SS_DEVICE_HANDLER_H__ +#ifndef __DEVICE_HANDLER_H__ +#define __DEVICE_HANDLER_H__ -#include "data.h" +#include "common.h" enum extcon_type { EXTCON_TA = 0, EXTCON_EARJACK, }; -#define CONNECTED(val) ((val) == 1) +enum device_change_type { + DEVICE_CHANGE_ABNORMAL = 0, + DEVICE_CHANGE_NORMAL = 1, +}; + +enum charge_full_type { + CHARGING_NOT_FULL = 0, + CHARGING_FULL = 1, +}; +enum charge_now_type { + CHARGER_ABNORMAL = -1, + CHARGER_DISCHARGING = 0, + CHARGER_CHARGING = 1, +}; +enum health_type { + HEALTH_BAD = 0, + HEALTH_GOOD = 1, +}; -/* MMC functions */ -int ss_mmc_inserted(); -int ss_mmc_removed(); +enum temp_type { + TEMP_LOW = 0, + TEMP_HIGH = 1, +}; -/* USB Storage */ -int _ss_usb_storage_init(void); +enum present_type { + PRESENT_ABNORMAL = 0, + PRESENT_NORMAL = 1, +}; + +enum ovp_type { + OVP_NORMAL = 0, + OVP_ABNORMAL = 1, +}; + +enum battery_noti_type { + DEVICE_NOTI_BATT_CHARGE = 0, + DEVICE_NOTI_BATT_LOW, + DEVICE_NOTI_BATT_FULL, + DEVICE_NOTI_MAX, +}; + +enum battery_noti_status { + DEVICE_NOTI_OFF = 0, + DEVICE_NOTI_ON = 1, +}; + +enum dock_type { + DOCK_NONE = 0, + DOCK_SOUND = 7, +}; + +struct battery_status { + int capacity; + int charge_full; + int charge_now; + int health; + int present; + int online; + int temp; + int ovp; +}; + +struct battery_status battery; + +#define CONNECTED(val) ((val) != 0) /* Battery functions */ -int ss_lowbat_is_charge_in_now(); -int ss_lowbat_set_charge_on(int onoff); -Eina_Bool ss_lowbat_monitor(void *data); +void lowbat_monitor(void *data); int extcon_set_count(int index); -#endif /* __SS_DEVICE_HANDLER_H__ */ +int get_usb_state_direct(void); + +void sync_cradle_status(void); + +void internal_pm_change_state(unsigned int s_bits); +#endif /* __DEVICE_HANDLER_H__ */ diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c index 677649b..5e5aa83 100644 --- a/src/core/device-notifier.c +++ b/src/core/device-notifier.c @@ -17,28 +17,30 @@ */ -#include - #include "log.h" #include "devices.h" #include "device-notifier.h" #include "list.h" #include "common.h" +#define LATE_INIT_WAIT_TIME 12 +#define DEFAULT_LATE_INIT_VALUE ((Ecore_Timer *)0x0DEF0DEF) + struct device_notifier { enum device_notifier_type status; int (*func)(void *data); }; -static Eina_List *device_notifier_list; +static dd_list *device_notifier_list; +static Ecore_Timer *late_init_timer = DEFAULT_LATE_INIT_VALUE; -#define FIND_NOTIFIER(a, b, c, d, e, f) \ - EINA_LIST_FOREACH_SAFE(a, b, c, d) \ +#define FIND_NOTIFIER(a, b, d, e, f) \ + DD_LIST_FOREACH(a, b, d) \ if (e == d->e && f == (d->f)) int register_notifier(enum device_notifier_type status, int (*func)(void *data)) { - Eina_List *n, *next; + dd_list *n; struct device_notifier *data, *notifier; _I("%d, %x", status, func); @@ -48,7 +50,7 @@ int register_notifier(enum device_notifier_type status, int (*func)(void *data)) return -EINVAL; } - FIND_NOTIFIER(device_notifier_list, n, next, notifier, status, func) { + FIND_NOTIFIER(device_notifier_list, n, notifier, status, func) { _E("function is already registered! [%d, %x]", status, func); return -EINVAL; @@ -63,14 +65,14 @@ int register_notifier(enum device_notifier_type status, int (*func)(void *data)) notifier->status = status; notifier->func = func; - EINA_LIST_APPEND(device_notifier_list, notifier); + DD_LIST_APPEND(device_notifier_list, notifier); return 0; } int unregister_notifier(enum device_notifier_type status, int (*func)(void *data)) { - Eina_List *n, *next; + dd_list *n; struct device_notifier *notifier; if (!func) { @@ -78,10 +80,10 @@ int unregister_notifier(enum device_notifier_type status, int (*func)(void *data return -EINVAL; } - FIND_NOTIFIER(device_notifier_list, n, next, notifier, status, func) { + FIND_NOTIFIER(device_notifier_list, n, notifier, status, func) { _I("[%d, %x]", status, func); + DD_LIST_REMOVE(device_notifier_list, notifier); free(notifier); - EINA_LIST_REMOVE_LIST(device_notifier_list, n); } return 0; @@ -89,11 +91,11 @@ int unregister_notifier(enum device_notifier_type status, int (*func)(void *data void device_notify(enum device_notifier_type status, void *data) { - Eina_List *n; + dd_list *n, *next; struct device_notifier *notifier; int cnt = 0; - EINA_LIST_FOREACH(device_notifier_list, n, notifier) { + DD_LIST_FOREACH_SAFE(device_notifier_list, n, next, notifier) { if (status == notifier->status) { if (notifier->func) { notifier->func(data); @@ -103,24 +105,74 @@ void device_notify(enum device_notifier_type status, void *data) } } +static void late_init_stop(void) +{ + if (late_init_timer == NULL || + late_init_timer == DEFAULT_LATE_INIT_VALUE) + return; + ecore_timer_del(late_init_timer); + late_init_timer = NULL; +} + +static int booting_done(void *data) +{ + static int done = 0; + + if (data == NULL) + goto out; + + done = (int)data; + if (late_init_timer == NULL) + return done; + late_init_stop(); +out: + return done; +} + +static Eina_Bool late_init_timer_cb(void *data) +{ + int done; + + late_init_stop(); + done = booting_done(NULL); + if (done) + return EINA_FALSE; + _I("late booting done"); + device_notify(DEVICE_NOTIFIER_BOOTING_DONE, (void *)TRUE); + return EINA_FALSE; +} + +static void device_notifier_init(void *data) +{ + int ret; + + ret = check_systemd_active(); + if (ret == TRUE) { + _I("restart booting done"); + return; + } + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + late_init_timer = ecore_timer_add(LATE_INIT_WAIT_TIME, + late_init_timer_cb, NULL); + if (!late_init_timer) + late_init_timer = DEFAULT_LATE_INIT_VALUE; +} + static void device_notifier_exit(void *data) { - Eina_List *n, *next; + dd_list *n; struct device_notifier *notifier; - EINA_LIST_FOREACH_SAFE(device_notifier_list, n, next, notifier) - if (notifier) { - free(notifier); - EINA_LIST_REMOVE_LIST(device_notifier_list, n); - } - - _I("all deleted!"); + DD_LIST_FOREACH(device_notifier_list, n, notifier) + DD_LIST_REMOVE(device_notifier_list, notifier); + free(notifier); } static const struct device_ops notifier_device_ops = { .priority = DEVICE_PRIORITY_NORMAL, - .name = "notifier", - .exit = device_notifier_exit, + .name = "notifier", + .init = device_notifier_init, + .exit = device_notifier_exit, }; DEVICE_OPS_REGISTER(¬ifier_device_ops) diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index 3111744..13bfb0b 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -22,11 +22,19 @@ enum device_notifier_type { DEVICE_NOTIFIER_BOOTING_DONE, + DEVICE_NOTIFIER_HDMI, DEVICE_NOTIFIER_LCD, + DEVICE_NOTIFIER_MMC, DEVICE_NOTIFIER_TA, + DEVICE_NOTIFIER_LOWBAT, + DEVICE_NOTIFIER_TOUCH_HARDKEY, DEVICE_NOTIFIER_INPUT_ADD, DEVICE_NOTIFIER_INPUT_REMOVE, DEVICE_NOTIFIER_PROCESS_TERMINATED, + DEVICE_NOTIFIER_POWER_SUPPLY, + DEVICE_NOTIFIER_BATTERY_HEALTH, + DEVICE_NOTIFIER_POWEROFF, + DEVICE_NOTIFIER_POWEROFF_HAPTIC, DEVICE_NOTIFIER_MAX, }; diff --git a/src/core/devices.c b/src/core/devices.c index 9cf130a..de766f3 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -24,6 +24,10 @@ #include "common.h" #include "devices.h" +static const struct device_ops default_ops = { + .name = "default-ops", +}; + static dd_list *dev_head; void add_device(const struct device_ops *dev) @@ -39,6 +43,25 @@ void remove_device(const struct device_ops *dev) DD_LIST_REMOVE(dev_head, dev); } +const struct device_ops *find_device(const char *name) +{ + dd_list *elem; + const struct device_ops *dev; + + DD_LIST_FOREACH(dev_head, elem, dev) { + if (!strcmp(dev->name, name)) + return dev; + } + + dev = &default_ops; + return dev; +} + +int check_default(const struct device_ops *dev) +{ + return (dev == &default_ops); +} + void devices_init(void *data) { dd_list *elem; diff --git a/src/core/devices.h b/src/core/devices.h index cc120f1..262e629 100644 --- a/src/core/devices.h +++ b/src/core/devices.h @@ -28,14 +28,27 @@ enum device_priority { DEVICE_PRIORITY_HIGH, }; +enum device_flags { + NORMAL_MODE = 0x00000001, + CORE_LOGIC_MODE = 0x00010000, + TOUCH_SCREEN_OFF_MODE = 0x00020000, + LCD_PANEL_OFF_MODE = 0x00040000, + LCD_PHASED_TRANSIT_MODE = 0x00080000, + LCD_ON_BY_GESTURE = 0x00100000, + LCD_ON_BY_POWER_KEY = 0x00200000, + LCD_ON_BY_EVENT = 0x00400000, + LCD_ON_BY_TOUCH = 0x00800000, +}; + struct device_ops { enum device_priority priority; char *name; void (*init) (void *data); void (*exit) (void *data); - int (*start) (void); - int (*stop) (void); + int (*start) (enum device_flags flags); + int (*stop) (enum device_flags flags); int (*status) (void); + int (*execute) (void *data); }; enum device_ops_status { @@ -51,7 +64,7 @@ void devices_exit(void *data); static inline int device_start(const struct device_ops *dev) { if (dev && dev->start) - return dev->start(); + return dev->start(NORMAL_MODE); return -EINVAL; } @@ -59,7 +72,25 @@ static inline int device_start(const struct device_ops *dev) static inline int device_stop(const struct device_ops *dev) { if (dev && dev->stop) - return dev->stop(); + return dev->stop(NORMAL_MODE); + + return -EINVAL; +} + +static inline int device_exit(const struct device_ops *dev, void *data) +{ + if (dev && dev->exit) { + dev->exit(data); + return 0; + } + + return -EINVAL; +} + +static inline int device_execute(const struct device_ops *dev, void *data) +{ + if (dev && dev->execute) + return dev->execute(data); return -EINVAL; } @@ -72,17 +103,31 @@ static inline int device_get_status(const struct device_ops *dev) return -EINVAL; } -#define DEVICE_OPS_REGISTER(dev) \ -static void __CONSTRUCTOR__ module_init(void) \ -{ \ - add_device(dev); \ -} \ -static void __DESTRUCTOR__ module_exit(void) \ -{ \ - remove_device(dev); \ +#define DEVICE_OPS_REGISTER(dev) \ +static void __CONSTRUCTOR__ module_init(void) \ +{ \ + add_device(dev); \ +} \ +static void __DESTRUCTOR__ module_exit(void) \ +{ \ + remove_device(dev); \ } void add_device(const struct device_ops *dev); void remove_device(const struct device_ops *dev); +const struct device_ops *find_device(const char *name); +int check_default(const struct device_ops *dev); + +#define NOT_SUPPORT_OPS(dev) \ + ((check_default(dev))? 1 : 0) + +#define FIND_DEVICE_INT(dev, name) do { \ + if (!dev) dev = find_device(name); if(check_default(dev)) return -ENODEV; \ +} while(0) + +#define FIND_DEVICE_VOID(dev, name) do { \ + if (!dev) dev = find_device(name); if(check_default(dev)) return; \ +} while(0) + #endif diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index 990cb00..75114f4 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -17,8 +17,8 @@ */ +#include #include "core/log.h" -#include "core/data.h" #include "core/edbus-handler.h" #include "core/common.h" #include "core/device-notifier.h" @@ -30,6 +30,9 @@ path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',\ member='NameOwnerChanged',arg0='%s'" +/* -1 is a default timeout value, it's converted to 25*1000 internally. */ +#define DBUS_REPLY_TIMEOUT (-1) +#define RETRY_MAX 5 struct edbus_list{ char *signal_name; @@ -44,15 +47,27 @@ static struct edbus_object { } edbus_objects[] = { { DEVICED_PATH_CORE , DEVICED_INTERFACE_CORE , NULL, NULL }, { DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, NULL, NULL }, + { DEVICED_PATH_POWER , DEVICED_INTERFACE_POWER , NULL, NULL }, { DEVICED_PATH_STORAGE, DEVICED_INTERFACE_STORAGE, NULL, NULL }, { DEVICED_PATH_HAPTIC , DEVICED_INTERFACE_HAPTIC , NULL, NULL }, - { DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, NULL, NULL }, { DEVICED_PATH_LED , DEVICED_INTERFACE_LED , NULL, NULL }, + { DEVICED_PATH_MMC , DEVICED_INTERFACE_MMC , NULL, NULL }, + { DEVICED_PATH_PROCESS, DEVICED_INTERFACE_PROCESS, NULL, NULL }, + { DEVICED_PATH_KEY , DEVICED_INTERFACE_KEY , NULL, NULL }, + { DEVICED_PATH_CPU , DEVICED_INTERFACE_CPU , NULL, NULL }, + { DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, NULL, NULL }, + { DEVICED_PATH_USB , DEVICED_INTERFACE_USB , NULL, NULL }, + { DEVICED_PATH_USBHOST, DEVICED_INTERFACE_USBHOST, NULL, NULL }, + { DEVICED_PATH_EXTCON , DEVICED_INTERFACE_EXTCON , NULL, NULL }, + { DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, NULL, NULL }, + { DEVICED_PATH_GPIO, DEVICED_INTERFACE_GPIO, NULL, NULL}, + { DEVICED_PATH_HDMICEC, DEVICED_INTERFACE_HDMICEC, NULL, NULL}, /* Add new object & interface here*/ }; -static Eina_List *edbus_handler_list; -static Eina_List *edbus_watch_list; +static dd_list *edbus_owner_list; +static dd_list *edbus_handler_list; +static dd_list *edbus_watch_list; static int edbus_init_val; static DBusConnection *conn; static E_DBus_Connection *edbus_conn; @@ -160,30 +175,27 @@ pid_t get_edbus_sender_pid(DBusMessage *msg) static void unregister_edbus_signal_handle(void) { - Eina_List *tmp; - Eina_List *tmp_next; + dd_list *tmp; struct edbus_list *entry; - EINA_LIST_FOREACH_SAFE(edbus_handler_list, tmp, tmp_next, entry) { - if (entry != NULL) { - e_dbus_signal_handler_del(edbus_conn, entry->handler); - edbus_handler_list = eina_list_remove(edbus_handler_list, entry); - free(entry->signal_name); - free(entry); - } + DD_LIST_FOREACH(edbus_handler_list, tmp, entry) { + e_dbus_signal_handler_del(edbus_conn, entry->handler); + DD_LIST_REMOVE(edbus_handler_list, entry); + free(entry->signal_name); + free(entry); } } int register_edbus_signal_handler(const char *path, const char *interface, const char *name, E_DBus_Signal_Cb cb) { - Eina_List *tmp; + dd_list *tmp; struct edbus_list *entry; E_DBus_Signal_Handler *handler; - EINA_LIST_FOREACH(edbus_handler_list, tmp, entry) { - if (entry != NULL && strncmp(entry->signal_name, name, strlen(name)) == 0) - return -1; + DD_LIST_FOREACH(edbus_handler_list, tmp, entry) { + if (strncmp(entry->signal_name, name, strlen(name)) == 0) + return -EEXIST; } handler = e_dbus_signal_handler_add(edbus_conn, NULL, path, @@ -191,16 +203,14 @@ int register_edbus_signal_handler(const char *path, const char *interface, if (!handler) { _E("fail to add edbus handler"); - return -1; + return -ENOMEM; } - _E("add edbus service: %s", name); - entry = malloc(sizeof(struct edbus_list)); if (!entry) { _E("Malloc failed"); - return -1; + return -ENOMEM; } entry->signal_name = strndup(name, strlen(name)); @@ -208,39 +218,49 @@ int register_edbus_signal_handler(const char *path, const char *interface, if (!entry->signal_name) { _E("Malloc failed"); free(entry); - return -1; + return -ENOMEM; } entry->handler = handler; - edbus_handler_list = eina_list_prepend(edbus_handler_list, entry); + DD_LIST_PREPEND(edbus_handler_list, entry); if (!edbus_handler_list) { _E("eina_list_prepend failed"); free(entry->signal_name); free(entry); - return -1; + return -ENOMEM; } return 0; } int broadcast_edbus_signal(const char *path, const char *interface, - const char *name, int type, void *value) + const char *name, const char *sig, char *param[]) { - DBusMessage *signal; + DBusMessage *msg; DBusMessageIter iter; - DBusMessageIter val; - char sig[2] = {type, '\0'}; + int r; - signal = dbus_message_new_signal(path, interface, name); - if (!signal) { + msg = dbus_message_new_signal(path, interface, name); + if (!msg) { _E("fail to allocate new %s.%s signal", interface, name); - return -1; + return -EPERM; + } + + dbus_message_iter_init_append(msg, &iter); + r = append_variant(&iter, sig, param); + if (r < 0) { + _E("append_variant error(%d)", r); + return -EPERM; } - dbus_message_append_args(signal, type, value, DBUS_TYPE_INVALID); + r = dbus_connection_send(conn, msg, NULL); + dbus_message_unref(msg); - e_dbus_message_send(edbus_conn, signal, NULL, -1, NULL); + if (r != TRUE) { + _E("dbus_connection_send error(%s:%s-%s)", + path, interface, name); + return -ECOMM; + } - dbus_message_unref(signal); return 0; } @@ -250,8 +270,8 @@ static DBusHandlerResult message_filter(DBusConnection *connection, char match[256]; int ret; const char *iface, *member, *arg = NULL; - char *watch; - Eina_List *l; + struct watch *watch; + dd_list *n; if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -274,21 +294,23 @@ static DBusHandlerResult message_filter(DBusConnection *connection, _D("Argument : %s", arg); - EINA_LIST_FOREACH(edbus_watch_list, l, watch) { - if (strcmp(arg, watch)) continue; + DD_LIST_FOREACH(edbus_watch_list, n, watch) { + if (strcmp(arg, watch->name)) continue; - /* notify 'process terminated' to device notifiers */ - device_notify(DEVICE_NOTIFIER_PROCESS_TERMINATED, (void *)watch); + if (watch->func) + watch->func(watch->name, watch->id); - /* remove registered sender */ - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch); - dbus_bus_remove_match(conn, match, NULL); - EINA_LIST_REMOVE(edbus_watch_list, watch); + DD_LIST_REMOVE(edbus_watch_list, watch); + free(watch->name); free(watch); - break; } - if (eina_list_count(edbus_watch_list) == 0) { + /* remove registered sender */ + snprintf(match, sizeof(match), NAME_OWNER_MATCH, arg); + dbus_bus_remove_match(conn, match, NULL); + + + if (DD_LIST_LENGTH(edbus_watch_list) == 0) { dbus_connection_remove_filter(conn, message_filter, NULL); _I("remove message filter, no watcher!"); } @@ -296,13 +318,14 @@ static DBusHandlerResult message_filter(DBusConnection *connection, return DBUS_HANDLER_RESULT_HANDLED; } -int register_edbus_watch(DBusMessage *msg) +int register_edbus_watch(DBusMessage *msg, enum watch_id id, int (*func)(char *name, enum watch_id id)) { char match[256]; const char *sender; - char *watch; - Eina_List *l; + struct watch *watch; + dd_list *n; int ret; + bool matched = false; if (!msg) { _E("invalid argument!"); @@ -315,38 +338,102 @@ int register_edbus_watch(DBusMessage *msg) return -EINVAL; } - /* check the sender is already registered */ - EINA_LIST_FOREACH(edbus_watch_list, l, watch) { - if (strcmp(sender, watch)) continue; + /* check the sender&id is already registered */ + DD_LIST_FOREACH(edbus_watch_list, n, watch) { + if (strcmp(sender, watch->name)) + continue; + if (id != watch->id) { + matched = true; + continue; + } + + _I("%s(%d) is already watched!", watch->name, watch->id); - _I("%s is already watched!", watch); return 0; } - watch = strndup(sender, strlen(sender)); - if (!watch) { - _E("Malloc failed"); + watch = malloc(sizeof(struct watch)); + if (!watch) { + _E("Fail to malloc for watch!"); + return -ENOMEM; + } + + watch->id = id; + watch->func = func; + watch->name = strndup(sender, strlen(sender)); + + if (!watch->name) { + _E("Fail to malloc for watch name"); + free(watch); return -ENOMEM; } /* Add message filter */ - if (eina_list_count(edbus_watch_list) == 0) { + if (DD_LIST_LENGTH(edbus_watch_list) == 0) { ret = dbus_connection_add_filter(conn, message_filter, NULL, NULL); if (!ret) { _E("fail to add message filter!"); + free(watch->name); free(watch); return -ENOMEM; } _I("success to add message filter!"); } - /* Add sender to watch list */ - EINA_LIST_APPEND(edbus_watch_list, watch); + /* Add watch to watch list */ + DD_LIST_APPEND(edbus_watch_list, watch); - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch); - dbus_bus_add_match(conn, match, NULL); + if (!matched) { + snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->name); + dbus_bus_add_match(conn, match, NULL); + } - _I("%s is watched by dbus!", watch); + _I("%s(%d) is watched by dbus!", watch->name, watch->id); + + return 0; +} + +int unregister_edbus_watch(DBusMessage *msg, enum watch_id id) +{ + char match[256]; + const char *sender; + struct watch *watch; + dd_list *n; + bool matched = false; + + if (!msg) { + _E("invalid argument!"); + return -EINVAL; + } + + sender = dbus_message_get_sender(msg); + if (!sender) { + _E("invalid sender!"); + return -EINVAL; + } + + DD_LIST_FOREACH(edbus_watch_list, n, watch) { + if (strcmp(sender, watch->name)) + continue; + + if (id != watch->id) { + matched = true; + continue; + } + DD_LIST_REMOVE(edbus_watch_list, watch); + free(watch->name); + free(watch); + } + + /* remove match */ + if (!matched) { + snprintf(match, sizeof(match), NAME_OWNER_MATCH, sender); + dbus_bus_remove_match(conn, match, NULL); + + if (DD_LIST_LENGTH(edbus_watch_list) == 0) + dbus_connection_remove_filter(conn, message_filter, + NULL); + } return 0; } @@ -354,16 +441,17 @@ int register_edbus_watch(DBusMessage *msg) static void unregister_edbus_watch_all(void) { char match[256]; - Eina_List *n, *next; - struct edbus_list *watch; + dd_list *n; + struct watch *watch; - if (eina_list_count(edbus_watch_list) > 0) + if (DD_LIST_LENGTH(edbus_watch_list) > 0) dbus_connection_remove_filter(conn, message_filter, NULL); - EINA_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch); + DD_LIST_FOREACH(edbus_watch_list, n, watch) { + snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->name); dbus_bus_remove_match(conn, match, NULL); - EINA_LIST_REMOVE(edbus_watch_list, watch); + DD_LIST_REMOVE(edbus_watch_list, watch); + free(watch->name); free(watch); } } @@ -383,10 +471,10 @@ int register_edbus_method(const char *path, const struct edbus_method *edbus_met for (i = 0; i < size; i++) { ret = e_dbus_interface_method_add(iface, - edbus_methods[i].member, - edbus_methods[i].signature, - edbus_methods[i].reply_signature, - edbus_methods[i].func); + edbus_methods[i].member, + edbus_methods[i].signature, + edbus_methods[i].reply_signature, + edbus_methods[i].func); if (!ret) { _E("fail to add method %s!", edbus_methods[i].member); return -EINVAL; @@ -396,58 +484,184 @@ int register_edbus_method(const char *path, const struct edbus_method *edbus_met return 0; } +static void request_name_cb(void *data, DBusMessage *msg, DBusError *error) +{ + DBusError err; + unsigned int val; + int r; + + if (!msg) { + _D("invalid DBusMessage!"); + return; + } + + dbus_error_init(&err); + r = dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &val, DBUS_TYPE_INVALID); + if (!r) { + _E("no message : [%s:%s]", err.name, err.message); + dbus_error_free(&err); + return; + } + + _I("Request Name reply : %d", val); +} + +static void check_owner_name(void) +{ + DBusError err; + DBusMessage *msg; + DBusMessageIter iter; + char *pa[1]; + char exe_name[PATH_MAX]; + char *entry; + dd_list *n; + int pid; + + DD_LIST_FOREACH(edbus_owner_list, n, entry) { + pa[0] = entry; + msg = dbus_method_sync_with_reply(E_DBUS_FDO_BUS, + E_DBUS_FDO_PATH, + E_DBUS_FDO_INTERFACE, + "GetConnectionUnixProcessID", "s", pa); + + if (!msg) { + _E("invalid DBusMessage!"); + return; + } + + dbus_error_init(&err); + dbus_message_iter_init(msg, &iter); + + dbus_message_iter_get_basic(&iter, &pid); + if (get_cmdline_name(pid, exe_name, PATH_MAX) != 0) + goto out; + _I("%s(%d)", exe_name, pid); + +out: + dbus_message_unref(msg); + dbus_error_free(&err); + } +} + +static void check_owner_list(void) +{ + DBusError err; + DBusMessage *msg; + DBusMessageIter array, iter, item, iter_val; + char *pa[1]; + char *name; + char *entry; + + pa[0] = DEVICED_BUS_NAME; + msg = dbus_method_sync_with_reply(E_DBUS_FDO_BUS, + E_DBUS_FDO_PATH, + E_DBUS_FDO_INTERFACE, + "ListQueuedOwners", "s", pa); + + if (!msg) { + _E("invalid DBusMessage!"); + return; + } + + dbus_error_init(&err); + dbus_message_iter_init(msg, &array); + + if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY) + goto out; + dbus_message_iter_recurse(&array, &item); + while (dbus_message_iter_get_arg_type(&item) == DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&item, &name); + entry = strndup(name, strlen(name)); + DD_LIST_APPEND(edbus_owner_list, entry); + if (!edbus_owner_list) { + _E("append failed"); + free(entry); + goto out; + } + dbus_message_iter_next(&item); + } + +out: + dbus_message_unref(msg); + dbus_error_free(&err); +} + void edbus_init(void *data) { - int retry = EDBUS_INIT_RETRY_COUNT; - int i, r; + DBusError error; + int retry = 0; + int i, ret; + + dbus_threads_init_default(); + dbus_error_init(&error); - while (--retry) { + do { edbus_init_val = e_dbus_init(); if (edbus_init_val) break; - if (!retry) { + if (retry == EDBUS_INIT_RETRY_COUNT) { _E("fail to init edbus"); return; } - } + retry++; + } while (retry <= EDBUS_INIT_RETRY_COUNT); + + retry = 0; + do { + conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if (conn) + break; + if (retry == EDBUS_INIT_RETRY_COUNT) { + _E("fail to get dbus"); + goto out1; + } + retry++; + } while (retry <= EDBUS_INIT_RETRY_COUNT); - retry = EDBUS_INIT_RETRY_COUNT; - while (--retry) { - edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM); + retry = 0; + do { + edbus_conn = e_dbus_connection_setup(conn); if (edbus_conn) break; - if (!retry) { + if (retry == EDBUS_INIT_RETRY_COUNT) { _E("fail to get edbus"); - goto err_dbus_shutdown; + goto out2; } - } + retry++; + } while (retry <= EDBUS_INIT_RETRY_COUNT); - retry = EDBUS_INIT_RETRY_COUNT; - while (--retry) { - edbus_request_name = e_dbus_request_name(edbus_conn, BUS_NAME, 0, NULL, NULL); + retry = 0; + do { + edbus_request_name = e_dbus_request_name(edbus_conn, DEVICED_BUS_NAME, + DBUS_NAME_FLAG_REPLACE_EXISTING, request_name_cb, NULL); if (edbus_request_name) break; - if (!retry) { + if (retry == EDBUS_INIT_RETRY_COUNT) { _E("fail to request edbus name"); - goto err_dbus_close; + goto out3; } - } + retry++; + } while (retry <= EDBUS_INIT_RETRY_COUNT); for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) { - r = register_edbus_interface(&edbus_objects[i]); - if (r < 0) + ret = register_edbus_interface(&edbus_objects[i]); + if (ret < 0) { _E("fail to add obj & interface for %s", edbus_objects[i].interface); - - _I("add new obj for %s", edbus_objects[i].interface); + return; + } + _D("add new obj for %s", edbus_objects[i].interface); } + check_owner_list(); + check_owner_name(); return; -err_dbus_close: +out3: e_dbus_connection_close(edbus_conn); -err_dbus_shutdown: +out2: + dbus_connection_set_exit_on_disconnect(conn, FALSE); +out1: e_dbus_shutdown(); - return; } void edbus_exit(void *data) diff --git a/src/core/edbus-handler.h b/src/core/edbus-handler.h index b25efc0..c0e79ca 100644 --- a/src/core/edbus-handler.h +++ b/src/core/edbus-handler.h @@ -21,77 +21,7 @@ #define __EDBUS_HANDLE_H__ #include - -#define BUS_NAME "org.tizen.system.deviced" -#define OBJECT_PATH "/Org/Tizen/System/DeviceD" -#define INTERFACE_NAME BUS_NAME - -/* - * Core service - * get/set device status - * operations about device - */ -#define DEVICED_PATH_CORE OBJECT_PATH"/Core" -#define DEVICED_INTERFACE_CORE INTERFACE_NAME".core" - -/* - * Display service - * start/stop display(pm) - * get/set brightness - * operations about display - */ -#define DEVICED_PATH_DISPLAY OBJECT_PATH"/Display" -#define DEVICED_INTERFACE_DISPLAY INTERFACE_NAME".display" - -/* - * Storage service - * get storage size - * operatioins about storage - */ -#define DEVICED_PATH_STORAGE OBJECT_PATH"/Storage" -#define DEVICED_INTERFACE_STORAGE INTERFACE_NAME".storage" - -/* - * Haptic service - * operatioins about haptic - */ -#define DEVICED_PATH_HAPTIC OBJECT_PATH"/Haptic" -#define DEVICED_INTERFACE_HAPTIC INTERFACE_NAME".haptic" - -/* - * Lowmem service - * get critical low status - * operations about Lowmem - */ -#define DEVICED_PATH_LOWMEM OBJECT_PATH"/Lowmem" -#define DEVICED_INTERFACE_LOWMEM INTERFACE_NAME".lowmem" - -/* - * Poweroff service - * get power off status - * operations about Poweroff - */ -#define DEVICED_PATH_POWEROFF OBJECT_PATH"/PowerOff" -#define DEVICED_INTERFACE_POWEROFF INTERFACE_NAME".PowerOff" - -/* - * Led service - * play/stop led - * operations about led - */ -#define DEVICED_PATH_LED OBJECT_PATH"/Led" -#define DEVICED_INTERFACE_LED INTERFACE_NAME".Led" - -#define DEVICED_PATH_SYSNOTI OBJECT_PATH"/SysNoti" -#define DEVICED_INTERFACE_SYSNOTI INTERFACE_NAME".SysNoti" - -/* - * Power service - * set resetkey disable - * operations about power - */ -#define DEVICED_PATH_POWER OBJECT_PATH"/Power" -#define DEVICED_INTERFACE_POWER INTERFACE_NAME".power" +#include "shared/dbus.h" struct edbus_method { const char *member; @@ -100,15 +30,30 @@ struct edbus_method { E_DBus_Method_Cb func; }; +enum watch_id { + WATCH_DISPLAY_AUTOBRIGHTNESS_MIN, + WATCH_DISPLAY_LCD_TIMEOUT, + WATCH_DISPLAY_LOCK_STATE, + WATCH_DISPLAY_HOLD_BRIGHTNESS, +}; + +struct watch { + enum watch_id id; + char *name; + int (*func)(char *name, enum watch_id id); +}; + int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size); int register_edbus_signal_handler(const char *path, const char *interface, const char *name, E_DBus_Signal_Cb cb); E_DBus_Interface *get_edbus_interface(const char *path); pid_t get_edbus_sender_pid(DBusMessage *msg); int broadcast_edbus_signal(const char *path, const char *interface, - const char *name, int type, void *value); + const char *name, const char *sig, char *param[]); +int register_edbus_watch(DBusMessage *msg, enum watch_id id, int (*func)(char *name, enum watch_id id)); +int unregister_edbus_watch(DBusMessage *msg, enum watch_id id); void edbus_init(void *data); void edbus_exit(void *data); -#endif /* __SS_EDBUS_HANDLE_H__ */ +#endif /* __EDBUS_HANDLE_H__ */ diff --git a/src/core/execute.c b/src/core/execute.c new file mode 100755 index 0000000..303f6b7 --- /dev/null +++ b/src/core/execute.c @@ -0,0 +1,101 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +#include "log.h" + +static int parent(pid_t pid) +{ + int status; + + /* wait for child */ + if (waitpid(pid, &status, 0) != -1) { + /* terminated normally */ + if (WIFEXITED(status)) { + _I("%d terminated by exit(%d)", pid, WEXITSTATUS(status)); + return WEXITSTATUS(status); + } else if (WIFSIGNALED(status)) + _I("%d terminated by signal %d", pid, WTERMSIG(status)); + else if (WIFSTOPPED(status)) + _I("%d stopped by signal %d", pid, WSTOPSIG(status)); + } else + _I("%d waitpid() failed : %s", pid, strerror(errno)); + + return -EAGAIN; +} + +static void child(int argc, const char *argv[]) +{ + int i, r; + + for (i = 0; i < _NSIG; ++i) + signal(i, SIG_DFL); + + r = execv(argv[0], (char **)argv); + if (r < 0) + exit(EXIT_FAILURE); +} + +int run_child(int argc, const char *argv[]) +{ + pid_t pid; + struct sigaction act, oldact; + int r; + FILE *fp; + + if (!argv) + return -EINVAL; + + fp = fopen(argv[0], "r"); + if (fp == NULL) { + _E("fail %s (%s)", argv[0], strerror(errno)); + return -errno; + } + fclose(fp); + + /* Use default signal handler */ + act.sa_handler = SIG_DFL; + act.sa_sigaction = NULL; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + + if (sigaction(SIGCHLD, &act, &oldact) < 0) + return -errno; + + pid = fork(); + if (pid < 0) { + _E("failed to fork"); + r = -errno; + } else if (pid == 0) { + child(argc, argv); + } else + r = parent(pid); + + if (sigaction(SIGCHLD, &oldact, NULL) < 0) + _E("failed to restore sigaction"); + + return r; +} diff --git a/src/core/launch.c b/src/core/launch.c index b6c85c3..eb59419 100644 --- a/src/core/launch.c +++ b/src/core/launch.c @@ -35,7 +35,7 @@ #define _S(str) ((str == NULL) ? "" : str) -int ss_set_current_lang(void) +static int set_current_lang(void) { char *lang; int ret; @@ -202,7 +202,7 @@ int launch_app_cmd(const char *cmdline) return launch_app_cmd_with_nice(cmdline, 0); } -int ss_launch_if_noexist(const char *execpath, const char *arg, ...) +int launch_if_noexist(const char *execpath, const char *arg, ...) { char *buf; int pid; @@ -221,12 +221,12 @@ int ss_launch_if_noexist(const char *execpath, const char *arg, ...) va_start(argptr, arg); flag = va_arg(argptr, int); - if (flag & SS_LAUNCH_NICE) + if (flag & LAUNCH_NICE) nice_value = va_arg(argptr, int); va_end(argptr); - ss_set_current_lang(); + set_current_lang(); arg = _S(arg); buf_size = strlen(execpath) + strlen(arg) + 10; @@ -247,7 +247,7 @@ int ss_launch_if_noexist(const char *execpath, const char *arg, ...) return pid; } -int ss_launch_evenif_exist(const char *execpath, const char *arg, ...) +int launch_evenif_exist(const char *execpath, const char *arg, ...) { char *buf; int pid; @@ -265,12 +265,12 @@ int ss_launch_evenif_exist(const char *execpath, const char *arg, ...) va_start(argptr, arg); flag = va_arg(argptr, int); - if (flag & SS_LAUNCH_NICE) + if (flag & LAUNCH_NICE) nice_value = va_arg(argptr, int); va_end(argptr); - ss_set_current_lang(); + set_current_lang(); arg = _S(arg); @@ -292,7 +292,7 @@ int ss_launch_evenif_exist(const char *execpath, const char *arg, ...) return pid; } -int ss_launch_after_kill_if_exist(const char *execpath, const char *arg, ...) +int launch_after_kill_if_exist(const char *execpath, const char *arg, ...) { char *buf; int pid; @@ -313,12 +313,12 @@ int ss_launch_after_kill_if_exist(const char *execpath, const char *arg, ...) va_start(argptr, arg); flag = va_arg(argptr, int); - if (flag & SS_LAUNCH_NICE) + if (flag & LAUNCH_NICE) nice_value = va_arg(argptr, int); va_end(argptr); - ss_set_current_lang(); + set_current_lang(); arg = _S(arg); diff --git a/src/core/launch.h b/src/core/launch.h index d5b76b6..495512c 100644 --- a/src/core/launch.h +++ b/src/core/launch.h @@ -17,13 +17,13 @@ */ -#ifndef __SS_LAUNCH_H__ -#define __SS_LAUNCH_H__ +#ifndef __LAUNCH_H__ +#define __LAUNCH_H__ -#define SS_LAUNCH_NICE 0x0002 +#define LAUNCH_NICE 0x0002 -int ss_launch_if_noexist(const char *execpath, const char *arg, ...); -int ss_launch_evenif_exist(const char *execpath, const char *arg, ...); -int ss_launch_after_kill_if_exist(const char *execpath, const char *arg, ...); +int launch_if_noexist(const char *execpath, const char *arg, ...); +int launch_evenif_exist(const char *execpath, const char *arg, ...); +int launch_after_kill_if_exist(const char *execpath, const char *arg, ...); -#endif /* __SS_LAUNCH_H__ */ +#endif /* __LAUNCH_H__ */ diff --git a/src/core/list.h b/src/core/list.h index 7af9298..d3fa641 100644 --- a/src/core/list.h +++ b/src/core/list.h @@ -20,6 +20,7 @@ #define __LIST_H__ #include +#include #define EINA_LIST_APPEND(a, b) \ a = eina_list_append(a, b) @@ -33,46 +34,80 @@ #define EINA_LIST_FREE_LIST(a) \ a = eina_list_free(a) +#define EINA_LIST_PROMOTE_LIST(a, b) \ + a = eina_list_promote_list(a, b) + #ifdef EINA_LIST typedef Eina_List dd_list; -#define DD_LIST_PREPEND(a, b) \ - a = eina_list_prepend(a, b) -#define DD_LIST_APPEND(a, b) \ - a = eina_list_append(a, b) -#define DD_LIST_REMOVE(a, b) \ - a = eina_list_remove(a, b) -#define DD_LIST_LENGTH(a) \ - eina_list_count(a) -#define DD_LIST_NTH(a, b) \ - eina_list_nth(a, b) +#define DD_LIST_PREPEND(a, b) \ + a = eina_list_prepend(a, b) +#define DD_LIST_APPEND(a, b) \ + a = eina_list_append(a, b) +#define DD_LIST_REMOVE(a, b) \ + a = eina_list_remove(a, b) +#define DD_LIST_LENGTH(a) \ + eina_list_count(a) +#define DD_LIST_NTH(a, b) \ + eina_list_nth(a, b) #define DD_LIST_FREE_LIST(a) \ - a = eina_list_free(a) -#define DD_LIST_FOREACH(head, elem, node) \ - EINA_LIST_FOREACH(head, elem, node) + a = eina_list_free(a) +#define DD_LIST_FOREACH(head, elem, node) \ + EINA_LIST_FOREACH(head, elem, node) #define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ - EINA_LIST_FOREACH_SAFE(head, elem, elem_next, node) + EINA_LIST_FOREACH_SAFE(head, elem, elem_next, node) #else #include typedef GList dd_list; -#define DD_LIST_PREPEND(a, b) \ - a = g_list_prepend(a, (gpointer)b) -#define DD_LIST_APPEND(a, b) \ - a = g_list_append(a, (gpointer)b) -#define DD_LIST_REMOVE(a, b) \ - a = g_list_remove(a, (gpointer)b) -#define DD_LIST_LENGTH(a) \ - g_list_length(a) -#define DD_LIST_NTH(a, b) \ - g_list_nth_data(a, b) + +/* + cover crash from corrupted double linked list under the glib 2.36.4 + if glib version upper than 2.36.3, exchange it to g_list_remove +*/ +static inline GList* g_list_check_remove(GList* list, gpointer data) +{ + GList *temp; + temp = list; + if (!temp) + goto out; + while (temp != NULL) { + if (temp->data != data) + temp = temp->next; + else { + if (temp->prev != NULL && temp->prev->next == temp) + temp->prev->next = temp->next; + if (temp->next != NULL && temp->next->prev == temp) + temp->next->prev = temp->prev; + if (temp == list) + list = list->next; + temp->prev = NULL; + temp->next = NULL; + g_list_free(list); + break; + } + } +out: + return list; +} + +#define DD_LIST_PREPEND(a, b) \ + a = g_list_prepend(a, (gpointer)b) +#define DD_LIST_APPEND(a, b) \ + a = g_list_append(a, (gpointer)b) +#define DD_LIST_REMOVE(a, b) \ + a = g_list_remove(a, (gpointer)b) +#define DD_LIST_LENGTH(a) \ + g_list_length(a) +#define DD_LIST_NTH(a, b) \ + g_list_nth_data(a, b) #define DD_LIST_FREE_LIST(a) \ - g_list_free(a) -#define DD_LIST_FOREACH(head, elem, node) \ - for (elem = head, node = NULL; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL) + g_list_free(a) +#define DD_LIST_FOREACH(head, elem, node) \ + for (elem = head, node = NULL; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL) #define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ - for (elem = head, elem_next = g_list_next(elem), node = NULL; \ - elem && ((node = elem->data) != NULL); \ - elem = elem_next, elem_next = g_list_next(elem), node = NULL) + for (elem = head, elem_next = g_list_next(elem), node = NULL; \ + elem && ((node = elem->data) != NULL); \ + elem = elem_next, elem_next = g_list_next(elem), node = NULL) #endif diff --git a/src/core/log.c b/src/core/log.c index aca16d9..04aa3da 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -16,6 +16,8 @@ * limitations under the License. */ +#include +#include "log.h" #ifdef DEBUG void __cyg_profile_func_enter(void *, void *) diff --git a/src/core/log.h b/src/core/log.h index f9ccf05..9684f38 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -24,7 +24,10 @@ #define ENABLE_DLOG #endif -#define LOG_TAG "DEVICED" -#include "libdeviced/log-macro.h" +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "DEVICED" +#include "shared/log-macro.h" #endif diff --git a/src/core/main.c b/src/core/main.c index 5a9022f..ab3e80c 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -21,17 +21,15 @@ #include #include +#include "display/core.h" #include "log.h" -#include "data.h" +#include "common.h" #include "edbus-handler.h" #include "devices.h" +#include "shared/dbus.h" +#include "device-notifier.h" -#define SS_PIDFILE_PATH "/var/run/.system_server.pid" - -static void init_ad(struct ss_main_data *ad) -{ - memset(ad, 0x0, sizeof(struct ss_main_data)); -} +#define PIDFILE_PATH "/var/run/.deviced.pid" static void writepid(char *pidpath) { @@ -46,7 +44,7 @@ static void writepid(char *pidpath) static void sig_quit(int signo) { - _E("received SIGTERM signal %d", signo); + _D("received SIGTERM signal %d", signo); } static void sig_usr1(int signo) @@ -56,27 +54,31 @@ static void sig_usr1(int signo) ecore_main_loop_quit(); } -static int system_main(int argc, char **argv) +static int deviced_main(int argc, char **argv) { - struct ss_main_data ad; + int ret; - init_ad(&ad); - edbus_init(&ad); - devices_init(&ad); + edbus_init(NULL); + devices_init(NULL); + ret = check_systemd_active(); + if (ret == TRUE) { + _I("notify relaunch"); + device_notify(DEVICE_NOTIFIER_BOOTING_DONE, (void *)TRUE); + } signal(SIGTERM, sig_quit); signal(SIGUSR1, sig_usr1); ecore_main_loop_begin(); - devices_exit(&ad); - edbus_exit(&ad); + devices_exit(NULL); + edbus_exit(NULL); ecore_shutdown(); return 0; } int main(int argc, char **argv) { - writepid(SS_PIDFILE_PATH); + writepid(PIDFILE_PATH); ecore_init(); - return system_main(argc, argv); + return deviced_main(argc, argv); } diff --git a/src/core/noti.c b/src/core/noti.c deleted file mode 100644 index 6845a18..0000000 --- a/src/core/noti.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 -#include "log.h" -#include "data.h" -#include "devices.h" -#include "common.h" - -static int noti_fd; - -int ss_noti_getfd() -{ - return noti_fd; -} - -int ss_noti_send(char *filename) -{ - return heynoti_publish(filename); -} - -int ss_noti_add(const char *noti, void (*cb) (void *), void *data) -{ - if (noti_fd < 0) - return -1; - - return heynoti_subscribe(noti_fd, noti, cb, data); -} - -static void noti_init(void *data) -{ - struct ss_main_data *ad = (struct ss_main_data*)data; - - if ((ad->noti_fd = heynoti_init()) < 0) { - _E("Hey Notification Initialize failed"); - return; - } - if (heynoti_attach_handler(ad->noti_fd) != 0) { - _E("fail to attach hey noti handler"); - return; - } - - noti_fd = heynoti_init(); - if (noti_fd < 0) { - _E("heynoti_init error"); - return; - } - - if (heynoti_attach_handler(noti_fd) < 0) { - _E("heynoti_attach_handler error"); - return; - } -} - -static void noti_exit(void *data) -{ - struct ss_main_data *ad = (struct ss_main_data*)data; - - heynoti_close(ad->noti_fd); - heynoti_close(noti_fd); -} - -static const struct device_ops noti_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "noti", - .init = noti_init, - .exit = noti_exit, -}; - -DEVICE_OPS_REGISTER(¬i_device_ops) diff --git a/src/core/noti.h b/src/core/noti.h deleted file mode 100644 index ddeef41..0000000 --- a/src/core/noti.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 __SS_NOTI_H__ -#define __SS_NOTI_H__ - -int ss_noti_getfd(void); -int ss_noti_send(char *filename); -int ss_noti_add(const char *noti, void (*cb) (void *), void *data); - -#endif /* __SS_NOTI_H__ */ diff --git a/src/core/power-supply.c b/src/core/power-supply.c new file mode 100644 index 0000000..7cdd4e4 --- /dev/null +++ b/src/core/power-supply.c @@ -0,0 +1,856 @@ +/* + * 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 +#include +#include +#include +#include +#include "devices.h" +#include "device-handler.h" +#include "device-notifier.h" +#include "udev.h" +#include "log.h" +#include "display/poll.h" +#include "display/setting.h" +#include "proc/proc-handler.h" +#include "config-parser.h" +#include "power-supply.h" + +#define BUFF_MAX 255 +#define POPUP_KEY_CONTENT "_SYSPOPUP_CONTENT_" + +#define SIGNAL_CHARGEERR_RESPONSE "ChargeErrResponse" +#define SIGNAL_TEMP_GOOD "TempGood" + +#define ABNORMAL_CHECK_TIMER_INTERVAL 60 + +#define METHOD_FULL_NOTI_ON "BatteryFullNotiOn" +#define METHOD_FULL_NOTI_OFF "BatteryFullNotiOff" +#define METHOD_CHARGE_NOTI_ON "BatteryChargeNotiOn" + +#define SIOP_DISABLE "memory/private/sysman/siop_disable" + +#define RETRY_MAX 5 +#define BATTERY_CHECK_TIMER_INTERVAL (0.5) + +#ifdef MICRO_DD +#define DEVICE_NOTIFIER "/usr/bin/sys_device_noti" +#define BATT_CHARGE_NOTI "0" +#define BATT_FULL_NOTI "2" +#endif + +enum power_supply_init_type { + POWER_SUPPLY_NOT_READY = 0, + POWER_SUPPLY_INITIALIZED = 1, +}; + +struct popup_data { + char *name; + char *key; + char *value; +}; + +static Ecore_Timer *power_timer = NULL; +static Ecore_Timer *abnormal_timer = NULL; +extern int battery_power_off_act(void *data); + +static void pm_check_and_change(int bInserted) +{ + static int old = -1; + if (old != bInserted) { + old = bInserted; + internal_pm_change_state(LCD_NORMAL); + } +} + +int check_lowbat_charge_device(int bInserted) +{ + static int bChargeDeviceInserted = 0; + int val = -1; + int bat_state = -1; + int ret = -1; + char *value; + struct popup_data *params; + static const struct device_ops *apps = NULL; + + pm_check_and_change(bInserted); + if (bInserted == 1) { + if (battery.charge_now) + bChargeDeviceInserted = 1; + return 0; + } else if (bInserted == 0) { + if (!battery.charge_now && bChargeDeviceInserted == 1) { + bChargeDeviceInserted = 0; + //low bat popup during charging device removing + if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) == 0) { + if(bat_state < VCONFKEY_SYSMAN_BAT_NORMAL + || bat_state == VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF) { + FIND_DEVICE_INT(apps, "apps"); + + if(bat_state == VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF) + value = "poweroff"; + else + value = "warning"; + params = malloc(sizeof(struct popup_data)); + if (params == NULL) { + _E("Malloc failed"); + return -1; + } + params->name = "lowbat-syspopup"; + params->key = POPUP_KEY_CONTENT; + params->value = value; + _I("%s %s %s(%x)", params->name, params->key, params->value, params); + if (apps->init) + apps->init((void *)params); + free(params); + } + } else { + _E("failed to get vconf key"); + return -1; + } + } + return 0; + } + return -1; +} + +static int changed_battery_cf(enum present_type status) +{ + struct popup_data *params; + static const struct device_ops *apps = NULL; + + FIND_DEVICE_INT(apps, "apps"); + params = malloc(sizeof(struct popup_data)); + if (params == NULL) { + _E("Malloc failed"); + return -ENOMEM; + } + params->name = "lowbat-syspopup"; + params->key = POPUP_KEY_CONTENT; + params->value = "battdisconnect"; + if (apps->init == NULL || apps->exit == NULL) + goto out; + if (status == PRESENT_ABNORMAL) + apps->init((void *)params); + else + apps->exit((void *)params); +out: + free(params); + return 0; +} + +int check_abnormal_popup(void) +{ + int ret = HEALTH_BAD; + + if (abnormal_timer) + ret = HEALTH_GOOD; + return ret; +} + +static void abnormal_popup_timer_init(void) +{ + if (abnormal_timer == NULL) + return; + ecore_timer_del(abnormal_timer); + abnormal_timer = NULL; + _I("delete health timer"); +} + +static void health_status_broadcast(void) +{ + broadcast_edbus_signal(DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, + SIGNAL_TEMP_GOOD, NULL, NULL); +} + +static int clean_health_popup(void) +{ + struct popup_data *params; + static const struct device_ops *apps = NULL; + + FIND_DEVICE_INT(apps, "apps"); + params = malloc(sizeof(struct popup_data)); + if (params == NULL) { + _E("Malloc failed"); + return -ENOMEM; + } + params->name = "lowbat-syspopup"; + params->key = POPUP_KEY_CONTENT; + if (apps->exit) + apps->exit((void *)params); + health_status_broadcast(); +out: + free(params); + return 0; + +} + +static void health_timer_reset(void) +{ + abnormal_timer = NULL; +} + +static Eina_Bool health_timer_cb(void *data) +{ + health_timer_reset(); + + if (battery.health == HEALTH_GOOD) + return EINA_FALSE; + + _I("popup - Battery health status is not good"); + vconf_set_int(SIOP_DISABLE, 1); + device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)HEALTH_BAD); + pm_change_internal(getpid(), LCD_NORMAL); + pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); + if (battery.temp == TEMP_LOW) + battery_charge_err_low_act(NULL); + else if (battery.temp == TEMP_HIGH) + battery_charge_err_high_act(NULL); + return EINA_FALSE; +} + +static void abnormal_popup_edbus_signal_handler(void *data, DBusMessage *msg) +{ + if (battery.health == HEALTH_GOOD) + return; + _I("restart health timer"); + abnormal_timer = ecore_timer_add(ABNORMAL_CHECK_TIMER_INTERVAL, + health_timer_cb, NULL); + if (abnormal_timer == NULL) + _E("Fail to add abnormal check timer"); +} + +static int noti_id; + +static void full_noti_cb(void *data, DBusMessage *msg, DBusError *err) +{ + DBusError r_err; + int ret, id; + + if (!msg) + return; + + dbus_error_init(&r_err); + ret = dbus_message_get_args(msg, &r_err, DBUS_TYPE_INT32, &id, DBUS_TYPE_INVALID); + if (!ret) { + _E("no message [%s:%s]", r_err.name, r_err.message); + dbus_error_free(&r_err); + return; + } + + noti_id = id; + _D("Inserted battery full noti : %d", noti_id); +} + +static int check_noti(void) +{ +#ifdef MICRO_DD + int r_disturb, s_disturb, r_block, s_block; + r_disturb = vconf_get_int("memory/shealth/sleep/do_not_disturb", &s_disturb); + r_block = vconf_get_bool("db/setting/blockmode_wearable", &s_block); + if ((r_disturb != 0 && r_block != 0) || + (s_disturb == 0 && s_block == 0)) { + return 1; + } + return 0; +#else + return 1; +#endif +} + +static int send_full_noti(enum charge_full_type state) +{ + int ret = 0; + int noti; + int retry; + char str_id[32]; + char *arr[1]; + + noti = check_noti(); + + if (!noti) + return noti; + + switch (state) { + case CHARGING_FULL: + for (retry = RETRY_MAX; retry > 0 ;retry--) { + ret = dbus_method_async_with_reply(POPUP_BUS_NAME, + POPUP_PATH_BATTERY, + POPUP_INTERFACE_BATTERY, + METHOD_FULL_NOTI_ON, + NULL, NULL, full_noti_cb, -1, NULL); + if (ret == 0) { + _D("Created battery full noti"); + return ret; + } + } + _E("Failed to call dbus method (err: %d)", ret); + break; + case CHARGING_NOT_FULL: + if (noti_id <= 0) + return -EPERM; + snprintf(str_id, sizeof(str_id), "%d", noti_id); + arr[0] = str_id; + for (retry = RETRY_MAX; retry > 0 ;retry--) { + ret = dbus_method_async(POPUP_BUS_NAME, + POPUP_PATH_BATTERY, + POPUP_INTERFACE_BATTERY, + METHOD_FULL_NOTI_OFF, + "i", arr); + if (ret == 0) { + _D("Deleted battery full noti"); + noti_id = 0; + return ret; + } + } + _E("Failed to call dbus method (err: %d)", ret); + break; + } + return ret; +} + +int send_charge_noti(void) +{ + int ret = 0; + int retry; + + for (retry = RETRY_MAX; retry > 0 ;retry--) { + ret = dbus_method_async(POPUP_BUS_NAME, + POPUP_PATH_BATTERY, + POPUP_INTERFACE_BATTERY, + METHOD_CHARGE_NOTI_ON, + NULL, NULL); + if (ret == 0) { + _D("Created battery charge noti"); + return ret; + } + } + _E("Failed to call dbus method (err: %d)", ret); + return ret; +} + +void battery_noti(enum battery_noti_type type, enum battery_noti_status status) +{ + static int charge = CHARGER_DISCHARGING; + static int full = CHARGING_NOT_FULL; + int ret, i; + + if (type == DEVICE_NOTI_BATT_FULL && status == DEVICE_NOTI_ON && + full == CHARGING_NOT_FULL) { + if (charge == CHARGER_DISCHARGING) + send_charge_noti(); + ret = send_full_noti(CHARGING_FULL); + if (ret == 0) + full = CHARGING_FULL; + } else if (type == DEVICE_NOTI_BATT_FULL && status == DEVICE_NOTI_OFF && + full == CHARGING_FULL) { + ret = send_full_noti(CHARGING_NOT_FULL); + if (ret == 0) + full = CHARGING_NOT_FULL; + } else if (type == DEVICE_NOTI_BATT_CHARGE && + battery.charge_now == CHARGER_CHARGING && + charge == CHARGER_DISCHARGING) { + if (full == CHARGING_FULL) { + ret = send_full_noti(CHARGING_NOT_FULL); + if (ret == 0) + full = CHARGING_NOT_FULL; + } + send_charge_noti(); + } + charge = battery.charge_now; +} + +static void noti_batt_full(void) +{ + char params[BUFF_MAX]; + static int bat_full_noti = 0; + int r_disturb, s_disturb, r_block, s_block; + + r_disturb = vconf_get_int("memory/shealth/sleep/do_not_disturb", &s_disturb); + r_block = vconf_get_bool("db/setting/blockmode_wearable", &s_block); + if (!battery.charge_full && bat_full_noti == 1) { + battery_noti(DEVICE_NOTI_BATT_FULL, DEVICE_NOTI_OFF); + bat_full_noti = 0; + } + if (battery.charge_full && bat_full_noti == 0) { + battery_noti(DEVICE_NOTI_BATT_FULL, DEVICE_NOTI_ON); + bat_full_noti = 1; + /* turn on LCD, if battery is full charged */ + if ((r_disturb != 0 && r_block != 0) || + (s_disturb == 0 && s_block == 0)) + pm_change_internal(getpid(), LCD_NORMAL); + else + _I("block LCD"); + } +} + +static void check_power_supply(int state) +{ + int ret = -1; + int val = 0; + char params[BUFF_MAX]; + + check_lowbat_charge_device(state); + if (update_pm_setting) + update_pm_setting(SETTING_CHARGING, state); + + ret = device_get_property(DEVICE_TYPE_POWER, + PROP_POWER_INSUSPEND_CHARGING_SUPPORT, &val); + + if (ret != 0 || val == 1) { + _D("fail to check charger insuspend"); + goto out; + } + + if (state == 0) + pm_unlock_internal(INTERNAL_LOCK_TA, LCD_OFF, STAY_CUR_STATE); + else + pm_lock_internal(INTERNAL_LOCK_TA, LCD_OFF, STAY_CUR_STATE, 0); +out: + _I("ta device %d(capacity %d)", state, battery.capacity); + + sync_cradle_status(); +} + +static void update_present(enum battery_noti_status status) +{ + static int old = DEVICE_NOTI_OFF; + enum present_type present; + + if (old == status) + return; + _I("charge %d present %d", battery.charge_now, battery.present); + old = status; + pm_change_internal(getpid(), LCD_NORMAL); + if (status == DEVICE_NOTI_ON) + present = PRESENT_ABNORMAL; + else + present = PRESENT_NORMAL; + changed_battery_cf(present); +} + +static void update_health(enum battery_noti_status status) +{ + static int old = DEVICE_NOTI_OFF; + + if (old == status) + return; + _I("charge %d health %d", battery.charge_now, battery.health); + old = status; + + if (status == DEVICE_NOTI_ON) { + _I("silent health popup"); + return; + } + + pm_change_internal(getpid(), LCD_NORMAL); + if (status == DEVICE_NOTI_ON) { + _I("popup - Battery health status is not good"); + vconf_set_int(SIOP_DISABLE, 1); + device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)HEALTH_BAD); + pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); + if (battery.temp == TEMP_LOW) + battery_charge_err_low_act(NULL); + else if (battery.temp == TEMP_HIGH) + battery_charge_err_high_act(NULL); + } else { + vconf_set_int(SIOP_DISABLE, 0); + device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)HEALTH_GOOD); + pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); + clean_health_popup(); + abnormal_popup_timer_init(); + } +} + +static void update_ovp(enum battery_noti_status status) +{ + static int old = DEVICE_NOTI_OFF; + + if (old == status) + return; + _I("charge %d ovp %d", battery.charge_now, battery.ovp); + old = status; + pm_change_internal(getpid(), LCD_NORMAL); +} + +static void check_battery_status(void) +{ + static int old = DEVICE_CHANGE_NORMAL; + int status; + + if (battery.charge_now == CHARGER_ABNORMAL && + (battery.health == HEALTH_BAD || battery.present == PRESENT_ABNORMAL)) + status = DEVICE_CHANGE_ABNORMAL; + else if (battery.ovp == OVP_ABNORMAL) + status = DEVICE_CHANGE_ABNORMAL; + else + status = DEVICE_CHANGE_NORMAL; + if (old == status) + return; + old = status; + + if (battery.charge_now == CHARGER_ABNORMAL) { + if (battery.health == HEALTH_BAD) { + update_health(DEVICE_NOTI_ON); + return; + } else if (battery.present == PRESENT_ABNORMAL) { + update_present(DEVICE_NOTI_ON); + return; + } + } + if (battery.ovp == OVP_ABNORMAL) { + update_ovp(DEVICE_NOTI_ON); + return; + } + + if (battery.charge_now != CHARGER_ABNORMAL && + status == DEVICE_CHANGE_NORMAL) { + update_health(DEVICE_NOTI_OFF); + update_ovp(DEVICE_NOTI_OFF); + update_present(DEVICE_NOTI_OFF); + } +} + +static void check_online(void) +{ + static int old_online; + + if (battery.online > POWER_SUPPLY_TYPE_BATTERY && + old_online == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED) { + old_online = VCONFKEY_SYSMAN_CHARGER_CONNECTED; + vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, old_online); + power_supply_broadcast(CHARGER_STATUS_SIGNAL, old_online); + extcon_set_count(EXTCON_TA); + check_power_supply(old_online); + } else if (battery.online <= POWER_SUPPLY_TYPE_BATTERY && + old_online == VCONFKEY_SYSMAN_CHARGER_CONNECTED) { + old_online = VCONFKEY_SYSMAN_CHARGER_DISCONNECTED; + vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, old_online); + power_supply_broadcast(CHARGER_STATUS_SIGNAL, old_online); + check_power_supply(old_online); + } +} + +static int load_uevent(struct parse_result *result, void *user_data) +{ + struct battery_status *info = user_data; + + if (!info) + return -EINVAL; + + if (MATCH(result->name, CHARGE_STATUS)) { + if (strstr(result->value, "Charging")) { + info->charge_now = CHARGER_CHARGING; + info->charge_full = CHARGING_NOT_FULL; + } else if (strstr(result->value, "Discharging")) { + info->charge_now = CHARGER_DISCHARGING; + info->charge_full = CHARGING_NOT_FULL; + } else if (strstr(result->value, "Full")) { + info->charge_now = CHARGER_DISCHARGING; + info->charge_full = CHARGING_FULL; + } else if (strstr(result->value, "Not charging")) { + info->charge_now = CHARGER_ABNORMAL; + info->charge_full = CHARGING_NOT_FULL; + } + } + else if (MATCH(result->name, CAPACITY)) + info->capacity = atoi(result->value); + return 0; +} + +static void power_load_uevent(void) +{ + int ret; + static int initialized = POWER_SUPPLY_NOT_READY; + + if (initialized == POWER_SUPPLY_INITIALIZED) + return; + ret = config_parse(POWER_SUPPLY_UEVENT, load_uevent, &battery); + if (ret < 0) + _E("Failed to load %s, %d Use default value!", POWER_SUPPLY_UEVENT, ret); + else + initialized = POWER_SUPPLY_INITIALIZED; +} + +void power_supply(void *data) +{ + int ret; + int status = POWER_SUPPLY_STATUS_DISCHARGING; + static struct battery_status old; + + if (old.charge_now != battery.charge_now || battery.charge_now == CHARGER_ABNORMAL) { + vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, battery.charge_now); + power_supply_broadcast(CHARGE_NOW_SIGNAL, battery.charge_now); + } + + if (old.online != battery.online || + old.charge_now != battery.charge_now || + old.charge_full != battery.charge_full) { + switch (battery.charge_now) + { + case CHARGER_ABNORMAL: + status = POWER_SUPPLY_STATUS_NOT_CHARGING; + break; + case CHARGER_DISCHARGING: + if (battery.charge_full == CHARGING_FULL) + status = POWER_SUPPLY_STATUS_FULL; + else + status = POWER_SUPPLY_STATUS_DISCHARGING; + break; + case CHARGER_CHARGING: + status = POWER_SUPPLY_STATUS_CHARGING; + break; + } + } + + lowbat_monitor(data); + check_online(); + if (old.charge_full != battery.charge_full) { + noti_batt_full(); + } + + old.capacity = battery.capacity; + old.online = battery.online; + old.charge_now = battery.charge_now; + old.charge_full = battery.charge_full; + + check_battery_status(); + device_notify(DEVICE_NOTIFIER_POWER_SUPPLY, NULL); +} + +void power_supply_status_init(void) +{ + int ret, val; + static int charge_now = -1; + static int charge_full = -1; + static int capacity = -1; + + power_load_uevent(); + battery.health = HEALTH_GOOD; + battery.ovp = OVP_NORMAL; + battery.present = PRESENT_NORMAL; + battery.temp = TEMP_LOW; + + if (charge_now == battery.charge_now && + charge_full == battery.charge_full && + capacity == battery.capacity) + return; + + if (charge_now != battery.charge_now || + charge_full != battery.charge_full || + capacity != battery.capacity) + _I("charging %d full %d capacity %d", battery.charge_now, battery.charge_full, battery.capacity); + + if (charge_now != battery.charge_now) { + vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, battery.charge_now); + power_supply_broadcast(CHARGE_NOW_SIGNAL, battery.charge_now); + } + if (capacity != battery.capacity) + vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery.capacity); + + charge_now = battery.charge_now; + charge_full = battery.charge_full; + capacity = battery.capacity; +} + +static Eina_Bool power_supply_update(void *data) +{ + power_supply_status_init(); + return EINA_TRUE; +} + +void power_supply_timer_start(void) +{ + _D("battery init timer during booting"); + power_timer = ecore_timer_add(BATTERY_CHECK_TIMER_INTERVAL, + power_supply_update, NULL); + if (power_timer == NULL) + _E("fail to add battery init timer during booting"); +} + +void power_supply_timer_stop(void) +{ + _D("battery init timer during booting"); + if (!power_timer) + return; + ecore_timer_del(power_timer); + power_timer = NULL; +} + +void power_supply_broadcast(char *sig, int status) +{ + static int old = 0; + static char sig_old[32]; + char *arr[1]; + char str_status[32]; + + if (strcmp(sig_old, sig) == 0 && old == status) + return; + + _D("%s %d", sig, status); + + old = status; + snprintf(sig_old, sizeof(sig_old), "%s", sig); + snprintf(str_status, sizeof(str_status), "%d", status); + arr[0] = str_status; + + broadcast_edbus_signal(DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, + sig, "i", arr); +} + +static DBusMessage *dbus_get_charger_status(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret; + + if (vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &ret) < 0) { + _E("vconf_get_int() failed"); + ret = -EIO; + } + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static DBusMessage *dbus_get_charge_now(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret; + + ret = battery.charge_now; + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static DBusMessage *dbus_get_charge_level(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret; + + if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &ret) < 0) { + _E("vconf_get_int() failed"); + ret = -EIO; + } + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static DBusMessage *dbus_get_percent(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret; + + ret = battery.capacity; + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static DBusMessage *dbus_get_percent_raw(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret, val; + + ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_CAPACITY_RAW, &val); + if (ret < 0) + goto out; + + if (val > 10000) + val = 10000; + + ret = val; + +out: + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static DBusMessage *dbus_is_full(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret; + + ret = battery.charge_full; + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static DBusMessage *dbus_get_health(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + int ret; + + ret = battery.health; + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + return reply; +} + +static const struct edbus_method edbus_methods[] = { + { CHARGER_STATUS_SIGNAL, NULL, "i", dbus_get_charger_status }, + { CHARGE_NOW_SIGNAL, NULL, "i", dbus_get_charge_now }, + { CHARGE_LEVEL_SIGNAL, NULL, "i", dbus_get_charge_level }, + { CHARGE_CAPACITY_SIGNAL, NULL, "i", dbus_get_percent }, + { CHARGE_CAPACITY_LAW_SIGNAL, NULL, "i", dbus_get_percent_raw }, + { CHARGE_FULL_SIGNAL, NULL, "i", dbus_is_full }, + { CHARGE_HEALTH_SIGNAL, NULL, "i", dbus_get_health }, +}; + +int power_supply_init(void *data) +{ + int ret; + + ret = register_edbus_method(DEVICED_PATH_BATTERY, edbus_methods, ARRAY_SIZE(edbus_methods)); + if (ret < 0) + _E("fail to init edbus method(%d)", ret); + ret = register_edbus_signal_handler(DEVICED_PATH_SYSNOTI, + DEVICED_INTERFACE_SYSNOTI, SIGNAL_CHARGEERR_RESPONSE, + abnormal_popup_edbus_signal_handler); + if (ret < 0) + _E("fail to init edbus signal(%d)", ret); + + /* for simple noti change cb */ + power_supply_status_init(); + power_supply(NULL); + return ret; +} diff --git a/src/core/power-supply.h b/src/core/power-supply.h new file mode 100644 index 0000000..49d3ea1 --- /dev/null +++ b/src/core/power-supply.h @@ -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 __POWER_SUPPLY_H__ +#define __POWER_SUPPLY_H__ + +#define CHARGER_STATUS_SIGNAL "ChargerStatus" +#define CHARGE_NOW_SIGNAL "ChargeNow" +#define CHARGE_LEVEL_SIGNAL "BatteryStatusLow" +#define CHARGE_CAPACITY_SIGNAL "GetPercent" +#define CHARGE_CAPACITY_LAW_SIGNAL "GetPercentRaw" +#define CHARGE_HEALTH_SIGNAL "GetHealth" +#define CHARGE_FULL_SIGNAL "IsFull" + +int check_abnormal_popup(void); +int check_lowbat_charge_device(int bInserted); +void power_supply(void *data); +int power_supply_init(void *data); +void power_supply_status_init(void); +void power_supply_timer_start(void); +void power_supply_timer_stop(void); +void power_supply_broadcast(char *sig, int status); +#endif /* __POWER_SUPPLY_H__ */ diff --git a/src/core/predefine.c b/src/core/predefine.c deleted file mode 100644 index b25f23f..0000000 --- a/src/core/predefine.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include "dd-deviced.h" -#include "log.h" -#include "launch.h" -#include "queue.h" -#include "device-handler.h" -#include "device-node.h" -#include "predefine.h" -#include "proc/proc-handler.h" -#include "data.h" -#include "common.h" -#include "display/poll.h" -#include "display/setting.h" -#include "devices.h" - -#define PREDEFINE_SO_DIR PREFIX"/lib/ss_predefine/" - -#define LOWBAT_EXEC_PATH PREFIX"/bin/lowbatt-popup" - -#define HDMI_NOTI_EXEC_PATH PREFIX"/bin/hdmi_connection_noti" -#define LOWBAT_POPUP_NAME "lowbat-syspopup" -#define POWEROFF_POPUP_NAME "poweroff-syspopup" -#define HDMI_POPUP_NAME "hdmi-syspopup" -#define LOWMEM_POPUP_NAME "lowmem-syspopup" - -static int __predefine_get_pid(const char *execpath) -{ - DIR *dp; - struct dirent *dentry; - int pid = -1, fd; - char buf[PATH_MAX]; - char buf2[PATH_MAX]; - - dp = opendir("/proc"); - if (!dp) { - _E("open /proc"); - return -1; - } - - while ((dentry = readdir(dp)) != NULL) { - if (!isdigit(dentry->d_name[0])) - continue; - - pid = atoi(dentry->d_name); - - snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid); - fd = open(buf, O_RDONLY); - if (fd < 0) - continue; - if (read(fd, buf2, PATH_MAX) < 0) { - close(fd); - continue; - } - close(fd); - - if (!strcmp(buf2, execpath)) { - closedir(dp); - return pid; - } - } - - errno = ESRCH; - closedir(dp); - return -1; -} - -int predefine_control_launch(char *name, bundle *b, int option) -{ - int pid; - static int launched_poweroff = 0; - //lowbat-popup - if (strncmp(name, LOWBAT_POPUP_NAME, strlen(LOWBAT_POPUP_NAME)) == 0) { - if (launched_poweroff == 1) { - _E("will be foreced power off"); - internal_poweroff_def_predefine_action(0,NULL); - return 0; - } - - if (option == 2) - launched_poweroff = 1; - - pid = __predefine_get_pid(LOWBAT_EXEC_PATH); - if (pid > 0) { - _E("pre launched %s destroy", LOWBAT_EXEC_PATH); - kill(pid, SIGTERM); - } - if (syspopup_launch(name, b) < 0) - return -1; - } - //poweroff-popup - if (strncmp(name, POWEROFF_POPUP_NAME, strlen(POWEROFF_POPUP_NAME)) == 0) { - if (syspopup_launch(name, b) < 0) - return -1; - } - //hdmi-popup - if (strncmp(name, HDMI_POPUP_NAME, strlen(HDMI_POPUP_NAME)) == 0) { - if (syspopup_launch(name, b) < 0) - return -1; - } - //hdmi-noti - if (strncmp(name, HDMI_NOTI_EXEC_PATH, strlen(HDMI_NOTI_EXEC_PATH)) == 0) { - if (ss_launch_if_noexist(name, "1") < 0) - return -1; - } - //user mem lowmem-popup - if (strncmp(name, LOWMEM_POPUP_NAME, strlen(LOWMEM_POPUP_NAME)) == 0) { - if (syspopup_launch(name, b) < 0) - return -1; - } - return 0; -} - -void predefine_pm_change_state(unsigned int s_bits) -{ - pm_change_internal(getpid(), s_bits); -} - -static void action_entry_load_from_sodir() -{ - DIR *dp; - struct dirent *dentry; - struct sysnoti *msg; - char *ext; - char tmp[128]; - - dp = opendir(PREDEFINE_SO_DIR); - if (!dp) { - _E("fail open %s", PREDEFINE_SO_DIR); - return; - } - - msg = malloc(sizeof(struct sysnoti)); - if (msg == NULL) { - _E("Malloc failed"); - closedir(dp); - return; - } - - msg->pid = getpid(); - - while ((dentry = readdir(dp)) != NULL) { - if ((ext = strstr(dentry->d_name, ".so")) == NULL) - continue; - - snprintf(tmp, sizeof(tmp), "%s/%s", PREDEFINE_SO_DIR, - dentry->d_name); - msg->path = tmp; - *ext = 0; - msg->type = &(dentry->d_name[3]); - action_entry_add(msg); - } - free(msg); - - closedir(dp); -} - -static void predefine_init(void *data) -{ - action_entry_load_from_sodir(); -} - -static const struct device_ops predefine_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "predefine", - .init = predefine_init, -}; - -DEVICE_OPS_REGISTER(&predefine_device_ops) diff --git a/src/core/predefine.h b/src/core/predefine.h deleted file mode 100644 index 6202b61..0000000 --- a/src/core/predefine.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 __SS_PREDEFINE_H__ -#define __SS_PREDEFINE_H__ -#include - -int call_predefine_action(int argc, char **argv); -void predefine_pm_change_state(unsigned int s_bits); -int predefine_control_launch(char *popup_name, bundle *b, int option); - -#endif /* __SS_PREDEFINE_H__ */ diff --git a/src/core/queue.c b/src/core/queue.c deleted file mode 100644 index def9d35..0000000 --- a/src/core/queue.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - * 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 -#include "data.h" -#include "core.h" -#include "queue.h" -#include "log.h" - -#define SS_PREDEFINE_ACT_FUNC_STR "ss_predefine_action" -#define SS_IS_ACCESSIBLE_FUNC_STR "ss_is_accessible" -#define SS_UI_VIEWABLE_FUNC_STR "ss_ui_viewable" - -static Eina_List *predef_act_list; -static Eina_List *run_queue; - -static struct ss_action_entry *action_entry_find(char *type) -{ - Eina_List *tmp; - Eina_List *tmp_next; - struct ss_action_entry *data; - - EINA_LIST_FOREACH_SAFE(predef_act_list, tmp, tmp_next, data) { - if ((data != NULL) && (!strcmp(data->type, type))) - return data; - } - - return NULL; -} - -int action_entry_add_internal(char *type, - int (*predefine_action) (), - int (*ui_viewable) (), - int (*is_accessible) (int)) -{ - struct ss_action_entry *data; - - data = malloc(sizeof(struct ss_action_entry)); - - if (data == NULL) { - _E("Malloc failed"); - return -1; - } - - data->type = NULL; - if (action_entry_find(type) != NULL) - goto err; - - data->handle = NULL; - data->predefine_action = predefine_action; - if (data->predefine_action == NULL) - goto err; - - data->is_accessible = is_accessible; - data->ui_viewable = ui_viewable; - data->owner_pid = getpid(); - data->type = strdup(type); - data->path = strdup(""); - - predef_act_list = eina_list_prepend(predef_act_list, data); - - _I("[SYSMAN] add predefine action entry suceessfully - %s", - data->type); - return 0; - err: - if (data->type != NULL) - _E("[SYSMAN] add predefine action entry -%s", - data->type); - free(data); - return -1; -} - -int action_entry_add(struct sysnoti *msg) -{ - struct ss_action_entry *data; - - data = malloc(sizeof(struct ss_action_entry)); - - if (data == NULL) { - _E("Malloc failed"); - return -1; - } - - if (action_entry_find(msg->type) != NULL) - goto err; - - data->handle = dlopen(msg->path, RTLD_LAZY); - if (!data->handle) { - _E("cannot find such library"); - goto err; - } - - data->predefine_action = dlsym(data->handle, SS_PREDEFINE_ACT_FUNC_STR); - if (data->predefine_action == NULL) { - _E("cannot find predefine_action symbol : %s", - SS_PREDEFINE_ACT_FUNC_STR); - goto err; - } - - data->is_accessible = dlsym(data->handle, SS_IS_ACCESSIBLE_FUNC_STR); - data->ui_viewable = dlsym(data->handle, SS_UI_VIEWABLE_FUNC_STR); - data->owner_pid = msg->pid; - data->type = strdup(msg->type); - data->path = strdup(msg->path); - - predef_act_list = eina_list_prepend(predef_act_list, data); - - _I("[SYSMAN]add predefine action entry suceessfully - %s", - data->type); - return 0; - err: - _E("[SYSMAN] FAIL predefine action entry - %s", msg->type); - free(data); - return -1; -} - -int action_entry_call_internal(char *type, int argc, ...) -{ - Eina_List *tmp; - Eina_List *tmp_next; - struct ss_action_entry *data; - va_list argptr; - int i; - char *args = NULL; - char *argv[SYSMAN_MAXARG]; - - if (argc > SYSMAN_MAXARG || type == NULL) - return -1; - - EINA_LIST_FOREACH_SAFE(predef_act_list, tmp, tmp_next, data) { - if ((data != NULL) && (!strcmp(data->type, type))) { - va_start(argptr, argc); - for (i = 0; i < argc; i++) { - args = va_arg(argptr, char *); - if (args != NULL) - argv[i] = strdup(args); - else - argv[i] = NULL; - } - va_end(argptr); - - int ret; - ret=ss_run_queue_add(data, argc, argv); - ret=ss_core_action_run(); - return 0; - } - } - - return 0; -} - -int action_entry_call(struct sysnoti *msg, int sockfd) -{ - Eina_List *tmp; - Eina_List *tmp_next; - struct ss_action_entry *data; - - EINA_LIST_FOREACH_SAFE(predef_act_list, tmp, tmp_next, data) { - if ((data != NULL) && (!strcmp(data->type, msg->type))) { - if (data->is_accessible != NULL - && data->is_accessible(sockfd) == 0) { - _E("%d cannot call that predefine module", msg->pid); - return -1; - } - int ret; - ret=ss_run_queue_add(data, msg->argc, msg->argv); - ret=ss_core_action_run(); - return 0; - } - } - - _E("[SYSMAN] cannot found action"); - return -1; -} - -int ss_run_queue_add(struct ss_action_entry *act_entry, int argc, char **argv) -{ - struct ss_run_queue_entry *rq_entry; - int i; - - rq_entry = malloc(sizeof(struct ss_run_queue_entry)); - - if (rq_entry == NULL) { - _E("Malloc failed"); - return -1; - } - - rq_entry->state = SS_STATE_INIT; - rq_entry->action_entry = act_entry; - rq_entry->forked_pid = 0; - if ( argc < 0 ) { - rq_entry->argc = 0; - } else { - rq_entry->argc = argc; - for (i = 0; i < argc; i++) - rq_entry->argv[i] = argv[i]; - } - - run_queue = eina_list_prepend(run_queue, rq_entry); - - _I("[SYSMAN] new action called : %s", act_entry->type); - return 0; -} - -int ss_run_queue_run(enum ss_run_state state, - int (*run_func) (void *, struct ss_run_queue_entry *), - void *user_data) -{ - Eina_List *tmp; - Eina_List *tmp_next; - struct ss_run_queue_entry *rq_entry; - - EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) { - if ((rq_entry != NULL) && (rq_entry->state == state)) - run_func(user_data, rq_entry); - } - - return 0; -} - -struct ss_run_queue_entry *ss_run_queue_find_bypid(int pid) -{ - Eina_List *tmp; - Eina_List *tmp_next; - struct ss_run_queue_entry *rq_entry; - - EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) { - if ((rq_entry != NULL) && (rq_entry->forked_pid == pid)) - return rq_entry; - } - - return NULL; -} - -int ss_run_queue_del(struct ss_run_queue_entry *entry) -{ - Eina_List *tmp; - Eina_List *tmp_next; - struct ss_run_queue_entry *rq_entry; - int i; - - EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) { - if ((rq_entry != NULL) && (rq_entry == entry)) { - run_queue = eina_list_remove(run_queue, rq_entry); - _I("[SYSMAN] action deleted : %s", - rq_entry->action_entry->type); - for (i = 0; i < rq_entry->argc; i++) { - if (rq_entry->argv[i]) - free(rq_entry->argv[i]); - } - free(rq_entry); - } - } - - return 0; -} - -int ss_run_queue_del_bypid(int pid) -{ - Eina_List *tmp; - Eina_List *tmp_next; - struct ss_run_queue_entry *rq_entry; - int i; - - EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) { - if ((rq_entry != NULL) && (rq_entry->forked_pid == pid)) { - run_queue = eina_list_remove(run_queue, rq_entry); - _I("[SYSMAN] action deleted : %s", - rq_entry->action_entry->type); - for (i = 0; i < rq_entry->argc; i++) { - if (rq_entry->argv[i]) - free(rq_entry->argv[i]); - } - free(rq_entry); - } - } - - return 0; -} diff --git a/src/core/queue.h b/src/core/queue.h deleted file mode 100644 index dee46b3..0000000 --- a/src/core/queue.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 __SS_QUEUE_H__ -#define __SS_QUEUE_H__ - -#include "sysnoti.h" - -struct ss_action_entry { - int owner_pid; - void *handle; - char *type; - char *path; - int (*predefine_action) (); - int (*ui_viewable) (); - int (*is_accessible) (int caller_sockfd); -}; - -enum ss_run_state { - SS_STATE_INIT, - SS_STATE_RUNNING, - SS_STATE_DONE -}; - -struct ss_run_queue_entry { - enum ss_run_state state; - struct ss_action_entry *action_entry; - int forked_pid; - int argc; - char *argv[SYSMAN_MAXARG]; -}; - -int action_entry_add_internal(char *type, - int (*predefine_action) (), - int (*ui_viewable) (), - int (*is_accessible) (int)); -int action_entry_add(struct sysnoti *msg); -int action_entry_call_internal(char *type, int argc, ...); -int action_entry_call(struct sysnoti *msg, int sockfd); - -int ss_run_queue_run(enum ss_run_state state, - int (*run_func) (void *, struct ss_run_queue_entry *), - void *user_data); - -struct ss_run_queue_entry *ss_run_queue_find_bypid(int pid); -int ss_run_queue_add(struct ss_action_entry *act_entry, int argc, char **argv); -int ss_run_queue_del(struct ss_run_queue_entry *entry); -int ss_run_queue_del_bypid(int pid); - -#endif /* __SS_QUEUE_H__ */ diff --git a/src/core/sig-handler.c b/src/core/sig-handler.c index 34f78d5..a04253c 100644 --- a/src/core/sig-handler.c +++ b/src/core/sig-handler.c @@ -21,7 +21,6 @@ #include #include #include -#include "core.h" #include "log.h" #include "edbus-handler.h" #include "display/poll.h" @@ -36,6 +35,9 @@ static void sig_child_handler(int signo, siginfo_t *info, void *data) pid_t pid; int status; + if (!info || signo != SIGCHLD) + return; + pid = waitpid(info->si_pid, &status, 0); if (pid == -1) { _E("SIGCHLD received\n"); @@ -43,8 +45,6 @@ static void sig_child_handler(int signo, siginfo_t *info, void *data) } _D("sig child actend call - %d\n", info->si_pid); - - ss_core_action_clear(info->si_pid); } static void sig_pipe_handler(int signo, siginfo_t *info, void *data) diff --git a/src/core/sysnoti.c b/src/core/sysnoti.c deleted file mode 100644 index 1fc56ca..0000000 --- a/src/core/sysnoti.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include "data.h" -#include "log.h" -#include "queue.h" -#include "common.h" -#include "devices.h" - -#define SYSNOTI_SOCKET_PATH "/tmp/sn" -#define RETRY_READ_COUNT 5 -enum sysnoti_cmd { - ADD_SYSMAN_ACTION, - CALL_SYSMAN_ACTION -}; - -static Ecore_Fd_Handler *sysnoti_efd = NULL; - -static int __sysnoti_start(void); -static int __sysnoti_stop(int fd); - -static void print_sysnoti_msg(const char *title, struct sysnoti *msg) -{ - int i; - char exe_name[PATH_MAX]; - - if (get_cmdline_name(msg->pid, exe_name, PATH_MAX) < 0) - snprintf(exe_name, sizeof(exe_name), "Unknown (maybe dead)"); - - _SD("pid : %d name: %s cmd : %d type : %s path : %s", - msg->pid, exe_name, msg->cmd, msg->type, msg->path); -} - -static inline int recv_int(int fd) -{ - int val, r = -1; - int retry_count = 0; - while (retry_count < RETRY_READ_COUNT) { - r = read(fd, &val, sizeof(int)); - if (r < 0) { - if(errno == EINTR) { - _E("Re-read for error(EINTR)"); - retry_count++; - continue; - } - else { - _E("Read fail for int"); - return -1; - } - } else { - return val; - } - } - return -1; -} - -static inline char *recv_str(int fd) -{ - int len, r = -1; - int retry_count = 0; - char *str; - - while (retry_count < RETRY_READ_COUNT) { - r = read(fd, &len, sizeof(int)); - if (r < 0) { - if(errno == EINTR) { - _E("Re-read for error(EINTR)"); - retry_count++; - continue; - } - else { - _E("Read fail for str length"); - return NULL; - } - } else - break; - } - if (retry_count == RETRY_READ_COUNT) { - _E("Read retry failed"); - return NULL; - } - if (len <= 0) - return NULL; - - if (len >= INT_MAX) { - _E("size is over INT_MAX"); - return NULL; - } - - str = (char *)malloc(len + 1); - if (str == NULL) { - _E("Not enough memory"); - return NULL; - } - retry_count = 0; - while (retry_count < RETRY_READ_COUNT) { - r = read(fd, str, len); - if(r < 0) { - if(errno == EINTR) { - _E("Re-read for error(EINTR)"); - retry_count++; - continue; - } else { - _E("Read fail for str"); - free(str); - str = NULL; - return NULL; - } - } else - break; - } - if (retry_count == RETRY_READ_COUNT) { - _E("Read retry failed"); - free(str); - str = NULL; - return NULL; - } - - str[len] = 0; - return str; -} - -static int read_message(int fd, struct sysnoti *msg) -{ - int i; - - if ((msg->pid = recv_int(fd)) == -1) - return -1; - if ((msg->cmd = recv_int(fd)) == -1) - return -1; - if ((msg->type = recv_str(fd)) == NULL) - return -1; - msg->path = recv_str(fd); - msg->argc = recv_int(fd); - - if (msg->argc < 0) - return -1; - for (i = 0; i < msg->argc; i++) - msg->argv[i] = recv_str(fd); - - return 0; -} - -static inline void internal_free(char *str) -{ - if (str) - free(str); -} - -static inline void free_message(struct sysnoti *msg) -{ - internal_free(msg->type); - internal_free(msg->path); - free(msg); -} - -static Eina_Bool sysnoti_cb(void *data, Ecore_Fd_Handler * fd_handler) -{ - int fd; - struct sysnoti *msg; - int ret = -1; - struct sockaddr_un client_address; - int client_sockfd; - int client_len; - - if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { - _E("ecore_main_fd_handler_active_get error , return"); - goto out; - } - - fd = ecore_main_fd_handler_fd_get(fd_handler); - msg = malloc(sizeof(struct sysnoti)); - if (msg == NULL) { - _E("Not enough memory"); - goto out; - } - - client_len = sizeof(client_address); - client_sockfd = accept(fd, (struct sockaddr *)&client_address, (socklen_t *)&client_len); - - if (client_sockfd == -1) { - _E("socket accept error"); - free(msg); - goto out; - } - if (read_message(client_sockfd, msg) < 0) { - _E("recv error msg"); - print_sysnoti_msg(__FUNCTION__, msg); - free_message(msg); - write(client_sockfd, &ret, sizeof(int)); - close(client_sockfd); - __sysnoti_stop(fd); - __sysnoti_start(); - goto out; - } - - print_sysnoti_msg(__FUNCTION__, msg); - if (msg->argc > SYSMAN_MAXARG) { - _E("error argument"); - free_message(msg); - write(client_sockfd, &ret, sizeof(int)); - close(client_sockfd); - goto out; - } - - switch (msg->cmd) { - case CALL_SYSMAN_ACTION: - ret = action_entry_call(msg, client_sockfd); - break; - default: - ret = -1; - } - - - write(client_sockfd, &ret, sizeof(int)); - close(client_sockfd); - - free_message(msg); -out: - return EINA_TRUE; -} - -static int ss_sysnoti_server_init(void) -{ - int fd; - struct sockaddr_un serveraddr; - - if (access(SYSNOTI_SOCKET_PATH, F_OK) == 0) - unlink(SYSNOTI_SOCKET_PATH); - - fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd < 0) { - _E("socket create failed"); - return -1; - } - if((fsetxattr(fd, "security.SMACK64IPOUT", "@", 2, 0)) < 0 ) { - _E("Socket SMACK labeling failed"); - if(errno != EOPNOTSUPP) { - close(fd); - return -1; - } - } - - if((fsetxattr(fd, "security.SMACK64IPIN", "*", 2, 0)) < 0 ) { - _E("Socket SMACK labeling failed"); - if(errno != EOPNOTSUPP) { - close(fd); - return -1; - } - } - - bzero(&serveraddr, sizeof(struct sockaddr_un)); - serveraddr.sun_family = AF_UNIX; - strncpy(serveraddr.sun_path, SYSNOTI_SOCKET_PATH, - sizeof(serveraddr.sun_path)); - - if (bind(fd, (struct sockaddr *)&serveraddr, sizeof(struct sockaddr)) < 0) { - _E("socket bind failed"); - close(fd); - return -1; - } - - if (chmod(SYSNOTI_SOCKET_PATH, (S_IRWXU | S_IRWXG | S_IRWXO)) < 0) /* 0777 */ - _E("failed to change the socket permission"); - - if (listen(fd, 5) < 0) { - _E("failed to listen"); - close(fd); - return -1; - } - - return fd; -} - -static int __sysnoti_start(void) -{ - int fd; - fd = ss_sysnoti_server_init(); - if ( fd < 0 ) - return -1; - sysnoti_efd = ecore_main_fd_handler_add(fd, ECORE_FD_READ, sysnoti_cb, NULL, NULL, - NULL); - if (!sysnoti_efd) { - _E("error ecore_main_fd_handler_add"); - return -1; - } - return fd; -} - -static int __sysnoti_stop(int fd) -{ - if (sysnoti_efd) { - ecore_main_fd_handler_del(sysnoti_efd); - sysnoti_efd = NULL; - } - if (fd >=0) { - close(fd); - fd = -1; - } - return 0; -} - -static void sysnoti_init(void *data) -{ - struct ss_main_data *ad = (struct ss_main_data*)data; - - ad->sysnoti_fd = __sysnoti_start(); -} - -static const struct device_ops sysnoti_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "sysnoti", - .init = sysnoti_init, -}; - -DEVICE_OPS_REGISTER(&sysnoti_device_ops) diff --git a/src/core/udev.h b/src/core/udev.h index bfa606f..441030a 100644 --- a/src/core/udev.h +++ b/src/core/udev.h @@ -20,23 +20,74 @@ #ifndef __UDEV_H__ #define __UDEV_H__ +#include + +#define UDEV "kernel" +#define UDEV_SUBSYSTEM "SUBSYSTEM" + +#define UDEV_ACTION "ACTION" +#define UDEV_CHANGE "change" +#define UDEV_ADD "add" +#define UDEV_REMOVE "remove" + +#define UDEV_DEVPATH "DEVPATH" + +#define UDEV_MONITOR_SIZE (10*1024) +#define UDEV_MONITOR_SIZE_LARGE (128*1024*1024) + +/* platform */ +#define PLATFORM_SUBSYSTEM "platform" + /* battery device */ -#define POWER_SUBSYSTEM "power_supply" +#define POWER_SUBSYSTEM "power_supply" +#define POWER_PATH "/sys/class/power_supply/battery" +#define POWER_SUPPLY_UEVENT POWER_PATH"/uevent" +#define CAPACITY "POWER_SUPPLY_CAPACITY" +#define CHARGE_FULL "POWER_SUPPLY_CHARGE_FULL" +#define CHARGE_NOW "POWER_SUPPLY_CHARGE_NOW" +#define CHARGE_HEALTH "POWER_SUPPLY_HEALTH" +#define CHARGE_PRESENT "POWER_SUPPLY_PRESENT" +#define CHARGE_NAME "POWER_SUPPLY_NAME" +#define CHARGE_STATUS "POWER_SUPPLY_STATUS" +#define CHARGE_ONLINE "POWER_SUPPLY_ONLINE" /* input device */ #define INPUT_SUBSYSTEM "input" #define INPUT_PATH "*/input[0-9]*/event[0-9]*" -#define ADD "add" -#define REMOVE "remove" /* switch device */ #define SWITCH_SUBSYSTEM "switch" -/* block device */ -#define BLOCK_SUBSYSTEM "block" -#define MMC_PATH "*/mmcblk[0-9]" - /* host device */ #define HOST_SUBSYSTEM "host_notify" +/* power supply status */ +enum { + POWER_SUPPLY_STATUS_UNKNOWN = 0, + POWER_SUPPLY_STATUS_CHARGING, + POWER_SUPPLY_STATUS_DISCHARGING, + POWER_SUPPLY_STATUS_NOT_CHARGING, + POWER_SUPPLY_STATUS_FULL, +}; + +enum { + POWER_SUPPLY_TYPE_UNKNOWN = 0, + POWER_SUPPLY_TYPE_BATTERY, + POWER_SUPPLY_TYPE_UPS, + POWER_SUPPLY_TYPE_MAINS, + POWER_SUPPLY_TYPE_USB, +}; + +struct uevent_handler { + char *subsystem; + void (*uevent_func)(struct udev_device *dev); + void *data; +}; + +int register_uevent_control(const struct uevent_handler *uh); +void unregister_uevent_control(const struct uevent_handler *uh); +int register_kernel_uevent_control(const struct uevent_handler *uh); +void unregister_kernel_uevent_control(const struct uevent_handler *uh); + + #endif /* __UDEV_H__ */ diff --git a/src/cpu/cpu-handler.c b/src/cpu/cpu-handler.c index 02b7bc0..71d6d36 100644 --- a/src/cpu/cpu-handler.c +++ b/src/cpu/cpu-handler.c @@ -21,82 +21,130 @@ #include #include +#include "core/list.h" #include "core/log.h" -#include "core/data.h" #include "core/devices.h" #include "core/edbus-handler.h" #include "core/common.h" +#include "core/device-notifier.h" +#include "proc/proc-handler.h" -#define PREDEF_SET_MAX_FREQUENCY "set_max_frequency" -#define PREDEF_SET_MIN_FREQUENCY "set_min_frequency" -#define PREDEF_RELEASE_MAX_FREQUENCY "release_max_frequency" -#define PREDEF_RELEASE_MIN_FREQUENCY "release_min_frequency" +#define SET_MAX_FREQ "set_max_frequency" +#define SET_MIN_FREQ "set_min_frequency" +#define SET_FREQ_LEN 17 + +#define RELEASE_MAX_FREQ "release_max_frequency" +#define RELEASE_MIN_FREQ "release_min_frequency" +#define RELEASE_FREQ_LEN 21 + +#define POWER_SAVING_CPU_FREQ_RATE (0.7) #define DEFAULT_MAX_CPU_FREQ 1200000 #define DEFAULT_MIN_CPU_FREQ 100000 -#define POWER_SAVING_CPUFREQ 800000 + +enum emergency_type { + EMERGENCY_UNLOCK = 0, + EMERGENCY_LOCK = 1, +}; static int max_cpu_freq_limit = -1; static int min_cpu_freq_limit = -1; static int cur_max_cpu_freq = INT_MAX; static int cur_min_cpu_freq = INT_MIN; +static int power_saving_freq = -1; -static Eina_List *max_cpu_freq_list; -static Eina_List *min_cpu_freq_list; +static dd_list *max_cpu_freq_list; +static dd_list *min_cpu_freq_list; + +static int cpu_number_limit = -1; +static int cur_cpu_number = INT_MAX; +static dd_list *cpu_number_list; struct cpu_freq_entry { int pid; int freq; }; -static void __set_freq_limit(); -static int __is_entry_enble(int pid); -static int __remove_entry_from_max_cpu_freq_list(int pid); -static int __remove_entry_from_min_cpu_freq_list(int pid); -static int __add_entry_to_max_cpu_freq_list(int pid, int freq); -static int __add_entry_to_min_cpu_freq_list(int pid, int freq); -static int __write_max_cpu_freq(int freq); -static int __write_min_cpu_freq(int freq); +struct cpu_number_entry { + int pid; + int number; +}; -int set_max_frequency_action(int argc, char **argv) +static int is_entry_enable(int pid) { - int r; - - if (argc < 2) - return -1; + char pid_path[PATH_MAX]; - r = __add_entry_to_max_cpu_freq_list(atoi(argv[0]), atoi(argv[1])); - if (r < 0) { - _E("Add entry failed"); - return -1; + snprintf(pid_path, PATH_MAX, "/proc/%d", pid); + if (access(pid_path, F_OK) < 0) { + return 0; } - r = __write_max_cpu_freq(cur_max_cpu_freq); - if (r < 0) { - _E("Write entry failed"); - return -1; + return 1; +} + +static int write_min_cpu_freq(int freq) +{ + int ret; + + ret = device_set_property(DEVICE_TYPE_CPU, PROP_CPU_SCALING_MIN_FREQ, freq); + if (ret < 0) { + _E("set cpufreq min freq write error: %s", strerror(errno)); + return ret; } return 0; } -int set_min_frequency_action(int argc, char **argv) +static int write_max_cpu_freq(int freq) { - int r; - - if (argc < 2) - return -1; + int ret; - r = __add_entry_to_min_cpu_freq_list(atoi(argv[0]), atoi(argv[1])); - if (r < 0) { - _E("Add entry failed"); - return -1; + ret = device_set_property(DEVICE_TYPE_CPU, PROP_CPU_SCALING_MAX_FREQ, freq); + if (ret < 0) { + _E("set cpufreq max freq write error: %s", strerror(errno)); + return ret; } - - r = __write_min_cpu_freq(cur_min_cpu_freq); - if (r < 0) { - _E("Write entry failed"); - return -1; + + return 0; +} + +static int remove_entry_from_min_cpu_freq_list(int pid) +{ + dd_list *tmp; + struct cpu_freq_entry *entry; + + cur_min_cpu_freq = INT_MIN; + + DD_LIST_FOREACH(min_cpu_freq_list, tmp, entry) { + if ((!is_entry_enable(entry->pid)) || (entry->pid == pid)) { + DD_LIST_REMOVE(min_cpu_freq_list, entry); + free(entry); + continue; + } + if (entry->freq > cur_min_cpu_freq) { + cur_min_cpu_freq = entry->freq; + } + } + + return 0; +} + +static int remove_entry_from_max_cpu_freq_list(int pid) +{ + dd_list *tmp; + struct cpu_freq_entry *entry; + + cur_max_cpu_freq = INT_MAX; + + DD_LIST_FOREACH(max_cpu_freq_list, tmp, entry) { + if ((!is_entry_enable(entry->pid)) || (entry->pid == pid)) { + DD_LIST_REMOVE(max_cpu_freq_list, entry); + free(entry); + continue; + } + if (entry->freq < cur_max_cpu_freq) { + cur_max_cpu_freq = entry->freq; + } } return 0; @@ -105,22 +153,23 @@ int set_min_frequency_action(int argc, char **argv) int release_max_frequency_action(int argc, char **argv) { int r; + if (argc < 1) - return -1; - - r = __remove_entry_from_max_cpu_freq_list(atoi(argv[0])); + return -EINVAL; + + r = remove_entry_from_max_cpu_freq_list(atoi(argv[0])); if (r < 0) { _E("Remove entry failed"); - return -1; + return r; } if (cur_max_cpu_freq == INT_MAX) cur_max_cpu_freq = max_cpu_freq_limit; - r = __write_max_cpu_freq(cur_max_cpu_freq); + r = write_max_cpu_freq(cur_max_cpu_freq); if (r < 0) { _E("Write freq failed"); - return -1; + return r; } return 0; @@ -131,291 +180,295 @@ int release_min_frequency_action(int argc, char **argv) int r; if (argc < 1) - return -1; + return -EINVAL; - r = __remove_entry_from_min_cpu_freq_list(atoi(argv[0])); + r = remove_entry_from_min_cpu_freq_list(atoi(argv[0])); if (r < 0) { _E("Remove entry failed"); - return -1; + return r; } if (cur_min_cpu_freq == INT_MIN) cur_min_cpu_freq = min_cpu_freq_limit; - r = __write_min_cpu_freq(cur_min_cpu_freq); + r = write_min_cpu_freq(cur_min_cpu_freq); if (r < 0) { _E("Write entry failed"); - return -1; + return r; } return 0; } -static int power_saving_cb(keynode_t *key_nodes, void *data) +static int add_entry_to_max_cpu_freq_list(int pid, int freq) { - int ret = -1; - int power_saving_stat = -1; - int power_saving_cpu_stat = -1; + int r; + struct cpu_freq_entry *entry; - power_saving_stat = vconf_keynode_get_bool(key_nodes); - if (power_saving_stat == 1) { - if (vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &power_saving_cpu_stat) == 0) { - if (power_saving_cpu_stat == 1) { - ret = __add_entry_to_max_cpu_freq_list(getpid(), POWER_SAVING_CPUFREQ); - if (ret < 0) { - _E("Add entry failed"); - return -1; - } - } - } else { - _E("failed to get vconf key"); - return -1; - } - } else { - ret = __remove_entry_from_max_cpu_freq_list(getpid()); - if (ret < 0) { - _E("Remove entry failed"); - return -1; - } - if (cur_max_cpu_freq == INT_MIN) - cur_max_cpu_freq = max_cpu_freq_limit; + r = remove_entry_from_max_cpu_freq_list(pid); + if (r < 0) { + _E("Remove duplicated entry failed"); } - ret = __write_max_cpu_freq(cur_max_cpu_freq); - if (ret < 0) { - _E("Write failed"); - return -1; + + entry = malloc(sizeof(struct cpu_freq_entry)); + if (!entry) { + _E("Malloc failed"); + return -ENOMEM; } + entry->pid = pid; + entry->freq = freq; + + DD_LIST_PREPEND(max_cpu_freq_list, entry); + if (!max_cpu_freq_list) { + _E("eina_list_prepend failed"); + return -ENOSPC; + } + if (freq < cur_max_cpu_freq) { + cur_max_cpu_freq = freq; + } return 0; } -static int power_saving_cpu_cb(keynode_t *key_nodes, void *data) +static int add_entry_to_min_cpu_freq_list(int pid, int freq) { - int ret = -1; - int power_saving_stat = -1; - int power_saving_cpu_stat = -1; + int r; + struct cpu_freq_entry *entry; - if (vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS, &power_saving_stat) == 0) { - if (power_saving_stat == 1) { - power_saving_cpu_stat = vconf_keynode_get_bool(key_nodes); - if (power_saving_cpu_stat == 1) { - ret = __add_entry_to_max_cpu_freq_list(getpid(), POWER_SAVING_CPUFREQ); - if (ret < 0) { - _E("Add entry failed"); - return -1; - } - } else { - ret = __remove_entry_from_max_cpu_freq_list(getpid()); - if (ret < 0) { - _E("Remove entry failed"); - return -1; - } - if (cur_max_cpu_freq == INT_MAX) - cur_max_cpu_freq = max_cpu_freq_limit; - } - ret = __write_max_cpu_freq(cur_max_cpu_freq); - if (ret < 0) { - _E("Write failed"); - return -1; - } - } - } else { - _E("failed to get vconf key"); - return -1; + r = remove_entry_from_min_cpu_freq_list(pid); + if (r < 0) { + _E("Remove duplicated entry failed"); + } + + entry = malloc(sizeof(struct cpu_freq_entry)); + if (!entry) { + _E("Malloc failed"); + return -ENOMEM; } + entry->pid = pid; + entry->freq = freq; + + DD_LIST_PREPEND(min_cpu_freq_list, entry); + if (!min_cpu_freq_list) { + _E("eina_list_prepend failed"); + return -ENOSPC; + } + if (freq > cur_min_cpu_freq) { + cur_min_cpu_freq = freq; + } return 0; } -static void __set_freq_limit() +int set_max_frequency_action(int argc, char **argv) { - int ret; - int power_saving_stat = -1; - int power_saving_cpu_stat = -1; + int r; - ret = device_get_property(DEVICE_TYPE_CPU, PROP_CPU_CPUINFO_MAX_FREQ, &max_cpu_freq_limit); - if (ret < 0) { - _E("get cpufreq cpuinfo max readerror: %s", strerror(errno)); - max_cpu_freq_limit = DEFAULT_MAX_CPU_FREQ; - } + if (argc < 2) + return -EINVAL; - ret = device_get_property(DEVICE_TYPE_CPU, PROP_CPU_CPUINFO_MIN_FREQ, &min_cpu_freq_limit); - if (ret < 0) { - _E("get cpufreq cpuinfo min readerror: %s", strerror(errno)); - min_cpu_freq_limit = DEFAULT_MIN_CPU_FREQ; + r = add_entry_to_max_cpu_freq_list(atoi(argv[0]), atoi(argv[1])); + if (r < 0) { + _E("Add entry failed"); + return r; } - /* check power saving */ - if (vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS, &power_saving_stat) == 0) { - if (power_saving_stat == 1) { - if (vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, &power_saving_cpu_stat) == 0) { - if (power_saving_cpu_stat == 1) { - ret = __add_entry_to_max_cpu_freq_list(getpid(), POWER_SAVING_CPUFREQ); - if (ret < 0) { - _E("Add entry failed"); - return; - } - ret = __write_max_cpu_freq(cur_max_cpu_freq); - if (ret < 0) { - _E("Write entry failed"); - return; - } - } - } else { - _E("failed to get vconf key"); - } - } - } else { - _E("failed to get vconf key"); + r = write_max_cpu_freq(cur_max_cpu_freq); + if (r < 0) { + _E("Write entry failed"); + return r; } + + return 0; } -static int __is_entry_enable(int pid) +int set_min_frequency_action(int argc, char **argv) { - char pid_path[PATH_MAX]; - - snprintf(pid_path, PATH_MAX, "/proc/%d", pid); - if (access(pid_path, F_OK) < 0) { - return 0; + int r; + + if (argc < 2) + return -EINVAL; + + r = add_entry_to_min_cpu_freq_list(atoi(argv[0]), atoi(argv[1])); + if (r < 0) { + _E("Add entry failed"); + return r; } - return 1; + r = write_min_cpu_freq(cur_min_cpu_freq); + if (r < 0) { + _E("Write entry failed"); + return r; + } + + return 0; } -static int __remove_entry_from_max_cpu_freq_list(int pid) +static int power_saving_cpu_cb(keynode_t *key_nodes, void *data) { - Eina_List *tmp; - Eina_List *tmp_next; - struct cpu_freq_entry *entry; - - cur_max_cpu_freq = INT_MAX; + int ret = 0; + int val = 0; + int power_saving_cpu_stat = -1; - EINA_LIST_FOREACH_SAFE(max_cpu_freq_list, tmp, tmp_next, entry) { - if (entry != NULL) { - if ((!__is_entry_enable(entry->pid)) || (entry->pid == pid)) { - max_cpu_freq_list = eina_list_remove(max_cpu_freq_list, entry); - free(entry); - continue; - } - - if (entry->freq < cur_max_cpu_freq) { - cur_max_cpu_freq = entry->freq; - } + power_saving_cpu_stat = vconf_keynode_get_bool(key_nodes); + if (power_saving_cpu_stat == 1) { + val = 1; + ret = add_entry_to_max_cpu_freq_list(getpid(), power_saving_freq); + if (ret < 0) { + _E("Add entry failed"); + goto out; + } + } else { + ret = remove_entry_from_max_cpu_freq_list(getpid()); + if (ret < 0) { + _E("Remove entry failed"); + goto out; } + if (cur_max_cpu_freq == INT_MAX) + cur_max_cpu_freq = max_cpu_freq_limit; } - - return 0; + ret = write_max_cpu_freq(cur_max_cpu_freq); + if (ret < 0) + _E("Write failed"); +out: + device_notify(DEVICE_NOTIFIER_PMQOS_POWERSAVING, (void*)val); + return ret; } -static int __remove_entry_from_min_cpu_freq_list(int pid) +static void set_emergency_limit(void) { - Eina_List *tmp; - Eina_List *tmp_next; - struct cpu_freq_entry *entry; + int ret, val; - cur_min_cpu_freq = INT_MIN; - - EINA_LIST_FOREACH_SAFE(min_cpu_freq_list, tmp, tmp_next, entry) { - if (entry != NULL) { - if ((!__is_entry_enable(entry->pid)) || (entry->pid == pid)) { - min_cpu_freq_list = eina_list_remove(min_cpu_freq_list, entry); - free(entry); - continue; - } + ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &val); + if (ret < 0) { + _E("failed to get vconf key"); + return; + } + if (val == SETTING_PSMODE_EMERGENCY) { + val = EMERGENCY_LOCK; + device_notify(DEVICE_NOTIFIER_PMQOS_EMERGENCY, (void*)val); + } +} - if (entry->freq > cur_min_cpu_freq) { - cur_min_cpu_freq = entry->freq; - } +static int emergency_cpu_cb(keynode_t *key_nodes, void *data) +{ + int val; - } - } + val = vconf_keynode_get_int(key_nodes); + if (val == SETTING_PSMODE_EMERGENCY) + val = EMERGENCY_LOCK; + else + val = EMERGENCY_UNLOCK; + device_notify(DEVICE_NOTIFIER_PMQOS_EMERGENCY, (void*)val); return 0; } -static int __add_entry_to_max_cpu_freq_list(int pid, int freq) +static void set_freq_limit(void) { - int r; - struct cpu_freq_entry *entry; - - r = __remove_entry_from_max_cpu_freq_list(pid); - if (r < 0) { - _E("Remove duplicated entry failed"); - } + int ret = 0; + int val = 0; + int power_saving_stat = -1; + int power_saving_cpu_stat = -1; - entry = malloc(sizeof(struct cpu_freq_entry)); - if (!entry) { - _E("Malloc failed"); - return -1; + ret = device_get_property(DEVICE_TYPE_CPU, PROP_CPU_CPUINFO_MAX_FREQ, + &max_cpu_freq_limit); + if (ret < 0) { + _E("get cpufreq cpuinfo max readerror: %s", strerror(errno)); + max_cpu_freq_limit = DEFAULT_MAX_CPU_FREQ; } - - entry->pid = pid; - entry->freq = freq; - max_cpu_freq_list = eina_list_prepend(max_cpu_freq_list, entry); - if (!max_cpu_freq_list) { - _E("eina_list_prepend failed"); - return -1; + ret = device_get_property(DEVICE_TYPE_CPU, PROP_CPU_CPUINFO_MIN_FREQ, + &min_cpu_freq_limit); + if (ret < 0) { + _E("get cpufreq cpuinfo min readerror: %s", strerror(errno)); + min_cpu_freq_limit = DEFAULT_MIN_CPU_FREQ; } - if (freq < cur_max_cpu_freq) { - cur_max_cpu_freq = freq; + power_saving_freq = (int)(max_cpu_freq_limit * POWER_SAVING_CPU_FREQ_RATE); + _I("max(%d) , ps(%d), min(%d)", + max_cpu_freq_limit, + power_saving_freq, + min_cpu_freq_limit); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, + &power_saving_cpu_stat); + if (ret < 0) { + _E("failed to get vconf key"); + return; + } + if (power_saving_cpu_stat != 1) + return; + val = 1; + ret = add_entry_to_max_cpu_freq_list(getpid(), power_saving_freq); + if (ret < 0) { + _E("Add entry failed"); + goto out; + } + ret = write_max_cpu_freq(cur_max_cpu_freq); + if (ret < 0) + _E("Write entry failed"); +out: + _I("init"); + device_notify(DEVICE_NOTIFIER_PMQOS_POWERSAVING, (void*)val); +} + +static int remove_entry_from_cpu_number_list(int pid) +{ + dd_list *tmp; + struct cpu_number_entry *entry; + + cur_cpu_number = INT_MAX; + + DD_LIST_FOREACH(cpu_number_list, tmp, entry) { + if ((!is_entry_enable(entry->pid)) || (entry->pid == pid)) { + DD_LIST_REMOVE(cpu_number_list, entry); + free(entry); + continue; + } + if (entry->number < cur_cpu_number) { + cur_cpu_number = entry->number; + } } + return 0; } -static int __add_entry_to_min_cpu_freq_list(int pid, int freq) +static int add_entry_to_cpu_number_list(int pid, int number) { int r; - struct cpu_freq_entry *entry; - - r = __remove_entry_from_min_cpu_freq_list(pid); + struct cpu_number_entry *entry; + + r = remove_entry_from_cpu_number_list(pid); if (r < 0) { _E("Remove duplicated entry failed"); } - entry = malloc(sizeof(struct cpu_freq_entry)); + + + entry = malloc(sizeof(struct cpu_number_entry)); if (!entry) { _E("Malloc failed"); - return -1; + return -ENOMEM; } - + entry->pid = pid; - entry->freq = freq; + entry->number = number; - min_cpu_freq_list = eina_list_prepend(min_cpu_freq_list, entry); - if (!min_cpu_freq_list) { + DD_LIST_PREPEND(cpu_number_list, entry); + if (!cpu_number_list) { _E("eina_list_prepend failed"); - return -1; + return -ENOSPC; } - if (freq > cur_min_cpu_freq) { - cur_min_cpu_freq = freq; + if (number < cur_cpu_number) { + cur_cpu_number = number; } return 0; } -static int __write_max_cpu_freq(int freq) +static int booting_done(void *data) { - int ret; - - ret = device_set_property(DEVICE_TYPE_CPU, PROP_CPU_SCALING_MAX_FREQ, freq); - if (ret < 0) { - _E("set cpufreq max freq write error: %s", strerror(errno)); - return -1; - } - - return 0; -} - -static int __write_min_cpu_freq(int freq) -{ - int ret; - - ret = device_set_property(DEVICE_TYPE_CPU, PROP_CPU_SCALING_MIN_FREQ, freq); - if (ret < 0) { - _E("set cpufreq min freq write error: %s", strerror(errno)); - return -1; - } - + set_freq_limit(); + set_emergency_limit(); return 0; } @@ -432,68 +485,63 @@ static DBusMessage *dbus_cpu_handler(E_DBus_Object *obj, DBusMessage *msg) dbus_error_init(&err); - if (!dbus_message_get_args(msg, &err, - DBUS_TYPE_STRING, &type_str, - DBUS_TYPE_INT32, &argc, - DBUS_TYPE_STRING, &argv[0], - DBUS_TYPE_STRING, &argv[1], DBUS_TYPE_INVALID)) { - _E("there is no message"); - ret = -EINVAL; - goto out; - } - - if (argc < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - pid = get_edbus_sender_pid(msg); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (strncmp(type_str, PREDEF_SET_MAX_FREQUENCY, strlen(PREDEF_SET_MAX_FREQUENCY)) == 0) - ret = set_max_frequency_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_SET_MIN_FREQUENCY, strlen(PREDEF_SET_MIN_FREQUENCY)) == 0) - ret = set_min_frequency_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_RELEASE_MAX_FREQUENCY, strlen(PREDEF_RELEASE_MAX_FREQUENCY)) == 0) - ret = release_max_frequency_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_RELEASE_MIN_FREQUENCY, strlen(PREDEF_RELEASE_MIN_FREQUENCY)) == 0) - ret = release_min_frequency_action(argc, (char **)&argv); + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &type_str, + DBUS_TYPE_INT32, &argc, + DBUS_TYPE_STRING, &argv[0], + DBUS_TYPE_STRING, &argv[1], DBUS_TYPE_INVALID)) { + _E("there is no message"); + ret = -EINVAL; + goto out; + } + + if (argc < 0) { + _E("message is invalid!"); + ret = -EINVAL; + goto out; + } + + pid = get_edbus_sender_pid(msg); + if (kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored!", pid); + ret = -ESRCH; + goto out; + } + + if (!strncmp(type_str, SET_MAX_FREQ, SET_FREQ_LEN)) + ret = set_max_frequency_action(argc, (char **)&argv); + else if (!strncmp(type_str, SET_MIN_FREQ, SET_FREQ_LEN)) + ret = set_min_frequency_action(argc, (char **)&argv); + else if (!strncmp(type_str, RELEASE_MAX_FREQ, RELEASE_FREQ_LEN)) + ret = release_max_frequency_action(argc, (char **)&argv); + else if (!strncmp(type_str, RELEASE_MIN_FREQ, RELEASE_FREQ_LEN)) + ret = release_min_frequency_action(argc, (char **)&argv); out: - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - return reply; + return reply; } static const struct edbus_method edbus_methods[] = { - { PREDEF_SET_MAX_FREQUENCY, "siss", "i", dbus_cpu_handler }, - { PREDEF_SET_MIN_FREQUENCY, "siss", "i", dbus_cpu_handler }, - { PREDEF_RELEASE_MAX_FREQUENCY, "siss", "i", dbus_cpu_handler }, - { PREDEF_RELEASE_MIN_FREQUENCY, "siss", "i", dbus_cpu_handler }, + { SET_MAX_FREQ, "siss", "i", dbus_cpu_handler }, + { SET_MIN_FREQ, "siss", "i", dbus_cpu_handler }, + { RELEASE_MAX_FREQ, "siss", "i", dbus_cpu_handler }, + { RELEASE_MIN_FREQ, "siss", "i", dbus_cpu_handler }, }; static void cpu_init(void *data) { int ret; + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods)); if (ret < 0) _E("fail to init edbus method(%d)", ret); - __set_freq_limit(); - action_entry_add_internal(PREDEF_SET_MAX_FREQUENCY, set_max_frequency_action, NULL, NULL); - action_entry_add_internal(PREDEF_SET_MIN_FREQUENCY, set_min_frequency_action, NULL, NULL); - action_entry_add_internal(PREDEF_RELEASE_MAX_FREQUENCY, release_max_frequency_action, NULL, NULL); - action_entry_add_internal(PREDEF_RELEASE_MIN_FREQUENCY, release_min_frequency_action, NULL, NULL); - - vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_SYSMODE_STATUS, (void *)power_saving_cb, NULL); vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, (void *)power_saving_cpu_cb, NULL); + vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, (void *)emergency_cpu_cb, NULL); } static const struct device_ops cpu_device_ops = { diff --git a/src/devicectl/CMakeLists.txt b/src/devicectl/CMakeLists.txt new file mode 100755 index 0000000..b5e2e3c --- /dev/null +++ b/src/devicectl/CMakeLists.txt @@ -0,0 +1,40 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(devicectl C) + +IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_ENGINEER_MODE") + OPTION(USE_ENGINEER_MODE "Use Engineer mode" ON) +ENDIF() + +SET(SRCS + devicectl.c + usb.c +) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED dbus-1) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +IF(USE_ENGINEER_MODE) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") +ELSE() + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer") +ENDIF() + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +MESSAGE("FLAGS: ${CMAKE_C_FLAGS}") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") +IF( $ENV{ARCH} MATCHES "arm" ) + ADD_DEFINITIONS("-DTARGET") +ENDIF() + +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} shared) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) + diff --git a/src/devicectl/devicectl.c b/src/devicectl/devicectl.c new file mode 100644 index 0000000..18f195f --- /dev/null +++ b/src/devicectl/devicectl.c @@ -0,0 +1,250 @@ +/* + * devicectl + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 +#include +#include +#include +#include +#include +#include "usb.h" + +/* + * devicectl [device] [action] + * ex> devicectl display stop + * devicectl pass start + */ + +enum device_type { + DEVICE_CORE, + DEVICE_DISPLAY, + DEVICE_LED, + DEVICE_PASS, + DEVICE_USB, + DEVICE_MAX, + DEVICE_ALL, +}; +static enum device_type arg_id; + +static const struct device { + const enum device_type id; + const char *name; + const char *path; + const char *iface; +} devices[] = { + { DEVICE_CORE, "core", DEVICED_PATH_CORE, DEVICED_INTERFACE_CORE }, + { DEVICE_DISPLAY, "display", DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY }, + { DEVICE_LED, "led", DEVICED_PATH_LED, DEVICED_INTERFACE_LED }, + { DEVICE_PASS, "pass", DEVICED_PATH_PASS, DEVICED_INTERFACE_PASS }, + { DEVICE_USB, "usb", DEVICED_PATH_USB, DEVICED_INTERFACE_USB }, +}; + +static int start_device(char **args) +{ + DBusMessage *msg; + + if (!args[1]) + return -EINVAL; + + printf("start %s device!\n", args[1]); + + msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, + devices[arg_id].path, devices[arg_id].iface, + "start", NULL, NULL); + if (!msg) + return -EBADMSG; + + dbus_message_unref(msg); + + return 0; +} + +static int stop_device(char **args) +{ + DBusMessage *msg; + + if (!args[1]) + return -EINVAL; + + printf("start %s device!\n", args[1]); + + msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, + devices[arg_id].path, devices[arg_id].iface, + "stop", NULL, NULL); + if (!msg) + return -EBADMSG; + + dbus_message_unref(msg); + + return 0; +} + +static int dump_mode(char **args) +{ + DBusError err; + DBusMessage *msg; + int ret, val; + char *arr[1]; + + if (!args[1] || !args[2] || !args[3]) + return -EINVAL; + + printf("%s (%s %s)!\n", args[1], args[2], args[3]); + + arr[0] = args[3]; + msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, + devices[arg_id].path, devices[arg_id].iface, + "Dumpmode", "s", arr); + if (!msg) + return -EBADMSG; + + dbus_error_init(&err); + + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); + if (!ret) { + printf("no message : [%s:%s]", err.name, err.message); + dbus_error_free(&err); + val = -ENOMSG; + } + + dbus_message_unref(msg); + return val; +} + +static int save_log(char **args) +{ + DBusMessage *msg; + + if (!args[1]) + return -EINVAL; + + printf("save log %s device!\n", args[1]); + + msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, + devices[arg_id].path, devices[arg_id].iface, + "SaveLog", NULL, NULL); + if (!msg) + return -EBADMSG; + + dbus_message_unref(msg); + + return 0; +} + +static int set_usb_mode(char **args) +{ + return load_usb_mode(args[3]); +} + +static int unset_usb_mode(char **args) +{ + return unload_usb_mode(args[3]); +} + +static const struct action { + const enum device_type id; + const char *action; + const int argc; + int (* const func)(char **args); + const char *option; +} actions[] = { + { DEVICE_ALL, "start", 3, start_device, "" }, + { DEVICE_ALL, "stop", 3, stop_device, "" }, + { DEVICE_DISPLAY, "dumpmode", 4, dump_mode, "[on|off]" }, + { DEVICE_LED, "dumpmode", 4, dump_mode, "[on|off]" }, + { DEVICE_DISPLAY, "savelog", 3, save_log, "" }, + { DEVICE_USB, "set", 4, set_usb_mode, "[sdb|ssh]" }, + { DEVICE_USB, "unset", 4, unset_usb_mode, "[sdb|ssh]" }, +}; + +static inline void usage() +{ + printf("[usage] devicectl \n"); + printf("Please use option --help to check options\n"); +} + +static void help() +{ + int i; + + printf("[usage] devicectl