murphyif: Free the connect timer when unloading
[profile/ivi/pulseaudio-module-murphy-ivi.git] / murphy / murphy-config.c
1 /*
2  * module-murphy-ivi -- PulseAudio module for providing audio routing support
3  * Copyright (c) 2012, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU Lesser General Public License,
7  * version 2.1, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.
12  * See the GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston,
17  * MA 02110-1301 USA.
18  *
19  */
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <errno.h>
24
25 #include <pulsecore/pulsecore-config.h>
26
27 #include "murphy-config.h"
28 #include "zone.h"
29 #include "node.h"
30 #include "router.h"
31 #include "volume.h"
32 #include "scripting.h"
33
34 typedef struct {
35     const char *name;
36 } zone_def;
37
38 typedef struct {
39     mir_direction          type;
40     const char            *name;
41     mir_rtgroup_accept_t   accept;
42     mir_rtgroup_compare_t  compare;
43 } rtgroup_def;
44
45 typedef struct {
46     mir_node_type  class;
47     uint32_t       zone;
48     mir_direction  type;
49     const char    *rtgroup;
50 } classmap_def;
51
52 typedef struct {
53     char          *id;
54     mir_node_type  type;
55 } typemap_def;
56
57 typedef struct {
58     mir_node_type  class;
59     int            priority;
60 } prior_def;
61
62
63
64 static zone_def zones[] = {
65     "driver",
66     "passanger1",
67     "passanger2",
68     "passanger3",
69     "passanger4",
70     NULL
71 };
72
73 static rtgroup_def  rtgroups[] = {
74     {mir_input,
75      "phone",
76      mir_router_phone_accept,
77      mir_router_phone_compare
78     },
79
80     {mir_output,
81      "default",
82      mir_router_default_accept,
83      mir_router_default_compare
84     },
85
86     {mir_output,
87      "phone",
88      mir_router_phone_accept,
89      mir_router_phone_compare
90     },
91
92     {0,NULL,NULL,NULL}
93 };
94
95 static classmap_def classmap[] = {
96     {mir_phone    , 0, mir_input , "phone"  },
97     {mir_radio    , 0, mir_output, "default"},
98     {mir_player   , 0, mir_output, "default"},
99     {mir_navigator, 0, mir_output, "default"},
100     {mir_game     , 0, mir_output, "default"},
101     {mir_browser  , 0, mir_output, "default"},
102     {mir_phone    , 0, mir_output, "phone"  },
103     {mir_event    , 0, mir_output, "default"},
104     {mir_node_type_unknown, 0, mir_direction_unknown, NULL}
105 };
106
107 static typemap_def rolemap[] = {
108     {"video"    , mir_player    },
109     {"music"    , mir_player    },
110     {"game"     , mir_game      },
111     {"event"    , mir_event     },
112     {"navigator", mir_navigator },
113     {"phone"    , mir_phone     },
114     {"carkit"   , mir_phone     },
115     {"animation", mir_browser   },
116     {"test"     , mir_player    },
117     {"ringtone" , mir_alert     },
118     {"alarm"    , mir_alert     },
119     {"camera"   , mir_camera    },
120     {"system"   , mir_system    },
121     {NULL, mir_node_type_unknown}
122 };
123
124 static typemap_def binmap[] = {
125     {"rhytmbox"    , mir_player },
126     {"firefox"     , mir_browser},
127     {"chrome"      , mir_browser},
128     {"sound-juicer", mir_player },
129     {NULL, mir_node_type_unknown}
130 };
131
132 static prior_def priormap[] = {
133     {mir_radio    , 1},
134     {mir_player   , 1},
135     {mir_navigator, 2},
136     {mir_game     , 3},
137     {mir_browser  , 1},
138     {mir_phone    , 4},
139     {mir_event    , 5},
140     {mir_node_type_unknown, 0}
141 };
142
143 static double speedvol;
144 static double supprvol = -20.0;
145 static int exception_classes[] = {mir_phone, mir_navigator};
146 static mir_volume_suppress_arg suppress = {
147     &supprvol, {DIM(exception_classes), exception_classes}
148 };
149
150
151 static bool use_default_configuration(struct userdata *);
152
153 #if 0
154 static bool parse_config_file(struct userdata *, FILE *);
155 #endif
156
157 pa_mir_config *pa_mir_config_init(struct userdata *u)
158 {
159     pa_mir_config *config;
160
161     pa_assert(u);
162
163     config = pa_xnew0(pa_mir_config, 1);
164
165     return config;
166 }
167
168 void pa_mir_config_done(struct userdata *u)
169 {
170     pa_mir_config *config;
171
172     if (u && (config = u->config)) {
173         pa_xfree(config);
174         u->config = NULL;
175     }
176 }
177
178
179 bool pa_mir_config_parse_file(struct userdata *u, const char *path)
180 {
181     pa_module *module;
182     pa_mir_config *config;
183     int success;
184     char buf[4096];
185
186     pa_assert(u);
187     pa_assert_se((module = u->module));
188     pa_assert_se((config = u->config));
189
190     if (!path)
191         success = false;
192     else {
193         pa_log_info("%s: configuration file is '%s'", module->name, path);
194         success =  pa_scripting_dofile(u, path);
195     }
196
197     if (!success) {
198         pa_log_info("%s: builtin default configuration applies", module->name);
199         success = use_default_configuration(u);
200     }
201
202     pa_nodeset_print_maps(u, buf, sizeof(buf));
203     pa_log_debug(buf);
204
205     return success;
206 }
207
208 static bool use_default_configuration(struct userdata *u)
209 {
210     zone_def     *z;
211     rtgroup_def  *r;
212     classmap_def *c;
213     typemap_def  *t;
214     prior_def    *p;
215
216     pa_assert(u);
217
218     for (z = zones;  z->name;  z++)
219         pa_zoneset_add_zone(u, z->name, z - zones);
220
221     for (r = rtgroups;  r->name;   r++)
222         mir_router_create_rtgroup(u, r->type, r->name, r->accept, r->compare);
223
224     for (c = classmap;  c->rtgroup;  c++) {
225         mir_router_assign_class_to_rtgroup(u, c->class, c->zone,
226                                            c->type, c->rtgroup);
227     }
228
229     for (t = rolemap; t->id; t++)
230         pa_nodeset_add_role(u, t->id, t->type, NULL);
231
232     for (t = binmap; t->id; t++)
233         pa_nodeset_add_binary(u, t->id, t->type, NULL, NULL);
234
235     for (p = priormap;  p->class;  p++)
236         mir_router_assign_class_priority(u, p->class, p->priority);
237
238
239     mir_volume_add_generic_limit(u, mir_volume_correction, &speedvol);
240
241     mir_volume_add_class_limit(u, mir_phone,mir_volume_suppress, &suppress);
242     mir_volume_add_class_limit(u, mir_navigator,mir_volume_suppress,&suppress);
243
244
245     return true;
246 }
247
248 /*
249  * Local Variables:
250  * c-basic-offset: 4
251  * indent-tabs-mode: nil
252  * End:
253  *
254  */