summaryrefslogtreecommitdiffstats
path: root/node.c
blob: c6c59e2a28f6c8660d788301cf9233c2532e11bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 * module-agl-audio -- PulseAudio module for providing audio routing support
 * (forked from "module-murphy-ivi" - https://github.com/otcshare )
 * Copyright (c) 2012, Intel Corporation.
 * Copyright (c) 2016, IoT.bzh
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston,
 * MA 02110-1301 USA.
 *
 */
#include "node.h"

#include <pulsecore/idxset.h>

pa_nodeset *pa_nodeset_init (struct userdata *u)
{
	pa_nodeset *ns;

	pa_assert (u);

	ns = pa_xnew0 (pa_nodeset, 1);
	ns->nodes = pa_idxset_new (pa_idxset_trivial_hash_func,
		                   pa_idxset_trivial_compare_func);
	ns->roles = pa_hashmap_new (pa_idxset_string_hash_func,
		                    pa_idxset_string_compare_func);
	ns->binaries = pa_hashmap_new (pa_idxset_string_hash_func,
		                       pa_idxset_string_compare_func);
	return ns;
}

void pa_nodeset_done(struct userdata *u)
{
	pa_nodeset *ns;
	pa_nodeset_map *role, *binary;
	void *state;
	int i;

	if (u && (ns = u->nodeset)) {
		pa_idxset_free (ns->nodes, NULL);

		PA_HASHMAP_FOREACH(role, ns->roles, state) {
			pa_xfree ((void *)role->name);
			pa_xfree ((void *)role->resdef);
		}
		pa_hashmap_free (ns->roles);

		PA_HASHMAP_FOREACH(binary, ns->binaries, state) {
			pa_xfree ((void *)binary->name);
			pa_xfree ((void *)binary->resdef);
		}
		pa_hashmap_free (ns->binaries);

		for (i = 0;  i < APCLASS_DIM;  i++)
			pa_xfree((void *)ns->class_name[i]);

		free(ns);
	}
}

agl_node *agl_node_create (struct userdata *u, agl_node *data)
{
	pa_nodeset *ns;
	agl_node *node;

	pa_assert (u);
	pa_assert_se (ns = u->nodeset);

	node = pa_xnew0 (agl_node, 1);

	pa_idxset_put (ns->nodes, node, &node->index);

	if (data) {
		node->key = pa_xstrdup (data->key);
		node->direction = data->direction;
		node->implement = data->implement;
		node->channels = data->channels;
		node->location = data->location;
		node->privacy = data->privacy;
		node->type = data->type;
		node->zone = pa_xstrdup (data->zone);
		node->visible = data->visible;
		node->available = data->available;
		node->amname = pa_xstrdup (data->amname ? data->amname : data->paname);
		node->amdescr = pa_xstrdup(data->amdescr ? data->amdescr : "");
		node->amid = data->amid;
		node->paname = pa_xstrdup (data->paname);
		node->stamp = data->stamp;
		node->rset.id = data->rset.id ? pa_xstrdup(data->rset.id) : NULL;
		node->rset.grant = data->rset.grant;

		if (node->implement == agl_device) {
			node->pacard.index = data->pacard.index;
			if (data->pacard.profile)
				node->pacard.profile = pa_xstrdup (data->pacard.profile);
			if (data->paport)
				node->paport = data->paport;
		}
	}

	 /* TODO : register the node to the router */
	/* agl_router_register_node (u, node); */

	return node;
}

const char *agl_node_type_str (agl_node_type type)
{
	switch (type) {
		case agl_node_type_unknown: return "Unknown";
		case agl_radio:             return "Radio";
		case agl_player:            return "Player";
		case agl_navigator:         return "Navigator";
		case agl_game:              return "Game";
		case agl_browser:           return "Browser";
                case agl_camera:            return "Camera";
		case agl_phone:             return "Phone";
		case agl_alert:             return "Alert";
		case agl_event:             return "Event";
		case agl_system:            return "System";
		default:                    return "<user defined>";
	}
}

agl_node *agl_node_get_from_data (struct userdata *u, agl_direction type, void *data)
{
	pa_sink_input_new_data *sinp_data;
	pa_source_output_new_data *sout_data;
	pa_nodeset *nodeset;
	agl_node *node;
	uint32_t index;

	pa_assert (u);
	pa_assert (data);
	pa_assert (nodeset = u->nodeset);

	pa_assert (type == agl_input || type == agl_output);

	/* input (= sink_input) */
	if (type == agl_input) {
		sinp_data = (pa_sink_input_new_data *) data;
		PA_IDXSET_FOREACH(node, nodeset->nodes, index) {
			if (node->client == sinp_data->client)
				return node;
		}
	/* output (= source_output) TODO */
	/*} else {*/
	}

	return NULL;
}

agl_node *agl_node_get_from_client (struct userdata *u, pa_client *client)
{
	pa_nodeset *nodeset;
	agl_node *node;
	uint32_t index;

	pa_assert (u);
	pa_assert (client);
	pa_assert (nodeset = u->nodeset);

	PA_IDXSET_FOREACH(node, nodeset->nodes, index) {
		if (node->client == client)
			return node;
	}

	return NULL;
}