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>
33 #include <notification.h>
34 #include <ui-gadget-module.h>
35 #include <app_control_internal.h>
37 #include <wifi-direct.h>
39 #include <efl_assist.h>
40 #include <linux/unistd.h>
47 #include "wfd-app-util.h"
49 wfd_appdata_t *g_wfd_ad;
52 wfd_appdata_t *wfd_get_appdata()
57 static void _win_del(void *data, Evas_Object *obj, void *event)
62 static Evas_Object *_create_win(Evas_Object *parent, const char *name)
67 /* eo = elm_win_add(parent, name, ELM_WIN_BASIC); */
68 eo = elm_win_add(NULL, name, ELM_WIN_NOTIFICATION);
70 elm_win_title_set(eo, name);
71 elm_win_borderless_set(eo, EINA_TRUE);
72 elm_win_alpha_set(eo, EINA_TRUE);
73 evas_object_smart_callback_add(eo, "delete,request", _win_del, NULL);
75 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
77 efl_util_set_notification_window_level(eo, EFL_UTIL_NOTIFICATION_LEVEL_1);
78 evas_object_resize(eo, w, h);
79 evas_object_raise(eo);
85 static bool _app_create(void *data)
87 __WFD_APP_FUNC_ENTER__;
88 wfd_appdata_t *ad = wfd_get_appdata();
92 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
96 bindtextdomain(LOCALE_FILE_NAME, LOCALEDIR);
98 ad->popup_data = (wfd_popup_t *) malloc(sizeof(wfd_popup_t));
99 if (!ad->popup_data) {
100 WFD_APP_LOG(WFD_APP_LOG_ERROR, "malloc failed\n");
104 memset(ad->popup_data, 0x0, sizeof(wfd_popup_t));
105 ad->win = _create_win(NULL, PACKAGE);
107 if (elm_win_wm_rotation_supported_get(ad->win)) {
108 int rots[4] = { 0, 90, 180, 270 };
109 elm_win_wm_rotation_available_rotations_set(ad->win, rots, 1);
112 ad->conformant = elm_conformant_add(ad->win);
113 assertm_if(NULL == ad->conformant, "conformant is NULL!!");
114 elm_win_conformant_set(ad->win, EINA_TRUE);
115 elm_win_resize_object_add(ad->win, ad->conformant);
116 evas_object_size_hint_weight_set(ad->conformant, EVAS_HINT_EXPAND, 0.0);
117 evas_object_size_hint_align_set(ad->conformant, EVAS_HINT_FILL, 0.0);
118 evas_object_show(ad->conformant);
121 ad->back_grnd = elm_bg_add(ad->conformant);
122 if (NULL == ad->back_grnd) {
123 WFD_APP_LOG(WFD_APP_LOG_LOW, "Create background failed\n");
126 elm_object_signal_emit(ad->conformant, "elm,state,indicator,nooverlap", "elm");
127 elm_object_style_set(ad->back_grnd, "indicator/headerbg");
128 elm_object_part_content_set(ad->conformant, "elm.swallow.indicator_bg", ad->back_grnd);
129 evas_object_size_hint_weight_set(ad->back_grnd,
130 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
131 evas_object_show(ad->back_grnd);
133 ad->layout = elm_layout_add(ad->conformant);
134 elm_object_content_set(ad->conformant, ad->layout);
137 if (!ecore_x_display_get()) {
142 ret = init_wfd_client(ad);
144 WFD_APP_LOG(WFD_APP_LOG_ERROR, "init_wfd_popup_client error\n");
145 wfd_prepare_popup(WFD_POP_FAIL_INIT, NULL);
146 __WFD_APP_FUNC_EXIT__;
150 ret = wfd_app_util_register_vconf_callbacks(ad);
152 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf notification");
156 /* Register Hard Key Press CB */
157 wfd_app_util_register_hard_key_down_cb(ad);
159 /* Initializes feedback API */
160 ret = feedback_initialize();
161 if (ret != FEEDBACK_ERROR_NONE) {
162 WFD_APP_LOG(WFD_APP_LOG_ERROR, "feedback_initialize error : %d\n", ret);
165 __WFD_APP_FUNC_EXIT__;
169 static void _app_terminate(void *data)
171 __WFD_APP_FUNC_ENTER__;
172 wfd_appdata_t *ad = (wfd_appdata_t *) data;
176 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
180 wfd_app_util_del_notification(ad);
182 ret = wfd_app_util_deregister_vconf_callbacks(ad);
184 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf notification");
187 /* Deregister Hardkey CB */
188 wfd_app_util_deregister_hard_key_down_cb(ad);
190 /* Deinitializes feedback API */
191 ret = feedback_deinitialize();
192 if (ret != FEEDBACK_ERROR_NONE) {
193 WFD_APP_LOG(WFD_APP_LOG_ERROR, "feedback_deinitialize error : %d\n", ret);
195 if (ad->transmit_timer) {
196 ecore_timer_del(ad->transmit_timer);
197 ad->transmit_timer = NULL;
202 ret = deinit_wfd_client(ad);
204 WFD_APP_LOG(WFD_APP_LOG_ERROR, "deinit_wfd_client error\n");
208 evas_object_del(ad->back_grnd);
209 ad->back_grnd = NULL;
213 evas_object_del(ad->win);
217 if (ad->popup_data) {
218 free(ad->popup_data);
219 ad->popup_data = NULL;
222 __WFD_APP_FUNC_EXIT__;
226 static void _app_pause(void *data)
228 __WFD_APP_FUNC_ENTER__;
229 __WFD_APP_FUNC_EXIT__;
233 static void _app_resume(void *data)
235 __WFD_APP_FUNC_ENTER__;
236 __WFD_APP_FUNC_EXIT__;
240 static void _app_reset(app_control_h control, void *data)
242 __WFD_APP_FUNC_ENTER__;
245 wfd_appdata_t *ad = (wfd_appdata_t *) data;
247 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
250 if (control == NULL) {
251 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Service is NULL");
256 char *noti_type = NULL;
257 app_control_get_extra_data(control, NOTIFICATION_BUNDLE_PARAM, ¬i_type);
259 if (noti_type == NULL) {
260 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Notification type is wrong.");
264 WFD_APP_LOG(WFD_APP_LOG_LOW, "Notification type is [%s]", noti_type);
265 if (strncmp(noti_type, NOTIFICATION_BUNDLE_VALUE, strlen(NOTIFICATION_BUNDLE_PARAM)) == 0) {
266 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launch wifidirect-ug");
267 wifi_direct_get_state(&ad->wfd_status);
268 WFD_APP_LOG(WFD_APP_LOG_LOW, "State: %d", ad->wfd_status);
269 if (ad->wfd_status == WIFI_DIRECT_STATE_CONNECTED) {
270 WFD_APP_LOG(WFD_APP_LOG_LOW, "Connected");
271 if (ad->transmit_timer) {
272 ecore_timer_del(ad->transmit_timer);
273 ad->transmit_timer = NULL;
275 WFD_APP_LOG(WFD_APP_LOG_LOW, "start the transmit timer again\n");
276 ad->last_wfd_transmit_time = time(NULL);
277 ad->transmit_timer = ecore_timer_add(5.0,
278 (Ecore_Task_Cb)wfd_automatic_deactivated_for_connection_cb, ad);
280 app_control_h ug_control;
281 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launching Settings EFL from notification\n");
282 app_control_create(&ug_control);
283 app_control_set_operation(ug_control, APP_CONTROL_OPERATION_DEFAULT);
284 app_control_set_window(ug_control, elm_win_xwindow_get(ug_get_window()));
285 app_control_set_app_id(ug_control, "setting-wifidirect-efl");
287 ret = app_control_send_launch_request(ug_control, NULL, NULL);
288 if(ret == APP_CONTROL_ERROR_NONE) {
289 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launch Wi-Fi Direct successful");
291 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to launch Wi-Fi Direct");
293 app_control_destroy(ug_control);
296 WFD_IF_FREE_MEM(noti_type);
297 __WFD_APP_FUNC_EXIT__;
301 int main(int argc, char *argv[])
304 ui_app_lifecycle_callback_s event_callback;
305 memset(&event_callback, 0x0, sizeof(ui_app_lifecycle_callback_s));
307 event_callback.create = _app_create;
308 event_callback.terminate = _app_terminate;
309 event_callback.pause = _app_pause;
310 event_callback.resume = _app_resume;
311 event_callback.app_control = _app_reset;
313 memset(&ad, 0x0, sizeof(wfd_appdata_t));
316 return ui_app_main(argc, argv, &event_callback, &ad);