summaryrefslogtreecommitdiff
path: root/include/user-awareness-private.h
blob: 61ebee946d67847ed62bf2067084f911ca991d4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef __TIZEN_CAPI_NETWORK_USER_AWARENESS_PRIVATE_H__
#define __TIZEN_CAPI_NETWORK_USER_AWARENESS_PRIVATE_H__

#include <user-awareness-log.h>
#include <glib.h>

#ifdef __cplusplus
extern "C" {
#endif

#define ret_if(expr) \
	do { \
		if (expr) { \
			UA_DBG("(%s) return", #expr); \
			return; \
		} \
	} while (0)

#define retv_if(expr, val) \
	do { \
		if (expr) { \
			UA_DBG("(%s) return", #expr); \
			return (val); \
		} \
	} while (0)

#define UA_VALIDATE_INPUT_PARAMETER(arg) \
	if (arg == NULL) { \
		UA_ERR("INVALID_PARAMETER(%s is NULL)", #arg); \
		return UA_ERROR_INVALID_PARAMETER; \
	}

#define UA_PRINT_DEVICE_HANDLE(arg) \
		UA_INFO("Device Handle [%p]", #arg); \

#define UA_VALIDATE_HANDLE(h1, list) \
	{ \
		GSList *l; \
		bool valid = FALSE; \
		for (l = list; l; l = g_slist_next(l)) { \
			void *h2 = (void *)l->data; \
			if (h1 == h2) { \
				UA_INFO("Handle matched [%p]", h2); \
				valid = TRUE; break; \
			} \
		} \
		if (valid == FALSE) { \
			UA_ERR("Handle [%p] did not match with any stored handles!!", h1); \
			return UA_ERROR_INVALID_PARAMETER; \
		} \
	} \

#define UA_EXIST_HANDLE(h1, list) \
	{ \
		GSList *l; \
		bool valid = FALSE; \
		for (l = list; l; l = g_slist_next(l)) { \
			void *h2 = (void *)l->data; \
			if (h1 == h2) { \
				UA_INFO("Handle matched [%p]", h2); \
				valid = TRUE; break; \
			} \
		} \
		if (valid == TRUE) { \
			UA_ERR("Handle [%p] match with any stored handles!!", h1); \
			return UA_ERROR_ALREADY_DONE; \
		} \
	} \

#define UA_ALL_SENSOR_PRESENCE_DETECTION_WAIT_TIME 65

/////
#define UA_MAX_DETECTION_WINDOW		290  /* 290 seconds */
#define UA_MIN_DETECTION_CYCLE		300  /* 5 min */
#define UA_SERVICE_DEFAULT "ua.service.default"

	typedef struct {
		const void *callback; /**< Callback function pointer */
		void *user_data; /**< User data */
	} ua_callback_t;

	typedef struct {
		unsigned int sensor_bitmask; /**< Bit-mask for sensors which be supported */
		unsigned int presence_detected_bitmask; /**< Detetected presence bitmask */
		unsigned int absence_detected_bitmask; /**< Detected Absence bitmask */
		ua_detection_mode_e presence_mode; /**< Presence mode */
		ua_detection_mode_e absence_mode; /**< Absence mode */
		gboolean presence_detection_started; /**< Is presence detection started */
		gboolean absence_detection_started; /**< Is absence detection started */
		gboolean scan_device_started; /**< Is scan device started */
		unsigned int presence_detection_timer; /**< Presence detection timer */
		unsigned int absence_detection_timer; /**< Absence detection timer */
		ua_callback_t sensor_state_cb; /**< Callback to let apps know sensors added or not */
		ua_callback_t absence_user_cb; /**< Callback to let apps know user is absence */
		ua_callback_t presence_user_cb; /**< Callback to let apps know user is presence */
		ua_scan_completed_cb scan_device_cb; /**< Callback to let apps know scanned registered devices */
		ua_presence_detected_cb presence_cb; /**< User presence detection callback */
		ua_absence_detected_cb absence_cb; /**< Absence detection callback */
		char *service; /**< Service name */
		GSList *user_state; /**< User current state i.e presence or absence */
		void *user_data; /**< User data */
	} ua_monitor_s;

	typedef struct {
		char *account;
		unsigned int sensor_bitmask;
	} ua_user_state_info;

	typedef struct {
		ua_monitor_s *monitor; /**< Monitor handle */
		ua_sensor_e type; /**< Bitmask to express the supported sensors */
		unsigned short absence_period; /**< Absence period */
		unsigned int absence_timer; /**< Absence timer */
		unsigned int detection_timer; /**< Detection timer */
	} ua_sensors_s;

	typedef struct {
		ua_user_h user_handle; /**< User handle */
		ua_presence_state_e state; /**< Presence state */
		unsigned int sensor_bitmask; /**< Detected user devices bitmask */
		char *account; /**< Account */
		char *name; /**< User name */
		gboolean isadded; /**< Is the user addition completed? */
		gboolean default_user; /**< Is it a default user? */
		gboolean create_by_app; /**< Did app add this user information? */
	} ua_user_info_s;

	typedef enum {
		UA_PRESENCE_DETECTION = 0x00, /**< Presence detcection */
		UA_ABSENCE_DETECTION /**< Absence detection */
	} ua_detection_type_e;

	typedef struct {
		ua_user_h user; /**< User handle */
		ua_device_h handle; /**< Device handle */
		char *mac; /**< MAC address */
		char *bssid; /**< BSSID */
		char *ipv4; /**< IPv4 address */
		char *ipv6; /**< IPv6 address */
		char *mobile_id; /**< Mobile id (e.g. BT MAC or UUID) */
		ua_mac_type_e type; /**< Connectivity technology type using this MAC address */
		bool pairing_required; /**< Does it need pairing? */
		ua_presence_state_e state; /**< Presence state */
		ua_os_type_e os; /**< OS type */
		gboolean isadded; /**< Is the device addition completed? */
		gboolean create_by_app; /**< Did app add this device information? */
	} ua_dev_info_s;

	void _ua_monitor_handle_scanned_device(int result, uam_device_info_t *uam_info);

	void _ua_monitor_handle_scan_complete(int result);

	void _ua_monitor_handle_user_presence_detected(
			unsigned int bitmask, char *service, char *account);

	void _ua_monitor_handle_detection_stopped();

	void _ua_monitor_handle_sensor_state(unsigned int bitmask, gboolean ready);

	void _ua_monitor_handle_user_absence_detected(
			unsigned int bitmask, char *service, char *account);

	void _ua_free_ua_user_info_t(ua_user_info_s *user);

	void _ua_free_ua_device_info_t(gpointer data);

	ua_dev_info_s* __ua_get_device_info_from_uam(uam_device_info_t *uam_info);

	int _ua_mark_user_info_state_db(char *account, int state, unsigned sensor_bitmask);

	bool _ua_check_all_users_absence_any(unsigned int bitmask);

	int _ua_user_add_info_to_list(ua_user_info_s* ua_info);

	int _ua_user_add_info_to_list_from_uapi_data(uam_user_info_t *uam_info);

	int _ua_remove_user_info_from_list(char *account);

	void _ua_handle_device_added(int result, uam_device_info_t *uam_info);

	void _ua_handle_device_removed(int result, uam_device_info_t *uam_info);

	typedef bool (*_ua_intr_registered_user_cb)(ua_user_h user_handle, void *user_data);

	int _ua_intr_foreach_registered_users(
			_ua_intr_registered_user_cb foreach_cb,
			void *user_data);

	int _ua_foreach_registered_users(
			ua_registered_user_cb foreach_cb,
			void *user_data);

	int _ua_intr_get_default_user(void);

	ua_user_h _ua_get_user_handle_by_account(char *account);

	int _ua_is_device_exist(char *mobile_id, char *mac, ua_mac_type_e type, gboolean *is_exist);

	GSList *_ua_user_get_users(void);

#ifdef __cplusplus
}
#endif
#endif /* __TIZEN_CAPI_NETWORK_USER_AWARENESS_PRIVATE_H__ */