3621ba3cbb74e3664bd161d8df5e511012f54a4d
[platform/core/uifw/stt.git] / server / sttd_network.c
1 /*
2 *  Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved 
3 *  Licensed under the Apache License, Version 2.0 (the "License");
4 *  you may not use this file except in compliance with the License.
5 *  You may obtain a copy of the License at
6 *  http://www.apache.org/licenses/LICENSE-2.0
7 *  Unless required by applicable law or agreed to in writing, software
8 *  distributed under the License is distributed on an "AS IS" BASIS,
9 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 *  See the License for the specific language governing permissions and
11 *  limitations under the License.
12 */
13
14
15 #include "sttd_main.h"
16 #include "sttd_network.h"
17
18 #include <vconf.h>
19
20 static bool g_is_connected;
21
22 bool sttd_network_is_connected()
23 {
24         return g_is_connected;
25 }
26
27 void __net_config_change_cb(keynode_t* node, void *data) 
28 {
29         int network_configuration = 0;
30         vconf_get_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND , &network_configuration);
31
32         if (network_configuration == 0) {
33                 SLOG(LOG_DEBUG, TAG_STTD, "[Network DEBUG] Change Network Connection is OFF ");
34                 g_is_connected = false;
35         } else {
36                 SLOG(LOG_DEBUG, TAG_STTD, "[Network DEBUG] Change Network Connection is ON ");
37                 g_is_connected = true;
38                 
39                 /* need to notify changing net to engine. */
40         }
41
42         return;
43 }
44
45 int sttd_network_initialize()
46 {
47         int network_configuration = 0;
48         vconf_get_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND , &network_configuration);
49
50         if (network_configuration == 0) {
51                 /*      "0" means the network configuration is not set. 
52                 *       It could be network connection is not open
53                 */
54
55                 int network_status = 0;
56                 vconf_get_int(VCONFKEY_NETWORK_STATUS, &network_status);
57
58                 if(network_status == VCONFKEY_NETWORK_OFF){
59                         printf("Current network connection is OFF!! \n");
60                         SLOG(LOG_DEBUG, TAG_STTD, "[Network DEBUG] Current network connection is OFF.");
61                 }
62                 else{
63                         /*
64                         *       This is the problem of network connection
65                         *       Just terminate the application, network f/w will fix the problem automatically.
66                         */
67                         printf("network status is wrong or IP is not set\n");
68                         printf("network has problem, try again\n");
69                         exit(0);
70                 }
71
72                 g_is_connected = false;
73         } else {
74                 printf("Current network connection is ON. \n");
75                 SLOG(LOG_DEBUG, TAG_STTD, "[Network DEBUG] Current network connection is ON.");
76                         
77                 g_is_connected = true;
78         }
79
80         vconf_notify_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, __net_config_change_cb, NULL);
81         
82         return 0;
83 }
84
85 int sttd_network_finalize()
86 {
87         vconf_ignore_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, __net_config_change_cb);
88
89         return 0;
90 }
91