summaryrefslogtreecommitdiff
path: root/popup-wifidirect/src/wfd-app-main.c
diff options
context:
space:
mode:
authorjk7744.park <jk7744.park@samsung.com>2015-09-08 21:40:41 +0900
committerjk7744.park <jk7744.park@samsung.com>2015-09-08 21:40:41 +0900
commitb0f3619ab0a54ffd1350ba9d7be917fa17133ab1 (patch)
tree75eaf38fd23b9662a39e96efdcedf074309c1f67 /popup-wifidirect/src/wfd-app-main.c
parent1dad141916551e3fa97bfbed2d754c5a69adc579 (diff)
downloadug-wifi-direct-b0f3619ab0a54ffd1350ba9d7be917fa17133ab1.tar.gz
ug-wifi-direct-b0f3619ab0a54ffd1350ba9d7be917fa17133ab1.tar.bz2
ug-wifi-direct-b0f3619ab0a54ffd1350ba9d7be917fa17133ab1.zip
Diffstat (limited to 'popup-wifidirect/src/wfd-app-main.c')
-rw-r--r--[-rwxr-xr-x]popup-wifidirect/src/wfd-app-main.c369
1 files changed, 228 insertions, 141 deletions
diff --git a/popup-wifidirect/src/wfd-app-main.c b/popup-wifidirect/src/wfd-app-main.c
index 16dd365..860cd68 100755..100644
--- a/popup-wifidirect/src/wfd-app-main.c
+++ b/popup-wifidirect/src/wfd-app-main.c
@@ -26,9 +26,18 @@
*/
#include <libintl.h>
-#include <appcore-efl.h>
-#include <appsvc.h>
-#include <app_service.h>
+#include <Elementary.h>
+#include <Ecore_X.h>
+#include <notification.h>
+#include <ui-gadget-module.h>
+#include <app_control.h>
+#include <feedback.h>
+#include <wifi-direct.h>
+#include <efl_util.h>
+#include <efl_assist.h>
+#include <linux/unistd.h>
+#include <utilX.h>
+#include <vconf.h>
#include "wfd-app.h"
#include "wfd-app-util.h"
@@ -38,188 +47,266 @@ wfd_appdata_t *g_wfd_ad;
wfd_appdata_t *wfd_get_appdata()
{
- return g_wfd_ad;
+ return g_wfd_ad;
}
-static void _win_del(void *data, Evas_Object * obj, void *event)
+static void _win_del(void *data, Evas_Object *obj, void *event)
{
- elm_exit();
+ elm_exit();
}
-static Evas_Object *_create_win(Evas_Object * parent, const char *name)
+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;
-}
+ 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);
+ efl_util_set_notification_window_level(eo, EFL_UTIL_NOTIFICATION_LEVEL_1);
+ evas_object_resize(eo, w, h);
+ evas_object_raise(eo);
+ }
+ return eo;
+}
-static int _app_create(void *data)
+static bool _app_create(void *data)
{
- __WFD_APP_FUNC_ENTER__;
+ __WFD_APP_FUNC_ENTER__;
+ wfd_appdata_t *ad = wfd_get_appdata();
+ int ret = 0;
+
+ if (data == NULL) {
+ WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
+ return FALSE;
+ }
- wfd_appdata_t *ad = wfd_get_appdata();
+ bindtextdomain(LOCALE_FILE_NAME, LOCALEDIR);
- if (data == NULL)
- {
- WFD_APP_LOG(WFD_APP_LOG_LOW, "Incorrect parameter\n");
- return -1;
- }
+ 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 FALSE;
+ }
- bindtextdomain(LOCALE_FILE_NAME, LOCALEDIR);
+ memset(ad->popup_data, 0x0, sizeof(wfd_popup_t));
+ ad->win = _create_win(NULL, PACKAGE);
- 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));
+ if (elm_win_wm_rotation_supported_get(ad->win)) {
+ int rots[4] = { 0, 90, 180, 270 };
+ elm_win_wm_rotation_available_rotations_set(ad->win, rots, 1);
+ }
- ad->win = _create_win(NULL, PACKAGE);
- elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
+ ad->conformant = elm_conformant_add(ad->win);
+ assertm_if(NULL == ad->conformant, "conformant is NULL!!");
+ elm_win_conformant_set(ad->win, EINA_TRUE);
+ elm_win_resize_object_add(ad->win, ad->conformant);
+ evas_object_size_hint_weight_set(ad->conformant, EVAS_HINT_EXPAND, 0.0);
+ evas_object_size_hint_align_set(ad->conformant, EVAS_HINT_FILL, 0.0);
+ evas_object_show(ad->conformant);
- int r;
- if (!ecore_x_display_get())
- return -1;
+ ad->back_grnd = elm_bg_add(ad->conformant);
+ if (NULL == ad->back_grnd) {
+ WFD_APP_LOG(WFD_APP_LOG_LOW, "Create background failed\n");
+ return FALSE;
+ }
+ elm_object_signal_emit(ad->conformant, "elm,state,indicator,nooverlap", "elm");
+ elm_object_style_set(ad->back_grnd, "indicator/headerbg");
+ elm_object_part_content_set(ad->conformant, "elm.swallow.indicator_bg", ad->back_grnd);
+ evas_object_size_hint_weight_set(ad->back_grnd,
+ EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_show(ad->back_grnd);
+
+ ad->layout = elm_layout_add(ad->conformant);
+ elm_object_content_set(ad->conformant, ad->layout);
+
+ if (!ecore_x_display_get()) {
+ return FALSE;
+ }
- r = appcore_set_i18n(PACKAGE, NULL);
- if (r != 0)
- {
- WFD_APP_LOG(WFD_APP_LOG_LOW, "appcore_set_i18n error\n");
- return -1;
- }
+ ret = init_wfd_client(ad);
+ if (!ret) {
+ 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 FALSE;
+ }
+
+ ret = wfd_app_util_register_vconf_callbacks(ad);
+ if (ret < 0) {
+ WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf notification");
+ return FALSE;
+ }
- 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);
- }
+ /* Enable Changeable UI feature */
+ ea_theme_changeable_ui_enabled_set(EINA_TRUE);
- __WFD_APP_FUNC_EXIT__;
+ /* Register Hard Key Press CB */
+ wfd_app_util_register_hard_key_down_cb(ad);
- return 0;
+ /* Initializes feedback API */
+ ret = feedback_initialize();
+ if (ret != FEEDBACK_ERROR_NONE) {
+ WFD_APP_LOG(WFD_APP_LOG_ERROR, "feedback_initialize error : %d\n", ret);
+ return FALSE;
+ }
+ __WFD_APP_FUNC_EXIT__;
+ return TRUE;
}
-static int _app_terminate(void *data)
+static void _app_terminate(void *data)
{
__WFD_APP_FUNC_ENTER__;
+ wfd_appdata_t *ad = (wfd_appdata_t *) data;
+ int ret = 0;
- if (data == NULL)
- {
+ if (data == NULL) {
WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
- return -1;
+ return;
}
- wfd_appdata_t *ad = (wfd_appdata_t *) data;
+ wfd_app_util_del_notification(ad);
- if (deinit_wfd_popup_client(ad) == FALSE)
- {
- WFD_APP_LOG(WFD_APP_LOG_ERROR, "deinit_wfd_popup_client error\n");
+ ret = wfd_app_util_deregister_vconf_callbacks(ad);
+ if (ret < 0) {
+ WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register vconf notification");
}
- 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;
- }
+
+ /* Deregister Hardkey CB */
+ wfd_app_util_deregister_hard_key_down_cb(ad);
+
+ /* Deinitializes feedback API */
+ ret = feedback_deinitialize();
+ if (ret != FEEDBACK_ERROR_NONE) {
+ WFD_APP_LOG(WFD_APP_LOG_ERROR, "feedback_deinitialize error : %d\n", ret);
+ }
+ if (ad->transmit_timer) {
+ ecore_timer_del(ad->transmit_timer);
+ ad->transmit_timer = NULL;
}
- __WFD_APP_FUNC_EXIT__;
+ wfd_destroy_popup();
+
+ ret = deinit_wfd_client(ad);
+ if (ret < 0) {
+ WFD_APP_LOG(WFD_APP_LOG_ERROR, "deinit_wfd_client error\n");
+ }
+
+ if (ad->back_grnd) {
+ evas_object_del(ad->back_grnd);
+ ad->back_grnd = NULL;
+ }
+
+ if (ad->win) {
+ evas_object_del(ad->win);
+ ad->win = NULL;
+ }
- return 0;
+ if (ad->popup_data) {
+ free(ad->popup_data);
+ ad->popup_data = NULL;
+ }
+
+ __WFD_APP_FUNC_EXIT__;
+ return;
}
-static int _app_pause(void *data)
+static void _app_pause(void *data)
{
- __WFD_APP_FUNC_ENTER__;
- __WFD_APP_FUNC_EXIT__;
- return 0;
+ __WFD_APP_FUNC_ENTER__;
+ __WFD_APP_FUNC_EXIT__;
+ return;
}
-static int _app_resume(void *data)
+static void _app_resume(void *data)
{
- __WFD_APP_FUNC_ENTER__;
- __WFD_APP_FUNC_EXIT__;
- return 0;
+ __WFD_APP_FUNC_ENTER__;
+ __WFD_APP_FUNC_EXIT__;
+ return;
}
-static int _app_reset(bundle * b, void *data)
+static void _app_reset(app_control_h control, 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;
+ __WFD_APP_FUNC_ENTER__;
+
+ int ret;
+ wfd_appdata_t *ad = (wfd_appdata_t *) data;
+ if (ad == NULL) {
+ WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
+ return;
+ }
+ if (control == NULL) {
+ WFD_APP_LOG(WFD_APP_LOG_ERROR, "Service is NULL");
+ return;
+ }
+
+ // From Notification
+ char *noti_type = NULL;
+ app_control_get_extra_data(control, NOTIFICATION_BUNDLE_PARAM, &noti_type);
+
+ if (noti_type == NULL) {
+ WFD_APP_LOG(WFD_APP_LOG_ERROR, "Notification type is wrong.");
+ return;
+ }
+
+ 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-ug");
+ wifi_direct_get_state(&ad->wfd_status);
+ WFD_APP_LOG(WFD_APP_LOG_LOW, "State: %d", ad->wfd_status);
+ if (ad->wfd_status == WIFI_DIRECT_STATE_CONNECTED) {
+ WFD_APP_LOG(WFD_APP_LOG_LOW, "Connected");
+ if (ad->transmit_timer) {
+ ecore_timer_del(ad->transmit_timer);
+ ad->transmit_timer = NULL;
+ }
+ WFD_APP_LOG(WFD_APP_LOG_LOW, "start the transmit timer again\n");
+ ad->last_wfd_transmit_time = time(NULL);
+ ad->transmit_timer = ecore_timer_add(5.0,
+ (Ecore_Task_Cb)wfd_automatic_deactivated_for_connection_cb, ad);
+ }
+ app_control_h ug_control;
+ WFD_APP_LOG(WFD_APP_LOG_LOW, "Launching Settings EFL from notification\n");
+ app_control_create(&ug_control);
+ app_control_set_operation(ug_control, APP_CONTROL_OPERATION_DEFAULT);
+ app_control_set_window(ug_control, elm_win_xwindow_get(ug_get_window()));
+ app_control_set_app_id(ug_control, "setting-wifidirect-efl");
+
+ ret = app_control_send_launch_request(ug_control, NULL, NULL);
+ if(ret == APP_CONTROL_ERROR_NONE) {
+ WFD_APP_LOG(WFD_APP_LOG_LOW, "Launch Wi-Fi Direct successful");
+ } else {
+ WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to launch Wi-Fi Direct");
+ }
+ app_control_destroy(ug_control);
+
+ }
+ WFD_IF_FREE_MEM(noti_type);
+ __WFD_APP_FUNC_EXIT__;
+ return;
}
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);
+ wfd_appdata_t ad;
+ ui_app_lifecycle_callback_s event_callback;
+ memset(&event_callback, 0x0, sizeof(ui_app_lifecycle_callback_s));
+
+ event_callback.create = _app_create;
+ event_callback.terminate = _app_terminate;
+ event_callback.pause = _app_pause;
+ event_callback.resume = _app_resume;
+ event_callback.app_control = _app_reset;
+
+ memset(&ad, 0x0, sizeof(wfd_appdata_t));
+ g_wfd_ad = &ad;
+
+ return ui_app_main(argc, argv, &event_callback, &ad);
}