Fix bug of UG launching failure
[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 <ui-gadget-module.h>
25 #include <tethering.h>
26 #include <wifi-direct.h>
27
28 #define PACKAGE "ug-setting-wifidirect-efl"
29 #define LOCALEDIR "/usr/ug/res/locale"
30 #define VCONF_WFD_APNAME "db/setting/device_name"
31
32 #ifdef USE_DLOG
33 #include <dlog.h>
34
35 #undef LOG_TAG
36 #define LOG_TAG "UG_WIFI_DIRECT"
37
38 #define WDUG_LOGV(format, args...) LOGV(format, ##args)
39 #define WDUG_LOGD(format, args...) LOGD(format, ##args)
40 #define WDUG_LOGI(format, args...) LOGI(format, ##args)
41 #define WDUG_LOGW(format, args...) LOGW(format, ##args)
42 #define WDUG_LOGE(format, args...) LOGE(format, ##args)
43 #define WDUG_LOGF(format, args...) LOGF(format, ##args)
44
45 #define __WDUG_LOG_FUNC_ENTER__ LOGV("Enter")
46 #define __WDUG_LOG_FUNC_EXIT__ LOGV("Quit")
47
48 #define assertm_if(expr, fmt, args...) do { \
49         if (expr) { \
50           WDUG_LOGF(" ##(%s) -> assert!!## "fmt, #expr, ##args); \
51                  assert(1); \
52         } \
53 } while (0)
54
55 #else /** _DLOG_UTIL */
56
57 #define WDUG_LOGV(format, args...) \
58         printf("[V/UG_WIFI_DIRECT] %s: %s()(%4d)> "format, __FILE__, __FUNCTION__, __LINE__, ##args)
59 #define WDUG_LOGD(format, args...) \
60         printf("[D/UG_WIFI_DIRECT] %s: %s()(%4d)> "format, __FILE__, __FUNCTION__, __LINE__, ##args)
61 #define WDUG_LOGI(format, args...) \
62         printf("[I/UG_WIFI_DIRECT] %s: %s()(%4d)> "format, __FILE__, __FUNCTION__, __LINE__, ##args)
63 #define WDUG_LOGW(format, args...) \
64         printf("[W/UG_WIFI_DIRECT] %s: %s()(%4d)> "format, __FILE__, __FUNCTION__, __LINE__, ##args)
65 #define WDUG_LOGE(format, args...) \
66         printf("[E/UG_WIFI_DIRECT] %s: %s()(%4d)> "format, __FILE__, __FUNCTION__, __LINE__, ##args)
67 #define WDUG_LOGF(format, args...) \
68         printf("[F/UG_WIFI_DIRECT] %s: %s()(%4d)> "format, __FILE__, __FUNCTION__, __LINE__, ##args)
69
70 #define __WDUG_LOG_FUNC_ENTER__ \
71         printf("[V/UG_WIFI_DIRECT] %s: %s()(%4d)> Enter", __FILE__, __FUNCTION__, __LINE__)
72 #define __WDUG_LOG_FUNC_EXIT__ \
73         printf("[V/UG_WIFI_DIRECT] %s: %s()(%4d)> Exit", __FILE__, __FUNCTION__, __LINE__)
74
75 #endif /** _DLOG_UTIL */
76
77 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
78 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
79
80 #define AP_NAME_LENGTH_MAX              32
81 #define AP_PASSWORD_LENGTH_MAX  64
82 #define AP_PASSWORD_LENGTH_MIN  8
83 #define AP_REJECT_CHAR_LIST             "=,"
84
85 #define DEFAULT_DEV_NAME        "Tizen"
86 #define MAC_LENGTH  18
87 #define SSID_LENGTH 32
88 #define MAX_PEER_NUM 10
89 #define MAX_POPUP_PEER_NUM 7
90 #define MAX_POPUP_TEXT_SIZE 256
91 #define MAX_DISPLAY_TIME_OUT    30
92 #define MAX_NO_ACTION_TIME_OUT  300            /*5min*/
93 #define MAX_SCAN_TIME_OUT 30
94
95 #define _(s)        dgettext(PACKAGE, s)
96 #define N_(s)      dgettext_noop(s)
97 #define S_(s)      dgettext("sys_string", s)
98
99 #if 1
100 /* To-Do : Text should be translated. */
101 #define IDS_WFD_POP_SCAN_AGAIN "Current connection will be disconnected so that scanning can start.Continue?"
102 #define IDS_WFD_POP_WARN_BUSY_DEVICE "Unavailable device. Device is connected to another device."
103 #define IDS_WFD_POP_AUTOMATIC_TURN_OFF "There has been no activity for 5 minutes since Wi-Fi Direct was enabled. To extend battery life, Wi-Fi Direct has been disabled."
104 #define IDS_WFD_BODY_FAILED_DEVICES "Failed Devices"
105 #define IDS_WFD_TITLE_ABOUT_WIFI_DIRECT "About Wi-Fi Direct"
106 #endif
107
108
109 #define WFD_GLOBALIZATION_STR_LENGTH 256
110
111 typedef enum {
112         WFD_MULTI_CONNECT_MODE_NONE,
113         WFD_MULTI_CONNECT_MODE_IN_PROGRESS,
114         WFD_MULTI_CONNECT_MODE_COMPLETED,
115 } wfd_multi_connect_mode_e;
116
117 typedef enum {
118         PEER_CONN_STATUS_DISCONNECTED,
119         PEER_CONN_STATUS_DISCONNECTING,
120         PEER_CONN_STATUS_CONNECTING = PEER_CONN_STATUS_DISCONNECTING,
121         PEER_CONN_STATUS_CONNECTED,
122         PEER_CONN_STATUS_FAILED_TO_CONNECT,
123         PEER_CONN_STATUS_WAIT_FOR_CONNECT,
124 } conn_status_e;
125
126
127 typedef struct {
128         char ssid[SSID_LENGTH];
129         unsigned int category;
130         char mac_addr[MAC_LENGTH];
131         char if_addr[MAC_LENGTH];
132         conn_status_e conn_status;
133         bool is_group_owner;  /** Is an active P2P Group Owner */
134         bool is_persistent_group_owner;  /** Is a stored Persistent GO */
135         bool is_connected;  /** Is peer connected*/
136         Elm_Object_Item *gl_item;
137 } device_type_s;
138
139 typedef struct {
140         bool dev_sel_state;
141         device_type_s peer;
142 } wfd_multi_sel_data_s;
143
144 struct ug_data {
145         Evas_Object *base;
146         ui_gadget_h ug;
147
148         Evas_Object *win;
149         Evas_Object *bg;
150         Evas_Object *naviframe;
151         Evas_Object *genlist;
152         Evas_Object *multiconn_view_genlist;
153         Evas_Object *popup;
154         Evas_Object *act_popup;
155         Evas_Object *warn_popup;
156
157         Elm_Object_Item *head;
158         Evas_Object *scan_btn;
159         Evas_Object *multi_scan_btn;
160         Evas_Object *multi_connect_btn;
161
162         Elm_Object_Item *nodevice_title_item;
163         Elm_Object_Item *nodevice_item;
164
165         Elm_Object_Item *about_wfd_item;
166         Elm_Object_Item *about_wfd_sep_high_item;
167         Elm_Object_Item *about_wfd_sep_low_item;
168
169         Elm_Object_Item *conn_wfd_item;
170         Elm_Object_Item *conn_failed_wfd_item;
171         Elm_Object_Item *avlbl_wfd_item;
172         Elm_Object_Item *busy_wfd_item;
173         Elm_Object_Item *multi_connect_wfd_item;
174
175         Elm_Object_Item *multi_button_item;
176         Elm_Object_Item *multi_button_sep_item;
177
178         Elm_Object_Item *mcview_select_all_item;
179         Elm_Object_Item *mcview_title_item;
180         Elm_Object_Item *mcview_nodevice_item;
181
182         Evas_Object *back_btn;
183         Evas_Object *multi_btn;
184
185         // Notify
186         Evas_Object *notify;
187         Evas_Object *notify_layout;
188
189         int head_text_mode;
190
191         // Raw peer data
192         device_type_s raw_connected_peers[MAX_PEER_NUM];
193         int raw_connected_peer_cnt;
194         device_type_s raw_discovered_peers[MAX_PEER_NUM];
195         int raw_discovered_peer_cnt;
196
197         // Peer data in the Genlist
198         device_type_s gl_connected_peers[MAX_PEER_NUM];
199         int gl_connected_peer_cnt;
200
201         device_type_s gl_connected_failed_peers[MAX_PEER_NUM];
202         int gl_connected_failed_peer_cnt;
203
204         device_type_s gl_available_peers[MAX_PEER_NUM];
205         int gl_available_peer_cnt;
206
207         device_type_s gl_busy_peers[MAX_PEER_NUM];
208         int gl_busy_peer_cnt;
209
210         device_type_s raw_multi_selected_peers[MAX_PEER_NUM];
211         int raw_multi_selected_peer_cnt;
212
213         device_type_s gl_multi_connect_peers[MAX_PEER_NUM];
214         int gl_multi_connect_peer_cnt;
215
216         // My status
217         bool I_am_group_owner;
218         bool I_am_connected;
219
220         // Following variables are used at the Multi connect view.
221         wfd_multi_connect_mode_e multi_connect_mode;
222         wfd_multi_sel_data_s multi_conn_dev_list[MAX_PEER_NUM];
223         int gl_available_dev_cnt_at_multiconn_view;
224         int g_source_multi_connect_next;
225
226         int wfd_onoff;
227         wifi_direct_state_e wfd_status;
228         char *dev_name;
229         char *dev_pass;
230
231         // For connect failed peers
232         int last_display_time;
233         Ecore_Timer *display_timer;
234
235         // Tethering
236         bool is_hotspot_off;
237         tethering_h hotspot_handle;
238
239         // Used for automatic turn off
240         int last_wfd_status;
241         int last_wfd_time;
242         Ecore_Timer *monitor_timer;
243
244         // Re-discover or not
245         bool is_re_discover;
246 };
247
248 extern Elm_Gen_Item_Class head_itc;
249 extern Elm_Gen_Item_Class name_itc;
250 extern Elm_Gen_Item_Class title_itc;
251 extern Elm_Gen_Item_Class peer_itc;
252 extern Elm_Gen_Item_Class noitem_itc;
253 extern Elm_Gen_Item_Class button_itc;
254
255 extern Elm_Gen_Item_Class title_conn_itc;
256 extern Elm_Gen_Item_Class peer_conn_itc;
257
258 extern Elm_Gen_Item_Class title_busy_itc;
259 extern Elm_Gen_Item_Class peer_busy_itc;
260
261 extern Elm_Gen_Item_Class title_multi_connect_itc;
262 extern Elm_Gen_Item_Class peer_multi_connect_itc;
263
264 extern Elm_Gen_Item_Class title_conn_failed_itc;
265 extern Elm_Gen_Item_Class peer_conn_failed_itc;
266
267
268 #endif  /* __WFD_UG_H__ */