Add ua-manager core APIs to insert payload information
[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 secondary_key; /** Purpose */
74         char *device_uid; /** DEVICE_UID */
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_tech_info_t;
87
88 typedef struct uam_db_device_info {
89         int os; /**< OS type */
90         char *device_id; /**< Device ID */
91         GSList *tech_list; /**< Connectivity device info. list (i.e., BT/BLE/Wi-Fi/...)*/
92         unsigned int supported_techs; /**< bitmask to check how many connectivities are supported */
93         struct uam_db_user_info *user; /**< Owner infomation for these devices */
94         gboolean discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
95 } uam_db_device_info_t;
96
97 typedef struct uam_db_user_info {
98         int user_id; /**< User ID */
99         char *name; /**< User name */
100         char *account; /**< Account */
101         GSList *devices; /**< Device list */
102         unsigned long long last_seen; /**< Last seen time */
103 } uam_db_user_info_t;
104
105
106 typedef enum {
107         UAM_ACTIVE_DEVICE_FOUND = 0x01, /**< Found devices using ARPing */
108         UAM_ACTIVE_SCAN_COMPLETED = 0x02 /**< Active ARPing done */
109 } uam_active_scan_event_e;
110
111 int _uam_core_add_user(int *user_id, const char *account, const char *name);
112
113 int _uam_core_remove_user(const char *account);
114
115 int _uam_core_update_user(uam_user_info_s *user);
116
117 int _uam_core_add_device(const char *account,
118         const uam_device_info_s *dev_info);
119
120 int _uam_core_remove_device(const char *account,
121         const uam_device_info_s *dev_info);
122
123 int _uam_core_remove_device_by_device_id(const char *device_id,
124         int tech_type);
125
126 int _uam_core_remove_device_by_mac(const char *mac);
127
128 int _uam_core_get_default_user(uam_user_info_s *user_info);
129
130 int _uam_core_get_users(int *count, uam_user_info_s **user_list);
131
132 int _uam_core_get_user_by_account(const char *account, uam_user_info_s *user);
133
134 int _uam_core_get_devcie_by_device_id(
135                 const char *device_id, int tech_type, uam_device_info_s *device);
136
137 int _uam_core_get_devcie_by_mac(const char *mac, uam_device_info_s *device);
138
139 int _uam_core_get_user_by_device_id(const char *device_id,
140         uam_user_info_s *user);
141
142 int _uam_core_get_user_by_mac(const char *mac, uam_user_info_s *user);
143
144 int _uam_core_get_devices(int *count, uam_device_info_s **device_list);
145
146 int _uam_core_get_user_devices(const char *account,
147                 int *count, uam_device_info_s **device_list);
148
149 int _uam_core_is_device_added(uam_device_info_s *dev, gboolean *is_added);
150
151 int _uam_core_get_available_sensors(unsigned int *sensor_bitmask);
152
153 gboolean _uam_core_is_sensor_ready(unsigned int sensor);
154
155 int _uam_core_set_detection_threshold(unsigned int sensor,
156                 int presence_threshold, int absence_threshold);
157
158 int _uam_core_start_presence_detection(const char *svc_name, char *sender,
159         unsigned int sensors);
160
161 int _uam_core_stop_presence_detection(const char *svc_name, char *sender,
162         unsigned int sensors);
163
164 int _uam_core_start_absence_detection(const char *svc_name, char *sender,
165         unsigned int sensors);
166
167 int _uam_core_stop_absence_detection(const char *svc_name, char *sender,
168         unsigned int sensors);
169
170 int _uam_core_set_low_power_mode(unsigned int bit_mask, gboolean mode);
171
172 int _uam_core_get_detection_window(unsigned int *window);
173
174 int _uam_core_set_detection_window(unsigned int window);
175
176 int _uam_core_init(void);
177
178 void _uam_core_deinit(void);
179
180 void _uam_core_handle_sensor_ready(unsigned int sensor, gboolean is_ready);
181
182 int _uam_core_handle_device_added(int status,
183                 int user_id, const uam_device_info_s *dev_info);
184
185 int _uam_core_handle_presence_detected(unsigned int sensor,
186                 int user_id, void *sensor_info);
187
188 void _uam_core_handle_absence_detected(unsigned int sensor,
189                 int user_id, void *sensor_info);
190
191 void _uam_core_cleanup_monitor(char *name);
192
193 void _uam_core_reset_database(void);
194
195 unsigned int _uam_core_get_active_sensors(int detection_mode);
196
197 void _uam_core_handle_detection_started(unsigned int sensor);
198
199 void _uam_core_handle_detection_stopped(unsigned int sensor);
200
201 int _uam_core_start_active_device_scan(char *sender, unsigned int sensors,
202         int detection_period);
203
204 int _uam_core_stop_active_device_scan(char *sender, unsigned int sensors);
205
206 void _uam_core_handle_active_device(uam_active_scan_event_e event,
207         unsigned int sensor, const uam_device_info_s *dev_info);
208
209 int _uam_core_get_default_service(uam_service_info_s *service_info);
210
211 int _uam_core_register_service(uam_service_info_s *svc);
212
213 int _uam_core_update_service(uam_service_info_s *svc);
214
215 int _uam_core_unregister_service(const char *svc_name);
216
217 int _uam_core_get_service_devices(const char *svc_name, int *count,
218         uam_device_info_s **device_list);
219
220 int _uam_core_get_service_users(const char *svc_name, int *count,
221         uam_user_info_s **user_list);
222
223 int _uam_core_get_services(int *count, uam_service_info_s **service_list);
224
225 int _uam_core_service_add_user(const char *service_name, const char *account);
226
227 int _uam_core_service_remove_user(const char *service, const char *account);
228
229 int _uam_core_service_add_device(const char *service_name,
230         const char *device_id, int tech_type);
231
232 int _uam_core_service_remove_device(const char *service_name,
233         const char *device_id, int tech_type);
234
235 int _uam_core_service_set_device_discriminant(const char *service_name,
236         const char *device_id, int tech_type, gboolean discriminant);
237
238 int _uam_core_service_get_device_discriminant(const char *service_name,
239         const char *device_id, int tech_type, gboolean *discriminant);
240
241 int _uam_core_service_get_device_last_seen(const char *svc_name,
242         const char *device_id, int tech_type, unsigned long long *last_seen);
243
244 int _uam_core_set_service_detection_cycle(const char *svc_name,
245         unsigned int cycle);
246
247 int _uam_core_get_service_detection_cycle(const char *svc_name,
248         unsigned int *cycle);
249
250 int _uam_core_update_device(const uam_device_info_s *a_device);
251
252 int _uam_core_add_ibeacon_adv(unsigned int adv_len, const char *iadv);
253
254 void _uam_core_handle_status_changed(unsigned int sensor, void *info);
255
256 int _uam_core_add_payload(uam_ble_payload_s *payload, const char *device_id,
257         int tech_type);
258
259 #ifdef __cplusplus
260 }
261 #endif
262 #endif /* __UAM_MANAGER_CORE_H__ */