Fix compilation with json-c on Yocto
[staging/agl-audio-plugin.git] / zone.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 "zone.h"
23
24 struct agl_zoneset {
25         struct {
26                 pa_hashmap     *hash;
27                 agl_zone       *index[AGL_ZONE_MAX];
28         } zones;
29 };
30
31 agl_zoneset *agl_zoneset_init (struct userdata *u)
32 {
33         agl_zoneset *zs;
34
35         pa_assert (u);
36
37         zs = pa_xnew0 (agl_zoneset, 1);
38         zs->zones.hash = pa_hashmap_new (pa_idxset_string_hash_func,
39                                          pa_idxset_string_compare_func);
40
41         return zs;
42 }
43
44 void agl_zoneset_done (struct userdata *u)
45 {
46         agl_zoneset *zs;
47         void *state;
48         agl_zone *zone;
49
50         if (u && (zs = u->zoneset)) {
51
52                 PA_HASHMAP_FOREACH(zone, zs->zones.hash, state) {
53                         pa_xfree ((void *)zone->name);
54                 }
55                 pa_hashmap_free (zs->zones.hash);
56                 free (zs);
57         }    
58 }
59
60 int agl_zoneset_add_zone (struct userdata *u, const char *name, uint32_t index)
61 {
62         agl_zoneset *zs;
63         agl_zone *zone;
64
65         pa_assert (u);
66         pa_assert (name);
67         pa_assert (index < AGL_ZONE_MAX);
68         pa_assert_se (zs = u->zoneset);
69
70         zone = pa_xnew (agl_zone, 1);
71         zone->name = pa_xstrdup (name);
72         zone->index = index;
73
74         pa_hashmap_put (zs->zones.hash, (void *)zone->name, zone);
75
76         zs->zones.index[index] = zone;
77
78         return 0;
79 }
80
81 agl_zone *agl_zoneset_get_zone_by_name (struct userdata *u, const char *name)
82 {
83         agl_zoneset *zs;
84         agl_zone *zone;
85
86         pa_assert (u);
87         pa_assert_se (zs = u->zoneset);
88
89         if (name && zs->zones.hash)
90                 zone = pa_hashmap_get (zs->zones.hash, name);
91         else
92                 zone = NULL;
93
94         return zone;
95 }
96
97 agl_zone *agl_zoneset_get_zone_by_index (struct userdata *u, uint32_t index)
98 {
99         agl_zoneset *zs;
100         agl_zone *zone;
101
102         pa_assert (u);
103         pa_assert_se (zs = u->zoneset);
104
105         if (index < AGL_ZONE_MAX)
106                 zone = zs->zones.index[index];
107         else
108                 zone = NULL;
109
110         return zone;
111 }