Fix TC-2372 Dialer crashes when BT phone is offline
[profile/ivi/lemolo.git] / messages / main.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 #include "log.h"
8 #include "ofono.h"
9 #include "gui.h"
10 #include "rc.h"
11 #include "util.h"
12
13 #include <Ecore_Getopt.h>
14
15 static const char def_modem_hardware_api[] =
16         "SimManager,"
17         "VoiceCallManager,"
18         "MessageManager,"
19         "SimToolkit,"
20         "CallForwarding";
21
22 static const char def_modem_hfp_api[] =
23         "VoiceCallManager";
24
25 static const char def_modem_type[] =
26         "hardware";
27
28 static const char def_rc_service[] = "org.tizen.messages";
29
30
31 static const Ecore_Getopt options = {
32         PACKAGE_NAME,
33         "%prog [options]",
34         PACKAGE_VERSION,
35         "(C) 2012 Intel Corporation",
36         "GPL-2" /* TODO: check license with Intel */,
37         "Phone Messages using oFono and EFL.",
38         EINA_FALSE,
39         {ECORE_GETOPT_STORE_STR('H', "theme", "path to theme EDJ file."),
40          ECORE_GETOPT_STORE_STR('m', "modem", "Modem object path in oFono."),
41          ECORE_GETOPT_STORE_STR('a', "api", "oFono modem APIs to use, comma "
42                                 "separated. Example: "
43                                 "SimManager,VoiceCallManager. See --list-api"),
44          ECORE_GETOPT_STORE_TRUE('A', "list-api", "list all oFono modem API."),
45          ECORE_GETOPT_STORE_DEF_STR('t', "type", "oFono modem type to use.",
46                                         def_modem_type),
47          ECORE_GETOPT_STORE_TRUE('T', "list-types",
48                                         "list all oFono modem types."),
49          ECORE_GETOPT_STORE_STR('R', "rc-dbus-name",
50                                 "The DBus name to use for the remote control."),
51          ECORE_GETOPT_VERSION('V', "version"),
52          ECORE_GETOPT_COPYRIGHT('C', "copyright"),
53          ECORE_GETOPT_LICENSE('L', "license"),
54          ECORE_GETOPT_HELP('h', "help"),
55          ECORE_GETOPT_SENTINEL
56         }
57 };
58
59 int _log_domain = -1;
60 int _app_exit_code = EXIT_SUCCESS;
61
62 EAPI int elm_main(int argc, char **argv)
63 {
64         int args;
65         char *modem_path = NULL;
66         char *modem_api = NULL;
67         char *modem_type = NULL;
68         char *theme = NULL;
69         char *rc_service = NULL;
70         Eina_Bool list_api = EINA_FALSE;
71         Eina_Bool list_type = EINA_FALSE;
72         Eina_Bool quit_option = EINA_FALSE;
73         Ecore_Getopt_Value values[] = {
74                 ECORE_GETOPT_VALUE_STR(theme),
75                 ECORE_GETOPT_VALUE_STR(modem_path),
76                 ECORE_GETOPT_VALUE_STR(modem_api),
77                 ECORE_GETOPT_VALUE_BOOL(list_api),
78                 ECORE_GETOPT_VALUE_STR(modem_type),
79                 ECORE_GETOPT_VALUE_BOOL(list_type),
80                 ECORE_GETOPT_VALUE_STR(rc_service),
81                 ECORE_GETOPT_VALUE_BOOL(quit_option),
82                 ECORE_GETOPT_VALUE_BOOL(quit_option),
83                 ECORE_GETOPT_VALUE_BOOL(quit_option),
84                 ECORE_GETOPT_VALUE_BOOL(quit_option),
85                 ECORE_GETOPT_VALUE_NONE
86         };
87
88         _log_domain = eina_log_domain_register("messages", NULL);
89         if (_log_domain < 0)
90         {
91                 EINA_LOG_CRIT("Could not create log domain 'messages'.");
92                 elm_shutdown();
93                 return EXIT_FAILURE;
94         }
95
96         args = ecore_getopt_parse(&options, values, argc, argv);
97         if (args < 0)
98         {
99                 ERR("Could not parse command line options.");
100                 _app_exit_code = EXIT_FAILURE;
101                 goto end;
102         }
103         if (list_api) {
104                 puts("Supported oFono API:");
105                 ofono_modem_api_list(stdout, "\t", "\n");
106                 goto end;
107         }
108         if (list_type) {
109                 puts("Supported oFono type:");
110                 ofono_modem_type_list(stdout, "\t", "\n");
111                 goto end;
112         }
113
114         if (quit_option)
115                 goto end;
116
117         if (rc_service) {
118                 INF("User-defined DBus remote control service name: %s",
119                         rc_service);
120         } else {
121                 INF("Using default DBus remote control service name: %s",
122                         def_rc_service);
123         }
124
125         if (!rc_init(rc_service ? rc_service : def_rc_service)) {
126                 CRITICAL("Could not setup remote control via DBus.");
127                 _app_exit_code = EXIT_FAILURE;
128                 goto end;
129         }
130
131         if (!ofono_init()) {
132                 CRITICAL("Could not setup ofono");
133                 _app_exit_code = EXIT_FAILURE;
134                 goto end_rc;
135         }
136
137         if (modem_path) {
138                 INF("User-defined modem path: %s", modem_path);
139                 ofono_modem_path_wanted_set(modem_path);
140         }
141
142         if (modem_api) {
143                 INF("User-defined modem API: %s", modem_api);
144                 ofono_modem_api_require(modem_api);
145         } else {
146                 const char *api;
147                 if (!modem_type)
148                         api = def_modem_hardware_api;
149                 else if (strstr(modem_type, "hfp"))
150                         api = def_modem_hfp_api;
151                 else if (strcmp(modem_type, "hardware"))
152                         api = def_modem_hardware_api;
153                 else {
154                         WRN("modem type not handled: %s", modem_type);
155                         api = "VoiceCallManager";
156                 }
157
158                 INF("Using default modem API: %s", api);
159                 ofono_modem_api_require(api);
160         }
161
162         if (modem_type) {
163                 INF("User-defined modem type: %s", modem_type);
164                 ofono_modem_type_require(modem_type);
165         } else {
166                 INF("Using default modem type: %s", def_modem_type);
167                 ofono_modem_type_require(def_modem_type);
168         }
169
170         if (!util_init(theme)) {
171                 CRITICAL("Could not setup graphical user interface");
172                 _app_exit_code = EXIT_FAILURE;
173                 goto end_ofono;
174         }
175
176         if (!gui_init()) {
177                 CRITICAL("Could not setup graphical user interface");
178                 _app_exit_code = EXIT_FAILURE;
179                 goto end_util;
180         }
181
182         INF("Entering main loop");
183         elm_run();
184         INF("Quit main loop");
185
186         gui_shutdown();
187
188 end_util:
189         util_shutdown();
190 end_ofono:
191         ofono_shutdown();
192 end_rc:
193         rc_shutdown();
194 end:
195         elm_shutdown();
196
197         return _app_exit_code;
198 }
199
200 #endif
201 ELM_MAIN()