sensord: change the HAL interface
[platform/core/system/sensord.git] / src / server / sensor_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_BASE_H_
21 #define _SENSOR_BASE_H_
22
23 #include <vector>
24 #include <sensor_types.h>
25 #include <plugin_info_list.h>
26 #include <cmutex.h>
27
28 #include <sensor_logs.h>
29 #include <sensor_common.h>
30 #include <worker_thread.h>
31 #include <sensor_info.h>
32 #include <sensor_hal.h>
33
34 class sensor_base {
35 public:
36         sensor_base();
37         virtual ~sensor_base();
38
39         /* id */
40         void set_id(sensor_id_t id);
41         sensor_id_t get_id(void);
42
43         /* sensor info */
44         virtual sensor_type_t get_type();
45         virtual unsigned int get_event_type(void);
46         virtual const char* get_name(void);
47
48         virtual bool get_sensor_info(sensor_info &info);
49         virtual bool is_virtual(void);
50
51         /* set/get data */
52         virtual int get_data(sensor_data_t **data, int *length);
53
54         virtual bool flush(void);
55         virtual int set_attribute(int32_t attribute, int32_t value);
56         virtual int set_attribute(char *attribute, char *value, int value_size);
57
58         /* start/stop */
59         bool start(void);
60         bool stop(void);
61         bool is_started(void);
62
63         /* interval / batch / wakeup */
64         bool add_interval(int client_id, unsigned int interval, bool is_processor);
65         bool delete_interval(int client_id, bool is_processor);
66         unsigned int get_interval(int client_id, bool is_processor);
67
68         bool add_batch(int client_id, unsigned int latency);
69         bool delete_batch(int client_id);
70         unsigned int get_batch(int client_id);
71
72         bool add_wakeup(int client_id, int wakeup);
73         bool delete_wakeup(int client_id);
74         int get_wakeup(int client_id);
75         bool is_wakeup_supported(void);
76
77         bool push(sensor_event_t *event);
78
79         /* permission(privilege) */
80         int get_permission(void);
81
82 protected:
83         void set_permission(int permission);
84
85 private:
86         sensor_id_t m_unique_id;
87         int m_permission;
88
89         plugin_info_list m_plugin_info_list;
90         cmutex m_plugin_info_list_mutex;
91
92         bool m_started;
93         unsigned int m_client;
94         cmutex m_client_mutex;
95
96         virtual bool set_interval(unsigned long interval);
97         virtual bool set_batch_latency(unsigned long latency);
98         virtual bool set_wakeup(int wakeup);
99
100         virtual bool on_start(void);
101         virtual bool on_stop(void);
102
103         static unsigned long long get_timestamp(void);
104         static unsigned long long get_timestamp(timeval *t);
105 };
106
107 #endif /* _SENSOR_BASE_H_ */