sensorctl test
[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 #include <sensorctl_log.h>
27 #include "dbus_util.h"
28 #include "injector_manager.h"
29 #include "injector_wristup_algo.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 bool injector_wristup_algo::init(void)
38 {
39         option_map.insert(option_map_t::value_type("auto", 0));
40         option_map.insert(option_map_t::value_type("green", 1));
41         option_map.insert(option_map_t::value_type("purple", 2));
42         option_map.insert(option_map_t::value_type("red", 3));
43
44         return true;
45 }
46
47 bool injector_wristup_algo::inject(int option_count, char *options[])
48 {
49         int option;
50
51         if (option_count == 0) {
52                 _E("ERROR: invalid argument\n");
53                 return false;
54         }
55
56         option_map_t::iterator it;
57         it = option_map.find(options[OPTION_INDEX]);
58
59         if (it == option_map.end()) {
60                 _E("ERROR: no matched-option: %s\n", options[OPTION_INDEX]);
61                 return false;
62         }
63
64         option = it->second;
65
66         dbus_emit_signal(NULL,
67                         (gchar *)SENSORD_OBJ_PATH,
68                         (gchar *)SENSORD_INTERFACE_NAME,
69                         (gchar *)WRISTUP_ALGO_SIGNAL,
70                         g_variant_new("(i)", option),
71                         NULL);
72
73         _I("set [%s] mode to wristup (%d)", options[OPTION_INDEX], option);
74         return true;
75 }
76
77 REGISTER_INJECTOR(MOTION_SENSOR, "algo", injector_wristup_algo)