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(mh_appdata_t *ad)
30 __MOBILE_AP_FUNC_ENTER__;
32 ad->naviframe = _create_naviframe(ad->layout);
35 __MOBILE_AP_FUNC_EXIT__;
40 static void __set_callbacks(tethering_h handle, void *user_data)
42 tethering_set_enabled_cb(handle, TETHERING_TYPE_USB, _enabled_cb, user_data);
43 tethering_set_enabled_cb(handle, TETHERING_TYPE_WIFI, _enabled_cb, user_data);
44 tethering_set_enabled_cb(handle, TETHERING_TYPE_BT, _enabled_cb, user_data);
46 tethering_set_disabled_cb(handle, TETHERING_TYPE_USB, _disabled_cb, user_data);
47 tethering_set_disabled_cb(handle, TETHERING_TYPE_WIFI, _disabled_cb, user_data);
48 tethering_set_disabled_cb(handle, TETHERING_TYPE_BT, _disabled_cb, user_data);
50 tethering_set_connection_state_changed_cb(handle, TETHERING_TYPE_USB, _connection_changed_cb, user_data);
51 tethering_set_connection_state_changed_cb(handle, TETHERING_TYPE_WIFI, _connection_changed_cb, user_data);
52 tethering_set_connection_state_changed_cb(handle, TETHERING_TYPE_BT, _connection_changed_cb, user_data);
55 static void __unset_callbacks(tethering_h handle)
57 tethering_unset_enabled_cb(handle, TETHERING_TYPE_USB);
58 tethering_unset_enabled_cb(handle, TETHERING_TYPE_WIFI);
59 tethering_unset_enabled_cb(handle, TETHERING_TYPE_BT);
61 tethering_unset_disabled_cb(handle, TETHERING_TYPE_USB);
62 tethering_unset_disabled_cb(handle, TETHERING_TYPE_WIFI);
63 tethering_unset_disabled_cb(handle, TETHERING_TYPE_BT);
65 tethering_unset_connection_state_changed_cb(handle, TETHERING_TYPE_USB);
66 tethering_unset_connection_state_changed_cb(handle, TETHERING_TYPE_WIFI);
67 tethering_unset_connection_state_changed_cb(handle, TETHERING_TYPE_BT);
70 static void *on_create(ui_gadget_h ug, enum ug_mode mode,
71 service_h service, void *priv)
73 __MOBILE_AP_FUNC_ENTER__;
76 ERR("The param is NULL\n");
80 if (mode != UG_MODE_FULLVIEW) {
81 ERR("Only Fullview is supported\n");
91 bindtextdomain(MH_TEXT_DOMAIN, MH_LOCALEDIR);
92 dgettext(PACKAGE, LOCALEDIR);
94 ad = (mh_appdata_t *)malloc(sizeof(mh_appdata_t));
97 ERR("Error!!! failed to allocate memory()\n");
100 memset(ad, 0x0, sizeof(mh_appdata_t));
102 ugd = (mh_ugdata_t *)priv;
109 ret = tethering_create(&ad->handle);
110 if (ret != TETHERING_ERROR_NONE) {
111 ERR("tethering_create is failed : %d\n", ret);
117 ad->win = ug_get_parent_layout(ug);
119 ERR("ad->win is NULL\n");
125 layout = _create_win_layout(ad);
126 if (layout == NULL) {
127 ERR("_create_win_layout is failed\n");
133 content = create_content(ad);
134 if (content == NULL) {
135 ERR("create_content is failed\n");
141 elm_object_part_content_set(layout, "elm.swallow.content", content);
142 evas_object_show(layout);
144 ret = connection_create(&ad->conn_handle);
145 if (ret != CONNECTION_ERROR_NONE) {
146 ERR("connection_create() is failed : %d\n", ret);
149 ret = wifi_initialize();
150 if (ret != WIFI_ERROR_NONE) {
151 ERR("wifi_initialize() is failed : %d\n", ret);
154 __set_callbacks(ad->handle, (void *)ad);
156 __MOBILE_AP_FUNC_EXIT__;
160 static void on_start(ui_gadget_h ug, service_h service, void *priv)
164 static void on_pause(ui_gadget_h ug, service_h service, void *priv)
169 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
174 static void on_destroy(ui_gadget_h ug, service_h service, void *priv)
176 __MOBILE_AP_FUNC_ENTER__;
179 ERR("The param is NULL\n");
183 mh_ugdata_t *ugd = priv;
184 mh_appdata_t *ad = ugd->ad;
188 ERR("The param is NULL\n");
192 __unset_callbacks(ad->handle);
193 _stop_update_data_packet_usage(ad);
195 ret = wifi_deinitialize();
196 if (ret != WIFI_ERROR_NONE) {
197 ERR("wifi_deinitialize() is failed : %d\n", ret);
200 ret = connection_destroy(ad->conn_handle);
201 if (ret != CONNECTION_ERROR_NONE) {
202 ERR("connection_destroy() is failed : %d\n", ret);
205 ret = tethering_destroy(ad->handle);
206 if (ret != TETHERING_ERROR_NONE) {
207 ERR("tethering_destroy() is failed : %d\n", ret);
210 if (ad->layout == NULL) {
211 ERR("ad->layout is NULL\n");
219 evas_object_del(ad->popup);
223 evas_object_del(ad->bg);
226 evas_object_del(ad->layout);
229 ecore_imf_shutdown();
234 __MOBILE_AP_FUNC_EXIT__;
238 static void on_message(ui_gadget_h ug, service_h msg,
239 service_h service, void *priv)
243 static void on_event(ui_gadget_h ug, enum ug_event event,
244 service_h service, void *priv)
246 __MOBILE_AP_FUNC_ENTER__;
249 ERR("The param is NULL\n");
254 case UG_EVENT_LOW_MEMORY:
255 DBG("UG_EVENT_LOW_MEMORY\n");
257 case UG_EVENT_LOW_BATTERY:
258 DBG("UG_EVENT_LOW_BATTERY\n");
260 case UG_EVENT_LANG_CHANGE:
261 DBG("UG_EVENT_LANG_CHANGE\n");
263 case UG_EVENT_ROTATE_PORTRAIT:
264 DBG("UG_EVENT_ROTATE_PORTRAIT\n");
266 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
267 DBG("UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN\n");
269 case UG_EVENT_ROTATE_LANDSCAPE:
270 DBG("UG_EVENT_ROTATE_LANDSCAPE\n");
272 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
273 DBG("UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN\n");
280 __MOBILE_AP_FUNC_EXIT__;
283 static void on_key_event(ui_gadget_h ug, enum ug_key_event event,
284 service_h service, void *priv)
286 __MOBILE_AP_FUNC_ENTER__;
288 if (priv == NULL || ug == NULL) {
289 ERR("The param is NULL\n");
293 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
294 mh_appdata_t *ad = ugd->ad;
302 case UG_KEY_EVENT_END:
303 DBG("UG_KEY_EVENT_END is received : %p\n", ad->popup);
304 if (NULL == ad->popup) {
309 if (ad->popup_type != MH_POP_INFORMATION_WO_BUTTON) {
310 evas_object_del(ad->popup);
312 ad->popup_type = MH_POPUP_NONE;
320 __MOBILE_AP_FUNC_EXIT__;
323 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
325 __MOBILE_AP_FUNC_ENTER__;
328 ERR("The param is NULL\n");
333 ugd = calloc(1, sizeof(mh_ugdata_t));
335 ERR("Quit : calloc failed(ugd)\n");
339 ops->create = on_create;
340 ops->start = on_start;
341 ops->pause = on_pause;
342 ops->resume = on_resume;
343 ops->destroy = on_destroy;
344 ops->message = on_message;
345 ops->event = on_event;
346 ops->key_event = on_key_event;
348 ops->opt = UG_OPT_INDICATOR_ENABLE;
350 __MOBILE_AP_FUNC_EXIT__;
355 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
357 __MOBILE_AP_FUNC_ENTER__;
360 ERR("The param is NULL\n");
364 mh_ugdata_t *ugd = (mh_ugdata_t *)ops->priv;
369 __MOBILE_AP_FUNC_EXIT__;
372 static void __mh_reset_vconf(tethering_h handle)
376 ret = vconf_set_int(VCONF_MOBILE_AP_PREV_WIFI_STATUS, 0);
378 ERR("vconf_set_int failed\n");
380 ret = tethering_wifi_set_ssid_visibility(handle, true);
381 if (ret != TETHERING_ERROR_NONE)
382 ERR("tethering_wifi_set_ssid_visibility failed\n");
384 ret = tethering_wifi_set_security_type(handle, TETHERING_WIFI_SECURITY_TYPE_NONE);
385 if (ret != TETHERING_ERROR_NONE)
386 ERR("tethering_wifi_set_security_type failed\n");
391 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
393 __MOBILE_AP_FUNC_ENTER__;
396 tethering_h handle = NULL;
398 if (tethering_create(&handle) != TETHERING_ERROR_NONE) {
399 ERR("tethering_create failed\n");
403 if (tethering_is_enabled(handle, TETHERING_TYPE_USB) ||
404 tethering_is_enabled(handle, TETHERING_TYPE_WIFI) ||
405 tethering_is_enabled(handle, TETHERING_TYPE_BT)) {
406 ret = tethering_disable(handle, TETHERING_TYPE_ALL);
407 if (ret != TETHERING_ERROR_NONE) {
408 ERR("tethering_disable failed : %d\n", ret);
409 tethering_destroy(handle);
415 __mh_reset_vconf(handle);
417 tethering_destroy(handle);
419 __MOBILE_AP_FUNC_EXIT__;