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 #define UG_MODULE_API __attribute__ ((visibility("default")))
24 #include "mobile_hotspot.h"
25 #include "mh_view_main.h"
26 #include "mh_func_onoff.h"
28 static Evas_Object *create_content(Evas_Object *parent,
29 mh_ugdata_t *ugd, mh_appdata_t *ad)
31 __MOBILE_AP_FUNC_ENTER__;
33 ad->naviframe = _create_naviframe(ugd->base);
36 /* init internationalization */
37 dgettext(PACKAGE, LOCALEDIR);
39 __MOBILE_AP_FUNC_EXIT__;
44 static Evas_Object *create_fullview(Evas_Object *parent, mh_ugdata_t *ugd)
46 __MOBILE_AP_FUNC_ENTER__;
51 /* Create Full view */
52 base = _create_layout(parent);
54 ERR("base is NULL\n");
58 bg = _create_bg(base, "group_list");
61 evas_object_del(base);
64 elm_object_part_content_set(base, "elm.swallow.bg", bg);
66 elm_win_resize_object_add(parent, base);
68 __MOBILE_AP_FUNC_EXIT__;
72 static Evas_Object *create_frameview(Evas_Object *parent, mh_ugdata_t *ugd)
74 __MOBILE_AP_FUNC_ENTER__;
79 /* Create Frame view */
80 base = _create_layout(parent);
82 ERR("base is NULL\n");
86 bg = _create_bg(base, "group_list");
89 evas_object_del(base);
92 elm_object_part_content_set(base, "elm.swallow.bg", bg);
94 elm_win_resize_object_add(parent, base);
96 __MOBILE_AP_FUNC_EXIT__;
100 static void __set_callbacks(tethering_h handle, void *user_data)
102 tethering_set_enabled_cb(handle, TETHERING_TYPE_USB, _enabled_cb, user_data);
103 tethering_set_enabled_cb(handle, TETHERING_TYPE_WIFI, _enabled_cb, user_data);
104 tethering_set_enabled_cb(handle, TETHERING_TYPE_BT, _enabled_cb, user_data);
106 tethering_set_disabled_cb(handle, TETHERING_TYPE_USB, _disabled_cb, user_data);
107 tethering_set_disabled_cb(handle, TETHERING_TYPE_WIFI, _disabled_cb, user_data);
108 tethering_set_disabled_cb(handle, TETHERING_TYPE_BT, _disabled_cb, user_data);
110 tethering_set_connection_state_changed_cb(handle, TETHERING_TYPE_USB, _connection_changed_cb, user_data);
111 tethering_set_connection_state_changed_cb(handle, TETHERING_TYPE_WIFI, _connection_changed_cb, user_data);
112 tethering_set_connection_state_changed_cb(handle, TETHERING_TYPE_BT, _connection_changed_cb, user_data);
115 static void __unset_callbacks(tethering_h handle)
117 tethering_unset_enabled_cb(handle, TETHERING_TYPE_USB);
118 tethering_unset_enabled_cb(handle, TETHERING_TYPE_WIFI);
119 tethering_unset_enabled_cb(handle, TETHERING_TYPE_BT);
121 tethering_unset_disabled_cb(handle, TETHERING_TYPE_USB);
122 tethering_unset_disabled_cb(handle, TETHERING_TYPE_WIFI);
123 tethering_unset_disabled_cb(handle, TETHERING_TYPE_BT);
125 tethering_unset_connection_state_changed_cb(handle, TETHERING_TYPE_USB);
126 tethering_unset_connection_state_changed_cb(handle, TETHERING_TYPE_WIFI);
127 tethering_unset_connection_state_changed_cb(handle, TETHERING_TYPE_BT);
130 static void *on_create(ui_gadget_h ug, enum ug_mode mode,
131 service_h service, void *priv)
133 __MOBILE_AP_FUNC_ENTER__;
136 ERR("The param is NULL\n");
140 Evas_Object *content;
145 bindtextdomain(MH_TEXT_DOMAIN, MH_LOCALEDIR);
147 ad = (mh_appdata_t *)malloc(sizeof(mh_appdata_t));
150 ERR("Error!!! failed to allocate memory()\n");
153 memset(ad, 0x0, sizeof(mh_appdata_t));
155 if (tethering_create(&ad->handle) != TETHERING_ERROR_NONE) {
156 ERR("tethering_create is failed\n");
161 ugd = (mh_ugdata_t *)priv;
165 ad->win = ug_get_parent_layout(ug);
167 ERR("ad->win is NULL\n");
172 if (mode == UG_MODE_FULLVIEW)
173 ugd->base = create_fullview(ad->win, ugd);
175 ugd->base = create_frameview(ad->win, ugd);
178 content = create_content(ad->win, ugd, ad);
179 elm_object_part_content_set(ugd->base, "elm.swallow.content", content);
180 evas_object_show(ugd->base);
183 ret = connection_create(&ad->conn_handle);
184 if (ret != CONNECTION_ERROR_NONE) {
185 ERR("connection_create() is failed : %d\n", ret);
188 ret = wifi_initialize();
189 if (ret != WIFI_ERROR_NONE) {
190 ERR("wifi_initialize() is failed : %d\n", ret);
193 __set_callbacks(ad->handle, (void *)ad);
195 __MOBILE_AP_FUNC_EXIT__;
199 static void on_start(ui_gadget_h ug, service_h service, void *priv)
203 static void on_pause(ui_gadget_h ug, service_h service, void *priv)
208 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
213 static void on_destroy(ui_gadget_h ug, service_h service, void *priv)
215 __MOBILE_AP_FUNC_ENTER__;
218 ERR("The param is NULL\n");
222 mh_ugdata_t *ugd = priv;
225 if (ugd->ad == NULL || ugd->base == NULL) {
226 ERR("The param is NULL\n");
230 __unset_callbacks(ugd->ad->handle);
232 _stop_update_data_packet_usage(ugd->ad);
233 DBG("After Stop update data packet usage\n");
235 ret = wifi_deinitialize();
236 if (ret != WIFI_ERROR_NONE) {
237 ERR("wifi_deinitialize() is failed : %d\n", ret);
240 ret = connection_destroy(ugd->ad->conn_handle);
241 if (ret != CONNECTION_ERROR_NONE) {
242 ERR("connection_destroy() is failed : %d\n", ret);
245 ap_callback_del(ugd->ad);
246 DBG("After deleting callback functions \n");
248 ret = tethering_destroy(ugd->ad->handle);
249 DBG("The result of tethering_destroy is %d\n", ret);
251 if (ugd->ad->popup) {
252 evas_object_del(ugd->ad->popup);
253 ugd->ad->popup = NULL;
255 evas_object_del(ugd->base);
261 __MOBILE_AP_FUNC_EXIT__;
264 static void on_message(ui_gadget_h ug, service_h msg,
265 service_h service, void *priv)
269 static void on_event(ui_gadget_h ug, enum ug_event event,
270 service_h service, void *priv)
272 __MOBILE_AP_FUNC_ENTER__;
275 ERR("The param is NULL\n");
280 case UG_EVENT_LOW_MEMORY:
281 DBG("UG_EVENT_LOW_MEMORY\n");
283 case UG_EVENT_LOW_BATTERY:
284 DBG("UG_EVENT_LOW_BATTERY\n");
286 case UG_EVENT_LANG_CHANGE:
287 DBG("UG_EVENT_LANG_CHANGE\n");
289 case UG_EVENT_ROTATE_PORTRAIT:
290 DBG("UG_EVENT_ROTATE_PORTRAIT\n");
292 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
293 DBG("UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN\n");
295 case UG_EVENT_ROTATE_LANDSCAPE:
296 DBG("UG_EVENT_ROTATE_LANDSCAPE\n");
298 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
299 DBG("UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN\n");
306 __MOBILE_AP_FUNC_EXIT__;
309 static void on_key_event(ui_gadget_h ug, enum ug_key_event event,
310 service_h service, void *priv)
312 __MOBILE_AP_FUNC_ENTER__;
314 if (priv == NULL || ug == NULL) {
315 ERR("The param is NULL\n");
319 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
320 mh_appdata_t *ad = (mh_appdata_t *)ugd->ad;
328 case UG_KEY_EVENT_END:
329 DBG("UG_KEY_EVENT_END is received : %p\n", ad->popup);
330 if (NULL == ad->popup) {
335 if (ad->popup_type != MH_POP_INFORMATION_WO_BUTTON) {
336 evas_object_del(ad->popup);
338 ad->popup_type = MH_POPUP_NONE;
346 __MOBILE_AP_FUNC_EXIT__;
349 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
351 __MOBILE_AP_FUNC_ENTER__;
354 ERR("The param is NULL\n");
359 ugd = calloc(1, sizeof(mh_ugdata_t));
361 ERR("Quit : calloc failed(ugd)\n");
365 ops->create = on_create;
366 ops->start = on_start;
367 ops->pause = on_pause;
368 ops->resume = on_resume;
369 ops->destroy = on_destroy;
370 ops->message = on_message;
371 ops->event = on_event;
372 ops->key_event = on_key_event;
374 ops->opt = UG_OPT_INDICATOR_ENABLE;
376 __MOBILE_AP_FUNC_EXIT__;
381 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
383 __MOBILE_AP_FUNC_ENTER__;
386 ERR("The param is NULL\n");
396 __MOBILE_AP_FUNC_EXIT__;
399 static void __mh_reset_vconf(tethering_h handle)
403 ret = vconf_set_int(VCONF_MOBILE_AP_PREV_WIFI_STATUS, 0);
405 ERR("vconf_set_int failed\n");
407 ret = tethering_wifi_set_ssid_visibility(handle, true);
408 if (ret != TETHERING_ERROR_NONE)
409 ERR("tethering_wifi_set_ssid_visibility failed\n");
411 ret = tethering_wifi_set_security_type(handle, TETHERING_WIFI_SECURITY_TYPE_NONE);
412 if (ret != TETHERING_ERROR_NONE)
413 ERR("tethering_wifi_set_security_type failed\n");
418 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
420 __MOBILE_AP_FUNC_ENTER__;
423 tethering_h handle = NULL;
425 if (tethering_create(&handle) != TETHERING_ERROR_NONE) {
426 ERR("tethering_create failed\n");
430 if (tethering_is_enabled(handle, TETHERING_TYPE_USB) ||
431 tethering_is_enabled(handle, TETHERING_TYPE_WIFI) ||
432 tethering_is_enabled(handle, TETHERING_TYPE_BT)) {
433 ret = tethering_disable(handle, TETHERING_TYPE_ALL);
434 if (ret != TETHERING_ERROR_NONE) {
435 ERR("tethering_disable failed : %d\n", ret);
436 tethering_destroy(handle);
442 __mh_reset_vconf(handle);
444 tethering_destroy(handle);
446 __MOBILE_AP_FUNC_EXIT__;