Init pulseaudio at startup
[profile/ivi/lemolo.git] / dialer / main.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4 #ifdef HAVE_TIZEN
5 #include <appcore-efl.h>
6 #endif
7 #include <Elementary.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <Evas.h>
11
12 #ifndef ELM_LIB_QUICKLAUNCH
13
14 #include "amb.h"
15 #include "gui.h"
16 #include "log.h"
17 #include "ofono.h"
18 #include "pulseaudio.h"
19 #include "rc.h"
20 #include "util.h"
21
22 #include <Ecore_Getopt.h>
23
24 static const char def_modem_hardware_api[] =
25         "SimManager,"
26         "VoiceCallManager,"
27         "MessageManager,"
28         "SimToolkit,"
29         "CallForwarding";
30
31 static const char def_modem_hfp_api[] =
32         "VoiceCallManager";
33
34 static const char def_modem_type[] =
35         "hfp";
36
37 static const char def_rc_service[] = "org.tizen.dialer";
38
39
40 static const Ecore_Getopt options = {
41         PACKAGE_NAME,
42         "%prog [options]",
43         PACKAGE_VERSION,
44         "(C) 2012 Intel Corporation",
45         "GPL-2" /* TODO: check license with Intel */,
46         "Phone Dialer using oFono and EFL.",
47         EINA_FALSE,
48         {ECORE_GETOPT_STORE_STR('H', "theme", "path to theme EDJ file."),
49          ECORE_GETOPT_STORE_STR('m', "modem", "Modem object path in oFono."),
50          ECORE_GETOPT_STORE_STR('a', "api", "oFono modem APIs to use, comma "
51                                 "separated. Example: "
52                                 "SimManager,VoiceCallManager. See --list-api"),
53          ECORE_GETOPT_STORE_TRUE('A', "list-api", "list all oFono modem API."),
54          ECORE_GETOPT_STORE_DEF_STR('t', "type", "oFono modem type to use.",
55                                         def_modem_type),
56          ECORE_GETOPT_STORE_TRUE('T', "list-types",
57                                         "list all oFono modem types."),
58          ECORE_GETOPT_STORE_STR('R', "rc-dbus-name",
59                                 "The DBus name to use for the remote control."),
60          ECORE_GETOPT_VERSION('V', "version"),
61          ECORE_GETOPT_COPYRIGHT('C', "copyright"),
62          ECORE_GETOPT_LICENSE('L', "license"),
63          ECORE_GETOPT_HELP('h', "help"),
64          ECORE_GETOPT_SENTINEL
65         }
66 };
67
68 int _log_domain = -1;
69 int _app_exit_code = EXIT_SUCCESS;
70
71 #ifdef HAVE_TIZEN
72 static int _create(void *data __UNUSED__)
73 {
74         return 0;
75 }
76
77 static int _reset(bundle *b __UNUSED__, void *data __UNUSED__)
78 {
79         return 0;
80 }
81
82 static int _resume(void *data __UNUSED__)
83 {
84         return 0;
85 }
86
87 static int _pause(void *data __UNUSED__)
88 {
89         return 0;
90 }
91
92 static int _terminate(void *data __UNUSED__)
93 {
94         return 0;
95 }
96 #endif
97
98 EAPI int elm_main(int argc, char **argv)
99 {
100         int args;
101         char *modem_path = NULL;
102         char *modem_api = NULL;
103         char *modem_type = NULL;
104         char *theme = NULL;
105         char *rc_service = NULL;
106         Eina_Bool list_api = EINA_FALSE;
107         Eina_Bool list_type = EINA_FALSE;
108         Eina_Bool quit_option = EINA_FALSE;
109         Ecore_Getopt_Value values[] = {
110                 ECORE_GETOPT_VALUE_STR(theme),
111                 ECORE_GETOPT_VALUE_STR(modem_path),
112                 ECORE_GETOPT_VALUE_STR(modem_api),
113                 ECORE_GETOPT_VALUE_BOOL(list_api),
114                 ECORE_GETOPT_VALUE_STR(modem_type),
115                 ECORE_GETOPT_VALUE_BOOL(list_type),
116                 ECORE_GETOPT_VALUE_STR(rc_service),
117                 ECORE_GETOPT_VALUE_BOOL(quit_option),
118                 ECORE_GETOPT_VALUE_BOOL(quit_option),
119                 ECORE_GETOPT_VALUE_BOOL(quit_option),
120                 ECORE_GETOPT_VALUE_BOOL(quit_option),
121                 ECORE_GETOPT_VALUE_NONE
122         };
123
124         _log_domain = eina_log_domain_register("dialer", NULL);
125         if (_log_domain < 0)
126         {
127                 EINA_LOG_CRIT("Could not create log domain 'dialer'.");
128                 elm_shutdown();
129                 return EXIT_FAILURE;
130         }
131
132         args = ecore_getopt_parse(&options, values, argc, argv);
133         if (args < 0)
134         {
135                 ERR("Could not parse command line options.");
136                 _app_exit_code = EXIT_FAILURE;
137                 goto end;
138         }
139         if (list_api) {
140                 puts("Supported oFono API:");
141                 ofono_modem_api_list(stdout, "\t", "\n");
142                 goto end;
143         }
144         if (list_type) {
145                 puts("Supported oFono type:");
146                 ofono_modem_type_list(stdout, "\t", "\n");
147                 goto end;
148         }
149
150         if (quit_option)
151                 goto end;
152
153         if (rc_service) {
154                 INF("User-defined DBus remote control service name: %s",
155                         rc_service);
156         } else {
157                 INF("Using default DBus remote control service name: %s",
158                         def_rc_service);
159         }
160
161         if (!rc_init(rc_service ? rc_service : def_rc_service)) {
162                 CRITICAL("Could not setup remote control via DBus.");
163                 _app_exit_code = EXIT_FAILURE;
164                 goto end;
165         }
166
167         if (!ofono_init()) {
168                 CRITICAL("Could not setup ofono");
169                 _app_exit_code = EXIT_FAILURE;
170                 goto end_rc;
171         }
172
173         if (modem_path) {
174                 INF("User-defined modem path: %s", modem_path);
175                 ofono_modem_path_wanted_set(modem_path);
176         }
177
178         if (modem_api) {
179                 INF("User-defined modem API: %s", modem_api);
180                 ofono_modem_api_require(modem_api);
181         } else {
182                 const char *api;
183                 if (!modem_type)
184                         api = def_modem_hfp_api;
185                 else if (strstr(modem_type, "hfp"))
186                         api = def_modem_hfp_api;
187                 else if (strcmp(modem_type, "hardware"))
188                         api = def_modem_hardware_api;
189                 else {
190                         WRN("modem type not handled: %s", modem_type);
191                         api = "VoiceCallManager";
192                 }
193
194                 INF("Using default modem API: %s", api);
195                 ofono_modem_api_require(api);
196         }
197
198         if (modem_type) {
199                 INF("User-defined modem type: %s", modem_type);
200                 ofono_modem_type_require(modem_type);
201         } else {
202                 INF("Using default modem type: %s", def_modem_type);
203                 ofono_modem_type_require(def_modem_type);
204         }
205
206         if (!util_init(theme)) {
207                 CRITICAL("Could not setup graphical user interface");
208                 _app_exit_code = EXIT_FAILURE;
209                 goto end_ofono;
210         }
211
212 #ifdef HAVE_TIZEN
213         if (!amb_init()) {
214                 CRITICAL("Could not setup automotive-message-broker");
215                 _app_exit_code = EXIT_FAILURE;
216                 goto end_amb;
217         }
218 #endif
219
220         if (!pa_init()) {
221                 CRITICAL("Could not setup pulseaudio");
222                 _app_exit_code = EXIT_FAILURE;
223                 goto end_pulseaudio;
224         }
225
226         if (!gui_init()) {
227                 CRITICAL("Could not setup graphical user interface");
228                 _app_exit_code = EXIT_FAILURE;
229                 goto end_util;
230         }
231
232         INF("Entering main loop");
233
234 #ifdef HAVE_TIZEN
235         int iReturn = 0;
236         struct appcore_ops ops = {
237                 .create = _create,
238                 .resume = _resume,
239                 .reset = _reset,
240                 .pause = _pause,
241                 .terminate = _terminate,
242         };
243         ops.data = NULL;
244         iReturn = appcore_efl_main("org.tizen.dialer", &argc, &argv, &ops);
245 #else
246         elm_run();
247 #endif
248         INF("Quit main loop");
249
250         gui_shutdown();
251
252 end_util:
253         util_shutdown();
254 end_pulseaudio:
255         pa_shutdown();
256 #ifdef HAVE_TIZEN
257 end_amb:
258         amb_shutdown();
259 #endif
260 end_ofono:
261         ofono_shutdown();
262 end_rc:
263         rc_shutdown();
264 end:
265         elm_shutdown();
266
267 #ifdef HAVE_TIZEN
268         return iReturn;
269 #else
270         return _app_exit_code;
271 #endif
272 }
273
274 #endif
275 ELM_MAIN()