Rename ble payload service_id to primary_key
[platform/core/connectivity/ua-manager.git] / ua-daemon / include / ua-manager-core.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #ifndef __UAM_MANAGER_CORE_H__
19 #define __UAM_MANAGER_CORE_H__
20
21 #include <dlog.h>
22 #include <glib.h>
23 #include <gio/gio.h>
24 #include <ua-api.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 typedef enum {
31         UAM_ADDR_TYPE_BT = 0x01, /**< Bluetooth device address */
32         UAM_ADDR_TYPE_BLE, /**< BLE device adress */
33         UAM_ADDR_TYPE_WIFI, /**< Wi-Fi Infra. device address  */
34         UAM_ADDR_TYPE_P2P, /**< Wi-Fi Direct device address */
35         UAM_ADDR_TYPE_IPv4, /**< IPv4 Address */
36         UAM_ADDR_TYPE_IPv6, /**< IPv6 Address */
37         UAM_ADDR_TYPE_MAX
38 } uam_addr_type_e;
39
40 #define UAM_DETECTION_WINDOW_DEFAULT 55 /* 55 seconds */
41 #define UAM_DETECTION_WINDOW_MAX  55 /* 55 seconds */
42 #define UAM_DETECTION_WINDOW_STEP 5 /* 5 seconds */
43
44 #define UAM_DETECTION_CYCLE_DEFAULT 900 /* 900 seconds */
45 #define UAM_DETECTION_CYCLE_MIN 60 /* 60 seconds */
46
47 typedef struct {
48         char *name;
49         unsigned int cycle; /**< Detection Cycle = Detection Period * cycle */
50         int remaining_time; /**< Time remaining up to detection_cycle (unit: sec) */
51         int presence_threshold; /**< PRESENCE threshold */
52         int absence_threshold; /**< ABSENCE threshold */
53         GSList *monitors; /**< Monitor handle list */
54         GSList *dev_techs; /**< Device list */
55 } uam_db_service_info_t;
56
57 typedef struct {
58         char *device_id; /**< Device ID */
59         uam_tech_type_e tech_type; /**< Connectivity type */
60         char *service; /**< Connected service name */
61         int discriminant; /**< Service dependent discriminant */
62         unsigned long long last_seen; /**< Service dependent last seen time */
63 } uam_svc_dev_info_t;
64
65 typedef struct {
66         uam_addr_type_e addr_type; /**< Address type (i.e., BT/BLE/Wi-Fi/IPv4/IPv6) */
67         char *address; /**< Address */
68 } uam_db_address_info_t;
69
70 typedef struct {
71         char primary_key; /** Primary key */
72         char device_icon; /** Device icon */
73         char purpose; /** Purpose */
74         char *duid; /** DUID */
75         char *bt_mac; /** BT MAC Address */
76 } uam_db_ble_payload_t;
77
78 typedef struct {
79         uam_tech_type_e tech_type; /**< Connectivity type */
80         GSList *addresses; /**< Address list */
81         int presence_state; /**< PRESENCE or ABSENCE */
82         unsigned long long last_seen; /**< Last seen time */
83         gboolean discriminant; /**< Decide whether to detect device or not */
84         struct uam_db_device_info *device; /**< Device info which stored in the DB */
85         GSList *svc_list; /**< Service list */
86         uam_db_ble_payload_t *payload; /**< Filtering info when detecting the BLE payload */
87 } uam_db_tech_info_t;
88
89 typedef struct uam_db_device_info {
90         int os; /**< OS type */
91         char *device_id; /**< Device ID */
92         GSList *tech_list; /**< Connectivity device info. list (i.e., BT/BLE/Wi-Fi/...)*/
93         unsigned int supported_techs; /**< bitmask to check how many connectivities are supported */
94         struct uam_db_user_info *user; /**< Owner infomation for these devices */
95         gboolean discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
96 } uam_db_device_info_t;
97
98 typedef struct uam_db_user_info {
99         int user_id; /**< User ID */
100         char *name; /**< User name */
101         char *account; /**< Account */
102         GSList *devices; /**< Device list */
103         unsigned long long last_seen; /**< Last seen time */
104 } uam_db_user_info_t;
105
106
107 typedef enum {
108         UAM_ACTIVE_DEVICE_FOUND = 0x01, /**< Found devices using ARPing */
109         UAM_ACTIVE_SCAN_COMPLETED = 0x02 /**< Active ARPing done */
110 } uam_active_scan_event_e;
111
112 int _uam_core_add_user(int *user_id, const char *account, const char *name);
113
114 int _uam_core_remove_user(const char *account);
115
116 int _uam_core_update_user(uam_user_info_s *user);
117
118 int _uam_core_add_device(const char *account,
119         const uam_device_info_s *dev_info);
120
121 int _uam_core_remove_device(const char *account,
122         const uam_device_info_s *dev_info);
123
124 int _uam_core_remove_device_by_device_id(const char *device_id,
125         int tech_type);
126
127 int _uam_core_remove_device_by_mac(const char *mac);
128
129 int _uam_core_get_default_user(uam_user_info_s *user_info);
130
131 int _uam_core_get_users(int *count, uam_user_info_s **user_list);
132
133 int _uam_core_get_user_by_account(const char *account, uam_user_info_s *user);
134
135 int _uam_core_get_devcie_by_device_id(
136                 const char *device_id, int tech_type, uam_device_info_s *device);
137
138 int _uam_core_get_devcie_by_mac(const char *mac, uam_device_info_s *device);
139
140 int _uam_core_get_user_by_device_id(const char *device_id,
141         uam_user_info_s *user);
142
143 int _uam_core_get_user_by_mac(const char *mac, uam_user_info_s *user);
144
145 int _uam_core_get_devices(int *count, uam_device_info_s **device_list);
146
147 int _uam_core_get_user_devices(const char *account,
148                 int *count, uam_device_info_s **device_list);
149
150 int _uam_core_is_device_added(uam_device_info_s *dev, gboolean *is_added);
151
152 int _uam_core_get_available_sensors(unsigned int *sensor_bitmask);
153
154 gboolean _uam_core_is_sensor_ready(unsigned int sensor);
155
156 int _uam_core_set_detection_threshold(unsigned int sensor,
157                 int presence_threshold, int absence_threshold);
158
159 int _uam_core_start_presence_detection(const char *svc_name, char *sender,
160         unsigned int sensors);
161
162 int _uam_core_stop_presence_detection(const char *svc_name, char *sender,
163         unsigned int sensors);
164
165 int _uam_core_start_absence_detection(const char *svc_name, char *sender,
166         unsigned int sensors);
167
168 int _uam_core_stop_absence_detection(const char *svc_name, char *sender,
169         unsigned int sensors);
170
171 int _uam_core_set_low_power_mode(unsigned int bit_mask, gboolean mode);
172
173 int _uam_core_get_detection_window(unsigned int *window);
174
175 int _uam_core_set_detection_window(unsigned int window);
176
177 int _uam_core_init(void);
178
179 void _uam_core_deinit(void);
180
181 void _uam_core_handle_sensor_ready(unsigned int sensor, gboolean is_ready);
182
183 int _uam_core_handle_device_added(int status,
184                 int user_id, const uam_device_info_s *dev_info);
185
186 int _uam_core_handle_presence_detected(unsigned int sensor,
187                 int user_id, void *sensor_info);
188
189 void _uam_core_handle_absence_detected(unsigned int sensor,
190                 int user_id, void *sensor_info);
191
192 void _uam_core_cleanup_monitor(char *name);
193
194 void _uam_core_reset_database(void);
195
196 unsigned int _uam_core_get_active_sensors(int detection_mode);
197
198 void _uam_core_handle_detection_started(unsigned int sensor);
199
200 void _uam_core_handle_detection_stopped(unsigned int sensor);
201
202 int _uam_core_start_active_device_scan(char *sender, unsigned int sensors,
203         int detection_period);
204
205 int _uam_core_stop_active_device_scan(char *sender, unsigned int sensors);
206
207 void _uam_core_handle_active_device(uam_active_scan_event_e event,
208         unsigned int sensor, const uam_device_info_s *dev_info);
209
210 int _uam_core_get_default_service(uam_service_info_s *service_info);
211
212 int _uam_core_register_service(uam_service_info_s *svc);
213
214 int _uam_core_update_service(uam_service_info_s *svc);
215
216 int _uam_core_unregister_service(const char *svc_name);
217
218 int _uam_core_get_service_devices(const char *svc_name, int *count,
219         uam_device_info_s **device_list);
220
221 int _uam_core_get_service_users(const char *svc_name, int *count,
222         uam_user_info_s **user_list);
223
224 int _uam_core_get_services(int *count, uam_service_info_s **service_list);
225
226 int _uam_core_service_add_user(const char *service_name, const char *account);
227
228 int _uam_core_service_remove_user(const char *service, const char *account);
229
230 int _uam_core_service_add_device(const char *service_name,
231         const char *device_id, int tech_type);
232
233 int _uam_core_service_remove_device(const char *service_name,
234         const char *device_id, int tech_type);
235
236 int _uam_core_service_set_device_discriminant(const char *service_name,
237         const char *device_id, int tech_type, gboolean discriminant);
238
239 int _uam_core_service_get_device_discriminant(const char *service_name,
240         const char *device_id, int tech_type, gboolean *discriminant);
241
242 int _uam_core_service_get_device_last_seen(const char *svc_name,
243         const char *device_id, int tech_type, unsigned long long *last_seen);
244
245 int _uam_core_set_service_detection_cycle(const char *svc_name,
246         unsigned int cycle);
247
248 int _uam_core_get_service_detection_cycle(const char *svc_name,
249         unsigned int *cycle);
250
251 int _uam_core_update_device(const uam_device_info_s *a_device);
252
253 int _uam_core_add_ibeacon_adv(unsigned int adv_len, const char *iadv);
254
255 void _uam_core_handle_status_changed(unsigned int sensor, void *info);
256
257 #ifdef __cplusplus
258 }
259 #endif
260 #endif /* __UAM_MANAGER_CORE_H__ */