calssification: more heuristics to guess bluetooth device classes
[profile/ivi/pulseaudio-module-murphy-ivi.git] / 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 <string.h>
22 #include <errno.h>
23
24 #include <pulsecore/pulsecore-config.h>
25
26 #include "config.h"
27 #include "node.h"
28 #include "router.h"
29 #include "volume.h"
30
31 typedef struct {
32     const char            *name;
33     mir_rtgroup_accept_t   accept;
34     mir_rtgroup_compare_t  compare;
35 } rtgroup_def;
36
37 typedef struct {
38     mir_node_type  class;
39     const char    *rtgroup;
40 } classmap_def;
41
42 typedef struct {
43     mir_node_type  class;
44     int            priority;
45 } prior_def;
46
47
48 static rtgroup_def  rtgroups[] = {
49     {"default"  , mir_router_default_accept, mir_router_default_compare},
50     {"phone"    , mir_router_phone_accept  , mir_router_phone_compare  },
51     {   NULL  ,            NULL          ,              NULL         }
52 };
53
54 static classmap_def classmap[] = {
55     {mir_radio    , "default"},
56     {mir_player   , "default"},
57     {mir_navigator, "default"},
58     {mir_game     , "default"},
59     {mir_browser  , "default"},
60     {mir_phone    , "phone"  },
61     {mir_event    , "default"},
62     {mir_node_type_unknown, NULL}
63 };
64
65 static prior_def priormap[] = {
66     {mir_radio    , 1},
67     {mir_player   , 1},
68     {mir_navigator, 2},
69     {mir_game     , 3},
70     {mir_browser  , 1},
71     {mir_phone    , 4},
72     {mir_event    , 5},
73     {mir_node_type_unknown, 0}
74 };
75
76 static double speedvol;
77 static int exception_classes[] = {mir_phone, mir_navigator};
78 static mir_volume_suppress_arg suppress = {
79     -20.0, {DIM(exception_classes), exception_classes}
80 };
81
82
83 static pa_bool_t use_default_configuration(struct userdata *);
84 static pa_bool_t parse_config_file(struct userdata *, FILE *);
85
86
87 pa_mir_config *pa_mir_config_init(struct userdata *u)
88 {
89     pa_mir_config *config;
90
91     pa_assert(u);
92
93     config = pa_xnew0(pa_mir_config, 1);
94
95     return config;
96 }
97
98 void pa_mir_config_done(struct userdata *u)
99 {
100     pa_mir_config *config;
101
102     if (u && (config = u->config)) {
103         pa_xfree(config);
104         u->config = NULL;
105     }
106 }
107
108
109 pa_bool_t pa_mir_config_parse_file(struct userdata *u, const char *path)
110 {
111     pa_mir_config *config;
112     FILE *f;
113     int success;
114
115     pa_assert(u);
116     pa_assert_se((config = u->config));
117
118     if (path) {
119         if ((f = fopen(path, "r"))) {
120             success = parse_config_file(u, f);
121             fclose(f);
122             return success;
123         }
124         else {
125             pa_log_info("%s: failed to open config file '%s': %s",
126                         __FILE__, path, strerror(errno));            
127         }
128     }
129
130     pa_log_debug("%s: default config values will apply", __FILE__);
131
132     success = use_default_configuration(u);
133
134     return success;
135 }
136
137 static pa_bool_t use_default_configuration(struct userdata *u)
138 {
139     rtgroup_def  *r;
140     classmap_def *c;
141     prior_def    *p;
142
143     pa_assert(u);
144
145     for (r = rtgroups;  r->name;   r++)
146         mir_router_create_rtgroup(u, r->name, r->accept, r->compare);
147
148     for (c = classmap;  c->rtgroup;  c++)
149         mir_router_assign_class_to_rtgroup(u, c->class, c->rtgroup);
150
151     for (p = priormap;  p->class;  p++)
152         mir_router_assign_class_priority(u, p->class, p->priority);
153
154
155     mir_volume_add_generic_limit(u, mir_volume_correction, &speedvol);
156
157     mir_volume_add_class_limit(u, mir_phone,mir_volume_suppress, &suppress);
158     mir_volume_add_class_limit(u, mir_navigator,mir_volume_suppress,&suppress);
159
160
161     return TRUE;
162 }
163
164 static pa_bool_t parse_config_file(struct userdata *u, FILE *f)
165 {
166     return TRUE;
167 }
168                                   
169 /*
170  * Local Variables:
171  * c-basic-offset: 4
172  * indent-tabs-mode: nil
173  * End:
174  *
175  */