merge with master
[platform/core/uifw/tts.git] / server / ttsd_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 "ttsd_main.h"
16 #include "ttsd_network.h"
17
18 #include <vconf.h>
19
20 bool g_is_connected;
21
22 bool ttsd_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         SLOG(LOG_DEBUG, get_tag(), "[Network DEBUG] Network configuration : %d", network_configuration);
32
33         if (network_configuration == 0) {
34                 SLOG(LOG_DEBUG, get_tag(), "[Network] Notification : Network connection is OFF ");
35                 g_is_connected = false;
36         } else {
37                 SLOG(LOG_DEBUG, get_tag(), "[Network] Notification : Network connection is ON ");
38                 g_is_connected = true;
39
40                 /* need to notify changing net to engine. */
41         }
42
43         return;
44 }
45
46 int ttsd_network_initialize()
47 {
48         int network_configuration = 0;
49         vconf_get_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND , &network_configuration);
50         SLOG(LOG_DEBUG, get_tag(), "[Network DEBUG] Network configuration : %d", network_configuration);
51
52         if (network_configuration == 0) {
53                 /*      "0" means the network configuration is not set. 
54                 *       It could be network connection is not open
55                 */
56
57                 int network_status = 0;
58                 vconf_get_int(VCONFKEY_NETWORK_STATUS, &network_status);
59
60                 if(network_status == VCONFKEY_NETWORK_OFF){
61                         SLOG(LOG_DEBUG, get_tag(), "[Network] Current network connection is OFF.");
62                 }
63                 else{
64                         /*
65                         *       This is the problem of network connection
66                         *       Just terminate the application, network f/w will fix the problem automatically.
67                         */
68                         SLOG(LOG_WARN, get_tag(), "network status is wrong or IP is not set\n");
69                         SLOG(LOG_WARN, get_tag(), "network has problem, try again\n");
70                         return -1;
71                 }
72
73                 g_is_connected = false;
74         } else {
75                 SLOG(LOG_DEBUG, get_tag(), "[Network] 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         SLOG(LOG_DEBUG, get_tag(), "[Network SUCCESS] Initialize network ...\n");
83
84         return 0;
85 }
86
87 int ttsd_network_finalize()
88 {
89         vconf_ignore_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, __net_config_change_cb);
90
91         return 0;
92 }
93