sync with tizen_2.2 tizen
authorsungmin82.ha <sungmin82.ha@samsung.com>
Tue, 30 Jul 2013 05:52:38 +0000 (14:52 +0900)
committersungmin82.ha <sungmin82.ha@samsung.com>
Tue, 30 Jul 2013 05:52:38 +0000 (14:52 +0900)
Change-Id: I23b89023066f4af3e3d940db30e4daad04712877
Signed-off-by: Sungmin Ha <sungmin82.ha@samsung.com>
13 files changed:
AUTHORS
CMakeLists.txt
debian/changelog
debian/control
debian/copyright
emuld [new file with mode: 0644]
emuld.service [new file with mode: 0644]
include/emuld.h
include/emuld_common.h [new file with mode: 0644]
packaging/emuld.manifest [new file with mode: 0644]
packaging/emuld.spec
src/emuld.c
src/get_status.c [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
index caffe7b..978df0f 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,9 +1,6 @@
-HyunGoo Kang <hyungoo1.kang@samsung.com>
 YeongKyoon Lee <yeongkyoon.lee@samsung.com>
-DongKyun Yun <dk77.yun@samsung.com>
-DoHyung Hong <don.hong@samsung.com>
+DaiYoung Kim <daiyoung777.kim@samsung.com>
 SeokYeon Hwang <syeon.hwang@samsung.com>
-Hyunjun Son <hj79.son@samsung.com>
 SangJin Kim <sangjin3.kim@samsung.com>
 KiTae Kim <kt920.kim@samsung.com>
 JinHyung Jo <jinhyung.jo@samsung.com>
@@ -11,3 +8,6 @@ SungMin Ha <sungmin82.ha@samsung.com>
 MunKyu Im <munkyu.im@samsung.com>
 JiHye Kim <jihye1128.kim@samsung.com>
 GiWoong Kim <giwoong.kim@samsung.com>
+SooYoung Ha <yoosah.ha@samsnung.com>
+HyunGoo Kang <hyungoo1.kang@samsung.com>
+
index 62a56b8..e958d0b 100644 (file)
@@ -34,9 +34,9 @@ ADD_DEFINITIONS("-DTARGET -DHWREV_CHECK")
 add_definitions(-Wall -O3 -omit-frame-pointer)
 #add_definitions(-Wall -g -D_DEBUG)
 add_definitions(-Iinclude)
-ADD_EXECUTABLE(${PROJECT_NAME} src/emuld.c)
+ADD_EXECUTABLE(${PROJECT_NAME} src/emuld.c src/get_status.c)
 
 target_link_libraries(${PROJECT_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} "-lpthread" )
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} "-lpthread -lvconf" )
 
 install(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin)
index 572b8ea..5108c36 100644 (file)
@@ -1,3 +1,19 @@
+emuld (0.2.20) unstable; urgency=low
+
+  * add checking routine 'recv' function's return value
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.20
+
+ -- Jihye kim <jihye1128.kim@samsung.com> Mon, 04 Nov 2012 20:00:18 +0900
+
+emuld (0.2.18) unstable; urgency=low
+
+  * fixed hang up when sending packet vmodem to eventinjector
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.18
+
+ -- Sungmin ha <sungmin82.ha@samsung.com> Wed, 12 Sep 2012 20:00:18 +0900
+
 emuld (0.2.17) unstable; urgency=low
 
   * modified for scm build
index 15fa734..685dbb7 100644 (file)
@@ -2,7 +2,7 @@ Source: emuld
 Section: misc
 Priority: extra
 Maintainer:Sungmin Ha <sungmin82.ha@samsung.com>,Jihye Kim <jihye1128.kim@samsung.com>,Yeongkyoon Lee <yeongkyoon.lee@samsung.com>
-Standards-Version: 0.2.17
+Standards-Version: 0.2.20
 
 Package: emuld
 Section: misc
index e7f26e9..8b13789 100644 (file)
@@ -1,21 +1 @@
-This is $PACKAGE_NAME, written and maintained by $NAME <$EMAIL>
-on Fri, 18 Nov 2011 17:08:22 +0900.
 
-The original source can always be found at:
-       slp/sdk/public/common/emulator/default-files-emulator/src/emulator-daemon
-
-Copyright Holder: $NAME
-
-License:
-       samsung
-
-/*
- * Copyright (c) 2008 Samsung Electronics, Inc.
- * All rights reserved.
- *
- * This software is a confidential and proprietary information
- * of Samsung Electronics, Inc. ("Confidential Information").  You
- * shall not disclose such Confidential Information and shall use
- * it only in accordance with the terms of the license agreement
- * you entered into with Samsung Electronics. 
- */
diff --git a/emuld b/emuld
new file mode 100644 (file)
index 0000000..7f13703
--- /dev/null
+++ b/emuld
@@ -0,0 +1,3 @@
+/usr/bin/emuld &
+/usr/sbin/sensord &
+/etc/emulator/sensor_setting.sh &
diff --git a/emuld.service b/emuld.service
new file mode 100644 (file)
index 0000000..1d9173f
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=Daemon for emulator
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/emuld
+
+[Install]
+WantedBy=emulator.target
+
index 5c528eb..9a07b11 100644 (file)
@@ -3,9 +3,9 @@
  *
  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: 
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsnung.com>
  * Sungmin Ha <sungmin82.ha@samsung.com>
- * DongKyun Yun <dk77.yun@samsung.com>
  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -43,6 +43,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <sys/mount.h>
+#include <stdbool.h>
 
 /* definition */
 #define MAX_CLIENT             10000
@@ -60,6 +61,9 @@
 #define POWEROFF_DURATION      2
 
 /* function prototype */
+
+void set_vm_connect_status(const int v);
+bool is_vm_connected(void);
 void init_data0(void);            /* initialize data. */
 void init_server0(int svr_port);  /* server socket bind/listen */
 void* init_vm_connect(void* data);
@@ -71,7 +75,7 @@ int parse_val(char *buff, unsigned char data, char *parsbuf);
 void udp_init(void);
 int recv_data(int event_fd, char** r_databuf, int size);
 void client_recv(int event_fd);
-void server_process(void);
+bool server_process(void);
 void end_server(int sig);
 int is_mounted(void);
 
@@ -80,6 +84,7 @@ FILE* log_fd;
 
 // location
 void setting_location(char* databuf);
+
 #define LOG(fmt, arg...) \
        do { \
                log_print_out("[%s:%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); \
diff --git a/include/emuld_common.h b/include/emuld_common.h
new file mode 100644 (file)
index 0000000..5e96735
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsnung.com>
+ * Sungmin Ha <sungmin82.ha@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+#include <netdb.h>
+#include <unistd.h>
+
+// define group id
+// return value to the injector
+#define STATUS 15
+
+// define action id
+#define BATTERY_LEVEL 100
+#define BATTERY_CHARGER 101
+#define USB_STATUS 102
+#define EARJACK_STATUS 103
+#define RSSI_LEVEL 104
+
+#define ACCEL_VALUE 110
+#define GYRO_VALUE 111
+#define MAG_VALUE 112
+#define LIGHT_VALUE 113
+#define PROXI_VALUE 114
+#define MOTION_VALUE 115
+
+#define LOCATION_STATUS 120
+
+#define NFC_STATUS 121
+
+struct LXT_MESSAGE// lxt_message
+{
+       unsigned short length;
+       unsigned char group;
+       unsigned char action;
+       void *data; 
+};
+
+typedef struct LXT_MESSAGE LXT_MESSAGE;
+
+// Device
+char* get_battery_level(void* );
+char* get_battery_charger(void* );
+char* get_usb_status(void* );
+char* get_earjack_status(void* );
+char* get_rssi_level(void* );
+
+// Sensor
+char* get_proximity_status(void* );
+char* get_light_level(void* );
+char* get_acceleration_value(void* );
+char* get_gyroscope_value(void* );
+char* get_magnetic_value(void* );
+
+// Location
+char* get_location_status(void* );
+
+// NFC
+char* get_nfc_status(void* );
diff --git a/packaging/emuld.manifest b/packaging/emuld.manifest
new file mode 100644 (file)
index 0000000..017d22d
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+    <domain name="_"/>
+ </request>
+</manifest>
index ed9d37e..974f5ca 100644 (file)
@@ -1,13 +1,13 @@
 #git:/slp/pkgs/e/emulator-daemon
 Name: emuld
-Version: 0.2.17
+Version: 0.2.40
 Release: 1
 Summary: emuld is used for communication emulator between and ide.
 License: Apache
 Source0: %{name}-%{version}.tar.gz
-BuildArch: i386
-ExclusiveArch: %{ix86}
+Source1001: packaging/emuld.manifest
 BuildRequires: cmake
+BuildRequires:  pkgconfig(vconf)
 
 %description
 
@@ -15,14 +15,31 @@ BuildRequires: cmake
 %setup -q
 
 %build
-export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed"    
-    
+export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed"
+
 LDFLAGS="$LDFLAGS" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
 
 make
 
 %install
+#for systemd
 rm -rf %{buildroot}
+if [ ! -d %{buildroot}/usr/lib/systemd/system/emulator.target.wants ]; then
+    mkdir -p %{buildroot}/usr/lib/systemd/system/emulator.target.wants
+fi
+cp emuld.service %{buildroot}/usr/lib/systemd/system/.
+ln -s ../emuld.service %{buildroot}/usr/lib/systemd/system/emulator.target.wants/emuld.service
+
+#for legacy init
+if [ ! -d %{buildroot}/etc/init.d ]; then
+    mkdir -p %{buildroot}/etc/init.d
+fi
+cp emuld %{buildroot}/etc/init.d/.
+if [ ! -d %{buildroot}/etc/rc.d/rc3.d ]; then
+    mkdir -p %{buildroot}/etc/rc.d/rc3.d
+fi
+ln -s /etc/init.d/emuld %{buildroot}/etc/rc.d/rc3.d/S04emuld
+
 %make_install
 
 %clean
@@ -43,5 +60,9 @@ touch /opt/nfc/sdkMsg
 %files
 %defattr(-,root,root,-)
 %{_prefix}/bin/emuld
+/usr/lib/systemd/system/emuld.service
+/usr/lib/systemd/system/emulator.target.wants/emuld.service
+/etc/init.d/emuld
+/etc/rc.d/rc3.d/S04emuld
 
 %changelog
index dc386d7..f271999 100644 (file)
@@ -1,11 +1,11 @@
-/*
+/* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: t -*-
  * emulator-daemon
  *
  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: 
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsnung.com>
  * Sungmin Ha <sungmin82.ha@samsung.com>
- * DongKyun Yun <dk77.yun@samsung.com>
  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,9 +33,12 @@ compiler Gcc: 3.4.3.
 License: GNU General Public License   
 
 ------------------------------------------------------------------*/
-
+#include "emuld_common.h"
 #include "emuld.h"
+#include <error.h>
+
 
+#define MAX_CONNECT_TRY_COUNT  (60 * 3)
 /* global definition */
 unsigned short sdbd_port = SDBD_PORT;
 unsigned short vmodem_port = VMODEM_PORT;
@@ -48,6 +51,7 @@ int g_vm_sockfd;              /* vmodem fd */
 int g_sdbd_sockfd = -1;                /* sdbd fd */
 static int g_vm_connect_status;        /* connection status between emuld and vmodem  */
 int g_sdcard_sockfd = -1;
+int g_get_status_sockfd = -1;   /* return status of devive to the injector */
 
 pthread_t tid[MAX_CLIENT + 1];
 
@@ -64,16 +68,9 @@ struct {
 
 int g_epoll_fd;                                /* epoll fd */
 
-struct epoll_event g_events[MAX_EVENTS]; 
+static pthread_mutex_t mutex_vmconnect = PTHREAD_MUTEX_INITIALIZER;
 
-// for vmodem packets
-typedef struct // lxt_message
-{
-       unsigned short length;
-       unsigned char group;
-       unsigned char action;
-       void *data; 
-} LXT_MESSAGE;
+struct epoll_event g_events[MAX_EVENTS]; 
 
 void TAPIMessageInit(LXT_MESSAGE *packet)
 {       
@@ -84,7 +81,10 @@ void TAPIMessageInit(LXT_MESSAGE *packet)
 }
 
 char SDpath[256];
-       
+
+unsigned char ActionID = 0;
+char GetBuffer[256];
+void setting_device(); 
 /*--------------------------------------------------------------*/
 /* FUNCTION PART 
    ---------------------------------------------------------------*/
@@ -102,6 +102,31 @@ void init_data0(void)
        }
 }
 
+bool is_vm_connected(void)
+{
+       bool ret = false;
+
+       pthread_mutex_lock(&mutex_vmconnect);
+
+       if (g_vm_connect_status == 1)
+       {
+               ret = true;
+       }
+
+       pthread_mutex_unlock(&mutex_vmconnect);
+
+       return ret;
+}
+
+void set_vm_connect_status(const int v)
+{
+       pthread_mutex_lock(&mutex_vmconnect);
+
+       g_vm_connect_status = v;
+
+       pthread_mutex_unlock(&mutex_vmconnect);
+}
+
 /*------------------------------------------------------------- 
 function: init_server0 
 io: input : integer - server port (must be positive)
@@ -156,13 +181,16 @@ void* init_vm_connect(void* data)
 {
        struct sockaddr_in vm_addr;
        int ret = -1;   
-       g_vm_connect_status = 0;
+       //int connect_try_count = 0;
+       bool is_connected = false;
 
-       LOG("start");
+       set_vm_connect_status(0);
+
+       LOG("init_vm_connect start");
 
        pthread_detach(pthread_self());
        /* Open TCP Socket */
-       if( (g_vm_sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0 ) 
+       if( (g_vm_sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
        {
                fprintf(stderr, "Server Start Fails. : Can't open stream socket \n");
                exit(0);
@@ -175,24 +203,36 @@ void* init_vm_connect(void* data)
        vm_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
        vm_addr.sin_port = htons(vmodem_port);
 
-       while(ret < 0)
+       while(ret < 0  /*&& (connect_try_count < MAX_CONNECT_TRY_COUNT)*/)
        {
                ret = connect(g_vm_sockfd, (struct sockaddr *)&vm_addr, sizeof(vm_addr));
 
                LOG("vm_sockfd: %d, connect ret: %d", g_vm_sockfd, ret);
 
                if(ret < 0) {
-                       LOG("connection failed to vmodem!");            
+                       LOG("connection failed to vmodem! try \n");
                        sleep(1);
                }
+               else
+               {
+                       is_connected = true;
+               }
+               //connect_try_count ++;
        }
+       /*
+       if (!is_connected)
+       {
+               LOG("try to connect to vmoden was failed!");
+               exit(0);
+       }*/
        
        userpool_add(g_vm_sockfd, vm_addr.sin_port);
 
        /* add client sockfd at event pool */
        epoll_cli_add(g_vm_sockfd);
        
-       g_vm_connect_status = 1;
+       set_vm_connect_status(1);
+
        pthread_exit((void *) 0); 
 }
 
@@ -222,7 +262,7 @@ int is_mounted()
 
 void* mount_sdcard(void* data)
 {
-       int ret = -1, i = 0, vconf_value = -1;  
+       int ret = -1, i = 0;
        struct stat buf;
        char file_name[128], command[256];
        memset(file_name, '\0', sizeof(file_name));
@@ -257,14 +297,11 @@ void* mount_sdcard(void* data)
                if( i != 10 )
                {
                        LOG( "%s is exist", file_name);
-                       ret = mount(file_name, "/mnt/mmc", "ext3", 0, "");
-                       LOG("mount ret = %d, errno = %d", ret, errno);
-                       
                        LOG("sdcard fd: %d", g_sdcard_sockfd);
                        if(g_sdcard_sockfd != -1)
                        {
-                               packet->length = strlen(SDpath);                // length
-                               packet->group = 11;                             // sdcard
+                               packet->length = strlen(SDpath); // length
+                               packet->group = 11; // sdcard
                                if(ret == 0)
                                        packet->action = 1;     // mounted
                                else
@@ -273,14 +310,12 @@ void* mount_sdcard(void* data)
                                send(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
                                LOG("SDpath is %s", SDpath);
                                send(g_sdcard_sockfd, SDpath, packet->length, 0);
-                               
+
                                if(ret == 0)
                                {
-                                       system("chmod -R 777 /opt/storage/sdcard");
-                                       system("vconftool set -t int memory/sysman/mmc 1 -i -f");
+                                       system("/usr/bin/sys_event mmcblk_add");
                                }
                        }
-
                        break;
                }
                else
@@ -290,15 +325,18 @@ void* mount_sdcard(void* data)
                }               
        }
 
-       pthread_exit((void *) 0); 
-} 
+       pthread_exit((void *) 0);
+}
 
 int umount_sdcard(void)
 {
-       int ret = -1, i = 0;    
+       int ret = -1, i = 0;
        char file_name[128];
        memset(file_name, '\0', sizeof(file_name));
        LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+       if(packet == NULL){
+           return ret;
+       }
        memset(packet, 0, sizeof(LXT_MESSAGE));
 
        LOG("start sdcard umount");
@@ -312,31 +350,23 @@ int umount_sdcard(void)
                if ( ret == 0 )
                {
                        LOG( "%s is exist", file_name);
-                       ret = umount("/mnt/mmc");
-                       LOG("umount ret = %d, errno = %d", ret, errno);
-                       
                        LOG("sdcard fd: %d", g_sdcard_sockfd);
                        if(g_sdcard_sockfd != -1)
                        {
                                packet->length = strlen(SDpath);                // length
                                packet->group = 11;                             // sdcard
-                               if(ret == 0)
-                                       packet->action = 0;                             // unmounted
-                               else
-                                       packet->action = 4;                             // failed
+                               packet->action = 0;                             // unmounted
 
                                send(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
                                LOG("SDpath is %s", SDpath);
                                send(g_sdcard_sockfd, SDpath, packet->length, 0);
                                
-                               if(ret == 0)
                                {
                                        memset(SDpath, '\0', sizeof(SDpath));
                                        sprintf(SDpath, "umounted");
-                                       system("vconftool set -t int memory/sysman/mmc 0 -i -f");
-                               }                               
+                                       system("/usr/bin/sys_event mmcblk_remove");
+                               }
                        }
-
                        break;
                }
                else
@@ -345,8 +375,12 @@ int umount_sdcard(void)
                }
        }
 
+       if(packet){
+           free(packet);
+           packet = NULL;
+       }
        return ret;
-} 
+}
 
 void epoll_init(void)
 {
@@ -363,7 +397,7 @@ void epoll_init(void)
        LOG("[START] epoll creation success");
 
        /* event control set */
-       events.events = EPOLLIN;        // check In event
+       events.events = EPOLLIN; // check In event
        events.data.fd = g_svr_sockfd;
 
        /* server events set(read for accept) */
@@ -386,7 +420,7 @@ void epoll_cli_add(int cli_fd)
 
        /* event control set for read event */
        events.events = EPOLLIN;
-       events.data.fd = cli_fd; 
+       events.data.fd = cli_fd;
 
        if( epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, cli_fd, &events) < 0 )
        {
@@ -403,7 +437,10 @@ void userpool_add(int cli_fd, unsigned short cli_port)
        {
                if(g_client[i].cli_sockfd == -1) break;
        }
-       if( i >= MAX_CLIENT ) close(cli_fd);
+       if( i >= MAX_CLIENT ){
+           close(cli_fd);
+           return;
+       }
 
        LOG("g_client[%d].cli_port: %d", i, cli_port);
 
@@ -419,7 +456,7 @@ void userpool_delete(int cli_fd)
        {
                if(g_client[i].cli_sockfd == cli_fd)
                {
-                       g_client[i].cli_sockfd = -1;    
+                       g_client[i].cli_sockfd = -1;
                        break;
                }
        }
@@ -444,63 +481,123 @@ int parse_val(char *buff, unsigned char data, char *parsbuf)
        return 0;
 }
 
+#define STR_HELPER(x) #x
+#define STR(x) STR_HELPER(x)
+
 void udp_init(void)
 {
+       char emul_ip[HOST_NAME_MAX+1];
+       struct addrinfo *res;
+       struct addrinfo hints;
+       int rc;
+
        LOG("start");
-       char* emul_ip = getenv("HOSTNAME");
-       if(emul_ip == NULL)
+
+       memset(emul_ip, 0, sizeof(emul_ip));
+       if (gethostname(emul_ip, sizeof(emul_ip)) < 0)
+       {
+               LOG("gethostname(): %s", strerror(errno));
+               assert(0);
+       }
+
+       memset(&hints, 0, sizeof(hints));
+       hints.ai_family=AF_INET;
+       hints.ai_socktype=SOCK_DGRAM;
+       hints.ai_protocol=IPPROTO_UDP;
+
+       if ((rc=getaddrinfo(emul_ip, STR(SENSORD_PORT), &hints, &res)) != 0)
        {
-               LOG("emul_ip is null");
+               if (rc == EAI_SYSTEM)
+                       LOG("getaddrinfo(sensord): %s", strerror(errno));
+               else
+                       LOG("getaddrinfo(sensord): %s", gai_strerror(rc));
                assert(0);
        }
 
-       if ((uSensordFd=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1){
+       if ((uSensordFd=socket(res->ai_family, res->ai_socktype, res->ai_protocol))==-1){
                fprintf(stderr, "socket error!\n");
        }
 
+       if (res->ai_addrlen > sizeof(si_sensord_other))
+       {
+               LOG("sockaddr structure too big");
+               /* XXX: if you `return' remember to clean up */
+               assert(0);
+       }
        memset((char *) &si_sensord_other, 0, sizeof(si_sensord_other));
-       si_sensord_other.sin_family = AF_INET;
-       si_sensord_other.sin_port = htons(sensord_port);
-       if (inet_aton(emul_ip, &si_sensord_other.sin_addr)==0) {
-               fprintf(stderr, "inet_aton() failed\n");
+       memcpy((char *) &si_sensord_other, res->ai_addr, res->ai_addrlen);
+       freeaddrinfo(res);
+
+       if ((rc=getaddrinfo(emul_ip, STR(GPSD_PORT), &hints, &res)) != 0)
+       {
+               if (rc == EAI_SYSTEM)
+                       LOG("getaddrinfo(gpsd): %s", strerror(errno));
+               else
+                       LOG("getaddrinfo(gpsd): %s", gai_strerror(rc));
+               assert(0);
        }
 
-       if ((uGpsdFd=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1){
+       if ((uGpsdFd=socket(res->ai_family, res->ai_socktype, res->ai_protocol))==-1){
                fprintf(stderr, "socket error!\n");
        }
 
-       memset((char *) &si_gpsd_other, 0, sizeof(si_gpsd_other));
-       si_gpsd_other.sin_family = AF_INET;
-       si_gpsd_other.sin_port = htons(gpsd_port);
-       if (inet_aton(emul_ip, &si_gpsd_other.sin_addr)==0) {
-               fprintf(stderr, "inet_aton() failed\n");
+       if (res->ai_addrlen > sizeof(si_gpsd_other))
+       {
+               LOG("sockaddr structure too big");
+               assert(0);
        }
+       memset((char *) &si_gpsd_other, 0, sizeof(si_gpsd_other));
+       memcpy((char *) &si_gpsd_other, res->ai_addr, res->ai_addrlen);
+       freeaddrinfo(res);
 }
 
+#undef STR_HELPER
+#undef STR
+
 int recv_data(int event_fd, char** r_databuf, int size)
 {
        int recvd_size = 0;
        int len = 0;
        int getcnt = 0;
        char* r_tmpbuf = NULL;
+       const int alloc_size = sizeof(char) * size + 1;
+
+       r_tmpbuf = (char*)malloc(alloc_size);
+       if(r_tmpbuf == NULL)
+       {
+           return -1;
+       }
+
+       char* databuf = (char*)malloc(alloc_size);
+       if(databuf == NULL)
+       {
+           free(r_tmpbuf);
+           *r_databuf = NULL;
+           return -1;
+       }
 
-       r_tmpbuf = (char*)malloc(sizeof(char) * size + 1);
-       *r_databuf = (char*)malloc(sizeof(char) * size + 1);
-       memset(*r_databuf, '\0', sizeof(char) * size + 1);
+       memset(databuf, '\0', alloc_size);
 
        while(recvd_size < size)
        {
-               memset(r_tmpbuf, '\0', sizeof(char) * size);
+               memset(r_tmpbuf, '\0', alloc_size);
                len = recv(event_fd, r_tmpbuf, size - recvd_size, 0);
-               memcpy((*r_databuf) + recvd_size, r_tmpbuf, len);
+               if (len < 0) {
+                       break;
+               }
+
+               memcpy(databuf + recvd_size, r_tmpbuf, len);
                recvd_size += len;
                getcnt++;
-               if(getcnt > MAX_GETCNT)
+               if(getcnt > MAX_GETCNT) {
                        break;
+               }
        }
        free(r_tmpbuf);
        r_tmpbuf = NULL;
 
+       *r_databuf = databuf;
+
        return recvd_size;
 }
 
@@ -508,20 +605,6 @@ int powerdown_by_force()
 {
        struct timeval now;
        int poweroff_duration = POWEROFF_DURATION;
-       char *buf;
-
-       /* Getting poweroff duration */
-       buf = getenv("PWROFF_DUR");
-       if(buf == NULL)
-       {
-               LOG("PWROFF_DUR is null");
-               assert(0);
-       }
-       
-       if (strlen(buf) < 1024)
-               poweroff_duration = atoi(buf);
-       if (poweroff_duration < 0 || poweroff_duration > 60) 
-               poweroff_duration = POWEROFF_DURATION;
 
        gettimeofday(&now, NULL);
        /* Waiting until power off duration and displaying animation */
@@ -529,7 +612,7 @@ int powerdown_by_force()
                LOG("wait");
                usleep(100000);
                gettimeofday(&now, NULL);
-       }   
+       }
 
        LOG("Power off by force");
        LOG("sync");
@@ -544,21 +627,28 @@ void client_recv(int event_fd)
 {
        char* r_databuf = NULL;
        char tmpbuf[48];
-       int len, recvd_size, parse_len = 0;
+       int len = 0, recvd_size = 0, parse_len = 0;
+
+       if (event_fd == -1) {
+               LOG("invalid event fd");
+               return;
+       }
+
        LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
-       memset(packet, 0, sizeof(LXT_MESSAGE));
+       if (!packet)
+           return;
 
-       LOG("start");
-       /* there need to be more precise code here */ 
+       memset(packet, 0, sizeof(*packet));
+
+       LOG("start (event fd: %d)", event_fd);
+       /* there need to be more precise code here */
        /* for example , packet check(protocol needed) , real recv size check , etc. */
 
        // vmodem to event injector
        if(event_fd == g_vm_sockfd)
-       {       
+       {
                recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);
-
-               LOG("recv_len: %d, vmodem header recv buffer: %s", recvd_size, r_databuf);
-
+               LOG("receive size: %d", recvd_size);
                if(recvd_size <= 0)
                {
                        free(r_databuf);
@@ -567,63 +657,58 @@ void client_recv(int event_fd)
                        packet = NULL;
                        userpool_delete(event_fd);
                        close(event_fd); /* epoll set fd also deleted automatically by this call as a spec */
+
+                       set_vm_connect_status(0);
+
                        if(pthread_create(&tid[0], NULL, init_vm_connect, NULL) != 0)
                                LOG("pthread create fail!");
                        return;
                }
 
-               memcpy((void*)packet, (void*)r_databuf, sizeof(char) * HEADER_SIZE);
+               LOG("vmodem header recv buffer: %s", r_databuf);
+               memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);
 
                LOG("first packet of vmodem to event injector %s", r_databuf);
                free(r_databuf);
                r_databuf = NULL;
-               
-               if(g_sdbd_sockfd != -1)
-                       len = send(g_sdbd_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
-               else
-                       return;
-
-               LOG("send_len: %d, next packet length: %d", len, packet->length);
 
-               if(packet->length <= 0)
-               {
-                       free(packet);
-                       packet = NULL;
-                       return;
-               }       
-                       
                if(g_sdbd_sockfd != -1)
-                       recvd_size = recv_data(event_fd, &r_databuf, packet->length);
-               else
-                       return;
-
-               LOG("recv_len: %d, vmodem data recv buffer: %s", recvd_size, r_databuf);
-
-               if(recvd_size <= 0)
                {
-                       free(r_databuf);
-                       r_databuf = NULL;
-                       free(packet);
-                       packet = NULL;
-                       return;
+                       len = send(g_sdbd_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+                       LOG("send_len: %d, next packet length: %d", len, packet->length);
                }
-               len = send(g_sdbd_sockfd, r_databuf, packet->length, 0);
 
-               LOG("send_len: %d", len);
+               if (packet->length > 0)
+               {
+                       if (g_sdbd_sockfd != -1)
+                       {
+                               recvd_size = recv_data(event_fd, &r_databuf, packet->length);
+                               LOG("recv_len: %d, vmodem data recv buffer: %s", recvd_size, r_databuf);
+                               if (recvd_size > 0)
+                               {
+                                       len = send(g_sdbd_sockfd, r_databuf, packet->length, 0);
+                                       LOG("send_len: %d", len);
+                               }
+                       }
+                       else
+                       {
+                               // for packet clear
+                               recvd_size = recv_data(event_fd, &r_databuf, packet->length);
+                       }
+               }
        }
        else    // event injector to vmodem, sensord or gpsd
        {
                /* read from socket */
                // read identifier
                recvd_size = recv_data(event_fd, &r_databuf, ID_SIZE);
-
-               LOG("Something may be added in the data end, but it does not matter.");
-               LOG("identifier: %s", r_databuf);
-
+               LOG("receive size: %d", recvd_size);
                if( recvd_size <= 0 )
                {
                        free(r_databuf);
                        r_databuf = NULL;
+                       free(packet);
+                       packet = NULL;
                        LOG("close event_fd: %d", event_fd);
                        userpool_delete(event_fd);
                        close(event_fd); /* epoll set fd also deleted automatically by this call as a spec */
@@ -633,6 +718,9 @@ void client_recv(int event_fd)
                        return;
                }
 
+               LOG("Something may be added in the data end, but it does not matter.");
+               LOG("identifier: %s", r_databuf);
+
                memset(tmpbuf, '\0', sizeof(tmpbuf));
                parse_len = parse_val(r_databuf, 0x0a, tmpbuf);
 
@@ -646,12 +734,15 @@ void client_recv(int event_fd)
                if(strncmp(tmpbuf, "telephony", 9) == 0)
                {
                        g_sdbd_sockfd = event_fd;
-                       if(g_vm_connect_status != 1)    // The connection is lost with vmodem
+                       if(!is_vm_connected()) {        // The connection is lost with vmodem
+                               free(packet);
+                               packet = NULL;
                                return;
+                       }
 
-                       recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);                      
+                       recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);
                        len = send(g_vm_sockfd, r_databuf, HEADER_SIZE, 0);
-                       
+
                        memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);
 
                        LOG("next packet length: %d", packet->length);
@@ -661,7 +752,7 @@ void client_recv(int event_fd)
                        r_databuf = NULL;
 
                        if(packet->length == 0)
-                       {       
+                       {
                                if(packet->action == 71)        // that's strange packet from telephony initialize
                                {
                                        packet->length = 4;
@@ -672,31 +763,31 @@ void client_recv(int event_fd)
                                        packet = NULL;
                                        return;
                                }
-                       }                               
+                       }
 
-                       if(g_vm_connect_status != 1)    // The connection is lost with vmodem
+                       if(!is_vm_connected())  // The connection is lost with vmodem
                                return;
 
                        recvd_size = recv_data(event_fd, &r_databuf, packet->length);
 
-                       LOG("Something may be added in the data end, but it does not matter.");
-                       LOG("telephony data recv buffer: %s", r_databuf);
-
                        if(recvd_size <= 0)
                        {
                                free(r_databuf);
-                               r_databuf = NULL;                               
+                               r_databuf = NULL;
                                free(packet);
                                packet = NULL;
                                return;
-                       }
-                       else
+                       } else {
+                               LOG("Something may be added in the data end, but it does not matter.");
+                               LOG("telephony data recv buffer: %s", r_databuf);
+
                                len = send(g_vm_sockfd, r_databuf, packet->length, 0);
+                       }
                }
                else if(strncmp(tmpbuf, "sensor", 6) == 0)
                {
                        recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);
-                       memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);   
+                       memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);
 
                        LOG("sensor packet_length: %d", packet->length);
 
@@ -707,8 +798,20 @@ void client_recv(int event_fd)
                        LOG("Something may be added in the data end, but it does not matter.");
                        LOG("sensor data recv buffer: %s", r_databuf);
 
-                       if(sendto(uSensordFd, r_databuf, packet->length, 0, (struct sockaddr*)&si_sensord_other, sslen) == -1)     
+                       if (packet->group == STATUS) {
+                               g_get_status_sockfd = event_fd;
+                               ActionID = packet->action;
+                               memset(GetBuffer, '\0', sizeof(GetBuffer));
+                               strcpy(GetBuffer, r_databuf);
+                               LOG("GetBuffer is %s", GetBuffer);
+
+                               if(pthread_create(&tid[2], NULL, setting_device, NULL) != 0) {
+                                       LOG("pthread create fail!");
+                               }
+                       }
+                       else if(sendto(uSensordFd, r_databuf, packet->length, 0, (struct sockaddr*)&si_sensord_other, sslen) == -1) {
                                LOG("sendto error!");
+                       }
                }
                else if(strncmp(tmpbuf, "location", 8) == 0)
                {
@@ -724,59 +827,75 @@ void client_recv(int event_fd)
                        LOG("Something may be added in the data end, but it does not matter.");
                        LOG("location data recv buffer: %s", r_databuf);
 
-                       setting_location(r_databuf);
+                       if (packet->group == STATUS) {
+                               g_get_status_sockfd = event_fd;
+                               ActionID = packet->action;
+                               memset(GetBuffer, '\0', sizeof(GetBuffer));
+                               strcpy(GetBuffer, r_databuf);
+                               LOG("GetBuffer is %s", GetBuffer);
+
+                               if(pthread_create(&tid[2], NULL, setting_device, NULL) != 0) {
+                                       LOG("pthread create fail!");
+                               }
+                       } else {
+                               setting_location(r_databuf);
+                       }
                }
                else if(strncmp(tmpbuf, "nfc", 3) == 0)
                {
                        recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);
                        if( recvd_size <= 0 )
-                       {
-                               free(r_databuf);
-                               r_databuf = NULL;
-                               return;
-                       }
-                       /*
-                       LOG("nfc packet length r_databuf: %s", r_databuf);
-
-                               memset(tmpbuf, '\0', sizeof(tmpbuf));
-                       parse_len = parse_val(r_databuf, 0x0a, tmpbuf);
-
-                       int length = atoi(tmpbuf);
-                       */
-
-                       //byte to int
-                       int length = ((r_databuf[0] & 0xff) << 24 | (r_databuf[1] & 0xff) << 16
-                                       | (r_databuf[2] & 0xff) << 8 | (r_databuf[3] & 0xff)) ;
-                       LOG("nfc packet converted length: %d", length);
-                       free(r_databuf);
-                       r_databuf = NULL;
-
-                       recvd_size = recv_data(event_fd, &r_databuf, length);
-                       /*
-                       char* strbuf = NULL;
-                       strbuf = (char*)malloc(length + 1);
-                       memset(strbuf, '\0', length + 1);
-                       memcpy(strbuf, r_databuf, length);
-                       */
-                       LOG("nfc data recv buffer: %s", r_databuf);
-
-                       FILE* fd;
-                       fd = fopen("/opt/nfc/sdkMsg", "w");
-                       if(!fd)
                        {
-                               LOG("nfc file open fail!");
+                               free(r_databuf);
+                               r_databuf = NULL;
                                free(packet);
                                packet = NULL;
                                return;
                        }
-                       fprintf(fd, "%s", r_databuf);
-                       fclose(fd);
-                       //free(strbuf);
-                       //strbuf = NULL;
+
+                       memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);
+                       LOG("nfc packet_length: %d", packet->length);
+
+                       free(r_databuf);
+                       r_databuf = NULL;
+                       recvd_size = recv_data(event_fd, &r_databuf, packet->length);
+                       if(r_databuf == NULL){
+                           free(packet);
+                           packet = NULL;
+                           return;
+                       }
+                       LOG("nfc data recv buffer: %s", r_databuf);
+
+                       if (packet->group == STATUS) {
+                               g_get_status_sockfd = event_fd;
+                               ActionID = packet->action;
+                               memset(GetBuffer, '\0', sizeof(GetBuffer));
+                               strcpy(GetBuffer, r_databuf);
+                               LOG("GetBuffer is %s", GetBuffer);
+
+                               if(pthread_create(&tid[2], NULL, setting_device, NULL) != 0) {
+                                       LOG("pthread create fail!");
+                               }
+                       } else {
+                               FILE* fd;
+                               fd = fopen("/opt/nfc/sdkMsg", "w");
+                               if(!fd)
+                               {
+                                       LOG("nfc file open fail!");
+                                       free(r_databuf);
+                                       r_databuf = NULL;
+                                       free(packet);
+                                       packet = NULL;
+                                       return;
+                               }
+                               fprintf(fd, "%s", r_databuf);
+                               fclose(fd);
+                               //free(strbuf);
+                               //strbuf = NULL;
+                       }
                }
                else if(strncmp(tmpbuf, "system", 6) == 0)
                {
-
                        recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);
                        memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);
 
@@ -801,17 +920,34 @@ void client_recv(int event_fd)
                {
                        g_sdcard_sockfd = event_fd;
                        recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);
-                       memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);   
+                       memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);
 
                        LOG("sdcard packet_length: %d", packet->length);
 
                        free(r_databuf);
                        r_databuf = NULL;
                        recvd_size = recv_data(event_fd, &r_databuf, packet->length);
+                       if(recvd_size <= 0){
+                               LOG("client_recv: recv_data err");
+                               if(r_databuf) {
+                                       free(r_databuf);
+                                       r_databuf = NULL;
+                               }
+                               if(packet) {
+                                       free(packet);
+                                       packet = NULL;
+                               }
+                               LOG("close event_fd: %d", event_fd);
+                               userpool_delete(event_fd);
+                               close(event_fd); /* epoll set fd also deleted automatically by this call as a spec */
+                               if(event_fd == g_sdbd_sockfd)
+                                       g_sdbd_sockfd = -1;
+                               return;
+                       }
 
                        LOG("Something may be added in the data end, but it does not matter.");
                        LOG("sdcard data recv buffer: %s", r_databuf);
-                       
+
                        char token[] = "\n";
                        char tmpdata[recvd_size];
                        memcpy(tmpdata, r_databuf, recvd_size);
@@ -826,7 +962,7 @@ void client_recv(int event_fd)
                        {
                        case 0:                                                 // umount
                                mount_status = umount_sdcard();
-                               if(mount_status == 0)                           
+                               if(mount_status == 0)
                                        send_guest_server(r_databuf);
                                break;
                        case 1:                                                 // mount
@@ -843,6 +979,9 @@ void client_recv(int event_fd)
                                mount_status = is_mounted();
 
                                LXT_MESSAGE* mntData = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+                               if(mntData == NULL){
+                                   break;
+                               }
                                memset(mntData, 0, sizeof(LXT_MESSAGE));
 
                                mntData->length = strlen(SDpath);       // length
@@ -853,7 +992,7 @@ void client_recv(int event_fd)
                                case 0:
                                        mntData->action = 2;                    // umounted status
                                        send(g_sdcard_sockfd, (void*)mntData, sizeof(char) * HEADER_SIZE, 0);
-                                       
+
                                        LOG("SDpath is %s", SDpath);
                                        send(g_sdcard_sockfd, SDpath, mntData->length, 0);
                                        memset(SDpath, '\0', sizeof(SDpath));
@@ -869,12 +1008,13 @@ void client_recv(int event_fd)
                                default:
                                        break;
                                }
+                               free(mntData);
                                break;
                        default:
                                LOG("unknown data %s", ret);
                                break;
-                       }       
-               }               
+                       }
+               }
                else
                {
                        LOG("Unknown packet: %s", tmpbuf);
@@ -894,26 +1034,28 @@ void client_recv(int event_fd)
        }
 }
 
-void server_process(void)
+bool server_process(void)
 {
        struct sockaddr_in cli_addr;
        int i,nfds;
        int cli_sockfd;
        int cli_len = sizeof(cli_addr);
 
-       nfds = epoll_wait(g_epoll_fd,g_events,MAX_EVENTS,100); /* timeout 100ms */
+       nfds = epoll_wait(g_epoll_fd, g_events,MAX_EVENTS, 100); /* timeout 100ms */
 
        if(nfds == 0){
                /* no event , no work */
-               return;
+               return false;
        }
 
 
        if(nfds < 0) {
-               fprintf(stderr, "epoll wait error\n");
+               fprintf(stderr, "epoll wait %d\n", errno);
                /* return but this is epoll wait error */
-               return;
-       } 
+               if (errno == EINTR)
+                       return false;
+               return true;
+       }
 
        for( i = 0 ; i < nfds ; i++ )
        {
@@ -921,7 +1063,7 @@ void server_process(void)
                if(g_events[i].data.fd == g_svr_sockfd)
                {
                        cli_sockfd = accept(g_svr_sockfd, (struct sockaddr *)&cli_addr,(socklen_t *)&cli_len);
-                       if(cli_sockfd < 0) 
+                       if(cli_sockfd < 0)
                        {
                                /* accept error */
                                fprintf(stderr, "accept error\n");
@@ -944,8 +1086,10 @@ void server_process(void)
                }
                /* if not server socket , this socket is for client socket, so we read it */
 
-               client_recv(g_events[i].data.fd);    
+               client_recv(g_events[i].data.fd);
        } /* end of for 0-nfds */
+
+       return false;
 }
 /*------------------------------- end of function server_process */
 
@@ -959,6 +1103,119 @@ void end_server(int sig)
        exit(0);
 }
 
+void setting_device()
+{
+       pthread_detach(pthread_self());
+
+       char* msg = 0;
+       LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+
+       switch(ActionID)
+       {
+       case BATTERY_LEVEL:
+               msg = get_battery_level((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting battery level");
+               }
+       break;
+       case BATTERY_CHARGER:
+               msg = get_battery_charger((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting battery charger state");
+               }
+       break;
+       case USB_STATUS:
+               msg = get_usb_status((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting usb status");
+               }
+       break;
+       case EARJACK_STATUS:
+               msg = get_earjack_status((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting earjack status");
+               }
+       break;
+       case RSSI_LEVEL:
+               msg = get_rssi_level((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting rssi level");
+               }
+       break;
+       case ACCEL_VALUE:
+               msg = get_acceleration_value((void*)packet);
+               if (msg == 0) {
+                       LOG("falied getting acceleration value");
+               }
+       break;
+       case GYRO_VALUE:
+               msg = get_gyroscope_value((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting gyroscope value");
+               }
+       break;
+       case MAG_VALUE:
+               msg = get_magnetic_value((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting magnetic value");
+               }
+       break;
+       case LIGHT_VALUE:
+               msg = get_light_level((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting light level");
+               }
+       break;
+       case PROXI_VALUE:
+               msg = get_proximity_status((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting proximity status");
+               }
+       break;
+       case MOTION_VALUE:
+               LOG("not support getting motion value");
+       break;
+       case LOCATION_STATUS:
+               msg = get_location_status((void*)packet);
+               if (msg == 0) {
+                       LOG("failed getting location status");
+               }
+       break;
+       case NFC_STATUS:
+               msg = get_nfc_status((void*)packet);
+               if (msg ==0) {
+                       LOG("failed getting nfc status");
+               }
+       break;
+       default:
+               //TODO
+       break;
+       }
+
+       if (g_get_status_sockfd != -1) {
+               if (msg != 0) {
+                       LOG("send data to injector");
+               } else {
+                       LOG("send error message to injector");
+                       memset(packet, 0, sizeof(LXT_MESSAGE));
+                       packet->length = 0;
+                       packet->group  = STATUS;
+                       packet->action = ActionID;
+               }
+               send(g_get_status_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+               if (packet->length != 0) {
+                       send(g_get_status_sockfd, msg, packet->length, 0);
+               }
+       }
+
+       if(msg != 0) {
+               free(msg);
+       }
+       free(packet);
+
+       pthread_exit((void *) 0);
+}
+
 // location event
 char command[512];
 char latitude[128];
@@ -1022,10 +1279,16 @@ void setting_location(char* databuf)
 //sdcard event
 void send_guest_server(char* databuf)
 {
+       if (!databuf)
+       {
+               LOG("invalid data buf");
+               return;
+       }
+
        char buf[32];
        struct sockaddr_in si_other;
        int s, slen=sizeof(si_other);
-       FILE* fd;
+       FILE* fd;
        char fbuf[16];
        int port;
        fd = fopen("/opt/home/sdb_port.txt", "r");
@@ -1043,8 +1306,11 @@ void send_guest_server(char* databuf)
        }
 
        if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
-                 LOG("socket error!");
-           
+       {
+               LOG("socket error!");
+               return;
+       }
+
        memset((char *) &si_other, 0, sizeof(si_other));
        si_other.sin_family = AF_INET;
        si_other.sin_port = htons(port);
@@ -1053,18 +1319,21 @@ void send_guest_server(char* databuf)
        }
 
        memset(buf, '\0', sizeof(buf));
-       sprintf(buf, "4\n%s", databuf);
+       snprintf(buf, sizeof(buf), "4\n%s", databuf);
+
        LOG("sendGuestServer msg: %s", buf);
        if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
-       {     
+       {
                LOG("sendto error!");
        }
-       
+
        close(s);
 }
 
 int main( int argc , char *argv[])
 {
+       int state;
+
        if(log_print == 1)
        {
                // for emuld log file
@@ -1074,11 +1343,11 @@ int main( int argc , char *argv[])
 
        LOG("start");
        /* entry , argument check and process */
-       if(argc < 3){ 
+       if(argc < 3){
 
                g_svr_port = DEFAULT_PORT;
 
-       }else {
+       } else {
 
                if(strcmp("-port",argv[1]) ==  0 ) {
 
@@ -1086,25 +1355,33 @@ int main( int argc , char *argv[])
                        if(g_svr_port < 1024) {
                                fprintf(stderr, "[STOP] port number invalid : %d\n",g_svr_port);
                                exit(0);
-                       } 
+                       }
                }
        }
 
-       init_data0();   
+       init_data0();
 
        /* init server */
        init_server0(g_svr_port);
 
        epoll_init();    /* epoll initialize  */
+
+       set_vm_connect_status(0);
+
        if(pthread_create(&tid[0], NULL, init_vm_connect, NULL) != 0)
                LOG("pthread create fail!");
 
        udp_init();
 
+       bool is_exit = false;
        /* main loop */
-       while(1)
+       while(!is_exit)
        {
-               server_process();  /* accept process. */
+               is_exit = server_process();  /* accept process. */
        } /* infinite loop while end. */
+
+       state = pthread_mutex_destroy(&mutex_vmconnect);
+
+       fprintf(stderr, "emuld exit\n");
 }
 
diff --git a/src/get_status.c b/src/get_status.c
new file mode 100644 (file)
index 0000000..fb033d1
--- /dev/null
@@ -0,0 +1,397 @@
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsnung.com>
+ * Sungmin Ha <sungmin82.ha@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+//#include <vconf.h>
+#include "emuld_common.h"
+
+
+char* message;
+char* get_usb_status(void* p)
+{
+       FILE* fd = fopen("/sys/devices/platform/jack/usb_online", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int status = 0;
+       fscanf(fd, "%d", &status);
+       fclose(fd);
+
+       // int to byte
+       message = (char*)malloc(5);
+       message[3] = (char) (status & 0xff);
+       message[2] = (char) (status >> 8 & 0xff);
+       message[1] = (char) (status >> 16 & 0xff);
+       message[0] = (char) (status >> 24 & 0xff);
+       message[4] = '\0';
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = USB_STATUS;
+
+       return message;
+}
+
+char* get_earjack_status(void* p)
+{
+       FILE* fd = fopen("/sys/devices/platform/jack/earjack_online", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int status = 0;
+       fscanf(fd, "%d", &status);
+       fclose(fd);
+
+       // int to byte
+       message = (char*)malloc(5);
+       message[3] = (char) (status & 0xff);
+       message[2] = (char) (status >> 8 & 0xff);
+       message[1] = (char) (status >> 16 & 0xff);
+       message[0] = (char) (status >> 24 & 0xff);
+       message[4] = '\0';
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = EARJACK_STATUS;
+
+       return message;
+}
+
+char* get_rssi_level(void* p)
+{
+       int level;
+       int ret = vconf_get_int("memory/telephony/rssi", &level);
+       if (ret != 0) {
+               return 0;
+       }
+
+       // int to byte
+       message = (char*)malloc(5);
+       message[3] = (char) (level & 0xff);
+       message[2] = (char) (level >> 8 & 0xff);
+       message[1] = (char) (level >> 16 & 0xff);
+       message[0] = (char) (level >> 24 & 0xff);
+       message[4] = '\0';
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = RSSI_LEVEL;
+
+       return message;
+}
+
+char* get_battery_level(void* p)
+{
+       FILE* fd = fopen("/sys/class/power_supply/battery/capacity", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int level = 0;
+       fscanf(fd, "%d", &level);
+       fclose(fd);
+
+       // int to byte
+       message = (char*)malloc(5);
+       message[3] = (char) (level & 0xff);
+       message[2] = (char) (level >> 8 & 0xff);
+       message[1] = (char) (level >> 16 & 0xff);
+       message[0] = (char) (level >> 24 & 0xff);
+       message[4] = '\0';
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = BATTERY_LEVEL;
+
+       return message;
+}
+
+char* get_battery_charger(void* p)
+{
+       FILE* fd = fopen("/sys/class/power_supply/battery/charge_now", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int charge = 0;
+       fscanf(fd, "%d", &charge);
+       fclose(fd);
+       // int to byte
+       message = (char*)malloc(5);
+
+       message[3] = (char) (charge & 0xff);
+       message[2] = (char) (charge >> 8 & 0xff);
+       message[1] = (char) (charge >> 16 & 0xff);
+       message[0] = (char) (charge >> 24 & 0xff);
+       message[4] = '\0';
+       
+       LXT_MESSAGE* packet = p;        
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = BATTERY_CHARGER;
+
+       return message;
+}
+
+char* get_proximity_status(void* p)
+{
+       FILE* fd = fopen("/opt/sensor/proxi/vo", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int status = 0;
+       fscanf(fd, "%d", &status);
+       fclose(fd);
+       // int to byte
+       message = (char*)malloc(5);
+
+       message[3] = (char) (status & 0xff);
+       message[2] = (char) (status >> 8 & 0xff);
+       message[1] = (char) (status >> 16 & 0xff);
+       message[0] = (char) (status >> 24 & 0xff);
+       message[4] = '\0';
+       
+       LXT_MESSAGE* packet = p;        
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = PROXI_VALUE;
+
+       return message;
+}
+
+char* get_light_level(void* p)
+{
+       FILE* fd = fopen("/opt/sensor/light/adc", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       int level = 0;
+       fscanf(fd, "%d", &level);
+       fclose(fd);
+
+       // int to byte
+       message = (char*)malloc(5);
+       message[3] = (char) (level & 0xff);
+       message[2] = (char) (level >> 8 & 0xff);
+       message[1] = (char) (level >> 16 & 0xff);
+       message[0] = (char) (level >> 24 & 0xff);
+       message[4] = '\0';
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = 4;
+       packet->group  = STATUS;
+       packet->action = LIGHT_VALUE;
+
+       return message;
+}
+
+char* get_acceleration_value(void* p)
+{
+       FILE* fd = fopen("/opt/sensor/accel/xyz", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       message = (char*)malloc(128);
+       //fscanf(fd, "%d, %d, %d", message);
+       fgets(message, 128, fd);
+       fclose(fd);
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = strlen(message);
+       packet->group  = STATUS;
+       packet->action = ACCEL_VALUE;
+
+       return message;
+}
+
+char* get_gyroscope_value(void* p)
+{
+       int x;
+       int y;
+       int z;
+       FILE* fd = fopen("/opt/sensor/gyro/gyro_x_raw", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+       fscanf(fd, "%d", &x);
+       fclose(fd);
+
+       fd = fopen("/opt/sensor/gyro/gyro_y_raw", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+       fscanf(fd, "%d", &y);
+       fclose(fd);
+
+       fd = fopen("/opt/sensor/gyro/gyro_z_raw", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+       fscanf(fd, "%d", &z);
+       fclose(fd);
+       message = (char*)malloc(128);
+       memset(message, 0, 128);
+       int ret = sprintf(message, "%d, %d, %d", x, y, z);      
+       if (ret < 0) {
+               free(message);
+               return 0;
+       }
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = strlen(message);
+       packet->group  = STATUS;
+       packet->action = GYRO_VALUE;
+
+       return message;
+}
+
+char* get_magnetic_value(void* p)
+{
+       FILE* fd = fopen("/opt/sensor/geo/tesla", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       message = (char*)malloc(128);
+       fgets(message, 128, fd);
+       fclose(fd);
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = strlen(message);
+       packet->group  = STATUS;
+       packet->action = MAG_VALUE;
+       return message;
+}
+
+char* get_location_status(void* p)
+{
+       int mode;
+       int ret = vconf_get_int("db/location/replay/ReplayMode", &mode);
+       if (ret != 0) {
+               return 0;
+       }
+
+       if (mode == 0) { // STOP
+               message = (char*)malloc(5);
+               ret = sprintf(message, "%d", mode);
+               if (ret < 0) {
+                       free(message);
+                       return 0;
+               }
+       } else if (mode == 1) { // NMEA MODE(LOG MODE)
+               //char* temp = (char*)malloc(128);
+               char* temp = 0;
+               temp = vconf_get_str("db/location/replay/FileName");
+               if (temp == 0) {
+                       //free(temp);
+                       return 0;
+               }
+
+               message = (char*)malloc(256);
+               ret = sprintf(message, "%d,%s", mode, temp);
+               if (ret < 0) {
+                       free(message);
+                       return 0;
+               }
+       } else if (mode == 2) { // MANUAL MODE
+               double latitude;
+               double logitude;
+               ret = vconf_get_dbl("db/location/replay/ManualLatitude", &latitude);
+               if (ret != 0) {
+                       return 0;
+               }
+               ret = vconf_get_dbl("db/location/replay/ManualLongitude", &logitude);
+               if (ret != 0) {
+                       return 0;
+               }
+               message = (char*)malloc(128);
+               ret = sprintf(message, "%d,%f,%f", mode, latitude, logitude);
+               if (ret < 0) {
+                       free(message);
+                       return 0;
+               }
+       }
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = strlen(message);
+       packet->group  = STATUS;
+       packet->action = LOCATION_STATUS;
+
+       return message;
+}
+
+char* get_nfc_status(void* p)
+{
+       FILE* fd = fopen("/opt/nfc/sdkMsg", "r");
+       if(!fd)
+       {
+               return 0;
+       }
+
+       message = (char*)malloc(5000);
+       fscanf(fd, "%s\n", message);
+       fclose(fd);
+
+       LXT_MESSAGE* packet = p;
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+       packet->length = strlen(message);
+       packet->group  = STATUS;
+       packet->action = NFC_STATUS;
+
+       return message;
+}