sensor-hal: rename interface of HAL for managing it easily
[platform/adaptation/tm1/sensor-hal-tm1.git] / src / interface / sensor_device_base.h
1 /*
2  * libsensord-share
3  *
4  * Copyright (c) 2014 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 #ifndef _SENSOR_DEVICE_BASE_H_
21 #define _SENSOR_DEVICE_BASE_H_
22 #include <sys/time.h>
23 #include <sensor_logs.h>
24 #include <string>
25 #include <sensor_hal.h>
26
27 /*
28 * As of Linux 3.4, there is a new EVIOCSCLOCKID ioctl to set the desired clock
29 * Current kernel-headers package doesn't have it so we should define it here.
30 */
31
32 #ifndef EVIOCSCLOCKID
33 /* Set clockid to be used for timestamps */
34 #define EVIOCSCLOCKID           _IOW('E', 0xa0, int)
35 #endif
36
37 typedef struct {
38         int method;
39         std::string data_node_path;
40         std::string enable_node_path;
41         std::string interval_node_path;
42         std::string buffer_enable_node_path;
43         std::string buffer_length_node_path;
44         std::string trigger_node_path;
45 } node_info;
46
47 typedef struct {
48         bool sensorhub_controlled;
49         std::string sensor_type;
50         std::string key;
51         std::string iio_enable_node_name;
52         std::string sensorhub_interval_node_name;
53 } node_info_query;
54
55 enum input_method {
56         IIO_METHOD = 0,
57         INPUT_EVENT_METHOD = 1,
58 };
59
60 typedef struct {
61         int method;
62         std::string dir_path;
63         std::string prefix;
64 } input_method_info;
65
66 class sensor_device_base : public sensor_device
67 {
68 public:
69         sensor_device_base();
70         virtual ~sensor_device_base();
71
72 protected:
73         bool set_enable_node(const std::string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0);
74
75         static unsigned long long get_timestamp(void);
76         static unsigned long long get_timestamp(timeval *t);
77         static bool is_sensorhub_controlled(const std::string &key);
78         static bool get_node_info(const node_info_query &query, node_info &info);
79         static void show_node_info(node_info &info);
80         static bool set_node_value(const std::string &node_path, int value);
81         static bool set_node_value(const std::string &node_path, unsigned long long value);
82         static bool get_node_value(const std::string &node_path, int &value);
83 private:
84         static bool get_event_num(const std::string &node_path, std::string &event_num);
85         static bool get_input_method(const std::string &key, int &method, std::string &device_num);
86
87         static bool get_iio_node_info(const std::string& enable_node_name, const std::string& device_num, node_info &info);
88         static bool get_sensorhub_iio_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info);
89         static bool get_input_event_node_info(const std::string& device_num, node_info &info);
90         static bool get_sensorhub_input_event_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info);
91 };
92 #endif /*_SENSOR_DEVICE_BASE_H_*/