4 * Copyright 2012 Samsung Electronics Co., Ltd
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
10 * http://www.tizenopensource.org/license
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.
21 * This file implements wifi direct application main functions.
23 * @file wfd-app-main.c
24 * @author Sungsik Jang (sungsik.jang@samsung.com)
29 #include <Elementary.h>
31 #include <notification.h>
32 #include <ui-gadget-module.h>
33 #include <app_control.h>
35 #include <wifi-direct.h>
37 #include <efl_assist.h>
38 #include <linux/unistd.h>
43 #include "wfd-app-util.h"
45 wfd_appdata_t *g_wfd_ad;
48 wfd_appdata_t *wfd_get_appdata()
53 static void _win_del(void *data, Evas_Object *obj, void *event)
58 static Evas_Object *_create_win(Evas_Object *parent, const char *name)
63 /* eo = elm_win_add(parent, name, ELM_WIN_BASIC); */
64 eo = elm_win_add(NULL, name, ELM_WIN_NOTIFICATION);
66 elm_win_title_set(eo, name);
67 elm_win_borderless_set(eo, EINA_TRUE);
68 elm_win_alpha_set(eo, EINA_TRUE);
69 evas_object_smart_callback_add(eo, "delete,request", _win_del, NULL);
70 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
71 efl_util_set_notification_window_level(eo, EFL_UTIL_NOTIFICATION_LEVEL_1);
72 evas_object_resize(eo, w, h);
73 evas_object_raise(eo);
79 static bool _app_create(void *data)
81 __WFD_APP_FUNC_ENTER__;
82 wfd_appdata_t *ad = wfd_get_appdata();
86 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
90 bindtextdomain(LOCALE_FILE_NAME, LOCALEDIR);
92 ad->popup_data = (wfd_popup_t *) malloc(sizeof(wfd_popup_t));
93 if (!ad->popup_data) {
94 WFD_APP_LOG(WFD_APP_LOG_ERROR, "malloc failed\n");
98 memset(ad->popup_data, 0x0, sizeof(wfd_popup_t));
99 ad->win = _create_win(NULL, PACKAGE);
101 if (elm_win_wm_rotation_supported_get(ad->win)) {
102 int rots[4] = { 0, 90, 180, 270 };
103 elm_win_wm_rotation_available_rotations_set(ad->win, rots, 1);
106 ad->conformant = elm_conformant_add(ad->win);
107 assertm_if(NULL == ad->conformant, "conformant is NULL!!");
108 elm_win_conformant_set(ad->win, EINA_TRUE);
109 elm_win_resize_object_add(ad->win, ad->conformant);
110 evas_object_size_hint_weight_set(ad->conformant, EVAS_HINT_EXPAND, 0.0);
111 evas_object_size_hint_align_set(ad->conformant, EVAS_HINT_FILL, 0.0);
112 evas_object_show(ad->conformant);
115 ad->back_grnd = elm_bg_add(ad->conformant);
116 if (NULL == ad->back_grnd) {
117 WFD_APP_LOG(WFD_APP_LOG_LOW, "Create background failed\n");
120 elm_object_signal_emit(ad->conformant, "elm,state,indicator,nooverlap", "elm");
121 elm_object_style_set(ad->back_grnd, "indicator/headerbg");
122 elm_object_part_content_set(ad->conformant, "elm.swallow.indicator_bg", ad->back_grnd);
123 evas_object_size_hint_weight_set(ad->back_grnd,
124 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
125 evas_object_show(ad->back_grnd);
127 ad->layout = elm_layout_add(ad->conformant);
128 elm_object_content_set(ad->conformant, ad->layout);
130 if (!ecore_x_display_get()) {
134 ret = init_wfd_client(ad);
136 WFD_APP_LOG(WFD_APP_LOG_ERROR, "init_wfd_popup_client error\n");
137 wfd_prepare_popup(WFD_POP_FAIL_INIT, NULL);
138 __WFD_APP_FUNC_EXIT__;
142 ret = wfd_app_util_register_vconf_callbacks(ad);
144 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf notification");
148 /* Enable Changeable UI feature */
149 ea_theme_changeable_ui_enabled_set(EINA_TRUE);
151 /* Register Hard Key Press CB */
152 wfd_app_util_register_hard_key_down_cb(ad);
154 /* Initializes feedback API */
155 ret = feedback_initialize();
156 if (ret != FEEDBACK_ERROR_NONE) {
157 WFD_APP_LOG(WFD_APP_LOG_ERROR, "feedback_initialize error : %d\n", ret);
160 __WFD_APP_FUNC_EXIT__;
164 static void _app_terminate(void *data)
166 __WFD_APP_FUNC_ENTER__;
167 wfd_appdata_t *ad = (wfd_appdata_t *) data;
171 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
175 wfd_app_util_del_notification(ad);
177 ret = wfd_app_util_deregister_vconf_callbacks(ad);
179 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf notification");
182 /* Deregister Hardkey CB */
183 wfd_app_util_deregister_hard_key_down_cb(ad);
185 /* Deinitializes feedback API */
186 ret = feedback_deinitialize();
187 if (ret != FEEDBACK_ERROR_NONE) {
188 WFD_APP_LOG(WFD_APP_LOG_ERROR, "feedback_deinitialize error : %d\n", ret);
190 if (ad->transmit_timer) {
191 ecore_timer_del(ad->transmit_timer);
192 ad->transmit_timer = NULL;
197 ret = deinit_wfd_client(ad);
199 WFD_APP_LOG(WFD_APP_LOG_ERROR, "deinit_wfd_client error\n");
203 evas_object_del(ad->back_grnd);
204 ad->back_grnd = NULL;
208 evas_object_del(ad->win);
212 if (ad->popup_data) {
213 free(ad->popup_data);
214 ad->popup_data = NULL;
217 __WFD_APP_FUNC_EXIT__;
221 static void _app_pause(void *data)
223 __WFD_APP_FUNC_ENTER__;
224 __WFD_APP_FUNC_EXIT__;
228 static void _app_resume(void *data)
230 __WFD_APP_FUNC_ENTER__;
231 __WFD_APP_FUNC_EXIT__;
235 static void _app_reset(app_control_h control, void *data)
237 __WFD_APP_FUNC_ENTER__;
240 wfd_appdata_t *ad = (wfd_appdata_t *) data;
242 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
245 if (control == NULL) {
246 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Service is NULL");
251 char *noti_type = NULL;
252 app_control_get_extra_data(control, NOTIFICATION_BUNDLE_PARAM, ¬i_type);
254 if (noti_type == NULL) {
255 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Notification type is wrong.");
259 WFD_APP_LOG(WFD_APP_LOG_LOW, "Notification type is [%s]", noti_type);
260 if (strncmp(noti_type, NOTIFICATION_BUNDLE_VALUE, strlen(NOTIFICATION_BUNDLE_PARAM)) == 0) {
261 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launch wifidirect-ug");
262 wifi_direct_get_state(&ad->wfd_status);
263 WFD_APP_LOG(WFD_APP_LOG_LOW, "State: %d", ad->wfd_status);
264 if (ad->wfd_status == WIFI_DIRECT_STATE_CONNECTED) {
265 WFD_APP_LOG(WFD_APP_LOG_LOW, "Connected");
266 if (ad->transmit_timer) {
267 ecore_timer_del(ad->transmit_timer);
268 ad->transmit_timer = NULL;
270 WFD_APP_LOG(WFD_APP_LOG_LOW, "start the transmit timer again\n");
271 ad->last_wfd_transmit_time = time(NULL);
272 ad->transmit_timer = ecore_timer_add(5.0,
273 (Ecore_Task_Cb)wfd_automatic_deactivated_for_connection_cb, ad);
275 app_control_h ug_control;
276 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launching Settings EFL from notification\n");
277 app_control_create(&ug_control);
278 app_control_set_operation(ug_control, APP_CONTROL_OPERATION_DEFAULT);
279 app_control_set_window(ug_control, elm_win_xwindow_get(ug_get_window()));
280 app_control_set_app_id(ug_control, "setting-wifidirect-efl");
282 ret = app_control_send_launch_request(ug_control, NULL, NULL);
283 if(ret == APP_CONTROL_ERROR_NONE) {
284 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launch Wi-Fi Direct successful");
286 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to launch Wi-Fi Direct");
288 app_control_destroy(ug_control);
291 WFD_IF_FREE_MEM(noti_type);
292 __WFD_APP_FUNC_EXIT__;
296 int main(int argc, char *argv[])
299 ui_app_lifecycle_callback_s event_callback;
300 memset(&event_callback, 0x0, sizeof(ui_app_lifecycle_callback_s));
302 event_callback.create = _app_create;
303 event_callback.terminate = _app_terminate;
304 event_callback.pause = _app_pause;
305 event_callback.resume = _app_resume;
306 event_callback.app_control = _app_reset;
308 memset(&ad, 0x0, sizeof(wfd_appdata_t));
311 return ui_app_main(argc, argv, &event_callback, &ad);