suspend/resume: setting suspend lock state 01/13301/1
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Tue, 3 Dec 2013 06:56:58 +0000 (15:56 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Tue, 3 Dec 2013 06:56:58 +0000 (15:56 +0900)
Emuld sets the suspend lock state as default.
But now, it requests to qemu the lock state, and sets the state.

Change-Id: If3faa765971ffb61d2c1d8d22dcb3f032837d094
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
include/emuld.h
packaging/emuld.spec
src/emuld.cpp

index 8c6a8e1d65ae2f99281aa1da1e52787690227da7..052b9a36a7e393e7460e7adff3eb36fe8f6b1649 100644 (file)
@@ -75,6 +75,9 @@
 #define EMD_DEBUG
 #define POWEROFF_DURATION   2
 
+#define SUSPEND_UNLOCK      0
+#define SUSPEND_LOCK        1
+
 #define SDB_PORT_FILE       "/opt/home/sdb_port.txt"
 
 enum
@@ -94,6 +97,7 @@ extern int g_fd[fdtype_max];
 
 #define IJTYPE_TELEPHONY    "telephony"
 #define IJTYPE_SDCARD       "sdcard"
+#define IJTYPE_SUSPEND      "suspend"
 
 bool epoll_ctl_add(const int fd);
 
index 9ab81721b1b4fe06bfc5d7e200e4fa79cd3b3d7a..ea6703387e6f91036f1a1566dcb99619f4c364b5 100644 (file)
@@ -1,5 +1,5 @@
 Name: emuld
-Version: 0.4.0
+Version: 0.4.1
 Release: 0
 Summary: Emulator daemon
 License: Apache-2.0
index ed02f02a814505c016b4cbd7fca8d36e3f696713..d58ff8ebcda2bcce64b8f2d7200a53a642d19843 100644 (file)
@@ -78,6 +78,28 @@ void systemcall(const char* param)
         LOG("system call failure(command = %s)\n", param);
 }
 
+void set_lock_state(int state) {
+    int i = 0;
+    int ret = 0;
+    // Now we blocking to enter "SLEEP".
+    while(i < PMAPI_RETRY_COUNT ) {
+        if (state == SUSPEND_LOCK) {
+            ret = pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
+        } else {
+            ret = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
+        }
+        LOG("pm_lock_state() return: %d", ret);
+        if(ret == 0)
+        {
+            break;
+        }
+        ++i;
+        sleep(10);
+    }
+    if (i == PMAPI_RETRY_COUNT) {
+        LOG("Emulator Daemon: Failed to call pm_lock_state().\n");
+    }
+}
 
 /*---------------------------------------------------------------
 function : init_data0
@@ -628,7 +650,7 @@ bool accept_proc(const int server_fd)
     }
     else
     {
-        LOG("[Accpet] New client connected. fd:%d, port:%d"
+        LOG("[Accept] New client connected. fd:%d, port:%d"
                 ,cli_sockfd, cli_addr.sin_port);
 
         clipool_add(cli_sockfd, cli_addr.sin_port, fdtype_ij);
@@ -637,6 +659,44 @@ bool accept_proc(const int server_fd)
     return true;
 }
 
+static void msgproc_suspend(int fd, ijcommand* ijcmd, bool evdi)
+{
+    if (ijcmd->msg.action == SUSPEND_LOCK) {
+        set_lock_state(SUSPEND_LOCK);
+    } else {
+        set_lock_state(SUSPEND_UNLOCK);
+    }
+
+       LOG("[Suspend] Set lock state as %d (1: lock, other: unlock)\n", ijcmd->msg.action);
+}
+
+static void send_default_suspend_req(void)
+{
+    LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+    if(packet == NULL){
+        return;
+    }
+    memset(packet, 0, sizeof(LXT_MESSAGE));
+
+    packet->length = 0;
+    packet->group = 5;
+    packet->action = 15;
+
+       int tmplen = HEADER_SIZE;
+       char* tmp = (char*) malloc(tmplen);
+       if (!tmp)
+               return;
+
+    memcpy(tmp, packet, HEADER_SIZE);
+
+    ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SUSPEND, (const char*) tmp, tmplen);
+
+
+       if (tmp)
+           free(tmp);
+       if (packet)
+               free(packet);
+}
 
 static synbuf g_synbuf;
 
@@ -668,6 +728,10 @@ void process_evdi_command(ijcommand* ijcmd)
     {
         msgproc_sdcard(fd, ijcmd, true);
     }
+    else if (strncmp(ijcmd->cmd, "suspend", 7) == 0)
+    {
+        msgproc_suspend(fd, ijcmd, true);
+    }
     else
     {
         LOG("Unknown packet: %s", ijcmd->cmd);
@@ -803,18 +867,6 @@ void end_server(int sig)
     exit(0);
 }
 
-void set_lock_state() {
-    int i = 0;
-    // Now we blocking to enter "SLEEP".
-    while (i < PMAPI_RETRY_COUNT && pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0) == -1) {
-        ++i;
-        sleep(10);
-    }
-    if (i == PMAPI_RETRY_COUNT) {
-        fprintf(stderr, "Emulator Daemon: Failed to call pm_lock_state().\n");
-    }
-}
-
 int main( int argc , char *argv[])
 {
     int state;
@@ -872,7 +924,7 @@ int main( int argc , char *argv[])
 
     udp_init();
 
-    set_lock_state();
+    send_default_suspend_req();
 
     bool is_exit = false;