ecs: Add location data set/get
authorMunkyu Im <munkyu.im@samsung.com>
Wed, 23 Jul 2014 09:25:59 +0000 (18:25 +0900)
committerMunkyu Im <munkyu.im@samsung.com>
Wed, 23 Jul 2014 09:38:25 +0000 (18:38 +0900)
store location data in ecs.
When client needs location data, hand this value over.
change strncmp to strcmp.

Change-Id: I9bdcc17399ddefabbbe70ee3ff5b30f0c321fd60
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
tizen/src/ecs/ecs.c
tizen/src/ecs/ecs.h
tizen/src/ecs/ecs_msg.c

index e42d2bae343999e0f55855ff5d3f3394afa98c34..ca7568d2cb37fccc357a03a37e84afd09015b678 100644 (file)
@@ -72,6 +72,7 @@ static int g_client_id = 1;
 
 static QemuMutex mutex_clilist;
 QemuMutex mutex_guest_connection;
+QemuMutex mutex_location_data;
 
 static QemuThread ecs_thread_id;
 
@@ -235,6 +236,7 @@ static void ecs_close(ECS_State *cs) {
 
     qemu_mutex_destroy(&mutex_clilist);
     qemu_mutex_destroy(&mutex_guest_connection);
+    qemu_mutex_destroy(&mutex_location_data);
 }
 
 #ifndef _WIN32
@@ -715,6 +717,7 @@ static void* ecs_initialize(void* args) {
 
     qemu_mutex_init(&mutex_clilist);
     qemu_mutex_init(&mutex_guest_connection);
+    qemu_mutex_init(&mutex_location_data);
 
     TRACE("ecs_loop entered.\n");
     while (cs->ecs_running) {
index 7f912a20737a59924cc2bb54ca87cbdc5b228567..4d208b469675521244ee39bc5ff5c26ec9b0e929 100644 (file)
@@ -61,6 +61,7 @@
 #define COMMAND_TYPE_TETHERING  "tethering"
 
 #define MSG_TYPE_SENSOR         "sensor"
+#define MSG_TYPE_LOCATION       "location"
 #define MSG_TYPE_NFC            "nfc"
 #define MSG_TYPE_SIMUL_NFC      "simul_nfc"
 #define MSG_TYPE_SDCARD         "sdcard"
@@ -79,7 +80,8 @@ enum message_action {
     MSG_ACT_MAG = 112,
     MSG_ACT_LIGHT = 113,
     MSG_ACT_PROXI = 114,
-    MSG_ACT_MOTION = 115
+    MSG_ACT_MOTION = 115,
+    MSG_ACT_LOCATION = 120
 };
 
 #define TIMER_ALIVE_S           60
@@ -104,6 +106,7 @@ typedef unsigned char   type_action;
 #define OUT_BUF_SIZE    4096
 #define READ_BUF_LEN    4096
 #define MAX_ID_SIZE     255
+#define MAX_INJECTOR_REQ_DATA 32
 typedef struct sbuf
 {
     int _netlen;
index e1628e5a12fb93733815b58ddc05a1543701bcdd..9503a3d4834dfb998eb25a5cd0ccb35893e5bd7a 100644 (file)
@@ -77,7 +77,9 @@ MULTI_DEBUG_CHANNEL(qemu, ecs);
 // utility functions
 static int guest_connection = 0;
 extern QemuMutex mutex_guest_connection;
+extern QemuMutex mutex_location_data;
 
+static char location_data[MAX_INJECTOR_REQ_DATA];
 /*static function define*/
 static void handle_sdcard(char* dataBuf, size_t dataLen);
 static char* get_emulator_sdcard_path(void);
@@ -266,7 +268,7 @@ static void msgproc_device_ans(ECS_Client* ccli, const char* category, bool succ
 bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg)
 {
     char cmd[10];
-    char data[10];
+    char data[MAX_INJECTOR_REQ_DATA];
     bool ret = false;
     int sndlen = 0;
     int value = 0;
@@ -285,11 +287,11 @@ bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg)
     }
     //TRACE(">> count= %d", ++ijcount);
 
-    TRACE(">> header = cmd = %s, length = %d, action=%d, group=%d\n", cmd, length,
-            action, group);
+    TRACE(">> header = cmd = %s, length = %d, action=%d, group=%d, data= %s\n", cmd, length,
+            action, group, msg->data.data);
 
     /*SD CARD msg process*/
-    if (!strncmp(cmd, MSG_TYPE_SDCARD, strlen(MSG_TYPE_SDCARD))) {
+    if (!strcmp(cmd, MSG_TYPE_SDCARD)) {
         if (msg->has_data) {
             TRACE("msg(%zu) : %s\n", msg->data.len, msg->data.data);
             handle_sdcard((char*) msg->data.data, msg->data.len);
@@ -298,13 +300,17 @@ bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg)
             ERR("has no msg\n");
         }
 
-    } else if (!strncmp(cmd, MSG_TYPE_SENSOR, sizeof(MSG_TYPE_SENSOR))) {
+    } else if (!strcmp(cmd, MSG_TYPE_SENSOR)) {
         if (group == MSG_GROUP_STATUS) {
-            memset(data, 0, 10);
+            memset(data, 0, MAX_INJECTOR_REQ_DATA);
             if (action == MSG_ACT_BATTERY_LEVEL) {
                 sprintf(data, "%d", get_power_capacity());
             } else if (action == MSG_ACT_BATTERY_CHARGER) {
                 sprintf(data, "%d", get_jack_charger());
+            } else if (action == MSG_ACT_LOCATION) {
+                qemu_mutex_lock(&mutex_location_data);
+                sprintf(data, "%s", location_data);
+                qemu_mutex_unlock(&mutex_location_data);
             } else {
                 goto injector_send;
             }
@@ -317,12 +323,18 @@ bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg)
                 set_injector_data((char*) msg->data.data);
             }
         }
-    } else if (!strncmp(cmd, MSG_TYPE_GUEST, 5)) {
+    } else if (!strcmp(cmd, MSG_TYPE_GUEST)) {
         qemu_mutex_lock(&mutex_guest_connection);
         value = guest_connection;
         qemu_mutex_unlock(&mutex_guest_connection);
         send_status_injector_ntf(MSG_TYPE_GUEST, 5, value, NULL);
         return true;
+    } else if (!strcmp(cmd, MSG_TYPE_LOCATION)) {
+        if (msg->data.data && datalen > 0) {
+            qemu_mutex_lock(&mutex_location_data);
+            snprintf(location_data, msg->data.len + 1, "%s", (char*)msg->data.data);
+            qemu_mutex_unlock(&mutex_location_data);
+        }
     }
 
 injector_send:
@@ -469,7 +481,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
     TRACE(">> header = cmd = %s, length = %d, action=%d, group=%d\n", cmd, length,
             action, group);
 
-    if (!strncmp(cmd, MSG_TYPE_SENSOR, 6)) {
+    if (!strcmp(cmd, MSG_TYPE_SENSOR)) {
         if (group == MSG_GROUP_STATUS) {
             if (action == MSG_ACT_ACCEL) {
                 get_sensor_accel();
@@ -490,7 +502,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
             }
         }
         msgproc_device_ans(ccli, cmd, true, NULL);
-    } else if (!strncmp(cmd, "Network", 7)) {
+    } else if (!strcmp(cmd, "Network")) {
         if (data != NULL) {
             TRACE(">>> Network msg: '%s'\n", data);
             if(net_slirp_redir(data) < 0) {
@@ -501,7 +513,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
         } else {
             ERR("Network redirection data is null.\n");
         }
-    } else if (!strncmp(cmd, "HKeyboard", 8)) {
+    } else if (!strcmp(cmd, "HKeyboard")) {
         if (group == MSG_GROUP_STATUS) {
             send_host_keyboard_ntf(mloop_evcmd_get_hostkbd_status());
         } else {
@@ -510,13 +522,13 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
                 return false;
             }
 
-            if (!strncmp(data, "1", 1)) {
+            if (!strcmp(data, "1")) {
                 is_on = 1;
             }
             do_host_kbd_enable(is_on);
             notify_host_kbd_state(is_on);
         }
-    } else if (!strncmp(cmd, "TGesture", strlen("TGesture"))) {
+    } else if (!strcmp(cmd, "TGesture")) {
         /* release multi-touch */
 #ifndef CONFIG_USE_SHM
         if (get_multi_touch_enable() != 0) {
@@ -558,12 +570,12 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
 
             do_mouse_event(1/* LEFT */, event_type, 0, 0, xx, yy, zz);
         }
-    } else if (!strncmp(cmd, "info", 4)) {
+    } else if (!strcmp(cmd, "info")) {
         // check to emulator target image path
         TRACE("receive info message %s\n", tizen_target_img_path);
         send_target_image_information(ccli);
 
-    } else if (!strncmp(cmd, "input", strlen("input"))) {
+    } else if (!strcmp(cmd, "input")) {
         // cli input
         TRACE("receive input message [%s]\n", data);
 
@@ -593,10 +605,10 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
         }
         msgproc_device_ans(ccli, cmd, true, NULL);
 
-    } else if (!strncmp(cmd, "vmname", strlen("vmname"))) {
+    } else if (!strcmp(cmd, "vmname")) {
         char* vmname = get_emul_vm_name();
         msgproc_device_ans(ccli, cmd, true, vmname);
-    } else if (!strncmp(cmd, "nfc", strlen("nfc"))) {
+    } else if (!strcmp(cmd, "nfc")) {
         if (group == MSG_GROUP_STATUS) {
             //TODO:
             INFO("get nfc data: do nothing\n");
@@ -707,13 +719,13 @@ bool ntf_to_injector(const char* data, const int len) {
 static bool injector_req_handle(const char* cat, type_action action)
 {
     /*SD CARD msg process*/
-    if (!strncmp(cat, MSG_TYPE_SDCARD, strlen(MSG_TYPE_SDCARD))) {
+    if (!strcmp(cat, MSG_TYPE_SDCARD)) {
        return false;
 
-    } else if (!strncmp(cat, "suspend", 7)) {
+    } else if (!strcmp(cat, "suspend")) {
         ecs_suspend_lock_state(ecs_get_suspend_state());
         return true;
-    } else if (!strncmp(cat, MSG_TYPE_GUEST, 5)) {
+    } else if (!strcmp(cat, MSG_TYPE_GUEST)) {
         INFO("emuld connection is %d\n", action);
         qemu_mutex_lock(&mutex_guest_connection);
         guest_connection = action;