upload tizen1.0 source
[framework/telephony/tel-plugin-socket_communicator.git] / test / main.c
1 /*
2  * tel-plugin-socket-communicator
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/time.h>
25 #include <unistd.h>
26 #include <glib.h>
27 #include <glib-object.h>
28
29 #include <tapi_sipc.h>
30
31 #include "menu.h"
32 #include "noti.h"
33
34 extern struct menu_data menu_modem[];
35 extern struct menu_data menu_gprs[];
36 extern struct menu_data menu_net[];
37 extern struct menu_data menu_custom[];
38
39 static struct menu_data menu_xxx[] = {
40         { "1", "XXX",           NULL,   NULL,           NULL},
41         { NULL, NULL, },
42 };
43
44 static struct menu_data menu_main[] = {
45         { "1", "Common",        menu_xxx,       NULL,           NULL},
46         { "2", "Modem",         menu_modem,     NULL,           NULL},
47         { "3", "Call",          menu_xxx,       NULL,           NULL},
48         { "4", "SIM",           menu_xxx,       NULL,           NULL},
49         { "5", "SS",            menu_xxx,       NULL,           NULL},
50         { "6", "SMS",           menu_xxx,       NULL,           NULL},
51         { "7", "Network",       menu_net,       NULL,           NULL},
52         { "8", "SAT",           menu_xxx,       NULL,           NULL},
53         { "9", "GPRS",          menu_gprs,      NULL,           NULL},
54         { "a", "SOUND",         menu_xxx,       NULL,           NULL},
55         { "b", "Custom",        menu_custom,NULL,               NULL},
56         { NULL, NULL, },
57 };
58
59 tapi_handle_t *register_client(void)
60 {
61         tapi_handle_t *handle;
62
63         handle = tapi_init("com.xxx.test", "default");
64         if (!handle) {
65                 printf("fail to register server\n");
66                 return NULL;
67         }
68
69         printf("success to register server\n");
70         return handle;
71 }
72
73 void register_event(tapi_handle_t *handle)
74 {
75         int ret;
76
77         /* PS */
78         ret = tapi_register_notification(handle, TAPI_NOTI_PS_DUN_PIN_CONTROL, on_noti_ps_dun_pin_control, NULL);
79         ret = tapi_register_notification(handle, TAPI_NOTI_PS_EXTERNAL_CALL, on_noti_ps_external_call, NULL);
80
81         /* Network */
82         ret = tapi_register_notification(handle, TAPI_NOTI_NETWORK_REGISTRATION_STATUS, on_noti_network_registration_status, NULL);
83         ret = tapi_register_notification(handle, TAPI_NOTI_NETWORK_LOCATION_CELLINFO, on_noti_network_location_cellinfo, NULL);
84         ret = tapi_register_notification(handle, TAPI_NOTI_NETWORK_ICON_INFO, on_noti_network_icon_info, NULL);
85         ret = tapi_register_notification(handle, TAPI_NOTI_NETWORK_CHANGE, on_noti_network_change, NULL);
86         ret = tapi_register_notification(handle, TAPI_NOTI_NETWORK_TIMEINFO, on_noti_network_timeinfo, NULL);
87 }
88
89 void deregister_client(tapi_handle_t *handle)
90 {
91         gboolean rv = FALSE;
92
93         if (!handle)
94                 return;
95
96         rv = tapi_deinit(handle);
97         if (!rv) {
98                 printf("fail to deregister server\n");
99                 return;
100         }
101
102         printf("success to deregister server\n");
103         return;
104 }
105
106 int main(int arg, char **argv)
107 {
108         GMainLoop *mainloop;
109         GIOChannel *channel = g_io_channel_unix_new(STDIN_FILENO);
110         MManager *manager;
111         tapi_handle_t *handle;
112
113         mainloop = g_main_loop_new(NULL, FALSE);
114         handle = register_client();
115
116         register_event(handle);
117
118         printf("******* Integrated TAPI Test Application: Version 0.4  *****\n");
119         printf("******* Buid On: %s  %s  ********\n", __DATE__, __TIME__);
120
121         manager = menu_manager_new(menu_main, mainloop);
122         menu_manager_set_user_data(manager, handle);
123         menu_manager_run(manager);
124
125         g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL), on_menu_manager_keyboard, manager);
126
127         g_main_loop_run(mainloop);
128
129         printf("******* Bye bye *******\n");
130
131         deregister_client(handle);
132
133         return 0;
134 }
135