register vconf callback to be notified status of power lock 38/56538/1 submit/tizen/20160128.073515
authorshingil.kang <shingil.kang@samsung.com>
Mon, 13 Apr 2015 07:41:02 +0000 (16:41 +0900)
committershingil.kang <shingil.kang@samsung.com>
Mon, 11 Jan 2016 05:47:51 +0000 (14:47 +0900)
Change-Id: Id39406a82f5c75c5eea66c28a17938cdb5f519f9
Signed-off-by: shingil.kang <shingil.kang@samsung.com>
packaging/sdbd.spec
src/sdb.c

index 4260794e539d3aeff0a630158bc5bac0102677e1..7357f6507778ffec36d4c4fe8e638dc63e830528 100644 (file)
@@ -104,4 +104,4 @@ fi
 /usr/share/license/%{name}
 /usr/bin/profile_command
 
-%changelog
+%changelog
\ No newline at end of file
index 2fff648f5552a5eba88e73fbbc9b606eeaf8ce7c..30d55a49c4fea39d8a8fa98a31dcc92a7308dc46 100644 (file)
--- a/src/sdb.c
+++ b/src/sdb.c
@@ -48,7 +48,9 @@
 #endif
 #include <system_info.h>
 #include <vconf.h>
+#include <glib.h>
 #include "utils.h"
+
 #define PROC_CMDLINE_PATH "/proc/cmdline"
 #define USB_SERIAL_PATH "/sys/class/usb_mode/usb0/iSerial"
 
@@ -1249,31 +1251,47 @@ int should_drop_privileges() {
     return 1;
 }
 
-static void *pwlock_tmp_cb(void *x)
-{
-    int status = is_pwlocked();
-    /**
-     * FIXME: make it callback using vconf_notify_key_changed
-     */
-
-    while(1) {
-        if (status != is_pwlocked()) {
-            send_device_status();
-            status = is_pwlocked();
-        }
-        sdb_sleep_ms(3000);
+static void pwlock_cb(keynode_t *key, void* data) {
+       D("pwlock callback is issued\n");
+    send_device_status();
+}
+
+static void *pwlock_thread(void *x) {
+       GMainLoop *loop;
+       loop = g_main_loop_new(NULL, FALSE);
+       register_pwlock_cb();
+       g_main_loop_run(loop);
+       g_main_loop_unref(loop);
+       unregister_pwlock_cb();
+       return 0;
+}
+
+
+void create_pwlock_thread() {
+    sdb_thread_t t;
+    if(sdb_thread_create( &t, pwlock_thread, NULL)) {
+        D("cannot create_pwlock_thread.\n");
+        return;
     }
-    return 0;
+    D("created pwlock_thread\n");
 }
 
 void register_pwlock_cb() {
-    D("registerd vconf callback\n");
+    int ret = vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE, pwlock_cb, NULL);
+    if(ret != 0) {
+        D("cannot register vconf callback.\n");
+        return;
+    }
+    D("registered vconf callback\n");
+}
 
-    sdb_thread_t t;
-    if(sdb_thread_create( &t, pwlock_tmp_cb, NULL)){
-        D("cannot create service thread\n");
+void unregister_pwlock_cb() {
+    int ret = vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE, pwlock_cb);
+    if(ret != 0) {
+        D("cannot unregister vconf callback.\n");
         return;
     }
+    D("unregistered vconf callback\n");
 }
 
 #include <dbus/dbus.h>
@@ -1650,11 +1668,11 @@ static void init_sdk_requirements() {
 
     execute_required_process();
 
-    register_pwlock_cb();
-
     if (is_emulator()) {
         register_bootdone_cb();
     }
+
+    create_pwlock_thread();
 }
 #endif /* !SDB_HOST */