HDS: added mount/umount for "Host Directory Sharing"
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Mon, 13 Oct 2014 09:09:38 +0000 (18:09 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Mon, 13 Oct 2014 09:09:38 +0000 (18:09 +0900)
Change-Id: I7f1737f0351c9184fd1d91dfcac286e46919dbc0
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
include/emuld.h
include/mobile.h
include/wearable.h
packaging/emuld.spec
src/client.cpp
src/common.cpp
src/common_dev.cpp
src/emuld.cpp
src/mobile.cpp
src/mobile_dev.cpp
src/wearable.cpp

index dc5d49724f67d8d87f5b2bc3e3f2f93d4f16390b..7dffdf4909d4fba58e5921484034bf137130aa10 100644 (file)
@@ -55,6 +55,11 @@ enum
 #define ID_SIZE             10
 #define HEADER_SIZE         4
 
+// Thread TID profile uses >= 5
+#define TID_SDCARD                     1
+#define TID_LOCATION           2
+#define TID_HDS                                3
+
 extern pthread_t tid[MAX_CLIENT + 1];
 extern int g_fd[fdtype_max];
 extern bool exit_flag;
@@ -178,6 +183,7 @@ int parse_val(char *buff, unsigned char data, char *parsbuf);
 
 void msgproc_suspend(int fd, ijcommand* ijcmd);
 void msgproc_system(int fd, ijcommand* ijcmd);
+void msgproc_hds(int fd, ijcommand* ijcmd);
 void msgproc_location(int fd, ijcommand* ijcmd);
 void msgproc_sdcard(int fd, ijcommand* ijcmd);
 
index 534c9a531a4ace7fcd90a1519611babc742eaf29..2348566c4c555c8cf8f8d85970438d806a5e2a62 100644 (file)
@@ -30,6 +30,8 @@
 #ifndef __MOBILE_H__
 #define __MOBILE_H__
 
+#define TID_SENSOR                     5
+
 void msgproc_sensor(const int sockfd, ijcommand* ijcmd);
 
 #endif
index ed386d172475179ea92df3d78da023bd2efe4d7f..9fa2d8f507411e9b8b5a88155d45ab46d2f4ffca 100644 (file)
@@ -30,6 +30,7 @@
 #ifndef __WEARABLE_H__
 #define __WEARABLE_H__
 
+#define TID_PEDOMETER          5
 void msgproc_sensor(const int sockfd, ijcommand* ijcmd);
 
 #endif
index 942fdca5af31412355c98120324ee939312a4f78..1dd9c9abb6d0956f821529ff3d67540fbd4f8db1 100644 (file)
@@ -1,5 +1,5 @@
 Name: emuld
-Version: 0.7.2
+Version: 0.7.3
 Release: 0
 Summary: Emulator daemon
 License: Apache-2.0
index aae9e922c3b4e46700225b3a97db0394cb5f03b2..89698944830d12081d72fd1b2e3ab37b18910b64 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <arpa/inet.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include "emuld.h"
 
index 09a84660bf370ecb110da46fe93afbcac73751cd..5b186e834ea86db9e0eaac8c6f1ddd3da2cf6eb9 100644 (file)
@@ -32,7 +32,6 @@
 #include <unistd.h>
 
 #include "emuld.h"
-
 #include "deviced/dd-display.h"
 
 #define PMAPI_RETRY_COUNT   3
@@ -162,7 +161,6 @@ void send_default_suspend_req(void)
 
     ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SUSPEND, (const char*) tmp, tmplen);
 
-
     if (tmp)
         free(tmp);
     if (packet)
index c507eab6da2bb79a9df7debaf6f56b8317c4fa64..a85eabb5189accfc30cf5ece4ee9c5f04f11c7e3 100644 (file)
  *
  */
 
+#include <sys/mount.h>
+#include <errno.h>
+#include <unistd.h>
+
 // SD Card
 #include <dirent.h>
 #include <sys/stat.h>
-#include <sys/mount.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <mntent.h>
@@ -46,6 +49,9 @@
 // SDCard
 #define IJTYPE_SDCARD       "sdcard"
 
+// HDS
+#define IJTYPE_HDS          "hds"
+
 char SDpath[256];
 
 // Location
@@ -218,7 +224,7 @@ int umount_sdcard(const int fd)
 
     LOGINFO("start sdcard umount");
 
-    pthread_cancel(tid[1]);
+    pthread_cancel(tid[TID_SDCARD]);
 
     for (i = 0; i < 10; i++)
     {
@@ -226,23 +232,23 @@ int umount_sdcard(const int fd)
         ret = access(file_name, F_OK);
         if (ret == 0)
         {
-                       LOGDEBUG("SDpath is %s", SDpath);
+            LOGDEBUG("SDpath is %s", SDpath);
 
-                       packet->length = strlen(SDpath);        // length
-                       packet->group = 11;                     // sdcard
-                       packet->action = 0;                     // unmounted
+            packet->length = strlen(SDpath);        // length
+            packet->group = 11;                     // sdcard
+            packet->action = 0;                     // unmounted
 
-                       const int tmplen = HEADER_SIZE + packet->length;
-                       char* tmp = (char*) malloc(tmplen);
-                       if (!tmp)
-                               break;
+            const int tmplen = HEADER_SIZE + packet->length;
+            char* tmp = (char*) malloc(tmplen);
+            if (!tmp)
+                break;
 
-                       memcpy(tmp, packet, HEADER_SIZE);
-                       memcpy(tmp + HEADER_SIZE, SDpath, packet->length);
+            memcpy(tmp, packet, HEADER_SIZE);
+            memcpy(tmp + HEADER_SIZE, SDpath, packet->length);
 
-                       ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
+            ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
 
-                       free(tmp);
+            free(tmp);
 
             memset(SDpath, '\0', sizeof(SDpath));
             sprintf(SDpath, "umounted");
@@ -299,7 +305,7 @@ void msgproc_sdcard(const int sockfd, ijcommand* ijcmd)
                 if (!param)
                     break;
 
-                if (pthread_create(&tid[1], NULL, mount_sdcard, (void*) param) != 0)
+                if (pthread_create(&tid[TID_SDCARD], NULL, mount_sdcard, (void*) param) != 0)
                     LOGERR("mount sdcard pthread create fail!");
             }
 
@@ -467,7 +473,7 @@ static char* get_location_status(void* p)
     return message;
 }
 
-static void* setting_device(void* data)
+static void* getting_location(void* data)
 {
     pthread_detach(pthread_self());
 
@@ -492,30 +498,30 @@ static void* setting_device(void* data)
         break;
     }
 
-       if (msg == 0)
-       {
-               LOGDEBUG("send error message to injector");
-               memset(packet, 0, sizeof(LXT_MESSAGE));
-               packet->length = 0;
-               packet->group = STATUS;
-               packet->action = param->ActionID;
-       }
-       else
-       {
-               LOGDEBUG("send data to injector");
-       }
-
-       const int tmplen = HEADER_SIZE + packet->length;
-       char* tmp = (char*) malloc(tmplen);
-       if (tmp)
-       {
-               memcpy(tmp, packet, HEADER_SIZE);
-               if (packet->length > 0)
-                       memcpy(tmp + HEADER_SIZE, msg, packet->length);
-
-               ijmsg_send_to_evdi(g_fd[fdtype_device], param->type_cmd, (const char*) tmp, tmplen);
-
-               free(tmp);
+    if (msg == 0)
+    {
+        LOGDEBUG("send error message to injector");
+        memset(packet, 0, sizeof(LXT_MESSAGE));
+        packet->length = 0;
+        packet->group = STATUS;
+        packet->action = param->ActionID;
+    }
+    else
+    {
+        LOGDEBUG("send data to injector");
+    }
+
+    const int tmplen = HEADER_SIZE + packet->length;
+    char* tmp = (char*) malloc(tmplen);
+    if (tmp)
+    {
+        memcpy(tmp, packet, HEADER_SIZE);
+        if (packet->length > 0)
+            memcpy(tmp + HEADER_SIZE, msg, packet->length);
+
+        ijmsg_send_to_evdi(g_fd[fdtype_device], param->type_cmd, (const char*) tmp, tmplen);
+
+        free(tmp);
     }
 
     if(msg != 0)
@@ -604,7 +610,7 @@ void msgproc_location(const int sockfd, ijcommand* ijcmd)
         param->ActionID = ijcmd->msg.action;
         memcpy(param->type_cmd, ijcmd->cmd, ID_SIZE);
 
-        if (pthread_create(&tid[2], NULL, setting_device, (void*) param) != 0)
+        if (pthread_create(&tid[TID_LOCATION], NULL, getting_location, (void*) param) != 0)
         {
             LOGERR("location pthread create fail!");
             return;
@@ -616,5 +622,113 @@ void msgproc_location(const int sockfd, ijcommand* ijcmd)
     }
 }
 
+static char* make_header_msg(int group, int action)
+{
+    char *tmp = (char*) malloc(HEADER_SIZE);
+    if (!tmp)
+        return NULL;
+
+    memset(tmp, 0, HEADER_SIZE);
+
+    memcpy(tmp + 2, &group, 1);
+    memcpy(tmp + 3, &action, 1);
+
+    return tmp;
+}
+
+#define MSG_GROUP_HDS   100
+
+void* mount_hds(void* data)
+{
+    int i, ret = 0;
+    char* tmp;
+    int group, action;
+
+    LOGINFO("start hds mount thread");
+
+    pthread_detach(pthread_self());
+
+    usleep(1000);
+
+    for (i = 0; i < 10; i++)
+    {
+        ret = mount("fileshare", "/mnt/host", "9p", 0,
+                    "trans=virtio,version=9p2000.L,msize=65536");
+        if(ret == 0) {
+            action = 1;
+            break;
+        } else {
+            LOGERR("%d trial: mount is failed with errno: %d", i, errno);
+        }
+        usleep(100);
+    }
+
+    group = MSG_GROUP_HDS;
+
+    if (i == 10 || ret != 0)
+        action = 2;
+
+    tmp = make_header_msg(group, action);
+    if (!tmp) {
+        LOGERR("failed to alloc: out of resource.");
+        pthread_exit((void *) 0);
+        return NULL;
+    }
+
+    ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_HDS, (const char*) tmp, HEADER_SIZE);
+
+    free(tmp);
+
+    pthread_exit((void *) 0);
+}
+
+int umount_hds(void)
+{
+    int ret = 0;
+    char* tmp;
+    int group, action;
+
+    pthread_cancel(tid[TID_HDS]);
+
+    LOGINFO("unmount /mnt/host.");
+
+    ret = umount("/mnt/host");
+    if (ret != 0) {
+        LOGERR("unmount failed with error num: %d", errno);
+        action = 4;
+    } else {
+        action = 3;
+    }
+
+    group = MSG_GROUP_HDS;
+
+    tmp = make_header_msg(group, action);
+    if (!tmp) {
+        LOGERR("failed to alloc: out of resource.");
+        return -1;
+    }
+
+    LOGINFO("send result with action %d to evdi", action);
+
+    ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_HDS, (const char*) tmp, HEADER_SIZE);
+
+    free(tmp);
+
+    return 0;
+}
+
+void msgproc_hds(const int sockfd, ijcommand* ijcmd)
+{
+    LOGDEBUG("msgproc_hds");
+
+    if (ijcmd->msg.action == 1) {
+        if (pthread_create(&tid[TID_HDS], NULL, mount_hds, NULL) != 0)
+            LOGERR("mount hds pthread create fail!");
+    } else if (ijcmd->msg.action == 2) {
+        umount_hds();
+    } else {
+        LOGERR("unknown action cmd.");
+    }
+}
 
 
index 4fc79deaaf832913410c65e3767b14cc27bed7ae..bb8ce4195efdb609bb1c7edf5b465dd25a1311eb 100644 (file)
@@ -217,7 +217,7 @@ void recv_from_evdi(evdi_fd fd)
         }
     }
 
-    LOGDEBUG("total readed  = %d, read count = %d, index = %d, use = %d, msg = %s",
+    LOGINFO("total readed  = %d, read count = %d, index = %d, use = %d, msg = %s",
             readed, _msg.count, _msg.index, _msg.use, _msg.buf);
 
     g_synbuf.reset_buf();
index 197b7c90434c2e3a47355a978838d387e8b23daf..842f4267090dc7eabff7480b2943e39319fefa18 100644 (file)
@@ -52,6 +52,10 @@ void process_evdi_command(ijcommand* ijcmd)
     {
         msgproc_location(fd, ijcmd);
     }
+    else if (strncmp(ijcmd->cmd, "hds", 3) == 0)
+    {
+        msgproc_hds(fd, ijcmd);
+    }
     else if (strncmp(ijcmd->cmd, "system", 6) == 0)
     {
         msgproc_system(fd, ijcmd);
index 13f62f4ba14cf5a9c12b9175718ab5084946b5de..5d958648adc67752a7fb067adda0956a67a50a08 100644 (file)
@@ -37,8 +37,6 @@
 #define STATUS              15
 #define RSSI_LEVEL          104
 
-static int battery_level = 50;
-
 enum sensor_type{
     MOTION = 6,
     USBKEYBOARD = 7,
@@ -78,6 +76,87 @@ enum motion_move{
     SENSOR_MOTION_MOVE_MOVETOCALL = 1
 };
 
+static void system_cmd(const char* msg)
+{
+    int ret = system(msg);
+    if (ret == -1) {
+        LOGERR("system command is failed: %s", msg);
+    }
+}
+
+#define DBUS_SEND_CMD   "dbus-send --system --type=method_call --print-reply --reply-timeout=120000 --dest=org.tizen.system.deviced /Org/Tizen/System/DeviceD/SysNoti org.tizen.system.deviced.SysNoti."
+static void dbus_send(const char* device, const char* option)
+{
+    const char* dbus_send_cmd = DBUS_SEND_CMD;
+    char* cmd;
+
+    if (device == NULL || option == NULL)
+        return;
+
+    cmd = (char*)malloc(512);
+    if (cmd == NULL)
+        return;
+
+    memset(cmd, 0, 512);
+
+    sprintf(cmd, "%s%s string:\"%s\" %s", dbus_send_cmd, device, device, option);
+
+    system_cmd(cmd);
+    LOGINFO("dbus_send: %s", cmd);
+
+    free(cmd);
+}
+
+#define POWER_SUPPLY    "power_supply"
+#define FULL            "Full"
+#define CHARGING        "Charging"
+#define DISCHARGING     "Discharging"
+static void dbus_send_power_supply(int capacity, int charger)
+{
+    const char* power_device = POWER_SUPPLY;
+    char state [16];
+    char option [128];
+    memset(state, 0, 16);
+    memset(option, 0, 128);
+
+    if (capacity == 100 && charger == 1) {
+               memcpy(state, FULL, 4);
+    } else if (charger == 1) {
+               memcpy(state, CHARGING, 8);
+    } else {
+               memcpy(state, DISCHARGING, 11);
+    }
+
+    sprintf(option, "int32:5 string:\"%d\" string:\"%s\" string:\"Good\" string:\"%d\" string:\"1\"",
+            capacity, state, (charger + 1));
+
+    dbus_send(power_device, option);
+}
+
+#define DEVICE_CHANGED      "device_changed"
+
+static void dbus_send_usb(int on)
+{
+    const char* usb_device = DEVICE_CHANGED;
+    char option [128];
+    memset(option, 0, 128);
+
+    sprintf(option, "int32:2 string:\"usb\" string:\"%d\"", on);
+
+    dbus_send(usb_device, option);
+}
+
+static void dbus_send_earjack(int on)
+{
+       const char* earjack_device = DEVICE_CHANGED;
+    char option [128];
+    memset(option, 0, 128);
+
+    sprintf(option, "int32:2 string:\"earjack\" string:\"%d\"", on);
+
+    dbus_send(earjack_device, option);
+}
+
 int parse_motion_data(int len, char *buffer)
 {
     int len1=0;
@@ -164,168 +243,75 @@ int parse_motion_data(int len, char *buffer)
     return 0;
 }
 
-#define PATH_BATTERY_CAPACITY       "sys/class/power_supply/battery/capacity"
-#define PATH_BATTERY_CHARGER_ON     "/sys/devices/platform/jack/charger_online"
-#define PATH_BATTERY_CHARGE_FULL    "/sys/class/power_supply/battery/charge_full"
-#define PATH_BATTERY_CHARGE_NOW     "/sys/class/power_supply/battery/charge_now"
+#define FILE_BATTERY_CAPACITY "/sys/class/power_supply/battery/capacity"
+#define FILE_BATTERY_CHARGER_ONLINE "/sys/devices/platform/jack/charger_online"
+#define FILE_BATTERY_CHARGE_FULL "/sys/class/power_supply/battery/charge_full"
+#define FILE_BATTERY_CHARGE_NOW "/sys/class/power_supply/battery/charge_now"
 
-int parse_batterylevel_data(int len, char *buffer)
+static int read_from_file(const char* file_name)
 {
-    int len1=0, id = 0, ret = 0;
-    char tmpbuf[255];
-    int level = 0, charger = 0, charger_online = 0, charge_full = 0;
+    int ret;
     FILE* fd;
+    int value;
 
-    LOGDEBUG("read data: %s", buffer);
-
-    // read param count
-    memset(tmpbuf, '\0', sizeof(tmpbuf));
-    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
-    len += len1;
-
-    /* first data */
-    memset(tmpbuf, '\0', sizeof(tmpbuf));
-    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
-    len += len1;
-
-    id = atoi(tmpbuf);
-    if(id == 1) // level
+    fd = fopen(file_name, "r");
+    if(!fd)
     {
-        memset(tmpbuf, '\0', sizeof(tmpbuf));
-        len1 = parse_val(buffer+len, 0x0a, tmpbuf);
-        len += len1;
-
-        level = atoi(tmpbuf);
-        battery_level = level;
-
-        if(level == 100)
-        {
-            charger = 0;
-        }
-        else
-        {
-            charger = 1;
-        }
-
-        fd = fopen(PATH_BATTERY_CAPACITY, "w");
-        if(!fd)
-        {
-            LOGERR("fopen fail");
-            return -1;
-        }
-        fprintf(fd, "%d", level);
-        fclose(fd);
-
-        fd = fopen(PATH_BATTERY_CHARGER_ON, "r");
-        if(!fd)
-        {
-            LOGERR("fopen fail");
-            return -1;
-        }
-        ret = fscanf(fd, "%d", &charger_online);
-        fclose(fd);
-        if (ret < 0)
-        {
-            LOGERR("failed to get charger_online value");
-            return -1;
-        }
-
-        LOGDEBUG("charge_online: %d", charger_online);
+        LOGERR("fopen fail: %s", file_name);
+        return -1;
+    }
 
-        if(charger_online == 1 && level == 100)
-        {
-            charge_full = 1;
-        }
-        else
-        {
-            charge_full = 0;
-        }
-        LOGDEBUG("charge_full: %d", charge_full);
+    ret = fscanf(fd, "%d", &value);
+    fclose(fd);
+    if (ret <= 0) {
+        LOGERR("failed to get value");
+        return -1;
+    }
 
-        fd = fopen(PATH_BATTERY_CHARGE_FULL, "w");
-        if(!fd)
-        {
-            LOGERR("charge_full fopen fail");
-            return -1;
-        }
-        fprintf(fd, "%d", charge_full);
-        fclose(fd);
+    return value;
+}
 
-        if(charger_online == 1)
-        {
-            fd = fopen(PATH_BATTERY_CHARGE_NOW, "w");
-            if(!fd)
-            {
-                LOGERR("charge_now fopen fail");
-                return -1;
-            }
-            fprintf(fd, "%d", charger);
-            fclose(fd);
-        }
+static void write_to_file(const char* file_name, int value)
+{
+    FILE* fd;
 
-        // because time based polling
-        systemcall("/usr/bin/sys_event device_charge_chgdet");
-    }
-    else if(id == 2)
+    fd = fopen(file_name, "w");
+    if(!fd)
     {
-        /* second data */
-        memset(tmpbuf, '\0', sizeof(tmpbuf));
-        len1 = parse_val(buffer+len, 0x0a, tmpbuf);
-        len += len1;
-
-        charger = atoi(tmpbuf);
-        fd = fopen(PATH_BATTERY_CHARGER_ON, "w");
-        if(!fd)
-        {
-            LOGERR("charger_online fopen fail");
-            return -1;
-        }
-        fprintf(fd, "%d", charger);
-        fclose(fd);
-
-        fd = fopen(PATH_BATTERY_CHARGE_FULL, "w");
-        if(!fd)
-        {
-            LOGERR("charge_full fopen fail");
-            return -1;
-        }
+        LOGERR("fopen fail: %s", file_name);
+        return;
+    }
+    fprintf(fd, "%d", value);
+    fclose(fd);
+}
 
-        if(battery_level == 100 && charger == 1)
-        {
-            fprintf(fd, "%d", 1);   // charge full
-            charger = 0;
-        }
-        else
-        {
-            fprintf(fd, "%d", 0);
-        }
-        fclose(fd);
+int set_battery_data(void)
+{
+    int charger_online = 0;
+    int battery_level = 0;
 
-        systemcall("/usr/bin/sys_event device_charge_chgdet");
+    battery_level = read_from_file(FILE_BATTERY_CAPACITY);
+    LOGINFO("battery level: %d", battery_level);
+    if (battery_level < 0)
+        return -1;
 
-        fd = fopen(PATH_BATTERY_CHARGE_NOW, "w");
-        if(!fd)
-        {
-            LOGERR("charge_now fopen fail");
-            return -1;
-        }
-        fprintf(fd, "%d", charger);
-        fclose(fd);
+    charger_online = read_from_file(FILE_BATTERY_CHARGER_ONLINE);
+    LOGINFO("charge_online: %d", charger_online);
+    if (charger_online < 0)
+        return -1;
 
-        // because time based polling
-        systemcall("/usr/bin/sys_event device_ta_chgdet");
-    }
+    dbus_send_power_supply(battery_level, charger_online);
 
     return 0;
 }
 
-int parse_rssi_data(int len, char *buffer)
+#define PATH_JACK_EARJACK           "/sys/devices/platform/jack/earjack_online"
+int parse_earjack_data(int len, char *buffer)
 {
     int len1=0;
     char tmpbuf[255];
     int x;
-    char command[128];
-    memset(command, '\0', sizeof(command));
+    FILE* fd;
 
     LOGDEBUG("read data: %s", buffer);
 
@@ -341,22 +327,32 @@ int parse_rssi_data(int len, char *buffer)
 
     x = atoi(tmpbuf);
 
-    sprintf(command, "vconftool set -t int memory/telephony/rssi %d -i -f", x);
-    systemcall(command);
+    fd = fopen(PATH_JACK_EARJACK, "w");
+    if(!fd)
+    {
+        LOGERR("earjack_online fopen fail");
+        return -1;
+    }
+    fprintf(fd, "%d", x);
+    fclose(fd);
 
+    // because time based polling
+       //FIXME: change to dbus
+    //system_cmd("/usr/bin/sys_event device_earjack_chgdet");
+       dbus_send_earjack(x);
     return 0;
 }
 
-#define PATH_JACK_EARJACK           "/sys/devices/platform/jack/earjack_online"
-int parse_earjack_data(int len, char *buffer)
+#define FILE_USB_ONLINE "/sys/devices/platform/jack/usb_online"
+int parse_usb_data(int len, char *buffer)
 {
     int len1=0;
     char tmpbuf[255];
     int x;
-    FILE* fd;
-
-    LOGDEBUG("read data: %s", buffer);
 
+    #ifdef SENSOR_DEBUG
+    LOG("read data: %s", buffer);
+    #endif
     // read param count
     memset(tmpbuf, '\0', sizeof(tmpbuf));
     len1 = parse_val(buffer+len, 0x0a, tmpbuf);
@@ -369,30 +365,24 @@ int parse_earjack_data(int len, char *buffer)
 
     x = atoi(tmpbuf);
 
-    fd = fopen(PATH_JACK_EARJACK, "w");
-    if(!fd)
-    {
-        LOGERR("earjack_online fopen fail");
-        return -1;
-    }
-    fprintf(fd, "%d", x);
-    fclose(fd);
+    write_to_file(FILE_USB_ONLINE, x);
 
     // because time based polling
-    systemcall("/usr/bin/sys_event device_earjack_chgdet");
+    dbus_send_usb(x);
 
     return 0;
 }
 
-#define PATH_JACK_USB               "/sys/devices/platform/jack/usb_online"
-int parse_usb_data(int len, char *buffer)
+
+int parse_rssi_data(int len, char *buffer)
 {
     int len1=0;
     char tmpbuf[255];
     int x;
-    FILE* fd;
+    char command[128];
+    memset(command, '\0', sizeof(command));
 
-    LOGDEBUG("read data: %s", buffer);
+    LOGINFO("read data: %s", buffer);
 
     // read param count
     memset(tmpbuf, '\0', sizeof(tmpbuf));
@@ -406,21 +396,13 @@ int parse_usb_data(int len, char *buffer)
 
     x = atoi(tmpbuf);
 
-    fd = fopen(PATH_JACK_USB, "w");
-    if(!fd)
-    {
-        LOGERR("usb_online fopen fail");
-        return -1;
-    }
-    fprintf(fd, "%d", x);
-    fclose(fd);
+    sprintf(command, "vconftool set -t int memory/telephony/rssi %d -i -f", x);
+    systemcall(command);
 
-    // because time based polling
-    systemcall("/usr/bin/sys_event device_usb_chgdet");
     return 0;
 }
 
-void device_parser(char *buffer)
+void setting_sensor(char *buffer)
 {
     int len = 0;
     int ret = 0;
@@ -440,15 +422,10 @@ void device_parser(char *buffer)
             LOGERR("motion parse error!");
         break;
     case BATTERYLEVEL:
-        ret = parse_batterylevel_data(len, buffer);
+        ret = set_battery_data();
         if(ret < 0)
             LOGERR("batterylevel parse error!");
         break;
-    case RSSI:
-        ret = parse_rssi_data(len, buffer);
-        if(ret < 0)
-            LOGERR("rssi parse error!");
-        break;
     case EARJACK:
         ret = parse_earjack_data(len, buffer);
         if(ret < 0)
@@ -459,28 +436,16 @@ void device_parser(char *buffer)
         if(ret < 0)
             LOGERR("usb parse error!");
         break;
+    case RSSI:
+        ret = parse_rssi_data(len, buffer);
+        if(ret < 0)
+            LOGERR("rssi parse error!");
+        break;
     default:
         break;
     }
 }
 
-static int inline get_status(const char* filename)
-{
-    int ret;
-    int status = 0;
-    FILE* fd = fopen(filename, "r");
-    if(!fd)
-        return -1;
-
-    ret = fscanf(fd, "%d", &status);
-    fclose(fd);
-
-    if (ret < 0) {
-        return ret;
-    }
-
-    return status;
-}
 
 static int inline get_vconf_status(char* msg, const char* key, int buf_len)
 {
@@ -519,7 +484,7 @@ char* get_rssi_level(void* p)
     return message;
 }
 
-static void* setting_device(void* data)
+static void* getting_sensor(void* data)
 {
     pthread_detach(pthread_self());
 
@@ -603,7 +568,7 @@ void msgproc_sensor(const int sockfd, ijcommand* ijcmd)
         param->ActionID = ijcmd->msg.action;
         memcpy(param->type_cmd, ijcmd->cmd, ID_SIZE);
 
-        if (pthread_create(&tid[2], NULL, setting_device, (void*)param) != 0)
+        if (pthread_create(&tid[TID_SENSOR], NULL, getting_sensor, (void*)param) != 0)
         {
             LOGERR("sensor pthread create fail!");
             return;
@@ -613,7 +578,7 @@ void msgproc_sensor(const int sockfd, ijcommand* ijcmd)
     else
     {
         if (ijcmd->data != NULL && strlen(ijcmd->data) > 0) {
-            device_parser(ijcmd->data);
+            getting_sensor(ijcmd->data);
         }
     }
 }
index 0a3e25e76d690b62c95716f10f6fdd026854e915..d358f08966c906538efad6e49b4f2d36692e602b 100644 (file)
@@ -140,7 +140,7 @@ void recv_from_pedometer(int fd)
 
         close(fd);
 
-        if (pthread_create(&tid[3], NULL, init_pedometer_connect, NULL) != 0)
+        if (pthread_create(&tid[TID_PEDOMETER], NULL, init_pedometer_connect, NULL) != 0)
         {
             LOGERR("pthread create fail!");
         }
@@ -185,6 +185,10 @@ void process_evdi_command(ijcommand* ijcmd)
     {
         msgproc_location(fd, ijcmd);
     }
+    else if (strncmp(ijcmd->cmd, "hds", 3) == 0)
+    {
+        msgproc_hds(fd, ijcmd);
+    }
     else if (strncmp(ijcmd->cmd, "system", 6) == 0)
     {
         msgproc_system(fd, ijcmd);
@@ -234,7 +238,7 @@ bool server_process(void)
 
 void init_profile(void)
 {
-    if(pthread_create(&tid[3], NULL, init_pedometer_connect, NULL) != 0)
+    if(pthread_create(&tid[TID_PEDOMETER], NULL, init_pedometer_connect, NULL) != 0)
     {
         LOGERR("pthread create fail!");
         close(g_epoll_fd);
@@ -248,7 +252,7 @@ void exit_profile(void)
     if (!is_pedometer_connected())
     {
         int status;
-        pthread_join(tid[3], (void **)&status);
+        pthread_join(tid[TID_PEDOMETER], (void **)&status);
         LOGINFO("pedometer thread end %d\n", status);
        }