Map labels to classes, map routing groups to audio adapters
[staging/agl-audio-plugin.git] / config.c
1 /*
2  * module-agl-audio -- PulseAudio module for providing audio routing support
3  * (forked from "module-murphy-ivi" - https://github.com/otcshare )
4  * Copyright (c) 2012, Intel Corporation.
5  * Copyright (c) 2016, IoT.bzh
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms and conditions of the GNU Lesser General Public License,
9  * version 2.1, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston,
19  * MA 02110-1301 USA.
20  *
21  */
22 #include "config.h"
23 #include "zone.h"
24
25 bool use_default_configuration (struct userdata *);
26
27 const char *agl_config_file_get_path (const char *dir, const char *file, char *buf, size_t len)
28 {
29         pa_assert (file);
30         pa_assert (buf);
31         pa_assert (len > 0);
32
33         snprintf (buf, len, "%s/%s", dir, file);
34
35         return buf;
36 }
37
38 bool agl_config_parse_file (struct userdata *u, const char *path)
39 {
40         bool success;
41
42         pa_assert (u);
43
44         if (!path)
45                 return false;
46         else {
47                 pa_log_info ("parsing configuration file '%s'", path);
48                 success = agl_config_dofile (u, path);
49         }
50
51         if (!success) {
52                 pa_log_info ("applying builtin default configuration");
53                 success = use_default_configuration (u);
54         }
55
56         return success;
57 }
58
59 bool agl_config_dofile (struct userdata *u, const char *path)
60 {
61         /* TODO */
62         return false;
63 }
64
65
66  /* DEFAULT CONFIGURATION PART */
67
68 static zone_def zones[] = {
69         { "driver" },
70         { "passenger1" },
71         { "passenger2" },
72         { "passenger3" },
73         { "passenger4" },
74         { NULL }
75 };
76
77
78 static rtgroup_def rtgroups[] = {
79         { agl_input,
80           "Phone",
81           "PhoneCard",
82           agl_router_phone_accept,
83           agl_router_phone_compare
84         },
85
86         { 0, NULL, NULL, NULL, NULL }
87 };
88
89 static classmap_def classmap[] = {
90         { agl_phone,    0, agl_input, "Phone" },
91         { agl_player,   0, agl_input, "default" },
92         { agl_radio,    0, agl_input, "default" },
93         { agl_navigator,0, agl_input, "default" },
94         { agl_event,    0, agl_input, "default" },
95         { agl_node_type_unknown, 0, agl_direction_unknown, NULL }
96 };
97
98 static typemap_def typemap[] = {
99         { "phone", agl_phone },
100         { "music", agl_player },
101         { "radio", agl_radio },
102         { "navi", agl_navigator },
103         { "event", agl_event },
104         { NULL, agl_node_type_unknown }
105 };
106
107 static prior_def priormap[] = {
108         { agl_event,     5 },
109         { agl_phone,     4 },
110         { agl_navigator, 2 },
111         { agl_radio,     1 },
112         { agl_player,    1 },
113         { agl_node_type_unknown, 0}
114 };
115
116 bool use_default_configuration (struct userdata *u)
117 {
118         zone_def *z;
119         rtgroup_def *r;
120         classmap_def *c;
121         typemap_def *t;
122         prior_def *p;
123
124         pa_assert (u);
125
126         for (z = zones; z->name; z++)
127                 agl_zoneset_add_zone (u, z->name, (uint32_t)(z - zones));
128
129         for (r = rtgroups; r->name; r++)
130                 agl_router_create_rtgroup (u, r->type, r->name, r->node_desc,
131                                               r->accept, r->compare);
132
133         for (c = classmap; c->rtgroup; c++)
134                 agl_router_assign_class_to_rtgroup (u, c->class, c->zone,
135                                                        c->type, c->rtgroup);
136
137         for (t = typemap; t->id; t++) 
138                 agl_nodeset_add_role (u, t->id, t->type, NULL);
139
140         for (p = priormap; p->class; p++)
141                 agl_router_assign_class_priority (u, p->class, p->priority);
142
143         return true;
144 }