From 95650e4366295f686ba8c4474fc6cc468ca0f09b Mon Sep 17 00:00:00 2001 From: "jy910.yun" Date: Fri, 8 Mar 2013 14:22:37 +0900 Subject: [PATCH] add ss_vibrator.c support for vibration between multi application when requesting vibration, haptic-module-tizen send to system_server --- CMakeLists.txt | 1 + include/ss_data.h | 1 + packaging/system-server.manifest | 28 +++--- packaging/system-server.spec | 2 +- ss_predefine.c | 6 +- ss_vibrator.c | 203 +++++++++++++++++++++++++++++++++++++++ ss_vibrator.h | 23 +++++ 7 files changed, 248 insertions(+), 16 deletions(-) create mode 100644 ss_vibrator.c create mode 100644 ss_vibrator.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a733074..8ad3a00 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ SET(SRCS ss_procmgr.c ss_timemgr.c ss_cpu_handler.c + ss_vibrator.c ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/include/ss_data.h b/include/ss_data.h index 1c860ae..d56aad7 100644 --- a/include/ss_data.h +++ b/include/ss_data.h @@ -50,6 +50,7 @@ enum { #define PREDEF_USB_STORAGE_ADD "usbstorage-add" #define PREDEF_USB_STORAGE_REMOVE "usbstorage-remove" #define PREDEF_INACTIVE "inactive" +#define PREDEF_HAPTIC "haptic" #define OOMADJ_SET "oomadj_set" #define LOW_MEM_ACT "low_mem_act" diff --git a/packaging/system-server.manifest b/packaging/system-server.manifest index 99cdb25..fa0d09e 100644 --- a/packaging/system-server.manifest +++ b/packaging/system-server.manifest @@ -1,16 +1,16 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/packaging/system-server.spec b/packaging/system-server.spec index b5c1e09..df0ac47 100755 --- a/packaging/system-server.spec +++ b/packaging/system-server.spec @@ -2,7 +2,7 @@ Name: system-server Summary: System server Version: 0.1.65 -Release: 2 +Release: 3 Group: Framework/system License: Apache License, Version 2.0 Source0: system-server-%{version}.tar.gz diff --git a/ss_predefine.c b/ss_predefine.c index d6a1f1a..6674146 100644 --- a/ss_predefine.c +++ b/ss_predefine.c @@ -38,6 +38,7 @@ #include "device-node.h" #include "ss_predefine.h" #include "ss_procmgr.h" +#include "ss_vibrator.h" #include "include/ss_data.h" #define PREDEFINE_SO_DIR PREFIX"/lib/ss_predefine/" @@ -626,6 +627,7 @@ int flight_mode_def_predefine_action(int argc, char **argv) return 0; } + static void ss_action_entry_load_from_sodir() { DIR *dp; @@ -730,9 +732,11 @@ void ss_predefine_internal_init(void) launching_predefine_action, NULL, NULL); ss_action_entry_add_internal(PREDEF_REBOOT, restart_def_predefine_action, NULL, NULL); - ss_action_entry_add_internal(PREDEF_FLIGHT_MODE, flight_mode_def_predefine_action, NULL, NULL); + ss_action_entry_add_internal(PREDEF_HAPTIC, haptic_def_predefine_action, + NULL, NULL); + if (vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (void *)poweroff_control_cb, NULL) < 0) { PRT_TRACE_ERR("Vconf notify key chaneged failed: KEY(%s)", VCONFKEY_SYSMAN_POWER_OFF_STATUS); } diff --git a/ss_vibrator.c b/ss_vibrator.c new file mode 100644 index 0000000..9ea3343 --- /dev/null +++ b/ss_vibrator.c @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + + +#include +#include + +#include "ss_log.h" +#include "ss_predefine.h" +#include "include/ss_data.h" + +enum { + PLAY_HAPTIC = 0, + STOP_HAPTIC, + LEVEL_HAPTIC, +}; + +struct haptic_node { + int pid; + int level; + int play; +}; + +static GList *haptic_head; + +static int add_node(struct haptic_node *node) +{ + haptic_head = g_list_append(haptic_head, node); +} + +static int delete_node(struct haptic_node *node) +{ + haptic_head = g_list_remove(haptic_head, node); +} + +static struct haptic_node *find_node(int pid) +{ + GList *elem; + struct haptic_node *node = NULL; + + for (elem = haptic_head; elem; elem = elem->next) { + node = elem->data; + if (node->pid == pid) + break; + } + + return node; +} + +static int haptic_play(int pid) +{ + struct haptic_node *node; + int r; + + node = malloc(sizeof(struct haptic_node)); + if (node == NULL) { + PRT_TRACE_ERR("malloc fail"); + return -1; + } + + node->pid = pid; + node->level = 0; + node->play = 1; + + add_node(node); + + r = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_ENABLE, 1); + if (r < 0) { + PRT_TRACE_ERR("set enable fail"); + return -1; + } + + return 0; +} + +static void check_play_state(gpointer data, gpointer user_data) +{ + struct haptic_node *node = (struct haptic_node*)data; + int *play = (int*)user_data; + + *play += node->play; + PRT_TRACE_ERR("node pid : %d, level : %d, play : %d", node->pid, node->level, node->play); +} + +static int haptic_stop(int pid) +{ + struct haptic_node *node; + int play = 0; + int r; + + node = find_node(pid); + if (node == NULL) { + PRT_TRACE_ERR("find_node(%d) fail", pid); + return -1; + } + + node->play = 0; + delete_node(node); + free(node); + + g_list_foreach(haptic_head, check_play_state, &play); + PRT_TRACE_ERR("play state : %d", play); + + if (!play) { + PRT_TRACE_ERR("not playing anymore, will be stop"); + r = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_ENABLE, 0); + if (r < 0) { + PRT_TRACE_ERR("set enable fail"); + return -1; + } + } + + return 0; +} + +static void get_current_level(gpointer data, gpointer user_data) +{ + struct haptic_node *node = (struct haptic_node*)data; + int *sum = (int*)user_data; + + PRT_TRACE_ERR("node pid : %d, level : %d, play : %d", node->pid, node->level, node->play); + if (node->play == 1) { + PRT_TRACE_ERR("node->play : %d, sum : %d", node->play, *sum); + *sum += node->level; + } +} + +static int haptic_change_level(int pid, int level) +{ + struct haptic_node *node; + int sum = 0; + int r; + + PRT_TRACE_ERR("pid : %d, level : %d", pid, level); + + node = find_node(pid); + if (node == NULL) { + PRT_TRACE_ERR("find_node(%d) fail", pid); + return -1; + } + + node->level = level; + + g_list_foreach(haptic_head, get_current_level, &sum); + PRT_TRACE_ERR("current sum level : %d", sum); + + r = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_LEVEL, sum); + if (r < 0) { + PRT_TRACE_ERR("set level fail"); + return -1; + } + + return 0; +} + +int haptic_def_predefine_action(int argc, char **argv) +{ + int i; + int pid; + int mode; + + PRT_TRACE_ERR("argc : %d", argc); + for (i = 0; i < argc; ++i) + PRT_TRACE_ERR("[%2d] %s", i, argv[i]); + + if (argc != 3) { + PRT_TRACE_ERR("Haptic predefine action failed"); + return -1; + } + + pid = atoi(argv[0]); + mode = atoi(argv[1]); + PRT_TRACE_ERR("pid : %d, mode : %d", pid, mode); + + switch(mode) { + case PLAY_HAPTIC: + haptic_play(pid); + break; + case STOP_HAPTIC: + haptic_stop(pid); + break; + case LEVEL_HAPTIC: + haptic_change_level(pid, atoi(argv[2])); + break; + default: + break; + } + + return 0; +} diff --git a/ss_vibrator.h b/ss_vibrator.h new file mode 100644 index 0000000..43c98c5 --- /dev/null +++ b/ss_vibrator.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + + +#ifndef __SS_VIBRATOR_H__ +#define __SS_VIBRATOR_H__ + +int haptic_def_predefine_action(int argc, char **argv); + +#endif /* __SS_VIBRATOR_H__ */ -- 2.7.4