suspend/resume: setting suspend lock state 03/13303/1
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Tue, 3 Dec 2013 07:01:37 +0000 (16:01 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Tue, 3 Dec 2013 07:01:37 +0000 (16:01 +0900)
- qemu option "ignore-suspend-lock" is created, that skips
  suspend lock as default.
- qemu manages suspend state.
- sdb server can request suspend lock and unlock state.
- emulator daemon request to qumu the suspend state, and
  it sets default suspend state through power manager

Change-Id: I4d6e4898b41fca419501ce098eb8d1e67e843cb5
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
qemu-options.hx
tizen/src/ecs/ecs.c
tizen/src/ecs/ecs.h
tizen/src/ecs/ecs_msg.c
tizen/src/guest_server.c
vl.c

index cf891b2..8f43232 100644 (file)
@@ -3125,6 +3125,13 @@ STEXI
 @findex -disable-skin
 ETEXI
 
+DEF("ignore-suspend-lock", 0, QEMU_OPTION_ignore_suspend_lock, "", QEMU_ARCH_ALL)
+STEXI
+@item -ignore-suspend-lock
+@findex -ignore-suspend-lock
+Disable suspend lock statement in order to reach suspend power state
+ETEXI
+
 HXCOMM Internal use
 DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL)
 DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "", QEMU_ARCH_ALL)
index f44b8f3..7bbd271 100644 (file)
@@ -75,6 +75,18 @@ static int g_client_id = 1;
 
 static pthread_mutex_t mutex_clilist = PTHREAD_MUTEX_INITIALIZER;
 
+static int suspend_state = 1;
+
+void ecs_set_suspend_state(int state)
+{
+    suspend_state = state;
+}
+
+int ecs_get_suspend_state(void)
+{
+    return suspend_state;
+}
+
 static char* get_emulator_ecs_log_path(void)
 {
     gchar *emulator_ecs_log_path = NULL;
index 05e9c5e..a2b366c 100644 (file)
@@ -125,7 +125,6 @@ struct Monitor {
     int suspend_cnt;
     uint8_t outbuf[OUT_BUF_SIZE];
     int outbuf_index;
-    CPUArchState *mon_cpu;
     void *password_opaque;
     QError *error;
     QLIST_HEAD(,mon_fd_t) fds;
@@ -218,6 +217,13 @@ bool msgproc_tethering_req(ECS_Client* ccli, ECS__TetheringReq* msg);
 /* version check  */
 //void send_ecs_version_check(ECS_Client* ccli);
 
+/* Suspend/resume */
+#define SUSPEND_LOCK   1
+#define SUSPEND_UNLOCK 0
+int ecs_get_suspend_state(void);
+void ecs_set_suspend_state(int state);
+void ecs_suspend_lock_state(int state);
+
 /* request */
 int accel_min_max(double value);
 void req_set_sensor_accel(int x, int y, int z);
index 5ef0f6b..9942eef 100644 (file)
@@ -142,6 +142,9 @@ static bool send_to_single_client(ECS__Master* master, ECS_Client *ccli)
 #endif
 static void msgproc_injector_ans(ECS_Client* ccli, const char* category, bool succeed)
 {
+    if (ccli == NULL) {
+        return;
+    }
     int catlen = 0;
     ECS__Master master = ECS__MASTER__INIT;
     ECS__InjectorAns ans = ECS__INJECTOR_ANS__INIT;
@@ -223,6 +226,24 @@ injector_req_fail:
     msgproc_injector_ans(ccli, cmd, ret);
     return false;
 }
+
+void ecs_suspend_lock_state(int state)
+{
+    int catlen;
+
+    ECS__InjectorReq msg = ECS__INJECTOR_REQ__INIT;
+    const char* category = "suspend";
+
+    catlen = strlen(category);
+    msg.category = (char*) g_malloc0(catlen + 1);
+    memcpy(msg.category, category, catlen);
+
+    msg.group = 5;
+    msg.action = state;
+
+    msgproc_injector_req(NULL, &msg);
+}
+
 #if 0
 void msgproc_checkversion_req(ECS_Client* ccli, ECS__CheckVersionReq* msg)
 {
@@ -438,6 +459,16 @@ bool ntf_to_injector(const char* data, const int len) {
     return true;
 }
 
+static bool injector_req_handle(const char* cat)
+{
+    if (!strncmp(cat, "suspend", 7)) {
+        ecs_suspend_lock_state(ecs_get_suspend_state());
+        return true;
+    }
+
+    return false;
+}
+
 bool send_injector_ntf(const char* data, const int len)
 {
     type_length length = 0;
@@ -453,6 +484,9 @@ bool send_injector_ntf(const char* data, const int len)
     read_val_char(data + catsize + 2, &group);
     read_val_char(data + catsize + 2 + 1, &action);
 
+    if (injector_req_handle(cat)) {
+        return true;
+    }
 
     const char* ijdata = (data + catsize + 2 + 1 + 1);
 
@@ -464,7 +498,6 @@ bool send_injector_ntf(const char* data, const int len)
     ntf.category = (char*) g_malloc(catsize + 1);
     strncpy(ntf.category, cat, 10);
 
-
     ntf.length = length;
     ntf.group = group;
     ntf.action = action;
index 51a0d3f..4394f88 100644 (file)
@@ -54,6 +54,7 @@
 #include "maru_common.h"
 #include "hw/maru_virtio_hwkey.h"
 #include "hw/maru_pm.h"
+#include "ecs/ecs.h"
 
 MULTI_DEBUG_CHANNEL(qemu, guest_server);
 
@@ -92,7 +93,7 @@ static void remove_sdb_client(GS_Client* client)
     pthread_mutex_unlock(&mutex_clilist);
 }
 
-static void send_to_client(GS_Client* client, int state)
+static void send_to_sdb_client(GS_Client* client, int state)
 {
     struct sockaddr_in sock_addr;
     int s, slen = sizeof(sock_addr);
@@ -143,7 +144,7 @@ void notify_all_sdb_clients(int state)
 
     QTAILQ_FOREACH(client, &clients, next)
     {
-        send_to_client(client, state);
+        send_to_sdb_client(client, state);
     }
     pthread_mutex_unlock(&mutex_clilist);
 
@@ -191,7 +192,7 @@ static void add_sdb_client(struct sockaddr_in* addr, int port, const char* seria
 
     INFO("Added new sdb client. ip: %s, port: %d, serial: %s\n", inet_ntoa((client->addr).sin_addr), client->port, client->serial);
 
-    send_to_client(client, runstate_check(RUN_STATE_SUSPENDED));
+    send_to_sdb_client(client, runstate_check(RUN_STATE_SUSPENDED));
 }
 
 static int parse_val(char* buff, unsigned char data, char* parsbuf)
@@ -461,6 +462,11 @@ static void wakeup_guest(void)
     maru_hwkey_event(RELEASE, POWER_KEY);
 }
 
+static void suspend_lock_state(int state)
+{
+    ecs_suspend_lock_state(state);
+}
+
 static void command_handler(char* readbuf, struct sockaddr_in* client_addr)
 {
     char command[RECV_BUF_SIZE];
@@ -481,6 +487,10 @@ static void command_handler(char* readbuf, struct sockaddr_in* client_addr)
         register_sdb_server(readbuf, client_addr);
     } else if (strcmp(command, "6\n") == 0) {
         wakeup_guest();
+    } else if (strcmp(command, "7\n") == 0) {
+        suspend_lock_state(SUSPEND_LOCK);
+    } else if (strcmp(command, "8\n") == 0) {
+        suspend_lock_state(SUSPEND_UNLOCK);
     } else {
         INFO("!!! unknown command : %s\n", command);
     }
diff --git a/vl.c b/vl.c
index f8f648b..fbdde1b 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -189,6 +189,7 @@ int qemu_main(int argc, char **argv, char **envp);
 #include "tizen/src/emul_state.h"
 #include "tizen/src/maru_display.h"
 #include "tizen/src/skin/maruskin_operation.h"
+#include "tizen/src/ecs/ecs.h"
 #endif
 
 //#define DEBUG_NET
@@ -3996,6 +3997,11 @@ int main(int argc, char **argv, char **envp)
                 exit(1);
 #endif
                 break;
+#ifdef CONFIG_MARU
+            case QEMU_OPTION_ignore_suspend_lock:
+                ecs_set_suspend_state(SUSPEND_UNLOCK);
+                break;
+#endif
             case QEMU_OPTION_object:
                 opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1);
                 if (!opts) {