Add sensor APIs related to batch event
[platform/core/system/sensord.git] / src / sensorctl / sensor_adapter.h
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 #pragma once /* __SENSOR_ADAPTER_H__ */
21
22 #include <sensor_internal.h>
23
24 class sensor_info {
25 public:
26         sensor_info()
27         { }
28
29         sensor_info(sensor_type_t _type, int _index, int _interval, int _batch_latency, int _powersave, sensor_cb_t _cb, void *_user_data)
30         : type(_type)
31         , index(_index)
32         , interval(_interval)
33         , batch_latency(_batch_latency)
34         , powersave(_powersave)
35         , cb(_cb)
36         , user_data(_user_data)
37         { }
38
39         sensor_info(sensor_type_t _type, int _index, int _interval, int _batch_latency, int _powersave, sensor_events_cb_t _events_cb, void *_user_data)
40         : type(_type)
41         , index(_index)
42         , interval(_interval)
43         , batch_latency(_batch_latency)
44         , powersave(_powersave)
45         , events_cb(_events_cb)
46         , user_data(_user_data)
47         { }
48
49         sensor_type_t type { UNKNOWN_SENSOR };
50         int index { 0 };
51         int interval { 0 };
52         int batch_latency { 0 };
53         int powersave { 0 };
54         union
55         {
56                 sensor_cb_t cb { NULL };
57                 sensor_events_cb_t events_cb;
58         };
59         void *user_data { NULL };
60 };
61
62 class sensor_adapter {
63 public:
64         static bool is_supported(sensor_type_t type);
65         static int  get_count(sensor_type_t type);
66         static bool get_handle(sensor_info info, int &handle);
67
68         static bool start(sensor_info info, int &handle);
69         static bool stop(sensor_info info, int handle);
70
71         static bool change_interval(int handle, int interval);
72         static bool change_batch_latency(int handle, int batch_latency);
73         static bool change_powersave(int handle, int powersave);
74         static bool set_attribute(int handle, int attribute, int value);
75         static bool set_attribute(int handle, int attribute, char *value, int size);
76
77         static bool get_data(int handle, sensor_type_t type, sensor_data_t &data);
78         static bool flush(int handle);
79         static bool is_batch_mode;
80 };