From: munkyu.im Date: Mon, 25 Nov 2013 10:33:56 +0000 (+0900) Subject: emuld: update the latest code from public X-Git-Tag: submit/tizen/20150527.025434^2~10^2~1^2~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e1aa924c3eb60c629017cfe971513eed314a720c;p=platform%2Fadaptation%2Femulator%2Femulator-daemon.git emuld: update the latest code from public integrated public source codes added sap supporting codes on it. modified boilerplate. Change-Id: If991eca08c0f534d17229a7fac22432a76863930 Signed-off-by: munkyu.im --- diff --git a/AUTHORS b/AUTHORS index 3ba9fb3..73e5de9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,7 +1,7 @@ YeongKyoon Lee DaiYoung Kim -SeokYeon Hwang Jinhyung Choi +SeokYeon Hwang SangJin Kim KiTae Kim JinHyung Jo diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e658f8..4730ffd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,23 +20,23 @@ set(CMAKE_VERBOSE_MAKEFILE OFF) #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") +# ADD_DEFINITIONS("-DTARGET -DHWREV_CHECK") +# MESSAGE("add -DTARGET") #ELSE("${ARCH}" STREQUAL "arm") -# ADD_DEFINITIONS("-DSIMULATOR") -# MESSAGE("add -DSIMULATOR") +# 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(-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" ) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} "-lpthread -lvconf -lpmapi" ) install(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin) diff --git a/NOTICE b/NOTICE index f085dc6..272ca70 100644 --- a/NOTICE +++ b/NOTICE @@ -1 +1 @@ -Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. diff --git a/emuld b/emuld deleted file mode 100644 index 7f13703..0000000 --- a/emuld +++ /dev/null @@ -1,3 +0,0 @@ -/usr/bin/emuld & -/usr/sbin/sensord & -/etc/emulator/sensor_setting.sh & diff --git a/include/emuld.h b/include/emuld.h old mode 100755 new mode 100644 index a063e45..c70fd1d --- a/include/emuld.h +++ b/include/emuld.h @@ -1,11 +1,13 @@ /* * emulator-daemon * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: + * Jinhyung Choi * SooYoung Ha * Sungmin Ha + * Daiyoung Kim * YeongKyoon Lee * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -59,23 +61,22 @@ #include "emuld_proc.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 SAP_PORT 9999 -#define GPSD_PORT 3579 -#define SENSORD_PORT 3580 -#define SRV_IP "10.0.2.2" -#define ID_SIZE 10 -#define HEADER_SIZE 4 +#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 SAP_PORT 9999 +#define GPSD_PORT 3579 +#define SENSORD_PORT 3580 +#define SRV_IP "10.0.2.2" +#define ID_SIZE 10 +#define HEADER_SIZE 4 #define EMD_DEBUG -#define POWEROFF_DURATION 2 +#define POWEROFF_DURATION 2 - -#define SDB_PORT_FILE "/opt/home/sdb_port.txt" +#define SDB_PORT_FILE "/opt/home/sdb_port.txt" enum { @@ -93,20 +94,18 @@ extern struct sockaddr_in si_sensord_other; extern int g_fd[fdtype_max]; -#define IJTYPE_TELEPHONY "telephony" -#define IJTYPE_SAP "sap" -#define IJTYPE_SDCARD "sdcard" +#define IJTYPE_TELEPHONY "telephony" +#define IJTYPE_SAP "sap" +#define IJTYPE_SDCARD "sdcard" 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); @@ -128,48 +127,36 @@ bool is_sap_connected(void); void* init_vm_connect(void* data); void* init_sap_connect(void* data); - - - - void systemcall(const char* param); void recv_from_evdi(evdi_fd fd); -static int log_print = 1; - - 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) - - - + do { \ + log_print_out("[%s:%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); \ + } while (0) #include -typedef unsigned short CliSN; +typedef unsigned short CliSN; struct Cli { - Cli(CliSN clisn, int fdtype, int fd, unsigned short port) : - clisn(clisn), fdtype(fdtype), sockfd(fd), cli_port(port) {} + Cli(CliSN clisn, int fdtype, int fd, unsigned short port) : + clisn(clisn), fdtype(fdtype), sockfd(fd), cli_port(port) {} - CliSN clisn; - int fdtype; - int sockfd; /* client socket fds */ - unsigned short cli_port; /* client connection port */ + CliSN clisn; + int fdtype; + int sockfd; /* client socket fds */ + unsigned short cli_port; /* client connection port */ }; typedef std::map CliMap; - void clipool_add(int fd, unsigned short port, const int fdtype); void clipool_delete(int fd); void close_cli(int cli_fd); @@ -180,34 +167,33 @@ bool send_to_all_ij(char* data, const int len); bool is_ij_exist(); void stop_listen(void); - struct fd_info { - fd_info() : fd(-1){} - int fd; - int fdtype; + fd_info() : fd(-1){} + int fd; + int fdtype; }; struct ijcommand { - enum { CMD_SIZE = 48 }; - ijcommand() : data(NULL) - { - memset(cmd, 0, CMD_SIZE); - } - ~ijcommand() - { - if (data) - { - free(data); - data = NULL; - } - } - char cmd[CMD_SIZE]; - char* data; - fd_info fdinfo; - - LXT_MESSAGE msg; + enum { CMD_SIZE = 48 }; + ijcommand() : data(NULL) + { + memset(cmd, 0, CMD_SIZE); + } + ~ijcommand() + { + if (data) + { + free(data); + data = NULL; + } + } + char cmd[CMD_SIZE]; + char* data; + fd_info fdinfo; + + LXT_MESSAGE msg; }; void process_evdi_command(ijcommand* ijcmd); @@ -224,5 +210,4 @@ bool msgproc_nfc(const int sockfd, ijcommand* ijcmd, const bool is_evdi); bool msgproc_system(const int sockfd, ijcommand* ijcmd, const bool is_evdi); bool msgproc_sdcard(const int sockfd, ijcommand* ijcmd, const bool is_evdi); - #endif //__emuld_h__ diff --git a/include/emuld_common.h b/include/emuld_common.h old mode 100755 new mode 100644 index 579e841..638651a --- a/include/emuld_common.h +++ b/include/emuld_common.h @@ -1,11 +1,13 @@ /* * emulator-daemon * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: + * Jinhyung Choi * SooYoung Ha * Sungmin Ha + * Daiyoung Kim * YeongKyoon Lee * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,41 +43,41 @@ // define group id // return value to the injector -#define STATUS 15 +#define STATUS 15 // define action id -#define BATTERY_LEVEL 100 -#define BATTERY_CHARGER 101 -#define USB_STATUS 102 -#define EARJACK_STATUS 103 -#define RSSI_LEVEL 104 - -#define ACCEL_VALUE 110 -#define GYRO_VALUE 111 -#define MAG_VALUE 112 -#define LIGHT_VALUE 113 -#define PROXI_VALUE 114 -#define MOTION_VALUE 115 - -#define LOCATION_STATUS 120 - -#define NFC_STATUS 121 - -#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_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" -#define PATH_SENSOR_GEO_TESLA "/sys/devices/virtual/sensor/geo/tesla" -#define PATH_NFC_DATA "/sys/devices/virtual/network/nfc/data" +#define BATTERY_LEVEL 100 +#define BATTERY_CHARGER 101 +#define USB_STATUS 102 +#define EARJACK_STATUS 103 +#define RSSI_LEVEL 104 + +#define ACCEL_VALUE 110 +#define GYRO_VALUE 111 +#define MAG_VALUE 112 +#define LIGHT_VALUE 113 +#define PROXI_VALUE 114 +#define MOTION_VALUE 115 + +#define LOCATION_STATUS 120 + +#define NFC_STATUS 121 + +#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_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" +#define PATH_SENSOR_GEO_TESLA "/sys/devices/virtual/sensor/geo/tesla" +#define PATH_NFC_DATA "/sys/devices/virtual/network/nfc/data" struct LXT_MESSAGE// lxt_message { - unsigned short length; - unsigned char group; - unsigned char action; - void *data; + unsigned short length; + unsigned char group; + unsigned char action; + void *data; }; typedef struct LXT_MESSAGE LXT_MESSAGE; @@ -102,18 +104,18 @@ char* get_nfc_status(void* , bool); struct _auto_mutex { - _auto_mutex(pthread_mutex_t* t) - { - _mutex = t; - pthread_mutex_lock(_mutex); - - } - ~_auto_mutex() - { - pthread_mutex_unlock(_mutex); - } - - pthread_mutex_t* _mutex; + _auto_mutex(pthread_mutex_t* t) + { + _mutex = t; + pthread_mutex_lock(_mutex); + + } + ~_auto_mutex() + { + pthread_mutex_unlock(_mutex); + } + + pthread_mutex_t* _mutex; }; #endif // diff --git a/include/emuld_proc.h b/include/emuld_proc.h index 3d423b9..d825a85 100644 --- a/include/emuld_proc.h +++ b/include/emuld_proc.h @@ -1,3 +1,31 @@ +/* + * emulator-daemon + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jinhyung Choi + * SooYoung Ha + * Sungmin Ha + * Daiyoung Kim + * YeongKyoon Lee + * + * 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 __emuld_proc_h__ #define __emuld_proc_h__ diff --git a/include/evdi.h b/include/evdi.h index 29e0f24..28996a0 100644 --- a/include/evdi.h +++ b/include/evdi.h @@ -1,9 +1,37 @@ +/* + * emulator-daemon + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jinhyung Choi + * SooYoung Ha + * Sungmin Ha + * Daiyoung Kim + * YeongKyoon Lee + * + * 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 __evdi_h__ #define __evdi_h__ -typedef int evdi_fd; +typedef int evdi_fd; bool init_device(evdi_fd* ret_fd); diff --git a/include/evdi_protocol.h b/include/evdi_protocol.h old mode 100755 new mode 100644 index 36f3d98..e389f4b --- a/include/evdi_protocol.h +++ b/include/evdi_protocol.h @@ -1,38 +1,61 @@ -/* - * evdi_protocol.h - * - * Created on: 2013. 4. 15. - * Author: dykim - */ - -#ifndef EVDI_PROTOCOL_H_ -#define EVDI_PROTOCOL_H_ - -/* device protocol */ - -#define __MAX_BUF_SIZE 1024 - -enum -{ - route_qemu = 0, - route_control_server = 1, - route_monitor = 2 -}; - -typedef unsigned int CSCliSN; - -struct msg_info { - char buf[__MAX_BUF_SIZE]; - - uint32_t route; - uint32_t use; - uint16_t count; - uint16_t index; - - CSCliSN cclisn; -}; - -/* device protocol */ - - -#endif /* EVDI_PROTOCOL_H_ */ +/* + * emulator-daemon + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jinhyung Choi + * SooYoung Ha + * Sungmin Ha + * Daiyoung Kim + * YeongKyoon Lee + * + * 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 EVDI_PROTOCOL_H_ +#define EVDI_PROTOCOL_H_ + +/* device protocol */ + +#define __MAX_BUF_SIZE 1024 + +enum +{ + route_qemu = 0, + route_control_server = 1, + route_monitor = 2 +}; + +typedef unsigned int CSCliSN; + +struct msg_info { + char buf[__MAX_BUF_SIZE]; + + uint32_t route; + uint32_t use; + uint16_t count; + uint16_t index; + + CSCliSN cclisn; +}; + +/* device protocol */ + + +#endif /* EVDI_PROTOCOL_H_ */ diff --git a/include/log.h b/include/log.h index 1135171..8c4cec2 100644 --- a/include/log.h +++ b/include/log.h @@ -1,3 +1,32 @@ +/* + * emulator-daemon + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jinhyung Choi + * SooYoung Ha + * Sungmin Ha + * Daiyoung Kim + * YeongKyoon Lee + * + * 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__ diff --git a/include/synbuf.h b/include/synbuf.h old mode 100755 new mode 100644 index bb79751..26bacfe --- a/include/synbuf.h +++ b/include/synbuf.h @@ -1,135 +1,158 @@ -/* - * synbuf.h - * - * Created on: 2013. 4. 12. - * Author: dykim - */ - -#ifndef SYNBUF_H_ -#define SYNBUF_H_ - -#include - - -class synbuf -{ -public: - - enum - { - default_buf_size = 2048 - }; - synbuf() - : m_buf(NULL), m_size(default_buf_size), m_use(0) - { - m_buf = (char*) malloc(default_buf_size); - memset(m_buf, 0, default_buf_size); - m_readptr = m_buf; - } - - void reset_buf() - { - freebuf(); - - m_buf = (char*) malloc(default_buf_size); - memset(m_buf, 0, default_buf_size); - m_readptr = m_buf; - - m_size = default_buf_size; - m_use = 0; - } - - int available() - { - return m_size - m_use; - } - - char* get_readptr() - { - return m_readptr; - } - - void set_written(const int written) - { - m_use += written; - } - - void freebuf() - { - if (m_buf) - { - free(m_buf); - m_buf = NULL; - } - } - - bool realloc_and_move(const int newsize, const int readed) - { - char* tmp = (char*) malloc(newsize); - if (!tmp) - return false; - - int left = m_use - readed; - memset(tmp, 0, newsize); - memcpy(tmp, m_buf + readed, left); - - freebuf(); - - m_buf = tmp; - m_use = left; - m_size = newsize; - m_readptr = m_buf; - - return true; - } - - bool write(const char* buf, const int len) - { - if (len >= available()) - { - if (!realloc_and_move((m_size * 2), 0)) - return false; - } - - memcpy(m_buf + m_use, buf, len); - m_use += len; - - return true; - } - - int read(char* buf, const int len) - { - if (m_use < len) - return 0; - - memcpy(buf, m_buf, len); - - int left = m_use - len; - if (left > 0) - { - realloc_and_move(m_size, len); - } - else - { - // there is no more readable buffer, reset all variables - memset(m_buf, 0, m_size); - m_readptr = m_buf; - m_use = 0; - } - - return len; - } - - -private: - - - char* m_buf; - char* m_readptr; - int m_size; - int m_use; -}; - - - -#endif /* SYNBUF_H_ */ +/* + * emulator-daemon + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jinhyung Choi + * SooYoung Ha + * Sungmin Ha + * Daiyoung Kim + * YeongKyoon Lee + * + * 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 SYNBUF_H_ +#define SYNBUF_H_ + +#include + + +class synbuf +{ +public: + + enum + { + default_buf_size = 2048 + }; + synbuf() + : m_buf(NULL), m_size(default_buf_size), m_use(0) + { + m_buf = (char*) malloc(default_buf_size); + memset(m_buf, 0, default_buf_size); + m_readptr = m_buf; + } + + void reset_buf() + { + freebuf(); + + m_buf = (char*) malloc(default_buf_size); + memset(m_buf, 0, default_buf_size); + m_readptr = m_buf; + + m_size = default_buf_size; + m_use = 0; + } + + int available() + { + return m_size - m_use; + } + + char* get_readptr() + { + return m_readptr; + } + + void set_written(const int written) + { + m_use += written; + } + + void freebuf() + { + if (m_buf) + { + free(m_buf); + m_buf = NULL; + } + } + + bool realloc_and_move(const int newsize, const int readed) + { + char* tmp = (char*) malloc(newsize); + if (!tmp) + return false; + + int left = m_use - readed; + memset(tmp, 0, newsize); + memcpy(tmp, m_buf + readed, left); + + freebuf(); + + m_buf = tmp; + m_use = left; + m_size = newsize; + m_readptr = m_buf; + + return true; + } + + bool write(const char* buf, const int len) + { + if (len >= available()) + { + if (!realloc_and_move((m_size * 2), 0)) + return false; + } + + memcpy(m_buf + m_use, buf, len); + m_use += len; + + return true; + } + + int read(char* buf, const int len) + { + if (m_use < len) + return 0; + + memcpy(buf, m_buf, len); + + int left = m_use - len; + if (left > 0) + { + realloc_and_move(m_size, len); + } + else + { + // there is no more readable buffer, reset all variables + memset(m_buf, 0, m_size); + m_readptr = m_buf; + m_use = 0; + } + + return len; + } + + +private: + + + char* m_buf; + char* m_readptr; + int m_size; + int m_use; +}; + + + +#endif /* SYNBUF_H_ */ diff --git a/packaging/emuld.spec b/packaging/emuld.spec index 6ae8d39..9ab8172 100644 --- a/packaging/emuld.spec +++ b/packaging/emuld.spec @@ -1,32 +1,31 @@ -#git:/slp/pkgs/e/emulator-daemon Name: emuld -Version: 0.2.30 -Release: 1 -Summary: emuld is used for communication emulator between and ide. -License: Apache +Version: 0.4.0 +Release: 0 +Summary: Emulator daemon +License: Apache-2.0 Source0: %{name}-%{version}.tar.gz +Group: SDK/Other Source1001: packaging/emuld.manifest -BuildArch: i386 -ExclusiveArch: %{ix86} BuildRequires: cmake -BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(pmapi) %description +A emulator daemon is used for communication emulator between and ide. %prep %setup -q %build -export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed" - +export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed" + LDFLAGS="$LDFLAGS" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} make %install -rm -rf %{buildroot} - #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 @@ -34,14 +33,17 @@ 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 +#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} %make_install @@ -51,20 +53,20 @@ rm -rf CMakeCache.txt rm -rf CMakeFiles rm -rf cmake_install.cmake rm -rf Makefile -rm -rf install_manifes.txt +rm -rf install_manifest.txt %post -chmod 777 /usr/bin/emuld +chmod 770 %{_prefix}/bin/emuld mkdir -p /opt/nfc - -%postun +touch /opt/nfc/sdkMsg %files %defattr(-,root,root,-) %{_prefix}/bin/emuld +/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 +#/etc/init.d/emuld +#/etc/rc.d/rc3.d/S04emuld %changelog diff --git a/src/client.cpp b/src/client.cpp index 876771c..2fd0e9b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1,129 +1,157 @@ - - -#include "emuld.h" -#include "emuld_common.h" - -static pthread_mutex_t mutex_climap = PTHREAD_MUTEX_INITIALIZER; - - -CliMap g_climap; - -void clipool_add(int fd, unsigned short port, const int fdtype) -{ - _auto_mutex _(&mutex_climap); - - static CliSN s_id = 0; - - CliSN id = s_id; - s_id++; - Cli* cli = new Cli(id, fdtype, fd, port); - if (!cli) - return; - - if (!g_climap.insert(CliMap::value_type(fd, cli)).second) - return; - - LOG("clipool_add fd = %d, port = %d, type = %d \n", fd, port, fdtype); -} - - -void close_cli(int cli_fd) -{ - clipool_delete(cli_fd); - close(cli_fd); -} - -void clipool_delete(int fd) -{ - _auto_mutex _(&mutex_climap); - - CliMap::iterator it = g_climap.find(fd); - - if (it != g_climap.end()) - { - Cli* cli = it->second; - g_climap.erase(it); - - if (cli) - { - delete cli; - cli = NULL; - } - } - - LOG("clipool_delete fd = %d\n", fd); -} - - -Cli* find_cli(const int fd) -{ - _auto_mutex _(&mutex_climap); - - CliMap::iterator it = g_climap.find(fd); - if (it != g_climap.end()) - return NULL; - - Cli* cli = it->second; - return cli; -} - -// for thread safe -bool send_to_cli(const int fd, char* data, const int len) -{ - _auto_mutex _(&mutex_climap); - - CliMap::iterator it = g_climap.find(fd); - if (it == g_climap.end()) - return false; - - Cli* cli = it->second; - - if (send(cli->sockfd, data, len, 0) == -1) - return false; - - return true; -} - -bool send_to_all_ij(char* data, const int len) -{ - _auto_mutex _(&mutex_climap); - - bool result = false; - CliMap::iterator it, itend = g_climap.end(); - - for (it = g_climap.begin(); it != itend; it++) - { - Cli* cli = it->second; - - if (!cli) - continue; - - int sent = send(cli->sockfd, data, len, 0); - result = (sent == -1) ? false : true; - if (sent == -1) - { - perror("failed to send to ij\n"); - } - - LOG("send_len: %d, err= %d\n", sent, errno); - } - return result; -} - -bool is_ij_exist() -{ - _auto_mutex _(&mutex_climap); - - bool result = (g_climap.size() > 0) ? true : false; - return result; -} - -void stop_listen(void) -{ - pthread_mutex_destroy(&mutex_climap);; -} - - - - - +/* + * emulator-daemon + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jinhyung Choi + * SooYoung Ha + * Sungmin Ha + * Daiyoung Kim + * YeongKyoon Lee + * + * 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 "emuld.h" +#include "emuld_common.h" + +static pthread_mutex_t mutex_climap = PTHREAD_MUTEX_INITIALIZER; + + +CliMap g_climap; + +void clipool_add(int fd, unsigned short port, const int fdtype) +{ + _auto_mutex _(&mutex_climap); + + static CliSN s_id = 0; + + CliSN id = s_id; + s_id++; + Cli* cli = new Cli(id, fdtype, fd, port); + if (!cli) + return; + + if (!g_climap.insert(CliMap::value_type(fd, cli)).second) + return; + + LOG("clipool_add fd = %d, port = %d, type = %d \n", fd, port, fdtype); +} + + +void close_cli(int cli_fd) +{ + clipool_delete(cli_fd); + close(cli_fd); +} + +void clipool_delete(int fd) +{ + _auto_mutex _(&mutex_climap); + + CliMap::iterator it = g_climap.find(fd); + + if (it != g_climap.end()) + { + Cli* cli = it->second; + g_climap.erase(it); + + if (cli) + { + delete cli; + cli = NULL; + } + } + + LOG("clipool_delete fd = %d\n", fd); +} + + +Cli* find_cli(const int fd) +{ + _auto_mutex _(&mutex_climap); + + CliMap::iterator it = g_climap.find(fd); + if (it != g_climap.end()) + return NULL; + + Cli* cli = it->second; + return cli; +} + +// for thread safe +bool send_to_cli(const int fd, char* data, const int len) +{ + _auto_mutex _(&mutex_climap); + + CliMap::iterator it = g_climap.find(fd); + if (it == g_climap.end()) + return false; + + Cli* cli = it->second; + + if (send(cli->sockfd, data, len, 0) == -1) + return false; + + return true; +} + +bool send_to_all_ij(char* data, const int len) +{ + _auto_mutex _(&mutex_climap); + + bool result = false; + CliMap::iterator it, itend = g_climap.end(); + + for (it = g_climap.begin(); it != itend; it++) + { + Cli* cli = it->second; + + if (!cli) + continue; + + int sent = send(cli->sockfd, data, len, 0); + result = (sent == -1) ? false : true; + if (sent == -1) + { + perror("failed to send to ij\n"); + } + + LOG("send_len: %d, err= %d\n", sent, errno); + } + return result; +} + +bool is_ij_exist() +{ + _auto_mutex _(&mutex_climap); + + bool result = (g_climap.size() > 0) ? true : false; + return result; +} + +void stop_listen(void) +{ + pthread_mutex_destroy(&mutex_climap);; +} + + + + + diff --git a/src/emuld.cpp b/src/emuld.cpp index 1296c6e..b626a87 100644 --- a/src/emuld.cpp +++ b/src/emuld.cpp @@ -1,14 +1,15 @@ -/* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: t -*- +/* * emulator-daemon * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: + * Jinhyung Choi * DaiYoung Kim * SooYoung Ha * Sungmin Ha * YeongKyoon Lee - * + * * 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 @@ -20,25 +21,18 @@ * 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_common.h" #include "emuld.h" #include "synbuf.h" +#include "pmapi.h" - +#define PMAPI_RETRY_COUNT 3 #define MAX_CONNECT_TRY_COUNT (60 * 3) #define SRV_IP "10.0.2.2" @@ -47,41 +41,35 @@ unsigned short vmodem_port = VMODEM_PORT; unsigned short sap_port = SAP_PORT; unsigned short sensord_port = SENSORD_PORT; -int g_svr_port; /* global server port number */ +/* global server port number */ +int g_svr_port; static int g_vm_connect_status; /* connection status between emuld and vmodem */ static int g_sap_connect_status;/* connection status between emuld and sap daemon */ - pthread_t tid[MAX_CLIENT + 1]; - /* udp socket */ struct sockaddr_in si_sensord_other; - - int g_fd[fdtype_max]; - typedef std::queue __msg_queue; __msg_queue g_msgqueue; - int g_epoll_fd; static pthread_mutex_t mutex_vmconnect = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t mutex_sapconnect = PTHREAD_MUTEX_INITIALIZER; -struct epoll_event g_events[MAX_EVENTS]; +struct epoll_event g_events[MAX_EVENTS]; bool exit_flag = false; -/*--------------------------------------------------------------*/ -/* FUNCTION PART - *---------------------------------------------------------------*/ - +/*----------------------------------------------------------------*/ +/* FUNCTION PART */ +/* ---------------------------------------------------------------*/ void systemcall(const char* param) { @@ -142,10 +130,8 @@ void set_sap_connect_status(const int v) g_sap_connect_status = v; } - - -/*------------------------------------------------------------- -function: init_server0 +/*------------------------------------------------------------- +function: init_server0 io: input : integer - server port (must be positive) output: none desc : tcp/ip listening socket setting with input variable @@ -195,7 +181,7 @@ bool init_server0(int svr_port, int* ret_fd) } LOG("[START] Now Server listening on port %d, EMdsockfd: %d" ,svr_port, fd); - + /* notify to qemu that emuld is ready */ emuld_ready(); @@ -211,7 +197,7 @@ bool init_server0(int svr_port, int* ret_fd) fail: close(fd); return false; -} +} /*------------------------------- end of function init_server0 */ void emuld_ready() @@ -253,11 +239,12 @@ void emuld_ready() 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); } @@ -265,8 +252,7 @@ void emuld_ready() void* init_vm_connect(void* data) { struct sockaddr_in vm_addr; - int ret = -1; - bool is_connected = false; + int ret = -1; set_vm_connect_status(0); @@ -281,7 +267,7 @@ void* init_vm_connect(void* data) } /* Address Setting */ - memset( &vm_addr , 0 , sizeof(vm_addr)) ; + 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"); @@ -297,10 +283,6 @@ void* init_vm_connect(void* data) LOG("connection failed to vmodem! try \n"); sleep(1); } - else - { - is_connected = true; - } } epoll_ctl_add(g_fd[fdtype_vmodem]); @@ -314,7 +296,6 @@ void* init_sap_connect(void* data) { struct sockaddr_in sap_addr; int ret = -1; - bool is_connected = false; set_sap_connect_status(0); @@ -345,10 +326,6 @@ void* init_sap_connect(void* data) LOG("connection failed to sap! try \n"); sleep(1); } - else - { - is_connected = true; - } } epoll_ctl_add(g_fd[fdtype_sap]); @@ -358,7 +335,6 @@ void* init_sap_connect(void* data) pthread_exit((void *) 0); } - bool epoll_ctl_add(const int fd) { struct epoll_event events; @@ -618,7 +594,7 @@ void recv_from_vmodem(int fd) } LOG("vmodem data length: %d", ijcmd.msg.length); - const int tmplen = HEADER_SIZE + ijcmd.msg.length; + const int tmplen = HEADER_SIZE + ijcmd.msg.length; char* tmp = (char*) malloc(tmplen); if (tmp) @@ -684,7 +660,6 @@ void recv_from_sap(int fd) } } - void recv_from_ij(int fd) { printf("recv_from_ij\n"); @@ -934,12 +909,24 @@ void end_server(int sig) exit(0); } +void set_lock_state() { + int i = 0; + // Now we blocking to enter "SLEEP". + while (i < PMAPI_RETRY_COUNT && pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0) == -1) { + ++i; + sleep(10); + } + if (i == PMAPI_RETRY_COUNT) { + fprintf(stderr, "Emulator Daemon: Failed to call pm_lock_state().\n"); + } +} int main( int argc , char *argv[]) { - int state; + int vm_state; + int sap_state; - if(log_print == 1) + //if(log_print == 1) { // for emuld log file systemcall("rm /var/log/emuld.log"); @@ -949,13 +936,9 @@ int main( int argc , char *argv[]) LOG("start"); /* entry , argument check and process */ if(argc < 3){ - g_svr_port = DEFAULT_PORT; - }else { - - if(strcmp("-port",argv[1]) == 0 ) { - + 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); @@ -1000,10 +983,10 @@ int main( int argc , char *argv[]) close(g_epoll_fd); exit(0); } - - udp_init(); + set_lock_state(); + bool is_exit = false; while(!is_exit) @@ -1020,7 +1003,11 @@ int main( int argc , char *argv[]) LOG("vmodem thread end %d\n", status); } - state = pthread_mutex_destroy(&mutex_vmconnect); + vm_state = pthread_mutex_destroy(&mutex_vmconnect); + if (vm_state != 0) + { + LOG("mutex_vmconnect is failed to destroy."); + } if (!is_sap_connected()) { @@ -1029,7 +1016,11 @@ int main( int argc , char *argv[]) LOG("sap thread end %d\n", status); } - state = pthread_mutex_destroy(&mutex_sapconnect); + sap_state = pthread_mutex_destroy(&mutex_sapconnect); + if (sap_state != 0) + { + LOG("mutex_vmconnect is failed to destroy."); + } stop_listen(); diff --git a/src/emuld_proc.cpp b/src/emuld_proc.cpp index aff8eb3..5db50c8 100644 --- a/src/emuld_proc.cpp +++ b/src/emuld_proc.cpp @@ -1,3 +1,32 @@ +/* + * emulator-daemon + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jinhyung Choi + * SooYoung Ha + * Sungmin Ha + * Daiyoung Kim + * YeongKyoon Lee + * + * 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 + * + */ + /* * emuld_proc.cpp * @@ -15,11 +44,9 @@ #include #include - char SDpath[256]; static struct timeval tv_start_poweroff; - struct setting_device_param { setting_device_param() : get_status_sockfd(-1), ActionID(0), is_evdi(false) @@ -39,8 +66,6 @@ struct mount_param bool is_evdi; }; - - char* get_mount_info() { struct mntent *ent; FILE *aFile; @@ -168,7 +193,7 @@ void* mount_sdcard(void* data) // if (ret == 0) { - //ret = system("/usr/bin/sys_event mmcblk_add"); // sdcard is not supported + ret = system("/usr/bin/sys_event mmcblk_add"); } break; @@ -250,7 +275,7 @@ int umount_sdcard(const int fd, bool is_evdi) memset(SDpath, '\0', sizeof(SDpath)); sprintf(SDpath, "umounted"); - //ret = system("/usr/bin/sys_event mmcblk_remove"); // sdcard is not supported + ret = system("/usr/bin/sys_event mmcblk_remove"); break; } @@ -588,7 +613,7 @@ bool msgproc_sensor(const int sockfd, ijcommand* ijcmd, const bool is_evdi) if (!param) return false; - memset(param, 0, sizeof(param)); + memset(param, 0, sizeof(*param)); param->get_status_sockfd = sockfd; param->ActionID = ijcmd->msg.action; @@ -692,8 +717,6 @@ bool msgproc_system(const int sockfd, ijcommand* ijcmd, const bool is_evdi) return true; } - - bool msgproc_sdcard(const int sockfd, ijcommand* ijcmd, const bool is_evdi) { LOG("msgproc_sdcard\n"); @@ -846,7 +869,6 @@ bool msgproc_sdcard(const int sockfd, ijcommand* ijcmd, const bool is_evdi) return true; } - //sdcard event void send_guest_server(char* databuf) { diff --git a/src/evdi.cpp b/src/evdi.cpp index c92134a..f520b77 100644 --- a/src/evdi.cpp +++ b/src/evdi.cpp @@ -1,164 +1,178 @@ -/* - * evdi.cpp - * - * Created on: 2013. 4. 15. - * Author: dykim - */ - -#include "evdi.h" -#include "emuld.h" - -#define DEVICE_NODE_PATH "/dev/evdi0" - - -static pthread_mutex_t mutex_evdi = PTHREAD_MUTEX_INITIALIZER; - - -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); - - if (fd <= 0) { - printf("open %s fail", DEVICE_NODE_PATH); - return fd; - } - - return fd; -} - - -bool set_nonblocking(evdi_fd fd) -{ - int opts; - opts= fcntl(fd, F_GETFL); - if (opts < 0) - { - perror("fcntl failed\n"); - return false; - } - opts = opts | O_NONBLOCK; - if (fcntl(fd, F_SETFL, opts) < 0) - { - perror("fcntl failed\n"); - return false; - } - return true; -} - - -bool init_device(evdi_fd* ret_fd) -{ - evdi_fd fd; - - *ret_fd = -1; - - fd = open_device(); - if (fd <= 0) - return false; - - if (!set_nonblocking(fd)) - { - close(fd); - return false; - } - - if (!epoll_ctl_add(fd)) - { - fprintf(stderr, "Epoll control fails.\n"); - close(fd); - return false; - } - - *ret_fd = fd; - - return true; -} - - -bool send_to_evdi(evdi_fd fd, const char* data, const int len) -{ - printf("send to evdi client, len = %d\n", len); - int ret; - - ret = write(fd, data, len); - - printf("written bytes = %d\n", ret); - - if (ret == -1) - return false; - return true; -} - -bool ijmsg_send_to_evdi(evdi_fd fd, const char* cat, const char* data, const int len) -{ - _auto_mutex _(&mutex_evdi); - - LOG("ijmsg_send_to_evdi\n"); - - if (fd == -1) - return false; - - char tmp[ID_SIZE]; - memset(tmp, 0, ID_SIZE); - strncpy(tmp, cat, 10); - - // TODO: need to make fragmented transmission - if (len + ID_SIZE > __MAX_BUF_SIZE) { - LOG("evdi message len is too large\n"); - return false; - } - - msg_info _msg; - memset(_msg.buf, 0, __MAX_BUF_SIZE); - memcpy(_msg.buf, tmp, ID_SIZE); - memcpy(_msg.buf + ID_SIZE, data, len); - - _msg.route = route_control_server; - _msg.use = len + ID_SIZE; - _msg.count = 1; - _msg.index = 0; - _msg.cclisn = 0; - - LOG("ijmsg_send_to_evdi - %s", _msg.buf); - - if (!send_to_evdi(fd, (char*) &_msg, sizeof(_msg))) - return false; - - return true; -} - -bool msg_send_to_evdi(evdi_fd fd, const char* data, const int len) -{ - _auto_mutex _(&mutex_evdi); - - // TODO: need to make fragmented transmission - if (len > __MAX_BUF_SIZE) - { - LOG("evdi message len is too large\n"); - return false; - } - - msg_info _msg; - memset(_msg.buf, 0, __MAX_BUF_SIZE); - memcpy(_msg.buf, data, len); - - _msg.route = route_control_server; - _msg.use = len; - _msg.count = 1; - _msg.index = 0; - _msg.cclisn = 0; - - LOG("msg_send_to_evdi - %s", _msg.buf); - - if (!send_to_evdi(fd, (char*)&_msg, sizeof(_msg))) - return false; - - return true; -} - - - - +/* + * emulator-daemon + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jinhyung Choi + * SooYoung Ha + * Sungmin Ha + * Daiyoung Kim + * YeongKyoon Lee + * + * 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 "evdi.h" +#include "emuld.h" + +#define DEVICE_NODE_PATH "/dev/evdi0" + +static pthread_mutex_t mutex_evdi = PTHREAD_MUTEX_INITIALIZER; + +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); + + if (fd <= 0) { + printf("open %s fail", DEVICE_NODE_PATH); + return fd; + } + + return fd; +} + +bool set_nonblocking(evdi_fd fd) +{ + int opts; + opts= fcntl(fd, F_GETFL); + if (opts < 0) + { + perror("fcntl failed\n"); + return false; + } + opts = opts | O_NONBLOCK; + if (fcntl(fd, F_SETFL, opts) < 0) + { + perror("fcntl failed\n"); + return false; + } + return true; +} + +bool init_device(evdi_fd* ret_fd) +{ + evdi_fd fd; + + *ret_fd = -1; + + fd = open_device(); + if (fd <= 0) + return false; + + if (!set_nonblocking(fd)) + { + close(fd); + return false; + } + + if (!epoll_ctl_add(fd)) + { + fprintf(stderr, "Epoll control fails.\n"); + close(fd); + return false; + } + + *ret_fd = fd; + + return true; +} + +bool send_to_evdi(evdi_fd fd, const char* data, const int len) +{ + printf("send to evdi client, len = %d\n", len); + int ret; + + ret = write(fd, data, len); + + printf("written bytes = %d\n", ret); + + if (ret == -1) + return false; + return true; +} + +bool ijmsg_send_to_evdi(evdi_fd fd, const char* cat, const char* data, const int len) +{ + _auto_mutex _(&mutex_evdi); + + LOG("ijmsg_send_to_evdi\n"); + + if (fd == -1) + return false; + + char tmp[ID_SIZE]; + memset(tmp, 0, ID_SIZE); + strncpy(tmp, cat, 10); + + // TODO: need to make fragmented transmission + if (len + ID_SIZE > __MAX_BUF_SIZE) { + LOG("evdi message len is too large\n"); + return false; + } + + msg_info _msg; + memset(_msg.buf, 0, __MAX_BUF_SIZE); + memcpy(_msg.buf, tmp, ID_SIZE); + memcpy(_msg.buf + ID_SIZE, data, len); + + _msg.route = route_control_server; + _msg.use = len + ID_SIZE; + _msg.count = 1; + _msg.index = 0; + _msg.cclisn = 0; + + LOG("ijmsg_send_to_evdi - %s", _msg.buf); + + if (!send_to_evdi(fd, (char*) &_msg, sizeof(_msg))) + return false; + + return true; +} + +bool msg_send_to_evdi(evdi_fd fd, const char* data, const int len) +{ + _auto_mutex _(&mutex_evdi); + + // TODO: need to make fragmented transmission + if (len > __MAX_BUF_SIZE) + { + LOG("evdi message len is too large\n"); + return false; + } + + msg_info _msg; + memset(_msg.buf, 0, __MAX_BUF_SIZE); + memcpy(_msg.buf, data, len); + + _msg.route = route_control_server; + _msg.use = len; + _msg.count = 1; + _msg.index = 0; + _msg.cclisn = 0; + + LOG("msg_send_to_evdi - %s", _msg.buf); + + if (!send_to_evdi(fd, (char*)&_msg, sizeof(_msg))) + return false; + + return true; +} + diff --git a/src/get_status.cpp b/src/get_status.cpp index 6c75ed1..9341927 100644 --- a/src/get_status.cpp +++ b/src/get_status.cpp @@ -1,7 +1,7 @@ /* * emulator-daemon * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * SooYoung Ha @@ -33,370 +33,374 @@ static int inline get_message(char* message, int status, int buf_len, bool is_evdi) { - if (is_evdi) { - sprintf(message, "%d", status); - return strlen(message); - } else { - // int to byte - message[3] = (char) (status & 0xff); - message[2] = (char) (status >> 8 & 0xff); - message[1] = (char) (status >> 16 & 0xff); - message[0] = (char) (status >> 24 & 0xff); - message[4] = '\0'; - } - - return 4; + if (is_evdi) { + sprintf(message, "%d", status); + return strlen(message); + } else { + // int to byte + message[3] = (char) (status & 0xff); + message[2] = (char) (status >> 8 & 0xff); + message[1] = (char) (status >> 16 & 0xff); + message[0] = (char) (status >> 24 & 0xff); + message[4] = '\0'; + } + + return 4; } static int inline get_status(const char* filename) { - int ret; - int status = 0; - FILE* fd = fopen(filename, "r"); - if(!fd) - return -1; - - ret = fscanf(fd, "%d", &status); - fclose(fd); - - if (ret < 0) { - return ret; - } - - return status; + int ret; + int status = 0; + FILE* fd = fopen(filename, "r"); + if(!fd) + return -1; + + ret = fscanf(fd, "%d", &status); + fclose(fd); + + if (ret < 0) { + return ret; + } + + return status; } static int inline get_file_status(char* msg, const char* filename, int buf_len, bool is_evdi) { - int status = get_status(filename); - if (status < 0) - return status; - return get_message(msg, status, buf_len, is_evdi); + int status = get_status(filename); + if (status < 0) + return status; + return get_message(msg, status, buf_len, is_evdi); } static int inline get_vconf_status(char* msg, const char* key, int buf_len, bool is_evdi) { - int status; - int ret = vconf_get_int(key, &status); - if (ret != 0) { - //LOG("cannot get vconf key - %s", key); - return -1; - } - - return get_message(msg, status, buf_len, is_evdi); + int status; + int ret = vconf_get_int(key, &status); + if (ret != 0) { + //LOG("cannot get vconf key - %s", key); + return -1; + } + + return get_message(msg, status, buf_len, is_evdi); } char* __tmpalloc(const int size) { - char* message = (char*)malloc(sizeof(char) * size); - memset(message, 0, sizeof(char) * size); - return message; + char* message = (char*)malloc(sizeof(char) * size); + memset(message, 0, sizeof(char) * size); + return message; } 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); - length = 0; - } - - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = length; - packet->group = STATUS; - packet->action = USB_STATUS; - - return message; + 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); + length = 0; + } + + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = length; + packet->group = STATUS; + packet->action = USB_STATUS; + + return message; } char* get_earjack_status(void* p, bool is_evdi) { - char* message = __tmpalloc(5); - int length = get_file_status(message, "/sys/devices/platform/jack/earjack_online", 5, is_evdi); - if (length < 0){ - return 0; - } - - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = length; - packet->group = STATUS; - packet->action = EARJACK_STATUS; - - return message; + char* message = __tmpalloc(5); + int length = get_file_status(message, "/sys/devices/platform/jack/earjack_online", 5, is_evdi); + if (length < 0){ + return 0; + } + + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = length; + packet->group = STATUS; + packet->action = EARJACK_STATUS; + + return message; } char* get_rssi_level(void* p, bool is_evdi) { - char* message = __tmpalloc(5); - int length = get_vconf_status(message, "memory/telephony/rssi", 5, is_evdi); - if (length < 0){ - return 0; - } - - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = length; - packet->group = STATUS; - packet->action = RSSI_LEVEL; - - return message; + char* message = __tmpalloc(5); + int length = get_vconf_status(message, "memory/telephony/rssi", 5, is_evdi); + if (length < 0){ + return 0; + } + + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = length; + packet->group = STATUS; + packet->action = RSSI_LEVEL; + + return message; } char* get_battery_level(void* p, bool is_evdi) { - char* message = __tmpalloc(5); - int length = get_file_status(message, "/sys/class/power_supply/battery/capacity", 5, is_evdi); - if (length < 0){ - return 0; - } - - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = length; - packet->group = STATUS; - packet->action = BATTERY_LEVEL; - - return message; + char* message = __tmpalloc(5); + int length = get_file_status(message, "/sys/class/power_supply/battery/capacity", 5, is_evdi); + if (length < 0){ + return 0; + } + + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = length; + packet->group = STATUS; + packet->action = BATTERY_LEVEL; + + return message; } char* get_battery_charger(void* p, bool is_evdi) { - char* message = __tmpalloc(5); - int length = get_file_status(message, "/sys/class/power_supply/battery/charge_now", 5, is_evdi); - if (length < 0){ - return 0; - } - - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = length; - packet->group = STATUS; - packet->action = BATTERY_CHARGER; - - return message; + char* message = __tmpalloc(5); + int length = get_file_status(message, "/sys/class/power_supply/battery/charge_now", 5, is_evdi); + if (length < 0){ + return 0; + } + + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = length; + packet->group = STATUS; + packet->action = BATTERY_CHARGER; + + return message; } char* get_proximity_status(void* p, bool is_evdi) { - char* message = __tmpalloc(5); - int length = get_file_status(message, PATH_SENSOR_PROXI_VO, 5, is_evdi); - if (length < 0){ - return 0; - } - - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = length; - packet->group = STATUS; - packet->action = PROXI_VALUE; - - return message; + char* message = __tmpalloc(5); + int length = get_file_status(message, PATH_SENSOR_PROXI_VO, 5, is_evdi); + if (length < 0){ + return 0; + } + + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = length; + packet->group = STATUS; + packet->action = PROXI_VALUE; + + return message; } char* get_light_level(void* p, bool is_evdi) { - char* message = __tmpalloc(6); - int length = get_file_status(message, PATH_SENSOR_LIGHT_ADC, 6, is_evdi); - if (length < 0){ - return 0; - } - - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = length; - packet->group = STATUS; - packet->action = LIGHT_VALUE; - - return message; + char* message = __tmpalloc(6); + int length = get_file_status(message, PATH_SENSOR_LIGHT_ADC, 6, is_evdi); + if (length < 0){ + return 0; + } + + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = length; + packet->group = STATUS; + packet->action = LIGHT_VALUE; + + return message; } char* get_acceleration_value(void* p, bool is_evdi) { - FILE* fd = fopen(PATH_SENSOR_ACCEL_XYZ, "r"); - if(!fd) - { - return 0; - } + FILE* fd = fopen(PATH_SENSOR_ACCEL_XYZ, "r"); + if(!fd) + { + return 0; + } - char* message = __tmpalloc(128); + char* message = __tmpalloc(128); - //fscanf(fd, "%d, %d, %d", message); - if (!fgets(message, 128, fd)) - fprintf(stderr, "fgets failure"); + //fscanf(fd, "%d, %d, %d", message); + if (!fgets(message, 128, fd)) + fprintf(stderr, "fgets failure"); - fclose(fd); + fclose(fd); - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = strlen(message); - packet->group = STATUS; - packet->action = ACCEL_VALUE; + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = strlen(message); + packet->group = STATUS; + packet->action = ACCEL_VALUE; - return message; + return message; } char* get_gyroscope_value(void* p, bool is_evdi) { - int x, y, z; - int ret; - - FILE* fd = fopen(PATH_SENSOR_GYRO_X_RAW, "r"); - if(!fd) - { - return 0; - } - ret = fscanf(fd, "%d", &x); - fclose(fd); - - fd = fopen(PATH_SENSOR_GYRO_Y_RAW, "r"); - if(!fd) - { - return 0; - } - ret = fscanf(fd, "%d", &y); - fclose(fd); - - fd = fopen(PATH_SENSOR_GYRO_Z_RAW, "r"); - if(!fd) - { - return 0; - } - ret = fscanf(fd, "%d", &z); - fclose(fd); - - char* message = __tmpalloc(128); - - ret = sprintf(message, "%d, %d, %d", x, y, z); - if (ret < 0) { - free(message); - message = 0; - return 0; - } - - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = strlen(message); - packet->group = STATUS; - packet->action = GYRO_VALUE; - - return message; + int x, y, z; + int ret; + + FILE* fd = fopen(PATH_SENSOR_GYRO_X_RAW, "r"); + if(!fd) + { + return 0; + } + ret = fscanf(fd, "%d", &x); + fclose(fd); + + fd = fopen(PATH_SENSOR_GYRO_Y_RAW, "r"); + if(!fd) + { + return 0; + } + ret = fscanf(fd, "%d", &y); + fclose(fd); + + fd = fopen(PATH_SENSOR_GYRO_Z_RAW, "r"); + if(!fd) + { + return 0; + } + ret = fscanf(fd, "%d", &z); + fclose(fd); + + char* message = __tmpalloc(128); + + ret = sprintf(message, "%d, %d, %d", x, y, z); + if (ret < 0) { + free(message); + message = 0; + return 0; + } + + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = strlen(message); + packet->group = STATUS; + packet->action = GYRO_VALUE; + + return message; } char* get_magnetic_value(void* p, bool is_evdi) { - FILE* fd = fopen(PATH_SENSOR_GEO_TESLA, "r"); - if(!fd) - { - return 0; - } - - char* message = __tmpalloc(128); - if (!fgets(message, 128, fd)) - { - fprintf(stderr, "fgets failure"); - } - fclose(fd); - - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = strlen(message); - packet->group = STATUS; - packet->action = MAG_VALUE; - return message; + FILE* fd = fopen(PATH_SENSOR_GEO_TESLA, "r"); + if(!fd) + { + return 0; + } + + char* message = __tmpalloc(128); + if (!fgets(message, 128, fd)) + { + fprintf(stderr, "fgets failure"); + } + fclose(fd); + + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = strlen(message); + packet->group = STATUS; + packet->action = MAG_VALUE; + return message; } char* get_location_status(void* p, bool is_evdi) { - int mode; - int ret = vconf_get_int("db/location/replay/ReplayMode", &mode); - if (ret != 0) { - return 0; - } - - char* message = 0; - - if (mode == 0) - { // STOP - message = (char*)malloc(5); - memset(message, 0, 5); - - ret = sprintf(message, "%d", mode); - if (ret < 0) { - free(message); - message = 0; - return 0; - } - } - else if (mode == 1) - { // NMEA MODE(LOG MODE) - char* temp = 0; - temp = (char*) vconf_get_str("db/location/replay/FileName"); - if (temp == 0) { - //free(temp); - return 0; - } - - message = (char*)malloc(256); - memset(message, 0, 256); - ret = sprintf(message, "%d,%s", mode, temp); - if (ret < 0) { - free(message); - message = 0; - return 0; - } - } else if (mode == 2) { // MANUAL MODE - double latitude; - double logitude; - ret = vconf_get_dbl("db/location/replay/ManualLatitude", &latitude); - if (ret != 0) { - return 0; - } - ret = vconf_get_dbl("db/location/replay/ManualLongitude", &logitude); - if (ret != 0) { - return 0; - } - message = (char*)malloc(128); - memset(message, 0, 128); - ret = sprintf(message, "%d,%f,%f", mode, latitude, logitude); - if (ret < 0) { - free(message); - message = 0; - return 0; - } - } - - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = strlen(message); - packet->group = STATUS; - packet->action = LOCATION_STATUS; - - return message; + int mode; + int ret = vconf_get_int("db/location/replay/ReplayMode", &mode); + if (ret != 0) { + return 0; + } + + char* message = 0; + + if (mode == 0) + { // STOP + message = (char*)malloc(5); + memset(message, 0, 5); + + ret = sprintf(message, "%d", mode); + if (ret < 0) { + free(message); + message = 0; + return 0; + } + } + else if (mode == 1) + { // NMEA MODE(LOG MODE) + char* temp = 0; + temp = (char*) vconf_get_str("db/location/replay/FileName"); + if (temp == 0) { + //free(temp); + return 0; + } + + message = (char*)malloc(256); + memset(message, 0, 256); + ret = sprintf(message, "%d,%s", mode, temp); + if (ret < 0) { + free(message); + message = 0; + return 0; + } + } else if (mode == 2) { // MANUAL MODE + double latitude; + double logitude; + ret = vconf_get_dbl("db/location/replay/ManualLatitude", &latitude); + if (ret != 0) { + return 0; + } + ret = vconf_get_dbl("db/location/replay/ManualLongitude", &logitude); + if (ret != 0) { + return 0; + } + message = (char*)malloc(128); + memset(message, 0, 128); + ret = sprintf(message, "%d,%f,%f", mode, latitude, logitude); + if (ret < 0) { + free(message); + message = 0; + return 0; + } + } + + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = strlen(message); + packet->group = STATUS; + packet->action = LOCATION_STATUS; + + return message; } char* get_nfc_status(void* p, bool is_evdi) { - int ret; - FILE* fd = fopen(PATH_NFC_DATA, "r"); - if(!fd) - { - return 0; - } - - char* message = __tmpalloc(5000); - ret = fscanf(fd, "%s\n", message); - fclose(fd); - - LXT_MESSAGE* packet = (LXT_MESSAGE*)p; - memset(packet, 0, sizeof(LXT_MESSAGE)); - packet->length = strlen(message); - packet->group = STATUS; - packet->action = NFC_STATUS; - - return message; + int ret; + FILE* fd = fopen(PATH_NFC_DATA, "r"); + if(!fd) + { + return 0; + } + + char* message = __tmpalloc(5000); + ret = fscanf(fd, "%s\n", message); + if (ret < 0) + { + return 0; + } + fclose(fd); + + LXT_MESSAGE* packet = (LXT_MESSAGE*)p; + memset(packet, 0, sizeof(LXT_MESSAGE)); + packet->length = strlen(message); + packet->group = STATUS; + packet->action = NFC_STATUS; + + return message; } diff --git a/src/log.cpp b/src/log.cpp index 5391d88..029b9b0 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,3 +1,31 @@ +/* + * emulator-daemon + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jinhyung Choi + * SooYoung Ha + * Sungmin Ha + * Daiyoung Kim + * YeongKyoon Lee + * + * 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 #include @@ -9,49 +37,49 @@ 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; + 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; }; @@ -62,17 +90,17 @@ void log_print_out(const char *fmt, ...) #ifdef EMD_DEBUG - char buf[4096]; - va_list ap; + char buf[4096]; + va_list ap; - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); - g_log.out(buf); + g_log.out(buf); #endif - return; + return; } void make_timestamp(char* ret)