set(CMAKE_VERBOSE_MAKEFILE OFF)
IF("$ENV{CFLAGS}" MATCHES "-DMOBILE")
- OPTION(USE_D_MOBILE "Use Mobile Def" ON)
+ OPTION(USE_D_MOBILE "Use Mobile Def" ON)
ENDIF()
IF("$ENV{CFLAGS}" MATCHES "-DWEARABLE")
- OPTION(USE_D_WEARABLE "Use Wearable Def" ON)
+ OPTION(USE_D_WEARABLE "Use Wearable Def" ON)
+ENDIF()
+
+IF("$ENV{CFLAGS}" MATCHES "-DTV")
+ OPTION(USE_D_TV "Use TV Def" ON)
ENDIF()
SET(SRCS
- src/emuld.cpp
- src/evdi.cpp
- src/client.cpp
- src/common.cpp
+ src/emuld.cpp
+ src/evdi.cpp
+ src/client.cpp
+ src/common.cpp
)
IF(USE_D_MOBILE)
- SET(SRCS ${SRCS}
- src/mobile.cpp
- src/mobile_dev.cpp
- src/common_dev.cpp
- )
+ SET(SRCS ${SRCS}
+ src/mobile.cpp
+ )
ENDIF(USE_D_MOBILE)
IF(USE_D_WEARABLE)
- SET(SRCS ${SRCS}
- src/wearable.cpp
- src/wearable_dev.cpp
- src/common_dev.cpp
- )
+ SET(SRCS ${SRCS}
+ src/wearable.cpp
+ )
ENDIF(USE_D_WEARABLE)
+IF(USE_D_TV)
+ SET(SRCS ${SRCS}
+ src/tv.cpp
+ )
+ENDIF(USE_D_TV)
+
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
INCLUDE(FindPkgConfig)
SET(PKG_MODULE
- vconf
- deviced
- dlog
- ecore
- edbus
+ vconf
+ deviced
+ dlog
+ ecore
+ edbus
)
pkg_check_modules(PKGS REQUIRED ${PKG_MODULE})
+SET(LIBS
+ ${LIBS}
+ pthread
+)
+
+#IF(USE_D_TV)
+# SET(LIBS ${LIBS}
+# sinative
+# si-api
+# )
+#ENDIF(USE_D_TV)
+
ADD_DEFINITIONS("-DENABLE_DLOG_OUT")
ADD_DEFINITIONS(-Wall -O3 -omit-frame-pointer)
ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS} -lpthread)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS} ${LIBS})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin)
#define MAX_GETCNT 10
#define ID_SIZE 10
#define HEADER_SIZE 4
+#define STATUS 15
// Thread TID profile uses >= 5
#define TID_BOOT 1
int parse_val(char *buff, unsigned char data, char *parsbuf);
#define IJTYPE_SUSPEND "suspend"
+#define IJTYPE_HDS "hds"
+#define IJTYPE_SYSTEM "system"
#define IJTYPE_GUEST "guest"
+#define IJTYPE_CMD "cmd"
#define IJTYPE_PACKAGE "package"
#define IJTYPE_BOOT "boot"
void msgproc_system(ijcommand* ijcmd);
void msgproc_package(ijcommand* ijcmd);
void msgproc_hds(ijcommand* ijcmd);
+#define IJTYPE_LOCATION "location"
void msgproc_location(ijcommand* ijcmd);
+#define IJTYPE_SDCARD "sdcard"
void msgproc_sdcard(ijcommand* ijcmd);
void* exec_cmd_thread(void *args);
void msgproc_cmd(ijcommand* ijcmd);
/*
* For the multi-profile
*/
-void process_evdi_command(ijcommand* ijcmd);
-bool server_process(void);
-void init_profile(void);
-void exit_profile(void);
+bool extra_evdi_command(ijcommand* ijcmd);
#endif
#define TID_SENSOR 5
+#define IJTYPE_SENSOR "sensor"
+
void msgproc_sensor(ijcommand* ijcmd);
#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 __TV_H__
+#define __TV_H__
+
+#define IJTYPE_GESTURE "gesture"
+#define IJTYPE_VOICE "voice"
+#define IJTYPE_EI "ei"
+
+bool msgproc_gesture(ijcommand* ijcmd);
+bool msgproc_voice(ijcommand* ijcmd);
+bool msgproc_extinput(ijcommand* ijcmd);
+
+#endif
#ifndef __WEARABLE_H__
#define __WEARABLE_H__
-#define TID_PEDOMETER 5
+#define IJTYPE_SENSOR "sensor"
+
void msgproc_sensor(ijcommand* ijcmd);
#endif
Name: emuld
-Version: 0.8.8
+Version: 0.9.0
Release: 0
Summary: Emulator daemon
License: Apache-2.0
%else
%if "%{?tizen_profile_name}" == "wearable"
export CFLAGS+=" -DWEARABLE"
+%else
+%if "%{?tizen_profile_name}" == "tv"
+export CFLAGS+=" -DTV"
+%endif
%endif
%endif
/*
* emulator-daemon
*
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact:
* Jinhyung Choi <jinhyung2.choi@samsnung.com>
#include <sys/time.h>
#include <sys/reboot.h>
#include <sys/ioctl.h>
+#include <sys/mount.h>
#include <stdio.h>
#include <unistd.h>
-
-#include "emuld.h"
-#include "deviced/dd-display.h"
+#include <errno.h>
#include <E_DBus.h>
#include <Ecore.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <mntent.h>
+
+#include <vconf.h>
+#include <vconf-keys.h>
+
+#include "emuld.h"
+#include "dd-display.h"
+
#define PMAPI_RETRY_COUNT 3
#define POWEROFF_DURATION 2
#define RPM_CMD_QUERY "-q"
#define RPM_CMD_INSTALL "-U"
static pthread_mutex_t mutex_pkg = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t mutex_cmd = PTHREAD_MUTEX_INITIALIZER;
static struct timeval tv_start_poweroff;
return NULL;
}
+char SDpath[256];
+
+// Location
+#define STATUS 15
+#define LOCATION_STATUS 120
+char command[512];
+
+/*
+ * SD Card functions
+ */
+
+static 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)
+{
+ 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;
+ }
+
+ pthread_exit((void *) 0);
+}
+
+static int umount_sdcard(void)
+{
+ 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(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();
+ }
+ break;
+ case 1: // mount
+ {
+ memset(SDpath, '\0', sizeof(SDpath));
+ ret = strtok(NULL, token);
+ strncpy(SDpath, ret, strlen(ret));
+ LOGDEBUG("sdcard path is %s", SDpath);
+
+ if (pthread_create(&tid[TID_SDCARD], NULL, mount_sdcard, NULL) != 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);
+ free(mountinfo);
+ }
+
+ ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
+
+ free(tmp);
+ } else {
+ if (mountinfo) {
+ free(mountinfo);
+ }
+ }
+ }
+ 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(ijcommand* ijcmd)
+{
+ _auto_mutex _(&mutex_cmd);
+ pthread_t cmd_thread_id;
+ char *cmd = (char*) malloc(ijcmd->msg.length + 1);
+
+ if (!cmd) {
+ LOGERR("malloc failed.");
+ return;
+ }
+
+ memset(cmd, 0x00, ijcmd->msg.length + 1);
+ 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;
+ }
+ }
+
+ if (message) {
+ 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;
+ } else {
+ return NULL;
+ }
+}
+
+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 != NULL) {
+ free(packet);
+ }
+ 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(ijcommand* ijcmd)
+{
+ LOGDEBUG("msgproc_location");
+ if (ijcmd->msg.group == STATUS)
+ {
+ setting_device_param* param = new setting_device_param();
+ if (!param)
+ return;
+
+ 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(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>
- * 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
- */
-
-static 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)
-{
- 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;
- }
-
- pthread_exit((void *) 0);
-}
-
-static int umount_sdcard(void)
-{
- 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(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();
- }
- break;
- case 1: // mount
- {
- memset(SDpath, '\0', sizeof(SDpath));
- ret = strtok(NULL, token);
- strncpy(SDpath, ret, strlen(ret));
- LOGDEBUG("sdcard path is %s", SDpath);
-
- if (pthread_create(&tid[TID_SDCARD], NULL, mount_sdcard, NULL) != 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);
- free(mountinfo);
- }
-
- ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_SDCARD, (const char*) tmp, tmplen);
-
- free(tmp);
- } else {
- if (mountinfo) {
- free(mountinfo);
- }
- }
- }
- 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(ijcommand* ijcmd)
-{
- _auto_mutex _(&mutex_cmd);
- pthread_t cmd_thread_id;
- char *cmd = (char*) malloc(ijcmd->msg.length + 1);
-
- if (!cmd) {
- LOGERR("malloc failed.");
- return;
- }
-
- memset(cmd, 0x00, ijcmd->msg.length + 1);
- 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;
- }
- }
-
- if (message) {
- 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;
- } else {
- return NULL;
- }
-}
-
-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 != NULL) {
- free(packet);
- }
- 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(ijcommand* ijcmd)
-{
- LOGDEBUG("msgproc_location");
- if (ijcmd->msg.group == STATUS)
- {
- setting_device_param* param = new setting_device_param();
- if (!param)
- return;
-
- 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(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.");
- }
-}
-
-
return readed;
}
+static void process_evdi_command(ijcommand* ijcmd)
+{
+ if (strcmp(ijcmd->cmd, IJTYPE_SUSPEND) == 0)
+ {
+ msgproc_suspend(ijcmd);
+ }
+ else if (strcmp(ijcmd->cmd, IJTYPE_HDS) == 0)
+ {
+ msgproc_hds(ijcmd);
+ }
+ else if (strcmp(ijcmd->cmd, IJTYPE_SYSTEM) == 0)
+ {
+ msgproc_system(ijcmd);
+ }
+ else if (strcmp(ijcmd->cmd, IJTYPE_PACKAGE) == 0)
+ {
+ msgproc_package(ijcmd);
+ }
+ else if (strcmp(ijcmd->cmd, IJTYPE_CMD) == 0)
+ {
+ msgproc_cmd(ijcmd);
+ }
+ else
+ {
+ if (!extra_evdi_command(ijcmd)) {
+ LOGERR("Unknown packet: %s", ijcmd->cmd);
+ }
+ }
+}
bool read_ijcmd(const int fd, ijcommand* ijcmd)
{
fclose(logfile);
}
+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_device])
+ {
+ recv_from_evdi(fd_tmp);
+ }
+ else
+ {
+ LOGERR("unknown request event fd : (%d)", fd_tmp);
+ }
+ }
+
+ return false;
+}
+
int main( int argc , char *argv[])
{
init_fd();
LOGINFO("[START] epoll & device init success");
- init_profile();
-
send_emuld_connection();
send_default_suspend_req();
exit_flag = server_process();
}
- exit_profile();
-
stop_listen();
LOGINFO("emuld exit");
*
*/
-#include <errno.h>
#include <stdio.h>
-#include <arpa/inet.h>
-#include <unistd.h>
+#include <vconf/vconf.h>
+#include <vconf/vconf-keys.h>
#include "emuld.h"
#include "mobile.h"
+#define RSSI_LEVEL 104
-void process_evdi_command(ijcommand* ijcmd)
+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)
{
- if (strncmp(ijcmd->cmd, "sensor", 6) == 0)
- {
- msgproc_sensor(ijcmd);
+ 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);
}
- else if (strcmp(ijcmd->cmd, IJTYPE_SUSPEND) == 0)
+
+ 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)
{
- msgproc_suspend(ijcmd);
+ 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;
}
- else if (strcmp(ijcmd->cmd, "location") == 0)
+
+ 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)
{
- msgproc_location(ijcmd);
+ 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;
}
- else if (strcmp(ijcmd->cmd, "hds") == 0)
+
+ return value;
+}
+
+static void write_to_file(const char* file_name, int value)
+{
+ FILE* fd;
+
+ fd = fopen(file_name, "w");
+ if(!fd)
{
- msgproc_hds(ijcmd);
+ LOGERR("fopen fail: %s", file_name);
+ return;
}
- else if (strcmp(ijcmd->cmd, "system") == 0)
+ 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)
{
- msgproc_system(ijcmd);
+ LOGERR("earjack_online fopen fail");
+ return -1;
}
- else if (strcmp(ijcmd->cmd, IJTYPE_PACKAGE) == 0)
+ 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))
{
- msgproc_package(ijcmd);
+ 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;
}
- else if (strcmp(ijcmd->cmd, "sdcard") == 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)
{
- msgproc_sdcard(ijcmd);
+ 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;
}
- else if (strcmp(ijcmd->cmd, "cmd") == 0)
+
+ if (msg == 0)
{
- msgproc_cmd(ijcmd);
+ LOGDEBUG("send error message to injector");
+ memset(packet, 0, sizeof(LXT_MESSAGE));
+ packet->length = 0;
+ packet->group = STATUS;
+ packet->action = param->ActionID;
}
else
{
- LOGERR("Unknown packet: %s", ijcmd->cmd);
+ LOGDEBUG("send data to injector");
}
-}
-bool server_process(void)
-{
- int i,nfds;
- int fd_tmp;
+ 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);
- nfds = epoll_wait(g_epoll_fd, g_events, MAX_EVENTS, 100);
+ ijmsg_send_to_evdi(g_fd[fdtype_device], param->type_cmd, (const char*) tmp, tmplen);
- if (nfds == -1 && errno != EAGAIN && errno != EINTR)
- {
- LOGERR("epoll wait(%d)", errno);
- return true;
+ free(tmp);
}
- for( i = 0 ; i < nfds ; i++ )
+ if(msg != 0)
{
- 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);
- }
+ free(msg);
+ msg = 0;
}
- return false;
-}
+ free(packet);
-void init_profile(void)
-{
+ if (param)
+ delete param;
+
+ pthread_exit((void *) 0);
}
-void exit_profile(void)
+void msgproc_sensor(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->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);
+ }
+ }
}
+bool extra_evdi_command(ijcommand* ijcmd) {
+ if (strncmp(ijcmd->cmd, IJTYPE_SENSOR, 6) == 0)
+ {
+ msgproc_sensor(ijcmd);
+ return true;
+ }
+ else if (strcmp(ijcmd->cmd, IJTYPE_LOCATION) == 0)
+ {
+ msgproc_location(ijcmd);
+ return true;
+ }
+ else if (strcmp(ijcmd->cmd, IJTYPE_SDCARD) == 0)
+ {
+ msgproc_sdcard(ijcmd);
+ return true;
+ }
+ return false;
+}
+++ /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;
- }
-
- free(packet);
-
- if (param)
- delete param;
-
- pthread_exit((void *) 0);
-}
-
-void msgproc_sensor(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->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) 2015 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 <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <vconf/vconf.h>
+#include <vconf/vconf-keys.h>
+
+#include "emuld.h"
+#include "tv.h"
+//#include "si_service_native.h"
+//#include "si_service_signal.h"
+
+#ifdef SI_ENABLE
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+static int motion_handle = 0;
+static int INIT_SERVER = 0;
+
+void init_gesture()
+{
+ /* initialize gesture structure */
+}
+
+
+int gesture_onehand(void)
+{
+ init_gesture();
+
+ //EmitSignal(SIGNAL_MOTION_START, NULL);
+ EmitSignal(SIGNAL_MOTION_BEGIN_MONITOR, NULL);
+ //EmitSignal(SIGNAL_MOTION_FUN_GESTURE_THUMBUP, NULL);
+ return 0;
+}
+
+int gesture_twohand(void)
+{
+ //EmitSignal(SIGNAL_MOTION_START, NULL);
+ return 0;
+}
+
+void gesture_end(void)
+{
+
+ EmitSignal(SIGNAL_MOTION_END_MONITOR, NULL);
+}
+
+
+void gesture_return(void)
+{
+// EmitSignal(SIGNAL_MOTION_ZOOM, (void *)val);
+
+}
+
+
+void gesture_slapleft(void)
+{
+ EmitSignal(SIGNAL_MOTION_SLAP_LEFT, NULL);
+}
+
+
+void gesture_slapright(void)
+{
+
+ EmitSignal(SIGNAL_MOTION_SLAP_RIGHT, NULL);
+}
+
+void gesture_circle(void)
+{
+
+ EmitSignal(SIGNAL_MOTION_FUN_GESTURE_THUMBUP, NULL);
+}
+
+void gesture_rotate(int data)
+{
+ //int p_angle[1];
+ //*p_angle = data;
+ //printf(" Rotation : angle=%d \n", *p_angle);
+ EmitSignal(SIGNAL_MOTION_ROTATE, (const void*)&data);
+ //EmitSignal(SIGNAL_MOTION_ROTATE, (const void*)p_angle);
+}
+
+void gesture_zoom(int data)
+{
+ //int val;
+ //val = data;
+ EmitSignal(SIGNAL_MOTION_ZOOM, (const void *)&data);
+}
+
+char *s1 = (char *)calloc(sizeof(char), 10);
+
+void si_get_cmd_list(const si_voice_cmd_item_s *cmdList, const int currentCnt)
+{
+
+ //if(NULL != cmdList && currentCnt > 0)
+ //{
+ // printf("cmd list, cnt=%d, list=%s\n", currentCnt, cmdList[0].excute_command);
+ //}
+ //return cmdList[0].excute_command;
+}
+
+void si_get_bgcmd_list(const char** bg_cmd_list, const int currentCnt)
+{
+ //if(NULL != bg_cmd_list && currentCnt > 0)
+ //{
+ // printf("bg cmd list, cnt=%d, list=%s\n", currentCnt, bg_cmd_list[0]);
+ //}
+ //return bg_cmd_list[0];
+}
+
+int send_hi_tv()
+{
+ //printf("Emit begin_monitor signal to SI server : HI TV\n");
+
+ /* Begin voice recognition */
+ EmitSignal(SIGNAL_VOICE_BEGIN_MONITOR, NULL);
+
+ return 0;
+}
+
+int get_voice_cmd()
+{
+
+ //printf("Set voice callback function! \n");
+ SetCmdChangedCallback(si_get_cmd_list);
+ SetBgCmdChangedCallback(si_get_bgcmd_list);
+
+ return 0;
+}
+
+int send_guide_me()
+{
+
+ sprintf(s1, "%s", "guide me");
+
+ si_voice_result_data_s t_voice;
+ t_voice.handle = 0;
+ t_voice.m_Domain = 0;
+ t_voice.m_Data = s1;
+
+ //printf("Emit signal to SI server : %s\n", s1);
+
+ EmitSignal(SIGNAL_VOICE_CUSTOM_RECOG_RESULT, &t_voice);
+
+ return 0;
+}
+
+int send_describe()
+{
+
+ sprintf(s1, "%s", "describe");
+
+ si_voice_result_data_s t_voice;
+ t_voice.handle = 0;
+ t_voice.m_Domain = 0;
+ t_voice.m_Data = s1;
+
+ //printf("Emit signal to SI server : %s\n", s1);
+
+ EmitSignal(SIGNAL_VOICE_DEFAULT_RECOG_RESULT, &t_voice);
+
+ return 0;
+}
+
+int send_left()
+{
+
+ sprintf(s1, "%s", "left");
+
+ si_voice_result_data_s t_voice;
+ t_voice.m_Domain = 20;
+ t_voice.m_Data = s1;
+
+ //printf("Emit signal to SI server : %s\n", s1);
+
+ EmitSignal(SIGNAL_VOICE_DEFAULT_RECOG_RESULT, &t_voice);
+
+ return 0;
+}
+
+int send_right()
+{
+
+ sprintf(s1, "%s", "right");
+
+ si_voice_result_data_s t_voice;
+ t_voice.m_Domain = 20;
+ t_voice.m_Data = s1;
+
+ //printf("Emit signal to SI server : %s\n", s1);
+
+ EmitSignal(SIGNAL_VOICE_DEFAULT_RECOG_RESULT, &t_voice);
+
+ return 0;
+}
+
+int send_close()
+{
+ //printf("Emit signal to SI server : close\n");
+
+ EmitSignal(SIGNAL_VOICE_END_MONITOR, NULL);
+
+ return 0;
+}
+#endif
+bool msgproc_gesture(ijcommand* ijcmd)
+{
+#ifdef SI_ENABLE
+ int command, ret, data;
+ const int tmpsize = ijcmd->msg.length;
+
+ char* data_p = NULL;
+ char token[] = "\n";
+ char tmpdata[tmpsize+1];
+ char* s_cnt = NULL;
+ int cnt = 0;
+
+ if (!SI_INIT) {
+ ret = InitServer();
+
+ if (ret) {
+ SI_INIT = true;
+ } else {
+ SI_INIT = false;
+ LOGERR("Failed to init server %s", ret);
+ }
+ }
+
+ memset(tmpdata, 0, tmpsize+1);
+ memcpy(tmpdata, ijcmd->data, tmpsize);
+
+ s_cnt = strtok(tmpdata, token);
+ cnt = atoi(s_cnt);
+
+ while(data_p = strtok(NULL, token)) {
+ data = atoi(data_p);
+ }
+ printf("msgproc_gesture action : %d\n", ijcmd->msg.action);
+
+ command = ijcmd->msg.action;
+
+ switch(command) {
+ case ONE_HAND :
+ gesture_onehand();
+ break;
+ case TWO_HAND :
+ gesture_twohand();
+ break;
+ case END_HAND :
+ gesture_end();
+ break;
+ case RETURN_HAND :
+ gesture_return();
+ break;
+ case SLAP_LEFT :
+ gesture_slapleft();
+ break;
+ case SLAP_RIGHT :
+ gesture_slapright();
+ break;
+ case CIRCLE :
+ gesture_circle();
+ break;
+ case ROTATE :
+ gesture_rotate(data);
+ break;
+ case ZOOM :
+ gesture_zoom(data);
+ break;
+ default :
+ LOGERR("invalid command");
+ }
+#endif
+ return true;
+}
+
+bool msgproc_voice(ijcommand* ijcmd)
+{
+#ifdef SI_ENABLE
+ int command, ret;
+
+ if (!SI_INIT) {
+ ret = InitServer();
+
+ if (ret) {
+ SI_INIT = true;
+ } else {
+ LOGERR("Failed to init server %s", ret);
+ }
+ }
+ printf("msgproc_voice() action:%d\n", ijcmd->msg.action);
+ //parsing cmd
+ command = ijcmd->msg.action;
+
+ switch(command) {
+ case HI_TV :
+ get_voice_cmd();
+ send_hi_tv();
+ break;
+ case GUIDE_ME :
+ send_guide_me();
+ break;
+ case DESCRIBE :
+ send_describe();
+ break;
+ case LEFT :
+ send_left();
+ break;
+ case RIGHT :
+ send_right();
+ break;
+ case V_CLOSE :
+ // SI_INIT = false;
+ send_close();
+ break;
+ default :
+ printf("ERROR : incorrect voice-command\n");
+ }
+/*
+ int sslen = sizeof(si_sensord_other);
+
+ 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)
+ {
+ LOG("pthread create fail!");
+ return false;
+ }
+
+ }
+ else if (sendto(g_fd[fdtype_sensor], ijcmd->data, ijcmd->msg.length, 0,
+ (struct sockaddr*) &si_sensord_other, sslen) == -1)
+ {
+ LOG("sendto error!");
+ return false;
+ } */
+#endif
+ return true;
+}
+
+enum {
+ EXTINPUT_HDMI1 = 1,
+ EXTINPUT_HDMI2,
+ EXTINPUT_HDMI3,
+ EXTINPUT_HDMI4,
+ EXTINPUT_AV1,
+ EXTINPUT_AV2,
+ EXTINPUT_COMP1,
+ EXTINPUT_COMP2,
+};
+#define STATE_CHECKER 0xffff
+#define STATE_SHIFT 16
+#define MAX_EXTINPUT_COUNT 8
+#define EXTINPUT_GET_INFO 2
+#define HDMI_CNT 4
+#define AV_CNT 2
+#define COMP_CNT 1
+static unsigned int extinput[MAX_EXTINPUT_COUNT];
+bool msgproc_extinput(ijcommand* ijcmd)
+{
+ char command[128];
+ memset(command, '\0', sizeof(command));
+
+ if (ijcmd->msg.action == EXTINPUT_GET_INFO) {
+ int i = 0;
+ char *tmp;
+ int tmplen = HEADER_SIZE + 16;
+ int onoff_state = 0;
+ LXT_MESSAGE *packet = (LXT_MESSAGE *)malloc(sizeof(LXT_MESSAGE));
+ if (packet) {
+ memset(packet, 0, sizeof(LXT_MESSAGE));
+ }
+ /* get hdmi plugged state */
+ for (i = 0; i < HDMI_CNT; i++) {
+ sprintf(command, "memory/sysman/hdmi%d", i+1);
+ if (vconf_get_int(command, &onoff_state)) {
+ onoff_state = 0;
+ }
+ extinput[i] = onoff_state;
+ }
+ /* get av plugged state */
+ for (i = 0; i < AV_CNT; i++) {
+ sprintf(command, "memory/sysman/av%d", i+1);
+ if (vconf_get_int(command, &onoff_state)) {
+ onoff_state = 0;
+ }
+ extinput[i + HDMI_CNT] = onoff_state;
+ }
+ /* get comp plugged state */
+ for (i = 0; i < COMP_CNT; i++) {
+ sprintf(command, "memory/sysman/comp%d", i+1);
+ if (vconf_get_int(command, &onoff_state)) {
+ onoff_state = 0;
+ }
+ extinput[i + HDMI_CNT + AV_CNT] = onoff_state;
+ }
+
+ /* send current state to Emulator Control Panel */
+ tmp = (char *)malloc(tmplen);
+ if (tmp) {
+ memset(command, 0, sizeof(command));
+ packet->length = 16;
+ packet->group = 15;
+ packet->action = 211;
+ memcpy(tmp, packet, HEADER_SIZE);
+ sprintf(command, "%d:%d:%d:%d:%d:%d:%d:%d:",
+ extinput[0], extinput[1], extinput[2], extinput[3], extinput[4], extinput[5], extinput[6], extinput[7]);
+ memcpy(tmp + HEADER_SIZE, command, packet->length);
+ ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_EI, (const char *)tmp, tmplen);
+ free(tmp);
+ }
+
+ if (packet) {
+ free(packet);
+ packet = NULL;
+ }
+ } else {
+ char plugged[128];
+ char token[] = ":";
+ char *section = NULL;
+ unsigned int number = 0;
+ unsigned int state = 0;
+ memset(plugged, '\0', sizeof(plugged));
+ memcpy(plugged, ijcmd->data, ijcmd->msg.length);
+
+ section = strtok(plugged, token);
+ number = (unsigned int)atoi(section);
+ section = strtok(NULL, token);
+ state = (unsigned int)atoi(section);
+
+ if (number > MAX_EXTINPUT_COUNT) {
+ LOGDEBUG("external_input number : %d is invalid.", number);
+ return false;
+ }
+
+ switch (number) {
+ case EXTINPUT_HDMI1:
+ case EXTINPUT_HDMI2:
+ case EXTINPUT_HDMI3:
+ case EXTINPUT_HDMI4:
+ sprintf(command, "vconftool set -t int memory/sysman/hdmi%d %d -i -f", number, state);
+ break;
+ case EXTINPUT_AV1:
+ sprintf(command, "vconftool set -t int memory/sysman/av1 %d -i -f", state);
+ break;
+ case EXTINPUT_AV2:
+ sprintf(command, "vconftool set -t int memory/sysman/av2 %d -i -f", state);
+ break;
+ case EXTINPUT_COMP1:
+ sprintf(command, "vconftool set -t int memory/sysman/comp1 %d -i -f", state);
+ break;
+ case EXTINPUT_COMP2:
+ sprintf(command, "vconftool set -t int memory/sysman/comp2 %d -i -f", state);
+ break;
+ }
+ extinput[number-1] = state;
+ systemcall(command);
+ }
+
+ return true;
+}
+
+bool extra_evdi_command(ijcommand* ijcmd) {
+
+ if (strncmp(ijcmd->cmd, IJTYPE_GESTURE, 7) == 0)
+ {
+ msgproc_gesture(ijcmd);
+ return true;
+ }
+ else if (strncmp(ijcmd->cmd, IJTYPE_VOICE, 5) == 0)
+ {
+ msgproc_voice(ijcmd);
+ return true;
+ }
+ else if (strncmp(ijcmd->cmd, IJTYPE_EI, 2) == 0)
+ {
+ msgproc_extinput(ijcmd);
+ return true;
+ }
+
+ return false;
+}
*/
#include <stdio.h>
-#include <errno.h>
#include "emuld.h"
#include "wearable.h"
-void process_evdi_command(ijcommand* ijcmd)
+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)
{
- if (strcmp(ijcmd->cmd, "suspend") == 0)
- {
- msgproc_suspend(ijcmd);
- }
- else if (strcmp(ijcmd->cmd, "sensor") == 0)
- {
- msgproc_sensor(ijcmd);
- }
- else if (strcmp(ijcmd->cmd, "location") == 0)
- {
- msgproc_location(ijcmd);
- }
- else if (strcmp(ijcmd->cmd, "hds") == 0)
- {
- msgproc_hds(ijcmd);
- }
- else if (strcmp(ijcmd->cmd, "system") == 0)
- {
- msgproc_system(ijcmd);
+ 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);
}
- else if (strcmp(ijcmd->cmd, IJTYPE_PACKAGE) == 0)
+
+ 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)
{
- msgproc_package(ijcmd);
+ LOGERR("fopen fail: %s", file_name);
+ return -1;
}
- else if (strcmp(ijcmd->cmd, "sdcard") == 0)
- {
- msgproc_sdcard(ijcmd);
+
+ ret = fscanf(fd, "%d", &value);
+ fclose(fd);
+ if (ret <= 0) {
+ LOGERR("failed to get value");
+ return -1;
}
- else if (strcmp(ijcmd->cmd, "cmd") == 0)
+
+ return value;
+}
+
+static void write_to_file(const char* file_name, int value)
+{
+ FILE* fd;
+
+ fd = fopen(file_name, "w");
+ if(!fd)
{
- msgproc_cmd(ijcmd);
+ LOGERR("fopen fail: %s", file_name);
+ return;
}
- else
+ 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("Unknown packet: %s", ijcmd->cmd);
+ 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;
}
-bool server_process(void)
+static void setting_sensor(char *buffer)
{
- int i,nfds;
- int fd_tmp;
+ int len = 0;
+ int ret = 0;
+ char tmpbuf[255];
- nfds = epoll_wait(g_epoll_fd, g_events, MAX_EVENTS, 100);
+ LOGDEBUG("read data: %s", buffer);
- if (nfds == -1 && errno != EAGAIN && errno != EINTR)
+ // read sensor type
+ memset(tmpbuf, '\0', sizeof(tmpbuf));
+ len = parse_val(buffer, 0x0a, tmpbuf);
+
+ switch(atoi(tmpbuf))
{
- LOGERR("epoll wait(%d)", errno);
- return true;
+ 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;
}
+}
- for( i = 0 ; i < nfds ; i++ )
+void msgproc_sensor(ijcommand* ijcmd)
+{
+ LOGDEBUG("msgproc_sensor");
+
+ if (ijcmd->msg.group != STATUS)
{
- 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);
+ if (ijcmd->data != NULL && strlen(ijcmd->data) > 0) {
+ setting_sensor(ijcmd->data);
}
}
-
- return false;
}
-void init_profile(void)
-{
-}
+bool extra_evdi_command(ijcommand* ijcmd) {
-void exit_profile(void)
-{
+ if (strncmp(ijcmd->cmd, IJTYPE_SENSOR, 6) == 0)
+ {
+ msgproc_sensor(ijcmd);
+ return true;
+ }
+ else if (strcmp(ijcmd->cmd, IJTYPE_LOCATION) == 0)
+ {
+ msgproc_location(ijcmd);
+ return true;
+ }
+ else if (strcmp(ijcmd->cmd, IJTYPE_SDCARD) == 0)
+ {
+ msgproc_sdcard(ijcmd);
+ return true;
+ }
+ return false;
}
+++ /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(ijcommand* ijcmd)
-{
- LOGDEBUG("msgproc_sensor");
-
- if (ijcmd->msg.group != 15)
- {
- if (ijcmd->data != NULL && strlen(ijcmd->data) > 0) {
- device_parser(ijcmd->data);
- }
- }
-}