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
|
|
|
|
|
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
|
|
|
|
|
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
|
2004-07-16 19:56:36 +00:00
|
|
|
by the Free Software Foundation; either version 2 of the License,
|
|
|
|
|
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-15 15:18:33 +00:00
|
|
|
#include <stdio.h>
|
2004-06-08 23:54:24 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/xmalloc.h>
|
2009-01-22 00:15:19 +01:00
|
|
|
#include <pulse/util.h>
|
2006-05-17 16:34:18 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/core-subscribe.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulsecore/macro.h>
|
2008-05-15 23:34:41 +00:00
|
|
|
#include <pulsecore/core-util.h>
|
2006-02-17 12:10:58 +00:00
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
#include "client.h"
|
|
|
|
|
|
2009-01-15 17:52:29 +01:00
|
|
|
pa_client_new_data* pa_client_new_data_init(pa_client_new_data *data) {
|
|
|
|
|
pa_assert(data);
|
|
|
|
|
|
|
|
|
|
memset(data, 0, sizeof(*data));
|
|
|
|
|
data->proplist = pa_proplist_new();
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_client_new_data_done(pa_client_new_data *data) {
|
|
|
|
|
pa_assert(data);
|
|
|
|
|
|
|
|
|
|
pa_proplist_free(data->proplist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_client *pa_client_new(pa_core *core, pa_client_new_data *data) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_client *c;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_core_assert_ref(core);
|
2009-01-15 17:52:29 +01:00
|
|
|
pa_assert(data);
|
|
|
|
|
|
|
|
|
|
if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_NEW], data) < 0)
|
|
|
|
|
return NULL;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
c = pa_xnew(pa_client, 1);
|
2004-06-08 23:54:24 +00:00
|
|
|
c->core = core;
|
2009-01-15 17:52:29 +01:00
|
|
|
c->proplist = pa_proplist_copy(data->proplist);
|
2009-01-22 00:15:19 +01:00
|
|
|
c->driver = pa_xstrdup(pa_path_get_filename(data->driver));
|
2009-01-15 17:52:29 +01:00
|
|
|
c->module = data->module;
|
2004-06-15 17:05:03 +00:00
|
|
|
|
2009-01-15 18:38:20 +01:00
|
|
|
c->sink_inputs = pa_idxset_new(NULL, NULL);
|
|
|
|
|
c->source_outputs = pa_idxset_new(NULL, NULL);
|
|
|
|
|
|
2004-06-15 17:05:03 +00:00
|
|
|
c->userdata = NULL;
|
2009-01-15 17:52:29 +01:00
|
|
|
c->kill = NULL;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert_se(pa_idxset_put(core->clients, c, &c->index) >= 0);
|
2004-06-15 15:18:33 +00:00
|
|
|
|
2009-01-15 17:52:29 +01:00
|
|
|
pa_log_info("Created %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
|
2004-08-11 00:11:12 +00:00
|
|
|
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index);
|
2004-09-04 00:27:36 +00:00
|
|
|
|
2009-01-15 17:52:29 +01:00
|
|
|
pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_PUT], c);
|
|
|
|
|
|
2008-08-06 19:39:12 +02:00
|
|
|
pa_core_check_idle(core);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_client_free(pa_client *c) {
|
2008-06-11 16:56:03 +00:00
|
|
|
pa_core *core;
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(c->core);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2009-01-15 18:27:43 +01:00
|
|
|
core = c->core;
|
|
|
|
|
|
2009-01-15 17:52:29 +01:00
|
|
|
pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_UNLINK], c);
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_remove_by_data(c->core->clients, c, NULL);
|
2004-09-04 00:27:36 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_log_info("Freed %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
|
2004-08-11 00:11:12 +00:00
|
|
|
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
|
2009-01-15 17:52:29 +01:00
|
|
|
|
2009-01-15 18:38:20 +01:00
|
|
|
pa_assert(pa_idxset_isempty(c->sink_inputs));
|
|
|
|
|
pa_idxset_free(c->sink_inputs, NULL, NULL);
|
|
|
|
|
pa_assert(pa_idxset_isempty(c->source_outputs));
|
|
|
|
|
pa_idxset_free(c->source_outputs, NULL, NULL);
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_proplist_free(c->proplist);
|
2006-01-27 16:25:31 +00:00
|
|
|
pa_xfree(c->driver);
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_xfree(c);
|
2008-06-11 16:56:03 +00:00
|
|
|
|
2008-08-06 19:39:12 +02:00
|
|
|
pa_core_check_idle(core);
|
2004-06-08 23:54:24 +00:00
|
|
|
}
|
2004-06-14 20:30:50 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_client_kill(pa_client *c) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(c);
|
|
|
|
|
|
2004-07-04 17:40:15 +00:00
|
|
|
if (!c->kill) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_warn("kill() operation not implemented for client %u", c->index);
|
2004-07-04 17:40:15 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c->kill(c);
|
2004-06-14 20:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_client_set_name(pa_client *c, const char *name) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(c);
|
2006-06-13 09:33:55 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_log_info("Client %u changed name from \"%s\" to \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)), name);
|
|
|
|
|
pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
|
2004-08-15 00:02:26 +00:00
|
|
|
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
|
2004-06-29 16:48:37 +00:00
|
|
|
}
|