[Non-ACR][TFIVE-357]
[platform/core/system/sensord.git] / src / sensorctl / injector_wristup_algo.cpp
1 /*
2  * sensorctl
3  *
4  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <glib.h>
23 #include <gio/gio.h>
24 #include <map>
25 #include <string>
26
27 #include "log.h"
28 #include "dbus_util.h"
29 #include "injector.h"
30
31 #define WRISTUP_ALGO_SIGNAL "algo"
32 #define OPTION_INDEX 0
33
34 typedef std::map<std::string, int> option_map_t;
35 static option_map_t option_map;
36
37 class injector_wristup_algo : public injector {
38 public:
39         injector_wristup_algo(sensor_type_t sensor_type, const char *event_name);
40         virtual ~injector_wristup_algo() {}
41
42         bool setup(void);
43         bool inject(int argc, char *argv[]);
44 };
45
46 injector_wristup_algo::injector_wristup_algo(sensor_type_t sensor_type, const char *event_name)
47 : injector(sensor_type, event_name)
48 {
49 }
50
51 bool injector_wristup_algo::setup(void)
52 {
53         option_map.insert(option_map_t::value_type("auto", 0));
54         option_map.insert(option_map_t::value_type("green", 1));
55         option_map.insert(option_map_t::value_type("purple", 2));
56         option_map.insert(option_map_t::value_type("red", 3));
57
58         return true;
59 }
60
61 bool injector_wristup_algo::inject(int argc, char *argv[])
62 {
63         int option;
64
65         RETVM_IF(argc == 0, false, "Invalid argument\n");
66
67         option_map_t::iterator it;
68         it = option_map.find(argv[INJECTOR_ARGC]);
69         RETVM_IF(it == option_map.end(), false, "No matched option: %s\n", argv[INJECTOR_ARGC]);
70
71         option = it->second;
72
73         dbus_emit_signal(NULL,
74                         (gchar *)SENSORD_OBJ_PATH,
75                         (gchar *)SENSORD_INTERFACE_NAME,
76                         (gchar *)WRISTUP_ALGO_SIGNAL,
77                         g_variant_new("(i)", option),
78                         NULL);
79
80         _I("Set up [%s] mode to wristup (%d)\n", argv[INJECTOR_ARGC], option);
81         return true;
82 }
83
84 REGISTER_INJECTOR(GESTURE_WRIST_UP_SENSOR, WRISTUP_ALGO_SIGNAL, injector_wristup_algo)