Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SampleApp / tizen / SSMTesterApp / oic-sample / src / oicapp-utils.c
1 /*
2  * Copyright (c) 2014 Samsung Electronics, Inc.
3  * All rights reserved.
4  *
5  * This software is a confidential and proprietary information
6  * of Samsung Electronics, Inc. ("Confidential Information").  You
7  * shall not disclose such Confidential Information and shall use
8  * it only in accordance with the terms of the license agreement
9  * you entered into with Samsung Electronics.
10  */
11 #include <appcore-efl.h>
12 #include <wifi.h>
13
14 #include "oicapp-utils.h"
15
16 static void _popup_timeout_cb(void *data, Evas_Object *obj, void *event_info)
17 {
18         oicapp_data *ad = data;
19
20         ret_if(data == NULL);
21
22         //evas_object_del(ad->popup);
23         ad->popup = NULL;
24 }
25
26 void oicapp_fail_popup(oicapp_data *ad, char *title, char *text, int timeout)
27 {
28         if (ad->popup)
29         {
30                 evas_object_del(ad->popup);
31                 ad->popup = NULL;
32         }
33
34         Evas_Object *popup = elm_popup_add(ad->win);
35         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
36
37         if (title)
38                 elm_object_part_text_set(popup, "title,text", title);
39
40         if (text)
41                 elm_object_text_set(popup, text);
42
43         if (0 < timeout)
44                 elm_popup_timeout_set(popup, timeout);
45         else
46                 elm_popup_timeout_set(popup, 3);
47
48         evas_object_smart_callback_add(popup, "timeout", _popup_timeout_cb, ad);
49
50         evas_object_show(popup);
51
52         ad->popup = popup;
53 }
54
55 void oicapp_util_put_msg(oicapp_data *ad, const char *msg)
56 {
57         ret_if(NULL == msg);
58
59         if (ad->output_msg)
60                 free(ad->output_msg);
61         ad->output_msg = strdup(msg);
62
63         DBG("Output msg : %s", ad->output_msg);
64
65         elm_genlist_item_update(ad->item_multiline);
66         elm_genlist_item_item_class_update(ad->item_multiline, &(ad->itc_multiline));
67 }
68
69 char* oicapp_util_wifi()
70 {
71         int ret;
72         wifi_ap_h ap;
73         char *ip_addr = NULL;
74
75         ret = wifi_initialize();
76         if (WIFI_ERROR_NONE != ret)
77         {
78                 ERR("wifi_initialize() Fail");
79                 return NULL;
80         }
81
82         ret = wifi_get_connected_ap(&ap);
83         if (WIFI_ERROR_NONE != ret)
84         {
85                 ERR("wifi_get_connected_ap() Fail");
86                 return NULL;
87         }
88
89         ret = wifi_ap_get_ip_address(ap, WIFI_ADDRESS_FAMILY_IPV4, &ip_addr);
90         if (WIFI_ERROR_NONE != ret)
91         {
92                 ERR("wifi_ap_get_ip_address() Fail");
93                 return NULL;
94         }
95
96         return ip_addr;
97 }
98
99