Patch version revert to build other pakages
[platform/core/api/network-info.git] / test / network_info_service_state_changed_test.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <telephony_network.h>
22 #include <dlog.h>
23 #include <glib.h>
24
25 #ifdef LOG_TAG
26 #undef LOG_TAG
27 #endif
28 #define LOG_TAG "TIZEN_N_NETWORK_INFO_TEST"
29
30 static GMainLoop *event_loop;
31
32 static const char *capi_network_service_state[] = {
33 "In service",
34 "Out of service",
35 "Emergency only",
36 "Radio off",
37 };
38
39 static void state_changed_cb(network_info_service_state_e status, void* user_data)
40 {
41         LOGI("[%s] Start telephony_service_changed_cb", __FUNCTION__);
42
43         LOGI("[%s] Service status: %s", __FUNCTION__, capi_network_service_state[status]);
44         LOGI("[%s] user data: %s", __FUNCTION__, user_data);
45
46         LOGI("[%s] End telephony_service_changed_cb", __FUNCTION__);
47         g_main_loop_quit(event_loop);
48 }
49
50 int main()
51 {
52         if( network_info_set_service_state_changed_cb(state_changed_cb, "telephony_service_changed_test") == NETWORK_INFO_ERROR_NONE )
53         {
54                 LOGI("[%s] Succeeded to add callback function", __FUNCTION__);
55         }
56         else
57         {
58                 LOGE("[%s] Failed to add callback function", __FUNCTION__);
59                 return -1;
60         }
61
62         LOGI("[%s] If service status is changed, then callback function will be called", __FUNCTION__);
63         event_loop = g_main_loop_new(NULL, FALSE);
64         g_main_loop_run(event_loop);
65
66         if( network_info_unset_service_state_changed_cb() == NETWORK_INFO_ERROR_NONE )
67         {
68                 LOGI("[%s] Succeeded to remove callback function", __FUNCTION__);
69         }
70         else
71         {
72                 LOGE("[%s] Failed to remove callback function", __FUNCTION__);
73                 return -1;
74         }
75
76         return 0;
77 }