router: fix for bluetooth disappearing causing assert in combine
[profile/ivi/pulseaudio-module-murphy-ivi.git] / murphy / module-murphy-ivi.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/stat.h>
4 #include <stdio.h>
5 #include <errno.h>
6 #include <string.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <limits.h>
10
11 #include <sys/types.h>
12 #include <sys/socket.h>
13
14 #include <pulsecore/pulsecore-config.h>
15
16 #include <pulse/timeval.h>
17 #include <pulse/xmalloc.h>
18
19 #include <pulsecore/macro.h>
20 #include <pulsecore/module.h>
21 #include <pulsecore/idxset.h>
22 #include <pulsecore/client.h>
23 #include <pulsecore/core-util.h>
24 #include <pulsecore/core-error.h>
25 #include <pulsecore/modargs.h>
26 #include <pulsecore/log.h>
27
28 #include "module-murphy-ivi-symdef.h"
29 #include "userdata.h"
30 #include "node.h"
31 #include "tracker.h"
32 #include "discover.h"
33 #include "router.h"
34 #include "multiplex.h"
35 #include "audiomgr.h"
36 #include "dbusif.h"
37 #include "config.h"
38 #include "utils.h"
39
40 #ifndef DEFAULT_CONFIG_FILE
41 #define DEFAULT_CONFIG_FILE "murphy-ivi.conf"
42 #endif
43
44
45 PA_MODULE_AUTHOR("Janos Kovacs");
46 PA_MODULE_DESCRIPTION("Murphy and GenIVI compliant audio policy module");
47 PA_MODULE_VERSION(PACKAGE_VERSION);
48 PA_MODULE_LOAD_ONCE(TRUE);
49 PA_MODULE_USAGE(
50     "config_dir=<configuration directory>"
51     "config_file=<policy configuration file> "
52     "dbus_bus_type=<system|session> "
53     "dbus_if_name=<policy dbus interface> "
54     "dbus_murphy_path=<policy daemon's path> "
55     "dbus_murphy_name=<policy daemon's name> "
56     "dbus_audiomgr_path=<GenIVI audio manager's path> " 
57     "dbus_audiomgr_name=<GenIVI audio manager's name> " 
58     "null_sink_name=<name of the null sink> "
59 );
60
61 static const char* const valid_modargs[] = {
62     "config_dir",
63     "config_file",
64     "dbus_bus_type",
65     "dbus_if_name",
66     "dbus_murphy_path",
67     "dbus_murphy_name",
68     "dbus_audiomgr_path",
69     "dbus_audiomgr_name",
70     "null_sink_name",
71     NULL
72 };
73
74
75 int pa__init(pa_module *m) {
76     struct userdata *u = NULL;
77     pa_modargs      *ma = NULL;
78     const char      *cfgdir;
79     const char      *cfgfile;
80     const char      *dbustype;
81     const char      *ifnam;
82     const char      *mrppath;
83     const char      *mrpnam;
84     const char      *ampath;
85     const char      *amnam;
86     const char      *nsnam;
87     const char      *cfgpath;
88     char             buf[4096];
89     
90     pa_assert(m);
91     
92     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
93         pa_log("Failed to parse module arguments.");
94         goto fail;
95     }
96
97     cfgdir   = pa_modargs_get_value(ma, "config_dir", NULL);
98     cfgfile  = pa_modargs_get_value(ma, "config_file", DEFAULT_CONFIG_FILE);
99     dbustype = pa_modargs_get_value(ma, "dbus_bus_type", NULL);
100     ifnam    = pa_modargs_get_value(ma, "dbus_if_name", NULL);
101     mrppath  = pa_modargs_get_value(ma, "dbus_murphy_path", NULL);
102     mrpnam   = pa_modargs_get_value(ma, "dbus_murphy_name", NULL);
103     ampath   = pa_modargs_get_value(ma, "dbus_audiomgr_path", NULL);
104     amnam    = pa_modargs_get_value(ma, "dbus_audiomgr_name", NULL);
105     nsnam    = pa_modargs_get_value(ma, "null_sink_name", NULL);
106     
107     u = pa_xnew0(struct userdata, 1);
108     u->core      = m->core;
109     u->module    = m;
110     u->nullsink  = pa_utils_create_null_sink(u, nsnam);
111     u->nodeset   = pa_nodeset_init(u);
112     u->audiomgr  = pa_audiomgr_init(u);
113     u->dbusif    = pa_policy_dbusif_init(u, dbustype, ifnam, mrppath, mrpnam,
114                                          ampath, amnam);
115     u->discover  = pa_discover_init(u);
116     u->tracker   = pa_tracker_init(u);
117     u->router    = pa_router_init(u);
118     u->multiplex = pa_multiplex_init();
119     u->config    = pa_mir_config_init(u);
120
121     if (u->nullsink == NULL || u->dbusif == NULL  ||
122         u->audiomgr == NULL || u->discover == NULL)
123         goto fail;
124
125     m->userdata = u;
126
127     //cfgpath = pa_utils_file_path(cfgfile, buf, sizeof(buf));
128     cfgpath = cfgfile;
129     pa_mir_config_parse_file(u, cfgpath);
130
131     pa_tracker_synchronize(u);
132
133     mir_router_print_rtgroups(u, buf, sizeof(buf));
134     pa_log_debug("%s", buf);
135     
136     pa_modargs_free(ma);
137     
138     return 0;
139     
140  fail:
141     
142     if (ma)
143         pa_modargs_free(ma);
144     
145     pa__done(m);
146     
147     return -1;
148 }
149
150 void pa__done(pa_module *m) {
151     struct userdata *u;
152
153     pa_assert(m);
154     
155     if ((u = m->userdata)) {
156     
157         pa_tracker_done(u);
158         pa_discover_done(u);
159         pa_router_done(u);
160         pa_audiomgr_done(u);
161         pa_policy_dbusif_done(u);
162         pa_mir_config_done(u);
163         pa_nodeset_done(u);
164         pa_utils_destroy_null_sink(u);
165
166         pa_multiplex_done(u->multiplex, u->core);
167
168
169         pa_xfree(u);
170     }
171 }
172
173
174
175 /*
176  * Local Variables:
177  * c-basic-offset: 4
178  * indent-tabs-mode: nil
179  * End:
180  *
181  */
182
183