cmake_minimum_required(VERSION 2.6)
project(emuld CXX)
+# to install pkgconfig setup file.
+SET(EXEC_PREFIX "\${prefix}")
+#SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION 1.1)
+
+set(PROJECT_MAJOR_VERSION "1")
+set(PROJECT_MINOR_VERSION "1")
+set(PROJECT_RELEASE_VERSION "0")
+set(CMAKE_VERBOSE_MAKEFILE OFF)
+
IF("$ENV{CFLAGS}" MATCHES "-DMOBILE")
- # to install pkgconfig setup file.
- SET(EXEC_PREFIX "\${prefix}")
- SET(INCLUDEDIR "\${prefix}/include")
- SET(VERSION 1.1)
+ OPTION(USE_D_MOBILE "Use Mobile Def" ON)
+ENDIF()
- set(PROJECT_MAJOR_VERSION "1")
- set(PROJECT_MINOR_VERSION "1")
- set(PROJECT_RELEASE_VERSION "0")
- set(CMAKE_VERBOSE_MAKEFILE OFF)
+IF("$ENV{CFLAGS}" MATCHES "-DWEARABLE")
+ OPTION(USE_D_WEARABLE "Use Wearable Def" ON)
+ENDIF()
- OPTION(USE_D_MOBILE "Use Mobile Def" ON)
+SET(SRCS
+ src/emuld.cpp
+ src/evdi.cpp
+ src/client.cpp
+ src/common.cpp
+)
- SET(SRCS
- src/emuld.cpp
- src/evdi.cpp
- src/emuld_proc.cpp
- src/client.cpp
- src/device.cpp
- )
+IF(USE_D_MOBILE)
+ SET(SRCS ${SRCS}
+ src/mobile.cpp
+ src/mobile_dev.cpp
+ src/common_dev.cpp
+ )
+ENDIF(USE_D_MOBILE)
- INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+IF(USE_D_WEARABLE)
+ SET(SRCS ${SRCS}
+ src/wearable.cpp
+ src/wearable_dev.cpp
+ src/common_dev.cpp
+ )
+ENDIF(USE_D_WEARABLE)
- INCLUDE(FindPkgConfig)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
- SET(PKG_MODULE
- vconf
- deviced
- dlog
- pmapi
- )
+INCLUDE(FindPkgConfig)
- pkg_check_modules(PKGS REQUIRED ${PKG_MODULE})
+SET(PKG_MODULE
+ vconf
+ deviced
+ dlog
+)
- ADD_DEFINITIONS("-DENABLE_DLOG_OUT")
- ADD_DEFINITIONS(-Wall -O3 -omit-frame-pointer)
+pkg_check_modules(PKGS REQUIRED ${PKG_MODULE})
- ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+ADD_DEFINITIONS("-DENABLE_DLOG_OUT")
+ADD_DEFINITIONS(-Wall -O3 -omit-frame-pointer)
- TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS} -lpthread)
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
- INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin)
-ELSE()
- INSTALL(FILES ${CMAKE_SOURCE_DIR}/wearable/${PROJECT_NAME} DESTINATION /usr/bin)
-ENDIF()
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS} -lpthread)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin)
*/
-#ifndef __emuld_h__
-#define __emuld_h__
+#ifndef __EMULD_H__
+#define __EMULD_H__
-/* 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>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <assert.h>
-#include <errno.h>
-#include <sys/mount.h>
-#include <stdbool.h>
-#include <fcntl.h>
-#include <queue>
+#include <sys/epoll.h>
+
#include <map>
-#include "emuld_common.h"
-#include "evdi_protocol.h"
#include "evdi.h"
+#define FDTYPE_MAX 6
+
+enum
+{
+ fdtype_device = 1,
+ fdtype_ij = 4,
+ fdtype_max = FDTYPE_MAX
+};
+
/* definition */
#define MAX_CLIENT 10000
#define MAX_EVENTS 10000
#define MAX_GETCNT 10
-#define DEFAULT_PORT 3577
-#define VMODEM_PORT 3578
-
-#define SRV_IP "10.0.2.2"
#define ID_SIZE 10
#define HEADER_SIZE 4
-#define EMD_DEBUG
-#define POWEROFF_DURATION 2
-#define SUSPEND_UNLOCK 0
-#define SUSPEND_LOCK 1
-
-#define SDB_PORT_FILE "/opt/home/sdb_port.txt"
-
-enum
-{
- fdtype_server = 0,
- fdtype_device = 1,
- fdtype_vmodem = 2,
- fdtype_pedometer = 3,
- fdtype_ij = 4,
- fdtype_sensor = 5, //udp
- fdtype_max = 6
-};
+// Thread TID profile uses >= 5
+#define TID_SDCARD 1
+#define TID_LOCATION 2
+#define TID_HDS 3
extern pthread_t tid[MAX_CLIENT + 1];
-extern struct sockaddr_in si_sensord_other;
extern int g_fd[fdtype_max];
+extern bool exit_flag;
+extern int g_epoll_fd;
+extern struct epoll_event g_events[MAX_EVENTS];
#if defined(ENABLE_DLOG_OUT)
# define LOG_TAG "EMULATOR_DAEMON"
# define LOGDEBUG(fmt, arg...) printf(fmt, arg...)
#endif
-#define IJTYPE_TELEPHONY "telephony"
-#define IJTYPE_PEDOMETER "pedometer"
-#define IJTYPE_SDCARD "sdcard"
-#define IJTYPE_SUSPEND "suspend"
-
-int parse_val(char *buff, unsigned char data, char *parsbuf);
-
-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 is_vm_connected(void);
-#ifdef CONFIG_VMODEM
-void set_vm_connect_status(const int v);
-void* init_vm_connect(void* data);
-#endif
-
-void set_pedometer_connect_status(const int v);
-bool is_pedometer_connected(void);
-void* init_pedometer_connect(void* data);
-
-void udp_init(void);
-
-void systemcall(const char* param);
-
-int powerdown_by_force(void);
-// location
-void setting_location(char* databuf);
-
-#include <map>
-
typedef unsigned short CliSN;
struct Cli
void clipool_delete(int fd);
void close_cli(int cli_fd);
-Cli* find_cli(const int fd);
bool send_to_cli(const int fd, char* data, const int len);
bool send_to_all_ij(char* data, const int len);
bool is_ij_exist();
void stop_listen(void);
+bool epoll_ctl_add(const int fd);
+void userpool_add(int cli_fd, unsigned short cli_port, const int fdtype);
+void userpool_delete(int cli_fd);
+
struct fd_info
{
fd_info() : fd(-1){}
int fdtype;
};
+struct LXT_MESSAGE
+{
+ unsigned short length;
+ unsigned char group;
+ unsigned char action;
+ void *data;
+};
+
+typedef struct LXT_MESSAGE LXT_MESSAGE;
+
struct ijcommand
{
enum { CMD_SIZE = 48 };
LXT_MESSAGE msg;
};
-void process_evdi_command(ijcommand* ijcmd);
+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;
+};
+
+struct setting_device_param
+{
+ setting_device_param() : get_status_sockfd(-1), ActionID(0)
+ {
+ memset(type_cmd, 0, ID_SIZE);
+ }
+ int get_status_sockfd;
+ unsigned char ActionID;
+ char type_cmd[ID_SIZE];
+};
+
bool read_ijcmd(const int fd, ijcommand* ijcmd);
+int recv_data(int event_fd, char** r_databuf, int size);
+void recv_from_evdi(evdi_fd fd);
+bool accept_proc(const int server_fd);
+
+void send_default_suspend_req(void);
+void systemcall(const char* param);
+int parse_val(char *buff, unsigned char data, char *parsbuf);
-void* setting_device(void* data);
+void msgproc_suspend(int fd, ijcommand* ijcmd);
+void msgproc_system(int fd, ijcommand* ijcmd);
+void msgproc_hds(int fd, ijcommand* ijcmd);
+void msgproc_location(int fd, ijcommand* ijcmd);
+void msgproc_sdcard(int fd, ijcommand* ijcmd);
+void* exec_cmd_thread(void *args);
+void msgproc_cmd(int fd, ijcommand* ijcmd);
-// msg proc
-bool msgproc_telephony(const int sockfd, ijcommand* ijcmd, const bool is_evdi);
-bool msgproc_pedometer(const int sockfd, ijcommand* ijcmd, const bool is_evdi);
-bool msgproc_sensor(const int sockfd, ijcommand* ijcmd, const bool is_evdi);
-bool msgproc_location(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);
+/*
+ * For the multi-profile
+ */
+void process_evdi_command(ijcommand* ijcmd);
+bool server_process(void);
+void init_profile(void);
+void exit_profile(void);
-#endif //__emuld_h__
+#endif
+++ /dev/null
-/*
- * emulator-daemon
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Jinhyung Choi <jinhyung2.choi@samsnung.com>
- * SooYoung Ha <yoosah.ha@samsnung.com>
- * Sungmin Ha <sungmin82.ha@samsung.com>
- * Daiyoung Kim <daiyoung777.kim@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-
-#ifndef __emuld_common_h__
-#define __emuld_common_h__
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <errno.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <pthread.h>
-
-// define group id
-// return value to the injector
-#define STATUS 15
-
-// define action id
-#define BATTERY_LEVEL 100
-#define BATTERY_CHARGER 101
-#define USB_STATUS 102
-#define EARJACK_STATUS 103
-#define RSSI_LEVEL 104
-
-#define ACCEL_VALUE 110
-#define GYRO_VALUE 111
-#define MAG_VALUE 112
-#define LIGHT_VALUE 113
-#define PROXI_VALUE 114
-#define MOTION_VALUE 115
-
-#define LOCATION_STATUS 120
-
-
-#define 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_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_BATTERY_CAPACITY "sys/class/power_supply/battery/capacity"
-#define PATH_BATTERY_CHARGER_ON "/sys/devices/platform/jack/charger_online"
-#define PATH_BATTERY_CHARGE_FULL "/sys/class/power_supply/battery/charge_full"
-#define PATH_BATTERY_CHARGE_NOW "/sys/class/power_supply/battery/charge_now"
-
-#define PATH_JACK_EARJACK "/sys/devices/platform/jack/earjack_online"
-#define PATH_JACK_USB "/sys/devices/platform/jack/usb_online"
-
-struct LXT_MESSAGE// lxt_message
-{
- unsigned short length;
- unsigned char group;
- unsigned char action;
- void *data;
-};
-
-typedef struct LXT_MESSAGE LXT_MESSAGE;
-
-// Device
-char* get_battery_level(void* , bool);
-char* get_battery_charger(void* , bool);
-char* get_usb_status(void* , bool);
-char* get_earjack_status(void* , bool);
-char* get_rssi_level(void* , bool);
-
-void device_parser(char*);
-
-// Sensor
-char* get_proximity_status(void* , bool);
-char* get_light_level(void* , bool);
-char* get_acceleration_value(void* , bool);
-char* get_gyroscope_value(void* , bool);
-char* get_magnetic_value(void* , bool);
-
-// Location
-char* get_location_status(void* , bool);
-
-// SD Card
-int is_mounted(void);
-void* mount_sdcard(void* data);
-int umount_sdcard(const int fd);
-
-void send_guest_server(char* databuf);
-
-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;
-};
-
-#endif //
* Sungmin Ha <sungmin82.ha@samsung.com>
* Daiyoung Kim <daiyoung777.kim@samsung.com>
* YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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__
+#ifndef __EVDI_H__
+#define __EVDI_H__
+
+#define __MAX_BUF_SIZE 1024
+
+#include <stdarg.h>
+
+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;
+};
typedef int evdi_fd;
bool send_to_evdi(evdi_fd fd, const char* msg, const int len);
bool msg_send_to_evdi(evdi_fd fd, const char* data, const int len);
-
-
#endif
+++ /dev/null
-/*
- * emulator-daemon
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Jinhyung Choi <jinhyung2.choi@samsnung.com>
- * SooYoung Ha <yoosah.ha@samsnung.com>
- * Sungmin Ha <sungmin82.ha@samsung.com>
- * Daiyoung Kim <daiyoung777.kim@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-
-#ifndef 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_ */
--- /dev/null
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Jinhyung Choi <jinhyung2.choi@samsnung.com>
+ * SooYoung Ha <yoosah.ha@samsnung.com>
+ * Sungmin Ha <sungmin82.ha@samsung.com>
+ * Daiyoung Kim <daiyoung777.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#ifndef __MOBILE_H__
+#define __MOBILE_H__
+
+#define TID_SENSOR 5
+
+void msgproc_sensor(const int sockfd, ijcommand* ijcmd);
+
+#endif
* Sungmin Ha <sungmin82.ha@samsung.com>
* Daiyoung Kim <daiyoung777.kim@samsung.com>
* YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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
*
#define SYNBUF_H_
#include <stdbool.h>
-
+#include <stdlib.h>
class synbuf
{
m_readptr = m_buf;
}
+ ~synbuf()
+ {
+ freebuf();
+ }
+
void reset_buf()
{
freebuf();
--- /dev/null
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Jinhyung Choi <jinhyung2.choi@samsnung.com>
+ * SooYoung Ha <yoosah.ha@samsnung.com>
+ * Sungmin Ha <sungmin82.ha@samsung.com>
+ * Daiyoung Kim <daiyoung777.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#ifndef __WEARABLE_H__
+#define __WEARABLE_H__
+
+#define TID_PEDOMETER 5
+void msgproc_sensor(const int sockfd, ijcommand* ijcmd);
+
+#endif
Name: emuld
-Version: 0.5.3
+Version: 0.8.0
Release: 0
Summary: Emulator daemon
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
Group: SDK/Other
-
-%if ("%{_repository}" == "mobile")
+%if "%{?tizen_profile_name}" == "mobile"
Source1001: packaging/emuld_mobile.manifest
-%endif
-
-%if ("%{_repository}" == "wearable")
-Source1002: packaging/emuld_wearable.manifest
+%elseif "%{?tizen_profile_name}" == "wearable"
+Source1001: packaging/emuld_wearable.manifest
%endif
BuildRequires: cmake
BuildRequires: pkgconfig(deviced)
BuildRequires: pkgconfig(dlog)
-%if ("%{_repository}" == "wearable")
+%if "%{?tizen_profile_name}" == "wearable"
Requires: context-manager
%endif
-%if ("%{_repository}" == "mobile")
-BuildRequires: pkgconfig(pmapi)
-%endif
-
%description
A emulator daemon is used for communication between guest and host
%prep
%setup -q
-%if ("%{_repository}" == "mobile")
+%if "%{?tizen_profile_name}" == "mobile"
export CFLAGS+=" -DMOBILE"
+%elseif "%{?tizen_profile_name}" == "wearable"
+export CFLAGS+=" -DWEARABLE"
%endif
cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
%make_install
%clean
-%if ("%{_repository}" == "mobile")
make clean
rm -rf CMakeCache.txt
rm -rf CMakeFiles
rm -rf cmake_install.cmake
rm -rf Makefile
rm -rf install_manifest.txt
-%endif
%post
chmod 770 %{_prefix}/bin/emuld
%files
%defattr(-,root,root,-)
-%if ("%{_repository}" == "wearable")
-%manifest packaging/emuld_wearable.manifest
-%endif
-
-%if ("%{_repository}" == "mobile")
+%if "%{?tizen_profile_name}" == "mobile"
%manifest packaging/emuld_mobile.manifest
+%elseif "%{?tizen_profile_name}" == "wearable"
+%manifest packaging/emuld_wearable.manifest
%endif
%{_prefix}/bin/emuld
<manifest>
- <request>
- <domain name="_"/>
- </request>
+ <define>
+ <domain name="emuld"/>
+ <request>
+ <smack request="deviced::display" type="rw" />
+ </request>
+ </define>
+ <request>
+ <domain name="emuld" />
+ </request>
</manifest>
<define>
<domain name="emuld"/>
<request>
+ <smack request="deviced::display" type="rw" />
<smack request="context-manager" type="w" />
<smack request="system::use_internet" type="w" />
+ <smack request="system::debugging_network" type="w" />
</request>
<permit>
<smack permit="system::use_internet" type="w" />
+ <smack permit="system::debugging_network" type="w" />
</permit>
</define>
<request>
* Sungmin Ha <sungmin82.ha@samsung.com>
* Daiyoung Kim <daiyoung777.kim@samsung.com>
* YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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 <arpa/inet.h>
+#include <unistd.h>
+#include <errno.h>
#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)
LOGINFO("clipool_delete fd = %d", 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)
{
--- /dev/null
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Jinhyung Choi <jinhyung2.choi@samsnung.com>
+ * SooYoung Ha <yoosah.ha@samsnung.com>
+ * Sungmin Ha <sungmin82.ha@samsung.com>
+ * Daiyoung Kim <daiyoung777.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include <sys/time.h>
+#include <sys/reboot.h>
+#include <unistd.h>
+
+#include "emuld.h"
+#include "deviced/dd-display.h"
+
+#define PMAPI_RETRY_COUNT 3
+#define POWEROFF_DURATION 2
+
+#define IJTYPE_SUSPEND "suspend"
+
+#define SUSPEND_UNLOCK 0
+#define SUSPEND_LOCK 1
+
+static struct timeval tv_start_poweroff;
+
+void systemcall(const char* param)
+{
+ if (!param)
+ return;
+
+ if (system(param) == -1)
+ LOGERR("system call failure(command = %s)", param);
+}
+
+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 powerdown_by_force(void)
+{
+ struct timeval now;
+ int 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) {
+ LOGINFO("power down wait");
+ usleep(100000);
+ gettimeofday(&now, NULL);
+ }
+
+ LOGINFO("Power off by force");
+ LOGINFO("sync");
+
+ sync();
+
+ LOGINFO("poweroff");
+
+ reboot(RB_POWER_OFF);
+}
+
+void msgproc_system(const int sockfd, ijcommand* ijcmd)
+{
+ LOGDEBUG("msgproc_system");
+
+ LOGINFO("/etc/rc.d/rc.shutdown, sync, reboot(RB_POWER_OFF)");
+
+ sync();
+
+ systemcall("/etc/rc.d/rc.shutdown &");
+
+ gettimeofday(&tv_start_poweroff, NULL);
+
+ powerdown_by_force();
+}
+
+static void set_lock_state(int state) {
+ int i = 0;
+ int ret = 0;
+ // Now we blocking to enter "SLEEP".
+ while(i < PMAPI_RETRY_COUNT ) {
+ ret = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
+ LOGINFO("display_lock_state() return: %d", ret);
+ if(ret == 0)
+ {
+ break;
+ }
+ ++i;
+ sleep(10);
+ }
+ if (i == PMAPI_RETRY_COUNT) {
+ LOGERR("Emulator Daemon: Failed to call display_lock_state().\n");
+ }
+}
+
+void msgproc_suspend(int fd, ijcommand* ijcmd)
+{
+ if (ijcmd->msg.action == SUSPEND_LOCK) {
+ set_lock_state(SUSPEND_LOCK);
+ } else {
+ set_lock_state(SUSPEND_UNLOCK);
+ }
+
+ LOGINFO("[Suspend] Set lock state as %d (1: lock, other: unlock)", ijcmd->msg.action);
+}
+
+void send_default_suspend_req(void)
+{
+ LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+ if(packet == NULL){
+ return;
+ }
+ memset(packet, 0, sizeof(LXT_MESSAGE));
+
+ packet->length = 0;
+ packet->group = 5;
+ packet->action = 15;
+
+ int tmplen = HEADER_SIZE;
+ char* tmp = (char*) malloc(tmplen);
+ if (!tmp)
+ return;
+
+ memcpy(tmp, packet, HEADER_SIZE);
+
+ ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SUSPEND, (const char*) tmp, tmplen);
+
+ if (tmp)
+ free(tmp);
+ if (packet)
+ free(packet);
+}
+
+
--- /dev/null
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Jinhyung Choi <jinhyung2.choi@samsnung.com>
+ * SooYoung Ha <yoosah.ha@samsnung.com>
+ * Sungmin Ha <sungmin82.ha@samsung.com>
+ * Daiyoung Kim <daiyoung777.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include <sys/mount.h>
+#include <errno.h>
+#include <unistd.h>
+
+// SD Card
+#include <dirent.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <mntent.h>
+
+// Location
+#include <vconf/vconf.h>
+#include <vconf/vconf-keys.h>
+
+// Common
+#include <unistd.h>
+#include "emuld.h"
+
+static pthread_mutex_t mutex_cmd = PTHREAD_MUTEX_INITIALIZER;
+
+// SDCard
+#define IJTYPE_SDCARD "sdcard"
+
+// HDS
+#define IJTYPE_HDS "hds"
+
+char SDpath[256];
+
+// Location
+#define STATUS 15
+#define LOCATION_STATUS 120
+char command[512];
+
+/*
+ * SD Card functions
+ */
+
+struct mount_param
+{
+ mount_param(int _fd) : fd(_fd) {}
+ int fd;
+};
+
+char* get_mount_info() {
+ struct mntent *ent;
+ FILE *aFile;
+
+ aFile = setmntent("/proc/mounts", "r");
+ if (aFile == NULL) {
+ LOGERR("/proc/mounts is not exist");
+ return NULL;
+ }
+ char* mountinfo = new char[512];
+ memset(mountinfo, 0, 512);
+
+ while (NULL != (ent = getmntent(aFile))) {
+
+ if (strcmp(ent->mnt_dir, "/opt/storage/sdcard") == 0)
+ {
+ LOGDEBUG(",%s,%s,%d,%s,%d,%s",
+ ent->mnt_fsname, ent->mnt_dir, ent->mnt_freq, ent->mnt_opts, ent->mnt_passno, ent->mnt_type);
+ sprintf(mountinfo,",%s,%s,%d,%s,%d,%s\n",
+ ent->mnt_fsname, ent->mnt_dir, ent->mnt_freq, ent->mnt_opts, ent->mnt_passno, ent->mnt_type);
+ break;
+ }
+ }
+ endmntent(aFile);
+
+ return mountinfo;
+}
+
+int is_mounted()
+{
+ int ret = -1, i = 0;
+ struct stat buf;
+ char file_name[128];
+ memset(file_name, '\0', sizeof(file_name));
+
+ for(i = 0; i < 10; i++)
+ {
+ sprintf(file_name, "/dev/mmcblk%d", i);
+ ret = access(file_name, F_OK);
+ if( ret == 0 )
+ {
+ lstat(file_name, &buf);
+ if(S_ISBLK(buf.st_mode))
+ return 1;
+ else
+ return 0;
+ }
+ }
+
+ return 0;
+}
+
+void* mount_sdcard(void* data)
+{
+ mount_param* param = (mount_param*) data;
+
+ int ret = -1, i = 0;
+ struct stat buf;
+ char file_name[128], command[256];
+ memset(file_name, '\0', sizeof(file_name));
+ memset(command, '\0', sizeof(command));
+
+ LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+ memset(packet, 0, sizeof(LXT_MESSAGE));
+
+ LOGINFO("start sdcard mount thread");
+
+ pthread_detach(pthread_self());
+
+ while (ret < 0)
+ {
+ for (i = 0; i < 10; i++)
+ {
+ sprintf(file_name, "/dev/mmcblk%d", i);
+ ret = access( file_name, F_OK );
+ if( ret == 0 )
+ {
+ lstat(file_name, &buf);
+ if(!S_ISBLK(buf.st_mode))
+ {
+ sprintf(command, "rm -rf %s", file_name);
+ systemcall(command);
+ }
+ else
+ break;
+ }
+ }
+
+ if (i != 10)
+ {
+ LOGDEBUG( "%s is exist", file_name);
+ packet->length = strlen(SDpath); // length
+ packet->group = 11; // sdcard
+ if (ret == 0)
+ packet->action = 1; // mounted
+ else
+ packet->action = 5; // failed
+
+ //
+ LOGDEBUG("SDpath is %s", SDpath);
+
+ const int tmplen = HEADER_SIZE + packet->length;
+ char* tmp = (char*) malloc(tmplen);
+
+ if (tmp)
+ {
+ memcpy(tmp, packet, HEADER_SIZE);
+ if (packet->length > 0)
+ {
+ memcpy(tmp + HEADER_SIZE, SDpath, packet->length);
+ }
+
+ ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
+
+ free(tmp);
+ }
+
+ break;
+ }
+ else
+ {
+ LOGERR( "%s is not exist", file_name);
+ }
+ }
+
+ if(packet)
+ {
+ free(packet);
+ packet = NULL;
+ }
+
+ if (param)
+ {
+ delete param;
+ param = NULL;
+ }
+ pthread_exit((void *) 0);
+}
+
+int umount_sdcard(const int fd)
+{
+ int ret = -1, i = 0;
+ char file_name[128];
+ memset(file_name, '\0', sizeof(file_name));
+
+ LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+ if(packet == NULL){
+ return ret;
+ }
+ memset(packet, 0, sizeof(LXT_MESSAGE));
+
+ LOGINFO("start sdcard umount");
+
+ pthread_cancel(tid[TID_SDCARD]);
+
+ for (i = 0; i < 10; i++)
+ {
+ sprintf(file_name, "/dev/mmcblk%d", i);
+ ret = access(file_name, F_OK);
+ if (ret == 0)
+ {
+ LOGDEBUG("SDpath is %s", SDpath);
+
+ packet->length = strlen(SDpath); // length
+ packet->group = 11; // sdcard
+ packet->action = 0; // unmounted
+
+ const int tmplen = HEADER_SIZE + packet->length;
+ char* tmp = (char*) malloc(tmplen);
+ if (!tmp)
+ break;
+
+ memcpy(tmp, packet, HEADER_SIZE);
+ memcpy(tmp + HEADER_SIZE, SDpath, packet->length);
+
+ ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
+
+ free(tmp);
+
+ memset(SDpath, '\0', sizeof(SDpath));
+ sprintf(SDpath, "umounted");
+
+ break;
+ }
+ else
+ {
+ LOGERR( "%s is not exist", file_name);
+ }
+ }
+
+ if(packet){
+ free(packet);
+ packet = NULL;
+ }
+ return ret;
+}
+
+
+void msgproc_sdcard(const int sockfd, ijcommand* ijcmd)
+{
+ LOGDEBUG("msgproc_sdcard");
+
+ const int tmpsize = ijcmd->msg.length;
+
+ char token[] = "\n";
+ char tmpdata[tmpsize];
+ memcpy(tmpdata, ijcmd->data, tmpsize);
+
+ char* ret = NULL;
+ ret = strtok(tmpdata, token);
+
+ LOGDEBUG("%s", ret);
+
+ int mount_val = atoi(ret);
+ int mount_status = 0;
+
+ switch (mount_val)
+ {
+ case 0: // umount
+ {
+ mount_status = umount_sdcard(sockfd);
+ }
+ break;
+ case 1: // mount
+ {
+ memset(SDpath, '\0', sizeof(SDpath));
+ ret = strtok(NULL, token);
+ strcpy(SDpath, ret);
+ LOGDEBUG("sdcard path is %s", SDpath);
+
+ mount_param* param = new mount_param(sockfd);
+ if (!param)
+ break;
+
+ if (pthread_create(&tid[TID_SDCARD], NULL, mount_sdcard, (void*) param) != 0)
+ LOGERR("mount sdcard pthread create fail!");
+ }
+
+ break;
+ case 2: // mount status
+ {
+ mount_status = is_mounted();
+ LXT_MESSAGE* mntData = (LXT_MESSAGE*) malloc(sizeof(LXT_MESSAGE));
+ if (mntData == NULL)
+ {
+ break;
+ }
+ memset(mntData, 0, sizeof(LXT_MESSAGE));
+
+ mntData->length = strlen(SDpath); // length
+ mntData->group = 11; // sdcard
+
+ LOGDEBUG("SDpath is %s", SDpath);
+
+ switch (mount_status)
+ {
+ case 0:
+ {
+ mntData->action = 2; // umounted status
+
+ const int tmplen = HEADER_SIZE + mntData->length;
+ char* tmp = (char*) malloc(tmplen);
+
+ if (tmp)
+ {
+ memcpy(tmp, mntData, HEADER_SIZE);
+ if (mntData->length > 0)
+ {
+ memcpy(tmp + HEADER_SIZE, SDpath, mntData->length);
+ }
+
+ ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
+
+ free(tmp);
+ }
+
+ memset(SDpath, '\0', sizeof(SDpath));
+ sprintf(SDpath, "umounted");
+ }
+ break;
+ case 1:
+ {
+ mntData->action = 3; // mounted status
+
+ int mountinfo_size = 0;
+ char* mountinfo = get_mount_info();
+ if (mountinfo)
+ {
+ mountinfo_size = strlen(mountinfo);
+ }
+
+ const int tmplen = HEADER_SIZE + mntData->length + mountinfo_size;
+ char* tmp = (char*) malloc(tmplen);
+
+ if (tmp)
+ {
+ memcpy(tmp, mntData, HEADER_SIZE);
+ if (mntData->length > 0)
+ {
+ memcpy(tmp + HEADER_SIZE, SDpath, mntData->length);
+ }
+
+ if (mountinfo)
+ {
+ memcpy(tmp + HEADER_SIZE + mntData->length, mountinfo, mountinfo_size);
+ mntData->length += mountinfo_size;
+ memcpy(tmp, mntData, HEADER_SIZE);
+ delete mountinfo;
+ mountinfo = NULL;
+ }
+
+ ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
+
+ free(tmp);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ free(mntData);
+ }
+ break;
+ default:
+ LOGERR("unknown data %s", ret);
+ break;
+ }
+}
+
+void* exec_cmd_thread(void *args)
+{
+ char *command = (char*)args;
+
+ systemcall(command);
+ LOGDEBUG("executed cmd: %s", command);
+ free(command);
+
+ pthread_exit(NULL);
+}
+
+void msgproc_cmd(int fd, ijcommand* ijcmd)
+{
+ _auto_mutex _(&mutex_cmd);
+ pthread_t cmd_thread_id;
+ char *cmd = (char*) malloc(ijcmd->msg.length + 1);
+
+ memset(cmd, 0x00, sizeof(cmd));
+ strncpy(cmd, ijcmd->data, ijcmd->msg.length);
+ LOGDEBUG("cmd: %s, length: %d", cmd, ijcmd->msg.length);
+
+ if (pthread_create(&cmd_thread_id, NULL, exec_cmd_thread, (void*)cmd) != 0)
+ {
+ LOGERR("cmd pthread create fail!");
+ }
+}
+
+/*
+ * Location function
+ */
+static char* get_location_status(void* p)
+{
+ 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;
+ double altitude;
+ double accuracy;
+ 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;
+ }
+ ret = vconf_get_dbl("db/location/replay/ManualAltitude", &altitude);
+ if (ret != 0) {
+ return 0;
+ }
+ ret = vconf_get_dbl("db/location/replay/ManualHAccuracy", &accuracy);
+ if (ret != 0) {
+ return 0;
+ }
+
+ message = (char*)malloc(128);
+ memset(message, 0, 128);
+ ret = sprintf(message, "%d,%f,%f,%f,%f", mode, latitude, logitude, altitude, accuracy);
+ 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;
+}
+
+static void* getting_location(void* data)
+{
+ pthread_detach(pthread_self());
+
+ setting_device_param* param = (setting_device_param*) data;
+
+ if (!param)
+ return 0;
+
+ char* msg = 0;
+ LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+
+ switch(param->ActionID)
+ {
+ case LOCATION_STATUS:
+ msg = get_location_status((void*)packet);
+ if (msg == 0) {
+ LOGERR("failed getting location status");
+ }
+ break;
+ default:
+ LOGERR("Wrong action ID. %d", param->ActionID);
+ break;
+ }
+
+ if (msg == 0)
+ {
+ LOGDEBUG("send error message to injector");
+ memset(packet, 0, sizeof(LXT_MESSAGE));
+ packet->length = 0;
+ packet->group = STATUS;
+ packet->action = param->ActionID;
+ }
+ else
+ {
+ LOGDEBUG("send data to injector");
+ }
+
+ const int tmplen = HEADER_SIZE + packet->length;
+ char* tmp = (char*) malloc(tmplen);
+ if (tmp)
+ {
+ memcpy(tmp, packet, HEADER_SIZE);
+ if (packet->length > 0)
+ memcpy(tmp + HEADER_SIZE, msg, packet->length);
+
+ ijmsg_send_to_evdi(g_fd[fdtype_device], param->type_cmd, (const char*) tmp, tmplen);
+
+ free(tmp);
+ }
+
+ if(msg != 0)
+ {
+ free(msg);
+ msg = 0;
+ }
+ if (packet)
+ {
+ free(packet);
+ packet = NULL;
+ }
+
+ if (param)
+ delete param;
+
+ pthread_exit((void *) 0);
+}
+
+void setting_location(char* databuf)
+{
+ char* s = strchr(databuf, ',');
+ memset(command, 0, 256);
+ if (s == NULL) { // SET MODE
+ int mode = atoi(databuf);
+ switch (mode) {
+ case 0: // STOP MODE
+ sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 0 -f");
+ break;
+ case 1: // NMEA MODE (LOG MODE)
+ sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 1 -f");
+ break;
+ case 2: // MANUAL MODE
+ sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 2 -f");
+ break;
+ default:
+ LOGERR("error(%s) : stop replay mode", databuf);
+ sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 0 -f");
+ break;
+ }
+ LOGDEBUG("Location Command : %s", command);
+ systemcall(command);
+ } else {
+ *s = '\0';
+ int mode = atoi(databuf);
+ if(mode == 1) { // NMEA MODE (LOG MODE)
+ sprintf(command, "vconftool set -t string db/location/replay/FileName \"%s\"", s+1);
+ LOGDEBUG("%s", command);
+ systemcall(command);
+ memset(command, 0, 256);
+ sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 1 -f");
+ LOGDEBUG("%s", command);
+ systemcall(command);
+ } else if(mode == 2) {
+ char* ptr = strtok(s+1, ",");
+
+ // Latitude
+ sprintf(command, "vconftool set -t double db/location/replay/ManualLatitude %s -f", ptr);
+ LOGINFO("%s", command);
+ systemcall(command);
+
+ // Longitude
+ ptr = strtok(NULL, ",");
+ sprintf(command, "vconftool set -t double db/location/replay/ManualLongitude %s -f", ptr);
+ LOGINFO("%s", command);
+ systemcall(command);
+
+ // Altitude
+ ptr = strtok(NULL, ",");
+ sprintf(command, "vconftool set -t double db/location/replay/ManualAltitude %s -f", ptr);
+ LOGINFO("%s", command);
+ systemcall(command);
+
+ // accuracy
+ ptr = strtok(NULL, ",");
+ sprintf(command, "vconftool set -t double db/location/replay/ManualHAccuracy %s -f", ptr);
+ LOGINFO("%s", command);
+ systemcall(command);
+ }
+ }
+}
+
+void msgproc_location(const int sockfd, ijcommand* ijcmd)
+{
+ LOGDEBUG("msgproc_location");
+ if (ijcmd->msg.group == STATUS)
+ {
+ setting_device_param* param = new setting_device_param();
+ if (!param)
+ return;
+
+ param->get_status_sockfd = sockfd;
+ param->ActionID = ijcmd->msg.action;
+ memcpy(param->type_cmd, ijcmd->cmd, ID_SIZE);
+
+ if (pthread_create(&tid[TID_LOCATION], NULL, getting_location, (void*) param) != 0)
+ {
+ LOGERR("location pthread create fail!");
+ return;
+ }
+ }
+ else
+ {
+ setting_location(ijcmd->data);
+ }
+}
+
+static char* make_header_msg(int group, int action)
+{
+ char *tmp = (char*) malloc(HEADER_SIZE);
+ if (!tmp)
+ return NULL;
+
+ memset(tmp, 0, HEADER_SIZE);
+
+ memcpy(tmp + 2, &group, 1);
+ memcpy(tmp + 3, &action, 1);
+
+ return tmp;
+}
+
+#define MSG_GROUP_HDS 100
+
+void* mount_hds(void* data)
+{
+ int i, ret = 0;
+ char* tmp;
+ int group, action;
+
+ LOGINFO("start hds mount thread");
+
+ pthread_detach(pthread_self());
+
+ usleep(500000);
+
+ for (i = 0; i < 20; i++)
+ {
+ ret = mount("fileshare", "/mnt/host", "9p", 0,
+ "trans=virtio,version=9p2000.L,msize=65536");
+ if(ret == 0) {
+ action = 1;
+ break;
+ } else {
+ LOGERR("%d trial: mount is failed with errno: %d", i, errno);
+ }
+ usleep(500000);
+ }
+
+ group = MSG_GROUP_HDS;
+
+ if (i == 20 || ret != 0)
+ action = 2;
+
+ tmp = make_header_msg(group, action);
+ if (!tmp) {
+ LOGERR("failed to alloc: out of resource.");
+ pthread_exit((void *) 0);
+ return NULL;
+ }
+
+ ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_HDS, (const char*) tmp, HEADER_SIZE);
+
+ free(tmp);
+
+ pthread_exit((void *) 0);
+}
+
+int umount_hds(void)
+{
+ int ret = 0;
+ char* tmp;
+ int group, action;
+
+ pthread_cancel(tid[TID_HDS]);
+
+ LOGINFO("unmount /mnt/host.");
+
+ ret = umount("/mnt/host");
+ if (ret != 0) {
+ LOGERR("unmount failed with error num: %d", errno);
+ action = 4;
+ } else {
+ action = 3;
+ }
+
+ group = MSG_GROUP_HDS;
+
+ tmp = make_header_msg(group, action);
+ if (!tmp) {
+ LOGERR("failed to alloc: out of resource.");
+ return -1;
+ }
+
+ LOGINFO("send result with action %d to evdi", action);
+
+ ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_HDS, (const char*) tmp, HEADER_SIZE);
+
+ free(tmp);
+
+ return 0;
+}
+
+void msgproc_hds(const int sockfd, ijcommand* ijcmd)
+{
+ LOGDEBUG("msgproc_hds");
+
+ if (ijcmd->msg.action == 1) {
+ if (pthread_create(&tid[TID_HDS], NULL, mount_hds, NULL) != 0)
+ LOGERR("mount hds pthread create fail!");
+ } else if (ijcmd->msg.action == 2) {
+ umount_hds();
+ } else {
+ LOGERR("unknown action cmd.");
+ }
+}
+
+
+++ /dev/null
-/*
- * emulator-daemon
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Jinhyung Choi <jinhyung2.choi@samsnung.com>
- * SooYoung Ha <yoosah.ha@samsnung.com>
- * Sungmin Ha <sungmin82.ha@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <limits.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <pthread.h>
-#include <stdarg.h>
-
-#include <vconf/vconf.h>
-#include <vconf/vconf-keys.h>
-
-#include "emuld.h"
-#include "emuld_common.h"
-
-static int battery_level = 50;
-
-pthread_t d_tid[16];
-
-struct appdata
-{
- void* data;
-};
-struct appdata ad;
-
-typedef struct
-{
- int len;
- int repeatCnt;
- int fileCnt;
- char *buffer;
-} FileInput_args;
-
-typedef struct
-{
- char filename[256];
-} FileInput_files;
-
-enum sensor_type{
- MOTION = 6,
- USBKEYBOARD = 7,
- BATTERYLEVEL = 8,
- EARJACK = 9,
- USB = 10,
- RSSI = 11,
- FILE_ACCEL = 14,
- FILE_MAGNETIC = 15,
- FILE_GYRO = 16
-};
-
-enum motion_doubletap{
- SENSOR_MOTION_DOUBLETAP_NONE = 0,
- SENSOR_MOTION_DOUBLETAP_DETECTION = 1
-};
-
-enum motion_shake{
- SENSOR_MOTION_SHAKE_NONE = 0,
- SENSOR_MOTION_SHAKE_DETECTED = 1,
- SENSOR_MOTION_SHAKE_CONTINUING = 2,
- SENSOR_MOTION_SHAKE_FINISHED = 3,
- SENSOR_MOTION_SHAKE_BREAK = 4
-};
-
-enum motion_snap{
- SENSOR_MOTION_SNAP_NONE = 0,
- SENSOR_MOTION_SNAP_NEGATIVE_X = 1,
- SENSOR_MOTION_SNAP_POSITIVE_X = 2,
- SENSOR_MOTION_SNAP_NEGATIVE_Y = 3,
- SENSOR_MOTION_SNAP_POSITIVE_Y = 4,
- SENSOR_MOTION_SNAP_NEGATIVE_Z = 5,
- SENSOR_MOTION_SNAP_POSITIVE_Z = 6,
- SENSOR_MOTION_SNAP_LEFT = SENSOR_MOTION_SNAP_NEGATIVE_X,
- SENSOR_MOTION_SNAP_RIGHT = SENSOR_MOTION_SNAP_POSITIVE_X
-};
-
-enum motion_move{
- SENSOR_MOTION_MOVE_NONE = 0,
- SENSOR_MOTION_MOVE_MOVETOCALL = 1
-};
-
-int check_nodes();
-
-int parse_motion_data(int len, char *buffer);
-int parse_usbkeyboard_data(int len, char *buffer);
-int parse_batterylevel_data(int len, char *buffer);
-int parse_earjack_data(int len, char *buffer);
-int parse_rssi_data(int len, char *buffer);
-
-static void system_cmd(const char* msg)
-{
- int ret = system(msg);
- if (ret == -1) {
- LOGERR("system command is failed: %s", msg);
- }
-}
-
-int parse_motion_data(int len, char *buffer)
-{
- int len1=0;
- char tmpbuf[255];
- int x;
- char command[128];
- memset(command, '\0', sizeof(command));
-
- LOGDEBUG("read data: %s", buffer);
-
- // read param count
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- /* first data */
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- x = atoi(tmpbuf);
-
- switch(x)
- {
- case 1: // double tap
- sprintf(command, "vconftool set -t int memory/private/sensor/800004 %d -i -f", SENSOR_MOTION_DOUBLETAP_DETECTION);
- system_cmd(command);
- // memset(command, '\0', sizeof(command));
- // sprintf(command, "vconftool set -t int memory/private/sensor/800004 %d -i -f", SENSOR_MOTION_DOUBLETAP_NONE);
- // system_cmd(command);
- break;
- case 2: // shake start
- sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_DETECTED);
- system_cmd(command);
- memset(command, '\0', sizeof(command));
- sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_CONTINUING);
- system_cmd(command);
- break;
- case 3: // shake stop
- sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_FINISHED);
- system_cmd(command);
- break;
- case 4: // snap x+
- sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_X);
- system_cmd(command);
- break;
- case 5: // snap x-
- sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_X);
- system_cmd(command);
- break;
- case 6: // snap y+
- sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_Y);
- system_cmd(command);
- break;
- case 7: // snap y-
- sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_Y);
- system_cmd(command);
- break;
- case 8: // snap z+
- sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_Z);
- system_cmd(command);
- break;
- case 9: // snap z-
- sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_Z);
- system_cmd(command);
- break;
- case 10: // snap left
- sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_X);
- system_cmd(command);
- break;
- case 11: // snap right
- sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_X);
- system_cmd(command);
- break;
- case 12: // move to call (direct call)
- sprintf(command, "vconftool set -t int memory/private/sensor/800020 %d -i -f", SENSOR_MOTION_MOVE_MOVETOCALL);
- system_cmd(command);
- break;
- default:
- LOGERR("not supported activity");
- break;
- }
-
- return 0;
-}
-
-int parse_usbkeyboard_data(int len, char *buffer)
-{
- int len1=0;
- char tmpbuf[255];
- int x;
-
- LOGDEBUG("read data: %s", buffer);
-
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- x = atoi(tmpbuf);
-
- if(x == 1)
- {
- system_cmd("udevadm trigger --subsystem-match=input --sysname-match=event3 --action=add");
- }
- else if(x == 0)
- {
- system_cmd("udevadm trigger --subsystem-match=input --sysname-match=event3 --action=remove");
- }
- else
- assert(0);
-
- return 0;
-}
-
-int parse_batterylevel_data(int len, char *buffer)
-{
- int len1=0, id = 0, ret = 0;
- char tmpbuf[255];
- int level = 0, charger = 0, charger_online = 0, charge_full = 0;
- FILE* fd;
-
- LOGDEBUG("read data: %s", buffer);
-
- // read param count
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- /* first data */
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- id = atoi(tmpbuf);
- if(id == 1) // level
- {
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- level = atoi(tmpbuf);
- battery_level = level;
-
- if(level == 100)
- {
- charger = 0;
- }
- else
- {
- charger = 1;
- }
-
- fd = fopen(PATH_BATTERY_CAPACITY, "w");
- if(!fd)
- {
- LOGERR("fopen fail");
- return -1;
- }
- fprintf(fd, "%d", level);
- fclose(fd);
-
- fd = fopen(PATH_BATTERY_CHARGER_ON, "r");
- if(!fd)
- {
- LOGERR("fopen fail");
- return -1;
- }
- ret = fscanf(fd, "%d", &charger_online);
- fclose(fd);
- if (ret < 0)
- {
- LOGERR("failed to get charger_online value");
- return -1;
- }
-
- LOGDEBUG("charge_online: %d", charger_online);
-
- if(charger_online == 1 && level == 100)
- {
- charge_full = 1;
- }
- else
- {
- charge_full = 0;
- }
- LOGDEBUG("charge_full: %d", charge_full);
-
- fd = fopen(PATH_BATTERY_CHARGE_FULL, "w");
- if(!fd)
- {
- LOGERR("charge_full fopen fail");
- return -1;
- }
- fprintf(fd, "%d", charge_full);
- fclose(fd);
-
- if(charger_online == 1)
- {
- fd = fopen(PATH_BATTERY_CHARGE_NOW, "w");
- if(!fd)
- {
- LOGERR("charge_now fopen fail");
- return -1;
- }
- fprintf(fd, "%d", charger);
- fclose(fd);
- }
-
- // because time based polling
- system_cmd("/usr/bin/sys_event device_charge_chgdet");
- }
- else if(id == 2)
- {
- /* second data */
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- charger = atoi(tmpbuf);
- fd = fopen(PATH_BATTERY_CHARGER_ON, "w");
- if(!fd)
- {
- LOGERR("charger_online fopen fail");
- return -1;
- }
- fprintf(fd, "%d", charger);
- fclose(fd);
-
- fd = fopen(PATH_BATTERY_CHARGE_FULL, "w");
- if(!fd)
- {
- LOGERR("charge_full fopen fail");
- return -1;
- }
-
- if(battery_level == 100 && charger == 1)
- {
- fprintf(fd, "%d", 1); // charge full
- charger = 0;
- }
- else
- {
- fprintf(fd, "%d", 0);
- }
- fclose(fd);
-
- system_cmd("/usr/bin/sys_event device_charge_chgdet");
-
- fd = fopen(PATH_BATTERY_CHARGE_NOW, "w");
- if(!fd)
- {
- LOGERR("charge_now fopen fail");
- return -1;
- }
- fprintf(fd, "%d", charger);
- fclose(fd);
-
- // because time based polling
- system_cmd("/usr/bin/sys_event device_ta_chgdet");
- }
-
- return 0;
-}
-
-int parse_earjack_data(int len, char *buffer)
-{
- int len1=0;
- char tmpbuf[255];
- int x;
- FILE* fd;
-
- LOGDEBUG("read data: %s", buffer);
-
- // read param count
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- /* first data */
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- x = atoi(tmpbuf);
-
- fd = fopen(PATH_JACK_EARJACK, "w");
- if(!fd)
- {
- LOGERR("earjack_online fopen fail");
- return -1;
- }
- fprintf(fd, "%d", x);
- fclose(fd);
-
- // because time based polling
- system_cmd("/usr/bin/sys_event device_earjack_chgdet");
-
- return 0;
-}
-
-int parse_usb_data(int len, char *buffer)
-{
- int len1=0;
- char tmpbuf[255];
- int x;
- FILE* fd;
-
- LOGDEBUG("read data: %s", buffer);
-
- // read param count
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- /* first data */
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- x = atoi(tmpbuf);
-
- fd = fopen(PATH_JACK_USB, "w");
- if(!fd)
- {
- LOGERR("usb_online fopen fail");
- return -1;
- }
- fprintf(fd, "%d", x);
- fclose(fd);
-
- // because time based polling
- system_cmd("/usr/bin/sys_event device_usb_chgdet");
- return 0;
-}
-
-int parse_rssi_data(int len, char *buffer)
-{
- int len1=0;
- char tmpbuf[255];
- int x;
- char command[128];
- memset(command, '\0', sizeof(command));
-
- LOGDEBUG("read data: %s", buffer);
-
- // read param count
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- /* first data */
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- x = atoi(tmpbuf);
-
- sprintf(command, "vconftool set -t int memory/telephony/rssi %d -i -f", x);
- system_cmd(command);
-
- return 0;
-}
-
-void* file_input_accel(void* param)
-{
- FILE* srcFD;
- FILE* dstFD;
-
- int len1 = 0, fileCnt = 0, repeatCnt = 0, prevTime = 0, nextTime = 0, sleepTime = 0, x, y, z;
- int waitCnt = 0;
- double g = 9.80665;
-
- char tmpbuf[255];
- char token[] = ",";
- char* ret = NULL;
- char command[255];
- char lineData[1024];
-
- FileInput_args* args = (FileInput_args*)param;
- FileInput_files fname[args->fileCnt];
- memset(fname, '\0', sizeof(fname));
-
- pthread_detach(pthread_self());
-
- LOGINFO("file_input_accel start");
-
- // save file names
- for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
- {
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(args->buffer+args->len, 0x0a, tmpbuf);
- args->len += len1;
-
- strcpy(fname[fileCnt].filename, tmpbuf);
- LOGINFO("saved file name: %s", fname[fileCnt].filename);
- }
-
- // play files
- for(repeatCnt = 0; repeatCnt < args->repeatCnt; repeatCnt++)
- {
- for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
- {
- memset(command, '\0', sizeof(command));
- sprintf(command, "/tmp/accel/InputFiles/%s", fname[fileCnt].filename);
- command[strlen(command) - 1] = 0x00; // erase '\n' for fopen
- LOGINFO("fopen command: %s", command);
-
- waitCnt = 0;
- while(access(command, F_OK) != 0 && waitCnt < 3)
- {
- usleep(10000);
- waitCnt++;
- }
-
- srcFD = fopen(command, "r");
- if(!srcFD)
- {
- LOGINFO("fopen fail");
- pthread_exit((void *) 0);
- }
-
- prevTime = 0;
- nextTime = 0;
-
- memset(lineData, '\0', sizeof(lineData));
- while(fgets(lineData, 1024, srcFD) != NULL)
- {
- ret = strtok(lineData, token);
- if(!ret)
- {
- LOGINFO("data is NULL");
- nextTime = prevTime + 1;
- }
- else
- nextTime = atoi(ret);
-
- sleepTime = (nextTime - prevTime) * 10000;
- if(sleepTime < 0)
- {
- sleepTime = 10000;
- nextTime = prevTime + 1;
- }
-
- usleep(sleepTime); // convert millisecond
- prevTime = nextTime;
-
- ret = strtok(NULL, token);
- if(!ret)
- {
- LOGINFO("x data is NULL");
- x = 0;
- }
- else
- x = (int)(atof(ret) * g * -100000);
-
- if (x > 1961330)
- x = 1961330;
- if (x < -1961330)
- x = -1961330;
- LOGINFO("x: %d", x);
-
- ret = strtok(NULL, token);
- if(!ret)
- {
- LOGINFO("y data is NULL");
- y = 0;
- }
- else
- y = (int)(atof(ret) * g * -100000);
-
- if (y > 1961330)
- y = 1961330;
- if (y < -1961330)
- y = -1961330;
- LOGINFO("y: %d", y);
-
- ret = strtok(NULL, token);
- if(!ret)
- {
- LOGINFO("data is NULL");
- z = 0;
- }
- else
- z = (int)(atof(ret) * g * -100000);
-
- if (z > 1961330)
- z = 1961330;
- if (z < -1961330)
- z = -1961330;
- LOGINFO("z: %d", z);
-
- dstFD = fopen(PATH_SENSOR_ACCEL_XYZ, "w");
- if(!dstFD)
- {
- LOGINFO("fopen fail");
- pthread_exit((void *) 0);
- }
- fprintf(dstFD, "%d, %d, %d",x, y, z);
- fclose(dstFD);
- }
-
- fclose(srcFD);
- }
- }
-
- LOGINFO("thread exit");
- system_cmd("rm -rf /tmp/accel/InputFiles/*");
-
- pthread_exit((void *) 0);
-}
-
-int parse_file_accel_data(int len, char *buffer)
-{
- int len1=0, repeat = -1;
- char tmpbuf[255];
-
- LOGDEBUG("read data: %s", buffer);
-
- // read start/stop
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- repeat = atoi(tmpbuf);
-
- pthread_cancel(d_tid[0]);
-
- if(repeat == 0) // stop
- {
- system_cmd("rm -rf /tmp/accel/InputFiles/*");
- }
- else // start
- {
- // read file count
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- FileInput_args args;
- args.len = len;
- args.repeatCnt = repeat;
- args.fileCnt = atoi(tmpbuf);
- args.buffer = buffer;
- if(pthread_create(&d_tid[0], NULL, file_input_accel, &args) != 0) {
- LOGERR("pthread create fail!");
- }
- }
-
- return 0;
-}
-
-void* file_input_magnetic(void* param)
-{
- FILE* srcFD;
- FILE* dstFD;
-
- int len1 = 0, fileCnt = 0, repeatCnt = 0, prevTime = 0, nextTime = 0, sleepTime = 0, x, y, z;
- int waitCnt = 0;
-
- char tmpbuf[255];
- char token[] = ",";
- char* ret = NULL;
- char command[255];
- char lineData[1024];
- FileInput_args* args = (FileInput_args*) param;
- FileInput_files fname[args->fileCnt];
- memset(fname, '\0', sizeof(fname));
-
- pthread_detach(pthread_self());
-
- LOGINFO("file_input_magnetic start");
-
- // save file names
- for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
- {
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(args->buffer+args->len, 0x0a, tmpbuf);
- args->len += len1;
-
- strcpy(fname[fileCnt].filename, tmpbuf);
- LOGINFO("saved file name: %s", fname[fileCnt].filename);
- }
-
- // play files
- for(repeatCnt = 0; repeatCnt < args->repeatCnt; repeatCnt++)
- {
- for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
- {
- memset(command, '\0', sizeof(command));
- sprintf(command, "/tmp/geo/InputFiles/%s", fname[fileCnt].filename);
- command[strlen(command) - 1] = 0x00; // erase '\n' for fopen
- LOGINFO("fopen command: %s", command);
-
- waitCnt = 0;
- while(access(command, F_OK) != 0 && waitCnt < 3)
- {
- usleep(10000);
- waitCnt++;
- }
-
- srcFD = fopen(command, "r");
- if(!srcFD)
- {
- LOGERR("fopen fail");
- pthread_exit((void *) 0);
- }
-
- prevTime = 0;
- nextTime = 0;
-
- memset(lineData, '\0', sizeof(lineData));
- while(fgets(lineData, 1024, srcFD) != NULL)
- {
- ret = strtok(lineData, token);
- if(!ret)
- {
- LOGINFO("data is NULL");
- nextTime = prevTime + 1;
- }
- else
- nextTime = atoi(ret);
-
- sleepTime = (nextTime - prevTime) * 10000;
- if(sleepTime < 0)
- {
- sleepTime = 10000;
- nextTime = prevTime + 1;
- }
-
- usleep(sleepTime); // convert millisecond
- prevTime = nextTime;
-
- ret = strtok(NULL, token);
- if(!ret)
- {
- LOGINFO("x data is NULL");
- x = 0;
- }
- else
- x = atoi(ret);
-
- if (x > 2000)
- x = 2000;
- if (x < -2000)
- x = -2000;
- LOGINFO("x: %d", x);
-
- ret = strtok(NULL, token);
- if(!ret)
- {
- LOGINFO("y data is NULL");
- y = 0;
- }
- else
- y = atoi(ret);
-
- if (y > 2000)
- y = 2000;
- if (y < -2000)
- y = -2000;
- LOGINFO("y: %d", y);
-
- ret = strtok(NULL, token);
- if(!ret)
- {
- LOGINFO("data is NULL");
- z = 0;
- }
- else
- z = atoi(ret);
-
- if (z > 2000)
- z = 2000;
- if (z < -2000)
- z = -2000;
- LOGINFO("z: %d", z);
-
- dstFD = fopen(PATH_SENSOR_GEO_TESLA, "w");
- if(!dstFD)
- {
- LOGINFO("fopen fail");
- pthread_exit((void *) 0);
- }
- fprintf(dstFD, "%d %d %d",x, y, z);
- fclose(dstFD);
- }
-
- fclose(srcFD);
- }
- }
-
- LOGINFO("thread exit");
- system_cmd("rm -rf /tmp/geo/InputFiles/*");
-
- pthread_exit((void *) 0);
-}
-
-int parse_file_magnetic_data(int len, char *buffer)
-{
- int len1=0, repeat = -1;
- char tmpbuf[255];
-
- LOGDEBUG("read data: %s", buffer);
-
- // read start/stop
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- repeat = atoi(tmpbuf);
-
- pthread_cancel(d_tid[1]);
-
- if(repeat == 0) // stop
- {
- system_cmd("rm -rf /tmp/geo/InputFiles/*");
- }
- else // start
- {
- // read file count
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- FileInput_args args;
- args.len = len;
- args.repeatCnt = repeat;
- args.fileCnt = atoi(tmpbuf);
- args.buffer = buffer;
- if(pthread_create(&d_tid[1], NULL, file_input_magnetic, &args) != 0)
- LOGINFO("pthread create fail!");
- }
-
- return 0;
-}
-
-void* file_input_gyro(void* param)
-{
- FILE* srcFD;
- FILE* dstFD;
-
- int len1 = 0, fileCnt = 0, repeatCnt = 0, prevTime = 0, nextTime = 0, sleepTime = 0, x, y, z;
- int waitCnt = 0;
-
- char tmpbuf[255];
- char token[] = ",";
- char* ret = NULL;
- char command[255];
- char lineData[1024];
- FileInput_args* args = (FileInput_args*) param;
- FileInput_files fname[args->fileCnt];
- memset(fname, '\0', sizeof(fname));
-
- pthread_detach(pthread_self());
-
- LOGINFO("file_input_gyro start");
-
- // save file names
- for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
- {
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(args->buffer+args->len, 0x0a, tmpbuf);
- args->len += len1;
-
- strcpy(fname[fileCnt].filename, tmpbuf);
- LOGINFO("saved file name: %s", fname[fileCnt].filename);
- }
-
- // play files
- for(repeatCnt = 0; repeatCnt < args->repeatCnt; repeatCnt++)
- {
- for(fileCnt = 0; fileCnt < args->fileCnt; fileCnt++)
- {
- memset(command, '\0', sizeof(command));
- sprintf(command, "/tmp/gyro/InputFiles/%s", fname[fileCnt].filename);
- command[strlen(command) - 1] = 0x00; // erase '\n' for fopen
- LOGINFO("fopen command: %s", command);
-
- waitCnt = 0;
- while(access(command, F_OK) != 0 && waitCnt < 3)
- {
- usleep(10000);
- waitCnt++;
- }
-
- srcFD = fopen(command, "r");
- if(!srcFD)
- {
- LOGINFO("fopen fail");
- pthread_exit((void *) 0);
- }
-
- prevTime = 0;
- nextTime = 0;
-
- memset(lineData, '\0', sizeof(lineData));
- while(fgets(lineData, 1024, srcFD) != NULL)
- {
- ret = strtok(lineData, token);
- if(!ret)
- {
- LOGINFO("data is NULL");
- nextTime = prevTime + 1;
- }
- else
- nextTime = atoi(ret);
-
- sleepTime = (nextTime - prevTime) * 10000;
- if(sleepTime < 0)
- {
- sleepTime = 10000;
- nextTime = prevTime + 1;
- }
-
- usleep(sleepTime); // convert millisecond
- prevTime = nextTime;
-
- ret = strtok(NULL, token);
- if(!ret)
- {
- LOGINFO("x data is NULL");
- x = 0;
- }
- else
- x = (int)(atof(ret) * 1000)/17.50;
-
- if (x > 571)
- x = 571;
- if (x < -571)
- x = -571;
- LOGINFO("x: %d", x);
-
- ret = strtok(NULL, token);
- if(!ret)
- {
- LOGINFO("y data is NULL");
- y = 0;
- }
- else
- y = (int)(atof(ret) * 1000)/17.50;
-
- if (y > 571)
- y = 571;
- if (y < -571)
- y = -571;
- LOGINFO("y: %d", y);
-
- ret = strtok(NULL, token);
- if(!ret)
- {
- LOGINFO("data is NULL");
- z = 0;
- }
- else
- z = (int)(atof(ret) * 1000)/17.50;
-
- if (z > 571)
- z = 571;
- if (z < -571)
- z = -571;
- LOGINFO("z: %d", z);
-
- dstFD = fopen(PATH_SENSOR_GYRO_X_RAW, "w");
- if(!dstFD)
- {
- LOGINFO("fopen fail");
- pthread_exit((void *) 0);
- }
- fprintf(dstFD, "%d",x);
- fclose(dstFD);
-
- dstFD = fopen(PATH_SENSOR_GYRO_Y_RAW, "w");
- if(!dstFD)
- {
- LOGINFO("fopen fail");
- pthread_exit((void *) 0);
- }
- fprintf(dstFD, "%d",y);
- fclose(dstFD);
-
- dstFD = fopen(PATH_SENSOR_GYRO_Z_RAW, "w");
- if(!dstFD)
- {
- LOGINFO("fopen fail");
- pthread_exit((void *) 0);
- }
- fprintf(dstFD, "%d",z);
- fclose(dstFD);
- }
- fclose(srcFD);
- }
- }
-
- LOGINFO("thread exit");
- system_cmd("rm -rf /tmp/gyro/InputFiles/*");
-
- pthread_exit((void *) 0);
-}
-
-int parse_file_gyro_data(int len, char *buffer)
-{
- int len1=0, repeat = -1;
- char tmpbuf[255];
-
- LOGDEBUG("read data: %s", buffer);
-
- // read start/stop
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- repeat = atoi(tmpbuf);
-
- pthread_cancel(d_tid[2]);
-
- if(repeat == 0) // stop
- {
- system_cmd("rm -rf /tmp/gyro/InputFiles/*");
- }
- else // start
- {
- // read file count
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len1 = parse_val(buffer+len, 0x0a, tmpbuf);
- len += len1;
-
- FileInput_args args;
- args.len = len;
- args.repeatCnt = repeat;
- args.fileCnt = atoi(tmpbuf);
- args.buffer = buffer;
- if(pthread_create(&d_tid[2], NULL, file_input_gyro, &args) != 0)
- LOGINFO("pthread create fail!");
- }
-
- return 0;
-}
-
-void device_parser(char *buffer)
-{
- int len = 0;
- int ret = 0;
- char tmpbuf[255];
-
- LOGDEBUG("read data: %s", buffer);
-
- // read sensor type
- memset(tmpbuf, '\0', sizeof(tmpbuf));
- len = parse_val(buffer, 0x0a, tmpbuf);
-
- switch(atoi(tmpbuf))
- {
- case MOTION:
- ret = parse_motion_data(len, buffer);
- if(ret < 0)
- LOGERR("motion parse error!");
- break;
- case USBKEYBOARD:
- ret = parse_usbkeyboard_data(len, buffer);
- if(ret < 0)
- LOGERR("usbkeyboard parse error!");
- break;
- case BATTERYLEVEL:
- ret = parse_batterylevel_data(len, buffer);
- if(ret < 0)
- LOGERR("batterylevel parse error!");
- break;
- case EARJACK:
- ret = parse_earjack_data(len, buffer);
- if(ret < 0)
- LOGERR("earjack parse error!");
- break;
- case USB:
- ret = parse_usb_data(len, buffer);
- if(ret < 0)
- LOGERR("usb parse error!");
- break;
- case RSSI:
- ret = parse_rssi_data(len, buffer);
- if(ret < 0)
- LOGERR("rssi parse error!");
- break;
- case FILE_ACCEL:
- ret = parse_file_accel_data(len, buffer);
- if(ret < 0)
- LOGERR("file_accel parse error!");
- break;
- case FILE_MAGNETIC:
- ret = parse_file_magnetic_data(len, buffer);
- if(ret < 0)
- LOGERR("file_magnetic parse error!");
- break;
- case FILE_GYRO:
- ret = parse_file_gyro_data(len, buffer);
- if(ret < 0)
- LOGERR("file_gyro parse error!");
- break;
- default:
- break;
- }
-}
-
-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;
-}
-
-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;
-}
-
-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);
-}
-
-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) {
- LOGERR("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* get_usb_status(void* p, bool is_evdi)
-{
- char* message = __tmpalloc(5);
- int length = get_file_status(message, PATH_JACK_USB, 5, is_evdi);
- if (length < 0){
- LOGERR("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, PATH_JACK_EARJACK, 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* 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;
-}
-
-/*
+/*
* emulator-daemon
*
* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
* SooYoung Ha <yoosah.ha@samsnung.com>
* Sungmin Ha <sungmin82.ha@samsung.com>
* YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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_common.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.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"
+#include <queue>
/* global definition */
-unsigned short vmodem_port = VMODEM_PORT;
-
-/* global server port number */
-int g_svr_port;
-
-/* connection status between emuld and vmodem */
-static int g_vm_connect_status;
-
-pthread_t tid[MAX_CLIENT + 1];
-
-/* udp socket */
-struct sockaddr_in si_sensord_other;
-
-int g_fd[fdtype_max];
-
typedef std::queue<msg_info*> __msg_queue;
-
__msg_queue g_msgqueue;
int g_epoll_fd;
-
-static pthread_mutex_t mutex_vmconnect = PTHREAD_MUTEX_INITIALIZER;
-
+int g_fd[fdtype_max];
+pthread_t tid[MAX_CLIENT + 1];
struct epoll_event g_events[MAX_EVENTS];
-
bool exit_flag = false;
-/*----------------------------------------------------------------*/
-/* FUNCTION PART */
-/* ---------------------------------------------------------------*/
-
-void systemcall(const char* param)
-{
- if (!param)
- return;
-
- if (system(param) == -1)
- LOGERR("system call failure(command = %s)", param);
-}
-
-void set_lock_state(int state) {
- int i = 0;
- int ret = 0;
- // Now we blocking to enter "SLEEP".
- while(i < PMAPI_RETRY_COUNT ) {
- if (state == SUSPEND_LOCK) {
- ret = pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
- } else {
- ret = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
- }
- LOGINFO("pm_lock/unlock_state() return: %d", ret);
- if(ret == 0)
- {
- break;
- }
- ++i;
- sleep(10);
- }
- if (i == PMAPI_RETRY_COUNT) {
- LOGERR("Emulator Daemon: Failed to call pm_lock/unlock_state().");
- }
-}
-
-/*---------------------------------------------------------------
-function : init_data0
-io: none
-desc: initialize global client structure values
-----------------------------------------------------------------*/
-static void init_data0(void)
+static void init_fd(void)
{
register int i;
}
}
-bool is_vm_connected(void)
-{
- _auto_mutex _(&mutex_vmconnect);
-
- if (g_vm_connect_status != 1)
- return false;
-
- return true;
-}
-
-static void set_vm_connect_status(const int v)
-{
- _auto_mutex _(&mutex_vmconnect);
-
- g_vm_connect_status = v;
-}
-
bool epoll_ctl_add(const int fd)
{
struct epoll_event events;
return true;
}
-static void emuld_ready()
-{
- char buf[16];
-
- struct sockaddr_in si_other;
- int s, slen=sizeof(si_other);
- int port;
- char *ptr;
- char *temp_sdbport;
- temp_sdbport = getenv("sdb_port");
- if(temp_sdbport == NULL) {
- LOGERR("failed to get env variable from sdb_port");
- return;
- }
-
- port = strtol(temp_sdbport, &ptr, 10);
- port = port + 3;
-
- LOGINFO("guest_server port: %d", port);
-
- if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1){
- LOGERR("socket error!");
- return;
- }
-
- memset((char *) &si_other, 0, sizeof(si_other));
- si_other.sin_family = AF_INET;
- si_other.sin_port = htons(port);
- if (inet_aton(SRV_IP, &si_other.sin_addr)==0) {
- LOGERR("inet_aton() failed");
- }
-
- memset(buf, '\0', sizeof(buf));
-
- sprintf(buf, "5\n");
-
- LOGINFO("send message 5\\n to guest server");
-
- while(sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
- {
- LOGERR("sendto error! retry sendto");
- usleep(1000);
- }
- LOGINFO("emuld is ready.");
-
- close(s);
-
-}
-
-/*-------------------------------------------------------------
-function: init_server0
-io: input : integer - server port (must be positive)
-output: none
-desc : tcp/ip listening socket setting with input variable
-----------------------------------------------------------------*/
-
-static bool init_server0(int svr_port, int* ret_fd)
-{
- struct sockaddr_in serv_addr;
- int fd;
-
- *ret_fd = -1;
-
- /* Open TCP Socket */
- if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- {
- LOGERR("Server Start Fails. : Can't open stream socket");
- return false;
- }
-
- /* 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(fd, SOL_SOCKET, SO_REUSEADDR, &nSocketOpt, sizeof(nSocketOpt)) < 0)
- {
- LOGERR("Server Start Fails. : Can't set reuse address");
- goto fail;
- }
-
- /* Bind Socket */
- if (bind(fd,(struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
- {
- LOGERR("Server Start Fails. : Can't bind local address");
- goto fail;
- }
-
- /* Listening */
- if (listen(fd, 15) < 0) /* connection queue is 15. */
- {
- LOGERR("Server Start Fails. : listen failure");
- goto fail;
- }
- LOGINFO("[START] Now Server listening on port %d, EMdsockfd: %d"
- ,svr_port, fd);
-
- /* notify to qemu that emuld is ready */
- emuld_ready();
-
- if (!epoll_ctl_add(fd))
- {
- LOGERR("Epoll control fails.");
- goto fail;
- }
-
- *ret_fd = fd;
-
- return true;
-fail:
- close(fd);
- return false;
-}
-/*------------------------------- end of function init_server0 */
-
-static void* init_vm_connect(void* data)
-{
- struct sockaddr_in vm_addr;
- int ret = -1;
-
- set_vm_connect_status(0);
-
- LOGINFO("init_vm_connect start");
-
- pthread_detach(pthread_self());
- /* Open TCP Socket */
- if ((g_fd[fdtype_vmodem] = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- {
- LOGERR("Server Start Fails. : Can't open stream socket.");
- 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 && !exit_flag)
- {
- ret = connect(g_fd[fdtype_vmodem], (struct sockaddr *)&vm_addr, sizeof(vm_addr));
-
- LOGDEBUG("vm_sockfd: %d, connect ret: %d", g_fd[fdtype_vmodem], ret);
-
- if(ret < 0) {
- LOGERR("connection failed to vmodem! try.");
- sleep(1);
- }
- }
-
- epoll_ctl_add(g_fd[fdtype_vmodem]);
-
- set_vm_connect_status(1);
-
- pthread_exit((void *) 0);
-}
-
static bool epoll_init(void)
{
g_epoll_fd = epoll_create(MAX_EVENTS); // create event pool
return true;
}
-
-
-/*------------------------------- end of function epoll_init */
-
-
-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;
-}
-
-static int recv_data(int event_fd, char** r_databuf, int size)
+int recv_data(int event_fd, char** r_databuf, int size)
{
int recvd_size = 0;
int len = 0;
return recvd_size;
}
-int read_header(int fd, LXT_MESSAGE* packet)
+static int read_header(int fd, LXT_MESSAGE* packet)
{
char* readbuf = NULL;
int readed = recv_data(fd, &readbuf, HEADER_SIZE);
return true;
}
-bool read_id(const int fd, ijcommand* ijcmd)
-{
- char* readbuf = NULL;
- int readed = recv_data(fd, &readbuf, ID_SIZE);
-
- LOGDEBUG("read_id : receive size: %d", readed);
-
- if (readed <= 0)
- {
- free(readbuf);
- readbuf = NULL;
- return false;
- }
-
- LOGDEBUG("identifier: %s", readbuf);
-
- memset(ijcmd->cmd, '\0', sizeof(ijcmd->cmd));
- int parselen = parse_val(readbuf, 0x0a, ijcmd->cmd);
-
- LOGDEBUG("parse_len: %d, buf = %s, fd=%d", parselen, ijcmd->cmd, fd);
-
- if (readbuf)
- {
- free(readbuf);
- readbuf = NULL;
- }
-
- return true;
-}
-
-void recv_from_vmodem(int fd)
-{
- LOGDEBUG("recv_from_vmodem");
-
- ijcommand ijcmd;
- if (!read_ijcmd(fd, &ijcmd))
- {
- LOGINFO("fail to read ijcmd");
-
- set_vm_connect_status(0);
-
- close(fd);
-
- if (pthread_create(&tid[0], NULL, init_vm_connect, NULL) != 0)
- {
- LOGERR("pthread create fail!");
- }
- return;
- }
-
- LOGDEBUG("vmodem data length: %d", ijcmd.msg.length);
- const int tmplen = HEADER_SIZE + ijcmd.msg.length;
- char* tmp = (char*) malloc(tmplen);
-
- if (tmp)
- {
- memcpy(tmp, &ijcmd.msg, HEADER_SIZE);
- if (ijcmd.msg.length > 0)
- memcpy(tmp + HEADER_SIZE, ijcmd.data, ijcmd.msg.length);
-
- if(!ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_TELEPHONY, (const char*) tmp, tmplen)) {
- LOGERR("msg_send_to_evdi: failed");
- }
-
- free(tmp);
- }
-
- // send header to ij
- if (is_ij_exist())
- {
- send_to_all_ij((char*) &ijcmd.msg, HEADER_SIZE);
-
- if (ijcmd.msg.length > 0)
- {
- send_to_all_ij((char*) ijcmd.data, ijcmd.msg.length);
- }
- }
-}
-
-void recv_from_ij(int fd)
-{
- LOGDEBUG("recv_from_ij");
-
- ijcommand ijcmd;
-
- if (!read_id(fd, &ijcmd))
- {
- close_cli(fd);
- return;
- }
-
- // TODO : if recv 0 then close client
-
- if (!read_ijcmd(fd, &ijcmd))
- {
- LOGERR("fail to read ijcmd");
- return;
- }
-
-
- if (strncmp(ijcmd.cmd, "telephony", 9) == 0)
- {
- msgproc_telephony(fd, &ijcmd, false);
- }
- else if (strncmp(ijcmd.cmd, "sensor", 6) == 0)
- {
- msgproc_sensor(fd, &ijcmd, false);
- }
- else if (strncmp(ijcmd.cmd, "location", 8) == 0)
- {
- msgproc_location(fd, &ijcmd, false);
- }
- else if (strncmp(ijcmd.cmd, "system", 6) == 0)
- {
- msgproc_system(fd, &ijcmd, false);
- }
- else if (strncmp(ijcmd.cmd, "sdcard", 6) == 0)
- {
- msgproc_sdcard(fd, &ijcmd, false);
- }
- else
- {
- LOGERR("Unknown packet: %s", ijcmd.cmd);
- close_cli (fd);
- }
-}
-
-static bool accept_proc(const int server_fd)
-{
- struct sockaddr_in cli_addr;
- int cli_sockfd;
- int cli_len = sizeof(cli_addr);
-
- cli_sockfd = accept(server_fd, (struct sockaddr *)&cli_addr,(socklen_t *)&cli_len);
- if(cli_sockfd < 0)
- {
- LOGERR("accept error");
- return false;
- }
- else
- {
- LOGINFO("[Accept] New client connected. fd:%d, port:%d"
- ,cli_sockfd, cli_addr.sin_port);
-
- clipool_add(cli_sockfd, cli_addr.sin_port, fdtype_ij);
- epoll_ctl_add(cli_sockfd);
- }
- return true;
-}
-
-static void msgproc_suspend(int fd, ijcommand* ijcmd, bool evdi)
-{
- if (ijcmd->msg.action == SUSPEND_LOCK) {
- set_lock_state(SUSPEND_LOCK);
- } else {
- set_lock_state(SUSPEND_UNLOCK);
- }
-
- LOGINFO("[Suspend] Set lock state as %d (1: lock, other: unlock)", ijcmd->msg.action);
-}
-
-static void send_default_suspend_req(void)
-{
- LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
- if(packet == NULL){
- return;
- }
- memset(packet, 0, sizeof(LXT_MESSAGE));
-
- packet->length = 0;
- packet->group = 5;
- packet->action = 15;
-
- int tmplen = HEADER_SIZE;
- char* tmp = (char*) malloc(tmplen);
- if (!tmp)
- return;
-
- memcpy(tmp, packet, HEADER_SIZE);
-
- ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SUSPEND, (const char*) tmp, tmplen);
-
-
- if (tmp)
- free(tmp);
- if (packet)
- free(packet);
-}
-
-static synbuf g_synbuf;
-
-void process_evdi_command(ijcommand* ijcmd)
-{
- int fd = -1;
-
- if (strncmp(ijcmd->cmd, "sensor", 6) == 0)
- {
- msgproc_sensor(fd, ijcmd, true);
- }
- else if (strncmp(ijcmd->cmd, "telephony", 9) == 0)
- {
- msgproc_telephony(fd, ijcmd, true);
- }
- else if (strncmp(ijcmd->cmd, "suspend", 7) == 0)
- {
- msgproc_suspend(fd, ijcmd, true);
- }
- else if (strncmp(ijcmd->cmd, "location", 8) == 0)
- {
- msgproc_location(fd, ijcmd, true);
- }
- else if (strncmp(ijcmd->cmd, "system", 6) == 0)
- {
- msgproc_system(fd, ijcmd, true);
- }
- else if (strncmp(ijcmd->cmd, "sdcard", 6) == 0)
- {
- msgproc_sdcard(fd, ijcmd, true);
- }
- else
- {
- LOGERR("Unknown packet: %s", ijcmd->cmd);
- }
-}
-
-static void recv_from_evdi(evdi_fd fd)
+void recv_from_evdi(evdi_fd fd)
{
LOGDEBUG("recv_from_evdi");
int readed;
+ synbuf g_synbuf;
struct msg_info _msg;
int to_read = sizeof(struct msg_info);
}
}
- LOGDEBUG("total readed = %d, read count = %d, index = %d, use = %d, msg = %s",
+ LOGINFO("total readed = %d, read count = %d, index = %d, use = %d, msg = %s",
readed, _msg.count, _msg.index, _msg.use, _msg.buf);
g_synbuf.reset_buf();
g_synbuf.write(_msg.buf, _msg.use);
-
ijcommand ijcmd;
readed = g_synbuf.read(ijcmd.cmd, ID_SIZE);
if (readed < HEADER_SIZE)
return;
- int act = ijcmd.msg.action;
- int grp = ijcmd.msg.group;
- int len = ijcmd.msg.length;
-
-
- LOGDEBUG("HEADER : action = %d, group = %d, length = %d", act, grp, len);
+ LOGDEBUG("HEADER : action = %d, group = %d, length = %d",
+ ijcmd.msg.action, ijcmd.msg.group, ijcmd.msg.length);
if (ijcmd.msg.length > 0)
{
if (readed < ijcmd.msg.length)
{
LOGERR("received data is insufficient");
- //return;
}
}
process_evdi_command(&ijcmd);
}
-static bool server_process(void)
-{
- int i,nfds;
- int fd_tmp;
-
- nfds = epoll_wait(g_epoll_fd, g_events, MAX_EVENTS, 100);
-
- if (nfds == -1 && errno != EAGAIN && errno != EINTR)
- {
- LOGERR("epoll wait(%d)", errno);
- return true;
- }
-
- for( i = 0 ; i < nfds ; i++ )
- {
- fd_tmp = g_events[i].data.fd;
- if (fd_tmp == g_fd[fdtype_server])
- {
- accept_proc(fd_tmp);
- }
- else if (fd_tmp == g_fd[fdtype_device])
- {
- recv_from_evdi(fd_tmp);
- }
- else if(fd_tmp == g_fd[fdtype_vmodem])
- {
- recv_from_vmodem(fd_tmp);
- }
- else
- {
- recv_from_ij(fd_tmp);
- }
- }
-
- return false;
-}
-
int main( int argc , char *argv[])
{
- int state;
-
- LOGINFO("emuld 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) {
- LOGERR("[STOP] port number invalid : %d",g_svr_port);
- exit(0);
- }
- }
- }
-
- init_data0();
+ init_fd();
if (!epoll_init())
{
exit(0);
}
- if (!init_server0(g_svr_port, &g_fd[fdtype_server]))
- {
- close(g_epoll_fd);
- exit(0);
- }
-
if (!init_device(&g_fd[fdtype_device]))
{
close(g_epoll_fd);
exit(0);
}
- LOGINFO("[START] epoll events set success for server");
+ LOGINFO("[START] epoll & device init success");
- set_vm_connect_status(0);
-
- if(pthread_create(&tid[0], NULL, init_vm_connect, NULL) != 0)
- {
- LOGERR("pthread create fail!");
- close(g_epoll_fd);
- exit(0);
- }
+ init_profile();
send_default_suspend_req();
- bool is_exit = false;
-
- while(!is_exit)
+ while(!exit_flag)
{
- is_exit = server_process();
+ exit_flag = server_process();
}
- exit_flag = true;
-
- if (!is_vm_connected())
- {
- int status;
- pthread_join(tid[0], (void **)&status);
- LOGINFO("vmodem thread end %d", status);
- }
-
- state = pthread_mutex_destroy(&mutex_vmconnect);
- if (state != 0)
- {
- LOGERR("mutex_vmconnect is failed to destroy.");
- }
+ exit_profile();
stop_listen();
- if (g_fd[fdtype_server])
- close(g_fd[fdtype_server]);
-
LOGINFO("emuld exit");
return 0;
+++ /dev/null
-/*
- * emulator-daemon
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Jinhyung Choi <jinhyung2.choi@samsnung.com>
- * SooYoung Ha <yoosah.ha@samsnung.com>
- * Sungmin Ha <sungmin82.ha@samsung.com>
- * Daiyoung Kim <daiyoung777.kim@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-/*
- * emuld_proc.cpp
- *
- * Created on: 2013. 4. 12.
- * Author: dykim
- */
-
-#include "emuld_common.h"
-#include "emuld.h"
-#include <errno.h>
-
-#include <sys/mount.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <mntent.h>
-
-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)
- {
- memset(type_cmd, 0, ID_SIZE);
- }
- int get_status_sockfd;
- unsigned char ActionID;
- bool is_evdi;
- char type_cmd[ID_SIZE];
-};
-
-struct mount_param
-{
- mount_param(int _fd) : fd(_fd), is_evdi(false) {}
- int fd;
- bool is_evdi;
-};
-
-char* get_mount_info() {
- struct mntent *ent;
- FILE *aFile;
-
- aFile = setmntent("/proc/mounts", "r");
- if (aFile == NULL) {
- LOGERR("/proc/mounts is not exist");
- return NULL;
- }
- char* mountinfo = new char[512];
- memset(mountinfo, 0, 512);
-
- while (NULL != (ent = getmntent(aFile))) {
-
- if (strcmp(ent->mnt_dir, "/opt/storage/sdcard") == 0)
- {
- LOGDEBUG(",%s,%s,%d,%s,%d,%s",
- ent->mnt_fsname, ent->mnt_dir, ent->mnt_freq, ent->mnt_opts, ent->mnt_passno, ent->mnt_type);
- sprintf(mountinfo,",%s,%s,%d,%s,%d,%s\n",
- ent->mnt_fsname, ent->mnt_dir, ent->mnt_freq, ent->mnt_opts, ent->mnt_passno, ent->mnt_type);
- break;
- }
- }
- endmntent(aFile);
-
- return mountinfo;
-}
-
-int is_mounted()
-{
- int ret = -1, i = 0;
- struct stat buf;
- char file_name[128];
- memset(file_name, '\0', sizeof(file_name));
-
- for(i = 0; i < 10; i++)
- {
- sprintf(file_name, "/dev/mmcblk%d", i);
- ret = access(file_name, F_OK);
- if( ret == 0 )
- {
- lstat(file_name, &buf);
- if(S_ISBLK(buf.st_mode))
- return 1;
- else
- return 0;
- }
- }
-
- return 0;
-}
-
-void* mount_sdcard(void* data)
-{
- mount_param* param = (mount_param*) data;
-
- int ret = -1, i = 0;
- struct stat buf;
- char file_name[128], command[256];
- memset(file_name, '\0', sizeof(file_name));
- memset(command, '\0', sizeof(command));
-
- LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
- memset(packet, 0, sizeof(LXT_MESSAGE));
-
- LOGINFO("start sdcard mount thread");
-
- pthread_detach(pthread_self());
-
- while (ret < 0)
- {
- for (i = 0; i < 10; i++)
- {
- sprintf(file_name, "/dev/mmcblk%d", i);
- ret = access( file_name, F_OK );
- if( ret == 0 )
- {
- lstat(file_name, &buf);
- if(!S_ISBLK(buf.st_mode))
- {
- sprintf(command, "rm -rf %s", file_name);
- systemcall(command);
- }
- else
- break;
- }
- }
-
- if (i != 10)
- {
- LOGDEBUG( "%s is exist", file_name);
- packet->length = strlen(SDpath); // length
- packet->group = 11; // sdcard
- if (ret == 0)
- packet->action = 1; // mounted
- else
- packet->action = 5; // failed
-
- //
- LOGDEBUG("SDpath is %s", SDpath);
-
- const int tmplen = HEADER_SIZE + packet->length;
- char* tmp = (char*) malloc(tmplen);
-
- if (tmp)
- {
- memcpy(tmp, packet, HEADER_SIZE);
- if (packet->length > 0)
- {
- memcpy(tmp + HEADER_SIZE, SDpath, packet->length);
- }
-
- if (param->is_evdi)
- {
- ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
- }
- else
- {
- send_to_cli(param->fd, (char*) tmp, tmplen);
- }
-
- free(tmp);
- }
-
- //
-
- if (ret == 0) {
- ret = system("/usr/bin/sys_event mmcblk_add");
- }
-
- break;
- }
- else
- {
- LOGERR( "%s is not exist", file_name);
- sleep(1);
- }
- }
-
- if(packet)
- {
- free(packet);
- packet = NULL;
- }
-
- if (param)
- {
- delete param;
- param = NULL;
- }
- pthread_exit((void *) 0);
-}
-
-int umount_sdcard(const int fd, bool is_evdi)
-{
- int ret = -1, i = 0;
- char file_name[128];
- memset(file_name, '\0', sizeof(file_name));
-
- LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
- if(packet == NULL){
- return ret;
- }
- memset(packet, 0, sizeof(LXT_MESSAGE));
-
- LOGINFO("start sdcard umount");
-
- pthread_cancel(tid[1]);
-
- for (i = 0; i < 10; i++)
- {
- sprintf(file_name, "/dev/mmcblk%d", i);
- ret = access(file_name, F_OK);
- if (ret == 0)
- {
- if(fd != -1)
- {
- packet->length = strlen(SDpath); // length
- packet->group = 11; // sdcard
- packet->action = 0; // unmounted
-
- send(fd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
-
- LOGDEBUG("SDpath is %s", SDpath);
- send(fd, SDpath, packet->length, 0);
- }
- else if (is_evdi)
- {
- LOGDEBUG("SDpath is %s", SDpath);
-
- packet->length = strlen(SDpath); // length
- packet->group = 11; // sdcard
- packet->action = 0; // unmounted
-
- const int tmplen = HEADER_SIZE + packet->length;
- char* tmp = (char*) malloc(tmplen);
- if (!tmp)
- break;
-
- memcpy(tmp, packet, HEADER_SIZE);
- memcpy(tmp + HEADER_SIZE, SDpath, packet->length);
-
- ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
-
- free(tmp);
- }
-
- memset(SDpath, '\0', sizeof(SDpath));
- sprintf(SDpath, "umounted");
- ret = system("/usr/bin/sys_event mmcblk_remove");
-
- break;
- }
- else
- {
- LOGERR( "%s is not exist", file_name);
- }
- }
-
- if(packet){
- free(packet);
- packet = NULL;
- }
- return ret;
-}
-
-
-int powerdown_by_force(void)
-{
- struct timeval now;
- int 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) {
- LOGINFO("power down wait");
- usleep(100000);
- gettimeofday(&now, NULL);
- }
-
- LOGINFO("Power off by force");
- LOGINFO("sync");
-
- sync();
-
- LOGINFO("poweroff");
-
- reboot(RB_POWER_OFF);
-
- return 1;
-}
-
-// location event
-char command[512];
-char latitude[128];
-char longitude[128];
-void setting_location(char* databuf)
-{
- char* s = strchr(databuf, ',');
- memset(command, 0, 256);
- if (s == NULL) { // SET MODE
- int mode = atoi(databuf);
- switch (mode) {
- case 0: // STOP MODE
- sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 0 -f");
- break;
- case 1: // NMEA MODE (LOG MODE)
- sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 1 -f");
- break;
- case 2: // MANUAL MODE
- sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 2 -f");
- break;
- default:
- LOGERR("error(%s) : stop replay mode", databuf);
- sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 0 -f");
- break;
- }
- LOGDEBUG("Location Command : %s", command);
- systemcall(command);
- } else {
- *s = '\0';
- int mode = atoi(databuf);
- if(mode == 1) { // NMEA MODE (LOG MODE)
- sprintf(command, "vconftool set -t string db/location/replay/FileName \"%s\"", s+1);
- LOGDEBUG("%s", command);
- systemcall(command);
- memset(command, 0, 256);
- sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 1 -f");
- LOGDEBUG("%s", command);
- systemcall(command);
- } else if(mode == 2) {
- memset(latitude, 0, 128);
- memset(longitude, 0, 128);
- char* t = strchr(s+1, ',');
- *t = '\0';
- strcpy(latitude, s+1);
- strcpy(longitude, t+1);
- //strcpy(longitude, s+1);
- //strcpy(latitude, databuf);
- // Latitude
- sprintf(command, "vconftool set -t double db/location/replay/ManualLatitude %s -f", latitude);
- LOGDEBUG("%s", command);
- systemcall(command);
-
- // Longitude
- sprintf(command, "vconftool set -t double db/location/replay/ManualLongitude %s -f", longitude);
- LOGDEBUG("%s", command);
- systemcall(command);
- }
- }
-}
-
-
-void* setting_device(void* data)
-{
- pthread_detach(pthread_self());
-
- setting_device_param* param = (setting_device_param*) data;
-
- if (!param)
- return 0;
-
- int sockfd = param->get_status_sockfd;
-
- bool is_evdi = param->is_evdi;
-
- char* msg = 0;
- LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
-
- switch(param->ActionID)
- {
- case USB_STATUS:
- msg = get_usb_status((void*)packet, is_evdi);
- if (msg == 0) {
- LOGERR("failed getting usb status");
- }
- break;
- case EARJACK_STATUS:
- msg = get_earjack_status((void*)packet, is_evdi);
- if (msg == 0) {
- LOGERR("failed getting earjack status");
- }
- break;
- case RSSI_LEVEL:
- msg = get_rssi_level((void*)packet, is_evdi);
- if (msg == 0) {
- LOGERR("failed getting rssi level");
- }
- break;
- case MOTION_VALUE:
- LOGERR("not support getting motion value");
- break;
- case LOCATION_STATUS:
- msg = get_location_status((void*)packet, is_evdi);
- if (msg == 0) {
- LOGERR("failed getting location status");
- }
- break;
- default:
- LOGERR("Wrong action ID. %d", param->ActionID);
- break;
- }
-
- if (sockfd != -1)
- {
- if (msg != 0)
- {
- LOGDEBUG("send data to injector");
- }
- else
- {
- LOGERR("send error message to injector");
- memset(packet, 0, sizeof(LXT_MESSAGE));
- packet->length = 0;
- packet->group = STATUS;
- packet->action = param->ActionID;
- }
-
- send(sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
-
- if (packet->length > 0)
- {
- send(sockfd, msg, packet->length, 0);
- }
- }
- else if (param->is_evdi)
- {
- if (msg == 0)
- {
- LOGDEBUG("send error message to injector");
- memset(packet, 0, sizeof(LXT_MESSAGE));
- packet->length = 0;
- packet->group = STATUS;
- packet->action = param->ActionID;
- }
- else
- {
- LOGDEBUG("send data to injector");
- }
-
- const int tmplen = HEADER_SIZE + packet->length;
- char* tmp = (char*) malloc(tmplen);
- if (tmp)
- {
- memcpy(tmp, packet, HEADER_SIZE);
- if (packet->length > 0)
- memcpy(tmp + HEADER_SIZE, msg, packet->length);
-
- ijmsg_send_to_evdi(g_fd[fdtype_device], param->type_cmd, (const char*) tmp, tmplen);
-
- free(tmp);
- }
- }
-
- if(msg != 0)
- {
- free(msg);
- msg = 0;
- }
- if (packet)
- {
- free(packet);
- packet = NULL;
- }
-
- if (param)
- delete param;
-
- pthread_exit((void *) 0);
-}
-
-
-// event injector message handlers
-
-bool msgproc_telephony(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
-{
- LOGDEBUG("msgproc_telephony");
-
- if (!is_vm_connected())
- return false;
-
- int sent;
- sent = send(g_fd[fdtype_vmodem], &ijcmd->msg, HEADER_SIZE, 0);
- if (sent == -1)
- {
- perror("vmodem send error");
- }
-
- LOGDEBUG("sent to vmodem = %d, err = %d", sent, errno);
-
- sent = send(g_fd[fdtype_vmodem], ijcmd->data, ijcmd->msg.length, 0);
- if (sent == -1)
- {
- perror("vmodem send error");
- }
-
- LOGDEBUG("sent to vmodem = %d, err = %d", sent, errno);
-
-
- return true;
-}
-
-bool msgproc_sensor(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
-{
- LOGDEBUG("msgproc_sensor");
-
- if (ijcmd->msg.group == STATUS)
- {
- setting_device_param* param = new setting_device_param();
- if (!param)
- return false;
-
- memset(param, 0, sizeof(*param));
-
- param->get_status_sockfd = sockfd;
- param->ActionID = ijcmd->msg.action;
- param->is_evdi = is_evdi;
- memcpy(param->type_cmd, ijcmd->cmd, ID_SIZE);
-
- if (pthread_create(&tid[2], NULL, setting_device, (void*)param) != 0)
- {
- LOGERR("sensor pthread create fail!");
- return false;
- }
-
- }
- else
- {
- if (ijcmd->data != NULL && strlen(ijcmd->data) > 0) {
- device_parser(ijcmd->data);
- }
- }
- return true;
-}
-
-bool msgproc_location(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
-{
- LOGDEBUG("msgproc_location");
- if (ijcmd->msg.group == STATUS)
- {
- setting_device_param* param = new setting_device_param();
- if (!param)
- return false;
-
- param->get_status_sockfd = sockfd;
- param->ActionID = ijcmd->msg.action;
- param->is_evdi = is_evdi;
- memcpy(param->type_cmd, ijcmd->cmd, ID_SIZE);
-
- if (pthread_create(&tid[2], NULL, setting_device, (void*) param) != 0)
- {
- LOGERR("location pthread create fail!");
- return false;
- }
- }
- else
- {
- setting_location(ijcmd->data);
- }
- return true;
-}
-
-bool msgproc_system(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
-{
- LOGDEBUG("msgproc_system");
-
- LOGINFO("/etc/rc.d/rc.shutdown, sync, reboot(RB_POWER_OFF)");
-
- sync();
-
- systemcall("/etc/rc.d/rc.shutdown &");
-
- gettimeofday(&tv_start_poweroff, NULL);
-
- powerdown_by_force();
-
- return true;
-}
-
-bool msgproc_sdcard(const int sockfd, ijcommand* ijcmd, const bool is_evdi)
-{
- LOGDEBUG("msgproc_sdcard");
-
- const int tmpsize = ijcmd->msg.length;
-
- char token[] = "\n";
- char tmpdata[tmpsize];
- memcpy(tmpdata, ijcmd->data, tmpsize);
-
- char* ret = NULL;
- ret = strtok(tmpdata, token);
-
- LOGDEBUG("%s", ret);
-
- int mount_val = atoi(ret);
- int mount_status = 0;
-
- switch (mount_val)
- {
- case 0: // umount
- {
- mount_status = umount_sdcard(sockfd, is_evdi);
- if (mount_status == 0)
- send_guest_server(ijcmd->data);
- }
- break;
- case 1: // mount
- {
- memset(SDpath, '\0', sizeof(SDpath));
- ret = strtok(NULL, token);
- strcpy(SDpath, ret);
- LOGDEBUG("sdcard path is %s", SDpath);
-
- send_guest_server(ijcmd->data);
-
- mount_param* param = new mount_param(sockfd);
- if (!param)
- break;
-
- param->is_evdi = is_evdi;
-
- if (pthread_create(&tid[1], NULL, mount_sdcard, (void*) param) != 0)
- LOGERR("mount sdcard pthread create fail!");
- }
-
- break;
- case 2: // mount status
- {
- mount_status = is_mounted();
- LXT_MESSAGE* mntData = (LXT_MESSAGE*) malloc(sizeof(LXT_MESSAGE));
- if (mntData == NULL)
- {
- break;
- }
- memset(mntData, 0, sizeof(LXT_MESSAGE));
-
- mntData->length = strlen(SDpath); // length
- mntData->group = 11; // sdcard
-
- LOGDEBUG("SDpath is %s", SDpath);
-
- switch (mount_status)
- {
- case 0:
- {
- mntData->action = 2; // umounted status
-
- const int tmplen = HEADER_SIZE + mntData->length;
- char* tmp = (char*) malloc(tmplen);
-
- if (tmp)
- {
- memcpy(tmp, mntData, HEADER_SIZE);
- if (mntData->length > 0)
- {
- memcpy(tmp + HEADER_SIZE, SDpath, mntData->length);
- }
-
- if (is_evdi)
- {
- ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
- }
- else
- {
- send_to_cli(sockfd, (char*) tmp, tmplen);
- }
-
- free(tmp);
- }
-
- memset(SDpath, '\0', sizeof(SDpath));
- sprintf(SDpath, "umounted");
- }
- break;
- case 1:
- {
- mntData->action = 3; // mounted status
-
- int mountinfo_size = 0;
- char* mountinfo = get_mount_info();
- if (mountinfo)
- {
- mountinfo_size = strlen(mountinfo);
- }
-
- const int tmplen = HEADER_SIZE + mntData->length + mountinfo_size;
- char* tmp = (char*) malloc(tmplen);
-
- if (tmp)
- {
- memcpy(tmp, mntData, HEADER_SIZE);
- if (mntData->length > 0)
- {
- memcpy(tmp + HEADER_SIZE, SDpath, mntData->length);
- }
-
- if (mountinfo)
- {
- memcpy(tmp + HEADER_SIZE + mntData->length, mountinfo, mountinfo_size);
- mntData->length += mountinfo_size;
- memcpy(tmp, mntData, HEADER_SIZE);
- delete mountinfo;
- mountinfo = NULL;
- }
-
- if (is_evdi)
- {
- ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
- }
- else
- {
- send_to_cli(sockfd, (char*) tmp, tmplen);
- }
-
- free(tmp);
- }
- }
- break;
- default:
- break;
- }
- free(mntData);
- }
- break;
- default:
- LOGERR("unknown data %s", ret);
- break;
- }
- return true;
-}
-
-//sdcard event
-void send_guest_server(char* databuf)
-{
- if (!databuf)
- {
- LOGERR("invalid data buf");
- return;
- }
-
- char buf[32];
- struct sockaddr_in si_other;
- int s, slen=sizeof(si_other);
- FILE* fd;
- char fbuf[16];
- int port = 3581;
-
- fd = fopen(SDB_PORT_FILE, "r");
- if(!fd)
- {
- LOGERR("fail to open %s file", SDB_PORT_FILE);
- return;
- }
-
- if (fgets(fbuf, 16, fd))
- {
- port = atoi(fbuf) + 3;
- }
- else
- {
- LOGERR("guest port fgets failure");
- return;
- }
-
- fclose(fd);
-
- s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (s == -1)
- {
- LOGERR("socket error!");
- return;
- }
-
- memset((char *) &si_other, 0, sizeof(si_other));
- si_other.sin_family = AF_INET;
- si_other.sin_port = htons(port);
- if (inet_aton(SRV_IP, &si_other.sin_addr) == 0)
- {
- LOGERR("inet_aton() failed");
- }
-
- memset(buf, '\0', sizeof(buf));
- snprintf(buf, sizeof(buf), "4\n%s", databuf);
- LOGDEBUG("sendGuestServer msg: %s", buf);
- if (sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
- {
- LOGERR("sendto error!");
- }
-
- close(s);
-}
-
* Sungmin Ha <sungmin82.ha@samsung.com>
* Daiyoung Kim <daiyoung777.kim@samsung.com>
* YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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 <unistd.h>
+#include <fcntl.h>
+
#include "emuld.h"
#define DEVICE_NODE_PATH "/dev/evdi0"
--- /dev/null
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Jinhyung Choi <jinhyung2.choi@samsnung.com>
+ * DaiYoung Kim <daiyoung777.kim@samsnung.com>
+ * SooYoung Ha <yoosah.ha@samsnung.com>
+ * Sungmin Ha <sungmin82.ha@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+
+#include "emuld.h"
+#include "mobile.h"
+
+
+void process_evdi_command(ijcommand* ijcmd)
+{
+ int fd = -1;
+
+ if (strncmp(ijcmd->cmd, "sensor", 6) == 0)
+ {
+ msgproc_sensor(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "suspend", 7) == 0)
+ {
+ msgproc_suspend(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "location", 8) == 0)
+ {
+ msgproc_location(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "hds", 3) == 0)
+ {
+ msgproc_hds(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "system", 6) == 0)
+ {
+ msgproc_system(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "sdcard", 6) == 0)
+ {
+ msgproc_sdcard(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "cmd", 3) == 0)
+ {
+ msgproc_cmd(fd, ijcmd);
+ }
+ else
+ {
+ LOGERR("Unknown packet: %s", ijcmd->cmd);
+ }
+}
+
+bool server_process(void)
+{
+ int i,nfds;
+ int fd_tmp;
+
+ nfds = epoll_wait(g_epoll_fd, g_events, MAX_EVENTS, 100);
+
+ if (nfds == -1 && errno != EAGAIN && errno != EINTR)
+ {
+ LOGERR("epoll wait(%d)", errno);
+ return true;
+ }
+
+ for( i = 0 ; i < nfds ; i++ )
+ {
+ fd_tmp = g_events[i].data.fd;
+ if (fd_tmp == g_fd[fdtype_device])
+ {
+ recv_from_evdi(fd_tmp);
+ }
+ else
+ {
+ LOGERR("unknown request event fd : (%d)", fd_tmp);
+ }
+ }
+
+ return false;
+}
+
+void init_profile(void)
+{
+}
+
+void exit_profile(void)
+{
+}
+
+
--- /dev/null
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Jinhyung Choi <jinhyung2.choi@samsnung.com>
+ * DaiYoung Kim <daiyoung777.kim@samsnung.com>
+ * SooYoung Ha <yoosah.ha@samsnung.com>
+ * Sungmin Ha <sungmin82.ha@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include <stdio.h>
+#include <vconf/vconf.h>
+#include <vconf/vconf-keys.h>
+
+#include "emuld.h"
+#include "mobile.h"
+
+#define STATUS 15
+#define RSSI_LEVEL 104
+
+enum sensor_type{
+ MOTION = 6,
+ USBKEYBOARD = 7,
+ BATTERYLEVEL = 8,
+ EARJACK = 9,
+ USB = 10,
+ RSSI = 11,
+};
+
+enum motion_doubletap{
+ SENSOR_MOTION_DOUBLETAP_NONE = 0,
+ SENSOR_MOTION_DOUBLETAP_DETECTION = 1
+};
+
+enum motion_shake{
+ SENSOR_MOTION_SHAKE_NONE = 0,
+ SENSOR_MOTION_SHAKE_DETECTED = 1,
+ SENSOR_MOTION_SHAKE_CONTINUING = 2,
+ SENSOR_MOTION_SHAKE_FINISHED = 3,
+ SENSOR_MOTION_SHAKE_BREAK = 4
+};
+
+enum motion_snap{
+ SENSOR_MOTION_SNAP_NONE = 0,
+ SENSOR_MOTION_SNAP_NEGATIVE_X = 1,
+ SENSOR_MOTION_SNAP_POSITIVE_X = 2,
+ SENSOR_MOTION_SNAP_NEGATIVE_Y = 3,
+ SENSOR_MOTION_SNAP_POSITIVE_Y = 4,
+ SENSOR_MOTION_SNAP_NEGATIVE_Z = 5,
+ SENSOR_MOTION_SNAP_POSITIVE_Z = 6,
+ SENSOR_MOTION_SNAP_LEFT = SENSOR_MOTION_SNAP_NEGATIVE_X,
+ SENSOR_MOTION_SNAP_RIGHT = SENSOR_MOTION_SNAP_POSITIVE_X
+};
+
+enum motion_move{
+ SENSOR_MOTION_MOVE_NONE = 0,
+ SENSOR_MOTION_MOVE_MOVETOCALL = 1
+};
+
+static void system_cmd(const char* msg)
+{
+ int ret = system(msg);
+ if (ret == -1) {
+ LOGERR("system command is failed: %s", msg);
+ }
+}
+
+#define DBUS_SEND_CMD "dbus-send --system --type=method_call --print-reply --reply-timeout=120000 --dest=org.tizen.system.deviced /Org/Tizen/System/DeviceD/SysNoti org.tizen.system.deviced.SysNoti."
+static void dbus_send(const char* device, const char* option)
+{
+ const char* dbus_send_cmd = DBUS_SEND_CMD;
+ char* cmd;
+
+ if (device == NULL || option == NULL)
+ return;
+
+ cmd = (char*)malloc(512);
+ if (cmd == NULL)
+ return;
+
+ memset(cmd, 0, 512);
+
+ sprintf(cmd, "%s%s string:\"%s\" %s", dbus_send_cmd, device, device, option);
+
+ system_cmd(cmd);
+ LOGINFO("dbus_send: %s", cmd);
+
+ free(cmd);
+}
+
+#define POWER_SUPPLY "power_supply"
+#define FULL "Full"
+#define CHARGING "Charging"
+#define DISCHARGING "Discharging"
+static void dbus_send_power_supply(int capacity, int charger)
+{
+ const char* power_device = POWER_SUPPLY;
+ char state [16];
+ char option [128];
+ memset(state, 0, 16);
+ memset(option, 0, 128);
+
+ if (capacity == 100 && charger == 1) {
+ memcpy(state, FULL, 4);
+ } else if (charger == 1) {
+ memcpy(state, CHARGING, 8);
+ } else {
+ memcpy(state, DISCHARGING, 11);
+ }
+
+ sprintf(option, "int32:5 string:\"%d\" string:\"%s\" string:\"Good\" string:\"%d\" string:\"1\"",
+ capacity, state, (charger + 1));
+
+ dbus_send(power_device, option);
+}
+
+#define DEVICE_CHANGED "device_changed"
+
+static void dbus_send_usb(int on)
+{
+ const char* usb_device = DEVICE_CHANGED;
+ char option [128];
+ memset(option, 0, 128);
+
+ sprintf(option, "int32:2 string:\"usb\" string:\"%d\"", on);
+
+ dbus_send(usb_device, option);
+}
+
+static void dbus_send_earjack(int on)
+{
+ const char* earjack_device = DEVICE_CHANGED;
+ char option [128];
+ memset(option, 0, 128);
+
+ sprintf(option, "int32:2 string:\"earjack\" string:\"%d\"", on);
+
+ dbus_send(earjack_device, option);
+}
+
+int parse_motion_data(int len, char *buffer)
+{
+ int len1=0;
+ char tmpbuf[255];
+ int x;
+ char command[128];
+ memset(command, '\0', sizeof(command));
+
+ LOGDEBUG("read data: %s", buffer);
+
+ // read param count
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ /* first data */
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ x = atoi(tmpbuf);
+
+ switch(x)
+ {
+ case 1: // double tap
+ sprintf(command, "vconftool set -t int memory/private/sensor/800004 %d -i -f", SENSOR_MOTION_DOUBLETAP_DETECTION);
+ systemcall(command);
+ // memset(command, '\0', sizeof(command));
+ // sprintf(command, "vconftool set -t int memory/private/sensor/800004 %d -i -f", SENSOR_MOTION_DOUBLETAP_NONE);
+ // systemcall(command);
+ break;
+ case 2: // shake start
+ sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_DETECTED);
+ systemcall(command);
+ memset(command, '\0', sizeof(command));
+ sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_CONTINUING);
+ systemcall(command);
+ break;
+ case 3: // shake stop
+ sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_FINISHED);
+ systemcall(command);
+ break;
+ case 4: // snap x+
+ sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_X);
+ systemcall(command);
+ break;
+ case 5: // snap x-
+ sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_X);
+ systemcall(command);
+ break;
+ case 6: // snap y+
+ sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_Y);
+ systemcall(command);
+ break;
+ case 7: // snap y-
+ sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_Y);
+ systemcall(command);
+ break;
+ case 8: // snap z+
+ sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_Z);
+ systemcall(command);
+ break;
+ case 9: // snap z-
+ sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_Z);
+ systemcall(command);
+ break;
+ case 10: // snap left
+ sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_X);
+ systemcall(command);
+ break;
+ case 11: // snap right
+ sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_X);
+ systemcall(command);
+ break;
+ case 12: // move to call (direct call)
+ sprintf(command, "vconftool set -t int memory/private/sensor/800020 %d -i -f", SENSOR_MOTION_MOVE_MOVETOCALL);
+ systemcall(command);
+ break;
+ default:
+ LOGERR("not supported activity");
+ break;
+ }
+
+ return 0;
+}
+
+#define FILE_BATTERY_CAPACITY "/sys/class/power_supply/battery/capacity"
+#define FILE_BATTERY_CHARGER_ONLINE "/sys/devices/platform/jack/charger_online"
+#define FILE_BATTERY_CHARGE_FULL "/sys/class/power_supply/battery/charge_full"
+#define FILE_BATTERY_CHARGE_NOW "/sys/class/power_supply/battery/charge_now"
+
+static int read_from_file(const char* file_name)
+{
+ int ret;
+ FILE* fd;
+ int value;
+
+ fd = fopen(file_name, "r");
+ if(!fd)
+ {
+ LOGERR("fopen fail: %s", file_name);
+ return -1;
+ }
+
+ ret = fscanf(fd, "%d", &value);
+ fclose(fd);
+ if (ret <= 0) {
+ LOGERR("failed to get value");
+ return -1;
+ }
+
+ return value;
+}
+
+static void write_to_file(const char* file_name, int value)
+{
+ FILE* fd;
+
+ fd = fopen(file_name, "w");
+ if(!fd)
+ {
+ LOGERR("fopen fail: %s", file_name);
+ return;
+ }
+ fprintf(fd, "%d", value);
+ fclose(fd);
+}
+
+int set_battery_data(void)
+{
+ int charger_online = 0;
+ int battery_level = 0;
+
+ battery_level = read_from_file(FILE_BATTERY_CAPACITY);
+ LOGINFO("battery level: %d", battery_level);
+ if (battery_level < 0)
+ return -1;
+
+ charger_online = read_from_file(FILE_BATTERY_CHARGER_ONLINE);
+ LOGINFO("charge_online: %d", charger_online);
+ if (charger_online < 0)
+ return -1;
+
+ dbus_send_power_supply(battery_level, charger_online);
+
+ return 0;
+}
+
+#define PATH_JACK_EARJACK "/sys/devices/platform/jack/earjack_online"
+int parse_earjack_data(int len, char *buffer)
+{
+ int len1=0;
+ char tmpbuf[255];
+ int x;
+ FILE* fd;
+
+ LOGDEBUG("read data: %s", buffer);
+
+ // read param count
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ /* first data */
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ x = atoi(tmpbuf);
+
+ fd = fopen(PATH_JACK_EARJACK, "w");
+ if(!fd)
+ {
+ LOGERR("earjack_online fopen fail");
+ return -1;
+ }
+ fprintf(fd, "%d", x);
+ fclose(fd);
+
+ // because time based polling
+ //FIXME: change to dbus
+ //system_cmd("/usr/bin/sys_event device_earjack_chgdet");
+ dbus_send_earjack(x);
+ return 0;
+}
+
+#define FILE_USB_ONLINE "/sys/devices/platform/jack/usb_online"
+int parse_usb_data(int len, char *buffer)
+{
+ int len1=0;
+ char tmpbuf[255];
+ int x;
+
+ #ifdef SENSOR_DEBUG
+ LOG("read data: %s", buffer);
+ #endif
+ // read param count
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ /* first data */
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ x = atoi(tmpbuf);
+
+ write_to_file(FILE_USB_ONLINE, x);
+
+ // because time based polling
+ dbus_send_usb(x);
+
+ return 0;
+}
+
+
+int parse_rssi_data(int len, char *buffer)
+{
+ int len1=0;
+ char tmpbuf[255];
+ int x;
+ char command[128];
+ memset(command, '\0', sizeof(command));
+
+ LOGINFO("read data: %s", buffer);
+
+ // read param count
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ /* first data */
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ x = atoi(tmpbuf);
+
+ sprintf(command, "vconftool set -t int memory/telephony/rssi %d -i -f", x);
+ systemcall(command);
+
+ return 0;
+}
+
+void setting_sensor(char *buffer)
+{
+ int len = 0;
+ int ret = 0;
+ char tmpbuf[255];
+
+ LOGDEBUG("read data: %s", buffer);
+
+ // read sensor type
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len = parse_val(buffer, 0x0a, tmpbuf);
+
+ switch(atoi(tmpbuf))
+ {
+ case MOTION:
+ ret = parse_motion_data(len, buffer);
+ if(ret < 0)
+ LOGERR("motion parse error!");
+ break;
+ case BATTERYLEVEL:
+ ret = set_battery_data();
+ if(ret < 0)
+ LOGERR("batterylevel parse error!");
+ break;
+ case EARJACK:
+ ret = parse_earjack_data(len, buffer);
+ if(ret < 0)
+ LOGERR("earjack parse error!");
+ break;
+ case USB:
+ ret = parse_usb_data(len, buffer);
+ if(ret < 0)
+ LOGERR("usb parse error!");
+ break;
+ case RSSI:
+ ret = parse_rssi_data(len, buffer);
+ if(ret < 0)
+ LOGERR("rssi parse error!");
+ break;
+ default:
+ break;
+ }
+}
+
+
+static int inline get_vconf_status(char* msg, const char* key, int buf_len)
+{
+ int status;
+ int ret = vconf_get_int(key, &status);
+ if (ret != 0) {
+ LOGERR("cannot get vconf key - %s", key);
+ return -1;
+ }
+
+ sprintf(msg, "%d", status);
+ return strlen(msg);
+}
+
+char* __tmpalloc(const int size)
+{
+ char* message = (char*)malloc(sizeof(char) * size);
+ memset(message, 0, sizeof(char) * size);
+ return message;
+}
+
+char* get_rssi_level(void* p)
+{
+ char* message = __tmpalloc(5);
+ int length = get_vconf_status(message, "memory/telephony/rssi", 5);
+ 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;
+}
+
+static void* getting_sensor(void* data)
+{
+ pthread_detach(pthread_self());
+
+ setting_device_param* param = (setting_device_param*) data;
+
+ if (!param)
+ return 0;
+
+ char* msg = 0;
+ LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+
+ switch(param->ActionID)
+ {
+ case RSSI_LEVEL:
+ msg = get_rssi_level((void*)packet);
+ if (msg == 0) {
+ LOGERR("failed getting rssi level");
+ }
+ break;
+ default:
+ LOGERR("Wrong action ID. %d", param->ActionID);
+ break;
+ }
+
+ if (msg == 0)
+ {
+ LOGDEBUG("send error message to injector");
+ memset(packet, 0, sizeof(LXT_MESSAGE));
+ packet->length = 0;
+ packet->group = STATUS;
+ packet->action = param->ActionID;
+ }
+ else
+ {
+ LOGDEBUG("send data to injector");
+ }
+
+ const int tmplen = HEADER_SIZE + packet->length;
+ char* tmp = (char*) malloc(tmplen);
+ if (tmp)
+ {
+ memcpy(tmp, packet, HEADER_SIZE);
+ if (packet->length > 0)
+ memcpy(tmp + HEADER_SIZE, msg, packet->length);
+
+ ijmsg_send_to_evdi(g_fd[fdtype_device], param->type_cmd, (const char*) tmp, tmplen);
+
+ free(tmp);
+ }
+
+ if(msg != 0)
+ {
+ free(msg);
+ msg = 0;
+ }
+ if (packet)
+ {
+ free(packet);
+ packet = NULL;
+ }
+
+ if (param)
+ delete param;
+
+ pthread_exit((void *) 0);
+}
+
+void msgproc_sensor(const int sockfd, ijcommand* ijcmd)
+{
+ LOGDEBUG("msgproc_sensor");
+
+ if (ijcmd->msg.group == STATUS)
+ {
+ setting_device_param* param = new setting_device_param();
+ if (!param)
+ return;
+
+ memset(param, 0, sizeof(*param));
+
+ param->get_status_sockfd = sockfd;
+ param->ActionID = ijcmd->msg.action;
+ memcpy(param->type_cmd, ijcmd->cmd, ID_SIZE);
+
+ if (pthread_create(&tid[TID_SENSOR], NULL, getting_sensor, (void*)param) != 0)
+ {
+ LOGERR("sensor pthread create fail!");
+ return;
+ }
+
+ }
+ else
+ {
+ if (ijcmd->data != NULL && strlen(ijcmd->data) > 0) {
+ setting_sensor(ijcmd->data);
+ }
+ }
+}
+
--- /dev/null
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Jinhyung Choi <jinhyung2.choi@samsnung.com>
+ * DaiYoung Kim <daiyoung777.kim@samsnung.com>
+ * SooYoung Ha <yoosah.ha@samsnung.com>
+ * Sungmin Ha <sungmin82.ha@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+
+#include "emuld.h"
+#include "wearable.h"
+
+enum
+{
+ fdtype_pedometer = 3
+};
+
+#define PEDOMETER_PORT 3600
+
+#define IJTYPE_PEDOMETER "pedometer"
+
+unsigned short pedometer_port = PEDOMETER_PORT;
+static int g_pedometer_connect_status;
+static pthread_mutex_t mutex_pedometerconnect = PTHREAD_MUTEX_INITIALIZER;
+
+bool is_pedometer_connected(void)
+{
+ _auto_mutex _(&mutex_pedometerconnect);
+
+ if (g_pedometer_connect_status != 1)
+ return false;
+
+ return true;
+}
+
+bool msgproc_pedometer(const int sockfd, ijcommand* ijcmd)
+{
+ int sent = 0;
+
+ LOGINFO("msgproc_pedometer");
+ if (!is_pedometer_connected() || !ijcmd->data)
+ return false;
+
+ LOGINFO("send data state: %s", ijcmd->data);
+
+ sent = send(g_fd[fdtype_pedometer], ijcmd->data, 1, 0);
+ if (sent == -1)
+ {
+ LOGERR("pedometer send error");
+ }
+
+ LOGDEBUG("sent to pedometer daemon: %d byte", sent);
+
+ return true;
+}
+
+void set_pedometer_connect_status(const int v)
+{
+ _auto_mutex _(&mutex_pedometerconnect);
+
+ g_pedometer_connect_status = v;
+}
+
+void* init_pedometer_connect(void* data)
+{
+ struct sockaddr_in pedometer_addr;
+ int ret = -1;
+
+ set_pedometer_connect_status(0);
+
+ LOGINFO("init_pedometer_connect start\n");
+
+ pthread_detach(pthread_self());
+ if ((g_fd[fdtype_pedometer] = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+ {
+ LOGERR("Server Start Fails. : Can't open stream socket \n");
+ exit(0);
+ }
+
+ memset(&pedometer_addr , 0 , sizeof(pedometer_addr)) ;
+
+ pedometer_addr.sin_family = AF_INET;
+ pedometer_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
+ pedometer_addr.sin_port = htons(pedometer_port);
+
+ while (ret < 0 && !exit_flag)
+ {
+ ret = connect(g_fd[fdtype_pedometer], (struct sockaddr *)&pedometer_addr, sizeof(pedometer_addr));
+
+ LOGINFO("pedometer_sockfd: %d, connect ret: %d\n", g_fd[fdtype_pedometer], ret);
+
+ if(ret < 0) {
+ LOGERR("connection failed to pedometer! try \n");
+ sleep(1);
+ }
+ }
+
+ epoll_ctl_add(g_fd[fdtype_pedometer]);
+
+ set_pedometer_connect_status(1);
+
+ pthread_exit((void *) 0);
+}
+
+void recv_from_pedometer(int fd)
+{
+ printf("recv_from_pedometer\n");
+
+ ijcommand ijcmd;
+ if (!read_ijcmd(fd, &ijcmd))
+ {
+ LOGERR("fail to read ijcmd\n");
+
+ set_pedometer_connect_status(0);
+
+ close(fd);
+
+ if (pthread_create(&tid[TID_PEDOMETER], NULL, init_pedometer_connect, NULL) != 0)
+ {
+ LOGERR("pthread create fail!");
+ }
+ return;
+ }
+
+ LOGDEBUG("pedometer data length: %d", ijcmd.msg.length);
+ const int tmplen = HEADER_SIZE + ijcmd.msg.length;
+ char* tmp = (char*) malloc(tmplen);
+
+ if (tmp)
+ {
+ memcpy(tmp, &ijcmd.msg, HEADER_SIZE);
+ if (ijcmd.msg.length > 0)
+ memcpy(tmp + HEADER_SIZE, ijcmd.data, ijcmd.msg.length);
+
+ if(!ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_PEDOMETER, (const char*) tmp, tmplen)) {
+ LOGERR("msg_send_to_evdi: failed\n");
+ }
+
+ free(tmp);
+ }
+}
+
+void process_evdi_command(ijcommand* ijcmd)
+{
+ int fd = -1;
+
+ if (strncmp(ijcmd->cmd, "suspend", 7) == 0)
+ {
+ msgproc_suspend(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "sensor", 6) == 0)
+ {
+ msgproc_sensor(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "pedometer", 9) == 0)
+ {
+ msgproc_pedometer(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "location", 8) == 0)
+ {
+ msgproc_location(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "hds", 3) == 0)
+ {
+ msgproc_hds(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "system", 6) == 0)
+ {
+ msgproc_system(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "sdcard", 6) == 0)
+ {
+ msgproc_sdcard(fd, ijcmd);
+ }
+ else if (strncmp(ijcmd->cmd, "cmd", 3) == 0)
+ {
+ msgproc_cmd(fd, ijcmd);
+ }
+ else
+ {
+ LOGERR("Unknown packet: %s", ijcmd->cmd);
+ }
+}
+
+bool server_process(void)
+{
+ int i,nfds;
+ int fd_tmp;
+
+ nfds = epoll_wait(g_epoll_fd, g_events, MAX_EVENTS, 100);
+
+ if (nfds == -1 && errno != EAGAIN && errno != EINTR)
+ {
+ LOGERR("epoll wait(%d)", errno);
+ return true;
+ }
+
+ for( i = 0 ; i < nfds ; i++ )
+ {
+ fd_tmp = g_events[i].data.fd;
+ if (fd_tmp == g_fd[fdtype_device])
+ {
+ recv_from_evdi(fd_tmp);
+ }
+ else if (fd_tmp == g_fd[fdtype_pedometer])
+ {
+ recv_from_pedometer(fd_tmp);
+ }
+ else
+ {
+ LOGERR("unknown request event fd : (%d)", fd_tmp);
+ }
+ }
+
+ return false;
+}
+
+void init_profile(void)
+{
+ if(pthread_create(&tid[TID_PEDOMETER], NULL, init_pedometer_connect, NULL) != 0)
+ {
+ LOGERR("pthread create fail!");
+ close(g_epoll_fd);
+ exit(0);
+ }
+}
+
+void exit_profile(void)
+{
+ int state;
+ if (!is_pedometer_connected())
+ {
+ int status;
+ pthread_join(tid[TID_PEDOMETER], (void **)&status);
+ LOGINFO("pedometer thread end %d\n", status);
+ }
+
+ state = pthread_mutex_destroy(&mutex_pedometerconnect);
+ if (state != 0)
+ {
+ LOGERR("mutex_pedometerconnect is failed to destroy.");
+ }
+}
--- /dev/null
+/*
+ * emulator-daemon
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Jinhyung Choi <jinhyung2.choi@samsnung.com>
+ * DaiYoung Kim <daiyoung777.kim@samsnung.com>
+ * SooYoung Ha <yoosah.ha@samsnung.com>
+ * Sungmin Ha <sungmin82.ha@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include <stdio.h>
+
+#include "emuld.h"
+#include "wearable.h"
+
+enum sensor_type{
+ BATTERYLEVEL = 8,
+ EARJACK = 9,
+ USB = 10,
+};
+
+#define DBUS_SEND_CMD "dbus-send --system --type=method_call --print-reply --reply-timeout=120000 --dest=org.tizen.system.deviced /Org/Tizen/System/DeviceD/SysNoti org.tizen.system.deviced.SysNoti."
+static void dbus_send(const char* device, const char* option)
+{
+ const char* dbus_send_cmd = DBUS_SEND_CMD;
+ char* cmd;
+
+ if (device == NULL || option == NULL)
+ return;
+
+ cmd = (char*)malloc(512);
+ if (cmd == NULL)
+ return;
+
+ memset(cmd, 0, 512);
+
+ sprintf(cmd, "%s%s string:\"%s\" %s", dbus_send_cmd, device, device, option);
+
+ systemcall(cmd);
+ LOGINFO("dbus_send: %s", cmd);
+
+ free(cmd);
+}
+
+#define POWER_SUPPLY "power_supply"
+#define FULL "Full"
+#define CHARGING "Charging"
+#define DISCHARGING "Discharging"
+
+static void dbus_send_power_supply(int capacity, int charger)
+{
+ const char* power_device = POWER_SUPPLY;
+ char state [16];
+ char option [128];
+ memset(state, 0, 16);
+ memset(option, 0, 128);
+
+ if (capacity == 100 && charger == 1) {
+ memcpy(state, FULL, 4);
+ } else if (charger == 1) {
+ memcpy(state, CHARGING, 8);
+ } else {
+ memcpy(state, DISCHARGING, 11);
+ }
+
+ sprintf(option, "int32:5 string:\"%d\" string:\"%s\" string:\"Good\" string:\"%d\" string:\"1\"",
+ capacity, state, (charger + 1));
+
+ dbus_send(power_device, option);
+}
+
+#define DEVICE_CHANGED "device_changed"
+static void dbus_send_usb(int on)
+{
+ const char* usb_device = DEVICE_CHANGED;
+ char option [128];
+ memset(option, 0, 128);
+
+ sprintf(option, "int32:2 string:\"usb\" string:\"%d\"", on);
+
+ dbus_send(usb_device, option);
+}
+
+static void dbus_send_earjack(int on)
+{
+ const char* earjack_device = DEVICE_CHANGED;
+ char option [128];
+ memset(option, 0, 128);
+
+ sprintf(option, "int32:2 string:\"earjack\" string:\"%d\"", on);
+
+ dbus_send(earjack_device, option);
+}
+
+static int read_from_file(const char* file_name)
+{
+ int ret;
+ FILE* fd;
+ int value;
+
+ fd = fopen(file_name, "r");
+ if(!fd)
+ {
+ LOGERR("fopen fail: %s", file_name);
+ return -1;
+ }
+
+ ret = fscanf(fd, "%d", &value);
+ fclose(fd);
+ if (ret <= 0) {
+ LOGERR("failed to get value");
+ return -1;
+ }
+
+ return value;
+}
+
+static void write_to_file(const char* file_name, int value)
+{
+ FILE* fd;
+
+ fd = fopen(file_name, "w");
+ if(!fd)
+ {
+ LOGERR("fopen fail: %s", file_name);
+ return;
+ }
+ fprintf(fd, "%d", value);
+ fclose(fd);
+}
+
+#define FILE_BATTERY_CAPACITY "/sys/class/power_supply/battery/capacity"
+#define FILE_BATTERY_CHARGER_ONLINE "/sys/devices/platform/jack/charger_online"
+
+int set_battery_data(void)
+{
+ int charger_online = 0;
+ int battery_level = 0;
+
+ battery_level = read_from_file(FILE_BATTERY_CAPACITY);
+ LOGINFO("battery level: %d", battery_level);
+ if (battery_level < 0)
+ return -1;
+
+ charger_online = read_from_file(FILE_BATTERY_CHARGER_ONLINE);
+ LOGINFO("charge_online: %d", charger_online);
+ if (charger_online < 0)
+ return -1;
+
+ dbus_send_power_supply(battery_level, charger_online);
+
+ return 0;
+}
+
+#define PATH_JACK_EARJACK "/sys/devices/platform/jack/earjack_online"
+int parse_earjack_data(int len, char *buffer)
+{
+ int len1=0;
+ char tmpbuf[255];
+ int x;
+ FILE* fd;
+
+ LOGDEBUG("read data: %s", buffer);
+
+ // read param count
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ /* first data */
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ x = atoi(tmpbuf);
+
+ fd = fopen(PATH_JACK_EARJACK, "w");
+ if(!fd)
+ {
+ LOGERR("earjack_online fopen fail");
+ return -1;
+ }
+ fprintf(fd, "%d", x);
+ fclose(fd);
+
+ dbus_send_earjack(x);
+ return 0;
+}
+
+#define FILE_USB_ONLINE "/sys/devices/platform/jack/usb_online"
+int parse_usb_data(int len, char *buffer)
+{
+ int len1=0;
+ char tmpbuf[255];
+ int x;
+
+ // read param count
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ /* first data */
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len1 = parse_val(buffer+len, 0x0a, tmpbuf);
+ len += len1;
+
+ x = atoi(tmpbuf);
+
+ write_to_file(FILE_USB_ONLINE, x);
+
+ // because time based polling
+ dbus_send_usb(x);
+
+ return 0;
+}
+
+static void device_parser(char *buffer)
+{
+ int len = 0;
+ int ret = 0;
+ char tmpbuf[255];
+
+ LOGDEBUG("read data: %s", buffer);
+
+ // read sensor type
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len = parse_val(buffer, 0x0a, tmpbuf);
+
+ switch(atoi(tmpbuf))
+ {
+ case BATTERYLEVEL:
+ ret = set_battery_data();
+ if(ret < 0)
+ LOGERR("batterylevel parse error!");
+ break;
+ case EARJACK:
+ ret = parse_earjack_data(len, buffer);
+ if(ret < 0)
+ LOGERR("earjack parse error!");
+ break;
+ case USB:
+ ret = parse_usb_data(len, buffer);
+ if(ret < 0)
+ LOGERR("usb parse error!");
+ break;
+ default:
+ break;
+ }
+}
+
+void msgproc_sensor(const int sockfd, ijcommand* ijcmd)
+{
+ LOGDEBUG("msgproc_sensor");
+
+ if (ijcmd->msg.group != 15)
+ {
+ if (ijcmd->data != NULL && strlen(ijcmd->data) > 0) {
+ device_parser(ijcmd->data);
+ }
+ }
+}