[Non-ACR][TFIVE-357]
[platform/core/system/sensord.git] / src / sensorctl / info.cpp
1 /*
2  * sensorctl
3  *
4  * Copyright (c) 2017 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 "info.h"
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <glib.h>
25 #include <sensor_internal.h>
26
27 #include "log.h"
28
29 #define INFO_ARGC 3 /* e.g. {sensorctl, info, accelerometer} */
30
31 bool info_manager::run(int argc, char *argv[])
32 {
33         sensor_type_t type;
34         sensor_t *sensors;
35         int count;
36
37         if (argc < INFO_ARGC) {
38                 usage();
39                 return false;
40         }
41
42         type = get_sensor_type(argv[2]);
43         RETVM_IF(type == UNKNOWN_SENSOR, false, "Wrong argument : %s\n", argv[2]);
44
45         sensord_get_sensor_list(type, &sensors, &count);
46         show_info(sensors, count);
47
48         if (sensors) {
49                 free(sensors);
50                 sensors = NULL;
51         }
52         return true;
53 }
54
55 void info_manager::show_info(sensor_t *sensors, int count)
56 {
57         sensor_type_t type;
58         sensor_t sensor;
59         char *vendor;
60         char *name;
61         float min_range;
62         float max_range;
63         float resolution;
64         int min_interval;
65         int fifo_count;
66         int max_batch_count;
67
68         for (int i = 0; i < count; ++i) {
69                 sensor = sensors[i];
70
71                 sensord_get_type(sensor, &type);
72                 name = const_cast<char *>(sensord_get_name(sensor));
73                 vendor = const_cast<char *>(sensord_get_vendor(sensor));
74                 sensord_get_max_range(sensor, &max_range);
75                 sensord_get_min_range(sensor, &min_range);
76                 sensord_get_resolution(sensor, &resolution);
77                 sensord_get_min_interval(sensor, &min_interval);
78                 sensord_get_fifo_count(sensor, &fifo_count);
79                 sensord_get_max_batch_count(sensor, &max_batch_count);
80
81                 _N("-------sensor[%d] information-------\n", i);
82                 _N("type            : %#x\n", type);
83                 _N("vendor          : %s\n", vendor);
84                 _N("name            : %s\n", name);
85                 _N("min_range       : %f\n", min_range);
86                 _N("max_range       : %f\n", max_range);
87                 _N("resolution      : %f\n", resolution);
88                 _N("min_interval    : %d\n", min_interval);
89                 _N("fifo_count      : %d\n", fifo_count);
90                 _N("max_batch_count : %d\n", max_batch_count);
91                 _N("--------------------------------\n");
92         }
93 }
94
95 void info_manager::usage(void)
96 {
97         _N("usage: sensorctl info <sensor_type>\n\n");
98
99         usage_sensors();
100 }