sensorctl test
[platform/core/system/sensord.git] / src / sensorctl / sensorctl.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 <string.h>
23 #include <signal.h>
24
25 #include <sensorctl_log.h>
26 #include "sensor_manager.h"
27 #include "tester_manager.h"
28 #include "injector_manager.h"
29 #include "info_manager.h"
30
31 static void good_bye(void)
32 {
33 }
34
35 static void signal_handler(int signo)
36 {
37         _E("\nReceived SIGNAL(%d)\n", signo);
38         exit(EXIT_SUCCESS);
39
40         return;
41 }
42
43 void usage(void)
44 {
45         PRINT("usage: sensorctl <command> <sensor_type> [<args>]\n");
46
47         PRINT("The sensorctl commands are:\n");
48         PRINT("  test:   test sensor(s)\n");
49         PRINT("  inject: inject the event to sensor\n");
50         PRINT("  info:   show sensor infos\n");
51 }
52
53 sensor_manager *create_manager(int argc, char *argv[2])
54 {
55         sensor_manager *manager = NULL;
56
57         if (!strcmp(argv[1], "test"))
58                 manager = new(std::nothrow) tester_manager;
59         if (!strcmp(argv[1], "inject"))
60                 manager = new(std::nothrow) injector_manager;
61         if (!strcmp(argv[1], "info"))
62                 manager = new(std::nothrow) info_manager;
63
64         if (!manager) {
65                 _E("failed to allocate memory for manager");
66                 return NULL;
67         }
68
69         return manager;
70 }
71
72 int main(int argc, char *argv[])
73 {
74         atexit(good_bye);
75
76         signal(SIGINT,  signal_handler);
77         signal(SIGHUP,  signal_handler);
78         signal(SIGTERM, signal_handler);
79         signal(SIGQUIT, signal_handler);
80         signal(SIGABRT, signal_handler);
81
82         if (argc < 2) {
83                 usage();
84                 return 0;
85         }
86
87         sensor_manager *manager = create_manager(argc, argv);
88         if (!manager) {
89                 usage();
90                 return 0;
91         }
92
93         manager->process(argc, argv);
94
95         return 0;
96 }