2004-07-16 19:56:36 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2009-03-03 20:23:02 +00:00
|
|
|
by the Free Software Foundation; either version 2.1 of the License,
|
2004-07-16 19:56:36 +00:00
|
|
|
or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-07-16 19:56:36 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2006-06-19 21:53:48 +00:00
|
|
|
along with PulseAudio; if not, write to the Free Software
|
2004-07-16 19:56:36 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
2004-07-16 19:16:42 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-06-19 19:27:47 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/xmalloc.h>
|
2006-05-17 16:34:18 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/cli.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulsecore/macro.h>
|
2008-08-03 16:44:38 +02:00
|
|
|
#include <pulsecore/shared.h>
|
2006-02-17 12:10:58 +00:00
|
|
|
|
2004-06-19 19:27:47 +00:00
|
|
|
#include "protocol-cli.h"
|
2004-11-18 00:28:26 +00:00
|
|
|
|
|
|
|
|
/* Don't allow more than this many concurrent connections */
|
2005-09-16 00:08:53 +00:00
|
|
|
#define MAX_CONNECTIONS 25
|
2004-06-19 19:27:47 +00:00
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
struct pa_cli_protocol {
|
|
|
|
|
PA_REFCNT_DECLARE;
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_core *core;
|
|
|
|
|
pa_idxset *connections;
|
2004-06-19 19:27:47 +00:00
|
|
|
};
|
|
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
static void cli_unlink(pa_cli_protocol *p, pa_cli *c) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(p);
|
2008-08-03 16:44:38 +02:00
|
|
|
pa_assert(c);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_remove_by_data(p->connections, c, NULL);
|
|
|
|
|
pa_cli_free(c);
|
2004-06-19 19:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
static void cli_eof_cb(pa_cli*c, void*userdata) {
|
|
|
|
|
pa_cli_protocol *p = userdata;
|
|
|
|
|
pa_assert(p);
|
|
|
|
|
|
|
|
|
|
cli_unlink(p, c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_cli_protocol_connect(pa_cli_protocol *p, pa_iochannel *io, pa_module *m) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_cli *c;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_assert(p);
|
2008-08-03 16:44:38 +02:00
|
|
|
pa_assert(io);
|
|
|
|
|
pa_assert(m);
|
2004-06-23 23:17:30 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
|
2004-11-18 00:28:26 +00:00
|
|
|
pa_iochannel_free(io);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
c = pa_cli_new(p->core, io, m);
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_cli_set_eof_callback(c, cli_eof_cb, p);
|
2004-06-19 19:27:47 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_put(p->connections, c, NULL);
|
2004-06-19 19:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
void pa_cli_protocol_disconnect(pa_cli_protocol *p, pa_module *m) {
|
|
|
|
|
pa_cli *c;
|
|
|
|
|
void *state = NULL;
|
|
|
|
|
|
|
|
|
|
pa_assert(p);
|
|
|
|
|
pa_assert(m);
|
|
|
|
|
|
|
|
|
|
while ((c = pa_idxset_iterate(p->connections, &state, NULL)))
|
|
|
|
|
if (pa_cli_get_module(c) == m)
|
|
|
|
|
cli_unlink(p, c);
|
|
|
|
|
}
|
2004-06-19 19:27:47 +00:00
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
static pa_cli_protocol* cli_protocol_new(pa_core *c) {
|
|
|
|
|
pa_cli_protocol *p;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
pa_assert(c);
|
|
|
|
|
|
|
|
|
|
p = pa_xnew(pa_cli_protocol, 1);
|
|
|
|
|
PA_REFCNT_INIT(p);
|
|
|
|
|
p->core = c;
|
2004-07-03 23:35:12 +00:00
|
|
|
p->connections = pa_idxset_new(NULL, NULL);
|
2004-06-19 19:27:47 +00:00
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
pa_assert_se(pa_shared_set(c, "cli-protocol", p) >= 0);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-06-19 19:27:47 +00:00
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
pa_cli_protocol* pa_cli_protocol_get(pa_core *c) {
|
|
|
|
|
pa_cli_protocol *p;
|
|
|
|
|
|
|
|
|
|
if ((p = pa_shared_get(c, "cli-protocol")))
|
|
|
|
|
return pa_cli_protocol_ref(p);
|
|
|
|
|
|
|
|
|
|
return cli_protocol_new(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_cli_protocol* pa_cli_protocol_ref(pa_cli_protocol *p) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(p);
|
2008-08-03 16:44:38 +02:00
|
|
|
pa_assert(PA_REFCNT_VALUE(p) >= 1);
|
|
|
|
|
|
|
|
|
|
PA_REFCNT_INC(p);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
return p;
|
2004-06-19 19:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-03 16:44:38 +02:00
|
|
|
void pa_cli_protocol_unref(pa_cli_protocol *p) {
|
|
|
|
|
pa_cli *c;
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(p);
|
2008-08-03 16:44:38 +02:00
|
|
|
pa_assert(PA_REFCNT_VALUE(p) >= 1);
|
|
|
|
|
|
|
|
|
|
if (PA_REFCNT_DEC(p) > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
while ((c = pa_idxset_first(p->connections, NULL)))
|
|
|
|
|
cli_unlink(p, c);
|
|
|
|
|
|
|
|
|
|
pa_idxset_free(p->connections, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
pa_assert_se(pa_shared_remove(p->core, "cli-protocol") >= 0);
|
2004-06-19 19:27:47 +00:00
|
|
|
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_xfree(p);
|
2004-06-19 19:27:47 +00:00
|
|
|
}
|