sensord: change the HAL interface
[platform/core/system/sensord.git] / src / shared / sf_common.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 _SF_COMMON_H_
21 #define _SF_COMMON_H_
22
23 #include <unistd.h>
24 #include <sensor_common.h>
25 #include <string>
26 #include <vector>
27 #include <sensor_logs.h>
28
29 #define COMMAND_CHANNEL_PATH                    "/tmp/sensord_command_socket"
30 #define EVENT_CHANNEL_PATH                              "/tmp/sensord_event_socket"
31
32 #define MAX_HANDLE                      256
33 #define MAX_HANDLE_REACHED      -2
34
35 #define CLIENT_ID_INVALID   -1
36
37 enum packet_type_t {
38         CMD_NONE = 0,
39         CMD_GET_ID,
40         CMD_GET_SENSOR_LIST,
41         CMD_HELLO,
42         CMD_BYEBYE,
43         CMD_DONE,
44         CMD_START,
45         CMD_STOP,
46         CMD_REG,
47         CMD_UNREG,
48         CMD_SET_OPTION,
49         CMD_SET_WAKEUP,
50         CMD_SET_BATCH,
51         CMD_UNSET_BATCH,
52         CMD_SET_COMMAND,
53         CMD_GET_DATA,
54         CMD_SEND_SENSORHUB_DATA,
55         CMD_CNT,
56 };
57
58 enum sensor_state_t {
59         SENSOR_STATE_UNKNOWN = -1,
60         SENSOR_STATE_STOPPED = 0,
61         SENSOR_STATE_STARTED = 1,
62         SENSOR_STATE_PAUSED = 2
63 };
64
65 enum poll_interval_t {
66         POLL_100HZ_MS   = 10,
67         POLL_50HZ_MS    = 20,
68         POLL_25HZ_MS    = 40,
69         POLL_20HZ_MS    = 50,
70         POLL_10HZ_MS    = 100,
71         POLL_5HZ_MS             = 200,
72         POLL_1HZ_MS             = 1000,
73         POLL_MAX_HZ_MS  = POLL_1HZ_MS,
74 };
75
76 typedef struct {
77         char name[NAME_MAX];
78 } cmd_get_id_t;
79
80 typedef struct {
81 } cmd_get_sensor_list_t;
82
83 typedef struct {
84         int client_id;
85         sensor_id_t sensor;
86 } cmd_hello_t;
87
88 typedef struct {
89 } cmd_byebye_t;
90
91
92 typedef struct {
93         unsigned int type;
94 } cmd_get_data_t;
95
96 typedef struct {
97         long value;
98 } cmd_done_t;
99
100
101 typedef struct {
102         int client_id;
103 } cmd_get_id_done_t;
104
105 typedef struct {
106         int sensor_cnt;
107         char data[0];
108 } cmd_get_sensor_list_done_t;
109
110 typedef struct {
111         int state;
112         sensor_data_t base_data;
113 } cmd_get_data_done_t;
114
115 typedef struct {
116 } cmd_start_t;
117
118 typedef struct {
119 } cmd_stop_t;
120
121 typedef struct {
122         unsigned int event_type;
123 } cmd_reg_t;
124
125 typedef struct {
126         unsigned int event_type;
127 } cmd_unreg_t;
128
129 typedef struct {
130         unsigned int interval;
131         unsigned int latency;
132 } cmd_set_batch_t;
133
134 typedef struct {
135 } cmd_unset_batch_t;
136
137 typedef struct {
138         int option;
139 } cmd_set_option_t;
140
141 typedef struct {
142         int wakeup;
143 } cmd_set_wakeup_t;
144
145 typedef struct  {
146         unsigned int cmd;
147         long value;
148 } cmd_set_command_t;
149
150 typedef struct  {
151         int data_len;
152         char data[0];
153 } cmd_send_sensorhub_data_t;
154
155 #define EVENT_CHANNEL_MAGIC 0xCAFECAFE
156
157 typedef struct {
158         unsigned int magic;
159         int client_id;
160 } event_channel_ready_t;
161
162 typedef struct sensor_event_t {
163         unsigned int event_type;
164         sensor_id_t sensor_id;
165         unsigned int data_length;
166         sensor_data_t *data;
167 } sensor_event_t;
168
169 typedef struct sensorhub_event_t {
170         unsigned int event_type;
171         sensor_id_t sensor_id;
172         unsigned int data_length;
173         sensorhub_data_t data;
174 } sensorhub_event_t;
175
176 typedef void *(*cmd_func_t)(void *data, void *cb_data);
177
178 typedef std::vector<unsigned int> event_type_vector;
179
180 enum sensor_permission_t {
181         SENSOR_PERMISSION_NONE  = 0,
182         SENSOR_PERMISSION_STANDARD = (1 << 0),
183         SENSOR_PERMISSION_BIO   =  (1 << 1),
184 };
185
186 #define BIO_SENSOR_PRIVELEGE_NAME "sensord::bio"
187 #define BIO_SENSOR_ACCESS_RIGHT "rw"
188
189 #endif /* _SF_COMMON_H_ */