ADDITION: sensor daemon migration & log format changed 96/17096/4
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Tue, 4 Mar 2014 02:27:34 +0000 (11:27 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Tue, 4 Mar 2014 04:28:32 +0000 (13:28 +0900)
- sensor daemon src is merged into emulator daemon source
- dlog is used for log system
- cmake refactoring

Change-Id: Ifba82b0cef09f3140a5a0304a878d84a095f2a43
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
12 files changed:
CMakeLists.txt
include/emuld.h
include/emuld_common.h
include/log.h [deleted file]
packaging/emuld.spec
src/client.cpp
src/device.cpp [new file with mode: 0644]
src/emuld.cpp
src/emuld_proc.cpp
src/evdi.cpp
src/get_status.cpp
src/log.cpp [deleted file]

index 4730ffd3db72820862f8ad9f892b6af3fc640b48..d82f47b489fb34ab2816fe29b59e40f2814bb77c 100644 (file)
@@ -7,36 +7,38 @@ SET(EXEC_PREFIX "\${prefix}")
 SET(INCLUDEDIR "\${prefix}/include")
 SET(VERSION 1.1)
 
-#include(FindPkgConfig)
-#pkg_check_modules(rpkgs REQUIRED ecore-x)
-#add_definitions(${rpkgs_CFLAGS} -DUSE_ONLY_ONE_MODULE)
-
 set(PROJECT_MAJOR_VERSION "1")
 set(PROJECT_MINOR_VERSION "1")
 set(PROJECT_RELEASE_VERSION "0")
 set(CMAKE_VERBOSE_MAKEFILE OFF)
 
-# does not check target type (SIMUL/REAL)
-#FIND_PROGRAM(UNAME NAMES uname)
-#EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
-#IF("${ARCH}" STREQUAL "arm")
-#   ADD_DEFINITIONS("-DTARGET -DHWREV_CHECK")
-#   MESSAGE("add -DTARGET")
-#ELSE("${ARCH}" STREQUAL "arm")
-#   ADD_DEFINITIONS("-DSIMULATOR")
-#   MESSAGE("add -DSIMULATOR")
-#ENDIF("${ARCH}" STREQUAL "arm")
-
-ADD_DEFINITIONS("-DTARGET -DHWREV_CHECK")
-
-#add_definitions(-D_ESTIMATE_PERFORMANCE)
-#add_definitions(-D_DEFAULT_FONT_NAME="Vera")
-add_definitions(-Werror -Wall -O3 -omit-frame-pointer)
-#add_definitions(-Wall -g -D_DEBUG)
-add_definitions(-Iinclude)
-ADD_EXECUTABLE(${PROJECT_NAME} src/emuld.cpp src/evdi.cpp src/emuld_proc.cpp src/client.cpp src/get_status.cpp src/log.cpp)
-
-target_link_libraries(${PROJECT_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} "-lpthread -lvconf -lpmapi" )
-
-install(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin)
+SET(SRCS
+    src/emuld.cpp
+    src/evdi.cpp
+    src/emuld_proc.cpp
+    src/client.cpp
+    src/get_status.cpp
+    src/device.cpp
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
+INCLUDE(FindPkgConfig)
+
+SET(PKG_MODULE
+    vconf
+    dlog
+    pmapi
+)
+
+pkg_check_modules(PKGS REQUIRED ${PKG_MODULE})
+
+ADD_DEFINITIONS("-DENABLE_DLOG_OUT")
+
+ADD_DEFINITIONS(-Werror -Wall -O3 -omit-frame-pointer)
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS})
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin)
index 052b9a36a7e393e7460e7adff3eb36fe8f6b1649..dc2d26194293e12ea6ba2ae417914aaeb15cfd0d 100644 (file)
@@ -54,7 +54,6 @@
 #include <queue>
 #include <map>
 
-#include "log.h"
 #include "emuld_common.h"
 #include "evdi_protocol.h"
 #include "evdi.h"
 #define MAX_CLIENT          10000
 #define MAX_EVENTS          10000
 #define MAX_GETCNT          10
-#define SDBD_PORT           26101
 #define DEFAULT_PORT        3577
 #define VMODEM_PORT         3578
-#define GPSD_PORT           3579
-#define SENSORD_PORT        3580
 #define SRV_IP              "10.0.2.2"
 #define ID_SIZE             10
 #define HEADER_SIZE         4
@@ -86,7 +82,6 @@ enum
     fdtype_device = 1,
     fdtype_vmodem = 2,
     fdtype_ij     = 3,
-    fdtype_sensor = 4, //udp
     fdtype_max    = 5
 };
 
@@ -94,50 +89,38 @@ extern pthread_t tid[MAX_CLIENT + 1];
 extern struct sockaddr_in si_sensord_other;
 extern int g_fd[fdtype_max];
 
+#if defined(ENABLE_DLOG_OUT)
+#  define LOG_TAG           "EMULATOR_DAEMON"
+#  include <dlog/dlog.h>
+#  define LOGINFO LOGI
+#  define LOGERR LOGE
+#  define LOGDEBUG LOGD
+#else
+#  define LOGINFO(fmt, arg...)
+#  define LOGERR(fmt, arg...)
+#  define LOGDEBUG(fmt, arg...)
+#endif
 
 #define IJTYPE_TELEPHONY    "telephony"
 #define IJTYPE_SDCARD       "sdcard"
 #define IJTYPE_SUSPEND      "suspend"
 
+int parse_val(char *buff, unsigned char data, char *parsbuf);
+
+bool is_vm_connected(void);
 bool epoll_ctl_add(const int fd);
 
 void userpool_add(int cli_fd, unsigned short cli_port, const int fdtype);
 void userpool_delete(int cli_fd);
 
-bool epoll_init(void);            /* epoll fd create */
-bool epoll_ctl_add(const int fd);
-
-void init_data0(void);            /* initialize data. */
-bool init_server0(int svr_port, int* ret_fd);
-void end_server(int sig);
-
 void udp_init(void);
-void emuld_ready(void);
-
-bool server_process(void);
-bool accept_proc(const int server_fd);
-
-int recv_data(int event_fd, char** r_databuf, int size);
-int parse_val(char *buff, unsigned char data, char *parsbuf);
-
-void set_vm_connect_status(const int v);
-bool is_vm_connected(void);
-
-void* init_vm_connect(void* data);
 
 void systemcall(const char* param);
 
-void recv_from_evdi(evdi_fd fd);
-
 int powerdown_by_force(void);
 // location
 void setting_location(char* databuf);
 
-#define LOG(fmt, arg...) \
-    do { \
-        log_print_out("[%s:%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); \
-    } while (0)
-
 #include <map>
 
 typedef unsigned short  CliSN;
index 638651a82331799db215f2cc66efe70bd67619b6..b592519a8ee3f3cca27b1c6191cbe353838978d2 100644 (file)
@@ -89,6 +89,8 @@ char* get_usb_status(void* , bool);
 char* get_earjack_status(void* , bool);
 char* get_rssi_level(void* , bool);
 
+void device_parser(char*);
+
 // Sensor
 char* get_proximity_status(void* , bool);
 char* get_light_level(void* , bool);
diff --git a/include/log.h b/include/log.h
deleted file mode 100644 (file)
index 675388f..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * emulator-daemon
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Jinhyung Choi <jinhyung2.choi@samsnung.com>
- * SooYoung Ha <yoosah.ha@samsnung.com>
- * Sungmin Ha <sungmin82.ha@samsung.com>
- * Daiyoung Kim <daiyoung777.kim@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
- *
- */
-
-
-#ifndef __log_h__
-#define __log_h__
-
-
-void make_timestamp(char* ret);
-void log_print_out(const char *fmt, ...);
-
-
-
-#endif
index ea6703387e6f91036f1a1566dcb99619f4c364b5..54808d273273a0b90bc9038995feefd2870be69c 100644 (file)
@@ -1,5 +1,5 @@
 Name: emuld
-Version: 0.4.1
+Version: 0.4.2
 Release: 0
 Summary: Emulator daemon
 License: Apache-2.0
@@ -8,10 +8,11 @@ Group: SDK/Other
 Source1001: packaging/emuld.manifest
 BuildRequires: cmake
 BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(pmapi)
 
 %description
-A emulator daemon is used for communication emulator between and ide.
+A emulator daemon is used for communication between guest and host
 
 %prep
 %setup -q
@@ -24,24 +25,13 @@ 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
-
 mkdir -p %{buildroot}/usr/share/license
 cp LICENSE %{buildroot}/usr/share/license/%{name}
 
@@ -57,8 +47,6 @@ rm -rf install_manifest.txt
 
 %post
 chmod 770 %{_prefix}/bin/emuld
-mkdir -p /opt/nfc
-touch /opt/nfc/sdkMsg
 
 %files
 %defattr(-,root,root,-)
@@ -66,7 +54,5 @@ touch /opt/nfc/sdkMsg
 /usr/share/license/%{name}
 /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 2fd0e9b1bed53c4371a3ca71000f7e643c1bc699..d7cb55df54a4d0f098fdbf0aea77e2c44ef5aeec 100644 (file)
@@ -51,7 +51,7 @@ void clipool_add(int fd, unsigned short port, const int fdtype)
     if (!g_climap.insert(CliMap::value_type(fd, cli)).second)
         return;
 
-    LOG("clipool_add fd = %d, port = %d, type = %d \n", fd, port, fdtype);
+    LOGINFO("clipool_add fd = %d, port = %d, type = %d", fd, port, fdtype);
 }
 
 
@@ -79,7 +79,7 @@ void clipool_delete(int fd)
         }
     }
 
-    LOG("clipool_delete fd = %d\n", fd);
+    LOGINFO("clipool_delete fd = %d", fd);
 }
 
 
@@ -130,10 +130,10 @@ bool send_to_all_ij(char* data, const int len)
         result = (sent == -1) ? false : true;
         if (sent == -1)
         {
-            perror("failed to send to ij\n");
+            LOGERR("failed to send to ij");
         }
 
-        LOG("send_len: %d, err= %d\n", sent, errno);
+        LOGDEBUG("send_len: %d, err= %d", sent, errno);
     }
     return result;
 }
diff --git a/src/device.cpp b/src/device.cpp
new file mode 100644 (file)
index 0000000..4b87ed7
--- /dev/null
@@ -0,0 +1,1136 @@
+/* 
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Jinhyung Choi <jinhyung2.choi@samsnung.com>
+ * 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 <assert.h>
+#include <limits.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <pthread.h>
+#include <stdarg.h>
+
+#define SENSOR_DEBUG
+
+#include "emuld.h"
+#include "emuld_proc.h"
+
+static int battery_level = 50;
+pthread_t d_tid[16];
+
+struct appdata
+{
+    void* data;
+};
+struct appdata ad;
+
+typedef struct
+{
+    int len;
+    int repeatCnt;
+    int fileCnt;
+    char *buffer;
+} FileInput_args;
+
+typedef struct
+{
+    char filename[256];
+} FileInput_files;
+
+enum sensor_type{
+    MOTION = 6,
+    USBKEYBOARD = 7,
+    BATTERYLEVEL = 8,
+    EARJACK = 9,
+    USB = 10,
+    RSSI = 11,
+    FILE_ACCEL = 14,
+    FILE_MAGNETIC = 15,
+    FILE_GYRO = 16
+};
+
+enum motion_doubletap{
+    SENSOR_MOTION_DOUBLETAP_NONE = 0,
+    SENSOR_MOTION_DOUBLETAP_DETECTION = 1
+};
+
+enum motion_shake{
+    SENSOR_MOTION_SHAKE_NONE = 0,
+    SENSOR_MOTION_SHAKE_DETECTED = 1,
+    SENSOR_MOTION_SHAKE_CONTINUING  = 2,
+    SENSOR_MOTION_SHAKE_FINISHED = 3,
+    SENSOR_MOTION_SHAKE_BREAK = 4
+};
+
+enum motion_snap{
+    SENSOR_MOTION_SNAP_NONE = 0,
+    SENSOR_MOTION_SNAP_NEGATIVE_X = 1,
+    SENSOR_MOTION_SNAP_POSITIVE_X = 2,
+    SENSOR_MOTION_SNAP_NEGATIVE_Y = 3,
+    SENSOR_MOTION_SNAP_POSITIVE_Y = 4,
+    SENSOR_MOTION_SNAP_NEGATIVE_Z = 5,
+    SENSOR_MOTION_SNAP_POSITIVE_Z = 6,
+    SENSOR_MOTION_SNAP_LEFT = SENSOR_MOTION_SNAP_NEGATIVE_X,
+    SENSOR_MOTION_SNAP_RIGHT = SENSOR_MOTION_SNAP_POSITIVE_X
+};
+
+enum motion_move{
+    SENSOR_MOTION_MOVE_NONE = 0,
+    SENSOR_MOTION_MOVE_MOVETOCALL = 1
+};
+
+#define PATH_SENSOR_ACCEL_XYZ       "/sys/devices/virtual/sensor/accel/xyz"
+#define PATH_SENSOR_PROXI_VO        "/sys/devices/virtual/sensor/proxi/vo"
+#define PATH_SENSOR_LIGHT_ADC       "/sys/devices/virtual/sensor/light/adc"
+#define PATH_SENSOR_LIGHT_LEVEL     "/sys/devices/virtual/sensor/light/level"
+#define PATH_SENSOR_GEO_RAW         "/sys/devices/virtual/sensor/geo/raw"
+#define PATH_SENSOR_GEO_TESLA       "/sys/devices/virtual/sensor/geo/tesla"
+#define PATH_SENSOR_GYRO_X_RAW      "/sys/devices/virtual/sensor/gyro/gyro_x_raw"
+#define PATH_SENSOR_GYRO_Y_RAW      "/sys/devices/virtual/sensor/gyro/gyro_y_raw"
+#define PATH_SENSOR_GYRO_Z_RAW      "/sys/devices/virtual/sensor/gyro/gyro_z_raw"
+
+int check_nodes();
+
+int parse_motion_data(int len, char *buffer);
+int parse_usbkeyboard_data(int len, char *buffer);
+int parse_batterylevel_data(int len, char *buffer);
+int parse_earjack_data(int len, char *buffer);
+int parse_usb_data(int len, char *buffer);
+int parse_rssi_data(int len, char *buffer);
+
+static void system_msg(const char* msg)
+{
+    int ret = system(msg);
+    if (ret == -1) {
+        LOGERR("system command is failed: %s", msg);
+    }
+}
+
+int parse_motion_data(int len, char *buffer)
+{
+    int len1=0;
+    char tmpbuf[255];
+    int x;
+    char command[128];
+    memset(command, '\0', sizeof(command));
+
+    LOGDEBUG("read data: %s", buffer);
+
+    // read param count
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    /* first data */
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    x = atoi(tmpbuf);
+
+    switch(x)
+    {
+    case 1: // double tap
+        sprintf(command, "vconftool set -t int memory/private/sensor/800004 %d -i -f", SENSOR_MOTION_DOUBLETAP_DETECTION);
+        system_msg(command);
+    //  memset(command, '\0', sizeof(command));
+    //  sprintf(command, "vconftool set -t int memory/private/sensor/800004 %d -i -f", SENSOR_MOTION_DOUBLETAP_NONE);
+    //  system_msg(command);
+        break;
+    case 2: // shake start
+        sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_DETECTED);
+        system_msg(command);
+        memset(command, '\0', sizeof(command));
+        sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_CONTINUING);
+        system_msg(command);
+        break;
+    case 3: // shake stop
+        sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_FINISHED);
+        system_msg(command);
+        break;
+    case 4: // snap x+
+        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_X);
+        system_msg(command);
+        break;
+    case 5: // snap x-
+        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_X);
+        system_msg(command);
+        break;
+    case 6: // snap y+
+        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_Y);
+        system_msg(command);
+        break;
+    case 7: // snap y-
+        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_Y);
+        system_msg(command);
+        break;
+    case 8: // snap z+
+        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_Z);
+        system_msg(command);
+        break;
+    case 9: // snap z-
+        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_Z);
+        system_msg(command);
+        break;
+    case 10: // snap left
+        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_X);
+        system_msg(command);
+        break;
+    case 11: // snap right
+        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_X);
+        system_msg(command);
+        break;
+    case 12: // move to call (direct call)
+        sprintf(command, "vconftool set -t int memory/private/sensor/800020 %d -i -f", SENSOR_MOTION_MOVE_MOVETOCALL);
+        system_msg(command);
+        break;
+    default:
+        LOGERR("not supported activity");
+        break;
+    }
+
+    return 0;
+}
+
+int parse_usbkeyboard_data(int len, char *buffer)
+{
+    int len1=0;
+    char tmpbuf[255];
+    int x;
+
+    LOGDEBUG("read data: %s", buffer);
+
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    x = atoi(tmpbuf);
+
+    if(x == 1)
+    {
+        system_msg("udevadm trigger --subsystem-match=input --sysname-match=event3 --action=add");
+    }
+    else if(x == 0)
+    {
+        system_msg("udevadm trigger --subsystem-match=input --sysname-match=event3 --action=remove");
+    }
+    else
+        assert(0);
+
+    return 0;
+}
+
+int parse_batterylevel_data(int len, char *buffer)
+{
+    int len1=0, id = 0, ret = 0;
+    char tmpbuf[255];
+    int level = 0, charger = 0, charger_online = 0, charge_full = 0;
+    FILE* fd;
+
+    LOGDEBUG("read data: %s", buffer);
+
+    // read param count
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    /* first data */
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    id = atoi(tmpbuf);
+    if(id == 1) // level
+    {
+        memset(tmpbuf, '\0', sizeof(tmpbuf));
+        len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+        len += len1;
+
+        level = atoi(tmpbuf);
+        battery_level = level;
+
+        if(level == 100)
+        {
+            charger = 0;
+        }
+        else
+        {
+            charger = 1;
+        }
+
+        fd = fopen("/sys/class/power_supply/battery/capacity", "w");
+        if(!fd)
+        {
+            LOGERR("fopen fail");
+            return -1;
+        }
+        fprintf(fd, "%d", level);
+        fclose(fd);
+
+        fd = fopen("/sys/devices/platform/jack/charger_online", "r");
+        if(!fd)
+        {
+            LOGERR("fopen fail");
+            return -1;
+        }
+        ret = fscanf(fd, "%d", &charger_online);
+        fclose(fd);
+        if (ret < 0)
+        {
+            LOGERR("failed to get charger_online value");
+            return -1;
+        }
+
+        LOGDEBUG("charge_online: %d", charger_online);
+
+        if(charger_online == 1 && level == 100)
+        {
+            charge_full = 1;
+        }
+        else
+        {
+            charge_full = 0;
+        }
+        LOGDEBUG("charge_full: %d", charge_full);
+
+        fd = fopen("/sys/class/power_supply/battery/charge_full", "w");
+        if(!fd)
+        {
+            LOGERR("charge_full fopen fail");
+            return -1;
+        }
+        fprintf(fd, "%d", charge_full);
+        fclose(fd);
+
+        if(charger_online == 1)
+        {
+            fd = fopen("/sys/class/power_supply/battery/charge_now", "w");
+            if(!fd)
+            {
+                LOGERR("charge_now fopen fail");
+                return -1;
+            }
+            fprintf(fd, "%d", charger);
+            fclose(fd);
+        }
+
+        // because time based polling
+        system_msg("/usr/bin/sys_event device_charge_chgdet");
+    }
+    else if(id == 2)
+    {
+        /* second data */
+        memset(tmpbuf, '\0', sizeof(tmpbuf));
+        len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+        len += len1;
+
+        charger = atoi(tmpbuf);
+        fd = fopen("/sys/devices/platform/jack/charger_online", "w");
+        if(!fd)
+        {
+            LOGERR("charger_online fopen fail");
+            return -1;
+        }
+        fprintf(fd, "%d", charger);
+        fclose(fd);
+
+        fd = fopen("/sys/class/power_supply/battery/charge_full", "w");
+        if(!fd)
+        {
+            LOGERR("charge_full fopen fail");
+            return -1;
+        }
+
+        if(battery_level == 100 && charger == 1)
+        {
+            fprintf(fd, "%d", 1);   // charge full
+            charger = 0;
+        }
+        else
+        {
+            fprintf(fd, "%d", 0);
+        }
+        fclose(fd);
+
+        system_msg("/usr/bin/sys_event device_charge_chgdet");
+
+        fd = fopen("/sys/class/power_supply/battery/charge_now", "w");
+        if(!fd)
+        {
+            LOGERR("charge_now fopen fail");
+            return -1;
+        }
+        fprintf(fd, "%d", charger);
+        fclose(fd);
+
+        // because time based polling
+        system_msg("/usr/bin/sys_event device_ta_chgdet");
+    }
+
+    return 0;
+}
+
+int parse_earjack_data(int len, char *buffer)
+{
+    int len1=0;
+    char tmpbuf[255];
+    int x;
+    FILE* fd;
+
+    LOGDEBUG("read data: %s", buffer);
+
+    // read param count
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    /* first data */
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    x = atoi(tmpbuf);
+
+    fd = fopen("/sys/devices/platform/jack/earjack_online", "w");
+    if(!fd)
+    {
+        LOGERR("earjack_online fopen fail");
+        return -1;
+    }
+    fprintf(fd, "%d", x);
+    fclose(fd);
+
+    // because time based polling
+    system_msg("/usr/bin/sys_event device_earjack_chgdet");
+
+    return 0;
+}
+
+int parse_usb_data(int len, char *buffer)
+{
+    int len1=0;
+    char tmpbuf[255];
+    int x;
+    FILE* fd;
+
+    LOGDEBUG("read data: %s", buffer);
+
+    // read param count
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    /* first data */
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    x = atoi(tmpbuf);
+
+    fd = fopen("/sys/devices/platform/jack/usb_online", "w");
+    if(!fd)
+    {
+        LOGERR("usb_online fopen fail");
+        return -1;
+    }
+    fprintf(fd, "%d", x);
+    fclose(fd);
+
+    // because time based polling
+    system_msg("/usr/bin/sys_event device_usb_chgdet");
+    return 0;
+}
+
+int parse_rssi_data(int len, char *buffer)
+{
+    int len1=0;
+    char tmpbuf[255];
+    int x;
+    char command[128];
+    memset(command, '\0', sizeof(command));
+
+    LOGDEBUG("read data: %s", buffer);
+
+    // read param count
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    /* first data */
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    x = atoi(tmpbuf);
+
+    sprintf(command, "vconftool set -t int memory/telephony/rssi %d -i -f", x);
+    system_msg(command);
+
+    return 0;
+}
+
+void* file_input_accel(void* param)
+{
+    FILE* srcFD;
+    FILE* dstFD;
+
+    int len1 = 0, fileCnt = 0, repeatCnt = 0, prevTime = 0, nextTime = 0, sleepTime = 0, x, y, z;
+    int waitCnt = 0;
+    double g = 9.80665;
+
+    char tmpbuf[255];
+    char token[] = ",";
+    char* ret = NULL;
+    char command[255];
+    char lineData[1024];
+
+    FileInput_args* args = (FileInput_args*)param;
+    FileInput_files fname[args->fileCnt];
+    memset(fname, '\0', sizeof(fname));
+
+    pthread_detach(pthread_self());
+
+    LOGINFO("file_input_accel start");
+
+    // save file names
+    for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
+    {
+        memset(tmpbuf, '\0', sizeof(tmpbuf));
+        len1 = parse_val(args->buffer+args->len, 0x0a, tmpbuf);
+        args->len += len1;
+
+        strcpy(fname[fileCnt].filename, tmpbuf);
+        LOGINFO("saved file name: %s", fname[fileCnt].filename);
+    }
+
+    // play files
+    for(repeatCnt = 0; repeatCnt < args->repeatCnt; repeatCnt++)
+    {
+        for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
+        {
+            memset(command, '\0', sizeof(command));
+            sprintf(command, "/tmp/accel/InputFiles/%s", fname[fileCnt].filename);
+            command[strlen(command) - 1] = 0x00;    // erase '\n' for fopen
+            LOGINFO("fopen command: %s", command);
+
+            waitCnt = 0;
+            while(access(command, F_OK) != 0 && waitCnt < 3)
+            {
+                usleep(10000);
+                waitCnt++;
+            }
+
+            srcFD = fopen(command, "r");
+            if(!srcFD)
+            {
+                LOGINFO("fopen fail");
+                pthread_exit((void *) 0);
+            }
+
+            prevTime = 0;
+            nextTime = 0;
+
+            memset(lineData, '\0', sizeof(lineData));
+            while(fgets(lineData, 1024, srcFD) != NULL)
+            {
+                ret = strtok(lineData, token);
+                if(!ret)
+                {
+                    LOGINFO("data is NULL");
+                    nextTime = prevTime + 1;
+                }
+                else
+                    nextTime = atoi(ret);
+
+                sleepTime = (nextTime - prevTime) * 10000;
+                if(sleepTime < 0)
+                {
+                    sleepTime = 10000;
+                    nextTime = prevTime + 1;
+                }
+
+                usleep(sleepTime);  // convert millisecond
+                prevTime = nextTime;
+
+                ret = strtok(NULL, token);
+                if(!ret)
+                {
+                    LOGINFO("x data is NULL");
+                    x = 0;
+                }
+                else
+                    x = (int)(atof(ret) * g * -100000);
+
+                if (x > 1961330)
+                    x = 1961330;
+                if (x < -1961330)
+                    x = -1961330;
+                LOGINFO("x: %d", x);
+
+                ret = strtok(NULL, token);
+                if(!ret)
+                {
+                    LOGINFO("y data is NULL");
+                    y = 0;
+                }
+                else
+                    y = (int)(atof(ret) * g * -100000);
+
+                if (y > 1961330)
+                    y = 1961330;
+                if (y < -1961330)
+                    y = -1961330;
+                LOGINFO("y: %d", y);
+
+                ret = strtok(NULL, token);
+                if(!ret)
+                {
+                    LOGINFO("data is NULL");
+                    z = 0;
+                }
+                else
+                    z = (int)(atof(ret) * g * -100000);
+
+                if (z > 1961330)
+                    z = 1961330;
+                if (z < -1961330)
+                    z = -1961330;
+                LOGINFO("z: %d", z);
+
+                dstFD = fopen("/opt/sensor/accel/xyz", "w");
+                if(!dstFD)
+                {
+                    LOGINFO("fopen fail");
+                    pthread_exit((void *) 0);
+                }
+                fprintf(dstFD, "%d, %d, %d",x, y, z);
+                fclose(dstFD);
+            }
+
+            fclose(srcFD);
+        }
+    }
+
+    LOGINFO("thread exit");
+    system_msg("rm -rf /tmp/accel/InputFiles/*");
+
+    pthread_exit((void *) 0);
+}
+
+int parse_file_accel_data(int len, char *buffer)
+{
+    int len1=0, repeat = -1;
+    char tmpbuf[255];
+
+    LOGDEBUG("read data: %s", buffer);
+
+    // read start/stop
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    repeat = atoi(tmpbuf);
+
+    pthread_cancel(d_tid[0]);
+
+    if(repeat == 0) // stop
+    {
+        system_msg("rm -rf /tmp/accel/InputFiles/*");
+    }
+    else            // start
+    {
+        // read file count
+        memset(tmpbuf, '\0', sizeof(tmpbuf));
+        len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+        len += len1;
+
+        FileInput_args args;
+        args.len = len;
+        args.repeatCnt = repeat;
+        args.fileCnt = atoi(tmpbuf);
+        args.buffer = buffer;
+        if(pthread_create(&d_tid[0], NULL, file_input_accel, &args) != 0) {
+            LOGERR("pthread create fail!");
+        }
+    }
+
+    return 0;
+}
+
+void* file_input_magnetic(void* param)
+{
+    FILE* srcFD;
+    FILE* dstFD;
+
+    int len1 = 0, fileCnt = 0, repeatCnt = 0, prevTime = 0, nextTime = 0, sleepTime = 0, x, y, z;
+    int waitCnt = 0;
+
+    char tmpbuf[255];
+    char token[] = ",";
+    char* ret = NULL;
+    char command[255];
+    char lineData[1024];
+    FileInput_args* args = (FileInput_args*) param;
+    FileInput_files fname[args->fileCnt];
+    memset(fname, '\0', sizeof(fname));
+
+    pthread_detach(pthread_self());
+
+    LOGINFO("file_input_magnetic start");
+
+    // save file names
+    for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
+    {
+        memset(tmpbuf, '\0', sizeof(tmpbuf));
+        len1 = parse_val(args->buffer+args->len, 0x0a, tmpbuf);
+        args->len += len1;
+
+        strcpy(fname[fileCnt].filename, tmpbuf);
+        LOGINFO("saved file name: %s", fname[fileCnt].filename);
+    }
+
+    // play files
+    for(repeatCnt = 0; repeatCnt < args->repeatCnt; repeatCnt++)
+    {
+        for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
+        {
+            memset(command, '\0', sizeof(command));
+            sprintf(command, "/tmp/geo/InputFiles/%s", fname[fileCnt].filename);
+            command[strlen(command) - 1] = 0x00;    // erase '\n' for fopen
+            LOGINFO("fopen command: %s", command);
+
+            waitCnt = 0;
+            while(access(command, F_OK) != 0 && waitCnt < 3)
+            {
+                usleep(10000);
+                waitCnt++;
+            }
+
+            srcFD = fopen(command, "r");
+            if(!srcFD)
+            {
+                LOGERR("fopen fail");
+                pthread_exit((void *) 0);
+            }
+
+            prevTime = 0;
+            nextTime = 0;
+
+            memset(lineData, '\0', sizeof(lineData));
+            while(fgets(lineData, 1024, srcFD) != NULL)
+            {
+                ret = strtok(lineData, token);
+                if(!ret)
+                {
+                    LOGINFO("data is NULL");
+                    nextTime = prevTime + 1;
+                }
+                else
+                    nextTime = atoi(ret);
+
+                sleepTime = (nextTime - prevTime) * 10000;
+                if(sleepTime < 0)
+                {
+                    sleepTime = 10000;
+                    nextTime = prevTime + 1;
+                }
+
+                usleep(sleepTime);  // convert millisecond
+                prevTime = nextTime;
+
+                ret = strtok(NULL, token);
+                if(!ret)
+                {
+                    LOGINFO("x data is NULL");
+                    x = 0;
+                }
+                else
+                    x = atoi(ret);
+
+                if (x > 2000)
+                    x = 2000;
+                if (x < -2000)
+                    x = -2000;
+                LOGINFO("x: %d", x);
+
+                ret = strtok(NULL, token);
+                if(!ret)
+                {
+                    LOGINFO("y data is NULL");
+                    y = 0;
+                }
+                else
+                    y = atoi(ret);
+
+                if (y > 2000)
+                    y = 2000;
+                if (y < -2000)
+                    y = -2000;
+                LOGINFO("y: %d", y);
+
+                ret = strtok(NULL, token);
+                if(!ret)
+                {
+                    LOGINFO("data is NULL");
+                    z = 0;
+                }
+                else
+                    z = atoi(ret);
+
+                if (z > 2000)
+                    z = 2000;
+                if (z < -2000)
+                    z = -2000;
+                LOGINFO("z: %d", z);
+
+                dstFD = fopen(PATH_SENSOR_GEO_TESLA, "w");
+                if(!dstFD)
+                {
+                    LOGINFO("fopen fail");
+                    pthread_exit((void *) 0);
+                }
+                fprintf(dstFD, "%d %d %d",x, y, z);
+                fclose(dstFD);
+            }
+
+            fclose(srcFD);
+        }
+    }
+
+    LOGINFO("thread exit");
+    system_msg("rm -rf /tmp/geo/InputFiles/*");
+
+    pthread_exit((void *) 0);
+}
+
+int parse_file_magnetic_data(int len, char *buffer)
+{
+    int len1=0, repeat = -1;
+    char tmpbuf[255];
+
+    LOGDEBUG("read data: %s", buffer);
+
+    // read start/stop
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    repeat = atoi(tmpbuf);
+
+    pthread_cancel(d_tid[1]);
+
+    if(repeat == 0) // stop
+    {
+        system_msg("rm -rf /tmp/geo/InputFiles/*");
+    }
+    else            // start
+    {
+        // read file count
+        memset(tmpbuf, '\0', sizeof(tmpbuf));
+        len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+        len += len1;
+
+        FileInput_args args;
+        args.len = len;
+        args.repeatCnt = repeat;
+        args.fileCnt = atoi(tmpbuf);
+        args.buffer = buffer;
+        if(pthread_create(&d_tid[1], NULL, file_input_magnetic, &args) != 0)
+                LOGINFO("pthread create fail!");
+    }
+
+    return 0;
+}
+
+void* file_input_gyro(void* param)
+{
+    FILE* srcFD;
+    FILE* dstFD;
+
+    int len1 = 0, fileCnt = 0, repeatCnt = 0, prevTime = 0, nextTime = 0, sleepTime = 0, x, y, z;
+    int waitCnt = 0;
+
+    char tmpbuf[255];
+    char token[] = ",";
+    char* ret = NULL;
+    char command[255];
+    char lineData[1024];
+    FileInput_args* args = (FileInput_args*) param;
+    FileInput_files fname[args->fileCnt];
+    memset(fname, '\0', sizeof(fname));
+
+    pthread_detach(pthread_self());
+
+    LOGINFO("file_input_gyro start");
+
+    // save file names
+    for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
+    {
+        memset(tmpbuf, '\0', sizeof(tmpbuf));
+        len1 = parse_val(args->buffer+args->len, 0x0a, tmpbuf);
+        args->len += len1;
+
+        strcpy(fname[fileCnt].filename, tmpbuf);
+        LOGINFO("saved file name: %s", fname[fileCnt].filename);
+    }
+
+    // play files
+    for(repeatCnt = 0; repeatCnt < args->repeatCnt; repeatCnt++)
+    {
+        for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
+        {
+            memset(command, '\0', sizeof(command));
+            sprintf(command, "/tmp/gyro/InputFiles/%s", fname[fileCnt].filename);
+            command[strlen(command) - 1] = 0x00;    // erase '\n' for fopen
+            LOGINFO("fopen command: %s", command);
+
+            waitCnt = 0;
+            while(access(command, F_OK) != 0 && waitCnt < 3)
+            {
+                usleep(10000);
+                waitCnt++;
+            }
+
+            srcFD = fopen(command, "r");
+            if(!srcFD)
+            {
+                LOGINFO("fopen fail");
+                pthread_exit((void *) 0);
+            }
+
+            prevTime = 0;
+            nextTime = 0;
+
+            memset(lineData, '\0', sizeof(lineData));
+            while(fgets(lineData, 1024, srcFD) != NULL)
+            {
+                ret = strtok(lineData, token);
+                if(!ret)
+                {
+                    LOGINFO("data is NULL");
+                    nextTime = prevTime + 1;
+                }
+                else
+                    nextTime = atoi(ret);
+
+                sleepTime = (nextTime - prevTime) * 10000;
+                if(sleepTime < 0)
+                {
+                    sleepTime = 10000;
+                    nextTime = prevTime + 1;
+                }
+
+                usleep(sleepTime);  // convert millisecond
+                prevTime = nextTime;
+
+                ret = strtok(NULL, token);
+                if(!ret)
+                {
+                    LOGINFO("x data is NULL");
+                    x = 0;
+                }
+                else
+                    x = (int)(atof(ret) * 1000)/17.50;
+
+                if (x > 571)
+                    x = 571;
+                if (x < -571)
+                    x = -571;
+                LOGINFO("x: %d", x);
+
+                ret = strtok(NULL, token);
+                if(!ret)
+                {
+                    LOGINFO("y data is NULL");
+                    y = 0;
+                }
+                else
+                    y = (int)(atof(ret) * 1000)/17.50;
+
+                if (y > 571)
+                    y = 571;
+                if (y < -571)
+                    y = -571;
+                LOGINFO("y: %d", y);
+
+                ret = strtok(NULL, token);
+                if(!ret)
+                {
+                    LOGINFO("data is NULL");
+                    z = 0;
+                }
+                else
+                    z = (int)(atof(ret) * 1000)/17.50;
+
+                if (z > 571)
+                    z = 571;
+                if (z < -571)
+                    z = -571;
+                LOGINFO("z: %d", z);
+
+                dstFD = fopen("/opt/sensor/gyro/gyro_x_raw", "w");
+                if(!dstFD)
+                {
+                    LOGINFO("fopen fail");
+                    pthread_exit((void *) 0);
+                }
+                fprintf(dstFD, "%d",x);
+                fclose(dstFD);
+
+                dstFD = fopen("/opt/sensor/gyro/gyro_y_raw", "w");
+                if(!dstFD)
+                {
+                    LOGINFO("fopen fail");
+                    pthread_exit((void *) 0);
+                }
+                fprintf(dstFD, "%d",y);
+                fclose(dstFD);
+
+                dstFD = fopen("/opt/sensor/gyro/gyro_z_raw", "w");
+                if(!dstFD)
+                {
+                    LOGINFO("fopen fail");
+                    pthread_exit((void *) 0);
+                }
+                fprintf(dstFD, "%d",z);
+                fclose(dstFD);
+            }
+            fclose(srcFD);
+        }
+    }
+
+    LOGINFO("thread exit");
+    system_msg("rm -rf /tmp/gyro/InputFiles/*");
+
+    pthread_exit((void *) 0);
+}
+
+int parse_file_gyro_data(int len, char *buffer)
+{
+    int len1=0, repeat = -1;
+    char tmpbuf[255];
+
+    LOGDEBUG("read data: %s", buffer);
+
+    // read start/stop
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+    len += len1;
+
+    repeat = atoi(tmpbuf);
+
+    pthread_cancel(d_tid[2]);
+
+    if(repeat == 0) // stop
+    {
+        system_msg("rm -rf /tmp/gyro/InputFiles/*");
+    }
+    else            // start
+    {
+        // read file count
+        memset(tmpbuf, '\0', sizeof(tmpbuf));
+        len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+        len += len1;
+
+        FileInput_args args;
+        args.len = len;
+        args.repeatCnt = repeat;
+        args.fileCnt = atoi(tmpbuf);
+        args.buffer = buffer;
+        if(pthread_create(&d_tid[2], NULL, file_input_gyro, &args) != 0)
+                LOGINFO("pthread create fail!");
+    }
+
+    return 0;
+}
+
+void device_parser(char *buffer)
+{
+    int len = 0;
+    int ret = 0;
+    char tmpbuf[255];
+
+    LOGDEBUG("read data: %s", buffer);
+
+    // read sensor type
+    memset(tmpbuf, '\0', sizeof(tmpbuf));
+    len = parse_val(buffer, 0x0a, tmpbuf);
+
+    switch(atoi(tmpbuf))
+    {
+    case MOTION:
+        ret = parse_motion_data(len, buffer);
+        if(ret < 0)
+            LOGERR("motion parse error!");
+        break;
+    case USBKEYBOARD:
+        ret = parse_usbkeyboard_data(len, buffer);
+        if(ret < 0)
+            LOGERR("usbkeyboard parse error!");
+        break;
+    case BATTERYLEVEL:
+        ret = parse_batterylevel_data(len, buffer);
+        if(ret < 0)
+            LOGERR("batterylevel parse error!");
+        break;
+    case EARJACK:
+        ret = parse_earjack_data(len, buffer);
+        if(ret < 0)
+            LOGERR("earjack parse error!");
+        break;
+    case USB:
+        ret = parse_usb_data(len, buffer);
+        if(ret < 0)
+            LOGERR("usb parse error!");
+        break;
+    case RSSI:
+        ret = parse_rssi_data(len, buffer);
+        if(ret < 0)
+            LOGERR("rssi parse error!");
+        break;
+    case FILE_ACCEL:
+        ret = parse_file_accel_data(len, buffer);
+        if(ret < 0)
+            LOGERR("file_accel parse error!");
+        break;
+    case FILE_MAGNETIC:
+        ret = parse_file_magnetic_data(len, buffer);
+        if(ret < 0)
+            LOGERR("file_magnetic parse error!");
+        break;
+    case FILE_GYRO:
+        ret = parse_file_gyro_data(len, buffer);
+        if(ret < 0)
+            LOGERR("file_gyro parse error!");
+        break;
+    default:
+        break;
+    }
+}
index d58ff8ebcda2bcce64b8f2d7200a53a642d19843..94f7d1eebe998f4e317ffec78ab12681e5bc3d6a 100644 (file)
@@ -38,7 +38,6 @@
 
 /* global definition */
 unsigned short vmodem_port = VMODEM_PORT;
-unsigned short sensord_port = SENSORD_PORT;
 
 /* global server port number */
 int g_svr_port;
@@ -75,7 +74,7 @@ void systemcall(const char* param)
         return;
 
     if (system(param) == -1)
-        LOG("system call failure(command = %s)\n", param);
+        LOGERR("system call failure(command = %s)", param);
 }
 
 void set_lock_state(int state) {
@@ -88,7 +87,7 @@ void set_lock_state(int state) {
         } else {
             ret = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
         }
-        LOG("pm_lock_state() return: %d", ret);
+        LOGINFO("pm_lock/unlock_state() return: %d", ret);
         if(ret == 0)
         {
             break;
@@ -97,7 +96,7 @@ void set_lock_state(int state) {
         sleep(10);
     }
     if (i == PMAPI_RETRY_COUNT) {
-        LOG("Emulator Daemon: Failed to call pm_lock_state().\n");
+        LOGERR("Emulator Daemon: Failed to call pm_lock/unlock_state().");
     }
 }
 
@@ -106,7 +105,7 @@ function : init_data0
 io: none
 desc: initialize global client structure values
 ----------------------------------------------------------------*/
-void init_data0(void)
+static void init_data0(void)
 {
     register int i;
 
@@ -126,7 +125,7 @@ bool is_vm_connected(void)
     return true;
 }
 
-void set_vm_connect_status(const int v)
+static void set_vm_connect_status(const int v)
 {
     _auto_mutex _(&mutex_vmconnect);
 
@@ -134,6 +133,72 @@ void set_vm_connect_status(const int v)
 }
 
 
+bool epoll_ctl_add(const int fd)
+{
+    struct epoll_event events;
+
+    events.events = EPOLLIN;    // check In event
+    events.data.fd = fd;
+
+    if (epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, fd, &events) < 0 )
+    {
+        LOGERR("Epoll control fails.");
+        return false;
+    }
+
+    LOGINFO("[START] epoll events add fd success for server");
+    return true;
+}
+
+static void emuld_ready()
+{
+    char buf[16];
+
+    struct sockaddr_in si_other;
+    int s, slen=sizeof(si_other);
+    int port;
+    char *ptr;
+    char *temp_sdbport;
+    temp_sdbport = getenv("sdb_port");
+    if(temp_sdbport == NULL) {
+        LOGERR("failed to get env variable from sdb_port");
+        return;
+    }
+
+    port = strtol(temp_sdbport, &ptr, 10);
+    port = port + 3;
+
+    LOGINFO("guest_server port: %d", port);
+
+    if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1){
+        LOGERR("socket error!");
+        return;
+    }
+
+    memset((char *) &si_other, 0, sizeof(si_other));
+    si_other.sin_family = AF_INET;
+    si_other.sin_port = htons(port);
+    if (inet_aton(SRV_IP, &si_other.sin_addr)==0) {
+        LOGERR("inet_aton() failed");
+    }
+
+    memset(buf, '\0', sizeof(buf));
+
+    sprintf(buf, "5\n");
+
+    LOGINFO("send message 5\\n to guest server");
+
+    while(sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
+    {
+        LOGERR("sendto error! retry sendto");
+        usleep(1000);
+    }
+    LOGINFO("emuld is ready.");
+
+    close(s);
+
+}
+
 /*-------------------------------------------------------------
 function: init_server0
 io: input : integer - server port (must be positive)
@@ -141,7 +206,7 @@ output: none
 desc : tcp/ip listening socket setting with input variable
 ----------------------------------------------------------------*/
 
-bool init_server0(int svr_port, int* ret_fd)
+static bool init_server0(int svr_port, int* ret_fd)
 {
     struct sockaddr_in serv_addr;
     int fd;
@@ -151,7 +216,7 @@ bool init_server0(int svr_port, int* ret_fd)
     /* Open TCP Socket */
     if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
     {
-        fprintf(stderr, "Server Start Fails. : Can't open stream socket \n");
+        LOGERR("Server Start Fails. : Can't open stream socket");
         return false;
     }
 
@@ -166,24 +231,24 @@ bool init_server0(int svr_port, int* ret_fd)
     int nSocketOpt = 1;
     if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &nSocketOpt, sizeof(nSocketOpt)) < 0)
     {
-        fprintf(stderr, "Server Start Fails. : Can't set reuse address\n");
+        LOGERR("Server Start Fails. : Can't set reuse address");
         goto fail;
     }
 
     /* Bind Socket */
     if (bind(fd,(struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
     {
-        fprintf(stderr, "Server Start Fails. : Can't bind local address\n");
+        LOGERR("Server Start Fails. : Can't bind local address");
         goto fail;
     }
 
     /* Listening */
     if (listen(fd, 15) < 0) /* connection queue is 15. */
     {
-        fprintf(stderr, "Server Start Fails. : listen failure\n");
+        LOGERR("Server Start Fails. : listen failure");
         goto fail;
     }
-    LOG("[START] Now Server listening on port %d, EMdsockfd: %d"
+    LOGINFO("[START] Now Server listening on port %d, EMdsockfd: %d"
             ,svr_port, fd);
  
     /* notify to qemu that emuld is ready */
@@ -191,7 +256,7 @@ bool init_server0(int svr_port, int* ret_fd)
 
     if (!epoll_ctl_add(fd))
     {
-        fprintf(stderr, "Epoll control fails.\n");
+        LOGERR("Epoll control fails.");
         goto fail;
     }
 
@@ -204,69 +269,20 @@ fail:
 }
 /*------------------------------- end of function init_server0 */
 
-void emuld_ready()
-{
-    char buf[16];
-
-    struct sockaddr_in si_other;
-    int s, slen=sizeof(si_other);
-    int port;
-    char *ptr;
-    char *temp_sdbport;
-    temp_sdbport = getenv("sdb_port");
-    if(temp_sdbport == NULL) {
-        fprintf(stderr, "failed to get env variable from sdb_port\n");
-        return;
-    }
-
-    port = strtol(temp_sdbport, &ptr, 10);
-    port = port + 3;
-
-    fprintf(stderr, "guest_server port: %d\n", port);
-
-    if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1){
-        fprintf(stderr, "socket error!\n");
-        return;
-    }
-
-    memset((char *) &si_other, 0, sizeof(si_other));
-    si_other.sin_family = AF_INET;
-    si_other.sin_port = htons(port);
-    if (inet_aton(SRV_IP, &si_other.sin_addr)==0) {
-        fprintf(stderr, "inet_aton() failed\n");
-    }
-
-    memset(buf, '\0', sizeof(buf));
-
-    sprintf(buf, "5\n");
-
-    fprintf(stderr, "send message to guest server\n");
-
-    while(sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
-    {
-        fprintf(stderr, "sendto error! retry sendto\n");
-        usleep(1000);
-    }
-    fprintf(stderr, "emuld is ready.\n");
-
-    close(s);
-
-}
-
-void* init_vm_connect(void* data)
+static void* init_vm_connect(void* data)
 {
     struct sockaddr_in vm_addr;
     int ret = -1;
 
     set_vm_connect_status(0);
 
-    LOG("init_vm_connect start\n");
+    LOGINFO("init_vm_connect start");
 
     pthread_detach(pthread_self());
     /* Open TCP Socket */
     if ((g_fd[fdtype_vmodem] = socket(AF_INET, SOCK_STREAM, 0)) < 0)
     {
-        fprintf(stderr, "Server Start Fails. : Can't open stream socket \n");
+        LOGERR("Server Start Fails. : Can't open stream socket.");
         exit(0);
     }
 
@@ -281,10 +297,10 @@ void* init_vm_connect(void* data)
     {
         ret = connect(g_fd[fdtype_vmodem], (struct sockaddr *)&vm_addr, sizeof(vm_addr));
 
-        LOG("vm_sockfd: %d, connect ret: %d\n", g_fd[fdtype_vmodem], ret);
+        LOGDEBUG("vm_sockfd: %d, connect ret: %d", g_fd[fdtype_vmodem], ret);
 
         if(ret < 0) {
-            LOG("connection failed to vmodem! try \n");
+            LOGERR("connection failed to vmodem! try.");
             sleep(1);
         }
     }
@@ -296,33 +312,16 @@ void* init_vm_connect(void* data)
     pthread_exit((void *) 0);
 }
 
-bool epoll_ctl_add(const int fd)
-{
-    struct epoll_event events;
-
-    events.events = EPOLLIN;    // check In event
-    events.data.fd = fd;
-
-    if (epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, fd, &events) < 0 )
-    {
-        fprintf(stderr, "Epoll control fails.\n");
-        return false;
-    }
-
-    printf("[START] epoll events set success for server\n");
-    return true;
-}
-
-bool epoll_init(void)
+static bool epoll_init(void)
 {
     g_epoll_fd = epoll_create(MAX_EVENTS); // create event pool
     if(g_epoll_fd < 0)
     {
-        fprintf(stderr, "Epoll create Fails.\n");
+        LOGERR("Epoll create Fails.");
         return false;
     }
 
-    LOG("[START] epoll creation success\n");
+    LOGINFO("[START] epoll creation success");
     return true;
 }
 
@@ -350,59 +349,7 @@ 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");
-
-    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)
-    {
-        if (rc == EAI_SYSTEM)
-            LOG("getaddrinfo(sensord): %s", strerror(errno));
-        else
-            LOG("getaddrinfo(sensord): %s", gai_strerror(rc));
-        assert(0);
-    }
-
-    if ((g_fd[fdtype_sensor] = 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));
-    memcpy((char *) &si_sensord_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)
+static int recv_data(int event_fd, char** r_databuf, int size)
 {
     int recvd_size = 0;
     int len = 0;
@@ -471,8 +418,8 @@ bool read_ijcmd(const int fd, ijcommand* ijcmd)
     int readed;
     readed = read_header(fd, &ijcmd->msg);
 
-    LOG("action: %d", ijcmd->msg.action);
-    LOG("length: %d", ijcmd->msg.length);
+    LOGDEBUG("action: %d", ijcmd->msg.action);
+    LOGDEBUG("length: %d", ijcmd->msg.length);
 
     if (readed <= 0)
         return false;
@@ -508,7 +455,7 @@ bool read_id(const int fd, ijcommand* ijcmd)
     char* readbuf = NULL;
     int readed = recv_data(fd, &readbuf, ID_SIZE);
 
-    LOG("read_id : receive size: %d", readed);
+    LOGDEBUG("read_id : receive size: %d", readed);
 
     if (readed <= 0)
     {
@@ -517,12 +464,12 @@ bool read_id(const int fd, ijcommand* ijcmd)
         return false;
     }
 
-    LOG("identifier: %s", readbuf);
+    LOGDEBUG("identifier: %s", readbuf);
 
     memset(ijcmd->cmd, '\0', sizeof(ijcmd->cmd));
     int parselen = parse_val(readbuf, 0x0a, ijcmd->cmd);
 
-    LOG("parse_len: %d, buf = %s, fd=%d", parselen, ijcmd->cmd, fd);
+    LOGDEBUG("parse_len: %d, buf = %s, fd=%d", parselen, ijcmd->cmd, fd);
 
     if (readbuf)
     {
@@ -536,12 +483,12 @@ bool read_id(const int fd, ijcommand* ijcmd)
 
 void recv_from_vmodem(int fd)
 {
-    printf("recv_from_vmodem\n");
+    LOGDEBUG("recv_from_vmodem");
 
     ijcommand ijcmd;
     if (!read_ijcmd(fd, &ijcmd))
     {
-        LOG("fail to read ijcmd\n");
+        LOGINFO("fail to read ijcmd");
 
         set_vm_connect_status(0);
 
@@ -549,12 +496,12 @@ void recv_from_vmodem(int fd)
 
         if (pthread_create(&tid[0], NULL, init_vm_connect, NULL) != 0)
         {
-            LOG("pthread create fail!");
+            LOGERR("pthread create fail!");
         }
         return;
     }
 
-    LOG("vmodem data length: %d", ijcmd.msg.length);
+    LOGDEBUG("vmodem data length: %d", ijcmd.msg.length);
     const int tmplen = HEADER_SIZE + ijcmd.msg.length;
     char* tmp = (char*) malloc(tmplen);
 
@@ -565,7 +512,7 @@ void recv_from_vmodem(int fd)
             memcpy(tmp + HEADER_SIZE, ijcmd.data, ijcmd.msg.length);
 
         if(!ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_TELEPHONY, (const char*) tmp, tmplen)) {
-            LOG("msg_send_to_evdi: failed\n");
+            LOGERR("msg_send_to_evdi: failed");
         }
 
         free(tmp);
@@ -586,7 +533,7 @@ void recv_from_vmodem(int fd)
 
 void recv_from_ij(int fd)
 {
-    printf("recv_from_ij\n");
+    LOGDEBUG("recv_from_ij");
 
     ijcommand ijcmd;
 
@@ -600,7 +547,7 @@ void recv_from_ij(int fd)
 
     if (!read_ijcmd(fd, &ijcmd))
     {
-        LOG("fail to read ijcmd\n");
+        LOGERR("fail to read ijcmd");
         return;
     }
 
@@ -631,12 +578,12 @@ void recv_from_ij(int fd)
     }
     else
     {
-        LOG("Unknown packet: %s", ijcmd.cmd);
+        LOGERR("Unknown packet: %s", ijcmd.cmd);
         close_cli (fd);
     }
 }
 
-bool accept_proc(const int server_fd)
+static bool accept_proc(const int server_fd)
 {
     struct sockaddr_in cli_addr;
     int cli_sockfd;
@@ -645,12 +592,12 @@ bool accept_proc(const int server_fd)
     cli_sockfd = accept(server_fd, (struct sockaddr *)&cli_addr,(socklen_t *)&cli_len);
     if(cli_sockfd < 0)
     {
-        fprintf(stderr, "accept error\n");
+        LOGERR("accept error");
         return false;
     }
     else
     {
-        LOG("[Accept] New client connected. fd:%d, port:%d"
+        LOGINFO("[Accept] New client connected. fd:%d, port:%d"
                 ,cli_sockfd, cli_addr.sin_port);
 
         clipool_add(cli_sockfd, cli_addr.sin_port, fdtype_ij);
@@ -667,7 +614,7 @@ static void msgproc_suspend(int fd, ijcommand* ijcmd, bool evdi)
         set_lock_state(SUSPEND_UNLOCK);
     }
 
-       LOG("[Suspend] Set lock state as %d (1: lock, other: unlock)\n", ijcmd->msg.action);
+       LOGINFO("[Suspend] Set lock state as %d (1: lock, other: unlock)", ijcmd->msg.action);
 }
 
 static void send_default_suspend_req(void)
@@ -734,15 +681,13 @@ void process_evdi_command(ijcommand* ijcmd)
     }
     else
     {
-        LOG("Unknown packet: %s", ijcmd->cmd);
+        LOGERR("Unknown packet: %s", ijcmd->cmd);
     }
 }
 
-//static long recv_count = 0;
-
-void recv_from_evdi(evdi_fd fd)
+static void recv_from_evdi(evdi_fd fd)
 {
-    printf("recv_from_evdi\n");
+    LOGDEBUG("recv_from_evdi");
     int readed;
 
     struct msg_info _msg;
@@ -758,8 +703,7 @@ void recv_from_evdi(evdi_fd fd)
         {
             if (errno != EAGAIN)
             {
-                perror ("recv_from_evdi : EAGAIN\n");
-                LOG("EAGAIN\n");
+                LOGERR("EAGAIN");
                 return;
             }
         }
@@ -769,8 +713,7 @@ void recv_from_evdi(evdi_fd fd)
         }
     }
 
-    //LOG("RECV COUNT = %d\n", ++recv_count);
-    LOG("total readed  = %d, read count = %d, index = %d, use = %d, msg = %s\n",
+    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();
@@ -780,7 +723,7 @@ void recv_from_evdi(evdi_fd fd)
     ijcommand ijcmd;
     readed = g_synbuf.read(ijcmd.cmd, ID_SIZE);
 
-    LOG("ij id : %s\n", ijcmd.cmd);
+    LOGDEBUG("ij id : %s", ijcmd.cmd);
 
     // TODO : check
     if (readed < ID_SIZE)
@@ -796,23 +739,23 @@ void recv_from_evdi(evdi_fd fd)
     int len = ijcmd.msg.length;
 
 
-    LOG("HEADER : action = %d, group = %d, length = %d\n", act, grp, len);
+    LOGDEBUG("HEADER : action = %d, group = %d, length = %d", act, grp, len);
 
     if (ijcmd.msg.length > 0)
     {
         ijcmd.data = (char*) malloc(ijcmd.msg.length);
         if (!ijcmd.data)
         {
-            LOG("failed to allocate memory\n");
+            LOGERR("failed to allocate memory");
             return;
         }
         readed = g_synbuf.read(ijcmd.data, ijcmd.msg.length);
 
-        LOG("DATA : %s\n", ijcmd.data);
+        LOGDEBUG("DATA : %s", ijcmd.data);
 
         if (readed < ijcmd.msg.length)
         {
-            LOG("received data is insufficient");
+            LOGERR("received data is insufficient");
             //return;
         }
     }
@@ -820,7 +763,7 @@ void recv_from_evdi(evdi_fd fd)
     process_evdi_command(&ijcmd);
 }
 
-bool server_process(void)
+static bool server_process(void)
 {
     int i,nfds;
     int fd_tmp;
@@ -829,7 +772,7 @@ bool server_process(void)
 
     if (nfds == -1 && errno != EAGAIN && errno != EINTR)
     {
-        fprintf(stderr, "epoll wait(%d)\n", errno);
+        LOGERR("epoll wait(%d)", errno);
         return true;
     }
 
@@ -856,29 +799,12 @@ bool server_process(void)
 
     return false;
 }
-/*------------------------------- end of function server_process */
-
-void end_server(int sig)
-{
-    close(g_fd[fdtype_server]); /* close server socket */
-    close(g_fd[fdtype_sensor]);
-    LOG("[SHUTDOWN] Server closed by signal %d",sig);
-
-    exit(0);
-}
 
 int main( int argc , char *argv[])
 {
     int state;
 
-    //if(log_print == 1)
-    {
-        // for emuld log file
-        systemcall("rm /var/log/emuld.log");
-        systemcall("touch /var/log/emuld.log");
-    }
-
-    LOG("start");
+    LOGINFO("emuld start");
     /* entry , argument check and process */
     if(argc < 3){
         g_svr_port = DEFAULT_PORT;
@@ -886,7 +812,7 @@ int main( int argc , char *argv[])
         if(strcmp("-port", argv[1]) ==  0 ) {
             g_svr_port = atoi(argv[2]);
             if(g_svr_port < 1024) {
-                fprintf(stderr, "[STOP] port number invalid : %d\n",g_svr_port);
+                LOGERR("[STOP] port number invalid : %d",g_svr_port);
                 exit(0);
             }
         }
@@ -911,19 +837,17 @@ int main( int argc , char *argv[])
         exit(0);
     }
 
-    LOG("[START] epoll events set success for server");
+    LOGINFO("[START] epoll events set success for server");
 
     set_vm_connect_status(0);
 
     if(pthread_create(&tid[0], NULL, init_vm_connect, NULL) != 0)
     {
-        LOG("pthread create fail!");
+        LOGERR("pthread create fail!");
         close(g_epoll_fd);
         exit(0);
     }
 
-    udp_init();
-
     send_default_suspend_req();
 
     bool is_exit = false;
@@ -939,18 +863,21 @@ int main( int argc , char *argv[])
     {
         int status;
         pthread_join(tid[0], (void **)&status);
-        LOG("vmodem thread end %d\n", status);
+        LOGINFO("vmodem thread end %d", status);
     }
 
     state = pthread_mutex_destroy(&mutex_vmconnect);
     if (state != 0)
     {
-        LOG("mutex_vmconnect is failed to destroy.");
+        LOGERR("mutex_vmconnect is failed to destroy.");
     }
 
     stop_listen();
 
-    fprintf(stderr, "emuld exit\n");
+       if (g_fd[fdtype_server])
+        close(g_fd[fdtype_server]);
+
+    LOGINFO("emuld exit");
 
     return 0;
 }
index 0254400583619c16cc25899696e3865e01ebaef0..88331bb7e62fe6738bf84630aec42b6a6aa07182 100644 (file)
@@ -72,7 +72,7 @@ char* get_mount_info() {
 
     aFile = setmntent("/proc/mounts", "r");
     if (aFile == NULL) {
-        LOG("/proc/mounts is not exist");
+        LOGERR("/proc/mounts is not exist");
         return NULL;
     }
     char* mountinfo = new char[512];
@@ -82,7 +82,7 @@ char* get_mount_info() {
 
         if (strcmp(ent->mnt_dir, "/opt/storage/sdcard") == 0)
         {
-            LOG(",%s,%s,%d,%s,%d,%s\n",
+            LOGDEBUG(",%s,%s,%d,%s,%d,%s",
                             ent->mnt_fsname, ent->mnt_dir, ent->mnt_freq, ent->mnt_opts, ent->mnt_passno, ent->mnt_type);
             sprintf(mountinfo,",%s,%s,%d,%s,%d,%s\n",
                             ent->mnt_fsname, ent->mnt_dir, ent->mnt_freq, ent->mnt_opts, ent->mnt_passno, ent->mnt_type);
@@ -131,7 +131,7 @@ void* mount_sdcard(void* data)
     LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
     memset(packet, 0, sizeof(LXT_MESSAGE));
 
-    LOG("start sdcard mount thread");
+    LOGINFO("start sdcard mount thread");
 
     pthread_detach(pthread_self());
 
@@ -156,7 +156,7 @@ void* mount_sdcard(void* data)
 
         if (i != 10)
         {
-            LOG( "%s is exist", file_name);
+            LOGDEBUG( "%s is exist", file_name);
             packet->length = strlen(SDpath);        // length
             packet->group = 11;             // sdcard
             if (ret == 0)
@@ -165,7 +165,7 @@ void* mount_sdcard(void* data)
                 packet->action = 5; // failed
 
             //
-            LOG("SDpath is %s", SDpath);
+            LOGDEBUG("SDpath is %s", SDpath);
 
             const int tmplen = HEADER_SIZE + packet->length;
             char* tmp = (char*) malloc(tmplen);
@@ -200,7 +200,7 @@ void* mount_sdcard(void* data)
         }
         else
         {
-            LOG( "%s is not exist", file_name);
+            LOGERR( "%s is not exist", file_name);
             sleep(1);
         }
     }
@@ -231,7 +231,7 @@ int umount_sdcard(const int fd, bool is_evdi)
     }
     memset(packet, 0, sizeof(LXT_MESSAGE));
 
-    LOG("start sdcard umount");
+    LOGINFO("start sdcard umount");
 
     pthread_cancel(tid[1]);
 
@@ -249,12 +249,12 @@ int umount_sdcard(const int fd, bool is_evdi)
 
                 send(fd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
 
-                LOG("SDpath is %s", SDpath);
+                LOGDEBUG("SDpath is %s", SDpath);
                 send(fd, SDpath, packet->length, 0);
             }
             else if (is_evdi)
             {
-                LOG("SDpath is %s", SDpath);
+                LOGDEBUG("SDpath is %s", SDpath);
 
                 packet->length = strlen(SDpath);        // length
                 packet->group = 11;                     // sdcard
@@ -281,7 +281,7 @@ int umount_sdcard(const int fd, bool is_evdi)
         }
         else
         {
-            LOG( "%s is not exist", file_name);
+            LOGERR( "%s is not exist", file_name);
         }
     }
 
@@ -301,17 +301,17 @@ int powerdown_by_force(void)
     gettimeofday(&now, NULL);
     /* Waiting until power off duration and displaying animation */
     while (now.tv_sec - tv_start_poweroff.tv_sec < poweroff_duration) {
-        LOG("wait");
+        LOGINFO("power down wait");
         usleep(100000);
         gettimeofday(&now, NULL);
     }
 
-    LOG("Power off by force");
-    LOG("sync");
+    LOGINFO("Power off by force");
+    LOGINFO("sync");
 
     sync();
 
-    LOG("poweroff");
+    LOGINFO("poweroff");
 
     reboot(RB_POWER_OFF);
 
@@ -339,22 +339,22 @@ void setting_location(char* databuf)
             sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 2 -f");
             break;
         default:
-            LOG("error(%s) : stop replay mode", databuf);
+            LOGERR("error(%s) : stop replay mode", databuf);
             sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 0 -f");
             break;
         }
-        LOG("Location Command : %s", command);
+        LOGDEBUG("Location Command : %s", command);
         systemcall(command);
     } else {
         *s = '\0';
         int mode = atoi(databuf);
         if(mode == 1) { // NMEA MODE (LOG MODE)
             sprintf(command, "vconftool set -t string db/location/replay/FileName \"%s\"", s+1);
-            LOG("%s", command);
+            LOGDEBUG("%s", command);
             systemcall(command);
             memset(command, 0, 256);
             sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 1 -f");
-            LOG("%s", command);
+            LOGDEBUG("%s", command);
             systemcall(command);
         } else if(mode == 2) {
             memset(latitude,  0, 128);
@@ -367,12 +367,12 @@ void setting_location(char* databuf)
             //strcpy(latitude, databuf);
             // Latitude
             sprintf(command, "vconftool set -t double db/location/replay/ManualLatitude %s -f", latitude);
-            LOG("%s", command);
+            LOGDEBUG("%s", command);
             systemcall(command);
 
             // Longitude
             sprintf(command, "vconftool set -t double db/location/replay/ManualLongitude %s -f", longitude);
-            LOG("%s", command);
+            LOGDEBUG("%s", command);
             systemcall(command);
         }
     }
@@ -400,80 +400,80 @@ void* setting_device(void* data)
     case BATTERY_LEVEL:
         msg = get_battery_level((void*)packet, is_evdi);
         if (msg == 0) {
-            LOG("failed getting battery level");
+            LOGERR("failed getting battery level");
         }
         break;
     case BATTERY_CHARGER:
         msg = get_battery_charger((void*)packet, is_evdi);
         if (msg == 0) {
-            LOG("failed getting battery charger state");
+            LOGERR("failed getting battery charger state");
         }
         break;
     case USB_STATUS:
         msg = get_usb_status((void*)packet, is_evdi);
         if (msg == 0) {
-            LOG("failed getting usb status");
+            LOGERR("failed getting usb status");
         }
         break;
     case EARJACK_STATUS:
         msg = get_earjack_status((void*)packet, is_evdi);
         if (msg == 0) {
-            LOG("failed getting earjack status");
+            LOGERR("failed getting earjack status");
         }
         break;
     case RSSI_LEVEL:
         msg = get_rssi_level((void*)packet, is_evdi);
         if (msg == 0) {
-            LOG("failed getting rssi level");
+            LOGERR("failed getting rssi level");
         }
         break;
     case MOTION_VALUE:
-        LOG("not support getting motion value");
+        LOGERR("not support getting motion value");
         break;
     case LOCATION_STATUS:
         msg = get_location_status((void*)packet, is_evdi);
         if (msg == 0) {
-            LOG("failed getting location status");
+            LOGERR("failed getting location status");
         }
         break;
     case NFC_STATUS:
         msg = get_nfc_status((void*)packet, is_evdi);
         if (msg ==0) {
-            LOG("failed getting nfc status");
+            LOGERR("failed getting nfc status");
         }
         break;
     case ACCEL_VALUE:
         msg = get_acceleration_value((void*)packet, is_evdi);
         if (msg == 0) {
-            LOG("falied getting acceleration value");
+            LOGERR("falied getting acceleration value");
         }
         break;
     case GYRO_VALUE:
         msg = get_gyroscope_value((void*)packet, is_evdi);
         if (msg == 0) {
-            LOG("failed getting gyroscope value");
+            LOGERR("failed getting gyroscope value");
         }
         break;
     case MAG_VALUE:
         msg = get_magnetic_value((void*)packet, is_evdi);
         if (msg == 0) {
-            LOG("failed getting magnetic value");
+            LOGERR("failed getting magnetic value");
         }
         break;
     case LIGHT_VALUE:
         msg = get_light_level((void*)packet, is_evdi);
         if (msg == 0) {
-            LOG("failed getting light level");
+            LOGERR("failed getting light level");
         }
         break;
     case PROXI_VALUE:
         msg = get_proximity_status((void*)packet, is_evdi);
         if (msg == 0) {
-            LOG("failed getting proximity status");
+            LOGERR("failed getting proximity status");
         }
         break;
     default:
-        //TODO
+        LOGERR("Wrong action ID. %d", param->ActionID);
     break;
     }
 
@@ -481,11 +481,11 @@ void* setting_device(void* data)
     {
         if (msg != 0)
         {
-            LOG("send data to injector");
+            LOGDEBUG("send data to injector");
         }
         else
         {
-            LOG("send error message to injector");
+            LOGERR("send error message to injector");
             memset(packet, 0, sizeof(LXT_MESSAGE));
             packet->length = 0;
             packet->group  = STATUS;
@@ -503,7 +503,7 @@ void* setting_device(void* data)
     {
         if (msg == 0)
         {
-            LOG("send error message to injector");
+            LOGDEBUG("send error message to injector");
             memset(packet, 0, sizeof(LXT_MESSAGE));
             packet->length = 0;
             packet->group = STATUS;
@@ -511,7 +511,7 @@ void* setting_device(void* data)
         }
         else
         {
-            LOG("send data to injector");
+            LOGDEBUG("send data to injector");
         }
 
         const int tmplen = HEADER_SIZE + packet->length;
@@ -550,7 +550,7 @@ void* setting_device(void* data)
 
 bool msgproc_telephony(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 {
-    LOG("msgproc_telephony\n");
+    LOGDEBUG("msgproc_telephony");
 
     if (!is_vm_connected())
         return false;
@@ -562,7 +562,7 @@ bool msgproc_telephony(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
         perror("vmodem send error");
     }
 
-    LOG("sent to vmodem = %d, err = %d\n", sent, errno);
+    LOGDEBUG("sent to vmodem = %d, err = %d", sent, errno);
 
     sent = send(g_fd[fdtype_vmodem], ijcmd->data, ijcmd->msg.length, 0);
     if (sent == -1)
@@ -570,15 +570,14 @@ bool msgproc_telephony(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
         perror("vmodem send error");
     }
 
-    LOG("sent to vmodem = %d, err = %d\n", sent, errno);
+    LOGDEBUG("sent to vmodem = %d, err = %d", sent, errno);
 
     return true;
 }
 
 bool msgproc_sensor(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 {
-    LOG("msgproc_sensor\n");
-    int sslen = sizeof(si_sensord_other);
+    LOGDEBUG("msgproc_sensor");
 
     if (ijcmd->msg.group == STATUS)
     {
@@ -595,23 +594,23 @@ bool msgproc_sensor(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 
         if (pthread_create(&tid[2], NULL, setting_device, (void*)param) != 0)
         {
-            LOG("pthread create fail!");
+            LOGERR("sensor pthread create fail!");
             return false;
         }
 
     }
-    else if (sendto(g_fd[fdtype_sensor], ijcmd->data, ijcmd->msg.length, 0,
-            (struct sockaddr*) &si_sensord_other, sslen) == -1)
+    else
     {
-        LOG("sendto error!");
-        return false;
+        if (ijcmd->data != NULL && strlen(ijcmd->data) > 0) {
+            device_parser(ijcmd->data);
+        }
     }
     return true;
 }
 
 bool msgproc_location(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 {
-    LOG("msgproc_location\n");
+    LOGDEBUG("msgproc_location");
     if (ijcmd->msg.group == STATUS)
     {
         setting_device_param* param = new setting_device_param();
@@ -625,7 +624,7 @@ bool msgproc_location(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 
         if (pthread_create(&tid[2], NULL, setting_device, (void*) param) != 0)
         {
-            LOG("pthread create fail!");
+            LOGERR("location pthread create fail!");
             return false;
         }
     }
@@ -638,7 +637,7 @@ bool msgproc_location(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 
 bool msgproc_nfc(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 {
-    LOG("msgproc_nfc\n");
+    LOGDEBUG("msgproc_nfc");
 
     if (ijcmd->msg.group == STATUS)
     {
@@ -653,7 +652,7 @@ bool msgproc_nfc(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 
         if (pthread_create(&tid[2], NULL, setting_device, (void*) param) != 0)
         {
-            LOG("pthread create fail!");
+            LOGERR("nfc pthread create fail!");
             return false;
         }
     }
@@ -662,7 +661,7 @@ bool msgproc_nfc(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
         FILE* fd;
         fd = fopen(PATH_NFC_DATA, "w");
         if (!fd) {
-            LOG("nfc file open fail!");
+            LOGERR("nfc file open fail!");
             return false;
         }
         fprintf(fd, "%s", ijcmd->data);
@@ -674,15 +673,14 @@ bool msgproc_nfc(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 
 bool msgproc_system(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 {
-    LOG("msgproc_system\n");
+    LOGDEBUG("msgproc_system");
 
-    LOG("/etc/rc.d/rc.shutdown, sync, reboot(RB_POWER_OFF)");
+    LOGINFO("/etc/rc.d/rc.shutdown, sync, reboot(RB_POWER_OFF)");
 
     sync();
 
     systemcall("/etc/rc.d/rc.shutdown &");
 
-
     gettimeofday(&tv_start_poweroff, NULL);
 
     powerdown_by_force();
@@ -692,7 +690,7 @@ bool msgproc_system(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 
 bool msgproc_sdcard(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
 {
-    LOG("msgproc_sdcard\n");
+    LOGDEBUG("msgproc_sdcard");
 
     const int tmpsize = ijcmd->msg.length;
 
@@ -703,7 +701,7 @@ bool msgproc_sdcard(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
     char* ret = NULL;
     ret = strtok(tmpdata, token);
 
-    LOG("%s", ret);
+    LOGDEBUG("%s", ret);
 
     int mount_val = atoi(ret);
     int mount_status = 0;
@@ -722,7 +720,7 @@ bool msgproc_sdcard(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
                 memset(SDpath, '\0', sizeof(SDpath));
                 ret = strtok(NULL, token);
                 strcpy(SDpath, ret);
-                LOG("sdcard path is %s", SDpath);
+                LOGDEBUG("sdcard path is %s", SDpath);
 
                 send_guest_server(ijcmd->data);
 
@@ -733,7 +731,7 @@ bool msgproc_sdcard(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
                 param->is_evdi = is_evdi;
 
                 if (pthread_create(&tid[1], NULL, mount_sdcard, (void*) param) != 0)
-                    LOG("pthread create fail!");
+                    LOGERR("mount sdcard pthread create fail!");
             }
 
             break;
@@ -750,7 +748,7 @@ bool msgproc_sdcard(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
                 mntData->length = strlen(SDpath);   // length
                 mntData->group = 11;            // sdcard
 
-                LOG("SDpath is %s", SDpath);
+                LOGDEBUG("SDpath is %s", SDpath);
 
                 switch (mount_status)
                 {
@@ -836,7 +834,7 @@ bool msgproc_sdcard(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
             }
             break;
         default:
-            LOG("unknown data %s", ret);
+            LOGERR("unknown data %s", ret);
             break;
     }
     return true;
@@ -847,7 +845,7 @@ void send_guest_server(char* databuf)
 {
     if (!databuf)
     {
-        LOG("invalid data buf");
+        LOGERR("invalid data buf");
         return;
     }
 
@@ -861,7 +859,8 @@ void send_guest_server(char* databuf)
     fd = fopen(SDB_PORT_FILE, "r");
     if(!fd)
     {
-        LOG("fail to open %s file", SDB_PORT_FILE);
+        LOGERR("fail to open %s file", SDB_PORT_FILE);
+        return;
     }
 
     if (fgets(fbuf, 16, fd))
@@ -870,7 +869,8 @@ void send_guest_server(char* databuf)
     }
     else
     {
-        LOG("fgets failure\n");
+        LOGERR("guest port fgets failure");
+        return;
     }
 
     fclose(fd);
@@ -878,7 +878,7 @@ void send_guest_server(char* databuf)
     s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
     if (s == -1)
     {
-        LOG("socket error!");
+        LOGERR("socket error!");
         return;
     }
 
@@ -887,15 +887,15 @@ void send_guest_server(char* databuf)
     si_other.sin_port = htons(port);
     if (inet_aton(SRV_IP, &si_other.sin_addr) == 0)
     {
-          fprintf(stderr, "inet_aton() failed\n");
+          LOGERR("inet_aton() failed");
     }
 
     memset(buf, '\0', sizeof(buf));
     snprintf(buf, sizeof(buf), "4\n%s", databuf);
-    LOG("sendGuestServer msg: %s", buf);
+    LOGDEBUG("sendGuestServer msg: %s", buf);
     if (sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
     {
-        LOG("sendto error!");
+        LOGERR("sendto error!");
     }
 
     close(s);
index 4ef87582555c0f3a6e7692067a8dd70a95ae4e0e..851e69b31db8311bf0316a3961b6da1de8d9aa33 100644 (file)
@@ -39,10 +39,10 @@ evdi_fd open_device(void)
     evdi_fd fd;
 
     fd = open(DEVICE_NODE_PATH, O_RDWR); //O_CREAT|O_WRONLY|O_TRUNC.
-    printf("evdi open fd is %d", fd);
+    LOGDEBUG("evdi open fd is %d", fd);
 
     if (fd <= 0) {
-        printf("open %s fail", DEVICE_NODE_PATH);
+        LOGERR("open %s fail", DEVICE_NODE_PATH);
         return fd;
     }
 
@@ -55,13 +55,13 @@ bool set_nonblocking(evdi_fd fd)
     opts= fcntl(fd, F_GETFL);
     if (opts < 0)
     {
-        perror("fcntl failed\n");
+        LOGERR("F_GETFL fcntl failed");
         return false;
     }
     opts = opts | O_NONBLOCK;
     if (fcntl(fd, F_SETFL, opts) < 0)
     {
-        perror("fcntl failed\n");
+        LOGERR("NONBLOCK fcntl failed");
         return false;
     }
     return true;
@@ -85,7 +85,7 @@ bool init_device(evdi_fd* ret_fd)
 
     if (!epoll_ctl_add(fd))
     {
-        fprintf(stderr, "Epoll control fails.\n");
+        LOGERR("Epoll control fails.");
         close(fd);
         return false;
     }
@@ -97,12 +97,12 @@ bool init_device(evdi_fd* ret_fd)
 
 bool send_to_evdi(evdi_fd fd, const char* data, const int len)
 {
-    printf("send to evdi client, len = %d\n", len);
+    LOGDEBUG("send to evdi client, len = %d", len);
     int ret;
 
     ret = write(fd, data, len);
 
-    printf("written bytes = %d\n", ret);
+    LOGDEBUG("written bytes = %d", ret);
 
     if (ret == -1)
         return false;
@@ -113,7 +113,7 @@ bool ijmsg_send_to_evdi(evdi_fd fd, const char* cat, const char* data, const int
 {
     _auto_mutex _(&mutex_evdi);
 
-    LOG("ijmsg_send_to_evdi\n");
+    LOGDEBUG("ijmsg_send_to_evdi");
 
     if (fd == -1)
         return false;
@@ -124,7 +124,7 @@ bool ijmsg_send_to_evdi(evdi_fd fd, const char* cat, const char* data, const int
 
     // TODO: need to make fragmented transmission
     if (len + ID_SIZE > __MAX_BUF_SIZE) {
-        LOG("evdi message len is too large\n");
+        LOGERR("evdi message len is too large");
         return false;
     }
 
@@ -139,7 +139,7 @@ bool ijmsg_send_to_evdi(evdi_fd fd, const char* cat, const char* data, const int
     _msg.index = 0;
     _msg.cclisn = 0;
 
-    LOG("ijmsg_send_to_evdi - %s", _msg.buf);
+    LOGDEBUG("ijmsg_send_to_evdi - %s", _msg.buf);
 
     if (!send_to_evdi(fd, (char*) &_msg, sizeof(_msg)))
         return false;
@@ -154,7 +154,7 @@ bool msg_send_to_evdi(evdi_fd fd, const char* data, const int len)
     // TODO: need to make fragmented transmission
     if (len > __MAX_BUF_SIZE)
     {
-        LOG("evdi message len is too large\n");
+        LOGERR("evdi message len is too large");
         return false;
     }
 
@@ -168,7 +168,7 @@ bool msg_send_to_evdi(evdi_fd fd, const char* data, const int len)
     _msg.index = 0;
     _msg.cclisn = 0;
 
-    LOG("msg_send_to_evdi - %s", _msg.buf);
+    LOGDEBUG("msg_send_to_evdi - %s", _msg.buf);
 
     if (!send_to_evdi(fd, (char*)&_msg, sizeof(_msg)))
         return false;
index 934192724a9eb12684ad5c47f5411b0ebe47e27d..ae640cd22dbfac815f8d50622f04e3064a9f046a 100644 (file)
@@ -26,6 +26,7 @@
  */
 
 
+#include "emuld.h"
 #include "emuld_common.h"
 #include <vconf/vconf.h>
 #include <vconf/vconf-keys.h>
@@ -79,7 +80,7 @@ static int inline get_vconf_status(char* msg, const char* key, int buf_len, bool
     int status;
     int ret = vconf_get_int(key, &status);
     if (ret != 0) {
-        //LOG("cannot get vconf key - %s", key);
+        LOGERR("cannot get vconf key - %s", key);
         return -1;
     }
 
@@ -98,7 +99,7 @@ char* get_usb_status(void* p, bool is_evdi)
     char* message = __tmpalloc(5);
     int length = get_file_status(message, "/sys/devices/platform/jack/usb_online", 5, is_evdi);
     if (length < 0){
-        //LOG("get usb status error - %d", length);
+        LOGERR("get usb status error - %d", length);
         length = 0;
     }
 
@@ -225,7 +226,7 @@ char* get_acceleration_value(void* p, bool is_evdi)
 
     //fscanf(fd, "%d, %d, %d", message);
     if (!fgets(message, 128, fd))
-        fprintf(stderr, "fgets failure");
+        LOGERR("accel xyz fgets failure");
 
     fclose(fd);
 
@@ -296,7 +297,7 @@ char* get_magnetic_value(void* p, bool is_evdi)
     char* message = __tmpalloc(128);
     if (!fgets(message, 128, fd))
     {
-        fprintf(stderr, "fgets failure");
+        LOGERR("tesla fgets failure");
     }
     fclose(fd);
 
diff --git a/src/log.cpp b/src/log.cpp
deleted file mode 100644 (file)
index 6f4dbbe..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * emulator-daemon
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Jinhyung Choi <jinhyung2.choi@samsnung.com>
- * SooYoung Ha <yoosah.ha@samsnung.com>
- * Sungmin Ha <sungmin82.ha@samsung.com>
- * Daiyoung Kim <daiyoung777.kim@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 <stdarg.h>
-#include <time.h>
-#include "log.h"
-
-#define EMD_DEBUG
-
-struct emuld_log
-{
-    emuld_log()
-    {
-        m_isLogout = false;
-
-        char* buf = getenv("EMULD_LOG");
-        if (buf != NULL) {
-            fprintf(stdout, "env EMULD_LOG is set => print logs \n");
-            m_isLogout = true;
-        }
-    }
-
-    void out_v(const char *fmt, ...)
-    {
-        if (m_isLogout)
-        {
-            char buf[4096];
-            va_list ap;
-
-            va_start(ap, fmt);
-            vsnprintf(buf, sizeof(buf), fmt, ap);
-            va_end(ap);
-
-            fprintf(stdout, "%s", buf);
-            FILE* log_fd = fopen("/var/log/emuld.log", "a");
-            fprintf(log_fd, "%s", buf);
-            fclose(log_fd);
-        }
-    }
-
-    void out(const char* outbuf)
-        {
-            if (!m_isLogout)
-                return;
-
-            char timestr[512];
-            make_timestamp(timestr);
-            fprintf(stdout, "%s - %s", timestr, outbuf);
-            FILE* log_fd = fopen("/var/log/emuld.log", "a");
-            fprintf(log_fd, "%s - %s", timestr, outbuf);
-            fclose(log_fd);
-        }
-
-    bool m_isLogout;
-};
-
-
-static emuld_log g_log;
-
-void log_print_out(const char *fmt, ...)
-{
-
-#ifdef EMD_DEBUG
-
-    char buf[4096];
-    va_list ap;
-
-    va_start(ap, fmt);
-    vsnprintf(buf, sizeof(buf), fmt, ap);
-    va_end(ap);
-
-    g_log.out(buf);
-#endif
-
-    return;
-}
-
-void make_timestamp(char* ret)
-{
-    time_t ltime;
-    ltime = time(NULL);
-
-    struct tm* ts;
-    ts = localtime(&ltime);
-
-    strftime(ret, 512, "%a_%Y-%m-%d_%H-%M-%S", ts);
-}
-
-