Initial Commit, basic infrastructure.
[profile/ivi/lemolo.git] / dialer / 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
12 #include <Ecore_Getopt.h>
13
14 static const Ecore_Getopt options = {
15         PACKAGE_NAME,
16         "%prog [options]",
17         PACKAGE_VERSION,
18         "(C) 2012 Intel Corporation",
19         "GPL-2" /* TODO: check license with Intel */,
20         "Phone Dialer using oFono and EFL.",
21         EINA_FALSE,
22         {ECORE_GETOPT_STORE_STR('m', "modem", "Modem object path in oFono."),
23          ECORE_GETOPT_STORE_UINT('a', "api", "oFono modem API mask."),
24          ECORE_GETOPT_VERSION('V', "version"),
25          ECORE_GETOPT_COPYRIGHT('C', "copyright"),
26          ECORE_GETOPT_LICENSE('L', "license"),
27          ECORE_GETOPT_HELP('h', "help"),
28          ECORE_GETOPT_SENTINEL
29         }
30 };
31
32 int _log_domain = -1;
33 int _app_exit_code = EXIT_SUCCESS;
34
35 EAPI int elm_main(int argc, char **argv)
36 {
37         int args;
38         char *modem_path = NULL;
39         unsigned int modem_api = 0;
40         Eina_Bool quit_option = EINA_FALSE;
41         Ecore_Getopt_Value values[] = {
42                 ECORE_GETOPT_VALUE_STR(modem_path),
43                 ECORE_GETOPT_VALUE_UINT(modem_api),
44                 ECORE_GETOPT_VALUE_BOOL(quit_option),
45                 ECORE_GETOPT_VALUE_BOOL(quit_option),
46                 ECORE_GETOPT_VALUE_BOOL(quit_option),
47                 ECORE_GETOPT_VALUE_BOOL(quit_option),
48                 ECORE_GETOPT_VALUE_NONE
49         };
50
51         _log_domain = eina_log_domain_register("dialer", NULL);
52         if (_log_domain < 0)
53         {
54                 EINA_LOG_CRIT("Could not create log domain 'dialer'.");
55                 elm_shutdown();
56                 return EXIT_FAILURE;
57         }
58
59         args = ecore_getopt_parse(&options, values, argc, argv);
60         if (args < 0)
61         {
62                 ERR("Could not parse command line options.");
63                 _app_exit_code = EXIT_FAILURE;
64                 goto end;
65         }
66         if (quit_option)
67                 goto end;
68
69         if (!rc_init()) {
70                 CRITICAL("Could not setup remote control via DBus.");
71                 _app_exit_code = EXIT_FAILURE;
72                 goto end;
73         }
74
75         if (!ofono_init()) {
76                 CRITICAL("Could not setup ofono");
77                 _app_exit_code = EXIT_FAILURE;
78                 goto end_rc;
79         }
80
81         if (modem_path) {
82                 INF("User-defined modem path: %s", modem_path);
83                 ofono_modem_path_wanted_set(modem_path);
84         }
85
86         if (modem_api) {
87                 INF("User-defined modem API mask: %#x", modem_api);
88                 ofono_modem_api_require(modem_api);
89         }
90
91         if (!gui_init()) {
92                 CRITICAL("Could not setup graphical user interface");
93                 _app_exit_code = EXIT_FAILURE;
94                 goto end_ofono;
95         }
96
97         INF("Entering main loop");
98         elm_run();
99         INF("Quit main loop");
100
101         gui_shutdown();
102
103 end_ofono:
104         ofono_shutdown();
105 end_rc:
106         rc_shutdown();
107 end:
108         elm_shutdown();
109
110         return _app_exit_code;
111 }
112
113 #endif
114 ELM_MAIN()