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");
170 /* Deregister Hardkey CB */
171 wfd_app_util_deregister_hard_key_down_cb(ad);
173 /* Deinitializes feedback API */
174 ret = feedback_deinitialize();
175 if (ret != FEEDBACK_ERROR_NONE) {
176 WFD_APP_LOG(WFD_APP_LOG_ERROR, "feedback_deinitialize error : %d\n", ret);
178 if (ad->transmit_timer) {
179 ecore_timer_del(ad->transmit_timer);
180 ad->transmit_timer = NULL;
185 ret = deinit_wfd_client(ad);
187 WFD_APP_LOG(WFD_APP_LOG_ERROR, "deinit_wfd_client error\n");
191 evas_object_del(ad->back_grnd);
192 ad->back_grnd = NULL;
196 evas_object_del(ad->win);
200 if (ad->popup_data) {
201 free(ad->popup_data);
202 ad->popup_data = NULL;
205 __WFD_APP_FUNC_EXIT__;
209 static void _app_pause(void *data)
211 __WFD_APP_FUNC_ENTER__;
212 __WFD_APP_FUNC_EXIT__;
216 static void _app_resume(void *data)
218 __WFD_APP_FUNC_ENTER__;
219 __WFD_APP_FUNC_EXIT__;
223 static void _app_reset(app_control_h control, void *data)
225 __WFD_APP_FUNC_ENTER__;
228 wfd_appdata_t *ad = (wfd_appdata_t *) data;
230 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
233 if (control == NULL) {
234 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Service is NULL");
239 char *noti_type = NULL;
240 app_control_get_extra_data(control, NOTIFICATION_BUNDLE_PARAM, ¬i_type);
242 if (noti_type == NULL) {
243 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Notification type is wrong.");
247 WFD_APP_LOG(WFD_APP_LOG_LOW, "Notification type is [%s]", noti_type);
248 if (strncmp(noti_type, NOTIFICATION_BUNDLE_VALUE, strlen(NOTIFICATION_BUNDLE_PARAM)) == 0) {
249 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launch wifidirect-ug");
250 wifi_direct_get_state(&ad->wfd_status);
251 WFD_APP_LOG(WFD_APP_LOG_LOW, "State: %d", ad->wfd_status);
252 if (ad->wfd_status == WIFI_DIRECT_STATE_CONNECTED) {
253 WFD_APP_LOG(WFD_APP_LOG_LOW, "Connected");
254 if (ad->transmit_timer) {
255 ecore_timer_del(ad->transmit_timer);
256 ad->transmit_timer = NULL;
258 WFD_APP_LOG(WFD_APP_LOG_LOW, "start the transmit timer again\n");
259 ad->last_wfd_transmit_time = time(NULL);
260 ad->transmit_timer = ecore_timer_add(5.0,
261 (Ecore_Task_Cb)wfd_automatic_deactivated_for_connection_cb, ad);
263 app_control_h ug_control;
264 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launching Settings EFL from notification\n");
265 app_control_create(&ug_control);
266 app_control_set_operation(ug_control, APP_CONTROL_OPERATION_DEFAULT);
267 app_control_set_launch_mode(ug_control, APP_CONTROL_LAUNCH_MODE_GROUP);
268 app_control_set_app_id(ug_control, "setting-wifidirect-efl");
270 ret = app_control_send_launch_request(ug_control, NULL, NULL);
271 if(ret == APP_CONTROL_ERROR_NONE) {
272 WFD_APP_LOG(WFD_APP_LOG_LOW, "Launch Wi-Fi Direct successful");
274 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to launch Wi-Fi Direct");
276 app_control_destroy(ug_control);
279 WFD_IF_FREE_MEM(noti_type);
280 __WFD_APP_FUNC_EXIT__;
284 int main(int argc, char *argv[])
287 ui_app_lifecycle_callback_s event_callback;
288 memset(&event_callback, 0x0, sizeof(ui_app_lifecycle_callback_s));
290 event_callback.create = _app_create;
291 event_callback.terminate = _app_terminate;
292 event_callback.pause = _app_pause;
293 event_callback.resume = _app_resume;
294 event_callback.app_control = _app_reset;
296 memset(&ad, 0x0, sizeof(wfd_appdata_t));
299 return ui_app_main(argc, argv, &event_callback, &ad);