add description field for sinks/sources
[profile/ivi/pulseaudio.git] / src / protocol-cli.c
1 #include <assert.h>
2 #include <stdlib.h>
3
4 #include "protocol-cli.h"
5 #include "cli.h"
6
7 struct pa_protocol_cli {
8     struct pa_module *module;
9     struct pa_core *core;
10     struct pa_socket_server*server;
11     struct pa_idxset *connections;
12 };
13
14 static void cli_eof_cb(struct pa_cli*c, void*userdata) {
15     struct pa_protocol_cli *p = userdata;
16     assert(p);
17     pa_idxset_remove_by_data(p->connections, c, NULL);
18     pa_cli_free(c);
19 }
20
21 static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
22     struct pa_protocol_cli *p = userdata;
23     struct pa_cli *c;
24     assert(s && io && p);
25
26     c = pa_cli_new(p->core, io, p->module);
27     assert(c);
28     pa_cli_set_eof_callback(c, cli_eof_cb, p);
29
30     pa_idxset_put(p->connections, c, NULL);
31 }
32
33 struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m) {
34     struct pa_protocol_cli* p;
35     assert(core && server);
36
37     p = malloc(sizeof(struct pa_protocol_cli));
38     assert(p);
39     p->module = m;
40     p->core = core;
41     p->server = server;
42     p->connections = pa_idxset_new(NULL, NULL);
43
44     pa_socket_server_set_callback(p->server, on_connection, p);
45     
46     return p;
47 }
48
49 static void free_connection(void *p, void *userdata) {
50     assert(p);
51     pa_cli_free(p);
52 }
53
54 void pa_protocol_cli_free(struct pa_protocol_cli *p) {
55     assert(p);
56
57     pa_idxset_free(p->connections, free_connection, NULL);
58     pa_socket_server_free(p->server);
59     free(p);
60 }