26d725ee16ea684f632d5b6e3c799cbc2a0b99b0
[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 const char *agl_config_file_get_path (const char *dir, const char *file, char *buf, size_t len)
26 {
27         pa_assert (file);
28         pa_assert (buf);
29         pa_assert (len > 0);
30
31         snprintf (buf, len, "%s/%s", dir, file);
32
33         return buf;
34 }
35
36 bool agl_config_parse_file (struct userdata *u, const char *path)
37 {
38         bool success;
39
40         pa_assert (u);
41
42         if (!path)
43                 return false;
44         else {
45                 pa_log_info ("parsing configuration file '%s'", path);
46                 success = agl_config_dofile (u, path);
47         }
48
49         if (!success) {
50                 pa_log_info ("applying builtin default configuration");
51                 //success = use_default_configuration (u);
52         }
53
54         return success;
55 }
56
57 bool agl_config_dofile (struct userdata *u, const char *path)
58 {
59         /* TODO */
60         return false;
61 }
62
63
64  /* DEFAULT CONFIGURATION PART */
65
66 static zone_def zones[] = {
67         { "driver" },
68         { "passenger1" },
69         { "passenger2" },
70         { "passenger3" },
71         { "passenger4" },
72         { NULL }
73 };
74
75
76 static rtgroup_def rtgroups[] = {
77         { agl_input,
78           "phone",
79           agl_router_phone_accept,
80           agl_router_phone_compare
81         },
82
83         { 0, NULL, NULL, NULL }
84 };
85
86 static classmap_def classmap[] = {
87         { agl_phone,    0, agl_output, "phone" },
88         { agl_player,   0, agl_output, "default" },
89         { agl_radio,    0, agl_output, "default" },
90         { agl_navigator,0, agl_output, "default" },
91         { agl_event,    0, agl_output, "default" },
92         { agl_node_type_unknown, 0, agl_direction_unknown, NULL }
93 };
94
95 static typemap_def typemap[] = {
96         { "phone", agl_phone },
97         { "music", agl_player },
98         { "radio", agl_radio },
99         { "navi", agl_navigator },
100         { "event", agl_event },
101         { NULL, agl_node_type_unknown }
102 };
103
104 static prior_def priormap[] = {
105         { agl_event,     5 },
106         { agl_phone,     4 },
107         { agl_navigator, 2 },
108         { agl_radio,     1 },
109         { agl_player,    1 },
110         { agl_node_type_unknown, 0}
111 };
112
113 bool use_default_configuration (struct userdata *u)
114 {
115         zone_def *z;
116         rtgroup_def *r;
117         classmap_def *c;
118         typemap_def *t;
119         prior_def *p;
120
121         pa_assert (u);
122
123         for (z = zones; z->name; z++)
124                 agl_zoneset_add_zone (u, z->name, (uint32_t)(z - zones));
125
126         for (r = rtgroups; r->name; r++)
127                 agl_router_create_rtgroup (u, r->type, r->name, r->accept, r->compare);
128
129         for (c = classmap; c->rtgroup; c++)
130                 agl_router_assign_class_to_rtgroup (u, c->class, c->zone,
131                                                        c->type, c->rtgroup);
132
133         for (t = typemap; t->id; t++) 
134                 agl_nodeset_add_role (u, t->id, t->type, NULL);
135
136         for (p = priormap; p->class; p++)
137                 agl_router_assign_class_priority (u, p->class, p->priority);
138
139         return true;
140 }