2 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <device-node.h>
22 #include "ss_predefine.h"
23 #include "include/ss_data.h"
37 static GList *haptic_head;
39 static int add_node(struct haptic_node *node)
41 haptic_head = g_list_append(haptic_head, node);
44 static int delete_node(struct haptic_node *node)
46 haptic_head = g_list_remove(haptic_head, node);
49 static struct haptic_node *find_node(int pid)
52 struct haptic_node *node = NULL;
54 for (elem = haptic_head; elem; elem = elem->next) {
63 static int haptic_play(int pid)
65 struct haptic_node *node;
68 node = malloc(sizeof(struct haptic_node));
70 PRT_TRACE_ERR("malloc fail");
80 r = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_ENABLE, 1);
82 PRT_TRACE_ERR("set enable fail");
89 static void check_play_state(gpointer data, gpointer user_data)
91 struct haptic_node *node = (struct haptic_node*)data;
92 int *play = (int*)user_data;
95 PRT_TRACE_ERR("node pid : %d, level : %d, play : %d", node->pid, node->level, node->play);
98 static int haptic_stop(int pid)
100 struct haptic_node *node;
104 node = find_node(pid);
106 PRT_TRACE_ERR("find_node(%d) fail", pid);
114 g_list_foreach(haptic_head, check_play_state, &play);
115 PRT_TRACE_ERR("play state : %d", play);
118 PRT_TRACE_ERR("not playing anymore, will be stop");
119 r = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_ENABLE, 0);
121 PRT_TRACE_ERR("set enable fail");
129 static void get_current_level(gpointer data, gpointer user_data)
131 struct haptic_node *node = (struct haptic_node*)data;
132 int *sum = (int*)user_data;
134 PRT_TRACE_ERR("node pid : %d, level : %d, play : %d", node->pid, node->level, node->play);
135 if (node->play == 1) {
136 PRT_TRACE_ERR("node->play : %d, sum : %d", node->play, *sum);
141 static int haptic_change_level(int pid, int level)
143 struct haptic_node *node;
147 PRT_TRACE_ERR("pid : %d, level : %d", pid, level);
149 node = find_node(pid);
151 PRT_TRACE_ERR("find_node(%d) fail", pid);
157 g_list_foreach(haptic_head, get_current_level, &sum);
158 PRT_TRACE_ERR("current sum level : %d", sum);
160 r = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_LEVEL, sum);
162 PRT_TRACE_ERR("set level fail");
169 int haptic_def_predefine_action(int argc, char **argv)
175 PRT_TRACE_ERR("argc : %d", argc);
176 for (i = 0; i < argc; ++i)
177 PRT_TRACE_ERR("[%2d] %s", i, argv[i]);
180 PRT_TRACE_ERR("Haptic predefine action failed");
185 mode = atoi(argv[1]);
186 PRT_TRACE_ERR("pid : %d, mode : %d", pid, mode);
196 haptic_change_level(pid, atoi(argv[2]));