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