ecs: sync with 2.3 development 91/32791/1
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Fri, 19 Dec 2014 08:10:51 +0000 (17:10 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Wed, 24 Dec 2014 05:05:25 +0000 (21:05 -0800)
- bug fixed with ecs_mon not null terminate buffer
- added hds functionality
- added sensors(HRM, UV and Pressure)

Change-Id: I3a362a8b1e29acc55ed6ac8a9a9b538c5673f42a
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
13 files changed:
hw/9pfs/virtio-9p-device.c
tizen/src/ecs/ecs.h
tizen/src/ecs/ecs_mon.c
tizen/src/ecs/ecs_msg.c
tizen/src/ecs/ecs_msg_device.c
tizen/src/ecs/ecs_msg_injector.c
tizen/src/ecs/ecs_sensor.c
tizen/src/emul_state.c
tizen/src/emul_state.h
tizen/src/hw/virtio/maru_virtio_sensor.c
tizen/src/hw/virtio/maru_virtio_sensor.h
tizen/src/util/maru_device_hotplug.c
vl.c

index 05dd759..3228483 100644 (file)
@@ -22,6 +22,7 @@
 
 #ifdef CONFIG_MARU
 #include "tizen/src/util/maru_err_table.h"
+#include "tizen/src/emul_state.h"
 #endif
 
 static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features)
@@ -157,6 +158,12 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
 #endif
         goto out;
     }
+
+#ifdef CONFIG_MARU
+    set_emul_hds_attached(true);
+    set_emul_hds_path(fse->path);
+#endif
+
     v9fs_path_free(&path);
 
     return;
index 2f6b20a..d3a58eb 100644 (file)
 #define MSG_TYPE_GUEST          "guest"
 
 #define MSG_GROUP_STATUS        15
+#define MSG_GROUP_HDS           100
+
+#define HDS_ACTION_MOUNT        1
+#define HDS_ACTION_UMOUNT       2
 
 enum message_action {
     MSG_ACT_BATTERY_LEVEL = 100,
@@ -80,6 +84,9 @@ enum message_action {
     MSG_ACT_LIGHT = 113,
     MSG_ACT_PROXI = 114,
     MSG_ACT_MOTION = 115,
+    MSG_ACT_PRESSURE = 116,
+    MSG_ACT_UV = 117,
+    MSG_ACT_HRM = 118,
     MSG_ACT_LOCATION = 120
 };
 
@@ -94,7 +101,10 @@ enum injector_level {
     level_geo = 5,
     level_battery = 8,
     level_tilt = 12,
-    level_magnetic = 13
+    level_magnetic = 13,
+    level_pressure = 20,
+    level_uv = 21,
+    level_hrm = 22,
 };
 
 #define MAX_CATEGORY_LEN        10
@@ -178,6 +188,7 @@ bool ntf_to_monitor(const char* data, const int len);
 
 bool send_msg_to_guest(ECS_Client* ccli, char* cmd, int group, int action,
                        char* data, int data_len);
+
 void make_send_device_ntf (char* cmd, int group, int action, char* data);
 
 bool pb_to_all_clients(ECS__Master* master);
index ae4be4e..3999402 100644 (file)
@@ -126,6 +126,7 @@ static void ecs_monitor_flush(ECS_Client *clii, Monitor *mon) {
     if (clii && 0 < clii->client_fd && mon && mon->outbuf_index != 0) {
         //ret = ecs_write(clii->client_fd, mon->outbuf, mon->outbuf_index);
         ret = send_monitor_ntf((char*)mon->outbuf, mon->outbuf_index);
+        memset(mon->outbuf, 0, sizeof(mon->outbuf));
         mon->outbuf_index = 0;
         if (ret < -1) {
             ecs_client_close(clii);
@@ -149,8 +150,10 @@ static void ecs_monitor_puts(ECS_Client *clii, Monitor *mon, const char *str) {
             mon->outbuf[mon->outbuf_index++] = '\r';
 #endif
         mon->outbuf[mon->outbuf_index++] = c;
-        if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1) || c == '\n')
+        if (mon->outbuf_index >= (sizeof(mon->outbuf) - 2) || c == '\n') {
+            mon->outbuf[mon->outbuf_index++] = 0;
             ecs_monitor_flush(clii, mon);
+        }
     }
 }
 
index cb1567b..0f8ffc5 100644 (file)
@@ -28,7 +28,6 @@
  */
 
 #include <stdbool.h>
-#include <pthread.h>
 #include <glib.h>
 
 #include "hw/qdev.h"
@@ -134,10 +133,13 @@ void make_send_device_ntf (char* cmd, int group, int action, char* data)
     if (data != NULL) {
         length = strlen(data);
     }
+
     msg_length += length;
+
     char* send_msg = (char*) malloc(msg_length);
     if(!send_msg)
         return;
+
     memcpy(send_msg, cmd, 10);
     memcpy(send_msg + 10, &length, sizeof(unsigned short));
     memcpy(send_msg + 12, &group, sizeof(unsigned char));
@@ -145,12 +147,14 @@ void make_send_device_ntf (char* cmd, int group, int action, char* data)
     if (data != NULL) {
         memcpy(send_msg + 14, data, strlen(data));
     }
+
     send_device_ntf(send_msg, msg_length);
+
     free(send_msg);
 }
 
 bool send_msg_to_guest(ECS_Client* ccli, char* cmd, int group, int action, char* data, int data_len)
- {
+{
     int sndlen = 15; // HEADER(CMD + LENGTH + GROUP + ACTION) + 1
     char* sndbuf;
     bool ret = false;
@@ -162,6 +166,7 @@ bool send_msg_to_guest(ECS_Client* ccli, char* cmd, int group, int action, char*
     if (!sndbuf) {
         return false;
     }
+
     memcpy(sndbuf, cmd, 10);
     memcpy(sndbuf + 10, &data_len, 2);
     memcpy(sndbuf + 12, &group, 1);
@@ -175,7 +180,7 @@ bool send_msg_to_guest(ECS_Client* ccli, char* cmd, int group, int action, char*
         TRACE("telephony msg >>");
         ret = send_to_vmodem(route_ij, sndbuf, sndlen);
     } else {
-        INFO("evdi msg >> %s", cmd);
+        TRACE("evdi msg >> %s", cmd);
         ret = send_to_evdi(route_ij, sndbuf, sndlen);
     }
 
@@ -250,4 +255,3 @@ bool ntf_to_injector(const char* data, const int len) {
 
     return true;
 }
-
index 5fda57a..328d5a6 100644 (file)
@@ -56,7 +56,7 @@ static void msgproc_device_ans(ECS_Client* ccli, const char* category, bool succ
     ECS__Master master = ECS__MASTER__INIT;
     ECS__DeviceAns ans = ECS__DEVICE_ANS__INIT;
 
-    TRACE("device ans - category : %s, succed : %d\n", category, succeed);
+    LOG_TRACE("device ans - category : %s, succed : %d\n", category, succeed);
 
     catlen = strlen(category);
     ans.category = (char*) g_malloc0(catlen + 1);
@@ -72,7 +72,7 @@ static void msgproc_device_ans(ECS_Client* ccli, const char* category, bool succ
             ans.data.data = g_malloc(ans.length);
             ans.data.len = ans.length;
             memcpy(ans.data.data, data, ans.length);
-            TRACE("data = %s, length = %hu\n", data, ans.length);
+            LOG_TRACE("data = %s, length = %hu\n", data, ans.length);
         }
     }
 
@@ -107,7 +107,7 @@ void send_target_image_information(ECS_Client* ccli) {
         ans.data.len = length;
         memcpy(ans.data.data, tizen_target_img_path, length);
 
-        TRACE("data = %s, length = %hu\n", tizen_target_img_path, length);
+        LOG_TRACE("data = %s, length = %hu\n", tizen_target_img_path, length);
     }
 
     master.type = ECS__MASTER__TYPE__DEVICE_ANS;
@@ -146,15 +146,21 @@ static void msgproc_device_req_sensor(ECS_Client* ccli, ECS__DeviceReq* msg, cha
             get_sensor_light();
         } else if (action == MSG_ACT_PROXI) {
             get_sensor_proxi();
+        } else if (action == MSG_ACT_PRESSURE) {
+            get_sensor_pressure();
+        } else if (action == MSG_ACT_UV) {
+            get_sensor_uv();
+        } else if (action == MSG_ACT_HRM) {
+            get_sensor_hrm();
         }
     } else {
         if (data != NULL) {
             set_injector_data(data);
+            msgproc_device_ans(ccli, cmd, true, NULL);
         } else {
-            ERR("sensor set data is null\n");
+            LOG_SEVERE("sensor set data is null\n");
         }
     }
-    msgproc_device_ans(ccli, cmd, true, NULL);
 
     if (data) {
         g_free(data);
@@ -172,14 +178,14 @@ static void msgproc_device_req_network(ECS_Client* ccli, ECS__DeviceReq* msg)
     }
 
     if (data != NULL) {
-        TRACE(">>> Network msg: '%s'\n", data);
+        LOG_TRACE(">>> Network msg: '%s'\n", data);
         if(net_slirp_redir(data) < 0) {
-            ERR( "redirect [%s] fail\n", data);
+            LOG_SEVERE( "redirect [%s] fail\n", data);
         } else {
-            TRACE("redirect [%s] success\n", data);
+            LOG_TRACE("redirect [%s] success\n", data);
         }
     } else {
-        ERR("Network redirection data is null.\n");
+        LOG_SEVERE("Network redirection data is null.\n");
     }
 
     if (data) {
@@ -199,7 +205,7 @@ static void msgproc_device_req_tgesture(ECS_Client* ccli, ECS__DeviceReq* msg)
     }
 
     /* release multi-touch */
-#ifdef CONFIG_SDL
+#ifndef CONFIG_USE_SHM
     if (get_multi_touch_enable() != 0) {
         clear_finger_slot(false);
     }
@@ -208,11 +214,11 @@ static void msgproc_device_req_tgesture(ECS_Client* ccli, ECS__DeviceReq* msg)
 #endif
 
     if (data == NULL) {
-        ERR("touch gesture data is NULL\n");
+        LOG_SEVERE("touch gesture data is NULL\n");
         return;
     }
 
-    TRACE("%s\n", data);
+    LOG_TRACE("%s\n", data);
 
     char token[] = "#";
 
@@ -258,10 +264,10 @@ static void msgproc_device_req_input(ECS_Client* ccli, ECS__DeviceReq* msg, char
     }
 
     // cli input
-    TRACE("receive input message [%s]\n", data);
+    LOG_TRACE("receive input message [%s]\n", data);
 
     if (group == 0) {
-        TRACE("input keycode data : [%s]\n", data);
+        LOG_TRACE("input keycode data : [%s]\n", data);
 
         char token[] = " ";
         char *section = strtok(data, token);
@@ -275,13 +281,13 @@ static void msgproc_device_req_input(ECS_Client* ccli, ECS__DeviceReq* msg, char
             do_hw_key_event(KEY_RELEASED, keycode);
 
         } else {
-            ERR("unknown action : [%d]\n", (int)action);
+            LOG_SEVERE("unknown action : [%d]\n", (int)action);
         }
     } else if (group == 1) {
         //spec out
-        TRACE("input category's group 1 is spec out\n");
+        LOG_TRACE("input category's group 1 is spec out\n");
     } else {
-        ERR("unknown group [%d]\n", (int)group);
+        LOG_SEVERE("unknown group [%d]\n", (int)group);
     }
     msgproc_device_ans(ccli, cmd, true, NULL);
 
@@ -307,7 +313,7 @@ static void msgproc_device_req_nfc(ECS_Client* ccli, ECS__DeviceReq* msg)
         if (data != NULL) {
             send_to_nfc(ccli->client_id, ccli->client_type, data, msg->data.len);
         } else {
-            ERR("nfc data is null\n");
+            LOG_SEVERE("nfc data is null\n");
         }
     }
 
@@ -316,11 +322,10 @@ static void msgproc_device_req_nfc(ECS_Client* ccli, ECS__DeviceReq* msg)
     }
 }
 
-static char hds_path[PATH_MAX];
-
 static void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char * cmd)
 {
     char* data = NULL;
+    char token[] = "\n";
     type_group group = (type_group) (msg->group & 0xff);
     type_action action = (type_action) (msg->action & 0xff);
 
@@ -330,43 +335,60 @@ static void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char *
         memcpy(data, msg->data.data, msg->data.len);
     }
 
-    INFO("hds group: %d, action : %d\n", group, action);
+    LOG_INFO("hds group: %d, action : %d\n", group, action);
     if (group == MSG_GROUP_STATUS) {
         char hds_data_send[PATH_MAX + 3];
         if (is_hds_attached()) {
-            sprintf(hds_data_send, "1, %s", hds_path);
+            char* guest_path = get_emul_hds_guest_path();
+            if (strlen(guest_path) == 0) {
+                set_emul_hds_guest_path("/mnt/host");
+                guest_path = get_emul_hds_guest_path();
+            }
+            sprintf(hds_data_send, "1, %s, %s", get_emul_hds_path(), guest_path);
         } else {
             sprintf(hds_data_send, "0, ");
         }
         make_send_device_ntf(cmd, group, 99, hds_data_send);
-    } else if (group == 100 && action == 1) {
-        INFO("try attach with is_hds_attached : %d\n", is_hds_attached());
-        if (data != NULL && !is_hds_attached()) {
-            do_hotplug(ATTACH_HDS, data, strlen(data) + 1);
-            if (!is_hds_attached()) {
-                ERR("failed to attach");
-                make_send_device_ntf(cmd, 100, 2, NULL);
-            } else {
-                memset(hds_path, 0, sizeof(hds_path));
-                memcpy(hds_path, data, sizeof(hds_path) - 1);
-                INFO("send emuld to mount.\n");
-                send_msg_to_guest(ccli, cmd, group, action, data, strlen(data));
-            }
+    } else if (group == MSG_GROUP_HDS && action == HDS_ACTION_MOUNT) {
+        LOG_INFO("try attach with is_hds_attached : %d\n", is_hds_attached());
+        char *host = strtok(data, token);
+        if (host == NULL) {
+            make_send_device_ntf(cmd, group, 2, NULL);
+            goto hds_free;
+        }
+        char *guest = strtok(NULL, token);
+        if (guest == NULL) {
+            make_send_device_ntf(cmd, group, 2, NULL);
+            goto hds_free;
+        }
+
+        if (!is_hds_attached()) {
+            LOG_INFO("do attach host: %s\n", host);
+            do_hotplug(ATTACH_HDS, host, strlen(host) + 1);
+            LOG_INFO("send emuld to mount: %s, %d.\n", guest, strlen(guest));
+            set_emul_hds_guest_path(guest);
+            send_msg_to_guest(ccli, cmd, group, action, guest, strlen(guest) + 1);
         } else {
-            make_send_device_ntf(cmd, 100, 2, NULL);
+            make_send_device_ntf(cmd, group, 2, NULL);
         }
-    } else if (group == 100 && action == 2) {
-        INFO("try detach with is_hds_attached : %d\n", is_hds_attached());
+    } else if (group == MSG_GROUP_HDS && action == HDS_ACTION_UMOUNT) {
+        LOG_INFO("try detach with is_hds_attached : %d\n", is_hds_attached());
         if (is_hds_attached()) {
-            INFO("send emuld to umount.\n");
-            send_msg_to_guest(ccli, cmd, group, action, NULL, 0);
+            char* guest_path = get_emul_hds_guest_path();
+            if (strlen(guest_path) == 0) {
+                set_emul_hds_guest_path("/mnt/host");
+                guest_path = get_emul_hds_guest_path();
+            }
+            LOG_INFO("send emuld to umount.%s\n", guest_path);
+            send_msg_to_guest(ccli, cmd, group, action, guest_path, strlen(guest_path) + 1);
         } else {
-            INFO("hds is not attached. do not try detach it.\n");
+            LOG_INFO("hds is not attached. do not try detach it.\n");
+            make_send_device_ntf(cmd, group, 4, NULL);
         }
     } else {
-        ERR("hds unknown command: group %d action %d\n", group, action);
+        LOG_SEVERE("hds unknown command: group %d action %d\n", group, action);
     }
-
+hds_free:
     if (data) {
         g_free(data);
     }
@@ -378,7 +400,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
     memset(cmd, 0, 10);
     strcpy(cmd, msg->category);
 
-    TRACE(">> device_req: header = cmd = %s, length = %d, action=%d, group=%d\n",
+    LOG_TRACE(">> device_req: header = cmd = %s, length = %d, action=%d, group=%d\n",
             cmd, msg->length, msg->action, msg->group);
 
     if (!strcmp(cmd, MSG_TYPE_SENSOR)) {
@@ -389,7 +411,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
         msgproc_device_req_tgesture(ccli, msg);
     } else if (!strcmp(cmd, "info")) {
         // check to emulator target image path
-        TRACE("receive info message %s\n", tizen_target_img_path);
+        LOG_TRACE("receive info message %s\n", tizen_target_img_path);
         send_target_image_information(ccli);
     } else if (!strcmp(cmd, "hds")) {
         msgproc_device_req_hds(ccli, msg, cmd);
@@ -401,7 +423,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg)
     } else if (!strcmp(cmd, "nfc")) {
         msgproc_device_req_nfc(ccli, msg);
     } else {
-        ERR("unknown cmd [%s]\n", cmd);
+        LOG_SEVERE("unknown cmd [%s]\n", cmd);
     }
 
     return true;
@@ -424,7 +446,7 @@ bool send_device_ntf(const char* data, const int len)
 
     const char* ijdata = (data + catsize + 2 + 1 + 1);
 
-    TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group);
+    LOG_TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group);
 
     ECS__Master master = ECS__MASTER__INIT;
     ECS__DeviceNtf ntf = ECS__DEVICE_NTF__INIT;
@@ -445,7 +467,7 @@ bool send_device_ntf(const char* data, const int len)
         ntf.data.len = length;
         memcpy(ntf.data.data, ijdata, length);
 
-        TRACE("data = %s, length = %hu\n", ijdata, length);
+        LOG_TRACE("data = %s, length = %hu\n", ijdata, length);
     }
 
     master.type = ECS__MASTER__TYPE__DEVICE_NTF;
index 1d20de1..84423fb 100644 (file)
@@ -361,12 +361,12 @@ static int handle_sdcard(char* dataBuf, size_t dataLen)
 {
     int err_no = 0;
     char ret = 0;
-
     if (dataBuf != NULL){
         ret = dataBuf[0];
 
         if (ret == '0' ) {
             /* umount sdcard */
+            INFO("datalen: %d\n", dataLen);
             char* sdcard_img_path = get_sdcard_img_path(dataBuf + 2, dataLen);
             err_no = remove_sdcard_lock_os(sdcard_img_path);
             if (errno == 0 && is_sdcard_attached()) {
@@ -379,6 +379,7 @@ static int handle_sdcard(char* dataBuf, size_t dataLen)
             g_free(sdcard_img_path);
         } else if (ret == '1') {
             /* mount sdcard */
+            INFO("datalen: %d\n", dataLen);
             char* sdcard_img_path = get_sdcard_img_path(dataBuf + 2, dataLen);
             if ( !is_sdcard_attached() && make_sdcard_lock_os(sdcard_img_path)) {
                 do_hotplug(ATTACH_SDCARD, sdcard_img_path, strlen(sdcard_img_path) + 1);
@@ -570,10 +571,19 @@ static bool injector_req_handle(char* cat, type_action action)
     } else if (!strcmp(cat, "suspend")) {
         ecs_suspend_lock_state(ecs_get_suspend_state());
         return true;
+    } else if (!strcmp(cat, "boot")) {
+        LOG_INFO("emulator booting done.\n");
+        set_emulator_condition(BOOT_COMPLETED);
+        return true;
     } else if (!strcmp(cat, MSG_TYPE_GUEST)) {
         INFO("emuld connection is %d\n", action);
         qemu_mutex_lock(&mutex_guest_connection);
         guest_connection = action;
+        if (action == 1) {
+            set_emulator_condition(BOOT_COMPLETED);
+        } else {
+            set_emulator_condition(RESET);
+        }
         qemu_mutex_unlock(&mutex_guest_connection);
         return false;
     } else if (!strcmp(cat, "hds")) {
@@ -583,15 +593,12 @@ static bool injector_req_handle(char* cat, type_action action)
                 make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
                 break;
             case 2:
+                do_hotplug(DETACH_HDS, NULL, 0);
                 make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
                 break;
             case 3:
                 do_hotplug(DETACH_HDS, NULL, 0);
-                if (!is_hds_attached()) {
-                    make_send_device_ntf(cat, MSG_GROUP_HDS, 5, NULL);
-                } else {
-                    make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
-                }
+                make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
                 break;
             case 4:
                 make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
@@ -601,8 +608,6 @@ static bool injector_req_handle(char* cat, type_action action)
                 break;
         }
         return true;
-    } else {
-        ERR("unknown command: %s.\n", cat);
     }
 
     return false;
index 550637e..4be4cea 100644 (file)
 #include "hw/virtio/maru_virtio_power.h"
 #include "hw/virtio/maru_virtio_jack.h"
 
+#include "debug_ch.h"
+
+MULTI_DEBUG_CHANNEL(qemu, ecs);
+
 #define TEMP_BUF_SIZE   255
 #define MAX_VAL_LENGTH  40
 
@@ -69,7 +73,7 @@ static int get_parse_val (const char* buf, char* tmp)
 {
     int index = 0;
 
-    memset(tmp, 0, sizeof(TEMP_BUF_SIZE));
+    memset(tmp, 0, strlen(tmp));
 
     index = parse_val(buf, 0x0a, tmp);
     tmp[index - 1] = 0;
@@ -124,9 +128,9 @@ static void _req_set_sensor_accel(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     z = _accel_min_max(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
-    sprintf(tmp, "%d, %d, %d", x, y, z);
+    sprintf(tmp, "%d,%d,%d", x, y, z);
 
     set_sensor_accel(tmp, strlen(tmp));
 }
@@ -164,6 +168,82 @@ static void _req_set_sensor_light(int len, const char* data)
     }
 }
 
+static void _req_set_sensor_pressure(int len, const char* data)
+{
+    char tmp[TEMP_BUF_SIZE];
+    int pressure, temperature;
+
+    // get sensor level
+    len += get_parse_val(data + len, tmp);
+
+    // pressure
+    len += get_parse_val(data + len, tmp);
+    pressure = atoi(tmp);
+
+    // temperature
+    len += get_parse_val(data + len, tmp);
+    temperature = atoi(tmp);
+
+    memset(tmp, 0, sizeof(tmp));
+
+    sprintf(tmp, "%d, %d", pressure, temperature);
+
+    set_sensor_pressure(tmp, strlen(tmp));
+}
+
+static void _req_set_sensor_uv(int len, const char* data)
+{
+    char tmp[TEMP_BUF_SIZE];
+
+    // get sensor level
+    len += get_parse_val(data + len, tmp);
+
+    // value
+    len += get_parse_val(data + len, tmp);
+
+    set_sensor_uv(tmp, strlen(tmp));
+}
+
+static void _req_set_sensor_hrm(int len, const char* data)
+{
+    char tmp[TEMP_BUF_SIZE];
+    int hrm = 0, rri = 0, index = 0;
+
+    // get sensor level
+    len += get_parse_val(data + len, tmp);
+
+    // get index
+    len += get_parse_val(data + len, tmp);
+    index = atoi(tmp);
+
+    if (index == 1 || index == 0) {
+        // heart rate
+        len += get_parse_val(data + len, tmp);
+        hrm = atoi(tmp);
+    }
+
+    if (index == 2 || index == 0) {
+        // RRI
+        len += get_parse_val(data + len, tmp);
+        rri = atoi(tmp);
+    }
+
+    memset(tmp, 0, sizeof(tmp));
+
+    if (index == 0) {
+        sprintf(tmp, "%d, %d", hrm, rri);
+        set_sensor_hrm(tmp, strlen(tmp));
+    } else if (index == 1) {
+        sprintf(tmp, "%d", hrm);
+        set_sensor_hrm_heart(tmp, strlen(tmp));
+    } else if (index == 2) {
+        sprintf(tmp, "%d", rri);
+        set_sensor_hrm_rri(tmp, strlen(tmp));
+    } else {
+        LOG_SEVERE("unknown index with data '%s' & index '%d'\n", data, index);
+    }
+}
+
 static void _req_set_sensor_gyro(int len, const char* data)
 {
     char tmp[TEMP_BUF_SIZE];
@@ -184,7 +264,7 @@ static void _req_set_sensor_gyro(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     z = (int)atoi(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
     sprintf(tmp, "%d %d %d", x, y, z);
 
@@ -214,7 +294,7 @@ static void _req_set_sensor_geo(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     accuracy = atoi(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
     sprintf(tmp, "%d %d %d %d", x, y, z, accuracy);
 
@@ -232,7 +312,7 @@ static void _req_set_sensor_geo(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     t_vertical = atoi(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
     sprintf(tmp, "%d %d %d", t_north, t_east, t_vertical);
 
@@ -259,7 +339,7 @@ static void _req_set_sensor_tilt(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     z = atoi(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
     sprintf(tmp, "%d %d %d %d", x, y, z, accuracy);
 
@@ -286,7 +366,7 @@ static void _req_set_sensor_mag(int len, const char* data)
     len += get_parse_val(data + len, tmp);
     z = atoi(tmp);
 
-    memset(tmp, 0, TEMP_BUF_SIZE);
+    memset(tmp, 0, sizeof(tmp));
 
     sprintf(tmp, "%d %d %d", x, y, z);
 
@@ -356,6 +436,15 @@ void set_injector_data(const char* data)
         case level_magnetic:
             _req_set_sensor_mag(len, data);
             break;
+        case level_pressure:
+            _req_set_sensor_pressure(len, data);
+            break;
+        case level_uv:
+            _req_set_sensor_uv(len, data);
+            break;
+        case level_hrm:
+            _req_set_sensor_hrm(len, data);
+            break;
         default:
             break;
     }
index 0f47b12..4b8e5c5 100644 (file)
@@ -356,3 +356,43 @@ char* get_emul_vm_name(void)
     return _emul_info.vm_name;
 }
 
+void set_emul_hds_attached(bool attached)
+{
+    _emul_state.hds_attached = attached;
+}
+
+bool get_emul_hds_attached(void)
+{
+    return _emul_state.hds_attached;
+}
+
+void set_emul_hds_path(const char *path)
+{
+    if (path == NULL) {
+        memset(_emul_state.hds_path, 0, sizeof(_emul_state.hds_path));
+    } else {
+        strncpy(_emul_state.hds_path, path, sizeof(_emul_state.hds_path));
+        _emul_state.hds_path[sizeof(_emul_state.hds_path) -1] = 0;
+    }
+}
+
+char* get_emul_hds_path(void)
+{
+    return _emul_state.hds_path;
+}
+
+void set_emul_hds_guest_path(const char *path)
+{
+    if (path == NULL) {
+        memset(_emul_state.hds_guest_path, 0, sizeof(_emul_state.hds_guest_path));
+    } else {
+        strncpy(_emul_state.hds_guest_path, path, sizeof(_emul_state.hds_guest_path));
+        _emul_state.hds_guest_path[sizeof(_emul_state.hds_guest_path) -1] = 0;
+    }
+}
+
+char* get_emul_hds_guest_path(void)
+{
+    return _emul_state.hds_guest_path;
+}
+
index 5c9d599..0795d3c 100644 (file)
@@ -38,6 +38,8 @@
 
 #define SUPPORT_LEGACY_ARGS
 
+#define MAX_HDS_PATH    256
+
 enum {
     RESET = 0,
     BOOT_COMPLETED = 1,
@@ -110,6 +112,9 @@ typedef struct EmulatorConfigState {
     int qemu_caps_lock;
     int qemu_num_lock;
     /* add here */
+    bool hds_attached;
+    char hds_path[MAX_HDS_PATH];
+    char hds_guest_path[MAX_HDS_PATH];
 } EmulatorConfigState;
 
 /* misc */
@@ -139,6 +144,9 @@ void set_emul_rotation(short rotation_type);
 void set_emul_caps_lock_state(int state);
 void set_emul_num_lock_state(int state);
 void set_emul_vm_name(char *vm_name);
+void set_emul_hds_attached(bool attached);
+void set_emul_hds_path(const char *path);
+void set_emul_hds_guest_path(const char *path);
 
 /* getter */
 bool get_emul_skin_enable(void);
@@ -164,5 +172,8 @@ int get_host_lock_key_state_darwin(int key);
 int get_emul_caps_lock_state(void);
 int get_emul_num_lock_state(void);
 char* get_emul_vm_name(void);
+bool get_emul_hds_attached(void);
+char* get_emul_hds_path(void);
+char* get_emul_hds_guest_path(void);
 
 #endif /* __EMUL_STATE_H__ */
index 6efedac..3d9bd47 100644 (file)
@@ -46,6 +46,9 @@ static QemuMutex gyro_mutex;
 static QemuMutex light_mutex;
 static QemuMutex proxi_mutex;
 static QemuMutex rot_mutex;
+static QemuMutex pressure_mutex;
+static QemuMutex uv_mutex;
+static QemuMutex hrm_mutex;
 
 static char accel_xyz [__MAX_BUF_SENSOR] = {'1','0','0',',','9','8','0','6','6','5',',','1','0','0'};
 static int accel_enable = 0;
@@ -75,6 +78,19 @@ static char rot_quad [__MAX_BUF_SENSOR] = {'2','3','6','2',',','-','1','4','0','
 static int rot_enable = 0;
 static int rot_delay = 200000000;
 
+static char pressure_data [__MAX_BUF_SENSOR] = {'7','6','0',',',' ','4','2','5', 0};
+static int pressure_enable = 0;
+static int pressure_delay = 200000000;
+
+static int uv_level = 0;
+static int uv_enable = 0;
+static int uv_delay = 200000000;
+
+static int hrm_heart = 1000;
+static int hrm_rri = 600;
+static int hrm_enable = 0;
+static int hrm_delay = 200000000;
+
 VirtIOSENSOR* vsensor;
 static int sensor_capability = 0;
 
@@ -108,6 +124,15 @@ static type_action get_action(enum sensor_types type)
     case sensor_type_rotation_vector:
         action = ACTION_ROTATION;
         break;
+    case sensor_type_pressure:
+        action = ACTION_PRESSURE;
+        break;
+    case sensor_type_uv:
+        action = ACTION_UV;
+        break;
+    case sensor_type_hrm:
+        action = ACTION_HRM;
+        break;
     default:
         break;
     }
@@ -138,7 +163,7 @@ static void send_sensor_to_ecs(const char* data, enum sensor_types type)
     memcpy(ecs_message + 13, &action, sizeof(unsigned char));
     memcpy(ecs_message + 14, data, buf_len);
 
-    TRACE("ntf_to_injector- len: %d, group: %d, action: %d, data: %s\n", length, group, action, data);
+    LOG_TRACE("ntf_to_injector- len: %d, group: %d, action: %d, data: %s\n", length, group, action, data);
 
     send_device_ntf(ecs_message, message_len);
 
@@ -149,16 +174,16 @@ static void send_sensor_to_ecs(const char* data, enum sensor_types type)
 static void __set_sensor_data (enum sensor_types type, char* data, int len)
 {
     if (len < 0 || len > __MAX_BUF_SENSOR) {
-        ERR("sensor data size is wrong.\n");
+        LOG_SEVERE("sensor data size is wrong.\n");
         return;
     }
 
     if (data == NULL) {
-        ERR("sensor data is NULL.\n");
+        LOG_SEVERE("sensor data is NULL.\n");
         return;
     }
 
-    TRACE("set_sensor_data with type '%d' with data '%s'", type, data);
+    LOG_TRACE("set_sensor_data with type '%d' with data '%s'", type, data);
 
     switch (type) {
         case sensor_type_accel:
@@ -277,6 +302,61 @@ static void __set_sensor_data (enum sensor_types type, char* data, int len)
             sscanf(data, "%d", &geo_delay);
             qemu_mutex_unlock(&geo_mutex);
             break;
+        case sensor_type_pressure:
+            qemu_mutex_lock(&pressure_mutex);
+            strcpy(pressure_data, data);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_pressure_enable:
+            qemu_mutex_lock(&pressure_mutex);
+            sscanf(data, "%d", &pressure_enable);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_pressure_delay:
+            qemu_mutex_lock(&pressure_mutex);
+            sscanf(data, "%d", &pressure_delay);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_uv:
+            qemu_mutex_lock(&uv_mutex);
+            sscanf(data, "%d", &uv_level);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_uv_enable:
+            qemu_mutex_lock(&uv_mutex);
+            sscanf(data, "%d", &uv_enable);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_uv_delay:
+            qemu_mutex_lock(&uv_mutex);
+            sscanf(data, "%d", &uv_delay);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_hrm:
+            qemu_mutex_lock(&hrm_mutex);
+            sscanf(data, "%d, %d", &hrm_heart, &hrm_rri);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_heart:
+            qemu_mutex_lock(&hrm_mutex);
+            sscanf(data, "%d", &hrm_heart);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_rri:
+            qemu_mutex_lock(&hrm_mutex);
+            sscanf(data, "%d", &hrm_rri);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_enable:
+            qemu_mutex_lock(&hrm_mutex);
+            sscanf(data, "%d", &hrm_enable);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_delay:
+            qemu_mutex_lock(&hrm_mutex);
+            sscanf(data, "%d", &hrm_delay);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
         default:
             return;
     }
@@ -408,6 +488,51 @@ static void __get_sensor_data(enum sensor_types type, char* msg_info)
             sprintf(msg_info, "%d", rot_delay);
             qemu_mutex_unlock(&rot_mutex);
             break;
+        case sensor_type_pressure:
+            qemu_mutex_lock(&pressure_mutex);
+            strcpy(msg_info, pressure_data);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_pressure_enable:
+            qemu_mutex_lock(&pressure_mutex);
+            sprintf(msg_info, "%d", pressure_enable);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_pressure_delay:
+            qemu_mutex_lock(&pressure_mutex);
+            sprintf(msg_info, "%d", pressure_delay);
+            qemu_mutex_unlock(&pressure_mutex);
+            break;
+        case sensor_type_uv:
+            qemu_mutex_lock(&uv_mutex);
+            sprintf(msg_info, "%d", uv_level);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_uv_enable:
+            qemu_mutex_lock(&uv_mutex);
+            sprintf(msg_info, "%d", uv_enable);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_uv_delay:
+            qemu_mutex_lock(&uv_mutex);
+            sprintf(msg_info, "%d", uv_delay);
+            qemu_mutex_unlock(&uv_mutex);
+            break;
+        case sensor_type_hrm:
+            qemu_mutex_lock(&hrm_mutex);
+            sprintf(msg_info, "%d, %d", hrm_heart, hrm_rri);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_enable:
+            qemu_mutex_lock(&hrm_mutex);
+            sprintf(msg_info, "%d", hrm_enable);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
+        case sensor_type_hrm_delay:
+            qemu_mutex_lock(&hrm_mutex);
+            sprintf(msg_info, "%d", hrm_delay);
+            qemu_mutex_unlock(&hrm_mutex);
+            break;
         default:
             return;
     }
@@ -416,10 +541,10 @@ static void __get_sensor_data(enum sensor_types type, char* msg_info)
 void req_sensor_data (enum sensor_types type, enum request_cmd req, char* data, int len)
 {
     char msg_info [__MAX_BUF_SENSOR];
-    memset(msg_info, 0, __MAX_BUF_SENSOR);
+    memset(msg_info, 0, sizeof(msg_info));
 
     if (type >= sensor_type_max || (req != request_get && req != request_set)) {
-        ERR("unavailable sensor type request.\n");
+        LOG_SEVERE("unavailable sensor type request.\n");
         return;
     }
 
@@ -435,7 +560,7 @@ static void answer_sensor_data_request(int type, char* data, VirtQueueElement *e
 {
     msg_info* msginfo = (msg_info*) malloc(sizeof(msg_info));
     if (!msginfo) {
-        ERR("msginfo is NULL!\n");
+        LOG_SEVERE("msginfo is NULL!\n");
         return;
     }
 
@@ -443,7 +568,7 @@ static void answer_sensor_data_request(int type, char* data, VirtQueueElement *e
     msginfo->type = type;
     __get_sensor_data(type, msginfo->buf);
 
-    TRACE("sending message: %s, type: %d, req: %d\n", msginfo->buf, msginfo->type, msginfo->req);
+    LOG_TRACE("sending message: %s, type: %d, req: %d\n", msginfo->buf, msginfo->type, msginfo->req);
 
     memset(elem->in_sg[0].iov_base, 0, elem->in_sg[0].iov_len);
     memcpy(elem->in_sg[0].iov_base, msginfo, sizeof(struct msg_info));
@@ -457,7 +582,7 @@ static void handle_msg(struct msg_info *msg, VirtQueueElement *elem)
     unsigned int len = 0;
 
     if (msg == NULL) {
-        ERR("msg info structure is NULL.\n");
+        LOG_SEVERE("msg info structure is NULL.\n");
         return;
     }
 
@@ -480,17 +605,17 @@ static void virtio_sensor_vq(VirtIODevice *vdev, VirtQueue *vq)
     int index = 0;
 
     if (vsensor->vq == NULL) {
-        ERR("virt queue is not ready.\n");
+        LOG_SEVERE("virt queue is not ready.\n");
         return;
     }
 
     if (!virtio_queue_ready(vsensor->vq)) {
-        ERR("virtqueue is not ready.");
+        LOG_SEVERE("virtqueue is not ready.");
         return;
     }
 
     if (virtio_queue_empty(vsensor->vq)) {
-        ERR("<< virtqueue is empty.\n");
+        LOG_SEVERE("<< virtqueue is empty.\n");
         return;
     }
 
@@ -498,7 +623,7 @@ static void virtio_sensor_vq(VirtIODevice *vdev, VirtQueue *vq)
         memset(&msg, 0x00, sizeof(msg));
         memcpy(&msg, elem.out_sg[0].iov_base, elem.out_sg[0].iov_len);
 
-        TRACE("handling msg from driver: %s, len: %d, type: %d, req: %d, index: %d\n", msg.buf, strlen(msg.buf), msg.type, msg.req, index);
+        LOG_TRACE("handling msg from driver: %s, len: %d, type: %d, req: %d, index: %d\n", msg.buf, strlen(msg.buf), msg.type, msg.req, index);
 
         handle_msg(&msg, &elem);
     }
@@ -520,8 +645,14 @@ static int set_capability(char* sensor)
         return sensor_cap_rotation_vector;
     } else if (!strncmp(sensor, SENSOR_NAME_HAPTIC, 6)) {
         return sensor_cap_haptic;
+    } else if (!strncmp(sensor, SENSOR_NAME_PRESSURE, 5)) {
+        return sensor_cap_pressure;
+    } else if (!strncmp(sensor, SENSOR_NAME_UV, 2)) {
+        return sensor_cap_uv;
+    } else if (!strncmp(sensor, SENSOR_NAME_HRM, 3)) {
+        return sensor_cap_hrm;
     } else {
-        ERR("unknown sensor request: %s", sensor);
+        LOG_SEVERE("unknown sensor request: %s", sensor);
     }
 
     return 0;
@@ -543,12 +674,12 @@ static void parse_sensor_capability(char* lists)
         }
     }
 
-    INFO("sensor device capabilty enabled with %02x\n", sensor_capability);
+    LOG_INFO("sensor device capabilty enabled with %02x\n", sensor_capability);
 }
 
 static void virtio_sensor_realize(DeviceState *dev, Error **errp)
 {
-    INFO("initialize virtio-sensor device\n");
+    LOG_INFO("initialize virtio-sensor device\n");
 
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     vsensor = VIRTIO_SENSOR(vdev);
@@ -556,7 +687,7 @@ static void virtio_sensor_realize(DeviceState *dev, Error **errp)
     virtio_init(vdev, SENSOR_DEVICE_NAME, VIRTIO_ID_SENSOR, 0);
 
     if (vsensor == NULL) {
-        ERR("failed to initialize sensor device\n");
+        LOG_SEVERE("failed to initialize sensor device\n");
         error_set(errp, QERR_DEVICE_INIT_FAILED, SENSOR_DEVICE_NAME);
         return;
     }
@@ -567,10 +698,13 @@ static void virtio_sensor_realize(DeviceState *dev, Error **errp)
     qemu_mutex_init(&light_mutex);
     qemu_mutex_init(&proxi_mutex);
     qemu_mutex_init(&rot_mutex);
+    qemu_mutex_init(&pressure_mutex);
+    qemu_mutex_init(&uv_mutex);
+    qemu_mutex_init(&hrm_mutex);
 
     vsensor->vq = virtio_add_queue(&vsensor->vdev, 64, virtio_sensor_vq);
 
-    INFO("initialized sensor type: %s\n", vsensor->sensors);
+    LOG_INFO("initialized sensor type: %s\n", vsensor->sensors);
 
     if (vsensor->sensors) {
         parse_sensor_capability(vsensor->sensors);
@@ -580,7 +714,7 @@ static void virtio_sensor_realize(DeviceState *dev, Error **errp)
 static void virtio_sensor_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
-    INFO("destroy sensor device\n");
+    LOG_INFO("destroy sensor device\n");
 
     qemu_mutex_destroy(&accel_mutex);
     qemu_mutex_destroy(&gyro_mutex);
@@ -588,6 +722,9 @@ static void virtio_sensor_unrealize(DeviceState *dev, Error **errp)
     qemu_mutex_destroy(&light_mutex);
     qemu_mutex_destroy(&proxi_mutex);
     qemu_mutex_destroy(&rot_mutex);
+    qemu_mutex_destroy(&pressure_mutex);
+    qemu_mutex_destroy(&uv_mutex);
+    qemu_mutex_destroy(&hrm_mutex);
 
     virtio_cleanup(vdev);
 }
@@ -595,13 +732,13 @@ static void virtio_sensor_unrealize(DeviceState *dev, Error **errp)
 
 static void virtio_sensor_reset(VirtIODevice *vdev)
 {
-    TRACE("virtio_sensor_reset.\n");
+    LOG_TRACE("virtio_sensor_reset.\n");
 }
 
 static uint32_t virtio_sensor_get_features(VirtIODevice *vdev,
                                             uint32_t request_feature)
 {
-    TRACE("virtio_sensor_get_features.\n");
+    LOG_TRACE("virtio_sensor_get_features.\n");
     return 0;
 }
 
index 0c81d0c..11a0786 100644 (file)
@@ -69,17 +69,31 @@ enum sensor_types {
     sensor_type_rotation_vector_delay,
     sensor_type_mag,
     sensor_type_tilt,
+    sensor_type_pressure,
+    sensor_type_pressure_enable,
+    sensor_type_pressure_delay,
+    sensor_type_uv,
+    sensor_type_uv_enable,
+    sensor_type_uv_delay,
+    sensor_type_hrm,
+    sensor_type_hrm_heart,
+    sensor_type_hrm_rri,
+    sensor_type_hrm_enable,
+    sensor_type_hrm_delay,
     sensor_type_max
 };
 
 enum sensor_capabilities {
-    sensor_cap_accel            = 0x01,
-    sensor_cap_geo              = 0x02,
-    sensor_cap_gyro             = 0x04,
-    sensor_cap_light            = 0x08,
-    sensor_cap_proxi            = 0x10,
-    sensor_cap_rotation_vector  = 0x20,
-    sensor_cap_haptic           = 0x40
+    sensor_cap_accel            = 0x0001,
+    sensor_cap_geo              = 0x0002,
+    sensor_cap_gyro             = 0x0004,
+    sensor_cap_light            = 0x0008,
+    sensor_cap_proxi            = 0x0010,
+    sensor_cap_rotation_vector  = 0x0020,
+    sensor_cap_haptic           = 0x0040,
+    sensor_cap_pressure         = 0x0080,
+    sensor_cap_uv               = 0x0100,
+    sensor_cap_hrm              = 0x0200
 };
 
 #define MESSAGE_TYPE_SENSOR "sensor"
@@ -92,16 +106,22 @@ enum sensor_capabilities {
 #define ACTION_LIGHT        113
 #define ACTION_PROXI        114
 #define ACTION_ROTATION     115
+#define ACTION_PRESSURE     116
+#define ACTION_UV           117
+#define ACTION_HRM          118
 
 #define ATTRIBUTE_NAME_SENSORS "sensors"
 
-#define SENSOR_NAME_ACCEL  "accel"
-#define SENSOR_NAME_GYRO   "gyro"
-#define SENSOR_NAME_GEO    "geo"
-#define SENSOR_NAME_LIGHT  "light"
-#define SENSOR_NAME_PROXI  "proxi"
-#define SENSOR_NAME_ROT    "rot"
-#define SENSOR_NAME_HAPTIC "haptic"
+#define SENSOR_NAME_ACCEL       "accel"
+#define SENSOR_NAME_GYRO        "gyro"
+#define SENSOR_NAME_GEO         "geo"
+#define SENSOR_NAME_LIGHT       "light"
+#define SENSOR_NAME_PROXI       "proxi"
+#define SENSOR_NAME_ROT         "rot"
+#define SENSOR_NAME_HAPTIC      "haptic"
+#define SENSOR_NAME_PRESSURE    "press"
+#define SENSOR_NAME_UV          "uv"
+#define SENSOR_NAME_HRM         "hrm"
 
 #define SENSOR_CAP_TOKEN "&"
 
@@ -158,6 +178,34 @@ void req_sensor_data(enum sensor_types type, enum request_cmd req, char* data, i
 #define set_sensor_rotation_vector(data, len)  \
     req_sensor_data(sensor_type_rotation_vector, request_set, data, len);
 
+// Pressure
+#define get_sensor_pressure()  \
+    req_sensor_data(sensor_type_pressure, request_get, NULL, 0);
+
+#define set_sensor_pressure(data, len) \
+    req_sensor_data(sensor_type_pressure, request_set, data, len);
+
+// UV
+#define get_sensor_uv()  \
+    req_sensor_data(sensor_type_uv, request_get, NULL, 0);
+
+#define set_sensor_uv(data, len) \
+    req_sensor_data(sensor_type_uv, request_set, data, len);
+
+// HRM
+#define get_sensor_hrm()  \
+    req_sensor_data(sensor_type_hrm, request_get, NULL, 0);
+
+#define set_sensor_hrm(data, len) \
+    req_sensor_data(sensor_type_hrm, request_set, data, len);
+
+#define set_sensor_hrm_heart(data, len) \
+    req_sensor_data(sensor_type_hrm_heart, request_set, data, len);
+
+#define set_sensor_hrm_rri(data, len) \
+    req_sensor_data(sensor_type_hrm_rri, request_set, data, len);
+
+
 #ifdef __cplusplus
 }
 #endif
index f55fd59..e295077 100644 (file)
@@ -36,6 +36,7 @@
 #include "qemu/event_notifier.h"
 
 #include "emulator.h"
+#include "emul_state.h"
 #include "maru_device_hotplug.h"
 
 #define HOST_KEYBOARD_DRIVER        "virtio-keyboard-pci"
 
 #define FS_MOUNT_TAG                "fileshare"
 
+#include "debug_ch.h"
+
+MULTI_DEBUG_CHANNEL(qemu, hotplug);
+
 struct maru_device_hotplug {
     EventNotifier notifier;
 
@@ -56,7 +61,6 @@ struct maru_device_hotplug {
     // FIXME: Should we query device every time ??
     bool host_keyboard_attached;
     bool sdcard_attached;
-    bool hds_attached;
 };
 
 static struct maru_device_hotplug *state;
@@ -164,6 +168,8 @@ static bool do_hds_attach(const char * const file)
         return false;
     }
 
+    LOG_INFO("do_hds_attach - data: %s\n", file);
+
     qemu_opt_set(fsdev, "fsdriver", "local");
     qemu_opt_set(fsdev, "path", file);
     qemu_opt_set(fsdev, "security_model", "none");
@@ -186,8 +192,6 @@ static bool do_hds_attach(const char * const file)
 
     QDECREF(qdict);
 
-    state->hds_attached = true;
-
     return true;
 }
 
@@ -205,14 +209,16 @@ static bool do_hds_detach(void)
 
     QDECREF(qdict);
 
-    state->hds_attached = false;
+    set_emul_hds_attached(false);
+    set_emul_hds_path(NULL);
+    set_emul_hds_guest_path(NULL);
 
     return true;
 }
 
 void do_hotplug(int command, void *opaque, size_t size)
 {
-    if (command == ATTACH_SDCARD) {
+    if (opaque != NULL && size > 0) {
         state->opaque = g_malloc(size);
         memcpy(state->opaque, opaque, size);
     }
@@ -234,7 +240,6 @@ static void device_hotplug_handler(EventNotifier *e)
         break;
     case ATTACH_SDCARD:
         do_sdcard_attach(state->opaque);
-        g_free(state->opaque);
         break;
     case DETACH_SDCARD:
         do_sdcard_detach();
@@ -248,6 +253,11 @@ static void device_hotplug_handler(EventNotifier *e)
     default:
         break;
     }
+
+    if (state->opaque != NULL) {
+        g_free(state->opaque);
+        state->opaque = NULL;
+    }
 }
 
 static void maru_device_hotplug_deinit(Notifier *notifier, void *data)
@@ -281,6 +291,6 @@ bool is_sdcard_attached(void)
 
 bool is_hds_attached(void)
 {
-    return state->hds_attached;
+    return get_emul_hds_attached();
 }
 
diff --git a/vl.c b/vl.c
index e26460a..a75a16b 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -3584,8 +3584,13 @@ int main(int argc, char **argv, char **envp)
 
                 qemu_opt_set_bool(fsdev, "readonly",
                                 qemu_opt_get_bool(opts, "readonly", 0));
+#ifdef CONFIG_MARU
+                device = qemu_opts_create(qemu_find_opts("device"), "fileshare", 0,
+                                          &error_abort);
+#else
                 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
                                           &error_abort);
+#endif
                 qemu_opt_set(device, "driver", "virtio-9p-pci");
                 qemu_opt_set(device, "fsdev",
                              qemu_opt_get(opts, "mount_tag"));