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>
30 #include <notification.h>
31 #include <ui-gadget-module.h>
32 #include <app_control_internal.h>
34 #include <wifi-direct.h>
36 #include <linux/unistd.h>
40 #include "wfd-app-util.h"
42 wfd_appdata_t *g_wfd_ad;
45 wfd_appdata_t *wfd_get_appdata()
50 static void _win_del(void *data, Evas_Object *obj, void *event)
55 static Evas_Object *_create_win(Evas_Object *parent, const char *name)
59 /* eo = elm_win_add(parent, name, ELM_WIN_BASIC); */
60 eo = elm_win_add(NULL, name, ELM_WIN_NOTIFICATION);
62 elm_win_title_set(eo, name);
63 elm_win_borderless_set(eo, EINA_TRUE);
64 elm_win_alpha_set(eo, EINA_TRUE);
65 evas_object_smart_callback_add(eo, "delete,request", _win_del, NULL);
66 efl_util_set_notification_window_level(eo, EFL_UTIL_NOTIFICATION_LEVEL_1);
67 evas_object_raise(eo);
73 static bool _app_create(void *data)
75 __WFD_APP_FUNC_ENTER__;
76 wfd_appdata_t *ad = wfd_get_appdata();
80 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
84 bindtextdomain(LOCALE_FILE_NAME, LOCALEDIR);
86 ad->popup_data = (wfd_popup_t *) malloc(sizeof(wfd_popup_t));
87 if (!ad->popup_data) {
88 WFD_APP_LOG(WFD_APP_LOG_ERROR, "malloc failed\n");
92 memset(ad->popup_data, 0x0, sizeof(wfd_popup_t));
93 ad->win = _create_win(NULL, PACKAGE);
96 if (elm_win_wm_rotation_supported_get(ad->win)) {
97 int rots[4] = {0, 90, 180, 270};
98 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
101 ad->conformant = elm_conformant_add(ad->win);
102 assertm_if(NULL == ad->conformant, "conformant is NULL!!");
103 elm_win_conformant_set(ad->win, EINA_TRUE);
104 elm_win_resize_object_add(ad->win, ad->conformant);
105 evas_object_size_hint_weight_set(ad->conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
106 evas_object_size_hint_align_set(ad->conformant, EVAS_HINT_FILL, 0.0);
107 evas_object_show(ad->conformant);
110 ad->back_grnd = elm_bg_add(ad->conformant);
111 if (NULL == ad->back_grnd) {
112 WFD_APP_LOG(WFD_APP_LOG_LOW, "Create background failed\n");
115 elm_object_signal_emit(ad->conformant, "elm,state,indicator,nooverlap", "elm");
116 elm_object_style_set(ad->back_grnd, "indicator/headerbg");
117 elm_object_part_content_set(ad->conformant, "elm.swallow.indicator_bg", ad->back_grnd);
118 evas_object_size_hint_weight_set(ad->back_grnd,
119 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
120 evas_object_show(ad->back_grnd);
122 ad->layout = elm_layout_add(ad->conformant);
123 elm_object_content_set(ad->conformant, ad->layout);
125 ret = init_wfd_client(ad);
127 WFD_APP_LOG(WFD_APP_LOG_ERROR, "init_wfd_popup_client error\n");
128 wfd_prepare_popup(WFD_POP_FAIL_INIT, NULL);
129 __WFD_APP_FUNC_EXIT__;
133 ret = wfd_app_util_register_vconf_callbacks(ad);
135 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf notification");
139 /* Register Hard Key Press CB */
140 wfd_app_util_register_hard_key_down_cb(ad);
142 /* Initializes feedback API */
143 ret = feedback_initialize();
144 if (ret != FEEDBACK_ERROR_NONE) {
145 WFD_APP_LOG(WFD_APP_LOG_ERROR, "feedback_initialize error : %d\n", ret);
148 __WFD_APP_FUNC_EXIT__;
152 static void _app_terminate(void *data)
154 __WFD_APP_FUNC_ENTER__;
155 wfd_appdata_t *ad = (wfd_appdata_t *) data;
159 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
163 wfd_app_util_del_notification(ad);
165 ret = wfd_app_util_deregister_vconf_callbacks(ad);
167 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf notification");
169 /* Deregister Hardkey CB */
170 wfd_app_util_deregister_hard_key_down_cb(ad);
172 /* Deinitializes feedback API */
173 ret = feedback_deinitialize();
174 if (ret != FEEDBACK_ERROR_NONE)
175 WFD_APP_LOG(WFD_APP_LOG_ERROR, "feedback_deinitialize error : %d\n", ret);
177 if (ad->transmit_timer) {
178 ecore_timer_del(ad->transmit_timer);
179 ad->transmit_timer = NULL;
184 ret = deinit_wfd_client(ad);
186 WFD_APP_LOG(WFD_APP_LOG_ERROR, "deinit_wfd_client error\n");
189 evas_object_del(ad->back_grnd);
190 ad->back_grnd = NULL;
194 evas_object_del(ad->win);
198 if (ad->popup_data) {
199 free(ad->popup_data);
200 ad->popup_data = NULL;
203 __WFD_APP_FUNC_EXIT__;
207 static void _app_pause(void *data)
209 __WFD_APP_FUNC_ENTER__;
210 __WFD_APP_FUNC_EXIT__;
214 static void _app_resume(void *data)
216 __WFD_APP_FUNC_ENTER__;
217 __WFD_APP_FUNC_EXIT__;
221 static void _app_reset(app_control_h control, void *data)
223 __WFD_APP_FUNC_ENTER__;
226 wfd_appdata_t *ad = (wfd_appdata_t *) data;
228 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
231 if (control == NULL) {
232 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Service is NULL");
237 char *noti_type = NULL;
238 app_control_get_extra_data(control, NOTIFICATION_BUNDLE_PARAM, ¬i_type);
240 if (noti_type == NULL) {
241 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Notification type is wrong.");
245 WFD_APP_LOG(WFD_APP_LOG_LOW, "Notification type is [%s]", noti_type);
246 if (strncmp(noti_type, NOTIFICATION_BUNDLE_VALUE, strlen(NOTIFICATION_BUNDLE_PARAM)) == 0) {
247 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launch wifidirect-ug");
248 wifi_direct_get_state(&ad->wfd_status);
249 WFD_APP_LOG(WFD_APP_LOG_LOW, "State: %d", ad->wfd_status);
250 if (ad->wfd_status == WIFI_DIRECT_STATE_CONNECTED) {
251 WFD_APP_LOG(WFD_APP_LOG_LOW, "Connected");
252 if (ad->transmit_timer) {
253 ecore_timer_del(ad->transmit_timer);
254 ad->transmit_timer = NULL;
256 WFD_APP_LOG(WFD_APP_LOG_LOW, "start the transmit timer again\n");
257 ad->last_wfd_transmit_time = time(NULL);
258 ad->transmit_timer = ecore_timer_add(5.0,
259 (Ecore_Task_Cb)wfd_automatic_deactivated_for_connection_cb, ad);
261 app_control_h ug_control;
262 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launching Settings EFL from notification\n");
263 app_control_create(&ug_control);
264 app_control_set_operation(ug_control, APP_CONTROL_OPERATION_DEFAULT);
265 app_control_set_launch_mode(ug_control, APP_CONTROL_LAUNCH_MODE_GROUP);
266 app_control_set_app_id(ug_control, "setting-wifidirect-efl");
268 ret = app_control_send_launch_request(ug_control, NULL, NULL);
269 if (ret == APP_CONTROL_ERROR_NONE)
270 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launch Wi-Fi Direct successful");
272 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to launch Wi-Fi Direct");
274 app_control_destroy(ug_control);
277 WFD_IF_FREE_MEM(noti_type);
278 __WFD_APP_FUNC_EXIT__;
282 int main(int argc, char *argv[])
285 ui_app_lifecycle_callback_s event_callback;
286 memset(&event_callback, 0x0, sizeof(ui_app_lifecycle_callback_s));
288 event_callback.create = _app_create;
289 event_callback.terminate = _app_terminate;
290 event_callback.pause = _app_pause;
291 event_callback.resume = _app_resume;
292 event_callback.app_control = _app_reset;
294 memset(&ad, 0x0, sizeof(wfd_appdata_t));
297 return ui_app_main(argc, argv, &event_callback, &ad);