apply FSL(Flora Software License)
[apps/native/ug-wifi-direct.git] / popup-wifidirect / src / wfd-app-main.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *    http://www.tizenopensource.org/license
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * This file implements wifi direct application main functions.
19  *
20  * @file    wfd-app-main.c
21  * @author  Sungsik Jang (sungsik.jang@samsung.com)
22  * @version 0.1
23  */
24
25 #include <libintl.h>
26
27 #include "wfd-app.h"
28 #include "wfd-app-util.h"
29
30 wfd_appdata_t *g_wfd_ad;
31
32
33 wfd_appdata_t *wfd_get_appdata()
34 {
35     return g_wfd_ad;
36 }
37
38 static void _win_del(void *data, Evas_Object * obj, void *event)
39 {
40     elm_exit();
41 }
42
43 static Evas_Object *_create_win(Evas_Object * parent, const char *name)
44 {
45     Evas_Object *eo;
46     int w, h;
47
48     eo = elm_win_add(parent, name, ELM_WIN_BASIC);
49     if (eo)
50     {
51         elm_win_title_set(eo, name);
52         elm_win_borderless_set(eo, EINA_TRUE);
53         elm_win_alpha_set(eo, EINA_TRUE);
54         evas_object_smart_callback_add(eo, "delete,request", _win_del, NULL);
55         ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
56         evas_object_resize(eo, w, h);
57         evas_object_raise(eo);
58     }
59
60     return eo;
61 }
62
63
64 static int _app_create(void *data)
65 {
66     __WFD_APP_FUNC_ENTER__;
67
68     wfd_appdata_t *ad = wfd_get_appdata();
69
70     if (data == NULL)
71     {
72         WFD_APP_LOG(WFD_APP_LOG_LOW, "Incorrect parameter\n");
73         return -1;
74     }
75
76     bindtextdomain(PACKAGE, LOCALEDIR);
77
78     ad->popup_data = (wfd_popup_t *) malloc(sizeof(wfd_popup_t));
79     if (!ad->popup_data)
80     {
81         WFD_APP_LOG(WFD_APP_LOG_ERROR, "malloc failed\n");
82         return -1;
83     }
84     memset(ad->popup_data, 0x0, sizeof(wfd_popup_t));
85
86     ad->win = _create_win(NULL, PACKAGE);
87     elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
88
89     int r;
90
91     if (!ecore_x_display_get())
92         return -1;
93
94     r = appcore_set_i18n(PACKAGE, NULL);
95     if (r != 0)
96     {
97         WFD_APP_LOG(WFD_APP_LOG_LOW, "appcore_set_i18n error\n");
98         return -1;
99     }
100
101     if (init_wfd_popup_client(ad) == FALSE)
102     {
103         WFD_APP_LOG(WFD_APP_LOG_ERROR, "init_wfd_popup_client error\n");
104         wfd_prepare_popup(WFD_POP_FAIL_INIT, NULL);
105     }
106
107     __WFD_APP_FUNC_EXIT__;
108
109     return 0;
110 }
111
112 static int _app_terminate(void *data)
113 {
114         __WFD_APP_FUNC_ENTER__;
115
116         if (data == NULL)
117         {
118                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
119                 return -1;
120         }
121
122         wfd_appdata_t *ad = (wfd_appdata_t *) data;
123
124         if (deinit_wfd_popup_client() == FALSE)
125         {
126                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "deinit_wfd_popup_client error\n");
127         }
128         else
129         {
130                 if (ad->popup)
131                 {
132                         evas_object_del(ad->popup);
133                         ad->popup = NULL;
134                 }
135                 if (ad->win)
136                 {
137                         evas_object_del(ad->win);
138                         ad->win = NULL;
139                 }
140                 if (ad->discovered_peers)
141                 {
142                         free(ad->discovered_peers);
143                         ad->discovered_peers = NULL;
144                 }
145         }
146
147         __WFD_APP_FUNC_EXIT__;
148
149         return 0;
150 }
151
152 static int _app_pause(void *data)
153 {
154     __WFD_APP_FUNC_ENTER__;
155     __WFD_APP_FUNC_EXIT__;
156     return 0;
157 }
158
159 static int _app_resume(void *data)
160 {
161     __WFD_APP_FUNC_ENTER__;
162     __WFD_APP_FUNC_EXIT__;
163     return 0;
164 }
165
166 static int _app_reset(bundle * b, void *data)
167 {
168     __WFD_APP_FUNC_ENTER__;
169     __WFD_APP_FUNC_EXIT__;
170     return 0;
171 }
172
173 int main(int argc, char *argv[])
174 {
175     wfd_appdata_t ad;
176     struct appcore_ops ops = {
177         .create = _app_create,
178         .terminate = _app_terminate,
179         .pause = _app_pause,
180         .resume = _app_resume,
181         .reset = _app_reset,
182     };
183
184     memset(&ad, 0x0, sizeof(wfd_appdata_t));
185     ops.data = &ad;
186     g_wfd_ad = &ad;
187
188     return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
189 }