pkg: added extra package installation
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Tue, 6 Jan 2015 08:02:59 +0000 (17:02 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Tue, 6 Jan 2015 08:02:59 +0000 (17:02 +0900)
Change-Id: I2f1dbdc8ce12db427b0d25013c789b6986251e32
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
16 files changed:
CMakeLists.txt
emuld.manifest [new file with mode: 0644]
include/emuld.h
include/mobile.h
include/wearable.h
packaging/emuld.spec
packaging/emuld_mobile.manifest [deleted file]
packaging/emuld_wearable.manifest [deleted file]
src/common.cpp
src/common_dev.cpp
src/emuld.cpp
src/evdi.cpp
src/mobile.cpp
src/mobile_dev.cpp
src/wearable.cpp
src/wearable_dev.cpp

index cf4e9f2ab203f8411e1a07afcbe53697947cc6ef..8a8a3e8c42676faaf140bb3bdd7fcc737687d962 100644 (file)
@@ -55,12 +55,6 @@ SET(PKG_MODULE
 
 pkg_check_modules(PKGS REQUIRED ${PKG_MODULE})
 
-IF(USE_D_MOBILE)
-    ADD_DEFINITIONS("-DMOBILE")
-ELSEIF(USE_D_WEARABLE)
-    ADD_DEFINITIONS("-DWEARABLE")
-ENDIF()
-
 ADD_DEFINITIONS("-DENABLE_DLOG_OUT")
 ADD_DEFINITIONS(-Wall -O3 -omit-frame-pointer)
 
diff --git a/emuld.manifest b/emuld.manifest
new file mode 100644 (file)
index 0000000..e325658
--- /dev/null
@@ -0,0 +1,11 @@
+<manifest>
+       <define>
+               <domain name="emuld"/>
+               <request>
+                       <smack request="deviced::display" type="rw" />
+               </request>
+       </define>
+       <request>
+               <domain name="emuld" />
+       </request>
+</manifest>
index 7dffdf4909d4fba58e5921484034bf137130aa10..8065dddce081f37aadb7b1d82c9835ce2ce71647 100644 (file)
@@ -32,6 +32,7 @@
 #define __EMULD_H__
 
 #include <stdlib.h>
+#include <string.h>
 #include <pthread.h>
 #include <sys/epoll.h>
 
@@ -66,16 +67,18 @@ extern bool exit_flag;
 extern int g_epoll_fd;
 extern struct epoll_event g_events[MAX_EVENTS];
 
+void writelog(const char* fmt, ...);
+
 #if defined(ENABLE_DLOG_OUT)
-#  define LOG_TAG           "EMULATOR_DAEMON"
+#  define LOG_TAG           "EMULD"
 #  include <dlog/dlog.h>
 #  define LOGINFO LOGI
 #  define LOGERR LOGE
 #  define LOGDEBUG LOGD
 #else
-#  define LOGINFO(fmt, arg...) printf(fmt, arg...)
-#  define LOGERR(fmt, arg...) printf(fmt, arg...)
-#  define LOGDEBUG(fmt, arg...) printf(fmt, arg...)
+#  define LOGINFO(fmt, ...) { writelog(fmt, ##__VA_ARGS__); }
+#  define LOGERR LOGINFO
+#  define LOGDEBUG LOGINFO
 #endif
 
 typedef unsigned short  CliSN;
@@ -163,11 +166,10 @@ struct _auto_mutex
 
 struct setting_device_param
 {
-    setting_device_param() : get_status_sockfd(-1), ActionID(0)
+    setting_device_param() : ActionID(0)
     {
         memset(type_cmd, 0, ID_SIZE);
     }
-    int get_status_sockfd;
     unsigned char ActionID;
     char type_cmd[ID_SIZE];
 };
@@ -177,15 +179,24 @@ int recv_data(int event_fd, char** r_databuf, int size);
 void recv_from_evdi(evdi_fd fd);
 bool accept_proc(const int server_fd);
 
+void send_to_ecs(const char* cat, int group, int action, char* data);
+void send_emuld_connection(void);
 void send_default_suspend_req(void);
 void systemcall(const char* param);
 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);
+#define IJTYPE_SUSPEND      "suspend"
+#define IJTYPE_GUEST        "guest"
+#define IJTYPE_PACKAGE      "package"
+
+void msgproc_suspend(ijcommand* ijcmd);
+void msgproc_system(ijcommand* ijcmd);
+void msgproc_package(ijcommand* ijcmd);
+void msgproc_hds(ijcommand* ijcmd);
+void msgproc_location(ijcommand* ijcmd);
+void msgproc_sdcard(ijcommand* ijcmd);
+void* exec_cmd_thread(void *args);
+void msgproc_cmd(ijcommand* ijcmd);
 
 /*
  * For the multi-profile
index 2348566c4c555c8cf8f8d85970438d806a5e2a62..b6aaace780ebc2e880e3623d4c7993540fa6e25d 100644 (file)
@@ -32,6 +32,6 @@
 
 #define TID_SENSOR                     5
 
-void msgproc_sensor(const int sockfd, ijcommand* ijcmd);
+void msgproc_sensor(ijcommand* ijcmd);
 
 #endif
index ed386d172475179ea92df3d78da023bd2efe4d7f..86164cdd3c6ba937575cda4520dd68bba8c0c482 100644 (file)
@@ -30,6 +30,7 @@
 #ifndef __WEARABLE_H__
 #define __WEARABLE_H__
 
-void msgproc_sensor(const int sockfd, ijcommand* ijcmd);
+#define TID_PEDOMETER          5
+void msgproc_sensor(ijcommand* ijcmd);
 
 #endif
index 34604a3a8c54de2d562f9c67aae2e942427d765f..94cd815d5b714311dde3c064581e8e30760a2cf9 100644 (file)
@@ -1,11 +1,10 @@
 Name: emuld
-Version: 0.7.5
+Version: 0.8.4
 Release: 0
 Summary: Emulator daemon
 License: Apache-2.0
 Source0: %{name}-%{version}.tar.gz
 Group: SDK/Other
-Source1001: packaging/emuld_wearable.manifest
 
 BuildRequires: cmake
 BuildRequires: pkgconfig(vconf)
@@ -54,7 +53,7 @@ chmod 770 %{_prefix}/bin/emuld
 
 %files
 %defattr(-,root,root,-)
-%manifest packaging/emuld_wearable.manifest
+%manifest emuld.manifest
 %{_prefix}/bin/emuld
 /usr/share/license/%{name}
 /usr/lib/systemd/system/emuld.service
diff --git a/packaging/emuld_mobile.manifest b/packaging/emuld_mobile.manifest
deleted file mode 100644 (file)
index e325658..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<manifest>
-       <define>
-               <domain name="emuld"/>
-               <request>
-                       <smack request="deviced::display" type="rw" />
-               </request>
-       </define>
-       <request>
-               <domain name="emuld" />
-       </request>
-</manifest>
diff --git a/packaging/emuld_wearable.manifest b/packaging/emuld_wearable.manifest
deleted file mode 100644 (file)
index e325658..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<manifest>
-       <define>
-               <domain name="emuld"/>
-               <request>
-                       <smack request="deviced::display" type="rw" />
-               </request>
-       </define>
-       <request>
-               <domain name="emuld" />
-       </request>
-</manifest>
index 5b186e834ea86db9e0eaac8c6f1ddd3da2cf6eb9..23c56ec2283bf434030f91d6bed094642bff9994 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <sys/time.h>
 #include <sys/reboot.h>
+#include <stdio.h>
 #include <unistd.h>
 
 #include "emuld.h"
 #define PMAPI_RETRY_COUNT   3
 #define POWEROFF_DURATION   2
 
-#define IJTYPE_SUSPEND      "suspend"
-
 #define SUSPEND_UNLOCK      0
 #define SUSPEND_LOCK        1
 
+#define MAX_PKGS_BUF        1024
+
+#define PATH_PACKAGE_INSTALL   "/opt/usr/apps/tmp/sdk_tools/"
+#define RPM_CMD_QUERY          "-q"
+#define RPM_CMD_INSTALL                "-U"
+static pthread_mutex_t mutex_pkg = PTHREAD_MUTEX_INITIALIZER;
+
 static struct timeval tv_start_poweroff;
 
 void systemcall(const char* param)
@@ -95,7 +101,7 @@ void powerdown_by_force(void)
     reboot(RB_POWER_OFF);
 }
 
-void msgproc_system(const int sockfd, ijcommand* ijcmd)
+void msgproc_system(ijcommand* ijcmd)
 {
     LOGDEBUG("msgproc_system");
 
@@ -129,7 +135,7 @@ static void set_lock_state(int state) {
     }
 }
 
-void msgproc_suspend(int fd, ijcommand* ijcmd)
+void msgproc_suspend(ijcommand* ijcmd)
 {
     if (ijcmd->msg.action == SUSPEND_LOCK) {
         set_lock_state(SUSPEND_LOCK);
@@ -140,31 +146,229 @@ void msgproc_suspend(int fd, ijcommand* ijcmd)
     LOGINFO("[Suspend] Set lock state as %d (1: lock, other: unlock)", ijcmd->msg.action);
 }
 
-void send_default_suspend_req(void)
+void send_to_ecs(const char* cat, int group, int action, char* data)
 {
-    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 datalen = 0;
     int tmplen = HEADER_SIZE;
+       if (data != NULL) {
+               datalen = strlen(data);
+               tmplen += datalen;
+       }
+
     char* tmp = (char*) malloc(tmplen);
     if (!tmp)
         return;
 
-    memcpy(tmp, packet, HEADER_SIZE);
+       if (data != NULL) {
+               memcpy(tmp, &datalen, 2);
+       }
+       memcpy(tmp + 2, &group, 1);
+       memcpy(tmp + 3, &action, 1);
+       if (data != NULL) {
+               memcpy(tmp + 4, data, datalen);
+       }
+
+    ijmsg_send_to_evdi(g_fd[fdtype_device], cat, (const char*) tmp, tmplen);
+
+       if (tmp)
+               free(tmp);
+}
+
+void send_emuld_connection(void)
+{
+       send_to_ecs(IJTYPE_GUEST, 0, 1, NULL);
+}
+
+void send_default_suspend_req(void)
+{
+       send_to_ecs(IJTYPE_SUSPEND, 5, 15, NULL);
+}
+
+static bool do_validate(char* pkgs)
+{
+       char buf[MAX_PKGS_BUF];
+
+       FILE* fp = popen(pkgs, "r");
+       if (fp == NULL) {
+               LOGERR("Failed to popen %s", pkgs);
+               return false;
+       }
+
+       memset(buf, 0, sizeof(buf));
+       while(fgets(buf, sizeof(buf), fp)) {
+               LOGINFO("[rpm]%s", buf);
+               if (!strncmp(buf, IJTYPE_PACKAGE, 7)) {
+                       pclose(fp);
+                       return false;
+               }
+           memset(buf, 0, sizeof(buf));
+       }
+
+       pclose(fp);
+       return true;
+}
+
+static bool do_install(char* pkgs)
+{
+       char buf[MAX_PKGS_BUF];
+       bool ret = true;
+
+       FILE* fp = popen(pkgs, "r");
+       if (fp == NULL) {
+               LOGERR("Failed to popen %s", pkgs);
+               return false;
+       }
+
+       memset(buf, 0, sizeof(buf));
+       while(fgets(buf, sizeof(buf), fp)) {
+               LOGINFO("[rpm] %s", buf);
+
+               if (!strncmp(buf, "error", 5)) {
+                       ret = false;
+               }
+           memset(buf, 0, sizeof(buf));
+       }
+
+       pclose(fp);
+
+       return ret;
+}
+
+static void remove_package(char* data)
+{
+       char token[] = ", ";
+       char pkg_list[MAX_PKGS_BUF];
+       char *addon = NULL;
+       char *copy = strdup(data);
+       if (copy == NULL) {
+               LOGERR("Failed to copy data.");
+               return;
+       }
+
+       memset(pkg_list, 0, sizeof(pkg_list));
 
-    ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SUSPEND, (const char*) tmp, tmplen);
+       strcpy(pkg_list, "rm -rf ");
 
-    if (tmp)
-        free(tmp);
-    if (packet)
-        free(packet);
+       strcat(pkg_list, PATH_PACKAGE_INSTALL);
+       addon = strtok(copy, token);
+       strcat(pkg_list, addon);
+
+       LOGINFO("remove packages: %s", pkg_list);
+
+       systemcall(pkg_list);
+
+       free(copy);
+}
+
+static bool do_package(int action, char* data)
+{
+       char token[] = ", ";
+       char *pkg = NULL;
+       char *addon = NULL;
+       char pkg_list[MAX_PKGS_BUF];
+
+       memset(pkg_list, 0, sizeof(pkg_list));
+
+       strcpy(pkg_list, "rpm");
+
+       if (action == 1) {
+               strcat(pkg_list, " ");
+               strcat(pkg_list, RPM_CMD_QUERY);
+       } else if (action == 2) {
+               strcat(pkg_list, " ");
+               strcat(pkg_list, RPM_CMD_INSTALL);
+       } else {
+               LOGERR("Unknown action.");
+               return false;
+       }
+       addon = strtok(data, token); // for addon path
+
+       pkg = strtok(NULL, token);
+       while (pkg != NULL) {
+               if (action == 1) {
+                       pkg[strlen(pkg) - 4] = 0; //remove .rpm
+               }
+               strcat(pkg_list, " ");
+               if (action == 2) {
+                       strcat(pkg_list, PATH_PACKAGE_INSTALL);
+                       strcat(pkg_list, addon);
+                       strcat(pkg_list, "/");
+               }
+               strcat(pkg_list, pkg);
+
+               pkg = strtok(NULL, token);
+       }
+
+       strcat(pkg_list, " ");
+       strcat(pkg_list, "2>&1");
+
+       LOGINFO("[cmd]%s", pkg_list);
+       if (action == 1 && do_validate(pkg_list)) {
+               return true;
+       } else if (action == 2 && do_install(pkg_list)) {
+               return true;
+       }
+
+       return false;
 }
 
+static void* package_thread(void* args)
+{
+       LOGINFO("install package_thread starts.");
+       int action = 0;
+       ijcommand* ijcmd = (ijcommand*)args;
+       char* data = strdup(ijcmd->data);
+       if (data == NULL) {
+               LOGERR("install data is failed to copied.");
+               return NULL;
+       }
+
+       if (ijcmd->msg.action == 1) { // validate packages
+               if (do_package(1, data)) {
+                       action = 1; // already installed
+               } else {
+                       action = 2; // need to install
+               }
+       } else if (ijcmd->msg.action == 2) { // install packages
+               if (do_package(2, data)) {
+                       action = 3; // install success
+               } else {
+                       action = 4; // failed to install
+               }
+               remove_package(ijcmd->data);
+       } else {
+               LOGERR("invalid command (action:%d)", ijcmd->msg.action);
+       }
+
+       LOGINFO("send %d, with %s", action, ijcmd->data);
+       send_to_ecs(IJTYPE_PACKAGE, 0, action, ijcmd->data);
+
+       free(data);
+
+       return NULL;
+}
+
+void msgproc_package(ijcommand* ijcmd)
+{
+       _auto_mutex _(&mutex_pkg);
+       int ret = 0;
+       void* retval = NULL;
+       pthread_t pkg_thread_id;
+
+       if (!ijcmd->data) {
+               LOGERR("package data is empty.");
+               return;
+       }
+
+       LOGINFO("received %d, with %s", ijcmd->msg.action, ijcmd->data);
+
+       if (pthread_create(&pkg_thread_id, NULL, package_thread, (void*)ijcmd) != 0)
+       {
+               LOGERR("validate package pthread creation is failed!");
+       }
+       ret = pthread_join(pkg_thread_id, &retval);
+       if (ret < 0) {
+               LOGERR("validate package pthread join is failed.");
+       }
+}
 
index b80710f1df18b6708b21cba2d27126741213818a..dde5cf34f6cbd8e6afd47e0eb495568436f01616 100644 (file)
@@ -46,6 +46,8 @@
 #include <unistd.h>
 #include "emuld.h"
 
+static pthread_mutex_t mutex_cmd = PTHREAD_MUTEX_INITIALIZER;
+
 // SDCard
 #define IJTYPE_SDCARD       "sdcard"
 
@@ -58,20 +60,12 @@ char SDpath[256];
 #define STATUS              15
 #define LOCATION_STATUS     120
 char command[512];
-char latitude[128];
-char longitude[128];
 
 /*
  * SD Card functions
  */
 
-struct mount_param
-{
-    mount_param(int _fd) : fd(_fd) {}
-    int fd;
-};
-
-char* get_mount_info() {
+static char* get_mount_info() {
     struct mntent *ent;
     FILE *aFile;
 
@@ -125,8 +119,6 @@ int is_mounted()
 
 void* mount_sdcard(void* data)
 {
-    mount_param* param = (mount_param*) data;
-
     int ret = -1, i = 0;
     struct stat buf;
     char file_name[128], command[256];
@@ -202,15 +194,10 @@ void* mount_sdcard(void* data)
         packet = NULL;
     }
 
-    if (param)
-    {
-        delete param;
-        param = NULL;
-    }
     pthread_exit((void *) 0);
 }
 
-int umount_sdcard(const int fd)
+static int umount_sdcard(void)
 {
     int ret = -1, i = 0;
     char file_name[128];
@@ -269,7 +256,7 @@ int umount_sdcard(const int fd)
 }
 
 
-void msgproc_sdcard(const int sockfd, ijcommand* ijcmd)
+void msgproc_sdcard(ijcommand* ijcmd)
 {
     LOGDEBUG("msgproc_sdcard");
 
@@ -291,21 +278,17 @@ void msgproc_sdcard(const int sockfd, ijcommand* ijcmd)
     {
         case 0:                         // umount
             {
-                mount_status = umount_sdcard(sockfd);
+                mount_status = umount_sdcard();
             }
             break;
         case 1:                         // mount
             {
                 memset(SDpath, '\0', sizeof(SDpath));
                 ret = strtok(NULL, token);
-                strcpy(SDpath, ret);
+                strncpy(SDpath, ret, strlen(ret));
                 LOGDEBUG("sdcard path is %s", SDpath);
 
-                mount_param* param = new mount_param(sockfd);
-                if (!param)
-                    break;
-
-                if (pthread_create(&tid[TID_SDCARD], NULL, mount_sdcard, (void*) param) != 0)
+                if (pthread_create(&tid[TID_SDCARD], NULL, mount_sdcard, NULL) != 0)
                     LOGERR("mount sdcard pthread create fail!");
             }
 
@@ -378,13 +361,16 @@ void msgproc_sdcard(const int sockfd, ijcommand* ijcmd)
                                     memcpy(tmp + HEADER_SIZE + mntData->length, mountinfo, mountinfo_size);
                                     mntData->length += mountinfo_size;
                                     memcpy(tmp, mntData, HEADER_SIZE);
-                                    delete mountinfo;
-                                    mountinfo = NULL;
+                                    free(mountinfo);
                                 }
 
                                 ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
 
                                 free(tmp);
+                            } else {
+                                if (mountinfo) {
+                                    free(mountinfo);
+                                }
                             }
                         }
                         break;
@@ -400,6 +386,37 @@ void msgproc_sdcard(const int sockfd, ijcommand* ijcmd)
     }
 }
 
+void* exec_cmd_thread(void *args)
+{
+    char *command = (char*)args;
+
+    systemcall(command);
+    LOGDEBUG("executed cmd: %s", command);
+    free(command);
+
+    pthread_exit(NULL);
+}
+
+void msgproc_cmd(ijcommand* ijcmd)
+{
+    _auto_mutex _(&mutex_cmd);
+    pthread_t cmd_thread_id;
+    char *cmd = (char*) malloc(ijcmd->msg.length + 1);
+
+    if (!cmd) {
+        LOGERR("malloc failed.");
+        return;
+    }
+
+    memset(cmd, 0x00, ijcmd->msg.length + 1);
+    strncpy(cmd, ijcmd->data, ijcmd->msg.length);
+    LOGDEBUG("cmd: %s, length: %d", cmd, ijcmd->msg.length);
+
+    if (pthread_create(&cmd_thread_id, NULL, exec_cmd_thread, (void*)cmd) != 0)
+    {
+        LOGERR("cmd pthread create fail!");
+    }
+}
 
 /*
  * Location function
@@ -446,6 +463,8 @@ static char* get_location_status(void* p)
     } else if (mode == 2) { // MANUAL MODE
         double latitude;
         double logitude;
+        double altitude;
+        double accuracy;
         ret = vconf_get_dbl("db/location/replay/ManualLatitude", &latitude);
         if (ret != 0) {
             return 0;
@@ -454,9 +473,18 @@ static char* get_location_status(void* p)
         if (ret != 0) {
             return 0;
         }
+        ret = vconf_get_dbl("db/location/replay/ManualAltitude", &altitude);
+        if (ret != 0) {
+            return 0;
+        }
+         ret = vconf_get_dbl("db/location/replay/ManualHAccuracy", &accuracy);
+        if (ret != 0) {
+            return 0;
+        }
+
         message = (char*)malloc(128);
         memset(message, 0, 128);
-        ret = sprintf(message, "%d,%f,%f", mode, latitude, logitude);
+        ret = sprintf(message, "%d,%f,%f,%f,%f", mode, latitude, logitude, altitude, accuracy);
         if (ret < 0) {
             free(message);
             message = 0;
@@ -464,13 +492,16 @@ static char* get_location_status(void* p)
         }
     }
 
-    LXT_MESSAGE* packet = (LXT_MESSAGE*)p;
-    memset(packet, 0, sizeof(LXT_MESSAGE));
-    packet->length = strlen(message);
-    packet->group  = STATUS;
-    packet->action = LOCATION_STATUS;
-
-    return message;
+    if (message) {
+        LXT_MESSAGE* packet = (LXT_MESSAGE*)p;
+        memset(packet, 0, sizeof(LXT_MESSAGE));
+        packet->length = strlen(message);
+        packet->group  = STATUS;
+        packet->action = LOCATION_STATUS;
+        return message;
+    } else {
+        return NULL;
+    }
 }
 
 static void* getting_location(void* data)
@@ -529,12 +560,9 @@ static void* getting_location(void* data)
         free(msg);
         msg = 0;
     }
-    if (packet)
-    {
+    if (packet != NULL) {
         free(packet);
-        packet = NULL;
     }
-
     if (param)
         delete param;
 
@@ -576,28 +604,35 @@ void setting_location(char* databuf)
             LOGDEBUG("%s", command);
             systemcall(command);
         } else if(mode == 2) {
-            memset(latitude,  0, 128);
-            memset(longitude, 0, 128);
-            char* t = strchr(s+1, ',');
-            *t = '\0';
-            strcpy(latitude, s+1);
-            strcpy(longitude, t+1);
-            //strcpy(longitude, s+1);
-            //strcpy(latitude, databuf);
+            char* ptr = strtok(s+1, ",");
+
             // Latitude
-            sprintf(command, "vconftool set -t double db/location/replay/ManualLatitude %s -f", latitude);
-            LOGDEBUG("%s", command);
+            sprintf(command, "vconftool set -t double db/location/replay/ManualLatitude %s -f", ptr);
+            LOGINFO("%s", command);
             systemcall(command);
 
             // Longitude
-            sprintf(command, "vconftool set -t double db/location/replay/ManualLongitude %s -f", longitude);
-            LOGDEBUG("%s", command);
+            ptr = strtok(NULL, ",");
+            sprintf(command, "vconftool set -t double db/location/replay/ManualLongitude %s -f", ptr);
+            LOGINFO("%s", command);
+            systemcall(command);
+
+            // Altitude
+            ptr = strtok(NULL, ",");
+            sprintf(command, "vconftool set -t double db/location/replay/ManualAltitude %s -f", ptr);
+            LOGINFO("%s", command);
+            systemcall(command);
+
+            // accuracy
+            ptr = strtok(NULL, ",");
+            sprintf(command, "vconftool set -t double db/location/replay/ManualHAccuracy %s -f", ptr);
+            LOGINFO("%s", command);
             systemcall(command);
         }
     }
 }
 
-void msgproc_location(const int sockfd, ijcommand* ijcmd)
+void msgproc_location(ijcommand* ijcmd)
 {
     LOGDEBUG("msgproc_location");
     if (ijcmd->msg.group == STATUS)
@@ -606,7 +641,6 @@ void msgproc_location(const int sockfd, ijcommand* ijcmd)
         if (!param)
             return;
 
-        param->get_status_sockfd = sockfd;
         param->ActionID = ijcmd->msg.action;
         memcpy(param->type_cmd, ijcmd->cmd, ID_SIZE);
 
@@ -717,7 +751,7 @@ int umount_hds(void)
     return 0;
 }
 
-void msgproc_hds(const int sockfd, ijcommand* ijcmd)
+void msgproc_hds(ijcommand* ijcmd)
 {
     LOGDEBUG("msgproc_hds");
 
index bb8ce4195efdb609bb1c7edf5b465dd25a1311eb..b2669c1e6d18f6c6b5b64d7f1f191c625ea09985 100644 (file)
@@ -29,6 +29,8 @@
 
 #include <errno.h>
 #include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
 #include <arpa/inet.h>
 #include <unistd.h>
 
@@ -138,8 +140,11 @@ static int read_header(int fd, LXT_MESSAGE* packet)
 {
     char* readbuf = NULL;
     int readed = recv_data(fd, &readbuf, HEADER_SIZE);
-    if (readed <= 0)
+    if (readed <= 0){
+               if (readbuf)
+                       free(readbuf);
         return 0;
+       }
     memcpy((void*) packet, (void*) readbuf, HEADER_SIZE);
 
     if (readbuf)
@@ -217,7 +222,7 @@ void recv_from_evdi(evdi_fd fd)
         }
     }
 
-    LOGINFO("total readed  = %d, read count = %d, index = %d, use = %d, msg = %s",
+    LOGDEBUG("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();
@@ -261,6 +266,17 @@ void recv_from_evdi(evdi_fd fd)
     process_evdi_command(&ijcmd);
 }
 
+void writelog(const char* fmt, ...)
+{
+    FILE* logfile = fopen("/tmp/emuld.log", "a+");
+       va_list args;
+       va_start(args, fmt);
+       vfprintf(logfile, fmt, args);
+       vfprintf(logfile, "\n", NULL);
+       va_end(args);
+       fclose(logfile);
+}
+
 int main( int argc , char *argv[])
 {
     init_fd();
@@ -280,6 +296,8 @@ int main( int argc , char *argv[])
 
        init_profile();
 
+       send_emuld_connection();
+
     send_default_suspend_req();
 
     while(!exit_flag)
@@ -291,7 +309,7 @@ int main( int argc , char *argv[])
 
     stop_listen();
 
-    LOGINFO("emuld exit");
+       LOGINFO("emuld exit");
 
     return 0;
 }
index 16526ba351ff26987b6b9444845dfd9d02b0918a..b64836ce9ba6a5dc2e5b9153f7e68ab6136015d7 100644 (file)
@@ -43,9 +43,8 @@ evdi_fd open_device(void)
     fd = open(DEVICE_NODE_PATH, O_RDWR); //O_CREAT|O_WRONLY|O_TRUNC.
     LOGDEBUG("evdi open fd is %d", fd);
 
-    if (fd <= 0) {
+    if (fd < 0) {
         LOGERR("open %s fail", DEVICE_NODE_PATH);
-        return fd;
     }
 
     return fd;
@@ -76,7 +75,7 @@ bool init_device(evdi_fd* ret_fd)
     *ret_fd = -1;
 
     fd = open_device();
-    if (fd <= 0)
+    if (fd < 0)
         return false;
 
     if (!set_nonblocking(fd))
@@ -122,7 +121,7 @@ bool ijmsg_send_to_evdi(evdi_fd fd, const char* cat, const char* data, const int
 
     char tmp[ID_SIZE];
     memset(tmp, 0, ID_SIZE);
-    strncpy(tmp, cat, 10);
+    strncpy(tmp, cat, ID_SIZE - 1);
 
     // TODO: need to make fragmented transmission
     if (len + ID_SIZE > __MAX_BUF_SIZE) {
index 842f4267090dc7eabff7480b2943e39319fefa18..f8c704144fe7a901d2313b972281b38c87df5148 100644 (file)
 
 void process_evdi_command(ijcommand* ijcmd)
 {
-    int fd = -1;
-
     if (strncmp(ijcmd->cmd, "sensor", 6) == 0)
     {
-        msgproc_sensor(fd, ijcmd);
+        msgproc_sensor(ijcmd);
+    }
+    else if (strcmp(ijcmd->cmd, IJTYPE_SUSPEND) == 0)
+    {
+        msgproc_suspend(ijcmd);
+    }
+    else if (strcmp(ijcmd->cmd, "location") == 0)
+    {
+        msgproc_location(ijcmd);
     }
-    else if (strncmp(ijcmd->cmd, "suspend", 7) == 0)
+    else if (strcmp(ijcmd->cmd, "hds") == 0)
     {
-        msgproc_suspend(fd, ijcmd);
+        msgproc_hds(ijcmd);
     }
-    else if (strncmp(ijcmd->cmd, "location", 8) == 0)
+    else if (strcmp(ijcmd->cmd, "system") == 0)
     {
-        msgproc_location(fd, ijcmd);
+        msgproc_system(ijcmd);
     }
-    else if (strncmp(ijcmd->cmd, "hds", 3) == 0)
+    else if (strcmp(ijcmd->cmd, IJTYPE_PACKAGE) == 0)
     {
-        msgproc_hds(fd, ijcmd);
+        msgproc_package(ijcmd);
     }
-    else if (strncmp(ijcmd->cmd, "system", 6) == 0)
+    else if (strcmp(ijcmd->cmd, "sdcard") == 0)
     {
-        msgproc_system(fd, ijcmd);
+        msgproc_sdcard(ijcmd);
     }
-    else if (strncmp(ijcmd->cmd, "sdcard", 6) == 0)
+    else if (strcmp(ijcmd->cmd, "cmd") == 0)
     {
-        msgproc_sdcard(fd, ijcmd);
+        msgproc_cmd(ijcmd);
     }
     else
     {
index 5d958648adc67752a7fb067adda0956a67a50a08..9b04229a385b31550b10bab11cb140d2617ed67e 100644 (file)
@@ -540,11 +540,8 @@ static void* getting_sensor(void* data)
         free(msg);
         msg = 0;
     }
-    if (packet)
-    {
-        free(packet);
-        packet = NULL;
-    }
+
+    free(packet);
 
     if (param)
         delete param;
@@ -552,7 +549,7 @@ static void* getting_sensor(void* data)
     pthread_exit((void *) 0);
 }
 
-void msgproc_sensor(const int sockfd, ijcommand* ijcmd)
+void msgproc_sensor(ijcommand* ijcmd)
 {
     LOGDEBUG("msgproc_sensor");
 
@@ -564,7 +561,6 @@ void msgproc_sensor(const int sockfd, ijcommand* ijcmd)
 
         memset(param, 0, sizeof(*param));
 
-        param->get_status_sockfd = sockfd;
         param->ActionID = ijcmd->msg.action;
         memcpy(param->type_cmd, ijcmd->cmd, ID_SIZE);
 
@@ -578,7 +574,7 @@ void msgproc_sensor(const int sockfd, ijcommand* ijcmd)
     else
     {
         if (ijcmd->data != NULL && strlen(ijcmd->data) > 0) {
-            getting_sensor(ijcmd->data);
+            setting_sensor(ijcmd->data);
         }
     }
 }
index 6443a8a0663e9887b62935635140f358ef5ebf1b..c3b1a0d33fa32b38af3fd8f0ef037d7d75b67227 100644 (file)
 
 #include <stdio.h>
 #include <errno.h>
-#include <arpa/inet.h>
-#include <unistd.h>
 
 #include "emuld.h"
 #include "wearable.h"
 
 void process_evdi_command(ijcommand* ijcmd)
 {
-    int fd = -1;
-
-    if (strncmp(ijcmd->cmd, "suspend", 7) == 0)
+    if (strcmp(ijcmd->cmd, "suspend") == 0)
+    {
+        msgproc_suspend(ijcmd);
+    }
+    else if (strcmp(ijcmd->cmd, "sensor") == 0)
+    {
+        msgproc_sensor(ijcmd);
+    }
+    else if (strcmp(ijcmd->cmd, "location") == 0)
     {
-        msgproc_suspend(fd, ijcmd);
+        msgproc_location(ijcmd);
     }
-    else if (strncmp(ijcmd->cmd, "sensor", 6) == 0)
+    else if (strcmp(ijcmd->cmd, "hds") == 0)
     {
-        msgproc_sensor(fd, ijcmd);
+        msgproc_hds(ijcmd);
     }
-    else if (strncmp(ijcmd->cmd, "location", 8) == 0)
+    else if (strcmp(ijcmd->cmd, "system") == 0)
     {
-        msgproc_location(fd, ijcmd);
+        msgproc_system(ijcmd);
     }
-    else if (strncmp(ijcmd->cmd, "hds", 3) == 0)
+    else if (strcmp(ijcmd->cmd, IJTYPE_PACKAGE) == 0)
     {
-        msgproc_hds(fd, ijcmd);
+        msgproc_package(ijcmd);
     }
-    else if (strncmp(ijcmd->cmd, "system", 6) == 0)
+    else if (strcmp(ijcmd->cmd, "sdcard") == 0)
     {
-        msgproc_system(fd, ijcmd);
+        msgproc_sdcard(ijcmd);
     }
-    else if (strncmp(ijcmd->cmd, "sdcard", 6) == 0)
+    else if (strcmp(ijcmd->cmd, "cmd") == 0)
     {
-        msgproc_sdcard(fd, ijcmd);
+        msgproc_cmd(ijcmd);
     }
     else
     {
index 5399e8e7f998084fc70505c6dc3dfebacef96f3e..fdc390c51297695d193d8435bfee54de73cb405f 100644 (file)
@@ -267,7 +267,7 @@ static void device_parser(char *buffer)
     }
 }
 
-void msgproc_sensor(const int sockfd, ijcommand* ijcmd)
+void msgproc_sensor(ijcommand* ijcmd)
 {
     LOGDEBUG("msgproc_sensor");
 
@@ -278,4 +278,3 @@ void msgproc_sensor(const int sockfd, ijcommand* ijcmd)
         }
     }
 }
-