tizen beta release
[platform/core/uifw/tts.git] / server / ttsd_network.c
1 /*
2 * Copyright (c) 2011 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, TAG_TTSD, "[Network DEBUG] Network configuration : %d", network_configuration);
32
33         if (network_configuration == 0) {
34                 SLOG(LOG_DEBUG, TAG_TTSD, "[Network] Notification : Network connection is OFF ");
35                 g_is_connected = false;
36         } else {
37                 SLOG(LOG_DEBUG, TAG_TTSD, "[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, TAG_TTSD, "[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                         printf("Current network connection is OFF!! \n");
62                         SLOG(LOG_DEBUG, TAG_TTSD, "[Network] Current network connection is OFF.");
63                 }
64                 else{
65                         /*
66                         *       This is the problem of network connection
67                         *       Just terminate the application, network f/w will fix the problem automatically.
68                         */
69                         printf("network status is wrong or IP is not set\n");
70                         printf("network has problem, try again\n");
71                         return -1;
72                 }
73
74                 g_is_connected = false;
75         } else {
76                 printf("Current network connection is ON. \n");
77                 SLOG(LOG_DEBUG, TAG_TTSD, "[Network] Current network connection is ON.");
78
79                 g_is_connected = true;
80         }
81
82         vconf_notify_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, __net_config_change_cb, NULL);
83
84         SLOG(LOG_DEBUG, TAG_TTSD, "[Network SUCCESS] Initialize network ...\n");
85
86         return 0;
87 }
88
89 int ttsd_network_finalize()
90 {
91         vconf_ignore_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, __net_config_change_cb);
92
93         return 0;
94 }
95