tizen beta release
authorKibum Kim <kb0929.kim@samsung.com>
Mon, 27 Feb 2012 12:15:53 +0000 (21:15 +0900)
committerKibum Kim <kb0929.kim@samsung.com>
Mon, 27 Feb 2012 12:15:53 +0000 (21:15 +0900)
15 files changed:
AUTHORS [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0644]
LICENSE [new file with mode: 0644]
NOTICE [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/copyright [new file with mode: 0644]
debian/dirs [new file with mode: 0644]
debian/docs [new file with mode: 0644]
debian/emuld.install.in [new file with mode: 0644]
debian/emuld.postinst.in [new file with mode: 0644]
debian/rules [new file with mode: 0644]
include/emuld.h [new file with mode: 0644]
src/emuld.c [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..caffe7b
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,13 @@
+HyunGoo Kang <hyungoo1.kang@samsung.com>
+YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+DongKyun Yun <dk77.yun@samsung.com>
+DoHyung Hong <don.hong@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>
+SungMin Ha <sungmin82.ha@samsung.com>
+MunKyu Im <munkyu.im@samsung.com>
+JiHye Kim <jihye1128.kim@samsung.com>
+GiWoong Kim <giwoong.kim@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..62a56b8
--- /dev/null
@@ -0,0 +1,42 @@
+cmake_minimum_required(VERSION 2.6)
+project(emuld C)
+
+# to install pkgconfig setup file.
+SET(EXEC_PREFIX "\${prefix}")
+#SET(LIBDIR "\${prefix}/lib")
+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(-Wall -O3 -omit-frame-pointer)
+#add_definitions(-Wall -g -D_DEBUG)
+add_definitions(-Iinclude)
+ADD_EXECUTABLE(${PROJECT_NAME} src/emuld.c)
+
+target_link_libraries(${PROJECT_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} "-lpthread" )
+
+install(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin)
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..bbe9d02
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,206 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+\r
+                                 Apache License\r
+                           Version 2.0, January 2004\r
+                        http://www.apache.org/licenses/\r
+\r
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
+\r
+   1. Definitions.\r
+\r
+      "License" shall mean the terms and conditions for use, reproduction,\r
+      and distribution as defined by Sections 1 through 9 of this document.\r
+\r
+      "Licensor" shall mean the copyright owner or entity authorized by\r
+      the copyright owner that is granting the License.\r
+\r
+      "Legal Entity" shall mean the union of the acting entity and all\r
+      other entities that control, are controlled by, or are under common\r
+      control with that entity. For the purposes of this definition,\r
+      "control" means (i) the power, direct or indirect, to cause the\r
+      direction or management of such entity, whether by contract or\r
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
+      outstanding shares, or (iii) beneficial ownership of such entity.\r
+\r
+      "You" (or "Your") shall mean an individual or Legal Entity\r
+      exercising permissions granted by this License.\r
+\r
+      "Source" form shall mean the preferred form for making modifications,\r
+      including but not limited to software source code, documentation\r
+      source, and configuration files.\r
+\r
+      "Object" form shall mean any form resulting from mechanical\r
+      transformation or translation of a Source form, including but\r
+      not limited to compiled object code, generated documentation,\r
+      and conversions to other media types.\r
+\r
+      "Work" shall mean the work of authorship, whether in Source or\r
+      Object form, made available under the License, as indicated by a\r
+      copyright notice that is included in or attached to the work\r
+      (an example is provided in the Appendix below).\r
+\r
+      "Derivative Works" shall mean any work, whether in Source or Object\r
+      form, that is based on (or derived from) the Work and for which the\r
+      editorial revisions, annotations, elaborations, or other modifications\r
+      represent, as a whole, an original work of authorship. For the purposes\r
+      of this License, Derivative Works shall not include works that remain\r
+      separable from, or merely link (or bind by name) to the interfaces of,\r
+      the Work and Derivative Works thereof.\r
+\r
+      "Contribution" shall mean any work of authorship, including\r
+      the original version of the Work and any modifications or additions\r
+      to that Work or Derivative Works thereof, that is intentionally\r
+      submitted to Licensor for inclusion in the Work by the copyright owner\r
+      or by an individual or Legal Entity authorized to submit on behalf of\r
+      the copyright owner. For the purposes of this definition, "submitted"\r
+      means any form of electronic, verbal, or written communication sent\r
+      to the Licensor or its representatives, including but not limited to\r
+      communication on electronic mailing lists, source code control systems,\r
+      and issue tracking systems that are managed by, or on behalf of, the\r
+      Licensor for the purpose of discussing and improving the Work, but\r
+      excluding communication that is conspicuously marked or otherwise\r
+      designated in writing by the copyright owner as "Not a Contribution."\r
+\r
+      "Contributor" shall mean Licensor and any individual or Legal Entity\r
+      on behalf of whom a Contribution has been received by Licensor and\r
+      subsequently incorporated within the Work.\r
+\r
+   2. Grant of Copyright License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      copyright license to reproduce, prepare Derivative Works of,\r
+      publicly display, publicly perform, sublicense, and distribute the\r
+      Work and such Derivative Works in Source or Object form.\r
+\r
+   3. Grant of Patent License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      (except as stated in this section) patent license to make, have made,\r
+      use, offer to sell, sell, import, and otherwise transfer the Work,\r
+      where such license applies only to those patent claims licensable\r
+      by such Contributor that are necessarily infringed by their\r
+      Contribution(s) alone or by combination of their Contribution(s)\r
+      with the Work to which such Contribution(s) was submitted. If You\r
+      institute patent litigation against any entity (including a\r
+      cross-claim or counterclaim in a lawsuit) alleging that the Work\r
+      or a Contribution incorporated within the Work constitutes direct\r
+      or contributory patent infringement, then any patent licenses\r
+      granted to You under this License for that Work shall terminate\r
+      as of the date such litigation is filed.\r
+\r
+   4. Redistribution. You may reproduce and distribute copies of the\r
+      Work or Derivative Works thereof in any medium, with or without\r
+      modifications, and in Source or Object form, provided that You\r
+      meet the following conditions:\r
+\r
+      (a) You must give any other recipients of the Work or\r
+          Derivative Works a copy of this License; and\r
+\r
+      (b) You must cause any modified files to carry prominent notices\r
+          stating that You changed the files; and\r
+\r
+      (c) You must retain, in the Source form of any Derivative Works\r
+          that You distribute, all copyright, patent, trademark, and\r
+          attribution notices from the Source form of the Work,\r
+          excluding those notices that do not pertain to any part of\r
+          the Derivative Works; and\r
+\r
+      (d) If the Work includes a "NOTICE" text file as part of its\r
+          distribution, then any Derivative Works that You distribute must\r
+          include a readable copy of the attribution notices contained\r
+          within such NOTICE file, excluding those notices that do not\r
+          pertain to any part of the Derivative Works, in at least one\r
+          of the following places: within a NOTICE text file distributed\r
+          as part of the Derivative Works; within the Source form or\r
+          documentation, if provided along with the Derivative Works; or,\r
+          within a display generated by the Derivative Works, if and\r
+          wherever such third-party notices normally appear. The contents\r
+          of the NOTICE file are for informational purposes only and\r
+          do not modify the License. You may add Your own attribution\r
+          notices within Derivative Works that You distribute, alongside\r
+          or as an addendum to the NOTICE text from the Work, provided\r
+          that such additional attribution notices cannot be construed\r
+          as modifying the License.\r
+\r
+      You may add Your own copyright statement to Your modifications and\r
+      may provide additional or different license terms and conditions\r
+      for use, reproduction, or distribution of Your modifications, or\r
+      for any such Derivative Works as a whole, provided Your use,\r
+      reproduction, and distribution of the Work otherwise complies with\r
+      the conditions stated in this License.\r
+\r
+   5. Submission of Contributions. Unless You explicitly state otherwise,\r
+      any Contribution intentionally submitted for inclusion in the Work\r
+      by You to the Licensor shall be under the terms and conditions of\r
+      this License, without any additional terms or conditions.\r
+      Notwithstanding the above, nothing herein shall supersede or modify\r
+      the terms of any separate license agreement you may have executed\r
+      with Licensor regarding such Contributions.\r
+\r
+   6. Trademarks. This License does not grant permission to use the trade\r
+      names, trademarks, service marks, or product names of the Licensor,\r
+      except as required for reasonable and customary use in describing the\r
+      origin of the Work and reproducing the content of the NOTICE file.\r
+\r
+   7. Disclaimer of Warranty. Unless required by applicable law or\r
+      agreed to in writing, Licensor provides the Work (and each\r
+      Contributor provides its Contributions) on an "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
+      implied, including, without limitation, any warranties or conditions\r
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
+      PARTICULAR PURPOSE. You are solely responsible for determining the\r
+      appropriateness of using or redistributing the Work and assume any\r
+      risks associated with Your exercise of permissions under this License.\r
+\r
+   8. Limitation of Liability. In no event and under no legal theory,\r
+      whether in tort (including negligence), contract, or otherwise,\r
+      unless required by applicable law (such as deliberate and grossly\r
+      negligent acts) or agreed to in writing, shall any Contributor be\r
+      liable to You for damages, including any direct, indirect, special,\r
+      incidental, or consequential damages of any character arising as a\r
+      result of this License or out of the use or inability to use the\r
+      Work (including but not limited to damages for loss of goodwill,\r
+      work stoppage, computer failure or malfunction, or any and all\r
+      other commercial damages or losses), even if such Contributor\r
+      has been advised of the possibility of such damages.\r
+\r
+   9. Accepting Warranty or Additional Liability. While redistributing\r
+      the Work or Derivative Works thereof, You may choose to offer,\r
+      and charge a fee for, acceptance of support, warranty, indemnity,\r
+      or other liability obligations and/or rights consistent with this\r
+      License. However, in accepting such obligations, You may act only\r
+      on Your own behalf and on Your sole responsibility, not on behalf\r
+      of any other Contributor, and only if You agree to indemnify,\r
+      defend, and hold each Contributor harmless for any liability\r
+      incurred by, or claims asserted against, such Contributor by reason\r
+      of your accepting any such warranty or additional liability.\r
+\r
+   END OF TERMS AND CONDITIONS\r
+\r
+   APPENDIX: How to apply the Apache License to your work.\r
+\r
+      To apply the Apache License to your work, attach the following\r
+      boilerplate notice, with the fields enclosed by brackets "[]"\r
+      replaced with your own identifying information. (Don't include\r
+      the brackets!)  The text should be enclosed in the appropriate\r
+      comment syntax for the file format. We also recommend that a\r
+      file or class name and description of purpose be included on the\r
+      same "printed page" as the copyright notice for easier\r
+      identification within third-party archives.\r
+\r
+   Copyright [yyyy] [name of copyright owner]\r
+\r
+   Licensed under the Apache License, Version 2.0 (the "License");\r
+   you may not use this file except in compliance with the License.\r
+   You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+\r
+\r
diff --git a/NOTICE b/NOTICE
new file mode 100644 (file)
index 0000000..f085dc6
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..206cc93
--- /dev/null
@@ -0,0 +1,29 @@
+emuld (0.2.4) unstable; urgency=low
+
+  * modified post install script for fix install error
+
+ -- Sungmin Ha <sungmin82.ha@samsung.com>  Mon, 20 Feb 2012 15:16:52 +0900
+
+emuld (0.2.3) unstable; urgency=low
+
+  * modified for build only i386
+
+ -- Sungmin Ha <sungmin82.ha@samsung.com>  Sat, 18 Feb 2012 13:06:52 +0900
+
+emuld (0.2.2) unstable; urgency=low
+
+  * modified for distinction close fd by event injector
+
+ -- Sungmin Ha <sungmin82.ha@samsung.com>  Wed, 15 Feb 2012 15:35:52 +0900
+
+emuld (0.2.2) unstable; urgency=low
+
+  * modified for distinction close fd by event injector
+
+ -- Sungmin Ha <sungmin82.ha@samsung.com>  Wed, 15 Feb 2012 15:35:52 +0900
+
+emuld (0.2.1) unstable; urgency=low
+
+  * Initial Release.
+
+ -- Sungmin Ha <sungmin82.ha@samsung.com>  Fri, 18 Nov 2011 09:29:52 +0900
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..232cedb
--- /dev/null
@@ -0,0 +1,10 @@
+Source: emuld
+Section: misc
+Priority: extra
+Maintainer: Sungmin Ha <sungmin82.ha@samsung.com>
+Standards-Version: 0.2.4
+
+Package: emuld
+Section: misc
+Architecture: i386
+Description: emulator daemon for sdb
diff --git a/debian/copyright b/debian/copyright
new file mode 100644 (file)
index 0000000..e7f26e9
--- /dev/null
@@ -0,0 +1,21 @@
+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/debian/dirs b/debian/dirs
new file mode 100644 (file)
index 0000000..ca882bb
--- /dev/null
@@ -0,0 +1,2 @@
+usr/bin
+usr/sbin
diff --git a/debian/docs b/debian/docs
new file mode 100644 (file)
index 0000000..a0f0008
--- /dev/null
@@ -0,0 +1 @@
+CMakeLists.txt
diff --git a/debian/emuld.install.in b/debian/emuld.install.in
new file mode 100644 (file)
index 0000000..6c1b7eb
--- /dev/null
@@ -0,0 +1 @@
+/usr/bin/emuld
diff --git a/debian/emuld.postinst.in b/debian/emuld.postinst.in
new file mode 100644 (file)
index 0000000..2abc24c
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+chmod 777 /usr/bin/emuld
+       
diff --git a/debian/rules b/debian/rules
new file mode 100644 (file)
index 0000000..63f8398
--- /dev/null
@@ -0,0 +1,120 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+CFLAGS ?= -Wall -g
+CXXFLAGS ?=  -Wall -g
+LDFLAGS ?= 
+PREFIX ?= /usr
+DATADIR ?= /opt
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+       CFLAGS += -O0
+       CXXFLAGS += -O0
+else
+       CFLAGS += -O2
+       CXXFLAGS += -O2
+endif
+
+LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed
+
+configure: configure-stamp
+configure-stamp:
+       dh_testdir
+       # Add here commands to configure the package.
+       CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" cmake . -DCMAKE_INSTALL_PREFIX=$(PREFIX)
+
+       touch configure-stamp
+
+build: build-stamp
+
+build-stamp: configure-stamp 
+       dh_testdir
+
+       # Add here commands to compile the package.
+       $(MAKE)
+       #docbook-to-man debian/wavplayer.sgml > wavplayer.1
+
+       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+               cat $$f > $${f%.in}; \
+               sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \
+               sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \
+       done
+
+
+       touch $@
+
+clean:
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp configure-stamp
+
+       # Add here commands to clean up after the build process.
+       -$(MAKE) clean
+       rm -rf CMakeCache.txt
+       rm -rf CMakeFiles
+       rm -rf cmake_install.cmake
+       rm -rf Makefile
+       rm -rf install_manifest.txt
+#      rm -rf *.so
+
+       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+               rm -f $${f%.in}; \
+       done
+
+       dh_clean 
+
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k 
+       dh_installdirs
+
+       # Add here commands to install the package into debian/wavplayer.
+       $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+       dh_installchangelogs 
+       dh_installdocs
+       dh_installexamples
+       dh_install --sourcedir=debian/tmp
+#      dh_installmenu
+#      dh_installdebconf       
+#      dh_installlogrotate
+#      dh_installemacsen
+#      dh_installpam
+#      dh_installmime
+#      dh_python
+#      dh_installinit
+#      dh_installcron
+#      dh_installinfo
+       dh_installman
+       dh_link
+       dh_strip
+       dh_compress
+       dh_fixperms
+#      dh_perl
+       dh_makeshlibs
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
diff --git a/include/emuld.h b/include/emuld.h
new file mode 100644 (file)
index 0000000..764bd03
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * 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");
+ * 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
+ *
+ */
+
+/* header files */
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/epoll.h>
+#include <arpa/inet.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/reboot.h>
+#include <stdarg.h>
+#include <sys/time.h>
+#include <pthread.h>
+
+/* definition */
+#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 EMUL_IP                        "10.0.2.16"
+#define ID_SIZE                        10
+#define HEADER_SIZE            4
+#define EMD_DEBUG
+#define POWEROFF_DURATION      2
+
+/* function prototype */
+void init_data0(void);            /* initialize data. */
+void init_server0(int svr_port);  /* server socket bind/listen */
+void* init_vm_connect(void* data);
+void epoll_init(void);            /* epoll fd create */
+void epoll_cli_add(int cli_fd);   /* client fd add to epoll set */
+void userpool_add(int cli_fd, unsigned short cli_port);
+void userpool_delete(int cli_fd);
+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);
+void end_server(int sig);
+
+static int log_print = -1;
+FILE* log_fd;
+
+#define LOG(fmt, arg...) \
+       do { \
+               log_print_out("[%s:%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); \
+       } while (0)
+
+inline void log_print_out(char *fmt, ...)
+{
+
+#ifdef EMD_DEBUG
+       char *buf;
+
+       if(log_print == -1){
+               /* not initialized */
+               buf = getenv("EMULD_LOG");
+               if(buf != NULL){
+                       /* log print */
+                       fprintf(stdout, "env EMULD_LOG is set => print logs \n");
+                       log_print = 1;
+               }else{
+                       /* log not print */
+                       fprintf(stdout, "env EMULD_LOG is not set => Not print logs \n");
+                       log_print = 0;
+               }
+       }
+
+       if(log_print == 1){
+               char buf[4096]; 
+               va_list ap;
+
+               va_start(ap, fmt);
+               vsnprintf(buf, sizeof(buf), fmt, ap);
+               va_end(ap);
+
+               fprintf(stdout, "%s", buf);
+               // for emuld log file
+               log_fd = fopen("/opt/sensor/emuld.log", "a"); 
+               fprintf(log_fd, "%s", buf);
+               fclose(log_fd);
+       }
+
+#endif
+
+       return;
+}
diff --git a/src/emuld.c b/src/emuld.c
new file mode 100644 (file)
index 0000000..77da748
--- /dev/null
@@ -0,0 +1,758 @@
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * 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");
+ * 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
+ *
+ */
+
+/*-----------------------------------------------------------------
+
+epoll server program by Sungmin Ha.
+Platform : Linux 2.6.x (kernel)
+compiler Gcc: 3.4.3. 
+License: GNU General Public License   
+
+------------------------------------------------------------------*/
+
+#include "emuld.h"
+
+/* global definition */
+unsigned short sdbd_port = SDBD_PORT;
+unsigned short vmodem_port = VMODEM_PORT;
+unsigned short gpsd_port = GPSD_PORT;
+unsigned short sensord_port = SENSORD_PORT;
+
+int g_svr_sockfd;                      /* global server socket fd */
+int g_svr_port;                        /* global server port number */
+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  */
+
+pthread_t tid[MAX_CLIENT + 1];
+
+static struct timeval tv_start_poweroff;
+
+/* udp socket */
+struct sockaddr_in si_sensord_other, si_gpsd_other;
+int uSensordFd, uGpsdFd, sslen=sizeof(si_sensord_other), sglen=sizeof(si_gpsd_other);
+
+struct {
+       int  cli_sockfd;                                /* client socket fds */
+       unsigned short cli_port;              /* client connection port */
+} g_client[MAX_CLIENT];
+
+int g_epoll_fd;                                /* epoll fd */
+
+struct epoll_event g_events[MAX_EVENTS]; 
+
+/*--------------------------------------------------------------*/
+/* FUNCTION PART 
+   ---------------------------------------------------------------*/
+/*---------------------------------------------------------------
+function : init_data0
+io: none
+desc: initialize global client structure values
+----------------------------------------------------------------*/
+void init_data0(void)
+{
+       register int i;
+
+       for(i = 0 ; i < MAX_CLIENT ; i++) {
+               g_client[i].cli_sockfd = -1;
+       }
+}
+
+/*------------------------------------------------------------- 
+function: init_server0 
+io: input : integer - server port (must be positive)
+output: none
+desc : tcp/ip listening socket setting with input variable
+----------------------------------------------------------------*/
+
+void init_server0(int svr_port)
+{
+       struct sockaddr_in serv_addr;
+
+       /* Open TCP Socket */
+       if( (g_svr_sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0 ) 
+       {
+               fprintf(stderr, "Server Start Fails. : Can't open stream socket \n");
+               exit(0);
+       }
+
+       /* Address Setting */
+       memset( &serv_addr , 0 , sizeof(serv_addr)) ; 
+
+       serv_addr.sin_family = AF_INET;
+       serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+       serv_addr.sin_port = htons(svr_port);
+
+       /* Set Socket Option  */
+       int nSocketOpt = 1;
+       if( setsockopt(g_svr_sockfd, SOL_SOCKET, SO_REUSEADDR, &nSocketOpt, sizeof(nSocketOpt)) < 0 )
+       {
+               fprintf(stderr, "Server Start Fails. : Can't set reuse address\n");
+               close(g_svr_sockfd); 
+               exit(0);
+       }
+
+       /* Bind Socket */
+       if(bind(g_svr_sockfd,(struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
+       {
+               fprintf(stderr, "Server Start Fails. : Can't bind local address\n");
+               close(g_svr_sockfd);
+               exit(0);
+       }
+
+       /* Listening */
+       listen(g_svr_sockfd,15); /* connection queue is 15. */
+
+       LOG("[START] Now Server listening on port %d, EMdsockfd: %d"
+                       ,svr_port, g_svr_sockfd);
+} 
+/*------------------------------- end of function init_server0 */
+
+void* init_vm_connect(void* data)
+{
+       struct sockaddr_in vm_addr;
+       int ret = -1;   
+       g_vm_connect_status = 0;
+
+       LOG("start");
+
+       pthread_detach(pthread_self());
+       /* Open TCP Socket */
+       if( (g_vm_sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0 ) 
+       {
+               fprintf(stderr, "Server Start Fails. : Can't open stream socket \n");
+               exit(0);
+       }
+
+       /* Address Setting */
+       memset( &vm_addr , 0 , sizeof(vm_addr)) ; 
+
+       vm_addr.sin_family = AF_INET;
+       vm_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
+       vm_addr.sin_port = htons(vmodem_port);
+
+       while(ret < 0)
+       {
+               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!");            
+                       sleep(1);
+               }
+       }
+       
+       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;
+       pthread_exit((void *) 0); 
+} 
+
+void epoll_init(void)
+{
+       struct epoll_event events;
+
+       g_epoll_fd = epoll_create(MAX_EVENTS); // create event pool
+       if(g_epoll_fd < 0)
+       {
+               fprintf(stderr, "Epoll create Fails.\n");
+               close(g_svr_sockfd);
+               exit(0);
+       }
+
+       LOG("[START] epoll creation success");
+
+       /* event control set */
+       events.events = EPOLLIN;        // check In event
+       events.data.fd = g_svr_sockfd;
+
+       /* server events set(read for accept) */
+       // add sockfd at event pool
+       if( epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, g_svr_sockfd, &events) < 0 )
+       {
+               fprintf(stderr, "Epoll control fails.\n");
+               close(g_svr_sockfd);
+               close(g_epoll_fd);
+               exit(0);
+       }
+
+       LOG("[START] epoll events set success for server");
+}
+/*------------------------------- end of function epoll_init */
+
+void epoll_cli_add(int cli_fd)
+{
+       struct epoll_event events;
+
+       /* event control set for read event */
+       events.events = EPOLLIN;
+       events.data.fd = cli_fd; 
+
+       if( epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, cli_fd, &events) < 0 )
+       {
+               LOG("Epoll control fails.in epoll_cli_add");
+       }
+}
+
+void userpool_add(int cli_fd, unsigned short cli_port)
+{
+       /* get empty element */
+       register int i;
+
+       for( i = 0 ; i < MAX_CLIENT ; i++ )
+       {
+               if(g_client[i].cli_sockfd == -1) break;
+       }
+       if( i >= MAX_CLIENT ) close(cli_fd);
+
+       LOG("g_client[%d].cli_port: %d", i, cli_port);
+
+       g_client[i].cli_sockfd = cli_fd;
+       g_client[i].cli_port = cli_port;
+}
+
+void userpool_delete(int cli_fd)
+{
+       register int i;
+
+       for( i = 0 ; i < MAX_CLIENT ; i++)
+       {
+               if(g_client[i].cli_sockfd == cli_fd)
+               {
+                       g_client[i].cli_sockfd = -1;
+                       break;
+               }
+       }
+}
+
+int parse_val(char *buff, unsigned char data, char *parsbuf)
+{
+       int count=0;
+       while(1)
+       {
+               if(count > 40)
+                       return -1;
+               if(buff[count] == data)
+               {
+                       count++;
+                       strncpy(parsbuf, buff, count);
+                       return count;
+               }
+               count++;
+       }
+
+       return 0;
+}
+
+void udp_init(void)
+{
+       LOG("start");
+
+       if ((uSensordFd=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1){
+               fprintf(stderr, "socket error!\n");
+       }
+
+       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");
+       }
+
+       if ((uGpsdFd=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-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");
+       }
+}
+
+// for vmodem packets
+typedef struct // lxt_message
+{
+       unsigned short length;
+       unsigned char group;
+       unsigned char action;
+       void *data; 
+} LXT_MESSAGE;
+
+void TAPIMessageInit(LXT_MESSAGE *packet)
+{       
+       packet->length = 0;
+       packet->group = 0;
+       packet->action = 0;
+       packet->data = 0;
+}       
+
+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;
+
+       r_tmpbuf = (char*)malloc(sizeof(char) * size);
+       *r_databuf = (char*)malloc(sizeof(char) * size);
+       memset(*r_databuf, '\0', sizeof(char) * size);
+
+       while(recvd_size < size)
+       {
+               memset(r_tmpbuf, '\0', sizeof(char) * size);
+               len = recv(event_fd, r_tmpbuf, size - recvd_size, 0);
+               memcpy((*r_databuf) + recvd_size, r_tmpbuf, len);
+               recvd_size += len;
+               getcnt++;
+               if(getcnt > MAX_GETCNT)
+                       break;
+       }
+       free(r_tmpbuf);
+       r_tmpbuf = NULL;
+
+       return recvd_size;
+}
+
+int powerdown_by_force()
+{
+       struct timeval now;
+       int poweroff_duration = POWEROFF_DURATION;
+       char *buf;
+
+       /* Getting poweroff duration */
+       buf = getenv("PWROFF_DUR");
+       if (buf != NULL && 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 */
+       while (now.tv_sec - tv_start_poweroff.tv_sec < poweroff_duration) {
+               LOG("wait");
+               usleep(100000);
+               gettimeofday(&now, NULL);
+       }   
+
+       LOG("Power off by force");
+       LOG("sync");
+       sync();
+       LOG("poweroff");
+       reboot(RB_POWER_OFF);
+
+       return 1;
+}
+
+void client_recv(int event_fd)
+{
+       char* r_databuf = NULL;
+       char tmpbuf[48];
+       int len, recvd_size, parse_len = 0;
+       LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+
+       LOG("start");
+       /* 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);
+
+               if(recvd_size <= 0)
+               {
+                       free(r_databuf);
+                       r_databuf = NULL;
+                       free(packet);
+                       packet = NULL;
+                       userpool_delete(event_fd);
+                       close(event_fd); /* epoll set fd also deleted automatically by this call as a spec */
+                       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("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, r_databuf, packet->length, 0);
+
+               LOG("send_len: %d", len);
+       }
+       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);
+
+               if( recvd_size <= 0 )
+               {
+                       free(r_databuf);
+                       r_databuf = 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;
+               }
+
+               memset(tmpbuf, '\0', sizeof(tmpbuf));
+               parse_len = parse_val(r_databuf, 0x0a, tmpbuf);
+
+               LOG("parse_len: %d", parse_len);
+               LOG("parsed_buffer: %s", tmpbuf);
+               LOG("event fd: %d", event_fd);
+
+               free(r_databuf);
+               r_databuf = NULL;
+
+               if(strncmp(tmpbuf, "telephony", 9) == 0)
+               {
+                       g_sdbd_sockfd = event_fd;
+                       if(g_vm_connect_status != 1)    // The connection is lost with vmodem
+                               return;
+
+                       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);
+                       LOG("packet->action: %d", packet->action);
+
+                       free(r_databuf);
+                       r_databuf = NULL;
+
+                       if(packet->length == 0)
+                       {       
+                               if(packet->action == 71)        // that's strange packet from telephony initialize
+                               {
+                                       packet->length = 4;
+                               }
+                               else
+                               {
+                                       free(packet);
+                                       packet = NULL;
+                                       return;
+                               }
+                       }                               
+
+                       if(g_vm_connect_status != 1)    // 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;                               
+                               free(packet);
+                               packet = NULL;
+                               return;
+                       }
+                       else
+                               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);   
+
+                       LOG("sensor packet_length: %d", packet->length);
+
+                       free(r_databuf);
+                       r_databuf = NULL;
+                       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("sensor data recv buffer: %s", r_databuf);
+
+                       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)
+               {
+                       recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);
+                       memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);
+
+                       LOG("location packet_length: %d", packet->length);
+
+                       free(r_databuf);
+                       r_databuf = NULL;
+                       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("location data recv buffer: %s", r_databuf);
+
+                       if(sendto(uGpsdFd, r_databuf, packet->length, 0, (struct sockaddr*)&si_gpsd_other, sglen) == -1)
+                               LOG("sendto error!");
+               }
+               else if(strncmp(tmpbuf, "nfc", 3) == 0)
+               {
+                       recvd_size = recv_data(event_fd, &r_databuf, 5);
+
+                       LOG("nfc packet length r_databuf: %s", r_databuf);
+
+                       if( recvd_size <= 0 )
+                       {
+                               free(r_databuf);
+                               r_databuf = NULL;
+                               return;
+                       }
+
+                               memset(tmpbuf, '\0', sizeof(tmpbuf));
+                       parse_len = parse_val(r_databuf, 0x0a, tmpbuf);
+
+                       int length = atoi(tmpbuf);
+                       
+                       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", strbuf);
+
+                       FILE* fd;
+                       fd = fopen("/opt/nfc/sdkMsg", "w");
+                       if(fd < 0)
+                       {
+                               LOG("nfc file open fail!");
+                               free(packet);
+                               packet = NULL;
+                               return;
+                       }
+                       fprintf(fd, "%s", strbuf);
+                       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);
+
+                       LOG("system packet_length: %d", packet->length);
+
+                       free(r_databuf);
+                       r_databuf = NULL;
+                       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("system data recv buffer: %s", r_databuf);
+                       LOG("/etc/rc.d/rc.shutdown, sync, reboot(RB_POWER_OFF)");
+
+                       LOG("sync");
+                       sync();
+                       system("/etc/rc.d/rc.shutdown &");
+                       gettimeofday(&tv_start_poweroff, NULL);
+                       powerdown_by_force();
+
+               }
+               else
+               {
+                       LOG("Unknown packet: %s", tmpbuf);
+                       userpool_delete(event_fd);
+                       close(event_fd); /* epoll set fd also deleted automatically by this call as a spec */
+               }
+       }
+       if(r_databuf)
+       {
+               free(r_databuf);
+               r_databuf = NULL;
+       }
+       if(packet)
+       {
+               free(packet);
+               packet = NULL;
+       }
+}
+
+void 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 */
+
+       if(nfds == 0){
+               /* no event , no work */
+               return;
+       }
+
+
+       if(nfds < 0) {
+               fprintf(stderr, "epoll wait error\n");
+               /* return but this is epoll wait error */
+               return;
+       } 
+
+       for( i = 0 ; i < nfds ; i++ )
+       {
+               /* connect client */
+               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) 
+                       {
+                               /* accept error */
+                               fprintf(stderr, "accept error\n");
+                       }
+                       else
+                       {
+                               LOG("[Accpet] New client connected. fd:%d, port:%d"
+                                               ,cli_sockfd, cli_addr.sin_port);
+
+                               /* save client port */
+                               userpool_add(cli_sockfd, cli_addr.sin_port);
+
+                               /* for vmodem to sdbd directly */
+                               //g_sdbd_sockfd = cli_sockfd;
+
+                               /* add client sockfd at event pool */
+                               epoll_cli_add(cli_sockfd);
+                       }
+                       continue; /* next fd */
+               }
+               /* if not server socket , this socket is for client socket, so we read it */
+
+               client_recv(g_events[i].data.fd);    
+       } /* end of for 0-nfds */
+}
+/*------------------------------- end of function server_process */
+
+void end_server(int sig)
+{
+       close(g_svr_sockfd); /* close server socket */
+       close(uSensordFd);
+       close(uGpsdFd);
+       LOG("[SHUTDOWN] Server closed by signal %d",sig);
+
+       exit(0);
+}
+
+int main( int argc , char *argv[])
+{
+       if(log_print == 1)
+       {
+               // for emuld log file
+               system("rm /opt/sensor/emuld.log");
+               system("touch /opt/sensor/emuld.log");
+       }
+
+       LOG("start");
+       /* entry , argument check and process */
+       if(argc < 3){ 
+
+               g_svr_port = DEFAULT_PORT;
+
+       }else {
+
+               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);
+                               exit(0);
+                       } 
+               }
+       }
+
+       init_data0();   
+
+       /* init server */
+       init_server0(g_svr_port);
+
+       epoll_init();    /* epoll initialize  */
+       if(pthread_create(&tid[0], NULL, init_vm_connect, NULL) != 0)
+               LOG("pthread create fail!");
+
+       udp_init();
+
+       /* main loop */
+       while(1)
+       {
+               server_process();  /* accept process. */
+       } /* infinite loop while end. */
+}
+