/* * WiFi-Direct UG * * Copyright 2012 Samsung Electronics Co., Ltd * Licensed under the Flora License, Version 1.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.tizenopensource.org/license * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ /** * This file implements wifi direct application main functions. * * @file wfd-app-main.c * @author Sungsik Jang (sungsik.jang@samsung.com) * @version 0.1 */ #include #include #include #include #include "wfd-app.h" #include "wfd-app-util.h" wfd_appdata_t *g_wfd_ad; wfd_appdata_t *wfd_get_appdata() { return g_wfd_ad; } static void _win_del(void *data, Evas_Object * obj, void *event) { elm_exit(); } static Evas_Object *_create_win(Evas_Object * parent, const char *name) { Evas_Object *eo; int w, h; /* eo = elm_win_add(parent, name, ELM_WIN_BASIC); */ eo = elm_win_add(NULL, name, ELM_WIN_NOTIFICATION); if (eo) { elm_win_title_set(eo, name); elm_win_borderless_set(eo, EINA_TRUE); elm_win_alpha_set(eo, EINA_TRUE); evas_object_smart_callback_add(eo, "delete,request", _win_del, NULL); ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h); evas_object_resize(eo, w, h); evas_object_raise(eo); } return eo; } static int _app_create(void *data) { __WFD_APP_FUNC_ENTER__; wfd_appdata_t *ad = wfd_get_appdata(); if (data == NULL) { WFD_APP_LOG(WFD_APP_LOG_LOW, "Incorrect parameter\n"); return -1; } bindtextdomain(LOCALE_FILE_NAME, LOCALEDIR); ad->popup_data = (wfd_popup_t *) malloc(sizeof(wfd_popup_t)); if (!ad->popup_data) { WFD_APP_LOG(WFD_APP_LOG_ERROR, "malloc failed\n"); return -1; } memset(ad->popup_data, 0x0, sizeof(wfd_popup_t)); ad->win = _create_win(NULL, PACKAGE); elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW); int r; if (!ecore_x_display_get()) return -1; r = appcore_set_i18n(PACKAGE, NULL); if (r != 0) { WFD_APP_LOG(WFD_APP_LOG_LOW, "appcore_set_i18n error\n"); return -1; } if (init_wfd_popup_client(ad) == FALSE) { WFD_APP_LOG(WFD_APP_LOG_ERROR, "init_wfd_popup_client error\n"); wfd_prepare_popup(WFD_POP_FAIL_INIT, NULL); } __WFD_APP_FUNC_EXIT__; return 0; } static int _app_terminate(void *data) { __WFD_APP_FUNC_ENTER__; if (data == NULL) { WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n"); return -1; } wfd_appdata_t *ad = (wfd_appdata_t *) data; if (deinit_wfd_popup_client(ad) == FALSE) { WFD_APP_LOG(WFD_APP_LOG_ERROR, "deinit_wfd_popup_client error\n"); } else { if (ad->popup) { evas_object_del(ad->popup); ad->popup = NULL; } if (ad->win) { evas_object_del(ad->win); ad->win = NULL; } if (ad->discovered_peers) { free(ad->discovered_peers); ad->discovered_peers = NULL; } } __WFD_APP_FUNC_EXIT__; return 0; } static int _app_pause(void *data) { __WFD_APP_FUNC_ENTER__; __WFD_APP_FUNC_EXIT__; return 0; } static int _app_resume(void *data) { __WFD_APP_FUNC_ENTER__; __WFD_APP_FUNC_EXIT__; return 0; } static int _app_reset(bundle * b, void *data) { __WFD_APP_FUNC_ENTER__; wfd_appdata_t *ad = (wfd_appdata_t*) data; if(b == NULL) { WFD_APP_LOG(WFD_APP_LOG_LOW,"Bundle is NULL"); return -1; } // From Notification char *noti_type = NULL; noti_type = (char*) appsvc_get_data(b, NOTIFICATION_BUNDLE_PARAM); if (noti_type == NULL) { WFD_APP_LOG(WFD_APP_LOG_LOW,"Notification type is wrong."); return -1; } WFD_APP_LOG(WFD_APP_LOG_LOW,"Notification type is [%s]", noti_type); if (strncmp(noti_type, NOTIFICATION_BUNDLE_VALUE, strlen(NOTIFICATION_BUNDLE_PARAM))==0) { WFD_APP_LOG(WFD_APP_LOG_LOW,"Launch wifidirect-ugapp"); service_h service; service_create(&service); service_set_operation(service, SERVICE_OPERATION_DEFAULT); service_set_package(service, "org.tizen.wifi-direct-ugapp"); service_send_launch_request(service, NULL, NULL); service_destroy(service); } __WFD_APP_FUNC_EXIT__; return 0; } int main(int argc, char *argv[]) { wfd_appdata_t ad; struct appcore_ops ops = { .create = _app_create, .terminate = _app_terminate, .pause = _app_pause, .resume = _app_resume, .reset = _app_reset, }; memset(&ad, 0x0, sizeof(wfd_appdata_t)); ops.data = &ad; g_wfd_ad = &ad; return appcore_efl_main(PACKAGE, &argc, &argv, &ops); }