+++ /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.");
- }
-}
-
-
+++ /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_signal(power_device, DBUS_SEND_SYSNOTI, 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) 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_signal(power_device, DBUS_SEND_SYSNOTI, 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);
- }
- }
-}