Fix SVace issues WGID 1937, 1996, 4732, 4936
[apps/native/ug-wifi-direct.git] / ug-wifidirect / include / wfd_ug.h
1 /*
2 *  WiFi-Direct UG
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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
21 #ifndef __WFD_UG_H__
22 #define __WFD_UG_H__
23
24 #include <dlog.h>
25 #include <notification.h>
26 #include <ui-gadget-module.h>
27
28 #include <tethering.h>
29
30 #include <wifi-direct.h>
31 #include <efl-assist/efl_assist.h>
32
33 #include <glib-object.h>
34 #include <gio/gio.h>
35 #include <glib.h>
36 #include <assert.h>
37
38 #define PACKAGE "ug-setting-wifidirect-efl"
39 #define LOCALEDIR "/usr/share/locale"
40 #define COLOR_TABLE "/usr/apps/setting-wifidirect-efl/shared/res/tables/setting-wifidirect-efl_ChangeableColorTable.xml"
41 #define FONT_TABLE "/usr/apps/setting-wifidirect-efl/shared/res/tables/setting-wifidirect-efl_FontInfoTable.xml"
42
43 #define DIRECT_TAG  "wfd_ug"
44 /* TODO:: To change the log level as LOG_INFO */
45 #define DBG(log_level, format, args...) \
46         LOG(LOG_ERROR, DIRECT_TAG, "[%s()][%d] " format, __FUNCTION__, __LINE__, ##args)
47 #define DBG_SECURE(log_level, format, args...) \
48         SECURE_LOG(LOG_ERROR, DIRECT_TAG, "[%s()][%d] " format, __FUNCTION__, __LINE__, ##args)
49
50 #define MAC2SECSTR(a) (a)[0], (a)[4], (a)[5]
51 #define MACSECSTR "%02x:%02x:%02x"
52 #if 0
53 #define IP2SECSTR(a) (a)[0], (a)[3]
54 #define IPSECSTR "%d..%d"
55 #endif
56
57 #define __FUNC_ENTER__  DBG(LOG_INFO, "+\n")
58 #define __FUNC_EXIT__   DBG(LOG_INFO, "-\n")
59 #if 0
60 #define __FUNC_ENTER__
61 #define __FUNC_EXIT__
62 #endif
63
64 #define VCONF_WFD_APNAME                        "db/setting/device_name"
65
66 #define MAX_HEX_COLOR_LENGTH 255
67
68 #define assertm_if(expr, fmt, arg...) do { \
69         if (expr) { \
70           DBG(LOG_VERBOSE, " ##(%s) -> %s() assert!!## "fmt, #expr, __FUNCTION__, ##arg); \
71                  assert(1); \
72         } \
73 } while (0)
74
75 #define WFD_IF_DEL_OBJ(obj) \
76                 do { \
77                         if(obj) { \
78                                 evas_object_del(obj); \
79                                 obj = NULL; \
80                         } \
81                 } while (0)
82
83 #define WFD_IF_DEL_ITEM(obj) \
84                 do { \
85                         if(obj) { \
86                                 elm_object_item_del(obj); \
87                                 obj = NULL; \
88                         } \
89                 } while (0)
90
91 #define WFD_RET_IF(expr, fmt, args...) \
92                 do { \
93                         if(expr) { \
94                                 DBG(LOG_ERROR, "[%s] Return, message "fmt, #expr, ##args );\
95                                 return; \
96                         } \
97                 } while (0)
98
99 #define WFD_RETV_IF(expr, val, fmt, args...) \
100                 do { \
101                         if(expr) { \
102                                 DBG(LOG_ERROR,"[%s] Return value, message "fmt, #expr, ##args );\
103                                 return (val); \
104                         } \
105                 } while (0)
106
107 #define WFD_IF_FREE_MEM(mem) \
108                 do { \
109                         if(mem) { \
110                                 free(mem); \
111                                 mem = NULL; \
112                         } \
113                 } while (0)
114
115 #define AP_NAME_LENGTH_MAX              32
116 #define AP_PASSWORD_LENGTH_MAX  64
117 #define AP_PASSWORD_LENGTH_MIN  8
118 #define AP_REJECT_CHAR_LIST             "=,"
119
120 #define DEFAULT_DEV_NAME        "ZEQ"
121 #define MAC_LENGTH  18
122 #define SSID_LENGTH 32
123 #define MAX_CONNECTED_PEER_NUM 7
124 #define MAX_PEER_NUM 10
125 #define MAX_POPUP_TEXT_SIZE 256
126 #define MAX_DISPLAY_TIME_OUT 3
127 #define MAX_NO_ACTION_TIME_OUT  300            /*5min*/
128 #define MAX_SCAN_TIME_OUT 0
129
130 #define GENLIST_HEADER_POS 1
131 #define SR_CHECKBOX_ON_MSG "on/off button on"
132 #define SR_CHECKBOX_OFF_MSG "on/off button off"
133 #define SR_BUTTON_MSG "multiple connect button"
134
135 #define _(s)        dgettext(PACKAGE, s)
136 #define N_(s)      dgettext_noop(s)
137 #define S_(s)      dgettext("sys_string", s)
138
139 #define WFD_GLOBALIZATION_STR_LENGTH 256
140
141 typedef enum {
142         WFD_MULTI_CONNECT_MODE_NONE,
143         WFD_MULTI_CONNECT_MODE_IN_PROGRESS,
144         WFD_MULTI_CONNECT_MODE_COMPLETED,
145 } wfd_multi_connect_mode_e;
146
147 typedef enum {
148         PEER_CONN_STATUS_DISCONNECTED,
149         PEER_CONN_STATUS_DISCONNECTING,
150         PEER_CONN_STATUS_CONNECTING = PEER_CONN_STATUS_DISCONNECTING,
151         PEER_CONN_STATUS_CONNECTED,
152         PEER_CONN_STATUS_FAILED_TO_CONNECT,
153         PEER_CONN_STATUS_WAIT_FOR_CONNECT,
154 } conn_status_e;
155
156 typedef enum {
157         WIFI_DIRECT_DISCOVERY_NONE,
158         WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL_START,
159         WIFI_DIRECT_DISCOVERY_FULL_SCAN_START,
160         WIFI_DIRECT_DISCOVERY_STOPPED,
161         WIFI_DIRECT_DISCOVERY_BACKGROUND,
162 } discovery_status_e;
163
164
165 typedef struct device_type_s_{
166         char ssid[SSID_LENGTH];
167         unsigned int category;
168         unsigned int sub_category;
169         char mac_addr[MAC_LENGTH];
170         char if_addr[MAC_LENGTH];
171         conn_status_e conn_status;
172         bool is_group_owner;  /** Is an active P2P Group Owner */
173         bool is_persistent_group_owner;  /** Is a stored Persistent GO */
174         bool is_connected;  /** Is peer connected*/
175         bool is_alive;
176         bool dev_sel_state;
177         Elm_Object_Item *gl_item;
178         struct device_type_s_ *next;
179 } device_type_s;
180
181 struct ug_data {
182         Evas_Object *base;
183         ui_gadget_h ug;
184
185         Evas_Object *win;
186         Evas_Object *bg;
187         Evas_Object *layout;
188         Evas_Object *naviframe;
189         Elm_Object_Item *navi_item;
190         Elm_Object_Item *multi_navi_item;
191         Elm_Object_Item *head;
192         Evas_Object *genlist;
193         Evas_Object *multiconn_view_genlist;
194         Evas_Object *multiconn_layout;
195         Evas_Object *popup;
196         Evas_Object *act_popup;
197         Evas_Object *warn_popup;
198         Evas_Object *rename_popup;
199         Evas_Object *ctxpopup;
200         Evas_Object *scan_btn;
201         Evas_Object *disconnect_btn;
202         Evas_Object *toolbar;
203         Evas_Object *rename_entry;
204         Evas_Object *rename_button;
205
206 #ifdef WFD_ON_OFF_GENLIST
207         Evas_Object *on_off_check;
208 #endif
209
210         Evas_Object *scan_toolbar;
211         Evas_Object *multiconn_scan_stop_btn;
212         Evas_Object *multiconn_conn_btn;
213         Evas_Object *select_all_icon;
214
215
216
217         Elm_Object_Item *multi_connect_toolbar_item;
218         Elm_Object_Item *multi_view_connect_toolbar_item;
219
220         Elm_Object_Item *select_all_view_genlist;
221 #ifdef WFD_ON_OFF_GENLIST
222         Elm_Object_Item *item_wifi_onoff;
223 #endif
224         Elm_Object_Item *device_name_item;
225         Elm_Genlist_Item_Class *rename_entry_itc;
226         Elm_Genlist_Item_Class *rename_desc_itc;
227         Elm_Object_Item *multi_connect_sep_item;
228
229         Elm_Object_Item *nodevice_title_item;
230         Elm_Object_Item *nodevice_item;
231
232         Elm_Object_Item *conn_wfd_item;
233         Elm_Object_Item *conn_failed_wfd_item;
234         Elm_Object_Item *avlbl_wfd_item;
235         Elm_Object_Item *busy_wfd_item;
236         Elm_Object_Item *multi_connect_wfd_item;
237
238         Elm_Object_Item *mcview_title_item;
239         Elm_Object_Item *mcview_nodevice_item;
240         Elm_Object_Item *more_btn_multiconnect_item;
241
242         Evas_Object *back_btn;
243
244         // Notify
245         Evas_Object *notify;
246         Evas_Object *notify_layout;
247
248         int head_text_mode;
249
250         char *mac_addr_connecting;
251         char *mac_addr_req;
252
253         //Connection is incoming or not
254         bool is_conn_incoming;
255
256
257         // title mode of device list
258         int title_content_mode;
259
260         // Raw peer data
261         device_type_s raw_connected_peers[MAX_CONNECTED_PEER_NUM];
262         int raw_connected_peer_cnt;
263         GList *raw_discovered_peer_list;
264         int raw_discovered_peer_cnt;
265
266         // Peer data in the Genlist
267         int gl_connected_peer_cnt;
268         device_type_s *gl_conn_peers_start;
269
270         int gl_connected_failed_peer_cnt;
271         device_type_s *gl_failed_peers_start;
272
273         int gl_available_peer_cnt;
274         device_type_s *gl_avlb_peers_start;
275
276         int gl_busy_peer_cnt;
277         device_type_s *gl_busy_peers_start;
278
279         device_type_s raw_multi_selected_peers[MAX_PEER_NUM];
280         int raw_multi_selected_peer_cnt;
281
282         int gl_multi_connect_peer_cnt;
283         device_type_s *gl_mul_conn_peers_start;
284
285         // My status
286         bool I_am_group_owner;
287         bool I_am_connected;
288
289         // Following variables are used at the Multi connect view.
290         wfd_multi_connect_mode_e multi_connect_mode;
291         device_type_s *multi_conn_dev_list_start;
292         int gl_available_dev_cnt_at_multiconn_view;
293         int g_source_multi_connect_next;
294
295 #ifdef WFD_ON_OFF_GENLIST
296         int wfd_onoff;
297 #endif
298         wifi_direct_state_e wfd_status;
299         char *dev_name;
300         char *dev_pass;
301
302         // For connect failed peers
303         int last_display_time;
304         Ecore_Timer *display_timer;
305
306         // Tethering
307         bool is_hotspot_off;
308         bool is_hotspot_locally_disabled;
309         tethering_h hotspot_handle;
310
311         // wfds service
312         char *wfds;
313
314         // Device filter
315         int device_filter;
316
317         // Whether support auto exit after successed connection
318         bool is_auto_exit;
319
320         //Whether support multi connection
321         bool is_multi_connect;
322         bool is_select_all_checked;
323
324         //view type for search
325         char *view_type;
326
327         //Title of UG
328         char *title;
329
330         // The ip address of connected peer
331         char *peer_ip_address;
332
333         // The service name that supported WFDSP
334         char *service_name;
335
336         // Whether initialize wfd-namager ok
337         bool is_init_ok;
338
339         //timer for deleting progress bar
340         int timer_stop_progress_bar;
341
342         //timer for multi connect reset
343         int timer_multi_reset;
344
345         //if all the items are selected or not
346         bool is_multi_check_all_selected;
347
348         //timer for remove not alive peer
349         int timer_delete_not_alive_peer;
350
351         //wifi direct discovery status
352         int wfd_discovery_status;
353
354         bool is_paused;
355
356 #ifdef WFD_DBUS_LAUNCH
357         GCancellable *dbus_cancellable;
358         GDBusConnection *conn;
359 #endif
360 };
361
362 extern Elm_Gen_Item_Class device_name_title_itc;
363 #ifdef WFD_ON_OFF_GENLIST
364 extern Elm_Gen_Item_Class wfd_onoff_itc;
365 #endif
366 extern Elm_Gen_Item_Class device_name_itc;
367 extern Elm_Gen_Item_Class title_itc;
368 extern Elm_Gen_Item_Class multi_view_title_itc;
369 extern Elm_Gen_Item_Class peer_itc;
370 extern Elm_Gen_Item_Class title_no_device_itc;
371 extern Elm_Gen_Item_Class noitem_itc;
372 extern Elm_Gen_Item_Class title_available_itc;
373
374 extern Elm_Gen_Item_Class title_conn_itc;
375 extern Elm_Gen_Item_Class peer_conn_itc;
376
377 extern Elm_Gen_Item_Class title_busy_itc;
378 extern Elm_Gen_Item_Class peer_busy_itc;
379
380 extern Elm_Gen_Item_Class title_multi_connect_itc;
381 extern Elm_Gen_Item_Class peer_multi_connect_itc;
382 extern Elm_Gen_Item_Class select_all_multi_connect_itc;
383
384 extern Elm_Gen_Item_Class title_conn_failed_itc;
385 extern Elm_Gen_Item_Class peer_conn_failed_itc;
386
387 /**
388  *      This function let the ug destroy the ug
389  *      @return   void
390  *      @param[in] data the pointer to the main data structure
391  */
392 void wfd_destroy_ug(void *data);
393
394 /**
395  *      This function is called when ON/OFF button is turned ON/OFF
396  *      @return   void
397  *      @param[in] data the pointer to the main data structure
398  *      @param[in] object
399  *      @param[in] event
400  */
401 void _onoff_changed_cb(void *data, Evas_Object *obj, void *event_info);
402 void toolbar_language_changed(void *data, Evas_Object *obj, void *event_info);
403 void ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *event_info);
404 void wfd_free_nodivice_item(struct ug_data *ugd);
405 void discover_cb(int error_code, wifi_direct_discovery_state_e discovery_state, void *user_data);
406
407
408 #endif  /* __WFD_UG_H__ */